@vellumai/assistant 0.11.1-dev.202608032034.aebd2da → 0.11.1-dev.202608032226.351a4e2
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.
- package/openapi.yaml +1 -0
- package/package.json +1 -1
- package/src/__tests__/agent-loop-resume-interrupted.test.ts +223 -0
- package/src/__tests__/conversation-agent-loop.test.ts +16 -7
- package/src/__tests__/conversation-error.test.ts +106 -0
- package/src/__tests__/llm-resolver.test.ts +16 -0
- package/src/__tests__/provider-send-message-override-profile.test.ts +95 -0
- package/src/__tests__/workspace-migration-137-repair-retired-fireworks-minimax-model-id.test.ts +6 -6
- package/src/__tests__/workspace-migration-138-backfill-home-feed-titles.test.ts +373 -0
- package/src/agent/loop.ts +36 -7
- package/src/cli/commands/notifications.help.ts +3 -2
- package/src/config/llm-resolver.ts +19 -3
- package/src/daemon/conversation-agent-loop-handlers.ts +15 -6
- package/src/daemon/conversation-agent-loop.ts +31 -18
- package/src/daemon/conversation-error.ts +40 -24
- package/src/home/__tests__/feed-types.test.ts +43 -8
- package/src/home/__tests__/feed-writer.test.ts +59 -0
- package/src/home/feed-types.ts +34 -7
- package/src/home/feed-writer.ts +15 -6
- package/src/live-voice/__tests__/activity-label.test.ts +68 -0
- package/src/live-voice/__tests__/live-activity-reporter.test.ts +86 -5
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +14 -5
- package/src/live-voice/activity-label.ts +106 -0
- package/src/live-voice/live-activity-reporter.ts +35 -6
- package/src/live-voice/live-voice-session.ts +58 -0
- package/src/live-voice/protocol.ts +23 -0
- package/src/notifications/__tests__/copy-composer.test.ts +53 -3
- package/src/notifications/__tests__/decision-engine.test.ts +150 -20
- package/src/notifications/__tests__/edit-notification.test.ts +330 -0
- package/src/notifications/__tests__/home-feed-side-effect.test.ts +170 -12
- package/src/notifications/copy-composer.ts +23 -3
- package/src/notifications/decision-engine.ts +29 -7
- package/src/notifications/edit-notification.ts +8 -4
- package/src/notifications/home-feed-side-effect.ts +43 -6
- package/src/notifications/notification-utils.ts +8 -2
- package/src/persistence/conversation-title-service.ts +5 -170
- package/src/providers/__tests__/dispatch-connection-routing.test.ts +43 -2
- package/src/providers/__tests__/vellum-mismatch-routing.test.ts +8 -0
- package/src/providers/call-site-routing.ts +77 -14
- package/src/providers/connection-resolution.ts +42 -2
- package/src/providers/types.ts +7 -1
- package/src/runtime/routes/notification-routes.ts +4 -1
- package/src/util/__tests__/short-title.test.ts +229 -0
- package/src/util/errors.ts +15 -0
- package/src/util/short-title.ts +189 -0
- package/src/workspace/migrations/138-backfill-home-feed-titles.ts +179 -0
- package/src/workspace/migrations/registry.ts +2 -0
package/src/providers/types.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type { ToolDefinition } from "../tools/tool-types.js";
|
|
|
2
2
|
export type { ToolDefinition };
|
|
3
3
|
|
|
4
4
|
import type { LLMCallSite } from "../config/schemas/llm.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ProviderError,
|
|
7
|
+
type ProviderErrorReason,
|
|
8
|
+
type ProviderRouteAttribution,
|
|
9
|
+
} from "../util/errors.js";
|
|
6
10
|
|
|
7
11
|
export interface TextContent {
|
|
8
12
|
type: "text";
|
|
@@ -359,6 +363,8 @@ export interface SendMessageOptions {
|
|
|
359
363
|
|
|
360
364
|
export interface Provider {
|
|
361
365
|
name: string;
|
|
366
|
+
/** Connection route whose credentials this provider instance uses. */
|
|
367
|
+
routeAttribution?: ProviderRouteAttribution;
|
|
362
368
|
/**
|
|
363
369
|
* Provider key used by the local token estimator to select model-family
|
|
364
370
|
* specific rules (e.g. Anthropic's `width * height / 750` image sizing).
|
|
@@ -116,7 +116,10 @@ async function handleEmitSignal({ body = {} }: RouteHandlerArgs) {
|
|
|
116
116
|
const EditNotificationParams = z
|
|
117
117
|
.object({
|
|
118
118
|
id: z.string().min(1).describe("Feed item id (notif:<uuid>) or bare uuid"),
|
|
119
|
-
title: z
|
|
119
|
+
title: z
|
|
120
|
+
.string()
|
|
121
|
+
.optional()
|
|
122
|
+
.describe("New title. An empty value is ignored, never cleared."),
|
|
120
123
|
body: z.string().optional(),
|
|
121
124
|
urgency: UrgencySchema.optional(),
|
|
122
125
|
status: z.enum(["new", "seen", "acted_on", "dismissed"]).optional(),
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
normalizeTitle,
|
|
5
|
+
stripMarkdown,
|
|
6
|
+
stripThinkingTags,
|
|
7
|
+
truncateTitle,
|
|
8
|
+
} from "../short-title.js";
|
|
9
|
+
|
|
10
|
+
/** The character and word budgets `short-title.ts` documents and enforces. */
|
|
11
|
+
const MAX_TITLE_LENGTH = 40;
|
|
12
|
+
const MAX_TITLE_WORDS = 7;
|
|
13
|
+
|
|
14
|
+
describe("stripMarkdown", () => {
|
|
15
|
+
test("unwraps bold, italic, strikethrough, and code spans", () => {
|
|
16
|
+
expect(stripMarkdown("**Auth** Rewrite")).toBe("Auth Rewrite");
|
|
17
|
+
expect(stripMarkdown("__Auth__ Rewrite")).toBe("Auth Rewrite");
|
|
18
|
+
expect(stripMarkdown("*Auth* Rewrite")).toBe("Auth Rewrite");
|
|
19
|
+
expect(stripMarkdown("_Auth_ Rewrite")).toBe("Auth Rewrite");
|
|
20
|
+
expect(stripMarkdown("~~Auth~~ Rewrite")).toBe("Auth Rewrite");
|
|
21
|
+
expect(stripMarkdown("`Auth` Rewrite")).toBe("Auth Rewrite");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("keeps link text and drops the target", () => {
|
|
25
|
+
expect(stripMarkdown("[Auth Rewrite](https://example.com)")).toBe(
|
|
26
|
+
"Auth Rewrite",
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("removes heading markers", () => {
|
|
31
|
+
expect(stripMarkdown("## Auth Rewrite")).toBe("Auth Rewrite");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("preserves snake_case identifiers", () => {
|
|
35
|
+
expect(stripMarkdown("record_conversation_title")).toBe(
|
|
36
|
+
"record_conversation_title",
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("stripThinkingTags", () => {
|
|
42
|
+
test("removes paired thinking blocks and their contents", () => {
|
|
43
|
+
expect(stripThinkingTags("<thinking>hmm</thinking>Auth Rewrite")).toBe(
|
|
44
|
+
"Auth Rewrite",
|
|
45
|
+
);
|
|
46
|
+
expect(stripThinkingTags("<thought>hmm</thought>Auth Rewrite")).toBe(
|
|
47
|
+
"Auth Rewrite",
|
|
48
|
+
);
|
|
49
|
+
expect(stripThinkingTags("<think>hmm</think>Auth Rewrite")).toBe(
|
|
50
|
+
"Auth Rewrite",
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("removes unpaired tags but keeps the surrounding text", () => {
|
|
55
|
+
expect(stripThinkingTags("<thinking>Auth Rewrite")).toBe("Auth Rewrite");
|
|
56
|
+
expect(stripThinkingTags("Auth Rewrite</think>")).toBe("Auth Rewrite");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("removes colon-prefixed pseudo tags", () => {
|
|
60
|
+
expect(stripThinkingTags("<:anything>Auth Rewrite")).toBe("Auth Rewrite");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("leaves plain text untouched", () => {
|
|
64
|
+
expect(stripThinkingTags("Auth Rewrite")).toBe("Auth Rewrite");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("truncateTitle", () => {
|
|
69
|
+
test("leaves titles within the character limit untouched", () => {
|
|
70
|
+
const title = "Auth Middleware Rewrite";
|
|
71
|
+
expect(title.length).toBeLessThanOrEqual(MAX_TITLE_LENGTH);
|
|
72
|
+
expect(truncateTitle(title)).toBe(title);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("trims at a word boundary when few but long words exceed the char limit", () => {
|
|
76
|
+
const title = "Supercalifragilistic Authentication Middleware Rewrite";
|
|
77
|
+
expect(title.split(" ").length).toBeLessThanOrEqual(MAX_TITLE_WORDS);
|
|
78
|
+
expect(truncateTitle(title)).toBe("Supercalifragilistic Authentication");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("hard-slices a single word longer than the char limit", () => {
|
|
82
|
+
const title = "a".repeat(MAX_TITLE_LENGTH + 5);
|
|
83
|
+
expect(truncateTitle(title)).toBe("a".repeat(MAX_TITLE_LENGTH));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("keeps the first five words when the word limit is exceeded", () => {
|
|
87
|
+
const title =
|
|
88
|
+
"alpha bravo charlie delta echo foxtrot golf hotel india juliet";
|
|
89
|
+
expect(title.length).toBeGreaterThan(MAX_TITLE_LENGTH);
|
|
90
|
+
expect(title.split(" ").length).toBeGreaterThan(MAX_TITLE_WORDS);
|
|
91
|
+
expect(truncateTitle(title)).toBe("alpha bravo charlie delta echo");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("still honors the char limit when the first five words overflow it", () => {
|
|
95
|
+
const title =
|
|
96
|
+
"Authentication Infrastructure Modernization Deployment Verification Report Complete Today";
|
|
97
|
+
expect(title.length).toBeGreaterThan(MAX_TITLE_LENGTH);
|
|
98
|
+
expect(title.split(" ").length).toBeGreaterThan(MAX_TITLE_WORDS);
|
|
99
|
+
const result = truncateTitle(title);
|
|
100
|
+
expect(result).toBe("Authentication Infrastructure");
|
|
101
|
+
expect(result.length).toBeLessThanOrEqual(MAX_TITLE_LENGTH);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("normalizeTitle prose rejection", () => {
|
|
106
|
+
test("rejects multi-line output", () => {
|
|
107
|
+
expect(normalizeTitle("Auth Rewrite\nand more")).toBe("");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("rejects embedded transcript markers", () => {
|
|
111
|
+
expect(normalizeTitle("User: how do I log in")).toBe("");
|
|
112
|
+
expect(normalizeTitle("Assistant : here you go")).toBe("");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("rejects sentence-shaped clauses ending in terminal punctuation", () => {
|
|
116
|
+
expect(normalizeTitle("This is a topic about authentication.")).toBe("");
|
|
117
|
+
expect(normalizeTitle("What did they want to build here?")).toBe("");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("keeps short phrases that end in punctuation", () => {
|
|
121
|
+
expect(normalizeTitle("Auth Rewrite?")).toBe("Auth Rewrite?");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("rejects first-person reasoning openers", () => {
|
|
125
|
+
expect(normalizeTitle("I need to generate a title")).toBe("");
|
|
126
|
+
expect(normalizeTitle("I'll work through these files")).toBe("");
|
|
127
|
+
expect(normalizeTitle("I cannot title this")).toBe("");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("rejects imperative and deferral openers", () => {
|
|
131
|
+
expect(normalizeTitle("Let me summarize the request")).toBe("");
|
|
132
|
+
expect(normalizeTitle("Looking at the conversation")).toBe("");
|
|
133
|
+
expect(normalizeTitle("Based on the messages")).toBe("");
|
|
134
|
+
expect(normalizeTitle("Given the context")).toBe("");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("rejects infinitive openers", () => {
|
|
138
|
+
expect(normalizeTitle("To generate a good title")).toBe("");
|
|
139
|
+
expect(normalizeTitle("To summarize the discussion")).toBe("");
|
|
140
|
+
expect(normalizeTitle("To title this thread")).toBe("");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("rejects subject-led reasoning openers", () => {
|
|
144
|
+
expect(normalizeTitle("The user wants a summary")).toBe("");
|
|
145
|
+
expect(normalizeTitle("The conversation is about Docker")).toBe("");
|
|
146
|
+
expect(normalizeTitle("The assistant should reply")).toBe("");
|
|
147
|
+
expect(normalizeTitle("The title should be short")).toBe("");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("rejects preamble openers", () => {
|
|
151
|
+
expect(normalizeTitle("Here's a title")).toBe("");
|
|
152
|
+
expect(normalizeTitle("Here is a title")).toBe("");
|
|
153
|
+
expect(normalizeTitle("Here are the options")).toBe("");
|
|
154
|
+
expect(normalizeTitle("Sure, Auth Rewrite")).toBe("");
|
|
155
|
+
expect(normalizeTitle("Okay, Auth Rewrite")).toBe("");
|
|
156
|
+
expect(normalizeTitle("Ok, Auth Rewrite")).toBe("");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("accepts bare noun-phrase titles that share a subject word", () => {
|
|
160
|
+
expect(normalizeTitle("The Conversation API")).toBe("The Conversation API");
|
|
161
|
+
expect(normalizeTitle("The User Interface Redesign")).toBe(
|
|
162
|
+
"The User Interface Redesign",
|
|
163
|
+
);
|
|
164
|
+
expect(normalizeTitle("Auth Middleware Rewrite")).toBe(
|
|
165
|
+
"Auth Middleware Rewrite",
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("normalizeTitle", () => {
|
|
171
|
+
test("strips surrounding quotes", () => {
|
|
172
|
+
expect(normalizeTitle('"Auth Rewrite"')).toBe("Auth Rewrite");
|
|
173
|
+
expect(normalizeTitle("'Auth Rewrite'")).toBe("Auth Rewrite");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("strips markdown and thinking tags together", () => {
|
|
177
|
+
expect(normalizeTitle("<thinking>hmm</thinking> **Auth Rewrite**")).toBe(
|
|
178
|
+
"Auth Rewrite",
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("returns empty for blank input", () => {
|
|
183
|
+
expect(normalizeTitle("")).toBe("");
|
|
184
|
+
expect(normalizeTitle(" ")).toBe("");
|
|
185
|
+
expect(normalizeTitle("<thinking>hmm</thinking>")).toBe("");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("returns empty for leaked prose", () => {
|
|
189
|
+
expect(normalizeTitle("I need to generate a title for this")).toBe("");
|
|
190
|
+
expect(normalizeTitle("User: how do I log in")).toBe("");
|
|
191
|
+
expect(normalizeTitle("Auth Rewrite\nand more")).toBe("");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("returns empty for meta-failure titles regardless of case", () => {
|
|
195
|
+
const metaFailures = [
|
|
196
|
+
"missing context",
|
|
197
|
+
"no context",
|
|
198
|
+
"insufficient context",
|
|
199
|
+
"unclear context",
|
|
200
|
+
"empty context",
|
|
201
|
+
"no topic",
|
|
202
|
+
"unclear topic",
|
|
203
|
+
"unclear request",
|
|
204
|
+
"unclear message",
|
|
205
|
+
"empty conversation",
|
|
206
|
+
"empty message",
|
|
207
|
+
"no content",
|
|
208
|
+
];
|
|
209
|
+
for (const meta of metaFailures) {
|
|
210
|
+
expect(normalizeTitle(meta)).toBe("");
|
|
211
|
+
}
|
|
212
|
+
expect(normalizeTitle("Missing Context")).toBe("");
|
|
213
|
+
expect(normalizeTitle('"No Topic"')).toBe("");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("truncates an over-long accepted title", () => {
|
|
217
|
+
expect(
|
|
218
|
+
normalizeTitle("alpha bravo charlie delta echo foxtrot golf hotel india"),
|
|
219
|
+
).toBe("alpha bravo charlie delta echo");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("keeps a wordy title inside the character budget", () => {
|
|
223
|
+
const result = normalizeTitle(
|
|
224
|
+
"Authentication Infrastructure Modernization Deployment Verification Report Complete Today",
|
|
225
|
+
);
|
|
226
|
+
expect(result).toBe("Authentication Infrastructure");
|
|
227
|
+
expect(result.length).toBeLessThanOrEqual(MAX_TITLE_LENGTH);
|
|
228
|
+
});
|
|
229
|
+
});
|
package/src/util/errors.ts
CHANGED
|
@@ -123,6 +123,12 @@ export type ProviderErrorReason =
|
|
|
123
123
|
| "network_error"
|
|
124
124
|
| "unknown";
|
|
125
125
|
|
|
126
|
+
export interface ProviderRouteAttribution {
|
|
127
|
+
connectionName?: string;
|
|
128
|
+
profileName?: string;
|
|
129
|
+
isManagedRoute?: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
126
132
|
export class ProviderError extends AssistantError {
|
|
127
133
|
/** Delay (in ms) suggested by the server's Retry-After header, if present. */
|
|
128
134
|
public readonly retryAfterMs?: number;
|
|
@@ -146,6 +152,8 @@ export class ProviderError extends AssistantError {
|
|
|
146
152
|
public readonly abortReason?: unknown;
|
|
147
153
|
/** Semantic failure classification stamped at the throw site. */
|
|
148
154
|
public readonly reason?: ProviderErrorReason;
|
|
155
|
+
/** Transport route selected for the failed provider call. */
|
|
156
|
+
public routeAttribution?: ProviderRouteAttribution;
|
|
149
157
|
|
|
150
158
|
constructor(
|
|
151
159
|
message: string,
|
|
@@ -174,6 +182,13 @@ export class ProviderError extends AssistantError {
|
|
|
174
182
|
this.abortReason = options?.abortReason;
|
|
175
183
|
this.reason = options?.reason;
|
|
176
184
|
}
|
|
185
|
+
|
|
186
|
+
attachRouteAttribution(attribution: ProviderRouteAttribution): void {
|
|
187
|
+
this.routeAttribution = {
|
|
188
|
+
...attribution,
|
|
189
|
+
...this.routeAttribution,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
177
192
|
}
|
|
178
193
|
|
|
179
194
|
export class ToolError extends AssistantError {
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Title hygiene helpers shared by every surface that renders a short,
|
|
3
|
+
* scannable conversation title: markdown/thinking-tag stripping, prose and
|
|
4
|
+
* meta-failure rejection, and length truncation.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const MAX_TITLE_LENGTH = 40;
|
|
8
|
+
const MAX_TITLE_WORDS = 7;
|
|
9
|
+
|
|
10
|
+
/** Word count a title exceeding `MAX_TITLE_WORDS` is cut back to. */
|
|
11
|
+
const TRIMMED_TITLE_WORDS = 5;
|
|
12
|
+
|
|
13
|
+
const META_FAILURE_TITLES = new Set([
|
|
14
|
+
"missing context",
|
|
15
|
+
"no context",
|
|
16
|
+
"insufficient context",
|
|
17
|
+
"unclear context",
|
|
18
|
+
"empty context",
|
|
19
|
+
"no topic",
|
|
20
|
+
"unclear topic",
|
|
21
|
+
"unclear request",
|
|
22
|
+
"unclear message",
|
|
23
|
+
"empty conversation",
|
|
24
|
+
"empty message",
|
|
25
|
+
"no content",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/** Reasoning/sentence openers that never start a legitimate topic title. */
|
|
29
|
+
const LEAKED_PROSE_PREFIXES = [
|
|
30
|
+
"i need to",
|
|
31
|
+
"i needed to",
|
|
32
|
+
"i should",
|
|
33
|
+
"i will",
|
|
34
|
+
"i'll",
|
|
35
|
+
"i can ",
|
|
36
|
+
"i can't",
|
|
37
|
+
"i cannot",
|
|
38
|
+
"i'm ",
|
|
39
|
+
"i am ",
|
|
40
|
+
"i've ",
|
|
41
|
+
"i have ",
|
|
42
|
+
"i'd ",
|
|
43
|
+
"i would",
|
|
44
|
+
"let me",
|
|
45
|
+
"looking at",
|
|
46
|
+
"based on",
|
|
47
|
+
"given the",
|
|
48
|
+
"to generate",
|
|
49
|
+
"to summarize",
|
|
50
|
+
"to title",
|
|
51
|
+
// Subject-led reasoning openers. A bare noun phrase ("The User Interface
|
|
52
|
+
// Redesign", "The Conversation API") is a valid title, so each subject only
|
|
53
|
+
// counts as leaked prose when a verb or possessive follows it, marking the
|
|
54
|
+
// output as a sentence rather than a topic.
|
|
55
|
+
"the user wants",
|
|
56
|
+
"the user asked",
|
|
57
|
+
"the user is",
|
|
58
|
+
"the user wanted",
|
|
59
|
+
"the user needs",
|
|
60
|
+
"the user said",
|
|
61
|
+
"the user has",
|
|
62
|
+
"the user would",
|
|
63
|
+
"the user's request",
|
|
64
|
+
"the conversation is",
|
|
65
|
+
"this conversation is",
|
|
66
|
+
"the conversation appears",
|
|
67
|
+
"the conversation seems",
|
|
68
|
+
"the conversation covers",
|
|
69
|
+
"the conversation discusses",
|
|
70
|
+
"the assistant should",
|
|
71
|
+
"the assistant is",
|
|
72
|
+
"the assistant wants",
|
|
73
|
+
"the assistant needs",
|
|
74
|
+
"the title should",
|
|
75
|
+
"the title is",
|
|
76
|
+
"the title would",
|
|
77
|
+
"the title for",
|
|
78
|
+
"here's ",
|
|
79
|
+
"here is ",
|
|
80
|
+
"here are ",
|
|
81
|
+
"sure,",
|
|
82
|
+
"okay,",
|
|
83
|
+
"ok,",
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
/** Strip common markdown formatting so titles render as plain text. */
|
|
87
|
+
export function stripMarkdown(text: string): string {
|
|
88
|
+
return text
|
|
89
|
+
.replace(/\*\*(.+?)\*\*/g, "$1") // **bold**
|
|
90
|
+
.replace(/__(.+?)__/g, "$1") // __bold__
|
|
91
|
+
.replace(/\*(.+?)\*/g, "$1") // *italic*
|
|
92
|
+
.replace(/(?<!\w)_(.+?)_(?!\w)/g, "$1") // _italic_ (word-boundary-aware to preserve snake_case)
|
|
93
|
+
.replace(/~~(.+?)~~/g, "$1") // ~~strikethrough~~
|
|
94
|
+
.replace(/`(.+?)`/g, "$1") // `code`
|
|
95
|
+
.replace(/\[(.+?)\]\(.+?\)/g, "$1") // [link](url)
|
|
96
|
+
.replace(/^#{1,6}\s+/gm, ""); // # headings
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Strip thinking tags so they don't bleed into generated titles. */
|
|
100
|
+
export function stripThinkingTags(text: string): string {
|
|
101
|
+
return text
|
|
102
|
+
.replace(/<thinking>[\s\S]*?<\/thinking>/gi, "")
|
|
103
|
+
.replace(/<thought>[\s\S]*?<\/thought>/gi, "")
|
|
104
|
+
.replace(/<think>[\s\S]*?<\/think>/gi, "")
|
|
105
|
+
.replace(/<thought>/gi, "")
|
|
106
|
+
.replace(/<\/thought>/gi, "")
|
|
107
|
+
.replace(/<thinking>/gi, "")
|
|
108
|
+
.replace(/<\/thinking>/gi, "")
|
|
109
|
+
.replace(/<think>/gi, "")
|
|
110
|
+
.replace(/<\/think>/gi, "")
|
|
111
|
+
.replace(/<:[^>]*>/gi, "");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Clamp a title to `MAX_TITLE_LENGTH` characters and `MAX_TITLE_WORDS` words.
|
|
116
|
+
* Both budgets apply: a wordy title is cut back to `TRIMMED_TITLE_WORDS` words
|
|
117
|
+
* and the survivors are still trimmed at a word boundary to fit the character
|
|
118
|
+
* budget, so the returned string is never longer than `MAX_TITLE_LENGTH`.
|
|
119
|
+
*/
|
|
120
|
+
export function truncateTitle(title: string): string {
|
|
121
|
+
if (title.length <= MAX_TITLE_LENGTH) {
|
|
122
|
+
return title;
|
|
123
|
+
}
|
|
124
|
+
const words = title.split(/\s+/);
|
|
125
|
+
const kept =
|
|
126
|
+
words.length > MAX_TITLE_WORDS
|
|
127
|
+
? words.slice(0, TRIMMED_TITLE_WORDS)
|
|
128
|
+
: words;
|
|
129
|
+
let result = "";
|
|
130
|
+
for (const word of kept) {
|
|
131
|
+
const candidate = result ? result + " " + word : word;
|
|
132
|
+
if (candidate.length > MAX_TITLE_LENGTH) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
result = candidate;
|
|
136
|
+
}
|
|
137
|
+
// Empty when even the first word overflows: hard-slice rather than return "".
|
|
138
|
+
return result || title.slice(0, MAX_TITLE_LENGTH);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Heuristic guard for title outputs that are clearly prose: the model
|
|
143
|
+
* reasoning aloud or replying to the conversation rather than naming it. A real
|
|
144
|
+
* title is a single-line short noun phrase, so we reject multi-line output,
|
|
145
|
+
* embedded transcript markers, leading reasoning openers, and sentence-shaped
|
|
146
|
+
* clauses. Deliberately tight: a false reject only costs a deterministic
|
|
147
|
+
* fallback title, while a false accept persists a broken one.
|
|
148
|
+
*/
|
|
149
|
+
function looksLikeLeakedProse(title: string): boolean {
|
|
150
|
+
if (/\n/.test(title)) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (/\b(?:user|assistant)\s*:/i.test(title)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const lower = title.toLowerCase();
|
|
157
|
+
if (LEAKED_PROSE_PREFIXES.some((prefix) => lower.startsWith(prefix))) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
// Sentence-shaped: terminal punctuation on a multi-word clause.
|
|
161
|
+
if (/[.?!]$/.test(title) && title.split(/\s+/).length > 5) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Clean a raw title into a short, scannable label. Returns "" when the input is
|
|
169
|
+
* empty, reads as leaked prose, or is a meta-failure title, signalling that
|
|
170
|
+
* callers should fall back to a deterministic title.
|
|
171
|
+
*/
|
|
172
|
+
export function normalizeTitle(raw: string): string {
|
|
173
|
+
let title = raw.trim().replace(/^["']|["']$/g, "");
|
|
174
|
+
title = stripMarkdown(title);
|
|
175
|
+
title = stripThinkingTags(title).trim();
|
|
176
|
+
if (!title) {
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
// Reject outputs that are the model reasoning aloud or continuing the
|
|
180
|
+
// conversation instead of naming it (e.g. "I need to generate a…", "I'll
|
|
181
|
+
// work through these files…"). Callers fall back to a deterministic title.
|
|
182
|
+
if (looksLikeLeakedProse(title)) {
|
|
183
|
+
return "";
|
|
184
|
+
}
|
|
185
|
+
if (META_FAILURE_TITLES.has(title.toLowerCase())) {
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
return truncateTitle(title);
|
|
189
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace migration `138-backfill-home-feed-titles`.
|
|
3
|
+
*
|
|
4
|
+
* Gives every item in `<workspace>/data/home-feed.json` a non-empty
|
|
5
|
+
* `title`. The feed writer sets one on every item it appends; stored
|
|
6
|
+
* items that lack the field get a headline derived from their own
|
|
7
|
+
* `summary`, so the field is uniformly present across the file.
|
|
8
|
+
*
|
|
9
|
+
* Behaviour:
|
|
10
|
+
* - Missing file, unparseable JSON, or a non-object root: no-op.
|
|
11
|
+
* - Item that already has a non-empty `title`: untouched.
|
|
12
|
+
* - Item without one: title derived from `summary` (markdown and
|
|
13
|
+
* newlines flattened, first sentence, capped at 60 characters with
|
|
14
|
+
* an ellipsis).
|
|
15
|
+
* - `version`, `updatedAt`, and every other item field are preserved.
|
|
16
|
+
*
|
|
17
|
+
* Idempotent: a second run finds every item titled, so it writes
|
|
18
|
+
* nothing. The runner's checkpoint also skips re-runs, but this in-file
|
|
19
|
+
* guard keeps the migration safe even if the checkpoint is wiped.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
|
|
25
|
+
import { getLogger } from "../../util/logger.js";
|
|
26
|
+
import type { WorkspaceMigration } from "./types.js";
|
|
27
|
+
|
|
28
|
+
const log = getLogger("workspace-migration-138-backfill-home-feed-titles");
|
|
29
|
+
|
|
30
|
+
const HOME_FEED_RELATIVE_PATH = join("data", "home-feed.json");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Matches `NOTIFICATION_TITLE_MAX_LENGTH` in
|
|
34
|
+
* `notifications/notification-utils.ts`, the cap on the headline the feed
|
|
35
|
+
* writer derives from a summary, so a backfilled item and a freshly
|
|
36
|
+
* written one with the same summary carry the same title.
|
|
37
|
+
*/
|
|
38
|
+
const MAX_TITLE_LENGTH = 60;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The persisted item fields this migration touches. Inlined rather than
|
|
42
|
+
* imported from `home/feed-types.ts` so the migration stays
|
|
43
|
+
* self-contained per the migrations AGENTS.md.
|
|
44
|
+
*/
|
|
45
|
+
interface PersistedFeedItem {
|
|
46
|
+
/** Missing, empty, or non-string on the items repaired here. */
|
|
47
|
+
title?: unknown;
|
|
48
|
+
/** Source text for the derived title. */
|
|
49
|
+
summary?: unknown;
|
|
50
|
+
/** Every other persisted field is carried through untouched. */
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const backfillHomeFeedTitlesMigration: WorkspaceMigration = {
|
|
55
|
+
id: "138-backfill-home-feed-titles",
|
|
56
|
+
description:
|
|
57
|
+
"Backfill a summary-derived title on home-feed items that lack one",
|
|
58
|
+
|
|
59
|
+
run(workspaceDir: string): void {
|
|
60
|
+
const path = join(workspaceDir, HOME_FEED_RELATIVE_PATH);
|
|
61
|
+
if (!existsSync(path)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Read outside the parse catch: a transient filesystem error (EIO,
|
|
66
|
+
// EACCES) must reach the runner so the migration retries, while
|
|
67
|
+
// malformed JSON is a permanent state this migration cannot repair.
|
|
68
|
+
const rawText = readFileSync(path, "utf-8");
|
|
69
|
+
|
|
70
|
+
let feed: Record<string, unknown>;
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(rawText);
|
|
73
|
+
if (!isPlainObject(parsed)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
feed = parsed;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
log.warn(
|
|
79
|
+
{ err, path },
|
|
80
|
+
"Failed to parse home-feed.json; skipping title backfill",
|
|
81
|
+
);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const rawItems = Array.isArray(feed.items) ? feed.items : [];
|
|
86
|
+
let backfilled = 0;
|
|
87
|
+
for (const entry of rawItems) {
|
|
88
|
+
if (!isPlainObject(entry)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const item: PersistedFeedItem = entry;
|
|
92
|
+
if (typeof item.title === "string" && item.title.trim().length > 0) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (typeof item.summary !== "string") {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const derived = deriveTitle(item.summary);
|
|
99
|
+
if (derived.length === 0) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
item.title = derived;
|
|
103
|
+
backfilled++;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (backfilled === 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Write-then-rename so an interrupted write cannot leave
|
|
111
|
+
// home-feed.json truncated: the reader treats an unparseable file as
|
|
112
|
+
// an empty feed, so a torn in-place write would discard the user's
|
|
113
|
+
// notification history outright.
|
|
114
|
+
const tmpPath = `${path}.migration-138.tmp`;
|
|
115
|
+
writeFileSync(tmpPath, JSON.stringify(feed, null, 2), "utf-8");
|
|
116
|
+
renameSync(tmpPath, path);
|
|
117
|
+
|
|
118
|
+
log.info({ path, backfilled }, "Backfilled titles on home-feed items");
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
// Deriving a title from the summary is idempotent, so a transient
|
|
122
|
+
// failure (full disk, I/O error) is safe to retry on later startups.
|
|
123
|
+
retryFailedCheckpoint: true,
|
|
124
|
+
|
|
125
|
+
down(_workspaceDir: string): void {
|
|
126
|
+
// Forward-only: a derived title is indistinguishable from an
|
|
127
|
+
// authored one, so there is nothing safe to strip back out.
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Helpers: self-contained per the workspace migrations AGENTS.md
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Derive a short headline from a summary: the markdown is flattened to a
|
|
137
|
+
* single line of plain text, the first sentence is taken when the text
|
|
138
|
+
* has a terminator, and the result is capped at `MAX_TITLE_LENGTH`
|
|
139
|
+
* characters with an ellipsis. Returns "" when nothing usable survives.
|
|
140
|
+
*
|
|
141
|
+
* Inlined rather than imported from the notification pipeline so the
|
|
142
|
+
* migration stays self-contained per the migrations AGENTS.md.
|
|
143
|
+
*/
|
|
144
|
+
function deriveTitle(summary: string): string {
|
|
145
|
+
const text = flattenToPlainText(summary);
|
|
146
|
+
const firstSentenceEnd = text.search(/[.!?](\s|$)/);
|
|
147
|
+
const candidate =
|
|
148
|
+
firstSentenceEnd > 0 ? text.slice(0, firstSentenceEnd + 1) : text;
|
|
149
|
+
return candidate.length > MAX_TITLE_LENGTH
|
|
150
|
+
? candidate.slice(0, MAX_TITLE_LENGTH).trim() + "…"
|
|
151
|
+
: candidate.trim();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Reduce markdown-rich summary text to a single line of plain prose:
|
|
156
|
+
* block structure (code fences, headings, blockquotes, list markers) is
|
|
157
|
+
* dropped, inline formatting is unwrapped, and every run of whitespace,
|
|
158
|
+
* newlines included, collapses to one space.
|
|
159
|
+
*/
|
|
160
|
+
function flattenToPlainText(text: string): string {
|
|
161
|
+
return text
|
|
162
|
+
.replace(/^\s{0,3}(?:```|~~~).*$/gm, "")
|
|
163
|
+
.replace(/^\s{0,3}#{1,6}\s+/gm, "")
|
|
164
|
+
.replace(/^\s{0,3}>\s?/gm, "")
|
|
165
|
+
.replace(/^\s{0,3}(?:[-*+]|\d+[.)])\s+/gm, "")
|
|
166
|
+
.replace(/\*\*(.+?)\*\*/g, "$1")
|
|
167
|
+
.replace(/__(.+?)__/g, "$1")
|
|
168
|
+
.replace(/\*(.+?)\*/g, "$1")
|
|
169
|
+
.replace(/(?<!\w)_(.+?)_(?!\w)/g, "$1")
|
|
170
|
+
.replace(/~~(.+?)~~/g, "$1")
|
|
171
|
+
.replace(/`(.+?)`/g, "$1")
|
|
172
|
+
.replace(/\[(.+?)\]\(.*?\)/g, "$1")
|
|
173
|
+
.replace(/\s+/g, " ")
|
|
174
|
+
.trim();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
178
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
179
|
+
}
|
|
@@ -135,6 +135,7 @@ import { imageGenerationModeToProviderMigration } from "./134-image-generation-m
|
|
|
135
135
|
import { copySubstrateTunablesMigration } from "./135-copy-substrate-tunables.js";
|
|
136
136
|
import { repairStaleFireworksKimiModelIdMigration } from "./136-repair-stale-fireworks-kimi-model-id.js";
|
|
137
137
|
import { repairRetiredFireworksMinimaxModelIdMigration } from "./137-repair-retired-fireworks-minimax-model-id.js";
|
|
138
|
+
import { backfillHomeFeedTitlesMigration } from "./138-backfill-home-feed-titles.js";
|
|
138
139
|
import { migrateToWorkspaceVolumeMigration } from "./migrate-to-workspace-volume.js";
|
|
139
140
|
import type { WorkspaceMigration } from "./types.js";
|
|
140
141
|
|
|
@@ -285,4 +286,5 @@ export const WORKSPACE_MIGRATIONS: WorkspaceMigration[] = [
|
|
|
285
286
|
copySubstrateTunablesMigration,
|
|
286
287
|
repairStaleFireworksKimiModelIdMigration,
|
|
287
288
|
repairRetiredFireworksMinimaxModelIdMigration,
|
|
289
|
+
backfillHomeFeedTitlesMigration,
|
|
288
290
|
];
|