@zanii/blackbox 0.0.0-stage → 0.2.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 +202 -0
- package/README.md +109 -2
- package/dist/agents/index.d.ts +34 -0
- package/dist/agents/index.js +73 -0
- package/dist/analysis/detectors.d.ts +36 -0
- package/dist/analysis/detectors.js +339 -0
- package/dist/analysis/faults.d.ts +9 -0
- package/dist/analysis/faults.js +250 -0
- package/dist/analysis/index.d.ts +68 -0
- package/dist/analysis/index.js +388 -0
- package/dist/analysis/landing.d.ts +25 -0
- package/dist/analysis/landing.js +225 -0
- package/dist/analysis/memory.d.ts +13 -0
- package/dist/analysis/memory.js +33 -0
- package/dist/analysis/waste.d.ts +29 -0
- package/dist/analysis/waste.js +79 -0
- package/dist/approvals/index.d.ts +11 -0
- package/dist/approvals/index.js +27 -0
- package/dist/approvals/warnings.d.ts +2 -0
- package/dist/approvals/warnings.js +28 -0
- package/dist/attest/index.d.ts +17 -0
- package/dist/attest/index.js +106 -0
- package/dist/authority/index.d.ts +24 -0
- package/dist/authority/index.js +77 -0
- package/dist/billing/index.d.ts +99 -0
- package/dist/billing/index.js +174 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1057 -0
- package/dist/client/index.d.ts +146 -0
- package/dist/client/index.js +210 -0
- package/dist/compliance/index.d.ts +41 -0
- package/dist/compliance/index.js +96 -0
- package/dist/cost/index.d.ts +133 -0
- package/dist/cost/index.js +293 -0
- package/dist/data/index.d.ts +191 -0
- package/dist/data/index.js +762 -0
- package/dist/directives/index.d.ts +35 -0
- package/dist/directives/index.js +80 -0
- package/dist/drills/index.d.ts +43 -0
- package/dist/drills/index.js +101 -0
- package/dist/duty/index.d.ts +21 -0
- package/dist/duty/index.js +68 -0
- package/dist/fleet/index.d.ts +141 -0
- package/dist/fleet/index.js +454 -0
- package/dist/hooks/ai-sdk.d.ts +42 -0
- package/dist/hooks/ai-sdk.js +62 -0
- package/dist/hooks/claude-agent-sdk.d.ts +14 -0
- package/dist/hooks/claude-agent-sdk.js +70 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/langchain-agent.d.ts +69 -0
- package/dist/hooks/langchain-agent.js +163 -0
- package/dist/hooks/langchain.d.ts +41 -0
- package/dist/hooks/langchain.js +216 -0
- package/dist/hooks/langgraph-checkpoint.d.ts +12 -0
- package/dist/hooks/langgraph-checkpoint.js +73 -0
- package/dist/hooks/memory.d.ts +17 -0
- package/dist/hooks/memory.js +64 -0
- package/dist/hooks/openai-agents.d.ts +6 -0
- package/dist/hooks/openai-agents.js +40 -0
- package/dist/hooks/protect.d.ts +7 -0
- package/dist/hooks/protect.js +39 -0
- package/dist/hooks/providers.d.ts +16 -0
- package/dist/hooks/providers.js +149 -0
- package/dist/hooks/shared.d.ts +11 -0
- package/dist/hooks/shared.js +39 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +48 -0
- package/dist/investigate/index.d.ts +66 -0
- package/dist/investigate/index.js +119 -0
- package/dist/mcp-server/index.d.ts +85 -0
- package/dist/mcp-server/index.js +216 -0
- package/dist/mcp-wrap/index.d.ts +17 -0
- package/dist/mcp-wrap/index.js +170 -0
- package/dist/money/index.d.ts +114 -0
- package/dist/money/index.js +622 -0
- package/dist/occurrence/index.d.ts +108 -0
- package/dist/occurrence/index.js +168 -0
- package/dist/ocsf/index.d.ts +22 -0
- package/dist/ocsf/index.js +168 -0
- package/dist/otlp/index.d.ts +24 -0
- package/dist/otlp/index.js +143 -0
- package/dist/packs/index.d.ts +48 -0
- package/dist/packs/index.js +343 -0
- package/dist/policy/delta.d.ts +11 -0
- package/dist/policy/delta.js +39 -0
- package/dist/policy/drafts.d.ts +34 -0
- package/dist/policy/drafts.js +129 -0
- package/dist/policy/index.d.ts +47 -0
- package/dist/policy/index.js +154 -0
- package/dist/precog/index.d.ts +96 -0
- package/dist/precog/index.js +167 -0
- package/dist/precog/intervention.d.ts +22 -0
- package/dist/precog/intervention.js +44 -0
- package/dist/precog/normal.d.ts +31 -0
- package/dist/precog/normal.js +89 -0
- package/dist/preflight/index.d.ts +11 -0
- package/dist/preflight/index.js +19 -0
- package/dist/ratings/index.d.ts +21 -0
- package/dist/ratings/index.js +48 -0
- package/dist/reconcile/claude-code.d.ts +19 -0
- package/dist/reconcile/claude-code.js +220 -0
- package/dist/reconcile/codex.d.ts +5 -0
- package/dist/reconcile/codex.js +191 -0
- package/dist/reconcile/index.d.ts +19 -0
- package/dist/reconcile/index.js +50 -0
- package/dist/reconcile/record.d.ts +49 -0
- package/dist/reconcile/record.js +225 -0
- package/dist/reconcile/shared.d.ts +65 -0
- package/dist/reconcile/shared.js +113 -0
- package/dist/replay/index.d.ts +11 -0
- package/dist/replay/index.js +64 -0
- package/dist/replay/repair.d.ts +10 -0
- package/dist/replay/repair.js +62 -0
- package/dist/session/drain.d.ts +13 -0
- package/dist/session/drain.js +35 -0
- package/dist/session/index.d.ts +275 -0
- package/dist/session/index.js +681 -0
- package/dist/undo/index.d.ts +45 -0
- package/dist/undo/index.js +212 -0
- package/dist/verify/anchor.d.ts +54 -0
- package/dist/verify/anchor.js +77 -0
- package/dist/verify/chain.d.ts +27 -0
- package/dist/verify/chain.js +105 -0
- package/dist/verify/envelope.d.ts +28 -0
- package/dist/verify/envelope.js +55 -0
- package/dist/verify/index.d.ts +3 -0
- package/dist/verify/index.js +3 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/weather/index.d.ts +24 -0
- package/dist/weather/index.js +45 -0
- package/dist/workspace-receipt/index.d.ts +15 -0
- package/dist/workspace-receipt/index.js +121 -0
- package/package.json +56 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { type Attestation } from "../attest/index.ts";
|
|
2
|
+
export interface SessionOptions {
|
|
3
|
+
/** The gateway, e.g. http://127.0.0.1:8787 */
|
|
4
|
+
url: string;
|
|
5
|
+
/** An existing gateway session: its id and token… */
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
/** …or open a new one with the admin key. */
|
|
9
|
+
adminKey?: string;
|
|
10
|
+
/** Audit S25: the same as `adminKey`; a tenant's `bbxt_` key works too. */
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
mode?: "strict" | "available";
|
|
14
|
+
/** Audit S2: what else the gateway takes when it opens a session (spec/api.md). */
|
|
15
|
+
flightPlan?: FlightPlan;
|
|
16
|
+
/** Idea C4: rules that narrow this session (deny / require_approval); a child inherits them. */
|
|
17
|
+
policy?: {
|
|
18
|
+
rules: unknown[];
|
|
19
|
+
};
|
|
20
|
+
/** A decimal string, e.g. "2.50" (spec/control.md §2). */
|
|
21
|
+
budgetUsd?: string;
|
|
22
|
+
maxLlmCalls?: number;
|
|
23
|
+
/** spec/agents.md §2: the session that handed this one its work, and why. */
|
|
24
|
+
parent?: string;
|
|
25
|
+
handoff?: string;
|
|
26
|
+
/** spec/replay.md: replay (or fork) a recorded session. */
|
|
27
|
+
replay?: {
|
|
28
|
+
of: string;
|
|
29
|
+
fork?: boolean;
|
|
30
|
+
fork_after?: number;
|
|
31
|
+
};
|
|
32
|
+
/** The operator opens a session for a tenant (spec/tenancy.md). */
|
|
33
|
+
tenant?: string;
|
|
34
|
+
/** spec/authority.md: `supervised` from the start (risky actions wait for a second person). */
|
|
35
|
+
authority?: "agent" | "supervised";
|
|
36
|
+
/** spec/preflight.md: the equipment the run needs. A no-go returns a disabled session (and
|
|
37
|
+
* `stats.lastError` says why); optional items that are down show in `state().degraded`. */
|
|
38
|
+
preflight?: {
|
|
39
|
+
require?: string[];
|
|
40
|
+
optional?: string[];
|
|
41
|
+
};
|
|
42
|
+
/** Audit K12, spec/drills.md: failures the gateway injects on purpose, to test the agent. */
|
|
43
|
+
drill?: {
|
|
44
|
+
faults: Array<Record<string, unknown>>;
|
|
45
|
+
};
|
|
46
|
+
/** Default: $BLACKBOX_SPOOL_DIR, else <tmp>/zanii-blackbox-spool. */
|
|
47
|
+
spoolDir?: string;
|
|
48
|
+
flushMs?: number;
|
|
49
|
+
/** 0 turns the heartbeat off. */
|
|
50
|
+
heartbeatMs?: number;
|
|
51
|
+
closeTimeoutMs?: number;
|
|
52
|
+
/** Compact the spool once everything is acknowledged and this many bytes are behind (default 1 MB). */
|
|
53
|
+
compactBytes?: number;
|
|
54
|
+
logger?: (message: string) => void;
|
|
55
|
+
}
|
|
56
|
+
export interface SessionStats {
|
|
57
|
+
recorded: number;
|
|
58
|
+
acked: number;
|
|
59
|
+
errors: number;
|
|
60
|
+
dropped: number;
|
|
61
|
+
/** Audit S23: the latest failure, by kind, so an app can alert on the right thing. */
|
|
62
|
+
lastError?: SessionError;
|
|
63
|
+
}
|
|
64
|
+
export interface SessionError {
|
|
65
|
+
/** `network`: the gateway is unreachable · `rejected`: it answered with an error ·
|
|
66
|
+
* `disk`: the spool can't be written · `invalid`: an event was dropped as invalid. */
|
|
67
|
+
kind: "network" | "rejected" | "disk" | "invalid";
|
|
68
|
+
message: string;
|
|
69
|
+
at: string;
|
|
70
|
+
}
|
|
71
|
+
export interface FlightPlan {
|
|
72
|
+
objective: string;
|
|
73
|
+
expected_tools?: string[];
|
|
74
|
+
criteria?: unknown[];
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
/** Audit S17: what the gateway says about this session right now (GET /v1/sessions/:id/state). */
|
|
78
|
+
/** What `land()` found (spec/findings.md §5). */
|
|
79
|
+
export interface EgressCheck {
|
|
80
|
+
url: string;
|
|
81
|
+
/** The request got any answer: the agent can reach the internet around the gateway. */
|
|
82
|
+
open: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** spec/data.md §6: a direct HTTPS request to `url` (default https://example.com). Never throws. */
|
|
85
|
+
export declare function checkEgress(options?: {
|
|
86
|
+
url?: string;
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
}): Promise<EgressCheck>;
|
|
89
|
+
export interface LandingResult {
|
|
90
|
+
/** Only a `satisfied` verdict lands: `unverified` never counts as a pass. */
|
|
91
|
+
landed: boolean;
|
|
92
|
+
verdict: "satisfied" | "failed" | "unverified" | "error";
|
|
93
|
+
/** One line per criterion that didn't pass, to hand back to the model. */
|
|
94
|
+
feedback: string[];
|
|
95
|
+
/** How many more tries `maxAttempts` allows; at 0, stop and report. */
|
|
96
|
+
attemptsLeft: number;
|
|
97
|
+
}
|
|
98
|
+
export interface SessionState {
|
|
99
|
+
session_id: string;
|
|
100
|
+
closed: boolean;
|
|
101
|
+
events: number;
|
|
102
|
+
/** spec/authority.md: who is flying now. */
|
|
103
|
+
authority: "agent" | "supervised" | "human";
|
|
104
|
+
/** spec/preflight.md: optional equipment the session left without. */
|
|
105
|
+
degraded: string[];
|
|
106
|
+
control: {
|
|
107
|
+
state: "open" | "blocked";
|
|
108
|
+
blocked_by?: string;
|
|
109
|
+
};
|
|
110
|
+
findings: Array<{
|
|
111
|
+
code: string;
|
|
112
|
+
severity: string;
|
|
113
|
+
count: number;
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}>;
|
|
116
|
+
}
|
|
117
|
+
export interface LlmCallIds {
|
|
118
|
+
provider?: string;
|
|
119
|
+
request_id?: string;
|
|
120
|
+
message_id?: string;
|
|
121
|
+
/** An OpenAI Chat Completions id (`chatcmpl-…`); audit, also found. */
|
|
122
|
+
completion_id?: string;
|
|
123
|
+
response_id?: string;
|
|
124
|
+
model?: string;
|
|
125
|
+
}
|
|
126
|
+
/** N4 (idea R6): the same parts always give the same event id (sha256, 128 bits). */
|
|
127
|
+
export declare function stableEventId(...parts: readonly string[]): string;
|
|
128
|
+
/** Opens (or joins) a session. Never throws: on failure it returns a disabled session and logs why. */
|
|
129
|
+
export declare function session(options: SessionOptions): Promise<BlackboxSession>;
|
|
130
|
+
export declare class BlackboxSession {
|
|
131
|
+
readonly stats: SessionStats;
|
|
132
|
+
readonly enabled: boolean;
|
|
133
|
+
private readonly spool;
|
|
134
|
+
private readonly ackFile;
|
|
135
|
+
private nextSeq;
|
|
136
|
+
private ack;
|
|
137
|
+
/** The spool's size after our own last change; anything else means another process wrote. */
|
|
138
|
+
private knownSize;
|
|
139
|
+
private shipping;
|
|
140
|
+
private retryAt;
|
|
141
|
+
private backoff;
|
|
142
|
+
private timers;
|
|
143
|
+
private closed;
|
|
144
|
+
private landings;
|
|
145
|
+
/** A session that records nothing. `reason`, when opening failed, goes to `stats.lastError` (audit K1). */
|
|
146
|
+
static disabled(options: SessionOptions, reason?: string): BlackboxSession;
|
|
147
|
+
private readonly options;
|
|
148
|
+
readonly id: string;
|
|
149
|
+
readonly token: string;
|
|
150
|
+
constructor(options: SessionOptions, id: string, token: string, enabled?: boolean,
|
|
151
|
+
/** Audit K5: this SDK opened the session, so only it knows the token: keep it by the spool. */
|
|
152
|
+
keepToken?: boolean);
|
|
153
|
+
event(type: string, name?: string, data?: Record<string, unknown>, options?: {
|
|
154
|
+
eventId?: string;
|
|
155
|
+
}): void;
|
|
156
|
+
step(name: string, data?: Record<string, unknown>): void;
|
|
157
|
+
toolCall(name: string, args?: unknown): void;
|
|
158
|
+
toolResult(name: string, result?: {
|
|
159
|
+
ok?: boolean;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}): void;
|
|
162
|
+
/** spec/data.md §7: a subject's consent for a purpose. The subject is fingerprinted at capture,
|
|
163
|
+
* so it must be an identifier the deployment knows (an e-mail, an Emirates ID, a pack's own). */
|
|
164
|
+
consent(subject: string, purpose: string, granted: boolean): void;
|
|
165
|
+
/** spec/data.md §6: tries the internet directly, outside the gateway, and records the answer.
|
|
166
|
+
* `open: true` means the gateway isn't the only way out (EGRESS_OPEN). */
|
|
167
|
+
egressCheck(options?: {
|
|
168
|
+
url?: string;
|
|
169
|
+
timeoutMs?: number;
|
|
170
|
+
}): Promise<EgressCheck>;
|
|
171
|
+
llmCall(ids: LlmCallIds): void;
|
|
172
|
+
note(text: string): void;
|
|
173
|
+
/** Files the flight plan (spec/findings.md §5), unless one was filed when the session opened. */
|
|
174
|
+
flightPlan(plan: {
|
|
175
|
+
objective: string;
|
|
176
|
+
expected_tools?: string[];
|
|
177
|
+
criteria?: unknown[];
|
|
178
|
+
}): void;
|
|
179
|
+
/** A completion claim; the server judges it against the recorded tool calls. */
|
|
180
|
+
claim(summary: string, asserts?: unknown[]): void;
|
|
181
|
+
/** N2 (idea C10): claims it's done and reads the gateway's verdict, so a failed check goes back
|
|
182
|
+
* to the model as feedback, a bounded number of times. Never throws. */
|
|
183
|
+
land(summary: string, asserts?: unknown[], options?: {
|
|
184
|
+
maxAttempts?: number;
|
|
185
|
+
}): Promise<LandingResult>;
|
|
186
|
+
/** N4 (idea R8): the context the model sees changed (summarised, trimmed, a tool result moved
|
|
187
|
+
* aside), so a replay knows what the model saw. */
|
|
188
|
+
contextChange(change: {
|
|
189
|
+
kind: "summarized" | "trimmed" | "offloaded" | "edited";
|
|
190
|
+
before_tokens?: number;
|
|
191
|
+
after_tokens?: number;
|
|
192
|
+
cutoff_index?: number;
|
|
193
|
+
summary?: string;
|
|
194
|
+
file_path?: string;
|
|
195
|
+
}): void;
|
|
196
|
+
/** Stage 2 R3: the result of one of the customer's own checks (tests, a schema, a policy, a
|
|
197
|
+
* partial goal), mid-run or at the end. A pass then a fail is VERIFY_REGRESSION; a success whose last
|
|
198
|
+
* check failed is FALSE_SUCCESS (spec/findings.md §6). */
|
|
199
|
+
verify(check: string, ok: boolean, detail?: string): void;
|
|
200
|
+
/** N4 (idea R10): one more attempt at a model or tool call. */
|
|
201
|
+
retry(kind: "llm" | "tool", target: string, info: {
|
|
202
|
+
attempt: number;
|
|
203
|
+
error?: string;
|
|
204
|
+
delayMs?: number;
|
|
205
|
+
}): void;
|
|
206
|
+
/** N4 (idea R10): a call moved to another model or provider. */
|
|
207
|
+
fallback(from: string, to: string, reason?: string): void;
|
|
208
|
+
/** N4 (idea R5): how the run is configured: LangGraph's `durability` (sync, async, exit), retry,
|
|
209
|
+
* timeout and cache policies. */
|
|
210
|
+
runConfig(config: {
|
|
211
|
+
durability?: "sync" | "async" | "exit";
|
|
212
|
+
[key: string]: unknown;
|
|
213
|
+
}): void;
|
|
214
|
+
/** The agent reports something it almost got wrong (spec/fleet.md §3): a NEAR_MISS finding. */
|
|
215
|
+
nearMiss(description: string): void;
|
|
216
|
+
/** spec/attestation.md: re-runs a read-only command and records whether the output matches. */
|
|
217
|
+
attest(argv: string[], claimed: string, cwd?: string, claimedExit?: number): Attestation | undefined;
|
|
218
|
+
/** spec/agents.md §1: the agent's memory store wrote, revoked or returned memories. */
|
|
219
|
+
memoryWrite(memoryId: string, summary?: string): void;
|
|
220
|
+
memoryRevoke(memoryId: string, reason?: string): void;
|
|
221
|
+
memoryRead(memoryIds: string[], query?: string): void;
|
|
222
|
+
/** Ships what's pending now. Resolves true when everything recorded is acknowledged. With
|
|
223
|
+
* `timeoutMs` (audit S24) it keeps trying until then, and never waits longer. */
|
|
224
|
+
flush(options?: {
|
|
225
|
+
timeoutMs?: number;
|
|
226
|
+
}): Promise<boolean>;
|
|
227
|
+
/** Audit S17: the gateway's view of this session (blocked? findings?), or null if it can't be
|
|
228
|
+
* read. Lets an agent react to its own block before its next model call. Never throws. */
|
|
229
|
+
state(): Promise<SessionState | null>;
|
|
230
|
+
/** spec/approvals.md §2: asks a second person before running one of the agent's own risky tools,
|
|
231
|
+
* and waits (polling) for the answer. Never throws. Only `"approved"` means go ahead; anything
|
|
232
|
+
* else (`rejected`, `timeout`, or `error` when the gateway can't be asked) means don't. */
|
|
233
|
+
requestApproval(tool: string, options?: {
|
|
234
|
+
/** Audit K8: what the tool would be called with, so the approver sees what they approve. */
|
|
235
|
+
args?: Record<string, unknown>;
|
|
236
|
+
reason?: string;
|
|
237
|
+
timeoutMs?: number;
|
|
238
|
+
pollMs?: number;
|
|
239
|
+
}): Promise<"approved" | "rejected" | "timeout" | "error">;
|
|
240
|
+
/** N2 (idea C2): asks a person to let this session use a gateway tool its policy denies (the
|
|
241
|
+
* denial's `requires.tool`, e.g. `mcp__files__delete`). A yes is a standing grant for the
|
|
242
|
+
* session: retry the call. Answers like `requestApproval`. Never throws. */
|
|
243
|
+
requestPermission(tool: string, options?: {
|
|
244
|
+
reason?: string;
|
|
245
|
+
timeoutMs?: number;
|
|
246
|
+
pollMs?: number;
|
|
247
|
+
}): Promise<"approved" | "rejected" | "timeout" | "error">;
|
|
248
|
+
private ask;
|
|
249
|
+
/** Audit S8: `await using s = await session(…)` closes the session when the scope ends. */
|
|
250
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
251
|
+
/** Drains the spool (up to closeTimeoutMs), then closes the gateway session. Never throws.
|
|
252
|
+
* `outcome` labels the run for the waste ledger (spec/cost.md §5); `note` says why (audit S7).
|
|
253
|
+
* Audit K9: true only when the gateway closed it (or it was closed already); otherwise
|
|
254
|
+
* `stats.lastError` says why. */
|
|
255
|
+
close(outcome?: "success" | "failure" | "abandoned", note?: string): Promise<boolean>;
|
|
256
|
+
/** Stops shipping and heartbeats without closing the gateway session (for `drain`). */
|
|
257
|
+
stop(): void;
|
|
258
|
+
/** The kept token (K5) is no longer needed once everything is shipped and the session closed. */
|
|
259
|
+
private forgetToken;
|
|
260
|
+
private tick;
|
|
261
|
+
private ship;
|
|
262
|
+
/** L2.2.3: once everything is acknowledged and enough is behind, empty the spool. The ack is
|
|
263
|
+
* written first: a crash in between only resends acknowledged lines, which the server ignores. */
|
|
264
|
+
private compact;
|
|
265
|
+
/** Runs `fn` holding the session's spool lock (a lock file), after catching up with any other
|
|
266
|
+
* process's writes. A stale lock (a crashed holder) is broken after LOCK_STALE_MS. */
|
|
267
|
+
private withLock;
|
|
268
|
+
/** Catches up with the files if another process changed them since our own last change. */
|
|
269
|
+
private refresh;
|
|
270
|
+
private heartbeat;
|
|
271
|
+
private guard;
|
|
272
|
+
/** Records the latest failure (audit S23) and logs it. */
|
|
273
|
+
private fail;
|
|
274
|
+
private log;
|
|
275
|
+
}
|