@vellumai/assistant 0.12.4-staging.1 → 0.12.4-staging.2

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 (36) hide show
  1. package/openapi.yaml +3 -1
  2. package/package.json +1 -1
  3. package/src/__tests__/config-loader-backfill.test.ts +1 -0
  4. package/src/__tests__/default-profile-catalog-fallback.test.ts +1 -0
  5. package/src/__tests__/inference-profile-validation-jev.test.ts +17 -0
  6. package/src/__tests__/llm-catalog-parity.test.ts +4 -0
  7. package/src/__tests__/llm-resolver-override-or-default.test.ts +43 -0
  8. package/src/__tests__/plugin-api-model-profiles.test.ts +7 -0
  9. package/src/__tests__/workspace-migration-159-rename-colliding-jev-profile-name.test.ts +197 -0
  10. package/src/api/requests/dictation.ts +2 -2
  11. package/src/calls/__tests__/typesafe-noul.test.ts +66 -0
  12. package/src/calls/typesafe-noul.ts +8 -2
  13. package/src/calls/voice-escalation-judge.ts +5 -4
  14. package/src/config/__tests__/default-profile-catalog.test.ts +33 -1
  15. package/src/config/__tests__/jev-managed-profile.test.ts +82 -0
  16. package/src/config/call-site-defaults.ts +11 -11
  17. package/src/config/default-profile-catalog.ts +88 -18
  18. package/src/config/default-profile-names.ts +35 -0
  19. package/src/config/inference-profile-validation.ts +7 -6
  20. package/src/config/llm-resolver.ts +16 -0
  21. package/src/config/profile-text-generation.test.ts +9 -0
  22. package/src/config/schemas/call-site-catalog.ts +1 -1
  23. package/src/config/schemas/llm.ts +54 -9
  24. package/src/daemon/conversation-slash.ts +2 -2
  25. package/src/daemon/dictation-text-processing.ts +4 -4
  26. package/src/plugin-api/model-profiles.ts +5 -3
  27. package/src/providers/model-catalog.ts +23 -4
  28. package/src/runtime/routes/__tests__/dictation-processing.test.ts +174 -0
  29. package/src/runtime/routes/__tests__/llm-call-sites-routes.test.ts +16 -1
  30. package/src/runtime/routes/conversation-routes.ts +4 -2
  31. package/src/runtime/routes/diagnostics-routes.ts +66 -229
  32. package/src/runtime/routes/llm-call-sites-routes.ts +19 -10
  33. package/src/tools/workflows/manage-workflows.ts +4 -2
  34. package/src/workspace/migrations/159-rename-colliding-jev-profile-name.ts +344 -0
  35. package/src/workspace/migrations/registry.ts +2 -0
  36. package/src/runtime/routes/__tests__/dictation-cleanup-guard.test.ts +0 -107
@@ -0,0 +1,344 @@
1
+ /**
2
+ * Workspace migration `159-rename-colliding-jev-profile-name`.
3
+ *
4
+ * `jev-managed` became a reserved code-owned profile name (the managed Jev
5
+ * profile). From this release on, that name resolves to the code body no
6
+ * matter what `llm.profiles` holds, and the schema rejects it as
7
+ * `activeProfile` or `advisorProfile`, so a user-created profile that
8
+ * happens to carry the name would be silently replaced in the effective
9
+ * catalog and its selections stranded.
10
+ *
11
+ * This migration runs before the reservation can take effect (workspace
12
+ * migrations run ahead of the first config load and the profile seeder) and
13
+ * gives such a profile a fresh key, rewriting every reference to it so the
14
+ * user keeps both the profile and its wiring:
15
+ *
16
+ * - `llm.profiles` key (insertion order preserved)
17
+ * - `llm.activeProfile`, `llm.advisorProfile`
18
+ * - `llm.profileOrder` entries
19
+ * - `llm.callSites.<site>.profile` pins
20
+ * - `llm.profiles.<key>.mix[].profile` arms
21
+ * - `llm.profiles.<key>.fallbackProfile` targets
22
+ * - `conversations.inference_profile` and `cron_jobs.inference_profile`
23
+ * rows
24
+ *
25
+ * The new key is `jev-managed-custom`, suffixed `-custom-2`, `-custom-3`,
26
+ * ... when that is taken. Candidates are checked against every existing
27
+ * profile key AND every reserved code-defined name, so a rename never lands
28
+ * on another name the catalog owns.
29
+ *
30
+ * Only a workspace-owned profile is renamed. An entry whose `source` is
31
+ * `managed` is a thin stub for the code-owned profile, and a non-object
32
+ * value under the key is not a profile at all; both are left alone.
33
+ *
34
+ * The DB rewrite is not best effort: a pin the rewrite abandons would route
35
+ * through the managed Jev profile instead of the user's own, so a database
36
+ * that exists but cannot be written is retried with a short backoff and a
37
+ * failure that outlives the retries throws; `retryFailedCheckpoint` re-runs
38
+ * the whole migration on the next boot. The DB rewrite runs before the
39
+ * config write, so a throw leaves config.json holding the old key.
40
+ *
41
+ * Idempotent: after a successful run no workspace-owned profile carries the
42
+ * reserved name, so a re-run finds nothing to rename and writes nothing.
43
+ */
44
+
45
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
46
+ import { join } from "node:path";
47
+ import { Database } from "bun:sqlite";
48
+
49
+ import { getLogger } from "../../util/logger.js";
50
+ import type { WorkspaceMigration } from "./types.js";
51
+
52
+ const log = getLogger(
53
+ "workspace-migration-159-rename-colliding-jev-profile-name",
54
+ );
55
+
56
+ /**
57
+ * The newly reserved key this migration clears. Frozen snapshot as of
58
+ * 2026-09-22 (migrations are self-contained).
59
+ */
60
+ const RESERVED_KEYS = ["jev-managed"];
61
+
62
+ /**
63
+ * Every code-defined profile name as of 2026-09-22: the default keys, the
64
+ * backups, the flag-gated `os-beta`, and the Jev profile. A renamed profile
65
+ * must not land on any of them, or the rename would just move the collision.
66
+ */
67
+ const RESERVED_PROFILE_NAMES = new Set<string>([
68
+ "balanced",
69
+ "quality-optimized",
70
+ "cost-optimized",
71
+ "latency-optimized",
72
+ "balanced-backup",
73
+ "quality-optimized-backup",
74
+ "cost-optimized-backup",
75
+ "latency-optimized-backup",
76
+ "os-beta",
77
+ ...RESERVED_KEYS,
78
+ ]);
79
+
80
+ const RENAME_SUFFIX = "-custom";
81
+
82
+ /** Total attempts at the pin rewrite, the first one included. */
83
+ const DB_ATTEMPTS = 4;
84
+
85
+ /** First backoff step; each further wait doubles it (50, 100, 200 ms). */
86
+ const DB_RETRY_BASE_DELAY_MS = 50;
87
+
88
+ export const renameCollidingJevProfileNameMigration: WorkspaceMigration = {
89
+ id: "159-rename-colliding-jev-profile-name",
90
+ description:
91
+ "Rename a user profile colliding with the reserved managed Jev profile key and rewrite its references",
92
+ // The failure this migration can hit is a database it cannot write, and
93
+ // both halves of the run are idempotent, so a failed checkpoint is worth
94
+ // re-running: the config still holds the old keys, the mapping rebuilds
95
+ // from them, and the pin rewrite matches on the old name.
96
+ retryFailedCheckpoint: true,
97
+
98
+ async run(workspaceDir: string): Promise<void> {
99
+ const configPath = join(workspaceDir, "config.json");
100
+ if (!existsSync(configPath)) {
101
+ return;
102
+ }
103
+
104
+ let config: Record<string, unknown>;
105
+ try {
106
+ const parsed = JSON.parse(readFileSync(configPath, "utf-8"));
107
+ if (!isPlainObject(parsed)) {
108
+ return;
109
+ }
110
+ config = parsed;
111
+ } catch {
112
+ return;
113
+ }
114
+
115
+ const llm = asObject(config.llm);
116
+ const profiles = llm === null ? null : asObject(llm.profiles);
117
+ if (llm === null || profiles === null) {
118
+ return;
119
+ }
120
+
121
+ const renames = planRenames(profiles);
122
+ if (renames.size === 0) {
123
+ return;
124
+ }
125
+
126
+ // The DB rewrite runs first so an interrupted or failed migration re-runs
127
+ // with the config still holding the old keys, i.e. with the mapping
128
+ // intact. A rewrite that cannot be completed throws out of here, which
129
+ // stops the config rename below rather than stranding the pins.
130
+ await rewriteDbReferences(workspaceDir, renames);
131
+
132
+ llm.profiles = renameProfileKeys(profiles, renames);
133
+ rewriteConfigReferences(llm, renames);
134
+
135
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
136
+ log.info(
137
+ { renames: Object.fromEntries(renames) },
138
+ "Renamed a user profile colliding with the reserved managed Jev profile key",
139
+ );
140
+ },
141
+
142
+ down(_workspaceDir: string): void {
143
+ // Forward-only: the reserved names cannot be handed back.
144
+ },
145
+ };
146
+
147
+ /**
148
+ * Old key -> new key for a workspace-owned profile sitting on the reserved
149
+ * name. Deterministic: each assigned name is reserved against later
150
+ * candidates, so the same config always produces the same mapping.
151
+ */
152
+ function planRenames(profiles: Record<string, unknown>): Map<string, string> {
153
+ const renames = new Map<string, string>();
154
+ const taken = new Set<string>([
155
+ ...Object.keys(profiles),
156
+ ...RESERVED_PROFILE_NAMES,
157
+ ]);
158
+
159
+ for (const key of RESERVED_KEYS) {
160
+ if (!(key in profiles)) {
161
+ continue;
162
+ }
163
+ const entry = asObject(profiles[key]);
164
+ if (entry === null) {
165
+ log.warn(
166
+ { profile: key },
167
+ "Left a non-object value under the reserved Jev profile key; it is not a profile to preserve",
168
+ );
169
+ continue;
170
+ }
171
+ if (entry.source === "managed") {
172
+ // A managed stub is the workspace's overlay slot for the code-owned
173
+ // profile, not a user profile; renaming it would manufacture a phantom
174
+ // user profile.
175
+ continue;
176
+ }
177
+ let candidate = `${key}${RENAME_SUFFIX}`;
178
+ let counter = 2;
179
+ while (taken.has(candidate)) {
180
+ candidate = `${key}${RENAME_SUFFIX}-${counter}`;
181
+ counter += 1;
182
+ }
183
+ taken.add(candidate);
184
+ renames.set(key, candidate);
185
+ }
186
+
187
+ return renames;
188
+ }
189
+
190
+ /** Rebuild the profiles record with the renamed keys, preserving order. */
191
+ function renameProfileKeys(
192
+ profiles: Record<string, unknown>,
193
+ renames: Map<string, string>,
194
+ ): Record<string, unknown> {
195
+ const renamed: Record<string, unknown> = {};
196
+ for (const [name, value] of Object.entries(profiles)) {
197
+ renamed[renames.get(name) ?? name] = value;
198
+ }
199
+ return renamed;
200
+ }
201
+
202
+ /** Point every config reference at the renamed key. */
203
+ function rewriteConfigReferences(
204
+ llm: Record<string, unknown>,
205
+ renames: Map<string, string>,
206
+ ): void {
207
+ for (const field of ["activeProfile", "advisorProfile"]) {
208
+ const current = llm[field];
209
+ if (typeof current === "string" && renames.has(current)) {
210
+ llm[field] = renames.get(current);
211
+ }
212
+ }
213
+
214
+ if (Array.isArray(llm.profileOrder)) {
215
+ llm.profileOrder = (llm.profileOrder as unknown[]).map((name) =>
216
+ typeof name === "string" ? (renames.get(name) ?? name) : name,
217
+ );
218
+ }
219
+
220
+ const callSites = asObject(llm.callSites);
221
+ if (callSites !== null) {
222
+ for (const value of Object.values(callSites)) {
223
+ const site = asObject(value);
224
+ if (
225
+ site !== null &&
226
+ typeof site.profile === "string" &&
227
+ renames.has(site.profile)
228
+ ) {
229
+ site.profile = renames.get(site.profile);
230
+ }
231
+ }
232
+ }
233
+
234
+ const profiles = asObject(llm.profiles);
235
+ if (profiles === null) {
236
+ return;
237
+ }
238
+ for (const value of Object.values(profiles)) {
239
+ const entry = asObject(value);
240
+ if (entry === null) {
241
+ continue;
242
+ }
243
+ if (
244
+ typeof entry.fallbackProfile === "string" &&
245
+ renames.has(entry.fallbackProfile)
246
+ ) {
247
+ entry.fallbackProfile = renames.get(entry.fallbackProfile);
248
+ }
249
+ if (!Array.isArray(entry.mix)) {
250
+ continue;
251
+ }
252
+ for (const armValue of entry.mix as unknown[]) {
253
+ const arm = asObject(armValue);
254
+ if (
255
+ arm !== null &&
256
+ typeof arm.profile === "string" &&
257
+ renames.has(arm.profile)
258
+ ) {
259
+ arm.profile = renames.get(arm.profile);
260
+ }
261
+ }
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Repoint the profile pins stored outside config.json: the sticky
267
+ * per-conversation profile and the per-schedule profile.
268
+ *
269
+ * Retried as a whole rather than per statement: opening the database, reading
270
+ * `sqlite_master` and running the updates all fail the same way under write
271
+ * contention (`SQLITE_BUSY` from a second connection), and every step is
272
+ * idempotent, so re-running the block is the simplest recovery that cannot
273
+ * double-apply. A failure that outlives the attempts throws, which fails the
274
+ * migration for `retryFailedCheckpoint` to pick up on the next boot.
275
+ */
276
+ async function rewriteDbReferences(
277
+ workspaceDir: string,
278
+ renames: Map<string, string>,
279
+ ): Promise<void> {
280
+ const dbPath = join(workspaceDir, "data", "db", "assistant.db");
281
+ if (!existsSync(dbPath)) {
282
+ // No database yet, so there are no pins that could be stranded.
283
+ return;
284
+ }
285
+ await withDbRetry(() => {
286
+ const db = new Database(dbPath);
287
+ try {
288
+ for (const table of ["conversations", "cron_jobs"]) {
289
+ const present = db
290
+ .query(
291
+ `SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`,
292
+ )
293
+ .get(table);
294
+ if (!present) {
295
+ // A workspace whose schema does not carry this table holds no pins
296
+ // in it. Nothing to rewrite, and nothing to fail over.
297
+ log.info({ table }, "No profile pin table to repoint");
298
+ continue;
299
+ }
300
+ for (const [from, to] of renames) {
301
+ db.query(
302
+ `UPDATE ${table} SET inference_profile = ? WHERE inference_profile = ?`,
303
+ ).run(to, from);
304
+ }
305
+ }
306
+ } finally {
307
+ db.close();
308
+ }
309
+ });
310
+ }
311
+
312
+ /**
313
+ * Run the pin rewrite, retrying a transient database failure with a short
314
+ * doubling backoff. Rethrows once the attempts are spent so the caller stops
315
+ * before the config rename.
316
+ */
317
+ async function withDbRetry(attempt: () => void): Promise<void> {
318
+ for (let index = 0; ; index += 1) {
319
+ try {
320
+ attempt();
321
+ return;
322
+ } catch (err) {
323
+ if (index >= DB_ATTEMPTS - 1) {
324
+ throw new Error(
325
+ `Could not repoint conversation and schedule profile pins after ${DB_ATTEMPTS} attempts; leaving the config unrenamed so the next boot retries`,
326
+ { cause: err },
327
+ );
328
+ }
329
+ log.warn(
330
+ { err, attempt: index },
331
+ "Could not repoint profile pins; retrying",
332
+ );
333
+ await Bun.sleep(DB_RETRY_BASE_DELAY_MS * 2 ** index);
334
+ }
335
+ }
336
+ }
337
+
338
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
339
+ return value !== null && typeof value === "object" && !Array.isArray(value);
340
+ }
341
+
342
+ function asObject(value: unknown): Record<string, unknown> | null {
343
+ return isPlainObject(value) ? value : null;
344
+ }
@@ -155,6 +155,7 @@ import { repairRetiredCodexGpt54ModelIdsMigration } from "./154-repair-retired-c
155
155
  import { moveFrontModelConfigToVoiceMigration } from "./155-move-front-model-config-to-voice.js";
156
156
  import { extractWorkspaceMcpJsonMigration } from "./156-extract-workspace-mcp-json.js";
157
157
  import { addDesktopFilesLauncherMigration } from "./157-add-desktop-files-launcher.js";
158
+ import { renameCollidingJevProfileNameMigration } from "./159-rename-colliding-jev-profile-name.js";
158
159
  import { migrateToWorkspaceVolumeMigration } from "./migrate-to-workspace-volume.js";
159
160
  import type { WorkspaceMigration } from "./types.js";
160
161
 
@@ -325,4 +326,5 @@ export const WORKSPACE_MIGRATIONS: WorkspaceMigration[] = [
325
326
  moveFrontModelConfigToVoiceMigration,
326
327
  extractWorkspaceMcpJsonMigration,
327
328
  addDesktopFilesLauncherMigration,
329
+ renameCollidingJevProfileNameMigration,
328
330
  ];
@@ -1,107 +0,0 @@
1
- /**
2
- * The dictation cleanup pass rewrites what the user actually said, so a
3
- * rewrite the provider cut off at the token cap must never become the
4
- * payload: the raw transcript is sent instead.
5
- */
6
-
7
- import { describe, expect, test } from "bun:test";
8
-
9
- import {
10
- computeMaxTokens,
11
- resolveCleanedDictation,
12
- } from "../diagnostics-routes.js";
13
-
14
- const SPOKEN =
15
- "Hello Quill can you generate a list of 20 open HR coordinator or HR " +
16
- "related roles that are remote and pay about 50 to 60 K per year";
17
-
18
- describe("resolveCleanedDictation", () => {
19
- test("accepts an ordinary cleanup", () => {
20
- const cleaned =
21
- "Hello Quill, can you generate a list of 20 open HR coordinator or HR " +
22
- "related roles that are remote and pay about 50 to 60K per year?";
23
- expect(resolveCleanedDictation(SPOKEN, cleaned, "end_turn")).toEqual({
24
- text: cleaned,
25
- rejected: null,
26
- });
27
- });
28
-
29
- test("trims surrounding whitespace off an accepted cleanup", () => {
30
- const { text } = resolveCleanedDictation(
31
- "so um I think we should ship the thing on Tuesday you know",
32
- " I think we should ship the thing on Tuesday. ",
33
- "end_turn",
34
- );
35
- expect(text).toBe("I think we should ship the thing on Tuesday.");
36
- });
37
-
38
- test("rejects a rewrite cut off by max_tokens and keeps the raw words", () => {
39
- expect(
40
- resolveCleanedDictation(
41
- SPOKEN,
42
- "Hello Quill, can you create a list",
43
- "max_tokens",
44
- ),
45
- ).toEqual({ text: SPOKEN, rejected: "truncated" });
46
- });
47
-
48
- test("rejects a max_tokens rewrite even when it kept most of the words", () => {
49
- const nearlyComplete = SPOKEN.slice(0, SPOKEN.length - 4);
50
- const { rejected } = resolveCleanedDictation(
51
- SPOKEN,
52
- nearlyComplete,
53
- "max_tokens",
54
- );
55
- expect(rejected).toBe("truncated");
56
- });
57
-
58
- test("rejects the token-cap stop under every provider's name for it", () => {
59
- for (const stopReason of ["length", "max_output_tokens", "MAX_TOKENS "]) {
60
- expect(
61
- resolveCleanedDictation(SPOKEN, "Hello Quill, can you", stopReason)
62
- .rejected,
63
- ).toBe("truncated");
64
- }
65
- });
66
-
67
- test("a missing stop reason is not treated as a truncation", () => {
68
- const cleaned = "Hello Quill, can you generate a list?";
69
- expect(resolveCleanedDictation(SPOKEN, cleaned, undefined)).toEqual({
70
- text: cleaned,
71
- rejected: null,
72
- });
73
- });
74
-
75
- test("a much shorter rewrite is the model's call, not a rejection", () => {
76
- // The prompt asks for fillers and vague phrasing to go, so a concise
77
- // rewrite of a rambling utterance is a correct cleanup.
78
- const spoken =
79
- "um you know I just kind of wanted to say like thank you so much you know";
80
- expect(
81
- resolveCleanedDictation(spoken, "Thank you so much.", "end_turn"),
82
- ).toEqual({ text: "Thank you so much.", rejected: null });
83
- });
84
-
85
- test("an empty rewrite falls back to raw without flagging a rejection", () => {
86
- // The model returned nothing usable; there is no rewrite to distrust.
87
- expect(resolveCleanedDictation(SPOKEN, " ", "end_turn")).toEqual({
88
- text: SPOKEN,
89
- rejected: null,
90
- });
91
- });
92
- });
93
-
94
- describe("computeMaxTokens", () => {
95
- test("budgets room for the transcript, reasoning, and JSON scaffolding", () => {
96
- // The tool call carries the whole transcript back in `text`, so the
97
- // budget has to clear the input's own token count with room to spare.
98
- const estimatedInputTokens = Math.ceil(SPOKEN.length / 3);
99
- expect(computeMaxTokens(SPOKEN.length)).toBeGreaterThan(
100
- estimatedInputTokens * 2,
101
- );
102
- });
103
-
104
- test("holds a floor for very short transcripts", () => {
105
- expect(computeMaxTokens(5)).toBe(512);
106
- });
107
- });