MCPcopy
hub / github.com/claude-code-best/claude-code / handleRewindFiles

Function handleRewindFiles

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

Source from the content-addressed store, hash-verified

4747}
4748
4749async function handleRewindFiles(
4750 userMessageId: UUID,
4751 appState: AppState,
4752 setAppState: (updater: (prev: AppState) => AppState) => void,
4753 dryRun: boolean,
4754): Promise<RewindFilesResult> {
4755 if (!fileHistoryEnabled()) {
4756 return {
4757 canRewind: false,
4758 error: 'File rewinding is not enabled.',
4759 filesChanged: [],
4760 }
4761 }
4762 if (!fileHistoryCanRestore(appState.fileHistory, userMessageId)) {
4763 return {
4764 canRewind: false,
4765 error: 'No file checkpoint found for this message.',
4766 filesChanged: [],
4767 }
4768 }
4769
4770 if (dryRun) {
4771 const diffStats = await fileHistoryGetDiffStats(
4772 appState.fileHistory,
4773 userMessageId,
4774 )
4775 return {
4776 canRewind: true,
4777 filesChanged: diffStats?.filesChanged ?? [],
4778 insertions: diffStats?.insertions,
4779 deletions: diffStats?.deletions,
4780 }
4781 }
4782
4783 try {
4784 await fileHistoryRewind(
4785 updater =>
4786 setAppState(prev => ({
4787 ...prev,
4788 fileHistory: updater(prev.fileHistory),
4789 })),
4790 userMessageId,
4791 )
4792 } catch (error) {
4793 return {
4794 canRewind: false,
4795 error: `Failed to rewind: ${errorMessage(error)}`,
4796 filesChanged: [],
4797 }
4798 }
4799
4800 return { canRewind: true, filesChanged: [] }
4801}
4802
4803function handleSetPermissionMode(
4804 request: { mode: InternalPermissionMode },

Callers 2

runHeadlessFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 6

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

Tested by

no test coverage detected