core: update session summary after revert to show file changes
This commit is contained in:
@@ -8,6 +8,7 @@ import { splitWhen } from "remeda"
|
|||||||
import { Storage } from "../storage/storage"
|
import { Storage } from "../storage/storage"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { SessionPrompt } from "./prompt"
|
import { SessionPrompt } from "./prompt"
|
||||||
|
import { SessionSummary } from "./summary"
|
||||||
|
|
||||||
export namespace SessionRevert {
|
export namespace SessionRevert {
|
||||||
const log = Log.create({ service: "session.revert" })
|
const log = Log.create({ service: "session.revert" })
|
||||||
@@ -57,8 +58,20 @@ export namespace SessionRevert {
|
|||||||
revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track())
|
revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track())
|
||||||
await Snapshot.revert(patches)
|
await Snapshot.revert(patches)
|
||||||
if (revert.snapshot) revert.diff = await Snapshot.diff(revert.snapshot)
|
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 })
|
||||||
|
await Storage.write(["session_diff", input.sessionID], diffs)
|
||||||
|
Bus.publish(Session.Event.Diff, {
|
||||||
|
sessionID: input.sessionID,
|
||||||
|
diff: diffs,
|
||||||
|
})
|
||||||
return Session.update(input.sessionID, (draft) => {
|
return Session.update(input.sessionID, (draft) => {
|
||||||
draft.revert = revert
|
draft.revert = revert
|
||||||
|
draft.summary = {
|
||||||
|
additions: diffs.reduce((sum, x) => sum + x.additions, 0),
|
||||||
|
deletions: diffs.reduce((sum, x) => sum + x.deletions, 0),
|
||||||
|
files: diffs.length,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return session
|
return session
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export namespace SessionSummary {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async function computeDiff(input: { messages: MessageV2.WithParts[] }) {
|
export async function computeDiff(input: { messages: MessageV2.WithParts[] }) {
|
||||||
let from: string | undefined
|
let from: string | undefined
|
||||||
let to: string | undefined
|
let to: string | undefined
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user