11import type { Plugin } from "@opencode-ai/plugin"
22import { getConfig } from "./lib/config"
33import { Logger } from "./lib/logger"
4- import { loadPrompt } from "./lib/prompts"
54import { createSessionState } from "./lib/state"
65import { createDiscardTool , createExtractTool } from "./lib/strategies"
7- import { createChatMessageTransformHandler } from "./lib/hooks"
6+ import { createChatMessageTransformHandler , createSystemPromptHandler } from "./lib/hooks"
87
98const plugin : Plugin = ( async ( ctx ) => {
109 const config = getConfig ( ctx )
@@ -13,11 +12,6 @@ const plugin: Plugin = (async (ctx) => {
1312 return { }
1413 }
1514
16- // Suppress AI SDK warnings
17- if ( typeof globalThis !== "undefined" ) {
18- ; ( globalThis as any ) . AI_SDK_LOG_WARNINGS = false
19- }
20-
2115 const logger = new Logger ( config . debug )
2216 const state = createSessionState ( )
2317
@@ -26,38 +20,8 @@ const plugin: Plugin = (async (ctx) => {
2620 } )
2721
2822 return {
29- "experimental.chat.system.transform" : async (
30- _input : unknown ,
31- output : { system : string [ ] } ,
32- ) => {
33- const systemText = output . system . join ( "\n" )
34- const internalAgentSignatures = [
35- "You are a title generator" ,
36- "You are a helpful AI assistant tasked with summarizing conversations" ,
37- "Summarize what was done in this conversation" ,
38- ]
39- if ( internalAgentSignatures . some ( ( sig ) => systemText . includes ( sig ) ) ) {
40- logger . info ( "Skipping DCP system prompt injection for internal agent" )
41- return
42- }
23+ "experimental.chat.system.transform" : createSystemPromptHandler ( state , logger , config ) ,
4324
44- const discardEnabled = config . tools . discard . enabled
45- const extractEnabled = config . tools . extract . enabled
46-
47- let promptName : string
48- if ( discardEnabled && extractEnabled ) {
49- promptName = "user/system/system-prompt-both"
50- } else if ( discardEnabled ) {
51- promptName = "user/system/system-prompt-discard"
52- } else if ( extractEnabled ) {
53- promptName = "user/system/system-prompt-extract"
54- } else {
55- return
56- }
57-
58- const syntheticPrompt = loadPrompt ( promptName )
59- output . system . push ( syntheticPrompt )
60- } ,
6125 "experimental.chat.messages.transform" : createChatMessageTransformHandler (
6226 ctx . client ,
6327 state ,
0 commit comments