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

Function MemoryCommand

src/commands/memory/memory.tsx:14–80  ·  view source on GitHub ↗
({
  onDone
}: {
  onDone: (result?: string, options?: {
    display?: CommandResultDisplay;
  }) => void;
})

Source from the content-addressed store, hash-verified

12import { logError } from '../../utils/log.js';
13import { editFileInEditor } from '../../utils/promptEditor.js';
14function MemoryCommand({
15 onDone
16}: {
17 onDone: (result?: string, options?: {
18 display?: CommandResultDisplay;
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'
65 });
66 };
67 return <Dialog title="Memory" onCancel={handleCancel} color="remember">
68 <Box flexDirection="column">
69 <React.Suspense fallback={null}>
70 <MemoryFileSelector onSelect={handleSelectMemoryFile} onCancel={handleCancel} />
71 </React.Suspense>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected