MCPcopy Create free account
hub / github.com/anus-dev/ANUS / saveRestorableToolCalls

Function saveRestorableToolCalls

packages/cli/src/ui/hooks/useAnusStream.ts:869–964  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

867
868 useEffect(() => {
869 const saveRestorableToolCalls = async () => {
870 if (!config.getCheckpointingEnabled()) {
871 return;
872 }
873 const restorableToolCalls = toolCalls.filter(
874 (toolCall) =>
875 (toolCall.request.name === 'replace' ||
876 toolCall.request.name === 'write_file') &&
877 toolCall.status === 'awaiting_approval',
878 );
879
880 if (restorableToolCalls.length > 0) {
881 const checkpointDir = config.getProjectTempDir()
882 ? path.join(config.getProjectTempDir(), 'checkpoints')
883 : undefined;
884
885 if (!checkpointDir) {
886 return;
887 }
888
889 try {
890 await fs.mkdir(checkpointDir, { recursive: true });
891 } catch (error) {
892 if (!isNodeError(error) || error.code !== 'EEXIST') {
893 onDebugMessage(
894 `Failed to create checkpoint directory: ${getErrorMessage(error)}`,
895 );
896 return;
897 }
898 }
899
900 for (const toolCall of restorableToolCalls) {
901 const filePath = toolCall.request.args['file_path'] as string;
902 if (!filePath) {
903 onDebugMessage(
904 `Skipping restorable tool call due to missing file_path: ${toolCall.request.name}`,
905 );
906 continue;
907 }
908
909 try {
910 let commitHash = await gitService?.createFileSnapshot(
911 `Snapshot for ${toolCall.request.name}`,
912 );
913
914 if (!commitHash) {
915 commitHash = await gitService?.getCurrentCommitHash();
916 }
917
918 if (!commitHash) {
919 onDebugMessage(
920 `Failed to create snapshot for ${filePath}. Skipping restorable tool call.`,
921 );
922 continue;
923 }
924
925 const timestamp = new Date()
926 .toISOString()

Callers 1

useAnusStreamFunction · 0.85

Calls 8

isNodeErrorFunction · 0.85
getErrorMessageFunction · 0.85
getProjectTempDirMethod · 0.80
mkdirMethod · 0.80
createFileSnapshotMethod · 0.80
getCurrentCommitHashMethod · 0.80
getHistoryMethod · 0.45

Tested by

no test coverage detected