cvm-server 0.4.3 → 0.6.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.
Files changed (2) hide show
  1. package/main.cjs +822 -385
  2. package/package.json +1 -1
package/main.cjs CHANGED
@@ -2,73 +2,75 @@
2
2
  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
- const s$1 = require("typescript");
6
- const fs = require("fs");
7
- const c$1 = require("path");
5
+ const s$2 = require("typescript");
6
+ const M = require("fs");
7
+ const c$2 = require("path");
8
8
  const mongodb = require("mongodb");
9
+ const promises = require("fs/promises");
9
10
  const dotenv = require("dotenv");
10
11
  const url = require("url");
11
12
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
12
- function _interopNamespaceDefault(e) {
13
+ function _interopNamespaceDefault(e2) {
13
14
  const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
14
- if (e) {
15
- for (const k2 in e) {
15
+ if (e2) {
16
+ for (const k2 in e2) {
16
17
  if (k2 !== "default") {
17
- const d = Object.getOwnPropertyDescriptor(e, k2);
18
- Object.defineProperty(n2, k2, d.get ? d : {
18
+ const d2 = Object.getOwnPropertyDescriptor(e2, k2);
19
+ Object.defineProperty(n2, k2, d2.get ? d2 : {
19
20
  enumerable: true,
20
- get: () => e[k2]
21
+ get: () => e2[k2]
21
22
  });
22
23
  }
23
24
  }
24
25
  }
25
- n2.default = e;
26
+ n2.default = e2;
26
27
  return Object.freeze(n2);
27
28
  }
28
- const s__namespace = /* @__PURE__ */ _interopNamespaceDefault(s$1);
29
- const c__namespace = /* @__PURE__ */ _interopNamespaceDefault(c$1);
29
+ const s__namespace = /* @__PURE__ */ _interopNamespaceDefault(s$2);
30
+ const M__namespace = /* @__PURE__ */ _interopNamespaceDefault(M);
31
+ const c__namespace = /* @__PURE__ */ _interopNamespaceDefault(c$2);
30
32
  const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
31
- var S = Object.defineProperty;
32
- var p$1 = (i2, a2, e) => a2 in i2 ? S(i2, a2, { enumerable: true, configurable: true, writable: true, value: e }) : i2[a2] = e;
33
- var E$1 = (i2, a2, e) => p$1(i2, typeof a2 != "symbol" ? a2 + "" : a2, e);
34
- var n$1 = /* @__PURE__ */ ((i2) => (i2.PUSH = "PUSH", i2.POP = "POP", i2.LOAD = "LOAD", i2.STORE = "STORE", i2.CONCAT = "CONCAT", i2.ARRAY_NEW = "ARRAY_NEW", i2.ARRAY_PUSH = "ARRAY_PUSH", i2.ARRAY_GET = "ARRAY_GET", i2.ARRAY_SET = "ARRAY_SET", i2.ARRAY_LEN = "ARRAY_LEN", i2.STRING_LEN = "STRING_LEN", i2.LENGTH = "LENGTH", i2.JSON_PARSE = "JSON_PARSE", i2.TYPEOF = "TYPEOF", i2.ADD = "ADD", i2.SUB = "SUB", i2.MUL = "MUL", i2.DIV = "DIV", i2.MOD = "MOD", i2.EQ = "EQ", i2.NEQ = "NEQ", i2.LT = "LT", i2.GT = "GT", i2.LTE = "LTE", i2.GTE = "GTE", i2.EQ_STRICT = "EQ_STRICT", i2.NEQ_STRICT = "NEQ_STRICT", i2.JUMP = "JUMP", i2.JUMP_IF = "JUMP_IF", i2.JUMP_IF_FALSE = "JUMP_IF_FALSE", i2.JUMP_IF_TRUE = "JUMP_IF_TRUE", i2.CALL = "CALL", i2.RETURN = "RETURN", i2.AND = "AND", i2.OR = "OR", i2.NOT = "NOT", i2.BREAK = "BREAK", i2.CONTINUE = "CONTINUE", i2.ITER_START = "ITER_START", i2.ITER_NEXT = "ITER_NEXT", i2.ITER_END = "ITER_END", i2.FS_LIST_FILES = "FS_LIST_FILES", i2.CC = "CC", i2.PRINT = "PRINT", i2.HALT = "HALT", i2))(n$1 || {});
35
- function A(i2) {
36
- const a2 = [], e = [];
37
- let x = false, m2 = false;
38
- const c2 = s__namespace.createSourceFile(
33
+ var R = Object.defineProperty;
34
+ var h$1 = (n2, l2, e2) => l2 in n2 ? R(n2, l2, { enumerable: true, configurable: true, writable: true, value: e2 }) : n2[l2] = e2;
35
+ var u$1 = (n2, l2, e2) => h$1(n2, typeof l2 != "symbol" ? l2 + "" : l2, e2);
36
+ var r$1 = /* @__PURE__ */ ((n2) => (n2.PUSH = "PUSH", n2.PUSH_UNDEFINED = "PUSH_UNDEFINED", n2.POP = "POP", n2.LOAD = "LOAD", n2.STORE = "STORE", n2.CONCAT = "CONCAT", n2.ARRAY_NEW = "ARRAY_NEW", n2.ARRAY_PUSH = "ARRAY_PUSH", n2.ARRAY_GET = "ARRAY_GET", n2.ARRAY_SET = "ARRAY_SET", n2.ARRAY_LEN = "ARRAY_LEN", n2.STRING_LEN = "STRING_LEN", n2.STRING_SUBSTRING = "STRING_SUBSTRING", n2.STRING_INDEXOF = "STRING_INDEXOF", n2.STRING_SPLIT = "STRING_SPLIT", n2.STRING_SLICE = "STRING_SLICE", n2.STRING_CHARAT = "STRING_CHARAT", n2.STRING_TOUPPERCASE = "STRING_TOUPPERCASE", n2.STRING_TOLOWERCASE = "STRING_TOLOWERCASE", n2.LENGTH = "LENGTH", n2.JSON_PARSE = "JSON_PARSE", n2.TYPEOF = "TYPEOF", n2.ADD = "ADD", n2.SUB = "SUB", n2.MUL = "MUL", n2.DIV = "DIV", n2.MOD = "MOD", n2.UNARY_MINUS = "UNARY_MINUS", n2.UNARY_PLUS = "UNARY_PLUS", n2.INC = "INC", n2.DEC = "DEC", n2.EQ = "EQ", n2.NEQ = "NEQ", n2.LT = "LT", n2.GT = "GT", n2.LTE = "LTE", n2.GTE = "GTE", n2.EQ_STRICT = "EQ_STRICT", n2.NEQ_STRICT = "NEQ_STRICT", n2.JUMP = "JUMP", n2.JUMP_IF = "JUMP_IF", n2.JUMP_IF_FALSE = "JUMP_IF_FALSE", n2.JUMP_IF_TRUE = "JUMP_IF_TRUE", n2.CALL = "CALL", n2.RETURN = "RETURN", n2.AND = "AND", n2.OR = "OR", n2.NOT = "NOT", n2.BREAK = "BREAK", n2.CONTINUE = "CONTINUE", n2.ITER_START = "ITER_START", n2.ITER_NEXT = "ITER_NEXT", n2.ITER_END = "ITER_END", n2.FS_LIST_FILES = "FS_LIST_FILES", n2.CC = "CC", n2.PRINT = "PRINT", n2.HALT = "HALT", n2))(r$1 || {});
37
+ function I(n2) {
38
+ const l2 = [], e2 = [];
39
+ let o2 = false, T = false;
40
+ const a2 = s__namespace.createSourceFile(
39
41
  "program.ts",
40
- i2,
42
+ n2,
41
43
  s__namespace.ScriptTarget.Latest,
42
44
  true
43
45
  );
44
- function t2(r2) {
45
- if (s__namespace.isFunctionDeclaration(r2) && r2.name && r2.name.text === "main" && (x = true, r2.parameters.length > 0 && a2.push("main() must not have parameters")), s__namespace.isExpressionStatement(r2) && r2.parent === c2) {
46
- const l2 = r2.expression;
47
- s__namespace.isCallExpression(l2) && s__namespace.isIdentifier(l2.expression) && l2.expression.text === "main" && (m2 = true);
46
+ function t2(i2) {
47
+ if (s__namespace.isFunctionDeclaration(i2) && i2.name && i2.name.text === "main" && (o2 = true, i2.parameters.length > 0 && l2.push("main() must not have parameters")), s__namespace.isExpressionStatement(i2) && i2.parent === a2) {
48
+ const c2 = i2.expression;
49
+ s__namespace.isCallExpression(c2) && s__namespace.isIdentifier(c2.expression) && c2.expression.text === "main" && (T = true);
48
50
  }
49
- if (s__namespace.isCallExpression(r2) && s__namespace.isIdentifier(r2.expression)) {
50
- const l2 = r2.expression.text;
51
- ["setTimeout", "fetch", "require", "import"].includes(l2) && a2.push(`Unsupported function: ${l2}`);
51
+ if (s__namespace.isCallExpression(i2) && s__namespace.isIdentifier(i2.expression)) {
52
+ const c2 = i2.expression.text;
53
+ ["setTimeout", "fetch", "require", "import"].includes(c2) && l2.push(`Unsupported function: ${c2}`);
52
54
  }
53
- s__namespace.forEachChild(r2, t2);
55
+ s__namespace.forEachChild(i2, t2);
54
56
  }
55
- return t2(c2), x || a2.push("Program must have a main() function"), x && !m2 && a2.push("main() must be called at the top level"), a2.length === 0 && e.push({ op: n$1.HALT }), {
56
- bytecode: e,
57
- errors: a2,
58
- hasMain: x
57
+ return t2(a2), o2 || l2.push("Program must have a main() function"), o2 && !T && l2.push("main() must be called at the top level"), l2.length === 0 && e2.push({ op: r$1.HALT }), {
58
+ bytecode: e2,
59
+ errors: l2,
60
+ hasMain: o2
59
61
  };
60
62
  }
61
- let h$1 = class h {
63
+ let N$1 = class N {
62
64
  constructor() {
63
- E$1(this, "bytecode", []);
64
- E$1(this, "contextStack", []);
65
+ u$1(this, "bytecode", []);
66
+ u$1(this, "contextStack", []);
65
67
  }
66
68
  /**
67
69
  * Emit an instruction and return its index
68
70
  */
69
- emit(a2, e) {
70
- const x = this.bytecode.length;
71
- return this.bytecode.push({ op: a2, arg: e }), x;
71
+ emit(l2, e2) {
72
+ const o2 = this.bytecode.length;
73
+ return this.bytecode.push({ op: l2, arg: e2 }), o2;
72
74
  }
73
75
  /**
74
76
  * Get the current address (next instruction index)
@@ -79,20 +81,20 @@ let h$1 = class h {
79
81
  /**
80
82
  * Patch a jump instruction with the target address
81
83
  */
82
- patchJump(a2, e) {
83
- a2 >= 0 && a2 < this.bytecode.length && (this.bytecode[a2].arg = e);
84
+ patchJump(l2, e2) {
85
+ l2 >= 0 && l2 < this.bytecode.length && (this.bytecode[l2].arg = e2);
84
86
  }
85
87
  /**
86
88
  * Patch multiple jump instructions with the same target
87
89
  */
88
- patchJumps(a2, e) {
89
- a2.forEach((x) => this.patchJump(x, e));
90
+ patchJumps(l2, e2) {
91
+ l2.forEach((o2) => this.patchJump(o2, e2));
90
92
  }
91
93
  /**
92
94
  * Push a new jump context onto the stack
93
95
  */
94
- pushContext(a2) {
95
- this.contextStack.push(a2);
96
+ pushContext(l2) {
97
+ this.contextStack.push(l2);
96
98
  }
97
99
  /**
98
100
  * Pop the current jump context from the stack
@@ -110,9 +112,9 @@ let h$1 = class h {
110
112
  * Find the nearest loop context (for break/continue)
111
113
  */
112
114
  findLoopContext() {
113
- for (let a2 = this.contextStack.length - 1; a2 >= 0; a2--)
114
- if (this.contextStack[a2].type === "loop")
115
- return this.contextStack[a2];
115
+ for (let l2 = this.contextStack.length - 1; l2 >= 0; l2--)
116
+ if (this.contextStack[l2].type === "loop" || this.contextStack[l2].type === "foreach")
117
+ return this.contextStack[l2];
116
118
  return null;
117
119
  }
118
120
  /**
@@ -134,171 +136,279 @@ let h$1 = class h {
134
136
  return [...this.contextStack];
135
137
  }
136
138
  };
137
- function k(i2) {
138
- const a2 = A(i2);
139
- if (a2.errors.length > 0)
139
+ function k(n2) {
140
+ const l2 = I(n2);
141
+ if (l2.errors.length > 0)
140
142
  return {
141
143
  success: false,
142
144
  bytecode: [],
143
- errors: a2.errors
145
+ errors: l2.errors
144
146
  };
145
- const e = new h$1(), x = s__namespace.createSourceFile("program.ts", i2, s__namespace.ScriptTarget.Latest, true);
146
- function m2(t2) {
147
+ const e2 = new N$1(), o2 = s__namespace.createSourceFile("program.ts", n2, s__namespace.ScriptTarget.Latest, true);
148
+ function T(t2) {
147
149
  if (s__namespace.isIfStatement(t2)) {
148
- c2(t2.expression);
149
- const r2 = e.emit(n$1.JUMP_IF_FALSE, -1), l2 = {
150
+ a2(t2.expression);
151
+ const i2 = e2.emit(r$1.JUMP_IF_FALSE, -1), c2 = {
150
152
  type: "if",
151
153
  endTargets: []
152
154
  };
153
- if (t2.elseStatement ? l2.elseTarget = r2 : l2.endTargets.push(r2), e.pushContext(l2), m2(t2.thenStatement), t2.elseStatement) {
154
- const o2 = e.emit(n$1.JUMP, -1);
155
- l2.endTargets.push(o2);
156
- const u2 = e.currentAddress();
157
- e.patchJump(r2, u2), m2(t2.elseStatement);
155
+ if (t2.elseStatement ? c2.elseTarget = i2 : c2.endTargets.push(i2), e2.pushContext(c2), T(t2.thenStatement), t2.elseStatement) {
156
+ const x = e2.emit(r$1.JUMP, -1);
157
+ c2.endTargets.push(x);
158
+ const S = e2.currentAddress();
159
+ e2.patchJump(i2, S), T(t2.elseStatement);
158
160
  }
159
- const T2 = e.popContext();
160
- if (T2) {
161
- const o2 = e.currentAddress();
162
- e.patchJumps(T2.endTargets, o2);
161
+ const m2 = e2.popContext();
162
+ if (m2) {
163
+ const x = e2.currentAddress();
164
+ e2.patchJumps(m2.endTargets, x);
163
165
  }
164
166
  } else if (s__namespace.isWhileStatement(t2)) {
165
- const r2 = e.currentAddress();
166
- c2(t2.expression);
167
- const T2 = {
167
+ const i2 = e2.currentAddress();
168
+ a2(t2.expression);
169
+ const m2 = {
168
170
  type: "loop",
169
- breakTargets: [e.emit(n$1.JUMP_IF_FALSE, -1)],
171
+ breakTargets: [e2.emit(r$1.JUMP_IF_FALSE, -1)],
172
+ continueTargets: [],
173
+ endTargets: [],
174
+ startAddress: i2
175
+ };
176
+ e2.pushContext(m2), T(t2.statement), e2.emit(r$1.JUMP, i2);
177
+ const x = e2.popContext();
178
+ if (x) {
179
+ const S = e2.currentAddress();
180
+ e2.patchJumps(x.breakTargets || [], S);
181
+ }
182
+ } else if (s__namespace.isForOfStatement(t2)) {
183
+ const i2 = t2.initializer, c2 = t2.expression;
184
+ let m2;
185
+ if (s__namespace.isVariableDeclarationList(i2))
186
+ m2 = i2.declarations[0].name.getText();
187
+ else if (s__namespace.isIdentifier(i2))
188
+ m2 = i2.text;
189
+ else
190
+ throw new Error("Unsupported for-of variable declaration");
191
+ a2(c2), e2.emit(r$1.ITER_START);
192
+ const x = e2.currentAddress();
193
+ e2.emit(r$1.ITER_NEXT);
194
+ const S = e2.emit(r$1.JUMP_IF_FALSE, -1);
195
+ e2.emit(r$1.STORE, m2);
196
+ const A2 = {
197
+ type: "foreach",
198
+ breakTargets: [S],
170
199
  continueTargets: [],
171
200
  endTargets: [],
172
- startAddress: r2
201
+ startAddress: x,
202
+ iterVariable: m2
173
203
  };
174
- e.pushContext(T2), m2(t2.statement), e.emit(n$1.JUMP, r2);
175
- const o2 = e.popContext();
176
- if (o2) {
177
- const u2 = e.currentAddress();
178
- e.patchJumps(o2.breakTargets || [], u2);
204
+ e2.pushContext(A2), T(t2.statement), e2.emit(r$1.JUMP, x);
205
+ const f2 = e2.popContext();
206
+ if (f2) {
207
+ e2.emit(r$1.ITER_END);
208
+ const p2 = e2.currentAddress();
209
+ e2.patchJumps(f2.breakTargets || [], p2);
179
210
  }
180
211
  } else if (s__namespace.isBlock(t2))
181
- t2.statements.forEach((r2) => {
182
- m2(r2);
212
+ t2.statements.forEach((i2) => {
213
+ T(i2);
183
214
  });
184
215
  else if (s__namespace.isExpressionStatement(t2)) {
185
- const r2 = t2.expression;
186
- if (s__namespace.isCallExpression(r2) && s__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.expression.getText() === "console" && r2.expression.name.getText() === "log")
187
- r2.arguments.forEach((l2) => {
188
- c2(l2);
189
- }), e.emit(n$1.PRINT);
190
- else if (s__namespace.isCallExpression(r2) && s__namespace.isIdentifier(r2.expression) && r2.expression.text === "CC")
191
- r2.arguments.length > 0 && c2(r2.arguments[0]), e.emit(n$1.CC), e.emit(n$1.POP);
192
- else if (s__namespace.isCallExpression(r2) && s__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.name.getText() === "push")
193
- c2(r2.expression.expression), r2.arguments.length > 0 && c2(r2.arguments[0]), e.emit(n$1.ARRAY_PUSH);
194
- else if (s__namespace.isBinaryExpression(r2) && r2.operatorToken.kind === s__namespace.SyntaxKind.EqualsToken) {
195
- if (c2(r2.right), s__namespace.isIdentifier(r2.left))
196
- e.emit(n$1.STORE, r2.left.text);
197
- else if (s__namespace.isElementAccessExpression(r2.left)) {
198
- const l2 = `__temp_${e.getBytecode().length}`;
199
- e.emit(n$1.STORE, l2), c2(r2.left.expression), c2(r2.left.argumentExpression), e.emit(n$1.LOAD, l2), e.emit(n$1.ARRAY_SET);
216
+ const i2 = t2.expression;
217
+ if (s__namespace.isBinaryExpression(i2)) {
218
+ const c2 = i2.operatorToken.kind;
219
+ if (c2 === s__namespace.SyntaxKind.PlusEqualsToken || c2 === s__namespace.SyntaxKind.MinusEqualsToken || c2 === s__namespace.SyntaxKind.AsteriskEqualsToken || c2 === s__namespace.SyntaxKind.SlashEqualsToken || c2 === s__namespace.SyntaxKind.PercentEqualsToken) {
220
+ if (s__namespace.isIdentifier(i2.left)) {
221
+ switch (e2.emit(r$1.LOAD, i2.left.text), a2(i2.right), c2) {
222
+ case s__namespace.SyntaxKind.PlusEqualsToken:
223
+ s__namespace.isStringLiteral(i2.right) ? e2.emit(r$1.CONCAT) : e2.emit(r$1.ADD);
224
+ break;
225
+ case s__namespace.SyntaxKind.MinusEqualsToken:
226
+ e2.emit(r$1.SUB);
227
+ break;
228
+ case s__namespace.SyntaxKind.AsteriskEqualsToken:
229
+ e2.emit(r$1.MUL);
230
+ break;
231
+ case s__namespace.SyntaxKind.SlashEqualsToken:
232
+ e2.emit(r$1.DIV);
233
+ break;
234
+ case s__namespace.SyntaxKind.PercentEqualsToken:
235
+ e2.emit(r$1.MOD);
236
+ break;
237
+ }
238
+ e2.emit(r$1.STORE, i2.left.text);
239
+ } else if (s__namespace.isElementAccessExpression(i2.left))
240
+ throw new Error("Compound assignment to array elements not yet supported");
241
+ return;
242
+ } else if (c2 === s__namespace.SyntaxKind.EqualsToken) {
243
+ if (a2(i2.right), s__namespace.isIdentifier(i2.left))
244
+ e2.emit(r$1.STORE, i2.left.text);
245
+ else if (s__namespace.isElementAccessExpression(i2.left)) {
246
+ const m2 = `__temp_${e2.getBytecode().length}`;
247
+ e2.emit(r$1.STORE, m2), a2(i2.left.expression), a2(i2.left.argumentExpression), e2.emit(r$1.LOAD, m2), e2.emit(r$1.ARRAY_SET);
248
+ }
249
+ return;
200
250
  }
201
251
  }
252
+ s__namespace.isCallExpression(i2) && s__namespace.isPropertyAccessExpression(i2.expression) && i2.expression.expression.getText() === "console" && i2.expression.name.getText() === "log" ? (i2.arguments.forEach((c2) => {
253
+ a2(c2);
254
+ }), e2.emit(r$1.PRINT)) : s__namespace.isCallExpression(i2) && s__namespace.isIdentifier(i2.expression) && i2.expression.text === "CC" ? (i2.arguments.length > 0 && a2(i2.arguments[0]), e2.emit(r$1.CC), e2.emit(r$1.POP)) : s__namespace.isCallExpression(i2) && s__namespace.isPropertyAccessExpression(i2.expression) && i2.expression.name.getText() === "push" ? (a2(i2.expression.expression), i2.arguments.length > 0 && a2(i2.arguments[0]), e2.emit(r$1.ARRAY_PUSH)) : (s__namespace.isPostfixUnaryExpression(i2) || s__namespace.isPrefixUnaryExpression(i2)) && (a2(i2), e2.emit(r$1.POP));
202
255
  } else if (s__namespace.isVariableStatement(t2)) {
203
- const r2 = t2.declarationList.declarations[0];
204
- r2.initializer && (c2(r2.initializer), e.emit(n$1.STORE, r2.name.getText()));
205
- } else s__namespace.isReturnStatement(t2) && (t2.expression ? c2(t2.expression) : e.emit(n$1.PUSH, null), e.emit(n$1.RETURN));
256
+ const i2 = t2.declarationList.declarations[0];
257
+ i2.initializer && (a2(i2.initializer), e2.emit(r$1.STORE, i2.name.getText()));
258
+ } else if (s__namespace.isReturnStatement(t2))
259
+ t2.expression ? a2(t2.expression) : e2.emit(r$1.PUSH, null), e2.emit(r$1.RETURN);
260
+ else if (s__namespace.isBreakStatement(t2)) {
261
+ const i2 = e2.findLoopContext();
262
+ if (i2) {
263
+ i2.type === "foreach" && e2.emit(r$1.ITER_END);
264
+ const c2 = e2.emit(r$1.BREAK, -1);
265
+ i2.breakTargets = i2.breakTargets || [], i2.breakTargets.push(c2);
266
+ } else
267
+ throw new Error("break statement not in loop");
268
+ } else if (s__namespace.isContinueStatement(t2)) {
269
+ const i2 = e2.findLoopContext();
270
+ if (i2 && i2.startAddress !== void 0) {
271
+ const c2 = e2.emit(r$1.CONTINUE, i2.startAddress);
272
+ i2.continueTargets = i2.continueTargets || [], i2.continueTargets.push(c2);
273
+ } else
274
+ throw new Error("continue statement not in loop");
275
+ }
206
276
  }
207
- function c2(t2) {
277
+ function a2(t2) {
208
278
  if (s__namespace.isStringLiteral(t2))
209
- e.emit(n$1.PUSH, t2.text);
279
+ e2.emit(r$1.PUSH, t2.text);
210
280
  else if (s__namespace.isNumericLiteral(t2))
211
- e.emit(n$1.PUSH, Number(t2.text));
281
+ e2.emit(r$1.PUSH, Number(t2.text));
212
282
  else if (t2.kind === s__namespace.SyntaxKind.TrueKeyword)
213
- e.emit(n$1.PUSH, true);
283
+ e2.emit(r$1.PUSH, true);
214
284
  else if (t2.kind === s__namespace.SyntaxKind.FalseKeyword)
215
- e.emit(n$1.PUSH, false);
285
+ e2.emit(r$1.PUSH, false);
216
286
  else if (t2.kind === s__namespace.SyntaxKind.NullKeyword)
217
- e.emit(n$1.PUSH, null);
287
+ e2.emit(r$1.PUSH, null);
218
288
  else if (s__namespace.isArrayLiteralExpression(t2))
219
- e.emit(n$1.ARRAY_NEW), t2.elements.forEach((r2) => {
220
- c2(r2), e.emit(n$1.ARRAY_PUSH);
289
+ e2.emit(r$1.ARRAY_NEW), t2.elements.forEach((i2) => {
290
+ a2(i2), e2.emit(r$1.ARRAY_PUSH);
221
291
  });
222
292
  else if (s__namespace.isElementAccessExpression(t2))
223
- c2(t2.expression), t2.argumentExpression && c2(t2.argumentExpression), e.emit(n$1.ARRAY_GET);
293
+ a2(t2.expression), t2.argumentExpression && a2(t2.argumentExpression), e2.emit(r$1.ARRAY_GET);
224
294
  else if (s__namespace.isPropertyAccessExpression(t2) && t2.name.text === "length")
225
- c2(t2.expression), e.emit(n$1.LENGTH);
295
+ a2(t2.expression), e2.emit(r$1.LENGTH);
226
296
  else if (s__namespace.isIdentifier(t2))
227
- e.emit(n$1.LOAD, t2.text);
228
- else if (s__namespace.isCallExpression(t2))
229
- s__namespace.isPropertyAccessExpression(t2.expression) && s__namespace.isIdentifier(t2.expression.expression) && t2.expression.expression.text === "JSON" && t2.expression.name.text === "parse" ? (t2.arguments.length > 0 && c2(t2.arguments[0]), e.emit(n$1.JSON_PARSE)) : s__namespace.isIdentifier(t2.expression) && t2.expression.text === "CC" && (t2.arguments.length > 0 && c2(t2.arguments[0]), e.emit(n$1.CC));
230
- else if (s__namespace.isParenthesizedExpression(t2))
231
- c2(t2.expression);
297
+ t2.text === "undefined" ? e2.emit(r$1.PUSH_UNDEFINED) : e2.emit(r$1.LOAD, t2.text);
298
+ else if (s__namespace.isCallExpression(t2)) {
299
+ if (s__namespace.isPropertyAccessExpression(t2.expression) && s__namespace.isIdentifier(t2.expression.expression) && t2.expression.expression.text === "fs" && t2.expression.name.text === "listFiles")
300
+ t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, "."), t2.arguments.length > 1 && a2(t2.arguments[1]), e2.emit(r$1.FS_LIST_FILES);
301
+ else if (s__namespace.isPropertyAccessExpression(t2.expression) && s__namespace.isIdentifier(t2.expression.expression) && t2.expression.expression.text === "JSON" && t2.expression.name.text === "parse")
302
+ t2.arguments.length > 0 && a2(t2.arguments[0]), e2.emit(r$1.JSON_PARSE);
303
+ else if (s__namespace.isIdentifier(t2.expression) && t2.expression.text === "CC")
304
+ t2.arguments.length > 0 && a2(t2.arguments[0]), e2.emit(r$1.CC);
305
+ else if (s__namespace.isPropertyAccessExpression(t2.expression)) {
306
+ const i2 = t2.expression.name.text;
307
+ i2 === "substring" ? (a2(t2.expression.expression), t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, 0), t2.arguments.length > 1 && a2(t2.arguments[1]), e2.emit(r$1.STRING_SUBSTRING)) : i2 === "indexOf" ? (a2(t2.expression.expression), t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, ""), e2.emit(r$1.STRING_INDEXOF)) : i2 === "split" ? (a2(t2.expression.expression), t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, ""), e2.emit(r$1.STRING_SPLIT)) : i2 === "slice" ? (a2(t2.expression.expression), t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, 0), t2.arguments.length > 1 && a2(t2.arguments[1]), e2.emit(r$1.STRING_SLICE)) : i2 === "charAt" ? (a2(t2.expression.expression), t2.arguments.length > 0 ? a2(t2.arguments[0]) : e2.emit(r$1.PUSH, 0), e2.emit(r$1.STRING_CHARAT)) : i2 === "toUpperCase" ? (a2(t2.expression.expression), e2.emit(r$1.STRING_TOUPPERCASE)) : i2 === "toLowerCase" && (a2(t2.expression.expression), e2.emit(r$1.STRING_TOLOWERCASE));
308
+ }
309
+ } else if (s__namespace.isParenthesizedExpression(t2))
310
+ a2(t2.expression);
232
311
  else if (s__namespace.isBinaryExpression(t2)) {
233
- const r2 = t2.operatorToken.kind;
234
- switch (c2(t2.left), c2(t2.right), r2) {
312
+ const i2 = t2.operatorToken.kind;
313
+ switch (a2(t2.left), a2(t2.right), i2) {
235
314
  case s__namespace.SyntaxKind.PlusToken:
236
- f$1(t2.left, t2.right) ? e.emit(n$1.CONCAT) : e.emit(n$1.ADD);
315
+ E(t2.left, t2.right) ? e2.emit(r$1.CONCAT) : e2.emit(r$1.ADD);
237
316
  break;
238
317
  case s__namespace.SyntaxKind.MinusToken:
239
- e.emit(n$1.SUB);
318
+ e2.emit(r$1.SUB);
240
319
  break;
241
320
  case s__namespace.SyntaxKind.AsteriskToken:
242
- e.emit(n$1.MUL);
321
+ e2.emit(r$1.MUL);
243
322
  break;
244
323
  case s__namespace.SyntaxKind.SlashToken:
245
- e.emit(n$1.DIV);
324
+ e2.emit(r$1.DIV);
246
325
  break;
247
326
  case s__namespace.SyntaxKind.PercentToken:
248
- e.emit(n$1.MOD);
327
+ e2.emit(r$1.MOD);
249
328
  break;
250
329
  case s__namespace.SyntaxKind.EqualsEqualsToken:
251
- e.emit(n$1.EQ);
330
+ e2.emit(r$1.EQ);
252
331
  break;
253
332
  case s__namespace.SyntaxKind.ExclamationEqualsToken:
254
- e.emit(n$1.NEQ);
333
+ e2.emit(r$1.NEQ);
255
334
  break;
256
335
  case s__namespace.SyntaxKind.LessThanToken:
257
- e.emit(n$1.LT);
336
+ e2.emit(r$1.LT);
258
337
  break;
259
338
  case s__namespace.SyntaxKind.GreaterThanToken:
260
- e.emit(n$1.GT);
339
+ e2.emit(r$1.GT);
261
340
  break;
262
341
  case s__namespace.SyntaxKind.LessThanEqualsToken:
263
- e.emit(n$1.LTE);
342
+ e2.emit(r$1.LTE);
264
343
  break;
265
344
  case s__namespace.SyntaxKind.GreaterThanEqualsToken:
266
- e.emit(n$1.GTE);
345
+ e2.emit(r$1.GTE);
267
346
  break;
268
347
  case s__namespace.SyntaxKind.EqualsEqualsEqualsToken:
269
- e.emit(n$1.EQ_STRICT);
348
+ e2.emit(r$1.EQ_STRICT);
270
349
  break;
271
350
  case s__namespace.SyntaxKind.ExclamationEqualsEqualsToken:
272
- e.emit(n$1.NEQ_STRICT);
351
+ e2.emit(r$1.NEQ_STRICT);
273
352
  break;
274
353
  case s__namespace.SyntaxKind.AmpersandAmpersandToken:
275
- e.emit(n$1.AND);
354
+ e2.emit(r$1.AND);
276
355
  break;
277
356
  case s__namespace.SyntaxKind.BarBarToken:
278
- e.emit(n$1.OR);
357
+ e2.emit(r$1.OR);
279
358
  break;
280
359
  }
281
360
  } else if (s__namespace.isPrefixUnaryExpression(t2))
282
361
  switch (t2.operator) {
283
362
  case s__namespace.SyntaxKind.ExclamationToken:
284
- c2(t2.operand), e.emit(n$1.NOT);
363
+ a2(t2.operand), e2.emit(r$1.NOT);
364
+ break;
365
+ case s__namespace.SyntaxKind.MinusToken:
366
+ a2(t2.operand), e2.emit(r$1.UNARY_MINUS);
367
+ break;
368
+ case s__namespace.SyntaxKind.PlusToken:
369
+ a2(t2.operand), e2.emit(r$1.UNARY_PLUS);
370
+ break;
371
+ case s__namespace.SyntaxKind.PlusPlusToken:
372
+ s__namespace.isIdentifier(t2.operand) && (e2.emit(r$1.PUSH, t2.operand.text), e2.emit(r$1.INC, false));
373
+ break;
374
+ case s__namespace.SyntaxKind.MinusMinusToken:
375
+ s__namespace.isIdentifier(t2.operand) && (e2.emit(r$1.PUSH, t2.operand.text), e2.emit(r$1.DEC, false));
376
+ break;
377
+ }
378
+ else if (s__namespace.isPostfixUnaryExpression(t2))
379
+ switch (t2.operator) {
380
+ case s__namespace.SyntaxKind.PlusPlusToken:
381
+ s__namespace.isIdentifier(t2.operand) && (e2.emit(r$1.PUSH, t2.operand.text), e2.emit(r$1.INC, true));
382
+ break;
383
+ case s__namespace.SyntaxKind.MinusMinusToken:
384
+ s__namespace.isIdentifier(t2.operand) && (e2.emit(r$1.PUSH, t2.operand.text), e2.emit(r$1.DEC, true));
285
385
  break;
286
386
  }
287
- else s__namespace.isTypeOfExpression(t2) && (c2(t2.expression), e.emit(n$1.TYPEOF));
387
+ else if (s__namespace.isTypeOfExpression(t2))
388
+ a2(t2.expression), e2.emit(r$1.TYPEOF);
389
+ else if (s__namespace.isConditionalExpression(t2)) {
390
+ a2(t2.condition);
391
+ const i2 = e2.emit(r$1.JUMP_IF_FALSE, -1);
392
+ a2(t2.whenTrue);
393
+ const c2 = e2.emit(r$1.JUMP, -1), m2 = e2.currentAddress();
394
+ e2.patchJump(i2, m2), a2(t2.whenFalse);
395
+ const x = e2.currentAddress();
396
+ e2.patchJump(c2, x);
397
+ }
288
398
  }
289
- return x.forEachChild((t2) => {
290
- var r2;
291
- s__namespace.isFunctionDeclaration(t2) && ((r2 = t2.name) == null ? void 0 : r2.text) === "main" && t2.body && t2.body.statements.forEach((l2) => {
292
- m2(l2);
399
+ return o2.forEachChild((t2) => {
400
+ var i2;
401
+ s__namespace.isFunctionDeclaration(t2) && ((i2 = t2.name) == null ? void 0 : i2.text) === "main" && t2.body && t2.body.statements.forEach((c2) => {
402
+ T(c2);
293
403
  });
294
- }), e.emit(n$1.HALT), {
404
+ }), e2.emit(r$1.HALT), {
295
405
  success: true,
296
- bytecode: e.getBytecode(),
406
+ bytecode: e2.getBytecode(),
297
407
  errors: []
298
408
  };
299
409
  }
300
- function f$1(i2, a2) {
301
- return !!(s__namespace.isStringLiteral(i2) || s__namespace.isStringLiteral(a2) || s__namespace.isBinaryExpression(i2) && i2.operatorToken.kind === s__namespace.SyntaxKind.PlusToken && f$1(i2.left, i2.right) || s__namespace.isBinaryExpression(a2) && a2.operatorToken.kind === s__namespace.SyntaxKind.PlusToken && f$1(a2.left, a2.right));
410
+ function E(n2, l2) {
411
+ return !!(s__namespace.isStringLiteral(n2) || s__namespace.isStringLiteral(l2) || s__namespace.isBinaryExpression(n2) && n2.operatorToken.kind === s__namespace.SyntaxKind.PlusToken && E(n2.left, n2.right) || s__namespace.isBinaryExpression(l2) && l2.operatorToken.kind === s__namespace.SyntaxKind.PlusToken && E(l2.left, l2.right));
302
412
  }
303
413
  function n(r2) {
304
414
  return typeof r2 == "string";
@@ -306,41 +416,48 @@ function n(r2) {
306
416
  function t(r2) {
307
417
  return typeof r2 == "number";
308
418
  }
309
- function i$1(r2) {
419
+ function i(r2) {
310
420
  return typeof r2 == "boolean";
311
421
  }
312
422
  function f(r2) {
313
423
  return r2 === null;
314
424
  }
315
- function o$1(r2) {
425
+ function e(r2) {
316
426
  return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "array";
317
427
  }
318
- function u$1(r2) {
319
- return n(r2) ? r2 : t(r2) || i$1(r2) ? r2.toString() : f(r2) ? "null" : o$1(r2) ? `[array:${r2.elements.length}]` : String(r2);
428
+ function o(r2) {
429
+ return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "undefined";
320
430
  }
321
- function c(r2) {
322
- return i$1(r2) ? r2 : f(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : o$1(r2) ? true : !!r2;
431
+ function c$1(r2) {
432
+ return n(r2) ? r2 : t(r2) || i(r2) ? r2.toString() : f(r2) ? "null" : o(r2) ? "undefined" : e(r2) ? `[array:${r2.elements.length}]` : String(r2);
433
+ }
434
+ function y(r2) {
435
+ return i(r2) ? r2 : f(r2) || o(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : e(r2) ? true : !!r2;
323
436
  }
324
437
  function m(r2) {
325
- return n(r2) ? "string" : t(r2) ? "number" : i$1(r2) ? "boolean" : f(r2) ? "null" : o$1(r2) ? "array" : "unknown";
438
+ return n(r2) ? "string" : t(r2) ? "number" : i(r2) ? "boolean" : f(r2) ? "null" : o(r2) ? "undefined" : e(r2) ? "array" : "unknown";
326
439
  }
327
- function y(r2) {
440
+ function d(r2) {
328
441
  if (t(r2)) return r2;
329
- if (i$1(r2)) return r2 ? 1 : 0;
442
+ if (i(r2)) return r2 ? 1 : 0;
330
443
  if (f(r2)) return 0;
444
+ if (o(r2)) return NaN;
331
445
  if (n(r2)) {
332
- const e = r2.trim();
333
- return e === "" ? NaN : Number(e);
446
+ const u2 = r2.trim();
447
+ return u2 === "" ? 0 : Number(u2);
334
448
  }
335
- return o$1(r2) ? NaN : Number(r2);
449
+ return e(r2) ? NaN : Number(r2);
336
450
  }
337
- function s(r2 = []) {
451
+ function p$1(r2 = []) {
338
452
  return { type: "array", elements: r2 };
339
453
  }
454
+ function s$1() {
455
+ return { type: "undefined" };
456
+ }
340
457
  var l = Object.defineProperty;
341
458
  var u = (s2, t2, n2) => t2 in s2 ? l(s2, t2, { enumerable: true, configurable: true, writable: true, value: n2 }) : s2[t2] = n2;
342
459
  var r = (s2, t2, n2) => u(s2, typeof t2 != "symbol" ? t2 + "" : t2, n2);
343
- class h2 {
460
+ class h {
344
461
  constructor(t2) {
345
462
  r(this, "connected", false);
346
463
  r(this, "programsDir");
@@ -349,7 +466,7 @@ class h2 {
349
466
  this.dataDir = t2, this.programsDir = c__namespace.join(t2, "programs"), this.executionsDir = c__namespace.join(t2, "executions"), this.outputsDir = c__namespace.join(t2, "outputs");
350
467
  }
351
468
  async connect() {
352
- await fs.promises.mkdir(this.dataDir, { recursive: true }), await fs.promises.mkdir(this.programsDir, { recursive: true }), await fs.promises.mkdir(this.executionsDir, { recursive: true }), await fs.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
469
+ await M.promises.mkdir(this.dataDir, { recursive: true }), await M.promises.mkdir(this.programsDir, { recursive: true }), await M.promises.mkdir(this.executionsDir, { recursive: true }), await M.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
353
470
  }
354
471
  async disconnect() {
355
472
  this.connected = false;
@@ -359,55 +476,55 @@ class h2 {
359
476
  }
360
477
  async saveProgram(t2) {
361
478
  if (!this.connected) throw new Error("Not connected");
362
- const n2 = c__namespace.join(this.programsDir, `${t2.id}.json`), e = JSON.stringify(t2, null, 2);
363
- await fs.promises.writeFile(n2, e, "utf-8");
479
+ const n2 = c__namespace.join(this.programsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
480
+ await M.promises.writeFile(n2, e2, "utf-8");
364
481
  }
365
482
  async getProgram(t2) {
366
483
  if (!this.connected) throw new Error("Not connected");
367
484
  const n2 = c__namespace.join(this.programsDir, `${t2}.json`);
368
485
  try {
369
- const e = await fs.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e);
486
+ const e2 = await M.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
370
487
  return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
371
- } catch (e) {
372
- if (e.code === "ENOENT")
488
+ } catch (e2) {
489
+ if (e2.code === "ENOENT")
373
490
  return null;
374
- throw e;
491
+ throw e2;
375
492
  }
376
493
  }
377
494
  async saveExecution(t2) {
378
495
  if (!this.connected) throw new Error("Not connected");
379
- const n2 = c__namespace.join(this.executionsDir, `${t2.id}.json`), e = JSON.stringify(t2, null, 2);
380
- await fs.promises.writeFile(n2, e, "utf-8");
496
+ const n2 = c__namespace.join(this.executionsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
497
+ await M.promises.writeFile(n2, e2, "utf-8");
381
498
  }
382
499
  async getExecution(t2) {
383
500
  if (!this.connected) throw new Error("Not connected");
384
501
  const n2 = c__namespace.join(this.executionsDir, `${t2}.json`);
385
502
  try {
386
- const e = await fs.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e);
503
+ const e2 = await M.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
387
504
  return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
388
- } catch (e) {
389
- if (e.code === "ENOENT")
505
+ } catch (e2) {
506
+ if (e2.code === "ENOENT")
390
507
  return null;
391
- throw e;
508
+ throw e2;
392
509
  }
393
510
  }
394
511
  async appendOutput(t2, n2) {
395
512
  if (!this.connected) throw new Error("Not connected");
396
- const e = c__namespace.join(this.outputsDir, `${t2}.output`), o2 = n2.join(`
513
+ const e2 = c__namespace.join(this.outputsDir, `${t2}.output`), o2 = n2.join(`
397
514
  `) + `
398
515
  `;
399
- await fs.promises.appendFile(e, o2, "utf-8");
516
+ await M.promises.appendFile(e2, o2, "utf-8");
400
517
  }
401
518
  async getOutput(t2) {
402
519
  if (!this.connected) throw new Error("Not connected");
403
520
  const n2 = c__namespace.join(this.outputsDir, `${t2}.output`);
404
521
  try {
405
- return (await fs.promises.readFile(n2, "utf-8")).split(`
522
+ return (await M.promises.readFile(n2, "utf-8")).split(`
406
523
  `).filter((o2) => o2.length > 0);
407
- } catch (e) {
408
- if (e.code === "ENOENT")
524
+ } catch (e2) {
525
+ if (e2.code === "ENOENT")
409
526
  return [];
410
- throw e;
527
+ throw e2;
411
528
  }
412
529
  }
413
530
  }
@@ -423,8 +540,8 @@ class p {
423
540
  await this.client.connect();
424
541
  const t2 = ((o2 = this.connectionString.split("/").pop()) == null ? void 0 : o2.split("?")[0]) || "cvm";
425
542
  this.db = this.client.db(t2), this.connected = true;
426
- const e = (await this.db.listCollections().toArray()).map((a2) => a2.name);
427
- e.includes("programs") || await this.db.createCollection("programs"), e.includes("executions") || await this.db.createCollection("executions"), e.includes("outputs") || await this.db.createCollection("outputs");
543
+ const e2 = (await this.db.listCollections().toArray()).map((a2) => a2.name);
544
+ e2.includes("programs") || await this.db.createCollection("programs"), e2.includes("executions") || await this.db.createCollection("executions"), e2.includes("outputs") || await this.db.createCollection("outputs");
428
545
  }
429
546
  async disconnect() {
430
547
  await this.client.close(), this.connected = false, this.db = null;
@@ -461,15 +578,15 @@ class p {
461
578
  return await this.getCollection("executions").findOne({ id: t2 });
462
579
  }
463
580
  async appendOutput(t2, n2) {
464
- const e = this.getCollection("outputs");
465
- await e.findOne({ executionId: t2 }) ? await e.updateOne(
581
+ const e2 = this.getCollection("outputs");
582
+ await e2.findOne({ executionId: t2 }) ? await e2.updateOne(
466
583
  { executionId: t2 },
467
584
  { $push: { lines: { $each: n2 } } }
468
- ) : await e.insertOne({ executionId: t2, lines: n2 });
585
+ ) : await e2.insertOne({ executionId: t2, lines: n2 });
469
586
  }
470
587
  async getOutput(t2) {
471
- const e = await this.getCollection("outputs").findOne({ executionId: t2 });
472
- return (e == null ? void 0 : e.lines) || [];
588
+ const e2 = await this.getCollection("outputs").findOne({ executionId: t2 });
589
+ return (e2 == null ? void 0 : e2.lines) || [];
473
590
  }
474
591
  }
475
592
  class g {
@@ -477,106 +594,105 @@ class g {
477
594
  const n2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
478
595
  switch (n2) {
479
596
  case "file": {
480
- const e = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
481
- return new h2(e);
597
+ const e2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
598
+ return new h(e2);
482
599
  }
483
600
  case "mongodb": {
484
- const e = (t2 == null ? void 0 : t2.mongoUri) || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
485
- return new p(e);
601
+ const e2 = (t2 == null ? void 0 : t2.mongoUri) || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
602
+ return new p(e2);
486
603
  }
487
604
  default:
488
605
  throw new Error(`Unsupported storage type: ${n2}`);
489
606
  }
490
607
  }
491
608
  }
492
- var R = Object.defineProperty;
493
- var T = (d, a2, s2) => a2 in d ? R(d, a2, { enumerable: true, configurable: true, writable: true, value: s2 }) : d[a2] = s2;
494
- var v$1 = (d, a2, s2) => T(d, typeof a2 != "symbol" ? a2 + "" : a2, s2);
495
- class E {
496
- execute(a2, s$12) {
609
+ var C = Object.defineProperty;
610
+ var G = (g2, a2, s2) => a2 in g2 ? C(g2, a2, { enumerable: true, configurable: true, writable: true, value: s2 }) : g2[a2] = s2;
611
+ var N2 = (g2, a2, s2) => G(g2, typeof a2 != "symbol" ? a2 + "" : a2, s2);
612
+ class A {
613
+ execute(a2, s2) {
497
614
  const r2 = {
498
- pc: (s$12 == null ? void 0 : s$12.pc) ?? 0,
499
- stack: (s$12 == null ? void 0 : s$12.stack) ?? [],
500
- variables: (s$12 == null ? void 0 : s$12.variables) ?? /* @__PURE__ */ new Map(),
615
+ pc: (s2 == null ? void 0 : s2.pc) ?? 0,
616
+ stack: (s2 == null ? void 0 : s2.stack) ?? [],
617
+ variables: (s2 == null ? void 0 : s2.variables) ?? /* @__PURE__ */ new Map(),
501
618
  status: "running",
502
- output: (s$12 == null ? void 0 : s$12.output) ?? [],
503
- iterators: (s$12 == null ? void 0 : s$12.iterators) ?? [],
504
- ...s$12
619
+ output: (s2 == null ? void 0 : s2.output) ?? [],
620
+ iterators: (s2 == null ? void 0 : s2.iterators) ?? [],
621
+ ...s2
505
622
  };
506
623
  for (; r2.status === "running" && r2.pc < a2.length; ) {
507
- const i2 = a2[r2.pc];
508
- switch (i2.op) {
509
- case n$1.HALT:
624
+ const n$1 = a2[r2.pc];
625
+ switch (n$1.op) {
626
+ case r$1.HALT:
510
627
  r2.status = "complete";
511
628
  break;
512
- case n$1.PUSH:
513
- r2.stack.push(i2.arg), r2.pc++;
629
+ case r$1.PUSH:
630
+ r2.stack.push(n$1.arg), r2.pc++;
514
631
  break;
515
- case n$1.POP:
632
+ case r$1.PUSH_UNDEFINED:
633
+ r2.stack.push(s$1()), r2.pc++;
634
+ break;
635
+ case r$1.POP:
516
636
  r2.stack.pop(), r2.pc++;
517
637
  break;
518
- case n$1.LOAD: {
519
- const t2 = i2.arg;
520
- if (!r2.variables.has(t2)) {
521
- r2.status = "error", r2.error = `LOAD: Variable '${t2}' is not defined`;
522
- break;
523
- }
524
- r2.stack.push(r2.variables.get(t2)), r2.pc++;
638
+ case r$1.LOAD: {
639
+ const t2 = n$1.arg;
640
+ r2.variables.has(t2) ? r2.stack.push(r2.variables.get(t2)) : r2.stack.push(s$1()), r2.pc++;
525
641
  break;
526
642
  }
527
- case n$1.STORE:
528
- const f2 = r2.stack.pop();
529
- if (f2 === void 0) {
643
+ case r$1.STORE:
644
+ const f$1 = r2.stack.pop();
645
+ if (f$1 === void 0) {
530
646
  r2.status = "error", r2.error = "STORE: Stack underflow";
531
647
  break;
532
648
  }
533
- r2.variables.set(i2.arg, f2), r2.pc++;
649
+ r2.variables.set(n$1.arg, f$1), r2.pc++;
534
650
  break;
535
- case n$1.CONCAT:
536
- const u2 = r2.stack.pop(), k2 = r2.stack.pop();
537
- if (k2 === void 0 || u2 === void 0) {
651
+ case r$1.CONCAT:
652
+ const u2 = r2.stack.pop(), l2 = r2.stack.pop();
653
+ if (l2 === void 0 || u2 === void 0) {
538
654
  r2.status = "error", r2.error = "CONCAT: Stack underflow";
539
655
  break;
540
656
  }
541
- r2.stack.push(u$1(k2) + u$1(u2)), r2.pc++;
657
+ r2.stack.push(c$1(l2) + c$1(u2)), r2.pc++;
542
658
  break;
543
- case n$1.PRINT:
544
- const w = r2.stack.pop();
545
- w !== void 0 && r2.output.push(u$1(w)), r2.pc++;
659
+ case r$1.PRINT:
660
+ const k2 = r2.stack.pop();
661
+ k2 !== void 0 && r2.output.push(c$1(k2)), r2.pc++;
546
662
  break;
547
- case n$1.CC: {
663
+ case r$1.CC: {
548
664
  const t2 = r2.stack.pop();
549
665
  if (t2 === void 0) {
550
666
  r2.status = "error", r2.error = "CC: Stack underflow";
551
667
  break;
552
668
  }
553
- r2.ccPrompt = u$1(t2), r2.status = "waiting_cc";
669
+ r2.ccPrompt = c$1(t2), r2.status = "waiting_cc";
554
670
  break;
555
671
  }
556
672
  // Array operations
557
- case n$1.ARRAY_NEW:
558
- r2.stack.push(s()), r2.pc++;
673
+ case r$1.ARRAY_NEW:
674
+ r2.stack.push(p$1()), r2.pc++;
559
675
  break;
560
- case n$1.ARRAY_PUSH: {
561
- const t2 = r2.stack.pop(), e = r2.stack.pop();
562
- if (t2 === void 0 || e === void 0) {
676
+ case r$1.ARRAY_PUSH: {
677
+ const t2 = r2.stack.pop(), e$1 = r2.stack.pop();
678
+ if (t2 === void 0 || e$1 === void 0) {
563
679
  r2.status = "error", r2.error = "ARRAY_PUSH: Stack underflow";
564
680
  break;
565
681
  }
566
- if (!o$1(e)) {
682
+ if (!e(e$1)) {
567
683
  r2.status = "error", r2.error = "ARRAY_PUSH requires an array";
568
684
  break;
569
685
  }
570
- e.elements.push(t2), r2.stack.push(e), r2.pc++;
686
+ e$1.elements.push(t2), r2.stack.push(e$1), r2.pc++;
571
687
  break;
572
688
  }
573
- case n$1.ARRAY_GET: {
574
- const t$1 = r2.stack.pop(), e = r2.stack.pop();
575
- if (t$1 === void 0 || e === void 0) {
689
+ case r$1.ARRAY_GET: {
690
+ const t$1 = r2.stack.pop(), e$1 = r2.stack.pop();
691
+ if (t$1 === void 0 || e$1 === void 0) {
576
692
  r2.status = "error", r2.error = "ARRAY_GET: Stack underflow";
577
693
  break;
578
694
  }
579
- if (!o$1(e)) {
695
+ if (!e(e$1)) {
580
696
  r2.status = "error", r2.error = "ARRAY_GET requires an array";
581
697
  break;
582
698
  }
@@ -584,46 +700,46 @@ class E {
584
700
  r2.status = "error", r2.error = "ARRAY_GET requires numeric index";
585
701
  break;
586
702
  }
587
- const c2 = e.elements[t$1] ?? null;
588
- r2.stack.push(c2), r2.pc++;
703
+ const o2 = e$1.elements[t$1] ?? null;
704
+ r2.stack.push(o2), r2.pc++;
589
705
  break;
590
706
  }
591
- case n$1.ARRAY_SET: {
592
- const t$1 = r2.stack.pop(), e = r2.stack.pop(), c2 = r2.stack.pop();
593
- if (t$1 === void 0 || e === void 0 || c2 === void 0) {
707
+ case r$1.ARRAY_SET: {
708
+ const t$1 = r2.stack.pop(), e$1 = r2.stack.pop(), o2 = r2.stack.pop();
709
+ if (t$1 === void 0 || e$1 === void 0 || o2 === void 0) {
594
710
  r2.status = "error", r2.error = "ARRAY_SET: Stack underflow";
595
711
  break;
596
712
  }
597
- if (!o$1(c2)) {
713
+ if (!e(o2)) {
598
714
  r2.status = "error", r2.error = "ARRAY_SET requires an array";
599
715
  break;
600
716
  }
601
- if (!t(e)) {
717
+ if (!t(e$1)) {
602
718
  r2.status = "error", r2.error = "ARRAY_SET requires numeric index";
603
719
  break;
604
720
  }
605
- const n2 = Math.floor(e);
606
- if (n2 < 0) {
721
+ const i2 = Math.floor(e$1);
722
+ if (i2 < 0) {
607
723
  r2.status = "error", r2.error = "ARRAY_SET: Negative index not allowed";
608
724
  break;
609
725
  }
610
- c2.elements[n2] = t$1, r2.pc++;
726
+ o2.elements[i2] = t$1, r2.pc++;
611
727
  break;
612
728
  }
613
- case n$1.ARRAY_LEN: {
729
+ case r$1.ARRAY_LEN: {
614
730
  const t2 = r2.stack.pop();
615
731
  if (t2 === void 0) {
616
732
  r2.status = "error", r2.error = "ARRAY_LEN: Stack underflow";
617
733
  break;
618
734
  }
619
- if (!o$1(t2)) {
735
+ if (!e(t2)) {
620
736
  r2.status = "error", r2.error = "ARRAY_LEN requires an array";
621
737
  break;
622
738
  }
623
739
  r2.stack.push(t2.elements.length), r2.pc++;
624
740
  break;
625
741
  }
626
- case n$1.STRING_LEN: {
742
+ case r$1.STRING_LEN: {
627
743
  const t2 = r2.stack.pop();
628
744
  if (t2 === void 0) {
629
745
  r2.status = "error", r2.error = "STRING_LEN: Stack underflow";
@@ -636,7 +752,7 @@ class E {
636
752
  r2.stack.push(t2.length), r2.pc++;
637
753
  break;
638
754
  }
639
- case n$1.LENGTH: {
755
+ case r$1.LENGTH: {
640
756
  const t2 = r2.stack.pop();
641
757
  if (t2 === void 0) {
642
758
  r2.status = "error", r2.error = "LENGTH: Stack underflow";
@@ -644,7 +760,7 @@ class E {
644
760
  }
645
761
  if (n(t2))
646
762
  r2.stack.push(t2.length);
647
- else if (o$1(t2))
763
+ else if (e(t2))
648
764
  r2.stack.push(t2.elements.length);
649
765
  else {
650
766
  r2.status = "error", r2.error = "LENGTH requires a string or array";
@@ -653,7 +769,7 @@ class E {
653
769
  r2.pc++;
654
770
  break;
655
771
  }
656
- case n$1.JSON_PARSE: {
772
+ case r$1.JSON_PARSE: {
657
773
  const t2 = r2.stack.pop();
658
774
  if (t2 === void 0) {
659
775
  r2.status = "error", r2.error = "JSON_PARSE: Stack underflow";
@@ -664,15 +780,15 @@ class E {
664
780
  break;
665
781
  }
666
782
  try {
667
- const e = JSON.parse(t2);
668
- Array.isArray(e) ? r2.stack.push(s(e)) : r2.stack.push(s());
783
+ const e2 = JSON.parse(t2);
784
+ Array.isArray(e2) ? r2.stack.push(p$1(e2)) : r2.stack.push(p$1());
669
785
  } catch {
670
- r2.stack.push(s());
786
+ r2.stack.push(p$1());
671
787
  }
672
788
  r2.pc++;
673
789
  break;
674
790
  }
675
- case n$1.TYPEOF: {
791
+ case r$1.TYPEOF: {
676
792
  const t2 = r2.stack.pop();
677
793
  if (t2 === void 0) {
678
794
  r2.status = "error", r2.error = "TYPEOF: Stack underflow";
@@ -682,146 +798,205 @@ class E {
682
798
  break;
683
799
  }
684
800
  // Arithmetic operations
685
- case n$1.ADD: {
686
- const t2 = r2.stack.pop(), e = r2.stack.pop();
687
- if (e === void 0 || t2 === void 0) {
801
+ case r$1.ADD: {
802
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
803
+ if (e2 === void 0 || t2 === void 0) {
688
804
  r2.status = "error", r2.error = "ADD: Stack underflow";
689
805
  break;
690
806
  }
691
- const c2 = y(e), n2 = y(t2);
692
- r2.stack.push(c2 + n2), r2.pc++;
807
+ const o2 = d(e2), i2 = d(t2);
808
+ r2.stack.push(o2 + i2), r2.pc++;
693
809
  break;
694
810
  }
695
- case n$1.SUB: {
696
- const t2 = r2.stack.pop(), e = r2.stack.pop();
697
- if (e === void 0 || t2 === void 0) {
811
+ case r$1.SUB: {
812
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
813
+ if (e2 === void 0 || t2 === void 0) {
698
814
  r2.status = "error", r2.error = "SUB: Stack underflow";
699
815
  break;
700
816
  }
701
- const c2 = y(e), n2 = y(t2);
702
- r2.stack.push(c2 - n2), r2.pc++;
817
+ const o2 = d(e2), i2 = d(t2);
818
+ r2.stack.push(o2 - i2), r2.pc++;
703
819
  break;
704
820
  }
705
- case n$1.MUL: {
706
- const t2 = r2.stack.pop(), e = r2.stack.pop();
707
- if (e === void 0 || t2 === void 0) {
821
+ case r$1.MUL: {
822
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
823
+ if (e2 === void 0 || t2 === void 0) {
708
824
  r2.status = "error", r2.error = "MUL: Stack underflow";
709
825
  break;
710
826
  }
711
- const c2 = y(e), n2 = y(t2);
712
- r2.stack.push(c2 * n2), r2.pc++;
827
+ const o2 = d(e2), i2 = d(t2);
828
+ r2.stack.push(o2 * i2), r2.pc++;
713
829
  break;
714
830
  }
715
- case n$1.DIV: {
716
- const t2 = r2.stack.pop(), e = r2.stack.pop();
717
- if (e === void 0 || t2 === void 0) {
831
+ case r$1.DIV: {
832
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
833
+ if (e2 === void 0 || t2 === void 0) {
718
834
  r2.status = "error", r2.error = "DIV: Stack underflow";
719
835
  break;
720
836
  }
721
- const c2 = y(e), n2 = y(t2);
722
- if (n2 === 0) {
837
+ const o2 = d(e2), i2 = d(t2);
838
+ if (i2 === 0) {
723
839
  r2.status = "error", r2.error = "Division by zero";
724
840
  break;
725
841
  }
726
- r2.stack.push(c2 / n2), r2.pc++;
842
+ r2.stack.push(o2 / i2), r2.pc++;
727
843
  break;
728
844
  }
729
- case n$1.MOD: {
730
- const t2 = r2.stack.pop(), e = r2.stack.pop();
731
- if (e === void 0 || t2 === void 0) {
845
+ case r$1.MOD: {
846
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
847
+ if (e2 === void 0 || t2 === void 0) {
732
848
  r2.status = "error", r2.error = "MOD: Stack underflow";
733
849
  break;
734
850
  }
735
- const c2 = y(e), n2 = y(t2);
736
- r2.stack.push(c2 % n2), r2.pc++;
851
+ const o2 = d(e2), i2 = d(t2);
852
+ r2.stack.push(o2 % i2), r2.pc++;
853
+ break;
854
+ }
855
+ // Unary operations
856
+ case r$1.UNARY_MINUS: {
857
+ const t2 = r2.stack.pop();
858
+ if (t2 === void 0) {
859
+ r2.status = "error", r2.error = "UNARY_MINUS: Stack underflow";
860
+ break;
861
+ }
862
+ const e2 = d(t2);
863
+ r2.stack.push(-e2), r2.pc++;
864
+ break;
865
+ }
866
+ case r$1.UNARY_PLUS: {
867
+ const t2 = r2.stack.pop();
868
+ if (t2 === void 0) {
869
+ r2.status = "error", r2.error = "UNARY_PLUS: Stack underflow";
870
+ break;
871
+ }
872
+ const e2 = d(t2);
873
+ r2.stack.push(e2), r2.pc++;
874
+ break;
875
+ }
876
+ case r$1.INC: {
877
+ const t2 = r2.stack.pop();
878
+ if (t2 === void 0 || typeof t2 != "string") {
879
+ r2.status = "error", r2.error = "INC: Invalid variable name";
880
+ break;
881
+ }
882
+ const e2 = r2.variables.get(t2) ?? 0, o2 = d(e2) + 1;
883
+ r2.variables.set(t2, o2);
884
+ const i2 = n$1.arg === true;
885
+ r2.stack.push(i2 ? d(e2) : o2), r2.pc++;
886
+ break;
887
+ }
888
+ case r$1.DEC: {
889
+ const t2 = r2.stack.pop();
890
+ if (t2 === void 0 || typeof t2 != "string") {
891
+ r2.status = "error", r2.error = "DEC: Invalid variable name";
892
+ break;
893
+ }
894
+ const e2 = r2.variables.get(t2) ?? 0, o2 = d(e2) - 1;
895
+ r2.variables.set(t2, o2);
896
+ const i2 = n$1.arg === true;
897
+ r2.stack.push(i2 ? d(e2) : o2), r2.pc++;
737
898
  break;
738
899
  }
739
900
  // Comparison operations
740
- case n$1.EQ: {
741
- const t2 = r2.stack.pop(), e = r2.stack.pop();
742
- if (e === void 0 || t2 === void 0) {
901
+ case r$1.EQ: {
902
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
903
+ if (e2 === void 0 || t2 === void 0) {
743
904
  r2.status = "error", r2.error = "EQ: Stack underflow";
744
905
  break;
745
906
  }
746
- const c2 = y(e), n2 = y(t2);
747
- !isNaN(c2) && !isNaN(n2) ? r2.stack.push(c2 === n2) : r2.stack.push(u$1(e) === u$1(t2)), r2.pc++;
907
+ if (f(e2) && o(t2) || o(e2) && f(t2))
908
+ r2.stack.push(true);
909
+ else if (o(e2) && o(t2))
910
+ r2.stack.push(true);
911
+ else {
912
+ const o2 = d(e2), i2 = d(t2);
913
+ !isNaN(o2) && !isNaN(i2) ? r2.stack.push(o2 === i2) : r2.stack.push(c$1(e2) === c$1(t2));
914
+ }
915
+ r2.pc++;
748
916
  break;
749
917
  }
750
- case n$1.NEQ: {
751
- const t2 = r2.stack.pop(), e = r2.stack.pop();
752
- if (e === void 0 || t2 === void 0) {
918
+ case r$1.NEQ: {
919
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
920
+ if (e2 === void 0 || t2 === void 0) {
753
921
  r2.status = "error", r2.error = "NEQ: Stack underflow";
754
922
  break;
755
923
  }
756
- const c2 = y(e), n2 = y(t2);
757
- !isNaN(c2) && !isNaN(n2) ? r2.stack.push(c2 !== n2) : r2.stack.push(u$1(e) !== u$1(t2)), r2.pc++;
924
+ if (f(e2) && o(t2) || o(e2) && f(t2))
925
+ r2.stack.push(false);
926
+ else if (o(e2) && o(t2))
927
+ r2.stack.push(false);
928
+ else {
929
+ const o2 = d(e2), i2 = d(t2);
930
+ !isNaN(o2) && !isNaN(i2) ? r2.stack.push(o2 !== i2) : r2.stack.push(c$1(e2) !== c$1(t2));
931
+ }
932
+ r2.pc++;
758
933
  break;
759
934
  }
760
- case n$1.LT: {
761
- const t2 = r2.stack.pop(), e = r2.stack.pop();
762
- if (e === void 0 || t2 === void 0) {
935
+ case r$1.LT: {
936
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
937
+ if (e2 === void 0 || t2 === void 0) {
763
938
  r2.status = "error", r2.error = "LT: Stack underflow";
764
939
  break;
765
940
  }
766
- const c2 = y(e), n2 = y(t2);
767
- r2.stack.push(c2 < n2), r2.pc++;
941
+ const o2 = d(e2), i2 = d(t2);
942
+ r2.stack.push(o2 < i2), r2.pc++;
768
943
  break;
769
944
  }
770
- case n$1.GT: {
771
- const t2 = r2.stack.pop(), e = r2.stack.pop();
772
- if (e === void 0 || t2 === void 0) {
945
+ case r$1.GT: {
946
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
947
+ if (e2 === void 0 || t2 === void 0) {
773
948
  r2.status = "error", r2.error = "GT: Stack underflow";
774
949
  break;
775
950
  }
776
- const c2 = y(e), n2 = y(t2);
777
- r2.stack.push(c2 > n2), r2.pc++;
951
+ const o2 = d(e2), i2 = d(t2);
952
+ r2.stack.push(o2 > i2), r2.pc++;
778
953
  break;
779
954
  }
780
- case n$1.LTE: {
781
- const t2 = r2.stack.pop(), e = r2.stack.pop();
782
- if (e === void 0 || t2 === void 0) {
955
+ case r$1.LTE: {
956
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
957
+ if (e2 === void 0 || t2 === void 0) {
783
958
  r2.status = "error", r2.error = "LTE: Stack underflow";
784
959
  break;
785
960
  }
786
- const c2 = y(e), n2 = y(t2);
787
- r2.stack.push(c2 <= n2), r2.pc++;
961
+ const o2 = d(e2), i2 = d(t2);
962
+ r2.stack.push(o2 <= i2), r2.pc++;
788
963
  break;
789
964
  }
790
- case n$1.GTE: {
791
- const t2 = r2.stack.pop(), e = r2.stack.pop();
792
- if (e === void 0 || t2 === void 0) {
965
+ case r$1.GTE: {
966
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
967
+ if (e2 === void 0 || t2 === void 0) {
793
968
  r2.status = "error", r2.error = "GTE: Stack underflow";
794
969
  break;
795
970
  }
796
- const c2 = y(e), n2 = y(t2);
797
- r2.stack.push(c2 >= n2), r2.pc++;
971
+ const o2 = d(e2), i2 = d(t2);
972
+ r2.stack.push(o2 >= i2), r2.pc++;
798
973
  break;
799
974
  }
800
- case n$1.EQ_STRICT: {
801
- const t2 = r2.stack.pop(), e = r2.stack.pop();
802
- if (e === void 0 || t2 === void 0) {
975
+ case r$1.EQ_STRICT: {
976
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
977
+ if (e2 === void 0 || t2 === void 0) {
803
978
  r2.status = "error", r2.error = "EQ_STRICT: Stack underflow";
804
979
  break;
805
980
  }
806
- r2.stack.push(e === t2), r2.pc++;
981
+ r2.stack.push(e2 === t2), r2.pc++;
807
982
  break;
808
983
  }
809
- case n$1.NEQ_STRICT: {
810
- const t2 = r2.stack.pop(), e = r2.stack.pop();
811
- if (e === void 0 || t2 === void 0) {
984
+ case r$1.NEQ_STRICT: {
985
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
986
+ if (e2 === void 0 || t2 === void 0) {
812
987
  r2.status = "error", r2.error = "NEQ_STRICT: Stack underflow";
813
988
  break;
814
989
  }
815
- r2.stack.push(e !== t2), r2.pc++;
990
+ r2.stack.push(e2 !== t2), r2.pc++;
816
991
  break;
817
992
  }
818
993
  // Jump operations
819
- case n$1.JUMP: {
820
- if (i2.arg === void 0) {
994
+ case r$1.JUMP: {
995
+ if (n$1.arg === void 0) {
821
996
  r2.status = "error", r2.error = "JUMP requires a target address";
822
997
  break;
823
998
  }
824
- const t2 = i2.arg;
999
+ const t2 = n$1.arg;
825
1000
  if (t2 < 0 || t2 >= a2.length) {
826
1001
  r2.status = "error", r2.error = `Invalid jump target: ${t2}`;
827
1002
  break;
@@ -829,25 +1004,25 @@ class E {
829
1004
  r2.pc = t2;
830
1005
  break;
831
1006
  }
832
- case n$1.JUMP_IF_FALSE: {
1007
+ case r$1.JUMP_IF_FALSE: {
833
1008
  const t2 = r2.stack.pop();
834
1009
  if (t2 === void 0) {
835
1010
  r2.status = "error", r2.error = "JUMP_IF_FALSE: Stack underflow";
836
1011
  break;
837
1012
  }
838
- if (i2.arg === void 0) {
1013
+ if (n$1.arg === void 0) {
839
1014
  r2.status = "error", r2.error = "JUMP_IF_FALSE requires a target address";
840
1015
  break;
841
1016
  }
842
- const e = i2.arg;
843
- if (e < 0 || e >= a2.length) {
844
- r2.status = "error", r2.error = `Invalid jump target: ${e}`;
1017
+ const e2 = n$1.arg;
1018
+ if (e2 < 0 || e2 >= a2.length) {
1019
+ r2.status = "error", r2.error = `Invalid jump target: ${e2}`;
845
1020
  break;
846
1021
  }
847
- c(t2) ? r2.pc++ : r2.pc = e;
1022
+ y(t2) ? r2.pc++ : r2.pc = e2;
848
1023
  break;
849
1024
  }
850
- case n$1.ITER_START: {
1025
+ case r$1.ITER_START: {
851
1026
  if (r2.stack.length === 0) {
852
1027
  r2.status = "error", r2.error = "ITER_START: Stack underflow";
853
1028
  break;
@@ -857,7 +1032,7 @@ class E {
857
1032
  r2.status = "error", r2.error = "TypeError: Cannot iterate over null or undefined";
858
1033
  break;
859
1034
  }
860
- if (!o$1(t2)) {
1035
+ if (!e(t2)) {
861
1036
  r2.status = "error", r2.error = "TypeError: Cannot iterate over non-array value";
862
1037
  break;
863
1038
  }
@@ -865,14 +1040,14 @@ class E {
865
1040
  r2.status = "error", r2.error = "RuntimeError: Maximum iterator depth exceeded";
866
1041
  break;
867
1042
  }
868
- const e = s([...t2.elements]);
1043
+ const e$1 = p$1([...t2.elements]);
869
1044
  r2.iterators.push({
870
- array: e,
1045
+ array: e$1,
871
1046
  index: 0
872
1047
  }), r2.pc++;
873
1048
  break;
874
1049
  }
875
- case n$1.ITER_NEXT: {
1050
+ case r$1.ITER_NEXT: {
876
1051
  if (r2.iterators.length === 0) {
877
1052
  r2.status = "error", r2.error = "ITER_NEXT: No active iterator";
878
1053
  break;
@@ -881,7 +1056,7 @@ class E {
881
1056
  t2.index < t2.array.elements.length ? (r2.stack.push(t2.array.elements[t2.index]), r2.stack.push(true), t2.index++) : (r2.stack.push(null), r2.stack.push(false)), r2.pc++;
882
1057
  break;
883
1058
  }
884
- case n$1.ITER_END: {
1059
+ case r$1.ITER_END: {
885
1060
  if (r2.iterators.length === 0) {
886
1061
  r2.status = "error", r2.error = "ITER_END: No active iterator";
887
1062
  break;
@@ -890,40 +1065,198 @@ class E {
890
1065
  break;
891
1066
  }
892
1067
  // Logical operators
893
- case n$1.AND: {
894
- const t2 = r2.stack.pop(), e = r2.stack.pop();
895
- if (e === void 0 || t2 === void 0) {
1068
+ case r$1.AND: {
1069
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
1070
+ if (e2 === void 0 || t2 === void 0) {
896
1071
  r2.status = "error", r2.error = "AND: Stack underflow";
897
1072
  break;
898
1073
  }
899
- c(e) ? r2.stack.push(t2) : r2.stack.push(e), r2.pc++;
1074
+ y(e2) ? r2.stack.push(t2) : r2.stack.push(e2), r2.pc++;
900
1075
  break;
901
1076
  }
902
- case n$1.OR: {
903
- const t2 = r2.stack.pop(), e = r2.stack.pop();
904
- if (e === void 0 || t2 === void 0) {
1077
+ case r$1.OR: {
1078
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
1079
+ if (e2 === void 0 || t2 === void 0) {
905
1080
  r2.status = "error", r2.error = "OR: Stack underflow";
906
1081
  break;
907
1082
  }
908
- c(e) ? r2.stack.push(e) : r2.stack.push(t2), r2.pc++;
1083
+ y(e2) ? r2.stack.push(e2) : r2.stack.push(t2), r2.pc++;
909
1084
  break;
910
1085
  }
911
- case n$1.NOT: {
1086
+ case r$1.NOT: {
912
1087
  const t2 = r2.stack.pop();
913
1088
  if (t2 === void 0) {
914
1089
  r2.status = "error", r2.error = "NOT: Stack underflow";
915
1090
  break;
916
1091
  }
917
- r2.stack.push(!c(t2)), r2.pc++;
1092
+ r2.stack.push(!y(t2)), r2.pc++;
918
1093
  break;
919
1094
  }
920
- case n$1.RETURN: {
1095
+ case r$1.RETURN: {
921
1096
  const t2 = r2.stack.pop() ?? null;
922
1097
  r2.returnValue = t2, r2.status = "complete";
923
1098
  break;
924
1099
  }
1100
+ // String methods
1101
+ case r$1.STRING_SUBSTRING: {
1102
+ if (r2.stack.length < 2) {
1103
+ r2.status = "error", r2.error = "STRING_SUBSTRING: Stack underflow";
1104
+ break;
1105
+ }
1106
+ const t2 = r2.stack.length;
1107
+ let e2, o2, i2;
1108
+ const w2 = r2.stack[t2 - 1], _ = r2.stack[t2 - 2];
1109
+ if (t2 >= 3 && typeof w2 == "number" && typeof _ == "number" ? (i2 = r2.stack.pop(), o2 = r2.stack.pop(), e2 = r2.stack.pop()) : (o2 = r2.stack.pop(), e2 = r2.stack.pop(), i2 = void 0), !n(e2)) {
1110
+ r2.status = "error", r2.error = "STRING_SUBSTRING requires a string";
1111
+ break;
1112
+ }
1113
+ if (typeof o2 != "number") {
1114
+ r2.status = "error", r2.error = "STRING_SUBSTRING requires numeric start index";
1115
+ break;
1116
+ }
1117
+ const S = e2.length;
1118
+ o2 < 0 && (o2 = Math.max(0, S + o2)), i2 !== void 0 && i2 < 0 && (i2 = Math.max(0, S + i2));
1119
+ const O = i2 !== void 0 ? e2.substring(o2, i2) : e2.substring(o2);
1120
+ r2.stack.push(O), r2.pc++;
1121
+ break;
1122
+ }
1123
+ case r$1.STRING_INDEXOF: {
1124
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
1125
+ if (t2 === void 0 || e2 === void 0) {
1126
+ r2.status = "error", r2.error = "STRING_INDEXOF: Stack underflow";
1127
+ break;
1128
+ }
1129
+ if (!n(e2) || !n(t2)) {
1130
+ r2.status = "error", r2.error = "STRING_INDEXOF requires string arguments";
1131
+ break;
1132
+ }
1133
+ r2.stack.push(e2.indexOf(t2)), r2.pc++;
1134
+ break;
1135
+ }
1136
+ case r$1.STRING_SPLIT: {
1137
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
1138
+ if (t2 === void 0 || e2 === void 0) {
1139
+ r2.status = "error", r2.error = "STRING_SPLIT: Stack underflow";
1140
+ break;
1141
+ }
1142
+ if (!n(e2) || !n(t2)) {
1143
+ r2.status = "error", r2.error = "STRING_SPLIT requires string arguments";
1144
+ break;
1145
+ }
1146
+ let o2;
1147
+ t2 === "" ? o2 = e2.split("") : o2 = e2.split(t2), r2.stack.push(p$1(o2)), r2.pc++;
1148
+ break;
1149
+ }
1150
+ case r$1.STRING_SLICE: {
1151
+ if (r2.stack.length < 2) {
1152
+ r2.status = "error", r2.error = "STRING_SLICE: Stack underflow";
1153
+ break;
1154
+ }
1155
+ const t2 = r2.stack.length;
1156
+ let e2, o2, i2;
1157
+ const w2 = r2.stack[t2 - 1], _ = r2.stack[t2 - 2];
1158
+ if (t2 >= 3 && typeof w2 == "number" && typeof _ == "number" ? (i2 = r2.stack.pop(), o2 = r2.stack.pop(), e2 = r2.stack.pop()) : (o2 = r2.stack.pop(), e2 = r2.stack.pop(), i2 = void 0), !n(e2)) {
1159
+ r2.status = "error", r2.error = "STRING_SLICE requires a string";
1160
+ break;
1161
+ }
1162
+ if (typeof o2 != "number") {
1163
+ r2.status = "error", r2.error = "STRING_SLICE requires numeric start index";
1164
+ break;
1165
+ }
1166
+ const S = i2 !== void 0 ? e2.slice(o2, i2) : e2.slice(o2);
1167
+ r2.stack.push(S), r2.pc++;
1168
+ break;
1169
+ }
1170
+ case r$1.STRING_CHARAT: {
1171
+ const t2 = r2.stack.pop(), e2 = r2.stack.pop();
1172
+ if (t2 === void 0 || e2 === void 0) {
1173
+ r2.status = "error", r2.error = "STRING_CHARAT: Stack underflow";
1174
+ break;
1175
+ }
1176
+ if (!n(e2)) {
1177
+ r2.status = "error", r2.error = "STRING_CHARAT requires a string";
1178
+ break;
1179
+ }
1180
+ if (typeof t2 != "number") {
1181
+ r2.status = "error", r2.error = "STRING_CHARAT requires numeric index";
1182
+ break;
1183
+ }
1184
+ const o2 = e2.charAt(t2);
1185
+ r2.stack.push(o2), r2.pc++;
1186
+ break;
1187
+ }
1188
+ case r$1.STRING_TOUPPERCASE: {
1189
+ const t2 = r2.stack.pop();
1190
+ if (t2 === void 0) {
1191
+ r2.status = "error", r2.error = "STRING_TOUPPERCASE: Stack underflow";
1192
+ break;
1193
+ }
1194
+ if (!n(t2)) {
1195
+ r2.status = "error", r2.error = "STRING_TOUPPERCASE requires a string";
1196
+ break;
1197
+ }
1198
+ r2.stack.push(t2.toUpperCase()), r2.pc++;
1199
+ break;
1200
+ }
1201
+ case r$1.STRING_TOLOWERCASE: {
1202
+ const t2 = r2.stack.pop();
1203
+ if (t2 === void 0) {
1204
+ r2.status = "error", r2.error = "STRING_TOLOWERCASE: Stack underflow";
1205
+ break;
1206
+ }
1207
+ if (!n(t2)) {
1208
+ r2.status = "error", r2.error = "STRING_TOLOWERCASE requires a string";
1209
+ break;
1210
+ }
1211
+ r2.stack.push(t2.toLowerCase()), r2.pc++;
1212
+ break;
1213
+ }
1214
+ case r$1.BREAK: {
1215
+ if (n$1.arg === void 0) {
1216
+ r2.status = "error", r2.error = "BREAK requires a target address";
1217
+ break;
1218
+ }
1219
+ const t2 = n$1.arg;
1220
+ if (t2 < 0 || t2 >= a2.length) {
1221
+ r2.status = "error", r2.error = `Invalid break target: ${t2}`;
1222
+ break;
1223
+ }
1224
+ r2.pc = t2;
1225
+ break;
1226
+ }
1227
+ case r$1.CONTINUE: {
1228
+ if (n$1.arg === void 0) {
1229
+ r2.status = "error", r2.error = "CONTINUE requires a target address";
1230
+ break;
1231
+ }
1232
+ const t2 = n$1.arg;
1233
+ if (t2 < 0 || t2 >= a2.length) {
1234
+ r2.status = "error", r2.error = `Invalid continue target: ${t2}`;
1235
+ break;
1236
+ }
1237
+ r2.pc = t2;
1238
+ break;
1239
+ }
1240
+ case r$1.FS_LIST_FILES: {
1241
+ if (r2.stack.length < 1) {
1242
+ r2.status = "error", r2.error = "FS_LIST_FILES: Stack underflow";
1243
+ break;
1244
+ }
1245
+ let t2, e$1 = {};
1246
+ const o2 = r2.stack[r2.stack.length - 1];
1247
+ if (r2.stack.length >= 2 && typeof o2 == "object" && o2 !== null && !e(o2) && (e$1 = r2.stack.pop()), t2 = r2.stack.pop(), !n(t2)) {
1248
+ r2.status = "error", r2.error = "FS_LIST_FILES requires a string path";
1249
+ break;
1250
+ }
1251
+ r2.fsOperation = {
1252
+ type: "listFiles",
1253
+ path: t2,
1254
+ options: e$1
1255
+ }, r2.status = "waiting_fs";
1256
+ break;
1257
+ }
925
1258
  default:
926
- r2.status = "error", r2.error = `Unknown opcode: ${i2.op} (type: ${typeof i2.op})`;
1259
+ r2.status = "error", r2.error = `Unknown opcode: ${n$1.op} (type: ${typeof n$1.op})`;
927
1260
  }
928
1261
  }
929
1262
  return r2;
@@ -931,21 +1264,78 @@ class E {
931
1264
  resume(a2, s2, r2) {
932
1265
  if (a2.status !== "waiting_cc")
933
1266
  throw new Error("Cannot resume: VM not waiting for CC");
934
- const i2 = {
1267
+ const n2 = {
935
1268
  ...a2,
936
1269
  stack: [...a2.stack, s2],
937
1270
  status: "running",
938
1271
  ccPrompt: void 0,
939
1272
  pc: a2.pc + 1
940
1273
  };
941
- return this.execute(r2, i2);
1274
+ return this.execute(r2, n2);
1275
+ }
1276
+ resumeWithFsResult(a2, s2, r2) {
1277
+ if (a2.status !== "waiting_fs")
1278
+ throw new Error("Cannot resume: VM not waiting for FS operation");
1279
+ const n2 = {
1280
+ ...a2,
1281
+ stack: [...a2.stack, s2],
1282
+ status: "running",
1283
+ fsOperation: void 0,
1284
+ pc: a2.pc + 1
1285
+ };
1286
+ return this.execute(r2, n2);
942
1287
  }
943
1288
  }
944
- class L {
945
- constructor(a2) {
946
- v$1(this, "vms", /* @__PURE__ */ new Map());
947
- v$1(this, "storage");
948
- a2 ? this.storage = a2 : this.storage = g.create();
1289
+ class P {
1290
+ constructor() {
1291
+ N2(this, "sandboxPaths", []);
1292
+ const a2 = process.env.CVM_SANDBOX_PATHS, s2 = process.env.CVM_SANDBOX_ROOT;
1293
+ a2 ? this.sandboxPaths = a2.split(",").map((r2) => c__namespace.resolve(r2.trim())) : s2 && (this.sandboxPaths = [c__namespace.resolve(s2)]);
1294
+ }
1295
+ isPathAllowed(a2) {
1296
+ const s2 = c__namespace.resolve(a2);
1297
+ return s2.includes("..") || this.sandboxPaths.length === 0 ? false : this.sandboxPaths.some(
1298
+ (r2) => s2.startsWith(r2)
1299
+ );
1300
+ }
1301
+ listFiles(a2, s2 = {}) {
1302
+ const r2 = p$1();
1303
+ if (!this.isPathAllowed(a2))
1304
+ return r2;
1305
+ try {
1306
+ const n2 = c__namespace.resolve(a2);
1307
+ this.listFilesRecursive(n2, n2, r2.elements, s2);
1308
+ } catch {
1309
+ }
1310
+ return r2;
1311
+ }
1312
+ matchesPattern(a2, s2) {
1313
+ let r2 = s2.replace(/\./g, "\\.").replace(/\*\*/g, "__DOUBLESTAR__").replace(/\*/g, "[^/]*").replace(/__DOUBLESTAR__/g, ".*").replace(/\?/g, ".");
1314
+ r2 = "^" + r2 + "$";
1315
+ try {
1316
+ return new RegExp(r2).test(a2);
1317
+ } catch {
1318
+ return true;
1319
+ }
1320
+ }
1321
+ listFilesRecursive(a2, s2, r2, n2, f2 = 0) {
1322
+ try {
1323
+ const u2 = M__namespace.readdirSync(s2, { withFileTypes: true });
1324
+ for (const l2 of u2) {
1325
+ const k2 = c__namespace.join(s2, l2.name), t2 = c__namespace.relative(a2, k2);
1326
+ l2.isSymbolicLink() || n2.filter && !this.matchesPattern(t2, n2.filter) || (r2.push(k2), l2.isDirectory() && n2.recursive && this.listFilesRecursive(a2, k2, r2, n2, f2 + 1));
1327
+ }
1328
+ } catch {
1329
+ }
1330
+ }
1331
+ }
1332
+ new P();
1333
+ class $ {
1334
+ constructor(a2, s2) {
1335
+ N2(this, "vms", /* @__PURE__ */ new Map());
1336
+ N2(this, "storage");
1337
+ N2(this, "fileSystem");
1338
+ a2 ? this.storage = a2 : this.storage = g.create(), this.fileSystem = s2 || new P();
949
1339
  }
950
1340
  /**
951
1341
  * Initialize the VMManager (connect to database)
@@ -966,7 +1356,7 @@ class L {
966
1356
  const r2 = k(s2);
967
1357
  if (!r2.success)
968
1358
  throw new Error(`Compilation failed: ${r2.errors.join(", ")}`);
969
- const i2 = {
1359
+ const n2 = {
970
1360
  id: a2,
971
1361
  name: a2,
972
1362
  source: s2,
@@ -974,7 +1364,7 @@ class L {
974
1364
  // VM decides internal format
975
1365
  created: /* @__PURE__ */ new Date()
976
1366
  };
977
- await this.storage.saveProgram(i2);
1367
+ await this.storage.saveProgram(n2);
978
1368
  }
979
1369
  /**
980
1370
  * Start execution of a loaded program
@@ -982,7 +1372,7 @@ class L {
982
1372
  async startExecution(a2, s2) {
983
1373
  if (!await this.storage.getProgram(a2))
984
1374
  throw new Error(`Program not found: ${a2}`);
985
- const i2 = {
1375
+ const n2 = {
986
1376
  id: s2,
987
1377
  programId: a2,
988
1378
  state: "READY",
@@ -991,8 +1381,8 @@ class L {
991
1381
  variables: {},
992
1382
  created: /* @__PURE__ */ new Date()
993
1383
  };
994
- await this.storage.saveExecution(i2);
995
- const f2 = new E();
1384
+ await this.storage.saveExecution(n2);
1385
+ const f2 = new A();
996
1386
  this.vms.set(s2, f2);
997
1387
  }
998
1388
  /**
@@ -1007,14 +1397,14 @@ class L {
1007
1397
  const r2 = await this.storage.getProgram(s2.programId);
1008
1398
  if (!r2)
1009
1399
  throw new Error(`Program not found: ${s2.programId}`);
1010
- let i2 = this.vms.get(a2);
1011
- i2 || (i2 = new E(), this.vms.set(a2, i2));
1400
+ let n2 = this.vms.get(a2);
1401
+ n2 || (n2 = new A(), this.vms.set(a2, n2));
1012
1402
  const f2 = {
1013
1403
  pc: 0,
1014
1404
  stack: [],
1015
1405
  variables: /* @__PURE__ */ new Map(),
1016
1406
  output: []
1017
- }, u2 = i2.execute(r2.bytecode, f2);
1407
+ }, u2 = n2.execute(r2.bytecode, f2);
1018
1408
  if (u2.output.length > 0 && await this.storage.appendOutput(a2, u2.output), s2.pc = u2.pc, s2.stack = u2.stack, s2.variables = Object.fromEntries(u2.variables), u2.status === "complete")
1019
1409
  return s2.state = "COMPLETED", u2.returnValue !== void 0 && (s2.returnValue = u2.returnValue), await this.storage.saveExecution(s2), this.vms.delete(a2), {
1020
1410
  type: "completed",
@@ -1026,7 +1416,22 @@ class L {
1026
1416
  type: "waiting",
1027
1417
  message: u2.ccPrompt || "Waiting for input"
1028
1418
  };
1029
- if (u2.status === "error")
1419
+ if (u2.status === "waiting_fs") {
1420
+ if (u2.fsOperation) {
1421
+ const l2 = this.fileSystem.listFiles(u2.fsOperation.path, u2.fsOperation.options), k2 = n2.resumeWithFsResult(u2, l2, r2.bytecode);
1422
+ return k2.output.length > 0 && await this.storage.appendOutput(a2, k2.output), s2.pc = k2.pc, s2.stack = k2.stack, s2.variables = Object.fromEntries(k2.variables), k2.status === "complete" ? (s2.state = "COMPLETED", k2.returnValue !== void 0 && (s2.returnValue = k2.returnValue), await this.storage.saveExecution(s2), this.vms.delete(a2), {
1423
+ type: "completed",
1424
+ message: "Execution completed",
1425
+ result: k2.returnValue
1426
+ }) : k2.status === "error" ? (s2.state = "ERROR", s2.error = k2.error, await this.storage.saveExecution(s2), this.vms.delete(a2), {
1427
+ type: "error",
1428
+ error: k2.error
1429
+ }) : k2.status === "waiting_cc" ? (s2.state = "AWAITING_COGNITIVE_RESULT", s2.ccPrompt = k2.ccPrompt, await this.storage.saveExecution(s2), {
1430
+ type: "waiting",
1431
+ message: k2.ccPrompt || "Waiting for input"
1432
+ }) : (s2.state = "RUNNING", await this.storage.saveExecution(s2), this.getNext(a2));
1433
+ }
1434
+ } else if (u2.status === "error")
1030
1435
  return s2.state = "ERROR", s2.error = u2.error, await this.storage.saveExecution(s2), this.vms.delete(a2), {
1031
1436
  type: "error",
1032
1437
  error: u2.error
@@ -1056,11 +1461,11 @@ class L {
1056
1461
  const r2 = await this.storage.getExecution(a2);
1057
1462
  if (!r2)
1058
1463
  throw new Error(`Execution not found: ${a2}`);
1059
- const i2 = await this.storage.getProgram(r2.programId);
1060
- if (!i2)
1464
+ const n2 = await this.storage.getProgram(r2.programId);
1465
+ if (!n2)
1061
1466
  throw new Error(`Program not found: ${r2.programId}`);
1062
1467
  let f2 = this.vms.get(a2);
1063
- f2 || (f2 = new E(), this.vms.set(a2, f2));
1468
+ f2 || (f2 = new A(), this.vms.set(a2, f2));
1064
1469
  const u2 = {
1065
1470
  pc: r2.pc,
1066
1471
  stack: r2.stack,
@@ -1071,8 +1476,8 @@ class L {
1071
1476
  ccPrompt: void 0,
1072
1477
  iterators: []
1073
1478
  // TODO: persist iterators in future
1074
- }, k2 = f2.resume(u2, s2, i2.bytecode);
1075
- k2.output.length > 0 && await this.storage.appendOutput(a2, k2.output), r2.pc = k2.pc, r2.stack = k2.stack, r2.variables = Object.fromEntries(k2.variables), k2.status === "complete" ? (r2.state = "COMPLETED", k2.returnValue !== void 0 && (r2.returnValue = k2.returnValue), this.vms.delete(a2)) : k2.status === "error" ? (r2.state = "ERROR", r2.error = k2.error, this.vms.delete(a2)) : k2.status === "waiting_cc" ? (r2.state = "AWAITING_COGNITIVE_RESULT", r2.ccPrompt = k2.ccPrompt) : r2.state = "RUNNING", await this.storage.saveExecution(r2);
1479
+ }, l2 = f2.resume(u2, s2, n2.bytecode);
1480
+ l2.output.length > 0 && await this.storage.appendOutput(a2, l2.output), r2.pc = l2.pc, r2.stack = l2.stack, r2.variables = Object.fromEntries(l2.variables), l2.status === "complete" ? (r2.state = "COMPLETED", l2.returnValue !== void 0 && (r2.returnValue = l2.returnValue), this.vms.delete(a2)) : l2.status === "error" ? (r2.state = "ERROR", r2.error = l2.error, this.vms.delete(a2)) : l2.status === "waiting_cc" ? (r2.state = "AWAITING_COGNITIVE_RESULT", r2.ccPrompt = l2.ccPrompt) : r2.state = "RUNNING", await this.storage.saveExecution(r2);
1076
1481
  }
1077
1482
  /**
1078
1483
  * Get current execution status
@@ -1096,16 +1501,16 @@ class L {
1096
1501
  return await this.storage.getOutput(a2);
1097
1502
  }
1098
1503
  }
1099
- var i = Object.defineProperty;
1100
- var a = (s2, r2, t2) => r2 in s2 ? i(s2, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : s2[r2] = t2;
1101
- var o = (s2, r2, t2) => a(s2, typeof r2 != "symbol" ? r2 + "" : r2, t2);
1102
- class v {
1504
+ var a = Object.defineProperty;
1505
+ var c = (o2, r2, t2) => r2 in o2 ? a(o2, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : o2[r2] = t2;
1506
+ var s = (o2, r2, t2) => c(o2, typeof r2 != "symbol" ? r2 + "" : r2, t2);
1507
+ class w {
1103
1508
  constructor(r2 = "0.0.1") {
1104
- o(this, "server");
1105
- o(this, "transport", null);
1106
- o(this, "vmManager");
1107
- o(this, "version");
1108
- this.version = r2, this.vmManager = new L(), this.server = new mcp_js.McpServer({
1509
+ s(this, "server");
1510
+ s(this, "transport", null);
1511
+ s(this, "vmManager");
1512
+ s(this, "version");
1513
+ this.version = r2, this.vmManager = new $(), this.server = new mcp_js.McpServer({
1109
1514
  name: "cvm-server",
1110
1515
  version: this.version
1111
1516
  }), this.setupTools();
@@ -1128,9 +1533,41 @@ class v {
1128
1533
  return await this.vmManager.loadProgram(r2, t2), {
1129
1534
  content: [{ type: "text", text: `Program loaded successfully: ${r2}` }]
1130
1535
  };
1131
- } catch (e) {
1536
+ } catch (e2) {
1537
+ return {
1538
+ content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
1539
+ isError: true
1540
+ };
1541
+ }
1542
+ }
1543
+ ), this.server.tool(
1544
+ "loadFile",
1545
+ {
1546
+ programId: zod.z.string(),
1547
+ filePath: zod.z.string()
1548
+ },
1549
+ async ({ programId: r2, filePath: t2 }) => {
1550
+ try {
1551
+ const e2 = c$2.resolve(t2), i2 = await promises.readFile(e2, "utf-8");
1552
+ return await this.vmManager.loadProgram(r2, i2), {
1553
+ content: [{ type: "text", text: `Program loaded successfully from ${t2}: ${r2}` }]
1554
+ };
1555
+ } catch (e2) {
1556
+ if (e2 instanceof Error) {
1557
+ const i2 = e2;
1558
+ if (i2.code === "ENOENT")
1559
+ return {
1560
+ content: [{ type: "text", text: `Error: File not found: ${t2}` }],
1561
+ isError: true
1562
+ };
1563
+ if (i2.code === "EACCES")
1564
+ return {
1565
+ content: [{ type: "text", text: `Error: Permission denied: ${t2}` }],
1566
+ isError: true
1567
+ };
1568
+ }
1132
1569
  return {
1133
- content: [{ type: "text", text: `Error: ${e instanceof Error ? e.message : "Unknown error"}` }],
1570
+ content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
1134
1571
  isError: true
1135
1572
  };
1136
1573
  }
@@ -1146,9 +1583,9 @@ class v {
1146
1583
  return await this.vmManager.startExecution(r2, t2), {
1147
1584
  content: [{ type: "text", text: `Execution started: ${t2}` }]
1148
1585
  };
1149
- } catch (e) {
1586
+ } catch (e2) {
1150
1587
  return {
1151
- content: [{ type: "text", text: `Error: ${e instanceof Error ? e.message : "Unknown error"}` }],
1588
+ content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
1152
1589
  isError: true
1153
1590
  };
1154
1591
  }
@@ -1190,9 +1627,9 @@ class v {
1190
1627
  return await this.vmManager.reportCCResult(r2, t2), {
1191
1628
  content: [{ type: "text", text: "Execution resumed" }]
1192
1629
  };
1193
- } catch (e) {
1630
+ } catch (e2) {
1194
1631
  return {
1195
- content: [{ type: "text", text: `Error: ${e instanceof Error ? e.message : "Unknown error"}` }],
1632
+ content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
1196
1633
  isError: true
1197
1634
  };
1198
1635
  }
@@ -1228,7 +1665,7 @@ class v {
1228
1665
  return this.vmManager;
1229
1666
  }
1230
1667
  }
1231
- dotenv__namespace.config({ path: c$1.resolve(__dirname, "../../../.env") });
1668
+ dotenv__namespace.config({ path: c$2.resolve(__dirname, "../../../.env") });
1232
1669
  function loadConfig() {
1233
1670
  const env = process.env.NODE_ENV || "development";
1234
1671
  const storageType = process.env.CVM_STORAGE_TYPE || "file";
@@ -1309,7 +1746,7 @@ function getLogger() {
1309
1746
  return logger;
1310
1747
  }
1311
1748
  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);
1312
- const __dirname$1 = c$1.dirname(__filename$1);
1749
+ const __dirname$1 = c$2.dirname(__filename$1);
1313
1750
  async function main() {
1314
1751
  let cvmServer;
1315
1752
  try {
@@ -1318,21 +1755,21 @@ async function main() {
1318
1755
  const logger2 = getLogger();
1319
1756
  let version = "0.4.3";
1320
1757
  const possiblePaths = [
1321
- c$1.join(__dirname$1, "..", "package.json"),
1758
+ c$2.join(__dirname$1, "..", "package.json"),
1322
1759
  // Development
1323
- c$1.join(__dirname$1, "package.json"),
1760
+ c$2.join(__dirname$1, "package.json"),
1324
1761
  // Bundled dist
1325
- c$1.join(process.cwd(), "package.json")
1762
+ c$2.join(process.cwd(), "package.json")
1326
1763
  // Current directory
1327
1764
  ];
1328
1765
  for (const packageJsonPath of possiblePaths) {
1329
1766
  try {
1330
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1767
+ const packageJson = JSON.parse(M.readFileSync(packageJsonPath, "utf-8"));
1331
1768
  if (packageJson.name === "cvm-server" && packageJson.version) {
1332
1769
  version = packageJson.version;
1333
1770
  break;
1334
1771
  }
1335
- } catch (e) {
1772
+ } catch (e2) {
1336
1773
  }
1337
1774
  }
1338
1775
  logger2.info("Starting CVM Server...", {
@@ -1342,13 +1779,13 @@ async function main() {
1342
1779
  });
1343
1780
  if (config.storage.type === "file") {
1344
1781
  const dataDir = config.storage.dataDir || ".cvm";
1345
- const fullPath = c$1.resolve(process.cwd(), dataDir);
1782
+ const fullPath = c$2.resolve(process.cwd(), dataDir);
1346
1783
  logger2.info(`[CVM] Initializing file storage in: ${fullPath}`);
1347
1784
  logger2.warn(`[CVM] ⚠️ Remember to add '${dataDir}/' to your .gitignore file!`);
1348
1785
  } else {
1349
1786
  logger2.info("[CVM] Using MongoDB storage");
1350
1787
  }
1351
- cvmServer = new v(version);
1788
+ cvmServer = new w(version);
1352
1789
  await cvmServer.start();
1353
1790
  logger2.info("CVM Server is running and ready to accept MCP connections");
1354
1791
  process.on("SIGINT", async () => {