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)
The user wants me to:
Let me start by cloning the repo.
>cd /tmp && rm -rf clawdbot && git clone https://github.com/clawdbot/clawdbot.git 2>&1Repo cloned. Now let me explore the structure and find where they use the pi-mono SDK.
>cd /tmp/clawdbot && find . -type f -name "*.ts" -o -name "*.js" | head -50Let me look for the agent-related code that might use the pi-mono SDK.
>cd /tmp/clawdbot && ls -laLet me check for pi-mono or @anthropic references in package.json and look at the main source directory.
>cd /tmp/clawdbot && cat package.json | grep -E "(pi-mono|@anthropic|coding-agent)" | head -20>cd /tmp/clawdbot && ls -la src/They use @mariozechner/pi-coding-agent. Let me search for where they use this package and look for any pruning-related code.
>cd /tmp/clawdbot && rg -l "pi-coding-agent|@mariozechner" --type ts>cd /tmp/clawdbot && rg -l "prune|pruning|truncate|compaction" --type ts -iThere's a lot of pruning and compaction-related code. Let me examine the key files related to context pruning and tool result handling:
Good, they have dedicated files for context pruning. Let me examine the key files:
Excellent! This is very revealing. Let me also check the settings and the compact.ts file:
Let me also check the settings and the compact logic:
Now let me look at the compaction safeguard extension as well to get a complete picture:
Now I have a comprehensive view of their implementation. Let me summarize the findings:
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,});