Skip to content

Commit 63d1647

Browse files
committed
Revert "refactor(task): remove handoff aliases"
This reverts commit 628bb2b.
1 parent 628bb2b commit 63d1647

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

‎packages/core/src/task-history/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export type TaskFilePreImage = HistoryItem | typeof ABSENT_TASK_FILE_PREIMAGE |
2222
export function taskFilePreImage(existing: unknown, taskId: string, fileExists: boolean): TaskFilePreImage {
2323
const parsed = historyItemSchema.safeParse(existing)
2424
if (parsed.success && parsed.data.id === taskId) return structuredClone(existing as HistoryItem)
25-
if (existing !== null || fileExists) return INVALID_TASK_FILE_PREIMAGE
25+
if (existing !== null) return INVALID_TASK_FILE_PREIMAGE
26+
if (fileExists) return INVALID_TASK_FILE_PREIMAGE
2627
return ABSENT_TASK_FILE_PREIMAGE
2728
}
2829

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,15 @@ export class TaskHistoryStore {
908908
}
909909
}
910910

911+
/**
912+
* Return only the fields in `incoming` that differ from `cached`.
913+
*/
914+
private computeDelta(cached: HistoryItem, incoming: Partial<HistoryItem>): Partial<HistoryItem> {
915+
return computeHistoryDelta(cached, incoming)
916+
}
917+
911918
private buildDelta(id: string, cached: HistoryItem, incoming: Partial<HistoryItem>): Partial<HistoryItem> {
912-
return { id, ...computeHistoryDelta(cached, incoming) }
919+
return { id, ...this.computeDelta(cached, incoming) }
913920
}
914921

915922
/**
@@ -947,9 +954,10 @@ export class TaskHistoryStore {
947954
},
948955
})
949956
return written
957+
} else {
958+
await safeWriteJson(filePath, item)
959+
return item
950960
}
951-
await safeWriteJson(filePath, item)
952-
return item
953961
}
954962

955963
private async reconcileTaskCache(taskId: string): Promise<void> {
@@ -1244,11 +1252,13 @@ export class TaskHistoryStore {
12441252
const firstFileLock =
12451253
suppliedFirstFileLock ??
12461254
(holdFirstFileLock ? await lockJsonFile(await this.getTaskFilePath(firstId)) : undefined)
1255+
const ownsFirstFileLock = Boolean(firstFileLock && !suppliedFirstFileLock)
12471256

12481257
try {
12491258
let firstDiskSnapshot!: TaskFilePreImage
1259+
const firstDiskGuard = options?.firstDiskGuard
12501260
const firstDelta = this.buildDelta(firstId, first, updatedFirst)
1251-
const writtenFirst = await this.writeTaskFile(mergedFirst, firstDelta, options?.firstDiskGuard, {
1261+
const writtenFirst = await this.writeTaskFile(mergedFirst, firstDelta, firstDiskGuard, {
12521262
heldLock: firstFileLock,
12531263
capturePreImage: (preImage) => (firstDiskSnapshot = preImage),
12541264
})
@@ -1265,13 +1275,11 @@ export class TaskHistoryStore {
12651275
const firstRestoration = [firstId, firstDiskSnapshot, expectedFirst, firstFileLock] as const
12661276
const restorations = Array.of<TaskFileRestoration>(firstRestoration)
12671277
if (secondDiskSnapshot) {
1278+
const mergeSecond = mergeWithDisk(secondDelta)
12681279
const secondPreImage = isValidTaskFilePreImage(secondDiskSnapshot)
12691280
? secondDiskSnapshot
12701281
: null
1271-
const expectedSecond = mergeWithDisk(secondDelta)(
1272-
secondPreImage,
1273-
mergedSecond,
1274-
) as HistoryItem
1282+
const expectedSecond = mergeSecond(secondPreImage, mergedSecond) as HistoryItem
12751283
const persistedSecond = JSON.parse(JSON.stringify(expectedSecond)) as HistoryItem
12761284
const expectedSecondStates = expectedTaskFileStates(persistedSecond, secondDiskSnapshot)
12771285
restorations.unshift([secondId, secondDiskSnapshot, expectedSecondStates])
@@ -1315,12 +1323,12 @@ export class TaskHistoryStore {
13151323
}
13161324
}
13171325

1318-
if (compensationErrors.length)
1319-
throw new AggregateError(Array.of(error, ...compensationErrors), "Pair compensation failed")
1326+
const callbackErrors = Array.of(error, ...compensationErrors)
1327+
if (compensationErrors.length) throw new AggregateError(callbackErrors, "Pair compensation failed")
13201328
throw error
13211329
}
13221330
} finally {
1323-
if (firstFileLock && !suppliedFirstFileLock) await firstFileLock()
1331+
if (ownsFirstFileLock) await firstFileLock!()
13241332
}
13251333
}
13261334
return options?.storeLockAcquired ? update() : this.withLock(update)

‎src/core/webview/ClineProvider.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ export class ClineProvider
253253
private historyTaskCreationQueue = Promise.resolve()
254254

255255
private runDelegationTransition<T>(parentTaskId: string, fn: () => Promise<T>): Promise<T> {
256-
return (this.runs ??= new AsyncTaskTracker()).trackIfActive(() =>
256+
const tracker = (this.runs ??= new AsyncTaskTracker())
257+
return tracker.trackIfActive(() =>
257258
runDelegationTransition(ClineProvider.delegationTransitionLocks, parentTaskId, fn),
258259
)
259260
}
@@ -1318,7 +1319,9 @@ export class ClineProvider
13181319
// that only contain 'id' and 'name' fields. Activating such a profile would
13191320
// overwrite the CLI's working API configuration with empty settings.
13201321
const fullProfile = await this.providerSettingsManager.getProfile({ name: profile.name })
1321-
if (fullProfile.apiProvider) {
1322+
const hasActualSettings = !!fullProfile.apiProvider
1323+
1324+
if (hasActualSettings) {
13221325
await this.activateProviderProfile(
13231326
{ name: profile.name },
13241327
{ persistTaskHistory: false },

‎src/utils/safeWriteJson.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ export type JsonFileLock = (() => Promise<void>) & {
3636

3737
export async function lockJsonFile(filePath: string): Promise<JsonFileLock> {
3838
const absoluteFilePath = path.resolve(filePath)
39+
const dirPath = path.dirname(absoluteFilePath)
3940
let compromisedError: Error | undefined
4041

41-
await fs.mkdir(path.dirname(absoluteFilePath), { recursive: true })
42-
await fs.access(path.dirname(absoluteFilePath))
42+
await fs.mkdir(dirPath, { recursive: true })
43+
await fs.access(dirPath)
4344

4445
const release = await lockfile.lock(absoluteFilePath, {
4546
stale: LOCK_STALE_MS,

0 commit comments

Comments
 (0)