MCPcopy
hub / github.com/anomalyco/opencode / undo

Function undo

packages/app/src/pages/session/use-session-commands.tsx:297–323  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

295 }
296
297 const undo = async () => {
298 const sessionID = params.id
299 if (!sessionID) return
300 const owner = sessionOwnership.capture()
301 const client = sdk().client
302 const directory = sdk().directory
303 const promptSession = prompt.capture()
304 const revert = info()?.revert?.messageID
305 const messages = userMessages()
306 const message = findLast(messages, (x) => !revert || x.id < revert)
307 if (!message) return
308 const parts = sync().data.part[message.id]
309
310 if (sync().data.session_working(sessionID)) {
311 await client.session.abort({ sessionID }).catch(() => {})
312 }
313
314 await runCommand({
315 owner,
316 prompt: promptSession,
317 request: () => client.session.revert({ sessionID, messageID: message.id }),
318 updatePrompt: (promptSession) => {
319 if (parts) promptSession.set(extractPromptFromParts(parts, { directory }))
320 },
321 updateViewport: () => setActiveMessage(findLast(messages, (x) => x.id < message.id)),
322 })
323 }
324
325 const redo = async () => {
326 const sessionID = params.id

Callers

nothing calls this directly

Calls 11

findLastFunction · 0.90
extractPromptFromPartsFunction · 0.90
sdkFunction · 0.85
userMessagesFunction · 0.85
infoFunction · 0.70
syncFunction · 0.70
runCommandFunction · 0.70
setActiveMessageFunction · 0.50
abortMethod · 0.45
revertMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected