@vm0/cli 3.3.0 → 3.5.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 +245 -89
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12147,8 +12147,8 @@ var helloContract = c.router({
12147
12147
  var FOO = "hello";
12148
12148
 
12149
12149
  // src/index.ts
12150
- import { Command as Command11 } from "commander";
12151
- import chalk11 from "chalk";
12150
+ import { Command as Command15 } from "commander";
12151
+ import chalk14 from "chalk";
12152
12152
 
12153
12153
  // src/lib/auth.ts
12154
12154
  import chalk from "chalk";
@@ -12352,6 +12352,39 @@ var ApiClient = class {
12352
12352
  }
12353
12353
  return await response.json();
12354
12354
  }
12355
+ async getComposeById(id) {
12356
+ const baseUrl = await this.getBaseUrl();
12357
+ const headers = await this.getHeaders();
12358
+ const response = await fetch(`${baseUrl}/api/agent/composes/${id}`, {
12359
+ method: "GET",
12360
+ headers
12361
+ });
12362
+ if (!response.ok) {
12363
+ const error43 = await response.json();
12364
+ throw new Error(error43.error?.message || `Compose not found: ${id}`);
12365
+ }
12366
+ return await response.json();
12367
+ }
12368
+ /**
12369
+ * Resolve a version specifier to a full version ID
12370
+ * Supports: "latest", full hash (64 chars), or hash prefix (8+ chars)
12371
+ */
12372
+ async getComposeVersion(composeId, version2) {
12373
+ const baseUrl = await this.getBaseUrl();
12374
+ const headers = await this.getHeaders();
12375
+ const response = await fetch(
12376
+ `${baseUrl}/api/agent/composes/versions?composeId=${encodeURIComponent(composeId)}&version=${encodeURIComponent(version2)}`,
12377
+ {
12378
+ method: "GET",
12379
+ headers
12380
+ }
12381
+ );
12382
+ if (!response.ok) {
12383
+ const error43 = await response.json();
12384
+ throw new Error(error43.error?.message || `Version not found: ${version2}`);
12385
+ }
12386
+ return await response.json();
12387
+ }
12355
12388
  async createOrUpdateCompose(body) {
12356
12389
  const baseUrl = await this.getBaseUrl();
12357
12390
  const headers = await this.getHeaders();
@@ -12369,6 +12402,7 @@ var ApiClient = class {
12369
12402
  /**
12370
12403
  * Create a run with unified request format
12371
12404
  * Supports new runs, checkpoint resume, and session continue
12405
+ * Note: Environment variables are expanded server-side from templateVars
12372
12406
  */
12373
12407
  async createRun(body) {
12374
12408
  const baseUrl = await this.getBaseUrl();
@@ -12459,6 +12493,27 @@ var ApiClient = class {
12459
12493
  body: options?.body
12460
12494
  });
12461
12495
  }
12496
+ /**
12497
+ * Generic DELETE request
12498
+ */
12499
+ async delete(path9) {
12500
+ const baseUrl = await this.getBaseUrl();
12501
+ const token = await getToken();
12502
+ if (!token) {
12503
+ throw new Error("Not authenticated. Run: vm0 auth login");
12504
+ }
12505
+ const headers = {
12506
+ Authorization: `Bearer ${token}`
12507
+ };
12508
+ const bypassSecret = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
12509
+ if (bypassSecret) {
12510
+ headers["x-vercel-protection-bypass"] = bypassSecret;
12511
+ }
12512
+ return fetch(`${baseUrl}${path9}`, {
12513
+ method: "DELETE",
12514
+ headers
12515
+ });
12516
+ }
12462
12517
  };
12463
12518
  var apiClient = new ApiClient();
12464
12519
 
@@ -12540,6 +12595,23 @@ function validateAgentCompose(config2) {
12540
12595
  error: "Missing or invalid agent.provider (must be a string)"
12541
12596
  };
12542
12597
  }
12598
+ if (agent.environment !== void 0) {
12599
+ if (agent.environment === null || typeof agent.environment !== "object" || Array.isArray(agent.environment)) {
12600
+ return {
12601
+ valid: false,
12602
+ error: "agent.environment must be an object with string keys and values"
12603
+ };
12604
+ }
12605
+ const env = agent.environment;
12606
+ for (const [key, value] of Object.entries(env)) {
12607
+ if (typeof value !== "string") {
12608
+ return {
12609
+ valid: false,
12610
+ error: `agent.environment.${key} must be a string`
12611
+ };
12612
+ }
12613
+ }
12614
+ }
12543
12615
  const agentVolumes = agent.volumes;
12544
12616
  if (agentVolumes && Array.isArray(agentVolumes) && agentVolumes.length > 0) {
12545
12617
  const volumesSection = cfg.volumes;
@@ -12580,62 +12652,6 @@ function validateAgentCompose(config2) {
12580
12652
  return { valid: true };
12581
12653
  }
12582
12654
 
12583
- // src/lib/env-expander.ts
12584
- function expandEnvVars(value) {
12585
- return value.replace(/\$\{([^}]+)\}/g, (_, varName) => {
12586
- return process.env[varName] ?? "";
12587
- });
12588
- }
12589
- function extractEnvVarReferences(obj) {
12590
- const varNames = /* @__PURE__ */ new Set();
12591
- function scan(value) {
12592
- if (typeof value === "string") {
12593
- const matches = value.matchAll(/\$\{([^}]+)\}/g);
12594
- for (const match of matches) {
12595
- const varName = match[1];
12596
- if (varName) {
12597
- varNames.add(varName);
12598
- }
12599
- }
12600
- } else if (Array.isArray(value)) {
12601
- for (const item of value) {
12602
- scan(item);
12603
- }
12604
- } else if (value !== null && typeof value === "object") {
12605
- for (const val of Object.values(value)) {
12606
- scan(val);
12607
- }
12608
- }
12609
- }
12610
- scan(obj);
12611
- return Array.from(varNames);
12612
- }
12613
- function validateEnvVars(varNames) {
12614
- const missing = [];
12615
- for (const varName of varNames) {
12616
- if (process.env[varName] === void 0) {
12617
- missing.push(varName);
12618
- }
12619
- }
12620
- return missing;
12621
- }
12622
- function expandEnvVarsInObject(obj) {
12623
- if (typeof obj === "string") {
12624
- return expandEnvVars(obj);
12625
- }
12626
- if (Array.isArray(obj)) {
12627
- return obj.map((item) => expandEnvVarsInObject(item));
12628
- }
12629
- if (obj !== null && typeof obj === "object") {
12630
- const result = {};
12631
- for (const [key, value] of Object.entries(obj)) {
12632
- result[key] = expandEnvVarsInObject(value);
12633
- }
12634
- return result;
12635
- }
12636
- return obj;
12637
- }
12638
-
12639
12655
  // src/commands/build.ts
12640
12656
  var buildCommand = new Command().name("build").description("Create or update agent compose").argument("<config-file>", "Path to config YAML file").action(async (configFile) => {
12641
12657
  try {
@@ -12654,24 +12670,6 @@ var buildCommand = new Command().name("build").description("Create or update age
12654
12670
  }
12655
12671
  process.exit(1);
12656
12672
  }
12657
- const referencedVars = extractEnvVarReferences(config2);
12658
- const missingVars = validateEnvVars(referencedVars);
12659
- if (missingVars.length > 0) {
12660
- console.error(chalk2.red("\u2717 Missing required environment variables:"));
12661
- for (const varName of missingVars) {
12662
- console.error(chalk2.red(` - ${varName}`));
12663
- }
12664
- console.error();
12665
- console.error(
12666
- chalk2.gray("Please set these variables before running 'vm0 build'.")
12667
- );
12668
- console.error(chalk2.gray("Example:"));
12669
- for (const varName of missingVars) {
12670
- console.error(chalk2.gray(` export ${varName}=your-value`));
12671
- }
12672
- process.exit(1);
12673
- }
12674
- config2 = expandEnvVarsInObject(config2);
12675
12673
  const validation = validateAgentCompose(config2);
12676
12674
  if (!validation.valid) {
12677
12675
  console.error(chalk2.red(`\u2717 ${validation.error}`));
@@ -13100,6 +13098,19 @@ function collectVolumeVersions(value, previous) {
13100
13098
  function isUUID(str) {
13101
13099
  return /^[0-9a-f-]{36}$/i.test(str);
13102
13100
  }
13101
+ function parseIdentifier(identifier) {
13102
+ if (isUUID(identifier)) {
13103
+ return { name: identifier };
13104
+ }
13105
+ const colonIndex = identifier.lastIndexOf(":");
13106
+ if (colonIndex > 0 && colonIndex < identifier.length - 1) {
13107
+ return {
13108
+ name: identifier.slice(0, colonIndex),
13109
+ version: identifier.slice(colonIndex + 1)
13110
+ };
13111
+ }
13112
+ return { name: identifier };
13113
+ }
13103
13114
  var DEFAULT_TIMEOUT_SECONDS = 120;
13104
13115
  async function pollEvents(runId, timeoutSeconds, options) {
13105
13116
  let nextSequence = -1;
@@ -13166,7 +13177,7 @@ ${action}...`));
13166
13177
  }
13167
13178
  var runCmd = new Command2().name("run").description("Execute an agent").argument(
13168
13179
  "<identifier>",
13169
- "Agent name or config ID (e.g., 'my-agent' or 'cfg-abc-123')"
13180
+ "Agent name, config ID, or name:version (e.g., 'my-agent', 'my-agent:abc123', 'my-agent:latest')"
13170
13181
  ).argument("<prompt>", "Prompt for the agent").option(
13171
13182
  "--vars <KEY=value>",
13172
13183
  "Template variables for config placeholders (repeatable)",
@@ -13208,25 +13219,26 @@ var runCmd = new Command2().name("run").description("Execute an agent").argument
13208
13219
  }
13209
13220
  const verbose = options.verbose;
13210
13221
  try {
13222
+ const { name, version: version2 } = parseIdentifier(identifier);
13211
13223
  let composeId;
13212
- if (isUUID(identifier)) {
13213
- composeId = identifier;
13224
+ if (isUUID(name)) {
13225
+ composeId = name;
13214
13226
  if (verbose) {
13215
- console.log(chalk4.gray(` Using compose ID: ${composeId}`));
13227
+ console.log(chalk4.gray(` Using compose ID: ${identifier}`));
13216
13228
  }
13217
13229
  } else {
13218
13230
  if (verbose) {
13219
- console.log(chalk4.gray(` Resolving agent name: ${identifier}`));
13231
+ console.log(chalk4.gray(` Resolving agent name: ${name}`));
13220
13232
  }
13221
13233
  try {
13222
- const compose = await apiClient.getComposeByName(identifier);
13234
+ const compose = await apiClient.getComposeByName(name);
13223
13235
  composeId = compose.id;
13224
13236
  if (verbose) {
13225
13237
  console.log(chalk4.gray(` Resolved to compose ID: ${composeId}`));
13226
13238
  }
13227
13239
  } catch (error43) {
13228
13240
  if (error43 instanceof Error) {
13229
- console.error(chalk4.red(`\u2717 Agent not found: ${identifier}`));
13241
+ console.error(chalk4.red(`\u2717 Agent not found: ${name}`));
13230
13242
  console.error(
13231
13243
  chalk4.gray(
13232
13244
  " Make sure you've built the agent with: vm0 build"
@@ -13236,9 +13248,40 @@ var runCmd = new Command2().name("run").description("Execute an agent").argument
13236
13248
  process.exit(1);
13237
13249
  }
13238
13250
  }
13251
+ let agentComposeVersionId;
13252
+ if (version2 && version2 !== "latest") {
13253
+ if (verbose) {
13254
+ console.log(chalk4.gray(` Resolving version: ${version2}`));
13255
+ }
13256
+ try {
13257
+ const versionInfo = await apiClient.getComposeVersion(
13258
+ composeId,
13259
+ version2
13260
+ );
13261
+ agentComposeVersionId = versionInfo.versionId;
13262
+ if (verbose) {
13263
+ console.log(
13264
+ chalk4.gray(
13265
+ ` Resolved to version ID: ${agentComposeVersionId.slice(0, 8)}...`
13266
+ )
13267
+ );
13268
+ }
13269
+ } catch (error43) {
13270
+ if (error43 instanceof Error) {
13271
+ console.error(chalk4.red(`\u2717 Version not found: ${version2}`));
13272
+ console.error(
13273
+ chalk4.gray(
13274
+ " Make sure the version hash exists. Use 'vm0 build' to see available versions."
13275
+ )
13276
+ );
13277
+ }
13278
+ process.exit(1);
13279
+ }
13280
+ }
13239
13281
  if (verbose) {
13240
13282
  logVerbosePreFlight("Creating agent run", [
13241
13283
  { label: "Prompt", value: prompt },
13284
+ { label: "Version", value: version2 || "latest (HEAD)" },
13242
13285
  {
13243
13286
  label: "Variables",
13244
13287
  value: Object.keys(options.vars).length > 0 ? JSON.stringify(options.vars) : void 0
@@ -13253,7 +13296,8 @@ var runCmd = new Command2().name("run").description("Execute an agent").argument
13253
13296
  ]);
13254
13297
  }
13255
13298
  const response = await apiClient.createRun({
13256
- agentComposeId: composeId,
13299
+ // Use agentComposeVersionId if resolved, otherwise use agentComposeId (resolves to HEAD)
13300
+ ...agentComposeVersionId ? { agentComposeVersionId } : { agentComposeId: composeId },
13257
13301
  prompt,
13258
13302
  templateVars: Object.keys(options.vars).length > 0 ? options.vars : void 0,
13259
13303
  artifactName: options.artifactName,
@@ -14138,15 +14182,126 @@ var pullCommand2 = new Command9().name("pull").description("Pull cloud artifact
14138
14182
  // src/commands/artifact/index.ts
14139
14183
  var artifactCommand = new Command10().name("artifact").description("Manage cloud artifacts (work products)").addCommand(initCommand2).addCommand(pushCommand2).addCommand(pullCommand2);
14140
14184
 
14185
+ // src/commands/secret/index.ts
14186
+ import { Command as Command14 } from "commander";
14187
+
14188
+ // src/commands/secret/set.ts
14189
+ import { Command as Command11 } from "commander";
14190
+ import chalk11 from "chalk";
14191
+ var setCommand = new Command11().name("set").description("Create or update a secret").argument(
14192
+ "<name>",
14193
+ "Secret name (must start with letter, alphanumeric and underscores only)"
14194
+ ).argument("<value>", "Secret value").action(async (name, value) => {
14195
+ try {
14196
+ const nameRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;
14197
+ if (!nameRegex.test(name)) {
14198
+ console.error(chalk11.red("\u2717 Invalid secret name"));
14199
+ console.error(
14200
+ chalk11.gray(
14201
+ " Must start with a letter and contain only letters, numbers, and underscores"
14202
+ )
14203
+ );
14204
+ process.exit(1);
14205
+ }
14206
+ if (name.length > 255) {
14207
+ console.error(chalk11.red("\u2717 Secret name too long (max 255 characters)"));
14208
+ process.exit(1);
14209
+ }
14210
+ const response = await apiClient.post("/api/secrets", {
14211
+ body: JSON.stringify({ name, value })
14212
+ });
14213
+ if (!response.ok) {
14214
+ const error43 = await response.json();
14215
+ throw new Error(error43.error?.message || "Failed to set secret");
14216
+ }
14217
+ const result = await response.json();
14218
+ if (result.action === "created") {
14219
+ console.log(chalk11.green(`\u2713 Secret created: ${name}`));
14220
+ } else {
14221
+ console.log(chalk11.green(`\u2713 Secret updated: ${name}`));
14222
+ }
14223
+ } catch (error43) {
14224
+ console.error(chalk11.red("\u2717 Failed to set secret"));
14225
+ if (error43 instanceof Error) {
14226
+ console.error(chalk11.gray(` ${error43.message}`));
14227
+ }
14228
+ process.exit(1);
14229
+ }
14230
+ });
14231
+
14232
+ // src/commands/secret/list.ts
14233
+ import { Command as Command12 } from "commander";
14234
+ import chalk12 from "chalk";
14235
+ var listCommand = new Command12().name("list").alias("ls").description("List all secrets (names only)").action(async () => {
14236
+ try {
14237
+ const response = await apiClient.get("/api/secrets");
14238
+ if (!response.ok) {
14239
+ const error43 = await response.json();
14240
+ throw new Error(error43.error?.message || "Failed to list secrets");
14241
+ }
14242
+ const result = await response.json();
14243
+ if (result.secrets.length === 0) {
14244
+ console.log(chalk12.gray("No secrets found"));
14245
+ console.log(
14246
+ chalk12.gray(" Create one with: vm0 secret set <name> <value>")
14247
+ );
14248
+ return;
14249
+ }
14250
+ console.log(chalk12.cyan("Secrets:"));
14251
+ for (const secret of result.secrets) {
14252
+ const updatedAt = new Date(secret.updatedAt).toLocaleDateString();
14253
+ console.log(
14254
+ ` ${chalk12.white(secret.name)} ${chalk12.gray(`(updated: ${updatedAt})`)}`
14255
+ );
14256
+ }
14257
+ console.log(chalk12.gray(`
14258
+ Total: ${result.secrets.length} secret(s)`));
14259
+ } catch (error43) {
14260
+ console.error(chalk12.red("\u2717 Failed to list secrets"));
14261
+ if (error43 instanceof Error) {
14262
+ console.error(chalk12.gray(` ${error43.message}`));
14263
+ }
14264
+ process.exit(1);
14265
+ }
14266
+ });
14267
+
14268
+ // src/commands/secret/delete.ts
14269
+ import { Command as Command13 } from "commander";
14270
+ import chalk13 from "chalk";
14271
+ var deleteCommand = new Command13().name("delete").alias("rm").description("Delete a secret").argument("<name>", "Secret name to delete").action(async (name) => {
14272
+ try {
14273
+ const response = await apiClient.delete(
14274
+ `/api/secrets?name=${encodeURIComponent(name)}`
14275
+ );
14276
+ if (!response.ok) {
14277
+ const error43 = await response.json();
14278
+ throw new Error(error43.error?.message || `Secret not found: ${name}`);
14279
+ }
14280
+ const result = await response.json();
14281
+ if (result.deleted) {
14282
+ console.log(chalk13.green(`\u2713 Secret deleted: ${name}`));
14283
+ }
14284
+ } catch (error43) {
14285
+ console.error(chalk13.red("\u2717 Failed to delete secret"));
14286
+ if (error43 instanceof Error) {
14287
+ console.error(chalk13.gray(` ${error43.message}`));
14288
+ }
14289
+ process.exit(1);
14290
+ }
14291
+ });
14292
+
14293
+ // src/commands/secret/index.ts
14294
+ var secretCommand = new Command14().name("secret").description("Manage secrets for agent compose configurations").addCommand(setCommand).addCommand(listCommand).addCommand(deleteCommand);
14295
+
14141
14296
  // src/index.ts
14142
- var program = new Command11();
14143
- program.name("vm0").description("VM0 CLI - A modern build tool").version("3.3.0");
14297
+ var program = new Command15();
14298
+ program.name("vm0").description("VM0 CLI - A modern build tool").version("3.5.0");
14144
14299
  program.command("hello").description("Say hello from the App").action(() => {
14145
- console.log(chalk11.blue("Welcome to the VM0 CLI!"));
14146
- console.log(chalk11.green(`Core says: ${FOO}`));
14300
+ console.log(chalk14.blue("Welcome to the VM0 CLI!"));
14301
+ console.log(chalk14.green(`Core says: ${FOO}`));
14147
14302
  });
14148
14303
  program.command("info").description("Display environment information").action(async () => {
14149
- console.log(chalk11.cyan("System Information:"));
14304
+ console.log(chalk14.cyan("System Information:"));
14150
14305
  console.log(`Node Version: ${process.version}`);
14151
14306
  console.log(`Platform: ${process.platform}`);
14152
14307
  console.log(`Architecture: ${process.arch}`);
@@ -14167,6 +14322,7 @@ program.addCommand(buildCommand);
14167
14322
  program.addCommand(runCommand);
14168
14323
  program.addCommand(volumeCommand);
14169
14324
  program.addCommand(artifactCommand);
14325
+ program.addCommand(secretCommand);
14170
14326
  if (process.argv[1]?.endsWith("index.js") || process.argv[1]?.endsWith("index.ts") || process.argv[1]?.endsWith("vm0")) {
14171
14327
  program.parse();
14172
14328
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm0/cli",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "CLI application",
5
5
  "repository": {
6
6
  "type": "git",