( toolPermissionContext: ToolPermissionContext, )
| 168 | `${stderr.trim()}\nShell cwd was reset to ${getOriginalCwd()}` |
| 169 | |
| 170 | export function resetCwdIfOutsideProject( |
| 171 | toolPermissionContext: ToolPermissionContext, |
| 172 | ): boolean { |
| 173 | const cwd = getCwd() |
| 174 | const originalCwd = getOriginalCwd() |
| 175 | const shouldMaintain = shouldMaintainProjectWorkingDir() |
| 176 | if ( |
| 177 | shouldMaintain || |
| 178 | // Fast path: originalCwd is unconditionally in allWorkingDirectories |
| 179 | // (filesystem.ts), so when cwd hasn't moved, pathInAllowedWorkingPath is |
| 180 | // trivially true — skip its syscalls for the no-cd common case. |
| 181 | (cwd !== originalCwd && |
| 182 | !pathInAllowedWorkingPath(cwd, toolPermissionContext)) |
| 183 | ) { |
| 184 | // Reset to original directory if maintaining project dir OR outside allowed working directory |
| 185 | setCwd(originalCwd) |
| 186 | if (!shouldMaintain) { |
| 187 | logEvent('tengu_bash_tool_reset_to_original_dir', {}) |
| 188 | return true |
| 189 | } |
| 190 | } |
| 191 | return false |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Creates a human-readable summary of structured content blocks. |
no test coverage detected