@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,131 +1,162 @@
1
- import { logFeedEvent } from "../feed.ts";
2
- import * as store from "./store.ts";
3
- import { loadCrewConfig } from "./utils/config.ts";
4
- import { killWorkerByTask } from "./registry.ts";
5
- import type { Task } from "./types.ts";
6
-
7
- export type TaskAction = "start" | "block" | "unblock" | "reset" | "cascade-reset" | "delete" | "stop";
8
-
9
- export interface TaskActionOptions {
10
- isWorkerActive?: (taskId: string) => boolean;
11
- }
12
-
13
- export interface TaskActionResult {
14
- success: boolean;
15
- message: string;
16
- error?: string;
17
- task?: Task;
18
- resetTasks?: Task[];
19
- unmetDependencies?: string[];
20
- }
21
-
22
- export function executeTaskAction(
23
- cwd: string,
24
- action: TaskAction,
25
- taskId: string,
26
- agentName: string,
27
- reason?: string,
28
- options?: TaskActionOptions,
29
- ): TaskActionResult {
30
- const task = store.getTask(cwd, taskId);
31
- if (!task) return { success: false, error: "not_found", message: `Task ${taskId} not found` };
32
-
33
- switch (action) {
34
- case "start": {
35
- if (task.milestone) {
36
- return { success: false, error: "milestone_not_startable", message: `Task ${taskId} is a milestone and cannot be started manually` };
37
- }
38
- if (task.status === "in_progress" && task.assigned_to === agentName) {
39
- return { success: true, message: `Already started ${taskId}`, task };
40
- }
41
- if (task.status !== "todo") {
42
- return { success: false, error: "invalid_status", message: `Task ${taskId} is ${task.status}, not todo` };
43
- }
44
- const config = loadCrewConfig(store.getCrewDir(cwd));
45
- if (config.dependencies !== "advisory") {
46
- const unmetDependencies = task.depends_on.filter(depId => store.getTask(cwd, depId)?.status !== "done");
47
- if (unmetDependencies.length > 0) {
48
- return {
49
- success: false,
50
- error: "unmet_dependencies",
51
- message: `Unmet dependencies: ${unmetDependencies.join(", ")}`,
52
- unmetDependencies,
53
- };
54
- }
55
- }
56
- const started = store.startTask(cwd, taskId, agentName);
57
- if (!started) return { success: false, error: "start_failed", message: `Failed to start ${taskId}` };
58
- logFeedEvent(cwd, agentName, "task.start", taskId, started.title);
59
- return { success: true, message: `Started ${taskId}`, task: started };
60
- }
61
-
62
- case "block": {
63
- if (task.status !== "in_progress") {
64
- return { success: false, error: "invalid_status", message: `Task ${taskId} must be in_progress to block` };
65
- }
66
- if (!reason) {
67
- return { success: false, error: "missing_reason", message: `Reason required to block ${taskId}` };
68
- }
69
- const blocked = store.blockTask(cwd, taskId, reason);
70
- if (!blocked) return { success: false, error: "block_failed", message: `Failed to block ${taskId}` };
71
- logFeedEvent(cwd, agentName, "task.block", taskId, reason);
72
- return { success: true, message: `Blocked ${taskId}`, task: blocked };
73
- }
74
-
75
- case "unblock": {
76
- if (task.status !== "blocked") {
77
- return { success: false, error: "invalid_status", message: `Task ${taskId} is ${task.status}, not blocked` };
78
- }
79
- const unblocked = store.unblockTask(cwd, taskId);
80
- if (!unblocked) return { success: false, error: "unblock_failed", message: `Failed to unblock ${taskId}` };
81
- logFeedEvent(cwd, agentName, "task.unblock", taskId, unblocked.title);
82
- return { success: true, message: `Unblocked ${taskId}`, task: unblocked };
83
- }
84
-
85
- case "reset": {
86
- if (options?.isWorkerActive?.(taskId)) {
87
- return { success: false, error: "active_worker", message: `Cannot reset ${taskId} while its worker is active` };
88
- }
89
- const resetTasks = store.resetTask(cwd, taskId, false);
90
- if (resetTasks.length === 0) return { success: false, error: "reset_failed", message: `Failed to reset ${taskId}` };
91
- logFeedEvent(cwd, agentName, "task.reset", taskId, task.title);
92
- return { success: true, message: `Reset ${taskId}`, resetTasks };
93
- }
94
-
95
- case "cascade-reset": {
96
- const subtree = [task, ...store.getTransitiveDependents(cwd, taskId)];
97
- const activeTask = subtree.find(t => options?.isWorkerActive?.(t.id));
98
- if (activeTask) {
99
- return { success: false, error: "active_worker", message: `Cannot reset ${activeTask.id} while its worker is active` };
100
- }
101
- const resetTasks = store.resetTask(cwd, taskId, true);
102
- if (resetTasks.length === 0) return { success: false, error: "reset_failed", message: `Failed to reset ${taskId}` };
103
- logFeedEvent(cwd, agentName, "task.reset", taskId, `cascade (${resetTasks.length} tasks)`);
104
- return { success: true, message: `Reset ${taskId} + ${Math.max(0, resetTasks.length - 1)} dependents`, resetTasks };
105
- }
106
-
107
- case "delete": {
108
- if (task.status === "in_progress" && options?.isWorkerActive?.(taskId)) {
109
- return { success: false, error: "active_worker", message: `Cannot delete ${taskId} while its worker is active` };
110
- }
111
- if (!store.deleteTask(cwd, taskId)) return { success: false, error: "delete_failed", message: `Failed to delete ${taskId}` };
112
- logFeedEvent(cwd, agentName, "task.delete", taskId, task.title);
113
- return { success: true, message: `Deleted ${taskId}` };
114
- }
115
-
116
- case "stop": {
117
- if (task.status !== "in_progress") {
118
- return { success: false, error: "invalid_status", message: `Task ${taskId} is ${task.status}, not in_progress` };
119
- }
120
- if (options?.isWorkerActive?.(taskId)) {
121
- killWorkerByTask(cwd, taskId);
122
- store.appendTaskProgress(cwd, taskId, agentName, "Worker stopped by user");
123
- } else {
124
- store.appendTaskProgress(cwd, taskId, agentName, "Task unassigned (no active worker)");
125
- }
126
- store.updateTask(cwd, taskId, { status: "todo", assigned_to: undefined });
127
- logFeedEvent(cwd, agentName, "task.reset", taskId, "stopped");
128
- return { success: true, message: `Stopped ${taskId}` };
129
- }
130
- }
131
- }
1
+ import { logFeedEvent } from "../feed.ts";
2
+ import * as store from "./store.ts";
3
+ import { loadCrewConfig } from "./utils/config.ts";
4
+ import { killWorkerByTask } from "./registry.ts";
5
+ import type { Task } from "./types.ts";
6
+
7
+ export type TaskAction = "start" | "block" | "unblock" | "reset" | "cascade-reset" | "delete" | "stop";
8
+
9
+ export interface TaskActionOptions {
10
+ isWorkerActive?: (taskId: string) => boolean;
11
+ }
12
+
13
+ export interface TaskActionResult {
14
+ success: boolean;
15
+ message: string;
16
+ error?: string;
17
+ task?: Task;
18
+ resetTasks?: Task[];
19
+ unmetDependencies?: string[];
20
+ }
21
+
22
+ export function executeTaskAction(
23
+ cwd: string,
24
+ action: TaskAction,
25
+ taskId: string,
26
+ agentName: string,
27
+ reason?: string,
28
+ options?: TaskActionOptions,
29
+ ): TaskActionResult {
30
+ const task = store.getTask(cwd, taskId);
31
+ if (!task) return { success: false, error: "not_found", message: `Task ${taskId} not found` };
32
+
33
+ switch (action) {
34
+ case "start": {
35
+ if (task.milestone) {
36
+ return {
37
+ success: false,
38
+ error: "milestone_not_startable",
39
+ message: `Task ${taskId} is a milestone and cannot be started manually`,
40
+ };
41
+ }
42
+ if (task.status === "in_progress" && task.assigned_to === agentName) {
43
+ return { success: true, message: `Already started ${taskId}`, task };
44
+ }
45
+ if (task.status !== "todo") {
46
+ return { success: false, error: "invalid_status", message: `Task ${taskId} is ${task.status}, not todo` };
47
+ }
48
+ const config = loadCrewConfig(store.getCrewDir(cwd));
49
+ if (config.dependencies !== "advisory") {
50
+ const unmetDependencies = task.depends_on.filter(depId => store.getTask(cwd, depId)?.status !== "done");
51
+ if (unmetDependencies.length > 0) {
52
+ return {
53
+ success: false,
54
+ error: "unmet_dependencies",
55
+ message: `Unmet dependencies: ${unmetDependencies.join(", ")}`,
56
+ unmetDependencies,
57
+ };
58
+ }
59
+ }
60
+ const started = store.startTask(cwd, taskId, agentName);
61
+ if (!started) return { success: false, error: "start_failed", message: `Failed to start ${taskId}` };
62
+ logFeedEvent(cwd, agentName, "task.start", taskId, started.title);
63
+ return { success: true, message: `Started ${taskId}`, task: started };
64
+ }
65
+
66
+ case "block": {
67
+ if (task.status !== "in_progress") {
68
+ return { success: false, error: "invalid_status", message: `Task ${taskId} must be in_progress to block` };
69
+ }
70
+ if (!reason) {
71
+ return { success: false, error: "missing_reason", message: `Reason required to block ${taskId}` };
72
+ }
73
+ const blocked = store.blockTask(cwd, taskId, reason);
74
+ if (!blocked) return { success: false, error: "block_failed", message: `Failed to block ${taskId}` };
75
+ logFeedEvent(cwd, agentName, "task.block", taskId, reason);
76
+ return { success: true, message: `Blocked ${taskId}`, task: blocked };
77
+ }
78
+
79
+ case "unblock": {
80
+ if (task.status !== "blocked") {
81
+ return {
82
+ success: false,
83
+ error: "invalid_status",
84
+ message: `Task ${taskId} is ${task.status}, not blocked`,
85
+ };
86
+ }
87
+ const unblocked = store.unblockTask(cwd, taskId);
88
+ if (!unblocked) return { success: false, error: "unblock_failed", message: `Failed to unblock ${taskId}` };
89
+ logFeedEvent(cwd, agentName, "task.unblock", taskId, unblocked.title);
90
+ return { success: true, message: `Unblocked ${taskId}`, task: unblocked };
91
+ }
92
+
93
+ case "reset": {
94
+ if (options?.isWorkerActive?.(taskId)) {
95
+ return {
96
+ success: false,
97
+ error: "active_worker",
98
+ message: `Cannot reset ${taskId} while its worker is active`,
99
+ };
100
+ }
101
+ const resetTasks = store.resetTask(cwd, taskId, false);
102
+ if (resetTasks.length === 0)
103
+ return { success: false, error: "reset_failed", message: `Failed to reset ${taskId}` };
104
+ logFeedEvent(cwd, agentName, "task.reset", taskId, task.title);
105
+ return { success: true, message: `Reset ${taskId}`, resetTasks };
106
+ }
107
+
108
+ case "cascade-reset": {
109
+ const subtree = [task, ...store.getTransitiveDependents(cwd, taskId)];
110
+ const activeTask = subtree.find(t => options?.isWorkerActive?.(t.id));
111
+ if (activeTask) {
112
+ return {
113
+ success: false,
114
+ error: "active_worker",
115
+ message: `Cannot reset ${activeTask.id} while its worker is active`,
116
+ };
117
+ }
118
+ const resetTasks = store.resetTask(cwd, taskId, true);
119
+ if (resetTasks.length === 0)
120
+ return { success: false, error: "reset_failed", message: `Failed to reset ${taskId}` };
121
+ logFeedEvent(cwd, agentName, "task.reset", taskId, `cascade (${resetTasks.length} tasks)`);
122
+ return {
123
+ success: true,
124
+ message: `Reset ${taskId} + ${Math.max(0, resetTasks.length - 1)} dependents`,
125
+ resetTasks,
126
+ };
127
+ }
128
+
129
+ case "delete": {
130
+ if (task.status === "in_progress" && options?.isWorkerActive?.(taskId)) {
131
+ return {
132
+ success: false,
133
+ error: "active_worker",
134
+ message: `Cannot delete ${taskId} while its worker is active`,
135
+ };
136
+ }
137
+ if (!store.deleteTask(cwd, taskId))
138
+ return { success: false, error: "delete_failed", message: `Failed to delete ${taskId}` };
139
+ logFeedEvent(cwd, agentName, "task.delete", taskId, task.title);
140
+ return { success: true, message: `Deleted ${taskId}` };
141
+ }
142
+
143
+ case "stop": {
144
+ if (task.status !== "in_progress") {
145
+ return {
146
+ success: false,
147
+ error: "invalid_status",
148
+ message: `Task ${taskId} is ${task.status}, not in_progress`,
149
+ };
150
+ }
151
+ if (options?.isWorkerActive?.(taskId)) {
152
+ killWorkerByTask(cwd, taskId);
153
+ store.appendTaskProgress(cwd, taskId, agentName, "Worker stopped by user");
154
+ } else {
155
+ store.appendTaskProgress(cwd, taskId, agentName, "Task unassigned (no active worker)");
156
+ }
157
+ store.updateTask(cwd, taskId, { status: "todo", assigned_to: undefined });
158
+ logFeedEvent(cwd, agentName, "task.reset", taskId, "stopped");
159
+ return { success: true, message: `Stopped ${taskId}` };
160
+ }
161
+ }
162
+ }