@vellumai/assistant 0.11.10-dev.202609091315.2a4dd13 → 0.11.10-dev.202609091618.e0e8e78

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 (65) hide show
  1. package/AGENTS.md +1 -1
  2. package/openapi.yaml +4 -1
  3. package/package.json +2 -1
  4. package/scripts/probe-skill-retrieval.ts +498 -0
  5. package/src/__tests__/anthropic-provider.test.ts +60 -0
  6. package/src/__tests__/conversation-error.test.ts +38 -0
  7. package/src/__tests__/host-app-control-proxy.test.ts +2 -2
  8. package/src/__tests__/host-app-control-routes.test.ts +41 -0
  9. package/src/__tests__/host-bash-routes.test.ts +30 -1
  10. package/src/__tests__/host-browser-routes.test.ts +34 -0
  11. package/src/__tests__/host-cu-routes-targeted.test.ts +29 -0
  12. package/src/__tests__/host-file-routes-targeted.test.ts +29 -0
  13. package/src/__tests__/host-proxy-base.test.ts +1 -0
  14. package/src/__tests__/host-transfer-routes-targeted.test.ts +86 -0
  15. package/src/__tests__/memory-retrieval-hook.test.ts +15 -0
  16. package/src/__tests__/provider-catalog-visibility.test.ts +2 -2
  17. package/src/__tests__/schedule-routes.test.ts +30 -1
  18. package/src/__tests__/skills-install-extract.test.ts +26 -0
  19. package/src/__tests__/skills-install-staging.test.ts +11 -2
  20. package/src/archive/ustar-size.test.ts +32 -0
  21. package/src/archive/ustar-size.ts +23 -0
  22. package/src/cli/lib/bundled-marketplace.json +1 -1
  23. package/src/cli/lib/install-from-platform.ts +8 -10
  24. package/src/config/bundled-skills/screen-annotation/SKILL.md +60 -21
  25. package/src/config/bundled-skills/screen-annotation/TOOLS.json +7 -7
  26. package/src/config/feature-flag-registry.json +8 -0
  27. package/src/config/skills.ts +2 -2
  28. package/src/daemon/conversation-error.ts +20 -7
  29. package/src/daemon/host-app-control-proxy.ts +2 -0
  30. package/src/daemon/host-bash-proxy.ts +1 -0
  31. package/src/daemon/host-cu-proxy.ts +6 -6
  32. package/src/daemon/host-file-proxy.ts +6 -6
  33. package/src/daemon/host-proxy-base.ts +10 -9
  34. package/src/daemon/host-transfer-proxy.ts +21 -24
  35. package/src/notifications/__tests__/home-feed-side-effect.test.ts +27 -0
  36. package/src/notifications/home-feed-side-effect.ts +14 -3
  37. package/src/oauth/seed-providers.ts +3 -2
  38. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +8 -0
  39. package/src/plugins/defaults/memory/substrate/__tests__/skill-content.test.ts +49 -3
  40. package/src/plugins/defaults/memory/substrate/skill-content.ts +18 -3
  41. package/src/providers/anthropic/client.ts +9 -4
  42. package/src/providers/model-catalog.ts +22 -2
  43. package/src/providers/openai/__tests__/api-error-normalization.test.ts +50 -0
  44. package/src/providers/openai/api-error-normalization.ts +18 -3
  45. package/src/runtime/__tests__/background-job-runner.test.ts +42 -4
  46. package/src/runtime/auth/__tests__/guard-tests.test.ts +0 -2
  47. package/src/runtime/auth/same-actor.ts +29 -5
  48. package/src/runtime/background-job-runner.ts +38 -29
  49. package/src/runtime/migrations/vbundle-validator.ts +3 -3
  50. package/src/runtime/pending-interactions.ts +4 -5
  51. package/src/runtime/routes/document-comments-routes.ts +8 -2
  52. package/src/runtime/routes/host-app-control-routes.ts +10 -36
  53. package/src/runtime/routes/host-bash-routes.ts +11 -45
  54. package/src/runtime/routes/host-browser-routes.ts +24 -0
  55. package/src/runtime/routes/host-cu-routes.ts +11 -45
  56. package/src/runtime/routes/host-file-routes.ts +11 -44
  57. package/src/runtime/routes/host-proxy-result-binding.ts +57 -0
  58. package/src/runtime/routes/host-transfer-routes.ts +33 -25
  59. package/src/runtime/routes/schedule-routes.ts +15 -1
  60. package/src/skills/catalog-install.ts +40 -5
  61. package/src/tools/terminal/__tests__/safe-env.test.ts +17 -0
  62. package/src/tools/terminal/safe-env.ts +3 -2
  63. package/src/util/provider-error-patterns.ts +34 -0
  64. package/src/watcher/__tests__/engine.test.ts +5 -2
  65. package/src/watcher/engine.ts +7 -4
package/AGENTS.md CHANGED
@@ -16,7 +16,7 @@ When you introduce a new env var that the assistant process needs to read at run
16
16
 
17
17
  **Default to including it.** If the var doesn't contain secrets (e.g. a URL, a feature flag, a path, a mode string), add it. Only omit it if it carries credential material (tokens, passwords, private keys) — those must stay isolated to CES.
18
18
 
19
- `CES_LOCAL_SOCKET` is intentionally included despite the socket exposing credential RPCs — assistant subprocesses are expected to reach CES. Credential protection is rules-based access control inside CES, not socket-path secrecy (see root `AGENTS.md`).
19
+ `CES_LOCAL_SOCKET` is intentionally included despite the socket exposing credential RPCs: assistant subprocesses are expected to reach CES. Credential protection is rules-based access control inside CES, not socket-path secrecy (see root `AGENTS.md`). Do not forward `CES_SERVICE_TOKEN` or `CES_CREDENTIAL_URL`: the HTTP bearer is a vault secret and must stay in the assistant process.
20
20
 
21
21
  ## Daemon startup philosophy
22
22
 
package/openapi.yaml CHANGED
@@ -29048,7 +29048,8 @@ paths:
29048
29048
  summary: Run schedule now
29049
29049
  description:
29050
29050
  Trigger an immediate execution of a schedule. A plugin-sourced schedule is rejected with a 400 when its
29051
- plugin is disabled or no longer declares it.
29051
+ plugin is disabled or no longer declares it. Returns 409 while a drain quiesce lease is active so run-now cannot
29052
+ start work the shutdown snapshot would miss.
29052
29053
  tags:
29053
29054
  - schedules
29054
29055
  parameters:
@@ -29244,6 +29245,8 @@ paths:
29244
29245
  required:
29245
29246
  - schedules
29246
29247
  additionalProperties: false
29248
+ "409":
29249
+ description: A drain quiesce lease is active, so run-now is not starting new work.
29247
29250
  /v1/schedules/{id}/runs:
29248
29251
  get:
29249
29252
  operationId: schedules_by_id_runs_get
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.10-dev.202609091315.2a4dd13",
3
+ "version": "0.11.10-dev.202609091618.e0e8e78",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,6 +17,7 @@
17
17
  "generate:openapi": "bun run scripts/generate-openapi.ts",
18
18
  "sync:llm-catalog": "bun run scripts/sync-llm-catalog.ts",
19
19
  "sync:web-search-catalog": "bun run scripts/sync-web-search-catalog.ts",
20
+ "probe:skill-retrieval": "bun run scripts/probe-skill-retrieval.ts",
20
21
  "format": "prettier --write .",
21
22
  "format:check": "prettier --check .",
22
23
  "lint": "eslint",
@@ -0,0 +1,498 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Skill retrieval probe: rank skill capability cards against a query offline.
3
+ //
4
+ // Skills are surfaced to a turn by embedding one capability card per skill into
5
+ // the concept-page collection and retrieving against it. The card is built from
6
+ // SKILL.md frontmatter only (`description` + `activation-hints` + `avoid-when`),
7
+ // never the body, and is hard-truncated to a character budget. This script
8
+ // builds the same cards from SKILL.md on disk, embeds them with the assistant's
9
+ // local backend, and prints the ranking, so frontmatter wording can be validated
10
+ // without a running assistant. `--provider configured` ranks in the workspace's
11
+ // own embedding space instead, which needs a host that can reach its provider.
12
+ //
13
+ // Two limits on what a run proves. The dense lane is one of several retrieval
14
+ // lanes and its pool is handed to an LLM selector, so a skill ranking well here
15
+ // is necessary for it to be surfaced, not sufficient. And the pool is every
16
+ // SKILL.md on disk that this platform can run, where a real workspace also
17
+ // resolves feature flags, plugin ownership, and per-skill enabled state, so a
18
+ // host with skills disabled sees a slightly smaller field than this.
19
+ //
20
+ // Usage (from assistant/):
21
+ // bun run scripts/probe-skill-retrieval.ts -q "help me connect stripe link"
22
+ // bun run scripts/probe-skill-retrieval.ts --queries queries.json --top 10
23
+ // bun run scripts/probe-skill-retrieval.ts -q "..." --only stripe
24
+ // bun run scripts/probe-skill-retrieval.ts --queries q.json --save before.json
25
+ // ...edit SKILL.md...
26
+ // bun run scripts/probe-skill-retrieval.ts --queries q.json --baseline before.json
27
+ // ---------------------------------------------------------------------------
28
+
29
+ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
30
+ import { join, resolve } from "node:path";
31
+
32
+ import { getConfig } from "../src/config/loader.js";
33
+ import {
34
+ type ParsedFrontmatter,
35
+ parseFrontmatter,
36
+ } from "../src/config/skills.js";
37
+ import {
38
+ ALWAYS_CANDIDATE_CARD_CHARS,
39
+ augmentMcpSetupDescription,
40
+ buildSkillContent,
41
+ DEFAULT_CARD_CHARS,
42
+ renderSkillCard,
43
+ } from "../src/plugins/defaults/memory/substrate/skill-content.js";
44
+ import { filterSkillsByPlatform } from "../src/skills/platform-compatibility.js";
45
+
46
+ interface ProbeOptions {
47
+ queries: string[];
48
+ skillDirs: string[];
49
+ top: number;
50
+ only?: string;
51
+ json: boolean;
52
+ truncationReport: boolean;
53
+ platform: NodeJS.Platform;
54
+ useConfiguredProvider: boolean;
55
+ save?: string;
56
+ baseline?: string;
57
+ }
58
+
59
+ /** `--platform` takes the skill-facing names, not node's `process.platform`. */
60
+ const PLATFORM_ALIASES: Record<string, NodeJS.Platform> = {
61
+ macos: "darwin",
62
+ windows: "win32",
63
+ linux: "linux",
64
+ };
65
+
66
+ interface Card {
67
+ name: string;
68
+ text: string;
69
+ budget: number;
70
+ /** Characters the budget cut from the end of the card, 0 when it fits. */
71
+ lostChars: number;
72
+ }
73
+
74
+ interface Ranked {
75
+ name: string;
76
+ score: number;
77
+ rank: number;
78
+ }
79
+
80
+ /** An embedding backend plus the teardown that lets the process exit. */
81
+ interface Embedder {
82
+ embed: (texts: string[]) => Promise<number[][]>;
83
+ dispose: () => Promise<void> | void;
84
+ }
85
+
86
+ /** Score deltas below this are rounding, not signal, and are not reported. */
87
+ const DELTA_EPSILON = 0.0005;
88
+
89
+ const REPO_ROOT = resolve(import.meta.dirname, "..", "..");
90
+
91
+ const DEFAULT_SKILL_DIRS = [
92
+ join(REPO_ROOT, "skills"),
93
+ join(REPO_ROOT, "assistant", "src", "config", "bundled-skills"),
94
+ ];
95
+
96
+ function usage(): never {
97
+ console.error(
98
+ [
99
+ "Usage: bun run scripts/probe-skill-retrieval.ts [options]",
100
+ "",
101
+ " -q, --query <text> Query to rank (repeatable)",
102
+ " --queries <file> JSON array of queries, or one query per line",
103
+ " --skills-dir <dir> Directory of <skill>/SKILL.md (repeatable)",
104
+ " --top <n> Rows to print per query (default 8)",
105
+ " --only <substr> Always print skills matching this substring",
106
+ " --save <file> Write scores to a JSON baseline",
107
+ " --baseline <file> Compare against a saved baseline",
108
+ " --json Emit JSON instead of a table",
109
+ " --truncation-report List every card the budget truncates",
110
+ " --platform <name> Rank as macos | windows | linux (default: this host)",
111
+ " --provider <name> local (default, no daemon) | configured (workspace provider)",
112
+ ].join("\n"),
113
+ );
114
+ process.exit(1);
115
+ }
116
+
117
+ function parseArgs(argv: string[]): ProbeOptions {
118
+ const queries: string[] = [];
119
+ const skillDirs: string[] = [];
120
+ let top = 8;
121
+ let only: string | undefined;
122
+ let json = false;
123
+ let truncationReport = false;
124
+ let platform: NodeJS.Platform = process.platform;
125
+ let useConfiguredProvider = false;
126
+ let save: string | undefined;
127
+ let baseline: string | undefined;
128
+
129
+ for (let i = 0; i < argv.length; i++) {
130
+ const arg = argv[i];
131
+ const next = (): string => {
132
+ const value = argv[++i];
133
+ if (value === undefined) {
134
+ usage();
135
+ }
136
+ return value;
137
+ };
138
+ switch (arg) {
139
+ case "-q":
140
+ case "--query":
141
+ queries.push(next());
142
+ break;
143
+ case "--queries":
144
+ queries.push(...readQueryFile(next()));
145
+ break;
146
+ case "--skills-dir":
147
+ skillDirs.push(resolve(next()));
148
+ break;
149
+ case "--top":
150
+ top = Number.parseInt(next(), 10);
151
+ break;
152
+ case "--only":
153
+ only = next();
154
+ break;
155
+ case "--save":
156
+ save = resolve(next());
157
+ break;
158
+ case "--baseline":
159
+ baseline = resolve(next());
160
+ break;
161
+ case "--json":
162
+ json = true;
163
+ break;
164
+ case "--truncation-report":
165
+ truncationReport = true;
166
+ break;
167
+ case "--provider": {
168
+ const value = next();
169
+ if (value !== "local" && value !== "configured") {
170
+ console.error(
171
+ `Unknown --provider "${value}". Expected "local" or "configured".`,
172
+ );
173
+ process.exit(1);
174
+ }
175
+ useConfiguredProvider = value === "configured";
176
+ break;
177
+ }
178
+ case "--platform": {
179
+ const value = next();
180
+ const resolved = PLATFORM_ALIASES[value];
181
+ if (!resolved) {
182
+ console.error(
183
+ `Unknown --platform "${value}". Expected one of: ${Object.keys(PLATFORM_ALIASES).join(", ")}`,
184
+ );
185
+ process.exit(1);
186
+ }
187
+ platform = resolved;
188
+ break;
189
+ }
190
+ default:
191
+ usage();
192
+ }
193
+ }
194
+
195
+ if (queries.length === 0 || !Number.isFinite(top) || top < 1) {
196
+ usage();
197
+ }
198
+
199
+ return {
200
+ queries,
201
+ skillDirs: skillDirs.length > 0 ? skillDirs : DEFAULT_SKILL_DIRS,
202
+ top,
203
+ only,
204
+ json,
205
+ truncationReport,
206
+ platform,
207
+ useConfiguredProvider,
208
+ save,
209
+ baseline,
210
+ };
211
+ }
212
+
213
+ function readQueryFile(path: string): string[] {
214
+ const raw = readFileSync(resolve(path), "utf8");
215
+ const trimmed = raw.trim();
216
+ if (trimmed.startsWith("[")) {
217
+ const parsed: unknown = JSON.parse(trimmed);
218
+ if (!Array.isArray(parsed)) {
219
+ throw new Error(`${path}: JSON must be an array of query strings`);
220
+ }
221
+ return parsed.map(String);
222
+ }
223
+ return trimmed
224
+ .split("\n")
225
+ .map((line) => line.trim())
226
+ .filter((line) => line.length > 0 && !line.startsWith("#"));
227
+ }
228
+
229
+ function loadSkills(
230
+ dirs: string[],
231
+ platform: NodeJS.Platform,
232
+ ): ParsedFrontmatter[] {
233
+ const byName = new Map<string, ParsedFrontmatter>();
234
+ for (const dir of dirs) {
235
+ let entries: string[];
236
+ try {
237
+ entries = readdirSync(dir);
238
+ } catch {
239
+ console.error(`warning: skipping unreadable skills dir ${dir}`);
240
+ continue;
241
+ }
242
+ for (const entry of entries) {
243
+ const skillPath = join(dir, entry, "SKILL.md");
244
+ try {
245
+ if (!statSync(skillPath).isFile()) {
246
+ continue;
247
+ }
248
+ } catch {
249
+ continue;
250
+ }
251
+ const parsed = parseFrontmatter(
252
+ readFileSync(skillPath, "utf8"),
253
+ skillPath,
254
+ );
255
+ if (parsed) {
256
+ byName.set(parsed.name, parsed);
257
+ }
258
+ }
259
+ }
260
+ // Production never seeds a card for a skill the host cannot run, so leaving
261
+ // the other platforms' skills in would put candidates in the pool that no
262
+ // real retrieval could return, shifting every rank below them.
263
+ const eligible = filterSkillsByPlatform([...byName.values()], platform);
264
+ return eligible.sort((a, b) => a.name.localeCompare(b.name));
265
+ }
266
+
267
+ function buildCard(skill: ParsedFrontmatter): Card {
268
+ const budget = skill.alwaysCandidate
269
+ ? ALWAYS_CANDIDATE_CARD_CHARS
270
+ : DEFAULT_CARD_CHARS;
271
+ // Mirrors `buildInstalledSkillCards`: mcp-setup's card carries the configured
272
+ // server names, so a query naming a server has to score against them here too.
273
+ const input = augmentMcpSetupDescription({
274
+ id: skill.name,
275
+ displayName: skill.displayName,
276
+ description: skill.description,
277
+ activationHints: skill.activationHints,
278
+ avoidWhen: skill.avoidWhen,
279
+ });
280
+ const text = buildSkillContent(input, budget);
281
+ // A card at exactly the budget was not truncated, so compare against the
282
+ // untruncated render rather than testing `length >= budget`.
283
+ const full = renderSkillCard(input, budget);
284
+ return {
285
+ name: skill.name,
286
+ text,
287
+ budget,
288
+ lostChars: full.length - text.length,
289
+ };
290
+ }
291
+
292
+ function cosine(a: number[], b: number[]): number {
293
+ let dot = 0;
294
+ let normA = 0;
295
+ let normB = 0;
296
+ for (let i = 0; i < a.length; i++) {
297
+ dot += a[i] * b[i];
298
+ normA += a[i] * a[i];
299
+ normB += b[i] * b[i];
300
+ }
301
+ const denom = Math.sqrt(normA) * Math.sqrt(normB);
302
+ return denom === 0 ? 0 : dot / denom;
303
+ }
304
+
305
+ function rank(
306
+ queryVec: number[],
307
+ cards: Card[],
308
+ cardVecs: number[][],
309
+ ): Ranked[] {
310
+ return cards
311
+ .map((card, i) => ({
312
+ name: card.name,
313
+ score: cosine(queryVec, cardVecs[i]),
314
+ }))
315
+ .sort((a, b) => b.score - a.score)
316
+ .map((row, i) => ({ ...row, rank: i + 1 }));
317
+ }
318
+
319
+ function formatDelta(
320
+ current: Ranked,
321
+ baseline: Record<string, number> | undefined,
322
+ ): string {
323
+ if (!baseline) {
324
+ return "";
325
+ }
326
+ const before = baseline[current.name];
327
+ if (before === undefined) {
328
+ return " (new)";
329
+ }
330
+ const delta = current.score - before;
331
+ if (Math.abs(delta) < DELTA_EPSILON) {
332
+ return "";
333
+ }
334
+ return ` (${delta > 0 ? "+" : ""}${delta.toFixed(4)})`;
335
+ }
336
+
337
+ /**
338
+ * Embed through the provider the workspace config selects, which is what
339
+ * production ranks in, and fall back to the in-process local backend when that
340
+ * provider is unreachable (no key, no network, billing breaker open). Scores
341
+ * are not comparable across embedding models, so the provider actually used is
342
+ * always reported rather than assumed.
343
+ */
344
+ /**
345
+ * Pick the embedding space the ranking is measured in.
346
+ *
347
+ * Local is the default because it is the only backend that runs with no
348
+ * daemon: `embedWithBackend` resolves provider credentials through the
349
+ * credential store, which blocks when no assistant is running. `--provider
350
+ * configured` opts into the full production path on a host that has one.
351
+ *
352
+ * Scores are not comparable across embedding models, so the provider actually
353
+ * used is reported rather than assumed, and a saved baseline should only be
354
+ * diffed against a run that used the same one.
355
+ */
356
+ async function resolveEmbedder(
357
+ config: ReturnType<typeof getConfig>,
358
+ useConfiguredProvider: boolean,
359
+ quiet: boolean,
360
+ ): Promise<Embedder> {
361
+ const announce = (message: string): void => {
362
+ if (!quiet) {
363
+ console.error(message);
364
+ }
365
+ };
366
+ if (useConfiguredProvider) {
367
+ // Imported here rather than at module scope: the memory embeddings module
368
+ // pulls in the Qdrant client, whose import-time setup stalls with no
369
+ // assistant running, which would hang the local path too.
370
+ const { embedWithBackend } =
371
+ await import("../src/plugins/defaults/memory/embeddings.js");
372
+ const probe = await embedWithBackend(config, ["probe"]);
373
+ announce(`Embedding with ${probe.provider} / ${probe.model}`);
374
+ const { shutdownEmbeddingBackends } =
375
+ await import("../src/persistence/embeddings/embedding-backend.js");
376
+ return {
377
+ embed: async (texts) => (await embedWithBackend(config, texts)).vectors,
378
+ dispose: () => shutdownEmbeddingBackends(),
379
+ };
380
+ }
381
+ const localModel = config.memory.embeddings.localModel;
382
+ announce(
383
+ `Embedding with local / ${localModel}. Pass --provider configured to rank in the workspace's own embedding space.`,
384
+ );
385
+ const { LocalEmbeddingBackend } =
386
+ await import("../src/persistence/embeddings/embedding-local.js");
387
+ const backend = new LocalEmbeddingBackend(localModel);
388
+ return {
389
+ embed: (texts) => backend.embed(texts),
390
+ // The backend is constructed here rather than handed out by
391
+ // `selectEmbeddingBackend`, so the shared shutdown path does not know about
392
+ // it. A one-shot script has nothing to drain, so the worker is killed
393
+ // outright: `dispose()` only closes it once idle, which leaves it running
394
+ // and the process alive.
395
+ dispose: () => {
396
+ backend.terminateNow();
397
+ },
398
+ };
399
+ }
400
+
401
+ async function main(): Promise<void> {
402
+ const options = parseArgs(process.argv.slice(2));
403
+ const skills = loadSkills(options.skillDirs, options.platform);
404
+ if (skills.length === 0) {
405
+ throw new Error(
406
+ `No SKILL.md files found under: ${options.skillDirs.join(", ")}`,
407
+ );
408
+ }
409
+ const cards = skills.map(buildCard);
410
+
411
+ const truncated = cards
412
+ .filter((card) => card.lostChars > 0)
413
+ .sort((a, b) => b.lostChars - a.lostChars);
414
+ if (truncated.length > 0 && !options.json) {
415
+ console.error(
416
+ `${truncated.length} of ${cards.length} cards overrun their budget and lose trailing hints` +
417
+ (options.truncationReport
418
+ ? ":"
419
+ : " (--truncation-report to list them)"),
420
+ );
421
+ if (options.truncationReport) {
422
+ for (const card of truncated) {
423
+ console.error(
424
+ ` ${card.name}: ${card.budget + card.lostChars}/${card.budget} chars, ${card.lostChars} lost`,
425
+ );
426
+ }
427
+ }
428
+ }
429
+
430
+ const baseline: Record<string, Record<string, number>> | undefined =
431
+ options.baseline
432
+ ? JSON.parse(readFileSync(options.baseline, "utf8"))
433
+ : undefined;
434
+
435
+ // Embed through the same entry point production uses, so the provider the
436
+ // workspace config selects is the provider the ranking is measured in.
437
+ // Scores are not comparable across embedding models, which is why the
438
+ // provider and model are reported alongside them.
439
+ const config = getConfig();
440
+ const embedder = await resolveEmbedder(
441
+ config,
442
+ options.useConfiguredProvider,
443
+ options.json,
444
+ );
445
+ const embed = embedder.embed;
446
+ const results: Record<string, Record<string, number>> = {};
447
+
448
+ try {
449
+ const cardVecs = await embed(cards.map((card) => card.text));
450
+ for (const query of options.queries) {
451
+ const [queryVec] = await embed([query]);
452
+ const ranked = rank(queryVec, cards, cardVecs);
453
+ results[query] = Object.fromEntries(
454
+ ranked.map((row) => [row.name, row.score]),
455
+ );
456
+
457
+ if (options.json) {
458
+ continue;
459
+ }
460
+
461
+ console.log(`\nQ: ${query}`);
462
+ const shown = new Set<string>();
463
+ for (const row of ranked.slice(0, options.top)) {
464
+ shown.add(row.name);
465
+ console.log(
466
+ ` ${String(row.rank).padStart(3)}. ${row.score.toFixed(4)} ${row.name}${formatDelta(row, baseline?.[query])}`,
467
+ );
468
+ }
469
+ if (options.only) {
470
+ for (const row of ranked) {
471
+ if (!shown.has(row.name) && row.name.includes(options.only)) {
472
+ console.log(
473
+ ` ${String(row.rank).padStart(3)}. ${row.score.toFixed(4)} ${row.name}${formatDelta(row, baseline?.[query])}`,
474
+ );
475
+ }
476
+ }
477
+ }
478
+ }
479
+ } finally {
480
+ const { shutdownEmbeddingBackends } =
481
+ await import("../src/persistence/embeddings/embedding-backend.js");
482
+ await shutdownEmbeddingBackends();
483
+ }
484
+
485
+ if (options.json) {
486
+ console.log(JSON.stringify(results, null, 2));
487
+ }
488
+ if (options.save) {
489
+ writeFileSync(options.save, `${JSON.stringify(results, null, 2)}\n`);
490
+ console.error(`\nSaved baseline to ${options.save}`);
491
+ }
492
+ }
493
+
494
+ await main();
495
+
496
+ // The embedding worker leaves handles the runtime still counts as live work, so
497
+ // a one-shot run would otherwise sit at an idle event loop after printing.
498
+ process.exit(0);
@@ -3194,6 +3194,66 @@ describe("AnthropicProvider — Haiku Model Gating", () => {
3194
3194
  // to the request at all.
3195
3195
  expect(lastStreamParams!.output_config).toBeUndefined();
3196
3196
  });
3197
+
3198
+ test("effort is omitted for Sonnet 4.5, which rejects the parameter", async () => {
3199
+ const sonnet45Provider = new AnthropicProvider(
3200
+ "sk-ant-test",
3201
+ "claude-sonnet-4-5-20250929",
3202
+ );
3203
+ await sonnet45Provider.sendMessage([userMsg("Hi")], {
3204
+ systemPrompt: "You are helpful.",
3205
+ config: { effort: "high" },
3206
+ });
3207
+
3208
+ // Sonnet 4.5 400s on `output_config.effort` ("This model does not
3209
+ // support the effort parameter"), so a profile effort must be dropped
3210
+ // on the wire rather than forwarded.
3211
+ expect(lastStreamParams!.output_config).toBeUndefined();
3212
+ });
3213
+
3214
+ test("effort is omitted for OpenRouter's dotted Sonnet 4.5 id", async () => {
3215
+ // OpenRouter delegates `anthropic/*` models to this provider under
3216
+ // dotted ids, so the exclusion must survive that spelling.
3217
+ const openRouterProvider = new AnthropicProvider(
3218
+ "sk-or-test",
3219
+ "anthropic/claude-sonnet-4.5",
3220
+ );
3221
+ await openRouterProvider.sendMessage([userMsg("Hi")], {
3222
+ systemPrompt: "You are helpful.",
3223
+ config: { effort: "high" },
3224
+ });
3225
+
3226
+ expect(lastStreamParams!.output_config).toBeUndefined();
3227
+ });
3228
+
3229
+ test("effort is forwarded for Opus 4.5, which accepts the parameter", async () => {
3230
+ // Opus 4.5 shares Sonnet 4.5's generation (and its
3231
+ // adaptiveThinkingUnsupported flag) but accepts effort on the wire, so
3232
+ // the exclusion must stay narrow rather than family-wide.
3233
+ const opus45Provider = new AnthropicProvider(
3234
+ "sk-ant-test",
3235
+ "claude-opus-4-5-20251101",
3236
+ );
3237
+ await opus45Provider.sendMessage([userMsg("Hi")], {
3238
+ systemPrompt: "You are helpful.",
3239
+ config: { effort: "high" },
3240
+ });
3241
+
3242
+ expect(lastStreamParams!.output_config).toEqual({ effort: "high" });
3243
+ });
3244
+
3245
+ test("effort is forwarded for Sonnet 4.6", async () => {
3246
+ const sonnet46Provider = new AnthropicProvider(
3247
+ "sk-ant-test",
3248
+ "claude-sonnet-4-6",
3249
+ );
3250
+ await sonnet46Provider.sendMessage([userMsg("Hi")], {
3251
+ systemPrompt: "You are helpful.",
3252
+ config: { effort: "medium" },
3253
+ });
3254
+
3255
+ expect(lastStreamParams!.output_config).toEqual({ effort: "medium" });
3256
+ });
3197
3257
  });
3198
3258
 
3199
3259
  // ---------------------------------------------------------------------------
@@ -816,6 +816,44 @@ describe("classifyConversationError", () => {
816
816
  );
817
817
  });
818
818
 
819
+ it("classifies an OpenCode 401 ModelError as model-not-found, not an invalid key", () => {
820
+ providerRoutingSources.opencode = "user-key";
821
+ const err = new ProviderError(
822
+ "OpenCode API error (401): Model muse-spark-1.3-contributor is not supported [type=ModelError]",
823
+ "opencode",
824
+ 401,
825
+ { reason: "model_not_found" },
826
+ );
827
+
828
+ const result = classifyConversationError(err, {
829
+ ...baseCtx,
830
+ profileName: "custom-profile",
831
+ connectionName: "opencode-personal",
832
+ });
833
+
834
+ expect(result.code).toBe("PROVIDER_API");
835
+ expect(result.errorCategory).toBe("provider_model_not_found");
836
+ expect(result.retryable).toBe(false);
837
+ expect(result.userMessage).toContain("wasn't found by the provider");
838
+ expect(result.userMessage).not.toContain("API key");
839
+ });
840
+
841
+ it("classifies a reason-less OpenCode 401 ModelError via the message, not credentials", () => {
842
+ providerRoutingSources.opencode = "user-key";
843
+ const err = new ProviderError(
844
+ "OpenCode API error (401): Model muse-spark-1.3-contributor is not supported [type=ModelError]",
845
+ "opencode",
846
+ 401,
847
+ );
848
+
849
+ const result = classifyConversationError(err, baseCtx);
850
+
851
+ expect(result.code).toBe("PROVIDER_API");
852
+ expect(result.errorCategory).toBe("provider_model_not_found");
853
+ expect(result.retryable).toBe(false);
854
+ expect(result.userMessage).not.toContain("API key");
855
+ });
856
+
819
857
  it("classifies managed-proxy auth failures as managed credential refresh failures", () => {
820
858
  providerRoutingSources.anthropic = "managed-proxy";
821
859
  const err = new ProviderError(
@@ -1398,7 +1398,7 @@ describe("HostAppControlProxy", () => {
1398
1398
  proxy.dispose();
1399
1399
  });
1400
1400
 
1401
- test("request() without targetClientId: does not register targetActorPrincipalId", async () => {
1401
+ test("request() without targetClientId: registers the source actor principal", async () => {
1402
1402
  const proxy = new HostAppControlProxy("conv-1");
1403
1403
  const ctrl = new AbortController();
1404
1404
 
@@ -1413,7 +1413,7 @@ describe("HostAppControlProxy", () => {
1413
1413
 
1414
1414
  const sent = sentMessages[0] as Record<string, unknown>;
1415
1415
  expect(registeredInteractions[0].targetClientId).toBeUndefined();
1416
- expect(registeredInteractions[0].targetActorPrincipalId).toBeUndefined();
1416
+ expect(registeredInteractions[0].targetActorPrincipalId).toBe("user-1");
1417
1417
 
1418
1418
  proxy.resolve(sent.requestId as string, payload({ pngBase64: PNG_A }));
1419
1419
  await resultPromise;