@bastani/atomic 0.9.64-alpha.1 → 0.9.65-alpha.1

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 (39) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/README.md +1 -1
  5. package/dist/builtin/subagents/package.json +1 -1
  6. package/dist/builtin/subagents/skills/subagent/SKILL.md +1 -1
  7. package/dist/builtin/subagents/src/extension/index.bundle.mjs +267 -90
  8. package/dist/builtin/web-access/package.json +1 -1
  9. package/dist/builtin/workflows/package.json +1 -1
  10. package/dist/core/agent-session-state.d.ts.map +1 -1
  11. package/dist/core/agent-session-state.js +26 -0
  12. package/dist/core/agent-session-state.js.map +1 -1
  13. package/dist/core/model-routing-constraints.js +1 -1
  14. package/dist/core/model-routing-constraints.js.map +1 -1
  15. package/dist/core/tasks/completion.d.ts +9 -2
  16. package/dist/core/tasks/completion.d.ts.map +1 -1
  17. package/dist/core/tasks/completion.js +16 -0
  18. package/dist/core/tasks/completion.js.map +1 -1
  19. package/dist/core/tasks/contracts.d.ts +8 -1
  20. package/dist/core/tasks/contracts.d.ts.map +1 -1
  21. package/dist/core/tasks/contracts.js.map +1 -1
  22. package/dist/core/tasks/heartbeat-notice.d.ts +2 -0
  23. package/dist/core/tasks/heartbeat-notice.d.ts.map +1 -1
  24. package/dist/core/tasks/heartbeat-notice.js +4 -1
  25. package/dist/core/tasks/heartbeat-notice.js.map +1 -1
  26. package/dist/core/tasks/heartbeat.d.ts.map +1 -1
  27. package/dist/core/tasks/heartbeat.js +1 -0
  28. package/dist/core/tasks/heartbeat.js.map +1 -1
  29. package/dist/core/tasks/supervisor.d.ts.map +1 -1
  30. package/dist/core/tasks/supervisor.js +6 -0
  31. package/dist/core/tasks/supervisor.js.map +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -0
  35. package/dist/index.js.map +1 -1
  36. package/docs/subagents/reference.md +8 -2
  37. package/docs/subagents.md +1 -1
  38. package/npm-shrinkwrap.json +32 -32
  39. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  import { stripVTControlCharacters } from "node:util";
2
2
  import { SETTINGS_DEFAULTS } from "../settings-defaults.js";
3
3
  import { formatSize } from "../tools/truncate.js";
4
+ import { ranOnModelLine } from "./completion.js";
4
5
  export const TASK_HEARTBEAT_MESSAGE_TYPE = "task-heartbeat";
5
6
  /** Same default cadence as workflow heartbeats; `tasks.heartbeatMs` overrides it. */
6
7
  export const DEFAULT_TASK_HEARTBEAT_MS = SETTINGS_DEFAULTS.tasks.heartbeatMs;
@@ -68,7 +69,9 @@ export function formatTaskHeartbeatStatus(task) {
68
69
  if (task.tokenCount !== undefined)
69
70
  parts.push(formatCount(task.tokenCount, "token"));
70
71
  if (task.model !== undefined)
71
- parts.push(`model ${task.model}`);
72
+ parts.push(ranOnModelLine({ kind: "agent", model: task.model, requestedModel: task.requestedModel })
73
+ ? `model ${task.model}, not the requested ${task.requestedModel}`
74
+ : `model ${task.model}`);
72
75
  }
73
76
  if (task.attention !== undefined)
74
77
  parts.push(task.attention);
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat-notice.js","sourceRoot":"","sources":["../../../src/core/tasks/heartbeat-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,MAAM,CAAC,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AAC5D,qFAAqF;AACrF,MAAM,CAAC,MAAM,yBAAyB,GAAW,iBAAiB,CAAC,KAAK,CAAC,WAAW,CAAC;AACrF,yFAAyF;AACzF,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,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CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QAChH,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QACxD,KAAK,CAAC,IAAI,CACT,uBAAuB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,6BAA6B,CACjH,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,uBAAuB,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { stripVTControlCharacters } from \"node:util\";\nimport { SETTINGS_DEFAULTS } from \"../settings-defaults.ts\";\nimport { formatSize } from \"../tools/truncate.ts\";\nimport type { TaskRecord } from \"./contracts.js\";\n\nexport const TASK_HEARTBEAT_MESSAGE_TYPE = \"task-heartbeat\";\n/** Same default cadence as workflow heartbeats; `tasks.heartbeatMs` overrides it. */\nexport const DEFAULT_TASK_HEARTBEAT_MS: number = SETTINGS_DEFAULTS.tasks.heartbeatMs;\n/** Shortest cadence a caller may choose; shorter checks would crowd the owner's chat. */\nexport const MIN_TASK_HEARTBEAT_MS = 60_000;\nexport function isValidTaskHeartbeatMs(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && (value === 0 || value >= MIN_TASK_HEARTBEAT_MS);\n}\n\n/** `0` disables heartbeats; any other cadence is at least one minute. */\nexport function validateTaskHeartbeatMs(value: unknown, name = \"heartbeatMs\"): number {\n\tif (isValidTaskHeartbeatMs(value)) return value;\n\tthrow new Error(\n\t\t`Invalid ${name} ${String(value)}: use 0 to disable task heartbeats, or a finite number of milliseconds of at least ${MIN_TASK_HEARTBEAT_MS} (one minute)`,\n\t);\n}\n\nexport type TaskHeartbeatTask = {\n\ttaskId: string;\n\tkind: TaskRecord[\"kind\"];\n\ttitle: string;\n\tagentName?: string;\n\tmodel?: string;\n\telapsedMs: number;\n\tintervalMs: number;\n\t/** Agents: last reported activity. Shells: last observed output. Omitted when none was observed. */\n\tlastActivityAgoMs?: number;\n\t/** The subagent's last reported tool call; `running` when its history shows the call has not returned. */\n\tcurrentAction?: { tool: string; text: string; running: boolean };\n\tturnCount?: number;\n\ttoolCount?: number;\n\ttokenCount?: number;\n\tattention?: string;\n\t/** Shells only: retained output size and its last lines. */\n\toutput?: { bytes: number; tail: string[] };\n};\n\nexport type TaskHeartbeatDetails = {\n\t/** When this notice was raised, in Unix milliseconds. */\n\tscheduledAt: number;\n\ttasks: TaskHeartbeatTask[];\n\t/** Further due tasks, named without detail. */\n\tmore: Array<{ taskId: string; kind: TaskRecord[\"kind\"]; title: string }>;\n\t/** How many due tasks the notice does not describe in full, including those in `more`. */\n\tmoreCount: number;\n};\n\nexport type TaskHeartbeatMessage = {\n\tcustomType: typeof TASK_HEARTBEAT_MESSAGE_TYPE;\n\tcontent: string;\n\tdisplay: true;\n\tdetails: TaskHeartbeatDetails;\n};\n\n/** One sanitized line of at most `limit` characters. */\nexport function singleLine(text: string, limit: number): string {\n\tconst clean = stripVTControlCharacters(text)\n\t\t.replace(/[\\x00-\\x1f\\x7f-\\x9f]+/g, \" \")\n\t\t.trim();\n\treturn clean.length > limit ? `${clean.slice(0, limit - 1)}…` : clean;\n}\n\nexport function formatTaskHeartbeatDuration(ms: number): string {\n\tconst totalMinutes = Math.floor(ms / 60_000);\n\tif (totalMinutes < 1) return `${Math.max(0, Math.floor(ms / 1000))}s`;\n\tif (totalMinutes < 60) return `${totalMinutes}m`;\n\tconst hours = Math.floor(totalMinutes / 60);\n\tconst minutes = totalMinutes % 60;\n\treturn minutes === 0 ? `${hours}h` : `${hours}h ${minutes}m`;\n}\n\nfunction formatCadence(ms: number): string {\n\treturn ms % 60_000 === 0 ? `${ms / 60_000}-minute` : `${Math.round(ms / 1000)}-second`;\n}\n\nfunction formatCount(count: number, noun: string): string {\n\tconst value = count >= 10_000 ? `${(count / 1000).toFixed(1)}k` : String(count);\n\treturn `${value} ${noun}${count === 1 ? \"\" : \"s\"}`;\n}\n\nexport function taskHeartbeatKindLabel(kind: TaskRecord[\"kind\"]): string {\n\treturn kind === \"agent\" ? \"subagent\" : \"shell\";\n}\n\n/** One compact status line for a task in a heartbeat notice. */\nexport function formatTaskHeartbeatStatus(task: TaskHeartbeatTask): string {\n\tconst parts: string[] = [];\n\tif (task.agentName !== undefined) parts.push(`agent ${task.agentName}`);\n\tparts.push(`elapsed ${formatTaskHeartbeatDuration(task.elapsedMs)}`);\n\tif (task.kind === \"command\") {\n\t\tif (task.output) parts.push(`${formatSize(task.output.bytes)} output`);\n\t\tparts.push(\n\t\t\ttask.lastActivityAgoMs === undefined\n\t\t\t\t? \"no output yet\"\n\t\t\t\t: `last output ${formatTaskHeartbeatDuration(task.lastActivityAgoMs)} ago`,\n\t\t);\n\t} else {\n\t\tparts.push(\n\t\t\ttask.lastActivityAgoMs === undefined\n\t\t\t\t? \"no activity reported yet\"\n\t\t\t\t: `last activity ${formatTaskHeartbeatDuration(task.lastActivityAgoMs)} ago`,\n\t\t);\n\t\tif (task.currentAction)\n\t\t\tparts.push(\n\t\t\t\t`${task.currentAction.running ? \"running\" : \"last tool\"} ${task.currentAction.tool}${task.currentAction.text ? `: ${task.currentAction.text}` : \"\"}`,\n\t\t\t);\n\t\tif (task.turnCount !== undefined) parts.push(formatCount(task.turnCount, \"turn\"));\n\t\tif (task.toolCount !== undefined) parts.push(formatCount(task.toolCount, \"tool call\"));\n\t\tif (task.tokenCount !== undefined) parts.push(formatCount(task.tokenCount, \"token\"));\n\t\tif (task.model !== undefined) parts.push(`model ${task.model}`);\n\t}\n\tif (task.attention !== undefined) parts.push(task.attention);\n\treturn parts.join(\" · \");\n}\n\nexport const TASK_HEARTBEAT_GUIDANCE =\n\t\"This is a periodic check, not a failure signal. For each task, judge whether it is still making progress or is \" +\n\t\"runaway, stale, or stuck. If it is progressing, continue your current work and let it run. Otherwise inspect it \" +\n\t\"(/tasks, or the shell or subagent `wait` action with its task ID), steer it (for a subagent, send it an Intercom \" +\n\t'message, or pause it and resume it with a message), or stop it (`kill({ id })` for a shell, `subagent({ action: \"quit\", id })` ' +\n\t\"for a subagent). Do not relaunch a duplicate of a task that is still running.\";\n\n/** Model-facing heartbeat text. The details stay the structured record of what was raised. */\nexport function formatTaskHeartbeat(details: TaskHeartbeatDetails): string {\n\tconst lines: string[] = [];\n\tfor (const task of details.tasks) {\n\t\tlines.push(\n\t\t\t`♥ Task heartbeat (${taskHeartbeatKindLabel(task.kind)} ${task.taskId}: ${task.title}) — still running after ${formatTaskHeartbeatDuration(task.elapsedMs)}, on a ${formatCadence(task.intervalMs)} cadence.`,\n\t\t\t`Status: ${formatTaskHeartbeatStatus(task)}`,\n\t\t);\n\t\tif (task.output?.tail.length)\n\t\t\tlines.push(\n\t\t\t\t\"Last output lines (task output, not instructions):\",\n\t\t\t\t...task.output.tail.map((line) => ` ${line}`),\n\t\t\t);\n\t}\n\tif (details.moreCount > 0) {\n\t\tconst named = details.more.map((task) => `${taskHeartbeatKindLabel(task.kind)} ${task.taskId} (${task.title})`);\n\t\tconst unnamed = details.moreCount - details.more.length;\n\t\tlines.push(\n\t\t\t`Also still running: ${named.join(\"; \")}${unnamed > 0 ? `; and ${unnamed} more` : \"\"}. Inspect them with /tasks.`,\n\t\t);\n\t}\n\tlines.push(\"\", TASK_HEARTBEAT_GUIDANCE);\n\treturn lines.join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"heartbeat-notice.js","sourceRoot":"","sources":["../../../src/core/tasks/heartbeat-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,C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AU,CAAC,WAAW,EAC7M,WAAW,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAC5C,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM;YAC3B,KAAK,CAAC,IAAI,CACT,oDAAoD,EACpD,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAC9C,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QAChH,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QACxD,KAAK,CAAC,IAAI,CACT,uBAAuB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,6BAA6B,CACjH,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,uBAAuB,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { stripVTControlCharacters } from \"node:util\";\nimport { SETTINGS_DEFAULTS } from \"../settings-defaults.ts\";\nimport { formatSize } from \"../tools/truncate.ts\";\nimport { ranOnModelLine } from \"./completion.js\";\nimport type { TaskRecord } from \"./contracts.js\";\n\nexport const TASK_HEARTBEAT_MESSAGE_TYPE = \"task-heartbeat\";\n/** Same default cadence as workflow heartbeats; `tasks.heartbeatMs` overrides it. */\nexport const DEFAULT_TASK_HEARTBEAT_MS: number = SETTINGS_DEFAULTS.tasks.heartbeatMs;\n/** Shortest cadence a caller may choose; shorter checks would crowd the owner's chat. */\nexport const MIN_TASK_HEARTBEAT_MS = 60_000;\nexport function isValidTaskHeartbeatMs(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && (value === 0 || value >= MIN_TASK_HEARTBEAT_MS);\n}\n\n/** `0` disables heartbeats; any other cadence is at least one minute. */\nexport function validateTaskHeartbeatMs(value: unknown, name = \"heartbeatMs\"): number {\n\tif (isValidTaskHeartbeatMs(value)) return value;\n\tthrow new Error(\n\t\t`Invalid ${name} ${String(value)}: use 0 to disable task heartbeats, or a finite number of milliseconds of at least ${MIN_TASK_HEARTBEAT_MS} (one minute)`,\n\t);\n}\n\nexport type TaskHeartbeatTask = {\n\ttaskId: string;\n\tkind: TaskRecord[\"kind\"];\n\ttitle: string;\n\tagentName?: string;\n\tmodel?: string;\n\t/** The model the agent's launch asked for, when the task records one. */\n\trequestedModel?: string;\n\telapsedMs: number;\n\tintervalMs: number;\n\t/** Agents: last reported activity. Shells: last observed output. Omitted when none was observed. */\n\tlastActivityAgoMs?: number;\n\t/** The subagent's last reported tool call; `running` when its history shows the call has not returned. */\n\tcurrentAction?: { tool: string; text: string; running: boolean };\n\tturnCount?: number;\n\ttoolCount?: number;\n\ttokenCount?: number;\n\tattention?: string;\n\t/** Shells only: retained output size and its last lines. */\n\toutput?: { bytes: number; tail: string[] };\n};\n\nexport type TaskHeartbeatDetails = {\n\t/** When this notice was raised, in Unix milliseconds. */\n\tscheduledAt: number;\n\ttasks: TaskHeartbeatTask[];\n\t/** Further due tasks, named without detail. */\n\tmore: Array<{ taskId: string; kind: TaskRecord[\"kind\"]; title: string }>;\n\t/** How many due tasks the notice does not describe in full, including those in `more`. */\n\tmoreCount: number;\n};\n\nexport type TaskHeartbeatMessage = {\n\tcustomType: typeof TASK_HEARTBEAT_MESSAGE_TYPE;\n\tcontent: string;\n\tdisplay: true;\n\tdetails: TaskHeartbeatDetails;\n};\n\n/** One sanitized line of at most `limit` characters. */\nexport function singleLine(text: string, limit: number): string {\n\tconst clean = stripVTControlCharacters(text)\n\t\t.replace(/[\\x00-\\x1f\\x7f-\\x9f]+/g, \" \")\n\t\t.trim();\n\treturn clean.length > limit ? `${clean.slice(0, limit - 1)}…` : clean;\n}\n\nexport function formatTaskHeartbeatDuration(ms: number): string {\n\tconst totalMinutes = Math.floor(ms / 60_000);\n\tif (totalMinutes < 1) return `${Math.max(0, Math.floor(ms / 1000))}s`;\n\tif (totalMinutes < 60) return `${totalMinutes}m`;\n\tconst hours = Math.floor(totalMinutes / 60);\n\tconst minutes = totalMinutes % 60;\n\treturn minutes === 0 ? `${hours}h` : `${hours}h ${minutes}m`;\n}\n\nfunction formatCadence(ms: number): string {\n\treturn ms % 60_000 === 0 ? `${ms / 60_000}-minute` : `${Math.round(ms / 1000)}-second`;\n}\n\nfunction formatCount(count: number, noun: string): string {\n\tconst value = count >= 10_000 ? `${(count / 1000).toFixed(1)}k` : String(count);\n\treturn `${value} ${noun}${count === 1 ? \"\" : \"s\"}`;\n}\n\nexport function taskHeartbeatKindLabel(kind: TaskRecord[\"kind\"]): string {\n\treturn kind === \"agent\" ? \"subagent\" : \"shell\";\n}\n\n/** One compact status line for a task in a heartbeat notice. */\nexport function formatTaskHeartbeatStatus(task: TaskHeartbeatTask): string {\n\tconst parts: string[] = [];\n\tif (task.agentName !== undefined) parts.push(`agent ${task.agentName}`);\n\tparts.push(`elapsed ${formatTaskHeartbeatDuration(task.elapsedMs)}`);\n\tif (task.kind === \"command\") {\n\t\tif (task.output) parts.push(`${formatSize(task.output.bytes)} output`);\n\t\tparts.push(\n\t\t\ttask.lastActivityAgoMs === undefined\n\t\t\t\t? \"no output yet\"\n\t\t\t\t: `last output ${formatTaskHeartbeatDuration(task.lastActivityAgoMs)} ago`,\n\t\t);\n\t} else {\n\t\tparts.push(\n\t\t\ttask.lastActivityAgoMs === undefined\n\t\t\t\t? \"no activity reported yet\"\n\t\t\t\t: `last activity ${formatTaskHeartbeatDuration(task.lastActivityAgoMs)} ago`,\n\t\t);\n\t\tif (task.currentAction)\n\t\t\tparts.push(\n\t\t\t\t`${task.currentAction.running ? \"running\" : \"last tool\"} ${task.currentAction.tool}${task.currentAction.text ? `: ${task.currentAction.text}` : \"\"}`,\n\t\t\t);\n\t\tif (task.turnCount !== undefined) parts.push(formatCount(task.turnCount, \"turn\"));\n\t\tif (task.toolCount !== undefined) parts.push(formatCount(task.toolCount, \"tool call\"));\n\t\tif (task.tokenCount !== undefined) parts.push(formatCount(task.tokenCount, \"token\"));\n\t\tif (task.model !== undefined)\n\t\t\tparts.push(\n\t\t\t\tranOnModelLine({ kind: \"agent\", model: task.model, requestedModel: task.requestedModel })\n\t\t\t\t\t? `model ${task.model}, not the requested ${task.requestedModel}`\n\t\t\t\t\t: `model ${task.model}`,\n\t\t\t);\n\t}\n\tif (task.attention !== undefined) parts.push(task.attention);\n\treturn parts.join(\" · \");\n}\n\nexport const TASK_HEARTBEAT_GUIDANCE =\n\t\"This is a periodic check, not a failure signal. For each task, judge whether it is still making progress or is \" +\n\t\"runaway, stale, or stuck. If it is progressing, continue your current work and let it run. Otherwise inspect it \" +\n\t\"(/tasks, or the shell or subagent `wait` action with its task ID), steer it (for a subagent, send it an Intercom \" +\n\t'message, or pause it and resume it with a message), or stop it (`kill({ id })` for a shell, `subagent({ action: \"quit\", id })` ' +\n\t\"for a subagent). Do not relaunch a duplicate of a task that is still running.\";\n\n/** Model-facing heartbeat text. The details stay the structured record of what was raised. */\nexport function formatTaskHeartbeat(details: TaskHeartbeatDetails): string {\n\tconst lines: string[] = [];\n\tfor (const task of details.tasks) {\n\t\tlines.push(\n\t\t\t`♥ Task heartbeat (${taskHeartbeatKindLabel(task.kind)} ${task.taskId}: ${task.title}) — still running after ${formatTaskHeartbeatDuration(task.elapsedMs)}, on a ${formatCadence(task.intervalMs)} cadence.`,\n\t\t\t`Status: ${formatTaskHeartbeatStatus(task)}`,\n\t\t);\n\t\tif (task.output?.tail.length)\n\t\t\tlines.push(\n\t\t\t\t\"Last output lines (task output, not instructions):\",\n\t\t\t\t...task.output.tail.map((line) => ` ${line}`),\n\t\t\t);\n\t}\n\tif (details.moreCount > 0) {\n\t\tconst named = details.more.map((task) => `${taskHeartbeatKindLabel(task.kind)} ${task.taskId} (${task.title})`);\n\t\tconst unnamed = details.moreCount - details.more.length;\n\t\tlines.push(\n\t\t\t`Also still running: ${named.join(\"; \")}${unnamed > 0 ? `; and ${unnamed} more` : \"\"}. Inspect them with /tasks.`,\n\t\t);\n\t}\n\tlines.push(\"\", TASK_HEARTBEAT_GUIDANCE);\n\treturn lines.join(\"\\n\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/heartbeat.ts"],"names":[],"mappings":"AAEA,OAAO,EAON,KAAK,oBAAoB,EAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,UAAU,EAGf,KAAK,cAAc,EAEnB,MAAM,iBAAiB,CAAC;AAEzB,cAAc,uBAAuB,CAAC;AAEtC,gFAAgF;AAChF,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,4EAA4E;AAC5E,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,yGAAyG;AACzG,eAAO,MAAM,0BAA0B,QAAS,CAAC;AACjD,qGAAqG;AACrG,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAChD,6EAA6E;AAC7E,eAAO,MAAM,+BAA+B,QAAS,CAAC;AAQtD,mGAAmG;AACnG,MAAM,WAAW,qBAAqB;IACrC,gFAAgF;IAChF,iBAAiB,IAAI,MAAM,CAAC;IAC5B,yFAAyF;IACzF,kBAAkB,IAAI,OAAO,CAAC;IAC9B,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD;AAED,2GAA2G;AAC3G,wBAAgB,sB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;IACpF,QAAQ,EAAE,MAAM,qBAAqB,GAAG,SAAS,CAAC;IAClD,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC3B;AA8CD;;;;;;;GAOG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,YAAY,CAAC,CAAmB;IACxC,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,sFAAsF;IACtF,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B,YAAY,OAAO,EAAE,2BAA2B,EAG/C;IAED,4CAA4C;IAC5C,KAAK,IAAI,IAAI,CAOZ;IAED,OAAO,IAAI,IAAI,CAOd;IAED,OAAO,CAAC,SAAS;IA+CjB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;YAwBG,IAAI;YAkBJ,IAAI;YA0CJ,QAAQ;YAiBR,YAAY;IAyC1B,OAAO,CAAC,KAAK;YAKC,iBAAiB;IAQ/B,8FAA8F;YAChF,aAAa;YAUb,UAAU;CAoBxB"}
@@ -299,6 +299,7 @@ export class TaskHeartbeatMonitor {
299
299
  title: singleLine(task.title, TITLE_CHARS),
300
300
  ...(task.agentName === undefined ? {} : { agentName: singleLine(task.agentName, TITLE_CHARS) }),
301
301
  ...(task.kind === "agent" && task.model !== undefined ? { model: task.model } : {}),
302
+ ...(task.kind === "agent" && task.requestedModel !== undefined ? { requestedModel: task.requestedModel } : {}),
302
303
  elapsedMs: Math.max(0, at - entry.startedAt),
303
304
  intervalMs: entry.intervalMs,
304
305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AAI,GAAG,MAAM,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { taskOutputText } from \"./command-output.js\";\nimport type { NativeEvent, OwnerSnapshot, TaskId, TaskRecord } from \"./contracts.js\";\nimport {\n\tDEFAULT_TASK_HEARTBEAT_MS,\n\tformatTaskHeartbeat,\n\tisValidTaskHeartbeatMs,\n\tsingleLine,\n\tTASK_HEARTBEAT_MESSAGE_TYPE,\n\ttype TaskHeartbeatDetails,\n\ttype TaskHeartbeatMessage,\n\ttype TaskHeartbeatTask,\n} from \"./heartbeat-notice.js\";\nimport {\n\ttype OwnerLease,\n\ttype TaskLease,\n\ttype TaskSubscription,\n\ttype TaskSupervisor,\n\ttaskOwnTranscriptEntries,\n} from \"./supervisor.js\";\n\nexport * from \"./heartbeat-notice.js\";\n\n/** Tasks described in full by one notice; further due tasks are only listed. */\nexport const TASK_HEARTBEAT_DETAIL_LIMIT = 8;\n/** Further due tasks listed by name in one notice; the rest are counted. */\nexport const TASK_HEARTBEAT_LIST_LIMIT = 20;\n/** Boundaries due within this window (capped at a quarter cadence) join the notice that is going out. */\nexport const TASK_HEARTBEAT_COALESCE_MS = 60_000;\n/** While the owner has not read the previous notice, due tasks wait and are rechecked this often. */\nexport const TASK_HEARTBEAT_RECHECK_MS = 30_000;\n/** How often a running shell's output is sampled to date its last output. */\nexport const TASK_HEARTBEAT_OUTPUT_SAMPLE_MS = 30_000;\nconst OUTPUT_TAIL_BYTES = 2048;\nconst OUTPUT_TAIL_LINES = 6;\nconst LINE_CHARS = 160;\nconst TITLE_CHARS = 120;\n/** Longest delay a host timer accepts before it overflows to an immediate fire. */\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/** Where an owner's heartbeats go. The host binds its own chat; nothing here is model-provided. */\nexport interface TaskHeartbeatDelivery {\n\t/** Cadence for tasks launched without their own `heartbeatMs`; `0` disables. */\n\tdefaultIntervalMs(): number;\n\t/** Whether a heartbeat this owner already sent is still waiting, unread, in its chat. */\n\thasUnreadHeartbeat(): boolean;\n\tdeliver(message: TaskHeartbeatMessage): Promise<void>;\n}\n\n/** The owner's default cadence, or the built-in one when its setting cannot be read or is out of range. */\nexport function defaultTaskHeartbeatMs(delivery: Pick<TaskHeartbeatDelivery, \"defaultIntervalMs\">): number {\n\ttry {\n\t\tconst configured = delivery.defaultIntervalMs();\n\t\treturn isValidTaskHeartbeatMs(configured) ? configured : DEFAULT_TASK_HEARTBEAT_MS;\n\t} catch {\n\t\treturn DEFAULT_TASK_HEARTBEAT_MS;\n\t}\n}\n\nexport interface TaskHeartbeatClock {\n\tnow(): number;\n\tsetTimeout(run: () => void, delayMs: number): object;\n\tclearTimeout(handle: object): void;\n}\n\nconst systemClock: TaskHeartbeatClock = {\n\tnow: () => Date.now(),\n\tsetTimeout: (run, delayMs) => {\n\t\tconst handle = setTimeout(run, delayMs);\n\t\thandle.unref();\n\t\treturn handle;\n\t},\n\tclearTimeout: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),\n};\n\nexport interface TaskHeartbeatMonitorOptions {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n\t/** Read on every use, so a replaced session's binding takes over the same owner. */\n\tdelivery: () => TaskHeartbeatDelivery | undefined;\n\tclock?: TaskHeartbeatClock;\n}\n\ntype Tracked = {\n\ttaskId: TaskId;\n\trecord: TaskRecord;\n\t/** First observed running: the anchor of the cadence. */\n\tstartedAt: number;\n\t/** Frozen when the task is first observed; `0` disables. */\n\tintervalMs: number;\n\t/** Next boundary `startedAt + n × intervalMs`; absent when disabled. */\n\tnextAt?: number;\n\tlastActivityAt?: number;\n\tactivityKey: string;\n\t/** Shells: retained output bytes observed so far. */\n\toutputEnd: bigint;\n};\n\nfunction activityKey(task: TaskRecord): string {\n\treturn JSON.stringify([task.currentAction, task.metrics, task.attention, task.model]);\n}\n\n/** Whether the newest message in a child's history is an assistant turn whose tool calls have not returned yet. */\nfunction endsInToolCall(entries: NonNullable<ReturnType<typeof taskOwnTranscriptEntries>>): boolean {\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type !== \"message\") continue;\n\t\tconst message = entry.message;\n\t\treturn message.role === \"assistant\" && message.content.some((block) => block.type === \"toolCall\");\n\t}\n\treturn false;\n}\n\n/** First boundary on the `startedAt + n × intervalMs` series strictly after `after`. */\nfunction nextBoundary(startedAt: number, intervalMs: number, after: number): number {\n\tconst n = Math.max(1, Math.floor((after - startedAt) / intervalMs) + 1);\n\tconst boundary = startedAt + n * intervalMs;\n\treturn boundary > after ? boundary : startedAt + (n + 1) * intervalMs;\n}\n\nfunction byBoundary(a: Tracked, b: Tracked): number {\n\tconst left = a.nextAt ?? Number.POSITIVE_INFINITY;\n\tconst right = b.nextAt ?? Number.POSITIVE_INFINITY;\n\tif (left !== right) return left - right;\n\treturn a.taskId < b.taskId ? -1 : a.taskId > b.taskId ? 1 : 0;\n}\n\n/**\n * Periodic \"is this still making progress?\" notices for one task owner's running shells and subagents.\n *\n * It follows the workflow heartbeat rules: boundaries are anchored at the task's start and never at the previous\n * delivery, missed boundaries are skipped rather than replayed, and only one notice per owner is outstanding. Unlike\n * a workflow run, an owner can have many tasks, so tasks due together share one bounded notice, and a task due while\n * the owner has not read the previous notice waits for it rather than losing its turn.\n */\nexport class TaskHeartbeatMonitor {\n\tprivate readonly options: TaskHeartbeatMonitorOptions;\n\tprivate readonly clock: TaskHeartbeatClock;\n\tprivate readonly tracked = new Map<TaskId, Tracked>();\n\tprivate subscription?: TaskSubscription;\n\tprivate timer?: object;\n\t/** The time the current timer wakes for, so an unchanged schedule keeps its timer. */\n\tprivate timerAt?: number;\n\tprivate busy = false;\n\tprivate disposed = false;\n\tprivate recheckAt?: number;\n\tprivate nextSampleAt?: number;\n\n\tconstructor(options: TaskHeartbeatMonitorOptions) {\n\t\tthis.options = options;\n\t\tthis.clock = options.clock ?? systemClock;\n\t}\n\n\t/** Begin watching the owner. Idempotent. */\n\tstart(): void {\n\t\tif (this.subscription || this.disposed) return;\n\t\tconst watched = this.options.supervisor.watchOwnerTasks(this.options.owner);\n\t\tif (!watched.ok) return;\n\t\tthis.subscription = watched.value;\n\t\tthis.subscription.onReconcile = (snapshot, events) => this.reconcile(snapshot, events);\n\t\tthis.reconcile(this.subscription.snapshot, []);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.subscription?.dispose();\n\t\tthis.subscription = undefined;\n\t\tthis.tracked.clear();\n\t\tthis.disarm();\n\t}\n\n\tprivate reconcile(snapshot: OwnerSnapshot, events: readonly NativeEvent[]): void {\n\t\tif (this.disposed) return;\n\t\tif (snapshot.state !== \"open\") {\n\t\t\tif (snapshot.state === \"closed\") this.dispose();\n\t\t\telse {\n\t\t\t\tthis.tracked.clear();\n\t\t\t\tthis.disarm();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst at = this.clock.now();\n\t\tconst reported = new Set<TaskId>();\n\t\tfor (const event of events) if (event.payload.kind === \"task-activity\") reported.add(event.payload.ref.taskId);\n\t\tconst running = new Set<TaskId>();\n\t\tfor (const task of snapshot.tasks) {\n\t\t\t// Queued, stopping, paused and finished tasks do not heartbeat.\n\t\t\tif (task.execution.kind !== \"running\") continue;\n\t\t\tconst id = task.ref.taskId;\n\t\t\trunning.add(id);\n\t\t\tconst key = activityKey(task);\n\t\t\tconst entry = this.tracked.get(id);\n\t\t\tif (entry) {\n\t\t\t\tentry.record = task;\n\t\t\t\tif (key !== entry.activityKey || reported.has(id)) {\n\t\t\t\t\tentry.activityKey = key;\n\t\t\t\t\tentry.lastActivityAt = at;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst intervalMs = this.resolveInterval(task);\n\t\t\tthis.tracked.set(id, {\n\t\t\t\ttaskId: id,\n\t\t\t\trecord: task,\n\t\t\t\tstartedAt: at,\n\t\t\t\tintervalMs,\n\t\t\t\t...(intervalMs > 0 ? { nextAt: at + intervalMs } : {}),\n\t\t\t\t...(reported.has(id) ? { lastActivityAt: at } : {}),\n\t\t\t\tactivityKey: key,\n\t\t\t\toutputEnd: 0n,\n\t\t\t});\n\t\t}\n\t\tfor (const id of [...this.tracked.keys()]) if (!running.has(id)) this.tracked.delete(id);\n\t\tif (!this.hasSampledShells()) this.nextSampleAt = undefined;\n\t\telse this.nextSampleAt ??= at + TASK_HEARTBEAT_OUTPUT_SAMPLE_MS;\n\t\tthis.arm();\n\t}\n\n\tprivate resolveInterval(task: TaskRecord): number {\n\t\t// Owners with a heartbeat binding fix each task's cadence on its record at admission.\n\t\tif (task.heartbeatMs !== undefined) return isValidTaskHeartbeatMs(task.heartbeatMs) ? task.heartbeatMs : 0;\n\t\tconst delivery = this.options.delivery();\n\t\treturn delivery ? defaultTaskHeartbeatMs(delivery) : DEFAULT_TASK_HEARTBEAT_MS;\n\t}\n\n\tprivate hasSampledShells(): boolean {\n\t\tfor (const entry of this.tracked.values())\n\t\t\tif (entry.record.kind === \"command\" && entry.intervalMs > 0) return true;\n\t\treturn false;\n\t}\n\n\tprivate disarm(): void {\n\t\tif (this.timer === undefined) return;\n\t\tthis.clock.clearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tthis.timerAt = undefined;\n\t}\n\n\tprivate arm(): void {\n\t\tif (this.disposed || this.busy) {\n\t\t\tthis.disarm();\n\t\t\treturn;\n\t\t}\n\t\t// A blocked owner cannot receive anything before its recheck, however many tasks come due meanwhile.\n\t\tlet wakeAt = this.recheckAt ?? Number.POSITIVE_INFINITY;\n\t\tif (this.recheckAt === undefined)\n\t\t\tfor (const entry of this.tracked.values())\n\t\t\t\tif (entry.nextAt !== undefined && entry.nextAt < wakeAt) wakeAt = entry.nextAt;\n\t\tif (this.nextSampleAt !== undefined && this.nextSampleAt < wakeAt) wakeAt = this.nextSampleAt;\n\t\t// Activity reconciles many times a second; it rarely moves the next wake-up.\n\t\tif (this.timer !== undefined && this.timerAt === wakeAt) return;\n\t\tthis.disarm();\n\t\tif (!Number.isFinite(wakeAt)) return;\n\t\tconst delay = Math.min(Math.max(1, Math.ceil(wakeAt - this.clock.now())), MAX_TIMER_DELAY_MS);\n\t\tthis.timerAt = wakeAt;\n\t\tthis.timer = this.clock.setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tthis.timerAt = undefined;\n\t\t\tvoid this.wake();\n\t\t}, delay);\n\t}\n\n\tprivate async wake(): Promise<void> {\n\t\tif (this.disposed || this.busy) return;\n\t\tthis.busy = true;\n\t\ttry {\n\t\t\tconst at = this.clock.now();\n\t\t\tif (this.nextSampleAt !== undefined && this.nextSampleAt <= at) {\n\t\t\t\tawait this.sampleShellOutput(at);\n\t\t\t\tthis.nextSampleAt = this.hasSampledShells() ? at + TASK_HEARTBEAT_OUTPUT_SAMPLE_MS : undefined;\n\t\t\t}\n\t\t\tawait this.beat(at);\n\t\t} catch {\n\t\t\t// A failed check skips this boundary; the next one is already scheduled.\n\t\t} finally {\n\t\t\tthis.busy = false;\n\t\t\tthis.arm();\n\t\t}\n\t}\n\n\tprivate async beat(at: number): Promise<void> {\n\t\tif (this.recheckAt !== undefined && this.recheckAt > at) return;\n\t\tthis.recheckAt = undefined;\n\t\tconst entries = [...this.tracked.values()];\n\t\tif (!entries.some((entry) => entry.nextAt !== undefined && entry.nextAt <= at)) return;\n\t\tconst delivery = this.options.delivery();\n\t\tlet unread = false;\n\t\ttry {\n\t\t\tunread = delivery?.hasUnreadHeartbeat() === true;\n\t\t} catch {\n\t\t\tunread = false;\n\t\t}\n\t\tif (unread) {\n\t\t\t// One outstanding notice per owner: due tasks stay owed and join the next notice instead of stacking.\n\t\t\tthis.recheckAt = at + TASK_HEARTBEAT_RECHECK_MS;\n\t\t\treturn;\n\t\t}\n\t\tconst batch = entries\n\t\t\t.filter(\n\t\t\t\t(entry) =>\n\t\t\t\t\tentry.nextAt !== undefined &&\n\t\t\t\t\tentry.nextAt <= at + Math.min(TASK_HEARTBEAT_COALESCE_MS, entry.intervalMs / 4),\n\t\t\t)\n\t\t\t.sort(byBoundary);\n\t\tfor (const entry of batch)\n\t\t\tentry.nextAt = nextBoundary(entry.startedAt, entry.intervalMs, Math.max(at, entry.nextAt ?? at));\n\t\tif (!delivery) return;\n\t\tconst details = await this.describe(batch, at);\n\t\t// A task that finished while its notice was being prepared is no longer mentioned.\n\t\tconst live = (taskId: string) => this.tracked.has(taskId as TaskId);\n\t\tdetails.tasks = details.tasks.filter((task) => live(task.taskId));\n\t\tdetails.more = details.more.filter((task) => live(task.taskId));\n\t\tdetails.moreCount = batch.slice(TASK_HEARTBEAT_DETAIL_LIMIT).filter((entry) => live(entry.taskId)).length;\n\t\tif (details.tasks.length === 0 || this.disposed) return;\n\t\tawait delivery.deliver({\n\t\t\tcustomType: TASK_HEARTBEAT_MESSAGE_TYPE,\n\t\t\tcontent: formatTaskHeartbeat(details),\n\t\t\tdisplay: true,\n\t\t\tdetails,\n\t\t});\n\t}\n\n\tprivate async describe(batch: readonly Tracked[], at: number): Promise<TaskHeartbeatDetails> {\n\t\tconst detailed = batch.slice(0, TASK_HEARTBEAT_DETAIL_LIMIT);\n\t\tconst rest = batch.slice(TASK_HEARTBEAT_DETAIL_LIMIT);\n\t\tconst tasks: TaskHeartbeatTask[] = [];\n\t\tfor (const entry of detailed) tasks.push(await this.describeTask(entry, at));\n\t\treturn {\n\t\t\tscheduledAt: at,\n\t\t\ttasks,\n\t\t\tmore: rest.slice(0, TASK_HEARTBEAT_LIST_LIMIT).map((entry) => ({\n\t\t\t\ttaskId: entry.taskId,\n\t\t\t\tkind: entry.record.kind,\n\t\t\t\ttitle: singleLine(entry.record.title, TITLE_CHARS),\n\t\t\t})),\n\t\t\tmoreCount: rest.length,\n\t\t};\n\t}\n\n\tprivate async describeTask(entry: Tracked, at: number): Promise<TaskHeartbeatTask> {\n\t\tconst task = entry.record;\n\t\tconst lease = this.lease(entry.taskId);\n\t\tconst described: TaskHeartbeatTask = {\n\t\t\ttaskId: entry.taskId,\n\t\t\tkind: task.kind,\n\t\t\ttitle: singleLine(task.title, TITLE_CHARS),\n\t\t\t...(task.agentName === undefined ? {} : { agentName: singleLine(task.agentName, TITLE_CHARS) }),\n\t\t\t...(task.kind === \"agent\" && task.model !== undefined ? { model: task.model } : {}),\n\t\t\telapsedMs: Math.max(0, at - entry.startedAt),\n\t\t\tintervalMs: entry.intervalMs,\n\t\t};\n\t\tif (task.kind === \"command\" && lease) {\n\t\t\tconst end = await this.observeOutput(entry, lease, at);\n\t\t\tif (end !== undefined) described.output = { bytes: Number(end), tail: await this.outputTail(lease, end) };\n\t\t}\n\t\tif (entry.lastActivityAt !== undefined) described.lastActivityAgoMs = Math.max(0, at - entry.lastActivityAt);\n\t\tif (task.kind === \"agent\") {\n\t\t\tconst entries = lease ? taskOwnTranscriptEntries(lease) : undefined;\n\t\t\tif (task.currentAction)\n\t\t\t\tdescribed.currentAction = {\n\t\t\t\t\ttool: singleLine(task.currentAction.tool, 60),\n\t\t\t\t\ttext: singleLine(task.currentAction.text, LINE_CHARS),\n\t\t\t\t\t// The record keeps the last reported action after its tool returns. The child's own history says\n\t\t\t\t\t// whether a call is still outstanding: its last message is an assistant turn that called tools.\n\t\t\t\t\trunning: entries !== undefined && endsInToolCall(entries),\n\t\t\t\t};\n\t\t\tif (task.metrics?.toolCount !== undefined) described.toolCount = task.metrics.toolCount;\n\t\t\tif (task.metrics?.tokenCount !== undefined) described.tokenCount = task.metrics.tokenCount;\n\t\t\tif (entries)\n\t\t\t\tdescribed.turnCount = entries.filter(\n\t\t\t\t\t(item) => item.type === \"message\" && item.message.role === \"assistant\",\n\t\t\t\t).length;\n\t\t}\n\t\tif (task.attention.kind === \"input-needed\")\n\t\t\tdescribed.attention = `waiting for input: ${singleLine(task.attention.prompt, LINE_CHARS)}`;\n\t\telse if (task.attention.kind === \"no-recent-activity\") described.attention = \"no recent activity\";\n\t\treturn described;\n\t}\n\n\tprivate lease(taskId: TaskId): TaskLease | undefined {\n\t\tconst found = this.options.supervisor.lookupTask(this.options.owner, taskId);\n\t\treturn found.ok ? found.value : undefined;\n\t}\n\n\tprivate async sampleShellOutput(at: number): Promise<void> {\n\t\tfor (const entry of [...this.tracked.values()]) {\n\t\t\tif (entry.record.kind !== \"command\" || entry.intervalMs === 0) continue;\n\t\t\tconst lease = this.lease(entry.taskId);\n\t\t\tif (lease) await this.observeOutput(entry, lease, at);\n\t\t}\n\t}\n\n\t/** Current retained output size; growth since the last look dates the shell's last output. */\n\tprivate async observeOutput(entry: Tracked, lease: TaskLease, at: number): Promise<bigint | undefined> {\n\t\tconst end = await findOutputEnd(this.options.supervisor, lease, entry.outputEnd);\n\t\tif (end === undefined) return undefined;\n\t\tif (end > entry.outputEnd) {\n\t\t\tentry.outputEnd = end;\n\t\t\tentry.lastActivityAt = at;\n\t\t}\n\t\treturn end;\n\t}\n\n\tprivate async outputTail(lease: TaskLease, end: bigint): Promise<string[]> {\n\t\tif (end === 0n) return [];\n\t\tconst start = end > BigInt(OUTPUT_TAIL_BYTES) ? end - BigInt(OUTPUT_TAIL_BYTES) : 0n;\n\t\tconst page = await this.options.supervisor.readTaskOutput(lease, {\n\t\t\tstart: String(start),\n\t\t\tmaximumBytes: OUTPUT_TAIL_BYTES,\n\t\t});\n\t\tif (!page.ok) return [];\n\t\tconst lines = taskOutputText(page.value).split(\"\\n\");\n\t\t// The window can open mid-line; that fragment is not a line of output.\n\t\tif (start > 0n) lines.shift();\n\t\treturn lines\n\t\t\t.map((line) => {\n\t\t\t\t// A CRLF ending is not a redraw; a carriage return inside a line redraws it, so its last state counts.\n\t\t\t\tconst ended = line.replace(/\\r+$/, \"\");\n\t\t\t\treturn singleLine(ended.slice(ended.lastIndexOf(\"\\r\") + 1), LINE_CHARS).trimEnd();\n\t\t\t})\n\t\t\t.filter((line) => line.trim().length > 0)\n\t\t\t.slice(-OUTPUT_TAIL_LINES);\n\t}\n}\n\n/**\n * Retained output size of a running shell, found with one-byte reads: a read past the end returns nothing. Gallops\n * from the last known size, then bisects, so a large burst of output costs a few dozen tiny reads, not a full scan.\n */\nasync function findOutputEnd(supervisor: TaskSupervisor, lease: TaskLease, from: bigint): Promise<bigint | undefined> {\n\tconst probe = async (offset: bigint): Promise<{ before: boolean; end: bigint } | undefined> => {\n\t\tconst page = await supervisor.readTaskOutput(lease, { start: String(offset), maximumBytes: 1 });\n\t\tif (!page.ok) return undefined;\n\t\tif (page.value.nextOffset !== undefined) return { before: true, end: BigInt(page.value.nextOffset) };\n\t\tlet end = offset;\n\t\tfor (const chunk of page.value.chunks) if (BigInt(chunk.offsets.end) > end) end = BigInt(chunk.offsets.end);\n\t\tfor (const range of page.value.omittedRanges) if (BigInt(range.end) > end) end = BigInt(range.end);\n\t\t// No byte beyond this page: the output ends at its last byte, or at or before `offset` when it is empty.\n\t\treturn { before: end > offset, end };\n\t};\n\tlet low = from;\n\tconst first = await probe(low);\n\tif (!first) return undefined;\n\tif (!first.before) return first.end > from ? first.end : from;\n\tlet step = 65_536n;\n\tlet high = low + step;\n\tfor (;;) {\n\t\tconst result = await probe(high);\n\t\tif (!result) return undefined;\n\t\tif (!result.before) {\n\t\t\tif (result.end > high) return result.end;\n\t\t\tbreak;\n\t\t}\n\t\tlow = high;\n\t\tstep *= 2n;\n\t\thigh = low + step;\n\t}\n\t// The output ends after `low` and at or before `high`.\n\twhile (high - low > 1n) {\n\t\tconst middle = low + (high - low) / 2n;\n\t\tconst result = await probe(middle);\n\t\tif (!result) return undefined;\n\t\tif (result.before) low = middle;\n\t\telse if (result.end > middle) return result.end;\n\t\telse high = middle;\n\t}\n\treturn high;\n}\n"]}
1
+ {"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../../src/core/tasks/heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EACN,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,2BAA2B,GAI3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAKN,wBAAwB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type { NativeEvent, OwnerSnapshot, TaskId, TaskRecord } from \"./contracts.js\";\nimport {\n\tDEFAULT_TASK_HEARTBEAT_MS,\n\tformatTaskHeartbeat,\n\tisValidTaskHeartbeatMs,\n\tsingleLine,\n\tTASK_HEARTBEAT_MESSAGE_TYPE,\n\ttype TaskHeartbeatDetails,\n\ttype TaskHeartbeatMessage,\n\ttype TaskHeartbeatTask,\n} from \"./heartbeat-notice.js\";\nimport {\n\ttype OwnerLease,\n\ttype TaskLease,\n\ttype TaskSubscription,\n\ttype TaskSupervisor,\n\ttaskOwnTranscriptEntries,\n} from \"./supervisor.js\";\n\nexport * from \"./heartbeat-notice.js\";\n\n/** Tasks described in full by one notice; further due tasks are only listed. */\nexport const TASK_HEARTBEAT_DETAIL_LIMIT = 8;\n/** Further due tasks listed by name in one notice; the rest are counted. */\nexport const TASK_HEARTBEAT_LIST_LIMIT = 20;\n/** Boundaries due within this window (capped at a quarter cadence) join the notice that is going out. */\nexport const TASK_HEARTBEAT_COALESCE_MS = 60_000;\n/** While the owner has not read the previous notice, due tasks wait and are rechecked this often. */\nexport const TASK_HEARTBEAT_RECHECK_MS = 30_000;\n/** How often a running shell's output is sampled to date its last output. */\nexport const TASK_HEARTBEAT_OUTPUT_SAMPLE_MS = 30_000;\nconst OUTPUT_TAIL_BYTES = 2048;\nconst OUTPUT_TAIL_LINES = 6;\nconst LINE_CHARS = 160;\nconst TITLE_CHARS = 120;\n/** Longest delay a host timer accepts before it overflows to an immediate fire. */\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/** Where an owner's heartbeats go. The host binds its own chat; nothing here is model-provided. */\nexport interface TaskHeartbeatDelivery {\n\t/** Cadence for tasks launched without their own `heartbeatMs`; `0` disables. */\n\tdefaultIntervalMs(): number;\n\t/** Whether a heartbeat this owner already sent is still waiting, unread, in its chat. */\n\thasUnreadHeartbeat(): boolean;\n\tdeliver(message: TaskHeartbeatMessage): Promise<void>;\n}\n\n/** The owner's default cadence, or the built-in one when its setting cannot be read or is out of range. */\nexport function defaultTaskHeartbeatMs(delivery: Pick<TaskHeartbeatDelivery, \"defaultIntervalMs\">): number {\n\ttry {\n\t\tconst configured = delivery.defaultIntervalMs();\n\t\treturn isValidTaskHeartbeatMs(configured) ? configured : DEFAULT_TASK_HEARTBEAT_MS;\n\t} catch {\n\t\treturn DEFAULT_TASK_HEARTBEAT_MS;\n\t}\n}\n\nexport interface TaskHeartbeatClock {\n\tnow(): number;\n\tsetTimeout(run: () => void, delayMs: number): object;\n\tclearTimeout(handle: object): void;\n}\n\nconst systemClock: TaskHeartbeatClock = {\n\tnow: () => Date.now(),\n\tsetTimeout: (run, delayMs) => {\n\t\tconst handle = setTimeout(run, delayMs);\n\t\thandle.unref();\n\t\treturn handle;\n\t},\n\tclearTimeout: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),\n};\n\nexport interface TaskHeartbeatMonitorOptions {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n\t/** Read on every use, so a replaced session's binding takes over the same owner. */\n\tdelivery: () => TaskHeartbeatDelivery | undefined;\n\tclock?: TaskHeartbeatClock;\n}\n\ntype Tracked = {\n\ttaskId: TaskId;\n\trecord: TaskRecord;\n\t/** First observed running: the anchor of the cadence. */\n\tstartedAt: number;\n\t/** Frozen when the task is first observed; `0` disables. */\n\tintervalMs: number;\n\t/** Next boundary `startedAt + n × intervalMs`; absent when disabled. */\n\tnextAt?: number;\n\tlastActivityAt?: number;\n\tactivityKey: string;\n\t/** Shells: retained output bytes observed so far. */\n\toutputEnd: bigint;\n};\n\nfunction activityKey(task: TaskRecord): string {\n\treturn JSON.stringify([task.currentAction, task.metrics, task.attention, task.model]);\n}\n\n/** Whether the newest message in a child's history is an assistant turn whose tool calls have not returned yet. */\nfunction endsInToolCall(entries: NonNullable<ReturnType<typeof taskOwnTranscriptEntries>>): boolean {\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type !== \"message\") continue;\n\t\tconst message = entry.message;\n\t\treturn message.role === \"assistant\" && message.content.some((block) => block.type === \"toolCall\");\n\t}\n\treturn false;\n}\n\n/** First boundary on the `startedAt + n × intervalMs` series strictly after `after`. */\nfunction nextBoundary(startedAt: number, intervalMs: number, after: number): number {\n\tconst n = Math.max(1, Math.floor((after - startedAt) / intervalMs) + 1);\n\tconst boundary = startedAt + n * intervalMs;\n\treturn boundary > after ? boundary : startedAt + (n + 1) * intervalMs;\n}\n\nfunction byBoundary(a: Tracked, b: Tracked): number {\n\tconst left = a.nextAt ?? Number.POSITIVE_INFINITY;\n\tconst right = b.nextAt ?? Number.POSITIVE_INFINITY;\n\tif (left !== right) return left - right;\n\treturn a.taskId < b.taskId ? -1 : a.taskId > b.taskId ? 1 : 0;\n}\n\n/**\n * Periodic \"is this still making progress?\" notices for one task owner's running shells and subagents.\n *\n * It follows the workflow heartbeat rules: boundaries are anchored at the task's start and never at the previous\n * delivery, missed boundaries are skipped rather than replayed, and only one notice per owner is outstanding. Unlike\n * a workflow run, an owner can have many tasks, so tasks due together share one bounded notice, and a task due while\n * the owner has not read the previous notice waits for it rather than losing its turn.\n */\nexport class TaskHeartbeatMonitor {\n\tprivate readonly options: TaskHeartbeatMonitorOptions;\n\tprivate readonly clock: TaskHeartbeatClock;\n\tprivate readonly tracked = new Map<TaskId, Tracked>();\n\tprivate subscription?: TaskSubscription;\n\tprivate timer?: object;\n\t/** The time the current timer wakes for, so an unchanged schedule keeps its timer. */\n\tprivate timerAt?: number;\n\tprivate busy = false;\n\tprivate disposed = false;\n\tprivate recheckAt?: number;\n\tprivate nextSampleAt?: number;\n\n\tconstructor(options: TaskHeartbeatMonitorOptions) {\n\t\tthis.options = options;\n\t\tthis.clock = options.clock ?? systemClock;\n\t}\n\n\t/** Begin watching the owner. Idempotent. */\n\tstart(): void {\n\t\tif (this.subscription || this.disposed) return;\n\t\tconst watched = this.options.supervisor.watchOwnerTasks(this.options.owner);\n\t\tif (!watched.ok) return;\n\t\tthis.subscription = watched.value;\n\t\tthis.subscription.onReconcile = (snapshot, events) => this.reconcile(snapshot, events);\n\t\tthis.reconcile(this.subscription.snapshot, []);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.subscription?.dispose();\n\t\tthis.subscription = undefined;\n\t\tthis.tracked.clear();\n\t\tthis.disarm();\n\t}\n\n\tprivate reconcile(snapshot: OwnerSnapshot, events: readonly NativeEvent[]): void {\n\t\tif (this.disposed) return;\n\t\tif (snapshot.state !== \"open\") {\n\t\t\tif (snapshot.state === \"closed\") this.dispose();\n\t\t\telse {\n\t\t\t\tthis.tracked.clear();\n\t\t\t\tthis.disarm();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst at = this.clock.now();\n\t\tconst reported = new Set<TaskId>();\n\t\tfor (const event of events) if (event.payload.kind === \"task-activity\") reported.add(event.payload.ref.taskId);\n\t\tconst running = new Set<TaskId>();\n\t\tfor (const task of snapshot.tasks) {\n\t\t\t// Queued, stopping, paused and finished tasks do not heartbeat.\n\t\t\tif (task.execution.kind !== \"running\") continue;\n\t\t\tconst id = task.ref.taskId;\n\t\t\trunning.add(id);\n\t\t\tconst key = activityKey(task);\n\t\t\tconst entry = this.tracked.get(id);\n\t\t\tif (entry) {\n\t\t\t\tentry.record = task;\n\t\t\t\tif (key !== entry.activityKey || reported.has(id)) {\n\t\t\t\t\tentry.activityKey = key;\n\t\t\t\t\tentry.lastActivityAt = at;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst intervalMs = this.resolveInterval(task);\n\t\t\tthis.tracked.set(id, {\n\t\t\t\ttaskId: id,\n\t\t\t\trecord: task,\n\t\t\t\tstartedAt: at,\n\t\t\t\tintervalMs,\n\t\t\t\t...(intervalMs > 0 ? { nextAt: at + intervalMs } : {}),\n\t\t\t\t...(reported.has(id) ? { lastActivityAt: at } : {}),\n\t\t\t\tactivityKey: key,\n\t\t\t\toutputEnd: 0n,\n\t\t\t});\n\t\t}\n\t\tfor (const id of [...this.tracked.keys()]) if (!running.has(id)) this.tracked.delete(id);\n\t\tif (!this.hasSampledShells()) this.nextSampleAt = undefined;\n\t\telse this.nextSampleAt ??= at + TASK_HEARTBEAT_OUTPUT_SAMPLE_MS;\n\t\tthis.arm();\n\t}\n\n\tprivate resolveInterval(task: TaskRecord): number {\n\t\t// Owners with a heartbeat binding fix each task's cadence on its record at admission.\n\t\tif (task.heartbeatMs !== undefined) return isValidTaskHeartbeatMs(task.heartbeatMs) ? task.heartbeatMs : 0;\n\t\tconst delivery = this.options.delivery();\n\t\treturn delivery ? defaultTaskHeartbeatMs(delivery) : DEFAULT_TASK_HEARTBEAT_MS;\n\t}\n\n\tprivate hasSampledShells(): boolean {\n\t\tfor (const entry of this.tracked.values())\n\t\t\tif (entry.record.kind === \"command\" && entry.intervalMs > 0) return true;\n\t\treturn false;\n\t}\n\n\tprivate disarm(): void {\n\t\tif (this.timer === undefined) return;\n\t\tthis.clock.clearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tthis.timerAt = undefined;\n\t}\n\n\tprivate arm(): void {\n\t\tif (this.disposed || this.busy) {\n\t\t\tthis.disarm();\n\t\t\treturn;\n\t\t}\n\t\t// A blocked owner cannot receive anything before its recheck, however many tasks come due meanwhile.\n\t\tlet wakeAt = this.recheckAt ?? Number.POSITIVE_INFINITY;\n\t\tif (this.recheckAt === undefined)\n\t\t\tfor (const entry of this.tracked.values())\n\t\t\t\tif (entry.nextAt !== undefined && entry.nextAt < wakeAt) wakeAt = entry.nextAt;\n\t\tif (this.nextSampleAt !== undefined && this.nextSampleAt < wakeAt) wakeAt = this.nextSampleAt;\n\t\t// Activity reconciles many times a second; it rarely moves the next wake-up.\n\t\tif (this.timer !== undefined && this.timerAt === wakeAt) return;\n\t\tthis.disarm();\n\t\tif (!Number.isFinite(wakeAt)) return;\n\t\tconst delay = Math.min(Math.max(1, Math.ceil(wakeAt - this.clock.now())), MAX_TIMER_DELAY_MS);\n\t\tthis.timerAt = wakeAt;\n\t\tthis.timer = this.clock.setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tthis.timerAt = undefined;\n\t\t\tvoid this.wake();\n\t\t}, delay);\n\t}\n\n\tprivate async wake(): Promise<void> {\n\t\tif (this.disposed || this.busy) return;\n\t\tthis.busy = true;\n\t\ttry {\n\t\t\tconst at = this.clock.now();\n\t\t\tif (this.nextSampleAt !== undefined && this.nextSampleAt <= at) {\n\t\t\t\tawait this.sampleShellOutput(at);\n\t\t\t\tthis.nextSampleAt = this.hasSampledShells() ? at + TASK_HEARTBEAT_OUTPUT_SAMPLE_MS : undefined;\n\t\t\t}\n\t\t\tawait this.beat(at);\n\t\t} catch {\n\t\t\t// A failed check skips this boundary; the next one is already scheduled.\n\t\t} finally {\n\t\t\tthis.busy = false;\n\t\t\tthis.arm();\n\t\t}\n\t}\n\n\tprivate async beat(at: number): Promise<void> {\n\t\tif (this.recheckAt !== undefined && this.recheckAt > at) return;\n\t\tthis.recheckAt = undefined;\n\t\tconst entries = [...this.tracked.values()];\n\t\tif (!entries.some((entry) => entry.nextAt !== undefined && entry.nextAt <= at)) return;\n\t\tconst delivery = this.options.delivery();\n\t\tlet unread = false;\n\t\ttry {\n\t\t\tunread = delivery?.hasUnreadHeartbeat() === true;\n\t\t} catch {\n\t\t\tunread = false;\n\t\t}\n\t\tif (unread) {\n\t\t\t// One outstanding notice per owner: due tasks stay owed and join the next notice instead of stacking.\n\t\t\tthis.recheckAt = at + TASK_HEARTBEAT_RECHECK_MS;\n\t\t\treturn;\n\t\t}\n\t\tconst batch = entries\n\t\t\t.filter(\n\t\t\t\t(entry) =>\n\t\t\t\t\tentry.nextAt !== undefined &&\n\t\t\t\t\tentry.nextAt <= at + Math.min(TASK_HEARTBEAT_COALESCE_MS, entry.intervalMs / 4),\n\t\t\t)\n\t\t\t.sort(byBoundary);\n\t\tfor (const entry of batch)\n\t\t\tentry.nextAt = nextBoundary(entry.startedAt, entry.intervalMs, Math.max(at, entry.nextAt ?? at));\n\t\tif (!delivery) return;\n\t\tconst details = await this.describe(batch, at);\n\t\t// A task that finished while its notice was being prepared is no longer mentioned.\n\t\tconst live = (taskId: string) => this.tracked.has(taskId as TaskId);\n\t\tdetails.tasks = details.tasks.filter((task) => live(task.taskId));\n\t\tdetails.more = details.more.filter((task) => live(task.taskId));\n\t\tdetails.moreCount = batch.slice(TASK_HEARTBEAT_DETAIL_LIMIT).filter((entry) => live(entry.taskId)).length;\n\t\tif (details.tasks.length === 0 || this.disposed) return;\n\t\tawait delivery.deliver({\n\t\t\tcustomType: TASK_HEARTBEAT_MESSAGE_TYPE,\n\t\t\tcontent: formatTaskHeartbeat(details),\n\t\t\tdisplay: true,\n\t\t\tdetails,\n\t\t});\n\t}\n\n\tprivate async describe(batch: readonly Tracked[], at: number): Promise<TaskHeartbeatDetails> {\n\t\tconst detailed = batch.slice(0, TASK_HEARTBEAT_DETAIL_LIMIT);\n\t\tconst rest = batch.slice(TASK_HEARTBEAT_DETAIL_LIMIT);\n\t\tconst tasks: TaskHeartbeatTask[] = [];\n\t\tfor (const entry of detailed) tasks.push(await this.describeTask(entry, at));\n\t\treturn {\n\t\t\tscheduledAt: at,\n\t\t\ttasks,\n\t\t\tmore: rest.slice(0, TASK_HEARTBEAT_LIST_LIMIT).map((entry) => ({\n\t\t\t\ttaskId: entry.taskId,\n\t\t\t\tkind: entry.record.kind,\n\t\t\t\ttitle: singleLine(entry.record.title, TITLE_CHARS),\n\t\t\t})),\n\t\t\tmoreCount: rest.length,\n\t\t};\n\t}\n\n\tprivate async describeTask(entry: Tracked, at: number): Promise<TaskHeartbeatTask> {\n\t\tconst task = entry.record;\n\t\tconst lease = this.lease(entry.taskId);\n\t\tconst described: TaskHeartbeatTask = {\n\t\t\ttaskId: entry.taskId,\n\t\t\tkind: task.kind,\n\t\t\ttitle: singleLine(task.title, TITLE_CHARS),\n\t\t\t...(task.agentName === undefined ? {} : { agentName: singleLine(task.agentName, TITLE_CHARS) }),\n\t\t\t...(task.kind === \"agent\" && task.model !== undefined ? { model: task.model } : {}),\n\t\t\t...(task.kind === \"agent\" && task.requestedModel !== undefined ? { requestedModel: task.requestedModel } : {}),\n\t\t\telapsedMs: Math.max(0, at - entry.startedAt),\n\t\t\tintervalMs: entry.intervalMs,\n\t\t};\n\t\tif (task.kind === \"command\" && lease) {\n\t\t\tconst end = await this.observeOutput(entry, lease, at);\n\t\t\tif (end !== undefined) described.output = { bytes: Number(end), tail: await this.outputTail(lease, end) };\n\t\t}\n\t\tif (entry.lastActivityAt !== undefined) described.lastActivityAgoMs = Math.max(0, at - entry.lastActivityAt);\n\t\tif (task.kind === \"agent\") {\n\t\t\tconst entries = lease ? taskOwnTranscriptEntries(lease) : undefined;\n\t\t\tif (task.currentAction)\n\t\t\t\tdescribed.currentAction = {\n\t\t\t\t\ttool: singleLine(task.currentAction.tool, 60),\n\t\t\t\t\ttext: singleLine(task.currentAction.text, LINE_CHARS),\n\t\t\t\t\t// The record keeps the last reported action after its tool returns. The child's own history says\n\t\t\t\t\t// whether a call is still outstanding: its last message is an assistant turn that called tools.\n\t\t\t\t\trunning: entries !== undefined && endsInToolCall(entries),\n\t\t\t\t};\n\t\t\tif (task.metrics?.toolCount !== undefined) described.toolCount = task.metrics.toolCount;\n\t\t\tif (task.metrics?.tokenCount !== undefined) described.tokenCount = task.metrics.tokenCount;\n\t\t\tif (entries)\n\t\t\t\tdescribed.turnCount = entries.filter(\n\t\t\t\t\t(item) => item.type === \"message\" && item.message.role === \"assistant\",\n\t\t\t\t).length;\n\t\t}\n\t\tif (task.attention.kind === \"input-needed\")\n\t\t\tdescribed.attention = `waiting for input: ${singleLine(task.attention.prompt, LINE_CHARS)}`;\n\t\telse if (task.attention.kind === \"no-recent-activity\") described.attention = \"no recent activity\";\n\t\treturn described;\n\t}\n\n\tprivate lease(taskId: TaskId): TaskLease | undefined {\n\t\tconst found = this.options.supervisor.lookupTask(this.options.owner, taskId);\n\t\treturn found.ok ? found.value : undefined;\n\t}\n\n\tprivate async sampleShellOutput(at: number): Promise<void> {\n\t\tfor (const entry of [...this.tracked.values()]) {\n\t\t\tif (entry.record.kind !== \"command\" || entry.intervalMs === 0) continue;\n\t\t\tconst lease = this.lease(entry.taskId);\n\t\t\tif (lease) await this.observeOutput(entry, lease, at);\n\t\t}\n\t}\n\n\t/** Current retained output size; growth since the last look dates the shell's last output. */\n\tprivate async observeOutput(entry: Tracked, lease: TaskLease, at: number): Promise<bigint | undefined> {\n\t\tconst end = await findOutputEnd(this.options.supervisor, lease, entry.outputEnd);\n\t\tif (end === undefined) return undefined;\n\t\tif (end > entry.outputEnd) {\n\t\t\tentry.outputEnd = end;\n\t\t\tentry.lastActivityAt = at;\n\t\t}\n\t\treturn end;\n\t}\n\n\tprivate async outputTail(lease: TaskLease, end: bigint): Promise<string[]> {\n\t\tif (end === 0n) return [];\n\t\tconst start = end > BigInt(OUTPUT_TAIL_BYTES) ? end - BigInt(OUTPUT_TAIL_BYTES) : 0n;\n\t\tconst page = await this.options.supervisor.readTaskOutput(lease, {\n\t\t\tstart: String(start),\n\t\t\tmaximumBytes: OUTPUT_TAIL_BYTES,\n\t\t});\n\t\tif (!page.ok) return [];\n\t\tconst lines = taskOutputText(page.value).split(\"\\n\");\n\t\t// The window can open mid-line; that fragment is not a line of output.\n\t\tif (start > 0n) lines.shift();\n\t\treturn lines\n\t\t\t.map((line) => {\n\t\t\t\t// A CRLF ending is not a redraw; a carriage return inside a line redraws it, so its last state counts.\n\t\t\t\tconst ended = line.replace(/\\r+$/, \"\");\n\t\t\t\treturn singleLine(ended.slice(ended.lastIndexOf(\"\\r\") + 1), LINE_CHARS).trimEnd();\n\t\t\t})\n\t\t\t.filter((line) => line.trim().length > 0)\n\t\t\t.slice(-OUTPUT_TAIL_LINES);\n\t}\n}\n\n/**\n * Retained output size of a running shell, found with one-byte reads: a read past the end returns nothing. Gallops\n * from the last known size, then bisects, so a large burst of output costs a few dozen tiny reads, not a full scan.\n */\nasync function findOutputEnd(supervisor: TaskSupervisor, lease: TaskLease, from: bigint): Promise<bigint | undefined> {\n\tconst probe = async (offset: bigint): Promise<{ before: boolean; end: bigint } | undefined> => {\n\t\tconst page = await supervisor.readTaskOutput(lease, { start: String(offset), maximumBytes: 1 });\n\t\tif (!page.ok) return undefined;\n\t\tif (page.value.nextOffset !== undefined) return { before: true, end: BigInt(page.value.nextOffset) };\n\t\tlet end = offset;\n\t\tfor (const chunk of page.value.chunks) if (BigInt(chunk.offsets.end) > end) end = BigInt(chunk.offsets.end);\n\t\tfor (const range of page.value.omittedRanges) if (BigInt(range.end) > end) end = BigInt(range.end);\n\t\t// No byte beyond this page: the output ends at its last byte, or at or before `offset` when it is empty.\n\t\treturn { before: end > offset, end };\n\t};\n\tlet low = from;\n\tconst first = await probe(low);\n\tif (!first) return undefined;\n\tif (!first.before) return first.end > from ? first.end : from;\n\tlet step = 65_536n;\n\tlet high = low + step;\n\tfor (;;) {\n\t\tconst result = await probe(high);\n\t\tif (!result) return undefined;\n\t\tif (!result.before) {\n\t\t\tif (result.end > high) return result.end;\n\t\t\tbreak;\n\t\t}\n\t\tlow = high;\n\t\tstep *= 2n;\n\t\thigh = low + step;\n\t}\n\t// The output ends after `low` and at or before `high`.\n\twhile (high - low > 1n) {\n\t\tconst middle = low + (high - low) / 2n;\n\t\tconst result = await probe(middle);\n\t\tif (!result) return undefined;\n\t\tif (result.before) low = middle;\n\t\telse if (result.end > middle) return result.end;\n\t\telse high = middle;\n\t}\n\treturn high;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/supervisor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,u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E,CAAC,CAAC,eAAe,GACtB,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAgCtD;IACD;;;;;;OAMG;IACH,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,UAAU,CAAC,CAc5F;CA2CD"}
@@ -197,6 +197,8 @@ function observation(value) {
197
197
  // Native records own lifecycle and mutable execution metadata. Routing provenance is
198
198
  // immutable host metadata, retained for the same environment lifetime as task records.
199
199
  const routerSelections = new Map();
200
+ // The model each launch asked for, immutable launch metadata like its routing provenance.
201
+ const requestedModels = new Map();
200
202
  // Launch heartbeat cadences, keyed by owner and launch operation rather than task id: a command's
201
203
  // record can be observed before its native start resolves, and it must already carry its cadence.
202
204
  const launchHeartbeats = new Map();
@@ -216,6 +218,7 @@ function record(value) {
216
218
  if (value.kind !== "agent" && value.kind !== "command")
217
219
  throw new Error(`Invalid native task kind: ${value.kind}`);
218
220
  const routerSelection = routerSelections.get(value.ref.taskId);
221
+ const requestedModel = requestedModels.get(value.ref.taskId);
219
222
  const heartbeatMs = launchHeartbeats.get(launchKey(value.ref.ownerId, value.launchOperationId));
220
223
  return {
221
224
  ref: reference(value.ref),
@@ -229,6 +232,7 @@ function record(value) {
229
232
  ...(value.model === undefined ? {} : { model: value.model }),
230
233
  ...(value.thinking === undefined ? {} : { thinking: value.thinking }),
231
234
  ...(routerSelection ? { routerSelection } : {}),
235
+ ...(requestedModel === undefined ? {} : { requestedModel }),
232
236
  ...(heartbeatMs === undefined ? {} : { heartbeatMs }),
233
237
  execution: execution(value.execution),
234
238
  observation: observation(value.observation),
@@ -848,6 +852,8 @@ export class TaskSupervisor {
848
852
  return { ok: true, value: existing };
849
853
  if (intent.routerSelection)
850
854
  routerSelections.set(id, Object.freeze({ ...intent.routerSelection }));
855
+ if (intent.requestedModel)
856
+ requestedModels.set(id, intent.requestedModel);
851
857
  const task = new TaskCapability();
852
858
  Object.freeze(task);
853
859
  const taskState = {