()
| 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() |
no test coverage detected