(
client: any,
state: SessionState,
logger: Logger,
config: PluginConfig,
workingDirectory: string,
hostPermissions: HostPermissionSnapshot,
)
| 157 | } |
| 158 | |
| 159 | export 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") { |
no test coverage detected