@vellumai/assistant 0.12.1-dev.202609141913.5e16607 → 0.12.1-dev.202609142113.d1590bc

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 (118) hide show
  1. package/ARCHITECTURE.md +9 -9
  2. package/openapi.yaml +35 -2
  3. package/package.json +2 -1
  4. package/src/__tests__/anthropic-provider.test.ts +0 -63
  5. package/src/__tests__/assistant-event-hub-machine-name.test.ts +6 -7
  6. package/src/__tests__/assistant-event-hub.test.ts +44 -0
  7. package/src/__tests__/computer-use-skill-manifest-regression.test.ts +1 -1
  8. package/src/__tests__/computer-use-tools.test.ts +2 -2
  9. package/src/__tests__/heartbeat-service.test.ts +56 -40
  10. package/src/__tests__/host-cu-proxy.test.ts +539 -0
  11. package/src/__tests__/list-messages-camera-frame.test.ts +121 -0
  12. package/src/__tests__/oauth-commands-routes.test.ts +113 -0
  13. package/src/__tests__/oauth-provider-profiles.test.ts +18 -0
  14. package/src/__tests__/openai-provider.test.ts +1 -0
  15. package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
  16. package/src/__tests__/qdrant-manager.test.ts +132 -0
  17. package/src/__tests__/scaffold-managed-skill-tool.test.ts +229 -6
  18. package/src/__tests__/skills.test.ts +9 -4
  19. package/src/__tests__/test-support/computer-use-skill-harness.ts +3 -2
  20. package/src/__tests__/unicode.test.ts +13 -0
  21. package/src/acp/agent-process.ts +2 -1
  22. package/src/agent/loop.ts +1 -0
  23. package/src/api/events/user-message-echo.ts +7 -1
  24. package/src/api/responses/conversation-message.ts +5 -0
  25. package/src/avatar/identity-avatar.ts +7 -2
  26. package/src/config/bundled-skills/computer-use/SKILL.md +20 -2
  27. package/src/config/bundled-skills/computer-use/TOOLS.json +99 -0
  28. package/src/config/bundled-skills/computer-use/tools/computer-use-sequence.ts +12 -0
  29. package/src/config/bundled-skills/media-processing/services/preprocess.ts +2 -1
  30. package/src/config/bundled-skills/media-processing/services/processing-pipeline.ts +2 -1
  31. package/src/config/bundled-skills/media-processing/tools/generate-clip.ts +2 -1
  32. package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +2 -1
  33. package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +2 -1
  34. package/src/config/bundled-skills/skill-management/TOOLS.json +4 -0
  35. package/src/config/bundled-skills/transcribe/tools/transcribe-media.ts +5 -2
  36. package/src/credential-health/credential-health-service.ts +11 -17
  37. package/src/daemon/conversation-error.ts +3 -2
  38. package/src/daemon/conversation-media-retry.ts +2 -1
  39. package/src/daemon/conversation-runtime-assembly.ts +2 -1
  40. package/src/daemon/conversation-surfaces.ts +5 -1
  41. package/src/daemon/dictation-profile-store.ts +2 -1
  42. package/src/daemon/handlers/shared.ts +2 -1
  43. package/src/daemon/handlers/skills.ts +6 -3
  44. package/src/daemon/host-cu-proxy.ts +186 -19
  45. package/src/daemon/host-proxy-preactivation.ts +2 -1
  46. package/src/daemon/reaction-history-render.ts +2 -1
  47. package/src/heartbeat/heartbeat-service.ts +21 -3
  48. package/src/live-voice/__tests__/live-voice-sight-frame-echo.test.ts +238 -0
  49. package/src/live-voice/live-voice-photo.ts +25 -6
  50. package/src/oauth/AGENTS.md +2 -0
  51. package/src/oauth/byo-connection.test.ts +60 -0
  52. package/src/oauth/scope-utils.ts +24 -0
  53. package/src/oauth/seed-providers.ts +39 -25
  54. package/src/persistence/conversation-queries.ts +2 -2
  55. package/src/persistence/embeddings/qdrant-manager.ts +163 -18
  56. package/src/plugins/defaults/memory/__tests__/memory-retrospective-prompt.test.ts +5 -0
  57. package/src/plugins/defaults/memory/context-search/agent-runner.ts +3 -2
  58. package/src/plugins/defaults/memory/context-search/format.ts +3 -2
  59. package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +6 -3
  60. package/src/plugins/defaults/memory/context-search/sources/workspace.ts +3 -2
  61. package/src/plugins/defaults/memory/graph/capability-seed.ts +2 -1
  62. package/src/plugins/defaults/memory/host-utils.ts +10 -0
  63. package/src/plugins/defaults/memory/memory-retrospective-prompt.ts +1 -1
  64. package/src/plugins/defaults/memory/startup.ts +22 -1
  65. package/src/plugins/defaults/memory/substrate/page-index.ts +6 -1
  66. package/src/plugins/defaults/memory/v1/graph/consolidation.ts +4 -2
  67. package/src/plugins/defaults/memory/v1/graph/extraction.ts +4 -2
  68. package/src/plugins/defaults/memory/v1/graph/retriever.ts +4 -1
  69. package/src/plugins/defaults/memory/v2/reranker.ts +6 -1
  70. package/src/plugins/defaults/memory/v3/__tests__/card.test.ts +24 -0
  71. package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +39 -3
  72. package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +26 -0
  73. package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +30 -0
  74. package/src/plugins/defaults/memory/v3/card.ts +3 -2
  75. package/src/plugins/defaults/memory/v3/pool-select.ts +5 -3
  76. package/src/plugins/defaults/memory/v3/sections.ts +9 -3
  77. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +5 -2
  78. package/src/providers/__tests__/retry-outbound-sanitize.test.ts +176 -0
  79. package/src/providers/anthropic/client.ts +0 -47
  80. package/src/providers/openai/__tests__/chat-completions-output-token-limit.test.ts +141 -0
  81. package/src/providers/openai/chat-completions-provider.ts +20 -1
  82. package/src/providers/openrouter/client.ts +20 -0
  83. package/src/providers/outbound-request-sanitize.ts +96 -0
  84. package/src/providers/retry.ts +24 -3
  85. package/src/providers/unparseable-tool-args.ts +5 -1
  86. package/src/runtime/AGENTS.md +1 -1
  87. package/src/runtime/__tests__/host-observe.test.ts +40 -1
  88. package/src/runtime/agent-wake.ts +2 -1
  89. package/src/runtime/assistant-event-hub.ts +21 -3
  90. package/src/runtime/host-observe.ts +11 -1
  91. package/src/runtime/routes/conversation-routes.ts +16 -3
  92. package/src/runtime/routes/diagnostics-routes.ts +6 -1
  93. package/src/runtime/routes/events-routes.ts +4 -0
  94. package/src/runtime/routes/host-cu-routes.ts +6 -0
  95. package/src/runtime/routes/oauth-commands-routes.ts +36 -0
  96. package/src/runtime/routes/workspace-routes.test.ts +55 -26
  97. package/src/runtime/routes/workspace-routes.ts +46 -63
  98. package/src/runtime/routes/workspace-tree-walk.test.ts +244 -0
  99. package/src/runtime/routes/workspace-tree-walk.ts +240 -0
  100. package/src/runtime/routes/workspace-utils.ts +17 -0
  101. package/src/schedule/run-script.ts +2 -1
  102. package/src/schedule/schedule-store.ts +9 -2
  103. package/src/security/untrusted-content.ts +3 -1
  104. package/src/tools/__tests__/side-effect-abort-guard.test.ts +1 -0
  105. package/src/tools/browser/browser-execution.ts +1 -1
  106. package/src/tools/browser/cdp-client/accessibility-snapshot.ts +9 -3
  107. package/src/tools/browser/cdp-client/cdp-inspect/discovery.ts +2 -1
  108. package/src/tools/browser/cdp-client/extension-cdp-client.ts +3 -2
  109. package/src/tools/browser/network-recorder.ts +2 -1
  110. package/src/tools/computer-use/definitions.ts +117 -0
  111. package/src/tools/filesystem/search.ts +2 -1
  112. package/src/tools/network/web-search.ts +6 -1
  113. package/src/tools/skills/scaffold-managed.ts +61 -3
  114. package/src/types/host-capabilities.ts +5 -3
  115. package/src/util/unicode.ts +15 -1
  116. package/src/watch/watch-timeline.ts +2 -2
  117. package/src/workflows/run-manager.ts +2 -1
  118. package/src/workspace/git-service.ts +1 -1
@@ -237,6 +237,7 @@ async function enqueueStandaloneImagePersist(
237
237
  [ticket.attachmentId],
238
238
  ticket.content,
239
239
  uuidv7(),
240
+ kind,
240
241
  );
241
242
  return { ok: false };
242
243
  }
@@ -389,11 +390,18 @@ function reclaimOrDefer(
389
390
  attachmentIds: readonly string[],
390
391
  content: string,
391
392
  messageId: string,
393
+ kind: "photo" | "sight_frame",
392
394
  ): void {
393
395
  if (reclaimDroppedFrame(attachmentIds)) {
394
396
  return;
395
397
  }
396
- deferFrameReclaimDecision(conversationId, messageId, attachmentIds, content);
398
+ deferFrameReclaimDecision(
399
+ conversationId,
400
+ messageId,
401
+ attachmentIds,
402
+ content,
403
+ kind,
404
+ );
397
405
  }
398
406
 
399
407
  /** Conversations with a standalone-image persist still in flight. */
@@ -429,6 +437,8 @@ interface PendingFrameReclaim {
429
437
  attachmentIds: readonly string[];
430
438
  /** Row text, so a frame found to have landed can still be announced. */
431
439
  content: string;
440
+ /** The echo shape used if a later recheck finds the row. */
441
+ kind: "photo" | "sight_frame";
432
442
  attempts: number;
433
443
  }
434
444
 
@@ -465,12 +475,14 @@ function deferFrameReclaimDecision(
465
475
  messageId: string,
466
476
  attachmentIds: readonly string[],
467
477
  content: string,
478
+ kind: "photo" | "sight_frame",
468
479
  ): void {
469
480
  pendingFrameReclaims.push({
470
481
  conversationId,
471
482
  messageId,
472
483
  attachmentIds,
473
484
  content,
485
+ kind,
474
486
  attempts: 0,
475
487
  });
476
488
  scheduleFrameReclaimRecheck();
@@ -521,6 +533,7 @@ function announceDeferredImage(pending: PendingFrameReclaim): void {
521
533
  pending.conversationId,
522
534
  pending.content,
523
535
  pending.messageId,
536
+ pending.kind,
524
537
  );
525
538
  } catch (err) {
526
539
  log.warn(
@@ -700,6 +713,7 @@ function persistStandaloneImage(
700
713
  uuidv7(),
701
714
  [attachmentId],
702
715
  persistOptions.content,
716
+ kind,
703
717
  );
704
718
  }
705
719
  return Promise.resolve({ ok: false });
@@ -715,6 +729,7 @@ function persistStandaloneImage(
715
729
  [attachmentId],
716
730
  persistOptions.content,
717
731
  uuidv7(),
732
+ kind,
718
733
  );
719
734
  }
720
735
  return Promise.resolve({ ok: false });
@@ -754,7 +769,7 @@ function dropReplacedImage(
754
769
  "Standalone image dropped: its conversation was replaced before the write",
755
770
  );
756
771
  if (kind === "sight_frame") {
757
- reclaimOrDefer(conversationId, [attachmentId], content, uuidv7());
772
+ reclaimOrDefer(conversationId, [attachmentId], content, uuidv7(), kind);
758
773
  }
759
774
  return { ok: false };
760
775
  }
@@ -806,7 +821,7 @@ async function writeStandaloneImage(
806
821
  "Standalone image dropped: its conversation was deleted while it waited",
807
822
  );
808
823
  if (kind === "sight_frame") {
809
- reclaimOrDefer(conversationId, [attachmentId], content, uuidv7());
824
+ reclaimOrDefer(conversationId, [attachmentId], content, uuidv7(), kind);
810
825
  }
811
826
  return { ok: false };
812
827
  }
@@ -831,7 +846,7 @@ async function writeStandaloneImage(
831
846
  "Standalone image timed out waiting for the conversation to go idle",
832
847
  );
833
848
  if (kind === "sight_frame") {
834
- reclaimOrDefer(conversationId, [attachmentId], content, uuidv7());
849
+ reclaimOrDefer(conversationId, [attachmentId], content, uuidv7(), kind);
835
850
  }
836
851
  return { ok: false };
837
852
  }
@@ -882,7 +897,7 @@ async function writeStandaloneImage(
882
897
  // of.
883
898
  conversation.markHistoryStaleForForeignScope(persistOptions.trustContext);
884
899
 
885
- announcePersistedImage(conversationId, content, persisted.id);
900
+ announcePersistedImage(conversationId, content, persisted.id, kind);
886
901
 
887
902
  return {
888
903
  ok: true,
@@ -930,7 +945,7 @@ async function writeStandaloneImage(
930
945
  // `ensureActorScopedHistory` reloads instead of reusing what it holds.
931
946
  findConversation(conversationId)?.markHistoryStale();
932
947
  try {
933
- announcePersistedImage(conversationId, content, requestId);
948
+ announcePersistedImage(conversationId, content, requestId, kind);
934
949
  } catch (announceErr) {
935
950
  log.warn(
936
951
  { err: announceErr, conversationId, messageId: requestId },
@@ -946,6 +961,7 @@ async function writeStandaloneImage(
946
961
  [attachmentId, ...strandedClones],
947
962
  content,
948
963
  requestId,
964
+ kind,
949
965
  );
950
966
  } else {
951
967
  // The store would not say whether the row landed. The refusal below
@@ -957,6 +973,7 @@ async function writeStandaloneImage(
957
973
  requestId,
958
974
  [attachmentId, ...strandedClones],
959
975
  content,
976
+ kind,
960
977
  );
961
978
  }
962
979
  }
@@ -974,12 +991,14 @@ function announcePersistedImage(
974
991
  conversationId: string,
975
992
  text: string,
976
993
  messageId: string,
994
+ kind: "photo" | "sight_frame",
977
995
  ): void {
978
996
  broadcastMessage({
979
997
  type: "user_message_echo",
980
998
  text,
981
999
  conversationId,
982
1000
  messageId,
1001
+ ...(kind === "sight_frame" ? { cameraFrame: true as const } : {}),
983
1002
  });
984
1003
  recordConversationPersistedSeq(conversationId, getCurrentSeq());
985
1004
  publishConversationMessagesChanged(conversationId);
@@ -8,6 +8,8 @@ When introducing a new built-in OAuth integration (one that appears in `seed-pro
8
8
 
9
9
  Add an entry to `PROVIDER_SEED_DATA`. Required fields: `provider`, `authorizeUrl`, `tokenExchangeUrl`, `defaultScopes`, `displayLabel`, `description`, `dashboardUrl`, `clientIdPlaceholder`, `logoUrl`, and `injectionTemplates`. Optional: `availableScopes` — either a structured array of `{scope, description?}` objects or a URL string pointing to the provider's scope documentation. See existing entries for the full shape. The `provider` key must be snake_case and is used as the canonical identifier everywhere else.
10
10
 
11
+ `injectionTemplates` is also a security boundary, not only an injection rule. `assistant oauth request` and `assistant channels request` accept an absolute URL only when its host matches one of the entry's `hostPattern` values (`assertOAuthRequestUrlAllowed` in `../runtime/routes/oauth-commands-routes.ts`), so that list is the full set of hosts the credential may be sent to. A pattern matches exactly unless it starts with `*.`; reserve the wildcard for per-tenant hosts that cannot be enumerated (`*.salesforce.com`), and name a fixed host the provider documents (`files.slack.com`) by name. The guard sees only the URL the caller passes: the connection follows a redirect itself, and a cross-origin hop carries no `Authorization`, so a redirect target never receives the credential and never needs listing.
12
+
11
13
  If the provider will support managed mode, set `managedServiceConfigKey` to a slug matching the key you will add to `ServicesSchema` (e.g. `"acme-oauth"`).
12
14
 
13
15
  ### 2. _(managed only)_ Add a service schema — `../config/schemas/services.ts`
@@ -308,6 +308,66 @@ describe("BYOOAuthConnection", () => {
308
308
  expect((init as RequestInit).method).toBe("GET");
309
309
  });
310
310
 
311
+ test("follows a cross-origin redirect without the credential and returns the target's bytes", async () => {
312
+ // Real fetch against two loopback origins: the credential goes to the
313
+ // host the caller named, the redirect target sees no Authorization,
314
+ // and the target's bytes come back as the response body. This is the
315
+ // path a Slack file download takes when files.slack.com answers with a
316
+ // 302 to its CDN.
317
+ globalThis.fetch = originalFetch;
318
+ await setupCredential("google");
319
+ const bytes = Buffer.from([
320
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
321
+ ]);
322
+ const seen: { origin?: string | null; target?: string | null } = {};
323
+
324
+ const target = Bun.serve({
325
+ port: 0,
326
+ hostname: "127.0.0.1",
327
+ fetch: (req) => {
328
+ seen.target = req.headers.get("authorization");
329
+ return new Response(bytes, {
330
+ status: 200,
331
+ headers: { "content-type": "image/png" },
332
+ });
333
+ },
334
+ });
335
+ const origin = Bun.serve({
336
+ port: 0,
337
+ hostname: "127.0.0.1",
338
+ fetch: (req) => {
339
+ seen.origin = req.headers.get("authorization");
340
+ return new Response(null, {
341
+ status: 302,
342
+ headers: { Location: `http://127.0.0.1:${target.port}/signed` },
343
+ });
344
+ },
345
+ });
346
+
347
+ try {
348
+ const conn = new BYOOAuthConnection({
349
+ id: "conn-google",
350
+ provider: "google",
351
+ baseUrl: `http://127.0.0.1:${origin.port}`,
352
+ accountInfo: null,
353
+ });
354
+
355
+ const result = await conn.request({
356
+ method: "GET",
357
+ path: "/files-pri/T0123-F0456/download/shot.png",
358
+ });
359
+
360
+ expect(seen.origin).toBe("Bearer test-access-token");
361
+ expect(seen.target).toBeNull();
362
+ expect(result.status).toBe(200);
363
+ expect(Buffer.isBuffer(result.body)).toBe(true);
364
+ expect(Buffer.from(result.body as Buffer).equals(bytes)).toBe(true);
365
+ } finally {
366
+ origin.stop(true);
367
+ target.stop(true);
368
+ }
369
+ });
370
+
311
371
  test("appends query parameters", async () => {
312
372
  await setupCredential("google");
313
373
  const conn = createConnection();
@@ -72,6 +72,30 @@ export function expectedScopesForStoredToken(
72
72
  return parsed.length > 0 ? parsed : defaultScopes;
73
73
  }
74
74
 
75
+ /**
76
+ * The required scopes a stored grant lacks. Requirements come from the request
77
+ * that produced the stored token ({@link expectedScopesForStoredToken}), so a
78
+ * provider's bot-only scopes are never demanded of a user token. An empty
79
+ * requirement or an unrecorded grant reports nothing, because unknown scope
80
+ * data must never read as a failure.
81
+ */
82
+ export function missingScopesForStoredToken(
83
+ defaultScopes: string[],
84
+ authorizeParams: Record<string, string> | undefined,
85
+ scopeSeparator: string | undefined,
86
+ grantedScopes: string[],
87
+ ): string[] {
88
+ const expected = expectedScopesForStoredToken(
89
+ defaultScopes,
90
+ authorizeParams,
91
+ scopeSeparator,
92
+ );
93
+ if (expected.length === 0 || grantedScopes.length === 0) {
94
+ return [];
95
+ }
96
+ return scopeDifference(expected, grantedScopes);
97
+ }
98
+
75
99
  const GMAIL_FULL_ACCESS_SCOPE = "https://mail.google.com/";
76
100
  const GMAIL_READONLY_SCOPE = "https://www.googleapis.com/auth/gmail.readonly";
77
101
 
@@ -9,6 +9,30 @@ import { migrateProviderBaseUrl, seedProviders } from "./oauth-store.js";
9
9
  */
10
10
  const STALE_GOOGLE_BASE_URL = "https://gmail.googleapis.com/gmail/v1/users/me";
11
11
 
12
+ /**
13
+ * The hosts a Slack credential may be sent to, shared by the person-identity
14
+ * `slack` provider and the `slack_channel` bot: both read messages, and a file
15
+ * shared in a message is fetched from the file object's `url_private`,
16
+ * `url_private_download`, or `thumb_*` URL on `files.slack.com` with the same
17
+ * Bearer token as the Web API. Slack documents that one file host by name.
18
+ */
19
+ const SLACK_PROVIDER_INJECTION_TEMPLATES: NonNullable<
20
+ (typeof PROVIDER_SEED_DATA)[string]["injectionTemplates"]
21
+ > = [
22
+ {
23
+ hostPattern: "slack.com",
24
+ injectionType: "header",
25
+ headerName: "Authorization",
26
+ valuePrefix: "Bearer ",
27
+ },
28
+ {
29
+ hostPattern: "files.slack.com",
30
+ injectionType: "header",
31
+ headerName: "Authorization",
32
+ valuePrefix: "Bearer ",
33
+ },
34
+ ];
35
+
12
36
  /**
13
37
  * Protocol-level seed data for each well-known OAuth provider.
14
38
  *
@@ -183,14 +207,13 @@ export const PROVIDER_SEED_DATA: Record<
183
207
  clientIdPlaceholder: null,
184
208
  logoUrl:
185
209
  "https://cdn.jsdelivr.net/gh/glincker/thesvg@main/public/icons/slack/default.svg",
186
- // Sent as the bot `scope` parameter, while this flow persists the
187
- // `authed_user` token and stores `authed_user.scope` as `grantedScopes`.
188
- // Credential health compares this list against that grant, so a scope
189
- // listed here that `user_scope` does not also request reports as
190
- // `missing_scopes`, a hard failure that disables the provider's tools.
191
- // The wider bot set belongs to Socket Mode installs, which verify the live
192
- // `x-oauth-scopes` header against SLACK_REQUIRED_BOT_SCOPES in
193
- // channel-readiness-service.ts.
210
+ // Sent as the bot `scope` parameter on the same authorize request. This
211
+ // flow persists the `authed_user` token and stores `authed_user.scope` as
212
+ // `grantedScopes`; credential health measures that grant against
213
+ // `user_scope` below, never against this list, so a scope the stored
214
+ // token needs belongs in `user_scope`. The wider bot set belongs to Socket
215
+ // Mode installs, which verify the live `x-oauth-scopes` header against
216
+ // SLACK_REQUIRED_BOT_SCOPES in channel-readiness-service.ts.
194
217
  defaultScopes: [
195
218
  "channels:join",
196
219
  "channels:read",
@@ -212,19 +235,17 @@ export const PROVIDER_SEED_DATA: Record<
212
235
  // only credential this flow stores, so it acts as the installer for every
213
236
  // call including `chat.postMessage`. The manifest's user list is read-only
214
237
  // instead, since a Socket Mode install keeps a bot token beside it.
238
+ // `files:read` is what lets that token fetch a file shared in a message
239
+ // from files.slack.com. Credential health measures every stored grant
240
+ // against this list, so a scope added here reports each existing
241
+ // connection as `missing_scopes` until it reconnects: that is how a newly
242
+ // required scope reaches an install.
215
243
  authorizeParams: {
216
244
  user_scope:
217
- "channels:read,channels:history,groups:read,groups:history,im:read,im:history,im:write,mpim:read,mpim:history,users:read,chat:write,search:read,reactions:write",
245
+ "channels:read,channels:history,groups:read,groups:history,im:read,im:history,im:write,mpim:read,mpim:history,users:read,chat:write,search:read,reactions:write,files:read",
218
246
  },
219
247
  loopbackPort: 17322,
220
- injectionTemplates: [
221
- {
222
- hostPattern: "slack.com",
223
- injectionType: "header",
224
- headerName: "Authorization",
225
- valuePrefix: "Bearer ",
226
- },
227
- ],
248
+ injectionTemplates: SLACK_PROVIDER_INJECTION_TEMPLATES,
228
249
  appType: "Slack App",
229
250
  identityUrl: "https://slack.com/api/auth.test",
230
251
  identityOkField: "ok",
@@ -1194,14 +1215,7 @@ export const PROVIDER_SEED_DATA: Record<
1194
1215
  logoUrl:
1195
1216
  "https://cdn.jsdelivr.net/gh/glincker/thesvg@main/public/icons/slack/default.svg",
1196
1217
  defaultScopes: [],
1197
- injectionTemplates: [
1198
- {
1199
- hostPattern: "slack.com",
1200
- injectionType: "header",
1201
- headerName: "Authorization",
1202
- valuePrefix: "Bearer ",
1203
- },
1204
- ],
1218
+ injectionTemplates: SLACK_PROVIDER_INJECTION_TEMPLATES,
1205
1219
  },
1206
1220
 
1207
1221
  // The bot that sits in a server and talks to people there, which is a
@@ -17,6 +17,7 @@ import {
17
17
  wrapUntrustedContent,
18
18
  } from "../security/untrusted-content.js";
19
19
  import { getLogger } from "../util/logger.js";
20
+ import { safeStringSlice } from "../util/unicode.js";
20
21
  import { isLexicalBackfillComplete } from "./checkpoints.js";
21
22
  import { unseenAttentionStateConditions } from "./conversation-attention-store.js";
22
23
  import type { ConversationRow } from "./conversation-crud.js";
@@ -1443,8 +1444,7 @@ function buildExcerptFromText(
1443
1444
  if (!match) {
1444
1445
  // Neither the query nor any of its tokens is present (e.g. the lexical
1445
1446
  // index matched JSON structure instead); fall back to the text start.
1446
- return text
1447
- .slice(0, EXCERPT_WINDOW * 2)
1447
+ return safeStringSlice(text, 0, EXCERPT_WINDOW * 2)
1448
1448
  .replace(/\s+/g, " ")
1449
1449
  .trim();
1450
1450
  }
@@ -33,6 +33,116 @@ const SHUTDOWN_GRACE_MS = 5_000;
33
33
  const STDOUT_CAPTURE_LIMIT = 16_384;
34
34
  const STDERR_CAPTURE_LIMIT = 4_096;
35
35
 
36
+ /**
37
+ * Which step of a local start failed. `install` covers the download, checksum
38
+ * and extraction of the binary; `spawn` the OS refusing to run it; `exited`
39
+ * the process dying before `/readyz` answered; `not_ready` the readiness
40
+ * deadline passing with the process still alive (or, in external mode, the
41
+ * remote instance never answering).
42
+ */
43
+ export type QdrantStartFailureKind =
44
+ | "install"
45
+ | "spawn"
46
+ | "exited"
47
+ | "not_ready";
48
+
49
+ /**
50
+ * A failed `QdrantManager.start()`. The message keeps the captured output for
51
+ * the log line; the fields carry the same facts in a form a reporter can use
52
+ * without parsing that message.
53
+ */
54
+ export class QdrantStartError extends Error {
55
+ constructor(
56
+ message: string,
57
+ readonly kind: QdrantStartFailureKind,
58
+ readonly exitCode: number | null,
59
+ readonly stdout: string,
60
+ readonly stderr: string,
61
+ options?: ErrorOptions,
62
+ ) {
63
+ super(message, options);
64
+ this.name = "QdrantStartError";
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Budget for the `panic` string {@link describeQdrantStartFailure} emits, in
70
+ * the bytes the telemetry server counts: JSON with every code unit above 0x7E
71
+ * escaped as `\uXXXX` (see `jsonByteLength` in `telemetry-wire.generated.ts`).
72
+ * A quarter of `WATCHDOG_DETAIL_MAX_JSON_BYTES`, leaving the other fields and
73
+ * the event envelope far from the limit that silently drops the event.
74
+ */
75
+ const PANIC_REPORT_MAX_JSON_BYTES = 1_024;
76
+
77
+ /**
78
+ * Longest prefix of `text` whose server-side JSON size fits `maxBytes`. Each
79
+ * UTF-16 code unit above 0x7E costs six bytes (astral characters two units,
80
+ * so twelve); quotes, backslashes and control characters cost what
81
+ * `JSON.stringify` escapes them to. Counting characters instead would let a
82
+ * non-ASCII reason overshoot the budget six-fold.
83
+ */
84
+ function truncateToJsonBytes(text: string, maxBytes: number): string {
85
+ let bytes = 0;
86
+ for (let i = 0; i < text.length; i++) {
87
+ const unit = text.charCodeAt(i);
88
+ bytes += unit > 0x7e ? 6 : JSON.stringify(text[i]).length - 2;
89
+ if (bytes > maxBytes) {
90
+ return text.slice(0, i);
91
+ }
92
+ }
93
+ return text;
94
+ }
95
+
96
+ /** Qdrant's panic hook logs `Panic occurred <location>: <reason>` on stdout. */
97
+ const PANIC_MARKER = "Panic occurred";
98
+
99
+ /**
100
+ * Reduce a start failure to the metadata a `watchdog` telemetry event may
101
+ * carry: the failing step, the exit code, and Qdrant's own one-line reason.
102
+ *
103
+ * The reason is engine output, never conversation content, so it is in the
104
+ * same class as the SQLite `integrity_check` strings `db-integrity-sample.ts`
105
+ * already reports. The one thing in it that is not pure engine text is the
106
+ * absolute data directory, which is swapped for a placeholder. The panic hook
107
+ * prints the reason after the backtrace, so it is everything from the last
108
+ * marker on; when Qdrant died without panicking (a port collision logs a plain
109
+ * error) the last stdout line is the best available explanation. Capped by
110
+ * the server's own byte measure well inside the detail budget. Anything that is not a
111
+ * {@link QdrantStartError} reports as `unknown`, so a new throw site can never
112
+ * silently drop the event.
113
+ */
114
+ export function describeQdrantStartFailure(
115
+ err: unknown,
116
+ dataDir: string = getDataDir(),
117
+ ): {
118
+ kind: QdrantStartFailureKind | "unknown";
119
+ exit_code: number | null;
120
+ panic: string | null;
121
+ } {
122
+ if (!(err instanceof QdrantStartError)) {
123
+ return { kind: "unknown", exit_code: null, panic: null };
124
+ }
125
+ const stdout = err.stdout.trim();
126
+ let reason: string | null = null;
127
+ if (stdout) {
128
+ const marker = stdout.lastIndexOf(PANIC_MARKER);
129
+ reason =
130
+ marker >= 0
131
+ ? stdout.slice(marker)
132
+ : (stdout
133
+ .split("\n")
134
+ .filter((line) => line.trim())
135
+ .at(-1) ?? null);
136
+ }
137
+ if (reason) {
138
+ reason = truncateToJsonBytes(
139
+ reason.split(dataDir).join("<data>"),
140
+ PANIC_REPORT_MAX_JSON_BYTES,
141
+ );
142
+ }
143
+ return { kind: err.kind, exit_code: err.exitCode, panic: reason };
144
+ }
145
+
36
146
  export function resolveQdrantReleaseAsset(
37
147
  os: NodeJS.Platform,
38
148
  cpu: string,
@@ -144,7 +254,11 @@ export class QdrantManager {
144
254
 
145
255
  const binaryPath = this.getBinaryPath();
146
256
  if (!existsSync(binaryPath)) {
147
- await this.installBinary(binaryPath);
257
+ try {
258
+ await this.installBinary(binaryPath);
259
+ } catch (err) {
260
+ throw this.startError(err, "install");
261
+ }
148
262
  }
149
263
 
150
264
  const spawnPath = this.ensureVellumSymlink(binaryPath);
@@ -154,21 +268,26 @@ export class QdrantManager {
154
268
  "Starting Qdrant",
155
269
  );
156
270
 
157
- const proc = Bun.spawn({
158
- cmd: [spawnPath],
159
- windowsHide: true,
160
- env: {
161
- ...process.env,
162
- QDRANT__SERVICE__HOST: this.host,
163
- QDRANT__SERVICE__HTTP_PORT: String(this.port),
164
- QDRANT__SERVICE__GRPC_PORT: "0", // disable gRPC
165
- QDRANT__TELEMETRY_DISABLED: "true",
166
- QDRANT__STORAGE__STORAGE_PATH: this.storagePath,
167
- QDRANT__LOG_LEVEL: "WARN",
168
- },
169
- stdout: "pipe",
170
- stderr: "pipe",
171
- });
271
+ let proc: Subprocess<"ignore", "pipe", "pipe">;
272
+ try {
273
+ proc = Bun.spawn({
274
+ cmd: [spawnPath],
275
+ windowsHide: true,
276
+ env: {
277
+ ...process.env,
278
+ QDRANT__SERVICE__HOST: this.host,
279
+ QDRANT__SERVICE__HTTP_PORT: String(this.port),
280
+ QDRANT__SERVICE__GRPC_PORT: "0", // disable gRPC
281
+ QDRANT__TELEMETRY_DISABLED: "true",
282
+ QDRANT__STORAGE__STORAGE_PATH: this.storagePath,
283
+ QDRANT__LOG_LEVEL: "WARN",
284
+ },
285
+ stdout: "pipe",
286
+ stderr: "pipe",
287
+ });
288
+ } catch (err) {
289
+ throw this.startError(err, "spawn");
290
+ }
172
291
  this.process = proc;
173
292
  this.drainOutputFrom(proc.stdout, proc.stderr);
174
293
 
@@ -311,6 +430,24 @@ export class QdrantManager {
311
430
  );
312
431
  }
313
432
 
433
+ /**
434
+ * Wrap a failure from a start step in a {@link QdrantStartError}. Errors the
435
+ * manager already classified pass through untouched.
436
+ */
437
+ private startError(err: unknown, kind: QdrantStartFailureKind): Error {
438
+ if (err instanceof QdrantStartError) {
439
+ return err;
440
+ }
441
+ return new QdrantStartError(
442
+ err instanceof Error ? err.message : String(err),
443
+ kind,
444
+ null,
445
+ this.stdoutBuffer,
446
+ this.stderrBuffer,
447
+ { cause: err },
448
+ );
449
+ }
450
+
314
451
  private async waitForReady(): Promise<void> {
315
452
  const start = Date.now();
316
453
  // Build a single exited-promise once so each race reuses the same handle.
@@ -327,9 +464,13 @@ export class QdrantManager {
327
464
 
328
465
  const throwOnExit = async (code: number): Promise<never> => {
329
466
  await this.outputDrained;
330
- throw new Error(
467
+ throw new QdrantStartError(
331
468
  `Qdrant process exited with code ${code} before becoming ready` +
332
469
  this.formatCapturedOutput(),
470
+ "exited",
471
+ code,
472
+ this.stdoutBuffer,
473
+ this.stderrBuffer,
333
474
  );
334
475
  };
335
476
 
@@ -363,9 +504,13 @@ export class QdrantManager {
363
504
  await throwOnExit(sleepOutcome.code);
364
505
  }
365
506
  }
366
- throw new Error(
507
+ throw new QdrantStartError(
367
508
  `Qdrant did not become ready within ${this.readyzTimeoutMs}ms at ${this.url}` +
368
509
  this.formatCapturedOutput(),
510
+ "not_ready",
511
+ null,
512
+ this.stdoutBuffer,
513
+ this.stderrBuffer,
369
514
  );
370
515
  }
371
516
 
@@ -115,6 +115,11 @@ For everything else in your review window, use the \`remember\` tool on facts, p
115
115
  expect(out).toContain(
116
116
  "\n---\n\nIf your review window contains a PROCEDURE you actually carried out",
117
117
  );
118
+ // An UPDATE is announced by a notice whose only account of the change is
119
+ // what the pass passes here, so the instruction has to ask for it.
120
+ expect(out).toContain(
121
+ "and pass `change_summary` (the update is rejected without it): one or two short sentences (under 200 characters)",
122
+ );
118
123
  expect(
119
124
  out.endsWith(
120
125
  "skills are for executed, reusable procedures, not for facts.\n",
@@ -7,6 +7,7 @@ import type {
7
7
  import { getConfiguredProvider } from "@vellumai/plugin-api";
8
8
 
9
9
  import { redactSecrets } from "../../../../security/secret-scanner.js";
10
+ import { safeStringSlice } from "../host-utils.js";
10
11
  import {
11
12
  buildRecallAgentPromptBundle,
12
13
  FINISH_RECALL_TOOL_DEFINITION,
@@ -862,9 +863,9 @@ function compactText(text: string, maxChars: number): string {
862
863
  return compacted;
863
864
  }
864
865
  if (maxChars <= 3) {
865
- return compacted.slice(0, maxChars);
866
+ return safeStringSlice(compacted, 0, maxChars);
866
867
  }
867
- return `${compacted.slice(0, maxChars - 3).trimEnd()}...`;
868
+ return `${safeStringSlice(compacted, 0, maxChars - 3).trimEnd()}...`;
868
869
  }
869
870
 
870
871
  function dedupeEvidenceById(
@@ -1,3 +1,4 @@
1
+ import { safeStringSlice } from "../host-utils.js";
1
2
  import type {
2
3
  DeterministicRecallSearchResult,
3
4
  DeterministicRecallSourceNote,
@@ -139,9 +140,9 @@ function compactText(text: string, maxChars: number): string {
139
140
  return compacted;
140
141
  }
141
142
  if (maxChars <= 3) {
142
- return compacted.slice(0, maxChars);
143
+ return safeStringSlice(compacted, 0, maxChars);
143
144
  }
144
- return `${compacted.slice(0, maxChars - 3).trimEnd()}...`;
145
+ return `${safeStringSlice(compacted, 0, maxChars - 3).trimEnd()}...`;
145
146
  }
146
147
 
147
148
  function dedupeStrings(values: readonly string[]): string[] {
@@ -27,6 +27,7 @@ import { readdir, readFile, realpath, stat } from "node:fs/promises";
27
27
  import { extname, join } from "node:path";
28
28
 
29
29
  import { embedWithRetry } from "../../../../../persistence/embeddings/embed.js";
30
+ import { safeStringSlice } from "../../host-utils.js";
30
31
  import { getLogger } from "../../logging.js";
31
32
  import { isPathInsideRoot } from "../../path-containment.js";
32
33
  import { getEdgeIndex } from "../../substrate/edge-index.js";
@@ -518,9 +519,11 @@ function buildLexicalExcerpt(
518
519
  if (focusedLine.length <= MEMORY_V2_LEXICAL_EXCERPT_MAX_CHARS) {
519
520
  return focusedLine;
520
521
  }
521
- return `${focusedLine
522
- .slice(0, MEMORY_V2_LEXICAL_EXCERPT_MAX_CHARS - 3)
523
- .trimEnd()}...`;
522
+ return `${safeStringSlice(
523
+ focusedLine,
524
+ 0,
525
+ MEMORY_V2_LEXICAL_EXCERPT_MAX_CHARS - 3,
526
+ ).trimEnd()}...`;
524
527
  }
525
528
 
526
529
  function toLexicalEvidence(match: MemoryV2LexicalMatch): RecallEvidence {