chap-analytics 0.1.0__tar.gz → 0.2.1__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 (70) hide show
  1. chap_analytics-0.2.1/CHANGELOG.md +158 -0
  2. chap_analytics-0.2.1/MANIFEST.in +6 -0
  3. chap_analytics-0.2.1/PKG-INFO +444 -0
  4. chap_analytics-0.2.1/README.md +395 -0
  5. chap_analytics-0.2.1/chap_analytics/__init__.py +64 -0
  6. chap_analytics-0.2.1/chap_analytics/_report/report.css +52 -0
  7. chap_analytics-0.2.1/chap_analytics/_report/report.html +70 -0
  8. chap_analytics-0.2.1/chap_analytics/_report/report.js +517 -0
  9. chap_analytics-0.2.1/chap_analytics/_report/stats.js +577 -0
  10. chap_analytics-0.2.1/chap_analytics/_vendor/LICENSE.vega +27 -0
  11. chap_analytics-0.2.1/chap_analytics/_vendor/LICENSE.vega-embed +27 -0
  12. chap_analytics-0.2.1/chap_analytics/_vendor/LICENSE.vega-lite +27 -0
  13. chap_analytics-0.2.1/chap_analytics/_vendor/README.md +15 -0
  14. chap_analytics-0.2.1/chap_analytics/_vendor/render.js +44 -0
  15. chap_analytics-0.2.1/chap_analytics/_vendor/vega-embed.min.js +7 -0
  16. chap_analytics-0.2.1/chap_analytics/_vendor/vega-lite.min.js +2 -0
  17. chap_analytics-0.2.1/chap_analytics/_vendor/vega.min.js +1 -0
  18. chap_analytics-0.2.1/chap_analytics/briefs.py +461 -0
  19. chap_analytics-0.2.1/chap_analytics/charts.py +924 -0
  20. chap_analytics-0.2.1/chap_analytics/export.py +144 -0
  21. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics/frames.py +104 -17
  22. chap_analytics-0.2.1/chap_analytics/graph.py +1050 -0
  23. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics/load.py +36 -4
  24. chap_analytics-0.2.1/chap_analytics/models.py +109 -0
  25. chap_analytics-0.2.1/chap_analytics/report.py +187 -0
  26. chap_analytics-0.2.1/chap_analytics/sample.py +553 -0
  27. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics/schema.py +38 -5
  28. chap_analytics-0.2.1/chap_analytics/stats.py +993 -0
  29. chap_analytics-0.2.1/chap_analytics/watch.py +199 -0
  30. chap_analytics-0.2.1/chap_analytics.egg-info/PKG-INFO +444 -0
  31. chap_analytics-0.2.1/chap_analytics.egg-info/SOURCES.txt +59 -0
  32. chap_analytics-0.2.1/chap_analytics.egg-info/requires.txt +24 -0
  33. chap_analytics-0.2.1/examples/build_notebook.py +806 -0
  34. chap_analytics-0.2.1/examples/chap_analytics_walkthrough.ipynb +12381 -0
  35. chap_analytics-0.2.1/examples/support_desk.py +200 -0
  36. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/pyproject.toml +15 -8
  37. chap_analytics-0.2.1/tests/js_stats_runner.js +36 -0
  38. chap_analytics-0.2.1/tests/test_charts_and_briefs.py +186 -0
  39. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_differential.py +9 -3
  40. chap_analytics-0.2.1/tests/test_from_url_scheme.py +30 -0
  41. chap_analytics-0.2.1/tests/test_graph.py +217 -0
  42. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_identity.py +2 -1
  43. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_projection.py +52 -0
  44. chap_analytics-0.2.1/tests/test_refusals.py +110 -0
  45. chap_analytics-0.2.1/tests/test_report.py +239 -0
  46. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_sample_and_export.py +2 -0
  47. chap_analytics-0.2.1/tests/test_stats.py +294 -0
  48. chap_analytics-0.2.1/tests/test_successors.py +135 -0
  49. chap_analytics-0.2.1/tests/test_watch_export_models.py +132 -0
  50. chap_analytics-0.1.0/CHANGELOG.md +0 -32
  51. chap_analytics-0.1.0/MANIFEST.in +0 -2
  52. chap_analytics-0.1.0/PKG-INFO +0 -307
  53. chap_analytics-0.1.0/README.md +0 -267
  54. chap_analytics-0.1.0/chap_analytics/__init__.py +0 -45
  55. chap_analytics-0.1.0/chap_analytics/sample.py +0 -281
  56. chap_analytics-0.1.0/chap_analytics.egg-info/PKG-INFO +0 -307
  57. chap_analytics-0.1.0/chap_analytics.egg-info/SOURCES.txt +0 -27
  58. chap_analytics-0.1.0/chap_analytics.egg-info/requires.txt +0 -14
  59. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/LICENSE +0 -0
  60. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics/_patch.py +0 -0
  61. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics/py.typed +0 -0
  62. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics.egg-info/dependency_links.txt +0 -0
  63. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/chap_analytics.egg-info/top_level.txt +0 -0
  64. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/setup.cfg +0 -0
  65. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/conftest.py +0 -0
  66. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_example.py +0 -0
  67. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_handoff_and_routing.py +0 -0
  68. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_notebook.py +0 -0
  69. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_redaction_and_malformed.py +0 -0
  70. {chap_analytics-0.1.0 → chap_analytics-0.2.1}/tests/test_review_passes.py +0 -0
@@ -0,0 +1,158 @@
1
+ # Changelog
2
+
3
+ `chap-analytics` versions on its own track. It is a reader of the protocol,
4
+ so a protocol release moves the coordinator packages together and leaves this
5
+ one where it is until the tables or the analyses change.
6
+
7
+ ## Unreleased
8
+
9
+ ## 0.2.1
10
+
11
+ Reads the logs a 0.3 coordinator writes. Install it with `chap-coordinator`
12
+ 0.3.0 or later where the `coordinator` extra drives a live coordinator.
13
+
14
+ ### Added
15
+
16
+ - **A `refusals` table.** A coordinator now records a member's refused call
17
+ when it was a governed attempt, such as a decision on a review addressed to
18
+ someone else or a pull on an emergency brake the workspace has switched off.
19
+ The entry holds the call under `request` with an `outcome` beside it. The
20
+ new table lists those attempts with the code each was refused with, and no
21
+ other table replays them, so a refused approval never counts as a decision.
22
+ `events` now holds the accepted entries, and the two tables together hold
23
+ the whole log. The assurance shares, in `stats`, the brief and the report,
24
+ count both, since a refusal is linked into the chain like any other entry.
25
+ A chain written before refusals were recorded reads exactly as before. The
26
+ redaction hook applies to a refused call's parameters as it does to an
27
+ accepted one's.
28
+
29
+ ### Changed
30
+
31
+ - **A successor keeps its original's review requirement.** From 0.3.0 the
32
+ coordinators give the successor that `escalate.raise` or
33
+ `control.supersede` makes the review requirement of the task it replaces,
34
+ and require review of a trial successor of `escalate.raise` under
35
+ `modes/1.0`. The replay follows, so completing such a successor opens a
36
+ review in the tables as it does on the coordinator. Read with server state,
37
+ `review_required` is the coordinator's own value, unset where the
38
+ coordinator left it unset, and a review pass the replay inferred on a task
39
+ the coordinator holds no review on is dropped. Read from envelopes alone, a
40
+ chain written by an earlier coordinator shows a successor that coordinator
41
+ completed directly, the successor of a reviewed task or a trial successor
42
+ of `escalate.raise` under `modes/1.0`, as requiring review, in state
43
+ `review_requested` with outcome `open`.
44
+ - **A log without a recorded submission says so.** A coordinator from 0.3.0
45
+ returns receipts from `audit.submit_to_scitt` and keeps no submission on the
46
+ log, so its logs mark no entry as submitted. Where the log holds no
47
+ submission, the assurance brief and the report say none is on record, and
48
+ the assurance chart leaves the submitted share out. The receipts the
49
+ coordinator returns are the record of what was submitted.
50
+
51
+ ### Fixed
52
+
53
+ - **The `fulfils` edge reads the field where the protocol puts it.**
54
+ SPECIFICATION 9.4 carries `fulfils` on the artefact, and the `tasks` table
55
+ reads it from the output a `task.complete` carried. `graph.build` read a
56
+ top-level field of the same name on the envelope instead, so the edge never
57
+ appeared on a chain a producer had actually written, including every chain
58
+ the wrap helper produces. The graph now reads the same field as the table.
59
+ The id is kept as the producer wrote it and lands on a decision node marked
60
+ `referenced`.
61
+
62
+ ## 0.2.0
63
+
64
+ The decision layer: every row of the roadmap's decision table, as a
65
+ statistic with its interval, a chart, and a brief, assembled into a
66
+ self-contained interactive report.
67
+
68
+ - `chap_analytics.stats`: approval, override, rejection and abstention rates
69
+ with Wilson intervals, overall, by group and over time; the refining
70
+ against reversing split; patch-path frequency with the rationales behind
71
+ each cell; the reliability table with expected calibration error and Brier
72
+ score; time to decision as a Kaplan-Meier curve with open reviews
73
+ censored, latency by group and the open queue; promotion readiness as a
74
+ Beta posterior against a threshold and Wald's sequential test; Fleiss'
75
+ kappa on multi-reviewer passes and on deliberation votes, pairwise Cohen's
76
+ kappa and abstentions by category; whisper lapse and handoff acceptance
77
+ rates with response times; chain assurance per period; and a Bernoulli
78
+ CUSUM on the correction rate with its decision interval set by simulation
79
+ for a stated false-alarm rate. Every estimate with a minimum carries a
80
+ `sufficient` flag and the minimum it was judged against.
81
+ - `chap_analytics.graph`: the chain as a typed graph with a fixed ontology
82
+ of nine node types and twenty-five edge types; the lineage of one task as
83
+ a graph and as swimlane rows; the collaboration graph with degree,
84
+ betweenness and per-agent reviewer concentration; oversight coverage of
85
+ shipped outcomes; separation-of-duties findings; a Fruchterman-Reingold
86
+ layout; node-link JSON, GraphML and networkx exports; and the ontology
87
+ drawn as SVG from the declarations.
88
+ - `chap_analytics.charts`: one Vega-Lite specification per chart in the
89
+ decision table, as a plain dictionary that a notebook renders, Altair
90
+ takes, `Chart.save` writes as SVG or PNG, and the report embeds. Charts
91
+ carry the question they answer and the decision they inform.
92
+ - `chap_analytics.briefs`: each decision in a paragraph, with the numbers,
93
+ their intervals, and the decision they support, in words that change with
94
+ the numbers.
95
+ - `chap_analytics.report`: one HTML file with the Vega runtime, the rows
96
+ behind every chart and the page inside it. Headline cards per decision, a
97
+ filter bar for date range, kind, agent, reviewer, mode and tag, brushing
98
+ on the time axis, drill-through from the correction heatmap to the
99
+ rationales, the open queue, and a lineage view for any task. Every
100
+ statistic is recomputed in the browser as the reader filters, by a
101
+ JavaScript mirror of the library that the suite checks against the Python
102
+ functions. Artefact content stays out of the file.
103
+ - `chap_analytics.watch`: a `Watcher` that reads `audit.read` incrementally
104
+ from a sequence cursor over HTTP, an in-process coordinator or any
105
+ callable, re-projects, regenerates the report, and raises each drift alarm
106
+ once with the tasks behind it.
107
+ - `chap_analytics.export`: evaluation cases with the agent's output, the
108
+ corrected output and the rationale, written as JSON lines; prompt-revision
109
+ candidates ranked by frequency and reversing share; and routing
110
+ calibration, the confidence threshold that reaches a target acceptance.
111
+ - `chap_analytics.models`: reviewer severity separated from agent quality
112
+ by a Rasch-style logistic model in numpy, with approximate standard
113
+ errors, which declines to fit below its minimum and says why.
114
+ - `chap_analytics.sample.synthetic`: a workspace generated from stated
115
+ rates (override, rejection, refining share, quorum share and agreement,
116
+ latency, open share, whisper and lapse rates, handoffs, drift, reviewer
117
+ strictness, agent quality, and how confidence relates to outcomes), so
118
+ every statistic is tested against the truth that produced it. The
119
+ coordinator's own clock follows the simulated timeline.
120
+ - `events.signed` and `events.scitt_submitted` columns.
121
+ - A `concerns` edge for the task a deliberation is about; `asked_to` and
122
+ `whispered_to` read from the `to` field of the request envelope; `fulfils`
123
+ read from the `fulfils` field of a `task.complete` envelope where a chain
124
+ carries one.
125
+ - Documentation: the README carries the decision table and the pictures;
126
+ `docs/methods.md`, `docs/graph.md` and `docs/report.md` state each
127
+ method's assumptions and minimums, the ontology, and how the report is
128
+ built. The walkthrough notebook continues from the tables to the decision
129
+ layer, with the charts drawn inline.
130
+ - Extras: `viz` (Altair and vl-convert), `graph` (networkx). numpy is named
131
+ as a dependency alongside pandas.
132
+
133
+ ## 0.1.0
134
+
135
+ First release: stage one of the analytics roadmap.
136
+
137
+ - Eleven documented tables, projected from a CHAP audit chain by replaying
138
+ the envelope stream: `events`, `tasks`, `decisions`, `overrides`,
139
+ `patch_ops`, `participants`, `deliberations`, `votes`, `whispers`,
140
+ `handoffs`, `routing`. Every column declared with its dtype and provenance.
141
+ - Four loaders: a SQLite store, a JSON export, an `audit.read` endpoint, and
142
+ a `Coordinator` in the same process.
143
+ - Review passes kept apart, so a task sent back for revision is measured from
144
+ each pass's own opening and `outcome` reads from the decision that settled
145
+ the last one.
146
+ - The corrected artefact reconstructed from the patch with the coordinator's
147
+ own RFC 6902 semantics, and checked against what the coordinator stored by
148
+ the differential suite.
149
+ - Successors minted by escalation and supersession counted as tasks, with
150
+ what they inherit from the original.
151
+ - `id_certain` and `assignee_certain`, so a row says which of its values are
152
+ inferred.
153
+ - A redactor hook that covers every artefact-bearing field, in both the
154
+ envelope stream and the snapshot.
155
+ - `chap_analytics.sample.support_desk()`, a generated week of review work; a
156
+ walkthrough notebook and a printed report over it.
157
+ - A differential suite: random workspaces against a live coordinator, read
158
+ both ways and checked against what the coordinator holds.
@@ -0,0 +1,6 @@
1
+ include CHANGELOG.md
2
+ include tests/conftest.py
3
+ include tests/js_stats_runner.js
4
+ recursive-include chap_analytics/_vendor *
5
+ recursive-include chap_analytics/_report *
6
+ recursive-include examples *.py *.ipynb
@@ -0,0 +1,444 @@
1
+ Metadata-Version: 2.4
2
+ Name: chap-analytics
3
+ Version: 0.2.1
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
+ Author-email: Brightbeam AI <oss@brightbeam.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/BrightbeamAI/chap/tree/main/packages/chap-analytics
8
+ Project-URL: Repository, https://github.com/BrightbeamAI/chap
9
+ Project-URL: Bugs, https://github.com/BrightbeamAI/chap/issues
10
+ Project-URL: Changelog, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md
11
+ Project-URL: Walkthrough, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb
12
+ Project-URL: Report, https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/report.md
13
+ Project-URL: Specification, https://github.com/BrightbeamAI/chap/blob/main/SPECIFICATION.md
14
+ Project-URL: Roadmap, https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md
15
+ Keywords: chap,audit,analytics,pandas,human-in-the-loop,agent,vega-lite,review,provenance,multi-agent
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Science/Research
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
26
+ Requires-Python: >=3.10
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: pandas>=2.0
30
+ Requires-Dist: numpy>=1.23
31
+ Provides-Extra: coordinator
32
+ Requires-Dist: chap-coordinator>=0.3.0; extra == "coordinator"
33
+ Provides-Extra: viz
34
+ Requires-Dist: altair>=5; extra == "viz"
35
+ Requires-Dist: vl-convert-python>=1.0; extra == "viz"
36
+ Provides-Extra: graph
37
+ Requires-Dist: networkx>=3; extra == "graph"
38
+ Provides-Extra: notebook
39
+ Requires-Dist: nbformat>=5; extra == "notebook"
40
+ Requires-Dist: nbclient>=0.9; extra == "notebook"
41
+ Requires-Dist: ipykernel>=6; extra == "notebook"
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=8; extra == "dev"
44
+ Requires-Dist: chap-coordinator>=0.3.0; extra == "dev"
45
+ Requires-Dist: nbformat>=5; extra == "dev"
46
+ Requires-Dist: altair>=5; extra == "dev"
47
+ Requires-Dist: networkx>=3; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # chap-analytics
51
+
52
+ [![PyPI](https://img.shields.io/pypi/v/chap-analytics?style=flat-square&logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/chap-analytics/)
53
+ [![Python](https://img.shields.io/pypi/pyversions/chap-analytics?style=flat-square)](https://pypi.org/project/chap-analytics/)
54
+ [![Licence](https://img.shields.io/badge/licence-Apache_2.0-7c3aed?style=flat-square)](https://github.com/BrightbeamAI/chap/blob/main/LICENSE)
55
+
56
+ [CHAP](https://github.com/BrightbeamAI/chap) is a protocol for work that
57
+ people and agents do together under review. A coordinator, the CHAP server,
58
+ keeps an audit log of every request it handled: each entry is a JSON-RPC
59
+ envelope, hash-linked to the one before it where the coordinator chains its
60
+ log. That log records what people decided about agent work: what an agent
61
+ produced, what a person changed, why, under which rule, and when. Every
62
+ override carries the patch and the reviewer's reason. Every decision
63
+ carries who made it and when, against the time the review opened. Every
64
+ question an agent asked, every handoff between people, every vote and every
65
+ escalation is an envelope in the same log.
66
+
67
+ This package reads that log back and answers the questions a team running
68
+ agents under review has to answer: how often the work is changed and whether
69
+ that is falling, which corrections keep recurring, whether the agent's
70
+ reported confidence means anything, how long review takes and where it
71
+ waits, when an agent has earned a lighter mode of oversight (CHAP tasks run
72
+ in shadow, trial or production mode), whether reviewers agree with each
73
+ other, who decides on whose work, and whether every outcome that went out
74
+ had a person on its path.
75
+
76
+ Each answer comes as a table with its interval and sample size, a chart, and
77
+ a paragraph that states the number and the decision it supports. All of it
78
+ assembles into one self-contained HTML report that recomputes as the reader
79
+ filters.
80
+
81
+ ## Install
82
+
83
+ ```bash
84
+ pip install chap-analytics
85
+ ```
86
+
87
+ Python 3.10 or later; pandas and numpy are the dependencies. The extras:
88
+
89
+ ```bash
90
+ pip install 'chap-analytics[coordinator]' # read a live coordinator in-process; generate the sample chains
91
+ pip install 'chap-analytics[viz]' # Altair objects; SVG and PNG without Node
92
+ pip install 'chap-analytics[graph]' # hand the graph to networkx
93
+ pip install 'chap-analytics[notebook]' # regenerate the walkthrough notebook with its outputs
94
+ ```
95
+
96
+ Charts render in Jupyter with the base install. Saving a chart as SVG uses
97
+ `vl-convert` where it is installed and otherwise the Vega runtime the package
98
+ ships, under Node. The report needs nothing beyond the base install.
99
+
100
+ ## Quick start
101
+
102
+ ```python
103
+ from chap_analytics import from_sqlite, frames, briefs, charts, report
104
+
105
+ chain = from_sqlite("./chap.db", workspace="wsp_support") # or from_url, from_json, from_coordinator
106
+ f = frames(chain)
107
+
108
+ # Every decision in the table below, answered in a sentence.
109
+ for b in briefs.everything(f):
110
+ print(b.headline)
111
+ print(" ", b.decision)
112
+
113
+ # The same answers as charts. In a notebook, the last line draws it.
114
+ c = charts.everything(f)
115
+ c["rate_over_time"]
116
+
117
+ # One file, opens from disk, filters and recomputes in the browser.
118
+ report.write(f, "support.html")
119
+ ```
120
+
121
+ Without a chain of your own, the package ships two:
122
+
123
+ ```python
124
+ from chap_analytics.sample import support_desk, synthetic
125
+
126
+ f = frames(support_desk()) # a week at a support desk, driven against a real coordinator
127
+ f = frames(synthetic(seed=1, tasks=400, # a workspace generated from stated rates, for checking statistics
128
+ override_rate=0.15, quorum_share=0.25, drift=(300, 0.4)))
129
+ ```
130
+
131
+ Both need `chap-coordinator`, which the `coordinator` extra installs.
132
+
133
+ ## What the chain makes decidable
134
+
135
+ The package is organised around the decisions a team makes about its
136
+ agents. Each row is one question, the statistic that answers it, and the
137
+ chart that shows it. `briefs.everything` states every row that has a number
138
+ in words; `charts.everything` draws every row that has a chart; the report
139
+ carries all of them. A "substantive correction" below is an override that
140
+ reversed the agent's decision, or a rejection.
141
+
142
+ | Decision | Question | Statistic | Chart |
143
+ |---|---|---|---|
144
+ | Revise the prompt, or revise the policy | How often do reviewers change the agent's output, and do they refine it or reverse it? | Override, rejection and approval rates with Wilson intervals; refining share from `intent_preserved` | Rate over time with its interval band; refine and reverse split by task kind |
145
+ | 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
+ | 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
+ | 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 |
149
+ | 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
+ | 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
+ | Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
152
+ | Trust the record | Is the chain verifiable end to end? | Hash-linked, signed and transparency-log-submitted fractions | Coverage over time |
153
+ | Notice a change early | Has the correction rate moved since the last prompt or model change? | Bernoulli CUSUM with a stated false-alarm rate | Control chart with the alarms marked |
154
+ | Trace one outcome to its origin | What led to this action, and who was involved at each step? | The lineage of one task: draft, review, decisions, override, supersession, in order | A swimlane, one lane per participant |
155
+ | Find the bottleneck | Who does most of the reviewing, and does one reviewer decide most of one agent's work? | Betweenness on the collaboration graph; each agent's top reviewer share and Herfindahl index | Collaboration graph, edges weighted by work |
156
+ | Confirm there is a person in the loop | Which outcomes that went out had a person on their path? | Share of shipped outcomes with a human decision on the task or a predecessor, or a person doing the work; `coverage(f).attrs["uncovered"]` names the rest | The lineage view for any uncovered outcome |
157
+ | Separate duties | Does the same actor draft and approve, or propose and accept? | Same-actor pairs across roles, one row per finding in `duties(f)` | The collaboration graph, where a self-review shows as a reviewer deciding on their own work |
158
+
159
+ Every rate carries its sample size and its interval, and every estimate
160
+ with a minimum carries a `sufficient` flag that says whether there is
161
+ enough data to read it. A function that lacks the data to answer says so.
162
+
163
+ ## The pictures
164
+
165
+ Every chart is a Vega-Lite specification built from a frame: a plain
166
+ dictionary, rendered in a notebook, in the report, or saved as SVG or PNG
167
+ for a paper. The pictures below come from a generated quarter with a story
168
+ in it: a correction rate near 15% for most of the period, quorum reviews on
169
+ a quarter of the tasks, one reviewer stricter than the others, and a drift
170
+ upwards late on. The reliability diagram comes from a second generated
171
+ workspace whose agent reports a confidence that tracks its outcomes.
172
+ [`docs/build_images.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/build_images.py)
173
+ is the script that makes them.
174
+
175
+ | | |
176
+ |---|---|
177
+ | ![Override rate over time](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/rate_over_time.png) | ![Drift in the correction rate](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/cusum.png) |
178
+ | The rate per week with its 95% interval. The rise in June is visible here; the chart on the right says when it became more than noise. | The CUSUM, tuned to the shift it should catch and the false-alarm rate it should keep, with the alarms marked. |
179
+ | ![Reliability diagram](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/reliability.png) | ![Promotion readiness](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/promotion.png) |
180
+ | Reported confidence against the share of work accepted as drafted. An agent whose confidence tracks its outcomes sits on the diagonal, and routing thresholds can be read off the curve. | The posterior for the substantive correction rate against the promotion threshold. The area to the left of the line is the chance the agent is already under it. |
181
+ | ![Where corrections land](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/patch_heatmap.png) | ![Refining against reversing](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/refine_reverse.png) |
182
+ | Which part of the artefact reviewers touch, by task kind. In the report, a click on a cell lists the rationales behind it. | Whether corrections kept the agent's decision and improved the wording, or reversed it. The two call for different fixes. |
183
+ | ![Time to first decision](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/survival.png) | ![Sequential test](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/sequential.png) |
184
+ | The share of reviews still waiting after each hour, with open reviews censored rather than dropped. | Wald's sequential probability ratio test on the same rate: it stops at the first crossing and says which way. |
185
+
186
+ ## The chain as a graph
187
+
188
+ The same chain is also a graph. The workspace, its participants, tasks,
189
+ review passes, artefacts, decisions, whispers, deliberations and handoffs
190
+ are nodes. Who delegated, who was assigned, who was asked to review, who
191
+ decided, what an override was based on, which task superseded which, who
192
+ handed work to whom, who asked and who answered, who voted: those are the
193
+ edges. Every edge is an envelope or a field on one. The vocabulary is fixed
194
+ in `graph.NODE_TYPES` and `graph.EDGE_TYPES`, the diagram below is drawn
195
+ from those two tables, and the node-link export carries them under
196
+ `ontology`.
197
+
198
+ <p align="center">
199
+ <img src="https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/ontology.svg" alt="The ontology of a CHAP workspace: nine node types and the edges between them" width="860">
200
+ </p>
201
+
202
+ Two views come out of the graph. The lineage of one task is everything that
203
+ led to it, in time order, with a lane per participant: the picture to start
204
+ from when someone asks what happened. The collaboration graph is the people
205
+ and agents of a workspace with the work that passed between them, where
206
+ load, concentration and separation of duties can be seen at a glance.
207
+
208
+ | | |
209
+ |---|---|
210
+ | ![Lineage of one task](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/lineage.png) | ![Collaboration graph](https://raw.githubusercontent.com/BrightbeamAI/chap/main/packages/chap-analytics/docs/images/collaboration.png) |
211
+
212
+ ```python
213
+ from chap_analytics import graph
214
+
215
+ g = graph.build(f) # the whole chain
216
+ task_id = f.tasks["task_id"].iloc[-1]
217
+ graph.lineage_table(f, task_id) # one task's history, in order
218
+ graph.collaboration(f) # who worked with whom, weighted
219
+ graph.centrality(f) # betweenness per participant
220
+ graph.concentration(f) # each agent's top reviewer and Herfindahl index
221
+ graph.coverage(f) # shipped outcomes with a person on the path
222
+ graph.duties(f) # same-actor pairs that should be separate
223
+ graph.to_node_link(g) # also to_graphml(g) and to_networkx(g)
224
+ graph.ontology_svg() # the diagram above
225
+ ```
226
+
227
+ ## The report
228
+
229
+ `report.write(f, "workspace.html")` produces one HTML file with the Vega
230
+ runtime, the data and the page inside it, so it opens from a file share
231
+ with no network. The front page carries a headline card for every decision
232
+ that has a number: the figure, its interval, the sample size and one line
233
+ on what it means for that workspace. Below it, one section per decision
234
+ with the charts and the brief.
235
+
236
+ The filter bar applies to everything on the page: date range, task kind,
237
+ agent, reviewer, mode and tag. Every chart and every headline recomputes in
238
+ the browser from the embedded rows, using a JavaScript mirror of the
239
+ library's statistics that the test suite checks against the Python numbers.
240
+ Brushing the time axis re-scopes the page. A click on a cell of the
241
+ correction heatmap lists the overrides behind it with their rationales. The
242
+ open queue is a list. A selector opens the lineage of any task.
243
+
244
+ Artefact content stays out of the file. Rationales are included by default
245
+ and can be left out with `rationales=False`.
246
+
247
+ ## Watching a live workspace
248
+
249
+ ```python
250
+ from chap_analytics import watch
251
+
252
+ w = watch.Watcher("http://localhost:8080/chap", "wsp_support",
253
+ report_path="support.html",
254
+ on_alarm=lambda a: print(a.headline))
255
+ w.run(interval_s=300)
256
+ ```
257
+
258
+ On each poll the watcher calls `audit.read`, the protocol method that
259
+ returns the log, from a sequence cursor, then re-projects, runs the drift
260
+ chart and regenerates the report. When the CUSUM crosses its decision
261
+ interval it calls `on_alarm` once with the metric, the task and time it
262
+ moved at, and the changed tasks among the twenty decided before it. The
263
+ source can be an HTTP endpoint, an in-process `Coordinator`, or any callable
264
+ that returns entries from a sequence number.
265
+
266
+ ## Exports
267
+
268
+ ```python
269
+ from chap_analytics import export
270
+
271
+ cases = export.evaluation_cases(f) # one row per corrected task
272
+ export.to_jsonl(cases, "cases.jsonl") # input, agent output, corrected output, rationale, tags
273
+ export.prompt_revision_candidates(f, top=10) # the correction clusters most worth addressing, with examples
274
+ export.routing_calibration(f, target_acceptance=0.9) # the confidence threshold that reaches the target, if any
275
+ ```
276
+
277
+ The task input is available where the chain was read with state (a SQLite
278
+ file or an in-process coordinator); from `audit.read` alone it is null. The
279
+ agent's output and the corrected output come from the envelopes themselves.
280
+
281
+ ## Models
282
+
283
+ ```python
284
+ from chap_analytics import models
285
+
286
+ m = models.reviewer_severity(f)
287
+ m.attrs["fitted"], m.attrs.get("reason")
288
+ ```
289
+
290
+ A reviewer who changes half of what they see may be strict, or may be seeing
291
+ weak work. With several reviewers deciding on several agents the two can be
292
+ separated: one number per agent for quality and one per reviewer for
293
+ severity, fitted as a Rasch-style logistic model in numpy, each with an
294
+ approximate standard error and the count it rests on. Below its minimum the
295
+ function declines to fit and says which minimum it fell short of.
296
+
297
+ ## What each statistic needs
298
+
299
+ A new adopter has a dozen decisions in month one, and kappa, drift
300
+ detection and calibration curves need far more. So every estimate carries
301
+ its uncertainty: rates carry Wilson intervals, the promotion question is
302
+ answered with a posterior rather than a point, the survival curve carries
303
+ Greenwood bands, and each estimate with a minimum carries a `sufficient`
304
+ flag with the minimum it was judged against. The briefs read that flag and
305
+ say so where it is false.
306
+ [`docs/methods.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/docs/methods.md)
307
+ states each method, what it assumes, and the minimum it asks for.
308
+
309
+ ## The tables
310
+
311
+ Underneath the statistics are documented tables, projected from the chain by
312
+ replaying the envelope stream.
313
+
314
+ | Table | Grain |
315
+ |---|---|
316
+ | `events` | one row per accepted audit log entry |
317
+ | `tasks` | one row per task |
318
+ | `decisions` | one row per approve, reject, override or abstain |
319
+ | `overrides` | one row per correction, with its diff summarised |
320
+ | `patch_ops` | one row per RFC 6902 (JSON Patch) operation within an override |
321
+ | `participants` | one row per participant per workspace |
322
+ | `deliberations` | one row per group decision |
323
+ | `votes` | one row per vote |
324
+ | `whispers` | one row per deadline-bound question |
325
+ | `handoffs` | one row per proposed handoff |
326
+ | `routing` | one row per routing decision |
327
+ | `refusals` | one row per refused call the coordinator recorded |
328
+
329
+ Every column is declared in
330
+ [`schema.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/chap_analytics/schema.py)
331
+ with its dtype and its provenance, and `describe()` returns the whole
332
+ contract as text. A column the source lacked a value for is present and
333
+ null, so code downstream sees missingness rather than a `KeyError`.
334
+ `f.to_csv(directory)` writes them all.
335
+
336
+ ```python
337
+ from chap_analytics import from_sqlite, from_url, from_json, from_coordinator
338
+
339
+ from_sqlite("./chap.db", workspace="wsp_support") # the full snapshot
340
+ from_url("http://localhost:8080/chap", "wsp_support") # envelopes, via audit.read
341
+ from_json("export.json") # an audit.read result, a bare entry list, or a snapshot
342
+ from_coordinator(coord, workspace="wsp_support") # a live coordinator, in-process
343
+ ```
344
+
345
+ A SQLite file or a live coordinator carries the workspace snapshot and the
346
+ audit log beside it. `audit.read`, which is what an MCP client can call,
347
+ returns the audit log alone. The tables are replayed from the envelope
348
+ stream, so most of what is worth analysing is available from either source:
349
+ the artefact under review arrives on `review.request` and the patch on
350
+ `decide.override`, so the before and the after of every correction come
351
+ from the envelopes themselves. Three things come from the snapshot alone:
352
+ deliberation and routing outcomes, which the server computes; the assignee
353
+ a `task.route` chose, which `assignee_certain` flags; and the certainty of
354
+ which server-minted id belongs to which creation, which `id_certain` flags.
355
+
356
+ The projection does the work that otherwise gets done in every notebook. It
357
+ parses `confidence` from its decimal-string wire form. It censors open
358
+ work, so `lifetime_s` is null while a task is unsettled and `settled` says
359
+ which rows are censored. It knows when a decision settled a review under
360
+ each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
361
+ review passes apart, so a task sent back for revision is measured from each
362
+ pass's own opening and `outcome` reads from the decision that settled the
363
+ last pass. It reconstructs the corrected artefact from the patch with the
364
+ coordinator's own RFC 6902 semantics. It counts the tasks the server mints
365
+ on escalation and supersession, with what they inherit from the original.
366
+ And it says how sure it is: `id_certain` and `assignee_certain` mark the
367
+ rows where the chain admits more than one reading, so the population to
368
+ draw conclusions from is a filter away.
369
+
370
+ ## Redaction
371
+
372
+ Artefacts hold whatever the agent was working on: customer messages,
373
+ contracts, source code. A redactor sees every one of them before anything
374
+ reaches a table, and what the tables lack the charts, briefs, report and
375
+ exports lack too.
376
+
377
+ ```python
378
+ from chap_analytics import from_sqlite, redact_artefacts, frames
379
+
380
+ f = frames(from_sqlite("./chap.db", redact=redact_artefacts))
381
+ ```
382
+
383
+ What goes: task inputs and outputs, the artefact under review and the
384
+ corrected one, the values a patch writes, free-text whisper answers, lapse
385
+ defaults, the inputs of a successor an escalation or supersession mints,
386
+ and the copies a snapshot holds. What stays, because it is the analysis:
387
+ counts, rates, latencies, tags, policy references, patch paths and
388
+ operations, which option a whisper answer chose, and the words participants
389
+ wrote about the work. A reviewer's rationale, a decline reason, a handoff
390
+ summary and a deliberation question are the people's account of what they
391
+ did. A whisper question is the agent's own words to a person; a deployment
392
+ that needs it removed strips the `question` field before loading.
393
+
394
+ ## Sample data
395
+
396
+ `sample.support_desk()` generates a week at a support desk against a real
397
+ coordinator: an agent drafts replies to tickets and three people review
398
+ them, approving most, correcting some and sending a few back. One declares
399
+ a conflict of interest, work changes hands at a shift change, the agent
400
+ asks two questions and gets one answer, a policy exception goes to a vote,
401
+ and one ticket is escalated to legal.
402
+
403
+ `sample.synthetic()` generates a workspace from stated rates: the override
404
+ and rejection rates, the refining share, how many tasks go to two reviewers
405
+ and how often the second agrees, the latency range, how many are left open,
406
+ whisper and lapse rates, handoffs, a drift point, reviewer strictness and
407
+ agent quality, and how the agent's confidence relates to its outcomes. The
408
+ test suite checks every statistic against the truth that generated it.
409
+
410
+ The [walkthrough notebook](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/chap_analytics_walkthrough.ipynb)
411
+ follows the sample week from the envelopes to the tables and on to every
412
+ decision in the table, with the charts drawn inline, and
413
+ [`examples/support_desk.py`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/examples/support_desk.py)
414
+ prints the same analyses from the command line.
415
+
416
+ ## Tests
417
+
418
+ ```bash
419
+ pip install -e ".[dev]"
420
+ pytest
421
+ ```
422
+
423
+ The fixtures drive a real coordinator, so the suite fails when the protocol
424
+ moves. Statistics are checked against generated chains whose truth is
425
+ known. Every chart is compiled and rendered by the Vega-Lite runtime the
426
+ package ships. The report is checked to be self-contained, and its
427
+ JavaScript is run under Node on the embedded tables and compared with the
428
+ Python numbers. The notebook is executed. A differential suite reads random
429
+ workspaces both ways and checks the tables against what the coordinator
430
+ holds. The chart and report checks need `node` on the path and are skipped
431
+ without it.
432
+
433
+ ## Documentation
434
+
435
+ - [`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
+ - [`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.
437
+ - [`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
+ - [`ANALYTICS_ROADMAP.md`](https://github.com/BrightbeamAI/chap/blob/main/ANALYTICS_ROADMAP.md): the plan this package follows.
439
+ - [`CHANGELOG.md`](https://github.com/BrightbeamAI/chap/blob/main/packages/chap-analytics/CHANGELOG.md).
440
+
441
+ ## Licence
442
+
443
+ Apache 2.0. The report embeds Vega, Vega-Lite and vega-embed, which are
444
+ BSD-3-Clause; their licences ship in `chap_analytics/_vendor`.