refactor(pack): extract shared hook-bootstrap (stdin, pause, manifest load)#312
Merged
Merged
Conversation
… load) The claude and codex pack hooks each reimplemented the same init boilerplate: stdin envelope read, pause-sentinel check with announcement, and manifest load with injection support. That drift was already real (hook-runtime-reality once omitted the pause check entirely). Extract the three pieces into src/cli/pack/hook-bootstrap.ts (readStdin, checkHookPause, loadManifestOrInjected) and route every hook through it; per-hook decision logic, error envelopes, and early-return shapes stay local. Pure refactor, behavior-preserving: - checkHookPause forwards all opts to checkPauseFromLoader, which already treats explicit undefined identically to an absent field, so each hook's prior conditional opts-building is byte-identical. All hook labels and per-hook generatedDir/now/loaderOpts forwarding preserved. - loadManifestOrInjected keeps the if-injected/else-loadManifest pattern and the manifestPath mapping; each hook keeps its own try/catch and error envelope. - hook-runtime-reality keeps its isTTY/async-iteration stdin reader (a legitimately different contract); writeguard/stay-in-scope load no manifest; codex-stop/codex-user-prompt-submit have no pause check. Adds a 10-test unit suite for the shared module, including a loaderOpts passthrough case. Full suite green (2531 passed / 1 skipped), build + typecheck clean. Reviewer subagent: APPROVE, confirmed a true no-op across all hooks. Refs: task 6cba4ff9 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
The claude and codex pack hooks each reimplemented the same init boilerplate (stdin read, pause-sentinel check + announcement, manifest load with injection). That drift was already real —
hook-runtime-realityonce omitted the pause check entirely (M1). This extracts the three pieces intosrc/cli/pack/hook-bootstrap.ts(readStdin,checkHookPause,loadManifestOrInjected) and routes every hook through it.Pure refactor — behavior-preserving (verified)
checkHookPauseforwards all opts tocheckPauseFromLoader, which already treats explicitundefinedidentically to an absent field (!== undefined/?? {}), so each hook's prior conditional opts-building is byte-identical. All 9hookLabels and per-hookgeneratedDir/now/loaderOptsforwarding preserved.loadManifestOrInjectedkeeps theif-injected / else loadManifestpattern and themanifestPathmapping; each hook keeps its own try/catch + error envelope (allow/block/note).hook-runtime-realitykeeps itsisTTY/async-iteration reader;writeguard&stay-in-scopeload no manifest;codex-stop&codex-user-prompt-submithave no pause check.11 hooks migrated; per-hook decision logic untouched.
Tests / verification
tests/cli/pack-hook-bootstrap.test.ts(incl. aloaderOptspassthrough case locking the loader-derived generated-dir resolution).tscbuild + typecheck clean.undefinedonly (NIT).Scope: only
src/cli/pack/*+ the new test. No gate decision/envelope/exit-code touched.Refs: task 6cba4ff9