Metadata-Version: 2.5
Name: secondop-panel
Version: 1.0.2
Summary: A second opinion on your code from a PANEL of vendors, not one model. One reviewer is a special case of a panel, and it should be named out loud.
Project-URL: Homepage, https://github.com/tonydzi/secondop-panel
Project-URL: Source, https://github.com/tonydzi/secondop-panel
Project-URL: Issues, https://github.com/tonydzi/secondop-panel/issues
Project-URL: Changelog, https://github.com/tonydzi/secondop-panel/releases
Author: Palo Alto AI Research Lab
License: MIT License
        
        Copyright (c) 2026 Anton Dziatkovskii / Palo Alto AI Research Lab
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agents,cli,code-review,llm,multi-vendor,panel,second-opinion
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# secondop-panel

Asks several different AI models to review your code change at the same time, so you do not rely on one model's opinion.

**Who it's for:** developers who use an AI agent to write code and want a real second look before calling it "done".
**What you get:** one command that sends your files to reviewers from different AI companies, then prints their findings and an exit code that only says "pass" when enough different companies actually answered.

## Quick start
1. Download the repo: `git clone https://github.com/tonydzi/secondop-panel.git` and open the folder.
2. Copy `panel.example.json` to `panel.json`, keep only the reviewers you have, and set your own API key as an environment variable (for example `OPENROUTER_API_KEY`).
3. Run `python secondop_panel.py selftest`, then `python secondop_panel.py t3 --task my-fix --files src/a.py --context "what I changed"`.

**Done when:** selftest ends with `0 failed`, and the review prints which reviewers answered and which did not, with a verdict.

> Want an AI agent to do it for you? Paste this to Claude Code / Codex / Cursor:
> "Read the 'For AI agents' section of https://github.com/tonydzi/secondop-panel and set it up for me."

## For AI agents

### Preconditions
- Python 3.8 or newer. One stdlib-only file, no `pip` dependencies.
- At least two reviewers from different AI companies ("families"). Each is either a logged-in CLI on PATH (`codex`, `grok`, `gemini`, `claude`) or an OpenAI-compatible HTTP endpoint with an API key in the environment.
- Ask the human: which reviewer CLIs they have logged in, which API keys they are willing to use (for example OpenRouter), and whether this code is allowed to leave the machine. The panel sends full file contents to third parties (see `docs/SECURITY.md`).

### Install
```bash
git clone https://github.com/tonydzi/secondop-panel.git
cd secondop-panel
cp panel.example.json panel.json   # PowerShell: Copy-Item panel.example.json panel.json
```
Optional, to get a `secondop-panel` command (declared in `pyproject.toml`): `pip install .`. You can also just copy the single file `secondop_panel.py` into a project.

### Configure
- `panel.json` (read from next to the script, or from `$SECONDOP_PANEL_CONF`): a `quorum` number and a list of `rails`. Each rail has a `name`, a `family` (the AI company; quorum counts families, not rails), and either `kind: "http"` with `api`, `key_env`, `model`, or `kind: "cmd"` with a `cmd` list. Keep only the rails the human really has.
- API keys come from the environment only, named by `key_env`. The human supplies them. Never write a key into `panel.json`.
- Usage log goes to `panel_usage.jsonl` next to the script, or `$SECONDOP_PANEL_LOG`.
- Optional agent skill: `skills/secondop-panel/SKILL.md` (copy to `~/.claude/skills/secondop-panel/SKILL.md` for Claude Code).
- Wire in three moments, as in `PROMPT.md`: `t1` before coding, `t2` at a design fork, `t3` after the change. Always pass real files to `--files`, never only paths.

### Verify
```bash
python secondop_panel.py selftest
python secondop_panel.py doctor
```
Expected: `selftest: <N> checks, 0 failed` and exit `0` (offline, no keys; this clone printed `33 checks`). `doctor` prints one line per reviewer: `OK`, `DEGRADED` (installed but refusing) or `ABSENT`, and whether live families meet quorum. Without `panel.json`, `doctor` prints `no rails configured` and exits `2`. A real review (`t3`) exits `0` only when quorum is met, `3` when there was no independent second opinion (treat as a warning, never a pass), `2` on bad config.

### Uninstall / rollback
Delete the cloned folder (or the copied `secondop_panel.py`, `panel.json`, `panel_usage.jsonl`). `pip uninstall secondop-panel` if you used `pip install .`. Remove any hook or CI step you added that calls it.

### Rules for the agent
- Before sending anything, show the human what leaves the machine: `python secondop_panel.py t3 --files <file> --print-prompt` calls nobody.
- Never send a file you have not read. Never send files that hold secrets or private data.
- Never put API keys in `panel.json` or any repo file. Environment variables only.
- Never let a dead reviewer fall back to another vendor, and never report a pass on exit code `3`. Say which families were missing.
- Do not choose cheap "flash" or "lite" model tiers to save money. They return empty answers and silently shrink the quorum.

## Details

**Nobody reviews themselves.** The usual fix — "have another model check it" — quietly collapses into asking *one* other model, and one model is one opinion with one blind spot.

This is the panel: a review request fanned out to **several model families at once**, with a verdict contract, quorum counted by family, and an exit code that refuses to go green when there was no real second opinion.

Stdlib-only Python, one file, MIT. Works with local CLIs (`codex`, `grok`, `gemini`, `claude`), any OpenAI-compatible HTTP endpoint (OpenRouter, vendor APIs, your own gateway), or a mix.

Built and used daily at [Palo Alto AI Research Lab](https://github.com/tonydzi/tonydzi) — it is the gate our agents must pass before they are allowed to say "done".

---

## The one thing to take away: send CONTENTS, not paths

If you hand a panel a list of **file paths**, the models that cannot read your disk will not tell you. They will invent.

We measured it on this very repository, 2026-08-10, four models from four different families, same code, same reviewer role — only the material changed:

| what the panel was given | rails that answered | findings | findings anchored on something that actually exists | models that said "I cannot see the code" |
|---|---|---|---|---|
| **paths only**, framed the way an integrator naturally writes it | 4 / 4 | 20 | **0** | **0 / 4** |
| **paths only**, but the prompt says contents are missing and honesty is allowed | 2 / 4 | 0 | — | **2 / 2** |
| **full file contents** | 2 / 4 | 10 | **10** | — |

The paths-only run was not "weaker". It was *confidently wrong*: findings about a `families_needed` counter, a `--model-config` CLI flag, per-request subprocess spawning and unlocked concurrent log writes. None of those exist here — the file has a two-level lock and no such flag. All four models produced a clean, numbered, professional-looking review of a program they had never seen.

The contents run named real functions — `is_finding`, `families_answered`, `_run_cmd_rail`, `strip_prefixes` — and **four of its findings were real defects, fixed in this repo before publishing** (see [GOTCHAS](docs/GOTCHAS.md#found-by-the-panel-on-its-own-code)).

So two rules are wired into the tool, not left to your discipline:

1. `pack_files()` sends **line-numbered file contents**; missing and truncated files are named explicitly, because a silent absence invites invention while a named absence does not.
2. `--paths-only` exists so you can reproduce the failure yourself — and a run in that mode **can never exit 0**.

And a third rule for choosing models: **an honest "I don't have the data" beats a confident guess.** That is a selection criterion, not a nicety — a model that will not say "I can't see it" is a model that will fabricate under pressure. Test yours: `python secondop_panel.py t3 --paths-only --files anything.py`.

---

## Three touchpoints, not "review at the end"

| point | when | question | role |
|---|---|---|---|
| `t1` | before you write code | "is this plan sound?" | `verify` |
| `t2` | at a fork | "which of these two designs?" | `counter` |
| `t3` | after the build | "try to **break** what I just made" | `break` |

A panel called only at `t3` finds bugs. A panel called at `t1` prevents the build.

```bash
python secondop_panel.py t1 --task new-cache --context "the plan, in full"
python secondop_panel.py t2 --task new-cache --context "option A ... option B ... I lean A because ..."
python secondop_panel.py t3 --task new-cache --files src/cache.py tests/test_cache.py \
       --context "what I changed and why" --diff HEAD~1
```

---

## Quickstart

```bash
git clone https://github.com/tonydzi/secondop-panel.git && cd secondop-panel
cp panel.example.json panel.json         # edit: keep the rails you actually have
export OPENROUTER_API_KEY=...            # or point the rails at your own endpoints
python secondop_panel.py selftest        # offline: 33 checks, no network, no keys
python secondop_panel.py doctor          # which rails are alive on THIS machine
python secondop_panel.py t3 --task my-fix --files src/a.py --context "what I did"
```

Exit codes are the gate, not decoration:

| code | meaning | what your ritual should do |
|---|---|---|
| `0` | quorum met — N distinct **families** answered | a pass is allowed |
| `3` | no independent second opinion (rails dead, skipped, all one family, or a degraded paths-only run) | report at most a **warning**, never a pass |
| `2` | bad config / nothing to review | fix and re-run |

---

## What makes it a panel and not a lucky loop

**Quorum counts FAMILIES.** `google/gemini-*` through a gateway and the local `gemini` CLI are two *doors to one lab*, not two opinions. Counting heads instead of families is how a tool reports "four reviewers agreed" after asking the same lab four times. The threshold never learns vendor names — add or remove rails freely, the rule does not change.

**No silent vendor substitution.** An unknown rail name is a **skip**, never a redirect into whichever rail happens to work. A verdict from vendor A printed under the name of vendor C makes the independence fake and your gate green on one opinion. Duplicates (`--rails codex,codex`) are dropped before the run for the same reason.

**A skip is visible and it costs you the pass.** Rails that were asked and did not answer are printed with the reason, and the run cannot return 0 unless enough distinct families spoke. "Two rails" while one is alive is a lie your CI will believe.

**A closed door is not a dead vendor.** `doctor` separates `ABSENT` (this machine never had it) from `DEGRADED` (installed and refusing) — different diseases, different cures. A vendor is only dead when *every* door is closed; the browser is usually still open.

**One rail may never take the panel down.** A vendor that crashes is a missing opinion, not the loss of everyone else's.

---

## Configuration

`panel.json` — rails are just data (see [`panel.example.json`](panel.example.json)):

```json
{ "quorum": 2, "timeout_s": 180,
  "rails": [
    {"name":"gemini","family":"google","kind":"http",
     "api":"https://openrouter.ai/api/v1/chat/completions",
     "key_env":"OPENROUTER_API_KEY","model":"google/gemini-3.1-pro-preview","effort":"medium"},
    {"name":"grok","family":"x-ai","kind":"cmd","unset_env":["XAI_API_KEY"],
     "cmd":["grok","--prompt-file","{prompt_file}","--tools","","--no-plan"]}
  ] }
```

**Tier is not a budget knob.** The `*-flash` / `*-lite` tier spends its token budget on reasoning and hands back an empty answer, so the rail drops out and your quorum quietly shrinks to whoever finished — we chased that three times before naming it ([gotcha 20](docs/GOTCHAS.md)). Smartest model each family sells, `effort` **medium** (not `high` — `high` is what truncated them). And if you already pay a flat subscription for a family, run it as a `cmd` rail and drop its gateway twin ([gotcha 21](docs/GOTCHAS.md)).

`{prompt_file}` is replaced with a temp file holding the prompt; rails without it get the prompt on stdin. **Never pass a multi-line prompt as an argv string** — shell/CRT quoting mangles it and the vendor silently sees only the first line.

Keys come from the environment only. Nothing here stores a secret; see [`docs/SECURITY.md`](docs/SECURITY.md) — you are shipping your source code to third parties, and that deserves one page of thought.

Picking the 3–4 families: [`docs/MODEL-FAMILIES.md`](docs/MODEL-FAMILIES.md).

---

## Wiring it into your own agent

[`PROMPT.md`](PROMPT.md) is a copy-paste prompt for Claude Code / Codex / Cursor: *"install a panel of breakers on my pipeline"*, ~15 minutes, including where to put the three calls and how to make a failed quorum downgrade your verdict instead of being ignored.

---

## Every trap we paid for

[`docs/GOTCHAS.md`](docs/GOTCHAS.md) — 19 of them, each one a bug a live panel found in this code: markdown-bolded verdict tags, `VERIFYING` scored as a verdict, `ACCEPT` on line one with `COUNTER` in the body, empty strings counted as opinions, `O_APPEND` not being atomic on Windows, and the reasoning-model trap where a tight token budget returns empty `content` with `finish_reason: stop` so your client invents a silence that never happened.

## License

MIT.

---

Part of the reliability series by Palo Alto AI Research Lab. Closest neighbour: [`verdict-contract`](https://github.com/tonydzi/verdict-contract) — the structured verdict a reviewer must answer in, and the parser that refuses to guess (this kit ships the same discipline for a whole panel). See also [`verified-ops-starter`](https://github.com/tonydzi/verified-ops-starter) (your job says exit 0 — prove it did the work), [`agent-approval-gate`](https://github.com/tonydzi/agent-approval-gate) (when the panel says BLOCK and a human has to decide) and [`telegram-mcp-kit`](https://github.com/tonydzi/telegram-mcp-kit). Questions / broken step? Open an issue — we answer within 24h.

---

> **Publishing your own internals?** This repo was sanitized for release with
> [`oss-publish`](https://github.com/tonydzi/oss-publish) — personal data replaced by plausible
> fakes of the same shape (never `<REDACTED>`), and a fail-closed gate re-scans the whole tree
> before the push. Free, MIT.

<!--kits-series:start-->

## 🧰 Connector & Ops Kits

Eight kits, all published 2026-08-10, each lifted out of the same live fleet after it
survived production rather than written as a demo. They are independent: take one, ignore
the rest. All stdlib-only Python, all free.

| kit | what it solves |
|---|---|
| [`telegram-mcp-kit`](https://github.com/tonydzi/telegram-mcp-kit) | Connect your agent to your own Telegram account in ~15 minutes, with the production patches and every gotcha |
| [`whatsapp-mcp-kit`](https://github.com/tonydzi/whatsapp-mcp-kit) | Link WhatsApp, using a live self-refreshing QR page that makes pairing actually work |
| [`mcp-daemon-diet`](https://github.com/tonydzi/mcp-daemon-diet) | One shared MCP daemon per machine instead of a stdio copy in every session, with a watchdog that will not blind your live sessions |
| [`agent-approval-gate`](https://github.com/tonydzi/agent-approval-gate) | Your agent needs a human's OK and nobody is at the terminal: the ask goes to a messenger, the answer comes back into the run |
| [`fleet-deploy`](https://github.com/tonydzi/fleet-deploy) | Roll a fix to N machines and prove it landed on each one: canary waves and a verify that must read a fact back |
| [`secondop-panel`](https://github.com/tonydzi/secondop-panel) | Nobody reviews themselves, and one reviewer model is one blind spot: fan a change out to several model families with quorum and honest skips |
| [`oss-publish`](https://github.com/tonydzi/oss-publish) | Open up internal work without leaking it: plausible substitutions of the same shape, then a fail-closed gate over the whole tree |
| [`llm-spend-audit`](https://github.com/tonydzi/llm-spend-audit) | What your own wiring charges on every session, and which paid subscriptions are going undrawn |

<!--kits-series:end-->

<!--ecosystem-map:start-->

## 🧩 One piece of a working system

This repository is one piece lifted out of a live operation: one engineer running a fleet of
machines, built with Claude as implementation collaborator; the machines reach consensus with
each other and wake the human only for money or the irreversible. It was extracted after it
survived production, not written as a demo — and it runs on its own: nothing here phones home
to the rest.

**See how the whole thing fits together → [SYSTEM.md](https://github.com/tonydzi/tonydzi/blob/main/SYSTEM.md)**

<!--ecosystem-map:end-->

## AI contributors

This project is built by a human + AI team, and the git log says so: Claude writes most of
the code, Codex and Grok review it, Gemini feeds the research. Each is credited on a commit
**only if its output changed that commit's content** — no decorative credits. Lab-wide
policy, one source for every repo: [AI-CONTRIBUTORS.md](https://github.com/tonydzi/.github/blob/main/AI-CONTRIBUTORS.md).

<!-- READ-WITH-AI:START (generated by read_with_ai.py - do not hand-edit) -->

### READ THIS WITH AI

One click and an agent reads the repo, pulls out the patterns and helps you apply them to your own work.

<a href="https://chatgpt.com/codex?prompt=Read%20this%20repo%3A%20https%3A%2F%2Fgithub.com%2Ftonydzi%2Fsecondop-panel%20%28%E2%80%9Csecondop-panel%E2%80%9D%20-%20Nobody%20reviews%20themselves%20-%20and%20one%20reviewer%20model%20is%20one%20blind%20spot.%20Fan%20every%20change%20out%20to%20several%20model%20FAMILIES%20at%20once%3A%20verdict%20contract%2C%20quorum%20by%20family%2C%20honest%20skips%2C%20and%20an%20exit%20code%20that...%29.%20Work%20out%20what%20problem%20it%20actually%20solves%2C%20pull%20out%20the%20reusable%20patterns%20and%20help%20me%20apply%20them%20to%20my%20own%20setup.%20Start%20by%20asking%20what%20I%20am%20working%20on."><img alt="Codex - open" src="https://img.shields.io/badge/Codex-open-000000?style=for-the-badge&logo=openai&logoColor=white"></a> <a href="https://chatgpt.com/?q=Read%20this%20repo%3A%20https%3A%2F%2Fgithub.com%2Ftonydzi%2Fsecondop-panel%20%28%E2%80%9Csecondop-panel%E2%80%9D%20-%20Nobody%20reviews%20themselves%20-%20and%20one%20reviewer%20model%20is%20one%20blind%20spot.%20Fan%20every%20change%20out%20to%20several%20model%20FAMILIES%20at%20once%3A%20verdict%20contract%2C%20quorum%20by%20family%2C%20honest%20skips%2C%20and%20an%20exit%20code%20that...%29.%20Work%20out%20what%20problem%20it%20actually%20solves%2C%20pull%20out%20the%20reusable%20patterns%20and%20help%20me%20apply%20them%20to%20my%20own%20setup.%20Start%20by%20asking%20what%20I%20am%20working%20on."><img alt="ChatGPT - open" src="https://img.shields.io/badge/ChatGPT-open-10a37f?style=for-the-badge&logo=openai&logoColor=white"></a> <a href="https://claude.ai/new?q=Read%20this%20repo%3A%20https%3A%2F%2Fgithub.com%2Ftonydzi%2Fsecondop-panel%20%28%E2%80%9Csecondop-panel%E2%80%9D%20-%20Nobody%20reviews%20themselves%20-%20and%20one%20reviewer%20model%20is%20one%20blind%20spot.%20Fan%20every%20change%20out%20to%20several%20model%20FAMILIES%20at%20once%3A%20verdict%20contract%2C%20quorum%20by%20family%2C%20honest%20skips%2C%20and%20an%20exit%20code%20that...%29.%20Work%20out%20what%20problem%20it%20actually%20solves%2C%20pull%20out%20the%20reusable%20patterns%20and%20help%20me%20apply%20them%20to%20my%20own%20setup.%20Start%20by%20asking%20what%20I%20am%20working%20on."><img alt="Claude - open" src="https://img.shields.io/badge/Claude-open-d97757?style=for-the-badge&logo=anthropic&logoColor=white"></a>

<details>
<summary>Copy the prompt (works in any agent: Gemini, Grok, a local model, your own CLI)</summary>

```text
Read this repo: https://github.com/tonydzi/secondop-panel (“secondop-panel” - Nobody reviews themselves - and one reviewer model is one blind spot. Fan every change out to several model FAMILIES at once: verdict contract, quorum by family, honest skips, and an exit code that...). Work out what problem it actually solves, pull out the reusable patterns and help me apply them to my own setup. Start by asking what I am working on.
```

</details>

<sub>— TonyDzi, Palo Alto AI Research Lab · second brain, agent coordination, persistent memory: github.com/tonydzi</sub>

<!-- READ-WITH-AI:END -->
