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
+119
-227
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
||||
import type { CorpConfig } from "../core/config/types.js";
|
||||
import { VERSION_INFO } from "../version.js";
|
||||
import { isUpdateCacheExpired, loadUpdateCache, triggerBackgroundUpdateCheck } from "../core/update-cache.js";
|
||||
import { classifyCliError } from "./errors.js";
|
||||
import { classifyCliError, usageError } from "../core/errors.js";
|
||||
import {
|
||||
booleanOption,
|
||||
materialPackFilePolicyOptions,
|
||||
@@ -22,52 +22,70 @@ import {
|
||||
printJson,
|
||||
redactSensitiveText
|
||||
} from "./printer.js";
|
||||
import type { CliResult, CliRunOptions, CliRuntime } from "./types.js";
|
||||
import type { KyInstance } from "ky";
|
||||
import type { ParsedArgs, CliResult, CliRunOptions, CliRuntime } from "./types.js";
|
||||
|
||||
const DEFAULT_APP_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
||||
export const UPDATE_ALIASES = new Set([
|
||||
"update",
|
||||
"upgrade",
|
||||
"up",
|
||||
"self-update",
|
||||
"selfupdate"
|
||||
]);
|
||||
export { UPDATE_ALIASES } from "./area-aliases.js";
|
||||
import { AREA_ALIASES, normalizeCliArea, UPDATE_ALIASES } from "./area-aliases.js";
|
||||
|
||||
type LocalCommand = (args: ParsedArgs, runtime: CliRuntime) => Promise<void>;
|
||||
type CorpCommand = (args: ParsedArgs, corp: CorpConfig) => Promise<void>;
|
||||
type ClientCommand = (args: ParsedArgs, corp: CorpConfig, client: KyInstance) => Promise<void>;
|
||||
|
||||
// Handler tables also define the known command surface. Imports stay lazy so
|
||||
// local discovery never loads the tenant, Excel, or zip implementation graphs.
|
||||
const LOCAL_COMMANDS: Record<string, LocalCommand> = {
|
||||
"mcp-config": async () => (await import("./commands/mcp.js")).printMcpConfig(),
|
||||
skill: async (args) => (await import("./commands/skill.js")).handleSkillCommand(args.command[1], args.command[2], args),
|
||||
mcp: async (args) => (await import("./commands/mcp.js")).handleMcpCommand(args.command[1]),
|
||||
probe: async (args) => (await import("./commands/probe.js")).handleProbeCommand(args.command[1], args.command[2], args),
|
||||
doctor: async (args) => (await import("./commands/doctor.js")).handleDoctorCommand(args.command[1], args.command[2], args),
|
||||
langfuse: async (args) => (await import("./commands/langfuse.js")).handleLangfuseCommand(args.command[1], args.command[2], args),
|
||||
test: async (args) => (await import("./commands/test.js")).handleTestCommand(args.command[1], args.command[2], args),
|
||||
config: async (args) => (await import("./commands/config.js")).handleConfigCommand(args.command[1], args.command[2], args),
|
||||
update: dispatchUpdate,
|
||||
changelog: dispatchUpdate,
|
||||
corps: async (args) => {
|
||||
const action = args.command[1];
|
||||
if (action === "regression" || action === "test-regression") {
|
||||
await (await import("./commands/test.js")).handleTestCommand("regression", args.command[2], args);
|
||||
return;
|
||||
}
|
||||
await (await import("./commands/corps.js")).handleCorpsCommand(action, args.command[2], args);
|
||||
}
|
||||
};
|
||||
|
||||
const CORP_COMMANDS: Record<string, CorpCommand> = {
|
||||
source: async (args, corp) => (await import("./commands/source.js")).handleSourceCommand(args.command[1], corp),
|
||||
auth: async (args, corp) => (await import("./commands/auth.js")).handleAuthCommand(args.command[1], corp, args)
|
||||
};
|
||||
|
||||
const CLIENT_COMMANDS: Record<string, ClientCommand> = {
|
||||
"users": async (args, corp, client) => (await import("./commands/users.js")).handleUsersCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"contacts": async (args, corp, client) => (await import("./commands/contacts.js")).handleContactsCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"data": async (args, corp, client) => (await import("./commands/data.js")).handleDataCommand(args.command[1], client, corp, args),
|
||||
"llm": async (args, corp, client) => (await import("./commands/llm.js")).handleLlmCommand(args.command[1], client, corp, args),
|
||||
"permissions": async (args, corp, client) => (await import("./commands/permissions.js")).handlePermissionsCommand(args.command[1], client, corp, args),
|
||||
"billing": async (args, corp, client) => (await import("./commands/billing.js")).handleBillingCommand(args.command[1], client, corp, args),
|
||||
"webhook": async (args, corp, client) => (await import("./commands/webhook.js")).handleWebhookCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"context": async (args, corp, client) => (await import("./commands/context.js")).handleContextCommand(client, corp, args),
|
||||
"documents": async (args, corp, client) => (await import("./commands/documents.js")).handleDocumentsCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"rules": async (args, corp, client) => (await import("./commands/rules.js")).handleRulesCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"approval-runs": async (args, corp, client) => (await import("./commands/approval-runs.js")).handleApprovalRunsCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"analytics": async (args, corp, client) => (await import("./commands/analytics.js")).handleAnalyticsCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"report": async (args, corp, client) => (await import("./commands/report.js")).handleReportCommand(args.command[1], client, corp, args),
|
||||
"simulation": async (args, corp, client) => (await import("./commands/simulation.js")).handleSimulationCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"deploy": async (args, corp, client) => (await import("./commands/deploy.js")).handleDeployCommand(args.command[1], args.command[2], args.command[3], client, corp, args),
|
||||
"hose-ebot": async (args, corp, client) => (await import("./commands/hose-ebot.js")).handleHoseEbotCommand(args.command[1], args.command[2], client, corp, args),
|
||||
"preference": async (args, corp, client) => (await import("./commands/preference.js")).handlePreferenceCommand(args.command[1], args.command[2], args.command[3], args.command[4], client, corp, args),
|
||||
};
|
||||
|
||||
export const KNOWN_AREAS = new Set([
|
||||
"config",
|
||||
"update",
|
||||
"corps",
|
||||
"corp",
|
||||
"source",
|
||||
"hose-ebot",
|
||||
"auth",
|
||||
"users",
|
||||
"contacts",
|
||||
"data",
|
||||
"llm",
|
||||
"permissions",
|
||||
"billing",
|
||||
"webhook",
|
||||
"webhooks",
|
||||
"context",
|
||||
"documents",
|
||||
"rules",
|
||||
"approval-runs",
|
||||
"analytics",
|
||||
"report",
|
||||
"simulation",
|
||||
"deploy",
|
||||
"preference",
|
||||
"preferences",
|
||||
"mcp",
|
||||
"server",
|
||||
"mcp-config",
|
||||
"skill",
|
||||
"probe",
|
||||
"doctor",
|
||||
"langfuse",
|
||||
"changelog",
|
||||
"test"
|
||||
...Object.keys(LOCAL_COMMANDS),
|
||||
...Object.keys(CORP_COMMANDS),
|
||||
...Object.keys(CLIENT_COMMANDS),
|
||||
...Object.keys(AREA_ALIASES)
|
||||
]);
|
||||
|
||||
export type { CliResult, CliRunOptions } from "./types.js";
|
||||
@@ -140,12 +158,53 @@ async function runCliOnce(argv: string[], options: CliRunOptions): Promise<CliRe
|
||||
}
|
||||
}
|
||||
|
||||
async function dispatchUpdate(args: ParsedArgs, runtime: CliRuntime): Promise<void> {
|
||||
const [rawArea, action] = args.command;
|
||||
const isUpdate = rawArea ? UPDATE_ALIASES.has(rawArea.toLowerCase()) : false;
|
||||
const area = rawArea?.toLowerCase();
|
||||
if (isUpdate && rawArea !== "update") {
|
||||
console.error(`⚠️ Notice: '${rawArea}' is an alias for 'seal-use update'. Please use 'seal-use update' instead.`);
|
||||
}
|
||||
|
||||
const lowerAction = action?.toLowerCase();
|
||||
const isChangelog =
|
||||
area === "changelog" ||
|
||||
lowerAction === "changelog" ||
|
||||
lowerAction === "log" ||
|
||||
lowerAction === "history" ||
|
||||
booleanOption(args.options.changelog) === true;
|
||||
|
||||
const isCheck =
|
||||
lowerAction === "check" ||
|
||||
booleanOption(args.options.check) === true ||
|
||||
booleanOption(args.options["check-only"]) === true;
|
||||
|
||||
const isBgSave =
|
||||
booleanOption(args.options["bg-save"]) === true ||
|
||||
booleanOption(args.options["silent-save"]) === true;
|
||||
|
||||
const targetVersion =
|
||||
stringOption(args.options.version) ??
|
||||
stringOption(args.options.tag) ??
|
||||
(!isChangelog && !isCheck && !isBgSave && action && !action.startsWith("-") ? action : undefined);
|
||||
|
||||
await (await import("./commands/update.js")).handleUpdateCommand(runtime, {
|
||||
checkOnly: isCheck || isBgSave,
|
||||
changelogOnly: isChangelog,
|
||||
limit: numberOption(args.options.limit),
|
||||
force: booleanOption(args.options.force),
|
||||
targetVersion,
|
||||
repo: stringOption(args.options.repo),
|
||||
bgSave: isBgSave
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
const args = parseArgs(argv);
|
||||
const [rawArea, action, maybeName] = args.command;
|
||||
const lowerArea = rawArea?.toLowerCase();
|
||||
const isUpdate = lowerArea ? UPDATE_ALIASES.has(lowerArea) : false;
|
||||
const area = isUpdate ? "update" : lowerArea;
|
||||
const area = lowerArea ? normalizeCliArea(lowerArea) : undefined;
|
||||
|
||||
if (
|
||||
area === "version" ||
|
||||
@@ -186,7 +245,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
}
|
||||
|
||||
if (!area || !KNOWN_AREAS.has(area)) {
|
||||
throw new Error(`Unknown command: ${args.command.join(" ")}. Run 'seal-use help' for available commands.`);
|
||||
throw usageError(`Unknown command: ${args.command.join(" ")}. Run 'seal-use help' for available commands.`);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -195,36 +254,11 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
maybeName === "preview"
|
||||
) {
|
||||
const filePath = args.command[3] ?? stringOption(args.options.file) ?? stringOption(args.options.input);
|
||||
if (!filePath) throw new Error("Usage: seal-use webhook resource-pack preview <资源包.zip>");
|
||||
if (!filePath) throw usageError("Usage: seal-use webhook resource-pack preview <资源包.zip>");
|
||||
await (await import("./commands/webhook.js")).handleWebhookResourcePackPreview(filePath, materialPackFilePolicyOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "mcp-config") {
|
||||
(await import("./commands/mcp.js")).printMcpConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "skill") {
|
||||
(await import("./commands/skill.js")).handleSkillCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "mcp" || area === "server") {
|
||||
await (await import("./commands/mcp.js")).handleMcpCommand(action);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "probe") {
|
||||
await (await import("./commands/probe.js")).handleProbeCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "doctor") {
|
||||
await (await import("./commands/doctor.js")).handleDoctorCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
area === "report" &&
|
||||
(action === "validate" ||
|
||||
@@ -239,69 +273,11 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Langfuse trace inspection needs no tenant: it authenticates with the
|
||||
// compile-time injected read-only key pair, so it dispatches before corp
|
||||
// selection (like probe/doctor) and never touches a Seal client.
|
||||
if (area === "langfuse") {
|
||||
await (await import("./commands/langfuse.js")).handleLangfuseCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "test") {
|
||||
await (await import("./commands/test.js")).handleTestCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "config") {
|
||||
(await import("./commands/config.js")).handleConfigCommand(action, maybeName, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isUpdate || area === "changelog") {
|
||||
if (isUpdate && rawArea !== "update") {
|
||||
console.error(`⚠️ Notice: '${rawArea}' is an alias for 'seal-use update'. Please use 'seal-use update' instead.`);
|
||||
}
|
||||
|
||||
const lowerAction = action?.toLowerCase();
|
||||
const isChangelog =
|
||||
area === "changelog" ||
|
||||
lowerAction === "changelog" ||
|
||||
lowerAction === "log" ||
|
||||
lowerAction === "history" ||
|
||||
booleanOption(args.options.changelog) === true;
|
||||
|
||||
const isCheck =
|
||||
lowerAction === "check" ||
|
||||
booleanOption(args.options.check) === true ||
|
||||
booleanOption(args.options["check-only"]) === true;
|
||||
|
||||
const isBgSave =
|
||||
booleanOption(args.options["bg-save"]) === true ||
|
||||
booleanOption(args.options["silent-save"]) === true;
|
||||
|
||||
const targetVersion =
|
||||
stringOption(args.options.version) ??
|
||||
stringOption(args.options.tag) ??
|
||||
(!isChangelog && !isCheck && !isBgSave && action && !action.startsWith("-") ? action : undefined);
|
||||
|
||||
await (await import("./commands/update.js")).handleUpdateCommand(runtime, {
|
||||
checkOnly: isCheck || isBgSave,
|
||||
changelogOnly: isChangelog,
|
||||
limit: numberOption(args.options.limit),
|
||||
force: booleanOption(args.options.force),
|
||||
targetVersion,
|
||||
repo: stringOption(args.options.repo),
|
||||
bgSave: isBgSave
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "corps" || area === "corp") {
|
||||
if (action === "regression" || action === "test-regression") {
|
||||
await (await import("./commands/test.js")).handleTestCommand("regression", maybeName, args);
|
||||
return;
|
||||
}
|
||||
await (await import("./commands/corps.js")).handleCorpsCommand(action, maybeName, args);
|
||||
// These handlers intentionally run before enterprise selection, including
|
||||
// Langfuse's compile-time credentials and purely local discovery commands.
|
||||
const localCommand = LOCAL_COMMANDS[area];
|
||||
if (localCommand) {
|
||||
await localCommand(args, runtime);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -339,102 +315,18 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
|
||||
const corp = (await import("./helpers.js")).selectCorp(stringOption(args.options.corp));
|
||||
|
||||
if (area === "source") {
|
||||
await (await import("./commands/source.js")).handleSourceCommand(action, corp);
|
||||
const corpCommand = CORP_COMMANDS[area];
|
||||
if (corpCommand) {
|
||||
await corpCommand(args, corp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "auth") {
|
||||
await (await import("./commands/auth.js")).handleAuthCommand(action, corp, args);
|
||||
const clientCommand = CLIENT_COMMANDS[area];
|
||||
if (clientCommand) {
|
||||
const client = await (await import("../core/http/factory.js")).createSealClient(corp);
|
||||
await clientCommand(args, corp, client);
|
||||
return;
|
||||
}
|
||||
|
||||
const client = await (await import("../core/http/factory.js")).createSealClient(corp);
|
||||
|
||||
if (area === "users") {
|
||||
await (await import("./commands/users.js")).handleUsersCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "contacts") {
|
||||
await (await import("./commands/contacts.js")).handleContactsCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "data") {
|
||||
await (await import("./commands/data.js")).handleDataCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "llm") {
|
||||
await (await import("./commands/llm.js")).handleLlmCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "permissions") {
|
||||
await (await import("./commands/permissions.js")).handlePermissionsCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "billing") {
|
||||
await (await import("./commands/billing.js")).handleBillingCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "webhook" || area === "webhooks") {
|
||||
await (await import("./commands/webhook.js")).handleWebhookCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "context") {
|
||||
await (await import("./commands/context.js")).handleContextCommand(client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "documents") {
|
||||
await (await import("./commands/documents.js")).handleDocumentsCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "rules") {
|
||||
await (await import("./commands/rules.js")).handleRulesCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "approval-runs") {
|
||||
await (await import("./commands/approval-runs.js")).handleApprovalRunsCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "analytics") {
|
||||
await (await import("./commands/analytics.js")).handleAnalyticsCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "report") {
|
||||
await (await import("./commands/report.js")).handleReportCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "simulation") {
|
||||
await (await import("./commands/simulation.js")).handleSimulationCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "deploy") {
|
||||
await (await import("./commands/deploy.js")).handleDeployCommand(action, maybeName, args.command[3], client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "hose-ebot") {
|
||||
await (await import("./commands/hose-ebot.js")).handleHoseEbotCommand(action, maybeName, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "preference" || area === "preferences") {
|
||||
await (await import("./commands/preference.js")).handlePreferenceCommand(action, maybeName, args.command[3], args.command[4], client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown command: ${args.command.join(" ")}. Run 'seal-use help' for available commands.`);
|
||||
throw usageError(`Unknown command: ${args.command.join(" ")}. Run 'seal-use help' for available commands.`);
|
||||
}
|
||||
Reference in new issue
Block a user