Browse Source

fix(preset): clear stale scalar fields using prevOverride keys

ReqX 3 months ago
parent
commit
e9046194f8
2 changed files with 24 additions and 4 deletions
  1. 19 4
      src/index.ts
  2. 5 0
      src/tools/preset-manager.ts

+ 19 - 4
src/index.ts

@@ -2,6 +2,7 @@ import type { Plugin } from '@opencode-ai/plugin';
 import { createAgents, getAgentConfigs, getDisabledAgents } from './agents';
 import { buildOrchestratorPrompt } from './agents/orchestrator';
 import {
+  type AgentOverrideConfig,
   deepMerge,
   loadPluginConfig,
   type MultiplexerConfig,
@@ -588,20 +589,31 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               | Record<string, unknown>
               | undefined;
             if (!entry) continue;
-            // Reset to config-file baseline
+            // Reset to config-file baseline. Use the previous preset's
+            // override to identify which fields to clear even when the
+            // baseline doesn't define them.
             const baseline =
               config.agents?.[resolvedName];
+            const prevOverride = prevPreset[agentName] as
+              | AgentOverrideConfig
+              | undefined;
             if (typeof baseline?.model === 'string') {
               entry.model = baseline.model;
             }
             if (typeof baseline?.variant === 'string') {
               entry.variant = baseline.variant;
-            } else if (baseline && 'variant' in baseline) {
+            } else if (
+              prevOverride &&
+              'variant' in prevOverride
+            ) {
               delete entry.variant;
             }
             if (typeof baseline?.temperature === 'number') {
               entry.temperature = baseline.temperature;
-            } else if (baseline && 'temperature' in baseline) {
+            } else if (
+              prevOverride &&
+              'temperature' in prevOverride
+            ) {
               delete entry.temperature;
             }
             if (
@@ -610,7 +622,10 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               !Array.isArray(baseline.options)
             ) {
               entry.options = baseline.options;
-            } else if (baseline && 'options' in baseline) {
+            } else if (
+              prevOverride &&
+              'options' in prevOverride
+            ) {
               delete entry.options;
             }
             log('[plugin] runtime preset reset from previous', {

+ 5 - 0
src/tools/preset-manager.ts

@@ -161,6 +161,11 @@ export function createPresetManager(ctx: PluginInput, config: PluginConfig) {
         if (resolvedOld in agentUpdates) continue; // new preset handles this agent
         const baseline = config.agents?.[resolvedOld];
         if (baseline) {
+          // Note: mapOverrideToAgentConfig(baseline) only emits fields
+          // the baseline defines. Scalar fields (variant/temperature/options)
+          // not in baseline are NOT cleared here. The config() hook in
+          // src/index.ts handles complete cleanup using the previous
+          // preset's override keys to drive deletion.
           resetUpdates[resolvedOld] = mapOverrideToAgentConfig(baseline);
         }
       }