Add background setup hooks with state tracking#7
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_run-setupsubprocess with state tracking, sowt addreturns immediately while hooks run asynchronously.wt-setup-state.jsonwith status, PID, elapsed time, and hook completion count — viewable viawt statusstty: stdin isn't a terminalfailures with tools like DocksalTest plan
wt add --background <name>returns immediately and hooks run in backgroundwt statusshows background setup progress and completionwt add --foreground <name>runs hooks inline withoutsttyerrorswt remove <name>cleans up state files.wt-setup.logcontains clean output without ANSI escape codesmake testpasses