magenta-canon 0.1.0

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 (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +255 -0
  3. package/bin/magenta-canon.mjs +97 -0
  4. package/docs/MAGENTA_VERIFICATION_SPEC.md +122 -0
  5. package/docs/MCP_GATEWAY.md +97 -0
  6. package/docs/NPM_PACKAGING.md +177 -0
  7. package/docs/SECURITY_MODEL.md +96 -0
  8. package/examples/magenta-gateway.config.json +24 -0
  9. package/examples/magenta-gateway.demo.config.json +20 -0
  10. package/examples/mock-mcp-server.mjs +62 -0
  11. package/package.json +171 -0
  12. package/scripts/agent-demo.ts +164 -0
  13. package/scripts/demo.mjs +281 -0
  14. package/scripts/heartbeat-loop.cjs +86 -0
  15. package/scripts/magenta-cli.ts +322 -0
  16. package/scripts/magenta-verify.ts +235 -0
  17. package/scripts/mcp-demo-drive.mjs +52 -0
  18. package/scripts/mcp-gateway.ts +230 -0
  19. package/scripts/post-merge.sh +6 -0
  20. package/scripts/uci-compiler.cjs +286 -0
  21. package/scripts/uci-inspector.cjs +624 -0
  22. package/scripts/uci-inspector.js +35 -0
  23. package/scripts/uci-snippet-generator.cjs +156 -0
  24. package/scripts/uci-snippet-generator.js +28 -0
  25. package/scripts/uci-witness.cjs +102 -0
  26. package/scripts/uci-witness.js +28 -0
  27. package/server/agent-auth.ts +126 -0
  28. package/server/agent-policy.ts +97 -0
  29. package/server/agent-record.ts +96 -0
  30. package/server/authority-containment.ts +582 -0
  31. package/server/authority-topology.ts +826 -0
  32. package/server/behavioral-vector.ts +575 -0
  33. package/server/canon-self-audit/checks/01-spine-body.ts +165 -0
  34. package/server/canon-self-audit/checks/02-deps-coherence.ts +164 -0
  35. package/server/canon-self-audit/checks/03-headers-posture.ts +133 -0
  36. package/server/canon-self-audit/checks/04-mutation-absence.ts +87 -0
  37. package/server/canon-self-audit/checks/05-language-discipline.ts +182 -0
  38. package/server/canon-self-audit/checks/06-validator-health.ts +132 -0
  39. package/server/canon-self-audit/index.ts +29 -0
  40. package/server/canon-self-audit/loopback.ts +53 -0
  41. package/server/canon-self-audit/provenance.ts +73 -0
  42. package/server/canon-self-audit/runner.ts +119 -0
  43. package/server/canon-self-audit/types.ts +236 -0
  44. package/server/canon-spine-validator.selftest.ts +281 -0
  45. package/server/canon-spine-validator.ts +446 -0
  46. package/server/conformance.ts +317 -0
  47. package/server/corrigibility.ts +603 -0
  48. package/server/crypto.ts +133 -0
  49. package/server/economic-trust.ts +511 -0
  50. package/server/execution-gate.ts +553 -0
  51. package/server/execution-receipts.ts +97 -0
  52. package/server/index.ts +351 -0
  53. package/server/ingestion-generators.ts +140 -0
  54. package/server/opus-bridge.ts +117 -0
  55. package/server/origin-proof.ts +245 -0
  56. package/server/persistence.ts +130 -0
  57. package/server/precedent-memory.ts +705 -0
  58. package/server/proposal-containment.ts +747 -0
  59. package/server/routes.ts +2906 -0
  60. package/server/sovereign-auth.ts +353 -0
  61. package/server/ssr-templates.ts +1292 -0
  62. package/server/static.ts +36 -0
  63. package/server/storage.ts +1758 -0
  64. package/server/transparency-log.ts +218 -0
  65. package/server/trust-bootstrap.ts +197 -0
  66. package/server/types/semver.d.ts +7 -0
  67. package/server/ucik-normalize.ts +40 -0
  68. package/server/verification-harness.ts +107 -0
  69. package/server/verification.ts +137 -0
  70. package/server/vite.ts +58 -0
  71. package/server/witness.ts +64 -0
  72. package/shared/canonical.ts +221 -0
  73. package/shared/certificates.ts +233 -0
  74. package/shared/schema.ts +2563 -0
  75. package/tsconfig.json +23 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Royal Ohio
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,255 @@
1
+ <p align="center">
2
+ <img src="docs/magenta-canon-banner.png" alt="Magenta Canon — Verifiable MCP Gateway" width="820">
3
+ </p>
4
+
5
+ # Magenta Canon
6
+
7
+ **A verifiable MCP accountability gateway for AI-agent tool calls.** It sits between an
8
+ MCP host (Claude Code, Claude Desktop, Cursor, …) and downstream MCP tools, and:
9
+
10
+ > **allows authorized calls · blocks unauthorized calls · records both · and
11
+ > produces cryptographic evidence anyone can verify.**
12
+
13
+ ## In 60 seconds
14
+
15
+ AI agents are starting to take real actions through tools (refunds, deploys,
16
+ file writes). The unanswerable question becomes: *was that action authorized, and
17
+ can you prove what actually happened?*
18
+
19
+ Magenta answers it. You point your agent's MCP connection at the **Magenta
20
+ Gateway**. For every tool call it:
21
+
22
+ 1. **gates** the call against an operator-delegated capability (e.g. "may refund
23
+ up to $100") — default **deny**;
24
+ 2. **witnesses** the decision — allowed *and* refused — as a hash-chained, signed
25
+ **execution receipt** in an append-only Merkle transparency log;
26
+ 3. **forwards** allowed calls to the real tool; **blocks** the rest (the tool is
27
+ never even contacted) and returns an error the agent can read.
28
+
29
+ Afterward, anyone can run a **standalone verifier** over the published evidence
30
+ and get `VERIFIED` — *without trusting the server that produced it.* Tamper with
31
+ the record and verification fails. That's the whole point: not "trust our log,"
32
+ but "verify the receipt yourself."
33
+
34
+ ## The proof (we don't rely on claims)
35
+
36
+ Two recorded, reproducible, live end-to-end runs live in the repo:
37
+
38
+ - **[`docs/MCP_GATEWAY_RUN.md`](docs/MCP_GATEWAY_RUN.md)** — the wedge: an agent
39
+ tried two tool calls; one was allowed, one was blocked, both were recorded, the
40
+ downstream tool's *own log* proves the blocked call never arrived, and
41
+ `magenta-verify` returned **VERIFIED**.
42
+ - **[`docs/VERIFICATION_RUN.md`](docs/VERIFICATION_RUN.md)** — the trust anchor:
43
+ operator publishes evidence → independent verifier checks it → a tampered
44
+ bundle **fails** (exit code 1).
45
+
46
+ Why this matters and where it's going: **[`docs/LAUNCH_MANIFESTO.md`](docs/LAUNCH_MANIFESTO.md)** — *Verifiable Agent Actions: stop trusting the log, verify the receipt.*
47
+
48
+ ## Architecture
49
+
50
+ ```
51
+ MCP host (Claude Code / Desktop / Cursor)
52
+ │ tools/call
53
+
54
+ ┌─────────────────────┐ gate + witness ┌──────────────────────────┐
55
+ │ Magenta Gateway │ ─────────────────────▶ │ Control plane │
56
+ │ (stdio proxy) │ │ • capability gate │
57
+ │ │ ◀───── allow/deny ──── │ • transparency-log witness│
58
+ └─────────┬───────────┘ │ • /api/trust/evidence │
59
+ │ forward IF allowed └──────────────┬───────────┘
60
+ ▼ │ signed receipts
61
+ downstream MCP tool ▼
62
+ (refund, search, …) evidence bundle ──▶ magenta-verify
63
+ = VERIFIED ✓
64
+ ```
65
+
66
+ The verifier imports **nothing** from the server — only `node:crypto` + `tweetnacl`
67
+ — so it's independently auditable. See
68
+ [`docs/MAGENTA_VERIFICATION_SPEC.md`](docs/MAGENTA_VERIFICATION_SPEC.md).
69
+
70
+ ## Quickstart — one command
71
+
72
+ ```bash
73
+ npm install
74
+ npm run demo
75
+ ```
76
+
77
+ `npm run demo` runs the entire proof loop locally and narrates it end to end: it
78
+ boots the control plane, bootstraps trust, drives the MCP gateway through one
79
+ **allowed** and one **blocked** tool call, proves the blocked call never reached
80
+ the downstream tool, publishes the evidence bundle, verifies it with the
81
+ standalone `magenta-verify` (→ `VERIFIED`), then tampers with one byte of the
82
+ record and shows verification **fails**. It is local/dev only — an ephemeral port
83
+ and a fresh universe in a temp dir, cleaned up on exit.
84
+
85
+ <details>
86
+ <summary>Prefer the manual steps?</summary>
87
+
88
+ ```bash
89
+ # 1. boot the control plane (the witness + evidence surface) and bootstrap trust
90
+ INTERNAL_API_KEY=operator-secret-xyz MAGENTA_STATE_FILE=/tmp/magenta-state.json \
91
+ PORT=5000 npx tsx server/index.ts &
92
+ # wait until it is healthy before bootstrapping (the server takes a few seconds)
93
+ until curl -sf :5000/api/health >/dev/null 2>&1; do sleep 1; done
94
+ curl -s -X POST :5000/internal/founder/ceremony \
95
+ -H 'X-Internal-Key: operator-secret-xyz' -d '{}'
96
+
97
+ # 2. run the live gateway demo (gateway spawns a real downstream MCP server)
98
+ DOWNSTREAM_LOG=/tmp/downstream-calls.log \
99
+ node scripts/mcp-demo-drive.mjs examples/magenta-gateway.demo.config.json
100
+
101
+ # 3. publish evidence and verify it independently
102
+ curl -s :5000/api/trust/evidence > bundle.json
103
+ npx tsx scripts/magenta-verify.ts bundle.json # → RESULT: VERIFIED
104
+ ```
105
+ </details>
106
+
107
+ Full walkthrough: [`docs/MCP_GATEWAY.md`](docs/MCP_GATEWAY.md).
108
+
109
+ ### From the repo vs. as a CLI
110
+
111
+ - **From a repo checkout** (above): `npm install` then `npm run demo`.
112
+ - **As a package/CLI** — the same three capabilities without cloning internals.
113
+ The first npm release is **`0.1.0`** under the **`next`** dist-tag (a proven
114
+ reference implementation, not production-hosted infra yet), so install from
115
+ `@next`:
116
+
117
+ ```bash
118
+ npx magenta-canon@next demo # the full local proof loop
119
+ npx magenta-canon@next verify <bundle.json> # independently verify an evidence bundle
120
+ npx magenta-canon@next gateway <config.json># run the stdio MCP capability gateway
121
+ ```
122
+
123
+ `verify` exits `0` on `VERIFIED`, `1` on `VERIFICATION FAILED`. The packaged
124
+ `demo` boots a **headless** control plane (no frontend needed). What ships,
125
+ what doesn't, and how to test the package locally:
126
+ [`docs/NPM_PACKAGING.md`](docs/NPM_PACKAGING.md). *(Packaging readiness — not yet
127
+ published to npm.)*
128
+
129
+ ## Connect your MCP host
130
+
131
+ Point Claude Code / Claude Desktop / Cursor at the gateway (it proxies your real
132
+ downstream MCP server, configured in `examples/magenta-gateway.demo.config.json`):
133
+
134
+ ```jsonc
135
+ {
136
+ "mcpServers": {
137
+ "magenta-gated-tools": {
138
+ "command": "npx",
139
+ "args": [
140
+ "tsx",
141
+ "/abs/path/to/magenta-canon/scripts/mcp-gateway.ts",
142
+ "/abs/path/to/magenta-canon/examples/magenta-gateway.demo.config.json"
143
+ ]
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ Every tool call your agent makes now flows through the gate and is witnessed.
150
+
151
+ ## Demo transcript
152
+
153
+ ```
154
+ HANDSHAKE_OK tools=refund
155
+ ALLOWED_CALL isError=false :: refund executed: {"amount_cents":8900,"order_id":"4471"}
156
+ REFUSED_CALL isError=true :: Blocked by Magenta capability gate: exceeds delegated
157
+ refund ceiling (25000 > 10000 cents). Witnessed as receipt e993d86ef721cf94…
158
+
159
+ # downstream tool's own log — ground truth of what actually reached it:
160
+ {"name":"refund","args":{"amount_cents":8900,"order_id":"4471"}} ← only the allowed call
161
+ # the blocked $250 refund is ABSENT — it never reached the tool.
162
+
163
+ $ npx tsx scripts/magenta-verify.ts bundle.json
164
+ [PASS] STH signature verifies
165
+ [PASS] receipt chain intact
166
+ [PASS] recomputed Merkle root == signed STH root
167
+ RESULT: VERIFIED (exit code 0)
168
+ ```
169
+
170
+ ## Security model
171
+
172
+ Magenta gives **accountability**, not magic: an action is gated before it happens
173
+ and recorded so that tampering is detectable **by an independent party**. The key
174
+ honest condition — the insider guarantee holds only when the Signed Tree Head is
175
+ **mirrored to an outside party**; the code emits/verifies it, the mirror is an
176
+ operational step. Read the full threat model and assumptions:
177
+ **[`docs/SECURITY_MODEL.md`](docs/SECURITY_MODEL.md)**.
178
+
179
+ ## Current status (honest)
180
+
181
+ - ✅ **Proven reference implementation** — validated live in a development sandbox.
182
+ - ✅ Capability gate, witness, signed receipts, standalone verifier, stdio MCP gateway — all tested (full suite green).
183
+ - ⏳ **Production durability (single-writer / Postgres) is not yet complete** — the demo uses file-backed persistence.
184
+ - ⏳ The demo's downstream MCP server is **minimal** (real stdio JSON-RPC, enough to prove the path; not a production tool server).
185
+ - ⏳ Transport is **stdio only** — no Streamable HTTP, no hosted/multi-tenant.
186
+ - Capabilities here are **operator-configured (Act 1, proven)**; per-call
187
+ **agent-signed certificates (Act 2)** are a stronger, separate mode also proven
188
+ (`docs/AGENT_ACCOUNTABILITY_SPEC.md`), not exercised by the stdio demo.
189
+
190
+ This is a credible, reproducible wedge — **not** a claim of production readiness.
191
+
192
+ ## Open source vs. paid
193
+
194
+ The verifier, spec, evidence formats, stdio gateway, and the local reference
195
+ control plane are **free and open** under Apache-2.0 (verification must never
196
+ require trusting us); hosted witness, external STH mirroring, multi-tenant /
197
+ team policy control plane, remote HTTP gateway, and compliance reporting are the
198
+ reserved paid surface — **not shipped in this repo**. This boundary is
199
+ **ratified**: [`docs/OSS_VS_PAID.md`](docs/OSS_VS_PAID.md).
200
+
201
+ ## Docs index
202
+
203
+ | Doc | What it is |
204
+ |---|---|
205
+ | [`docs/LAUNCH_MANIFESTO.md`](docs/LAUNCH_MANIFESTO.md) | The category thesis: verifiable agent accountability |
206
+ | [`docs/DEMO_VIDEO_STORYBOARD.md`](docs/DEMO_VIDEO_STORYBOARD.md) | Storyboard + capture plan for the `npm run demo` video/GIF |
207
+ | [`docs/MCP_GATEWAY.md`](docs/MCP_GATEWAY.md) | How the gateway works + run guide |
208
+ | [`docs/MCP_GATEWAY_RUN.md`](docs/MCP_GATEWAY_RUN.md) | Live end-to-end gateway proof |
209
+ | [`docs/VERIFICATION_RUN.md`](docs/VERIFICATION_RUN.md) | Live trust-anchor proof (+ negative control) |
210
+ | [`docs/MAGENTA_VERIFICATION_SPEC.md`](docs/MAGENTA_VERIFICATION_SPEC.md) | Language-agnostic verification spec |
211
+ | [`docs/SECURITY_MODEL.md`](docs/SECURITY_MODEL.md) | Threat model & trust assumptions |
212
+ | [`docs/AGENT_ACCOUNTABILITY_SPEC.md`](docs/AGENT_ACCOUNTABILITY_SPEC.md) | Agent-action accountability (Act 1 + Act 2) |
213
+ | [`docs/OSS_VS_PAID.md`](docs/OSS_VS_PAID.md) | Open/paid boundary (ratified) |
214
+ | [`docs/NPM_PACKAGING.md`](docs/NPM_PACKAGING.md) | What the npm package ships, and how to verify it locally |
215
+
216
+ ## Stack
217
+
218
+ Express + TypeScript backend · React + Tailwind/shadcn frontend · Drizzle ORM
219
+ (PostgreSQL, for the durability roadmap) · Ed25519 + SHA-256 + RFC 6962 Merkle.
220
+
221
+ ---
222
+
223
+ ## Platform operational requirements
224
+
225
+ Magenta Canon also operates as a structural execution-eligibility control plane
226
+ (binary ALLOWED/BLOCKED gating of software artifacts via computed conformance;
227
+ epoch-based append-only baselines; non-circumventable, no override flags). The
228
+ following operational rules are **load-bearing for the live deployment** and must
229
+ be preserved.
230
+
231
+ ### Crawl & SEO enforcement (non-negotiable)
232
+
233
+ All public pages MUST comply with the **Sovereign HTML Base Template** and the
234
+ **Universal Crawl Enforcement Prompt** in `/docs`:
235
+
236
+ 1. Every page renders complete semantic HTML **without** JavaScript.
237
+ 2. Exactly one `<h1>` per page.
238
+ 3. Required: `<main>`, `<article>`, canonical link, JSON-LD.
239
+ 4. Head ordering: charset → viewport → title → description → robots → canonical.
240
+
241
+ Validate by disabling JavaScript and viewing source; if `<title>`, `<meta
242
+ description>`, `<link rel="canonical">`, exactly one `<h1>`, or `<article>` body
243
+ text is missing, **the page is invalid.** Build-time check:
244
+
245
+ ```bash
246
+ npm run crawl:lint
247
+ ```
248
+
249
+ Any PR, agent, or refactor that violates these rules is invalid. See
250
+ `docs/SOVEREIGN_HTML_BASE.html` (canonical template) and
251
+ `docs/CRAWL_ENFORCEMENT.md` (full rules).
252
+
253
+ ## Contact
254
+
255
+ cj@trendinghot.com
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * magenta-canon — CLI entry point for the open-source reference implementation.
4
+ *
5
+ * npx magenta-canon demo run the full local proof loop
6
+ * npx magenta-canon verify <bundle> independently verify an evidence bundle
7
+ * npx magenta-canon gateway <config> run the stdio MCP capability gateway
8
+ * npx magenta-canon --help | --version
9
+ *
10
+ * This is a thin dispatcher: it does NOT change any verifier, witness, evidence,
11
+ * or gate behavior. It locates the package's existing entry scripts and runs
12
+ * them, resolving the `tsx` TypeScript runner robustly (whether hoisted into the
13
+ * consumer's node_modules or nested), so the CLI works the same from a global
14
+ * install, `npx`, or a repo checkout.
15
+ */
16
+ import { spawn } from "node:child_process";
17
+ import { fileURLToPath } from "node:url";
18
+ import { createRequire } from "node:module";
19
+ import { existsSync } from "node:fs";
20
+ import path from "node:path";
21
+
22
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
23
+ const require = createRequire(import.meta.url);
24
+ const pkg = require(path.join(ROOT, "package.json"));
25
+
26
+ // Resolve the tsx CLI (dist/cli.mjs) from wherever it is installed.
27
+ function tsxCli() {
28
+ try {
29
+ const pkgJson = require.resolve("tsx/package.json", { paths: [ROOT] });
30
+ return path.join(path.dirname(pkgJson), "dist", "cli.mjs");
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ const USAGE = `magenta-canon ${pkg.version} — verifiable MCP gateway for AI-agent tool calls
37
+
38
+ Usage:
39
+ magenta-canon demo Run the full local proof loop (allow, block,
40
+ witness, verify, and a tamper control).
41
+ magenta-canon verify <bundle.json> Independently verify an evidence bundle.
42
+ Exit 0 = VERIFIED, 1 = VERIFICATION FAILED.
43
+ magenta-canon gateway <config.json> Run the stdio MCP capability gateway
44
+ (a transparent proxy in front of a tool).
45
+ magenta-canon --help Show this help.
46
+ magenta-canon --version Print the version.
47
+
48
+ Docs: https://github.com/royal-ohio/magenta-canon
49
+ `;
50
+
51
+ function run(cmd, args, opts = {}) {
52
+ const child = spawn(cmd, args, { cwd: ROOT, stdio: "inherit", ...opts });
53
+ child.on("exit", (code, signal) => process.exit(signal ? 1 : code ?? 0));
54
+ child.on("error", (e) => { console.error(`magenta-canon: failed to start: ${e.message}`); process.exit(1); });
55
+ }
56
+
57
+ // Run one of the package's TypeScript entry scripts via tsx.
58
+ function runTs(relScript, args) {
59
+ const cli = tsxCli();
60
+ const script = path.join(ROOT, relScript);
61
+ if (!existsSync(script)) { console.error(`magenta-canon: missing ${relScript} in package`); process.exit(1); }
62
+ if (!cli) { console.error("magenta-canon: could not locate 'tsx' (a dependency). Try reinstalling."); process.exit(1); }
63
+ run(process.execPath, [cli, script, ...args]);
64
+ }
65
+
66
+ const [sub, ...rest] = process.argv.slice(2);
67
+
68
+ switch (sub) {
69
+ case "demo":
70
+ // demo.mjs is plain ESM and resolves tsx + headless mode itself.
71
+ run(process.execPath, [path.join(ROOT, "scripts", "demo.mjs"), ...rest]);
72
+ break;
73
+ case "verify":
74
+ if (!rest[0] || rest[0].startsWith("-") && rest[0] !== "--self-test") {
75
+ // pass flags through (e.g. --self-test, --version); only warn on no target
76
+ }
77
+ runTs("scripts/magenta-verify.ts", rest);
78
+ break;
79
+ case "gateway":
80
+ if (!rest[0]) { console.error("magenta-canon gateway: missing <config.json>\n\n" + USAGE); process.exit(2); }
81
+ runTs("scripts/mcp-gateway.ts", rest);
82
+ break;
83
+ case "-v":
84
+ case "--version":
85
+ case "version":
86
+ console.log(pkg.version);
87
+ break;
88
+ case undefined:
89
+ case "-h":
90
+ case "--help":
91
+ case "help":
92
+ process.stdout.write(USAGE);
93
+ break;
94
+ default:
95
+ console.error(`magenta-canon: unknown command '${sub}'\n\n` + USAGE);
96
+ process.exit(2);
97
+ }
@@ -0,0 +1,122 @@
1
+ # Magenta Verification Spec v1
2
+
3
+ **What this is:** the complete, language-agnostic recipe for verifying a Magenta
4
+ agent-action record **without trusting — or running — the Magenta server.** If you
5
+ can compute SHA-256 and verify an Ed25519 signature, you can implement this in any
6
+ language and independently check that an agent's action log is authentic,
7
+ append-only, and untampered. This is the document that makes "don't trust the
8
+ operator" real: the operator publishes evidence, anyone verifies it.
9
+
10
+ `scripts/magenta-verify.ts` is the reference implementation. It imports nothing
11
+ from the server — only `node:crypto` and `tweetnacl` — so it is itself auditable.
12
+
13
+ ---
14
+
15
+ ## 1. Primitives
16
+
17
+ | Name | Definition |
18
+ |---|---|
19
+ | `sha256hex(bytes)` | lowercase hex of SHA-256 over the bytes |
20
+ | **canonical JSON** | keys sorted by UTF-8 code unit (recursively), no whitespace, `undefined` omitted, `null` preserved. (JCS-like; see §6) |
21
+ | `canonicalHash(obj)` | `sha256hex( utf8( canonicalJSON(obj) ) )` |
22
+ | `chainHash(prev, h)` | `sha256hex( utf8( prev concatenated with h ) )` — both are 64-char hex strings concatenated as text, then hashed |
23
+ | Ed25519 | detached signatures over the **UTF-8 bytes of the message string**; keys and signatures are lowercase hex |
24
+
25
+ ---
26
+
27
+ ## 2. Execution receipt
28
+
29
+ A receipt commits to an action and a decision by hash, and chains to its predecessor:
30
+
31
+ ```
32
+ action_hash = canonicalHash({ action, payload })
33
+ decision_hash = canonicalHash(decision)
34
+ execution_hash = canonicalHash({ action_hash, decision_hash, timestamp })
35
+ receipt_hash = chainHash(previous_receipt_hash, execution_hash)
36
+ ```
37
+
38
+ The first receipt's `previous_receipt_hash` is the genesis value (64 zeros) or the
39
+ server's configured genesis. `receipt_signature` is the issuer's Ed25519 signature
40
+ over the canonical receipt body (all fields except `receipt_signature`).
41
+
42
+ **Chain check** (per receipt `i`, in creation order, oldest-first):
43
+ 1. `execution_hash == canonicalHash({ action_hash, decision_hash, timestamp })`
44
+ 2. `receipt_hash == chainHash(previous_receipt_hash, execution_hash)`
45
+ 3. for `i > 0`: `previous_receipt_hash == receipts[i-1].receipt_hash`
46
+
47
+ **Payload binding (optional):** given the original `payload` / `decision`, confirm
48
+ `action_hash == canonicalHash({ action, payload })` and
49
+ `decision_hash == canonicalHash(decision)`. This proves the human-readable content
50
+ matches what the receipt committed to.
51
+
52
+ ---
53
+
54
+ ## 3. Merkle transparency log (RFC 6962 domain separation)
55
+
56
+ Each receipt's `receipt_hash` is a leaf. Leaves are added in **creation order**.
57
+
58
+ ```
59
+ hashLeaf(receipt_hash) = sha256hex( 0x00 || utf8(receipt_hash) )
60
+ hashNode(left, right) = sha256hex( 0x01 || fromHex(left) || fromHex(right) )
61
+ ```
62
+
63
+ > Note the asymmetry, which a re-implementation MUST preserve: a leaf hashes the
64
+ > UTF-8 bytes of the receipt-hash *string*; an internal node hashes the *raw bytes*
65
+ > of its two child hex digests. Odd nodes are promoted unchanged to the next level.
66
+
67
+ **Merkle root:** fold the leaf list with `hashNode` pairwise, promoting a lone
68
+ trailing node, until one hash remains. Empty log → `sha256hex(<empty>)`.
69
+
70
+ **Inclusion proof** for a leaf: the ordered list of sibling hashes with a `right`
71
+ flag (true if the sibling is to the right). Verify by folding the leaf with each
72
+ sibling (`hashNode(h, sibling)` if `right`, else `hashNode(sibling, h)`); the
73
+ result must equal the published root.
74
+
75
+ ---
76
+
77
+ ## 4. Signed Tree Head (STH)
78
+
79
+ ```
80
+ sthMessage = "magenta-sth-v1|" + tree_size + "|" + root_hash + "|" + timestamp + "|" + witness_pubkey
81
+ ```
82
+
83
+ The witness signs `sthMessage` with its Ed25519 key (separate from the receipt
84
+ issuer key). An STH is `{ tree_size, root_hash, timestamp, witness_pubkey, signature }`.
85
+
86
+ **STH check:** `Ed25519.verify(utf8(sthMessage), fromHex(signature), fromHex(witness_pubkey))`.
87
+
88
+ ---
89
+
90
+ ## 5. What an auditor verifies
91
+
92
+ Given evidence published by the operator (and a witness public key obtained
93
+ out-of-band, e.g. mirrored to the auditor earlier):
94
+
95
+ 1. **STH authenticity** — the STH signature verifies under the witness key (§4).
96
+ 2. **Inclusion** — a specific receipt's leaf + proof recompute the STH's `root_hash` (§3).
97
+ 3. **Whole-log integrity** — recompute the Merkle root over all receipt leaves;
98
+ it must equal the STH `root_hash` (§3) — and the receipt chain checks (§2).
99
+ 4. **Append-only (consistency)** — given the full leaf list and an *older* STH the
100
+ auditor mirrored previously, the older `root_hash` must equal the root over the
101
+ first `older.tree_size` leaves, and both STHs must verify. A divergence means
102
+ history was rewritten.
103
+ 5. **Payload binding (optional)** — §2.
104
+
105
+ **The insider property:** an operator who controls the process and the receipt
106
+ issuer key can still forge a self-consistent receipt chain (§2 passes). But the
107
+ operator cannot make the recomputed root match an STH the auditor *already holds*
108
+ unless they also control the witness key and every mirror of that STH. So checks
109
+ (1)+(3)+(4) against a pre-mirrored STH expose insider tampering.
110
+
111
+ ---
112
+
113
+ ## 6. Canonical JSON details
114
+
115
+ - Sort object keys ascending by JavaScript string comparison (UTF-16 code unit,
116
+ which matches UTF-8 byte order for the ASCII key names used here).
117
+ - Recurse into arrays (order preserved) and objects (keys sorted).
118
+ - Omit properties whose value is `undefined`; preserve `null`.
119
+ - No insignificant whitespace. Numbers per standard JSON.
120
+
121
+ A conformant implementation in any language that reproduces these byte sequences
122
+ will compute identical hashes and verify identical signatures.