@vellumai/assistant 0.11.9-dev.202609061013.dcf82c1 → 0.11.9-dev.202609061357.22f66f9

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 (27) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/assistant-event-hub-machine-name.test.ts +40 -0
  3. package/src/__tests__/assistant-event-hub.test.ts +45 -0
  4. package/src/__tests__/computer-use-native-history.test.ts +30 -0
  5. package/src/__tests__/computer-use-window-schema.test.ts +24 -0
  6. package/src/__tests__/host-cu-proxy.test.ts +159 -1
  7. package/src/channels/types.ts +5 -0
  8. package/src/config/bundled-skills/computer-use/SKILL.md +21 -0
  9. package/src/config/bundled-skills/computer-use/TOOLS.json +6 -0
  10. package/src/daemon/host-cu-proxy.ts +58 -6
  11. package/src/persistence/embeddings/embedding-gemini.test.ts +328 -9
  12. package/src/persistence/embeddings/embedding-gemini.ts +211 -27
  13. package/src/plugins/defaults/memory/job-handlers.ts +4 -1
  14. package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +66 -0
  15. package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +170 -1
  16. package/src/plugins/defaults/memory/substrate/consolidation-job.ts +40 -1
  17. package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +117 -6
  18. package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +99 -2
  19. package/src/plugins/defaults/memory/v3/__tests__/overlong-sections.test.ts +109 -0
  20. package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +54 -0
  21. package/src/plugins/defaults/memory/v3/maintain-job.ts +52 -0
  22. package/src/plugins/defaults/memory/v3/overlong-sections.ts +83 -0
  23. package/src/plugins/defaults/memory/v3/section-dense-store.ts +30 -0
  24. package/src/plugins/defaults/memory/v3/sections.ts +10 -2
  25. package/src/runtime/assistant-event-hub.ts +7 -1
  26. package/src/runtime/routes/events-routes.ts +9 -3
  27. package/src/tools/computer-use/definitions.ts +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.9-dev.202609061013.dcf82c1",
3
+ "version": "0.11.9-dev.202609061357.22f66f9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -124,3 +124,43 @@ describe("AssistantEventHub — machineName", () => {
124
124
  expect(entry?.machineName).toBeUndefined();
125
125
  });
126
126
  });
127
+
128
+ describe("window capture negotiation", () => {
129
+ test.each([
130
+ ["macos", undefined, false],
131
+ ["macos", "0", false],
132
+ ["macos", "unknown", false],
133
+ ["macos", "1", true],
134
+ ["windows", "1", false],
135
+ ["linux", "1", false],
136
+ ["chrome-extension", "1", false],
137
+ ] as const)(
138
+ "%s advertising %s negotiates support=%s",
139
+ (interfaceId, advertised, supported) => {
140
+ const ac = new AbortController();
141
+ const hub = new AssistantEventHub();
142
+ try {
143
+ handleSubscribeAssistantEvents(
144
+ {
145
+ headers: {
146
+ "x-vellum-client-id": "client-1",
147
+ "x-vellum-interface-id": interfaceId,
148
+ ...(advertised
149
+ ? { "x-vellum-cu-window-capture": advertised }
150
+ : {}),
151
+ },
152
+ abortSignal: ac.signal,
153
+ },
154
+ { hub },
155
+ );
156
+ expect(
157
+ hub
158
+ .getClientById("client-1")
159
+ ?.capabilities.includes("host_cu_window_capture"),
160
+ ).toBe(supported);
161
+ } finally {
162
+ ac.abort();
163
+ }
164
+ },
165
+ );
166
+ });
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, test } from "bun:test";
3
3
  import type { AssistantEventEnvelope } from "../api/index.js";
4
4
  import {
5
5
  AssistantEventHub,
6
+ assistantEventHub,
6
7
  broadcastMessage,
7
8
  capabilityForMessageType,
8
9
  } from "../runtime/assistant-event-hub.js";
@@ -645,3 +646,47 @@ describe("broadcastMessage — replay ring", () => {
645
646
  ]);
646
647
  });
647
648
  });
649
+
650
+ test("window requests never reach an older overlapping connection with the same device ID", async () => {
651
+ const receivedLegacy: unknown[] = [];
652
+ const receivedSupported: unknown[] = [];
653
+ const legacy = assistantEventHub.subscribe({
654
+ type: "client",
655
+ clientId: "window-client",
656
+ interfaceId: "macos",
657
+ capabilities: ["host_cu"],
658
+ callback: (event) => {
659
+ receivedLegacy.push(event);
660
+ },
661
+ });
662
+ const supported = assistantEventHub.subscribe({
663
+ type: "client",
664
+ clientId: "window-client",
665
+ interfaceId: "macos",
666
+ capabilities: ["host_cu", "host_cu_window_capture"],
667
+ callback: (event) => {
668
+ receivedSupported.push(event);
669
+ },
670
+ });
671
+ try {
672
+ broadcastMessage(
673
+ {
674
+ type: "host_cu_request",
675
+ requestId: "window-request",
676
+ conversationId: "window-session",
677
+ toolName: "computer_use_observe",
678
+ input: { capture_window_id: 12 },
679
+ stepNumber: 1,
680
+ targetClientId: "window-client",
681
+ },
682
+ "window-session",
683
+ { targetClientId: "window-client" },
684
+ );
685
+ await new Promise((resolve) => setTimeout(resolve, 0));
686
+ expect(receivedLegacy).toHaveLength(0);
687
+ expect(receivedSupported).toHaveLength(1);
688
+ } finally {
689
+ legacy.dispose();
690
+ supported.dispose();
691
+ }
692
+ });
@@ -0,0 +1,30 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { expect, test } from "bun:test";
3
+
4
+ // Source contract for the macOS-only implementation; native capture itself is
5
+ // exercised on macOS, not by this cross-platform guard.
6
+ test("native targeted observations reset but never overwrite desktop history", () => {
7
+ const source = readFileSync(
8
+ new URL(
9
+ "../../../clients/macos/native/mac-helper/Sources/MacHelperExecutable/ComputerUse/HostCuExecutor.swift",
10
+ import.meta.url,
11
+ ),
12
+ "utf8",
13
+ );
14
+ const builder = source.slice(
15
+ source.indexOf("private static func buildObservation("),
16
+ source.indexOf("/// Package observation data"),
17
+ );
18
+ expect(builder).toContain(
19
+ "if captureTarget != nil {\n previousAXElements.removeValue(forKey: conversationId)\n }",
20
+ );
21
+ expect(builder.indexOf("previousAXElements.removeValue")).toBeLessThan(
22
+ builder.indexOf("switch captureTarget"),
23
+ );
24
+ expect(builder).toContain(
25
+ "currentElements = captureTarget == nil ? flat : nil",
26
+ );
27
+ expect(builder).toContain(
28
+ "if captureTarget == nil, let previousFlat = previousAXElements[conversationId]",
29
+ );
30
+ });
@@ -0,0 +1,24 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { expect, test } from "bun:test";
3
+
4
+ import { computerUseObserveTool } from "../tools/computer-use/definitions.js";
5
+
6
+ test("window observation schema matches the skill manifest", () => {
7
+ const manifest = JSON.parse(
8
+ readFileSync(
9
+ new URL(
10
+ "../config/bundled-skills/computer-use/TOOLS.json",
11
+ import.meta.url,
12
+ ),
13
+ "utf8",
14
+ ),
15
+ );
16
+ expect(
17
+ manifest.tools.find(
18
+ (tool: { name: string }) => tool.name === "computer_use_observe",
19
+ ).input_schema,
20
+ ).toEqual(computerUseObserveTool.input_schema);
21
+ expect(
22
+ computerUseObserveTool.input_schema.properties.capture_window_id,
23
+ ).toMatchObject({ type: "integer", minimum: 1, maximum: 4294967295 });
24
+ });
@@ -1,6 +1,7 @@
1
1
  import { afterEach, describe, expect, jest, mock, test } from "bun:test";
2
2
 
3
3
  const sentMessages: unknown[] = [];
4
+ const sentOptions: unknown[] = [];
4
5
  let mockHasClient = false;
5
6
  type MockClient = {
6
7
  clientId: string;
@@ -10,13 +11,18 @@ type MockClient = {
10
11
  let mockClients: MockClient[] = [];
11
12
 
12
13
  mock.module("../runtime/assistant-event-hub.js", () => ({
13
- broadcastMessage: (msg: unknown) => {
14
+ broadcastMessage: (
15
+ msg: unknown,
16
+ _conversationId: unknown,
17
+ options: unknown,
18
+ ) => {
14
19
  // Skip `interaction_resolved` envelopes — pending-interactions emits one
15
20
  // on every resolve and these tests assert on host-proxy wire messages.
16
21
  if ((msg as { type?: string } | null)?.type === "interaction_resolved") {
17
22
  return;
18
23
  }
19
24
  sentMessages.push(msg);
25
+ sentOptions.push(options);
20
26
  },
21
27
  assistantEventHub: {
22
28
  getMostRecentClientByCapability: (cap: string) =>
@@ -39,6 +45,7 @@ describe("HostCuProxy", () => {
39
45
 
40
46
  function setup(maxSteps?: number) {
41
47
  sentMessages.length = 0;
48
+ sentOptions.length = 0;
42
49
  mockHasClient = false;
43
50
  mockClients = [];
44
51
  pendingInteractions.clear();
@@ -1494,4 +1501,155 @@ describe("HostCuProxy", () => {
1494
1501
  expect(result.isError).toBe(false);
1495
1502
  });
1496
1503
  });
1504
+
1505
+ describe("window capture privacy and observation history", () => {
1506
+ function connect(supported = true) {
1507
+ mockClients = [
1508
+ {
1509
+ clientId: "mac-1",
1510
+ actorPrincipalId: "user-1",
1511
+ capabilities: supported
1512
+ ? ["host_cu", "host_cu_window_capture"]
1513
+ : ["host_cu"],
1514
+ },
1515
+ ];
1516
+ }
1517
+ function observe(input: Record<string, unknown>, targetClientId?: string) {
1518
+ return proxy.request(
1519
+ "computer_use_observe",
1520
+ input,
1521
+ "session-1",
1522
+ 1,
1523
+ undefined,
1524
+ undefined,
1525
+ targetClientId,
1526
+ "user-1",
1527
+ );
1528
+ }
1529
+ async function finish(
1530
+ input: Record<string, unknown>,
1531
+ observation: Record<string, string>,
1532
+ ) {
1533
+ proxy.recordAction("computer_use_observe", input);
1534
+ const pending = observe(input);
1535
+ const sent = sentMessages.at(-1) as { requestId: string };
1536
+ proxy.processObservation(sent.requestId, observation);
1537
+ return await pending;
1538
+ }
1539
+
1540
+ test("old clients fail closed for both explicit and automatic targeting", async () => {
1541
+ setup();
1542
+ connect(false);
1543
+ for (const target of [undefined, "mac-1"]) {
1544
+ expect((await observe({ capture_window_id: 12 }, target)).isError).toBe(
1545
+ true,
1546
+ );
1547
+ }
1548
+ expect(sentMessages).toHaveLength(0);
1549
+ });
1550
+ test("unknown support never falls back to an untargeted broadcast", async () => {
1551
+ setup();
1552
+ expect((await observe({ capture_window_id: 12 })).isError).toBe(true);
1553
+ expect(sentMessages).toHaveLength(0);
1554
+ });
1555
+ test("supported clients receive explicitly targeted dispatch", async () => {
1556
+ setup();
1557
+ connect();
1558
+ for (const target of [undefined, "mac-1"]) {
1559
+ const pending = observe({ capture_window_id: 12 }, target);
1560
+ const sent = sentMessages.at(-1) as {
1561
+ requestId: string;
1562
+ targetClientId: string;
1563
+ };
1564
+ expect(sent.targetClientId).toBe("mac-1");
1565
+ expect(sentOptions.at(-1)).toEqual({
1566
+ targetClientId: "mac-1",
1567
+ });
1568
+ proxy.processObservation(sent.requestId, { axTree: "Window" });
1569
+ expect((await pending).isError).toBe(false);
1570
+ }
1571
+ });
1572
+ test("invalid targets and scoped actions are rejected before dispatch", async () => {
1573
+ setup();
1574
+ connect();
1575
+ for (const id of [0, -1, 1.5, "12", null, NaN, Infinity, 4294967296]) {
1576
+ expect((await observe({ capture_window_id: id })).isError).toBe(true);
1577
+ }
1578
+ expect(
1579
+ (await observe({ capture_window_id: 12, captureDisplayId: 2 })).isError,
1580
+ ).toBe(true);
1581
+ expect(
1582
+ (await observe({ capture_window_id: 12, captureWindowId: 2 })).isError,
1583
+ ).toBe(true);
1584
+ expect(
1585
+ (
1586
+ await proxy.request(
1587
+ "computer_use_click",
1588
+ { capture_window_id: 12 },
1589
+ "session-1",
1590
+ 1,
1591
+ undefined,
1592
+ undefined,
1593
+ "mac-1",
1594
+ "user-1",
1595
+ )
1596
+ ).isError,
1597
+ ).toBe(true);
1598
+ expect(sentMessages).toHaveLength(0);
1599
+ });
1600
+ test("targeted snapshots reset history without no-effect warnings or cross-window diffs", async () => {
1601
+ setup();
1602
+ connect();
1603
+ await finish({}, { axTree: "Private desktop" });
1604
+ await finish({}, { axTree: "Private desktop" });
1605
+ expect(proxy.consecutiveUnchangedSteps).toBe(1);
1606
+ for (const id of [12, 12, 13]) {
1607
+ const result = await finish(
1608
+ { capture_window_id: id },
1609
+ {
1610
+ axTree: "Chosen window",
1611
+ axDiff: "Removed Private desktop",
1612
+ secondaryWindows: "Private secondary window",
1613
+ },
1614
+ );
1615
+ expect(result.content).not.toContain("NO VISIBLE EFFECT");
1616
+ expect(result.content).not.toContain("Private");
1617
+ expect(proxy.previousAXTree).toBeUndefined();
1618
+ expect(proxy.consecutiveUnchangedSteps).toBe(0);
1619
+ }
1620
+ const desktop = await finish({}, { axTree: "Returned desktop" });
1621
+ expect(desktop.content).not.toContain("NO VISIBLE EFFECT");
1622
+ expect(proxy.previousAXTree).toBe("Returned desktop");
1623
+ expect(proxy.consecutiveUnchangedSteps).toBe(0);
1624
+ await finish({}, { axTree: "Returned desktop" });
1625
+ expect(proxy.consecutiveUnchangedSteps).toBe(1);
1626
+ });
1627
+ test("failed targeted captures also break the desktop comparison baseline", async () => {
1628
+ setup();
1629
+ connect();
1630
+ await finish({}, { axTree: "Desktop" });
1631
+ expect(
1632
+ (
1633
+ await finish(
1634
+ { capture_window_id: 99 },
1635
+ { executionError: "Window not found" },
1636
+ )
1637
+ ).isError,
1638
+ ).toBe(true);
1639
+ expect(proxy.previousAXTree).toBeUndefined();
1640
+ const result = await finish({}, { axTree: "Desktop" });
1641
+ expect(result.content).not.toContain("NO VISIBLE EFFECT");
1642
+ });
1643
+ test("legacy camel-case companion targets also reset observation history", async () => {
1644
+ setup();
1645
+ connect();
1646
+ await finish({}, { axTree: "Desktop" });
1647
+ const result = await finish(
1648
+ { captureDisplayId: 1 },
1649
+ { axTree: "Display" },
1650
+ );
1651
+ expect(result.content).not.toContain("NO VISIBLE EFFECT");
1652
+ expect(proxy.previousAXTree).toBeUndefined();
1653
+ });
1654
+ });
1497
1655
  });
@@ -307,6 +307,7 @@ export const HOST_PROXY_CAPABILITIES = [
307
307
  "host_bash",
308
308
  "host_file",
309
309
  "host_cu",
310
+ "host_cu_window_capture",
310
311
  "host_browser",
311
312
  "host_app_control",
312
313
  "host_ui_snapshot",
@@ -347,6 +348,10 @@ export function supportsHostProxy(
347
348
  id: InterfaceId,
348
349
  capability?: HostProxyCapability,
349
350
  ): boolean {
351
+ // Window capture is additionally negotiated on each client connection.
352
+ if (capability === "host_cu_window_capture") {
353
+ return id === "macos";
354
+ }
350
355
  // macOS supports every host proxy capability including host_browser
351
356
  // and host_app_control. The host_browser proxy is provisioned via the
352
357
  // assistant event hub. When no extension is connected, browser tools fall
@@ -22,3 +22,24 @@ The skill is internally preactivated for conversations with a connected desktop
22
22
 
23
23
  Tools in this skill are proxy tools. Execution is forwarded to a connected
24
24
  desktop client and is never handled locally by the assistant.
25
+
26
+ ## Window-scoped observation (macOS)
27
+
28
+ `computer_use_observe` accepts optional `capture_window_id`, a native macOS
29
+ CGWindowID (not a browser tab ID or accessibility element ID). Obtain the ID
30
+ from a current native window inventory before using it; never guess one.
31
+ The native helper captures that window and its accessibility tree without
32
+ including secondary windows, even when another app covers the selected window.
33
+ A missing window must not be replaced with a desktop capture.
34
+
35
+ This is a **single observation**, not a session-wide privacy boundary: normal
36
+ click/type/scroll and other action tools still return their normal desktop
37
+ observations. Do not promise app-only capture for a whole control session.
38
+ The desktop must explicitly advertise `host_cu_window_capture` support on its
39
+ connection; the daemon rejects older or unsupported clients before requesting
40
+ any capture. Other desktop platforms reject this option.
41
+
42
+ The screenshot is window-relative, while action coordinates are screen points;
43
+ do not scale it using full-display dimensions. Prefer accessibility element IDs
44
+ and ensure the intended window is focused before a later action. Window-scoped
45
+ observation does not focus the window or confine subsequent input to that app.
@@ -9,6 +9,12 @@
9
9
  "input_schema": {
10
10
  "type": "object",
11
11
  "properties": {
12
+ "capture_window_id": {
13
+ "type": "integer",
14
+ "minimum": 1,
15
+ "maximum": 4294967295,
16
+ "description": "macOS only: capture this native CGWindowID instead of the desktop, including only its accessibility tree. Obtain a current native window ID first; do not guess or use a browser tab ID. Applies to this observation only, not subsequent actions. Requires a desktop helper with window-capture support. Screenshot coordinates are window-relative; use accessibility element IDs for later actions, not desktop scaling."
17
+ },
12
18
  "target_client_id": {
13
19
  "type": "string",
14
20
  "description": "ID of the specific client to target. Required when multiple clients support host_cu; omit when only one is connected. Obtain IDs from `assistant clients list --capability host_cu`."
@@ -174,8 +174,8 @@ export class HostCuProxy {
174
174
  private _previousAXTree: string | undefined;
175
175
  private _consecutiveUnchangedSteps = 0;
176
176
  private _actionHistory: ActionRecord[] = [];
177
- /** Request IDs owned by this instance — used to scope dispose(). */
178
- private _ownedRequests = new Set<string>();
177
+ /** Owned request IDs mapped to whether their observation is scoped. */
178
+ private _ownedRequests = new Map<string, boolean>();
179
179
 
180
180
  constructor(maxSteps = loadConfig().maxStepsPerSession) {
181
181
  this._maxSteps = maxSteps;
@@ -303,6 +303,46 @@ export class HostCuProxy {
303
303
  }
304
304
  }
305
305
 
306
+ const hasWindowTarget = Object.hasOwn(input, "capture_window_id");
307
+ if (hasWindowTarget) {
308
+ const id = input.capture_window_id;
309
+ if (
310
+ toolName !== "computer_use_observe" ||
311
+ typeof id !== "number" ||
312
+ !Number.isInteger(id) ||
313
+ id < 1 ||
314
+ id > 0xffffffff ||
315
+ Object.hasOwn(input, "captureWindowId") ||
316
+ Object.hasOwn(input, "captureDisplayId")
317
+ ) {
318
+ return Promise.resolve({
319
+ content:
320
+ "capture_window_id requires a valid CGWindowID on computer_use_observe with no conflicting capture target.",
321
+ isError: true,
322
+ });
323
+ }
324
+ // Never dispatch this option to a legacy executor: it would forward the
325
+ // unknown snake-case key and silently capture the entire desktop.
326
+ const client =
327
+ resolvedTargetClientId == null
328
+ ? undefined
329
+ : assistantEventHub.getClientById(resolvedTargetClientId);
330
+ if (!client?.capabilities.includes("host_cu_window_capture")) {
331
+ return Promise.resolve({
332
+ content:
333
+ "Window-only observation requires a connected client advertising host_cu_window_capture; update the desktop app before retrying. No capture was requested.",
334
+ isError: true,
335
+ });
336
+ }
337
+ }
338
+ const scopedObservation =
339
+ hasWindowTarget ||
340
+ Object.hasOwn(input, "captureWindowId") ||
341
+ Object.hasOwn(input, "captureDisplayId");
342
+ if (scopedObservation) {
343
+ this._previousAXTree = undefined;
344
+ this._consecutiveUnchangedSteps = 0;
345
+ }
306
346
  const requestId = uuid();
307
347
 
308
348
  return new Promise<ToolExecutionResult>((resolve, reject) => {
@@ -346,7 +386,7 @@ export class HostCuProxy {
346
386
  detachAbort = () => signal.removeEventListener("abort", onAbort);
347
387
  }
348
388
 
349
- this._ownedRequests.add(requestId);
389
+ this._ownedRequests.set(requestId, scopedObservation);
350
390
 
351
391
  pendingInteractions.register(requestId, {
352
392
  conversationId,
@@ -399,6 +439,7 @@ export class HostCuProxy {
399
439
  requestId: string,
400
440
  observation: CuObservationResult,
401
441
  ): ToolExecutionResult | undefined {
442
+ const scopedObservation = this._ownedRequests.get(requestId) ?? false;
402
443
  this._ownedRequests.delete(requestId);
403
444
  const interaction = pendingInteractions.resolve(requestId, "answered");
404
445
  if (!interaction?.rpcResolve) {
@@ -406,9 +447,20 @@ export class HostCuProxy {
406
447
  return undefined;
407
448
  }
408
449
 
450
+ // A targeted snapshot has no comparable action/diff baseline; neither it
451
+ // nor the first desktop observation after it can imply "no visible effect".
452
+ if (scopedObservation) {
453
+ this._previousAXTree = undefined;
454
+ this._consecutiveUnchangedSteps = 0;
455
+ }
409
456
  const prevAXTree = this._previousAXTree;
410
- this.updateStateFromObservation(observation);
411
- const result = this.formatObservation(observation, prevAXTree);
457
+ const comparableObservation = scopedObservation
458
+ ? { ...observation, axDiff: undefined, secondaryWindows: undefined }
459
+ : observation;
460
+ if (!scopedObservation) {
461
+ this.updateStateFromObservation(comparableObservation);
462
+ }
463
+ const result = this.formatObservation(comparableObservation, prevAXTree);
412
464
  interaction.rpcResolve(result);
413
465
  return result;
414
466
  }
@@ -566,7 +618,7 @@ export class HostCuProxy {
566
618
  // ---------------------------------------------------------------------------
567
619
 
568
620
  dispose(): void {
569
- for (const requestId of this._ownedRequests) {
621
+ for (const requestId of this._ownedRequests.keys()) {
570
622
  const entry = pendingInteractions.resolve(requestId, "cancelled");
571
623
  if (!entry) {
572
624
  continue;