Implement the following plan: Plan: Replace combinatorial wrapper types with…
- User
Implement the following plan:
Plan: Replace combinatorial wrapper types with CapabilityDeclarer pattern
Context
The
Wrap()function inexternal/capabilities.gomanually defines wrapper types for each combination of capabilities an external agent can declare. With 7 capability flags, this doesn't scale (128 possible combinations; currently only 9 are covered). The fix: introduce aCapabilityDeclarerinterface andAs*helper functions so a single wrapper type can implement all interfaces, with capability gating done at the call site via helpers.Built-in agents are unaffected — they don't implement
CapabilityDeclarer, so the helpers fall through to direct type assertions.Implementation Steps
1. Create
cmd/entire/cli/agent/capabilities.go(new file)Define:
CapabilityDeclarerinterface withDeclaredCapabilities() DeclaredCapsDeclaredCapsstruct (7 bool fields matchingexternal.Capabilities)- 7 helper functions:
AsHookSupport,AsTranscriptAnalyzer,AsTranscriptPreparer,AsTokenCalculator,AsTextGenerator,AsHookResponseWriter,AsSubagentAwareExtractor
Each helper:
gofunc AsHookSupport(ag Agent) (HookSupport, bool) { hs, ok := ag.(HookSupport) if !ok { return nil, false } if cd, ok := ag.(CapabilityDeclarer); ok { return hs, cd.DeclaredCapabilities().Hooks } return hs, true }2. Create
cmd/entire/cli/agent/capabilities_test.go(new file)Test each helper with 4 scenarios:
- Mock agent NOT implementing the interface →
false - Mock built-in agent implementing the interface (no
CapabilityDeclarer) →true - Mock agent with
CapabilityDeclarer+ capability=true→true - Mock agent with
CapabilityDeclarer+ capability=false→false
3. Rewrite
cmd/entire/cli/agent/external/capabilities.go Assistant
I'll start by reading the key files to understand the current code structure.
Assistant
Now let me read the remaining call sites.
Assistant
Let me read the remaining files.
Assistant
Now let me read the remaining files needed.
Assistant
Now let me read the setup_test.go around lines 1163-1176.
Assistant
Good. Now I have a clear picture of all the files and call sites. Let me create the tasks and start implementing.
Assistant
Now rewrite external/capabilities.go with a single wrappedAgent:
Assistant
Now update all call sites. Let me start with the production code:
Assistant
Now update lifecycle.go:
Assistant
Now update the strategy files and remaining production files:
Assistant
Now update config.go, hook_registry.go, hooks_cmd.go, state.go:
Assistant
Now update token_usage.go (same package, no
agent.prefix):Assistant
Now update setup_test.go:
Assistant
Now update external_test.go. The tests need to use
agent.AsXinstead of direct type assertions:Assistant
Now update the integration tests. Let me read the file to understand the patterns:
Assistant
The integration tests have two patterns:
hookAgent, ok := ag.(agent.HookSupport)with ok checkhookAgent := ag.(agent.HookSupport)direct assertion (will panic if fails)
Let me update them all:
Assistant
Now run fmt, lint, and tests:
Assistant
Two lint issues to fix:
ireturnon the As* functions andnilnilin the test mocks. Let me fix both:Assistant
I need to add
//nolint:ireturnto each function since returning an interface is the whole point of these helpers. And add//nolint:nilnilto the test mocks.Assistant
Now fix the nilnil issues in the test file:
Assistant
Now run lint again:
Assistant
Lint is clean. Now run tests:
Assistant
All tests pass. Let me update the task status.
Assistant
All done. Here's a summary of what was implemented:
New files:
cmd/entire/cli/agent/capabilities.go—CapabilityDeclarerinterface,DeclaredCapsstruct, and 7As*helper functionscmd/entire/cli/agent/capabilities_test.go— Tests for each helper with mock agents
Rewritten:
cmd/entire/cli/agent/external/capabilities.go— Replaced 9 combinatorial wrapper types (baseAgent,hooksAgent,analyzerAgent, etc.) with a singlewrappedAgentthat implements all interfaces andCapabilityDeclarer
Updated call sites (22 production + 2 test + 15 integration test):
setup.go(5 sites),lifecycle.go(5),strategy/manual_commit_hooks.go(4),strategy/common.go(1),config.go(1),hook_registry.go(1),hooks_cmd.go(1),state.go(1),agent/token_usage.go(2),setup_test.go(2),external/external_test.go(all assertions), (15 sites)