@vm0/cli 9.82.2 → 9.83.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm0/cli",
3
- "version": "9.82.2",
3
+ "version": "9.83.1",
4
4
  "description": "CLI application",
5
5
  "repository": {
6
6
  "type": "git",
package/zero.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  createZeroAgent,
10
10
  createZeroComputerConnector,
11
11
  createZeroConnectorSession,
12
+ decodeCliTokenPayload,
12
13
  decodeZeroTokenPayload,
13
14
  deleteZeroAgent,
14
15
  deleteZeroComputerConnector,
@@ -73,6 +74,7 @@ import {
73
74
  setZeroOrgVariable,
74
75
  setZeroSecret,
75
76
  setZeroVariable,
77
+ switchZeroOrg,
76
78
  updateZeroAgent,
77
79
  updateZeroAgentInstructions,
78
80
  updateZeroOrg,
@@ -80,7 +82,7 @@ import {
80
82
  updateZeroUserPreferences,
81
83
  upsertZeroOrgModelProvider,
82
84
  withErrorHandler
83
- } from "./chunk-2RXB3R33.js";
85
+ } from "./chunk-5BLBSO2W.js";
84
86
 
85
87
  // src/zero.ts
86
88
  import { Command as Command55 } from "commander";
@@ -127,7 +129,16 @@ var setCommand = new Command2().name("set").description("Rename your organizatio
127
129
  );
128
130
  }
129
131
  const org = await updateZeroOrg({ slug, force: true });
130
- await saveConfig({ activeOrg: org.slug });
132
+ const token = await getToken();
133
+ if (decodeCliTokenPayload(token)) {
134
+ const result = await switchZeroOrg(org.slug);
135
+ await saveConfig({
136
+ token: result.access_token,
137
+ activeOrg: result.org_slug
138
+ });
139
+ } else {
140
+ await saveConfig({ activeOrg: org.slug });
141
+ }
131
142
  console.log(chalk2.green(`\u2713 Organization updated to ${org.slug}`));
132
143
  console.log();
133
144
  console.log("Your agents will now be namespaced as:");
@@ -171,7 +182,16 @@ var useCommand = new Command4().name("use").description("Switch to a different o
171
182
  if (!target) {
172
183
  throw new Error(`Organization '${slug}' not found or not accessible.`);
173
184
  }
174
- await saveConfig({ activeOrg: slug });
185
+ const token = await getToken();
186
+ if (decodeCliTokenPayload(token)) {
187
+ const result = await switchZeroOrg(slug);
188
+ await saveConfig({
189
+ token: result.access_token,
190
+ activeOrg: result.org_slug
191
+ });
192
+ } else {
193
+ await saveConfig({ activeOrg: slug });
194
+ }
175
195
  console.log(chalk4.green(`\u2713 Switched to organization: ${slug}`));
176
196
  })
177
197
  );
@@ -224,7 +244,7 @@ var leaveCommand = new Command8().name("leave").description("Leave the current o
224
244
  await leaveZeroOrg();
225
245
  const { orgs } = await listZeroOrgs();
226
246
  if (orgs.length === 0) {
227
- await saveConfig({ activeOrg: void 0 });
247
+ await saveConfig({ activeOrg: void 0, token: void 0 });
228
248
  console.log(chalk8.green("\u2713 Left organization."));
229
249
  console.log(
230
250
  chalk8.yellow("No remaining organizations. Run: vm0 auth login")
@@ -232,7 +252,16 @@ var leaveCommand = new Command8().name("leave").description("Leave the current o
232
252
  return;
233
253
  }
234
254
  const nextOrg = orgs[0].slug;
235
- await saveConfig({ activeOrg: nextOrg });
255
+ const token = await getToken();
256
+ if (decodeCliTokenPayload(token)) {
257
+ const result = await switchZeroOrg(nextOrg);
258
+ await saveConfig({
259
+ token: result.access_token,
260
+ activeOrg: result.org_slug
261
+ });
262
+ } else {
263
+ await saveConfig({ activeOrg: nextOrg });
264
+ }
236
265
  console.log(chalk8.green(`\u2713 Left organization. Switched to: ${nextOrg}`));
237
266
  })
238
267
  );
@@ -1068,7 +1097,7 @@ var createCommand = new Command24().name("create").description("Create a new zer
1068
1097
  const content = readFileSync(options.instructionsFile, "utf-8");
1069
1098
  await updateZeroAgentInstructions(agent.agentId, content);
1070
1099
  }
1071
- console.log(chalk21.green(`\u2713 Zero agent '${agent.agentId}' created`));
1100
+ console.log(chalk21.green(`\u2713 Agent "${agent.agentId}" created`));
1072
1101
  console.log(` Agent ID: ${agent.agentId}`);
1073
1102
  console.log(` Connectors: ${agent.connectors.join(", ")}`);
1074
1103
  if (agent.displayName) {
@@ -1111,7 +1140,7 @@ var editCommand = new Command25().name("edit").description("Edit a zero agent").
1111
1140
  const content = readFileSync2(options.instructionsFile, "utf-8");
1112
1141
  await updateZeroAgentInstructions(agentId, content);
1113
1142
  }
1114
- console.log(chalk22.green(`\u2713 Zero agent '${agentId}' updated`));
1143
+ console.log(chalk22.green(`\u2713 Agent "${agentId}" updated`));
1115
1144
  }
1116
1145
  )
1117
1146
  );
@@ -1202,7 +1231,7 @@ var deleteCommand2 = new Command28().name("delete").alias("rm").description("Del
1202
1231
  }
1203
1232
  }
1204
1233
  await deleteZeroAgent(agentId);
1205
- console.log(chalk25.green(`\u2713 Zero agent '${agentId}' deleted`));
1234
+ console.log(chalk25.green(`\u2713 Agent "${agentId}" deleted`));
1206
1235
  })
1207
1236
  );
1208
1237
 
@@ -1440,10 +1469,8 @@ async function connectViaApiToken(connectorType, tokenValue) {
1440
1469
  description: `API token for ${config.label} connector`
1441
1470
  });
1442
1471
  }
1443
- console.log(
1444
- chalk27.green(`
1445
- \u2713 ${config.label} connected successfully via API token!`)
1446
- );
1472
+ console.log(chalk27.green(`
1473
+ \u2713 Connector "${connectorType}" connected`));
1447
1474
  }
1448
1475
  async function connectComputer() {
1449
1476
  await checkComputerDependencies();
@@ -1519,7 +1546,7 @@ The session expires in ${Math.floor(session.expiresIn / 60)} minutes.`
1519
1546
  console.log(
1520
1547
  chalk27.green(`
1521
1548
 
1522
- ${connectorType} connected successfully!`)
1549
+ \u2713 Connector "${connectorType}" connected`)
1523
1550
  );
1524
1551
  return;
1525
1552
  case "expired":
@@ -2247,15 +2274,11 @@ Deploying schedule for agent ${chalk32.cyan(params.agentName)}...`
2247
2274
  });
2248
2275
  return deployResult;
2249
2276
  }
2250
- function displayDeployResult(agentName, deployResult) {
2277
+ function displayDeployResult(scheduleName, deployResult) {
2251
2278
  if (deployResult.created) {
2252
- console.log(
2253
- chalk32.green(`\u2713 Created schedule for agent ${chalk32.cyan(agentName)}`)
2254
- );
2279
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" created`));
2255
2280
  } else {
2256
- console.log(
2257
- chalk32.green(`\u2713 Updated schedule for agent ${chalk32.cyan(agentName)}`)
2258
- );
2281
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" updated`));
2259
2282
  }
2260
2283
  console.log(chalk32.dim(` Timezone: ${deployResult.schedule.timezone}`));
2261
2284
  if (deployResult.schedule.triggerType === "loop" && deployResult.schedule.intervalSeconds != null) {
@@ -2284,9 +2307,7 @@ function displayDeployResult(agentName, deployResult) {
2284
2307
  async function tryEnableSchedule(scheduleName, agentId, agentName) {
2285
2308
  try {
2286
2309
  await enableZeroSchedule({ name: scheduleName, agentId });
2287
- console.log(
2288
- chalk32.green(`\u2713 Enabled schedule for agent ${chalk32.cyan(agentName)}`)
2289
- );
2310
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" enabled`));
2290
2311
  } catch (error) {
2291
2312
  console.error(chalk32.yellow("\u26A0 Failed to enable schedule"));
2292
2313
  if (error instanceof ApiRequestError) {
@@ -2396,7 +2417,7 @@ var setupCommand2 = new Command36().name("setup").description("Create or edit a
2396
2417
  notifyEmail,
2397
2418
  notifySlack
2398
2419
  });
2399
- displayDeployResult(agentName, deployResult);
2420
+ displayDeployResult(scheduleName, deployResult);
2400
2421
  const shouldPromptEnable = deployResult.created || existingSchedule !== void 0 && !existingSchedule.enabled;
2401
2422
  await handleScheduleEnabling({
2402
2423
  scheduleName,
@@ -2567,9 +2588,7 @@ var deleteCommand3 = new Command39().name("delete").alias("rm").description("Del
2567
2588
  name: resolved.name,
2568
2589
  agentId: resolved.agentId
2569
2590
  });
2570
- console.log(
2571
- chalk35.green(`\u2713 Deleted schedule for agent ${chalk35.cyan(agentName)}`)
2572
- );
2591
+ console.log(chalk35.green(`\u2713 Schedule "${resolved.name}" deleted`));
2573
2592
  }
2574
2593
  )
2575
2594
  );
@@ -2590,9 +2609,7 @@ var enableCommand = new Command40().name("enable").description("Enable a zero sc
2590
2609
  name: resolved.name,
2591
2610
  agentId: resolved.agentId
2592
2611
  });
2593
- console.log(
2594
- chalk36.green(`\u2713 Enabled schedule for agent ${chalk36.cyan(agentName)}`)
2595
- );
2612
+ console.log(chalk36.green(`\u2713 Schedule "${resolved.name}" enabled`));
2596
2613
  })
2597
2614
  );
2598
2615
 
@@ -2612,9 +2629,7 @@ var disableCommand = new Command41().name("disable").description("Disable a zero
2612
2629
  name: resolved.name,
2613
2630
  agentId: resolved.agentId
2614
2631
  });
2615
- console.log(
2616
- chalk37.green(`\u2713 Disabled schedule for agent ${chalk37.cyan(agentName)}`)
2617
- );
2632
+ console.log(chalk37.green(`\u2713 Schedule "${resolved.name}" disabled`));
2618
2633
  })
2619
2634
  );
2620
2635
 
@@ -2910,12 +2925,9 @@ function isInsideSandbox() {
2910
2925
  async function showSandboxInfo() {
2911
2926
  const agentId = process.env.ZERO_AGENT_ID;
2912
2927
  const payload = decodeZeroTokenPayload();
2913
- console.log(chalk45.bold("Agent:"));
2914
- console.log(` ID: ${agentId}`);
2915
- console.log();
2916
- console.log(chalk45.bold("Run:"));
2917
- console.log(` ID: ${payload?.runId ?? chalk45.dim("unavailable")}`);
2918
- console.log(` Org: ${payload?.orgId ?? chalk45.dim("unavailable")}`);
2928
+ console.log(`Agent ID: ${agentId}`);
2929
+ console.log(`Run ID: ${payload?.runId ?? chalk45.dim("unavailable")}`);
2930
+ console.log(`Org ID: ${payload?.orgId ?? chalk45.dim("unavailable")}`);
2919
2931
  if (payload?.capabilities?.length) {
2920
2932
  console.log();
2921
2933
  console.log(chalk45.bold("Capabilities:"));
@@ -2959,38 +2971,40 @@ var COMMAND_CAPABILITY_MAP = {
2959
2971
  slack: "slack:write",
2960
2972
  whoami: null
2961
2973
  };
2962
- function applyCapabilityVisibility(prog) {
2974
+ var DEFAULT_COMMANDS = [
2975
+ zeroOrgCommand,
2976
+ zeroAgentCommand,
2977
+ zeroConnectorCommand,
2978
+ zeroPreferenceCommand,
2979
+ zeroScheduleCommand,
2980
+ zeroSecretCommand,
2981
+ zeroSlackCommand,
2982
+ zeroVariableCommand,
2983
+ zeroWhoamiCommand
2984
+ ];
2985
+ function shouldHideCommand(name, payload) {
2986
+ if (!payload) return false;
2987
+ const requiredCap = COMMAND_CAPABILITY_MAP[name];
2988
+ if (requiredCap === void 0) return true;
2989
+ return requiredCap !== null && !payload.capabilities.includes(requiredCap);
2990
+ }
2991
+ function registerZeroCommands(prog, commands) {
2963
2992
  const token = process.env.ZERO_TOKEN;
2964
- if (!token) return;
2965
- const payload = decodeZeroTokenPayload(token);
2966
- if (!payload) return;
2967
- for (const cmd of prog.commands) {
2968
- const requiredCap = COMMAND_CAPABILITY_MAP[cmd.name()];
2969
- if (requiredCap === void 0) {
2970
- cmd._hidden = true;
2971
- } else if (requiredCap !== null && !payload.capabilities.includes(requiredCap)) {
2972
- cmd._hidden = true;
2973
- }
2993
+ const payload = token ? decodeZeroTokenPayload(token) : void 0;
2994
+ for (const cmd of commands ?? DEFAULT_COMMANDS) {
2995
+ const hidden = shouldHideCommand(cmd.name(), payload);
2996
+ prog.addCommand(cmd, hidden ? { hidden: true } : {});
2974
2997
  }
2975
2998
  }
2976
2999
  var program = new Command55();
2977
- program.name("zero").description("Zero CLI - Manage your zero platform").version("9.82.2");
2978
- program.addCommand(zeroOrgCommand);
2979
- program.addCommand(zeroAgentCommand);
2980
- program.addCommand(zeroConnectorCommand);
2981
- program.addCommand(zeroPreferenceCommand);
2982
- program.addCommand(zeroScheduleCommand);
2983
- program.addCommand(zeroSecretCommand);
2984
- program.addCommand(zeroSlackCommand);
2985
- program.addCommand(zeroVariableCommand);
2986
- program.addCommand(zeroWhoamiCommand);
3000
+ program.name("zero").description("Zero CLI - Manage your zero platform").version("9.83.1");
2987
3001
  if (process.argv[1]?.endsWith("zero.js") || process.argv[1]?.endsWith("zero.ts") || process.argv[1]?.endsWith("zero")) {
2988
3002
  configureGlobalProxyFromEnv();
2989
- applyCapabilityVisibility(program);
3003
+ registerZeroCommands(program);
2990
3004
  program.parse();
2991
3005
  }
2992
3006
  export {
2993
- applyCapabilityVisibility,
2994
- program
3007
+ program,
3008
+ registerZeroCommands
2995
3009
  };
2996
3010
  //# sourceMappingURL=zero.js.map