Skip to content

fix: wire TUI process cwd to active project - #1632

Merged
avoidwork merged 3 commits into
mainfrom
fix/tui-project-cwd
Nov 1, 2026
Merged

avoidwork merged 3 commits into
mainfrom
fix/tui-project-cwd

Conversation

@avoidwork

@avoidwork avoidwork commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Description

Wires the TUI's process working directory to the active project. handleSelectProject, handleClearProject, and handleNewSession in src/tui/app.js previously updated in-memory project state but never called process.chdir, so consumers reading process.cwd() — the cron command builders in src/scheduler/cron.js and src/tools/cron/index.js (which embed cd ${process.cwd()}) — ran in the wrong directory. This change adds a guarded, exported safeChdir helper and calls it from all three handlers: into the selected project on select, and back to config.cwd (fallback process.cwd()) on clear and on new session. Failures are recorded via the structured logger (no silent catch, per AGENTS.md 1.1). The branch also carries the OpenSpec change tui-project-cwd (proposal, design, spec, tasks) and its archive.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Added regression tests to tests/unit/tui/app.test.js covering: (1) safeChdir moves the process cwd into a valid project directory, (2) it restores the cwd to the configured root on clear, and (3) the invalid-path case — process.chdir throws, the logger records it, and no exception propagates. Full suite: 4482 tests pass.

Coverage

  • Line coverage maintained (91.51% overall; safeChdir is directly tested. The App component body is not rendered in the suite — pre-existing — so handler lines remain uncovered, not a regression.)

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Closes #1629

Specs, design, and tasks for wiring the TUI process cwd to the active
project on select/clear/new-session. Closes #1629.
@avoidwork avoidwork added the bug Something isn't working label Nov 1, 2026
@avoidwork avoidwork self-assigned this Nov 1, 2026
Add a guarded safeChdir helper and call it from handleSelectProject,
handleClearProject, and handleNewSession so the OS process cwd moves into
the selected project and restores to config.cwd on clear/new-session.
Failures are logged via the structured logger (no silent catch). Adds
regression tests for select, clear, and the invalid-path case. Closes #1629.
@avoidwork

Copy link
Copy Markdown
Owner Author

Audit Results — tui-project-cwd

Goal Fulfillment

  • Goal 1 (select moves cwd): handleSelectProject calls safeChdir(projectPath) after setProjectCwd. ✔
  • Goal 2 (clear restores cwd): handleClearProject calls safeChdir(config.cwd || process.cwd()). ✔
  • Goal 3 (new session restores cwd): handleNewSession calls safeChdir(config.cwd || process.cwd()) and adds config to its useCallback deps. ✔
  • Goal 4 (regression tests): tests/unit/tui/app.test.js covers select (valid), clear (restore), and invalid-path (logged, no crash). ✔

Spec Compliance

  • "Process cwd moves into the selected project" — implemented via safeChdir(projectPath). ✔
  • "Process cwd restores on project clear" — safeChdir(config.cwd || process.cwd()). ✔
  • "Process cwd restores on new session" — same guard in handleNewSession. ✔
  • "Chdir failures are guarded and logged" — safeChdir wraps process.chdir in try/catch → logger.error. ✔

Task Completion

All 10 tasks in tasks.md marked [x].

Quality

  • safeChdir is a single, exported, JSDoc'd helper (DRY across three call sites).
  • No silent catch — failures logged via the structured logger (AGENTS.md 1.1).
  • No forbidden patterns; lint + format clean; 4482 tests pass; coverage 91.51% (maintained).
  • safeChdir is directly tested; the App component body is not rendered in the suite (pre-existing), so handler lines remain uncovered — not a regression.

Verdict

All goals fulfilled, spec-compliant, tasks complete, no quality issues. No iteration required.

@avoidwork
avoidwork merged commit 5b1aa47 into main Nov 1, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/tui-project-cwd branch November 1, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: process cwd not updated on /projects select/clear

1 participant