Files
hose-use/src/packaging/embedded-skill.ts
T
gitea b787130880 feat(agent): 增强开放平台文档自省与端点检索引导
- 规约硬化:在 SKILL.md 新增第 18 条执行原则,严禁 Agent 盲目翻找源码或用脚本暴力解析底层 specs JSON,确立 hose-use docs search/show 为唯一合法第一入口;
- 参考专卷:新增 skills/hose-use/references/docs.md,系统阐述 4 大文档子命令、加权搜索机制与售前方案调研 SOP;
- 内嵌打包:在 src/packaging/embedded-skill.ts 注册 references/docs.md,确保二进制与全局 Skill 分发无遗漏;
- 上下文自省:在 hose-use context (及 --json) 注入开放平台文档库就绪指标 (330 篇文档 / 279 个端点),并在诊断提示中显式引导 docs search 用法;
- 架构总纲:在 AGENTS.md 登记 docs 领域说明与零原始 JSON 侵入原则。
2026-11-17 14:29:50 +08:00

144 lines
6.5 KiB
TypeScript

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" };
import refBill from "../../skills/hose-use/references/bill.md" with { type: "text" };
import refWorkflow from "../../skills/hose-use/references/workflow.md" with { type: "text" };
import refService from "../../skills/hose-use/references/service.md" with { type: "text" };
import refContact from "../../skills/hose-use/references/contact.md" with { type: "text" };
import refTask from "../../skills/hose-use/references/task.md" with { type: "text" };
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 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" };
import refDocs from "../../skills/hose-use/references/docs.md" with { type: "text" };
import multiMvel from "../../skills/hose-use/multi/ekuaibao-mvel/SKILL.md" with { type: "text" };
import multiMvelAgent from "../../skills/hose-use/multi/ekuaibao-mvel/agents/openai.yaml" with { type: "text" };
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" };
// ── 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/bill.md": refBill,
"references/feetype.md": refFeeType,
"references/contact.md": refContact,
"references/task.md": refTask,
"references/message.md": refMessage,
"references/dimension.md": refDimension,
"references/role.md": refRole,
"references/workflow.md": refWorkflow,
"references/service.md": refService,
"references/store.md": refStore,
"references/assist-platform.md": refAssistPlatform,
"references/docs.md": refDocs,
"multi/ekuaibao-mvel/SKILL.md": multiMvel,
"multi/ekuaibao-mvel/agents/openai.yaml": multiMvelAgent,
"multi/ekuaibao-nodes/SKILL.md": multiNodes,
"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_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 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_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 };
}
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] };
}