@verax-ai/body 0.8.2 → 0.9.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.
@@ -0,0 +1,163 @@
1
+ import { type SignedCheckpoint } from "@cedulon/checkpoint";
2
+ import { type SignedDecisionRecord } from "@cedulon/core";
3
+ export declare const EX_USAGE = 64;
4
+ /** Same code `verax verify` uses for an unreadable state directory. */
5
+ export declare const EX_STATE_UNREADABLE = 77;
6
+ type DecisionCounts = {
7
+ allow: number;
8
+ deny: number;
9
+ defer: number;
10
+ };
11
+ export type ApprovalCounts = {
12
+ approved: number;
13
+ withOperatorSignatureFieldPresent: number;
14
+ withoutOperatorSignatureField: number;
15
+ closedWithoutAllow: number;
16
+ /**
17
+ * Defers with no hash-bound answer. Established as a fact only when no held
18
+ * defer could be answered by an unbound record after it; otherwise null
19
+ * (see heldWithoutBoundAnswer / heldPossiblyAnsweredByUnbound).
20
+ */
21
+ stillHeld: number | null;
22
+ unmatched: number;
23
+ /** Allow/deny records in the window whose inputs are not hash-bound. */
24
+ terminalsWithoutBoundInputs: number;
25
+ /** Defers with no hash-bound answer (raw open count; always computed). */
26
+ heldWithoutBoundAnswer: number;
27
+ /**
28
+ * Of those held without a bound answer, how many an unbound terminal's
29
+ * inputs row names with matching request hash and tool.
30
+ */
31
+ heldPossiblyAnsweredByUnbound: number;
32
+ };
33
+ export type PeriodReport = {
34
+ from: string;
35
+ to: string;
36
+ /** Head of the whole verified ledger. Null when the ledger does not verify. */
37
+ headHash: string | null;
38
+ /** Records in the window. Null when the ledger does not verify. */
39
+ recordCount: number | null;
40
+ firstRecordMs: number | null;
41
+ lastRecordMs: number | null;
42
+ verification: {
43
+ ok: boolean;
44
+ verdict: string;
45
+ problems: string[];
46
+ };
47
+ /** Why every count is null, or null when counts are available. */
48
+ countsUnavailableReason: string | null;
49
+ /** Set when approvals.jsonl is malformed. Never affects verdict or counts. */
50
+ unsignedApprovalsNote: string | null;
51
+ decisions: {
52
+ total: DecisionCounts | null;
53
+ byTool: {
54
+ [tool: string]: DecisionCounts;
55
+ } | null;
56
+ /**
57
+ * Records whose subject is empty or not a string. Null when counts are
58
+ * unavailable. Identity: for each kind, sum(byTool[*][kind]) +
59
+ * withoutSubject[kind] === total[kind].
60
+ */
61
+ withoutSubject: DecisionCounts | null;
62
+ };
63
+ approvals: {
64
+ approved: number | null;
65
+ /** Approving records whose hash-bound inputs carry an approver signature field. Not a verification. */
66
+ withOperatorSignatureFieldPresent: number | null;
67
+ withoutOperatorSignatureField: number | null;
68
+ closedWithoutAllow: number | null;
69
+ stillHeld: number | null;
70
+ unmatched: number | null;
71
+ /** Allow/deny in the window with no hash-bound inputs. Null when counts unavailable. */
72
+ terminalsWithoutBoundInputs: number | null;
73
+ /** Defers with no hash-bound answer. Null when counts unavailable. */
74
+ heldWithoutBoundAnswer: number | null;
75
+ /** Held defers an unbound terminal's inputs row could answer. Null when counts unavailable. */
76
+ heldPossiblyAnsweredByUnbound: number | null;
77
+ /** Class only, when approvals could not be counted although the ledger verified. */
78
+ unavailableReason: string | null;
79
+ };
80
+ checkpoints: {
81
+ count: number | null;
82
+ /** Anchor receipts for window checkpoints that verified. Zero when anchors were not checked. */
83
+ withAnchorVerified: number | null;
84
+ /** Anchor rows for window checkpoints present but not checked (no anchor key). */
85
+ anchorRowsPresentNotChecked: number | null;
86
+ /** Class only, when anchors could not be read although the ledger verified. */
87
+ anchorUnavailableReason: string | null;
88
+ };
89
+ whatThisReportDoesNotShow: string;
90
+ };
91
+ /** UTC midnight for a calendar date, or null when the string is not YYYY-MM-DD. */
92
+ export declare function parseReportDate(raw: string): number | null;
93
+ /**
94
+ * Usable per-tool subject, or null when empty or not a string. Null subjects
95
+ * are counted in `withoutSubject`, not under a synthetic byTool key, so a
96
+ * real tool named U+001F cannot collide with the empty/missing bucket.
97
+ */
98
+ export declare function subjectToolKey(subject: unknown): string | null;
99
+ /**
100
+ * Stable class for a verify problem line: the longest known class prefix
101
+ * followed by a space, a colon, or the end. Ledger detail after that prefix
102
+ * is dropped. Anything that is not a known class is `unclassified`.
103
+ */
104
+ export declare function problemClass(problem: string): string;
105
+ /** Decision records in chain order, using the same piece listing verify's helpers use. */
106
+ export declare function readDecisionRecords(dir: string): SignedDecisionRecord[];
107
+ /**
108
+ * Cedulon/verify coverage is half-open `[startMs, endMs)` (see verify-ledger:
109
+ * `r.claims.timestampMs >= startMs && r.claims.timestampMs < endMs`). Overlap
110
+ * with the report window `[fromMs, toExclusive)` is therefore
111
+ * `start < toExclusive && fromMs < end`. A checkpoint with `start >= end`
112
+ * covers nothing and is never counted.
113
+ */
114
+ export declare function checkpointInWindow(row: SignedCheckpoint, fromMs: number, toExclusive: number): boolean;
115
+ /**
116
+ * Held-call counts from attested records only, in chain order.
117
+ *
118
+ * A defer is answered by the first terminal (allow or deny) record that
119
+ * follows it in chain order, whose hash-bound inputs name the defer's ref in
120
+ * `approver.resolves`, and that agrees with the defer on request hash and
121
+ * tool. A record whose decision is defer is never an answer. One answer
122
+ * answers one defer: each answer names at most one resolves ref, and a ref
123
+ * shared by two defers is unmatched, so no shared-consumption set is needed.
124
+ * A defer with no usable ref, a ref shared with another defer, or only
125
+ * disagreeing answers is unmatched.
126
+ *
127
+ * Identity (when counts are available):
128
+ * approved + closedWithoutAllow + unmatched + heldWithoutBoundAnswer
129
+ * === windowDeferCount
130
+ * Bound answers and unbound possibility both scan every later terminal in
131
+ * chain order, inside the window or not. stillHeld is heldWithoutBoundAnswer
132
+ * when no held defer could be answered by an unbound record after it
133
+ * (heldPossiblyAnsweredByUnbound === 0); otherwise null. terminalsWithoutBoundInputs
134
+ * still counts only unbound terminals whose time falls in the window.
135
+ * heldPossiblyAnsweredByUnbound never exceeds heldWithoutBoundAnswer.
136
+ */
137
+ export declare function countApprovalsFromSigned(dir: string, all: readonly SignedDecisionRecord[], fromMs: number, toExclusive: number): ApprovalCounts;
138
+ /**
139
+ * Temp file with a random name, exclusive create, then a hard link to the
140
+ * final name: the link fails with EEXIST if the target exists, so an existing
141
+ * file is never replaced. The temp name is removed on every path.
142
+ * `tempPath` is for tests that plant a collision at a known name; the CLI
143
+ * never passes it.
144
+ */
145
+ export declare function writeOutExclusive(outPath: string, content: string, tempPath?: string): void;
146
+ export declare function buildPeriodReport(dir: string, from: string, to: string, fromMs: number, toExclusive: number): Promise<PeriodReport>;
147
+ /**
148
+ * Fixed key order. The same ledger and window give the same bytes. These are
149
+ * the one canonical display-safe bytes: terminal-control and bidi characters
150
+ * are escaped here, before any digest, so stdout, the digest and the digest
151
+ * shown in HTML are all of this exact sequence.
152
+ */
153
+ export declare function serializePeriodReport(report: PeriodReport): string;
154
+ export declare function reportDigest(jsonBytes: string): string;
155
+ export declare function htmlEscape(text: string): string;
156
+ export declare function renderReportHtml(report: PeriodReport, digest: string): string;
157
+ export declare function renderReportText(report: PeriodReport, digest: string): string;
158
+ export declare function runReport(argv: readonly string[], out?: (s: string) => void,
159
+ /** Test-only: force the exclusive-create temp path. Not a CLI flag. */
160
+ opts?: {
161
+ writeTempPath?: string;
162
+ }): Promise<number>;
163
+ export {};