@kindgi/compliance 0.0.0-stage → 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,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
95
+ Derivative 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 describing the origin of the Work and
141
+ 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 Kindgi Inc.
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 CHANGED
@@ -1,3 +1,88 @@
1
- # Temporary Holding Version
1
+ # `@kindgi/compliance`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Type contract for compliance evidence in Kindgi: the `Evidence` wire record, the `ComplianceEvidenceGenerator` interface that records evidence from finished runs and produces signed export bundles, and the classifier that decides retention, signing, and export per event kind. It also ships a few small functions: a pure audit-event-to-evidence transform and helpers that write `env-*` / `secret-*` audit events. The generator is implemented by the Kindgi runtime (or by a caller-supplied implementation) and consumed by [`@kindgi/api`](../api/).
4
+
5
+ ## Purpose
6
+
7
+ Evidence is a classification lens over the audit-event stream from [`@kindgi/audit-events`](../audit-events/): there is one write path for audit events, and the classifier selects which kinds are retained, signed, and exported. This package fixes the shapes on both sides of that lens: the record regulators and auditors read (matching `compliance-evidence.schema.json` in [`@kindgi/specs`](../specs/)), the signed bundle envelope they verify, and the run summary callers hand to the generator. Run summaries are redaction-safe by construction: model prompts and tool arguments appear only as caller-supplied hashes, and raw messages are embedded only with an explicit opt-in.
8
+
9
+ ## Exports
10
+
11
+ - **Evidence record**
12
+ - **`Evidence`** (alias **`ComplianceEvidence`**) — `id`, `tenantId`, `projectId?`, `kind`, `timestamp`, `actor?`, `subject?`, `outcome?`, `payload`, `provenanceRef?`, `signature?`.
13
+ - **`EvidenceKind`** — one of **`EVIDENCE_KINDS`** (the built-in kinds, e.g. `'authz-decision'`, `'run-outcome'`, `'secret-rotated'`, `'hitl-decision'`) or any other string. Consumers must tolerate unknown kinds.
14
+ - **`EvidenceActor`** (with **`ActorKind`**), **`EvidenceSubject`**, **`EvidenceOutcome`**, **`EvidencePayload`** (always carries a numeric `version`), **`EvidenceSignature`** (Ed25519), **`ProvenanceRef`**.
15
+ - **Generator**
16
+ - **`ComplianceEvidenceGenerator`** — `recordFromRun(options)`, `exportSigned(tenantId, filter, signingKeyId)`, `describe()`.
17
+ - **`RecordFromRunOptions`** — `tenantId`, `projectId`, `runId`, `kind`, `runContext`, optional actor/subject/outcome/id/timestamp/`provenanceRef`, and `rawMessages` (embedded only when `allowRawMessages: true`).
18
+ - **`RunEvidenceContext`** — `status`, timing, agent/flow ids, and lists of **`ModelCallSummary`**, **`ToolInvocationSummary`**, **`GuardrailResultSummary`**; plus caller-redacted `failureMessage` and `extra`.
19
+ - **`EvidenceFilter`** (AND-composed; `evidenceKinds: []` matches nothing), **`EvidencePage`**, **`SignedEvidenceBundle`** (base64 canonical `bundle`, `signature`, PEM `publicKey`, `signingKeyId`, `canonicalization: 'sorted-key-json'`), **`EvidenceBundleBody`** (the decoded `bundle`).
20
+ - **Provider seam** — **`ComplianceProvider`** (`emit`, `list`, `describe`) for adapters that forward evidence to an external system, with **`EmitEvidenceInput`**, **`ListEvidenceFilter`**, and **`EvidenceSigner`** (`(bytes, tenantId) => Promise<EvidenceSignature>`).
21
+ - **Classifier**
22
+ - **`ComplianceClassifierFile`** — `{ version: 1, default, byKind }`, the file format.
23
+ - **`Classification`** — `retention` (`days`, `onDenyDays?`, `legalHold?`), `signed`, `exportable`.
24
+ - **`LoadedClassifier`** — `file` plus `resolve(kind)`, which returns the per-kind entry or the default.
25
+ - **`auditEventToEvidence(event)`** — pure transform from an `AuditEvent` to an `Evidence` record (unwraps the `{ v, doc }` payload envelope).
26
+ - **`emitResolveEvent(input)`** / **`emitLifecycleEvent(input)`** — append `env-resolved` / `secret-resolved` and `env-set` / `secret-rotated` / … audit events to an `AuditEventBinding`. Payloads carry metadata only (scope, name, version, caller), never the value. Failures are logged with `console.warn` and never thrown. Inputs: **`EmitResolveEventInput`**, **`EmitLifecycleEventInput`**, **`ResolveContext`**.
27
+ - **Errors** — **`ComplianceError`** union of `InvalidEvidenceError`, `PersistenceError`, `SignerFailureError`, `SigningKeyMissingError`, `SigningFailureError`, `InvalidCursorError`, `ProjectNotFoundError`, `UnsupportedVersionError`, each with a `code`. **`EmitResult`** and **`ListResult`** are the `ComplianceProvider` return types.
28
+
29
+ ## Example
30
+
31
+ ```ts
32
+ import type {
33
+ ComplianceEvidenceGenerator,
34
+ EvidenceBundleBody,
35
+ RunEvidenceContext,
36
+ } from '@kindgi/compliance';
37
+
38
+ // tenantId, projectId, runId, signingKeyId, startedAt, endedAt, promptHash and
39
+ // argsHash come from the finished run and the deployment's configuration.
40
+ async function recordAndExport(generator: ComplianceEvidenceGenerator): Promise<void> {
41
+ // Redaction-safe run summary: hashes and counts, no prompt or argument text.
42
+ const runContext: RunEvidenceContext = {
43
+ status: 'completed',
44
+ startedAt,
45
+ endedAt,
46
+ modelCalls: [{ provider: 'acme', model: 'acme-chat-2', promptHash, inputTokens: 812, outputTokens: 164 }],
47
+ toolInvocations: [{ toolId: 'crm.lookup', argsHash, outcome: 'succeeded', durationMs: 84 }],
48
+ guardrailResults: [{ guardrailId: 'pii-scan', verdict: 'pass' }],
49
+ };
50
+
51
+ const recorded = await generator.recordFromRun({
52
+ tenantId,
53
+ projectId,
54
+ runId,
55
+ kind: 'run-outcome', // the caller decides the kind; it is not inferred
56
+ outcome: 'succeeded',
57
+ actor: { kind: 'agent', id: 'support-triage' },
58
+ runContext,
59
+ });
60
+ if (recorded.kind === 'err') throw new Error(`${recorded.error.code}: ${recorded.error.message}`);
61
+
62
+ const exported = await generator.exportSigned(
63
+ tenantId,
64
+ { runId, evidenceKinds: ['run-outcome', 'authz-decision'] },
65
+ signingKeyId,
66
+ );
67
+ if (exported.kind === 'err') throw new Error(`${exported.error.code}: ${exported.error.message}`);
68
+
69
+ // `bundle` is base64 of the exact canonical JSON bytes that were signed.
70
+ const body = JSON.parse(
71
+ Buffer.from(exported.value.bundle, 'base64').toString('utf8'),
72
+ ) as EvidenceBundleBody;
73
+ console.log(body.recordCount, exported.value.signingKeyId, exported.value.algorithm);
74
+ }
75
+ ```
76
+
77
+ ## Non-goals
78
+
79
+ - **No generator, persistence, or classifier parser.** This package defines the interfaces and the classifier file format. Implementing `ComplianceEvidenceGenerator`, storing evidence, and loading a classifier file into a `LoadedClassifier` are left to the Kindgi runtime or the caller.
80
+ - **No kind inference.** `recordFromRun` files evidence under the `kind` the caller passes; it does not derive one from the run outcome.
81
+ - **No content scanning.** `failureMessage` and `extra` are embedded as given; redacting them is the caller's responsibility.
82
+ - **No closed set of kinds.** `EVIDENCE_KINDS` lists the built-in kinds; any audit-event kind the classifier marks exportable can appear as evidence.
83
+
84
+ ## Related
85
+
86
+ - [`@kindgi/audit-events`](../audit-events/) — the `AuditEvent` stream evidence is derived from.
87
+ - [`@kindgi/api`](../api/) — mounts the compliance routes from `auditEvents`, `complianceClassifier`, and `complianceGenerator`.
88
+ - [`@kindgi/specs`](../specs/) — `compliance-evidence.schema.json`.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Per-kind classification decision. The retention + signing + export
3
+ * behavior for one event kind. Loaded from a classifier JSON file at
4
+ * deployment boot; consumed by retention cleanup and signed export.
5
+ */
6
+ export interface Classification {
7
+ readonly retention: {
8
+ /**
9
+ * Baseline retention in days. Rows older than this are eligible
10
+ * for deletion UNLESS `legalHold` is set OR `onDenyDays` is set
11
+ * and applies.
12
+ */
13
+ readonly days: number;
14
+ /**
15
+ * When set, denied/failed variants of this kind are retained
16
+ * longer than the baseline. Security investigations often need
17
+ * denials retained past the operational rows. Only meaningful
18
+ * for kinds that carry a deny signal (authz-decision:
19
+ * `allowed=false`).
20
+ */
21
+ readonly onDenyDays?: number;
22
+ /**
23
+ * When true, retention cleanup NEVER deletes rows of this kind.
24
+ * Legal-hold semantics — deletion requires operator action past
25
+ * this classifier. Overrides `days`.
26
+ */
27
+ readonly legalHold?: boolean;
28
+ };
29
+ /**
30
+ * Kinds that get Ed25519-signed at export time when a regulator
31
+ * bundle is generated. Signatures are byte-exact over canonical
32
+ * event bytes; the classifier doesn't hold the key, only the
33
+ * decision to sign.
34
+ */
35
+ readonly signed: boolean;
36
+ /**
37
+ * Kinds included in regulator-facing signed export bundles.
38
+ * Non-exportable kinds stay out of the bundle regardless of
39
+ * signature policy.
40
+ */
41
+ readonly exportable: boolean;
42
+ }
43
+ /** Wire schema for the classifier JSON file. Versioned envelope. */
44
+ export interface ComplianceClassifierFile {
45
+ readonly version: 1;
46
+ /** Default classification for kinds not explicitly listed. */
47
+ readonly default: Classification;
48
+ /** Per-kind overrides. Missing kind → `default`. */
49
+ readonly byKind: Readonly<Record<string, Classification>>;
50
+ }
51
+ /**
52
+ * Loaded classifier — same shape as the file, but the `resolve` helper
53
+ * returns the correct classification (per-kind or default) in one call.
54
+ *
55
+ * Built from a `ComplianceClassifierFile` by the runtime's loader or by
56
+ * the caller; deployments pass it to `@kindgi/api` as
57
+ * `CreateAppInput.complianceClassifier`. This package only defines the
58
+ * shape.
59
+ */
60
+ export interface LoadedClassifier {
61
+ readonly file: ComplianceClassifierFile;
62
+ /** Return the classification for the given event kind. */
63
+ resolve(kind: string): Classification;
64
+ }
65
+ //# sourceMappingURL=classifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../src/classifier.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE;QAClB;;;;WAIG;QACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB;;;;;;WAMG;QACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B;;;;WAIG;QACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,oEAAoE;AACpE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAC3D;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,0DAA0D;IAC1D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CACvC"}
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export {};
4
+ //# sourceMappingURL=classifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.js","sourceRoot":"","sources":["../src/classifier.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
@@ -0,0 +1,93 @@
1
+ import type { ProjectId, Result, SigningKeyId } from '@kindgi/types';
2
+ import type { Evidence } from './types.js';
3
+ /**
4
+ * Errors emitted by the compliance surface. Every variant carries a `code`
5
+ * for pattern matching; messages are human-readable, not API contract.
6
+ */
7
+ export type ComplianceError = InvalidEvidenceError | PersistenceError | SignerFailureError | SigningKeyMissingError | SigningFailureError | InvalidCursorError | ProjectNotFoundError | UnsupportedVersionError;
8
+ /**
9
+ * Structural validation of an evidence record against the compliance
10
+ * schema failed — e.g. `generator.recordFromRun` assembled a record that
11
+ * doesn't match the wire schema. A caller-shape bug or a schema drift,
12
+ * never a persistence issue.
13
+ */
14
+ export interface InvalidEvidenceError {
15
+ readonly code: 'invalid-evidence';
16
+ readonly message: string;
17
+ readonly issues: readonly {
18
+ readonly path: string;
19
+ readonly message: string;
20
+ }[];
21
+ }
22
+ /**
23
+ * The caller-plugged persistence binding threw or returned an error.
24
+ */
25
+ export interface PersistenceError {
26
+ readonly code: 'persistence-error';
27
+ readonly message: string;
28
+ readonly cause: unknown;
29
+ }
30
+ /**
31
+ * A caller-plugged `EvidenceSigner` function threw. Distinct from
32
+ * `SigningFailureError` (which is specific to the generator's own
33
+ * Ed25519 signing path, e.g. `exportSigned`) so callers can distinguish
34
+ * the two signing paths.
35
+ */
36
+ export interface SignerFailureError {
37
+ readonly code: 'signer-failure';
38
+ readonly message: string;
39
+ readonly cause: unknown;
40
+ }
41
+ /**
42
+ * The caller asked for a signed export but the requested `SigningKeyId`
43
+ * has no material in the mounted `SigningKeyBinding`. Typically a
44
+ * misconfiguration.
45
+ */
46
+ export interface SigningKeyMissingError {
47
+ readonly code: 'signing-key-missing';
48
+ readonly message: string;
49
+ readonly signingKeyId: SigningKeyId;
50
+ }
51
+ /**
52
+ * The Ed25519 signing primitive itself rejected the material — malformed
53
+ * key bytes, wrong length, or an underlying primitive that refused the
54
+ * input.
55
+ */
56
+ export interface SigningFailureError {
57
+ readonly code: 'signing-failure';
58
+ readonly message: string;
59
+ readonly signingKeyId: SigningKeyId;
60
+ readonly cause: unknown;
61
+ }
62
+ /**
63
+ * An evidence listing received a `cursor` that isn't decodable to a
64
+ * `(timestamp, id)` pair. Almost always a client bug.
65
+ */
66
+ export interface InvalidCursorError {
67
+ readonly code: 'invalid-cursor';
68
+ readonly message: string;
69
+ }
70
+ /**
71
+ * An evidence write (`recordFromRun`, `ComplianceProvider.emit`) named a
72
+ * `projectId` that doesn't exist inside the tenant. Distinct from
73
+ * `PersistenceError` so the API layer can map the caller-shape bug to a
74
+ * 404 wire response rather than 500.
75
+ */
76
+ export interface ProjectNotFoundError {
77
+ readonly code: 'project-not-found';
78
+ readonly message: string;
79
+ readonly projectId: ProjectId;
80
+ }
81
+ /**
82
+ * A record read from storage carried a `payload.version` newer than this
83
+ * reader knows how to normalize — typically during a rolling deploy.
84
+ */
85
+ export interface UnsupportedVersionError {
86
+ readonly code: 'unsupported-version';
87
+ readonly message: string;
88
+ readonly version: number;
89
+ readonly evidenceId: string;
90
+ }
91
+ export type EmitResult = Result<Evidence, ComplianceError>;
92
+ export type ListResult = Result<readonly Evidence[], ComplianceError>;
93
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,oBAAoB,GACpB,gBAAgB,GAChB,kBAAkB,GAClB,sBAAsB,GACtB,mBAAmB,GACnB,kBAAkB,GAClB,oBAAoB,GACpB,uBAAuB,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,QAAQ,EAAE,EAAE,eAAe,CAAC,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export {};
4
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
@@ -0,0 +1,34 @@
1
+ import type { AuditEvent } from '@kindgi/audit-events';
2
+ import type { ComplianceEvidenceId, Result, SigningKeyId, TenantId } from '@kindgi/types';
3
+ import type { ComplianceError } from './errors.js';
4
+ import type { ComplianceEvidence, EvidenceFilter, RecordFromRunOptions, SignedEvidenceBundle } from './types.js';
5
+ /**
6
+ * The runtime service that turns terminated runs into audit-event
7
+ * records and produces signed export bundles.
8
+ *
9
+ * Public interface — deployments plug an implementation into
10
+ * `@kindgi/api` via `CreateAppInput.complianceGenerator`. The Kindgi
11
+ * runtime provides one; callers may supply their own. Implementations
12
+ * may expose additional subscription / auto-emit methods; this interface
13
+ * is the minimum surface `@kindgi/api` consumes.
14
+ */
15
+ export interface ComplianceEvidenceGenerator {
16
+ recordFromRun(options: RecordFromRunOptions): Promise<Result<{
17
+ readonly evidenceId: ComplianceEvidenceId;
18
+ }, ComplianceError>>;
19
+ exportSigned(tenantId: TenantId, filter: EvidenceFilter, signingKeyId: SigningKeyId): Promise<Result<SignedEvidenceBundle, ComplianceError>>;
20
+ describe(): {
21
+ readonly name: string;
22
+ readonly version: string;
23
+ };
24
+ }
25
+ /**
26
+ * Materialize a `ComplianceEvidence` wire record from an `AuditEvent`.
27
+ * The bundle body carries `ComplianceEvidence[]` for wire-shape
28
+ * stability — regulators verifying bundles read one record shape
29
+ * regardless of how events are stored.
30
+ *
31
+ * Pure function — no I/O, no random. Safe to call from any layer.
32
+ */
33
+ export declare function auditEventToEvidence(event: AuditEvent): ComplianceEvidence;
34
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAS,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EAGd,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,WAAW,2BAA2B;IAC1C,aAAa,CACX,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC;QAAE,QAAQ,CAAC,UAAU,EAAE,oBAAoB,CAAA;KAAE,EAAE,eAAe,CAAC,CAAC,CAAC;IAEnF,YAAY,CACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC,CAAC;IAE1D,QAAQ,IAAI;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAY1E"}
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ /**
4
+ * Materialize a `ComplianceEvidence` wire record from an `AuditEvent`.
5
+ * The bundle body carries `ComplianceEvidence[]` for wire-shape
6
+ * stability — regulators verifying bundles read one record shape
7
+ * regardless of how events are stored.
8
+ *
9
+ * Pure function — no I/O, no random. Safe to call from any layer.
10
+ */
11
+ export function auditEventToEvidence(event) {
12
+ return {
13
+ id: event.id,
14
+ tenantId: event.tenantId,
15
+ // Tenant-level events carry no project; the key is omitted, never `undefined`.
16
+ ...(event.projectId !== undefined && { projectId: event.projectId }),
17
+ kind: event.kind,
18
+ timestamp: event.timestamp,
19
+ payload: extractDoc(event.payload),
20
+ ...(event.outcome !== undefined && { outcome: event.outcome }),
21
+ ...(event.runId !== undefined && { provenanceRef: { runId: event.runId } }),
22
+ };
23
+ }
24
+ function extractDoc(payload) {
25
+ const inner = payload.doc;
26
+ if (inner !== null && typeof inner === 'object' && !Array.isArray(inner)) {
27
+ return inner;
28
+ }
29
+ return payload;
30
+ }
31
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAuCjC;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAiB;IACpD,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAA0B;QACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,+EAA+E;QAC/E,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACpE,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,CAAoB;QACrD,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAA0B,EAAE,CAAC;QACjF,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAc,EAAE,EAAE,CAAC;KACrF,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAA0C;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;IAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,OAAO,KAA0C,CAAC;IACpD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { EVIDENCE_KINDS } from './types.js';
2
+ export type { ActorKind, ComplianceEvidence, ComplianceProvider, EmitEvidenceInput, Evidence, EvidenceActor, EvidenceKind, EvidenceOutcome, EvidencePayload, EvidenceSignature, EvidenceSigner, EvidenceSubject, ListEvidenceFilter, ProvenanceRef, } from './types.js';
3
+ export type { EvidenceBundleBody, EvidenceFilter, EvidencePage, GuardrailResultSummary, ModelCallSummary, RecordFromRunOptions, RunEvidenceContext, SignedEvidenceBundle, ToolInvocationSummary, } from './types.js';
4
+ export type { ComplianceError, EmitResult, InvalidCursorError, InvalidEvidenceError, ListResult, PersistenceError, ProjectNotFoundError, SignerFailureError, SigningFailureError, SigningKeyMissingError, UnsupportedVersionError, } from './errors.js';
5
+ export type { Classification, ComplianceClassifierFile, LoadedClassifier, } from './classifier.js';
6
+ export type { ComplianceEvidenceGenerator } from './generator.js';
7
+ export { auditEventToEvidence } from './generator.js';
8
+ export { emitLifecycleEvent, emitResolveEvent } from './resolve-emit.js';
9
+ export type { EmitLifecycleEventInput, EmitResolveEventInput, ResolveContext, } from './resolve-emit.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EACV,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,cAAc,EACd,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzE,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,cAAc,GACf,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ // ============ Wire types ============
4
+ export { EVIDENCE_KINDS } from './types.js';
5
+ export { auditEventToEvidence } from './generator.js';
6
+ // ============ Resolve + lifecycle event emitters ============
7
+ export { emitLifecycleEvent, emitResolveEvent } from './resolve-emit.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuD5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,+DAA+D;AAC/D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}