feat(install): validate agent CLI runtime registries

This commit is contained in:
2026-09-18 16:42:09 +08:00
parent 867a23497f
commit 5a259a95af
11 changed files with 350 additions and 23 deletions
+42 -1
View File
@@ -47,7 +47,7 @@ const PLATFORMS = [
{ name: 'claude', label: 'Claude Code', base: 'home', detect: ['.claude'], target: ['.claude', 'commands'], kind: 'command' },
{ name: 'codex', label: 'Codex', base: 'home', detect: ['.codex'], target: ['.codex', 'prompts'], kind: 'command' },
{ name: 'opencode', label: 'OpenCode', base: 'home', detect: ['.config', 'opencode'], target: ['.config', 'opencode', 'command'], kind: 'command' },
{ name: 'oh-my-pi', label: 'oh-my-pi', base: 'home', detect: ['.omp'], target: ['.omp', 'commands'], kind: 'command' },
{ name: 'oh-my-pi', label: 'oh-my-pi', base: 'home', detect: ['.omp'], target: ['.omp', 'agent', 'commands'], kind: 'command' },
{ name: 'antigravity', label: 'Antigravity', base: 'home', detect: ['.gemini'], target: ['.gemini', 'skills'], kind: 'skill' },
{ name: 'kiro', label: 'Kiro', base: 'home', detect: ['.kiro'], target: ['.kiro', 'skills'], kind: 'skill' },
{ name: 'copilot', label: 'GitHub Copilot', base: 'cwd', detect: ['.github'], target: ['.github', 'skills'], kind: 'skill' },
@@ -220,7 +220,48 @@ export function platformReport() {
});
}
/**
* 供 verify 使用的唯讀目標。它只看目前偵測到的平台,不進互動選擇,也不寫檔。
* @param {string|undefined} flag --platform 的值
* @returns {{name: string, adapters: {name: string, path: string}[]}[]}
*/
export function verificationTargets(flag) {
const detected = PLATFORMS.filter((platform) => existsSync(pathOf(platform, platform.detect)));
const chosen = flag === undefined
? detected
: (() => {
const names = parsePlatformFlag(flag);
const missing = names.filter((name) => !detected.some((platform) => platform.name === name));
if (missing.length > 0) {
throw new ScriptError(
'PLATFORM_NOT_DETECTED',
`這台機器上偵測不到 ${missing.join('、')};請先把該平台裝起來再重跑`,
);
}
return PLATFORMS.filter((platform) => names.includes(platform.name));
})();
if (chosen.length === 0) {
throw new ScriptError(
'NO_PLATFORM_DETECTED',
`偵測不到任何 agent 平台(找過 ${PLATFORMS.map(detectLabel).join('、')});請先安裝其中至少一個`,
);
}
const names = readPrompts().map((prompt) => prompt.name);
return chosen.map((platform) => ({
name: platform.name,
adapters: names.map((name) => ({ name, path: adapterPath(platform, name) })),
}));
}
/** @returns {{name: string, text: string}} */
export function verificationPrompt() {
const prompt = readPrompts()[0];
return { name: prompt.name, text: prompt.text };
}
// ── 平台挑選 ───────────────────────────────────────────────────────
/**