(memoryDir: string)
| 127 | * try/catch needed for the happy path. |
| 128 | */ |
| 129 | export async function ensureMemoryDirExists(memoryDir: string): Promise<void> { |
| 130 | const fs = getFsImplementation() |
| 131 | try { |
| 132 | await fs.mkdir(memoryDir) |
| 133 | } catch (e) { |
| 134 | // fs.mkdir already handles EEXIST internally. Anything reaching here is |
| 135 | // a real problem (EACCES/EPERM/EROFS) — log so --debug shows why. Prompt |
| 136 | // building continues either way; the model's Write will surface the |
| 137 | // real perm error (and FileWriteTool does its own mkdir of the parent). |
| 138 | const code = |
| 139 | e instanceof Error && 'code' in e && typeof e.code === 'string' |
| 140 | ? e.code |
| 141 | : undefined |
| 142 | logForDebugging( |
| 143 | `ensureMemoryDirExists failed for ${memoryDir}: ${code ?? String(e)}`, |
| 144 | { level: 'debug' }, |
| 145 | ) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Log memory directory file/subdir counts asynchronously. |
no test coverage detected