consequa-x 0.1.0a2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. consequa_x-0.1.0a2/CONTRIBUTING.md +88 -0
  2. consequa_x-0.1.0a2/LICENSE +21 -0
  3. consequa_x-0.1.0a2/MANIFEST.in +5 -0
  4. consequa_x-0.1.0a2/PKG-INFO +303 -0
  5. consequa_x-0.1.0a2/README.md +280 -0
  6. consequa_x-0.1.0a2/docs/attribution-calibration.md +148 -0
  7. consequa_x-0.1.0a2/docs/build-contract.md +60 -0
  8. consequa_x-0.1.0a2/docs/car-reproduction-plan.md +91 -0
  9. consequa_x-0.1.0a2/docs/decision-contrastive.md +157 -0
  10. consequa_x-0.1.0a2/docs/decision-replay.md +63 -0
  11. consequa_x-0.1.0a2/docs/decision-shapley.md +207 -0
  12. consequa_x-0.1.0a2/docs/design.md +66 -0
  13. consequa_x-0.1.0a2/docs/interval-followup-plan.md +120 -0
  14. consequa_x-0.1.0a2/docs/policy-evaluation.md +208 -0
  15. consequa_x-0.1.0a2/docs/policy-replay.md +262 -0
  16. consequa_x-0.1.0a2/docs/refund-interactions.md +108 -0
  17. consequa_x-0.1.0a2/docs/release-readiness.md +134 -0
  18. consequa_x-0.1.0a2/docs/research-roadmap.md +47 -0
  19. consequa_x-0.1.0a2/docs/studies/refund-family-candidates-v1.json +485 -0
  20. consequa_x-0.1.0a2/docs/study-manifests.md +70 -0
  21. consequa_x-0.1.0a2/docs/study-plan.md +246 -0
  22. consequa_x-0.1.0a2/docs/variable-length-game-plan.md +83 -0
  23. consequa_x-0.1.0a2/examples/decision_shapley_fixture.py +157 -0
  24. consequa_x-0.1.0a2/pyproject.toml +48 -0
  25. consequa_x-0.1.0a2/requirements-dev.lock +17 -0
  26. consequa_x-0.1.0a2/setup.cfg +4 -0
  27. consequa_x-0.1.0a2/src/consequa_x/__init__.py +22 -0
  28. consequa_x-0.1.0a2/src/consequa_x/__main__.py +3 -0
  29. consequa_x-0.1.0a2/src/consequa_x/adapters/__init__.py +5 -0
  30. consequa_x-0.1.0a2/src/consequa_x/adapters/ollama.py +350 -0
  31. consequa_x-0.1.0a2/src/consequa_x/attribution.py +407 -0
  32. consequa_x-0.1.0a2/src/consequa_x/benchmark/__init__.py +1 -0
  33. consequa_x-0.1.0a2/src/consequa_x/benchmark/assessment_metrics.py +54 -0
  34. consequa_x-0.1.0a2/src/consequa_x/benchmark/calibration.py +787 -0
  35. consequa_x-0.1.0a2/src/consequa_x/benchmark/calibration_export.py +139 -0
  36. consequa_x-0.1.0a2/src/consequa_x/benchmark/calibration_mechanisms.py +266 -0
  37. consequa_x-0.1.0a2/src/consequa_x/benchmark/decision_coalition.py +254 -0
  38. consequa_x-0.1.0a2/src/consequa_x/benchmark/decision_contrastive.py +448 -0
  39. consequa_x-0.1.0a2/src/consequa_x/benchmark/decision_replay.py +329 -0
  40. consequa_x-0.1.0a2/src/consequa_x/benchmark/decision_shapley.py +628 -0
  41. consequa_x-0.1.0a2/src/consequa_x/benchmark/evaluation.py +187 -0
  42. consequa_x-0.1.0a2/src/consequa_x/benchmark/interaction_export.py +220 -0
  43. consequa_x-0.1.0a2/src/consequa_x/benchmark/interaction_mechanisms.py +192 -0
  44. consequa_x-0.1.0a2/src/consequa_x/benchmark/interval_comparison.py +276 -0
  45. consequa_x-0.1.0a2/src/consequa_x/benchmark/intervals.py +164 -0
  46. consequa_x-0.1.0a2/src/consequa_x/benchmark/payments.py +426 -0
  47. consequa_x-0.1.0a2/src/consequa_x/benchmark/policy_experiment.py +298 -0
  48. consequa_x-0.1.0a2/src/consequa_x/benchmark/policy_runner.py +234 -0
  49. consequa_x-0.1.0a2/src/consequa_x/benchmark/runner.py +241 -0
  50. consequa_x-0.1.0a2/src/consequa_x/benchmark/study.py +183 -0
  51. consequa_x-0.1.0a2/src/consequa_x/benchmark/targets.py +149 -0
  52. consequa_x-0.1.0a2/src/consequa_x/benchmark/templates.py +102 -0
  53. consequa_x-0.1.0a2/src/consequa_x/cli.py +1191 -0
  54. consequa_x-0.1.0a2/src/consequa_x/explanation.py +130 -0
  55. consequa_x-0.1.0a2/src/consequa_x/graph.py +142 -0
  56. consequa_x-0.1.0a2/src/consequa_x/models.py +532 -0
  57. consequa_x-0.1.0a2/src/consequa_x/policies.py +248 -0
  58. consequa_x-0.1.0a2/src/consequa_x/py.typed +0 -0
  59. consequa_x-0.1.0a2/src/consequa_x/schema.py +159 -0
  60. consequa_x-0.1.0a2/src/consequa_x/schemas/trace-v0.1.json +543 -0
  61. consequa_x-0.1.0a2/src/consequa_x/verification.py +192 -0
  62. consequa_x-0.1.0a2/src/consequa_x.egg-info/PKG-INFO +303 -0
  63. consequa_x-0.1.0a2/src/consequa_x.egg-info/SOURCES.txt +102 -0
  64. consequa_x-0.1.0a2/src/consequa_x.egg-info/dependency_links.txt +1 -0
  65. consequa_x-0.1.0a2/src/consequa_x.egg-info/entry_points.txt +2 -0
  66. consequa_x-0.1.0a2/src/consequa_x.egg-info/requires.txt +6 -0
  67. consequa_x-0.1.0a2/src/consequa_x.egg-info/top_level.txt +1 -0
  68. consequa_x-0.1.0a2/tests/test_assessment_metrics.py +233 -0
  69. consequa_x-0.1.0a2/tests/test_attribution.py +470 -0
  70. consequa_x-0.1.0a2/tests/test_calibration.py +382 -0
  71. consequa_x-0.1.0a2/tests/test_calibration_cli.py +120 -0
  72. consequa_x-0.1.0a2/tests/test_calibration_mechanisms.py +347 -0
  73. consequa_x-0.1.0a2/tests/test_cli.py +129 -0
  74. consequa_x-0.1.0a2/tests/test_decision_coalition.py +498 -0
  75. consequa_x-0.1.0a2/tests/test_decision_contrastive.py +552 -0
  76. consequa_x-0.1.0a2/tests/test_decision_contrastive_cli.py +306 -0
  77. consequa_x-0.1.0a2/tests/test_decision_replay.py +360 -0
  78. consequa_x-0.1.0a2/tests/test_decision_shapley.py +531 -0
  79. consequa_x-0.1.0a2/tests/test_decision_shapley_cli.py +226 -0
  80. consequa_x-0.1.0a2/tests/test_graph.py +143 -0
  81. consequa_x-0.1.0a2/tests/test_graph_identity.py +34 -0
  82. consequa_x-0.1.0a2/tests/test_integration.py +261 -0
  83. consequa_x-0.1.0a2/tests/test_interval_comparison.py +86 -0
  84. consequa_x-0.1.0a2/tests/test_interval_replay.py +184 -0
  85. consequa_x-0.1.0a2/tests/test_intervals.py +119 -0
  86. consequa_x-0.1.0a2/tests/test_model_eval_integration.py +229 -0
  87. consequa_x-0.1.0a2/tests/test_models.py +307 -0
  88. consequa_x-0.1.0a2/tests/test_ollama.py +500 -0
  89. consequa_x-0.1.0a2/tests/test_payments.py +429 -0
  90. consequa_x-0.1.0a2/tests/test_policies.py +193 -0
  91. consequa_x-0.1.0a2/tests/test_policy_evaluation.py +138 -0
  92. consequa_x-0.1.0a2/tests/test_policy_experiment.py +440 -0
  93. consequa_x-0.1.0a2/tests/test_policy_experiment_integration.py +275 -0
  94. consequa_x-0.1.0a2/tests/test_policy_runner.py +389 -0
  95. consequa_x-0.1.0a2/tests/test_prompt_profile_cli.py +44 -0
  96. consequa_x-0.1.0a2/tests/test_refund_interactions.py +298 -0
  97. consequa_x-0.1.0a2/tests/test_refund_interactions_cli.py +25 -0
  98. consequa_x-0.1.0a2/tests/test_replay_targets.py +240 -0
  99. consequa_x-0.1.0a2/tests/test_research_integration.py +78 -0
  100. consequa_x-0.1.0a2/tests/test_schema.py +145 -0
  101. consequa_x-0.1.0a2/tests/test_snapshot_integrity.py +20 -0
  102. consequa_x-0.1.0a2/tests/test_study.py +192 -0
  103. consequa_x-0.1.0a2/tests/test_task_templates.py +192 -0
  104. consequa_x-0.1.0a2/tests/test_verification.py +331 -0
@@ -0,0 +1,88 @@
1
+ # Contributing to Consequa-X
2
+
3
+ Contributions to the Python framework and the research are welcome. This is an alpha: the implementation uses refund simulation, programmatic policies, and an optional local Ollama adapter. Recorded results include scripted fixtures and a small [local-model pilot](output/live-pilot-2026-10-10/README.md). These establish implementation behavior, not empirical superiority or a new causal estimator. Preserve original live samples when adding exploratory prompt profiles or new evaluations.
4
+
5
+ Start with the [README](README.md), [design](docs/design.md), and [research roadmap](docs/research-roadmap.md). The [policy replay guide](docs/policy-replay.md) covers bounded context comparisons and evidence exports. Use an issue to discuss a larger adapter, schema change, new domain, or study before investing in the implementation. Small fixes and reproducible bug reports can go straight to a pull request.
6
+
7
+ ## Set up a development environment
8
+
9
+ Fork the repository, clone your fork, and create a branch for your change. Use Python 3.11 or 3.12:
10
+
11
+ ```sh
12
+ python -m venv .venv
13
+ ```
14
+
15
+ Activate it with `source .venv/bin/activate` on macOS/Linux or `.\.venv\Scripts\Activate.ps1` in PowerShell. Then install the project and tools:
16
+
17
+ ```sh
18
+ python -m pip install -e ".[dev]"
19
+ ```
20
+
21
+ For the pinned development dependencies used in CI, install `requirements-dev.lock` first, then install the project with `python -m pip install -e .`. The lock records the initial Python 3.12 environment; CI checks it on both supported versions.
22
+
23
+ Run the checks before submitting:
24
+
25
+ ```sh
26
+ python -m pytest
27
+ python -m ruff check src tests
28
+ python -m build
29
+ ```
30
+
31
+ CI runs tests, lint, and package builds on Ubuntu and Windows with Python 3.11 and 3.12. A wheel installation check verifies that the bundled trace schema is available. CI does not publish packages to a registry.
32
+
33
+ GitHub Actions is currently disabled because the account quota is exhausted.
34
+ Automatic push and pull-request triggers have been removed; use the local
35
+ checks above. The retained workflow is manual only and must not be re-enabled
36
+ or dispatched without the maintainer's authorization.
37
+
38
+ ## Where changes belong
39
+
40
+ | Location | Purpose |
41
+ | --- | --- |
42
+ | `src/consequa_x/` | Public records, validation, verification, graphs, explanations, attribution, and CLI |
43
+ | `src/consequa_x/benchmark/` | Offline simulator, scenarios, and replay runner |
44
+ | `src/consequa_x/adapters/` | Provider policy adapters with strict visible-input boundaries |
45
+ | `src/consequa_x/schemas/` | Versioned portable trace schema |
46
+ | `tests/` | Behavioral, conformance, integration, and export checks |
47
+ | `docs/` | Contracts, architecture, research plan, and supporting documents |
48
+ | `output/research/` | Literature assessment and research notes |
49
+
50
+ Include a regression test when correcting a behavioral defect. Adapter tests should use fixtures or local mocks so the default suite runs without provider credentials, network calls, or paid inference. Explain any public API or trace-format change and update the relevant documentation and schema/conformance checks together.
51
+
52
+ Generate the fixture outputs locally when a change affects their behavior:
53
+
54
+ ```sh
55
+ consequa-x demo --output output/demo --seed 0
56
+ consequa-x experiment --output output/experiments --samples 40 --seed 0
57
+ ```
58
+
59
+ These outputs are reproducible snapshots. If you propose updating committed snapshots, include the generating command, seed, and relevant revision in your pull request.
60
+
61
+ ## Preserve the evidence contract
62
+
63
+ - Keep tool responses, reported agent assessments, observed outcomes, and effect origin separate. A successful response does not establish a completed effect.
64
+ - Preserve `unknown` outcomes for insufficient, stale, incomplete, or malformed evidence. State adapter trust assumptions, including completeness, watermark, and provenance declarations.
65
+ - Keep evaluator truth, fault labels, and scenario labels outside policy and explainer inputs. Simulator truth can support evaluation, but cannot be evidence available to the evaluated policy.
66
+ - Keep replay isolated, align paired random draws, and preserve the target outcome contract under context interventions. Report unknown pairs and the distribution an estimate describes.
67
+ - Label graph edge meanings explicitly. Observed provenance and recency do not establish counterfactual necessity; signed replay effects are not normalized responsibility shares.
68
+
69
+ Use synthetic or appropriately shareable examples in issues and fixtures. Do not include credentials or real customer/payment records.
70
+
71
+ ## Research contributions
72
+
73
+ Useful contributions include related-work corrections, stronger baselines, additional LLM policy adapters, held-out task designs, independent outcome-verification adapters, and reproducible evaluations. Start with the [policy evaluation guide](docs/policy-evaluation.md) and [proposed study protocol](docs/study-plan.md). An issue should state the research question, primary sources, proposed comparison, and evidence needed to support the claim.
74
+
75
+ For experiments, report the model/provider and version where applicable, task templates and splits, seeds, interventions, verifier and origin assumptions, sample size, uncertainty, abstention/error coverage, and budget. Compare methods with equivalent evidence and resources. Distinguish simulator fixture results from actual model results, and distinguish a framework improvement from a methodological novelty claim.
76
+
77
+ The [attribution calibration guide](docs/attribution-calibration.md) describes
78
+ the offline repeated-mechanism command and its compressed evidence exports.
79
+ Preserve the predeclared protocol and all refused trials when extending it.
80
+ Keep analytic reference labels separate from the production outcome adapter;
81
+ do not redesign intervals after viewing a retained study and score the same
82
+ study as an independent validation.
83
+
84
+ The research brief is a proposal. Its claims should be checked against the literature and results before appearing as findings in a paper.
85
+
86
+ ## Submit a pull request
87
+
88
+ Keep each pull request focused. Describe the problem, resulting behavior, evidence or tests, and remaining limitations. Link a related issue when available. State which checks you ran and which you could not run. Submit only material you have permission to share. Contributions submitted for inclusion in this project are provided under its [MIT License](LICENSE).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Devrajsinh Jhala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include README.md CONTRIBUTING.md LICENSE requirements-dev.lock
2
+ recursive-include docs *.md
3
+ recursive-include docs/studies *.json
4
+ recursive-include tests *.py
5
+ recursive-include examples *.py
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: consequa-x
3
+ Version: 0.1.0a2
4
+ Summary: Evidence-aware explanation of consequential agent actions
5
+ Author: Devrajsinh Jhala
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/Devrajsinh-Jhala/consequa-x
8
+ Project-URL: Issues, https://github.com/Devrajsinh-Jhala/consequa-x/issues
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8; extra == "dev"
19
+ Requires-Dist: build>=1.2; extra == "dev"
20
+ Requires-Dist: ruff>=0.8; extra == "dev"
21
+ Requires-Dist: jsonschema>=4.23; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # Consequa-X
25
+
26
+ [![CI](https://github.com/Devrajsinh-Jhala/consequa-x/actions/workflows/ci.yml/badge.svg)](https://github.com/Devrajsinh-Jhala/consequa-x/actions/workflows/ci.yml)
27
+
28
+ Consequa-X explains consequential agent actions using captured history and independent outcome evidence. Its Python alpha (`0.1.0a2`) provides a versioned trace format, refund verification, evidence graphs, and isolated replay experiments.
29
+
30
+ The working prototype uses an isolated payment simulator with scripted policies and an optional local Ollama adapter. It keeps the tool response, the agent's reported assessment, the observed outcome, and effect origin separate. A timeout can coexist with a completed refund; another actor can satisfy the desired state after the agent's attempt fails.
31
+
32
+ The first [recorded local-model pilot](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/live-pilot-2026-10-10/README.md) completed six runs with Qwen3 4B. All refunds were independently verified as successful, while the model reported failure in every run; changing the retry instruction produced no observed effect in two replay pairs. This is a small integration result. Payments remain simulated, and neither fixture experiments nor the pilot establish a new attribution method or empirical superiority. See [the design](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/design.md) for exact semantics and [the research roadmap](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/research-roadmap.md) for the paper and release milestones.
33
+
34
+ ## Research materials and contributions
35
+
36
+ - [Original research brief (PDF)](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/research/Consequa-X_Research_Brief.pdf)
37
+ - [Initial literature assessment](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/research/Consequa-X_Research_Assessment.md)
38
+ - [Demo results and evidence exports](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/demo/README.md)
39
+ - [Paired fixture experiment results](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/experiments/README.md)
40
+ - [Policy evaluation guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/policy-evaluation.md)
41
+ - [Scripted policy smoke results](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/policy-smoke/README.md)
42
+ - [Paired policy replay guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/policy-replay.md)
43
+ - [Scripted replay smoke results](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/replay-smoke/README.md)
44
+ - [First live-model pilot and audit](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/live-pilot-2026-10-10/README.md)
45
+ - [Exploratory prompt comparison and retry diagnostic](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/prompt-sensitivity-2026-10-10/README.md)
46
+ - [Proposed model study protocol](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/study-plan.md)
47
+ - [Candidate task-family splits and evidence targets](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/study-manifests.md)
48
+ - [Decision-prefix replay](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-replay.md)
49
+ - [Decision contrastive replay](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-contrastive.md)
50
+ - [Positional decision coalitions and Shapley replay](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-shapley.md)
51
+ - [Strong baseline reproduction plan](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/car-reproduction-plan.md)
52
+ - [Installed-package study and replay checks](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/study-foundation-2026-10-11/README.md)
53
+ - [Decision contrastive controls and seeded fixture](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/contrastive-foundation-2026-10-11/README.md)
54
+ - [Shapley controls, protective decision, and unavailable coalitions](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/shapley-foundation-2026-10-11/README.md)
55
+ - [Alpha validation report](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/build/README.md)
56
+
57
+ Contributions to the framework and research are welcome. Read [CONTRIBUTING.md](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/CONTRIBUTING.md), then open an issue or pull request. The project uses the [MIT license](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/LICENSE). Useful next contributions include additional policy adapters, verified domains, stronger baseline comparisons, and held-out task templates.
58
+
59
+ ## Install locally
60
+
61
+ From this repository, use Python 3.11 or newer:
62
+
63
+ ```sh
64
+ git clone https://github.com/Devrajsinh-Jhala/consequa-x.git
65
+ cd consequa-x
66
+ python -m venv .venv
67
+ ```
68
+
69
+ Activate the environment in PowerShell:
70
+
71
+ ```powershell
72
+ .\.venv\Scripts\Activate.ps1
73
+ ```
74
+
75
+ Or on macOS/Linux:
76
+
77
+ ```sh
78
+ source .venv/bin/activate
79
+ ```
80
+
81
+ Then install the source and development tools:
82
+
83
+ ```sh
84
+ python -m pip install -e ".[dev]"
85
+ consequa-x --version
86
+ ```
87
+
88
+ The installed framework has no required runtime dependencies and needs no provider credentials. Use `python -m consequa_x` wherever these examples use `consequa-x`.
89
+
90
+ ## Run the demo
91
+
92
+ ```sh
93
+ consequa-x demo --output output/demo --seed 0
94
+ ```
95
+
96
+ This writes 12 scenarios, including a timeout after commit, false success, partial refunds, delayed visibility, safe and unsafe retries, external-actor effects, and missing provenance. Open `output/demo/README.md` for the outcome table.
97
+
98
+ | Export | Purpose |
99
+ | --- | --- |
100
+ | `traces/` | Captured events, responses, assessments, observations, and verification records |
101
+ | `explanations/` | Diagnoses and evidence graphs produced from those traces |
102
+ | `evaluator_truth/` | Simulator truth, injection labels, and scenario configuration for evaluation only |
103
+ | `trace-schema.json` | Portable JSON Schema for trace structure |
104
+ | `manifest.json` | SHA-256 hashes of episode artifacts for integrity checks |
105
+
106
+ Keep evaluator truth outside explainer and policy inputs. Manifest hashes detect file changes; they do not authenticate evidence sources. The simulator uses local synthetic funds, including synthetic compensation for temporal-contract tests.
107
+
108
+ Explain a saved trace without replaying a policy or executing a provider call:
109
+
110
+ ```sh
111
+ consequa-x explain output/demo/traces/episode_01.json --output output/explanation.json
112
+ ```
113
+
114
+ ## Evaluate a policy
115
+
116
+ Run the policy interface without installing a model:
117
+
118
+ ```sh
119
+ consequa-x model-eval --provider scripted --samples 2 --max-calls 100 --output output/my-policy-smoke
120
+ ```
121
+
122
+ The policy chooses whether to refund, retry, or stop, then reports its assessment before independent verification. Each trial starts a fresh simulated world. Reports include completed, failed, and unstarted samples; provider/protocol errors stay separate from verified consequence violations and unknown readback. Use a fresh output directory for each run.
123
+
124
+ Once you have installed Ollama and a local model, replace `YOUR_INSTALLED_MODEL` with its name:
125
+
126
+ ```sh
127
+ consequa-x model-eval --provider ollama --model YOUR_INSTALLED_MODEL --cases clean,timeout_after_commit --samples 1 --max-calls 6 --output output/my-local-model
128
+ ```
129
+
130
+ The adapter checks installed models and declared local routing before generation, uses structured decisions, and records model identity and request hashes. It performs no model installation or download. See [the evaluation guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/policy-evaluation.md) for setup, limits, API examples, and trust assumptions. The [study protocol](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/study-plan.md) defines the stronger comparisons and held-out tasks still needed for a research paper.
131
+
132
+ The original `refund-policy-v1` prompt remains the default. Select the opt-in `--prompt-version refund-policy-v2` to clarify assessment, timing, and attempt-budget semantics and add stop-after-success guidance. This is a pilot-informed policy refinement; comparison results are exploratory. Both evaluation and replay record the chosen version and its exact prompt hash. Reports also expose assessment abstention, claim coverage, and contradictions with explicit denominators. These metrics score the structured status, while rationale text requires separate review. The [follow-up pilot](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/prompt-sensitivity-2026-10-10/README.md) found unknown status fields alongside affirmative rationale claims, so it does not establish an accuracy gain. Hindsight alignment with verified state does not establish what a policy could know from an ambiguous response.
133
+
134
+ ## Use the Python API
135
+
136
+ For study preparation, `model-eval --study docs/studies/refund-family-candidates-v1.json --split tuning`
137
+ selects a validated candidate wording family and records the planned order and
138
+ exact manifest hash. The original pilot family is excluded from the held-out
139
+ reserve. This assignment is not a claim of held-out model performance.
140
+ `model-experiment --targets action,consequence,action_linked_consequence` adds
141
+ qualifying action-linked outcomes without additional replay calls. The
142
+ [decision replay API](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-replay.md) holds factual prefixes for future
143
+ baseline implementations. [Decision contrastive replay](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-contrastive.md)
144
+ now estimates suffix effects against one recorded factual outcome.
145
+ [Positional Shapley replay](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-shapley.md) adds fresh coalition walks,
146
+ paired contribution estimates, and independent endpoint diagnostics. Strict
147
+ unreachable-position refusal can make variable-length games unavailable;
148
+ calibration and the final matched comparison remain research milestones.
149
+
150
+ ```python
151
+ from consequa_x import Trace, explain, verify
152
+ from consequa_x.benchmark.runner import run_scenario
153
+ from consequa_x.schema import get_trace_schema, validate_trace
154
+
155
+ episode = run_scenario(seed=0) # Default: timeout after the refund commits.
156
+ trace = episode.trace
157
+
158
+ receipt = verify(trace.action, trace.observations[-1])
159
+ print(receipt.status.value) # satisfied
160
+ print(receipt.origin.value) # confirmed
161
+ print(explain(trace).diagnosis) # BELIEF / RESPONSE DIVERGENCE
162
+
163
+ encoded = trace.to_json()
164
+ restored = Trace.from_json(encoded)
165
+ assert validate_trace(encoded) == restored
166
+ schema = get_trace_schema() # Bundled trace schema v0.1.
167
+ ```
168
+
169
+ `verify(action, observation)` is read-only. The built-in `refund_processed` contract checks the payment, amount, currency, count, deadline, and optional stability interval. Stale, incomplete, unavailable, or malformed readback produces `unknown` rather than a final success/failure claim. Origin is reported independently as `confirmed`, `other_actor`, or `unknown`.
170
+
171
+ `explain(trace, estimates=())` uses the latest captured verification. It records reported-assessment alignment and graph edges with explicit meanings. A reported assessment is not a measurement of hidden reasoning; an origin link is not proof of counterfactual necessity. Supplied replay estimates add estimated-influence edges. Recency remains a labeled heuristic.
172
+
173
+ Trace decoding rejects unsupported versions, unknown fields, invalid references, and dependency cycles. The portable JSON Schema covers record structure; `validate_trace` also checks relationships between records. These checks trust source and watermark declarations and do not authenticate a provider. See [the design](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/design.md) before writing an adapter.
174
+
175
+ ## Run paired replay experiments
176
+
177
+ Replay the policy interface under declared context changes:
178
+
179
+ ```sh
180
+ consequa-x model-experiment --provider scripted --case unsafe_retry --samples 20 --max-calls 400 --output output/my-policy-replay
181
+ ```
182
+
183
+ Each factual seed runs once and is reused across candidate comparisons and all selected targets. The call limit applies to the whole experiment. Failed or unstarted branches and unknown consequences remain explicit; an estimate requires every planned target pair to be usable. The export includes branch evidence, signed effects, pair coverage, and an optional factual explanation with estimated-influence edges. See [the replay guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/policy-replay.md) for the Python API and prepared Ollama entry point.
184
+
185
+ The committed [scripted replay example](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/replay-smoke/README.md) uses two seeds per condition to check the integration. It is not a model result or an adequate sample size for a research claim.
186
+
187
+ Test recorded decision boundaries using one factual capture and fresh suffixes:
188
+
189
+ ```sh
190
+ consequa-x decision-experiment --provider scripted --case unsafe_retry --samples 16 --seed 100 --factual-seed 0 --max-calls 400 --output output/my-decision-replay
191
+ ```
192
+
193
+ This independently written CAR-style binary adaptation estimates changed-minus-factual
194
+ bad-outcome probability and reports the latest nominal rescue position. Its shared
195
+ call budget includes the factual recording. Unknowns, failures, and unstarted
196
+ samples refuse affected estimates; incomplete decision coverage refuses the final
197
+ locus. The default exact binomial intervals retain uncertainty at homogeneous
198
+ samples and condition on one observed factual episode. Legacy bootstrap and
199
+ Wilson options remain explicit comparators. See [the decision guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-contrastive.md)
200
+ for signs, reference version, implementation deviations, and statistical limits.
201
+
202
+ Allocate signed contributions with fresh held-decision coalition walks:
203
+
204
+ ```sh
205
+ consequa-x decision-shapley --provider scripted --case clean --pairs 16 --samples 1 --endpoint-samples 16 --seed 100 --max-calls 2000 --output output/my-decision-shapley
206
+ ```
207
+
208
+ One permutation and its reverse form one observation. Separate endpoint draws
209
+ check the total scale without normalizing the shares. Unknown or unavailable
210
+ path evidence refuses the affected target vector. See the
211
+ [Shapley guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/decision-shapley.md) for intervention validity, signs,
212
+ budgets, and conditional interval limits. Defaults use Hoeffding bounds for
213
+ pair means and two exact binomial marginals for endpoint differences. They can
214
+ be wide at small budgets; normal intervals remain an explicit comparator.
215
+
216
+ The default strict game refuses unreachable held positions. The separate
217
+ `--coalition-game on_reach` option records normally unreached held positions as
218
+ inactive and uses the actual completed trajectory. Reached incompatible
219
+ decisions still invalidate a draw. See the
220
+ [refund interaction guide](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/refund-interactions.md) for exact physical
221
+ enumeration and the distinction between the two games.
222
+
223
+ Probe both decision estimators against declared analytic refund mechanisms:
224
+
225
+ ```sh
226
+ consequa-x calibrate-attribution --replicates 32 --output output/my-calibration
227
+ ```
228
+
229
+ This offline experiment reports error, interval coverage, false nonzero flags,
230
+ locus recovery and refusals with explicit denominators. It saves its protocol
231
+ before execution, every planned draw in compressed JSONL, and full evidence
232
+ for a preselected repetition. See [the calibration design](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/attribution-calibration.md)
233
+ for analytic references, budget controls and interpretation limits.
234
+
235
+ The [retained 1,280-trial probe](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/calibration-probe-2026-10-11/FINDINGS.md)
236
+ and [independent finite interval analysis](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/calibration-theory-2026-10-11/README.md)
237
+ show weak coverage for several original nominal 95% intervals. The
238
+ [384-trial same-draw comparison](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/output/interval-comparison-2026-10-13/README.md)
239
+ and [follow-up protocol](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/interval-followup-plan.md) compare revised bounds
240
+ on fresh data, including width and detection strength. The original probe and
241
+ its methods remain available; synthetic checks do not establish live-model
242
+ coverage or superiority.
243
+
244
+ ```sh
245
+ consequa-x compare-intervals --replicates 32 --seed 2000000 --output output/my-interval-comparison
246
+ ```
247
+
248
+ A [working research paper](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/paper/manuscript.md) links the completed evidence and
249
+ the held-out studies still required. [Release readiness](https://github.com/Devrajsinh-Jhala/consequa-x/blob/main/docs/release-readiness.md)
250
+ distinguishes a locally installable alpha from a completed PyPI publication.
251
+
252
+ Run the original deterministic and stochastic fixture comparison:
253
+
254
+ ```sh
255
+ consequa-x experiment --output output/experiments --samples 40 --seed 0
256
+ ```
257
+
258
+ The command requires at least 20 samples per condition. It writes `results.json` and a report comparing action selection and verified consequence under deterministic and stochastic programmatic policies. Both branches of each pair start in fresh simulated worlds with aligned random draws.
259
+
260
+ The unsafe retry fixture illustrates why the targets differ: neutralizing the retry instruction leaves initial action selection unchanged, but prevents a second refund and restores exactly-once satisfaction.
261
+
262
+ For a custom fixture experiment:
263
+
264
+ ```python
265
+ from consequa_x import Intervention, explain, leave_one_out
266
+ from consequa_x.benchmark.runner import (
267
+ RefundContext, RefundReplayRunner, ScenarioConfig, run_scenario,
268
+ )
269
+
270
+ config = ScenarioConfig(
271
+ context=RefundContext(retry_instruction=True),
272
+ use_idempotency=False,
273
+ )
274
+ estimates = leave_one_out(
275
+ RefundReplayRunner(config),
276
+ (Intervention("retry_instruction"), Intervention("distractor")),
277
+ target="consequence",
278
+ samples=40,
279
+ seed=0,
280
+ )
281
+ print(estimates[0].effect) # -1.0: removing retry improves this target.
282
+ explanation = explain(run_scenario(config, seed=0).trace, estimates)
283
+ ```
284
+
285
+ An estimate is the original rate minus the intervened rate, with an approximate conservative 95% interval. It is a signed experimental effect, not a normalized responsibility share. Unknown consequence pairs refuse an estimate. Results describe the declared replay distribution; they do not demonstrate generalization across tasks or LLMs. A custom replay runner must reset its world, preserve the outcome contract, and supply independently verified outcomes. The current fixture runner supports neutralization or typed replacement of declared context fields.
286
+
287
+ ## Development and local distribution
288
+
289
+ ```sh
290
+ python -m pytest
291
+ python -m ruff check src tests
292
+ python -m build
293
+ ```
294
+
295
+ The build writes a wheel and source distribution to `dist/`. To install the wheel in another environment:
296
+
297
+ ```sh
298
+ python -m pip install dist/consequa_x-0.1.0a2-py3-none-any.whl
299
+ ```
300
+
301
+ `requirements-dev.lock` captures the development environment used for this build. Public interfaces are alpha and may change. The Python requirement is declared as 3.11+, with local validation currently on Python 3.12; broader compatibility remains a release check.
302
+
303
+ The package has not been published to PyPI or npm. The first registry target is PyPI; a later npm adapter can share the trace schema and conformance fixtures. The repository includes MIT licensing, author metadata, contributor guides, and CI for Python 3.11/3.12 on Windows and Ubuntu. Registry availability, broader compatibility, and the final release process remain to be verified. Broader model evaluations, held-out task templates, and comparisons against strong existing methods remain necessary for the research paper.