@letta-ai/letta-code 0.34.37 → 0.34.38

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 (56) hide show
  1. package/dist/app-server-client.cjs +8 -1
  2. package/dist/app-server-client.cjs.map +3 -3
  3. package/dist/app-server-client.js +8 -1
  4. package/dist/app-server-client.js.map +3 -3
  5. package/dist/mcp-client.js +2 -2
  6. package/dist/mcp-client.js.map +1 -1
  7. package/dist/mcp-oauth.js +2 -2
  8. package/dist/mcp-oauth.js.map +1 -1
  9. package/dist/types/agent/subagent-events.d.ts +30 -0
  10. package/dist/types/agent/subagent-events.d.ts.map +1 -0
  11. package/dist/types/agent/subagent-state.d.ts +6 -0
  12. package/dist/types/agent/subagent-state.d.ts.map +1 -1
  13. package/dist/types/agent/subagents/manager.d.ts.map +1 -1
  14. package/dist/types/agent/subagents/remote-turn-wait.d.ts +6 -1
  15. package/dist/types/agent/subagents/remote-turn-wait.d.ts.map +1 -1
  16. package/dist/types/agent/subagents/subagent-stream.d.ts +30 -0
  17. package/dist/types/agent/subagents/subagent-stream.d.ts.map +1 -1
  18. package/dist/types/app-server-client.d.ts +4 -1
  19. package/dist/types/app-server-client.d.ts.map +1 -1
  20. package/dist/types/headless-super-run-wait.d.ts +7 -0
  21. package/dist/types/headless-super-run-wait.d.ts.map +1 -1
  22. package/dist/types/tools/impl/claude-stream-session.d.ts +2 -2
  23. package/dist/types/tools/impl/claude-stream-session.d.ts.map +1 -1
  24. package/dist/types/tools/impl/codex-app-server-payloads.d.ts +5 -1
  25. package/dist/types/tools/impl/codex-app-server-payloads.d.ts.map +1 -1
  26. package/dist/types/tools/impl/codex-app-server.d.ts +2 -2
  27. package/dist/types/tools/impl/codex-app-server.d.ts.map +1 -1
  28. package/dist/types/tools/impl/cursor-session.d.ts +1 -1
  29. package/dist/types/tools/impl/cursor-session.d.ts.map +1 -1
  30. package/dist/types/tools/impl/external-coding-agent.d.ts +10 -6
  31. package/dist/types/tools/impl/external-coding-agent.d.ts.map +1 -1
  32. package/dist/types/tools/impl/external-tool-call.d.ts +27 -0
  33. package/dist/types/tools/impl/external-tool-call.d.ts.map +1 -1
  34. package/dist/types/tools/impl/opencode-server.d.ts +2 -0
  35. package/dist/types/tools/impl/opencode-server.d.ts.map +1 -1
  36. package/dist/types/tools/impl/opencode-session.d.ts +4 -1
  37. package/dist/types/tools/impl/opencode-session.d.ts.map +1 -1
  38. package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
  39. package/dist/types/tools/impl/remote-subagent-events.d.ts +18 -0
  40. package/dist/types/tools/impl/remote-subagent-events.d.ts.map +1 -0
  41. package/dist/types/tools/impl/task-transcript.d.ts +66 -14
  42. package/dist/types/tools/impl/task-transcript.d.ts.map +1 -1
  43. package/dist/types/tools/impl/task.d.ts.map +1 -1
  44. package/dist/types/tools/secret-substitution.d.ts +7 -0
  45. package/dist/types/tools/secret-substitution.d.ts.map +1 -1
  46. package/dist/types/types/app-server-protocol.d.ts +3 -3
  47. package/dist/types/types/app-server-protocol.d.ts.map +1 -1
  48. package/dist/types/types/protocol_v2.d.ts +1 -1
  49. package/dist/types/types/protocol_v2.d.ts.map +1 -1
  50. package/dist/types/types/subagent-protocol.d.ts +48 -0
  51. package/dist/types/types/subagent-protocol.d.ts.map +1 -1
  52. package/dist/types/websocket/listener/protocol-outbound.d.ts.map +1 -1
  53. package/letta.js +805 -231
  54. package/npm-shrinkwrap.json +91 -68
  55. package/package.json +2 -2
  56. package/skills/speech-generation/SKILL.md +26 -0
package/letta.js CHANGED
@@ -6077,7 +6077,7 @@ var package_default;
6077
6077
  var init_package = __esm(() => {
6078
6078
  package_default = {
6079
6079
  name: "@letta-ai/letta-code",
6080
- version: "0.34.37",
6080
+ version: "0.34.38",
6081
6081
  lettaStartupLogProtocol: 1,
6082
6082
  lettaConfigDirProtocol: 1,
6083
6083
  description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
@@ -6355,7 +6355,7 @@ var init_package = __esm(() => {
6355
6355
  },
6356
6356
  lettaLifecycleProtocol: 1,
6357
6357
  lettaRuntimeGraphProtocol: 1,
6358
- lettaRuntimeGraphSha512: "sha512-WqLO/tmUfIp8hKqBdQE1lQtkR5VxOaoI/Ajy8QoRz3N1f0x2/gRcyGbTKlonrJrkKMNXyKJMWYtqAbudmdmrog==",
6358
+ lettaRuntimeGraphSha512: "sha512-A1kdX0tWknAIbqO7TviYhJ8DS12ycZiM8dB/8GuJPSW1AHCVvJ9QpqCQ/iVE1TOGYMRJpRz+FcpND+DAwTF7pg==",
6359
6359
  patchedDependencies: {
6360
6360
  "@earendil-works/pi-ai@0.99.1": "patches/@earendil-works%2Fpi-ai@0.99.1.patch"
6361
6361
  }
@@ -172831,15 +172831,35 @@ function getAmbientRedactionSecrets(scopedAgentId) {
172831
172831
  return mergeAmbientSecrets({}, scopedAgentId);
172832
172832
  }
172833
172833
  function scrubWithEntries(input, entries) {
172834
+ const forms = entries.flatMap(([name, value]) => {
172835
+ const escaped = JSON.stringify(value).slice(1, -1);
172836
+ return escaped === value ? [[name, value]] : [[name, value], [name, escaped]];
172837
+ });
172834
172838
  let result2 = input;
172835
- const sorted = [...entries].sort(([, a2], [, b3]) => b3.length - a2.length);
172836
- for (const [name, value] of sorted) {
172839
+ forms.sort(([, a2], [, b3]) => b3.length - a2.length);
172840
+ for (const [name, value] of forms) {
172837
172841
  if (value.length > 0) {
172838
172842
  result2 = result2.replaceAll(value, `${name}=<REDACTED>`);
172839
172843
  }
172840
172844
  }
172841
172845
  return result2;
172842
172846
  }
172847
+ function scrubSecretsDeep(value, secrets2) {
172848
+ const entries = Object.entries(secrets2);
172849
+ if (entries.length === 0)
172850
+ return value;
172851
+ const walk3 = (node) => {
172852
+ if (typeof node === "string")
172853
+ return scrubWithEntries(node, entries);
172854
+ if (Array.isArray(node))
172855
+ return node.map(walk3);
172856
+ if (node && typeof node === "object") {
172857
+ return Object.fromEntries(Object.entries(node).map(([key2, child]) => [key2, walk3(child)]));
172858
+ }
172859
+ return node;
172860
+ };
172861
+ return walk3(value);
172862
+ }
172843
172863
  function scrubSecretsFromString(input, secrets2, scopedAgentId) {
172844
172864
  return scrubWithEntries(input, Object.entries(mergeAmbientSecrets(secrets2, scopedAgentId)));
172845
172865
  }
@@ -211765,7 +211785,7 @@ var init_mcp_client = __esm(() => {
211765
211785
  init_streamableHttp();
211766
211786
  DEFAULT_CLIENT_INFO = {
211767
211787
  name: "letta-code",
211768
- version: "0.34.37"
211788
+ version: "0.34.38"
211769
211789
  };
211770
211790
  });
211771
211791
 
@@ -216114,7 +216134,9 @@ When launching a new subagent, you must specify a subagent_type parameter to sel
216114
216134
  - Always include a short description (3-5 words) summarizing what the agent will do
216115
216135
  - Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
216116
216136
  - When the agent is done, it will return a single message back to you along with its conversation ID. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
216117
- - Agents always run in the background. The tool result includes a task ID and an output_file path, and you will be notified automatically via a <task-notification> message when it completes, so there is no need to poll. The output file receives the report when the agent finishes; it has no interim progress. You can continue working while agents run.
216137
+ - Agents always run in the background. The tool result includes a task ID and an output_file path. You are notified with a <task-notification> when the agent finishes, so don't poll just to wait; keep working.
216138
+ - To check on a running agent of any type, Read its output file. It logs each tool call (\`tool:\`), its outcome (\`result: ok, 3.2 KB\`, or \`result: error, …\` with the line naming the error), and each message (\`text:\`) as they happen, with timestamps, and ends with \`[Task completed]\` or \`[Task failed]\`. To get each step as an event, arm a Monitor on \`tail -f\` of the file. A tool call writes nothing until it returns, so a quiet log under a long-running \`tool:\` line usually means busy, not stuck; don't call an agent stalled or dead from a quiet log alone.
216139
+ - For exact details, such as which test failed and its error, a file's contents, or a command's full output, read the event log next to the output file (the \`Event log:\` path in the tool result, \`<task>.jsonl\`). It has one JSON object per line, in order and untruncated: \`tool_call\` (\`id\`, \`name\`, \`input\`), \`tool_result\` (\`tool_call_id\`, \`name\`, \`is_error\`, \`output\`), \`text\`, \`reasoning\`, and \`notification\` (a background command's completion notice, with its output). Search it with Grep or \`jq\` instead of reading it whole when it is large. For a Letta subagent, \`letta messages list --agent <agent_id> --conversation <conversation_id>\` reads its full conversation, including turns after this task.
216118
216140
  - Agents can be resumed using the \`conversation_id\` parameter by passing the conversation ID from a previous invocation. When resumed, the agent continues with its full previous context preserved.
216119
216141
  - Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
216120
216142
  - Agents with "access to current context" can see the full conversation history before the tool call. When using these agents, you can write concise prompts that reference earlier context (e.g., "investigate the error discussed above") instead of repeating information. The agent will receive all prior messages and understand the context.
@@ -216281,7 +216303,7 @@ Agent({
216281
216303
 
216282
216304
  Behavior notes:
216283
216305
  - The remote turn runs with the remote machine's working directory, tools, and skills. Subagent-type tool restrictions (e.g. recall's read-only toolset) travel with the turn on current servers; older servers ignore them.
216284
- - The remote turn's final assistant message is returned as the task result. Token and step statistics are not available for remote runs.
216306
+ - The remote turn's tool calls, results, and messages reach the output file and event log within a few seconds, as for a local run. Its final assistant message is returned as the task result. Token and step statistics are not available for remote runs.
216285
216307
  - Computer-routed tasks are submitted asynchronously and tracked through Cloud's existing Super Run status feed. Temporary status-read failures retry in the background; there is no one-hour tracking ceiling. Completion still notifies you if the reply could not be collected; use \`letta messages list\` to read the conversation rather than launching the task again. Stopping a task cancels its queued input or its executing listener run.
216286
216308
 
216287
216309
  ## Concurrency and Safety:
@@ -223956,6 +223978,83 @@ var init_hooks = __esm(() => {
223956
223978
  init_types9();
223957
223979
  });
223958
223980
 
223981
+ // src/agent/subagent-events.ts
223982
+ function capTaskEvent(event, maxBytes = REMOTE_EVENT_MAX_BYTES) {
223983
+ const size2 = jsonBytes(event);
223984
+ if (size2 <= maxBytes)
223985
+ return event;
223986
+ const field = ["output", "text", "input"].find((key2) => (key2 in event));
223987
+ if (!field)
223988
+ return { seq: event.seq, at: event.at, type: event.type };
223989
+ const value = event[field];
223990
+ const text2 = Buffer.from(typeof value === "string" ? value : JSON.stringify(value) ?? "");
223991
+ const keep = Math.max(0, text2.length - (size2 - maxBytes) - 128);
223992
+ const dropped = text2.length - keep;
223993
+ return {
223994
+ ...event,
223995
+ [field]: `${text2.subarray(0, keep).toString("utf8")}
223996
+ [truncated ${dropped} bytes]`,
223997
+ truncated_bytes: dropped
223998
+ };
223999
+ }
224000
+ function serveSubagentEvents(subagentId) {
224001
+ if (!stores4.has(subagentId))
224002
+ stores4.set(subagentId, { events: [], bytes: 0, droppedThrough: 0 });
224003
+ }
224004
+ function storeSubagentEvent(subagentId, event) {
224005
+ const store2 = stores4.get(subagentId);
224006
+ if (!store2)
224007
+ return;
224008
+ const capped = capTaskEvent(event);
224009
+ const bytes = jsonBytes(capped);
224010
+ store2.events.push({ event: capped, bytes });
224011
+ store2.bytes += bytes;
224012
+ while (store2.bytes > REMOTE_EVENT_STORE_MAX_BYTES) {
224013
+ const dropped = store2.events.shift();
224014
+ if (!dropped)
224015
+ break;
224016
+ store2.bytes -= dropped.bytes;
224017
+ store2.droppedThrough = dropped.event.seq;
224018
+ }
224019
+ }
224020
+ function readSubagentEvents(subagentId, afterSeq, maxBytes = REMOTE_EVENT_PAGE_BYTES) {
224021
+ const store2 = stores4.get(subagentId);
224022
+ if (!store2)
224023
+ return;
224024
+ const budget = Math.min(maxBytes, REMOTE_EVENT_PAGE_BYTES);
224025
+ const events = [];
224026
+ let bytes = 0;
224027
+ let next = Math.max(afterSeq, store2.droppedThrough);
224028
+ let hasMore = false;
224029
+ for (const stored of store2.events) {
224030
+ if (stored.event.seq <= afterSeq)
224031
+ continue;
224032
+ if (events.length > 0 && bytes + stored.bytes > budget) {
224033
+ hasMore = true;
224034
+ break;
224035
+ }
224036
+ events.push(stored.event);
224037
+ bytes += stored.bytes;
224038
+ next = stored.event.seq;
224039
+ }
224040
+ return {
224041
+ events,
224042
+ next_seq: next,
224043
+ has_more: hasMore,
224044
+ missed: Math.max(0, store2.droppedThrough - afterSeq)
224045
+ };
224046
+ }
224047
+ function clearSubagentEvents(subagentId) {
224048
+ stores4.delete(subagentId);
224049
+ }
224050
+ var REMOTE_EVENT_MAX_BYTES, REMOTE_EVENT_STORE_MAX_BYTES, REMOTE_EVENT_PAGE_BYTES, jsonBytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8"), stores4;
224051
+ var init_subagent_events = __esm(() => {
224052
+ REMOTE_EVENT_MAX_BYTES = 256 * 1024;
224053
+ REMOTE_EVENT_STORE_MAX_BYTES = 32 * 1024 * 1024;
224054
+ REMOTE_EVENT_PAGE_BYTES = 1024 * 1024;
224055
+ stores4 = new Map;
224056
+ });
224057
+
223959
224058
  // src/agent/subagent-state.ts
223960
224059
  function excerptProgressText(value, max2) {
223961
224060
  const line = value.replace(/\s+/g, " ").trim();
@@ -224015,6 +224114,7 @@ function armCompletedSubagentCleanup(id2) {
224015
224114
  return;
224016
224115
  }
224017
224116
  store2.agents.delete(id2);
224117
+ clearSubagentEvents(id2);
224018
224118
  notifyListeners();
224019
224119
  }, isPublished(agent) ? publishedResultRetentionMs : completedSubagentRetentionMs);
224020
224120
  unrefTimer2(timer);
@@ -224186,6 +224286,7 @@ function clearCompletedSubagents() {
224186
224286
  if (agent.status === "completed" || agent.status === "error") {
224187
224287
  clearCompletedSubagentCleanup(id2);
224188
224288
  store2.agents.delete(id2);
224289
+ clearSubagentEvents(id2);
224189
224290
  removedAny = true;
224190
224291
  }
224191
224292
  }
@@ -224202,6 +224303,7 @@ function clearSubagentsByIds(ids) {
224202
224303
  continue;
224203
224304
  }
224204
224305
  clearCompletedSubagentCleanup(id2);
224306
+ clearSubagentEvents(id2);
224205
224307
  removedAny = store2.agents.delete(id2) || removedAny;
224206
224308
  }
224207
224309
  if (removedAny) {
@@ -224314,6 +224416,7 @@ function emitStreamEvent(subagentId, event) {
224314
224416
  }
224315
224417
  var PROGRESS_TEXT_CHARS = 300, MAX_PROGRESS_TEXTS = 20, store2, cachedSnapshot, cachedLifecycleItems, DEFAULT_COMPLETED_SUBAGENT_RETENTION_MS = 30000, completedSubagentRetentionMs, DEFAULT_PUBLISHED_RESULT_RETENTION_MS, publishedResultRetentionMs, completedSubagentCleanupTimers, subagentCounter = 0, subagentAbortHooks, streamEventListeners;
224316
224418
  var init_subagent_state = __esm(() => {
224419
+ init_subagent_events();
224317
224420
  store2 = {
224318
224421
  agents: new Map,
224319
224422
  expanded: false,
@@ -238060,6 +238163,7 @@ function buildSubagentSnapshot(runtime, scope) {
238060
238163
  start_time: a2.startTime,
238061
238164
  tool_calls: a2.toolCalls,
238062
238165
  ...a2.progressTexts?.length ? { progress_texts: a2.progressTexts } : {},
238166
+ ...a2.eventSeq !== undefined ? { event_seq: a2.eventSeq } : {},
238063
238167
  total_tokens: a2.totalTokens,
238064
238168
  duration_ms: a2.durationMs,
238065
238169
  error: a2.error,
@@ -244353,6 +244457,22 @@ async function waitForAcceptedSuperRun(receipt, signal, deps) {
244353
244457
  const pollMs = deps.pollMs ?? 1000;
244354
244458
  const runLinkGraceMs = deps.runLinkGraceMs ?? DEFAULT_RUN_LINK_GRACE_MS;
244355
244459
  let completedWithoutRunSince;
244460
+ const progressMs = deps.progressMs ?? 3000;
244461
+ let lastProgressAt;
244462
+ const reportProgress = async (runIds, force) => {
244463
+ if (!deps.onProgress || runIds.length === 0)
244464
+ return;
244465
+ const now2 = Date.now();
244466
+ if (!force && lastProgressAt !== undefined && now2 - lastProgressAt < progressMs) {
244467
+ return;
244468
+ }
244469
+ lastProgressAt = now2;
244470
+ try {
244471
+ await deps.onProgress(runIds, AbortSignal.any([signal, AbortSignal.timeout(1e4)]));
244472
+ } catch {
244473
+ signal.throwIfAborted();
244474
+ }
244475
+ };
244356
244476
  const sleep11 = deps.sleep ?? ((ms, waitSignal) => delay3(ms, undefined, { signal: waitSignal }));
244357
244477
  while (true) {
244358
244478
  signal.throwIfAborted();
@@ -244363,6 +244483,7 @@ async function waitForAcceptedSuperRun(receipt, signal, deps) {
244363
244483
  throwIfSuperRunFailed(exact);
244364
244484
  const terminal = exact.status === "COM" || exact.completed_at !== null;
244365
244485
  if (!terminal) {
244486
+ await reportProgress(exact.run_ids, false);
244366
244487
  await sleep11(pollMs, signal);
244367
244488
  continue;
244368
244489
  }
@@ -244383,6 +244504,7 @@ async function waitForAcceptedSuperRun(receipt, signal, deps) {
244383
244504
  await sleep11(pollMs, signal);
244384
244505
  continue;
244385
244506
  }
244507
+ await reportProgress(exact.run_ids, true);
244386
244508
  let messages = [];
244387
244509
  try {
244388
244510
  messages = await deps.messages(runId, AbortSignal.any([signal, AbortSignal.timeout(1e4)]));
@@ -244676,6 +244798,29 @@ function formatExternalToolCallArgs(value) {
244676
244798
  }
244677
244799
  return json2.length > MAX_TOOL_CALL_ARGS_LENGTH ? `${json2.slice(0, MAX_TOOL_CALL_ARGS_LENGTH)}…` : json2;
244678
244800
  }
244801
+ function parseToolInput2(args) {
244802
+ try {
244803
+ return JSON.parse(args);
244804
+ } catch {
244805
+ return args;
244806
+ }
244807
+ }
244808
+ function toolOutputText(value) {
244809
+ if (value === undefined || value === null)
244810
+ return "";
244811
+ if (typeof value === "string")
244812
+ return value;
244813
+ if (Array.isArray(value)) {
244814
+ return value.map((part) => typeof part?.text === "string" ? part.text : toolOutputText(part)).join(`
244815
+ `);
244816
+ }
244817
+ return JSON.stringify(value) ?? String(value);
244818
+ }
244819
+ function emitProgress(listener, value) {
244820
+ try {
244821
+ listener?.(value);
244822
+ } catch {}
244823
+ }
244679
244824
  var MAX_TOOL_CALL_ARGS_LENGTH = 1000;
244680
244825
 
244681
244826
  // src/tools/impl/claude-stream-session.ts
@@ -244896,13 +245041,9 @@ function reportText(session3, messageId, text2) {
244896
245041
  if (session3.seenTextBlocks.has(key2))
244897
245042
  return;
244898
245043
  session3.seenTextBlocks.add(key2);
244899
- try {
244900
- session3.onText(text2);
244901
- } catch {}
245044
+ emitProgress(session3.onText, text2);
244902
245045
  }
244903
245046
  function handleAssistant(session3, value) {
244904
- if (!session3.onToolCall && !session3.onText)
244905
- return;
244906
245047
  const message = readRecord(value.message);
244907
245048
  const content = message?.content;
244908
245049
  if (!Array.isArray(content))
@@ -244913,16 +245054,41 @@ function handleAssistant(session3, value) {
244913
245054
  reportText(session3, message?.id, block.text);
244914
245055
  continue;
244915
245056
  }
244916
- if (!session3.onToolCall || block?.type !== "tool_use" || typeof block.id !== "string" || typeof block.name !== "string" || session3.seenToolCallIds.has(block.id))
245057
+ if (block?.type === "thinking" && typeof block.thinking === "string") {
245058
+ if (block.thinking.trim())
245059
+ emitProgress(session3.onReasoning, block.thinking);
245060
+ continue;
245061
+ }
245062
+ if (block?.type !== "tool_use" || typeof block.id !== "string" || typeof block.name !== "string" || session3.seenToolCallIds.has(block.id))
244917
245063
  continue;
244918
245064
  session3.seenToolCallIds.add(block.id);
244919
- try {
244920
- session3.onToolCall({
244921
- id: block.id,
244922
- name: block.name,
244923
- args: formatExternalToolCallArgs(block.input)
244924
- });
244925
- } catch {}
245065
+ session3.toolNames.set(block.id, block.name);
245066
+ emitProgress(session3.onToolCall, {
245067
+ id: block.id,
245068
+ name: block.name,
245069
+ args: formatExternalToolCallArgs(block.input),
245070
+ input: block.input
245071
+ });
245072
+ }
245073
+ }
245074
+ function handleToolResults(session3, value) {
245075
+ const content = readRecord(value.message)?.content;
245076
+ if (!Array.isArray(content))
245077
+ return;
245078
+ for (const entry of content) {
245079
+ const block = readRecord(entry);
245080
+ const id2 = block?.tool_use_id;
245081
+ if (block?.type !== "tool_result" || typeof id2 !== "string")
245082
+ continue;
245083
+ const name = session3.toolNames.get(id2);
245084
+ if (!session3.toolNames.delete(id2))
245085
+ continue;
245086
+ emitProgress(session3.onToolResult, {
245087
+ id: id2,
245088
+ name,
245089
+ isError: block.is_error === true,
245090
+ output: toolOutputText(block.content)
245091
+ });
244926
245092
  }
244927
245093
  }
244928
245094
  function settleResult(session3, value) {
@@ -245057,7 +245223,10 @@ async function launchSession(options, deps) {
245057
245223
  onToolCall: options.onToolCall,
245058
245224
  seenToolCallIds: new Set,
245059
245225
  onText: options.onText,
245060
- seenTextBlocks: new Set
245226
+ seenTextBlocks: new Set,
245227
+ onToolResult: options.onToolResult,
245228
+ onReasoning: options.onReasoning,
245229
+ toolNames: new Map
245061
245230
  };
245062
245231
  sessions.set(sessionId, session3);
245063
245232
  transport3.process.stderr.setEncoding("utf8");
@@ -245074,6 +245243,8 @@ async function launchSession(options, deps) {
245074
245243
  handleControlResponse(session3, value);
245075
245244
  } else if (value.type === "user" && value.isReplay === true) {
245076
245245
  acknowledgeInput(session3, value.uuid);
245246
+ } else if (value.type === "user") {
245247
+ handleToolResults(session3, value);
245077
245248
  } else if (value.type === "command_lifecycle" && (value.state === "started" || value.state === "completed")) {
245078
245249
  acknowledgeInput(session3, value.command_uuid);
245079
245250
  } else if (value.type === "result") {
@@ -245345,7 +245516,8 @@ function describeCodexToolItem(item) {
245345
245516
  const call2 = (name, args) => ({
245346
245517
  id: id2,
245347
245518
  name,
245348
- args: formatExternalToolCallArgs(args)
245519
+ args: formatExternalToolCallArgs(args),
245520
+ input: args
245349
245521
  });
245350
245522
  switch (item.type) {
245351
245523
  case "commandExecution":
@@ -245368,6 +245540,33 @@ function describeCodexToolItem(item) {
245368
245540
  return;
245369
245541
  }
245370
245542
  }
245543
+ function describeCodexToolResult(item) {
245544
+ const id2 = readString3(item, "id");
245545
+ if (!id2 || !TOOL_ITEM_TYPES.has(String(item.type)))
245546
+ return;
245547
+ const status = readString3(item, "status");
245548
+ const exitCode = typeof item.exitCode === "number" ? item.exitCode : 0;
245549
+ const error5 = asRecord9(item.error);
245550
+ const output = item.type === "commandExecution" ? `${toolOutputText(item.aggregatedOutput)}${exitCode ? `
245551
+ [exit code ${exitCode}]` : ""}` : item.type === "fileChange" ? toolOutputText(item.changes) : item.type === "mcpToolCall" ? error5 ? readString3(error5, "message") ?? toolOutputText(error5) : toolOutputText(asRecord9(item.result)?.content ?? item.result) : toolOutputText(item.contentItems);
245552
+ return {
245553
+ id: id2,
245554
+ isError: status === "failed" || status === "declined" || exitCode !== 0 || Boolean(error5) || item.success === false,
245555
+ output
245556
+ };
245557
+ }
245558
+ function codexReasoningText(item) {
245559
+ if (item.type !== "reasoning")
245560
+ return "";
245561
+ for (const parts of [item.summary, item.content]) {
245562
+ const text2 = Array.isArray(parts) ? parts.filter((part) => typeof part === "string").join(`
245563
+
245564
+ `) : "";
245565
+ if (text2.trim())
245566
+ return text2;
245567
+ }
245568
+ return "";
245569
+ }
245371
245570
  function capacityResult(result3) {
245372
245571
  return {
245373
245572
  ...result3,
@@ -245516,7 +245715,7 @@ class CodexAppServerClient {
245516
245715
  await this.request("initialize", {
245517
245716
  clientInfo: {
245518
245717
  name: "letta-code",
245519
- version: "0.34.37"
245718
+ version: "0.34.38"
245520
245719
  },
245521
245720
  capabilities: null
245522
245721
  });
@@ -245629,6 +245828,14 @@ function recordItem(session3, params, completed) {
245629
245828
  session3.activeWaiter.latestAgentMessage = item.text;
245630
245829
  recordTextItem(session3.activeWaiter, item);
245631
245830
  }
245831
+ if (completed) {
245832
+ const result3 = describeCodexToolResult(item);
245833
+ if (result3)
245834
+ emitProgress(session3.activeWaiter.onToolResult, result3);
245835
+ const reasoning = codexReasoningText(item);
245836
+ if (reasoning)
245837
+ emitProgress(session3.activeWaiter.onReasoning, reasoning);
245838
+ }
245632
245839
  return true;
245633
245840
  }
245634
245841
  function settleTurn(session3, params) {
@@ -245833,6 +246040,8 @@ async function startTurnAttempt(session3, prompt, startedAt, listeners5) {
245833
246040
  onToolCall: listeners5.onToolCall,
245834
246041
  seenToolCallIds: new Set,
245835
246042
  onText: listeners5.onText,
246043
+ onToolResult: listeners5.onToolResult,
246044
+ onReasoning: listeners5.onReasoning,
245836
246045
  reportedText: listeners5.reportedText,
245837
246046
  textFromEarlierAttempts: new Set(listeners5.reportedText.texts),
245838
246047
  ranTool: false,
@@ -245842,11 +246051,13 @@ async function startTurnAttempt(session3, prompt, startedAt, listeners5) {
245842
246051
  });
245843
246052
  return { turnId, outcome };
245844
246053
  }
245845
- async function startTurnUnlocked(session3, prompt, signal, onStarted, { onToolCall, onText } = {}) {
246054
+ async function startTurnUnlocked(session3, prompt, signal, onStarted, { onToolCall, onText, onToolResult, onReasoning } = {}) {
245846
246055
  const startedAt = Date.now();
245847
246056
  const listeners5 = {
245848
246057
  onToolCall,
245849
246058
  onText,
246059
+ onToolResult,
246060
+ onReasoning,
245850
246061
  reportedText: { itemIds: new Set, texts: new Set }
245851
246062
  };
245852
246063
  const first = await startTurnAttempt(session3, prompt, startedAt, listeners5);
@@ -246092,13 +246303,15 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
246092
246303
  const event = JSON.parse(line.slice("letta-cursor:".length));
246093
246304
  if (event.type === "started")
246094
246305
  options.onStarted?.(id2);
246095
- else if (event.type === "tool")
246306
+ else if (event.type === "tool") {
246307
+ const args = redact(JSON.stringify(event.args ?? {}));
246096
246308
  options.onToolCall?.({
246097
246309
  id: event.id,
246098
246310
  name: event.name,
246099
- args: redact(JSON.stringify(event.args ?? {})).slice(0, 1000)
246311
+ args: args.slice(0, 1000),
246312
+ input: parseToolInput2(args)
246100
246313
  });
246101
- else if (event.type === "steer") {
246314
+ } else if (event.type === "steer") {
246102
246315
  const waiter = pending2.get(event.id);
246103
246316
  pending2.delete(event.id);
246104
246317
  if (event.error)
@@ -248041,7 +248254,17 @@ function onEvent(session3, event) {
248041
248254
  turn.onToolCall?.({
248042
248255
  id: part.callID,
248043
248256
  name: part.tool,
248044
- args: formatExternalToolCallArgs(part.state?.input)
248257
+ args: formatExternalToolCallArgs(part.state?.input),
248258
+ input: part.state?.input
248259
+ });
248260
+ }
248261
+ const status = part?.state?.status;
248262
+ if (event.type === "message.part.updated" && part?.type === "tool" && part.callID && (status === "completed" || status === "error")) {
248263
+ emitProgress(turn.onToolResult, {
248264
+ id: part.callID,
248265
+ name: part.tool,
248266
+ isError: status === "error",
248267
+ output: toolOutputText(status === "error" ? part.state?.error : part.state?.output)
248045
248268
  });
248046
248269
  }
248047
248270
  }
@@ -248140,7 +248363,8 @@ function start(session3, options) {
248140
248363
  startedAt: Date.now(),
248141
248364
  generation: 0,
248142
248365
  seen: new Set,
248143
- onToolCall: options.onToolCall
248366
+ onToolCall: options.onToolCall,
248367
+ onToolResult: options.onToolResult
248144
248368
  };
248145
248369
  session3.active = turn;
248146
248370
  submit(session3, turn, options.prompt);
@@ -248486,10 +248710,27 @@ function scrubExternalWorkerResult(result3, secretEnv) {
248486
248710
  }
248487
248711
  };
248488
248712
  }
248713
+ function scrubWorkerListeners(listeners5, secretEnv) {
248714
+ if (Object.keys(secretEnv).length === 0)
248715
+ return listeners5;
248716
+ const redactions = captureSecretRedactions(undefined, secretEnv);
248717
+ const scrub = (value) => scrubSecretsDeep(value, redactions);
248718
+ const { onToolCall, onText, onToolResult, onReasoning } = listeners5;
248719
+ return {
248720
+ onToolCall: onToolCall && ((call2) => onToolCall(scrub(call2))),
248721
+ onText: onText && ((text2) => onText(scrub(text2))),
248722
+ onToolResult: onToolResult && ((result3) => onToolResult(scrub(result3))),
248723
+ onReasoning: onReasoning && ((text2) => onReasoning(scrub(text2)))
248724
+ };
248725
+ }
248489
248726
  async function runExternalCodingAgent(options, deps = {}) {
248490
248727
  const startedAt = Date.now();
248491
248728
  const { env: env6, secretEnv, mcpReminder } = await buildExternalWorkerLaunchEnv(options, deps);
248492
- options = { ...options, mcpReminder };
248729
+ options = {
248730
+ ...options,
248731
+ ...scrubWorkerListeners(options, secretEnv),
248732
+ mcpReminder
248733
+ };
248493
248734
  const cwd2 = options.cwd ?? getCurrentWorkingDirectory();
248494
248735
  const captureActingUserId = options.actingUserId !== undefined ? options.actingUserId : getRuntimeActingUserAttribution();
248495
248736
  const scope = options.parentConversationId ? {
@@ -248565,6 +248806,8 @@ async function runExternalCodingAgent(options, deps = {}) {
248565
248806
  resumeThreadId: options.resumeSessionId,
248566
248807
  onToolCall: options.onToolCall,
248567
248808
  onText: options.onText,
248809
+ onToolResult: options.onToolResult,
248810
+ onReasoning: options.onReasoning,
248568
248811
  beforeStart: async (threadId) => {
248569
248812
  if (scope && !captureReservation) {
248570
248813
  if (!options.resumeSessionId) {
@@ -248608,7 +248851,9 @@ async function runExternalCodingAgent(options, deps = {}) {
248608
248851
  resumeSessionId: options.resumeSessionId,
248609
248852
  sessionId,
248610
248853
  onToolCall: options.onToolCall,
248611
- onText: options.onText
248854
+ onText: options.onText,
248855
+ onToolResult: options.onToolResult,
248856
+ onReasoning: options.onReasoning
248612
248857
  }, { env: env6 }));
248613
248858
  }
248614
248859
  const result3 = await (deps.runProcess ?? runProcess)(buildExternalCodingAgentCommand({ ...options, cwd: cwd2 }), { cwd: cwd2, env: env6, signal: options.signal });
@@ -249663,6 +249908,13 @@ class AppServerClient {
249663
249908
  predicate: (message2) => message2.type === "subagent_message_response"
249664
249909
  });
249665
249910
  }
249911
+ readSubagentEvents(command, options = {}) {
249912
+ const requestId = command.request_id ?? this.nextRequestId("read-subagent-events");
249913
+ return this.request({ ...command, type: "read_subagent_events", request_id: requestId }, {
249914
+ ...options,
249915
+ predicate: (message2) => message2.type === "read_subagent_events_response" && message2.request_id === requestId
249916
+ });
249917
+ }
249666
249918
  stopSubagent(command, options = {}) {
249667
249919
  return this.request({
249668
249920
  ...command,
@@ -250188,12 +250440,267 @@ var init_headless_listener_launch = __esm(() => {
250188
250440
  init_headless_environment_response();
250189
250441
  });
250190
250442
 
250443
+ // src/tools/impl/task-transcript.ts
250444
+ import { writeFileSync as writeFileSync30 } from "node:fs";
250445
+ function buildTaskResultHeader(subagentType, subagentId, result3, status) {
250446
+ return [
250447
+ `subagent_type=${subagentType}`,
250448
+ `subagent_id=${subagentId}`,
250449
+ status ? `subagent_status=${status}` : undefined,
250450
+ result3?.agentId ? `agent_id=${result3.agentId}` : undefined,
250451
+ result3?.conversationId ? `conversation_id=${result3.conversationId}` : undefined,
250452
+ result3?.runtimeSessionId ? `runtime_session_id=${result3.runtimeSessionId}` : undefined
250453
+ ].filter(Boolean).join(" ");
250454
+ }
250455
+ function writeTaskTranscriptStart(outputFile, description, subagentType) {
250456
+ appendToOutputFile(outputFile, `[Task started: ${description}]
250457
+ [subagent_type: ${subagentType}]
250458
+
250459
+ `);
250460
+ }
250461
+ function writeTaskTranscriptResult(outputFile, result3, header, reportAlreadyWritten = false) {
250462
+ if (result3.success) {
250463
+ const report = reportAlreadyWritten ? "" : `${result3.report}
250464
+
250465
+ `;
250466
+ appendToOutputFile(outputFile, `${header}
250467
+
250468
+ ${report}[Task completed]
250469
+ `);
250470
+ return;
250471
+ }
250472
+ appendToOutputFile(outputFile, `${header ? `${header}
250473
+
250474
+ ` : ""}[error] ${result3.error || "Subagent execution failed"}
250475
+
250476
+ [Task failed]
250477
+ `);
250478
+ }
250479
+ function taskEventsFileFor(outputFile) {
250480
+ return `${outputFile.replace(/\.(log|output)$/, "")}.jsonl`;
250481
+ }
250482
+ function appendProgress(log3, entry, at2) {
250483
+ if (log3.lines >= TASK_PROGRESS_MAX_LINES)
250484
+ return;
250485
+ log3.lines++;
250486
+ const line = log3.lines === TASK_PROGRESS_MAX_LINES ? `[progress log reached ${TASK_PROGRESS_MAX_LINES} lines; further progress omitted; every event is in ${log3.eventsFile}]` : `[${at2}] ${entry}`;
250487
+ appendToOutputFile(log3.outputFile, `${line}
250488
+ `);
250489
+ }
250490
+ function appendEvent(log3, record6) {
250491
+ if (log3.eventBytes >= TASK_EVENTS_MAX_BYTES)
250492
+ return;
250493
+ let json2 = JSON.stringify(record6);
250494
+ log3.eventBytes += json2.length + 1;
250495
+ if (log3.eventBytes >= TASK_EVENTS_MAX_BYTES) {
250496
+ json2 = JSON.stringify({ type: "status", status: "event_log_full" });
250497
+ }
250498
+ appendToOutputFile(log3.eventsFile, `${json2}
250499
+ `);
250500
+ }
250501
+ function formatBytes2(bytes) {
250502
+ if (bytes < 1024)
250503
+ return `${bytes} B`;
250504
+ if (bytes < 1024 * 1024)
250505
+ return `${(bytes / 1024).toFixed(1)} KB`;
250506
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
250507
+ }
250508
+ function errorLine(output) {
250509
+ const lines = output.split(`
250510
+ `).filter((line) => line.trim());
250511
+ const named = lines.find((line) => /\b(error|fail(ed|ure)?|exception|assert\w*|panic|traceback)\b/i.test(line));
250512
+ return excerptProgressText(named ?? lines.at(-1) ?? "", 200);
250513
+ }
250514
+ function readableLine(event) {
250515
+ switch (event.type) {
250516
+ case "tool_call": {
250517
+ const json2 = typeof event.input === "string" ? event.input : JSON.stringify(event.input) ?? "";
250518
+ const args = excerptProgressText(json2, TASK_PROGRESS_ARGS_CHARS);
250519
+ return `tool: ${event.name}${args ? ` ${args}` : ""}`;
250520
+ }
250521
+ case "tool_result": {
250522
+ const size2 = formatBytes2(Buffer.byteLength(event.output, "utf8"));
250523
+ const error5 = event.is_error ? errorLine(event.output) : "";
250524
+ return `result: ${event.name ?? "tool"} ${event.is_error ? "error" : "ok"}, ${size2}${error5 ? `: ${error5}` : ""}`;
250525
+ }
250526
+ case "text":
250527
+ return `text: ${excerptProgressText(event.text, TASK_PROGRESS_TEXT_CHARS)}`;
250528
+ case "reasoning":
250529
+ return null;
250530
+ case "notification": {
250531
+ const summary = /<summary>([\s\S]*?)<\/summary>/.exec(event.text)?.[1];
250532
+ return `notification: ${excerptProgressText(summary ?? event.text, 200)}`;
250533
+ }
250534
+ }
250535
+ }
250536
+ function openTaskProgressLog(subagentId, outputFile, parentAgentId, {
250537
+ now: now2 = () => new Date,
250538
+ redactions = captureSecretRedactions(parentAgentId)
250539
+ } = {}) {
250540
+ const eventsFile = taskEventsFileFor(outputFile);
250541
+ try {
250542
+ writeFileSync30(eventsFile, "", { mode: 384, flag: "a" });
250543
+ } catch {}
250544
+ progressLogs.set(subagentId, {
250545
+ outputFile,
250546
+ eventsFile,
250547
+ lines: 0,
250548
+ eventBytes: 0,
250549
+ seq: 0,
250550
+ seen: new Set,
250551
+ toolNames: new Map,
250552
+ now: now2,
250553
+ redactions,
250554
+ serve: false
250555
+ });
250556
+ }
250557
+ function serveTaskEvents(subagentId) {
250558
+ const log3 = progressLogs.get(subagentId);
250559
+ if (!log3)
250560
+ return;
250561
+ log3.serve = true;
250562
+ serveSubagentEvents(subagentId);
250563
+ updateSubagent(subagentId, { eventSeq: log3.seq });
250564
+ }
250565
+ function closeTaskProgressLog(subagentId) {
250566
+ progressLogs.delete(subagentId);
250567
+ }
250568
+ function isoOrUndefined(at2) {
250569
+ return at2 === undefined || Number.isNaN(Date.parse(at2)) ? undefined : new Date(at2).toISOString();
250570
+ }
250571
+ function recordTaskEvent(subagentId, event, options = {}) {
250572
+ const log3 = progressLogs.get(subagentId);
250573
+ if (!log3)
250574
+ return;
250575
+ event = scrubSecretsDeep(event, log3.redactions);
250576
+ const keys3 = [
250577
+ options.key,
250578
+ event.type === "tool_call" ? `call:${event.id}` : undefined,
250579
+ event.type === "tool_result" ? `result:${event.tool_call_id}` : undefined
250580
+ ].filter((value) => value !== undefined);
250581
+ if (keys3.some((value) => log3.seen.has(value)))
250582
+ return;
250583
+ const key4 = keys3[0];
250584
+ if (event.type === "tool_call") {
250585
+ log3.lastText = undefined;
250586
+ log3.toolNames.set(event.id, event.name);
250587
+ } else if (event.type === "tool_result") {
250588
+ event = {
250589
+ ...event,
250590
+ name: event.name ?? log3.toolNames.get(event.tool_call_id)
250591
+ };
250592
+ } else {
250593
+ if (!event.text.trim())
250594
+ return;
250595
+ if (event.type === "text") {
250596
+ if (key4 === undefined && event.text === log3.lastText)
250597
+ return;
250598
+ log3.lastText = event.text;
250599
+ }
250600
+ }
250601
+ for (const value of keys3)
250602
+ log3.seen.add(value);
250603
+ const at2 = isoOrUndefined(options.at) ?? log3.now().toISOString();
250604
+ const record6 = { seq: ++log3.seq, at: at2, ...event };
250605
+ appendEvent(log3, record6);
250606
+ const line = readableLine(event);
250607
+ if (line !== null)
250608
+ appendProgress(log3, line, at2);
250609
+ if (log3.serve) {
250610
+ storeSubagentEvent(subagentId, record6);
250611
+ updateSubagent(subagentId, { eventSeq: log3.seq });
250612
+ }
250613
+ }
250614
+ function recordRemoteTaskEvent(subagentId, { seq, at: at2, ...event }) {
250615
+ recordTaskEvent(subagentId, event, {
250616
+ at: at2,
250617
+ key: `remote:${seq}`
250618
+ });
250619
+ }
250620
+ function recordMissedRemoteEvents(subagentId, missed) {
250621
+ const log3 = progressLogs.get(subagentId);
250622
+ if (!log3 || missed <= 0)
250623
+ return;
250624
+ const at2 = log3.now().toISOString();
250625
+ appendEvent(log3, { seq: ++log3.seq, at: at2, type: "events_missed", missed });
250626
+ appendProgress(log3, `[${missed} earlier events were not received]`, at2);
250627
+ }
250628
+ function recordTaskProgressToolCall(subagentId, call2, at2) {
250629
+ const input = call2.input !== undefined ? call2.input : parseToolInput2(call2.args);
250630
+ recordTaskEvent(subagentId, { type: "tool_call", id: call2.id, name: call2.name, input }, { at: at2 });
250631
+ }
250632
+ function recordTaskProgressText(subagentId, text2) {
250633
+ recordTaskEvent(subagentId, { type: "text", text: text2 });
250634
+ }
250635
+ function recordTaskProgressRemoteText(subagentId, entry) {
250636
+ recordTaskEvent(subagentId, { type: "text", text: entry.text }, { at: entry.at, key: `text:${entry.id}` });
250637
+ }
250638
+ function externalWorkerProgressListeners(subagentId) {
250639
+ return {
250640
+ onToolCall: (call2) => {
250641
+ addToolCall(subagentId, call2.id, call2.name, call2.args);
250642
+ recordTaskProgressToolCall(subagentId, call2);
250643
+ },
250644
+ onText: (text2) => {
250645
+ addProgressText(subagentId, text2);
250646
+ recordTaskProgressText(subagentId, text2);
250647
+ },
250648
+ onToolResult: (result3) => recordTaskEvent(subagentId, {
250649
+ type: "tool_result",
250650
+ tool_call_id: result3.id,
250651
+ name: result3.name,
250652
+ is_error: result3.isError,
250653
+ output: result3.output
250654
+ }),
250655
+ onReasoning: (text2) => recordTaskEvent(subagentId, { type: "reasoning", text: text2 })
250656
+ };
250657
+ }
250658
+ var TASK_PROGRESS_TEXT_CHARS, TASK_PROGRESS_ARGS_CHARS = 200, TASK_PROGRESS_MAX_LINES = 1000, TASK_EVENTS_MAX_BYTES, progressLogs;
250659
+ var init_task_transcript = __esm(() => {
250660
+ init_subagent_events();
250661
+ init_subagent_state();
250662
+ init_secret_substitution();
250663
+ init_process_manager();
250664
+ TASK_PROGRESS_TEXT_CHARS = PROGRESS_TEXT_CHARS;
250665
+ TASK_EVENTS_MAX_BYTES = 256 * 1024 * 1024;
250666
+ progressLogs = new Map;
250667
+ });
250668
+
250191
250669
  // src/agent/subagents/subagent-stream.ts
250192
- function recordToolCall(subagentId, toolCallId, toolName2, toolArgs, displayedToolCalls) {
250670
+ function recordToolCall(subagentId, toolCallId, toolName2, toolArgs, displayedToolCalls, at2) {
250193
250671
  if (!toolCallId || !toolName2 || displayedToolCalls.has(toolCallId))
250194
250672
  return;
250195
250673
  displayedToolCalls.add(toolCallId);
250196
250674
  addToolCall(subagentId, toolCallId, toolName2, toolArgs);
250675
+ recordTaskProgressToolCall(subagentId, { id: toolCallId, name: toolName2, args: toolArgs }, at2);
250676
+ }
250677
+ function assistantChunkText(content) {
250678
+ if (typeof content === "string")
250679
+ return content;
250680
+ if (!Array.isArray(content))
250681
+ return "";
250682
+ return content.map((part) => part && typeof part === "object" && ("text" in part) ? String(part.text ?? "") : "").join("");
250683
+ }
250684
+ function flushPendingProgressText(state2, subagentId) {
250685
+ const pending2 = state2.pendingText;
250686
+ if (!pending2)
250687
+ return;
250688
+ state2.pendingText = undefined;
250689
+ recordTaskEvent(subagentId, { type: pending2.kind, text: pending2.text });
250690
+ }
250691
+ function handleTextChunk(event, state2, subagentId) {
250692
+ const kind = event.message_type === "reasoning_message" ? "reasoning" : "text";
250693
+ const id2 = event.id ?? event.otid ?? "";
250694
+ const text2 = kind === "reasoning" ? toolOutputText(event.reasoning) : assistantChunkText(event.content);
250695
+ const pending2 = state2.pendingText;
250696
+ if (pending2 && (pending2.id !== id2 || pending2.kind !== kind)) {
250697
+ flushPendingProgressText(state2, subagentId);
250698
+ }
250699
+ state2.pendingText = {
250700
+ id: id2,
250701
+ kind,
250702
+ text: (state2.pendingText?.text ?? "") + text2
250703
+ };
250197
250704
  }
250198
250705
  function handleInitEvent(event, state2, subagentId) {
250199
250706
  if (event.agent_id) {
@@ -250219,11 +250726,26 @@ function handleToolCallEvent(event, state2, subagentId) {
250219
250726
  for (const tc of toolCalls) {
250220
250727
  const { tool_call_id, name, arguments: toolArgs = "{}" } = tc;
250221
250728
  if (tool_call_id && name) {
250222
- recordToolCall(subagentId, tool_call_id, name, toolArgs, state2.displayedToolCalls);
250729
+ recordToolCall(subagentId, tool_call_id, name, toolArgs, state2.displayedToolCalls, typeof event.date === "string" ? event.date : undefined);
250223
250730
  }
250224
250731
  }
250225
250732
  }
250226
- function handleToolReturnEvent(event, state2) {
250733
+ function recordToolReturnProgress(event, subagentId) {
250734
+ const returns = Array.isArray(event.tool_returns) ? event.tool_returns : [event];
250735
+ for (const toolReturn of returns) {
250736
+ if (!toolReturn.tool_call_id)
250737
+ continue;
250738
+ const output = toolOutputText(toolReturn.tool_return) || [toolReturn.stdout, toolReturn.stderr].map(toolOutputText).filter(Boolean).join(`
250739
+ `);
250740
+ recordTaskEvent(subagentId, {
250741
+ type: "tool_result",
250742
+ tool_call_id: toolReturn.tool_call_id,
250743
+ is_error: toolReturn.status === "error",
250744
+ output
250745
+ }, { at: typeof event.date === "string" ? event.date : undefined });
250746
+ }
250747
+ }
250748
+ function handleToolReturnEvent(event, state2, subagentId) {
250227
250749
  const returns = Array.isArray(event.tool_returns) ? event.tool_returns : [event];
250228
250750
  for (const toolReturn of returns) {
250229
250751
  const toolCallId = toolReturn.tool_call_id;
@@ -250233,6 +250755,7 @@ function handleToolReturnEvent(event, state2) {
250233
250755
  state2.toolCallStatuses.set(toolCallId, toolReturn.status);
250234
250756
  }
250235
250757
  }
250758
+ recordToolReturnProgress(event, subagentId);
250236
250759
  }
250237
250760
  function isEnqueueReceipt(event) {
250238
250761
  return event.status === "queued" && (typeof event.agent_id === "string" || event.agent_id === null && typeof event.parent_agent_id === "string") && (event.parent_agent_id === undefined || typeof event.parent_agent_id === "string") && typeof event.conversation_id === "string" && typeof event.client_message_id === "string" && typeof event.super_run_id === "string" && typeof event.workflow_id === "string" && (event.acting_user_id === undefined || event.acting_user_id === null || typeof event.acting_user_id === "string");
@@ -250284,18 +250807,25 @@ function processStreamEvent(line, state2, subagentId) {
250284
250807
  }
250285
250808
  break;
250286
250809
  case "message":
250810
+ if (event.message_type === "assistant_message" || event.message_type === "reasoning_message") {
250811
+ handleTextChunk(event, state2, subagentId);
250812
+ } else if (event.message_type !== "usage_statistics") {
250813
+ flushPendingProgressText(state2, subagentId);
250814
+ }
250287
250815
  if (event.message_type === "tool_call_message") {
250288
250816
  handleToolCallEvent(event, state2, subagentId);
250289
250817
  }
250290
250818
  if (event.message_type === "tool_return_message") {
250291
- handleToolReturnEvent(event, state2);
250819
+ handleToolReturnEvent(event, state2, subagentId);
250292
250820
  }
250293
250821
  emitStreamEvent(subagentId, event);
250294
250822
  break;
250295
250823
  case "result":
250824
+ flushPendingProgressText(state2, subagentId);
250296
250825
  handleResultEvent(event, state2, subagentId);
250297
250826
  break;
250298
250827
  case "error":
250828
+ flushPendingProgressText(state2, subagentId);
250299
250829
  state2.finalError = event.error || event.message || "Unknown error";
250300
250830
  break;
250301
250831
  }
@@ -250371,11 +250901,41 @@ var STDERR_TAIL_CHARS = 2000;
250371
250901
  var init_subagent_stream = __esm(() => {
250372
250902
  init_subagent_state();
250373
250903
  init_app_urls();
250904
+ init_task_transcript();
250374
250905
  init_debug();
250375
250906
  });
250376
250907
 
250377
250908
  // src/agent/subagents/remote-turn-wait.ts
250378
- async function collectRemoteTurnResult(receipt, state2, subagentId, signal = new AbortController().signal) {
250909
+ function messageText(content) {
250910
+ if (typeof content === "string")
250911
+ return content;
250912
+ if (!Array.isArray(content))
250913
+ return "";
250914
+ return content.map((part) => part?.type === "text" ? String(part.text ?? "") : "").join("");
250915
+ }
250916
+ function recordRemoteRunProgress(messages, state2, subagentId) {
250917
+ for (const message2 of messages) {
250918
+ if (message2.message_type === "tool_call_message" || message2.message_type === "approval_request_message") {
250919
+ processStreamEvent(JSON.stringify({
250920
+ type: "message",
250921
+ ...message2,
250922
+ message_type: "tool_call_message"
250923
+ }), state2, subagentId);
250924
+ } else if (message2.message_type === "tool_return_message") {
250925
+ recordToolReturnProgress(message2, subagentId);
250926
+ } else if (message2.message_type === "reasoning_message") {
250927
+ recordTaskEvent(subagentId, { type: "reasoning", text: message2.reasoning }, { at: message2.date, key: `${message2.id}:reasoning` });
250928
+ } else if (message2.message_type === "user_message") {
250929
+ const text2 = messageText(message2.content);
250930
+ if (text2.includes("<task-notification>")) {
250931
+ recordTaskEvent(subagentId, { type: "notification", text: text2 }, { at: message2.date, key: `${message2.id}:notification` });
250932
+ }
250933
+ } else if (message2.message_type === "assistant_message") {
250934
+ recordTaskEvent(subagentId, { type: "text", text: messageText(message2.content) }, { at: message2.date, key: `${message2.id}:assistant` });
250935
+ }
250936
+ }
250937
+ }
250938
+ async function collectRemoteTurnResult(receipt, state2, subagentId, signal = new AbortController().signal, deps = {}) {
250379
250939
  const startedAt = Date.now();
250380
250940
  updateSubagent(subagentId, {
250381
250941
  agentId: receipt.agent_id ?? undefined,
@@ -250386,18 +250946,29 @@ async function collectRemoteTurnResult(receipt, state2, subagentId, signal = new
250386
250946
  });
250387
250947
  try {
250388
250948
  const backend3 = getBackend();
250949
+ const listMessages = deps.listMessages ?? listEnqueuedRunMessages;
250950
+ const finishedRuns = new Set;
250389
250951
  const reply = await waitForAcceptedSuperRun(receipt, signal, {
250390
- exact: getExactSuperRun,
250391
- run: (runId, readSignal) => backend3.retrieveRun(runId, { signal: readSignal }),
250952
+ exact: deps.exact ?? getExactSuperRun,
250953
+ run: deps.run ?? ((runId, readSignal) => backend3.retrieveRun(runId, { signal: readSignal })),
250392
250954
  messages: async (runId, readSignal) => {
250393
- const messages = await listEnqueuedRunMessages(runId, readSignal);
250394
- for (const message2 of messages) {
250395
- if (message2.message_type === "tool_call_message") {
250396
- processStreamEvent(JSON.stringify({ type: "message", ...message2 }), state2, subagentId);
250397
- }
250398
- }
250955
+ const messages = await listMessages(runId, readSignal);
250956
+ recordRemoteRunProgress(messages, state2, subagentId);
250399
250957
  return messages;
250400
- }
250958
+ },
250959
+ onProgress: async (runIds, readSignal) => {
250960
+ const [newest] = runIds;
250961
+ for (const runId of [...runIds].reverse()) {
250962
+ if (finishedRuns.has(runId))
250963
+ continue;
250964
+ recordRemoteRunProgress(await listMessages(runId, readSignal), state2, subagentId);
250965
+ if (runId !== newest)
250966
+ finishedRuns.add(runId);
250967
+ }
250968
+ },
250969
+ ...deps.pollMs !== undefined ? { pollMs: deps.pollMs } : {},
250970
+ ...deps.progressMs !== undefined ? { progressMs: deps.progressMs } : {},
250971
+ ...deps.sleep ? { sleep: deps.sleep } : {}
250401
250972
  });
250402
250973
  return {
250403
250974
  agentId: receipt.agent_id ?? "",
@@ -250430,6 +251001,7 @@ var init_remote_turn_wait = __esm(() => {
250430
251001
  init_constants2();
250431
251002
  init_headless_listener_launch();
250432
251003
  init_headless_super_run_wait();
251004
+ init_task_transcript();
250433
251005
  init_subagent_stream();
250434
251006
  });
250435
251007
 
@@ -250923,6 +251495,7 @@ async function executeSubagent(type3, config2, model, userPrompt, subagentId, is
250923
251495
  if (stdoutBuffer.length > 0) {
250924
251496
  processStreamEvent(stdoutBuffer, state2, subagentId);
250925
251497
  }
251498
+ flushPendingProgressText(state2, subagentId);
250926
251499
  if (runningProcess.wasAborted()) {
250927
251500
  return withModel({
250928
251501
  agentId: state2.agentId || "",
@@ -251611,110 +252184,63 @@ var init_memory_task_lifecycle = __esm(() => {
251611
252184
  init_process_manager();
251612
252185
  });
251613
252186
 
251614
- // src/tools/impl/task-transcript.ts
251615
- function buildTaskResultHeader(subagentType, subagentId, result3, status) {
251616
- return [
251617
- `subagent_type=${subagentType}`,
251618
- `subagent_id=${subagentId}`,
251619
- status ? `subagent_status=${status}` : undefined,
251620
- result3?.agentId ? `agent_id=${result3.agentId}` : undefined,
251621
- result3?.conversationId ? `conversation_id=${result3.conversationId}` : undefined,
251622
- result3?.runtimeSessionId ? `runtime_session_id=${result3.runtimeSessionId}` : undefined
251623
- ].filter(Boolean).join(" ");
251624
- }
251625
- function writeTaskTranscriptStart(outputFile, description, subagentType) {
251626
- appendToOutputFile(outputFile, `[Task started: ${description}]
251627
- [subagent_type: ${subagentType}]
251628
-
251629
- `);
251630
- }
251631
- function writeTaskTranscriptResult(outputFile, result3, header, reportAlreadyWritten = false) {
251632
- if (result3.success) {
251633
- const report = reportAlreadyWritten ? "" : `${result3.report}
251634
-
251635
- `;
251636
- appendToOutputFile(outputFile, `${header}
251637
-
251638
- ${report}[Task completed]
251639
- `);
251640
- return;
251641
- }
251642
- appendToOutputFile(outputFile, `${header ? `${header}
251643
-
251644
- ` : ""}[error] ${result3.error || "Subagent execution failed"}
251645
-
251646
- [Task failed]
251647
- `);
251648
- }
251649
- function appendProgress(log3, entry, at2) {
251650
- if (log3.lines >= TASK_PROGRESS_MAX_LINES)
251651
- return;
251652
- log3.lines++;
251653
- const line = log3.lines === TASK_PROGRESS_MAX_LINES ? `[progress log reached ${TASK_PROGRESS_MAX_LINES} lines; further progress omitted]` : `[${at2 ?? log3.now().toISOString()}] ${entry}`;
251654
- appendToOutputFile(log3.outputFile, `${line}
251655
- `);
251656
- }
251657
- function openTaskProgressLog(subagentId, outputFile, now2 = () => new Date) {
251658
- progressLogs.set(subagentId, {
251659
- outputFile,
251660
- lines: 0,
251661
- seenToolCallIds: new Set,
251662
- seenTextIds: new Set,
251663
- now: now2
251664
- });
251665
- }
251666
- function closeTaskProgressLog(subagentId) {
251667
- progressLogs.delete(subagentId);
251668
- }
251669
- function recordTaskProgressToolCall(subagentId, call2) {
251670
- const log3 = progressLogs.get(subagentId);
251671
- if (!log3 || log3.seenToolCallIds.has(call2.id))
251672
- return;
251673
- log3.seenToolCallIds.add(call2.id);
251674
- log3.lastText = undefined;
251675
- const args = excerptProgressText(call2.args, TASK_PROGRESS_ARGS_CHARS);
251676
- appendProgress(log3, `tool: ${call2.name}${args ? ` ${args}` : ""}`);
251677
- }
251678
- function recordTaskProgressText(subagentId, text2) {
251679
- const log3 = progressLogs.get(subagentId);
251680
- if (!log3)
251681
- return;
251682
- const line = excerptProgressText(text2, TASK_PROGRESS_TEXT_CHARS);
251683
- if (!line || line === log3.lastText)
251684
- return;
251685
- log3.lastText = line;
251686
- appendProgress(log3, `text: ${line}`);
251687
- }
251688
- function recordTaskProgressRemoteText(subagentId, entry) {
251689
- const log3 = progressLogs.get(subagentId);
251690
- if (!log3 || log3.seenTextIds.has(entry.id))
251691
- return;
251692
- log3.seenTextIds.add(entry.id);
251693
- const line = excerptProgressText(entry.text, TASK_PROGRESS_TEXT_CHARS);
251694
- if (!line)
251695
- return;
251696
- log3.lastText = line;
251697
- const at2 = Number.isNaN(Date.parse(entry.at)) ? undefined : new Date(entry.at).toISOString();
251698
- appendProgress(log3, `text: ${line}`, at2);
251699
- }
251700
- function externalWorkerProgressListeners(subagentId) {
251701
- return {
251702
- onToolCall: (call2) => {
251703
- addToolCall(subagentId, call2.id, call2.name, call2.args);
252187
+ // src/tools/impl/remote-subagent-events.ts
252188
+ function followRemoteSubagentEvents(subagentId, read2) {
252189
+ let cursor = 0;
252190
+ let requested = 0;
252191
+ let failures = 0;
252192
+ let draining = Promise.resolve();
252193
+ const pull2 = (target2) => {
252194
+ requested = target2;
252195
+ draining = draining.then(async () => {
252196
+ try {
252197
+ while (cursor < requested) {
252198
+ const page = await read2(cursor);
252199
+ recordMissedRemoteEvents(subagentId, page.missed);
252200
+ for (const event of page.events)
252201
+ recordRemoteTaskEvent(subagentId, event);
252202
+ if (page.next_seq <= cursor)
252203
+ break;
252204
+ cursor = page.next_seq;
252205
+ }
252206
+ failures = 0;
252207
+ } catch {
252208
+ failures++;
252209
+ requested = cursor;
252210
+ }
252211
+ });
252212
+ };
252213
+ const recordSnapshot = (snapshot2) => {
252214
+ if (typeof snapshot2.event_seq === "number" && failures < 2) {
252215
+ if (snapshot2.event_seq > requested)
252216
+ pull2(snapshot2.event_seq);
252217
+ return;
252218
+ }
252219
+ for (const call2 of snapshot2.tool_calls ?? [])
251704
252220
  recordTaskProgressToolCall(subagentId, call2);
251705
- },
251706
- onText: (text2) => {
251707
- addProgressText(subagentId, text2);
251708
- recordTaskProgressText(subagentId, text2);
252221
+ for (const entry of snapshot2.progress_texts ?? []) {
252222
+ if (typeof entry?.id === "string" && typeof entry.text === "string")
252223
+ recordTaskProgressRemoteText(subagentId, {
252224
+ id: entry.id,
252225
+ at: typeof entry.at === "string" ? entry.at : "",
252226
+ text: entry.text
252227
+ });
252228
+ }
252229
+ };
252230
+ return {
252231
+ recordSnapshot,
252232
+ async finish(final) {
252233
+ recordSnapshot(final);
252234
+ await draining;
252235
+ if (failures > 0 && cursor < (final.event_seq ?? 0)) {
252236
+ failures = 2;
252237
+ recordSnapshot(final);
252238
+ }
251709
252239
  }
251710
252240
  };
251711
252241
  }
251712
- var TASK_PROGRESS_TEXT_CHARS, TASK_PROGRESS_ARGS_CHARS = 200, TASK_PROGRESS_MAX_LINES = 1000, progressLogs;
251713
- var init_task_transcript = __esm(() => {
251714
- init_subagent_state();
251715
- init_process_manager();
251716
- TASK_PROGRESS_TEXT_CHARS = PROGRESS_TEXT_CHARS;
251717
- progressLogs = new Map;
252242
+ var init_remote_subagent_events = __esm(() => {
252243
+ init_task_transcript();
251718
252244
  });
251719
252245
 
251720
252246
  // src/tools/impl/remote-external-coding-agent.ts
@@ -251822,6 +252348,22 @@ class RemoteSubagentFollower {
251822
252348
  markLaunched() {
251823
252349
  this.launched = true;
251824
252350
  }
252351
+ async readEvents(afterSeq) {
252352
+ const subagentId = this.latest?.subagent_id;
252353
+ if (!this.client || this.disconnected || !subagentId)
252354
+ throw new Error("Not connected");
252355
+ const page = await this.client.readSubagentEvents({
252356
+ runtime: {
252357
+ agent_id: this.scope.agentId,
252358
+ conversation_id: this.scope.conversationId
252359
+ },
252360
+ subagent_id: subagentId,
252361
+ after_seq: afterSeq
252362
+ });
252363
+ if (!page.success)
252364
+ throw new Error(page.error);
252365
+ return page;
252366
+ }
251825
252367
  latestAgentId() {
251826
252368
  return this.latest?.agent_id ?? undefined;
251827
252369
  }
@@ -251991,28 +252533,16 @@ async function launchRemoteExternalCodingAgent(params, deps) {
251991
252533
  spawnSubagentImpl: async (_type, _prompt, model, subagentId2, signal) => {
251992
252534
  const startedAt = Date.now();
251993
252535
  updateSubagent(subagentId2, { status: "running" });
251994
- const recordProgress = (snapshot2) => {
251995
- for (const call2 of snapshot2.tool_calls ?? [])
251996
- recordTaskProgressToolCall(subagentId2, call2);
251997
- const texts = Array.isArray(snapshot2.progress_texts) ? snapshot2.progress_texts : [];
251998
- for (const entry of texts) {
251999
- if (typeof entry?.id === "string" && typeof entry.text === "string")
252000
- recordTaskProgressRemoteText(subagentId2, {
252001
- id: entry.id,
252002
- at: typeof entry.at === "string" ? entry.at : "",
252003
- text: entry.text
252004
- });
252005
- }
252006
- };
252536
+ const progress = followRemoteSubagentEvents(subagentId2, (afterSeq) => follower.readEvents(afterSeq));
252007
252537
  try {
252008
252538
  const final = await follower.waitForTerminal(signal, (snapshot2) => {
252009
252539
  updateSubagent(subagentId2, {
252010
252540
  toolCalls: snapshot2.tool_calls,
252011
252541
  totalTokens: snapshot2.total_tokens
252012
252542
  });
252013
- recordProgress(snapshot2);
252543
+ progress.recordSnapshot(snapshot2);
252014
252544
  });
252015
- recordProgress(final);
252545
+ await progress.finish(final);
252016
252546
  return {
252017
252547
  agentId: workerAgentId(),
252018
252548
  model: final.model ?? model,
@@ -252184,7 +252714,7 @@ var init_remote_external_coding_agent = __esm(() => {
252184
252714
  init_headless_environment_response();
252185
252715
  init_headless_listener_launch();
252186
252716
  init_external_coding_agent();
252187
- init_task_transcript();
252717
+ init_remote_subagent_events();
252188
252718
  REMOTE_EXTERNAL_WORKER_STOPPED = Symbol("remote external worker stopped");
252189
252719
  DISPLAY_NAMES = {
252190
252720
  "claude-code": "Claude Code",
@@ -252508,7 +253038,9 @@ function spawnBackgroundSubagentTask(args) {
252508
253038
  backgroundTasks.set(taskId, bgTask);
252509
253039
  registerSubagentAbortHook(subagentId, buildBackgroundTaskAbortHook(taskId, abortController));
252510
253040
  writeTaskTranscriptStart(outputFile, description, subagentType);
252511
- openTaskProgressLog(subagentId, outputFile);
253041
+ openTaskProgressLog(subagentId, outputFile, resolvedParentScope?.agentId);
253042
+ if (publishResult)
253043
+ serveTaskEvents(subagentId);
252512
253044
  const parentAgentIdForSpawn = resolvedParentScope?.agentId;
252513
253045
  const workerMemoryDir = subagentType === "memory" && resolvedParentScope ? memoryScope?.primaryRoot ?? getScopedMemoryFilesystemRoot(resolvedParentScope.agentId) : undefined;
252514
253046
  const effectiveMemoryScope = memoryScope ?? (workerMemoryDir ? { primaryRoot: workerMemoryDir, writableRoots: [workerMemoryDir] } : undefined);
@@ -252951,8 +253483,9 @@ Agent ID: ${result3.agent_id}` : "";
252951
253483
  Conversation ID: ${result3.conversation_id}` : "";
252952
253484
  return `Task running in background with task ID: ${result3.task_id}${agentIdLine}${conversationIdLine}
252953
253485
  Output file: ${result3.output_file}
253486
+ Event log: ${taskEventsFileFor(result3.output_file)}
252954
253487
 
252955
- You will be notified automatically when this task completes — a <task-notification> message will be delivered with the result. No need to poll, sleep-wait, or check the output file. Just continue with your current work.`;
253488
+ You will be notified automatically when this task completes — a <task-notification> message will be delivered with the result. No need to poll or sleep-wait; continue with your current work. To see what it is doing meanwhile, Read the output file: one line per tool call, tool result, and message, live. For exact details (full tool arguments and outputs, such as a command's error), read the event log.`;
252956
253489
  }
252957
253490
  var VALID_DEPLOY_TYPES;
252958
253491
  var init_task = __esm(async () => {
@@ -257660,10 +258193,10 @@ var init_rename_sync_with_retry = () => {};
257660
258193
 
257661
258194
  // src/websocket/listener/interrupted-turn-storage.ts
257662
258195
  import { createHash as createHash11 } from "node:crypto";
257663
- import { closeSync as closeSync8, fsyncSync as fsyncSync4, openSync as openSync8, writeFileSync as writeFileSync30 } from "node:fs";
258196
+ import { closeSync as closeSync8, fsyncSync as fsyncSync4, openSync as openSync8, writeFileSync as writeFileSync31 } from "node:fs";
257664
258197
  import { join as join73 } from "node:path";
257665
258198
  function writeInterruptedTurnRecordFile(temporary, destination, directory, record6, syncDirectory) {
257666
- writeFileSync30(temporary, JSON.stringify(record6), {
258199
+ writeFileSync31(temporary, JSON.stringify(record6), {
257667
258200
  mode: 384,
257668
258201
  flush: true
257669
258202
  });
@@ -257764,7 +258297,7 @@ import {
257764
258297
  readFileSync as readFileSync40,
257765
258298
  rmSync as rmSync19,
257766
258299
  statSync as statSync20,
257767
- writeFileSync as writeFileSync31
258300
+ writeFileSync as writeFileSync32
257768
258301
  } from "node:fs";
257769
258302
  import { join as join74 } from "node:path";
257770
258303
  function createRecoveryLineageSidecarAccess(params) {
@@ -257798,7 +258331,7 @@ function createRecoveryLineageSidecarAccess(params) {
257798
258331
  const destination = path33(sidecar.agentId, sidecar.conversationId, sidecar.lineageId);
257799
258332
  const temporary = `${destination}.${process.pid}.${sidecarWriterInstanceId}.${randomUUID46()}.tmp`;
257800
258333
  try {
257801
- writeFileSync31(temporary, JSON.stringify(sidecar), {
258334
+ writeFileSync32(temporary, JSON.stringify(sidecar), {
257802
258335
  mode: 384,
257803
258336
  flush: true
257804
258337
  });
@@ -258148,7 +258681,7 @@ import {
258148
258681
  readFileSync as readFileSync41,
258149
258682
  rmSync as rmSync20,
258150
258683
  unlinkSync as unlinkSync12,
258151
- writeFileSync as writeFileSync32
258684
+ writeFileSync as writeFileSync33
258152
258685
  } from "node:fs";
258153
258686
  import { join as join75 } from "node:path";
258154
258687
  function createInterruptedTurnStore(directory = defaultInterruptedTurnDirectory(), dependencies4 = {}) {
@@ -258524,7 +259057,7 @@ function createInterruptedTurnStore(directory = defaultInterruptedTurnDirectory(
258524
259057
  sync(directory);
258525
259058
  } catch (error5) {
258526
259059
  try {
258527
- writeFileSync32(destination, evidence, {
259060
+ writeFileSync33(destination, evidence, {
258528
259061
  mode: 384,
258529
259062
  flush: true
258530
259063
  });
@@ -258584,7 +259117,7 @@ function createInterruptedTurnStore(directory = defaultInterruptedTurnDirectory(
258584
259117
  sync(directory);
258585
259118
  } catch (error5) {
258586
259119
  try {
258587
- writeFileSync32(destination, evidence, { mode: 384, flush: true });
259120
+ writeFileSync33(destination, evidence, { mode: 384, flush: true });
258588
259121
  sync(directory);
258589
259122
  } catch {}
258590
259123
  throw error5;
@@ -260600,7 +261133,7 @@ import {
260600
261133
  readFileSync as readFileSync42,
260601
261134
  statSync as statSync21,
260602
261135
  unlinkSync as unlinkSync13,
260603
- writeFileSync as writeFileSync33
261136
+ writeFileSync as writeFileSync34
260604
261137
  } from "node:fs";
260605
261138
  import { dirname as dirname33 } from "node:path";
260606
261139
  function ordinaryInputIdentity(clientMessageId) {
@@ -260757,7 +261290,7 @@ function writeDurableStore(path33, store3) {
260757
261290
  }
260758
261291
  const temporaryPath = `${path33}.${process.pid}.${randomUUID48()}.tmp`;
260759
261292
  try {
260760
- writeFileSync33(temporaryPath, serialized, { mode: 384, flag: "wx" });
261293
+ writeFileSync34(temporaryPath, serialized, { mode: 384, flag: "wx" });
260761
261294
  const fd = openSync9(temporaryPath, "r+");
260762
261295
  try {
260763
261296
  fsyncSync5(fd);
@@ -261192,7 +261725,7 @@ import {
261192
261725
  readdirSync as readdirSync20,
261193
261726
  readFileSync as readFileSync43,
261194
261727
  rmSync as rmSync21,
261195
- writeFileSync as writeFileSync34
261728
+ writeFileSync as writeFileSync35
261196
261729
  } from "node:fs";
261197
261730
  import { join as join77 } from "node:path";
261198
261731
  function terminalAuthorityStatus(runtime, terminal, terminals, interruptedStore = createInterruptedTurnStore()) {
@@ -261281,7 +261814,7 @@ function createTurnFinishedStore(directory = defaultTurnFinishedDirectory(), opt
261281
261814
  const destination = path33(record6.agentId, record6.conversationId);
261282
261815
  const temporary = `${destination}.${randomUUID49()}.tmp`;
261283
261816
  try {
261284
- writeFileSync34(temporary, JSON.stringify(record6), {
261817
+ writeFileSync35(temporary, JSON.stringify(record6), {
261285
261818
  mode: 384,
261286
261819
  flush: true
261287
261820
  });
@@ -268419,6 +268952,12 @@ function isSubagentMessageCommand(value) {
268419
268952
  function isSubagentStopCommand(value) {
268420
268953
  return hasValidControlBase(value) && value.type === "subagent_stop";
268421
268954
  }
268955
+ function isReadSubagentEventsCommand(value) {
268956
+ if (!value || typeof value !== "object")
268957
+ return false;
268958
+ const c = value;
268959
+ return c.type === "read_subagent_events" && typeof c.request_id === "string" && c.request_id.trim().length > 0 && isAgentRuntimeScope(c.runtime) && c.runtime.agent_id.trim().length > 0 && c.runtime.conversation_id.trim().length > 0 && typeof c.subagent_id === "string" && c.subagent_id.trim().length > 0 && typeof c.after_seq === "number" && Number.isSafeInteger(c.after_seq) && c.after_seq >= 0 && (c.max_bytes === undefined || typeof c.max_bytes === "number" && Number.isSafeInteger(c.max_bytes) && c.max_bytes > 0);
268960
+ }
268422
268961
  var ARGUMENTS;
268423
268962
  var init_subagent_protocol_inbound = __esm(() => {
268424
268963
  ARGUMENTS = new Set([
@@ -268462,7 +269001,7 @@ var init_browser_device_mcp_oauth_protocol_inbound = __esm(() => {
268462
269001
 
268463
269002
  // src/websocket/listener/task-control-protocol-inbound.ts
268464
269003
  function isTaskControlProtocolCommand(value) {
268465
- return isBrowserDeviceMcpOAuthProtocolCommand(value) || isExecuteCommandCommand(value) || isRemoveQueueItemCommand(value) || isMonitorStopCommand(value) || isSubagentMessageCommand(value) || isSubagentStopCommand(value);
269004
+ return isBrowserDeviceMcpOAuthProtocolCommand(value) || isExecuteCommandCommand(value) || isRemoveQueueItemCommand(value) || isMonitorStopCommand(value) || isSubagentMessageCommand(value) || isSubagentStopCommand(value) || isReadSubagentEventsCommand(value);
268466
269005
  }
268467
269006
  function isExecuteCommandCommand(value) {
268468
269007
  if (!value || typeof value !== "object")
@@ -270705,7 +271244,7 @@ __export(exports_remote_model_catalog, {
270705
271244
  applyCatalogModels: () => applyCatalogModels,
270706
271245
  __testResetRemoteModelCatalog: () => __testResetRemoteModelCatalog
270707
271246
  });
270708
- import { existsSync as existsSync53, mkdirSync as mkdirSync41, readFileSync as readFileSync45, writeFileSync as writeFileSync35 } from "node:fs";
271247
+ import { existsSync as existsSync53, mkdirSync as mkdirSync41, readFileSync as readFileSync45, writeFileSync as writeFileSync36 } from "node:fs";
270709
271248
  import { dirname as dirname34, join as join80 } from "node:path";
270710
271249
  function catalogCachePath() {
270711
271250
  const dir = process.env.LETTA_MODEL_CATALOG_CACHE_DIR || join80(resolveGlobalConfigDir(), "cache");
@@ -270793,7 +271332,7 @@ function persistCatalogCache(entries2, source) {
270793
271332
  try {
270794
271333
  const path34 = catalogCachePath();
270795
271334
  mkdirSync41(dirname34(path34), { recursive: true });
270796
- writeFileSync35(path34, JSON.stringify({
271335
+ writeFileSync36(path34, JSON.stringify({
270797
271336
  schemaVersion: CACHE_SCHEMA_VERSION,
270798
271337
  source,
270799
271338
  fetchedAt: Date.now(),
@@ -271536,7 +272075,7 @@ var init_paths2 = __esm(() => {
271536
272075
  });
271537
272076
 
271538
272077
  // src/mods/mod-diagnostics-file.ts
271539
- import { mkdirSync as mkdirSync42, writeFileSync as writeFileSync36 } from "node:fs";
272078
+ import { mkdirSync as mkdirSync42, writeFileSync as writeFileSync37 } from "node:fs";
271540
272079
  import { homedir as homedir21 } from "node:os";
271541
272080
  import path35 from "node:path";
271542
272081
  function getDefaultModDiagnosticsRoot(homeDirectory = homedir21()) {
@@ -271555,7 +272094,7 @@ function writeModDiagnosticsLatestFile(diagnostics2, options = {}) {
271555
272094
  const file = createModDiagnosticsFile(diagnostics2, options.generatedAt);
271556
272095
  const filePath = getModDiagnosticsLatestFilePath(options.rootDirectory);
271557
272096
  mkdirSync42(path35.dirname(filePath), { recursive: true });
271558
- writeFileSync36(filePath, `${JSON.stringify(file, null, 2)}
272097
+ writeFileSync37(filePath, `${JSON.stringify(file, null, 2)}
271559
272098
  `, "utf-8");
271560
272099
  return file;
271561
272100
  }
@@ -378728,14 +379267,14 @@ ${lanes.join(`
378728
379267
  }
378729
379268
  if (diagnostic.relatedInformation) {
378730
379269
  output += host.getNewLine();
378731
- for (const { file, start: start2, length: length2, messageText } of diagnostic.relatedInformation) {
379270
+ for (const { file, start: start2, length: length2, messageText: messageText2 } of diagnostic.relatedInformation) {
378732
379271
  if (file) {
378733
379272
  output += host.getNewLine();
378734
379273
  output += halfIndent + formatLocation(file, start2, host);
378735
379274
  output += formatCodeSpan(file, start2, length2, indent, "\x1B[96m", host);
378736
379275
  }
378737
379276
  output += host.getNewLine();
378738
- output += indent + flattenDiagnosticMessageText(messageText, host.getNewLine());
379277
+ output += indent + flattenDiagnosticMessageText(messageText2, host.getNewLine());
378739
379278
  }
378740
379279
  }
378741
379280
  output += host.getNewLine();
@@ -407507,8 +408046,8 @@ ${newComment.split(`
407507
408046
  }
407508
408047
  }
407509
408048
  }
407510
- function tryGetConstraintFromDiagnosticMessage(messageText) {
407511
- const [, constraint] = flattenDiagnosticMessageText(messageText, `
408049
+ function tryGetConstraintFromDiagnosticMessage(messageText2) {
408050
+ const [, constraint] = flattenDiagnosticMessageText(messageText2, `
407512
408051
  `, 0).match(/`extends (.*)`/) || [];
407513
408052
  return constraint;
407514
408053
  }
@@ -409162,8 +409701,8 @@ ${newComment.split(`
409162
409701
  const operator = expression.operatorToken.kind;
409163
409702
  changes.replaceNode(sourceFile, expression, operator === 38 || operator === 36 ? factory.createPrefixUnaryExpression(54, callExpression) : callExpression);
409164
409703
  }
409165
- function getSuggestion(messageText) {
409166
- const [, suggestion] = flattenDiagnosticMessageText(messageText, `
409704
+ function getSuggestion(messageText2) {
409705
+ const [, suggestion] = flattenDiagnosticMessageText(messageText2, `
409167
409706
  `, 0).match(/'(.*)'/) || [];
409168
409707
  return suggestion;
409169
409708
  }
@@ -440587,7 +441126,7 @@ import {
440587
441126
  mkdirSync as mkdirSync43,
440588
441127
  readFileSync as readFileSync47,
440589
441128
  rmSync as rmSync22,
440590
- writeFileSync as writeFileSync37
441129
+ writeFileSync as writeFileSync38
440591
441130
  } from "node:fs";
440592
441131
  import path37 from "node:path";
440593
441132
  function isRecord16(value) {
@@ -441082,7 +441621,7 @@ function findPackageIndex(modsRoot, packagesValue, specifier) {
441082
441621
  }
441083
441622
  function writePackageRegistry(registryPath, registry4) {
441084
441623
  mkdirSync43(path37.dirname(registryPath), { recursive: true });
441085
- writeFileSync37(registryPath, `${JSON.stringify(registry4, null, 2)}
441624
+ writeFileSync38(registryPath, `${JSON.stringify(registry4, null, 2)}
441086
441625
  `);
441087
441626
  }
441088
441627
  function validateManagedModPackageRegistryForMutation(modsRoot) {
@@ -441414,7 +441953,7 @@ import {
441414
441953
  readFileSync as readFileSync48,
441415
441954
  statSync as statSync23,
441416
441955
  unlinkSync as unlinkSync16,
441417
- writeFileSync as writeFileSync38
441956
+ writeFileSync as writeFileSync39
441418
441957
  } from "node:fs";
441419
441958
  import { createRequire as createRequire7 } from "node:module";
441420
441959
  import path40 from "node:path";
@@ -441599,7 +442138,7 @@ function createImportableModPath(modPath, cacheDirectory, source) {
441599
442138
  const baseName = path40.basename(modPath, fileExtension).replace(/[^a-zA-Z0-9_-]/g, "-");
441600
442139
  const importPath = path40.join(importCacheDirectory, `.letta-mod-${baseName}-${hash3}.mjs`);
441601
442140
  if (!existsSync57(importPath)) {
441602
- writeFileSync38(importPath, importableSource, "utf8");
442141
+ writeFileSync39(importPath, importableSource, "utf8");
441603
442142
  }
441604
442143
  try {
441605
442144
  for (const entry of readdirSync24(importCacheDirectory)) {
@@ -448146,7 +448685,7 @@ import {
448146
448685
  mkdirSync as mkdirSync47,
448147
448686
  readdirSync as readdirSync25,
448148
448687
  unlinkSync as unlinkSync17,
448149
- writeFileSync as writeFileSync39
448688
+ writeFileSync as writeFileSync40
448150
448689
  } from "node:fs";
448151
448690
  import { join as join82 } from "node:path";
448152
448691
  function truncateStr(value, maxLen) {
@@ -448257,7 +448796,7 @@ class ChunkLog {
448257
448796
  try {
448258
448797
  const content = this.buffer.map((entry) => JSON.stringify(entry)).join(`
448259
448798
  `);
448260
- writeFileSync39(this.logPath, `${content}
448799
+ writeFileSync40(this.logPath, `${content}
448261
448800
  `, "utf8");
448262
448801
  } catch (e2) {
448263
448802
  debugWarn("chunkLog", `Failed to write ${this.logPath}: ${e2 instanceof Error ? e2.message : String(e2)}`);
@@ -466980,6 +467519,35 @@ var init_subagent_control = __esm(async () => {
466980
467519
  responses = new Map;
466981
467520
  });
466982
467521
 
467522
+ // src/websocket/listener/commands/subagent-events.ts
467523
+ function handleReadSubagentEventsCommand(command) {
467524
+ const base2 = {
467525
+ type: "read_subagent_events_response",
467526
+ request_id: command.request_id,
467527
+ runtime: command.runtime,
467528
+ subagent_id: command.subagent_id
467529
+ };
467530
+ const subagent = getSubagents().find((entry) => entry.id === command.subagent_id);
467531
+ if (!subagent || subagent.parentAgentId !== command.runtime.agent_id || (subagent.parentConversationId ?? "default") !== command.runtime.conversation_id)
467532
+ return {
467533
+ ...base2,
467534
+ success: false,
467535
+ error: "Subagent does not belong to this conversation"
467536
+ };
467537
+ const page = readSubagentEvents(command.subagent_id, command.after_seq, command.max_bytes);
467538
+ if (!page)
467539
+ return {
467540
+ ...base2,
467541
+ success: false,
467542
+ error: "This subagent's events are not kept on this computer"
467543
+ };
467544
+ return { ...base2, success: true, ...page };
467545
+ }
467546
+ var init_subagent_events2 = __esm(() => {
467547
+ init_subagent_events();
467548
+ init_subagent_state();
467549
+ });
467550
+
466983
467551
  // src/websocket/listener/commands/subagents.ts
466984
467552
  async function handleLaunchSubagentCommand(command, parent, connectionId, launch = launchSubagent, startupTimeoutMs2 = 25000) {
466985
467553
  const response = {
@@ -467068,6 +467636,11 @@ async function handleTaskControlCommand(command, context3) {
467068
467636
  safeSocketSend(socket, response2, response2.type, command.type);
467069
467637
  return;
467070
467638
  }
467639
+ if (command.type === "read_subagent_events") {
467640
+ const response2 = handleReadSubagentEventsCommand(command);
467641
+ safeSocketSend(socket, response2, response2.type, command.type);
467642
+ return;
467643
+ }
467071
467644
  const parent = getOrCreateScopedRuntime2(runtime, command.runtime.agent_id, command.runtime.conversation_id);
467072
467645
  const response = command.type === "launch_subagent" ? await handleLaunchSubagentCommand(command, parent, connectionId) : command.type === "subagent_message" ? await handleSubagentMessageCommand(command, parent) : await handleSubagentStopCommand(command, parent);
467073
467646
  safeSocketSend(socket, response, response.type, command.type);
@@ -467079,6 +467652,7 @@ async function handleTaskControlCommand(command, context3) {
467079
467652
  }
467080
467653
  }
467081
467654
  var init_task_control = __esm(async () => {
467655
+ init_subagent_events2();
467082
467656
  await __promiseAll([
467083
467657
  init_monitors(),
467084
467658
  init_subagent_control(),
@@ -467155,7 +467729,7 @@ function createListenerMessageHandler(params) {
467155
467729
  handleTurnFinishedAck(runtime, socket, connectionId, parsed);
467156
467730
  return;
467157
467731
  }
467158
- if (parsed.type === "launch_subagent" || parsed.type === "monitor_stop" || parsed.type === "subagent_message" || parsed.type === "subagent_stop") {
467732
+ if (parsed.type === "launch_subagent" || parsed.type === "monitor_stop" || parsed.type === "subagent_message" || parsed.type === "subagent_stop" || parsed.type === "read_subagent_events") {
467159
467733
  const { handleTaskControlCommand: handleTaskControlCommand2 } = await init_task_control().then(() => exports_task_control);
467160
467734
  await handleTaskControlCommand2(parsed, {
467161
467735
  runtime,
@@ -473068,7 +473642,7 @@ import {
473068
473642
  mkdirSync as mkdirSync48,
473069
473643
  readdirSync as readdirSync27,
473070
473644
  readFileSync as readFileSync49,
473071
- writeFileSync as writeFileSync40
473645
+ writeFileSync as writeFileSync41
473072
473646
  } from "node:fs";
473073
473647
  import { join as join97 } from "node:path";
473074
473648
  function readJsonl(path47) {
@@ -473084,7 +473658,7 @@ function isPiLocalMessage(value) {
473084
473658
  return isRecord2(value) && typeof value.id === "string" && (value.role === "user" || value.role === "assistant" || value.role === "toolResult") && Object.hasOwn(value, "content");
473085
473659
  }
473086
473660
  function writeJsonl(path47, items3) {
473087
- writeFileSync40(path47, `${items3.map((item) => JSON.stringify(item)).join(`
473661
+ writeFileSync41(path47, `${items3.map((item) => JSON.stringify(item)).join(`
473088
473662
  `)}
473089
473663
  `);
473090
473664
  }
@@ -473385,7 +473959,7 @@ function migrateLocalBackendTranscripts(input) {
473385
473959
  result3.skipped.push({ conversationDir, reason: "empty" });
473386
473960
  if (!input.dryRun) {
473387
473961
  mkdirSync48(conversationDir, { recursive: true });
473388
- writeFileSync40(manifestPath, `${JSON.stringify(manifest({}), null, 2)}
473962
+ writeFileSync41(manifestPath, `${JSON.stringify(manifest({}), null, 2)}
473389
473963
  `);
473390
473964
  }
473391
473965
  continue;
@@ -473438,12 +474012,12 @@ function migrateLocalBackendTranscripts(input) {
473438
474012
  }
473439
474013
  }
473440
474014
  conversation.in_context_message_ids = remapped;
473441
- writeFileSync40(conversationPath, `${JSON.stringify(conversation, null, 2)}
474015
+ writeFileSync41(conversationPath, `${JSON.stringify(conversation, null, 2)}
473442
474016
  `);
473443
474017
  }
473444
474018
  } catch {}
473445
474019
  }
473446
- writeFileSync40(manifestPath, `${JSON.stringify(manifest({
474020
+ writeFileSync41(manifestPath, `${JSON.stringify(manifest({
473447
474021
  backupPath,
473448
474022
  migratedFrom: repairVersioned ? hasLegacyUiRows ? "versioned-pi-transcript-with-legacy-ui-message-rows" : "versioned-pi-ai-message-jsonl" : undefined
473449
474023
  }), null, 2)}
@@ -475284,7 +475858,7 @@ import {
475284
475858
  readFileSync as readFileSync51,
475285
475859
  renameSync as renameSync12,
475286
475860
  rmSync as rmSync24,
475287
- writeFileSync as writeFileSync41
475861
+ writeFileSync as writeFileSync42
475288
475862
  } from "node:fs";
475289
475863
  import { tmpdir as tmpdir14 } from "node:os";
475290
475864
  import path47 from "node:path";
@@ -475508,7 +476082,7 @@ function restoreRegistry(registryPath, previousContents) {
475508
476082
  return;
475509
476083
  }
475510
476084
  mkdirSync50(path47.dirname(registryPath), { recursive: true });
475511
- writeFileSync41(registryPath, previousContents);
476085
+ writeFileSync42(registryPath, previousContents);
475512
476086
  }
475513
476087
  function removeIfExists(targetPath) {
475514
476088
  if (!targetPath)
@@ -475629,7 +476203,7 @@ function getNpmInstallArgs(installSpec) {
475629
476203
  ];
475630
476204
  }
475631
476205
  function writeNpmInstallManifest(tempRoot) {
475632
- writeFileSync41(path47.join(tempRoot, "package.json"), `${JSON.stringify({
476206
+ writeFileSync42(path47.join(tempRoot, "package.json"), `${JSON.stringify({
475633
476207
  private: true,
475634
476208
  name: "letta-managed-mod-install"
475635
476209
  }, null, 2)}
@@ -475903,7 +476477,7 @@ function getPackageVersionForGitPackage(params) {
475903
476477
  }
475904
476478
  function writeCompatibilityPackageManifest(params) {
475905
476479
  const packageJsonPath = path47.join(params.packageDirectory, "package.json");
475906
- writeFileSync41(packageJsonPath, `${JSON.stringify({
476480
+ writeFileSync42(packageJsonPath, `${JSON.stringify({
475907
476481
  ...params.packageJson ?? {},
475908
476482
  name: params.packageName,
475909
476483
  version: params.version,
@@ -476141,7 +476715,7 @@ import {
476141
476715
  lstatSync as lstatSync5,
476142
476716
  mkdirSync as mkdirSync51,
476143
476717
  rmSync as rmSync25,
476144
- writeFileSync as writeFileSync42
476718
+ writeFileSync as writeFileSync43
476145
476719
  } from "node:fs";
476146
476720
  import path48 from "node:path";
476147
476721
  function assertValidPackageName(packageName) {
@@ -476244,10 +476818,10 @@ function scaffoldLocalModPackage(options) {
476244
476818
  try {
476245
476819
  mkdirSync51(targetModsDirectory, { recursive: true });
476246
476820
  copyFileSync5(sourceFile, targetModPath);
476247
- writeFileSync42(packageJsonPath, `${JSON.stringify(createPackageJson(packageName, manifestEntry), null, 2)}
476821
+ writeFileSync43(packageJsonPath, `${JSON.stringify(createPackageJson(packageName, manifestEntry), null, 2)}
476248
476822
  `);
476249
- writeFileSync42(readmePath, createReadme(packageName));
476250
- writeFileSync42(modGuidePath, createModGuide(packageName, manifestEntry));
476823
+ writeFileSync43(readmePath, createReadme(packageName));
476824
+ writeFileSync43(modGuidePath, createModGuide(packageName, manifestEntry));
476251
476825
  } catch (error5) {
476252
476826
  rmSync25(outputDirectory, { force: true, recursive: true });
476253
476827
  throw error5;
@@ -479638,7 +480212,7 @@ import {
479638
480212
  readFileSync as readFileSync52,
479639
480213
  rmSync as rmSync26,
479640
480214
  statSync as statSync27,
479641
- writeFileSync as writeFileSync43
480215
+ writeFileSync as writeFileSync44
479642
480216
  } from "node:fs";
479643
480217
  import { mkdir as mkdir16, readdir as readdir13 } from "node:fs/promises";
479644
480218
  import { tmpdir as tmpdir15 } from "node:os";
@@ -479979,7 +480553,7 @@ async function downloadDirectSkillFileSource(location, options = {}) {
479979
480553
  try {
479980
480554
  const sourceDir = join102(tmpDir, "skill");
479981
480555
  await mkdir16(sourceDir, { recursive: true });
479982
- writeFileSync43(join102(sourceDir, "SKILL.md"), skillText, "utf8");
480556
+ writeFileSync44(join102(sourceDir, "SKILL.md"), skillText, "utf8");
479983
480557
  return { tmpDir, sourceDir };
479984
480558
  } catch (error5) {
479985
480559
  rmSync26(tmpDir, { recursive: true, force: true });
@@ -480031,7 +480605,7 @@ async function downloadClawHubSkillSource(location) {
480031
480605
  if (!response.ok) {
480032
480606
  throw new Error(`ClawHub download failed for ${location.slug}@${version3}: ${response.status}`);
480033
480607
  }
480034
- writeFileSync43(zipPath, Buffer.from(await response.arrayBuffer()));
480608
+ writeFileSync44(zipPath, Buffer.from(await response.arrayBuffer()));
480035
480609
  const { stdout } = await execFile21("unzip", ["-Z1", zipPath], {
480036
480610
  timeout: 30000
480037
480611
  });
@@ -484429,7 +485003,7 @@ var init_message_channel_gateway_tool = __esm(() => {
484429
485003
  });
484430
485004
 
484431
485005
  // src/channels/custom/scaffolding.ts
484432
- import { existsSync as existsSync72, mkdirSync as mkdirSync52, rmSync as rmSync27, writeFileSync as writeFileSync44 } from "node:fs";
485006
+ import { existsSync as existsSync72, mkdirSync as mkdirSync52, rmSync as rmSync27, writeFileSync as writeFileSync45 } from "node:fs";
484433
485007
  function removeUserPlugin(channelId) {
484434
485008
  if (FIRST_PARTY_SET.has(channelId)) {
484435
485009
  return;
@@ -493670,7 +494244,7 @@ import {
493670
494244
  existsSync as existsSync75,
493671
494245
  mkdirSync as mkdirSync54,
493672
494246
  readFileSync as readFileSync54,
493673
- writeFileSync as writeFileSync46
494247
+ writeFileSync as writeFileSync47
493674
494248
  } from "node:fs";
493675
494249
  import { homedir as homedir34, platform as platform10 } from "node:os";
493676
494250
  import { dirname as dirname41, join as join110 } from "node:path";
@@ -493785,7 +494359,7 @@ function installKeybinding(keybindingsPath) {
493785
494359
  keybindings.push(SHIFT_ENTER_KEYBINDING);
493786
494360
  const newContent = `${JSON.stringify(keybindings, null, 2)}
493787
494361
  `;
493788
- writeFileSync46(keybindingsPath, newContent, { encoding: "utf-8" });
494362
+ writeFileSync47(keybindingsPath, newContent, { encoding: "utf-8" });
493789
494363
  return {
493790
494364
  success: true,
493791
494365
  backupPath: backupPath ?? undefined
@@ -493814,7 +494388,7 @@ function removeKeybinding(keybindingsPath) {
493814
494388
  const filtered = keybindings.filter((kb) => !(kb.key?.toLowerCase() === "shift+enter" && kb.command === "workbench.action.terminal.sendSequence" && kb.when?.includes("terminalFocus")));
493815
494389
  const newContent = `${JSON.stringify(filtered, null, 2)}
493816
494390
  `;
493817
- writeFileSync46(keybindingsPath, newContent, { encoding: "utf-8" });
494391
+ writeFileSync47(keybindingsPath, newContent, { encoding: "utf-8" });
493818
494392
  return { success: true };
493819
494393
  } catch (error5) {
493820
494394
  const message2 = error5 instanceof Error ? error5.message : String(error5);
@@ -494004,7 +494578,7 @@ function installWezTermDeleteFix() {
494004
494578
  if (!existsSync75(parentDir)) {
494005
494579
  mkdirSync54(parentDir, { recursive: true });
494006
494580
  }
494007
- writeFileSync46(configPath, content, { encoding: "utf-8" });
494581
+ writeFileSync47(configPath, content, { encoding: "utf-8" });
494008
494582
  return {
494009
494583
  success: true,
494010
494584
  backupPath: backupPath ?? undefined
@@ -504927,7 +505501,7 @@ import {
504927
505501
  mkdtempSync as mkdtempSync7,
504928
505502
  readFileSync as readFileSync55,
504929
505503
  rmSync as rmSync28,
504930
- writeFileSync as writeFileSync47
505504
+ writeFileSync as writeFileSync48
504931
505505
  } from "node:fs";
504932
505506
  import { tmpdir as tmpdir16 } from "node:os";
504933
505507
  import { dirname as dirname42, join as join112 } from "node:path";
@@ -505175,7 +505749,7 @@ function writeWorkflow(repoDir, workflowPath, content) {
505175
505749
  return false;
505176
505750
  }
505177
505751
  }
505178
- writeFileSync47(absolutePath, next, "utf8");
505752
+ writeFileSync48(absolutePath, next, "utf8");
505179
505753
  return true;
505180
505754
  }
505181
505755
  function getDefaultBaseBranch(repoDir) {
@@ -509059,7 +509633,7 @@ __export(exports_generate_memory_viewer, {
509059
509633
  generateAndOpenMemoryViewer: () => generateAndOpenMemoryViewer
509060
509634
  });
509061
509635
  import { execFile as execFileCb6 } from "node:child_process";
509062
- import { chmodSync as chmodSync11, existsSync as existsSync77, mkdirSync as mkdirSync56, writeFileSync as writeFileSync48 } from "node:fs";
509636
+ import { chmodSync as chmodSync11, existsSync as existsSync77, mkdirSync as mkdirSync56, writeFileSync as writeFileSync49 } from "node:fs";
509063
509637
  import { join as join113 } from "node:path";
509064
509638
  import { promisify as promisify21 } from "node:util";
509065
509639
  function messagesFromOverview(overview) {
@@ -509386,7 +509960,7 @@ async function generateAndOpenMemoryViewer(agentId, options) {
509386
509960
  chmodSync11(VIEWERS_DIR, 448);
509387
509961
  } catch {}
509388
509962
  const filePath = join113(VIEWERS_DIR, `memory-${encodeURIComponent(agentId)}.html`);
509389
- writeFileSync48(filePath, html5);
509963
+ writeFileSync49(filePath, html5);
509390
509964
  chmodSync11(filePath, 384);
509391
509965
  const skipOpen = Boolean(process.env.TMUX) || Boolean(process.env.SSH_CONNECTION) || Boolean(process.env.SSH_TTY);
509392
509966
  if (!skipOpen) {
@@ -510793,7 +511367,7 @@ function MessageSearch({
510793
511367
  children: visibleResults.map((msg, visibleIndex) => {
510794
511368
  const actualIndex = startIndex + visibleIndex;
510795
511369
  const isSelected = actualIndex === selectedIndex;
510796
- const messageText = getMessageText(msg);
511370
+ const messageText2 = getMessageText(msg);
510797
511371
  const msgWithDate = msg;
510798
511372
  const msgType = msg.message_type || "unknown";
510799
511373
  const agentIdFromMsg = msgWithDate.agent_id || "unknown";
@@ -510802,7 +511376,7 @@ function MessageSearch({
510802
511376
  const isAssistant = msgType === "assistant_message" || msgType === "reasoning_message";
510803
511377
  const emoji2 = isAssistant ? "\uD83D\uDC7E" : "\uD83D\uDC64";
510804
511378
  const availableWidth = Math.max(20, terminalWidth - 8);
510805
- const displayText = truncateText2(messageText.replace(/\n/g, " "), availableWidth);
511379
+ const displayText = truncateText2(messageText2.replace(/\n/g, " "), availableWidth);
510806
511380
  const idToShow = conversationIdFromMsg || agentIdFromMsg;
510807
511381
  const msgId = "message_id" in msg ? String(msg.message_id) : "result";
510808
511382
  const uniqueKey = `${msgId}-${actualIndex}`;
@@ -520081,7 +520655,7 @@ __export(exports_generate_diff_viewer, {
520081
520655
  generateAndOpenDiffViewer: () => generateAndOpenDiffViewer
520082
520656
  });
520083
520657
  import { execFile as execFileCb7 } from "node:child_process";
520084
- import { chmodSync as chmodSync12, existsSync as existsSync79, mkdirSync as mkdirSync57, writeFileSync as writeFileSync49 } from "node:fs";
520658
+ import { chmodSync as chmodSync12, existsSync as existsSync79, mkdirSync as mkdirSync57, writeFileSync as writeFileSync50 } from "node:fs";
520085
520659
  import { isAbsolute as isAbsolute28, join as join117, resolve as resolve43 } from "node:path";
520086
520660
  import { promisify as promisify22 } from "node:util";
520087
520661
  async function runGit8(cwd2, args) {
@@ -520312,7 +520886,7 @@ async function generateAndOpenDiffViewer(targetPath) {
520312
520886
  chmodSync12(VIEWERS_DIR2, 448);
520313
520887
  } catch {}
520314
520888
  const filePath = join117(VIEWERS_DIR2, `diff-${encodeURIComponent(worktreePath)}.html`);
520315
- writeFileSync49(filePath, html5);
520889
+ writeFileSync50(filePath, html5);
520316
520890
  chmodSync12(filePath, 384);
520317
520891
  const skipOpen = shouldSkipOpen();
520318
520892
  if (!skipOpen) {
@@ -527868,7 +528442,7 @@ async function runModLearningCandidate(params) {
527868
528442
  const evaluator = createModLearningEvaluator({ options, runDir });
527869
528443
  const evalMemoryDir = evaluator.artifactsDir;
527870
528444
  const maxScore = maxEvaluationScore(options.spec.evaluation, options.scenarioLimit);
527871
- const emitProgress = (phase, message2, extra = {}) => {
528445
+ const emitProgress2 = (phase, message2, extra = {}) => {
527872
528446
  options.onProgress?.({
527873
528447
  ...params.previousAttempts.length > 0 ? { attempts: [...params.previousAttempts] } : {},
527874
528448
  candidateCount: params.candidateCount,
@@ -527882,15 +528456,15 @@ async function runModLearningCandidate(params) {
527882
528456
  ...extra
527883
528457
  });
527884
528458
  };
527885
- emitProgress("preparing", params.candidateCount > 1 ? `Preparing optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Preparing mod learning run");
528459
+ emitProgress2("preparing", params.candidateCount > 1 ? `Preparing optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Preparing mod learning run");
527886
528460
  await mkdir20(candidateDir, { recursive: true });
527887
528461
  await writeJsonArtifact(path50.join(runDir, "env.snapshot.json"), options.spec);
527888
528462
  let generationResult = null;
527889
528463
  if (options.candidateSourcePath) {
527890
- emitProgress("generating", "Copying candidate mod");
528464
+ emitProgress2("generating", "Copying candidate mod");
527891
528465
  await copyFile2(path50.resolve(repoRoot, options.candidateSourcePath), candidatePath);
527892
528466
  } else if (!options.skipGeneration) {
527893
- emitProgress("generating", params.candidateCount > 1 ? `Generating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Generating candidate mod");
528467
+ emitProgress2("generating", params.candidateCount > 1 ? `Generating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Generating candidate mod");
527894
528468
  const promptHistory = {
527895
528469
  candidateCount: params.candidateCount,
527896
528470
  candidateIndex: params.candidateIndex,
@@ -527938,7 +528512,7 @@ async function runModLearningCandidate(params) {
527938
528512
  passed: false
527939
528513
  };
527940
528514
  if (candidateExists) {
527941
- emitProgress("evaluating", `${params.candidateCount > 1 ? `Evaluating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Evaluating candidate mod"} with ${evaluator.label}`);
528515
+ emitProgress2("evaluating", `${params.candidateCount > 1 ? `Evaluating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Evaluating candidate mod"} with ${evaluator.label}`);
527942
528516
  const evaluatorResult = await evaluator.evaluate({
527943
528517
  backend: options.backend,
527944
528518
  baseEnv: params.baseEnv,
@@ -527952,7 +528526,7 @@ async function runModLearningCandidate(params) {
527952
528526
  cliCommand: params.cliCommand,
527953
528527
  evalModel: options.evalModel,
527954
528528
  onScenarioProgress: (progress2) => {
527955
- emitProgress("evaluating", `${params.candidateCount > 1 ? `Evaluating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Evaluating candidate mod"}: scenario ${progress2.scenarioIndex}/${progress2.scenarioCount} ${progress2.scenarioName}`, {
528529
+ emitProgress2("evaluating", `${params.candidateCount > 1 ? `Evaluating optimization iteration ${params.candidateIndex}/${params.candidateCount}` : "Evaluating candidate mod"}: scenario ${progress2.scenarioIndex}/${progress2.scenarioCount} ${progress2.scenarioName}`, {
527956
528530
  passed: progress2.evaluation.passed,
527957
528531
  score: progress2.score
527958
528532
  });
@@ -527968,13 +528542,13 @@ async function runModLearningCandidate(params) {
527968
528542
  const passed = candidateExists && evaluation.passed;
527969
528543
  let promotedToPath = null;
527970
528544
  if (passed && options.promoteToPath) {
527971
- emitProgress("promoting", "Promoting passing candidate mod");
528545
+ emitProgress2("promoting", "Promoting passing candidate mod");
527972
528546
  promotedToPath = path50.resolve(repoRoot, options.promoteToPath);
527973
528547
  await mkdir20(path50.dirname(promotedToPath), { recursive: true });
527974
528548
  await copyFile2(candidatePath, promotedToPath);
527975
528549
  }
527976
528550
  const reportPath = path50.join(runDir, "report.md");
527977
- emitProgress("writing-report", "Writing mod learning report");
528551
+ emitProgress2("writing-report", "Writing mod learning report");
527978
528552
  const report = {
527979
528553
  candidateCount: params.candidateCount,
527980
528554
  candidateIndex: params.candidateIndex,
@@ -527994,7 +528568,7 @@ async function runModLearningCandidate(params) {
527994
528568
  await writeJsonArtifact(path50.join(runDir, "report.json"), report);
527995
528569
  await writeFile23(reportPath, renderMarkdownReport(report), "utf8");
527996
528570
  await writeCandidateManifest(report);
527997
- emitProgress("done", params.candidateCount > 1 ? `Optimization iteration ${params.candidateIndex}/${params.candidateCount} complete` : "mod optimization complete", {
528571
+ emitProgress2("done", params.candidateCount > 1 ? `Optimization iteration ${params.candidateIndex}/${params.candidateCount} complete` : "mod optimization complete", {
527998
528572
  attempts: [...params.previousAttempts, summarizeAttempt(report)],
527999
528573
  passed: report.passed,
528000
528574
  score
@@ -540513,4 +541087,4 @@ function registerBunOAuthFlows() {
540513
541087
  registerBunOAuthFlows();
540514
541088
  await init_src5().then(() => exports_src2);
540515
541089
 
540516
- //# debugId=23162BCF185F91F064756E2164756E21
541090
+ //# debugId=27D2CAFC27386FDE64756E2164756E21