import{AGENTS as e}from"../definitions/agents.mjs";import{AGENT_BODIES as t}from"../definitions/bodies.mjs";import{VARIANT_GROUPS as n,getPrimaryAgentModel as r}from"../definitions/models.mjs";import{PROMPTS as i}from"../definitions/prompts.mjs";import{AIKIT_INSTALL_HINT_SECTION as a,PLATFORM_OUTPUT_RULES_SECTION as o,PROTOCOLS as s,TEMPLATES as c}from"../definitions/protocols.mjs";import{IDE_CAPABILITIES as l}from"../definitions/tools.mjs";import{buildCompactAgentTable as u}from"./_shared.mjs";import{generateHooks as d,getHookScriptFiles as f}from"./hooks.mjs";import{generateForbiddenTable as p}from"../definitions/policies.mjs";const m={terminal:`execute/runInTerminal`,problems:`read/problems`,readFile:`read/readFile`,lastCommand:`read/terminalLastCommand`,subagent:`agent/runSubagent`,createFile:`edit/createFile`,editFiles:`edit/editFiles`,rename:`edit/rename`,createDirectory:`edit/createDirectory`,search:`search/changes, search/codebase, search/usages`,web:`web/fetch, web/githubRepo`,todo:`todo`,memory:`vscode/memory`,newWorkspace:`vscode/newWorkspace`,reviewPlan:`vscode/reviewPlan`,askQuestions:`vscode/askQuestions`,resolveMemoryFileUri:`vscode/resolveMemoryFileUri`,runCommand:`vscode/runCommand`,switchAgent:`vscode/switchAgent`,killTerminal:`execute/killTerminal`,createTask:`execute/createAndRunTask`,terminalSel:`read/terminalSelection`,fileSearch:`search/fileSearch`,listDir:`search/listDirectory`,textSearch:`search/textSearch`,searchSubagent:`search/searchSubagent`};function h(e){return`[${[...(l[e]||[]).map(e=>m[e]).filter(Boolean),`aikit/*`].join(`, `)}]`}function g(e){return r(`copilot`,e,`Auto (copilot)`)}const _=[`## Flows`,``,"This project uses aikit's pluggable flow system. Check flow status with the `flow` MCP tool.","If a flow is active, follow the current step's skill instructions. Advance with `flow({ action: 'step', advance: 'next' })`.","Use `flow({ action: 'list' })` to see available flows and `flow({ action: 'start', name, topic })` to begin one."].join(`
`),v=[`## Flows`,``,"This project uses aikit's pluggable flow system. Use `flow({ action: 'status' })` to check if a flow is active.",`If dispatched as part of a flow, your work contributes to the current step. Do NOT advance or manage the flow — the Orchestrator handles flow lifecycle.`].join(`
`);function y(){let t=[];for(let[i,a]of Object.entries(e))if(a.variants)for(let e of n[i]||[]){let n=`${i}-${e}`,o=r(`copilot`,n,`Unknown`),s=(a.variants[e]||{}).description||a.description;t.push(`| **${n}** | ${s} | ${o} | ${a.category} |`)}else{let e=r(`copilot`,i,`Unknown`);t.push(`| **${i}** | ${a.description} | ${e} | ${a.category} |`)}return`| Agent | Purpose | Model | Category |\n|-------|---------|-------|----------|\n${t.join(`
`)}`}function b(e,t,r){let i=`${e}-${t}`,a=r.variants[t]||{},o=g(i),c=a.description||r.description,l=a.identity||(t===n[e]?.[0]?`, the primary ${e} agent.`:`, a variant of ${e}. Same responsibilities, different model perspective.`),u=r.sharedBase&&s[r.sharedBase]?`\n\n${s[r.sharedBase]}`:``,d=r.extraBody?`\n\n${r.extraBody}`:``,f=a.bodyAddendum?`\n\n${a.bodyAddendum}`:``,p=(r.sharedProtocols||[]).map(e=>s[e]?`\n\n${s[e]}`:``).join(``),m=r.skills?.length?`\n\n## Skills (load on demand)\n\n| Skill | When to load |\n|-------|--------------|\n${r.skills.map(([e,t])=>`| ${e} | ${t} |`).join(`
`)}`:``,_=r.title||e;return`---
description: '${c}'
${r.argumentHint?`argument-hint: "${r.argumentHint}"\n`:``}tools: ${h(r.toolRole)}
model: ${o}
---

# ${i} - ${_}

You are **${i}**${l}${d}
${u}${p}${f}${m}

${v}
`}function x(n,r){let i=g(n),a=typeof t[n]==`function`?t[n](u(e)):t[n]||``,o=r.sharedBase&&s[r.sharedBase]?`\n\n${s[r.sharedBase]}`:``,c=(r.sharedProtocols||[]).map(e=>s[e]?`\n\n${s[e]}`:``).join(``),l=r.title||n,d=r.skills?.length?`\n## Skills (load on demand)\n\n| Skill | When to load |\n|-------|--------------|\n${r.skills.map(([e,t])=>`| ${e} | ${t} |`).join(`
`)}\n`:``;return`---
description: '${r.description}'
${r.argumentHint?`argument-hint: "${r.argumentHint}"\n`:``}tools: ${h(r.toolRole)}
model: ${i}
---

# ${n} - ${l}

You are the **${n}**, ${r.description.toLowerCase().replace(/^./,e=>e.toLowerCase())}

${a}${o}${c}${d}

${n===`Orchestrator`?_:v}
`}function S(e,t){return`---
description: "${t.description}"
agent: "${t.agent}"
---

${t.content}
`}function C(){return`# Agents

This directory contains AI agent definitions generated by \`@vpxa/aikit init\`.

## Agent Roster

${y()}

## Multi-Model Pattern

Variant agents (Researcher-Alpha/Beta/Gamma/Delta, Code-Reviewer-Alpha/Beta, Architect-Reviewer-Alpha/Beta) share the same methodology via files in \`_shared/\`. They differ only in which LLM model backs them — enabling multi-model decision analysis and dual-review workflows.

**Agent names are model-agnostic.** The backing model can vary by platform in \`scaffold/definitions/models.mjs\` without renaming any agent files.

## Structure

\`\`\`
agents/
  {Name}.agent.md          — Agent definition (YAML frontmatter + instructions)
  _shared/                  — Shared protocols referenced by multiple agents
    code-agent-base.md      — Base for all code-modifying agents
    researcher-base.md      — Base for all Researcher variants
    code-reviewer-base.md   — Base for all Code-Reviewer variants
    architect-reviewer-base.md — Base for all Architect-Reviewer variants
    decision-protocol.md    — Multi-model decision protocol rules
    forge-protocol.md       — FORGE quality gate protocol
  templates/
    execution-state.md      — Orchestrator state tracking template
    adr-template.md         — Architecture Decision Record template
\`\`\`

## Regenerating

To regenerate after changing models or agent definitions:

\`\`\`bash
cd knowledge-base
node scaffold/generate.mjs
\`\`\`
`}function w(){return[`# aikit — Copilot Instructions`,``,"This file is generated from `scaffold/definitions/`. Do not edit directly.",``,o,``,`## Tool Routing Rules`,``,`These rules are enforced by AI Kit compliance checking. Violations are flagged in reports and reduce your compliance score.`,``,p(),``,a,``].join(`
`)}function T(){let t=[];if(f().length===0)throw Error(`Executable hooks are not configured.`);t.push({path:`copilot-instructions.md`,content:w()});for(let[r,i]of Object.entries(e))if(i.variants)for(let e of n[r]||[])t.push({path:`agents/${r}-${e}.agent.md`,content:b(r,e,i)});else t.push({path:`agents/${r}.agent.md`,content:x(r,i)});for(let[e,n]of Object.entries(s))t.push({path:`agents/_shared/${e}.md`,content:`${n}\n`});for(let[e,n]of Object.entries(c))t.push({path:`agents/templates/${e}.md`,content:`${n}\n`});t.push({path:`agents/README.md`,content:C()});for(let[e,n]of Object.entries(i))t.push({path:`prompts/aikit-${e}.prompt.md`,content:S(e,n)});let r=d(`copilot`,`~/.copilot/hooks/scripts`);return t.push(...r.map(e=>({path:`hooks/${e.path}`,content:e.content}))),t}export{T as generateCopilot};