Pi Agent Rust
60-Second Bootstrap
export CARGO_TARGET_DIR="/data/tmp/pi_agent_rust/${USER:-agent}"
export TMPDIR="/data/tmp/pi_agent_rust/${USER:-agent}/tmp"
mkdir -p "$TMPDIR"
rch exec -- cargo check --all-targets
rch exec -- cargo clippy --all-targets -- -D warnings
cargo fmt --check
bash tests/installer_regression.sh
Symptom Router
| Symptom |
First 3 Commands |
| Provider stream/tool-call regression |
cargo test provider_streaming -- --nocapture ; `rg -n "stream |
| Session replay/index drift |
cargo test session -- --nocapture ; `rg -n "Session |
| Extension policy/runtime failure |
cargo test extension -- --nocapture ; `rg -n "policy |
| Installer/uninstaller/skill issue |
bash tests/installer_regression.sh ; `rg -n "AGENT_SKILL_STATUS |
| Interactive vs RPC divergence |
cargo test e2e_rpc -- --nocapture ; `rg -n "interactive |
For deeper diagnosis, use references/DEBUGGING-PLAYBOOKS.md.
Non-Negotiables
- Read
AGENTS.md first, then follow it exactly.
- Do not delete files or run destructive git/filesystem commands.
- Keep edits in-place; avoid creating variant files for the same purpose.
- Use
main semantics in docs/scripts; do not introduce master.
- Prefer
rg for fast text recon and ast-grep for structural matching/refactors.
- Prefer
rch exec -- <cargo ...> for heavy compile/test workloads.
- After substantive edits, run compile/lint/format gates and the smallest relevant regression slice.
Core Workflow
Changed Files -> Required Tests
| Changed Files (examples) |
Minimum Required Tests |
install.sh, uninstall.sh, .claude/skills/pi-agent-rust/** |
bash -n install.sh uninstall.sh tests/installer_regression.sh ; shellcheck -x install.sh uninstall.sh tests/installer_regression.sh ; bash tests/installer_regression.sh ; bash scripts/skill-smoke.sh |
src/providers/**, src/provider.rs, src/sse.rs |
cargo test provider_streaming ; cargo test conformance |
src/session.rs, src/session_index.rs, src/session_test.rs |
cargo test session ; cargo test conformance |
src/extensions.rs, src/extensions_js.rs |
cargo test extension ; cargo test conformance |
src/tools.rs |
cargo test tools ; cargo test conformance |
src/interactive.rs, src/rpc.rs, src/main.rs |
cargo test e2e_rpc ; cargo test conformance |
Do Not Run Yet
Run these only after targeted repro + focused slice indicates need:
- Broad
cargo test across entire workspace when a narrower slice already reproduces.
- Heavy multi-surface runs before confirming changed-file impact.
- Repeated full conformance loops while the core failing slice is still unstable.
High-Value Commands
# Fast recon
git status --short
rg -n "install|uninstall|skill|checksum|sigstore|completion|provider|session|extension" \
install.sh uninstall.sh README.md tests/installer_regression.sh src/
# Installer + skill safety gates
bash -n install.sh uninstall.sh tests/installer_regression.sh
shellcheck -x install.sh uninstall.sh tests/installer_regression.sh
bash tests/installer_regression.sh
bash scripts/skill-smoke.sh
# Rust gates
rch exec -- cargo check --all-targets
rch exec -- cargo clippy --all-targets -- -D warnings
cargo fmt --check
For an expanded command cookbook, see references/COMMANDS.md.
For deep incident triage, see references/DEBUGGING-PLAYBOOKS.md.
Critical Files
src/main.rs: CLI entry and mode dispatch.
src/agent.rs: agent loop and tool iteration behavior.
src/provider.rs: provider trait contract.
src/providers/: provider implementations and factory wiring.
src/tools.rs: built-in tools (read, write, edit, bash, grep, find, ls).
src/session.rs: JSONL session persistence.
src/session_index.rs: session index and metadata cache.
src/extensions.rs + src/extensions_js.rs: extension policy and QuickJS bridge.
src/interactive.rs + src/rpc.rs: TUI and RPC/stdin surfaces.
install.sh + uninstall.sh: install lifecycle, migration, and skill management.
tests/installer_regression.sh: installer regression harness.
scripts/skill-smoke.sh: skill integrity + inline-sync validation.
Known Footguns
- Custom artifact install paths without compatible release context can fall back incorrectly if not explicitly guarded.
- Skill status can become misleading on mixed outcomes unless partial/failure branches are explicit.
- Uninstall logic must enforce both marker checks and expected destination path shape.
- Installer progress/status text should stay on stderr when stdout is used for data plumbing.
- Bundled skill and inline fallback can silently drift unless explicitly checked.
Patch Patterns
Pattern 1: Mixed Outcome Status Clarity
# BEFORE: everything collapsed into "skipped custom"
if [ "$skipped_custom" -ge 1 ]; then
AGENT_SKILL_STATUS="skipped (existing custom skill)"
fi
# AFTER: distinguish custom-skip from write failure
if [ "$skipped_custom" -ge 1 ] && [ "$failed_writes" -ge 1 ]; then
AGENT_SKILL_STATUS="partial (custom skill kept; other install failed)"
elif [ "$skipped_custom" -ge 1 ]; then
AGENT_SKILL_STATUS="skipped (existing custom skill)"
fi
Pattern 2: Safe Skill Replacement
# BEFORE: remove destination before validating copy result
rm -rf "$destination"
cp "$source" "$destination/SKILL.md"
# AFTER: stage then atomically move into place
staged="$(mktemp -d ...)"
cp "$source" "$staged/SKILL.md"
mv "$staged" "$destination"
Failure Triage
- Installer summary/status mismatch:
trace
AGENT_SKILL_STATUS, CHECKSUM_STATUS, and COMPLETIONS_STATUS in install.sh.
- Install/uninstall safety concern:
verify marker checks and expected destination guards in both scripts.
- Provider/session/extension regressions:
use symptom router, then follow
references/DEBUGGING-PLAYBOOKS.md.
- Docs drift:
ensure
README.md flags/examples match current installer behavior.
Done Criteria
- Changed-file matrix minimum tests passed.
- Compile/lint/format checks passed for touched surfaces.
- Installer/skill changes pass
tests/installer_regression.sh and scripts/skill-smoke.sh.
- Behavior is explicit on failure paths; no silent fallback surprises.
- Skill docs and inline fallback remain aligned and current.
1---2name: pi-agent-rust3description: Speeds up pi_agent_rust development and verification workflows. Use when editing providers, tools, sessions, extensions, installer/uninstaller logic, or triaging regressions in this repo.4---56# Pi Agent Rust78## 60-Second Bootstrap910```bash11export CARGO_TARGET_DIR="/data/tmp/pi_agent_rust/${USER:-agent}"12export TMPDIR="/data/tmp/pi_agent_rust/${USER:-agent}/tmp"13mkdir -p "$TMPDIR"1415rch exec -- cargo check --all-targets16rch exec -- cargo clippy --all-targets -- -D warnings17cargo fmt --check18bash tests/installer_regression.sh19```2021## Symptom Router2223| Symptom | First 3 Commands |24|---|---|25| Provider stream/tool-call regression | `cargo test provider_streaming -- --nocapture` ; `rg -n "stream|tool|delta|event|SSE" src/providers src/sse.rs` ; `cargo test conformance` |26| Session replay/index drift | `cargo test session -- --nocapture` ; `rg -n "Session|save|open|index|jsonl|sqlite" src/session.rs src/session_index.rs` ; `cargo test conformance` |27| Extension policy/runtime failure | `cargo test extension -- --nocapture` ; `rg -n "policy|hostcall|capability|quickjs|deny|allow" src/extensions.rs src/extensions_js.rs` ; `cargo test conformance` |28| Installer/uninstaller/skill issue | `bash tests/installer_regression.sh` ; `rg -n "AGENT_SKILL_STATUS|CHECKSUM_STATUS|SIGSTORE_STATUS|COMPLETIONS_STATUS" install.sh` ; `rg -n "managed skill|expected skill directory|PIAR_AGENT_SKILL" uninstall.sh` |29| Interactive vs RPC divergence | `cargo test e2e_rpc -- --nocapture` ; `rg -n "interactive|rpc|stdin|event|session" src/main.rs src/interactive.rs src/rpc.rs` ; `cargo test conformance` |3031For deeper diagnosis, use `references/DEBUGGING-PLAYBOOKS.md`.3233## Non-Negotiables3435- Read `AGENTS.md` first, then follow it exactly.36- Do not delete files or run destructive git/filesystem commands.37- Keep edits in-place; avoid creating variant files for the same purpose.38- Use `main` semantics in docs/scripts; do not introduce `master`.39- Prefer `rg` for fast text recon and `ast-grep` for structural matching/refactors.40- Prefer `rch exec -- <cargo ...>` for heavy compile/test workloads.41- After substantive edits, run compile/lint/format gates and the smallest relevant regression slice.4243## Core Workflow4445- [ ] Recon: identify exact change surface and invariants.46- [ ] Implement: minimal, behavior-focused patch with explicit failure semantics.47- [ ] Validate: targeted tests first, broaden only as needed.48- [ ] Verify UX: error/status output is explicit, stable, and non-ambiguous.49- [ ] Sync docs: update `README.md` when flags/behavior/user guidance changed.5051## Changed Files -> Required Tests5253| Changed Files (examples) | Minimum Required Tests |54|---|---|55| `install.sh`, `uninstall.sh`, `.claude/skills/pi-agent-rust/**` | `bash -n install.sh uninstall.sh tests/installer_regression.sh` ; `shellcheck -x install.sh uninstall.sh tests/installer_regression.sh` ; `bash tests/installer_regression.sh` ; `bash scripts/skill-smoke.sh` |56| `src/providers/**`, `src/provider.rs`, `src/sse.rs` | `cargo test provider_streaming` ; `cargo test conformance` |57| `src/session.rs`, `src/session_index.rs`, `src/session_test.rs` | `cargo test session` ; `cargo test conformance` |58| `src/extensions.rs`, `src/extensions_js.rs` | `cargo test extension` ; `cargo test conformance` |59| `src/tools.rs` | `cargo test tools` ; `cargo test conformance` |60| `src/interactive.rs`, `src/rpc.rs`, `src/main.rs` | `cargo test e2e_rpc` ; `cargo test conformance` |6162## Do Not Run Yet6364Run these only after targeted repro + focused slice indicates need:6566- Broad `cargo test` across entire workspace when a narrower slice already reproduces.67- Heavy multi-surface runs before confirming changed-file impact.68- Repeated full conformance loops while the core failing slice is still unstable.6970## High-Value Commands7172```bash73# Fast recon74git status --short75rg -n "install|uninstall|skill|checksum|sigstore|completion|provider|session|extension" \76 install.sh uninstall.sh README.md tests/installer_regression.sh src/7778# Installer + skill safety gates79bash -n install.sh uninstall.sh tests/installer_regression.sh80shellcheck -x install.sh uninstall.sh tests/installer_regression.sh81bash tests/installer_regression.sh82bash scripts/skill-smoke.sh8384# Rust gates85rch exec -- cargo check --all-targets86rch exec -- cargo clippy --all-targets -- -D warnings87cargo fmt --check88```8990For an expanded command cookbook, see `references/COMMANDS.md`.91For deep incident triage, see `references/DEBUGGING-PLAYBOOKS.md`.9293## Critical Files9495- `src/main.rs`: CLI entry and mode dispatch.96- `src/agent.rs`: agent loop and tool iteration behavior.97- `src/provider.rs`: provider trait contract.98- `src/providers/`: provider implementations and factory wiring.99- `src/tools.rs`: built-in tools (`read`, `write`, `edit`, `bash`, `grep`, `find`, `ls`).100- `src/session.rs`: JSONL session persistence.101- `src/session_index.rs`: session index and metadata cache.102- `src/extensions.rs` + `src/extensions_js.rs`: extension policy and QuickJS bridge.103- `src/interactive.rs` + `src/rpc.rs`: TUI and RPC/stdin surfaces.104- `install.sh` + `uninstall.sh`: install lifecycle, migration, and skill management.105- `tests/installer_regression.sh`: installer regression harness.106- `scripts/skill-smoke.sh`: skill integrity + inline-sync validation.107108## Known Footguns109110- Custom artifact install paths without compatible release context can fall back incorrectly if not explicitly guarded.111- Skill status can become misleading on mixed outcomes unless partial/failure branches are explicit.112- Uninstall logic must enforce both marker checks and expected destination path shape.113- Installer progress/status text should stay on stderr when stdout is used for data plumbing.114- Bundled skill and inline fallback can silently drift unless explicitly checked.115116## Patch Patterns117118### Pattern 1: Mixed Outcome Status Clarity119120```bash121# BEFORE: everything collapsed into "skipped custom"122if [ "$skipped_custom" -ge 1 ]; then123 AGENT_SKILL_STATUS="skipped (existing custom skill)"124fi125126# AFTER: distinguish custom-skip from write failure127if [ "$skipped_custom" -ge 1 ] && [ "$failed_writes" -ge 1 ]; then128 AGENT_SKILL_STATUS="partial (custom skill kept; other install failed)"129elif [ "$skipped_custom" -ge 1 ]; then130 AGENT_SKILL_STATUS="skipped (existing custom skill)"131fi132```133134### Pattern 2: Safe Skill Replacement135136```bash137# BEFORE: remove destination before validating copy result138rm -rf "$destination"139cp "$source" "$destination/SKILL.md"140141# AFTER: stage then atomically move into place142staged="$(mktemp -d ...)"143cp "$source" "$staged/SKILL.md"144mv "$staged" "$destination"145```146147## Failure Triage148149- Installer summary/status mismatch:150 trace `AGENT_SKILL_STATUS`, `CHECKSUM_STATUS`, and `COMPLETIONS_STATUS` in `install.sh`.151- Install/uninstall safety concern:152 verify marker checks and expected destination guards in both scripts.153- Provider/session/extension regressions:154 use symptom router, then follow `references/DEBUGGING-PLAYBOOKS.md`.155- Docs drift:156 ensure `README.md` flags/examples match current installer behavior.157158## Done Criteria159160- Changed-file matrix minimum tests passed.161- Compile/lint/format checks passed for touched surfaces.162- Installer/skill changes pass `tests/installer_regression.sh` and `scripts/skill-smoke.sh`.163- Behavior is explicit on failure paths; no silent fallback surprises.164- Skill docs and inline fallback remain aligned and current.