omp packages

@lifetime42/pi-retro0.3.1

Lean, Harness²-inspired offline improvement loop for pi with judge gating and git-versioned anti-oscillation history

lifetime42 Published 4 hours ago MIT ~0 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-retro

A lean, Harness²-inspired offline improvement loop for pi. Normal sessions stay untouched; when you run /retro, a Proposer analyzes scrubbed session friction against your full harness git history, and a separate Judge agent gates every change (adopt or reject) before auto-committing and reloading pi.

What sets it apart: every change passes an independent judge and a real A/B benchmark gate before it lands, every decision (adopted, rejected, reverted) lives in git so the loop never oscillates back to a rejected idea, and /retro status shows whether the retros actually pay for themselves.

Quickstart

Requires Node.js >= 22.18 (zero runtime dependencies).

1. Install into pi

Copy & run in your terminal (use GitHub's copy button on the right):

pi install npm:@lifetime42/pi-retro
# or straight from GitHub:
pi install git:github.com/lifetime42/pi-retro

(For local development, you can also load directly via pi --extension ~/pi-retro/extension/index.ts or symlink ~/.pi/agent/extensions/pi-retro → ~/pi-retro/extension.)

2. Configure inside pi

Run /retro setup inside pi to pick your Proposer and Judge models directly from pi's model list (just like /model), set your harness repo path (default ~/.pi/agent/pi-retro-harness), add an optional external git remote, and link AGENTS.md:

/retro setup

Tip: You can also just ask pi in chat (e.g., "Configure pi-retro with Qwen 32B as proposer and Claude Sonnet as judge") — the extension registers a pi_retro_configure tool so pi can write and validate ~/.pi/agent/pi-retro.json for you.

(Prefer terminal setup? npm run setup is also available when cloned locally.)

3. Verify & Run

Inside pi:

/retro status    # Verify config, models, and recent harness commits
/retro dry-run   # Preview proposals & judge verdicts without committing
/retro           # Run the loop, commit adopted changes, log rejections, and reload

If an adopted change isn't helpful, roll it back cleanly with one command:

/retro revert <sha>

The revert commit enters git history so future /retro runs won't oscillate back to it.


Commands

Command Behavior
/retro Collect new sessions since last run → Propose → Judge → auto-commit adopted changes (1 atomic commit each), log rejections to DECISIONS.md, reload pi, and print a summary with the conclusion and per-proposal judge reasons. Shows a blocking live progress screen (step, active model, elapsed, ETA) that previews the proposals under discussion, what is being judged right now, and the latest verdict; Esc stops and saves a checkpoint — run /retro again to resume. If a checkpoint exists, /retro resumes it automatically. The final outcome — including stops and failures — is also persisted as a permanent entry in the session transcript (like tool output), so nothing is lost when the progress screen closes; it survives reloads and session resume. The proposer's proposals and each judge verdict are streamed into the transcript live as expandable entries (compact header by default, full rationale/evidence/reasoning on expand, just like pi tool calls/results) — without ever being sent to the main model.
/retro setup Interactive in-pi setup wizard for harness repo, optional external git remote, Proposer & Judge models, config, and AGENTS.md symlink
/retro dry-run Run Collect → Propose → Judge without committing or advancing the session cursor
/retro bench [sha] Run the lightweight policy + friction replay benchmark in harness/evals/ (or A/B compare HEAD against commit <sha>)
/retro status Show harness repo path, proposer/judge models, limits, eval counts, last run timestamp, payback (retro token spend vs. friction/session and real tokens/session trend, first vs. last runs), and last 5 harness commits
/retro revert <sha> Run git revert --no-edit <sha> in the harness repo and reload pi
/retro discard Drop the saved checkpoint of an interrupted run (next /retro starts fresh)
/retro reset Clear the session cursor (lastRunIso + processed map) and any checkpoint so the next /retro re-scans all sessions. Harness history (adopted commits + DECISIONS.md) is preserved, so anti-oscillation stays intact.

How It Works

At a glance:

flowchart LR
    H(("Harness<br/>v1")) -->|"/retro"| C(("Harness v2<br/>candidate"))
    C -->|"eval<br/>(judge + benchmark)"| D{"Does it<br/>help?"}
    D -->|"yes: v2 replaces v1"| H
    D -->|"no"| X["Discarded<br/>(logged to DECISIONS.md)"]

In detail:

flowchart TD
    S["Pi v3 Sessions<br/>(*.jsonl)"] --> C["1. Collect & Scrub<br/>active branch · friction signals · secret redaction"]
    H["Harness Git Repo<br/>files · full git history · DECISIONS.md"] --> I["2. Issue Spotter (Model A)<br/>spot generalizable issues & save checkpoint"]
    C --> I

    subgraph Loop ["3. Per-Issue Loop (sequential, checkpointed)"]
        D["Draft Proposal (Model A)<br/>against staged candidate tree"]
        G{"Safety & Token Budget<br/>path check · AGENTS.md cap · ROI brief"}
        J{"Independent Judge (Model B)<br/>evidence · quality · anti-oscillation · ROI"}
        ST["Stage in Memory<br/>update candidate tree"]
        RJ["Log to DECISIONS.md<br/>& commit rejection"]
        SK1["Skip<br/>(Fail-Closed)"]

        D --> G
        G -->|unsafe / over budget| SK1
        G -->|pass| J
        J -->|adopt| ST
        J -->|reject| RJ
        J -->|error / invalid| SK1
    end

    I -->|"for each issue"| D
    H -.->|"history & rules"| D
    H -.->|"history & rules"| J

    ST -->|"after loop: all staged changes"| B{"4. Batch A/B Benchmark Gate<br/>real headless pi: HEAD vs candidate<br/>(when harness/evals/*.json exist)"}
    B -->|"pass (or no evals)"| A["5. Apply & Commit<br/>1 atomic commit per change<br/>+ auto-capture friction evals"]
    B -->|regression| RB["Reject Whole Batch<br/>log all to DECISIONS.md"]
    B -->|error| SK2["Skip Batch<br/>(Fail-Closed)"]

    A --> RL["Save Cursor, Clear Checkpoint<br/>& Reload pi"]
    RB --> SC["Save Cursor &<br/>Clear Checkpoint"]
    SK2 --> SC
  1. Collect & Scrub (extension/sessions.ts, extension/scrub.ts): Scans new Pi JSONL v3 sessions since the last run, walks only the active parentId branch, extracts friction signals (tool errors, repeated retries, user corrections, aborts), truncates excerpts, and redacts API keys, JWTs, auth headers, private keys, .env secrets, and local usernames.
  2. Full History Anti-Oscillation (extension/history.ts): Loads the current harness/ tree, complete git history (including reverts and diffs, with budgeted fallback), and harness/DECISIONS.md (all previously rejected proposals).
  3. Issues → Draft → Safety/ROI → Judge (extension/retro.ts, extension/prompts.ts, extension/roi.ts, extension/checkpoint.ts): Model A first spots a list of generalizable issues (problems + evidence), shown to you so you know what's coming. Then, per issue, Model A drafts one proposal (add/update/expand/shrink) against the staged candidate tree; path safety, the AGENTS.md token budget, and a zero-LLM historical-savings ROI brief are checked; and Model B independently rules on it. Judge-adopted proposals are staged in memory, rejections are committed to DECISIONS.md, and progress is checkpointed after each issue so Esc can stop and resume cleanly. Uncapped by default (maxProposalsPerRun: 0).
  4. Batch A/B Benchmark Gate (extension/bench.ts): When benchmark.enabled is true and harness/evals/*.json cases exist, one real headless pi A/B benchmark compares baseline (HEAD) against the full candidate harness (all staged changes together) using deterministic checks and a blinded order-swapped judge. A regression that a fresh re-run reproduces rejects the whole staged batch (only the aggregate score is logged to DECISIONS.md, and evals/ is kept out of the history the proposer sees); CLI or benchmark errors fail closed (skip).
  5. Apply, Capture Evals & Reload (extension/harness.ts, extension/git.ts, extension/index.ts): Passing staged proposals become individual atomic commits on main (optionally auto-capturing scrubbed counterfactual friction evals into harness/evals/), the session cursor is saved, the checkpoint is cleared, and pi reloads automatically.

Safety Boundaries

  • The extension (extension/) is an immutable control plane and never edits itself.
  • All edits are strictly path-checked inside harness/ (no .., absolute paths, .git, symlink escapes, editing evals/, or deleting DECISIONS.md).
  • ~/.pi/agent/auth.json is never placed in git.
  • Benchmark runs (/retro bench, batch gate) use throwaway temp workspaces but are not network-isolated: the headless pi can reach the internet. Restrict egress yourself if that matters.
  • Judge failures (network errors, malformed JSON, unsafe paths) fail closed — proposals are skipped and never auto-adopted.

Documentation

  • Configuration Reference — all config options, provider recipes (LM Studio, llama.cpp, Ollama, OpenRouter, OpenAI, Anthropic), and state cursor details
  • Architecture & Pipeline — active-branch JSONL v3 parsing, friction heuristics, secret scrubbing, anti-oscillation git history, and Proposer/Judge contracts
  • Harness Repository Guide — managing AGENTS.md, skills/, prompts/, manual commits, and rollbacks
  • Troubleshooting — common config, provider, fail-closed judge, and revert issues
  • Blueprint — original design specification

Development

Requires Node.js >= 22.18 (zero runtime dependencies).

npm test          # Run unit & integration tests (node --test)
npm install       # Optional: install @types/node + typescript for typechecking
npm run typecheck # Run tsc --noEmit

See PLAN.md for the full architecture blueprint.