feat: add managed system prompt optimization

Add an opt-in OpenCode plugin that replaces the built-in provider behavioral prompt with a minimal identity while preserving environment, project, MCP, skill, history, and tool context.

Track the active agent per session and apply the transform only to build and plan. Keep plan/build mode reminders and permission enforcement owned by OpenCode, leave all other agents untouched, and fail safely when the expected prompt boundary is absent.

Expose the feature in Behavior settings with localized guidance, explicit Save + Reload application, settings search integration, persisted boolean validation, and managed-runtime lifecycle composition that does not load the plugin while disabled or on external OpenCode servers.

Document the runtime contract and cover plugin materialization, config preservation, build/plan selection, agent switching, unknown prompt formats, and settings sanitization.
This commit is contained in:
Bohdan Triapitsyn
2026-07-29 01:42:40 +03:00
parent 0259f11017
commit 3cf1d82106
21 changed files with 334 additions and 3 deletions
@@ -579,6 +579,11 @@ export const settingsDict = {
'settings.behavior.page.warning.title': 'Global rules are combined with project rules',
'settings.behavior.page.warning.description': 'Changes made here update {path}. OpenCode also includes any project-level AGENTS.md rules when they exist.',
'settings.behavior.page.section.systemPrompt': 'Global AGENTS.md',
'settings.behavior.page.section.systemPromptOptimization': 'System prompt optimization',
'settings.behavior.page.systemPromptOptimization.enable': 'Optimize system prompt size',
'settings.behavior.page.systemPromptOptimization.enableAria': 'Optimize OpenCode system prompt size',
'settings.behavior.page.systemPromptOptimization.info': 'Reduces the system prompt by an estimated 40% for the build and plan agents. Other agents are not changed. This can remove custom definitions that override build or plan, so do not enable it for workflows that customize those agents. Restarting OpenCode applies the change.',
'settings.behavior.page.systemPromptOptimization.restarting': 'Restarting OpenCode to apply system prompt optimization…',
'settings.behavior.page.field.systemPromptPlaceholder': 'You are a helpful AI assistant...\n\nUse this space to define absolute rules for how the AI should behave across all sessions and providers.',
'settings.behavior.page.section.responseStyle': 'Response style',
'settings.behavior.page.responseStyle.tooltip': 'When enabled, these instructions guide how the assistant responds in each new conversation. They are sent with your first message and do not change your global AGENTS.md rules.',