@zanii/compliance 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.
package/LICENSE ADDED
@@ -0,0 +1,159 @@
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; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained
107
+ within such NOTICE file.
108
+
109
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
110
+ any Contribution intentionally submitted for inclusion in the Work
111
+ by You to the Licensor shall be under the terms and conditions of
112
+ this License, without any additional terms or conditions.
113
+
114
+ 6. Trademarks. This License does not grant permission to use the trade
115
+ names, trademarks, service marks, or product names of the Licensor,
116
+ except as required for reasonable and customary use in describing the
117
+ origin of the Work and reproducing the content of the NOTICE file.
118
+
119
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
120
+ to in writing, Licensor provides the Work (and each Contributor
121
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
122
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
123
+ without limitation, any warranties or conditions of TITLE,
124
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
125
+
126
+ 8. Limitation of Liability. In no event and under no legal theory,
127
+ whether in tort (including negligence), contract, or otherwise,
128
+ unless required by applicable law (such as deliberate and grossly
129
+ negligent acts) or agreed to in writing, shall any Contributor be
130
+ liable to You for damages, including any direct, indirect, special,
131
+ incidental, or consequential damages of any character arising as a
132
+ result of this License or out of the use or inability to use the
133
+ Work.
134
+
135
+ 9. Accepting Warranty or Additional Liability. While redistributing
136
+ the Work or Derivative Works thereof, You may choose to offer,
137
+ and charge a fee for, acceptance of support, warranty, indemnity,
138
+ or other liability obligations and/or rights consistent with this
139
+ License. However, in accepting such obligations, You may act only
140
+ on Your own behalf and on Your sole responsibility, not on behalf
141
+ of any other Contributor, and only if You agree to indemnify,
142
+ defend, and hold each Contributor harmless for any liability
143
+ incurred by, or claims asserted against, such Contributor.
144
+
145
+ END OF TERMS AND CONDITIONS
146
+
147
+ Copyright 2026 Zanii
148
+
149
+ Licensed under the Apache License, Version 2.0 (the "License");
150
+ you may not use this file except in compliance with the License.
151
+ You may obtain a copy of the License at
152
+
153
+ http://www.apache.org/licenses/LICENSE-2.0
154
+
155
+ Unless required by applicable law or agreed to in writing, software
156
+ distributed under the License is distributed on an "AS IS" BASIS,
157
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158
+ See the License for the specific language governing permissions and
159
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @zanii/compliance
2
+
3
+ Turn a Zanii **audit bundle** into an auditor-ready compliance report — verified
4
+ offline, no network, no trust in Zanii's servers. Action breakdown by control,
5
+ on-chain anchoring coverage, and a Markdown renderer you can hand straight to an
6
+ auditor.
7
+
8
+ ```sh
9
+ npm install @zanii/compliance
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { buildComplianceReport, renderComplianceMarkdown } from '@zanii/compliance';
16
+
17
+ // bundle = the JSON from `zanii export <did>` (or GET /v1/export/<did>)
18
+ const report = buildComplianceReport(bundle, {
19
+ controls: {
20
+ crm: 'AC-2 Account Management',
21
+ email: 'AU-2 Audit Events',
22
+ pay: 'SC-13 Cryptographic Protection',
23
+ },
24
+ });
25
+
26
+ console.log(report.verified, report.flags); // false-verified bundles still summarize, with a flag
27
+ console.log(renderComplianceMarkdown(report)); // → hand to the auditor
28
+ ```
29
+
30
+ `buildComplianceReport` verifies the bundle with `@zanii/core` first; every figure
31
+ is derived from the receipts, and anything an auditor should notice (failed
32
+ verification, unanchored receipts, revoked delegations, unmapped namespaces)
33
+ lands in `report.flags`.
34
+
35
+ ## Changelog
36
+
37
+ - **0.1.0** — initial release: `buildComplianceReport`, `renderComplianceMarkdown`, `ControlMap`.
38
+
39
+ ## License
40
+
41
+ Apache-2.0.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @zanii/compliance — turn a verifiable Zanii audit bundle into an auditor-ready
3
+ * compliance report: offline verification, action breakdown by namespace,
4
+ * anchoring coverage, optional control mapping, and a Markdown renderer.
5
+ *
6
+ * Builds entirely on `@zanii/core` — no network, no trust in Zanii's servers.
7
+ */
8
+ import { type AuditBundle, type BundleReport } from '@zanii/core';
9
+ /** Map a target namespace (e.g. `crm`, `email`) to the control(s) it evidences. */
10
+ export type ControlMap = Record<string, string>;
11
+ export interface ComplianceReport {
12
+ agent_id: string;
13
+ generated_at: string;
14
+ /** Did the bundle verify offline? A `false` here invalidates everything below. */
15
+ verified: boolean;
16
+ verification: BundleReport;
17
+ period: {
18
+ first: string | null;
19
+ last: string | null;
20
+ };
21
+ total_actions: number;
22
+ /** Action count per target namespace (first `.`-segment of the target). */
23
+ by_namespace: Record<string, number>;
24
+ /** How many receipts are covered by an on-chain anchor. */
25
+ anchored: {
26
+ count: number;
27
+ total: number;
28
+ complete: boolean;
29
+ };
30
+ /** Namespace → declared control, for the namespaces actually seen. */
31
+ controls: Array<{
32
+ namespace: string;
33
+ control: string;
34
+ actions: number;
35
+ }>;
36
+ /** Anything an auditor should notice. Empty = clean. */
37
+ flags: string[];
38
+ }
39
+ /**
40
+ * Build a compliance report from an audit bundle. Verifies it offline first; the
41
+ * summary is derived from the receipts regardless, so a failed verification still
42
+ * produces a report — with `verified: false` and a flag.
43
+ */
44
+ export declare function buildComplianceReport(bundle: AuditBundle, opts?: {
45
+ controls?: ControlMap;
46
+ generatedAt?: string;
47
+ }): ComplianceReport;
48
+ /** Render a report as auditor-ready Markdown. */
49
+ export declare function renderComplianceMarkdown(r: ComplianceReport): string;
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAErF,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,kFAAkF;IAClF,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACtD,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,2DAA2D;IAC3D,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAC9D,sEAAsE;IACtE,QAAQ,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzE,wDAAwD;IACxD,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,WAAW,EACnB,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACzD,gBAAgB,CAyClB;AAED,iDAAiD;AACjD,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAwBpE"}
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @zanii/compliance — turn a verifiable Zanii audit bundle into an auditor-ready
3
+ * compliance report: offline verification, action breakdown by namespace,
4
+ * anchoring coverage, optional control mapping, and a Markdown renderer.
5
+ *
6
+ * Builds entirely on `@zanii/core` — no network, no trust in Zanii's servers.
7
+ */
8
+ import { verifyAuditBundle } from '@zanii/core';
9
+ const namespaceOf = (target) => target.split('.')[0] || 'unknown';
10
+ /**
11
+ * Build a compliance report from an audit bundle. Verifies it offline first; the
12
+ * summary is derived from the receipts regardless, so a failed verification still
13
+ * produces a report — with `verified: false` and a flag.
14
+ */
15
+ export function buildComplianceReport(bundle, opts = {}) {
16
+ const verification = verifyAuditBundle(bundle);
17
+ const receipts = bundle.receipts.map((b) => b.receipt);
18
+ const by_namespace = {};
19
+ for (const r of receipts) {
20
+ if (!r.target)
21
+ continue;
22
+ const ns = namespaceOf(r.target);
23
+ by_namespace[ns] = (by_namespace[ns] ?? 0) + 1;
24
+ }
25
+ const anchoredCount = verification.stats.anchored_through ?? 0;
26
+ const total = receipts.length;
27
+ const controls = Object.entries(by_namespace).map(([namespace, actions]) => ({
28
+ namespace,
29
+ control: opts.controls?.[namespace] ?? '(unmapped)',
30
+ actions,
31
+ }));
32
+ const flags = [];
33
+ if (!verification.ok)
34
+ flags.push('bundle FAILED offline verification — treat all figures below as unproven');
35
+ if (anchoredCount < total)
36
+ flags.push(`${total - anchoredCount} of ${total} receipts are not yet anchored on-chain`);
37
+ if (verification.stats.revoked_certs > 0)
38
+ flags.push(`${verification.stats.revoked_certs} delegation cert(s) were revoked in this period`);
39
+ if (opts.controls) {
40
+ const unmapped = controls.filter((c) => c.control === '(unmapped)').map((c) => c.namespace);
41
+ if (unmapped.length)
42
+ flags.push(`no control mapped for namespace(s): ${unmapped.join(', ')}`);
43
+ }
44
+ return {
45
+ agent_id: bundle.agent_id,
46
+ generated_at: opts.generatedAt ?? bundle.generated_at,
47
+ verified: verification.ok,
48
+ verification,
49
+ period: { first: verification.stats.first_ts, last: verification.stats.last_ts },
50
+ total_actions: total,
51
+ by_namespace,
52
+ anchored: { count: anchoredCount, total, complete: anchoredCount >= total },
53
+ controls,
54
+ flags,
55
+ };
56
+ }
57
+ /** Render a report as auditor-ready Markdown. */
58
+ export function renderComplianceMarkdown(r) {
59
+ const rows = r.controls
60
+ .sort((a, b) => b.actions - a.actions)
61
+ .map((c) => `| \`${c.namespace}\` | ${c.control} | ${c.actions} |`)
62
+ .join('\n');
63
+ const flags = r.flags.length ? r.flags.map((f) => `- ⚠️ ${f}`).join('\n') : '- ✅ none';
64
+ return `# Zanii Compliance Report
65
+
66
+ - **Agent:** \`${r.agent_id}\`
67
+ - **Generated:** ${r.generated_at}
68
+ - **Verification:** ${r.verified ? '✅ PROVEN offline' : '❌ FAILED'}
69
+ - **Period:** ${r.period.first ?? '—'} → ${r.period.last ?? '—'}
70
+ - **Actions:** ${r.total_actions} (${r.anchored.count}/${r.anchored.total} anchored on-chain)
71
+
72
+ ## Actions by control
73
+
74
+ | Namespace | Control | Actions |
75
+ | --- | --- | --- |
76
+ ${rows || '| — | — | 0 |'}
77
+
78
+ ## Findings
79
+
80
+ ${flags}
81
+ `;
82
+ }
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAuC,MAAM,aAAa,CAAC;AAuBrF,MAAM,WAAW,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;AAElF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAmB,EACnB,OAAwD,EAAE;IAE1D,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAA2C,CAAC,CAAC;IAE3F,MAAM,YAAY,GAA2B,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,IAAI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AO;;iBAEQ,CAAC,CAAC,QAAQ;mBACR,CAAC,CAAC,YAAY;sBACX,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,UAAU;gBAClD,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG;iBAC9C,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK;;;;;;EAMvE,IAAI,IAAI,eAAe;;;;EAIvB,KAAK;CACN,CAAC;AACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@zanii/compliance",
3
+ "version": "0.1.0",
4
+ "description": "Turn a Zanii audit bundle into an auditor-ready compliance report - offline verification, action breakdown, anchoring coverage, and control mapping, rendered to Markdown.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://ledger.zanii.agency",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^26.1.0",
30
+ "typescript": "^5.8.2",
31
+ "vitest": "^3.0.9",
32
+ "@zanii/testing": "0.1.0"
33
+ },
34
+ "dependencies": {
35
+ "@zanii/core": "0.2.0"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "test": "vitest run",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @zanii/compliance — turn a verifiable Zanii audit bundle into an auditor-ready
3
+ * compliance report: offline verification, action breakdown by namespace,
4
+ * anchoring coverage, optional control mapping, and a Markdown renderer.
5
+ *
6
+ * Builds entirely on `@zanii/core` — no network, no trust in Zanii's servers.
7
+ */
8
+ import { verifyAuditBundle, type AuditBundle, type BundleReport } from '@zanii/core';
9
+
10
+ /** Map a target namespace (e.g. `crm`, `email`) to the control(s) it evidences. */
11
+ export type ControlMap = Record<string, string>;
12
+
13
+ export interface ComplianceReport {
14
+ agent_id: string;
15
+ generated_at: string;
16
+ /** Did the bundle verify offline? A `false` here invalidates everything below. */
17
+ verified: boolean;
18
+ verification: BundleReport;
19
+ period: { first: string | null; last: string | null };
20
+ total_actions: number;
21
+ /** Action count per target namespace (first `.`-segment of the target). */
22
+ by_namespace: Record<string, number>;
23
+ /** How many receipts are covered by an on-chain anchor. */
24
+ anchored: { count: number; total: number; complete: boolean };
25
+ /** Namespace → declared control, for the namespaces actually seen. */
26
+ controls: Array<{ namespace: string; control: string; actions: number }>;
27
+ /** Anything an auditor should notice. Empty = clean. */
28
+ flags: string[];
29
+ }
30
+
31
+ const namespaceOf = (target: string): string => target.split('.')[0] || 'unknown';
32
+
33
+ /**
34
+ * Build a compliance report from an audit bundle. Verifies it offline first; the
35
+ * summary is derived from the receipts regardless, so a failed verification still
36
+ * produces a report — with `verified: false` and a flag.
37
+ */
38
+ export function buildComplianceReport(
39
+ bundle: AuditBundle,
40
+ opts: { controls?: ControlMap; generatedAt?: string } = {},
41
+ ): ComplianceReport {
42
+ const verification = verifyAuditBundle(bundle);
43
+ const receipts = bundle.receipts.map((b) => b.receipt as { target?: string; ts?: string });
44
+
45
+ const by_namespace: Record<string, number> = {};
46
+ for (const r of receipts) {
47
+ if (!r.target) continue;
48
+ const ns = namespaceOf(r.target);
49
+ by_namespace[ns] = (by_namespace[ns] ?? 0) + 1;
50
+ }
51
+
52
+ const anchoredCount = verification.stats.anchored_through ?? 0;
53
+ const total = receipts.length;
54
+
55
+ const controls = Object.entries(by_namespace).map(([namespace, actions]) => ({
56
+ namespace,
57
+ control: opts.controls?.[namespace] ?? '(unmapped)',
58
+ actions,
59
+ }));
60
+
61
+ const flags: string[] = [];
62
+ if (!verification.ok) flags.push('bundle FAILED offline verification — treat all figures below as unproven');
63
+ if (anchoredCount < total) flags.push(`${total - anchoredCount} of ${total} receipts are not yet anchored on-chain`);
64
+ if (verification.stats.revoked_certs > 0) flags.push(`${verification.stats.revoked_certs} delegation cert(s) were revoked in this period`);
65
+ if (opts.controls) {
66
+ const unmapped = controls.filter((c) => c.control === '(unmapped)').map((c) => c.namespace);
67
+ if (unmapped.length) flags.push(`no control mapped for namespace(s): ${unmapped.join(', ')}`);
68
+ }
69
+
70
+ return {
71
+ agent_id: bundle.agent_id,
72
+ generated_at: opts.generatedAt ?? bundle.generated_at,
73
+ verified: verification.ok,
74
+ verification,
75
+ period: { first: verification.stats.first_ts, last: verification.stats.last_ts },
76
+ total_actions: total,
77
+ by_namespace,
78
+ anchored: { count: anchoredCount, total, complete: anchoredCount >= total },
79
+ controls,
80
+ flags,
81
+ };
82
+ }
83
+
84
+ /** Render a report as auditor-ready Markdown. */
85
+ export function renderComplianceMarkdown(r: ComplianceReport): string {
86
+ const rows = r.controls
87
+ .sort((a, b) => b.actions - a.actions)
88
+ .map((c) => `| \`${c.namespace}\` | ${c.control} | ${c.actions} |`)
89
+ .join('\n');
90
+ const flags = r.flags.length ? r.flags.map((f) => `- ⚠️ ${f}`).join('\n') : '- ✅ none';
91
+ return `# Zanii Compliance Report
92
+
93
+ - **Agent:** \`${r.agent_id}\`
94
+ - **Generated:** ${r.generated_at}
95
+ - **Verification:** ${r.verified ? '✅ PROVEN offline' : '❌ FAILED'}
96
+ - **Period:** ${r.period.first ?? '—'} → ${r.period.last ?? '—'}
97
+ - **Actions:** ${r.total_actions} (${r.anchored.count}/${r.anchored.total} anchored on-chain)
98
+
99
+ ## Actions by control
100
+
101
+ | Namespace | Control | Actions |
102
+ | --- | --- | --- |
103
+ ${rows || '| — | — | 0 |'}
104
+
105
+ ## Findings
106
+
107
+ ${flags}
108
+ `;
109
+ }