@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/overlay.ts
ADDED
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Messenger - Chat Overlay Component
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Component, Focusable, TUI } from "@earendil-works/pi-tui";
|
|
6
|
+
import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
extractFolder,
|
|
10
|
+
formatDuration,
|
|
11
|
+
type MessengerState,
|
|
12
|
+
type Dirs,
|
|
13
|
+
} from "./lib.ts";
|
|
14
|
+
import * as crewStore from "./crew/store.ts";
|
|
15
|
+
import { adjustConcurrency, autonomousState, isAutonomousForCwd, isPlanningForCwd, planningState } from "./crew/state.ts";
|
|
16
|
+
import { loadCrewConfig, cycleCoordinationLevel, setCoordinationOverride } from "./crew/utils/config.ts";
|
|
17
|
+
import { readFeedEvents, type FeedEvent, type FeedEventType } from "./feed.ts";
|
|
18
|
+
import type { Task } from "./crew/types.ts";
|
|
19
|
+
import {
|
|
20
|
+
renderStatusBar,
|
|
21
|
+
renderWorkersSection,
|
|
22
|
+
renderTaskList,
|
|
23
|
+
renderTaskSummary,
|
|
24
|
+
renderFeedSection,
|
|
25
|
+
renderAgentsRow,
|
|
26
|
+
renderLegend,
|
|
27
|
+
renderEmptyState,
|
|
28
|
+
renderPlanningState,
|
|
29
|
+
renderDetailView,
|
|
30
|
+
navigateTask,
|
|
31
|
+
} from "./overlay-render.ts";
|
|
32
|
+
import {
|
|
33
|
+
createCrewViewState,
|
|
34
|
+
handleConfirmInput,
|
|
35
|
+
handleBlockReasonInput,
|
|
36
|
+
handleMessageInput,
|
|
37
|
+
handleRevisePromptInput,
|
|
38
|
+
handleCrewKeyBinding,
|
|
39
|
+
setNotification,
|
|
40
|
+
type CrewViewState,
|
|
41
|
+
} from "./overlay-actions.ts";
|
|
42
|
+
import { getLiveWorkers, hasLiveWorkers, onLiveWorkersChanged } from "./crew/live-progress.ts";
|
|
43
|
+
import { loadConfig } from "./config.ts";
|
|
44
|
+
import { discoverCrewAgents } from "./crew/utils/discover.ts";
|
|
45
|
+
import { spawnSingleWorker, spawnWorkersForReadyTasks } from "./crew/spawn.ts";
|
|
46
|
+
import * as teamStore from "./crew/team/store.ts";
|
|
47
|
+
import { spawnLobbyWorker, removeLobbyWorkerByIndex, cleanupUnassignedAliveFiles } from "./crew/lobby.ts";
|
|
48
|
+
|
|
49
|
+
export interface OverlayCallbacks {
|
|
50
|
+
onBackground?: (snapshot: string) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class MessengerOverlay implements Component, Focusable {
|
|
54
|
+
get width(): number {
|
|
55
|
+
return Math.min(100, Math.max(40, process.stdout.columns ?? 90));
|
|
56
|
+
}
|
|
57
|
+
focused = false;
|
|
58
|
+
|
|
59
|
+
private crewViewState: CrewViewState = createCrewViewState();
|
|
60
|
+
private cwd: string;
|
|
61
|
+
private stuckThresholdMs: number;
|
|
62
|
+
private progressTimer: ReturnType<typeof setInterval> | null = null;
|
|
63
|
+
private planningTimer: ReturnType<typeof setInterval> | null = null;
|
|
64
|
+
private progressUnsubscribe: (() => void) | null = null;
|
|
65
|
+
private sawIncompleteWork = false;
|
|
66
|
+
private completionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
67
|
+
private completionDismissed = false;
|
|
68
|
+
private wasPlanning: boolean;
|
|
69
|
+
private prevInProgressCount = 0;
|
|
70
|
+
|
|
71
|
+
constructor(
|
|
72
|
+
private tui: TUI,
|
|
73
|
+
private theme: Theme,
|
|
74
|
+
private state: MessengerState,
|
|
75
|
+
private dirs: Dirs,
|
|
76
|
+
private done: (snapshot?: string) => void,
|
|
77
|
+
private callbacks: OverlayCallbacks,
|
|
78
|
+
cwd: string,
|
|
79
|
+
) {
|
|
80
|
+
this.cwd = cwd;
|
|
81
|
+
const cfg = loadConfig(this.cwd);
|
|
82
|
+
this.stuckThresholdMs = cfg.stuckThreshold * 1000;
|
|
83
|
+
|
|
84
|
+
for (const key of this.state.unreadCounts.keys()) {
|
|
85
|
+
this.state.unreadCounts.set(key, 0);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.wasPlanning = isPlanningForCwd(this.cwd);
|
|
89
|
+
|
|
90
|
+
this.progressUnsubscribe = onLiveWorkersChanged(() => {
|
|
91
|
+
this.syncCrewRefreshTimers();
|
|
92
|
+
this.tui.requestRender();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
this.syncCrewRefreshTimers();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private hasPlan(): boolean {
|
|
99
|
+
return crewStore.hasPlan(this.cwd);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private handleTaskStart(task: Task): void {
|
|
103
|
+
const config = loadCrewConfig(crewStore.getCrewDir(this.cwd));
|
|
104
|
+
if (config.dependencies !== "advisory") {
|
|
105
|
+
const unmet = task.depends_on.filter(depId => crewStore.getTask(this.cwd, depId)?.status !== "done");
|
|
106
|
+
if (unmet.length > 0) {
|
|
107
|
+
setNotification(this.crewViewState, this.tui, false, `Unmet deps: ${unmet.join(", ")}`);
|
|
108
|
+
this.tui.requestRender();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (teamStore.taskNeedsApproval(task)) {
|
|
113
|
+
const message = teamStore.taskNeedsRevision(task) ? `${task.id} needs revision` : `${task.id} needs lead approval`;
|
|
114
|
+
setNotification(this.crewViewState, this.tui, false, message);
|
|
115
|
+
this.tui.requestRender();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const worker = spawnSingleWorker(this.cwd, task.id, this.state.model);
|
|
120
|
+
if (worker) {
|
|
121
|
+
setNotification(this.crewViewState, this.tui, true, `${worker.name} → ${task.id}`);
|
|
122
|
+
} else {
|
|
123
|
+
setNotification(this.crewViewState, this.tui, false, `Failed to spawn worker for ${task.id}`);
|
|
124
|
+
}
|
|
125
|
+
this.tui.requestRender();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private spawnWorkerForReadyTask(task: Task, newConcurrency: number): void {
|
|
129
|
+
const worker = spawnSingleWorker(this.cwd, task.id, this.state.model);
|
|
130
|
+
if (!worker) {
|
|
131
|
+
const message = teamStore.taskNeedsRevision(task)
|
|
132
|
+
? `${task.id} needs revision`
|
|
133
|
+
: teamStore.taskNeedsApproval(task)
|
|
134
|
+
? `${task.id} needs lead approval`
|
|
135
|
+
: `Failed to spawn worker for ${task.id}`;
|
|
136
|
+
setNotification(this.crewViewState, this.tui, false, message);
|
|
137
|
+
this.tui.requestRender();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setNotification(this.crewViewState, this.tui, true, `${worker.name} → ${task.id} (${newConcurrency}w)`);
|
|
142
|
+
this.tui.requestRender();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private isPlanningActiveForCurrentProject(): boolean {
|
|
146
|
+
return isPlanningForCwd(this.cwd);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private checkAutoSpawnOnPlanComplete(planning: boolean, tasks: Task[]): void {
|
|
150
|
+
const wasPlanningBefore = this.wasPlanning;
|
|
151
|
+
this.wasPlanning = planning;
|
|
152
|
+
|
|
153
|
+
if (!wasPlanningBefore || planning) return;
|
|
154
|
+
|
|
155
|
+
const config = loadCrewConfig(crewStore.getCrewDir(this.cwd));
|
|
156
|
+
const readyTasks = crewStore.getReadyTasksFrom(tasks, { advisory: config.dependencies === "advisory" });
|
|
157
|
+
const startableTasks = readyTasks.filter(t => !teamStore.taskNeedsApproval(t));
|
|
158
|
+
if (startableTasks.length > 0) {
|
|
159
|
+
const target = Math.min(startableTasks.length, autonomousState.concurrency);
|
|
160
|
+
const { assigned } = spawnWorkersForReadyTasks(this.cwd, target, this.state.model);
|
|
161
|
+
if (assigned > 0) {
|
|
162
|
+
setNotification(this.crewViewState, this.tui, true, `Plan ready — ${assigned} worker${assigned > 1 ? "s" : ""} started`);
|
|
163
|
+
this.tui.requestRender();
|
|
164
|
+
}
|
|
165
|
+
} else if (readyTasks.length > 0) {
|
|
166
|
+
const rejected = readyTasks.filter(teamStore.taskNeedsRevision);
|
|
167
|
+
const pending = readyTasks.filter(teamStore.taskPendingApproval);
|
|
168
|
+
const message = rejected.length > 0
|
|
169
|
+
? `Plan ready — ${rejected.length} task${rejected.length > 1 ? "s" : ""} need revision`
|
|
170
|
+
: `Plan ready — ${pending.length} task${pending.length > 1 ? "s" : ""} need lead approval`;
|
|
171
|
+
setNotification(this.crewViewState, this.tui, false, message);
|
|
172
|
+
this.tui.requestRender();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
cleanupUnassignedAliveFiles(this.cwd);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private checkAutoRefillWorkers(tasks: Task[], hasPlan: boolean): void {
|
|
179
|
+
const inProgressCount = tasks.filter(t => t.status === "in_progress").length;
|
|
180
|
+
const prev = this.prevInProgressCount;
|
|
181
|
+
this.prevInProgressCount = inProgressCount;
|
|
182
|
+
|
|
183
|
+
if (inProgressCount >= prev || inProgressCount >= autonomousState.concurrency || !hasPlan) return;
|
|
184
|
+
|
|
185
|
+
const config = loadCrewConfig(crewStore.getCrewDir(this.cwd));
|
|
186
|
+
const readyTasks = crewStore.getReadyTasksFrom(tasks, { advisory: config.dependencies === "advisory" });
|
|
187
|
+
const startableTasks = readyTasks.filter(t => !teamStore.taskNeedsApproval(t));
|
|
188
|
+
if (startableTasks.length === 0) return;
|
|
189
|
+
|
|
190
|
+
const slots = autonomousState.concurrency - inProgressCount;
|
|
191
|
+
const target = Math.min(startableTasks.length, slots);
|
|
192
|
+
if (target <= 0) return;
|
|
193
|
+
|
|
194
|
+
const { assigned } = spawnWorkersForReadyTasks(this.cwd, target, this.state.model);
|
|
195
|
+
if (assigned > 0) {
|
|
196
|
+
setNotification(this.crewViewState, this.tui, true, `${assigned} worker${assigned > 1 ? "s" : ""} → ready tasks`);
|
|
197
|
+
this.tui.requestRender();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private syncCrewRefreshTimers(): void {
|
|
202
|
+
if (hasLiveWorkers(this.cwd)) this.startProgressRefresh();
|
|
203
|
+
else this.stopProgressRefresh();
|
|
204
|
+
|
|
205
|
+
if (this.isPlanningActiveForCurrentProject()) this.startPlanningRefresh();
|
|
206
|
+
else this.stopPlanningRefresh();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private startProgressRefresh(): void {
|
|
210
|
+
if (this.progressTimer) return;
|
|
211
|
+
this.progressTimer = setInterval(() => {
|
|
212
|
+
if (hasLiveWorkers(this.cwd)) {
|
|
213
|
+
this.tui.requestRender();
|
|
214
|
+
} else {
|
|
215
|
+
this.stopProgressRefresh();
|
|
216
|
+
}
|
|
217
|
+
}, 1000);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private stopProgressRefresh(): void {
|
|
221
|
+
if (this.progressTimer) {
|
|
222
|
+
clearInterval(this.progressTimer);
|
|
223
|
+
this.progressTimer = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private startPlanningRefresh(): void {
|
|
228
|
+
if (this.planningTimer) return;
|
|
229
|
+
this.planningTimer = setInterval(() => {
|
|
230
|
+
if (this.isPlanningActiveForCurrentProject()) {
|
|
231
|
+
this.tui.requestRender();
|
|
232
|
+
} else {
|
|
233
|
+
this.stopPlanningRefresh();
|
|
234
|
+
}
|
|
235
|
+
}, 15_000);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private stopPlanningRefresh(): void {
|
|
239
|
+
if (this.planningTimer) {
|
|
240
|
+
clearInterval(this.planningTimer);
|
|
241
|
+
this.planningTimer = null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
handleInput(data: string): void {
|
|
246
|
+
this.cancelCompletionTimer();
|
|
247
|
+
|
|
248
|
+
if (data === "\x14") {
|
|
249
|
+
this.done(this.generateSnapshot());
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (data === "\x02") {
|
|
254
|
+
this.callbacks.onBackground?.(this.generateSnapshot());
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (this.crewViewState.confirmAction) {
|
|
259
|
+
handleConfirmInput(data, this.crewViewState, this.cwd, this.state.agentName, this.tui);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (this.crewViewState.inputMode === "block-reason") {
|
|
264
|
+
const tasks = crewStore.getTasks(this.cwd);
|
|
265
|
+
const task = tasks[this.crewViewState.selectedTaskIndex];
|
|
266
|
+
handleBlockReasonInput(data, this.crewViewState, this.cwd, task, this.state.agentName, this.tui);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (this.crewViewState.inputMode === "message") {
|
|
271
|
+
handleMessageInput(data, this.crewViewState, this.state, this.dirs, this.cwd, this.tui);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (this.crewViewState.inputMode === "revise-prompt") {
|
|
276
|
+
const tasks = crewStore.getTasks(this.cwd);
|
|
277
|
+
const task = tasks[this.crewViewState.selectedTaskIndex];
|
|
278
|
+
handleRevisePromptInput(data, this.crewViewState, this.cwd, task, this.state.agentName, this.tui);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (matchesKey(data, "escape")) {
|
|
283
|
+
if (this.crewViewState.mode === "detail") {
|
|
284
|
+
this.crewViewState.mode = "list";
|
|
285
|
+
this.tui.requestRender();
|
|
286
|
+
} else {
|
|
287
|
+
this.done();
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (data === "+" || matchesKey(data, "=") || matchesKey(data, "shift+=") || matchesKey(data, "-")) {
|
|
293
|
+
const delta = matchesKey(data, "-") ? -1 : 1;
|
|
294
|
+
const crewDir = crewStore.getCrewDir(this.cwd);
|
|
295
|
+
const config = loadCrewConfig(crewDir);
|
|
296
|
+
const prev = autonomousState.concurrency;
|
|
297
|
+
const next = adjustConcurrency(delta, config.concurrency.max);
|
|
298
|
+
if (prev === next) {
|
|
299
|
+
this.tui.requestRender();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (next > prev) {
|
|
304
|
+
const readyTasks = crewStore.getReadyTasks(this.cwd, { advisory: config.dependencies === "advisory" });
|
|
305
|
+
if (readyTasks.length === 0) {
|
|
306
|
+
const worker = spawnLobbyWorker(this.cwd, undefined, this.state.model);
|
|
307
|
+
const label = worker ? `Lobby worker ${worker.name} spawned (${next}w)` : `Workers → ${next}`;
|
|
308
|
+
setNotification(this.crewViewState, this.tui, true, label);
|
|
309
|
+
} else {
|
|
310
|
+
this.spawnWorkerForReadyTask(readyTasks[0], next);
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
const killed = removeLobbyWorkerByIndex(this.cwd);
|
|
314
|
+
const label = killed ? `Lobby worker removed (${next}w)` : `Workers: ${prev} → ${next}`;
|
|
315
|
+
setNotification(this.crewViewState, this.tui, true, label);
|
|
316
|
+
}
|
|
317
|
+
this.tui.requestRender();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (data === "@" || matchesKey(data, "m")) {
|
|
322
|
+
if (isPlanningForCwd(this.cwd)) {
|
|
323
|
+
setNotification(this.crewViewState, this.tui, false, "Chat unavailable during planning");
|
|
324
|
+
this.tui.requestRender();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
this.crewViewState.inputMode = "message";
|
|
328
|
+
this.crewViewState.messageInput = data === "@" ? "@" : "";
|
|
329
|
+
this.tui.requestRender();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (matchesKey(data, "f")) {
|
|
334
|
+
this.crewViewState.feedFocus = !this.crewViewState.feedFocus;
|
|
335
|
+
this.tui.requestRender();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (matchesKey(data, "v")) {
|
|
340
|
+
const crewDir = crewStore.getCrewDir(this.cwd);
|
|
341
|
+
const config = loadCrewConfig(crewDir);
|
|
342
|
+
const next = cycleCoordinationLevel(config.coordination);
|
|
343
|
+
setCoordinationOverride(next);
|
|
344
|
+
setNotification(this.crewViewState, this.tui, true, `Coordination: ${next}`);
|
|
345
|
+
this.tui.requestRender();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (matchesKey(data, "c") && this.isPlanningActiveForCurrentProject()) {
|
|
350
|
+
this.crewViewState.confirmAction = {
|
|
351
|
+
type: "cancel-planning",
|
|
352
|
+
taskId: "",
|
|
353
|
+
label: "planning",
|
|
354
|
+
};
|
|
355
|
+
this.tui.requestRender();
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const tasks = crewStore.getTasks(this.cwd);
|
|
360
|
+
const task = tasks[this.crewViewState.selectedTaskIndex];
|
|
361
|
+
|
|
362
|
+
if (matchesKey(data, "right")) {
|
|
363
|
+
if (this.crewViewState.mode === "detail") {
|
|
364
|
+
navigateTask(this.crewViewState, 1, tasks.length);
|
|
365
|
+
this.crewViewState.detailScroll = 0;
|
|
366
|
+
this.crewViewState.detailAutoScroll = true;
|
|
367
|
+
this.tui.requestRender();
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (matchesKey(data, "left")) {
|
|
373
|
+
if (this.crewViewState.mode === "detail") {
|
|
374
|
+
navigateTask(this.crewViewState, -1, tasks.length);
|
|
375
|
+
this.crewViewState.detailScroll = 0;
|
|
376
|
+
this.crewViewState.detailAutoScroll = true;
|
|
377
|
+
this.tui.requestRender();
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (matchesKey(data, "up")) {
|
|
383
|
+
if (this.crewViewState.mode === "detail") {
|
|
384
|
+
this.crewViewState.detailScroll = Math.max(0, this.crewViewState.detailScroll - 1);
|
|
385
|
+
this.crewViewState.detailAutoScroll = false;
|
|
386
|
+
} else {
|
|
387
|
+
navigateTask(this.crewViewState, -1, tasks.length);
|
|
388
|
+
}
|
|
389
|
+
this.tui.requestRender();
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (matchesKey(data, "down")) {
|
|
394
|
+
if (this.crewViewState.mode === "detail") {
|
|
395
|
+
this.crewViewState.detailScroll++;
|
|
396
|
+
this.crewViewState.detailAutoScroll = false;
|
|
397
|
+
} else {
|
|
398
|
+
navigateTask(this.crewViewState, 1, tasks.length);
|
|
399
|
+
}
|
|
400
|
+
this.tui.requestRender();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (matchesKey(data, "home")) {
|
|
405
|
+
this.crewViewState.selectedTaskIndex = 0;
|
|
406
|
+
this.crewViewState.scrollOffset = 0;
|
|
407
|
+
if (this.crewViewState.mode === "detail") {
|
|
408
|
+
this.crewViewState.detailScroll = 0;
|
|
409
|
+
this.crewViewState.detailAutoScroll = false;
|
|
410
|
+
}
|
|
411
|
+
this.tui.requestRender();
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (matchesKey(data, "end")) {
|
|
416
|
+
this.crewViewState.selectedTaskIndex = Math.max(0, tasks.length - 1);
|
|
417
|
+
if (this.crewViewState.mode === "detail") {
|
|
418
|
+
this.crewViewState.detailScroll = 0;
|
|
419
|
+
this.crewViewState.detailAutoScroll = true;
|
|
420
|
+
}
|
|
421
|
+
this.tui.requestRender();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (matchesKey(data, "enter")) {
|
|
426
|
+
if (task && this.crewViewState.mode !== "detail") {
|
|
427
|
+
this.crewViewState.mode = "detail";
|
|
428
|
+
this.crewViewState.detailScroll = 0;
|
|
429
|
+
this.crewViewState.detailAutoScroll = true;
|
|
430
|
+
this.tui.requestRender();
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this.crewViewState.mode === "detail") {
|
|
436
|
+
if (matchesKey(data, "[")) {
|
|
437
|
+
navigateTask(this.crewViewState, -1, tasks.length);
|
|
438
|
+
this.crewViewState.detailScroll = 0;
|
|
439
|
+
this.crewViewState.detailAutoScroll = true;
|
|
440
|
+
this.tui.requestRender();
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (matchesKey(data, "]")) {
|
|
444
|
+
navigateTask(this.crewViewState, 1, tasks.length);
|
|
445
|
+
this.crewViewState.detailScroll = 0;
|
|
446
|
+
this.crewViewState.detailAutoScroll = true;
|
|
447
|
+
this.tui.requestRender();
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (task) {
|
|
453
|
+
if (matchesKey(data, "s") && task.status === "todo" && !task.milestone) {
|
|
454
|
+
this.handleTaskStart(task);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
handleCrewKeyBinding(data, task, this.crewViewState, this.cwd, this.state.agentName, this.tui);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
private snapshotIdleLabel(): string {
|
|
462
|
+
const last = this.state.activity.lastActivityAt || this.state.sessionStartedAt;
|
|
463
|
+
const ageMs = Math.max(0, Date.now() - new Date(last).getTime());
|
|
464
|
+
return `idle ${formatDuration(ageMs)}`;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private formatTaskSnapshotLine(task: Task, liveTaskIds: Set<string>): string {
|
|
468
|
+
if (task.status === "done") {
|
|
469
|
+
return `${task.id} (${task.title})`;
|
|
470
|
+
}
|
|
471
|
+
if (task.status === "in_progress") {
|
|
472
|
+
const parts = [task.title];
|
|
473
|
+
if (task.assigned_to) parts.push(task.assigned_to);
|
|
474
|
+
if (liveTaskIds.has(task.id)) parts.push("live");
|
|
475
|
+
return `${task.id} (${parts.join(", ")})`;
|
|
476
|
+
}
|
|
477
|
+
if (task.status === "blocked") {
|
|
478
|
+
const reason = task.blocked_reason ? ` — ${task.blocked_reason}` : "";
|
|
479
|
+
return `${task.id} (${task.title}${reason})`;
|
|
480
|
+
}
|
|
481
|
+
if (task.depends_on.length > 0) {
|
|
482
|
+
return `${task.id} (${task.title}, deps: ${task.depends_on.join(" ")})`;
|
|
483
|
+
}
|
|
484
|
+
return `${task.id} (${task.title})`;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private formatRecentFeedEvent(event: FeedEvent): string {
|
|
488
|
+
const time = new Date(event.ts).toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false });
|
|
489
|
+
if (event.type === "task.done") return `${event.agent} completed ${event.target ?? "task"} (${time})`;
|
|
490
|
+
if (event.type === "task.start") return `${event.agent} started ${event.target ?? "task"} (${time})`;
|
|
491
|
+
if (event.type === "message") {
|
|
492
|
+
const dir = event.target ? `→ ${event.target}: ` : "✦ ";
|
|
493
|
+
return event.preview
|
|
494
|
+
? `${event.agent} ${dir}${event.preview} (${time})`
|
|
495
|
+
: `${event.agent} ${dir.trim()} (${time})`;
|
|
496
|
+
}
|
|
497
|
+
if (event.target) return `${event.agent} ${event.type} ${event.target} (${time})`;
|
|
498
|
+
return `${event.agent} ${event.type} (${time})`;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
private generateSnapshot(): string {
|
|
502
|
+
const plan = crewStore.getPlan(this.cwd);
|
|
503
|
+
const tasks = crewStore.getTasks(this.cwd);
|
|
504
|
+
const liveWorkers = getLiveWorkers(this.cwd);
|
|
505
|
+
|
|
506
|
+
if (this.isPlanningActiveForCurrentProject() && tasks.length === 0) {
|
|
507
|
+
const updated = planningState.updatedAt ? formatDuration(Math.max(0, Date.now() - new Date(planningState.updatedAt).getTime())) : "unknown";
|
|
508
|
+
return [
|
|
509
|
+
`Crew snapshot: planning in progress (pass ${planningState.pass}/${planningState.maxPasses}, ${planningState.phase}), ${autonomousState.concurrency}w concurrency`,
|
|
510
|
+
"",
|
|
511
|
+
`Planning: pass ${planningState.pass}/${planningState.maxPasses}, phase: ${planningState.phase}, updated ${updated} ago`,
|
|
512
|
+
"",
|
|
513
|
+
`Agents: You (${this.snapshotIdleLabel()})`,
|
|
514
|
+
].join("\n");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (!plan) {
|
|
518
|
+
const discovered = discoverCrewAgents(this.cwd);
|
|
519
|
+
const configLine = discovered.length === 0
|
|
520
|
+
? "Config: no crew agents discovered"
|
|
521
|
+
: `Config: ${discovered.map(agent => `${agent.name}${agent.model ? ` (${agent.model})` : ""}`).join(", ")}`;
|
|
522
|
+
|
|
523
|
+
return [
|
|
524
|
+
`Crew snapshot: no active plan, ${autonomousState.concurrency}w concurrency`,
|
|
525
|
+
"",
|
|
526
|
+
`Agents: You (${this.snapshotIdleLabel()})`,
|
|
527
|
+
"",
|
|
528
|
+
configLine,
|
|
529
|
+
].join("\n");
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const config = loadCrewConfig(crewStore.getCrewDir(this.cwd));
|
|
533
|
+
const readyTasks = crewStore.getReadyTasks(this.cwd, { advisory: config.dependencies === "advisory" });
|
|
534
|
+
const readyIds = new Set(readyTasks.map(task => task.id));
|
|
535
|
+
const liveTaskIds = new Set(Array.from(liveWorkers.keys()));
|
|
536
|
+
const activeLines = Array.from(liveWorkers.values()).map(worker => {
|
|
537
|
+
const activity = worker.progress.currentTool
|
|
538
|
+
? `${worker.progress.currentTool}${worker.progress.currentToolArgs ? ` ${worker.progress.currentToolArgs}` : ""}`
|
|
539
|
+
: "thinking";
|
|
540
|
+
return `${worker.taskId} (${worker.agent}, ${activity}, ${formatDuration(Date.now() - worker.startedAt)})`;
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
const doneTasks = tasks.filter(task => task.status === "done");
|
|
544
|
+
const inProgressTasks = tasks.filter(task => task.status === "in_progress");
|
|
545
|
+
const blockedTasks = tasks.filter(task => task.status === "blocked");
|
|
546
|
+
const waitingTasks = tasks.filter(task => task.status === "todo" && !readyIds.has(task.id));
|
|
547
|
+
const recentEvents = readFeedEvents(this.cwd, 2);
|
|
548
|
+
const headerParts = [
|
|
549
|
+
`Crew snapshot: ${plan.completed_count}/${plan.task_count} tasks done`,
|
|
550
|
+
`${readyTasks.length} ready`,
|
|
551
|
+
`${autonomousState.concurrency}w`,
|
|
552
|
+
];
|
|
553
|
+
if (isAutonomousForCwd(this.cwd)) {
|
|
554
|
+
headerParts.push(`autonomous wave ${autonomousState.waveNumber}`);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const lines = [
|
|
558
|
+
headerParts.join(", "),
|
|
559
|
+
"",
|
|
560
|
+
`Active: ${activeLines.length > 0 ? activeLines.join(", ") : "none"}`,
|
|
561
|
+
`Done: ${doneTasks.length > 0 ? doneTasks.map(task => this.formatTaskSnapshotLine(task, liveTaskIds)).join(", ") : "none"}`,
|
|
562
|
+
`In progress: ${inProgressTasks.length > 0 ? inProgressTasks.map(task => this.formatTaskSnapshotLine(task, liveTaskIds)).join(", ") : "none"}`,
|
|
563
|
+
`Ready: ${readyTasks.length > 0 ? readyTasks.map(task => this.formatTaskSnapshotLine(task, liveTaskIds)).join(", ") : "none"}`,
|
|
564
|
+
`Blocked: ${blockedTasks.length > 0 ? blockedTasks.map(task => this.formatTaskSnapshotLine(task, liveTaskIds)).join(", ") : "none"}`,
|
|
565
|
+
`Waiting: ${waitingTasks.length > 0 ? waitingTasks.map(task => this.formatTaskSnapshotLine(task, liveTaskIds)).join(", ") : "none"}`,
|
|
566
|
+
];
|
|
567
|
+
|
|
568
|
+
if (recentEvents.length > 0) {
|
|
569
|
+
lines.push("");
|
|
570
|
+
lines.push(`Recent: ${recentEvents.map(event => this.formatRecentFeedEvent(event)).join(", ")}`);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return lines.join("\n");
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
render(_width: number): string[] {
|
|
577
|
+
const w = this.width;
|
|
578
|
+
const innerW = w - 2;
|
|
579
|
+
const sectionW = innerW - 2;
|
|
580
|
+
const border = (s: string) => this.theme.fg("dim", s);
|
|
581
|
+
const pad = (s: string, len: number) => s + " ".repeat(Math.max(0, len - visibleWidth(s)));
|
|
582
|
+
const sanitizeRowContent = (content: string) => content
|
|
583
|
+
.replaceAll("\r", " ")
|
|
584
|
+
.replaceAll("\n", " ")
|
|
585
|
+
.replaceAll("\t", " ");
|
|
586
|
+
const row = (content: string) => {
|
|
587
|
+
const safe = truncateToWidth(sanitizeRowContent(content), sectionW);
|
|
588
|
+
return border("│") + pad(" " + safe, innerW) + border("│");
|
|
589
|
+
};
|
|
590
|
+
const emptyRow = () => border("│") + " ".repeat(innerW) + border("│");
|
|
591
|
+
const sectionSeparator = this.theme.fg("dim", "─".repeat(sectionW));
|
|
592
|
+
|
|
593
|
+
const tasks = crewStore.getTasks(this.cwd);
|
|
594
|
+
if (tasks.length === 0) {
|
|
595
|
+
this.crewViewState.selectedTaskIndex = 0;
|
|
596
|
+
if (this.crewViewState.mode === "detail") this.crewViewState.mode = "list";
|
|
597
|
+
} else {
|
|
598
|
+
this.crewViewState.selectedTaskIndex = Math.max(0, Math.min(this.crewViewState.selectedTaskIndex, tasks.length - 1));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const selectedTask = tasks[this.crewViewState.selectedTaskIndex] ?? null;
|
|
602
|
+
const hasPlan = this.hasPlan();
|
|
603
|
+
const planning = this.isPlanningActiveForCurrentProject();
|
|
604
|
+
this.checkAutoSpawnOnPlanComplete(planning, tasks);
|
|
605
|
+
this.checkAutoRefillWorkers(tasks, hasPlan);
|
|
606
|
+
|
|
607
|
+
const lines: string[] = [];
|
|
608
|
+
const titleContent = this.renderTitleContent();
|
|
609
|
+
const titleText = ` ${titleContent} `;
|
|
610
|
+
const titleLen = visibleWidth(titleContent) + 2;
|
|
611
|
+
const borderLen = Math.max(0, innerW - titleLen);
|
|
612
|
+
const leftBorder = Math.floor(borderLen / 2);
|
|
613
|
+
const rightBorder = borderLen - leftBorder;
|
|
614
|
+
|
|
615
|
+
lines.push(border("╭" + "─".repeat(leftBorder)) + titleText + border("─".repeat(rightBorder) + "╮"));
|
|
616
|
+
lines.push(row(renderStatusBar(this.theme, this.cwd, sectionW, tasks)));
|
|
617
|
+
lines.push(emptyRow());
|
|
618
|
+
|
|
619
|
+
const chromeLines = 6;
|
|
620
|
+
const termRows = process.stdout.rows ?? 24;
|
|
621
|
+
const contentHeight = Math.max(8, termRows - chromeLines);
|
|
622
|
+
|
|
623
|
+
const prevTs = this.crewViewState.lastSeenEventTs;
|
|
624
|
+
const allEvents = readFeedEvents(this.cwd, 20);
|
|
625
|
+
this.detectAndFlashEvents(allEvents, prevTs);
|
|
626
|
+
this.checkCompletion(tasks, planning);
|
|
627
|
+
|
|
628
|
+
let contentLines: string[];
|
|
629
|
+
if (this.crewViewState.mode === "detail" && selectedTask) {
|
|
630
|
+
contentLines = renderDetailView(this.cwd, selectedTask, sectionW, contentHeight, this.crewViewState);
|
|
631
|
+
} else {
|
|
632
|
+
const workersLimit = termRows <= 26 ? 2 : 5;
|
|
633
|
+
const hasWorkers = hasLiveWorkers(this.cwd);
|
|
634
|
+
|
|
635
|
+
let workerLines = renderWorkersSection(this.theme, this.cwd, sectionW, workersLimit);
|
|
636
|
+
const agentsLine = renderAgentsRow(
|
|
637
|
+
this.cwd,
|
|
638
|
+
sectionW,
|
|
639
|
+
this.state,
|
|
640
|
+
this.dirs,
|
|
641
|
+
this.stuckThresholdMs,
|
|
642
|
+
new Map([[this.cwd, tasks]]),
|
|
643
|
+
);
|
|
644
|
+
const agentsHeight = 2;
|
|
645
|
+
const workersHeight = () => workerLines.length > 0 ? workerLines.length + 1 : 0;
|
|
646
|
+
const available = contentHeight - workersHeight() - agentsHeight;
|
|
647
|
+
|
|
648
|
+
const isFeedFocus = this.crewViewState.feedFocus;
|
|
649
|
+
let feedHeight: number;
|
|
650
|
+
let mainHeight: number;
|
|
651
|
+
|
|
652
|
+
if (!hasPlan && !planning) {
|
|
653
|
+
feedHeight = Math.min(allEvents.length, Math.max(2, Math.floor(available * 0.4)));
|
|
654
|
+
mainHeight = available - feedHeight - (feedHeight > 0 ? 1 : 0);
|
|
655
|
+
} else if (isFeedFocus) {
|
|
656
|
+
const summaryLines = 2;
|
|
657
|
+
mainHeight = summaryLines;
|
|
658
|
+
feedHeight = available - summaryLines - 1;
|
|
659
|
+
} else if (hasWorkers) {
|
|
660
|
+
feedHeight = Math.max(6, Math.floor(available * 0.7));
|
|
661
|
+
mainHeight = available - feedHeight - 1;
|
|
662
|
+
} else {
|
|
663
|
+
feedHeight = Math.max(4, Math.floor(available * 0.6));
|
|
664
|
+
mainHeight = available - feedHeight - 1;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
feedHeight = Math.max(0, feedHeight);
|
|
668
|
+
mainHeight = Math.max(2, mainHeight);
|
|
669
|
+
|
|
670
|
+
// Cap task list to actual content height — surplus goes to feed
|
|
671
|
+
const isTaskList = hasPlan && !isFeedFocus && tasks.length > 0;
|
|
672
|
+
if (isTaskList) {
|
|
673
|
+
const taskContentHeight = Math.max(2, tasks.length);
|
|
674
|
+
if (taskContentHeight < mainHeight) {
|
|
675
|
+
const surplus = mainHeight - taskContentHeight;
|
|
676
|
+
feedHeight += surplus;
|
|
677
|
+
mainHeight = taskContentHeight;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const displayEvents = allEvents.slice(-feedHeight);
|
|
682
|
+
let feedLines = renderFeedSection(this.theme, displayEvents, sectionW, prevTs);
|
|
683
|
+
if (feedLines.length > feedHeight) feedLines = feedLines.slice(-feedHeight);
|
|
684
|
+
|
|
685
|
+
while (workerLines.length > 0 && workersHeight() + mainHeight + (feedLines.length > 0 ? feedLines.length + 1 : 0) + agentsHeight > contentHeight) {
|
|
686
|
+
workerLines = workerLines.slice(0, workerLines.length - 1);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
let mainLines: string[];
|
|
690
|
+
if (!hasPlan && !planning) {
|
|
691
|
+
mainLines = renderEmptyState(this.theme, this.cwd, sectionW, mainHeight);
|
|
692
|
+
} else if (planning && tasks.length === 0) {
|
|
693
|
+
mainLines = renderPlanningState(this.theme, this.cwd, sectionW, mainHeight);
|
|
694
|
+
} else if (isFeedFocus && tasks.length > 0) {
|
|
695
|
+
mainLines = renderTaskSummary(this.theme, this.cwd, sectionW, mainHeight, tasks);
|
|
696
|
+
} else {
|
|
697
|
+
mainLines = renderTaskList(this.theme, this.cwd, sectionW, mainHeight, this.crewViewState, tasks);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
contentLines = [];
|
|
701
|
+
|
|
702
|
+
contentLines.push(agentsLine);
|
|
703
|
+
contentLines.push(sectionSeparator);
|
|
704
|
+
|
|
705
|
+
if (workerLines.length > 0) {
|
|
706
|
+
contentLines.push(...workerLines);
|
|
707
|
+
contentLines.push(sectionSeparator);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
contentLines.push(...mainLines);
|
|
711
|
+
|
|
712
|
+
if (feedLines.length > 0) {
|
|
713
|
+
contentLines.push(sectionSeparator);
|
|
714
|
+
contentLines.push(...feedLines);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (contentLines.length > contentHeight) {
|
|
718
|
+
contentLines = contentLines.slice(0, contentHeight);
|
|
719
|
+
}
|
|
720
|
+
while (contentLines.length < contentHeight) {
|
|
721
|
+
contentLines.push("");
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
for (const line of contentLines) {
|
|
726
|
+
lines.push(row(line));
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
lines.push(border("├" + "─".repeat(innerW) + "┤"));
|
|
730
|
+
lines.push(row(renderLegend(this.theme, this.cwd, sectionW, this.crewViewState, selectedTask)));
|
|
731
|
+
lines.push(border("╰" + "─".repeat(innerW) + "╯"));
|
|
732
|
+
|
|
733
|
+
if (allEvents.length > 0) {
|
|
734
|
+
this.crewViewState.lastSeenEventTs = allEvents[allEvents.length - 1].ts;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return lines;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
private static readonly SIGNIFICANT_EVENTS = new Set<FeedEventType>([
|
|
741
|
+
"task.done", "task.block", "task.start", "message",
|
|
742
|
+
"plan.done", "plan.failed", "task.revise", "task.revise-tree",
|
|
743
|
+
]);
|
|
744
|
+
|
|
745
|
+
private detectAndFlashEvents(events: FeedEvent[], prevTs: string | null): void {
|
|
746
|
+
if (prevTs === null) return;
|
|
747
|
+
const newEvents = events.filter(e => e.ts > prevTs);
|
|
748
|
+
if (newEvents.length === 0) return;
|
|
749
|
+
|
|
750
|
+
const significant = newEvents.filter(e => MessengerOverlay.SIGNIFICANT_EVENTS.has(e.type));
|
|
751
|
+
if (significant.length === 0) return;
|
|
752
|
+
|
|
753
|
+
const last = significant[significant.length - 1];
|
|
754
|
+
const sameType = significant.filter(e => e.type === last.type);
|
|
755
|
+
|
|
756
|
+
let message: string;
|
|
757
|
+
if (sameType.length > 1) {
|
|
758
|
+
const label =
|
|
759
|
+
last.type === "task.done" ? `${sameType.length} tasks completed` :
|
|
760
|
+
last.type === "task.start" ? `${sameType.length} tasks started` :
|
|
761
|
+
last.type === "task.block" ? `${sameType.length} tasks blocked` :
|
|
762
|
+
last.type === "message" ? `${sameType.length} new messages` :
|
|
763
|
+
`${sameType.length} ${last.type} events`;
|
|
764
|
+
message = label;
|
|
765
|
+
} else {
|
|
766
|
+
const target = last.target ? ` ${last.target}` : "";
|
|
767
|
+
const preview = last.preview ? ` — ${last.preview.slice(0, 40)}` : "";
|
|
768
|
+
message =
|
|
769
|
+
last.type === "task.done" ? `${last.agent} completed${target}` :
|
|
770
|
+
last.type === "task.start" ? `${last.agent} started${target}` :
|
|
771
|
+
last.type === "task.block" ? `${last.agent} blocked${target}${preview}` :
|
|
772
|
+
last.type === "message" ? `${last.agent}${preview || " sent a message"}` :
|
|
773
|
+
last.type === "plan.done" ? "Planning completed" :
|
|
774
|
+
last.type === "plan.failed" ? "Planning failed" :
|
|
775
|
+
`${last.agent} ${last.type}${target}`;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
setNotification(this.crewViewState, this.tui, true, message);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private checkCompletion(tasks: Task[], planning: boolean): void {
|
|
782
|
+
const allDone = tasks.length > 0 && tasks.every(t => t.status === "done");
|
|
783
|
+
const isIdle = !hasLiveWorkers(this.cwd) && !isAutonomousForCwd(this.cwd) && !planning;
|
|
784
|
+
|
|
785
|
+
if (!allDone) {
|
|
786
|
+
this.sawIncompleteWork = true;
|
|
787
|
+
this.cancelCompletionTimer();
|
|
788
|
+
this.completionDismissed = false;
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if (isIdle && this.sawIncompleteWork && !this.completionTimer && !this.completionDismissed) {
|
|
793
|
+
setNotification(this.crewViewState, this.tui, true, "All tasks complete! Closing in 3s...");
|
|
794
|
+
this.completionTimer = setTimeout(() => {
|
|
795
|
+
this.completionTimer = null;
|
|
796
|
+
this.done(this.generateSnapshot());
|
|
797
|
+
}, 3000);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
private cancelCompletionTimer(): void {
|
|
802
|
+
if (this.completionTimer) {
|
|
803
|
+
clearTimeout(this.completionTimer);
|
|
804
|
+
this.completionTimer = null;
|
|
805
|
+
this.completionDismissed = true;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
private renderTitleContent(): string {
|
|
810
|
+
const label = this.theme.fg("accent", "Messenger");
|
|
811
|
+
const folder = this.theme.fg("dim", extractFolder(this.cwd));
|
|
812
|
+
return `${label} ─ ${folder}`;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
invalidate(): void {
|
|
816
|
+
// No cached state
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
dispose(): void {
|
|
820
|
+
this.stopProgressRefresh();
|
|
821
|
+
this.stopPlanningRefresh();
|
|
822
|
+
this.cancelCompletionTimer();
|
|
823
|
+
if (this.crewViewState.notificationTimer) {
|
|
824
|
+
clearTimeout(this.crewViewState.notificationTimer);
|
|
825
|
+
this.crewViewState.notificationTimer = null;
|
|
826
|
+
}
|
|
827
|
+
this.progressUnsubscribe?.();
|
|
828
|
+
this.progressUnsubscribe = null;
|
|
829
|
+
}
|
|
830
|
+
}
|