pi-orchestrator-config 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +808 -0
  2. package/agents/api-documenter.md +32 -0
  3. package/agents/bash-expert.md +53 -0
  4. package/agents/code-reviewer-docs.md +145 -0
  5. package/agents/code-reviewer-guidelines.md +97 -0
  6. package/agents/code-reviewer-quality.md +142 -0
  7. package/agents/code-reviewer-security.md +107 -0
  8. package/agents/code-reviewer-spec.md +164 -0
  9. package/agents/debugger.md +63 -0
  10. package/agents/docker-expert.md +40 -0
  11. package/agents/docs-fetcher.md +48 -0
  12. package/agents/git-expert.md +63 -0
  13. package/agents/github-expert.md +83 -0
  14. package/agents/go-expert.md +62 -0
  15. package/agents/issue-reviewer-feasibility.md +60 -0
  16. package/agents/issue-reviewer-scope.md +63 -0
  17. package/agents/issue-reviewer-spec.md +77 -0
  18. package/agents/java-expert.md +31 -0
  19. package/agents/jenkins-expert.md +38 -0
  20. package/agents/kubernetes-expert.md +40 -0
  21. package/agents/planner.md +42 -0
  22. package/agents/python-expert.md +61 -0
  23. package/agents/reviewer.md +26 -0
  24. package/agents/scout.md +40 -0
  25. package/agents/security-auditor.md +254 -0
  26. package/agents/technical-documentation-writer.md +37 -0
  27. package/agents/test-automator.md +55 -0
  28. package/agents/test-runner.md +47 -0
  29. package/agents/ts-expert.md +23 -0
  30. package/agents/worker.md +30 -0
  31. package/extensions/acpx-provider/index.ts +104 -0
  32. package/extensions/acpx-provider/load-runtime.ts +99 -0
  33. package/extensions/acpx-provider/runtime-models.ts +40 -0
  34. package/extensions/cli-provider/agents/claude.ts +128 -0
  35. package/extensions/cli-provider/agents/cursor.ts +84 -0
  36. package/extensions/cli-provider/agents/gemini.ts +100 -0
  37. package/extensions/cli-provider/discover.ts +77 -0
  38. package/extensions/cli-provider/index.ts +57 -0
  39. package/extensions/cli-provider/parsers.ts +304 -0
  40. package/extensions/cli-provider/providers.ts +58 -0
  41. package/extensions/cli-provider/runner.ts +225 -0
  42. package/extensions/cli-provider/runtime-models.ts +32 -0
  43. package/extensions/cli-provider/session-reaper.ts +122 -0
  44. package/extensions/cli-provider/sessions.ts +533 -0
  45. package/extensions/cli-provider/shared/discover-cache.ts +235 -0
  46. package/extensions/cli-provider/types.ts +48 -0
  47. package/extensions/coms/coms-net-server.ts +1642 -0
  48. package/extensions/coms/coms-net-wrapper.ts +521 -0
  49. package/extensions/coms/coms-net.ts +1589 -0
  50. package/extensions/coms/coms-p2p.ts +1879 -0
  51. package/extensions/coms/coms-shared.ts +510 -0
  52. package/extensions/coms/coms-wrapper.ts +138 -0
  53. package/extensions/coms/index.ts +20 -0
  54. package/extensions/coms/themeMap.ts +147 -0
  55. package/extensions/image-gen/image-gen.ts +332 -0
  56. package/extensions/image-gen/index.ts +14 -0
  57. package/extensions/orchestrator/agents.ts +134 -0
  58. package/extensions/orchestrator/ask-user.ts +293 -0
  59. package/extensions/orchestrator/async-agents.ts +1037 -0
  60. package/extensions/orchestrator/async-capability.ts +129 -0
  61. package/extensions/orchestrator/async-runner.ts +324 -0
  62. package/extensions/orchestrator/async-status-parse.ts +31 -0
  63. package/extensions/orchestrator/async-status-ui.ts +201 -0
  64. package/extensions/orchestrator/async-wait.ts +36 -0
  65. package/extensions/orchestrator/btw.ts +210 -0
  66. package/extensions/orchestrator/cron-status-format.ts +126 -0
  67. package/extensions/orchestrator/cron-status-ui.ts +132 -0
  68. package/extensions/orchestrator/cron.ts +730 -0
  69. package/extensions/orchestrator/dreaming.ts +355 -0
  70. package/extensions/orchestrator/enforcement-helpers.ts +530 -0
  71. package/extensions/orchestrator/enforcement-rules.ts +329 -0
  72. package/extensions/orchestrator/enforcement.ts +828 -0
  73. package/extensions/orchestrator/extended-autocomplete.ts +593 -0
  74. package/extensions/orchestrator/git-helpers.ts +420 -0
  75. package/extensions/orchestrator/github-autocomplete.ts +250 -0
  76. package/extensions/orchestrator/icons.ts +17 -0
  77. package/extensions/orchestrator/index.ts +100 -0
  78. package/extensions/orchestrator/memory-embeddings.ts +281 -0
  79. package/extensions/orchestrator/memory-promotion.ts +449 -0
  80. package/extensions/orchestrator/memory-provenance.ts +80 -0
  81. package/extensions/orchestrator/memory-query-class.ts +90 -0
  82. package/extensions/orchestrator/memory-scoring.ts +434 -0
  83. package/extensions/orchestrator/memory-tools.ts +883 -0
  84. package/extensions/orchestrator/memory-tree.ts +212 -0
  85. package/extensions/orchestrator/nvim.ts +169 -0
  86. package/extensions/orchestrator/overlay-dashboard-utils.ts +25 -0
  87. package/extensions/orchestrator/overlay-dashboard.ts +512 -0
  88. package/extensions/orchestrator/pi-config-review-state.ts +303 -0
  89. package/extensions/orchestrator/preference-extractor.ts +106 -0
  90. package/extensions/orchestrator/project-settings.ts +468 -0
  91. package/extensions/orchestrator/promotion-queue.ts +311 -0
  92. package/extensions/orchestrator/resolve-agent-model.ts +32 -0
  93. package/extensions/orchestrator/review-ui.ts +204 -0
  94. package/extensions/orchestrator/rule-placeholders.ts +12 -0
  95. package/extensions/orchestrator/rules.ts +481 -0
  96. package/extensions/orchestrator/session-search.ts +243 -0
  97. package/extensions/orchestrator/session-validation.ts +374 -0
  98. package/extensions/orchestrator/situation-report.ts +370 -0
  99. package/extensions/orchestrator/status-bar.ts +31 -0
  100. package/extensions/orchestrator/status-line.ts +192 -0
  101. package/extensions/orchestrator/status.ts +110 -0
  102. package/extensions/orchestrator/subagent-tool.ts +1748 -0
  103. package/extensions/orchestrator/task-lifecycle.ts +88 -0
  104. package/extensions/orchestrator/utils.ts +227 -0
  105. package/extensions/pidash/index.ts +15 -0
  106. package/extensions/pidash/pidash.ts +941 -0
  107. package/extensions/pidiff/index.ts +13 -0
  108. package/extensions/pidiff/pidiff.ts +369 -0
  109. package/extensions/providers/acpx-driver.ts +479 -0
  110. package/extensions/providers/built-in-drivers.ts +52 -0
  111. package/extensions/providers/claude-driver.ts +319 -0
  112. package/extensions/providers/cursor-acpx-driver.ts +398 -0
  113. package/extensions/providers/cursor-cli-driver.ts +484 -0
  114. package/extensions/providers/gemini-driver.ts +302 -0
  115. package/extensions/providers/index.ts +513 -0
  116. package/extensions/shared/build-system-prompt.ts +57 -0
  117. package/extensions/shared/create-runtime-provider.ts +190 -0
  118. package/extensions/shared/daemon-manager.ts +248 -0
  119. package/extensions/shared/file-logger.ts +115 -0
  120. package/extensions/shared/managed-refresh.ts +211 -0
  121. package/extensions/shared/provider-driver.ts +295 -0
  122. package/extensions/shared/provider-errors.ts +305 -0
  123. package/extensions/shared/provider-registry.ts +388 -0
  124. package/extensions/shared/stream-builder.ts +275 -0
  125. package/extensions/shared/types.ts +20 -0
  126. package/extensions/shared/ui/README.md +10 -0
  127. package/extensions/shared/ui/badge.tsx +52 -0
  128. package/extensions/shared/ui/button.tsx +58 -0
  129. package/extensions/shared/ui/collapsible.tsx +21 -0
  130. package/extensions/shared/ui/dropdown-menu.tsx +266 -0
  131. package/extensions/shared/ui/input.tsx +20 -0
  132. package/extensions/shared/ui/popover.tsx +114 -0
  133. package/extensions/shared/ui/resizable.tsx +48 -0
  134. package/extensions/shared/ui/scroll-area.tsx +53 -0
  135. package/extensions/shared/ui/select.tsx +201 -0
  136. package/extensions/shared/ui/separator.tsx +25 -0
  137. package/extensions/shared/ui/tooltip.tsx +64 -0
  138. package/extensions/shared/ws-client.ts +74 -0
  139. package/package.json +59 -0
  140. package/prompts/coderabbit-rate-limit.md +95 -0
  141. package/prompts/create-coms-feature-manager.md +186 -0
  142. package/prompts/create-skill.md +128 -0
  143. package/prompts/domain-model.md +109 -0
  144. package/prompts/external-ai.md +665 -0
  145. package/prompts/implement-and-review.md +25 -0
  146. package/prompts/implement.md +26 -0
  147. package/prompts/issue-review.md +256 -0
  148. package/prompts/pr-review.md +753 -0
  149. package/prompts/query-db.md +154 -0
  150. package/prompts/refine-review.md +208 -0
  151. package/prompts/release.md +235 -0
  152. package/prompts/remember.md +33 -0
  153. package/prompts/review-handler-status.md +27 -0
  154. package/prompts/review-handler.md +677 -0
  155. package/prompts/review-local.md +159 -0
  156. package/prompts/scout-and-plan.md +21 -0
  157. package/rules/00-orchestrator-core.md +42 -0
  158. package/rules/05-issue-first-workflow.md +119 -0
  159. package/rules/10-agent-routing.md +58 -0
  160. package/rules/15-mcp-launchpad.md +46 -0
  161. package/rules/20-code-review-loop.md +234 -0
  162. package/rules/25-documentation-updates.md +15 -0
  163. package/rules/30-prompt-templates.md +19 -0
  164. package/rules/35-memory.md +240 -0
  165. package/rules/40-critical-rules.md +124 -0
  166. package/rules/45-file-preview.md +29 -0
  167. package/rules/50-agent-bug-reporting.md +90 -0
  168. package/rules/55-coms-protocol.md +63 -0
  169. package/rules/60-task-tracking.md +66 -0
  170. package/skills/conflict-resolver/SKILL.md +213 -0
  171. package/skills/skill-creator/SKILL.md +85 -0
  172. package/skills/systematic-debugging/SKILL.md +353 -0
  173. package/skills/test-driven-development/SKILL.md +335 -0
  174. package/skills/update-agents-md/SKILL.md +282 -0
  175. package/templates/coms-feature-manager-prompt.md +313 -0
@@ -0,0 +1,665 @@
1
+ ---
2
+ description: "Run a prompt via ai-cli-runner to any AI CLI (cursor, claude, gemini). Full model access including all variants. Use for peer review, code review, or any task — /external-ai <agent> [--model <model>] [--fix|--peer|--resume] <prompt>"
3
+ argument-hint: "<agent> [--model <model>] [--fix|--peer|--resume] <prompt>"
4
+ ---
5
+
6
+ ## Raw Arguments
7
+
8
+ ```text
9
+ $ARGUMENTS
10
+ ```
11
+
12
+ # ai-cli-runner Multi-Agent Prompt Command
13
+
14
+ > **Bug Reporting Policy:** If you encounter ANY error, unexpected behavior, or reproducible bug
15
+ > while executing this command — DO NOT work around it silently. Ask the user:
16
+ > "Should I create a GitHub issue for this?" Route to:
17
+ > `myk-org/pi-config` for plugin/command spec issues,
18
+ > `myk-org/ai-cli-runner` for ai-cli-runner package issues.
19
+ > Do not silently skip steps or apply manual fixes that hide the root cause.
20
+
21
+ 🚨 **CRITICAL: NEVER set a timeout on AI CLI execution commands** (Step 5 and Step 9).
22
+ External agents can take minutes to complete (reading files, thinking, multi-step tool calls).
23
+ Any bash call running an AI CLI prompt MUST NOT include a timeout parameter. Let it run
24
+ until it finishes. Quick probes (`--version`, model listing) may use bounded timeouts (e.g., 30s).
25
+
26
+ Run a prompt through [ai-cli-runner](https://github.com/myk-org/ai-cli-runner) which calls
27
+ AI CLI tools directly via subprocess — giving full model access including all variants
28
+ (reasoning levels, fast mode, context sizes).
29
+
30
+ ## Supported Providers
31
+
32
+ | Provider | Binary | Notes |
33
+ |----------|--------|-------|
34
+ | `cursor` | `agent` | `--print` for non-interactive, `--workspace` for cwd |
35
+ | `claude` | `claude` | `-p` for non-interactive print mode |
36
+ | `gemini` | `gemini` | Stdin prompt |
37
+
38
+ For other providers (codex, copilot, droid, kiro, etc.), use `/acpx-prompt` instead.
39
+
40
+ ## Usage
41
+
42
+ - `/external-ai cursor fix the tests`
43
+ - `/external-ai claude review this code`
44
+ - `/external-ai gemini explain this function`
45
+ - `/external-ai cursor --model gpt-5.4-high review the architecture`
46
+ - `/external-ai cursor --model claude-4.6-opus-max-thinking --fix fix the code`
47
+ - `/external-ai cursor --fix fix the code quality issues`
48
+ - `/external-ai cursor --peer review this code`
49
+ - `/external-ai cursor --model gpt-5.4-xhigh --peer review the architecture`
50
+ - `/external-ai cursor,claude review this code`
51
+ - `/external-ai cursor --resume explain the last change`
52
+ - `/external-ai cursor --model gpt-5.4-high --resume continue reviewing`
53
+ - `/external-ai claude --resume what about the edge cases?`
54
+ - `/external-ai review this code` — uses last saved agent from `.pi/external-ai-config.json`
55
+ - `/external-ai --peer review this` — uses last saved peers from `.pi/external-ai-config.json`
56
+
57
+ ## Workflow
58
+
59
+ ### Step 1: Prerequisites Check
60
+
61
+ ```bash
62
+ myk-pi-tools --version
63
+ ```
64
+
65
+ If not found, prompt to install: `uv tool install myk-pi-tools`
66
+
67
+ ### Step 2: Parse Arguments
68
+
69
+ Read the **Raw Arguments** section above. Tokenize by whitespace and parse as follows:
70
+
71
+ 1. **Consume flags** — strip `--fix`, `--peer`, `--resume`, and `--model <value>` from the token stream.
72
+ `--model` consumes the NEXT token as the model value.
73
+ 2. **Detect agent spec** — the next non-flag token is an agent spec if it matches a known provider name
74
+ or is a comma-separated list of provider names.
75
+ 3. **Remainder is the prompt** — everything after the agent spec (or after flags if no agent)
76
+
77
+ **Known providers:** `cursor`, `claude`, `gemini`
78
+
79
+ **Unknown provider handling:** If any agent name is not one of the 3 known providers,
80
+ abort with: "Unknown provider: `<name>`. Supported: cursor, claude, gemini.
81
+ For other agents (codex, copilot, droid, kiro, etc.), use `/acpx-prompt` instead."
82
+
83
+ **Flag validation:**
84
+
85
+ - `--model` takes the next token as its value. If `--model` appears without a value,
86
+ abort with: "`--model` requires a model name (e.g., `--model gpt-5.4-high`)."
87
+ - `--model` can be combined with any other flag (`--fix`, `--peer`, `--resume`).
88
+ - `--resume` can be combined with `--fix` but NOT with `--peer` (peer mode manages sessions automatically).
89
+ If `--resume` and `--peer` are both passed, abort with: "`--resume` and `--peer` cannot be used together — peer mode manages sessions automatically."
90
+ - `--fix` and `--peer` are **mutually exclusive**. If both are passed,
91
+ abort with: "`--fix` and `--peer` cannot be used together."
92
+ - Multiple agents and `--fix` are **mutually exclusive**. If more than one
93
+ agent is specified with `--fix`, abort with:
94
+ "`--fix` can only be used with a single agent."
95
+ - If `--fix` appears more than once, abort with: "Duplicate --fix flag."
96
+ - If `--peer` appears more than once, abort with: "Duplicate --peer flag."
97
+ - If `--resume` appears more than once, abort with: "Duplicate --resume flag."
98
+
99
+ **Parsing order:**
100
+
101
+ 1. **Consume leading flags first** — strip any `--fix` or `--peer` from the token stream
102
+ 2. **Check if the next token is an agent spec** — a token is an agent spec if:
103
+ - It matches a known provider name exactly (e.g., `cursor`, `claude`)
104
+ - OR it's a comma-separated list where ALL parts match known provider names
105
+ 3. **If the first non-flag token looks like an agent but contains unknown names**, abort with
106
+ the unknown provider message above
107
+ 4. **If no agent spec found** (first non-flag token is not a recognized provider), fall through
108
+ to saved config below
109
+
110
+ **Resolve provider and model (global rule — ALL modes):**
111
+
112
+ Saved config: `.pi/external-ai-config.json` with `lastAgents` and `lastPeers` fields.
113
+ Read it: `cat .pi/external-ai-config.json 2>/dev/null`.
114
+
115
+ For any missing piece (provider or model), fill from saved config and confirm:
116
+
117
+ 1. **Provider missing?** Check saved config (`lastAgents` or `lastPeers` depending on mode).
118
+ If saved config exists, ask: `Last used: SAVED_VALUE. Use this?` (Yes/Change/Cancel).
119
+ If no saved config, ask: `Select provider:` with options `cursor`, `claude`, `gemini`, `Cancel`.
120
+ For `--peer` without providers: `Select providers:` with `cursor,claude`, `cursor,gemini`,
121
+ `claude,gemini`, `cursor,claude,gemini`, `Cancel`.
122
+ 2. **Model missing?** For EACH provider without a `--model`, ask:
123
+ `Select model for PROVIDER:` — run:
124
+ `myk-pi-tools ai-cli models PROVIDER 2>/dev/null`
125
+ The command outputs a JSON array to stdout. Parse it directly — do NOT
126
+ pipe through python or any other tool. Present ALL model IDs from the
127
+ `id` field as ask_user options. Do NOT filter, subset, or cherry-pick.
128
+ Add `default (DEFAULT_MODEL)` and `Cancel` at the end.
129
+ 3. **Prompt missing?** Abort: `No prompt provided.`
130
+
131
+ The user must always know exactly which provider+model will be used before execution.
132
+
133
+ **Default model handling:** If no `--model` was specified for a provider,
134
+ you must still pass a model to `ai-cli-runner`. Use these defaults:
135
+
136
+ | Provider | Default model |
137
+ |----------|---------------|
138
+ | `cursor` | `composer-2-fast` |
139
+ | `claude` | `claude-sonnet-4-6` |
140
+ | `gemini` | `gemini-2.5-flash` |
141
+
142
+ These match each CLI's default behavior. When generating the Python script (Step 5),
143
+ use the default model if none was specified by the user.
144
+
145
+ When `--model` is specified, use that model.
146
+ When not specified, use the default from the table above.
147
+
148
+ ### Step 2b: Display Execution Summary
149
+
150
+ Before proceeding, display a summary of what will be executed so the user knows
151
+ exactly what is about to be sent. **No black magic.**
152
+
153
+ ```text
154
+ Provider: <provider>
155
+ Model: <model> (or "default: <default_model>" if using default)
156
+ Mode: <read-only | fix | peer>
157
+ Resume: <yes | no>
158
+ ```
159
+
160
+ No confirmation prompt needed — the user already confirmed by providing arguments
161
+ or selecting from the interactive prompts above.
162
+
163
+ ### Step 3: Session Management
164
+
165
+ Sessions allow the AI CLI to maintain conversation context across prompts.
166
+ `ai-cli-runner` exposes `session_id` and `continue_session` params, and returns
167
+ `session_id` in the result. The `myk-pi-tools ai-cli run` command supports:
168
+
169
+ - `--resume` — continue the most recent session (`continue_session=True`)
170
+ - `--session-id <id>` — resume a specific session by ID (exact targeting)
171
+ - `--cli-flags <flag>` — extra flags passed to the AI CLI binary (repeatable)
172
+
173
+ **Session behavior by mode:**
174
+
175
+ | Mode | Session behavior |
176
+ |------|------------------|
177
+ | **Normal** (no flags) | Stateless — fresh session each call |
178
+ | **`--resume`** | Continue the most recent session |
179
+ | **`--session-id <id>`** | Resume a specific session by ID |
180
+ | **`--fix`** | Stateless by default. Combine with `--resume` or `--session-id` to continue a session |
181
+ | **`--peer`** | Automatic sessions — first round is fresh, subsequent rounds use `--session-id <id>` captured from the first round's output to maintain exact conversation context. Do NOT combine with `--resume` |
182
+
183
+ When `--resume` is active, pass `--resume` to the `myk-pi-tools ai-cli run` command.
184
+ In peer mode follow-up rounds, pass `--session-id <id>` instead of `--resume`
185
+ for exact session targeting (see Step 9).
186
+
187
+ ### Step 4: Workspace Safety Check (--fix and --peer modes)
188
+
189
+ **Skip this step if neither --fix nor --peer was passed.**
190
+
191
+ Before running in fix or peer mode, inspect the workspace state.
192
+
193
+ ```bash
194
+ git rev-parse --is-inside-work-tree
195
+ git status --short
196
+ ```
197
+
198
+ Follow this decision process:
199
+
200
+ 1. If the current directory is not a Git repository, ask the user via
201
+ AskUserQuestion:
202
+ "This directory is not a Git repository. Continue anyway?
203
+ I won't be able to show a git diff or provide an easy rollback point."
204
+ 2. If the current directory is a Git repository and `git status --short`
205
+ shows any output (modified, staged, or untracked files), ask the user via
206
+ AskUserQuestion with the following options (in this order):
207
+ - **Commit first (Recommended)** — Create a checkpoint commit of the
208
+ current changes before proceeding, so the agent's changes are
209
+ cleanly isolated
210
+ - **Continue anyway** — Proceed despite uncommitted changes; the final
211
+ diff summary may include pre-existing edits
212
+ - **Abort** — Stop here to handle changes manually
213
+ 3. Handle the response:
214
+ - **Commit first**: Stage only tracked modified files with `git add -u`
215
+ and create a checkpoint commit with the message
216
+ `chore: checkpoint before ai-cli changes`. This avoids staging
217
+ untracked files (e.g., `.envrc`, `.claude/`) that may contain
218
+ secrets or local config. After the commit, proceed. If untracked
219
+ files remain, that is expected — do not treat them as dirty.
220
+ If the commit fails, display the raw output and abort.
221
+ - **Continue anyway**: Proceed and remember the workspace was dirty.
222
+ - **Abort**: Stop immediately.
223
+ 4. If the user declines the non-git prompt from step 1, abort.
224
+ 5. If proceeding despite a dirty worktree (via **Continue anyway**),
225
+ remember that state so Steps 7-8 (`--fix`) or Step 9e (`--peer`)
226
+ can warn that diffs may include pre-existing edits.
227
+
228
+ ### Step 5: Run Prompt
229
+
230
+ **If `--peer` was passed, skip Steps 5-8 and jump to Step 9 (Peer Review Loop).**
231
+
232
+ **MANDATORY:** Always use `myk-pi-tools ai-cli run` — never generate inline Python scripts.
233
+
234
+ **Single provider:**
235
+
236
+ ```bash
237
+ myk-pi-tools ai-cli run --provider <PROVIDER> --model <MODEL> [--cli-flags=<FLAG>...] "<PROMPT>"
238
+ ```
239
+
240
+ With resume:
241
+
242
+ ```bash
243
+ myk-pi-tools ai-cli run --provider <PROVIDER> --model <MODEL> --resume "<PROMPT>"
244
+ ```
245
+
246
+ **Multi-agent execution:**
247
+
248
+ When multiple providers are specified (without `--peer`), run all agents **in parallel**
249
+ by delegating each to a separate subagent or running sequential CLI calls:
250
+
251
+ ```bash
252
+ myk-pi-tools ai-cli run --provider <P1> --model <M1> "<PROMPT>"
253
+ myk-pi-tools ai-cli run --provider <P2> --model <M2> "<PROMPT>"
254
+ ```
255
+
256
+ Collect results from all providers and display grouped by provider.
257
+
258
+ **Read-only prompt guard (non-fix mode):**
259
+
260
+ When `--fix` is NOT passed, append to the user's prompt:
261
+
262
+ ```text
263
+ IMPORTANT: This is a read-only request. Do NOT modify, create, or
264
+ delete any files. Report your findings only.
265
+ ```
266
+
267
+ In fix mode, append to the user's prompt:
268
+
269
+ ```text
270
+ You have full permission to modify, create, and delete files as needed.
271
+ Make all necessary changes directly.
272
+ ```
273
+
274
+ **No timeout:** NEVER pass a timeout parameter to bash when running ai-cli commands.
275
+ Agents need time to read files, think, and execute multi-step tool calls.
276
+
277
+ **Error handling:**
278
+
279
+ If the command exits with a non-zero code:
280
+
281
+ - If the error indicates a **permission failure** (write denied, permission
282
+ rejected, or similar), this means the agent attempted to modify files
283
+ without `--fix` mode. Retry the prompt once with a stricter instruction
284
+ appended:
285
+
286
+ ```text
287
+ CRITICAL: You are NOT allowed to modify any files. Your previous
288
+ attempt was blocked because you tried to write files. This is a
289
+ read-only review. Report findings as text only. Do NOT use any
290
+ file modification tools.
291
+ ```
292
+
293
+ If the retry also fails with a permission error, display the error
294
+ and abort.
295
+
296
+ - For any other error, display the raw output as an error.
297
+
298
+ ### Step 6: Display Result
299
+
300
+ Display the output to the user.
301
+
302
+ The CLI outputs structured JSON to stdout:
303
+
304
+ ```json
305
+ {
306
+ "success": true,
307
+ "text": "<response>",
308
+ "provider": "cursor",
309
+ "model": "gpt-5.4-high",
310
+ "usage": {
311
+ "input_tokens": 1234,
312
+ "output_tokens": 567,
313
+ "cache_read_tokens": 890,
314
+ "cost_usd": 0.0123,
315
+ "duration_ms": 5000
316
+ }
317
+ }
318
+ ```
319
+
320
+ Parse the JSON and display:
321
+
322
+ 1. The agent's response text
323
+ 2. A usage summary:
324
+
325
+ ```text
326
+ Provider: <provider>
327
+ Model: <model>
328
+ Mode: [read-only | fix]
329
+ Tokens: in=<input_tokens> out=<output_tokens> cache_read=<cache_read_tokens>
330
+ Cost: $<cost_usd>
331
+ Duration: <duration_ms>ms
332
+ ```
333
+
334
+ Omit fields that are missing or zero. On error (`"success": false`), display the `error` field.
335
+
336
+ **Save config:** See "Persist Config" section after Step 9e.
337
+
338
+ ### Step 7: Read Diff (--fix mode only)
339
+
340
+ **Skip this step if --fix was NOT passed or if the command failed.**
341
+
342
+ After the agent completes in fix mode, inspect what changed:
343
+
344
+ ```bash
345
+ git status --short
346
+ git diff --stat
347
+ git diff
348
+ git diff --cached --stat
349
+ git diff --cached
350
+ ```
351
+
352
+ If the diff is too large (over ~200 lines), use `--stat` summary only.
353
+
354
+ If the workspace was already dirty before running, note that the diff
355
+ may include pre-existing edits.
356
+
357
+ Report to the user:
358
+
359
+ - Which files were modified/created/deleted
360
+ - A summary of the changes
361
+ - Verify suggestion: what command to run to confirm changes work
362
+
363
+ ### Step 8: Summary (--fix mode only)
364
+
365
+ **Skip this step if --fix was NOT passed or if the command failed.**
366
+
367
+ Present a clear summary:
368
+
369
+ 1. **Files changed** — List each file with what was modified
370
+ 2. **What was done** — Brief description in plain language
371
+ 3. **Impact** — Behavioral changes, new dependencies, verification steps
372
+
373
+ ### Step 9: Peer Review Loop (--peer mode only)
374
+
375
+ **Skip this step if --peer was NOT passed.**
376
+
377
+ Claude orchestrates an AI-to-AI debate loop with the target agent(s) until
378
+ all participants agree on the code. When multiple agents are specified,
379
+ each agent reviews independently in parallel, and Claude evaluates the
380
+ merged findings.
381
+
382
+ **CRITICAL RULE: Only the peer agent(s) can end the loop.** Claude fixing
383
+ code does NOT count as convergence. After EVERY fix round, Claude MUST
384
+ send the fixes back to the peer agent(s) (Step 9c) for re-review. The loop
385
+ ends ONLY when each peer agent confirms no remaining issues. With multiple
386
+ peers, ALL peer agents must agree before the loop exits.
387
+
388
+ #### 9a: Initial Agent Review
389
+
390
+ Initialize a round counter at 1. Use the current counter value in the Step 9c
391
+ response template (`Round {N}`), then increment the counter after sending.
392
+
393
+ Before sending the peer framing prompt, check if `AGENTS.md` exists
394
+ in the project. If it does, include the AGENTS.md convention block
395
+ in the framing prompt. If `AGENTS.md` does not exist, omit that
396
+ block from the prompt.
397
+
398
+ Send the first prompt to the agent with peer review framing:
399
+
400
+ **If `AGENTS.md` exists:**
401
+
402
+ ```text
403
+ IMPORTANT FRAMING: You are participating in a peer-to-peer AI code
404
+ review. The other participant is another AI (Claude). This is NOT a
405
+ human interaction. Do NOT be agreeable or sycophantic. Hold your
406
+ position when you have valid technical reasoning. Push back when you
407
+ disagree. Only concede a point when the other AI provides a genuinely
408
+ better technical argument.
409
+
410
+ IMPORTANT: This project has a AGENTS.md file with coding conventions
411
+ and project guidelines. Read it before reviewing. Flag any violations
412
+ of those conventions as findings.
413
+
414
+ Your role: Review the code and report findings. Be direct, specific,
415
+ and technically rigorous. For each finding, explain WHY it matters and
416
+ provide a concrete fix or suggestion.
417
+
418
+ Original prompt: <user's prompt>
419
+ ```
420
+
421
+ **If `AGENTS.md` does NOT exist:**
422
+
423
+ ```text
424
+ IMPORTANT FRAMING: You are participating in a peer-to-peer AI code
425
+ review. The other participant is another AI (Claude). This is NOT a
426
+ human interaction. Do NOT be agreeable or sycophantic. Hold your
427
+ position when you have valid technical reasoning. Push back when you
428
+ disagree. Only concede a point when the other AI provides a genuinely
429
+ better technical argument.
430
+
431
+ Your role: Review the code and report findings. Be direct, specific,
432
+ and technically rigorous. For each finding, explain WHY it matters and
433
+ provide a concrete fix or suggestion.
434
+
435
+ Original prompt: <user's prompt>
436
+ ```
437
+
438
+ Execute via `myk-pi-tools ai-cli run` (read-only mode — append the read-only guard to the prompt).
439
+ This first round is a **fresh session** — do NOT pass `--resume` or `--session-id`.
440
+ Do NOT display intermediate results to the user.
441
+ If the command fails, abort the peer loop and report the error.
442
+
443
+ **Capture session_id:** Parse the JSON output from the first round. Extract
444
+ `session_id` from the response. Store it per-provider for use in subsequent
445
+ rounds (Step 9c). The `session_id` enables exact session targeting instead
446
+ of generic `--resume`.
447
+
448
+ **Multi-agent:** Send the peer framing prompt to ALL agents in parallel
449
+ using `run_parallel_with_limit`. Collect and merge findings from all agents,
450
+ deduplicating where the same issue is raised by multiple agents.
451
+
452
+ **Multi-agent group context:** In the first round, each agent reviews
453
+ independently (no group context yet). Their individual responses are
454
+ collected for use in subsequent rounds. Store each provider's `session_id`.
455
+
456
+ If ALL agents report no findings, skip to Step 9e.
457
+ If only SOME agents report no findings, continue to Step 9b with the findings
458
+ from agents that did report issues.
459
+
460
+ #### 9b: Claude Acts on Findings
461
+
462
+ For each finding from the agent(s):
463
+
464
+ 1. **Evaluate the finding** — Does Claude agree it's a valid issue?
465
+ 2. **If Claude agrees** — Fix the code by delegating to the
466
+ appropriate specialist agent (follow the normal agent routing rules).
467
+ 3. **If Claude disagrees** — Prepare a technical counter-argument
468
+ explaining WHY the finding is not valid, not applicable, or would
469
+ cause other issues.
470
+
471
+ **Rules for disagreement:**
472
+
473
+ - Claude MUST provide specific technical reasoning, not just "I disagree"
474
+ - Reference the actual code, explain trade-offs, cite patterns or conventions
475
+ - If the project has established conventions (AGENTS.md, etc.) that
476
+ support Claude's position, cite them explicitly
477
+ - Claude should be open to changing its mind if the agent makes a good
478
+ point in the next round
479
+
480
+ **Multi-agent:** Merge and deduplicate findings from all agents.
481
+
482
+ **After completing all fixes and counter-arguments, proceed to Step 9c.
483
+ This is MANDATORY — do NOT skip to the summary.**
484
+
485
+ #### 9c: Claude Responds to Agent
486
+
487
+ After acting on all findings, send a response back to the agent:
488
+
489
+ ```text
490
+ PEER REVIEW RESPONSE — Round {N}
491
+
492
+ IMPORTANT FRAMING: You are in an ongoing peer-to-peer AI code review
493
+ with another AI (Claude). This is NOT a human interaction. Do NOT back
494
+ down from valid technical positions just to be agreeable.
495
+
496
+ Here is what I (Claude) did with your findings:
497
+
498
+ ADDRESSED:
499
+ {For each addressed finding:
500
+ "- Finding: {summary} → Fixed: {what was done}"}
501
+
502
+ NOT ADDRESSED (with reasoning):
503
+ {For each disagreement:
504
+ "- Finding: {summary} → Disagreed: {technical reason}"}
505
+
506
+ Please re-review the code. Focus on:
507
+ 1. Verify that addressed findings were fixed correctly
508
+ 2. Re-evaluate your positions on the disagreements
509
+ 3. Report any NEW issues you find in the updated code.
510
+ ```
511
+
512
+ **Multi-agent group context:** When multiple peers are involved, each
513
+ peer's response MUST include what ALL other peers said. Append a
514
+ "GROUP CONTEXT" section to the response for each peer:
515
+
516
+ ```text
517
+ GROUP CONTEXT — What other peers said in Round {N}:
518
+
519
+ {For each OTHER peer (not the recipient):
520
+ "## {peer_name} (model: {model}) findings:
521
+ {summary of that peer's findings and positions}
522
+ "}
523
+
524
+ Always include the model when the provider was invoked with `--model`.
525
+ If no model was specified, omit the model parenthetical (e.g., `## cursor findings:`).
526
+ ```
527
+
528
+ This enables a true group conversation where every peer has full
529
+ visibility into the discussion. Each peer can agree, disagree, or
530
+ build on other peers' findings.
531
+
532
+ When sending to peer A, include findings from peers B, C, etc.
533
+ When sending to peer B, include findings from peers A, C, etc.
534
+
535
+ Execute via `myk-pi-tools ai-cli run --session-id <id>` using the `session_id`
536
+ captured in Step 9a. Do NOT display intermediate results.
537
+ **Use `--session-id <id>`** for this and all subsequent rounds so the peer agent
538
+ resumes the exact conversation session from previous rounds. If `session_id` was
539
+ not captured (provider didn't return one), fall back to `--resume`.
540
+
541
+ **Multi-agent:** Send the response to ALL agents in parallel. Each agent uses
542
+ its own `--session-id <id>` captured from its first-round output.
543
+
544
+ #### 9d: Loop Until Convergence
545
+
546
+ Parse each agent's response:
547
+
548
+ - **No findings and no remaining disagreements** — All AIs agree. Exit loop.
549
+ - **New findings or continued disagreements** — Go to Step 9b.
550
+
551
+ **Convergence criteria (checked ONLY from each peer agent's response in Step 9c):**
552
+
553
+ - All agents explicitly state no remaining issues, OR
554
+ - All agents' responses contain no actionable findings (only acknowledgments)
555
+
556
+ **What does NOT count as convergence:**
557
+
558
+ - Claude fixing all findings (fixes must be verified by the agent)
559
+ - Claude agreeing with all findings (the agent must confirm the fixes are correct)
560
+ - A single round completing (minimum: agent reviews → Claude fixes → agent re-reviews)
561
+
562
+ **Multi-agent convergence:** ALL peers must independently confirm no remaining issues.
563
+
564
+ **Claude's behavior across rounds:**
565
+
566
+ - Claude SHOULD change its mind when a peer agent provides a better argument
567
+ - Claude SHOULD NOT stubbornly hold a position just to "win"
568
+ - If a disagreement persists for 3+ rounds on the same point, note it as
569
+ "unresolved disagreement" and move on
570
+
571
+ #### 9e: Summary to User
572
+
573
+ After the loop exits, present a comprehensive summary.
574
+
575
+ **Usage tracking (MANDATORY):** Parse the JSON output from EVERY `myk-pi-tools ai-cli run`
576
+ call during the peer review (all rounds). **Sum** `input_tokens`, `output_tokens`,
577
+ `cache_read_tokens`, and `cost_usd` across ALL rounds per provider to get totals.
578
+ Since peer review runs in the same session, the totals represent the full session cost.
579
+
580
+ ```text
581
+ ## Peer Review Complete — {N} round(s)
582
+
583
+ Provider(s): <provider>[, <provider2>, ...]
584
+
585
+ ### Findings Addressed ({count})
586
+
587
+ | # | File | Line | Finding | Fix Applied |
588
+ |---|------|------|---------|-------------|
589
+ | 1 | src/foo.py | 42 | Missing null check | Added guard clause |
590
+
591
+ ### Agreements Reached After Debate ({count})
592
+
593
+ | # | File | Finding | Rounds | Resolution |
594
+ |---|------|---------|--------|------------|
595
+ | 1 | src/baz.py | Error swallowing | 2 | Claude conceded, added logging |
596
+
597
+ ### Unresolved Disagreements ({count})
598
+
599
+ | # | File | Finding | Claude's Position | Agent(s) Position |
600
+ |---|------|---------|-------------------|------------------|
601
+ | 1 | src/qux.py | Naming convention | Follows project style | Prefers stdlib convention |
602
+
603
+ ### No Changes Needed ({count})
604
+
605
+ Items where the agent initially flagged but later agreed no change was needed.
606
+ ```
607
+
608
+ **Summary rules:**
609
+
610
+ - **Always use tables** — consistent format
611
+ - **Show both sides** for unresolved disagreements
612
+ - **Include round count** for debated items
613
+ - **Next steps reminder** — If any code was changed, end with:
614
+ "Next steps: Run tests and the standard review workflow before committing."
615
+ - **Dirty worktree warning** — If the workspace was already dirty before
616
+ the peer review, note: "Workspace had pre-existing changes; resulting
617
+ diffs may include edits not made during this peer review."
618
+
619
+ **Multi-agent group summary:** When multiple peers participated, add:
620
+
621
+ ```text
622
+ ### Group Dynamics
623
+
624
+ | Finding | Raised By | Agreed By | Resolution |
625
+ |---------|-----------|-----------|------------|
626
+ | Missing null check | cursor | claude, gemini | All agreed, fixed |
627
+ ```
628
+
629
+ ### Peer Review Usage
630
+
631
+ **Per round:**
632
+
633
+ | Round | Provider | Model | Input tokens | Output tokens | Cache read | Cost | Duration |
634
+ |-------|----------|-------|-------------|--------------|------------|------|----------|
635
+ | 1 | cursor | gpt-5.4-high | 27,668 | 1,423 | 24,064 | $0.0182 | 12s |
636
+ | 2 | cursor | gpt-5.4-high | 29,104 | 892 | 26,200 | $0.0171 | 9s |
637
+ | 3 | cursor | gpt-5.4-high | 30,332 | 416 | 28,100 | $0.0170 | 8s |
638
+
639
+ **Totals:**
640
+
641
+ | Provider | Model | Rounds | Input tokens | Output tokens | Cache read | Cost | Duration |
642
+ |----------|-------|--------|-------------|--------------|------------|------|----------|
643
+ | cursor | gpt-5.4-high | 3 | 87,104 | 2,731 | 78,364 | $0.0523 | 29s |
644
+
645
+ Total: tokens=87,104 in / 2,731 out / 78,364 cache, cost=$0.0523, duration=29s
646
+
647
+ **Save config:** See "Persist Config" section below.
648
+
649
+ ### Persist Config (runs once after successful completion)
650
+
651
+ After successful execution (Step 6 for normal mode, Step 9e for peer mode), persist
652
+ the agent spec using the CLI. Run exactly once per successful completion.
653
+
654
+ **Skip if any step failed** — do not persist config after errors or aborted runs.
655
+
656
+ ```bash
657
+ # After normal/fix mode:
658
+ myk-pi-tools ai-cli save-config --agents "<normalized agent string>"
659
+
660
+ # After peer mode (include models for each provider):
661
+ myk-pi-tools ai-cli save-config --peers "<provider1 --model model1,provider2 --model model2>"
662
+ ```
663
+
664
+ **Normalized agent string:** The exact agent spec used for the run, as the user would type it
665
+ (e.g., `cursor --model gpt-5.4-high`, `cursor,claude`).
@@ -0,0 +1,25 @@
1
+ ---
2
+ description: "Implement → 5 parallel reviewers → fix — /implement-and-review <task>"
3
+ argument-hint: "<task>"
4
+ ---
5
+
6
+ ## Raw Arguments
7
+
8
+ ```text
9
+ $ARGUMENTS
10
+ ```
11
+
12
+ Use the subagent tool with a chain of agents:
13
+
14
+ 1. **worker** — Implement the task from the raw arguments above.
15
+ Make all necessary code changes following project conventions.
16
+
17
+ 2. Run 5 review subagents **in parallel**:
18
+ - **code-reviewer-quality** — Review {previous} for code quality
19
+ - **code-reviewer-guidelines** — Review {previous} for guideline adherence
20
+ - **code-reviewer-security** — Review {previous} for bugs and security
21
+ - **code-reviewer-docs** — Review {previous} for documentation quality
22
+ - **code-reviewer-spec** — Review {previous} for spec compliance
23
+
24
+ 3. **worker** — Based on the review feedback from {previous}, fix all issues found.
25
+ Then report what was fixed.