@llblab/pi-actors 0.14.3 → 0.16.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 (76) hide show
  1. package/AGENTS.md +5 -1
  2. package/BACKLOG.md +54 -32
  3. package/CHANGELOG.md +39 -0
  4. package/README.md +53 -61
  5. package/banner.jpg +0 -0
  6. package/docs/actor-messages.md +1 -1
  7. package/docs/async-runs.md +4 -4
  8. package/docs/command-templates.md +11 -11
  9. package/docs/recipe-library.md +7 -3
  10. package/docs/task-first-recipes.md +44 -43
  11. package/docs/template-recipes.md +45 -23
  12. package/docs/tool-registry.md +50 -42
  13. package/index.ts +34 -0
  14. package/lib/actor-messages.ts +20 -7
  15. package/lib/async-runs.ts +35 -12
  16. package/lib/command-templates.ts +6 -1
  17. package/lib/config.ts +3 -2
  18. package/lib/execution.ts +9 -5
  19. package/lib/observability.ts +20 -10
  20. package/lib/paths.ts +6 -1
  21. package/lib/prompts.ts +14 -21
  22. package/lib/recipe-discovery.ts +226 -0
  23. package/lib/recipe-migration.ts +123 -0
  24. package/lib/recipe-references.ts +45 -13
  25. package/lib/recipe-usage.ts +44 -0
  26. package/lib/registry.ts +48 -15
  27. package/lib/runtime.ts +59 -15
  28. package/lib/tools.ts +237 -65
  29. package/package.json +21 -11
  30. package/recipes/coordinator-locker.json +46 -0
  31. package/recipes/music-player.json +16 -2
  32. package/recipes/pipeline-architect-coordinator.json +11 -3
  33. package/recipes/pipeline-artifact-bundle.json +12 -3
  34. package/recipes/pipeline-artifact-report.json +9 -3
  35. package/recipes/pipeline-artifact-write.json +9 -3
  36. package/recipes/pipeline-async-run-ops.json +18 -9
  37. package/recipes/pipeline-checkpoint-continuation.json +14 -3
  38. package/recipes/pipeline-development-tasking.json +12 -3
  39. package/recipes/pipeline-docs-maintenance.json +12 -3
  40. package/recipes/pipeline-media-library.json +12 -3
  41. package/recipes/pipeline-quorum-review.json +12 -9
  42. package/recipes/pipeline-release-readiness.json +27 -9
  43. package/recipes/pipeline-release-summary.json +89 -0
  44. package/recipes/pipeline-repo-health.json +12 -3
  45. package/recipes/pipeline-research-synthesis.json +11 -3
  46. package/recipes/pipeline-review-readiness.json +12 -6
  47. package/recipes/subagent-artifact.json +9 -3
  48. package/recipes/subagent-checkpoint.json +10 -3
  49. package/recipes/subagent-conflict-report.json +11 -3
  50. package/recipes/subagent-contradiction-map.json +11 -3
  51. package/recipes/subagent-critic.json +11 -3
  52. package/recipes/subagent-evidence-map.json +11 -3
  53. package/recipes/subagent-followup.json +10 -3
  54. package/recipes/subagent-judge.json +11 -3
  55. package/recipes/subagent-merge.json +11 -3
  56. package/recipes/subagent-message.json +8 -3
  57. package/recipes/subagent-normalize.json +11 -3
  58. package/recipes/subagent-plan.json +11 -3
  59. package/recipes/subagent-prompt.json +10 -3
  60. package/recipes/subagent-quorum.json +10 -7
  61. package/recipes/subagent-review-coordinator.json +14 -6
  62. package/recipes/subagent-review.json +11 -3
  63. package/recipes/subagent-task-card.json +11 -3
  64. package/recipes/subagent-tools.json +10 -3
  65. package/recipes/subagent-verify.json +11 -3
  66. package/recipes/subagents-prompts.json +10 -3
  67. package/recipes/utility-coordinator-lock-snapshot.json +14 -0
  68. package/recipes/utility-run-ops-snapshot.json +3 -3
  69. package/recipes/utility-skill-summary.json +14 -0
  70. package/scripts/coordinator-locker.mjs +272 -0
  71. package/scripts/music-player.mjs +2 -1
  72. package/scripts/recipe-utils.mjs +239 -81
  73. package/scripts/validate-recipe.mjs +28 -10
  74. package/skills/actors/SKILL.md +301 -0
  75. package/skills/swarm/SKILL.md +451 -0
  76. package/skills/swarm/references/development-swarm.md +596 -0
@@ -0,0 +1,301 @@
1
+ ---
2
+ name: actors
3
+ description: Highest-density practical guide for pi-actors. Read this skill whenever prompt and tools are not enough for spawn, message, inspect, actor runs, tools, recipes, command templates, async lifecycle, mailboxes, artifacts, and local orchestration mechanics.
4
+ metadata:
5
+ version: 0.16.0
6
+ ---
7
+
8
+ # Actors (pi-actors)
9
+
10
+ `pi-actors` turns trusted local capabilities into addressable actors. This skill is the compact operator/reference layer for the extension itself: tools, nouns, lifecycle, message protocol, recipes, and common edge cases. It is not a multi-agent strategy guide; use a swarm skill for decomposition, quorum design, reviewer lenses, and consensus methodology.
11
+
12
+ ## Knowledge Surfaces
13
+
14
+ Context arrives in layers:
15
+
16
+ - **Injected prompt**: always present at extension load. It is a bootstrap/reminder of current verbs, paths, and runtime rules; it should not try to be documentation.
17
+ - **Skill header**: automatically matched by agents from `name`/`description`. Its job is to signal: if pi-actors use is unclear, read this skill body.
18
+ - **This skill body**: highest-density practical reference. It should explain extension operation from multiple angles and link to deeper docs without becoming a changelog or swarm-methodology guide.
19
+ - **README**: human entrypoint. It explains what pi-actors is, why it matters, benefits, rhythm, and representative scenarios; it is not automatically in agent context.
20
+ - **Docs**: transportable standards by domain: command templates, recipes, async runs, actor messages, registry, recipe library; read on demand.
21
+ - **AGENTS.md**: project context for agents changing pi-actors: architecture constraints, durable conventions, do/don't rules, validation; read for repo work.
22
+
23
+ ## Core Nouns
24
+
25
+ ```text
26
+ Trusted local capability
27
+ -> Command template execution graph
28
+ -> Recipe saved actor definition
29
+ -> spawn starts one run instance
30
+ -> run:<id> addressable actor
31
+
32
+ Trusted local capability
33
+ -> Command template or recipe
34
+ -> register_tool persists an agent-callable wrapper
35
+ -> tool:<name> addressable tool actor
36
+ ```
37
+
38
+ - **Command template**: portable execution graph. String leaf, sequence array, or object node with controls.
39
+ - **Recipe**: saved JSON definition wrapping a template with args, defaults, imports, mailbox, artifacts, metadata, and optional `async: true`.
40
+ - **Run actor**: one detached execution instance addressable as `run:<id>` with status, logs, messages, mailbox metadata, files, and artifacts.
41
+ - **Tool actor**: registered persistent capability addressable as `tool:<name>` and callable through the generated tool or `message`.
42
+ - **Coordinator/session**: the current pi session endpoint that receives bounded actor follow-ups.
43
+ - **Mailbox**: public interaction contract: message types the actor accepts/emits.
44
+ - **Artifact**: named durable output path declared by a recipe/run.
45
+
46
+ ## Three Verbs
47
+
48
+ ### `spawn` — create a run actor
49
+
50
+ Use for long work, background services, subagents, fanout, pipelines, and reusable recipes.
51
+
52
+ ```json
53
+ {
54
+ "as": "run:repo-health",
55
+ "file": "pipeline-repo-health",
56
+ "values": { "path": "/repo" },
57
+ "artifacts": { "report": "/tmp/repo-health.md" }
58
+ }
59
+ ```
60
+
61
+ Rules:
62
+
63
+ - Use `file`/`recipe` for saved recipes; bare names resolve under `~/.pi/agent/recipes`.
64
+ - Use inline `template` for one-off experiments; promote useful repeats to recipes.
65
+ - Use stable `as` names when you will inspect or message the actor later.
66
+ - `async: true` on the recipe is the detached run switch.
67
+
68
+ ### `message` — send a typed envelope
69
+
70
+ ```json
71
+ {
72
+ "to": "run:repo-health",
73
+ "type": "control.cancel",
74
+ "summary": "Cancel stale repo-health run",
75
+ "body": {}
76
+ }
77
+ ```
78
+
79
+ Envelope fields:
80
+
81
+ - Required: `to`, `type`.
82
+ - Useful: `summary`, `body`, `from`, `reply_to`, `correlation_id`, `metadata`.
83
+ - Addresses: `run:<id>`, `branch:<run>/<branch>`, `tool:<name>`, `coordinator`, `session:<id>`.
84
+ - Standard termination messages: `control.stop`, `control.cancel`, `control.kill`.
85
+
86
+ Check `inspect view=mailbox` before domain-specific messages.
87
+
88
+ ### `inspect` — observe intentionally
89
+
90
+ ```json
91
+ { "target": "run:repo-health", "view": "status" }
92
+ { "target": "run:repo-health", "view": "tail", "lines": "80" }
93
+ { "target": "run:repo-health", "view": "messages" }
94
+ { "target": "run:repo-health", "view": "artifacts" }
95
+ { "target": "tool:music_player", "view": "status" }
96
+ { "target": "recipes", "view": "status" }
97
+ { "target": "coordinator", "view": "status" }
98
+ ```
99
+
100
+ Views:
101
+
102
+ - `status`: lifecycle, pid, values, progress, result, compact summary.
103
+ - `tail`: recent stdout/stderr/log tail.
104
+ - `messages`: actor messages emitted by the run.
105
+ - `mailbox`: declared accepts/emits contract.
106
+ - `files`: run state directory file list.
107
+ - `artifacts`: declared artifact paths/status.
108
+ - `recipes` target: registry summary for active, shadowed, invalid, disabled, and diagnostic recipe entries.
109
+
110
+ Let terminal notifications arrive; avoid sleep-poll loops except during diagnosis.
111
+
112
+ ## Command Template Standard
113
+
114
+ Forms:
115
+
116
+ ```json
117
+ "npm test -- {file}"
118
+ ["npm run typecheck", "npm test"]
119
+ { "parallel": true, "template": ["job-a", "job-b"] }
120
+ ```
121
+
122
+ Controls:
123
+
124
+ - `args`, `defaults`: public placeholder declarations and defaults.
125
+ - `parallel: true`: fanout child nodes.
126
+ - `when`: conditional execution.
127
+ - `timeout`, `delay`, `retry`: timing and retry controls; string placeholders are allowed where supported.
128
+ - `failure`: `continue`, `branch`, or `root` propagation.
129
+ - `recover`: cleanup between retry attempts.
130
+ - `repeat`: repeated node expansion.
131
+ - `output`: output behavior selection.
132
+
133
+ Placeholders:
134
+
135
+ - `{name}` required value.
136
+ - `{name=default}` inline default.
137
+ - `{name:type=default}` typed inline arg.
138
+ - `{value??fallback}` nullish fallback.
139
+ - `{flag?yes:no}` ternary fallback.
140
+
141
+ Templates are synchronous and portable. Recipes give them identity and lifecycle.
142
+
143
+ ## Recipe Standard
144
+
145
+ Minimal actor recipe:
146
+
147
+ ```json
148
+ {
149
+ "name": "my-task",
150
+ "async": true,
151
+ "args": ["path:path", "model:string"],
152
+ "defaults": {},
153
+ "mailbox": {
154
+ "accepts": ["control.stop", "control.cancel", "control.kill"],
155
+ "emits": ["command.done", "run.done", "run.failed"]
156
+ },
157
+ "artifacts": { "report": "{path}/report.md" },
158
+ "template": "some-command {path} --model {model}"
159
+ }
160
+ ```
161
+
162
+ Rules:
163
+
164
+ 1. Every recipe owns `template` directly.
165
+ 2. `async: true` makes spawned work a detached actor run.
166
+ 3. Public knobs belong in `args`/`defaults`; hidden launch mechanics stay inside `template`.
167
+ 4. Use `imports` to compose recipes; imported recipes are definitions, not nested async runs.
168
+ 5. Declare `mailbox` for actors that accept or emit meaningful messages.
169
+ 6. Declare `artifacts` for durable outputs the coordinator should inspect.
170
+ 7. Recipe identity comes from the filename basename when `name` is omitted.
171
+ 8. Keep packaged recipes generic: no machine-local paths, no private companion identities, no project-specific defaults unless the recipe is explicitly project-specific.
172
+ 9. Do not ship concrete model-version defaults in packaged recipes; expose `model`, `models`, and stage-specific model args so the caller must choose current policy at launch.
173
+
174
+ Priority for same-name recipes:
175
+
176
+ 1. No recipe: no capability.
177
+ 2. Packaged pi-actors recipe: standard-library declarative actor component.
178
+ 3. Explicit ad hoc user recipe file outside `~/.pi/agent/recipes`.
179
+ 4. User recipe in `~/.pi/agent/recipes/*.json`: highest-priority operator tool surface.
180
+
181
+ Only matching filename ids compete. Higher priority shadows lower priority. An invalid or `disabled: true` higher-priority recipe blocks fallback so the agent does not silently run standard-library behavior when a user override is broken or intentionally disabled.
182
+
183
+ Muscle-memory lens: every recipe in `~/.pi/agent/recipes/*.json` becomes an easy-to-call tool by default. This is intentionally sticky: successful local patterns can quickly become durable agent muscle memory. The tradeoff is tool-surface clutter; accidental or one-off tools behave like persistent intrusive thoughts until an agent/operator focuses on cleanup.
184
+
185
+ Usage lens: user recipes may carry extension-maintained launch metadata such as `usage.calls` and `usage.last_called`. The extension increments the counter when it starts that concrete recipe; agents should not hand-edit counters as part of normal recipe maintenance. Treat usage as evidence for usefulness analysis: heavily used recipes are good candidates for promotion, documentation, or stronger tests; unused recipes are cleanup or `tool: false` candidates. Do not use failure counts as a primary usefulness signal because failures may reflect bad caller judgment rather than bad recipes. Do not delete or demote solely from counters without operator approval.
186
+
187
+ Cleanup rule: periodically inspect `~/.pi/agent/recipes` as the live muscle-memory set. For each stale, duplicate, too-specific, or low-value recipe, choose one explicit action: keep as a tool, set `tool: false` to retain recipe-only memory, merge into a better recipe, or delete/archive the file. Prefer demotion over deletion when the recipe may still be useful as a component. Never silently remove tools during unrelated work.
188
+
189
+ ## Registered Tools
190
+
191
+ `register_tool` persists trusted local capabilities as recipe files in `~/.pi/agent/recipes/*.json`.
192
+
193
+ Use it when a command/template/recipe should become durable agent muscle memory. Prefer typed args or placeholder-derived args; use `update=true` for replacement and `template=null` or `template=""` for deletion. `register_tool` should create/update/delete recipe files in the user recipe root; direct file editing is allowed but is the lower-level path.
194
+
195
+ Tool templates may be:
196
+
197
+ - A foreground command template.
198
+ - A file-backed recipe name/path.
199
+ - A complete recipe body, optionally `async: true`.
200
+
201
+ The user recipe root is the default tool set; packaged recipes are the lower-priority standard library and opt into tool exposure with `tool: true`. Ideal runtime behavior is reactive: create/edit/delete recipe files, validate them, then connect valid tools or surface diagnostics without requiring agents to hand-maintain a separate registry.
202
+
203
+ ## Recipe Navigator
204
+
205
+ Use packaged recipes by name with `spawn file=<name>` for async actors, or register/call them as tools when repeated use deserves a stable shortcut. The links below point to recipe files shipped with this extension; read the JSON for args, defaults, mailbox, artifacts, and imports.
206
+
207
+ ### Coordination and Services
208
+
209
+ - [`coordinator-locker`](../../recipes/coordinator-locker.json): queue + acquire/renew/release lease locks + journaled coordinator messages.
210
+ - [`utility-coordinator-lock-snapshot`](../../recipes/utility-coordinator-lock-snapshot.json): one-shot JSON snapshot of a coordinator-locker state directory.
211
+ - [`music-player`](../../recipes/music-player.json): background local/URL/directory/playlist playback actor controlled by messages.
212
+
213
+ ### Subagent Atoms
214
+
215
+ - Launchers: [`subagent-prompt`](../../recipes/subagent-prompt.json), [`subagent-tools`](../../recipes/subagent-tools.json), [`subagents-prompts`](../../recipes/subagents-prompts.json).
216
+ - Review chain: [`subagent-review`](../../recipes/subagent-review.json), [`subagent-verify`](../../recipes/subagent-verify.json), [`subagent-merge`](../../recipes/subagent-merge.json), [`subagent-judge`](../../recipes/subagent-judge.json), [`subagent-normalize`](../../recipes/subagent-normalize.json).
217
+ - Planning/evidence: [`subagent-plan`](../../recipes/subagent-plan.json), [`subagent-task-card`](../../recipes/subagent-task-card.json), [`subagent-evidence-map`](../../recipes/subagent-evidence-map.json), [`subagent-contradiction-map`](../../recipes/subagent-contradiction-map.json), [`subagent-critic`](../../recipes/subagent-critic.json).
218
+ - Handoffs: [`subagent-checkpoint`](../../recipes/subagent-checkpoint.json), [`subagent-followup`](../../recipes/subagent-followup.json), [`subagent-message`](../../recipes/subagent-message.json), [`subagent-artifact`](../../recipes/subagent-artifact.json), [`subagent-conflict-report`](../../recipes/subagent-conflict-report.json).
219
+ - Composition: [`subagent-quorum`](../../recipes/subagent-quorum.json), [`subagent-review-coordinator`](../../recipes/subagent-review-coordinator.json).
220
+
221
+ ### Pipelines
222
+
223
+ - [`pipeline-release-readiness`](../../recipes/pipeline-release-readiness.json): changelog/package/skill/validation evidence → release review → artifact report.
224
+ - [`pipeline-release-summary`](../../recipes/pipeline-release-summary.json): evidence-only release summary, risk checklist, and PR body draft artifact without release side effects.
225
+ - [`pipeline-repo-health`](../../recipes/pipeline-repo-health.json): git/doc/validation evidence → normalized repository health report.
226
+ - [`pipeline-async-run-ops`](../../recipes/pipeline-async-run-ops.json): run summary + selected run messages → operations report.
227
+ - [`pipeline-docs-maintenance`](../../recipes/pipeline-docs-maintenance.json): docs index/review/planning → maintenance artifact.
228
+ - Artifacts: [`pipeline-artifact-report`](../../recipes/pipeline-artifact-report.json), [`pipeline-artifact-write`](../../recipes/pipeline-artifact-write.json), [`pipeline-artifact-bundle`](../../recipes/pipeline-artifact-bundle.json).
229
+ - Review gates: [`pipeline-quorum-review`](../../recipes/pipeline-quorum-review.json), [`pipeline-review-readiness`](../../recipes/pipeline-review-readiness.json).
230
+ - Task-first workflows: [`pipeline-architect-coordinator`](../../recipes/pipeline-architect-coordinator.json), [`pipeline-research-synthesis`](../../recipes/pipeline-research-synthesis.json), [`pipeline-development-tasking`](../../recipes/pipeline-development-tasking.json), [`pipeline-checkpoint-continuation`](../../recipes/pipeline-checkpoint-continuation.json), [`pipeline-media-library`](../../recipes/pipeline-media-library.json).
231
+
232
+ ### Utilities
233
+
234
+ - Repo/release evidence: [`utility-git-status`](../../recipes/utility-git-status.json), [`utility-git-log`](../../recipes/utility-git-log.json), [`utility-changelog-head`](../../recipes/utility-changelog-head.json), [`utility-changelog-section`](../../recipes/utility-changelog-section.json), [`utility-package-summary`](../../recipes/utility-package-summary.json), [`utility-skill-summary`](../../recipes/utility-skill-summary.json).
235
+ - Validation/state: [`utility-validation-wrapper`](../../recipes/utility-validation-wrapper.json), [`utility-validate-recipe`](../../recipes/utility-validate-recipe.json), [`utility-run-summary`](../../recipes/utility-run-summary.json), [`utility-run-ops-snapshot`](../../recipes/utility-run-ops-snapshot.json), [`utility-run-state-files`](../../recipes/utility-run-state-files.json), [`utility-jsonl-tail`](../../recipes/utility-jsonl-tail.json).
236
+ - Artifacts/media/messages: [`utility-artifact-manifest`](../../recipes/utility-artifact-manifest.json), [`utility-artifact-write`](../../recipes/utility-artifact-write.json), [`utility-actor-message`](../../recipes/utility-actor-message.json), [`utility-markdown-index`](../../recipes/utility-markdown-index.json), [`utility-playlist-scan`](../../recipes/utility-playlist-scan.json), [`utility-playlist-build`](../../recipes/utility-playlist-build.json).
237
+
238
+ Deep inventory: [`docs/recipe-library.md`](../../docs/recipe-library.md).
239
+
240
+ ## Operating Patterns
241
+
242
+ - **Short deterministic command**: call foreground registered tool or command template.
243
+ - **Long job/service/fanout**: `spawn` async recipe, then inspect/messages/artifacts.
244
+ - **One-off experiment**: inline `template`; promote after repeat use.
245
+ - **Reusable workflow**: recipe with public knobs, mailbox, artifacts, docs.
246
+ - **Subagent/swarm execution**: actor mechanics here; methodology belongs to swarm guidance.
247
+ - **Coordinated workers**: spawn `coordinator-locker` when several actors need a shared queue, acquire/renew/release resource leases, or a journaled coordination point.
248
+ - **Release/review pipeline**: pi-actors can prepare evidence, summaries, and artifacts; external actions such as commit, PR, merge, tag, and publish require the appropriate gated release workflow.
249
+
250
+ ## Complementary Methodology Engines
251
+
252
+ pi-actors is the local execution engine for methodology skills. A methodology skill can define abstract patterns such as lens swarm, quorum, task cards, lock discipline, or clean-context merge; pi-actors turns those patterns into concrete local actors, recipes, queues, leases, artifacts, and messages.
253
+
254
+ Example mapping:
255
+
256
+ ```text
257
+ methodology says: protect shared files
258
+ pi-actors does: spawn coordinator-locker, enqueue tasks, lease resources
259
+
260
+ methodology says: run reviewers then merge
261
+ pi-actors does: spawn review pipeline, inspect messages/artifacts
262
+ ```
263
+
264
+ Keep the split clean: methodology chooses coordination shape; pi-actors supplies addressable local machinery.
265
+
266
+ ## Lifecycle Discipline
267
+
268
+ 1. Choose existing recipe/tool when available.
269
+ 2. Spawn with a stable actor id for observable work.
270
+ 3. Inspect `status` after launch.
271
+ 4. Use notifications and `inspect`; do not busy-poll.
272
+ 5. Read `messages` and `artifacts`, not only stdout.
273
+ 6. Use `message` for explicit control or domain commands.
274
+ 7. Promote repeated inline forms to recipes.
275
+ 8. Update docs/context when changing public behavior.
276
+
277
+ ## Common Pitfalls
278
+
279
+ - Treating actor mechanics as multi-agent methodology.
280
+ - Repeating inline templates instead of promoting recipes.
281
+ - Omitting stable run ids for work that needs follow-up.
282
+ - Sending domain messages without checking `mailbox`.
283
+ - Reading only stdout and missing actor messages/artifacts.
284
+ - Baking local absolute paths into published docs or reusable recipes.
285
+ - Creating recipes that perform external side effects without explicit operator gates.
286
+ - Preserving old runtime/event/FIFO vocabulary instead of `spawn`/`message`/`inspect` and actor messages.
287
+
288
+ ## Deep References
289
+
290
+ - `docs/command-templates.md` — execution graph semantics.
291
+ - `docs/template-recipes.md` — recipe storage, imports, defaults, references.
292
+ - `docs/async-runs.md` — detached lifecycle, state, cancellation, observability.
293
+ - `docs/actor-messages.md` — addressed envelope protocol and mailbox model.
294
+ - `docs/tool-registry.md` — persistent tool registry and generated tools.
295
+ - `docs/recipe-library.md` — packaged recipes.
296
+ - `docs/task-first-recipes.md` — deriving reusable pipelines from operator tasks.
297
+ - `docs/component-recipes.md` — reusable coordinator/subagent building blocks.
298
+
299
+ ## One-Sentence Contract
300
+
301
+ Use pi-actors to wrap local capabilities as addressable actors: define launch with templates, preserve semantics in recipes/tools, start with `spawn`, communicate with `message`, observe with `inspect`, and hand off durable results through messages and artifacts.