Browse Source

docs: update codemaps for RuntimeConfig and removed runtime-preset

adikpb 1 month ago
parent
commit
abb670606b
5 changed files with 18 additions and 11 deletions
  1. 2 1
      codemap.md
  2. 1 1
      src/codemap.md
  3. 13 7
      src/config/codemap.md
  4. 1 1
      src/tools/codemap.md
  5. 1 1
      src/tools/smartfetch/codemap.md

+ 2 - 1
codemap.md

@@ -21,6 +21,7 @@ This codemap covers the plugin repository itself and excludes the nested `openco
 | `src/index.ts` | Main plugin bootstrap: wires agents, tools, MCPs, hooks, council managers, shared background job board, multiplexer session mirroring, preset managers, task-session tracking, and config merge behavior. |
 | `src/cli/index.ts` | CLI entrypoint for installation/bootstrap workflows. |
 | `src/config/schema.ts` | Source-of-truth runtime config schema used by validation and schema generation. |
+| `src/config/runtime.ts` | Per-directory `RuntimeConfig` singleton: derived getters over the frozen plugin config, host-config capture, and runtime preset state. |
 | `scripts/generate-schema.ts` | Generates `oh-my-opencode-slim.schema.json` from the Zod config schema. |
 
 ## Repository Directory Map
@@ -30,7 +31,7 @@ This codemap covers the plugin repository itself and excludes the nested `openco
 | `src/` | Main application surface that composes plugin bootstrap, runtime model chains, hook orchestration, task-session aliasing, and installer-facing code. | [View Map](src/codemap.md) |
 | `src/agents/` | Agent factory layer for orchestrator and specialists, including prompt/model overrides, display-name normalization, MCP assignment, and permission shaping. | [View Map](src/agents/codemap.md) |
 | `src/cli/` | Installer, config editing, provider preset generation, and built-in skill installation. | [View Map](src/cli/codemap.md) |
-| `src/config/` | Configuration schema, layered loaders, preset merging, compatibility migrations, constant tables, and agent/MCP policy helpers. | [View Map](src/config/codemap.md) |
+| `src/config/` | Configuration schema, layered loaders, preset merging, compatibility migrations, constant tables, the `RuntimeConfig` runtime-state singleton, and agent/MCP policy helpers. | [View Map](src/config/codemap.md) |
 
 | `src/hooks/` | Aggregated runtime hook surface for prompt transforms, recovery logic, task-session aliasing, nudges, and lifecycle policies. | [View Map](src/hooks/codemap.md) |
 | `src/hooks/apply-patch/` | Structured `apply_patch` parsing, matching, recovery, and rewrite pipeline. | [View Map](src/hooks/apply-patch/codemap.md) |

+ 1 - 1
src/codemap.md

@@ -116,7 +116,7 @@ Key event flows:
 
 ### Dependencies
 
-- **Config System** (`src/config/`): Configuration loading, validation, and runtime presets
+- **Config System** (`src/config/`): Configuration loading, validation, the `RuntimeConfig` runtime-state singleton, and runtime presets
 - **Agents** (`src/agents/`): Agent personalities and permission sets
 - **Tools** (`src/tools/`): Tool implementations (council, webfetch, AST operations)
 - **Hooks** (`src/hooks/`): Lifecycle hooks for auto-update, phase reminders, etc.

+ 13 - 7
src/config/codemap.md

@@ -11,14 +11,14 @@ The config system follows a layered architecture:
 - **Schema Layer**: Defines Zod schemas for all configuration objects (PluginConfig, AgentOverrideConfig, CouncilConfig, etc.) ensuring runtime validation and type safety
 - **Loader Layer**: Implements configuration discovery, merging, and environment variable interpolation across user and project scopes
 - **Utility Layer**: Provides helper functions for agent-specific configuration lookup and MCP permission resolution
-- **Runtime State**: Manages active preset state across plugin re-initializations
+- **Runtime State**: Manages active preset state and derived runtime configuration across plugin re-initializations
 
 ### Design Patterns
 
 - **Factory Pattern**: `loadPluginConfig()` creates the merged configuration object
 - **Strategy Pattern**: Presets allow swapping entire agent configurations via `preset` field
 - **Decorator Pattern**: Agent overrides decorate default agent behavior with per-model, skill, and MCP restrictions
-- **Singleton Pattern**: Runtime preset state persists across plugin re-inits via module-level variables
+- **Singleton Pattern**: Runtime config and active preset state persist per project directory via the `RuntimeConfig` registry (`runtime.ts`)
 
 ### Key Abstractions
 
@@ -28,6 +28,7 @@ The config system follows a layered architecture:
 | `AgentOverrideConfig` | Per-agent configuration (model, temperature, skills, MCPs) | schema.ts |
 | `CouncilConfig` | Multi-LLM council configuration with presets and execution modes | council-schema.ts |
 | `MultiplexerConfig` | Unified pane management configuration (tmux/zellij) | schema.ts |
+| `RuntimeConfig` | Per-directory runtime config singleton with derived getters and preset state | runtime.ts |
 
 ## Flow
 
@@ -51,8 +52,8 @@ The config system follows a layered architecture:
    └─ Normalization: companion defaults, ACP agent defaults
 
 4. Runtime Phase
-   ├─ Active preset state persisted across plugin re-inits
-   └─ Previous preset tracked for reset diff computation
+   ├─ RuntimeConfig seeded with deep-frozen plugin config snapshot
+   └─ Derived getters (agents, modelArrays, disabled*, presets) computed on demand
 ```
 
 ### Agent Configuration Resolution
@@ -131,9 +132,13 @@ This allows consumers to import directly from `src/config` rather than individua
 
 ### Runtime State
 
-- `setActiveRuntimePreset(name)`: Set currently active preset
-- `getActiveRuntimePreset()`: Get currently active preset
-- `getPreviousRuntimePreset()`: Get previously active preset
+- `RuntimeConfig.init(directory, pluginConfig)`: Seed the per-directory singleton with a deep-frozen plugin config snapshot
+- `RuntimeConfig.get(directory)`: Get (lazily creating) the singleton for a directory
+- `RuntimeConfig.reset(directory)`: Clear the singleton for a directory
+- `RuntimeConfig.captureHostConfig(opencodeConfig)`: Capture host-side config before the config hook mutates it
+- `setRuntimePreset(name)`: Set the currently active runtime preset (stale names clear it)
+- `getRuntimePreset()`: Get the currently active runtime preset
+- Derived getters: `agents()`, `agent(name)`, `disabledAgents`, `disabledTools`, `disabledSkills`, `disabledMcps`, `imageRouting`, `multiplexer`, `backgroundJobs`, `fallback`, `webfetch`, `acpAgents`, `companion`, `council`, `modelArrays`, `runtimeChains`, `primaryModel`, `smallModel()`, `hostAgent(name)`
 
 ### MCP Management
 
@@ -208,3 +213,4 @@ Configuration loading is tested via:
 - `src/config/utils.test.ts`: Agent configuration utilities
 - `src/config/agent-mcps.test.ts`: MCP permission resolution
 - `src/config/council-schema.test.ts`: Council configuration validation
+- `src/config/runtime.test.ts`: RuntimeConfig seeding, derived getters, preset state, and host capture

+ 1 - 1
src/tools/codemap.md

@@ -42,7 +42,7 @@ Each tool is implemented as a factory function that returns a `ToolDefinition` r
 
 ### State Management
 
-- **Runtime Presets**: Preset state persists across plugin reloads via `runtime-preset.ts`
+- **Runtime Presets**: Preset state persists across plugin reloads via `RuntimeConfig` (`src/config/runtime.ts`)
 - **TUI Integration**: Preset changes persist to the config file only; the sidebar is NOT refreshed mid-session (the agent registry is unchanged until reload) — hot-swapping the agent tree during an active conversation risks context truncation, drifted prior turns, and stale subagent references
 - **Background Jobs**: Task cancellation uses a centralized job board for tracking and cleanup
 

+ 1 - 1
src/tools/smartfetch/codemap.md

@@ -29,5 +29,5 @@
 
 - `src/index.ts` registers the tool under the public name `webfetch`, so agents can call it alongside council and AST-grep tools.
 - `src/tools/smartfetch/index.ts` re-exports the tool factory, description, and shared types for other modules or docs to import without reaching into implementation files.
-- `secondary-model.ts` depends on the OpenCode plugin client (`PluginInput['client']`) to spawn an isolated helper session, resolve `small_model` from the effective OpenCode config, and resolve `explorer` / `librarian` fallbacks from slim's own plugin config loader.
+- `secondary-model.ts` depends on the OpenCode plugin client (`PluginInput['client']`) to spawn an isolated helper session. The secondary-model chain is resolved purely in memory at plugin construction by `resolveSecondaryModels` (`secondary-model.ts`): dedicated `webfetch` models, then the host's `small_model` (via `RuntimeConfig.smallModel()`), then the `explorer` / `librarian` agent models (via `RuntimeConfig.agent()`). No config files are re-read on the webfetch hot path — see `config-read-guard.test.ts`.
 - `cache.ts`, `network.ts`, and `utils.ts` are intentionally reusable seams for tests: cache behavior, redirect policy, llms probing, heading extraction, and render/metadata helpers can be verified without hitting the full tool entrypoint.