Skip to content
Closed
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion packages/opencode/src/session/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { splitWhen } from "remeda"
import { Storage } from "../storage/storage"
import { Bus } from "../bus"
import { SessionPrompt } from "./prompt"
import { FileTime } from "../file/time"
import { SessionSummary } from "./summary"

export namespace SessionRevert {
Expand Down Expand Up @@ -57,6 +58,12 @@ export namespace SessionRevert {
const session = await Session.get(input.sessionID)
revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track())
await Snapshot.revert(patches)
// Update FileTime for reverted files so the edit tool doesn't see them as externally modified
for (const patch of patches) {
for (const file of patch.files) {
FileTime.read(input.sessionID, file)
}
}
if (revert.snapshot) revert.diff = await Snapshot.diff(revert.snapshot)
const rangeMessages = all.filter((msg) => msg.info.id >= revert!.messageID)
const diffs = await SessionSummary.computeDiff({ messages: rangeMessages })
Expand All @@ -82,7 +89,14 @@ export namespace SessionRevert {
SessionPrompt.assertNotBusy(input.sessionID)
const session = await Session.get(input.sessionID)
if (!session.revert) return session
if (session.revert.snapshot) await Snapshot.restore(session.revert.snapshot)
if (session.revert.snapshot) {
const patch = await Snapshot.patch(session.revert.snapshot)
await Snapshot.restore(session.revert.snapshot)
// Update FileTime for restored files so the edit tool doesn't see them as externally modified
for (const file of patch.files) {
FileTime.read(input.sessionID, file)
}
}
const next = await Session.update(input.sessionID, (draft) => {
draft.revert = undefined
})
Expand Down