Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ uninstalling, using Copilot with your own model key, and troubleshooting.
| Codex | 0.153.1 to 0.171.0 | not supported |
| Copilot CLI | 1.0.83 to 1.0.114 | not supported |
| Pi | 1.2.0 to 1.5.2 | 0.99.x: load the extension by path (below) |
| oh-my-pi (`omp`, experimental) | 19.1.1 | not tested |
| Cursor Agent (experimental) | 3.24.9 and cursor-agent 2026.11.05, macOS and Linux (below) | not tested |
| Grok Build (experimental) | 1.0.70 | not tested |
| opencode (experimental) | 1.19.5 and 2.2.0 | not tested |
Expand Down
6 changes: 4 additions & 2 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ after the loop guard's redirect gets a notice: press **Esc** to abort it, or Ctr
on your default model (`paid_model` names another). If that model's provider comes from an
extension (a company gateway, a package's provider), list the extension's file in
`pi_extensions` so the calls can reach it; it loads with no tools. If the first `pi` on your PATH
is a wrapper the calls should not run, set `pi_cli` to the real one.
is a wrapper the calls should not run, set `pi_cli` to the real one. oh-my-pi (`omp`) works too:
with no `pi` on PATH, `pi_cli` falls back to `omp` (or `OMPCODE=1` names it), and a side call
leaves out the flags that CLI reports unknown (`--no-prompt-templates`, `--no-mcp`).

**Update.** `pi update --extensions` (plain `pi update` does not update extensions).

Expand Down Expand Up @@ -935,7 +937,7 @@ first session there ends.
| `local_roles` | `judge` | which side calls `local_model` takes: `judge`, `nudge` (the redirect writer), `proposer`, separated by commas |
| `local_judge_confidence` | `0.9` | how sure a stuck verdict from the on-device judge must be to count; below it the turn is spared |
| `pi_extensions` | `""` | Pi only: extension files (comma-separated paths) the plugin's own calls load, for a model whose provider an extension registers |
| `pi_cli` | `""` | Pi only: the `pi` the plugin's own calls run; empty: the first on PATH |
| `pi_cli` | `""` | Pi only: the `pi` the plugin's own calls run; empty: the first `pi` on PATH, else oh-my-pi's `omp` |
| `tool_roles` | none | tools the mechanisms do not know by name, each given the role of a built-in one: `tool=role` entries separated by commas, a tool by name or pattern, a role `shell`, `edit` or `read` (`mcp__serena__replace_content=edit,mcp__serena__execute_shell_command=shell`). Micro-skills read a shell tool's commands, and an edit tool's file counts as edited; tool pruning still knows each tool by its own name |
| `shadow` | `false` | decide and log everything, act on nothing |
| `mode` | `auto` | `interactive` or `headless` to override what the plugin detects |
Expand Down
42 changes: 42 additions & 0 deletions tests/test_live_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,47 @@ def fake_run(cmd, **kw):
assert calls[-1][0][-4:-2] == ["--model", "openrouter/anthropic/claude-haiku-4.5"]


@pytest.mark.real_sidecalls
def test_a_pi_side_call_drops_every_flag_the_cli_reports_unknown(monkeypatch):
"""oh-my-pi (`omp`) rejects two of Pi's flags in one error line; both are left out and the
call retried, rather than failing the side call."""
import subprocess
from tokeneconomizer.plugin import sidecall
monkeypatch.setattr(sidecall, "program", lambda cli: [cli])
calls = []

def fake_run(cmd, **kw):
calls.append(cmd)
if "--no-prompt-templates" in cmd or "--no-mcp" in cmd:
return subprocess.CompletedProcess(
cmd, 1, stdout="",
stderr="Error: unknown flags: --no-prompt-templates, --no-mcp\n")
return subprocess.CompletedProcess(
cmd, 0, stdout="\n".join(json.dumps(e) for e in PI_JSON_RUN), stderr="")

monkeypatch.setattr(sidecall.subprocess, "run", fake_run)
text, eff = sidecall.pi_call("propose facts", cli="omp")
assert text == "- use python -m pytest" and eff and eff > 0
assert "--no-prompt-templates" not in calls[-1] and "--no-mcp" not in calls[-1]
assert "--offline" in calls[-1] and calls[-1][-2:] == ["--", "propose facts"]


def test_a_pi_side_call_prefers_pi_and_falls_back_to_oh_my_pi_s_omp(monkeypatch):
from tokeneconomizer.plugin import sidecall
monkeypatch.delenv("OMPCODE", raising=False)
monkeypatch.setattr(sidecall.shutil, "which",
lambda name: {"pi": "/usr/local/bin/pi"}.get(name))
assert sidecall.pi_cli() == "/usr/local/bin/pi"
monkeypatch.setattr(sidecall.shutil, "which",
lambda name: {"omp": "/usr/local/bin/omp"}.get(name))
assert sidecall.pi_cli() == "/usr/local/bin/omp"
monkeypatch.setattr(sidecall.shutil, "which", lambda name: None)
monkeypatch.setenv("OMPCODE", "1")
assert sidecall.pi_cli() == "omp"
monkeypatch.delenv("OMPCODE")
assert sidecall.pi_cli() == "pi"


@pytest.mark.real_sidecalls
def test_a_pi_side_call_loads_the_provider_extensions_and_the_pi_the_person_names(
monkeypatch, tmp_path):
Expand All @@ -1438,6 +1479,7 @@ def test_a_pi_side_call_loads_the_provider_extensions_and_the_pi_the_person_name
import subprocess
from tokeneconomizer.plugin import sidecall
monkeypatch.setattr(sidecall, "program", lambda cli: [cli])
monkeypatch.setattr(sidecall, "pi_cli", lambda: "pi")
calls = []

def fake_run(cmd, **kw):
Expand Down
36 changes: 32 additions & 4 deletions tokeneconomizer/plugin/sidecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ def resume(host, root=None):
return False


def pi_cli():
"""The Pi executable side calls run: `pi` on PATH, else oh-my-pi's `omp`, the fork this
plugin also serves. A session inside oh-my-pi carries `OMPCODE=1`, so the bare `omp` is used
even where PATH lookup cannot find it. Falls back to `pi`, so the error stays the
CLI-not-found one."""
found = shutil.which("pi")
if found:
return found
# oh-my-pi's binary is `omp`, not `pi`; a session inside it carries OMPCODE=1.
return shutil.which("omp") or ("omp" if os.environ.get("OMPCODE") else "pi")


def claude_cli():
"""The Claude Code executable to start: `claude` on PATH (with PATHEXT on Windows, so a
`claude.cmd` shim too), else the native installer's `~/.local/bin/claude` -- which is often
Expand Down Expand Up @@ -367,6 +379,18 @@ def codex_call(prompt, model="", cli="codex", timeout=TIMEOUT_S, effort=""):
PI_FLAGS = ("--print", "--mode", "json", "--no-session", "--no-tools", "--no-extensions",
"--no-skills", "--no-prompt-templates", "--no-context-files", "--offline")

# A flag this CLI does not have: Pi says `Unknown option: --no-mcp`; oh-my-pi says
# `unknown flags: --no-prompt-templates, --no-mcp` (one line, any number of names).
_UNKNOWN_FLAG_RE = re.compile(r"unknown (?:option|flag)s?:?\s*(.*)", re.IGNORECASE)


def _unknown_flags(stderr):
"""The `--flags` a CLI's error names as unknown, which a side call leaves out and retries:
the two Pi implementations do not have the same set (oh-my-pi drops `--no-prompt-templates`
and `--no-mcp`), and probing `--help` would cost a second start."""
m = _UNKNOWN_FLAG_RE.search(stderr or "")
return set(re.findall(r"--[\w-]+", m.group(1))) if m else set()


def pi_extension_args(extensions):
"""`--extension <path>` for each extension a side call loads despite `--no-extensions` (Pi
Expand All @@ -383,14 +407,18 @@ def pi_call(prompt, model="", cli="pi", timeout=TIMEOUT_S, extensions=()):
model_args = ["--model", model] if model else []
ext_args = pi_extension_args(extensions)
exe = program(cli)
flags = [*PI_FLAGS, "--no-mcp"] # Pi before 1.0 and oh-my-pi reject the last one
with tempfile.TemporaryDirectory(prefix="te-side-", ignore_cleanup_errors=True) as cwd:
for extra in (["--no-mcp"], []):
cmd = [*exe, *PI_FLAGS, *extra, *ext_args, *model_args, "--", prompt]
for _ in range(len(flags) + 1):
cmd = [*exe, *flags, *ext_args, *model_args, "--", prompt]
out = subprocess.run(cmd, capture_output=True, encoding="utf-8", errors="replace",
timeout=timeout, env=_env(), cwd=cwd,
stdin=subprocess.DEVNULL)
if "Unknown option: --no-mcp" not in (out.stderr or ""):
unknown = _unknown_flags(out.stderr)
kept = [f for f in flags if f not in unknown]
if not unknown or kept == flags:
break
flags = kept
text, usage = trace.pi_json_reply(out.stdout)
if not text:
_no_reply("pi", out)
Expand Down Expand Up @@ -1022,7 +1050,7 @@ def _host_call(host_name, config):
effort = getattr(config, f"{host_name}_paid_effort", "")
kw = {"effort": effort} if effort else {}
if host_name == "pi":
cli = os.path.expanduser(config.pi_cli) if config.pi_cli else "pi"
cli = os.path.expanduser(config.pi_cli) if config.pi_cli else pi_cli()
extensions = list(config.pi_extensions)
return lambda prompt, _m="agent": pi_call(prompt, model=model, cli=cli,
extensions=extensions)
Expand Down