{"version":3,"file":"subagent-cli.d.ts","sourceRoot":"","sources":["../../src/core/subagent-cli.ts"],"names":[],"mappings":"AAgBA,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAmF5E","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { getAgentDir } from \"../config.js\";\nimport { applySkillMigration, previewSkillMigration } from \"./skill-migration.js\";\nimport type { Skill } from \"./skills.js\";\nimport { loadSkills } from \"./skills.js\";\nimport { getCanonicalSubagentRegistry, validateSkillAgentReferences } from \"./subagent-registry.js\";\n\nfunction printJson(value: unknown, json: boolean): void {\n\tconsole.log(json ? JSON.stringify(value, null, 2) : JSON.stringify(value, null, 2));\n}\n\nfunction skillDependencies(skill: Skill) {\n\tif (!existsSync(skill.filePath)) return [];\n\treturn validateSkillAgentReferences(skill.name, skill.filePath, readFileSync(skill.filePath, \"utf8\"));\n}\n\nexport async function handleSubagentCommand(args: string[]): Promise<boolean> {\n\tif (args[0] === \"skills\" && args[1] === \"migrate\") {\n\t\tconst previews = args.includes(\"--apply\") ? applySkillMigration() : previewSkillMigration();\n\t\tprintJson({ mode: args.includes(\"--apply\") ? \"apply\" : \"preview\", previews }, args.includes(\"--json\"));\n\t\treturn true;\n\t}\n\tif (args[0] === \"cavecrew\") {\n\t\tif (args[1] !== \"status\" && args[1] !== \"validate\") throw new Error(\"Usage: jensen cavecrew status|validate\");\n\t\tconst registry = getCanonicalSubagentRegistry();\n\t\tconst cavecrewAgents = [\"cavecrew-investigator\", \"planner\", \"cavecrew-builder\", \"cavecrew-reviewer\"];\n\t\tconst resolutions = cavecrewAgents.map((agent) => ({ agent, resolution: registry.resolve(agent) }));\n\t\tprintJson(\n\t\t\t{ valid: resolutions.every(({ resolution }) => !(\"code\" in resolution)), resolutions },\n\t\t\targs.includes(\"--json\"),\n\t\t);\n\t\tprocess.exitCode = resolutions.every(({ resolution }) => !(\"code\" in resolution)) ? 0 : 1;\n\t\treturn true;\n\t}\n\tif (args[0] !== \"agents\" && args[0] !== \"skills\") return false;\n\tconst registry = getCanonicalSubagentRegistry();\n\tconst json = args.includes(\"--json\");\n\tif (args[0] === \"agents\") {\n\t\tconst command = args[1] ?? \"list\";\n\t\tif (command === \"list\" || command === \"models\") {\n\t\t\tprintJson(\n\t\t\t\tcommand === \"models\"\n\t\t\t\t\t? registry.list().map((agent) => ({\n\t\t\t\t\t\t\tagent: agent.name,\n\t\t\t\t\t\t\tprovider: agent.provider,\n\t\t\t\t\t\t\tmodel: agent.model,\n\t\t\t\t\t\t\tresolutionPolicy: agent.modelResolutionPolicy,\n\t\t\t\t\t\t}))\n\t\t\t\t\t: registry.list(),\n\t\t\t\tjson,\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\t\tif (command === \"aliases\") {\n\t\t\tprintJson(registry.aliasesList(), json);\n\t\t\treturn true;\n\t\t}\n\t\tif (command === \"validate\") {\n\t\t\tprintJson(registry.validate(), json);\n\t\t\tprocess.exitCode = registry.validate().valid ? 0 : 1;\n\t\t\treturn true;\n\t\t}\n\t\tif (command === \"inspect\" || command === \"resolve\") {\n\t\t\tconst name = args[2];\n\t\t\tif (!name) throw new Error(`jensen agents ${command} requires <agent>`);\n\t\t\tconst result = registry.resolve(name);\n\t\t\tprintJson(result, json);\n\t\t\tif (\"code\" in result) process.exitCode = 1;\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (args[0] === \"skills\") {\n\t\tconst loaded = loadSkills({ cwd: process.cwd(), agentDir: getAgentDir() });\n\t\tconst command = args[1] ?? \"list\";\n\t\tif (command === \"list\") {\n\t\t\tprintJson(loaded.skills, json);\n\t\t\treturn true;\n\t\t}\n\t\tif (command === \"validate\" || command === \"dependencies\") {\n\t\t\tconst selected =\n\t\t\t\tcommand === \"dependencies\" && args[2]\n\t\t\t\t\t? loaded.skills.filter((skill) => skill.name === args[2])\n\t\t\t\t\t: loaded.skills;\n\t\t\tif (command === \"dependencies\" && args[2] && selected.length === 0) {\n\t\t\t\tthrow new Error(`Unknown skill: ${args[2]}`);\n\t\t\t}\n\t\t\tconst dependencies = selected.flatMap(skillDependencies);\n\t\t\tprintJson({ valid: dependencies.length === 0, dependencies }, json);\n\t\t\tprocess.exitCode = dependencies.length === 0 ? 0 : 1;\n\t\t\treturn true;\n\t\t}\n\t\tif (command === \"inspect\") {\n\t\t\tconst skill = loaded.skills.find((candidate) => candidate.name === args[2]);\n\t\t\tif (!skill) throw new Error(`Unknown skill: ${args[2]}`);\n\t\t\tprintJson({ ...skill, dependencies: skillDependencies(skill) }, json);\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"]}