Skip to content

Add background setup hooks with state tracking#7

Merged
bkildow merged 4 commits intomainfrom
feature/background-setup
Mar 20, 2026
Merged

Add background setup hooks with state tracking#7
bkildow merged 4 commits intomainfrom
feature/background-setup

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented Mar 20, 2026

Summary

  • Adds background setup hook execution via a detached _run-setup subprocess with state tracking, so wt add returns immediately while hooks run asynchronously
  • Tracks setup progress in .wt-setup-state.json with status, PID, elapsed time, and hook completion count — viewable via wt status
  • Adds git exclude management to keep state/log files out of version control
  • Strips ANSI escape codes from background setup log output for clean log files
  • Connects stdin to the terminal for foreground hooks to fix stty: stdin isn't a terminal failures with tools like Docksal

Test plan

  • wt add --background <name> returns immediately and hooks run in background
  • wt status shows background setup progress and completion
  • wt add --foreground <name> runs hooks inline without stty errors
  • wt remove <name> cleans up state files
  • .wt-setup.log contains clean output without ANSI escape codes
  • make test passes

bkildow added 4 commits March 20, 2026 09:20
Allow setup hooks to run in a detached background process so `wt add`
returns immediately. Controlled via --background/--foreground flags or
the `background_setup` config option. A hidden `_run-setup` subcommand
executes hooks in the child process, writing progress to a JSON state
file (.wt-setup.json) and logs to .wt-setup.log.

Key changes:
- Setup state tracking (running/complete/failed/skipped) with stale
  process detection via PID liveness checks
- `wt status` displays a SETUP column showing hook execution state
- `wt remove` terminates in-progress background setup before teardown
- EnsureGitExclude adds wt-managed files to info/exclude so state and
  log files don't appear as untracked
- RunSetupHooks accepts an optional progress callback for per-hook
  state updates
Display human-friendly elapsed time when setup hooks finish, for both
foreground (wt add) and background (_run-setup) execution paths. Adds
ui.FormatDuration helper that renders durations as "45 seconds" or
"2 minutes 30 seconds".
Wrap the log file with colorprofile.NewWriter so ANSI color codes from
subprocesses (e.g. composer, npm) are automatically stripped before
being written to disk, producing clean readable logs.
Hooks executed in foreground mode inherited the controlling terminal
but had stdin connected to /dev/null, causing tools like Docksal's
fin to fail with "stty: stdin isn't a terminal" at cleanup. Setting
cmd.Stdin = os.Stdin for all hook execution paths fixes this.
@bkildow bkildow merged commit 4e0e43a into main Mar 20, 2026
@bkildow bkildow deleted the feature/background-setup branch March 20, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant