( oldCwd: string, newCwd: string, )
| 131 | } |
| 132 | |
| 133 | export async function onCwdChangedForHooks( |
| 134 | oldCwd: string, |
| 135 | newCwd: string, |
| 136 | ): Promise<void> { |
| 137 | if (oldCwd === newCwd) return |
| 138 | |
| 139 | // Re-evaluate from the current snapshot so mid-session hook changes are picked up |
| 140 | const config = getHooksConfigFromSnapshot() |
| 141 | const currentHasEnvHooks = |
| 142 | (config?.CwdChanged?.length ?? 0) > 0 || |
| 143 | (config?.FileChanged?.length ?? 0) > 0 |
| 144 | if (!currentHasEnvHooks) return |
| 145 | currentCwd = newCwd |
| 146 | |
| 147 | await clearCwdEnvFiles() |
| 148 | const hookResult = await executeCwdChangedHooks(oldCwd, newCwd).catch(e => { |
| 149 | const msg = errorMessage(e) |
| 150 | logForDebugging(`CwdChanged hook failed: ${msg}`, { |
| 151 | level: 'error', |
| 152 | }) |
| 153 | notifyCallback?.(msg, true) |
| 154 | return { |
| 155 | results: [] as HookOutsideReplResult[], |
| 156 | watchPaths: [] as string[], |
| 157 | systemMessages: [] as string[], |
| 158 | } |
| 159 | }) |
| 160 | dynamicWatchPaths = hookResult.watchPaths |
| 161 | dynamicWatchPathsSorted = hookResult.watchPaths.slice().sort() |
| 162 | for (const msg of hookResult.systemMessages) { |
| 163 | notifyCallback?.(msg, false) |
| 164 | } |
| 165 | for (const r of hookResult.results) { |
| 166 | if (!r.succeeded && r.output) { |
| 167 | notifyCallback?.(r.output, true) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Re-resolve matcher paths against the new cwd |
| 172 | if (initialized) { |
| 173 | restartWatching() |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | function dispose(): void { |
| 178 | if (watcher) { |
no test coverage detected