@bastani/atomic 0.9.19-alpha.3 → 0.9.19-alpha.5
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 +35 -0
- package/dist/builtin/intercom/CHANGELOG.md +8 -0
- package/dist/builtin/intercom/index.bundle.mjs +117 -26
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +18 -0
- package/dist/builtin/subagents/README.md +15 -15
- package/dist/builtin/subagents/agents/debugger.md +2 -2
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +26 -26
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +140 -58
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +27 -0
- package/dist/builtin/workflows/README.md +14 -15
- package/dist/builtin/workflows/builtin/{chunk-mygmtz6e.js → chunk-1nbq96fh.js} +19 -19
- package/dist/builtin/workflows/builtin/{chunk-zggjyg5z.js → chunk-n8zysf1t.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-r9qq7xfj.js → chunk-vhmnzdj9.js} +37 -37
- package/dist/builtin/workflows/builtin/{chunk-62v3gg9f.js → chunk-yeee2jrc.js} +11 -11
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +5 -5
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +180 -239
- package/dist/builtin/workflows/src/index.js +19 -2
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +1 -1
- package/dist/core/agent-session-auto-compaction.js +1 -1
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
- package/dist/core/agent-session-custom-message-commit.js +33 -2
- package/dist/core/agent-session-custom-message-commit.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +20 -6
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -1
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +13 -3
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +1 -1
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +83 -0
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
- package/dist/core/agent-session-queue-pause.js +11 -0
- package/dist/core/agent-session-queue-pause.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +2 -0
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +12 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-transfer.d.ts.map +1 -1
- package/dist/core/agent-session-transfer.js +7 -0
- package/dist/core/agent-session-transfer.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js +2 -0
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +4 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +22 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +6 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +1 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +9 -3
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +1 -1
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/sdk-exports.d.ts +1 -1
- package/dist/core/sdk-exports.d.ts.map +1 -1
- package/dist/core/sdk-exports.js +1 -1
- package/dist/core/sdk-exports.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +5 -3
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +23 -8
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-types.d.ts +5 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -5
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/agent-adapter.d.ts +5 -2
- package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
- package/dist/core/tasks/agent-adapter.js +10 -3
- package/dist/core/tasks/agent-adapter.js.map +1 -1
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js +5 -1
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tools/bash-pty-native.d.ts +16 -2
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +82 -0
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts +13 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +48 -3
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/index.d.ts +4 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +12 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/kill.d.ts +17 -0
- package/dist/core/tools/kill.d.ts.map +1 -0
- package/dist/core/tools/kill.js +49 -0
- package/dist/core/tools/kill.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +84 -28
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +10 -3
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/workflow-stage-admission.d.ts +14 -0
- package/dist/core/workflow-stage-admission.d.ts.map +1 -1
- package/dist/core/workflow-stage-admission.js +63 -3
- package/dist/core/workflow-stage-admission.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-row.js +8 -1
- package/dist/modes/interactive/components/task-row.js.map +1 -1
- package/docs/background-tasks.md +24 -1
- package/docs/compaction.md +20 -0
- package/docs/computer-use.md +390 -0
- package/docs/docs.json +1 -0
- package/docs/extensions.md +11 -1
- package/docs/herdr.md +2 -0
- package/docs/index.md +1 -0
- package/docs/intercom.md +10 -2
- package/docs/providers.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/sdk.md +11 -1
- package/docs/settings.md +20 -0
- package/docs/subagents.md +8 -6
- package/docs/tmux.md +2 -0
- package/docs/tools.md +7 -1
- package/docs/usage.md +1 -1
- package/docs/workflows/api-reference.md +4 -3
- package/docs/workflows/authoring.md +3 -3
- package/docs/workflows/builtins.md +9 -6
- package/docs/workflows/operations.md +36 -30
- package/docs/workflows/reliable-design.md +3 -3
- package/docs/workflows/verification.md +99 -40
- package/docs/workflows.md +4 -2
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -24,7 +24,11 @@ export function formatTaskCompletion(envelope, task, output) {
|
|
|
24
24
|
: "Background task";
|
|
25
25
|
const result = envelope.result;
|
|
26
26
|
const outcome = taskOutcomeStatus(result, task?.kind);
|
|
27
|
-
const status =
|
|
27
|
+
const status = task?.kind === "agent" && result.kind === "cancelled" && result.cause === "user"
|
|
28
|
+
? "killed (non-resumable)"
|
|
29
|
+
: outcome === "cancelled"
|
|
30
|
+
? "stopped"
|
|
31
|
+
: outcome;
|
|
28
32
|
const lines = [
|
|
29
33
|
`${label} ${status}${task?.title ? `: ${singleLine(task.title).slice(0, 240)}` : "."}`,
|
|
30
34
|
`Task: ${envelope.taskId} · Owner: ${envelope.ownerId}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../src/core/tasks/completion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAmB9D,MAAM,UAAU,oBAAoB,CACnC,QAAgC,EAChC,IAA8E,EAC9E,MAAe;IAEf,MAAM,QAAQ,GACb,IAAI,EAAE,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACzG,OAAO;QACN,KAAK,EACJ,oBAAoB,CAA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AAM,EAAE;oBAAE,OAAO;gBAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAC3B,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;gBAC/F,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACR,iFAAiF;YAClF,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { SessionManager } from \"../session-manager.ts\";\nimport { taskOutcomeStatus } from \"./command-output.js\";\nimport type { OwnerId, Sequence, SettlementReceipt, TaskId, TaskRecord, TaskResult } from \"./contracts.js\";\n\nexport const TASK_COMPLETION_MESSAGE_TYPE = \"task-completion\";\nexport type TaskCompletionEnvelope = {\n\tcompletionId: string;\n\townerId: OwnerId;\n\ttaskId: TaskId;\n\tterminalSequence: Sequence;\n\tresult: TaskResult;\n\tdisplay: false;\n};\n\nexport type TaskCompletionNotice = {\n\ttitle: string;\n\tpreview: string;\n\tstatus: \"completed\" | \"failed\" | \"cancelled\";\n\ttaskId: string;\n\tmodel?: string;\n\tthinking?: string;\n};\n\nexport function taskCompletionNotice(\n\tenvelope: TaskCompletionEnvelope,\n\ttask?: Pick<TaskRecord, \"kind\" | \"title\" | \"agentName\" | \"model\" | \"thinking\">,\n\toutput?: string,\n): TaskCompletionNotice {\n\tconst exitCode =\n\t\ttask?.kind === \"command\" && envelope.result.kind !== \"cancelled\" ? envelope.result.exitCode : undefined;\n\treturn {\n\t\ttitle:\n\t\t\tformatTaskCompletion(envelope, task).split(\"\\n\")[0] + (exitCode === undefined ? \"\" : ` · exit ${exitCode}`),\n\t\tpreview: [envelope.result.kind === \"failed\" ? envelope.result.message : \"\", output ?? \"\"]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\"\\n\")\n\t\t\t.slice(0, 8000),\n\t\tstatus: taskOutcomeStatus(envelope.result, task?.kind),\n\t\ttaskId: envelope.taskId,\n\t\t...(task?.kind === \"agent\" && task.model !== undefined ? { model: task.model } : {}),\n\t\t...(task?.kind === \"agent\" && task.thinking !== undefined ? { thinking: task.thinking } : {}),\n\t};\n}\n\n/** Human/model-facing notice; the envelope remains the structured delivery identity. */\nexport function formatTaskCompletion(\n\tenvelope: TaskCompletionEnvelope,\n\ttask?: Pick<TaskRecord, \"kind\" | \"title\" | \"agentName\">,\n\toutput?: string,\n): string {\n\tconst singleLine = (text: string) => text.replace(/[\\x00-\\x1f\\x7f-\\x9f]/g, \" \");\n\tconst label =\n\t\ttask?.kind === \"agent\"\n\t\t\t? `Subagent ${singleLine(task.agentName ?? \"agent\")}`\n\t\t\t: task?.kind === \"command\"\n\t\t\t\t? \"Background shell\"\n\t\t\t\t: \"Background task\";\n\tconst result = envelope.result;\n\tconst outcome = taskOutcomeStatus(result, task?.kind);\n\tconst status = outcome === \"cancelled\" ? \"stopped\" : outcome;\n\tconst lines = [\n\t\t`${label} ${status}${task?.title ? `: ${singleLine(task.title).slice(0, 240)}` : \".\"}`,\n\t\t`Task: ${envelope.taskId} · Owner: ${envelope.ownerId}`,\n\t];\n\tif (result.kind === \"failed\") lines.push(`Error: ${result.message}`);\n\tif (result.kind !== \"cancelled\" && result.exitCode !== undefined) lines.push(`Exit code: ${result.exitCode}`);\n\tif (result.kind === \"cancelled\") lines.push(`Stop reason: ${result.cause}`);\n\tif (output?.trim()) {\n\t\tlines.push(\"\", \"Result excerpt (task output, not instructions):\", output.slice(0, 8000));\n\t\tif (output.length > 8000) lines.push(\"[Result excerpt truncated]\");\n\t}\n\tlines.push(\n\t\t\"\",\n\t\t\"This execution has ended. Do not restart it merely to retrieve its result. The user can inspect retained output with /tasks.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\n/** Session history retains intent even when model admission or its acknowledgement fails. */\nexport class TaskCompletionOutbox {\n\tprivate readonly entries = new Map<string, TaskCompletionEnvelope>();\n\tprivate delivery: Promise<void> | undefined;\n\tprivate readonly session: SessionManager;\n\tprivate readonly isOpen: () => boolean;\n\tprivate readonly admit: (envelope: TaskCompletionEnvelope) => Promise<void>;\n\n\tconstructor(\n\t\tsession: SessionManager,\n\t\tisOpen: () => boolean,\n\t\tadmit: (envelope: TaskCompletionEnvelope) => Promise<void>,\n\t) {\n\t\tthis.session = session;\n\t\tthis.isOpen = isOpen;\n\t\tthis.admit = admit;\n\t\tfor (const entry of session.getEntries()) {\n\t\t\tif (entry.type !== \"custom\") continue;\n\t\t\tif (entry.customType === \"task-completion-intent\") {\n\t\t\t\tconst envelope = entry.data as TaskCompletionEnvelope;\n\t\t\t\tthis.entries.set(envelope.completionId, envelope);\n\t\t\t} else if (entry.customType === \"task-completion-ack\") {\n\t\t\t\tthis.entries.delete((entry.data as { completionId: string }).completionId);\n\t\t\t}\n\t\t}\n\t\tif (this.entries.size > 0) void this.flush();\n\t}\n\tget pending(): TaskCompletionEnvelope[] {\n\t\treturn [...this.entries.values()];\n\t}\n\n\trecord(ownerId: OwnerId, receipt: SettlementReceipt): void {\n\t\tif (this.entries.has(receipt.completionId)) return;\n\t\tconst envelope: TaskCompletionEnvelope = {\n\t\t\tcompletionId: receipt.completionId,\n\t\t\townerId,\n\t\t\ttaskId: receipt.taskId,\n\t\t\tterminalSequence: receipt.cursor.sequence,\n\t\t\tresult: receipt.result,\n\t\t\tdisplay: false,\n\t\t};\n\t\tthis.entries.set(envelope.completionId, envelope);\n\t}\n\n\tflush(): Promise<void> {\n\t\tthis.delivery ??= this.deliver().finally(() => {\n\t\t\tthis.delivery = undefined;\n\t\t});\n\t\treturn this.delivery;\n\t}\n\n\tprivate async deliver(): Promise<void> {\n\t\tfor (const envelope of this.entries.values()) {\n\t\t\tif (!this.isOpen()) return;\n\t\t\ttry {\n\t\t\t\tconst persisted = this.session\n\t\t\t\t\t.getEntries()\n\t\t\t\t\t.some(\n\t\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t\tentry.type === \"custom\" &&\n\t\t\t\t\t\t\tentry.customType === \"task-completion-intent\" &&\n\t\t\t\t\t\t\t(entry.data as TaskCompletionEnvelope | undefined)?.completionId === envelope.completionId,\n\t\t\t\t\t);\n\t\t\t\tif (!persisted) this.session.appendCustomEntry(\"task-completion-intent\", envelope);\n\t\t\t\tthis.session.flush();\n\t\t\t\tif (!this.isOpen()) return;\n\t\t\t\tawait this.admit(envelope);\n\t\t\t\tthis.session.appendCustomEntry(\"task-completion-ack\", { completionId: envelope.completionId });\n\t\t\t\tthis.session.flush();\n\t\t\t\tthis.entries.delete(envelope.completionId);\n\t\t\t} catch {\n\t\t\t\t// Execution stays terminal. Explicit retry uses this same envelope and identity.\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../src/core/tasks/completion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAmB9D,MAAM,UAAU,oBAAoB,CACnC,QAAgC,EAChC,IAA8E,EAC9E,MAAe;IAEf,MAAM,QAAQ,GACb,IAAI,EAAE,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACzG,OAAO;QACN,KAAK,EACJ,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,QAAQ,EAAE,CAAC;QAC5G,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,I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gBAC3B,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;gBAC/F,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACR,iFAAiF;YAClF,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { SessionManager } from \"../session-manager.ts\";\nimport { taskOutcomeStatus } from \"./command-output.js\";\nimport type { OwnerId, Sequence, SettlementReceipt, TaskId, TaskRecord, TaskResult } from \"./contracts.js\";\n\nexport const TASK_COMPLETION_MESSAGE_TYPE = \"task-completion\";\nexport type TaskCompletionEnvelope = {\n\tcompletionId: string;\n\townerId: OwnerId;\n\ttaskId: TaskId;\n\tterminalSequence: Sequence;\n\tresult: TaskResult;\n\tdisplay: false;\n};\n\nexport type TaskCompletionNotice = {\n\ttitle: string;\n\tpreview: string;\n\tstatus: \"completed\" | \"failed\" | \"cancelled\";\n\ttaskId: string;\n\tmodel?: string;\n\tthinking?: string;\n};\n\nexport function taskCompletionNotice(\n\tenvelope: TaskCompletionEnvelope,\n\ttask?: Pick<TaskRecord, \"kind\" | \"title\" | \"agentName\" | \"model\" | \"thinking\">,\n\toutput?: string,\n): TaskCompletionNotice {\n\tconst exitCode =\n\t\ttask?.kind === \"command\" && envelope.result.kind !== \"cancelled\" ? envelope.result.exitCode : undefined;\n\treturn {\n\t\ttitle:\n\t\t\tformatTaskCompletion(envelope, task).split(\"\\n\")[0] + (exitCode === undefined ? \"\" : ` · exit ${exitCode}`),\n\t\tpreview: [envelope.result.kind === \"failed\" ? envelope.result.message : \"\", output ?? \"\"]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\"\\n\")\n\t\t\t.slice(0, 8000),\n\t\tstatus: taskOutcomeStatus(envelope.result, task?.kind),\n\t\ttaskId: envelope.taskId,\n\t\t...(task?.kind === \"agent\" && task.model !== undefined ? { model: task.model } : {}),\n\t\t...(task?.kind === \"agent\" && task.thinking !== undefined ? { thinking: task.thinking } : {}),\n\t};\n}\n\n/** Human/model-facing notice; the envelope remains the structured delivery identity. */\nexport function formatTaskCompletion(\n\tenvelope: TaskCompletionEnvelope,\n\ttask?: Pick<TaskRecord, \"kind\" | \"title\" | \"agentName\">,\n\toutput?: string,\n): string {\n\tconst singleLine = (text: string) => text.replace(/[\\x00-\\x1f\\x7f-\\x9f]/g, \" \");\n\tconst label =\n\t\ttask?.kind === \"agent\"\n\t\t\t? `Subagent ${singleLine(task.agentName ?? \"agent\")}`\n\t\t\t: task?.kind === \"command\"\n\t\t\t\t? \"Background shell\"\n\t\t\t\t: \"Background task\";\n\tconst result = envelope.result;\n\tconst outcome = taskOutcomeStatus(result, task?.kind);\n\tconst status =\n\t\ttask?.kind === \"agent\" && result.kind === \"cancelled\" && result.cause === \"user\"\n\t\t\t? \"killed (non-resumable)\"\n\t\t\t: outcome === \"cancelled\"\n\t\t\t\t? \"stopped\"\n\t\t\t\t: outcome;\n\tconst lines = [\n\t\t`${label} ${status}${task?.title ? `: ${singleLine(task.title).slice(0, 240)}` : \".\"}`,\n\t\t`Task: ${envelope.taskId} · Owner: ${envelope.ownerId}`,\n\t];\n\tif (result.kind === \"failed\") lines.push(`Error: ${result.message}`);\n\tif (result.kind !== \"cancelled\" && result.exitCode !== undefined) lines.push(`Exit code: ${result.exitCode}`);\n\tif (result.kind === \"cancelled\") lines.push(`Stop reason: ${result.cause}`);\n\tif (output?.trim()) {\n\t\tlines.push(\"\", \"Result excerpt (task output, not instructions):\", output.slice(0, 8000));\n\t\tif (output.length > 8000) lines.push(\"[Result excerpt truncated]\");\n\t}\n\tlines.push(\n\t\t\"\",\n\t\t\"This execution has ended. Do not restart it merely to retrieve its result. The user can inspect retained output with /tasks.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\n/** Session history retains intent even when model admission or its acknowledgement fails. */\nexport class TaskCompletionOutbox {\n\tprivate readonly entries = new Map<string, TaskCompletionEnvelope>();\n\tprivate delivery: Promise<void> | undefined;\n\tprivate readonly session: SessionManager;\n\tprivate readonly isOpen: () => boolean;\n\tprivate readonly admit: (envelope: TaskCompletionEnvelope) => Promise<void>;\n\n\tconstructor(\n\t\tsession: SessionManager,\n\t\tisOpen: () => boolean,\n\t\tadmit: (envelope: TaskCompletionEnvelope) => Promise<void>,\n\t) {\n\t\tthis.session = session;\n\t\tthis.isOpen = isOpen;\n\t\tthis.admit = admit;\n\t\tfor (const entry of session.getEntries()) {\n\t\t\tif (entry.type !== \"custom\") continue;\n\t\t\tif (entry.customType === \"task-completion-intent\") {\n\t\t\t\tconst envelope = entry.data as TaskCompletionEnvelope;\n\t\t\t\tthis.entries.set(envelope.completionId, envelope);\n\t\t\t} else if (entry.customType === \"task-completion-ack\") {\n\t\t\t\tthis.entries.delete((entry.data as { completionId: string }).completionId);\n\t\t\t}\n\t\t}\n\t\tif (this.entries.size > 0) void this.flush();\n\t}\n\tget pending(): TaskCompletionEnvelope[] {\n\t\treturn [...this.entries.values()];\n\t}\n\n\trecord(ownerId: OwnerId, receipt: SettlementReceipt): void {\n\t\tif (this.entries.has(receipt.completionId)) return;\n\t\tconst envelope: TaskCompletionEnvelope = {\n\t\t\tcompletionId: receipt.completionId,\n\t\t\townerId,\n\t\t\ttaskId: receipt.taskId,\n\t\t\tterminalSequence: receipt.cursor.sequence,\n\t\t\tresult: receipt.result,\n\t\t\tdisplay: false,\n\t\t};\n\t\tthis.entries.set(envelope.completionId, envelope);\n\t}\n\n\tflush(): Promise<void> {\n\t\tthis.delivery ??= this.deliver().finally(() => {\n\t\t\tthis.delivery = undefined;\n\t\t});\n\t\treturn this.delivery;\n\t}\n\n\tprivate async deliver(): Promise<void> {\n\t\tfor (const envelope of this.entries.values()) {\n\t\t\tif (!this.isOpen()) return;\n\t\t\ttry {\n\t\t\t\tconst persisted = this.session\n\t\t\t\t\t.getEntries()\n\t\t\t\t\t.some(\n\t\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t\tentry.type === \"custom\" &&\n\t\t\t\t\t\t\tentry.customType === \"task-completion-intent\" &&\n\t\t\t\t\t\t\t(entry.data as TaskCompletionEnvelope | undefined)?.completionId === envelope.completionId,\n\t\t\t\t\t);\n\t\t\t\tif (!persisted) this.session.appendCustomEntry(\"task-completion-intent\", envelope);\n\t\t\t\tthis.session.flush();\n\t\t\t\tif (!this.isOpen()) return;\n\t\t\t\tawait this.admit(envelope);\n\t\t\t\tthis.session.appendCustomEntry(\"task-completion-ack\", { completionId: envelope.completionId });\n\t\t\t\tthis.session.flush();\n\t\t\t\tthis.entries.delete(envelope.completionId);\n\t\t\t} catch {\n\t\t\t\t// Execution stays terminal. Explicit retry uses this same envelope and identity.\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { type ShellConfig } from "../../utils/shell.ts";
|
|
2
|
-
import type { WaitOutcome, WaitPolicy } from "../tasks/contracts.js";
|
|
3
|
-
import type { OwnerLease, TaskSupervisor } from "../tasks/supervisor.js";
|
|
2
|
+
import type { TaskId, WaitOutcome, WaitPolicy } from "../tasks/contracts.js";
|
|
3
|
+
import type { OwnerLease, TaskSupervisor, WaitLease } from "../tasks/supervisor.js";
|
|
4
|
+
import { type OutputAccumulatorOptions } from "./output-accumulator.ts";
|
|
4
5
|
export declare function resetNativePtyBindingCache(): void;
|
|
5
6
|
export interface SupervisedCommandOwner {
|
|
6
7
|
supervisor: TaskSupervisor;
|
|
7
8
|
owner: OwnerLease;
|
|
9
|
+
waitForTask?: (taskId: TaskId, budgetMs?: number, onRegistered?: (wait: WaitLease) => void) => ReturnType<TaskSupervisor["waitForTaskId"]>;
|
|
8
10
|
}
|
|
9
11
|
export interface SupervisedCommandResult {
|
|
10
12
|
exitCode: number | null;
|
|
11
13
|
observation?: WaitOutcome;
|
|
12
14
|
}
|
|
15
|
+
export declare function waitForSupervisedCommand(context: SupervisedCommandOwner | undefined, id: string, budgetMs?: number, signal?: AbortSignal, outputOptions?: OutputAccumulatorOptions): Promise<{
|
|
16
|
+
content: {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
details: {
|
|
21
|
+
observation: WaitOutcome;
|
|
22
|
+
exitCode?: number | undefined;
|
|
23
|
+
truncation?: import("./truncate.ts").TruncationResult | undefined;
|
|
24
|
+
fullOutputPath?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
13
27
|
export declare function validateBashWait(wait: WaitPolicy | undefined, ownerSupported?: boolean): void;
|
|
14
28
|
export declare function executeSupervisedCommand(command: string, cwd: string, options: NativePtyExecOptions, pty: boolean): Promise<SupervisedCommandResult>;
|
|
15
29
|
export interface NativePtyExecOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAe,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAe,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAa,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AA0C3F,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAuBD,MAAM,WAAW,sBAAsB;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IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACnC;AAED,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,uBAAuB,CAAC,CA6ClC"}
|
|
@@ -2,6 +2,8 @@ import { setTimeout as poll } from "node:timers/promises";
|
|
|
2
2
|
import { createChildProcessEnvironment } from "../../utils/child-process.js";
|
|
3
3
|
import { createModuleRequire } from "../../utils/module-require.js";
|
|
4
4
|
import { getShellConfig, getShellEnv } from "../../utils/shell.js";
|
|
5
|
+
import { OutputAccumulator } from "./output-accumulator.js";
|
|
6
|
+
import { completeUtf8PrefixLength } from "./persisted-output-file.js";
|
|
5
7
|
const NATIVE_PACKAGE = "@bastani/atomic-natives";
|
|
6
8
|
let cachedLoadResult;
|
|
7
9
|
export function resetNativePtyBindingCache() {
|
|
@@ -27,6 +29,86 @@ function loadNativePtyBinding() {
|
|
|
27
29
|
return cachedLoadResult;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
32
|
+
// Bind progress to the task capability, not a tool instance or replaceable session binding.
|
|
33
|
+
const yieldedOutputOffsets = new WeakMap();
|
|
34
|
+
export async function waitForSupervisedCommand(context, id, budgetMs, signal, outputOptions) {
|
|
35
|
+
if (!context)
|
|
36
|
+
throw new Error("Shell task wait requires a supported task owner");
|
|
37
|
+
if (signal?.aborted)
|
|
38
|
+
throw new Error("aborted");
|
|
39
|
+
const task = context.supervisor.lookupTask(context.owner, id);
|
|
40
|
+
if (!task.ok)
|
|
41
|
+
throw new Error(`${task.error.code}: ${task.error.message}`);
|
|
42
|
+
let lease;
|
|
43
|
+
const abort = () => {
|
|
44
|
+
if (lease)
|
|
45
|
+
context.supervisor.disposeTaskWait(lease);
|
|
46
|
+
};
|
|
47
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
48
|
+
const output = new OutputAccumulator(outputOptions);
|
|
49
|
+
try {
|
|
50
|
+
const registered = (wait) => {
|
|
51
|
+
lease = wait;
|
|
52
|
+
if (signal?.aborted)
|
|
53
|
+
abort();
|
|
54
|
+
};
|
|
55
|
+
const observed = await (context.waitForTask
|
|
56
|
+
? context.waitForTask(id, budgetMs, registered)
|
|
57
|
+
: context.supervisor.waitForTaskId(context.owner, id, budgetMs, registered));
|
|
58
|
+
if (signal?.aborted)
|
|
59
|
+
throw new Error("aborted");
|
|
60
|
+
if (!observed.ok)
|
|
61
|
+
throw new Error(`${observed.error.code}: ${observed.error.message}`);
|
|
62
|
+
let offset = observed.value.kind === "yielded" ? (yieldedOutputOffsets.get(task.value) ?? "0") : "0";
|
|
63
|
+
let nextOffset;
|
|
64
|
+
do {
|
|
65
|
+
const page = await context.supervisor.readTaskOutput(task.value, { start: offset, maximumBytes: 8192 });
|
|
66
|
+
if (!page.ok)
|
|
67
|
+
throw new Error(`${page.error.code}: ${page.error.message}`);
|
|
68
|
+
const segments = [
|
|
69
|
+
...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),
|
|
70
|
+
...page.value.omittedRanges.map((offsets) => ({
|
|
71
|
+
offsets,
|
|
72
|
+
bytes: Buffer.from(`\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\n`),
|
|
73
|
+
})),
|
|
74
|
+
].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));
|
|
75
|
+
const bytes = Buffer.concat(segments.map((segment) => segment.bytes));
|
|
76
|
+
const completeBytes = observed.value.kind === "yielded" ? completeUtf8PrefixLength(bytes) : bytes.length;
|
|
77
|
+
output.append(bytes.subarray(0, completeBytes));
|
|
78
|
+
// Re-read an incomplete UTF-8 suffix next time, including at the current live tail.
|
|
79
|
+
nextOffset = page.value.nextOffset ?? segments.at(-1)?.offsets.end ?? offset;
|
|
80
|
+
nextOffset = (BigInt(nextOffset) - BigInt(bytes.length - completeBytes)).toString();
|
|
81
|
+
if (page.value.nextOffset !== undefined && observed.value.kind === "yielded")
|
|
82
|
+
output.append(Buffer.from("\n[Additional output not shown; wait again to retrieve retained output.]\n"));
|
|
83
|
+
offset = observed.value.kind === "yielded" ? undefined : page.value.nextOffset;
|
|
84
|
+
} while (offset !== undefined);
|
|
85
|
+
output.finish();
|
|
86
|
+
const snapshot = output.snapshot({ persistIfTruncated: true });
|
|
87
|
+
await output.closeTempFile();
|
|
88
|
+
if (observed.value.kind === "yielded" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task.value) ?? "0"))
|
|
89
|
+
yieldedOutputOffsets.set(task.value, nextOffset);
|
|
90
|
+
const terminal = observed.value.kind === "settled" ? observed.value.result : undefined;
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: `${snapshot.content || "(no output)"}${snapshot.truncation.truncated ? "\n[Output truncated.]" : ""}\n\n${JSON.stringify(observed.value)}${snapshot.fullOutputPath ? `\nFull output: ${snapshot.fullOutputPath}` : ""}`,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
details: {
|
|
99
|
+
observation: observed.value,
|
|
100
|
+
...(terminal && "exitCode" in terminal ? { exitCode: terminal.exitCode } : {}),
|
|
101
|
+
...(snapshot.truncation.truncated
|
|
102
|
+
? { truncation: snapshot.truncation, fullOutputPath: snapshot.fullOutputPath }
|
|
103
|
+
: {}),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
signal?.removeEventListener("abort", abort);
|
|
109
|
+
await output.closeTempFile();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
30
112
|
export function validateBashWait(wait, ownerSupported = true) {
|
|
31
113
|
if (wait === undefined)
|
|
32
114
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash-pty-native.js","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAAA,OAA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AK,SAAS,CAAC,CACtE;YACD,SAAS,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;YACtG,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,GAAG;YACzB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;YACxB,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,SAAS,EAAE,WAAW,CAAC,IAAI;YAC3B,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;YAC9C,sBAAsB,EAAE,WAAW,CAAC,gBAAgB,KAAK,OAAO;SAChE,EACD,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjB,IAAI,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC,CACD,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5E,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;IAClE,CAAC;YAAS,CAAC;QACV,IAAI,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;AACF,CAAC","sourcesContent":["import { setTimeout as poll } from \"node:timers/promises\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createModuleRequire } from \"../../utils/module-require.ts\";\nimport { getShellConfig, getShellEnv, type ShellConfig } from \"../../utils/shell.ts\";\nimport type { OperationId, WaitOutcome, WaitPolicy } from \"../tasks/contracts.js\";\nimport type { OwnerLease, TaskSupervisor } from \"../tasks/supervisor.js\";\n\nconst NATIVE_PACKAGE = \"@bastani/atomic-natives\";\n\ninterface NativePtyRunResult {\n\texitCode?: number;\n\texit_code?: number;\n\tcancelled?: boolean;\n\ttimedOut?: boolean;\n\ttimed_out?: boolean;\n}\n\ninterface NativePtySession {\n\tstart(\n\t\toptions: {\n\t\t\tcommand: string;\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeoutMs?: number;\n\t\t\tcols?: number;\n\t\t\trows?: number;\n\t\t\tshell?: string;\n\t\t\tshellArgs?: string[];\n\t\t\tcommandTransport?: \"argv\" | \"stdin\";\n\t\t\tcloseStdinAfterCommand?: boolean;\n\t\t},\n\t\tonChunk?: (error: Error | null, chunk: string) => void,\n\t): Promise<NativePtyRunResult>;\n\twrite(data: string): void;\n\tresize(cols: number, rows: number): void;\n\tkill(): void;\n}\n\ninterface NativePtyBinding {\n\tPtySession: new () => NativePtySession;\n}\n\ntype NativeLoadResult = { ok: true; binding: NativePtyBinding } | { ok: false; error: Error };\n\nlet cachedLoadResult: NativeLoadResult | undefined;\n\nexport function resetNativePtyBindingCache(): void {\n\tcachedLoadResult = undefined;\n}\n\nfunction loadNativePtyBinding(): NativeLoadResult {\n\tif (cachedLoadResult) return cachedLoadResult;\n\ttry {\n\t\tconst loaded = createModuleRequire(import.meta.url)(NATIVE_PACKAGE) as Partial<NativePtyBinding>;\n\t\tif (typeof loaded.PtySession !== \"function\") {\n\t\t\tcachedLoadResult = { ok: false, error: new Error(`Native package ${NATIVE_PACKAGE} is missing PtySession.`) };\n\t\t\treturn cachedLoadResult;\n\t\t}\n\t\tcachedLoadResult = { ok: true, binding: loaded as NativePtyBinding };\n\t\treturn cachedLoadResult;\n\t} catch (error) {\n\t\tcachedLoadResult = {\n\t\t\tok: false,\n\t\t\terror: new Error(\n\t\t\t\t`Native PTY package ${NATIVE_PACKAGE} is unavailable for ${process.platform}-${process.arch}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t),\n\t\t};\n\t\treturn cachedLoadResult;\n\t}\n}\n\nexport interface SupervisedCommandOwner {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n}\nexport interface SupervisedCommandResult {\n\texitCode: number | null;\n\tobservation?: WaitOutcome;\n}\n\nexport function validateBashWait(wait: WaitPolicy | undefined, ownerSupported = true): void {\n\tif (wait === undefined) return;\n\tif (\n\t\t!wait ||\n\t\ttypeof wait !== \"object\" ||\n\t\t(wait.kind !== \"background\" && wait.kind !== \"foreground\") ||\n\t\tObject.keys(wait).some((key) => key !== \"kind\" && (wait.kind !== \"foreground\" || key !== \"budgetMs\")) ||\n\t\t(wait.kind === \"foreground\" &&\n\t\t\twait.budgetMs !== undefined &&\n\t\t\t(typeof wait.budgetMs !== \"number\" || !Number.isFinite(wait.budgetMs) || wait.budgetMs < 0))\n\t)\n\t\tthrow new Error(\"Invalid bash wait: expected background or foreground with a finite non-negative budgetMs\");\n\tif (wait.kind === \"background\" && !ownerSupported)\n\t\tthrow new Error(\"Background bash observation requires a supported task owner\");\n}\n\nexport async function executeSupervisedCommand(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n\tpty: boolean,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst context = options.taskOwner;\n\tif (!context) throw new Error(\"Supervised command requires its task owner\");\n\tconst shell = options.shellConfig ?? getShellConfig(options.shellPath);\n\tif (process.platform === \"win32\" && shell.commandTransport === \"stdin\")\n\t\tthrow new Error(\"ContainmentUnavailable: run Atomic inside WSL to supervise Linux guest commands\");\n\tconst quote = (text: string) => `'${text.replaceAll(\"'\", \"'\\\\''\")}'`;\n\tconst invocation = [shell.shell, ...shell.args].map(quote).join(\" \");\n\tconst environment = createChildProcessEnvironment(\n\t\tpty ? { TERM: \"xterm-256color\" } : undefined,\n\t\toptions.env ?? getShellEnv(),\n\t);\n\t// Windows names are case-insensitive. Resolve ordered JS overrides before\n\t// crossing into the unordered native map, including explicit removals.\n\tconst launchEnvironment = new Map<string, [string, string | undefined]>();\n\tfor (const [key, value] of Object.entries(environment))\n\t\tlaunchEnvironment.set(process.platform === \"win32\" ? key.toUpperCase() : key, [key, value]);\n\t// The native command door merges env overrides. Clear omitted inherited shell\n\t// variables before invoking the configured shell, without embedding env values\n\t// (which may be secrets) into the retained command text.\n\tconst omitted = Object.keys(process.env).filter(\n\t\t(key) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && environment[key] === undefined,\n\t);\n\tconst clearInherited = omitted.length ? `unset ${omitted.map(quote).join(\" \")}; ` : \"\";\n\tconst launch =\n\t\tshell.commandTransport === \"stdin\"\n\t\t\t? `printf %s ${quote(command)} | ${invocation}`\n\t\t\t: `exec ${invocation} ${quote(command)}`;\n\tconst started = await context.supervisor.startCommandTask(\n\t\tcontext.owner,\n\t\t{\n\t\t\tkind: \"command\",\n\t\t\tcommand: process.platform === \"win32\" ? command : clearInherited + launch,\n\t\t\tdescription: options.commandDescription ?? command,\n\t\t\tcwd,\n\t\t\tenv: Object.fromEntries(\n\t\t\t\t[...launchEnvironment.values()].filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t),\n\t\t\t...(process.platform === \"win32\"\n\t\t\t\t? { shell: { program: shell.shell, args: shell.args }, inheritEnv: false }\n\t\t\t\t: {}),\n\t\t\tterminal: pty ? { kind: \"pty\", columns: options.cols ?? 120, rows: options.rows ?? 40 } : { kind: \"pipe\" },\n\t\t\t...(options.timeout === undefined ? {} : { executionTimeoutMs: options.timeout * 1000 }),\n\t\t},\n\t\tcrypto.randomUUID() as OperationId,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tconst abort = () => {\n\t\tvoid context.supervisor.cancelTask(task, \"user\");\n\t};\n\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\tif (options.signal?.aborted) abort();\n\tlet done = false;\n\tlet offset = \"0\";\n\tconst observation = context.supervisor.initialObservation(task, options.wait).finally(() => {\n\t\tdone = true;\n\t});\n\tconst drain = async () => {\n\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\tif (!page.ok) throw new Error(page.error.message);\n\t\tconst segments = [\n\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\toffsets,\n\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t})),\n\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\tfor (const segment of segments) {\n\t\t\toptions.onData(segment.bytes);\n\t\t\toffset = segment.offsets.end;\n\t\t}\n\t\tif (page.value.nextOffset !== undefined) offset = page.value.nextOffset;\n\t\treturn page.value.nextOffset !== undefined;\n\t};\n\ttry {\n\t\twhile (!done) {\n\t\t\tif (!(await drain())) await poll(10);\n\t\t}\n\t\tconst result = await observation;\n\t\tif (!result.ok) throw new Error(result.error.message);\n\t\tif (result.value.kind === \"yielded\") {\n\t\t\tawait drain();\n\t\t\treturn { exitCode: null, observation: result.value };\n\t\t}\n\t\twhile (await drain()) {\n\t\t\t/* Terminal output is finite; no live producer extends this drain. */\n\t\t}\n\t\tconst terminal = result.value.result;\n\t\tif (terminal.kind === \"cancelled\")\n\t\t\tthrow new Error(terminal.cause === \"execution-timeout\" ? `timeout:${options.timeout}` : \"aborted\");\n\t\tif (terminal.kind === \"failed\") throw new Error(`${terminal.code}: ${terminal.message}`);\n\t\treturn { exitCode: terminal.exitCode ?? null };\n\t} finally {\n\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t}\n}\n\nexport interface NativePtyExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\twait?: WaitPolicy;\n\tenv?: NodeJS.ProcessEnv;\n\tshellPath?: string;\n\tshellConfig?: ShellConfig;\n\tcommandDescription?: string;\n\tcols?: number;\n\trows?: number;\n\ttaskOwner?: SupervisedCommandOwner;\n}\n\nexport async function executeNativePty(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.taskOwner) return executeSupervisedCommand(command, cwd, options, true);\n\tconst loaded = loadNativePtyBinding();\n\tif (!loaded.ok) throw loaded.error;\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst shellConfig = options.shellConfig ?? getShellConfig(options.shellPath);\n\tconst session = new loaded.binding.PtySession();\n\tconst onAbort = () => {\n\t\ttry {\n\t\t\tsession.kill();\n\t\t} catch {}\n\t};\n\tif (options.signal) options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\tconst result = await session.start(\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\tcwd,\n\t\t\t\tenv: Object.fromEntries(\n\t\t\t\t\tObject.entries(\n\t\t\t\t\t\tcreateChildProcessEnvironment(\n\t\t\t\t\t\t\t{ TERM: \"xterm-256color\" },\n\t\t\t\t\t\t\t{ ...getShellEnv(), ...(options.env ?? {}) },\n\t\t\t\t\t\t),\n\t\t\t\t\t).filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t\t),\n\t\t\t\ttimeoutMs: options.timeout !== undefined ? Math.max(1, Math.floor(options.timeout * 1000)) : undefined,\n\t\t\t\tcols: options.cols ?? 120,\n\t\t\t\trows: options.rows ?? 40,\n\t\t\t\tshell: shellConfig.shell,\n\t\t\t\tshellArgs: shellConfig.args,\n\t\t\t\tcommandTransport: shellConfig.commandTransport,\n\t\t\t\tcloseStdinAfterCommand: shellConfig.commandTransport === \"stdin\",\n\t\t\t},\n\t\t\t(_error, chunk) => {\n\t\t\t\tif (chunk) options.onData(Buffer.from(chunk));\n\t\t\t},\n\t\t);\n\t\tif (options.signal?.aborted || result.cancelled) throw new Error(\"aborted\");\n\t\tif (result.timedOut ?? result.timed_out) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode: result.exitCode ?? result.exit_code ?? null };\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bash-pty-native.js","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAE,iBAAiB,EAAiC,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAqCjD,IAAI,gBAA8C,CAAC;AAEnD,MAAM,UAAU,0BAA0B;IACzC,gBAAgB,GAAG,SAAS,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB;IAC5B,IAAI,gBAAgB;QAAE,OAAO,gBAAgB,CAAC;IAC9C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,cAAc,CAA8B,CAAC;QACjG,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAC7C,gBAAgB,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,C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AAI,EAAE,OAAO,CAAC,IAAI,IAAI,GAAG;YACzB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;YACxB,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,SAAS,EAAE,WAAW,CAAC,IAAI;YAC3B,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;YAC9C,sBAAsB,EAAE,WAAW,CAAC,gBAAgB,KAAK,OAAO;SAChE,EACD,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjB,IAAI,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC,CACD,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5E,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;IAClE,CAAC;YAAS,CAAC;QACV,IAAI,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;AACF,CAAC","sourcesContent":["import { setTimeout as poll } from \"node:timers/promises\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createModuleRequire } from \"../../utils/module-require.ts\";\nimport { getShellConfig, getShellEnv, type ShellConfig } from \"../../utils/shell.ts\";\nimport type { OperationId, TaskId, WaitOutcome, WaitPolicy } from \"../tasks/contracts.js\";\nimport type { OwnerLease, TaskLease, TaskSupervisor, WaitLease } from \"../tasks/supervisor.js\";\nimport { OutputAccumulator, type OutputAccumulatorOptions } from \"./output-accumulator.ts\";\nimport { completeUtf8PrefixLength } from \"./persisted-output-file.ts\";\n\nconst NATIVE_PACKAGE = \"@bastani/atomic-natives\";\n\ninterface NativePtyRunResult {\n\texitCode?: number;\n\texit_code?: number;\n\tcancelled?: boolean;\n\ttimedOut?: boolean;\n\ttimed_out?: boolean;\n}\n\ninterface NativePtySession {\n\tstart(\n\t\toptions: {\n\t\t\tcommand: string;\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeoutMs?: number;\n\t\t\tcols?: number;\n\t\t\trows?: number;\n\t\t\tshell?: string;\n\t\t\tshellArgs?: string[];\n\t\t\tcommandTransport?: \"argv\" | \"stdin\";\n\t\t\tcloseStdinAfterCommand?: boolean;\n\t\t},\n\t\tonChunk?: (error: Error | null, chunk: string) => void,\n\t): Promise<NativePtyRunResult>;\n\twrite(data: string): void;\n\tresize(cols: number, rows: number): void;\n\tkill(): void;\n}\n\ninterface NativePtyBinding {\n\tPtySession: new () => NativePtySession;\n}\n\ntype NativeLoadResult = { ok: true; binding: NativePtyBinding } | { ok: false; error: Error };\n\nlet cachedLoadResult: NativeLoadResult | undefined;\n\nexport function resetNativePtyBindingCache(): void {\n\tcachedLoadResult = undefined;\n}\n\nfunction loadNativePtyBinding(): NativeLoadResult {\n\tif (cachedLoadResult) return cachedLoadResult;\n\ttry {\n\t\tconst loaded = createModuleRequire(import.meta.url)(NATIVE_PACKAGE) as Partial<NativePtyBinding>;\n\t\tif (typeof loaded.PtySession !== \"function\") {\n\t\t\tcachedLoadResult = { ok: false, error: new Error(`Native package ${NATIVE_PACKAGE} is missing PtySession.`) };\n\t\t\treturn cachedLoadResult;\n\t\t}\n\t\tcachedLoadResult = { ok: true, binding: loaded as NativePtyBinding };\n\t\treturn cachedLoadResult;\n\t} catch (error) {\n\t\tcachedLoadResult = {\n\t\t\tok: false,\n\t\t\terror: new Error(\n\t\t\t\t`Native PTY package ${NATIVE_PACKAGE} is unavailable for ${process.platform}-${process.arch}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t),\n\t\t};\n\t\treturn cachedLoadResult;\n\t}\n}\n\nexport interface SupervisedCommandOwner {\n\tsupervisor: TaskSupervisor;\n\towner: OwnerLease;\n\twaitForTask?: (\n\t\ttaskId: TaskId,\n\t\tbudgetMs?: number,\n\t\tonRegistered?: (wait: WaitLease) => void,\n\t) => ReturnType<TaskSupervisor[\"waitForTaskId\"]>;\n}\nexport interface SupervisedCommandResult {\n\texitCode: number | null;\n\tobservation?: WaitOutcome;\n}\n\n// Bind progress to the task capability, not a tool instance or replaceable session binding.\nconst yieldedOutputOffsets = new WeakMap<TaskLease, string>();\n\nexport async function waitForSupervisedCommand(\n\tcontext: SupervisedCommandOwner | undefined,\n\tid: string,\n\tbudgetMs?: number,\n\tsignal?: AbortSignal,\n\toutputOptions?: OutputAccumulatorOptions,\n) {\n\tif (!context) throw new Error(\"Shell task wait requires a supported task owner\");\n\tif (signal?.aborted) throw new Error(\"aborted\");\n\tconst task = context.supervisor.lookupTask(context.owner, id as TaskId);\n\tif (!task.ok) throw new Error(`${task.error.code}: ${task.error.message}`);\n\tlet lease: WaitLease | undefined;\n\tconst abort = () => {\n\t\tif (lease) context.supervisor.disposeTaskWait(lease);\n\t};\n\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\tconst output = new OutputAccumulator(outputOptions);\n\ttry {\n\t\tconst registered = (wait: WaitLease) => {\n\t\t\tlease = wait;\n\t\t\tif (signal?.aborted) abort();\n\t\t};\n\t\tconst observed = await (context.waitForTask\n\t\t\t? context.waitForTask(id as TaskId, budgetMs, registered)\n\t\t\t: context.supervisor.waitForTaskId(context.owner, id as TaskId, budgetMs, registered));\n\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\tif (!observed.ok) throw new Error(`${observed.error.code}: ${observed.error.message}`);\n\t\tlet offset: string | undefined =\n\t\t\tobserved.value.kind === \"yielded\" ? (yieldedOutputOffsets.get(task.value) ?? \"0\") : \"0\";\n\t\tlet nextOffset: string;\n\t\tdo {\n\t\t\tconst page = await context.supervisor.readTaskOutput(task.value, { start: offset, maximumBytes: 8192 });\n\t\t\tif (!page.ok) throw new Error(`${page.error.code}: ${page.error.message}`);\n\t\t\tconst segments = [\n\t\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\t\toffsets,\n\t\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t\t})),\n\t\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\t\tconst bytes = Buffer.concat(segments.map((segment) => segment.bytes));\n\t\t\tconst completeBytes = observed.value.kind === \"yielded\" ? completeUtf8PrefixLength(bytes) : bytes.length;\n\t\t\toutput.append(bytes.subarray(0, completeBytes));\n\t\t\t// Re-read an incomplete UTF-8 suffix next time, including at the current live tail.\n\t\t\tnextOffset = page.value.nextOffset ?? segments.at(-1)?.offsets.end ?? offset;\n\t\t\tnextOffset = (BigInt(nextOffset) - BigInt(bytes.length - completeBytes)).toString();\n\t\t\tif (page.value.nextOffset !== undefined && observed.value.kind === \"yielded\")\n\t\t\t\toutput.append(Buffer.from(\"\\n[Additional output not shown; wait again to retrieve retained output.]\\n\"));\n\t\t\toffset = observed.value.kind === \"yielded\" ? undefined : page.value.nextOffset;\n\t\t} while (offset !== undefined);\n\t\toutput.finish();\n\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\tawait output.closeTempFile();\n\t\tif (observed.value.kind === \"yielded\" && BigInt(nextOffset) > BigInt(yieldedOutputOffsets.get(task.value) ?? \"0\"))\n\t\t\tyieldedOutputOffsets.set(task.value, nextOffset);\n\t\tconst terminal = observed.value.kind === \"settled\" ? observed.value.result : undefined;\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\ttext: `${snapshot.content || \"(no output)\"}${snapshot.truncation.truncated ? \"\\n[Output truncated.]\" : \"\"}\\n\\n${JSON.stringify(observed.value)}${snapshot.fullOutputPath ? `\\nFull output: ${snapshot.fullOutputPath}` : \"\"}`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tdetails: {\n\t\t\t\tobservation: observed.value,\n\t\t\t\t...(terminal && \"exitCode\" in terminal ? { exitCode: terminal.exitCode } : {}),\n\t\t\t\t...(snapshot.truncation.truncated\n\t\t\t\t\t? { truncation: snapshot.truncation, fullOutputPath: snapshot.fullOutputPath }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\tawait output.closeTempFile();\n\t}\n}\n\nexport function validateBashWait(wait: WaitPolicy | undefined, ownerSupported = true): void {\n\tif (wait === undefined) return;\n\tif (\n\t\t!wait ||\n\t\ttypeof wait !== \"object\" ||\n\t\t(wait.kind !== \"background\" && wait.kind !== \"foreground\") ||\n\t\tObject.keys(wait).some((key) => key !== \"kind\" && (wait.kind !== \"foreground\" || key !== \"budgetMs\")) ||\n\t\t(wait.kind === \"foreground\" &&\n\t\t\twait.budgetMs !== undefined &&\n\t\t\t(typeof wait.budgetMs !== \"number\" || !Number.isFinite(wait.budgetMs) || wait.budgetMs < 0))\n\t)\n\t\tthrow new Error(\"Invalid bash wait: expected background or foreground with a finite non-negative budgetMs\");\n\tif (wait.kind === \"background\" && !ownerSupported)\n\t\tthrow new Error(\"Background bash observation requires a supported task owner\");\n}\n\nexport async function executeSupervisedCommand(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n\tpty: boolean,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst context = options.taskOwner;\n\tif (!context) throw new Error(\"Supervised command requires its task owner\");\n\tconst shell = options.shellConfig ?? getShellConfig(options.shellPath);\n\tif (process.platform === \"win32\" && shell.commandTransport === \"stdin\")\n\t\tthrow new Error(\"ContainmentUnavailable: run Atomic inside WSL to supervise Linux guest commands\");\n\tconst quote = (text: string) => `'${text.replaceAll(\"'\", \"'\\\\''\")}'`;\n\tconst invocation = [shell.shell, ...shell.args].map(quote).join(\" \");\n\tconst environment = createChildProcessEnvironment(\n\t\tpty ? { TERM: \"xterm-256color\" } : undefined,\n\t\toptions.env ?? getShellEnv(),\n\t);\n\t// Windows names are case-insensitive. Resolve ordered JS overrides before\n\t// crossing into the unordered native map, including explicit removals.\n\tconst launchEnvironment = new Map<string, [string, string | undefined]>();\n\tfor (const [key, value] of Object.entries(environment))\n\t\tlaunchEnvironment.set(process.platform === \"win32\" ? key.toUpperCase() : key, [key, value]);\n\t// The native command door merges env overrides. Clear omitted inherited shell\n\t// variables before invoking the configured shell, without embedding env values\n\t// (which may be secrets) into the retained command text.\n\tconst omitted = Object.keys(process.env).filter(\n\t\t(key) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && environment[key] === undefined,\n\t);\n\tconst clearInherited = omitted.length ? `unset ${omitted.map(quote).join(\" \")}; ` : \"\";\n\tconst launch =\n\t\tshell.commandTransport === \"stdin\"\n\t\t\t? `printf %s ${quote(command)} | ${invocation}`\n\t\t\t: `exec ${invocation} ${quote(command)}`;\n\tconst started = await context.supervisor.startCommandTask(\n\t\tcontext.owner,\n\t\t{\n\t\t\tkind: \"command\",\n\t\t\tcommand: process.platform === \"win32\" ? command : clearInherited + launch,\n\t\t\tdescription: options.commandDescription ?? command,\n\t\t\tcwd,\n\t\t\tenv: Object.fromEntries(\n\t\t\t\t[...launchEnvironment.values()].filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t),\n\t\t\t...(process.platform === \"win32\"\n\t\t\t\t? { shell: { program: shell.shell, args: shell.args }, inheritEnv: false }\n\t\t\t\t: {}),\n\t\t\tterminal: pty ? { kind: \"pty\", columns: options.cols ?? 120, rows: options.rows ?? 40 } : { kind: \"pipe\" },\n\t\t\t...(options.timeout === undefined ? {} : { executionTimeoutMs: options.timeout * 1000 }),\n\t\t},\n\t\tcrypto.randomUUID() as OperationId,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tconst abort = () => {\n\t\tvoid context.supervisor.cancelTask(task, \"user\");\n\t};\n\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\tif (options.signal?.aborted) abort();\n\tlet done = false;\n\tlet offset = \"0\";\n\tconst observation = context.supervisor.initialObservation(task, options.wait).finally(() => {\n\t\tdone = true;\n\t});\n\tconst drain = async () => {\n\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\tif (!page.ok) throw new Error(page.error.message);\n\t\tconst segments = [\n\t\t\t...page.value.chunks.map((chunk) => ({ offsets: chunk.offsets, bytes: Buffer.from(chunk.bytes) })),\n\t\t\t...page.value.omittedRanges.map((offsets) => ({\n\t\t\t\toffsets,\n\t\t\t\tbytes: Buffer.from(`\\n[Output omitted: bytes ${offsets.start}-${offsets.end}]\\n`),\n\t\t\t})),\n\t\t].sort((a, b) => (BigInt(a.offsets.start) < BigInt(b.offsets.start) ? -1 : 1));\n\t\tfor (const segment of segments) {\n\t\t\toptions.onData(segment.bytes);\n\t\t\toffset = segment.offsets.end;\n\t\t}\n\t\tif (page.value.nextOffset !== undefined) offset = page.value.nextOffset;\n\t\treturn page.value.nextOffset !== undefined;\n\t};\n\ttry {\n\t\twhile (!done) {\n\t\t\tif (!(await drain())) await poll(10);\n\t\t}\n\t\tconst result = await observation;\n\t\tif (!result.ok) throw new Error(result.error.message);\n\t\tif (result.value.kind === \"yielded\") {\n\t\t\tawait drain();\n\t\t\treturn { exitCode: null, observation: result.value };\n\t\t}\n\t\twhile (await drain()) {\n\t\t\t/* Terminal output is finite; no live producer extends this drain. */\n\t\t}\n\t\tconst terminal = result.value.result;\n\t\tif (terminal.kind === \"cancelled\")\n\t\t\tthrow new Error(terminal.cause === \"execution-timeout\" ? `timeout:${options.timeout}` : \"aborted\");\n\t\tif (terminal.kind === \"failed\") throw new Error(`${terminal.code}: ${terminal.message}`);\n\t\treturn { exitCode: terminal.exitCode ?? null };\n\t} finally {\n\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t}\n}\n\nexport interface NativePtyExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\twait?: WaitPolicy;\n\tenv?: NodeJS.ProcessEnv;\n\tshellPath?: string;\n\tshellConfig?: ShellConfig;\n\tcommandDescription?: string;\n\tcols?: number;\n\trows?: number;\n\ttaskOwner?: SupervisedCommandOwner;\n}\n\nexport async function executeNativePty(\n\tcommand: string,\n\tcwd: string,\n\toptions: NativePtyExecOptions,\n): Promise<SupervisedCommandResult> {\n\tvalidateBashWait(options.wait, !!options.taskOwner);\n\tif (options.taskOwner) return executeSupervisedCommand(command, cwd, options, true);\n\tconst loaded = loadNativePtyBinding();\n\tif (!loaded.ok) throw loaded.error;\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst shellConfig = options.shellConfig ?? getShellConfig(options.shellPath);\n\tconst session = new loaded.binding.PtySession();\n\tconst onAbort = () => {\n\t\ttry {\n\t\t\tsession.kill();\n\t\t} catch {}\n\t};\n\tif (options.signal) options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\tconst result = await session.start(\n\t\t\t{\n\t\t\t\tcommand,\n\t\t\t\tcwd,\n\t\t\t\tenv: Object.fromEntries(\n\t\t\t\t\tObject.entries(\n\t\t\t\t\t\tcreateChildProcessEnvironment(\n\t\t\t\t\t\t\t{ TERM: \"xterm-256color\" },\n\t\t\t\t\t\t\t{ ...getShellEnv(), ...(options.env ?? {}) },\n\t\t\t\t\t\t),\n\t\t\t\t\t).filter((entry): entry is [string, string] => entry[1] !== undefined),\n\t\t\t\t),\n\t\t\t\ttimeoutMs: options.timeout !== undefined ? Math.max(1, Math.floor(options.timeout * 1000)) : undefined,\n\t\t\t\tcols: options.cols ?? 120,\n\t\t\t\trows: options.rows ?? 40,\n\t\t\t\tshell: shellConfig.shell,\n\t\t\t\tshellArgs: shellConfig.args,\n\t\t\t\tcommandTransport: shellConfig.commandTransport,\n\t\t\t\tcloseStdinAfterCommand: shellConfig.commandTransport === \"stdin\",\n\t\t\t},\n\t\t\t(_error, chunk) => {\n\t\t\t\tif (chunk) options.onData(Buffer.from(chunk));\n\t\t\t},\n\t\t);\n\t\tif (options.signal?.aborted || result.cancelled) throw new Error(\"aborted\");\n\t\tif (result.timedOut ?? result.timed_out) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode: result.exitCode ?? result.exit_code ?? null };\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import type { WaitPolicy } from "../tasks/contracts.js";
|
|
|
6
6
|
import { type BashInterceptorRule } from "./bash-interceptor.ts";
|
|
7
7
|
import { type SupervisedCommandOwner, type SupervisedCommandResult } from "./bash-pty-native.js";
|
|
8
8
|
import { type TruncationResult } from "./truncate.ts";
|
|
9
|
-
declare const
|
|
9
|
+
declare const bashBaseSchema: Type.TObject<{
|
|
10
10
|
command: Type.TString;
|
|
11
11
|
env: Type.TOptional<Type.TUnsafe<Record<string, string>>>;
|
|
12
12
|
timeout: Type.TOptional<Type.TNumber>;
|
|
@@ -14,9 +14,20 @@ declare const bashSchema: Type.TObject<{
|
|
|
14
14
|
cwd: Type.TOptional<Type.TString>;
|
|
15
15
|
pty: Type.TOptional<Type.TBoolean>;
|
|
16
16
|
}>;
|
|
17
|
+
type ShellCommandInput = Static<typeof bashBaseSchema> & {
|
|
18
|
+
action?: never;
|
|
19
|
+
id?: never;
|
|
20
|
+
budgetMs?: never;
|
|
21
|
+
};
|
|
22
|
+
type ShellWaitInput = {
|
|
23
|
+
action: "wait";
|
|
24
|
+
id: string;
|
|
25
|
+
budgetMs?: number;
|
|
26
|
+
} & Partial<Record<keyof Static<typeof bashBaseSchema>, never>>;
|
|
27
|
+
declare const bashSchema: Type.TUnsafe<ShellCommandInput | ShellWaitInput>;
|
|
17
28
|
export declare const bashToolSystemPromptContribution: Readonly<{
|
|
18
29
|
readonly snippet: "Execute a shell command.";
|
|
19
|
-
readonly guidelines: readonly ["You can inspect ATOMIC_* or PI_* environment variables for current model and session details.", "Choose foreground or background bash observation as needed without asking the user each time. Background yields after admission; foreground waits for its optional budget then the same command continues in background. Omitted wait uses owner-configured automatic background yield (default 10s). Observation never changes the execution timeout, which stops the command. Background requires a supported task owner; unbound foreground waits until completion regardless of budget."];
|
|
30
|
+
readonly guidelines: readonly ["You can inspect ATOMIC_* or PI_* environment variables for current model and session details.", "Use { action: \"wait\", id: taskId, budgetMs: 1000 } to observe an existing shell task. Omit budgetMs for owner policy; zero polls. Never relaunch a yielded command. Waiting does not extend execution timeout or owner lifetime.", "Choose foreground or background bash observation as needed without asking the user each time. Background yields after admission; foreground waits for its optional budget then the same command continues in background. Omitted wait uses owner-configured automatic background yield (default 10s). Observation never changes the execution timeout, which stops the command. Background requires a supported task owner; unbound foreground waits until completion regardless of budget."];
|
|
20
31
|
}>;
|
|
21
32
|
export type BashToolInput = Static<typeof bashSchema>;
|
|
22
33
|
export interface BashToolDetails {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAoB,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AACxG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,KAAK,mBA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AG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AA0HF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,EACzB,YAAY,GAAE,qBAA+C,GAC3D,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAmTjF;AACD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
|
package/dist/core/tools/bash.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createChildProcessEnvironment, waitForChildProcess } from "../../utils/
|
|
|
12
12
|
import { getShellConfig, getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid, } from "../../utils/shell.js";
|
|
13
13
|
import { checkBashInterceptionCandidates, DEFAULT_BASH_INTERCEPTOR_RULES, } from "./bash-interceptor.js";
|
|
14
14
|
import { stripLeadingCdCommand } from "./bash-leading-cd.js";
|
|
15
|
-
import { executeNativePty, executeSupervisedCommand, validateBashWait, } from "./bash-pty-native.js";
|
|
15
|
+
import { executeNativePty, executeSupervisedCommand, validateBashWait, waitForSupervisedCommand, } from "./bash-pty-native.js";
|
|
16
16
|
import { applyBashSessionEnvironment, snapshotBashSessionEnvironment } from "./bash-session-environment.js";
|
|
17
17
|
import { OutputAccumulator } from "./output-accumulator.js";
|
|
18
18
|
import { getTextOutput, invalidArgText, str } from "./render-utils.js";
|
|
@@ -47,11 +47,36 @@ const bashBaseSchema = Type.Object({
|
|
|
47
47
|
cwd: Type.Optional(Type.String({ description: "Working directory for the command." })),
|
|
48
48
|
pty: Type.Optional(Type.Boolean({ description: "Run with PTY handling." })),
|
|
49
49
|
}, { additionalProperties: false });
|
|
50
|
-
const bashSchema =
|
|
50
|
+
const bashSchema = Type.Unsafe({
|
|
51
|
+
...bashBaseSchema,
|
|
52
|
+
properties: {
|
|
53
|
+
...bashBaseSchema.properties,
|
|
54
|
+
action: {
|
|
55
|
+
type: "string",
|
|
56
|
+
enum: ["wait"],
|
|
57
|
+
description: "Observe an existing asynchronous task without executing a command.",
|
|
58
|
+
},
|
|
59
|
+
id: { type: "string", description: "Existing task ID owned by this session." },
|
|
60
|
+
budgetMs: {
|
|
61
|
+
type: "number",
|
|
62
|
+
minimum: 0,
|
|
63
|
+
description: "Observation budget in milliseconds; omitted uses owner policy.",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: [],
|
|
67
|
+
anyOf: [
|
|
68
|
+
{ required: ["command"], not: { anyOf: ["action", "id", "budgetMs"].map((key) => ({ required: [key] })) } },
|
|
69
|
+
{
|
|
70
|
+
required: ["action", "id"],
|
|
71
|
+
not: { anyOf: Object.keys(bashBaseSchema.properties).map((key) => ({ required: [key] })) },
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
51
75
|
export const bashToolSystemPromptContribution = Object.freeze({
|
|
52
76
|
snippet: "Execute a shell command.",
|
|
53
77
|
guidelines: Object.freeze([
|
|
54
78
|
"You can inspect ATOMIC_* or PI_* environment variables for current model and session details.",
|
|
79
|
+
'Use { action: "wait", id: taskId, budgetMs: 1000 } to observe an existing shell task. Omit budgetMs for owner policy; zero polls. Never relaunch a yielded command. Waiting does not extend execution timeout or owner lifetime.',
|
|
55
80
|
"Choose foreground or background bash observation as needed without asking the user each time. Background yields after admission; foreground waits for its optional budget then the same command continues in background. Omitted wait uses owner-configured automatic background yield (default 10s). Observation never changes the execution timeout, which stops the command. Background requires a supported task owner; unbound foreground waits until completion regardless of budget.",
|
|
56
81
|
]),
|
|
57
82
|
});
|
|
@@ -207,6 +232,8 @@ function formatDuration(ms) {
|
|
|
207
232
|
return `${seconds}s`;
|
|
208
233
|
}
|
|
209
234
|
function formatBashCall(args, prompt) {
|
|
235
|
+
if (args?.action === "wait")
|
|
236
|
+
return theme.fg("toolTitle", theme.bold(`${prompt} wait ${str(args.id) ?? "..."}`));
|
|
210
237
|
const command = str(args?.command);
|
|
211
238
|
const timeout = args?.timeout;
|
|
212
239
|
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
@@ -302,13 +329,31 @@ export function createBashToolDefinition(cwd, options, presentation = BASH_SHELL
|
|
|
302
329
|
return {
|
|
303
330
|
name: "bash",
|
|
304
331
|
label: "bash",
|
|
305
|
-
description:
|
|
332
|
+
description: 'Execute a shell command with optional PTY handling and foreground/background observation, or observe an existing task with action: "wait", id, and optional budgetMs. Omitted command wait uses owner policy (default 10s). Observation never changes execution timeout. Background and existing-task waits require a supported task owner; unbound foreground execution waits until completion.',
|
|
306
333
|
promptSnippet: bashToolSystemPromptContribution.snippet,
|
|
307
334
|
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
308
335
|
promptGuidelines: exposeSessionEnvironment ? [...bashToolSystemPromptContribution.guidelines] : undefined,
|
|
309
336
|
parameters: bashSchema,
|
|
310
337
|
maxResultSizeChars: Infinity,
|
|
311
338
|
async execute(_toolCallId, bashCommand, signal, onUpdate, ctx) {
|
|
339
|
+
if (bashCommand.action !== undefined) {
|
|
340
|
+
if (bashCommand.action !== "wait" ||
|
|
341
|
+
typeof bashCommand.id !== "string" ||
|
|
342
|
+
Object.keys(bashCommand).some((key) => !["action", "id", "budgetMs"].includes(key)) ||
|
|
343
|
+
(bashCommand.budgetMs !== undefined &&
|
|
344
|
+
(typeof bashCommand.budgetMs !== "number" ||
|
|
345
|
+
!Number.isFinite(bashCommand.budgetMs) ||
|
|
346
|
+
bashCommand.budgetMs < 0)))
|
|
347
|
+
throw new Error("Invalid shell wait: expected action wait, id, and optional finite non-negative budgetMs");
|
|
348
|
+
return waitForSupervisedCommand(options?.taskOwner, bashCommand.id, bashCommand.budgetMs, signal, {
|
|
349
|
+
tempFilePrefix: presentation.tempFilePrefix,
|
|
350
|
+
tempDir: resolveSessionTempDir(),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
if (bashCommand.id !== undefined ||
|
|
354
|
+
bashCommand.budgetMs !== undefined ||
|
|
355
|
+
typeof bashCommand.command !== "string")
|
|
356
|
+
throw new Error("Invalid shell command: command is required; id and budgetMs require action wait");
|
|
312
357
|
const { command } = bashCommand;
|
|
313
358
|
const timeout = normalizeTimeoutSeconds(bashCommand.timeout);
|
|
314
359
|
validateBashWait(bashCommand.wait, !!options?.operations || !!options?.taskOwner);
|