-
-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathhelp.ts
More file actions
76 lines (62 loc) · 3 KB
/
Copy pathhelp.ts
File metadata and controls
76 lines (62 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* DCP Help command handler.
* Shows available DCP commands and their descriptions.
*/
import type { Logger } from "../logger"
import type { PluginConfig } from "../config"
import type { SessionState, WithParts } from "../state"
import { compressPermission } from "../shared-utils"
import { sendIgnoredMessage } from "../ui/notification"
import { getCurrentParams } from "../strategies/utils"
export interface HelpCommandContext {
client: any
state: SessionState
config: PluginConfig
logger: Logger
sessionId: string
messages: WithParts[]
}
const BASE_COMMANDS: [string, string][] = [
["/dcp context", "Show token usage breakdown for current session"],
["/dcp stats", "Show DCP pruning statistics"],
["/dcp sweep [n]", "Prune tools since last user message, or last n tools"],
["/dcp manual [on|off]", "Toggle manual mode or set explicit state"],
]
const TOOL_COMMANDS: Record<string, [string, string]> = {
compress: ["/dcp compress [focus]", "Trigger manual compress tool execution"],
decompress: ["/dcp decompress <n>", "Restore selected compression"],
recompress: ["/dcp recompress <n>", "Re-apply a user-decompressed compression"],
}
function getVisibleCommands(state: SessionState, config: PluginConfig): [string, string][] {
const commands = [...BASE_COMMANDS]
if (compressPermission(state, config) !== "deny") {
commands.push(TOOL_COMMANDS.compress)
commands.push(TOOL_COMMANDS.decompress)
commands.push(TOOL_COMMANDS.recompress)
}
return commands
}
function formatHelpMessage(state: SessionState, config: PluginConfig): string {
const commands = getVisibleCommands(state, config)
const colWidth = Math.max(...commands.map(([cmd]) => cmd.length)) + 4
const lines: string[] = []
lines.push("╭─────────────────────────────────────────────────────────────────────────╮")
lines.push("│ DCP Commands │")
lines.push("╰─────────────────────────────────────────────────────────────────────────╯")
lines.push("")
lines.push(` ${"Manual mode:".padEnd(colWidth)}${state.manualMode ? "ON" : "OFF"}`)
lines.push("")
for (const [cmd, desc] of commands) {
lines.push(` ${cmd.padEnd(colWidth)}${desc}`)
}
lines.push("")
return lines.join("\n")
}
export async function handleHelpCommand(ctx: HelpCommandContext): Promise<void> {
const { client, state, logger, sessionId, messages } = ctx
const { config } = ctx
const message = formatHelpMessage(state, config)
const params = getCurrentParams(state, messages, logger)
await sendIgnoredMessage(client, sessionId, message, params, logger)
logger.info("Help command executed")
}