← Catalog

pi-nunc

In-session rolling context and working memory extension for Pi.

Extension

Install

Install with PiG

pig install npm:pi-nunc

Install with Pi

pi install npm:pi-nunc
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./dist/src/index.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.5 (README.md). PiG does not review it.

Nunc

Nunc is a Pi extension designed to keep a single long-running session coherent inside a finite context window.

Scope stays strictly within the active session branch: /new starts with empty memory, and /tree, /fork, and /clone follow the selected branch. Nunc avoids cross-session memory databases, user profiling, or background document indexing—durable project knowledge belongs in code, docs, and commits.

How It Works

Stock compaction replaces older conversation history with a single flat summary, which often drops exact constraints, parameters, or mid-task state over multiple compactions, and invalidates prompt caches when summaries move. Nunc replaces that summary with incremental working-memory slots (M) and a cache-friendly context layout:

Normal turn:   F | R_before | M | R_after
Compaction:    F | M | B | K   -->   updated M + retained K
  1. Verbatim recent history (R / K): Recent turns stay verbatim so the model sees exact tool calls, outputs, and immediate context.
  2. Anchored working memory (M): Information that still matters after older turns age out—goals, constraints, decisions, inputs, and unfinished work—lives in discrete text slots ({ id, text }). During normal turns, unchanged M stays anchored at the history boundary where it was last sent (R_before | M | R_after), keeping the prompt prefix stable for provider caching.
  3. Incremental maintenance: When Pi triggers compaction (threshold, overflow recovery, or /compact), Nunc splits active history into retiring B and retained K, then performs one extraction transaction on the session's current model, with bounded transient transport retry and no model-repair loop. The model returns a structured JSON patch (add, update, remove, priority, required, and optional toolResultEdits). All required items are kept together. Capacity, cancellation and provider-error failures preserve existing state. Eligible completed-response failures can instead save a mechanical window roll with unchanged M and retained K, visibly marking that retired history was not extracted. Targeted compaction does not use that fallback.
  4. Tool-result cleanup & overflow calibration: Completed business-tool outputs that have already been distilled into M (or duplicated in K) can be compacted or summarized in place while keeping raw originals in the session JSONL. If a provider undercounts tokens or rejects a maintenance request for context overflow, Nunc records branch-bound calibration so the next attempt automatically trims large tool bodies or fails fast without repeating the same rejected call.

Tools and TUI

Interactive TUI & Commands

  • /nunc or F7: Opens the Nunc overlay in TUI mode (Slots tab to search, preview, edit, or delete memory slots; Context tab to inspect the live F / M / R layout, token budgets, and last maintenance record). In non-TUI modes, /nunc prints the full text report.
  • /nunc details: Prints the text report (slot occupancy, budgets, last main/maintenance status, and recent diagnostics) without calling a model.
  • Footer indicator: Shows slot count and memory-target occupancy (🧠 8·42%, 🧠 0 when empty, 🧠 ↻8 during maintenance/save, 🧠 !8 on warnings, 🧠 × on invalid config).

Optional Model Tools (--nunc-memory-tools)

By default, Nunc manages M only during compaction without changing the model's toolset. When enabled via --nunc-memory-tools or Pi settings ({"nunc": {"memoryTools": true}}), Nunc exposes two tools to the model:

  • nunc_memory_read: Reads current slots, revision, and budget; also supports read-only keyword search (query) and entry lookup (entryIds, originals) over retired messages and cleaned tool outputs on the current session branch.
  • nunc_memory_patch: Atomically adds, updates, or removes memory slots (and optional toolResultEdits) during a turn using compare-and-swap (expectedRevision).

Requirements

DependencyVersion
NodeStable >=22.19.0 (.node-version: 26 for live checks)
npmStable >=11.5.1
Pi / @earendil-works/pi-ai / @earendil-works/pi-tuiRuntime: stable ^1.0.3; devDependencies pinned to 1.4.0

Runtime constraints:

  • Persistent sessions only (--no-session is rejected).
  • Native images only (images.blockImages must remain false).
  • Single custom compaction owner (do not run another compaction extension alongside Nunc).

Quick Start

git clone https://github.com/tefx/pi-nunc.git
cd pi-nunc
npm ci --ignore-scripts --no-audit --no-fund
npm run build

node node_modules/@earendil-works/pi-coding-agent/dist/cli.js \
  --offline --no-extensions -e dist/src/index.js

With a custom config file or model memory tools enabled:

node node_modules/@earendil-works/pi-coding-agent/dist/cli.js \
  --offline --no-extensions -e dist/src/index.js \
  --nunc-config ./nunc.json --nunc-memory-tools

package.json registers "pi": { "extensions": ["./dist/src/index.js"] }, so the repo directory can also be loaded as a local Pi package after npm run build.

Configuration

Pi settings.json

In ~/.pi/agent/settings.json or a trusted project .pi/settings.json:

{
  "nunc": {
    "memoryTools": false,
    "toolResultCleanup": true
  }
}

--nunc-config JSON

All fields are optional. policyFile resolves relative to the config file's directory.

FieldDefaultPurpose
policyFileunsetSupplemental UTF-8 Markdown maintenance preferences appended to policies/default.md.
memory.fraction0.1Planning reserve fraction of available context ([0, 1)).
memory.targetTokens8192Soft organizing target for M.
memory.maxTokensunsetOptional advisory ceiling on the maintenance organizing target.
memory.hardMaxTokensunsetOptional hard cap on saved M (when unset, required slots may exceed the soft target).
rolling.keepRecentFraction0.5Target fraction of post-M context kept as verbatim K ((0, 1)).
extraction.toolResults"auto""auto" (head/tail reduction only when needed to fit input limits) or "full".
extraction.headTailChars200Head and tail character count kept when reducing large tool results.
extraction.outputTokens"auto""auto" (scales from an 8192 floor up to model output capability) or positive integer.
budget.safetyTokens1024Safety margin subtracted from input limits.
budget.growthTokens1024Post-compaction growth room reserved for upcoming turns.
budget.extraMainInputTokens0Extra input token allowance for main requests.
budget.extraExtractionInputTokens0Extra input token allowance for maintenance requests.
budget.inputLimitunsetOptional explicit input token ceiling.
budget.imageTokensunsetOptional per-image token estimate override (defaults to Pi's heuristic).

Example nunc.json (overriding rolling.keepRecentFraction from 0.5 to 0.67):

{
  "policyFile": "./preferences.md",
  "memory": { "fraction": 0.1, "maxTokens": 2000, "hardMaxTokens": 8192 },
  "rolling": { "keepRecentFraction": 0.67 },
  "extraction": { "toolResults": "auto", "headTailChars": 200 },
  "budget": { "safetyTokens": 1024, "growthTokens": 1024 }
}

Development

npm ci and npm run build compile the extension. npm run check:engine uses the Node/npm floors above. The full check suite (scripts/check.mjs all) additionally requires Node ^26.7.0 for live preflight, historical Git objects and offline dependency-cache entries for comparison fixtures, POSIX PTYs, and /usr/bin/python3. The check runner rejects versions below the declared floors, malformed versions, and prereleases. Checks report the actual observed Node/npm versions; live preflight records the observed Node version in its receipt and SHA-256 binding, invalidating earlier receipts after a runtime change. See docs/DEVELOPMENT.md and docs/LIVE.md.

The build first emits TypeScript JS and declarations, then bundles dist/src/index.js into one ESM unit using the locked TypeScript compiler API (no additional bundler dependency). Local engine, Pi, and UI modules stay within that unit so Pi's /reload cannot combine an upgraded entrypoint with stale native ESM submodules. Host @earendil-works/pi-* modules and node:* builtins remain external. The standalone ./pi and ./engine exports and declarations remain available. Live build parity applies the same compiler and bundle transformation in memory without rewriting artifacts.

Comparison tests prepare and remove isolated temporary worktrees from 70dacad and immutable scoped-task pre-change commit 1d4fc4a210b64f71871ab3f5c10093215a25990c. Each fixture uses its own tracked dependency lock with offline installation and disabled lifecycle scripts; no pre-existing .scratch checkout is required.

Documentation

Detailed specifications live in docs/: