@verax-ai/proxy 0.9.0 → 0.10.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/dist/approvals.js +2 -0
- package/dist/canary.d.ts +118 -0
- package/dist/canary.js +755 -0
- package/dist/explain.js +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/inputs.d.ts +5 -0
- package/dist/inputs.js +38 -0
- package/dist/ledger.js +17 -1
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +38 -1
- package/dist/proxy.js +274 -26
- package/dist/session-taint.d.ts +92 -0
- package/dist/session-taint.js +343 -0
- package/dist/tool-labels.d.ts +43 -0
- package/dist/tool-labels.js +94 -0
- package/dist/types.d.ts +82 -1
- package/dist/verify-ledger.js +28 -11
- package/package.json +1 -1
package/dist/explain.js
CHANGED
|
@@ -3,6 +3,7 @@ import { findDecisionRecordChainBreak } from "@cedulon/core";
|
|
|
3
3
|
import { approvalsLogFor } from "./approvals.js";
|
|
4
4
|
import { sha256Canonical } from "./hash.js";
|
|
5
5
|
import { inputsLogFor, inputsMatchingHash } from "./inputs.js";
|
|
6
|
+
import { taintOnInputs } from "./session-taint.js";
|
|
6
7
|
import { lookupResolvedBy } from "./ledger.js";
|
|
7
8
|
import { loadCheckpoints } from "./checkpoints.js";
|
|
8
9
|
import { samePublicKey, thirdPartyReceiptCoversRow } from "./third-party.js";
|
|
@@ -346,6 +347,12 @@ export async function explain(ledger, ref, opts) {
|
|
|
346
347
|
source: pinSource,
|
|
347
348
|
},
|
|
348
349
|
...(report.scope ? { scope: report.scope } : {}),
|
|
350
|
+
...(inputsDoc &&
|
|
351
|
+
typeof record.claims.inputsHash === "string" &&
|
|
352
|
+
sha256Canonical(inputsDoc) === record.claims.inputsHash &&
|
|
353
|
+
taintOnInputs(inputsDoc)
|
|
354
|
+
? { sessionTaint: taintOnInputs(inputsDoc) }
|
|
355
|
+
: {}),
|
|
349
356
|
finding: {
|
|
350
357
|
code,
|
|
351
358
|
label: guarantee === "conditional" || conditions.length > 0 ? "conditional" : null,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type { PolicyParseOptions } from "./policy.ts";
|
|
|
7
7
|
export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, lockBeatOf } from "./ledger.ts";
|
|
8
8
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.ts";
|
|
9
9
|
export { explain } from "./explain.ts";
|
|
10
|
+
export { unlabelledDownstreamNames } from "./tool-labels.ts";
|
|
11
|
+
export { appendTaintClearLine } from "./session-taint.ts";
|
|
10
12
|
export { approvalArgsBound, approvalDispatchArgs, approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.ts";
|
|
11
13
|
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadSignedForwardedHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.ts";
|
|
12
14
|
export { tenantKey } from "./tenant.ts";
|
|
@@ -14,6 +16,8 @@ export { diskProbe } from "./disk.ts";
|
|
|
14
16
|
export { checkpointsPath, readCheckpointFile } from "./checkpoints.ts";
|
|
15
17
|
export { signEffectAttestation } from "./ledger.ts";
|
|
16
18
|
export { spokenReason } from "./spoken-reason.ts";
|
|
19
|
+
export { CANARY_CHECK_BOUND_MS, CANARY_FILE, CANARY_FINDING, CANARY_SHAPES, activeCanaryValue, addCanary, CanaryStoreError, haltForCanary, listCanaries, loadActiveCanaries, matchCanary, readCanaryFile, retireCanary, writeCanaryFile, } from "./canary.ts";
|
|
20
|
+
export type { CanaryListRow, CanaryMatch, CanaryNeedle, CanaryShape, StoredCanary } from "./canary.ts";
|
|
17
21
|
export { OPERATOR_REMOVED_DIR, operatorRemovalMark } from "./operator-removal-sync.ts";
|
|
18
22
|
export type { ApprovalRow, ApproveResult } from "./approvals.ts";
|
|
19
23
|
export type { CardCsvOpts, ChannelRow, ReconcileReport } from "./reconcile.ts";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export { loadPolicy, TERMINAL_CONTROL_CLASS, DISPLAY_ESCAPE_CLASS, terminalText,
|
|
|
6
6
|
export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, lockBeatOf } from "./ledger.js";
|
|
7
7
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.js";
|
|
8
8
|
export { explain } from "./explain.js";
|
|
9
|
+
export { unlabelledDownstreamNames } from "./tool-labels.js";
|
|
10
|
+
export { appendTaintClearLine } from "./session-taint.js";
|
|
9
11
|
export { approvalArgsBound, approvalDispatchArgs, approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.js";
|
|
10
12
|
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadSignedForwardedHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.js";
|
|
11
13
|
export { tenantKey } from "./tenant.js";
|
|
@@ -19,6 +21,7 @@ export { diskProbe } from "./disk.js";
|
|
|
19
21
|
export { checkpointsPath, readCheckpointFile } from "./checkpoints.js";
|
|
20
22
|
export { signEffectAttestation } from "./ledger.js";
|
|
21
23
|
export { spokenReason } from "./spoken-reason.js";
|
|
24
|
+
export { CANARY_CHECK_BOUND_MS, CANARY_FILE, CANARY_FINDING, CANARY_SHAPES, activeCanaryValue, addCanary, CanaryStoreError, haltForCanary, listCanaries, loadActiveCanaries, matchCanary, readCanaryFile, retireCanary, writeCanaryFile, } from "./canary.js";
|
|
22
25
|
export { OPERATOR_REMOVED_DIR, operatorRemovalMark } from "./operator-removal-sync.js";
|
|
23
26
|
export { verifyLedger } from "./verify-ledger.js";
|
|
24
27
|
export { anchorEntryHash, appendAnchor, isEntryId, readAnchors } from "./anchors.js";
|
package/dist/inputs.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class MemoryInputsLog implements InputsLog {
|
|
|
4
4
|
append(ref: string, inputs: DecisionInputs): Promise<void>;
|
|
5
5
|
get(ref: string): Promise<DecisionInputs | null>;
|
|
6
6
|
getMatching(ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
7
|
+
readIndex(): Promise<Map<string, DecisionInputs>>;
|
|
7
8
|
}
|
|
8
9
|
export declare class FileInputsLog implements InputsLog {
|
|
9
10
|
private readonly dir;
|
|
@@ -17,7 +18,11 @@ export declare class FileInputsLog implements InputsLog {
|
|
|
17
18
|
append(ref: string, inputs: DecisionInputs): Promise<void>;
|
|
18
19
|
get(ref: string): Promise<DecisionInputs | null>;
|
|
19
20
|
getMatching(ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
21
|
+
/** One read of every inputs file. The last row for a ref and hash wins, as `getMatching` does. */
|
|
22
|
+
readIndex(): Promise<Map<string, DecisionInputs>>;
|
|
20
23
|
}
|
|
24
|
+
/** The ref+hash map from one read, when the log can build it. Null means the caller walks record by record. */
|
|
25
|
+
export declare function readInputsIndex(log: InputsLog): Promise<Map<string, DecisionInputs> | null>;
|
|
21
26
|
/** The inputs row `hash` names. Last-row `get` is not this. */
|
|
22
27
|
export declare function inputsMatchingHash(log: InputsLog, ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
23
28
|
export declare function inputsLogFor(ledger: object): InputsLog;
|
package/dist/inputs.js
CHANGED
|
@@ -15,6 +15,13 @@ export class MemoryInputsLog {
|
|
|
15
15
|
return null;
|
|
16
16
|
return sha256Canonical(row) === hash ? row : null;
|
|
17
17
|
}
|
|
18
|
+
async readIndex() {
|
|
19
|
+
const map = new Map();
|
|
20
|
+
for (const [ref, inputs] of this.rows) {
|
|
21
|
+
map.set(`${sha256Canonical(inputs)}:${ref}`, inputs);
|
|
22
|
+
}
|
|
23
|
+
return map;
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
export class FileInputsLog {
|
|
20
27
|
dir;
|
|
@@ -83,6 +90,37 @@ export class FileInputsLog {
|
|
|
83
90
|
}
|
|
84
91
|
return found;
|
|
85
92
|
}
|
|
93
|
+
/** One read of every inputs file. The last row for a ref and hash wins, as `getMatching` does. */
|
|
94
|
+
async readIndex() {
|
|
95
|
+
const map = new Map();
|
|
96
|
+
for (const path of this.paths().all) {
|
|
97
|
+
let text;
|
|
98
|
+
try {
|
|
99
|
+
text = await ledgerFs.readFile(path, "utf8");
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err.code === "ENOENT")
|
|
103
|
+
continue;
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
for (const line of text.split("\n")) {
|
|
107
|
+
if (line === "")
|
|
108
|
+
continue;
|
|
109
|
+
const row = JSON.parse(line);
|
|
110
|
+
if (typeof row.ref !== "string")
|
|
111
|
+
continue;
|
|
112
|
+
map.set(`${sha256Canonical(row.inputs)}:${row.ref}`, row.inputs);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return map;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** The ref+hash map from one read, when the log can build it. Null means the caller walks record by record. */
|
|
119
|
+
export async function readInputsIndex(log) {
|
|
120
|
+
const reader = log;
|
|
121
|
+
if (typeof reader.readIndex !== "function")
|
|
122
|
+
return null;
|
|
123
|
+
return reader.readIndex();
|
|
86
124
|
}
|
|
87
125
|
/** The inputs row `hash` names. Last-row `get` is not this. */
|
|
88
126
|
export async function inputsMatchingHash(log, ref, hash) {
|
package/dist/ledger.js
CHANGED
|
@@ -126,6 +126,7 @@ function signedEffectFields(row, witnessClass, resultHash, signer) {
|
|
|
126
126
|
if (!signer)
|
|
127
127
|
return {};
|
|
128
128
|
const clean = asEffectRow(row);
|
|
129
|
+
const receiving = receivingSessionOf(row);
|
|
129
130
|
const receipt = signEffectExtract({
|
|
130
131
|
deciderId: "verax-proxy",
|
|
131
132
|
channelId: "verax-body",
|
|
@@ -138,6 +139,7 @@ function signedEffectFields(row, witnessClass, resultHash, signer) {
|
|
|
138
139
|
effectHash: clean.effectHash,
|
|
139
140
|
witnessClass,
|
|
140
141
|
resultHash: resultHash ?? null,
|
|
142
|
+
...(receiving ? { session: receiving.jti, sessionId: receiving.sessionId } : {}),
|
|
141
143
|
}), "utf8");
|
|
142
144
|
const attestation = {
|
|
143
145
|
coseHex: coseToHex(signCoseSign1(payload, signer.privateKeyPem, "application/json")),
|
|
@@ -153,6 +155,14 @@ function asEffectRow(row) {
|
|
|
153
155
|
...(row.actor !== undefined ? { actor: row.actor } : {}),
|
|
154
156
|
};
|
|
155
157
|
}
|
|
158
|
+
function receivingSessionOf(row) {
|
|
159
|
+
const extra = row.receivingSession;
|
|
160
|
+
if (!extra || typeof extra.jti !== "string" || extra.jti === "")
|
|
161
|
+
return undefined;
|
|
162
|
+
if (typeof extra.sessionId !== "string" || extra.sessionId === "")
|
|
163
|
+
return undefined;
|
|
164
|
+
return { jti: extra.jti, sessionId: extra.sessionId };
|
|
165
|
+
}
|
|
156
166
|
function asStoredEffect(row, witnessClass, resultHash, signer, externalReceipt) {
|
|
157
167
|
if (witnessClass === "third-party") {
|
|
158
168
|
// The downstream signed only the extract: resultHash is stored but unattested.
|
|
@@ -166,6 +176,9 @@ function asStoredEffect(row, witnessClass, resultHash, signer, externalReceipt)
|
|
|
166
176
|
};
|
|
167
177
|
if (resultHash !== undefined)
|
|
168
178
|
stored.resultHash = resultHash;
|
|
179
|
+
const receiving = receivingSessionOf(row);
|
|
180
|
+
if (receiving)
|
|
181
|
+
stored.receivingSession = receiving;
|
|
169
182
|
return stored;
|
|
170
183
|
}
|
|
171
184
|
function indexRowOf(signed) {
|
|
@@ -197,8 +210,11 @@ function noteReauth(map, row) {
|
|
|
197
210
|
}
|
|
198
211
|
function noteCounted(times, row) {
|
|
199
212
|
// A halt or resume is not a tool call. Counting it would spend the rate budget on the switch.
|
|
200
|
-
|
|
213
|
+
// A halt, a resume, or a session-taint clear is not a tool call. Counting it
|
|
214
|
+
// would spend the rate budget on the operator's command.
|
|
215
|
+
if (row.reasonCode === "operator-halt" || row.reasonCode === "operator-resume" || row.reasonCode === "taint-cleared") {
|
|
201
216
|
return;
|
|
217
|
+
}
|
|
202
218
|
if (row.decision === "allow" || row.decision === "defer")
|
|
203
219
|
times.push(row.timestampMs);
|
|
204
220
|
}
|
package/dist/policy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataClassChoice, MediaConfig, Policy, ResultClassChoice } from "./types.ts";
|
|
1
|
+
import type { DataClassChoice, MediaConfig, Policy, ToolLabelName, ResultClassChoice } from "./types.ts";
|
|
2
2
|
export type PolicySpend = {
|
|
3
3
|
maxAmountMinor: number;
|
|
4
4
|
currency: string;
|
|
@@ -43,6 +43,14 @@ export type PolicyDocument = {
|
|
|
43
43
|
block: readonly string[];
|
|
44
44
|
};
|
|
45
45
|
scanCharCap?: number;
|
|
46
|
+
/** Absent: a canary match halts. `deny` records the deny and does not flip the switch. */
|
|
47
|
+
canary?: "halt" | "deny";
|
|
48
|
+
/** Operator labels. A present key replaces the built-in default for that tool. */
|
|
49
|
+
toolLabels?: Readonly<Record<string, readonly ToolLabelName[]>>;
|
|
50
|
+
/** Absent means hold. */
|
|
51
|
+
sessionTaint?: "hold" | "deny";
|
|
52
|
+
/** Absent means an unlabelled downstream tool is both labels. */
|
|
53
|
+
unlabelledDownstream?: "both" | "neither";
|
|
46
54
|
rules: PolicyRule[];
|
|
47
55
|
};
|
|
48
56
|
/** Named per tool. Do not sniff `host` / `url` on arbitrary arguments. */
|
package/dist/policy.js
CHANGED
|
@@ -2,6 +2,7 @@ import { parseIJson } from "@cedulon/core";
|
|
|
2
2
|
import { dataClassMapHasLocal, parseDataClassMap } from "./data-classes.js";
|
|
3
3
|
import { defaultDiskFreeBytes } from "./disk.js";
|
|
4
4
|
import { sha256Canonical } from "./hash.js";
|
|
5
|
+
import { parseToolLabelMap } from "./tool-labels.js";
|
|
5
6
|
/** One DNS label: letters, digits, hyphens; no leading or trailing hyphen. */
|
|
6
7
|
function plainDnsLabel(label) {
|
|
7
8
|
if (label.length === 0 || label.length > 63)
|
|
@@ -48,7 +49,19 @@ export const HOST_EXTRACTORS = {
|
|
|
48
49
|
"message.send": messageSendHost,
|
|
49
50
|
};
|
|
50
51
|
const DEFAULT_APPROVAL_TTL_MS = 86_400_000;
|
|
51
|
-
const DOCUMENT_KEYS = new Set([
|
|
52
|
+
const DOCUMENT_KEYS = new Set([
|
|
53
|
+
"version",
|
|
54
|
+
"default",
|
|
55
|
+
"rules",
|
|
56
|
+
"egress",
|
|
57
|
+
"approvalTtlMs",
|
|
58
|
+
"limits",
|
|
59
|
+
"requireInputs",
|
|
60
|
+
"canary",
|
|
61
|
+
"toolLabels",
|
|
62
|
+
"sessionTaint",
|
|
63
|
+
"unlabelledDownstream",
|
|
64
|
+
]);
|
|
52
65
|
const DOCUMENT_KEYS_V2 = new Set([
|
|
53
66
|
...DOCUMENT_KEYS,
|
|
54
67
|
"dataClasses",
|
|
@@ -309,6 +322,21 @@ export function parsePolicyDocument(json, options = {}) {
|
|
|
309
322
|
}
|
|
310
323
|
document.requireInputs = true;
|
|
311
324
|
}
|
|
325
|
+
if (rec.toolLabels !== undefined) {
|
|
326
|
+
document.toolLabels = parseToolLabelMap(rec.toolLabels, "policy-tool-labels");
|
|
327
|
+
}
|
|
328
|
+
if (rec.sessionTaint !== undefined) {
|
|
329
|
+
if (rec.sessionTaint !== "hold" && rec.sessionTaint !== "deny") {
|
|
330
|
+
throw new Error("policy-session-taint");
|
|
331
|
+
}
|
|
332
|
+
document.sessionTaint = rec.sessionTaint;
|
|
333
|
+
}
|
|
334
|
+
if (rec.unlabelledDownstream !== undefined) {
|
|
335
|
+
if (rec.unlabelledDownstream !== "both" && rec.unlabelledDownstream !== "neither") {
|
|
336
|
+
throw new Error("policy-unlabelled-downstream");
|
|
337
|
+
}
|
|
338
|
+
document.unlabelledDownstream = rec.unlabelledDownstream;
|
|
339
|
+
}
|
|
312
340
|
if (version === 2) {
|
|
313
341
|
if (rec.dataClasses !== undefined) {
|
|
314
342
|
document.dataClasses = parseDataClassMap(rec.dataClasses);
|
|
@@ -339,6 +367,11 @@ export function parsePolicyDocument(json, options = {}) {
|
|
|
339
367
|
throw new Error("policy-data-class-local-tools");
|
|
340
368
|
}
|
|
341
369
|
}
|
|
370
|
+
if (rec.canary !== undefined) {
|
|
371
|
+
if (rec.canary !== "halt" && rec.canary !== "deny")
|
|
372
|
+
throw new Error("policy-canary");
|
|
373
|
+
document.canary = rec.canary === "halt" ? "halt" : "deny";
|
|
374
|
+
}
|
|
342
375
|
rejectDuplicateRules(document.rules);
|
|
343
376
|
return document;
|
|
344
377
|
}
|
|
@@ -517,6 +550,10 @@ export function loadPolicy(json, options = {}) {
|
|
|
517
550
|
approvalTtlMs: document.approvalTtlMs ?? DEFAULT_APPROVAL_TTL_MS,
|
|
518
551
|
limits,
|
|
519
552
|
...(document.requireInputs ? { requireInputs: true } : {}),
|
|
553
|
+
...(document.canary !== undefined ? { canary: document.canary } : {}),
|
|
554
|
+
toolLabels: document.toolLabels ?? {},
|
|
555
|
+
sessionTaint: document.sessionTaint ?? "hold",
|
|
556
|
+
unlabelledDownstream: document.unlabelledDownstream ?? "both",
|
|
520
557
|
...(document.version === 2
|
|
521
558
|
? {
|
|
522
559
|
...(document.dataClasses !== undefined ||
|