halo-record 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,204 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ Copyright 2026 Brian Kuan
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # halo-record (TypeScript)
2
+
3
+ Tamper-evident, hash-chained Runtime Records for AI agents: the TypeScript recorder.
4
+
5
+ **Chain-format compatible with the Python `halo-record` package.** Records written here verify with either verifier, anchor to the same hosted witness, and render in the same Runtime Report. Canonicalization (RFC 8785 subset), hashing, redaction patterns, provenance tagging, and the witness wire protocol are ports of the Python implementation; cross-language interop is the package's defining test.
6
+
7
+ Zero runtime dependencies (Node ≥ 20, `node:crypto` / `node:fs`).
8
+
9
+ ## Why you can trust this code
10
+
11
+ You are being asked to put a recorder inside your agent. You should not take that on faith:
12
+
13
+ - **Zero runtime dependencies.** `npm install halo-record` installs exactly one package; framework adapters use structural typing and never import the frameworks.
14
+ - **One sanctioned network call:** the opt-in witness anchor, which sends only `{subject, count, head, chain_root}`. Record contents never leave your infrastructure.
15
+ - **Raw inputs never enter a record.** Arguments are hashed and summarized through a redaction pass before writing.
16
+ - **Small enough to audit.** ~1,400 lines of TypeScript. Read all of it in an afternoon.
17
+ - **Apache-2.0.**
18
+
19
+ ## Use
20
+
21
+ ```ts
22
+ import { Recorder } from "halo-record";
23
+
24
+ const recorder = new Recorder("./runtime-records/acme.jsonl");
25
+
26
+ recorder.record("tool_call", "privacy", {
27
+ tool: "email.send",
28
+ toolInput: { to: "alice@acme.com" }, // hashed + redacted summary; raw args never stored
29
+ subject: "acme", // per-customer chain isolation
30
+ source: "recorder", // provenance: captured vs ingested
31
+ outcome: { status: "ok", summary: "sent" }, // redacted + scanned, same as input
32
+ });
33
+ ```
34
+
35
+ Verify a chain (yours or one you received):
36
+
37
+ ```ts
38
+ import { verifyLog, readLog, verifyCompleteness } from "halo-record";
39
+ import { fetchCheckpoints } from "halo-record";
40
+
41
+ const integrity = verifyLog("./runtime-records/acme.jsonl"); // nothing edited
42
+ const cps = await fetchCheckpoints("https://witness.example", "acme");
43
+ const completeness = verifyCompleteness(readLog("./runtime-records/acme.jsonl"), cps); // nothing omitted
44
+ ```
45
+
46
+ Anchor to a witness (the one sanctioned network call; only `{subject, count, head, chain_root}` is sent, and record contents never leave your infrastructure):
47
+
48
+ ```ts
49
+ import { anchorRemote, readLog } from "halo-record";
50
+ await anchorRemote("https://witness.example", VENDOR_KEY, readLog("./runtime-records/acme.jsonl"));
51
+ ```
52
+
53
+ Record a model call (the buyer's first question: "which model saw my data?"):
54
+
55
+ ```ts
56
+ import { recordModelCall } from "halo-record";
57
+
58
+ recordModelCall(recorder, {
59
+ provider: "anthropic", model: "claude-sonnet-4-6",
60
+ zeroDataRetention: true, purpose: "draft support reply",
61
+ subject: "acme",
62
+ }); // tool=model.generate, scope=model:anthropic; provider and retention terms, disclosed per call
63
+ ```
64
+
65
+ ## Framework adapters
66
+
67
+ All boundary-captured, all dependency-free (structural typing; the framework
68
+ packages are never imported):
69
+
70
+ ```ts
71
+ import { createLangChainHandler } from "halo-record"; // LangChain.js / LangGraph.js callbacks
72
+ import { instrumentMcpClient, wrapMcpToolHandler } from "halo-record"; // MCP TS SDK, client or server side
73
+ import { createAgentsHooks } from "halo-record"; // OpenAI Agents SDK (JS) run hooks
74
+ import { wrapVercelTools, createStepRecorder } from "halo-record"; // Vercel AI SDK tools / onStepFinish
75
+ import { createClaudeAgentHook } from "halo-record"; // Claude Agent SDK PostToolUse hook
76
+ ```
77
+
78
+ Every adapter funnels through the same core (`recordToolCall`), so
79
+ classification, scope, redaction, and provenance behave identically across
80
+ ecosystems, and identically to the Python adapters. Framework hook shapes are
81
+ structural; if a framework changes its callback signature, the adapter is a
82
+ small shim to update, not a rewrite.
83
+
84
+ ## Test
85
+
86
+ ```
87
+ node --test test/core.test.ts # unit suite
88
+ npx tsc --noEmit # typecheck (TS >= 5.8)
89
+ ```
90
+
91
+ Cross-language checks (require the Python package):
92
+ - a TS-written chain passes `python -m halo_record.cli verify`
93
+ - a Python-written chain passes `verifyLog` here, including completeness against a Python witness log
94
+ - `canon()` output is byte-identical across both implementations
95
+
96
+ ## Render the Runtime Report
97
+
98
+ The chain you write here renders with the Python CLI, same format by design:
99
+
100
+ ```
101
+ pip install halo-record
102
+ halo report ./runtime-records/acme.jsonl -o acme.html
103
+ ```
104
+
105
+ You end up looking at your agent's Runtime Report in a browser: every action, its provenance, the chain verdict, and (if anchored) the completeness verdict. Reference implementation and recorder internals: [halo-record (Python)](https://github.com/bkuan001/halo-record).
106
+
107
+ ## License
108
+
109
+ Apache-2.0
@@ -0,0 +1,22 @@
1
+ import type { HaloRecord } from "./record.ts";
2
+ export interface Checkpoint {
3
+ chain_root: string | null;
4
+ subject: string | null;
5
+ count: number;
6
+ head: string;
7
+ ts: string;
8
+ }
9
+ export declare function chainRoot(records: HaloRecord[]): string | null;
10
+ export declare function head(records: HaloRecord[]): string;
11
+ export declare function checkpoint(records: HaloRecord[]): Checkpoint;
12
+ export interface CompletenessResult {
13
+ ok: boolean | null;
14
+ why?: string;
15
+ at?: number;
16
+ have?: number;
17
+ witnessed_count?: number;
18
+ witnessed: number;
19
+ latest_count?: number;
20
+ head?: string;
21
+ }
22
+ export declare function verifyCompleteness(records: HaloRecord[], checkpoints: Checkpoint[]): CompletenessResult;
package/dist/anchor.js ADDED
@@ -0,0 +1,91 @@
1
+ /* Completeness witnessing — checkpoints + verification against a neutral
2
+ witness. Port of the Python anchor.py client-side surface. */
3
+ import { GENESIS_PREV, computeHash } from "./canon.js";
4
+ function nowZ() {
5
+ return new Date().toISOString();
6
+ }
7
+ /* Stable identity of a chain: the hash of its first record. */
8
+ export function chainRoot(records) {
9
+ if (records.length === 0)
10
+ return null;
11
+ const integ = (records[0]["integrity"] ?? {});
12
+ return integ["hash"] ?? null;
13
+ }
14
+ /* The current chain head — the last record's hash, or genesis if empty. */
15
+ export function head(records) {
16
+ if (records.length === 0)
17
+ return GENESIS_PREV;
18
+ const integ = (records[records.length - 1]["integrity"] ?? {});
19
+ return integ["hash"] ?? GENESIS_PREV;
20
+ }
21
+ function subjectId(records) {
22
+ for (const r of records) {
23
+ const s = r["subject"];
24
+ if (s && typeof s === "object" && s["id"]) {
25
+ return String(s["id"]);
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ /* A witness of the chain's current state. */
31
+ export function checkpoint(records) {
32
+ return {
33
+ chain_root: chainRoot(records),
34
+ subject: subjectId(records),
35
+ count: records.length,
36
+ head: head(records),
37
+ ts: nowZ(),
38
+ };
39
+ }
40
+ /* Recompute the hash chain. Returns the index (1-based) of the first broken
41
+ record, or 0 if intact. */
42
+ function chainIntact(records) {
43
+ let prev = GENESIS_PREV;
44
+ for (let i = 0; i < records.length; i++) {
45
+ const integ = (records[i]["integrity"] ?? {});
46
+ if (integ["prev_hash"] !== prev)
47
+ return i + 1;
48
+ const recomputed = computeHash(records[i], prev);
49
+ if (integ["hash"] !== recomputed)
50
+ return i + 1;
51
+ prev = integ["hash"] || recomputed;
52
+ }
53
+ return 0;
54
+ }
55
+ function matches(cp, records) {
56
+ const subj = subjectId(records);
57
+ if (subj !== null)
58
+ return cp.subject === subj;
59
+ return cp.chain_root === chainRoot(records);
60
+ }
61
+ /* Check a presented chain against what the notary independently witnessed.
62
+ ok=null: no witnesses (unknown, not a failure). ok=false: a witnessed record
63
+ is missing or altered. ok=true: every witnessed checkpoint still matches. */
64
+ export function verifyCompleteness(records, checkpoints) {
65
+ const relevant = checkpoints.filter((c) => matches(c, records));
66
+ if (relevant.length === 0) {
67
+ return { ok: null, why: "no witnesses for this chain", witnessed: 0 };
68
+ }
69
+ const brokenAt = chainIntact(records);
70
+ if (brokenAt) {
71
+ return { ok: false, why: "chain integrity broken", at: brokenAt, witnessed: relevant.length };
72
+ }
73
+ const latest = Math.max(...relevant.map((c) => c.count));
74
+ if (records.length < latest) {
75
+ return {
76
+ ok: false, why: "chain truncated below witnessed length",
77
+ have: records.length, witnessed_count: latest, witnessed: relevant.length,
78
+ };
79
+ }
80
+ for (const c of relevant) {
81
+ const n = c.count;
82
+ if (n < 1 || n > records.length) {
83
+ return { ok: false, why: "witnessed count out of range", at: n, witnessed: relevant.length };
84
+ }
85
+ const integ = (records[n - 1]["integrity"] ?? {});
86
+ if (integ["hash"] !== c.head) {
87
+ return { ok: false, why: "record altered or dropped before witnessed point", at: n, witnessed: relevant.length };
88
+ }
89
+ }
90
+ return { ok: true, witnessed: relevant.length, latest_count: latest, head: head(records) };
91
+ }
@@ -0,0 +1,8 @@
1
+ export declare const GENESIS_PREV: string;
2
+ export type Json = null | boolean | number | string | Json[] | {
3
+ [k: string]: Json;
4
+ };
5
+ export declare function canon(value: unknown): string;
6
+ export declare function sha256Hex(text: string): string;
7
+ export declare function computeHash(record: Record<string, unknown>, prevHash: string): string;
8
+ export declare function inputHash(value: unknown): string;
package/dist/canon.js ADDED
@@ -0,0 +1,99 @@
1
+ /* RFC 8785 (JSON Canonicalization Scheme) + SHA-256 hashing.
2
+ Byte-for-byte compatible with the Python implementation (canon.py): same
3
+ subset (integer-valued numbers only), same key ordering (UTF-16 code units,
4
+ which equals Python's utf-16-be byte sort), same string escaping. */
5
+ import { createHash } from "node:crypto";
6
+ export const GENESIS_PREV = "0".repeat(64);
7
+ export function canon(value) {
8
+ if (value === true)
9
+ return "true";
10
+ if (value === false)
11
+ return "false";
12
+ if (value === null || value === undefined)
13
+ return "null";
14
+ if (typeof value === "string")
15
+ return canonString(value);
16
+ if (typeof value === "number")
17
+ return canonNumber(value);
18
+ if (Array.isArray(value))
19
+ return "[" + value.map(canon).join(",") + "]";
20
+ if (typeof value === "object") {
21
+ const obj = value;
22
+ const keys = Object.keys(obj).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
23
+ return "{" + keys.map((k) => canonString(k) + ":" + canon(obj[k])).join(",") + "}";
24
+ }
25
+ throw new TypeError("cannot canonicalize " + typeof value);
26
+ }
27
+ function canonString(s) {
28
+ let out = '"';
29
+ for (const ch of s) {
30
+ const o = ch.codePointAt(0);
31
+ if (ch === '"')
32
+ out += '\\"';
33
+ else if (ch === "\\")
34
+ out += "\\\\";
35
+ else if (ch === "\b")
36
+ out += "\\b";
37
+ else if (ch === "\t")
38
+ out += "\\t";
39
+ else if (ch === "\n")
40
+ out += "\\n";
41
+ else if (ch === "\f")
42
+ out += "\\f";
43
+ else if (ch === "\r")
44
+ out += "\\r";
45
+ else if (o < 0x20)
46
+ out += "\\u" + o.toString(16).padStart(4, "0");
47
+ else
48
+ out += ch;
49
+ }
50
+ return out + '"';
51
+ }
52
+ function canonNumber(n) {
53
+ if (!Number.isFinite(n))
54
+ throw new RangeError("non-finite number is not valid JSON");
55
+ if (Number.isInteger(n))
56
+ return String(n);
57
+ throw new RangeError("non-integer float " + n + ": full RFC 8785 number formatting is out of scope; " +
58
+ "the record format uses integer-valued numbers only");
59
+ }
60
+ export function sha256Hex(text) {
61
+ return createHash("sha256").update(text, "utf8").digest("hex");
62
+ }
63
+ /* A record's integrity.hash: set integrity.prev_hash, drop integrity.hash,
64
+ canonicalize per RFC 8785, return the lowercase SHA-256 hex digest. */
65
+ export function computeHash(record, prevHash) {
66
+ const clone = JSON.parse(JSON.stringify(record));
67
+ const integ = (clone["integrity"] ??= {});
68
+ integ["prev_hash"] = prevHash;
69
+ delete integ["hash"];
70
+ return sha256Hex(canon(clone));
71
+ }
72
+ /* "sha256:" + SHA-256 of the canonical arguments, with a stable sorted-key
73
+ fallback so a recorder embedded in a hook never crashes on an odd input. */
74
+ export function inputHash(value) {
75
+ let c;
76
+ try {
77
+ c = canon(value);
78
+ }
79
+ catch {
80
+ c = stableStringify(value);
81
+ }
82
+ return "sha256:" + sha256Hex(c);
83
+ }
84
+ function stableStringify(value) {
85
+ if (value === null || value === undefined)
86
+ return "null";
87
+ if (typeof value === "string" || typeof value === "boolean")
88
+ return JSON.stringify(value);
89
+ if (typeof value === "number")
90
+ return Number.isFinite(value) ? JSON.stringify(value) : JSON.stringify(String(value));
91
+ if (Array.isArray(value))
92
+ return "[" + value.map(stableStringify).join(",") + "]";
93
+ if (typeof value === "object") {
94
+ const obj = value;
95
+ const keys = Object.keys(obj).sort();
96
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
97
+ }
98
+ return JSON.stringify(String(value));
99
+ }
@@ -0,0 +1,12 @@
1
+ export { GENESIS_PREV, canon, sha256Hex, computeHash, inputHash } from "./canon.ts";
2
+ export { redactText, redactSample, scan, topSeverity, SEVERITY_RANK, type Finding, type Severity } from "./redact.ts";
3
+ export { SCHEMA_VERSION, ACTION_TYPES, CATEGORIES, SOURCES, normalizeSource, build, Recorder, TenantRecorder, type Source, type BuildOptions, type HaloRecord, } from "./record.ts";
4
+ export { loadSchema, validateRecord, verifyRecords, verifyLog, readLog, type VerifyResult } from "./verify.ts";
5
+ export { chainRoot, head, checkpoint, verifyCompleteness, type Checkpoint, type CompletenessResult, } from "./anchor.ts";
6
+ export { anchorRemote, fetchCheckpoints } from "./witness.ts";
7
+ export { classifyTool, deriveScope, deriveOutcome, recordToolCall, recordModelCall, ACTION_TYPE_BY_CLASS, CATEGORY_BY_CLASS, type ActionClass, type RecorderLike, type ToolCallOptions, type ModelCallOptions, } from "./integrations/common.ts";
8
+ export { createLangChainHandler, type LangChainHandlerOptions } from "./integrations/langchain.ts";
9
+ export { recordMcpCall, instrumentMcpClient, wrapMcpToolHandler, type McpOptions } from "./integrations/mcp.ts";
10
+ export { createAgentsHooks, type AgentsHooksOptions } from "./integrations/openaiAgents.ts";
11
+ export { wrapVercelTools, createStepRecorder, type VercelOptions } from "./integrations/vercel.ts";
12
+ export { createClaudeAgentHook, DEFAULT_SKIP_TOOLS, type ClaudeAgentHookOptions } from "./integrations/claudeAgent.ts";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /* halo-record — tamper-evident Runtime Records for AI agents (TypeScript).
2
+ Same chain format as the Python package: records written here verify with
3
+ either verifier and anchor to the same witness. */
4
+ export { GENESIS_PREV, canon, sha256Hex, computeHash, inputHash } from "./canon.js";
5
+ export { redactText, redactSample, scan, topSeverity, SEVERITY_RANK } from "./redact.js";
6
+ export { SCHEMA_VERSION, ACTION_TYPES, CATEGORIES, SOURCES, normalizeSource, build, Recorder, TenantRecorder, } from "./record.js";
7
+ export { loadSchema, validateRecord, verifyRecords, verifyLog, readLog } from "./verify.js";
8
+ export { chainRoot, head, checkpoint, verifyCompleteness, } from "./anchor.js";
9
+ export { anchorRemote, fetchCheckpoints } from "./witness.js";
10
+ export { classifyTool, deriveScope, deriveOutcome, recordToolCall, recordModelCall, ACTION_TYPE_BY_CLASS, CATEGORY_BY_CLASS, } from "./integrations/common.js";
11
+ export { createLangChainHandler } from "./integrations/langchain.js";
12
+ export { recordMcpCall, instrumentMcpClient, wrapMcpToolHandler } from "./integrations/mcp.js";
13
+ export { createAgentsHooks } from "./integrations/openaiAgents.js";
14
+ export { wrapVercelTools, createStepRecorder } from "./integrations/vercel.js";
15
+ export { createClaudeAgentHook, DEFAULT_SKIP_TOOLS } from "./integrations/claudeAgent.js";
@@ -0,0 +1,29 @@
1
+ import { type RecorderLike } from "./common.ts";
2
+ import type { Source } from "../record.ts";
3
+ export declare const DEFAULT_SKIP_TOOLS: Set<string>;
4
+ export interface ClaudeAgentHookOptions {
5
+ category?: string;
6
+ scope?: string;
7
+ sessionId?: string;
8
+ agent?: {
9
+ id: string;
10
+ name: string;
11
+ };
12
+ subject?: string | {
13
+ id: string;
14
+ name?: string;
15
+ } | null;
16
+ source?: string | Partial<Source>;
17
+ summaries?: boolean;
18
+ skipTools?: Set<string>;
19
+ }
20
+ interface PostToolUseInput {
21
+ hook_event_name?: string;
22
+ tool_name?: string;
23
+ tool_input?: unknown;
24
+ tool_response?: unknown;
25
+ session_id?: string;
26
+ [k: string]: unknown;
27
+ }
28
+ export declare function createClaudeAgentHook(recorder: RecorderLike, opts?: ClaudeAgentHookOptions): (input: PostToolUseInput, _toolUseID?: string, _extra?: unknown) => Promise<Record<string, never>>;
29
+ export {};
@@ -0,0 +1,44 @@
1
+ /* Claude Agent SDK adapter.
2
+
3
+ Returns a PostToolUse hook callback — every tool call the agent makes is
4
+ recorded, and the hook never blocks or alters the call (record-only, by
5
+ design). No dependency on @anthropic-ai/claude-agent-sdk; the hook input
6
+ shape is structural (same event JSON as the Claude Code hook):
7
+
8
+ import { Recorder, createClaudeAgentHook } from "halo-record";
9
+
10
+ const rec = new Recorder("audit.jsonl");
11
+ const result = query({
12
+ prompt,
13
+ options: {
14
+ hooks: { PostToolUse: [{ hooks: [createClaudeAgentHook(rec)] }] },
15
+ },
16
+ });
17
+
18
+ Skips the same workflow-internal tools as the Python Claude Code hook
19
+ (TodoWrite, Task, etc.) — override with opts.skipTools. */
20
+ import { recordToolCall } from "./common.js";
21
+ const AGENT = { id: "claude_agent_sdk", name: "claude_agent_sdk" };
22
+ /* Same defaults as the Python hook's SKIP_TOOLS. */
23
+ export const DEFAULT_SKIP_TOOLS = new Set([
24
+ "TodoWrite", "ExitPlanMode", "Task", "Skill", "BashOutput", "KillShell",
25
+ ]);
26
+ export function createClaudeAgentHook(recorder, opts = {}) {
27
+ const skip = opts.skipTools ?? DEFAULT_SKIP_TOOLS;
28
+ return async (input, _toolUseID, _extra) => {
29
+ const name = input?.tool_name;
30
+ if (name && !skip.has(name)) {
31
+ recordToolCall(recorder, name, input.tool_input, {
32
+ response: input.tool_response,
33
+ agent: opts.agent ?? AGENT,
34
+ category: opts.category,
35
+ scope: opts.scope,
36
+ sessionId: opts.sessionId ?? (typeof input.session_id === "string" ? input.session_id : "local"),
37
+ subject: opts.subject,
38
+ source: opts.source ?? "claude_agent_sdk",
39
+ summaries: opts.summaries ?? true,
40
+ });
41
+ }
42
+ return {}; // record-only: never block, never modify
43
+ };
44
+ }