diff --git a/apps/opencode-plugin/index.ts b/apps/opencode-plugin/index.ts index 2615e2b..f4f20f2 100644 --- a/apps/opencode-plugin/index.ts +++ b/apps/opencode-plugin/index.ts @@ -70,30 +70,36 @@ Do NOT proceed with implementation until your plan is approved. server.stop(); if (result.approved) { - // Switch TUI display to build agent - try { - await ctx.client.tui.executeCommand({ - body: { command: "agent_cycle" }, - }); - } catch { - // Silently fail - } - - // Create a user message with build agent using noReply: true - // This ensures the message is created BEFORE we return from the tool, - // so the current loop's next iteration will see it. - // noReply: true means we don't wait for a new loop to complete. - try { - await ctx.client.session.prompt({ - path: { id: context.sessionID }, - body: { - agent: "build", - noReply: true, - parts: [{ type: "text", text: "Proceed with implementation" }], - }, - }); - } catch { - // Silently fail if session is busy + // Check agent switch setting (defaults to 'build' if not set) + const shouldSwitchAgent = result.agentSwitch && result.agentSwitch !== 'disabled'; + const targetAgent = result.agentSwitch || 'build'; + + if (shouldSwitchAgent) { + // Switch TUI display to target agent + try { + await ctx.client.tui.executeCommand({ + body: { command: "agent_cycle" }, + }); + } catch { + // Silently fail + } + + // Create a user message with target agent using noReply: true + // This ensures the message is created BEFORE we return from the tool, + // so the current loop's next iteration will see it. + // noReply: true means we don't wait for a new loop to complete. + try { + await ctx.client.session.prompt({ + path: { id: context.sessionID }, + body: { + agent: targetAgent, + noReply: true, + parts: [{ type: "text", text: "Proceed with implementation" }], + }, + }); + } catch { + // Silently fail if session is busy + } } // If user approved with annotations, include them as notes for implementation diff --git a/packages/editor/App.tsx b/packages/editor/App.tsx index 829bc18..0cedd4c 100644 --- a/packages/editor/App.tsx +++ b/packages/editor/App.tsx @@ -16,6 +16,8 @@ import { storage } from '@plannotator/ui/utils/storage'; import { UpdateBanner } from '@plannotator/ui/components/UpdateBanner'; import { getObsidianSettings } from '@plannotator/ui/utils/obsidian'; import { getBearSettings } from '@plannotator/ui/utils/bear'; +import { getAgentSwitchSettings } from '@plannotator/ui/utils/agentSwitch'; +import { getPlanSaveSettings } from '@plannotator/ui/utils/planSave'; import { ImageAnnotator } from '@plannotator/ui/components/ImageAnnotator'; const PLAN_CONTENT = `# Implementation Plan: Real-time Collaboration @@ -446,9 +448,20 @@ const App: React.FC = () => { try { const obsidianSettings = getObsidianSettings(); const bearSettings = getBearSettings(); + const agentSwitchSettings = getAgentSwitchSettings(); + const planSaveSettings = getPlanSaveSettings(); // Build request body - include integrations if enabled - const body: { obsidian?: object; bear?: object; feedback?: string } = {}; + const body: { obsidian?: object; bear?: object; feedback?: string; agentSwitch?: string; planSave?: { enabled: boolean; customPath?: string } } = {}; + + // Always include agent switch setting for OpenCode + body.agentSwitch = agentSwitchSettings.switchTo; + + // Include plan save settings + body.planSave = { + enabled: planSaveSettings.enabled, + ...(planSaveSettings.customPath && { customPath: planSaveSettings.customPath }), + }; if (obsidianSettings.enabled && obsidianSettings.vaultPath) { body.obsidian = { @@ -481,10 +494,17 @@ const App: React.FC = () => { const handleDeny = async () => { setIsSubmitting(true); try { + const planSaveSettings = getPlanSaveSettings(); await fetch('/api/deny', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ feedback: diffOutput }) + body: JSON.stringify({ + feedback: diffOutput, + planSave: { + enabled: planSaveSettings.enabled, + ...(planSaveSettings.customPath && { customPath: planSaveSettings.customPath }), + }, + }) }); setSubmitted('denied'); } catch { @@ -616,7 +636,7 @@ const App: React.FC = () => { )} - + + + + {planSave.enabled && ( +
+ + handlePlanSaveChange({ customPath: e.target.value || null })} + placeholder="~/.plannotator/plans/" + className="w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50" + /> +
+ Leave empty to use default location +
+
+ )} + + + {origin === 'opencode' && ( + <> +
+ + {/* Agent Switching (OpenCode only) */} +
+
+
Agent Switching
+
+ Which agent to switch to after plan approval +
+
+ +
+ {AGENT_OPTIONS.find(o => o.value === agent.switchTo)?.description} +
+
+ + )} + +
+ {/* Tater Mode */}
Tater Mode
@@ -184,54 +286,54 @@ export const Settings: React.FC = ({ taterMode, onTaterModeChange {obsidian.enabled && (
- {/* Vault Path */} -
- - {vaultsLoading ? ( -
- Detecting vaults... -
- ) : detectedVaults.length > 0 ? ( - - ) : ( + {/* Vault & Folder Row */} +
+ {/* Vault Path */} +
+ + {vaultsLoading ? ( +
+ Detecting... +
+ ) : detectedVaults.length > 0 ? ( + + ) : ( + handleObsidianChange({ vaultPath: e.target.value })} + placeholder="/path/to/vault" + className="w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50" + /> + )} +
+ + {/* Folder */} +
+ handleObsidianChange({ vaultPath: e.target.value })} - placeholder="/Users/you/Documents/MyVault" + value={obsidian.folder} + onChange={(e) => handleObsidianChange({ folder: e.target.value })} + placeholder="plannotator" className="w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50" /> - )} - {detectedVaults.length === 0 && !vaultsLoading && ( -
- No vaults detected. Enter path manually. -
- )} +
- {/* Folder */} -
- - handleObsidianChange({ folder: e.target.value })} - placeholder="plannotator" - className="w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50" - /> -
- Plans saved to: {obsidian.vaultPath || '...'}/{obsidian.folder || 'plannotator'}/ -
+ {/* Save path preview */} +
+ Plans saved to: {obsidian.vaultPath || '...'}/{obsidian.folder || 'plannotator'}/
{/* Frontmatter Preview */} @@ -274,7 +376,8 @@ tags: [plan, ...] />
-
+ +
, document.body diff --git a/packages/ui/utils/agentSwitch.ts b/packages/ui/utils/agentSwitch.ts new file mode 100644 index 0000000..d292a65 --- /dev/null +++ b/packages/ui/utils/agentSwitch.ts @@ -0,0 +1,53 @@ +/** + * Agent Switch Settings Utility + * + * Manages settings for automatic agent switching after plan approval. + * Used by OpenCode users who want to disable auto-switch (e.g., oh-my-opencode). + * + * 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'; + +export type AgentSwitchOption = 'build' | 'disabled'; + +export interface AgentSwitchSettings { + switchTo: AgentSwitchOption; +} + +export const AGENT_OPTIONS: { value: AgentSwitchOption; label: string; description: string }[] = [ + { value: 'build', label: 'Build', description: 'Switch to build agent after approval' }, + { value: 'disabled', label: 'Disabled', description: 'Stay on current agent after approval' }, +]; + +const DEFAULT_SETTINGS: AgentSwitchSettings = { + switchTo: 'build', +}; + +/** + * Get current agent switch settings from storage + */ +export function getAgentSwitchSettings(): AgentSwitchSettings { + const stored = storage.getItem(STORAGE_KEY); + if (stored === 'disabled' || stored === 'build') { + return { switchTo: stored }; + } + return DEFAULT_SETTINGS; +} + +/** + * Save agent switch settings to storage + */ +export function saveAgentSwitchSettings(settings: AgentSwitchSettings): void { + storage.setItem(STORAGE_KEY, settings.switchTo); +} + +/** + * Check if agent switching is enabled + */ +export function isAgentSwitchEnabled(): boolean { + return getAgentSwitchSettings().switchTo !== 'disabled'; +} diff --git a/packages/ui/utils/planSave.ts b/packages/ui/utils/planSave.ts new file mode 100644 index 0000000..3548e85 --- /dev/null +++ b/packages/ui/utils/planSave.ts @@ -0,0 +1,56 @@ +/** + * Plan Save Settings Utility + * + * Manages settings for automatic plan saving after approval/denial. + * Users can configure custom save path or disable saving entirely. + * + * 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_ENABLED = 'plannotator-save-enabled'; +const STORAGE_KEY_PATH = 'plannotator-save-path'; + +export interface PlanSaveSettings { + enabled: boolean; + customPath: string | null; +} + +const DEFAULT_SETTINGS: PlanSaveSettings = { + enabled: true, + customPath: null, // null means use default ~/.plannotator/plans/ +}; + +/** + * Get current plan save settings from storage + */ +export function getPlanSaveSettings(): PlanSaveSettings { + const enabled = storage.getItem(STORAGE_KEY_ENABLED); + const customPath = storage.getItem(STORAGE_KEY_PATH); + + return { + enabled: enabled !== 'false', // default to true + customPath: customPath || null, + }; +} + +/** + * Save plan save settings to storage + */ +export function savePlanSaveSettings(settings: PlanSaveSettings): void { + storage.setItem(STORAGE_KEY_ENABLED, String(settings.enabled)); + if (settings.customPath) { + storage.setItem(STORAGE_KEY_PATH, settings.customPath); + } else { + storage.removeItem(STORAGE_KEY_PATH); + } +} + +/** + * Check if plan saving is enabled + */ +export function isPlanSaveEnabled(): boolean { + return getPlanSaveSettings().enabled; +}