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:
@@ -96,6 +96,7 @@ import { attachRealtimeProxy } from './lib/realtime-proxy.js';
|
||||
import { createRelayService } from './lib/relay/service.js';
|
||||
import { createRelayHostLock } from './lib/relay/host-lock.js';
|
||||
import { createAgentToolRuntime } from './lib/agent-tool/runtime.js';
|
||||
import { createSystemPromptRuntime } from './lib/system-prompt/runtime.js';
|
||||
import { createOpenChamberSessionService } from './lib/openchamber-sessions/routes.js';
|
||||
import { createScheduledTaskService } from './lib/scheduled-tasks/service.js';
|
||||
import { createOpenChamberControlService } from './lib/openchamber-control/service.js';
|
||||
@@ -269,6 +270,7 @@ const readCustomThemesFromDisk = (...args) => themeRuntime.readCustomThemesFromD
|
||||
|
||||
let notificationTemplateRuntime = null;
|
||||
let agentToolRuntime = null;
|
||||
let systemPromptRuntime = null;
|
||||
|
||||
const createTimeoutSignal = (...args) => notificationTemplateRuntime.createTimeoutSignal(...args);
|
||||
const formatProjectLabel = (...args) => notificationTemplateRuntime.formatProjectLabel(...args);
|
||||
@@ -1056,8 +1058,14 @@ const openCodeLifecycleRuntime = createOpenCodeLifecycleRuntime({
|
||||
getActiveSessionCount,
|
||||
getManagedOpenCodeEnv: async () => {
|
||||
const settings = await readSettingsFromDiskMigrated().catch(() => null);
|
||||
if (settings?.agentControlToolEnabled === false) return {};
|
||||
return agentToolRuntime?.prepareManagedOpenCodeEnv() || {};
|
||||
const managedEnv = settings?.agentControlToolEnabled === false
|
||||
? {}
|
||||
: await (agentToolRuntime?.prepareManagedOpenCodeEnv() || {});
|
||||
if (settings?.optimizeSystemPrompt !== true) return managedEnv;
|
||||
|
||||
const configContent = managedEnv.OPENCODE_CONFIG_CONTENT ?? process.env.OPENCODE_CONFIG_CONTENT;
|
||||
const systemPromptEnv = await systemPromptRuntime.prepareManagedOpenCodeEnv(configContent);
|
||||
return { ...managedEnv, ...systemPromptEnv };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1240,6 +1248,11 @@ async function main(options = {}) {
|
||||
return typeof address === 'object' && address ? address.port : null;
|
||||
},
|
||||
});
|
||||
systemPromptRuntime = createSystemPromptRuntime({
|
||||
fsPromises,
|
||||
path,
|
||||
dataDir: OPENCHAMBER_DATA_DIR,
|
||||
});
|
||||
|
||||
// Pairing transports advertised to the create-device dialog. LAN reachability is
|
||||
// derived from the SERVER's actual bind (a wildcard bind → the machine's LAN IP;
|
||||
|
||||
Reference in New Issue
Block a user