laohuang 0.9.8 → 0.9.9
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 +19 -0
- package/THIRD_PARTY_NOTICES +23 -0
- package/dist/bin.js +8018 -6231
- package/dist/bin.js.map +4 -4
- package/dist/codemode-worker.js +344 -0
- package/dist/codemode-worker.js.map +7 -0
- package/package.json +7 -1
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createBundleRequire } from 'node:module';
|
|
3
|
+
const require = createBundleRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// ../../packages/core/codemode/dist/globals.js
|
|
6
|
+
var RESERVED = new Set("tools ALL_TOOLS text image console exit store load process require fetch global globalThis await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield".split(" "));
|
|
7
|
+
|
|
8
|
+
// ../../packages/core/codemode/dist/limits.js
|
|
9
|
+
var CODEMODE_LIMITS = {
|
|
10
|
+
memoryBytes: 268435456,
|
|
11
|
+
outputChars: 16777216,
|
|
12
|
+
outputItems: 1e5,
|
|
13
|
+
storeValueChars: 262144,
|
|
14
|
+
storeTotalChars: 1048576
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// ../../packages/core/codemode/dist/runtime/protocol.js
|
|
18
|
+
function isHostToWorkerMessage(value) {
|
|
19
|
+
if (!value || typeof value !== "object")
|
|
20
|
+
return false;
|
|
21
|
+
const message = value;
|
|
22
|
+
return message.type === "result" && Number.isSafeInteger(message.id) && Number(message.id) > 0 && typeof message.ok === "boolean" && (message.payload === void 0 || typeof message.payload === "string");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ../../packages/core/codemode/dist/runtime/worker.js
|
|
26
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
27
|
+
|
|
28
|
+
// ../../packages/core/codemode/dist/runtime/vm.js
|
|
29
|
+
import { JSException, MAX_STACK_SIZE, QuickJS } from "quickjs-wasi";
|
|
30
|
+
|
|
31
|
+
// ../../packages/core/codemode/dist/runtime/lockdown-source.js
|
|
32
|
+
var LOCKDOWN_SOURCE = `(() => {
|
|
33
|
+
const overridable = new Set(['constructor', 'name', 'message', 'toString', 'toLocaleString', 'valueOf', 'toJSON']);
|
|
34
|
+
const seen = new Set([globalThis]);
|
|
35
|
+
const queue = [];
|
|
36
|
+
const add = value => {
|
|
37
|
+
if ((typeof value === 'object' && value !== null) || typeof value === 'function') {
|
|
38
|
+
if (!seen.has(value)) { seen.add(value); queue.push(value); }
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (const key of Reflect.ownKeys(globalThis)) {
|
|
42
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, key);
|
|
43
|
+
add(descriptor.value); add(descriptor.get); add(descriptor.set);
|
|
44
|
+
if ('value' in descriptor && descriptor.configurable) Object.defineProperty(globalThis, key, { writable: false, configurable: false });
|
|
45
|
+
}
|
|
46
|
+
add(Object.getPrototypeOf(function* () {}));
|
|
47
|
+
add(Object.getPrototypeOf(async function () {}));
|
|
48
|
+
add(Object.getPrototypeOf(async function* () {}));
|
|
49
|
+
add(Object.getPrototypeOf(Int8Array));
|
|
50
|
+
for (const instance of [[], new Map(), new Set(), '']) add(Object.getPrototypeOf(instance[Symbol.iterator]()));
|
|
51
|
+
add(Object.getPrototypeOf(/a/[Symbol.matchAll]('')));
|
|
52
|
+
while (queue.length) {
|
|
53
|
+
const object = queue.pop();
|
|
54
|
+
add(Object.getPrototypeOf(object));
|
|
55
|
+
const descriptors = Object.getOwnPropertyDescriptors(object);
|
|
56
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
57
|
+
const descriptor = descriptors[key];
|
|
58
|
+
add(descriptor.value); add(descriptor.get); add(descriptor.set);
|
|
59
|
+
if (descriptor.writable && descriptor.configurable && (object === Object.prototype || overridable.has(key))) {
|
|
60
|
+
const value = descriptor.value;
|
|
61
|
+
const {get, set} = Object.getOwnPropertyDescriptor({
|
|
62
|
+
get accessor() { return value; },
|
|
63
|
+
set accessor(next) {
|
|
64
|
+
if (this === object) throw new TypeError('Cannot assign a built-in property');
|
|
65
|
+
if ((typeof this !== 'object' || this === null) && typeof this !== 'function') return;
|
|
66
|
+
Object.defineProperty(this, key, { value: next, writable: true, enumerable: true, configurable: true });
|
|
67
|
+
}
|
|
68
|
+
}, 'accessor');
|
|
69
|
+
Object.defineProperty(object, key, {get, set, enumerable: descriptor.enumerable, configurable: false});
|
|
70
|
+
add(get); add(set);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
Object.freeze(object);
|
|
74
|
+
}
|
|
75
|
+
})()`;
|
|
76
|
+
|
|
77
|
+
// ../../packages/core/codemode/dist/runtime/prelude-source.js
|
|
78
|
+
var PRELUDE_SOURCE = `(bridge, toolsJson, storeJson, globalsJson) => {
|
|
79
|
+
${LOCKDOWN_SOURCE};
|
|
80
|
+
const pending = new Map();
|
|
81
|
+
const parse = JSON.parse;
|
|
82
|
+
const stringify = JSON.stringify;
|
|
83
|
+
let nextId = 0;
|
|
84
|
+
let done = false;
|
|
85
|
+
let outputChars = 0;
|
|
86
|
+
let outputItems = 0;
|
|
87
|
+
const describeError = error => {
|
|
88
|
+
try { return stringify({name: String(error?.name ?? 'Error'), message: String(error?.message ?? error), stack: typeof error?.stack === 'string' ? error.stack : undefined}); }
|
|
89
|
+
catch { return stringify({message: 'Script threw an indescribable value'}); }
|
|
90
|
+
};
|
|
91
|
+
const fail = error => {
|
|
92
|
+
if (done) return;
|
|
93
|
+
done = true; bridge('done', false, describeError(error));
|
|
94
|
+
};
|
|
95
|
+
const budget = chars => {
|
|
96
|
+
if (outputChars + chars > ${CODEMODE_LIMITS.outputChars} || outputItems + 1 > ${CODEMODE_LIMITS.outputItems}) {
|
|
97
|
+
const error = new RangeError('Script output exceeded its limit');
|
|
98
|
+
fail(error); throw error;
|
|
99
|
+
}
|
|
100
|
+
outputChars += chars; outputItems++;
|
|
101
|
+
};
|
|
102
|
+
const stored = new Map(Object.entries(parse(storeJson)));
|
|
103
|
+
let storedChars = [...stored].reduce((sum, [key, json]) => sum + key.length + json.length, 0);
|
|
104
|
+
const writes = new Map();
|
|
105
|
+
const complete = value => {
|
|
106
|
+
if (done) return;
|
|
107
|
+
try {
|
|
108
|
+
if (typeof value === 'string') budget(value.length);
|
|
109
|
+
const encoded = stringify(value);
|
|
110
|
+
if (value !== undefined && typeof value !== 'string') {
|
|
111
|
+
if (encoded === undefined) throw new TypeError('Return value must be JSON serializable');
|
|
112
|
+
budget(encoded.length);
|
|
113
|
+
}
|
|
114
|
+
const encodedWrites = stringify([...writes].map(([key, json]) => json === undefined ? [key] : [key, json]));
|
|
115
|
+
done = true;
|
|
116
|
+
bridge('done', true, encoded, encodedWrites);
|
|
117
|
+
} catch (error) { fail(error); }
|
|
118
|
+
};
|
|
119
|
+
const EXIT = Object.freeze({});
|
|
120
|
+
Object.defineProperty(globalThis, 'exit', { value: () => { complete(undefined); throw EXIT; } });
|
|
121
|
+
const checkKey = key => { if (typeof key !== 'string') throw new TypeError('store/load key must be a string'); };
|
|
122
|
+
Object.defineProperty(globalThis, 'store', { value: (key, value) => {
|
|
123
|
+
checkKey(key);
|
|
124
|
+
const previous = stored.has(key) ? key.length + stored.get(key).length : 0;
|
|
125
|
+
if (value === undefined) { stored.delete(key); storedChars -= previous; writes.set(key, undefined); return; }
|
|
126
|
+
const json = stringify(value);
|
|
127
|
+
if (json === undefined) throw new TypeError('store value must be JSON serializable');
|
|
128
|
+
if (json.length > ${CODEMODE_LIMITS.storeValueChars}) throw new RangeError('Store value exceeded its JSON character limit');
|
|
129
|
+
const next = storedChars - previous + key.length + json.length;
|
|
130
|
+
if (next > ${CODEMODE_LIMITS.storeTotalChars}) throw new RangeError('Total store exceeded its character limit');
|
|
131
|
+
storedChars = next;
|
|
132
|
+
stored.set(key, json); writes.set(key, json);
|
|
133
|
+
} });
|
|
134
|
+
Object.defineProperty(globalThis, 'load', { value: key => {
|
|
135
|
+
checkKey(key); const json = stored.get(key); return json === undefined ? undefined : parse(json);
|
|
136
|
+
} });
|
|
137
|
+
Object.defineProperty(globalThis, 'text', { value: value => {
|
|
138
|
+
if (done) return;
|
|
139
|
+
const rendered = typeof value === 'object' && value !== null ? stringify(value) : String(value);
|
|
140
|
+
budget(rendered.length);
|
|
141
|
+
bridge('output', rendered);
|
|
142
|
+
} });
|
|
143
|
+
const console = Object.create(null);
|
|
144
|
+
for (const level of ['log', 'info', 'warn', 'error', 'debug']) console[level] = (...values) => {
|
|
145
|
+
if (done) return;
|
|
146
|
+
const rendered = values.map(value => value instanceof Error ? String(value) : typeof value === 'object' && value !== null ? stringify(value) : String(value)).join(' ');
|
|
147
|
+
budget(rendered.length); bridge('output', rendered, true);
|
|
148
|
+
};
|
|
149
|
+
Object.defineProperty(globalThis, 'console', {value: Object.freeze(console)});
|
|
150
|
+
Object.defineProperty(globalThis, 'image', { value: value => {
|
|
151
|
+
if (done) return;
|
|
152
|
+
if (value && typeof value === 'object' && value.type === 'image' && typeof value.attachment_id === 'string' && value.attachment_id) {
|
|
153
|
+
if (value.view !== undefined && (!value.view || typeof value.view !== 'object' || Array.isArray(value.view))) throw new TypeError('Invalid image view');
|
|
154
|
+
const source = {attachment_id: value.attachment_id, ...(value.view === undefined ? {} : {view: value.view})};
|
|
155
|
+
const encoded = stringify(source);
|
|
156
|
+
budget(value.attachment_id.length + (value.view === undefined ? 0 : stringify(value.view).length));
|
|
157
|
+
bridge('image', encoded); return;
|
|
158
|
+
}
|
|
159
|
+
let url;
|
|
160
|
+
if (typeof value === 'string') url = value;
|
|
161
|
+
else if (value && typeof value === 'object' && typeof value.image_url === 'string') url = value.image_url;
|
|
162
|
+
else if (value && value.type === 'image' && typeof value.data === 'string') url = value.data.toLowerCase().startsWith('data:') ? value.data : 'data:;base64,' + value.data;
|
|
163
|
+
if (typeof url !== 'string' || !/^data:[^,]*;base64,/i.test(url)) throw new TypeError('Image requires base64 data; remote URLs are unavailable');
|
|
164
|
+
const data = url.slice(url.indexOf(',') + 1).replace(/\\s+/g, '');
|
|
165
|
+
if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data)) throw new TypeError('Invalid image base64');
|
|
166
|
+
const signature = [
|
|
167
|
+
['image/png', /^iVBORw0KGg/], ['image/jpeg', /^[/]9j[/](?!9)/],
|
|
168
|
+
['image/gif', /^R0lGOD[dl]h/], ['image/webp', /^UklG.{8}RUJQ/]
|
|
169
|
+
].find(([, pattern]) => pattern.test(data.slice(0, 16)));
|
|
170
|
+
if (!signature) throw new TypeError('Image must be PNG, JPEG, GIF, or WebP');
|
|
171
|
+
budget(data.length); bridge('image', stringify({data, mimeType: signature[0]}));
|
|
172
|
+
} });
|
|
173
|
+
const tools = Object.create(null);
|
|
174
|
+
const caller = (kind, name, spread) => (...args) => new Promise((resolve, reject) => {
|
|
175
|
+
if (done) { reject(new Error('Script execution has ended')); return; }
|
|
176
|
+
const id = ++nextId;
|
|
177
|
+
const encoded = stringify(spread ? args : args[0]);
|
|
178
|
+
pending.set(id, {resolve, reject});
|
|
179
|
+
bridge(kind, id, name, encoded);
|
|
180
|
+
});
|
|
181
|
+
const allTools = [];
|
|
182
|
+
for (const tool of parse(toolsJson)) {
|
|
183
|
+
const fn = caller('call', tool.name, false);
|
|
184
|
+
tools[tool.jsName] = fn; tools[tool.name] = fn;
|
|
185
|
+
allTools.push(Object.freeze({name: tool.jsName, ...(tool.description === undefined ? {} : {description: tool.description})}));
|
|
186
|
+
}
|
|
187
|
+
Object.freeze(tools);
|
|
188
|
+
const guard = (target, label) => new Proxy(target, {get(object, property, receiver) {
|
|
189
|
+
if (typeof property !== 'string' || property in object || property in Object.prototype || property === 'then' || property === 'toJSON') return Reflect.get(object, property, receiver);
|
|
190
|
+
throw new TypeError(label + '.' + property + ' does not exist. Available: ' + Object.keys(object).slice(0, 20).join(', ') + '. Use ALL_TOOLS and searchTools to discover tools.');
|
|
191
|
+
}});
|
|
192
|
+
const toolsProxy = guard(tools, 'tools');
|
|
193
|
+
Object.defineProperty(globalThis, 'tools', { value: toolsProxy });
|
|
194
|
+
Object.defineProperty(globalThis, 'ALL_TOOLS', { value: Object.freeze(allTools) });
|
|
195
|
+
const namespaces = new Map();
|
|
196
|
+
for (const global of parse(globalsJson)) {
|
|
197
|
+
const fn = caller('global', global.name, global.spread);
|
|
198
|
+
const parts = global.name.split('.');
|
|
199
|
+
if (parts.length === 1) Object.defineProperty(globalThis, global.name, { value: fn });
|
|
200
|
+
else {
|
|
201
|
+
if (!namespaces.has(parts[0])) namespaces.set(parts[0], Object.create(null));
|
|
202
|
+
namespaces.get(parts[0])[parts[1]] = fn;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const [name, members] of namespaces) Object.defineProperty(globalThis, name, {value: guard(Object.freeze(members), name)});
|
|
206
|
+
return {
|
|
207
|
+
settle(id, ok, payload) {
|
|
208
|
+
const call = pending.get(id);
|
|
209
|
+
if (!call) throw new Error('Unknown host response ID');
|
|
210
|
+
pending.delete(id);
|
|
211
|
+
if (ok) call.resolve(payload === undefined ? undefined : parse(payload));
|
|
212
|
+
else call.reject(new Error(payload));
|
|
213
|
+
},
|
|
214
|
+
run(fn) {
|
|
215
|
+
fn(toolsProxy).then(complete, fail);
|
|
216
|
+
},
|
|
217
|
+
stalled() {
|
|
218
|
+
if (!done && pending.size === 0) {
|
|
219
|
+
done = true;
|
|
220
|
+
bridge('done', false, stringify({message: 'Script is stalled: no pending host calls can resume it.'}));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}`;
|
|
225
|
+
|
|
226
|
+
// ../../packages/core/codemode/dist/runtime/vm.js
|
|
227
|
+
async function startVm(options) {
|
|
228
|
+
const { data, post } = options;
|
|
229
|
+
const vm = await QuickJS.create({
|
|
230
|
+
wasm: options.wasm,
|
|
231
|
+
memoryLimit: data.memoryLimitBytes,
|
|
232
|
+
maxStackSize: MAX_STACK_SIZE,
|
|
233
|
+
interruptHandler: options.shouldInterrupt,
|
|
234
|
+
wasi: (memory) => ({ fd_write(_fd, pointer, count, writtenPointer) {
|
|
235
|
+
const view = new DataView(memory.buffer);
|
|
236
|
+
let written = 0;
|
|
237
|
+
for (let index = 0; index < count; index++)
|
|
238
|
+
written += view.getUint32(pointer + index * 8 + 4, true);
|
|
239
|
+
view.setUint32(writtenPointer, written, true);
|
|
240
|
+
return 0;
|
|
241
|
+
} })
|
|
242
|
+
});
|
|
243
|
+
let api;
|
|
244
|
+
let settle;
|
|
245
|
+
let stalled;
|
|
246
|
+
let disposed = false;
|
|
247
|
+
const exports = vm._getExports();
|
|
248
|
+
const drain = () => {
|
|
249
|
+
let jobs = 0;
|
|
250
|
+
while (exports.qjs_is_job_pending()) {
|
|
251
|
+
if (exports.qjs_execute_pending_job() < 0)
|
|
252
|
+
throw new Error("Promise job failed");
|
|
253
|
+
if (++jobs % 50 === 0 && options.shouldInterrupt())
|
|
254
|
+
throw new Error("Execution interrupted");
|
|
255
|
+
}
|
|
256
|
+
vm.callFunction(stalled, api).dispose();
|
|
257
|
+
};
|
|
258
|
+
const fail = (error) => {
|
|
259
|
+
if (error instanceof JSException)
|
|
260
|
+
post({ type: "done", ok: false, error: JSON.stringify({ name: error.name, message: error.message, stack: error.stack }) });
|
|
261
|
+
else
|
|
262
|
+
post({ type: "crash", message: error instanceof Error ? error.message : String(error) });
|
|
263
|
+
};
|
|
264
|
+
const session = {
|
|
265
|
+
deliver(message) {
|
|
266
|
+
if (disposed)
|
|
267
|
+
return;
|
|
268
|
+
try {
|
|
269
|
+
vm.withScope(() => {
|
|
270
|
+
vm.callFunction(settle, api, vm.newNumber(message.id), message.ok ? vm.true : vm.false, message.payload === void 0 ? vm.undefined : vm.newString(message.payload));
|
|
271
|
+
});
|
|
272
|
+
drain();
|
|
273
|
+
} catch (error) {
|
|
274
|
+
fail(error);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
dispose() {
|
|
278
|
+
if (!disposed) {
|
|
279
|
+
disposed = true;
|
|
280
|
+
vm.dispose();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
try {
|
|
285
|
+
const bridge = vm.newFunction("bridge", (kind, a, b, c) => {
|
|
286
|
+
if (kind.toString() === "call" || kind.toString() === "global")
|
|
287
|
+
post({ type: "call", target: kind.toString() === "call" ? "tool" : "global", id: a.toNumber(), name: b.toString(), args: c?.isUndefined ? void 0 : c?.toString() });
|
|
288
|
+
else if (kind.toString() === "output")
|
|
289
|
+
post({ type: "output", item: { type: "text", text: a.toString(), ...b?.toBoolean() ? { console: true } : {} } });
|
|
290
|
+
else if (kind.toString() === "image")
|
|
291
|
+
post({ type: "output", item: { type: "image", ...JSON.parse(a.toString()) } });
|
|
292
|
+
else if (kind.toString() === "done") {
|
|
293
|
+
if (a.toBoolean())
|
|
294
|
+
post({ type: "done", ok: true, value: b?.isUndefined ? void 0 : b?.toString(), writes: c.toString() });
|
|
295
|
+
else
|
|
296
|
+
post({ type: "done", ok: false, error: b.toString() });
|
|
297
|
+
} else
|
|
298
|
+
throw new Error("Invalid VM bridge operation");
|
|
299
|
+
return vm.undefined;
|
|
300
|
+
});
|
|
301
|
+
api = vm.withScope((scope) => scope.escape(vm.callFunction(vm.evalCode(PRELUDE_SOURCE, "codemode-prelude.js"), vm.undefined, bridge, vm.newString(JSON.stringify(data.tools)), vm.newString(JSON.stringify(data.store)), vm.newString(JSON.stringify(data.globals)))));
|
|
302
|
+
settle = api.getProp("settle");
|
|
303
|
+
stalled = api.getProp("stalled");
|
|
304
|
+
vm.withScope(() => {
|
|
305
|
+
const fn = vm.evalCode(`(async (tools) => {${data.code}
|
|
306
|
+
})`, "codemode.js");
|
|
307
|
+
vm.callFunction(api.getProp("run"), api, fn);
|
|
308
|
+
});
|
|
309
|
+
drain();
|
|
310
|
+
} catch (error) {
|
|
311
|
+
fail(error);
|
|
312
|
+
}
|
|
313
|
+
return session;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ../../packages/core/codemode/dist/runtime/worker.js
|
|
317
|
+
async function runCodeModeWorker() {
|
|
318
|
+
if (!parentPort)
|
|
319
|
+
throw new Error("Code Mode worker requires a parent port");
|
|
320
|
+
const port = parentPort;
|
|
321
|
+
const data = workerData;
|
|
322
|
+
const interrupt = new Int32Array(data.interrupt);
|
|
323
|
+
try {
|
|
324
|
+
const session = await startVm({
|
|
325
|
+
data,
|
|
326
|
+
wasm: data.wasm,
|
|
327
|
+
post: (message) => port.postMessage(message),
|
|
328
|
+
shouldInterrupt: () => Atomics.load(interrupt, 0) !== 0
|
|
329
|
+
});
|
|
330
|
+
port.on("message", (message) => {
|
|
331
|
+
if (isHostToWorkerMessage(message))
|
|
332
|
+
session.deliver(message);
|
|
333
|
+
else
|
|
334
|
+
port.postMessage({ type: "crash", message: "Invalid host protocol message" });
|
|
335
|
+
});
|
|
336
|
+
port.on("close", () => session.dispose());
|
|
337
|
+
} catch (error) {
|
|
338
|
+
port.postMessage({ type: "crash", message: error instanceof Error ? error.message : String(error) });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/codemode-worker.ts
|
|
343
|
+
await runCodeModeWorker();
|
|
344
|
+
//# sourceMappingURL=codemode-worker.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/core/codemode/src/globals.ts", "../../../packages/core/codemode/src/limits.ts", "../../../packages/core/codemode/src/runtime/protocol.ts", "../../../packages/core/codemode/src/runtime/worker.ts", "../../../packages/core/codemode/src/runtime/vm.ts", "../../../packages/core/codemode/src/runtime/lockdown-source.ts", "../../../packages/core/codemode/src/runtime/prelude-source.ts", "../src/codemode-worker.ts"],
|
|
4
|
+
"sourcesContent": ["import type { CodeModeGlobal } from \"./types.ts\";\n\nconst RESERVED = new Set(\"tools ALL_TOOLS text image console exit store load process require fetch global globalThis await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield\".split(\" \"));\n\nexport function validateCodeModeGlobals(globals: readonly CodeModeGlobal[]): void {\n const names = new Set<string>();\n const roots = new Map<string, boolean>();\n for (const global of globals) {\n const parts = global.name.split(\".\");\n const root = parts[0]!;\n const namespace = parts.length === 2;\n if (parts.length > 2 || parts.some(part => !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(part)) ||\n RESERVED.has(root) || root in globalThis || names.has(global.name) ||\n roots.has(root) && (!namespace || !roots.get(root)) || typeof global.execute !== \"function\") throw new Error(`Invalid or conflicting Code Mode global: ${global.name}`);\n names.add(global.name);\n roots.set(root, namespace);\n }\n}\n", "export const CODEMODE_LIMITS = {\n memoryBytes: 268435456,\n outputChars: 16777216,\n outputItems: 100000,\n storeValueChars: 262144,\n storeTotalChars: 1048576,\n} as const;\n", "import type { CodeModeOutputItem } from \"../types.ts\";\n\nexport interface VmStartData {\n readonly code: string;\n readonly memoryLimitBytes: number;\n readonly store: Readonly<Record<string, string>>;\n readonly globals: readonly { name: string; spread: boolean }[];\n readonly tools: readonly { name: string; jsName: string; description?: string }[];\n}\n\nexport interface WorkerData extends VmStartData {\n readonly wasm: object;\n readonly interrupt: SharedArrayBuffer;\n}\n\nexport type WorkerToHostMessage =\n | { type: \"call\"; id: number; target: \"tool\" | \"global\"; name: string; args?: string }\n | { type: \"output\"; item: CodeModeOutputItem }\n | { type: \"done\"; ok: true; value?: string; writes: string }\n | { type: \"done\"; ok: false; error: string }\n | { type: \"crash\"; message: string };\n\nexport interface HostToWorkerMessage {\n type: \"result\";\n id: number;\n ok: boolean;\n payload?: string;\n}\n\nexport function isWorkerToHostMessage(value: unknown): value is WorkerToHostMessage {\n if (!value || typeof value !== \"object\") return false;\n const message = value as Record<string, unknown>;\n switch (message.type) {\n case \"output\": {\n if (!message.item || typeof message.item !== \"object\") return false;\n const item = message.item as Record<string, unknown>;\n if (item.type === \"text\") return typeof item.text === \"string\" && (item.console === undefined || typeof item.console === \"boolean\");\n if (item.type !== \"image\") return false;\n if (typeof item.data === \"string\") return typeof item.mimeType === \"string\" && item.data.length > 0 && item.attachment_id === undefined;\n return typeof item.attachment_id === \"string\" && item.attachment_id.length > 0 &&\n (item.view === undefined || typeof item.view === \"object\" && item.view !== null && !Array.isArray(item.view));\n }\n case \"call\": return Number.isSafeInteger(message.id) && Number(message.id) > 0 && (message.target === \"tool\" || message.target === \"global\") && typeof message.name === \"string\" && (message.args === undefined || typeof message.args === \"string\");\n case \"done\": return message.ok === true ? (message.value === undefined || typeof message.value === \"string\") && typeof message.writes === \"string\" : message.ok === false && typeof message.error === \"string\";\n case \"crash\": return typeof message.message === \"string\";\n default: return false;\n }\n}\n\nexport function isHostToWorkerMessage(value: unknown): value is HostToWorkerMessage {\n if (!value || typeof value !== \"object\") return false;\n const message = value as Record<string, unknown>;\n return message.type === \"result\" && Number.isSafeInteger(message.id) && Number(message.id) > 0 && typeof message.ok === \"boolean\" && (message.payload === undefined || typeof message.payload === \"string\");\n}\n\nexport function isNodeWatchMessage(value: unknown): boolean {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n const keys = Object.keys(value);\n if (keys.length !== 1 || keys[0] !== \"watch:import\" && keys[0] !== \"watch:require\") return false;\n const paths = (value as Record<string, unknown>)[keys[0]];\n return Array.isArray(paths) && paths.every(path => typeof path === \"string\");\n}\n", "import { parentPort, workerData } from \"node:worker_threads\";\nimport { isHostToWorkerMessage, type WorkerData } from \"./protocol.ts\";\nimport { startVm } from \"./vm.ts\";\n\nexport async function runCodeModeWorker(): Promise<void> {\n if (!parentPort) throw new Error(\"Code Mode worker requires a parent port\");\n const port = parentPort;\n const data = workerData as WorkerData;\n const interrupt = new Int32Array(data.interrupt);\n try {\n const session = await startVm({ data, wasm: data.wasm, post: message => port.postMessage(message),\n shouldInterrupt: () => Atomics.load(interrupt, 0) !== 0 });\n port.on(\"message\", (message: unknown) => {\n if (isHostToWorkerMessage(message)) session.deliver(message);\n else port.postMessage({ type: \"crash\", message: \"Invalid host protocol message\" });\n });\n port.on(\"close\", () => session.dispose());\n } catch (error) { port.postMessage({ type: \"crash\", message: error instanceof Error ? error.message : String(error) }); }\n}\n", "import { JSException, MAX_STACK_SIZE, QuickJS, type JSValueHandle } from \"quickjs-wasi\";\nimport { PRELUDE_SOURCE } from \"./prelude-source.ts\";\nimport type { HostToWorkerMessage, VmStartData, WorkerToHostMessage } from \"./protocol.ts\";\nimport type { CodeModeImageSource } from \"../types.ts\";\n\nexport interface VmSession {\n deliver(message: HostToWorkerMessage): void;\n dispose(): void;\n}\n\nexport async function startVm(options: {\n data: VmStartData; wasm: object; post(message: WorkerToHostMessage): void; shouldInterrupt(): boolean;\n}): Promise<VmSession> {\n const { data, post } = options;\n const vm = await QuickJS.create({ wasm: options.wasm, memoryLimit: data.memoryLimitBytes,\n maxStackSize: MAX_STACK_SIZE, interruptHandler: options.shouldInterrupt,\n wasi: (memory: { readonly buffer: ArrayBufferLike }) => ({ fd_write(_fd: number, pointer: number, count: number, writtenPointer: number) {\n const view = new DataView(memory.buffer);\n let written = 0;\n for (let index = 0; index < count; index++) written += view.getUint32(pointer + index * 8 + 4, true);\n view.setUint32(writtenPointer, written, true);\n return 0;\n } }),\n });\n let api: JSValueHandle;\n let settle: JSValueHandle;\n let stalled: JSValueHandle;\n let disposed = false;\n const exports = vm._getExports();\n const drain = () => {\n let jobs = 0;\n while (exports.qjs_is_job_pending()) {\n if (exports.qjs_execute_pending_job() < 0) throw new Error(\"Promise job failed\");\n if (++jobs % 50 === 0 && options.shouldInterrupt()) throw new Error(\"Execution interrupted\");\n }\n vm.callFunction(stalled, api).dispose();\n };\n const fail = (error: unknown) => {\n if (error instanceof JSException) post({ type: \"done\", ok: false, error: JSON.stringify({ name: error.name, message: error.message, stack: error.stack }) });\n else post({ type: \"crash\", message: error instanceof Error ? error.message : String(error) });\n };\n const session: VmSession = {\n deliver(message) {\n if (disposed) return;\n try {\n vm.withScope(() => {\n vm.callFunction(settle, api, vm.newNumber(message.id), message.ok ? vm.true : vm.false,\n message.payload === undefined ? vm.undefined : vm.newString(message.payload));\n });\n drain();\n } catch (error) { fail(error); }\n },\n dispose() { if (!disposed) { disposed = true; vm.dispose(); } },\n };\n try {\n const bridge = vm.newFunction(\"bridge\", (kind, a, b, c) => {\n if (kind.toString() === \"call\" || kind.toString() === \"global\") post({ type: \"call\", target: kind.toString() === \"call\" ? \"tool\" : \"global\", id: a.toNumber(), name: b.toString(), args: c?.isUndefined ? undefined : c?.toString() });\n else if (kind.toString() === \"output\") post({ type: \"output\", item: { type: \"text\", text: a.toString(), ...(b?.toBoolean() ? { console: true } : {}) } });\n else if (kind.toString() === \"image\") post({ type: \"output\", item: { type: \"image\", ...JSON.parse(a.toString()) as CodeModeImageSource } });\n else if (kind.toString() === \"done\") {\n if (a.toBoolean()) post({ type: \"done\", ok: true, value: b?.isUndefined ? undefined : b?.toString(), writes: c.toString() });\n else post({ type: \"done\", ok: false, error: b.toString() });\n } else throw new Error(\"Invalid VM bridge operation\");\n return vm.undefined;\n });\n api = vm.withScope(scope => scope.escape(vm.callFunction(vm.evalCode(PRELUDE_SOURCE, \"codemode-prelude.js\"),\n vm.undefined, bridge, vm.newString(JSON.stringify(data.tools)), vm.newString(JSON.stringify(data.store)), vm.newString(JSON.stringify(data.globals)))));\n settle = api.getProp(\"settle\");\n stalled = api.getProp(\"stalled\");\n vm.withScope(() => {\n const fn = vm.evalCode(`(async (tools) => {${data.code}\\n})`, \"codemode.js\");\n vm.callFunction(api.getProp(\"run\"), api, fn);\n });\n drain();\n } catch (error) { fail(error); }\n return session;\n}\n", "/** Adapted from Pi's prelude lockdown; see this package's MIT license. */\nexport const LOCKDOWN_SOURCE = `(() => {\n const overridable = new Set(['constructor', 'name', 'message', 'toString', 'toLocaleString', 'valueOf', 'toJSON']);\n const seen = new Set([globalThis]);\n const queue = [];\n const add = value => {\n if ((typeof value === 'object' && value !== null) || typeof value === 'function') {\n if (!seen.has(value)) { seen.add(value); queue.push(value); }\n }\n };\n for (const key of Reflect.ownKeys(globalThis)) {\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, key);\n add(descriptor.value); add(descriptor.get); add(descriptor.set);\n if ('value' in descriptor && descriptor.configurable) Object.defineProperty(globalThis, key, { writable: false, configurable: false });\n }\n add(Object.getPrototypeOf(function* () {}));\n add(Object.getPrototypeOf(async function () {}));\n add(Object.getPrototypeOf(async function* () {}));\n add(Object.getPrototypeOf(Int8Array));\n for (const instance of [[], new Map(), new Set(), '']) add(Object.getPrototypeOf(instance[Symbol.iterator]()));\n add(Object.getPrototypeOf(/a/[Symbol.matchAll]('')));\n while (queue.length) {\n const object = queue.pop();\n add(Object.getPrototypeOf(object));\n const descriptors = Object.getOwnPropertyDescriptors(object);\n for (const key of Reflect.ownKeys(descriptors)) {\n const descriptor = descriptors[key];\n add(descriptor.value); add(descriptor.get); add(descriptor.set);\n if (descriptor.writable && descriptor.configurable && (object === Object.prototype || overridable.has(key))) {\n const value = descriptor.value;\n const {get, set} = Object.getOwnPropertyDescriptor({\n get accessor() { return value; },\n set accessor(next) {\n if (this === object) throw new TypeError('Cannot assign a built-in property');\n if ((typeof this !== 'object' || this === null) && typeof this !== 'function') return;\n Object.defineProperty(this, key, { value: next, writable: true, enumerable: true, configurable: true });\n }\n }, 'accessor');\n Object.defineProperty(object, key, {get, set, enumerable: descriptor.enumerable, configurable: false});\n add(get); add(set);\n }\n }\n Object.freeze(object);\n }\n})()`;\n", "import { LOCKDOWN_SOURCE } from \"./lockdown-source.ts\";\nimport { CODEMODE_LIMITS } from \"../limits.ts\";\n\n/** The bridge stays in a closure; functions and host objects never enter the VM. */\nexport const PRELUDE_SOURCE = `(bridge, toolsJson, storeJson, globalsJson) => {\n ${LOCKDOWN_SOURCE};\n const pending = new Map();\n const parse = JSON.parse;\n const stringify = JSON.stringify;\n let nextId = 0;\n let done = false;\n let outputChars = 0;\n let outputItems = 0;\n const describeError = error => {\n try { return stringify({name: String(error?.name ?? 'Error'), message: String(error?.message ?? error), stack: typeof error?.stack === 'string' ? error.stack : undefined}); }\n catch { return stringify({message: 'Script threw an indescribable value'}); }\n };\n const fail = error => {\n if (done) return;\n done = true; bridge('done', false, describeError(error));\n };\n const budget = chars => {\n if (outputChars + chars > ${CODEMODE_LIMITS.outputChars} || outputItems + 1 > ${CODEMODE_LIMITS.outputItems}) {\n const error = new RangeError('Script output exceeded its limit');\n fail(error); throw error;\n }\n outputChars += chars; outputItems++;\n };\n const stored = new Map(Object.entries(parse(storeJson)));\n let storedChars = [...stored].reduce((sum, [key, json]) => sum + key.length + json.length, 0);\n const writes = new Map();\n const complete = value => {\n if (done) return;\n try {\n if (typeof value === 'string') budget(value.length);\n const encoded = stringify(value);\n if (value !== undefined && typeof value !== 'string') {\n if (encoded === undefined) throw new TypeError('Return value must be JSON serializable');\n budget(encoded.length);\n }\n const encodedWrites = stringify([...writes].map(([key, json]) => json === undefined ? [key] : [key, json]));\n done = true;\n bridge('done', true, encoded, encodedWrites);\n } catch (error) { fail(error); }\n };\n const EXIT = Object.freeze({});\n Object.defineProperty(globalThis, 'exit', { value: () => { complete(undefined); throw EXIT; } });\n const checkKey = key => { if (typeof key !== 'string') throw new TypeError('store/load key must be a string'); };\n Object.defineProperty(globalThis, 'store', { value: (key, value) => {\n checkKey(key);\n const previous = stored.has(key) ? key.length + stored.get(key).length : 0;\n if (value === undefined) { stored.delete(key); storedChars -= previous; writes.set(key, undefined); return; }\n const json = stringify(value);\n if (json === undefined) throw new TypeError('store value must be JSON serializable');\n if (json.length > ${CODEMODE_LIMITS.storeValueChars}) throw new RangeError('Store value exceeded its JSON character limit');\n const next = storedChars - previous + key.length + json.length;\n if (next > ${CODEMODE_LIMITS.storeTotalChars}) throw new RangeError('Total store exceeded its character limit');\n storedChars = next;\n stored.set(key, json); writes.set(key, json);\n } });\n Object.defineProperty(globalThis, 'load', { value: key => {\n checkKey(key); const json = stored.get(key); return json === undefined ? undefined : parse(json);\n } });\n Object.defineProperty(globalThis, 'text', { value: value => {\n if (done) return;\n const rendered = typeof value === 'object' && value !== null ? stringify(value) : String(value);\n budget(rendered.length);\n bridge('output', rendered);\n } });\n const console = Object.create(null);\n for (const level of ['log', 'info', 'warn', 'error', 'debug']) console[level] = (...values) => {\n if (done) return;\n const rendered = values.map(value => value instanceof Error ? String(value) : typeof value === 'object' && value !== null ? stringify(value) : String(value)).join(' ');\n budget(rendered.length); bridge('output', rendered, true);\n };\n Object.defineProperty(globalThis, 'console', {value: Object.freeze(console)});\n Object.defineProperty(globalThis, 'image', { value: value => {\n if (done) return;\n if (value && typeof value === 'object' && value.type === 'image' && typeof value.attachment_id === 'string' && value.attachment_id) {\n if (value.view !== undefined && (!value.view || typeof value.view !== 'object' || Array.isArray(value.view))) throw new TypeError('Invalid image view');\n const source = {attachment_id: value.attachment_id, ...(value.view === undefined ? {} : {view: value.view})};\n const encoded = stringify(source);\n budget(value.attachment_id.length + (value.view === undefined ? 0 : stringify(value.view).length));\n bridge('image', encoded); return;\n }\n let url;\n if (typeof value === 'string') url = value;\n else if (value && typeof value === 'object' && typeof value.image_url === 'string') url = value.image_url;\n else if (value && value.type === 'image' && typeof value.data === 'string') url = value.data.toLowerCase().startsWith('data:') ? value.data : 'data:;base64,' + value.data;\n if (typeof url !== 'string' || !/^data:[^,]*;base64,/i.test(url)) throw new TypeError('Image requires base64 data; remote URLs are unavailable');\n const data = url.slice(url.indexOf(',') + 1).replace(/\\\\s+/g, '');\n if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data)) throw new TypeError('Invalid image base64');\n const signature = [\n ['image/png', /^iVBORw0KGg/], ['image/jpeg', /^[/]9j[/](?!9)/],\n ['image/gif', /^R0lGOD[dl]h/], ['image/webp', /^UklG.{8}RUJQ/]\n ].find(([, pattern]) => pattern.test(data.slice(0, 16)));\n if (!signature) throw new TypeError('Image must be PNG, JPEG, GIF, or WebP');\n budget(data.length); bridge('image', stringify({data, mimeType: signature[0]}));\n } });\n const tools = Object.create(null);\n const caller = (kind, name, spread) => (...args) => new Promise((resolve, reject) => {\n if (done) { reject(new Error('Script execution has ended')); return; }\n const id = ++nextId;\n const encoded = stringify(spread ? args : args[0]);\n pending.set(id, {resolve, reject});\n bridge(kind, id, name, encoded);\n });\n const allTools = [];\n for (const tool of parse(toolsJson)) {\n const fn = caller('call', tool.name, false);\n tools[tool.jsName] = fn; tools[tool.name] = fn;\n allTools.push(Object.freeze({name: tool.jsName, ...(tool.description === undefined ? {} : {description: tool.description})}));\n }\n Object.freeze(tools);\n const guard = (target, label) => new Proxy(target, {get(object, property, receiver) {\n if (typeof property !== 'string' || property in object || property in Object.prototype || property === 'then' || property === 'toJSON') return Reflect.get(object, property, receiver);\n throw new TypeError(label + '.' + property + ' does not exist. Available: ' + Object.keys(object).slice(0, 20).join(', ') + '. Use ALL_TOOLS and searchTools to discover tools.');\n }});\n const toolsProxy = guard(tools, 'tools');\n Object.defineProperty(globalThis, 'tools', { value: toolsProxy });\n Object.defineProperty(globalThis, 'ALL_TOOLS', { value: Object.freeze(allTools) });\n const namespaces = new Map();\n for (const global of parse(globalsJson)) {\n const fn = caller('global', global.name, global.spread);\n const parts = global.name.split('.');\n if (parts.length === 1) Object.defineProperty(globalThis, global.name, { value: fn });\n else {\n if (!namespaces.has(parts[0])) namespaces.set(parts[0], Object.create(null));\n namespaces.get(parts[0])[parts[1]] = fn;\n }\n }\n for (const [name, members] of namespaces) Object.defineProperty(globalThis, name, {value: guard(Object.freeze(members), name)});\n return {\n settle(id, ok, payload) {\n const call = pending.get(id);\n if (!call) throw new Error('Unknown host response ID');\n pending.delete(id);\n if (ok) call.resolve(payload === undefined ? undefined : parse(payload));\n else call.reject(new Error(payload));\n },\n run(fn) {\n fn(toolsProxy).then(complete, fail);\n },\n stalled() {\n if (!done && pending.size === 0) {\n done = true;\n bridge('done', false, stringify({message: 'Script is stalled: no pending host calls can resume it.'}));\n }\n }\n };\n}`;\n", "import { runCodeModeWorker } from \"@laoh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,SAAS;AAC/B,OAAG,UAAU,MAAK;AAChB,YAAM,KAAK,GAAG,SAAS,sBAAsB,KAAK,IAAI;KAAQ,aAAa;AAC3E,SAAG,aAAa,IAAI,QAAQ,KAAK,GAAG,KAAK,EAAE;IAC7C,CAAC;AACD,UAAK;EACP,SAAS,OAAO;AAAE,SAAK,KAAK;EAAG;AAC/B,SAAO;AACT;;;ADxEA,eAAsB,oBAAiB;AACrC,MAAI,CAAC;AAAY,UAAM,IAAI,MAAM,yCAAyC;AAC1E,QAAM,OAAO;AACb,QAAM,OAAO;AACb,QAAM,YAAY,IAAI,WAAW,KAAK,SAAS;AAC/C,MAAI;AACF,UAAM,UAAU,MAAM,QAAQ;MAAE;MAAM,MAAM,KAAK;MAAM,MAAM,aAAW,KAAK,YAAY,OAAO;MAC9F,iBAAiB,MAAM,QAAQ,KAAK,WAAW,CAAC,MAAM;IAAC,CAAE;AAC3D,SAAK,GAAG,WAAW,CAAC,YAAoB;AACtC,UAAI,sBAAsB,OAAO;AAAG,gBAAQ,QAAQ,OAAO;;AACtD,aAAK,YAAY,EAAE,MAAM,SAAS,SAAS,gCAA+B,CAAE;IACnF,CAAC;AACD,SAAK,GAAG,SAAS,MAAM,QAAQ,QAAO,CAAE;EAC1C,SAAS,OAAO;AAAE,SAAK,YAAY,EAAE,MAAM,SAAS,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAC,CAAE;EAAG;AAC1H;;;AIhBA,MAAM,kBAAkB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "laohuang",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
4
4
|
"description": "A terminal coding agent CLI with a provider-neutral model runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,16 +17,22 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist/bin.js",
|
|
19
19
|
"dist/bin.js.map",
|
|
20
|
+
"dist/codemode-worker.js",
|
|
21
|
+
"dist/codemode-worker.js.map",
|
|
22
|
+
"THIRD_PARTY_NOTICES",
|
|
20
23
|
"README.md",
|
|
21
24
|
"LICENSE"
|
|
22
25
|
],
|
|
23
26
|
"dependencies": {
|
|
27
|
+
"quickjs-wasi": "3.6.2",
|
|
24
28
|
"sharp": "0.35.4",
|
|
25
29
|
"@modelcontextprotocol/client": "2.0.0",
|
|
26
30
|
"koffi": "3.2.1",
|
|
27
31
|
"@earendil-works/pi-ai": "1.0.0"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
34
|
+
"@laohuang/codemode": "0.0.0",
|
|
35
|
+
"@laohuang/tool-codemode": "0.0.0",
|
|
30
36
|
"@laohuang/attachment": "0.0.0",
|
|
31
37
|
"@laohuang/attachment-local": "0.0.0",
|
|
32
38
|
"@laohuang/skill": "0.0.0",
|