refute 0.5.12__py3-none-any.whl
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.
- refute/__init__.py +4 -0
- refute/cli.py +465 -0
- refute/core/__init__.py +0 -0
- refute/core/budget.py +492 -0
- refute/core/canonical.py +63 -0
- refute/core/chi2.py +129 -0
- refute/core/claim.py +203 -0
- refute/core/codehash.py +185 -0
- refute/core/dossier.py +296 -0
- refute/core/environment.py +104 -0
- refute/core/hashing.py +51 -0
- refute/core/inconclusive.py +166 -0
- refute/core/io.py +99 -0
- refute/core/ledger.py +143 -0
- refute/core/lock.py +644 -0
- refute/core/lock_compat.py +291 -0
- refute/core/pack.py +178 -0
- refute/core/paper.py +595 -0
- refute/core/reply.py +262 -0
- refute/core/reproduce.py +260 -0
- refute/core/review.py +171 -0
- refute/core/run.py +568 -0
- refute/core/runner.py +169 -0
- refute/core/seal.py +392 -0
- refute/core/sensitivity.py +297 -0
- refute/core/verdict.py +276 -0
- refute/drand.py +147 -0
- refute/packs/__init__.py +0 -0
- refute/packs/ml/__init__.py +76 -0
- refute/packs/ml/_reaper.py +192 -0
- refute/packs/ml/attacks.py +329 -0
- refute/packs/ml/container_reader.py +128 -0
- refute/packs/ml/coverage_hook.py +468 -0
- refute/packs/ml/docker_backend.py +541 -0
- refute/packs/ml/extract.py +496 -0
- refute/packs/ml/fetch.py +308 -0
- refute/packs/ml/integration.py +1843 -0
- refute/packs/ml/ladder.py +260 -0
- refute/packs/ml/orchestrate.py +570 -0
- refute/packs/ml/patches.py +541 -0
- refute/packs/ml/predicates.py +360 -0
- refute/packs/ml/production.py +1554 -0
- refute/packs/ml/readers.py +209 -0
- refute/packs/ml/recompute.py +664 -0
- refute/packs/ml/repository.py +195 -0
- refute/packs/ml/reproduction.py +175 -0
- refute/packs/ml/rules.py +50 -0
- refute/packs/ml/sandbox.py +543 -0
- refute/packs/ml/schema.py +2357 -0
- refute/packs/ml/seeds.py +61 -0
- refute/packs/ml/synthetic.py +376 -0
- refute/packs/ml/tbevents.py +271 -0
- refute/packs/ml/uncertainty.py +195 -0
- refute/packs/tess/__init__.py +34 -0
- refute/packs/tess/a0.py +424 -0
- refute/packs/tess/a0_v4.py +248 -0
- refute/packs/tess/adapter.py +861 -0
- refute/packs/tess/battery.py +1059 -0
- refute/packs/tess/battery_v5.py +538 -0
- refute/packs/tess/battery_v51.py +602 -0
- refute/packs/tess/battery_v51_diff.py +673 -0
- refute/packs/tess/battery_v52.py +430 -0
- refute/packs/tess/calib05/__init__.py +4 -0
- refute/packs/tess/calib05/c1.py +716 -0
- refute/packs/tess/calib05/c2.py +410 -0
- refute/packs/tess/calib05/c3run.py +433 -0
- refute/packs/tess/calib05/c3select.py +471 -0
- refute/packs/tess/calib05/plans.py +35 -0
- refute/packs/tess/calib05/runner.py +315 -0
- refute/packs/tess/calib05/steps.py +539 -0
- refute/packs/tess/calib05/values.py +105 -0
- refute/packs/tess/calib051/__init__.py +10 -0
- refute/packs/tess/calib051/claim.py +152 -0
- refute/packs/tess/calib051/plans.py +38 -0
- refute/packs/tess/calib051/tasks.py +254 -0
- refute/packs/tess/calib051/values.py +55 -0
- refute/packs/tess/calibration.py +314 -0
- refute/packs/tess/centroid_v5.py +364 -0
- refute/packs/tess/detrend.py +137 -0
- refute/packs/tess/detrend_fast.py +345 -0
- refute/packs/tess/discover/__init__.py +5 -0
- refute/packs/tess/discover/case.py +254 -0
- refute/packs/tess/discover/claim.py +392 -0
- refute/packs/tess/discover/dedup.py +197 -0
- refute/packs/tess/discover/funnel.py +243 -0
- refute/packs/tess/discover/injection.py +250 -0
- refute/packs/tess/discover/measure.py +235 -0
- refute/packs/tess/discover/paired.py +280 -0
- refute/packs/tess/discover/pilot.py +1011 -0
- refute/packs/tess/discover/promotion_v05.py +59 -0
- refute/packs/tess/discover/protocol.py +123 -0
- refute/packs/tess/discover/runs.py +225 -0
- refute/packs/tess/discover/selection.py +609 -0
- refute/packs/tess/discover/steps.py +546 -0
- refute/packs/tess/discover/transforms.py +152 -0
- refute/packs/tess/domain.py +223 -0
- refute/packs/tess/duration.py +138 -0
- refute/packs/tess/ebcatalog.py +360 -0
- refute/packs/tess/ephemeris.py +141 -0
- refute/packs/tess/events.py +184 -0
- refute/packs/tess/exporter.py +171 -0
- refute/packs/tess/frozen.py +95 -0
- refute/packs/tess/gauntlet.py +317 -0
- refute/packs/tess/holdout.py +1998 -0
- refute/packs/tess/inconclusive.py +71 -0
- refute/packs/tess/params.py +681 -0
- refute/packs/tess/pipeline.py +1247 -0
- refute/packs/tess/pipeline_v52.py +201 -0
- refute/packs/tess/plots.py +152 -0
- refute/packs/tess/power.py +351 -0
- refute/packs/tess/prewhiten.py +300 -0
- refute/packs/tess/rednoise.py +212 -0
- refute/packs/tess/rednoise_fast.py +91 -0
- refute/packs/tess/report.py +345 -0
- refute/packs/tess/schema.py +195 -0
- refute/packs/tess/screen_d5.py +835 -0
- refute/packs/tess/search.py +370 -0
- refute/packs/tess/synthetic.py +976 -0
- refute/packs/tess/timing.py +277 -0
- refute/packs/tess/types.py +263 -0
- refute/selection/__init__.py +5 -0
- refute/selection/filters.py +307 -0
- refute/selection/frame.py +58 -0
- refute/selection/inventory.py +356 -0
- refute/selection/publication.py +199 -0
- refute/selection/walk.py +244 -0
- refute-0.5.12.dist-info/METADATA +202 -0
- refute-0.5.12.dist-info/RECORD +131 -0
- refute-0.5.12.dist-info/WHEEL +4 -0
- refute-0.5.12.dist-info/entry_points.txt +6 -0
- refute-0.5.12.dist-info/licenses/LICENSE +191 -0
refute/__init__.py
ADDED
refute/cli.py
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
"""Command-line interface: ``refute``.
|
|
2
|
+
|
|
3
|
+
Exit codes are documented in ``docs/cli.md``.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Annotated
|
|
12
|
+
|
|
13
|
+
import typer
|
|
14
|
+
|
|
15
|
+
import refute
|
|
16
|
+
from refute.core.claim import ClaimError, load_claim
|
|
17
|
+
from refute.core.dossier import check_dossier, write_archive
|
|
18
|
+
from refute.core.lock import LockError, code_only_note, create_lock, verify_claim
|
|
19
|
+
from refute.core.pack import PackError, available_packs, load_pack
|
|
20
|
+
from refute.core.review import ReviewError, attach_review
|
|
21
|
+
|
|
22
|
+
app = typer.Typer(
|
|
23
|
+
add_completion=False,
|
|
24
|
+
no_args_is_help=True,
|
|
25
|
+
help="Refute: find signals, try to kill them, keep what survives.",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _version_callback(value: bool) -> None:
|
|
30
|
+
if value:
|
|
31
|
+
typer.echo(f"refute {refute.__version__}")
|
|
32
|
+
raise typer.Exit(0)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.callback()
|
|
36
|
+
def _root(
|
|
37
|
+
version: Annotated[
|
|
38
|
+
bool,
|
|
39
|
+
typer.Option("--version", callback=_version_callback, is_eager=True, help="Show version."),
|
|
40
|
+
] = False,
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Refute command-line interface."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@app.command("packs")
|
|
46
|
+
def packs_command() -> None:
|
|
47
|
+
"""List installed domain packs."""
|
|
48
|
+
packs = available_packs()
|
|
49
|
+
if not packs:
|
|
50
|
+
typer.echo("no domain packs installed")
|
|
51
|
+
raise typer.Exit(1)
|
|
52
|
+
for name, target in sorted(packs.items()):
|
|
53
|
+
try:
|
|
54
|
+
pack = load_pack(name)
|
|
55
|
+
typer.echo(f"{name} {pack.version}: {pack.description}")
|
|
56
|
+
except PackError as exc:
|
|
57
|
+
typer.echo(f"{name} ({target}): ERROR {exc}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@app.command("lock")
|
|
61
|
+
def lock_command(
|
|
62
|
+
claim: Annotated[Path, typer.Argument(help="Path to claim.yaml")],
|
|
63
|
+
force: Annotated[
|
|
64
|
+
bool, typer.Option("--force", help="Re-lock an already locked claim.")
|
|
65
|
+
] = False,
|
|
66
|
+
reason: Annotated[
|
|
67
|
+
str | None, typer.Option("--reason", help="Why the claim is re-locked (with --force).")
|
|
68
|
+
] = None,
|
|
69
|
+
) -> None:
|
|
70
|
+
"""Lock a claim: hash the claim, its attachments and the code; record it in LOCK_HISTORY.md."""
|
|
71
|
+
try:
|
|
72
|
+
lock = create_lock(claim, force=force, reason=reason)
|
|
73
|
+
except LockError as exc:
|
|
74
|
+
typer.echo(f"lock refused: {exc}", err=True)
|
|
75
|
+
raise typer.Exit(1) from exc
|
|
76
|
+
typer.echo(f"locked {lock['claim_path']} ({lock['claim_id']})")
|
|
77
|
+
typer.echo(f" claim_sha256: {lock['claim_sha256']}")
|
|
78
|
+
for attachment in lock["attachments"]:
|
|
79
|
+
typer.echo(f" attachment {attachment['path']}: {attachment['sha256']}")
|
|
80
|
+
typer.echo(f" code_sha256: {lock['code']['sha256']} ({len(lock['code']['files'])} files)")
|
|
81
|
+
typer.echo(f" git_commit: {lock['git_commit']} (dirty: {lock['git_dirty']})")
|
|
82
|
+
typer.echo(f" locked_at: {lock['locked_at_utc']}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@app.command("verify")
|
|
86
|
+
def verify_command(
|
|
87
|
+
claim: Annotated[Path, typer.Argument(help="Path to claim.yaml")],
|
|
88
|
+
as_json: Annotated[bool, typer.Option("--json", help="Print the result as JSON.")] = False,
|
|
89
|
+
) -> None:
|
|
90
|
+
"""Verify a locked claim. Exit code 0 PASS, 1 FAIL, 2 TAMPERED."""
|
|
91
|
+
result = verify_claim(claim)
|
|
92
|
+
if as_json:
|
|
93
|
+
typer.echo(json.dumps(result.to_dict(), indent=2))
|
|
94
|
+
else:
|
|
95
|
+
typer.echo(result.status.value)
|
|
96
|
+
for message in result.messages:
|
|
97
|
+
typer.echo(f" {message}")
|
|
98
|
+
# text output only, and only when the code is the only problem (issue #66)
|
|
99
|
+
note = code_only_note(result)
|
|
100
|
+
if note:
|
|
101
|
+
typer.echo(f" note: {note}")
|
|
102
|
+
raise typer.Exit(result.exit_code)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@app.command("prepare-inputs")
|
|
106
|
+
def prepare_inputs_command(
|
|
107
|
+
claim: Annotated[Path, typer.Argument(help="Path to claim.yaml")],
|
|
108
|
+
) -> None:
|
|
109
|
+
"""Fetch and verify the inputs a clone lacks, as the locked claim declares them (v0.5).
|
|
110
|
+
|
|
111
|
+
The claim is verified first (its declaration is part of the locked claim); each input is
|
|
112
|
+
fetched over https, checked against its SHA-256 and installed under `.cache/frozen/` without
|
|
113
|
+
replacing anything. Exit code 0 when every input is present."""
|
|
114
|
+
from refute.core.claim import load_claim
|
|
115
|
+
from refute.core.reproduce import InputError, prepare, specs_from
|
|
116
|
+
from refute.core.run import input_root
|
|
117
|
+
|
|
118
|
+
result = verify_claim(claim)
|
|
119
|
+
if result.status.value != "PASS":
|
|
120
|
+
typer.echo(f"refused: refute verify gives {result.status.value}")
|
|
121
|
+
raise typer.Exit(1)
|
|
122
|
+
loaded = load_claim(claim)
|
|
123
|
+
hook = getattr(loaded.pack.schema, "reproduction_inputs", None)
|
|
124
|
+
declared = hook(loaded) if hook is not None else []
|
|
125
|
+
if not declared:
|
|
126
|
+
typer.echo("the claim declares no inputs")
|
|
127
|
+
raise typer.Exit(0)
|
|
128
|
+
try:
|
|
129
|
+
report = prepare(specs_from(declared), input_root(loaded))
|
|
130
|
+
except (InputError, OSError) as error:
|
|
131
|
+
typer.echo(f"refused: {error}")
|
|
132
|
+
raise typer.Exit(1) from error
|
|
133
|
+
for line in report:
|
|
134
|
+
typer.echo(f" {line['name']}: {line['state']}")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@app.command("fetch")
|
|
138
|
+
def fetch_command(
|
|
139
|
+
claim: Annotated[Path, typer.Argument(help="Path to claim.yaml")],
|
|
140
|
+
target: Annotated[
|
|
141
|
+
list[str] | None, typer.Option("--target", help="Only this target (repeatable).")
|
|
142
|
+
] = None,
|
|
143
|
+
cache_dir: Annotated[Path | None, typer.Option("--cache-dir")] = None,
|
|
144
|
+
stage: Annotated[
|
|
145
|
+
int | None,
|
|
146
|
+
typer.Option("--stage", help="Discover claims: the funnel stage whose data to fetch."),
|
|
147
|
+
] = None,
|
|
148
|
+
promotion: Annotated[
|
|
149
|
+
Path | None,
|
|
150
|
+
typer.Option("--promotion", help="Discover claims, stage 2: the promotion record."),
|
|
151
|
+
] = None,
|
|
152
|
+
) -> None:
|
|
153
|
+
"""Download and cache the public data of a claim's targets (network)."""
|
|
154
|
+
from refute.core.run import (
|
|
155
|
+
_fetch_one,
|
|
156
|
+
_select_targets,
|
|
157
|
+
default_cache_dir,
|
|
158
|
+
duplicate_keys_problem,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
loaded = load_claim(claim)
|
|
163
|
+
except ClaimError as exc:
|
|
164
|
+
typer.echo(str(exc), err=True)
|
|
165
|
+
raise typer.Exit(1) from exc
|
|
166
|
+
duplicates = duplicate_keys_problem(loaded)
|
|
167
|
+
if duplicates:
|
|
168
|
+
typer.echo(duplicates, err=True)
|
|
169
|
+
raise typer.Exit(1)
|
|
170
|
+
selected, missing = _select_targets(loaded, target)
|
|
171
|
+
if missing:
|
|
172
|
+
typer.echo(f"unknown target(s): {', '.join(missing)}", err=True)
|
|
173
|
+
raise typer.Exit(1)
|
|
174
|
+
from refute.core.run import RunOutcome, _discover_stage, prepare_claim_data
|
|
175
|
+
|
|
176
|
+
test_plan = loaded.claim.test_plan
|
|
177
|
+
mode = "discover" if loaded.claim.kind == "discover" else loaded.claim.kind
|
|
178
|
+
# v0.4: stage 1 of the funnel downloads no target pixel file, and stage 2 downloads them
|
|
179
|
+
# only for controls and promoted stars (decision D12); the same checks as a run.
|
|
180
|
+
staging = _discover_stage(loaded, mode, stage, promotion, selected)
|
|
181
|
+
if isinstance(staging, RunOutcome):
|
|
182
|
+
typer.echo(staging.messages[0], err=True)
|
|
183
|
+
raise typer.Exit(1)
|
|
184
|
+
if staging is not None:
|
|
185
|
+
test_plan = loaded.pack.schema.plan_for_stage(test_plan, staging["stage"])
|
|
186
|
+
|
|
187
|
+
cache = cache_dir or default_cache_dir()
|
|
188
|
+
prepared = prepare_claim_data(loaded.pack, loaded, cache, offline=False)
|
|
189
|
+
if isinstance(prepared, RunOutcome):
|
|
190
|
+
typer.echo(prepared.messages[0], err=True)
|
|
191
|
+
raise typer.Exit(1)
|
|
192
|
+
for message in prepared:
|
|
193
|
+
typer.echo(message)
|
|
194
|
+
failures = 0
|
|
195
|
+
for item in selected:
|
|
196
|
+
key = loaded.pack.schema.target_key(item)
|
|
197
|
+
error = _fetch_one((loaded.pack, item, test_plan, cache))
|
|
198
|
+
typer.echo(f"{key}: {'ok' if error is None else 'FAILED ' + error}")
|
|
199
|
+
failures += error is not None
|
|
200
|
+
raise typer.Exit(1 if failures else 0)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _run(
|
|
204
|
+
mode: str,
|
|
205
|
+
claim: Path,
|
|
206
|
+
target: list[str] | None,
|
|
207
|
+
out: Path,
|
|
208
|
+
workers: int | None,
|
|
209
|
+
offline: bool,
|
|
210
|
+
run_id: str | None,
|
|
211
|
+
cache_dir: Path | None,
|
|
212
|
+
stage: int | None = None,
|
|
213
|
+
promotion: Path | None = None,
|
|
214
|
+
) -> None:
|
|
215
|
+
from refute.core.run import execute_run
|
|
216
|
+
|
|
217
|
+
if workers is not None and workers < 1:
|
|
218
|
+
typer.echo("--workers must be >= 1", err=True)
|
|
219
|
+
raise typer.Exit(1)
|
|
220
|
+
outcome = execute_run(
|
|
221
|
+
claim,
|
|
222
|
+
mode=mode,
|
|
223
|
+
targets=target,
|
|
224
|
+
out_dir=out,
|
|
225
|
+
workers=workers,
|
|
226
|
+
offline=offline,
|
|
227
|
+
run_id=run_id,
|
|
228
|
+
cache_dir=cache_dir,
|
|
229
|
+
stage=stage,
|
|
230
|
+
promotion=promotion,
|
|
231
|
+
)
|
|
232
|
+
for message in outcome.messages:
|
|
233
|
+
_echo_safely(message, err=outcome.exit_code != 0)
|
|
234
|
+
if outcome.run_dir is not None:
|
|
235
|
+
_echo_safely((outcome.run_dir / "summary.md").read_text(encoding="utf-8"))
|
|
236
|
+
_echo_safely(f"dossiers written to {outcome.run_dir}")
|
|
237
|
+
raise typer.Exit(outcome.exit_code)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _echo_safely(text: str, err: bool = False) -> None:
|
|
241
|
+
"""Print without letting a broken or closed output stream fail a completed run.
|
|
242
|
+
|
|
243
|
+
In v0.1 the CLI crashed with "I/O operation on closed file" while printing the
|
|
244
|
+
summary of a run that had already written every dossier (issue #1). The exit
|
|
245
|
+
code reports whether the run completed, so printing must never change it.
|
|
246
|
+
"""
|
|
247
|
+
try:
|
|
248
|
+
typer.echo(text, err=err)
|
|
249
|
+
except (ValueError, OSError):
|
|
250
|
+
try:
|
|
251
|
+
stream = sys.__stderr__ if err else sys.__stdout__
|
|
252
|
+
if stream is not None and not stream.closed:
|
|
253
|
+
stream.write(text + chr(10))
|
|
254
|
+
stream.flush()
|
|
255
|
+
except (ValueError, OSError):
|
|
256
|
+
pass
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
TargetOpt = Annotated[
|
|
260
|
+
list[str] | None, typer.Option("--target", help="Only this target, e.g. TIC-123 (repeatable).")
|
|
261
|
+
]
|
|
262
|
+
OutOpt = Annotated[Path, typer.Option("--out", help="Output directory for dossiers.")]
|
|
263
|
+
WorkersOpt = Annotated[
|
|
264
|
+
int | None, typer.Option("--workers", help="Analysis processes (default: CPU count - 2).")
|
|
265
|
+
]
|
|
266
|
+
OfflineOpt = Annotated[bool, typer.Option("--offline", help="Use cached data only; no network.")]
|
|
267
|
+
RunIdOpt = Annotated[str | None, typer.Option("--run-id", help="Name of the run directory.")]
|
|
268
|
+
CacheOpt = Annotated[Path | None, typer.Option("--cache-dir", help="Data cache directory.")]
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
@app.command("replicate")
|
|
272
|
+
def replicate_command(
|
|
273
|
+
claim: Annotated[Path, typer.Argument(help="Path to a locked replicate claim.")],
|
|
274
|
+
target: TargetOpt = None,
|
|
275
|
+
out: OutOpt = Path("dossiers"),
|
|
276
|
+
workers: WorkersOpt = None,
|
|
277
|
+
offline: OfflineOpt = False,
|
|
278
|
+
run_id: RunIdOpt = None,
|
|
279
|
+
cache_dir: CacheOpt = None,
|
|
280
|
+
) -> None:
|
|
281
|
+
"""Re-derive a published claim from public data, then attack it."""
|
|
282
|
+
_run("replicate", claim, target, out, workers, offline, run_id, cache_dir)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
@app.command("calibrate")
|
|
286
|
+
def calibrate_command(
|
|
287
|
+
claim: Annotated[Path, typer.Option("--claim", help="Locked calibration claim.")] = Path(
|
|
288
|
+
"calibration/self_claim.yaml"
|
|
289
|
+
),
|
|
290
|
+
target: TargetOpt = None,
|
|
291
|
+
out: OutOpt = Path("dossiers"),
|
|
292
|
+
workers: WorkersOpt = None,
|
|
293
|
+
offline: OfflineOpt = False,
|
|
294
|
+
run_id: RunIdOpt = None,
|
|
295
|
+
cache_dir: CacheOpt = None,
|
|
296
|
+
) -> None:
|
|
297
|
+
"""Run the locked calibration claim on every calibration target."""
|
|
298
|
+
_run("calibrate", claim, target, out, workers, offline, run_id, cache_dir)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@app.command("discover")
|
|
302
|
+
def discover_command(
|
|
303
|
+
claim: Annotated[Path, typer.Argument(help="Path to a locked discover claim.")],
|
|
304
|
+
stage: Annotated[int, typer.Option("--stage", help="Funnel stage: 1 or 2.")],
|
|
305
|
+
promotion: Annotated[
|
|
306
|
+
Path | None,
|
|
307
|
+
typer.Option("--promotion", help="Committed promotion record (stage 2 of funnel stars)."),
|
|
308
|
+
] = None,
|
|
309
|
+
target: TargetOpt = None,
|
|
310
|
+
out: OutOpt = Path("dossiers"),
|
|
311
|
+
workers: WorkersOpt = None,
|
|
312
|
+
offline: OfflineOpt = False,
|
|
313
|
+
run_id: RunIdOpt = None,
|
|
314
|
+
cache_dir: CacheOpt = None,
|
|
315
|
+
) -> None:
|
|
316
|
+
"""Search the claim's targets for a signal, then attack it (v0.4 funnel stages)."""
|
|
317
|
+
_run("discover", claim, target, out, workers, offline, run_id, cache_dir, stage, promotion)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@app.command("check-dossier")
|
|
321
|
+
def check_dossier_command(
|
|
322
|
+
dossier: Annotated[Path, typer.Argument(help="Dossier directory to check.")],
|
|
323
|
+
against: Annotated[
|
|
324
|
+
Path | None, typer.Option("--against", help="Original dossier to compare with.")
|
|
325
|
+
] = None,
|
|
326
|
+
) -> None:
|
|
327
|
+
"""Verify a dossier's MANIFEST and optionally compare it with an original dossier."""
|
|
328
|
+
result = check_dossier(dossier, against)
|
|
329
|
+
for problem in result.integrity_problems:
|
|
330
|
+
typer.echo(f"integrity: {problem}")
|
|
331
|
+
for difference in result.differences:
|
|
332
|
+
typer.echo(f"difference: {difference}")
|
|
333
|
+
if result.seal is not None:
|
|
334
|
+
# The core and each annex are reported separately (W2.12).
|
|
335
|
+
if result.seal.core_problems:
|
|
336
|
+
typer.echo("core: NOT intact against its seal")
|
|
337
|
+
for problem in result.seal.core_problems:
|
|
338
|
+
typer.echo(f"core: {problem}")
|
|
339
|
+
else:
|
|
340
|
+
typer.echo("core: intact against its seal")
|
|
341
|
+
for problem in result.seal.annex_problems:
|
|
342
|
+
typer.echo(f"annexes: {problem}")
|
|
343
|
+
for name, problems in result.seal.annexes.items():
|
|
344
|
+
if problems:
|
|
345
|
+
typer.echo(f"annex {name}: NOT intact")
|
|
346
|
+
for problem in problems:
|
|
347
|
+
typer.echo(f"annex {name}: {problem}")
|
|
348
|
+
else:
|
|
349
|
+
typer.echo(f"annex {name}: intact against its manifest")
|
|
350
|
+
if result.ok:
|
|
351
|
+
message = "OK: manifest intact"
|
|
352
|
+
if against is not None:
|
|
353
|
+
message += "; key results reproduced"
|
|
354
|
+
typer.echo(message)
|
|
355
|
+
raise typer.Exit(0 if result.ok else 1)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
@app.command("seal")
|
|
359
|
+
def seal_command(
|
|
360
|
+
dossiers: Annotated[list[Path], typer.Argument(help="Dossier directories to seal.")],
|
|
361
|
+
) -> None:
|
|
362
|
+
"""Seal the experimental core of each dossier (SEAL.json) and print the core hashes
|
|
363
|
+
and the combined hash of the set."""
|
|
364
|
+
from refute.core.seal import SealError, combined_sha256, seal
|
|
365
|
+
|
|
366
|
+
if len({d.name for d in dossiers}) != len(dossiers):
|
|
367
|
+
typer.echo("dossier names must be unique within a set", err=True)
|
|
368
|
+
raise typer.Exit(1)
|
|
369
|
+
cores = {}
|
|
370
|
+
for dossier in dossiers:
|
|
371
|
+
try:
|
|
372
|
+
record = seal(dossier)
|
|
373
|
+
except SealError as exc:
|
|
374
|
+
typer.echo(f"{dossier}: {exc}", err=True)
|
|
375
|
+
raise typer.Exit(1) from exc
|
|
376
|
+
cores[dossier.name] = record["core_sha256"]
|
|
377
|
+
typer.echo(f"{record['core_sha256']} {dossier.name}")
|
|
378
|
+
typer.echo(f"{combined_sha256(cores)} combined ({len(cores)} dossier(s))")
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
@app.command("annex")
|
|
382
|
+
def annex_command(
|
|
383
|
+
dossier: Annotated[Path, typer.Argument(help="Sealed dossier directory.")],
|
|
384
|
+
name: Annotated[str, typer.Argument(help="Annex name (lowercase letters, digits, '-').")],
|
|
385
|
+
source: Annotated[Path, typer.Argument(help="Directory with the annex files.")],
|
|
386
|
+
) -> None:
|
|
387
|
+
"""Add an annex (annexes/<name>/ with its ANNEX.json) to a sealed, intact dossier."""
|
|
388
|
+
from refute.core.seal import SealError, add_annex
|
|
389
|
+
|
|
390
|
+
try:
|
|
391
|
+
record = add_annex(dossier, name, source)
|
|
392
|
+
except SealError as exc:
|
|
393
|
+
typer.echo(str(exc), err=True)
|
|
394
|
+
raise typer.Exit(1) from exc
|
|
395
|
+
from refute.core.hashing import sha256_file
|
|
396
|
+
from refute.core.seal import ANNEX_DIR, ANNEX_MANIFEST
|
|
397
|
+
|
|
398
|
+
manifest = sha256_file(dossier / ANNEX_DIR / name / ANNEX_MANIFEST)
|
|
399
|
+
typer.echo(f"annex {name}: {len(record['files'])} file(s), core {record['core_sha256']}")
|
|
400
|
+
# recorded publicly, like the seal: lets a later check catch a replaced manifest
|
|
401
|
+
typer.echo(f"annex {name}: {ANNEX_MANIFEST} sha256 {manifest}")
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@app.command("reply-draft")
|
|
405
|
+
def reply_draft_command(
|
|
406
|
+
dossier: Annotated[Path, typer.Argument(help="Sealed dossier directory.")],
|
|
407
|
+
contact: Annotated[
|
|
408
|
+
Path, typer.Option("--contact", help="Private contact file (JSON, under private/).")
|
|
409
|
+
],
|
|
410
|
+
out: Annotated[Path, typer.Option("--out", help="Draft to write (under private/).")],
|
|
411
|
+
) -> None:
|
|
412
|
+
"""Write an email draft to the authors from a sealed dossier. Never sends anything;
|
|
413
|
+
prints only the SHA-256 of the draft and of the address."""
|
|
414
|
+
from refute.core.reply import ReplyDraftError, write_reply_draft
|
|
415
|
+
|
|
416
|
+
try:
|
|
417
|
+
result = write_reply_draft(dossier, contact, out)
|
|
418
|
+
except ReplyDraftError as exc:
|
|
419
|
+
typer.echo(f"reply-draft refused: {exc}", err=True)
|
|
420
|
+
raise typer.Exit(1) from exc
|
|
421
|
+
typer.echo(f"draft sha256 {result.draft_sha256}")
|
|
422
|
+
typer.echo(f"address sha256 {result.address_sha256}")
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@app.command("archive")
|
|
426
|
+
def archive_command(
|
|
427
|
+
run_dir: Annotated[Path, typer.Argument(help="Run directory containing dossiers.")],
|
|
428
|
+
out: Annotated[Path | None, typer.Option("--out", help="Zip file to write.")] = None,
|
|
429
|
+
) -> None:
|
|
430
|
+
"""Write a deterministic zip of a run directory and its SHA-256."""
|
|
431
|
+
target = out or run_dir.with_name(run_dir.name + ".zip")
|
|
432
|
+
try:
|
|
433
|
+
path, digest = write_archive(run_dir, target)
|
|
434
|
+
except (FileNotFoundError, FileExistsError, ValueError) as exc:
|
|
435
|
+
typer.echo(str(exc), err=True)
|
|
436
|
+
raise typer.Exit(1) from exc
|
|
437
|
+
typer.echo(f"{digest} {path}")
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
review_app = typer.Typer(no_args_is_help=True, help="Independent reviewer reports.")
|
|
441
|
+
app.add_typer(review_app, name="review")
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
@review_app.command("attach")
|
|
445
|
+
def review_attach_command(
|
|
446
|
+
dossier: Annotated[Path, typer.Argument(help="Dossier directory.")],
|
|
447
|
+
report: Annotated[Path, typer.Argument(help="Reviewer report (Markdown).")],
|
|
448
|
+
reviewer: Annotated[str, typer.Option("--reviewer", help="Reviewer id, e.g. opus-1.")],
|
|
449
|
+
model: Annotated[str, typer.Option("--model", help="Model that wrote the report.")],
|
|
450
|
+
) -> None:
|
|
451
|
+
"""Attach a reviewer report to a dossier. The verdict and analysis files never change."""
|
|
452
|
+
try:
|
|
453
|
+
entry = attach_review(dossier, report, reviewer=reviewer, model=model)
|
|
454
|
+
except ReviewError as exc:
|
|
455
|
+
typer.echo(f"review refused: {exc}", err=True)
|
|
456
|
+
raise typer.Exit(1) from exc
|
|
457
|
+
typer.echo(f"attached {entry['file']} (sha256 {entry['sha256']})")
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def main() -> None:
|
|
461
|
+
app()
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
if __name__ == "__main__":
|
|
465
|
+
main()
|
refute/core/__init__.py
ADDED
|
File without changes
|