cvm-server 0.2.7 → 0.3.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.js +72 -72
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -29,7 +29,7 @@ const s__namespace = /* @__PURE__ */ _interopNamespaceDefault(s);
29
29
  const h__namespace = /* @__PURE__ */ _interopNamespaceDefault(h);
30
30
  const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
31
31
  var a = /* @__PURE__ */ ((i2) => (i2.PUSH = "PUSH", i2.POP = "POP", i2.LOAD = "LOAD", i2.STORE = "STORE", i2.CONCAT = "CONCAT", i2.JUMP = "JUMP", i2.JUMP_IF = "JUMP_IF", i2.CALL = "CALL", i2.RETURN = "RETURN", i2.CC = "CC", i2.PRINT = "PRINT", i2.HALT = "HALT", i2))(a || {});
32
- function l$1(i2) {
32
+ function l$2(i2) {
33
33
  const p3 = [], r2 = [];
34
34
  let u2 = false, c2 = false;
35
35
  const o = t__namespace.createSourceFile(
@@ -56,7 +56,7 @@ function l$1(i2) {
56
56
  };
57
57
  }
58
58
  function m$1(i2) {
59
- const p3 = l$1(i2);
59
+ const p3 = l$2(i2);
60
60
  if (p3.errors.length > 0)
61
61
  return {
62
62
  success: false,
@@ -89,8 +89,8 @@ function m$1(i2) {
89
89
  errors: []
90
90
  };
91
91
  }
92
- var l = Object.defineProperty;
93
- var d = (i2, t2, e) => t2 in i2 ? l(i2, t2, { enumerable: true, configurable: true, writable: true, value: e }) : i2[t2] = e;
92
+ var l$1 = Object.defineProperty;
93
+ var d = (i2, t2, e) => t2 in i2 ? l$1(i2, t2, { enumerable: true, configurable: true, writable: true, value: e }) : i2[t2] = e;
94
94
  var r = (i2, t2, e) => d(i2, typeof t2 != "symbol" ? t2 + "" : t2, e);
95
95
  let p$1 = class p {
96
96
  constructor(t2) {
@@ -211,10 +211,10 @@ class g {
211
211
  }
212
212
  }
213
213
  var m = Object.defineProperty;
214
- var w2 = (p3, r2, t2) => r2 in p3 ? m(p3, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : p3[r2] = t2;
215
- var u = (p3, r2, t2) => w2(p3, typeof r2 != "symbol" ? r2 + "" : r2, t2);
214
+ var w2 = (p3, s2, t2) => s2 in p3 ? m(p3, s2, { enumerable: true, configurable: true, writable: true, value: t2 }) : p3[s2] = t2;
215
+ var u = (p3, s2, t2) => w2(p3, typeof s2 != "symbol" ? s2 + "" : s2, t2);
216
216
  class i {
217
- execute(r2, t2) {
217
+ execute(s2, t2) {
218
218
  const e = {
219
219
  pc: (t2 == null ? void 0 : t2.pc) ?? 0,
220
220
  stack: (t2 == null ? void 0 : t2.stack) ?? [],
@@ -223,24 +223,24 @@ class i {
223
223
  output: (t2 == null ? void 0 : t2.output) ?? [],
224
224
  ...t2
225
225
  };
226
- for (; e.status === "running" && e.pc < r2.length; ) {
227
- const s2 = r2[e.pc];
228
- switch (s2.op) {
226
+ for (; e.status === "running" && e.pc < s2.length; ) {
227
+ const r2 = s2[e.pc];
228
+ switch (r2.op) {
229
229
  case a.HALT:
230
230
  e.status = "complete";
231
231
  break;
232
232
  case a.PUSH:
233
- e.stack.push(s2.arg), e.pc++;
233
+ e.stack.push(r2.arg), e.pc++;
234
234
  break;
235
235
  case a.POP:
236
236
  e.stack.pop(), e.pc++;
237
237
  break;
238
238
  case a.LOAD:
239
- e.stack.push(e.variables.get(s2.arg) ?? ""), e.pc++;
239
+ e.stack.push(e.variables.get(r2.arg) ?? ""), e.pc++;
240
240
  break;
241
241
  case a.STORE:
242
242
  const c2 = e.stack.pop();
243
- e.variables.set(s2.arg, c2), e.pc++;
243
+ e.variables.set(r2.arg, c2), e.pc++;
244
244
  break;
245
245
  case a.CONCAT:
246
246
  const o = e.stack.pop(), a$1 = e.stack.pop();
@@ -254,29 +254,29 @@ class i {
254
254
  e.ccPrompt = e.stack.pop(), e.status = "waiting_cc";
255
255
  break;
256
256
  default:
257
- e.status = "error", e.error = `Unknown opcode: ${s2.op}`;
257
+ e.status = "error", e.error = `Unknown opcode: ${r2.op}`;
258
258
  }
259
259
  }
260
260
  return e;
261
261
  }
262
- resume(r2, t2, e) {
263
- if (r2.status !== "waiting_cc")
262
+ resume(s2, t2, e) {
263
+ if (s2.status !== "waiting_cc")
264
264
  throw new Error("Cannot resume: VM not waiting for CC");
265
- const s2 = {
266
- ...r2,
267
- stack: [...r2.stack, t2],
265
+ const r2 = {
266
+ ...s2,
267
+ stack: [...s2.stack, t2],
268
268
  status: "running",
269
269
  ccPrompt: void 0,
270
- pc: r2.pc + 1
270
+ pc: s2.pc + 1
271
271
  };
272
- return this.execute(e, s2);
272
+ return this.execute(e, r2);
273
273
  }
274
274
  }
275
- class b {
276
- constructor(r2) {
275
+ class l {
276
+ constructor(s2) {
277
277
  u(this, "vms", /* @__PURE__ */ new Map());
278
278
  u(this, "storage");
279
- r2 ? this.storage = r2 : this.storage = g.create();
279
+ s2 ? this.storage = s2 : this.storage = g.create();
280
280
  }
281
281
  /**
282
282
  * Initialize the VMManager (connect to database)
@@ -293,37 +293,37 @@ class b {
293
293
  /**
294
294
  * Load and compile a program from source code
295
295
  */
296
- async loadProgram(r2, t2) {
296
+ async loadProgram(s2, t2) {
297
297
  const e = m$1(t2);
298
298
  if (!e.success)
299
299
  throw new Error(`Compilation failed: ${e.errors.join(", ")}`);
300
- const s2 = {
301
- id: r2,
302
- name: r2,
300
+ const r2 = {
301
+ id: s2,
302
+ name: s2,
303
303
  source: t2,
304
304
  bytecode: e.bytecode,
305
305
  // VM decides internal format
306
306
  created: /* @__PURE__ */ new Date()
307
307
  };
308
- await this.storage.saveProgram(s2);
308
+ await this.storage.saveProgram(r2);
309
309
  }
310
310
  /**
311
311
  * Start execution of a loaded program
312
312
  */
313
- async startExecution(r2, t2) {
314
- if (!await this.storage.getProgram(r2))
315
- throw new Error(`Program not found: ${r2}`);
316
- const s2 = {
313
+ async startExecution(s2, t2) {
314
+ if (!await this.storage.getProgram(s2))
315
+ throw new Error(`Program not found: ${s2}`);
316
+ const r2 = {
317
317
  id: t2,
318
- programId: r2,
319
- state: "ready",
318
+ programId: s2,
319
+ state: "READY",
320
320
  pc: 0,
321
321
  stack: [],
322
322
  variables: {},
323
323
  output: [],
324
324
  created: /* @__PURE__ */ new Date()
325
325
  };
326
- await this.storage.saveExecution(s2);
326
+ await this.storage.saveExecution(r2);
327
327
  const c2 = new i();
328
328
  this.vms.set(t2, c2);
329
329
  }
@@ -331,49 +331,49 @@ class b {
331
331
  * Get next action from execution (Claude polls this)
332
332
  * This is READ-ONLY - just returns current state
333
333
  */
334
- async getNext(r2) {
335
- const t2 = await this.storage.getExecution(r2);
334
+ async getNext(s2) {
335
+ const t2 = await this.storage.getExecution(s2);
336
336
  if (!t2)
337
- throw new Error(`Execution not found: ${r2}`);
338
- if (t2.state === "ready") {
337
+ throw new Error(`Execution not found: ${s2}`);
338
+ if (t2.state === "READY") {
339
339
  const e = await this.storage.getProgram(t2.programId);
340
340
  if (!e)
341
341
  throw new Error(`Program not found: ${t2.programId}`);
342
- let s2 = this.vms.get(r2);
343
- s2 || (s2 = new i(), this.vms.set(r2, s2));
342
+ let r2 = this.vms.get(s2);
343
+ r2 || (r2 = new i(), this.vms.set(s2, r2));
344
344
  const c2 = {
345
345
  pc: 0,
346
346
  stack: [],
347
347
  variables: /* @__PURE__ */ new Map(),
348
348
  output: []
349
- }, o = s2.execute(e.bytecode, c2);
349
+ }, o = r2.execute(e.bytecode, c2);
350
350
  if (t2.pc = o.pc, t2.stack = o.stack, t2.variables = Object.fromEntries(o.variables), t2.output = o.output, o.status === "complete")
351
- return t2.state = "completed", await this.storage.saveExecution(t2), this.vms.delete(r2), {
351
+ return t2.state = "COMPLETED", await this.storage.saveExecution(t2), this.vms.delete(s2), {
352
352
  type: "completed",
353
353
  message: "Execution completed"
354
354
  };
355
355
  if (o.status === "waiting_cc")
356
- return t2.state = "waiting_cc", t2.ccPrompt = o.ccPrompt, await this.storage.saveExecution(t2), {
356
+ return t2.state = "AWAITING_COGNITIVE_RESULT", t2.ccPrompt = o.ccPrompt, await this.storage.saveExecution(t2), {
357
357
  type: "waiting",
358
358
  message: o.ccPrompt || "Waiting for input"
359
359
  };
360
360
  if (o.status === "error")
361
- return t2.state = "error", t2.error = o.error, await this.storage.saveExecution(t2), this.vms.delete(r2), {
361
+ return t2.state = "ERROR", t2.error = o.error, await this.storage.saveExecution(t2), this.vms.delete(s2), {
362
362
  type: "error",
363
363
  error: o.error
364
364
  };
365
365
  }
366
- if (t2.state === "completed")
366
+ if (t2.state === "COMPLETED")
367
367
  return {
368
368
  type: "completed",
369
369
  message: "Execution completed"
370
370
  };
371
- if (t2.state === "error")
371
+ if (t2.state === "ERROR")
372
372
  return {
373
373
  type: "error",
374
374
  error: t2.error || "Unknown error"
375
375
  };
376
- if (t2.state === "waiting_cc")
376
+ if (t2.state === "AWAITING_COGNITIVE_RESULT")
377
377
  return {
378
378
  type: "waiting",
379
379
  message: t2.ccPrompt || "Waiting for input"
@@ -383,15 +383,15 @@ class b {
383
383
  /**
384
384
  * Report result from cognitive operation and continue execution
385
385
  */
386
- async reportCCResult(r2, t2) {
387
- const e = await this.storage.getExecution(r2);
386
+ async reportCCResult(s2, t2) {
387
+ const e = await this.storage.getExecution(s2);
388
388
  if (!e)
389
- throw new Error(`Execution not found: ${r2}`);
390
- const s2 = await this.storage.getProgram(e.programId);
391
- if (!s2)
389
+ throw new Error(`Execution not found: ${s2}`);
390
+ const r2 = await this.storage.getProgram(e.programId);
391
+ if (!r2)
392
392
  throw new Error(`Program not found: ${e.programId}`);
393
- let c2 = this.vms.get(r2);
394
- c2 || (c2 = new i(), this.vms.set(r2, c2));
393
+ let c2 = this.vms.get(s2);
394
+ c2 || (c2 = new i(), this.vms.set(s2, c2));
395
395
  const o = {
396
396
  pc: e.pc,
397
397
  stack: e.stack,
@@ -399,16 +399,16 @@ class b {
399
399
  status: "waiting_cc",
400
400
  output: e.output,
401
401
  ccPrompt: void 0
402
- }, a2 = c2.resume(o, t2, s2.bytecode);
403
- e.pc = a2.pc, e.stack = a2.stack, e.variables = Object.fromEntries(a2.variables), e.output = a2.output, a2.status === "complete" ? (e.state = "completed", this.vms.delete(r2)) : a2.status === "error" ? (e.state = "error", e.error = a2.error, this.vms.delete(r2)) : a2.status === "waiting_cc" ? (e.state = "waiting_cc", e.ccPrompt = a2.ccPrompt) : e.state = "running", await this.storage.saveExecution(e);
402
+ }, a2 = c2.resume(o, t2, r2.bytecode);
403
+ e.pc = a2.pc, e.stack = a2.stack, e.variables = Object.fromEntries(a2.variables), e.output = a2.output, a2.status === "complete" ? (e.state = "COMPLETED", this.vms.delete(s2)) : a2.status === "error" ? (e.state = "ERROR", e.error = a2.error, this.vms.delete(s2)) : a2.status === "waiting_cc" ? (e.state = "AWAITING_COGNITIVE_RESULT", e.ccPrompt = a2.ccPrompt) : e.state = "RUNNING", await this.storage.saveExecution(e);
404
404
  }
405
405
  /**
406
406
  * Get current execution status
407
407
  */
408
- async getExecutionStatus(r2) {
409
- const t2 = await this.storage.getExecution(r2);
408
+ async getExecutionStatus(s2) {
409
+ const t2 = await this.storage.getExecution(s2);
410
410
  if (!t2)
411
- throw new Error(`Execution not found: ${r2}`);
411
+ throw new Error(`Execution not found: ${s2}`);
412
412
  return {
413
413
  id: t2.id,
414
414
  state: t2.state,
@@ -427,7 +427,7 @@ class f {
427
427
  c(this, "server");
428
428
  c(this, "transport", null);
429
429
  c(this, "vmManager");
430
- this.vmManager = new b(), this.server = new mcp_js.McpServer({
430
+ this.vmManager = new l(), this.server = new mcp_js.McpServer({
431
431
  name: "cvm-server",
432
432
  version: "1.0.0"
433
433
  }), this.setupTools();
@@ -440,7 +440,7 @@ class f {
440
440
  }
441
441
  setupTools() {
442
442
  this.server.tool(
443
- "loadProgram",
443
+ "load",
444
444
  {
445
445
  programId: zod.z.string(),
446
446
  source: zod.z.string()
@@ -458,7 +458,7 @@ class f {
458
458
  }
459
459
  }
460
460
  ), this.server.tool(
461
- "startExecution",
461
+ "start",
462
462
  {
463
463
  programId: zod.z.string(),
464
464
  executionId: zod.z.string()
@@ -476,7 +476,7 @@ class f {
476
476
  }
477
477
  }
478
478
  ), this.server.tool(
479
- "getNext",
479
+ "getTask",
480
480
  {
481
481
  executionId: zod.z.string()
482
482
  },
@@ -502,7 +502,7 @@ class f {
502
502
  }
503
503
  }
504
504
  ), this.server.tool(
505
- "reportCCResult",
505
+ "submitTask",
506
506
  {
507
507
  executionId: zod.z.string(),
508
508
  result: zod.z.string()
@@ -520,7 +520,7 @@ class f {
520
520
  }
521
521
  }
522
522
  ), this.server.tool(
523
- "getExecutionState",
523
+ "status",
524
524
  {
525
525
  executionId: zod.z.string()
526
526
  },
@@ -548,21 +548,21 @@ class f {
548
548
  // For testing - direct tool invocation
549
549
  async handleTool(r2, t2) {
550
550
  const u2 = {
551
- loadProgram: async ({ programId: n, source: e }) => {
551
+ load: async ({ programId: n, source: e }) => {
552
552
  try {
553
553
  return await this.vmManager.loadProgram(n, e), { content: [{ type: "text", text: `Program loaded successfully: ${n}` }] };
554
554
  } catch (s2) {
555
555
  return { content: [{ type: "text", text: s2 instanceof Error ? s2.message : "Unknown error" }], isError: true };
556
556
  }
557
557
  },
558
- startExecution: async ({ programId: n, executionId: e }) => {
558
+ start: async ({ programId: n, executionId: e }) => {
559
559
  try {
560
560
  return await this.vmManager.startExecution(n, e), { content: [{ type: "text", text: `Execution started: ${e}` }] };
561
561
  } catch (s2) {
562
562
  return { content: [{ type: "text", text: s2 instanceof Error ? s2.message : "Unknown error" }], isError: true };
563
563
  }
564
564
  },
565
- getNext: async ({ executionId: n }) => {
565
+ getTask: async ({ executionId: n }) => {
566
566
  try {
567
567
  const e = await this.vmManager.getNext(n);
568
568
  return e.type === "completed" ? { content: [{ type: "text", text: "Execution completed" }] } : e.type === "waiting" ? { content: [{ type: "text", text: e.message || "Waiting for input" }] } : { content: [{ type: "text", text: `Error: ${e.error}` }], isError: true };
@@ -570,14 +570,14 @@ class f {
570
570
  return { content: [{ type: "text", text: e instanceof Error ? e.message : "Unknown error" }], isError: true };
571
571
  }
572
572
  },
573
- reportCCResult: async ({ executionId: n, result: e }) => {
573
+ submitTask: async ({ executionId: n, result: e }) => {
574
574
  try {
575
575
  return await this.vmManager.reportCCResult(n, e), { content: [{ type: "text", text: "Execution resumed" }] };
576
576
  } catch (s2) {
577
577
  return { content: [{ type: "text", text: s2 instanceof Error ? s2.message : "Unknown error" }], isError: true };
578
578
  }
579
579
  },
580
- getExecutionState: async ({ executionId: n }) => {
580
+ status: async ({ executionId: n }) => {
581
581
  try {
582
582
  const e = await this.vmManager.getExecutionStatus(n);
583
583
  return { content: [{ type: "text", text: JSON.stringify(e, null, 2) }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cvm-server",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Cognitive Virtual Machine (CVM) - A deterministic bytecode VM with AI cognitive operations",
5
5
  "keywords": [
6
6
  "mcp",