MCPcopy Index your code
hub / github.com/Opencode-DCP/opencode-dynamic-context-pruning / createSystemPromptHandler

Function createSystemPromptHandler

lib/hooks.ts:49–97  ·  view source on GitHub ↗
(
    state: SessionState,
    logger: Logger,
    config: PluginConfig,
    prompts: PromptStore,
)

Source from the content-addressed store, hash-verified

47]
48
49export function createSystemPromptHandler(
50 state: SessionState,
51 logger: Logger,
52 config: PluginConfig,
53 prompts: PromptStore,
54) {
55 return async (
56 input: { sessionID?: string; model: { limit: { context: number } } },
57 output: { system: string[] },
58 ) => {
59 if (input.model?.limit?.context) {
60 state.modelContextLimit = input.model.limit.context
61 logger.debug("Cached model context limit", { limit: state.modelContextLimit })
62 }
63
64 if (state.isSubAgent && !config.experimental.allowSubAgents) {
65 return
66 }
67
68 const systemText = output.system.join("\n")
69 if (INTERNAL_AGENT_SIGNATURES.some((sig) => systemText.includes(sig))) {
70 logger.info("Skipping DCP system prompt injection for internal agent")
71 return
72 }
73
74 const effectivePermission =
75 input.sessionID && state.sessionId === input.sessionID
76 ? compressPermission(state, config)
77 : config.compress.permission
78
79 if (effectivePermission === "deny") {
80 return
81 }
82
83 prompts.reload()
84 const runtimePrompts = prompts.getRuntimePrompts()
85 const newPrompt = renderSystemPrompt(
86 runtimePrompts,
87 buildProtectedToolsExtension(config.compress.protectedTools),
88 !!state.manualMode,
89 state.isSubAgent && config.experimental.allowSubAgents,
90 )
91 if (output.system.length > 0) {
92 output.system[output.system.length - 1] += "\n\n" + newPrompt
93 } else {
94 output.system.push(newPrompt)
95 }
96 }
97}
98
99export function createChatMessageTransformHandler(
100 client: any,

Callers 2

index.tsFile · 0.90

Calls 7

compressPermissionFunction · 0.90
renderSystemPromptFunction · 0.90
debugMethod · 0.80
infoMethod · 0.80
reloadMethod · 0.80
getRuntimePromptsMethod · 0.80

Tested by

no test coverage detected