diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index c9e24f8ca046..06b85ec12d90 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -694,6 +694,14 @@ export namespace SessionPrompt { system.push(MAX_STEPS) } + const original = [...system] + await Plugin.trigger("experimental.chat.system.transform", {}, { system }) + + if (system.length === 0) { + log.error("system prompt is empty after plugin transform, using original") + system.push(...original) + } + // max 2 system prompt messages for caching purposes const [first, ...rest] = system system = [first, rest.join("\n")] diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 57ca75d604f4..9dd4820b9f61 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -185,6 +185,12 @@ export interface Hooks { }[] }, ) => Promise + "experimental.chat.system.transform"?: ( + input: {}, + output: { + system: string[] + }, + ) => Promise "experimental.text.complete"?: ( input: { sessionID: string; messageID: string; partID: string }, output: { text: string },