feat(cli): extract TUI hooks into typed createTUIHooks factory#591
feat(cli): extract TUI hooks into typed createTUIHooks factory#591
Conversation
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
nhopeatall
left a comment
There was a problem hiding this comment.
Summary
LGTM — Clean extraction of ~120 lines of inline hook logic into a typed, testable factory function. The refactoring is behavior-preserving, follows the existing HookPresets pattern, replaces all any-typed contexts with proper types, and comes with thorough test coverage (30 tests covering all hooks).
The mutable ref pattern (iterationsRef, usageRef) is a reasonable approach for sharing state between the factory's hooks and the caller. CI is green across all checks.
Nitpicks
- tui-hooks.test.ts:12 —
beforeEachis imported from vitest but never used - tui-hooks.test.ts:46 —
createDefaultApprovalConfig()helper is defined but never called — dead code that can be removed
🕵️ claude-code · claude-opus-4-6 · run details
Summary
tuiHooksobject fromagent-command.tsinto a newpackages/cli/src/tui/tui-hooks.tsmodulecreateTUIHooks(options): AgentHooksfactory function following the pattern inpackages/llmist/src/agent/hook-presets.tsany-typed hook contexts with proper types (ObserveLLMCallContext,ObserveChunkContext,ObserveLLMCompleteContext,ObserveRateLimitThrottleContext,ObserveRetryAttemptContext,GadgetExecutionControllerContext)packages/cli/src/tui/tui-hooks.test.tscovering all observer hooks and thebeforeGadgetExecutioncontrollerCloses: https://linear.app/mongrel/issue/MNG-294
Key Decisions
iterationsRef,usageRef) instead of raw variables so the factory can update state the caller reads after the agent run, without returning values from the hook callbacksgadgetApprovalsobject passed by reference so "always allow"/"always deny" choices persist in the caller's map across REPL turnsStatusBarimported directly from./status-bar.js(not./index.js) to avoid potential circular import issues sincetui-hooks.tslives inside thetui/directoryagent-command.tsretains thetuiHooks: AgentHookslocal variable type annotation so the surrounding code is minimally disturbedTest plan
npm run typecheckpasses (0 errors)npm run testpasses (220 test files, 6569 tests)npm run lint(no new errors introduced; pre-existing warnings unchanged)agent-command-tui.test.tsandagent-command-throttle.test.tstests continue passingtui-hooks.test.tscoversonLLMCallStart,onStreamChunk,onLLMCallComplete,onRateLimitThrottle,onRetryAttempt, andbeforeGadgetExecution🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details