Skip to content

fix(hooks): 🐛 repair post-create hook execution, output rendering, and launch - #37

Open
CarmeloCampos wants to merge 2 commits into
arturosdg:mainfrom
CarmeloCampos:fix/post-create-hooks
Open

fix(hooks): 🐛 repair post-create hook execution, output rendering, and launch#37
CarmeloCampos wants to merge 2 commits into
arturosdg:mainfrom
CarmeloCampos:fix/post-create-hooks

Conversation

@CarmeloCampos

Copy link
Copy Markdown

Summary

The post-create hook system was broken end-to-end: hook output corrupted the TUI, and the worktree selector never launched after a successful hook (the screen stayed stuck).

Changes

  • src/hooks.ts
    • Stream stdout/stderr as UTF-8 (setEncoding) so multibyte characters are not corrupted across chunk boundaries.
    • Exactly-once completion callback (spawn error + close no longer double-fire).
    • Abort terminates the whole process tree: POSIX process-group kill with SIGTERM → SIGKILL escalation, taskkill /t /f on Windows. No output/completion after abort.
    • Added normalizeHookOutput: strips ANSI/VT/OSC escape sequences (stripVTControlCharacters) and applies carriage-return overwrite + CRLF semantics for progress output.
  • src/ui.ts
    • Bounded raw output tail (64 KB) and normalization before display — large/noisy hooks (e.g. bun install && codegraph init && codegraph index && codegraph sync) no longer corrupt the frame or accumulate unboundedly.
    • hideHookOutput() now returns the pending worktree path before clearing it; success, "open anyway", cancel, and Ctrl+C abort all capture the path first — the launch command now runs in the correct worktree and the dead/stuck UI is gone.
    • Clear the launch timer on teardown; accurate "Hook completed. Launching..." instructions.
    • Worktree/branch creation submits on ENTER instead of CHANGE — OpenTUI 0.1.75 emits CHANGE on blur(), so pressing Esc was silently creating worktrees/branches.
    • Failure prompt uses the configured launch command name instead of hardcoded opencode.
  • test/hooks.test.ts + "test": "bun test" script
    • 11 tests: ANSI/OSC stripping, CR overwrite, CRLF, unicode preservation, UTF-8 chunk decoding, exactly-once completion, abort suppression, spawn-error handling, and a realistic colored-progress pipeline.

Verification

  • bun test — 11 pass
  • bunx tsc --noEmit — only pre-existing @opentui/core module-resolution errors (present on clean main)
  • bun run build:single — builds cleanly

Out of scope

  • Detached hook renderable destruction (leak after many cancel cycles) and launch-spawn error handling — pre-existing, can follow up separately.

CarmeloCampos added a commit to CarmeloCampos/opencode-worktree that referenced this pull request Aug 12, 2026
CarmeloCampos added a commit to CarmeloCampos/opencode-worktree that referenced this pull request Aug 12, 2026
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