refactor: 全面转向 CLI 驱动架构与底层 SDK,裁撤繁杂 MCP 工具并参考 seal-home 规范

This commit is contained in:
gitea committed 2026-08-27 10:56:45 +08:00
1 parent 3d549e2e2f
commit e7aa8a86cc
19 files changed
+1228 -589

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import { VERSION } from "../version.js";
import { parseArgs, stringOption, booleanOption } from "./parser.js";
import { printHelp, printJson } from "./printer.js";
import { initCorpRuntime } from "./helpers.js";
import { handleAuthCommand } from "./commands/auth.js";
import { handleCorpsCommand } from "./commands/corps.js";
import { handleWorkflowCommand } from "./commands/workflow.js";
import { handlePlatformCommand } from "./commands/platform.js";
import { handleProbeCommand } from "./commands/probe.js";
import { handleMcpCommand } from "./commands/mcp.js";
import type { CliResult, CliRunOptions } from "./types.js";
export async function runCli(
rawArgs: string[],
options: CliRunOptions = {}
): Promise<CliResult> {
const parsed = parseArgs(rawArgs);
if (booleanOption(parsed.options, ["help", "h"]) || parsed.area === "help") {
return { stdout: printHelp() + "\n", stderr: "", exitCode: 0 };
}
if (booleanOption(parsed.options, ["version", "v"]) || parsed.area === "version") {
return { stdout: `hose v${VERSION}\n`, stderr: "", exitCode: 0 };
}
const jsonMode = booleanOption(parsed.options, ["json", "j"]);
const corpIdOption = stringOption(parsed.options, ["corp", "c"]);
const runtime = initCorpRuntime(corpIdOption, jsonMode);
try {
switch (parsed.area) {
case "auth":
case "login":
return await handleAuthCommand(parsed, runtime);
case "corps":
case "corp":
return await handleCorpsCommand(parsed, runtime);
case "workflow":
case "workflows":
case "wf":
return await handleWorkflowCommand(parsed, runtime);
case "platform":
case "platforms":
case "app":
case "apps":
return await handlePlatformCommand(parsed, runtime);
case "probe":
case "check":
case "diagnose":
return await handleProbeCommand(parsed, runtime);
case "mcp":
case "serve":
return await handleMcpCommand(parsed, options);
case undefined:
return { stdout: printHelp() + "\n", stderr: "", exitCode: 0 };
default:
return {
stdout: "",
stderr: `未知命令域: ${parsed.area}。运行 hose --help 查看帮助\n`,
exitCode: 1,
};
}
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
if (jsonMode) {
return {
stdout: printJson({ error: true, message: errorMsg }),
stderr: "",
exitCode: 1,
};
}
return {
stdout: "",
stderr: `[ERROR] ${errorMsg}\n`,
exitCode: 1,
};
}
}