mirror of
https://github.com/wassname/pi-dynamic-context-pruning.git
synced 2026-06-27 17:31:11 +08:00
docs: clarify 'DCP summary blocks' not message blocks, note message counting reset
This commit is contained in:
@@ -11,6 +11,7 @@ Automatically reduces token usage in Pi coding agent sessions by managing conver
|
|||||||
- **Manual mode** — disable autonomous compression nudges; trigger compression only via `/dcp compress` or explicit user request
|
- **Manual mode** — disable autonomous compression nudges; trigger compression only via `/dcp compress` or explicit user request
|
||||||
- **Session persistence** — compression blocks and pruning state survive session restarts
|
- **Session persistence** — compression blocks and pruning state survive session restarts
|
||||||
- **`/dcp` commands** — inspect context usage, view stats, sweep tool outputs, and manage compression blocks interactively
|
- **`/dcp` commands** — inspect context usage, view stats, sweep tool outputs, and manage compression blocks interactively
|
||||||
|
- **Auto-compaction** — triggers pi's built-in compaction when DCP summary blocks exceed a configurable fraction of context, preventing indefinite block accumulation
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -81,7 +82,13 @@ DCP uses a layered configuration system (later layers override earlier ones):
|
|||||||
// Glob patterns — matching file paths are never pruned
|
// Glob patterns — matching file paths are never pruned
|
||||||
"protectedFilePatterns": [],
|
"protectedFilePatterns": [],
|
||||||
// "off" | "minimal" | "detailed"
|
// "off" | "minimal" | "detailed"
|
||||||
"pruneNotification": "detailed"
|
"pruneNotification": "detailed",
|
||||||
|
// Auto-compaction: trigger pi's built-in compaction when DCP summary blocks
|
||||||
|
// occupy >= this fraction of context tokens (0 = disabled).
|
||||||
|
// Compaction deactivates all DCP blocks and resets message counting.
|
||||||
|
// "compact": {
|
||||||
|
// "autoCompactThreshold": 0.5
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export interface DcpConfig {
|
|||||||
protectUserMessages: boolean
|
protectUserMessages: boolean
|
||||||
}
|
}
|
||||||
compact: {
|
compact: {
|
||||||
autoCompactThreshold: number // 0-1, fraction of context that DCP blocks must occupy before triggering compaction (0 = disabled)
|
autoCompactThreshold: number // 0-1, fraction of context that DCP summary blocks must occupy before triggering compaction (0 = disabled). Compaction deactivates all DCP blocks and resets message counting.
|
||||||
}
|
}
|
||||||
strategies: {
|
strategies: {
|
||||||
deduplication: {
|
deduplication: {
|
||||||
@@ -62,7 +62,7 @@ const DEFAULT_CONFIG: DcpConfig = {
|
|||||||
protectUserMessages: false,
|
protectUserMessages: false,
|
||||||
},
|
},
|
||||||
compact: {
|
compact: {
|
||||||
autoCompactThreshold: 0.5, // trigger compaction when DCP blocks occupy >= 50% of context tokens
|
autoCompactThreshold: 0.5, // trigger compaction when DCP summary blocks occupy >= 50% of context tokens. Resets message counting.
|
||||||
},
|
},
|
||||||
strategies: {
|
strategies: {
|
||||||
deduplication: {
|
deduplication: {
|
||||||
@@ -109,7 +109,7 @@ const DEFAULT_CONFIG_FILE_CONTENT = `{
|
|||||||
// "protectedFilePatterns": [],
|
// "protectedFilePatterns": [],
|
||||||
// "pruneNotification": "detailed",
|
// "pruneNotification": "detailed",
|
||||||
// "compact": {
|
// "compact": {
|
||||||
// "autoCompactThreshold": 0.5 // trigger pi compaction when DCP blocks >= 50% of context (0 = disabled)
|
// "autoCompactThreshold": 0.5 // trigger pi compaction when DCP summary blocks >= 50% of context (0 = disabled). Resets message counting.
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ export default function (pi: ExtensionAPI) {
|
|||||||
// automaticStrategies is on) but skip autonomous nudge injection.
|
// automaticStrategies is on) but skip autonomous nudge injection.
|
||||||
const usage = ctx.getContextUsage()
|
const usage = ctx.getContextUsage()
|
||||||
if (usage && usage.tokens !== null) {
|
if (usage && usage.tokens !== null) {
|
||||||
// ── Auto-compaction: if DCP blocks exceed threshold, trigger pi compaction ──
|
// ── Auto-compaction: if DCP summary blocks exceed threshold, trigger pi compaction ──
|
||||||
if (!state.manualMode && config.compact.autoCompactThreshold > 0) {
|
if (!state.manualMode && config.compact.autoCompactThreshold > 0) {
|
||||||
const activeBlocks = state.compressionBlocks.filter((b) => b.active)
|
const activeBlocks = state.compressionBlocks.filter((b) => b.active)
|
||||||
const dcpBlockTokens = activeBlocks.reduce((sum, b) => sum + b.summaryTokenEstimate, 0)
|
const dcpBlockTokens = activeBlocks.reduce((sum, b) => sum + b.summaryTokenEstimate, 0)
|
||||||
@@ -263,10 +263,10 @@ export default function (pi: ExtensionAPI) {
|
|||||||
return { messages: prunedMessages }
|
return { messages: prunedMessages }
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── 11. session_compact: deactivate all DCP blocks ───────────────────────
|
// ── 11. session_compact: deactivate all DCP summary blocks and reset message counting ───────────────────────
|
||||||
// When pi's built-in compaction runs, it folds all prior context (including
|
// When pi's built-in compaction runs, it folds all prior context (including
|
||||||
// DCP summary blocks) into a single compaction summary. All active DCP
|
// DCP summary blocks) into a single compaction summary. All active DCP
|
||||||
// blocks are now redundant — deactivate them.
|
// blocks are now redundant — deactivate them and reset message counting.
|
||||||
pi.on("session_compact", async (_event, _ctx) => {
|
pi.on("session_compact", async (_event, _ctx) => {
|
||||||
const activeBlocks = state.compressionBlocks.filter((b) => b.active)
|
const activeBlocks = state.compressionBlocks.filter((b) => b.active)
|
||||||
if (activeBlocks.length > 0) {
|
if (activeBlocks.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user