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