- CliRuntime 新增 app?: "hose-use" | "hose-aipro",由 runCli 与 runAiProCli 各自标注;skill.ts 优先用它判断调用方,修复 hose-aipro skill dump 误输出 hose-use Skill 的既有 bug——根因是 multicall 二进制的 argv0 不会进入 parsed.raw。保留 raw 里的历史 aipro 标记作为兼容。 - 新增 skill.test.ts 覆盖两个入口与历史兼容三条路径。 - 补齐 4 份目录 README(scripts/build、cli/commands/aipro、web、 web/src):web/ 文件在 #177 合入后由 untracked 转为 tracked, 才被 check:readme 纳入扫描,暴露出 4 个目录缺文档。 校验:bun test 1111 pass / 0 fail,bun run check 通过, check:readme 36/36 通过;编译产物实测 hose-aipro skill dump 返回 AI PRO Skill、hose-use 返回平台 Skill。
185 lines
6.3 KiB
TypeScript
185 lines
6.3 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import {
|
|
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";
|
|
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../mutation.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
|
|
|
export async function handleSkillCommand(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
const action = parsed.action || "status";
|
|
const isAiProCaller =
|
|
runtime.app === "hose-aipro" ||
|
|
parsed.area === "hose-aipro" ||
|
|
parsed.raw.some((arg) => arg.includes("hose-aipro") || arg === "aipro");
|
|
|
|
switch (action) {
|
|
case "dump":
|
|
case "cat":
|
|
case "show":
|
|
return {
|
|
stdout: `${isAiProCaller ? getAiProSkillContent() : getSkillContent()}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
|
|
case "install":
|
|
case "init":
|
|
case "sync": {
|
|
const isLocal =
|
|
booleanOption(parsed.options, ["local"]) ||
|
|
booleanOption(parsed.options, ["workspace"]);
|
|
const customDir =
|
|
stringOption(parsed.options, ["dir", "target"]) || parsed.args[0];
|
|
|
|
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 文件 (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 文件",
|
|
`${isAiProCaller ? "hose-aipro" : "hose-use"} skill install${customDir ? ` --dir=${customDir}` : ""} --yes`
|
|
);
|
|
|
|
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,
|
|
targetDirs: installedReport.targetDirs,
|
|
fileCount: installedReport.filesCount,
|
|
skills: installedReport.skills,
|
|
}),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
return {
|
|
stdout:
|
|
`[SUCCESS] Agent 技能已成功安装:\n` +
|
|
installedReport.targetDirs.map((d) => ` • ${d}`).join("\n") +
|
|
`\n共 ${installedReport.filesCount} 个文件。\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
case "status":
|
|
case "get": {
|
|
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 = {
|
|
"hose-use": {
|
|
global: {
|
|
dir: globalHoseDir,
|
|
installed: existsSync(join(globalHoseDir, "SKILL.md")),
|
|
},
|
|
local: {
|
|
dir: localHoseDir,
|
|
installed: existsSync(join(localHoseDir, "SKILL.md")),
|
|
},
|
|
},
|
|
"hose-aipro": {
|
|
global: {
|
|
dir: globalAiProDir,
|
|
installed: existsSync(join(globalAiProDir, "SKILL.md")),
|
|
},
|
|
local: {
|
|
dir: localAiProDir,
|
|
installed: existsSync(join(localAiProDir, "SKILL.md")),
|
|
},
|
|
},
|
|
};
|
|
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(statusObj), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
const output = printKeyValue({
|
|
"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提示: 运行 ${isAiProCaller ? "hose-aipro" : "hose-use"} skill install --yes 进行全局安装\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
default:
|
|
return {
|
|
stdout: "",
|
|
stderr: `未知 skill 子命令: ${action}。支持: install, status, dump\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
}
|