Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1301a2b
u917 recut rung 1: the safe-write primitives with the tests that desc…
easonLiangWorldedtech Nov 14, 2026
fc00dd8
u917 recut rung 2: guarded write core with the unwired knip entry and…
easonLiangWorldedtech Nov 14, 2026
26f08b2
u917 recut rung 3: diffview publish and the patch edit tools with the…
easonLiangWorldedtech Nov 14, 2026
9dbc832
u917 recut rung 4: task history store and provider and read write app…
easonLiangWorldedtech Nov 14, 2026
01cc8ee
u917 leg 182: port the private-DACL staging grant and the descriptor …
easonLiangWorldedtech Nov 14, 2026
f94f24b
u917 leg 186: name each icacls step the staging-cleanup row counts p…
easonLiangWorldedtech Nov 14, 2026
1d86e6b
u917 leg 187: resolve the staging account from the host when USERNAME…
easonLiangWorldedtech Nov 14, 2026
2662d84
test(u9b): pin five reviewer rows on the guarded-write and safety specs
easonLiangWorldedtech Nov 15, 2026
ab6a6ff
test(u9b): pin the guard rows the 2445 review asks name
easonLiangWorldedtech Nov 15, 2026
4fb1787
fix(types): import Stats and LegacyReadFileParams in the read-file to…
easonLiangWorldedtech Nov 29, 2026
e54cf89
test(2445): prove the placeholder cleanup unlinks under the same lock
easonLiangWorldedtech Nov 29, 2026
0c75bb8
test(2445): tie directory removal to a successful placeholder unlink
easonLiangWorldedtech Nov 29, 2026
4001987
test(2445): gate the publish so a mid-write keystroke is observable
easonLiangWorldedtech Nov 29, 2026
90c3582
test(2445): order the activation, revert, and focus restore in one trace
easonLiangWorldedtech Nov 29, 2026
c253850
test(2445): seed the autosave adoption tests with a distinct prior token
easonLiangWorldedtech Nov 29, 2026
a63319e
test(2445): fail the teardown race when the owner never enters cleanup
easonLiangWorldedtech Nov 29, 2026
e005523
test(2445): prove the cancellation stays parked during the save cleanup
easonLiangWorldedtech Nov 29, 2026
eb4c180
test(2445): handle the expected rejection where the operation starts
easonLiangWorldedtech Nov 29, 2026
99fe6fd
fix(2445): let only the first waiting cancellation close the session
easonLiangWorldedtech Nov 29, 2026
6f2f9b1
test(2445): prove the teardown close claim is cleared for each new pass
easonLiangWorldedtech Nov 29, 2026
a1ec5fc
test(2445): inspect the registry while the post-read stat is still pe…
easonLiangWorldedtech Nov 29, 2026
364ebb1
test(2445): run the completeness cases through the real reader
easonLiangWorldedtech Nov 29, 2026
cdb8610
refactor(2445): read filesystem error codes through the shared conver…
easonLiangWorldedtech Nov 29, 2026
d454059
fix(2445): sweep the leftovers beside the named path before removing it
easonLiangWorldedtech Nov 29, 2026
b2747b9
fix(2445): scan the named directory before certifying absence without…
easonLiangWorldedtech Nov 29, 2026
bb609a6
fix(2445): read the task file again after a probe that found no lock
easonLiangWorldedtech Nov 29, 2026
4ac93ee
fix(2445): publish a new file with the rights of the directory it lan…
easonLiangWorldedtech Nov 29, 2026
702b163
fix(2445): ask the buffer again after activating it for a forced revert
easonLiangWorldedtech Nov 29, 2026
1379997
fix(2445): refuse to heal and publish when the target moved out of th…
easonLiangWorldedtech Nov 29, 2026
7aa34eb
fix(2445): name each guard verdict so only a stale version may be ado…
easonLiangWorldedtech Nov 29, 2026
c940e48
fix(2445): recheck the held lock key against the publish target after…
easonLiangWorldedtech Nov 29, 2026
902c134
test(2445): pin that an ordinary first write survives a key that diff…
easonLiangWorldedtech Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"!utils/versionToken.ts!",
"!services/tools/Bm25Ranker.ts!",
"!services/tools/types.ts!",
"!core/tools/helpers/toolResultFormatting.ts!"
"!core/tools/helpers/toolResultFormatting.ts!",
"!core/tools/guardedWrite.ts!"
],
"ignoreDependencies": [
"@roo-code/config-typescript",
Expand Down
660 changes: 644 additions & 16 deletions src/core/task-persistence/TaskHistoryStore.ts

Large diffs are not rendered by default.

1,550 changes: 1,513 additions & 37 deletions src/core/task-persistence/__tests__/TaskHistoryStore.deleteSemantics.spec.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/task-persistence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {
} from "./taskMessages"
export { taskMetadata } from "./taskMetadata"
export { ensureMessageIdentifiers } from "./mergeMessageSnapshots"
export { TaskHistoryStore } from "./TaskHistoryStore"
export { TaskHistoryDeleteError, TaskHistoryStore } from "./TaskHistoryStore"
export {
abandonDelegatedChild,
assertValidTransition,
Expand Down
27 changes: 27 additions & 0 deletions src/core/task/__tests__/Task.dispose.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/core/task/__tests__/observationRegistry.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/core/task/observationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ export class ObservationRegistry {
return this.entries.has(absolutePath)
}

/**
* Drop the observation for one path. A caller that must revoke an
* authorization it did not earn - a preview that observed a version the model
* never read - needs this instead of clear(), which would also discard the
* observations other reads of the same task still rely on.
*/
forget(absolutePath: string): boolean {
return this.entries.delete(absolutePath)
}

clear(): void {
this.entries.clear()
}
Expand Down
56 changes: 54 additions & 2 deletions src/core/tools/ApplyDiffTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TelemetryService } from "@roo-code/telemetry"

import { getReadablePath } from "../../utils/path"
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
import { versionTokenOfStat } from "../../utils/versionToken"
import { Task } from "../task/Task"
import { formatResponse } from "../prompts/responses"
import { fileExistsAtPath } from "../../utils/fs"
Expand All @@ -15,6 +16,7 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import type { DiffResult, ToolUse } from "../../shared/tools"

import { canonicalizeForApproval } from "./guardedWrite"
import { BaseTool, ToolCallbacks } from "./BaseTool"

interface ApplyDiffParams {
Expand Down Expand Up @@ -74,7 +76,32 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
return
}

// The diff below is built from this exact read, so the save that follows must be
// authorized against the version captured here - not against whatever version the
// preview happens to stat afterwards. Same contract as ApplyPatchTool's hunk read:
// stat around the read and observe only when the file did not change underneath it.
const preReadStats = await fs.stat(absolutePath, { bigint: true }).catch(() => undefined)
const originalContent: string = await fs.readFile(absolutePath, "utf-8")
const postReadStats = await fs.stat(absolutePath, { bigint: true }).catch(() => undefined)
if (preReadStats && postReadStats) {
const preReadToken = versionTokenOfStat(preReadStats)
if (preReadToken === versionTokenOfStat(postReadStats)) {
// A tool read is not a model read. With no prior observation this stays a
// partial observation of the version the diff was computed against - the only
// authorization the save can have, since apply_diff computes its hunks from
// this read. When the model already observed the file, keep the completeness it
// earned, but only on the version it was earned on: refreshing an OLDER
// observation to the current version would let content the model built from a
// stale read pass the compare-and-swap, so an out-of-date observation is left
// alone and the save fails with the re-read remediation.
const prior = task.observationRegistry.get(absolutePath)
if (prior === undefined) {
task.observationRegistry.observe(absolutePath, preReadToken, false)
} else if (prior.version === preReadToken) {
task.observationRegistry.observe(absolutePath, preReadToken, prior.complete === true)
}
}
}

// Apply the diff to the original content
const diffResult = (await task.diffStrategy?.applyDiff(
Expand Down Expand Up @@ -139,7 +166,19 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {

// Check if file is write-protected
const isWriteProtected = task.rooProtectedController?.isWriteProtected(relPath) || false

// The guard in guardedWrite refuses a target outside every workspace root unless the tool
// layer says the user approved this one, and it binds the publish to the identity that was
// approved. apply_diff has both save paths behind an askApproval, so it has to carry both
// through; without them an approved write outside the workspace is rejected by its own guard.
const isOutsideWorkspace = isPathOutsideWorkspace(absolutePath)
// Captured before the approval is asked: guardedWrite binds the publish to this identity, so
// a name repointed between the approval and the publish is refused instead of publishing to
// whatever the name points at by then. Inside the try so an unresolvable target goes through
// the tool's normal error handling and the diff-view reset.
const approvedCanonicalTarget = isOutsideWorkspace
? await canonicalizeForApproval(absolutePath, relPath)
: undefined

const sharedMessageProps: ClineSayTool = {
tool: "appliedDiff",
Expand Down Expand Up @@ -177,7 +216,8 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
return
}

// Save directly without showing diff view or opening the file
// Save directly without showing diff view or opening the file. The diff is
// applied to an existing file, so edit-guard semantics require a prior read.
task.diffViewProvider.editType = "modify"
task.diffViewProvider.originalContent = originalContent
await task.diffViewProvider.saveDirectly(
Expand All @@ -186,6 +226,12 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
false,
diagnosticsEnabled,
writeDelayMs,
"edit",
// Seventh parameter is completeOverride (this call claims no completeness of its
// own); the eighth is the approval flag for a target outside every workspace root.
undefined,
isOutsideWorkspace,
approvedCanonicalTarget,
)
} else {
// Original behavior with diff view
Expand Down Expand Up @@ -225,7 +271,13 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
}

// Call saveChanges to update the DiffViewProvider properties
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
await task.diffViewProvider.saveChanges(
diagnosticsEnabled,
writeDelayMs,
"edit",
isOutsideWorkspace,
approvedCanonicalTarget,
)
}

// Track file edit operation
Expand Down
Loading
Loading