feat(cli): 分离 hose-aipro 独立命令体系并升级至 v0.9.0
1. 架构对称性与声明式注册表抽取:
- 新增 src/cli/aipro-registry.ts,声明式定义 AIPRO_COMMAND_REGISTRY 及其别名映射与 mutating 突变检查
- 重构 src/aipro-cli.ts,移除过程式 switch-case 分发,改为查表式声明分发,与 hose-use 的 CLI_COMMAND_REGISTRY 保持 100% 对称
- 在 src/cli/registry.ts 统一重导出 aipro-registry,巩固其作为顶层声明注册表的单一事实源地位
- 增加 aipro-cli 测试用例,强制校验 COMMAND_METADATA["hose-aipro"] 与声明式注册表双向一致性
2. 双 Skill 独立打包与内嵌部署:
- 注册两个独立技能:skills/hose-use 与 skills/hose-aipro,互相关联引用
- src/packaging/embedded-skill.ts 增加双 Skill 编译期嵌入与 installSkillFiles 全量同步
- hose-use / hose-aipro 下的 skill status/dump/install 完全对齐
3. 守护服务交叉治理:
- src/cli/service.ts 支持 ServiceTargetName ("hose-use" | "hose-aipro"),默认端口 8888 与 8889
- 支持 hose-use aipro <start|stop|...> 与 hose-aipro hose-use <start|stop|...> 双向服务纳管
- 误触非本领域业务命令时提供友好互导拦截
4. 审批领域数据层防御加固:
- 迁移 004:approval_runs 增加 short_id 唯一约束
- 增加 allocateUniqueShortId 冲突重试,多步写操作纳入事务
5. 版本升级至 v0.9.0:
- package.json、README.md、specs、.zcode-plugin 及两套 Skill 同步更新至 0.9.0
- bump-version 脚本适配多 Skill 自动递增
This commit is contained in:
1 parent
c3e39fe77a
commit
362acfba58
38 files changed
+1380
-690
No files matched your search
+100
-21
@@ -1,8 +1,14 @@
|
||||
import { isDryRun, mutationPreview } from "../mutation.js";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { VERSION } from "../../version.js";
|
||||
import { runServiceCommand, ServiceConfig, getPidFile, getLogFile } from "../service.js";
|
||||
import {
|
||||
runServiceCommand,
|
||||
getHoseUseServiceConfig,
|
||||
getAiProServiceConfig,
|
||||
getPidFile,
|
||||
getLogFile,
|
||||
SERVICE_STATE_DIR,
|
||||
type ServiceConfig,
|
||||
type ServiceTargetName,
|
||||
} from "../service.js";
|
||||
import { printJson, printKeyValue } from "../printer.js";
|
||||
import { numberOption, stringOption } from "../parser.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
@@ -10,13 +16,30 @@ import { createSessionClient } from "../../core/http/session-client.js";
|
||||
import { EventStore } from "../../domains/events/store.js";
|
||||
import { pollEvents } from "../../domains/events/poller.js";
|
||||
|
||||
export const SERVICE_STATE_DIR = process.env.HOSE_STATE_DIR || join(homedir(), ".config", "hose-use");
|
||||
export { SERVICE_STATE_DIR };
|
||||
|
||||
export async function handleServiceCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
runtime: CliRuntime,
|
||||
forcedTarget?: ServiceTargetName
|
||||
): Promise<CliResult> {
|
||||
const action = parsed.action || parsed.args[0] || "status";
|
||||
const firstPos = (parsed.action || parsed.args[0] || "").toLowerCase();
|
||||
const secondPos = (parsed.args[0] || parsed.args[1] || "").toLowerCase();
|
||||
|
||||
let target: ServiceTargetName = forcedTarget || "hose-use";
|
||||
let action = parsed.action || parsed.args[0] || "status";
|
||||
|
||||
// 支持 hose-use service aipro <start|stop|status>
|
||||
if (!forcedTarget) {
|
||||
if (firstPos === "aipro" || firstPos === "hose-aipro") {
|
||||
target = "hose-aipro";
|
||||
action = secondPos || "status";
|
||||
} else if (firstPos === "hose-use" || firstPos === "hose") {
|
||||
target = "hose-use";
|
||||
action = secondPos || "status";
|
||||
}
|
||||
}
|
||||
|
||||
const port = numberOption(parsed.options, ["port", "p"]);
|
||||
const host = stringOption(parsed.options, ["host", "h"]);
|
||||
|
||||
@@ -30,22 +53,34 @@ export async function handleServiceCommand(
|
||||
const store = new EventStore(stateFile || `corp:${corpId}`);
|
||||
const result = await pollEvents(client, corpId, store, limit);
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
return { stdout: `====== 事件轮询 (企业: ${corp.name}) ======\n${printKeyValue({ "待办扫描": result.scanned.todo, "未读消息扫描": result.scanned.messages, "新增事件": result.newEvents.length, "重复事件": result.duplicateCount, "存储后端": stateFile || "SQLite (observed_events)" })}\n`, stderr: "", exitCode: 0 };
|
||||
return {
|
||||
stdout: `====== 事件轮询 (企业: ${corp.name}) ======\n${printKeyValue({
|
||||
"待办扫描": result.scanned.todo,
|
||||
"未读消息扫描": result.scanned.messages,
|
||||
"新增事件": result.newEvents.length,
|
||||
"重复事件": result.duplicateCount,
|
||||
"存储后端": stateFile || "SQLite (observed_events)",
|
||||
})}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const config: ServiceConfig = {
|
||||
appRoot: runtime.appRoot || process.cwd(),
|
||||
entryFile: runtime.entryFile || join(runtime.appRoot || process.cwd(), "src", "cli.ts"),
|
||||
stateDir: SERVICE_STATE_DIR,
|
||||
version: VERSION,
|
||||
launcher: runtime.launcher,
|
||||
port,
|
||||
host,
|
||||
};
|
||||
const config: ServiceConfig =
|
||||
target === "hose-aipro"
|
||||
? getAiProServiceConfig(runtime, { port, host })
|
||||
: getHoseUseServiceConfig(runtime, { port, host });
|
||||
|
||||
if (["start", "stop", "restart", "run"].includes(action) && isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "管理 hose-use 服务", action, { action, port, host, stateDir: config.stateDir });
|
||||
return mutationPreview(
|
||||
parsed,
|
||||
runtime,
|
||||
`管理 ${config.serviceName} 服务`,
|
||||
action,
|
||||
{ action, port, host, stateDir: config.stateDir }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await runServiceCommand(action, config);
|
||||
|
||||
if (result === undefined) {
|
||||
@@ -60,7 +95,7 @@ export async function handleServiceCommand(
|
||||
if (action === "logs" || action === "log") {
|
||||
const logsResult = result as { logFile: string; lines: string[]; content: string };
|
||||
return {
|
||||
stdout: `====== hose-use 守护进程日志 (${logsResult.logFile}) ======\n${logsResult.content}\n`,
|
||||
stdout: `====== ${config.serviceName} 守护进程日志 (${logsResult.logFile}) ======\n${logsResult.content}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -73,7 +108,7 @@ export async function handleServiceCommand(
|
||||
"服务状态": isRunning ? "🟢 正在运行 (Running)" : "⚪ 已停止 (Stopped)",
|
||||
...(status.pid ? { "进程 PID": status.pid } : {}),
|
||||
...(status.url ? { "服务地址": status.url } : {}),
|
||||
...(status.url ? { "交互式文档": `${status.url}/docs` } : {}),
|
||||
...(target === "hose-use" && status.url ? { "交互式文档": `${status.url}/docs` } : {}),
|
||||
...(status.url ? { "CLI 网关": `POST ${status.url}/api/cli` } : {}),
|
||||
"运行版本": status.version || config.version,
|
||||
"状态目录": status.stateDir || config.stateDir,
|
||||
@@ -81,10 +116,54 @@ export async function handleServiceCommand(
|
||||
"日志文件": status.logFile || getLogFile(config),
|
||||
};
|
||||
|
||||
const title = (status.serviceTitle as string) || config.serviceTitle || "常驻服务管理 (Service)";
|
||||
const formatted = printKeyValue(displayPairs);
|
||||
return {
|
||||
stdout: `====== hose-use 常驻服务管理 (Service) ======\n${formatted}\n`,
|
||||
stdout: `====== ${title} ======\n${formatted}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
export async function handleAiProServiceCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const action = (parsed.action || parsed.args[0] || "status").toLowerCase();
|
||||
const serviceActions = ["start", "stop", "restart", "status", "logs", "log", "run"];
|
||||
|
||||
if (!serviceActions.includes(action)) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr:
|
||||
`[提示] AI PRO 确定性审批仲裁命令已完全独立为 hose-aipro 命令行。\n` +
|
||||
`请直接运行: hose-aipro ${action} ${parsed.args.join(" ")}\n\n` +
|
||||
`如需管理本机的 AI PRO 网关常驻服务,请运行:\n` +
|
||||
` hose-use aipro <start|stop|restart|status|logs>\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
return handleServiceCommand(parsed, runtime, "hose-aipro");
|
||||
}
|
||||
|
||||
export async function handleApprovalRedirectCommand(
|
||||
parsed: CliParsedArgs,
|
||||
_runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const action = parsed.action || parsed.args[0] || "";
|
||||
const subArgs = parsed.args.slice(1).join(" ");
|
||||
return {
|
||||
stdout: "",
|
||||
stderr:
|
||||
`[提示] 确定性审批仲裁命令已独立为 hose-aipro 命令行。\n` +
|
||||
`请直接运行: hose-aipro ${action}${subArgs ? ` ${subArgs}` : ""}\n\n` +
|
||||
`常用命令推荐:\n` +
|
||||
` • 查看要点: hose-aipro points <单号>\n` +
|
||||
` • 事实证据核验: hose-aipro review <单号> --findings='[...]'\n` +
|
||||
` • 执行审批仲裁: hose-aipro decide <单号> --apply --yes\n` +
|
||||
` • 审批日志溯源: hose-aipro logs <单号>\n` +
|
||||
` • 网关服务启停: hose-use aipro <start|stop|status>\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user