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
@@ -1,335 +0,0 @@
|
||||
import { isDryRun, mutationPreview } from "../mutation.js";
|
||||
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
import { printJson, printTable } from "../printer.js";
|
||||
import { stringOption, booleanOption, numberOption } from "../parser.js";
|
||||
import { createSessionClient } from "../../core/http/session-client.js";
|
||||
import {
|
||||
ApprovalService,
|
||||
ApprovalGatewayBlockedError,
|
||||
FindingCheckStatus,
|
||||
} from "../../domains/approval/index.js";
|
||||
|
||||
export async function handleApprovalCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) {
|
||||
throw new Error(
|
||||
"未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。"
|
||||
);
|
||||
}
|
||||
|
||||
const corpId = corp.corpId || corp.id;
|
||||
|
||||
// 解析命令层级:
|
||||
// 形式 A: hose-use approval audit points S26000001
|
||||
// 形式 B: hose-use approval points S26000001
|
||||
// 形式 C: hose-use approval audit S26000001
|
||||
let subAction = parsed.action?.toLowerCase();
|
||||
let args = [...parsed.args];
|
||||
|
||||
if (subAction === "audit" && args.length > 0) {
|
||||
const candidateSub = args[0]?.toLowerCase();
|
||||
if (["points", "inject", "checklist", "list", "review", "eval", "evaluate", "decide", "approve", "reject"].includes(candidateSub)) {
|
||||
subAction = candidateSub;
|
||||
args.shift();
|
||||
}
|
||||
}
|
||||
|
||||
const targetSn = args[0] || stringOption(parsed.options, ["code", "sn", "target", "id"]);
|
||||
|
||||
if (targetSn && isDryRun(parsed, runtime) && ["audit", "points", "inject", "review", "eval", "evaluate", "decide", "approve", "reject"].includes(subAction || "audit")) {
|
||||
return mutationPreview(parsed, runtime, "预览审批操作", targetSn, { action: subAction || "audit", corpId, apply: booleanOption(parsed.options, ["apply", "execute", "run", "do"]) });
|
||||
}
|
||||
const client = await createSessionClient(corp);
|
||||
const service = new ApprovalService();
|
||||
|
||||
switch (subAction) {
|
||||
// ── 1. 规则注入与出明细级审核要点清单 ─────────────────────────────────────
|
||||
case "points":
|
||||
case "inject": {
|
||||
if (!targetSn) {
|
||||
throw new Error("请提供单号或单据 ID: hose-use approval audit points <单号>");
|
||||
}
|
||||
|
||||
const scopeOption = stringOption(parsed.options, ["scope", "s"]);
|
||||
const result = await service.injectAuditPoints(client, corpId, targetSn, {
|
||||
scope: scopeOption ? (isNaN(Number(scopeOption)) ? scopeOption : Number(scopeOption)) : undefined,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
sn: result.bill.billCode,
|
||||
scope: result.scope,
|
||||
runId: result.run.id,
|
||||
count: result.findings.length,
|
||||
findings: result.findings,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const headers = ["#", "严格程度", "归属规则", "审核要点内容", "核验状态"];
|
||||
const rows = result.findings.map((f, i) => [
|
||||
i + 1,
|
||||
`[${f.strictness}]`,
|
||||
f.ruleCode ? `#${f.ruleCode}` : "-",
|
||||
f.clauseText,
|
||||
f.checkStatus,
|
||||
]);
|
||||
|
||||
const table = printTable(headers, rows);
|
||||
const title = `====== 单据 ${result.bill.billCode} 明细级审核要点清单 (场景: ${result.scope} | 共 ${result.findings.length} 条要点) ======\n`;
|
||||
const tip =
|
||||
`\n[要点注入完成] 审核要点已固化至审批实例,审批链路已激活!\n` +
|
||||
`下一步: 请对要点进行事实核验判定: hose-use approval audit review ${result.bill.billCode} --eval "1=PASS; 2=FAIL:证据说明; ..."\n` +
|
||||
`完成核验后,由确定性网关仲裁审批: hose-use approval audit decide ${result.bill.billCode} --apply --yes\n`;
|
||||
|
||||
return {
|
||||
stdout: title + table + tip,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ── 2. 查看当前审核要点清单与核验状态 ─────────────────────────────────────
|
||||
case "checklist":
|
||||
case "list":
|
||||
case "status": {
|
||||
if (!targetSn) {
|
||||
throw new Error("请提供单号或单据 ID: hose-use approval audit checklist <单号>");
|
||||
}
|
||||
|
||||
const { run, findings } = service.getAuditChecklist(targetSn, corpId);
|
||||
if (!run || findings.length === 0) {
|
||||
const errorMsg =
|
||||
`[审批链路阻断] 单据 [${targetSn}] 尚未注入任何明细级审核要点(要点列表为空)!\n` +
|
||||
`审批链路当前物理不通!请先执行: hose-use approval audit points ${targetSn} 注入审核要点清单。\n`;
|
||||
return { stdout: "", stderr: errorMsg, exitCode: 1 };
|
||||
}
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ run, findings }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const headers = ["#", "严格程度", "规则", "审核要点内容", "核验状态", "事实证据 / 推理说明"];
|
||||
const rows = findings.map((f, i) => [
|
||||
i + 1,
|
||||
`[${f.strictness}]`,
|
||||
f.ruleCode ? `#${f.ruleCode}` : "-",
|
||||
f.clauseText,
|
||||
f.checkStatus === "PASS" ? "✅ PASS" : f.checkStatus === "FAIL" ? "❌ FAIL" : f.checkStatus === "SKIP" ? "➖ SKIP" : "⏳ PENDING",
|
||||
[f.evidence, f.reasoning].filter(Boolean).join(" | ") || "-",
|
||||
]);
|
||||
|
||||
const table = printTable(headers, rows);
|
||||
const pendingCount = findings.filter((f) => f.checkStatus === "PENDING").length;
|
||||
const title = `====== 单据 ${targetSn} 审核要点核验进度 (总计: ${findings.length} | 待核验: ${pendingCount} | 运行决策: ${run.decision}) ======\n`;
|
||||
|
||||
return {
|
||||
stdout: title + table,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ── 3. 逐项核验事实打标 ──────────────────────────────────────────────────
|
||||
case "review":
|
||||
case "eval":
|
||||
case "evaluate": {
|
||||
if (!targetSn) {
|
||||
throw new Error("请提供单号: hose-use approval audit review <单号> --eval '...'");
|
||||
}
|
||||
|
||||
const evalStr = stringOption(parsed.options, ["eval", "findings", "data", "e"]);
|
||||
const pointIndex = numberOption(parsed.options, ["point", "p", "index", "i"], 0);
|
||||
const statusInput = stringOption(parsed.options, ["status", "state"])?.toUpperCase() as FindingCheckStatus | undefined;
|
||||
const evidence = stringOption(parsed.options, ["evidence", "proof"]);
|
||||
const reasoning = stringOption(parsed.options, ["reasoning", "reason", "r"]);
|
||||
|
||||
const updates: Array<{
|
||||
index?: number;
|
||||
id?: string;
|
||||
status: FindingCheckStatus;
|
||||
evidence?: string;
|
||||
reasoning?: string;
|
||||
}> = [];
|
||||
|
||||
if (typeof pointIndex === "number" && pointIndex > 0 && statusInput) {
|
||||
updates.push({
|
||||
index: pointIndex,
|
||||
status: statusInput,
|
||||
evidence,
|
||||
reasoning,
|
||||
});
|
||||
} else if (evalStr) {
|
||||
// 解析便捷语法: "1=FAIL:未上传发票; 2=PASS; 3=SKIP; 4=FAIL:大连住宿超标且无特批"
|
||||
const segments = evalStr.split(";").map((s) => s.trim()).filter(Boolean);
|
||||
for (const seg of segments) {
|
||||
const match = seg.match(/^(\d+)\s*=\s*(PASS|FAIL|SKIP)(?::(.*))?$/i);
|
||||
if (match) {
|
||||
const idx = parseInt(match[1], 10);
|
||||
const status = match[2].toUpperCase() as FindingCheckStatus;
|
||||
const desc = match[3]?.trim();
|
||||
updates.push({
|
||||
index: idx,
|
||||
status,
|
||||
evidence: desc,
|
||||
reasoning: desc,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updates.length === 0) {
|
||||
throw new Error(
|
||||
`请提供核验判定参数,例如:\n` +
|
||||
` hose-use approval audit review ${targetSn} --eval "1=PASS; 2=FAIL:未上传特批邮件; 3=SKIP"\n` +
|
||||
` 或: hose-use approval audit review ${targetSn} --point 2 --status FAIL --reason "缺少特批邮件"`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedFindings = service.evaluateAuditPoints(targetSn, updates, corpId);
|
||||
const headers = ["#", "严格程度", "审核要点内容", "核验状态", "事实证据与说明"];
|
||||
const rows = updatedFindings.map((f, i) => [
|
||||
i + 1,
|
||||
`[${f.strictness}]`,
|
||||
f.clauseText,
|
||||
f.checkStatus === "PASS" ? "✅ PASS" : f.checkStatus === "FAIL" ? "❌ FAIL" : f.checkStatus === "SKIP" ? "➖ SKIP" : "⏳ PENDING",
|
||||
[f.evidence, f.reasoning].filter(Boolean).join(" | ") || "-",
|
||||
]);
|
||||
|
||||
const table = printTable(headers, rows);
|
||||
const pendingCount = updatedFindings.filter((f) => f.checkStatus === "PENDING").length;
|
||||
const msg =
|
||||
`====== 单据 ${targetSn} 核验判定已更新 (待核验剩余: ${pendingCount} 项) ======\n` +
|
||||
table +
|
||||
(pendingCount === 0
|
||||
? `\n[核验全部闭环] 所有要点已完成事实核验!可运行确定性网关仲裁: hose-use approval audit decide ${targetSn} --apply --yes\n`
|
||||
: `\n[待续] 尚有 ${pendingCount} 项处于 PENDING,请继续核验。\n`);
|
||||
|
||||
return { stdout: msg, stderr: "", exitCode: 0 };
|
||||
} catch (err: any) {
|
||||
if (err instanceof ApprovalGatewayBlockedError) {
|
||||
return { stdout: "", stderr: `${err.message}\n`, exitCode: 1 };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 4. 确定性网关仲裁与审批决断 ──────────────────────────────────────────
|
||||
case "decide":
|
||||
case "approve":
|
||||
case "reject": {
|
||||
if (!targetSn) {
|
||||
throw new Error("请提供单号: hose-use approval audit decide <单号> [--apply] [--yes]");
|
||||
}
|
||||
|
||||
const apply = booleanOption(parsed.options, ["apply", "execute", "run", "do"]);
|
||||
if (apply) {
|
||||
const confirmed = booleanOption(parsed.options, ["yes", "y", "confirm"]);
|
||||
if (!confirmed) {
|
||||
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
||||
throw new Error("开启 --apply 会真实改变单据流转状态,请显式添加 --yes 确认。");
|
||||
}
|
||||
const { prompt } = await import("../helpers.js");
|
||||
const ans = await prompt("网关将向合思系统真实执行审批/驳回/留痕,确认继续?输入 yes: ");
|
||||
if (!/^(y|yes|是)$/i.test(ans.trim())) throw new Error("已取消审批操作");
|
||||
}
|
||||
}
|
||||
|
||||
const requestedAction = subAction === "approve" ? "approve" : subAction === "reject" ? "reject" : (stringOption(parsed.options, ["action"]) as any);
|
||||
const userComment = stringOption(parsed.options, ["comment", "message", "m"]);
|
||||
|
||||
try {
|
||||
const decisionResult = await service.decideAudit(client, corpId, targetSn, {
|
||||
requestedAction,
|
||||
apply,
|
||||
comment: userComment,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(decisionResult, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const outLines: string[] = [];
|
||||
outLines.push(`\n====== 合思 AI 确定性网关仲裁裁决书 (单号: ${targetSn}) ======`);
|
||||
outLines.push(`网关决策 : ${decisionResult.decision}`);
|
||||
outLines.push(`违规统计 : 硬性 ${decisionResult.hardFailedCount} 项 | 弹性 ${decisionResult.elasticFailedCount} 项 | 建议 ${decisionResult.suggestFailedCount} 项 | 特殊 ${decisionResult.specialFailedCount} 项`);
|
||||
if (apply) {
|
||||
outLines.push(`下游动作 : 已安全执行 [${decisionResult.appliedAction}] 动作`);
|
||||
} else {
|
||||
outLines.push(`执行模式 : 预审仿真 (Dry Run)。若需执行下游审批流转,请追加 --apply --yes`);
|
||||
}
|
||||
outLines.push(`\n--- 审计意见文本快照 ---\n${decisionResult.decisionSummary}\n`);
|
||||
|
||||
return {
|
||||
stdout: outLines.join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
} catch (err: any) {
|
||||
if (err instanceof ApprovalGatewayBlockedError) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `\n${err.message}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 5. 缺省:智能引导 (未注入则出要点,已注入则显示清单) ─────────────────────
|
||||
case "audit":
|
||||
case undefined: {
|
||||
if (!targetSn) {
|
||||
return {
|
||||
stdout:
|
||||
`====== 合思 AI 确定性审批网关 (hose-use approval) ======\n` +
|
||||
`用法:\n` +
|
||||
` 1. 出明细级审核要点 (规则注入) : hose-use approval audit points <单号> [--scope <场景>]\n` +
|
||||
` 2. 查看当前审核要点清单 : hose-use approval audit checklist <单号>\n` +
|
||||
` 3. 逐项录入事实核验判定 : hose-use approval audit review <单号> --eval "1=PASS; 2=FAIL:说明"\n` +
|
||||
` 4. 网关确定性仲裁与执行审批 : hose-use approval audit decide <单号> [--apply] [--yes]\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 检查当前是否已注入要点
|
||||
const { run } = service.getAuditChecklist(targetSn, corpId);
|
||||
if (!run) {
|
||||
// 自动触发第一步:注入并出审核要点
|
||||
return await handleApprovalCommand(
|
||||
{ ...parsed, action: "points", args: [targetSn] },
|
||||
runtime
|
||||
);
|
||||
} else {
|
||||
// 已有要点,展示清单与进度
|
||||
return await handleApprovalCommand(
|
||||
{ ...parsed, action: "checklist", args: [targetSn] },
|
||||
runtime
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`未知的审批网关动作: ${subAction}。请运行 hose-use approval audit 查看帮助。`);
|
||||
}
|
||||
}
|
||||
@@ -79,13 +79,14 @@ describe("CLI - 上下文自省与 AI PRO 状态命令 (Zero-Source-Reading Cont
|
||||
expect(data.sessions).toBeDefined();
|
||||
});
|
||||
|
||||
test("hose-use aipro status 双向桥接成功转发", async () => {
|
||||
test("hose-use aipro status 管理本机 aipro 守护进程状态", async () => {
|
||||
const res = await runCli(["aipro", "status", "--json"]);
|
||||
expect(res.exitCode).toBe(0);
|
||||
|
||||
const data = JSON.parse(res.stdout);
|
||||
expect(data.tool).toBe("hose-aipro");
|
||||
expect(data.ruleEngine.scopesCount).toBe(2);
|
||||
expect(data.serviceName).toBe("hose-aipro");
|
||||
expect(data.port).toBe(8889);
|
||||
expect(data.running).toBe(false);
|
||||
});
|
||||
|
||||
test("hose-aipro 帮助页在顶部动态展示当前企业页眉", async () => {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { expect, spyOn, test } from "bun:test";
|
||||
import * as service from "../service.js";
|
||||
import { parseArgs } from "../parser.js";
|
||||
import { handleServiceCommand } from "./service.js";
|
||||
import {
|
||||
handleServiceCommand,
|
||||
handleAiProServiceCommand,
|
||||
handleApprovalRedirectCommand,
|
||||
} from "./service.js";
|
||||
|
||||
test("service lifecycle previews never dispatch process or state mutations", async () => {
|
||||
const dispatch = spyOn(service, "runServiceCommand").mockResolvedValue({ running: false } as any);
|
||||
try {
|
||||
@@ -13,5 +18,19 @@ test("service lifecycle previews never dispatch process or state mutations", asy
|
||||
expect(dispatch).not.toHaveBeenCalled();
|
||||
await handleServiceCommand(parseArgs(["service", "status"]), { jsonMode: true } as any);
|
||||
expect(dispatch).toHaveBeenCalledTimes(1);
|
||||
|
||||
// hose-use aipro status
|
||||
await handleAiProServiceCommand(parseArgs(["aipro", "status"]), { jsonMode: true } as any);
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
|
||||
// hose-use aipro bind 重定向阻断提示
|
||||
const bindRedirect = await handleAiProServiceCommand(parseArgs(["aipro", "bind", "S123"]), { jsonMode: true } as any);
|
||||
expect(bindRedirect.exitCode).toBe(1);
|
||||
expect(bindRedirect.stderr).toContain("hose-aipro");
|
||||
|
||||
// hose-use approval 重定向提示
|
||||
const approvalRedirect = await handleApprovalRedirectCommand(parseArgs(["approval", "decide", "S123"]), { jsonMode: true } as any);
|
||||
expect(approvalRedirect.exitCode).toBe(1);
|
||||
expect(approvalRedirect.stderr).toContain("hose-aipro");
|
||||
} finally { dispatch.mockRestore(); }
|
||||
});
|
||||
+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,
|
||||
};
|
||||
}
|
||||
+97
-29
@@ -1,10 +1,15 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
EMBEDDED_SKILL_FILES,
|
||||
EMBEDDED_HOSE_USE_SKILL_FILES,
|
||||
EMBEDDED_AIPRO_SKILL_FILES,
|
||||
getDefaultGlobalSkillDir,
|
||||
getDefaultAiProGlobalSkillDir,
|
||||
getSkillContent,
|
||||
getAiProSkillContent,
|
||||
installSkillFiles,
|
||||
installHoseUseSkillFiles,
|
||||
installAiProSkillFiles,
|
||||
} from "../../packaging/embedded-skill.js";
|
||||
import { booleanOption, stringOption } from "../parser.js";
|
||||
import { printJson, printKeyValue } from "../printer.js";
|
||||
@@ -16,13 +21,16 @@ export async function handleSkillCommand(
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const action = parsed.action || "status";
|
||||
const isAiProCaller =
|
||||
parsed.area === "hose-aipro" ||
|
||||
parsed.raw.some((arg) => arg.includes("hose-aipro") || arg === "aipro");
|
||||
|
||||
switch (action) {
|
||||
case "dump":
|
||||
case "cat":
|
||||
case "show":
|
||||
return {
|
||||
stdout: `${getSkillContent()}\n`,
|
||||
stdout: `${isAiProCaller ? getAiProSkillContent() : getSkillContent()}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -36,30 +44,71 @@ export async function handleSkillCommand(
|
||||
const customDir =
|
||||
stringOption(parsed.options, ["dir", "target"]) || parsed.args[0];
|
||||
|
||||
const targetDir = customDir
|
||||
? customDir
|
||||
: isLocal
|
||||
? join(process.cwd(), ".agents", "skills", "hose-use")
|
||||
: getDefaultGlobalSkillDir();
|
||||
const globalHoseDir = getDefaultGlobalSkillDir();
|
||||
const globalAiProDir = getDefaultAiProGlobalSkillDir();
|
||||
const localHoseDir = join(process.cwd(), ".agents", "skills", "hose-use");
|
||||
const localAiProDir = join(process.cwd(), ".agents", "skills", "hose-aipro");
|
||||
|
||||
const targetPolicy = customDir ? "explicit" : isLocal ? "workspace" : "global-canonical";
|
||||
const totalFiles =
|
||||
Object.keys(EMBEDDED_HOSE_USE_SKILL_FILES).length +
|
||||
Object.keys(EMBEDDED_AIPRO_SKILL_FILES).length;
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "安装 Agent Skill 文件", targetDir, {
|
||||
fileCount: Object.keys(EMBEDDED_SKILL_FILES).length,
|
||||
local: isLocal,
|
||||
targetPolicy: customDir ? "explicit" : isLocal ? "workspace" : "global-canonical",
|
||||
});
|
||||
return mutationPreview(
|
||||
parsed,
|
||||
runtime,
|
||||
"安装 Agent Skill 文件 (hose-use 与 hose-aipro)",
|
||||
customDir || (isLocal ? `${localHoseDir} & ${localAiProDir}` : `${globalHoseDir} & ${globalAiProDir}`),
|
||||
{
|
||||
fileCount: totalFiles,
|
||||
local: isLocal,
|
||||
targetPolicy,
|
||||
skills: ["hose-use", "hose-aipro"],
|
||||
}
|
||||
);
|
||||
}
|
||||
requireMutationConfirmation(parsed, runtime, "安装 Agent Skill 文件", `hose-use skill install${customDir ? ` --dir=${customDir}` : ""} --yes`);
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
"安装 Agent Skill 文件",
|
||||
`${isAiProCaller ? "hose-aipro" : "hose-use"} skill install${customDir ? ` --dir=${customDir}` : ""} --yes`
|
||||
);
|
||||
|
||||
const result = installSkillFiles(targetDir);
|
||||
let installedReport: { targetDirs: string[]; filesCount: number; skills: string[] };
|
||||
|
||||
if (customDir) {
|
||||
const res = installSkillFiles(customDir);
|
||||
installedReport = {
|
||||
targetDirs: [res.targetDir],
|
||||
filesCount: res.files.length,
|
||||
skills: ["hose-use"],
|
||||
};
|
||||
} else if (isLocal) {
|
||||
const hoseRes = installHoseUseSkillFiles(localHoseDir);
|
||||
const aiproRes = installAiProSkillFiles(localAiProDir);
|
||||
installedReport = {
|
||||
targetDirs: [hoseRes.targetDir, aiproRes.targetDir],
|
||||
filesCount: hoseRes.files.length + aiproRes.files.length,
|
||||
skills: ["hose-use", "hose-aipro"],
|
||||
};
|
||||
} else {
|
||||
const hoseRes = installHoseUseSkillFiles(globalHoseDir);
|
||||
const aiproRes = installAiProSkillFiles(globalAiProDir);
|
||||
installedReport = {
|
||||
targetDirs: [hoseRes.targetDir, aiproRes.targetDir],
|
||||
filesCount: hoseRes.files.length + aiproRes.files.length,
|
||||
skills: ["hose-use", "hose-aipro"],
|
||||
};
|
||||
}
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({
|
||||
installed: true,
|
||||
targetDir: result.targetDir,
|
||||
fileCount: result.files.length,
|
||||
files: result.files,
|
||||
targetDirs: installedReport.targetDirs,
|
||||
fileCount: installedReport.filesCount,
|
||||
skills: installedReport.skills,
|
||||
}),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
@@ -67,7 +116,10 @@ export async function handleSkillCommand(
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `[SUCCESS] hose-use 技能已成功安装至: ${result.targetDir}\n包含文件: ${result.files.join(", ")}\n`,
|
||||
stdout:
|
||||
`[SUCCESS] Agent 技能已成功安装:\n` +
|
||||
installedReport.targetDirs.map((d) => ` • ${d}`).join("\n") +
|
||||
`\n共 ${installedReport.filesCount} 个文件。\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -75,17 +127,31 @@ export async function handleSkillCommand(
|
||||
|
||||
case "status":
|
||||
case "get": {
|
||||
const globalDir = getDefaultGlobalSkillDir();
|
||||
const localDir = join(process.cwd(), ".agents", "skills", "hose-use");
|
||||
const globalHoseDir = getDefaultGlobalSkillDir();
|
||||
const globalAiProDir = getDefaultAiProGlobalSkillDir();
|
||||
const localHoseDir = join(process.cwd(), ".agents", "skills", "hose-use");
|
||||
const localAiProDir = join(process.cwd(), ".agents", "skills", "hose-aipro");
|
||||
|
||||
const statusObj = {
|
||||
global: {
|
||||
dir: globalDir,
|
||||
installed: existsSync(join(globalDir, "SKILL.md")),
|
||||
"hose-use": {
|
||||
global: {
|
||||
dir: globalHoseDir,
|
||||
installed: existsSync(join(globalHoseDir, "SKILL.md")),
|
||||
},
|
||||
local: {
|
||||
dir: localHoseDir,
|
||||
installed: existsSync(join(localHoseDir, "SKILL.md")),
|
||||
},
|
||||
},
|
||||
local: {
|
||||
dir: localDir,
|
||||
installed: existsSync(join(localDir, "SKILL.md")),
|
||||
"hose-aipro": {
|
||||
global: {
|
||||
dir: globalAiProDir,
|
||||
installed: existsSync(join(globalAiProDir, "SKILL.md")),
|
||||
},
|
||||
local: {
|
||||
dir: localAiProDir,
|
||||
installed: existsSync(join(localAiProDir, "SKILL.md")),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -94,12 +160,14 @@ export async function handleSkillCommand(
|
||||
}
|
||||
|
||||
const output = printKeyValue({
|
||||
"全局 Skill 目录": `${globalDir} [${statusObj.global.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
"本地 Skill 目录": `${localDir} [${statusObj.local.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
"hose-use (全局)": `${globalHoseDir} [${statusObj["hose-use"].global.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
"hose-aipro (全局)": `${globalAiProDir} [${statusObj["hose-aipro"].global.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
"hose-use (本地)": `${localHoseDir} [${statusObj["hose-use"].local.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
"hose-aipro (本地)": `${localAiProDir} [${statusObj["hose-aipro"].local.installed ? "已安装 ✅" : "未安装 ❌"}]`,
|
||||
});
|
||||
|
||||
return {
|
||||
stdout: `====== Agent Skill 状态 ======\n${output}\n\n提示: 运行 hose-use skill install --yes 进行全局安装\n`,
|
||||
stdout: `====== Agent Skill 状态 ======\n${output}\n\n提示: 运行 ${isAiProCaller ? "hose-aipro" : "hose-use"} skill install --yes 进行全局安装\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user