← Catalog

@kvidzibo/pi-context

Preview, filter, trace, and capture Pi startup context

Package

Install

Install with PiG

pig install npm:@kvidzibo/pi-context

Install with Pi

pi install npm:@kvidzibo/pi-context
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": [
    "./index.ts"
  ]
}

README

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

pi-context

npm · GitHub

Preview and disable Pi startup context, trace its sources, and save provider requests as JSON, YAML, or normalized YAML.

Install

From GitHub:

pi install git:github.com/kvidzibo/pi-context

Or from npm:

pi install npm:@kvidzibo/pi-context

Requires Node.js 22.19+ and Pi 1.5.0+. Restart Pi after installing. After editing a loaded extension, use /reload.

Usage

Run /context to open Pi's native settings list:

SettingAction
CaptureToggle saving on/off; defaults off
OutputCycle JSON → YAML → Normalized YAML → JSON
Output directoryEdit the prefilled, unique temporary path
Preview startup contextExpand/minimise and enable/disable startup branches
Disable permanentlySave disabled matches for new sessions, after confirmation
Analyse disabled linesPrint source evidence without calling a model
Ask model to removeConfirm a model request to edit authoritative source files

Use the configured selection keys (normally ↑/↓ and Enter or Space); Esc closes. Settings apply immediately. Editing the directory uses Pi's editor; Esc returns without changing it. Relative paths resolve from the session's working directory; ~ is supported. Missing directories are created with mode 0700. Existing directory permissions are unchanged.

Startup preview and exclusions

The source/section tree shows initial system instructions, tool declarations, and extension-message text before the first user message—not conversation history. On / mixed / off shows whether a branch is included, has disabled descendants, or is excluded. Parent exclusions cover descendants; enable the parent before changing an inherited exclusion. Tool declarations are selectable only as whole tools; their schemas are read-only. Fenced code blocks and indented examples do not create heading or source boundaries. If an unterminated fence contains source tags, or a fence crosses file-closing/opening tags, the range is labeled Unsplit context (ambiguous source delimiters): it can be read or excluded as a whole, but granular exclusions are not applied to guessed file boundaries.

  • Enter expands/collapses a branch, or reads a leaf. → opens a branch or moves into it; ← collapses it or moves to its parent. Configured Pi tree-fold keys also work.
  • Space disables/restores the selected branch. Restoring a parent preserves its individually disabled descendants.
  • v reads the full original branch, with its source and breadcrumb. Tab switches between original text and normalized YAML. Both are read-only views of the original snapshot, including disabled text, not the filtered request.
  • In the reader, use the configured selection/page keys to scroll, Home/End to jump, and Esc to return to the same tree selection. Escape from the tree returns to settings.

The preview header distinguishes Provisional from Captured snapshot. Before the first request, the preview is provisional: extensions and tool-loadout preparation can still change it. The first request records the prefix before the first user message. This snapshot remains the preview for that session. Later chat messages, tool results, and images are never filtered.

Exclusions and expansion state persist in the active session branch across /reload, resume, and forks. Filtering runs on each normal model call, including tool follow-ups, and also removes exact matches from later system patches. It does not rewrite stored history. Source scope, exact text, and duplicate occurrence/count must match; changed or ambiguous branches remain enabled. Analyse disabled lines identifies exclusions that no longer match the startup snapshot.

Disable permanently merges exclusions into $PI_CODING_AGENT_DIR/context-settings.json (normally ~/.pi/agent/context-settings.json), not Pi's main settings file. New sessions inherit them; existing sessions retain their choices. Re-enabling a branch overrides the exclusion for that session only. To remove permanent exclusions, edit this file's disabled array; then start a new session. Failed or malformed settings writes are reported without replacing the file. An interrupted write can leave a .lock; remove it only after verifying no other writer is running.

Analyse disabled lines prints loaded file paths and matching line numbers, symlink targets, changed-file warnings, tool provenance, and generated-file source headers where available. Built-in, CLI, and extension-generated text may have no exposed file origin; the report says so rather than guessing. It is a display-only session entry.

Ask model to remove explicitly sends disabled text back as quoted evidence in a confirmed user request. It asks the model to verify sources, edit authoritative files rather than generated outputs, regenerate and validate, and ask about ambiguous origins. The extension itself does not edit instruction files. Reload or a new session may be necessary after those edits.

Request capture

Choosing a format or directory does not enable capture. Enable Capture to save each future provider request, including tool follow-ups. Capture off pauses saving. Capture settings are session-local and reset on session switch or /reload: capture off, JSON output, and a new temporary path. Startup exclusions and expansion state are retained. Nothing is saved retroactively.

At each turn's end, a display-only transcript entry lists saved paths. These entries never enter model context. Write errors are reported without blocking requests or claiming success.

Output formats

  • JSON (.json): pretty-printed provider request data.
  • YAML (.yml): the same data, with literal blocks for multiline strings where possible. This is a readable serialization, not the original JSON wire format.
  • Normalized YAML (.normalized.yml): a labeled, transformed reading view. Paired standalone tags become ordered sections with attributes and content. Embedded JSON objects/arrays become structures, including nested encoded JSON. Markdown headings, paragraphs, lists, and separators become ordered blocks; list nesting and numbering are retained.

Normalization is conservative, not a general document converter. Inline syntax, code, blockquotes, HTML comments, malformed tags, and invalid/duplicate-key JSON remain literal. Tags and JSON inside lists stay within their items. Blank prose lines are omitted; code whitespace and original empty JSON fields are preserved. Quoted attributes are not entity-decoded. Parsing stops at 64 nested levels. Use JSON or YAML when original values matter.

Privacy and limitations

  • Files contain unredacted requests: prompts, tool output, secrets in context, and embedded images may be included. Files use mode 0600 and unique names. They are not automatically removed or size-limited; delete them when finished.
  • The startup snapshot and exclusions contain unredacted instructions and tool declarations. They are stored in session entries; permanent settings contain the excluded text. Treat both as sensitive. Full captured requests are not retained in memory after saving.
  • Exclusions are not a security boundary or a tool-execution permission system. They cannot erase prior requests, assistant recollections, provider-owned prompts, or text repeated in conversation. Compaction and other auxiliary model calls are outside the normal request hook.
  • The captured payload is the request body at this hook, not HTTP headers or proof of delivery. Later extensions can modify it; load this extension after request-transforming extensions for the closest view. SDK/provider transformations and remote prompt processing are outside its scope.
  • Retries appear separately only when the provider invokes the hook again. Separate delegate processes need their own loaded extension; this package does not aggregate them.
  • The settings menu requires interactive TUI mode. Context changes are allowed only while idle. Load after extensions that change prompts: later hooks can reintroduce text. Unsupported or malformed prompt markup remains literal; normalization never replaces the original request text.

Develop and validate

npm ci --ignore-scripts
pi -e ./index.ts
npm run check
dbus-run-session -- xvfb-run -a npm test
npm pack --dry-run

The test wrapper requires dbus-run-session, xvfb-run, and xauth. Tests make no model requests.

Publishing

Package: @kvidzibo/pi-context. The initial public release is 0.3.0.

One-time bootstrap after review: run npm login and npm publish --ignore-scripts for the first release. In npm package settings, add a GitHub Actions trusted publisher: owner kvidzibo, repository pi-context, workflow publish.yml, no environment. Allow direct npm publish. CI uses OIDC, not an npm token secret.

Later releases bump package.json and package-lock.json together in a PR. Every push to main runs tests on Node 22.19 and 24, then publishes new stable versions publicly with provenance. Existing versions are skipped; registry lookup failures stop publishing. No release tag is needed. Pull requests run the same checks without publishing.

License

MIT.