Cairn v1.3.0
v1.3.0
What's new
Features
-
LLM-based context compaction — long Pi agent sessions no longer hit the context window ceiling. When token usage reaches 80% of the model's context window, the agent automatically summarises the oldest portion of the conversation with a lightweight non-streaming LLM call. The summary is injected as a structured context block; the 6 most recent turns are always preserved verbatim. Compaction runs asynchronously (fire-and-forget) so the current turn is never blocked — a sliding-window fallback is used for that turn if the summary isn't ready yet. A
"Compacting context…"indicator appears in the Pi agent status bar while the summary call is in flight. -
Automatic retry with exponential backoff — transient API errors (429, 500, 502, 503, 504, overloaded/rate-limit body patterns) are now retried automatically instead of failing the session. Up to 3 retries with 2 s / 4 s / 8 s backoff. A countdown badge (
"Transient error — retrying (1/3) in 8s…") appears in the status bar and is cleared when the retry succeeds. Abort cancels any in-progress sleep cleanly. -
Parallel tool execution — all tool calls in a single assistant turn now run concurrently via
Promise.all. Tool result messages are appended in original source order regardless of completion order.onToolEndfires as each tool completes. Per-file serialisation is handled transparently by the existing file mutex. -
Edit tool unified diff — the
edittool now returns a unified diff alongside the success confirmation, so the model and the user can see exactly what changed in each edit operation. The diff is generated inline using an LCS-based algorithm (no new dependencies). -
Bash process-group cleanup — bash subprocesses are now spawned with
detached: trueon Unix, and their PIDs are tracked viatrackPid/untrackPid. All tracked processes are killed as a process group (process.kill(-pid, "SIGKILL")) on app quit viabefore-quit, preventing zombie shells from surviving after Cairn exits. -
transformContexthook —AgentLoopCallbacksgains an optionaltransformContext?: (messages: AgentMessage[]) => AgentMessage[]hook that runs on the session message history before each LLM call without mutating the stored history. Used internally by both the compaction transformer and the sliding-window pruner. -
System prompt fix — the Pi agent system prompt is now passed as the
system:field in the OpenAI request body rather than prepended as ausermessage, matching the OpenAI API specification.
Fixes
-
Test suite aligned to refactored signature —
pi-agent-loop.test.tswas callingrunAgentLoopwith the old positional parameter signature after theAgentToolContextrefactor. All 10 call sites updated; 394/394 tests pass. -
Lint clean — removed unused
contextWindowparameter fromslidingWindowFallbackincompaction.ts; prefixed unusedgetWindestructuring inpi-agent-loop.tsto satisfy theno-unused-varsrule.
Changes
electron/lib/pi-agent-loop.ts—AgentToolContextinterface introduced (groupscwd,db,req,workspacePath,sessionId,send,getWin?);runAgentLoopsignature reduced from 11 to 6 parameters;AgentLLMConfiggainsmaxRetries?,baseRetryDelayMs?,contextWindow?;AgentLoopCallbacksgainsonRetry?,transformContext?;PiAgentSessiongainslastPromptTokens?; sequential tool loop replaced withPromise.all;isRetryable()andsleep()helpers added; sliding-window pruner built in as default fallback when notransformContextis providedelectron/lib/compaction.ts— new file; exportsbuildCompactionTransformer,COMPACT_THRESHOLD,FALLBACK_KEEP_TURNS,FALLBACK_THRESHOLDelectron/lib/coding-tools/bash.ts—detached: trueon non-Windows;trackPid/untrackPid/killTrackedBashProcessesaddedelectron/lib/coding-tools/edit.ts—generateUnifiedDiff()(inline LCS) added; edit tool returns diff in outputelectron/ipc/pi-agent.ts—buildCompactionTransformerwired into bothrunAgentLoopcalls;pi-agent:compactandpi-agent:retryIPC events emittedelectron/preload.ts—onCompactbridge added topiAgentAPIelectron/main.ts—before-quithandler callskillTrackedBashProcesses()src/components/agent/PiAgentPane.tsx— retry countdown UI;isCompactingstate wired toonCompact;"Compacting context…"shown in status barelectron/lib/pi-agent-loop.test.ts— allrunAgentLoopcall sites updated to newAgentToolContextsignature;makeToolCtxhelper added