MCPcopy Create free account
hub / github.com/WJX20/claude-code / handleRewindFiles

Function handleRewindFiles

src/cli/print.ts:4525–4573  ·  view source on GitHub ↗
(
  userMessageId: UUID,
  appState: AppState,
  setAppState: (updater: (prev: AppState) => AppState) => void,
  dryRun: boolean,
)

Source from the content-addressed store, hash-verified

4523}
4524
4525async function handleRewindFiles(
4526 userMessageId: UUID,
4527 appState: AppState,
4528 setAppState: (updater: (prev: AppState) => AppState) => void,
4529 dryRun: boolean,
4530): Promise<RewindFilesResult> {
4531 if (!fileHistoryEnabled()) {
4532 return { canRewind: false, error: 'File rewinding is not enabled.', filesChanged: [] }
4533 }
4534 if (!fileHistoryCanRestore(appState.fileHistory, userMessageId)) {
4535 return {
4536 canRewind: false,
4537 error: 'No file checkpoint found for this message.',
4538 filesChanged: [],
4539 }
4540 }
4541
4542 if (dryRun) {
4543 const diffStats = await fileHistoryGetDiffStats(
4544 appState.fileHistory,
4545 userMessageId,
4546 )
4547 return {
4548 canRewind: true,
4549 filesChanged: diffStats?.filesChanged,
4550 insertions: diffStats?.insertions,
4551 deletions: diffStats?.deletions,
4552 }
4553 }
4554
4555 try {
4556 await fileHistoryRewind(
4557 updater =>
4558 setAppState(prev => ({
4559 ...prev,
4560 fileHistory: updater(prev.fileHistory),
4561 })),
4562 userMessageId,
4563 )
4564 } catch (error) {
4565 return {
4566 canRewind: false,
4567 error: `Failed to rewind: ${errorMessage(error)}`,
4568 filesChanged: [],
4569 }
4570 }
4571
4572 return { canRewind: true, filesChanged: [] }
4573}
4574
4575function handleSetPermissionMode(
4576 request: { mode: InternalPermissionMode },

Callers 2

runHeadlessFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 5

fileHistoryEnabledFunction · 0.85
fileHistoryCanRestoreFunction · 0.85
fileHistoryGetDiffStatsFunction · 0.85
fileHistoryRewindFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected