Skip to content

feat: support hierarchical config structure for oh-my-opencode#7

Merged
j4rviscmd merged 5 commits intomainfrom
feature/hierarchical-config-structure
Jan 27, 2026
Merged

feat: support hierarchical config structure for oh-my-opencode#7
j4rviscmd merged 5 commits intomainfrom
feature/hierarchical-config-structure

Conversation

@j4rviscmd
Copy link
Owner

Summary

Refactor configuration handling to support arbitrary nested structures in both opencode and oh-my-opencode configs using recursive merge functions. This makes the plugin future-proof against structure changes.

Changes

Type System

  • Add HierarchicalPreset type for recursive structure representation
  • Make ModelConfig fully generic with [key: string]: unknown
  • Unify type definitions for both opencode and oh-my-opencode

Core Functionality

  • Replace flat structure with recursive model/variant merge logic
  • Implement deepMergeModel for preserving non-model properties during mode switches
  • Add hasDriftRecursive for hierarchical drift detection
  • Update status display with formatHierarchicalTree to show hierarchical tree format

Code Organization

  • Extract isObject to src/config/guards.ts (shared utility)
  • Move test helpers to src/test-utils/recursive-helpers.ts
  • Extract isLeafNode helper for better code clarity
  • Add comprehensive JSDoc documentation to all helper functions

Test Plan

  • All 73 unit tests pass
  • Type checking passes (bun run typecheck)
  • Code formatting passes (bun run lint)
  • Build succeeds (bun run build)
  • Manual testing with actual opencode/oh-my-opencode configs
  • Verify custom properties (piyo, abc, etc.) are preserved during mode switches
  • Test with hierarchical structures (agents, categories)
  • Code review completed

Benefits

  • Future-proof: Works with any config structure (agents, categories, future sections)
  • Property preservation: Custom settings are not lost during mode switches
  • Unified approach: Same logic for both opencode and oh-my-opencode
  • Better DX: Improved code organization and documentation

🤖 Generated with Claude Code

j4rviscmd and others added 5 commits January 28, 2026 00:40
Refactor configuration handling to support arbitrary nested structures
in both opencode and oh-my-opencode configs using recursive merge
functions. This makes the plugin future-proof against structure changes.

Changes:
- Add HierarchicalPreset type for recursive structure representation
- Replace flat structure with recursive model/variant merge logic
- Implement deepMergeModel for preserving non-model properties
- Add recursive drift detection with hasDriftRecursive
- Update status display to show hierarchical tree format

Benefits:
- Works with agents/categories structure in oh-my-opencode
- Preserves custom properties (piyo, abc, etc.) during mode switches
- No code changes needed when config structure evolves
- Unified approach for both opencode and oh-my-opencode

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Extract duplicate type guard and helper functions into dedicated modules
to improve code organization and reduce duplication.

Changes:
- Extract isObject to src/config/guards.ts (shared utility)
- Move test helpers to src/test-utils/recursive-helpers.ts
- Extract isLeafNode helper for better code clarity
- Add comprehensive JSDoc documentation to helpers

Benefits:
- Reduced code duplication across test and production code
- Better separation of concerns
- Improved testability by isolating recursive logic
- Enhanced code readability with descriptive helper names

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ility

Fixed deepMergeModel to correctly merge all preset properties (including
new properties like color, icon, etc.) by changing spread order from
valueRecord -> existing to existing -> valueRecord.

Fixed hasConfigDrift to detect drift on all preset properties, not just
model and variant. This ensures that newly added properties in presets
are properly applied on opencode startup.

Changes:
- deepMergeModel: Corrected spread order to existing -> valueRecord
- hasDriftRecursive: Check all preset properties instead of just model/variant
- hasConfigDrift: Added early return when no configs exist, simplified nested conditions
- switchMode: Changed toast to fire-and-forget pattern
- Added tests for new property merging and drift detection

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed deepMergeModel and hasDriftRecursive to properly handle ALL
preset properties, not just model and variant. This ensures that
new properties (color, icon, etc.) added to presets are correctly
merged into configs and drift is properly detected.

Changes:
- deepMergeModel: Spread entire preset instead of just model/variant
- hasDriftRecursive: Check all preset properties, not just model/variant
- Add tests for new property merging and drift detection

Example:
Preset with { model: "new", color: "blue" } now correctly merges
into existing config { model: "old", temp: 0.5 } resulting in
{ model: "new", temp: 0.5, color: "blue" }.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@j4rviscmd j4rviscmd merged commit d4160ae into main Jan 27, 2026
1 check passed
@j4rviscmd j4rviscmd deleted the feature/hierarchical-config-structure branch January 27, 2026 16:59
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.

1 participant