@llblab/pi-actors 0.22.5 → 0.24.0

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 (180) hide show
  1. package/AGENTS.md +125 -59
  2. package/BACKLOG.md +88 -403
  3. package/CHANGELOG.md +39 -0
  4. package/README.md +14 -1
  5. package/dist/fixtures/protocol/actor-message-branch.json +13 -0
  6. package/dist/fixtures/protocol/artifact-manifest.json +9 -0
  7. package/dist/fixtures/protocol/mailbox-contract.json +15 -0
  8. package/dist/fixtures/protocol/recipe-summary.json +16 -0
  9. package/dist/fixtures/protocol/room-message.json +11 -0
  10. package/dist/fixtures/protocol/room-roster.json +11 -0
  11. package/dist/fixtures/protocol/run-inbox-message.json +9 -0
  12. package/dist/fixtures/protocol/run-outbox-event.json +9 -0
  13. package/dist/fixtures/protocol/run-state.json +10 -0
  14. package/dist/index.js +18 -2
  15. package/dist/lib/actor-inspector-tui.d.ts +4 -0
  16. package/dist/lib/actor-inspector-tui.js +58 -44
  17. package/dist/lib/actor-rooms.d.ts +16 -0
  18. package/dist/lib/actor-rooms.js +123 -28
  19. package/dist/lib/actor-worker.d.ts +13 -0
  20. package/dist/lib/actor-worker.js +86 -0
  21. package/dist/lib/async-runner.d.ts +5 -0
  22. package/dist/lib/async-runner.js +134 -0
  23. package/dist/lib/async-runs.d.ts +34 -2
  24. package/dist/lib/async-runs.js +224 -50
  25. package/dist/lib/build-dist.d.ts +5 -0
  26. package/dist/lib/build-dist.js +24 -0
  27. package/dist/lib/command-templates.js +5 -5
  28. package/dist/lib/conformance.d.ts +12 -0
  29. package/dist/lib/conformance.js +28 -0
  30. package/dist/lib/coordinator.d.ts +5 -0
  31. package/dist/lib/coordinator.js +557 -0
  32. package/dist/lib/limits.d.ts +11 -0
  33. package/dist/lib/limits.js +11 -0
  34. package/dist/lib/locker.d.ts +5 -0
  35. package/dist/lib/locker.js +310 -0
  36. package/dist/lib/mailbox-loop.d.ts +41 -0
  37. package/dist/lib/mailbox-loop.js +62 -0
  38. package/dist/lib/observability.d.ts +2 -2
  39. package/dist/lib/observability.js +57 -57
  40. package/dist/lib/output.js +4 -5
  41. package/dist/lib/prompts.d.ts +1 -1
  42. package/dist/lib/prompts.js +1 -1
  43. package/dist/lib/recipe-discovery.js +1 -0
  44. package/dist/lib/recipe-references.d.ts +11 -2
  45. package/dist/lib/recipe-references.js +29 -4
  46. package/dist/lib/recipe-usage.d.ts +2 -1
  47. package/dist/lib/recipe-usage.js +15 -3
  48. package/dist/lib/recipe-utils.d.ts +5 -0
  49. package/dist/lib/recipe-utils.js +385 -0
  50. package/dist/lib/runtime-notifier.js +3 -7
  51. package/dist/lib/runtime.js +12 -2
  52. package/dist/lib/state-readers.d.ts +21 -0
  53. package/dist/lib/state-readers.js +74 -0
  54. package/dist/lib/tools.js +198 -39
  55. package/dist/lib/validate-recipe.d.ts +6 -0
  56. package/dist/lib/validate-recipe.js +104 -0
  57. package/dist/recipes/actor-worker.json +35 -0
  58. package/dist/recipes/coordinator-locker.json +45 -0
  59. package/dist/recipes/lens-swarm.json +66 -0
  60. package/dist/recipes/locker.json +45 -0
  61. package/dist/recipes/music-player.json +38 -0
  62. package/dist/recipes/pipeline-architect-coordinator.json +95 -0
  63. package/dist/recipes/pipeline-artifact-bundle.json +100 -0
  64. package/dist/recipes/pipeline-artifact-report.json +58 -0
  65. package/dist/recipes/pipeline-artifact-write.json +72 -0
  66. package/dist/recipes/pipeline-async-run-ops.json +70 -0
  67. package/dist/recipes/pipeline-checkpoint-continuation.json +67 -0
  68. package/dist/recipes/pipeline-development-tasking.json +81 -0
  69. package/dist/recipes/pipeline-docs-maintenance.json +80 -0
  70. package/dist/recipes/pipeline-media-library.json +59 -0
  71. package/dist/recipes/pipeline-quorum-review.json +79 -0
  72. package/dist/recipes/pipeline-release-readiness.json +110 -0
  73. package/dist/recipes/pipeline-release-summary.json +88 -0
  74. package/dist/recipes/pipeline-repo-health.json +89 -0
  75. package/dist/recipes/pipeline-research-synthesis.json +94 -0
  76. package/dist/recipes/pipeline-review-readiness.json +54 -0
  77. package/dist/recipes/pipeline-room-swarm.json +50 -0
  78. package/dist/recipes/subagent-artifact.json +32 -0
  79. package/dist/recipes/subagent-checkpoint.json +33 -0
  80. package/dist/recipes/subagent-conflict-report.json +32 -0
  81. package/dist/recipes/subagent-contradiction-map.json +33 -0
  82. package/dist/recipes/subagent-critic.json +35 -0
  83. package/dist/recipes/subagent-evidence-map.json +33 -0
  84. package/dist/recipes/subagent-followup.json +33 -0
  85. package/dist/recipes/subagent-judge.json +33 -0
  86. package/dist/recipes/subagent-merge.json +33 -0
  87. package/dist/recipes/subagent-message.json +34 -0
  88. package/dist/recipes/subagent-normalize.json +31 -0
  89. package/dist/recipes/subagent-plan.json +33 -0
  90. package/dist/recipes/subagent-prompt.json +28 -0
  91. package/dist/recipes/subagent-quorum.json +43 -0
  92. package/dist/recipes/subagent-review-coordinator.json +114 -0
  93. package/dist/recipes/subagent-review.json +37 -0
  94. package/dist/recipes/subagent-task-card.json +35 -0
  95. package/dist/recipes/subagent-tools.json +27 -0
  96. package/dist/recipes/subagent-verify.json +34 -0
  97. package/dist/recipes/subagents-prompts.json +51 -0
  98. package/dist/recipes/utility-actor-message.json +23 -0
  99. package/dist/recipes/utility-artifact-manifest.json +16 -0
  100. package/dist/recipes/utility-artifact-write.json +16 -0
  101. package/dist/recipes/utility-changelog-head.json +11 -0
  102. package/dist/recipes/utility-changelog-section.json +13 -0
  103. package/dist/recipes/utility-coordinator-lock-snapshot.json +13 -0
  104. package/dist/recipes/utility-git-log.json +11 -0
  105. package/dist/recipes/utility-git-status.json +9 -0
  106. package/dist/recipes/utility-jsonl-tail.json +10 -0
  107. package/dist/recipes/utility-markdown-index.json +14 -0
  108. package/dist/recipes/utility-package-summary.json +11 -0
  109. package/dist/recipes/utility-playlist-build.json +17 -0
  110. package/dist/recipes/utility-playlist-scan.json +11 -0
  111. package/dist/recipes/utility-run-ops-snapshot.json +17 -0
  112. package/dist/recipes/utility-run-state-files.json +13 -0
  113. package/dist/recipes/utility-run-summary.json +11 -0
  114. package/dist/recipes/utility-skill-summary.json +13 -0
  115. package/dist/recipes/utility-validate-recipe.json +13 -0
  116. package/dist/recipes/utility-validation-wrapper.json +13 -0
  117. package/dist/scripts/actor-worker.mjs +31 -0
  118. package/dist/scripts/async-runner.mjs +31 -0
  119. package/dist/scripts/build-dist.mjs +25 -0
  120. package/dist/scripts/conformance.mjs +33 -0
  121. package/dist/scripts/coordinator.mjs +31 -0
  122. package/dist/scripts/locker.mjs +33 -0
  123. package/dist/scripts/music-player.mjs +964 -0
  124. package/dist/scripts/recipe-utils.mjs +31 -0
  125. package/dist/scripts/validate-recipe.mjs +34 -0
  126. package/dist/skills/actors/SKILL.md +375 -0
  127. package/dist/skills/swarm/SKILL.md +467 -0
  128. package/dist/skills/swarm/references/development-swarm.md +596 -0
  129. package/docs/actor-messages.md +2 -2
  130. package/docs/async-runs.md +13 -1
  131. package/docs/template-recipes.md +2 -2
  132. package/docs/tool-registry.md +0 -1
  133. package/fixtures/protocol/actor-message-branch.json +13 -0
  134. package/fixtures/protocol/artifact-manifest.json +9 -0
  135. package/fixtures/protocol/mailbox-contract.json +15 -0
  136. package/fixtures/protocol/recipe-summary.json +16 -0
  137. package/fixtures/protocol/room-message.json +11 -0
  138. package/fixtures/protocol/room-roster.json +11 -0
  139. package/fixtures/protocol/run-inbox-message.json +9 -0
  140. package/fixtures/protocol/run-outbox-event.json +9 -0
  141. package/fixtures/protocol/run-state.json +10 -0
  142. package/index.ts +21 -0
  143. package/lib/actor-inspector-tui.ts +138 -59
  144. package/lib/actor-rooms.ts +241 -60
  145. package/lib/actor-worker.ts +118 -0
  146. package/lib/async-runner.ts +173 -0
  147. package/lib/async-runs.ts +302 -53
  148. package/lib/build-dist.ts +30 -0
  149. package/lib/command-templates.ts +5 -5
  150. package/lib/conformance.ts +46 -0
  151. package/lib/coordinator.ts +649 -0
  152. package/lib/limits.ts +12 -0
  153. package/lib/locker.ts +340 -0
  154. package/lib/mailbox-loop.ts +148 -0
  155. package/lib/observability.ts +34 -23
  156. package/lib/output.ts +4 -6
  157. package/lib/prompts.ts +1 -1
  158. package/lib/recipe-discovery.ts +1 -0
  159. package/lib/recipe-references.ts +57 -6
  160. package/lib/recipe-usage.ts +31 -4
  161. package/lib/recipe-utils.ts +486 -0
  162. package/lib/runtime-notifier.ts +4 -6
  163. package/lib/runtime.ts +31 -7
  164. package/lib/state-readers.ts +93 -0
  165. package/lib/tools.ts +297 -58
  166. package/lib/validate-recipe.ts +110 -0
  167. package/package.json +11 -2
  168. package/recipes/actor-worker.json +35 -0
  169. package/recipes/pipeline-quorum-review.json +12 -7
  170. package/scripts/actor-worker.mjs +31 -0
  171. package/scripts/async-runner.mjs +11 -195
  172. package/scripts/build-dist.mjs +25 -0
  173. package/scripts/conformance.mjs +33 -0
  174. package/scripts/coordinator.mjs +19 -616
  175. package/scripts/locker.mjs +23 -322
  176. package/scripts/music-player.mjs +21 -2
  177. package/scripts/recipe-utils.mjs +20 -467
  178. package/scripts/validate-recipe.mjs +23 -113
  179. package/skills/actors/SKILL.md +7 -4
  180. package/skills/swarm/SKILL.md +3 -1
@@ -0,0 +1,596 @@
1
+ # Small-Team Development Swarm
2
+
3
+ Also known as `MAWP`: Multi-Agent Worktree Protocol.
4
+
5
+ Use this protocol when 2–4 implementation agents work on one project at the same time.
6
+ It is intentionally lighter than a full orchestrator runtime.
7
+
8
+ Core idea: do not block everything in advance. Isolate work surfaces, declare intent before edits, exchange context only after collisions, and merge through one integrator.
9
+
10
+ ## Core Shape
11
+
12
+ ```text
13
+ 1 project
14
+ → 1 shared backlog
15
+ → 2–4 isolated worktrees or branches
16
+ → each agent owns a small task card
17
+ → conflicts trigger structured context exchange
18
+ → one integrator merges
19
+ ```
20
+
21
+ Agents should not mutate the same `main` checkout concurrently. Prefer isolated branches or worktrees:
22
+
23
+ ```bash
24
+ git worktree add ../agent-a -b agent/a-task
25
+ git worktree add ../agent-b -b agent/b-task
26
+ git worktree add ../agent-c -b agent/c-task
27
+ ```
28
+
29
+ ## When To Use
30
+
31
+ Use this mode when:
32
+
33
+ - Work can be split into small file/domain scopes.
34
+ - Agents need to write code, docs, tests, or fixtures concurrently.
35
+ - A human or integrator-agent can merge patches.
36
+ - The project is not high-risk enough to justify a heavy orchestration platform.
37
+
38
+ Do not use this mode when:
39
+
40
+ - Tasks require the same public API files.
41
+ - The architecture direction is unsettled.
42
+ - The expected conflicts are semantic, not just file-level.
43
+ - No integrator is available.
44
+
45
+ ## Agent Role Split
46
+
47
+ Prefer splitting agents by **mutation class**, not by unrelated features.
48
+
49
+ Stable split:
50
+
51
+ ```text
52
+ Agent A: mutate behavior
53
+ Agent B: verify behavior
54
+ Agent C: describe behavior
55
+ Agent D: integrate behavior
56
+ ```
57
+
58
+ Practical mappings:
59
+
60
+ - `2 agents`: implementation; tests/docs/review.
61
+ - `3 agents`: implementation; tests; docs plus review.
62
+ - `4 agents`: implementation; tests; docs/examples; integrator/refactor/audit.
63
+
64
+ Recommended roles:
65
+
66
+ - `Implementation Agent`: writes logic; avoids docs unless needed for the task.
67
+ - `Test Agent`: writes tests and may expose bugs; avoids changing production logic.
68
+ - `Docs Agent`: updates docs/spec/examples/comments; avoids code.
69
+ - `Review/Integrator Agent`: reviews patches, resolves conflicts, runs checks, and merges.
70
+
71
+ Dangerous split:
72
+
73
+ ```text
74
+ Agent A: implement feature X
75
+ Agent B: implement feature Y
76
+ Agent C: refactor architecture
77
+ Agent D: clean up types
78
+ ```
79
+
80
+ This creates overlapping semantic ownership. Prefer behavior/test/docs/integration separation so agents do not compete for the same memetic niche.
81
+
82
+ ## Task Card
83
+
84
+ Every implementation agent gets a task card. The card is the unit of delegation.
85
+
86
+ ```markdown
87
+ # Task
88
+
89
+ Goal:
90
+
91
+ - What needs to be done.
92
+
93
+ Allowed files:
94
+
95
+ - Src/lib/foo.ts
96
+ - Src/routes/game/+page.svelte
97
+
98
+ Avoid files:
99
+
100
+ - Src/lib/shared/types.ts
101
+ - Src/lib/stores/\*
102
+
103
+ Expected output:
104
+
105
+ - Patch
106
+ - Short summary
107
+ - Tests/checks run
108
+ - Touched files list
109
+ ```
110
+
111
+ A task card should specify mutation zones, not just intent. The smaller the allowed file set, the less coordination machinery is needed.
112
+
113
+ Scope expansion is the main conflict generator. Agents must not opportunistically refactor unrelated code or silently edit outside the declared task. If an out-of-scope change is needed, write it as a new backlog item or ask the integrator to replan.
114
+
115
+ ## Backlog Partitioning
116
+
117
+ Use explicit task IDs when a coordinator will split backlog work across agents. File position is too fragile once agents start editing, while stable IDs can appear in scope files, branch names, handoffs, and review reports.
118
+
119
+ Recommended task card shape:
120
+
121
+ ```markdown
122
+ ## T-001: Add trust warnings
123
+
124
+ Labels:
125
+
126
+ - Docs
127
+ - Runtime
128
+
129
+ Allowed files:
130
+
131
+ - Docs/command-templates.md
132
+ - Lib/schema.ts
133
+
134
+ Avoid files:
135
+
136
+ - Package.json
137
+
138
+ Exit:
139
+
140
+ - Docs explain the trusted executable boundary.
141
+ - Tests cover warning detection.
142
+ ```
143
+
144
+ Partition by independent mutation zones first, then by effort. Do not split one shared public contract across agents unless a single integrator owns that contract. If task independence is uncertain, assign the risky task to the integrator or run a planning/review swarm before implementation.
145
+
146
+ ## Collaborative Branch Subagents
147
+
148
+ Use this pattern when a coordinator needs 2-4 implementation agents to work from one backlog without sharing a mutable checkout.
149
+
150
+ ```text
151
+ coordinator reads backlog
152
+ → coordinator writes one scope file per agent
153
+ → local async-run adapter starts isolated clone or worktree branches
154
+ → each subagent works only inside its branch workspace
155
+ → runner verifies commit and pushes branch
156
+ → coordinator reviews ready branches
157
+ → integrator merges through the normal project flow
158
+ ```
159
+
160
+ This is primarily a branch artifact protocol, not real-time agent chat. Subagents do not coordinate with each other during execution. They communicate by branch commits, handoff files, conflict reports, and integrator review. When the local runtime supports resumable sessions, a subagent may also use a coordinator checkpoint to ask the orchestrator for a bounded decision without losing its own context.
161
+
162
+ Coordinator responsibilities:
163
+
164
+ 1. Read the canonical backlog and project instructions.
165
+ 2. Select independent task groups with stable task IDs.
166
+ 3. Write one scope file per agent with goal, allowed files, avoided files, exit criteria, checks, and branch name.
167
+ 4. Start the local async-run adapter.
168
+ 5. Inspect run status and logs until terminal.
169
+ 6. Review successful branch diffs before merge.
170
+ 7. Record failed or out-of-scope work back into the backlog.
171
+
172
+ Scope file rules:
173
+
174
+ - Prefer local files over large inline prompts.
175
+ - Include task IDs and exact workspace path.
176
+ - Include allowed and avoided file lists.
177
+ - Require the agent to restate task IDs, allowed files, and exit criteria before editing.
178
+ - State that commit and push may be handled by the runner when the local adapter owns git finalization.
179
+
180
+ Subagent instruction core:
181
+
182
+ ```text
183
+ Work only in this repository workspace: <work_dir>.
184
+ Read your assigned scope from: <scope_file>.
185
+ Before editing, restate task IDs, allowed files, avoided files, and exit criteria.
186
+ Do not edit outside declared scope.
187
+ If an out-of-scope change is required, write it as a backlog note or handoff risk.
188
+ If blocked by a coordinator-only decision and the runtime supports checkpoints, emit a bounded Coordinator Checkpoint instead of discarding your context.
189
+ Run the checks named in the scope when practical.
190
+ Write a concise handoff report before finishing.
191
+ ```
192
+
193
+ ## Coordinator Checkpoints
194
+
195
+ A coordinator checkpoint is a deliberate pause, not free-form chat. It is useful when the subagent has built local context that should not be thrown away, but continuing requires a coordinator decision: scope change, ambiguous product choice, conflict policy, credential/account boundary, or release/publish permission.
196
+
197
+ Target behavior for capable adapters:
198
+
199
+ ```text
200
+ subagent reaches a decision gate
201
+ → subagent emits Coordinator Checkpoint
202
+ → runner pauses the subagent session without dropping context
203
+ → coordinator answers the bounded question
204
+ → runner resumes the same subagent context with the answer
205
+ → subagent records the decision in its handoff
206
+ ```
207
+
208
+ Checkpoint payload:
209
+
210
+ ```markdown
211
+ # Coordinator Checkpoint
212
+
213
+ Agent:
214
+ Task IDs:
215
+ Workspace:
216
+ Question:
217
+ Why coordinator input is needed:
218
+ Options considered:
219
+ Recommended option:
220
+ Risk if guessed:
221
+ State to preserve:
222
+ ```
223
+
224
+ Coordinator reply should answer only the checkpoint question. It should not inject broad new context unless the subagent explicitly asked for it. If the runtime cannot resume the same subagent context, write the checkpoint as an artifact, stop the branch as degraded, and let the coordinator replan or launch a new subagent with the checkpoint included.
225
+
226
+ Coordinator prompt template:
227
+
228
+ ```text
229
+ Read the project backlog and instructions.
230
+ Partition actionable work into <N> independent task groups.
231
+ Prefer groups with non-overlapping allowed files.
232
+ Write one scope file per agent under <run_dir>/scopes/.
233
+ Each scope file must include task IDs, goal, allowed files, avoided files, exit criteria, checks, branch name, and handoff path.
234
+ Do not start execution until every scope has a clear branch artifact contract.
235
+ ```
236
+
237
+ Scope file template:
238
+
239
+ ```markdown
240
+ # Scope: agent-01
241
+
242
+ Run:
243
+ Branch:
244
+ Workspace:
245
+ Handoff path:
246
+
247
+ Task IDs:
248
+
249
+ - T-001
250
+ - T-002
251
+
252
+ Goal:
253
+
254
+ - ...
255
+
256
+ Allowed files:
257
+
258
+ - ...
259
+
260
+ Avoid files:
261
+
262
+ - ...
263
+
264
+ Exit criteria:
265
+
266
+ - ...
267
+
268
+ Checks:
269
+
270
+ - ...
271
+
272
+ Out-of-scope handling:
273
+
274
+ - Do not edit outside allowed files.
275
+ - Record required out-of-scope changes in the handoff risk section.
276
+ ```
277
+
278
+ Branch artifact contract:
279
+
280
+ - Success means the expected branch exists, contains at least one commit for the assigned task group, and has been pushed.
281
+ - The branch name should include the run id and task range or agent id.
282
+ - The handoff report should name task IDs, touched files, checks, risks, and follow-up.
283
+ - A branch with no commit is not a successful artifact, even if the subagent exits with code 0.
284
+
285
+ Partial failure is normal. Treat a run with some ready branches and some failed branches as degraded, not as total failure. The coordinator should report ready branches, failed branches, failure reasons, and the safest next action for each failed scope.
286
+
287
+ ## Soft-Lock Manifest
288
+
289
+ For 2–4 agents, start with a simple repository-local manifest rather than a lock server.
290
+
291
+ Suggested path:
292
+
293
+ ```text
294
+ .agents/locks.md
295
+ ```
296
+
297
+ Example:
298
+
299
+ ```markdown
300
+ # Agent Locks
301
+
302
+ ## agent-a
303
+
304
+ Task: fix scheduler tests
305
+ Owns:
306
+
307
+ - Pallets/aaa/src/tests/scheduler/\*
308
+ - Pallets/aaa/src/mock.rs
309
+
310
+ ## agent-b
311
+
312
+ Task: update fee model docs
313
+ Owns:
314
+
315
+ - Docs/aaa/fees.md
316
+ - Docs/aaa/spec.md
317
+
318
+ ## agent-c
319
+
320
+ Task: refactor frontend card component
321
+ Owns:
322
+
323
+ - Src/lib/components/Card.svelte
324
+ ```
325
+
326
+ Protocol:
327
+
328
+ 1. Read `.agents/locks.md` before starting.
329
+ 2. Add or update your section before editing.
330
+ 3. Treat `Owns:` as a soft write claim.
331
+ 4. Avoid another agent's owned files unless the integrator replans.
332
+ 5. On completion, remove the section or mark it done.
333
+
334
+ This manifest is weaker than an automated lock adapter but easier for humans and agents to inspect. Use a runtime-backed lock protocol when automation, TTL, or conflict enforcement is needed.
335
+
336
+ ## Exclusive Files
337
+
338
+ Some files create semantic conflicts even when Git merges cleanly. Require exclusive ownership for public contracts and central runtime boundaries.
339
+
340
+ Examples:
341
+
342
+ ```text
343
+ src/lib/types/*
344
+ pallets/*/src/lib.rs
345
+ runtime/src/*
346
+ docs/spec/*
347
+ package.json
348
+ Cargo.toml
349
+ ```
350
+
351
+ Project-local protocol should define its own exclusive files. If a task needs one, assign it to a single agent or the integrator.
352
+
353
+ ## Conflict Types
354
+
355
+ ### Merge Conflict
356
+
357
+ Git cannot combine two edits to the same file.
358
+
359
+ Response:
360
+
361
+ 1. Both agents produce conflict reports.
362
+ 2. Resolver/integrator reads both reports.
363
+ 3. Resolver merges patch.
364
+ 4. Original agents review affected files only.
365
+
366
+ ### Semantic Conflict
367
+
368
+ Files may merge, but meaning diverges. Example: one agent changes an API while another writes code against the old API.
369
+
370
+ Response:
371
+
372
+ 1. Stop affected workers.
373
+ 2. Integrator decides whether the backlog task is invalidated.
374
+ 3. Split or replan before more implementation.
375
+
376
+ ### Architecture Conflict
377
+
378
+ The task decomposition itself is wrong.
379
+
380
+ Response:
381
+
382
+ 1. Stop workers on affected scopes.
383
+ 2. Re-open planning.
384
+ 3. Produce new task cards with corrected ownership.
385
+
386
+ ## Conflict Handshake Protocol
387
+
388
+ Agents should not freely negotiate in long context-sharing threads. Exchange semantic deltas in a bounded format.
389
+
390
+ ```markdown
391
+ # Conflict Report
392
+
393
+ Agent:
394
+ Task:
395
+ Conflicting files:
396
+
397
+ - ...
398
+
399
+ What I changed:
400
+
401
+ - ...
402
+
403
+ Why I changed it:
404
+
405
+ - ...
406
+
407
+ What I need preserved:
408
+
409
+ - ...
410
+
411
+ Can safely discard:
412
+
413
+ - ...
414
+
415
+ Suggested resolution:
416
+
417
+ - ...
418
+ ```
419
+
420
+ Resolution flow:
421
+
422
+ ```text
423
+ Agent A hits conflict with Agent B
424
+ → Agent A writes Conflict Report
425
+ → Agent B writes Conflict Report
426
+ → Integrator/resolver reads both
427
+ → Resolver creates merged patch
428
+ → Original agents review only affected files
429
+ ```
430
+
431
+ The goal is to exchange intent and invariants, not to let agents recursively debate.
432
+
433
+ ## Scope Expansion Rule
434
+
435
+ Multi-agent work is stricter than solo work.
436
+
437
+ Required instruction for implementation agents:
438
+
439
+ ```text
440
+ Do not opportunistically refactor unrelated code.
441
+ Do not modify files outside declared scope.
442
+ If you discover a needed out-of-scope change, record it as a backlog item or conflict note.
443
+ ```
444
+
445
+ This is the difference between useful parallelism and diff chaos.
446
+
447
+ ## Handoff Report
448
+
449
+ Each agent writes a concise handoff after finishing.
450
+
451
+ Suggested path:
452
+
453
+ ```text
454
+ .agents/handoff/agent-a.md
455
+ ```
456
+
457
+ Template:
458
+
459
+ ```markdown
460
+ # Handoff: agent-a
461
+
462
+ Task:
463
+ Branch/worktree:
464
+
465
+ Summary:
466
+
467
+ - ...
468
+
469
+ Touched files:
470
+
471
+ - ...
472
+
473
+ Tests/checks:
474
+
475
+ - ...
476
+
477
+ Behavior changes:
478
+
479
+ - ...
480
+
481
+ Risks / follow-up:
482
+
483
+ - ...
484
+
485
+ Integrator notes:
486
+
487
+ - What must be preserved during merge.
488
+ ```
489
+
490
+ Example:
491
+
492
+ ```markdown
493
+ # Agent A Handoff
494
+
495
+ Task:
496
+ A1: Add tests for scheduler window expiry
497
+
498
+ Touched files:
499
+
500
+ - Pallets/aaa/src/tests/scheduler/window.rs
501
+
502
+ Summary:
503
+
504
+ - Added tests for inclusive window end.
505
+ - Added test for close only when current_block > end.
506
+
507
+ Checks:
508
+
509
+ - Cargo test -p pallet-aaa scheduler_window
510
+
511
+ Open questions:
512
+
513
+ - None.
514
+
515
+ Conflict notes:
516
+
517
+ - Does not touch runtime logic.
518
+ ```
519
+
520
+ ## Runner Adapter Contract
521
+
522
+ A local branch runner may be useful, but it is adapter policy rather than portable Swarm core. Keep concrete model names, tool allowlists, async-run syntax, and runtime-specific CLI invocation outside this skill.
523
+
524
+ Minimum runner behavior:
525
+
526
+ 1. Clone or create an isolated worktree from the requested repo and base branch.
527
+ 2. Create the expected feature branch.
528
+ 3. Run one subagent with the prepared scope file and bounded tool access.
529
+ 4. Verify the current branch is still the expected branch.
530
+ 5. Verify there are intentional changes before commit.
531
+ 6. Commit with a task-aware summary when the adapter owns git finalization.
532
+ 7. Push the expected branch.
533
+ 8. Emit a structured result with branch, commit, pushed status, handoff path, checks, and failure reason.
534
+
535
+ Recommended subagent tools are the smallest set that can complete the task, usually read, edit/write, and shell validation. Avoid broad external account tools inside implementation subagents. External actions such as opening pull requests, merging, publishing, or commenting belong to the coordinator or integrator after review.
536
+
537
+ Runner exit policy:
538
+
539
+ - Exit 0 only after commit verification and successful push when the runner owns git finalization.
540
+ - Exit non-zero when clone, checkout, subagent execution, commit verification, or push fails.
541
+ - A failed branch should not cancel sibling branches in the same async fanout.
542
+ - Timeouts should preserve logs and any handoff artifacts for coordinator inspection.
543
+
544
+ ## Integrator Protocol
545
+
546
+ The integrator is the only actor that merges to the shared target branch.
547
+
548
+ Integrator steps:
549
+
550
+ 1. Read backlog, locks, and handoffs.
551
+ 2. Merge one branch at a time.
552
+ 3. Resolve conflicts using conflict reports, not guesses.
553
+ 4. Run the project's validation gates.
554
+ 5. Ask original agents to review affected files when conflict resolution changed their work.
555
+ 6. Produce final summary: merged tasks, tests, touched files, residual risks.
556
+
557
+ ## Effective Protocol
558
+
559
+ ```markdown
560
+ # Multi-Agent Protocol
561
+
562
+ 1. Each agent MUST work in a separate branch or worktree.
563
+ 2. Before editing, each agent MUST declare task, intended files, forbidden files, and expected output.
564
+ 3. Agents SHOULD avoid files already claimed in `.agents/locks.md`.
565
+ 4. Public API, storage, runtime, schema, and spec files require exclusive ownership.
566
+ 5. Each agent MUST produce a handoff note after completion: touched files, semantic changes, checks run, unresolved risks.
567
+ 6. If a conflict occurs, both agents MUST produce Conflict Reports.
568
+ 7. Conflict resolution MUST preserve semantic intent, not merely compile.
569
+ 8. Integrator merges patches into the shared target after checks pass.
570
+ 9. No agent may silently expand task scope.
571
+ ```
572
+
573
+ Context exchange rule:
574
+
575
+ ```text
576
+ Before conflict: minimal shared context.
577
+ At conflict: compressed intent/diff/risk exchange.
578
+ After conflict: update backlog/locks.
579
+ ```
580
+
581
+ Constant agent chat destroys independence. Conflict reports preserve the useful context without contaminating every worker.
582
+
583
+ ## Minimal Directory
584
+
585
+ ```text
586
+ .agents/
587
+ backlog.md
588
+ locks.md
589
+ protocol.md
590
+ handoff/
591
+ agent-a.md
592
+ agent-b.md
593
+ agent-c.md
594
+ ```
595
+
596
+ This directory is optional. Use it when the repository lacks an existing coordination plane. If the project already has backlog, lock, and handoff conventions, reuse them instead.
@@ -69,9 +69,9 @@ Field rules:
69
69
 
70
70
  - `to`: required address.
71
71
  - `from`: optional address; runtime fills when known.
72
- - `type`: required semantic message type.
72
+ - `type`: required semantic message type. Prefer compact dotted names such as `control.stop`, `task.claim`, or `player.next`, where the prefix is the interaction channel/domain and the suffix is the action. Many script-backed actors should be able to dispatch from `type` alone without requiring a structured body.
73
73
  - `summary`: short human-facing line for notifications/follow-ups.
74
- - `body`: string or JSON payload.
74
+ - `body`: optional string or JSON payload. Use it when extra context is needed: scripts may ignore it for action-only messages, while LLM-backed agents can accept free-form natural-language prompts without a rigid schema.
75
75
  - Routing/delivery is inferred from `to`, actor ownership, and coordinator runtime policy; recipes should not expose delivery knobs. When a coordinator session is known, addressed run/branch/control messages fail closed before controlling or emitting from runs owned by another session.
76
76
  - `reply_to`: optional message id for conversational checkpoints.
77
77
  - `correlation_id`: optional task/run/workflow id.
@@ -166,8 +166,9 @@ Low-level async actions map into the actor surface instead of forming a second p
166
166
  - Send/control → `message`
167
167
  - Status/tail/messages/list → `inspect`
168
168
  - Stop/kill → `message` with `control.stop` or `control.kill`, with synchronous results
169
+ - Archive/prune terminal state → `message` with `control.archive` or `control.prune`, with active runs rejected fail-closed
169
170
 
170
- Compact text is returned by default so async management does not flood agent context; use verbose inspection when the full state object is needed. List output intentionally shares one state root across music, subagents, timers, and other async work; source fields such as `tool` and `recipe` distinguish run purpose when the launcher recorded them. Registered tools are the preferred user-facing surface for reusable recipes.
171
+ Compact text is returned by default so async management does not flood agent context; use verbose inspection when the full state object is needed. List output intentionally shares one state root across music, subagents, timers, and other async work; source fields such as `tool` and `recipe` distinguish run purpose when the launcher recorded them. The run root may contain a rebuildable `index.json` with run id, state directory, owner, status, update time, and recipe/tool hints; corrupt indexes fall back to recursive scan. Registered tools are the preferred user-facing surface for reusable recipes. `control.prune` accepts `body.preserve_artifacts=true` to copy existing named artifacts beside the run root before deleting terminal state.
171
172
 
172
173
  ## Run-Local Messages
173
174
 
@@ -187,6 +188,17 @@ For `run:<id>`, `message` adapts the body to the recipe's run-local control chan
187
188
 
188
189
  Run-local control uses a platform adapter under the same `message` API. Unix recipes may keep the existing FIFO endpoint, and native Windows recipes can expose a named-pipe endpoint in run state. Recipe authors should document message vocabulary through `mailbox.accepts`, not through transport arguments. Packaged scripts that still create Unix-only endpoints remain WSL/Linux/macOS-only until migrated.
189
190
 
191
+ Portable control matrix:
192
+
193
+ | Control surface | Linux/macOS/WSL | Native Windows | Guidance |
194
+ | --- | --- | --- | --- |
195
+ | File-backed run inbox + wake | Supported | Supported | Preferred durable baseline. |
196
+ | Mailbox-only endpoint | Supported | Supported | Use for cross-platform workers. |
197
+ | FIFO endpoint | Supported | Rejected before delivery | Keep only for Unix-compatible recipes. |
198
+ | Named-pipe endpoint | Optional | Supported | Use for native Windows live delivery. |
199
+ | Cancel/kill | Process group signal with pid fallback | Process-tree adapter | Same public `message` API. |
200
+
201
+
190
202
  Runtime wake notifications are now modeled separately from durable queues. Message handling records canonical state in file-backed mailbox/event files before attempting optional live endpoint delivery. Runs may expose a mailbox-only control endpoint when durable inbox plus wake notification is the intended delivery path; FIFO and named-pipe endpoints remain compatibility/fast-wake paths rather than the durable queue itself. Successful FIFO or named-pipe delivery marks the run inbox entry `sent`; mailbox-only delivery leaves the entry queued for the runtime to claim. `wake.jsonl` is an advisory doorbell that lets a live runtime subscribe through file-system notifications plus explicit initial, wake-triggered, and polling reconciliation callbacks. A missed wake must not lose work because actors can re-read the canonical mailbox state. Runtime loops that consume the file-backed mailbox should claim queued run inbox entries, then mark them `handled` or `failed`; the helper path uses a small lock so concurrent reconciliation callbacks do not process the same entry twice.
191
203
 
192
204
  ## Coordinator Notifications
@@ -90,7 +90,7 @@ npm run check -- {scope}
90
90
  ```
91
91
  ````
92
92
 
93
- Fenced blocks marked `template`, `command-template`, `json`, or `recipe` are executable. A `template` fence stores its text as the command-template string. A JSON fence can contain either a full recipe object with `template` or a raw command-template value. Frontmatter supports the recipe metadata used by JSON recipes, including `args`, `defaults`, `imports`, `mailbox`, `artifacts`, `async`, and command-template flags.
93
+ Fenced blocks marked `template`, `command-template`, `json`, or `recipe` are executable. A `template` fence stores its text as the command-template string. A JSON fence can contain either a full recipe object with `template` or a raw command-template value. Frontmatter supports the recipe metadata used by JSON recipes, including `args`, `defaults`, `imports`, `mailbox`, `artifacts`, `async`, and command-template flags. For Markdown ergonomics, `args` may be either a YAML list or a comma-separated scalar, and `defaults` may be either a YAML object or a list of `key: value` entries; both normalize to the same JSON recipe shape.
94
94
 
95
95
  JSON remains the source-of-truth format for precise machine editing. If `<id>.json` and `<id>.md` exist in the same discovery priority layer, `<id>.json` wins and the Markdown recipe is reported as shadowed.
96
96
 
@@ -162,7 +162,7 @@ Use recipe-level `mailbox` to document the semantic messages a recipe actor acce
162
162
  }
163
163
  ```
164
164
 
165
- `mailbox` is contract metadata, not transport configuration. It should name semantic message types, not transport commands, file paths, or CLI fragments.
165
+ `mailbox` is contract metadata, not transport configuration. It should name semantic message types, not transport commands, file paths, or CLI fragments. Entries may be strings or typed objects such as `{ "type": "task.assign", "requires_response": true, "summary": "Assign work" }`; inspection normalizes both forms. Acceptance contracts are advisory by default: messages outside `mailbox.accepts` produce warnings rather than hard routing failures.
166
166
 
167
167
  ## Actor Recipe Context
168
168
 
@@ -15,7 +15,6 @@ The registry source is location-discovered recipes, not a live tool-only JSON fi
15
15
  - Recipe identity is the filename basename; `~/.pi/agent/recipes/docs_review.json` and `docs_review.md` both have id/tool name `docs_review`.
16
16
  - Same-id JSON shadows Markdown in the same priority layer.
17
17
 
18
-
19
18
  Because the user recipe directory is sticky agent muscle memory, runtime launches update `usage.calls`, `usage.last_called`, and a content `usage.fingerprint` on user-owned recipe files. If authored recipe content changes, the next launch resets `usage.calls` and records `usage.reset_at` before counting the launch, so usage evidence follows the current recipe meaning rather than an older file history. `inspect target=recipes view=summary verbose=true` includes usage metadata and operator-gated cleanup recommendations for invalid, shadowed, disabled, component-only, unused, or overriding recipes. Recommended actions stay explicit: keep as a tool/component, enable, merge, fix, delete, or archive. The extension does not maintain a failure counter and agents should not silently clean tools during unrelated work.
20
19
 
21
20
  `register_tool` is the preferred agent-facing mutation API. It creates, updates, and deletes recipe files in `~/.pi/agent/recipes`; agents do not need to edit the files directly for normal registration. Direct file edits are still valid for operators and advanced agents. Runtime behavior is reactive: file creation, deletion, or edits in the user recipe root trigger validation and tool-set refresh, with invalid recipes surfaced as diagnostics rather than silently ignored.
@@ -0,0 +1,13 @@
1
+ {
2
+ "to": "branch:demo/reviewer",
3
+ "from": "run:demo",
4
+ "type": "task.assign",
5
+ "summary": "Review the current slice",
6
+ "body": {
7
+ "task": "Check mailbox loop semantics"
8
+ },
9
+ "correlation_id": "task-001",
10
+ "metadata": {
11
+ "requires_response": true
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "report": {
3
+ "path": "{state_dir}/report.md",
4
+ "kind": "markdown",
5
+ "media_type": "text/markdown",
6
+ "required": true
7
+ },
8
+ "journal": "{state_dir}/journal.jsonl"
9
+ }