From dd7b28867fcaca3ac971d1cd338c76317de54d12 Mon Sep 17 00:00:00 2001 From: HarryHe <2496583567@qq.com> Date: Wed, 25 Nov 2026 01:26:43 +0800 Subject: [PATCH] docs: add canonical verification truth and causal fixtures --- CHANGELOG.md | 2 + README.md | 1 + docs/INDEX.md | 3 + docs/ROADMAP.md | 8 +- docs/causal-continuity-benchmark.md | 44 ++++++++ docs/native-resume-manual-verification.md | 43 +++++++ docs/verification-matrix.md | 46 ++++++++ scripts/r17_causal_fixture.py | 130 ++++++++++++++++++++++ 8 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 docs/causal-continuity-benchmark.md create mode 100644 docs/native-resume-manual-verification.md create mode 100644 docs/verification-matrix.md create mode 100644 scripts/r17_causal_fixture.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 63c0d3c..8e88cda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ All notable changes to Voyager are documented here. Format loosely follows - Contract tests now pin ambiguous WorkThread previews to expose `thread_ambiguous`, every candidate and an explicit default reason while carrying neither `selected_thread` nor `thread`; an explicit `--thread` still returns `selected_thread` and `thread_requested`. This documents the existing JSON contract only: no field, Bridge op or schema version changed, and no new user capability was added. +- Added a canonical verification matrix, a safe manual Native Resume procedure and a privacy-safe causal continuity fixture/verifier. The matrix separates historical live, R16-only, BLOCKED and NOT VERIFIED claims; no production behaviour, schema, Bridge op or release state changed. + ## [1.6.0] — 2026-11-22 ### Added diff --git a/README.md b/README.md index e07e1f3..6d2a968 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ is one client of it, and the core is a general-purpose local tool.) | **Current release** | [v1.6.0](https://github.com/HarryHeYu/sessionFlow/releases/tag/v1.6.0) · Python ≥ 3.10 · Windows / macOS / Linux | | **Community** | Listed in the third-party [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin/blob/main/data/plugins/HarryHeYu__dsh-sessionflow.yml) directory — a listing, not a certification | | **Known limitation** | Native resume is **not verified** end to end — see [supported platforms](#supported-platforms) | +| **Verification truth** | [Canonical verification matrix](docs/verification-matrix.md) separates UNIT, INTEGRATION, historical live, R16-only, BLOCKED and NOT VERIFIED claims. | | **Maintaining it** | [Known issues, compatibility matrix, release checklist](docs/MAINTENANCE.md) | > **Current release:** Core 1.6.0 is published as tag `v1.6.0` with wheel and sdist assets. The pins above install that immutable tag. Work still in development lives on `main` or a candidate branch and is never represented here as the published release. diff --git a/docs/INDEX.md b/docs/INDEX.md index e453b5e..95fa999 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -24,6 +24,7 @@ wrong; it is history, and it should not be quoted as current state. | Document | Kind | Audience | Status | |---|---|---|---| | [FAQ.md](FAQ.md) | USER_GUIDE | user | maintained | +| [native-resume-manual-verification.md](native-resume-manual-verification.md) | DEVELOPER_GUIDE | user | maintained — safe manual procedure; status remains NOT VERIFIED | | [WORKFLOWS.md](WORKFLOWS.md) | USER_GUIDE | user | maintained — pinned by `tests/test_workflows.py` | | [use-cases.md](use-cases.md) | USER_GUIDE | prospective user | maintained | | [demos/demo1-search.md](demos/demo1-search.md) | GENERATED_ARTIFACT | user | regenerated by `scripts/make_demos.py` | @@ -38,6 +39,7 @@ one is a compatibility decision, not an edit. | Document | Kind | Audience | Status | |---|---|---|---| | [API.md](API.md) | API_CONTRACT | integrator | maintained | +| [verification-matrix.md](verification-matrix.md) | REFERENCE | everyone | maintained — canonical boundary between claim classes and dated evidence | | [SCAN_CONSISTENCY.md](SCAN_CONSISTENCY.md) | ARCHITECTURE | maintainer | maintained — the crash-consistency contract; pinned by `tests/test_scan_consistency.py` | | [GLOSSARY.md](GLOSSARY.md) | REFERENCE | everyone | maintained — canonical names for the domain vocabulary | | [CONCEPT_MODEL.md](CONCEPT_MODEL.md) | ARCHITECTURE | maintainer | maintained — the classifications, the relationships and the invariants, each mapped to the code that owns it | @@ -92,6 +94,7 @@ true on a date; it is not a description of the product and is not updated. | Document | Kind | Audience | Status | |---|---|---|---| | [PERF_O1.md](PERF_O1.md) | EXPERIMENT_REPORT | maintainer | maintained — still the reference for the 1M-event limit | +| [causal-continuity-benchmark.md](causal-continuity-benchmark.md) | EXPERIMENT_PROTOCOL | maintainer | maintained — R17 CONTROL/SESSIONFLOW protocol and oracle | | [RECON.md](RECON.md) | EXPERIMENT_REPORT (中文) | maintainer | frozen — 2026-09-13 platform recon; cited by README, FAQ, POST-1.0 | ## Planning diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index bccc126..0a42621 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -34,10 +34,10 @@ **Status:** Phase 1 shipped (`voyager merge`, commit `ff13096`). **Phase 1b shipped (`5e8271c`); Phase 2 COMPLETE — 2a WorkThread (`b580001`/`934dfd5`), 2b lease (`c41f99b`), 2c deferred items closed (MCP voyager_thread + deterministic --repo thread resolution; multi-signal auto-clustering re-scoped as a later enhancement under #3).** **Phase 3 shipped (`d931b02`); Phase 4 shipped (`96fc752`); Phase 5 shipped (`2f01a7f`); ** -**Phase 6 `voyager switch` shipped; Phase 7 partially shipped — core API + stdio bridge + VS Code extension scaffold + Context Composer webview + timeline view + one-click switch (VSIX packaging still pending; see CHANGELOG).** +**Phase 6 `voyager switch` shipped; Phase 7 partially shipped — core API + stdio bridge + VS Code extension scaffold + Context Composer webview + timeline view + one-click switch implemented. VSIX package/install was VERIFIED in R16; full GUI activation and one-click-switch E2E remain NOT VERIFIED. See [verification-matrix.md](verification-matrix.md).** **Continuity Engine 主线到此完整:`index → WorkThread → goal rank → budget → skill → lease → switch → API/UI client`。** -Phase 7 is partially shipped (API/bridge/scaffold + Context Composer webview + timeline view + one-click switch done; VSIX packaging pending). +Phase 7 is partially shipped (API/bridge/scaffold + Context Composer webview + timeline view + one-click switch implemented; VSIX package/install VERIFIED in R16; GUI activation and one-click-switch E2E NOT VERIFIED). **Final assessment (2026-09-20; classification corrected 2026-09-23)**: All roadmap phases complete. Zero-Touch Startup Continuity core implementation verified via pytest (`374 collected → 372 passed, 2 skipped` with the full dev extras; `356 passed, 18 skipped` simulated core-only). @@ -886,7 +886,7 @@ voyager switch codex User-visible: one command. Internally: scan → select → compile → launch. -### Phase 7 — VS Code sidebar / Context Composer *(partially shipped: API + bridge + extension scaffold + Context Composer webview + timeline view + one-click switch; VSIX packaging pending — docs/POST-1.0.md)* +### Phase 7 — VS Code sidebar / Context Composer *(partially shipped: API + bridge + extension scaffold + Context Composer webview + timeline view + one-click switch; VSIX package/install verified, GUI E2E still NOT VERIFIED — docs/POST-1.0.md)* Only after Phases 1–4 exist, so the UI is a client of the compiler. @@ -916,7 +916,7 @@ Treat the checkboxes as the implementation contract. | [#6](https://github.com/HarryHeYu/sessionFlow/issues/6) | Voyager Skill + `voyager skill install` | 5 | #2 *(shipped `2f01a7f`)* | | [#7](https://github.com/HarryHeYu/sessionFlow/issues/7) | `voyager switch ` | 6 | #3, #4, #5, **#9**, **#11** *(shipped — see CHANGELOG)* | | [#10](https://github.com/HarryHeYu/sessionFlow/issues/10) | Optional transcript transplant (per-adapter writers) | later | #9, **#11** — **stays OPEN**: codex/grok writers shipped (opt-in, lease-gated); claude/dsh unsupported pending probe gates | -| [#8](https://github.com/HarryHeYu/sessionFlow/issues/8) | VS Code sidebar / Context Composer | 7 | #3, #4, #5 — **partially shipped** (API + bridge + extension scaffold + Context Composer webview + timeline view + one-click switch ✅; VSIX packaging pending) | +| [#8](https://github.com/HarryHeYu/sessionFlow/issues/8) | VS Code sidebar / Context Composer | 7 | #3, #4, #5 — **partially shipped** (API + bridge + extension scaffold + Context Composer webview + timeline view + one-click switch ✅; VSIX package/install VERIFIED; GUI E2E NOT VERIFIED) | #1 is the umbrella. Close it when #2–#7, #9 and #11 are done; #8 and #10 are post-moat (#10 is now Grok/Codex-shaped, still lease-gated). diff --git a/docs/causal-continuity-benchmark.md b/docs/causal-continuity-benchmark.md new file mode 100644 index 0000000..35971ee --- /dev/null +++ b/docs/causal-continuity-benchmark.md @@ -0,0 +1,44 @@ +# Causal continuity benchmark — R17 protocol + +This benchmark answers a narrow question: can a continuation bundle give an +incoming Agent information that is not available from the repository itself? +It is deliberately small and falsifiable; it is not a statistical completion +rate and it does not bind the protocol to a particular model vendor. + +## Three scenarios + +| Task | Hidden information in the prior session | Repo state | +|---|---|---| +| E1 hidden behavioral requirement | Collapse every whitespace run, including tabs, newlines and U+00A0, into one ASCII space | Visible tests green; no TODO or failing test | +| E2 hidden architectural constraint | Accept legacy numeric strings and `Decimal`; stdlib only; signature unchanged; existing output unchanged | Visible tests green; no TODO or failing test | +| E3 hidden rejected approach | `line.split('#', 1)` was tried and failed because it destroys `#` inside values; use a quote-aware parser | Visible tests green; failed attempt rolled back and not in the repo | + +## Protocol + +1. Run `python scripts/r17_causal_fixture.py --out ` to generate three + fixture repos, private hidden tests and a machine-readable oracle. +2. Verify deterministic setup: visible tests pass, hidden tests fail. +3. Agent A writes a prior session containing the hidden information without + modifying the repo. Ingest that transcript through the real Core CLI: + `scan`, `thread create --attach`, then `continue --bundle --no-launch`. +4. Run two independent Agent B conditions on identical repo copies: + - `CONTROL`: only the repo and a neutral continuation prompt; + - `SESSIONFLOW`: the same prompt plus the one continuation bundle. +5. Run `python scripts/r17_causal_fixture.py --out --action verify` to + apply the pre-written oracle. The verifier checks hidden tests and structural + constraints; it does not trust the Agent's self-report. + +## Interpretation + +- If CONTROL also solves the task, the scenario is SUPPORTIVE at best and must + not be used as causal evidence. +- If SESSIONFLOW recovers hidden facts and passes the oracle while CONTROL does + not, the scenario is CAUSAL-EVIDENCE for that fact. +- A scenario whose SESSIONFLOW run fails the oracle stays PARTIAL; do not relax + the oracle after seeing the output. + +## R17 result + +CONTROL 0/3 complete; SESSIONFLOW 2/3 complete. E1 and E2 are causal evidence; +E3 recovered the hidden failure history and avoided the rejected approach but +failed one hidden test, so its completion claim was not promoted. diff --git a/docs/native-resume-manual-verification.md b/docs/native-resume-manual-verification.md new file mode 100644 index 0000000..651587c --- /dev/null +++ b/docs/native-resume-manual-verification.md @@ -0,0 +1,43 @@ +# Native Resume — manual verification procedure + +Status: **NOT VERIFIED**. This document describes a safe procedure for a user +who chooses to verify Native Resume with their own provider account. It does +not grant permission to run authenticated provider sessions in CI or in an +automated sandbox, and it does not change the public status to VERIFIED. + +## Principle + +A provider CLI knowing a resume command is not evidence. Verification requires +a unique fact that exists only in the original session, a real resumed session +with a checkable identity, and a post-resume answer that recovers the fact. + +## Procedure + +1. Create a disposable project or use a throwaway branch. Do not use a private + repository containing secrets. +2. Start a new session with the chosen provider. Give it a unique marker, for + example `R17_NATIVE_RESUME_MARKER=`, and ask it to remember and + repeat the value later. Use your own account only if you explicitly choose + to do so. +3. Let the provider write its native session file. Capture the provider session + id or the conversation identity if the CLI exposes one. +4. Run `voyager scan --force` in the project, then locate the indexed session + with `voyager list` / `voyager recent`. +5. Run `voyager resume --print ` to inspect the exact native command. + Confirm that the adapter names the same provider session id from step 3. +6. Run the printed native resume command yourself. Do not paste credentials + into issue trackers, logs or test fixtures. +7. Ask the resumed session for the unique marker. Record whether it answers + with the exact value. +8. Compare session identity: the resumed CLI session should be the same native + session, not merely a new session with copied prose. +9. Record only redacted evidence: dates, provider, session id, command shape, + pass/fail and the marker equality result. Never commit credentials, tokens + or private conversation text. + +## Acceptance + +A provider may be claimed as `LIVE VERIFIED end to end` only after steps 1–8 +are observed by a human and the redacted record is attached to the relevant +issue or release audit. Until then the status remains `NOT VERIFIED`, regardless +of adapter source, CLI help output or startup-hook evidence. diff --git a/docs/verification-matrix.md b/docs/verification-matrix.md new file mode 100644 index 0000000..8829453 --- /dev/null +++ b/docs/verification-matrix.md @@ -0,0 +1,46 @@ +# Canonical verification matrix + +This page is the canonical source for verification claims in Core. Other +documents may describe a feature, but they must not silently upgrade a claim +beyond the boundary recorded here. A claim is always tied to its evidence date +and evidence class; "historical live verified" is not the same as "re-verified +in the current round", and "BLOCKED in one round" is not the same as "never +verified anywhere". + +## Evidence classes + +| Class | Meaning | +|---|---| +| `UNIT` | hermetic test; no real host behaviour | +| `INTEGRATION` | real components in a synthetic/isolated environment | +| `LIVE-HISTORICAL` | real host/model/session evidence from a dated past run | +| `LIVE-R16` | real process or real Agent evidence from the 2026-11-24 R16 round | +| `LIVE-R17` | real evidence from the 2026-11-25 R17 round | +| `INSTALL-ONLY` | install/discovery succeeded; launch, activation or model use did not | +| `BLOCKED` | environment, credential or user constraint stopped the experiment | +| `NOT VERIFIED` | no sufficient evidence; implementation existence does not promote it | + +## Capability matrix + +| Capability | Highest defensible claim | Evidence class | Boundary | +|---|---|---|---| +| Local multi-provider index and cross-agent timeline | LIVE VERIFIED (historical) | `LIVE-HISTORICAL` + `UNIT` | Historical live index evidence exists. R17 did not re-run a real user index. | +| WorkThread / merge / continue work continuity | LIVE-R16 VERIFIED | `INTEGRATION` + `LIVE-R16` | Real Core CLI and real WorkBuddy subagent A→B and A+B→C. Not cross-vendor native provider E2E. | +| Ambiguous WorkThread write safety | LIVE-R16 VERIFIED for Core CLI/API; DSH Agent path BLOCKED | `INTEGRATION` + `LIVE-R16` + `BLOCKED` | Ambiguous preview has `thread_ambiguous` and candidates, no `selected_thread`; ambiguous continue exits 2 with no side effects. | +| Claude Code / Grok / Codex startup hook zero-touch | LIVE VERIFIED (2026-09-24/25/28) | `LIVE-HISTORICAL` | Dated historical runs. The CLI static letter remains `H`; that is a state-expression design, not a refutation. | +| ZCode / Cursor / Kiro startup hook | UNIT VERIFIED; live provider firing NOT VERIFIED | `UNIT` | Handler driven with a real payload; no provider-fired run claimed. | +| Evidence Verify five-state API | VERIFIED (historical) | `INTEGRATION` + `LIVE-HISTORICAL` | `MATCH` is reference consistency, not claim truth. | +| Native Resume | NOT VERIFIED end to end | `NOT VERIFIED` + `BLOCKED` | Commands exist in adapters/help. R16 and R17 did not run authenticated sessions. See [native resume manual verification](native-resume-manual-verification.md). | +| VSIX package and isolated install | LIVE-R16 VERIFIED | `LIVE-R16` + `INSTALL-ONLY` | `@vscode/vsce` package and isolated `code --install-extension` succeeded. | +| Extension Host activation / selector | PARTIAL (R16), full E2E NOT VERIFIED | `PARTIAL` / `BLOCKED` | Real host observation reached the Voyager icon, WorkThreads tree and selector iframe; full case matrix and internal UI interaction were not completed. GUI was stopped at the user's request. | +| One-click switch | Implemented; real UI E2E NOT VERIFIED | `BLOCKED` | No real click and resulting thread ID were captured. | +| Reproducible continuity benchmarks | UNIT/INTEGRATION VERIFIED; live model completion NOT VERIFIED | `UNIT` + `INTEGRATION` | Harnesses are research tools. No live model completion rate is claimed. | +| Causal continuity with hidden information | LIVE-R17 VERIFIED for E1/E2; E3 partial | `LIVE-R17` | Three falsifiable tasks with CONTROL/SESSIONFLOW. CONTROL 0/3, sessionFlow 2/3 complete. See [causal continuity benchmark](causal-continuity-benchmark.md). | + +## Rules when editing other documents + +1. Keep historical dates when quoting historical live evidence. +2. Do not turn `BLOCKED THIS RUN` into global `NOT VERIFIED` when dated historical evidence exists. +3. Do not turn implementation existence or unit tests into `LIVE VERIFIED`. +4. Do not turn R16-only evidence into a current public claim without its `LIVE-R16` label. +5. When this matrix and a feature document disagree, update the feature document. diff --git a/scripts/r17_causal_fixture.py b/scripts/r17_causal_fixture.py new file mode 100644 index 0000000..f81d6b9 --- /dev/null +++ b/scripts/r17_causal_fixture.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Generate and verify the privacy-safe R17 causal continuity fixtures.""" +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path + +TASKS = ("e1_textutil", "e2_amount", "e3_config") + +FILES = { + "e1_textutil": { + "textutil.py": '''"""Small text helpers."""\n\n\ndef normalize(text: str) -> str:\n """Return text with leading and trailing ASCII spaces removed."""\n return text.strip(" ")\n''', + "tests/test_textutil.py": '''import unittest\n\nfrom textutil import normalize\n\n\nclass TestNormalize(unittest.TestCase):\n def test_leading_trailing_spaces(self):\n self.assertEqual(normalize(" Hi "), "Hi")\n\n def test_empty(self):\n self.assertEqual(normalize(" "), "")\n''', + }, + "e2_amount": { + "amount.py": '''"""Tiny amount formatter."""\n\n\ndef format_amount(value):\n """Format a numeric amount with two decimals."""\n return f"{value:.2f}"\n''', + "tests/test_amount.py": '''import unittest\n\nfrom amount import format_amount\n\n\nclass TestFormatAmount(unittest.TestCase):\n def test_float(self):\n self.assertEqual(format_amount(1.5), "1.50")\n\n def test_int(self):\n self.assertEqual(format_amount(2), "2.00")\n''', + }, + "e3_config": { + "config.py": '''"""Tiny configuration parser."""\n\n\ndef parse(text):\n """Parse simple key=value lines."""\n result = {}\n for line in text.splitlines():\n line = line.strip()\n if not line or line.startswith("#"):\n continue\n key, value = line.split("=", 1)\n result[key.strip()] = value.strip()\n return result\n''', + "tests/test_config.py": '''import unittest\n\nfrom config import parse\n\n\nclass TestParse(unittest.TestCase):\n def test_simple_pairs(self):\n self.assertEqual(parse("a=1\\nb=2"), {"a": "1", "b": "2"})\n\n def test_comment_line(self):\n self.assertEqual(parse("# comment\\na=1"), {"a": "1"})\n''', + }, +} + +HIDDEN = { + "e1_textutil": '''import unittest\n\nfrom textutil import normalize\n\n\nclass TestHidden(unittest.TestCase):\n def test_mixed_whitespace(self):\n self.assertEqual(normalize(" Hello\\t World\\n"), "Hello World")\n\n def test_nbsp(self):\n self.assertEqual(normalize("a\\u00a0\\u00a0b"), "a b")\n\n def test_existing(self):\n self.assertEqual(normalize(" Hi "), "Hi")\n''', + "e2_amount": '''import inspect\nimport unittest\nfrom decimal import Decimal\n\nfrom amount import format_amount\n\n\nclass TestHidden(unittest.TestCase):\n def test_string(self):\n self.assertEqual(format_amount(" 3.5 "), "3.50")\n\n def test_decimal(self):\n self.assertEqual(format_amount(Decimal("2.5")), "2.50")\n\n def test_signature(self):\n self.assertEqual(str(inspect.signature(format_amount)), "(value)")\n\n def test_existing(self):\n self.assertEqual(format_amount(1.5), "1.50")\n''', + "e3_config": '''import unittest\n\nfrom config import parse\n\n\nclass TestHidden(unittest.TestCase):\n def test_hash_in_value(self):\n self.assertEqual(parse("token=abc#def"), {"token": "abc#def"})\n\n def test_quoted_values(self):\n self.assertEqual(parse('name="a=b"\\nnote="x # y"'), {"name": "a=b", "note": "x # y"})\n\n def test_trailing_comment(self):\n self.assertEqual(parse("a=1 # trailing"), {"a": "1"})\n''', +} + + +def write_files(out: Path) -> None: + for task in TASKS: + root = out / "fixtures" / task + (root / "tests").mkdir(parents=True, exist_ok=True) + for rel, text in FILES[task].items(): + path = root / rel + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text, encoding="utf-8", newline="\n") + hidden_dir = out / "hidden-tests" / task + hidden_dir.mkdir(parents=True, exist_ok=True) + (hidden_dir / "test_hidden.py").write_text(HIDDEN[task], encoding="utf-8", newline="\n") + oracle = { + "schema": "r17-causal-oracle-v1", + "tasks": [ + {"id": "E1", "task": "e1_textutil", "critical_omission": "any required whitespace fact missing"}, + {"id": "E2", "task": "e2_amount", "critical_omission": "string/Decimal support, stdlib only or signature changed"}, + {"id": "E3", "task": "e3_config", "forbidden": "line.split('#', 1) style comment stripping"}, + ], + } + (out / "benchmark-oracles.json").write_text( + json.dumps(oracle, ensure_ascii=False, indent=2), encoding="utf-8", newline="\n") + + +def env_for(repo: Path) -> dict[str, str]: + env = dict(os.environ) + env["PYTHONDONTWRITEBYTECODE"] = "1" + env["PYTHONIOENCODING"] = "utf-8" + env["PYTHONPATH"] = str(repo) + return env + + +def preflight(out: Path, python: str) -> int: + bad = 0 + for task in TASKS: + repo = out / "fixtures" / task + hidden = out / "hidden-tests" / task + visible = subprocess.run( + [python, "-m", "unittest", "discover", "-s", "tests", "-v"], + cwd=str(repo), env=env_for(repo), capture_output=True, text=True, + encoding="utf-8", errors="replace", timeout=120, + ) + hidden_proc = subprocess.run( + [python, "-m", "unittest", "discover", "-s", str(hidden), "-v"], + cwd=str(repo), env=env_for(repo), capture_output=True, text=True, + encoding="utf-8", errors="replace", timeout=120, + ) + ok = visible.returncode == 0 and hidden_proc.returncode != 0 + print(f"{task}: visible_rc={visible.returncode} hidden_rc={hidden_proc.returncode} ok={ok}") + bad += 0 if ok else 1 + return 1 if bad else 0 + + +def verify(out: Path, python: str) -> int: + bad = 0 + found = 0 + for task in TASKS: + hidden = out / "hidden-tests" / task + for condition in ("control", "sessionflow"): + repo = out / "runs" / task / condition / "repo" + if not repo.exists(): + continue + found += 1 + proc = subprocess.run( + [python, "-m", "unittest", "discover", "-s", str(hidden), "-v"], + cwd=str(repo), env=env_for(repo), capture_output=True, text=True, + encoding="utf-8", errors="replace", timeout=120, + ) + print(f"{task}/{condition}: hidden_rc={proc.returncode}") + bad += 0 if proc.returncode == 0 else 1 + if not found: + print("no Agent B run directories found; deterministic setup only") + return 1 if bad else 0 + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument("--out", default="r17-causal-artifact") + parser.add_argument("--python", default=sys.executable) + parser.add_argument("--action", choices=("generate", "preflight", "verify", "all"), default="all") + args = parser.parse_args() + out = Path(args.out).resolve() + if args.action in ("generate", "all"): + write_files(out) + print(f"generated fixtures at {out}") + if args.action in ("preflight", "all"): + rc = preflight(out, args.python) + if rc: + return rc + if args.action in ("verify", "all"): + return verify(out, args.python) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())