@astralyn/pi 0.84.6 → 0.84.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/core/compaction/compaction.d.ts +2 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +7 -7
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/extensions/background/index.d.ts.map +1 -1
- package/dist/extensions/background/index.js +48 -72
- package/dist/extensions/background/index.js.map +1 -1
- package/dist/extensions/background/manager.d.ts.map +1 -1
- package/dist/extensions/background/manager.js +5 -3
- package/dist/extensions/background/manager.js.map +1 -1
- package/dist/extensions/background/registry.d.ts +11 -13
- package/dist/extensions/background/registry.d.ts.map +1 -1
- package/dist/extensions/background/registry.js +71 -80
- package/dist/extensions/background/registry.js.map +1 -1
- package/dist/extensions/background/render.d.ts.map +1 -1
- package/dist/extensions/background/render.js +17 -4
- package/dist/extensions/background/render.js.map +1 -1
- package/dist/extensions/deepwiki/constants.d.ts +2 -2
- package/dist/extensions/deepwiki/constants.d.ts.map +1 -1
- package/dist/extensions/deepwiki/constants.js +5 -5
- package/dist/extensions/deepwiki/constants.js.map +1 -1
- package/dist/extensions/deepwiki/schema.js +1 -1
- package/dist/extensions/deepwiki/schema.js.map +1 -1
- package/dist/extensions/question/constants.d.ts +2 -2
- package/dist/extensions/question/constants.d.ts.map +1 -1
- package/dist/extensions/question/constants.js +5 -2
- package/dist/extensions/question/constants.js.map +1 -1
- package/dist/extensions/router/dialog-host.d.ts +60 -0
- package/dist/extensions/router/dialog-host.d.ts.map +1 -0
- package/dist/extensions/router/dialog-host.js +196 -0
- package/dist/extensions/router/dialog-host.js.map +1 -0
- package/dist/extensions/router/probe.d.ts.map +1 -1
- package/dist/extensions/router/probe.js +2 -0
- package/dist/extensions/router/probe.js.map +1 -1
- package/dist/extensions/router/ui.d.ts.map +1 -1
- package/dist/extensions/router/ui.js +117 -67
- package/dist/extensions/router/ui.js.map +1 -1
- package/dist/extensions/subagent/activity.d.ts +9 -0
- package/dist/extensions/subagent/activity.d.ts.map +1 -1
- package/dist/extensions/subagent/activity.js +21 -0
- package/dist/extensions/subagent/activity.js.map +1 -1
- package/dist/extensions/subagent/agents-command.d.ts.map +1 -1
- package/dist/extensions/subagent/agents-command.js +355 -71
- package/dist/extensions/subagent/agents-command.js.map +1 -1
- package/dist/extensions/subagent/agents.d.ts.map +1 -1
- package/dist/extensions/subagent/agents.js +7 -3
- package/dist/extensions/subagent/agents.js.map +1 -1
- package/dist/extensions/subagent/constants.d.ts +1 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -1
- package/dist/extensions/subagent/constants.js +4 -0
- package/dist/extensions/subagent/constants.js.map +1 -1
- package/dist/extensions/subagent/index.js +2 -2
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent/render.d.ts.map +1 -1
- package/dist/extensions/subagent/render.js +1 -7
- package/dist/extensions/subagent/render.js.map +1 -1
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
- package/dist/extensions/subagent/sdk-runner.js +19 -0
- package/dist/extensions/subagent/sdk-runner.js.map +1 -1
- package/dist/extensions/subagent/settings.d.ts.map +1 -1
- package/dist/extensions/subagent/settings.js +11 -4
- package/dist/extensions/subagent/settings.js.map +1 -1
- package/dist/extensions/subagent/state.d.ts +9 -0
- package/dist/extensions/subagent/state.d.ts.map +1 -1
- package/dist/extensions/subagent/state.js +33 -2
- package/dist/extensions/subagent/state.js.map +1 -1
- package/dist/extensions/subagent/ui/model-list.d.ts +1 -0
- package/dist/extensions/subagent/ui/model-list.d.ts.map +1 -1
- package/dist/extensions/subagent/ui/model-list.js +5 -0
- package/dist/extensions/subagent/ui/model-list.js.map +1 -1
- package/dist/extensions/todo/constants.d.ts +1 -1
- package/dist/extensions/todo/constants.d.ts.map +1 -1
- package/dist/extensions/todo/constants.js +10 -27
- package/dist/extensions/todo/constants.js.map +1 -1
- package/dist/extensions/todo/state.d.ts.map +1 -1
- package/dist/extensions/todo/state.js +27 -16
- package/dist/extensions/todo/state.js.map +1 -1
- package/dist/extensions/todo/view.d.ts.map +1 -1
- package/dist/extensions/todo/view.js +16 -5
- package/dist/extensions/todo/view.js.map +1 -1
- package/docs/bundled/extensions/background.md +3 -3
- package/docs/bundled/extensions/todo.md +2 -2
- package/docs/compaction.md +2 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/background/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAEN,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACN,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,cAAc,EAKd,gBAAgB,EAChB,cAAc,EAEd,eAAe,EACf,eAAe,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,YAAY,EACZ,4BAA4B,EAC5B,YAAY,EACZ,cAAc,GAEd,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AACvC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,0DAA0D;AAC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KAAK,UAAU,qBAAqB,CAAC,GAA4B,EAAE,QAAgC;IAClG,mFAAmF;IACnF,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAClB,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CACjC,IAAI,mBAAmB,CAAC;QACvB,GAAG;QACH,KAAK;QACL,WAAW;QACX,IAAI,EAAE;YACL,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE;YACrC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC;SACpE;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;KAC9B,CAAC,CACH,CAAC;AACH,CAAC;AAED,eAAe,yBAAyB,EAAE,CAAC","sourcesContent":["/**\n * background — run bash commands in the background.\n *\n * Tools: a single `bg` tool with five actions. create starts a task and\n * returns immediately; the result arrives as a <background-task> notification\n * (queued behind the current run while streaming, waking the agent when\n * idle). read returns a bounded slice of a task's output file; wait blocks\n * (bounded) for a task's completion and delivers it inline — the followUp\n * notification is suppressed so the completion is delivered exactly once;\n * kill stops a single task; list enumerates known tasks. /bg opens the\n * interactive task manager. Running counts surface in the footer via\n * ctx.ui.setStatus.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport {\n\ttype BashOperations,\n\tcreateLocalBashOperations,\n\tMAX_TIMEOUT_SECONDS,\n\tresolveSpawnContext,\n} from \"../../core/tools/bash.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize } from \"../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { BackgroundTasksMenu } from \"./manager.ts\";\nimport {\n\tBackgroundTaskRegistry,\n\tBG_WAIT_DEFAULT_MS,\n\tBG_WAIT_MAX_MS,\n\tBG_WAIT_MIN_MS,\n\ttype BgStallNotification,\n\ttype BgTask,\n\ttype BgTaskNotification,\n\ttype BgTaskStatus,\n\tfirstCommandLine,\n\tformatDuration,\n\ttype ResolveTaskResult,\n\treadOutputSince,\n\treadOutputSlice,\n} from \"./registry.ts\";\nimport {\n\tcommandLabel,\n\trenderBackgroundNotification,\n\trenderBgCall,\n\trenderBgResult,\n\ttype WaitLiveProbe,\n} from \"./render.ts\";\n\nexport const BG_NOTIFICATION_TYPE = \"background-task\";\nconst BG_LOGS_DEFAULT_BYTES = 8 * 1024;\nconst BG_LOGS_MIN_BYTES = 256;\nconst BG_LIST_FINISHED_SHOWN = 5;\n/** Bounded output delta returned by a successful wait. */\nconst BG_WAIT_DELTA_BYTES = 32 * 1024;\n/** Tail peek included in a wait timeout result so progress stays visible. */\nconst BG_WAIT_PEEK_BYTES = 2 * 1024;\n\nconst bgSchema = Type.Object({\n\taction: Type.Union(\n\t\t[Type.Literal(\"create\"), Type.Literal(\"read\"), Type.Literal(\"wait\"), Type.Literal(\"kill\"), Type.Literal(\"list\")],\n\t\t{ description: \"Which background-task operation to perform\" },\n\t),\n\t// — create —\n\tcommand: Type.Optional(\n\t\tType.String({ description: \"Bash command to run in the background (create). Do not append '&'\" }),\n\t),\n\tdescription: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Short label for the task, shown in /bg and notifications, e.g. 'dev server' (create)\",\n\t\t}),\n\t),\n\ttimeout: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: \"Kill the task after this many seconds; on expiry it is reported as timeout (create)\",\n\t\t}),\n\t),\n\t// — read / wait / kill —\n\ttaskId: Type.Optional(\n\t\tType.String({ description: \"Task id; a unique prefix is accepted, e.g. 'bg-3f' or '3f' (read/wait/kill)\" }),\n\t),\n\t// — read —\n\tmode: Type.Optional(\n\t\tType.Union([Type.Literal(\"tail\"), Type.Literal(\"head\")], {\n\t\t\tdescription: \"Read from the end (default) or the start of the output (read)\",\n\t\t}),\n\t),\n\tbytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Max bytes to return (read, default ${formatSize(BG_LOGS_DEFAULT_BYTES)}, max ${formatSize(DEFAULT_MAX_BYTES)})`,\n\t\t}),\n\t),\n\t// — wait —\n\twaitMs: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Max time to wait in ms, default ${BG_WAIT_DEFAULT_MS}, max ${BG_WAIT_MAX_MS} (wait)`,\n\t\t}),\n\t),\n\tsinceBytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription:\n\t\t\t\t\"Only return output written after this byte offset — take it from a previous read/wait result (wait)\",\n\t\t}),\n\t),\n});\n\nexport type BgInput = Static<typeof bgSchema>;\n\n/** Per-action inputs: validateAction guarantees the required fields before the cast. */\nexport type BgCreateInput = BgInput & { action: \"create\"; command: string };\nexport type BgReadInput = BgInput & { action: \"read\"; taskId: string };\nexport type BgWaitInput = BgInput & { action: \"wait\"; taskId: string };\nexport type BgKillInput = BgInput & { action: \"kill\"; taskId: string };\n\nexport interface BgCreateDetails {\n\taction: \"create\";\n\ttaskId: string;\n\toutputPath: string;\n\tcommand: string;\n\tdescription?: string;\n}\n\nexport interface BgReadDetails {\n\taction: \"read\";\n\ttaskId: string;\n\tmode: \"head\" | \"tail\";\n\tsliceBytes: number;\n\ttotalBytes: number;\n\toutputPath: string;\n}\n\nexport interface BgWaitDetails {\n\taction: \"wait\";\n\ttaskId: string;\n\t/** True when the wait window expired and the task is still running. */\n\ttimedOut: boolean;\n\tstatus: BgTaskStatus;\n\texitCode: number | null | undefined;\n\twaitedMs: number;\n\tdeltaBytes: number;\n\ttotalBytes: number;\n\tdeltaTruncated: boolean;\n\toutputPath: string;\n}\n\nexport interface BgKillDetails {\n\taction: \"kill\";\n\ttaskId: string;\n\tcommand: string;\n}\n\nexport interface BgListDetails {\n\taction: \"list\";\n\trunning: number;\n\tfinished: number;\n\tshown: number;\n\thidden: number;\n}\n\nexport type BgDetails = BgCreateDetails | BgReadDetails | BgWaitDetails | BgKillDetails | BgListDetails;\n\nexport interface BgNotificationDetails {\n\ttaskId: string;\n\tcommand: string;\n\tdescription?: string;\n\tstatus: BgTaskStatus;\n\t/** True for the one-shot \"waiting for interactive input\" signal; the task keeps running. */\n\tstalled?: true;\n\texitCode: number | null | undefined;\n\truntimeMs: number;\n\toutputPath: string;\n\ttotalBytes: number;\n\ttailText: string;\n\ttailTruncated: boolean;\n\terror?: string;\n\ttailError?: string;\n}\n\nexport function escapeXml(text: string): string {\n\treturn text\n\t\t.replaceAll(\"&\", \"&\")\n\t\t.replaceAll(\"<\", \"<\")\n\t\t.replaceAll(\">\", \">\")\n\t\t.replaceAll('\"', \""\")\n\t\t.replaceAll(\"'\", \"'\");\n}\n\n/**\n * Strip characters XML 1.0 forbids: C0 controls (except \\t \\n \\r), lone\n * surrogates (U+D800–U+DFFF), and the non-characters U+FFFE/U+FFFF.\n * sanitizeBinaryOutput does not remove the latter two classes, so this filter\n * is the authority for every text field in the notification XML.\n */\nexport function filterXmlCharacters(text: string): string {\n\tlet result = \"\";\n\tfor (const char of text) {\n\t\tconst code = char.codePointAt(0) ?? 0;\n\t\tif (\n\t\t\tcode === 0x09 ||\n\t\t\tcode === 0x0a ||\n\t\t\tcode === 0x0d ||\n\t\t\t(code >= 0x20 && code <= 0xd7ff) ||\n\t\t\t(code >= 0xe000 && code <= 0xfffd) ||\n\t\t\tcode >= 0x10000\n\t\t) {\n\t\t\tresult += char;\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function buildNotificationContent(notification: BgTaskNotification): string {\n\tconst task = notification.task;\n\tconst runtime = formatDuration((task.endedAt ?? task.startedAt) - task.startedAt);\n\tconst exitCode = task.exitCode === undefined || task.exitCode === null ? \"\" : ` exitCode=\"${task.exitCode}\"`;\n\t// filterXmlCharacters keeps \\t \\n \\r and every other XML-legal codepoint,\n\t// so each field below is valid XML 1.0 after escaping.\n\tconst xmlText = (text: string) => escapeXml(filterXmlCharacters(text));\n\tconst lines = [\n\t\t`<background-task id=\"${task.id}\" status=\"${task.status}\"${exitCode} runtime=\"${runtime}\">`,\n\t\t`<command>${xmlText(task.command)}</command>`,\n\t];\n\tif (task.description) {\n\t\tlines.push(`<description>${xmlText(task.description)}</description>`);\n\t}\n\tlines.push(`<output-file>${xmlText(task.outputPath)}</output-file>`);\n\tif (task.error) {\n\t\tlines.push(`<error>${xmlText(task.error)}</error>`);\n\t}\n\tif (notification.tailError) {\n\t\tlines.push(`<output-tail unavailable=\"${xmlText(notification.tailError)}\"/>`);\n\t} else {\n\t\tconst attrs = [\n\t\t\t`bytes=\"${notification.tailBytes}\"`,\n\t\t\t`totalBytes=\"${notification.totalBytes}\"`,\n\t\t\tnotification.tailTruncated ? 'truncated=\"true\"' : \"\",\n\t\t\tnotification.tailStartsMidLine ? 'startsMidLine=\"true\"' : \"\",\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\" \");\n\t\tconst tail = notification.tailText.length > 0 ? xmlText(notification.tailText) : \"(no output)\";\n\t\tlines.push(`<output-tail ${attrs}>`, tail.trimEnd(), \"</output-tail>\");\n\t}\n\tlines.push(\"</background-task>\");\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatStatusline(counts: { running: number; total: number; stalled?: number }): string | undefined {\n\tif (counts.total === 0) return undefined;\n\t// Stalled tasks are running tasks: report them separately so the counts add up.\n\tconst waiting = counts.stalled ?? 0;\n\tconst running = counts.running - waiting;\n\tconst ended = counts.total - counts.running;\n\tconst parts: string[] = [];\n\tif (running > 0) parts.push(`${running} running`);\n\tif (waiting > 0) parts.push(`${waiting} waiting for input`);\n\tif (ended > 0) parts.push(`${ended} done`);\n\treturn `bg ${parts.join(\" · \")}`;\n}\n\nexport function buildStallContent(notification: BgStallNotification): string {\n\tconst task = notification.task;\n\tconst runtime = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\tconst xmlText = (text: string) => escapeXml(filterXmlCharacters(text));\n\tconst lines = [\n\t\t`<background-task id=\"${task.id}\" status=\"running\" waiting-for-input=\"true\" runtime=\"${runtime}\">`,\n\t\t`<command>${xmlText(task.command)}</command>`,\n\t];\n\tif (task.description) {\n\t\tlines.push(`<description>${xmlText(task.description)}</description>`);\n\t}\n\tlines.push(`<output-file>${xmlText(task.outputPath)}</output-file>`);\n\tif (notification.tailError) {\n\t\tlines.push(`<output-tail unavailable=\"${xmlText(notification.tailError)}\"/>`);\n\t} else {\n\t\tconst attrs = [\n\t\t\t`bytes=\"${notification.tailBytes}\"`,\n\t\t\t`totalBytes=\"${notification.totalBytes}\"`,\n\t\t\tnotification.tailTruncated ? 'truncated=\"true\"' : \"\",\n\t\t\tnotification.tailStartsMidLine ? 'startsMidLine=\"true\"' : \"\",\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\" \");\n\t\tconst tail = notification.tailText.length > 0 ? xmlText(notification.tailText) : \"(no output)\";\n\t\tlines.push(`<output-tail ${attrs}>`, tail.trimEnd(), \"</output-tail>\");\n\t}\n\tlines.push(\n\t\t\"<advice>The command appears blocked waiting for interactive input. Kill it (bg action kill) and \" +\n\t\t\t\"re-run with piped input (e.g. echo y | command) or a non-interactive flag if one exists (e.g. --yes). \" +\n\t\t\t\"The task keeps running until then.</advice>\",\n\t);\n\tlines.push(\"</background-task>\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction toStallDetails(notification: BgStallNotification): BgNotificationDetails {\n\tconst task = notification.task;\n\treturn {\n\t\ttaskId: task.id,\n\t\tcommand: task.command,\n\t\tdescription: task.description,\n\t\tstatus: \"running\",\n\t\tstalled: true,\n\t\texitCode: undefined,\n\t\truntimeMs: Date.now() - task.startedAt,\n\t\toutputPath: task.outputPath,\n\t\ttotalBytes: notification.totalBytes,\n\t\ttailText: notification.tailText,\n\t\ttailTruncated: notification.tailTruncated,\n\t\ttailError: notification.tailError,\n\t};\n}\n\nfunction describeResolveFailure(input: string, result: ResolveTaskResult & { ok: false }): string {\n\tif (result.reason === \"ambiguous\") {\n\t\tconst lines = result.candidates.map(\n\t\t\t(task) => ` ${task.id} (${task.status}) ${commandLabel(taskLabel(task), 60)}`,\n\t\t);\n\t\treturn `Task id \"${input}\" is ambiguous. Candidates:\\n${lines.join(\"\\n\")}`;\n\t}\n\treturn `No background task matches \"${input}\". Check the id returned by bg (action create), or run action list.`;\n}\n\n/** One row of a bounded task listing: the model-facing list and /bg summaries. */\nfunction describeTaskLine(task: BgTask, now: number): string {\n\tconst duration = formatDuration((task.endedAt ?? now) - task.startedAt);\n\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? ` exit ${task.exitCode}` : \"\";\n\treturn ` ${task.id} ${task.status}${exit} ${duration} ${commandLabel(taskLabel(task), 60)}`;\n}\n\n/** Label for listings: the model-provided description over the first command line. */\nfunction taskLabel(task: BgTask): string {\n\treturn task.description ? `${task.description} — ${firstCommandLine(task.command)}` : firstCommandLine(task.command);\n}\n\nfunction toNotificationDetails(notification: BgTaskNotification): BgNotificationDetails {\n\tconst task = notification.task;\n\treturn {\n\t\ttaskId: task.id,\n\t\tcommand: task.command,\n\t\tdescription: task.description,\n\t\tstatus: task.status,\n\t\texitCode: task.exitCode,\n\t\truntimeMs: (task.endedAt ?? task.startedAt) - task.startedAt,\n\t\toutputPath: task.outputPath,\n\t\ttotalBytes: notification.totalBytes,\n\t\ttailText: notification.tailText,\n\t\ttailTruncated: notification.tailTruncated,\n\t\terror: task.error,\n\t\ttailError: notification.tailError,\n\t};\n}\n\n/**\n * Wrap operations so every executed command carries the prefix, mirroring the\n * built-in bash tool. The prefix never reaches task labels or notifications:\n * `BgTask.command` stays the user's original input.\n */\nexport function prependCommandPrefix(operations: BashOperations, prefix: string | undefined): BashOperations {\n\tif (!prefix) return operations;\n\treturn {\n\t\texec: (command, cwd, options) => operations.exec(`${prefix}\\n${command}`, cwd, options),\n\t};\n}\n\nexport interface BackgroundExtensionOverrides {\n\toperations?: BashOperations;\n\toutputDir?: string;\n\tmaxOutputBytes?: number;\n\t/** Stall watchdog tuning; defaults follow Claude Code's CC-1175 (5s/45s/1KB). */\n\tstall?: { pollIntervalMs?: number; thresholdMs?: number; tailBytes?: number };\n}\n\n/** Shell configuration for one bg session: the session's settings win, disk settings are the fallback. */\nexport function resolveSessionShell(\n\tctx: ExtensionContext,\n\treadDiskSettings?: () => { shellPath?: string; commandPrefix?: string },\n): { shellPath?: string; commandPrefix?: string } {\n\treturn ctx.getShellSettings?.() ?? readDiskSettings?.() ?? {};\n}\n\n/** Local shell operations honoring the session's shell settings (shellPath, commandPrefix). */\nfunction createSessionBashOperations(ctx: ExtensionContext): BashOperations {\n\tconst shell = resolveSessionShell(ctx, () => {\n\t\t// Hosts without getShellSettings (older SDK hosts): fall back to reading\n\t\t// settings from disk, matching what the session was configured with.\n\t\tconst settings = SettingsManager.create(ctx.cwd, getAgentDir(), {\n\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t});\n\t\treturn { shellPath: settings.getShellPath(), commandPrefix: settings.getShellCommandPrefix() };\n\t});\n\treturn prependCommandPrefix(createLocalBashOperations({ shellPath: shell.shellPath }), shell.commandPrefix);\n}\n\n/** Validate per-action required fields; every message names the next step. */\nfunction validateAction(input: BgInput): void {\n\tswitch (input.action) {\n\t\tcase \"create\":\n\t\t\tif (!input.command || input.command.trim().length === 0) {\n\t\t\t\tthrow new Error(\"action 'create' requires 'command' — pass the bash command to run in the background.\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"read\":\n\t\tcase \"wait\":\n\t\tcase \"kill\":\n\t\t\tif (!input.taskId || input.taskId.trim().length === 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`action '${input.action}' requires 'taskId' — use the id returned by action create, or action list to find it.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"list\":\n\t\t\tbreak;\n\t}\n}\n\n/** Factory with injectable seams for tests; the default export uses production wiring. */\nexport function createBackgroundExtension(overrides?: BackgroundExtensionOverrides): (pi: ExtensionAPI) => void {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet registry: BackgroundTaskRegistry | undefined;\n\t\tlet sessionCtx: ExtensionContext | undefined;\n\n\t\tconst requireRegistry = (): BackgroundTaskRegistry => {\n\t\t\tif (!registry) throw new Error(\"Background tasks are not available yet (no active session).\");\n\t\t\treturn registry;\n\t\t};\n\n\t\tconst resolveTaskOrThrow = (taskId: string): BgTask => {\n\t\t\tconst resolved = requireRegistry().resolveTask(taskId);\n\t\t\tif (!resolved.ok) throw new Error(describeResolveFailure(taskId, resolved));\n\t\t\treturn resolved.task;\n\t\t};\n\n\t\t/** Read-only live peek for the pending wait renderer; never throws. */\n\t\tconst waitLiveProbe: WaitLiveProbe = (taskId) => {\n\t\t\tif (!registry) return undefined;\n\t\t\tconst resolved = registry.resolveTask(taskId);\n\t\t\treturn resolved.ok ? { status: resolved.task.status, outputBytes: resolved.task.outputBytes } : undefined;\n\t\t};\n\n\t\tconst updateStatus = () => {\n\t\t\tif (!registry || registry.isShuttingDown) return;\n\t\t\tsessionCtx?.ui.setStatus(\"background\", formatStatusline(registry.counts()));\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tsessionCtx = ctx;\n\t\t\t// Defensive: a leftover registry (session_shutdown not seen) must not leak processes.\n\t\t\tif (registry) void registry.shutdown();\n\t\t\tregistry = new BackgroundTaskRegistry({\n\t\t\t\toperations: overrides?.operations ?? createSessionBashOperations(ctx),\n\t\t\t\toutputDir: overrides?.outputDir,\n\t\t\t\tmaxOutputBytes: overrides?.maxOutputBytes,\n\t\t\t\tstall: overrides?.stall,\n\t\t\t\tonNotify: (notification) => {\n\t\t\t\t\tpi.sendMessage(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustomType: BG_NOTIFICATION_TYPE,\n\t\t\t\t\t\t\tcontent: buildNotificationContent(notification),\n\t\t\t\t\t\t\tdisplay: true,\n\t\t\t\t\t\t\tdetails: toNotificationDetails(notification),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ deliverAs: \"followUp\", triggerTurn: true },\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tonStall: (notification) => {\n\t\t\t\t\t// Informational one-shot signal: not a terminal state, so it bypasses\n\t\t\t\t\t// the claim protocol (a waiting model needs to know it is blocked on\n\t\t\t\t\t// input, not merely slow).\n\t\t\t\t\tpi.sendMessage(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustomType: BG_NOTIFICATION_TYPE,\n\t\t\t\t\t\t\tcontent: buildStallContent(notification),\n\t\t\t\t\t\t\tdisplay: true,\n\t\t\t\t\t\t\tdetails: toStallDetails(notification),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ deliverAs: \"followUp\", triggerTurn: true },\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tonChange: updateStatus,\n\t\t\t});\n\t\t\tupdateStatus();\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\t\tctx.ui.setStatus(\"background\", undefined);\n\t\t\tsessionCtx = undefined;\n\t\t\tconst active = registry;\n\t\t\tregistry = undefined;\n\t\t\tawait active?.shutdown();\n\t\t});\n\n\t\tconst runCreate = async (\n\t\t\tparams: BgCreateInput,\n\t\t\tctx: ExtensionContext,\n\t\t): Promise<AgentToolResult<BgCreateDetails>> => {\n\t\t\tif (params.timeout !== undefined && (!Number.isFinite(params.timeout) || params.timeout <= 0)) {\n\t\t\t\tthrow new Error(\"Invalid timeout: must be a positive number of seconds.\");\n\t\t\t}\n\t\t\tif (params.timeout !== undefined && params.timeout > MAX_TIMEOUT_SECONDS) {\n\t\t\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t\t\t}\n\t\t\t// Same PI_* session variables as the built-in bash tool, snapshotted at start.\n\t\t\tconst spawnContext = resolveSpawnContext(params.command, ctx.cwd, undefined, true, ctx);\n\t\t\t// Deliberately ignore the turn signal: aborting the current turn must\n\t\t\t// not kill the background task (that is what action kill is for).\n\t\t\tconst task = requireRegistry().startTask({\n\t\t\t\tcommand: params.command,\n\t\t\t\tcwd: ctx.cwd,\n\t\t\t\tdescription: params.description,\n\t\t\t\ttimeoutSeconds: params.timeout,\n\t\t\t\tenv: spawnContext.env,\n\t\t\t});\n\t\t\tconst label = task.description ? ` (${task.description})` : \"\";\n\t\t\tconst text = [\n\t\t\t\t`Started background task ${task.id}${label}.`,\n\t\t\t\t`Output file: ${task.outputPath}`,\n\t\t\t\t\"\",\n\t\t\t\t\"A <background-task> notification with the result and output tail arrives automatically when the task \" +\n\t\t\t\t\t\"ends — do NOT poll (no sleep loops, no repeated reads). Use action read for an early peek, \" +\n\t\t\t\t\t\"action wait when the next step depends on the result, action kill to stop it.\",\n\t\t\t].join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"create\",\n\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\toutputPath: task.outputPath,\n\t\t\t\t\tcommand: params.command,\n\t\t\t\t\tdescription: params.description,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runRead = async (params: BgReadInput): Promise<AgentToolResult<BgReadDetails>> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst mode = params.mode ?? \"tail\";\n\t\t\tconst maxBytes = Math.min(\n\t\t\t\tDEFAULT_MAX_BYTES,\n\t\t\t\tMath.max(BG_LOGS_MIN_BYTES, Math.floor(params.bytes ?? BG_LOGS_DEFAULT_BYTES)),\n\t\t\t);\n\t\t\tlet slice: Awaited<ReturnType<typeof readOutputSlice>>;\n\t\t\ttry {\n\t\t\t\tslice = await readOutputSlice(task.outputPath, { mode, maxBytes });\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not read output for ${task.id} (${task.status}): ${message}\\nOutput file: ${task.outputPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst text = sanitizeBinaryOutput(slice.text);\n\t\t\tconst running = task.status === \"running\" ? [\"still running\"] : [];\n\t\t\tconst noticeParts = slice.truncated\n\t\t\t\t? [\n\t\t\t\t\t\t`${mode} ${formatSize(slice.sliceBytes)} of ${formatSize(slice.totalBytes)}`,\n\t\t\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\t\t\t...running,\n\t\t\t\t\t\t...(slice.startsMidLine ? [\"first line may be partial\"] : []),\n\t\t\t\t\t\t`full output: ${task.outputPath}`,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\t\t\t...running,\n\t\t\t\t\t\t`${formatSize(slice.totalBytes)} total`,\n\t\t\t\t\t\t`output: ${task.outputPath}`,\n\t\t\t\t\t];\n\t\t\tconst body = text.length > 0 ? text : \"(no output yet)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `[${noticeParts.join(\" · \")}]\\n${body}` }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"read\",\n\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\tmode,\n\t\t\t\t\tsliceBytes: slice.sliceBytes,\n\t\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\t\toutputPath: task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runWait = async (params: BgWaitInput): Promise<AgentToolResult<BgWaitDetails>> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst waitMs = Math.min(\n\t\t\t\tBG_WAIT_MAX_MS,\n\t\t\t\tMath.max(BG_WAIT_MIN_MS, Math.floor(params.waitMs ?? BG_WAIT_DEFAULT_MS)),\n\t\t\t);\n\t\t\tconst startedWait = Date.now();\n\t\t\tconst result = await requireRegistry().waitForResult(task.id, waitMs);\n\t\t\tconst waitedMs = Date.now() - startedWait;\n\t\t\tconst finalTask = result.task;\n\t\t\tconst exitSuffix =\n\t\t\t\tfinalTask.exitCode !== undefined && finalTask.exitCode !== null ? ` · exit ${finalTask.exitCode}` : \"\";\n\t\t\tconst ran = formatDuration((finalTask.endedAt ?? Date.now()) - finalTask.startedAt);\n\n\t\t\tif (result.outcome === \"timeout\") {\n\t\t\t\t// Still running: keep progress visible with a bounded tail peek.\n\t\t\t\tlet peekText = \"\";\n\t\t\t\tlet peekNote = \"\";\n\t\t\t\tlet totalBytes = finalTask.outputBytes;\n\t\t\t\ttry {\n\t\t\t\t\tconst peek = await readOutputSlice(finalTask.outputPath, { mode: \"tail\", maxBytes: BG_WAIT_PEEK_BYTES });\n\t\t\t\t\tpeekText = sanitizeBinaryOutput(peek.text);\n\t\t\t\t\ttotalBytes = peek.totalBytes;\n\t\t\t\t\tpeekNote = peek.truncated ? ` (last ${formatSize(peek.sliceBytes)})` : \"\";\n\t\t\t\t} catch {\n\t\t\t\t\tpeekNote = \" (output unavailable)\";\n\t\t\t\t}\n\t\t\t\tconst lines = [\n\t\t\t\t\t`[${finalTask.id} still running · waited ${formatDuration(waitedMs)} · ${formatSize(totalBytes)} total]`,\n\t\t\t\t];\n\t\t\t\tconst trimmed = peekText.trimEnd();\n\t\t\t\tif (trimmed.length > 0) lines.push(`Last output${peekNote}:\\n${trimmed}`);\n\t\t\t\tlines.push(\n\t\t\t\t\t\"The task keeps running. Wait again (action wait), peek with action read, or stop it with action kill; \" +\n\t\t\t\t\t\t\"the <background-task> notification still arrives when it ends. Do not sleep-poll.\",\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\\n\") }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\t\ttimedOut: true,\n\t\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Terminal: deliver the bounded delta since the requested offset.\n\t\t\t// The followUp notification was suppressed by the claim protocol —\n\t\t\t// this result is the single delivery of the completion.\n\t\t\tconst since = params.sinceBytes !== undefined ? Math.max(0, Math.floor(params.sinceBytes)) : undefined;\n\t\t\tlet delta: Awaited<ReturnType<typeof readOutputSince>>;\n\t\t\tlet offsetNote: string | undefined;\n\t\t\ttry {\n\t\t\t\tdelta = await readOutputSince(finalTask.outputPath, since ?? 0, BG_WAIT_DELTA_BYTES);\n\t\t\t\tif (since !== undefined && since > delta.totalBytes) {\n\t\t\t\t\t// A stale offset past EOF (the output was truncated at the cap, or\n\t\t\t\t\t// the model is reusing an id from an earlier read): fall back to\n\t\t\t\t\t// the tail and say so. Never an error — the offset is not a bug.\n\t\t\t\t\tdelta = await readOutputSince(finalTask.outputPath, 0, BG_WAIT_DELTA_BYTES);\n\t\t\t\t\toffsetNote = finalTask.outputTruncated\n\t\t\t\t\t\t? \"the given offset is past EOF — output was truncated at the limit; showing the tail\"\n\t\t\t\t\t\t: \"the given offset is past EOF; showing the tail\";\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Deliver the terminal status even when the output file cannot be read.\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `[${finalTask.id} ${finalTask.status}${exitSuffix} · ran ${ran} · waited ${formatDuration(waitedMs)}]\\nerror reading output: ${message}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes: finalTask.outputBytes,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst lines = [\n\t\t\t\t`[${finalTask.id} ${finalTask.status}${exitSuffix} · ran ${ran} · waited ${formatDuration(waitedMs)} · +${formatSize(delta.sliceBytes)} new output · total ${formatSize(delta.totalBytes)}]`,\n\t\t\t];\n\t\t\tif (offsetNote) lines.push(`[${offsetNote}]`);\n\t\t\tif (finalTask.error) lines.push(`error: ${finalTask.error}`);\n\t\t\tif (delta.truncated) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`[showing ${formatSize(delta.sliceBytes)} of ${formatSize(delta.totalBytes)}; full output: ${finalTask.outputPath}]`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst body = sanitizeBinaryOutput(delta.text).trimEnd();\n\t\t\tlines.push(body.length > 0 ? body : \"(no new output)\");\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"wait\",\n\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\ttimedOut: false,\n\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\twaitedMs,\n\t\t\t\t\tdeltaBytes: delta.sliceBytes,\n\t\t\t\t\ttotalBytes: delta.totalBytes,\n\t\t\t\t\tdeltaTruncated: delta.truncated,\n\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runKill = (params: BgKillInput): AgentToolResult<BgKillDetails> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst result = requireRegistry().killTask(task.id);\n\t\t\tif (!result.killed) {\n\t\t\t\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? `, exit ${task.exitCode}` : \"\";\n\t\t\t\tthrow new Error(`Task ${task.id} is not running (status: ${task.status}${exit}).`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `Killed task ${task.id}. If you are waiting on it (action wait) the killed status is delivered there; otherwise a completion notification follows once the process tree is reaped.`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { action: \"kill\", taskId: task.id, command: task.command },\n\t\t\t};\n\t\t};\n\n\t\tconst runList = (): AgentToolResult<BgListDetails> => {\n\t\t\tconst tasks = requireRegistry().listTasks();\n\t\t\tif (tasks.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"No background tasks this session. Start one with action create.\" }],\n\t\t\t\t\tdetails: { action: \"list\", running: 0, finished: 0, shown: 0, hidden: 0 },\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst now = Date.now();\n\t\t\tconst running = tasks.filter((task) => task.status === \"running\");\n\t\t\tconst finished = tasks.filter((task) => task.status !== \"running\");\n\t\t\tconst shownFinished = finished.slice(0, BG_LIST_FINISHED_SHOWN);\n\t\t\tconst hidden = finished.length - shownFinished.length;\n\t\t\tconst lines = [`${running.length} running · ${finished.length} finished`];\n\t\t\tfor (const task of [...running, ...shownFinished]) {\n\t\t\t\tlines.push(describeTaskLine(task, now));\n\t\t\t}\n\t\t\tif (hidden > 0) {\n\t\t\t\tlines.push(`(+${hidden} more finished, not shown — action read shows any task's output)`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"list\",\n\t\t\t\t\trunning: running.length,\n\t\t\t\t\tfinished: finished.length,\n\t\t\t\t\tshown: running.length + shownFinished.length,\n\t\t\t\t\thidden,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tpi.registerTool<typeof bgSchema, BgDetails>({\n\t\t\tname: \"bg\",\n\t\t\tlabel: \"bg\",\n\t\t\tdescription:\n\t\t\t\t\"Run and manage background bash tasks.\\n\\n\" +\n\t\t\t\t\"create: start a command in the background and return immediately with a task id and an \" +\n\t\t\t\t\"output file path. Only use this when you don't need the result immediately and are OK being \" +\n\t\t\t\t\"notified when the command completes later — a <background-task> notification with status, exit \" +\n\t\t\t\t\"code, and output tail arrives automatically when it ends. Do NOT append '&' to the command; bg \" +\n\t\t\t\t\"already runs it detached. An optional description labels the task in the UI; an optional timeout \" +\n\t\t\t\t\"in seconds kills the task on expiry.\\n\\n\" +\n\t\t\t\t\"read: bounded slice of a task's output (default: last 8KB); works while the task runs. The \" +\n\t\t\t\t\"output file is a plain file — the read tool also works on it for line-based paging.\\n\\n\" +\n\t\t\t\t\"wait: block until a task finishes (default 20s, max 60s) and return its status plus output \" +\n\t\t\t\t\"written since a given offset. Use when the next step depends on the result; on timeout the task \" +\n\t\t\t\t\"is still running and you may wait again. Never emulate waiting with sleep.\\n\\n\" +\n\t\t\t\t\"kill: stop a running task (whole process tree).\\n\\n\" +\n\t\t\t\t\"list: currently known tasks with status.\\n\\n\" +\n\t\t\t\t\"Task ids accept a unique prefix ('3f' for 'bg-3f').\",\n\t\t\tpromptSnippet: \"Manage background shell tasks (bg: create/read/wait/kill/list)\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use bg (action create) for long-running commands (dev servers, watch builds, slow tests) instead of regular bash; results arrive as an automatic <background-task> notification, so continue independent work or end the turn.\",\n\t\t\t\t\"Never wait on background tasks with sleep loops or repeated reads; use bg action wait (bounded) when a step depends on a task's result, or rely on the completion notification.\",\n\t\t\t],\n\t\t\tparameters: bgSchema,\n\t\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx): Promise<AgentToolResult<BgDetails>> {\n\t\t\t\tvalidateAction(params);\n\t\t\t\tswitch (params.action) {\n\t\t\t\t\tcase \"create\":\n\t\t\t\t\t\treturn runCreate(params as BgCreateInput, ctx);\n\t\t\t\t\tcase \"read\":\n\t\t\t\t\t\treturn runRead(params as BgReadInput);\n\t\t\t\t\tcase \"wait\":\n\t\t\t\t\t\treturn runWait(params as BgWaitInput);\n\t\t\t\t\tcase \"kill\":\n\t\t\t\t\t\treturn runKill(params as BgKillInput);\n\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\treturn runList();\n\t\t\t\t}\n\t\t\t},\n\t\t\trenderCall(args, theme, context) {\n\t\t\t\treturn renderBgCall(args, theme, context, waitLiveProbe);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderBgResult(result, options, theme, context);\n\t\t\t},\n\t\t});\n\n\t\tpi.registerMessageRenderer<BgNotificationDetails>(BG_NOTIFICATION_TYPE, renderBackgroundNotification);\n\n\t\tpi.registerCommand(\"bg\", {\n\t\t\tdescription: \"View and manage background tasks\",\n\t\t\thandler: async (_args, ctx: ExtensionCommandContext) => {\n\t\t\t\tconst active = registry;\n\t\t\t\tif (!active || active.counts().total === 0) {\n\t\t\t\t\tctx.ui.notify(\"No background tasks.\", \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\t\t// RPC/print: ctx.ui.custom is unavailable — show a bounded summary.\n\t\t\t\t\tconst lines = active\n\t\t\t\t\t\t.listTasks()\n\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t.map((task) => describeTaskLine(task, Date.now()));\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Background tasks:\\n${lines.join(\"\\n\")}\\nUse the bg tool (action kill) to stop a task.`,\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait showBackgroundManager(ctx, active);\n\t\t\t},\n\t\t});\n\t};\n}\n\nasync function showBackgroundManager(ctx: ExtensionCommandContext, registry: BackgroundTaskRegistry): Promise<void> {\n\t// No overlay options: the component mounts inline in the editor slot, like /model.\n\tawait ctx.ui.custom(\n\t\t(tui, theme, keybindings, done) =>\n\t\t\tnew BackgroundTasksMenu({\n\t\t\t\ttui,\n\t\t\t\ttheme,\n\t\t\t\tkeybindings,\n\t\t\t\thost: {\n\t\t\t\t\tlistTasks: () => registry.listTasks(),\n\t\t\t\t\tkillTask: (id) => registry.killTask(id),\n\t\t\t\t\treadSlice: (filePath, options) => readOutputSlice(filePath, options),\n\t\t\t\t},\n\t\t\t\tonClose: () => done(undefined),\n\t\t\t}),\n\t);\n}\n\nexport default createBackgroundExtension();\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/background/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAEN,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACN,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,cAAc,EAKd,gBAAgB,EAChB,cAAc,EAEd,eAAe,EACf,eAAe,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,YAAY,EACZ,4BAA4B,E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AAC;AAED,eAAe,yBAAyB,EAAE,CAAC","sourcesContent":["/**\n * background — run bash commands in the background.\n *\n * Tools: a single `bg` tool with five actions. create starts a task and\n * returns immediately; the result arrives as a <background-task> notification\n * (queued behind the current run while streaming, waking the agent when\n * idle). read returns a bounded slice of a task's output file; wait blocks\n * (bounded) for a task's completion and delivers it inline — the followUp\n * notification is suppressed so the completion is delivered exactly once;\n * kill stops a single task; list enumerates known tasks. /bg opens the\n * interactive task manager. Running counts surface in the footer via\n * ctx.ui.setStatus.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport {\n\ttype BashOperations,\n\tcreateLocalBashOperations,\n\tMAX_TIMEOUT_SECONDS,\n\tresolveSpawnContext,\n} from \"../../core/tools/bash.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize } from \"../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { BackgroundTasksMenu } from \"./manager.ts\";\nimport {\n\tBackgroundTaskRegistry,\n\tBG_WAIT_DEFAULT_MS,\n\tBG_WAIT_MAX_MS,\n\tBG_WAIT_MIN_MS,\n\ttype BgStallNotification,\n\ttype BgTask,\n\ttype BgTaskNotification,\n\ttype BgTaskStatus,\n\tfirstCommandLine,\n\tformatDuration,\n\ttype ResolveTaskResult,\n\treadOutputSince,\n\treadOutputSlice,\n} from \"./registry.ts\";\nimport {\n\tcommandLabel,\n\trenderBackgroundNotification,\n\trenderBgCall,\n\trenderBgResult,\n\ttype WaitLiveProbe,\n} from \"./render.ts\";\n\nexport const BG_NOTIFICATION_TYPE = \"background-task\";\nconst BG_LOGS_DEFAULT_BYTES = 8 * 1024;\nconst BG_LOGS_MIN_BYTES = 256;\nconst BG_LIST_FINISHED_SHOWN = 5;\n/** Bounded output delta returned by a successful wait. */\nconst BG_WAIT_DELTA_BYTES = 32 * 1024;\n/** Tail peek included in a wait timeout result so progress stays visible. */\nconst BG_WAIT_PEEK_BYTES = 2 * 1024;\n\nconst bgSchema = Type.Object({\n\taction: Type.Union(\n\t\t[Type.Literal(\"create\"), Type.Literal(\"read\"), Type.Literal(\"wait\"), Type.Literal(\"kill\"), Type.Literal(\"list\")],\n\t\t{ description: \"Which background-task operation to perform\" },\n\t),\n\t// — create —\n\tcommand: Type.Optional(\n\t\tType.String({ description: \"Bash command to run in the background (create). Do not append '&'\" }),\n\t),\n\tdescription: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Short label for the task, shown in /bg and notifications, e.g. 'dev server' (create)\",\n\t\t}),\n\t),\n\ttimeout: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: \"Kill the task after this many seconds; on expiry it is reported as timeout (create)\",\n\t\t}),\n\t),\n\t// — read / wait / kill —\n\ttaskId: Type.Optional(\n\t\tType.String({ description: \"Task id; a unique prefix is accepted, e.g. 'bg-3f' or '3f' (read/wait/kill)\" }),\n\t),\n\t// — read —\n\tmode: Type.Optional(\n\t\tType.Union([Type.Literal(\"tail\"), Type.Literal(\"head\")], {\n\t\t\tdescription: \"Read from the end (default) or the start of the output (read)\",\n\t\t}),\n\t),\n\tbytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Max bytes to return (read, default ${formatSize(BG_LOGS_DEFAULT_BYTES)}, max ${formatSize(DEFAULT_MAX_BYTES)})`,\n\t\t}),\n\t),\n\t// — wait —\n\twaitMs: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription: `Max time to wait in ms, default ${BG_WAIT_DEFAULT_MS}, max ${BG_WAIT_MAX_MS} (wait)`,\n\t\t}),\n\t),\n\tsinceBytes: Type.Optional(\n\t\tType.Number({\n\t\t\tdescription:\n\t\t\t\t\"Only return output written after this byte offset — take it from a previous read/wait result (wait)\",\n\t\t}),\n\t),\n});\n\nexport type BgInput = Static<typeof bgSchema>;\n\n/** Per-action inputs: validateAction guarantees the required fields before the cast. */\nexport type BgCreateInput = BgInput & { action: \"create\"; command: string };\nexport type BgReadInput = BgInput & { action: \"read\"; taskId: string };\nexport type BgWaitInput = BgInput & { action: \"wait\"; taskId: string };\nexport type BgKillInput = BgInput & { action: \"kill\"; taskId: string };\n\nexport interface BgCreateDetails {\n\taction: \"create\";\n\ttaskId: string;\n\toutputPath: string;\n\tcommand: string;\n\tdescription?: string;\n}\n\nexport interface BgReadDetails {\n\taction: \"read\";\n\ttaskId: string;\n\tmode: \"head\" | \"tail\";\n\tsliceBytes: number;\n\ttotalBytes: number;\n\toutputPath: string;\n}\n\nexport interface BgWaitDetails {\n\taction: \"wait\";\n\ttaskId: string;\n\t/** True when the wait window expired and the task is still running. */\n\ttimedOut: boolean;\n\tstatus: BgTaskStatus;\n\texitCode: number | null | undefined;\n\twaitedMs: number;\n\tdeltaBytes: number;\n\ttotalBytes: number;\n\tdeltaTruncated: boolean;\n\toutputPath: string;\n}\n\nexport interface BgKillDetails {\n\taction: \"kill\";\n\ttaskId: string;\n\tcommand: string;\n}\n\nexport interface BgListDetails {\n\taction: \"list\";\n\trunning: number;\n\tfinished: number;\n\tshown: number;\n\thidden: number;\n}\n\nexport type BgDetails = BgCreateDetails | BgReadDetails | BgWaitDetails | BgKillDetails | BgListDetails;\n\nexport interface BgNotificationDetails {\n\ttaskId: string;\n\tcommand: string;\n\tdescription?: string;\n\tstatus: BgTaskStatus;\n\t/** True for the one-shot \"waiting for interactive input\" signal; the task keeps running. */\n\tstalled?: true;\n\texitCode: number | null | undefined;\n\truntimeMs: number;\n\toutputPath: string;\n\ttotalBytes: number;\n\ttailText: string;\n\ttailTruncated: boolean;\n\terror?: string;\n\ttailError?: string;\n}\n\nexport function escapeXml(text: string): string {\n\treturn text\n\t\t.replaceAll(\"&\", \"&\")\n\t\t.replaceAll(\"<\", \"<\")\n\t\t.replaceAll(\">\", \">\")\n\t\t.replaceAll('\"', \""\")\n\t\t.replaceAll(\"'\", \"'\");\n}\n\n/**\n * Strip characters XML 1.0 forbids: C0 controls (except \\t \\n \\r), lone\n * surrogates (U+D800–U+DFFF), and the non-characters U+FFFE/U+FFFF.\n * sanitizeBinaryOutput does not remove the latter two classes, so this filter\n * is the authority for every text field in the notification XML.\n */\nexport function filterXmlCharacters(text: string): string {\n\tlet result = \"\";\n\tfor (const char of text) {\n\t\tconst code = char.codePointAt(0) ?? 0;\n\t\tif (\n\t\t\tcode === 0x09 ||\n\t\t\tcode === 0x0a ||\n\t\t\tcode === 0x0d ||\n\t\t\t(code >= 0x20 && code <= 0xd7ff) ||\n\t\t\t(code >= 0xe000 && code <= 0xfffd) ||\n\t\t\tcode >= 0x10000\n\t\t) {\n\t\t\tresult += char;\n\t\t}\n\t}\n\treturn result;\n}\n\n/**\n * filterXmlCharacters keeps \\t \\n \\r and every other XML-legal codepoint, so\n * every field built with this is valid XML 1.0 after escaping.\n */\nconst xmlText = (text: string) => escapeXml(filterXmlCharacters(text));\n\n/** The `<output-tail>` element, shared by the completion and stall notifications. */\nfunction renderOutputTail(notification: BgTaskNotification): string[] {\n\tif (notification.tailError) {\n\t\treturn [`<output-tail unavailable=\"${xmlText(notification.tailError)}\"/>`];\n\t}\n\tconst attrs = [\n\t\t`bytes=\"${notification.tailBytes}\"`,\n\t\t`totalBytes=\"${notification.totalBytes}\"`,\n\t\tnotification.tailTruncated ? 'truncated=\"true\"' : \"\",\n\t\tnotification.tailStartsMidLine ? 'startsMidLine=\"true\"' : \"\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n\tconst tail = notification.tailText.length > 0 ? xmlText(notification.tailText) : \"(no output)\";\n\treturn [`<output-tail ${attrs}>`, tail.trimEnd(), \"</output-tail>\"];\n}\n\nexport function buildNotificationContent(notification: BgTaskNotification): string {\n\tconst task = notification.task;\n\tconst runtime = formatDuration((task.endedAt ?? task.startedAt) - task.startedAt);\n\tconst exitCode = task.exitCode === undefined || task.exitCode === null ? \"\" : ` exitCode=\"${task.exitCode}\"`;\n\tconst lines = [\n\t\t`<background-task id=\"${task.id}\" status=\"${task.status}\"${exitCode} runtime=\"${runtime}\">`,\n\t\t`<command>${xmlText(task.command)}</command>`,\n\t];\n\tif (task.description) {\n\t\tlines.push(`<description>${xmlText(task.description)}</description>`);\n\t}\n\tlines.push(`<output-file>${xmlText(task.outputPath)}</output-file>`);\n\tif (task.error) {\n\t\tlines.push(`<error>${xmlText(task.error)}</error>`);\n\t}\n\tlines.push(...renderOutputTail(notification));\n\tlines.push(\"</background-task>\");\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatStatusline(counts: { running: number; total: number; stalled?: number }): string | undefined {\n\tif (counts.total === 0) return undefined;\n\t// Stalled tasks are running tasks: report them separately so the counts add up.\n\tconst waiting = counts.stalled ?? 0;\n\tconst running = counts.running - waiting;\n\tconst ended = counts.total - counts.running;\n\tconst parts: string[] = [];\n\tif (running > 0) parts.push(`${running} running`);\n\tif (waiting > 0) parts.push(`${waiting} waiting for input`);\n\tif (ended > 0) parts.push(`${ended} done`);\n\treturn `bg ${parts.join(\" · \")}`;\n}\n\nexport function buildStallContent(notification: BgStallNotification): string {\n\tconst task = notification.task;\n\t// A stalled task is by definition still running, so it has no endedAt.\n\tconst runtime = formatDuration(Date.now() - task.startedAt);\n\tconst lines = [\n\t\t`<background-task id=\"${task.id}\" status=\"running\" waiting-for-input=\"true\" runtime=\"${runtime}\">`,\n\t\t`<command>${xmlText(task.command)}</command>`,\n\t];\n\tif (task.description) {\n\t\tlines.push(`<description>${xmlText(task.description)}</description>`);\n\t}\n\tlines.push(`<output-file>${xmlText(task.outputPath)}</output-file>`);\n\tlines.push(...renderOutputTail(notification));\n\tlines.push(\n\t\t\"<advice>The command appears blocked waiting for interactive input. Kill it (bg action kill) and \" +\n\t\t\t\"re-run with piped input (e.g. echo y | command) or a non-interactive flag if one exists (e.g. --yes). \" +\n\t\t\t\"The task keeps running until then.</advice>\",\n\t);\n\tlines.push(\"</background-task>\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction toStallDetails(notification: BgStallNotification): BgNotificationDetails {\n\tconst task = notification.task;\n\treturn {\n\t\ttaskId: task.id,\n\t\tcommand: task.command,\n\t\tdescription: task.description,\n\t\tstatus: \"running\",\n\t\tstalled: true,\n\t\texitCode: undefined,\n\t\truntimeMs: Date.now() - task.startedAt,\n\t\toutputPath: task.outputPath,\n\t\ttotalBytes: notification.totalBytes,\n\t\ttailText: notification.tailText,\n\t\ttailTruncated: notification.tailTruncated,\n\t\ttailError: notification.tailError,\n\t};\n}\n\nfunction describeResolveFailure(input: string, result: ResolveTaskResult & { ok: false }): string {\n\tif (result.reason === \"ambiguous\") {\n\t\tconst lines = result.candidates.map(\n\t\t\t(task) => ` ${task.id} (${task.status}) ${commandLabel(taskLabel(task), 60)}`,\n\t\t);\n\t\treturn `Task id \"${input}\" is ambiguous. Candidates:\\n${lines.join(\"\\n\")}`;\n\t}\n\treturn `No background task matches \"${input}\". Check the id returned by bg (action create), or run action list.`;\n}\n\n/** One row of a bounded task listing: the model-facing list and /bg summaries. */\nfunction describeTaskLine(task: BgTask, now: number): string {\n\tconst duration = formatDuration((task.endedAt ?? now) - task.startedAt);\n\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? ` exit ${task.exitCode}` : \"\";\n\treturn ` ${task.id} ${task.status}${exit} ${duration} ${commandLabel(taskLabel(task), 60)}`;\n}\n\n/** Label for listings: the model-provided description over the first command line. */\nfunction taskLabel(task: BgTask): string {\n\treturn task.description ? `${task.description} — ${firstCommandLine(task.command)}` : firstCommandLine(task.command);\n}\n\nfunction toNotificationDetails(notification: BgTaskNotification): BgNotificationDetails {\n\tconst task = notification.task;\n\treturn {\n\t\ttaskId: task.id,\n\t\tcommand: task.command,\n\t\tdescription: task.description,\n\t\tstatus: task.status,\n\t\texitCode: task.exitCode,\n\t\truntimeMs: (task.endedAt ?? task.startedAt) - task.startedAt,\n\t\toutputPath: task.outputPath,\n\t\ttotalBytes: notification.totalBytes,\n\t\ttailText: notification.tailText,\n\t\ttailTruncated: notification.tailTruncated,\n\t\terror: task.error,\n\t\ttailError: notification.tailError,\n\t};\n}\n\n/**\n * Wrap operations so every executed command carries the prefix, mirroring the\n * built-in bash tool. The prefix never reaches task labels or notifications:\n * `BgTask.command` stays the user's original input.\n */\nexport function prependCommandPrefix(operations: BashOperations, prefix: string | undefined): BashOperations {\n\tif (!prefix) return operations;\n\treturn {\n\t\texec: (command, cwd, options) => operations.exec(`${prefix}\\n${command}`, cwd, options),\n\t};\n}\n\nexport interface BackgroundExtensionOverrides {\n\toperations?: BashOperations;\n\toutputDir?: string;\n\tmaxOutputBytes?: number;\n\t/** Stall watchdog tuning; defaults follow Claude Code's CC-1175 (5s/45s/1KB). */\n\tstall?: { pollIntervalMs?: number; thresholdMs?: number; tailBytes?: number };\n}\n\n/** Shell configuration for one bg session: the session's settings win, disk settings are the fallback. */\nexport function resolveSessionShell(\n\tctx: ExtensionContext,\n\treadDiskSettings?: () => { shellPath?: string; commandPrefix?: string },\n): { shellPath?: string; commandPrefix?: string } {\n\treturn ctx.getShellSettings?.() ?? readDiskSettings?.() ?? {};\n}\n\n/** Local shell operations honoring the session's shell settings (shellPath, commandPrefix). */\nfunction createSessionBashOperations(ctx: ExtensionContext): BashOperations {\n\tconst shell = resolveSessionShell(ctx, () => {\n\t\t// Hosts without getShellSettings (older SDK hosts): fall back to reading\n\t\t// settings from disk, matching what the session was configured with.\n\t\tconst settings = SettingsManager.create(ctx.cwd, getAgentDir(), {\n\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t});\n\t\treturn { shellPath: settings.getShellPath(), commandPrefix: settings.getShellCommandPrefix() };\n\t});\n\treturn prependCommandPrefix(createLocalBashOperations({ shellPath: shell.shellPath }), shell.commandPrefix);\n}\n\n/** Validate per-action required fields; every message names the next step. */\nfunction validateAction(input: BgInput): void {\n\tswitch (input.action) {\n\t\tcase \"create\":\n\t\t\tif (!input.command || input.command.trim().length === 0) {\n\t\t\t\tthrow new Error(\"action 'create' requires 'command' — pass the bash command to run in the background.\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"read\":\n\t\tcase \"wait\":\n\t\tcase \"kill\":\n\t\t\tif (!input.taskId || input.taskId.trim().length === 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`action '${input.action}' requires 'taskId' — use the id returned by action create, or action list to find it.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"list\":\n\t\t\tbreak;\n\t}\n}\n\n/** Factory with injectable seams for tests; the default export uses production wiring. */\nexport function createBackgroundExtension(overrides?: BackgroundExtensionOverrides): (pi: ExtensionAPI) => void {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet registry: BackgroundTaskRegistry | undefined;\n\t\tlet sessionCtx: ExtensionContext | undefined;\n\n\t\tconst requireRegistry = (): BackgroundTaskRegistry => {\n\t\t\tif (!registry) throw new Error(\"Background tasks are not available yet (no active session).\");\n\t\t\treturn registry;\n\t\t};\n\n\t\tconst resolveTaskOrThrow = (taskId: string): BgTask => {\n\t\t\tconst resolved = requireRegistry().resolveTask(taskId);\n\t\t\tif (!resolved.ok) throw new Error(describeResolveFailure(taskId, resolved));\n\t\t\treturn resolved.task;\n\t\t};\n\n\t\t/** Read-only live peek for the pending wait renderer; never throws. */\n\t\tconst waitLiveProbe: WaitLiveProbe = (taskId) => {\n\t\t\tif (!registry) return undefined;\n\t\t\tconst resolved = registry.resolveTask(taskId);\n\t\t\treturn resolved.ok ? { status: resolved.task.status, outputBytes: resolved.task.outputBytes } : undefined;\n\t\t};\n\n\t\tconst updateStatus = () => {\n\t\t\tif (!registry || registry.isShuttingDown) return;\n\t\t\tsessionCtx?.ui.setStatus(\"background\", formatStatusline(registry.counts()));\n\t\t};\n\n\t\t/** Both background messages reach the model the same way; that choice lives here only. */\n\t\tconst notify = (content: string, details: BgNotificationDetails) => {\n\t\t\tpi.sendMessage(\n\t\t\t\t{ customType: BG_NOTIFICATION_TYPE, content, display: true, details },\n\t\t\t\t{ deliverAs: \"followUp\", triggerTurn: true },\n\t\t\t);\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tsessionCtx = ctx;\n\t\t\t// Defensive: a leftover registry (session_shutdown not seen) must not leak processes.\n\t\t\tif (registry) void registry.shutdown();\n\t\t\tregistry = new BackgroundTaskRegistry({\n\t\t\t\toperations: overrides?.operations ?? createSessionBashOperations(ctx),\n\t\t\t\toutputDir: overrides?.outputDir,\n\t\t\t\tmaxOutputBytes: overrides?.maxOutputBytes,\n\t\t\t\tstall: overrides?.stall,\n\t\t\t\tonNotify: (notification) =>\n\t\t\t\t\tnotify(buildNotificationContent(notification), toNotificationDetails(notification)),\n\t\t\t\t// Informational one-shot signal: not a terminal state, so it bypasses\n\t\t\t\t// the claim protocol (a waiting model needs to know it is blocked on\n\t\t\t\t// input, not merely slow).\n\t\t\t\tonStall: (notification) => notify(buildStallContent(notification), toStallDetails(notification)),\n\t\t\t\tonChange: updateStatus,\n\t\t\t});\n\t\t\tupdateStatus();\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\t\tctx.ui.setStatus(\"background\", undefined);\n\t\t\tsessionCtx = undefined;\n\t\t\tconst active = registry;\n\t\t\tregistry = undefined;\n\t\t\tawait active?.shutdown();\n\t\t});\n\n\t\tconst runCreate = async (\n\t\t\tparams: BgCreateInput,\n\t\t\tctx: ExtensionContext,\n\t\t): Promise<AgentToolResult<BgCreateDetails>> => {\n\t\t\tif (params.timeout !== undefined && (!Number.isFinite(params.timeout) || params.timeout <= 0)) {\n\t\t\t\tthrow new Error(\"Invalid timeout: must be a positive number of seconds.\");\n\t\t\t}\n\t\t\tif (params.timeout !== undefined && params.timeout > MAX_TIMEOUT_SECONDS) {\n\t\t\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t\t\t}\n\t\t\t// Same PI_* session variables as the built-in bash tool, snapshotted at start.\n\t\t\tconst spawnContext = resolveSpawnContext(params.command, ctx.cwd, undefined, true, ctx);\n\t\t\t// Deliberately ignore the turn signal: aborting the current turn must\n\t\t\t// not kill the background task (that is what action kill is for).\n\t\t\tconst task = requireRegistry().startTask({\n\t\t\t\tcommand: params.command,\n\t\t\t\tcwd: ctx.cwd,\n\t\t\t\tdescription: params.description,\n\t\t\t\ttimeoutSeconds: params.timeout,\n\t\t\t\tenv: spawnContext.env,\n\t\t\t});\n\t\t\tconst label = task.description ? ` (${task.description})` : \"\";\n\t\t\tconst text = [\n\t\t\t\t`Started background task ${task.id}${label}.`,\n\t\t\t\t`Output file: ${task.outputPath}`,\n\t\t\t\t\"\",\n\t\t\t\t\"A <background-task> notification with the result and output tail arrives automatically when the task \" +\n\t\t\t\t\t\"ends — do NOT poll (no sleep loops, no repeated reads). Use action read for an early peek, \" +\n\t\t\t\t\t\"action wait when the next step depends on the result, action kill to stop it.\",\n\t\t\t].join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"create\",\n\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\toutputPath: task.outputPath,\n\t\t\t\t\tcommand: params.command,\n\t\t\t\t\tdescription: params.description,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runRead = async (params: BgReadInput): Promise<AgentToolResult<BgReadDetails>> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst mode = params.mode ?? \"tail\";\n\t\t\tconst maxBytes = Math.min(\n\t\t\t\tDEFAULT_MAX_BYTES,\n\t\t\t\tMath.max(BG_LOGS_MIN_BYTES, Math.floor(params.bytes ?? BG_LOGS_DEFAULT_BYTES)),\n\t\t\t);\n\t\t\tlet slice: Awaited<ReturnType<typeof readOutputSlice>>;\n\t\t\ttry {\n\t\t\t\tslice = await readOutputSlice(task.outputPath, { mode, maxBytes });\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not read output for ${task.id} (${task.status}): ${message}\\nOutput file: ${task.outputPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst text = sanitizeBinaryOutput(slice.text);\n\t\t\tconst running = task.status === \"running\" ? [\"still running\"] : [];\n\t\t\tconst noticeParts = slice.truncated\n\t\t\t\t? [\n\t\t\t\t\t\t`${mode} ${formatSize(slice.sliceBytes)} of ${formatSize(slice.totalBytes)}`,\n\t\t\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\t\t\t...running,\n\t\t\t\t\t\t...(slice.startsMidLine ? [\"first line may be partial\"] : []),\n\t\t\t\t\t\t`full output: ${task.outputPath}`,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t`task ${task.id} ${task.status}`,\n\t\t\t\t\t\t...running,\n\t\t\t\t\t\t`${formatSize(slice.totalBytes)} total`,\n\t\t\t\t\t\t`output: ${task.outputPath}`,\n\t\t\t\t\t];\n\t\t\tconst body = text.length > 0 ? text : \"(no output yet)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `[${noticeParts.join(\" · \")}]\\n${body}` }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"read\",\n\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\tmode,\n\t\t\t\t\tsliceBytes: slice.sliceBytes,\n\t\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\t\toutputPath: task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runWait = async (params: BgWaitInput, signal?: AbortSignal): Promise<AgentToolResult<BgWaitDetails>> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst waitMs = Math.min(\n\t\t\t\tBG_WAIT_MAX_MS,\n\t\t\t\tMath.max(BG_WAIT_MIN_MS, Math.floor(params.waitMs ?? BG_WAIT_DEFAULT_MS)),\n\t\t\t);\n\t\t\tconst startedWait = Date.now();\n\t\t\tconst result = await requireRegistry().waitForResult(task.id, waitMs, signal);\n\t\t\tconst waitedMs = Date.now() - startedWait;\n\t\t\tconst finalTask = result.task;\n\t\t\tconst exitSuffix =\n\t\t\t\tfinalTask.exitCode !== undefined && finalTask.exitCode !== null ? ` · exit ${finalTask.exitCode}` : \"\";\n\t\t\tconst ran = formatDuration((finalTask.endedAt ?? Date.now()) - finalTask.startedAt);\n\n\t\t\tif (result.outcome === \"timeout\") {\n\t\t\t\t// Still running: keep progress visible with a bounded tail peek.\n\t\t\t\tlet peekText = \"\";\n\t\t\t\tlet peekNote = \"\";\n\t\t\t\tlet totalBytes = finalTask.outputBytes;\n\t\t\t\ttry {\n\t\t\t\t\tconst peek = await readOutputSlice(finalTask.outputPath, { mode: \"tail\", maxBytes: BG_WAIT_PEEK_BYTES });\n\t\t\t\t\tpeekText = sanitizeBinaryOutput(peek.text);\n\t\t\t\t\ttotalBytes = peek.totalBytes;\n\t\t\t\t\tpeekNote = peek.truncated ? ` (last ${formatSize(peek.sliceBytes)})` : \"\";\n\t\t\t\t} catch {\n\t\t\t\t\tpeekNote = \" (output unavailable)\";\n\t\t\t\t}\n\t\t\t\tconst lines = [\n\t\t\t\t\t`[${finalTask.id} still running · waited ${formatDuration(waitedMs)} · ${formatSize(totalBytes)} total]`,\n\t\t\t\t];\n\t\t\t\tconst trimmed = peekText.trimEnd();\n\t\t\t\tif (trimmed.length > 0) lines.push(`Last output${peekNote}:\\n${trimmed}`);\n\t\t\t\tlines.push(\n\t\t\t\t\t\"The task keeps running. Wait again (action wait), peek with action read, or stop it with action kill; \" +\n\t\t\t\t\t\t\"the <background-task> notification still arrives when it ends. Do not sleep-poll.\",\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\\n\") }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\t\ttimedOut: true,\n\t\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Terminal: deliver the bounded delta since the requested offset.\n\t\t\t// The followUp notification was suppressed by the claim protocol —\n\t\t\t// this result is the single delivery of the completion.\n\t\t\tconst since = params.sinceBytes !== undefined ? Math.max(0, Math.floor(params.sinceBytes)) : undefined;\n\t\t\tlet delta: Awaited<ReturnType<typeof readOutputSince>>;\n\t\t\tlet offsetNote: string | undefined;\n\t\t\ttry {\n\t\t\t\tdelta = await readOutputSince(finalTask.outputPath, since ?? 0, BG_WAIT_DELTA_BYTES);\n\t\t\t\tif (since !== undefined && since > delta.totalBytes) {\n\t\t\t\t\t// A stale offset past EOF (the output was truncated at the cap, or\n\t\t\t\t\t// the model is reusing an id from an earlier read): fall back to\n\t\t\t\t\t// the tail and say so. Never an error — the offset is not a bug.\n\t\t\t\t\tdelta = await readOutputSince(finalTask.outputPath, 0, BG_WAIT_DELTA_BYTES);\n\t\t\t\t\toffsetNote = finalTask.outputTruncated\n\t\t\t\t\t\t? \"the given offset is past EOF — output was truncated at the limit; showing the tail\"\n\t\t\t\t\t\t: \"the given offset is past EOF; showing the tail\";\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Deliver the terminal status even when the output file cannot be read.\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `[${finalTask.id} ${finalTask.status}${exitSuffix} · ran ${ran} · waited ${formatDuration(waitedMs)}]\\nerror reading output: ${message}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes: finalTask.outputBytes,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst lines = [\n\t\t\t\t`[${finalTask.id} ${finalTask.status}${exitSuffix} · ran ${ran} · waited ${formatDuration(waitedMs)} · +${formatSize(delta.sliceBytes)} new output · total ${formatSize(delta.totalBytes)}]`,\n\t\t\t];\n\t\t\tif (offsetNote) lines.push(`[${offsetNote}]`);\n\t\t\tif (finalTask.error) lines.push(`error: ${finalTask.error}`);\n\t\t\tif (delta.truncated) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`[showing ${formatSize(delta.sliceBytes)} of ${formatSize(delta.totalBytes)}; full output: ${finalTask.outputPath}]`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst body = sanitizeBinaryOutput(delta.text).trimEnd();\n\t\t\tlines.push(body.length > 0 ? body : \"(no new output)\");\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"wait\",\n\t\t\t\t\ttaskId: finalTask.id,\n\t\t\t\t\ttimedOut: false,\n\t\t\t\t\tstatus: finalTask.status,\n\t\t\t\t\texitCode: finalTask.exitCode,\n\t\t\t\t\twaitedMs,\n\t\t\t\t\tdeltaBytes: delta.sliceBytes,\n\t\t\t\t\ttotalBytes: delta.totalBytes,\n\t\t\t\t\tdeltaTruncated: delta.truncated,\n\t\t\t\t\toutputPath: finalTask.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tconst runKill = (params: BgKillInput): AgentToolResult<BgKillDetails> => {\n\t\t\tconst task = resolveTaskOrThrow(params.taskId);\n\t\t\tconst result = requireRegistry().killTask(task.id);\n\t\t\tif (!result.killed) {\n\t\t\t\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? `, exit ${task.exitCode}` : \"\";\n\t\t\t\tthrow new Error(`Task ${task.id} is not running (status: ${task.status}${exit}).`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `Killed task ${task.id}. If you are waiting on it (action wait) the killed status is delivered there; otherwise a completion notification follows once the process tree is reaped.`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { action: \"kill\", taskId: task.id, command: task.command },\n\t\t\t};\n\t\t};\n\n\t\tconst runList = (): AgentToolResult<BgListDetails> => {\n\t\t\tconst tasks = requireRegistry().listTasks();\n\t\t\tif (tasks.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"No background tasks this session. Start one with action create.\" }],\n\t\t\t\t\tdetails: { action: \"list\", running: 0, finished: 0, shown: 0, hidden: 0 },\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst now = Date.now();\n\t\t\tconst running = tasks.filter((task) => task.status === \"running\");\n\t\t\tconst finished = tasks.filter((task) => task.status !== \"running\");\n\t\t\tconst shownFinished = finished.slice(0, BG_LIST_FINISHED_SHOWN);\n\t\t\tconst hidden = finished.length - shownFinished.length;\n\t\t\tconst lines = [`${running.length} running · ${finished.length} finished`];\n\t\t\tfor (const task of [...running, ...shownFinished]) {\n\t\t\t\tlines.push(describeTaskLine(task, now));\n\t\t\t}\n\t\t\tif (hidden > 0) {\n\t\t\t\tlines.push(`(+${hidden} more finished, not shown — action read shows any task's output)`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: lines.join(\"\\n\") }],\n\t\t\t\tdetails: {\n\t\t\t\t\taction: \"list\",\n\t\t\t\t\trunning: running.length,\n\t\t\t\t\tfinished: finished.length,\n\t\t\t\t\tshown: running.length + shownFinished.length,\n\t\t\t\t\thidden,\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tpi.registerTool<typeof bgSchema, BgDetails>({\n\t\t\tname: \"bg\",\n\t\t\tlabel: \"bg\",\n\t\t\tdescription:\n\t\t\t\t\"Run and manage background bash tasks.\\n\\n\" +\n\t\t\t\t\"create: start a command in the background and return immediately with a task id and an \" +\n\t\t\t\t\"output file path. A <background-task> notification with status, exit code, and output tail \" +\n\t\t\t\t\"arrives automatically when it ends. Do NOT append '&' to the command; bg already runs it \" +\n\t\t\t\t\"detached.\\n\\n\" +\n\t\t\t\t\"read: bounded slice of a task's output; works while the task runs. The \" +\n\t\t\t\t\"output file is a plain file — the read tool also works on it for line-based paging.\\n\\n\" +\n\t\t\t\t\"wait: block until a task finishes and return its status plus output written since a given \" +\n\t\t\t\t\"offset. On timeout the task is still running and you may wait again.\\n\\n\" +\n\t\t\t\t\"kill: stop a running task (whole process tree).\\n\\n\" +\n\t\t\t\t\"list: currently known tasks with status.\",\n\t\t\tpromptSnippet: \"Manage background shell tasks (create, read, wait, kill, list)\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use `bg` action create for long-running commands (dev servers, watch builds, slow tests) instead of regular bash; the completion notification arrives on its own, so continue independent work or end the turn.\",\n\t\t\t\t\"Never wait on a `bg` task with sleep loops or repeated reads; use `bg` action wait when the next step depends on its result.\",\n\t\t\t],\n\t\t\tparameters: bgSchema,\n\t\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx): Promise<AgentToolResult<BgDetails>> {\n\t\t\t\tvalidateAction(params);\n\t\t\t\tswitch (params.action) {\n\t\t\t\t\tcase \"create\":\n\t\t\t\t\t\treturn runCreate(params as BgCreateInput, ctx);\n\t\t\t\t\tcase \"read\":\n\t\t\t\t\t\treturn runRead(params as BgReadInput);\n\t\t\t\t\tcase \"wait\":\n\t\t\t\t\t\treturn runWait(params as BgWaitInput, signal);\n\t\t\t\t\tcase \"kill\":\n\t\t\t\t\t\treturn runKill(params as BgKillInput);\n\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\treturn runList();\n\t\t\t\t}\n\t\t\t},\n\t\t\trenderCall(args, theme, context) {\n\t\t\t\treturn renderBgCall(args, theme, context, waitLiveProbe);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderBgResult(result, options, theme, context);\n\t\t\t},\n\t\t});\n\n\t\tpi.registerMessageRenderer<BgNotificationDetails>(BG_NOTIFICATION_TYPE, renderBackgroundNotification);\n\n\t\tpi.registerCommand(\"bg\", {\n\t\t\tdescription: \"View and manage background tasks\",\n\t\t\thandler: async (_args, ctx: ExtensionCommandContext) => {\n\t\t\t\tconst active = registry;\n\t\t\t\tif (!active || active.counts().total === 0) {\n\t\t\t\t\tctx.ui.notify(\"No background tasks.\", \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\t\t// RPC/print: ctx.ui.custom is unavailable — show a bounded summary.\n\t\t\t\t\tconst lines = active\n\t\t\t\t\t\t.listTasks()\n\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t.map((task) => describeTaskLine(task, Date.now()));\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Background tasks:\\n${lines.join(\"\\n\")}\\nUse the bg tool (action kill) to stop a task.`,\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait showBackgroundManager(ctx, active);\n\t\t\t},\n\t\t});\n\t};\n}\n\nasync function showBackgroundManager(ctx: ExtensionCommandContext, registry: BackgroundTaskRegistry): Promise<void> {\n\t// No overlay options: the component mounts inline in the editor slot, like /model.\n\tawait ctx.ui.custom(\n\t\t(tui, theme, keybindings, done) =>\n\t\t\tnew BackgroundTasksMenu({\n\t\t\t\ttui,\n\t\t\t\ttheme,\n\t\t\t\tkeybindings,\n\t\t\t\thost: {\n\t\t\t\t\tlistTasks: () => registry.listTasks(),\n\t\t\t\t\tkillTask: (id) => registry.killTask(id),\n\t\t\t\t\treadSlice: (filePath, options) => readOutputSlice(filePath, options),\n\t\t\t\t},\n\t\t\t\tonClose: () => done(undefined),\n\t\t\t}),\n\t);\n}\n\nexport default createBackgroundExtension();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/extensions/background/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAA2C,MAAM,wBAAwB,CAAC;AACjH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EAAE,KAAK,MAAM,EAAoC,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAWhG,MAAM,WAAW,qBAAqB;IACrC,SAAS,IAAI,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1C,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/F;AAED,UAAU,OAAO;IAChB,aAAa,IAAI,IAAI,CAAC;IACtB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5C;AAED,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,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B;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED,UAAU,IAAI,IAAI;IAIlB,OAAO,IAAI,IAAI;IAQf,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAuB/B,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,iBAAiB;IAkBzB,+EAA+E;IAC/E,OAAO,CAAC,YAAY;IAiBpB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAQ/B,qFAAqF;IACrF,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;YAeN,IAAI;IAclB,0DAA0D;IAC1D,OAAO,CAAC,kBAAkB;IAS1B,kFAAkF;IAClF,OAAO,CAAC,eAAe;IAqBvB,4EAA4E;IAC5E,OAAO,CAAC,mBAAmB;YAab,eAAe;CA0B7B"}
|
|
@@ -322,11 +322,13 @@ export class BackgroundTasksMenu {
|
|
|
322
322
|
if (!this.selectedTask() && this.tasks[0])
|
|
323
323
|
this.selectedTaskId = this.tasks[0].id;
|
|
324
324
|
this.expireKillFeedback();
|
|
325
|
-
|
|
325
|
+
// A pending re-read counts as a change: refreshViewport may skip this tick
|
|
326
|
+
// (readBusy), and the signature alone would let that retry be dropped.
|
|
327
|
+
const needsRead = this.view === "detail" && this.follow && this.detailOutputChanged();
|
|
328
|
+
if (!needsRead && this.renderSignature() === this.lastSignature)
|
|
326
329
|
return; // Nothing visible changed.
|
|
327
|
-
if (
|
|
330
|
+
if (needsRead)
|
|
328
331
|
await this.refreshViewport();
|
|
329
|
-
}
|
|
330
332
|
this.lastSignature = this.renderSignature();
|
|
331
333
|
this.tui.requestRender();
|
|
332
334
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/extensions/background/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkC,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEjH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wDAAwD,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAe,gBAAgB,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,oFAAoF;AACpF,MAAM,kBAAkB,GAAG,EAAE,CAAC;AA+B9B,2EAA2E;AAC3E,SAAS,OAAO,CAAC,IAAY,EAAE,KAAa;IAC3C,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,OAAO,mBAAmB;IAyB/B,YAAY,OAAmC;QAjBvC,SAAI,GAAsB,MAAM,CAAC;QACjC,UAAK,GAAa,EAAE,CAAC;QAErB,kBAAa,GAAG,CAAC,CAAC;QAClB,WAAM,GAAG,IAAI,CAAC;QACd,oBAAe,GAAG,CAAC,CAAC;QAK5B,2EAA2E;QACnE,kBAAa,GAAG,EA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AC,IAAI,CAAC;gBAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,WAAW,EAAE,IAAI,CAAC,MAAM,KAAK,SAAS;aACtC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC,EAAE;gBAAE,OAAO;YAC7D,IAAI,CAAC,SAAS,GAAG;gBAChB,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,KAAK,EAAE,EAAE;gBACT,UAAU,EAAE,IAAI,CAAC,WAAW;gBAC5B,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC7D,CAAC;QACH,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACvB,CAAC;IACF,CAAC;CACD;AAED,SAAS,WAAW,CAAC,IAAY;IAChC,0EAA0E;IAC1E,0DAA0D;IAC1D,MAAM,KAAK,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7E,2EAA2E;IAC3E,uEAAuE;IACvE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IACvE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/**\n * /bg task manager — an inline, /model-style menu that mounts in the editor\n * slot. Two views in one component: a task list, and a live output viewport\n * for the selected task (Enter to open, Esc to go back). The host dependency\n * is narrowed to three callbacks so the component stays testable.\n */\n\nimport { type Component, type Focusable, stripTerminalSequences, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { formatSize } from \"../../core/tools/truncate.ts\";\nimport { keyLabel } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { type BgTask, firstCommandLine, formatDuration, type OutputSlice } from \"./registry.ts\";\nimport { statusColor, statusGlyph } from \"./render.ts\";\n\nconst POLL_INTERVAL_MS = 1000;\nconst VIEW_TAIL_BYTES = 128 * 1024;\nconst MAX_VIEW_LINES = 2000;\nconst LIST_MAX_VISIBLE = 10;\nconst LIST_MIN_VISIBLE = 3;\n/** Rows outside the task list itself (borders, title, counter, footer, padding). */\nconst LIST_RESERVED_ROWS = 14;\n\nexport interface BackgroundManagerHost {\n\tlistTasks(): BgTask[];\n\tkillTask(id: string): { killed: boolean };\n\treadSlice(filePath: string, options: { mode: \"tail\"; maxBytes: number }): Promise<OutputSlice>;\n}\n\ninterface MenuTui {\n\trequestRender(): void;\n\tterminal: { rows: number; columns: number };\n}\n\nexport interface BackgroundTasksMenuOptions {\n\ttui: MenuTui;\n\ttheme: Theme;\n\tkeybindings: Pick<KeybindingsManager, \"matches\" | \"getKeys\">;\n\thost: BackgroundManagerHost;\n\tonClose: () => void;\n\tpollIntervalMs?: number;\n}\n\ninterface TailCache {\n\ttaskId: string;\n\tlines: string[];\n\ttotalBytes: number;\n\t/** True once a terminal task's final output has been read; skips re-reads. */\n\tsettledRead?: boolean;\n\terror?: string;\n}\n\n/** Truncate to an exact visible width, padding short lines with spaces. */\nfunction padLine(line: string, width: number): string {\n\treturn truncateToWidth(line, width, \"…\", true);\n}\n\nexport class BackgroundTasksMenu implements Component, Focusable {\n\tprivate readonly tui: MenuTui;\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: Pick<KeybindingsManager, \"matches\" | \"getKeys\">;\n\tprivate readonly host: BackgroundManagerHost;\n\tprivate readonly onClose: () => void;\n\tprivate readonly pollIntervalMs: number;\n\n\tprivate view: \"list\" | \"detail\" = \"list\";\n\tprivate tasks: BgTask[] = [];\n\tprivate selectedTaskId: string | undefined;\n\tprivate listScrollTop = 0;\n\tprivate follow = true;\n\tprivate tailOffsetLines = 0;\n\tprivate tailCache: TailCache | undefined;\n\tprivate killFeedback: string | undefined;\n\t/** Task whose settle expires killFeedback; undefined = persists until the next key. */\n\tprivate killFeedbackTaskId: string | undefined;\n\t/** Last tick's render signature; unchanged means nothing visible moved. */\n\tprivate lastSignature = \"\";\n\tprivate pollTimer: ReturnType<typeof setInterval> | undefined;\n\tprivate readBusy = false;\n\tprivate disposed = false;\n\tprivate _focused = false;\n\n\tconstructor(options: BackgroundTasksMenuOptions) {\n\t\tthis.tui = options.tui;\n\t\tthis.theme = options.theme;\n\t\tthis.keybindings = options.keybindings;\n\t\tthis.host = options.host;\n\t\tthis.onClose = options.onClose;\n\t\tthis.pollIntervalMs = options.pollIntervalMs ?? POLL_INTERVAL_MS;\n\n\t\tthis.tasks = this.host.listTasks();\n\t\tthis.selectedTaskId = this.tasks[0]?.id;\n\t\tvoid this.tick();\n\t\tthis.pollTimer = setInterval(() => void this.tick(), this.pollIntervalMs);\n\t}\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached render state; the poller drives refresh.\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tif (this.pollTimer !== undefined) {\n\t\t\tclearInterval(this.pollTimer);\n\t\t\tthis.pollTimer = undefined;\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.killFeedback !== undefined) {\n\t\t\tthis.killFeedback = undefined;\n\t\t\tthis.killFeedbackTaskId = undefined;\n\t\t\tthis.tui.requestRender();\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\tif (this.view === \"detail\") {\n\t\t\t\tthis.view = \"list\";\n\t\t\t\tthis.tui.requestRender();\n\t\t\t} else {\n\t\t\t\tthis.onClose();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"app.backgroundTasks.kill\")) {\n\t\t\tthis.killSelected();\n\t\t\treturn;\n\t\t}\n\t\tif (this.view === \"list\") this.handleListInput(data);\n\t\telse this.handleDetailInput(data);\n\t}\n\n\tprivate handleListInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.moveSelection(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tthis.moveSelection(1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.confirm\")) {\n\t\t\tif (!this.selectedTask()) return;\n\t\t\tthis.view = \"detail\";\n\t\t\tthis.resetFollow();\n\t\t\tthis.tui.requestRender();\n\t\t}\n\t}\n\n\tprivate handleDetailInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.select.pageUp\")) {\n\t\t\tthis.scrollDetail(Math.max(1, this.detailBodyHeight()));\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.pageDown\")) {\n\t\t\tif (!this.follow) this.scrollDetail(-Math.max(1, this.detailBodyHeight()));\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.scrollDetail(1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tif (!this.follow) this.scrollDetail(-1);\n\t\t}\n\t}\n\n\t/** Scroll the detail viewport by `lines` (positive = back through history). */\n\tprivate scrollDetail(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\tconst max = this.maxTailOffset();\n\t\t\tif (max === 0) return; // Nothing above the viewport to scroll back to.\n\t\t\tthis.follow = false;\n\t\t\tthis.tailOffsetLines = Math.min(max, this.tailOffsetLines + lines);\n\t\t} else {\n\t\t\tif (this.follow) return;\n\t\t\tthis.tailOffsetLines = Math.max(0, this.tailOffsetLines + lines);\n\t\t\tif (this.tailOffsetLines === 0) {\n\t\t\t\tthis.follow = true;\n\t\t\t\tvoid this.refreshViewport();\n\t\t\t}\n\t\t}\n\t\tthis.tui.requestRender();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst body = this.view === \"list\" ? this.renderList(width) : this.renderDetail(width);\n\t\tconst border = this.theme.fg(\"border\", \"─\".repeat(Math.max(1, width)));\n\t\treturn [border, ...body, padLine(this.footerLine(), width), border];\n\t}\n\n\t// ── list view ──────────────────────────────────────────────────────────\n\n\t/** Task rows the terminal can spare; short windows trade rows for the transcript. */\n\tprivate listMaxVisible(): number {\n\t\treturn Math.min(LIST_MAX_VISIBLE, Math.max(LIST_MIN_VISIBLE, this.tui.terminal.rows - LIST_RESERVED_ROWS));\n\t}\n\n\tprivate renderList(width: number): string[] {\n\t\tconst lines: string[] = [];\n\t\tconst counts = this.countsLabel();\n\t\tconst title = counts ? `Background tasks — ${counts}` : \"Background tasks\";\n\t\tlines.push(padLine(this.theme.fg(\"accent\", this.theme.bold(title)), width));\n\n\t\tif (this.tasks.length === 0) {\n\t\t\tlines.push(padLine(this.theme.fg(\"muted\", \" (no tasks)\"), width));\n\t\t\treturn lines;\n\t\t}\n\n\t\tconst selected = this.selectedTask();\n\t\tconst maxVisible = this.listMaxVisible();\n\t\tconst visible = this.tasks.slice(this.listScrollTop, this.listScrollTop + maxVisible);\n\t\tlet seenRunning = false;\n\t\tfor (const task of visible) {\n\t\t\t// listTasks() orders running first, finished after: one separator at the boundary.\n\t\t\tif (seenRunning && task.status !== \"running\") {\n\t\t\t\tlines.push(padLine(this.theme.fg(\"muted\", \" ── finished ──\"), width));\n\t\t\t\tseenRunning = false;\n\t\t\t}\n\t\t\tif (task.status === \"running\") seenRunning = true;\n\t\t\tlines.push(this.renderTaskRow(task, task === selected, width));\n\t\t}\n\t\tif (this.tasks.length > maxVisible) {\n\t\t\tconst index = this.tasks.findIndex((task) => task.id === this.selectedTaskId);\n\t\t\tlines.push(padLine(this.theme.fg(\"muted\", ` (${index + 1}/${this.tasks.length})`), width));\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate renderTaskRow(task: BgTask, isSelected: boolean, width: number): string {\n\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\tconst label = task.description\n\t\t\t? `${task.description} — ${firstCommandLine(task.command)}`\n\t\t\t: firstCommandLine(task.command);\n\t\tif (isSelected) {\n\t\t\t// Pad to full width before styling so the selection background spans the row.\n\t\t\tconst plain = padLine(`→ ${statusGlyph(task.status, task.stalled)} ${task.id} ${duration} ${label}`, width);\n\t\t\treturn this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", plain));\n\t\t}\n\t\tconst glyph = this.theme.fg(statusColor(task.status, task.stalled), statusGlyph(task.status, task.stalled));\n\t\tconst id = this.theme.fg(\"accent\", task.id);\n\t\tconst rest = this.theme.fg(\"muted\", `${duration} ${label}`);\n\t\treturn padLine(` ${glyph} ${id} ${rest}`, width);\n\t}\n\n\tprivate countsLabel(): string {\n\t\tlet running = 0;\n\t\tfor (const task of this.tasks) if (task.status === \"running\") running++;\n\t\tconst ended = this.tasks.length - running;\n\t\tconst parts: string[] = [];\n\t\tif (running > 0) parts.push(`${running} running`);\n\t\tif (ended > 0) parts.push(`${ended} done`);\n\t\treturn parts.join(\" · \");\n\t}\n\n\t// ── detail view ────────────────────────────────────────────────────────\n\n\tprivate renderDetail(width: number): string[] {\n\t\tconst task = this.selectedTask();\n\t\tconst lines: string[] = [padLine(this.detailHeader(task), width)];\n\t\tconst height = this.detailBodyHeight();\n\t\tconst cache = task && this.tailCache?.taskId === task.id ? this.tailCache : undefined;\n\t\tif (cache?.error) {\n\t\t\tlines.push(padLine(this.theme.fg(\"error\", `Cannot read output: ${cache.error}`), width));\n\t\t\tfor (let row = 1; row < height; row++) lines.push(padLine(\"\", width));\n\t\t\treturn lines;\n\t\t}\n\t\tconst content = cache?.lines ?? [];\n\t\tconst fromEnd = this.follow ? 0 : this.tailOffsetLines;\n\t\tconst start = content.length - height - fromEnd;\n\t\tfor (let row = 0; row < height; row++) {\n\t\t\tconst line = content[start + row];\n\t\t\tlines.push(line === undefined ? padLine(\"\", width) : padLine(this.theme.fg(\"toolOutput\", line), width));\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate detailHeader(task: BgTask | undefined): string {\n\t\tif (!task) return this.theme.fg(\"muted\", \"(no task selected)\");\n\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? ` exit ${task.exitCode}` : \"\";\n\t\tconst resumeLabel = keyLabel(\"tui.select.pageDown\", { keybindings: this.keybindings });\n\t\tconst paused = this.follow ? \"\" : resumeLabel ? ` — paused (${resumeLabel} to follow)` : \" — paused\";\n\t\tconst fileName = task.outputPath.replace(/\\\\/g, \"/\").split(\"/\").at(-1) ?? task.outputPath;\n\t\tconst glyph = this.theme.fg(statusColor(task.status, task.stalled), statusGlyph(task.status, task.stalled));\n\t\tconst statusLabel = task.stalled ? \"running, waiting for input\" : task.status;\n\t\tconst header = `${task.id} · ${statusLabel}${exit} · ${duration} · ${formatSize(task.outputBytes)} · ${fileName}${paused}`;\n\t\treturn `${glyph} ${this.theme.fg(\"muted\", header)}`;\n\t}\n\n\tprivate detailBodyHeight(): number {\n\t\t// Inline component: keep the chat transcript visible above the menu.\n\t\treturn Math.min(20, Math.max(4, this.tui.terminal.rows - 8));\n\t}\n\n\t// ── shared behavior ────────────────────────────────────────────────────\n\n\tprivate footerLine(): string {\n\t\tif (this.killFeedback) return this.theme.fg(\"warning\", this.killFeedback);\n\t\tconst opts = { keybindings: this.keybindings };\n\t\tconst parts =\n\t\t\tthis.view === \"list\"\n\t\t\t\t? [\n\t\t\t\t\t\t`${keyLabel(\"tui.select.up\", opts)}/${keyLabel(\"tui.select.down\", opts)} select`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.confirm\", opts)} output`,\n\t\t\t\t\t\t`${keyLabel(\"app.backgroundTasks.kill\", opts)} kill`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.cancel\", opts)} close`,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t`${keyLabel(\"tui.select.up\", opts)}/${keyLabel(\"tui.select.down\", opts)} scroll`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.pageUp\", opts)}/${keyLabel(\"tui.select.pageDown\", opts)} page`,\n\t\t\t\t\t\t`${keyLabel(\"app.backgroundTasks.kill\", opts)} kill`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.cancel\", opts)} back`,\n\t\t\t\t\t];\n\t\treturn this.theme.fg(\"dim\", parts.join(\" · \"));\n\t}\n\n\tprivate selectedTask(): BgTask | undefined {\n\t\treturn this.tasks.find((task) => task.id === this.selectedTaskId);\n\t}\n\n\tprivate moveSelection(offset: -1 | 1): void {\n\t\tif (this.tasks.length === 0) return;\n\t\tconst current = this.tasks.findIndex((task) => task.id === this.selectedTaskId);\n\t\tconst next = (current + offset + this.tasks.length) % this.tasks.length;\n\t\tconst task = this.tasks[next];\n\t\tif (!task) return;\n\t\tthis.selectedTaskId = task.id;\n\t\tif (next < this.listScrollTop) this.listScrollTop = next;\n\t\tif (next >= this.listScrollTop + this.listMaxVisible()) {\n\t\t\tthis.listScrollTop = next - this.listMaxVisible() + 1;\n\t\t}\n\t\tthis.resetFollow();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate resetFollow(): void {\n\t\tthis.follow = true;\n\t\tthis.tailOffsetLines = 0;\n\t\tthis.tailCache = undefined;\n\t\tvoid this.refreshViewport();\n\t}\n\n\tprivate currentLines(): string[] {\n\t\tconst task = this.selectedTask();\n\t\tconst cache = this.tailCache;\n\t\treturn task && cache && cache.taskId === task.id ? cache.lines : [];\n\t}\n\n\tprivate maxTailOffset(): number {\n\t\treturn Math.max(0, this.currentLines().length - this.detailBodyHeight());\n\t}\n\n\tprivate killSelected(): void {\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return;\n\t\tif (task.status !== \"running\") {\n\t\t\tthis.killFeedback = `${task.id} is not running`;\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.host.killTask(task.id);\n\t\t// Terminal state lands on the next poll; the feedback expires with it (tick).\n\t\tthis.killFeedback = `stopping ${task.id}…`;\n\t\tthis.killFeedbackTaskId = task.id;\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate async tick(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.tasks = this.host.listTasks();\n\t\tif (!this.selectedTask() && this.tasks[0]) this.selectedTaskId = this.tasks[0].id;\n\t\tthis.expireKillFeedback();\n\t\tif (this.renderSignature() === this.lastSignature) return; // Nothing visible changed.\n\t\tif (this.view === \"detail\" && this.follow && this.detailOutputChanged()) {\n\t\t\tawait this.refreshViewport();\n\t\t}\n\t\tthis.lastSignature = this.renderSignature();\n\t\tthis.tui.requestRender();\n\t}\n\n\t/** Drop \"stopping\" feedback once its task has settled. */\n\tprivate expireKillFeedback(): void {\n\t\tif (this.killFeedbackTaskId === undefined) return;\n\t\tconst task = this.tasks.find((candidate) => candidate.id === this.killFeedbackTaskId);\n\t\tif (!task || task.status !== \"running\") {\n\t\t\tthis.killFeedback = undefined;\n\t\t\tthis.killFeedbackTaskId = undefined;\n\t\t}\n\t}\n\n\t/** Everything the rendered output depends on; equal signatures need no redraw. */\n\tprivate renderSignature(): string {\n\t\tconst parts = [\n\t\t\tthis.view,\n\t\t\tthis.selectedTaskId ?? \"\",\n\t\t\tString(this.listScrollTop),\n\t\t\tString(this.follow),\n\t\t\tString(this.tailOffsetLines),\n\t\t\tthis.killFeedback ?? \"\",\n\t\t\tthis.tailCache\n\t\t\t\t? `${this.tailCache.taskId}:${this.tailCache.lines.length}:${this.tailCache.totalBytes}:${this.tailCache.error ?? \"\"}:${String(this.tailCache.settledRead ?? false)}`\n\t\t\t\t: \"\",\n\t\t];\n\t\tfor (const task of this.tasks) {\n\t\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\t\tparts.push(\n\t\t\t\t`${task.id}:${task.status}:${String(task.stalled)}:${task.outputBytes}:${task.exitCode ?? \"\"}:${duration}`,\n\t\t\t);\n\t\t}\n\t\treturn parts.join(\"|\");\n\t}\n\n\t/** True when the detail viewport must re-read the output file this tick. */\n\tprivate detailOutputChanged(): boolean {\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return false;\n\t\tconst cache = this.tailCache;\n\t\tif (!cache || cache.taskId !== task.id) return true;\n\t\tif (cache.error !== undefined) return true; // Keep retrying; failed reads are cheap.\n\t\tif (task.status !== \"running\") {\n\t\t\t// Terminal task: the file is final — read it once, then never again.\n\t\t\treturn cache.settledRead !== true;\n\t\t}\n\t\treturn cache.totalBytes !== task.outputBytes;\n\t}\n\n\tprivate async refreshViewport(): Promise<void> {\n\t\tif (this.readBusy) return;\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return;\n\t\tthis.readBusy = true;\n\t\ttry {\n\t\t\tconst slice = await this.host.readSlice(task.outputPath, { mode: \"tail\", maxBytes: VIEW_TAIL_BYTES });\n\t\t\tif (this.disposed || this.selectedTaskId !== task.id || !this.follow) return;\n\t\t\tthis.tailCache = {\n\t\t\t\ttaskId: task.id,\n\t\t\t\tlines: toViewLines(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tsettledRead: task.status !== \"running\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (this.disposed || this.selectedTaskId !== task.id) return;\n\t\t\tthis.tailCache = {\n\t\t\t\ttaskId: task.id,\n\t\t\t\tlines: [],\n\t\t\t\ttotalBytes: task.outputBytes,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t} finally {\n\t\t\tthis.readBusy = false;\n\t\t}\n\t}\n}\n\nfunction toViewLines(text: string): string[] {\n\t// Strip ANSI first: sanitize would remove the escape bytes alone, leaving\n\t// orphaned \"[31m\" fragments that strip can no longer see.\n\tconst lines = sanitizeBinaryOutput(stripTerminalSequences(text)).split(\"\\n\");\n\t// Drop the trailing empty line produced by a final newline, then bound the\n\t// window: a 128KB slice of one-byte lines must never become 128k rows.\n\twhile (lines.length > 0 && lines[lines.length - 1] === \"\") lines.pop();\n\treturn lines.slice(-MAX_VIEW_LINES);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/extensions/background/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkC,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEjH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wDAAwD,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAe,gBAAgB,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,oFAAoF;AACpF,MAAM,kBAAkB,GAAG,EAAE,CAAC;AA+B9B,2EAA2E;AAC3E,SAAS,OAAO,CAAC,IAAY,EAAE,KAAa;IAC3C,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,OAAO,mBAAmB;IAyB/B,YAAY,OAAmC;QAjBvC,SAAI,GAAsB,MAAM,CAAC;QACjC,UAAK,GAAa,EAAE,CAAC;QAErB,kBAAa,GAAG,CAAC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* slot. Two views in one component: a task list, and a live output viewport\n * for the selected task (Enter to open, Esc to go back). The host dependency\n * is narrowed to three callbacks so the component stays testable.\n */\n\nimport { type Component, type Focusable, stripTerminalSequences, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { formatSize } from \"../../core/tools/truncate.ts\";\nimport { keyLabel } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { type BgTask, firstCommandLine, formatDuration, type OutputSlice } from \"./registry.ts\";\nimport { statusColor, statusGlyph } from \"./render.ts\";\n\nconst POLL_INTERVAL_MS = 1000;\nconst VIEW_TAIL_BYTES = 128 * 1024;\nconst MAX_VIEW_LINES = 2000;\nconst LIST_MAX_VISIBLE = 10;\nconst LIST_MIN_VISIBLE = 3;\n/** Rows outside the task list itself (borders, title, counter, footer, padding). */\nconst LIST_RESERVED_ROWS = 14;\n\nexport interface BackgroundManagerHost {\n\tlistTasks(): BgTask[];\n\tkillTask(id: string): { killed: boolean };\n\treadSlice(filePath: string, options: { mode: \"tail\"; maxBytes: number }): Promise<OutputSlice>;\n}\n\ninterface MenuTui {\n\trequestRender(): void;\n\tterminal: { rows: number; columns: number };\n}\n\nexport interface BackgroundTasksMenuOptions {\n\ttui: MenuTui;\n\ttheme: Theme;\n\tkeybindings: Pick<KeybindingsManager, \"matches\" | \"getKeys\">;\n\thost: BackgroundManagerHost;\n\tonClose: () => void;\n\tpollIntervalMs?: number;\n}\n\ninterface TailCache {\n\ttaskId: string;\n\tlines: string[];\n\ttotalBytes: number;\n\t/** True once a terminal task's final output has been read; skips re-reads. */\n\tsettledRead?: boolean;\n\terror?: string;\n}\n\n/** Truncate to an exact visible width, padding short lines with spaces. */\nfunction padLine(line: string, width: number): string {\n\treturn truncateToWidth(line, width, \"…\", true);\n}\n\nexport class BackgroundTasksMenu implements Component, Focusable {\n\tprivate readonly tui: MenuTui;\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: Pick<KeybindingsManager, \"matches\" | \"getKeys\">;\n\tprivate readonly host: BackgroundManagerHost;\n\tprivate readonly onClose: () => void;\n\tprivate readonly pollIntervalMs: number;\n\n\tprivate view: \"list\" | \"detail\" = \"list\";\n\tprivate tasks: BgTask[] = [];\n\tprivate selectedTaskId: string | undefined;\n\tprivate listScrollTop = 0;\n\tprivate follow = true;\n\tprivate tailOffsetLines = 0;\n\tprivate tailCache: TailCache | undefined;\n\tprivate killFeedback: string | undefined;\n\t/** Task whose settle expires killFeedback; undefined = persists until the next key. */\n\tprivate killFeedbackTaskId: string | undefined;\n\t/** Last tick's render signature; unchanged means nothing visible moved. */\n\tprivate lastSignature = \"\";\n\tprivate pollTimer: ReturnType<typeof setInterval> | undefined;\n\tprivate readBusy = false;\n\tprivate disposed = false;\n\tprivate _focused = false;\n\n\tconstructor(options: BackgroundTasksMenuOptions) {\n\t\tthis.tui = options.tui;\n\t\tthis.theme = options.theme;\n\t\tthis.keybindings = options.keybindings;\n\t\tthis.host = options.host;\n\t\tthis.onClose = options.onClose;\n\t\tthis.pollIntervalMs = options.pollIntervalMs ?? POLL_INTERVAL_MS;\n\n\t\tthis.tasks = this.host.listTasks();\n\t\tthis.selectedTaskId = this.tasks[0]?.id;\n\t\tvoid this.tick();\n\t\tthis.pollTimer = setInterval(() => void this.tick(), this.pollIntervalMs);\n\t}\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached render state; the poller drives refresh.\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tif (this.pollTimer !== undefined) {\n\t\t\tclearInterval(this.pollTimer);\n\t\t\tthis.pollTimer = undefined;\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.killFeedback !== undefined) {\n\t\t\tthis.killFeedback = undefined;\n\t\t\tthis.killFeedbackTaskId = undefined;\n\t\t\tthis.tui.requestRender();\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\tif (this.view === \"detail\") {\n\t\t\t\tthis.view = \"list\";\n\t\t\t\tthis.tui.requestRender();\n\t\t\t} else {\n\t\t\t\tthis.onClose();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"app.backgroundTasks.kill\")) {\n\t\t\tthis.killSelected();\n\t\t\treturn;\n\t\t}\n\t\tif (this.view === \"list\") this.handleListInput(data);\n\t\telse this.handleDetailInput(data);\n\t}\n\n\tprivate handleListInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.moveSelection(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tthis.moveSelection(1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.confirm\")) {\n\t\t\tif (!this.selectedTask()) return;\n\t\t\tthis.view = \"detail\";\n\t\t\tthis.resetFollow();\n\t\t\tthis.tui.requestRender();\n\t\t}\n\t}\n\n\tprivate handleDetailInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.select.pageUp\")) {\n\t\t\tthis.scrollDetail(Math.max(1, this.detailBodyHeight()));\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.pageDown\")) {\n\t\t\tif (!this.follow) this.scrollDetail(-Math.max(1, this.detailBodyHeight()));\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.scrollDetail(1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tif (!this.follow) this.scrollDetail(-1);\n\t\t}\n\t}\n\n\t/** Scroll the detail viewport by `lines` (positive = back through history). */\n\tprivate scrollDetail(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\tconst max = this.maxTailOffset();\n\t\t\tif (max === 0) return; // Nothing above the viewport to scroll back to.\n\t\t\tthis.follow = false;\n\t\t\tthis.tailOffsetLines = Math.min(max, this.tailOffsetLines + lines);\n\t\t} else {\n\t\t\tif (this.follow) return;\n\t\t\tthis.tailOffsetLines = Math.max(0, this.tailOffsetLines + lines);\n\t\t\tif (this.tailOffsetLines === 0) {\n\t\t\t\tthis.follow = true;\n\t\t\t\tvoid this.refreshViewport();\n\t\t\t}\n\t\t}\n\t\tthis.tui.requestRender();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst body = this.view === \"list\" ? this.renderList(width) : this.renderDetail(width);\n\t\tconst border = this.theme.fg(\"border\", \"─\".repeat(Math.max(1, width)));\n\t\treturn [border, ...body, padLine(this.footerLine(), width), border];\n\t}\n\n\t// ── list view ──────────────────────────────────────────────────────────\n\n\t/** Task rows the terminal can spare; short windows trade rows for the transcript. */\n\tprivate listMaxVisible(): number {\n\t\treturn Math.min(LIST_MAX_VISIBLE, Math.max(LIST_MIN_VISIBLE, this.tui.terminal.rows - LIST_RESERVED_ROWS));\n\t}\n\n\tprivate renderList(width: number): string[] {\n\t\tconst lines: string[] = [];\n\t\tconst counts = this.countsLabel();\n\t\tconst title = counts ? `Background tasks — ${counts}` : \"Background tasks\";\n\t\tlines.push(padLine(this.theme.fg(\"accent\", this.theme.bold(title)), width));\n\n\t\tif (this.tasks.length === 0) {\n\t\t\tlines.push(padLine(this.theme.fg(\"muted\", \" (no tasks)\"), width));\n\t\t\treturn lines;\n\t\t}\n\n\t\tconst selected = this.selectedTask();\n\t\tconst maxVisible = this.listMaxVisible();\n\t\tconst visible = this.tasks.slice(this.listScrollTop, this.listScrollTop + maxVisible);\n\t\tlet seenRunning = false;\n\t\tfor (const task of visible) {\n\t\t\t// listTasks() orders running first, finished after: one separator at the boundary.\n\t\t\tif (seenRunning && task.status !== \"running\") {\n\t\t\t\tlines.push(padLine(this.theme.fg(\"muted\", \" ── finished ──\"), width));\n\t\t\t\tseenRunning = false;\n\t\t\t}\n\t\t\tif (task.status === \"running\") seenRunning = true;\n\t\t\tlines.push(this.renderTaskRow(task, task === selected, width));\n\t\t}\n\t\tif (this.tasks.length > maxVisible) {\n\t\t\tconst index = this.tasks.findIndex((task) => task.id === this.selectedTaskId);\n\t\t\tlines.push(padLine(this.theme.fg(\"muted\", ` (${index + 1}/${this.tasks.length})`), width));\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate renderTaskRow(task: BgTask, isSelected: boolean, width: number): string {\n\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\tconst label = task.description\n\t\t\t? `${task.description} — ${firstCommandLine(task.command)}`\n\t\t\t: firstCommandLine(task.command);\n\t\tif (isSelected) {\n\t\t\t// Pad to full width before styling so the selection background spans the row.\n\t\t\tconst plain = padLine(`→ ${statusGlyph(task.status, task.stalled)} ${task.id} ${duration} ${label}`, width);\n\t\t\treturn this.theme.bg(\"selectedBg\", this.theme.fg(\"text\", plain));\n\t\t}\n\t\tconst glyph = this.theme.fg(statusColor(task.status, task.stalled), statusGlyph(task.status, task.stalled));\n\t\tconst id = this.theme.fg(\"accent\", task.id);\n\t\tconst rest = this.theme.fg(\"muted\", `${duration} ${label}`);\n\t\treturn padLine(` ${glyph} ${id} ${rest}`, width);\n\t}\n\n\tprivate countsLabel(): string {\n\t\tlet running = 0;\n\t\tfor (const task of this.tasks) if (task.status === \"running\") running++;\n\t\tconst ended = this.tasks.length - running;\n\t\tconst parts: string[] = [];\n\t\tif (running > 0) parts.push(`${running} running`);\n\t\tif (ended > 0) parts.push(`${ended} done`);\n\t\treturn parts.join(\" · \");\n\t}\n\n\t// ── detail view ────────────────────────────────────────────────────────\n\n\tprivate renderDetail(width: number): string[] {\n\t\tconst task = this.selectedTask();\n\t\tconst lines: string[] = [padLine(this.detailHeader(task), width)];\n\t\tconst height = this.detailBodyHeight();\n\t\tconst cache = task && this.tailCache?.taskId === task.id ? this.tailCache : undefined;\n\t\tif (cache?.error) {\n\t\t\tlines.push(padLine(this.theme.fg(\"error\", `Cannot read output: ${cache.error}`), width));\n\t\t\tfor (let row = 1; row < height; row++) lines.push(padLine(\"\", width));\n\t\t\treturn lines;\n\t\t}\n\t\tconst content = cache?.lines ?? [];\n\t\tconst fromEnd = this.follow ? 0 : this.tailOffsetLines;\n\t\tconst start = content.length - height - fromEnd;\n\t\tfor (let row = 0; row < height; row++) {\n\t\t\tconst line = content[start + row];\n\t\t\tlines.push(line === undefined ? padLine(\"\", width) : padLine(this.theme.fg(\"toolOutput\", line), width));\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate detailHeader(task: BgTask | undefined): string {\n\t\tif (!task) return this.theme.fg(\"muted\", \"(no task selected)\");\n\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\tconst exit = task.exitCode !== undefined && task.exitCode !== null ? ` exit ${task.exitCode}` : \"\";\n\t\tconst resumeLabel = keyLabel(\"tui.select.pageDown\", { keybindings: this.keybindings });\n\t\tconst paused = this.follow ? \"\" : resumeLabel ? ` — paused (${resumeLabel} to follow)` : \" — paused\";\n\t\tconst fileName = task.outputPath.replace(/\\\\/g, \"/\").split(\"/\").at(-1) ?? task.outputPath;\n\t\tconst glyph = this.theme.fg(statusColor(task.status, task.stalled), statusGlyph(task.status, task.stalled));\n\t\tconst statusLabel = task.stalled ? \"running, waiting for input\" : task.status;\n\t\tconst header = `${task.id} · ${statusLabel}${exit} · ${duration} · ${formatSize(task.outputBytes)} · ${fileName}${paused}`;\n\t\treturn `${glyph} ${this.theme.fg(\"muted\", header)}`;\n\t}\n\n\tprivate detailBodyHeight(): number {\n\t\t// Inline component: keep the chat transcript visible above the menu.\n\t\treturn Math.min(20, Math.max(4, this.tui.terminal.rows - 8));\n\t}\n\n\t// ── shared behavior ────────────────────────────────────────────────────\n\n\tprivate footerLine(): string {\n\t\tif (this.killFeedback) return this.theme.fg(\"warning\", this.killFeedback);\n\t\tconst opts = { keybindings: this.keybindings };\n\t\tconst parts =\n\t\t\tthis.view === \"list\"\n\t\t\t\t? [\n\t\t\t\t\t\t`${keyLabel(\"tui.select.up\", opts)}/${keyLabel(\"tui.select.down\", opts)} select`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.confirm\", opts)} output`,\n\t\t\t\t\t\t`${keyLabel(\"app.backgroundTasks.kill\", opts)} kill`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.cancel\", opts)} close`,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t`${keyLabel(\"tui.select.up\", opts)}/${keyLabel(\"tui.select.down\", opts)} scroll`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.pageUp\", opts)}/${keyLabel(\"tui.select.pageDown\", opts)} page`,\n\t\t\t\t\t\t`${keyLabel(\"app.backgroundTasks.kill\", opts)} kill`,\n\t\t\t\t\t\t`${keyLabel(\"tui.select.cancel\", opts)} back`,\n\t\t\t\t\t];\n\t\treturn this.theme.fg(\"dim\", parts.join(\" · \"));\n\t}\n\n\tprivate selectedTask(): BgTask | undefined {\n\t\treturn this.tasks.find((task) => task.id === this.selectedTaskId);\n\t}\n\n\tprivate moveSelection(offset: -1 | 1): void {\n\t\tif (this.tasks.length === 0) return;\n\t\tconst current = this.tasks.findIndex((task) => task.id === this.selectedTaskId);\n\t\tconst next = (current + offset + this.tasks.length) % this.tasks.length;\n\t\tconst task = this.tasks[next];\n\t\tif (!task) return;\n\t\tthis.selectedTaskId = task.id;\n\t\tif (next < this.listScrollTop) this.listScrollTop = next;\n\t\tif (next >= this.listScrollTop + this.listMaxVisible()) {\n\t\t\tthis.listScrollTop = next - this.listMaxVisible() + 1;\n\t\t}\n\t\tthis.resetFollow();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate resetFollow(): void {\n\t\tthis.follow = true;\n\t\tthis.tailOffsetLines = 0;\n\t\tthis.tailCache = undefined;\n\t\tvoid this.refreshViewport();\n\t}\n\n\tprivate currentLines(): string[] {\n\t\tconst task = this.selectedTask();\n\t\tconst cache = this.tailCache;\n\t\treturn task && cache && cache.taskId === task.id ? cache.lines : [];\n\t}\n\n\tprivate maxTailOffset(): number {\n\t\treturn Math.max(0, this.currentLines().length - this.detailBodyHeight());\n\t}\n\n\tprivate killSelected(): void {\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return;\n\t\tif (task.status !== \"running\") {\n\t\t\tthis.killFeedback = `${task.id} is not running`;\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.host.killTask(task.id);\n\t\t// Terminal state lands on the next poll; the feedback expires with it (tick).\n\t\tthis.killFeedback = `stopping ${task.id}…`;\n\t\tthis.killFeedbackTaskId = task.id;\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate async tick(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.tasks = this.host.listTasks();\n\t\tif (!this.selectedTask() && this.tasks[0]) this.selectedTaskId = this.tasks[0].id;\n\t\tthis.expireKillFeedback();\n\t\t// A pending re-read counts as a change: refreshViewport may skip this tick\n\t\t// (readBusy), and the signature alone would let that retry be dropped.\n\t\tconst needsRead = this.view === \"detail\" && this.follow && this.detailOutputChanged();\n\t\tif (!needsRead && this.renderSignature() === this.lastSignature) return; // Nothing visible changed.\n\t\tif (needsRead) await this.refreshViewport();\n\t\tthis.lastSignature = this.renderSignature();\n\t\tthis.tui.requestRender();\n\t}\n\n\t/** Drop \"stopping\" feedback once its task has settled. */\n\tprivate expireKillFeedback(): void {\n\t\tif (this.killFeedbackTaskId === undefined) return;\n\t\tconst task = this.tasks.find((candidate) => candidate.id === this.killFeedbackTaskId);\n\t\tif (!task || task.status !== \"running\") {\n\t\t\tthis.killFeedback = undefined;\n\t\t\tthis.killFeedbackTaskId = undefined;\n\t\t}\n\t}\n\n\t/** Everything the rendered output depends on; equal signatures need no redraw. */\n\tprivate renderSignature(): string {\n\t\tconst parts = [\n\t\t\tthis.view,\n\t\t\tthis.selectedTaskId ?? \"\",\n\t\t\tString(this.listScrollTop),\n\t\t\tString(this.follow),\n\t\t\tString(this.tailOffsetLines),\n\t\t\tthis.killFeedback ?? \"\",\n\t\t\tthis.tailCache\n\t\t\t\t? `${this.tailCache.taskId}:${this.tailCache.lines.length}:${this.tailCache.totalBytes}:${this.tailCache.error ?? \"\"}:${String(this.tailCache.settledRead ?? false)}`\n\t\t\t\t: \"\",\n\t\t];\n\t\tfor (const task of this.tasks) {\n\t\t\tconst duration = formatDuration((task.endedAt ?? Date.now()) - task.startedAt);\n\t\t\tparts.push(\n\t\t\t\t`${task.id}:${task.status}:${String(task.stalled)}:${task.outputBytes}:${task.exitCode ?? \"\"}:${duration}`,\n\t\t\t);\n\t\t}\n\t\treturn parts.join(\"|\");\n\t}\n\n\t/** True when the detail viewport must re-read the output file this tick. */\n\tprivate detailOutputChanged(): boolean {\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return false;\n\t\tconst cache = this.tailCache;\n\t\tif (!cache || cache.taskId !== task.id) return true;\n\t\tif (cache.error !== undefined) return true; // Keep retrying; failed reads are cheap.\n\t\tif (task.status !== \"running\") {\n\t\t\t// Terminal task: the file is final — read it once, then never again.\n\t\t\treturn cache.settledRead !== true;\n\t\t}\n\t\treturn cache.totalBytes !== task.outputBytes;\n\t}\n\n\tprivate async refreshViewport(): Promise<void> {\n\t\tif (this.readBusy) return;\n\t\tconst task = this.selectedTask();\n\t\tif (!task) return;\n\t\tthis.readBusy = true;\n\t\ttry {\n\t\t\tconst slice = await this.host.readSlice(task.outputPath, { mode: \"tail\", maxBytes: VIEW_TAIL_BYTES });\n\t\t\tif (this.disposed || this.selectedTaskId !== task.id || !this.follow) return;\n\t\t\tthis.tailCache = {\n\t\t\t\ttaskId: task.id,\n\t\t\t\tlines: toViewLines(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tsettledRead: task.status !== \"running\",\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (this.disposed || this.selectedTaskId !== task.id) return;\n\t\t\tthis.tailCache = {\n\t\t\t\ttaskId: task.id,\n\t\t\t\tlines: [],\n\t\t\t\ttotalBytes: task.outputBytes,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t} finally {\n\t\t\tthis.readBusy = false;\n\t\t}\n\t}\n}\n\nfunction toViewLines(text: string): string[] {\n\t// Strip ANSI first: sanitize would remove the escape bytes alone, leaving\n\t// orphaned \"[31m\" fragments that strip can no longer see.\n\tconst lines = sanitizeBinaryOutput(stripTerminalSequences(text)).split(\"\\n\");\n\t// Drop the trailing empty line produced by a final newline, then bound the\n\t// window: a 128KB slice of one-byte lines must never become 128k rows.\n\twhile (lines.length > 0 && lines[lines.length - 1] === \"\") lines.pop();\n\treturn lines.slice(-MAX_VIEW_LINES);\n}\n"]}
|
|
@@ -35,7 +35,10 @@ export interface BgTask {
|
|
|
35
35
|
endedAt?: number;
|
|
36
36
|
/** True when the stall watchdog flagged this task as waiting for input. */
|
|
37
37
|
stalled: boolean;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Process exit code; null when reaped by a signal, undefined while running
|
|
40
|
+
* or when the run produced none (spawn failure, kill, timeout).
|
|
41
|
+
*/
|
|
39
42
|
exitCode: number | null | undefined;
|
|
40
43
|
outputPath: string;
|
|
41
44
|
/** Bytes accepted into the output file (excludes the overflow notice). */
|
|
@@ -44,6 +47,7 @@ export interface BgTask {
|
|
|
44
47
|
outputTruncated: boolean;
|
|
45
48
|
error?: string;
|
|
46
49
|
timeoutSeconds?: number;
|
|
50
|
+
/** Delivery was claimed: onNotify returned without throwing, or a waiter took it over. */
|
|
47
51
|
notified: boolean;
|
|
48
52
|
}
|
|
49
53
|
export interface BgTaskNotification {
|
|
@@ -58,15 +62,7 @@ export interface BgTaskNotification {
|
|
|
58
62
|
tailError?: string;
|
|
59
63
|
}
|
|
60
64
|
/** One-shot signal that a running task appears blocked on interactive input. */
|
|
61
|
-
export
|
|
62
|
-
task: BgTask;
|
|
63
|
-
tailText: string;
|
|
64
|
-
tailBytes: number;
|
|
65
|
-
totalBytes: number;
|
|
66
|
-
tailTruncated: boolean;
|
|
67
|
-
tailStartsMidLine: boolean;
|
|
68
|
-
tailError?: string;
|
|
69
|
-
}
|
|
65
|
+
export type BgStallNotification = BgTaskNotification;
|
|
70
66
|
export interface OutputSlice {
|
|
71
67
|
text: string;
|
|
72
68
|
sliceBytes: number;
|
|
@@ -86,8 +82,7 @@ export type WaitOutcome = {
|
|
|
86
82
|
};
|
|
87
83
|
/**
|
|
88
84
|
* Read a bounded slice from the head or tail of a file via positioned reads —
|
|
89
|
-
* never the whole file.
|
|
90
|
-
* starts on a codepoint boundary.
|
|
85
|
+
* never the whole file.
|
|
91
86
|
*/
|
|
92
87
|
export declare function readOutputSlice(filePath: string, options: {
|
|
93
88
|
mode: "head" | "tail";
|
|
@@ -184,8 +179,11 @@ export declare class BackgroundTaskRegistry {
|
|
|
184
179
|
* registers before finalize's synchronous claim check claims delivery; one
|
|
185
180
|
* that arrives after sees a terminal status and returns it immediately
|
|
186
181
|
* (the followUp may also arrive — an idempotent repeat, not a lie).
|
|
182
|
+
*
|
|
183
|
+
* An aborted wait (the turn was interrupted) hands the claim back: the
|
|
184
|
+
* caller's result is discarded, so it must not also swallow the followUp.
|
|
187
185
|
*/
|
|
188
|
-
waitForResult(id: string, timeoutMs: number): Promise<WaitOutcome>;
|
|
186
|
+
waitForResult(id: string, timeoutMs: number, signal?: AbortSignal): Promise<WaitOutcome>;
|
|
189
187
|
/**
|
|
190
188
|
* Mute notifications, refuse new tasks, abort every running task, and wait
|
|
191
189
|
* (bounded) for their finalization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/extensions/background/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI/D,eAAO,MAAM,wBAAwB,QAAmB,CAAC;AACzD,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