@markusylisiurunen/tau 0.3.46 → 0.3.47
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/README.md +55 -5
- package/dist/code_mode/command.d.ts +2 -0
- package/dist/code_mode/command.js +31 -0
- package/dist/code_mode/command.js.map +1 -0
- package/dist/code_mode/index.d.ts +4 -0
- package/dist/code_mode/index.js +4 -0
- package/dist/code_mode/index.js.map +1 -0
- package/dist/code_mode/runtime.d.ts +82 -0
- package/dist/code_mode/runtime.js +298 -0
- package/dist/code_mode/runtime.js.map +1 -0
- package/dist/core/static/code_mode/history/documentation.md +1 -12
- package/dist/core/static/code_mode/history/sandbox_runner.mjs +1 -111
- package/dist/core/static/code_mode/nook/documentation.md +1 -14
- package/dist/core/static/code_mode/nook/sandbox_runner.mjs +1 -147
- package/dist/core/static/code_mode/sandbox_runner.mjs +186 -0
- package/dist/core/static/code_mode/web/documentation.md +1 -13
- package/dist/core/static/code_mode/web/sandbox_runner.mjs +1 -115
- package/dist/core/tools/bash.js +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/code_mode.js +41 -47
- package/dist/core/tools/code_mode.js.map +1 -1
- package/dist/core/tools/code_mode_worker.js +43 -12
- package/dist/core/tools/code_mode_worker.js.map +1 -1
- package/dist/core/tools/history.js +16 -26
- package/dist/core/tools/history.js.map +1 -1
- package/dist/core/tools/nook.js +33 -21
- package/dist/core/tools/nook.js.map +1 -1
- package/dist/core/tools/web.js +15 -20
- package/dist/core/tools/web.js.map +1 -1
- package/dist/core/utils/spawn_capture.js +19 -5
- package/dist/core/utils/spawn_capture.js.map +1 -1
- package/dist/core/version.js +1 -1
- package/dist/sdk/client_tool_command.d.ts +63 -0
- package/dist/sdk/client_tool_command.js +282 -0
- package/dist/sdk/client_tool_command.js.map +1 -0
- package/dist/sdk/code_mode.d.ts +6 -0
- package/dist/sdk/code_mode.js +58 -0
- package/dist/sdk/code_mode.js.map +1 -0
- package/dist/sdk/index.d.ts +5 -1
- package/dist/sdk/index.js +3 -0
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/session.js +51 -39
- package/dist/sdk/session.js.map +1 -1
- package/dist/sdk/types.d.ts +14 -9
- package/dist/tui/chat_controller/diff_review_service.js +2 -2
- package/dist/tui/chat_controller/diff_review_service.js.map +1 -1
- package/dist/tui/command_client_tools.js +211 -21
- package/dist/tui/command_client_tools.js.map +1 -1
- package/dist/tui/session_chat_app.js +1 -1
- package/dist/tui/session_chat_app.js.map +1 -1
- package/dist/tui/session_chat_controller.js +9 -5
- package/dist/tui/session_chat_controller.js.map +1 -1
- package/dist/tui/session_tool_execution_backend.js +2 -2
- package/dist/tui/session_tool_execution_backend.js.map +1 -1
- package/package.json +6 -2
|
@@ -1,111 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { codeModeMath, createCodeModeDate } from "../capabilities.mjs";
|
|
3
|
-
|
|
4
|
-
if (!parentPort) throw new Error("history sandbox requires a parent port");
|
|
5
|
-
if (
|
|
6
|
-
typeof workerData !== "object" ||
|
|
7
|
-
workerData === null ||
|
|
8
|
-
typeof workerData.code !== "string" ||
|
|
9
|
-
typeof workerData.docs !== "string"
|
|
10
|
-
) {
|
|
11
|
-
throw new Error("history sandbox received invalid worker data");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
lockdown();
|
|
15
|
-
|
|
16
|
-
const codeModeDate = createCodeModeDate();
|
|
17
|
-
const pending = new Map();
|
|
18
|
-
let nextRequestId = 1;
|
|
19
|
-
|
|
20
|
-
parentPort.on("message", (message) => {
|
|
21
|
-
if (message?.type !== "response" || typeof message.id !== "number") return;
|
|
22
|
-
const request = pending.get(message.id);
|
|
23
|
-
if (!request) return;
|
|
24
|
-
pending.delete(message.id);
|
|
25
|
-
if (message.ok) {
|
|
26
|
-
request.resolve(message.value);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const error = new Error(message.error?.message || "History request failed");
|
|
30
|
-
if (message.error?.name) error.name = message.error.name;
|
|
31
|
-
request.reject(error);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
function requestHistory(method, argsJson) {
|
|
35
|
-
if (typeof method !== "string" || typeof argsJson !== "string") {
|
|
36
|
-
return Promise.reject(new Error("invalid history bridge request"));
|
|
37
|
-
}
|
|
38
|
-
const id = nextRequestId++;
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
pending.set(id, { resolve, reject });
|
|
41
|
-
parentPort.postMessage({ type: "request", id, method, argsJson });
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function writeOutput(stream, text) {
|
|
46
|
-
if ((stream !== "stdout" && stream !== "stderr") || typeof text !== "string") {
|
|
47
|
-
throw new Error("invalid console bridge output");
|
|
48
|
-
}
|
|
49
|
-
const output = stream === "stderr" ? process.stderr : process.stdout;
|
|
50
|
-
output.write(text + "\n");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const compartment = new Compartment({
|
|
54
|
-
globals: {
|
|
55
|
-
Date: codeModeDate,
|
|
56
|
-
Math: codeModeMath,
|
|
57
|
-
_requestHistory: harden(requestHistory),
|
|
58
|
-
_writeOutput: harden(writeOutput),
|
|
59
|
-
docs: workerData.docs,
|
|
60
|
-
},
|
|
61
|
-
__options__: true,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
compartment.evaluate(String.raw`
|
|
65
|
-
(() => {
|
|
66
|
-
const requestHistoryBridge = _requestHistory;
|
|
67
|
-
const writeOutputBridge = _writeOutput;
|
|
68
|
-
delete globalThis._requestHistory;
|
|
69
|
-
delete globalThis._writeOutput;
|
|
70
|
-
|
|
71
|
-
function formatOutputValue(value) {
|
|
72
|
-
if (typeof value === "string") return value;
|
|
73
|
-
if (value instanceof Error) return value.stack || value.message;
|
|
74
|
-
try {
|
|
75
|
-
const serialized = JSON.stringify(value);
|
|
76
|
-
if (serialized !== undefined) return serialized;
|
|
77
|
-
} catch {}
|
|
78
|
-
return String(value);
|
|
79
|
-
}
|
|
80
|
-
function writeConsole(stream, values) {
|
|
81
|
-
writeOutputBridge(stream, values.map(formatOutputValue).join(" "));
|
|
82
|
-
}
|
|
83
|
-
Object.defineProperty(globalThis, "console", {
|
|
84
|
-
value: Object.freeze({
|
|
85
|
-
debug: (...values) => writeConsole("stdout", values),
|
|
86
|
-
error: (...values) => writeConsole("stderr", values),
|
|
87
|
-
info: (...values) => writeConsole("stdout", values),
|
|
88
|
-
log: (...values) => writeConsole("stdout", values),
|
|
89
|
-
warn: (...values) => writeConsole("stderr", values),
|
|
90
|
-
}),
|
|
91
|
-
});
|
|
92
|
-
function callHistory(method, args) {
|
|
93
|
-
return requestHistoryBridge(method, JSON.stringify(args));
|
|
94
|
-
}
|
|
95
|
-
Object.defineProperty(globalThis, "history", {
|
|
96
|
-
value: Object.freeze({
|
|
97
|
-
search: (...args) => callHistory("search", args),
|
|
98
|
-
read: (...args) => callHistory("read", args),
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
})();
|
|
102
|
-
`);
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
await compartment.evaluate("(async () => {\n" + workerData.code + "\n})()");
|
|
106
|
-
} catch (error) {
|
|
107
|
-
writeOutput("stderr", error instanceof Error ? error.stack || error.message : String(error));
|
|
108
|
-
process.exitCode = 1;
|
|
109
|
-
} finally {
|
|
110
|
-
parentPort.close();
|
|
111
|
-
}
|
|
1
|
+
import "../sandbox_runner.mjs";
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
The one-shot JavaScript runtime provides these globals:
|
|
2
|
-
|
|
3
|
-
- `nook.skill()`: load the configured Nook deployment's version-matched app-authoring skill.
|
|
4
|
-
- `nook.sites`: list, copy, deploy, and delete sites.
|
|
5
|
-
- `nook.templates`: list, copy, save, and delete editable templates.
|
|
6
|
-
- `nook.kv`: get, put, import, export, delete, and list per-site JSON KV entries.
|
|
7
|
-
- `docs`: this agent-facing SDK document.
|
|
8
|
-
- `console`: program output. Only text written through console methods is returned; program return values are ignored.
|
|
9
|
-
- `Date`: standard date handling with live current-time access.
|
|
10
|
-
- `Math`: standard math operations, including `Math.random()`.
|
|
11
|
-
|
|
12
|
-
Top-level `await` is supported. A program may make at most 64 SDK calls, with at most four running concurrently, and must finish within 60 seconds. Independent calls can run concurrently with `Promise.all` within that limit.
|
|
13
|
-
|
|
14
1
|
Use absolute file system paths. Generated code has no direct filesystem, process, environment, network, credential, import, timer, or `fetch` access. Nook methods are the only platform capability.
|
|
15
2
|
|
|
16
3
|
## App-authoring guidance
|
|
@@ -215,4 +202,4 @@ Copy, inspect or modify with filesystem tools in later calls, build with Bash, t
|
|
|
215
202
|
|
|
216
203
|
## Output guidance
|
|
217
204
|
|
|
218
|
-
|
|
205
|
+
Print only information needed for the task. Prefer concise labeled text over serialized response objects. Select relevant fields when possible; when all fields matter, flatten and label them compactly. Emit JSON only when the user explicitly requests JSON or another machine-readable result.
|
|
@@ -1,147 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { codeModeMath, createCodeModeDate } from "../capabilities.mjs";
|
|
3
|
-
|
|
4
|
-
if (!parentPort) {
|
|
5
|
-
throw new Error("nook sandbox requires a parent port");
|
|
6
|
-
}
|
|
7
|
-
if (
|
|
8
|
-
typeof workerData !== "object" ||
|
|
9
|
-
workerData === null ||
|
|
10
|
-
typeof workerData.code !== "string" ||
|
|
11
|
-
typeof workerData.docs !== "string"
|
|
12
|
-
) {
|
|
13
|
-
throw new Error("nook sandbox received invalid worker data");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
lockdown();
|
|
17
|
-
|
|
18
|
-
const codeModeDate = createCodeModeDate();
|
|
19
|
-
const pending = new Map();
|
|
20
|
-
let nextRequestId = 1;
|
|
21
|
-
|
|
22
|
-
parentPort.on("message", (message) => {
|
|
23
|
-
if (message?.type !== "response" || typeof message.id !== "number") return;
|
|
24
|
-
const request = pending.get(message.id);
|
|
25
|
-
if (!request) return;
|
|
26
|
-
pending.delete(message.id);
|
|
27
|
-
if (message.ok) {
|
|
28
|
-
request.resolve(message.value);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const error = new Error(message.error?.message || "Nook request failed");
|
|
33
|
-
if (message.error?.name) error.name = message.error.name;
|
|
34
|
-
request.reject(error);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
function requestNook(method, argsJson) {
|
|
38
|
-
if (typeof method !== "string" || typeof argsJson !== "string") {
|
|
39
|
-
return Promise.reject(new Error("invalid nook bridge request"));
|
|
40
|
-
}
|
|
41
|
-
const id = nextRequestId++;
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
pending.set(id, { resolve, reject });
|
|
44
|
-
parentPort.postMessage({ type: "request", id, method, argsJson });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function writeOutput(stream, text) {
|
|
49
|
-
if ((stream !== "stdout" && stream !== "stderr") || typeof text !== "string") {
|
|
50
|
-
throw new Error("invalid console bridge output");
|
|
51
|
-
}
|
|
52
|
-
const output = stream === "stderr" ? process.stderr : process.stdout;
|
|
53
|
-
output.write(text + "\n");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const compartment = new Compartment({
|
|
57
|
-
globals: {
|
|
58
|
-
Date: codeModeDate,
|
|
59
|
-
Math: codeModeMath,
|
|
60
|
-
_requestNook: harden(requestNook),
|
|
61
|
-
_writeOutput: harden(writeOutput),
|
|
62
|
-
docs: workerData.docs,
|
|
63
|
-
},
|
|
64
|
-
__options__: true,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
compartment.evaluate(String.raw`
|
|
68
|
-
(() => {
|
|
69
|
-
const requestNookBridge = _requestNook;
|
|
70
|
-
const writeOutputBridge = _writeOutput;
|
|
71
|
-
delete globalThis._requestNook;
|
|
72
|
-
delete globalThis._writeOutput;
|
|
73
|
-
|
|
74
|
-
function formatOutputValue(value) {
|
|
75
|
-
if (typeof value === "string") return value;
|
|
76
|
-
if (value instanceof Error) return value.stack || value.message;
|
|
77
|
-
try {
|
|
78
|
-
const serialized = JSON.stringify(value);
|
|
79
|
-
if (serialized !== undefined) return serialized;
|
|
80
|
-
} catch {}
|
|
81
|
-
return String(value);
|
|
82
|
-
}
|
|
83
|
-
function writeConsole(stream, values) {
|
|
84
|
-
writeOutputBridge(stream, values.map(formatOutputValue).join(" "));
|
|
85
|
-
}
|
|
86
|
-
Object.defineProperty(globalThis, "console", {
|
|
87
|
-
value: Object.freeze({
|
|
88
|
-
debug: (...values) => writeConsole("stdout", values),
|
|
89
|
-
error: (...values) => writeConsole("stderr", values),
|
|
90
|
-
info: (...values) => writeConsole("stdout", values),
|
|
91
|
-
log: (...values) => writeConsole("stdout", values),
|
|
92
|
-
warn: (...values) => writeConsole("stderr", values),
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
function serializeArguments(args) {
|
|
96
|
-
return JSON.stringify(args, (_key, value) => {
|
|
97
|
-
if (
|
|
98
|
-
value === undefined ||
|
|
99
|
-
typeof value === "function" ||
|
|
100
|
-
typeof value === "symbol" ||
|
|
101
|
-
typeof value === "bigint" ||
|
|
102
|
-
(typeof value === "number" && !Number.isFinite(value))
|
|
103
|
-
) {
|
|
104
|
-
throw new TypeError("Nook arguments must be JSON-serializable values");
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function callNook(method, args) {
|
|
110
|
-
return requestNookBridge(method, serializeArguments(args));
|
|
111
|
-
}
|
|
112
|
-
Object.defineProperty(globalThis, "nook", {
|
|
113
|
-
value: Object.freeze({
|
|
114
|
-
skill: (...args) => callNook("skill", args),
|
|
115
|
-
sites: Object.freeze({
|
|
116
|
-
list: (...args) => callNook("sites.list", args),
|
|
117
|
-
copy: (...args) => callNook("sites.copy", args),
|
|
118
|
-
deploy: (...args) => callNook("sites.deploy", args),
|
|
119
|
-
delete: (...args) => callNook("sites.delete", args),
|
|
120
|
-
}),
|
|
121
|
-
templates: Object.freeze({
|
|
122
|
-
list: (...args) => callNook("templates.list", args),
|
|
123
|
-
copy: (...args) => callNook("templates.copy", args),
|
|
124
|
-
save: (...args) => callNook("templates.save", args),
|
|
125
|
-
delete: (...args) => callNook("templates.delete", args),
|
|
126
|
-
}),
|
|
127
|
-
kv: Object.freeze({
|
|
128
|
-
get: (...args) => callNook("kv.get", args),
|
|
129
|
-
getToFile: (...args) => callNook("kv.getToFile", args),
|
|
130
|
-
put: (...args) => callNook("kv.put", args),
|
|
131
|
-
putFromFile: (...args) => callNook("kv.putFromFile", args),
|
|
132
|
-
delete: (...args) => callNook("kv.delete", args),
|
|
133
|
-
list: (...args) => callNook("kv.list", args),
|
|
134
|
-
}),
|
|
135
|
-
}),
|
|
136
|
-
});
|
|
137
|
-
})();
|
|
138
|
-
`);
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
await compartment.evaluate("(async () => {\n" + workerData.code + "\n})()");
|
|
142
|
-
} catch (error) {
|
|
143
|
-
writeOutput("stderr", error instanceof Error ? error.stack || error.message : String(error));
|
|
144
|
-
process.exitCode = 1;
|
|
145
|
-
} finally {
|
|
146
|
-
parentPort.close();
|
|
147
|
-
}
|
|
1
|
+
import "../sandbox_runner.mjs";
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
import { codeModeMath, createCodeModeDate } from "./capabilities.mjs";
|
|
4
|
+
|
|
5
|
+
if (!parentPort) {
|
|
6
|
+
throw new Error("code-mode sandbox requires a parent port");
|
|
7
|
+
}
|
|
8
|
+
if (
|
|
9
|
+
typeof workerData !== "object" ||
|
|
10
|
+
workerData === null ||
|
|
11
|
+
typeof workerData.code !== "string" ||
|
|
12
|
+
typeof workerData.docs !== "string" ||
|
|
13
|
+
typeof workerData.name !== "string" ||
|
|
14
|
+
!Array.isArray(workerData.methods) ||
|
|
15
|
+
!Number.isSafeInteger(workerData.maxBridgeRequests) ||
|
|
16
|
+
workerData.maxBridgeRequests <= 0 ||
|
|
17
|
+
!Number.isSafeInteger(workerData.maxConcurrentBridgeRequests) ||
|
|
18
|
+
workerData.maxConcurrentBridgeRequests <= 0 ||
|
|
19
|
+
!Number.isSafeInteger(workerData.maxBridgePayloadBytes) ||
|
|
20
|
+
workerData.maxBridgePayloadBytes <= 0
|
|
21
|
+
) {
|
|
22
|
+
throw new Error("code-mode sandbox received invalid worker data");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
lockdown();
|
|
26
|
+
|
|
27
|
+
const codeModeDate = createCodeModeDate();
|
|
28
|
+
const pending = new Map();
|
|
29
|
+
let nextRequestId = 1;
|
|
30
|
+
|
|
31
|
+
parentPort.on("message", (message) => {
|
|
32
|
+
if (message?.type !== "response" || typeof message.id !== "number") return;
|
|
33
|
+
const request = pending.get(message.id);
|
|
34
|
+
if (!request) return;
|
|
35
|
+
pending.delete(message.id);
|
|
36
|
+
if (message.ok) {
|
|
37
|
+
try {
|
|
38
|
+
if (
|
|
39
|
+
typeof message.valueJson !== "string" ||
|
|
40
|
+
Buffer.byteLength(message.valueJson, "utf8") > workerData.maxBridgePayloadBytes
|
|
41
|
+
) {
|
|
42
|
+
throw new Error("invalid code-mode bridge response");
|
|
43
|
+
}
|
|
44
|
+
request.resolve(JSON.parse(message.valueJson));
|
|
45
|
+
} catch {
|
|
46
|
+
request.reject(new Error("code-mode bridge returned invalid JSON"));
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const error = new Error(message.error?.message || "Code-mode API request failed");
|
|
52
|
+
if (message.error?.name) error.name = message.error.name;
|
|
53
|
+
request.reject(error);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function requestApi(methodId, argsJson) {
|
|
57
|
+
if (!Number.isSafeInteger(methodId) || methodId < 0 || typeof argsJson !== "string") {
|
|
58
|
+
return Promise.reject(new Error("invalid code-mode bridge request"));
|
|
59
|
+
}
|
|
60
|
+
if (Buffer.byteLength(argsJson, "utf8") > workerData.maxBridgePayloadBytes) {
|
|
61
|
+
return Promise.reject(
|
|
62
|
+
new Error(
|
|
63
|
+
`code-mode API arguments exceeded ${workerData.maxBridgePayloadBytes} bridge payload bytes`,
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (nextRequestId > workerData.maxBridgeRequests) {
|
|
68
|
+
return Promise.reject(
|
|
69
|
+
new Error(`code-mode sandbox exceeded ${workerData.maxBridgeRequests} bridge requests`),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (pending.size >= workerData.maxConcurrentBridgeRequests) {
|
|
73
|
+
return Promise.reject(
|
|
74
|
+
new Error(
|
|
75
|
+
`code-mode sandbox exceeded ${workerData.maxConcurrentBridgeRequests} concurrent bridge requests`,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const id = nextRequestId++;
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
pending.set(id, { resolve, reject });
|
|
82
|
+
parentPort.postMessage({ type: "request", id, methodId, argsJson });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function writeOutput(stream, text) {
|
|
87
|
+
if ((stream !== "stdout" && stream !== "stderr") || typeof text !== "string") {
|
|
88
|
+
throw new Error("invalid console bridge output");
|
|
89
|
+
}
|
|
90
|
+
const output = stream === "stderr" ? process.stderr : process.stdout;
|
|
91
|
+
output.write(text + "\n");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const compartment = new Compartment({
|
|
95
|
+
globals: {
|
|
96
|
+
Date: codeModeDate,
|
|
97
|
+
Math: codeModeMath,
|
|
98
|
+
_apiName: workerData.name,
|
|
99
|
+
_methods: harden(workerData.methods),
|
|
100
|
+
_requestApi: harden(requestApi),
|
|
101
|
+
_writeOutput: harden(writeOutput),
|
|
102
|
+
docs: workerData.docs,
|
|
103
|
+
},
|
|
104
|
+
__options__: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
compartment.evaluate(String.raw`
|
|
108
|
+
(() => {
|
|
109
|
+
const apiName = _apiName;
|
|
110
|
+
const methods = _methods;
|
|
111
|
+
const requestApiBridge = _requestApi;
|
|
112
|
+
const writeOutputBridge = _writeOutput;
|
|
113
|
+
delete globalThis._apiName;
|
|
114
|
+
delete globalThis._methods;
|
|
115
|
+
delete globalThis._requestApi;
|
|
116
|
+
delete globalThis._writeOutput;
|
|
117
|
+
|
|
118
|
+
function formatOutputValue(value) {
|
|
119
|
+
if (typeof value === "string") return value;
|
|
120
|
+
if (value instanceof Error) return value.stack || value.message;
|
|
121
|
+
try {
|
|
122
|
+
const serialized = JSON.stringify(value);
|
|
123
|
+
if (serialized !== undefined) return serialized;
|
|
124
|
+
} catch {}
|
|
125
|
+
return String(value);
|
|
126
|
+
}
|
|
127
|
+
function writeConsole(stream, values) {
|
|
128
|
+
writeOutputBridge(stream, values.map(formatOutputValue).join(" "));
|
|
129
|
+
}
|
|
130
|
+
Object.defineProperty(globalThis, "console", {
|
|
131
|
+
value: Object.freeze({
|
|
132
|
+
debug: (...values) => writeConsole("stdout", values),
|
|
133
|
+
error: (...values) => writeConsole("stderr", values),
|
|
134
|
+
info: (...values) => writeConsole("stdout", values),
|
|
135
|
+
log: (...values) => writeConsole("stdout", values),
|
|
136
|
+
warn: (...values) => writeConsole("stderr", values),
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function serializeArguments(args) {
|
|
141
|
+
return JSON.stringify(args, (_key, value) => {
|
|
142
|
+
if (
|
|
143
|
+
value === undefined ||
|
|
144
|
+
typeof value === "function" ||
|
|
145
|
+
typeof value === "symbol" ||
|
|
146
|
+
typeof value === "bigint" ||
|
|
147
|
+
(typeof value === "number" && !Number.isFinite(value))
|
|
148
|
+
) {
|
|
149
|
+
throw new TypeError("Code-mode API arguments must be JSON-serializable values");
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const api = Object.create(null);
|
|
156
|
+
for (const method of methods) {
|
|
157
|
+
let target = api;
|
|
158
|
+
for (const segment of method.path.slice(0, -1)) {
|
|
159
|
+
target[segment] ??= Object.create(null);
|
|
160
|
+
target = target[segment];
|
|
161
|
+
}
|
|
162
|
+
target[method.path.at(-1)] = (...args) =>
|
|
163
|
+
requestApiBridge(method.id, serializeArguments(args));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function freezeApi(value) {
|
|
167
|
+
for (const child of Object.values(value)) {
|
|
168
|
+
if (typeof child === "object" && child !== null) freezeApi(child);
|
|
169
|
+
}
|
|
170
|
+
return Object.freeze(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
Object.defineProperty(globalThis, apiName, {
|
|
174
|
+
value: freezeApi(api),
|
|
175
|
+
});
|
|
176
|
+
})();
|
|
177
|
+
`);
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
await compartment.evaluate("(async () => {\n" + workerData.code + "\n})()");
|
|
181
|
+
} catch (error) {
|
|
182
|
+
writeOutput("stderr", error instanceof Error ? error.stack || error.message : String(error));
|
|
183
|
+
process.exitCode = 1;
|
|
184
|
+
} finally {
|
|
185
|
+
parentPort.close();
|
|
186
|
+
}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
The one-shot JavaScript runtime provides these globals:
|
|
2
|
-
|
|
3
|
-
- `web.discover(url)`: discover metadata for direct Markdown representations and `llms.txt` files for a direct URL.
|
|
4
|
-
- `web.search(query, options?)`: search the web and return relevant page highlights.
|
|
5
|
-
- `web.fetch(urls, options?)`: retrieve highlights or bounded text from known URLs through the web extraction service.
|
|
6
|
-
- `docs`: this document.
|
|
7
|
-
- `console`: program output. Only text written through console methods is returned; program return values are ignored.
|
|
8
|
-
- `Date`: standard date handling with live current-time access.
|
|
9
|
-
- `Math`: standard math operations, including `Math.random()`.
|
|
10
|
-
|
|
11
|
-
Top-level `await` is supported. A program may make at most 64 SDK calls, with at most four running concurrently, and must finish within 60 seconds. Independent calls can run concurrently with `Promise.all` within that limit.
|
|
12
|
-
|
|
13
1
|
## Defaults
|
|
14
2
|
|
|
15
3
|
The API is designed for agent workflows and defaults to token-efficient retrieval:
|
|
@@ -247,4 +235,4 @@ In the next turn, retrieve the selected Markdown representation or `llms.txt` wi
|
|
|
247
235
|
|
|
248
236
|
## Output guidance
|
|
249
237
|
|
|
250
|
-
|
|
238
|
+
Print only information needed for the task. Prefer concise labeled text over serialized response objects. Select relevant fields when possible; when all fields matter, flatten and label them compactly. Emit JSON only when the user explicitly requests JSON or another machine-readable result.
|
|
@@ -1,115 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { codeModeMath, createCodeModeDate } from "../capabilities.mjs";
|
|
3
|
-
|
|
4
|
-
if (!parentPort) {
|
|
5
|
-
throw new Error("web sandbox requires a parent port");
|
|
6
|
-
}
|
|
7
|
-
if (
|
|
8
|
-
typeof workerData !== "object" ||
|
|
9
|
-
workerData === null ||
|
|
10
|
-
typeof workerData.code !== "string" ||
|
|
11
|
-
typeof workerData.docs !== "string"
|
|
12
|
-
) {
|
|
13
|
-
throw new Error("web sandbox received invalid worker data");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
lockdown();
|
|
17
|
-
|
|
18
|
-
const codeModeDate = createCodeModeDate();
|
|
19
|
-
const pending = new Map();
|
|
20
|
-
let nextRequestId = 1;
|
|
21
|
-
|
|
22
|
-
parentPort.on("message", (message) => {
|
|
23
|
-
if (message?.type !== "response" || typeof message.id !== "number") return;
|
|
24
|
-
const request = pending.get(message.id);
|
|
25
|
-
if (!request) return;
|
|
26
|
-
pending.delete(message.id);
|
|
27
|
-
if (message.ok) {
|
|
28
|
-
request.resolve(message.value);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const error = new Error(message.error?.message || "Web request failed");
|
|
33
|
-
if (message.error?.name) error.name = message.error.name;
|
|
34
|
-
request.reject(error);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
function requestWeb(method, argsJson) {
|
|
38
|
-
if (typeof method !== "string" || typeof argsJson !== "string") {
|
|
39
|
-
return Promise.reject(new Error("invalid web bridge request"));
|
|
40
|
-
}
|
|
41
|
-
const id = nextRequestId++;
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
pending.set(id, { resolve, reject });
|
|
44
|
-
parentPort.postMessage({ type: "request", id, method, argsJson });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function writeOutput(stream, text) {
|
|
49
|
-
if ((stream !== "stdout" && stream !== "stderr") || typeof text !== "string") {
|
|
50
|
-
throw new Error("invalid console bridge output");
|
|
51
|
-
}
|
|
52
|
-
const output = stream === "stderr" ? process.stderr : process.stdout;
|
|
53
|
-
output.write(text + "\n");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const compartment = new Compartment({
|
|
57
|
-
globals: {
|
|
58
|
-
Date: codeModeDate,
|
|
59
|
-
Math: codeModeMath,
|
|
60
|
-
_requestWeb: harden(requestWeb),
|
|
61
|
-
_writeOutput: harden(writeOutput),
|
|
62
|
-
docs: workerData.docs,
|
|
63
|
-
},
|
|
64
|
-
__options__: true,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
compartment.evaluate(String.raw`
|
|
68
|
-
(() => {
|
|
69
|
-
const requestWebBridge = _requestWeb;
|
|
70
|
-
const writeOutputBridge = _writeOutput;
|
|
71
|
-
delete globalThis._requestWeb;
|
|
72
|
-
delete globalThis._writeOutput;
|
|
73
|
-
|
|
74
|
-
function formatOutputValue(value) {
|
|
75
|
-
if (typeof value === "string") return value;
|
|
76
|
-
if (value instanceof Error) return value.stack || value.message;
|
|
77
|
-
try {
|
|
78
|
-
const serialized = JSON.stringify(value);
|
|
79
|
-
if (serialized !== undefined) return serialized;
|
|
80
|
-
} catch {}
|
|
81
|
-
return String(value);
|
|
82
|
-
}
|
|
83
|
-
function writeConsole(stream, values) {
|
|
84
|
-
writeOutputBridge(stream, values.map(formatOutputValue).join(" "));
|
|
85
|
-
}
|
|
86
|
-
Object.defineProperty(globalThis, "console", {
|
|
87
|
-
value: Object.freeze({
|
|
88
|
-
debug: (...values) => writeConsole("stdout", values),
|
|
89
|
-
error: (...values) => writeConsole("stderr", values),
|
|
90
|
-
info: (...values) => writeConsole("stdout", values),
|
|
91
|
-
log: (...values) => writeConsole("stdout", values),
|
|
92
|
-
warn: (...values) => writeConsole("stderr", values),
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
function callWeb(method, args) {
|
|
96
|
-
return requestWebBridge(method, JSON.stringify(args));
|
|
97
|
-
}
|
|
98
|
-
Object.defineProperty(globalThis, "web", {
|
|
99
|
-
value: Object.freeze({
|
|
100
|
-
discover: (...args) => callWeb("discover", args),
|
|
101
|
-
search: (...args) => callWeb("search", args),
|
|
102
|
-
fetch: (...args) => callWeb("fetch", args),
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
|
-
})();
|
|
106
|
-
`);
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
await compartment.evaluate("(async () => {\n" + workerData.code + "\n})()");
|
|
110
|
-
} catch (error) {
|
|
111
|
-
writeOutput("stderr", error instanceof Error ? error.stack || error.message : String(error));
|
|
112
|
-
process.exitCode = 1;
|
|
113
|
-
} finally {
|
|
114
|
-
parentPort.close();
|
|
115
|
-
}
|
|
1
|
+
import "../sandbox_runner.mjs";
|
package/dist/core/tools/bash.js
CHANGED
|
@@ -96,7 +96,7 @@ async function createBashTempFilePath(backend) {
|
|
|
96
96
|
return undefined;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
async function writeBashTempFile(backend, content) {
|
|
99
|
+
export async function writeBashTempFile(backend, content) {
|
|
100
100
|
if (!content)
|
|
101
101
|
return undefined;
|
|
102
102
|
const tempPath = await createBashTempFilePath(backend);
|