chap-analytics 0.2.5__tar.gz → 0.3.0__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.
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/CHANGELOG.md +141 -0
- {chap_analytics-0.2.5/chap_analytics.egg-info → chap_analytics-0.3.0}/PKG-INFO +88 -8
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/README.md +81 -5
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/__init__.py +5 -3
- chap_analytics-0.3.0/chap_analytics/_canonical.py +90 -0
- chap_analytics-0.3.0/chap_analytics/_radar.py +608 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/briefs.py +59 -9
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/charts.py +340 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/export.py +11 -8
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/frames.py +77 -2
- chap_analytics-0.3.0/chap_analytics/ledgers.py +1464 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/sample.py +130 -5
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/schema.py +255 -3
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/stats.py +73 -10
- {chap_analytics-0.2.5 → chap_analytics-0.3.0/chap_analytics.egg-info}/PKG-INFO +88 -8
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics.egg-info/SOURCES.txt +12 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics.egg-info/requires.txt +6 -2
- chap_analytics-0.3.0/examples/build_ledgers_notebook.py +690 -0
- chap_analytics-0.3.0/examples/ledgers_walkthrough.ipynb +7663 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/pyproject.toml +8 -4
- chap_analytics-0.3.0/tests/test_acknowledgements.py +128 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_charts_and_briefs.py +17 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_handoff_and_routing.py +12 -7
- chap_analytics-0.3.0/tests/test_held_passes.py +90 -0
- chap_analytics-0.3.0/tests/test_ledger_analyses.py +245 -0
- chap_analytics-0.3.0/tests/test_ledger_story.py +112 -0
- chap_analytics-0.3.0/tests/test_ledgers.py +945 -0
- chap_analytics-0.3.0/tests/test_notebook.py +159 -0
- chap_analytics-0.3.0/tests/test_radar_sample.py +247 -0
- chap_analytics-0.3.0/tests/test_recorded_decisions.py +98 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_review_passes.py +69 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_watch_export_models.py +15 -0
- chap_analytics-0.2.5/tests/test_notebook.py +0 -63
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/LICENSE +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/MANIFEST.in +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_patch.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_report/report.css +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_report/report.html +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_report/report.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_report/stats.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega-embed +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega-lite +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/README.md +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/render.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega-embed.min.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega-lite.min.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega.min.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/graph.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/load.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/models.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/py.typed +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/report.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics/watch.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics.egg-info/dependency_links.txt +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/chap_analytics.egg-info/top_level.txt +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/examples/build_notebook.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/examples/chap_analytics_walkthrough.ipynb +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/examples/support_desk.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/setup.cfg +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/conftest.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/js_stats_runner.js +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_differential.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_example.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_from_url_scheme.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_graph.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_identity.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_patch_limits.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_projection.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_redaction_and_malformed.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_refusals.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_report.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_sample_and_export.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_stats.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_successors.py +0 -0
- {chap_analytics-0.2.5 → chap_analytics-0.3.0}/tests/test_typescript_store.py +0 -0
|
@@ -4,6 +4,147 @@
|
|
|
4
4
|
so a protocol release moves the coordinator packages together and leaves this
|
|
5
5
|
one where it is until the tables or the analyses change.
|
|
6
6
|
|
|
7
|
+
## 0.3.0
|
|
8
|
+
|
|
9
|
+
Reads the logs of `chap-coordinator` 0.3.5.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Ledgers.** `ledgers.extract` reads the CHAP record into five ledgers
|
|
14
|
+
with one row for each signal:
|
|
15
|
+
- decisions: approve, changes, decline, edit and abstain;
|
|
16
|
+
- judgements: ratings, agents' advice and votes;
|
|
17
|
+
- overrides;
|
|
18
|
+
- outcomes linked to the decisions they test;
|
|
19
|
+
- failures and the calls the coordinator refused.
|
|
20
|
+
|
|
21
|
+
Every row names the entry it reads and carries that entry's chain link.
|
|
22
|
+
It closes with eight properties as flags: attributable, timed, linked,
|
|
23
|
+
reasoned, grounded, consented, scoped and comparable. The ledgers are
|
|
24
|
+
declared in `schema.py` beside the tables, and `describe(LEDGERS)` renders
|
|
25
|
+
them.
|
|
26
|
+
- **Checking a ledger against the record.** `Ledgers.verify()` recomputes
|
|
27
|
+
every row's chain link from its entry, checks every link in the chain, and
|
|
28
|
+
reads the row again from the record. It uses a mirror of the coordinator's
|
|
29
|
+
canonical form, which needs pandas alone. A changed entry and the rows after
|
|
30
|
+
it, an edited row and a missing row are reported, and so is a link the
|
|
31
|
+
record cannot vouch for. A later copy of the log can check ledgers read
|
|
32
|
+
earlier.
|
|
33
|
+
- **Files and a daily run.** `Ledgers.write()` writes CSV, JSON Lines or
|
|
34
|
+
Parquet. Parquet needs the new `parquet` extra. Beside the files goes a
|
|
35
|
+
manifest that names the record by its last seq and chain head, and gives
|
|
36
|
+
the SHA-256 of each ledger and of each file written.
|
|
37
|
+
- `extract(since=...)` reads what arrived after the last run.
|
|
38
|
+
- It reads again any decision whose follow-up answer arrived after the last
|
|
39
|
+
run.
|
|
40
|
+
- **Conventions.** `LedgerSpec` names:
|
|
41
|
+
- the task kinds that record a judgement, an outcome, a failure and a
|
|
42
|
+
proposed change;
|
|
43
|
+
- the fields that hold evidence;
|
|
44
|
+
- a consent basis;
|
|
45
|
+
- the vocabulary of tags and assessments.
|
|
46
|
+
|
|
47
|
+
`ledgers.RADAR` holds the conventions of The Intelligence Radar.
|
|
48
|
+
- **Reading the ledgers.** These functions read the ledgers:
|
|
49
|
+
- `coverage`;
|
|
50
|
+
- `volume`;
|
|
51
|
+
- `choices`;
|
|
52
|
+
- `tag_shares`;
|
|
53
|
+
- `by_actor`;
|
|
54
|
+
- `by_assistant`;
|
|
55
|
+
- `judgements_against_decisions`;
|
|
56
|
+
- `outcomes_against_decisions`;
|
|
57
|
+
- `overturns`;
|
|
58
|
+
- `failures`.
|
|
59
|
+
|
|
60
|
+
They show which reasons recur, how each decider decides, what an
|
|
61
|
+
assistant's model does to the work, which judgements foretell decisions,
|
|
62
|
+
which decisions later outcomes overturn, and what fails. Shares come with
|
|
63
|
+
95% Wilson intervals.
|
|
64
|
+
- **Charts of the ledgers.** `charts.ledger_charts` draws every ledger
|
|
65
|
+
analysis and can mark the dates that a trend is read against. It draws these
|
|
66
|
+
charts:
|
|
67
|
+
- `ledger_coverage`;
|
|
68
|
+
- `ledger_volume`;
|
|
69
|
+
- `decision_mix`;
|
|
70
|
+
- `tag_trend`;
|
|
71
|
+
- `choice_by_actor`;
|
|
72
|
+
- `assistant_trend`;
|
|
73
|
+
- `judgement_decisions`;
|
|
74
|
+
- `overturn_rates`;
|
|
75
|
+
- `failure_mix`.
|
|
76
|
+
- **Pseudonymised copies.** `Ledgers.pseudonymised_copy(salt)` replaces
|
|
77
|
+
every participant with a salted pseudonym. The copy can be shared beyond
|
|
78
|
+
the people who may read the record.
|
|
79
|
+
- **A synthetic sample of The Intelligence Radar's review.**
|
|
80
|
+
`sample.intelligence_radar()` generates six months of synthetic
|
|
81
|
+
contributions to the Radar and drives their review against a real
|
|
82
|
+
coordinator. It plants events for the ledgers to find. None of it
|
|
83
|
+
records real contributions or real people. It can write the workspace to a
|
|
84
|
+
SqliteStore file and the log to JSON Lines. `detailed=True` records more
|
|
85
|
+
about the same work.
|
|
86
|
+
- **The ledgers notebook.** `examples/ledgers_walkthrough.ipynb` builds the
|
|
87
|
+
five ledgers from the synthetic sample, prints each, follows one
|
|
88
|
+
contribution through four of them, and reads and draws each one. The notebook
|
|
89
|
+
tests check every committed notebook was executed in order, and that the
|
|
90
|
+
ledgers notebook shows what a fresh run shows: its text, its tables and the
|
|
91
|
+
data in its charts.
|
|
92
|
+
- **The ledgers story in pictures.** An animated walkthrough and two still
|
|
93
|
+
pictures open the ledgers in the README, `docs/ledgers.md` and the
|
|
94
|
+
notebook. They show how the work in one workspace lands in one record, how
|
|
95
|
+
five ledgers come from that record and the question each ledger answers,
|
|
96
|
+
the pattern each ledger shows in the synthetic sample, and the change to the
|
|
97
|
+
work that each pattern points to. `docs/build_ledger_story.py` draws them
|
|
98
|
+
from the sample. The notebook opens each ledger's section with the question
|
|
99
|
+
that ledger answers.
|
|
100
|
+
- **Where a task was created.** `Frames.created` holds the seq of the entry
|
|
101
|
+
that created each task. The replay pairs each task with that entry.
|
|
102
|
+
|
|
103
|
+
## 0.2.6
|
|
104
|
+
|
|
105
|
+
Reads the logs of `chap-coordinator` 0.3.5.
|
|
106
|
+
|
|
107
|
+
### Added
|
|
108
|
+
|
|
109
|
+
- **Time to open and time to decide.** Coordinators from 0.3.5 record
|
|
110
|
+
`review.acknowledge` when a reviewer opens a review. The decisions table
|
|
111
|
+
gains `acknowledged_at`, `time_to_open_s` and `time_to_decide_s`, and
|
|
112
|
+
`stats.latency` splits each pass's wait the same way, open passes
|
|
113
|
+
included; `open_queue` says which waiting reviews were opened. The
|
|
114
|
+
latency brief reports both medians, counts the waiting reviews nobody
|
|
115
|
+
has opened, and says to tell reviewers when a review arrives where most
|
|
116
|
+
of the wait comes before anyone opens the work. A log without
|
|
117
|
+
acknowledgements reads as before.
|
|
118
|
+
- **Decisions a bridge recorded.** A framework bridge records a decision a
|
|
119
|
+
person made outside CHAP, and from 0.3.5 the call carries
|
|
120
|
+
`via: "bridge-record"`. The decisions table and each pass in
|
|
121
|
+
`stats.latency` carry `via`; `latency_by`, `survival` and the latency
|
|
122
|
+
brief leave out passes a recorded decision settled, and the brief counts
|
|
123
|
+
them. It also points out decisions made within a second of their request,
|
|
124
|
+
which a bridge from before 0.3.5 records unmarked.
|
|
125
|
+
- **The artefact each decision was made on.** The decisions table gains
|
|
126
|
+
`artefact`.
|
|
127
|
+
|
|
128
|
+
### Fixed
|
|
129
|
+
|
|
130
|
+
- **A completion after a review.** From 0.3.5 a task that has held a review
|
|
131
|
+
completes only through a decision, and completing it again opens a new
|
|
132
|
+
pass. The replay read such a completion as the end of the task, so the
|
|
133
|
+
decision that followed landed in the earlier pass. It now holds the
|
|
134
|
+
completion and opens a pass when a decision or an acknowledgement on the
|
|
135
|
+
task follows, or when the state shows the task under review; a log from
|
|
136
|
+
before 0.3.5 reads as before.
|
|
137
|
+
- **The successor of an escalated task.** From 0.3.5 `escalate.raise`
|
|
138
|
+
hands a review on with the work: the successor requires review when the
|
|
139
|
+
original held one. The replay now reads it so.
|
|
140
|
+
- **Approved evaluation cases.** `export.evaluation_cases(include_approved=True)`
|
|
141
|
+
gave approved tasks an empty `agent_output` and `corrected_output`. Both
|
|
142
|
+
now hold the artefact the settling decision approved.
|
|
143
|
+
- **One reviewer.** The concentration brief said reviewing was spread across
|
|
144
|
+
people when one reviewer decided everything on a small sample, and wrote
|
|
145
|
+
"1 reviewers". One reviewer is now named as the only one, and a high
|
|
146
|
+
share on too few decisions says the sample is too small to tell.
|
|
147
|
+
|
|
7
148
|
## 0.2.5
|
|
8
149
|
|
|
9
150
|
Reads the review rounds of `chap-coordinator` 0.3.4.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chap-analytics
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
|
|
5
5
|
Author-email: Brightbeam AI <oss@brightbeam.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -9,6 +9,7 @@ Project-URL: Repository, https://github.com/BrightbeamAI/chap
|
|
|
9
9
|
Project-URL: Bugs, https://github.com/BrightbeamAI/chap/issues
|
|
10
10
|
Project-URL: Changelog, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md
|
|
11
11
|
Project-URL: Walkthrough, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb
|
|
12
|
+
Project-URL: Ledgers, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/ledgers_walkthrough.ipynb
|
|
12
13
|
Project-URL: Report, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md
|
|
13
14
|
Project-URL: Specification, https://github.com/BrightbeamAI/chap/blob/main/SPECIFICATION.md
|
|
14
15
|
Project-URL: Roadmap, https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md
|
|
@@ -29,22 +30,25 @@ License-File: LICENSE
|
|
|
29
30
|
Requires-Dist: pandas>=2.0
|
|
30
31
|
Requires-Dist: numpy>=1.23
|
|
31
32
|
Provides-Extra: coordinator
|
|
32
|
-
Requires-Dist: chap-coordinator>=0.3.
|
|
33
|
+
Requires-Dist: chap-coordinator>=0.3.5; extra == "coordinator"
|
|
33
34
|
Provides-Extra: viz
|
|
34
35
|
Requires-Dist: altair>=5; extra == "viz"
|
|
35
36
|
Requires-Dist: vl-convert-python>=1.0; extra == "viz"
|
|
36
37
|
Provides-Extra: graph
|
|
37
38
|
Requires-Dist: networkx>=3; extra == "graph"
|
|
39
|
+
Provides-Extra: parquet
|
|
40
|
+
Requires-Dist: pyarrow>=14; extra == "parquet"
|
|
38
41
|
Provides-Extra: notebook
|
|
39
42
|
Requires-Dist: nbformat>=5; extra == "notebook"
|
|
40
43
|
Requires-Dist: nbclient>=0.9; extra == "notebook"
|
|
41
44
|
Requires-Dist: ipykernel>=6; extra == "notebook"
|
|
42
45
|
Provides-Extra: dev
|
|
43
46
|
Requires-Dist: pytest>=8; extra == "dev"
|
|
44
|
-
Requires-Dist: chap-coordinator>=0.3.
|
|
47
|
+
Requires-Dist: chap-coordinator>=0.3.5; extra == "dev"
|
|
45
48
|
Requires-Dist: nbformat>=5; extra == "dev"
|
|
46
49
|
Requires-Dist: altair>=5; extra == "dev"
|
|
47
50
|
Requires-Dist: networkx>=3; extra == "dev"
|
|
51
|
+
Requires-Dist: pyarrow>=14; extra == "dev"
|
|
48
52
|
Dynamic: license-file
|
|
49
53
|
|
|
50
54
|
# chap-analytics
|
|
@@ -90,7 +94,8 @@ Python 3.10 or later; pandas and numpy are the dependencies. The extras:
|
|
|
90
94
|
pip install 'chap-analytics[coordinator]' # read a live coordinator in-process; generate the sample chains
|
|
91
95
|
pip install 'chap-analytics[viz]' # Altair objects; SVG and PNG without Node
|
|
92
96
|
pip install 'chap-analytics[graph]' # hand the graph to networkx
|
|
93
|
-
pip install 'chap-analytics[notebook]' # regenerate the
|
|
97
|
+
pip install 'chap-analytics[notebook]' # regenerate the notebooks with their outputs
|
|
98
|
+
pip install 'chap-analytics[parquet]' # write ledgers as Parquet
|
|
94
99
|
```
|
|
95
100
|
|
|
96
101
|
Charts render in Jupyter with the base install. Saving a chart as SVG uses
|
|
@@ -145,7 +150,7 @@ reversed the agent's decision, or a rejection.
|
|
|
145
150
|
| Which part of the prompt to fix | Where do the corrections land in the artefact? | Patch path frequency by task kind | Heatmap of `top_path` (the first segment of the corrected path) against kind, with the rationales behind each cell one click away |
|
|
146
151
|
| Retune the routing thresholds | Does the agent's reported confidence track its outcomes? | Reliability curve, expected calibration error, Brier score | Reliability diagram with per-bin counts |
|
|
147
152
|
| Promote an agent from trial to production | Is the substantive correction rate below the bar, given how many tasks have been seen? | Beta posterior probability that the true rate is under the threshold; Wald's sequential test | Posterior density against the threshold; the sequential test between its bounds |
|
|
148
|
-
| Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue | Survival curve; median and 90th percentile per reviewer |
|
|
153
|
+
| Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue; where reviewers acknowledge opening a review, time to open and time to decide; decisions a framework bridge recorded from outside CHAP counted apart, and decisions too quick to have been read pointed out | Survival curve; median and 90th percentile per reviewer |
|
|
149
154
|
| Rewrite an ambiguous policy | Do reviewers agree with each other on the same artefact? | Fleiss' kappa across multi-reviewer passes; pairwise Cohen's kappa; abstentions by category | Agreement matrix |
|
|
150
155
|
| Clarify the task inputs | How often do agents have to ask, and does anyone answer in time? | Whispers (an agent's deadline-bound question to a person) per task, the share that lapsed unanswered, response time | Lapse rate by asker |
|
|
151
156
|
| Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
|
|
@@ -278,6 +283,63 @@ The task input is available where the chain was read with state (a SQLite
|
|
|
278
283
|
file or an in-process coordinator); from `audit.read` alone it is null. The
|
|
279
284
|
agent's output and the corrected output come from the envelopes themselves.
|
|
280
285
|
|
|
286
|
+
## Ledgers
|
|
287
|
+
|
|
288
|
+

|
|
289
|
+
|
|
290
|
+
*The animation is drawn from the synthetic sample of contributions to
|
|
291
|
+
[TheIntelligenceRadar.com](https://theintelligenceradar.com) that
|
|
292
|
+
`sample.intelligence_radar()` generates.*
|
|
293
|
+
|
|
294
|
+
People, agents and services work on shared tasks in a CHAP workspace, and
|
|
295
|
+
every decision, judgement and correction they make lands in one record. Five
|
|
296
|
+
ledgers come from that record. Each ledger answers its own question: what we
|
|
297
|
+
decide and why, what judgements foretell, what people change and where, which
|
|
298
|
+
decisions held up later, and what fails and what is held up.
|
|
299
|
+
When the ledgers are read across months of work, they show patterns that a
|
|
300
|
+
single decision cannot show. Those patterns point to what to change in how the
|
|
301
|
+
people, agents and services work together.
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
from chap_analytics import charts, ledgers
|
|
305
|
+
|
|
306
|
+
L = ledgers.extract(chain, ledgers.RADAR) # the decision, judgement, override, outcome and failure ledgers
|
|
307
|
+
L.decision.groupby("choice").size() # approve, changes, decline, edit and abstain
|
|
308
|
+
L.verify() # checks every row against its entry and the record
|
|
309
|
+
L.write("ledgers/2026-12-03", format="jsonl") # writes one file per ledger and a manifest of digests
|
|
310
|
+
ledgers.extract(chain, since=last_seq) # reads what arrived since the last run
|
|
311
|
+
L.pseudonymised_copy(salt) # replaces participants with salted pseudonyms
|
|
312
|
+
|
|
313
|
+
ledgers.tag_shares(L, ["source-not-independent"]) # how often a reason recurs each week
|
|
314
|
+
ledgers.by_actor(L, "changes") # how often each decider asks for changes
|
|
315
|
+
ledgers.by_assistant(L, "source-misread") # what an assistant's model does to the work
|
|
316
|
+
ledgers.overturns(L, "decision_task_kind") # which decisions later outcomes overturn
|
|
317
|
+
charts.ledger_charts(L) # draws every ledger analysis
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
A ledger reads one kind of signal out of the record and holds one row for each
|
|
321
|
+
signal. Together the five ledgers hold every decision, judgement, correction,
|
|
322
|
+
outcome and failure. Every row names its entry and carries that entry's chain
|
|
323
|
+
link, so any row can be checked against the record. Each row closes with eight
|
|
324
|
+
properties held as flags: attributable, timed, linked, reasoned, grounded,
|
|
325
|
+
consented, scoped and comparable. Decisions and
|
|
326
|
+
edits come from the review profile's own calls. Judgements, outcomes and
|
|
327
|
+
failures come from conventions a workspace adopts, which `LedgerSpec` names.
|
|
328
|
+
|
|
329
|
+

|
|
330
|
+
|
|
331
|
+
The analyses read the ledgers across many cases:
|
|
332
|
+
|
|
333
|
+
- reasons that recur and whether a change to the work moved them;
|
|
334
|
+
- deciders whose practice differs;
|
|
335
|
+
- what an assistant's model does to the work it helps produce;
|
|
336
|
+
- which judgements foretell the decisions after them;
|
|
337
|
+
- which decisions later outcomes overturn;
|
|
338
|
+
- what fails.
|
|
339
|
+
|
|
340
|
+
[`docs/ledgers.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/ledgers.md)
|
|
341
|
+
covers the columns, the conventions and the analyses.
|
|
342
|
+
|
|
281
343
|
## Models
|
|
282
344
|
|
|
283
345
|
```python
|
|
@@ -360,9 +422,14 @@ which rows are censored. It knows when a decision settled a review under
|
|
|
360
422
|
each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
|
|
361
423
|
review passes apart, so a task sent back for revision is measured from each
|
|
362
424
|
pass's own opening and `outcome` reads from the decision that settled the
|
|
363
|
-
last pass. It
|
|
364
|
-
|
|
365
|
-
|
|
425
|
+
last pass. It tells a decision a person sent from their own client, such as
|
|
426
|
+
a desk, from one a framework bridge recorded in their name, made in an
|
|
427
|
+
interface outside CHAP: `decisions.via` is `bridge-record` for those, and
|
|
428
|
+
the time-to-decision measures leave them out, since their time on the log
|
|
429
|
+
measures no review. It reconstructs the corrected artefact from the patch
|
|
430
|
+
with the coordinator's own RFC 6902 semantics. It counts the tasks the
|
|
431
|
+
server mints on escalation and supersession, with what they inherit from
|
|
432
|
+
the original.
|
|
366
433
|
And it says how sure it is: `id_certain` and `assignee_certain` mark the
|
|
367
434
|
rows where the chain admits more than one reading, so the population to
|
|
368
435
|
draw conclusions from is a filter away.
|
|
@@ -407,6 +474,18 @@ whisper and lapse rates, handoffs, a drift point, reviewer strictness and
|
|
|
407
474
|
agent quality, and how the agent's confidence relates to its outcomes. The
|
|
408
475
|
test suite checks every statistic against the truth that generated it.
|
|
409
476
|
|
|
477
|
+
`sample.intelligence_radar()` generates six months of synthetic contributions
|
|
478
|
+
to The Intelligence Radar and drives their review against a real coordinator.
|
|
479
|
+
The sample holds about 2,600 contributions and some 15,000 entries. It records
|
|
480
|
+
ratings, the advice of a triage agent, outcomes in later editions, failures,
|
|
481
|
+
appeals and three proposed changes, and it plants events for the ledgers to
|
|
482
|
+
find. The data is made up, and none of it records real contributions or real
|
|
483
|
+
people. The sample can write the workspace to a SqliteStore file and the log
|
|
484
|
+
to JSON Lines. The
|
|
485
|
+
[ledgers notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/ledgers_walkthrough.ipynb)
|
|
486
|
+
builds the five ledgers from it, prints each one, follows one contribution
|
|
487
|
+
through four of them, and reads and draws each ledger.
|
|
488
|
+
|
|
410
489
|
The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
|
|
411
490
|
follows the sample week from the envelopes to the tables and on to every
|
|
412
491
|
decision in the table, with the charts drawn inline, and
|
|
@@ -434,6 +513,7 @@ without it.
|
|
|
434
513
|
|
|
435
514
|
- [`docs/methods.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/methods.md): every statistic, what it assumes, what it needs, how to read it.
|
|
436
515
|
- [`docs/graph.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/graph.md): the ontology, the two views, the graph statistics and the exports.
|
|
516
|
+
- [`docs/ledgers.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/ledgers.md): the five ledgers, the eight properties, the conventions a workspace records under, the analyses and the files.
|
|
437
517
|
- [`docs/report.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md): what is in the report and how it is built.
|
|
438
518
|
- [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
|
|
439
519
|
- [`CHANGELOG.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md).
|
|
@@ -41,7 +41,8 @@ Python 3.10 or later; pandas and numpy are the dependencies. The extras:
|
|
|
41
41
|
pip install 'chap-analytics[coordinator]' # read a live coordinator in-process; generate the sample chains
|
|
42
42
|
pip install 'chap-analytics[viz]' # Altair objects; SVG and PNG without Node
|
|
43
43
|
pip install 'chap-analytics[graph]' # hand the graph to networkx
|
|
44
|
-
pip install 'chap-analytics[notebook]' # regenerate the
|
|
44
|
+
pip install 'chap-analytics[notebook]' # regenerate the notebooks with their outputs
|
|
45
|
+
pip install 'chap-analytics[parquet]' # write ledgers as Parquet
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
Charts render in Jupyter with the base install. Saving a chart as SVG uses
|
|
@@ -96,7 +97,7 @@ reversed the agent's decision, or a rejection.
|
|
|
96
97
|
| Which part of the prompt to fix | Where do the corrections land in the artefact? | Patch path frequency by task kind | Heatmap of `top_path` (the first segment of the corrected path) against kind, with the rationales behind each cell one click away |
|
|
97
98
|
| Retune the routing thresholds | Does the agent's reported confidence track its outcomes? | Reliability curve, expected calibration error, Brier score | Reliability diagram with per-bin counts |
|
|
98
99
|
| Promote an agent from trial to production | Is the substantive correction rate below the bar, given how many tasks have been seen? | Beta posterior probability that the true rate is under the threshold; Wald's sequential test | Posterior density against the threshold; the sequential test between its bounds |
|
|
99
|
-
| Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue | Survival curve; median and 90th percentile per reviewer |
|
|
100
|
+
| Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue; where reviewers acknowledge opening a review, time to open and time to decide; decisions a framework bridge recorded from outside CHAP counted apart, and decisions too quick to have been read pointed out | Survival curve; median and 90th percentile per reviewer |
|
|
100
101
|
| Rewrite an ambiguous policy | Do reviewers agree with each other on the same artefact? | Fleiss' kappa across multi-reviewer passes; pairwise Cohen's kappa; abstentions by category | Agreement matrix |
|
|
101
102
|
| Clarify the task inputs | How often do agents have to ask, and does anyone answer in time? | Whispers (an agent's deadline-bound question to a person) per task, the share that lapsed unanswered, response time | Lapse rate by asker |
|
|
102
103
|
| Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
|
|
@@ -229,6 +230,63 @@ The task input is available where the chain was read with state (a SQLite
|
|
|
229
230
|
file or an in-process coordinator); from `audit.read` alone it is null. The
|
|
230
231
|
agent's output and the corrected output come from the envelopes themselves.
|
|
231
232
|
|
|
233
|
+
## Ledgers
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
237
|
+
*The animation is drawn from the synthetic sample of contributions to
|
|
238
|
+
[TheIntelligenceRadar.com](https://theintelligenceradar.com) that
|
|
239
|
+
`sample.intelligence_radar()` generates.*
|
|
240
|
+
|
|
241
|
+
People, agents and services work on shared tasks in a CHAP workspace, and
|
|
242
|
+
every decision, judgement and correction they make lands in one record. Five
|
|
243
|
+
ledgers come from that record. Each ledger answers its own question: what we
|
|
244
|
+
decide and why, what judgements foretell, what people change and where, which
|
|
245
|
+
decisions held up later, and what fails and what is held up.
|
|
246
|
+
When the ledgers are read across months of work, they show patterns that a
|
|
247
|
+
single decision cannot show. Those patterns point to what to change in how the
|
|
248
|
+
people, agents and services work together.
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from chap_analytics import charts, ledgers
|
|
252
|
+
|
|
253
|
+
L = ledgers.extract(chain, ledgers.RADAR) # the decision, judgement, override, outcome and failure ledgers
|
|
254
|
+
L.decision.groupby("choice").size() # approve, changes, decline, edit and abstain
|
|
255
|
+
L.verify() # checks every row against its entry and the record
|
|
256
|
+
L.write("ledgers/2026-12-03", format="jsonl") # writes one file per ledger and a manifest of digests
|
|
257
|
+
ledgers.extract(chain, since=last_seq) # reads what arrived since the last run
|
|
258
|
+
L.pseudonymised_copy(salt) # replaces participants with salted pseudonyms
|
|
259
|
+
|
|
260
|
+
ledgers.tag_shares(L, ["source-not-independent"]) # how often a reason recurs each week
|
|
261
|
+
ledgers.by_actor(L, "changes") # how often each decider asks for changes
|
|
262
|
+
ledgers.by_assistant(L, "source-misread") # what an assistant's model does to the work
|
|
263
|
+
ledgers.overturns(L, "decision_task_kind") # which decisions later outcomes overturn
|
|
264
|
+
charts.ledger_charts(L) # draws every ledger analysis
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
A ledger reads one kind of signal out of the record and holds one row for each
|
|
268
|
+
signal. Together the five ledgers hold every decision, judgement, correction,
|
|
269
|
+
outcome and failure. Every row names its entry and carries that entry's chain
|
|
270
|
+
link, so any row can be checked against the record. Each row closes with eight
|
|
271
|
+
properties held as flags: attributable, timed, linked, reasoned, grounded,
|
|
272
|
+
consented, scoped and comparable. Decisions and
|
|
273
|
+
edits come from the review profile's own calls. Judgements, outcomes and
|
|
274
|
+
failures come from conventions a workspace adopts, which `LedgerSpec` names.
|
|
275
|
+
|
|
276
|
+

|
|
277
|
+
|
|
278
|
+
The analyses read the ledgers across many cases:
|
|
279
|
+
|
|
280
|
+
- reasons that recur and whether a change to the work moved them;
|
|
281
|
+
- deciders whose practice differs;
|
|
282
|
+
- what an assistant's model does to the work it helps produce;
|
|
283
|
+
- which judgements foretell the decisions after them;
|
|
284
|
+
- which decisions later outcomes overturn;
|
|
285
|
+
- what fails.
|
|
286
|
+
|
|
287
|
+
[`docs/ledgers.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/ledgers.md)
|
|
288
|
+
covers the columns, the conventions and the analyses.
|
|
289
|
+
|
|
232
290
|
## Models
|
|
233
291
|
|
|
234
292
|
```python
|
|
@@ -311,9 +369,14 @@ which rows are censored. It knows when a decision settled a review under
|
|
|
311
369
|
each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
|
|
312
370
|
review passes apart, so a task sent back for revision is measured from each
|
|
313
371
|
pass's own opening and `outcome` reads from the decision that settled the
|
|
314
|
-
last pass. It
|
|
315
|
-
|
|
316
|
-
|
|
372
|
+
last pass. It tells a decision a person sent from their own client, such as
|
|
373
|
+
a desk, from one a framework bridge recorded in their name, made in an
|
|
374
|
+
interface outside CHAP: `decisions.via` is `bridge-record` for those, and
|
|
375
|
+
the time-to-decision measures leave them out, since their time on the log
|
|
376
|
+
measures no review. It reconstructs the corrected artefact from the patch
|
|
377
|
+
with the coordinator's own RFC 6902 semantics. It counts the tasks the
|
|
378
|
+
server mints on escalation and supersession, with what they inherit from
|
|
379
|
+
the original.
|
|
317
380
|
And it says how sure it is: `id_certain` and `assignee_certain` mark the
|
|
318
381
|
rows where the chain admits more than one reading, so the population to
|
|
319
382
|
draw conclusions from is a filter away.
|
|
@@ -358,6 +421,18 @@ whisper and lapse rates, handoffs, a drift point, reviewer strictness and
|
|
|
358
421
|
agent quality, and how the agent's confidence relates to its outcomes. The
|
|
359
422
|
test suite checks every statistic against the truth that generated it.
|
|
360
423
|
|
|
424
|
+
`sample.intelligence_radar()` generates six months of synthetic contributions
|
|
425
|
+
to The Intelligence Radar and drives their review against a real coordinator.
|
|
426
|
+
The sample holds about 2,600 contributions and some 15,000 entries. It records
|
|
427
|
+
ratings, the advice of a triage agent, outcomes in later editions, failures,
|
|
428
|
+
appeals and three proposed changes, and it plants events for the ledgers to
|
|
429
|
+
find. The data is made up, and none of it records real contributions or real
|
|
430
|
+
people. The sample can write the workspace to a SqliteStore file and the log
|
|
431
|
+
to JSON Lines. The
|
|
432
|
+
[ledgers notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/ledgers_walkthrough.ipynb)
|
|
433
|
+
builds the five ledgers from it, prints each one, follows one contribution
|
|
434
|
+
through four of them, and reads and draws each ledger.
|
|
435
|
+
|
|
361
436
|
The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
|
|
362
437
|
follows the sample week from the envelopes to the tables and on to every
|
|
363
438
|
decision in the table, with the charts drawn inline, and
|
|
@@ -385,6 +460,7 @@ without it.
|
|
|
385
460
|
|
|
386
461
|
- [`docs/methods.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/methods.md): every statistic, what it assumes, what it needs, how to read it.
|
|
387
462
|
- [`docs/graph.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/graph.md): the ontology, the two views, the graph statistics and the exports.
|
|
463
|
+
- [`docs/ledgers.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/ledgers.md): the five ledgers, the eight properties, the conventions a workspace records under, the analyses and the files.
|
|
388
464
|
- [`docs/report.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md): what is in the report and how it is built.
|
|
389
465
|
- [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
|
|
390
466
|
- [`CHANGELOG.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md).
|
|
@@ -36,14 +36,16 @@ The layers, bottom up:
|
|
|
36
36
|
* ``watch``: a live workspace polled incrementally, with drift alarms.
|
|
37
37
|
* ``export``: evaluation cases, prompt-revision candidates and routing
|
|
38
38
|
thresholds in the shapes other tools take.
|
|
39
|
+
* ``ledgers``: one ledger per kind of signal, one row per signal, each row
|
|
40
|
+
linked back to its entry in the hash chain.
|
|
39
41
|
* ``models``: reviewer severity separated from agent quality.
|
|
40
42
|
* ``sample``: a sample week and a synthetic generator with known truth.
|
|
41
43
|
"""
|
|
42
44
|
from __future__ import annotations
|
|
43
45
|
|
|
44
|
-
__version__ = "0.
|
|
46
|
+
__version__ = "0.3.0"
|
|
45
47
|
|
|
46
|
-
from . import briefs, charts, export, graph, models, sample, stats, watch # noqa: E402
|
|
48
|
+
from . import briefs, charts, export, graph, ledgers, models, sample, stats, watch # noqa: E402
|
|
47
49
|
from .frames import Frames, frames # noqa: E402
|
|
48
50
|
from .load import (
|
|
49
51
|
Chain,
|
|
@@ -60,5 +62,5 @@ __all__ = [
|
|
|
60
62
|
"Chain", "Column", "Frames", "Table", "TABLES", "BY_NAME",
|
|
61
63
|
"describe", "frames", "from_coordinator", "from_json", "from_sqlite",
|
|
62
64
|
"from_url", "redact_artefacts", "sample", "stats", "graph", "charts",
|
|
63
|
-
"briefs", "report", "watch", "export", "models", "__version__",
|
|
65
|
+
"briefs", "report", "watch", "export", "models", "ledgers", "__version__",
|
|
64
66
|
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CHAP's canonical form and hashes, for checking a ledger row against its entry.
|
|
3
|
+
|
|
4
|
+
A mirror of ``chap_coordinator.canonical`` and of ``link_hash`` and
|
|
5
|
+
``entry_record`` in ``chap_coordinator.audit``, kept here so the base install
|
|
6
|
+
can verify a chain with pandas alone. The tests require the two to agree on
|
|
7
|
+
every entry of a generated chain.
|
|
8
|
+
|
|
9
|
+
The canonical form is RFC 8785 (JCS) with CHAP's one restriction: a number is
|
|
10
|
+
an integer within the safe-integer range. A decimal travels as a string.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import hashlib
|
|
15
|
+
import json
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
__all__ = ["canonicalize", "content_hash", "entry_record", "link_hash", "ZERO_HASH"]
|
|
19
|
+
|
|
20
|
+
ZERO_HASH = "sha256:" + "0" * 64
|
|
21
|
+
_MAX_SAFE_INTEGER = 9007199254740991
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _string(s: str) -> str:
|
|
25
|
+
s.encode("utf-8") # an unpaired surrogate raises here, as it does in the coordinator
|
|
26
|
+
return json.dumps(s, ensure_ascii=False)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _canon(obj: Any) -> str:
|
|
30
|
+
if obj is None:
|
|
31
|
+
return "null"
|
|
32
|
+
if obj is True:
|
|
33
|
+
return "true"
|
|
34
|
+
if obj is False:
|
|
35
|
+
return "false"
|
|
36
|
+
if isinstance(obj, str):
|
|
37
|
+
return _string(obj)
|
|
38
|
+
if isinstance(obj, int):
|
|
39
|
+
if abs(obj) > _MAX_SAFE_INTEGER:
|
|
40
|
+
raise ValueError("a CHAP canonical integer is within the safe-integer range")
|
|
41
|
+
return str(obj)
|
|
42
|
+
if isinstance(obj, float):
|
|
43
|
+
if obj != obj or obj in (float("inf"), float("-inf")) or not obj.is_integer():
|
|
44
|
+
raise ValueError("a CHAP canonical number is an integer")
|
|
45
|
+
if abs(int(obj)) > _MAX_SAFE_INTEGER:
|
|
46
|
+
raise ValueError("a CHAP canonical integer is within the safe-integer range")
|
|
47
|
+
return str(int(obj))
|
|
48
|
+
if isinstance(obj, dict):
|
|
49
|
+
for key in obj:
|
|
50
|
+
if not isinstance(key, str):
|
|
51
|
+
raise TypeError("JCS object keys are strings")
|
|
52
|
+
keys = sorted(obj, key=lambda k: k.encode("utf-16-be"))
|
|
53
|
+
return "{" + ",".join(f"{_string(k)}:{_canon(obj[k])}" for k in keys) + "}"
|
|
54
|
+
if isinstance(obj, (list, tuple)):
|
|
55
|
+
return "[" + ",".join(_canon(v) for v in obj) + "]"
|
|
56
|
+
raise TypeError(f"no canonical form for a value of type {type(obj).__name__}")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def canonicalize(obj: Any) -> bytes:
|
|
60
|
+
"""The JCS bytes of a JSON value, under CHAP's integer rule."""
|
|
61
|
+
return _canon(obj).encode("utf-8")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _sha256(data: bytes) -> str:
|
|
65
|
+
return "sha256:" + hashlib.sha256(data).hexdigest()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def content_hash(obj: Any) -> str | None:
|
|
69
|
+
"""
|
|
70
|
+
The digest CHAP gives a JSON artefact, or None where the value has no
|
|
71
|
+
canonical form, as an artefact holding a decimal number has none.
|
|
72
|
+
"""
|
|
73
|
+
if obj is None:
|
|
74
|
+
return None
|
|
75
|
+
try:
|
|
76
|
+
return _sha256(canonicalize(obj))
|
|
77
|
+
except (TypeError, ValueError):
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def entry_record(entry: dict) -> Any:
|
|
82
|
+
"""What an entry's chain link hashes: the call, or a refusal's outcome and request."""
|
|
83
|
+
if entry.get("outcome") is not None:
|
|
84
|
+
return {"outcome": entry.get("outcome"), "request": entry.get("request")}
|
|
85
|
+
return entry.get("envelope")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def link_hash(record: Any, prev: str) -> str:
|
|
89
|
+
"""The chain link: SHA-256 over the record's canonical bytes and the link before it."""
|
|
90
|
+
return _sha256(canonicalize(record) + prev.encode("utf-8"))
|