← Catalog

pi-uncertainty-guard

RUPA trajectory uncertainty auditing and tool-call gating for pi.

Extension

Install

Install with PiG

pig install npm:pi-uncertainty-guard

Install with Pi

pi install npm:pi-uncertainty-guard
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": [
    "./src/index.ts"
  ]
}

README

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

pi uncertainty-guard

RUPA (trajectory_tau) trajectory risk auditing and tool-call gating for the pi coding agent. This directory is a self-contained npm/pi package: it does not require Agent-Confidence, Harbor, tau2, an API key, or a separate decision-model service.

Version 0.1.0. Author: Zhengzhao Ma. MIT licensed. See CHANGELOG and publishing instructions.

Install

Requirements: pi 0.84.4 (tested), Node 22.19.0+, Python 3.10+, and NumPy. This release targets the @earendil-works pi extension API; other package namespaces/versions have not been validated.

Install the tagged GitHub release after preparing the local scorer environment:

python3 -m venv "$HOME/.local/share/uncertainty-guard/venv"
export UNCERTAINTY_GUARD_PYTHON="$HOME/.local/share/uncertainty-guard/venv/bin/python"
"$UNCERTAINTY_GUARD_PYTHON" -m pip install 'numpy>=1.24,<3'
pi install git:github.com/mazhengzhao/uncertainty-guard-pi@v0.1.0

Source repository: https://github.com/mazhengzhao/uncertainty-guard-pi. When version 0.1.0 is available on npm, the equivalent npm installation is pi install npm:pi-uncertainty-guard@0.1.0. To load a source checkout or extracted release instead:

# Run from the extracted plugin directory. Keep the interpreter after install.
python3 -m venv "$HOME/.local/share/uncertainty-guard/venv"
export UNCERTAINTY_GUARD_PYTHON="$HOME/.local/share/uncertainty-guard/venv/bin/python"
"$UNCERTAINTY_GUARD_PYTHON" -m pip install -r requirements.txt
"$UNCERTAINTY_GUARD_PYTHON" scripts/doctor.py

# Install this local package directory.
pi install "$PWD"
# Alternatively load for one session:
pi -e "$PWD/src/index.ts"

For a release npm tarball, first extract it into a persistent directory:

mkdir -p "$HOME/.local/share/uncertainty-guard/pi-package"
tar -xzf /absolute/path/pi-uncertainty-guard-0.1.0.tgz \
  -C "$HOME/.local/share/uncertainty-guard/pi-package" --strip-components=1
pi install "$HOME/.local/share/uncertainty-guard/pi-package"

pi 0.84.4 treats a local file source as an extension file; passing a .tgz directly does not unpack it. The npm package source uses the npm: prefix. Persist UNCERTAINTY_GUARD_PYTHON in your shell configuration or launcher.

Follow pi's project trust prompt when using a project extension. With --no-extensions, explicitly load this extension using -e. The environment variable must be exported before pi starts. .pi/uncertainty-guard.json can override pythonBin with an absolute interpreter path. The configuration is project-local, relative to the agent's working directory, not this plugin's directory.

mkdir -p /path/to/your/project/.pi
cp uncertainty-guard.example.json /path/to/your/project/.pi/uncertainty-guard.json
# Optional: add pythonBin with an absolute path to override the environment.

Behavior

Before each tool call, map the current pi session branch to user, assistant, and environment steps and score its last 40 steps. The scorer uses relational uncertainty propagation, repetition, observation instability, momentum, and goal coverage. It does not call a language model and does not require logprobs. This is a heuristic trajectory risk score, not a calibrated probability of failure and not a security boundary.

Default thresholds and policy match the existing research plugin:

OptionDefaultMeaning
enabledtrueEnable scoring
pythonBinenv UNCERTAINTY_GUARD_PYTHON, else python3Scorer interpreter
mediumThreshold0.6Low/medium boundary
highThreshold1.2Medium/high boundary
autoBlockThresholdnullOptional unconditional risk-based block
strictModefalseInclude write/edit in high-risk confirmations
sensitiveBashPatternsSee src/config.tsCase-insensitive substring matches
maxStepsForBridge40Trajectory window
maxStepTextLength2000Text retained per step
requestTimeoutMs5000Bridge request timeout

Low/medium risk and high-risk nonsensitive tools only produce an audit record. High-risk sensitive tools request confirmation; rejecting confirmation blocks the tool. A configured auto-block threshold blocks without confirmation. Pi's noninteractive mode may reject confirmation; count these interventions when interpreting a benchmark. This plugin does not ask the model to reflect at every step or resample actions.

Audit entries are stored in pi sessions as customType=uncertainty-guard. Confirmation audit entries can include the sensitive shell command being reviewed, and should be treated as private session data. Run /uncertainty-status for the latest score. The bridge is a local Python subprocess, started per session and stopped on shutdown. On unavailable Python, missing NumPy, or scoring errors, the original fail-open behavior is retained with a warning; benchmark harnesses should check audit evidence to detect this. No telemetry or network request is made by the plugin. Session data is processed locally; the Python scorer and extension have the same local access as pi.

Verify, update and remove

The offline scripts/doctor.py command must return "ok": true. It tests the packaged Python bridge and scorer without using a model. It does not verify pi loaded the extension: after a normal tool call, /uncertainty-status should show a score and the session should contain an uncertainty-guard audit entry. A passing model request alone does not establish that scoring is active.

Use pi update --extensions for package updates and pi remove npm:pi-uncertainty-guard@0.1.0 to remove the pinned npm installation. An exact version stays pinned; install a newer version explicitly when upgrading. For a local package use pi remove /absolute/path/to/the/plugin with the same source passed to pi install. Keep the Python environment while either plugin still uses it.

Develop and package

npm install
npm run typecheck
npm test
npm run test:bridge
npm pack --dry-run
npm pack

npm pack includes source, the bridge, the bundled scorer, configuration and licenses. It excludes dependencies, sessions, credentials and research results. The Python dependency must be installed separately; npm cannot install it. Extract the resulting pi-uncertainty-guard-0.1.0.tgz as shown above before installing the unpacked directory with pi install. Publishing to npm is a separate action; this source directory is not published by the packaging commands above.

The scoring snapshot is identical to the one in the companion Claude Code plugin. See THIRD_PARTY_NOTICES.md for provenance and its SHA-256.

MIT license; bundled third-party notices are retained.