* Log memory directory file/subdir counts asynchronously. * Fire-and-forget — doesn't block prompt building.
(
memoryDir: string,
baseMetadata: Record<
string,
| number
| boolean
| AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
>,
)
| 150 | * Fire-and-forget — doesn't block prompt building. |
| 151 | */ |
| 152 | function logMemoryDirCounts( |
| 153 | memoryDir: string, |
| 154 | baseMetadata: Record< |
| 155 | string, |
| 156 | | number |
| 157 | | boolean |
| 158 | | AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 159 | >, |
| 160 | ): void { |
| 161 | const fs = getFsImplementation() |
| 162 | void fs.readdir(memoryDir).then( |
| 163 | dirents => { |
| 164 | let fileCount = 0 |
| 165 | let subdirCount = 0 |
| 166 | for (const d of dirents) { |
| 167 | if (d.isFile()) { |
| 168 | fileCount++ |
| 169 | } else if (d.isDirectory()) { |
| 170 | subdirCount++ |
| 171 | } |
| 172 | } |
| 173 | logEvent('ncode_memdir_loaded', { |
| 174 | ...baseMetadata, |
| 175 | total_file_count: fileCount, |
| 176 | total_subdir_count: subdirCount, |
| 177 | }) |
| 178 | }, |
| 179 | () => { |
| 180 | // Directory unreadable — log without counts |
| 181 | logEvent('ncode_memdir_loaded', baseMetadata) |
| 182 | }, |
| 183 | ) |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Build the typed-memory behavioral instructions (without MEMORY.md content). |
no test coverage detected