@zanii/blackbox 0.21.0 → 0.21.1

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.
@@ -103,4 +103,4 @@ export declare function verifyRegression(events: Ev[]): Finding[];
103
103
  /** Stage 2 R4, judged at close: a run labelled (or claimed) a success that its own record contradicts:
104
104
  * a check's last result failed, or the last tool call failed with nothing succeeding after it. */
105
105
  export declare function falseSuccess(events: Ev[], now: number): Finding[];
106
- export { type Growth, growth, isoWeek, type Lessons, lessons, POWER_KINDS, promptChanged, SELF_CHANGE_KINDS, selfChanges, systemPromptHash, toolsHash, } from "./learning.ts";
106
+ export { type Growth, growth, isoWeek, type Lessons, lessons, POWER_KINDS, promptChanged, SELF_CHANGE_KINDS, selfChanges, successRange, systemPromptHash, toolsHash, } from "./learning.ts";
@@ -586,4 +586,4 @@ export function falseSuccess(events, now) {
586
586
  : "The agent claimed it was done, but its last tool call failed and nothing succeeded after it.");
587
587
  return [];
588
588
  }
589
- export { growth, isoWeek, lessons, POWER_KINDS, promptChanged, SELF_CHANGE_KINDS, selfChanges, systemPromptHash, toolsHash, } from "./learning.js";
589
+ export { growth, isoWeek, lessons, POWER_KINDS, promptChanged, SELF_CHANGE_KINDS, selfChanges, successRange, systemPromptHash, toolsHash, } from "./learning.js";
@@ -86,6 +86,10 @@ export interface Growth {
86
86
  spend_per_run_micro_usd: number;
87
87
  human_steps: number;
88
88
  declared: boolean;
89
+ success_low_ppm: number;
90
+ success_high_ppm: number;
91
+ vs_previous: "better" | "worse" | "unclear" | null;
92
+ certificate: string | null;
89
93
  }>;
90
94
  versions_total: number;
91
95
  learned: Array<{
@@ -98,9 +102,15 @@ export interface Growth {
98
102
  corrected: number;
99
103
  unknown: number;
100
104
  checked: boolean;
105
+ certificate: string | null;
101
106
  }>;
102
107
  hints: string[];
103
108
  }
109
+ /**
110
+ * spec/fleet.md §9: the 95% Wilson interval of `s` successes in `n` runs, in ppm (low rounded down,
111
+ * high up). The same IEEE operations in the same order in both SDKs, so the digits agree.
112
+ */
113
+ export declare function successRange(s: number, n: number): [number, number];
104
114
  /**
105
115
  * spec/fleet.md §9: how one agent (its label) grows, from its closed sessions' summaries, newest
106
116
  * first. Autonomy per ISO week (a run done alone is a success with no human step, shown next to the
@@ -219,6 +219,24 @@ export function isoWeek(ts) {
219
219
  return `${year}-W${String(week).padStart(2, "0")}`;
220
220
  }
221
221
  const ppm = (n, d) => (d ? Math.floor((n * 1_000_000) / d) : 0);
222
+ /**
223
+ * spec/fleet.md §9: the 95% Wilson interval of `s` successes in `n` runs, in ppm (low rounded down,
224
+ * high up). The same IEEE operations in the same order in both SDKs, so the digits agree.
225
+ */
226
+ export function successRange(s, n) {
227
+ if (!n)
228
+ return [0, 1_000_000];
229
+ const z = 1.96;
230
+ const z2 = z * z;
231
+ const p = s / n;
232
+ const denom = 1 + z2 / n;
233
+ const centre = (p + z2 / (2 * n)) / denom;
234
+ const half = (z * Math.sqrt((p * (1 - p)) / n + z2 / (4 * n * n))) / denom;
235
+ return [
236
+ Math.max(0, Math.floor((centre - half) * 1_000_000)),
237
+ Math.min(1_000_000, Math.ceil((centre + half) * 1_000_000)),
238
+ ];
239
+ }
222
240
  const VERSIONS = 20;
223
241
  const LEARNED = 50;
224
242
  /**
@@ -269,6 +287,10 @@ export function growth(summaries, label, options = {}) {
269
287
  .map((ss) => {
270
288
  const v = ss[0]?.version;
271
289
  const starts = ss.map((s) => s.started_at).sort();
290
+ const wins = ss.filter((s) => s.outcome === "success").length;
291
+ const [low, high] = successRange(wins, ss.length);
292
+ // the newest run's certificate first: ss is newest first
293
+ const cert = ss.flatMap((s) => (s.self_changes ?? []).map((c) => c.certificate)).find(Boolean) ?? null;
272
294
  return {
273
295
  id: v.id,
274
296
  prompt: v.prompt,
@@ -278,16 +300,27 @@ export function growth(summaries, label, options = {}) {
278
300
  sessions: ss.length,
279
301
  first_seen: starts[0],
280
302
  last_seen: starts[starts.length - 1],
281
- success_ppm: ppm(ss.filter((s) => s.outcome === "success").length, ss.length),
303
+ success_ppm: ppm(wins, ss.length),
282
304
  spend_per_run_micro_usd: Math.floor(ss.reduce((n, s) => n + s.spend_micro_usd, 0) / ss.length),
283
305
  human_steps: ss.reduce((n, s) => n + (s.human_steps ?? 0), 0),
284
306
  declared: ss.some((s) => (s.self_changes?.length ?? 0) > 0),
307
+ success_low_ppm: low,
308
+ success_high_ppm: high,
309
+ vs_previous: null,
310
+ certificate: cert,
285
311
  };
286
312
  })
287
313
  .sort((a, b) => a.first_seen < b.first_seen ? -1 : a.first_seen > b.first_seen ? 1 : a.id < b.id ? -1 : 1);
288
314
  for (let i = 1; i < all.length; i++) {
289
315
  const [p, v] = [all[i - 1], all[i]];
290
316
  v.changed = ["prompt", "tools", "model"].filter((k) => p[k] !== v[k]);
317
+ // only a difference outside both ranges counts: two runs each tell nothing
318
+ v.vs_previous =
319
+ v.success_low_ppm > p.success_high_ppm
320
+ ? "better"
321
+ : v.success_high_ppm < p.success_low_ppm
322
+ ? "worse"
323
+ : "unclear";
291
324
  }
292
325
  const decided = new Map();
293
326
  for (const s of runs)
@@ -312,6 +345,7 @@ export function growth(summaries, label, options = {}) {
312
345
  corrected,
313
346
  unknown,
314
347
  checked: found.length > 0 && unknown === 0,
348
+ certificate: c.certificate ?? null,
315
349
  });
316
350
  }
317
351
  const hints = [];
@@ -53,9 +53,14 @@ export interface SelfChangeEntry {
53
53
  kind: string;
54
54
  approval_id: string | null;
55
55
  taught_by: string[];
56
+ /** A Zanii Evolve certificate's digest behind the change, when the agent names one */
57
+ certificate?: string;
56
58
  }
57
59
  /** An approval id: what a lesson may point at, and nothing else (spec/fleet.md §9). */
58
60
  export declare const APPROVAL_ID: RegExp;
61
+ /** spec/fleet.md §9: a Zanii Evolve certificate's digest (`sha256:` + 64 hex, or the 64 hex its
62
+ * certificate carries), as `sha256:<hex>`; null for anything else. */
63
+ export declare function certificateOf(v: unknown): string | null;
59
64
  /** spec/fleet.md §9: the approval ids a self-change names as what taught it, at most 20. */
60
65
  export declare function taughtBy(v: unknown): string[];
61
66
  export declare function sessionSummary(lines: readonly string[], bodies: Bodies, prices: LoadedPrices): Summary;
@@ -12,6 +12,14 @@ import { callsOf } from "../reconcile/record.js";
12
12
  import { canonical } from "../reconcile/shared.js";
13
13
  /** An approval id: what a lesson may point at, and nothing else (spec/fleet.md §9). */
14
14
  export const APPROVAL_ID = /^apr_[0-9a-f]{18}$/;
15
+ /** spec/fleet.md §9: a Zanii Evolve certificate's digest (`sha256:` + 64 hex, or the 64 hex its
16
+ * certificate carries), as `sha256:<hex>`; null for anything else. */
17
+ export function certificateOf(v) {
18
+ if (typeof v !== "string")
19
+ return null;
20
+ const m = /^(?:sha256:)?([0-9a-f]{64})$/.exec(v);
21
+ return m ? `sha256:${m[1]}` : null;
22
+ }
15
23
  /** spec/fleet.md §9: the approval ids a self-change names as what taught it, at most 20. */
16
24
  export function taughtBy(v) {
17
25
  if (!Array.isArray(v))
@@ -127,6 +135,9 @@ export function sessionSummary(lines, bodies, prices) {
127
135
  kind: typeof d.kind === "string" && d.kind ? d.kind : "other",
128
136
  approval_id: typeof d.approval_id === "string" ? d.approval_id : null,
129
137
  taught_by: taughtBy(d.taught_by),
138
+ ...(certificateOf(d.certificate)
139
+ ? { certificate: certificateOf(d.certificate) }
140
+ : {}),
130
141
  };
131
142
  });
132
143
  const version = versionOf(events);
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { A2A_STREAMING, type AgentCardReport, a2aMethod, a2aRequestMeta, a2aResp
2
2
  export { causality, memoryXray } from "./agents/index.ts";
3
3
  export { type DetectorOptions, detectors, fingerprint } from "./analysis/detectors.ts";
4
4
  export { FAULTS, type Fault, faultOf } from "./analysis/faults.ts";
5
- export { type Accuracy, type AnalyzeOptions, type AnswerClaims, analyze, answerClaims, answerCredential, answerRisk, answersOf, answerText, type ClaimEntry, type ClaimVerdict, type CriterionResult, canonicalNumber, checkAgainstPacks, checkFlightPlan, checkpointReplay, detectorAccuracy, dualWitness, Evidence, eventsOf, type Fact, type Finding as AnalysisFinding, factsIn, findingKey, type GroundedClaim, groundingFindings, groundingRequest, growth, HOLD_TRIGGERS, identifiersIn, isoWeek, judgeFindings, judgeRequest, type Label as AccuracyLabel, type Landing, landing, lessons, loadReferencePacks, modelGroundingFindings, normaliseValue, OUTCOMES, type Outcome, type OutcomeRollup, packsFor, parseGroundingAnswer, parseJudgeAnswer, promptChanged, type ReferenceFact, type ReferencePack, type ReferenceVerdict, referenceContext, rollup, type Severity, schemaProblem, secretSent, selfChanges, systemPromptHash, toolDrifted, toolHallucinations, toolsHash, userDownvotes, verifyAnswerCredential, type WasteReason, type WasteReport, waste, wilsonLow, } from "./analysis/index.ts";
5
+ export { type Accuracy, type AnalyzeOptions, type AnswerClaims, analyze, answerClaims, answerCredential, answerRisk, answersOf, answerText, type ClaimEntry, type ClaimVerdict, type CriterionResult, canonicalNumber, checkAgainstPacks, checkFlightPlan, checkpointReplay, detectorAccuracy, dualWitness, Evidence, eventsOf, type Fact, type Finding as AnalysisFinding, factsIn, findingKey, type GroundedClaim, groundingFindings, groundingRequest, growth, HOLD_TRIGGERS, identifiersIn, isoWeek, judgeFindings, judgeRequest, type Label as AccuracyLabel, type Landing, landing, lessons, loadReferencePacks, modelGroundingFindings, normaliseValue, OUTCOMES, type Outcome, type OutcomeRollup, packsFor, parseGroundingAnswer, parseJudgeAnswer, promptChanged, type ReferenceFact, type ReferencePack, type ReferenceVerdict, referenceContext, rollup, type Severity, schemaProblem, secretSent, selfChanges, successRange, systemPromptHash, toolDrifted, toolHallucinations, toolsHash, userDownvotes, verifyAnswerCredential, type WasteReason, type WasteReport, waste, wilsonLow, } from "./analysis/index.ts";
6
6
  export { injectionFindings, injectionRule } from "./analysis/injection.ts";
7
7
  export { MITRE_ATLAS, OWASP_ASI, TAXONOMY, type Taxonomy, taxonomyOf, } from "./analysis/taxonomy.ts";
8
8
  export { type ApprovalFinding, approvalConfirmation, approvalFindings, argsHash, verifyConfirmation, } from "./approvals/index.ts";
@@ -30,7 +30,7 @@ export { openSegments, type SealedSegment } from "./encryption/index.ts";
30
30
  export { type EvidencePack, type EvidencePackOptions, evidencePack, renderEvidencePack, } from "./evidence/index.ts";
31
31
  export { buildEquivocationProof, compareViews, cosignLedgerSth, verifyEquivocationProof, verifyLedgerCosignature, } from "./federation/index.ts";
32
32
  export { buildOwnerAttestation, buildPayment, CURRENCIES, FTA_WALL_ID, financeFindings, formatMoney, ftaPayload, parseMoney, paymentsOf, screenCounterparty, screeningPayload, verifyOwnerAttestation, verifyOwnerBinding, } from "./finance/index.ts";
33
- export { APPROVAL_ID, aggregateFindings, airworthiness, type Collision, collisions, didFromSeed, type FindingGroup, incidentReport, logbook, type Summary, sessionSummary, signatureOf, signatures, signCertificate, taughtBy, verifyCertificate, } from "./fleet/index.ts";
33
+ export { APPROVAL_ID, aggregateFindings, airworthiness, type Collision, certificateOf, collisions, didFromSeed, type FindingGroup, incidentReport, logbook, type Summary, sessionSummary, signatureOf, signatures, signCertificate, taughtBy, verifyCertificate, } from "./fleet/index.ts";
34
34
  export { copilotContext, copilotPrompt, type Insights, insights, parseCopilotAnswer, } from "./fleet/insights.ts";
35
35
  export { type AppealItem, type AppealPack, appealPack, decisionPayload, GOV_DECISION_KINDS, renderAppealPack, ruleConsistency, signSubjectClaim, subjectTag, verifyDecision, verifyFactors, verifySubjectClaim, } from "./gov/index.ts";
36
36
  export { accessPayload, breakGlass, checkEpisodeTag, clinicianConfirmation, type EpisodeItem, episodeSeed, episodesPack, episodeTag, healthFindings, protocolTrail, recommendationHash, recommendationPayload, verifyCommitment, verifyHealthSignature, } from "./health/index.ts";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export { A2A_STREAMING, a2aMethod, a2aRequestMeta, a2aResponseMeta, a2aRestMetho
4
4
  export { causality, memoryXray } from "./agents/index.js";
5
5
  export { detectors, fingerprint } from "./analysis/detectors.js";
6
6
  export { FAULTS, faultOf } from "./analysis/faults.js";
7
- export { analyze, answerClaims, answerCredential, answerRisk, answersOf, answerText, canonicalNumber, checkAgainstPacks, checkFlightPlan, checkpointReplay, detectorAccuracy, dualWitness, Evidence, eventsOf, factsIn, findingKey, groundingFindings, groundingRequest, growth, HOLD_TRIGGERS, identifiersIn, isoWeek, judgeFindings, judgeRequest, landing, lessons, loadReferencePacks, modelGroundingFindings, normaliseValue, OUTCOMES, packsFor, parseGroundingAnswer, parseJudgeAnswer, promptChanged, referenceContext, rollup, schemaProblem, secretSent, selfChanges, systemPromptHash, toolDrifted, toolHallucinations, toolsHash, userDownvotes, verifyAnswerCredential, waste, wilsonLow, } from "./analysis/index.js";
7
+ export { analyze, answerClaims, answerCredential, answerRisk, answersOf, answerText, canonicalNumber, checkAgainstPacks, checkFlightPlan, checkpointReplay, detectorAccuracy, dualWitness, Evidence, eventsOf, factsIn, findingKey, groundingFindings, groundingRequest, growth, HOLD_TRIGGERS, identifiersIn, isoWeek, judgeFindings, judgeRequest, landing, lessons, loadReferencePacks, modelGroundingFindings, normaliseValue, OUTCOMES, packsFor, parseGroundingAnswer, parseJudgeAnswer, promptChanged, referenceContext, rollup, schemaProblem, secretSent, selfChanges, successRange, systemPromptHash, toolDrifted, toolHallucinations, toolsHash, userDownvotes, verifyAnswerCredential, waste, wilsonLow, } from "./analysis/index.js";
8
8
  export { injectionFindings, injectionRule } from "./analysis/injection.js";
9
9
  export { MITRE_ATLAS, OWASP_ASI, TAXONOMY, taxonomyOf, } from "./analysis/taxonomy.js";
10
10
  export { approvalConfirmation, approvalFindings, argsHash, verifyConfirmation, } from "./approvals/index.js";
@@ -32,7 +32,7 @@ export { openSegments } from "./encryption/index.js";
32
32
  export { evidencePack, renderEvidencePack, } from "./evidence/index.js";
33
33
  export { buildEquivocationProof, compareViews, cosignLedgerSth, verifyEquivocationProof, verifyLedgerCosignature, } from "./federation/index.js";
34
34
  export { buildOwnerAttestation, buildPayment, CURRENCIES, FTA_WALL_ID, financeFindings, formatMoney, ftaPayload, parseMoney, paymentsOf, screenCounterparty, screeningPayload, verifyOwnerAttestation, verifyOwnerBinding, } from "./finance/index.js";
35
- export { APPROVAL_ID, aggregateFindings, airworthiness, collisions, didFromSeed, incidentReport, logbook, sessionSummary, signatureOf, signatures, signCertificate, taughtBy, verifyCertificate, } from "./fleet/index.js";
35
+ export { APPROVAL_ID, aggregateFindings, airworthiness, certificateOf, collisions, didFromSeed, incidentReport, logbook, sessionSummary, signatureOf, signatures, signCertificate, taughtBy, verifyCertificate, } from "./fleet/index.js";
36
36
  export { copilotContext, copilotPrompt, insights, parseCopilotAnswer, } from "./fleet/insights.js";
37
37
  export { appealPack, decisionPayload, GOV_DECISION_KINDS, renderAppealPack, ruleConsistency, signSubjectClaim, subjectTag, verifyDecision, verifyFactors, verifySubjectClaim, } from "./gov/index.js";
38
38
  export { accessPayload, breakGlass, checkEpisodeTag, clinicianConfirmation, episodeSeed, episodesPack, episodeTag, healthFindings, protocolTrail, recommendationHash, recommendationPayload, verifyCommitment, verifyHealthSignature, } from "./health/index.js";
@@ -390,6 +390,8 @@ export declare class BlackboxSession {
390
390
  approvalId?: string;
391
391
  /** The approvals (ids) that taught it this, and nothing else: never content (fleet.md §9). */
392
392
  taughtBy?: readonly string[];
393
+ /** A Zanii Evolve certificate's digest behind the change (spec/fleet.md §9). */
394
+ certificate?: string;
393
395
  }): void;
394
396
  /** spec/findings.md §13.1: what in an answer (the latest, or the one at `seq`) would hold it,
395
397
  * for an app that streams the answer by itself: `{seq, risks, hold}`. `hold` says whether the
@@ -10,7 +10,7 @@ import { SELF_CHANGE_KINDS } from "../analysis/learning.js";
10
10
  import { argsHash } from "../approvals/index.js";
11
11
  import { attest, isReadOnly, parseCommand } from "../attest/index.js";
12
12
  import { buildPayment, ftaPayload, screeningPayload, } from "../finance/index.js";
13
- import { taughtBy } from "../fleet/index.js";
13
+ import { certificateOf, taughtBy } from "../fleet/index.js";
14
14
  import { decisionPayload } from "../gov/index.js";
15
15
  import { accessPayload, checkEpisodeTag, recommendationPayload, verifyHealthSignature, } from "../health/index.js";
16
16
  import { memoryEntry } from "../memory/index.js";
@@ -635,6 +635,9 @@ export class BlackboxSession {
635
635
  ...(options.reason ? { reason: options.reason.slice(0, 500) } : {}),
636
636
  ...(options.approvalId ? { approval_id: options.approvalId.slice(0, 128) } : {}),
637
637
  ...(taught.length ? { taught_by: taught } : {}),
638
+ ...(certificateOf(options.certificate)
639
+ ? { certificate: certificateOf(options.certificate) }
640
+ : {}),
638
641
  });
639
642
  }
640
643
  /** spec/findings.md §13.1: what in an answer (the latest, or the one at `seq`) would hold it,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.21.0";
1
+ export declare const VERSION = "0.21.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The SDK version, on its own so the CLI can print it without loading the whole SDK.
2
- export const VERSION = "0.21.0";
2
+ export const VERSION = "0.21.1";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zanii/blackbox",
3
3
  "license": "Apache-2.0",
4
- "version": "0.21.0",
4
+ "version": "0.21.1",
5
5
  "description": "The flight recorder for AI agents: sessions, a zero-loss spool, framework hooks, approvals, and offline verification of the gateway's hash-chained record.",
6
6
  "keywords": [
7
7
  "ai-agents",