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