omp packages

pi-uncertainty-guard0.1.0

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

winhana Published 11 days ago MIT ~324 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

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:

Option Default Meaning
enabled true Enable scoring
pythonBin env UNCERTAINTY_GUARD_PYTHON, else python3 Scorer interpreter
mediumThreshold 0.6 Low/medium boundary
highThreshold 1.2 Medium/high boundary
autoBlockThreshold null Optional unconditional risk-based block
strictMode false Include write/edit in high-risk confirmations
sensitiveBashPatterns See src/config.ts Case-insensitive substring matches
maxStepsForBridge 40 Trajectory window
maxStepTextLength 2000 Text retained per step
requestTimeoutMs 5000 Bridge 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.