hypgraph 0.7.14__tar.gz → 0.7.16__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.14 → hypgraph-0.7.16}/CHANGELOG.md +28 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/PKG-INFO +1 -1
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/PLAN.md +1 -1
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/RELEASE-READINESS.md +21 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/spec.md +23 -3
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/verification.md +9 -1
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/__init__.py +1 -1
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/bundle.py +121 -25
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/cli.py +8 -2
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/hypgraph.js +78 -20
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_blind.py +9 -3
- hypgraph-0.7.16/tests/test_verify_scope.py +153 -0
- hypgraph-0.7.16/tests/test_verify_views.py +193 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/.gitignore +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/AGENTS.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/CITATION.cff +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/DISCLAIMER.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/LICENSE +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/NOTICE +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/README.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/decisions/ADR-001-token-bound-authors.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/decisions/ADR-002-governance-profiles.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/profile-workflows-plan.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/review-2026-10-24.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/site-plan.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/ui-plan.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/README.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/knowledge.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/optimization.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/scientific.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/software.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/docs/workflows/trading.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/examples/frameworks/README.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/pyproject.toml +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/__main__.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/blind.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/checks.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/coord.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/demos/__init__.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/demos/broad_street.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/derive.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/graph.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/language.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/mcp.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/plan.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/policy.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/profiles.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/references.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/refusals.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/report_check.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/schema.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/server.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/skill/SKILL.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/stats.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/store.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/__init__.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/atlas.css +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/atlas.js +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/hypgraph.css +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/hypgraph.svg +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/index.html +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/vendor/LICENSES.md +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/vendor/cose-base.js +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/vendor/cytoscape-fcose.js +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/vendor/cytoscape.min.js +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/ui/vendor/layout-base.js +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/src/hypgraph/workflow.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_accept_work_kind.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_anchoring.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_blind_oracles.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_bound_support.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_bundle_telemetry.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_cancel_releases_lease.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_cited_and_failed_support.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_coord.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_d10.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_engine.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_engine_fixes.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_framework_examples.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_incremental.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_link_translate.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_log_and_check.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_measure_questions.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_opposed_answers.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_option_lead.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_order_detail.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_profiles.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_profiles_041.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_questions_not_assertions.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_references.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_refusal_friction.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_refusal_results.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_refusals.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_relation_words.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_report_answers.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_rerunnable.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_restates_scale.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_server_auth.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_server_hosts.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_shape_refusals.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_stats_not_backtests.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_stats_values.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_surfaces.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_telemetry_stream.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_trust_boundary.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_ui_app.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_ui_engine.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_uncorrected_effect.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_unnamed_inputs.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_verify_complete.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_verify_trust.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_versions_not_figures.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_vocabulary_friction.py +0 -0
- {hypgraph-0.7.14 → hypgraph-0.7.16}/tests/test_workflows.py +0 -0
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.16 — 2026-10-31: a bundle's scope must be a real one
|
|
4
|
+
|
|
5
|
+
- **A bundle's scope must be a real one.** A re-audit of 0.7.15 found that `scope.inv`, which the chain doesn't
|
|
6
|
+
cover, was taken on trust: naming a claim, question, result or hypothesis as the scope showed that one node, hid the
|
|
7
|
+
rest of the record, and still verified against the published head; a full export of two investigations relabelled
|
|
8
|
+
as one hid the other. Now, in the Python and browser verifiers alike, the scope must name an investigation and the
|
|
9
|
+
bundle hold only that investigation's nodes, as an export writes it; a bundle without a scope may not redact events
|
|
10
|
+
(`tests/test_verify_scope.py`).
|
|
11
|
+
- **The redaction warning says what can't be checked.** A redacted event keeps only its hash, so that it lies
|
|
12
|
+
outside the investigation is the bundle's word; the warning says so, and that only the full record against the
|
|
13
|
+
published head rules out a change hidden among them.
|
|
14
|
+
- **The verify page names the scope from the verified investigation**, not from the unhashed `scope.title`, and says
|
|
15
|
+
whether the bundle's derived views were checked or absent. The spec says what `ok`, `coverage` and `views` vouch for.
|
|
16
|
+
|
|
17
|
+
## 0.7.15 — 2026-10-31: derived views must carry every fact the rows fix
|
|
18
|
+
|
|
19
|
+
- **Derived views must carry every fact the rows fix.** A re-audit of 0.7.14 found that a derived field was compared
|
|
20
|
+
with the verified rows only when it was there: deleting a withdrawn claim's `state.lifecycle`, or its whole `state`,
|
|
21
|
+
still verified as complete, and the explorer then showed the claim as active. An emptied investigation list, nodes
|
|
22
|
+
without a title, author or code, and links without an end verified too. Now every one of those facts must be present
|
|
23
|
+
and agree, in the Python and browser verifiers alike; the lifecycle is derived again from the verified rows
|
|
24
|
+
(withdrawals and live replacements, under the 0.3 rule or the current one, as the exporter may have used either)
|
|
25
|
+
instead of only checked for "withdrawn"; the investigation list must show each investigation once. A bundle exported
|
|
26
|
+
without derived views still verifies and says so (`views: none`) (`tests/test_verify_views.py`).
|
|
27
|
+
- **A malformed bundle fails instead of raising.** An event body that isn't a JSON object fails with that problem; a
|
|
28
|
+
field missing or of the wrong kind fails as malformed; `hypgraph verify` on a file that isn't JSON says so.
|
|
29
|
+
- **The explorer never defaults a missing lifecycle to active.** It shows *unknown*.
|
|
30
|
+
|
|
3
31
|
## 0.7.14 — 2026-10-31: the verifier trusts its caller's policy, and derived screens say they are as exported
|
|
4
32
|
|
|
5
33
|
- **The verifier trusts its caller's policy, not the bundle's.** A re-audit of 0.7.13 found that the bundle and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hypgraph
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.16
|
|
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.16 (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
|
|
@@ -26,6 +26,27 @@ was taken from a changelog without being checked against the code.*
|
|
|
26
26
|
> **Where that stands.** #68 is merged with green CI (17 of 17 checks); the suite is 399 passed, and hypswarm and
|
|
27
27
|
> hypmesh pass on it. Released as 0.7.14.
|
|
28
28
|
|
|
29
|
+
> **Re-audit of 0.7.14 (2026-10-31).** Confirmed and fixed for 0.7.15: derived facts were compared only when present,
|
|
30
|
+
> so deleting a withdrawn claim's `state.lifecycle` (or its `state`) still verified as complete and the explorer showed
|
|
31
|
+
> the claim as active; an emptied investigation list, nodes without a title, author or code, and links without an end
|
|
32
|
+
> verified too; an event body that wasn't JSON raised instead of failing. Every such fact must now be present, the
|
|
33
|
+
> lifecycle is re-derived from the rows, malformed bundles fail cleanly, and the explorer shows a missing lifecycle as
|
|
34
|
+
> unknown. Tests: `tests/test_verify_views.py`. The required checks and the repository's About metadata are still the
|
|
35
|
+
> operator's.
|
|
36
|
+
>
|
|
37
|
+
> **Where that stands.** #70 is merged with green CI (17 of 17 checks); the suite is 406 passed, and hypswarm and
|
|
38
|
+
> hypmesh pass on it. Released as 0.7.15.
|
|
39
|
+
|
|
40
|
+
> **Re-audit of 0.7.15 (2026-10-31).** Confirmed and fixed for 0.7.16: the scope isn't hashed and wasn't checked, so a
|
|
41
|
+
> claim, question, result or hypothesis named as the scope showed alone, the rest of the record hidden, and the bundle
|
|
42
|
+
> verified against the published head; a full export of two investigations relabelled as one did the same. The scope
|
|
43
|
+
> must now name an investigation, the bundle hold only its nodes, and only a scoped bundle redact; the redaction
|
|
44
|
+
> warning says the bundle's word that redacted events lie outside can't be checked. Tests: `tests/test_verify_scope.py`.
|
|
45
|
+
> The required checks and the repository's About metadata are still the operator's.
|
|
46
|
+
>
|
|
47
|
+
> **Where that stands.** #72 is merged with green CI (17 of 17 checks); the suite is 412 passed, and hypswarm and
|
|
48
|
+
> hypmesh pass on it. Released as 0.7.16.
|
|
49
|
+
|
|
29
50
|
## Recommendation: CONDITIONAL GO
|
|
30
51
|
|
|
31
52
|
HypGraph is ready for a public developer preview once #59, #60 and #61 are merged with green CI and released as one
|
|
@@ -143,6 +143,19 @@ A **scoped** bundle (one investigation out of a shared record) replaces events o
|
|
|
143
143
|
checked, so a change hidden among them would not show. Verifiers must report `complete: false`. To publish a study,
|
|
144
144
|
keep it in a record of its own.
|
|
145
145
|
|
|
146
|
+
`scope` isn't covered by the chain, so a verifier requires the one shape an export writes: `scope.inv` names a node
|
|
147
|
+
of type `investigation`, and every node row is that investigation or belongs to it; a bundle without a scope has no
|
|
148
|
+
redacted events. Otherwise any node could pose as the investigation, or a whole record pass as one investigation,
|
|
149
|
+
and the views would hide the rest beside a verified chain. A redacted event keeps only its hash, so that it lies
|
|
150
|
+
outside the investigation is the bundle's word: only the full record, verified against the published head, rules
|
|
151
|
+
out a change hidden among them. `scope.title` is a label; a viewer names the scope from the verified investigation.
|
|
152
|
+
|
|
153
|
+
**What a verifier vouches for.** `ok` means the chain links and every row and event agree, both ways. `coverage:
|
|
154
|
+
complete` means every row field was vouched for by its event and nothing is redacted (`partial` otherwise). `views:
|
|
155
|
+
checked` means every fact the derived views show that the rows fix is present and agrees with the rows, and the
|
|
156
|
+
scope is a real one; `views: none` means the bundle carries no views. None of them vouches for standing, the report,
|
|
157
|
+
stages or work orders (as exported), for who an author really is, or that the head was published.
|
|
158
|
+
|
|
146
159
|
**Anchoring.** A bundle proves only its own consistency. To prove it wasn't rebuilt from scratch, publish its `head`
|
|
147
160
|
hash somewhere independent at the time (a paper, a preregistration, a repository tag). A later bundle whose chain
|
|
148
161
|
passes through that hash can't have rewritten anything before it. A verifier given a published head (the full hash,
|
|
@@ -152,9 +165,16 @@ published and signed, and what each check does and doesn't show: [verification.m
|
|
|
152
165
|
|
|
153
166
|
**Derived views.** `derived` is a convenience for viewers, and a viewer shows it beside a verified chain, so a
|
|
154
167
|
verifier must check every fact in it that the rows fix: which investigations it covers (the scope's, or every
|
|
155
|
-
investigation node), which
|
|
156
|
-
live (unretracted) links among them, each node's `type`, `code`, `inv`,
|
|
157
|
-
|
|
168
|
+
investigation node), which investigations the list shows (each once), which nodes each investigation's graph shows
|
|
169
|
+
(all of them, unless capped at 5,000) and which live (unretracted) links among them, each node's `type`, `code`, `inv`,
|
|
170
|
+
`by`, `at`, `v`, `title`, `kind` and `state.lifecycle`, and each link's `id`, ends, versions, `rel`, `data`, `at`,
|
|
171
|
+
`by` and `why`. Every one of these must be **present**, not only equal where present: a viewer fills a missing fact
|
|
172
|
+
with a default, and a withdrawn claim without its lifecycle would read as active. The lifecycle is derived from the
|
|
173
|
+
verified rows (withdrawn when a withdrawal exists; superseded when a live `supersedes` or `corrects` replacement is
|
|
174
|
+
active or, since 0.4, itself superseded; an investigation's own `state` otherwise), and a verifier accepts the value
|
|
175
|
+
either rule gives. A scoped bundle leaves out links to other investigations, so it may also call a node superseded
|
|
176
|
+
(never a withdrawn node anything but withdrawn). A bundle exported without derived views verifies, and a verifier says
|
|
177
|
+
it has none (`views: none`). **Standing** (review state, support, at-risk, the sentence) can't
|
|
158
178
|
be checked from the rows alone: it is what the exporting engine derived, and so are the report, the workflow stages,
|
|
159
179
|
completion, the question board and work-order status. A verifier reports them as not checked, or re-derives them with
|
|
160
180
|
the same engine version (`hypgraph verify FILE --standing`, under the caller's policy with `--policy`) and compares.
|
|
@@ -86,12 +86,20 @@ separate implementation.
|
|
|
86
86
|
match the bundle's. `--standing` derives under that policy and names the fields it took from the bundle on trust.
|
|
87
87
|
- **The report, stages and work orders** in a bundle are derived like standing. The explorer labels each of those
|
|
88
88
|
screens *as exported, not verified*; `--standing` re-derives and compares them.
|
|
89
|
+
- **What the views show must be there.** Every fact the rows fix — each node's type, code, author, time, version,
|
|
90
|
+
title and lifecycle, each link's ends and fields, the full investigation list — must be present in the derived
|
|
91
|
+
views, not only right where present: a view that drops a withdrawn claim's lifecycle fails, rather than being shown
|
|
92
|
+
as active. A bundle exported without derived views (`export(derived=False)`) verifies and says `views: none`.
|
|
89
93
|
|
|
90
94
|
## Scoped bundles and references
|
|
91
95
|
|
|
92
96
|
- `hypgraph export --inv INV` writes one investigation. Events outside it are redacted to their hash, so the chain
|
|
93
|
-
still verifies, but their content can't be checked; the verifier says how many.
|
|
97
|
+
still verifies, but their content can't be checked; the verifier says how many. That they lie outside the
|
|
98
|
+
investigation is the bundle's word: only the full record, verified against the published head, rules out a change
|
|
94
99
|
hidden among them.
|
|
100
|
+
- The scope itself isn't hashed, so the verifier requires what an export writes: it names an investigation, and the
|
|
101
|
+
bundle holds only that investigation's nodes. A claim posing as the scope, or a whole record relabelled as one
|
|
102
|
+
investigation, fails; so does a bundle without a scope that has redacted events.
|
|
95
103
|
- A source that pins another record's node checks that the cited body still hashes to the pinned version. It doesn't
|
|
96
104
|
check the cited record's history: for that, verify that record against its own published head.
|
|
97
105
|
|
|
@@ -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.16"
|
|
20
20
|
|
|
21
21
|
from .bundle import anchored, verify_bundle # noqa: E402
|
|
22
22
|
from .graph import Author, Graph, GraphError, file_sha256 # noqa: E402
|
|
@@ -34,6 +34,7 @@ from pathlib import Path
|
|
|
34
34
|
from typing import TYPE_CHECKING, Any
|
|
35
35
|
|
|
36
36
|
from . import __version__
|
|
37
|
+
from .schema import SAME_TYPE
|
|
37
38
|
from .store import GENESIS, ROW_TABLES, check_rows, event_body, now
|
|
38
39
|
|
|
39
40
|
if TYPE_CHECKING:
|
|
@@ -166,7 +167,10 @@ def verify_bundle(b: dict, head: str = "", *, standing: bool = False, policy: di
|
|
|
166
167
|
(a dict of Policy fields, e.g. ``{"importer": "importer"}``, from the record's publisher or host). Every field
|
|
167
168
|
given must equal the bundle's stated one; the importer defaults to the default policy's. ``coverage`` says whether
|
|
168
169
|
every row field was vouched for by its event ("complete") or not ("partial": see ``unchecked``, ``redacted``)."""
|
|
169
|
-
|
|
170
|
+
try:
|
|
171
|
+
res = anchored(_verify_bundle(b, policy), head)
|
|
172
|
+
except (KeyError, TypeError, ValueError, AttributeError, IndexError):
|
|
173
|
+
return {"ok": False, "problem": MALFORMED}
|
|
170
174
|
if standing and res.get("ok"):
|
|
171
175
|
res = {**res, "standing": rederive(b, policy)}
|
|
172
176
|
if res["standing"].get("problem"):
|
|
@@ -189,6 +193,9 @@ STANDING_NOTE = ("standing (review state, support, at-risk, the sentence) is wha
|
|
|
189
193
|
"chain doesn't cover it. Re-derive it from the verified rows with `hypgraph verify --standing`.")
|
|
190
194
|
|
|
191
195
|
|
|
196
|
+
MALFORMED = "the bundle is malformed: a field is missing or of the wrong kind"
|
|
197
|
+
|
|
198
|
+
|
|
192
199
|
def _verify_bundle(b: dict, policy: dict | None = None) -> dict:
|
|
193
200
|
if not isinstance(b, dict) or b.get("format") != BUNDLE_FORMAT:
|
|
194
201
|
return {"ok": False, "problem": f"not a {BUNDLE_FORMAT} bundle"}
|
|
@@ -208,7 +215,12 @@ def _verify_bundle(b: dict, policy: dict | None = None) -> dict:
|
|
|
208
215
|
continue
|
|
209
216
|
if _sha(ev["body"]) != ev["hash"]:
|
|
210
217
|
return {"ok": False, "broken_at": ev["seq"], "problem": "event body does not match its hash"}
|
|
211
|
-
|
|
218
|
+
try:
|
|
219
|
+
body = json.loads(ev["body"])
|
|
220
|
+
except ValueError:
|
|
221
|
+
body = None
|
|
222
|
+
if not isinstance(body, dict):
|
|
223
|
+
return {"ok": False, "broken_at": ev["seq"], "problem": "event body isn't a JSON object"}
|
|
212
224
|
if body.get("prev") != prev:
|
|
213
225
|
return {"ok": False, "broken_at": ev["seq"], "problem": "chain broken (prev does not match)"}
|
|
214
226
|
prev, checked = ev["hash"], checked + 1
|
|
@@ -226,18 +238,24 @@ def _verify_bundle(b: dict, policy: dict | None = None) -> dict:
|
|
|
226
238
|
hint = (f" (the bundle names {stated} as its importer, which the chain doesn't cover; if you trust that, "
|
|
227
239
|
f"verify with --importer {stated})" if stated != importer else "")
|
|
228
240
|
return {"ok": False, "problem": rows["problem"] + hint}
|
|
241
|
+
problem = _scope_problem(b, tables, red)
|
|
242
|
+
if problem:
|
|
243
|
+
return {"ok": False, "problem": problem}
|
|
229
244
|
problem = _derived_problem(b, tables)
|
|
230
245
|
if problem:
|
|
231
246
|
return {"ok": False, "problem": f"the derived views contradict the verified record: {problem}"}
|
|
232
247
|
out = {"ok": True, "checked": checked, "head": prev, "complete": red == 0, "redacted": red,
|
|
233
248
|
"nodes": len(tables["nodes"]), "edges": len(tables["edges"]), "unchecked": rows["unchecked"],
|
|
234
249
|
"coverage": "complete" if not rows["unchecked"] and not red else "partial",
|
|
250
|
+
"views": "none" if b.get("derived") is None else "checked",
|
|
235
251
|
"policy": {"trusted": sorted(policy or {}), "importer": importer},
|
|
236
252
|
"standing": {"checked": False, "note": STANDING_NOTE}}
|
|
237
253
|
notes = []
|
|
238
254
|
if red:
|
|
239
|
-
notes.append(f"{red} event(s)
|
|
240
|
-
"
|
|
255
|
+
notes.append(f"{red} event(s) are redacted. The bundle says they lie outside this investigation, but a "
|
|
256
|
+
"redacted event keeps only its hash, so that can't be checked: a change hidden among them (a "
|
|
257
|
+
"withdrawal, say) would not show. Only the full record, verified against the published head, "
|
|
258
|
+
"rules that out.")
|
|
241
259
|
if stated != importer:
|
|
242
260
|
notes.append(f"The bundle names {stated} as its importer; the chain doesn't cover that, so {importer} was "
|
|
243
261
|
"used.")
|
|
@@ -259,10 +277,51 @@ def _title(body: dict) -> str:
|
|
|
259
277
|
return str(t)[:300]
|
|
260
278
|
|
|
261
279
|
|
|
280
|
+
def _scope_of(b: dict) -> str:
|
|
281
|
+
"""The investigation a bundle says it is scoped to ("" for the whole record). Not covered by the chain."""
|
|
282
|
+
sc = b.get("scope")
|
|
283
|
+
return str(sc.get("inv") or "") if isinstance(sc, dict) else ""
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _scope_problem(b: dict, tables: dict, redacted: int) -> str:
|
|
287
|
+
"""The scope isn't hashed, so it must be the one shape export() writes: a scoped bundle names an investigation
|
|
288
|
+
node and holds only that investigation's nodes; only a scoped bundle redacts events. Otherwise any node could
|
|
289
|
+
pose as the investigation, or a whole record pass as one investigation, and hide the rest behind a verified
|
|
290
|
+
chain."""
|
|
291
|
+
inv = _scope_of(b)
|
|
292
|
+
if not inv:
|
|
293
|
+
if redacted:
|
|
294
|
+
return (f"the bundle has no scope but {redacted} redacted event(s): only an export of one investigation "
|
|
295
|
+
"redacts events, so this is a cut of the record presented as the whole of it")
|
|
296
|
+
return ""
|
|
297
|
+
nodes = {n["id"]: n for n in tables["nodes"]}
|
|
298
|
+
n = nodes.get(inv)
|
|
299
|
+
if n is None:
|
|
300
|
+
return f"the bundle's scope names {inv}, which the record doesn't hold"
|
|
301
|
+
if n["type"] != "investigation":
|
|
302
|
+
return (f"the bundle's scope names {n['code'] or inv}, a {n['type']}, not an investigation: a scope is "
|
|
303
|
+
"always an investigation")
|
|
304
|
+
other = [x for x in tables["nodes"] if x["id"] != inv and x["inv"] != inv]
|
|
305
|
+
if other:
|
|
306
|
+
return (f"the bundle's scope is {n['code'] or inv}, but it holds {len(other)} node(s) of other "
|
|
307
|
+
f"investigations ({other[0]['code'] or other[0]['id']} first): an export of one investigation holds "
|
|
308
|
+
"only its own")
|
|
309
|
+
return ""
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _eid(v: Any) -> int | None:
|
|
313
|
+
"""A link id as the browser's verifier reads one (Number.isInteger): 7 and 7.0, not true or "7"."""
|
|
314
|
+
if isinstance(v, bool) or not isinstance(v, (int, float)) or not float(v).is_integer():
|
|
315
|
+
return None
|
|
316
|
+
return int(v)
|
|
317
|
+
|
|
318
|
+
|
|
262
319
|
def _derived_problem(b: dict, tables: dict) -> str:
|
|
263
320
|
"""The derived views are presentation, but a viewer shows them beside a verified chain: every fact in them that
|
|
264
|
-
the rows fix — which nodes and live links each
|
|
265
|
-
|
|
321
|
+
the rows fix — which investigations there are, which nodes and live links each has, each node's type, code,
|
|
322
|
+
author, time, version, title and lifecycle, each link's ends and fields — must be present and agree with the
|
|
323
|
+
verified rows. A view that leaves a fact out fails: a viewer would fill the gap with a default (a withdrawn claim
|
|
324
|
+
shown as active). The rest of standing can't be checked this way."""
|
|
266
325
|
d = b.get("derived")
|
|
267
326
|
if d is None:
|
|
268
327
|
return ""
|
|
@@ -276,33 +335,66 @@ def _derived_problem(b: dict, tables: dict) -> str:
|
|
|
276
335
|
withdrawn = {w["node"] for w in tables["withdrawals"]}
|
|
277
336
|
retracted = {int(r["edge"]) for r in tables["retractions"]}
|
|
278
337
|
live = {int(e["id"]): e for e in tables["edges"] if int(e["id"]) not in retracted}
|
|
279
|
-
scope =
|
|
338
|
+
scope = _scope_of(b)
|
|
280
339
|
invs = {scope} if scope else {i for i, n in nodes.items() if n["type"] == "investigation"}
|
|
340
|
+
replaced: dict[str, list] = {}
|
|
341
|
+
for e in live.values():
|
|
342
|
+
if e["rel"] in SAME_TYPE:
|
|
343
|
+
replaced.setdefault(e["dst"], []).append(e["src"])
|
|
344
|
+
|
|
345
|
+
def lifecycle(nid: str, chains: bool, seen: frozenset = frozenset()) -> str:
|
|
346
|
+
"""derive.lifecycle on the verified rows. Since 0.4 a replacement that is itself superseded still replaces
|
|
347
|
+
(``chains``); 0.3 counted only an active one. Withdrawn is the same under both."""
|
|
348
|
+
if nid in withdrawn:
|
|
349
|
+
return "withdrawn"
|
|
350
|
+
counts = ("active", "superseded") if chains else ("active",)
|
|
351
|
+
for s in replaced.get(nid, []):
|
|
352
|
+
if s not in seen and lifecycle(s, chains, seen | {nid}) in counts:
|
|
353
|
+
return "superseded"
|
|
354
|
+
if nodes[nid]["type"] == "investigation":
|
|
355
|
+
return latest.get(nid, (0, {}))[1].get("state") or "active"
|
|
356
|
+
return "active"
|
|
281
357
|
|
|
282
358
|
def facts(x: dict, where: str) -> str:
|
|
283
|
-
|
|
359
|
+
if not isinstance(x, dict) or not isinstance(x.get("id"), str):
|
|
360
|
+
return f"{where} shows a node without its id"
|
|
361
|
+
n = nodes.get(x["id"])
|
|
284
362
|
if not n:
|
|
285
|
-
return f"{where} shows {x
|
|
363
|
+
return f"{where} shows {x['id']}, which the record doesn't hold"
|
|
364
|
+
name = n["code"] or n["id"]
|
|
286
365
|
v, body = latest.get(n["id"], (0, {}))
|
|
287
366
|
want = {"type": n["type"], "code": n["code"], "inv": n["inv"], "by": n["created_by"], "at": n["created_at"],
|
|
288
367
|
"v": v, "title": _title(body), "kind": body.get("kind") or body.get("verdict") or ""}
|
|
289
368
|
for k, w in want.items():
|
|
290
|
-
if k in x
|
|
291
|
-
return f"{where} shows {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
369
|
+
if k not in x:
|
|
370
|
+
return f"{where} shows {name} without its {k}"
|
|
371
|
+
if x[k] != w:
|
|
372
|
+
return f"{where} shows {name} with {k} {_j(x[k])}; the record has {_j(w)}"
|
|
373
|
+
st = x.get("state")
|
|
374
|
+
if not isinstance(st, dict) or "lifecycle" not in st:
|
|
375
|
+
return f"{where} shows {name} without its lifecycle"
|
|
376
|
+
w = lifecycle(n["id"], True)
|
|
377
|
+
allowed = {w, lifecycle(n["id"], False)}
|
|
378
|
+
if scope and n["id"] not in withdrawn:
|
|
379
|
+
allowed.add("superseded") # a scoped bundle leaves out links to other investigations: one may replace it
|
|
380
|
+
if st["lifecycle"] not in allowed:
|
|
381
|
+
return f"{where} shows {name} as {_j(st['lifecycle'])}; the record makes it {_j(w)}"
|
|
296
382
|
return ""
|
|
297
|
-
by_inv = d.get("by_inv")
|
|
298
|
-
if set(by_inv) != invs:
|
|
383
|
+
by_inv = d.get("by_inv")
|
|
384
|
+
if not isinstance(by_inv, dict) or set(by_inv) != invs:
|
|
299
385
|
return "the views don't cover the record's investigations"
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
386
|
+
listed = d.get("investigations")
|
|
387
|
+
if not isinstance(listed, list):
|
|
388
|
+
return "the investigation list is missing"
|
|
389
|
+
for x in listed:
|
|
390
|
+
if isinstance(x, dict) and isinstance(x.get("id"), str) and x["id"] not in invs:
|
|
391
|
+
return f"the investigation list shows {x['id']}, which isn't in the bundle's scope"
|
|
303
392
|
p = facts(x, "the investigation list")
|
|
304
393
|
if p:
|
|
305
394
|
return p
|
|
395
|
+
ids = [x["id"] for x in listed]
|
|
396
|
+
if len(ids) != len(set(ids)) or set(ids) != invs:
|
|
397
|
+
return "the investigation list doesn't show the record's investigations"
|
|
306
398
|
for inv, v in by_inv.items():
|
|
307
399
|
sg = (v or {}).get("subgraph") or {}
|
|
308
400
|
shown = sg.get("nodes") or []
|
|
@@ -316,14 +408,18 @@ def _derived_problem(b: dict, tables: dict) -> str:
|
|
|
316
408
|
return f"the graph of {nodes[inv]['code'] or inv} doesn't show the nodes the record holds"
|
|
317
409
|
want = {i: e for i, e in live.items() if e["src"] in set(ids) and e["dst"] in set(ids)}
|
|
318
410
|
got = sg.get("edges") or []
|
|
319
|
-
if
|
|
411
|
+
if not all(isinstance(e, dict) and _eid(e.get("id")) is not None for e in got):
|
|
412
|
+
return f"the graph of {nodes[inv]['code'] or inv} shows a link without its id"
|
|
413
|
+
if len(got) != len(want) or {_eid(e["id"]) for e in got} != set(want):
|
|
320
414
|
return f"the graph of {nodes[inv]['code'] or inv} doesn't show the live links the record holds"
|
|
321
415
|
for e in got:
|
|
322
|
-
r = want[
|
|
323
|
-
for k in ("src", "src_v", "rel", "dst", "dst_v", "at", "by", "why"):
|
|
324
|
-
if k in e
|
|
416
|
+
r = want[_eid(e["id"])]
|
|
417
|
+
for k in ("src", "src_v", "rel", "dst", "dst_v", "at", "by", "why", "data"):
|
|
418
|
+
if k not in e:
|
|
419
|
+
return f"the graph shows link {e['id']} without its {k}"
|
|
420
|
+
if k != "data" and e[k] != r[k]:
|
|
325
421
|
return f"the graph shows link {e['id']} with {k} {_j(e[k])}; the record has {_j(r[k])}"
|
|
326
|
-
if
|
|
422
|
+
if e["data"] != json.loads(r["data"]): # as values: 1.0 and 1 are one number
|
|
327
423
|
return f"the graph shows link {e['id']} with other data than the record"
|
|
328
424
|
return ""
|
|
329
425
|
|
|
@@ -279,8 +279,12 @@ def cmd_verify(args) -> int:
|
|
|
279
279
|
trusted = json.loads(Path(args.policy).read_text(encoding="utf-8")) if args.policy else {}
|
|
280
280
|
if args.importer:
|
|
281
281
|
trusted["importer"] = args.importer
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
try:
|
|
283
|
+
b = json.loads(Path(target).read_text(encoding="utf-8"))
|
|
284
|
+
except ValueError:
|
|
285
|
+
b = None
|
|
286
|
+
res = (verify_bundle(b, head=args.head, standing=args.standing, policy=trusted or None) if b is not None
|
|
287
|
+
else {"ok": False, "problem": "the file isn't JSON"})
|
|
284
288
|
else:
|
|
285
289
|
res = anchored(verify_file(target, importer=args.importer or "importer"), args.head)
|
|
286
290
|
ok = res.get("ok")
|
|
@@ -291,6 +295,8 @@ def cmd_verify(args) -> int:
|
|
|
291
295
|
else "\n consistent with itself; to rule out a rewrite, check it against a published head (--head)")
|
|
292
296
|
if ok and res.get("coverage") == "partial":
|
|
293
297
|
text += "\n coverage: PARTIAL — not every row field is vouched for by its event (see below)"
|
|
298
|
+
if ok and res.get("views") == "none":
|
|
299
|
+
text += "\n no derived views: exported without them, so a viewer has nothing to show beyond the rows"
|
|
294
300
|
if ok and res.get("unchecked"):
|
|
295
301
|
text += ("\n not covered (written before events hashed these fields): "
|
|
296
302
|
+ ", ".join(f"{f} ×{n}" for f, n in sorted(res["unchecked"].items())))
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
const VERSION = '0.6.0';
|
|
29
29
|
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
30
30
|
const RISKY = ['requires', 'derived_from', 'based_on'];
|
|
31
|
+
const SAME_TYPE = ['supersedes', 'corrects']; // schema.SAME_TYPE: a replacement of the same type
|
|
31
32
|
const cap = (t) => (t ? t[0].toUpperCase() + t.slice(1) : '');
|
|
32
33
|
|
|
33
34
|
// ── hashing (WebCrypto, with a small fallback for insecure contexts) ─────
|
|
@@ -182,6 +183,22 @@
|
|
|
182
183
|
const titleOf = (b) => cp(b.statement || b.title || b.text || b.aim || b.summary || b.choice || b.citation || b.name
|
|
183
184
|
|| b.path || b.verdict || '', 300);
|
|
184
185
|
|
|
186
|
+
/** The investigation a bundle says it is scoped to ('' for the whole record). Not covered by the chain. */
|
|
187
|
+
const scopeOf = (b) => (b.scope && typeof b.scope === 'object' && !Array.isArray(b.scope) ? String(b.scope.inv || '') : '');
|
|
188
|
+
|
|
189
|
+
/** The scope must be the one shape export() writes (bundle.py _scope_problem): it names an investigation node, the
|
|
190
|
+
* bundle holds only that investigation's nodes, and only a scoped bundle redacts events. */
|
|
191
|
+
function scopeProblem(b, tables, redacted) {
|
|
192
|
+
const inv = scopeOf(b);
|
|
193
|
+
if (!inv) return redacted ? `the bundle has no scope but ${redacted} redacted event(s): only an export of one investigation redacts events, so this is a cut of the record presented as the whole of it` : '';
|
|
194
|
+
const n = tables.nodes.find((x) => x.id === inv);
|
|
195
|
+
if (!n) return `the bundle's scope names ${inv}, which the record doesn't hold`;
|
|
196
|
+
if (n.type !== 'investigation') return `the bundle's scope names ${n.code || inv}, a ${n.type}, not an investigation: a scope is always an investigation`;
|
|
197
|
+
const other = tables.nodes.filter((x) => x.id !== inv && x.inv !== inv);
|
|
198
|
+
if (other.length) return `the bundle's scope is ${n.code || inv}, but it holds ${other.length} node(s) of other investigations (${other[0].code || other[0].id} first): an export of one investigation holds only its own`;
|
|
199
|
+
return '';
|
|
200
|
+
}
|
|
201
|
+
|
|
185
202
|
/** The derived views are presentation; every fact in them the rows fix must agree with the verified rows. */
|
|
186
203
|
function derivedProblem(b, tables) {
|
|
187
204
|
const d = b.derived;
|
|
@@ -191,26 +208,48 @@
|
|
|
191
208
|
tables.versions.forEach((v) => { if (v.v > ((latest.get(v.node) || [0])[0])) latest.set(v.node, [v.v, JSON.parse(v.body)]); });
|
|
192
209
|
const withdrawn = new Set(tables.withdrawals.map((w) => w.node)), retracted = new Set(tables.retractions.map((r) => Number(r.edge)));
|
|
193
210
|
const live = new Map(tables.edges.filter((e) => !retracted.has(Number(e.id))).map((e) => [Number(e.id), e]));
|
|
194
|
-
const scope =
|
|
211
|
+
const scope = scopeOf(b);
|
|
195
212
|
const invs = new Set(scope ? [scope] : [...nodes.values()].filter((n) => n.type === 'investigation').map((n) => n.id));
|
|
213
|
+
const replaced = new Map();
|
|
214
|
+
live.forEach((e) => { if (SAME_TYPE.includes(e.rel)) (replaced.get(e.dst) || replaced.set(e.dst, []).get(e.dst)).push(e.src); });
|
|
215
|
+
// derive.lifecycle on the verified rows; since 0.4 a superseded replacement still replaces (chains), 0.3 counted an active one
|
|
216
|
+
const lifecycle = (nid, chains, seen = new Set()) => {
|
|
217
|
+
if (withdrawn.has(nid)) return 'withdrawn';
|
|
218
|
+
const counts = chains ? ['active', 'superseded'] : ['active'];
|
|
219
|
+
for (const s of replaced.get(nid) || []) if (!seen.has(s) && counts.includes(lifecycle(s, chains, new Set([...seen, nid])))) return 'superseded';
|
|
220
|
+
if (nodes.get(nid).type === 'investigation') return ((latest.get(nid) || [0, {}])[1]).state || 'active';
|
|
221
|
+
return 'active';
|
|
222
|
+
};
|
|
196
223
|
const facts = (x, where) => {
|
|
197
|
-
|
|
198
|
-
|
|
224
|
+
if (!x || typeof x !== 'object' || typeof x.id !== 'string') return `${where} shows a node without its id`;
|
|
225
|
+
const n = nodes.get(x.id);
|
|
226
|
+
if (!n) return `${where} shows ${x.id}, which the record doesn't hold`;
|
|
227
|
+
const name = n.code || n.id;
|
|
199
228
|
const [v, body] = latest.get(n.id) || [0, {}];
|
|
200
229
|
const want = { type: n.type, code: n.code, inv: n.inv, by: n.created_by, at: n.created_at, v, title: titleOf(body),
|
|
201
230
|
kind: body.kind || body.verdict || '' };
|
|
202
|
-
for (const [k, w] of Object.entries(want))
|
|
203
|
-
|
|
204
|
-
|
|
231
|
+
for (const [k, w] of Object.entries(want)) {
|
|
232
|
+
if (!(k in x)) return `${where} shows ${name} without its ${k}`;
|
|
233
|
+
if (!same(x[k], w)) return `${where} shows ${name} with ${k} ${JSON.stringify(x[k])}; the record has ${JSON.stringify(w)}`;
|
|
234
|
+
}
|
|
235
|
+
const st = x.state;
|
|
236
|
+
if (!st || typeof st !== 'object' || !('lifecycle' in st)) return `${where} shows ${name} without its lifecycle`;
|
|
237
|
+
const w = lifecycle(n.id, true), allowed = new Set([w, lifecycle(n.id, false)]);
|
|
238
|
+
if (scope && !withdrawn.has(n.id)) allowed.add('superseded'); // a scoped bundle leaves out links to other investigations
|
|
239
|
+
if (!allowed.has(st.lifecycle)) return `${where} shows ${name} as ${JSON.stringify(st.lifecycle)}; the record makes it ${JSON.stringify(w)}`;
|
|
205
240
|
return '';
|
|
206
241
|
};
|
|
207
|
-
const byInv = d.by_inv
|
|
208
|
-
const keys = Object.keys(byInv);
|
|
209
|
-
if (keys.length !== invs.size || !keys.every((k) => invs.has(k))) return "the views don't cover the record's investigations";
|
|
210
|
-
|
|
211
|
-
|
|
242
|
+
const byInv = d.by_inv;
|
|
243
|
+
const keys = byInv && typeof byInv === 'object' && !Array.isArray(byInv) ? Object.keys(byInv) : null;
|
|
244
|
+
if (!keys || keys.length !== invs.size || !keys.every((k) => invs.has(k))) return "the views don't cover the record's investigations";
|
|
245
|
+
const listed = d.investigations;
|
|
246
|
+
if (!Array.isArray(listed)) return 'the investigation list is missing';
|
|
247
|
+
for (const x of listed) {
|
|
248
|
+
if (x && typeof x === 'object' && typeof x.id === 'string' && !invs.has(x.id)) return `the investigation list shows ${x.id}, which isn't in the bundle's scope`;
|
|
212
249
|
const p = facts(x, 'the investigation list'); if (p) return p;
|
|
213
250
|
}
|
|
251
|
+
const listedIds = listed.map((x) => x.id), listedSet = new Set(listedIds);
|
|
252
|
+
if (listedIds.length !== listedSet.size || listedSet.size !== invs.size || ![...invs].every((i) => listedSet.has(i))) return "the investigation list doesn't show the record's investigations";
|
|
214
253
|
for (const [inv, v] of Object.entries(byInv)) {
|
|
215
254
|
const sg = (v || {}).subgraph || {}, shown = sg.nodes || [], name = (nodes.get(inv) || {}).code || inv;
|
|
216
255
|
for (const x of shown) { const p = facts(x, `the graph of ${name}`); if (p) return p; }
|
|
@@ -220,11 +259,15 @@
|
|
|
220
259
|
if (ids.length !== idset.size || (!covers && !(mine.size > ids.length && ids.length >= 5000))) return `the graph of ${name} doesn't show the nodes the record holds`;
|
|
221
260
|
const want = new Map([...live].filter(([, e]) => idset.has(e.src) && idset.has(e.dst)));
|
|
222
261
|
const got = sg.edges || [];
|
|
223
|
-
if (
|
|
262
|
+
if (!got.every((e) => e && typeof e === 'object' && Number.isInteger(e.id))) return `the graph of ${name} shows a link without its id`;
|
|
263
|
+
if (got.length !== want.size || new Set(got.map((e) => e.id)).size !== got.length || !got.every((e) => want.has(e.id))) return `the graph of ${name} doesn't show the live links the record holds`;
|
|
224
264
|
for (const e of got) {
|
|
225
|
-
const r = want.get(
|
|
226
|
-
for (const k of ['src', 'src_v', 'rel', 'dst', 'dst_v', 'at', 'by', 'why'
|
|
227
|
-
|
|
265
|
+
const r = want.get(e.id);
|
|
266
|
+
for (const k of ['src', 'src_v', 'rel', 'dst', 'dst_v', 'at', 'by', 'why', 'data']) {
|
|
267
|
+
if (!(k in e)) return `the graph shows link ${e.id} without its ${k}`;
|
|
268
|
+
if (k !== 'data' && !same(e[k], r[k])) return `the graph shows link ${e.id} with ${k} ${JSON.stringify(e[k])}; the record has ${JSON.stringify(r[k])}`;
|
|
269
|
+
}
|
|
270
|
+
if (!same(e.data, JSON.parse(r.data))) return `the graph shows link ${e.id} with other data than the record`;
|
|
228
271
|
}
|
|
229
272
|
}
|
|
230
273
|
return '';
|
|
@@ -251,7 +294,15 @@
|
|
|
251
294
|
return '';
|
|
252
295
|
}
|
|
253
296
|
|
|
297
|
+
const MALFORMED = 'the bundle is malformed: a field is missing or of the wrong kind';
|
|
254
298
|
async function verifyBundle(b, head = '', opts = {}) {
|
|
299
|
+
try { return await verifyBundleRaw(b, head, opts); } catch (e) {
|
|
300
|
+
if (e instanceof TypeError || e instanceof SyntaxError || e instanceof RangeError) return { ok: false, problem: MALFORMED };
|
|
301
|
+
throw e;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function verifyBundleRaw(b, head = '', opts = {}) {
|
|
255
306
|
if (!b || b.format !== 'hypgraph/1-bundle') return { ok: false, problem: 'not a hypgraph/1-bundle' };
|
|
256
307
|
const policy = opts.policy || null;
|
|
257
308
|
const pp = policyProblem(b, policy);
|
|
@@ -266,7 +317,9 @@
|
|
|
266
317
|
prev = ev.hash; red += 1; continue;
|
|
267
318
|
}
|
|
268
319
|
if (await sha256(ev.body) !== ev.hash) return { ok: false, broken_at: ev.seq, problem: 'event body does not match its hash' };
|
|
269
|
-
|
|
320
|
+
let body = null;
|
|
321
|
+
try { body = JSON.parse(ev.body); } catch { /* not JSON */ }
|
|
322
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return { ok: false, broken_at: ev.seq, problem: "event body isn't a JSON object" };
|
|
270
323
|
if (body.prev !== prev) return { ok: false, broken_at: ev.seq, problem: 'chain broken (prev does not match)' };
|
|
271
324
|
prev = ev.hash; checked += 1;
|
|
272
325
|
events.push(body);
|
|
@@ -278,14 +331,17 @@
|
|
|
278
331
|
const importer = String((policy || {}).importer || 'importer'), stated = String((b.policy || {}).importer || 'importer');
|
|
279
332
|
const rows = await checkRows(events, tables, importer);
|
|
280
333
|
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})` : '') };
|
|
334
|
+
const sp = scopeProblem(b, tables, red);
|
|
335
|
+
if (sp) return { ok: false, problem: sp };
|
|
281
336
|
const dp = derivedProblem(b, tables);
|
|
282
337
|
if (dp) return { ok: false, problem: `the derived views contradict the verified record: ${dp}` };
|
|
283
338
|
const partial = Object.keys(rows.unchecked).length > 0 || red > 0;
|
|
284
339
|
const out = { ok: true, checked, head: prev, complete: red === 0, redacted: red, nodes: tables.nodes.length,
|
|
285
340
|
edges: tables.edges.length, unchecked: rows.unchecked, coverage: partial ? 'partial' : 'complete',
|
|
341
|
+
views: b.derived == null ? 'none' : 'checked',
|
|
286
342
|
policy: { trusted: Object.keys(policy || {}).sort(), importer }, standing: { checked: false, note: STANDING_NOTE } };
|
|
287
343
|
const notes = [];
|
|
288
|
-
if (red) notes.push(`${red} event(s) outside this investigation
|
|
344
|
+
if (red) notes.push(`${red} event(s) are redacted. The bundle says they lie outside this investigation, but a redacted event keeps only its hash, so that can't be checked: a change hidden among them (a withdrawal, say) would not show. Only the full record, verified against the published head, rules that out.`);
|
|
289
345
|
if (stated !== importer) notes.push(`The bundle names ${stated} as its importer; the chain doesn't cover that, so ${importer} was used.`);
|
|
290
346
|
if (notes.length) out.warning = notes.join(' ');
|
|
291
347
|
return anchored(out, head);
|
|
@@ -465,6 +521,8 @@
|
|
|
465
521
|
function standingPill(n) {
|
|
466
522
|
if (!n) return '';
|
|
467
523
|
const s = st(n), rv = reviewOf(n), stale = staleOf(n);
|
|
524
|
+
// no lifecycle: say so rather than default it (a withdrawn claim must never read as active)
|
|
525
|
+
if (s.lifecycle == null) return '<span class="pill warn" title="this view gives no lifecycle for it"><span class="d"></span>unknown</span>';
|
|
468
526
|
if (s.lifecycle === 'withdrawn') return '<span class="pill bad"><span class="d"></span>withdrawn</span>';
|
|
469
527
|
if (s.lifecycle === 'superseded') return '<span class="pill neutral">superseded</span>';
|
|
470
528
|
if (stale.length) return `<span class="pill warn" title="${esc(stale[0])}"><span class="d"></span>stale</span>`;
|
|
@@ -473,10 +531,10 @@
|
|
|
473
531
|
if (rv === 'checked') return '<span class="pill ok"><span class="d"></span>checked</span>';
|
|
474
532
|
if (rv === 'unchecked') return '<span class="pill neutral">unchecked</span>';
|
|
475
533
|
if (rv === 'needs_revalidation') return '<span class="pill warn">re-check</span>';
|
|
476
|
-
return `<span class="pill neutral">${esc(s.lifecycle
|
|
534
|
+
return `<span class="pill neutral">${esc(s.lifecycle)}</span>`;
|
|
477
535
|
}
|
|
478
|
-
const standingKey = (n) => { const s = st(n), rv = reviewOf(n); return s.lifecycle === 'withdrawn' ? 'withdrawn' : s.lifecycle === 'superseded' ? 'superseded'
|
|
479
|
-
: staleOf(n).length ? 'stale' : s.at_risk ? 'at risk' : rv || s.lifecycle
|
|
536
|
+
const standingKey = (n) => { const s = st(n), rv = reviewOf(n); return s.lifecycle == null ? 'unknown' : s.lifecycle === 'withdrawn' ? 'withdrawn' : s.lifecycle === 'superseded' ? 'superseded'
|
|
537
|
+
: staleOf(n).length ? 'stale' : s.at_risk ? 'at risk' : rv || s.lifecycle; };
|
|
480
538
|
|
|
481
539
|
function csv(rows) { return rows.map((r) => r.map((c) => { const s = String(c ?? ''); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; }).join(',')).join('\n'); }
|
|
482
540
|
function download(name, text, type = 'text/plain') {
|