Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 2 to 318

Compare

+46 −0 in 1 place
new file, 46 lines
1+import { createHash } from "node:crypto";
2+import { jsonValueChunks } from "../../src/engine/json-value-chunks.ts";
3+
4+/** Preserve canonicalJson identity bytes without retaining the complete encoded request. */
5+export function requestIdentityDigest(value: unknown): string {
6+ const hash = createHash("sha256");
7+ const active = new Set<object>();
8+ function* chunks(input: unknown, absent?: string): Generator<string> {
9+ if (typeof input === "string") {
10+ yield* jsonValueChunks(input);
11+ } else if (input && typeof input === "object") {
12+ if (active.has(input)) throw new TypeError("cyclic request identity");
13+ active.add(input);
14+ try {
15+ if (Array.isArray(input)) {
16+ yield "[";
17+ const length = input.length;
18+ for (let i = 0; i < length; i++) {
19+ if (i) yield ",";
20+ if (i in input) yield* chunks(input[i], "");
21+ }
22+ yield "]";
23+ } else {
24+ yield "{";
25+ let first = true;
26+ for (const key of Object.keys(input).sort()) {
27+ if (!first) yield ",";
28+ first = false;
29+ yield* jsonValueChunks(key);
30+ yield ":";
31+ yield* chunks((input as Record<string, unknown>)[key], "undefined");
32+ }
33+ yield "}";
34+ }
35+ } finally {
36+ active.delete(input);
37+ }
38+ } else {
39+ const encoded = JSON.stringify(input);
40+ if (encoded === undefined && absent === undefined) throw new TypeError("unsupported request identity");
41+ yield encoded ?? absent!;
42+ }
43+ }
44+ for (const chunk of chunks(value)) hash.update(chunk);
45+ return hash.digest("hex");
46+}
MCP
compare on this site's /mcp
CLI
abso diff 2 318 server/src/request-identity-digest.ts --json
JSON
/christopher/abso-core/compare/2..318?file=server%2Fsrc%2Frequest-identity-digest.ts&format=json