Skip to content

Commit a8ea1b4

Browse files
merge trunk d76dffa into 2357 (vps2f-1914-u5b) for the declared merge order
Trunk commit carried: feat(task-title): auto-generate task titles for new root tasks (#2398); the trunk tip was read over transport as refs/heads/main = d76dffa, and the merge base with this branch is 5f42a91, one commit behind that tip before this merge. What landed from the trunk: 58 files, 2622 insertions and 30 deletions, 113 hunks over 54 files. Unmerged paths: 0, and the two sides changed disjoint path sets: 24 files for this unit since the merge base and 58 for the trunk commit, with no path in common, so there was nothing to reconcile. git show --remerge-diff on this commit prints no hunk at all, which is the proof that the merge added nothing beyond the automatic merge and dropped neither intent. Control taken in this worktree at f1090c1 before the merge, over an in-tree workspace install (40 workspace-name links point into this tree, 56 manifests byte-identical to the blobs this head carries, no dependency resolution lands on another tree source): root tsc exit 0, src tsc exit 0, repository root gate pnpm run check-types exit 0 with 12 tasks, prettier --check over the 68 payload files present at the parent head exit 0, eslint --max-warnings=0 over 29 src and 13 webview-ui payload files exit 0 with the prune rewrite restored to the head blob, vitest over src 62 files and 1883 tests, webview-ui 51 files and 738 tests, packages/types 38 files and 642 tests, 0 failing rows.
2 parents f1090c1 + d76dffa commit a8ea1b4

58 files changed

Lines changed: 2622 additions & 30 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/vscode-e2e/src/suite/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export async function run() {
2727
openRouterApiKey: aimockUrl && !isRecord ? "mock-key" : process.env.OPENROUTER_API_KEY!,
2828
openRouterModelId: "openai/gpt-4.1",
2929
...(aimockUrl && { openRouterBaseUrl: `${aimockUrl}/v1` }),
30+
// Title requests embed the task prompt, so they match prompt-substring fixtures and
31+
// consume their sequenceIndex slots ahead of the task's own requests.
32+
taskTitleGenerationEnabled: false,
3033
})
3134

3235
await vscode.commands.executeCommand("zoo-code.SidebarProvider.focus")

‎apps/vscode-e2e/src/visual/sceneController.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export async function run(): Promise<void> {
108108
openRouterModelId: "openai/gpt-4.1",
109109
openRouterBaseUrl: `${aimockUrl}/v1`,
110110
telemetrySetting: "disabled",
111+
// A generated title lands asynchronously and would race the task header screenshot.
112+
taskTitleGenerationEnabled: false,
111113
})
112114
await log(`aimock=${aimockUrl}`)
113115
let completionHandler: ((event: { message: ClineMessage }) => void) | undefined

‎packages/types/src/global-settings.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export const DEFAULT_COLLAPSE_COMMAND_OUTPUT_BY_DEFAULT = false
5454

5555
export const DEFAULT_DESTRUCTIVE_COMMAND_GUARD_ENABLED = false
5656

57+
/** Whether new root tasks get a short generated title in the background. */
58+
export const DEFAULT_TASK_TITLE_GENERATION_ENABLED = true
59+
5760
/**
5861
* Whether commands that are not explicitly auto-approved are automatically
5962
* denied (with a structured reason sent to the model) instead of prompting the
@@ -273,6 +276,8 @@ export const globalSettingsSchema = z.object({
273276
customSupportPrompts: customSupportPromptsSchema.optional(),
274277
enhancementApiConfigId: z.string().optional(),
275278
includeTaskHistoryInEnhance: z.boolean().optional(),
279+
taskTitleGenerationEnabled: z.boolean().optional(),
280+
taskTitleApiConfigId: z.string().optional(),
276281
historyPreviewCollapsed: z.boolean().optional(),
277282
reasoningBlockCollapsed: z.boolean().optional(),
278283
/**

‎packages/types/src/history.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const historyItemSchema = z.object({
3434
ts: z.number(),
3535
task: z.string(),
3636
title: z.string().optional(), // User-assigned display name; `task` keeps the original prompt
37+
autoTitle: z.string().optional(), // Generated display name; `title` (manual) takes precedence
3738
tokensIn: z.number(),
3839
tokensOut: z.number(),
3940
cacheWrites: z.number().optional(),

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ export type ExtensionState = Pick<
340340
| "imageGenerationProvider"
341341
| "openRouterImageGenerationSelectedModel"
342342
| "includeTaskHistoryInEnhance"
343+
| "taskTitleGenerationEnabled"
344+
| "taskTitleApiConfigId"
343345
| "reasoningBlockCollapsed"
344346
| "chatFontSize"
345347
| "timeFormat"

‎scripts/check-task-store-concurrency.ts‎

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type OperationId =
2525
| "stale-save-a"
2626
| "abandon-b"
2727
| "reject-a"
28+
| "rename-a"
29+
| "auto-title-a"
30+
| "auto-title-b"
31+
| "delete-a"
2832
type RecordMap = Partial<Record<TaskId, HistoryItem>>
2933

3034
interface PreparedWrite {
@@ -34,7 +38,7 @@ interface PreparedWrite {
3438
}
3539

3640
interface OperationState {
37-
phase: "idle" | "read" | "prepared" | "revalidated" | "done" | "rejected" | "failed"
41+
phase: "idle" | "read" | "prepared" | "revalidated" | "done" | "rejected" | "skipped" | "failed"
3842
snapshot?: RecordMap
3943
writes?: PreparedWrite[]
4044
writeIndex: number
@@ -64,6 +68,13 @@ interface OperationSpec {
6468
externalSnapshot?: boolean
6569
allowRefreshAfterRead?: boolean
6670
publishCacheAtEnd?: boolean
71+
/**
72+
* "auto-title" mirrors TaskHistoryStore.setAutoTitleIfAbsent: under the file lock the write is
73+
* skipped when the persisted record is gone or already carries an autoTitle, and a commit copies
74+
* only autoTitle into the host cache.
75+
* "delete" removes the persisted record.
76+
*/
77+
kind?: "auto-title" | "delete"
6778
isEnabled?(snapshot: RecordMap): boolean
6879
buildWrites(snapshot: RecordMap): HistoryItem[]
6980
}
@@ -113,6 +124,12 @@ const semanticLandmarks = {
113124
state.commits.filter((entry) => entry.operationId === "complete-a").length === 1 &&
114125
state.caches.A["child-a"]?.status === "completed" &&
115126
state.caches.A.parent?.status === "delegated",
127+
"auto-title-skipped-after-delete": (state: ModelState) =>
128+
Object.values(state.operations).some((operation) => operation.phase === "skipped") &&
129+
state.operations["delete-a"]?.phase === "done" &&
130+
state.disk["child-a"] === undefined,
131+
"manual-and-auto-title-coexist": (state: ModelState) =>
132+
Boolean(state.disk["child-a"]?.title) && Boolean(state.disk["child-a"]?.autoTitle),
116133
} satisfies Record<string, (state: ModelState) => boolean>
117134

118135
function item(id: TaskId, overrides: Partial<HistoryItem> = {}): HistoryItem {
@@ -248,6 +265,32 @@ const operationSpecs: Record<OperationId, OperationSpec> = {
248265
return [abandoned.child, abandoned.parent]
249266
},
250267
},
268+
"rename-a": {
269+
id: "rename-a",
270+
host: "A",
271+
buildWrites: (snapshot) => [{ ...getRequired(snapshot, "child-a"), title: "manual" }],
272+
},
273+
"auto-title-a": {
274+
id: "auto-title-a",
275+
host: "A",
276+
kind: "auto-title",
277+
isEnabled: (snapshot) => snapshot["child-a"] !== undefined,
278+
buildWrites: (snapshot) => [{ ...getRequired(snapshot, "child-a"), autoTitle: "generated-a" }],
279+
},
280+
"auto-title-b": {
281+
id: "auto-title-b",
282+
host: "B",
283+
kind: "auto-title",
284+
isEnabled: (snapshot) => snapshot["child-a"] !== undefined,
285+
buildWrites: (snapshot) => [{ ...getRequired(snapshot, "child-a"), autoTitle: "generated-b" }],
286+
},
287+
"delete-a": {
288+
id: "delete-a",
289+
host: "A",
290+
kind: "delete",
291+
isEnabled: (snapshot) => snapshot["child-a"] !== undefined,
292+
buildWrites: (snapshot) => [getRequired(snapshot, "child-a")],
293+
},
251294
"reject-a": {
252295
id: "reject-a",
253296
host: "A",
@@ -316,6 +359,13 @@ function nextSteps(state: ModelState, scenario: Scenario): TraceStep[] {
316359
const target = next.operations[spec.id]!
317360
const targetWrite = target.writes![target.writeIndex]!
318361
next.locks[targetWrite.taskId] = spec.id
362+
const persisted = next.disk[targetWrite.taskId]
363+
if (spec.kind === "auto-title" && (!persisted || persisted.autoTitle)) {
364+
target.phase = "skipped"
365+
delete next.locks[targetWrite.taskId]
366+
delete next.hostMutexes[spec.host]
367+
return
368+
}
319369
try {
320370
target.candidate = mergeHistoryDelta(
321371
next.disk[targetWrite.taskId],
@@ -342,15 +392,29 @@ function nextSteps(state: ModelState, scenario: Scenario): TraceStep[] {
342392
throw new Error(`${spec.id} committed without owning ${targetWrite.taskId}`)
343393
}
344394
const previous = next.disk[targetWrite.taskId]
345-
next.disk[targetWrite.taskId] = target.candidate
346-
if (!spec.publishCacheAtEnd) next.caches[spec.host][targetWrite.taskId] = target.candidate
347-
next.commits.push({
348-
operationId: spec.id,
349-
taskId: targetWrite.taskId,
350-
previous,
351-
delta: targetWrite.delta,
352-
next: target.candidate,
353-
})
395+
if (spec.kind === "delete") {
396+
delete next.disk[targetWrite.taskId]
397+
delete next.caches[spec.host][targetWrite.taskId]
398+
} else {
399+
next.disk[targetWrite.taskId] = target.candidate
400+
const cached = next.caches[spec.host][targetWrite.taskId]
401+
if (spec.kind === "auto-title" && cached) {
402+
// setAutoTitleIfAbsent copies only autoTitle so the cache stays this host's save baseline.
403+
next.caches[spec.host][targetWrite.taskId] = {
404+
...cached,
405+
autoTitle: target.candidate.autoTitle,
406+
}
407+
} else if (!spec.publishCacheAtEnd) {
408+
next.caches[spec.host][targetWrite.taskId] = target.candidate
409+
}
410+
next.commits.push({
411+
operationId: spec.id,
412+
taskId: targetWrite.taskId,
413+
previous,
414+
delta: targetWrite.delta,
415+
next: target.candidate,
416+
})
417+
}
354418
delete next.locks[targetWrite.taskId]
355419
target.candidate = undefined
356420
target.writeIndex++
@@ -681,6 +745,59 @@ const scenarios: Scenario[] = [
681745
},
682746
check: () => [],
683747
},
748+
{
749+
name: "auto title vs manual rename",
750+
operations: [operationSpecs["rename-a"], operationSpecs["auto-title-b"]],
751+
check: (state) => {
752+
if (state.operations["rename-a"]?.phase !== "done" || state.operations["auto-title-b"]?.phase !== "done") {
753+
return []
754+
}
755+
const record = state.disk["child-a"]
756+
return record?.title === "manual" && record.autoTitle === "generated-b"
757+
? []
758+
: ["auto title and manual title did not both survive"]
759+
},
760+
},
761+
{
762+
name: "auto title vs stale save",
763+
operations: [operationSpecs["stale-save-a"], operationSpecs["auto-title-b"]],
764+
check: (state) => {
765+
if (
766+
state.operations["stale-save-a"]?.phase !== "done" ||
767+
state.operations["auto-title-b"]?.phase !== "done"
768+
) {
769+
return []
770+
}
771+
const record = state.disk["child-a"]
772+
return record?.autoTitle === "generated-b" && record.tokensOut === 1
773+
? []
774+
: ["stale save erased the auto title or lost its own update"]
775+
},
776+
},
777+
{
778+
name: "auto title vs delete",
779+
operations: [operationSpecs["delete-a"], operationSpecs["auto-title-b"]],
780+
check: (state) => {
781+
const autoTitle = state.operations["auto-title-b"]?.phase
782+
if (state.operations["delete-a"]?.phase !== "done" || (autoTitle !== "done" && autoTitle !== "skipped")) {
783+
return []
784+
}
785+
return state.disk["child-a"] === undefined ? [] : ["auto title resurrected a deleted record"]
786+
},
787+
},
788+
{
789+
name: "auto title never overwritten",
790+
operations: [operationSpecs["auto-title-a"], operationSpecs["auto-title-b"]],
791+
check: (state) => {
792+
const phases = [state.operations["auto-title-a"]?.phase, state.operations["auto-title-b"]?.phase]
793+
if (!phases.every((phase) => phase === "done" || phase === "skipped")) return []
794+
const titleCommits = state.commits.filter((entry) => entry.taskId === "child-a" && entry.delta.autoTitle)
795+
const first = titleCommits[0]
796+
return titleCommits.length === 1 && state.disk["child-a"]?.autoTitle === first?.next.autoTitle
797+
? []
798+
: ["a second auto title overwrote the first"]
799+
},
800+
},
684801
]
685802

686803
let totalStates = 0

‎src/__tests__/ClineProvider.delegation.spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
12051205
// The real deletion path: the store swallows a per-file history
12061206
// lock failure, so deleteMany resolves and cleanup continues.
12071207
deleteTaskWithId: ClineProvider.prototype.deleteTaskWithId,
1208+
taskTitleService: { cancel: vi.fn() },
12081209
createTaskWithHistoryItem,
12091210
log: vi.fn(),
12101211
postStateToWebview: vi.fn().mockResolvedValue(undefined),

‎src/core/task-persistence/TaskHistoryStore.ts‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ interface DelegationRepairIntent {
7171
/**
7272
* Options for TaskHistoryStore constructor.
7373
*/
74+
type AutoTitleDiskRead = { kind: "found"; item: HistoryItem } | { kind: "missing" } | { kind: "unreadable" }
75+
7476
export interface TaskHistoryStoreOptions {
7577
/**
7678
* Optional callback invoked inside the write lock after each mutation
@@ -1024,6 +1026,112 @@ export class TaskHistoryStore {
10241026
})
10251027
}
10261028

1029+
/**
1030+
* Record a generated title unless the task already has one. The persisted record is re-checked
1031+
* under the per-file lock, so a task deleted by another host is never resurrected and a title
1032+
* written by another host is never overwritten. Only a confirmed missing file evicts the cache:
1033+
* a read or parse failure leaves it intact so a later save still merges against a known record.
1034+
*/
1035+
public setAutoTitleIfAbsent(taskId: string, autoTitle: string): Promise<{ applied: boolean; item?: HistoryItem }> {
1036+
return this.withLock(async () => {
1037+
const title = autoTitle.trim()
1038+
const disk = await this.readTaskFileForAutoTitle(taskId)
1039+
if (disk.kind !== "found") {
1040+
return this.settleSkippedAutoTitle(taskId, disk)
1041+
}
1042+
if (disk.item.autoTitle || !title) {
1043+
return this.settleSkippedAutoTitle(taskId, disk)
1044+
}
1045+
1046+
const skipped = Symbol("auto-title-skipped")
1047+
let persisted: HistoryItem | undefined
1048+
try {
1049+
const filePath = await this.getTaskFilePath(taskId)
1050+
await safeWriteJson(
1051+
filePath,
1052+
{ ...disk.item, autoTitle: title },
1053+
{
1054+
merge: (existing) => {
1055+
const current = existing as Partial<HistoryItem> | null
1056+
if (!current || current.id !== taskId || current.autoTitle) {
1057+
throw Object.assign(new Error("auto title skipped"), { [skipped]: true })
1058+
}
1059+
persisted = { ...(current as HistoryItem), autoTitle: title }
1060+
return persisted
1061+
},
1062+
},
1063+
)
1064+
} catch (error) {
1065+
if (!(error instanceof Error) || !(skipped in error)) {
1066+
throw error
1067+
}
1068+
// safeWriteJson reports both a missing and an unparsable file as `null`, so re-read to tell them apart.
1069+
return this.settleSkippedAutoTitle(taskId, await this.readTaskFileForAutoTitle(taskId))
1070+
}
1071+
1072+
if (!persisted) {
1073+
return { applied: false }
1074+
}
1075+
this.cacheAutoTitle(persisted)
1076+
if (this.onWrite) {
1077+
await this.onWrite(this.getAll())
1078+
}
1079+
return { applied: true, item: persisted }
1080+
})
1081+
}
1082+
1083+
/**
1084+
* Copy only `autoTitle` from the disk record onto the cached one. The cache is the baseline that
1085+
* later saves diff against, so taking the peer's other fields here would let a stale snapshot
1086+
* from this host write its old values back over them. Callers still return the full disk record
1087+
* for display.
1088+
*/
1089+
private cacheAutoTitle(disk: HistoryItem): void {
1090+
const cached = this.cache.get(disk.id)
1091+
this.cache.set(disk.id, cached ? { ...cached, autoTitle: disk.autoTitle } : disk)
1092+
}
1093+
1094+
private settleSkippedAutoTitle(taskId: string, disk: AutoTitleDiskRead): { applied: false; item?: HistoryItem } {
1095+
switch (disk.kind) {
1096+
case "found":
1097+
this.cacheAutoTitle(disk.item)
1098+
return { applied: false, item: disk.item }
1099+
case "missing":
1100+
this.cache.delete(taskId)
1101+
return { applied: false }
1102+
case "unreadable":
1103+
return { applied: false, item: this.cache.get(taskId) }
1104+
}
1105+
}
1106+
1107+
private async readTaskFileForAutoTitle(taskId: string): Promise<AutoTitleDiskRead> {
1108+
let raw: string
1109+
try {
1110+
raw = await readFileWithMissingRetry(await this.getTaskFilePath(taskId))
1111+
} catch (error) {
1112+
if (getErrorCode(error) === "ENOENT") {
1113+
return { kind: "missing" }
1114+
}
1115+
return this.unreadableForAutoTitle(taskId, error)
1116+
}
1117+
try {
1118+
const item: unknown = JSON.parse(raw)
1119+
const id = typeof item === "object" && item !== null ? (item as { id?: unknown }).id : undefined
1120+
if (id !== taskId) {
1121+
return this.unreadableForAutoTitle(taskId, `task file has id ${JSON.stringify(id)}`)
1122+
}
1123+
return { kind: "found", item: item as HistoryItem }
1124+
} catch (error) {
1125+
return this.unreadableForAutoTitle(taskId, error)
1126+
}
1127+
}
1128+
1129+
/** The caller only sees `applied: false`, so the reason is logged here. */
1130+
private unreadableForAutoTitle(taskId: string, reason: unknown): AutoTitleDiskRead {
1131+
console.warn(`[TaskHistoryStore] Failed to read task ${taskId} for auto title:`, reason)
1132+
return { kind: "unreadable" }
1133+
}
1134+
10271135
/**
10281136
* Update two related HistoryItems within a single in-process lock acquisition.
10291137
* Both updaters run synchronously (no I/O, no lock re-entry). Both writes

0 commit comments

Comments
 (0)