@atbash/sdk 0.10.13-dev.0 → 0.13.0-dev.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 CHANGED
@@ -142,12 +142,17 @@ const atbash = Atbash.fromConfig(); // reads env + config file
142
142
  | `agentKey` | `ATBASH_AGENT_KEY` |
143
143
  | `orgName` | `ATBASH_ORG_NAME` |
144
144
  | `judgeEndpoint` | `ATBASH_ENDPOINT` |
145
+ | `judgeVerifyPubKey` | `ATBASH_JUDGE_VERIFY_PUBKEY` (self-hosted judge response-signing key; selects the self-hosted policy) |
145
146
  | `blockchainRid` | `ATBASH_BLOCKCHAIN_RID` |
146
147
  | `provider` | `ATBASH_PROVIDER` |
147
148
  | `providerModel` | `ATBASH_PROVIDER_MODEL` |
148
149
 
149
150
  Persistent config helpers: `saveUserConfig(config)`, `loadUserConfig()`, `resolve(key, flagValue?)`, `getConfigPath()`.
150
151
 
152
+ ### Judge endpoint policy
153
+
154
+ Both `Atbash.fromConfig()` and the direct constructor validate the judge endpoint before any request is made. `new Atbash(privkey, { endpoint })` accepts only an `https://` allowlisted judge host, or a self-hosted judge when `verifyPubKey` is also given (the 66-hex response-signing key, which then verifies every judge response). Plaintext `http://` is accepted only for loopback (`localhost`, `127.0.0.1`, `::1`) local development. Anything else throws at construction, so a misconfigured or injected endpoint can no longer receive the agent's signed actions or return unsigned verdicts. `validateJudgeEndpoint(...)` exposes the same check.
155
+
151
156
  Agent policy and detail reads can resolve the organization's active network, or
152
157
  accept an explicit network override:
153
158
 
@@ -30,6 +30,15 @@ interface ValidatedEndpoint {
30
30
  declare function buildAllowedJudgeHosts(): ReadonlySet<string>;
31
31
  declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
32
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
+
33
42
  /**
34
43
  * User-facing types. Two groups:
35
44
  * - Core types — the exact shapes the Rust core emits across the NAPI
@@ -290,7 +299,24 @@ interface AtbashLogger {
290
299
  interface AtbashOptions {
291
300
  endpoint?: string;
292
301
  timeoutMs?: number;
302
+ /**
303
+ * Full chain override — BRID + nodeUrls in one object. Wins over every
304
+ * other chain selector. Prefer this over paired `nodeUrls`/`blockchainRid`
305
+ * for anything but backwards compatibility.
306
+ */
307
+ chain?: ChainConfig;
308
+ /**
309
+ * Preset chain selector — `"public"` or `"private"`. Resolves to the
310
+ * matching `ChainConfig` via `chainForNetwork()`. Overridden by `chain`,
311
+ * overrides env `ATBASH_DEFAULT_CHAIN_NETWORK` and the config file.
312
+ */
313
+ network?: Network;
314
+ /**
315
+ * Explicit node URLs. Must be paired with `blockchainRid`. Passing one
316
+ * without the other throws — a BRID/nodes mismatch 404s every request.
317
+ */
293
318
  nodeUrls?: readonly string[];
319
+ /** Explicit BRID. Must be paired with `nodeUrls`. See {@link nodeUrls}. */
294
320
  blockchainRid?: string;
295
321
  /**
296
322
  * Default org name. When set, `judgeAction` / `auditToolCall` resolve
@@ -357,6 +383,10 @@ interface FromConfigOptions {
357
383
  keyPath?: string;
358
384
  /** Judge endpoint config — validated against the allowlist / self-hosted policy. */
359
385
  judge?: JudgeEndpointConfig;
386
+ /** See {@link AtbashOptions.chain}. */
387
+ chain?: ChainConfig;
388
+ /** See {@link AtbashOptions.network}. */
389
+ network?: Network;
360
390
  blockchainRid?: string;
361
391
  timeoutMs?: number;
362
392
  nodeUrls?: readonly string[];
@@ -408,12 +438,6 @@ interface LogToolCallOptions {
408
438
  orgEncryptionPubKey?: string;
409
439
  }
410
440
 
411
- interface ChainConfig {
412
- readonly network: Network;
413
- readonly blockchainRid: string;
414
- readonly nodeUrls: readonly string[];
415
- }
416
-
417
441
  declare class Atbash {
418
442
  readonly auth: AgentAuth;
419
443
  readonly endpoint: string;
@@ -437,6 +461,27 @@ declare class Atbash {
437
461
  * calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
438
462
  */
439
463
  private readonly _chainCache;
464
+ /**
465
+ * The chain the constructor settled on. Used only where a lookup returns no
466
+ * answer — see {@link resolveChainFromMap}.
467
+ */
468
+ private readonly _defaultChain;
469
+ /**
470
+ * True when the caller named a chain outright — `chain`, `network`, or the
471
+ * paired `blockchainRid` + `nodeUrls`.
472
+ *
473
+ * Such a client is never re-pointed: not by the migration switch, and not by
474
+ * where an org turns out to live. Naming a chain is the caller saying "talk
475
+ * to this one", and silently routing elsewhere would make the argument a
476
+ * suggestion. A client that names nothing is the one that follows the org.
477
+ */
478
+ private readonly _explicitChain;
479
+ /**
480
+ * The fleet-wide chain switch, read once at construction. `resolve()` hits
481
+ * the config file on disk, so re-reading it per call would put a file read
482
+ * on every judge.
483
+ */
484
+ private readonly _forcedNetwork;
440
485
  /**
441
486
  * Short-TTL cache for `/api/ai/exists`. The `registered` field is
442
487
  * monotonic (once true, stays true), so most calls in a burst re-fetch
@@ -552,7 +597,9 @@ declare class Atbash {
552
597
  * 2. Per-chain subscription fallback — public + private records
553
598
  * are fetched in parallel, with `is_private_blockchain` and
554
599
  * `assigned_at` reconciling mixed states.
555
- * Defaults to the public chain when nothing else resolves.
600
+ * A lookup that names exactly one chain wins outright. Where it names
601
+ * neither (a brand-new org) or cannot choose between them, the client's
602
+ * configured default decides.
556
603
  */
557
604
  resolveChainForOrg(orgName: string): Promise<ChainConfig>;
558
605
  /**
@@ -606,6 +653,25 @@ declare class Atbash {
606
653
  * back to the client default (best-effort discovery).
607
654
  */
608
655
  private bridForOrg;
656
+ /**
657
+ * BRID for the client's configured default org, if it has one.
658
+ *
659
+ * Calls that carry no `orgName` argument are not chain-less: they still
660
+ * belong to `this.orgName`, and that org lives on exactly one chain. Routing
661
+ * them by the constructor's chain instead means a client configured
662
+ * `network: "private"` reads the private chain for an org that lives on
663
+ * public, and gets an empty answer rather than an error. So where an org is
664
+ * known the org decides the chain, and the constructor's chain is what is
665
+ * left when no org is known at all — the order `resolveAgentLookupNetwork`
666
+ * already applies to agent metadata reads, and the order the dashboard
667
+ * applies in `resolveChainForWallet`.
668
+ *
669
+ * Undefined when there is no default org, so callers keep falling back to
670
+ * the client default.
671
+ */
672
+ /** The switch's chain, unless this client named one of its own. */
673
+ private forcedNetwork;
674
+ private defaultOrgBrid;
609
675
  private raiseIfError;
610
676
  /** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
611
677
  private httpError;
@@ -689,7 +755,20 @@ interface AtbashUserConfig {
689
755
  agentKey?: string;
690
756
  orgName?: string;
691
757
  judgeEndpoint?: string;
692
- blockchainRid?: string;
758
+ /**
759
+ * Response-signing pubkey of a self-hosted judge (66 hex). Setting it makes
760
+ * `fromConfig` use the self-hosted policy for `judgeEndpoint`, which is the
761
+ * only way a non-allowlisted judge host is accepted.
762
+ */
763
+ judgeVerifyPubKey?: string;
764
+ /**
765
+ * `"private"` pins every org to the private chain regardless of where the
766
+ * dashboard says it lives — the migration switch. Leave it unset for the
767
+ * normal mode, where each org's own chain decides. There is no `"public"`
768
+ * value; a caller that wants one specific chain passes `chain` or `network`
769
+ * at construction instead.
770
+ */
771
+ defaultChainNetwork?: Network;
693
772
  provider?: string;
694
773
  providerModel?: string;
695
774
  /** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
@@ -791,15 +870,26 @@ declare function scanMemoryBatch(entries: MemoryEntry[], auth: AgentAuth, opts?:
791
870
  interface CommitMemoryOptions {
792
871
  /** Score in [1, 10]. Defaults to 5 (matches the Rell entity default). */
793
872
  score?: number;
873
+ /**
874
+ * Which memory file this commit targets. Defaults to `""` — the
875
+ * un-pathed slot, matching Rell's `file_path: text = ""` default.
876
+ * Pass an explicit filename (e.g. `"AGENTS.md"`) to keep files
877
+ * versioned independently on chain.
878
+ */
879
+ filePath?: string;
794
880
  /** Org name — when set, the SDK resolves which chain the agent lives on. */
795
881
  orgName?: string;
796
882
  /** Atbash service endpoint for org→chain lookup. */
797
883
  endpoint?: string;
884
+ /** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
885
+ verifyPubKey?: string;
798
886
  chainOpts?: ChainOpts;
799
887
  }
800
888
  interface RollbackMemoryOptions {
801
889
  orgName?: string;
802
890
  endpoint?: string;
891
+ /** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
892
+ verifyPubKey?: string;
803
893
  chainOpts?: ChainOpts;
804
894
  }
805
895
  /**
@@ -821,6 +911,7 @@ declare function commitMemoryVersion(plaintext: string, auth: AgentAuth, opts?:
821
911
  */
822
912
  interface AgentMemoryEntry {
823
913
  id: number;
914
+ filePath: string;
824
915
  content: string;
825
916
  decryptError?: string;
826
917
  score: number;
@@ -832,6 +923,7 @@ interface AgentMemoryEntry {
832
923
  interface MemoryRollbackEvent {
833
924
  fromId: number;
834
925
  toId: number;
926
+ filePath: string;
835
927
  reason: string;
836
928
  signer: string;
837
929
  createdAt: number;
@@ -842,36 +934,39 @@ interface MemoryRollbackEvent {
842
934
  * response is a single integer, so this is safe to call on every
843
935
  * memory-read hot path.
844
936
  */
845
- declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts): Promise<number | null>;
937
+ declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<number | null>;
846
938
  /**
847
939
  * Recent active memory entries — subset of active versions filtered
848
940
  * by the chain's `MEMORY_RECENT_WINDOW_MS`. For a time-unbounded view
849
- * of every currently active version, use `getAllAgentMemory`.
941
+ * of every currently active version, use `getActiveAgentMemory`.
850
942
  */
851
- declare function getActiveMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
943
+ declare function getRecentAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
852
944
  /**
853
945
  * All currently-active memory entries with no time cutoff. Use this
854
946
  * when you need every active version regardless of age.
855
947
  */
856
- declare function getAllAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
948
+ declare function getActiveAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
857
949
  /**
858
950
  * Full version history — active + inactive, most recent first. Used
859
951
  * by rollback UX to choose a target version.
860
952
  */
861
- declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
953
+ declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<AgentMemoryEntry[]>;
862
954
  /**
863
955
  * Fetch a single memory entry by version id, including its current
864
- * `is_active` state.
956
+ * `is_active` state. Version ids are agent-unique on chain (not
957
+ * per-file), so `id` alone resolves the target row.
865
958
  */
866
959
  declare function getMemoryById(id: number, auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry>;
867
960
  /**
868
961
  * Audit trail of rollback events for this agent, most recent first.
962
+ * Scope by file with `filePath`; omit for a cross-file view.
869
963
  */
870
- declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<MemoryRollbackEvent[]>;
964
+ declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts, filePath?: string | null): Promise<MemoryRollbackEvent[]>;
871
965
  /**
872
966
  * Roll back to a previously-committed memory version. The target
873
- * `toId` must exist and be currently inactive. `reason` is required
874
- * and is recorded on-chain in `memory_rollback_log`.
967
+ * `toId` must exist and be currently inactive. The chain resolves the
968
+ * target row's `file_path` from `toId` — no file path is passed in.
969
+ * `reason` is required and is recorded on-chain in `memory_rollback_log`.
875
970
  */
876
971
  declare function rollbackMemory(toId: number, reason: string, auth: AgentAuth, opts?: RollbackMemoryOptions): Promise<void>;
877
972
 
@@ -956,8 +1051,6 @@ interface GuardMemoryWriteInput extends ClassifyMemoryWriteOptions {
956
1051
  debug?: boolean;
957
1052
  /** Optional logger for debug probe + persist-failure warnings. */
958
1053
  logger?: GuardLogger;
959
- /** Absolute path of the agent's managed memory file. Required for chain commits — omitted skips them. */
960
- memoryFilePath?: string;
961
1054
  }
962
1055
  /** Plugin-facing decision. Shape mirrors what plugins return from `before_tool_call`. */
963
1056
  interface GuardMemoryDecision {
@@ -1378,4 +1471,4 @@ declare function containsSecret(text: string): boolean;
1378
1471
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1379
1472
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1380
1473
 
1381
- 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 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, 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, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, keyPathCandidates, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, 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 };
1474
+ 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, 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, 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 };