@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
package/crew/registry.ts CHANGED
@@ -1,114 +1,114 @@
1
- /**
2
- * Crew - Unified Worker Registry
3
- *
4
- * Single registry for both regular workers and lobby workers.
5
- * Replaces the separate maps in agents.ts and lobby.ts.
6
- */
7
-
8
- import type { ChildProcess } from "node:child_process";
9
- import type { CoordinationLevel } from "./utils/config.ts";
10
-
11
- interface BaseWorkerEntry {
12
- proc: ChildProcess;
13
- name: string;
14
- cwd: string;
15
- taskId: string;
16
- }
17
-
18
- export interface RegularWorker extends BaseWorkerEntry {
19
- type: "worker";
20
- }
21
-
22
- export interface LobbyWorkerEntry extends BaseWorkerEntry {
23
- type: "lobby";
24
- lobbyId: string;
25
- assignedTaskId: string | null;
26
- coordination: CoordinationLevel;
27
- startedAt: number;
28
- promptTmpDir: string | null;
29
- aliveFile: string | null;
30
- }
31
-
32
- export type WorkerEntry = RegularWorker | LobbyWorkerEntry;
33
-
34
- const workers = new Map<string, WorkerEntry>();
35
-
36
- function makeKey(cwd: string, taskId: string): string {
37
- return `${cwd}::${taskId}`;
38
- }
39
-
40
- export function registerWorker(entry: WorkerEntry): void {
41
- workers.set(makeKey(entry.cwd, entry.taskId), entry);
42
- }
43
-
44
- export function unregisterWorker(cwd: string, taskId: string): void {
45
- workers.delete(makeKey(cwd, taskId));
46
- }
47
-
48
- export function findWorkerByTask(cwd: string, taskId: string): WorkerEntry | null {
49
- const direct = workers.get(makeKey(cwd, taskId));
50
- if (direct) return direct;
51
- for (const entry of workers.values()) {
52
- if (entry.cwd !== cwd) continue;
53
- if (entry.type === "lobby" && entry.assignedTaskId === taskId) return entry;
54
- }
55
- return null;
56
- }
57
-
58
- export function hasActiveWorker(cwd: string, taskId: string): boolean {
59
- const entry = findWorkerByTask(cwd, taskId);
60
- if (!entry) return false;
61
- return entry.proc.exitCode === null && !entry.proc.killed;
62
- }
63
-
64
- export function killWorkerByTask(cwd: string, taskId: string): boolean {
65
- const entry = findWorkerByTask(cwd, taskId);
66
- if (!entry) return false;
67
- if (entry.proc.exitCode === null && !entry.proc.killed) {
68
- entry.proc.kill("SIGTERM");
69
- const ref = entry.proc;
70
- const timer = setTimeout(() => {
71
- if (ref.exitCode === null) ref.kill("SIGKILL");
72
- }, 5000);
73
- timer.unref();
74
- return true;
75
- }
76
- return false;
77
- }
78
-
79
- export function killAll(cwd?: string): void {
80
- for (const [key, entry] of workers.entries()) {
81
- if (cwd && entry.cwd !== cwd) continue;
82
- if (entry.proc.exitCode === null && !entry.proc.killed) {
83
- entry.proc.kill("SIGTERM");
84
- }
85
- workers.delete(key);
86
- }
87
- }
88
-
89
- export function getLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
90
- const result: LobbyWorkerEntry[] = [];
91
- for (const entry of workers.values()) {
92
- if (entry.cwd === cwd && entry.type === "lobby") result.push(entry);
93
- }
94
- return result;
95
- }
96
-
97
- export function getAvailableLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
98
- const result: LobbyWorkerEntry[] = [];
99
- for (const entry of workers.values()) {
100
- if (entry.cwd !== cwd || entry.type !== "lobby") continue;
101
- if (entry.assignedTaskId) continue;
102
- if (entry.proc.exitCode !== null) continue;
103
- result.push(entry);
104
- }
105
- return result;
106
- }
107
-
108
- export function getLobbyWorkerCount(cwd: string): number {
109
- let count = 0;
110
- for (const entry of workers.values()) {
111
- if (entry.cwd === cwd && entry.type === "lobby" && !entry.assignedTaskId && entry.proc.exitCode === null) count++;
112
- }
113
- return count;
114
- }
1
+ /**
2
+ * Crew - Unified Worker Registry
3
+ *
4
+ * Single registry for both regular workers and lobby workers.
5
+ * Replaces the separate maps in agents.ts and lobby.ts.
6
+ */
7
+
8
+ import type { ChildProcess } from "node:child_process";
9
+ import type { CoordinationLevel } from "./utils/config.ts";
10
+
11
+ interface BaseWorkerEntry {
12
+ proc: ChildProcess;
13
+ name: string;
14
+ cwd: string;
15
+ taskId: string;
16
+ }
17
+
18
+ export interface RegularWorker extends BaseWorkerEntry {
19
+ type: "worker";
20
+ }
21
+
22
+ export interface LobbyWorkerEntry extends BaseWorkerEntry {
23
+ type: "lobby";
24
+ lobbyId: string;
25
+ assignedTaskId: string | null;
26
+ coordination: CoordinationLevel;
27
+ startedAt: number;
28
+ promptTmpDir: string | null;
29
+ aliveFile: string | null;
30
+ }
31
+
32
+ export type WorkerEntry = RegularWorker | LobbyWorkerEntry;
33
+
34
+ const workers = new Map<string, WorkerEntry>();
35
+
36
+ function makeKey(cwd: string, taskId: string): string {
37
+ return `${cwd}::${taskId}`;
38
+ }
39
+
40
+ export function registerWorker(entry: WorkerEntry): void {
41
+ workers.set(makeKey(entry.cwd, entry.taskId), entry);
42
+ }
43
+
44
+ export function unregisterWorker(cwd: string, taskId: string): void {
45
+ workers.delete(makeKey(cwd, taskId));
46
+ }
47
+
48
+ export function findWorkerByTask(cwd: string, taskId: string): WorkerEntry | null {
49
+ const direct = workers.get(makeKey(cwd, taskId));
50
+ if (direct) return direct;
51
+ for (const entry of workers.values()) {
52
+ if (entry.cwd !== cwd) continue;
53
+ if (entry.type === "lobby" && entry.assignedTaskId === taskId) return entry;
54
+ }
55
+ return null;
56
+ }
57
+
58
+ export function hasActiveWorker(cwd: string, taskId: string): boolean {
59
+ const entry = findWorkerByTask(cwd, taskId);
60
+ if (!entry) return false;
61
+ return entry.proc.exitCode === null && !entry.proc.killed;
62
+ }
63
+
64
+ export function killWorkerByTask(cwd: string, taskId: string): boolean {
65
+ const entry = findWorkerByTask(cwd, taskId);
66
+ if (!entry) return false;
67
+ if (entry.proc.exitCode === null && !entry.proc.killed) {
68
+ entry.proc.kill("SIGTERM");
69
+ const ref = entry.proc;
70
+ const timer = setTimeout(() => {
71
+ if (ref.exitCode === null) ref.kill("SIGKILL");
72
+ }, 5000);
73
+ timer.unref();
74
+ return true;
75
+ }
76
+ return false;
77
+ }
78
+
79
+ export function killAll(cwd?: string): void {
80
+ for (const [key, entry] of workers.entries()) {
81
+ if (cwd && entry.cwd !== cwd) continue;
82
+ if (entry.proc.exitCode === null && !entry.proc.killed) {
83
+ entry.proc.kill("SIGTERM");
84
+ }
85
+ workers.delete(key);
86
+ }
87
+ }
88
+
89
+ export function getLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
90
+ const result: LobbyWorkerEntry[] = [];
91
+ for (const entry of workers.values()) {
92
+ if (entry.cwd === cwd && entry.type === "lobby") result.push(entry);
93
+ }
94
+ return result;
95
+ }
96
+
97
+ export function getAvailableLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
98
+ const result: LobbyWorkerEntry[] = [];
99
+ for (const entry of workers.values()) {
100
+ if (entry.cwd !== cwd || entry.type !== "lobby") continue;
101
+ if (entry.assignedTaskId) continue;
102
+ if (entry.proc.exitCode !== null) continue;
103
+ result.push(entry);
104
+ }
105
+ return result;
106
+ }
107
+
108
+ export function getLobbyWorkerCount(cwd: string): number {
109
+ let count = 0;
110
+ for (const entry of workers.values()) {
111
+ if (entry.cwd === cwd && entry.type === "lobby" && !entry.assignedTaskId && entry.proc.exitCode === null) count++;
112
+ }
113
+ return count;
114
+ }
package/crew/spawn.ts CHANGED
@@ -1,111 +1,135 @@
1
- /**
2
- * Crew - Worker Spawning Helpers
3
- *
4
- * Shared logic for spawning workers and assigning tasks,
5
- * used by both the overlay and the work handler.
6
- */
7
-
8
- import { join } from "node:path";
9
- import * as store from "./store.ts";
10
- import { loadCrewConfig } from "./utils/config.ts";
11
- import { discoverCrewSkills } from "./utils/discover.ts";
12
- import { buildWorkerPrompt } from "./prompt.ts";
13
- import * as teamStore from "./team/store.ts";
14
- import { logFeedEvent } from "../feed.ts";
15
- import {
16
- spawnWorkerForTask,
17
- getAvailableLobbyWorkers,
18
- assignTaskToLobbyWorker,
19
- } from "./lobby.ts";
20
-
21
- export interface SpawnResult {
22
- assigned: number;
23
- firstWorkerName: string | null;
24
- }
25
-
26
- export function spawnWorkersForReadyTasks(
27
- cwd: string,
28
- maxWorkers: number,
29
- sessionModel?: string,
30
- ): SpawnResult {
31
- const plan = store.getPlan(cwd);
32
- if (!plan) return { assigned: 0, firstWorkerName: null };
33
-
34
- const crewDir = store.getCrewDir(cwd);
35
- const config = loadCrewConfig(crewDir);
36
- const workerCap = Math.min(maxWorkers, config.concurrency.max);
37
- const prdLabel = store.getPlanLabel(plan);
38
- const inboxDir = join(cwd, ".pi", "messenger", "inbox");
39
- const skills = discoverCrewSkills(cwd);
40
-
41
- let assigned = 0;
42
- let firstWorkerName: string | null = null;
43
-
44
- const lobby = getAvailableLobbyWorkers(cwd);
45
- for (const lw of lobby) {
46
- if (assigned >= workerCap) break;
47
- const fresh = store.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" }).filter(t => !teamStore.taskNeedsApproval(t));
48
- if (fresh.length === 0) break;
49
-
50
- const task = fresh[0];
51
- const others = fresh.filter(t => t.id !== task.id);
52
- const prompt = buildWorkerPrompt(task, prdLabel, cwd, config, others, skills, teamStore.buildTeamPromptContext(cwd, task));
53
-
54
- store.updateTask(cwd, task.id, {
55
- status: "in_progress",
56
- started_at: new Date().toISOString(),
57
- base_commit: store.getBaseCommit(cwd),
58
- assigned_to: lw.name,
59
- attempt_count: task.attempt_count + 1,
60
- });
61
-
62
- if (!assignTaskToLobbyWorker(lw, task.id, prompt, inboxDir)) {
63
- store.updateTask(cwd, task.id, { status: "todo", assigned_to: undefined });
64
- continue;
65
- }
66
-
67
- store.appendTaskProgress(cwd, task.id, "system", `Assigned to lobby worker ${lw.name} (attempt ${task.attempt_count + 1})`);
68
- logFeedEvent(cwd, lw.name, "task.start", task.id, task.title);
69
- if (!firstWorkerName) firstWorkerName = lw.name;
70
- assigned++;
71
- }
72
-
73
- while (assigned < workerCap) {
74
- const fresh = store.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" }).filter(t => !teamStore.taskNeedsApproval(t));
75
- if (fresh.length === 0) break;
76
-
77
- const task = fresh[0];
78
- const others = fresh.filter(t => t.id !== task.id);
79
- const prompt = buildWorkerPrompt(task, prdLabel, cwd, config, others, skills, teamStore.buildTeamPromptContext(cwd, task));
80
- const worker = spawnWorkerForTask(cwd, task.id, prompt, sessionModel);
81
- if (!worker) break;
82
-
83
- if (!firstWorkerName) firstWorkerName = worker.name;
84
- assigned++;
85
- }
86
-
87
- return { assigned, firstWorkerName };
88
- }
89
-
90
- export function spawnSingleWorker(
91
- cwd: string,
92
- taskId: string,
93
- sessionModel?: string,
94
- ): { name: string } | null {
95
- const plan = store.getPlan(cwd);
96
- if (!plan) return null;
97
-
98
- const task = store.getTask(cwd, taskId);
99
- if (!task) return null;
100
-
101
- const crewDir = store.getCrewDir(cwd);
102
- const config = loadCrewConfig(crewDir);
103
- const prdLabel = store.getPlanLabel(plan);
104
- const skills = discoverCrewSkills(cwd);
105
- if (teamStore.taskNeedsApproval(task)) return null;
106
- const readyTasks = store.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" }).filter(t => !teamStore.taskNeedsApproval(t));
107
- const others = readyTasks.filter(t => t.id !== task.id);
108
- const prompt = buildWorkerPrompt(task, prdLabel, cwd, config, others, skills, teamStore.buildTeamPromptContext(cwd, task));
109
- const worker = spawnWorkerForTask(cwd, taskId, prompt, sessionModel);
110
- return worker ? { name: worker.name } : null;
111
- }
1
+ /**
2
+ * Crew - Worker Spawning Helpers
3
+ *
4
+ * Shared logic for spawning workers and assigning tasks,
5
+ * used by both the overlay and the work handler.
6
+ */
7
+
8
+ import { join } from "node:path";
9
+ import * as store from "./store.ts";
10
+ import { getProjectMessengerDir } from "../paths.ts";
11
+ import { loadCrewConfig } from "./utils/config.ts";
12
+ import { discoverCrewSkills } from "./utils/discover.ts";
13
+ import { buildWorkerPrompt } from "./prompt.ts";
14
+ import * as teamStore from "./team/store.ts";
15
+ import { logFeedEvent } from "../feed.ts";
16
+ import { spawnWorkerForTask, getAvailableLobbyWorkers, assignTaskToLobbyWorker } from "./lobby.ts";
17
+
18
+ export interface SpawnResult {
19
+ assigned: number;
20
+ firstWorkerName: string | null;
21
+ }
22
+
23
+ export function spawnWorkersForReadyTasks(cwd: string, maxWorkers: number, sessionModel?: string): SpawnResult {
24
+ const plan = store.getPlan(cwd);
25
+ if (!plan) return { assigned: 0, firstWorkerName: null };
26
+
27
+ const crewDir = store.getCrewDir(cwd);
28
+ const config = loadCrewConfig(crewDir);
29
+ const workerCap = Math.min(maxWorkers, config.concurrency.max);
30
+ const prdLabel = store.getPlanLabel(plan);
31
+ const inboxDir = join(getProjectMessengerDir(cwd), "inbox");
32
+ const skills = discoverCrewSkills(cwd);
33
+
34
+ let assigned = 0;
35
+ let firstWorkerName: string | null = null;
36
+
37
+ const lobby = getAvailableLobbyWorkers(cwd);
38
+ for (const lw of lobby) {
39
+ if (assigned >= workerCap) break;
40
+ const fresh = store
41
+ .getReadyTasks(cwd, { advisory: config.dependencies === "advisory" })
42
+ .filter(t => !teamStore.taskNeedsApproval(t));
43
+ if (fresh.length === 0) break;
44
+
45
+ const task = fresh[0];
46
+ const others = fresh.filter(t => t.id !== task.id);
47
+ const prompt = buildWorkerPrompt(
48
+ task,
49
+ prdLabel,
50
+ cwd,
51
+ config,
52
+ others,
53
+ skills,
54
+ teamStore.buildTeamPromptContext(cwd, task),
55
+ );
56
+
57
+ store.updateTask(cwd, task.id, {
58
+ status: "in_progress",
59
+ started_at: new Date().toISOString(),
60
+ base_commit: store.getBaseCommit(cwd),
61
+ assigned_to: lw.name,
62
+ attempt_count: task.attempt_count + 1,
63
+ });
64
+
65
+ if (!assignTaskToLobbyWorker(lw, task.id, prompt, inboxDir)) {
66
+ store.updateTask(cwd, task.id, { status: "todo", assigned_to: undefined });
67
+ continue;
68
+ }
69
+
70
+ store.appendTaskProgress(
71
+ cwd,
72
+ task.id,
73
+ "system",
74
+ `Assigned to lobby worker ${lw.name} (attempt ${task.attempt_count + 1})`,
75
+ );
76
+ logFeedEvent(cwd, lw.name, "task.start", task.id, task.title);
77
+ if (!firstWorkerName) firstWorkerName = lw.name;
78
+ assigned++;
79
+ }
80
+
81
+ while (assigned < workerCap) {
82
+ const fresh = store
83
+ .getReadyTasks(cwd, { advisory: config.dependencies === "advisory" })
84
+ .filter(t => !teamStore.taskNeedsApproval(t));
85
+ if (fresh.length === 0) break;
86
+
87
+ const task = fresh[0];
88
+ const others = fresh.filter(t => t.id !== task.id);
89
+ const prompt = buildWorkerPrompt(
90
+ task,
91
+ prdLabel,
92
+ cwd,
93
+ config,
94
+ others,
95
+ skills,
96
+ teamStore.buildTeamPromptContext(cwd, task),
97
+ );
98
+ const worker = spawnWorkerForTask(cwd, task.id, prompt, sessionModel);
99
+ if (!worker) break;
100
+
101
+ if (!firstWorkerName) firstWorkerName = worker.name;
102
+ assigned++;
103
+ }
104
+
105
+ return { assigned, firstWorkerName };
106
+ }
107
+
108
+ export function spawnSingleWorker(cwd: string, taskId: string, sessionModel?: string): { name: string } | null {
109
+ const plan = store.getPlan(cwd);
110
+ if (!plan) return null;
111
+
112
+ const task = store.getTask(cwd, taskId);
113
+ if (!task) return null;
114
+
115
+ const crewDir = store.getCrewDir(cwd);
116
+ const config = loadCrewConfig(crewDir);
117
+ const prdLabel = store.getPlanLabel(plan);
118
+ const skills = discoverCrewSkills(cwd);
119
+ if (teamStore.taskNeedsApproval(task)) return null;
120
+ const readyTasks = store
121
+ .getReadyTasks(cwd, { advisory: config.dependencies === "advisory" })
122
+ .filter(t => !teamStore.taskNeedsApproval(t));
123
+ const others = readyTasks.filter(t => t.id !== task.id);
124
+ const prompt = buildWorkerPrompt(
125
+ task,
126
+ prdLabel,
127
+ cwd,
128
+ config,
129
+ others,
130
+ skills,
131
+ teamStore.buildTeamPromptContext(cwd, task),
132
+ );
133
+ const worker = spawnWorkerForTask(cwd, taskId, prompt, sessionModel);
134
+ return worker ? { name: worker.name } : null;
135
+ }