@vellumai/cli 0.8.2 → 0.8.4

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.
@@ -4,9 +4,12 @@ import path from "node:path";
4
4
 
5
5
  import {
6
6
  findAssistantByName,
7
+ formatAssistantLookupError,
7
8
  getActiveAssistant,
9
+ lookupAssistantByIdentifier,
8
10
  resolveAssistant,
9
11
  saveAssistantEntry,
12
+ type AssistantEntry,
10
13
  } from "../lib/assistant-config";
11
14
  import {
12
15
  DAEMON_INTERNAL_ASSISTANT_ID,
@@ -20,6 +23,7 @@ import {
20
23
  WEB_INTERFACE_ID,
21
24
  getClientRegistrationHeaders,
22
25
  } from "../lib/client-identity";
26
+ import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
23
27
  import {
24
28
  fetchOrganizationId,
25
29
  fetchPlatformAssistants,
@@ -51,13 +55,9 @@ interface ParsedArgs {
51
55
  bearerToken?: string;
52
56
  /** Interface identifier sent as X-Vellum-Interface-Id on all requests. */
53
57
  interfaceId: SupportedInterface;
54
- project?: string;
55
- zone?: string;
56
58
  }
57
59
 
58
- function readAssistantName(
59
- entry: ReturnType<typeof findAssistantByName>,
60
- ): string | undefined {
60
+ function readAssistantName(entry: AssistantEntry | null): string | undefined {
61
61
  const rawName = entry?.name ?? entry?.assistantName;
62
62
  return typeof rawName === "string" && rawName.trim()
63
63
  ? rawName.trim()
@@ -67,7 +67,14 @@ function readAssistantName(
67
67
  function parseArgs(): ParsedArgs {
68
68
  const args = process.argv.slice(3);
69
69
 
70
- let positionalName: string | undefined;
70
+ const positionalName = parseAssistantTargetArg(args, [
71
+ "--url",
72
+ "-u",
73
+ "--assistant-id",
74
+ "-a",
75
+ "--interface",
76
+ "-i",
77
+ ]);
71
78
  const flagArgs: string[] = [];
72
79
  for (let i = 0; i < args.length; i++) {
73
80
  const arg = args[i];
@@ -84,29 +91,29 @@ function parseArgs(): ParsedArgs {
84
91
  args[i + 1]
85
92
  ) {
86
93
  flagArgs.push(arg, args[++i]);
87
- } else if (!arg.startsWith("-") && positionalName === undefined) {
88
- positionalName = arg;
89
94
  }
90
95
  }
91
96
 
92
- let entry: ReturnType<typeof findAssistantByName> = null;
97
+ let entry: AssistantEntry | null = null;
93
98
  if (positionalName) {
94
- entry = findAssistantByName(positionalName);
95
- if (!entry) {
96
- console.error(
97
- `No assistant instance found with name '${positionalName}'.`,
98
- );
99
+ const result = lookupAssistantByIdentifier(positionalName);
100
+ if (result.status !== "found") {
101
+ console.error(formatAssistantLookupError(positionalName, result));
99
102
  process.exit(1);
100
103
  }
104
+ entry = result.entry;
101
105
  } else {
102
106
  const hasExplicitUrl =
103
107
  flagArgs.includes("--url") || flagArgs.includes("-u");
104
108
  const active = getActiveAssistant();
105
109
  if (active) {
106
- entry = findAssistantByName(active);
110
+ const result = lookupAssistantByIdentifier(active);
111
+ if (result.status === "found") {
112
+ entry = result.entry;
113
+ }
107
114
  if (!entry && !hasExplicitUrl) {
108
115
  console.error(
109
- `Active assistant '${active}' not found in lockfile. Set an active assistant with 'vellum use <name>'.`,
116
+ `Active assistant '${active}' not found in lockfile. Set an active assistant with 'vellum use <name-or-id>'.`,
110
117
  );
111
118
  process.exit(1);
112
119
  }
@@ -116,7 +123,7 @@ function parseArgs(): ParsedArgs {
116
123
  entry = resolveAssistant();
117
124
  } else if (!entry) {
118
125
  console.error(
119
- "No active assistant set. Set one with 'vellum use <name>' or specify a name: 'vellum client <name>'.",
126
+ "No active assistant set. Set one with 'vellum use <name-or-id>' or specify one: 'vellum client <name-or-id>'.",
120
127
  );
121
128
  process.exit(1);
122
129
  }
@@ -169,8 +176,6 @@ function parseArgs(): ParsedArgs {
169
176
  platformToken,
170
177
  bearerToken,
171
178
  interfaceId,
172
- project: entry?.project,
173
- zone: entry?.zone,
174
179
  };
175
180
  }
176
181
 
@@ -217,10 +222,10 @@ function printUsage(): void {
217
222
  console.log(`${ANSI.bold}vellum client${ANSI.reset} - Connect to a hatched assistant
218
223
 
219
224
  ${ANSI.bold}USAGE:${ANSI.reset}
220
- vellum client [name] [options]
225
+ vellum client [name-or-id] [options]
221
226
 
222
227
  ${ANSI.bold}ARGUMENTS:${ANSI.reset}
223
- [name] Instance name (default: active)
228
+ [name-or-id] Assistant display name or ID (default: active)
224
229
 
225
230
  ${ANSI.bold}OPTIONS:${ANSI.reset}
226
231
  -u, --url <url> Runtime URL
@@ -343,8 +348,6 @@ export async function client(): Promise<void> {
343
348
  platformToken,
344
349
  bearerToken,
345
350
  interfaceId,
346
- project,
347
- zone,
348
351
  } = parseArgs();
349
352
 
350
353
  if (interfaceId === WEB_INTERFACE_ID) {
@@ -404,6 +407,6 @@ export async function client(): Promise<void> {
404
407
  console.log(`${ANSI.dim}Disconnected.${ANSI.reset}`);
405
408
  process.exit(0);
406
409
  },
407
- { auth, project, zone, assistantName },
410
+ { auth, assistantName },
408
411
  );
409
412
  }
@@ -8,7 +8,6 @@ import {
8
8
  saveAssistantEntry,
9
9
  setActiveAssistant,
10
10
  } from "../lib/assistant-config";
11
- import { hatchAws } from "../lib/aws";
12
11
  import {
13
12
  SPECIES_CONFIG,
14
13
  VALID_REMOTE_HOSTS,
@@ -17,7 +16,6 @@ import {
17
16
  import type { RemoteHost, Species } from "../lib/constants";
18
17
  import { buildNestedConfig } from "../lib/config-utils";
19
18
  import { hatchDocker } from "../lib/docker";
20
- import { hatchGcp } from "../lib/gcp";
21
19
  import type { PollResult, WatchHatchingResult } from "../lib/gcp";
22
20
  import { hatchLocal } from "../lib/hatch-local";
23
21
  import {
@@ -169,6 +167,7 @@ source ${INSTALL_SCRIPT_REMOTE_PATH}
169
167
  }
170
168
 
171
169
  const DEFAULT_REMOTE: RemoteHost = "local";
170
+ const UNSUPPORTED_REMOTE_HATCH_TARGETS = new Set<RemoteHost>(["aws", "gcp"]);
172
171
 
173
172
  interface HatchArgs {
174
173
  species: Species;
@@ -177,7 +176,9 @@ interface HatchArgs {
177
176
  name: string | null;
178
177
  remote: RemoteHost;
179
178
  watch: boolean;
179
+ sourcePath: string | null;
180
180
  configValues: Record<string, string>;
181
+ analyze: boolean;
181
182
  }
182
183
 
183
184
  function parseArgs(): HatchArgs {
@@ -188,7 +189,9 @@ function parseArgs(): HatchArgs {
188
189
  let name: string | null = null;
189
190
  let remote: RemoteHost = DEFAULT_REMOTE;
190
191
  let watch = false;
192
+ let sourcePath: string | null = null;
191
193
  const configValues: Record<string, string> = {};
194
+ let analyze = false;
192
195
 
193
196
  for (let i = 0; i < args.length; i++) {
194
197
  const arg = args[i];
@@ -210,17 +213,33 @@ function parseArgs(): HatchArgs {
210
213
  console.log(
211
214
  " --watch Run assistant and gateway in watch mode (hot reload on source changes)",
212
215
  );
216
+ console.log(
217
+ " --source <path> Build images from a local source tree at <path> (no watcher). Useful for callers (e.g. evals) that want each run to pick up local CLI changes.",
218
+ );
213
219
  console.log(
214
220
  " --keep-alive Stay alive after hatch, exit when gateway stops",
215
221
  );
216
222
  console.log(
217
223
  " --config <key=value> Set a workspace config value (repeatable)",
218
224
  );
225
+ console.log(
226
+ " --analyze Emit a structured hatch-timing log line on stdout",
227
+ );
219
228
  process.exit(0);
220
229
  } else if (arg === "-d") {
221
230
  detached = true;
222
231
  } else if (arg === "--watch") {
223
232
  watch = true;
233
+ } else if (arg === "--analyze") {
234
+ analyze = true;
235
+ } else if (arg === "--source") {
236
+ const next = args[i + 1];
237
+ if (!next || next.startsWith("-")) {
238
+ console.error("Error: --source requires a path argument");
239
+ process.exit(1);
240
+ }
241
+ sourcePath = next;
242
+ i++;
224
243
  } else if (arg === "--keep-alive") {
225
244
  keepAlive = true;
226
245
  } else if (arg === "--name") {
@@ -270,7 +289,7 @@ function parseArgs(): HatchArgs {
270
289
  species = arg as Species;
271
290
  } else {
272
291
  console.error(
273
- `Error: Unknown argument '${arg}'. Valid options: ${VALID_SPECIES.join(", ")}, -d, --watch, --keep-alive, --name <name>, --remote <${VALID_REMOTE_HOSTS.join("|")}>, --config <key=value>`,
292
+ `Error: Unknown argument '${arg}'. Valid options: ${VALID_SPECIES.join(", ")}, -d, --watch, --source <path>, --keep-alive, --name <name>, --remote <${VALID_REMOTE_HOSTS.join("|")}>, --config <key=value>, --analyze`,
274
293
  );
275
294
  process.exit(1);
276
295
  }
@@ -283,7 +302,9 @@ function parseArgs(): HatchArgs {
283
302
  name,
284
303
  remote,
285
304
  watch,
305
+ sourcePath,
286
306
  configValues,
307
+ analyze,
287
308
  };
288
309
  }
289
310
 
@@ -508,8 +529,17 @@ export async function hatch(): Promise<void> {
508
529
  const cliVersion = getCliVersion();
509
530
  console.log(`@vellumai/cli v${cliVersion}`);
510
531
 
511
- const { species, detached, keepAlive, name, remote, watch, configValues } =
512
- parseArgs();
532
+ const {
533
+ species,
534
+ detached,
535
+ keepAlive,
536
+ name,
537
+ remote,
538
+ watch,
539
+ sourcePath,
540
+ configValues,
541
+ analyze,
542
+ } = parseArgs();
513
543
 
514
544
  if (watch && remote !== "local" && remote !== "docker") {
515
545
  console.error(
@@ -518,30 +548,33 @@ export async function hatch(): Promise<void> {
518
548
  process.exit(1);
519
549
  }
520
550
 
521
- if (remote === "local") {
522
- await hatchLocal(species, name, watch, keepAlive, configValues);
523
- return;
551
+ if (sourcePath !== null && remote !== "docker") {
552
+ console.error(
553
+ "Error: --source is only supported for docker hatch targets.",
554
+ );
555
+ process.exit(1);
524
556
  }
525
557
 
526
- if (remote === "gcp") {
527
- await hatchGcp(
528
- species,
529
- detached,
530
- name,
531
- buildStartupScript,
532
- watchHatching,
533
- configValues,
558
+ if (UNSUPPORTED_REMOTE_HATCH_TARGETS.has(remote)) {
559
+ console.error(
560
+ `Error: \`vellum hatch --remote ${remote}\` is not a supported provisioning target yet.`,
534
561
  );
535
- return;
562
+ console.error(
563
+ "No cloud resources were created. To self-host on AWS/GCP, SSH into the VM and run `vellum hatch` or `vellum hatch --remote docker` there.",
564
+ );
565
+ process.exit(1);
536
566
  }
537
567
 
538
- if (remote === "aws") {
539
- await hatchAws(species, detached, name, configValues);
568
+ if (remote === "local") {
569
+ await hatchLocal(species, name, watch, keepAlive, configValues);
540
570
  return;
541
571
  }
542
572
 
543
573
  if (remote === "docker") {
544
- await hatchDocker(species, detached, name, watch, configValues);
574
+ await hatchDocker(species, detached, name, watch, configValues, {
575
+ sourcePath,
576
+ analyze,
577
+ });
545
578
  return;
546
579
  }
547
580
 
@@ -2,11 +2,16 @@ import { join } from "path";
2
2
 
3
3
  import {
4
4
  findAssistantByName,
5
+ formatAssistantLookupError,
6
+ formatAssistantReference,
5
7
  getActiveAssistant,
8
+ getAssistantDisplayName,
6
9
  getDaemonPidPath,
7
10
  loadAllAssistants,
11
+ lookupAssistantByIdentifier,
8
12
  type AssistantEntry,
9
13
  } from "../lib/assistant-config";
14
+ import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
10
15
  import { resolveEnvironmentSource } from "../lib/environments/resolve";
11
16
  import { loadGuardianToken } from "../lib/guardian-token";
12
17
  import {
@@ -52,8 +57,10 @@ function pad(s: string, w: number): string {
52
57
  return s + " ".repeat(Math.max(0, w - s.length));
53
58
  }
54
59
 
55
- function computeColWidths(rows: TableRow[]): ColWidths {
56
- const headers: TableRow = { name: "NAME", status: "STATUS", info: "INFO" };
60
+ function computeColWidths(
61
+ rows: TableRow[],
62
+ headers: TableRow = { name: "NAME", status: "STATUS", info: "INFO" },
63
+ ): ColWidths {
57
64
  const all = [headers, ...rows];
58
65
  return {
59
66
  name: Math.max(...all.map((r) => r.name.length)),
@@ -66,9 +73,11 @@ function formatRow(r: TableRow, colWidths: ColWidths): string {
66
73
  return ` ${pad(r.name, colWidths.name)} ${pad(r.status, colWidths.status)} ${r.info}`;
67
74
  }
68
75
 
69
- function printTable(rows: TableRow[]): void {
70
- const colWidths = computeColWidths(rows);
71
- const headers: TableRow = { name: "PROCESS", status: "STATUS", info: "INFO" };
76
+ function printTable(
77
+ rows: TableRow[],
78
+ headers: TableRow = { name: "PROCESS", status: "STATUS", info: "INFO" },
79
+ ): void {
80
+ const colWidths = computeColWidths(rows, headers);
72
81
  console.log(formatRow(headers, colWidths));
73
82
  const sep = ` ${"-".repeat(colWidths.name)} ${"-".repeat(colWidths.status)} ${"-".repeat(colWidths.info)}`;
74
83
  console.log(sep);
@@ -377,7 +386,7 @@ async function getDockerProcesses(entry: AssistantEntry): Promise<TableRow[]> {
377
386
  async function showAssistantProcesses(entry: AssistantEntry): Promise<void> {
378
387
  const cloud = resolveCloud(entry);
379
388
 
380
- console.log(`Processes for ${entry.assistantId} (${cloud}):\n`);
389
+ console.log(`Processes for ${formatAssistantReference(entry)} (${cloud}):\n`);
381
390
 
382
391
  if (cloud === "local") {
383
392
  const rows = await getLocalProcesses(entry);
@@ -473,6 +482,75 @@ async function showAssistantProcesses(entry: AssistantEntry): Promise<void> {
473
482
 
474
483
  // ── List all assistants (no arg) ────────────────────────────────
475
484
 
485
+ type AssistantHealth = {
486
+ status: string;
487
+ detail: string | null;
488
+ version?: string;
489
+ };
490
+
491
+ async function getAssistantListHealth(
492
+ entry: AssistantEntry,
493
+ ): Promise<AssistantHealth> {
494
+ const resources = entry.resources;
495
+ if (entry.cloud === "local" && resources) {
496
+ // TODO(ATL-306): Remove readPidFile/getDaemonPidPath in favor of
497
+ // fetching daemon PIDs via the health API (Gateway Security Migration).
498
+ const pid = readPidFile(getDaemonPidPath(resources));
499
+ const alive = pid !== null && isProcessAlive(pid);
500
+ if (!alive) {
501
+ return { status: "sleeping", detail: null };
502
+ }
503
+ const token = loadGuardianToken(entry.assistantId)?.accessToken;
504
+ return checkHealth(entry.localUrl ?? entry.runtimeUrl, token);
505
+ }
506
+
507
+ if (entry.cloud === "docker") {
508
+ const res = dockerResourceNames(entry.assistantId);
509
+ const state = await getDockerContainerState(res.assistantContainer);
510
+ if (!state || state !== "running") {
511
+ return { status: "sleeping", detail: null };
512
+ }
513
+ const token = loadGuardianToken(entry.assistantId)?.accessToken;
514
+ return checkHealth(entry.localUrl ?? entry.runtimeUrl, token);
515
+ }
516
+
517
+ if (entry.cloud === "apple-container") {
518
+ // Apple containers are managed by the macOS app. Probe the gateway
519
+ // (runtimeUrl is always written to the lockfile during hatch).
520
+ const token = loadGuardianToken(entry.assistantId)?.accessToken;
521
+ return entry.runtimeUrl
522
+ ? checkHealth(entry.runtimeUrl, token)
523
+ : { status: "unknown", detail: "no runtime URL" };
524
+ }
525
+
526
+ if (entry.cloud === "vellum") {
527
+ return checkManagedHealth(entry.runtimeUrl, entry.assistantId);
528
+ }
529
+
530
+ const token = loadGuardianToken(entry.assistantId)?.accessToken;
531
+ return checkHealth(entry.localUrl ?? entry.runtimeUrl, token);
532
+ }
533
+
534
+ function formatAssistantListRow(
535
+ entry: AssistantEntry,
536
+ activeAssistantId: string | null,
537
+ health: AssistantHealth,
538
+ ): TableRow {
539
+ const infoParts: string[] = [];
540
+ infoParts.push(`id: ${entry.assistantId}`);
541
+ if (entry.runtimeUrl) infoParts.push(entry.runtimeUrl);
542
+ if (entry.cloud) infoParts.push(`cloud: ${entry.cloud}`);
543
+ if (entry.species) infoParts.push(`species: ${entry.species}`);
544
+ if (health.detail) infoParts.push(health.detail);
545
+
546
+ const prefix = entry.assistantId === activeAssistantId ? "* " : " ";
547
+ return {
548
+ name: prefix + getAssistantDisplayName(entry),
549
+ status: withStatusEmoji(health.status),
550
+ info: infoParts.join(" | "),
551
+ };
552
+ }
553
+
476
554
  export async function listAllAssistants(verbose: boolean): Promise<void> {
477
555
  const { name: envName, source: envSource } = resolveEnvironmentSource();
478
556
  const sourceLabels: Record<typeof envSource, string> = {
@@ -519,6 +597,9 @@ export async function listAllAssistants(verbose: boolean): Promise<void> {
519
597
 
520
598
  const assistants = loadAllAssistants();
521
599
  const activeId = getActiveAssistant();
600
+ const activeAssistantId = activeId
601
+ ? (findAssistantByName(activeId)?.assistantId ?? activeId)
602
+ : null;
522
603
 
523
604
  if (assistants.length === 0) {
524
605
  console.log("No assistants found.");
@@ -540,97 +621,17 @@ export async function listAllAssistants(verbose: boolean): Promise<void> {
540
621
  return;
541
622
  }
542
623
 
543
- const rows: TableRow[] = assistants.map((a) => {
544
- const infoParts: string[] = [];
545
- if (a.runtimeUrl) infoParts.push(a.runtimeUrl);
546
- if (a.cloud) infoParts.push(`cloud: ${a.cloud}`);
547
- if (a.species) infoParts.push(`species: ${a.species}`);
548
- const prefix = a.assistantId === activeId ? "* " : " ";
549
-
550
- return {
551
- name: prefix + a.assistantId,
552
- status: withStatusEmoji("checking..."),
553
- info: infoParts.join(" | "),
554
- };
555
- });
556
-
557
- const colWidths = computeColWidths(rows);
558
-
559
- const headers: TableRow = { name: "NAME", status: "STATUS", info: "INFO" };
560
- console.log(formatRow(headers, colWidths));
561
- const sep = ` ${"-".repeat(colWidths.name)} ${"-".repeat(colWidths.status)} ${"-".repeat(colWidths.info)}`;
562
- console.log(sep);
563
- for (const row of rows) {
564
- console.log(formatRow(row, colWidths));
565
- }
566
-
567
- const totalDataRows = rows.length;
568
-
569
- await Promise.all(
570
- assistants.map(async (a, rowIndex) => {
571
- // For local assistants, check if the daemon process is alive before
572
- // hitting the health endpoint. If the PID file is missing or the
573
- // process isn't running, the assistant is sleeping — skip the
574
- // network health check to avoid a misleading "unreachable" status.
575
- let health: { status: string; detail: string | null; version?: string };
576
- const resources = a.resources;
577
- if (a.cloud === "local" && resources) {
578
- // TODO(ATL-306): Remove readPidFile/getDaemonPidPath in favor of
579
- // fetching daemon PIDs via the health API (Gateway Security Migration).
580
- const pid = readPidFile(getDaemonPidPath(resources));
581
- const alive = pid !== null && isProcessAlive(pid);
582
- if (!alive) {
583
- health = { status: "sleeping", detail: null };
584
- } else {
585
- const token = loadGuardianToken(a.assistantId)?.accessToken;
586
- health = await checkHealth(a.localUrl ?? a.runtimeUrl, token);
587
- }
588
- } else if (a.cloud === "docker") {
589
- const res = dockerResourceNames(a.assistantId);
590
- const state = await getDockerContainerState(res.assistantContainer);
591
- if (!state || state !== "running") {
592
- health = { status: "sleeping", detail: null };
593
- } else {
594
- const token = loadGuardianToken(a.assistantId)?.accessToken;
595
- health = await checkHealth(a.localUrl ?? a.runtimeUrl, token);
596
- }
597
- } else if (a.cloud === "apple-container") {
598
- // Apple containers are managed by the macOS app. Probe the gateway
599
- // (runtimeUrl is always written to the lockfile during hatch).
600
- const token = loadGuardianToken(a.assistantId)?.accessToken;
601
- health = a.runtimeUrl
602
- ? await checkHealth(a.runtimeUrl, token)
603
- : { status: "unknown" as const, detail: "no runtime URL" };
604
- } else if (a.cloud === "vellum") {
605
- health = await checkManagedHealth(a.runtimeUrl, a.assistantId);
606
- } else {
607
- const token = loadGuardianToken(a.assistantId)?.accessToken;
608
- health = await checkHealth(a.localUrl ?? a.runtimeUrl, token);
609
- }
610
-
611
- const infoParts: string[] = [];
612
- if (a.runtimeUrl) infoParts.push(a.runtimeUrl);
613
- if (a.cloud) infoParts.push(`cloud: ${a.cloud}`);
614
- if (a.species) infoParts.push(`species: ${a.species}`);
615
- if (health.detail) infoParts.push(health.detail);
616
-
617
- const prefix = a.assistantId === activeId ? "* " : " ";
618
- const updatedRow: TableRow = {
619
- name: prefix + a.assistantId,
620
- status: withStatusEmoji(health.status),
621
- info: infoParts.join(" | "),
622
- };
623
-
624
- const linesUp = totalDataRows - rowIndex;
625
- process.stdout.write(
626
- `\x1b[${linesUp}A` +
627
- `\r\x1b[K` +
628
- formatRow(updatedRow, colWidths) +
629
- `\n` +
630
- (linesUp > 1 ? `\x1b[${linesUp - 1}B` : ""),
631
- );
632
- }),
624
+ const rows = await Promise.all(
625
+ assistants.map(async (entry) =>
626
+ formatAssistantListRow(
627
+ entry,
628
+ activeAssistantId,
629
+ await getAssistantListHealth(entry),
630
+ ),
631
+ ),
633
632
  );
633
+
634
+ printTable(rows, { name: "NAME", status: "STATUS", info: "INFO" });
634
635
  }
635
636
 
636
637
  // ── Entry point ─────────────────────────────────────────────────
@@ -638,14 +639,16 @@ export async function listAllAssistants(verbose: boolean): Promise<void> {
638
639
  export async function ps(): Promise<void> {
639
640
  const args = process.argv.slice(3);
640
641
  if (args.includes("--help") || args.includes("-h")) {
641
- console.log("Usage: vellum ps [<name>] [--verbose]");
642
+ console.log("Usage: vellum ps [<name-or-id>] [--verbose]");
642
643
  console.log("");
643
644
  console.log(
644
645
  "List all assistants, or show processes for a specific assistant.",
645
646
  );
646
647
  console.log("");
647
648
  console.log("Arguments:");
648
- console.log(" <name> Show processes for the named assistant");
649
+ console.log(
650
+ " <name-or-id> Show processes for the assistant display name or ID",
651
+ );
649
652
  console.log("");
650
653
  console.log("Options:");
651
654
  console.log(
@@ -655,19 +658,18 @@ export async function ps(): Promise<void> {
655
658
  }
656
659
 
657
660
  const verbose = args.includes("--verbose");
658
- const positional = args.filter((a) => !a.startsWith("--"));
659
- const assistantId = positional[0];
661
+ const assistantIdentifier = parseAssistantTargetArg(args);
660
662
 
661
- if (!assistantId) {
663
+ if (!assistantIdentifier) {
662
664
  await listAllAssistants(verbose);
663
665
  return;
664
666
  }
665
667
 
666
- const entry = findAssistantByName(assistantId);
667
- if (!entry) {
668
- console.error(`No assistant found with name '${assistantId}'.`);
668
+ const result = lookupAssistantByIdentifier(assistantIdentifier);
669
+ if (result.status !== "found") {
670
+ console.error(formatAssistantLookupError(assistantIdentifier, result));
669
671
  process.exit(1);
670
672
  }
671
673
 
672
- await showAssistantProcesses(entry);
674
+ await showAssistantProcesses(result.entry);
673
675
  }
@@ -1,5 +1,6 @@
1
1
  import { resolveAssistant } from "../lib/assistant-config.js";
2
2
  import {
3
+ leaseGuardianToken,
3
4
  loadGuardianToken,
4
5
  refreshGuardianToken,
5
6
  type GuardianTokenData,
@@ -41,6 +42,50 @@ function isGuardianAccessTokenUsable(
41
42
  return Number.isFinite(expiresAt) && expiresAt > Date.now();
42
43
  }
43
44
 
45
+ async function resolveSetupBearerToken(
46
+ entry: NonNullable<ReturnType<typeof resolveAssistant>>,
47
+ gatewayUrl: string,
48
+ ): Promise<string | undefined> {
49
+ const guardianToken = loadGuardianToken(entry.assistantId);
50
+ if (isGuardianAccessTokenUsable(guardianToken)) {
51
+ return guardianToken.accessToken;
52
+ }
53
+
54
+ if (guardianToken) {
55
+ const refreshedToken = await refreshGuardianToken(
56
+ gatewayUrl,
57
+ entry.assistantId,
58
+ );
59
+ if (isGuardianAccessTokenUsable(refreshedToken)) {
60
+ return refreshedToken.accessToken;
61
+ }
62
+ }
63
+
64
+ const canLeaseGuardianToken =
65
+ entry.cloud === "local" || entry.cloud === "docker" || entry.localUrl;
66
+ if (canLeaseGuardianToken) {
67
+ try {
68
+ const bootstrapSecret =
69
+ typeof entry.guardianBootstrapSecret === "string"
70
+ ? entry.guardianBootstrapSecret
71
+ : undefined;
72
+ const leasedToken = await leaseGuardianToken(
73
+ gatewayUrl,
74
+ entry.assistantId,
75
+ bootstrapSecret,
76
+ );
77
+ if (isGuardianAccessTokenUsable(leasedToken)) {
78
+ return leasedToken.accessToken;
79
+ }
80
+ } catch {
81
+ // Fall through to any lockfile bearer token, or let the setup request
82
+ // surface the gateway's auth error below.
83
+ }
84
+ }
85
+
86
+ return entry.bearerToken;
87
+ }
88
+
44
89
  export async function setup(): Promise<void> {
45
90
  const args = process.argv.slice(3);
46
91
 
@@ -85,18 +130,7 @@ export async function setup(): Promise<void> {
85
130
  }
86
131
 
87
132
  const gatewayUrl = entry.localUrl ?? entry.runtimeUrl;
88
- let bearerToken: string | undefined;
89
- const guardianToken = loadGuardianToken(entry.assistantId);
90
- if (isGuardianAccessTokenUsable(guardianToken)) {
91
- bearerToken = guardianToken.accessToken;
92
- } else {
93
- const refreshedToken = guardianToken
94
- ? await refreshGuardianToken(gatewayUrl, entry.assistantId)
95
- : null;
96
- bearerToken = isGuardianAccessTokenUsable(refreshedToken)
97
- ? refreshedToken.accessToken
98
- : entry.bearerToken;
99
- }
133
+ const bearerToken = await resolveSetupBearerToken(entry, gatewayUrl);
100
134
 
101
135
  console.log("Vellum Setup");
102
136
  console.log("============\n");