( context: CommandContext, args: string, )
| 16 | import { Config } from '@anus-dev/anus-core'; |
| 17 | |
| 18 | async function restoreAction( |
| 19 | context: CommandContext, |
| 20 | args: string, |
| 21 | ): Promise<void | SlashCommandActionReturn> { |
| 22 | const { services, ui } = context; |
| 23 | const { config, git: gitService } = services; |
| 24 | const { addItem, loadHistory } = ui; |
| 25 | |
| 26 | const checkpointDir = config?.getProjectTempDir() |
| 27 | ? path.join(config.getProjectTempDir(), 'checkpoints') |
| 28 | : undefined; |
| 29 | |
| 30 | if (!checkpointDir) { |
| 31 | return { |
| 32 | type: 'message', |
| 33 | messageType: 'error', |
| 34 | content: 'Could not determine the .anus directory path.', |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | try { |
| 39 | // Ensure the directory exists before trying to read it. |
| 40 | await fs.mkdir(checkpointDir, { recursive: true }); |
| 41 | const files = await fs.readdir(checkpointDir); |
| 42 | const jsonFiles = files.filter((file) => file.endsWith('.json')); |
| 43 | |
| 44 | if (!args) { |
| 45 | if (jsonFiles.length === 0) { |
| 46 | return { |
| 47 | type: 'message', |
| 48 | messageType: 'info', |
| 49 | content: 'No restorable tool calls found.', |
| 50 | }; |
| 51 | } |
| 52 | const truncatedFiles = jsonFiles.map((file) => { |
| 53 | const components = file.split('.'); |
| 54 | if (components.length <= 1) { |
| 55 | return file; |
| 56 | } |
| 57 | components.pop(); |
| 58 | return components.join('.'); |
| 59 | }); |
| 60 | const fileList = truncatedFiles.join('\n'); |
| 61 | return { |
| 62 | type: 'message', |
| 63 | messageType: 'info', |
| 64 | content: `Available tool calls to restore:\n\n${fileList}`, |
| 65 | }; |
| 66 | } |
| 67 | |
| 68 | const selectedFile = args.endsWith('.json') ? args : `${args}.json`; |
| 69 | |
| 70 | if (!jsonFiles.includes(selectedFile)) { |
| 71 | return { |
| 72 | type: 'message', |
| 73 | messageType: 'error', |
| 74 | content: `File not found: ${selectedFile}`, |
| 75 | }; |
nothing calls this directly
no test coverage detected