agent-bios 0.19.4 → 0.20.1
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.
- package/DEPENDENCIES.md +20 -5
- package/README.md +14 -19
- package/claude/agents/frontier.md +1 -1
- package/claude/guides/claude-prompting.md +475 -234
- package/claude/guides/cli-multi-model-workflow.md +8 -7
- package/claude/guides/gpt-prompting.md +319 -144
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/agents/frontier.toml +1 -1
- package/codex/agents/reviewer.toml +1 -1
- package/codex/agents/workhorse.toml +1 -1
- package/codex/guides/claude-prompting.md +475 -234
- package/codex/guides/cli-multi-model-workflow.md +8 -7
- package/codex/guides/gpt-prompting.md +319 -144
- package/codex/guides/session-distill-workflow.md +93 -43
- package/codex/guides/tooling-gotchas.md +3 -1
- package/compose/assemble.py +4 -1
- package/compose/canary.sh +8 -6
- package/compose/host_platform.py +158 -15
- package/compose/instructions-state.py +183 -41
- package/compose/instructions_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/docs/advanced-launch.md +5 -1
- package/docs/releases/0.20.0.md +102 -0
- package/docs/releases/0.20.1.md +76 -0
- package/install.sh +42 -14
- package/launch/agent-launch.py +152 -18
- package/launch/agent-launch.toml +28 -16
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- package/launch/shell_integration.py +7 -1
- package/learn/collect-learning.py +60 -9
- package/learn/migrate-learnings.py +70 -4
- package/learn/redact.py +2 -1
- package/package.json +36 -3
- package/provenance.json +1 -1
- package/session-cost.py +80 -9
- package/session-distill/coverage.json +6 -0
- package/session-distill/distill.py +2575 -0
- package/session-distill/grammar/__init__.py +0 -0
- package/session-distill/grammar/owner_lines.py +874 -0
- package/session-distill/originators.json +9 -0
- package/session-distill/packets/cross_review.md +31 -0
- package/session-distill/packets/form.md +86 -0
- package/session-distill/packets/judge.md +81 -0
- package/session-distill/packets/placement_contract.md +90 -0
- package/session-distill/packets/propose.md +124 -0
- package/session-distill/packets/read.md +57 -0
- package/session-distill/packets/reconsider.md +53 -0
- package/session-distill/packets/s7b.md +65 -0
- package/session-distill/packets/s9b.md +39 -0
- package/session-distill/packets/stitch.md +35 -0
- package/session-distill/packets/sweep.md +33 -0
- package/session-distill/runlib/__init__.py +0 -0
- package/session-distill/runlib/bound.py +1102 -0
- package/session-distill/runlib/breaker.py +467 -0
- package/session-distill/runlib/census.py +2347 -0
- package/session-distill/runlib/claims.py +420 -0
- package/session-distill/runlib/controls.py +902 -0
- package/session-distill/runlib/coverage.py +881 -0
- package/session-distill/runlib/declare.py +888 -0
- package/session-distill/runlib/delivery_evidence.py +1145 -0
- package/session-distill/runlib/derive.py +812 -0
- package/session-distill/runlib/destinations.py +3072 -0
- package/session-distill/runlib/dispatch.py +7940 -0
- package/session-distill/runlib/drift.py +1077 -0
- package/session-distill/runlib/entry.py +401 -0
- package/session-distill/runlib/evidence.py +890 -0
- package/session-distill/runlib/exposure.py +1162 -0
- package/session-distill/runlib/gate.py +2727 -0
- package/session-distill/runlib/gitread.py +79 -0
- package/session-distill/runlib/inventory.py +19624 -0
- package/session-distill/runlib/journal.py +1919 -0
- package/session-distill/runlib/ledger.py +3210 -0
- package/session-distill/runlib/ledger_compat.py +101 -0
- package/session-distill/runlib/ledger_migration.py +190 -0
- package/session-distill/runlib/lifecycle_intake.py +693 -0
- package/session-distill/runlib/lineage.py +454 -0
- package/session-distill/runlib/measures.py +249 -0
- package/session-distill/runlib/monitor.py +1180 -0
- package/session-distill/runlib/operations.py +522 -0
- package/session-distill/runlib/packet.py +838 -0
- package/session-distill/runlib/placement.py +1769 -0
- package/session-distill/runlib/projection.py +4090 -0
- package/session-distill/runlib/ranking.py +740 -0
- package/session-distill/runlib/receipts.py +200 -0
- package/session-distill/runlib/records.py +1965 -0
- package/session-distill/runlib/search.py +249 -0
- package/session-distill/runlib/sequencing.py +829 -0
- package/session-distill/runlib/sources.py +641 -0
- package/session-distill/runlib/stage_adjudicate.py +845 -0
- package/session-distill/runlib/stage_apply.py +1378 -0
- package/session-distill/runlib/stage_approvals.py +758 -0
- package/session-distill/runlib/stage_close.py +1220 -0
- package/session-distill/runlib/stage_confirm.py +929 -0
- package/session-distill/runlib/stage_delivery.py +3080 -0
- package/session-distill/runlib/stage_form.py +2576 -0
- package/session-distill/runlib/stage_judge.py +4248 -0
- package/session-distill/runlib/stage_propose.py +3307 -0
- package/session-distill/runlib/stage_read.py +5179 -0
- package/session-distill/runlib/stage_render.py +2739 -0
- package/session-distill/runlib/stage_retrieve.py +924 -0
- package/session-distill/runlib/stage_review_korean.py +1002 -0
- package/session-distill/runlib/stage_review_proposals.py +1292 -0
- package/session-distill/runlib/stagelock.py +412 -0
- package/session-distill/runlib/stop.py +1061 -0
- package/session-distill/runlib/targets.py +809 -0
- package/session-distill/runlib/usage.py +280 -0
- package/session-distill/runlib/validate.py +319 -0
- package/session-distill/runlib/views.py +4327 -0
- package/session-distill/schemas/adjudication.schema.json +35 -0
- package/session-distill/schemas/approval.schema.json +35 -0
- package/session-distill/schemas/census.schema.json +128 -0
- package/session-distill/schemas/checks.schema.json +207 -0
- package/session-distill/schemas/claim.schema.json +16 -0
- package/session-distill/schemas/confirmation.schema.json +24 -0
- package/session-distill/schemas/coverage.schema.json +66 -0
- package/session-distill/schemas/cross_review.schema.json +24 -0
- package/session-distill/schemas/event.schema.json +20 -0
- package/session-distill/schemas/evidence.schema.json +20 -0
- package/session-distill/schemas/expected_observation.schema.json +18 -0
- package/session-distill/schemas/form.schema.json +103 -0
- package/session-distill/schemas/intake.schema.json +71 -0
- package/session-distill/schemas/inventory.schema.json +872 -0
- package/session-distill/schemas/judge.schema.json +77 -0
- package/session-distill/schemas/ledger.schema.json +313 -0
- package/session-distill/schemas/observation.schema.json +16 -0
- package/session-distill/schemas/propose.schema.json +555 -0
- package/session-distill/schemas/read.schema.json +76 -0
- package/session-distill/schemas/reconsider.schema.json +122 -0
- package/session-distill/schemas/run.schema.json +150 -0
- package/session-distill/schemas/s7b.schema.json +200 -0
- package/session-distill/schemas/s9b.schema.json +28 -0
- package/session-distill/schemas/stitch.schema.json +25 -0
- package/session-distill/schemas/sweep.schema.json +25 -0
- package/session-distill/seats.json +149 -0
- package/session-distill/tables/allowed_pairs.json +257 -0
- package/session-distill/tables/controls.json +30 -0
- package/session-distill/tables/delivery_evidence.json +36 -0
- package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
- package/session-distill/tables/destinations.json +684 -0
- package/session-distill/tables/drift_layers.json +68 -0
- package/session-distill/tables/exposure_rules.json +192 -0
- package/session-distill/tables/placement_rules.json +148 -0
- package/session-distill/tables/propose_fixtures.json +154 -0
- package/session-distill/tables/ranking.json +194 -0
- package/session-distill/tables/redundancy.json +10 -0
- package/session-distill/tables/structural_rules.json +44 -0
- package/session-distill/tables/transition_fixtures.json +398 -0
- package/session-distill/tables/transitions.json +69 -0
- package/session-distill/tables/unit_outcome.json +67 -0
- package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
- package/wrappers/claude-run.sh +481 -33
- package/wrappers/claude_hermetic_evidence.py +1423 -0
- package/wrappers/codex-helm.sh +46 -15
- package/wrappers/codex-run.sh +183 -20
- package/wrappers/codex_frame_filter.py +1199 -0
- package/wrappers/codex_protocol.py +737 -0
- package/wrappers/jsonl_lines.py +65 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The record schemas every later stage keeps: claim, evidence, expected observation, event, observation.
|
|
3
|
+
|
|
4
|
+
They are `session-distill/schemas/<kind>.schema.json`, loaded through `validate.compile_schema`
|
|
5
|
+
(`check_schema`, then the schema-policy lint). Each carries `$comment: "design §X"` and its
|
|
6
|
+
`required` set is the field list of that design section: §3.3 (claim records), §5.5 (evidence
|
|
7
|
+
locators, plus `window_role` from §5.2), §7.3 (proposal content, the expected observation), §5.4 (events,
|
|
8
|
+
the field list of the implementation plan's WP-08 artifacts) and §11 (an observation instance, the same).
|
|
9
|
+
The `--self-test` holds the lists, copied once and cited, and fails naming the schema and the section when a
|
|
10
|
+
schema's field set differs; it also names the consumer of every field, so a field no later
|
|
11
|
+
stage reads cannot enter a schema unnoticed.
|
|
12
|
+
|
|
13
|
+
The two answers S3's calls return (`read.schema.json`, `stitch.schema.json`) are held to the same copies by
|
|
14
|
+
`answer_mismatch`: a reading's claim object is §3.3's, its vocabularies are the stored records', and what code
|
|
15
|
+
sets - an observation's coverage basis, an event's `unresolved`, `stitched_from` and `carried_from` - is never answered.
|
|
16
|
+
`validate_record` holds the one event rule no schema keyword can state: an event names a claim of its own unless it is
|
|
17
|
+
the line of one carried from an earlier run (`carried_from`).
|
|
18
|
+
|
|
19
|
+
claims.py --self-test
|
|
20
|
+
"""
|
|
21
|
+
import ast
|
|
22
|
+
import copy
|
|
23
|
+
import json
|
|
24
|
+
import pathlib
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
if __package__ in (None, ""): # run as a script: put session-distill/ on the import path
|
|
28
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
29
|
+
from runlib import validate
|
|
30
|
+
|
|
31
|
+
SCHEMA_DIR = pathlib.Path(__file__).resolve().parents[1] / "schemas"
|
|
32
|
+
KINDS = ("claim", "evidence", "expected_observation", "event", "observation")
|
|
33
|
+
ANSWERS = ("read", "stitch") # what S3's calls return; each holds the stored records' contracts, never its own
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def read_schema(kind, schema_dir=SCHEMA_DIR):
|
|
37
|
+
return json.loads((pathlib.Path(schema_dir) / f"{kind}.schema.json").read_text(encoding="utf-8"))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def validator_for(kind, schema_dir=SCHEMA_DIR):
|
|
41
|
+
return validate.compile_schema(read_schema(kind, schema_dir))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def validate_record(kind, record, schema_dir=SCHEMA_DIR):
|
|
45
|
+
"""Violations of one record against its kind's schema; empty when it conforms. An event's `claim_ids` may be empty
|
|
46
|
+
only on a line carried from an earlier run's pending events, which this run holds no claim of (`carried_from`): the
|
|
47
|
+
schema policy has no conditional keyword, so the rule is here, where every stored record is validated."""
|
|
48
|
+
problems = validate.validate_instance(validator_for(kind, schema_dir), record)
|
|
49
|
+
if kind == "event" and isinstance(record, dict) and record.get("claim_ids") == [] and "carried_from" not in record:
|
|
50
|
+
problems.append("claim_ids: an event of a run's own reading names at least one claim; only the line of one "
|
|
51
|
+
"carried from an earlier run (carried_from) names none")
|
|
52
|
+
return problems
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def contract_mismatch(kind, schema, section, required, together=()):
|
|
56
|
+
"""Where `schema` departs from the field list `section` of the design gives.
|
|
57
|
+
|
|
58
|
+
`required` are the fields every record carries; `together` are fields the section makes
|
|
59
|
+
conditional that must be present as a group or not at all."""
|
|
60
|
+
errors = []
|
|
61
|
+
if not str(schema.get("$comment", "")).startswith(f"design {section}"):
|
|
62
|
+
errors.append(f"CONTRACT_MISMATCH {kind} (design {section}): $comment does not cite the section")
|
|
63
|
+
want, have = set(required), set(schema.get("required", []))
|
|
64
|
+
for verb, fields in (("lacks", sorted(want - have)), ("adds", sorted(have - want))):
|
|
65
|
+
if fields:
|
|
66
|
+
errors.append(f"CONTRACT_MISMATCH {kind} (design {section}): required {verb} {fields}")
|
|
67
|
+
declared = set(schema.get("properties", {}))
|
|
68
|
+
for verb, fields in (("lacks", sorted((want | set(together)) - declared)),
|
|
69
|
+
("adds", sorted(declared - want - set(together)))):
|
|
70
|
+
if fields:
|
|
71
|
+
errors.append(f"CONTRACT_MISMATCH {kind} (design {section}): properties {verb} {fields}")
|
|
72
|
+
group = {name: sorted(set(together) - {name}) for name in together}
|
|
73
|
+
if schema.get("dependentRequired", {}) != group:
|
|
74
|
+
errors.append(f"CONTRACT_MISMATCH {kind} (design {section}): dependentRequired is not {group}")
|
|
75
|
+
return errors
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def unconsumed_fields(schema, consumers):
|
|
79
|
+
"""Properties of `schema` that name no consumer: the inert-field rule, as a check."""
|
|
80
|
+
return sorted(set(schema.get("properties", {})) - set(consumers))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def returned_literals(source, function):
|
|
84
|
+
"""The string constants `function` of `source` returns: the vocabulary a predicate can answer in."""
|
|
85
|
+
tree = ast.parse(source)
|
|
86
|
+
for node in tree.body:
|
|
87
|
+
if isinstance(node, ast.FunctionDef) and node.name == function:
|
|
88
|
+
return sorted({n.value.value for n in ast.walk(node) if isinstance(n, ast.Return)
|
|
89
|
+
and isinstance(n.value, ast.Constant) and isinstance(n.value.value, str)})
|
|
90
|
+
return []
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def answer_mismatch(answers, stored, claim_contract, basis, basis_returns, decisions):
|
|
94
|
+
"""Where S3's two answer schemas depart from the records they become (WP-08 done-when 8).
|
|
95
|
+
|
|
96
|
+
`answers` and `stored` map a kind to its schema; `claim_contract` is §3.3's field list, `basis` §5.4's
|
|
97
|
+
three words, `basis_returns` what `views.coverage_basis` can return, `decisions` `views.DECISIONS`. A
|
|
98
|
+
reading's claim object is §3.3's; an observation's exposure and verdict are the stored instance's and its
|
|
99
|
+
basis is never answered (code sets it over the scope, §5.4); a window's event is the stored event without
|
|
100
|
+
`unresolved` or `stitched_from` (the stitch call's), and a stitch answers resolved or unresolved, never
|
|
101
|
+
pending."""
|
|
102
|
+
errors = []
|
|
103
|
+
defs = answers["read"].get("$defs", {})
|
|
104
|
+
errors += contract_mismatch("read.claim", defs.get("claim", {}), "§3.3", claim_contract)
|
|
105
|
+
|
|
106
|
+
def enum(schema, field):
|
|
107
|
+
return sorted((schema.get("properties", {}).get(field) or {}).get("enum", []))
|
|
108
|
+
|
|
109
|
+
def differ(name, section, have, want):
|
|
110
|
+
if sorted(have) != sorted(want):
|
|
111
|
+
errors.append(f"CONTRACT_MISMATCH {name} (design {section}): {sorted(have)} is not {sorted(want)}")
|
|
112
|
+
|
|
113
|
+
observation, event = stored["observation"], stored["event"]
|
|
114
|
+
differ("observation.basis", "§5.4", enum(observation, "basis"), basis)
|
|
115
|
+
differ("views.coverage_basis returns", "§5.4", basis_returns, basis)
|
|
116
|
+
answered = defs.get("observation", {})
|
|
117
|
+
differ("read.observation fields", "§11", answered.get("properties", {}),
|
|
118
|
+
set(observation.get("properties", {})) - {"basis"})
|
|
119
|
+
for field in ("exposure", "verdict"):
|
|
120
|
+
differ(f"read.observation.{field}", "§11", enum(answered, field), enum(observation, field))
|
|
121
|
+
window_event = defs.get("event", {})
|
|
122
|
+
differ("read.event fields", "§5.4", window_event.get("properties", {}),
|
|
123
|
+
set(event.get("properties", {})) - {"stitched_from", "carried_from"})
|
|
124
|
+
differ("read.event.outcome", "§5.4", enum(window_event, "outcome"), set(enum(event, "outcome")) - {"unresolved"})
|
|
125
|
+
resolution = answers["stitch"].get("$defs", {}).get("resolution", {})
|
|
126
|
+
differ("stitch.resolution.outcome", "§5.4", enum(resolution, "outcome"), set(enum(event, "outcome")) - {"pending"})
|
|
127
|
+
differ("read.decision.decision", "§5.4", enum(defs.get("decision", {}), "decision"), decisions)
|
|
128
|
+
return errors
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def self_test():
|
|
132
|
+
# The field lists of the design sections, copied here once (WP-01 done-when 5). A second
|
|
133
|
+
# copy anywhere else is a second authority; the cross-provider review of this module
|
|
134
|
+
# compares these three against the design text.
|
|
135
|
+
contract = {
|
|
136
|
+
"claim": ("§3.3", ("claim_id", "fact", "interpretation", "uncertainty", "evidence_ids", "call_id"), ()),
|
|
137
|
+
# §5.5's list, and `window_role` from §5.2 ("every evidence record carries window_role"; plan WP-06 done-when 7)
|
|
138
|
+
"evidence": ("§5.5", ("evidence_id", "source_copy", "version_sha", "line", "json_pointer",
|
|
139
|
+
"char_span", "redaction_version", "redacted_text", "window_role"), ()),
|
|
140
|
+
"expected_observation": ("§7.3", ("occasion_criteria", "exposure_rule", "expected_behavior",
|
|
141
|
+
"retrieval_terms", "expiry"), ("counter", "threshold")),
|
|
142
|
+
# §5.4 names events and their outcomes; the field list is the implementation plan's WP-08 artifacts, and
|
|
143
|
+
# carried_from, a group of one, is the coverage origin a carried event's line names (design record
|
|
144
|
+
# 2026-11-04T0026--ed87f66, the lead's answer on the stitch's carried events)
|
|
145
|
+
"event": ("§5.4", ("event_id", "kind", "at_record", "claim_ids", "outcome", "description", "stitched_from"),
|
|
146
|
+
("carried_from",)),
|
|
147
|
+
# §11's instance, with §5.4's basis; the field list is the implementation plan's WP-08 artifacts
|
|
148
|
+
"observation": ("§11", ("expected_id", "occasion_locator", "exposure", "verdict", "basis", "evidence_ids"), ()),
|
|
149
|
+
}
|
|
150
|
+
# §5.4's three coverage bases, in its checking order (WP-08 done-when 8)
|
|
151
|
+
basis = ("incomplete", "view", "source")
|
|
152
|
+
# Every field and the work package that reads it (the inert-field rule): a field enters a
|
|
153
|
+
# schema when a later stage consumes it, and this table is where that is said.
|
|
154
|
+
consumers = {
|
|
155
|
+
"claim": {
|
|
156
|
+
"claim_id": "WP-08: S3 writes claims/<transcript>.jsonl; events and WP-09 candidates refer to a claim by it",
|
|
157
|
+
"fact": "WP-21 done-when 13: render and ledger project it unchanged",
|
|
158
|
+
"interpretation": "WP-21 done-when 13: render and ledger project it unchanged",
|
|
159
|
+
"uncertainty": "WP-21 done-when 13: render and ledger project it unchanged",
|
|
160
|
+
"evidence_ids": "WP-08 done-when 1: every claim's evidence records resolve (quote fidelity)",
|
|
161
|
+
"call_id": "WP-02 gate: cross-record integrity, design §3.2 item 4",
|
|
162
|
+
},
|
|
163
|
+
"evidence": {
|
|
164
|
+
"evidence_id": "WP-08: a claim's evidence_ids resolve to it",
|
|
165
|
+
"source_copy": "WP-06 done-when 1 (locator resolves to the immutable copy); WP-20 render (openable path)",
|
|
166
|
+
"version_sha": "WP-06 done-when 1: SOURCE_TAMPERED when the copy's hash differs",
|
|
167
|
+
"line": "WP-20 render: the openable line in the source copy (design §5.5)",
|
|
168
|
+
"json_pointer": "WP-06 done-when 1: locates the content block the projection is taken from",
|
|
169
|
+
"char_span": "WP-06 done-when 1: the span of the block the quote covers",
|
|
170
|
+
"redaction_version": "WP-06 done-when 1: REDACTION_VERSION_MISMATCH",
|
|
171
|
+
"redacted_text": "WP-08 done-when 1: QUOTE_MISMATCH when a model retypes the quote",
|
|
172
|
+
"window_role": "WP-08 done-when 5 and WP-10: only in_window evidence counts toward occasions and recurrence (design §5.2)",
|
|
173
|
+
},
|
|
174
|
+
"expected_observation": {
|
|
175
|
+
"occasion_criteria": "WP-08 done-when 5: reading finds the occasions where it holds",
|
|
176
|
+
"exposure_rule": "WP-21: the table-driven exposure predicate of design §11",
|
|
177
|
+
"expected_behavior": "WP-08 done-when 5: each occasion is judged observed or not observed against it",
|
|
178
|
+
"retrieval_terms": "WP-06: the full-source search; WP-08: the expansion it forces",
|
|
179
|
+
"expiry": "WP-09: lifecycle intake of incubates whose expiry is on or before the window end",
|
|
180
|
+
"counter": "WP-21: the plain-asks adapter of design §11",
|
|
181
|
+
"threshold": "WP-21: the plain-asks adapter resolves by it (design §11)",
|
|
182
|
+
},
|
|
183
|
+
"event": {
|
|
184
|
+
"event_id": "WP-08 done-when 3: the stitch call answers for it by id; coverage.json's pending_events carries it (WP-05)",
|
|
185
|
+
"kind": "WP-09: S4 forms candidates with set accounting over events (design §4)",
|
|
186
|
+
"at_record": "WP-08: an event belongs to the window of its first record (design §5.2); a pending one forces expansion (§5.4)",
|
|
187
|
+
"claim_ids": "WP-08 done-when 3: the stitch call receives the claims; WP-09 S4",
|
|
188
|
+
"outcome": "WP-08 done-when 3: pending until the unit's stitch, which appends resolved or unresolved; an unresolved one is handed on to coverage.json's pending_events",
|
|
189
|
+
"description": "WP-08 done-when 3: the stitch call receives it; WP-20 render",
|
|
190
|
+
"stitched_from": "WP-08 done-when 3: a stitched resolution names the claims it was resolved with",
|
|
191
|
+
"carried_from": "WP-08 done-when 4: a carried event's line names the window and record coverage carried it from; WP-09 S4",
|
|
192
|
+
},
|
|
193
|
+
"observation": {
|
|
194
|
+
"expected_id": "WP-08 measures.derive_resolution: the window resolution is derived per expected observation (design §11)",
|
|
195
|
+
"occasion_locator": "WP-20 render: where the occasion is",
|
|
196
|
+
"exposure": "WP-08 measures.derive_resolution: an exposure_unknown occasion leaves the resolution pending (design §11)",
|
|
197
|
+
"verdict": "WP-08 measures.derive_resolution: not observed / observed (design §11)",
|
|
198
|
+
"basis": "WP-08 measures.derive_resolution: an absence needs basis source (design §5.4, §11)",
|
|
199
|
+
"evidence_ids": "WP-08 done-when 5: each instance is judged with evidence ids; WP-20 render",
|
|
200
|
+
},
|
|
201
|
+
}
|
|
202
|
+
valid = {
|
|
203
|
+
"claim": {"claim_id": "c-1", "fact": "The owner asked for the plain version twice.",
|
|
204
|
+
"interpretation": "The first explanation was too technical.",
|
|
205
|
+
"uncertainty": "Two occurrences in one session.", "evidence_ids": ["e-1", "e-2"],
|
|
206
|
+
"call_id": "r1/S3/t1/1"},
|
|
207
|
+
"evidence": {"evidence_id": "e-1", "source_copy": "sources/" + "ab" * 32 + ".jsonl",
|
|
208
|
+
"version_sha": "ab" * 32, "line": 12, "json_pointer": "/message/content/0/text",
|
|
209
|
+
"char_span": [0, 40], "redaction_version": "r1", "redacted_text": "show me the plain version",
|
|
210
|
+
"window_role": "in_window"},
|
|
211
|
+
"expected_observation": {"occasion_criteria": "the owner asks for an explanation",
|
|
212
|
+
"exposure_rule": "the unit was delivered before the ask",
|
|
213
|
+
"expected_behavior": "no second request for the plain version",
|
|
214
|
+
"retrieval_terms": ["plain version", "explain"], "expiry": "2026-12-31"},
|
|
215
|
+
"event": {"event_id": "v-1", "kind": "request", "at_record": "4/message/content", "claim_ids": ["c-1"],
|
|
216
|
+
"outcome": "pending", "description": "The owner asked for a rerun; its result is not in this window.",
|
|
217
|
+
"stitched_from": []},
|
|
218
|
+
"observation": {"expected_id": "x-1", "occasion_locator": "12/message/content", "exposure": "eligible",
|
|
219
|
+
"verdict": "observed", "basis": "view", "evidence_ids": ["e-1"]},
|
|
220
|
+
}
|
|
221
|
+
# one rejected mutation per row: (kind, name, mutate(record), a fragment the violation must carry)
|
|
222
|
+
def drop(field):
|
|
223
|
+
return lambda r: {k: v for k, v in r.items() if k != field}
|
|
224
|
+
|
|
225
|
+
def put(field, value):
|
|
226
|
+
return lambda r: {**r, field: value}
|
|
227
|
+
|
|
228
|
+
mutations = [(kind, f"drop required {field}", drop(field), f"'{field}' is a required property")
|
|
229
|
+
for kind, (_s, fields, _t) in contract.items() for field in fields]
|
|
230
|
+
mutations += [
|
|
231
|
+
("claim", "unknown field", put("revises", "c-0"), "Additional properties"),
|
|
232
|
+
("claim", "empty fact", put("fact", ""), "fact:"),
|
|
233
|
+
("claim", "evidence_ids repeat an id", put("evidence_ids", ["e-1", "e-1"]), "evidence_ids:"),
|
|
234
|
+
("evidence", "version_sha not a sha256", put("version_sha", "abc"), "version_sha:"),
|
|
235
|
+
("evidence", "line as a string", put("line", "12"), "line:"),
|
|
236
|
+
("evidence", "line below 1", put("line", 0), "line:"),
|
|
237
|
+
("evidence", "char_span of three numbers", put("char_span", [0, 1, 2]), "char_span:"),
|
|
238
|
+
("evidence", "window_role outside the three", put("window_role", "elsewhere"), "window_role:"),
|
|
239
|
+
("evidence", "backlog without its window", put("window_role", "backlog()"), "window_role:"),
|
|
240
|
+
("evidence", "json_pointer without a leading slash", put("json_pointer", "message/content"), "json_pointer:"),
|
|
241
|
+
("expected_observation", "retrieval_terms empty", put("retrieval_terms", []), "retrieval_terms:"),
|
|
242
|
+
("expected_observation", "counter without threshold", put("counter", "plain-explanation asks"), "'threshold' is a dependency of"),
|
|
243
|
+
("expected_observation", "threshold without counter", put("threshold", 0.5), "'counter' is a dependency of"),
|
|
244
|
+
("event", "outcome outside the three", put("outcome", "open"), "outcome:"),
|
|
245
|
+
("event", "an event no claim describes", put("claim_ids", []), "claim_ids:"),
|
|
246
|
+
("observation", "a fourth coverage basis", put("basis", "partial"), "basis:"),
|
|
247
|
+
("observation", "exposure outside §11's two", put("exposure", "exposed"), "exposure:"),
|
|
248
|
+
("observation", "verdict outside §11's two", put("verdict", "maybe"), "verdict:"),
|
|
249
|
+
("observation", "an instance judged without evidence", put("evidence_ids", []), "evidence_ids:"),
|
|
250
|
+
]
|
|
251
|
+
|
|
252
|
+
failures = []
|
|
253
|
+
for kind in KINDS:
|
|
254
|
+
section, fields, together = contract[kind]
|
|
255
|
+
try: # positive controls first: the schema loads, matches its section, and takes a valid record
|
|
256
|
+
schema = read_schema(kind)
|
|
257
|
+
validator_for(kind)
|
|
258
|
+
except Exception as exc:
|
|
259
|
+
failures.append(f"positive control: {kind} schema did not load: {exc!r}")
|
|
260
|
+
continue
|
|
261
|
+
for problem in contract_mismatch(kind, schema, section, fields, together):
|
|
262
|
+
failures.append(f"positive control: {problem}")
|
|
263
|
+
for field in unconsumed_fields(schema, consumers[kind]):
|
|
264
|
+
failures.append(f"positive control: {kind}.{field} names no consumer")
|
|
265
|
+
if sorted(set(consumers[kind]) - set(schema["properties"])):
|
|
266
|
+
failures.append(f"positive control: {kind} consumers name a field the schema lacks")
|
|
267
|
+
if validate_record(kind, valid[kind]):
|
|
268
|
+
failures.append(f"positive control: the valid {kind} record was rejected: {validate_record(kind, valid[kind])}")
|
|
269
|
+
carried = {**valid["event"], "claim_ids": [], "outcome": "resolved", "stitched_from": ["c-9"],
|
|
270
|
+
"carried_from": {"window": "2026-10-01T00:00:00/2026-10-08T00:00:00@UTC", "first_record": 9}}
|
|
271
|
+
if validate_record("event", carried):
|
|
272
|
+
failures.append(f"positive control: a carried event's line naming no claim of its own was rejected: {validate_record('event', carried)}")
|
|
273
|
+
full = {**valid["expected_observation"], "counter": "plain-explanation asks", "threshold": 0.5}
|
|
274
|
+
if validate_record("expected_observation", full):
|
|
275
|
+
failures.append("positive control: an expected observation with counter and threshold was rejected")
|
|
276
|
+
|
|
277
|
+
for kind, name, mutate, fragment in mutations:
|
|
278
|
+
found = validate_record(kind, mutate(valid[kind]))
|
|
279
|
+
if not found:
|
|
280
|
+
failures.append(f"mutation NOT caught: {kind}: {name}")
|
|
281
|
+
elif not any(fragment in line for line in found):
|
|
282
|
+
failures.append(f"mutation caught for the wrong reason: {kind}: {name} -> {found}")
|
|
283
|
+
|
|
284
|
+
# the contract check itself: a schema that departs from its section is named with both
|
|
285
|
+
for kind in KINDS:
|
|
286
|
+
section, fields, together = contract[kind]
|
|
287
|
+
base = read_schema(kind)
|
|
288
|
+
extra = copy.deepcopy(base)
|
|
289
|
+
extra["required"].append("extra_field")
|
|
290
|
+
extra["properties"]["extra_field"] = {"type": "string"}
|
|
291
|
+
lacking = copy.deepcopy(base)
|
|
292
|
+
lacking["required"].remove(fields[0])
|
|
293
|
+
recited = copy.deepcopy(base)
|
|
294
|
+
recited["$comment"] = "design §0.0"
|
|
295
|
+
for label, schema, fragment in (
|
|
296
|
+
("one field added to required", extra, "required adds ['extra_field']"),
|
|
297
|
+
("one field removed from required", lacking, f"required lacks ['{fields[0]}']"),
|
|
298
|
+
("citation of another section", recited, "$comment does not cite the section")):
|
|
299
|
+
found = contract_mismatch(kind, schema, section, fields, together)
|
|
300
|
+
if not any(f"CONTRACT_MISMATCH {kind} (design {section})" in line and fragment in line for line in found):
|
|
301
|
+
failures.append(f"contract control not named: {kind}: {label} -> {found}")
|
|
302
|
+
if unconsumed_fields(extra, consumers[kind]) != ["extra_field"]:
|
|
303
|
+
failures.append(f"inert-field control: {kind}: a property with no consumer was not reported")
|
|
304
|
+
unlisted = copy.deepcopy(base) # a property that is not required is still a field of the record
|
|
305
|
+
unlisted["properties"]["extra_field"] = {"type": "string"}
|
|
306
|
+
unlinked = copy.deepcopy(base)
|
|
307
|
+
unlinked["dependentRequired"] = {"extra_field": ["extra_field"]}
|
|
308
|
+
for label, schema, fragment in (("a property added without being required", unlisted, "properties adds ['extra_field']"),
|
|
309
|
+
("a property removed with its requirement kept",
|
|
310
|
+
{**base, "properties": {k: v for k, v in base["properties"].items() if k != fields[0]}},
|
|
311
|
+
f"properties lacks ['{fields[0]}']"),
|
|
312
|
+
("dependentRequired changed", unlinked, "dependentRequired is not")):
|
|
313
|
+
found = contract_mismatch(kind, schema, section, fields, together)
|
|
314
|
+
if not any(f"CONTRACT_MISMATCH {kind} (design {section})" in line and fragment in line for line in found):
|
|
315
|
+
failures.append(f"contract control not named: {kind}: {label} -> {found}")
|
|
316
|
+
open_schema = copy.deepcopy(read_schema("claim"))
|
|
317
|
+
del open_schema["additionalProperties"]
|
|
318
|
+
try:
|
|
319
|
+
validate.compile_schema(open_schema)
|
|
320
|
+
failures.append("a claim schema without additionalProperties: false was accepted")
|
|
321
|
+
except validate.SchemaPolicyError:
|
|
322
|
+
pass
|
|
323
|
+
|
|
324
|
+
# S3's answers (WP-08 done-when 8): the two schemas the model answers in, held to the stored records' copies.
|
|
325
|
+
# `views` is read for its basis predicate and its decision vocabulary only, inside the test: the schemas
|
|
326
|
+
# are leaves, and nothing at import time may make them depend on the stage that cuts windows.
|
|
327
|
+
from runlib import views
|
|
328
|
+
answers = {}
|
|
329
|
+
for kind in ANSWERS:
|
|
330
|
+
try:
|
|
331
|
+
answers[kind] = read_schema(kind)
|
|
332
|
+
validator_for(kind)
|
|
333
|
+
except Exception as exc:
|
|
334
|
+
failures.append(f"positive control: the {kind} answer schema did not load: {exc!r}")
|
|
335
|
+
stored = {kind: read_schema(kind) for kind in ("event", "observation")}
|
|
336
|
+
basis_returns = returned_literals(pathlib.Path(views.__file__).read_text(encoding="utf-8"), "coverage_basis")
|
|
337
|
+
|
|
338
|
+
def answer_problems(answers=answers, stored=stored, returns=basis_returns):
|
|
339
|
+
return answer_mismatch(answers, stored, contract["claim"][1], basis, returns, views.DECISIONS)
|
|
340
|
+
|
|
341
|
+
answer_mutations = []
|
|
342
|
+
if len(answers) == len(ANSWERS):
|
|
343
|
+
for problem in answer_problems():
|
|
344
|
+
failures.append(f"positive control: {problem}")
|
|
345
|
+
if not basis_returns:
|
|
346
|
+
failures.append("positive control: views.coverage_basis returns no literal the check could read")
|
|
347
|
+
|
|
348
|
+
def planted(kind, edit, schemas):
|
|
349
|
+
copied = copy.deepcopy(schemas)
|
|
350
|
+
edit(copied[kind])
|
|
351
|
+
return copied
|
|
352
|
+
|
|
353
|
+
claim_of = lambda s: s["$defs"]["claim"] # noqa: E731
|
|
354
|
+
answer_mutations = [
|
|
355
|
+
("a fourth coverage basis in the stored instance", lambda: answer_problems(
|
|
356
|
+
stored=planted("observation", lambda s: s["properties"]["basis"]["enum"].append("partial"), stored)),
|
|
357
|
+
"CONTRACT_MISMATCH observation.basis (design §5.4)"),
|
|
358
|
+
("a fourth basis the predicate can return", lambda: answer_problems(returns=sorted(basis_returns + ["partial"])),
|
|
359
|
+
"CONTRACT_MISMATCH views.coverage_basis returns (design §5.4)"),
|
|
360
|
+
("a claim field added to the reading's claim object", lambda: answer_problems(
|
|
361
|
+
answers=planted("read", lambda s: (claim_of(s)["required"].append("revises"),
|
|
362
|
+
claim_of(s)["properties"].update(revises={"type": "string"})), answers)),
|
|
363
|
+
"CONTRACT_MISMATCH read.claim (design §3.3): required adds ['revises']"),
|
|
364
|
+
("a §3.3 field dropped from the reading's claim object", lambda: answer_problems(
|
|
365
|
+
answers=planted("read", lambda s: (claim_of(s)["required"].remove("uncertainty"),
|
|
366
|
+
claim_of(s)["properties"].pop("uncertainty")), answers)),
|
|
367
|
+
"CONTRACT_MISMATCH read.claim (design §3.3): required lacks ['uncertainty']"),
|
|
368
|
+
("the model answering the coverage basis", lambda: answer_problems(
|
|
369
|
+
answers=planted("read", lambda s: s["$defs"]["observation"]["properties"].update(
|
|
370
|
+
basis={"type": "string", "enum": list(basis)}), answers)),
|
|
371
|
+
"CONTRACT_MISMATCH read.observation fields (design §11)"),
|
|
372
|
+
("a window answering unresolved", lambda: answer_problems(
|
|
373
|
+
answers=planted("read", lambda s: s["$defs"]["event"]["properties"]["outcome"]["enum"].append("unresolved"),
|
|
374
|
+
answers)),
|
|
375
|
+
"CONTRACT_MISMATCH read.event.outcome (design §5.4)"),
|
|
376
|
+
("a stitch answering pending", lambda: answer_problems(
|
|
377
|
+
answers=planted("stitch", lambda s: s["$defs"]["resolution"]["properties"]["outcome"]["enum"].append("pending"),
|
|
378
|
+
answers)),
|
|
379
|
+
"CONTRACT_MISMATCH stitch.resolution.outcome (design §5.4)"),
|
|
380
|
+
("an exposure the stored instance cannot hold", lambda: answer_problems(
|
|
381
|
+
answers=planted("read", lambda s: s["$defs"]["observation"]["properties"]["exposure"]["enum"].append("exposed"),
|
|
382
|
+
answers)),
|
|
383
|
+
"CONTRACT_MISMATCH read.observation.exposure (design §11)"),
|
|
384
|
+
# X review of WP-08 r1 #3: each comparison has a departure only it names
|
|
385
|
+
("a window answering what the stitch records (stitched_from)", lambda: answer_problems(
|
|
386
|
+
answers=planted("read", lambda s: s["$defs"]["event"]["properties"].update(
|
|
387
|
+
stitched_from={"type": "array", "items": {"type": "string"}}), answers)),
|
|
388
|
+
"CONTRACT_MISMATCH read.event fields (design §5.4)"),
|
|
389
|
+
("a verdict the stored instance cannot hold", lambda: answer_problems(
|
|
390
|
+
answers=planted("read", lambda s: s["$defs"]["observation"]["properties"]["verdict"]["enum"].append("unclear"),
|
|
391
|
+
answers)),
|
|
392
|
+
"CONTRACT_MISMATCH read.observation.verdict (design §11)"),
|
|
393
|
+
("a decision other than expand or skip", lambda: answer_problems(
|
|
394
|
+
answers=planted("read", lambda s: s["$defs"]["decision"]["properties"]["decision"]["enum"].append("defer"),
|
|
395
|
+
answers)),
|
|
396
|
+
"CONTRACT_MISMATCH read.decision.decision (design §5.4)"),
|
|
397
|
+
]
|
|
398
|
+
for label, problems, fragment in answer_mutations:
|
|
399
|
+
found = problems()
|
|
400
|
+
if not any(fragment in line for line in found):
|
|
401
|
+
failures.append(f"answer contract control not named: {label} -> {found}")
|
|
402
|
+
planted_source = "def coverage_basis(scope):\n if scope:\n return 'incomplete'\n return 'partial'\n"
|
|
403
|
+
if returned_literals(planted_source, "coverage_basis") != ["incomplete", "partial"]:
|
|
404
|
+
failures.append("returned_literals control: a planted predicate's literals were not read")
|
|
405
|
+
|
|
406
|
+
for failure in failures:
|
|
407
|
+
print(f"claims --self-test [FAIL] {failure}")
|
|
408
|
+
if failures:
|
|
409
|
+
return 1
|
|
410
|
+
print(f"claims --self-test: OK ({len(KINDS)} schemas match §3.3, §5.5, §7.3, §5.4, §11; "
|
|
411
|
+
f"{sum(len(c) for c in consumers.values())} fields each name a consumer; "
|
|
412
|
+
f"{len(mutations)} record mutations and {6 * len(KINDS)} schema mutations rejected by name; "
|
|
413
|
+
f"{len(ANSWERS)} answer schemas hold the stored contracts, {len(answer_mutations)} departures named)")
|
|
414
|
+
return 0
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
if __name__ == "__main__":
|
|
418
|
+
if "--self-test" not in sys.argv[1:]:
|
|
419
|
+
sys.exit("usage: claims.py --self-test")
|
|
420
|
+
sys.exit(self_test())
|