Cloned repository to local directory.
SetupReviewed code for pruning logic.
UnderstandConfirmed comprehensive pruning implementation.
Verifyclone this repo to /tmp https://github.com/clawdbot/clawdbot. then analyze if they implemented tool result pruning or any form of history pruning in the code that uses pi-mono (coding-agent SDK)
Good, they have dedicated files for context pruning. Let me examine the key files:
Let me also check the settings and the compact logic:
Clawdbot implements comprehensive history and tool result pruning using the pi-coding-agent SDK. Here's what they built:
pi-extensions/context-pruning/)A pi-coding-agent extension that hooks into the context event to prune tool results before they're sent to the LLM.
Two modes:
adaptive: Progressively trims tool results based on context window utilization
"[Old tool result content cleared]"aggressive: Immediately clears all prunable tool results outside the protected tail
Key settings:
keepLastAssistants: 3 - protects the last 3 assistant turns from any pruningpi-embedded-runner/history.ts)Limits conversation history to the last N user turns for long-running DM sessions. Configurable per-provider and per-user via dmHistoryLimit.
session-tool-result-guard.ts)Monkey-patches SessionManager.appendMessage to:
<final> tags from assistant text before persistencetransformToolResultForPersistence hook for pre-persist transformationspi-extensions/compaction-safeguard.ts)Hooks into session_before_compact to generate summaries when the SDK's built-in compaction triggers:
All this is wired into the embedded pi runner via buildEmbeddedExtensionPaths() which registers these as SDK extensions:
const additionalExtensionPaths = buildEmbeddedExtensionPaths({ cfg: params.config, sessionManager, provider, modelId, model,});The pruning uses char-based estimates (4 chars/token) rather than precise token counting for performance.
const additionalExtensionPaths = buildEmbeddedExtensionPaths({ cfg: params.config, sessionManager, provider, modelId, model,});