@vm0/cli 3.6.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 +91 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -14332,7 +14332,60 @@ function execVm0Command(args, options = {}) {
14332
14332
  });
14333
14333
  });
14334
14334
  }
14335
- var cookCommand = new Command15().name("cook").description("One-click agent preparation and execution from vm0.yaml").argument("[prompt]", "Prompt for the agent").action(async (prompt) => {
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) => {
14336
14389
  const cwd = process.cwd();
14337
14390
  console.log(chalk14.blue(`Reading config: ${CONFIG_FILE3}`));
14338
14391
  if (!existsSync4(CONFIG_FILE3)) {
@@ -14446,14 +14499,46 @@ var cookCommand = new Command15().name("cook").description("One-click agent prep
14446
14499
  console.log();
14447
14500
  console.log(chalk14.blue(`Running agent: ${agentName}`));
14448
14501
  console.log();
14502
+ let runOutput;
14449
14503
  try {
14450
- await execVm0Command(
14451
- ["run", agentName, "--artifact-name", ARTIFACT_DIR, prompt],
14452
- { cwd, silent: false }
14453
- );
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 });
14454
14513
  } catch {
14455
14514
  process.exit(1);
14456
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
+ }
14457
14542
  } else {
14458
14543
  console.log();
14459
14544
  console.log(" Run your agent:");
@@ -14467,7 +14552,7 @@ var cookCommand = new Command15().name("cook").description("One-click agent prep
14467
14552
 
14468
14553
  // src/index.ts
14469
14554
  var program = new Command16();
14470
- program.name("vm0").description("VM0 CLI - A modern build tool").version("3.6.0");
14555
+ program.name("vm0").description("VM0 CLI - A modern build tool").version("3.7.0");
14471
14556
  program.command("hello").description("Say hello from the App").action(() => {
14472
14557
  console.log(chalk15.blue("Welcome to the VM0 CLI!"));
14473
14558
  console.log(chalk15.green(`Core says: ${FOO}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm0/cli",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "CLI application",
5
5
  "repository": {
6
6
  "type": "git",