@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.
- package/CHANGELOG.md +676 -0
- package/README.md +424 -0
- package/config-overlay.ts +171 -0
- package/config.ts +209 -0
- package/crew/agents/crew-plan-sync.md +64 -0
- package/crew/agents/crew-planner.md +172 -0
- package/crew/agents/crew-reviewer.md +58 -0
- package/crew/agents/crew-worker.md +129 -0
- package/crew/agents.ts +434 -0
- package/crew/handlers/coordination.ts +332 -0
- package/crew/handlers/plan.ts +906 -0
- package/crew/handlers/review.ts +333 -0
- package/crew/handlers/revise.ts +376 -0
- package/crew/handlers/status.ts +295 -0
- package/crew/handlers/sync.ts +233 -0
- package/crew/handlers/task.ts +792 -0
- package/crew/handlers/team.ts +235 -0
- package/crew/handlers/work.ts +425 -0
- package/crew/id-allocator.ts +30 -0
- package/crew/index.ts +257 -0
- package/crew/live-progress.ts +58 -0
- package/crew/lobby.ts +473 -0
- package/crew/prompt.ts +252 -0
- package/crew/registry.ts +114 -0
- package/crew/spawn.ts +111 -0
- package/crew/state-autonomous.ts +164 -0
- package/crew/state-planning.ts +263 -0
- package/crew/state.ts +20 -0
- package/crew/store.ts +642 -0
- package/crew/task-actions.ts +131 -0
- package/crew/team/store.ts +479 -0
- package/crew/team/subagent-roles.ts +87 -0
- package/crew/team/types.ts +50 -0
- package/crew/types.ts +194 -0
- package/crew/utils/artifacts.ts +62 -0
- package/crew/utils/config.ts +156 -0
- package/crew/utils/discover.ts +219 -0
- package/crew/utils/install.ts +85 -0
- package/crew/utils/progress.ts +187 -0
- package/crew/utils/result.ts +16 -0
- package/crew/utils/risk-labels.ts +7 -0
- package/crew/utils/task-format.ts +14 -0
- package/crew/utils/team-roles.ts +28 -0
- package/crew/utils/truncate.ts +79 -0
- package/crew/utils/verdict.ts +55 -0
- package/feed.ts +268 -0
- package/handlers.ts +1107 -0
- package/index.ts +1206 -0
- package/install.mjs +189 -0
- package/lib.ts +467 -0
- package/overlay-actions.ts +511 -0
- package/overlay-coordinator.ts +150 -0
- package/overlay-render.ts +676 -0
- package/overlay.ts +830 -0
- package/package.json +62 -0
- package/skills/pi-messenger-crew/SKILL.md +347 -0
- package/store.ts +1139 -0
- package/vitest.config.ts +10 -0
package/crew/lobby.ts
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Lobby Workers
|
|
3
|
+
*
|
|
4
|
+
* Spawns idle workers that join the mesh, explore the project, and chat
|
|
5
|
+
* while waiting for task assignments. When tasks become available, they
|
|
6
|
+
* receive assignments via steer message and transition to work mode.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as os from "node:os";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { generateMemorableName } from "../lib.ts";
|
|
16
|
+
import { resolveThinking, modelHasThinkingSuffix, pushModelArgs, getPiCommand, resolveModel } from "./agents.ts";
|
|
17
|
+
import { discoverCrewAgents } from "./utils/discover.ts";
|
|
18
|
+
import { loadCrewConfig, type CrewConfig } from "./utils/config.ts";
|
|
19
|
+
import {
|
|
20
|
+
createProgress,
|
|
21
|
+
parseJsonlLine,
|
|
22
|
+
updateProgress,
|
|
23
|
+
} from "./utils/progress.ts";
|
|
24
|
+
import { updateLiveWorker, removeLiveWorker } from "./live-progress.ts";
|
|
25
|
+
import * as store from "./store.ts";
|
|
26
|
+
import { logFeedEvent } from "../feed.ts";
|
|
27
|
+
import {
|
|
28
|
+
registerWorker,
|
|
29
|
+
unregisterWorker,
|
|
30
|
+
getLobbyWorkers as registryGetLobbyWorkers,
|
|
31
|
+
getAvailableLobbyWorkers as registryGetAvailableLobbyWorkers,
|
|
32
|
+
getLobbyWorkerCount as registryGetLobbyWorkerCount,
|
|
33
|
+
hasActiveWorker,
|
|
34
|
+
type LobbyWorkerEntry,
|
|
35
|
+
} from "./registry.ts";
|
|
36
|
+
|
|
37
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
38
|
+
const __dirname = path.dirname(__filename);
|
|
39
|
+
const EXTENSION_DIR = path.resolve(__dirname, "..");
|
|
40
|
+
const BUILTIN_TOOLS = new Set(["read", "bash", "edit", "write", "grep", "find", "ls"]);
|
|
41
|
+
|
|
42
|
+
export const LOBBY_TOKEN_BUDGETS: Record<string, number> = {
|
|
43
|
+
none: 10_000,
|
|
44
|
+
minimal: 20_000,
|
|
45
|
+
moderate: 50_000,
|
|
46
|
+
chatty: 100_000,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type LobbyWorker = LobbyWorkerEntry;
|
|
50
|
+
|
|
51
|
+
function lobbyTaskId(id: string): string {
|
|
52
|
+
return `__lobby-${id}__`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function spawnLobbyWorker(cwd: string, promptOverride?: string, sessionModel?: string): LobbyWorker | null {
|
|
56
|
+
const agents = discoverCrewAgents(cwd);
|
|
57
|
+
const workerConfig = agents.find(a => a.name === "crew-worker");
|
|
58
|
+
if (!workerConfig) return null;
|
|
59
|
+
|
|
60
|
+
const crewDir = store.getCrewDir(cwd);
|
|
61
|
+
const config = loadCrewConfig(crewDir);
|
|
62
|
+
const id = randomUUID().slice(0, 6);
|
|
63
|
+
let name = generateMemorableName();
|
|
64
|
+
for (let i = 0; i < 5; i++) {
|
|
65
|
+
const existing = registryGetLobbyWorkers(cwd);
|
|
66
|
+
const collision = existing.some(w => w.name === name && w.proc.exitCode === null);
|
|
67
|
+
if (!collision) break;
|
|
68
|
+
name = generateMemorableName();
|
|
69
|
+
}
|
|
70
|
+
const prompt = promptOverride ?? buildLobbyPrompt(cwd, config);
|
|
71
|
+
|
|
72
|
+
const args = ["--mode", "json", "--no-session", "-p"];
|
|
73
|
+
const model = resolveModel(undefined, undefined, undefined, config.models?.worker, sessionModel, workerConfig.model);
|
|
74
|
+
if (model) pushModelArgs(args, model);
|
|
75
|
+
|
|
76
|
+
const thinking = resolveThinking(
|
|
77
|
+
config.thinking?.worker,
|
|
78
|
+
workerConfig.thinking,
|
|
79
|
+
);
|
|
80
|
+
if (thinking && !modelHasThinkingSuffix(model)) {
|
|
81
|
+
args.push("--thinking", thinking);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (workerConfig.tools?.length) {
|
|
85
|
+
const builtinTools: string[] = [];
|
|
86
|
+
const extensionPaths: string[] = [];
|
|
87
|
+
for (const tool of workerConfig.tools) {
|
|
88
|
+
if (tool.includes("/") || tool.endsWith(".ts") || tool.endsWith(".js")) {
|
|
89
|
+
extensionPaths.push(tool);
|
|
90
|
+
} else if (BUILTIN_TOOLS.has(tool)) {
|
|
91
|
+
builtinTools.push(tool);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (builtinTools.length > 0) args.push("--tools", builtinTools.join(","));
|
|
95
|
+
for (const ext of extensionPaths) args.push("--extension", ext);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
args.push("--extension", EXTENSION_DIR);
|
|
99
|
+
|
|
100
|
+
let promptTmpDir: string | null = null;
|
|
101
|
+
if (workerConfig.systemPrompt) {
|
|
102
|
+
promptTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-messenger-lobby-"));
|
|
103
|
+
const promptPath = path.join(promptTmpDir, "crew-worker.md");
|
|
104
|
+
fs.writeFileSync(promptPath, workerConfig.systemPrompt, { mode: 0o600 });
|
|
105
|
+
args.push("--append-system-prompt", promptPath);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
args.push(prompt);
|
|
109
|
+
|
|
110
|
+
const envOverrides = config.work.env ?? {};
|
|
111
|
+
const env = { ...process.env, ...envOverrides, PI_AGENT_NAME: name, PI_CREW_WORKER: "1", PI_LOBBY_ID: id };
|
|
112
|
+
|
|
113
|
+
const proc = spawn(getPiCommand(), args, {
|
|
114
|
+
cwd,
|
|
115
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
116
|
+
env,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const aliveFile = path.join(crewDir, `lobby-${id}.alive`);
|
|
120
|
+
try { fs.writeFileSync(aliveFile, "", { mode: 0o600 }); } catch {}
|
|
121
|
+
|
|
122
|
+
const taskId = lobbyTaskId(id);
|
|
123
|
+
const worker: LobbyWorkerEntry = {
|
|
124
|
+
type: "lobby",
|
|
125
|
+
lobbyId: id,
|
|
126
|
+
name,
|
|
127
|
+
cwd,
|
|
128
|
+
proc,
|
|
129
|
+
taskId,
|
|
130
|
+
startedAt: Date.now(),
|
|
131
|
+
assignedTaskId: null,
|
|
132
|
+
coordination: config.coordination ?? "chatty",
|
|
133
|
+
promptTmpDir,
|
|
134
|
+
aliveFile,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
registerWorker(worker);
|
|
138
|
+
|
|
139
|
+
const progress = createProgress("crew-worker");
|
|
140
|
+
|
|
141
|
+
let jsonlBuffer = "";
|
|
142
|
+
proc.stdout?.on("data", (data) => {
|
|
143
|
+
try {
|
|
144
|
+
jsonlBuffer += data.toString();
|
|
145
|
+
const lines = jsonlBuffer.split("\n");
|
|
146
|
+
jsonlBuffer = lines.pop() ?? "";
|
|
147
|
+
for (const line of lines) {
|
|
148
|
+
const event = parseJsonlLine(line);
|
|
149
|
+
if (event) {
|
|
150
|
+
updateProgress(progress, event, worker.startedAt);
|
|
151
|
+
const displayId = worker.assignedTaskId ?? taskId;
|
|
152
|
+
updateLiveWorker(cwd, displayId, {
|
|
153
|
+
taskId: displayId,
|
|
154
|
+
agent: "crew-worker",
|
|
155
|
+
name,
|
|
156
|
+
progress: { ...progress, recentTools: progress.recentTools.map(t => ({ ...t })) },
|
|
157
|
+
startedAt: worker.startedAt,
|
|
158
|
+
});
|
|
159
|
+
if (!worker.assignedTaskId) {
|
|
160
|
+
const currentConfig = loadCrewConfig(crewDir);
|
|
161
|
+
const budget = LOBBY_TOKEN_BUDGETS[currentConfig.coordination ?? "chatty"] ?? LOBBY_TOKEN_BUDGETS.chatty;
|
|
162
|
+
if (progress.tokens > budget) {
|
|
163
|
+
proc.kill("SIGTERM");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch {}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
proc.on("close", (exitCode) => {
|
|
172
|
+
const displayId = worker.assignedTaskId ?? taskId;
|
|
173
|
+
removeLiveWorker(cwd, displayId);
|
|
174
|
+
unregisterWorker(cwd, taskId);
|
|
175
|
+
if (worker.promptTmpDir) {
|
|
176
|
+
try { fs.rmSync(worker.promptTmpDir, { recursive: true, force: true }); } catch {}
|
|
177
|
+
}
|
|
178
|
+
if (worker.aliveFile) {
|
|
179
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
180
|
+
}
|
|
181
|
+
if (worker.assignedTaskId) {
|
|
182
|
+
const task = store.getTask(cwd, worker.assignedTaskId);
|
|
183
|
+
if (task && task.status === "in_progress" && task.assigned_to === worker.name) {
|
|
184
|
+
const config = loadCrewConfig(store.getCrewDir(cwd));
|
|
185
|
+
if (task.attempt_count >= config.work.maxAttemptsPerTask) {
|
|
186
|
+
store.updateTask(cwd, worker.assignedTaskId, {
|
|
187
|
+
status: "blocked",
|
|
188
|
+
blocked_reason: `Max attempts (${config.work.maxAttemptsPerTask}) reached`,
|
|
189
|
+
assigned_to: undefined,
|
|
190
|
+
});
|
|
191
|
+
logFeedEvent(cwd, worker.name, "task.block", worker.assignedTaskId, `Max attempts reached`);
|
|
192
|
+
} else {
|
|
193
|
+
store.updateTask(cwd, worker.assignedTaskId, { status: "todo", assigned_to: undefined });
|
|
194
|
+
store.appendTaskProgress(cwd, worker.assignedTaskId, "system",
|
|
195
|
+
`Lobby worker ${worker.name} exited (code ${exitCode ?? "unknown"}), reset to todo`);
|
|
196
|
+
logFeedEvent(cwd, worker.name, "task.reset", worker.assignedTaskId, "worker exited");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
logFeedEvent(cwd, worker.name, "leave", undefined, `Lobby worker exited (code ${exitCode ?? "unknown"})`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
updateLiveWorker(cwd, taskId, {
|
|
205
|
+
taskId,
|
|
206
|
+
agent: "crew-worker",
|
|
207
|
+
name,
|
|
208
|
+
progress: { ...progress, recentTools: [] },
|
|
209
|
+
startedAt: worker.startedAt,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return worker;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function getLobbyWorkerCount(cwd: string): number {
|
|
216
|
+
return registryGetLobbyWorkerCount(cwd);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function getAvailableLobbyWorkers(cwd: string): LobbyWorker[] {
|
|
220
|
+
return registryGetAvailableLobbyWorkers(cwd);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function assignTaskToLobbyWorker(
|
|
224
|
+
worker: LobbyWorker,
|
|
225
|
+
taskId: string,
|
|
226
|
+
taskPrompt: string,
|
|
227
|
+
inboxDir: string,
|
|
228
|
+
): boolean {
|
|
229
|
+
if (worker.assignedTaskId) return false;
|
|
230
|
+
if (worker.proc.exitCode !== null) return false;
|
|
231
|
+
|
|
232
|
+
const targetInbox = path.join(inboxDir, worker.name);
|
|
233
|
+
try { fs.mkdirSync(targetInbox, { recursive: true }); } catch {}
|
|
234
|
+
|
|
235
|
+
const msg = {
|
|
236
|
+
id: randomUUID(),
|
|
237
|
+
from: "crew-orchestrator",
|
|
238
|
+
to: worker.name,
|
|
239
|
+
text: `# ⚡ TASK ASSIGNMENT — SWITCH TO WORK MODE
|
|
240
|
+
|
|
241
|
+
Drop your current activity and work on this task immediately.
|
|
242
|
+
|
|
243
|
+
**IMPORTANT:** This task is already claimed and started for you — do NOT call \`task.start\`. Follow the assignment below, including any Team role or read-only instructions, then mark complete with \`task.done\`.
|
|
244
|
+
|
|
245
|
+
${taskPrompt}`,
|
|
246
|
+
timestamp: new Date().toISOString(),
|
|
247
|
+
replyTo: null,
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
251
|
+
const msgFile = path.join(targetInbox, `${Date.now()}-${random}.json`);
|
|
252
|
+
const aliveFile = worker.aliveFile;
|
|
253
|
+
if (aliveFile) {
|
|
254
|
+
try { fs.unlinkSync(aliveFile); } catch {}
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
fs.writeFileSync(msgFile, JSON.stringify(msg, null, 2));
|
|
258
|
+
} catch {
|
|
259
|
+
if (aliveFile) {
|
|
260
|
+
try { fs.writeFileSync(aliveFile, "", { mode: 0o600 }); } catch {}
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
removeLiveWorker(worker.cwd, lobbyTaskId(worker.lobbyId));
|
|
266
|
+
worker.assignedTaskId = taskId;
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function killLobbyWorkerForTask(cwd: string, taskId: string): boolean {
|
|
271
|
+
const all = registryGetLobbyWorkers(cwd);
|
|
272
|
+
for (const worker of all) {
|
|
273
|
+
if (worker.assignedTaskId !== taskId) continue;
|
|
274
|
+
if (worker.proc.exitCode === null) {
|
|
275
|
+
worker.proc.kill("SIGTERM");
|
|
276
|
+
}
|
|
277
|
+
if (worker.aliveFile) {
|
|
278
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function shutdownLobbyWorkers(cwd: string): void {
|
|
286
|
+
const all = registryGetLobbyWorkers(cwd);
|
|
287
|
+
for (const worker of all) {
|
|
288
|
+
if (worker.proc.exitCode === null) {
|
|
289
|
+
worker.proc.kill("SIGTERM");
|
|
290
|
+
}
|
|
291
|
+
const displayId = worker.assignedTaskId ?? worker.taskId;
|
|
292
|
+
removeLiveWorker(cwd, displayId);
|
|
293
|
+
unregisterWorker(cwd, worker.taskId);
|
|
294
|
+
if (worker.promptTmpDir) {
|
|
295
|
+
try { fs.rmSync(worker.promptTmpDir, { recursive: true, force: true }); } catch {}
|
|
296
|
+
}
|
|
297
|
+
if (worker.aliveFile) {
|
|
298
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const crewDir = store.getCrewDir(cwd);
|
|
303
|
+
try {
|
|
304
|
+
for (const f of fs.readdirSync(crewDir)) {
|
|
305
|
+
if (f.startsWith("lobby-") && f.endsWith(".alive")) {
|
|
306
|
+
try { fs.unlinkSync(path.join(crewDir, f)); } catch {}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
} catch {}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function cleanupUnassignedAliveFiles(cwd: string): void {
|
|
313
|
+
const workers = registryGetLobbyWorkers(cwd);
|
|
314
|
+
for (const worker of workers) {
|
|
315
|
+
if (!worker.assignedTaskId && worker.aliveFile) {
|
|
316
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function spawnWorkerForTask(
|
|
322
|
+
cwd: string,
|
|
323
|
+
taskId: string,
|
|
324
|
+
taskPrompt: string,
|
|
325
|
+
sessionModel?: string,
|
|
326
|
+
): LobbyWorker | null {
|
|
327
|
+
const task = store.getTask(cwd, taskId);
|
|
328
|
+
if (!task || task.status !== "todo") return null;
|
|
329
|
+
if (hasActiveWorker(cwd, taskId)) return null;
|
|
330
|
+
|
|
331
|
+
const worker = spawnLobbyWorker(cwd, taskPrompt, sessionModel);
|
|
332
|
+
if (!worker) return null;
|
|
333
|
+
|
|
334
|
+
removeLiveWorker(cwd, lobbyTaskId(worker.lobbyId));
|
|
335
|
+
worker.assignedTaskId = taskId;
|
|
336
|
+
if (worker.aliveFile) {
|
|
337
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
338
|
+
}
|
|
339
|
+
store.updateTask(cwd, taskId, {
|
|
340
|
+
status: "in_progress",
|
|
341
|
+
started_at: new Date().toISOString(),
|
|
342
|
+
base_commit: store.getBaseCommit(cwd),
|
|
343
|
+
assigned_to: worker.name,
|
|
344
|
+
attempt_count: task.attempt_count + 1,
|
|
345
|
+
});
|
|
346
|
+
store.appendTaskProgress(cwd, taskId, "system", `Assigned to worker ${worker.name} (attempt ${task.attempt_count + 1})`);
|
|
347
|
+
logFeedEvent(cwd, worker.name, "task.start", taskId, task.title);
|
|
348
|
+
|
|
349
|
+
return worker;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function removeLobbyWorkerByIndex(cwd: string): boolean {
|
|
353
|
+
const available = registryGetAvailableLobbyWorkers(cwd);
|
|
354
|
+
if (available.length === 0) return false;
|
|
355
|
+
const worker = available[0];
|
|
356
|
+
if (worker.proc.exitCode === null) {
|
|
357
|
+
worker.proc.kill("SIGTERM");
|
|
358
|
+
}
|
|
359
|
+
removeLiveWorker(cwd, worker.taskId);
|
|
360
|
+
unregisterWorker(cwd, worker.taskId);
|
|
361
|
+
if (worker.promptTmpDir) {
|
|
362
|
+
try { fs.rmSync(worker.promptTmpDir, { recursive: true, force: true }); } catch {}
|
|
363
|
+
}
|
|
364
|
+
if (worker.aliveFile) {
|
|
365
|
+
try { fs.unlinkSync(worker.aliveFile); } catch {}
|
|
366
|
+
}
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function buildLobbyPrompt(cwd: string, config: CrewConfig): string {
|
|
371
|
+
const plan = store.getPlan(cwd);
|
|
372
|
+
const prdPath = plan?.prd;
|
|
373
|
+
const level = config.coordination ?? "chatty";
|
|
374
|
+
|
|
375
|
+
let prompt = `# Crew Lobby
|
|
376
|
+
|
|
377
|
+
You're a crew worker waiting for the team's plan to be finalized. There's no task for you yet — hang tight.
|
|
378
|
+
|
|
379
|
+
## Step 1: Join the Mesh
|
|
380
|
+
|
|
381
|
+
\`\`\`typescript
|
|
382
|
+
pi_messenger({ action: "join" })
|
|
383
|
+
\`\`\`
|
|
384
|
+
|
|
385
|
+
## Step 2: Get Familiar
|
|
386
|
+
|
|
387
|
+
`;
|
|
388
|
+
|
|
389
|
+
if (level === "none") {
|
|
390
|
+
prompt += `Skip this step — you'll get full context when your task arrives.
|
|
391
|
+
|
|
392
|
+
`;
|
|
393
|
+
} else if (prdPath) {
|
|
394
|
+
prompt += `Read the PRD to understand what the team is building:
|
|
395
|
+
|
|
396
|
+
\`\`\`typescript
|
|
397
|
+
read("${prdPath}")
|
|
398
|
+
\`\`\`
|
|
399
|
+
|
|
400
|
+
`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (level === "chatty" || level === "moderate") {
|
|
404
|
+
prompt += `Briefly explore the project structure to get oriented. Don't go deep — save your budget for the actual task.
|
|
405
|
+
|
|
406
|
+
`;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (level === "chatty") {
|
|
410
|
+
prompt += `## Step 3: Share Your Findings
|
|
411
|
+
|
|
412
|
+
Post updates to the team feed while you wait — the user watches it live. Other workers will see your broadcasts when they receive their task assignment.
|
|
413
|
+
|
|
414
|
+
- **Introduce yourself** — broadcast a greeting when you join
|
|
415
|
+
- **Share observations** — broadcast anything interesting you notice about the PRD
|
|
416
|
+
- **Respond to DMs** — if someone messages you directly, reply briefly
|
|
417
|
+
|
|
418
|
+
**Hard limit: send at most 5 messages total (broadcasts + DMs combined).** After that, stop messaging and wait quietly. Save your context for the actual task.
|
|
419
|
+
|
|
420
|
+
\`\`\`typescript
|
|
421
|
+
pi_messenger({ action: "broadcast", message: "Hey team! Just joined. Reading the PRD now..." })
|
|
422
|
+
\`\`\`
|
|
423
|
+
|
|
424
|
+
After sending your messages, wait for a **TASK ASSIGNMENT** message.
|
|
425
|
+
`;
|
|
426
|
+
} else if (level === "moderate") {
|
|
427
|
+
prompt += `## Step 3: Brief Check-in
|
|
428
|
+
|
|
429
|
+
Announce yourself, then wait:
|
|
430
|
+
|
|
431
|
+
\`\`\`typescript
|
|
432
|
+
pi_messenger({ action: "broadcast", message: "Joined the lobby. Reading the PRD..." })
|
|
433
|
+
\`\`\`
|
|
434
|
+
|
|
435
|
+
**Hard limit: send at most 2 messages total.** You may reply once if someone DMs you. Then stop messaging and wait.
|
|
436
|
+
|
|
437
|
+
Wait for a **TASK ASSIGNMENT** message to begin work.
|
|
438
|
+
`;
|
|
439
|
+
} else if (level === "minimal") {
|
|
440
|
+
prompt += `## Step 3: Wait for Assignment
|
|
441
|
+
|
|
442
|
+
Announce your presence with one broadcast, then wait:
|
|
443
|
+
|
|
444
|
+
\`\`\`typescript
|
|
445
|
+
pi_messenger({ action: "broadcast", message: "Standing by for task assignment." })
|
|
446
|
+
\`\`\`
|
|
447
|
+
|
|
448
|
+
**Do NOT send any other messages.** Wait for a **TASK ASSIGNMENT** message to begin work.
|
|
449
|
+
`;
|
|
450
|
+
} else {
|
|
451
|
+
prompt += `## Step 3: Wait
|
|
452
|
+
|
|
453
|
+
**Do NOT send any messages, do NOT explore the codebase.** Wait for a **TASK ASSIGNMENT** message.
|
|
454
|
+
`;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
prompt += `
|
|
458
|
+
## When You Receive a Task Assignment
|
|
459
|
+
|
|
460
|
+
You will receive a message with the header **⚡ TASK ASSIGNMENT**. When you get it:
|
|
461
|
+
|
|
462
|
+
1. Read the task details carefully — the assignment message has specific instructions
|
|
463
|
+
2. Reserve files you'll modify
|
|
464
|
+
3. Implement the feature following the spec
|
|
465
|
+
4. Run tests to verify
|
|
466
|
+
5. Commit your changes
|
|
467
|
+
6. Release reservations and mark complete
|
|
468
|
+
|
|
469
|
+
The task will already be claimed and started for you — do NOT call \`task.start\`. Switch to full work mode immediately — no more lobby chat.
|
|
470
|
+
`;
|
|
471
|
+
|
|
472
|
+
return prompt;
|
|
473
|
+
}
|