chap-analytics 0.2.6__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.
Files changed (76) hide show
  1. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/CHANGELOG.md +96 -0
  2. {chap_analytics-0.2.6/chap_analytics.egg-info → chap_analytics-0.3.0}/PKG-INFO +77 -2
  3. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/README.md +72 -1
  4. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/__init__.py +5 -3
  5. chap_analytics-0.3.0/chap_analytics/_canonical.py +90 -0
  6. chap_analytics-0.3.0/chap_analytics/_radar.py +608 -0
  7. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/charts.py +340 -0
  8. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/frames.py +15 -0
  9. chap_analytics-0.3.0/chap_analytics/ledgers.py +1464 -0
  10. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/sample.py +130 -5
  11. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/schema.py +250 -3
  12. {chap_analytics-0.2.6 → chap_analytics-0.3.0/chap_analytics.egg-info}/PKG-INFO +77 -2
  13. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics.egg-info/SOURCES.txt +9 -0
  14. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics.egg-info/requires.txt +4 -0
  15. chap_analytics-0.3.0/examples/build_ledgers_notebook.py +690 -0
  16. chap_analytics-0.3.0/examples/ledgers_walkthrough.ipynb +7663 -0
  17. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/pyproject.toml +7 -3
  18. chap_analytics-0.3.0/tests/test_ledger_analyses.py +245 -0
  19. chap_analytics-0.3.0/tests/test_ledger_story.py +112 -0
  20. chap_analytics-0.3.0/tests/test_ledgers.py +945 -0
  21. chap_analytics-0.3.0/tests/test_notebook.py +159 -0
  22. chap_analytics-0.3.0/tests/test_radar_sample.py +247 -0
  23. chap_analytics-0.2.6/tests/test_notebook.py +0 -63
  24. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/LICENSE +0 -0
  25. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/MANIFEST.in +0 -0
  26. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_patch.py +0 -0
  27. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_report/report.css +0 -0
  28. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_report/report.html +0 -0
  29. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_report/report.js +0 -0
  30. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_report/stats.js +0 -0
  31. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega +0 -0
  32. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega-embed +0 -0
  33. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/LICENSE.vega-lite +0 -0
  34. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/README.md +0 -0
  35. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/render.js +0 -0
  36. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega-embed.min.js +0 -0
  37. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega-lite.min.js +0 -0
  38. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/_vendor/vega.min.js +0 -0
  39. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/briefs.py +0 -0
  40. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/export.py +0 -0
  41. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/graph.py +0 -0
  42. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/load.py +0 -0
  43. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/models.py +0 -0
  44. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/py.typed +0 -0
  45. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/report.py +0 -0
  46. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/stats.py +0 -0
  47. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics/watch.py +0 -0
  48. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics.egg-info/dependency_links.txt +0 -0
  49. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/chap_analytics.egg-info/top_level.txt +0 -0
  50. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/examples/build_notebook.py +0 -0
  51. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/examples/chap_analytics_walkthrough.ipynb +0 -0
  52. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/examples/support_desk.py +0 -0
  53. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/setup.cfg +0 -0
  54. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/conftest.py +0 -0
  55. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/js_stats_runner.js +0 -0
  56. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_acknowledgements.py +0 -0
  57. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_charts_and_briefs.py +0 -0
  58. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_differential.py +0 -0
  59. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_example.py +0 -0
  60. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_from_url_scheme.py +0 -0
  61. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_graph.py +0 -0
  62. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_handoff_and_routing.py +0 -0
  63. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_held_passes.py +0 -0
  64. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_identity.py +0 -0
  65. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_patch_limits.py +0 -0
  66. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_projection.py +0 -0
  67. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_recorded_decisions.py +0 -0
  68. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_redaction_and_malformed.py +0 -0
  69. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_refusals.py +0 -0
  70. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_report.py +0 -0
  71. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_review_passes.py +0 -0
  72. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_sample_and_export.py +0 -0
  73. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_stats.py +0 -0
  74. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_successors.py +0 -0
  75. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_typescript_store.py +0 -0
  76. {chap_analytics-0.2.6 → chap_analytics-0.3.0}/tests/test_watch_export_models.py +0 -0
@@ -4,6 +4,102 @@
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
+
7
103
  ## 0.2.6
8
104
 
9
105
  Reads the logs of `chap-coordinator` 0.3.5.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chap-analytics
3
- Version: 0.2.6
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
@@ -35,6 +36,8 @@ 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"
@@ -45,6 +48,7 @@ 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 walkthrough notebook with its outputs
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
@@ -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
+ ![Animation: the work in a CHAP workspace lands in one record, five ledgers come from that record, and the ledgers show patterns that point to changes in the work](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ledgers-story.gif)
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
+ ![Five ledgers read from one record with example rows and the question each ledger answers](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ledgers-map.png)
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
@@ -412,6 +474,18 @@ whisper and lapse rates, handoffs, a drift point, reviewer strictness and
412
474
  agent quality, and how the agent's confidence relates to its outcomes. The
413
475
  test suite checks every statistic against the truth that generated it.
414
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
+
415
489
  The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
416
490
  follows the sample week from the envelopes to the tables and on to every
417
491
  decision in the table, with the charts drawn inline, and
@@ -439,6 +513,7 @@ without it.
439
513
 
440
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.
441
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.
442
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.
443
518
  - [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
444
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 walkthrough notebook with its outputs
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
@@ -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
+ ![Animation: the work in a CHAP workspace lands in one record, five ledgers come from that record, and the ledgers show patterns that point to changes in the work](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ledgers-story.gif)
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
+ ![Five ledgers read from one record with example rows and the question each ledger answers](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ledgers-map.png)
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
@@ -363,6 +421,18 @@ whisper and lapse rates, handoffs, a drift point, reviewer strictness and
363
421
  agent quality, and how the agent's confidence relates to its outcomes. The
364
422
  test suite checks every statistic against the truth that generated it.
365
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
+
366
436
  The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
367
437
  follows the sample week from the envelopes to the tables and on to every
368
438
  decision in the table, with the charts drawn inline, and
@@ -390,6 +460,7 @@ without it.
390
460
 
391
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.
392
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.
393
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.
394
465
  - [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
395
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.2.6"
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"))