cvm-server 0.10.0 → 0.11.0
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/main.cjs +550 -432
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
3
3
|
const stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
4
4
|
const zod = require("zod");
|
|
5
5
|
const i$2 = require("typescript");
|
|
6
|
-
const M$
|
|
7
|
-
const
|
|
6
|
+
const M$1 = require("fs");
|
|
7
|
+
const r = require("path");
|
|
8
8
|
const mongodb = require("mongodb");
|
|
9
9
|
const promises = require("fs/promises");
|
|
10
10
|
const dotenv = require("dotenv");
|
|
@@ -27,8 +27,8 @@ function _interopNamespaceDefault(e2) {
|
|
|
27
27
|
return Object.freeze(n2);
|
|
28
28
|
}
|
|
29
29
|
const i__namespace = /* @__PURE__ */ _interopNamespaceDefault(i$2);
|
|
30
|
-
const M__namespace = /* @__PURE__ */ _interopNamespaceDefault(M$
|
|
31
|
-
const
|
|
30
|
+
const M__namespace = /* @__PURE__ */ _interopNamespaceDefault(M$1);
|
|
31
|
+
const r__namespace = /* @__PURE__ */ _interopNamespaceDefault(r);
|
|
32
32
|
const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
|
|
33
33
|
var f$1 = Object.defineProperty;
|
|
34
34
|
var p$1 = (e2, t2, s2) => t2 in e2 ? f$1(e2, t2, { enumerable: true, configurable: true, writable: true, value: s2 }) : e2[t2] = s2;
|
|
@@ -36,7 +36,7 @@ var T$1 = (e2, t2, s2) => p$1(e2, typeof t2 != "symbol" ? t2 + "" : t2, s2);
|
|
|
36
36
|
var n$1 = /* @__PURE__ */ ((e2) => (e2.PUSH = "PUSH", e2.PUSH_UNDEFINED = "PUSH_UNDEFINED", e2.POP = "POP", e2.LOAD = "LOAD", e2.STORE = "STORE", e2.CONCAT = "CONCAT", e2.ARRAY_NEW = "ARRAY_NEW", e2.ARRAY_PUSH = "ARRAY_PUSH", e2.ARRAY_GET = "ARRAY_GET", e2.ARRAY_SET = "ARRAY_SET", e2.ARRAY_LEN = "ARRAY_LEN", e2.STRING_LEN = "STRING_LEN", e2.STRING_SUBSTRING = "STRING_SUBSTRING", e2.STRING_INDEXOF = "STRING_INDEXOF", e2.STRING_SPLIT = "STRING_SPLIT", e2.STRING_SLICE = "STRING_SLICE", e2.STRING_CHARAT = "STRING_CHARAT", e2.STRING_TOUPPERCASE = "STRING_TOUPPERCASE", e2.STRING_TOLOWERCASE = "STRING_TOLOWERCASE", e2.LENGTH = "LENGTH", e2.TO_STRING = "TO_STRING", e2.JSON_PARSE = "JSON_PARSE", e2.TYPEOF = "TYPEOF", e2.ADD = "ADD", e2.SUB = "SUB", e2.MUL = "MUL", e2.DIV = "DIV", e2.MOD = "MOD", e2.UNARY_MINUS = "UNARY_MINUS", e2.UNARY_PLUS = "UNARY_PLUS", e2.INC = "INC", e2.DEC = "DEC", e2.EQ = "EQ", e2.NEQ = "NEQ", e2.LT = "LT", e2.GT = "GT", e2.LTE = "LTE", e2.GTE = "GTE", e2.EQ_STRICT = "EQ_STRICT", e2.NEQ_STRICT = "NEQ_STRICT", e2.JUMP = "JUMP", e2.JUMP_IF = "JUMP_IF", e2.JUMP_IF_FALSE = "JUMP_IF_FALSE", e2.JUMP_IF_TRUE = "JUMP_IF_TRUE", e2.CALL = "CALL", e2.RETURN = "RETURN", e2.AND = "AND", e2.OR = "OR", e2.NOT = "NOT", e2.BREAK = "BREAK", e2.CONTINUE = "CONTINUE", e2.ITER_START = "ITER_START", e2.ITER_NEXT = "ITER_NEXT", e2.ITER_END = "ITER_END", e2.FS_LIST_FILES = "FS_LIST_FILES", e2.OBJECT_CREATE = "OBJECT_CREATE", e2.PROPERTY_GET = "PROPERTY_GET", e2.PROPERTY_SET = "PROPERTY_SET", e2.JSON_STRINGIFY = "JSON_STRINGIFY", e2.CC = "CC", e2.PRINT = "PRINT", e2.HALT = "HALT", e2))(n$1 || {});
|
|
37
37
|
function R(e2) {
|
|
38
38
|
const t2 = [], s2 = [];
|
|
39
|
-
let
|
|
39
|
+
let r2 = false;
|
|
40
40
|
const a2 = i__namespace.createSourceFile(
|
|
41
41
|
"program.ts",
|
|
42
42
|
e2,
|
|
@@ -44,16 +44,16 @@ function R(e2) {
|
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
46
|
function S(c2) {
|
|
47
|
-
if (i__namespace.isFunctionDeclaration(c2) && c2.name && c2.name.text === "main" && (
|
|
47
|
+
if (i__namespace.isFunctionDeclaration(c2) && c2.name && c2.name.text === "main" && (r2 = true, c2.parameters.length > 0 && t2.push("main() must not have parameters")), i__namespace.isCallExpression(c2) && i__namespace.isIdentifier(c2.expression)) {
|
|
48
48
|
const o2 = c2.expression.text;
|
|
49
49
|
["setTimeout", "fetch", "require", "import"].includes(o2) && t2.push(`Unsupported function: ${o2}`);
|
|
50
50
|
}
|
|
51
51
|
i__namespace.forEachChild(c2, S);
|
|
52
52
|
}
|
|
53
|
-
return S(a2),
|
|
53
|
+
return S(a2), r2 || t2.push("Program must have a main() function"), t2.length === 0 && s2.push({ op: n$1.HALT }), {
|
|
54
54
|
bytecode: s2,
|
|
55
55
|
errors: t2,
|
|
56
|
-
hasMain:
|
|
56
|
+
hasMain: r2
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
let A$1 = class A {
|
|
@@ -65,8 +65,8 @@ let A$1 = class A {
|
|
|
65
65
|
* Emit an instruction and return its index
|
|
66
66
|
*/
|
|
67
67
|
emit(t2, s2) {
|
|
68
|
-
const
|
|
69
|
-
return this.bytecode.push({ op: t2, arg: s2 }),
|
|
68
|
+
const r2 = this.bytecode.length;
|
|
69
|
+
return this.bytecode.push({ op: t2, arg: s2 }), r2;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Get the current address (next instruction index)
|
|
@@ -84,7 +84,7 @@ let A$1 = class A {
|
|
|
84
84
|
* Patch multiple jump instructions with the same target
|
|
85
85
|
*/
|
|
86
86
|
patchJumps(t2, s2) {
|
|
87
|
-
t2.forEach((
|
|
87
|
+
t2.forEach((r2) => this.patchJump(r2, s2));
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Push a new jump context onto the stack
|
|
@@ -134,24 +134,24 @@ let A$1 = class A {
|
|
|
134
134
|
return [...this.contextStack];
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
-
const P$1 = (e2, t2, { compileExpression: s2, compileStatement:
|
|
137
|
+
const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
138
138
|
s2(e2.expression);
|
|
139
139
|
const a2 = t2.emit(n$1.JUMP_IF_FALSE, -1), S = {
|
|
140
140
|
type: "if",
|
|
141
141
|
endTargets: []
|
|
142
142
|
};
|
|
143
|
-
if (e2.elseStatement ? S.elseTarget = a2 : S.endTargets.push(a2), t2.pushContext(S),
|
|
143
|
+
if (e2.elseStatement ? S.elseTarget = a2 : S.endTargets.push(a2), t2.pushContext(S), r2(e2.thenStatement), e2.elseStatement) {
|
|
144
144
|
const o2 = t2.emit(n$1.JUMP, -1);
|
|
145
145
|
S.endTargets.push(o2);
|
|
146
146
|
const m2 = t2.currentAddress();
|
|
147
|
-
t2.patchJump(a2, m2),
|
|
147
|
+
t2.patchJump(a2, m2), r2(e2.elseStatement);
|
|
148
148
|
}
|
|
149
149
|
const c2 = t2.popContext();
|
|
150
150
|
if (c2) {
|
|
151
151
|
const o2 = t2.currentAddress();
|
|
152
152
|
t2.patchJumps(c2.endTargets, o2);
|
|
153
153
|
}
|
|
154
|
-
}, I = (e2, t2, { compileExpression: s2, compileStatement:
|
|
154
|
+
}, I = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
155
155
|
const a2 = t2.currentAddress();
|
|
156
156
|
s2(e2.expression);
|
|
157
157
|
const c2 = {
|
|
@@ -161,13 +161,13 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
161
161
|
endTargets: [],
|
|
162
162
|
startAddress: a2
|
|
163
163
|
};
|
|
164
|
-
t2.pushContext(c2),
|
|
164
|
+
t2.pushContext(c2), r2(e2.statement), t2.emit(n$1.JUMP, a2);
|
|
165
165
|
const o2 = t2.popContext();
|
|
166
166
|
if (o2) {
|
|
167
167
|
const m2 = t2.currentAddress();
|
|
168
168
|
t2.patchJumps(o2.breakTargets || [], m2);
|
|
169
169
|
}
|
|
170
|
-
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement:
|
|
170
|
+
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
171
171
|
const a2 = e2.initializer, S = e2.expression;
|
|
172
172
|
let c2;
|
|
173
173
|
if (i__namespace.isVariableDeclarationList(a2))
|
|
@@ -189,28 +189,28 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
189
189
|
startAddress: o2,
|
|
190
190
|
iterVariable: c2
|
|
191
191
|
};
|
|
192
|
-
t2.pushContext(l2),
|
|
192
|
+
t2.pushContext(l2), r2(e2.statement), t2.emit(n$1.JUMP, o2);
|
|
193
193
|
const u2 = t2.popContext();
|
|
194
194
|
if (u2) {
|
|
195
|
-
const
|
|
196
|
-
t2.patchJumps(u2.breakTargets || [],
|
|
195
|
+
const E = t2.currentAddress();
|
|
196
|
+
t2.patchJumps(u2.breakTargets || [], E), t2.emit(n$1.ITER_END);
|
|
197
197
|
}
|
|
198
198
|
}, y$1 = (e2, t2, { compileStatement: s2 }) => {
|
|
199
|
-
e2.statements.forEach((
|
|
200
|
-
s2(
|
|
199
|
+
e2.statements.forEach((r2) => {
|
|
200
|
+
s2(r2);
|
|
201
201
|
});
|
|
202
|
-
}, N
|
|
203
|
-
const
|
|
204
|
-
|
|
202
|
+
}, N = (e2, t2, { compileExpression: s2 }) => {
|
|
203
|
+
const r2 = e2.declarationList.declarations[0];
|
|
204
|
+
r2.initializer && (s2(r2.initializer), t2.emit(n$1.STORE, r2.name.getText()));
|
|
205
205
|
}, _$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
206
|
-
const
|
|
207
|
-
if (i__namespace.isBinaryExpression(
|
|
208
|
-
const a2 =
|
|
206
|
+
const r2 = e2.expression;
|
|
207
|
+
if (i__namespace.isBinaryExpression(r2)) {
|
|
208
|
+
const a2 = r2.operatorToken.kind;
|
|
209
209
|
if (a2 === i__namespace.SyntaxKind.PlusEqualsToken || a2 === i__namespace.SyntaxKind.MinusEqualsToken || a2 === i__namespace.SyntaxKind.AsteriskEqualsToken || a2 === i__namespace.SyntaxKind.SlashEqualsToken || a2 === i__namespace.SyntaxKind.PercentEqualsToken) {
|
|
210
|
-
if (i__namespace.isIdentifier(
|
|
211
|
-
switch (t2.emit(n$1.LOAD,
|
|
210
|
+
if (i__namespace.isIdentifier(r2.left)) {
|
|
211
|
+
switch (t2.emit(n$1.LOAD, r2.left.text), s2(r2.right), a2) {
|
|
212
212
|
case i__namespace.SyntaxKind.PlusEqualsToken:
|
|
213
|
-
i__namespace.isStringLiteral(
|
|
213
|
+
i__namespace.isStringLiteral(r2.right) ? t2.emit(n$1.CONCAT) : t2.emit(n$1.ADD);
|
|
214
214
|
break;
|
|
215
215
|
case i__namespace.SyntaxKind.MinusEqualsToken:
|
|
216
216
|
t2.emit(n$1.SUB);
|
|
@@ -225,41 +225,41 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
225
225
|
t2.emit(n$1.MOD);
|
|
226
226
|
break;
|
|
227
227
|
}
|
|
228
|
-
t2.emit(n$1.STORE,
|
|
229
|
-
} else if (i__namespace.isElementAccessExpression(
|
|
228
|
+
t2.emit(n$1.STORE, r2.left.text);
|
|
229
|
+
} else if (i__namespace.isElementAccessExpression(r2.left))
|
|
230
230
|
throw new Error("Compound assignment to array elements not yet supported");
|
|
231
231
|
return;
|
|
232
232
|
} else if (a2 === i__namespace.SyntaxKind.EqualsToken) {
|
|
233
|
-
if (s2(
|
|
234
|
-
t2.emit(n$1.STORE,
|
|
235
|
-
else if (i__namespace.isElementAccessExpression(
|
|
233
|
+
if (s2(r2.right), i__namespace.isIdentifier(r2.left))
|
|
234
|
+
t2.emit(n$1.STORE, r2.left.text);
|
|
235
|
+
else if (i__namespace.isElementAccessExpression(r2.left)) {
|
|
236
236
|
const S = `__temp_${t2.getBytecode().length}`;
|
|
237
|
-
t2.emit(n$1.STORE, S), s2(
|
|
238
|
-
} else if (i__namespace.isPropertyAccessExpression(
|
|
237
|
+
t2.emit(n$1.STORE, S), s2(r2.left.expression), s2(r2.left.argumentExpression), t2.emit(n$1.LOAD, S), t2.emit(n$1.ARRAY_SET), t2.emit(n$1.POP);
|
|
238
|
+
} else if (i__namespace.isPropertyAccessExpression(r2.left)) {
|
|
239
239
|
const S = `__temp_${t2.getBytecode().length}`;
|
|
240
|
-
t2.emit(n$1.STORE, S), s2(
|
|
240
|
+
t2.emit(n$1.STORE, S), s2(r2.left.expression), t2.emit(n$1.PUSH, r2.left.name.text), t2.emit(n$1.LOAD, S), t2.emit(n$1.PROPERTY_SET), t2.emit(n$1.POP);
|
|
241
241
|
}
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
i__namespace.isCallExpression(
|
|
245
|
+
i__namespace.isCallExpression(r2) && i__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.expression.getText() === "console" && r2.expression.name.getText() === "log" ? (r2.arguments.forEach((a2) => {
|
|
246
246
|
s2(a2);
|
|
247
|
-
}), t2.emit(n$1.PRINT)) : i__namespace.isCallExpression(
|
|
248
|
-
}, g$
|
|
247
|
+
}), t2.emit(n$1.PRINT)) : i__namespace.isCallExpression(r2) && i__namespace.isIdentifier(r2.expression) && r2.expression.text === "CC" ? (r2.arguments.length > 0 && s2(r2.arguments[0]), t2.emit(n$1.CC), t2.emit(n$1.POP)) : i__namespace.isCallExpression(r2) && i__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.name.getText() === "push" ? (s2(r2.expression.expression), r2.arguments.length > 0 && s2(r2.arguments[0]), t2.emit(n$1.ARRAY_PUSH)) : (i__namespace.isPostfixUnaryExpression(r2) || i__namespace.isPrefixUnaryExpression(r2)) && (s2(r2), t2.emit(n$1.POP));
|
|
248
|
+
}, g$2 = (e2, t2, { compileExpression: s2 }) => {
|
|
249
249
|
e2.expression ? s2(e2.expression) : t2.emit(n$1.PUSH, null), t2.emit(n$1.RETURN);
|
|
250
250
|
}, k = (e2, t2, s2) => {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
253
|
-
|
|
251
|
+
const r2 = t2.findLoopContext();
|
|
252
|
+
if (r2) {
|
|
253
|
+
r2.type === "foreach" && t2.emit(n$1.ITER_END);
|
|
254
254
|
const a2 = t2.emit(n$1.BREAK, -1);
|
|
255
|
-
|
|
255
|
+
r2.breakTargets = r2.breakTargets || [], r2.breakTargets.push(a2);
|
|
256
256
|
} else
|
|
257
257
|
throw new Error("break statement not in loop");
|
|
258
258
|
}, U = (e2, t2, s2) => {
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
261
|
-
const a2 = t2.emit(n$1.CONTINUE,
|
|
262
|
-
|
|
259
|
+
const r2 = t2.findLoopContext();
|
|
260
|
+
if (r2 && r2.startAddress !== void 0) {
|
|
261
|
+
const a2 = t2.emit(n$1.CONTINUE, r2.startAddress);
|
|
262
|
+
r2.continueTargets = r2.continueTargets || [], r2.continueTargets.push(a2);
|
|
263
263
|
} else
|
|
264
264
|
throw new Error("continue statement not in loop");
|
|
265
265
|
}, L$1 = {
|
|
@@ -267,16 +267,16 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
267
267
|
[i__namespace.SyntaxKind.WhileStatement]: I,
|
|
268
268
|
[i__namespace.SyntaxKind.ForOfStatement]: h$2,
|
|
269
269
|
[i__namespace.SyntaxKind.Block]: y$1,
|
|
270
|
-
[i__namespace.SyntaxKind.VariableStatement]: N
|
|
270
|
+
[i__namespace.SyntaxKind.VariableStatement]: N,
|
|
271
271
|
[i__namespace.SyntaxKind.ExpressionStatement]: _$1,
|
|
272
|
-
[i__namespace.SyntaxKind.ReturnStatement]: g$
|
|
272
|
+
[i__namespace.SyntaxKind.ReturnStatement]: g$2,
|
|
273
273
|
[i__namespace.SyntaxKind.BreakStatement]: k,
|
|
274
274
|
[i__namespace.SyntaxKind.ContinueStatement]: U
|
|
275
275
|
}, K = (e2, t2, s2) => {
|
|
276
276
|
t2.emit(n$1.PUSH, e2.text);
|
|
277
277
|
}, d$1 = (e2, t2, s2) => {
|
|
278
278
|
t2.emit(n$1.PUSH, Number(e2.text));
|
|
279
|
-
}, b$
|
|
279
|
+
}, b$1 = (e2, t2, s2) => {
|
|
280
280
|
t2.emit(n$1.PUSH, true);
|
|
281
281
|
}, F$1 = (e2, t2, s2) => {
|
|
282
282
|
t2.emit(n$1.PUSH, false);
|
|
@@ -285,16 +285,16 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
285
285
|
}, D$1 = (e2, t2, s2) => {
|
|
286
286
|
e2.text === "undefined" ? t2.emit(n$1.PUSH_UNDEFINED) : t2.emit(n$1.LOAD, e2.text);
|
|
287
287
|
}, H$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
288
|
-
t2.emit(n$1.ARRAY_NEW), e2.elements.forEach((
|
|
289
|
-
s2(
|
|
288
|
+
t2.emit(n$1.ARRAY_NEW), e2.elements.forEach((r2) => {
|
|
289
|
+
s2(r2), t2.emit(n$1.ARRAY_PUSH);
|
|
290
290
|
});
|
|
291
|
-
}, M
|
|
291
|
+
}, M = (e2, t2, { compileExpression: s2 }) => {
|
|
292
292
|
s2(e2.expression);
|
|
293
293
|
}, J$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
294
294
|
e2.name.text === "length" ? (s2(e2.expression), t2.emit(n$1.LENGTH)) : (s2(e2.expression), t2.emit(n$1.PUSH, e2.name.text), t2.emit(n$1.PROPERTY_GET));
|
|
295
|
-
}, Y$1 = (e2, t2, { compileExpression: s2, reportError:
|
|
296
|
-
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) :
|
|
297
|
-
}, C = (e2, t2, { compileExpression: s2 }) => {
|
|
295
|
+
}, Y$1 = (e2, t2, { compileExpression: s2, reportError: r2 }) => {
|
|
296
|
+
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) : r2(e2, "Element access requires an index expression"), t2.emit(n$1.ARRAY_GET);
|
|
297
|
+
}, C$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
298
298
|
switch (e2.operator) {
|
|
299
299
|
case i__namespace.SyntaxKind.ExclamationToken:
|
|
300
300
|
s2(e2.operand), t2.emit(n$1.NOT);
|
|
@@ -322,14 +322,14 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
|
322
322
|
break;
|
|
323
323
|
}
|
|
324
324
|
};
|
|
325
|
-
function x$
|
|
326
|
-
return !!(i__namespace.isStringLiteral(e2) || i__namespace.isStringLiteral(t2) || i__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$
|
|
325
|
+
function x$2(e2, t2) {
|
|
326
|
+
return !!(i__namespace.isStringLiteral(e2) || i__namespace.isStringLiteral(t2) || i__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$2(e2.left, e2.right) || i__namespace.isBinaryExpression(t2) && t2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$2(t2.left, t2.right));
|
|
327
327
|
}
|
|
328
328
|
const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
329
|
-
const
|
|
330
|
-
switch (s2(e2.left), s2(e2.right),
|
|
329
|
+
const r2 = e2.operatorToken.kind;
|
|
330
|
+
switch (s2(e2.left), s2(e2.right), r2) {
|
|
331
331
|
case i__namespace.SyntaxKind.PlusToken:
|
|
332
|
-
x$
|
|
332
|
+
x$2(e2.left, e2.right) ? t2.emit(n$1.CONCAT) : t2.emit(n$1.ADD);
|
|
333
333
|
break;
|
|
334
334
|
case i__namespace.SyntaxKind.MinusToken:
|
|
335
335
|
t2.emit(n$1.SUB);
|
|
@@ -376,10 +376,10 @@ const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
|
376
376
|
}
|
|
377
377
|
}, q$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
378
378
|
s2(e2.condition);
|
|
379
|
-
const
|
|
379
|
+
const r2 = t2.emit(n$1.JUMP_IF_FALSE, -1);
|
|
380
380
|
s2(e2.whenTrue);
|
|
381
381
|
const a2 = t2.emit(n$1.JUMP, -1), S = t2.currentAddress();
|
|
382
|
-
t2.patchJump(
|
|
382
|
+
t2.patchJump(r2, S), s2(e2.whenFalse);
|
|
383
383
|
const c2 = t2.currentAddress();
|
|
384
384
|
t2.patchJump(a2, c2);
|
|
385
385
|
}, O = (e2, t2, { compileExpression: s2 }) => {
|
|
@@ -394,61 +394,61 @@ const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
|
394
394
|
else if (i__namespace.isIdentifier(e2.expression) && e2.expression.text === "CC")
|
|
395
395
|
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(n$1.CC);
|
|
396
396
|
else if (i__namespace.isPropertyAccessExpression(e2.expression)) {
|
|
397
|
-
const
|
|
398
|
-
if (
|
|
397
|
+
const r2 = e2.expression.name.text;
|
|
398
|
+
if (r2 === "substring")
|
|
399
399
|
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(n$1.STRING_SUBSTRING);
|
|
400
|
-
else if (
|
|
400
|
+
else if (r2 === "indexOf")
|
|
401
401
|
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, ""), t2.emit(n$1.STRING_INDEXOF);
|
|
402
|
-
else if (
|
|
402
|
+
else if (r2 === "split")
|
|
403
403
|
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, ""), t2.emit(n$1.STRING_SPLIT);
|
|
404
|
-
else if (
|
|
404
|
+
else if (r2 === "slice")
|
|
405
405
|
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(n$1.STRING_SLICE);
|
|
406
|
-
else if (
|
|
406
|
+
else if (r2 === "charAt")
|
|
407
407
|
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), t2.emit(n$1.STRING_CHARAT);
|
|
408
|
-
else if (
|
|
408
|
+
else if (r2 === "toUpperCase")
|
|
409
409
|
s2(e2.expression.expression), t2.emit(n$1.STRING_TOUPPERCASE);
|
|
410
|
-
else if (
|
|
410
|
+
else if (r2 === "toLowerCase")
|
|
411
411
|
s2(e2.expression.expression), t2.emit(n$1.STRING_TOLOWERCASE);
|
|
412
|
-
else if (
|
|
412
|
+
else if (r2 === "toString")
|
|
413
413
|
s2(e2.expression.expression), t2.emit(n$1.TO_STRING);
|
|
414
414
|
else
|
|
415
|
-
throw new Error(`Method call '${
|
|
415
|
+
throw new Error(`Method call '${r2}' is not supported`);
|
|
416
416
|
} else
|
|
417
417
|
throw new Error("Unsupported call expression");
|
|
418
418
|
}, Q = (e2, t2, { compileExpression: s2 }) => {
|
|
419
419
|
t2.emit(n$1.OBJECT_CREATE);
|
|
420
|
-
for (const
|
|
421
|
-
if (i__namespace.isPropertyAssignment(
|
|
420
|
+
for (const r2 of e2.properties)
|
|
421
|
+
if (i__namespace.isPropertyAssignment(r2)) {
|
|
422
422
|
let a2;
|
|
423
|
-
if (i__namespace.isIdentifier(
|
|
424
|
-
a2 =
|
|
425
|
-
else if (i__namespace.isStringLiteral(
|
|
426
|
-
a2 =
|
|
423
|
+
if (i__namespace.isIdentifier(r2.name))
|
|
424
|
+
a2 = r2.name.text;
|
|
425
|
+
else if (i__namespace.isStringLiteral(r2.name))
|
|
426
|
+
a2 = r2.name.text;
|
|
427
427
|
else
|
|
428
428
|
throw new Error("Computed property names are not supported");
|
|
429
|
-
t2.emit(n$1.PUSH, a2), s2(
|
|
430
|
-
} else if (i__namespace.isShorthandPropertyAssignment(
|
|
431
|
-
const a2 =
|
|
429
|
+
t2.emit(n$1.PUSH, a2), s2(r2.initializer), t2.emit(n$1.PROPERTY_SET);
|
|
430
|
+
} else if (i__namespace.isShorthandPropertyAssignment(r2)) {
|
|
431
|
+
const a2 = r2.name.text;
|
|
432
432
|
t2.emit(n$1.PUSH, a2), t2.emit(n$1.LOAD, a2), t2.emit(n$1.PROPERTY_SET);
|
|
433
433
|
} else
|
|
434
434
|
throw new Error("Unsupported property type in object literal");
|
|
435
435
|
}, j$2 = {
|
|
436
436
|
[i__namespace.SyntaxKind.StringLiteral]: K,
|
|
437
437
|
[i__namespace.SyntaxKind.NumericLiteral]: d$1,
|
|
438
|
-
[i__namespace.SyntaxKind.TrueKeyword]: b$
|
|
438
|
+
[i__namespace.SyntaxKind.TrueKeyword]: b$1,
|
|
439
439
|
[i__namespace.SyntaxKind.FalseKeyword]: F$1,
|
|
440
440
|
[i__namespace.SyntaxKind.NullKeyword]: G$1,
|
|
441
441
|
[i__namespace.SyntaxKind.Identifier]: D$1,
|
|
442
442
|
[i__namespace.SyntaxKind.ArrayLiteralExpression]: H$1,
|
|
443
443
|
[i__namespace.SyntaxKind.BinaryExpression]: B$1,
|
|
444
|
-
[i__namespace.SyntaxKind.PrefixUnaryExpression]: C,
|
|
444
|
+
[i__namespace.SyntaxKind.PrefixUnaryExpression]: C$1,
|
|
445
445
|
[i__namespace.SyntaxKind.PostfixUnaryExpression]: w$1,
|
|
446
446
|
[i__namespace.SyntaxKind.CallExpression]: V$1,
|
|
447
447
|
[i__namespace.SyntaxKind.PropertyAccessExpression]: J$1,
|
|
448
448
|
[i__namespace.SyntaxKind.ElementAccessExpression]: Y$1,
|
|
449
449
|
[i__namespace.SyntaxKind.ConditionalExpression]: q$1,
|
|
450
450
|
[i__namespace.SyntaxKind.TypeOfExpression]: O,
|
|
451
|
-
[i__namespace.SyntaxKind.ParenthesizedExpression]: M
|
|
451
|
+
[i__namespace.SyntaxKind.ParenthesizedExpression]: M,
|
|
452
452
|
[i__namespace.SyntaxKind.ObjectLiteralExpression]: Q
|
|
453
453
|
};
|
|
454
454
|
function W$1(e2) {
|
|
@@ -459,7 +459,7 @@ function W$1(e2) {
|
|
|
459
459
|
bytecode: [],
|
|
460
460
|
errors: t2.errors
|
|
461
461
|
};
|
|
462
|
-
const s2 = new A$1(),
|
|
462
|
+
const s2 = new A$1(), r2 = i__namespace.createSourceFile("program.ts", e2, i__namespace.ScriptTarget.Latest, true), a2 = {
|
|
463
463
|
compileStatement: S,
|
|
464
464
|
compileExpression: c2,
|
|
465
465
|
reportError: (o2, m2) => {
|
|
@@ -474,7 +474,7 @@ function W$1(e2) {
|
|
|
474
474
|
const m2 = j$2[o2.kind];
|
|
475
475
|
m2 && m2(o2, s2, a2);
|
|
476
476
|
}
|
|
477
|
-
return
|
|
477
|
+
return r2.forEachChild((o2) => {
|
|
478
478
|
var m2;
|
|
479
479
|
i__namespace.isFunctionDeclaration(o2) && ((m2 = o2.name) == null ? void 0 : m2.text) === "main" && o2.body && o2.body.statements.forEach((l2) => {
|
|
480
480
|
S(l2);
|
|
@@ -485,55 +485,55 @@ function W$1(e2) {
|
|
|
485
485
|
errors: []
|
|
486
486
|
};
|
|
487
487
|
}
|
|
488
|
-
function n(
|
|
489
|
-
return typeof
|
|
488
|
+
function n(r2) {
|
|
489
|
+
return typeof r2 == "string";
|
|
490
490
|
}
|
|
491
|
-
function t(
|
|
492
|
-
return typeof
|
|
491
|
+
function t(r2) {
|
|
492
|
+
return typeof r2 == "number";
|
|
493
493
|
}
|
|
494
|
-
function i$1(
|
|
495
|
-
return typeof
|
|
494
|
+
function i$1(r2) {
|
|
495
|
+
return typeof r2 == "boolean";
|
|
496
496
|
}
|
|
497
|
-
function e(
|
|
498
|
-
return
|
|
497
|
+
function e(r2) {
|
|
498
|
+
return r2 === null;
|
|
499
499
|
}
|
|
500
|
-
function f(
|
|
501
|
-
return
|
|
500
|
+
function f(r2) {
|
|
501
|
+
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "array";
|
|
502
502
|
}
|
|
503
|
-
function o(
|
|
504
|
-
return
|
|
503
|
+
function o(r2) {
|
|
504
|
+
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "undefined";
|
|
505
505
|
}
|
|
506
|
-
function c(
|
|
507
|
-
return
|
|
506
|
+
function c(r2) {
|
|
507
|
+
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "object";
|
|
508
508
|
}
|
|
509
|
-
function y(
|
|
510
|
-
return n(
|
|
509
|
+
function y(r2) {
|
|
510
|
+
return n(r2) ? r2 : t(r2) || i$1(r2) ? r2.toString() : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? `[array:${r2.elements.length}]` : c(r2) ? "[object Object]" : String(r2);
|
|
511
511
|
}
|
|
512
|
-
function b
|
|
513
|
-
return i$1(
|
|
512
|
+
function b(r2) {
|
|
513
|
+
return i$1(r2) ? r2 : e(r2) || o(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : f(r2) || c(r2) ? true : !!r2;
|
|
514
514
|
}
|
|
515
|
-
function p(
|
|
516
|
-
return n(
|
|
515
|
+
function p(r2) {
|
|
516
|
+
return n(r2) ? "string" : t(r2) ? "number" : i$1(r2) ? "boolean" : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? "array" : c(r2) ? "object" : "unknown";
|
|
517
517
|
}
|
|
518
|
-
function m(
|
|
519
|
-
if (t(
|
|
520
|
-
if (i$1(
|
|
521
|
-
if (e(
|
|
522
|
-
if (o(
|
|
523
|
-
if (n(
|
|
524
|
-
const u2 =
|
|
518
|
+
function m(r2) {
|
|
519
|
+
if (t(r2)) return r2;
|
|
520
|
+
if (i$1(r2)) return r2 ? 1 : 0;
|
|
521
|
+
if (e(r2)) return 0;
|
|
522
|
+
if (o(r2)) return NaN;
|
|
523
|
+
if (n(r2)) {
|
|
524
|
+
const u2 = r2.trim();
|
|
525
525
|
return u2 === "" ? 0 : Number(u2);
|
|
526
526
|
}
|
|
527
|
-
return f(
|
|
527
|
+
return f(r2) ? NaN : Number(r2);
|
|
528
528
|
}
|
|
529
|
-
function d(
|
|
530
|
-
return { type: "array", elements:
|
|
529
|
+
function d(r2 = []) {
|
|
530
|
+
return { type: "array", elements: r2 };
|
|
531
531
|
}
|
|
532
532
|
function s() {
|
|
533
533
|
return { type: "undefined" };
|
|
534
534
|
}
|
|
535
|
-
function j$1(
|
|
536
|
-
return { type: "object", properties:
|
|
535
|
+
function j$1(r2 = {}) {
|
|
536
|
+
return { type: "object", properties: r2 };
|
|
537
537
|
}
|
|
538
538
|
var l = Object.defineProperty;
|
|
539
539
|
var u$1 = (s2, t2, e2) => t2 in s2 ? l(s2, t2, { enumerable: true, configurable: true, writable: true, value: e2 }) : s2[t2] = e2;
|
|
@@ -544,13 +544,13 @@ let h$1 = class h {
|
|
|
544
544
|
a(this, "programsDir");
|
|
545
545
|
a(this, "executionsDir");
|
|
546
546
|
a(this, "outputsDir");
|
|
547
|
-
this.dataDir = t2, this.programsDir =
|
|
547
|
+
this.dataDir = t2, this.programsDir = r__namespace.join(t2, "programs"), this.executionsDir = r__namespace.join(t2, "executions"), this.outputsDir = r__namespace.join(t2, "outputs");
|
|
548
548
|
}
|
|
549
549
|
get metadataFile() {
|
|
550
|
-
return
|
|
550
|
+
return r__namespace.join(this.dataDir, "metadata.json");
|
|
551
551
|
}
|
|
552
552
|
async connect() {
|
|
553
|
-
await M$
|
|
553
|
+
await M$1.promises.mkdir(this.dataDir, { recursive: true }), await M$1.promises.mkdir(this.programsDir, { recursive: true }), await M$1.promises.mkdir(this.executionsDir, { recursive: true }), await M$1.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
|
|
554
554
|
}
|
|
555
555
|
async disconnect() {
|
|
556
556
|
this.connected = false;
|
|
@@ -560,14 +560,14 @@ let h$1 = class h {
|
|
|
560
560
|
}
|
|
561
561
|
async saveProgram(t2) {
|
|
562
562
|
if (!this.connected) throw new Error("Not connected");
|
|
563
|
-
const e2 =
|
|
564
|
-
await M$
|
|
563
|
+
const e2 = r__namespace.join(this.programsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
564
|
+
await M$1.promises.writeFile(e2, n2, "utf-8");
|
|
565
565
|
}
|
|
566
566
|
async getProgram(t2) {
|
|
567
567
|
if (!this.connected) throw new Error("Not connected");
|
|
568
|
-
const e2 =
|
|
568
|
+
const e2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
569
569
|
try {
|
|
570
|
-
const n2 = await M$
|
|
570
|
+
const n2 = await M$1.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
571
571
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
572
572
|
} catch (n2) {
|
|
573
573
|
if (n2.code === "ENOENT")
|
|
@@ -577,14 +577,14 @@ let h$1 = class h {
|
|
|
577
577
|
}
|
|
578
578
|
async saveExecution(t2) {
|
|
579
579
|
if (!this.connected) throw new Error("Not connected");
|
|
580
|
-
const e2 =
|
|
581
|
-
await M$
|
|
580
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
581
|
+
await M$1.promises.writeFile(e2, n2, "utf-8");
|
|
582
582
|
}
|
|
583
583
|
async getExecution(t2) {
|
|
584
584
|
if (!this.connected) throw new Error("Not connected");
|
|
585
|
-
const e2 =
|
|
585
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
586
586
|
try {
|
|
587
|
-
const n2 = await M$
|
|
587
|
+
const n2 = await M$1.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
588
588
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
589
589
|
} catch (n2) {
|
|
590
590
|
if (n2.code === "ENOENT")
|
|
@@ -594,16 +594,16 @@ let h$1 = class h {
|
|
|
594
594
|
}
|
|
595
595
|
async appendOutput(t2, e2) {
|
|
596
596
|
if (!this.connected) throw new Error("Not connected");
|
|
597
|
-
const n2 =
|
|
597
|
+
const n2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 = e2.join(`
|
|
598
598
|
`) + `
|
|
599
599
|
`;
|
|
600
|
-
await M$
|
|
600
|
+
await M$1.promises.appendFile(n2, o2, "utf-8");
|
|
601
601
|
}
|
|
602
602
|
async getOutput(t2) {
|
|
603
603
|
if (!this.connected) throw new Error("Not connected");
|
|
604
|
-
const e2 =
|
|
604
|
+
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
605
605
|
try {
|
|
606
|
-
return (await M$
|
|
606
|
+
return (await M$1.promises.readFile(e2, "utf-8")).split(`
|
|
607
607
|
`).filter((o2) => o2.length > 0);
|
|
608
608
|
} catch (n2) {
|
|
609
609
|
if (n2.code === "ENOENT")
|
|
@@ -613,18 +613,18 @@ let h$1 = class h {
|
|
|
613
613
|
}
|
|
614
614
|
async listExecutions() {
|
|
615
615
|
if (!this.connected) throw new Error("Not connected");
|
|
616
|
-
const t2 = await M$
|
|
616
|
+
const t2 = await M$1.promises.readdir(this.executionsDir), e2 = [];
|
|
617
617
|
for (const n2 of t2)
|
|
618
618
|
if (n2.endsWith(".json")) {
|
|
619
|
-
const o2 = n2.slice(0, -5),
|
|
620
|
-
|
|
619
|
+
const o2 = n2.slice(0, -5), c2 = await this.getExecution(o2);
|
|
620
|
+
c2 && e2.push(c2);
|
|
621
621
|
}
|
|
622
622
|
return e2;
|
|
623
623
|
}
|
|
624
624
|
async getCurrentExecutionId() {
|
|
625
625
|
if (!this.connected) throw new Error("Not connected");
|
|
626
626
|
try {
|
|
627
|
-
const t2 = await M$
|
|
627
|
+
const t2 = await M$1.promises.readFile(this.metadataFile, "utf-8");
|
|
628
628
|
return JSON.parse(t2).currentExecutionId || null;
|
|
629
629
|
} catch (t2) {
|
|
630
630
|
if (t2.code === "ENOENT")
|
|
@@ -635,24 +635,43 @@ let h$1 = class h {
|
|
|
635
635
|
async setCurrentExecutionId(t2) {
|
|
636
636
|
if (!this.connected) throw new Error("Not connected");
|
|
637
637
|
const e2 = { currentExecutionId: t2 };
|
|
638
|
-
await M$
|
|
638
|
+
await M$1.promises.writeFile(this.metadataFile, JSON.stringify(e2, null, 2), "utf-8");
|
|
639
639
|
}
|
|
640
640
|
async deleteExecution(t2) {
|
|
641
641
|
if (!this.connected) throw new Error("Not connected");
|
|
642
|
-
const e2 =
|
|
642
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
643
643
|
try {
|
|
644
|
-
await M$
|
|
645
|
-
} catch (
|
|
646
|
-
if (
|
|
644
|
+
await M$1.promises.unlink(e2);
|
|
645
|
+
} catch (c2) {
|
|
646
|
+
if (c2.code !== "ENOENT") throw c2;
|
|
647
647
|
}
|
|
648
|
-
const n2 =
|
|
648
|
+
const n2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
649
649
|
try {
|
|
650
|
-
await M$
|
|
651
|
-
} catch (
|
|
652
|
-
if (
|
|
650
|
+
await M$1.promises.unlink(n2);
|
|
651
|
+
} catch (c2) {
|
|
652
|
+
if (c2.code !== "ENOENT") throw c2;
|
|
653
653
|
}
|
|
654
654
|
await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
655
655
|
}
|
|
656
|
+
async listPrograms() {
|
|
657
|
+
if (!this.connected) throw new Error("Not connected");
|
|
658
|
+
const t2 = await M$1.promises.readdir(this.programsDir), e2 = [];
|
|
659
|
+
for (const n2 of t2)
|
|
660
|
+
if (n2.endsWith(".json")) {
|
|
661
|
+
const o2 = n2.slice(0, -5), c2 = await this.getProgram(o2);
|
|
662
|
+
c2 && e2.push(c2);
|
|
663
|
+
}
|
|
664
|
+
return e2;
|
|
665
|
+
}
|
|
666
|
+
async deleteProgram(t2) {
|
|
667
|
+
if (!this.connected) throw new Error("Not connected");
|
|
668
|
+
const e2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
669
|
+
try {
|
|
670
|
+
await M$1.promises.unlink(e2);
|
|
671
|
+
} catch (n2) {
|
|
672
|
+
if (n2.code !== "ENOENT") throw n2;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
656
675
|
};
|
|
657
676
|
class w {
|
|
658
677
|
constructor(t2) {
|
|
@@ -666,7 +685,7 @@ class w {
|
|
|
666
685
|
await this.client.connect();
|
|
667
686
|
const t2 = ((o2 = this.connectionString.split("/").pop()) == null ? void 0 : o2.split("?")[0]) || "cvm";
|
|
668
687
|
this.db = this.client.db(t2), this.connected = true;
|
|
669
|
-
const n2 = (await this.db.listCollections().toArray()).map((
|
|
688
|
+
const n2 = (await this.db.listCollections().toArray()).map((c2) => c2.name);
|
|
670
689
|
n2.includes("programs") || await this.db.createCollection("programs"), n2.includes("executions") || await this.db.createCollection("executions"), n2.includes("outputs") || await this.db.createCollection("outputs"), n2.includes("metadata") || await this.db.createCollection("metadata");
|
|
671
690
|
}
|
|
672
691
|
async disconnect() {
|
|
@@ -731,8 +750,14 @@ class w {
|
|
|
731
750
|
async deleteExecution(t2) {
|
|
732
751
|
await this.getCollection("executions").deleteOne({ id: t2 }), await this.getCollection("outputs").deleteOne({ executionId: t2 }), await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
733
752
|
}
|
|
753
|
+
async listPrograms() {
|
|
754
|
+
return await this.getCollection("programs").find({}).toArray();
|
|
755
|
+
}
|
|
756
|
+
async deleteProgram(t2) {
|
|
757
|
+
await this.getCollection("programs").deleteOne({ id: t2 });
|
|
758
|
+
}
|
|
734
759
|
}
|
|
735
|
-
class
|
|
760
|
+
let g$1 = class g {
|
|
736
761
|
static create(t2) {
|
|
737
762
|
const e2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
738
763
|
switch (e2) {
|
|
@@ -748,16 +773,16 @@ class E {
|
|
|
748
773
|
throw new Error(`Unsupported storage type: ${e2}`);
|
|
749
774
|
}
|
|
750
775
|
}
|
|
751
|
-
}
|
|
776
|
+
};
|
|
752
777
|
var A2 = Object.defineProperty;
|
|
753
|
-
var
|
|
754
|
-
var h2 = (e2,
|
|
778
|
+
var C = (e2, r2, t2) => r2 in e2 ? A2(e2, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : e2[r2] = t2;
|
|
779
|
+
var h2 = (e2, r2, t2) => C(e2, typeof r2 != "symbol" ? r2 + "" : r2, t2);
|
|
755
780
|
const G = {
|
|
756
781
|
[n$1.ADD]: {
|
|
757
782
|
stackIn: 2,
|
|
758
783
|
stackOut: 1,
|
|
759
784
|
execute: (e2) => {
|
|
760
|
-
const
|
|
785
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
761
786
|
e2.stack.push(s2 + o2);
|
|
762
787
|
}
|
|
763
788
|
},
|
|
@@ -765,7 +790,7 @@ const G = {
|
|
|
765
790
|
stackIn: 2,
|
|
766
791
|
stackOut: 1,
|
|
767
792
|
execute: (e2) => {
|
|
768
|
-
const
|
|
793
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
769
794
|
e2.stack.push(s2 - o2);
|
|
770
795
|
}
|
|
771
796
|
},
|
|
@@ -773,21 +798,21 @@ const G = {
|
|
|
773
798
|
stackIn: 2,
|
|
774
799
|
stackOut: 1,
|
|
775
800
|
execute: (e2) => {
|
|
776
|
-
const
|
|
801
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
777
802
|
e2.stack.push(s2 * o2);
|
|
778
803
|
}
|
|
779
804
|
},
|
|
780
805
|
[n$1.DIV]: {
|
|
781
806
|
stackIn: 2,
|
|
782
807
|
stackOut: 1,
|
|
783
|
-
execute: (e2,
|
|
808
|
+
execute: (e2, r2) => {
|
|
784
809
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = m(s2), n2 = m(t2);
|
|
785
810
|
if (n2 === 0)
|
|
786
811
|
return {
|
|
787
812
|
type: "DivisionByZero",
|
|
788
813
|
message: "Division by zero",
|
|
789
814
|
pc: e2.pc,
|
|
790
|
-
opcode:
|
|
815
|
+
opcode: r2.op
|
|
791
816
|
};
|
|
792
817
|
e2.stack.push(o2 / n2);
|
|
793
818
|
}
|
|
@@ -796,7 +821,7 @@ const G = {
|
|
|
796
821
|
stackIn: 2,
|
|
797
822
|
stackOut: 1,
|
|
798
823
|
execute: (e2) => {
|
|
799
|
-
const
|
|
824
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
800
825
|
e2.stack.push(s2 % o2);
|
|
801
826
|
}
|
|
802
827
|
},
|
|
@@ -804,7 +829,7 @@ const G = {
|
|
|
804
829
|
stackIn: 1,
|
|
805
830
|
stackOut: 1,
|
|
806
831
|
execute: (e2) => {
|
|
807
|
-
const
|
|
832
|
+
const r2 = e2.stack.pop(), t2 = m(r2);
|
|
808
833
|
e2.stack.push(-t2);
|
|
809
834
|
}
|
|
810
835
|
},
|
|
@@ -812,7 +837,7 @@ const G = {
|
|
|
812
837
|
stackIn: 1,
|
|
813
838
|
stackOut: 1,
|
|
814
839
|
execute: (e2) => {
|
|
815
|
-
const
|
|
840
|
+
const r2 = e2.stack.pop(), t2 = m(r2);
|
|
816
841
|
e2.stack.push(t2);
|
|
817
842
|
}
|
|
818
843
|
}
|
|
@@ -820,8 +845,8 @@ const G = {
|
|
|
820
845
|
[n$1.PUSH]: {
|
|
821
846
|
stackIn: 0,
|
|
822
847
|
stackOut: 1,
|
|
823
|
-
execute: (e2,
|
|
824
|
-
e2.stack.push(
|
|
848
|
+
execute: (e2, r2) => {
|
|
849
|
+
e2.stack.push(r2.arg);
|
|
825
850
|
}
|
|
826
851
|
},
|
|
827
852
|
[n$1.PUSH_UNDEFINED]: {
|
|
@@ -843,8 +868,8 @@ const G = {
|
|
|
843
868
|
stackIn: 1,
|
|
844
869
|
stackOut: 0,
|
|
845
870
|
execute: (e2) => {
|
|
846
|
-
const
|
|
847
|
-
|
|
871
|
+
const r2 = e2.stack.pop();
|
|
872
|
+
r2 !== void 0 && e2.output.push(y(r2));
|
|
848
873
|
}
|
|
849
874
|
},
|
|
850
875
|
[n$1.CC]: {
|
|
@@ -852,7 +877,7 @@ const G = {
|
|
|
852
877
|
stackOut: 0,
|
|
853
878
|
controlsPC: true,
|
|
854
879
|
// CC pauses execution
|
|
855
|
-
execute: (e2,
|
|
880
|
+
execute: (e2, r2) => {
|
|
856
881
|
const t2 = e2.stack.pop();
|
|
857
882
|
e2.ccPrompt = y(t2), e2.status = "waiting_cc";
|
|
858
883
|
}
|
|
@@ -870,21 +895,21 @@ const G = {
|
|
|
870
895
|
stackIn: 0,
|
|
871
896
|
stackOut: 0,
|
|
872
897
|
controlsPC: true,
|
|
873
|
-
execute: (e2,
|
|
874
|
-
if (
|
|
898
|
+
execute: (e2, r2) => {
|
|
899
|
+
if (r2.arg === void 0)
|
|
875
900
|
return {
|
|
876
901
|
type: "RuntimeError",
|
|
877
902
|
message: "JUMP requires a target address",
|
|
878
903
|
pc: e2.pc,
|
|
879
|
-
opcode:
|
|
904
|
+
opcode: r2.op
|
|
880
905
|
};
|
|
881
|
-
const t2 =
|
|
906
|
+
const t2 = r2.arg;
|
|
882
907
|
if (t2 < 0)
|
|
883
908
|
return {
|
|
884
909
|
type: "RuntimeError",
|
|
885
910
|
message: `Invalid jump target: ${t2}`,
|
|
886
911
|
pc: e2.pc,
|
|
887
|
-
opcode:
|
|
912
|
+
opcode: r2.op
|
|
888
913
|
};
|
|
889
914
|
e2.pc = t2;
|
|
890
915
|
}
|
|
@@ -893,72 +918,72 @@ const G = {
|
|
|
893
918
|
stackIn: 1,
|
|
894
919
|
stackOut: 0,
|
|
895
920
|
controlsPC: true,
|
|
896
|
-
execute: (e2,
|
|
921
|
+
execute: (e2, r2) => {
|
|
897
922
|
const t2 = e2.stack.pop();
|
|
898
|
-
if (
|
|
923
|
+
if (r2.arg === void 0)
|
|
899
924
|
return {
|
|
900
925
|
type: "RuntimeError",
|
|
901
926
|
message: "JUMP_IF_FALSE requires a target address",
|
|
902
927
|
pc: e2.pc,
|
|
903
|
-
opcode:
|
|
928
|
+
opcode: r2.op
|
|
904
929
|
};
|
|
905
|
-
const s2 =
|
|
930
|
+
const s2 = r2.arg;
|
|
906
931
|
if (s2 < 0)
|
|
907
932
|
return {
|
|
908
933
|
type: "RuntimeError",
|
|
909
934
|
message: `Invalid jump target: ${s2}`,
|
|
910
935
|
pc: e2.pc,
|
|
911
|
-
opcode:
|
|
936
|
+
opcode: r2.op
|
|
912
937
|
};
|
|
913
|
-
b
|
|
938
|
+
b(t2) ? e2.pc++ : e2.pc = s2;
|
|
914
939
|
}
|
|
915
940
|
},
|
|
916
941
|
[n$1.JUMP_IF]: {
|
|
917
942
|
stackIn: 1,
|
|
918
943
|
stackOut: 0,
|
|
919
944
|
controlsPC: true,
|
|
920
|
-
execute: (e2,
|
|
945
|
+
execute: (e2, r2) => {
|
|
921
946
|
const t2 = e2.stack.pop();
|
|
922
|
-
if (
|
|
947
|
+
if (r2.arg === void 0)
|
|
923
948
|
return {
|
|
924
949
|
type: "RuntimeError",
|
|
925
950
|
message: "JUMP_IF requires a target address",
|
|
926
951
|
pc: e2.pc,
|
|
927
|
-
opcode:
|
|
952
|
+
opcode: r2.op
|
|
928
953
|
};
|
|
929
|
-
const s2 =
|
|
954
|
+
const s2 = r2.arg;
|
|
930
955
|
if (s2 < 0)
|
|
931
956
|
return {
|
|
932
957
|
type: "RuntimeError",
|
|
933
958
|
message: `Invalid jump target: ${s2}`,
|
|
934
959
|
pc: e2.pc,
|
|
935
|
-
opcode:
|
|
960
|
+
opcode: r2.op
|
|
936
961
|
};
|
|
937
|
-
b
|
|
962
|
+
b(t2) ? e2.pc = s2 : e2.pc++;
|
|
938
963
|
}
|
|
939
964
|
},
|
|
940
965
|
[n$1.JUMP_IF_TRUE]: {
|
|
941
966
|
stackIn: 1,
|
|
942
967
|
stackOut: 0,
|
|
943
968
|
controlsPC: true,
|
|
944
|
-
execute: (e2,
|
|
969
|
+
execute: (e2, r2) => {
|
|
945
970
|
const t2 = e2.stack.pop();
|
|
946
|
-
if (
|
|
971
|
+
if (r2.arg === void 0)
|
|
947
972
|
return {
|
|
948
973
|
type: "RuntimeError",
|
|
949
974
|
message: "JUMP_IF_TRUE requires a target address",
|
|
950
975
|
pc: e2.pc,
|
|
951
|
-
opcode:
|
|
976
|
+
opcode: r2.op
|
|
952
977
|
};
|
|
953
|
-
const s2 =
|
|
978
|
+
const s2 = r2.arg;
|
|
954
979
|
if (s2 < 0)
|
|
955
980
|
return {
|
|
956
981
|
type: "RuntimeError",
|
|
957
982
|
message: `Invalid jump target: ${s2}`,
|
|
958
983
|
pc: e2.pc,
|
|
959
|
-
opcode:
|
|
984
|
+
opcode: r2.op
|
|
960
985
|
};
|
|
961
|
-
b
|
|
986
|
+
b(t2) ? e2.pc = s2 : e2.pc++;
|
|
962
987
|
}
|
|
963
988
|
},
|
|
964
989
|
[n$1.CALL]: {
|
|
@@ -976,45 +1001,45 @@ const G = {
|
|
|
976
1001
|
[n$1.LOAD]: {
|
|
977
1002
|
stackIn: 0,
|
|
978
1003
|
stackOut: 1,
|
|
979
|
-
execute: (e2,
|
|
980
|
-
const t2 =
|
|
1004
|
+
execute: (e2, r2) => {
|
|
1005
|
+
const t2 = r2.arg;
|
|
981
1006
|
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s());
|
|
982
1007
|
}
|
|
983
1008
|
},
|
|
984
1009
|
[n$1.STORE]: {
|
|
985
1010
|
stackIn: 1,
|
|
986
1011
|
stackOut: 0,
|
|
987
|
-
execute: (e2,
|
|
1012
|
+
execute: (e2, r2) => {
|
|
988
1013
|
const t2 = e2.stack.pop();
|
|
989
|
-
e2.variables.set(
|
|
1014
|
+
e2.variables.set(r2.arg, t2);
|
|
990
1015
|
}
|
|
991
1016
|
}
|
|
992
1017
|
}, D = {
|
|
993
1018
|
[n$1.ITER_START]: {
|
|
994
1019
|
stackIn: 1,
|
|
995
1020
|
stackOut: 0,
|
|
996
|
-
execute: (e2,
|
|
1021
|
+
execute: (e2, r2) => {
|
|
997
1022
|
const t2 = e2.stack.pop();
|
|
998
1023
|
if (t2 == null)
|
|
999
1024
|
return {
|
|
1000
1025
|
type: "TypeError",
|
|
1001
1026
|
message: "TypeError: Cannot iterate over null or undefined",
|
|
1002
1027
|
pc: e2.pc,
|
|
1003
|
-
opcode:
|
|
1028
|
+
opcode: r2.op
|
|
1004
1029
|
};
|
|
1005
1030
|
if (!f(t2))
|
|
1006
1031
|
return {
|
|
1007
1032
|
type: "TypeError",
|
|
1008
1033
|
message: "TypeError: Cannot iterate over non-array value",
|
|
1009
1034
|
pc: e2.pc,
|
|
1010
|
-
opcode:
|
|
1035
|
+
opcode: r2.op
|
|
1011
1036
|
};
|
|
1012
1037
|
if (e2.iterators.length >= 10)
|
|
1013
1038
|
return {
|
|
1014
1039
|
type: "RuntimeError",
|
|
1015
1040
|
message: "RuntimeError: Maximum iterator depth exceeded",
|
|
1016
1041
|
pc: e2.pc,
|
|
1017
|
-
opcode:
|
|
1042
|
+
opcode: r2.op
|
|
1018
1043
|
};
|
|
1019
1044
|
e2.iterators.push({
|
|
1020
1045
|
array: t2,
|
|
@@ -1027,13 +1052,13 @@ const G = {
|
|
|
1027
1052
|
stackIn: 0,
|
|
1028
1053
|
stackOut: 2,
|
|
1029
1054
|
// Pushes element and hasMore flag
|
|
1030
|
-
execute: (e2,
|
|
1055
|
+
execute: (e2, r2) => {
|
|
1031
1056
|
if (e2.iterators.length === 0)
|
|
1032
1057
|
return {
|
|
1033
1058
|
type: "RuntimeError",
|
|
1034
1059
|
message: "ITER_NEXT: No active iterator",
|
|
1035
1060
|
pc: e2.pc,
|
|
1036
|
-
opcode:
|
|
1061
|
+
opcode: r2.op
|
|
1037
1062
|
};
|
|
1038
1063
|
const t2 = e2.iterators[e2.iterators.length - 1];
|
|
1039
1064
|
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s()), e2.stack.push(true), t2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
@@ -1042,19 +1067,19 @@ const G = {
|
|
|
1042
1067
|
[n$1.ITER_END]: {
|
|
1043
1068
|
stackIn: 0,
|
|
1044
1069
|
stackOut: 0,
|
|
1045
|
-
execute: (e2,
|
|
1070
|
+
execute: (e2, r2) => {
|
|
1046
1071
|
if (e2.iterators.length === 0)
|
|
1047
1072
|
return {
|
|
1048
1073
|
type: "RuntimeError",
|
|
1049
1074
|
message: "ITER_END: No active iterator",
|
|
1050
1075
|
pc: e2.pc,
|
|
1051
|
-
opcode:
|
|
1076
|
+
opcode: r2.op
|
|
1052
1077
|
};
|
|
1053
1078
|
e2.iterators.pop();
|
|
1054
1079
|
}
|
|
1055
1080
|
}
|
|
1056
1081
|
};
|
|
1057
|
-
function
|
|
1082
|
+
function g2(e2, r2, t2) {
|
|
1058
1083
|
const s2 = e2.stack.pop(), o2 = e2.stack.pop(), n2 = t2(o2, s2);
|
|
1059
1084
|
e2.stack.push(n2);
|
|
1060
1085
|
}
|
|
@@ -1062,7 +1087,7 @@ const q = {
|
|
|
1062
1087
|
[n$1.EQ]: {
|
|
1063
1088
|
stackIn: 2,
|
|
1064
1089
|
stackOut: 1,
|
|
1065
|
-
execute: (e$1,
|
|
1090
|
+
execute: (e$1, r2) => g2(e$1, r2, (t2, s2) => {
|
|
1066
1091
|
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
1067
1092
|
return true;
|
|
1068
1093
|
if (o(t2) && o(s2))
|
|
@@ -1076,7 +1101,7 @@ const q = {
|
|
|
1076
1101
|
[n$1.NEQ]: {
|
|
1077
1102
|
stackIn: 2,
|
|
1078
1103
|
stackOut: 1,
|
|
1079
|
-
execute: (e$1,
|
|
1104
|
+
execute: (e$1, r2) => g2(e$1, r2, (t2, s2) => {
|
|
1080
1105
|
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
1081
1106
|
return false;
|
|
1082
1107
|
if (o(t2) && o(s2))
|
|
@@ -1090,7 +1115,7 @@ const q = {
|
|
|
1090
1115
|
[n$1.LT]: {
|
|
1091
1116
|
stackIn: 2,
|
|
1092
1117
|
stackOut: 1,
|
|
1093
|
-
execute: (e2,
|
|
1118
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
1094
1119
|
const o2 = m(t2), n2 = m(s2);
|
|
1095
1120
|
return o2 < n2;
|
|
1096
1121
|
})
|
|
@@ -1098,7 +1123,7 @@ const q = {
|
|
|
1098
1123
|
[n$1.GT]: {
|
|
1099
1124
|
stackIn: 2,
|
|
1100
1125
|
stackOut: 1,
|
|
1101
|
-
execute: (e2,
|
|
1126
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
1102
1127
|
const o2 = m(t2), n2 = m(s2);
|
|
1103
1128
|
return o2 > n2;
|
|
1104
1129
|
})
|
|
@@ -1106,7 +1131,7 @@ const q = {
|
|
|
1106
1131
|
[n$1.LTE]: {
|
|
1107
1132
|
stackIn: 2,
|
|
1108
1133
|
stackOut: 1,
|
|
1109
|
-
execute: (e2,
|
|
1134
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
1110
1135
|
const o2 = m(t2), n2 = m(s2);
|
|
1111
1136
|
return o2 <= n2;
|
|
1112
1137
|
})
|
|
@@ -1114,7 +1139,7 @@ const q = {
|
|
|
1114
1139
|
[n$1.GTE]: {
|
|
1115
1140
|
stackIn: 2,
|
|
1116
1141
|
stackOut: 1,
|
|
1117
|
-
execute: (e2,
|
|
1142
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
1118
1143
|
const o2 = m(t2), n2 = m(s2);
|
|
1119
1144
|
return o2 >= n2;
|
|
1120
1145
|
})
|
|
@@ -1122,57 +1147,57 @@ const q = {
|
|
|
1122
1147
|
[n$1.EQ_STRICT]: {
|
|
1123
1148
|
stackIn: 2,
|
|
1124
1149
|
stackOut: 1,
|
|
1125
|
-
execute: (e2,
|
|
1150
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => t2 === s2)
|
|
1126
1151
|
},
|
|
1127
1152
|
[n$1.NEQ_STRICT]: {
|
|
1128
1153
|
stackIn: 2,
|
|
1129
1154
|
stackOut: 1,
|
|
1130
|
-
execute: (e2,
|
|
1155
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => t2 !== s2)
|
|
1131
1156
|
}
|
|
1132
|
-
},
|
|
1157
|
+
}, $$1 = {
|
|
1133
1158
|
[n$1.AND]: {
|
|
1134
1159
|
stackIn: 2,
|
|
1135
1160
|
stackOut: 1,
|
|
1136
|
-
execute: (e2,
|
|
1137
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b
|
|
1161
|
+
execute: (e2, r2) => {
|
|
1162
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b(s2) ? t2 : s2;
|
|
1138
1163
|
e2.stack.push(o2);
|
|
1139
1164
|
}
|
|
1140
1165
|
},
|
|
1141
1166
|
[n$1.OR]: {
|
|
1142
1167
|
stackIn: 2,
|
|
1143
1168
|
stackOut: 1,
|
|
1144
|
-
execute: (e2,
|
|
1145
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b
|
|
1169
|
+
execute: (e2, r2) => {
|
|
1170
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b(s2) ? s2 : t2;
|
|
1146
1171
|
e2.stack.push(o2);
|
|
1147
1172
|
}
|
|
1148
1173
|
},
|
|
1149
1174
|
[n$1.NOT]: {
|
|
1150
1175
|
stackIn: 1,
|
|
1151
1176
|
stackOut: 1,
|
|
1152
|
-
execute: (e2,
|
|
1153
|
-
const t2 = e2.stack.pop(), s2 = !b
|
|
1177
|
+
execute: (e2, r2) => {
|
|
1178
|
+
const t2 = e2.stack.pop(), s2 = !b(t2);
|
|
1154
1179
|
e2.stack.push(s2);
|
|
1155
1180
|
}
|
|
1156
1181
|
}
|
|
1157
|
-
},
|
|
1182
|
+
}, H = {
|
|
1158
1183
|
[n$1.ARRAY_NEW]: {
|
|
1159
1184
|
stackIn: 0,
|
|
1160
1185
|
stackOut: 1,
|
|
1161
|
-
execute: (e2,
|
|
1186
|
+
execute: (e2, r2) => {
|
|
1162
1187
|
e2.stack.push(d());
|
|
1163
1188
|
}
|
|
1164
1189
|
},
|
|
1165
1190
|
[n$1.ARRAY_PUSH]: {
|
|
1166
1191
|
stackIn: 2,
|
|
1167
1192
|
stackOut: 1,
|
|
1168
|
-
execute: (e2,
|
|
1193
|
+
execute: (e2, r2) => {
|
|
1169
1194
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1170
1195
|
if (!f(s2))
|
|
1171
1196
|
return {
|
|
1172
1197
|
type: "RuntimeError",
|
|
1173
1198
|
message: "ARRAY_PUSH requires an array",
|
|
1174
1199
|
pc: e2.pc,
|
|
1175
|
-
opcode:
|
|
1200
|
+
opcode: r2.op
|
|
1176
1201
|
};
|
|
1177
1202
|
s2.elements.push(t2), e2.stack.push(s2);
|
|
1178
1203
|
}
|
|
@@ -1180,7 +1205,7 @@ const q = {
|
|
|
1180
1205
|
[n$1.ARRAY_GET]: {
|
|
1181
1206
|
stackIn: 2,
|
|
1182
1207
|
stackOut: 1,
|
|
1183
|
-
execute: (e2,
|
|
1208
|
+
execute: (e2, r2) => {
|
|
1184
1209
|
const t$1 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1185
1210
|
if (f(s2)) {
|
|
1186
1211
|
if (!t(t$1))
|
|
@@ -1188,7 +1213,7 @@ const q = {
|
|
|
1188
1213
|
type: "RuntimeError",
|
|
1189
1214
|
message: "ARRAY_GET requires numeric index for arrays",
|
|
1190
1215
|
pc: e2.pc,
|
|
1191
|
-
opcode:
|
|
1216
|
+
opcode: r2.op
|
|
1192
1217
|
};
|
|
1193
1218
|
const o2 = s2.elements[t$1] ?? null;
|
|
1194
1219
|
e2.stack.push(o2);
|
|
@@ -1200,7 +1225,7 @@ const q = {
|
|
|
1200
1225
|
type: "RuntimeError",
|
|
1201
1226
|
message: "ARRAY_GET requires string key for objects",
|
|
1202
1227
|
pc: e2.pc,
|
|
1203
|
-
opcode:
|
|
1228
|
+
opcode: r2.op
|
|
1204
1229
|
};
|
|
1205
1230
|
const o2 = s2.properties[t$1] ?? null;
|
|
1206
1231
|
e2.stack.push(o2);
|
|
@@ -1210,14 +1235,14 @@ const q = {
|
|
|
1210
1235
|
type: "RuntimeError",
|
|
1211
1236
|
message: "ARRAY_GET requires an array or object",
|
|
1212
1237
|
pc: e2.pc,
|
|
1213
|
-
opcode:
|
|
1238
|
+
opcode: r2.op
|
|
1214
1239
|
};
|
|
1215
1240
|
}
|
|
1216
1241
|
},
|
|
1217
1242
|
[n$1.ARRAY_SET]: {
|
|
1218
1243
|
stackIn: 3,
|
|
1219
1244
|
stackOut: 1,
|
|
1220
|
-
execute: (e2,
|
|
1245
|
+
execute: (e2, r2) => {
|
|
1221
1246
|
const t$1 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1222
1247
|
if (f(o2)) {
|
|
1223
1248
|
if (!t(s2))
|
|
@@ -1225,7 +1250,7 @@ const q = {
|
|
|
1225
1250
|
type: "RuntimeError",
|
|
1226
1251
|
message: "ARRAY_SET requires numeric index for arrays",
|
|
1227
1252
|
pc: e2.pc,
|
|
1228
|
-
opcode:
|
|
1253
|
+
opcode: r2.op
|
|
1229
1254
|
};
|
|
1230
1255
|
const n2 = Math.floor(s2);
|
|
1231
1256
|
if (n2 < 0)
|
|
@@ -1233,7 +1258,7 @@ const q = {
|
|
|
1233
1258
|
type: "RuntimeError",
|
|
1234
1259
|
message: "ARRAY_SET: Negative index not allowed",
|
|
1235
1260
|
pc: e2.pc,
|
|
1236
|
-
opcode:
|
|
1261
|
+
opcode: r2.op
|
|
1237
1262
|
};
|
|
1238
1263
|
o2.elements[n2] = t$1, e2.stack.push(o2);
|
|
1239
1264
|
return;
|
|
@@ -1244,7 +1269,7 @@ const q = {
|
|
|
1244
1269
|
type: "RuntimeError",
|
|
1245
1270
|
message: "ARRAY_SET requires string key for objects",
|
|
1246
1271
|
pc: e2.pc,
|
|
1247
|
-
opcode:
|
|
1272
|
+
opcode: r2.op
|
|
1248
1273
|
};
|
|
1249
1274
|
o2.properties[s2] = t$1, e2.stack.push(o2);
|
|
1250
1275
|
return;
|
|
@@ -1253,21 +1278,21 @@ const q = {
|
|
|
1253
1278
|
type: "RuntimeError",
|
|
1254
1279
|
message: "ARRAY_SET requires an array or object",
|
|
1255
1280
|
pc: e2.pc,
|
|
1256
|
-
opcode:
|
|
1281
|
+
opcode: r2.op
|
|
1257
1282
|
};
|
|
1258
1283
|
}
|
|
1259
1284
|
},
|
|
1260
1285
|
[n$1.ARRAY_LEN]: {
|
|
1261
1286
|
stackIn: 1,
|
|
1262
1287
|
stackOut: 1,
|
|
1263
|
-
execute: (e2,
|
|
1288
|
+
execute: (e2, r2) => {
|
|
1264
1289
|
const t2 = e2.stack.pop();
|
|
1265
1290
|
if (!f(t2))
|
|
1266
1291
|
return {
|
|
1267
1292
|
type: "RuntimeError",
|
|
1268
1293
|
message: "ARRAY_LEN requires an array",
|
|
1269
1294
|
pc: e2.pc,
|
|
1270
|
-
opcode:
|
|
1295
|
+
opcode: r2.op
|
|
1271
1296
|
};
|
|
1272
1297
|
e2.stack.push(t2.elements.length);
|
|
1273
1298
|
}
|
|
@@ -1279,16 +1304,16 @@ function T(e2) {
|
|
|
1279
1304
|
if (typeof e2 == "string" || typeof e2 == "number" || typeof e2 == "boolean" || e2 && typeof e2 == "object" && e2.type === "array" && Array.isArray(e2.elements))
|
|
1280
1305
|
return e2;
|
|
1281
1306
|
if (Array.isArray(e2)) {
|
|
1282
|
-
const
|
|
1283
|
-
return
|
|
1307
|
+
const r2 = d();
|
|
1308
|
+
return r2.elements = e2.map(T), r2;
|
|
1284
1309
|
}
|
|
1285
1310
|
if (e2 && typeof e2 == "object" && e2.type === "object" && e2.properties)
|
|
1286
1311
|
return e2;
|
|
1287
1312
|
if (typeof e2 == "object") {
|
|
1288
|
-
const
|
|
1313
|
+
const r2 = j$1();
|
|
1289
1314
|
for (const [t2, s2] of Object.entries(e2))
|
|
1290
|
-
|
|
1291
|
-
return
|
|
1315
|
+
r2.properties[t2] = T(s2);
|
|
1316
|
+
return r2;
|
|
1292
1317
|
}
|
|
1293
1318
|
return null;
|
|
1294
1319
|
}
|
|
@@ -1297,7 +1322,7 @@ const J = {
|
|
|
1297
1322
|
[n$1.CONCAT]: {
|
|
1298
1323
|
stackIn: 2,
|
|
1299
1324
|
stackOut: 1,
|
|
1300
|
-
execute: (e2,
|
|
1325
|
+
execute: (e2, r2) => {
|
|
1301
1326
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1302
1327
|
e2.stack.push(y(s2) + y(t2));
|
|
1303
1328
|
}
|
|
@@ -1305,14 +1330,14 @@ const J = {
|
|
|
1305
1330
|
[n$1.STRING_LEN]: {
|
|
1306
1331
|
stackIn: 1,
|
|
1307
1332
|
stackOut: 1,
|
|
1308
|
-
execute: (e2,
|
|
1333
|
+
execute: (e2, r2) => {
|
|
1309
1334
|
const t2 = e2.stack.pop();
|
|
1310
1335
|
if (!n(t2))
|
|
1311
1336
|
return {
|
|
1312
1337
|
type: "RuntimeError",
|
|
1313
1338
|
message: "STRING_LEN requires a string",
|
|
1314
1339
|
pc: e2.pc,
|
|
1315
|
-
opcode:
|
|
1340
|
+
opcode: r2.op
|
|
1316
1341
|
};
|
|
1317
1342
|
e2.stack.push(t2.length);
|
|
1318
1343
|
}
|
|
@@ -1320,7 +1345,7 @@ const J = {
|
|
|
1320
1345
|
[n$1.LENGTH]: {
|
|
1321
1346
|
stackIn: 1,
|
|
1322
1347
|
stackOut: 1,
|
|
1323
|
-
execute: (e2,
|
|
1348
|
+
execute: (e2, r2) => {
|
|
1324
1349
|
const t2 = e2.stack.pop();
|
|
1325
1350
|
if (n(t2))
|
|
1326
1351
|
e2.stack.push(t2.length);
|
|
@@ -1331,21 +1356,21 @@ const J = {
|
|
|
1331
1356
|
type: "RuntimeError",
|
|
1332
1357
|
message: "LENGTH requires a string or array",
|
|
1333
1358
|
pc: e2.pc,
|
|
1334
|
-
opcode:
|
|
1359
|
+
opcode: r2.op
|
|
1335
1360
|
};
|
|
1336
1361
|
}
|
|
1337
1362
|
},
|
|
1338
1363
|
[n$1.JSON_PARSE]: {
|
|
1339
1364
|
stackIn: 1,
|
|
1340
1365
|
stackOut: 1,
|
|
1341
|
-
execute: (e2,
|
|
1366
|
+
execute: (e2, r2) => {
|
|
1342
1367
|
const t2 = e2.stack.pop();
|
|
1343
1368
|
if (!n(t2))
|
|
1344
1369
|
return {
|
|
1345
1370
|
type: "RuntimeError",
|
|
1346
1371
|
message: "JSON_PARSE requires a string",
|
|
1347
1372
|
pc: e2.pc,
|
|
1348
|
-
opcode:
|
|
1373
|
+
opcode: r2.op
|
|
1349
1374
|
};
|
|
1350
1375
|
try {
|
|
1351
1376
|
const s2 = JSON.parse(t2);
|
|
@@ -1358,7 +1383,7 @@ const J = {
|
|
|
1358
1383
|
[n$1.TYPEOF]: {
|
|
1359
1384
|
stackIn: 1,
|
|
1360
1385
|
stackOut: 1,
|
|
1361
|
-
execute: (e2,
|
|
1386
|
+
execute: (e2, r2) => {
|
|
1362
1387
|
const t2 = e2.stack.pop();
|
|
1363
1388
|
e2.stack.push(p(t2));
|
|
1364
1389
|
}
|
|
@@ -1367,36 +1392,36 @@ const J = {
|
|
|
1367
1392
|
[n$1.INC]: {
|
|
1368
1393
|
stackIn: 1,
|
|
1369
1394
|
stackOut: 1,
|
|
1370
|
-
execute: (e2,
|
|
1395
|
+
execute: (e2, r2) => {
|
|
1371
1396
|
const t2 = e2.stack.pop();
|
|
1372
1397
|
if (typeof t2 != "string")
|
|
1373
1398
|
return {
|
|
1374
1399
|
type: "RuntimeError",
|
|
1375
1400
|
message: "INC: Invalid variable name",
|
|
1376
1401
|
pc: e2.pc,
|
|
1377
|
-
opcode:
|
|
1402
|
+
opcode: r2.op
|
|
1378
1403
|
};
|
|
1379
1404
|
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) + 1;
|
|
1380
1405
|
e2.variables.set(t2, o2);
|
|
1381
|
-
const n2 =
|
|
1406
|
+
const n2 = r2.arg === true;
|
|
1382
1407
|
e2.stack.push(n2 ? m(s2) : o2);
|
|
1383
1408
|
}
|
|
1384
1409
|
},
|
|
1385
1410
|
[n$1.DEC]: {
|
|
1386
1411
|
stackIn: 1,
|
|
1387
1412
|
stackOut: 1,
|
|
1388
|
-
execute: (e2,
|
|
1413
|
+
execute: (e2, r2) => {
|
|
1389
1414
|
const t2 = e2.stack.pop();
|
|
1390
1415
|
if (typeof t2 != "string")
|
|
1391
1416
|
return {
|
|
1392
1417
|
type: "RuntimeError",
|
|
1393
1418
|
message: "DEC: Invalid variable name",
|
|
1394
1419
|
pc: e2.pc,
|
|
1395
|
-
opcode:
|
|
1420
|
+
opcode: r2.op
|
|
1396
1421
|
};
|
|
1397
1422
|
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) - 1;
|
|
1398
1423
|
e2.variables.set(t2, o2);
|
|
1399
|
-
const n2 =
|
|
1424
|
+
const n2 = r2.arg === true;
|
|
1400
1425
|
e2.stack.push(n2 ? m(s2) : o2);
|
|
1401
1426
|
}
|
|
1402
1427
|
}
|
|
@@ -1405,7 +1430,7 @@ const J = {
|
|
|
1405
1430
|
stackIn: 0,
|
|
1406
1431
|
stackOut: 0,
|
|
1407
1432
|
controlsPC: true,
|
|
1408
|
-
execute: (e2,
|
|
1433
|
+
execute: (e2, r2) => {
|
|
1409
1434
|
const t2 = e2.stack.pop() ?? null;
|
|
1410
1435
|
e2.returnValue = t2, e2.status = "complete";
|
|
1411
1436
|
}
|
|
@@ -1414,21 +1439,21 @@ const J = {
|
|
|
1414
1439
|
stackIn: 0,
|
|
1415
1440
|
stackOut: 0,
|
|
1416
1441
|
controlsPC: true,
|
|
1417
|
-
execute: (e2,
|
|
1418
|
-
if (
|
|
1442
|
+
execute: (e2, r2) => {
|
|
1443
|
+
if (r2.arg === void 0)
|
|
1419
1444
|
return {
|
|
1420
1445
|
type: "RuntimeError",
|
|
1421
1446
|
message: "BREAK requires a target address",
|
|
1422
1447
|
pc: e2.pc,
|
|
1423
|
-
opcode:
|
|
1448
|
+
opcode: r2.op
|
|
1424
1449
|
};
|
|
1425
|
-
const t2 =
|
|
1450
|
+
const t2 = r2.arg;
|
|
1426
1451
|
if (t2 < 0)
|
|
1427
1452
|
return {
|
|
1428
1453
|
type: "RuntimeError",
|
|
1429
1454
|
message: `Invalid break target: ${t2}`,
|
|
1430
1455
|
pc: e2.pc,
|
|
1431
|
-
opcode:
|
|
1456
|
+
opcode: r2.op
|
|
1432
1457
|
};
|
|
1433
1458
|
e2.pc = t2;
|
|
1434
1459
|
}
|
|
@@ -1437,21 +1462,21 @@ const J = {
|
|
|
1437
1462
|
stackIn: 0,
|
|
1438
1463
|
stackOut: 0,
|
|
1439
1464
|
controlsPC: true,
|
|
1440
|
-
execute: (e2,
|
|
1441
|
-
if (
|
|
1465
|
+
execute: (e2, r2) => {
|
|
1466
|
+
if (r2.arg === void 0)
|
|
1442
1467
|
return {
|
|
1443
1468
|
type: "RuntimeError",
|
|
1444
1469
|
message: "CONTINUE requires a target address",
|
|
1445
1470
|
pc: e2.pc,
|
|
1446
|
-
opcode:
|
|
1471
|
+
opcode: r2.op
|
|
1447
1472
|
};
|
|
1448
|
-
const t2 =
|
|
1473
|
+
const t2 = r2.arg;
|
|
1449
1474
|
if (t2 < 0)
|
|
1450
1475
|
return {
|
|
1451
1476
|
type: "RuntimeError",
|
|
1452
1477
|
message: `Invalid continue target: ${t2}`,
|
|
1453
1478
|
pc: e2.pc,
|
|
1454
|
-
opcode:
|
|
1479
|
+
opcode: r2.op
|
|
1455
1480
|
};
|
|
1456
1481
|
e2.pc = t2;
|
|
1457
1482
|
}
|
|
@@ -1461,13 +1486,13 @@ const J = {
|
|
|
1461
1486
|
// Minimum 1 argument (path), optionally 2 (path + options)
|
|
1462
1487
|
stackOut: 0,
|
|
1463
1488
|
controlsPC: true,
|
|
1464
|
-
execute: (e2,
|
|
1489
|
+
execute: (e2, r2) => {
|
|
1465
1490
|
if (e2.stack.length < 1)
|
|
1466
1491
|
return {
|
|
1467
1492
|
type: "StackUnderflow",
|
|
1468
1493
|
message: "FS_LIST_FILES: Stack underflow",
|
|
1469
1494
|
pc: e2.pc,
|
|
1470
|
-
opcode:
|
|
1495
|
+
opcode: r2.op
|
|
1471
1496
|
};
|
|
1472
1497
|
let t2, s2 = {};
|
|
1473
1498
|
const o2 = e2.stack[e2.stack.length - 1];
|
|
@@ -1476,7 +1501,7 @@ const J = {
|
|
|
1476
1501
|
type: "RuntimeError",
|
|
1477
1502
|
message: "FS_LIST_FILES requires a string path",
|
|
1478
1503
|
pc: e2.pc,
|
|
1479
|
-
opcode:
|
|
1504
|
+
opcode: r2.op
|
|
1480
1505
|
};
|
|
1481
1506
|
e2.fsOperation = {
|
|
1482
1507
|
type: "listFiles",
|
|
@@ -1490,13 +1515,13 @@ const J = {
|
|
|
1490
1515
|
stackIn: 2,
|
|
1491
1516
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1492
1517
|
stackOut: 1,
|
|
1493
|
-
execute: (e2,
|
|
1518
|
+
execute: (e2, r2) => {
|
|
1494
1519
|
if (e2.stack.length < 2)
|
|
1495
1520
|
return {
|
|
1496
1521
|
type: "StackUnderflow",
|
|
1497
1522
|
message: "STRING_SUBSTRING: Stack underflow",
|
|
1498
1523
|
pc: e2.pc,
|
|
1499
|
-
opcode:
|
|
1524
|
+
opcode: r2.op
|
|
1500
1525
|
};
|
|
1501
1526
|
const t2 = e2.stack.length;
|
|
1502
1527
|
let s2, o2, n$12;
|
|
@@ -1506,14 +1531,14 @@ const J = {
|
|
|
1506
1531
|
type: "RuntimeError",
|
|
1507
1532
|
message: "STRING_SUBSTRING requires a string",
|
|
1508
1533
|
pc: e2.pc,
|
|
1509
|
-
opcode:
|
|
1534
|
+
opcode: r2.op
|
|
1510
1535
|
};
|
|
1511
1536
|
if (typeof o2 != "number")
|
|
1512
1537
|
return {
|
|
1513
1538
|
type: "RuntimeError",
|
|
1514
1539
|
message: "STRING_SUBSTRING requires numeric start index",
|
|
1515
1540
|
pc: e2.pc,
|
|
1516
|
-
opcode:
|
|
1541
|
+
opcode: r2.op
|
|
1517
1542
|
};
|
|
1518
1543
|
const u2 = s2.length;
|
|
1519
1544
|
o2 < 0 && (o2 = Math.max(0, u2 + o2)), n$12 !== void 0 && n$12 < 0 && (n$12 = Math.max(0, u2 + n$12));
|
|
@@ -1524,14 +1549,14 @@ const J = {
|
|
|
1524
1549
|
[n$1.STRING_INDEXOF]: {
|
|
1525
1550
|
stackIn: 2,
|
|
1526
1551
|
stackOut: 1,
|
|
1527
|
-
execute: (e2,
|
|
1552
|
+
execute: (e2, r2) => {
|
|
1528
1553
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1529
1554
|
if (!n(s2) || !n(t2))
|
|
1530
1555
|
return {
|
|
1531
1556
|
type: "RuntimeError",
|
|
1532
1557
|
message: "STRING_INDEXOF requires string arguments",
|
|
1533
1558
|
pc: e2.pc,
|
|
1534
|
-
opcode:
|
|
1559
|
+
opcode: r2.op
|
|
1535
1560
|
};
|
|
1536
1561
|
e2.stack.push(s2.indexOf(t2));
|
|
1537
1562
|
}
|
|
@@ -1539,14 +1564,14 @@ const J = {
|
|
|
1539
1564
|
[n$1.STRING_SPLIT]: {
|
|
1540
1565
|
stackIn: 2,
|
|
1541
1566
|
stackOut: 1,
|
|
1542
|
-
execute: (e2,
|
|
1567
|
+
execute: (e2, r2) => {
|
|
1543
1568
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1544
1569
|
if (!n(s2) || !n(t2))
|
|
1545
1570
|
return {
|
|
1546
1571
|
type: "RuntimeError",
|
|
1547
1572
|
message: "STRING_SPLIT requires string arguments",
|
|
1548
1573
|
pc: e2.pc,
|
|
1549
|
-
opcode:
|
|
1574
|
+
opcode: r2.op
|
|
1550
1575
|
};
|
|
1551
1576
|
let o2;
|
|
1552
1577
|
t2 === "" ? o2 = s2.split("") : o2 = s2.split(t2), e2.stack.push(d(o2));
|
|
@@ -1556,13 +1581,13 @@ const J = {
|
|
|
1556
1581
|
stackIn: 2,
|
|
1557
1582
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1558
1583
|
stackOut: 1,
|
|
1559
|
-
execute: (e2,
|
|
1584
|
+
execute: (e2, r2) => {
|
|
1560
1585
|
if (e2.stack.length < 2)
|
|
1561
1586
|
return {
|
|
1562
1587
|
type: "StackUnderflow",
|
|
1563
1588
|
message: "STRING_SLICE: Stack underflow",
|
|
1564
1589
|
pc: e2.pc,
|
|
1565
|
-
opcode:
|
|
1590
|
+
opcode: r2.op
|
|
1566
1591
|
};
|
|
1567
1592
|
const t2 = e2.stack.length;
|
|
1568
1593
|
let s2, o2, n$12;
|
|
@@ -1572,14 +1597,14 @@ const J = {
|
|
|
1572
1597
|
type: "RuntimeError",
|
|
1573
1598
|
message: "STRING_SLICE requires a string",
|
|
1574
1599
|
pc: e2.pc,
|
|
1575
|
-
opcode:
|
|
1600
|
+
opcode: r2.op
|
|
1576
1601
|
};
|
|
1577
1602
|
if (typeof o2 != "number")
|
|
1578
1603
|
return {
|
|
1579
1604
|
type: "RuntimeError",
|
|
1580
1605
|
message: "STRING_SLICE requires numeric start index",
|
|
1581
1606
|
pc: e2.pc,
|
|
1582
|
-
opcode:
|
|
1607
|
+
opcode: r2.op
|
|
1583
1608
|
};
|
|
1584
1609
|
const u2 = n$12 !== void 0 ? s2.slice(o2, n$12) : s2.slice(o2);
|
|
1585
1610
|
e2.stack.push(u2);
|
|
@@ -1588,21 +1613,21 @@ const J = {
|
|
|
1588
1613
|
[n$1.STRING_CHARAT]: {
|
|
1589
1614
|
stackIn: 2,
|
|
1590
1615
|
stackOut: 1,
|
|
1591
|
-
execute: (e2,
|
|
1616
|
+
execute: (e2, r2) => {
|
|
1592
1617
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1593
1618
|
if (!n(s2))
|
|
1594
1619
|
return {
|
|
1595
1620
|
type: "RuntimeError",
|
|
1596
1621
|
message: "STRING_CHARAT requires a string",
|
|
1597
1622
|
pc: e2.pc,
|
|
1598
|
-
opcode:
|
|
1623
|
+
opcode: r2.op
|
|
1599
1624
|
};
|
|
1600
1625
|
if (typeof t2 != "number")
|
|
1601
1626
|
return {
|
|
1602
1627
|
type: "RuntimeError",
|
|
1603
1628
|
message: "STRING_CHARAT requires numeric index",
|
|
1604
1629
|
pc: e2.pc,
|
|
1605
|
-
opcode:
|
|
1630
|
+
opcode: r2.op
|
|
1606
1631
|
};
|
|
1607
1632
|
const o2 = s2.charAt(t2);
|
|
1608
1633
|
e2.stack.push(o2);
|
|
@@ -1611,14 +1636,14 @@ const J = {
|
|
|
1611
1636
|
[n$1.STRING_TOUPPERCASE]: {
|
|
1612
1637
|
stackIn: 1,
|
|
1613
1638
|
stackOut: 1,
|
|
1614
|
-
execute: (e2,
|
|
1639
|
+
execute: (e2, r2) => {
|
|
1615
1640
|
const t2 = e2.stack.pop();
|
|
1616
1641
|
if (!n(t2))
|
|
1617
1642
|
return {
|
|
1618
1643
|
type: "RuntimeError",
|
|
1619
1644
|
message: "STRING_TOUPPERCASE requires a string",
|
|
1620
1645
|
pc: e2.pc,
|
|
1621
|
-
opcode:
|
|
1646
|
+
opcode: r2.op
|
|
1622
1647
|
};
|
|
1623
1648
|
e2.stack.push(t2.toUpperCase());
|
|
1624
1649
|
}
|
|
@@ -1626,14 +1651,14 @@ const J = {
|
|
|
1626
1651
|
[n$1.STRING_TOLOWERCASE]: {
|
|
1627
1652
|
stackIn: 1,
|
|
1628
1653
|
stackOut: 1,
|
|
1629
|
-
execute: (e2,
|
|
1654
|
+
execute: (e2, r2) => {
|
|
1630
1655
|
const t2 = e2.stack.pop();
|
|
1631
1656
|
if (!n(t2))
|
|
1632
1657
|
return {
|
|
1633
1658
|
type: "RuntimeError",
|
|
1634
1659
|
message: "STRING_TOLOWERCASE requires a string",
|
|
1635
1660
|
pc: e2.pc,
|
|
1636
|
-
opcode:
|
|
1661
|
+
opcode: r2.op
|
|
1637
1662
|
};
|
|
1638
1663
|
e2.stack.push(t2.toLowerCase());
|
|
1639
1664
|
}
|
|
@@ -1641,14 +1666,14 @@ const J = {
|
|
|
1641
1666
|
[n$1.TO_STRING]: {
|
|
1642
1667
|
stackIn: 1,
|
|
1643
1668
|
stackOut: 1,
|
|
1644
|
-
execute: (e2,
|
|
1669
|
+
execute: (e2, r2) => {
|
|
1645
1670
|
const t2 = e2.stack.pop();
|
|
1646
1671
|
if (t2 === void 0)
|
|
1647
1672
|
return {
|
|
1648
1673
|
type: "StackUnderflow",
|
|
1649
1674
|
message: "TO_STRING: Stack underflow",
|
|
1650
1675
|
pc: e2.pc,
|
|
1651
|
-
opcode:
|
|
1676
|
+
opcode: r2.op
|
|
1652
1677
|
};
|
|
1653
1678
|
const s2 = y(t2);
|
|
1654
1679
|
e2.stack.push(s2);
|
|
@@ -1659,10 +1684,10 @@ function _(e2) {
|
|
|
1659
1684
|
if (f(e2))
|
|
1660
1685
|
return e2.elements.map(_);
|
|
1661
1686
|
if (c(e2)) {
|
|
1662
|
-
const
|
|
1687
|
+
const r2 = {};
|
|
1663
1688
|
for (const [t2, s2] of Object.entries(e2.properties))
|
|
1664
|
-
|
|
1665
|
-
return
|
|
1689
|
+
r2[t2] = _(s2);
|
|
1690
|
+
return r2;
|
|
1666
1691
|
}
|
|
1667
1692
|
if (!o(e2))
|
|
1668
1693
|
return e2;
|
|
@@ -1678,21 +1703,21 @@ const W = {
|
|
|
1678
1703
|
[n$1.PROPERTY_SET]: {
|
|
1679
1704
|
stackIn: 3,
|
|
1680
1705
|
stackOut: 1,
|
|
1681
|
-
execute: (e2,
|
|
1706
|
+
execute: (e2, r2) => {
|
|
1682
1707
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1683
1708
|
if (!c(o2))
|
|
1684
1709
|
return {
|
|
1685
1710
|
type: "RuntimeError",
|
|
1686
1711
|
message: `Cannot set property '${s2}' on ${p(o2)}`,
|
|
1687
1712
|
pc: e2.pc,
|
|
1688
|
-
opcode:
|
|
1713
|
+
opcode: r2.op
|
|
1689
1714
|
};
|
|
1690
1715
|
if (!n(s2))
|
|
1691
1716
|
return {
|
|
1692
1717
|
type: "RuntimeError",
|
|
1693
1718
|
message: "Property key must be a string",
|
|
1694
1719
|
pc: e2.pc,
|
|
1695
|
-
opcode:
|
|
1720
|
+
opcode: r2.op
|
|
1696
1721
|
};
|
|
1697
1722
|
o2.properties[s2] = t2, e2.stack.push(o2);
|
|
1698
1723
|
}
|
|
@@ -1700,14 +1725,14 @@ const W = {
|
|
|
1700
1725
|
[n$1.PROPERTY_GET]: {
|
|
1701
1726
|
stackIn: 2,
|
|
1702
1727
|
stackOut: 1,
|
|
1703
|
-
execute: (e$1,
|
|
1728
|
+
execute: (e$1, r2) => {
|
|
1704
1729
|
const t2 = e$1.stack.pop(), s$1 = e$1.stack.pop();
|
|
1705
1730
|
if (e(s$1) || o(s$1))
|
|
1706
1731
|
return {
|
|
1707
1732
|
type: "RuntimeError",
|
|
1708
1733
|
message: `Cannot read property '${t2}' of ${p(s$1)}`,
|
|
1709
1734
|
pc: e$1.pc,
|
|
1710
|
-
opcode:
|
|
1735
|
+
opcode: r2.op
|
|
1711
1736
|
};
|
|
1712
1737
|
if (!c(s$1)) {
|
|
1713
1738
|
e$1.stack.push(s());
|
|
@@ -1721,7 +1746,7 @@ const W = {
|
|
|
1721
1746
|
stackIn: 1,
|
|
1722
1747
|
stackOut: 1,
|
|
1723
1748
|
execute: (e2) => {
|
|
1724
|
-
const
|
|
1749
|
+
const r2 = e2.stack.pop(), t2 = _(r2);
|
|
1725
1750
|
e2.stack.push(JSON.stringify(t2));
|
|
1726
1751
|
}
|
|
1727
1752
|
}
|
|
@@ -1733,16 +1758,16 @@ const W = {
|
|
|
1733
1758
|
...j,
|
|
1734
1759
|
...D,
|
|
1735
1760
|
...q,
|
|
1761
|
+
...$$1,
|
|
1736
1762
|
...H,
|
|
1737
|
-
...$,
|
|
1738
1763
|
...J,
|
|
1739
1764
|
...Y,
|
|
1740
1765
|
...B,
|
|
1741
1766
|
...W
|
|
1742
1767
|
};
|
|
1743
|
-
class
|
|
1744
|
-
validateStack(
|
|
1745
|
-
if (s2.stack.length <
|
|
1768
|
+
let x$1 = class x {
|
|
1769
|
+
validateStack(r2, t2, s2) {
|
|
1770
|
+
if (s2.stack.length < r2.stackIn)
|
|
1746
1771
|
return {
|
|
1747
1772
|
type: "StackUnderflow",
|
|
1748
1773
|
message: `${n$1[t2.op]}: Stack underflow`,
|
|
@@ -1750,7 +1775,7 @@ class N {
|
|
|
1750
1775
|
opcode: t2.op
|
|
1751
1776
|
};
|
|
1752
1777
|
}
|
|
1753
|
-
execute(
|
|
1778
|
+
execute(r2, t2) {
|
|
1754
1779
|
const s2 = {
|
|
1755
1780
|
pc: (t2 == null ? void 0 : t2.pc) ?? 0,
|
|
1756
1781
|
stack: (t2 == null ? void 0 : t2.stack) ?? [],
|
|
@@ -1760,15 +1785,15 @@ class N {
|
|
|
1760
1785
|
iterators: (t2 == null ? void 0 : t2.iterators) ?? [],
|
|
1761
1786
|
...t2
|
|
1762
1787
|
};
|
|
1763
|
-
for (; s2.status === "running" && s2.pc <
|
|
1764
|
-
const o2 =
|
|
1788
|
+
for (; s2.status === "running" && s2.pc < r2.length; ) {
|
|
1789
|
+
const o2 = r2[s2.pc], n2 = z[o2.op];
|
|
1765
1790
|
if (n2) {
|
|
1766
1791
|
const a2 = this.validateStack(n2, o2, s2);
|
|
1767
1792
|
if (a2) {
|
|
1768
1793
|
s2.status = "error", s2.error = a2.message;
|
|
1769
1794
|
break;
|
|
1770
1795
|
}
|
|
1771
|
-
if ((o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE || o2.op === n$1.BREAK || o2.op === n$1.CONTINUE) && o2.arg !== void 0 && o2.arg >=
|
|
1796
|
+
if ((o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE || o2.op === n$1.BREAK || o2.op === n$1.CONTINUE) && o2.arg !== void 0 && o2.arg >= r2.length) {
|
|
1772
1797
|
s2.status = "error";
|
|
1773
1798
|
const u2 = o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE ? "jump" : o2.op === n$1.BREAK ? "break" : "continue";
|
|
1774
1799
|
s2.error = `Invalid ${u2} target: ${o2.arg}`;
|
|
@@ -1787,69 +1812,69 @@ class N {
|
|
|
1787
1812
|
}
|
|
1788
1813
|
return s2;
|
|
1789
1814
|
}
|
|
1790
|
-
resume(
|
|
1791
|
-
if (
|
|
1815
|
+
resume(r2, t2, s2) {
|
|
1816
|
+
if (r2.status !== "waiting_cc")
|
|
1792
1817
|
throw new Error("Cannot resume: VM not waiting for CC");
|
|
1793
1818
|
const o2 = {
|
|
1794
|
-
...
|
|
1795
|
-
stack: [...
|
|
1819
|
+
...r2,
|
|
1820
|
+
stack: [...r2.stack, t2],
|
|
1796
1821
|
status: "running",
|
|
1797
1822
|
ccPrompt: void 0,
|
|
1798
|
-
pc:
|
|
1823
|
+
pc: r2.pc + 1
|
|
1799
1824
|
};
|
|
1800
1825
|
return this.execute(s2, o2);
|
|
1801
1826
|
}
|
|
1802
|
-
resumeWithFsResult(
|
|
1803
|
-
if (
|
|
1827
|
+
resumeWithFsResult(r2, t2, s2) {
|
|
1828
|
+
if (r2.status !== "waiting_fs")
|
|
1804
1829
|
throw new Error("Cannot resume: VM not waiting for FS operation");
|
|
1805
1830
|
const o2 = {
|
|
1806
|
-
...
|
|
1807
|
-
stack: [...
|
|
1831
|
+
...r2,
|
|
1832
|
+
stack: [...r2.stack, t2],
|
|
1808
1833
|
status: "running",
|
|
1809
1834
|
fsOperation: void 0,
|
|
1810
|
-
pc:
|
|
1835
|
+
pc: r2.pc + 1
|
|
1811
1836
|
};
|
|
1812
1837
|
return this.execute(s2, o2);
|
|
1813
1838
|
}
|
|
1814
|
-
}
|
|
1839
|
+
};
|
|
1815
1840
|
class P {
|
|
1816
1841
|
constructor() {
|
|
1817
1842
|
h2(this, "sandboxPaths", []);
|
|
1818
|
-
const
|
|
1819
|
-
|
|
1843
|
+
const r2 = process.env.CVM_SANDBOX_PATHS, t2 = process.env.CVM_SANDBOX_ROOT;
|
|
1844
|
+
r2 ? this.sandboxPaths = r2.split(",").map((s2) => r__namespace.resolve(s2.trim())) : t2 && (this.sandboxPaths = [r__namespace.resolve(t2)]);
|
|
1820
1845
|
}
|
|
1821
|
-
isPathAllowed(
|
|
1822
|
-
const t2 =
|
|
1846
|
+
isPathAllowed(r2) {
|
|
1847
|
+
const t2 = r__namespace.resolve(r2);
|
|
1823
1848
|
return t2.includes("..") || this.sandboxPaths.length === 0 ? false : this.sandboxPaths.some(
|
|
1824
1849
|
(s2) => t2.startsWith(s2)
|
|
1825
1850
|
);
|
|
1826
1851
|
}
|
|
1827
|
-
listFiles(
|
|
1852
|
+
listFiles(r2, t2 = {}) {
|
|
1828
1853
|
const s2 = d();
|
|
1829
|
-
if (!this.isPathAllowed(
|
|
1854
|
+
if (!this.isPathAllowed(r2))
|
|
1830
1855
|
return s2;
|
|
1831
1856
|
try {
|
|
1832
|
-
const o2 =
|
|
1857
|
+
const o2 = r__namespace.resolve(r2);
|
|
1833
1858
|
this.listFilesRecursive(o2, o2, s2.elements, t2);
|
|
1834
1859
|
} catch {
|
|
1835
1860
|
}
|
|
1836
1861
|
return s2;
|
|
1837
1862
|
}
|
|
1838
|
-
matchesPattern(
|
|
1863
|
+
matchesPattern(r2, t2) {
|
|
1839
1864
|
let s2 = t2.replace(/\./g, "\\.").replace(/\*\*/g, "__DOUBLESTAR__").replace(/\*/g, "[^/]*").replace(/__DOUBLESTAR__/g, ".*").replace(/\?/g, ".");
|
|
1840
1865
|
s2 = "^" + s2 + "$";
|
|
1841
1866
|
try {
|
|
1842
|
-
return new RegExp(s2).test(
|
|
1867
|
+
return new RegExp(s2).test(r2);
|
|
1843
1868
|
} catch {
|
|
1844
1869
|
return true;
|
|
1845
1870
|
}
|
|
1846
1871
|
}
|
|
1847
|
-
listFilesRecursive(
|
|
1872
|
+
listFilesRecursive(r2, t2, s2, o2, n2 = 0) {
|
|
1848
1873
|
try {
|
|
1849
1874
|
const a2 = M__namespace.readdirSync(t2, { withFileTypes: true });
|
|
1850
1875
|
for (const i2 of a2) {
|
|
1851
|
-
const u2 =
|
|
1852
|
-
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(O2, o2.filter) || (s2.push(u2), i2.isDirectory() && o2.recursive && this.listFilesRecursive(
|
|
1876
|
+
const u2 = r__namespace.join(t2, i2.name), O2 = r__namespace.relative(r2, u2);
|
|
1877
|
+
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(O2, o2.filter) || (s2.push(u2), i2.isDirectory() && o2.recursive && this.listFilesRecursive(r2, u2, s2, o2, n2 + 1));
|
|
1853
1878
|
}
|
|
1854
1879
|
} catch {
|
|
1855
1880
|
}
|
|
@@ -1857,11 +1882,11 @@ class P {
|
|
|
1857
1882
|
}
|
|
1858
1883
|
new P();
|
|
1859
1884
|
class te {
|
|
1860
|
-
constructor(
|
|
1885
|
+
constructor(r2, t2) {
|
|
1861
1886
|
h2(this, "vms", /* @__PURE__ */ new Map());
|
|
1862
1887
|
h2(this, "storage");
|
|
1863
1888
|
h2(this, "fileSystem");
|
|
1864
|
-
|
|
1889
|
+
r2 ? this.storage = r2 : this.storage = g$1.create(), this.fileSystem = t2 || new P();
|
|
1865
1890
|
}
|
|
1866
1891
|
/**
|
|
1867
1892
|
* Initialize the VMManager (connect to database)
|
|
@@ -1878,13 +1903,13 @@ class te {
|
|
|
1878
1903
|
/**
|
|
1879
1904
|
* Load and compile a program from source code
|
|
1880
1905
|
*/
|
|
1881
|
-
async loadProgram(
|
|
1906
|
+
async loadProgram(r2, t2) {
|
|
1882
1907
|
const s2 = W$1(t2);
|
|
1883
1908
|
if (!s2.success)
|
|
1884
1909
|
throw new Error(`Compilation failed: ${s2.errors.join(", ")}`);
|
|
1885
1910
|
const o2 = {
|
|
1886
|
-
id:
|
|
1887
|
-
name:
|
|
1911
|
+
id: r2,
|
|
1912
|
+
name: r2,
|
|
1888
1913
|
source: t2,
|
|
1889
1914
|
bytecode: s2.bytecode,
|
|
1890
1915
|
// VM decides internal format
|
|
@@ -1895,12 +1920,12 @@ class te {
|
|
|
1895
1920
|
/**
|
|
1896
1921
|
* Start execution of a loaded program
|
|
1897
1922
|
*/
|
|
1898
|
-
async startExecution(
|
|
1899
|
-
if (!await this.storage.getProgram(
|
|
1900
|
-
throw new Error(`Program not found: ${
|
|
1923
|
+
async startExecution(r2, t2) {
|
|
1924
|
+
if (!await this.storage.getProgram(r2))
|
|
1925
|
+
throw new Error(`Program not found: ${r2}`);
|
|
1901
1926
|
const o2 = {
|
|
1902
1927
|
id: t2,
|
|
1903
|
-
programId:
|
|
1928
|
+
programId: r2,
|
|
1904
1929
|
state: "READY",
|
|
1905
1930
|
pc: 0,
|
|
1906
1931
|
stack: [],
|
|
@@ -1908,31 +1933,31 @@ class te {
|
|
|
1908
1933
|
created: /* @__PURE__ */ new Date()
|
|
1909
1934
|
};
|
|
1910
1935
|
await this.storage.saveExecution(o2);
|
|
1911
|
-
const n2 = new
|
|
1936
|
+
const n2 = new x$1();
|
|
1912
1937
|
this.vms.set(t2, n2);
|
|
1913
1938
|
}
|
|
1914
1939
|
/**
|
|
1915
1940
|
* Get next action from execution (Claude polls this)
|
|
1916
1941
|
* This is READ-ONLY - just returns current state
|
|
1917
1942
|
*/
|
|
1918
|
-
async getNext(
|
|
1919
|
-
const t2 = await this.storage.getExecution(
|
|
1943
|
+
async getNext(r2) {
|
|
1944
|
+
const t2 = await this.storage.getExecution(r2);
|
|
1920
1945
|
if (!t2)
|
|
1921
|
-
throw new Error(`Execution not found: ${
|
|
1946
|
+
throw new Error(`Execution not found: ${r2}`);
|
|
1922
1947
|
if (t2.state === "READY") {
|
|
1923
1948
|
const s2 = await this.storage.getProgram(t2.programId);
|
|
1924
1949
|
if (!s2)
|
|
1925
1950
|
throw new Error(`Program not found: ${t2.programId}`);
|
|
1926
|
-
let o2 = this.vms.get(
|
|
1927
|
-
o2 || (o2 = new
|
|
1951
|
+
let o2 = this.vms.get(r2);
|
|
1952
|
+
o2 || (o2 = new x$1(), this.vms.set(r2, o2));
|
|
1928
1953
|
const n2 = {
|
|
1929
1954
|
pc: 0,
|
|
1930
1955
|
stack: [],
|
|
1931
1956
|
variables: /* @__PURE__ */ new Map(),
|
|
1932
1957
|
output: []
|
|
1933
1958
|
}, a2 = o2.execute(s2.bytecode, n2);
|
|
1934
|
-
if (a2.output.length > 0 && await this.storage.appendOutput(
|
|
1935
|
-
return t2.state = "COMPLETED", a2.returnValue !== void 0 && (t2.returnValue = a2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(
|
|
1959
|
+
if (a2.output.length > 0 && await this.storage.appendOutput(r2, a2.output), t2.pc = a2.pc, t2.stack = a2.stack, t2.variables = Object.fromEntries(a2.variables), t2.iterators = a2.iterators, a2.status === "complete")
|
|
1960
|
+
return t2.state = "COMPLETED", a2.returnValue !== void 0 && (t2.returnValue = a2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1936
1961
|
type: "completed",
|
|
1937
1962
|
message: "Execution completed",
|
|
1938
1963
|
result: a2.returnValue
|
|
@@ -1945,20 +1970,20 @@ class te {
|
|
|
1945
1970
|
if (a2.status === "waiting_fs") {
|
|
1946
1971
|
if (a2.fsOperation) {
|
|
1947
1972
|
const i2 = this.fileSystem.listFiles(a2.fsOperation.path, a2.fsOperation.options), u2 = o2.resumeWithFsResult(a2, i2, s2.bytecode);
|
|
1948
|
-
return u2.output.length > 0 && await this.storage.appendOutput(
|
|
1973
|
+
return u2.output.length > 0 && await this.storage.appendOutput(r2, u2.output), t2.pc = u2.pc, t2.stack = u2.stack, t2.variables = Object.fromEntries(u2.variables), t2.iterators = u2.iterators, u2.status === "complete" ? (t2.state = "COMPLETED", u2.returnValue !== void 0 && (t2.returnValue = u2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1949
1974
|
type: "completed",
|
|
1950
1975
|
message: "Execution completed",
|
|
1951
1976
|
result: u2.returnValue
|
|
1952
|
-
}) : u2.status === "error" ? (t2.state = "ERROR", t2.error = u2.error, await this.storage.saveExecution(t2), this.vms.delete(
|
|
1977
|
+
}) : u2.status === "error" ? (t2.state = "ERROR", t2.error = u2.error, await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1953
1978
|
type: "error",
|
|
1954
1979
|
error: u2.error
|
|
1955
1980
|
}) : u2.status === "waiting_cc" ? (t2.state = "AWAITING_COGNITIVE_RESULT", t2.ccPrompt = u2.ccPrompt, await this.storage.saveExecution(t2), {
|
|
1956
1981
|
type: "waiting",
|
|
1957
1982
|
message: u2.ccPrompt || "Waiting for input"
|
|
1958
|
-
}) : (t2.state = "RUNNING", await this.storage.saveExecution(t2), this.getNext(
|
|
1983
|
+
}) : (t2.state = "RUNNING", await this.storage.saveExecution(t2), this.getNext(r2));
|
|
1959
1984
|
}
|
|
1960
1985
|
} else if (a2.status === "error")
|
|
1961
|
-
return t2.state = "ERROR", t2.error = a2.error, await this.storage.saveExecution(t2), this.vms.delete(
|
|
1986
|
+
return t2.state = "ERROR", t2.error = a2.error, await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1962
1987
|
type: "error",
|
|
1963
1988
|
error: a2.error
|
|
1964
1989
|
};
|
|
@@ -1983,15 +2008,15 @@ class te {
|
|
|
1983
2008
|
/**
|
|
1984
2009
|
* Report result from cognitive operation and continue execution
|
|
1985
2010
|
*/
|
|
1986
|
-
async reportCCResult(
|
|
1987
|
-
const s2 = await this.storage.getExecution(
|
|
2011
|
+
async reportCCResult(r2, t2) {
|
|
2012
|
+
const s2 = await this.storage.getExecution(r2);
|
|
1988
2013
|
if (!s2)
|
|
1989
|
-
throw new Error(`Execution not found: ${
|
|
2014
|
+
throw new Error(`Execution not found: ${r2}`);
|
|
1990
2015
|
const o2 = await this.storage.getProgram(s2.programId);
|
|
1991
2016
|
if (!o2)
|
|
1992
2017
|
throw new Error(`Program not found: ${s2.programId}`);
|
|
1993
|
-
let n2 = this.vms.get(
|
|
1994
|
-
n2 || (n2 = new
|
|
2018
|
+
let n2 = this.vms.get(r2);
|
|
2019
|
+
n2 || (n2 = new x$1(), this.vms.set(r2, n2));
|
|
1995
2020
|
const a2 = {
|
|
1996
2021
|
pc: s2.pc,
|
|
1997
2022
|
stack: s2.stack,
|
|
@@ -2002,15 +2027,15 @@ class te {
|
|
|
2002
2027
|
ccPrompt: void 0,
|
|
2003
2028
|
iterators: s2.iterators || []
|
|
2004
2029
|
}, i2 = n2.resume(a2, t2, o2.bytecode);
|
|
2005
|
-
i2.output.length > 0 && await this.storage.appendOutput(
|
|
2030
|
+
i2.output.length > 0 && await this.storage.appendOutput(r2, i2.output), s2.pc = i2.pc, s2.stack = i2.stack, s2.variables = Object.fromEntries(i2.variables), s2.iterators = i2.iterators, i2.status === "complete" ? (s2.state = "COMPLETED", i2.returnValue !== void 0 && (s2.returnValue = i2.returnValue), this.vms.delete(r2)) : i2.status === "error" ? (s2.state = "ERROR", s2.error = i2.error, this.vms.delete(r2)) : i2.status === "waiting_cc" ? (s2.state = "AWAITING_COGNITIVE_RESULT", s2.ccPrompt = i2.ccPrompt) : s2.state = "RUNNING", await this.storage.saveExecution(s2);
|
|
2006
2031
|
}
|
|
2007
2032
|
/**
|
|
2008
2033
|
* Get current execution status
|
|
2009
2034
|
*/
|
|
2010
|
-
async getExecutionStatus(
|
|
2011
|
-
const t2 = await this.storage.getExecution(
|
|
2035
|
+
async getExecutionStatus(r2) {
|
|
2036
|
+
const t2 = await this.storage.getExecution(r2);
|
|
2012
2037
|
if (!t2)
|
|
2013
|
-
throw new Error(`Execution not found: ${
|
|
2038
|
+
throw new Error(`Execution not found: ${r2}`);
|
|
2014
2039
|
return {
|
|
2015
2040
|
id: t2.id,
|
|
2016
2041
|
state: t2.state,
|
|
@@ -2022,8 +2047,8 @@ class te {
|
|
|
2022
2047
|
/**
|
|
2023
2048
|
* Get output for an execution
|
|
2024
2049
|
*/
|
|
2025
|
-
async getExecutionOutput(
|
|
2026
|
-
return await this.storage.getOutput(
|
|
2050
|
+
async getExecutionOutput(r2) {
|
|
2051
|
+
return await this.storage.getOutput(r2);
|
|
2027
2052
|
}
|
|
2028
2053
|
/**
|
|
2029
2054
|
* List all executions
|
|
@@ -2040,35 +2065,54 @@ class te {
|
|
|
2040
2065
|
/**
|
|
2041
2066
|
* Set current execution ID
|
|
2042
2067
|
*/
|
|
2043
|
-
async setCurrentExecutionId(
|
|
2044
|
-
return await this.storage.setCurrentExecutionId(
|
|
2068
|
+
async setCurrentExecutionId(r2) {
|
|
2069
|
+
return await this.storage.setCurrentExecutionId(r2);
|
|
2045
2070
|
}
|
|
2046
2071
|
/**
|
|
2047
2072
|
* Delete an execution
|
|
2048
2073
|
*/
|
|
2049
|
-
async deleteExecution(
|
|
2050
|
-
return await this.storage.deleteExecution(
|
|
2074
|
+
async deleteExecution(r2) {
|
|
2075
|
+
return await this.storage.deleteExecution(r2);
|
|
2051
2076
|
}
|
|
2052
2077
|
/**
|
|
2053
2078
|
* Get execution with attempt tracking
|
|
2054
2079
|
*/
|
|
2055
|
-
async getExecutionWithAttempts(
|
|
2056
|
-
const t2 = await this.storage.getExecution(
|
|
2080
|
+
async getExecutionWithAttempts(r2) {
|
|
2081
|
+
const t2 = await this.storage.getExecution(r2);
|
|
2057
2082
|
if (!t2)
|
|
2058
|
-
throw new Error(`Execution not found: ${
|
|
2083
|
+
throw new Error(`Execution not found: ${r2}`);
|
|
2059
2084
|
return t2;
|
|
2060
2085
|
}
|
|
2086
|
+
/**
|
|
2087
|
+
* List all programs
|
|
2088
|
+
*/
|
|
2089
|
+
async listPrograms() {
|
|
2090
|
+
return await this.storage.listPrograms();
|
|
2091
|
+
}
|
|
2092
|
+
/**
|
|
2093
|
+
* Delete a program
|
|
2094
|
+
*/
|
|
2095
|
+
async deleteProgram(r2) {
|
|
2096
|
+
return await this.storage.deleteProgram(r2);
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Restart a program (create new execution and set as current)
|
|
2100
|
+
*/
|
|
2101
|
+
async restartExecution(r2, t2) {
|
|
2102
|
+
const s2 = t2 || `${r2}-${Date.now()}`;
|
|
2103
|
+
return await this.startExecution(r2, s2), await this.setCurrentExecutionId(s2), s2;
|
|
2104
|
+
}
|
|
2061
2105
|
}
|
|
2062
2106
|
var u = Object.defineProperty;
|
|
2063
|
-
var
|
|
2064
|
-
var i = (s2,
|
|
2065
|
-
class
|
|
2066
|
-
constructor(
|
|
2107
|
+
var x2 = (s2, e2, r2) => e2 in s2 ? u(s2, e2, { enumerable: true, configurable: true, writable: true, value: r2 }) : s2[e2] = r2;
|
|
2108
|
+
var i = (s2, e2, r2) => x2(s2, typeof e2 != "symbol" ? e2 + "" : e2, r2);
|
|
2109
|
+
class $ {
|
|
2110
|
+
constructor(e2 = "0.0.1") {
|
|
2067
2111
|
i(this, "server");
|
|
2068
2112
|
i(this, "transport", null);
|
|
2069
2113
|
i(this, "vmManager");
|
|
2070
2114
|
i(this, "version");
|
|
2071
|
-
this.version =
|
|
2115
|
+
this.version = e2, this.vmManager = new te(), this.server = new mcp_js.McpServer({
|
|
2072
2116
|
name: "cvm-server",
|
|
2073
2117
|
version: this.version
|
|
2074
2118
|
}), this.setupTools();
|
|
@@ -2086,10 +2130,10 @@ class M {
|
|
|
2086
2130
|
programId: zod.z.string(),
|
|
2087
2131
|
source: zod.z.string()
|
|
2088
2132
|
},
|
|
2089
|
-
async ({ programId:
|
|
2133
|
+
async ({ programId: e2, source: r2 }) => {
|
|
2090
2134
|
try {
|
|
2091
|
-
return await this.vmManager.loadProgram(
|
|
2092
|
-
content: [{ type: "text", text: `Program loaded successfully: ${
|
|
2135
|
+
return await this.vmManager.loadProgram(e2, r2), {
|
|
2136
|
+
content: [{ type: "text", text: `Program loaded successfully: ${e2}` }]
|
|
2093
2137
|
};
|
|
2094
2138
|
} catch (t2) {
|
|
2095
2139
|
return {
|
|
@@ -2104,23 +2148,23 @@ class M {
|
|
|
2104
2148
|
programId: zod.z.string(),
|
|
2105
2149
|
filePath: zod.z.string()
|
|
2106
2150
|
},
|
|
2107
|
-
async ({ programId:
|
|
2151
|
+
async ({ programId: e2, filePath: r$1 }) => {
|
|
2108
2152
|
try {
|
|
2109
|
-
const t2 =
|
|
2110
|
-
return await this.vmManager.loadProgram(
|
|
2111
|
-
content: [{ type: "text", text: `Program loaded successfully from ${
|
|
2153
|
+
const t2 = r.resolve(r$1), n2 = await promises.readFile(t2, "utf-8");
|
|
2154
|
+
return await this.vmManager.loadProgram(e2, n2), {
|
|
2155
|
+
content: [{ type: "text", text: `Program loaded successfully from ${r$1}: ${e2}` }]
|
|
2112
2156
|
};
|
|
2113
2157
|
} catch (t2) {
|
|
2114
2158
|
if (t2 instanceof Error) {
|
|
2115
2159
|
const n2 = t2;
|
|
2116
2160
|
if (n2.code === "ENOENT")
|
|
2117
2161
|
return {
|
|
2118
|
-
content: [{ type: "text", text: `Error: File not found: ${
|
|
2162
|
+
content: [{ type: "text", text: `Error: File not found: ${r$1}` }],
|
|
2119
2163
|
isError: true
|
|
2120
2164
|
};
|
|
2121
2165
|
if (n2.code === "EACCES")
|
|
2122
2166
|
return {
|
|
2123
|
-
content: [{ type: "text", text: `Error: Permission denied: ${
|
|
2167
|
+
content: [{ type: "text", text: `Error: Permission denied: ${r$1}` }],
|
|
2124
2168
|
isError: true
|
|
2125
2169
|
};
|
|
2126
2170
|
}
|
|
@@ -2137,10 +2181,10 @@ class M {
|
|
|
2137
2181
|
executionId: zod.z.string(),
|
|
2138
2182
|
setCurrent: zod.z.boolean().optional()
|
|
2139
2183
|
},
|
|
2140
|
-
async ({ programId:
|
|
2184
|
+
async ({ programId: e2, executionId: r2, setCurrent: t2 = true }) => {
|
|
2141
2185
|
try {
|
|
2142
|
-
return await this.vmManager.startExecution(
|
|
2143
|
-
content: [{ type: "text", text: `Execution started: ${
|
|
2186
|
+
return await this.vmManager.startExecution(e2, r2), t2 && await this.vmManager.setCurrentExecutionId(r2), {
|
|
2187
|
+
content: [{ type: "text", text: `Execution started: ${r2}${t2 ? " (set as current)" : ""}` }]
|
|
2144
2188
|
};
|
|
2145
2189
|
} catch (n2) {
|
|
2146
2190
|
return {
|
|
@@ -2154,18 +2198,18 @@ class M {
|
|
|
2154
2198
|
{
|
|
2155
2199
|
executionId: zod.z.string().optional()
|
|
2156
2200
|
},
|
|
2157
|
-
async ({ executionId:
|
|
2201
|
+
async ({ executionId: e2 }) => {
|
|
2158
2202
|
try {
|
|
2159
|
-
let
|
|
2160
|
-
if (!
|
|
2203
|
+
let r2 = e2;
|
|
2204
|
+
if (!r2) {
|
|
2161
2205
|
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2162
2206
|
if (!n2)
|
|
2163
2207
|
return {
|
|
2164
2208
|
content: [{ type: "text", text: "No current execution set. Use list_executions to see available executions." }]
|
|
2165
2209
|
};
|
|
2166
|
-
|
|
2210
|
+
r2 = n2;
|
|
2167
2211
|
}
|
|
2168
|
-
const t2 = await this.vmManager.getNext(
|
|
2212
|
+
const t2 = await this.vmManager.getNext(r2);
|
|
2169
2213
|
return t2.type === "completed" ? {
|
|
2170
2214
|
content: [{ type: "text", text: t2.result !== void 0 ? `Execution completed with result: ${JSON.stringify(t2.result)}` : "Execution completed" }]
|
|
2171
2215
|
} : t2.type === "waiting" ? {
|
|
@@ -2177,9 +2221,9 @@ class M {
|
|
|
2177
2221
|
content: [{ type: "text", text: "Unexpected state" }],
|
|
2178
2222
|
isError: true
|
|
2179
2223
|
};
|
|
2180
|
-
} catch (
|
|
2224
|
+
} catch (r2) {
|
|
2181
2225
|
return {
|
|
2182
|
-
content: [{ type: "text", text: `Error: ${
|
|
2226
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2183
2227
|
isError: true
|
|
2184
2228
|
};
|
|
2185
2229
|
}
|
|
@@ -2190,9 +2234,9 @@ class M {
|
|
|
2190
2234
|
executionId: zod.z.string().optional(),
|
|
2191
2235
|
result: zod.z.string()
|
|
2192
2236
|
},
|
|
2193
|
-
async ({ executionId:
|
|
2237
|
+
async ({ executionId: e2, result: r2 }) => {
|
|
2194
2238
|
try {
|
|
2195
|
-
let t2 =
|
|
2239
|
+
let t2 = e2;
|
|
2196
2240
|
if (!t2) {
|
|
2197
2241
|
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2198
2242
|
if (!n2)
|
|
@@ -2202,7 +2246,7 @@ class M {
|
|
|
2202
2246
|
};
|
|
2203
2247
|
t2 = n2;
|
|
2204
2248
|
}
|
|
2205
|
-
return await this.vmManager.reportCCResult(t2,
|
|
2249
|
+
return await this.vmManager.reportCCResult(t2, r2), {
|
|
2206
2250
|
content: [{ type: "text", text: "Execution resumed" }]
|
|
2207
2251
|
};
|
|
2208
2252
|
} catch (t2) {
|
|
@@ -2217,25 +2261,25 @@ class M {
|
|
|
2217
2261
|
{
|
|
2218
2262
|
executionId: zod.z.string().optional()
|
|
2219
2263
|
},
|
|
2220
|
-
async ({ executionId:
|
|
2264
|
+
async ({ executionId: e2 }) => {
|
|
2221
2265
|
try {
|
|
2222
|
-
let
|
|
2223
|
-
if (!
|
|
2266
|
+
let r2 = e2;
|
|
2267
|
+
if (!r2) {
|
|
2224
2268
|
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2225
2269
|
if (!n2)
|
|
2226
2270
|
return {
|
|
2227
2271
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2228
2272
|
isError: true
|
|
2229
2273
|
};
|
|
2230
|
-
|
|
2274
|
+
r2 = n2;
|
|
2231
2275
|
}
|
|
2232
|
-
const t2 = await this.vmManager.getExecutionStatus(
|
|
2276
|
+
const t2 = await this.vmManager.getExecutionStatus(r2);
|
|
2233
2277
|
return {
|
|
2234
2278
|
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2235
2279
|
};
|
|
2236
|
-
} catch (
|
|
2280
|
+
} catch (r2) {
|
|
2237
2281
|
return {
|
|
2238
|
-
content: [{ type: "text", text: `Error: ${
|
|
2282
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2239
2283
|
isError: true
|
|
2240
2284
|
};
|
|
2241
2285
|
}
|
|
@@ -2245,12 +2289,12 @@ class M {
|
|
|
2245
2289
|
{},
|
|
2246
2290
|
async () => {
|
|
2247
2291
|
try {
|
|
2248
|
-
const
|
|
2292
|
+
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((n2) => ({
|
|
2249
2293
|
executionId: n2.id,
|
|
2250
2294
|
programId: n2.programId,
|
|
2251
2295
|
state: n2.state,
|
|
2252
2296
|
created: n2.created,
|
|
2253
|
-
isCurrent: n2.id ===
|
|
2297
|
+
isCurrent: n2.id === r2,
|
|
2254
2298
|
summary: {
|
|
2255
2299
|
currentPrompt: n2.state === "AWAITING_COGNITIVE_RESULT" ? n2.ccPrompt : void 0,
|
|
2256
2300
|
tasksCompleted: 0
|
|
@@ -2260,9 +2304,9 @@ class M {
|
|
|
2260
2304
|
return {
|
|
2261
2305
|
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2262
2306
|
};
|
|
2263
|
-
} catch (
|
|
2307
|
+
} catch (e2) {
|
|
2264
2308
|
return {
|
|
2265
|
-
content: [{ type: "text", text: `Error: ${
|
|
2309
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2266
2310
|
isError: true
|
|
2267
2311
|
};
|
|
2268
2312
|
}
|
|
@@ -2272,19 +2316,19 @@ class M {
|
|
|
2272
2316
|
{
|
|
2273
2317
|
executionId: zod.z.string().optional()
|
|
2274
2318
|
},
|
|
2275
|
-
async ({ executionId:
|
|
2319
|
+
async ({ executionId: e2 }) => {
|
|
2276
2320
|
try {
|
|
2277
|
-
let
|
|
2278
|
-
if (!
|
|
2321
|
+
let r2 = e2;
|
|
2322
|
+
if (!r2) {
|
|
2279
2323
|
const a2 = await this.vmManager.getCurrentExecutionId();
|
|
2280
2324
|
if (!a2)
|
|
2281
2325
|
return {
|
|
2282
2326
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2283
2327
|
isError: true
|
|
2284
2328
|
};
|
|
2285
|
-
|
|
2329
|
+
r2 = a2;
|
|
2286
2330
|
}
|
|
2287
|
-
const t2 = await this.vmManager.getExecutionWithAttempts(
|
|
2331
|
+
const t2 = await this.vmManager.getExecutionWithAttempts(r2), n2 = await this.vmManager.getCurrentExecutionId(), c2 = {
|
|
2288
2332
|
executionId: t2.id,
|
|
2289
2333
|
programId: t2.programId,
|
|
2290
2334
|
state: t2.state,
|
|
@@ -2305,9 +2349,9 @@ class M {
|
|
|
2305
2349
|
return {
|
|
2306
2350
|
content: [{ type: "text", text: JSON.stringify(c2, null, 2) }]
|
|
2307
2351
|
};
|
|
2308
|
-
} catch (
|
|
2352
|
+
} catch (r2) {
|
|
2309
2353
|
return {
|
|
2310
|
-
content: [{ type: "text", text: `Error: ${
|
|
2354
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2311
2355
|
isError: true
|
|
2312
2356
|
};
|
|
2313
2357
|
}
|
|
@@ -2317,14 +2361,14 @@ class M {
|
|
|
2317
2361
|
{
|
|
2318
2362
|
executionId: zod.z.string()
|
|
2319
2363
|
},
|
|
2320
|
-
async ({ executionId:
|
|
2364
|
+
async ({ executionId: e2 }) => {
|
|
2321
2365
|
try {
|
|
2322
|
-
return await this.vmManager.setCurrentExecutionId(
|
|
2323
|
-
content: [{ type: "text", text: `Current execution set to: ${
|
|
2366
|
+
return await this.vmManager.setCurrentExecutionId(e2), {
|
|
2367
|
+
content: [{ type: "text", text: `Current execution set to: ${e2}` }]
|
|
2324
2368
|
};
|
|
2325
|
-
} catch (
|
|
2369
|
+
} catch (r2) {
|
|
2326
2370
|
return {
|
|
2327
|
-
content: [{ type: "text", text: `Error: ${
|
|
2371
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2328
2372
|
isError: true
|
|
2329
2373
|
};
|
|
2330
2374
|
}
|
|
@@ -2335,11 +2379,67 @@ class M {
|
|
|
2335
2379
|
executionId: zod.z.string(),
|
|
2336
2380
|
confirmToken: zod.z.string().optional()
|
|
2337
2381
|
},
|
|
2338
|
-
async ({ executionId:
|
|
2382
|
+
async ({ executionId: e2, confirmToken: r2 }) => {
|
|
2383
|
+
try {
|
|
2384
|
+
const t2 = `delete-${e2}-${Date.now()}`;
|
|
2385
|
+
return r2 ? r2 && r2.startsWith(`delete-${e2}-`) ? (await this.vmManager.deleteExecution(e2), {
|
|
2386
|
+
content: [{ type: "text", text: `Execution deleted: ${e2}` }]
|
|
2387
|
+
}) : {
|
|
2388
|
+
content: [{ type: "text", text: "Invalid confirmation token" }],
|
|
2389
|
+
isError: true
|
|
2390
|
+
} : {
|
|
2391
|
+
content: [{
|
|
2392
|
+
type: "text",
|
|
2393
|
+
text: JSON.stringify({
|
|
2394
|
+
confirmationRequired: true,
|
|
2395
|
+
message: `To delete execution '${e2}', call this tool again with the confirmation token`,
|
|
2396
|
+
token: t2
|
|
2397
|
+
}, null, 2)
|
|
2398
|
+
}]
|
|
2399
|
+
};
|
|
2400
|
+
} catch (t2) {
|
|
2401
|
+
return {
|
|
2402
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2403
|
+
isError: true
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
), this.server.tool(
|
|
2408
|
+
"list_programs",
|
|
2409
|
+
{},
|
|
2410
|
+
async () => {
|
|
2411
|
+
try {
|
|
2412
|
+
const e2 = await this.vmManager.listPrograms();
|
|
2413
|
+
if (e2.length === 0)
|
|
2414
|
+
return {
|
|
2415
|
+
content: [{ type: "text", text: "No programs loaded" }]
|
|
2416
|
+
};
|
|
2417
|
+
const r2 = e2.map((t2) => ({
|
|
2418
|
+
programId: t2.id,
|
|
2419
|
+
name: t2.name,
|
|
2420
|
+
created: t2.created
|
|
2421
|
+
}));
|
|
2422
|
+
return {
|
|
2423
|
+
content: [{ type: "text", text: JSON.stringify(r2, null, 2) }]
|
|
2424
|
+
};
|
|
2425
|
+
} catch (e2) {
|
|
2426
|
+
return {
|
|
2427
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2428
|
+
isError: true
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
), this.server.tool(
|
|
2433
|
+
"delete_program",
|
|
2434
|
+
{
|
|
2435
|
+
programId: zod.z.string(),
|
|
2436
|
+
confirmToken: zod.z.string().optional()
|
|
2437
|
+
},
|
|
2438
|
+
async ({ programId: e2, confirmToken: r2 }) => {
|
|
2339
2439
|
try {
|
|
2340
|
-
const t2 = `delete-${
|
|
2341
|
-
return
|
|
2342
|
-
content: [{ type: "text", text: `
|
|
2440
|
+
const t2 = `delete-${e2}-${Date.now()}`;
|
|
2441
|
+
return r2 ? r2 && r2.startsWith(`delete-${e2}-`) ? (await this.vmManager.deleteProgram(e2), {
|
|
2442
|
+
content: [{ type: "text", text: `Program deleted: ${e2}` }]
|
|
2343
2443
|
}) : {
|
|
2344
2444
|
content: [{ type: "text", text: "Invalid confirmation token" }],
|
|
2345
2445
|
isError: true
|
|
@@ -2348,7 +2448,7 @@ class M {
|
|
|
2348
2448
|
type: "text",
|
|
2349
2449
|
text: JSON.stringify({
|
|
2350
2450
|
confirmationRequired: true,
|
|
2351
|
-
message: `To delete
|
|
2451
|
+
message: `To delete program '${e2}', call this tool again with the confirmation token`,
|
|
2352
2452
|
token: t2
|
|
2353
2453
|
}, null, 2)
|
|
2354
2454
|
}]
|
|
@@ -2360,10 +2460,28 @@ class M {
|
|
|
2360
2460
|
};
|
|
2361
2461
|
}
|
|
2362
2462
|
}
|
|
2463
|
+
), this.server.tool(
|
|
2464
|
+
"restart",
|
|
2465
|
+
{
|
|
2466
|
+
programId: zod.z.string(),
|
|
2467
|
+
executionId: zod.z.string().optional()
|
|
2468
|
+
},
|
|
2469
|
+
async ({ programId: e2, executionId: r2 }) => {
|
|
2470
|
+
try {
|
|
2471
|
+
return {
|
|
2472
|
+
content: [{ type: "text", text: `Execution started: ${await this.vmManager.restartExecution(e2, r2)} (set as current)` }]
|
|
2473
|
+
};
|
|
2474
|
+
} catch (t2) {
|
|
2475
|
+
return {
|
|
2476
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2477
|
+
isError: true
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2363
2481
|
);
|
|
2364
2482
|
}
|
|
2365
|
-
async start(
|
|
2366
|
-
await this.vmManager.initialize(), this.transport =
|
|
2483
|
+
async start(e2) {
|
|
2484
|
+
await this.vmManager.initialize(), this.transport = e2 || new stdio_js.StdioServerTransport(), await this.server.connect(this.transport);
|
|
2367
2485
|
}
|
|
2368
2486
|
async stop() {
|
|
2369
2487
|
this.transport && (await this.transport.close(), this.transport = null), await this.vmManager.dispose();
|
|
@@ -2373,7 +2491,7 @@ class M {
|
|
|
2373
2491
|
return this.vmManager;
|
|
2374
2492
|
}
|
|
2375
2493
|
}
|
|
2376
|
-
dotenv__namespace.config({ path:
|
|
2494
|
+
dotenv__namespace.config({ path: r.resolve(__dirname, "../../../.env") });
|
|
2377
2495
|
function loadConfig() {
|
|
2378
2496
|
const env = process.env.NODE_ENV || "development";
|
|
2379
2497
|
const storageType = process.env.CVM_STORAGE_TYPE || "file";
|
|
@@ -2454,7 +2572,7 @@ function getLogger() {
|
|
|
2454
2572
|
return logger;
|
|
2455
2573
|
}
|
|
2456
2574
|
const __filename$1 = url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("main.cjs", document.baseURI).href);
|
|
2457
|
-
const __dirname$1 =
|
|
2575
|
+
const __dirname$1 = r.dirname(__filename$1);
|
|
2458
2576
|
async function main() {
|
|
2459
2577
|
let cvmServer;
|
|
2460
2578
|
try {
|
|
@@ -2463,16 +2581,16 @@ async function main() {
|
|
|
2463
2581
|
const logger2 = getLogger();
|
|
2464
2582
|
let version = "0.4.3";
|
|
2465
2583
|
const possiblePaths = [
|
|
2466
|
-
|
|
2584
|
+
r.join(__dirname$1, "..", "package.json"),
|
|
2467
2585
|
// Development
|
|
2468
|
-
|
|
2586
|
+
r.join(__dirname$1, "package.json"),
|
|
2469
2587
|
// Bundled dist
|
|
2470
|
-
|
|
2588
|
+
r.join(process.cwd(), "package.json")
|
|
2471
2589
|
// Current directory
|
|
2472
2590
|
];
|
|
2473
2591
|
for (const packageJsonPath of possiblePaths) {
|
|
2474
2592
|
try {
|
|
2475
|
-
const packageJson = JSON.parse(M$
|
|
2593
|
+
const packageJson = JSON.parse(M$1.readFileSync(packageJsonPath, "utf-8"));
|
|
2476
2594
|
if (packageJson.name === "cvm-server" && packageJson.version) {
|
|
2477
2595
|
version = packageJson.version;
|
|
2478
2596
|
break;
|
|
@@ -2487,13 +2605,13 @@ async function main() {
|
|
|
2487
2605
|
});
|
|
2488
2606
|
if (config.storage.type === "file") {
|
|
2489
2607
|
const dataDir = config.storage.dataDir || ".cvm";
|
|
2490
|
-
const fullPath =
|
|
2608
|
+
const fullPath = r.resolve(process.cwd(), dataDir);
|
|
2491
2609
|
logger2.info(`[CVM] Initializing file storage in: ${fullPath}`);
|
|
2492
2610
|
logger2.warn(`[CVM] ⚠️ Remember to add '${dataDir}/' to your .gitignore file!`);
|
|
2493
2611
|
} else {
|
|
2494
2612
|
logger2.info("[CVM] Using MongoDB storage");
|
|
2495
2613
|
}
|
|
2496
|
-
cvmServer = new
|
|
2614
|
+
cvmServer = new $(version);
|
|
2497
2615
|
await cvmServer.start();
|
|
2498
2616
|
logger2.info("CVM Server is running and ready to accept MCP connections");
|
|
2499
2617
|
process.on("SIGINT", async () => {
|