Files
ai-agent/backend/test_pi_compaction.py
gabrielvidalandClaude Opus 5.5 c3945fe965 refactor: retire core runner/ — pi's runner lives in the harness-pi plugin
runner/ (cli.mjs, extensions/folder-permissions.ts, test, README) was a
byte-for-byte duplicate of the harness-pi plugin's runner/, kept only as the
driver's fallback through the sidecar's config.RUNNER_BIN.

- delete runner/ and sidecar config.RUNNER_BIN
- scripts/test.py: drop the `runner` suite (it runs in ai-agent-plugins now)
- scripts/ab: the pi mirror replay uses a tree's runner/ when it has one
  (refs before this), else the plugin's (AB_PI_RUNNER)
- CLAUDE.md / docs / comments point at harness-pi's runner
- sidecar/local-model.md stays (harness-opencode's LOCAL_MODEL_GUIDE)

Merge only after harness-pi 1.1.0 is installed on the lab: harness-pi 1.0.x
reads config.RUNNER_BIN and would fail every pi run on this core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:44:54 +01:00

71 lines
2.9 KiB
Python

"""A pi run's compaction reads as the viewer's divider, and the runner's
auto-continue prompt stays out of the thread.
harness-pi's runner/cli.mjs mirrors pi's ``compaction_end`` as Claude Code's
``compact_boundary`` + ``isCompactSummary`` records, and when a reply a full
context cut off is continued, writes the continue prompt as an injected
``<pi-runner-auto-continue>`` text — the divider above already says it."""
import json
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
import conversations as c
SID = "01a2ffff-0000-7000-8000-00000000c0de"
MODEL = "inkling-2-mini"
def _rec(ts, **r):
return {"sessionId": SID, "timestamp": ts, **r}
def _assistant(ts, stop, text, inp, out):
return _rec(ts, type="assistant", costUSD=0, message={
"role": "assistant", "model": MODEL, "stop_reason": stop,
"usage": {"input_tokens": inp, "output_tokens": out,
"cache_read_input_tokens": 0, "cache_creation_input_tokens": 0},
"content": [{"type": "text", "text": text}] if text else []})
RECORDS = [
_rec("2026-11-24T10:00:00Z", type="user", message={"role": "user", "content": "do the task"}),
_assistant("2026-11-24T10:25:32Z", "length", "", 127134, 1),
_rec("2026-11-24T10:30:14Z", type="system", subtype="compact_boundary",
content="Conversation compacted",
compactMetadata={"trigger": "auto", "preTokens": 127135, "postTokens": 24000,
"durationMs": 282000}),
_rec("2026-11-24T10:30:14Z", type="user", isCompactSummary=True,
message={"role": "user", "content": "## Goal\nthe corner badge"}),
_rec("2026-11-24T10:30:15Z", type="user", isMeta=True, message={
"role": "user",
"content": "<pi-runner-auto-continue>\nYour last reply was cut off\n</pi-runner-auto-continue>"}),
_assistant("2026-11-24T10:31:00Z", "stop", "Picked it up ✅", 25000, 40),
_rec("2026-11-24T10:31:01Z", type="system", subtype="turn_end", entrypoint="pi"),
]
class PiCompactionTest(unittest.TestCase):
def test_divider_summary_and_hidden_continue(self):
with TemporaryDirectory() as d:
p = Path(d) / f"{SID}.jsonl"
p.write_text("".join(json.dumps(r) + "\n" for r in RECORDS))
st = c.ParserState(p, full=True)
for r in RECORDS:
st.feed(r)
dividers = [it for it in st.thread if it.get("kind") == "compact"]
self.assertEqual(len(dividers), 1)
d = dividers[0]
self.assertEqual(d["compact"]["trigger"], "auto")
self.assertEqual(d["compact"]["preTokens"], 127135)
self.assertEqual(d["compact"]["postTokens"], 24000)
self.assertEqual(d["text"], "## Goal\nthe corner badge")
prompts = [it.get("text") for it in st.thread
if it.get("role") == "user" and it.get("kind") == "text"]
self.assertEqual(prompts, ["do the task"])
if __name__ == "__main__":
unittest.main()