pi-mantice
Integrated Mantice runtime for Pi: routed models, mechanical request reduction, accountable goals, managed subagents, and an event-driven activity sidebar
Package details
Install pi-mantice from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-mantice- Package
pi-mantice- Version
1.4.5- Published
- Sep 14, 2026
- Downloads
- 241/mo · 225/wk
- Author
- ffrappo
- License
- MIT
- Types
- extension, skill, prompt
- Size
- 2 MB
- Dependencies
- 4 dependencies · 3 peers
Pi manifest JSON
{
"skills": [
"./node_modules/pi-subagent-extension/skills"
],
"prompts": [
"./node_modules/pi-codex-goal/prompts"
],
"extensions": [
"./extensions",
"./node_modules/pi-codex-goal/extensions/index.ts",
"./node_modules/pi-subagent-extension/index.ts",
"./node_modules/pi-message-sidebar/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-mantice
Integrated Mantice runtime for Pi: live routed models, pre-request mechanical reduction, accountable autonomous goals, managed subagents, and an event-driven activity sidebar.
The 1.3 line absorbs and replaces fornace-pi-models and bundles the reviewed
Fornace goal, subagent, and sidebar components. One package install keeps their
event and persistence contracts at matching revisions.
What it does
- Before either Mantice transport runs, an oversized request is mechanically projected below the lesser of 200K tokens and half the advertised context window. Images count at pi's fixed raster estimate (1200 tokens each), not their base64 wire size, because providers bill the decoded raster. When mechanical reduction cannot shrink a request, the guard admits it unreduced as long as it fits within the model's actual context window, so reduction limits never stop work. Provider failures remain the router's concern and do not cause irrelevant request compaction.
- Active goal budgets include parent and child input plus output. Child usage receipts are durable, deduplicated and reconciled after restart.
- Managed subagents share FIFO capacity, retain session files, release capacity while idle, and yield their partial result when a worker token tranche is reached. A background yield wakes the still-active parent once. One worker's budget yield does not block unrelated assignments.
- The sidebar consumes goal and worker events without polling. It distinguishes
active, queued, failed, paused and yielded workers. Message summaries have
bounded durable attempts and honor
Retry-Afterbefore automatic recovery. - Astra is used only when explicitly requested. Routine delegation uses
fornace-flash,fornace-fast,fornace-reasoningandfornace-max. - Registers
mantice(groups + aliases) andfornace(curated groups) from the authenticatedGET /v1/modelsat startup. One fetch shared by both. - Derives Pi model metadata from the gateway's capability fields (
mode,class,input_modalities,thinking) instead of hardcoded id lists. Gateways without those fields fall back to the legacy literal classifier with one loud warning; gateways with them fail closed on missing rows. - Fail-closed guard:
fornace-max/maxmust advertise > 128K context or registration aborts with the offending row named. A stale or missing client-side window silently strangles compaction (see the 2026-09-03 incident notes indocs/PLAN.md). - Two-stage compaction. Stage 1 (
/fast session) is aggressive mechanical pruning: the summarized span is replaced by a deterministic, byte-bounded digest (default ceiling 64 KiB) in milliseconds, with zero model calls. All user messages are retained as chronological excerpts (progressive caps 16 KiB to 128 B under budget pressure); older reasoning and tool payloads become references; assistant text becomes deduplicated excerpts. Stage 2 stays Pi native:/compact(manual or auto) summarizes the pruned payload with the session model, so the AI summary never sees unpruned bulk. Original session history always remains recoverable in the JSONL. - Agent-initiated compaction: the
fast_sessiontool lets the agent run stage 1 itself when context approaches ~50%, without waiting for the user. It arms the mechanical gate mid-turn and fires the exact same compaction path on the first idleagent_settled, so it never aborts an active run. While armed, any threshold or overflow auto-compaction also turns mechanical (zero model calls) instead of an expensive AI summary. - Native RTK integration: supported Bash
commands are rewritten for Mantice sessions to return compact output, and
the
fast_read/fast_writetools expose RTK's filtered read and heuristic smart summary as first-class tools for cheap file re-reads after compaction. Install thertkbinary on PATH (brew install rtkon macOS); no separate Pi RTK extension is needed. An existing RTK extension can coexist.RTK_DISABLED=1opts out of command rewriting; missing RTK preserves normal command execution and history pruning. - Overflow recovery: upstream context-miss wordings (including Z.ai code
- are canonicalized to
context_length_exceededso Pi auto-compacts and retries once. Rate limits and route-availability errors are never rewritten.
- are canonicalized to
- Failover transparency: one notice per backend model change on a route
(
fornace-max served by glm-5.3), context math untouched. - On Pi >= 0.85.1 with retries enabled, explicit gateway admission failures
keep the original request alive and retry every 30–60 seconds until capacity
returns or you cancel, including pre-execution deployment drain/quiesce and
full worker pools. Requires the gateway's
X-Mantice-Admissionmarker, recognized admission code, andupstream_started: falseon every HTTP attempt. No new user message or history rewrite occurs. Policy rejections, ambiguous transport failures, partial output and unmarked upstream errors keep their normal handling. This is not restart recovery or a universal error retry loop. - Session isolation: agent requests to Mantice providers send one opaque
X-Mantice-Session-ID, stable across resume and different for new sessions. This enables gateway-side session-local recovery without modifying payloads or cache-affinity headers. Requires Pi'sbefore_provider_headershook (verified with Pi 0.84.4). Other providers are untouched.
Install
pi install npm:pi-mantice@1.3.0
pi install git:github.com/Fornace/pi-mantice@v1.3.0
Requires MANTICE_API_KEY (and optionally MANTICE_BASE_URL) in the
environment. Remove any hand-written mantice/fornace blocks from
~/.pi/agent/models.json; this package owns both providers.
Fast commands
/fast shows help; subcommands have completion.
| Command | Action |
|---|---|
/fast session [focus] |
Mechanical compaction now: replace the summarized span with a bounded digest, zero model calls, optionally carrying a focus line, e.g. /fast session deployment |
/fast preview |
Estimate pruning savings without a model call |
/fast status |
Show context usage, selected model, stage status and last compaction |
/fast rtk |
Check the installed RTK binary and restore native integration after installation |
/compact |
Stage two: Pi native AI-assisted compaction of the pruned context |
Mechanical compaction preserves the original history in the session JSONL and
makes no LLM request; the digest is bounded (64 KiB ceiling), deterministic and
carries every user message as an excerpt. It requires an idle session without
queued messages and does not resume its task. Empty or already compact sessions
return a simple notice. /compact runs Pi's own summarizer on the pruned
payload. Preview measures serialized active-context bytes; the actual
summarization span also depends on Pi's retained window. Status, preview, help
and RTK checks do not call a model. RTK_DISABLED=1 remains respected by the
RTK check.
The fast_session tool is the agent-callable twin of /fast session: the
model can invoke it mid-turn when it notices context pressure (agents should
call it at ~50% usage and then finish the reply). It never compacts inline,
because compaction aborts the active run; it arms the mechanical gate and the
compaction fires automatically on the first idle agent_settled after the
turn, with the same notifications and stats as the slash command.
Setup for your own gateway
/mantice-setup walks a fresh Mantice installation: probes your provider
credentials, discovers models, classifies them into max/reasoning/
fast/flash plus modality groups using the daily
pi-frontier snapshot, shows the
full routing plan, and publishes it only after you type APPLY against the
current routing_revision. Non-empty registries require --replace.
Fornace production hosts are blocked by default.
Verify
npm test # unit tests, no Pi or network needed
npm run typecheck
npm run test:session-wire # real Pi CLI against an isolated loopback fixture
npm run verify:package # both wire checks from the tarball without local Pi peers
MANTICE_BIN=/absolute/path/to/mantice npm run test:session-recovery # full local chain
npm run snapshot # refresh extensions/models-snapshot.json from the live catalog
npm run audit # spawn a real Pi and compare its registry to the live catalog
Layout
src/catalog.tslive/snapshot catalog → Pi model entries (both tiers)src/classes.tsclass policy: max/reasoning/fast/flashsrc/summary-pruning.tsmechanical pruning of the summarizer's copysrc/mechanical-compaction.tsbounded digest builder (stage 1)src/fast-commands.ts/fastcommands and the mechanical gatesrc/rtk.ts,src/rtk-tools.tsRTK command rewriting and fast toolssrc/overflow.tscanonical overflow mapping + response-model noticessrc/frontier.tspi-frontier join used by setup and annotationssrc/spend-guard.ts,src/guard-projection.tspre-request reduction and managed-child allowance enforcementnode_modules/pi-codex-goalaccountable autonomous goal runtimenode_modules/pi-subagent-extensionmanaged delegation and usage receiptsnode_modules/pi-message-sidebargoal and worker activity surfacevendor/PROVENANCE.mdexact bundled component commits and SHA256 valuesextensions/mantice-models.tsMantice provider and guard wiringdocs/PLAN.mdarchitecture plan, incidents, and rollout gates
Publishing
The tag-push v* workflow uses npm trusted publishing with provenance. It
requires effective npm authorization for Fornace/pi-mantice, publish.yml,
and direct publishing. An npm E404 alone does not identify which permission
or identity setting is wrong; inspect the authenticated package settings.
Do not replace an existing staged-approval policy without owner authorization.
For a new release, review and validate current main, choose an unused package
version and matching fresh tag, and push through this workflow. It checks that
the tag matches package.json and that the checked-out event commit is current
main, both before validation and immediately before publishing. A main update
detected at either check stops publication. Never move an existing tag to work
around this. Tracked source changes also stop publication. These checks are
not an atomic lock on future main updates.
Older workflow runs retain their old workflow and do not gain this guard:
rerunning the old v1.0.1 run cannot distribute newer recovery fixes.
Source push, npm publication, installation and loaded-session adoption are separate states. Verify registry version and gitHead after a successful publish.