@vellumai/cli 0.6.3 → 0.6.5

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 (56) hide show
  1. package/AGENTS.md +12 -2
  2. package/README.md +3 -3
  3. package/bun.lock +17 -17
  4. package/bunfig.toml +6 -0
  5. package/package.json +18 -18
  6. package/src/__tests__/assistant-config.test.ts +124 -0
  7. package/src/__tests__/env-drift.test.ts +87 -0
  8. package/src/__tests__/guardian-token.test.ts +225 -0
  9. package/src/__tests__/llm-provider-env-var-parity.test.ts +64 -0
  10. package/src/__tests__/multi-local.test.ts +90 -13
  11. package/src/__tests__/orphan-detection.test.ts +214 -0
  12. package/src/__tests__/platform-client.test.ts +204 -0
  13. package/src/__tests__/preload.ts +27 -0
  14. package/src/__tests__/ssh-user-guard.test.ts +28 -0
  15. package/src/__tests__/teleport.test.ts +1073 -56
  16. package/src/commands/backup.ts +8 -0
  17. package/src/commands/exec.ts +186 -0
  18. package/src/commands/hatch.ts +1 -1
  19. package/src/commands/login.ts +209 -9
  20. package/src/commands/logs.ts +652 -0
  21. package/src/commands/pair.ts +9 -1
  22. package/src/commands/ps.ts +37 -7
  23. package/src/commands/recover.ts +8 -4
  24. package/src/commands/restore.ts +8 -0
  25. package/src/commands/retire.ts +16 -9
  26. package/src/commands/rollback.ts +32 -33
  27. package/src/commands/ssh.ts +7 -0
  28. package/src/commands/teleport.ts +253 -1
  29. package/src/commands/upgrade.ts +43 -52
  30. package/src/commands/wake.ts +25 -10
  31. package/src/components/DefaultMainScreen.tsx +7 -1
  32. package/src/index.ts +6 -0
  33. package/src/lib/__tests__/docker.test.ts +168 -0
  34. package/src/lib/assistant-config.ts +82 -108
  35. package/src/lib/aws.ts +12 -1
  36. package/src/lib/config-utils.ts +4 -4
  37. package/src/lib/constants.ts +0 -10
  38. package/src/lib/docker.ts +158 -8
  39. package/src/lib/environments/__tests__/paths.test.ts +228 -0
  40. package/src/lib/environments/__tests__/resolve.test.ts +226 -0
  41. package/src/lib/environments/__tests__/seeds.test.ts +72 -0
  42. package/src/lib/environments/paths.ts +109 -0
  43. package/src/lib/environments/resolve.ts +96 -0
  44. package/src/lib/environments/seeds.ts +74 -0
  45. package/src/lib/environments/types.ts +60 -0
  46. package/src/lib/exec-apple-container.ts +122 -0
  47. package/src/lib/gcp.ts +12 -1
  48. package/src/lib/guardian-token.ts +71 -10
  49. package/src/lib/hatch-local.ts +44 -23
  50. package/src/lib/local.ts +47 -5
  51. package/src/lib/orphan-detection.ts +28 -12
  52. package/src/lib/platform-client.ts +354 -24
  53. package/src/lib/retire-apple-container.ts +102 -0
  54. package/src/lib/ssh-apple-container.ts +166 -0
  55. package/src/lib/upgrade-lifecycle.ts +101 -28
  56. package/src/shared/provider-env-vars.ts +30 -6
@@ -125,6 +125,72 @@ export async function captureContainerEnv(
125
125
  return captured;
126
126
  }
127
127
 
128
+ /**
129
+ * Best-effort fetch of the running service group version from the gateway
130
+ * `/healthz` endpoint. Returns `undefined` when the endpoint is
131
+ * unreachable or does not include a version field.
132
+ */
133
+ export async function fetchCurrentVersion(
134
+ runtimeUrl: string,
135
+ ): Promise<string | undefined> {
136
+ try {
137
+ const resp = await fetch(`${runtimeUrl}/healthz`, {
138
+ signal: AbortSignal.timeout(5000),
139
+ });
140
+ if (resp.ok) {
141
+ const body = (await resp.json()) as { version?: string };
142
+ return body.version;
143
+ }
144
+ } catch {
145
+ // Best-effort
146
+ }
147
+ return undefined;
148
+ }
149
+
150
+ /**
151
+ * Determine the version that was running before the current one.
152
+ *
153
+ * Checks (in order):
154
+ * 1. `entry.previousVersion` (saved by the upgrade flow from health).
155
+ * 2. The releases list from the platform API — finds the version
156
+ * immediately before `currentVersion`.
157
+ *
158
+ * Returns `undefined` when neither source yields a result.
159
+ */
160
+ export async function fetchPreviousVersion(
161
+ currentVersion: string | undefined,
162
+ previousVersionFromLockfile: string | undefined,
163
+ ): Promise<string | undefined> {
164
+ // 1. Lockfile-cached value (written during upgrade from health endpoint)
165
+ if (previousVersionFromLockfile) return previousVersionFromLockfile;
166
+
167
+ // 2. Derive from releases list
168
+ if (!currentVersion) return undefined;
169
+ try {
170
+ const { getPlatformUrl } = await import("./platform-client.js");
171
+ const platformUrl = getPlatformUrl();
172
+ const resp = await fetch(`${platformUrl}/v1/releases/?stable=true`, {
173
+ signal: AbortSignal.timeout(10_000),
174
+ });
175
+ if (!resp.ok) return undefined;
176
+
177
+ const releases = (await resp.json()) as Array<{ version?: string }>;
178
+ const normalizedCurrent = currentVersion.replace(/^v/, "");
179
+
180
+ // Releases are ordered newest-first; find the entry right after the
181
+ // current version (i.e. the one that was running before the upgrade).
182
+ const idx = releases.findIndex(
183
+ (r) => (r.version ?? "").replace(/^v/, "") === normalizedCurrent,
184
+ );
185
+ if (idx >= 0 && idx + 1 < releases.length) {
186
+ return releases[idx + 1].version;
187
+ }
188
+ } catch {
189
+ // Best-effort
190
+ }
191
+ return undefined;
192
+ }
193
+
128
194
  /**
129
195
  * Poll the gateway `/readyz` endpoint until it returns 200 or the timeout
130
196
  * elapses. Returns whether the assistant became ready.
@@ -314,27 +380,8 @@ export async function performDockerRollback(
314
380
  throw new Error("targetVersion is required for performDockerRollback");
315
381
  }
316
382
 
317
- const currentVersion = entry.serviceGroupVersion;
318
-
319
- // Validate target version < current version
320
- if (currentVersion) {
321
- const cmp = compareVersions(targetVersion, currentVersion);
322
- if (cmp !== null) {
323
- if (cmp > 0) {
324
- const msg =
325
- "Cannot roll back to a newer version. Use `vellum upgrade` instead.";
326
- console.error(msg);
327
- emitCliError("VERSION_DIRECTION", msg);
328
- process.exit(1);
329
- }
330
- if (cmp === 0) {
331
- const msg = `Already on version ${targetVersion}. Nothing to roll back to.`;
332
- console.error(msg);
333
- emitCliError("VERSION_DIRECTION", msg);
334
- process.exit(1);
335
- }
336
- }
337
- }
383
+ // Fetch the current running version from the health endpoint.
384
+ let currentVersion: string | undefined;
338
385
 
339
386
  const instanceName = entry.assistantId;
340
387
  const res = dockerResourceNames(instanceName);
@@ -383,7 +430,7 @@ export async function performDockerRollback(
383
430
  console.log("📸 Capturing current image references for rollback...");
384
431
  const currentImageRefs = await captureImageRefs(res);
385
432
 
386
- // Capture current migration state for rollback targeting
433
+ // Capture current migration state and running version for rollback targeting
387
434
  let preMigrationState: {
388
435
  dbVersion?: number;
389
436
  lastWorkspaceMigrationId?: string;
@@ -395,25 +442,54 @@ export async function performDockerRollback(
395
442
  );
396
443
  if (healthResp.ok) {
397
444
  const health = (await healthResp.json()) as {
445
+ version?: string;
398
446
  migrations?: { dbVersion?: number; lastWorkspaceMigrationId?: string };
399
447
  };
400
448
  preMigrationState = health.migrations ?? {};
449
+ currentVersion = health.version;
401
450
  }
402
451
  } catch {
403
452
  // Best-effort
404
453
  }
405
454
 
455
+ // Validate target version < current version
456
+ if (!currentVersion) {
457
+ console.warn(
458
+ "⚠️ Could not determine current version from health endpoint — skipping version-direction check.\n",
459
+ );
460
+ }
461
+ if (currentVersion) {
462
+ const cmp = compareVersions(targetVersion, currentVersion);
463
+ if (cmp !== null) {
464
+ if (cmp > 0) {
465
+ const msg =
466
+ "Cannot roll back to a newer version. Use `vellum upgrade` instead.";
467
+ console.error(msg);
468
+ emitCliError("VERSION_DIRECTION", msg);
469
+ process.exit(1);
470
+ }
471
+ if (cmp === 0) {
472
+ const msg = `Already on version ${targetVersion}. Nothing to roll back to.`;
473
+ console.error(msg);
474
+ emitCliError("VERSION_DIRECTION", msg);
475
+ process.exit(1);
476
+ }
477
+ }
478
+ }
479
+
406
480
  // Persist rollback state to lockfile BEFORE any destructive changes
407
- if (entry.serviceGroupVersion && entry.containerInfo) {
481
+ if (entry.containerInfo) {
408
482
  const rollbackEntry: AssistantEntry = {
409
483
  ...entry,
410
- previousServiceGroupVersion: entry.serviceGroupVersion,
411
484
  previousContainerInfo: { ...entry.containerInfo },
485
+ previousVersion: currentVersion,
412
486
  previousDbMigrationVersion: preMigrationState.dbVersion,
413
487
  previousWorkspaceMigrationId: preMigrationState.lastWorkspaceMigrationId,
414
488
  };
415
489
  saveAssistantEntry(rollbackEntry);
416
- console.log(` Saved rollback state: ${entry.serviceGroupVersion}\n`);
490
+ if (currentVersion) {
491
+ console.log(` Saved rollback state: ${currentVersion}\n`);
492
+ }
417
493
  }
418
494
 
419
495
  // Record rollback start in workspace git history
@@ -613,7 +689,6 @@ export async function performDockerRollback(
613
689
  // Swap current/previous state to enable "rollback the rollback"
614
690
  const updatedEntry: AssistantEntry = {
615
691
  ...entry,
616
- serviceGroupVersion: targetVersion,
617
692
  containerInfo: {
618
693
  assistantImage: targetImageTags.assistant,
619
694
  gatewayImage: targetImageTags.gateway,
@@ -623,7 +698,6 @@ export async function performDockerRollback(
623
698
  cesDigest: newDigests?.["credential-executor"],
624
699
  networkName: res.network,
625
700
  },
626
- previousServiceGroupVersion: entry.serviceGroupVersion,
627
701
  previousContainerInfo: entry.containerInfo,
628
702
  previousDbMigrationVersion: preMigrationState.dbVersion,
629
703
  previousWorkspaceMigrationId: preMigrationState.lastWorkspaceMigrationId,
@@ -749,7 +823,6 @@ export async function performDockerRollback(
749
823
  currentImageRefs["credential-executor"],
750
824
  networkName: res.network,
751
825
  },
752
- previousServiceGroupVersion: undefined,
753
826
  previousContainerInfo: undefined,
754
827
  previousDbMigrationVersion: undefined,
755
828
  previousWorkspaceMigrationId: undefined,
@@ -1,19 +1,43 @@
1
1
  /**
2
2
  * Provider API key environment variable names, keyed by provider ID.
3
3
  *
4
- * Keep in sync with:
5
- * - assistant/src/shared/provider-env-vars.ts
6
- * - meta/provider-env-vars.json (consumed by the macOS client build)
4
+ * Two sources are merged into a single combined map:
7
5
  *
8
- * Once a consolidated shared package exists in packages/, all three
9
- * copies can be replaced by a single import.
6
+ * 1. Search-provider env vars sourced from `meta/provider-env-vars.json`
7
+ * (single source of truth, also bundled into the macOS client).
8
+ * 2. LLM-provider env vars — sourced from `PROVIDER_CATALOG` in
9
+ * `assistant/src/providers/model-catalog.ts` via a locally-maintained
10
+ * mirror (the CLI does not import from `assistant/src/`; drift is caught
11
+ * by `cli/src/__tests__/llm-provider-env-var-parity.test.ts`).
12
+ *
13
+ * The combined map is what cloud-infra code (docker.ts, aws.ts, gcp.ts)
14
+ * iterates to forward provider API keys from the caller's environment into
15
+ * containers / VMs. Keeping both kinds of provider env vars in one map means
16
+ * the infra call sites don't need to know which kind is which — they just
17
+ * forward every value whose env var is set.
10
18
  */
11
- export const PROVIDER_ENV_VAR_NAMES: Record<string, string> = {
19
+
20
+ /** LLM provider env var names. Mirrors `PROVIDER_CATALOG` entries with an `envVar`. */
21
+ export const LLM_PROVIDER_ENV_VAR_NAMES: Record<string, string> = {
12
22
  anthropic: "ANTHROPIC_API_KEY",
13
23
  openai: "OPENAI_API_KEY",
14
24
  gemini: "GEMINI_API_KEY",
15
25
  fireworks: "FIREWORKS_API_KEY",
16
26
  openrouter: "OPENROUTER_API_KEY",
27
+ };
28
+
29
+ /** Search-provider env var names. Mirrors `meta/provider-env-vars.json`. */
30
+ export const SEARCH_PROVIDER_ENV_VAR_NAMES: Record<string, string> = {
17
31
  brave: "BRAVE_API_KEY",
18
32
  perplexity: "PERPLEXITY_API_KEY",
19
33
  };
34
+
35
+ /**
36
+ * Combined provider env var names — the union of LLM and search providers.
37
+ * Used by the cloud-infra flows (docker/aws/gcp) to forward every supported
38
+ * provider API key from the caller's environment.
39
+ */
40
+ export const PROVIDER_ENV_VAR_NAMES: Record<string, string> = {
41
+ ...LLM_PROVIDER_ENV_VAR_NAMES,
42
+ ...SEARCH_PROVIDER_ENV_VAR_NAMES,
43
+ };