Skip to content

refactor: consolidate AgentCapabilities to single canonical type (Phase 02)#811

Merged
pedramamini merged 3 commits intoRunMaestro:rcfrom
jSydorowicz21:dedup/phase-02-agent-capabilities-bug
Apr 16, 2026
Merged

refactor: consolidate AgentCapabilities to single canonical type (Phase 02)#811
pedramamini merged 3 commits intoRunMaestro:rcfrom
jSydorowicz21:dedup/phase-02-agent-capabilities-bug

Conversation

@jSydorowicz21
Copy link
Copy Markdown
Contributor

@jSydorowicz21 jSydorowicz21 commented Apr 12, 2026

Summary

Fixes a type-shadowing bug in src/renderer/global.d.ts where AgentCapabilities was declared twice in the same file (lines 61 and 104), causing the second declaration to silently override the first. The second declaration was missing supportsThinkingDisplay.

Consolidates all 6 duplicate AgentCapabilities definitions into 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.

Net: -181 lines across 6 files

Files updated:

  • src/shared/types.ts - added canonical interface + DEFAULT_CAPABILITIES
  • src/main/agents/capabilities.ts - re-exports from shared
  • src/main/preload/agents.ts - re-exports from shared
  • src/renderer/global.d.ts - both duplicates replaced with single import() alias
  • src/renderer/types/index.ts - re-exports from shared
  • src/renderer/hooks/agent/useAgentCapabilities.ts - re-exports from shared, adds !! coercion in hasCapability since canonical type includes imageResumeMode?: 'prompt-embed'

Test plan

  • npm run lint passes (all 3 tsconfigs) - this is where the bug was previously hidden
  • 228 capability-related tests pass (capabilities, agent-completeness, detector, useAgentCapabilities, useAvailableAgents, ipc/agents)
  • Claude Code capabilities: resume, read-only, images, slash commands, model selection, thinking
  • Codex capabilities: batch mode, JSON output
  • OpenCode plan mode
  • Factory Droid batch mode

Risk

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

  • Refactor
    • Consolidated agent capability type definitions and default values into a centralized shared module, reducing duplication across the codebase while preserving all existing exported functionality and behavior.

…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).
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

The PR consolidates the AgentCapabilities interface and DEFAULT_CAPABILITIES constant into a single source of truth in src/shared/types.ts. Local duplicate definitions are removed from five files and replaced with imports and re-exports. Minor boolean coercion logic is added to capability checks.

Changes

Cohort / File(s) Summary
Shared Types Definition
src/shared/types.ts
Added new AgentCapabilities interface with boolean capability flags and optional imageResumeMode field. Added DEFAULT_CAPABILITIES constant with all flags set to false.
Main Module Consolidation
src/main/agents/capabilities.ts, src/main/preload/agents.ts
Removed local AgentCapabilities interface definitions; now imported from src/shared/types.ts and re-exported for backward compatibility.
Renderer Type Consolidation
src/renderer/global.d.ts, src/renderer/types/index.ts
Removed duplicate AgentCapabilities interface definitions; replaced with type imports from src/shared/types.ts to establish single source of truth.
Hook Capability Logic
src/renderer/hooks/agent/useAgentCapabilities.ts
Removed local AgentCapabilities and DEFAULT_CAPABILITIES definitions; replaced with imports from shared types. Added boolean coercion (!!) to hasCapability and hasCapabilityCached return values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With whiskers twitching, I hop with glee,
One source of truth, at last I see!
No more scattered duplicates about,
The shared types banish all the doubt.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: consolidating duplicate AgentCapabilities definitions into a single canonical type across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@jSydorowicz21 jSydorowicz21 self-assigned this Apr 14, 2026
@jSydorowicz21 jSydorowicz21 marked this pull request as ready for review April 14, 2026 04:35
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

This PR fixes a type-shadowing bug in src/renderer/global.d.ts where AgentCapabilities was declared twice — the second declaration silently overrode the first and was missing supportsThinkingDisplay. It consolidates six duplicate definitions into a single canonical AgentCapabilities interface and DEFAULT_CAPABILITIES constant in src/shared/types.ts, with all other files reduced to re-exports or import aliases. The !! coercion additions to hasCapability and hasCapabilityCached are correct — capabilities[capability] now has type boolean | 'prompt-embed' | undefined due to the optional imageResumeMode field, and !! safely normalises all cases to boolean.

Confidence Score: 5/5

  • Safe to merge — the refactoring is mechanically correct, the bug fix is valid, and the canonical type is a strict superset of every prior definition.
  • All six changed files are re-exports or import aliases pointing at a single canonical source; no field is dropped or narrowed. The !! coercion additions are correct and necessary for the optional imageResumeMode field. The three-commit self-correction history (uncached path coercion, import ordering) shows the author caught and fixed edge cases before landing. No P0/P1 findings.
  • No files require special attention.

Important Files Changed

Filename Overview
src/shared/types.ts Adds canonical AgentCapabilities interface (23 fields) and DEFAULT_CAPABILITIES constant — both well-structured, optional imageResumeMode field correctly typed.
src/main/agents/capabilities.ts Re-exports AgentCapabilities and DEFAULT_CAPABILITIES from shared/types; hasCapability now uses !! coercion to correctly return boolean when imageResumeMode is 'prompt-embed' or undefined.
src/main/preload/agents.ts Cleanly re-exports AgentCapabilities from shared/types; no logic changes.
src/renderer/global.d.ts Replaces two duplicate AgentCapabilities declarations (one missing supportsThinkingDisplay) with a single import alias from shared/types, fixing the type-shadowing bug.
src/renderer/hooks/agent/useAgentCapabilities.ts Imports AgentCapabilities and DEFAULT_CAPABILITIES from shared/types; hasCapability and hasCapabilityCached both correctly apply !! coercion for the optional string-valued imageResumeMode field.
src/renderer/types/index.ts Imports AgentCapabilities from shared/types at top of file and re-exports it (line 780), preserving existing consumers that import from renderer/types.

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
Loading

Reviews (1): Last reviewed commit: "fix: move AgentCapabilities import to to..." | Re-trigger Greptile

@jSydorowicz21 jSydorowicz21 added refactor Clean-up needs ready to merge This PR is ready to merge labels Apr 15, 2026
@pedramamini pedramamini merged commit 636fb21 into RunMaestro:rc Apr 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge This PR is ready to merge refactor Clean-up needs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants