MCPcopy Index your code
hub / github.com/codeaashu/claude-code / handleSelectMemoryFile

Function handleSelectMemoryFile

src/commands/memory/memory.tsx:21–63  ·  view source on GitHub ↗
(memoryPath: string)

Source from the content-addressed store, hash-verified

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'

Callers

nothing calls this directly

Calls 6

mkdirFunction · 0.85
getErrnoCodeFunction · 0.85
editFileInEditorFunction · 0.85
getRelativeMemoryPathFunction · 0.85
onDoneFunction · 0.50
logErrorFunction · 0.50

Tested by

no test coverage detected