@kenkaiiii/ggcoder 5.78.0 → 5.79.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 (69) hide show
  1. package/dist/app-sidecar/goal-routes.d.ts +26 -0
  2. package/dist/app-sidecar/goal-routes.js +444 -0
  3. package/dist/app-sidecar/goal-routes.js.map +1 -0
  4. package/dist/app-sidecar/history-routes.d.ts +13 -0
  5. package/dist/app-sidecar/history-routes.js +36 -25
  6. package/dist/app-sidecar/history-routes.js.map +1 -1
  7. package/dist/app-sidecar/route-context.d.ts +12 -0
  8. package/dist/app-sidecar/run-control-routes.js +2 -1
  9. package/dist/app-sidecar/run-control-routes.js.map +1 -1
  10. package/dist/app-sidecar/session-routes.js +41 -0
  11. package/dist/app-sidecar/session-routes.js.map +1 -1
  12. package/dist/app-sidecar/session-types.d.ts +2 -0
  13. package/dist/app-sidecar/workspace-routes.js +3 -0
  14. package/dist/app-sidecar/workspace-routes.js.map +1 -1
  15. package/dist/app-sidecar.js +108 -8
  16. package/dist/app-sidecar.js.map +1 -1
  17. package/dist/core/acceptance-checks.js +17 -4
  18. package/dist/core/acceptance-checks.js.map +1 -1
  19. package/dist/core/agent-notifications.d.ts +1 -1
  20. package/dist/core/agent-session.d.ts +50 -0
  21. package/dist/core/agent-session.js +49 -11
  22. package/dist/core/agent-session.js.map +1 -1
  23. package/dist/core/ask-user.d.ts +11 -0
  24. package/dist/core/ask-user.js +6 -1
  25. package/dist/core/ask-user.js.map +1 -1
  26. package/dist/core/context-files.d.ts +8 -0
  27. package/dist/core/context-files.js +46 -0
  28. package/dist/core/context-files.js.map +1 -0
  29. package/dist/core/goals-store.d.ts +208 -0
  30. package/dist/core/goals-store.js +520 -0
  31. package/dist/core/goals-store.js.map +1 -0
  32. package/dist/core/project-discovery.d.ts +7 -0
  33. package/dist/core/project-discovery.js +8 -2
  34. package/dist/core/project-discovery.js.map +1 -1
  35. package/dist/core/session-manager.d.ts +7 -1
  36. package/dist/core/session-manager.js +17 -7
  37. package/dist/core/session-manager.js.map +1 -1
  38. package/dist/core/session-storage.js +5 -1
  39. package/dist/core/session-storage.js.map +1 -1
  40. package/dist/core/subagent-manager.d.ts +51 -0
  41. package/dist/core/subagent-manager.js +95 -15
  42. package/dist/core/subagent-manager.js.map +1 -1
  43. package/dist/core/subagent-store.js +2 -1
  44. package/dist/core/subagent-store.js.map +1 -1
  45. package/dist/goals-agent/goal-team.d.ts +2 -0
  46. package/dist/goals-agent/goal-team.js +82 -0
  47. package/dist/goals-agent/goal-team.js.map +1 -0
  48. package/dist/goals-agent/goals-agent.d.ts +90 -0
  49. package/dist/goals-agent/goals-agent.js +246 -0
  50. package/dist/goals-agent/goals-agent.js.map +1 -0
  51. package/dist/modes/subagent-worker-mode.d.ts +12 -0
  52. package/dist/modes/subagent-worker-mode.js +22 -1
  53. package/dist/modes/subagent-worker-mode.js.map +1 -1
  54. package/dist/tools/bash-read-evidence.d.ts +13 -0
  55. package/dist/tools/bash-read-evidence.js +48 -1
  56. package/dist/tools/bash-read-evidence.js.map +1 -1
  57. package/dist/tools/index.d.ts +7 -1
  58. package/dist/tools/index.js +10 -2
  59. package/dist/tools/index.js.map +1 -1
  60. package/dist/tools/read-tracker.d.ts +6 -12
  61. package/dist/tools/read-tracker.js +21 -36
  62. package/dist/tools/read-tracker.js.map +1 -1
  63. package/dist/tools/read.js +2 -2
  64. package/dist/tools/read.js.map +1 -1
  65. package/dist/tools/subagent-control.js +22 -3
  66. package/dist/tools/subagent-control.js.map +1 -1
  67. package/dist/tools/write.js +110 -8
  68. package/dist/tools/write.js.map +1 -1
  69. package/package.json +4 -4
@@ -0,0 +1,26 @@
1
+ import type http from "node:http";
2
+ import { type GoalRecord } from "../core/goals-store.js";
3
+ import type { SessionRouteContext } from "./route-context.js";
4
+ /** One row of the app's goal list. */
5
+ export interface GoalSummary {
6
+ id: string;
7
+ name: string;
8
+ goal: string;
9
+ context: GoalRecord["context"];
10
+ path: string;
11
+ createdAt: string;
12
+ lastActiveMs: number;
13
+ lastActiveDisplay: string;
14
+ /** Newest non-empty session to resume; null opens a fresh coordinator session. */
15
+ latestSessionPath: string | null;
16
+ /**
17
+ * Where the goal stands, for the goal list: briefing (not started yet),
18
+ * running (working right now), paused (by the user), or idle (started,
19
+ * not working: done, or waiting to be opened again).
20
+ */
21
+ status: "briefing" | "running" | "paused" | "interrupted" | "idle";
22
+ }
23
+ /** A goal's status for the list (see GoalSummary.status). */
24
+ export declare function goalListStatus(record: GoalRecord, busy: boolean, cutOff?: boolean): GoalSummary["status"];
25
+ /** Goal list, create, and the coordinator's automatic first reply. */
26
+ export declare function handleGoalRoutes(ctx: SessionRouteContext, req: http.IncomingMessage, res: http.ServerResponse, url: string, method: string): boolean;
@@ -0,0 +1,444 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ import { createGoal, deleteGoal, goalKickoffPrompt, goalNeedsKickoff, goalPhase, goalResumePrompt, goalSettingsNote, goalWasInterrupted, setGoalCritterModel, setGoalPaused, updateGoal, goalsRoot, listGoals, markGoalKickoff, } from "../core/goals-store.js";
4
+ import { formatRelativeTime } from "../core/project-discovery.js";
5
+ import { getModel } from "../core/model-registry.js";
6
+ import { goalCritterPick } from "../goals-agent/goals-agent.js";
7
+ import { SessionManager } from "../core/session-manager.js";
8
+ import { log } from "../core/logger.js";
9
+ import { readBody, json } from "./http.js";
10
+ /** The kickoff instruction is runtime-authored and never shown as a user bubble. */
11
+ const KICKOFF_PROVENANCE = {
12
+ source: "runtime",
13
+ kind: "automation",
14
+ visibility: "hidden",
15
+ };
16
+ /** How much of a session file's end is read to find its last message. */
17
+ const TAIL_BYTES = 64 * 1024;
18
+ /**
19
+ * The last few messages of a session file (role and content), read from its
20
+ * end only, never thawing or rewriting it. Empty when it can't be read
21
+ * (archived, gone): the goal then just isn't marked interrupted.
22
+ */
23
+ async function lastMessages(file) {
24
+ let text;
25
+ try {
26
+ const handle = await fs.open(file, "r");
27
+ try {
28
+ const { size } = await handle.stat();
29
+ const start = Math.max(0, size - TAIL_BYTES);
30
+ const buf = Buffer.alloc(size - start);
31
+ await handle.read(buf, 0, buf.length, start);
32
+ text = buf.toString("utf-8");
33
+ }
34
+ finally {
35
+ await handle.close();
36
+ }
37
+ }
38
+ catch {
39
+ return [];
40
+ }
41
+ const out = [];
42
+ for (const line of text.split("\n")) {
43
+ if (!line.startsWith("{"))
44
+ continue;
45
+ try {
46
+ const entry = JSON.parse(line);
47
+ if (entry.type === "message" && entry.message?.role) {
48
+ out.push({ role: entry.message.role, content: entry.message.content });
49
+ }
50
+ }
51
+ catch {
52
+ // A line cut at the start of the read window.
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+ /** A goal's status for the list (see GoalSummary.status). */
58
+ export function goalListStatus(record, busy, cutOff = false) {
59
+ if (record.pausedAt)
60
+ return "paused";
61
+ if (busy)
62
+ return "running";
63
+ if (cutOff)
64
+ return "interrupted";
65
+ return record.startedAt ? "idle" : "briefing";
66
+ }
67
+ async function summarize(sessions, dir, record, busy = false) {
68
+ const list = await sessions.list(dir).catch(() => []);
69
+ const withMessages = list.filter((s) => s.messageCount > 0);
70
+ let lastActiveMs = Date.parse(record.createdAt) || 0;
71
+ let latestSessionPath = null;
72
+ let latestMs = -1;
73
+ for (const s of withMessages) {
74
+ const ms = Date.parse(s.lastActivity) || 0;
75
+ if (ms > latestMs) {
76
+ latestMs = ms;
77
+ latestSessionPath = s.path;
78
+ }
79
+ if (ms > lastActiveMs)
80
+ lastActiveMs = ms;
81
+ }
82
+ return {
83
+ id: record.id,
84
+ name: record.name,
85
+ goal: record.goal,
86
+ context: record.context,
87
+ path: dir,
88
+ createdAt: record.createdAt,
89
+ lastActiveMs,
90
+ lastActiveDisplay: formatRelativeTime(lastActiveMs),
91
+ latestSessionPath,
92
+ status: goalListStatus(record, busy,
93
+ // Not working, but its last turn never finished: the app closed, or it
94
+ // was stopped, mid-work. Workers aren't known here, only the session.
95
+ !busy &&
96
+ Boolean(record.startedAt) &&
97
+ latestSessionPath !== null &&
98
+ goalWasInterrupted(record, await lastMessages(latestSessionPath), [])),
99
+ };
100
+ }
101
+ /** Goal list, create, and the coordinator's automatic first reply. */
102
+ export function handleGoalRoutes(ctx, req, res, url, method) {
103
+ if (method === "GET" && url === "/goals") {
104
+ const sessions = new SessionManager(ctx.paths.sessionsDir);
105
+ void listGoals(goalsRoot(ctx.paths.agentDir))
106
+ .then((goals) => Promise.all(goals.map((g) => summarize(sessions, g.dir, g.record, ctx.busyAt(g.dir)))))
107
+ .then((goals) => {
108
+ goals.sort((a, b) => b.lastActiveMs - a.lastActiveMs || a.id.localeCompare(b.id));
109
+ json(res, 200, { goals });
110
+ })
111
+ .catch((err) => {
112
+ log("ERROR", "app-sidecar", "listGoals failed", {
113
+ message: err instanceof Error ? err.message : String(err),
114
+ });
115
+ json(res, 500, { error: "Couldn't read your goals" });
116
+ });
117
+ return true;
118
+ }
119
+ if (method === "POST" && url === "/goals") {
120
+ void readBody(req, res).then(async (raw) => {
121
+ if (raw === null)
122
+ return;
123
+ let body;
124
+ try {
125
+ body = JSON.parse(raw);
126
+ }
127
+ catch {
128
+ json(res, 400, { error: "invalid JSON body" });
129
+ return;
130
+ }
131
+ const input = body && typeof body === "object"
132
+ ? body
133
+ : {};
134
+ try {
135
+ const created = await createGoal(goalsRoot(ctx.paths.agentDir), {
136
+ name: typeof input.name === "string" ? input.name : "",
137
+ goal: typeof input.goal === "string" ? input.goal : "",
138
+ context: Array.isArray(input.context)
139
+ ? input.context.filter((p) => typeof p === "string")
140
+ : [],
141
+ }, new Date());
142
+ if (!created.ok) {
143
+ json(res, 400, { error: created.error });
144
+ return;
145
+ }
146
+ const sessions = new SessionManager(ctx.paths.sessionsDir);
147
+ json(res, 200, {
148
+ goal: await summarize(sessions, created.value.dir, created.value.record),
149
+ });
150
+ }
151
+ catch (err) {
152
+ log("ERROR", "app-sidecar", "createGoal failed", {
153
+ message: err instanceof Error ? err.message : String(err),
154
+ });
155
+ json(res, 500, { error: "Couldn't create the goal" });
156
+ }
157
+ });
158
+ return true;
159
+ }
160
+ // Deleting removes the goal folder and its coordinator sessions. Refused
161
+ // while another window has the goal open, or while this window is running in
162
+ // it, so no live session is left working in a folder that no longer exists.
163
+ if (method === "POST" && url === "/goals/delete") {
164
+ void readBody(req, res).then(async (raw) => {
165
+ if (raw === null)
166
+ return;
167
+ let id;
168
+ try {
169
+ id = JSON.parse(raw)?.id;
170
+ }
171
+ catch {
172
+ json(res, 400, { error: "invalid JSON body" });
173
+ return;
174
+ }
175
+ if (typeof id !== "string" || !id) {
176
+ json(res, 400, { error: "Missing goal id" });
177
+ return;
178
+ }
179
+ const root = goalsRoot(ctx.paths.agentDir);
180
+ const dir = path.join(root, id);
181
+ const holders = ctx.sessionIdsAt(dir);
182
+ if (holders.some((holder) => holder !== ctx.sessionId)) {
183
+ json(res, 409, { error: "This goal is open in another window. Close it there first." });
184
+ return;
185
+ }
186
+ const ownsIt = holders.includes(ctx.sessionId);
187
+ if (ownsIt && (ctx.running || ctx.runClaim.active || ctx.autopilotActive)) {
188
+ json(res, 409, { error: "This goal is still working. Stop it first." });
189
+ return;
190
+ }
191
+ try {
192
+ const deleted = await deleteGoal(root, ctx.paths.sessionsDir, id);
193
+ if (!deleted.ok) {
194
+ json(res, 404, { error: deleted.error });
195
+ return;
196
+ }
197
+ if (ownsIt)
198
+ ctx.goal = null;
199
+ json(res, 200, { ok: true });
200
+ }
201
+ catch (err) {
202
+ log("ERROR", "app-sidecar", "deleteGoal failed", {
203
+ message: err instanceof Error ? err.message : String(err),
204
+ });
205
+ json(res, 500, { error: "Couldn't delete the goal" });
206
+ }
207
+ });
208
+ return true;
209
+ }
210
+ // Pin the model GG Goals' workers run on, or clear it (null) so they follow
211
+ // GG Goals. Applies to the next worker started; running ones keep theirs,
212
+ // so this needs no run lock.
213
+ if (method === "POST" && url === "/goal/critter-model") {
214
+ const goal = ctx.goal;
215
+ if (!goal) {
216
+ json(res, 404, { error: "This window is not a goal" });
217
+ return true;
218
+ }
219
+ void readBody(req, res).then(async (raw) => {
220
+ if (raw === null)
221
+ return;
222
+ let requested;
223
+ try {
224
+ const parsed = JSON.parse(raw)?.model;
225
+ requested = typeof parsed === "string" && parsed.trim() ? parsed.trim() : null;
226
+ }
227
+ catch {
228
+ json(res, 400, { error: "invalid JSON body" });
229
+ return;
230
+ }
231
+ try {
232
+ let pick = null;
233
+ if (requested !== null) {
234
+ const target = getModel(requested);
235
+ if (!target) {
236
+ json(res, 404, { error: `unknown model: ${requested}` });
237
+ return;
238
+ }
239
+ if (!(await ctx.auth.hasProviderAuth(target.provider))) {
240
+ json(res, 400, { error: `Connect ${target.provider} first to use ${target.name}.` });
241
+ return;
242
+ }
243
+ pick = { provider: target.provider, model: target.id };
244
+ }
245
+ const updated = await setGoalCritterModel(goal.dir, pick);
246
+ if (!updated) {
247
+ json(res, 404, { error: "Unknown goal" });
248
+ return;
249
+ }
250
+ ctx.goal = { dir: goal.dir, record: updated };
251
+ const payload = {
252
+ id: updated.id,
253
+ phase: goalPhase(updated),
254
+ critterModel: goalCritterPick(updated)?.model ?? null,
255
+ };
256
+ ctx.broadcast("goal_state", payload);
257
+ json(res, 200, payload);
258
+ }
259
+ catch (err) {
260
+ log("ERROR", "app-sidecar", "set critter model failed", {
261
+ message: err instanceof Error ? err.message : String(err),
262
+ });
263
+ json(res, 500, { error: "Couldn't change the critters' model" });
264
+ }
265
+ });
266
+ return true;
267
+ }
268
+ // Change this goal's attached folders/files or standing instructions. GG
269
+ // Goals' brief is fixed for a session (prompt cache), so the change reaches
270
+ // it in the goal's next session; refused mid-run so no worker is left
271
+ // working from a folder that was just detached.
272
+ if (method === "POST" && url === "/goal/update") {
273
+ const goal = ctx.goal;
274
+ if (!goal) {
275
+ json(res, 404, { error: "This window is not a goal" });
276
+ return true;
277
+ }
278
+ if (ctx.running || ctx.runClaim.active || ctx.autopilotActive) {
279
+ json(res, 409, { error: "This goal is still working. Pause it first." });
280
+ return true;
281
+ }
282
+ void readBody(req, res).then(async (raw) => {
283
+ if (raw === null)
284
+ return;
285
+ let body;
286
+ try {
287
+ body = JSON.parse(raw);
288
+ }
289
+ catch {
290
+ json(res, 400, { error: "invalid JSON body" });
291
+ return;
292
+ }
293
+ try {
294
+ const updated = await updateGoal(goal.dir, body);
295
+ if (!updated.ok) {
296
+ json(res, 400, { error: updated.error });
297
+ return;
298
+ }
299
+ ctx.goal = { dir: goal.dir, record: updated.value };
300
+ // GG Goals' brief is fixed for the session (prompt cache): tell it the
301
+ // new settings at its next turn instead, and they're in the brief from
302
+ // the next session on.
303
+ ctx.session.notify("goal-settings", goalSettingsNote(updated.value));
304
+ for (const item of updated.value.context) {
305
+ if (item.kind !== "folder")
306
+ continue;
307
+ const added = await ctx.session.addDirectory(item.path);
308
+ if (!added.ok && !added.error.startsWith("Already in the workspace")) {
309
+ log("WARN", "app-sidecar", "goal context folder unavailable", { error: added.error });
310
+ }
311
+ }
312
+ json(res, 200, {
313
+ context: updated.value.context,
314
+ instructions: updated.value.instructions ?? "",
315
+ });
316
+ }
317
+ catch (err) {
318
+ log("ERROR", "app-sidecar", "update goal failed", {
319
+ message: err instanceof Error ? err.message : String(err),
320
+ });
321
+ json(res, 500, { error: "Couldn't update the goal" });
322
+ }
323
+ });
324
+ return true;
325
+ }
326
+ // Pause: the app stops the current run (POST /cancel, which also stops its
327
+ // workers) and the goal stays put, even across a restart, until resumed.
328
+ if (method === "POST" && url === "/goal/pause") {
329
+ const goal = ctx.goal;
330
+ if (!goal) {
331
+ json(res, 404, { error: "This window is not a goal" });
332
+ return true;
333
+ }
334
+ void setGoalPaused(goal.dir, true, new Date())
335
+ .then((updated) => {
336
+ if (!updated) {
337
+ json(res, 404, { error: "Unknown goal" });
338
+ return;
339
+ }
340
+ ctx.goal = { dir: goal.dir, record: updated };
341
+ const payload = { id: updated.id, phase: goalPhase(updated), paused: true };
342
+ ctx.broadcast("goal_state", payload);
343
+ json(res, 200, payload);
344
+ })
345
+ .catch((err) => {
346
+ log("ERROR", "app-sidecar", "pause goal failed", {
347
+ message: err instanceof Error ? err.message : String(err),
348
+ });
349
+ json(res, 500, { error: "Couldn't pause the goal" });
350
+ });
351
+ return true;
352
+ }
353
+ // Carry a goal on: after a pause, or when its window opens after the app
354
+ // was closed mid-work. Lifts any pause, then, if the goal was cut off
355
+ // (a worker interrupted, or GG Goals' own turn unfinished), runs once with
356
+ // the resume note so GG Goals checks what's done and continues. Idempotent:
357
+ // nothing to resume answers { resumed: false }.
358
+ if (method === "POST" && url === "/goal/resume") {
359
+ const goal = ctx.goal;
360
+ if (!goal) {
361
+ json(res, 404, { error: "This window is not a goal" });
362
+ return true;
363
+ }
364
+ if (ctx.running || ctx.runClaim.active || ctx.autopilotActive) {
365
+ json(res, 200, { resumed: false });
366
+ return true;
367
+ }
368
+ if (!ctx.runClaim.claim()) {
369
+ json(res, 200, { resumed: false });
370
+ return true;
371
+ }
372
+ void (async () => {
373
+ const wasPaused = Boolean(goal.record.pausedAt);
374
+ const record = wasPaused
375
+ ? ((await setGoalPaused(goal.dir, false, new Date())) ?? goal.record)
376
+ : goal.record;
377
+ ctx.goal = { dir: goal.dir, record };
378
+ if (wasPaused) {
379
+ ctx.broadcast("goal_state", { id: record.id, phase: goalPhase(record), paused: false });
380
+ }
381
+ const cutOff = wasPaused ||
382
+ goalWasInterrupted(record, ctx.session.getMessages(), ctx.session.listSubAgents());
383
+ if (!cutOff) {
384
+ json(res, 200, { resumed: false });
385
+ return;
386
+ }
387
+ json(res, 202, { resumed: true });
388
+ await ctx.runAgent(record.name, () => ctx.session.prompt(goalResumePrompt(record), KICKOFF_PROVENANCE));
389
+ })()
390
+ .catch((err) => {
391
+ log("ERROR", "app-sidecar", "goal resume failed", {
392
+ message: err instanceof Error ? err.message : String(err),
393
+ });
394
+ if (!res.headersSent)
395
+ json(res, 500, { error: "Couldn't resume the goal" });
396
+ })
397
+ .finally(() => ctx.runClaim.release());
398
+ return true;
399
+ }
400
+ // Idempotent: the app calls this whenever it opens a goal that still needs
401
+ // its first reply. Only the first call on a fresh goal starts a run.
402
+ if (method === "POST" && url === "/goal/kickoff") {
403
+ const goal = ctx.goal;
404
+ if (!goal) {
405
+ json(res, 404, { error: "This window is not a goal" });
406
+ return true;
407
+ }
408
+ if (!goalNeedsKickoff(goal.record, ctx.session.getMessages())) {
409
+ json(res, 200, { started: false });
410
+ return true;
411
+ }
412
+ if (ctx.running || ctx.runClaim.active || ctx.autopilotActive) {
413
+ json(res, 409, { error: "The agent is busy" });
414
+ return true;
415
+ }
416
+ // Claim synchronously so a racing prompt queues instead of starting a
417
+ // second run while the kickoff record is being written.
418
+ if (!ctx.runClaim.claim()) {
419
+ json(res, 409, { error: "The agent is busy" });
420
+ return true;
421
+ }
422
+ void markGoalKickoff(goal.dir, new Date())
423
+ .then(async (updated) => {
424
+ if (!updated) {
425
+ json(res, 200, { started: false });
426
+ return;
427
+ }
428
+ ctx.goal = { dir: goal.dir, record: updated };
429
+ json(res, 202, { started: true });
430
+ await ctx.runAgent(updated.name, () => ctx.session.prompt(goalKickoffPrompt(updated), KICKOFF_PROVENANCE));
431
+ })
432
+ .catch((err) => {
433
+ log("ERROR", "app-sidecar", "goal kickoff failed", {
434
+ message: err instanceof Error ? err.message : String(err),
435
+ });
436
+ if (!res.headersSent)
437
+ json(res, 500, { error: "Couldn't start the goal" });
438
+ })
439
+ .finally(() => ctx.runClaim.release());
440
+ return true;
441
+ }
442
+ return false;
443
+ }
444
+ //# sourceMappingURL=goal-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goal-routes.js","sourceRoot":"","sources":["../../src/app-sidecar/goal-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,E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,CACpC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,CACnE,CAAC;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE;gBACjD,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,WAAW;gBAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC,CAAC;QAC7E,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,3 +1,16 @@
1
1
  import type http from "node:http";
2
2
  import type { SessionRouteContext } from "./route-context.js";
3
+ /**
4
+ * The restored worker rows for one delegation call, as the transcript shows
5
+ * them on reopen (`resultIsError`: null when no result was saved). Async
6
+ * workers are intentionally non-resumable; restored rows are historical.
7
+ */
8
+ export declare function restoredWorkerRows(call: {
9
+ readonly name: string;
10
+ readonly args: Record<string, unknown>;
11
+ }, resultIsError: boolean | null): Array<{
12
+ agentName: string | undefined;
13
+ status: "done" | "error";
14
+ toolUseCount: number;
15
+ }>;
3
16
  export declare function handleHistoryRoutes(ctx: SessionRouteContext, req: http.IncomingMessage, res: http.ServerResponse, url: string, method: string): boolean;
@@ -8,6 +8,34 @@ import { downscaleForPreview, IMAGE_MEDIA_TYPES } from "../utils/image.js";
8
8
  import { readFileBounded } from "../tools/operations.js";
9
9
  import { json } from "./http.js";
10
10
  import { detectHookKind } from "./history.js";
11
+ /**
12
+ * The restored worker rows for one delegation call, as the transcript shows
13
+ * them on reopen (`resultIsError`: null when no result was saved). Async
14
+ * workers are intentionally non-resumable; restored rows are historical.
15
+ */
16
+ export function restoredWorkerRows(call, resultIsError) {
17
+ const status = resultIsError ? "error" : "done";
18
+ if (call.name === "spawn_agent") {
19
+ // A refused call started no worker (live bug: a spawn blocked during a
20
+ // goal's briefing came back after a restart as "3 critters didn't make
21
+ // it back").
22
+ if (resultIsError)
23
+ return [];
24
+ // One row per child: a batch call starts several.
25
+ return spawnedTasks(call.args).map((spawn) => ({
26
+ agentName: spawn.task_name ?? spawn.agent,
27
+ status,
28
+ toolUseCount: 0,
29
+ }));
30
+ }
31
+ return [
32
+ {
33
+ agentName: typeof call.args.agent === "string" ? call.args.agent : undefined,
34
+ status,
35
+ toolUseCount: 0,
36
+ },
37
+ ];
38
+ }
11
39
  export function handleHistoryRoutes(ctx, req, res, url, method) {
12
40
  if (method === "GET" && url === "/history") {
13
41
  // Reconstruct the transcript from persisted messages so resume is 1:1 with
@@ -323,31 +351,14 @@ export function handleHistoryRoutes(ctx, req, res, url, method) {
323
351
  if (msg.role === "assistant" && typeof msg.content !== "string") {
324
352
  const subagentCalls = msg.content.filter((c) => c.type === "tool_call" && (c.name === "subagent" || c.name === "spawn_agent"));
325
353
  if (subagentCalls.length > 0) {
326
- const agents = subagentCalls.flatMap((c) => {
327
- const result = toolResultMap.get(c.id);
328
- // Async workers are intentionally non-resumable; restored rows are historical.
329
- const status = result?.isError ? "error" : "done";
330
- if (c.name === "spawn_agent") {
331
- // One row per child: a batch call starts several.
332
- return spawnedTasks(c.args).map((spawn) => ({
333
- agentName: spawn.task_name ?? spawn.agent,
334
- status,
335
- toolUseCount: 0,
336
- }));
337
- }
338
- return [
339
- {
340
- agentName: typeof c.args?.agent === "string" ? c.args.agent : undefined,
341
- status,
342
- toolUseCount: 0,
343
- },
344
- ];
345
- });
346
- history.push({
347
- role: "assistant",
348
- text: "",
349
- subagentGroup: agents,
350
- });
354
+ const agents = subagentCalls.flatMap((c) => restoredWorkerRows(c, toolResultMap.get(c.id)?.isError ?? null));
355
+ if (agents.length > 0) {
356
+ history.push({
357
+ role: "assistant",
358
+ text: "",
359
+ subagentGroup: agents,
360
+ });
361
+ }
351
362
  }
352
363
  }
353
364
  }, (count) => {