MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / build_memory_options

Function build_memory_options

src/command_system/memory_command.py:71–128  ·  view source on GitHub ↗

Public: the memory-target hierarchy, shared by ``/memory`` and the C9 ``#`` shortcut so the two pickers can never drift.

(cwd: str)

Source from the content-addressed store, hash-verified

69
70
71async def build_memory_options(cwd: str) -> list[UIOption]:
72 """Public: the memory-target hierarchy, shared by ``/memory`` and
73 the C9 ``#`` shortcut so the two pickers can never drift."""
74 from src.context_system.claude_md import (
75 clear_memory_file_caches,
76 get_memory_files,
77 )
78
79 try:
80 clear_memory_file_caches() # TS primes fresh per open (memory.tsx:86-87)
81 files = list(await get_memory_files(cwd=cwd))
82 except Exception:
83 files = []
84
85 home = Path.home()
86 user_path = str(home / ".claude" / "CLAUDE.md")
87 project_path = _resolve_project_memory_path(files, cwd)
88
89 # Git-aware project description (TS: `${isGit ? 'Checked in at' : 'Saved in'} ./…`).
90 try:
91 from src.utils.git import get_repo_root
92
93 in_git = get_repo_root(cwd) is not None
94 except Exception:
95 in_git = False
96 project_desc = (
97 f"{'Checked in at' if in_git else 'Saved in'} ./{os.path.basename(project_path)}"
98 )
99
100 # NOTE: TS's `" (new)"` suffix is DEAD CODE (only interpolated in the depth>0
101 # branch, where exists is always true) — the real differentiation is the
102 # description column, ported here. Labels stay plain.
103 options: list[UIOption] = [
104 UIOption(
105 value=user_path,
106 label="User memory",
107 description="Saved in ~/.claude/CLAUDE.md", # verbatim TS (hardcoded tilde)
108 ),
109 UIOption(value=project_path, label="Project memory", description=project_desc),
110 ]
111 seen: set[str] = {os.path.realpath(user_path), os.path.realpath(project_path)}
112
113 # Remaining enumerated files (managed/user/project + rules), deduped by realpath
114 # (stronger than TS's exact-path dedup — deliberate). Parented files were
115 # @-imported (TS desc); others get no description.
116 for info in files:
117 real = os.path.realpath(info.path)
118 if real in seen:
119 continue
120 seen.add(real)
121 options.append(
122 UIOption(
123 value=info.path,
124 label=_display_path(info.path, cwd),
125 description="@-imported" if getattr(info, "parent", None) else None,
126 )
127 )
128 return options

Callers 1

runMethod · 0.85

Calls 8

clear_memory_file_cachesFunction · 0.90
get_memory_filesFunction · 0.90
get_repo_rootFunction · 0.90
UIOptionClass · 0.85
_display_pathFunction · 0.85
addMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected