hypgraph 0.7.13__tar.gz → 0.7.14__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.
- {hypgraph-0.7.13 → hypgraph-0.7.14}/CHANGELOG.md +19 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/PKG-INFO +1 -1
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/PLAN.md +1 -1
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/RELEASE-READINESS.md +10 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/spec.md +16 -3
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/verification.md +8 -1
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/__init__.py +1 -1
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/bundle.py +49 -14
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/cli.py +14 -2
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/store.py +4 -1
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/hypgraph.js +47 -11
- hypgraph-0.7.14/tests/test_verify_trust.py +179 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/.gitignore +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/AGENTS.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/CITATION.cff +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/DISCLAIMER.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/LICENSE +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/NOTICE +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/README.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/decisions/ADR-001-token-bound-authors.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/decisions/ADR-002-governance-profiles.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/profile-workflows-plan.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/review-2026-10-24.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/site-plan.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/ui-plan.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/README.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/knowledge.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/optimization.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/scientific.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/software.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/docs/workflows/trading.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/examples/frameworks/README.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/pyproject.toml +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/__main__.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/blind.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/checks.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/coord.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/demos/__init__.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/demos/broad_street.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/derive.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/graph.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/language.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/mcp.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/plan.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/policy.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/profiles.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/references.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/refusals.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/report_check.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/schema.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/server.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/skill/SKILL.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/stats.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/__init__.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/atlas.css +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/atlas.js +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/hypgraph.css +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/hypgraph.svg +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/index.html +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/vendor/LICENSES.md +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/vendor/cose-base.js +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/vendor/cytoscape-fcose.js +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/vendor/cytoscape.min.js +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/ui/vendor/layout-base.js +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/src/hypgraph/workflow.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_accept_work_kind.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_anchoring.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_blind.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_blind_oracles.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_bound_support.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_bundle_telemetry.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_cancel_releases_lease.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_cited_and_failed_support.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_coord.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_d10.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_engine.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_engine_fixes.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_framework_examples.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_incremental.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_link_translate.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_log_and_check.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_measure_questions.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_opposed_answers.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_option_lead.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_order_detail.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_profiles.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_profiles_041.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_questions_not_assertions.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_references.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_refusal_friction.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_refusal_results.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_refusals.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_relation_words.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_report_answers.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_rerunnable.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_restates_scale.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_server_auth.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_server_hosts.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_shape_refusals.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_stats_not_backtests.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_stats_values.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_surfaces.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_telemetry_stream.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_trust_boundary.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_ui_app.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_ui_engine.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_uncorrected_effect.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_unnamed_inputs.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_verify_complete.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_versions_not_figures.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_vocabulary_friction.py +0 -0
- {hypgraph-0.7.13 → hypgraph-0.7.14}/tests/test_workflows.py +0 -0
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.14 — 2026-10-31: the verifier trusts its caller's policy, and derived screens say they are as exported
|
|
4
|
+
|
|
5
|
+
- **The verifier trusts its caller's policy, not the bundle's.** A re-audit of 0.7.13 found that the bundle and
|
|
6
|
+
browser verifiers took the importer's name from the bundle's `policy`, which the chain doesn't cover. Older events
|
|
7
|
+
don't vouch for the author of a node the importer wrote, so naming a historical writer the importer let an edited
|
|
8
|
+
bundle re-attribute that writer's nodes, and it still verified against the published head. Now the default
|
|
9
|
+
importer is used unless the caller supplies a policy (`hypgraph verify --policy FILE` / `--importer NAME`,
|
|
10
|
+
`verify_bundle(b, policy=…)`, `verifyBundle(b, head, {policy})`); every supplied field must match the bundle's, and a
|
|
11
|
+
different stated importer is reported. `--standing` derives under the supplied policy and names the fields it took
|
|
12
|
+
from the bundle on trust (`tests/test_verify_trust.py`).
|
|
13
|
+
- **Coverage is stated at the top.** Every result says `coverage: complete` or `partial` (fields no event vouched
|
|
14
|
+
for, or redacted events); the CLI prints it, and the explorer shows a *partial coverage* badge.
|
|
15
|
+
- **Reports, stages and work orders are labelled as exported.** The explorer's Overview, Pipeline, Evidence, Work
|
|
16
|
+
orders and Report screens say, for a bundle, that what they show is as exported and not verified, and how to
|
|
17
|
+
re-derive it; the Report's subtitle no longer says its interpretation is checked. `dev/ui_smoke.py` fails a bundle
|
|
18
|
+
view that drops the label.
|
|
19
|
+
- **Sequence numbers must run 1 to n**, in bundles and graph files: they aren't hashed, so a relabelled or gapped log
|
|
20
|
+
now fails.
|
|
21
|
+
|
|
3
22
|
## 0.7.13 — 2026-10-31: verification checks every row, and examples for agent frameworks
|
|
4
23
|
|
|
5
24
|
- **Verification checks every row, both ways.** A pre-launch audit found that `verify_bundle`, `verify_file` and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hypgraph
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.14
|
|
4
4
|
Summary: The evidence layer for AI research agents: a hash-chained research record that checks every claim as it is written and derives how well each is known.
|
|
5
5
|
Project-URL: Homepage, https://hypgraph.com
|
|
6
6
|
Project-URL: Documentation, https://hypgraph.com/engineers/
|
|
@@ -109,7 +109,7 @@ claim's derived standing.
|
|
|
109
109
|
Multi-writer sync between graphs (bundles cover sharing), authentication (the host's job; the HTTP server binds to
|
|
110
110
|
loopback and is read-only unless started with `--writable`), and a hosted service.
|
|
111
111
|
|
|
112
|
-
## Status at 0.7.
|
|
112
|
+
## Status at 0.7.14 (2026-10-31)
|
|
113
113
|
|
|
114
114
|
All seven phases are done: the library, bundles, the server and UI, the MCP server, the website, Pegasus running on
|
|
115
115
|
the package, and releases to PyPI from tags with trusted publishing. What came after the plan, by release, is in
|
|
@@ -16,6 +16,16 @@ was taken from a changelog without being checked against the code.*
|
|
|
16
16
|
> hypswarm, hypmesh and hypdmz pass on it. Released as 0.7.13. The required-checks setting (condition 3 below) is
|
|
17
17
|
> still open, for the operator.
|
|
18
18
|
|
|
19
|
+
> **Re-audit of 0.7.13 (2026-10-31).** Confirmed: the deletion and field defects are closed. Two gaps remained, both
|
|
20
|
+
> reproduced and both fixed for 0.7.14: the verifier took the importer from the bundle's own (unhashed) policy, which
|
|
21
|
+
> let an edited legacy bundle re-attribute a historical writer's nodes against the published head; and reports,
|
|
22
|
+
> stages and work-order status were shown beside the verified badge without saying they are as exported. Sequence
|
|
23
|
+
> numbers must now run 1 to n. Tests: `tests/test_verify_trust.py`, `dev/ui_smoke.py`. The required-checks setting is
|
|
24
|
+
> still open, for the operator.
|
|
25
|
+
>
|
|
26
|
+
> **Where that stands.** #68 is merged with green CI (17 of 17 checks); the suite is 399 passed, and hypswarm and
|
|
27
|
+
> hypmesh pass on it. Released as 0.7.14.
|
|
28
|
+
|
|
19
29
|
## Recommendation: CONDITIONAL GO
|
|
20
30
|
|
|
21
31
|
HypGraph is ready for a public developer preview once #59, #60 and #61 are merged with green CI and released as one
|
|
@@ -106,7 +106,18 @@ Records written before these fields existed (before 0.7.13) carry events without
|
|
|
106
106
|
`note_sha`, `as`, or a review's `code` and `inv`. A verifier checks what those events do carry (a revision's or a
|
|
107
107
|
withdrawal's first 300 characters, a lease note given in full, a review's investigation from its target) and
|
|
108
108
|
reports every other non-empty field as **not covered**, by table and field, rather than passing it silently. Without
|
|
109
|
-
`as`, a row the importer wrote may credit any author; that is reported too.
|
|
109
|
+
`as`, a row the importer wrote may credit any author; that is reported too. A verifier states at the top level
|
|
110
|
+
whether every row field was vouched for by its event (`coverage: complete`) or not (`partial`: fields not covered,
|
|
111
|
+
or redacted events).
|
|
112
|
+
|
|
113
|
+
**What a verifier trusts.** Who the importer is decides which older rows may credit another author, so the importer
|
|
114
|
+
belongs to what a verifier trusts, and the chain doesn't cover a bundle's `policy`. A verifier must not take the
|
|
115
|
+
importer, or any other policy field, from the bundle: it uses a policy its caller supplies (from the record's
|
|
116
|
+
publisher or host), and the default importer name `importer` otherwise. Every field the caller supplies must equal
|
|
117
|
+
the bundle's stated one. When the bundle names a different importer, the verifier says so.
|
|
118
|
+
|
|
119
|
+
**Sequence numbers** (`seq`) label events but aren't hashed: the order is fixed by `prev`. A verifier requires them
|
|
120
|
+
to run 1 to n, so a relabelled or gapped log fails.
|
|
110
121
|
|
|
111
122
|
## 4. Bundles — `hypgraph/1-bundle`
|
|
112
123
|
|
|
@@ -144,8 +155,10 @@ verifier must check every fact in it that the rows fix: which investigations it
|
|
|
144
155
|
investigation node), which nodes each investigation's graph shows (all of them, unless capped at 5,000) and which
|
|
145
156
|
live (unretracted) links among them, each node's `type`, `code`, `inv`, `by`, `at`, `v`, `title` and `kind`, whether
|
|
146
157
|
it is shown as withdrawn, and each link's fields. **Standing** (review state, support, at-risk, the sentence) can't
|
|
147
|
-
be checked from the rows alone: it is what the exporting engine derived
|
|
148
|
-
|
|
158
|
+
be checked from the rows alone: it is what the exporting engine derived, and so are the report, the workflow stages,
|
|
159
|
+
completion, the question board and work-order status. A verifier reports them as not checked, or re-derives them with
|
|
160
|
+
the same engine version (`hypgraph verify FILE --standing`, under the caller's policy with `--policy`) and compares.
|
|
161
|
+
A viewer must label them as exported wherever it shows them from a bundle.
|
|
149
162
|
|
|
150
163
|
## 5. Derived standing (normative)
|
|
151
164
|
|
|
@@ -78,7 +78,14 @@ separate implementation.
|
|
|
78
78
|
- **Records written before 0.7.13** have events that don't hash a few row fields (a link's reason, a retraction's
|
|
79
79
|
reason, a lease note, a revision's full reason, the credited author of an importer's node). The verifier checks
|
|
80
80
|
what those events carry and lists the rest as *not covered*, with a count per field. Rewriting one of those fields
|
|
81
|
-
in an old record isn't caught; new writes cover them all.
|
|
81
|
+
in an old record isn't caught; new writes cover them all. The result says `coverage: partial` at the top, and the
|
|
82
|
+
explorer shows a *partial coverage* badge beside *verified*.
|
|
83
|
+
- **The bundle's own policy isn't trusted.** Who the importer is decides which older rows may credit another author,
|
|
84
|
+
and the chain doesn't cover a bundle's `policy`. The verifier uses the default importer, or the policy you give it:
|
|
85
|
+
`hypgraph verify study.bundle.json --policy policy.json` (or `--importer NAME`), and every field you give must
|
|
86
|
+
match the bundle's. `--standing` derives under that policy and names the fields it took from the bundle on trust.
|
|
87
|
+
- **The report, stages and work orders** in a bundle are derived like standing. The explorer labels each of those
|
|
88
|
+
screens *as exported, not verified*; `--standing` re-derives and compares them.
|
|
82
89
|
|
|
83
90
|
## Scoped bundles and references
|
|
84
91
|
|
|
@@ -16,7 +16,7 @@ Standing is derived on every read, never stored; every write is an event in a SH
|
|
|
16
16
|
their numbers; reviews pin versions; independence is counted, not assumed. See https://hypgraph.com.
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
|
-
__version__ = "0.7.
|
|
19
|
+
__version__ = "0.7.14"
|
|
20
20
|
|
|
21
21
|
from .bundle import anchored, verify_bundle # noqa: E402
|
|
22
22
|
from .graph import Author, Graph, GraphError, file_sha256 # noqa: E402
|
|
@@ -155,26 +155,46 @@ def anchored(res: dict, head: str) -> dict:
|
|
|
155
155
|
return {**res, "anchored": True}
|
|
156
156
|
|
|
157
157
|
|
|
158
|
-
def verify_bundle(b: dict, head: str = "", *, standing: bool = False) -> dict:
|
|
158
|
+
def verify_bundle(b: dict, head: str = "", *, standing: bool = False, policy: dict | None = None) -> dict:
|
|
159
159
|
"""Check a bundle string-for-string: the chain; then the rows against the events, both ways (every row written by
|
|
160
160
|
an event, every event's row present, every recorded field equal); then the derived views against those rows. With
|
|
161
161
|
``head``, also that the chain ends at that published head (see ``anchored``). With ``standing``, re-derive the
|
|
162
|
-
standing from the verified rows and compare it with what the bundle carries (``rederive``).
|
|
163
|
-
|
|
162
|
+
standing from the verified rows and compare it with what the bundle carries (``rederive``).
|
|
163
|
+
|
|
164
|
+
The bundle's ``policy`` is not covered by the chain, so it is never trusted: whoever edits the bundle could name
|
|
165
|
+
any author the importer and so loosen what older events vouch for. ``policy`` is what the verifier trusts instead
|
|
166
|
+
(a dict of Policy fields, e.g. ``{"importer": "importer"}``, from the record's publisher or host). Every field
|
|
167
|
+
given must equal the bundle's stated one; the importer defaults to the default policy's. ``coverage`` says whether
|
|
168
|
+
every row field was vouched for by its event ("complete") or not ("partial": see ``unchecked``, ``redacted``)."""
|
|
169
|
+
res = anchored(_verify_bundle(b, policy), head)
|
|
164
170
|
if standing and res.get("ok"):
|
|
165
|
-
res = {**res, "standing": rederive(b)}
|
|
171
|
+
res = {**res, "standing": rederive(b, policy)}
|
|
166
172
|
if res["standing"].get("problem"):
|
|
167
173
|
res = {**res, "ok": False, "problem": res["standing"]["problem"]}
|
|
168
174
|
return res
|
|
169
175
|
|
|
170
176
|
|
|
177
|
+
def _policy_problem(b: dict, policy: dict | None) -> str:
|
|
178
|
+
"""A field the caller trusts that the bundle states otherwise."""
|
|
179
|
+
from .policy import Policy
|
|
180
|
+
stated = Policy.from_dict(b.get("policy") or {}).to_dict()
|
|
181
|
+
for k, v in (policy or {}).items():
|
|
182
|
+
want = Policy.from_dict({k: v}).to_dict().get(k)
|
|
183
|
+
if k in stated and stated[k] != want:
|
|
184
|
+
return f"the bundle states {k} {_j(stated[k])}; the policy you trust has {_j(want)}"
|
|
185
|
+
return ""
|
|
186
|
+
|
|
187
|
+
|
|
171
188
|
STANDING_NOTE = ("standing (review state, support, at-risk, the sentence) is what the exporting engine derived: the "
|
|
172
189
|
"chain doesn't cover it. Re-derive it from the verified rows with `hypgraph verify --standing`.")
|
|
173
190
|
|
|
174
191
|
|
|
175
|
-
def _verify_bundle(b: dict) -> dict:
|
|
192
|
+
def _verify_bundle(b: dict, policy: dict | None = None) -> dict:
|
|
176
193
|
if not isinstance(b, dict) or b.get("format") != BUNDLE_FORMAT:
|
|
177
194
|
return {"ok": False, "problem": f"not a {BUNDLE_FORMAT} bundle"}
|
|
195
|
+
problem = _policy_problem(b, policy)
|
|
196
|
+
if problem:
|
|
197
|
+
return {"ok": False, "problem": problem}
|
|
178
198
|
prev, checked, red, seqs = GENESIS, 0, 0, set()
|
|
179
199
|
events: list[dict] = []
|
|
180
200
|
for ev in sorted(b.get("events") or [], key=lambda e: e["seq"]):
|
|
@@ -193,22 +213,36 @@ def _verify_bundle(b: dict) -> dict:
|
|
|
193
213
|
return {"ok": False, "broken_at": ev["seq"], "problem": "chain broken (prev does not match)"}
|
|
194
214
|
prev, checked = ev["hash"], checked + 1
|
|
195
215
|
events.append(body)
|
|
216
|
+
if sorted(seqs) != list(range(1, len(seqs) + 1)):
|
|
217
|
+
return {"ok": False, "problem": "the events aren't numbered 1 to n: sequence numbers were changed, or events "
|
|
218
|
+
"dropped from the start or the middle"}
|
|
196
219
|
if b.get("head") and b["head"] != prev:
|
|
197
220
|
return {"ok": False, "problem": "the chain does not end at the bundle's head"}
|
|
198
221
|
tables = {t: b.get(t) or [] for t in ROW_TABLES}
|
|
199
|
-
|
|
222
|
+
importer = str((policy or {}).get("importer") or "importer")
|
|
223
|
+
stated = str((b.get("policy") or {}).get("importer") or "importer")
|
|
224
|
+
rows = check_rows(events, tables, importer=importer)
|
|
200
225
|
if "problem" in rows:
|
|
201
|
-
|
|
226
|
+
hint = (f" (the bundle names {stated} as its importer, which the chain doesn't cover; if you trust that, "
|
|
227
|
+
f"verify with --importer {stated})" if stated != importer else "")
|
|
228
|
+
return {"ok": False, "problem": rows["problem"] + hint}
|
|
202
229
|
problem = _derived_problem(b, tables)
|
|
203
230
|
if problem:
|
|
204
231
|
return {"ok": False, "problem": f"the derived views contradict the verified record: {problem}"}
|
|
205
232
|
out = {"ok": True, "checked": checked, "head": prev, "complete": red == 0, "redacted": red,
|
|
206
233
|
"nodes": len(tables["nodes"]), "edges": len(tables["edges"]), "unchecked": rows["unchecked"],
|
|
234
|
+
"coverage": "complete" if not rows["unchecked"] and not red else "partial",
|
|
235
|
+
"policy": {"trusted": sorted(policy or {}), "importer": importer},
|
|
207
236
|
"standing": {"checked": False, "note": STANDING_NOTE}}
|
|
237
|
+
notes = []
|
|
208
238
|
if red:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
239
|
+
notes.append(f"{red} event(s) outside this investigation are redacted: their content can't be checked, so a "
|
|
240
|
+
"change hidden among them (a withdrawal, say) would not show. The full record rules that out.")
|
|
241
|
+
if stated != importer:
|
|
242
|
+
notes.append(f"The bundle names {stated} as its importer; the chain doesn't cover that, so {importer} was "
|
|
243
|
+
"used.")
|
|
244
|
+
if notes:
|
|
245
|
+
out["warning"] = " ".join(notes)
|
|
212
246
|
return out
|
|
213
247
|
|
|
214
248
|
|
|
@@ -294,11 +328,12 @@ def _derived_problem(b: dict, tables: dict) -> str:
|
|
|
294
328
|
return ""
|
|
295
329
|
|
|
296
330
|
|
|
297
|
-
def rederive(b: dict) -> dict:
|
|
331
|
+
def rederive(b: dict, policy: dict | None = None) -> dict:
|
|
298
332
|
"""Replay a complete bundle in memory and derive the standing again, at the time it was derived, with this
|
|
299
333
|
engine: {"checked": True} when it matches what the bundle carries, a "problem" when it doesn't. Standing rules
|
|
300
334
|
change between releases, so only a bundle exported by this version can be compared; others are reported as not
|
|
301
|
-
checked.
|
|
335
|
+
checked. The policy is the bundle's stated one with every field of ``policy`` (the caller's, trusted) over it; the
|
|
336
|
+
result names the fields that were only as stated (``policy_as_stated``): the chain doesn't cover them."""
|
|
302
337
|
from .graph import Graph
|
|
303
338
|
from .policy import Policy
|
|
304
339
|
d = b.get("derived")
|
|
@@ -310,7 +345,7 @@ def rederive(b: dict) -> dict:
|
|
|
310
345
|
if b.get("redacted_events") or any(e.get("redacted") for e in b.get("events") or []):
|
|
311
346
|
return {"checked": False, "note": "a scoped bundle can't be replayed; re-derive from the full record"}
|
|
312
347
|
at = str(d.get("at") or b.get("exported_at") or now())
|
|
313
|
-
g = Graph(None, policy=Policy.from_dict(b.get("policy") or {}), clock=lambda: at)
|
|
348
|
+
g = Graph(None, policy=Policy.from_dict({**(b.get("policy") or {}), **(policy or {})}), clock=lambda: at)
|
|
314
349
|
load(g, b)
|
|
315
350
|
fresh = json.loads(json.dumps(derive_views(g, list(d.get("by_inv") or {})), sort_keys=True))
|
|
316
351
|
old = json.loads(json.dumps(d, sort_keys=True))
|
|
@@ -322,7 +357,7 @@ def rederive(b: dict) -> dict:
|
|
|
322
357
|
if (fresh[k].get(i) or {}).get(view) != old[k][i][view]), k)
|
|
323
358
|
return {"checked": False, "problem": f"the standing the bundle carries differs from what its record "
|
|
324
359
|
f"derives ({where})"}
|
|
325
|
-
return {"checked": True}
|
|
360
|
+
return {"checked": True, "policy_as_stated": sorted(set(Policy().to_dict()) - set(policy or {}))}
|
|
326
361
|
|
|
327
362
|
|
|
328
363
|
def load(g: "Graph", b: dict) -> None:
|
|
@@ -276,22 +276,30 @@ def cmd_report(args) -> int:
|
|
|
276
276
|
def cmd_verify(args) -> int:
|
|
277
277
|
target = args.target or args.db
|
|
278
278
|
if str(target).endswith(".json"):
|
|
279
|
+
trusted = json.loads(Path(args.policy).read_text(encoding="utf-8")) if args.policy else {}
|
|
280
|
+
if args.importer:
|
|
281
|
+
trusted["importer"] = args.importer
|
|
279
282
|
res = verify_bundle(json.loads(Path(target).read_text(encoding="utf-8")), head=args.head,
|
|
280
|
-
standing=args.standing)
|
|
283
|
+
standing=args.standing, policy=trusted or None)
|
|
281
284
|
else:
|
|
282
|
-
res = anchored(verify_file(target), args.head)
|
|
285
|
+
res = anchored(verify_file(target, importer=args.importer or "importer"), args.head)
|
|
283
286
|
ok = res.get("ok")
|
|
284
287
|
text = (f"✓ {target}: {res.get('checked')} events verified — chain intact, every row matches the event that "
|
|
285
288
|
f"wrote it, and none is missing.\n head {res.get('head', '')}" if ok else f"✗ {target}: {res.get('problem')}")
|
|
286
289
|
if ok:
|
|
287
290
|
text += ("\n matches the anchored head: not rewritten or cut short since it was published" if res.get("anchored")
|
|
288
291
|
else "\n consistent with itself; to rule out a rewrite, check it against a published head (--head)")
|
|
292
|
+
if ok and res.get("coverage") == "partial":
|
|
293
|
+
text += "\n coverage: PARTIAL — not every row field is vouched for by its event (see below)"
|
|
289
294
|
if ok and res.get("unchecked"):
|
|
290
295
|
text += ("\n not covered (written before events hashed these fields): "
|
|
291
296
|
+ ", ".join(f"{f} ×{n}" for f, n in sorted(res["unchecked"].items())))
|
|
292
297
|
st = res.get("standing") or {}
|
|
293
298
|
if ok and st.get("checked"):
|
|
294
299
|
text += "\n standing re-derived from the verified rows: it matches what the bundle carries"
|
|
300
|
+
if st.get("policy_as_stated"):
|
|
301
|
+
text += ("\n (under the bundle's stated " + ", ".join(st["policy_as_stated"]) + ", which the chain "
|
|
302
|
+
"doesn't cover; pass --policy to derive under yours)")
|
|
295
303
|
elif ok and st:
|
|
296
304
|
text += "\n standing not checked: " + str(st.get("note") or "")
|
|
297
305
|
if res.get("warning"):
|
|
@@ -521,6 +529,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
521
529
|
"fail unless the chain ends there")
|
|
522
530
|
s.add_argument("--standing", action="store_true", help="bundles: re-derive the standing from the verified rows and "
|
|
523
531
|
"fail if it differs from what the bundle carries")
|
|
532
|
+
s.add_argument("--importer", default="", help="the importer name you trust (default: importer); a bundle's own "
|
|
533
|
+
"policy isn't covered by the chain, so it is never taken from there")
|
|
534
|
+
s.add_argument("--policy", default="", help="bundles: a JSON file of the policy you trust (reviewers, importer, …); "
|
|
535
|
+
"every field must match the bundle's, and --standing derives under it")
|
|
524
536
|
s = cmd("export", cmd_export, "write a verifiable bundle")
|
|
525
537
|
s.add_argument("--inv", default="", help="one investigation (events outside it are redacted)")
|
|
526
538
|
s.add_argument("-o", "--output", default="")
|
|
@@ -265,6 +265,8 @@ def verify_connection(con: sqlite3.Connection, importer: str = "importer") -> di
|
|
|
265
265
|
payload = json.loads(payload_s)
|
|
266
266
|
if prev_s != prev or sha(event_body(at, actor, kind, ref, payload, prev)) != h:
|
|
267
267
|
return {"ok": False, "broken_at": seq, "checked": n, "problem": "event hash chain broken"}
|
|
268
|
+
if seq != n + 1:
|
|
269
|
+
return {"ok": False, "broken_at": seq, "checked": n, "problem": "the events aren't numbered 1 to n"}
|
|
268
270
|
prev, n = h, n + 1
|
|
269
271
|
events.append({"at": at, "actor": actor, "kind": kind, "ref": ref, "payload": payload})
|
|
270
272
|
tables = {}
|
|
@@ -274,7 +276,8 @@ def verify_connection(con: sqlite3.Connection, importer: str = "importer") -> di
|
|
|
274
276
|
res = check_rows(events, tables, importer=importer)
|
|
275
277
|
if "problem" in res:
|
|
276
278
|
return {"ok": False, "checked": n, "problem": res["problem"]}
|
|
277
|
-
return {"ok": True, "checked": n, "head": prev, "unchecked": res["unchecked"]
|
|
279
|
+
return {"ok": True, "checked": n, "head": prev, "unchecked": res["unchecked"],
|
|
280
|
+
"coverage": "partial" if res["unchecked"] else "complete", "policy": {"importer": importer}}
|
|
278
281
|
|
|
279
282
|
|
|
280
283
|
def verify_file(path: str, importer: str = "importer") -> dict:
|
|
@@ -232,8 +232,30 @@
|
|
|
232
232
|
|
|
233
233
|
/** Check a bundle in the browser: the chain, then the rows against the events both ways, then the derived views
|
|
234
234
|
* against the rows. Standing isn't covered (see STANDING_NOTE). With `head`, also that the chain ends at it. */
|
|
235
|
-
|
|
235
|
+
// the bundle's policy isn't covered by the chain: the verifier trusts only what its caller supplies (bundle.py)
|
|
236
|
+
const POLICY_DEFAULT = { reviewers: [], instrument: 'lab', operator: 'operator', importer: 'importer', system: 'system',
|
|
237
|
+
max_creates_per_minute: 60, extra_reserved: [] };
|
|
238
|
+
const normPolicy = (p) => {
|
|
239
|
+
const o = { ...POLICY_DEFAULT };
|
|
240
|
+
for (const k of Object.keys(o)) if (p && p[k] !== undefined) o[k] = p[k];
|
|
241
|
+
for (const k of ['reviewers', 'extra_reserved']) o[k] = [...new Set(o[k] || [])].sort();
|
|
242
|
+
return o;
|
|
243
|
+
};
|
|
244
|
+
function policyProblem(b, policy) {
|
|
245
|
+
const stated = normPolicy(b.policy || {});
|
|
246
|
+
for (const k of Object.keys(policy || {})) {
|
|
247
|
+
if (!(k in stated)) continue;
|
|
248
|
+
const want = normPolicy({ [k]: policy[k] })[k];
|
|
249
|
+
if (!same(stated[k], want)) return `the bundle states ${k} ${JSON.stringify(stated[k])}; the policy you trust has ${JSON.stringify(want)}`;
|
|
250
|
+
}
|
|
251
|
+
return '';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function verifyBundle(b, head = '', opts = {}) {
|
|
236
255
|
if (!b || b.format !== 'hypgraph/1-bundle') return { ok: false, problem: 'not a hypgraph/1-bundle' };
|
|
256
|
+
const policy = opts.policy || null;
|
|
257
|
+
const pp = policyProblem(b, policy);
|
|
258
|
+
if (pp) return { ok: false, problem: pp };
|
|
237
259
|
let prev = '0'.repeat(64), checked = 0, red = 0;
|
|
238
260
|
const events = [], seqs = new Set();
|
|
239
261
|
for (const ev of [...(b.events || [])].sort((x, y) => x.seq - y.seq)) {
|
|
@@ -249,15 +271,23 @@
|
|
|
249
271
|
prev = ev.hash; checked += 1;
|
|
250
272
|
events.push(body);
|
|
251
273
|
}
|
|
274
|
+
const order = [...seqs].sort((x, y) => x - y);
|
|
275
|
+
if (!order.every((q, i) => q === i + 1)) return { ok: false, problem: "the events aren't numbered 1 to n: sequence numbers were changed, or events dropped from the start or the middle" };
|
|
252
276
|
if (b.head && b.head !== prev) return { ok: false, problem: "the chain does not end at the bundle's head" };
|
|
253
277
|
const tables = Object.fromEntries(ROW_TABLES.map((t) => [t, b[t] || []]));
|
|
254
|
-
const
|
|
255
|
-
|
|
278
|
+
const importer = String((policy || {}).importer || 'importer'), stated = String((b.policy || {}).importer || 'importer');
|
|
279
|
+
const rows = await checkRows(events, tables, importer);
|
|
280
|
+
if (rows.problem) return { ok: false, problem: rows.problem + (stated !== importer ? ` (the bundle names ${stated} as its importer, which the chain doesn't cover; if you trust that, verify with --importer ${stated})` : '') };
|
|
256
281
|
const dp = derivedProblem(b, tables);
|
|
257
282
|
if (dp) return { ok: false, problem: `the derived views contradict the verified record: ${dp}` };
|
|
283
|
+
const partial = Object.keys(rows.unchecked).length > 0 || red > 0;
|
|
258
284
|
const out = { ok: true, checked, head: prev, complete: red === 0, redacted: red, nodes: tables.nodes.length,
|
|
259
|
-
edges: tables.edges.length, unchecked: rows.unchecked,
|
|
260
|
-
|
|
285
|
+
edges: tables.edges.length, unchecked: rows.unchecked, coverage: partial ? 'partial' : 'complete',
|
|
286
|
+
policy: { trusted: Object.keys(policy || {}).sort(), importer }, standing: { checked: false, note: STANDING_NOTE } };
|
|
287
|
+
const notes = [];
|
|
288
|
+
if (red) notes.push(`${red} event(s) outside this investigation are redacted: their content can't be checked, so a change hidden among them (a withdrawal, say) would not show. The full record rules that out.`);
|
|
289
|
+
if (stated !== importer) notes.push(`The bundle names ${stated} as its importer; the chain doesn't cover that, so ${importer} was used.`);
|
|
290
|
+
if (notes.length) out.warning = notes.join(' ');
|
|
261
291
|
return anchored(out, head);
|
|
262
292
|
}
|
|
263
293
|
|
|
@@ -571,6 +601,7 @@
|
|
|
571
601
|
(m.pid ? `<span class="pill accent" title="${esc(m.profile.about || '')}">${esc(m.pid)}</span>` : '<span class="pill neutral">no profile</span>');
|
|
572
602
|
const v = m.verify;
|
|
573
603
|
$('#hg-chain').innerHTML = !v ? '' : v.ok ? `<span class="pill ok" title="hash chain and every row re-verified: ${v.checked} events, head ${esc(String(v.head || '').slice(0, 12))}…">⛓ verified · ${v.checked}</span>` +
|
|
604
|
+
(v.coverage === 'partial' ? ` <span class="pill warn" title="${esc('Not every row field is vouched for by its event' + (Object.keys(v.unchecked || {}).length ? ': ' + Object.entries(v.unchecked || {}).map(([f, n]) => `${f} ×${n}`).join(', ') : '') + (v.redacted ? `; ${v.redacted} event(s) outside this investigation are redacted` : ''))}">partial coverage</span>` : '') +
|
|
574
605
|
(v.standing && !v.standing.checked ? ` <span class="pill neutral" title="${esc(v.standing.note || '')}">standing as exported</span>` : '')
|
|
575
606
|
: `<span class="pill bad" title="${esc(v.problem || '')}">⛓ does not verify${v.broken_at ? ' at #' + v.broken_at : ''}</span>`;
|
|
576
607
|
const s = !live ? '' : S.stream === 'live' ? '<span class="pill ok"><span class="d"></span>live</span>'
|
|
@@ -578,6 +609,11 @@
|
|
|
578
609
|
: S.stream === 'reconnecting' ? '<span class="pill warn">reconnecting</span>' : S.stream === 'offline' ? '<span class="pill bad">offline</span>' : '';
|
|
579
610
|
$('#hg-status').innerHTML = s;
|
|
580
611
|
}
|
|
612
|
+
// a bundle's standing, stages, orders and report are what its exporter derived: the chain covers the rows, not these
|
|
613
|
+
const asExported = (what) => {
|
|
614
|
+
const v = S.m && S.m.verify;
|
|
615
|
+
return v && v.ok && v.standing && !v.standing.checked ? `<div class="note" data-exported>${what} as exported with the bundle, not verified: the chain covers the record's rows, not what an engine derived from them. Re-derive it with <code>hypgraph verify --standing</code>.</div>` : '';
|
|
616
|
+
};
|
|
581
617
|
const head = (h, p, acts = '') => `<div class="head"><div><h1>${h}</h1>${p ? `<p>${p}</p>` : ''}</div>${acts ? `<div class="acts">${acts}</div>` : ''}</div>`;
|
|
582
618
|
|
|
583
619
|
// ── stage helpers ──
|
|
@@ -787,7 +823,7 @@
|
|
|
787
823
|
: ['Spend', '—', 'not metered', '']];
|
|
788
824
|
const stagesBy = new Map((m.stages || []).map((x) => [x.code, x]));
|
|
789
825
|
const wf = m.profile.workflow;
|
|
790
|
-
return head(esc(m.title), esc(m.objective), comp ? `<span class="pill ${comp.complete ? 'ok' : 'warn'}"><span class="d"></span>${comp.complete ? 'Complete' : 'In progress'}</span>` : '') +
|
|
826
|
+
return head(esc(m.title), esc(m.objective), comp ? `<span class="pill ${comp.complete ? 'ok' : 'warn'}"><span class="d"></span>${comp.complete ? 'Complete' : 'In progress'}</span>` : '') + asExported('Completion and the counts below are') +
|
|
791
827
|
`<div class="grid kpis">${kp.map(([k, v, s, c]) => `<div class="card kpi ${c}"><div class="k">${k}</div><div class="v">${v}</div><div class="s">${s}</div></div>`).join('')}</div>
|
|
792
828
|
<div class="grid two" style="margin-top:14px">
|
|
793
829
|
<div class="card"><h3>${esc(m.L('question'))}s ${wf ? `<span class="sub">through the ${esc(m.profile.name)} workflow · ${wf.stages.map((s) => esc(s.name)).join(' → ')}</span>` : ''}</h3>
|
|
@@ -812,7 +848,7 @@
|
|
|
812
848
|
if (!m.stages) return head('Pipeline', '') + '<div class="note warn">This host doesn\'t serve the workflow stages (<code>/api/graph/stages</code>, hypgraph ≥ 0.5).</div>';
|
|
813
849
|
const stages = wf.stages, cols = `56px repeat(${stages.length}, minmax(120px, 1fr))`;
|
|
814
850
|
const qs = new Map((m.board || []).map((q) => [q.code, q]));
|
|
815
|
-
return head('Pipeline', `Each ${esc(m.L('question').toLowerCase())} moves through the ${esc(m.profile.name)} workflow. The stage is derived from the record, never set by hand, and each gate says what would meet it.`) +
|
|
851
|
+
return head('Pipeline', `Each ${esc(m.L('question').toLowerCase())} moves through the ${esc(m.profile.name)} workflow. The stage is derived from the record, never set by hand, and each gate says what would meet it.`) + asExported('Stages and gates are') +
|
|
816
852
|
`<div class="card" style="overflow:auto"><div class="lane" style="grid-template-columns:${cols};border-bottom:1px solid var(--line);background:var(--surface2)">
|
|
817
853
|
<div style="min-height:auto"></div>${stages.map((s, i) => `<div style="min-height:auto"><b>${i + 1}. ${esc(s.name)}</b>${s.optional ? ' <span class="pill neutral">optional</span>' : ''}<div class="dim" style="margin-top:2px">${esc(s.holds)}</div></div>`).join('')}</div>
|
|
818
854
|
${m.stages.map((sq) => `<div class="lane click" data-q="${esc(sq.code)}" tabindex="0" role="button" aria-label="${esc(sq.code)} ${esc((qs.get(sq.code) || {}).text || '')}" style="grid-template-columns:${cols};border-bottom:1px solid var(--line);cursor:pointer">
|
|
@@ -839,7 +875,7 @@
|
|
|
839
875
|
const m = S.m, rows = evidenceRows();
|
|
840
876
|
const types = ['claim', 'result', 'hypothesis', 'source', 'decision', 'experiment', 'run', 'artifact'].filter((t) => m.nodes.some((n) => n.type === t));
|
|
841
877
|
const th = (k, label, w) => `<th scope="col" ${w ? `style="width:${w}"` : ''} aria-sort="${S.sort.k === k ? (S.sort.asc ? 'ascending' : 'descending') : 'none'}"><button type="button" data-sort="${k}">${label}${S.sort.k === k ? (S.sort.asc ? ' ↑' : ' ↓') : ''}</button></th>`;
|
|
842
|
-
return head('Evidence', `Every ${esc(m.L('claim').toLowerCase())}, ${esc(m.L('result').toLowerCase())} and source with its derived standing: checked, stale, contested, at risk.`, '<button class="btn" type="button" data-act="csv-evidence">Export CSV</button>') +
|
|
878
|
+
return head('Evidence', `Every ${esc(m.L('claim').toLowerCase())}, ${esc(m.L('result').toLowerCase())} and source with its derived standing: checked, stale, contested, at risk.`, '<button class="btn" type="button" data-act="csv-evidence">Export CSV</button>') + asExported('Standing is') +
|
|
843
879
|
`<div class="toolbar"><input class="input" id="hg-ev-q" placeholder="Filter by code, text or author" value="${esc(S.ev.q)}" aria-label="Filter evidence">
|
|
844
880
|
${types.map((t) => `<button type="button" class="chip" data-evtype="${t}" aria-pressed="${S.ev.types.has(t)}">${esc(m.L(t))}</button>`).join('')}
|
|
845
881
|
<select class="select" id="hg-ev-st" aria-label="Standing"><option value="">any standing</option>${['checked', 'unchecked', 'contested', 'stale', 'at risk', 'superseded', 'withdrawn'].map((s) => `<option ${S.ev.standing === s ? 'selected' : ''}>${s}</option>`).join('')}</select>
|
|
@@ -854,7 +890,7 @@
|
|
|
854
890
|
const m = S.m, os = m.orders;
|
|
855
891
|
if (!os) return head('Work orders', '') + '<div class="note warn">This host doesn\'t serve work orders (<code>/api/graph/orders</code>).</div>';
|
|
856
892
|
const col = (name, list) => `<div class="col"><h3>${name}<b>${list.length}</b></h3>${list.map(orderCard).join('') || '<div class="dim" style="padding:6px">none</div>'}</div>`;
|
|
857
|
-
return head('Work orders', 'What the harness asked each seat to do, the record\'s predicates for done, and how each order ended.', '<button class="btn" type="button" data-act="csv-orders">Export CSV</button>') +
|
|
893
|
+
return head('Work orders', 'What the harness asked each seat to do, the record\'s predicates for done, and how each order ended.', '<button class="btn" type="button" data-act="csv-orders">Export CSV</button>') + asExported('Order status is') +
|
|
858
894
|
`<div class="kanban">${col('Open', os.filter((o) => ['open', 'overdue'].includes(o.status)))}${col('Returned', os.filter((o) => o.status === 'returned'))}
|
|
859
895
|
${col('Accepted', os.filter((o) => o.status === 'accepted'))}${col('Cancelled · reworked', os.filter((o) => ['cancelled', 'reworked'].includes(o.status)))}</div>`;
|
|
860
896
|
}
|
|
@@ -871,7 +907,7 @@
|
|
|
871
907
|
const m = S.m, rows = auditRows(), v = m.verify;
|
|
872
908
|
const actors = [...new Set(m.events.map((e) => e.actor))].sort(), kinds = [...new Set(m.events.map((e) => e.kind))].sort();
|
|
873
909
|
return head('Audit log', 'The record\'s append-only event log. Every write is hash-chained, and the chain is re-verified when the record is read.', '<button class="btn" type="button" data-act="csv-audit">Export CSV</button>') +
|
|
874
|
-
(v ? `<div class="note ${v.ok ? '' : 'warn'}">${v.ok ? `⛓ Verified: ${v.checked} events, head <code>${esc(String(v.head || '').slice(0, 16))}…</code>, and every row against its event${v.warning ? ' · ' + esc(v.warning) : ''}${v.standing && !v.standing.checked ? ' · ' + esc(v.standing.note) : ''}` : `⛓ The record does not verify: ${esc(v.problem || '')}`}</div>` : '') +
|
|
910
|
+
(v ? `<div class="note ${v.ok ? '' : 'warn'}">${v.ok ? `⛓ Verified: ${v.checked} events, head <code>${esc(String(v.head || '').slice(0, 16))}…</code>, and every row against its event${Object.keys(v.unchecked || {}).length ? ' · not covered (written before events vouched for them): ' + esc(Object.entries(v.unchecked || {}).map(([f, n]) => `${f} ×${n}`).join(', ')) : ''}${v.warning ? ' · ' + esc(v.warning) : ''}${v.standing && !v.standing.checked ? ' · ' + esc(v.standing.note) : ''}` : `⛓ The record does not verify: ${esc(v.problem || '')}`}</div>` : '') +
|
|
875
911
|
`<div class="toolbar"><select class="select" id="hg-au-actor" aria-label="Actor"><option value="">every actor</option>${actors.map((a) => `<option ${S.audit.actor === a ? 'selected' : ''}>${esc(a)}</option>`).join('')}</select>
|
|
876
912
|
<select class="select" id="hg-au-kind" aria-label="Event"><option value="">every event</option>${kinds.map((k) => `<option ${S.audit.kind === k ? 'selected' : ''}>${esc(k)}</option>`).join('')}</select><span class="dim">${rows.length} events</span></div>
|
|
877
913
|
<div class="card"><table><thead><tr><th scope="col" style="width:60px">Seq</th><th scope="col" style="width:170px">Time (UTC)</th><th scope="col" style="width:120px">Actor</th><th scope="col" style="width:120px">Event</th><th scope="col">What happened</th></tr></thead><tbody>
|
|
@@ -883,7 +919,7 @@
|
|
|
883
919
|
const m = S.m, name = (m.profile.workflow && m.profile.workflow.report) || 'Facts from the record';
|
|
884
920
|
const acts = '<button class="btn" type="button" data-act="print">Print · PDF</button><button class="btn" type="button" data-act="md">Download Markdown</button>' +
|
|
885
921
|
(src.exportUrl ? `<a class="btn" href="${esc(src.exportUrl(S.inv))}" download>Export bundle</a>` : src.bundle ? '<button class="btn" type="button" data-act="bundle">Export bundle</button>' : '');
|
|
886
|
-
return head(esc(name), '
|
|
922
|
+
return head(esc(name), 'The facts of the record, generated by the engine that serves or exported it. Interpretation belongs below them.', acts) + asExported('This report is') +
|
|
887
923
|
`<div class="card"><div class="body md">${m.report ? md(m.report.markdown) : '<div class="empty">This host doesn\'t serve the report.</div>'}</div></div>`;
|
|
888
924
|
}
|
|
889
925
|
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""What a verifier trusts (re-audit of 0.7.13, 2026-10-31).
|
|
2
|
+
|
|
3
|
+
A bundle's ``policy`` isn't covered by the hash chain. 0.7.13 took the importer's name from it, and older events don't
|
|
4
|
+
vouch for the author of a node the importer wrote, so whoever edited a bundle could name any historical writer the
|
|
5
|
+
importer and re-attribute that writer's nodes: it verified against the unchanged published head. Now the verifier
|
|
6
|
+
trusts only the policy its caller supplies (the default importer otherwise), every supplied field must match the
|
|
7
|
+
bundle's, and the result says at the top whether every row field was vouched for (``coverage``).
|
|
8
|
+
|
|
9
|
+
Event sequence numbers aren't hashed either: they must run 1 to n. Each case runs in Python and in the browser's
|
|
10
|
+
verifier, which must agree.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import copy
|
|
15
|
+
import json
|
|
16
|
+
import shutil
|
|
17
|
+
import sqlite3
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
import pytest
|
|
23
|
+
|
|
24
|
+
from hypgraph.bundle import export, verify_bundle
|
|
25
|
+
from hypgraph.demos import broad_street
|
|
26
|
+
from hypgraph.store import verify_file
|
|
27
|
+
|
|
28
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
29
|
+
UI_JS = ROOT / "src" / "hypgraph" / "ui" / "hypgraph.js"
|
|
30
|
+
JS_VERIFY = ROOT / "dev" / "js_verify.js"
|
|
31
|
+
LEGACY = ROOT / "dev" / "ui-fixtures" / "scientific.bundle.json"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _legacy() -> dict:
|
|
35
|
+
return json.loads(LEGACY.read_text(encoding="utf-8"))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _launder(b: dict) -> tuple[dict, str]:
|
|
39
|
+
"""The re-audit's case: name a historical writer the importer, then re-attribute one of its older nodes, in the
|
|
40
|
+
rows and in the derived views alike."""
|
|
41
|
+
bodies = [json.loads(e["body"]) for e in b["events"] if not e.get("redacted")]
|
|
42
|
+
e = next(x for x in bodies if x["kind"] == "create" and x["actor"] == "harness" and "reason_sha" not in x["payload"])
|
|
43
|
+
m = copy.deepcopy(b)
|
|
44
|
+
m["policy"]["importer"] = "harness"
|
|
45
|
+
for n in m["nodes"]:
|
|
46
|
+
if n["id"] == e["ref"]:
|
|
47
|
+
n["created_by"] = "FAKE_PROVENANCE"
|
|
48
|
+
for n in m["derived"].get("investigations", []):
|
|
49
|
+
if n["id"] == e["ref"]:
|
|
50
|
+
n["by"] = "FAKE_PROVENANCE"
|
|
51
|
+
for v in m["derived"]["by_inv"].values():
|
|
52
|
+
for n in v["subgraph"]["nodes"]:
|
|
53
|
+
if n["id"] == e["ref"]:
|
|
54
|
+
n["by"] = "FAKE_PROVENANCE"
|
|
55
|
+
return m, e["ref"]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.fixture(scope="module")
|
|
59
|
+
def fresh():
|
|
60
|
+
g, inv, _ = broad_street.build()
|
|
61
|
+
return {"g": g, "inv": inv, "bundle": g.export()}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _cases(fresh) -> dict:
|
|
65
|
+
"""name → (bundle, head, trusted policy, should verify)."""
|
|
66
|
+
old, b = _legacy(), fresh["bundle"]
|
|
67
|
+
laundered, _ = _launder(old)
|
|
68
|
+
relabelled = copy.deepcopy(b)
|
|
69
|
+
for i, ev in enumerate(relabelled["events"]):
|
|
70
|
+
ev["seq"] = i + 100
|
|
71
|
+
gap = copy.deepcopy(b)
|
|
72
|
+
gap["events"][-1]["seq"] += 5
|
|
73
|
+
stated = copy.deepcopy(b)
|
|
74
|
+
stated["policy"]["reviewers"] = ["fake_reviewer"]
|
|
75
|
+
return {
|
|
76
|
+
"legacy, untouched": (old, "", None, True),
|
|
77
|
+
"legacy, untouched, against its head": (old, old["head"], None, True),
|
|
78
|
+
"laundered author": (laundered, "", None, False),
|
|
79
|
+
"laundered author, against the published head": (laundered, old["head"], None, False),
|
|
80
|
+
"laundered author, caller trusts that importer": (laundered, old["head"], {"importer": "harness"}, True),
|
|
81
|
+
"fresh, untouched": (b, b["head"], None, True),
|
|
82
|
+
"fresh, the policy its publisher states": (b, b["head"], {"reviewers": ["whitehead"], "importer": "importer"}, True),
|
|
83
|
+
"fresh, a policy the bundle doesn't state": (b, b["head"], {"reviewers": ["fake_reviewer"]}, False),
|
|
84
|
+
"reviewers edited, caller supplies the real ones": (stated, b["head"], {"reviewers": ["whitehead"]}, False),
|
|
85
|
+
"reviewers edited, nothing supplied": (stated, b["head"], None, True),
|
|
86
|
+
"sequence numbers relabelled": (relabelled, b["head"], None, False),
|
|
87
|
+
"a gap in the sequence": (gap, b["head"], None, False),
|
|
88
|
+
"scoped bundle": (export(fresh["g"], fresh["inv"]), "", None, True),
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_a_bundle_cannot_name_its_own_importer():
|
|
93
|
+
m, ref = _launder(_legacy())
|
|
94
|
+
for head in ("", _legacy()["head"]):
|
|
95
|
+
v = verify_bundle(m, head=head)
|
|
96
|
+
assert not v["ok"], v
|
|
97
|
+
assert "created_by" in v["problem"] and "names harness as its importer" in v["problem"], v["problem"]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_the_supplied_policy_is_the_one_trusted(fresh):
|
|
101
|
+
m, _ = _launder(_legacy())
|
|
102
|
+
v = verify_bundle(m, head=_legacy()["head"], policy={"importer": "harness"})
|
|
103
|
+
assert v["ok"] and v["coverage"] == "partial" and v["policy"] == {"trusted": ["importer"], "importer": "harness"}
|
|
104
|
+
v = verify_bundle(fresh["bundle"], policy={"reviewers": ["fake_reviewer"]})
|
|
105
|
+
assert not v["ok"] and v["problem"].startswith("the bundle states reviewers"), v
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_coverage_is_stated_at_the_top(fresh):
|
|
109
|
+
assert verify_bundle(fresh["bundle"])["coverage"] == "complete"
|
|
110
|
+
assert verify_bundle(_legacy())["coverage"] == "partial"
|
|
111
|
+
named = copy.deepcopy(fresh["bundle"])
|
|
112
|
+
named["policy"]["importer"] = "someone"
|
|
113
|
+
v = verify_bundle(named)
|
|
114
|
+
assert v["ok"] and "names someone as its importer" in v["warning"], v
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_rederived_standing_names_the_policy_it_took_on_trust(fresh):
|
|
118
|
+
b = fresh["bundle"]
|
|
119
|
+
on_trust = verify_bundle(b, standing=True)["standing"]
|
|
120
|
+
assert on_trust["checked"] and "reviewers" in on_trust["policy_as_stated"] and "importer" in on_trust["policy_as_stated"]
|
|
121
|
+
supplied = verify_bundle(b, standing=True, policy=b["policy"])["standing"]
|
|
122
|
+
assert supplied == {"checked": True, "policy_as_stated": []}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@pytest.mark.parametrize("name", ["laundered author", "laundered author, against the published head",
|
|
126
|
+
"sequence numbers relabelled", "a gap in the sequence",
|
|
127
|
+
"fresh, a policy the bundle doesn't state",
|
|
128
|
+
"reviewers edited, caller supplies the real ones"])
|
|
129
|
+
def test_each_forgery_fails_in_python(fresh, name):
|
|
130
|
+
b, head, policy, _ = _cases(fresh)[name]
|
|
131
|
+
assert not verify_bundle(b, head=head, policy=policy)["ok"], name
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_renumbered_events_fail_in_a_graph_file(tmp_path):
|
|
135
|
+
g, _, _ = broad_street.build(path=str(tmp_path / "r.hypgraph"))
|
|
136
|
+
p = Path(g.path)
|
|
137
|
+
assert verify_file(str(p))["ok"] and verify_file(str(p))["coverage"] == "complete"
|
|
138
|
+
con = sqlite3.connect(p)
|
|
139
|
+
for (t,) in con.execute("SELECT name FROM sqlite_master WHERE type = 'trigger'").fetchall():
|
|
140
|
+
con.execute(f"DROP TRIGGER {t}")
|
|
141
|
+
con.execute("UPDATE events SET seq = seq + 100")
|
|
142
|
+
con.commit()
|
|
143
|
+
con.close()
|
|
144
|
+
v = verify_file(str(p))
|
|
145
|
+
assert not v["ok"] and "numbered" in v["problem"], v
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_the_cli_refuses_a_laundered_bundle(tmp_path):
|
|
149
|
+
m, _ = _launder(_legacy())
|
|
150
|
+
f = tmp_path / "laundered.bundle.json"
|
|
151
|
+
f.write_text(json.dumps(m), encoding="utf-8")
|
|
152
|
+
run = [sys.executable, "-m", "hypgraph", "verify", str(f), "--head", _legacy()["head"]]
|
|
153
|
+
bad = subprocess.run(run, capture_output=True, text=True, encoding="utf-8")
|
|
154
|
+
assert bad.returncode == 1 and "names harness as its importer" in bad.stdout, bad.stdout
|
|
155
|
+
trusted = subprocess.run(run + ["--importer", "harness"], capture_output=True, text=True, encoding="utf-8")
|
|
156
|
+
assert trusted.returncode == 0 and "coverage: PARTIAL" in trusted.stdout, trusted.stdout
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@pytest.mark.skipif(not shutil.which("node"), reason="node is not installed")
|
|
160
|
+
def test_the_browser_verifier_agrees(fresh, tmp_path):
|
|
161
|
+
cases = _cases(fresh)
|
|
162
|
+
paths = []
|
|
163
|
+
for i, (name, (b, head, policy, _)) in enumerate(cases.items()):
|
|
164
|
+
p = tmp_path / f"t{i:03d}.json"
|
|
165
|
+
p.write_text(json.dumps({"bundle": b, "head": head, "policy": policy}), encoding="utf-8")
|
|
166
|
+
paths.append(p)
|
|
167
|
+
out = subprocess.run(["node", str(JS_VERIFY), str(UI_JS), *map(str, paths)], capture_output=True, text=True,
|
|
168
|
+
encoding="utf-8", timeout=300)
|
|
169
|
+
assert out.returncode == 0, out.stderr[-2000:]
|
|
170
|
+
js = json.loads(out.stdout)
|
|
171
|
+
keys = ("ok", "problem", "coverage", "warning", "anchored")
|
|
172
|
+
for (name, (b, head, policy, should)), p in zip(cases.items(), paths):
|
|
173
|
+
py = verify_bundle(b, head=head, policy=policy)
|
|
174
|
+
assert py["ok"] is should, (name, py.get("problem"))
|
|
175
|
+
py_said = {k: py.get(k, False if k == "anchored" else "") for k in keys}
|
|
176
|
+
js_said = {k: js[p.name].get(k, False if k == "anchored" else "") for k in keys}
|
|
177
|
+
if not py["ok"]:
|
|
178
|
+
py_said.update(coverage="", warning="", anchored=False)
|
|
179
|
+
assert py_said == js_said, name
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|