Skip to content

About

Notebook-backed context windows for the Pi coding agent: notes, new_context, history.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

75 Commits

Folders and files

Repository files navigation

pi-note-context

Clean, summary-free context rollovers for the Pi coding agent.

Long coding sessions degrade when context fills up, and traditional LLM auto-compaction often summarizes away the exact decisions, ruled-out paths, file locations, and user preferences you need next.

pi-note-context replaces lossy summary compaction with a working notebook maintained by the agent itself. When a window rolls over, the new window opens cleanly with the notebook, an index of earlier requests, key user decisions, and mechanically extracted session facts — while everything that left the window stays searchable on demand.


Why pi-note-context?

Default Auto-Compaction pi-note-context
Handoff method Extra LLM call summarizes old messages Instant, deterministic rollover from the agent's working notebook
Large context windows (e.g. 1M) Waits until near full, after quality has already degraded Manages a configurable working budget (default 400K tokens)
Lost details Summarized away permanently Full current branch stays searchable via history
Edited files & commits Depends on whether the summary remembered them Mechanically extracted into the rollover handoff
Branching (/tree, /fork) Compaction snapshot Native branch-aware notebook revisions and history
Portability Standard Pi session Standard Pi session — readable even if you later uninstall this extension

Quick Start

Install the extension in Pi:

pi install git:github.com/KorenKrita/pi-note-context

That's it. No configuration is required — the extension works out of the box with sensible defaults.

Requirements: Pi >=0.87.0 (Node >=22). Optional Jev message classification activates automatically on Pi >=1.x when a TypeSafe classifier model is available, and silently falls back to built-in rules otherwise.


How It Works

  Work normally        Agent keeps a concise        Window approaches budget
  in Pi           ──▶  working notebook        ──▶  (or you ask for a fresh one)
                       (Task, State, Decisions,
                        Next, Refs)                        │
                                                           ▼
  Need an older detail?   ◀─────────────────────   Fresh context window opens
  Agent searches full                              with notebook + index +
  branch via `history`                             pinned decisions + facts

During a session, the extension gives the agent three focused tools:

  • notes — Read or update a compact, sectioned working notebook (up to 8 sections, capped at 16 KiB / ~4K tokens). Oversized writes are rejected atomically so existing notes are never partially overwritten.
  • new_context — Start a fresh context window cleanly without an extra summarization call.
  • history — Search, list, or read any earlier entry on the current session branch — including everything from previous context windows.

You don't need to micromanage any of these. As the conversation grows, the extension nudges the agent when notes become stale, schedules automatic rollovers once notes are fresh and enough context can be reclaimed, and enforces a safety checkpoint before the window hits its limit.


Everyday Controls

You stay in control at all times:

  • Inspect the current notebook: Run /notes in Pi to view the current revision number and every section of the working notebook.
  • Start a fresh window on demand: Simply tell the agent (e.g. "start a fresh context window"). It will update its notes and open a new window immediately, even if the current window is still small.
  • Run a custom compaction: Run /compact <your instructions> whenever you want Pi's normal summarization with specific instructions — pi-note-context automatically steps aside when custom instructions are provided.
  • Interrupt freely: Pressing Esc or sending a new message cancels any queued automatic rollover. The extension never forces a rollover after you interrupt a turn.

What Carries Over to a Fresh Window

Every rollover writes a standard Pi compaction entry containing four structured blocks:

  1. Working Notebook — The latest snapshot of Task, State, Decisions, Next, Refs, plus up to 3 temporary custom sections (8 total; extras are safely folded into State).
  2. Earlier User-Message Index — A compact, chronological one-line index of your earlier messages across all windows, so the agent sees what has already been discussed or investigated instead of redoing past work.
  3. Pinned Task & Decision Messages — Your opening task message stays verbatim, and key follow-up decisions or corrections from the closing window are preserved up to a token budget.
  4. Mechanically Extracted Facts — Even if the agent forgot to note them down, the rollover automatically extracts recently edited file paths, loaded SKILL.md files, git commits, and answers from interactive user prompts.

Everything else from earlier windows remains intact in the session journal and can be retrieved verbatim through history.


Optional Features

Smart Message Classification (Jev)

Enabled by default with zero-friction fallback. When Pi has access to a TypeSafe Jev classifier (default model: jev-latest), pi-note-context uses it to:

  • Classify incoming user messages (decide, ack, inform, ask, vent) so rollovers prioritize pinning actual decisions and corrections over casual acknowledgements.
  • Catch unrecorded decisions — if you make a clear decision and the notebook hasn't captured it yet, the extension gently reminds the agent once.

If no classifier model is configured, or if a call times out (default 5s), pi-note-context silently falls back to its built-in deterministic rules without interrupting your session.

Idle Notebook Tidy (Opt-In)

Disabled by default ("idleTidyEnabled": false). When enabled in an interactive session, if the agent finishes a turn, the session stays quiet for a configured period (default 55 minutes), and projected non-system reclaim reaches idleTidyMinReclaimTokens (defaults to minReclaimTokens; set 0 to disable), pi-note-context runs one quiet housekeeping pass to tidy the notebook (and optionally roll over if ready).

  • Runs at most once per user turn — never loops on itself.
  • Never resumes unfinished work or kicks off new tasks.
  • Cancels immediately if you type, run a bash command, or switch sessions.
  • Helpful if you leave long sessions open between bursts of work (and may help keep provider prompt caches warm where supported, though caching behavior depends on your model provider).

Common Configuration Recipes

Configuration lives in ~/.pi/agent/pi-note-context.json (or $PI_CODING_AGENT_DIR/pi-note-context.json). All fields are optional — omit anything you want to keep at its default.

Larger working budget for 1M-context models

Keep normal rollovers around 600K tokens while allowing a higher emergency ceiling:

{
  "budgetTokens": 600000,
  "fallbackBudgetTokens": 840000
}

Enable idle notebook tidying

Tidy the notebook automatically after 25 minutes of inactivity:

{
  "idleTidyEnabled": true,
  "idleTidyAfterMinutes": 25,
  "idleTidyMinReclaimTokens": 80000
}

Use a custom Jev classifier endpoint (or disable Jev)

{
  "jevEnabled": true,
  "jevModel": "jev-latest",
  "jevBaseUrl": "https://your-classifier-endpoint.example/v1",
  "jevApiKey": "$JEV_API_KEY"
}

To use pure deterministic rules without Jev:

{
  "jevEnabled": false
}

Skip models with built-in server-side compaction

List exact <provider>/<model-id> keys for models whose provider manages compaction externally:

{
  "externalCompactionModels": [
    "provider/model-id"
  ]
}

See docs/configuration.md for every option, default value, threshold calculation examples, and troubleshooting.


Compatibility

  • With /tree and /fork: Fully branch-aware. Navigating to an earlier branch restores the notebook revision and history belonging to that branch.
  • With SoL-Pi: Compatible with SoL-Pi's Action Fusion and ObservationPack. List pi-note-context after SoL-Pi in Pi's packages list, and keep SoL-Pi's Online Context Compact disabled so two rollover managers don't compete.
  • Uninstalling: Because rollovers are stored as standard Pi compaction entries, existing sessions remain complete and readable even without pi-note-context installed.

Documentation

Development

bun install
bun run verify   # TypeScript typecheck + full test suite

License

MIT

About

Notebook-backed context windows for the Pi coding agent: notes, new_context, history.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages