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 自动递增
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import { booleanOption } from "./parser.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "./types.js";
|
|
import { CliError } from "./errors.js";
|
|
|
|
/**
|
|
* All mutating CLI commands use the same two-step contract:
|
|
* 1. --dry-run only describes the intended change;
|
|
* 2. --yes/--confirm is required before the real operation runs.
|
|
*
|
|
* The parsed-argument fallback keeps command handlers easy to unit-test without
|
|
* requiring every hand-built CliRuntime to include the newer fields.
|
|
*/
|
|
export class MutationConfirmationRequired extends CliError {
|
|
readonly operation: string;
|
|
|
|
constructor(operation: string, nextAction: string) {
|
|
super(
|
|
`拒绝执行${operation}:该操作会改变数据。请先使用 --dry-run 预览,确认后追加 --yes(或 --confirm)。`,
|
|
10,
|
|
nextAction
|
|
);
|
|
this.name = "MutationConfirmationRequired";
|
|
this.operation = operation;
|
|
}
|
|
}
|
|
|
|
export function isDryRun(parsed: CliParsedArgs, runtime: CliRuntime): boolean {
|
|
return (Object.hasOwn(runtime, "dryRun") && runtime.dryRun === true) || booleanOption(parsed.options, ["dry-run", "dryRun", "dryrun"]);
|
|
}
|
|
|
|
export function isConfirmed(parsed: CliParsedArgs, runtime: CliRuntime): boolean {
|
|
return (
|
|
(Object.hasOwn(runtime, "confirmed") && runtime.confirmed === true) ||
|
|
booleanOption(parsed.options, ["yes", "y", "confirm", "force-write"])
|
|
);
|
|
}
|
|
|
|
export function requireMutationConfirmation(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime,
|
|
operation: string,
|
|
nextAction: string
|
|
): void {
|
|
if (isDryRun(parsed, runtime) || isConfirmed(parsed, runtime)) return;
|
|
throw new MutationConfirmationRequired(operation, nextAction);
|
|
}
|
|
|
|
export function mutationPreview(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime,
|
|
operation: string,
|
|
target: string,
|
|
changes: Record<string, unknown>
|
|
): CliResult {
|
|
const confirmedArgs = parsed.raw.filter((arg) => !["--dry-run", "--dryRun", "--dryrun"].includes(arg));
|
|
const isAiPro = confirmedArgs[0] === "hose-aipro" || confirmedArgs[0] === "aipro";
|
|
const binaryPrefix = isAiPro ? "hose-aipro" : "hose-use";
|
|
const cleanArgs =
|
|
confirmedArgs[0] === "hose-aipro" || confirmedArgs[0] === "hose-use" || confirmedArgs[0] === "aipro"
|
|
? confirmedArgs.slice(1)
|
|
: confirmedArgs;
|
|
const nextAction = `${binaryPrefix} ${cleanArgs.join(" ")} --yes`;
|
|
const payload = {
|
|
dryRun: true,
|
|
operation,
|
|
target,
|
|
changes,
|
|
nextAction,
|
|
};
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: `${JSON.stringify(payload, null, 2)}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const lines = [
|
|
"[DRY-RUN] 未执行任何写操作。",
|
|
`操作: ${operation}`,
|
|
`目标: ${target}`,
|
|
"变更:",
|
|
...Object.entries(changes).map(([key, value]) => ` ${key}: ${formatPreviewValue(value)}`),
|
|
`下一步: ${nextAction}`,
|
|
];
|
|
return { stdout: `${lines.join("\n")}\n`, stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
function formatPreviewValue(value: unknown): string {
|
|
if (typeof value === "string") return value;
|
|
return JSON.stringify(value);
|
|
}
|