@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.
- package/CHANGELOG.md +741 -676
- package/LICENSE +45 -0
- package/README.md +424 -424
- package/THIRD-PARTY-NOTICES.txt +22951 -0
- package/config-overlay.ts +175 -171
- package/config.ts +221 -209
- package/crew/agents/crew-plan-sync.md +66 -64
- package/crew/agents/crew-planner.md +173 -172
- package/crew/agents/crew-reviewer.md +58 -58
- package/crew/agents/crew-worker.md +130 -129
- package/crew/agents.ts +507 -434
- package/crew/handlers/coordination.ts +350 -332
- package/crew/handlers/plan.ts +988 -906
- package/crew/handlers/review.ts +354 -333
- package/crew/handlers/revise.ts +400 -376
- package/crew/handlers/status.ts +303 -295
- package/crew/handlers/sync.ts +237 -233
- package/crew/handlers/task.ts +820 -792
- package/crew/handlers/team.ts +294 -235
- package/crew/handlers/work.ts +467 -425
- package/crew/id-allocator.ts +30 -30
- package/crew/index.ts +297 -257
- package/crew/live-progress.ts +58 -58
- package/crew/lobby.ts +504 -473
- package/crew/prompt.ts +262 -252
- package/crew/registry.ts +114 -114
- package/crew/spawn.ts +135 -111
- package/crew/state-autonomous.ts +163 -164
- package/crew/state-planning.ts +264 -263
- package/crew/state.ts +20 -20
- package/crew/store.ts +646 -642
- package/crew/task-actions.ts +162 -131
- package/crew/team/store.ts +572 -479
- package/crew/team/subagent-roles.ts +105 -87
- package/crew/team/types.ts +50 -50
- package/crew/types.ts +194 -194
- package/crew/utils/artifacts.ts +57 -62
- package/crew/utils/config.ts +158 -156
- package/crew/utils/discover.ts +221 -219
- package/crew/utils/install.ts +94 -85
- package/crew/utils/migrations.ts +126 -0
- package/crew/utils/progress.ts +191 -187
- package/crew/utils/result.ts +16 -16
- package/crew/utils/risk-labels.ts +5 -7
- package/crew/utils/task-format.ts +14 -14
- package/crew/utils/team-roles.ts +44 -28
- package/crew/utils/truncate.ts +76 -79
- package/crew/utils/verdict.ts +55 -55
- package/editor-binary.ts +150 -0
- package/editor-command.ts +107 -0
- package/editor-target.ts +40 -0
- package/feed.ts +321 -268
- package/handlers.ts +1041 -1107
- package/index.ts +1314 -1206
- package/install.mjs +187 -189
- package/lib.ts +587 -467
- package/overlay-actions.ts +519 -511
- package/overlay-coordinator.ts +150 -150
- package/overlay-render.ts +770 -676
- package/overlay.ts +872 -830
- package/package.json +64 -60
- package/paths.ts +60 -0
- package/skills/pi-messenger-crew/SKILL.md +375 -347
- package/store.ts +1147 -1139
- package/teamagent-command.ts +321 -0
- 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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface RegularWorker extends BaseWorkerEntry {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface LobbyWorkerEntry extends BaseWorkerEntry {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function registerWorker(entry: WorkerEntry): void {
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function unregisterWorker(cwd: string, taskId: string): void {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function findWorkerByTask(cwd: string, taskId: string): WorkerEntry | null {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function hasActiveWorker(cwd: string, taskId: string): boolean {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function killWorkerByTask(cwd: string, taskId: string): boolean {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function killAll(cwd?: string): void {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function getLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function getAvailableLobbyWorkers(cwd: string): LobbyWorkerEntry[] {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function getLobbyWorkerCount(cwd: string): number {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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 {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
}
|