@vellumai/assistant 0.11.1-dev.202608042001.feb8dd6 → 0.11.1-dev.202608042034.3c87207

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,98 @@
1
+ /**
2
+ * Tests for reading an install layout: telling a repo checkout from an
3
+ * installed package, and locating the `assistant` command that ships with an
4
+ * install.
5
+ */
6
+
7
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
11
+
12
+ import { findAssistantCommand, isRepoCheckoutPath } from "../index.js";
13
+
14
+ let root: string;
15
+
16
+ beforeEach(() => {
17
+ root = mkdtempSync(join(tmpdir(), "install-layout-"));
18
+ });
19
+
20
+ afterEach(() => {
21
+ rmSync(root, { recursive: true, force: true });
22
+ });
23
+
24
+ /** Create `<nodeModulesDir>/.bin/assistant` and return its path. */
25
+ function seedCommand(nodeModulesDir: string): string {
26
+ const binDir = join(nodeModulesDir, ".bin");
27
+ mkdirSync(binDir, { recursive: true });
28
+ const command = join(binDir, "assistant");
29
+ writeFileSync(command, "#!/usr/bin/env bun\n");
30
+ return command;
31
+ }
32
+
33
+ describe("isRepoCheckoutPath", () => {
34
+ test("an installed package is not a checkout", () => {
35
+ expect(
36
+ isRepoCheckoutPath(
37
+ "/Users/x/Library/Application Support/@vellumai/macos/cli/latest/node_modules/@vellumai/assistant/src/index.ts",
38
+ ),
39
+ ).toBe(false);
40
+ });
41
+
42
+ test("a repo checkout is", () => {
43
+ expect(
44
+ isRepoCheckoutPath("/Users/x/dev/vellum/assistant/src/index.ts"),
45
+ ).toBe(true);
46
+ });
47
+
48
+ test("a directory merely named node_modules-ish is not enough", () => {
49
+ expect(
50
+ isRepoCheckoutPath("/Users/x/node_modules_backup/a/src/index.ts"),
51
+ ).toBe(true);
52
+ });
53
+ });
54
+
55
+ describe("findAssistantCommand", () => {
56
+ test("finds the command shipped beside an installed package", () => {
57
+ const nodeModules = join(root, "cli", "latest", "node_modules");
58
+ const command = seedCommand(nodeModules);
59
+ const path = join(nodeModules, "@vellumai", "assistant", "src", "index.ts");
60
+
61
+ expect(findAssistantCommand(path)).toBe(command);
62
+ });
63
+
64
+ test("prefers a nested install over a hoisted one", () => {
65
+ const outer = join(root, "node_modules");
66
+ const outerCommand = seedCommand(outer);
67
+ const inner = join(outer, "vellum", "node_modules");
68
+ const innerCommand = seedCommand(inner);
69
+ const path = join(inner, "@vellumai", "assistant", "src", "index.ts");
70
+
71
+ expect(findAssistantCommand(path)).toBe(innerCommand);
72
+ expect(innerCommand).not.toBe(outerCommand);
73
+ });
74
+
75
+ test("falls back to a hoisted install when the nested one has no command", () => {
76
+ const outer = join(root, "node_modules");
77
+ const outerCommand = seedCommand(outer);
78
+ const inner = join(outer, "vellum", "node_modules");
79
+ mkdirSync(inner, { recursive: true });
80
+ const path = join(inner, "@vellumai", "assistant", "src", "index.ts");
81
+
82
+ expect(findAssistantCommand(path)).toBe(outerCommand);
83
+ });
84
+
85
+ test("returns null for a repo checkout", () => {
86
+ expect(
87
+ findAssistantCommand(join(root, "assistant", "src", "index.ts")),
88
+ ).toBeNull();
89
+ });
90
+
91
+ test("returns null when the install ships no assistant command", () => {
92
+ const nodeModules = join(root, "node_modules");
93
+ mkdirSync(join(nodeModules, ".bin"), { recursive: true });
94
+ const path = join(nodeModules, "@vellumai", "assistant", "src", "index.ts");
95
+
96
+ expect(findAssistantCommand(path)).toBeNull();
97
+ });
98
+ });
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Package boundary tests for @vellumai/environments.
3
3
  *
4
- * This package is the lowest layer of the shared-packages hierarchy: pure
5
- * environment types and constants with no runtime dependencies. It must
6
- * stay a leaf so any consumer (CLI, assistant, local-mode host) can depend
7
- * on it without dragging in a dependency tree.
4
+ * This package is the lowest layer of the shared-packages hierarchy:
5
+ * environment types, constants, and small helpers over node builtins, with no
6
+ * runtime dependencies. It must stay a leaf so any consumer (CLI, assistant,
7
+ * local-mode host) can depend on it without dragging in a dependency tree.
8
8
  *
9
9
  * Enforces that the package:
10
10
  * 1. Imports only node builtins and its own relative modules — no `@vellumai/*`
@@ -79,7 +79,7 @@ describe("package boundary", () => {
79
79
  throw new Error(
80
80
  `Found ${violations.length} forbidden import(s) in @vellumai/environments:\n` +
81
81
  violations.map((v) => ` - ${v}`).join("\n") +
82
- "\n\n@vellumai/environments is a pure types/constants leaf and must\n" +
82
+ "\n\n@vellumai/environments is a dependency-free leaf and must\n" +
83
83
  "import only node builtins and its own relative modules.",
84
84
  );
85
85
  }
@@ -1,11 +1,22 @@
1
1
  /**
2
- * @vellumai/environments — the single source of truth for Vellum's known
3
- * deployment environments (names, platform/web URLs, per-service port
4
- * blocks). Consumed by the CLI, the assistant daemon, and the local-mode
5
- * host library so the environment list is defined exactly once on the TS
6
- * side. The Swift client mirrors the same set in `VellumEnvironment.swift`.
2
+ * @vellumai/environments: the single source of truth for how a Vellum install
3
+ * is laid out and which deployment environment it belongs to.
7
4
  *
8
- * Intentionally free of runtime dependencies: pure types and constants only.
5
+ * Two things live here:
6
+ *
7
+ * - The known deployment environments (names, platform/web URLs, per-service
8
+ * port blocks). The Swift client mirrors the same set in
9
+ * `VellumEnvironment.swift`.
10
+ * - Install layout: whether a runtime is a repo checkout or an installed
11
+ * package, and where the `assistant` command it ships lives.
12
+ *
13
+ * Consumed by the CLI, the assistant daemon, and the local-mode host library
14
+ * so each answer is defined exactly once on the TS side.
15
+ *
16
+ * This is the lowest layer of the shared-packages hierarchy and stays a leaf:
17
+ * types, constants, and small helpers over node builtins, with no runtime
18
+ * dependencies of its own. See `__tests__/package-boundary.test.ts`.
9
19
  */
10
20
  export * from "./types.js";
11
21
  export * from "./seeds.js";
22
+ export * from "./install-layout.js";
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Reading the layout a Vellum runtime is installed in.
3
+ *
4
+ * The daemon is started either from a developer's repo checkout or from an
5
+ * installed npm package (`<install>/node_modules/@vellumai/assistant/src/
6
+ * index.ts`, which is what the desktop app runs). The CLI needs the layout to
7
+ * decide whether a launch is a dev run and what to put on the daemon's PATH;
8
+ * the daemon needs it to decide what to install as the `assistant` command.
9
+ * Both ask the same two questions, so they ask them here.
10
+ */
11
+
12
+ import { existsSync } from "node:fs";
13
+ import { join, sep } from "node:path";
14
+
15
+ const NODE_MODULES_SEGMENT = `${sep}node_modules${sep}`;
16
+
17
+ /**
18
+ * Whether `path` sits in a developer's repo checkout rather than inside an
19
+ * installed package.
20
+ */
21
+ export function isRepoCheckoutPath(path: string): boolean {
22
+ return !path.includes(NODE_MODULES_SEGMENT);
23
+ }
24
+
25
+ /**
26
+ * The `assistant` command shipped with the install that contains `path`, or
27
+ * null when there is none (a repo checkout, or an install whose dependency
28
+ * graph omits the package declaring the bin).
29
+ *
30
+ * Searches innermost `node_modules` outward, since a nested install shadows a
31
+ * hoisted one.
32
+ */
33
+ export function findAssistantCommand(path: string): string | null {
34
+ let index = path.lastIndexOf(NODE_MODULES_SEGMENT);
35
+
36
+ while (index !== -1) {
37
+ const nodeModulesDir = path.slice(
38
+ 0,
39
+ index + NODE_MODULES_SEGMENT.length - 1,
40
+ );
41
+ const command = join(nodeModulesDir, ".bin", "assistant");
42
+ if (existsSync(command)) {
43
+ return command;
44
+ }
45
+ index = path.lastIndexOf(NODE_MODULES_SEGMENT, index - 1);
46
+ }
47
+
48
+ return null;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.1-dev.202608042001.feb8dd6",
3
+ "version": "0.11.1-dev.202608042034.3c87207",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -70,8 +70,12 @@ function buildMockContext(
70
70
  hostCuProxy?: InstanceType<typeof HostCuProxy>,
71
71
  trustGuardianPrincipalId: string | null = DEFAULT_PRINCIPAL,
72
72
  actorPrincipalId: string | null = trustGuardianPrincipalId,
73
+ // Mirrors `Conversation.ensureHostProxiesForTurn`: attaches a CU proxy when
74
+ // the gate passes. Left undefined to model a conversation that cannot
75
+ // attach one (the gate denies, or the context predates the hook).
76
+ ensureHostProxiesForTurn?: () => void,
73
77
  ): SurfaceConversationContext {
74
- return {
78
+ const ctx: SurfaceConversationContext = {
75
79
  conversationId: "test-session",
76
80
  trustContext:
77
81
  trustGuardianPrincipalId != null
@@ -100,12 +104,15 @@ function buildMockContext(
100
104
  surfaceActionRequestIds: new Set(),
101
105
  currentTurnSurfaces: [],
102
106
  hostCuProxy,
107
+ transportInterface: "web",
108
+ ensureHostProxiesForTurn,
103
109
  isProcessing: () => false,
104
110
  enqueueMessage: () => ({ queued: false, requestId: "r1" }),
105
111
  getQueueDepth: () => 0,
106
112
  processMessage: async () => "",
107
113
  withSurface: async (_id, fn) => fn(),
108
114
  };
115
+ return ctx;
109
116
  }
110
117
 
111
118
  // ---------------------------------------------------------------------------
@@ -137,21 +144,77 @@ describe("surfaceProxyResolver — CU tool routing", () => {
137
144
  // No desktop client connected
138
145
  // -------------------------------------------------------------------------
139
146
 
140
- describe("no desktop client connected", () => {
141
- test("returns error when hostCuProxy is undefined", async () => {
142
- const ctx = buildMockContext(/* no proxy */);
143
- const result = await surfaceProxyResolver(ctx, "computer_use_click", {
147
+ describe("attaching the proxy at tool-call time", () => {
148
+ test("attaches a proxy when the conversation has none and dispatches", async () => {
149
+ // The reported bug: `assistant clients list` showed the desktop
150
+ // connected and usable, while every computer_use_* call answered "no
151
+ // desktop client connected" — because attachment was decided at turn
152
+ // start, before the desktop was reachable, and never revisited.
153
+ sentMessages.length = 0;
154
+ mockHasClient = true;
155
+ mockCuClients = [
156
+ {
157
+ clientId: "mock-client-1",
158
+ capabilities: ["host_cu"],
159
+ actorPrincipalId: DEFAULT_PRINCIPAL,
160
+ },
161
+ ];
162
+
163
+ let attachCalls = 0;
164
+ const ctx: SurfaceConversationContext = buildMockContext(
165
+ /* no proxy */ undefined,
166
+ DEFAULT_PRINCIPAL,
167
+ DEFAULT_PRINCIPAL,
168
+ () => {
169
+ attachCalls++;
170
+ proxy = new HostCuProxy();
171
+ (ctx as { hostCuProxy?: unknown }).hostCuProxy = proxy;
172
+ },
173
+ );
174
+
175
+ const resultPromise = surfaceProxyResolver(ctx, "computer_use_click", {
144
176
  element_id: 42,
145
177
  reasoning: "click the button",
146
178
  });
147
179
 
180
+ expect(attachCalls).toBe(1);
181
+ expect(ctx.hostCuProxy).toBeDefined();
182
+ // Dispatched for real: the request reached the wire, not an error result.
183
+ expect(sentMessages).toHaveLength(1);
184
+ const sent = sentMessages[0] as { type?: string; requestId?: string };
185
+ expect(sent.type).toBe("host_cu_request");
186
+
187
+ proxy.processObservation(sent.requestId!, { axTree: "window Safari" });
188
+ const result = await resultPromise;
189
+ expect(result.isError).toBe(false);
190
+ });
191
+
192
+ test("reports the interface, not a missing desktop, when the gate still denies", async () => {
193
+ // The gate ran and refused (e.g. a chrome-extension source, or a
194
+ // desktop signed in as someone else). Saying "no desktop client
195
+ // connected" here contradicts a listing that plainly shows one.
196
+ mockCuClients = [
197
+ {
198
+ clientId: "mock-client-other",
199
+ capabilities: ["host_cu"],
200
+ actorPrincipalId: "someone-else",
201
+ },
202
+ ];
203
+ const ctx = buildMockContext(/* no proxy, no attach hook */);
204
+ const result = await surfaceProxyResolver(
205
+ ctx,
206
+ "computer_use_screenshot",
207
+ {},
208
+ );
209
+
148
210
  expect(result.isError).toBe(true);
149
- expect(result.content).toContain("not available");
150
- expect(result.content).toContain("no desktop client");
211
+ expect(result.content).toContain("not available for this conversation");
212
+ expect(result.content).not.toContain("no desktop client connected");
151
213
  });
152
214
 
153
- test("returns error for screenshot tool when no proxy", async () => {
154
- const ctx = buildMockContext();
215
+ test("reports no connected client when the hub has none", async () => {
216
+ mockCuClients = [];
217
+ const ctx = buildMockContext(/* no proxy */);
155
218
  const result = await surfaceProxyResolver(
156
219
  ctx,
157
220
  "computer_use_screenshot",
@@ -159,11 +222,12 @@ describe("surfaceProxyResolver — CU tool routing", () => {
159
222
  );
160
223
 
161
224
  expect(result.isError).toBe(true);
162
- expect(result.content).toContain("not available");
225
+ expect(result.content).toContain("no desktop client connected");
163
226
  });
164
227
 
165
228
  test("returns error when proxy exists but client not connected", async () => {
166
229
  mockHasClient = false;
230
+ mockCuClients = [];
167
231
  const proxyObj = new HostCuProxy();
168
232
  const ctx = buildMockContext(proxyObj);
169
233
  const result = await surfaceProxyResolver(ctx, "computer_use_click", {
@@ -171,7 +235,7 @@ describe("surfaceProxyResolver — CU tool routing", () => {
171
235
  });
172
236
 
173
237
  expect(result.isError).toBe(true);
174
- expect(result.content).toContain("not available");
238
+ expect(result.content).toContain("no desktop client connected");
175
239
  proxyObj.dispose();
176
240
  });
177
241
 
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Guard against deriving a filesystem path from a `file:` URL's `.pathname`.
3
+ *
4
+ * `URL.pathname` is percent-encoded, so any path segment containing a space
5
+ * survives as `%20` and every downstream `existsSync` / spawn against it
6
+ * fails. This is not theoretical: macOS desktop installs live under
7
+ * `~/Library/Application Support/…`, so the encoded form broke every
8
+ * background worker spawn on that platform. `fileURLToPath()` decodes.
9
+ *
10
+ * Two shapes are checked:
11
+ * 1. `.pathname` read off a URL built from `import.meta.url`.
12
+ * 2. `.pathname` passed inside a `cmd: [...]` spawn array, the sink that
13
+ * turns an encoded path into a "Module not found" at runtime.
14
+ */
15
+
16
+ import { readdirSync, readFileSync } from "node:fs";
17
+ import { join, relative } from "node:path";
18
+ import { describe, expect, test } from "bun:test";
19
+
20
+ const SRC_DIR = join(import.meta.dir, "..");
21
+
22
+ /** This guard's own file, which necessarily contains the forbidden patterns. */
23
+ const SELF = "__tests__/file-url-path-guard.test.ts";
24
+
25
+ /** `.pathname` read off a URL derived from `import.meta.url`. */
26
+ const IMPORT_META_URL_PATHNAME =
27
+ /import\.meta\.url[\s\S]{0,80}?\)\s*\.pathname/;
28
+
29
+ /** A `cmd: [...]` spawn array (bounded so it can't run away over a file). */
30
+ const SPAWN_CMD_ARRAY = /cmd:\s*\[[\s\S]{0,300}?\]/g;
31
+
32
+ function collectSourceFiles(rootDir: string): string[] {
33
+ const pending = [rootDir];
34
+ const files: string[] = [];
35
+
36
+ while (pending.length > 0) {
37
+ const current = pending.pop();
38
+ if (!current) {
39
+ continue;
40
+ }
41
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
42
+ const fullPath = join(current, entry.name);
43
+ if (entry.isDirectory()) {
44
+ if (entry.name !== "node_modules") {
45
+ pending.push(fullPath);
46
+ }
47
+ continue;
48
+ }
49
+ if (entry.isFile() && /\.tsx?$/.test(entry.name)) {
50
+ files.push(fullPath);
51
+ }
52
+ }
53
+ }
54
+
55
+ return files;
56
+ }
57
+
58
+ function offenders(predicate: (source: string) => boolean): string[] {
59
+ return collectSourceFiles(SRC_DIR)
60
+ .map((path) => ({ path, rel: relative(SRC_DIR, path) }))
61
+ .filter(({ rel }) => rel !== SELF)
62
+ .filter(({ path }) => predicate(readFileSync(path, "utf-8")))
63
+ .map(({ rel }) => rel)
64
+ .sort();
65
+ }
66
+
67
+ describe("file URL → path guard", () => {
68
+ test("no path is derived from import.meta.url via .pathname", () => {
69
+ expect(
70
+ offenders((source) => IMPORT_META_URL_PATHNAME.test(source)),
71
+ ).toEqual([]);
72
+ });
73
+
74
+ test("no .pathname is passed as a spawn argument", () => {
75
+ expect(
76
+ offenders((source) =>
77
+ [...source.matchAll(SPAWN_CMD_ARRAY)].some((match) =>
78
+ match[0].includes(".pathname"),
79
+ ),
80
+ ),
81
+ ).toEqual([]);
82
+ });
83
+ });
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import * as nodeFs from "node:fs";
15
+ import { fileURLToPath } from "node:url";
15
16
  import { beforeEach, describe, expect, mock, test } from "bun:test";
16
17
 
17
18
  import { Command } from "commander";
@@ -415,8 +416,9 @@ describe("cache set --value", () => {
415
416
  describe("cache set --file", () => {
416
417
  test("reads JSON from a file", async () => {
417
418
  mockIpcResult = { ok: true, result: { key: "file-key" } };
418
- const pkgPath = new URL("../../../../package.json", import.meta.url)
419
- .pathname;
419
+ const pkgPath = fileURLToPath(
420
+ new URL("../../../../package.json", import.meta.url),
421
+ );
420
422
 
421
423
  const { exitCode } = await runCommand(["cache", "set", "--file", pkgPath]);
422
424
 
@@ -442,8 +444,9 @@ describe("cache set --file", () => {
442
444
  test("works in TTY mode (no stdin required)", async () => {
443
445
  mockStdinIsTTY = true;
444
446
  mockIpcResult = { ok: true, result: { key: "file-tty-key" } };
445
- const pkgPath = new URL("../../../../package.json", import.meta.url)
446
- .pathname;
447
+ const pkgPath = fileURLToPath(
448
+ new URL("../../../../package.json", import.meta.url),
449
+ );
447
450
 
448
451
  const { exitCode } = await runCommand(["cache", "set", "--file", pkgPath]);
449
452
 
@@ -67,7 +67,7 @@ Semantic tokens flip automatically between light and dark. Use them for every su
67
67
  - Surfaces: --surface-base (page), --surface-lift (card), --surface-overlay, --surface-sunken (recessed tile), --surface-hover, --surface-active.
68
68
  - Text, strongest to faintest: --content-emphasised, --content-strong, --content-default (body), --content-secondary (labels and any text under 14px), --content-tertiary (14px and up only), --content-quiet, --content-faint, --content-disabled, --content-inset (on inverted fills). Text at 11 to 13px always takes --content-secondary or stronger.
69
69
  - Borders: --border-base (hairline), --border-subtle, --border-element (visible control edge), --border-hover, --border-active, --border-disabled.
70
- - Status pairs: --system-positive-strong/-weak, --system-negative-strong/-weak (and --system-negative-hover), --system-mid-strong/-weak, --system-info-strong/-weak.
70
+ - Status pairs: --system-positive-strong/-weak, --system-negative-strong/-weak (and --system-negative-hover), --system-mid-strong/-weak, --system-info-strong/-weak. A non-text glyph sitting on its own -weak fill takes --system-positive-on-weak or --system-negative-on-weak; those clear the 3:1 that non-text indicators need, which --system-negative-strong misses on --system-negative-weak in the dark theme. Text on a -weak fill needs 4.5:1 and takes --content-default or stronger; --content-tertiary misses that on both fills in the light and dark themes, and --content-secondary misses it on the negative fill in light.
71
71
  - Type: --font-sans (default), --font-mono (identifiers, code, tabular numbers only), --font-serif (editorial pull-quotes only).
72
72
  - Radius: --radius-xs 2, --radius-sm 4, --radius-md 8, --radius-lg 12, --radius-xl 16, --radius-xxl 20, --radius-pill 999.
73
73