Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dcp.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"default": "detailed",
"description": "Level of notification shown when pruning occurs"
},
"pruneNotificationType": {
"type": "string",
"enum": ["chat", "toast"],
"default": "chat",
"description": "Where to display prune notifications (chat message or toast notification)"
},
"commands": {
"type": "object",
"description": "Configuration for DCP slash commands (/dcp)",
Expand Down
20 changes: 20 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface PluginConfig {
enabled: boolean
debug: boolean
pruneNotification: "off" | "minimal" | "detailed"
pruneNotificationType: "chat" | "toast"
commands: Commands
turnProtection: TurnProtection
protectedFilePatterns: string[]
Expand Down Expand Up @@ -91,6 +92,7 @@ export const VALID_CONFIG_KEYS = new Set([
"debug",
"showUpdateToasts", // Deprecated but kept for backwards compatibility
"pruneNotification",
"pruneNotificationType",
"turnProtection",
"turnProtection.enabled",
"turnProtection.turns",
Expand Down Expand Up @@ -173,6 +175,17 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
}
}

if (config.pruneNotificationType !== undefined) {
const validValues = ["chat", "toast"]
if (!validValues.includes(config.pruneNotificationType)) {
errors.push({
key: "pruneNotificationType",
expected: '"chat" | "toast"',
actual: JSON.stringify(config.pruneNotificationType),
})
}
}

if (config.protectedFilePatterns !== undefined) {
if (!Array.isArray(config.protectedFilePatterns)) {
errors.push({
Expand Down Expand Up @@ -454,6 +467,7 @@ const defaultConfig: PluginConfig = {
enabled: true,
debug: false,
pruneNotification: "detailed",
pruneNotificationType: "chat",
commands: {
enabled: true,
protectedTools: [...DEFAULT_PROTECTED_TOOLS],
Expand Down Expand Up @@ -732,6 +746,8 @@ export function getConfig(ctx: PluginInput): PluginConfig {
enabled: result.data.enabled ?? config.enabled,
debug: result.data.debug ?? config.debug,
pruneNotification: result.data.pruneNotification ?? config.pruneNotification,
pruneNotificationType:
result.data.pruneNotificationType ?? config.pruneNotificationType,
commands: mergeCommands(config.commands, result.data.commands as any),
turnProtection: {
enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled,
Expand Down Expand Up @@ -775,6 +791,8 @@ export function getConfig(ctx: PluginInput): PluginConfig {
enabled: result.data.enabled ?? config.enabled,
debug: result.data.debug ?? config.debug,
pruneNotification: result.data.pruneNotification ?? config.pruneNotification,
pruneNotificationType:
result.data.pruneNotificationType ?? config.pruneNotificationType,
commands: mergeCommands(config.commands, result.data.commands as any),
turnProtection: {
enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled,
Expand Down Expand Up @@ -815,6 +833,8 @@ export function getConfig(ctx: PluginInput): PluginConfig {
enabled: result.data.enabled ?? config.enabled,
debug: result.data.debug ?? config.debug,
pruneNotification: result.data.pruneNotification ?? config.pruneNotification,
pruneNotificationType:
result.data.pruneNotificationType ?? config.pruneNotificationType,
commands: mergeCommands(config.commands, result.data.commands as any),
turnProtection: {
enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled,
Expand Down
77 changes: 77 additions & 0 deletions lib/ui/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ function buildDetailedMessage(
return (message + formatExtracted(showDistillation ? distillation : undefined)).trim()
}

const TOAST_BODY_MAX_LINES = 12
const TOAST_SUMMARY_MAX_CHARS = 600

function truncateToastBody(body: string, maxLines: number = TOAST_BODY_MAX_LINES): string {
const lines = body.split("\n")
if (lines.length <= maxLines) {
return body
}
const kept = lines.slice(0, maxLines - 1)
const remaining = lines.length - maxLines + 1
return kept.join("\n") + `\n... and ${remaining} more`
}

function truncateToastSummary(summary: string, maxChars: number = TOAST_SUMMARY_MAX_CHARS): string {
if (summary.length <= maxChars) {
return summary
}
return summary.slice(0, maxChars - 3) + "..."
}

function truncateExtractedSection(
message: string,
maxChars: number = TOAST_SUMMARY_MAX_CHARS,
): string {
const marker = "\n\n▣ Extracted"
const index = message.indexOf(marker)
if (index === -1) {
return message
}
const extracted = message.slice(index)
if (extracted.length <= maxChars) {
return message
}
return message.slice(0, index) + truncateToastSummary(extracted, maxChars)
}

export async function sendUnifiedNotification(
client: any,
logger: Logger,
Expand Down Expand Up @@ -100,6 +136,22 @@ export async function sendUnifiedNotification(
showDistillation,
)

if (config.pruneNotificationType === "toast") {
let toastMessage = truncateExtractedSection(message)
toastMessage =
config.pruneNotification === "minimal" ? toastMessage : truncateToastBody(toastMessage)

await client.tui.showToast({
body: {
title: "DCP: Prune Notification",
message: toastMessage,
variant: "info",
duration: 5000,
},
})
return true
}

await sendIgnoredMessage(client, sessionId, message, params, logger)
return true
}
Expand Down Expand Up @@ -150,6 +202,31 @@ export async function sendCompressNotification(
}
}

if (config.pruneNotificationType === "toast") {
let toastMessage = message
if (config.tools.compress.showCompression) {
const truncatedSummary = truncateToastSummary(summary)
if (truncatedSummary !== summary) {
toastMessage = toastMessage.replace(
`\n→ Compression: ${summary}`,
`\n→ Compression: ${truncatedSummary}`,
)
}
}
toastMessage =
config.pruneNotification === "minimal" ? toastMessage : truncateToastBody(toastMessage)

await client.tui.showToast({
body: {
title: "DCP: Compress Notification",
message: toastMessage,
variant: "info",
duration: 5000,
},
})
return true
}

await sendIgnoredMessage(client, sessionId, message, params, logger)
return true
}
Expand Down