(memoryPath: string)
| 18 | onDone: (result?: string, options?: { display?: CommandResultDisplay }) => void; |
| 19 | }): React.ReactNode { |
| 20 | const handleSelectMemoryFile = async (memoryPath: string) => { |
| 21 | try { |
| 22 | // Create claude directory if it doesn't exist (idempotent with recursive) |
| 23 | if (memoryPath.includes(getClaudeConfigHomeDir())) { |
| 24 | await mkdir(getClaudeConfigHomeDir(), { recursive: true }); |
| 25 | } |
| 26 | |
| 27 | // Create file if it doesn't exist (wx flag fails if file exists, |
| 28 | // which we catch to preserve existing content) |
| 29 | try { |
| 30 | await writeFile(memoryPath, '', { encoding: 'utf8', flag: 'wx' }); |
| 31 | } catch (e: unknown) { |
| 32 | if (getErrnoCode(e) !== 'EEXIST') { |
| 33 | throw e; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | await editFileInEditor(memoryPath); |
| 38 | |
| 39 | // Determine which environment variable controls the editor |
| 40 | let editorSource = 'default'; |
| 41 | let editorValue = ''; |
| 42 | if (process.env.VISUAL) { |
| 43 | editorSource = '$VISUAL'; |
| 44 | editorValue = process.env.VISUAL; |
| 45 | } else if (process.env.EDITOR) { |
| 46 | editorSource = '$EDITOR'; |
| 47 | editorValue = process.env.EDITOR; |
| 48 | } |
| 49 | |
| 50 | const editorInfo = editorSource !== 'default' ? `Using ${editorSource}="${editorValue}".` : ''; |
| 51 | |
| 52 | const editorHint = editorInfo |
| 53 | ? `> ${editorInfo} To change editor, set $EDITOR or $VISUAL environment variable.` |
| 54 | : `> To use a different editor, set the $EDITOR or $VISUAL environment variable.`; |
| 55 | |
| 56 | onDone(`Opened memory file at ${getRelativeMemoryPath(memoryPath)}\n\n${editorHint}`, { display: 'system' }); |
| 57 | } catch (error) { |
| 58 | logError(error); |
| 59 | onDone(`Error opening memory file: ${error}`); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | const handleCancel = () => { |
| 64 | onDone('Cancelled memory editing', { display: 'system' }); |
nothing calls this directly
no test coverage detected