Fix architecture review findings and align CLI metadata
This commit is contained in:
1 parent
780a4ba9c0
commit
50e4e492b4
83 files changed
+966
-792
No files matched your search
+16
-60
@@ -2,7 +2,7 @@ import type { WebhookMode } from "../domains/seal/types.js";
|
||||
import type { MaterialPackFilePolicyPatch } from "../domains/seal/material-pack/policy.js";
|
||||
import type { ParsedArgs } from "./types.js";
|
||||
import { type DurationToken, EXPIRE_UNITS, expireSeconds, tokenizeDuration } from "../core/duration.js";
|
||||
import { usageError } from "./errors.js";
|
||||
import { usageError, validationError } from "../core/errors.js";
|
||||
|
||||
/**
|
||||
* Flag metadata for argv parsing, derived from how the code reads each flag:
|
||||
@@ -23,6 +23,7 @@ import { usageError } from "./errors.js";
|
||||
|
||||
// Read with booleanOption(...) / Boolean(...) / presence check.
|
||||
export const BOOLEAN_FLAGS = new Set([
|
||||
"clear", "clear-max-file-size", "clearMaxFileSize", "latest", "show-secret", "showSecret",
|
||||
"V", "add", "all", "allow-unreviewed", "allowUnreviewed", "as-hose", "attachments", "auto",
|
||||
"auto-login", "autoLogin", "bg-save", "changelog", "check", "check-only",
|
||||
"completed-only", "completedOnly", "confirm", "count", "disable-attachment-cache", "disableAttachmentCache",
|
||||
@@ -40,6 +41,9 @@ export const BOOLEAN_FLAGS = new Set([
|
||||
|
||||
// Read with stringOption/numberOption/splitOption(...).
|
||||
export const VALUE_FLAGS = new Set([
|
||||
"allowed-extensions", "allowedExtensions", "extensions", "auto-approval-rate", "autoApprovalRate", "approval-rate",
|
||||
"min-file-size", "min-file-size-bytes", "minFileSize", "minFileSizeBytes",
|
||||
"max-file-size", "max-file-size-bytes", "maxFileSize", "maxFileSizeBytes", "templates",
|
||||
"access-token", "accessToken", "action", "add-approver-ids", "addApproverIds", "ai", "ai-accuracy", "aiAccuracy", "app-key", "app-security", "appKey", "appSecurity",
|
||||
"base-url", "batch", "batch-id", "batchId", "both", "both-accurate", "bothAccurate", "business-codes", "businessCodes",
|
||||
"channel", "chrome", "code", "comment", "concurrency", "confirm-code", "confirmCode", "content", "content-file", "content-hints", "content-type", "contentFile",
|
||||
@@ -86,60 +90,9 @@ export const VALUE_FLAGS = new Set([
|
||||
|
||||
// Registered flags. Unknown flags are rejected.
|
||||
export const KNOWN_FLAGS = new Set([
|
||||
"V", "access-token", "accessToken", "action", "add-approver-ids", "addApproverIds", "ai", "ai-accuracy", "aiAccuracy", "add", "all", "allow-unreviewed", "allowUnreviewed", "app-key",
|
||||
"app-security", "appKey", "appSecurity", "as-hose", "attachments", "auto",
|
||||
"auto-login", "autoLogin", "base-url", "batch", "batch-id", "batchId",
|
||||
"bg-save", "both", "both-accurate", "bothAccurate", "business-codes", "businessCodes", "channel", "changelog", "check", "check-only", "chrome",
|
||||
"code", "comment", "completed-only", "completedOnly", "concurrency", "confirm", "confirm-code", "confirmCode", "content",
|
||||
"content-file", "content-hints", "content-type", "contentFile", "contentType", "context-chars", "contextLines", "corp",
|
||||
"corp-id", "corpId", "corporation-id", "corporationId", "count", "date", "dedupe-by", "dedupeBy",
|
||||
"default", "departmentId", "dept", "desc", "description", "description-file",
|
||||
"descriptionFile", "dir", "disable-attachment-cache", "disableAttachmentCache", "doc-id-prefix", "doc-id-suffix",
|
||||
"docIdPrefix", "docIdSuffix", "document-id", "document-sn", "document-sns", "document-type",
|
||||
"documentId", "documentLimit", "documentSn", "documentType", "domain", "download",
|
||||
"downloads", "dry-run", "dryRun", "elevate-hose", "enable", "enabled",
|
||||
"end", "end-date", "end-time", "endDate", "endTime", "env",
|
||||
"environment", "exclude-deleted", "extract", "extract-expenses", "extractExpenses", "expire", "expires-in", "expiresIn", "f", "fail-on-flips",
|
||||
"fields", "file", "file-id", "file-name", "flow", "flow-concurrency", "flow-id", "flow-ids", "flow-status-list",
|
||||
"flowId", "flowIds", "flowStatusList", "force", "format", "from", "from-link",
|
||||
"full", "glossary", "h", "has-input", "has-output", "help", "hose", "hose-outbound", "hose-sso", "hoseOutbound", "hoseSso",
|
||||
"host", "human", "human-accuracy", "humanAccuracy", "humanResult", "id", "include-deleted", "include-io-preview", "include-simulation", "include-unchanged",
|
||||
"includeBridge", "includeSimulation", "includeUnchanged", "input", "integration", "json",
|
||||
"json-path", "key-id", "keyId", "keyword", "ledger", "level", "limit", "lines",
|
||||
"link", "linter", "local", "manual-status", "manualApprovalStatus", "manualStatus",
|
||||
"max-chars", "max-preview-chars", "maxChars", "maxResults", "max-results", "message-id", "messageId", "metadata", "metadata-key", "min-score", "minScore", "mode",
|
||||
"max-runs",
|
||||
"month",
|
||||
"n", "name", "name-contains", "no-attachments", "no-flow", "no-glossary", "no-wait", "noWait", "node-id", "nodeId",
|
||||
"note", "observation-id", "observation-types", "o", "offset", "out", "out-dir", "outDir", "outbound",
|
||||
"outgoing-result-webhook", "outgoingResultWebhook", "output", "output-file", "outputFile", "overwrite",
|
||||
"p", "package-id", "package-ids", "packageId", "packageIds", "path",
|
||||
"phone", "plain", "policy", "policyId", "poll-interval", "pollInterval", "port",
|
||||
"prod", "prod-corp", "prodCorp", "publish", "purpose", "q",
|
||||
"query", "quiet", "r", "recode", "record-id", "record-ids",
|
||||
"recordId", "recordIds", "refresh", "refresh-if-missing", "reject-node", "rejectNode", "reject-to", "rejectTo", "rejection-num", "rejectionNum", "repo",
|
||||
"report-id",
|
||||
"request-ids", "requestIds", "resubmit-method", "resubmitMethod", "result-url", "resultUrl", "reuse-window", "reuseWindow",
|
||||
"reviewed-by", "reviewedBy",
|
||||
"reveal", "rotate-secret", "rotateSecret", "rule", "rule-hints", "rule-id", "ruleId",
|
||||
"ruleVersion", "runtime-id", "runtimeId", "samples", "save", "scenarios",
|
||||
"schema-config", "schemaConfig", "scope", "sealUrl", "search", "secret",
|
||||
"selector", "session-id", "sign-key", "signKey", "silent", "silent-save", "simulation",
|
||||
"simulationBatchId", "since", "skip-expense-extraction", "skip-extract", "skip-invoice-generation", "skipExpenseExtraction", "skipExtract", "skipInvoiceGeneration",
|
||||
"sn", "sn-prefix", "sn-suffix", "snPrefix", "snSuffix", "snippet-only",
|
||||
"snippetOnly", "sns", "source-corp", "source-system", "sourceCorp", "sourceDocumentId",
|
||||
"sourceDocumentSN", "sourceSystem", "sso", "staff-id", "staff-name", "staff-phone",
|
||||
"staffId", "staffName", "staffPhone", "start", "start-date", "start-time",
|
||||
"startDate", "startTime", "state", "status", "strict", "strictness",
|
||||
"summary", "tag", "tag-id", "tagId", "tags", "target",
|
||||
"template",
|
||||
"target-corp", "targetCorp", "task-mode", "taskMode", "template-id", "templateId",
|
||||
"test-corp", "thinking-depth", "thinkingDepth", "timeout", "timezone", "title",
|
||||
"to", "to-downloads", "toDownloads", "token", "tokenId", "trace-id", "trace-limit", "type",
|
||||
"until", "url", "userId", "v", "version", "version-name",
|
||||
"verdict",
|
||||
"versionName", "wait", "webhook", "width", "with-expense-extraction", "withExpenseExtraction", "with-flow", "workflow-type-id", "workflowTypeId",
|
||||
"workspace", "yes"
|
||||
...BOOLEAN_FLAGS,
|
||||
...VALUE_FLAGS,
|
||||
"f", "h", "version"
|
||||
]);
|
||||
|
||||
export function parseArgs(argv: string[]): ParsedArgs {
|
||||
@@ -170,6 +123,9 @@ export function parseArgs(argv: string[]): ParsedArgs {
|
||||
const key = raw.slice(0, eqIdx);
|
||||
const val = raw.slice(eqIdx + 1);
|
||||
if (key === "python") throw usageError("--python 已移除:报告工具不再依赖 Python。");
|
||||
if (!KNOWN_FLAGS.has(key)) {
|
||||
throw usageError(`Unknown option: --${key}.${suggestFlag(key)}`);
|
||||
}
|
||||
options[key] = val;
|
||||
continue;
|
||||
}
|
||||
@@ -283,7 +239,7 @@ export function booleanOption(value: string | boolean | undefined): boolean | un
|
||||
|
||||
export function requiredString(input: Record<string, unknown>, key: string): string {
|
||||
const value = optionalString(input, key);
|
||||
if (!value) throw new Error(`Missing required JSON field: ${key}`);
|
||||
if (!value) throw usageError(`Missing required JSON field: ${key}`);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -292,7 +248,7 @@ export function requiredStringAlias(input: Record<string, unknown>, keys: string
|
||||
const value = optionalString(input, key);
|
||||
if (value) return value;
|
||||
}
|
||||
throw new Error(`Missing required JSON field: ${keys.join(" or ")}`);
|
||||
throw usageError(`Missing required JSON field: ${keys.join(" or ")}`);
|
||||
}
|
||||
|
||||
export function optionalString(input: Record<string, unknown>, key: string): string | undefined {
|
||||
@@ -318,7 +274,7 @@ export function parseStateMode(value: string): boolean {
|
||||
const normalized = value.trim().toLowerCase();
|
||||
if (["stateful", "state", "有状态"].includes(normalized)) return true;
|
||||
if (["stateless", "无状态"].includes(normalized)) return false;
|
||||
throw new Error("Invalid config mode. Use stateful or stateless.");
|
||||
throw validationError("Invalid config mode. Use stateful or stateless.");
|
||||
}
|
||||
|
||||
export function parseRuleVersionSelector(value: string) {
|
||||
@@ -388,7 +344,7 @@ export function parseWebhookMode(value?: string): WebhookMode | undefined {
|
||||
};
|
||||
const mode = aliases[normalized];
|
||||
if (!mode) {
|
||||
throw new Error("Invalid Webhook mode. Use assisted, semi_automatic, or fully_automatic");
|
||||
throw validationError("Invalid Webhook mode. Use assisted, semi_automatic, or fully_automatic");
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
@@ -398,7 +354,7 @@ export function webhookRateOption(options: Record<string, string | boolean>): nu
|
||||
options.autoApprovalRate ?? options["auto-approval-rate"] ?? options["approval-rate"]
|
||||
);
|
||||
if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > 100)) {
|
||||
throw new Error("Webhook auto approval rate must be an integer between 0 and 100");
|
||||
throw validationError("Webhook auto approval rate must be an integer between 0 and 100");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user