@linxiraos/pi-messenger 1.1.0 → 1.3.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 (66) hide show
  1. package/CHANGELOG.md +741 -676
  2. package/LICENSE +45 -0
  3. package/README.md +424 -424
  4. package/THIRD-PARTY-NOTICES.txt +22951 -0
  5. package/config-overlay.ts +175 -171
  6. package/config.ts +221 -209
  7. package/crew/agents/crew-plan-sync.md +66 -64
  8. package/crew/agents/crew-planner.md +173 -172
  9. package/crew/agents/crew-reviewer.md +58 -58
  10. package/crew/agents/crew-worker.md +130 -129
  11. package/crew/agents.ts +507 -434
  12. package/crew/handlers/coordination.ts +350 -332
  13. package/crew/handlers/plan.ts +988 -906
  14. package/crew/handlers/review.ts +354 -333
  15. package/crew/handlers/revise.ts +400 -376
  16. package/crew/handlers/status.ts +303 -295
  17. package/crew/handlers/sync.ts +237 -233
  18. package/crew/handlers/task.ts +820 -792
  19. package/crew/handlers/team.ts +294 -235
  20. package/crew/handlers/work.ts +467 -425
  21. package/crew/id-allocator.ts +30 -30
  22. package/crew/index.ts +297 -257
  23. package/crew/live-progress.ts +58 -58
  24. package/crew/lobby.ts +504 -473
  25. package/crew/prompt.ts +262 -252
  26. package/crew/registry.ts +114 -114
  27. package/crew/spawn.ts +135 -111
  28. package/crew/state-autonomous.ts +163 -164
  29. package/crew/state-planning.ts +264 -263
  30. package/crew/state.ts +20 -20
  31. package/crew/store.ts +646 -642
  32. package/crew/task-actions.ts +162 -131
  33. package/crew/team/store.ts +572 -479
  34. package/crew/team/subagent-roles.ts +105 -87
  35. package/crew/team/types.ts +50 -50
  36. package/crew/types.ts +194 -194
  37. package/crew/utils/artifacts.ts +57 -62
  38. package/crew/utils/config.ts +158 -156
  39. package/crew/utils/discover.ts +221 -219
  40. package/crew/utils/install.ts +94 -85
  41. package/crew/utils/migrations.ts +126 -0
  42. package/crew/utils/progress.ts +191 -187
  43. package/crew/utils/result.ts +16 -16
  44. package/crew/utils/risk-labels.ts +5 -7
  45. package/crew/utils/task-format.ts +14 -14
  46. package/crew/utils/team-roles.ts +44 -28
  47. package/crew/utils/truncate.ts +76 -79
  48. package/crew/utils/verdict.ts +55 -55
  49. package/editor-binary.ts +150 -0
  50. package/editor-command.ts +107 -0
  51. package/editor-target.ts +40 -0
  52. package/feed.ts +321 -268
  53. package/handlers.ts +1041 -1107
  54. package/index.ts +1314 -1206
  55. package/install.mjs +187 -189
  56. package/lib.ts +587 -467
  57. package/overlay-actions.ts +519 -511
  58. package/overlay-coordinator.ts +150 -150
  59. package/overlay-render.ts +770 -676
  60. package/overlay.ts +872 -830
  61. package/package.json +64 -60
  62. package/paths.ts +60 -0
  63. package/skills/pi-messenger-crew/SKILL.md +375 -347
  64. package/store.ts +1147 -1139
  65. package/teamagent-command.ts +321 -0
  66. package/vitest.config.ts +10 -10
@@ -1,30 +1,30 @@
1
- /**
2
- * Crew - ID Allocator
3
- *
4
- * Simple task ID allocation: task-1, task-2, ...
5
- */
6
-
7
- import * as fs from "node:fs";
8
- import * as path from "node:path";
9
-
10
- /**
11
- * Scans existing tasks to determine the next sequence number.
12
- * Returns task ID in format: task-N
13
- */
14
- export function allocateTaskId(cwd: string): string {
15
- const tasksDir = path.join(cwd, ".pi", "messenger", "crew", "tasks");
16
-
17
- let maxN = 0;
18
- if (fs.existsSync(tasksDir)) {
19
- for (const file of fs.readdirSync(tasksDir)) {
20
- const match = file.match(/^task-(\d+)\.json$/);
21
- if (match) {
22
- const n = parseInt(match[1], 10);
23
- if (n > maxN) maxN = n;
24
- }
25
- }
26
- }
27
-
28
- return `task-${maxN + 1}`;
29
- }
30
-
1
+ /**
2
+ * Crew - ID Allocator
3
+ *
4
+ * Simple task ID allocation: task-1, task-2, ...
5
+ */
6
+
7
+ import * as fs from "node:fs";
8
+ import * as path from "node:path";
9
+ import { getProjectCrewDir } from "../paths.ts";
10
+
11
+ /**
12
+ * Scans existing tasks to determine the next sequence number.
13
+ * Returns task ID in format: task-N
14
+ */
15
+ export function allocateTaskId(cwd: string): string {
16
+ const tasksDir = path.join(getProjectCrewDir(cwd), "tasks");
17
+
18
+ let maxN = 0;
19
+ if (fs.existsSync(tasksDir)) {
20
+ for (const file of fs.readdirSync(tasksDir)) {
21
+ const match = file.match(/^task-(\d+)\.json$/);
22
+ if (match) {
23
+ const n = parseInt(match[1], 10);
24
+ if (n > maxN) maxN = n;
25
+ }
26
+ }
27
+ }
28
+
29
+ return `task-${maxN + 1}`;
30
+ }
package/crew/index.ts CHANGED
@@ -1,257 +1,297 @@
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
- }
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 "@linxiraos/zeta";
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(
56
+ state,
57
+ dirs,
58
+ ctx,
59
+ deliverMessage,
60
+ updateStatus,
61
+ params.spec,
62
+ config?.nameTheme,
63
+ config?.feedRetention,
64
+ );
65
+ }
66
+
67
+ // autoRegisterPath - config management, not agent operation
68
+ if (group === "autoRegisterPath") {
69
+ if (!params.autoRegisterPath) {
70
+ return result("Error: autoRegisterPath requires value ('add', 'remove', or 'list').", {
71
+ mode: "autoRegisterPath",
72
+ error: "missing_value",
73
+ });
74
+ }
75
+ return handlers.executeAutoRegisterPath(params.autoRegisterPath, ctx.cwd);
76
+ }
77
+
78
+ // ═══════════════════════════════════════════════════════════════════════
79
+ // All other actions require registration
80
+ // ═══════════════════════════════════════════════════════════════════════
81
+ if (!state.registered) {
82
+ return handlers.notRegisteredError();
83
+ }
84
+
85
+ switch (group) {
86
+ // ═══════════════════════════════════════════════════════════════════════
87
+ // Coordination actions (delegate to existing handlers)
88
+ // ═══════════════════════════════════════════════════════════════════════
89
+ case "status":
90
+ return handlers.executeStatus(state, dirs, ctx.cwd);
91
+
92
+ case "leave":
93
+ return handlers.executeLeave(state, dirs, ctx);
94
+
95
+ case "list":
96
+ return handlers.executeList(state, dirs, ctx.cwd, { stuckThreshold: config?.stuckThreshold });
97
+
98
+ case "whois": {
99
+ if (!params.name) {
100
+ return result("Error: name required for whois action.", { mode: "whois", error: "missing_name" });
101
+ }
102
+ return handlers.executeWhois(state, dirs, ctx.cwd, params.name, { stuckThreshold: config?.stuckThreshold });
103
+ }
104
+
105
+ case "set_status": {
106
+ return handlers.executeSetStatus(state, dirs, ctx, params.message);
107
+ }
108
+
109
+ case "feed": {
110
+ return handlers.executeFeed(ctx.cwd, params.limit, config?.crewEventsInFeed ?? true);
111
+ }
112
+
113
+ case "spec":
114
+ if (!params.spec) {
115
+ return result("Error: spec path required.", { mode: "spec", error: "missing_spec" });
116
+ }
117
+ return handlers.executeSetSpec(state, dirs, ctx, params.spec);
118
+
119
+ case "send":
120
+ return handlers.executeSend(state, dirs, ctx.cwd, params.to, false, params.message, params.replyTo);
121
+
122
+ case "broadcast":
123
+ return handlers.executeSend(state, dirs, ctx.cwd, undefined, true, params.message, params.replyTo);
124
+
125
+ case "reserve":
126
+ if (!params.paths || params.paths.length === 0) {
127
+ return result("Error: paths required for reserve action.", { mode: "reserve", error: "missing_paths" });
128
+ }
129
+ return handlers.executeReserve(state, dirs, ctx, params.paths, params.reason);
130
+
131
+ case "release":
132
+ return handlers.executeRelease(state, dirs, ctx, params.paths ?? true);
133
+
134
+ case "rename":
135
+ if (!params.name) {
136
+ return result("Error: name required for rename action.", { mode: "rename", error: "missing_name" });
137
+ }
138
+ return handlers.executeRename(state, dirs, ctx, params.name, deliverMessage, updateStatus);
139
+
140
+ case "swarm":
141
+ return handlers.executeSwarm(state, dirs, ctx.cwd, params.spec);
142
+
143
+ case "claim":
144
+ if (!params.taskId) {
145
+ return result("Error: taskId required for claim action.", { mode: "claim", error: "missing_taskId" });
146
+ }
147
+ return handlers.executeClaim(state, dirs, ctx, params.taskId, params.spec, params.reason);
148
+
149
+ case "unclaim":
150
+ if (!params.taskId) {
151
+ return result("Error: taskId required for unclaim action.", { mode: "unclaim", error: "missing_taskId" });
152
+ }
153
+ return handlers.executeUnclaim(state, dirs, ctx.cwd, params.taskId, params.spec);
154
+
155
+ case "complete":
156
+ if (!params.taskId) {
157
+ return result("Error: taskId required for complete action.", { mode: "complete", error: "missing_taskId" });
158
+ }
159
+ return handlers.executeComplete(state, dirs, ctx.cwd, params.taskId, params.notes, params.spec);
160
+
161
+ // ═══════════════════════════════════════════════════════════════════════
162
+ // Crew actions - Simplified PRD-based workflow
163
+ // ═══════════════════════════════════════════════════════════════════════
164
+ case "team": {
165
+ if (!op) {
166
+ return result("Error: team action requires operation (e.g., 'team.status', 'team.profile.list').", {
167
+ mode: "team",
168
+ error: "missing_operation",
169
+ });
170
+ }
171
+ try {
172
+ const teamHandlers = await import("./handlers/team.ts");
173
+ return teamHandlers.execute(op, params, state, ctx);
174
+ } catch (e) {
175
+ return result(`Error: team.${op} handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
176
+ mode: "team",
177
+ error: "handler_error",
178
+ operation: op,
179
+ });
180
+ }
181
+ }
182
+
183
+ case "task": {
184
+ if (!op) {
185
+ return result("Error: task action requires operation (e.g., 'task.show', 'task.list').", {
186
+ mode: "task",
187
+ error: "missing_operation",
188
+ });
189
+ }
190
+ try {
191
+ const taskHandlers = await import("./handlers/task.ts");
192
+ return taskHandlers.execute(op, params, state, ctx);
193
+ } catch (e) {
194
+ return result(`Error: task.${op} handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
195
+ mode: "task",
196
+ error: "handler_error",
197
+ operation: op,
198
+ });
199
+ }
200
+ }
201
+
202
+ case "plan": {
203
+ if (op === "cancel") {
204
+ const cwd = ctx.cwd;
205
+ if (!isPlanningForCwd(cwd)) {
206
+ return result("No active planning to cancel.", { mode: "plan.cancel" });
207
+ }
208
+ cancelPlanningRun(cwd);
209
+ logFeedEvent(cwd, state.agentName || "unknown", "plan.cancel");
210
+ return result("Planning cancelled.", { mode: "plan.cancel" });
211
+ }
212
+ try {
213
+ const planHandler = await import("./handlers/plan.ts");
214
+ return planHandler.execute(
215
+ params,
216
+ ctx,
217
+ state.agentName || "unknown",
218
+ () => updateStatus(ctx),
219
+ sessionModel,
220
+ );
221
+ } catch (e) {
222
+ return result(`Error: plan handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
223
+ mode: "plan",
224
+ error: "handler_error",
225
+ });
226
+ }
227
+ }
228
+
229
+ case "work": {
230
+ if (op === "stop") {
231
+ const cwd = ctx.cwd;
232
+ if (!isAutonomousForCwd(cwd)) {
233
+ return result("No autonomous work running for this project.", { mode: "work.stop" });
234
+ }
235
+ stopAutonomous("manual");
236
+ appendEntry("crew-state", autonomousState);
237
+ return result("Autonomous work stopped.", { mode: "work.stop", autonomous: false });
238
+ }
239
+
240
+ try {
241
+ const workHandler = await import("./handlers/work.ts");
242
+ return workHandler.execute(params, dirs, ctx, appendEntry, signal, sessionModel);
243
+ } catch (e) {
244
+ return result(`Error: work handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
245
+ mode: "work",
246
+ error: "handler_error",
247
+ });
248
+ }
249
+ }
250
+
251
+ case "review": {
252
+ try {
253
+ const reviewHandler = await import("./handlers/review.ts");
254
+ return reviewHandler.execute(params, ctx, sessionModel);
255
+ } catch (e) {
256
+ return result(`Error: review handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
257
+ mode: "review",
258
+ error: "handler_error",
259
+ });
260
+ }
261
+ }
262
+
263
+ case "sync": {
264
+ try {
265
+ const syncHandler = await import("./handlers/sync.ts");
266
+ return syncHandler.execute(params, ctx, sessionModel);
267
+ } catch (e) {
268
+ return result(`Error: sync handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
269
+ mode: "sync",
270
+ error: "handler_error",
271
+ });
272
+ }
273
+ }
274
+
275
+ case "crew": {
276
+ if (!op) {
277
+ return result("Error: crew action requires operation (e.g., 'crew.status', 'crew.agents').", {
278
+ mode: "crew",
279
+ error: "missing_operation",
280
+ });
281
+ }
282
+ try {
283
+ const statusHandlers = await import("./handlers/status.ts");
284
+ return statusHandlers.executeCrew(op, ctx);
285
+ } catch (e) {
286
+ return result(`Error: crew.${op} handler failed: ${e instanceof Error ? e.message : "unknown"}`, {
287
+ mode: "crew",
288
+ error: "handler_error",
289
+ operation: op,
290
+ });
291
+ }
292
+ }
293
+
294
+ default:
295
+ return result(`Unknown action: ${action}`, { mode: "error", error: "unknown_action", action });
296
+ }
297
+ }