Skip to content

Cairn v1.3.0

Choose a tag to compare

@github-actions github-actions released this 10 May 22:45
· 1833 commits to main since this release

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. onToolEnd fires as each tool completes. Per-file serialisation is handled transparently by the existing file mutex.

  • Edit tool unified diff — the edit tool 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: true on Unix, and their PIDs are tracked via trackPid/untrackPid. All tracked processes are killed as a process group (process.kill(-pid, "SIGKILL")) on app quit via before-quit, preventing zombie shells from surviving after Cairn exits.

  • transformContext hook — AgentLoopCallbacks gains an optional transformContext?: (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 a user message, matching the OpenAI API specification.

Fixes

  • Test suite aligned to refactored signature — pi-agent-loop.test.ts was calling runAgentLoop with the old positional parameter signature after the AgentToolContext refactor. All 10 call sites updated; 394/394 tests pass.

  • Lint clean — removed unused contextWindow parameter from slidingWindowFallback in compaction.ts; prefixed unused getWin destructuring in pi-agent-loop.ts to satisfy the no-unused-vars rule.

Changes

  • electron/lib/pi-agent-loop.ts — AgentToolContext interface introduced (groups cwd, db, req, workspacePath, sessionId, send, getWin?); runAgentLoop signature reduced from 11 to 6 parameters; AgentLLMConfig gains maxRetries?, baseRetryDelayMs?, contextWindow?; AgentLoopCallbacks gains onRetry?, transformContext?; PiAgentSession gains lastPromptTokens?; sequential tool loop replaced with Promise.all; isRetryable() and sleep() helpers added; sliding-window pruner built in as default fallback when no transformContext is provided
  • electron/lib/compaction.ts — new file; exports buildCompactionTransformer, COMPACT_THRESHOLD, FALLBACK_KEEP_TURNS, FALLBACK_THRESHOLD
  • electron/lib/coding-tools/bash.ts — detached: true on non-Windows; trackPid/untrackPid/killTrackedBashProcesses added
  • electron/lib/coding-tools/edit.ts — generateUnifiedDiff() (inline LCS) added; edit tool returns diff in output
  • electron/ipc/pi-agent.ts — buildCompactionTransformer wired into both runAgentLoop calls; pi-agent:compact and pi-agent:retry IPC events emitted
  • electron/preload.ts — onCompact bridge added to piAgent API
  • electron/main.ts — before-quit handler calls killTrackedBashProcesses()
  • src/components/agent/PiAgentPane.tsx — retry countdown UI; isCompacting state wired to onCompact; "Compacting context…" shown in status bar
  • electron/lib/pi-agent-loop.test.ts — all runAgentLoop call sites updated to new AgentToolContext signature; makeToolCtx helper added