refactor: consolidate AgentCapabilities to single canonical type (Phase 02)#811
Conversation
…se 02) Fix a type-shadowing bug in src/renderer/global.d.ts where AgentCapabilities was declared twice in the same file (once at line 90 with supportsThinkingDisplay, again at line 133 without), causing the second declaration to silently override the first. Consolidate all 6 duplicate AgentCapabilities definitions in the codebase to a single canonical interface in src/shared/types.ts along with a canonical DEFAULT_CAPABILITIES constant. The canonical shape is a strict superset of every prior definition, including: - All 24 boolean capability flags - Optional imageResumeMode field (formerly only in main/agents/capabilities) - Full JSDoc on every field Files updated to import from the canonical source: - src/main/agents/capabilities.ts: re-exports from shared/types - src/main/preload/agents.ts: drops local definition, imports from shared - src/renderer/global.d.ts: both definitions replaced with import() alias - src/renderer/types/index.ts: re-exports from shared/types - src/renderer/hooks/agent/useAgentCapabilities.ts: imports from shared Also adds a missing !! coercion in useAgentCapabilities.hasCapability since the canonical type includes imageResumeMode (string | undefined), which breaks the strict boolean return type when indexed by key. Verified: lint clean (all three tsconfigs), capability tests pass (228/228 across capabilities, agent-completeness, detector, useAgentCapabilities, useAvailableAgents, ipc/handlers/agents).
📝 WalkthroughWalkthroughThe PR consolidates the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The as boolean cast on DEFAULT_CAPABILITIES[capability] returns undefined at runtime for optional fields like imageResumeMode. Using !! ensures a proper boolean false is returned.
The import was buried at line 778 after hundreds of interface declarations. Move it to the top with other imports per ES module conventions, keeping the re-export in its original position.
Greptile SummaryThis PR fixes a type-shadowing bug in Confidence Score: 5/5
Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class `src/shared/types.ts` {
+AgentCapabilities (canonical)
+DEFAULT_CAPABILITIES
}
class `src/main/agents/capabilities.ts` {
+AgentCapabilities (re-export)
+DEFAULT_CAPABILITIES (re-export)
+AGENT_CAPABILITIES Record
+getAgentCapabilities()
+hasCapability() !!coercion
}
class `src/main/preload/agents.ts` {
+AgentCapabilities (re-export)
}
class `src/renderer/global.d.ts` {
+AgentCapabilities (import alias)
note: was 2 duplicate declarations\none missing supportsThinkingDisplay
}
class `src/renderer/types/index.ts` {
+AgentCapabilities (re-export)
}
class `src/renderer/hooks/agent/useAgentCapabilities.ts` {
+AgentCapabilities (re-export)
+DEFAULT_CAPABILITIES (re-export)
+useAgentCapabilities()
+hasCapability() !!coercion
+hasCapabilityCached() !!coercion
}
`src/shared/types.ts` <|-- `src/main/agents/capabilities.ts` : re-exports
`src/shared/types.ts` <|-- `src/main/preload/agents.ts` : re-exports
`src/shared/types.ts` <|-- `src/renderer/global.d.ts` : import alias
`src/shared/types.ts` <|-- `src/renderer/types/index.ts` : re-exports
`src/shared/types.ts` <|-- `src/renderer/hooks/agent/useAgentCapabilities.ts` : re-exports
Reviews (1): Last reviewed commit: "fix: move AgentCapabilities import to to..." | Re-trigger Greptile |
Summary
Fixes a type-shadowing bug in
src/renderer/global.d.tswhereAgentCapabilitieswas declared twice in the same file (lines 61 and 104), causing the second declaration to silently override the first. The second declaration was missingsupportsThinkingDisplay.Consolidates all 6 duplicate
AgentCapabilitiesdefinitions into a single canonical interface insrc/shared/types.tsalong with a canonicalDEFAULT_CAPABILITIESconstant. The canonical shape is a strict superset of every prior definition.Net: -181 lines across 6 files
Files updated:
src/shared/types.ts- added canonical interface + DEFAULT_CAPABILITIESsrc/main/agents/capabilities.ts- re-exports from sharedsrc/main/preload/agents.ts- re-exports from sharedsrc/renderer/global.d.ts- both duplicates replaced with singleimport()aliassrc/renderer/types/index.ts- re-exports from sharedsrc/renderer/hooks/agent/useAgentCapabilities.ts- re-exports from shared, adds!!coercion inhasCapabilitysince canonical type includesimageResumeMode?: 'prompt-embed'Test plan
npm run lintpasses (all 3 tsconfigs) - this is where the bug was previously hiddenRisk
Medium - types touch main + renderer + preload boundary. Canonical is a strict superset so no existing code loses fields. Bug-fix side effect: runtime behavior around
hasCapability('imageResumeMode')now correctly returns a boolean.Note on merge ordering
Has minor overlap with Phase 05 (#TBD) - both add re-exports of types in
renderer/types/index.ts. When one merges, the other will need a trivial rebase to dedupe the re-export lines. Recommend merging Phase 02 first as it's the bug fix.Summary by CodeRabbit