MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / MemoryCommand

Function MemoryCommand

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

Source from the content-addressed store, hash-verified

14import { logError } from '../../utils/log.js';
15import { editFileInEditor } from '../../utils/promptEditor.js';
16function MemoryCommand({
17 onDone
18}: {
19 onDone: (result?: string, options?: {
20 display?: CommandResultDisplay;
21 }) => void;
22}): React.ReactNode {
23 const handleSelectMemoryFile = async (memoryPath: string) => {
24 try {
25 // Create claude directory if it doesn't exist (idempotent with recursive)
26 if (memoryPath.includes(getClaudeConfigHomeDir())) {
27 await mkdir(getClaudeConfigHomeDir(), {
28 recursive: true
29 });
30 }
31
32 // Create file if it doesn't exist (wx flag fails if file exists,
33 // which we catch to preserve existing content)
34 try {
35 await writeFile(memoryPath, '', {
36 encoding: 'utf8',
37 flag: 'wx'
38 });
39 } catch (e: unknown) {
40 if (getErrnoCode(e) !== 'EEXIST') {
41 throw e;
42 }
43 }
44 await editFileInEditor(memoryPath);
45
46 // Determine which environment variable controls the editor
47 let editorSource = 'default';
48 let editorValue = '';
49 if (process.env.VISUAL) {
50 editorSource = '$VISUAL';
51 editorValue = process.env.VISUAL;
52 } else if (process.env.EDITOR) {
53 editorSource = '$EDITOR';
54 editorValue = process.env.EDITOR;
55 }
56 const editorInfo = editorSource !== 'default' ? `Using ${editorSource}="${editorValue}".` : '';
57 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.`;
58 onDone(`Opened memory file at ${getRelativeMemoryPath(memoryPath)}\n\n${editorHint}`, {
59 display: 'system'
60 });
61 } catch (error) {
62 logError(error);
63 onDone(`Error opening memory file: ${error}`);
64 }
65 };
66 const handleCancel = () => {
67 onDone('Cancelled memory editing', {
68 display: 'system'
69 });
70 };
71 return <Dialog title="Memory" onCancel={handleCancel} color="remember">
72 <Box flexDirection="column">
73 <React.Suspense fallback={null}>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected