MCPcopy Create free account
hub / github.com/arctic-cli/interface / undo

Function undo

packages/arctic/src/session/benchmark.ts:282–327  ·  view source on GitHub ↗
(input: { sessionID: string; allowDirty?: boolean })

Source from the content-addressed store, hash-verified

280 * Manual edits made BEFORE apply are preserved (they're in the checkpoint).
281 */
282 export async function undo(input: { sessionID: string; allowDirty?: boolean }) {
283 return withWorktreeLock(async () => {
284 const parent = await resolveParent(input.sessionID)
285 if (!parent || !isParent(parent)) return parent ?? Session.get(input.sessionID)
286
287 const dirty = await isDirty()
288 if (!input.allowDirty && dirty) {
289 throw new WorkingTreeDirtyError({ message: "Working tree has uncommitted changes." })
290 }
291
292 if (!parent.benchmark.appliedSessionID) {
293 // Nothing applied, nothing to undo
294 return parent
295 }
296
297 if (!parent.benchmark.checkpointSnapshot) {
298 throw new SnapshotUnavailableError({
299 message: "No checkpoint snapshot available to undo.",
300 })
301 }
302
303 const appliedSnapshot = await Snapshot.track()
304 if (!appliedSnapshot) {
305 throw new SnapshotUnavailableError({
306 message: "Benchmark mode requires snapshots (git) to be enabled.",
307 })
308 }
309
310 const appliedChild = await Session.get(parent.benchmark.appliedSessionID)
311 if (isChild(appliedChild) && appliedChild.benchmark.parentID === parent.id) {
312 await updateChildSnapshot(appliedChild.id, appliedSnapshot)
313 const appliedChildWorktree = await ensureChildWorktree(parent, appliedChild)
314 await Snapshot.restoreTo(appliedSnapshot, appliedChildWorktree, { cleanUntracked: true })
315 }
316
317 // Simply restore the checkpoint
318 await Snapshot.restoreTo(parent.benchmark.checkpointSnapshot, Instance.worktree, { cleanUntracked: true })
319
320 return Session.update(parent.id, (draft) => {
321 if (draft.benchmark?.type === "parent") {
322 draft.benchmark.appliedSessionID = undefined
323 draft.benchmark.checkpointSnapshot = undefined
324 }
325 })
326 })
327 }
328
329 export function hasDuplicates(models: BenchmarkSchema.Model[]) {
330 const seen = new Set<string>()

Callers

nothing calls this directly

Calls 9

withWorktreeLockFunction · 0.85
resolveParentFunction · 0.85
isParentFunction · 0.85
isDirtyFunction · 0.85
isChildFunction · 0.85
updateChildSnapshotFunction · 0.85
ensureChildWorktreeFunction · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected