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.
1.7 KiB
Managed System Prompt Optimizer
Purpose
This module injects an opt-in OpenCode plugin only when OpenChamber launches
and owns the OpenCode process and optimizeSystemPrompt is enabled. The plugin
replaces OpenCode's built-in behavioral/provider prompt with a short identity
while preserving the environment, project instructions, MCP instructions,
skills, conversation history, and separately supplied tools.
Runtime flow
- Settings persist
optimizeSystemPromptin OpenChamber'ssettings.json. - The setting is applied when managed OpenCode restarts.
- The runtime materializes the plugin under
<openchamber-data-dir>/system-prompt/and appends itsfile://URL toOPENCODE_CONFIG_CONTENTwithout replacing existing plugin entries. - The plugin tracks the selected agent through
chat.message. The transform runs only for sessions using the built-inbuildorplanagent. - The transform locates OpenCode's environment boundary and removes only the preceding text. If the boundary is absent, it leaves the prompt unchanged.
Limitations
OpenCode exposes the assembled prompt rather than structured sections. A custom
prompt configured by overriding the build or plan agent occupies the same
prefix as the built-in provider prompt, so the optimizer also removes that
override. Other agents are never transformed. The setting is off by default.
Plan-mode restrictions and build-mode transitions are not part of the removed prefix. OpenCode injects those as synthetic message reminders after system prompt transformation and separately enforces plan restrictions through tool permissions.
The plugin is not injected for external OpenCode servers or VS Code's separate OpenCode lifecycle.