mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
ac3a84ba5a
* fix(opencode): default agent switching to disabled
* fix(opencode): keep plan-approval build handoff; default no-switch for review feedback only
The agent switch cookie is shared by plan approval and code review, so
flipping the stored default to `disabled` also removed OpenCode's
plan-approval hand-off for every user who never configured the setting.
Make the unset default surface-aware instead: `getAgentSwitchSettings('plan')`
keeps the historical build hand-off, `getAgentSwitchSettings('review')`
stays on the current agent. An explicit user choice still applies to both
surfaces. Settings and the agent warning resolve the default from the mode
they render in, and the OpenCode "agent not available" warning now names
plan approval on the plan path.
Claude-Session: https://claude.ai/code/session_01H5KQWqXqjrPxyxUNso1QHS
---------
Co-authored-by: Michael Ramos <mdramos8@gmail.com>
98 lines
3.3 KiB
TypeScript
98 lines
3.3 KiB
TypeScript
/**
|
|
* Agent Switch Settings Utility
|
|
*
|
|
* Manages settings for automatic agent switching after plan approval and after
|
|
* sending code review feedback. Supports discovered agents, disabled, or custom
|
|
* agent names.
|
|
*
|
|
* The stored value is shared across surfaces, but the default when nothing is
|
|
* stored is surface-specific: plan approval keeps its historical hand-off to the
|
|
* build agent, while review feedback stays on the current agent.
|
|
*
|
|
* Uses cookies (not localStorage) because each hook invocation runs on a
|
|
* random port, and localStorage is scoped by origin including port.
|
|
*/
|
|
|
|
import { storage } from './storage';
|
|
|
|
const STORAGE_KEY = 'plannotator-agent-switch';
|
|
const CUSTOM_NAME_KEY = 'plannotator-agent-custom';
|
|
|
|
// AgentSwitchOption is now a string to support dynamic agent names from OpenCode
|
|
export type AgentSwitchOption = string;
|
|
|
|
export interface AgentSwitchSettings {
|
|
switchTo: AgentSwitchOption;
|
|
customName?: string;
|
|
}
|
|
|
|
// Fallback options when API is unavailable or for non-OpenCode origins
|
|
export const AGENT_OPTIONS: { value: string; label: string; description: string }[] = [
|
|
{ value: 'build', label: 'Build', description: 'Switch to build agent after approval' },
|
|
{ value: 'custom', label: 'Custom', description: 'Switch to a custom agent after approval' },
|
|
{ value: 'disabled', label: 'Disabled', description: 'Stay on current agent after approval' },
|
|
];
|
|
|
|
/** UI surface asking for the setting — only affects the unset default. */
|
|
export type AgentSwitchSurface = 'plan' | 'review';
|
|
|
|
const PLAN_DEFAULT_SETTINGS: AgentSwitchSettings = {
|
|
switchTo: 'build',
|
|
};
|
|
|
|
const REVIEW_DEFAULT_SETTINGS: AgentSwitchSettings = {
|
|
switchTo: 'disabled',
|
|
};
|
|
|
|
/**
|
|
* Default used when the user has never picked an agent switch setting.
|
|
* Plan approval hands off to the build agent (historical behavior); review
|
|
* feedback stays on the current agent.
|
|
*/
|
|
export function getAgentSwitchDefaults(surface: AgentSwitchSurface = 'plan'): AgentSwitchSettings {
|
|
return surface === 'review' ? REVIEW_DEFAULT_SETTINGS : PLAN_DEFAULT_SETTINGS;
|
|
}
|
|
|
|
/**
|
|
* Get current agent switch settings from storage.
|
|
* An explicit user choice applies to every surface; only the unset default
|
|
* varies by surface.
|
|
*/
|
|
export function getAgentSwitchSettings(surface: AgentSwitchSurface = 'plan'): AgentSwitchSettings {
|
|
const stored = storage.getItem(STORAGE_KEY);
|
|
const customName = storage.getItem(CUSTOM_NAME_KEY) || undefined;
|
|
|
|
// Accept any non-empty string (supports dynamic agent names from OpenCode)
|
|
if (stored) {
|
|
return { switchTo: stored, customName };
|
|
}
|
|
return getAgentSwitchDefaults(surface);
|
|
}
|
|
|
|
/**
|
|
* Save agent switch settings to storage
|
|
*/
|
|
export function saveAgentSwitchSettings(settings: AgentSwitchSettings): void {
|
|
storage.setItem(STORAGE_KEY, settings.switchTo);
|
|
if (settings.customName) {
|
|
storage.setItem(CUSTOM_NAME_KEY, settings.customName);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the effective agent name for switching
|
|
* Returns undefined if disabled, otherwise returns the agent name
|
|
*/
|
|
export function getEffectiveAgentName(settings: AgentSwitchSettings): string | undefined {
|
|
if (settings.switchTo === 'disabled') {
|
|
return undefined;
|
|
}
|
|
if (settings.switchTo === 'custom' && settings.customName) {
|
|
return settings.customName;
|
|
}
|
|
if (settings.switchTo === 'custom') {
|
|
return undefined;
|
|
}
|
|
return settings.switchTo;
|
|
}
|