@linxiraos/pi-messenger 1.1.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 (58) hide show
  1. package/CHANGELOG.md +676 -0
  2. package/README.md +424 -0
  3. package/config-overlay.ts +171 -0
  4. package/config.ts +209 -0
  5. package/crew/agents/crew-plan-sync.md +64 -0
  6. package/crew/agents/crew-planner.md +172 -0
  7. package/crew/agents/crew-reviewer.md +58 -0
  8. package/crew/agents/crew-worker.md +129 -0
  9. package/crew/agents.ts +434 -0
  10. package/crew/handlers/coordination.ts +332 -0
  11. package/crew/handlers/plan.ts +906 -0
  12. package/crew/handlers/review.ts +333 -0
  13. package/crew/handlers/revise.ts +376 -0
  14. package/crew/handlers/status.ts +295 -0
  15. package/crew/handlers/sync.ts +233 -0
  16. package/crew/handlers/task.ts +792 -0
  17. package/crew/handlers/team.ts +235 -0
  18. package/crew/handlers/work.ts +425 -0
  19. package/crew/id-allocator.ts +30 -0
  20. package/crew/index.ts +257 -0
  21. package/crew/live-progress.ts +58 -0
  22. package/crew/lobby.ts +473 -0
  23. package/crew/prompt.ts +252 -0
  24. package/crew/registry.ts +114 -0
  25. package/crew/spawn.ts +111 -0
  26. package/crew/state-autonomous.ts +164 -0
  27. package/crew/state-planning.ts +263 -0
  28. package/crew/state.ts +20 -0
  29. package/crew/store.ts +642 -0
  30. package/crew/task-actions.ts +131 -0
  31. package/crew/team/store.ts +479 -0
  32. package/crew/team/subagent-roles.ts +87 -0
  33. package/crew/team/types.ts +50 -0
  34. package/crew/types.ts +194 -0
  35. package/crew/utils/artifacts.ts +62 -0
  36. package/crew/utils/config.ts +156 -0
  37. package/crew/utils/discover.ts +219 -0
  38. package/crew/utils/install.ts +85 -0
  39. package/crew/utils/progress.ts +187 -0
  40. package/crew/utils/result.ts +16 -0
  41. package/crew/utils/risk-labels.ts +7 -0
  42. package/crew/utils/task-format.ts +14 -0
  43. package/crew/utils/team-roles.ts +28 -0
  44. package/crew/utils/truncate.ts +79 -0
  45. package/crew/utils/verdict.ts +55 -0
  46. package/feed.ts +268 -0
  47. package/handlers.ts +1107 -0
  48. package/index.ts +1206 -0
  49. package/install.mjs +189 -0
  50. package/lib.ts +467 -0
  51. package/overlay-actions.ts +511 -0
  52. package/overlay-coordinator.ts +150 -0
  53. package/overlay-render.ts +676 -0
  54. package/overlay.ts +830 -0
  55. package/package.json +62 -0
  56. package/skills/pi-messenger-crew/SKILL.md +347 -0
  57. package/store.ts +1139 -0
  58. package/vitest.config.ts +10 -0
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@linxiraos/pi-messenger",
3
+ "version": "1.1.0",
4
+ "description": "Inter-agent messaging and file reservation system for pi coding agent",
5
+ "type": "module",
6
+ "author": "Nico Bailon",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/nicobailon/pi-messenger.git"
11
+ },
12
+ "homepage": "https://github.com/nicobailon/pi-messenger#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/nicobailon/pi-messenger/issues"
15
+ },
16
+ "keywords": [
17
+ "pi-package",
18
+ "pi",
19
+ "pi-coding-agent",
20
+ "extension",
21
+ "messaging",
22
+ "multi-agent",
23
+ "coordination",
24
+ "ai",
25
+ "agents",
26
+ "cli"
27
+ ],
28
+ "bin": {
29
+ "pi-messenger": "install.mjs"
30
+ },
31
+ "files": [
32
+ "*.ts",
33
+ "*.mjs",
34
+ "crew/**",
35
+ "skills/**",
36
+ "README.md",
37
+ "CHANGELOG.md"
38
+ ],
39
+ "scripts": {
40
+ "test": "vitest run",
41
+ "test:watch": "vitest"
42
+ },
43
+ "peerDependencies": {
44
+ "@earendil-works/pi-ai": "*",
45
+ "@earendil-works/pi-agent-core": "*",
46
+ "@earendil-works/pi-coding-agent": "*",
47
+ "@earendil-works/pi-tui": "*",
48
+ "typebox": "*"
49
+ },
50
+ "devDependencies": {
51
+ "vitest": "^2.1.8"
52
+ },
53
+ "pi": {
54
+ "extensions": [
55
+ "./index.ts"
56
+ ],
57
+ "skills": [
58
+ "./skills"
59
+ ]
60
+ },
61
+ "main": "index.ts"
62
+ }
@@ -0,0 +1,347 @@
1
+ ---
2
+ name: pi-messenger-crew
3
+ description: Orchestrator reference for pi-messenger Crew planning, task management, configuration, and agent coordination. Crew workers already have the pi_messenger actions they need in crew-worker.md.
4
+ ---
5
+
6
+ # Pi-Messenger Crew Skill
7
+
8
+ > Crew workers do not need this skill. `crew-worker.md` already contains every `pi_messenger` action workers need for task execution.
9
+ >
10
+ > Orchestrators and humans can use this as the full reference for planning, task management, configuration, and Crew internals.
11
+
12
+ Use pi-messenger for multi-agent coordination and Crew task orchestration.
13
+
14
+ ## Quick Reference
15
+
16
+ ### Join or Leave the Mesh
17
+ ```typescript
18
+ pi_messenger({ action: "join" })
19
+ pi_messenger({ action: "leave" })
20
+ ```
21
+
22
+ ### Check Status
23
+ ```typescript
24
+ pi_messenger({ action: "status" })
25
+ pi_messenger({ action: "list" }) // See other agents
26
+ pi_messenger({ action: "feed" }) // Activity feed
27
+ ```
28
+
29
+ ## Crew Workflow
30
+
31
+ ### 1. Check Crew Agents
32
+ ```typescript
33
+ pi_messenger({ action: "crew.agents" }) // Verify 5 agents
34
+ pi_messenger({ action: "crew.install" }) // Informational: shows discovered sources
35
+ ```
36
+
37
+ ### 2. Plan from PRD
38
+ ```typescript
39
+ // Auto-discover PRD.md in current directory
40
+ pi_messenger({ action: "plan" })
41
+
42
+ // Or specify path
43
+ pi_messenger({ action: "plan", prd: "path/to/PRD.md" })
44
+
45
+ // Or pass an inline prompt (no PRD file needed)
46
+ pi_messenger({ action: "plan", prompt: "Scan the codebase for bugs focusing on error handling" })
47
+
48
+ // Re-plan with a steering prompt (wipes existing tasks, preserves progress notes)
49
+ pi_messenger({ action: "plan", prompt: "Split the auth module into login and registration" })
50
+
51
+ // Steer first-time planning (prompt injected into progress notes before planner runs)
52
+ pi_messenger({ action: "plan", prd: "docs/PRD.md", prompt: "focus on backend first" })
53
+
54
+ // Plan + auto-start autonomous work when planning completes
55
+ pi_messenger({ action: "plan" }) // auto-starts workers (default)
56
+
57
+ // Cancel active or stale planning
58
+ pi_messenger({ action: "plan.cancel" })
59
+ ```
60
+
61
+ Re-planning rejects if any tasks are `in_progress` — stop or complete them first. The steering prompt is injected into `planning-progress.md`'s Notes section where the planner reads it on every pass.
62
+
63
+ ### Optional: Activate Team Context
64
+ ```typescript
65
+ pi_messenger({ action: "team.setup", name: "migration-squad" })
66
+ pi_messenger({ action: "team.setup", name: "review-squad" })
67
+ pi_messenger({ action: "team.setup", name: "research-squad", message: "Research first, then plan the implementation." })
68
+ pi_messenger({ action: "team.memory.note", type: "decision", message: "Use cursor pagination for task history" })
69
+ pi_messenger({ action: "team.roles" })
70
+ pi_messenger({ action: "team.status" })
71
+ ```
72
+
73
+ Team is optional. Use `team.setup` for first-run setup: it activates a profile, saves editable JSON if needed, creates a starter charter when missing, and returns next steps. Crew remains the execution engine. Team role names follow the packaged `pi-subagents` vocabulary where possible (`context-builder`, `delegate`, `oracle`, `planner`, `researcher`, `reviewer`, `scout`, `worker`). `pi-messenger` may read subagent markdown metadata from disk when present, but it does not require or invoke subagents. Active Team profiles let the planner tag tasks with `role` and `riskLabels`, then inject role, charter, and memory context into worker prompts. High-risk tasks wait for `task.approve`; `task.reject` records feedback and rejected tasks surface `task.revise` / `task.revise-tree` next steps.
74
+
75
+ ### 3. Work on Tasks
76
+ ```typescript
77
+ // Single wave (runs ready tasks once)
78
+ pi_messenger({ action: "work" })
79
+
80
+ // Autonomous (keeps running until done/blocked)
81
+ pi_messenger({ action: "work", autonomous: true })
82
+
83
+ // Override concurrency or model for this wave
84
+ pi_messenger({ action: "work", autonomous: true, concurrency: 4 })
85
+ pi_messenger({ action: "work", model: "claude-sonnet-4-20250514" })
86
+ ```
87
+
88
+ ### 4. Task Management
89
+ ```typescript
90
+ pi_messenger({ action: "task.list" })
91
+ pi_messenger({ action: "task.ready" }) // Tasks with no pending deps
92
+ pi_messenger({ action: "task.show", id: "task-1" })
93
+ pi_messenger({ action: "task.start", id: "task-1" })
94
+ pi_messenger({ action: "task.progress", id: "task-1", message: "Implemented auth middleware" })
95
+ pi_messenger({ action: "task.done", id: "task-1", summary: "What was done" })
96
+ pi_messenger({ action: "task.block", id: "task-1", reason: "Why blocked" })
97
+ pi_messenger({ action: "task.unblock", id: "task-1" })
98
+ pi_messenger({ action: "task.reset", id: "task-1" })
99
+ pi_messenger({ action: "task.reset", id: "task-1", cascade: true }) // Reset dependents too
100
+
101
+ // Create tasks manually
102
+ pi_messenger({ action: "task.create", title: "Implement auth", content: "Detailed spec...", dependsOn: ["task-1"] })
103
+ pi_messenger({ action: "task.create", title: "Change auth API", role: "worker", riskLabels: ["auth", "api-contract"] })
104
+ pi_messenger({ action: "task.approve", id: "task-2" })
105
+
106
+ // Split a task into subtasks (two-phase: inspect then execute)
107
+ pi_messenger({ action: "task.split", id: "task-3" }) // Inspect: shows spec, deps, dependents
108
+ pi_messenger({ action: "task.split", id: "task-3", subtasks: [
109
+ { title: "Subtask A", content: "..." },
110
+ { title: "Subtask B", content: "..." }
111
+ ] }) // Execute: creates subtasks, parent becomes milestone
112
+ ```
113
+
114
+ ### 5. Task Revision
115
+ ```typescript
116
+ // Revise a single task's spec (planner rewrites based on your prompt)
117
+ pi_messenger({ action: "task.revise", id: "task-3", prompt: "add error handling for network failures" })
118
+
119
+ // Revise a task and all its transitive dependents (subtree revision)
120
+ // Planner sees the full subtree and can add/remove/modify tasks
121
+ pi_messenger({ action: "task.revise-tree", id: "task-3", prompt: "split this into separate API and CLI tasks" })
122
+ ```
123
+
124
+ Single revision rewrites one task's spec. Tree revision rewrites an entire subtree — the planner can modify existing tasks, add new ones (capped at 2x subtree size), remove pending ones, and rewire dependencies. Done tasks in the subtree are preserved; revisable tasks reset to `todo`.
125
+
126
+ Both revisions are mutually exclusive (only one revision at a time).
127
+
128
+ ### 6. Review
129
+ ```typescript
130
+ // Review a task implementation
131
+ pi_messenger({ action: "review", target: "task-1" })
132
+
133
+ // Review the overall plan
134
+ pi_messenger({ action: "review", target: "plan", type: "plan" })
135
+ ```
136
+
137
+ ## Overlay Keybindings
138
+
139
+ The Crew overlay (accessible via `/messenger` then tab to Crew) supports these keybindings:
140
+
141
+ **Global:** `[+/-]` Adjust worker concurrency (1-10), `[c]` Cancel active planning, `[Esc]` Close/back
142
+
143
+ **Task list view:** `[↑/↓]` Navigate, `[Enter]` Detail view
144
+
145
+ **Task actions (list and detail):**
146
+ - `[s]` Start task (todo only)
147
+ - `[r]` Reset task, `[R]` Cascade reset (reset + all dependents)
148
+ - `[u]` Unblock task (blocked only)
149
+ - `[b]` Block with reason (in_progress only)
150
+ - `[q]` Stop worker (in_progress with live worker)
151
+ - `[m]` Message worker (in_progress with live worker)
152
+ - `[S]` Split task (shows hint with command)
153
+ - `[p]` Revise task spec, `[P]` Revise subtree (not in_progress, not milestone)
154
+ - `[x]` Delete task (not while worker is active)
155
+ - `[←/→]` Navigate between tasks in detail view
156
+
157
+ ## File Coordination
158
+
159
+ ```typescript
160
+ // Reserve files before editing
161
+ pi_messenger({ action: "reserve", paths: ["src/index.ts", "src/types.ts"], reason: "Working on core" })
162
+
163
+ // Release when done
164
+ pi_messenger({ action: "release" })
165
+ ```
166
+
167
+ ## Agent Communication
168
+
169
+ ```typescript
170
+ // Rename yourself
171
+ pi_messenger({ action: "rename", name: "MyAgentName" })
172
+
173
+ // Send message to specific agent
174
+ pi_messenger({ action: "send", to: "OtherAgent", message: "Hello!" })
175
+
176
+ // Broadcast to all
177
+ pi_messenger({ action: "broadcast", message: "Announcement" })
178
+ ```
179
+
180
+ Messages are logged to the feed and visible in the overlay. DMs interrupt only the target agent (delivered as steering); broadcasts interrupt all agents.
181
+
182
+ ## Typical Crew Session
183
+
184
+ ```typescript
185
+ // 1. Join
186
+ pi_messenger({ action: "join" })
187
+
188
+ // 2. Plan (spawns planner agent)
189
+ pi_messenger({ action: "plan" })
190
+
191
+ // 3. Check tasks
192
+ pi_messenger({ action: "task.list" })
193
+
194
+ // 4. Work
195
+ pi_messenger({ action: "work", autonomous: true })
196
+
197
+ // 5. Status
198
+ pi_messenger({ action: "status" })
199
+ ```
200
+
201
+ ## Data Storage
202
+
203
+ Crew stores data in `.pi/messenger/crew/`:
204
+ ```
205
+ .pi/messenger/crew/
206
+ ├── config.json # Project config (concurrency, models, coordination, etc.)
207
+ ├── plan.json # Plan metadata
208
+ ├── planning-progress.md # Planner output log (Notes section for steering)
209
+ ├── planning-outline.md # Latest plan outline
210
+ ├── planning-state.json # Current planning phase/pass
211
+ ├── agents/ # Optional: project-level crew agent overrides
212
+ │ └── crew-worker.md
213
+ ├── tasks/
214
+ │ ├── task-1.json # Task metadata (status, deps, summary)
215
+ │ ├── task-1.md # Task spec (planner-generated)
216
+ │ ├── task-1.progress.md # Worker progress log
217
+ │ └── ...
218
+ ├── blocks/
219
+ │ └── task-N.md # Block context
220
+ └── artifacts/ # Debug artifacts (agent input/output)
221
+ ```
222
+
223
+ Team stores active project state in `.pi/messenger/team/`:
224
+ ```
225
+ .pi/messenger/team/
226
+ ├── team.json # Active team/profile
227
+ ├── charter.md # Project team charter
228
+ ├── memory.jsonl # Structured memory source of truth
229
+ ├── decisions.md # Human-readable memory rollups
230
+ ├── interfaces.md
231
+ ├── risks.md
232
+ └── handoffs.md
233
+ ```
234
+
235
+ Reusable profiles are JSON files under `~/.pi/agent/messenger/team-profiles/`.
236
+
237
+ The activity feed lives at `.pi/messenger/feed.jsonl` (project-scoped, shared across all agents in the project).
238
+
239
+ Each crew agent ships with a default model:
240
+
241
+ | Agent | Role | Default Model |
242
+ |-------|------|---------------|
243
+ | `crew-planner` | planner | `anthropic/claude-opus-4-6` |
244
+ | `crew-worker` | worker | `anthropic/claude-haiku-4-5` |
245
+ | `crew-reviewer` | reviewer | `anthropic/claude-opus-4-6` |
246
+ | `crew-plan-sync` | analyst | `anthropic/claude-haiku-4-5` |
247
+
248
+ Override via `crew.models.<role>` in config. To customize an agent for a project, copy it from `~/.pi/agent/extensions/pi-messenger/crew/agents/` to `.pi/messenger/crew/agents/` and edit the frontmatter — project-level agents override extension defaults by name. Agents support `thinking: <level>` in frontmatter (off, minimal, low, medium, high, xhigh). Config `thinking.<role>` overrides the frontmatter value.
249
+
250
+ ## Configuration
251
+
252
+ User-level config goes in `~/.pi/agent/pi-messenger.json` under a `crew` key. Project-level config goes in `.pi/messenger/crew/config.json`. Project overrides user, both override defaults.
253
+
254
+ Crew spawns multiple LLM sessions in parallel — start with a cheap worker model and scale up. Add this to `~/.pi/agent/pi-messenger.json`:
255
+
256
+ ```json
257
+ { "crew": { "models": { "worker": "claude-haiku-4-5" } } }
258
+ ```
259
+
260
+ Model strings accept `provider/model` format for explicit provider selection and `:level` suffix for inline thinking control:
261
+
262
+ ```json
263
+ { "crew": { "models": { "worker": "anthropic/claude-haiku-4-5", "planner": "openrouter/anthropic/claude-sonnet-4:high" } } }
264
+ ```
265
+
266
+ The `:level` suffix and the `thinking.<role>` config are independent — if both are set, the suffix takes precedence.
267
+
268
+ Full example (`~/.pi/agent/pi-messenger.json`):
269
+ ```json
270
+ {
271
+ "crew": {
272
+ "concurrency": { "workers": 3, "max": 6 },
273
+ "models": { "worker": "claude-haiku-4-5", "planner": "claude-sonnet-4-6" },
274
+ "coordination": "chatty",
275
+ "work": { "maxAttemptsPerTask": 5 }
276
+ }
277
+ }
278
+ ```
279
+
280
+ Project-level (`.pi/messenger/crew/config.json`):
281
+ ```json
282
+ {
283
+ "concurrency": { "workers": 4 },
284
+ "coordination": "moderate",
285
+ "models": { "worker": "gpt-4.1" },
286
+ "planning": { "maxPasses": 1 },
287
+ "work": {
288
+ "maxWaves": 50,
289
+ "env": { "OPENAI_API_BASE": "https://custom.endpoint" }
290
+ }
291
+ }
292
+ ```
293
+
294
+ ### Key Settings
295
+
296
+ | Setting | Description | Default |
297
+ |---------|-------------|---------|
298
+ | `concurrency.workers` | Default parallel workers per wave | `2` |
299
+ | `concurrency.max` | Maximum workers allowed via `+` key (hard ceiling: 10) | `10` |
300
+ | `dependencies` | Dependency scheduling mode: `advisory` or `strict` | `"advisory"` |
301
+ | `coordination` | Worker communication level: `none`, `minimal`, `moderate`, `chatty` | `chatty` |
302
+ | `messageBudgets` | Max outgoing messages per worker per level (sends rejected after limit) | `{ none: 0, minimal: 2, moderate: 5, chatty: 10 }` |
303
+ | `models.worker` | Default model for workers | `anthropic/claude-haiku-4-5` |
304
+ | `models.planner` | Default model for planner | `anthropic/claude-opus-4-6` |
305
+ | `models.reviewer` | Default model for reviewer | `anthropic/claude-opus-4-6` |
306
+ | `models.analyst` | Default model for analyst (plan-sync) | `anthropic/claude-haiku-4-5` |
307
+ | `thinking.planner` | Thinking level for planner agent | (from frontmatter) |
308
+ | `thinking.worker` | Thinking level for worker agents | (from frontmatter) |
309
+ | `thinking.reviewer` | Thinking level for reviewer agents | (from frontmatter) |
310
+ | `thinking.analyst` | Thinking level for analyst agents | (from frontmatter) |
311
+ | `planning.maxPasses` | Max planner/reviewer refinement passes | `1` |
312
+ | `work.maxWaves` | Max autonomous waves | `50` |
313
+ | `work.maxAttemptsPerTask` | Max attempts before auto-blocking a task | `5` |
314
+ | `work.stopOnBlock` | Stop autonomous mode when any task blocks | `false` |
315
+ | `work.shutdownGracePeriodMs` | Grace period before SIGTERM on abort | `30000` |
316
+ | `work.env` | Environment variables passed to spawned workers | `{}` |
317
+
318
+ ### Coordination Levels
319
+
320
+ Controls how much workers communicate during execution:
321
+
322
+ - **`none`**: No coordination instructions. Workers just execute their task.
323
+ - **`minimal`**: Check reservations before editing files. Message if conflicts.
324
+ - **`moderate`**: Announce start/completion via broadcast. Check reservations. Ask about unclear dependencies.
325
+ - **`chatty`** (default): All of moderate, plus: DM peers whose tasks overlap, share progress on interface changes, respond to incoming messages, claim next task after completion.
326
+
327
+ At `moderate` and `chatty`, workers also receive recent activity context and concurrent task info in their prompts.
328
+
329
+ ### Model Override Priority
330
+
331
+ Worker model is resolved with this priority (highest wins):
332
+ 1. Per-task `model` field on the task object
333
+ 2. Per-wave `model` param on the work call
334
+ 3. Team role model when present
335
+ 4. Config-level `crew.models.worker`
336
+ 5. Host session model
337
+ 6. Agent `.md` frontmatter `model` field
338
+
339
+ ### Graceful Shutdown
340
+
341
+ When you cancel a work run (Ctrl+C), workers receive a shutdown sequence:
342
+ 1. Inbox message asking the worker to stop, release reservations, and exit
343
+ 2. Wait `shutdownGracePeriodMs` (default 30s) for clean exit
344
+ 3. SIGTERM if still running, wait 5s
345
+ 4. SIGKILL if still running
346
+
347
+ Tasks from gracefully shutdown workers reset to `todo` for retry on the next wave. Crashed workers (non-graceful exit) block the task in autonomous mode to prevent retry loops.