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

Function createCommandExecuteHandler

lib/hooks.ts:159–282  ·  view source on GitHub ↗
(
    client: any,
    state: SessionState,
    logger: Logger,
    config: PluginConfig,
    workingDirectory: string,
    hostPermissions: HostPermissionSnapshot,
)

Source from the content-addressed store, hash-verified

157}
158
159export function createCommandExecuteHandler(
160 client: any,
161 state: SessionState,
162 logger: Logger,
163 config: PluginConfig,
164 workingDirectory: string,
165 hostPermissions: HostPermissionSnapshot,
166) {
167 return async (
168 input: { command: string; sessionID: string; arguments: string },
169 output: { parts: any[] },
170 ) => {
171 if (!config.commands.enabled) {
172 return
173 }
174
175 if (input.command === "dcp" || input.command === "dcp-compress") {
176 const messagesResponse = await client.session.messages({
177 path: { id: input.sessionID },
178 })
179 const messages = filterMessages(messagesResponse.data || messagesResponse)
180
181 await ensureSessionInitialized(
182 client,
183 state,
184 input.sessionID,
185 logger,
186 messages,
187 config.manualMode.enabled,
188 )
189
190 syncCompressPermissionState(state, config, hostPermissions, messages)
191
192 const effectivePermission = compressPermission(state, config)
193 if (effectivePermission === "deny") {
194 return
195 }
196
197 const args = (input.arguments || "").trim().split(/\s+/).filter(Boolean)
198 const isCompressCommand = input.command === "dcp-compress"
199 const subcommand = isCompressCommand ? "compress" : args[0]?.toLowerCase() || ""
200 const subArgs = isCompressCommand ? args : args.slice(1)
201
202 const commandCtx = {
203 client,
204 state,
205 config,
206 logger,
207 sessionId: input.sessionID,
208 messages,
209 }
210
211 if (subcommand === "context") {
212 await handleContextCommand(commandCtx)
213 return
214 }
215
216 if (subcommand === "stats") {

Callers 2

index.tsFile · 0.90

Calls 12

filterMessagesFunction · 0.90
ensureSessionInitializedFunction · 0.90
compressPermissionFunction · 0.90
handleContextCommandFunction · 0.90
handleStatsCommandFunction · 0.90
handleSweepCommandFunction · 0.90
handleDecompressCommandFunction · 0.90
handleRecompressCommandFunction · 0.90
handleHelpCommandFunction · 0.90

Tested by

no test coverage detected