Skip to content

Commit 628bb2b

Browse files
committed
refactor(task): remove handoff aliases
1 parent 87e6176 commit 628bb2b

4 files changed

Lines changed: 16 additions & 29 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ 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) return INVALID_TASK_FILE_PREIMAGE
26-
if (fileExists) return INVALID_TASK_FILE_PREIMAGE
25+
if (existing !== null || fileExists) return INVALID_TASK_FILE_PREIMAGE
2726
return ABSENT_TASK_FILE_PREIMAGE
2827
}
2928

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -908,15 +908,8 @@ 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-
918911
private buildDelta(id: string, cached: HistoryItem, incoming: Partial<HistoryItem>): Partial<HistoryItem> {
919-
return { id, ...this.computeDelta(cached, incoming) }
912+
return { id, ...computeHistoryDelta(cached, incoming) }
920913
}
921914

922915
/**
@@ -954,10 +947,9 @@ export class TaskHistoryStore {
954947
},
955948
})
956949
return written
957-
} else {
958-
await safeWriteJson(filePath, item)
959-
return item
960950
}
951+
await safeWriteJson(filePath, item)
952+
return item
961953
}
962954

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

12571248
try {
12581249
let firstDiskSnapshot!: TaskFilePreImage
1259-
const firstDiskGuard = options?.firstDiskGuard
12601250
const firstDelta = this.buildDelta(firstId, first, updatedFirst)
1261-
const writtenFirst = await this.writeTaskFile(mergedFirst, firstDelta, firstDiskGuard, {
1251+
const writtenFirst = await this.writeTaskFile(mergedFirst, firstDelta, options?.firstDiskGuard, {
12621252
heldLock: firstFileLock,
12631253
capturePreImage: (preImage) => (firstDiskSnapshot = preImage),
12641254
})
@@ -1275,11 +1265,13 @@ export class TaskHistoryStore {
12751265
const firstRestoration = [firstId, firstDiskSnapshot, expectedFirst, firstFileLock] as const
12761266
const restorations = Array.of<TaskFileRestoration>(firstRestoration)
12771267
if (secondDiskSnapshot) {
1278-
const mergeSecond = mergeWithDisk(secondDelta)
12791268
const secondPreImage = isValidTaskFilePreImage(secondDiskSnapshot)
12801269
? secondDiskSnapshot
12811270
: null
1282-
const expectedSecond = mergeSecond(secondPreImage, mergedSecond) as HistoryItem
1271+
const expectedSecond = mergeWithDisk(secondDelta)(
1272+
secondPreImage,
1273+
mergedSecond,
1274+
) as HistoryItem
12831275
const persistedSecond = JSON.parse(JSON.stringify(expectedSecond)) as HistoryItem
12841276
const expectedSecondStates = expectedTaskFileStates(persistedSecond, secondDiskSnapshot)
12851277
restorations.unshift([secondId, secondDiskSnapshot, expectedSecondStates])
@@ -1323,12 +1315,12 @@ export class TaskHistoryStore {
13231315
}
13241316
}
13251317

1326-
const callbackErrors = Array.of(error, ...compensationErrors)
1327-
if (compensationErrors.length) throw new AggregateError(callbackErrors, "Pair compensation failed")
1318+
if (compensationErrors.length)
1319+
throw new AggregateError(Array.of(error, ...compensationErrors), "Pair compensation failed")
13281320
throw error
13291321
}
13301322
} finally {
1331-
if (ownsFirstFileLock) await firstFileLock!()
1323+
if (firstFileLock && !suppliedFirstFileLock) await firstFileLock()
13321324
}
13331325
}
13341326
return options?.storeLockAcquired ? update() : this.withLock(update)

‎src/core/webview/ClineProvider.ts‎

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

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

‎src/utils/safeWriteJson.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ 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)
4039
let compromisedError: Error | undefined
4140

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

4544
const release = await lockfile.lock(absoluteFilePath, {
4645
stale: LOCK_STALE_MS,

0 commit comments

Comments
 (0)