# Review / Closeout: Robust Pi subagent workflow for Nimrod

## Phase Contract

Allowed reads:
- `tickets/artifacts/2026-06-03-robust-pi-subagents/03-design.md`
- `tickets/artifacts/2026-06-03-robust-pi-subagents/05-plan.md`
- git diff / verification outputs

Will write:
- `tickets/artifacts/2026-06-03-robust-pi-subagents/06-review.md`

## Summary

Implemented the first robust Nimrod subagent MVP:

- Forked Pi's example subagent extension into `.pi/extensions/nimrod-subagents/`.
- Adapted the tool to register as `nimrod_subagent`.
- Defaulted agent scope to project-local `.pi/agents/`.
- Disabled project-agent confirmation by default for this trusted repo.
- Added all QRSPI role agents under `.pi/agents/`.
- Updated durable workflow docs/instructions to prefer `nimrod_subagent` for context-heavy Nimrod work.

## Files Changed

### Extension

- `.pi/extensions/nimrod-subagents/index.ts` — fork of Pi subagent runner with Nimrod defaults/tool name.
- `.pi/extensions/nimrod-subagents/agents.ts` — copied agent discovery helper.
- `.pi/extensions/nimrod-subagents/README.md` — usage, safety, reload, rollback notes.

### Agent prompts

- `.pi/agents/nimrod-locator.md`
- `.pi/agents/nimrod-researcher.md`
- `.pi/agents/nimrod-analyzer.md`
- `.pi/agents/nimrod-pattern-finder.md`
- `.pi/agents/nimrod-designer.md`
- `.pi/agents/nimrod-structurer.md`
- `.pi/agents/nimrod-planner.md`
- `.pi/agents/nimrod-implementer.md`
- `.pi/agents/nimrod-reviewer.md`

### Docs / workflow

- `docs/qrspi-adaptation.md` — updated to document the real project-local `nimrod_subagent` implementation.
- `AGENTS.md` — added durable instruction to use `.pi/extensions/nimrod-subagents/` and `.pi/agents/nimrod-*.md`.
- `tickets/active/2026-06-03-robust-pi-subagents.md`
- `tickets/artifacts/2026-06-03-robust-pi-subagents/*`

## Verification

Automated checks run:

```sh
set -e
printf 'Phase 1 checks\n'
test -f .pi/extensions/nimrod-subagents/index.ts
test -f .pi/extensions/nimrod-subagents/agents.ts
grep -q 'nimrod_subagent' .pi/extensions/nimrod-subagents/index.ts
grep -q 'params.agentScope ?? "project"' .pi/extensions/nimrod-subagents/index.ts
grep -q 'params.confirmProjectAgents ?? false' .pi/extensions/nimrod-subagents/index.ts
printf 'Phase 2 checks\n'
for f in .pi/agents/nimrod-*.md; do grep -q '^name:' "$f" && grep -q '^description:' "$f" && grep -q '^tools:' "$f"; done
test "$(find .pi/agents -maxdepth 1 -name 'nimrod-*.md' | wc -l | tr -d ' ')" -eq 9
printf 'Phase 3 checks\n'
grep -q 'nimrod_subagent' docs/qrspi-adaptation.md
grep -q 'nimrod-subagents' AGENTS.md
printf 'Files:\n'
find .pi/extensions/nimrod-subagents .pi/agents -type f | sort
printf 'OK\n'
```

Output:

```text
Phase 1 checks
Phase 2 checks
Phase 3 checks
Files:
.pi/agents/nimrod-analyzer.md
.pi/agents/nimrod-designer.md
.pi/agents/nimrod-implementer.md
.pi/agents/nimrod-locator.md
.pi/agents/nimrod-pattern-finder.md
.pi/agents/nimrod-planner.md
.pi/agents/nimrod-researcher.md
.pi/agents/nimrod-reviewer.md
.pi/agents/nimrod-structurer.md
.pi/extensions/nimrod-subagents/README.md
.pi/extensions/nimrod-subagents/agents.ts
.pi/extensions/nimrod-subagents/index.ts
OK
```

Scoped git status:

```text
 M AGENTS.md
?? .pi/agents/
?? .pi/extensions/nimrod-subagents/
?? docs/qrspi-adaptation.md
?? tickets/active/2026-06-03-robust-pi-subagents.md
?? tickets/artifacts/2026-06-03-robust-pi-subagents/
```

## Manual Verification Still Needed

After reloading Pi:

```text
/reload
```

Confirm:

- `nimrod_subagent` is available as a tool.
- A simple `nimrod-locator` or `nimrod-researcher` run works.
- Project agents are discovered from `.pi/agents/` without confirmation.

Suggested test request after reload:

```text
Use nimrod_subagent with agent nimrod-locator to list the Nimrod subagent files and summarize them briefly.
```

## Risks / Follow-ups

- This MVP allows write-capable subagents. Keep prompts narrow and review diffs.
- No hard path sandbox exists yet. Future enhancement: add artifact-path allowlists or a dedicated artifact-writing wrapper.
- The copied extension may need adjustment if child `pi` invocation behaves differently in this container/session.
- Manual `/reload` is required before the current Pi session sees the new extension.
- The repo already has unrelated dirty work, so no commit was made.

## Rollback Notes

Remove the subagent MVP files:

```sh
rm -rf .pi/extensions/nimrod-subagents
rm -f .pi/agents/nimrod-*.md
```

Then revert docs/ticket artifacts as desired:

```sh
git checkout -- AGENTS.md
rm -f docs/qrspi-adaptation.md
rm -f tickets/active/2026-06-03-robust-pi-subagents.md
rm -rf tickets/artifacts/2026-06-03-robust-pi-subagents
```

Because `docs/qrspi-adaptation.md` and the ticket artifacts are currently untracked, deleting them is sufficient unless they are later committed.
