Skip to content

refactor(pack): extract shared hook-bootstrap (stdin, pause, manifest load)#312

Merged
LanNguyenSi merged 1 commit into
masterfrom
refactor/shared-hook-bootstrap
Jun 26, 2026
Merged

refactor(pack): extract shared hook-bootstrap (stdin, pause, manifest load)#312
LanNguyenSi merged 1 commit into
masterfrom
refactor/shared-hook-bootstrap

Conversation

@LanNguyenSi

Copy link
Copy Markdown
Owner

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-reality once omitted the pause check entirely (M1). This extracts the three pieces into src/cli/pack/hook-bootstrap.ts (readStdin, checkHookPause, loadManifestOrInjected) and routes every hook through it.

Pure refactor — behavior-preserving (verified)

  • checkHookPause forwards all opts to checkPauseFromLoader, which already treats explicit undefined identically to an absent field (!== undefined / ?? {}), so each hook's prior conditional opts-building is byte-identical. All 9 hookLabels 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 + error envelope (allow/block/note).
  • Legitimate exceptions left local: hook-runtime-reality keeps its isTTY/async-iteration reader; writeguard & stay-in-scope load no manifest; codex-stop & codex-user-prompt-submit have no pause check.

11 hooks migrated; per-hook decision logic untouched.

Tests / verification

  • New 10-test unit suite tests/cli/pack-hook-bootstrap.test.ts (incl. a loaderOpts passthrough case locking the loader-derived generated-dir resolution).
  • Full suite 2531 passed / 1 skipped; tsc build + typecheck clean.
  • Reviewer subagent: APPROVE — traced every hook against the two underlying contracts and confirmed a true no-op. Addressed its findings: added the loaderOpts passthrough test (MINOR) + a comment that the helper narrows on undefined only (NIT).

Scope: only src/cli/pack/* + the new test. No gate decision/envelope/exit-code touched.

Refs: task 6cba4ff9

… 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>
@LanNguyenSi LanNguyenSi merged commit de5b81e into master Jun 26, 2026
1 check passed
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.

2 participants