@vellumai/cli 0.8.3 → 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.
@@ -0,0 +1,144 @@
1
+ import {
2
+ afterAll,
3
+ afterEach,
4
+ beforeEach,
5
+ describe,
6
+ expect,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
10
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+
14
+ import {
15
+ getActiveAssistant,
16
+ type AssistantEntry,
17
+ } from "../lib/assistant-config.js";
18
+ import { use } from "../commands/use.js";
19
+
20
+ const testDir = mkdtempSync(join(tmpdir(), "cli-use-test-"));
21
+ const originalArgv = [...process.argv];
22
+ const originalExit = process.exit;
23
+ const originalLockfileDir = process.env.VELLUM_LOCKFILE_DIR;
24
+
25
+ let consoleLogSpy: ReturnType<typeof spyOn>;
26
+ let consoleErrorSpy: ReturnType<typeof spyOn>;
27
+
28
+ function makeEntry(
29
+ assistantId: string,
30
+ extra: Partial<AssistantEntry> = {},
31
+ ): AssistantEntry {
32
+ return {
33
+ assistantId,
34
+ runtimeUrl: `http://localhost:${7800 + assistantId.length}`,
35
+ cloud: "local",
36
+ ...extra,
37
+ };
38
+ }
39
+
40
+ function writeLockfile(
41
+ entries: AssistantEntry[],
42
+ activeAssistant?: string,
43
+ ): void {
44
+ mkdirSync(testDir, { recursive: true });
45
+ writeFileSync(
46
+ join(testDir, ".vellum.lock.json"),
47
+ JSON.stringify(
48
+ {
49
+ assistants: entries,
50
+ ...(activeAssistant ? { activeAssistant } : {}),
51
+ },
52
+ null,
53
+ 2,
54
+ ),
55
+ );
56
+ }
57
+
58
+ describe("vellum use", () => {
59
+ beforeEach(() => {
60
+ process.env.VELLUM_LOCKFILE_DIR = testDir;
61
+ rmSync(join(testDir, ".vellum.lock.json"), { force: true });
62
+ process.argv = ["bun", "vellum", "use"];
63
+ process.exit = ((code?: number) => {
64
+ throw new Error(`process.exit:${code}`);
65
+ }) as typeof process.exit;
66
+ consoleLogSpy = spyOn(console, "log").mockImplementation(() => {});
67
+ consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {});
68
+ });
69
+
70
+ afterEach(() => {
71
+ process.argv = originalArgv;
72
+ process.exit = originalExit;
73
+ consoleLogSpy.mockRestore();
74
+ consoleErrorSpy.mockRestore();
75
+ });
76
+
77
+ afterAll(() => {
78
+ if (originalLockfileDir === undefined) {
79
+ delete process.env.VELLUM_LOCKFILE_DIR;
80
+ } else {
81
+ process.env.VELLUM_LOCKFILE_DIR = originalLockfileDir;
82
+ }
83
+ rmSync(testDir, { recursive: true, force: true });
84
+ });
85
+
86
+ test("sets active assistant by unique display name", async () => {
87
+ writeLockfile([
88
+ makeEntry("assistant-1", { name: "Alice" }),
89
+ makeEntry("assistant-2", { name: "Bob" }),
90
+ ]);
91
+ process.argv = ["bun", "vellum", "use", "Alice"];
92
+
93
+ await use();
94
+
95
+ expect(getActiveAssistant()).toBe("assistant-1");
96
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
97
+ "Active assistant set to Alice (assistant-1).",
98
+ );
99
+ });
100
+
101
+ test("sets active assistant by unquoted multi-word display name", async () => {
102
+ writeLockfile([
103
+ makeEntry("assistant-1", { name: "Example Assistant" }),
104
+ makeEntry("assistant-2", { name: "Bob" }),
105
+ ]);
106
+ process.argv = ["bun", "vellum", "use", "Example", "Assistant"];
107
+
108
+ await use();
109
+
110
+ expect(getActiveAssistant()).toBe("assistant-1");
111
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
112
+ "Active assistant set to Example Assistant (assistant-1).",
113
+ );
114
+ });
115
+
116
+ test("prints active assistant with display name and id", async () => {
117
+ writeLockfile([makeEntry("assistant-1", { name: "Alice" })], "assistant-1");
118
+
119
+ await use();
120
+
121
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
122
+ "Active assistant: Alice (assistant-1)",
123
+ );
124
+ });
125
+
126
+ test("rejects ambiguous display names without changing active assistant", async () => {
127
+ writeLockfile(
128
+ [
129
+ makeEntry("assistant-1", { name: "Alice" }),
130
+ makeEntry("assistant-2", { name: "Alice" }),
131
+ ],
132
+ "assistant-2",
133
+ );
134
+ process.argv = ["bun", "vellum", "use", "Alice"];
135
+
136
+ await expect(use()).rejects.toThrow("process.exit:1");
137
+
138
+ expect(getActiveAssistant()).toBe("assistant-2");
139
+ const output = consoleErrorSpy.mock.calls.flat().join("\n");
140
+ expect(output).toContain("Multiple assistants match 'Alice'");
141
+ expect(output).toContain("assistant-1");
142
+ expect(output).toContain("assistant-2");
143
+ });
144
+ });
@@ -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
  }
@@ -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,19 +1,24 @@
1
1
  import {
2
- findAssistantByName,
2
+ formatAssistantLookupError,
3
+ formatAssistantReference,
3
4
  getActiveAssistant,
5
+ lookupAssistantByIdentifier,
4
6
  setActiveAssistant,
5
7
  } from "../lib/assistant-config.js";
8
+ import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
6
9
 
7
10
  export async function use(): Promise<void> {
8
11
  const args = process.argv.slice(3);
9
12
 
10
13
  if (args.includes("--help") || args.includes("-h")) {
11
- console.log("Usage: vellum use [<name>]");
14
+ console.log("Usage: vellum use [<name-or-id>]");
12
15
  console.log("");
13
16
  console.log("Set the active assistant for commands.");
14
17
  console.log("");
15
18
  console.log("Arguments:");
16
- console.log(" <name> Name of the assistant to make active");
19
+ console.log(
20
+ " <name-or-id> Assistant display name or ID to make active",
21
+ );
17
22
  console.log("");
18
23
  console.log(
19
24
  "When called without a name, prints the current active assistant.",
@@ -21,24 +26,33 @@ export async function use(): Promise<void> {
21
26
  process.exit(0);
22
27
  }
23
28
 
24
- const name = args.find((a) => !a.startsWith("-"));
29
+ const name = parseAssistantTargetArg(args);
25
30
 
26
31
  if (!name) {
27
32
  const active = getActiveAssistant();
28
33
  if (active) {
29
- console.log(`Active assistant: ${active}`);
34
+ const result = lookupAssistantByIdentifier(active);
35
+ if (result.status === "found") {
36
+ console.log(
37
+ `Active assistant: ${formatAssistantReference(result.entry)}`,
38
+ );
39
+ } else {
40
+ console.log(`Active assistant: ${active} (not found in lockfile)`);
41
+ }
30
42
  } else {
31
43
  console.log("No active assistant set.");
32
44
  }
33
45
  return;
34
46
  }
35
47
 
36
- const entry = findAssistantByName(name);
37
- if (!entry) {
38
- console.error(`No assistant found with name '${name}'.`);
48
+ const result = lookupAssistantByIdentifier(name);
49
+ if (result.status !== "found") {
50
+ console.error(formatAssistantLookupError(name, result));
39
51
  process.exit(1);
40
52
  }
41
53
 
42
- setActiveAssistant(name);
43
- console.log(`Active assistant set to '${name}'.`);
54
+ setActiveAssistant(result.entry.assistantId);
55
+ console.log(
56
+ `Active assistant set to ${formatAssistantReference(result.entry)}.`,
57
+ );
44
58
  }