@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/crew/index.ts ADDED
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Crew - Action Router
3
+ *
4
+ * Routes crew actions to their respective handlers.
5
+ * Simplified: PRD → plan → tasks → work → done
6
+ */
7
+
8
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
9
+ import type { MessengerState, Dirs, AgentMailMessage, NameThemeConfig } from "../lib.ts";
10
+ import * as handlers from "../handlers.ts";
11
+ import type { CrewParams, AppendEntryFn } from "./types.ts";
12
+ import { result } from "./utils/result.ts";
13
+ import { isPlanningForCwd, cancelPlanningRun, autonomousState, isAutonomousForCwd, stopAutonomous } from "./state.ts";
14
+ import { logFeedEvent } from "../feed.ts";
15
+
16
+ type DeliverFn = (msg: AgentMailMessage) => void;
17
+ type UpdateStatusFn = (ctx: ExtensionContext) => void;
18
+
19
+ export interface CrewActionConfig {
20
+ stuckThreshold?: number;
21
+ crewEventsInFeed?: boolean;
22
+ nameTheme?: NameThemeConfig;
23
+ feedRetention?: number;
24
+ }
25
+
26
+ /**
27
+ * Execute a crew action.
28
+ *
29
+ * Routes action strings like "task.show" to the appropriate handler.
30
+ */
31
+ export async function executeCrewAction(
32
+ action: string,
33
+ params: CrewParams,
34
+ state: MessengerState,
35
+ dirs: Dirs,
36
+ ctx: ExtensionContext,
37
+ deliverMessage: DeliverFn,
38
+ updateStatus: UpdateStatusFn,
39
+ appendEntry: AppendEntryFn,
40
+ config?: CrewActionConfig,
41
+ signal?: AbortSignal
42
+ ) {
43
+ const sessionModel = state.model || undefined;
44
+ // Parse action: "task.show" → group="task", op="show"
45
+ const dotIndex = action.indexOf('.');
46
+ const group = dotIndex > 0 ? action.slice(0, dotIndex) : action;
47
+ const op = dotIndex > 0 ? action.slice(dotIndex + 1) : null;
48
+
49
+ // ═══════════════════════════════════════════════════════════════════════
50
+ // Actions that DON'T require registration
51
+ // ═══════════════════════════════════════════════════════════════════════
52
+
53
+ // join - this is how you register
54
+ if (group === 'join') {
55
+ return handlers.executeJoin(state, dirs, ctx, deliverMessage, updateStatus, params.spec, config?.nameTheme, config?.feedRetention);
56
+ }
57
+
58
+ // autoRegisterPath - config management, not agent operation
59
+ if (group === 'autoRegisterPath') {
60
+ if (!params.autoRegisterPath) {
61
+ return result("Error: autoRegisterPath requires value ('add', 'remove', or 'list').",
62
+ { mode: "autoRegisterPath", error: "missing_value" });
63
+ }
64
+ return handlers.executeAutoRegisterPath(params.autoRegisterPath, ctx.cwd);
65
+ }
66
+
67
+ // ═══════════════════════════════════════════════════════════════════════
68
+ // All other actions require registration
69
+ // ═══════════════════════════════════════════════════════════════════════
70
+ if (!state.registered) {
71
+ return handlers.notRegisteredError();
72
+ }
73
+
74
+ switch (group) {
75
+ // ═══════════════════════════════════════════════════════════════════════
76
+ // Coordination actions (delegate to existing handlers)
77
+ // ═══════════════════════════════════════════════════════════════════════
78
+ case 'status':
79
+ return handlers.executeStatus(state, dirs, ctx.cwd);
80
+
81
+ case 'leave':
82
+ return handlers.executeLeave(state, dirs, ctx);
83
+
84
+ case 'list':
85
+ return handlers.executeList(state, dirs, ctx.cwd, { stuckThreshold: config?.stuckThreshold });
86
+
87
+ case 'whois': {
88
+ if (!params.name) {
89
+ return result("Error: name required for whois action.", { mode: "whois", error: "missing_name" });
90
+ }
91
+ return handlers.executeWhois(state, dirs, ctx.cwd, params.name, { stuckThreshold: config?.stuckThreshold });
92
+ }
93
+
94
+ case 'set_status': {
95
+ return handlers.executeSetStatus(state, dirs, ctx, params.message);
96
+ }
97
+
98
+ case 'feed': {
99
+ return handlers.executeFeed(ctx.cwd, params.limit, config?.crewEventsInFeed ?? true);
100
+ }
101
+
102
+ case 'spec':
103
+ if (!params.spec) {
104
+ return result("Error: spec path required.", { mode: "spec", error: "missing_spec" });
105
+ }
106
+ return handlers.executeSetSpec(state, dirs, ctx, params.spec);
107
+
108
+ case 'send':
109
+ return handlers.executeSend(state, dirs, ctx.cwd, params.to, false, params.message, params.replyTo);
110
+
111
+ case 'broadcast':
112
+ return handlers.executeSend(state, dirs, ctx.cwd, undefined, true, params.message, params.replyTo);
113
+
114
+ case 'reserve':
115
+ if (!params.paths || params.paths.length === 0) {
116
+ return result("Error: paths required for reserve action.", { mode: "reserve", error: "missing_paths" });
117
+ }
118
+ return handlers.executeReserve(state, dirs, ctx, params.paths, params.reason);
119
+
120
+ case 'release':
121
+ return handlers.executeRelease(state, dirs, ctx, params.paths ?? true);
122
+
123
+ case 'rename':
124
+ if (!params.name) {
125
+ return result("Error: name required for rename action.", { mode: "rename", error: "missing_name" });
126
+ }
127
+ return handlers.executeRename(state, dirs, ctx, params.name, deliverMessage, updateStatus);
128
+
129
+ case 'swarm':
130
+ return handlers.executeSwarm(state, dirs, ctx.cwd, params.spec);
131
+
132
+ case 'claim':
133
+ if (!params.taskId) {
134
+ return result("Error: taskId required for claim action.", { mode: "claim", error: "missing_taskId" });
135
+ }
136
+ return handlers.executeClaim(state, dirs, ctx, params.taskId, params.spec, params.reason);
137
+
138
+ case 'unclaim':
139
+ if (!params.taskId) {
140
+ return result("Error: taskId required for unclaim action.", { mode: "unclaim", error: "missing_taskId" });
141
+ }
142
+ return handlers.executeUnclaim(state, dirs, ctx.cwd, params.taskId, params.spec);
143
+
144
+ case 'complete':
145
+ if (!params.taskId) {
146
+ return result("Error: taskId required for complete action.", { mode: "complete", error: "missing_taskId" });
147
+ }
148
+ return handlers.executeComplete(state, dirs, ctx.cwd, params.taskId, params.notes, params.spec);
149
+
150
+ // ═══════════════════════════════════════════════════════════════════════
151
+ // Crew actions - Simplified PRD-based workflow
152
+ // ═══════════════════════════════════════════════════════════════════════
153
+ case 'team': {
154
+ if (!op) {
155
+ return result("Error: team action requires operation (e.g., 'team.status', 'team.profile.list').",
156
+ { mode: "team", error: "missing_operation" });
157
+ }
158
+ try {
159
+ const teamHandlers = await import("./handlers/team.ts");
160
+ return teamHandlers.execute(op, params, state, ctx);
161
+ } catch (e) {
162
+ return result(`Error: team.${op} handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
163
+ { mode: "team", error: "handler_error", operation: op });
164
+ }
165
+ }
166
+
167
+ case 'task': {
168
+ if (!op) {
169
+ return result("Error: task action requires operation (e.g., 'task.show', 'task.list').",
170
+ { mode: "task", error: "missing_operation" });
171
+ }
172
+ try {
173
+ const taskHandlers = await import("./handlers/task.ts");
174
+ return taskHandlers.execute(op, params, state, ctx);
175
+ } catch (e) {
176
+ return result(`Error: task.${op} handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
177
+ { mode: "task", error: "handler_error", operation: op });
178
+ }
179
+ }
180
+
181
+ case 'plan': {
182
+ if (op === 'cancel') {
183
+ const cwd = ctx.cwd;
184
+ if (!isPlanningForCwd(cwd)) {
185
+ return result("No active planning to cancel.", { mode: "plan.cancel" });
186
+ }
187
+ cancelPlanningRun(cwd);
188
+ logFeedEvent(cwd, state.agentName || "unknown", "plan.cancel");
189
+ return result("Planning cancelled.", { mode: "plan.cancel" });
190
+ }
191
+ try {
192
+ const planHandler = await import("./handlers/plan.ts");
193
+ return planHandler.execute(params, ctx, state.agentName || "unknown", () => updateStatus(ctx), sessionModel);
194
+ } catch (e) {
195
+ return result(`Error: plan handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
196
+ { mode: "plan", error: "handler_error" });
197
+ }
198
+ }
199
+
200
+ case 'work': {
201
+ if (op === 'stop') {
202
+ const cwd = ctx.cwd;
203
+ if (!isAutonomousForCwd(cwd)) {
204
+ return result("No autonomous work running for this project.", { mode: "work.stop" });
205
+ }
206
+ stopAutonomous("manual");
207
+ appendEntry("crew-state", autonomousState);
208
+ return result("Autonomous work stopped.", { mode: "work.stop", autonomous: false });
209
+ }
210
+
211
+ try {
212
+ const workHandler = await import("./handlers/work.ts");
213
+ return workHandler.execute(params, dirs, ctx, appendEntry, signal, sessionModel);
214
+ } catch (e) {
215
+ return result(`Error: work handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
216
+ { mode: "work", error: "handler_error" });
217
+ }
218
+ }
219
+
220
+ case 'review': {
221
+ try {
222
+ const reviewHandler = await import("./handlers/review.ts");
223
+ return reviewHandler.execute(params, ctx, sessionModel);
224
+ } catch (e) {
225
+ return result(`Error: review handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
226
+ { mode: "review", error: "handler_error" });
227
+ }
228
+ }
229
+
230
+ case 'sync': {
231
+ try {
232
+ const syncHandler = await import("./handlers/sync.ts");
233
+ return syncHandler.execute(params, ctx, sessionModel);
234
+ } catch (e) {
235
+ return result(`Error: sync handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
236
+ { mode: "sync", error: "handler_error" });
237
+ }
238
+ }
239
+
240
+ case 'crew': {
241
+ if (!op) {
242
+ return result("Error: crew action requires operation (e.g., 'crew.status', 'crew.agents').",
243
+ { mode: "crew", error: "missing_operation" });
244
+ }
245
+ try {
246
+ const statusHandlers = await import("./handlers/status.ts");
247
+ return statusHandlers.executeCrew(op, ctx);
248
+ } catch (e) {
249
+ return result(`Error: crew.${op} handler failed: ${e instanceof Error ? e.message : 'unknown'}`,
250
+ { mode: "crew", error: "handler_error", operation: op });
251
+ }
252
+ }
253
+
254
+ default:
255
+ return result(`Unknown action: ${action}`, { mode: "error", error: "unknown_action", action });
256
+ }
257
+ }
@@ -0,0 +1,58 @@
1
+ import type { AgentProgress } from "./utils/progress.ts";
2
+
3
+ export interface LiveWorkerInfo {
4
+ cwd: string;
5
+ taskId: string;
6
+ agent: string;
7
+ name: string;
8
+ progress: AgentProgress;
9
+ startedAt: number;
10
+ }
11
+
12
+ const liveWorkers = new Map<string, LiveWorkerInfo>();
13
+ const listeners = new Set<() => void>();
14
+
15
+ function getWorkerKey(cwd: string, taskId: string): string {
16
+ return `${cwd}::${taskId}`;
17
+ }
18
+
19
+ export function updateLiveWorker(cwd: string, taskId: string, info: Omit<LiveWorkerInfo, "cwd">): void {
20
+ liveWorkers.set(getWorkerKey(cwd, taskId), {
21
+ ...info,
22
+ cwd,
23
+ });
24
+ notifyListeners();
25
+ }
26
+
27
+ export function removeLiveWorker(cwd: string, taskId: string): void {
28
+ liveWorkers.delete(getWorkerKey(cwd, taskId));
29
+ notifyListeners();
30
+ }
31
+
32
+ export function getLiveWorkers(cwd?: string): ReadonlyMap<string, LiveWorkerInfo> {
33
+ if (!cwd) return new Map(liveWorkers);
34
+
35
+ const filtered = new Map<string, LiveWorkerInfo>();
36
+ for (const info of liveWorkers.values()) {
37
+ if (info.cwd !== cwd) continue;
38
+ filtered.set(info.taskId, info);
39
+ }
40
+ return filtered;
41
+ }
42
+
43
+ export function hasLiveWorkers(cwd?: string): boolean {
44
+ if (!cwd) return liveWorkers.size > 0;
45
+ for (const info of liveWorkers.values()) {
46
+ if (info.cwd === cwd) return true;
47
+ }
48
+ return false;
49
+ }
50
+
51
+ export function onLiveWorkersChanged(fn: () => void): () => void {
52
+ listeners.add(fn);
53
+ return () => listeners.delete(fn);
54
+ }
55
+
56
+ function notifyListeners(): void {
57
+ for (const fn of listeners) fn();
58
+ }