--- name: ai-agent-system-bootstrap description: Initialize or completely rebuild a repository-specific AI Agent Team, including root AGENTS.md routing, project-local Agents and Skills, workflow DAGs, and selective SubAgent orchestration. Use for explicit Agent Team bootstrap or regeneration; treat generated .ai content as replaceable output rather than incrementally optimizing the previous team. --- # AI Agent System Bootstrap Run the plugin suite as the sole orchestrator. Produce a new Agent Team from current repository evidence, validate it outside the repository, then transactionally replace the managed output. ## Required suite material Read these files before dispatching a phase: - [`../../bundle.yaml`](../../bundle.yaml) for the fixed member allowlist and pipeline. The plugin manifest discovers Skills; this file defines suite execution. - [`../../shared/contracts/bootstrap-run.md`](../../shared/contracts/bootstrap-run.md) for run state. - [`../../shared/policies/ownership-and-rebuild.md`](../../shared/policies/ownership-and-rebuild.md) for ownership, legacy adoption, and replacement rules. Use only the four companion Skills declared in `bundle.yaml`. Keep dispatch centralized here; a phase Skill returns its result to this orchestrator and does not call a sibling. Resolve `` from this `SKILL.md` location before running a suite script. Invoke the resolved absolute script path; do not resolve script paths from the target repository working directory. The global-Skill restriction generated into a target repository governs that repository's future Agent Team. It does not constrain this explicitly invoked suite from dispatching its declared companion Skills. ## Pipeline Skill selection and thread selection are separate decisions. Execute the phases strictly in pipeline order: - For an inline phase, load and follow the named companion Skill in the current thread. - For an isolated phase, start a SubAgent with the stable phase input and explicitly require the named companion Skill in its task brief. - Run Inspect inline for small repositories or in a read-only SubAgent for broad discovery. - Run Design inline by default; isolate it read-only only when context separation materially improves the design pass. - Run Render as the single staging writer; never run it concurrently with another writer. - Run Validate in an independent read-only SubAgent when the runtime supports it; otherwise run it inline after Render completes. - Run repository replacement only in the main Bootstrap thread. Using a companion Skill alone does not create a SubAgent. No phase may begin before its declared input artifact is complete. ### 1. Open the run Create a `BootstrapRun` with an absolute repository root, `mode: pending`, suite version, unique run ID, explicit user constraints, and explicit exclusions. Inspect resolves ownership before the orchestrator sets the final mode. Completion criterion: the run identifies one repository, the pending mode state, the exact user request, and no unresolved target-path ambiguity. ### 2. Inspect Dispatch `ai-agent-system-inspect` with the run. Require a complete `ProjectSnapshot`; do not let later phases independently reinterpret the repository or the user's scope. Completion criterion: the snapshot covers every source category required by its contract and classifies existing `AGENTS.md` and `.ai` ownership. Resolve `BootstrapRun.mode` exactly once from that classification. ### 3. Design Dispatch `ai-agent-system-design` with the immutable snapshot, whose request block carries the verbatim user request and constraints. Require one `SystemBlueprint` that is the sole design input for rendering and semantic validation. Completion criterion: every generated Agent, local Skill, workflow, orchestration policy, managed path, and root routing rule appears in the blueprint with no unresolved writer overlap. ### 4. Create staging and render Run: ```text python /shared/scripts/create-staging-area.py --repository --run-id ``` Dispatch `ai-agent-system-render` with the BootstrapRun, blueprint, and returned staging path. Rendering may write only inside that staging path. Completion criterion: `RenderResult` accounts for every staged file and reports no write outside staging. ### 5. Validate Dispatch `ai-agent-system-validate` with the BootstrapRun, immutable ProjectSnapshot, blueprint, render result, and staging path. Before accepting the report, require its run ID, input snapshot-derived blueprint ID, input render result ID, validated run ID, validated blueprint ID, and candidate digest to match the current run artifacts. Accept `passed`. Accept `passed-with-warnings` only when every warning code appears in `BootstrapRun.allowed_warning_codes`. Completion criterion: structural and semantic validation both finish and the report contains a final decision. ### 6. Replace managed output On an accepted validation report, run: ```text python /shared/scripts/atomic-replace.py --repository --staging --expected-digest --expected-run-id --expected-blueprint-id [--allow-warning ]... ``` Pass only warning codes accepted in `BootstrapRun.allowed_warning_codes`. The replacement script binds the staging marker, manifest, validation digest, and installed digest; acquires the repository lock before target-state reads; preserves human-owned `AGENTS.md` text and unrelated repository Skills; replaces the complete `.ai` directory plus manifest-listed `.agents/skills`; migrates the legacy routing marker when present; performs a post-replacement structural check; and rolls back on failure. This is a multi-path transaction with rollback, not a filesystem-wide atomic rename. Completion criterion: the target repository passes its post-replacement check and no backup or staging directory remains. ## Failure handling - Stop before repository replacement when a phase returns `blocked` or `failed`. - Clean a failed staging area with `/shared/scripts/cleanup-staging.py`; preserve the current repository Agent Team. - Treat an existing unrelated `.ai` directory, malformed ownership marker, or repository mismatch in the staging marker as blocking evidence. - Report partial phase results and the exact failed gate. Do not claim initialization or rebuild succeeded. ## Final output Return: - run ID and mode - generated Agent, Skill, workflow, and policy counts - validation status and accepted warning codes - replaced managed paths - preserved human-owned `AGENTS.md` status - unresolved risks or blocking evidence