@bastani/atomic 0.9.57 → 0.9.58-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +39 -5
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/index.bundle.mjs +2 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +42 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +885 -228
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +933 -175
- package/dist/builtin/workflows/src/index.js +630 -162
- package/dist/builtin/workflows/src/local-worker-entry.mjs +933 -175
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +1 -1
- package/dist/builtin/workflows/src/shared/workflow-infrastructure-error.d.ts +13 -0
- package/dist/builtin/workflows/src/workers/public-options.d.ts +10 -0
- package/dist/core/agent-session-persistent-custom-messages.d.ts +5 -0
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +16 -0
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts.map +1 -1
- package/dist/core/agent-session-tasks.js +20 -0
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +4 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +4 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager-resource-accessors.d.ts +2 -0
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-resource-accessors.js +6 -0
- package/dist/core/settings-manager-resource-accessors.js.map +1 -1
- package/dist/core/settings-schema.d.ts +9 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +11 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/settings-types.d.ts +1 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/tasks/agent-adapter.d.ts +10 -1
- package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
- package/dist/core/tasks/agent-adapter.js +20 -0
- package/dist/core/tasks/agent-adapter.js.map +1 -1
- package/dist/core/tasks/contracts.d.ts +6 -0
- package/dist/core/tasks/contracts.d.ts.map +1 -1
- package/dist/core/tasks/contracts.js.map +1 -1
- package/dist/core/tasks/heartbeat-notice.d.ts +64 -0
- package/dist/core/tasks/heartbeat-notice.d.ts.map +1 -0
- package/dist/core/tasks/heartbeat-notice.js +98 -0
- package/dist/core/tasks/heartbeat-notice.js.map +1 -0
- package/dist/core/tasks/heartbeat.d.ts +75 -0
- package/dist/core/tasks/heartbeat.d.ts.map +1 -0
- package/dist/core/tasks/heartbeat.js +440 -0
- package/dist/core/tasks/heartbeat.js.map +1 -0
- package/dist/core/tasks/supervisor.d.ts +2 -0
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +32 -4
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tasks/task-view-source.d.ts +72 -0
- package/dist/core/tasks/task-view-source.d.ts.map +1 -0
- package/dist/core/tasks/task-view-source.js +155 -0
- package/dist/core/tasks/task-view-source.js.map +1 -0
- package/dist/core/tools/bash-pty-native.d.ts +2 -0
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +1 -0
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +20 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -8
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.js +7 -0
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +3 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +4 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.d.ts +11 -0
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +2 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +15 -8
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +12 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/task-detail.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-detail.js +5 -0
- package/dist/modes/interactive/components/task-detail.js.map +1 -1
- package/dist/modes/interactive/components/task-heartbeat-message.d.ts +14 -0
- package/dist/modes/interactive/components/task-heartbeat-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-heartbeat-message.js +76 -0
- package/dist/modes/interactive/components/task-heartbeat-message.js.map +1 -0
- package/dist/modes/interactive/components/task-inspector.d.ts +6 -3
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +53 -100
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/skill-command-autocomplete.d.ts +22 -2
- package/dist/modes/interactive/skill-command-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/skill-command-autocomplete.js +28 -9
- package/dist/modes/interactive/skill-command-autocomplete.js.map +1 -1
- package/docs/background-tasks.md +65 -1
- package/docs/settings.md +12 -0
- package/docs/subagents.md +2 -0
- package/docs/tools.md +2 -1
- package/docs/workflows/operations.md +5 -3
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/schemas/settings.schema.json +24 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { taskOutputText } from "./command-output.js";
|
|
3
|
+
import { taskExtensionStatuses, taskOwnTranscriptEntries, taskTranscriptSource, watchTaskExtensionStatuses, } from "./supervisor.js";
|
|
4
|
+
import { readTaskTranscriptSnapshot } from "./transcript.js";
|
|
5
|
+
const NO_STATUSES = new Map();
|
|
6
|
+
const sources = new WeakMap();
|
|
7
|
+
function messageText(message) {
|
|
8
|
+
if (message.role !== "user" && message.role !== "assistant")
|
|
9
|
+
return undefined;
|
|
10
|
+
const content = message.content;
|
|
11
|
+
if (typeof content === "string")
|
|
12
|
+
return content;
|
|
13
|
+
return content
|
|
14
|
+
.filter((block) => block.type === "text")
|
|
15
|
+
.map((block) => block.text)
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
/** The task view of a session's own task store; one per store. */
|
|
19
|
+
export function ownerTaskViewSource(store) {
|
|
20
|
+
const existing = sources.get(store);
|
|
21
|
+
if (existing !== undefined)
|
|
22
|
+
return existing;
|
|
23
|
+
const lease = (id) => store.resolveTask(id);
|
|
24
|
+
const source = {
|
|
25
|
+
get tasks() {
|
|
26
|
+
return store.tasks;
|
|
27
|
+
},
|
|
28
|
+
get backgroundTasks() {
|
|
29
|
+
return store.backgroundTasks;
|
|
30
|
+
},
|
|
31
|
+
get settlementOrder() {
|
|
32
|
+
return store.settlementOrder;
|
|
33
|
+
},
|
|
34
|
+
recentActivity: (id) => store.recentActivity(id),
|
|
35
|
+
activityOmitted: (id) => store.activityOmitted(id),
|
|
36
|
+
subscribe: (listener) => store.subscribe(listener),
|
|
37
|
+
async foregroundTask(id) {
|
|
38
|
+
const task = lease(id);
|
|
39
|
+
if (!task.ok)
|
|
40
|
+
return { ok: false, error: { message: task.error.message } };
|
|
41
|
+
const result = await store.supervisor.foregroundTask(task.value);
|
|
42
|
+
return result.ok
|
|
43
|
+
? { ok: true, value: { kind: result.value.kind } }
|
|
44
|
+
: { ok: false, error: { message: result.error.message } };
|
|
45
|
+
},
|
|
46
|
+
async cancelTask(id) {
|
|
47
|
+
const task = lease(id);
|
|
48
|
+
if (!task.ok)
|
|
49
|
+
return { ok: false, error: { message: task.error.message } };
|
|
50
|
+
const result = await store.supervisor.cancelTask(task.value, "user");
|
|
51
|
+
return result.ok ? { ok: true, value: undefined } : { ok: false, error: { message: result.error.message } };
|
|
52
|
+
},
|
|
53
|
+
stdinAvailable(id) {
|
|
54
|
+
const task = lease(id);
|
|
55
|
+
return task.ok && store.supervisor.taskStdin(task.value).ok;
|
|
56
|
+
},
|
|
57
|
+
async writeTaskInput(id, text) {
|
|
58
|
+
const task = lease(id);
|
|
59
|
+
if (!task.ok)
|
|
60
|
+
return { ok: false, error: { message: task.error.message } };
|
|
61
|
+
const stdin = store.supervisor.taskStdin(task.value);
|
|
62
|
+
if (!stdin.ok)
|
|
63
|
+
return { ok: false, error: { message: stdin.error.message } };
|
|
64
|
+
const result = await store.supervisor.writeTaskInput(stdin.value, randomUUID(), {
|
|
65
|
+
kind: "bytes",
|
|
66
|
+
bytes: Buffer.from(`${text}\n`),
|
|
67
|
+
});
|
|
68
|
+
return result.ok
|
|
69
|
+
? { ok: true, value: { acceptedBytes: result.value.acceptedBytes } }
|
|
70
|
+
: { ok: false, error: { message: result.error.message } };
|
|
71
|
+
},
|
|
72
|
+
async readTaskOutput(id, range) {
|
|
73
|
+
const task = lease(id);
|
|
74
|
+
if (!task.ok)
|
|
75
|
+
return { ok: false, error: { message: task.error.message } };
|
|
76
|
+
const page = await store.supervisor.readTaskOutput(task.value, {
|
|
77
|
+
start: range.start,
|
|
78
|
+
maximumBytes: range.maximumBytes,
|
|
79
|
+
});
|
|
80
|
+
return page.ok
|
|
81
|
+
? { ok: true, value: { text: taskOutputText(page.value), omitted: page.value.omittedRanges.length > 0 } }
|
|
82
|
+
: { ok: false, error: { message: page.error.message } };
|
|
83
|
+
},
|
|
84
|
+
taskDetailText(id) {
|
|
85
|
+
const task = lease(id);
|
|
86
|
+
if (!task.ok)
|
|
87
|
+
return {};
|
|
88
|
+
const entries = taskOwnTranscriptEntries(task.value);
|
|
89
|
+
if (entries === undefined)
|
|
90
|
+
return {};
|
|
91
|
+
const messages = entries.flatMap((entry) => (entry.type === "message" ? [entry.message] : []));
|
|
92
|
+
const prompt = messages.find((message) => message.role === "user");
|
|
93
|
+
const response = messages
|
|
94
|
+
.slice()
|
|
95
|
+
.reverse()
|
|
96
|
+
.find((message) => message.role === "assistant");
|
|
97
|
+
const promptText = prompt === undefined ? undefined : messageText(prompt);
|
|
98
|
+
const outputText = response === undefined ? undefined : messageText(response);
|
|
99
|
+
return {
|
|
100
|
+
...(promptText === undefined ? {} : { prompt: promptText }),
|
|
101
|
+
...(outputText === undefined ? {} : { output: outputText }),
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
readTaskTranscript(id, cursor) {
|
|
105
|
+
const task = lease(id);
|
|
106
|
+
if (!task.ok)
|
|
107
|
+
return { ok: false, error: { message: task.error.message } };
|
|
108
|
+
const page = readTaskTranscriptSnapshot(task.value, cursor);
|
|
109
|
+
const bound = taskTranscriptSource(task.value);
|
|
110
|
+
if (!bound.ok || (!page.ok && !bound.value.session.subscribe))
|
|
111
|
+
return { ok: false, error: { message: "Transcript unavailable" } };
|
|
112
|
+
const ids = new Set(page.ok ? page.value.items.map((item) => item.source.entryId) : []);
|
|
113
|
+
const messages = bound.value.session.getEntries().flatMap((entry) => {
|
|
114
|
+
if (entry.type !== "message" || !ids.has(entry.id))
|
|
115
|
+
return [];
|
|
116
|
+
const message = entry.message;
|
|
117
|
+
if (message.role === "assistant")
|
|
118
|
+
return [
|
|
119
|
+
{
|
|
120
|
+
...message,
|
|
121
|
+
content: message.content.filter((block, index) => block.type !== "thinking" &&
|
|
122
|
+
page.ok &&
|
|
123
|
+
page.value.items.some((item) => item.source.entryId === entry.id && item.source.contentIndex === index)),
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
return message.role === "user" || message.role === "toolResult" ? [message] : [];
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
ok: true,
|
|
130
|
+
value: {
|
|
131
|
+
messages,
|
|
132
|
+
...(page.ok && page.value.nextCursor !== undefined ? { nextCursor: page.value.nextCursor } : {}),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
followTaskTranscript(id) {
|
|
137
|
+
const task = lease(id);
|
|
138
|
+
const bound = task.ok ? taskTranscriptSource(task.value) : undefined;
|
|
139
|
+
if (!bound?.ok)
|
|
140
|
+
return undefined;
|
|
141
|
+
return { session: bound.value.session, historyOnly: bound.value.session.subscribe === undefined };
|
|
142
|
+
},
|
|
143
|
+
extensionStatuses(id) {
|
|
144
|
+
const task = lease(id);
|
|
145
|
+
return task.ok ? taskExtensionStatuses(task.value) : NO_STATUSES;
|
|
146
|
+
},
|
|
147
|
+
watchExtensionStatuses(id, listener) {
|
|
148
|
+
const task = lease(id);
|
|
149
|
+
return task.ok ? watchTaskExtensionStatuses(task.value, listener) : () => { };
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
sources.set(store, source);
|
|
153
|
+
return source;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=task-view-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-view-source.js","sourceRoot":"","sources":["../../../src/core/tasks/task-view-source.ts"],"names":[],"mapp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MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QAClE,CAAC;QACD,sBAAsB,CAAC,EAAE,EAAE,QAAQ;YAClC,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;QAC9E,CAAC;KACD,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { taskOutputText } from \"./command-output.js\";\nimport type { OperationId, TaskId, TaskRecord } from \"./contracts.js\";\nimport type { OwnerTaskStore, TaskActivity } from \"./owner-store.js\";\nimport {\n\ttype TaskTranscriptSource,\n\ttaskExtensionStatuses,\n\ttaskOwnTranscriptEntries,\n\ttaskTranscriptSource,\n\twatchTaskExtensionStatuses,\n} from \"./supervisor.js\";\nimport { readTaskTranscriptSnapshot } from \"./transcript.js\";\n\nexport type TaskViewResult<T> =\n\t| { readonly ok: true; readonly value: T }\n\t| { readonly ok: false; readonly error: { readonly message: string } };\n\n/** A retained slice of a shell task's output, as text. */\nexport interface TaskOutputView {\n\treadonly text: string;\n\t/** Some of the requested bytes are no longer retained. */\n\treadonly omitted: boolean;\n}\n\n/** One page of an agent task's transcript, oldest first. */\nexport interface TaskTranscriptView {\n\treadonly messages: readonly AgentMessage[];\n\t/** Cursor of the page before this one, when earlier messages are retained. */\n\treadonly nextCursor?: string;\n}\n\n/** How an open transcript of a task follows it: through its live session, or by reading it again. */\nexport interface TaskTranscriptFollow {\n\t/** The task's session in this process, when it publishes live updates. */\n\treadonly session?: TaskTranscriptSource;\n\t/** The transcript has no live tail; a view reads it again when the task changes. */\n\treadonly historyOnly: boolean;\n}\n\n/** The prompt and latest reply of an agent task, for its detail page. */\nexport interface TaskDetailText {\n\treadonly prompt?: string;\n\treadonly output?: string;\n}\n\n/**\n * What the task inspector and a chat's task footer read and do: a session's own task store, or\n * the tasks of a session that runs in another process (a workflow stage on a local worker). It\n * names tasks by id, so a view never holds a task lease.\n */\nexport interface TaskViewSource {\n\treadonly tasks: readonly TaskRecord[];\n\treadonly backgroundTasks: readonly TaskRecord[];\n\treadonly settlementOrder: ReadonlyMap<TaskId, bigint>;\n\trecentActivity(id: TaskId): TaskActivity[];\n\tactivityOmitted(id: TaskId): boolean;\n\tsubscribe(listener: () => void): () => void;\n\tforegroundTask(id: TaskId): Promise<TaskViewResult<{ readonly kind: string }>>;\n\t/** Asks the task to stop; a failed request says why. */\n\tcancelTask(id: TaskId): Promise<TaskViewResult<undefined>>;\n\tstdinAvailable(id: TaskId): boolean;\n\twriteTaskInput(id: TaskId, text: string): Promise<TaskViewResult<{ readonly acceptedBytes: number }>>;\n\treadTaskOutput(\n\t\tid: TaskId,\n\t\trange: { readonly start: string; readonly maximumBytes: number },\n\t): Promise<TaskViewResult<TaskOutputView>>;\n\t/** Synchronous where the task's session is in this process, so a view reads it in the same turn. */\n\ttaskDetailText(id: TaskId): TaskDetailText | Promise<TaskDetailText>;\n\treadTaskTranscript(\n\t\tid: TaskId,\n\t\tcursor?: string,\n\t): TaskViewResult<TaskTranscriptView> | Promise<TaskViewResult<TaskTranscriptView>>;\n\tfollowTaskTranscript(id: TaskId): TaskTranscriptFollow | undefined;\n\textensionStatuses(id: TaskId): ReadonlyMap<string, string>;\n\twatchExtensionStatuses(id: TaskId, listener: () => void): () => void;\n}\n\nconst NO_STATUSES: ReadonlyMap<string, string> = new Map();\nconst sources = new WeakMap<OwnerTaskStore, TaskViewSource>();\n\nfunction messageText(message: AgentMessage): string | undefined {\n\tif (message.role !== \"user\" && message.role !== \"assistant\") return undefined;\n\tconst content = message.content;\n\tif (typeof content === \"string\") return content;\n\treturn content\n\t\t.filter((block): block is Extract<typeof block, { type: \"text\" }> => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\");\n}\n\n/** The task view of a session's own task store; one per store. */\nexport function ownerTaskViewSource(store: OwnerTaskStore): TaskViewSource {\n\tconst existing = sources.get(store);\n\tif (existing !== undefined) return existing;\n\tconst lease = (id: TaskId) => store.resolveTask(id);\n\tconst source: TaskViewSource = {\n\t\tget tasks() {\n\t\t\treturn store.tasks;\n\t\t},\n\t\tget backgroundTasks() {\n\t\t\treturn store.backgroundTasks;\n\t\t},\n\t\tget settlementOrder() {\n\t\t\treturn store.settlementOrder;\n\t\t},\n\t\trecentActivity: (id) => store.recentActivity(id),\n\t\tactivityOmitted: (id) => store.activityOmitted(id),\n\t\tsubscribe: (listener) => store.subscribe(listener),\n\t\tasync foregroundTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.foregroundTask(task.value);\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { kind: result.value.kind } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync cancelTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.cancelTask(task.value, \"user\");\n\t\t\treturn result.ok ? { ok: true, value: undefined } : { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tstdinAvailable(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok && store.supervisor.taskStdin(task.value).ok;\n\t\t},\n\t\tasync writeTaskInput(id, text) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst stdin = store.supervisor.taskStdin(task.value);\n\t\t\tif (!stdin.ok) return { ok: false, error: { message: stdin.error.message } };\n\t\t\tconst result = await store.supervisor.writeTaskInput(stdin.value, randomUUID() as OperationId, {\n\t\t\t\tkind: \"bytes\",\n\t\t\t\tbytes: Buffer.from(`${text}\\n`),\n\t\t\t});\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { acceptedBytes: result.value.acceptedBytes } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync readTaskOutput(id, range) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = await store.supervisor.readTaskOutput(task.value, {\n\t\t\t\tstart: range.start,\n\t\t\t\tmaximumBytes: range.maximumBytes,\n\t\t\t});\n\t\t\treturn page.ok\n\t\t\t\t? { ok: true, value: { text: taskOutputText(page.value), omitted: page.value.omittedRanges.length > 0 } }\n\t\t\t\t: { ok: false, error: { message: page.error.message } };\n\t\t},\n\t\ttaskDetailText(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return {};\n\t\t\tconst entries = taskOwnTranscriptEntries(task.value);\n\t\t\tif (entries === undefined) return {};\n\t\t\tconst messages = entries.flatMap((entry) => (entry.type === \"message\" ? [entry.message] : []));\n\t\t\tconst prompt = messages.find((message) => message.role === \"user\");\n\t\t\tconst response = messages\n\t\t\t\t.slice()\n\t\t\t\t.reverse()\n\t\t\t\t.find((message) => message.role === \"assistant\");\n\t\t\tconst promptText = prompt === undefined ? undefined : messageText(prompt);\n\t\t\tconst outputText = response === undefined ? undefined : messageText(response);\n\t\t\treturn {\n\t\t\t\t...(promptText === undefined ? {} : { prompt: promptText }),\n\t\t\t\t...(outputText === undefined ? {} : { output: outputText }),\n\t\t\t};\n\t\t},\n\t\treadTaskTranscript(id, cursor) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = readTaskTranscriptSnapshot(task.value, cursor);\n\t\t\tconst bound = taskTranscriptSource(task.value);\n\t\t\tif (!bound.ok || (!page.ok && !bound.value.session.subscribe))\n\t\t\t\treturn { ok: false, error: { message: \"Transcript unavailable\" } };\n\t\t\tconst ids = new Set(page.ok ? page.value.items.map((item) => item.source.entryId) : []);\n\t\t\tconst messages = bound.value.session.getEntries().flatMap<AgentMessage>((entry) => {\n\t\t\t\tif (entry.type !== \"message\" || !ids.has(entry.id)) return [];\n\t\t\t\tconst message = entry.message;\n\t\t\t\tif (message.role === \"assistant\")\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...message,\n\t\t\t\t\t\t\tcontent: message.content.filter(\n\t\t\t\t\t\t\t\t(block, index) =>\n\t\t\t\t\t\t\t\t\tblock.type !== \"thinking\" &&\n\t\t\t\t\t\t\t\t\tpage.ok &&\n\t\t\t\t\t\t\t\t\tpage.value.items.some(\n\t\t\t\t\t\t\t\t\t\t(item) => item.source.entryId === entry.id && item.source.contentIndex === index,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\treturn message.role === \"user\" || message.role === \"toolResult\" ? [message] : [];\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tvalue: {\n\t\t\t\t\tmessages,\n\t\t\t\t\t...(page.ok && page.value.nextCursor !== undefined ? { nextCursor: page.value.nextCursor } : {}),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tfollowTaskTranscript(id) {\n\t\t\tconst task = lease(id);\n\t\t\tconst bound = task.ok ? taskTranscriptSource(task.value) : undefined;\n\t\t\tif (!bound?.ok) return undefined;\n\t\t\treturn { session: bound.value.session, historyOnly: bound.value.session.subscribe === undefined };\n\t\t},\n\t\textensionStatuses(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? taskExtensionStatuses(task.value) : NO_STATUSES;\n\t\t},\n\t\twatchExtensionStatuses(id, listener) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? watchTaskExtensionStatuses(task.value, listener) : () => {};\n\t\t},\n\t};\n\tsources.set(store, source);\n\treturn source;\n}\n"]}
|
|
@@ -42,6 +42,8 @@ export interface NativePtyExecOptions {
|
|
|
42
42
|
cols?: number;
|
|
43
43
|
rows?: number;
|
|
44
44
|
taskOwner?: SupervisedCommandOwner;
|
|
45
|
+
/** Task heartbeat cadence; `0` disables. Omitted uses the owner default. */
|
|
46
|
+
heartbeatMs?: number;
|
|
45
47
|
}
|
|
46
48
|
export declare function executeNativePty(command: string, cwd: string, options: NativePtyExecOptions): Promise<SupervisedCommandResult>;
|
|
47
49
|
//# sourceMappingURL=bash-pty-native.d.ts.map
|
|
@@ -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,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AA2C3F,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAuBD,MAAM,WAAW,sBAAsB;IACtC,UAAU,EAAE,cAAc,CAAC;IAC3B,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,KACpC,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;IACjD,gEAAgE;IAChE,QAAQ,CAAC,EAAE,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AAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,uBAAuB,CAAC,CA6ClC"}
|
|
@@ -172,6 +172,7 @@ export async function executeSupervisedCommand(command, cwd, options, pty) {
|
|
|
172
172
|
: {}),
|
|
173
173
|
terminal: pty ? { kind: "pty", columns: options.cols ?? 120, rows: options.rows ?? 40 } : { kind: "pipe" },
|
|
174
174
|
...(options.timeout === undefined ? {} : { executionTimeoutMs: options.timeout * 1000 }),
|
|
175
|
+
...(options.heartbeatMs === undefined ? {} : { heartbeatMs: options.heartbeatMs }),
|
|
175
176
|
}, crypto.randomUUID(), options.signal);
|
|
176
177
|
if (!started.ok)
|
|
177
178
|
throw new Error(`${started.error.code}: ${started.error.message}`);
|
|
@@ -1 +1 @@
|
|
|
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,sB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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\";\nimport { EMPTY_OUTPUT_TEXT, TaskToolError, waitResultTail } from \"./shell-task-status.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\t/** Narrow a shared owner to the tasks this binding launched. */\n\townsTask?: (taskId: TaskId) => boolean;\n\tonCommandStarted?: (taskId: TaskId) => void;\n}\n\nexport function lookupOwnedTask(context: SupervisedCommandOwner, id: string): TaskLease {\n\tconst taskId = id as TaskId;\n\tconst task = context.supervisor.lookupTask(context.owner, taskId);\n\tif (!task.ok) throw new TaskToolError(task.error, id);\n\tif (context.ownsTask && !context.ownsTask(taskId))\n\t\tthrow new TaskToolError({ code: \"UnknownTask\", message: \"task was not launched here\" }, id);\n\treturn task.value;\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 = lookupOwnedTask(context, id);\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 TaskToolError(observed.error, id);\n\t\tlet offset: string | undefined =\n\t\t\tobserved.value.kind === \"yielded\" ? (yieldedOutputOffsets.get(task) ?? \"0\") : \"0\";\n\t\tlet nextOffset: string;\n\t\tdo {\n\t\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\t\tif (!page.ok) throw new TaskToolError(page.error, id);\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) ?? \"0\"))\n\t\t\tyieldedOutputOffsets.set(task, 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 || EMPTY_OUTPUT_TEXT}${waitResultTail({\n\t\t\t\t\t\tobservation: observed.value,\n\t\t\t\t\t\ttruncated: snapshot.truncation.truncated,\n\t\t\t\t\t\tfullOutputPath: snapshot.truncation.truncated ? snapshot.fullOutputPath : undefined,\n\t\t\t\t\t})}`,\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\toptions.signal,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tcontext.onCommandStarted?.(context.supervisor.taskReference(task).taskId);\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;AACtE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE1F,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAqCjD,I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AAM,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\";\nimport { EMPTY_OUTPUT_TEXT, TaskToolError, waitResultTail } from \"./shell-task-status.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\t/** Narrow a shared owner to the tasks this binding launched. */\n\townsTask?: (taskId: TaskId) => boolean;\n\tonCommandStarted?: (taskId: TaskId) => void;\n}\n\nexport function lookupOwnedTask(context: SupervisedCommandOwner, id: string): TaskLease {\n\tconst taskId = id as TaskId;\n\tconst task = context.supervisor.lookupTask(context.owner, taskId);\n\tif (!task.ok) throw new TaskToolError(task.error, id);\n\tif (context.ownsTask && !context.ownsTask(taskId))\n\t\tthrow new TaskToolError({ code: \"UnknownTask\", message: \"task was not launched here\" }, id);\n\treturn task.value;\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 = lookupOwnedTask(context, id);\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 TaskToolError(observed.error, id);\n\t\tlet offset: string | undefined =\n\t\t\tobserved.value.kind === \"yielded\" ? (yieldedOutputOffsets.get(task) ?? \"0\") : \"0\";\n\t\tlet nextOffset: string;\n\t\tdo {\n\t\t\tconst page = await context.supervisor.readTaskOutput(task, { start: offset, maximumBytes: 8192 });\n\t\t\tif (!page.ok) throw new TaskToolError(page.error, id);\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) ?? \"0\"))\n\t\t\tyieldedOutputOffsets.set(task, 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 || EMPTY_OUTPUT_TEXT}${waitResultTail({\n\t\t\t\t\t\tobservation: observed.value,\n\t\t\t\t\t\ttruncated: snapshot.truncation.truncated,\n\t\t\t\t\t\tfullOutputPath: snapshot.truncation.truncated ? snapshot.fullOutputPath : undefined,\n\t\t\t\t\t})}`,\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\t...(options.heartbeatMs === undefined ? {} : { heartbeatMs: options.heartbeatMs }),\n\t\t},\n\t\tcrypto.randomUUID() as OperationId,\n\t\toptions.signal,\n\t);\n\tif (!started.ok) throw new Error(`${started.error.code}: ${started.error.message}`);\n\tconst task = started.value;\n\tcontext.onCommandStarted?.(context.supervisor.taskReference(task).taskId);\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\t/** Task heartbeat cadence; `0` disables. Omitted uses the owner default. */\n\theartbeatMs?: number;\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"]}
|
|
@@ -14,6 +14,7 @@ declare const bashBaseSchema: Type.TObject<{
|
|
|
14
14
|
wait: Type.TOptional<Type.TUnsafe<WaitPolicy>>;
|
|
15
15
|
cwd: Type.TOptional<Type.TString>;
|
|
16
16
|
pty: Type.TOptional<Type.TBoolean>;
|
|
17
|
+
heartbeatMs: Type.TOptional<Type.TNumber>;
|
|
17
18
|
}>;
|
|
18
19
|
type ShellCommandInput = Static<typeof bashBaseSchema> & {
|
|
19
20
|
action?: never;
|
|
@@ -50,6 +51,8 @@ export interface BashOperations {
|
|
|
50
51
|
wait?: WaitPolicy;
|
|
51
52
|
env?: NodeJS.ProcessEnv;
|
|
52
53
|
pty?: boolean;
|
|
54
|
+
/** Task heartbeat cadence for a supervised command; `0` disables. Omitted uses the owner default. */
|
|
55
|
+
heartbeatMs?: number;
|
|
53
56
|
}) => Promise<SupervisedCommandResult>;
|
|
54
57
|
}
|
|
55
58
|
export declare function createLocalBashOperations(options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAW5C,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;
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAW5C,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;AAExD,OAAO,EACN,KAAK,mBAAmB,EAGxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAGN,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAG5B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAMN,KAAK,cAAc,EAEnB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAiC,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAmBrF,QAAA,MAAM,cAAc;;;;;;;;EAgCnB,CAAC;AACF,KAAK,iBAAiB,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IA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AE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACzC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC;CACrD;AACD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;CACvB;AACD,eAAO,MAAM,uBAAuB,EAAE,qBAGrC,CAAC;AA4EF,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,cAAc,CAAC,CA6ThF;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
|
@@ -9,6 +9,7 @@ import { APP_NAME } from "../../config.js";
|
|
|
9
9
|
import { theme } from "../../modes/interactive/theme/theme.js";
|
|
10
10
|
import { createChildProcessEnvironment, waitForChildProcess } from "../../utils/child-process.js";
|
|
11
11
|
import { getShellConfig, getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid, } from "../../utils/shell.js";
|
|
12
|
+
import { validateTaskHeartbeatMs } from "../tasks/heartbeat-notice.js";
|
|
12
13
|
import { checkBashInterceptionCandidates, DEFAULT_BASH_INTERCEPTOR_RULES, } from "./bash-interceptor.js";
|
|
13
14
|
import { stripLeadingCdCommand } from "./bash-leading-cd.js";
|
|
14
15
|
import { executeNativePty, executeSupervisedCommand, validateBashWait, waitForSupervisedCommand, } from "./bash-pty-native.js";
|
|
@@ -56,6 +57,10 @@ const bashBaseSchema = Type.Object({
|
|
|
56
57
|
})),
|
|
57
58
|
cwd: Type.Optional(Type.String({ description: "Working directory for the command." })),
|
|
58
59
|
pty: Type.Optional(Type.Boolean({ description: "Run with PTY handling." })),
|
|
60
|
+
heartbeatMs: Type.Optional(Type.Number({
|
|
61
|
+
minimum: 0,
|
|
62
|
+
description: "Heartbeat cadence in ms while this runs as a task (default 15 min; 0 disables; min 60000).",
|
|
63
|
+
})),
|
|
59
64
|
}, { additionalProperties: false });
|
|
60
65
|
const bashSchema = Type.Unsafe({
|
|
61
66
|
...bashBaseSchema,
|
|
@@ -111,7 +116,7 @@ function normalizeTimeoutSeconds(timeout) {
|
|
|
111
116
|
}
|
|
112
117
|
export function createLocalBashOperations(options) {
|
|
113
118
|
return {
|
|
114
|
-
exec: async (command, cwd, { onData, signal, timeout, wait, env, pty }) => {
|
|
119
|
+
exec: async (command, cwd, { onData, signal, timeout, wait, env, pty, heartbeatMs }) => {
|
|
115
120
|
validateBashWait(wait, !!options?.taskOwner);
|
|
116
121
|
if (timeout !== undefined)
|
|
117
122
|
validateExplicitTimeoutSeconds(timeout);
|
|
@@ -123,6 +128,7 @@ export function createLocalBashOperations(options) {
|
|
|
123
128
|
timeout,
|
|
124
129
|
wait,
|
|
125
130
|
env,
|
|
131
|
+
heartbeatMs,
|
|
126
132
|
shellPath: options?.shellPath,
|
|
127
133
|
taskOwner: options?.taskOwner,
|
|
128
134
|
});
|
|
@@ -150,7 +156,16 @@ export function createLocalBashOperations(options) {
|
|
|
150
156
|
if (signal?.aborted)
|
|
151
157
|
throw new Error("aborted");
|
|
152
158
|
if (options?.taskOwner)
|
|
153
|
-
return executeSupervisedCommand(command, cwd, {
|
|
159
|
+
return executeSupervisedCommand(command, cwd, {
|
|
160
|
+
onData,
|
|
161
|
+
signal,
|
|
162
|
+
timeout,
|
|
163
|
+
wait,
|
|
164
|
+
env,
|
|
165
|
+
heartbeatMs,
|
|
166
|
+
shellPath: options.shellPath,
|
|
167
|
+
taskOwner: options.taskOwner,
|
|
168
|
+
}, false);
|
|
154
169
|
const commandFromStdin = shellConfig.commandTransport === "stdin";
|
|
155
170
|
const child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {
|
|
156
171
|
cwd,
|
|
@@ -322,6 +337,8 @@ export function createBashToolDefinition(cwd, options, presentation = BASH_SHELL
|
|
|
322
337
|
const { command } = bashCommand;
|
|
323
338
|
const timeout = normalizeTimeoutSeconds(bashCommand.timeout);
|
|
324
339
|
validateBashWait(bashCommand.wait, !!options?.operations || !!options?.taskOwner);
|
|
340
|
+
if (bashCommand.heartbeatMs !== undefined)
|
|
341
|
+
validateTaskHeartbeatMs(bashCommand.heartbeatMs);
|
|
325
342
|
const sessionEnvironment = snapshotBashSessionEnvironment(ctx, exposeSessionEnvironment);
|
|
326
343
|
const resourceCtx = ctx;
|
|
327
344
|
const executionCwd = ctx?.cwd || cwd;
|
|
@@ -491,6 +508,7 @@ export function createBashToolDefinition(cwd, options, presentation = BASH_SHELL
|
|
|
491
508
|
wait: bashCommand.wait,
|
|
492
509
|
env: executionContext.env,
|
|
493
510
|
pty: bashCommand.pty,
|
|
511
|
+
...(bashCommand.heartbeatMs === undefined ? {} : { heartbeatMs: bashCommand.heartbeatMs }),
|
|
494
512
|
});
|
|
495
513
|
exitCode = result.exitCode;
|
|
496
514
|
observation = result.observation;
|