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 )
@@ -26,42 +25,7 @@ const plugin: Plugin = (async (ctx) => {
2625 } )
2726
2827 return {
29- "experimental.chat.system.transform" : async (
30- _input : unknown ,
31- output : { system : string [ ] } ,
32- ) => {
33- if ( state . isSubAgent ) {
34- return
35- }
36-
37- const systemText = output . system . join ( "\n" )
38- const internalAgentSignatures = [
39- "You are a title generator" ,
40- "You are a helpful AI assistant tasked with summarizing conversations" ,
41- "Summarize what was done in this conversation" ,
42- ]
43- if ( internalAgentSignatures . some ( ( sig ) => systemText . includes ( sig ) ) ) {
44- logger . info ( "Skipping DCP system prompt injection for internal agent" )
45- return
46- }
47-
48- const discardEnabled = config . tools . discard . enabled
49- const extractEnabled = config . tools . extract . enabled
50-
51- let promptName : string
52- if ( discardEnabled && extractEnabled ) {
53- promptName = "user/system/system-prompt-both"
54- } else if ( discardEnabled ) {
55- promptName = "user/system/system-prompt-discard"
56- } else if ( extractEnabled ) {
57- promptName = "user/system/system-prompt-extract"
58- } else {
59- return
60- }
61-
62- const syntheticPrompt = loadPrompt ( promptName )
63- output . system . push ( syntheticPrompt )
64- } ,
28+ "experimental.chat.system.transform" : createSystemPromptHandler ( state , logger , config ) ,
6529 "experimental.chat.messages.transform" : createChatMessageTransformHandler (
6630 ctx . client ,
6731 state ,
0 commit comments