@vm0/cli 3.5.0 → 3.7.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/index.js +280 -22
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -736,10 +736,10 @@ function mergeDefs(...defs) {
736
736
  function cloneDef(schema) {
737
737
  return mergeDefs(schema._zod.def);
738
738
  }
739
- function getElementAtPath(obj, path9) {
740
- if (!path9)
739
+ function getElementAtPath(obj, path10) {
740
+ if (!path10)
741
741
  return obj;
742
- return path9.reduce((acc, key) => acc?.[key], obj);
742
+ return path10.reduce((acc, key) => acc?.[key], obj);
743
743
  }
744
744
  function promiseAllObject(promisesObj) {
745
745
  const keys = Object.keys(promisesObj);
@@ -1098,11 +1098,11 @@ function aborted(x, startIndex = 0) {
1098
1098
  }
1099
1099
  return false;
1100
1100
  }
1101
- function prefixIssues(path9, issues) {
1101
+ function prefixIssues(path10, issues) {
1102
1102
  return issues.map((iss) => {
1103
1103
  var _a;
1104
1104
  (_a = iss).path ?? (_a.path = []);
1105
- iss.path.unshift(path9);
1105
+ iss.path.unshift(path10);
1106
1106
  return iss;
1107
1107
  });
1108
1108
  }
@@ -1270,7 +1270,7 @@ function treeifyError(error43, _mapper) {
1270
1270
  return issue2.message;
1271
1271
  };
1272
1272
  const result = { errors: [] };
1273
- const processError = (error44, path9 = []) => {
1273
+ const processError = (error44, path10 = []) => {
1274
1274
  var _a, _b;
1275
1275
  for (const issue2 of error44.issues) {
1276
1276
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -1280,7 +1280,7 @@ function treeifyError(error43, _mapper) {
1280
1280
  } else if (issue2.code === "invalid_element") {
1281
1281
  processError({ issues: issue2.issues }, issue2.path);
1282
1282
  } else {
1283
- const fullpath = [...path9, ...issue2.path];
1283
+ const fullpath = [...path10, ...issue2.path];
1284
1284
  if (fullpath.length === 0) {
1285
1285
  result.errors.push(mapper(issue2));
1286
1286
  continue;
@@ -1312,8 +1312,8 @@ function treeifyError(error43, _mapper) {
1312
1312
  }
1313
1313
  function toDotPath(_path) {
1314
1314
  const segs = [];
1315
- const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1316
- for (const seg of path9) {
1315
+ const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1316
+ for (const seg of path10) {
1317
1317
  if (typeof seg === "number")
1318
1318
  segs.push(`[${seg}]`);
1319
1319
  else if (typeof seg === "symbol")
@@ -12147,8 +12147,8 @@ var helloContract = c.router({
12147
12147
  var FOO = "hello";
12148
12148
 
12149
12149
  // src/index.ts
12150
- import { Command as Command15 } from "commander";
12151
- import chalk14 from "chalk";
12150
+ import { Command as Command16 } from "commander";
12151
+ import chalk15 from "chalk";
12152
12152
 
12153
12153
  // src/lib/auth.ts
12154
12154
  import chalk from "chalk";
@@ -12453,7 +12453,7 @@ var ApiClient = class {
12453
12453
  /**
12454
12454
  * Generic GET request
12455
12455
  */
12456
- async get(path9) {
12456
+ async get(path10) {
12457
12457
  const baseUrl = await this.getBaseUrl();
12458
12458
  const token = await getToken();
12459
12459
  if (!token) {
@@ -12466,7 +12466,7 @@ var ApiClient = class {
12466
12466
  if (bypassSecret) {
12467
12467
  headers["x-vercel-protection-bypass"] = bypassSecret;
12468
12468
  }
12469
- return fetch(`${baseUrl}${path9}`, {
12469
+ return fetch(`${baseUrl}${path10}`, {
12470
12470
  method: "GET",
12471
12471
  headers
12472
12472
  });
@@ -12474,7 +12474,7 @@ var ApiClient = class {
12474
12474
  /**
12475
12475
  * Generic POST request
12476
12476
  */
12477
- async post(path9, options) {
12477
+ async post(path10, options) {
12478
12478
  const baseUrl = await this.getBaseUrl();
12479
12479
  const token = await getToken();
12480
12480
  if (!token) {
@@ -12487,7 +12487,7 @@ var ApiClient = class {
12487
12487
  if (bypassSecret) {
12488
12488
  headers["x-vercel-protection-bypass"] = bypassSecret;
12489
12489
  }
12490
- return fetch(`${baseUrl}${path9}`, {
12490
+ return fetch(`${baseUrl}${path10}`, {
12491
12491
  method: "POST",
12492
12492
  headers,
12493
12493
  body: options?.body
@@ -12496,7 +12496,7 @@ var ApiClient = class {
12496
12496
  /**
12497
12497
  * Generic DELETE request
12498
12498
  */
12499
- async delete(path9) {
12499
+ async delete(path10) {
12500
12500
  const baseUrl = await this.getBaseUrl();
12501
12501
  const token = await getToken();
12502
12502
  if (!token) {
@@ -12509,7 +12509,7 @@ var ApiClient = class {
12509
12509
  if (bypassSecret) {
12510
12510
  headers["x-vercel-protection-bypass"] = bypassSecret;
12511
12511
  }
12512
- return fetch(`${baseUrl}${path9}`, {
12512
+ return fetch(`${baseUrl}${path10}`, {
12513
12513
  method: "DELETE",
12514
12514
  headers
12515
12515
  });
@@ -14293,15 +14293,272 @@ var deleteCommand = new Command13().name("delete").alias("rm").description("Dele
14293
14293
  // src/commands/secret/index.ts
14294
14294
  var secretCommand = new Command14().name("secret").description("Manage secrets for agent compose configurations").addCommand(setCommand).addCommand(listCommand).addCommand(deleteCommand);
14295
14295
 
14296
+ // src/commands/cook.ts
14297
+ import { Command as Command15 } from "commander";
14298
+ import chalk14 from "chalk";
14299
+ import { readFile as readFile4, mkdir as mkdir3 } from "fs/promises";
14300
+ import { existsSync as existsSync4 } from "fs";
14301
+ import path9 from "path";
14302
+ import { spawn } from "child_process";
14303
+ import { parse as parseYaml3 } from "yaml";
14304
+ var CONFIG_FILE3 = "vm0.yaml";
14305
+ var ARTIFACT_DIR = "artifact";
14306
+ function execVm0Command(args, options = {}) {
14307
+ return new Promise((resolve, reject) => {
14308
+ const proc = spawn("vm0", args, {
14309
+ cwd: options.cwd,
14310
+ stdio: options.silent ? "pipe" : ["inherit", "inherit", "inherit"],
14311
+ shell: process.platform === "win32"
14312
+ });
14313
+ let stdout = "";
14314
+ let stderr = "";
14315
+ if (options.silent) {
14316
+ proc.stdout?.on("data", (data) => {
14317
+ stdout += data.toString();
14318
+ });
14319
+ proc.stderr?.on("data", (data) => {
14320
+ stderr += data.toString();
14321
+ });
14322
+ }
14323
+ proc.on("close", (code) => {
14324
+ if (code === 0) {
14325
+ resolve(stdout);
14326
+ } else {
14327
+ reject(new Error(stderr || `Command failed with exit code ${code}`));
14328
+ }
14329
+ });
14330
+ proc.on("error", (err) => {
14331
+ reject(err);
14332
+ });
14333
+ });
14334
+ }
14335
+ function execVm0RunWithCapture(args, options = {}) {
14336
+ return new Promise((resolve, reject) => {
14337
+ const proc = spawn("vm0", args, {
14338
+ cwd: options.cwd,
14339
+ stdio: ["inherit", "pipe", "pipe"],
14340
+ shell: process.platform === "win32"
14341
+ });
14342
+ let stdout = "";
14343
+ let stderr = "";
14344
+ proc.stdout?.on("data", (data) => {
14345
+ const chunk = data.toString();
14346
+ stdout += chunk;
14347
+ process.stdout.write(chunk);
14348
+ });
14349
+ proc.stderr?.on("data", (data) => {
14350
+ const chunk = data.toString();
14351
+ stderr += chunk;
14352
+ process.stderr.write(chunk);
14353
+ });
14354
+ proc.on("close", (code) => {
14355
+ if (code === 0) {
14356
+ resolve(stdout);
14357
+ } else {
14358
+ reject(new Error(stderr || `Command failed with exit code ${code}`));
14359
+ }
14360
+ });
14361
+ proc.on("error", (err) => {
14362
+ reject(err);
14363
+ });
14364
+ });
14365
+ }
14366
+ function parseArtifactVersion(output, artifactName, eventType) {
14367
+ const eventMarker = eventType === "vm0_start" ? "[vm0_start]" : "[vm0_result]";
14368
+ const eventIndex = output.indexOf(eventMarker);
14369
+ if (eventIndex === -1) return null;
14370
+ const nextEventIndex = output.indexOf(
14371
+ eventType === "vm0_start" ? "[vm0_result]" : "[vm0_error]",
14372
+ eventIndex
14373
+ );
14374
+ const section = nextEventIndex === -1 ? output.slice(eventIndex) : output.slice(eventIndex, nextEventIndex);
14375
+ const artifactPattern = new RegExp(
14376
+ `^\\s*${escapeRegExp(artifactName)}:\\s*(?:\\x1b\\[[0-9;]*m)?([a-f0-9]+)`,
14377
+ "m"
14378
+ );
14379
+ const match = section.match(artifactPattern);
14380
+ return match ? match[1] : null;
14381
+ }
14382
+ function escapeRegExp(str) {
14383
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14384
+ }
14385
+ var cookCommand = new Command15().name("cook").description("One-click agent preparation and execution from vm0.yaml").argument("[prompt]", "Prompt for the agent").option(
14386
+ "-t, --timeout <seconds>",
14387
+ "Polling timeout in seconds for agent run (default: 120)"
14388
+ ).action(async (prompt, options) => {
14389
+ const cwd = process.cwd();
14390
+ console.log(chalk14.blue(`Reading config: ${CONFIG_FILE3}`));
14391
+ if (!existsSync4(CONFIG_FILE3)) {
14392
+ console.error(chalk14.red(`\u2717 Config file not found: ${CONFIG_FILE3}`));
14393
+ process.exit(1);
14394
+ }
14395
+ let config2;
14396
+ try {
14397
+ const content = await readFile4(CONFIG_FILE3, "utf8");
14398
+ config2 = parseYaml3(content);
14399
+ } catch (error43) {
14400
+ console.error(chalk14.red("\u2717 Invalid YAML format"));
14401
+ if (error43 instanceof Error) {
14402
+ console.error(chalk14.gray(` ${error43.message}`));
14403
+ }
14404
+ process.exit(1);
14405
+ }
14406
+ const validation = validateAgentCompose(config2);
14407
+ if (!validation.valid) {
14408
+ console.error(chalk14.red(`\u2717 ${validation.error}`));
14409
+ process.exit(1);
14410
+ }
14411
+ const agentNames = Object.keys(config2.agents);
14412
+ const agentName = agentNames[0];
14413
+ const volumeCount = config2.volumes ? Object.keys(config2.volumes).length : 0;
14414
+ console.log(
14415
+ chalk14.green(`\u2713 Config validated: 1 agent, ${volumeCount} volume(s)`)
14416
+ );
14417
+ if (config2.volumes && Object.keys(config2.volumes).length > 0) {
14418
+ console.log();
14419
+ console.log(chalk14.blue("Processing volumes..."));
14420
+ for (const volumeConfig of Object.values(config2.volumes)) {
14421
+ const volumeDir = path9.join(cwd, volumeConfig.name);
14422
+ console.log(chalk14.gray(` ${volumeConfig.name}/`));
14423
+ if (!existsSync4(volumeDir)) {
14424
+ console.error(
14425
+ chalk14.red(
14426
+ ` \u2717 Directory not found. Create the directory and add files first.`
14427
+ )
14428
+ );
14429
+ process.exit(1);
14430
+ }
14431
+ try {
14432
+ const existingConfig = await readStorageConfig(volumeDir);
14433
+ if (!existingConfig) {
14434
+ await execVm0Command(["volume", "init"], {
14435
+ cwd: volumeDir,
14436
+ silent: true
14437
+ });
14438
+ console.log(chalk14.green(` \u2713 Initialized`));
14439
+ }
14440
+ await execVm0Command(["volume", "push"], {
14441
+ cwd: volumeDir,
14442
+ silent: true
14443
+ });
14444
+ console.log(chalk14.green(` \u2713 Pushed`));
14445
+ } catch (error43) {
14446
+ console.error(chalk14.red(` \u2717 Failed`));
14447
+ if (error43 instanceof Error) {
14448
+ console.error(chalk14.gray(` ${error43.message}`));
14449
+ }
14450
+ process.exit(1);
14451
+ }
14452
+ }
14453
+ }
14454
+ console.log();
14455
+ console.log(chalk14.blue("Processing artifact..."));
14456
+ const artifactDir = path9.join(cwd, ARTIFACT_DIR);
14457
+ console.log(chalk14.gray(` ${ARTIFACT_DIR}/`));
14458
+ try {
14459
+ if (!existsSync4(artifactDir)) {
14460
+ await mkdir3(artifactDir, { recursive: true });
14461
+ console.log(chalk14.green(` \u2713 Created directory`));
14462
+ }
14463
+ const existingConfig = await readStorageConfig(artifactDir);
14464
+ if (!existingConfig) {
14465
+ await execVm0Command(["artifact", "init"], {
14466
+ cwd: artifactDir,
14467
+ silent: true
14468
+ });
14469
+ console.log(chalk14.green(` \u2713 Initialized`));
14470
+ }
14471
+ await execVm0Command(["artifact", "push"], {
14472
+ cwd: artifactDir,
14473
+ silent: true
14474
+ });
14475
+ console.log(chalk14.green(` \u2713 Pushed`));
14476
+ } catch (error43) {
14477
+ console.error(chalk14.red(` \u2717 Failed`));
14478
+ if (error43 instanceof Error) {
14479
+ console.error(chalk14.gray(` ${error43.message}`));
14480
+ }
14481
+ process.exit(1);
14482
+ }
14483
+ console.log();
14484
+ console.log(chalk14.blue("Building compose..."));
14485
+ try {
14486
+ await execVm0Command(["build", CONFIG_FILE3], {
14487
+ cwd,
14488
+ silent: true
14489
+ });
14490
+ console.log(chalk14.green(`\u2713 Compose built: ${agentName}`));
14491
+ } catch (error43) {
14492
+ console.error(chalk14.red(`\u2717 Build failed`));
14493
+ if (error43 instanceof Error) {
14494
+ console.error(chalk14.gray(` ${error43.message}`));
14495
+ }
14496
+ process.exit(1);
14497
+ }
14498
+ if (prompt) {
14499
+ console.log();
14500
+ console.log(chalk14.blue(`Running agent: ${agentName}`));
14501
+ console.log();
14502
+ let runOutput;
14503
+ try {
14504
+ const runArgs = [
14505
+ "run",
14506
+ agentName,
14507
+ "--artifact-name",
14508
+ ARTIFACT_DIR,
14509
+ ...options.timeout ? ["--timeout", options.timeout] : [],
14510
+ prompt
14511
+ ];
14512
+ runOutput = await execVm0RunWithCapture(runArgs, { cwd });
14513
+ } catch {
14514
+ process.exit(1);
14515
+ }
14516
+ const startVersion = parseArtifactVersion(
14517
+ runOutput,
14518
+ ARTIFACT_DIR,
14519
+ "vm0_start"
14520
+ );
14521
+ const endVersion = parseArtifactVersion(
14522
+ runOutput,
14523
+ ARTIFACT_DIR,
14524
+ "vm0_result"
14525
+ );
14526
+ if (startVersion && endVersion && startVersion !== endVersion) {
14527
+ console.log();
14528
+ console.log(chalk14.blue("Pulling updated artifact..."));
14529
+ try {
14530
+ await execVm0Command(["artifact", "pull"], {
14531
+ cwd: artifactDir,
14532
+ silent: true
14533
+ });
14534
+ console.log(chalk14.green(`\u2713 Artifact pulled (${endVersion})`));
14535
+ } catch (error43) {
14536
+ console.error(chalk14.red(`\u2717 Artifact pull failed`));
14537
+ if (error43 instanceof Error) {
14538
+ console.error(chalk14.gray(` ${error43.message}`));
14539
+ }
14540
+ }
14541
+ }
14542
+ } else {
14543
+ console.log();
14544
+ console.log(" Run your agent:");
14545
+ console.log(
14546
+ chalk14.cyan(
14547
+ ` vm0 run ${agentName} --artifact-name ${ARTIFACT_DIR} "your prompt"`
14548
+ )
14549
+ );
14550
+ }
14551
+ });
14552
+
14296
14553
  // src/index.ts
14297
- var program = new Command15();
14298
- program.name("vm0").description("VM0 CLI - A modern build tool").version("3.5.0");
14554
+ var program = new Command16();
14555
+ program.name("vm0").description("VM0 CLI - A modern build tool").version("3.7.0");
14299
14556
  program.command("hello").description("Say hello from the App").action(() => {
14300
- console.log(chalk14.blue("Welcome to the VM0 CLI!"));
14301
- console.log(chalk14.green(`Core says: ${FOO}`));
14557
+ console.log(chalk15.blue("Welcome to the VM0 CLI!"));
14558
+ console.log(chalk15.green(`Core says: ${FOO}`));
14302
14559
  });
14303
14560
  program.command("info").description("Display environment information").action(async () => {
14304
- console.log(chalk14.cyan("System Information:"));
14561
+ console.log(chalk15.cyan("System Information:"));
14305
14562
  console.log(`Node Version: ${process.version}`);
14306
14563
  console.log(`Platform: ${process.platform}`);
14307
14564
  console.log(`Architecture: ${process.arch}`);
@@ -14323,6 +14580,7 @@ program.addCommand(runCommand);
14323
14580
  program.addCommand(volumeCommand);
14324
14581
  program.addCommand(artifactCommand);
14325
14582
  program.addCommand(secretCommand);
14583
+ program.addCommand(cookCommand);
14326
14584
  if (process.argv[1]?.endsWith("index.js") || process.argv[1]?.endsWith("index.ts") || process.argv[1]?.endsWith("vm0")) {
14327
14585
  program.parse();
14328
14586
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm0/cli",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "CLI application",
5
5
  "repository": {
6
6
  "type": "git",