@atbash/sdk 0.7.2-dev.0 → 0.8.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/README.md +19 -4
- package/dist/browser.d.mts +545 -79
- package/dist/browser.mjs +1817 -719
- package/dist/index.d.mts +545 -79
- package/dist/index.d.ts +545 -79
- package/dist/index.js +1191 -546
- package/dist/index.mjs +1168 -548
- package/index.d.ts +264 -14
- package/index.js +347 -104
- package/package.json +9 -5
- package/dist/browser.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -11,8 +11,34 @@ interface ValidatedEndpoint {
|
|
|
11
11
|
policy: "default" | "self-hosted";
|
|
12
12
|
verifyPubKey: string | null;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the trusted judge host set.
|
|
16
|
+
*
|
|
17
|
+
* The compiled-in default is always trusted: a `prod` build resolves it to
|
|
18
|
+
* atbash.ai, a dev build to whatever DEV_ENDPOINT was set at build time. No
|
|
19
|
+
* dev host is spelled out in source, and dev builds still validate their own
|
|
20
|
+
* default.
|
|
21
|
+
*
|
|
22
|
+
* Exported for tests only. The set is a build-time value and is deliberately
|
|
23
|
+
* never read from the process environment — an env var would let anyone widen
|
|
24
|
+
* the allowlist of an already-shipped artifact, which is the silent-redirection
|
|
25
|
+
* attack the allowlist exists to prevent (F-003). Asserting that requires
|
|
26
|
+
* calling this with the environment set, so it cannot stay module-private.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare function buildAllowedJudgeHosts(): ReadonlySet<string>;
|
|
14
31
|
declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
|
|
15
32
|
|
|
33
|
+
interface ChainConfig {
|
|
34
|
+
readonly network: Network;
|
|
35
|
+
readonly blockchainRid: string;
|
|
36
|
+
readonly nodeUrls: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
declare const PUBLIC_CHAIN: ChainConfig;
|
|
39
|
+
declare const PRIVATE_CHAIN: ChainConfig;
|
|
40
|
+
declare function chainForNetwork(network: Network): ChainConfig;
|
|
41
|
+
|
|
16
42
|
/**
|
|
17
43
|
* User-facing types. Two groups:
|
|
18
44
|
* - Core types — the exact shapes the Rust core emits across the NAPI
|
|
@@ -143,6 +169,11 @@ interface LogToolCallResult {
|
|
|
143
169
|
}
|
|
144
170
|
interface JudgeResult {
|
|
145
171
|
verdict: Verdict;
|
|
172
|
+
/**
|
|
173
|
+
* Canonical executable permission, computed by `canonicalAllow` — see that
|
|
174
|
+
* function for the rule. Never more permissive than `auditToolCall`.
|
|
175
|
+
*/
|
|
176
|
+
allow: boolean;
|
|
146
177
|
actionType: string;
|
|
147
178
|
reason: string;
|
|
148
179
|
confidence: number;
|
|
@@ -171,6 +202,8 @@ interface JudgeResult {
|
|
|
171
202
|
interface JudgmentStatus {
|
|
172
203
|
status: JudgmentState;
|
|
173
204
|
verdict: Verdict;
|
|
205
|
+
/** Same canonical executable permission as {@link JudgeResult.allow}. */
|
|
206
|
+
allow: boolean;
|
|
174
207
|
reason: string;
|
|
175
208
|
judgmentId: string;
|
|
176
209
|
onChain?: boolean;
|
|
@@ -257,6 +290,13 @@ interface AgentPolicy {
|
|
|
257
290
|
isCustom: boolean;
|
|
258
291
|
defaultPolicy: string;
|
|
259
292
|
}
|
|
293
|
+
/** Options for agent metadata and policy lookups. */
|
|
294
|
+
interface AgentLookupOptions {
|
|
295
|
+
/** Resolve the agent's network from this organization's active network. */
|
|
296
|
+
orgName?: string;
|
|
297
|
+
/** Explicit per-call chain override. `network` selects the dashboard chain. */
|
|
298
|
+
chainOpts?: ChainOpts;
|
|
299
|
+
}
|
|
260
300
|
/** Optional structured logger. */
|
|
261
301
|
interface AtbashLogger {
|
|
262
302
|
info?(...args: unknown[]): void;
|
|
@@ -266,7 +306,24 @@ interface AtbashLogger {
|
|
|
266
306
|
interface AtbashOptions {
|
|
267
307
|
endpoint?: string;
|
|
268
308
|
timeoutMs?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Full chain override — BRID + nodeUrls in one object. Wins over every
|
|
311
|
+
* other chain selector. Prefer this over paired `nodeUrls`/`blockchainRid`
|
|
312
|
+
* for anything but backwards compatibility.
|
|
313
|
+
*/
|
|
314
|
+
chain?: ChainConfig;
|
|
315
|
+
/**
|
|
316
|
+
* Preset chain selector — `"public"` or `"private"`. Resolves to the
|
|
317
|
+
* matching `ChainConfig` via `chainForNetwork()`. Overridden by `chain`,
|
|
318
|
+
* overrides env `ATBASH_DEFAULT_CHAIN_NETWORK` and the config file.
|
|
319
|
+
*/
|
|
320
|
+
network?: Network;
|
|
321
|
+
/**
|
|
322
|
+
* Explicit node URLs. Must be paired with `blockchainRid`. Passing one
|
|
323
|
+
* without the other throws — a BRID/nodes mismatch 404s every request.
|
|
324
|
+
*/
|
|
269
325
|
nodeUrls?: readonly string[];
|
|
326
|
+
/** Explicit BRID. Must be paired with `nodeUrls`. See {@link nodeUrls}. */
|
|
270
327
|
blockchainRid?: string;
|
|
271
328
|
/**
|
|
272
329
|
* Default org name. When set, `judgeAction` / `auditToolCall` resolve
|
|
@@ -281,8 +338,24 @@ interface AtbashOptions {
|
|
|
281
338
|
* per-call `verifyPubKey` still overrides it.
|
|
282
339
|
*/
|
|
283
340
|
verifyPubKey?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Org's encryption public key (33-byte compressed secp256k1, hex). When set,
|
|
343
|
+
* tool calls are sealed to it and signed as `log_encrypted_tool_call` instead
|
|
344
|
+
* of `log_tool_call`, so the action never reaches the block in clear.
|
|
345
|
+
*
|
|
346
|
+
* Required for any org that has registered a key — the contract refuses
|
|
347
|
+
* plaintext for those. Omitted, behaviour is unchanged. A per-call
|
|
348
|
+
* `orgEncryptionPubKey` overrides this, same as `verifyPubKey`.
|
|
349
|
+
*/
|
|
350
|
+
orgEncryptionPubKey?: string;
|
|
284
351
|
/** When true (default), `auditToolCall` denies on any error. */
|
|
285
352
|
failClosed?: boolean;
|
|
353
|
+
/**
|
|
354
|
+
* Verbose diagnostics. Off by default. When on, a failed judge call also
|
|
355
|
+
* logs the response body, which is the difference between "judge API failed"
|
|
356
|
+
* and knowing why it failed. Opt-in because that body can echo the action.
|
|
357
|
+
*/
|
|
358
|
+
debug?: boolean;
|
|
286
359
|
logger?: AtbashLogger;
|
|
287
360
|
}
|
|
288
361
|
/** Canonical decision returned by `auditToolCall`. */
|
|
@@ -317,12 +390,18 @@ interface FromConfigOptions {
|
|
|
317
390
|
keyPath?: string;
|
|
318
391
|
/** Judge endpoint config — validated against the allowlist / self-hosted policy. */
|
|
319
392
|
judge?: JudgeEndpointConfig;
|
|
393
|
+
/** See {@link AtbashOptions.chain}. */
|
|
394
|
+
chain?: ChainConfig;
|
|
395
|
+
/** See {@link AtbashOptions.network}. */
|
|
396
|
+
network?: Network;
|
|
320
397
|
blockchainRid?: string;
|
|
321
398
|
timeoutMs?: number;
|
|
322
399
|
nodeUrls?: readonly string[];
|
|
323
400
|
/** Default org name — see {@link AtbashOptions.orgName}. */
|
|
324
401
|
orgName?: string;
|
|
325
402
|
failClosed?: boolean;
|
|
403
|
+
/** See {@link AtbashOptions.debug}. */
|
|
404
|
+
debug?: boolean;
|
|
326
405
|
logger?: AtbashLogger;
|
|
327
406
|
}
|
|
328
407
|
/** Options accepted by `judgeAction`. */
|
|
@@ -332,6 +411,8 @@ interface JudgeOptions {
|
|
|
332
411
|
provider?: string;
|
|
333
412
|
model?: string;
|
|
334
413
|
verifyPubKey?: string;
|
|
414
|
+
/** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
|
|
415
|
+
orgEncryptionPubKey?: string;
|
|
335
416
|
/**
|
|
336
417
|
* Org name — when set, the SDK resolves which chain the agent lives
|
|
337
418
|
* on via the off-chain `org_networks` map (authoritative) before
|
|
@@ -360,12 +441,8 @@ interface LogToolCallOptions {
|
|
|
360
441
|
toolArgsJson?: string;
|
|
361
442
|
/** Per-call chain override — same semantics as `JudgeOptions.chainOpts`. */
|
|
362
443
|
chainOpts?: ChainOpts;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
interface ChainConfig {
|
|
366
|
-
readonly network: Network;
|
|
367
|
-
readonly blockchainRid: string;
|
|
368
|
-
readonly nodeUrls: readonly string[];
|
|
444
|
+
/** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
|
|
445
|
+
orgEncryptionPubKey?: string;
|
|
369
446
|
}
|
|
370
447
|
|
|
371
448
|
declare class Atbash {
|
|
@@ -377,8 +454,13 @@ declare class Atbash {
|
|
|
377
454
|
readonly orgName?: string;
|
|
378
455
|
/** Default judge response-signing pubkey, if configured (see fromConfig). */
|
|
379
456
|
readonly verifyPubKey?: string;
|
|
457
|
+
/** Default org encryption key — see {@link AtbashOptions.orgEncryptionPubKey}. */
|
|
458
|
+
readonly orgEncryptionPubKey?: string;
|
|
380
459
|
/** When true (default), `auditToolCall` denies on any error. */
|
|
381
460
|
readonly failClosed: boolean;
|
|
461
|
+
/** Org key learned from the last agent-exists check, for this agent only. */
|
|
462
|
+
private _orgKeyFromChain;
|
|
463
|
+
private readonly debug;
|
|
382
464
|
private readonly logger;
|
|
383
465
|
private readonly http;
|
|
384
466
|
/**
|
|
@@ -386,13 +468,57 @@ declare class Atbash {
|
|
|
386
468
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
387
469
|
*/
|
|
388
470
|
private readonly _chainCache;
|
|
471
|
+
/**
|
|
472
|
+
* The chain the constructor settled on. Used only where a lookup returns no
|
|
473
|
+
* answer — see {@link resolveChainFromMap}.
|
|
474
|
+
*/
|
|
475
|
+
private readonly _defaultChain;
|
|
476
|
+
/**
|
|
477
|
+
* True when the caller named a chain outright — `chain`, `network`, or the
|
|
478
|
+
* paired `blockchainRid` + `nodeUrls`.
|
|
479
|
+
*
|
|
480
|
+
* Such a client is never re-pointed: not by the migration switch, and not by
|
|
481
|
+
* where an org turns out to live. Naming a chain is the caller saying "talk
|
|
482
|
+
* to this one", and silently routing elsewhere would make the argument a
|
|
483
|
+
* suggestion. A client that names nothing is the one that follows the org.
|
|
484
|
+
*/
|
|
485
|
+
private readonly _explicitChain;
|
|
486
|
+
/**
|
|
487
|
+
* The fleet-wide chain switch, read once at construction. `resolve()` hits
|
|
488
|
+
* the config file on disk, so re-reading it per call would put a file read
|
|
489
|
+
* on every judge.
|
|
490
|
+
*/
|
|
491
|
+
private readonly _forcedNetwork;
|
|
492
|
+
/**
|
|
493
|
+
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
494
|
+
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
495
|
+
* data that hasn't changed. The `org_encryption_pubkey` field CAN change
|
|
496
|
+
* — an org toggling encryption mid-session — so the TTL is deliberately
|
|
497
|
+
* short (see `AGENT_EXISTS_TTL_MS`). Keyed by (pubkey, network) so
|
|
498
|
+
* cross-agent / cross-network calls don't collide.
|
|
499
|
+
*/
|
|
500
|
+
private _agentExistsCache;
|
|
501
|
+
private static readonly AGENT_EXISTS_TTL_MS;
|
|
389
502
|
/**
|
|
390
503
|
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
391
504
|
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
392
505
|
* server-side replay protection windows never expire it mid-session.
|
|
393
506
|
*/
|
|
394
|
-
private
|
|
507
|
+
private _authBearers;
|
|
508
|
+
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
509
|
+
private static environmentLogged;
|
|
395
510
|
constructor(privkey: string, options?: AtbashOptions);
|
|
511
|
+
/**
|
|
512
|
+
* Say which environment this build talks to, once per process.
|
|
513
|
+
*
|
|
514
|
+
* The endpoint and both chain RIDs are compiled in, chosen by the npm tag,
|
|
515
|
+
* and no configuration repoints a released build. So installing the build
|
|
516
|
+
* for the wrong environment is invisible: the plugin loads, the hook fires,
|
|
517
|
+
* and every judge call fails because the agent does not exist on the chain
|
|
518
|
+
* this build targets. Organisation names are not unique across environments
|
|
519
|
+
* either, so an org resolving is not evidence the build is right.
|
|
520
|
+
*/
|
|
521
|
+
private logEnvironmentOnce;
|
|
396
522
|
/**
|
|
397
523
|
* Construct from resolved config: explicit overrides → env vars → the
|
|
398
524
|
* `~/.config/atbash/config.json` file (see userConfig.resolve). The private
|
|
@@ -435,8 +561,27 @@ declare class Atbash {
|
|
|
435
561
|
* explicitly false.
|
|
436
562
|
*/
|
|
437
563
|
auditToolCall(input: ToolCallInput): Promise<Decision>;
|
|
564
|
+
/**
|
|
565
|
+
* One exit for every judge failure.
|
|
566
|
+
*
|
|
567
|
+
* Status and reason go in the *message*, not only in the meta object: hosts
|
|
568
|
+
* print the message and drop the meta, which is why this read as a bare
|
|
569
|
+
* "judge API failed" while the judge was answering with a precise reason.
|
|
570
|
+
* The response body follows only under `debug`, since it can echo the action.
|
|
571
|
+
*/
|
|
572
|
+
private failJudge;
|
|
438
573
|
private fail;
|
|
439
|
-
|
|
574
|
+
/**
|
|
575
|
+
* Return the current status of a previously submitted judgment.
|
|
576
|
+
*
|
|
577
|
+
* `chainOpts` names which chain the judgment was signed against. The
|
|
578
|
+
* server's GET /api/v1/judge routes to that chain when the SDK sends
|
|
579
|
+
* a `brid` query param; without it, the server falls back to public.
|
|
580
|
+
* Callers on the private chain must pass a `chainOpts` (or configure
|
|
581
|
+
* the client on the private chain) — otherwise polling a POSTed
|
|
582
|
+
* judgment on the private chain 404s at the server.
|
|
583
|
+
*/
|
|
584
|
+
getJudgmentStatus(judgmentId: string, agentPubkey?: string, chainOpts?: ChainOpts): Promise<JudgmentStatus>;
|
|
440
585
|
getToolCalls(maxCount: number): Promise<ToolCallRecord[]>;
|
|
441
586
|
getOrgToolCalls(orgName: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
442
587
|
getAgentToolCalls(agentPubkey: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
@@ -445,8 +590,8 @@ declare class Atbash {
|
|
|
445
590
|
getOrgTierInfo(orgName: string): Promise<TierInfo | null>;
|
|
446
591
|
getPendingHeldActions(orgName: string, maxCount: number): Promise<HeldAction[]>;
|
|
447
592
|
getHeldActionReviews(orgName: string, maxCount: number): Promise<HeldActionReview[]>;
|
|
448
|
-
getAgentDetail(agentPubkey: string): Promise<Record<string, unknown>>;
|
|
449
|
-
getAgentPolicy(agentPubkey: string): Promise<AgentPolicy>;
|
|
593
|
+
getAgentDetail(agentPubkey: string, options?: AgentLookupOptions): Promise<Record<string, unknown>>;
|
|
594
|
+
getAgentPolicy(agentPubkey: string, options?: AgentLookupOptions): Promise<AgentPolicy>;
|
|
450
595
|
getSafetyStats(): Promise<Record<string, unknown>>;
|
|
451
596
|
/**
|
|
452
597
|
* Org's subscription on a specific chain. The `network` arg selects
|
|
@@ -469,7 +614,9 @@ declare class Atbash {
|
|
|
469
614
|
* 2. Per-chain subscription fallback — public + private records
|
|
470
615
|
* are fetched in parallel, with `is_private_blockchain` and
|
|
471
616
|
* `assigned_at` reconciling mixed states.
|
|
472
|
-
*
|
|
617
|
+
* A lookup that names exactly one chain wins outright. Where it names
|
|
618
|
+
* neither (a brand-new org) or cannot choose between them, the client's
|
|
619
|
+
* configured default decides.
|
|
473
620
|
*/
|
|
474
621
|
resolveChainForOrg(orgName: string): Promise<ChainConfig>;
|
|
475
622
|
/**
|
|
@@ -481,6 +628,8 @@ declare class Atbash {
|
|
|
481
628
|
private resolveChainFromMap;
|
|
482
629
|
/** Drop any cached chain resolutions. Useful in tests. */
|
|
483
630
|
clearChainCache(): void;
|
|
631
|
+
/** Drop the short-TTL `/api/ai/exists` cache. Useful in tests. */
|
|
632
|
+
clearAgentExistsCache(): void;
|
|
484
633
|
/**
|
|
485
634
|
* Wrap an SDK method body in telemetry — records the call at start
|
|
486
635
|
* and a success/error duration at end. Re-throws on failure so the
|
|
@@ -495,6 +644,14 @@ declare class Atbash {
|
|
|
495
644
|
* chains; otherwise the client's default.
|
|
496
645
|
*/
|
|
497
646
|
private bridFromChainOpts;
|
|
647
|
+
/**
|
|
648
|
+
* Resolve the dashboard chain used by agent metadata/policy reads.
|
|
649
|
+
* Explicit per-call network overrides win; otherwise use the supplied org
|
|
650
|
+
* or the client's configured default org. A custom BRID is intentionally
|
|
651
|
+
* left untouched because it cannot be represented by the dashboard's
|
|
652
|
+
* public/private query selector.
|
|
653
|
+
*/
|
|
654
|
+
private resolveAgentLookupNetwork;
|
|
498
655
|
/**
|
|
499
656
|
* Get-or-create a Bearer token for dashboard reads. The token is a
|
|
500
657
|
* signed `log_tool_call` op (locally signed, never submitted) — the
|
|
@@ -507,10 +664,46 @@ declare class Atbash {
|
|
|
507
664
|
private riskEngineGet;
|
|
508
665
|
private riskEnginePost;
|
|
509
666
|
private riskEngineRecords;
|
|
667
|
+
/**
|
|
668
|
+
* BRID for an org — one round-trip to the map, honoring the client's chain
|
|
669
|
+
* cache. A "brand-new org" (nothing anywhere names its chain) is not an
|
|
670
|
+
* error — `resolveChainForOrg` returns the client default for that case and
|
|
671
|
+
* this helper returns its BRID. A transport failure or non-200 from
|
|
672
|
+
* `/api/org-network` IS an error and propagates: the caller cannot fall
|
|
673
|
+
* back to the default chain on outage, because with multi-chain live that
|
|
674
|
+
* silently reads from the wrong chain. Matches the Python binding's
|
|
675
|
+
* `_brid_for_org` semantics.
|
|
676
|
+
*/
|
|
677
|
+
private bridForOrg;
|
|
678
|
+
/**
|
|
679
|
+
* BRID for the client's configured default org, if it has one.
|
|
680
|
+
*
|
|
681
|
+
* Calls that carry no `orgName` argument are not chain-less: they still
|
|
682
|
+
* belong to `this.orgName`, and that org lives on exactly one chain. Routing
|
|
683
|
+
* them by the constructor's chain instead means a client configured
|
|
684
|
+
* `network: "private"` reads the private chain for an org that lives on
|
|
685
|
+
* public, and gets an empty answer rather than an error. So where an org is
|
|
686
|
+
* known the org decides the chain, and the constructor's chain is what is
|
|
687
|
+
* left when no org is known at all — the order `resolveAgentLookupNetwork`
|
|
688
|
+
* already applies to agent metadata reads, and the order the dashboard
|
|
689
|
+
* applies in `resolveChainForWallet`.
|
|
690
|
+
*
|
|
691
|
+
* Undefined when there is no default org, so callers keep falling back to
|
|
692
|
+
* the client default.
|
|
693
|
+
*/
|
|
694
|
+
/** The switch's chain, unless this client named one of its own. */
|
|
695
|
+
private forcedNetwork;
|
|
696
|
+
private defaultOrgBrid;
|
|
510
697
|
private raiseIfError;
|
|
511
698
|
/** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
|
|
512
699
|
private httpError;
|
|
513
|
-
/**
|
|
700
|
+
/**
|
|
701
|
+
* Wrap a transport failure (fetch threw, no response) as an AtbashAPIError.
|
|
702
|
+
*
|
|
703
|
+
* `HttpTransportError.kind` names the cause; the message is already
|
|
704
|
+
* human-readable. `debug` echoes the original exception so operators can
|
|
705
|
+
* cross-reference with node / undici logs when a class doesn't match.
|
|
706
|
+
*/
|
|
514
707
|
private transportError;
|
|
515
708
|
private json;
|
|
516
709
|
static generateKeypair(): KeyPair;
|
|
@@ -536,9 +729,62 @@ declare class SignatureVerificationError extends Error {
|
|
|
536
729
|
constructor(message: string);
|
|
537
730
|
}
|
|
538
731
|
|
|
732
|
+
/**
|
|
733
|
+
* Thin typed fetch wrapper.
|
|
734
|
+
*
|
|
735
|
+
* openapi-typescript emits types only (no runtime client), so this is the
|
|
736
|
+
* single hand-written transport — generic `get`/`post` over global `fetch`
|
|
737
|
+
* with a per-request timeout. The endpoint-specific request/response *shapes*
|
|
738
|
+
* are pulled from the generated `schema.ts` at the call sites in client.ts, so
|
|
739
|
+
* the wire contract still lives in spec/openapi.yaml. Methods return the raw
|
|
740
|
+
* `Response` so the caller can read the exact bytes the server signed before
|
|
741
|
+
* any decode (judge signature verification) — mirroring the Python surface's
|
|
742
|
+
* use of raw httpx (DECISIONS 2026-05-22).
|
|
743
|
+
*/
|
|
744
|
+
type QueryValue = string | number | boolean | undefined | null;
|
|
745
|
+
declare class HttpClient {
|
|
746
|
+
readonly baseUrl: string;
|
|
747
|
+
readonly timeoutMs: number;
|
|
748
|
+
constructor(baseUrl: string, timeoutMs: number);
|
|
749
|
+
buildUrl(path: string, query?: Record<string, QueryValue>): string;
|
|
750
|
+
get(path: string, query?: Record<string, QueryValue>, headers?: Record<string, string>): Promise<Response>;
|
|
751
|
+
post(path: string, body: unknown, headers?: Record<string, string>): Promise<Response>;
|
|
752
|
+
private fetch;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* A transport failure the SDK can act on. Every real cause the platform surfaces
|
|
756
|
+
* lands as one of these — the message names the cause in plain language so a
|
|
757
|
+
* plugin can show it to a user without decoding httpx / fetch internals.
|
|
758
|
+
*
|
|
759
|
+
* `cause` preserves the original error for debug logging; consumers that want
|
|
760
|
+
* the raw exception (e.g. tests) read it there.
|
|
761
|
+
*/
|
|
762
|
+
declare class HttpTransportError extends Error {
|
|
763
|
+
readonly kind: "timeout" | "aborted" | "dns" | "connect_refused" | "connection_reset" | "unknown";
|
|
764
|
+
constructor(kind: HttpTransportError["kind"], message: string, options?: {
|
|
765
|
+
cause?: unknown;
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
declare function canonicalAllow(data: Record<string, unknown>): boolean;
|
|
770
|
+
|
|
539
771
|
/** Normalize wire shapes (verdict casing, status, pubkey) to canonical forms. */
|
|
540
772
|
|
|
541
773
|
declare function normalizeVerdict(raw: unknown): Verdict;
|
|
774
|
+
/**
|
|
775
|
+
* Canonicalize `action_type` at the wire boundary, the way
|
|
776
|
+
* {@link normalizeVerdict} already canonicalizes `verdict`.
|
|
777
|
+
*
|
|
778
|
+
* `verdict` has been normalized here since the beginning and has never
|
|
779
|
+
* drifted between consumers. `action_type` was passed through raw, so every
|
|
780
|
+
* reader invented its own folding policy — `auditToolCall` compared exactly
|
|
781
|
+
* while `memory/scan.ts` trimmed and case-folded, and the same `" ALLOW "`
|
|
782
|
+
* was therefore an error on one path and permission on the other.
|
|
783
|
+
*
|
|
784
|
+
* Trim and case-fold only. Zero-width and homoglyph variants survive
|
|
785
|
+
* untouched, stay outside the known set, and still fail closed.
|
|
786
|
+
*/
|
|
787
|
+
declare function normalizeActionType(raw: unknown): string;
|
|
542
788
|
declare function normalizeStatus(raw: unknown): JudgmentState;
|
|
543
789
|
/** Wire pubkey may be a hex string, a Buffer/Uint8Array, or `{ data: [...] }`. */
|
|
544
790
|
declare function pubkeyToHex(val: unknown): string;
|
|
@@ -547,9 +793,24 @@ interface AtbashUserConfig {
|
|
|
547
793
|
agentKey?: string;
|
|
548
794
|
orgName?: string;
|
|
549
795
|
judgeEndpoint?: string;
|
|
550
|
-
|
|
796
|
+
/**
|
|
797
|
+
* Response-signing pubkey of a self-hosted judge (66 hex). Setting it makes
|
|
798
|
+
* `fromConfig` use the self-hosted policy for `judgeEndpoint`, which is the
|
|
799
|
+
* only way a non-allowlisted judge host is accepted.
|
|
800
|
+
*/
|
|
801
|
+
judgeVerifyPubKey?: string;
|
|
802
|
+
/**
|
|
803
|
+
* `"private"` pins every org to the private chain regardless of where the
|
|
804
|
+
* dashboard says it lives — the migration switch. Leave it unset for the
|
|
805
|
+
* normal mode, where each org's own chain decides. There is no `"public"`
|
|
806
|
+
* value; a caller that wants one specific chain passes `chain` or `network`
|
|
807
|
+
* at construction instead.
|
|
808
|
+
*/
|
|
809
|
+
defaultChainNetwork?: Network;
|
|
551
810
|
provider?: string;
|
|
552
811
|
providerModel?: string;
|
|
812
|
+
/** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
|
|
813
|
+
debug?: string;
|
|
553
814
|
}
|
|
554
815
|
declare function getConfigDir(): string;
|
|
555
816
|
declare function getConfigPath(): string;
|
|
@@ -560,6 +821,26 @@ declare function resolve(key: keyof AtbashUserConfig, flagValue?: string): strin
|
|
|
560
821
|
declare function resolveKeyPath(input?: string): string;
|
|
561
822
|
declare function loadAgentFromFile(keyPath?: string): AgentAuth;
|
|
562
823
|
|
|
824
|
+
/**
|
|
825
|
+
* Accepted key filenames, in precedence order.
|
|
826
|
+
*
|
|
827
|
+
* `guard-client-key` stays first: it is the name every existing install
|
|
828
|
+
* already has, and changing which file wins would silently switch agent
|
|
829
|
+
* identity for anyone holding both. `atbash-client-key` is accepted because
|
|
830
|
+
* it is the name people actually create — the old one carries retired
|
|
831
|
+
* branding — and hitting ENOENT on a key you just wrote, from a plugin that
|
|
832
|
+
* still reports itself installed, is a miserable first run.
|
|
833
|
+
*/
|
|
834
|
+
declare const KEY_FILENAMES: readonly ["guard-client-key", "atbash-client-key"];
|
|
835
|
+
/** Every path checked when no explicit key path is given, in order. */
|
|
836
|
+
declare function keyPathCandidates(): string[];
|
|
837
|
+
/**
|
|
838
|
+
* Pick the key path: an explicit input wins untouched; otherwise the first
|
|
839
|
+
* accepted filename that exists, falling back to the preferred name so the
|
|
840
|
+
* error names something recognisable when nothing is there.
|
|
841
|
+
*/
|
|
842
|
+
declare function chooseKeyPath(input: string | undefined, exists: (p: string) => boolean): string;
|
|
843
|
+
|
|
563
844
|
/**
|
|
564
845
|
* Canonical secret kinds reported by the Rust core in `SecretMatch.kind`.
|
|
565
846
|
* Wire is permissive (modelled as a free string in {@link SecretMatch})
|
|
@@ -578,6 +859,26 @@ declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHe
|
|
|
578
859
|
reason?: string;
|
|
579
860
|
};
|
|
580
861
|
|
|
862
|
+
/**
|
|
863
|
+
* The boot memory-sync failure line.
|
|
864
|
+
*
|
|
865
|
+
* Split out of `guard-manager.ts` so it can be asserted without constructing a
|
|
866
|
+
* guard manager, which needs the native addon. The message is the whole point
|
|
867
|
+
* of AT-304: hosts print the message and drop the structured meta, so a cause
|
|
868
|
+
* that lives only in meta never reaches the operator.
|
|
869
|
+
*/
|
|
870
|
+
/** Advice, not a diagnosis — appended only when the cause is unhelpful. */
|
|
871
|
+
declare const BOOT_SYNC_HINT = "check the chain endpoint and orgName if the cause above does not explain it";
|
|
872
|
+
/**
|
|
873
|
+
* Lead with the real cause.
|
|
874
|
+
*
|
|
875
|
+
* The previous wording named the chain endpoint and orgName as the things to
|
|
876
|
+
* check, which sent operators to verify configuration that was already correct
|
|
877
|
+
* while the actual cause (a node answering `404 Can't find blockchain with
|
|
878
|
+
* blockchainRID: …` for a chain it does not host) stayed hidden.
|
|
879
|
+
*/
|
|
880
|
+
declare function bootSyncFailureLine(cause: unknown): string;
|
|
881
|
+
|
|
581
882
|
/** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
|
|
582
883
|
declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
|
|
583
884
|
/** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
|
|
@@ -592,8 +893,8 @@ declare function decryptMemoryContent(ciphertext: Buffer, nonce: Buffer, key: Bu
|
|
|
592
893
|
* Scan a single memory entry for poisoning.
|
|
593
894
|
*
|
|
594
895
|
* `auth` is the agent that signs the on-chain audit log for the
|
|
595
|
-
* LLM-judge call.
|
|
596
|
-
*
|
|
896
|
+
* LLM-judge call. Unicode-evasion presence is surfaced to the prompt
|
|
897
|
+
* so the LLM can weight suspicion accordingly.
|
|
597
898
|
*/
|
|
598
899
|
declare function scanMemory(entry: MemoryEntry, auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult>;
|
|
599
900
|
/**
|
|
@@ -607,15 +908,26 @@ declare function scanMemoryBatch(entries: MemoryEntry[], auth: AgentAuth, opts?:
|
|
|
607
908
|
interface CommitMemoryOptions {
|
|
608
909
|
/** Score in [1, 10]. Defaults to 5 (matches the Rell entity default). */
|
|
609
910
|
score?: number;
|
|
911
|
+
/**
|
|
912
|
+
* Which memory file this commit targets. Defaults to `""` — the
|
|
913
|
+
* un-pathed slot, matching Rell's `file_path: text = ""` default.
|
|
914
|
+
* Pass an explicit filename (e.g. `"AGENTS.md"`) to keep files
|
|
915
|
+
* versioned independently on chain.
|
|
916
|
+
*/
|
|
917
|
+
filePath?: string;
|
|
610
918
|
/** Org name — when set, the SDK resolves which chain the agent lives on. */
|
|
611
919
|
orgName?: string;
|
|
612
920
|
/** Atbash service endpoint for org→chain lookup. */
|
|
613
921
|
endpoint?: string;
|
|
922
|
+
/** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
|
|
923
|
+
verifyPubKey?: string;
|
|
614
924
|
chainOpts?: ChainOpts;
|
|
615
925
|
}
|
|
616
926
|
interface RollbackMemoryOptions {
|
|
617
927
|
orgName?: string;
|
|
618
928
|
endpoint?: string;
|
|
929
|
+
/** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
|
|
930
|
+
verifyPubKey?: string;
|
|
619
931
|
chainOpts?: ChainOpts;
|
|
620
932
|
}
|
|
621
933
|
/**
|
|
@@ -624,9 +936,7 @@ interface RollbackMemoryOptions {
|
|
|
624
936
|
* deactivated on-chain.
|
|
625
937
|
*
|
|
626
938
|
* The caller is responsible for running `scanMemory` first when
|
|
627
|
-
* appropriate — this function does not gate on the verdict.
|
|
628
|
-
* `score` parameter is the only metadata that flows in alongside
|
|
629
|
-
* the ciphertext.
|
|
939
|
+
* appropriate — this function does not gate on the verdict.
|
|
630
940
|
*/
|
|
631
941
|
declare function commitMemoryVersion(plaintext: string, auth: AgentAuth, opts?: CommitMemoryOptions): Promise<void>;
|
|
632
942
|
/**
|
|
@@ -639,6 +949,7 @@ declare function commitMemoryVersion(plaintext: string, auth: AgentAuth, opts?:
|
|
|
639
949
|
*/
|
|
640
950
|
interface AgentMemoryEntry {
|
|
641
951
|
id: number;
|
|
952
|
+
filePath: string;
|
|
642
953
|
content: string;
|
|
643
954
|
decryptError?: string;
|
|
644
955
|
score: number;
|
|
@@ -650,6 +961,7 @@ interface AgentMemoryEntry {
|
|
|
650
961
|
interface MemoryRollbackEvent {
|
|
651
962
|
fromId: number;
|
|
652
963
|
toId: number;
|
|
964
|
+
filePath: string;
|
|
653
965
|
reason: string;
|
|
654
966
|
signer: string;
|
|
655
967
|
createdAt: number;
|
|
@@ -658,71 +970,53 @@ interface MemoryRollbackEvent {
|
|
|
658
970
|
* Cheap version-pointer probe. Returns just the id of the current
|
|
659
971
|
* active memory (or null if none). No ciphertext is transferred — the
|
|
660
972
|
* response is a single integer, so this is safe to call on every
|
|
661
|
-
* memory-read hot path.
|
|
662
|
-
* compare against a stored pointer and only refetch the full row via
|
|
663
|
-
* `getActiveMemory` when the id has changed.
|
|
973
|
+
* memory-read hot path.
|
|
664
974
|
*/
|
|
665
|
-
declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts): Promise<number | null>;
|
|
975
|
+
declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<number | null>;
|
|
666
976
|
/**
|
|
667
977
|
* Recent active memory entries — subset of active versions filtered
|
|
668
|
-
* by the chain's `MEMORY_RECENT_WINDOW_MS
|
|
669
|
-
*
|
|
670
|
-
* stale memory is worse than missing memory. For a time-unbounded
|
|
671
|
-
* view of every currently active version, use `getAllAgentMemory`.
|
|
978
|
+
* by the chain's `MEMORY_RECENT_WINDOW_MS`. For a time-unbounded view
|
|
979
|
+
* of every currently active version, use `getActiveAgentMemory`.
|
|
672
980
|
*/
|
|
673
|
-
declare function
|
|
981
|
+
declare function getRecentAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
|
|
674
982
|
/**
|
|
675
983
|
* All currently-active memory entries with no time cutoff. Use this
|
|
676
|
-
* when you need every active version regardless of age
|
|
677
|
-
* dashboard listing, or a long-running agent whose oldest active
|
|
678
|
-
* versions may have fallen outside `getActiveMemory`'s recent window.
|
|
984
|
+
* when you need every active version regardless of age.
|
|
679
985
|
*/
|
|
680
|
-
declare function
|
|
986
|
+
declare function getActiveAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
|
|
681
987
|
/**
|
|
682
|
-
* Full version history — active + inactive, most recent first.
|
|
683
|
-
*
|
|
988
|
+
* Full version history — active + inactive, most recent first. Used
|
|
989
|
+
* by rollback UX to choose a target version.
|
|
684
990
|
*/
|
|
685
|
-
declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
|
|
991
|
+
declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
|
|
686
992
|
/**
|
|
687
993
|
* Fetch a single memory entry by version id, including its current
|
|
688
|
-
* `is_active` state.
|
|
689
|
-
*
|
|
994
|
+
* `is_active` state. Version ids are agent-unique on chain (not
|
|
995
|
+
* per-file), so `id` alone resolves the target row.
|
|
690
996
|
*/
|
|
691
997
|
declare function getMemoryById(id: number, auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry>;
|
|
692
998
|
/**
|
|
693
999
|
* Audit trail of rollback events for this agent, most recent first.
|
|
1000
|
+
* Scope by file with `filePath`; omit for a cross-file view.
|
|
694
1001
|
*/
|
|
695
|
-
declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<MemoryRollbackEvent[]>;
|
|
1002
|
+
declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<MemoryRollbackEvent[]>;
|
|
696
1003
|
/**
|
|
697
1004
|
* Roll back to a previously-committed memory version. The target
|
|
698
|
-
* `toId` must exist and be currently inactive.
|
|
699
|
-
*
|
|
1005
|
+
* `toId` must exist and be currently inactive. The chain resolves the
|
|
1006
|
+
* target row's `file_path` from `toId` — no file path is passed in.
|
|
1007
|
+
* `reason` is required and is recorded on-chain in `memory_rollback_log`.
|
|
700
1008
|
*/
|
|
701
1009
|
declare function rollbackMemory(toId: number, reason: string, auth: AgentAuth, opts?: RollbackMemoryOptions): Promise<void>;
|
|
702
1010
|
|
|
703
|
-
/**
|
|
704
|
-
* Classify a plugin tool-call event as a memory write.
|
|
705
|
-
*
|
|
706
|
-
* Plugins receive `before_tool_call` events from their host runtime
|
|
707
|
-
* (openclaw, Claude API, MCP, etc.) with varying argument shapes. This
|
|
708
|
-
* module normalizes across shapes and returns a `MemoryEntry` when the
|
|
709
|
-
* call is writing to a memory-like path, or `null` when the SDK should
|
|
710
|
-
* skip the memory-scan path entirely.
|
|
711
|
-
*
|
|
712
|
-
* `event` and `ctx` are typed `unknown` so any plugin can pass its
|
|
713
|
-
* native hook payloads without adaptation — the classifier probes
|
|
714
|
-
* common key names at runtime.
|
|
715
|
-
*/
|
|
716
|
-
|
|
717
1011
|
/**
|
|
718
1012
|
* Tool names that indicate a memory write. Lowercase — matched
|
|
719
|
-
* case-insensitively so
|
|
720
|
-
*
|
|
1013
|
+
* case-insensitively so OpenClaw (lowercase) and Claude API family
|
|
1014
|
+
* (TitleCase) both hit.
|
|
721
1015
|
*/
|
|
722
1016
|
declare const DEFAULT_MEMORY_WRITE_TOOL_NAMES: ReadonlyArray<string>;
|
|
723
1017
|
/**
|
|
724
1018
|
* File path substrings that indicate a memory-shaped target. Callers
|
|
725
|
-
*
|
|
1019
|
+
* extend or override via `classifyMemoryWrite` options.
|
|
726
1020
|
*/
|
|
727
1021
|
declare const DEFAULT_MEMORY_PATH_PATTERNS: ReadonlyArray<string>;
|
|
728
1022
|
/**
|
|
@@ -765,19 +1059,6 @@ interface ClassifyMemoryWriteOptions {
|
|
|
765
1059
|
*/
|
|
766
1060
|
declare function classifyMemoryWrite(event: unknown, ctx: unknown, opts?: ClassifyMemoryWriteOptions): MemoryEntry | null;
|
|
767
1061
|
|
|
768
|
-
/**
|
|
769
|
-
* Plugin-agnostic memory-write guard.
|
|
770
|
-
*
|
|
771
|
-
* A single call that replaces the plugin's usual memory-write branch:
|
|
772
|
-
* classify → scan (Layer 1 regex + Layer 2 LLM) → gate on verdict →
|
|
773
|
-
* persist to chain (fire-and-forget when allowed) → return decision.
|
|
774
|
-
*
|
|
775
|
-
* Plugins call this from their `before_tool_call` hook. When it returns
|
|
776
|
-
* `{ handled: false }` the call wasn't a memory write and the plugin
|
|
777
|
-
* should fall through to its regular tool-call audit. When
|
|
778
|
-
* `{ handled: true }` the plugin returns `decision` directly.
|
|
779
|
-
*/
|
|
780
|
-
|
|
781
1062
|
/**
|
|
782
1063
|
* Minimal logger accepted by `guardMemoryWrite`. Plugins pass their
|
|
783
1064
|
* host runtime's logger (openclaw's `api.logger`, MCP's console, etc.).
|
|
@@ -872,12 +1153,19 @@ interface SyncMemoryOptions {
|
|
|
872
1153
|
* `drifted: false` — pointer is still valid; caller can keep serving the local copy.
|
|
873
1154
|
* `drifted: true` — active id changed on chain; `current` is the fresh decrypted row
|
|
874
1155
|
* (or `null` if active memory was removed entirely).
|
|
1156
|
+
*
|
|
1157
|
+
* `checked` — whether this call actually queried chain. `false` means the TTL
|
|
1158
|
+
* window was still open and the pointer was trusted without contacting chain, so
|
|
1159
|
+
* `drifted: false` carries no evidence about the current state. Callers that
|
|
1160
|
+
* vouch for content to a third party must not treat an unchecked result as proof.
|
|
875
1161
|
*/
|
|
876
1162
|
type SyncMemoryResult = {
|
|
877
1163
|
drifted: false;
|
|
1164
|
+
checked: boolean;
|
|
878
1165
|
pointer: MemoryPointer;
|
|
879
1166
|
} | {
|
|
880
1167
|
drifted: true;
|
|
1168
|
+
checked: true;
|
|
881
1169
|
current: AgentMemoryEntry | null;
|
|
882
1170
|
pointer: MemoryPointer;
|
|
883
1171
|
};
|
|
@@ -918,7 +1206,7 @@ declare function createFileLogger(filePath: string, upstream?: UpstreamLogger):
|
|
|
918
1206
|
/** Default log-file location — `<workspaceDir>/.atbash/plugin.log`. */
|
|
919
1207
|
declare function defaultPluginLogPath(workspaceDir?: string): string;
|
|
920
1208
|
|
|
921
|
-
/** Dedicated memory-read tool names, matched case-insensitively.
|
|
1209
|
+
/** Dedicated memory-read tool names, matched case-insensitively. */
|
|
922
1210
|
declare const DEFAULT_MEMORY_READ_TOOL_NAMES: ReadonlyArray<string>;
|
|
923
1211
|
interface ClassifyMemoryReadOptions {
|
|
924
1212
|
/** Tool names that always count as memory reads. Merged with defaults. */
|
|
@@ -932,15 +1220,49 @@ interface ClassifyMemoryReadOptions {
|
|
|
932
1220
|
* Returns `true` when this tool call is a memory read — either a
|
|
933
1221
|
* dedicated memory-read tool from `readToolNames`, or a generic read
|
|
934
1222
|
* tool (`read` / `read_file`) targeting a memory-shaped path.
|
|
1223
|
+
*
|
|
1224
|
+
* Caller-supplied `patterns` are MERGED with the defaults (matches
|
|
1225
|
+
* Node's original behavior — extending in one plugin doesn't disable
|
|
1226
|
+
* standard coverage).
|
|
935
1227
|
*/
|
|
936
1228
|
declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
|
|
937
1229
|
|
|
938
|
-
/**
|
|
1230
|
+
/**
|
|
1231
|
+
* Decision the manager returns to the plugin's `before_tool_call` handler.
|
|
1232
|
+
*
|
|
1233
|
+
* `allow: true` alone is NOT evidence that anything was checked. Read `audited`
|
|
1234
|
+
* to tell the two apart, and route un-audited calls to your own judge — see the
|
|
1235
|
+
* field docs below.
|
|
1236
|
+
*/
|
|
939
1237
|
interface HookDecision {
|
|
940
1238
|
allow?: boolean;
|
|
941
1239
|
block?: boolean;
|
|
942
1240
|
blockReason?: string;
|
|
943
1241
|
reason?: string;
|
|
1242
|
+
/**
|
|
1243
|
+
* Whether the guard reached an enforcement decision about *this* call.
|
|
1244
|
+
*
|
|
1245
|
+
* Note this describes whether the guard **decided**, not whether it allowed.
|
|
1246
|
+
* Every `block` is `audited: true` — a blocked call is the most thoroughly
|
|
1247
|
+
* checked outcome the guard produces (a red scan, a ciphertext integrity
|
|
1248
|
+
* failure, a rolled-back version), and a host must never re-judge its way past
|
|
1249
|
+
* one.
|
|
1250
|
+
*
|
|
1251
|
+
* Absent or false means the guard reached no decision — it was inside its cache
|
|
1252
|
+
* window, chain was unreachable, the scan never ran, the file it can vouch for
|
|
1253
|
+
* is not the file being read, or it is in observe mode. Those calls are
|
|
1254
|
+
* unaudited: fall through to your own judge exactly as for a `null` return.
|
|
1255
|
+
*
|
|
1256
|
+
* So the host rule is:
|
|
1257
|
+
* `if (d.block) deny; else if (d.audited) allow; else judge it yourself;`
|
|
1258
|
+
*
|
|
1259
|
+
* Treating a bare `allow: true` as a completed audit is what this field exists
|
|
1260
|
+
* to prevent. A host that ignores it and returns the decision verbatim will
|
|
1261
|
+
* execute unaudited tool calls.
|
|
1262
|
+
*/
|
|
1263
|
+
audited?: boolean;
|
|
1264
|
+
/** Scan verdict when one was produced (`green` | `yellow` | `red`). Absent when no scan ran. */
|
|
1265
|
+
verdict?: string;
|
|
944
1266
|
}
|
|
945
1267
|
interface MemoryGuardManagerOptions {
|
|
946
1268
|
auth: AgentAuth;
|
|
@@ -963,6 +1285,13 @@ interface MemoryGuardManagerOptions {
|
|
|
963
1285
|
rollbackMinScore?: number;
|
|
964
1286
|
/** True → return `{block:true}` on defense triggers. False → log and return `null` (audit-only). Default true. */
|
|
965
1287
|
enforce?: boolean;
|
|
1288
|
+
/**
|
|
1289
|
+
* Chain targeting for the pointer sync (network, blockchainRid, nodeUrls).
|
|
1290
|
+
* Defaults to the SDK's configured chain. Without this the manager could only
|
|
1291
|
+
* ever talk to the default chain, which left the whole memory-read path
|
|
1292
|
+
* untestable — `syncLocalMemory` already accepted these options.
|
|
1293
|
+
*/
|
|
1294
|
+
chainOpts?: ChainOpts;
|
|
966
1295
|
/** Host-specific tuning of what counts as a memory read. */
|
|
967
1296
|
memoryReadClassifier?: ClassifyMemoryReadOptions;
|
|
968
1297
|
/** Passed through to `guardMemoryWrite`. Host memory-write tool names override. */
|
|
@@ -991,7 +1320,29 @@ declare class MemoryGuardManager {
|
|
|
991
1320
|
private readonly rollbackMinScore;
|
|
992
1321
|
private readonly enforce;
|
|
993
1322
|
private readonly agentPubkeyHex;
|
|
1323
|
+
/**
|
|
1324
|
+
* Memoized org→chain resolution. Reads have to hit the SAME chain
|
|
1325
|
+
* writes did, so an org-scoped guard must resolve `orgName` to
|
|
1326
|
+
* network exactly like `commitMemoryVersion` does. Without this
|
|
1327
|
+
* cache the read path would either (a) hit the SDK-default chain
|
|
1328
|
+
* every time — silently returning "no active memory on chain" when
|
|
1329
|
+
* writes landed on the org's actual chain, or (b) hammer
|
|
1330
|
+
* `/api/org-network` on every read. `undefined` means "not yet
|
|
1331
|
+
* resolved"; a resolved `null` means "no org / use raw chainOpts".
|
|
1332
|
+
*/
|
|
1333
|
+
private _resolvedChainOpts;
|
|
1334
|
+
private _resolveChainInflight?;
|
|
994
1335
|
constructor(opts: MemoryGuardManagerOptions);
|
|
1336
|
+
/**
|
|
1337
|
+
* Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
|
|
1338
|
+
* already does this for writes; without the same call on the read
|
|
1339
|
+
* path, a client on the SDK's baked default chain reads from the wrong
|
|
1340
|
+
* chain and reports "no active memory" for an agent whose writes did
|
|
1341
|
+
* land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
|
|
1342
|
+
* still wins (caller vouched for it); everything else honors the
|
|
1343
|
+
* dashboard's `org_networks` map.
|
|
1344
|
+
*/
|
|
1345
|
+
private resolveChainOpts;
|
|
995
1346
|
/**
|
|
996
1347
|
* One-shot chain probe at plugin registration. Refreshes MEMORY.md
|
|
997
1348
|
* from chain when drifted and score passes threshold. Fire-and-forget
|
|
@@ -999,12 +1350,33 @@ declare class MemoryGuardManager {
|
|
|
999
1350
|
*/
|
|
1000
1351
|
runBootProbe(): Promise<void>;
|
|
1001
1352
|
/**
|
|
1002
|
-
* Returns a `HookDecision` when the
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1353
|
+
* Returns a `HookDecision` when the guard reached a decision about this event.
|
|
1354
|
+
* Returns `null` when it did not — either the event isn't memory-related, or it
|
|
1355
|
+
* is but the guard could not check it. In both cases the host falls through to
|
|
1356
|
+
* its own audit.
|
|
1357
|
+
*
|
|
1358
|
+
* A returned decision carries `audited` (see `HookDecision`). Only
|
|
1359
|
+
* `{ allow: true, audited: true }` means "checked and cleared"; anything else
|
|
1360
|
+
* that allows is a call the host still needs to judge.
|
|
1005
1361
|
*/
|
|
1006
1362
|
handleBeforeToolCall(event: unknown, ctx: unknown): Promise<HookDecision | null>;
|
|
1007
1363
|
private mapGuardResult;
|
|
1364
|
+
/**
|
|
1365
|
+
* Whether the pointer state this manager tracks actually describes the file
|
|
1366
|
+
* this call is about to read.
|
|
1367
|
+
*
|
|
1368
|
+
* The classifier fires on nine patterns — including the bare tokens
|
|
1369
|
+
* `"memory/"`, `"CLAUDE.md"` and `"AGENTS.md"` — but the sync path only ever
|
|
1370
|
+
* reads, refreshes, or vouches for `this.memoryFilePath`. Without this check a
|
|
1371
|
+
* read of `/repo/CLAUDE.md` (or any path merely containing `memory/`) would
|
|
1372
|
+
* receive an `audited: true` for a file the guard never opened.
|
|
1373
|
+
*
|
|
1374
|
+
* Conservative on purpose: every path-shaped value found must resolve to the
|
|
1375
|
+
* managed file. If none is found, or any one differs, the answer is no. That
|
|
1376
|
+
* also covers events carrying two different path keys, where the classifier
|
|
1377
|
+
* and the host could otherwise disagree about which one is authoritative.
|
|
1378
|
+
*/
|
|
1379
|
+
private vouchesForTarget;
|
|
1008
1380
|
private handleMemoryRead;
|
|
1009
1381
|
private writeMemoryAtomic;
|
|
1010
1382
|
}
|
|
@@ -1013,13 +1385,17 @@ declare function createMemoryGuardManager(opts: MemoryGuardManagerOptions): Memo
|
|
|
1013
1385
|
/**
|
|
1014
1386
|
* Atbash SDK Telemetry — OpenTelemetry metrics for usage tracking.
|
|
1015
1387
|
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1388
|
+
* Metrics are POSTed to the Atbash-owned `/api/telemetry` proxy, which
|
|
1389
|
+
* verifies the bearer, injects the Honeycomb ingest key server-side, and
|
|
1390
|
+
* forwards to Honeycomb. The ingest credential never enters the SDK.
|
|
1391
|
+
*
|
|
1392
|
+
* Environment opt-out (recommended for air-gapped deployments):
|
|
1393
|
+
* ATBASH_TELEMETRY_DISABLED=1
|
|
1018
1394
|
*
|
|
1019
1395
|
* Opt-out: create ~/.config/atbash/telemetry.json with { "enabled": false }
|
|
1020
1396
|
* The file must be readable by the SDK process. If missing, corrupted, or
|
|
1021
|
-
* unreadable
|
|
1022
|
-
*
|
|
1397
|
+
* unreadable, telemetry remains eligible to start unless the environment
|
|
1398
|
+
* opt-out is set.
|
|
1023
1399
|
*/
|
|
1024
1400
|
type ClientSource = "cli" | "sdk" | "plugin:openclaw" | "plugin:langchain" | "plugin:langgraph" | "plugin:hermes" | "plugin:eliza" | "plugin:crewai" | "plugin:mcp" | "plugin:autogen" | "plugin:jeenai" | (string & {});
|
|
1025
1401
|
interface TelemetryConfig {
|
|
@@ -1029,6 +1405,13 @@ interface TelemetryConfig {
|
|
|
1029
1405
|
source?: ClientSource;
|
|
1030
1406
|
/** Flush interval in ms. Default: 60000 */
|
|
1031
1407
|
exportIntervalMs?: number;
|
|
1408
|
+
/** Atbash endpoint that hosts /api/telemetry. Required to actually export. */
|
|
1409
|
+
endpoint?: string;
|
|
1410
|
+
/**
|
|
1411
|
+
* Called on every export to obtain fresh auth headers (typically
|
|
1412
|
+
* `{ Authorization: "Bearer <hex>" }`). Required to actually export.
|
|
1413
|
+
*/
|
|
1414
|
+
getAuthHeaders?: () => Record<string, string>;
|
|
1032
1415
|
}
|
|
1033
1416
|
declare function setupTelemetry(config: TelemetryConfig): void;
|
|
1034
1417
|
/**
|
|
@@ -1051,11 +1434,94 @@ declare function flushTelemetry(): Promise<void>;
|
|
|
1051
1434
|
*/
|
|
1052
1435
|
declare function shutdownTelemetry(): Promise<void>;
|
|
1053
1436
|
|
|
1437
|
+
/**
|
|
1438
|
+
* Rust core does the work; `browser/encrypted-toolcall.ts` mirrors it for the
|
|
1439
|
+
* browser and must produce the same columns.
|
|
1440
|
+
*/
|
|
1441
|
+
/** Must match `column_aad` in the core — the label binds a ciphertext to its column. */
|
|
1442
|
+
declare function columnAad(toolCallId: string, column: string): string;
|
|
1443
|
+
/** Byte-identical to the dashboard's copy — diverging breaks hold-retry resolution. */
|
|
1444
|
+
declare function normalizeActionForHash(action: string): string;
|
|
1445
|
+
/** Lets the judge check the request body against the ciphertext without an org key. */
|
|
1446
|
+
declare function claimHashHex(toolName: string, action: string, context: string, toolArgsJson: string): string;
|
|
1447
|
+
/** @returns hex-encoded signed tx, ready to POST as `signed_log_tool_call`. */
|
|
1448
|
+
declare function signEncryptedToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, orgEncryptionPubKey: string, privkeyHex: string, blockchainRidHex: string): string;
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Cryptographic domain per payload kind. Each kind derives a distinct
|
|
1452
|
+
* key from the same handshake — a verdict payload handed to the
|
|
1453
|
+
* tool-call reader fails authentication rather than silently decoding.
|
|
1454
|
+
*
|
|
1455
|
+
* Values here are the SHORT domain names the Rust core recognizes.
|
|
1456
|
+
* The full HKDF `info` strings (`atbash:chain-encryption:v1:<kind>`)
|
|
1457
|
+
* live inside the core and never surface at the API boundary.
|
|
1458
|
+
*/
|
|
1459
|
+
declare const EciesDomain: {
|
|
1460
|
+
readonly toolCall: "toolcall";
|
|
1461
|
+
readonly verdict: "verdict";
|
|
1462
|
+
readonly note: "note";
|
|
1463
|
+
readonly policy: "policy";
|
|
1464
|
+
readonly raw: "raw";
|
|
1465
|
+
};
|
|
1466
|
+
type EciesDomain = (typeof EciesDomain)[keyof typeof EciesDomain];
|
|
1467
|
+
/**
|
|
1468
|
+
* Encrypt `plaintext` so that only the holder of `orgPubKeyHex` can read it.
|
|
1469
|
+
*
|
|
1470
|
+
* @param plaintext UTF-8 text to protect.
|
|
1471
|
+
* @param orgPubKeyHex Org's compressed secp256k1 public key (33 bytes hex).
|
|
1472
|
+
* @param aad Context bound to the ciphertext — pass the record's id.
|
|
1473
|
+
* @returns raw payload for a Rell `byte_array` column.
|
|
1474
|
+
*/
|
|
1475
|
+
declare function encryptForOrg(plaintext: string, orgPubKeyHex: string, aad: string, domain?: EciesDomain): Uint8Array;
|
|
1476
|
+
/**
|
|
1477
|
+
* Decrypt a payload produced by {@link encryptForOrg}.
|
|
1478
|
+
*
|
|
1479
|
+
* Throws if the key is wrong, the `aad` does not match the one used at
|
|
1480
|
+
* encrypt time, or the ciphertext was tampered with — GCM authentication
|
|
1481
|
+
* makes all three indistinguishable by design.
|
|
1482
|
+
*
|
|
1483
|
+
* @param payload Value read from the on-chain `byte_array` column.
|
|
1484
|
+
* @param orgPrivKeyHex Org's secp256k1 private key (32 bytes hex).
|
|
1485
|
+
* @param aad Must equal the `aad` used when encrypting.
|
|
1486
|
+
*/
|
|
1487
|
+
declare function decryptForOrg(payload: Uint8Array, orgPrivKeyHex: string, aad: string, domain?: EciesDomain): string;
|
|
1488
|
+
/**
|
|
1489
|
+
* Size in bytes of the encrypted payload for a given plaintext length.
|
|
1490
|
+
* Lets callers check against the on-chain column cap
|
|
1491
|
+
* (`MAX_CONTENT_CIPHER_SIZE`) before submitting a transaction the
|
|
1492
|
+
* contract would reject.
|
|
1493
|
+
*/
|
|
1494
|
+
declare function encryptedLength(plaintextByteLength: number): number;
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* atb1.<key-fingerprint>.<claim-hash>.<base64 ciphertext>
|
|
1498
|
+
*
|
|
1499
|
+
* Normative spec: `core/src/crypto_envelope.rs`. This mirrors it for the browser.
|
|
1500
|
+
*/
|
|
1501
|
+
interface Envelope {
|
|
1502
|
+
/** First 8 bytes of the recipient public key, hex. May be empty. */
|
|
1503
|
+
keyFingerprint: string;
|
|
1504
|
+
/** Commitment to the accompanying plaintext claims. May be empty. */
|
|
1505
|
+
claimHash: string;
|
|
1506
|
+
/** Raw ECIES payload. */
|
|
1507
|
+
payload: Uint8Array;
|
|
1508
|
+
}
|
|
1509
|
+
declare function packEnvelope(payload: Uint8Array, keyFingerprint?: string, claimHash?: string): string;
|
|
1510
|
+
/**
|
|
1511
|
+
* Stays true for a truncated envelope that `parseEnvelope` rejects — a severed
|
|
1512
|
+
* ciphertext is not plaintext, so callers must show a placeholder.
|
|
1513
|
+
*/
|
|
1514
|
+
declare function isEnvelope(value: string): boolean;
|
|
1515
|
+
/** Null, not a throw — pre-encryption records are plaintext. */
|
|
1516
|
+
declare function parseEnvelope(value: string): Envelope | null;
|
|
1517
|
+
declare function keyFingerprintOf(pubKeyHex: string): string;
|
|
1518
|
+
|
|
1054
1519
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
1055
1520
|
declare function derivePublicKey(privkey: string): string;
|
|
1056
1521
|
declare function generateKeypair(): KeyPair;
|
|
1057
1522
|
declare function loadAgent(privkey: string): AgentAuth;
|
|
1058
1523
|
declare function signLogToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, privkey: string, blockchainRid: string): string;
|
|
1524
|
+
|
|
1059
1525
|
declare function signJudgeAction(judgmentId: string, action: string, context: string, extra: string, privkey: string, blockchainRid: string): string;
|
|
1060
1526
|
declare function verifySignature(body: Buffer, signatureHex: string, pubkeyHex: string): boolean;
|
|
1061
1527
|
declare function normalizeForMatching(text: string): string;
|
|
@@ -1065,4 +1531,4 @@ declare function containsSecret(text: string): boolean;
|
|
|
1065
1531
|
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
1066
1532
|
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
1067
1533
|
|
|
1068
|
-
export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, type EncryptedMemory, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, classifyMemoryRead, classifyMemoryWrite, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptMemoryContent, flushTelemetry, generateKeypair,
|
|
1534
|
+
export { type ActionType, type AgentAuth, type AgentLookupOptions, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, BOOT_SYNC_HINT, type ChainConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, HttpClient, HttpTransportError, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, KEY_FILENAMES, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PRIVATE_CHAIN, PUBLIC_CHAIN, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, bootSyncFailureLine, buildAllowedJudgeHosts, canonicalAllow, chainForNetwork, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveAgentMemory, getActiveMemoryId, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRecentAgentMemory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, keyPathCandidates, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, normalizeActionType, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
|