MCPcopy Create free account
hub / github.com/Noumena-Network/code / handleSelectMemoryFile

Function handleSelectMemoryFile

src/commands/memory/memory.tsx:21–61  ·  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 the parent directory if it doesn't exist.
24 await mkdir(dirname(memoryPath), {
25 recursive: true
26 });
27
28 // Create file if it doesn't exist (wx flag fails if file exists,
29 // which we catch to preserve existing content)
30 try {
31 await writeFile(memoryPath, '', {
32 encoding: 'utf8',
33 flag: 'wx'
34 });
35 } catch (e: unknown) {
36 if (getErrnoCode(e) !== 'EEXIST') {
37 throw e;
38 }
39 }
40 await editFileInEditor(memoryPath);
41
42 // Determine which environment variable controls the editor
43 let editorSource = 'default';
44 let editorValue = '';
45 if (process.env.VISUAL) {
46 editorSource = '$VISUAL';
47 editorValue = process.env.VISUAL;
48 } else if (process.env.EDITOR) {
49 editorSource = '$EDITOR';
50 editorValue = process.env.EDITOR;
51 }
52 const editorInfo = editorSource !== 'default' ? `Using ${editorSource}="${editorValue}".` : '';
53 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.`;
54 onDone(`Opened memory file at ${getRelativeMemoryPath(memoryPath)}\n\n${editorHint}`, {
55 display: 'system'
56 });
57 } catch (error) {
58 logError(error);
59 onDone(`Error opening memory file: ${error}`);
60 }
61 };
62 const handleCancel = () => {
63 onDone('Cancelled memory editing', {
64 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