@pasko70/pibo 1.9.13 → 1.10.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/README.md +183 -183
- package/context/codex-base-prompt.md +148 -148
- package/context/compute-worker.md +23 -23
- package/context/pibo-compaction-prompt.md +100 -100
- package/context/pibo-native-tooling.md +18 -18
- package/context/pibo-system-prompt.md +77 -77
- package/dist/apps/chat/agent-profiles.js +2 -2
- package/dist/apps/chat/agent-store.js +263 -250
- package/dist/apps/chat/chat-request-normalizers.js +17 -0
- package/dist/apps/chat/data/chat-data-mappers.js +2 -0
- package/dist/apps/chat/data/project-service.js +168 -168
- package/dist/apps/chat/data/read-state-service.js +18 -18
- package/dist/apps/chat/data/session-query-service.js +25 -25
- package/dist/apps/chat/data/timeline-query-service.js +19 -19
- package/dist/apps/chat/loop-api.js +181 -0
- package/dist/apps/chat/static-assets.js +854 -854
- package/dist/apps/chat/web-app.js +36 -16
- package/dist/apps/chat/workflow-manual-trigger-runtime.js +149 -46
- package/dist/apps/chat/workflow-persistence.js +255 -255
- package/dist/apps/chat-ui/assets/{dist-BZ2eTC4f.js → dist-3Sts0Afa.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BHa-kcGl.js → dist-4NlLjLs7.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-yCYNNb5d.js → dist-BA6mhAec.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-D811wJeV.js → dist-BPl-fzRB.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-Dq4GxJi3.js → dist-BPnn9e2B.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CzE6k3F3.js → dist-BpfBSMzK.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CnVsqwSG.js → dist-Cvx5M97R.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-WyXdYl-w.js → dist-DnXWNQRm.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BNMu92bb.js → dist-hU-2oAb6.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BCB6zezO.js → dist-r31x5Fcc.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-HqTN67dc.js → dist-uF6UXzI7.js} +1 -1
- package/dist/apps/chat-ui/assets/index-CaTGYBOS.js +173 -0
- package/dist/apps/chat-ui/assets/{index-C0x9nEcf.css → index-al8DeEjA.css} +1 -1
- package/dist/apps/chat-ui/index.html +18 -18
- package/dist/apps/chat-ui/manifest.webmanifest +25 -25
- package/dist/apps/chat-ui/sw.js +47 -47
- package/dist/apps/chat-vscode-web/assets/index-CK4SMZuu.js +41 -0
- package/dist/apps/chat-vscode-web/index.html +13 -13
- package/dist/apps/cli-ui/cliSessionsCommand.js +23 -23
- package/dist/apps/context-files-ui/index.html +11 -11
- package/dist/cli-session/localSessionSource.js +34 -12
- package/dist/cli.js +61 -44
- package/dist/compute/cli.js +54 -54
- package/dist/compute/resource-health.js +35 -2
- package/dist/core/events.js +6 -1
- package/dist/core/routed-session.js +97 -5
- package/dist/core/runtime.js +6 -1
- package/dist/core/session-router.js +27 -8
- package/dist/cron/cli.js +15 -15
- package/dist/cron/store.js +49 -49
- package/dist/data/cli.js +23 -23
- package/dist/data/event-log.js +23 -23
- package/dist/data/ingest-service.js +3 -1
- package/dist/data/message-store.js +27 -27
- package/dist/data/navigation-store.js +9 -9
- package/dist/data/observation-store.js +4 -4
- package/dist/data/payload-store.js +17 -17
- package/dist/data/schema.js +433 -433
- package/dist/data/session-store.js +4 -4
- package/dist/data/telemetry-queries.js +54 -54
- package/dist/data/telemetry.js +197 -197
- package/dist/debug/events.js +12 -12
- package/dist/debug/failures.js +6 -6
- package/dist/debug/index.js +231 -227
- package/dist/debug/messages.js +6 -6
- package/dist/debug/pty.js +124 -124
- package/dist/debug/session.js +29 -29
- package/dist/debug/tools.js +5 -5
- package/dist/debug/trace.js +42 -7
- package/dist/debug/web-snapshot-browser-scripts.js +294 -294
- package/dist/debug/web-streaming-browser-library.js +925 -925
- package/dist/debug/web-streaming-browser-scripts.js +232 -232
- package/dist/debug/web-streaming-provider-telemetry.js +4 -4
- package/dist/debug/web.js +93 -93
- package/dist/gateway/cli.js +19 -19
- package/dist/gateway/server.js +4 -2
- package/dist/gateway/web.js +2 -2
- package/dist/index.js +1 -0
- package/dist/loops/accounting.js +19 -0
- package/dist/loops/channel.js +8 -0
- package/dist/loops/cli.js +224 -0
- package/dist/loops/plugin.js +16 -0
- package/dist/loops/prompts.js +86 -0
- package/dist/loops/service.js +446 -0
- package/dist/loops/stopping.js +170 -0
- package/dist/loops/store.js +642 -0
- package/dist/loops/templates.js +232 -0
- package/dist/loops/tools.js +184 -0
- package/dist/loops/types.js +1 -0
- package/dist/mcp/config-command.js +53 -53
- package/dist/mcp/index.js +21 -21
- package/dist/mcp/registry.js +11 -11
- package/dist/pi-packages/cli.js +11 -11
- package/dist/plugins/builtin.js +8 -0
- package/dist/plugins/context-files-store.js +110 -110
- package/dist/plugins/context-files.js +4 -4
- package/dist/plugins/registry.js +23 -12
- package/dist/ralph/cli.js +18 -18
- package/dist/ralph/templates.js +140 -140
- package/dist/reliability/store.js +256 -229
- package/dist/runs/lifecycle.js +59 -0
- package/dist/runs/registry.js +47 -1
- package/dist/runs/tools.js +31 -13
- package/dist/session-ui/terminalRows.js +66 -2
- package/dist/sessions/pibo-data-store.js +16 -16
- package/dist/sessions/sqlite-store.js +53 -53
- package/dist/setup/cli.js +58 -58
- package/dist/shared/trace-async-agent-runs.js +4 -4
- package/dist/shared/trace-event-projection.js +59 -19
- package/dist/shared/trace-nodes.js +5 -0
- package/dist/shared/trace-page-merge.js +15 -0
- package/dist/shared/trace-run-notifications.js +3 -1
- package/dist/signals/projector.js +6 -2
- package/dist/tools/agent-browser-wrapper.js +80 -80
- package/dist/tools/browser-pool.js +50 -0
- package/dist/tools/browser-use-cdp.js +12 -12
- package/dist/tools/browser-use-leases.js +12 -8
- package/dist/tools/browser-use-wrapper.js +762 -762
- package/dist/tools/guides.js +596 -538
- package/dist/tools/index.js +123 -99
- package/dist/tools/registry.js +21 -3
- package/dist/tools/runtime/node-worker-source.js +205 -205
- package/dist/tools/runtime/python-worker-source.js +177 -177
- package/dist/vscode/cli.js +9 -9
- package/dist/web-annotations/cdp.js +900 -900
- package/dist/web-annotations/store.js +96 -96
- package/docs/README.md +23 -23
- package/docs/ops/install-developer-host.md +112 -112
- package/docs/ops/install-user-host.md +96 -96
- package/docs/ops/upgrade-user-to-developer-host.md +69 -69
- package/docs/ops/vscode-extension-release.md +160 -160
- package/package.json +99 -95
- package/skills/builtin/graphify/SKILL.md +52 -52
- package/skills/builtin/loop/SKILL.md +78 -0
- package/skills/builtin/pi-agent-harness/SKILL.md +319 -319
- package/skills/builtin/pi-agent-harness/agents/openai.yaml +4 -4
- package/skills/builtin/pibo-docker-system/SKILL.md +170 -170
- package/skills/builtin/pibo-spec-writing/SKILL.md +330 -330
- package/skills/builtin/prd/SKILL.md +143 -143
- package/skills/builtin/ralph-loop/SKILL.md +361 -359
- package/skills/builtin/ralph-prd-json/SKILL.md +123 -123
- package/skills/builtin/skill-creator/LICENSE.txt +201 -201
- package/skills/builtin/skill-creator/SKILL.md +513 -513
- package/skills/builtin/skill-creator/agents/analyzer.md +274 -274
- package/skills/builtin/skill-creator/agents/comparator.md +202 -202
- package/skills/builtin/skill-creator/agents/grader.md +223 -223
- package/skills/builtin/skill-creator/assets/eval_review.html +146 -146
- package/skills/builtin/skill-creator/eval-viewer/generate_review.py +471 -471
- package/skills/builtin/skill-creator/eval-viewer/viewer.html +1325 -1325
- package/skills/builtin/skill-creator/references/schemas.md +430 -430
- package/skills/builtin/skill-creator/scripts/aggregate_benchmark.py +401 -401
- package/skills/builtin/skill-creator/scripts/generate_report.py +326 -326
- package/skills/builtin/skill-creator/scripts/improve_description.py +247 -247
- package/skills/builtin/skill-creator/scripts/package_skill.py +136 -136
- package/skills/builtin/skill-creator/scripts/quick_validate.py +102 -102
- package/skills/builtin/skill-creator/scripts/run_eval.py +310 -310
- package/skills/builtin/skill-creator/scripts/run_loop.py +328 -328
- package/skills/builtin/skill-creator/scripts/utils.py +47 -47
- package/skills/builtin/web-annotations/SKILL.md +93 -93
- package/src/mcp/LICENSE.mcp-cli +21 -21
- package/dist/apps/chat-ui/assets/index-DwHJfmiF.js +0 -173
- package/dist/apps/chat-vscode-web/assets/index-BAMxIaI_.js +0 -41
- package/dist/apps/vscode-artifacts/latest.vsix +0 -0
- package/dist/apps/vscode-artifacts/pibo-vscode-ext-1.9.13.vsix +0 -0
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
export const NODE_RUNTIME_WORKER_SOURCE = String.raw `
|
|
2
|
-
const vm = require("node:vm");
|
|
3
|
-
const util = require("node:util");
|
|
4
|
-
|
|
5
|
-
let currentOutput = null;
|
|
6
|
-
|
|
7
|
-
function bounded(value, maxBytes = 8192) {
|
|
8
|
-
const text = String(value);
|
|
9
|
-
const bytes = Buffer.byteLength(text, "utf8");
|
|
10
|
-
if (bytes <= maxBytes) return text;
|
|
11
|
-
return Buffer.from(text, "utf8").subarray(0, maxBytes).toString("utf8") + "\n...<truncated>";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function safeInspect(value, maxBytes = 4096) {
|
|
15
|
-
try {
|
|
16
|
-
return bounded(util.inspect(value, { depth: 3, maxArrayLength: 50, breakLength: 120 }), maxBytes);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
return "<inspect failed: " + (error?.name || "Error") + ": " + (error?.message || String(error)) + ">";
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function summarize(value, maxBytes = 4096) {
|
|
23
|
-
const type = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
24
|
-
const result = { type, repr: safeInspect(value, maxBytes) };
|
|
25
|
-
try {
|
|
26
|
-
if (value != null && typeof value.length === "number") result.length = value.length;
|
|
27
|
-
if (Array.isArray(value)) result.length = value.length;
|
|
28
|
-
if (value && typeof value === "object") {
|
|
29
|
-
const keys = Object.keys(value).slice(0, 50);
|
|
30
|
-
if (keys.length > 0) result.keys = keys;
|
|
31
|
-
}
|
|
32
|
-
} catch {}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function errorSummary(error) {
|
|
37
|
-
const stack = error && error.stack ? String(error.stack) : String(error);
|
|
38
|
-
const out = {
|
|
39
|
-
name: error && error.name ? String(error.name) : "Error",
|
|
40
|
-
message: error && error.message ? String(error.message) : String(error),
|
|
41
|
-
stack,
|
|
42
|
-
};
|
|
43
|
-
const match = stack.match(/<pibo-runtime>:(\d+):(\d+)/) || stack.match(/evalmachine\.<anonymous>:(\d+):(\d+)/);
|
|
44
|
-
if (match) {
|
|
45
|
-
out.line = Number(match[1]);
|
|
46
|
-
out.column = Number(match[2]);
|
|
47
|
-
}
|
|
48
|
-
return out;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function appendStdout(chunk) {
|
|
52
|
-
if (currentOutput) currentOutput.stdout += String(chunk);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function appendStderr(chunk) {
|
|
56
|
-
if (currentOutput) currentOutput.stderr += String(chunk);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const processProxy = new Proxy(process, {
|
|
60
|
-
get(target, prop, receiver) {
|
|
61
|
-
if (prop === "stdout") return { write: (chunk) => { appendStdout(chunk); return true; } };
|
|
62
|
-
if (prop === "stderr") return { write: (chunk) => { appendStderr(chunk); return true; } };
|
|
63
|
-
return Reflect.get(target, prop, receiver);
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const consoleProxy = {
|
|
68
|
-
log: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
69
|
-
info: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
70
|
-
debug: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
71
|
-
warn: (...args) => appendStderr(util.format(...args) + "\n"),
|
|
72
|
-
error: (...args) => appendStderr(util.format(...args) + "\n"),
|
|
73
|
-
dir: (value, options) => appendStdout(util.inspect(value, options) + "\n"),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const context = vm.createContext({
|
|
77
|
-
console: consoleProxy,
|
|
78
|
-
require,
|
|
79
|
-
process: processProxy,
|
|
80
|
-
Buffer,
|
|
81
|
-
URL,
|
|
82
|
-
URLSearchParams,
|
|
83
|
-
TextEncoder,
|
|
84
|
-
TextDecoder,
|
|
85
|
-
setTimeout,
|
|
86
|
-
clearTimeout,
|
|
87
|
-
setInterval,
|
|
88
|
-
clearInterval,
|
|
89
|
-
setImmediate,
|
|
90
|
-
clearImmediate,
|
|
91
|
-
queueMicrotask,
|
|
92
|
-
});
|
|
93
|
-
context.global = context;
|
|
94
|
-
context.globalThis = context;
|
|
95
|
-
|
|
96
|
-
async function execute(req) {
|
|
97
|
-
const mode = req.mode || "exec";
|
|
98
|
-
const code = req.code || "";
|
|
99
|
-
const output = { stdout: "", stderr: "" };
|
|
100
|
-
currentOutput = output;
|
|
101
|
-
try {
|
|
102
|
-
const value = await (async () => {
|
|
103
|
-
if (mode === "eval") {
|
|
104
|
-
return await vm.runInContext(code, context, { filename: "<pibo-runtime>", timeout: Number(req.timeoutMs || 30000) });
|
|
105
|
-
}
|
|
106
|
-
const result = vm.runInContext(code, context, { filename: "<pibo-runtime>", timeout: Number(req.timeoutMs || 30000) });
|
|
107
|
-
if (result && typeof result.then === "function") await result;
|
|
108
|
-
return undefined;
|
|
109
|
-
})();
|
|
110
|
-
return {
|
|
111
|
-
id: req.id,
|
|
112
|
-
status: "ok",
|
|
113
|
-
stdout: output.stdout,
|
|
114
|
-
stderr: output.stderr,
|
|
115
|
-
result: value === undefined ? null : summarize(value),
|
|
116
|
-
};
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return {
|
|
119
|
-
id: req.id,
|
|
120
|
-
status: "error",
|
|
121
|
-
stdout: output.stdout,
|
|
122
|
-
stderr: output.stderr,
|
|
123
|
-
error: errorSummary(error),
|
|
124
|
-
};
|
|
125
|
-
} finally {
|
|
126
|
-
currentOutput = null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function inspectValue(req) {
|
|
131
|
-
const expression = req.expression || "";
|
|
132
|
-
const what = req.what || "summary";
|
|
133
|
-
const maxBytes = Number(req.maxBytes || 8192);
|
|
134
|
-
try {
|
|
135
|
-
const value = await vm.runInContext(expression, context, { filename: "<pibo-runtime>", timeout: 15000 });
|
|
136
|
-
const result = { id: req.id, status: "ok" };
|
|
137
|
-
if (what === "summary" || what === "all") result.summary = summarize(value, maxBytes);
|
|
138
|
-
if (what === "signature" || what === "all") result.signature = typeof value === "function" ? bounded(value.toString().split("{")[0].trim(), maxBytes) : "<signature unavailable>";
|
|
139
|
-
if (what === "members" || what === "all") {
|
|
140
|
-
const members = new Set();
|
|
141
|
-
for (const key of Reflect.ownKeys(Object(value))) members.add(String(key));
|
|
142
|
-
const proto = value == null ? undefined : Object.getPrototypeOf(value);
|
|
143
|
-
if (proto) for (const key of Reflect.ownKeys(proto)) members.add(String(key));
|
|
144
|
-
result.members = [...members].slice(0, 200);
|
|
145
|
-
}
|
|
146
|
-
if (what === "source" || what === "all") result.source = typeof value === "function" ? bounded(value.toString(), maxBytes) : "<source unavailable>";
|
|
147
|
-
if (what === "doc" || what === "all") result.doc = "";
|
|
148
|
-
return result;
|
|
149
|
-
} catch (error) {
|
|
150
|
-
return { id: req.id, status: "error", error: errorSummary(error) };
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function listVars(req) {
|
|
155
|
-
const includePrivate = Boolean(req.includePrivate);
|
|
156
|
-
const maxItems = Number(req.maxItems || 100);
|
|
157
|
-
const maxBytes = Number(req.maxBytes || 4096);
|
|
158
|
-
const hidden = new Set(["console", "require", "process", "Buffer", "URL", "URLSearchParams", "TextEncoder", "TextDecoder", "global", "globalThis"]);
|
|
159
|
-
const variables = [];
|
|
160
|
-
for (const name of Object.keys(context).sort()) {
|
|
161
|
-
if (hidden.has(name)) continue;
|
|
162
|
-
if (!includePrivate && name.startsWith("_")) continue;
|
|
163
|
-
variables.push({ name, summary: summarize(context[name], maxBytes) });
|
|
164
|
-
if (variables.length >= maxItems) break;
|
|
165
|
-
}
|
|
166
|
-
return { id: req.id, status: "ok", variables, truncated: variables.length >= maxItems };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function writeResponse(resp) {
|
|
170
|
-
process.stdout.write(JSON.stringify(resp) + "\n");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function handle(req) {
|
|
174
|
-
if (req.type === "exec") return await execute(req);
|
|
175
|
-
if (req.type === "inspect") return await inspectValue(req);
|
|
176
|
-
if (req.type === "vars") return listVars(req);
|
|
177
|
-
if (req.type === "shutdown") return { id: req.id, status: "ok", shutdown: true };
|
|
178
|
-
return { id: req.id, status: "error", error: { name: "RuntimeProtocolError", message: "unknown request type " + req.type } };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async function main() {
|
|
182
|
-
writeResponse({ id: "ready", status: "ready" });
|
|
183
|
-
let buffer = "";
|
|
184
|
-
process.stdin.setEncoding("utf8");
|
|
185
|
-
process.stdin.on("data", async (chunk) => {
|
|
186
|
-
buffer += chunk;
|
|
187
|
-
let index;
|
|
188
|
-
while ((index = buffer.indexOf("\n")) >= 0) {
|
|
189
|
-
const line = buffer.slice(0, index);
|
|
190
|
-
buffer = buffer.slice(index + 1);
|
|
191
|
-
if (!line.trim()) continue;
|
|
192
|
-
let req;
|
|
193
|
-
try {
|
|
194
|
-
req = JSON.parse(line);
|
|
195
|
-
const resp = await handle(req);
|
|
196
|
-
writeResponse(resp);
|
|
197
|
-
if (resp.shutdown) process.exit(0);
|
|
198
|
-
} catch (error) {
|
|
199
|
-
writeResponse({ id: req?.id, status: "error", error: errorSummary(error) });
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
main();
|
|
1
|
+
export const NODE_RUNTIME_WORKER_SOURCE = String.raw `
|
|
2
|
+
const vm = require("node:vm");
|
|
3
|
+
const util = require("node:util");
|
|
4
|
+
|
|
5
|
+
let currentOutput = null;
|
|
6
|
+
|
|
7
|
+
function bounded(value, maxBytes = 8192) {
|
|
8
|
+
const text = String(value);
|
|
9
|
+
const bytes = Buffer.byteLength(text, "utf8");
|
|
10
|
+
if (bytes <= maxBytes) return text;
|
|
11
|
+
return Buffer.from(text, "utf8").subarray(0, maxBytes).toString("utf8") + "\n...<truncated>";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function safeInspect(value, maxBytes = 4096) {
|
|
15
|
+
try {
|
|
16
|
+
return bounded(util.inspect(value, { depth: 3, maxArrayLength: 50, breakLength: 120 }), maxBytes);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return "<inspect failed: " + (error?.name || "Error") + ": " + (error?.message || String(error)) + ">";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function summarize(value, maxBytes = 4096) {
|
|
23
|
+
const type = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
24
|
+
const result = { type, repr: safeInspect(value, maxBytes) };
|
|
25
|
+
try {
|
|
26
|
+
if (value != null && typeof value.length === "number") result.length = value.length;
|
|
27
|
+
if (Array.isArray(value)) result.length = value.length;
|
|
28
|
+
if (value && typeof value === "object") {
|
|
29
|
+
const keys = Object.keys(value).slice(0, 50);
|
|
30
|
+
if (keys.length > 0) result.keys = keys;
|
|
31
|
+
}
|
|
32
|
+
} catch {}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function errorSummary(error) {
|
|
37
|
+
const stack = error && error.stack ? String(error.stack) : String(error);
|
|
38
|
+
const out = {
|
|
39
|
+
name: error && error.name ? String(error.name) : "Error",
|
|
40
|
+
message: error && error.message ? String(error.message) : String(error),
|
|
41
|
+
stack,
|
|
42
|
+
};
|
|
43
|
+
const match = stack.match(/<pibo-runtime>:(\d+):(\d+)/) || stack.match(/evalmachine\.<anonymous>:(\d+):(\d+)/);
|
|
44
|
+
if (match) {
|
|
45
|
+
out.line = Number(match[1]);
|
|
46
|
+
out.column = Number(match[2]);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function appendStdout(chunk) {
|
|
52
|
+
if (currentOutput) currentOutput.stdout += String(chunk);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function appendStderr(chunk) {
|
|
56
|
+
if (currentOutput) currentOutput.stderr += String(chunk);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const processProxy = new Proxy(process, {
|
|
60
|
+
get(target, prop, receiver) {
|
|
61
|
+
if (prop === "stdout") return { write: (chunk) => { appendStdout(chunk); return true; } };
|
|
62
|
+
if (prop === "stderr") return { write: (chunk) => { appendStderr(chunk); return true; } };
|
|
63
|
+
return Reflect.get(target, prop, receiver);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const consoleProxy = {
|
|
68
|
+
log: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
69
|
+
info: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
70
|
+
debug: (...args) => appendStdout(util.format(...args) + "\n"),
|
|
71
|
+
warn: (...args) => appendStderr(util.format(...args) + "\n"),
|
|
72
|
+
error: (...args) => appendStderr(util.format(...args) + "\n"),
|
|
73
|
+
dir: (value, options) => appendStdout(util.inspect(value, options) + "\n"),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const context = vm.createContext({
|
|
77
|
+
console: consoleProxy,
|
|
78
|
+
require,
|
|
79
|
+
process: processProxy,
|
|
80
|
+
Buffer,
|
|
81
|
+
URL,
|
|
82
|
+
URLSearchParams,
|
|
83
|
+
TextEncoder,
|
|
84
|
+
TextDecoder,
|
|
85
|
+
setTimeout,
|
|
86
|
+
clearTimeout,
|
|
87
|
+
setInterval,
|
|
88
|
+
clearInterval,
|
|
89
|
+
setImmediate,
|
|
90
|
+
clearImmediate,
|
|
91
|
+
queueMicrotask,
|
|
92
|
+
});
|
|
93
|
+
context.global = context;
|
|
94
|
+
context.globalThis = context;
|
|
95
|
+
|
|
96
|
+
async function execute(req) {
|
|
97
|
+
const mode = req.mode || "exec";
|
|
98
|
+
const code = req.code || "";
|
|
99
|
+
const output = { stdout: "", stderr: "" };
|
|
100
|
+
currentOutput = output;
|
|
101
|
+
try {
|
|
102
|
+
const value = await (async () => {
|
|
103
|
+
if (mode === "eval") {
|
|
104
|
+
return await vm.runInContext(code, context, { filename: "<pibo-runtime>", timeout: Number(req.timeoutMs || 30000) });
|
|
105
|
+
}
|
|
106
|
+
const result = vm.runInContext(code, context, { filename: "<pibo-runtime>", timeout: Number(req.timeoutMs || 30000) });
|
|
107
|
+
if (result && typeof result.then === "function") await result;
|
|
108
|
+
return undefined;
|
|
109
|
+
})();
|
|
110
|
+
return {
|
|
111
|
+
id: req.id,
|
|
112
|
+
status: "ok",
|
|
113
|
+
stdout: output.stdout,
|
|
114
|
+
stderr: output.stderr,
|
|
115
|
+
result: value === undefined ? null : summarize(value),
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
id: req.id,
|
|
120
|
+
status: "error",
|
|
121
|
+
stdout: output.stdout,
|
|
122
|
+
stderr: output.stderr,
|
|
123
|
+
error: errorSummary(error),
|
|
124
|
+
};
|
|
125
|
+
} finally {
|
|
126
|
+
currentOutput = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function inspectValue(req) {
|
|
131
|
+
const expression = req.expression || "";
|
|
132
|
+
const what = req.what || "summary";
|
|
133
|
+
const maxBytes = Number(req.maxBytes || 8192);
|
|
134
|
+
try {
|
|
135
|
+
const value = await vm.runInContext(expression, context, { filename: "<pibo-runtime>", timeout: 15000 });
|
|
136
|
+
const result = { id: req.id, status: "ok" };
|
|
137
|
+
if (what === "summary" || what === "all") result.summary = summarize(value, maxBytes);
|
|
138
|
+
if (what === "signature" || what === "all") result.signature = typeof value === "function" ? bounded(value.toString().split("{")[0].trim(), maxBytes) : "<signature unavailable>";
|
|
139
|
+
if (what === "members" || what === "all") {
|
|
140
|
+
const members = new Set();
|
|
141
|
+
for (const key of Reflect.ownKeys(Object(value))) members.add(String(key));
|
|
142
|
+
const proto = value == null ? undefined : Object.getPrototypeOf(value);
|
|
143
|
+
if (proto) for (const key of Reflect.ownKeys(proto)) members.add(String(key));
|
|
144
|
+
result.members = [...members].slice(0, 200);
|
|
145
|
+
}
|
|
146
|
+
if (what === "source" || what === "all") result.source = typeof value === "function" ? bounded(value.toString(), maxBytes) : "<source unavailable>";
|
|
147
|
+
if (what === "doc" || what === "all") result.doc = "";
|
|
148
|
+
return result;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return { id: req.id, status: "error", error: errorSummary(error) };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function listVars(req) {
|
|
155
|
+
const includePrivate = Boolean(req.includePrivate);
|
|
156
|
+
const maxItems = Number(req.maxItems || 100);
|
|
157
|
+
const maxBytes = Number(req.maxBytes || 4096);
|
|
158
|
+
const hidden = new Set(["console", "require", "process", "Buffer", "URL", "URLSearchParams", "TextEncoder", "TextDecoder", "global", "globalThis"]);
|
|
159
|
+
const variables = [];
|
|
160
|
+
for (const name of Object.keys(context).sort()) {
|
|
161
|
+
if (hidden.has(name)) continue;
|
|
162
|
+
if (!includePrivate && name.startsWith("_")) continue;
|
|
163
|
+
variables.push({ name, summary: summarize(context[name], maxBytes) });
|
|
164
|
+
if (variables.length >= maxItems) break;
|
|
165
|
+
}
|
|
166
|
+
return { id: req.id, status: "ok", variables, truncated: variables.length >= maxItems };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function writeResponse(resp) {
|
|
170
|
+
process.stdout.write(JSON.stringify(resp) + "\n");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function handle(req) {
|
|
174
|
+
if (req.type === "exec") return await execute(req);
|
|
175
|
+
if (req.type === "inspect") return await inspectValue(req);
|
|
176
|
+
if (req.type === "vars") return listVars(req);
|
|
177
|
+
if (req.type === "shutdown") return { id: req.id, status: "ok", shutdown: true };
|
|
178
|
+
return { id: req.id, status: "error", error: { name: "RuntimeProtocolError", message: "unknown request type " + req.type } };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function main() {
|
|
182
|
+
writeResponse({ id: "ready", status: "ready" });
|
|
183
|
+
let buffer = "";
|
|
184
|
+
process.stdin.setEncoding("utf8");
|
|
185
|
+
process.stdin.on("data", async (chunk) => {
|
|
186
|
+
buffer += chunk;
|
|
187
|
+
let index;
|
|
188
|
+
while ((index = buffer.indexOf("\n")) >= 0) {
|
|
189
|
+
const line = buffer.slice(0, index);
|
|
190
|
+
buffer = buffer.slice(index + 1);
|
|
191
|
+
if (!line.trim()) continue;
|
|
192
|
+
let req;
|
|
193
|
+
try {
|
|
194
|
+
req = JSON.parse(line);
|
|
195
|
+
const resp = await handle(req);
|
|
196
|
+
writeResponse(resp);
|
|
197
|
+
if (resp.shutdown) process.exit(0);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
writeResponse({ id: req?.id, status: "error", error: errorSummary(error) });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
main();
|
|
206
206
|
`;
|