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
@@ -2,65 +2,86 @@ import { describe, expect, test } from "bun:test";
|
||||
import { mkdtempSync, rmSync, existsSync } from "node:fs";
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { EMBEDDED_SKILL_FILES, getDefaultGlobalSkillDir, getSkillContent, installSkillFiles } from "./embedded-skill.js";
|
||||
import {
|
||||
EMBEDDED_HOSE_USE_SKILL_FILES,
|
||||
EMBEDDED_AIPRO_SKILL_FILES,
|
||||
getDefaultGlobalSkillDir,
|
||||
getDefaultAiProGlobalSkillDir,
|
||||
getSkillContent,
|
||||
getAiProSkillContent,
|
||||
installSkillFiles,
|
||||
installHoseUseSkillFiles,
|
||||
installAiProSkillFiles,
|
||||
} from "./embedded-skill.js";
|
||||
|
||||
describe("embedded-skill - 多文件内嵌 Skill 体系", () => {
|
||||
test("全局 Skill 目录固定为 ~/.agents/skills/hose-use", () => {
|
||||
describe("embedded-skill - 双 Skill 体系内嵌与分发 (hose-use 与 hose-aipro)", () => {
|
||||
test("全局 Skill 目录分别固定为 ~/.agents/skills/hose-use 与 hose-aipro", () => {
|
||||
expect(getDefaultGlobalSkillDir()).toBe(join(homedir(), ".agents", "skills", "hose-use"));
|
||||
expect(getDefaultAiProGlobalSkillDir()).toBe(join(homedir(), ".agents", "skills", "hose-aipro"));
|
||||
});
|
||||
|
||||
test("正确内嵌 SKILL.md、agents/openai.yaml 及各领域参考专卷", () => {
|
||||
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("name: hose-use");
|
||||
test("hose-use: 正确内嵌 SKILL.md、agents/openai.yaml 及各领域参考专卷", () => {
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"]).toContain("name: hose-use");
|
||||
expect(getSkillContent()).toContain("name: hose-use");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["agents/openai.yaml"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["agents/openai.yaml"]).toContain("hose_cli");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["agents/openai.yaml"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["agents/openai.yaml"]).toContain("hose_cli");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/auth.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/auth.md"]).toContain("RSA");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/auth.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/auth.md"]).toContain("RSA");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/bill.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/bill.md"]).toContain("bill get");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/bill.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/bill.md"]).toContain("bill get");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/workflow.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/workflow.md"]).toContain("workflow find");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/workflow.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/workflow.md"]).toContain("workflow find");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/service.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/service.md"]).toContain("POST /api/cli");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/service.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/service.md"]).toContain("hose-use aipro");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/contact.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/contact.md"]).toContain("contact search");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/contact.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/contact.md"]).toContain("contact search");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/approval.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/approval.md"]).toContain("hose-aipro");
|
||||
expect(EMBEDDED_SKILL_FILES["references/feetype.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/feetype.md"]).toContain("feetype");
|
||||
expect(EMBEDDED_SKILL_FILES["references/store.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/store.md"]).toContain("hose-use keys");
|
||||
expect(EMBEDDED_SKILL_FILES["references/assist-platform.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/assist-platform.md"]).toContain("assist-platform");
|
||||
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("--reveal -o <path>");
|
||||
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("references/store.md");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/feetype.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/feetype.md"]).toContain("feetype");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/store.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/store.md"]).toContain("hose-use keys");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/assist-platform.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/assist-platform.md"]).toContain("assist-platform");
|
||||
|
||||
// 套件结构:根入口路由到 multi/ 下的子技能
|
||||
expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("multi/ekuaibao-mvel/SKILL.md");
|
||||
expect(EMBEDDED_SKILL_FILES["multi/ekuaibao-mvel/SKILL.md"]).toContain("name: ekuaibao-mvel");
|
||||
expect(EMBEDDED_SKILL_FILES["multi/ekuaibao-mvel/agents/openai.yaml"]).toContain("ekuaibao-mvel");
|
||||
expect(EMBEDDED_SKILL_FILES["multi/ekuaibao-nodes/SKILL.md"]).toContain("name: ekuaibao-nodes");
|
||||
expect(EMBEDDED_SKILL_FILES["multi/ekuaibao-nodes/references/gray-nodes.md"]).toContain("灰度节点清单");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"]).toContain("multi/ekuaibao-mvel/SKILL.md");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["multi/ekuaibao-mvel/SKILL.md"]).toContain("name: ekuaibao-mvel");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["multi/ekuaibao-mvel/agents/openai.yaml"]).toContain("ekuaibao-mvel");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["multi/ekuaibao-nodes/SKILL.md"]).toContain("name: ekuaibao-nodes");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["multi/ekuaibao-nodes/references/gray-nodes.md"]).toContain("灰度节点清单");
|
||||
});
|
||||
|
||||
test("installSkillFiles 递归保留层级结构并落盘到目标目录", () => {
|
||||
test("hose-aipro: 正确内嵌 SKILL.md、agents/openai.yaml、approval.md 与 service.md", () => {
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["SKILL.md"]).toBeDefined();
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["SKILL.md"]).toContain("name: hose-aipro");
|
||||
expect(getAiProSkillContent()).toContain("name: hose-aipro");
|
||||
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["agents/openai.yaml"]).toBeDefined();
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["agents/openai.yaml"]).toContain("command: \"hose-aipro\"");
|
||||
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["references/approval.md"]).toBeDefined();
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["references/approval.md"]).toContain("hose-aipro decide");
|
||||
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["references/service.md"]).toBeDefined();
|
||||
expect(EMBEDDED_AIPRO_SKILL_FILES["references/service.md"]).toContain("8889");
|
||||
});
|
||||
|
||||
test("installSkillFiles 显式路径安装保留层级结构", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "hose-skill-test-"));
|
||||
try {
|
||||
const res = installSkillFiles(tmp);
|
||||
const res = installHoseUseSkillFiles(tmp);
|
||||
expect(res.targetDir).toBe(tmp);
|
||||
expect(res.files.length).toBe(19);
|
||||
expect(res.files.length).toBe(18);
|
||||
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "agents", "openai.yaml"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "auth.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "approval.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "bill.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "contact.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "feetype.md"))).toBe(true);
|
||||
@@ -74,4 +95,19 @@ describe("embedded-skill - 多文件内嵌 Skill 体系", () => {
|
||||
rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("installAiProSkillFiles 正确落盘 hose-aipro 专属技能文件", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "aipro-skill-test-"));
|
||||
try {
|
||||
const res = installAiProSkillFiles(tmp);
|
||||
expect(res.targetDir).toBe(tmp);
|
||||
expect(res.files.length).toBe(5);
|
||||
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "agents", "openai.yaml"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "approval.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "service.md"))).toBe(true);
|
||||
} finally {
|
||||
rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
// ── hose-use Skill 文件 ────────────────────────────────────────────────────────
|
||||
import skillMain from "../../skills/hose-use/SKILL.md" with { type: "text" };
|
||||
import agentOpenAi from "../../skills/hose-use/agents/openai.yaml" with { type: "text" };
|
||||
import refAuth from "../../skills/hose-use/references/auth.md" with { type: "text" };
|
||||
@@ -13,7 +14,6 @@ import refTask from "../../skills/hose-use/references/task.md" with { type: "tex
|
||||
import refMessage from "../../skills/hose-use/references/message.md" with { type: "text" };
|
||||
import refDimension from "../../skills/hose-use/references/dimension.md" with { type: "text" };
|
||||
import refRole from "../../skills/hose-use/references/role.md" with { type: "text" };
|
||||
import refApproval from "../../skills/hose-use/references/approval.md" with { type: "text" };
|
||||
import refFeeType from "../../skills/hose-use/references/feetype.md" with { type: "text" };
|
||||
import refStore from "../../skills/hose-use/references/store.md" with { type: "text" };
|
||||
import refAssistPlatform from "../../skills/hose-use/references/assist-platform.md" with { type: "text" };
|
||||
@@ -22,11 +22,17 @@ import multiMvelAgent from "../../skills/hose-use/multi/ekuaibao-mvel/agents/ope
|
||||
import multiNodes from "../../skills/hose-use/multi/ekuaibao-nodes/SKILL.md" with { type: "text" };
|
||||
import multiNodesGray from "../../skills/hose-use/multi/ekuaibao-nodes/references/gray-nodes.md" with { type: "text" };
|
||||
|
||||
export const EMBEDDED_SKILL_FILES: Record<string, string> = {
|
||||
// ── hose-aipro Skill 文件 ──────────────────────────────────────────────────────
|
||||
import aiproSkillMain from "../../skills/hose-aipro/SKILL.md" with { type: "text" };
|
||||
import aiproAgentOpenAi from "../../skills/hose-aipro/agents/openai.yaml" with { type: "text" };
|
||||
import aiproRefApproval from "../../skills/hose-aipro/references/approval.md" with { type: "text" };
|
||||
import aiproRefService from "../../skills/hose-aipro/references/service.md" with { type: "text" };
|
||||
import aiproRefReadme from "../../skills/hose-aipro/references/README.references.md" with { type: "text" };
|
||||
|
||||
export const EMBEDDED_HOSE_USE_SKILL_FILES: Record<string, string> = {
|
||||
"SKILL.md": skillMain,
|
||||
"agents/openai.yaml": agentOpenAi,
|
||||
"references/auth.md": refAuth,
|
||||
"references/approval.md": refApproval,
|
||||
"references/bill.md": refBill,
|
||||
"references/feetype.md": refFeeType,
|
||||
"references/contact.md": refContact,
|
||||
@@ -44,36 +50,92 @@ export const EMBEDDED_SKILL_FILES: Record<string, string> = {
|
||||
"multi/ekuaibao-nodes/references/gray-nodes.md": multiNodesGray,
|
||||
};
|
||||
|
||||
export const EMBEDDED_AIPRO_SKILL_FILES: Record<string, string> = {
|
||||
"SKILL.md": aiproSkillMain,
|
||||
"agents/openai.yaml": aiproAgentOpenAi,
|
||||
"references/approval.md": aiproRefApproval,
|
||||
"references/service.md": aiproRefService,
|
||||
"references/README.references.md": aiproRefReadme,
|
||||
};
|
||||
|
||||
// 保持模块级向后兼容
|
||||
export const EMBEDDED_SKILL_FILES: Record<string, string> = EMBEDDED_HOSE_USE_SKILL_FILES;
|
||||
|
||||
export function getSkillContent(): string {
|
||||
return EMBEDDED_SKILL_FILES["SKILL.md"] || "";
|
||||
return EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"] || "";
|
||||
}
|
||||
|
||||
export function getAiProSkillContent(): string {
|
||||
return EMBEDDED_AIPRO_SKILL_FILES["SKILL.md"] || "";
|
||||
}
|
||||
|
||||
export function getDefaultGlobalSkillDir(): string {
|
||||
return join(homedir(), ".agents", "skills", "hose-use");
|
||||
}
|
||||
|
||||
export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): {
|
||||
export function getDefaultAiProGlobalSkillDir(): string {
|
||||
return join(homedir(), ".agents", "skills", "hose-aipro");
|
||||
}
|
||||
|
||||
export function installHoseUseSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): {
|
||||
targetDir: string;
|
||||
files: string[];
|
||||
} {
|
||||
mkdirSync(targetDir, { recursive: true });
|
||||
const installed: string[] = [];
|
||||
|
||||
for (const [relPath, content] of Object.entries(EMBEDDED_SKILL_FILES)) {
|
||||
for (const [relPath, content] of Object.entries(EMBEDDED_HOSE_USE_SKILL_FILES)) {
|
||||
const fullPath = join(targetDir, relPath);
|
||||
mkdirSync(dirname(fullPath), { recursive: true });
|
||||
writeFileSync(fullPath, content, "utf8");
|
||||
installed.push(relPath);
|
||||
}
|
||||
|
||||
return {
|
||||
targetDir,
|
||||
files: installed,
|
||||
};
|
||||
return { targetDir, files: installed };
|
||||
}
|
||||
|
||||
export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: string } {
|
||||
const globalDir = getDefaultGlobalSkillDir();
|
||||
installSkillFiles(globalDir);
|
||||
return { synced: true, targetDir: globalDir };
|
||||
export function installAiProSkillFiles(targetDir: string = getDefaultAiProGlobalSkillDir()): {
|
||||
targetDir: string;
|
||||
files: string[];
|
||||
} {
|
||||
mkdirSync(targetDir, { recursive: true });
|
||||
const installed: string[] = [];
|
||||
|
||||
for (const [relPath, content] of Object.entries(EMBEDDED_AIPRO_SKILL_FILES)) {
|
||||
const fullPath = join(targetDir, relPath);
|
||||
mkdirSync(dirname(fullPath), { recursive: true });
|
||||
writeFileSync(fullPath, content, "utf8");
|
||||
installed.push(relPath);
|
||||
}
|
||||
|
||||
return { targetDir, files: installed };
|
||||
}
|
||||
|
||||
export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): {
|
||||
targetDir: string;
|
||||
files: string[];
|
||||
skills?: string[];
|
||||
} {
|
||||
const defaultGlobalDir = getDefaultGlobalSkillDir();
|
||||
// 当为全局默认目录时,自动同时安装两个 Skill
|
||||
if (targetDir === defaultGlobalDir) {
|
||||
const hoseRes = installHoseUseSkillFiles(defaultGlobalDir);
|
||||
const aiproRes = installAiProSkillFiles(getDefaultAiProGlobalSkillDir());
|
||||
return {
|
||||
targetDir,
|
||||
files: [...hoseRes.files, ...aiproRes.files.map((f) => `hose-aipro/${f}`)],
|
||||
skills: ["hose-use", "hose-aipro"],
|
||||
};
|
||||
}
|
||||
|
||||
// 显式指定自定义目录时,在该目录下安装 hose-use 文件
|
||||
return installHoseUseSkillFiles(targetDir);
|
||||
}
|
||||
|
||||
export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: string; targetDirs: string[] } {
|
||||
const hoseDir = getDefaultGlobalSkillDir();
|
||||
const aiproDir = getDefaultAiProGlobalSkillDir();
|
||||
installHoseUseSkillFiles(hoseDir);
|
||||
installAiProSkillFiles(aiproDir);
|
||||
return { synced: true, targetDir: hoseDir, targetDirs: [hoseDir, aiproDir] };
|
||||
}
|
||||
Reference in new issue
Block a user