@atbash/sdk 0.15.1-dev.0 → 0.16.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
@@ -144,8 +144,6 @@ const atbash = Atbash.fromConfig(); // reads env + config file
144
144
  | `judgeEndpoint` | `ATBASH_ENDPOINT` |
145
145
  | `judgeVerifyPubKey` | `ATBASH_JUDGE_VERIFY_PUBKEY` (self-hosted judge response-signing key; selects the self-hosted policy) |
146
146
  | `blockchainRid` | `ATBASH_BLOCKCHAIN_RID` |
147
- | `provider` | `ATBASH_PROVIDER` |
148
- | `providerModel` | `ATBASH_PROVIDER_MODEL` |
149
147
 
150
148
  Persistent config helpers: `saveUserConfig(config)`, `loadUserConfig()`, `resolve(key, flagValue?)`, `getConfigPath()`.
151
149
 
@@ -408,8 +408,6 @@ interface FromConfigOptions {
408
408
  interface JudgeOptions {
409
409
  toolName?: string;
410
410
  toolArgsJson?: string;
411
- provider?: string;
412
- model?: string;
413
411
  verifyPubKey?: string;
414
412
  /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
415
413
  orgEncryptionPubKey?: string;
@@ -807,8 +805,6 @@ interface AtbashUserConfig {
807
805
  * at construction instead.
808
806
  */
809
807
  defaultChainNetwork?: Network;
810
- provider?: string;
811
- providerModel?: string;
812
808
  /** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
813
809
  debug?: string;
814
810
  }
@@ -879,6 +875,22 @@ declare const BOOT_SYNC_HINT = "check the chain endpoint and orgName if the caus
879
875
  */
880
876
  declare function bootSyncFailureLine(cause: unknown): string;
881
877
 
878
+ /**
879
+ * Make a chain query result crossable at the NAPI boundary.
880
+ *
881
+ * `postchain-client` decodes a Rell `byte_array` into a Node `Buffer`. The
882
+ * core's `parse*` functions take `serde_json::Value`, and NAPI-RS cannot
883
+ * convert a `Buffer` into one — it reaches the methods every `Uint8Array`
884
+ * inherits and fails with "JS functions cannot be represented as a
885
+ * serde_json::Value", which names functions for what is a plain Buffer.
886
+ *
887
+ * The conversion has to happen here because the failure is in the argument
888
+ * conversion, before any core code runs. Of the shapes the core accepts —
889
+ * hex string, `[u8]`, `{ data: [...] }` — hex is the cheapest to produce.
890
+ */
891
+ /** Recursively rewrite byte containers to hex, leaving everything else as-is. */
892
+ declare function gtvToFfiSafe(value: unknown): unknown;
893
+
882
894
  /** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
883
895
  declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
884
896
  /** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
@@ -1320,7 +1332,29 @@ declare class MemoryGuardManager {
1320
1332
  private readonly rollbackMinScore;
1321
1333
  private readonly enforce;
1322
1334
  private readonly agentPubkeyHex;
1335
+ /**
1336
+ * Memoized org→chain resolution. Reads have to hit the SAME chain
1337
+ * writes did, so an org-scoped guard must resolve `orgName` to
1338
+ * network exactly like `commitMemoryVersion` does. Without this
1339
+ * cache the read path would either (a) hit the SDK-default chain
1340
+ * every time — silently returning "no active memory on chain" when
1341
+ * writes landed on the org's actual chain, or (b) hammer
1342
+ * `/api/org-network` on every read. `undefined` means "not yet
1343
+ * resolved"; a resolved `null` means "no org / use raw chainOpts".
1344
+ */
1345
+ private _resolvedChainOpts;
1346
+ private _resolveChainInflight?;
1323
1347
  constructor(opts: MemoryGuardManagerOptions);
1348
+ /**
1349
+ * Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
1350
+ * already does this for writes; without the same call on the read
1351
+ * path, a client on the SDK's baked default chain reads from the wrong
1352
+ * chain and reports "no active memory" for an agent whose writes did
1353
+ * land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
1354
+ * still wins (caller vouched for it); everything else honors the
1355
+ * dashboard's `org_networks` map.
1356
+ */
1357
+ private resolveChainOpts;
1324
1358
  /**
1325
1359
  * One-shot chain probe at plugin registration. Refreshes MEMORY.md
1326
1360
  * from chain when drifted and score passes threshold. Fire-and-forget
@@ -1509,4 +1543,4 @@ declare function containsSecret(text: string): boolean;
1509
1543
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1510
1544
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1511
1545
 
1512
- 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 };
1546
+ 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, gtvToFfiSafe, 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 };
package/dist/browser.mjs CHANGED
@@ -44656,8 +44656,6 @@ function resolve(_key, flagValue) {
44656
44656
  function forcedChainNetwork(flagValue) {
44657
44657
  return flagValue === "public" || flagValue === "private" ? flagValue : void 0;
44658
44658
  }
44659
- function warnDeprecatedEnvVarsOnce(_log) {
44660
- }
44661
44659
 
44662
44660
  // src-ts/client.ts
44663
44661
  function generateToolCallId() {
@@ -44765,7 +44763,6 @@ var Atbash = class _Atbash {
44765
44763
  this._defaultChain = resolvedChain;
44766
44764
  this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
44767
44765
  this._forcedNetwork = forcedChainNetwork();
44768
- warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
44769
44766
  this.orgName = options.orgName;
44770
44767
  this.verifyPubKey = validated.verifyPubKey ?? void 0;
44771
44768
  this.orgEncryptionPubKey = options.orgEncryptionPubKey;
@@ -45023,18 +45020,15 @@ var Atbash = class _Atbash {
45023
45020
  if (!logResult.success || !logResult.toolCallId || !logResult.signedHex) {
45024
45021
  throw new Error(logResult.error || "Failed to sign log_tool_call");
45025
45022
  }
45026
- let signedJudgeAction;
45027
- if (!options.provider) {
45028
- const judgmentId = generateToolCallId();
45029
- signedJudgeAction = native.signJudgeAction(
45030
- judgmentId,
45031
- action,
45032
- context || "",
45033
- "",
45034
- this.auth.privkey,
45035
- brid
45036
- );
45037
- }
45023
+ const judgmentId = generateToolCallId();
45024
+ const signedJudgeAction = native.signJudgeAction(
45025
+ judgmentId,
45026
+ action,
45027
+ context || "",
45028
+ "",
45029
+ this.auth.privkey,
45030
+ brid
45031
+ );
45038
45032
  const body = {
45039
45033
  tool_call_id: logResult.toolCallId,
45040
45034
  agent_pubkey: this.auth.pubkey,
@@ -45043,10 +45037,8 @@ var Atbash = class _Atbash {
45043
45037
  };
45044
45038
  if (signedJudgeAction) body.signed_judge_action = signedJudgeAction;
45045
45039
  if (context) body.context = context;
45046
- if (options.provider) body.provider = options.provider;
45047
45040
  if (options.toolName) body.tool_name = options.toolName;
45048
45041
  if (options.toolArgsJson) body.tool_args_json = options.toolArgsJson;
45049
- if (options.model) body.model = options.model;
45050
45042
  if (options.resolved) body.resolved = options.resolved;
45051
45043
  if (options.mode) body.mode = options.mode;
45052
45044
  let resp;
@@ -45927,6 +45919,22 @@ function bootSyncFailureLine(cause) {
45927
45919
  );
45928
45920
  }
45929
45921
 
45922
+ // src-ts/memory/_gtv_bytes.ts
45923
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45924
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45925
+ function gtvToFfiSafe(value) {
45926
+ if (value instanceof Uint8Array) return Buffer.from(value).toString("hex");
45927
+ if (Array.isArray(value)) return value.map(gtvToFfiSafe);
45928
+ if (value !== null && typeof value === "object") {
45929
+ const out = {};
45930
+ for (const [key3, val] of Object.entries(value)) {
45931
+ out[key3] = gtvToFfiSafe(val);
45932
+ }
45933
+ return out;
45934
+ }
45935
+ return value;
45936
+ }
45937
+
45930
45938
  // src-ts/memory/index.ts
45931
45939
  init_define_ATBASH_CHROMIA_NODE_URLS();
45932
45940
  init_define_ATBASH_PRIVATE_NODE_URLS();
@@ -46394,6 +46402,7 @@ export {
46394
46402
  getMemoryHistory,
46395
46403
  getRecentAgentMemory,
46396
46404
  getRollbackHistory,
46405
+ gtvToFfiSafe,
46397
46406
  guardMemoryWrite,
46398
46407
  isEnvelope,
46399
46408
  isValidPrivateKey2 as isValidPrivateKey,
package/dist/index.d.mts CHANGED
@@ -408,8 +408,6 @@ interface FromConfigOptions {
408
408
  interface JudgeOptions {
409
409
  toolName?: string;
410
410
  toolArgsJson?: string;
411
- provider?: string;
412
- model?: string;
413
411
  verifyPubKey?: string;
414
412
  /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
415
413
  orgEncryptionPubKey?: string;
@@ -807,8 +805,6 @@ interface AtbashUserConfig {
807
805
  * at construction instead.
808
806
  */
809
807
  defaultChainNetwork?: Network;
810
- provider?: string;
811
- providerModel?: string;
812
808
  /** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
813
809
  debug?: string;
814
810
  }
@@ -879,6 +875,22 @@ declare const BOOT_SYNC_HINT = "check the chain endpoint and orgName if the caus
879
875
  */
880
876
  declare function bootSyncFailureLine(cause: unknown): string;
881
877
 
878
+ /**
879
+ * Make a chain query result crossable at the NAPI boundary.
880
+ *
881
+ * `postchain-client` decodes a Rell `byte_array` into a Node `Buffer`. The
882
+ * core's `parse*` functions take `serde_json::Value`, and NAPI-RS cannot
883
+ * convert a `Buffer` into one — it reaches the methods every `Uint8Array`
884
+ * inherits and fails with "JS functions cannot be represented as a
885
+ * serde_json::Value", which names functions for what is a plain Buffer.
886
+ *
887
+ * The conversion has to happen here because the failure is in the argument
888
+ * conversion, before any core code runs. Of the shapes the core accepts —
889
+ * hex string, `[u8]`, `{ data: [...] }` — hex is the cheapest to produce.
890
+ */
891
+ /** Recursively rewrite byte containers to hex, leaving everything else as-is. */
892
+ declare function gtvToFfiSafe(value: unknown): unknown;
893
+
882
894
  /** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
883
895
  declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
884
896
  /** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
@@ -1320,7 +1332,29 @@ declare class MemoryGuardManager {
1320
1332
  private readonly rollbackMinScore;
1321
1333
  private readonly enforce;
1322
1334
  private readonly agentPubkeyHex;
1335
+ /**
1336
+ * Memoized org→chain resolution. Reads have to hit the SAME chain
1337
+ * writes did, so an org-scoped guard must resolve `orgName` to
1338
+ * network exactly like `commitMemoryVersion` does. Without this
1339
+ * cache the read path would either (a) hit the SDK-default chain
1340
+ * every time — silently returning "no active memory on chain" when
1341
+ * writes landed on the org's actual chain, or (b) hammer
1342
+ * `/api/org-network` on every read. `undefined` means "not yet
1343
+ * resolved"; a resolved `null` means "no org / use raw chainOpts".
1344
+ */
1345
+ private _resolvedChainOpts;
1346
+ private _resolveChainInflight?;
1323
1347
  constructor(opts: MemoryGuardManagerOptions);
1348
+ /**
1349
+ * Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
1350
+ * already does this for writes; without the same call on the read
1351
+ * path, a client on the SDK's baked default chain reads from the wrong
1352
+ * chain and reports "no active memory" for an agent whose writes did
1353
+ * land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
1354
+ * still wins (caller vouched for it); everything else honors the
1355
+ * dashboard's `org_networks` map.
1356
+ */
1357
+ private resolveChainOpts;
1324
1358
  /**
1325
1359
  * One-shot chain probe at plugin registration. Refreshes MEMORY.md
1326
1360
  * from chain when drifted and score passes threshold. Fire-and-forget
@@ -1509,4 +1543,4 @@ declare function containsSecret(text: string): boolean;
1509
1543
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1510
1544
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1511
1545
 
1512
- 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 };
1546
+ 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, gtvToFfiSafe, 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 };
package/dist/index.d.ts CHANGED
@@ -408,8 +408,6 @@ interface FromConfigOptions {
408
408
  interface JudgeOptions {
409
409
  toolName?: string;
410
410
  toolArgsJson?: string;
411
- provider?: string;
412
- model?: string;
413
411
  verifyPubKey?: string;
414
412
  /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
415
413
  orgEncryptionPubKey?: string;
@@ -807,8 +805,6 @@ interface AtbashUserConfig {
807
805
  * at construction instead.
808
806
  */
809
807
  defaultChainNetwork?: Network;
810
- provider?: string;
811
- providerModel?: string;
812
808
  /** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
813
809
  debug?: string;
814
810
  }
@@ -879,6 +875,22 @@ declare const BOOT_SYNC_HINT = "check the chain endpoint and orgName if the caus
879
875
  */
880
876
  declare function bootSyncFailureLine(cause: unknown): string;
881
877
 
878
+ /**
879
+ * Make a chain query result crossable at the NAPI boundary.
880
+ *
881
+ * `postchain-client` decodes a Rell `byte_array` into a Node `Buffer`. The
882
+ * core's `parse*` functions take `serde_json::Value`, and NAPI-RS cannot
883
+ * convert a `Buffer` into one — it reaches the methods every `Uint8Array`
884
+ * inherits and fails with "JS functions cannot be represented as a
885
+ * serde_json::Value", which names functions for what is a plain Buffer.
886
+ *
887
+ * The conversion has to happen here because the failure is in the argument
888
+ * conversion, before any core code runs. Of the shapes the core accepts —
889
+ * hex string, `[u8]`, `{ data: [...] }` — hex is the cheapest to produce.
890
+ */
891
+ /** Recursively rewrite byte containers to hex, leaving everything else as-is. */
892
+ declare function gtvToFfiSafe(value: unknown): unknown;
893
+
882
894
  /** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
883
895
  declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
884
896
  /** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
@@ -1320,7 +1332,29 @@ declare class MemoryGuardManager {
1320
1332
  private readonly rollbackMinScore;
1321
1333
  private readonly enforce;
1322
1334
  private readonly agentPubkeyHex;
1335
+ /**
1336
+ * Memoized org→chain resolution. Reads have to hit the SAME chain
1337
+ * writes did, so an org-scoped guard must resolve `orgName` to
1338
+ * network exactly like `commitMemoryVersion` does. Without this
1339
+ * cache the read path would either (a) hit the SDK-default chain
1340
+ * every time — silently returning "no active memory on chain" when
1341
+ * writes landed on the org's actual chain, or (b) hammer
1342
+ * `/api/org-network` on every read. `undefined` means "not yet
1343
+ * resolved"; a resolved `null` means "no org / use raw chainOpts".
1344
+ */
1345
+ private _resolvedChainOpts;
1346
+ private _resolveChainInflight?;
1323
1347
  constructor(opts: MemoryGuardManagerOptions);
1348
+ /**
1349
+ * Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
1350
+ * already does this for writes; without the same call on the read
1351
+ * path, a client on the SDK's baked default chain reads from the wrong
1352
+ * chain and reports "no active memory" for an agent whose writes did
1353
+ * land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
1354
+ * still wins (caller vouched for it); everything else honors the
1355
+ * dashboard's `org_networks` map.
1356
+ */
1357
+ private resolveChainOpts;
1324
1358
  /**
1325
1359
  * One-shot chain probe at plugin registration. Refreshes MEMORY.md
1326
1360
  * from chain when drifted and score passes threshold. Fire-and-forget
@@ -1509,4 +1543,4 @@ declare function containsSecret(text: string): boolean;
1509
1543
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1510
1544
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1511
1545
 
1512
- 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 };
1546
+ 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, gtvToFfiSafe, 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 };
package/dist/index.js CHANGED
@@ -2908,6 +2908,7 @@ __export(src_ts_exports, {
2908
2908
  getMemoryHistory: () => getMemoryHistory,
2909
2909
  getRecentAgentMemory: () => getRecentAgentMemory,
2910
2910
  getRollbackHistory: () => getRollbackHistory,
2911
+ gtvToFfiSafe: () => gtvToFfiSafe,
2911
2912
  guardMemoryWrite: () => guardMemoryWrite,
2912
2913
  isEnvelope: () => isEnvelope,
2913
2914
  isValidPrivateKey: () => isValidPrivateKey,
@@ -3434,33 +3435,8 @@ var ENV_MAP = {
3434
3435
  // Same variable name the Hermes plugin already documents.
3435
3436
  judgeVerifyPubKey: "ATBASH_JUDGE_VERIFY_PUBKEY",
3436
3437
  defaultChainNetwork: "ATBASH_DEFAULT_CHAIN_NETWORK",
3437
- provider: "ATBASH_PROVIDER",
3438
- providerModel: "ATBASH_PROVIDER_MODEL",
3439
3438
  debug: "ATBASH_DEBUG"
3440
3439
  };
3441
- var DEPRECATED_ENV_VARS = ["ATBASH_BLOCKCHAIN_RID"];
3442
- var DEPRECATED_CONFIG_FIELDS = ["blockchainRid"];
3443
- var deprecatedWarned = false;
3444
- function warnDeprecatedEnvVarsOnce(log = console.warn) {
3445
- if (deprecatedWarned) return;
3446
- for (const name2 of DEPRECATED_ENV_VARS) {
3447
- if (process.env[name2]) {
3448
- deprecatedWarned = true;
3449
- log(
3450
- `[atbash] ${name2} is ignored \u2014 each org's chain is resolved from the dashboard; set ATBASH_DEFAULT_CHAIN_NETWORK=private only to pin everything to private`
3451
- );
3452
- }
3453
- }
3454
- const fileConfig = loadUserConfig();
3455
- for (const field of DEPRECATED_CONFIG_FIELDS) {
3456
- if (fileConfig[field]) {
3457
- deprecatedWarned = true;
3458
- log(
3459
- `[atbash] "${field}" in ${getConfigPath()} is ignored \u2014 pass \`chain\` or \`network\` at construction instead`
3460
- );
3461
- }
3462
- }
3463
- }
3464
3440
  function getConfigDir() {
3465
3441
  const home2 = process.env.HOME || (0, import_node_os3.homedir)() || "";
3466
3442
  return (0, import_node_path3.join)(home2, ".config", "atbash");
@@ -3619,7 +3595,6 @@ var Atbash = class _Atbash {
3619
3595
  this._defaultChain = resolvedChain;
3620
3596
  this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
3621
3597
  this._forcedNetwork = forcedChainNetwork();
3622
- warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
3623
3598
  this.orgName = options.orgName;
3624
3599
  this.verifyPubKey = validated.verifyPubKey ?? void 0;
3625
3600
  this.orgEncryptionPubKey = options.orgEncryptionPubKey;
@@ -3877,18 +3852,15 @@ var Atbash = class _Atbash {
3877
3852
  if (!logResult.success || !logResult.toolCallId || !logResult.signedHex) {
3878
3853
  throw new Error(logResult.error || "Failed to sign log_tool_call");
3879
3854
  }
3880
- let signedJudgeAction;
3881
- if (!options.provider) {
3882
- const judgmentId = generateToolCallId();
3883
- signedJudgeAction = native.signJudgeAction(
3884
- judgmentId,
3885
- action,
3886
- context || "",
3887
- "",
3888
- this.auth.privkey,
3889
- brid
3890
- );
3891
- }
3855
+ const judgmentId = generateToolCallId();
3856
+ const signedJudgeAction = native.signJudgeAction(
3857
+ judgmentId,
3858
+ action,
3859
+ context || "",
3860
+ "",
3861
+ this.auth.privkey,
3862
+ brid
3863
+ );
3892
3864
  const body = {
3893
3865
  tool_call_id: logResult.toolCallId,
3894
3866
  agent_pubkey: this.auth.pubkey,
@@ -3897,10 +3869,8 @@ var Atbash = class _Atbash {
3897
3869
  };
3898
3870
  if (signedJudgeAction) body.signed_judge_action = signedJudgeAction;
3899
3871
  if (context) body.context = context;
3900
- if (options.provider) body.provider = options.provider;
3901
3872
  if (options.toolName) body.tool_name = options.toolName;
3902
3873
  if (options.toolArgsJson) body.tool_args_json = options.toolArgsJson;
3903
- if (options.model) body.model = options.model;
3904
3874
  if (options.resolved) body.resolved = options.resolved;
3905
3875
  if (options.mode) body.mode = options.mode;
3906
3876
  let resp;
@@ -4752,6 +4722,20 @@ function bootSyncFailureLine(cause) {
4752
4722
  );
4753
4723
  }
4754
4724
 
4725
+ // src-ts/memory/_gtv_bytes.ts
4726
+ function gtvToFfiSafe(value) {
4727
+ if (value instanceof Uint8Array) return Buffer.from(value).toString("hex");
4728
+ if (Array.isArray(value)) return value.map(gtvToFfiSafe);
4729
+ if (value !== null && typeof value === "object") {
4730
+ const out = {};
4731
+ for (const [key3, val] of Object.entries(value)) {
4732
+ out[key3] = gtvToFfiSafe(val);
4733
+ }
4734
+ return out;
4735
+ }
4736
+ return value;
4737
+ }
4738
+
4755
4739
  // src-ts/memory/crypto.ts
4756
4740
  async function deriveMemoryKey(privkey) {
4757
4741
  return native.deriveMemoryKey(privkey);
@@ -42971,16 +42955,25 @@ async function resolveChainOptsForOrg(opts, auth) {
42971
42955
  return opts?.chainOpts;
42972
42956
  }
42973
42957
  function materializeChain(chainOpts) {
42974
- if (chainOpts?.blockchainRid && chainOpts.nodeUrls) {
42958
+ const hasNodeUrls = chainOpts?.nodeUrls !== void 0;
42959
+ const hasBrid = chainOpts?.blockchainRid !== void 0;
42960
+ if (hasNodeUrls !== hasBrid) {
42961
+ throw new Error(
42962
+ 'chainOpts.nodeUrls and chainOpts.blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `network: "public" | "private"`, or set both.'
42963
+ );
42964
+ }
42965
+ if (hasNodeUrls && hasBrid) {
42975
42966
  return {
42976
42967
  nodeUrls: chainOpts.nodeUrls,
42977
42968
  blockchainRid: chainOpts.blockchainRid
42978
42969
  };
42979
42970
  }
42980
- const config2 = chainOpts?.network ? chainForNetwork(chainOpts.network) : PUBLIC_CHAIN;
42971
+ const config2 = chainForNetwork(
42972
+ chainOpts?.network ?? forcedChainNetwork() ?? "private"
42973
+ );
42981
42974
  return {
42982
- nodeUrls: chainOpts?.nodeUrls ?? config2.nodeUrls,
42983
- blockchainRid: chainOpts?.blockchainRid ?? config2.blockchainRid
42975
+ nodeUrls: config2.nodeUrls,
42976
+ blockchainRid: config2.blockchainRid
42984
42977
  };
42985
42978
  }
42986
42979
  async function buildChainClient(chainOpts) {
@@ -43030,7 +43023,7 @@ async function commitMemoryVersion(plaintext, auth, opts) {
43030
43023
  );
43031
43024
  }
43032
43025
  async function decryptRow(row, key3) {
43033
- const parsed = native.parseMemoryRow(row);
43026
+ const parsed = native.parseMemoryRow(gtvToFfiSafe(row));
43034
43027
  let content;
43035
43028
  let decryptError;
43036
43029
  try {
@@ -43070,7 +43063,7 @@ async function getActiveMemoryId(auth, chainOpts, filePath) {
43070
43063
  native.QUERY_GET_ACTIVE_MEMORY_ID,
43071
43064
  paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
43072
43065
  );
43073
- return native.parseActiveMemoryId(raw2);
43066
+ return native.parseActiveMemoryId(gtvToFfiSafe(raw2));
43074
43067
  }
43075
43068
  async function getRecentAgentMemory(auth, chainOpts, filePath) {
43076
43069
  const client = await buildChainClient(chainOpts);
@@ -43122,7 +43115,7 @@ async function getRollbackHistory(auth, chainOpts, filePath) {
43122
43115
  native.QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY,
43123
43116
  paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
43124
43117
  );
43125
- const parsed = native.parseRollbackRows(raw2 ?? []);
43118
+ const parsed = native.parseRollbackRows(gtvToFfiSafe(raw2 ?? []));
43126
43119
  return parsed.map((r2) => ({
43127
43120
  fromId: r2.from_id,
43128
43121
  toId: r2.to_id,
@@ -43434,6 +43427,66 @@ var MemoryGuardManager = class {
43434
43427
  rollbackMinScore;
43435
43428
  enforce;
43436
43429
  agentPubkeyHex;
43430
+ /**
43431
+ * Memoized org→chain resolution. Reads have to hit the SAME chain
43432
+ * writes did, so an org-scoped guard must resolve `orgName` to
43433
+ * network exactly like `commitMemoryVersion` does. Without this
43434
+ * cache the read path would either (a) hit the SDK-default chain
43435
+ * every time — silently returning "no active memory on chain" when
43436
+ * writes landed on the org's actual chain, or (b) hammer
43437
+ * `/api/org-network` on every read. `undefined` means "not yet
43438
+ * resolved"; a resolved `null` means "no org / use raw chainOpts".
43439
+ */
43440
+ _resolvedChainOpts = void 0;
43441
+ _resolveChainInflight;
43442
+ /**
43443
+ * Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
43444
+ * already does this for writes; without the same call on the read
43445
+ * path, a client on the SDK's baked default chain reads from the wrong
43446
+ * chain and reports "no active memory" for an agent whose writes did
43447
+ * land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
43448
+ * still wins (caller vouched for it); everything else honors the
43449
+ * dashboard's `org_networks` map.
43450
+ */
43451
+ async resolveChainOpts() {
43452
+ if (this._resolvedChainOpts !== void 0) {
43453
+ return this._resolvedChainOpts ?? void 0;
43454
+ }
43455
+ if (this._resolveChainInflight) return this._resolveChainInflight;
43456
+ this._resolveChainInflight = (async () => {
43457
+ if (this.opts.chainOpts?.blockchainRid) {
43458
+ this._resolvedChainOpts = this.opts.chainOpts;
43459
+ return this.opts.chainOpts;
43460
+ }
43461
+ if (!this.opts.orgName) {
43462
+ this._resolvedChainOpts = this.opts.chainOpts ?? null;
43463
+ return this.opts.chainOpts;
43464
+ }
43465
+ try {
43466
+ const atbash = new Atbash(this.opts.auth.privkey, {
43467
+ endpoint: this.opts.judgeEndpoint,
43468
+ verifyPubKey: this.opts.judgeVerifyPubKey,
43469
+ orgName: this.opts.orgName
43470
+ });
43471
+ const resolved = await atbash.resolveChainForOrg(this.opts.orgName);
43472
+ const chainOpts = { ...this.opts.chainOpts, network: resolved.network };
43473
+ this._resolvedChainOpts = chainOpts;
43474
+ this.logger.info(
43475
+ `[atbash] resolved org \u2192 chain \u2014 org=${this.opts.orgName} network=${resolved.network}`
43476
+ );
43477
+ return chainOpts;
43478
+ } catch (err) {
43479
+ const msg = err instanceof Error ? err.message : String(err);
43480
+ this.logger.warn(
43481
+ `[atbash] org \u2192 chain resolution failed (falling back to SDK default): ${msg}`
43482
+ );
43483
+ return this.opts.chainOpts;
43484
+ } finally {
43485
+ this._resolveChainInflight = void 0;
43486
+ }
43487
+ })();
43488
+ return this._resolveChainInflight;
43489
+ }
43437
43490
  /**
43438
43491
  * One-shot chain probe at plugin registration. Refreshes MEMORY.md
43439
43492
  * from chain when drifted and score passes threshold. Fire-and-forget
@@ -43441,11 +43494,12 @@ var MemoryGuardManager = class {
43441
43494
  */
43442
43495
  async runBootProbe() {
43443
43496
  try {
43497
+ const chainOpts = await this.resolveChainOpts();
43444
43498
  const seed = { activeId: null, checkedAt: 0 };
43445
43499
  const result = await syncLocalMemory(this.opts.auth, seed, {
43446
43500
  ttlMs: 0,
43447
43501
  force: true,
43448
- chainOpts: this.opts.chainOpts
43502
+ chainOpts
43449
43503
  });
43450
43504
  if (!result.drifted && result.pointer.activeId == null) {
43451
43505
  this.logger.info(
@@ -43584,9 +43638,10 @@ var MemoryGuardManager = class {
43584
43638
  const pointer = await this.pointerStore.get(this.agentPubkeyHex);
43585
43639
  let result;
43586
43640
  try {
43641
+ const chainOpts = await this.resolveChainOpts();
43587
43642
  result = await syncLocalMemory(this.opts.auth, pointer, {
43588
43643
  ttlMs: this.ttlMs,
43589
- chainOpts: this.opts.chainOpts
43644
+ chainOpts
43590
43645
  });
43591
43646
  } catch (err) {
43592
43647
  if (err instanceof MemoryIntegrityError) {
@@ -43820,6 +43875,7 @@ function diffMemorySnapshots(before, after) {
43820
43875
  getMemoryHistory,
43821
43876
  getRecentAgentMemory,
43822
43877
  getRollbackHistory,
43878
+ gtvToFfiSafe,
43823
43879
  guardMemoryWrite,
43824
43880
  isEnvelope,
43825
43881
  isValidPrivateKey,
package/dist/index.mjs CHANGED
@@ -3348,33 +3348,8 @@ var ENV_MAP = {
3348
3348
  // Same variable name the Hermes plugin already documents.
3349
3349
  judgeVerifyPubKey: "ATBASH_JUDGE_VERIFY_PUBKEY",
3350
3350
  defaultChainNetwork: "ATBASH_DEFAULT_CHAIN_NETWORK",
3351
- provider: "ATBASH_PROVIDER",
3352
- providerModel: "ATBASH_PROVIDER_MODEL",
3353
3351
  debug: "ATBASH_DEBUG"
3354
3352
  };
3355
- var DEPRECATED_ENV_VARS = ["ATBASH_BLOCKCHAIN_RID"];
3356
- var DEPRECATED_CONFIG_FIELDS = ["blockchainRid"];
3357
- var deprecatedWarned = false;
3358
- function warnDeprecatedEnvVarsOnce(log = console.warn) {
3359
- if (deprecatedWarned) return;
3360
- for (const name2 of DEPRECATED_ENV_VARS) {
3361
- if (process.env[name2]) {
3362
- deprecatedWarned = true;
3363
- log(
3364
- `[atbash] ${name2} is ignored \u2014 each org's chain is resolved from the dashboard; set ATBASH_DEFAULT_CHAIN_NETWORK=private only to pin everything to private`
3365
- );
3366
- }
3367
- }
3368
- const fileConfig = loadUserConfig();
3369
- for (const field of DEPRECATED_CONFIG_FIELDS) {
3370
- if (fileConfig[field]) {
3371
- deprecatedWarned = true;
3372
- log(
3373
- `[atbash] "${field}" in ${getConfigPath()} is ignored \u2014 pass \`chain\` or \`network\` at construction instead`
3374
- );
3375
- }
3376
- }
3377
- }
3378
3353
  function getConfigDir() {
3379
3354
  const home2 = process.env.HOME || homedir3() || "";
3380
3355
  return join3(home2, ".config", "atbash");
@@ -3533,7 +3508,6 @@ var Atbash = class _Atbash {
3533
3508
  this._defaultChain = resolvedChain;
3534
3509
  this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
3535
3510
  this._forcedNetwork = forcedChainNetwork();
3536
- warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
3537
3511
  this.orgName = options.orgName;
3538
3512
  this.verifyPubKey = validated.verifyPubKey ?? void 0;
3539
3513
  this.orgEncryptionPubKey = options.orgEncryptionPubKey;
@@ -3791,18 +3765,15 @@ var Atbash = class _Atbash {
3791
3765
  if (!logResult.success || !logResult.toolCallId || !logResult.signedHex) {
3792
3766
  throw new Error(logResult.error || "Failed to sign log_tool_call");
3793
3767
  }
3794
- let signedJudgeAction;
3795
- if (!options.provider) {
3796
- const judgmentId = generateToolCallId();
3797
- signedJudgeAction = native.signJudgeAction(
3798
- judgmentId,
3799
- action,
3800
- context || "",
3801
- "",
3802
- this.auth.privkey,
3803
- brid
3804
- );
3805
- }
3768
+ const judgmentId = generateToolCallId();
3769
+ const signedJudgeAction = native.signJudgeAction(
3770
+ judgmentId,
3771
+ action,
3772
+ context || "",
3773
+ "",
3774
+ this.auth.privkey,
3775
+ brid
3776
+ );
3806
3777
  const body = {
3807
3778
  tool_call_id: logResult.toolCallId,
3808
3779
  agent_pubkey: this.auth.pubkey,
@@ -3811,10 +3782,8 @@ var Atbash = class _Atbash {
3811
3782
  };
3812
3783
  if (signedJudgeAction) body.signed_judge_action = signedJudgeAction;
3813
3784
  if (context) body.context = context;
3814
- if (options.provider) body.provider = options.provider;
3815
3785
  if (options.toolName) body.tool_name = options.toolName;
3816
3786
  if (options.toolArgsJson) body.tool_args_json = options.toolArgsJson;
3817
- if (options.model) body.model = options.model;
3818
3787
  if (options.resolved) body.resolved = options.resolved;
3819
3788
  if (options.mode) body.mode = options.mode;
3820
3789
  let resp;
@@ -4666,6 +4635,20 @@ function bootSyncFailureLine(cause) {
4666
4635
  );
4667
4636
  }
4668
4637
 
4638
+ // src-ts/memory/_gtv_bytes.ts
4639
+ function gtvToFfiSafe(value) {
4640
+ if (value instanceof Uint8Array) return Buffer.from(value).toString("hex");
4641
+ if (Array.isArray(value)) return value.map(gtvToFfiSafe);
4642
+ if (value !== null && typeof value === "object") {
4643
+ const out = {};
4644
+ for (const [key3, val] of Object.entries(value)) {
4645
+ out[key3] = gtvToFfiSafe(val);
4646
+ }
4647
+ return out;
4648
+ }
4649
+ return value;
4650
+ }
4651
+
4669
4652
  // src-ts/memory/crypto.ts
4670
4653
  async function deriveMemoryKey(privkey) {
4671
4654
  return native.deriveMemoryKey(privkey);
@@ -42885,16 +42868,25 @@ async function resolveChainOptsForOrg(opts, auth) {
42885
42868
  return opts?.chainOpts;
42886
42869
  }
42887
42870
  function materializeChain(chainOpts) {
42888
- if (chainOpts?.blockchainRid && chainOpts.nodeUrls) {
42871
+ const hasNodeUrls = chainOpts?.nodeUrls !== void 0;
42872
+ const hasBrid = chainOpts?.blockchainRid !== void 0;
42873
+ if (hasNodeUrls !== hasBrid) {
42874
+ throw new Error(
42875
+ 'chainOpts.nodeUrls and chainOpts.blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `network: "public" | "private"`, or set both.'
42876
+ );
42877
+ }
42878
+ if (hasNodeUrls && hasBrid) {
42889
42879
  return {
42890
42880
  nodeUrls: chainOpts.nodeUrls,
42891
42881
  blockchainRid: chainOpts.blockchainRid
42892
42882
  };
42893
42883
  }
42894
- const config2 = chainOpts?.network ? chainForNetwork(chainOpts.network) : PUBLIC_CHAIN;
42884
+ const config2 = chainForNetwork(
42885
+ chainOpts?.network ?? forcedChainNetwork() ?? "private"
42886
+ );
42895
42887
  return {
42896
- nodeUrls: chainOpts?.nodeUrls ?? config2.nodeUrls,
42897
- blockchainRid: chainOpts?.blockchainRid ?? config2.blockchainRid
42888
+ nodeUrls: config2.nodeUrls,
42889
+ blockchainRid: config2.blockchainRid
42898
42890
  };
42899
42891
  }
42900
42892
  async function buildChainClient(chainOpts) {
@@ -42944,7 +42936,7 @@ async function commitMemoryVersion(plaintext, auth, opts) {
42944
42936
  );
42945
42937
  }
42946
42938
  async function decryptRow(row, key3) {
42947
- const parsed = native.parseMemoryRow(row);
42939
+ const parsed = native.parseMemoryRow(gtvToFfiSafe(row));
42948
42940
  let content;
42949
42941
  let decryptError;
42950
42942
  try {
@@ -42984,7 +42976,7 @@ async function getActiveMemoryId(auth, chainOpts, filePath) {
42984
42976
  native.QUERY_GET_ACTIVE_MEMORY_ID,
42985
42977
  paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
42986
42978
  );
42987
- return native.parseActiveMemoryId(raw2);
42979
+ return native.parseActiveMemoryId(gtvToFfiSafe(raw2));
42988
42980
  }
42989
42981
  async function getRecentAgentMemory(auth, chainOpts, filePath) {
42990
42982
  const client = await buildChainClient(chainOpts);
@@ -43036,7 +43028,7 @@ async function getRollbackHistory(auth, chainOpts, filePath) {
43036
43028
  native.QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY,
43037
43029
  paramsWithOptionalFilePath(q.agent_pubkey_hex, q.file_path)
43038
43030
  );
43039
- const parsed = native.parseRollbackRows(raw2 ?? []);
43031
+ const parsed = native.parseRollbackRows(gtvToFfiSafe(raw2 ?? []));
43040
43032
  return parsed.map((r2) => ({
43041
43033
  fromId: r2.from_id,
43042
43034
  toId: r2.to_id,
@@ -43348,6 +43340,66 @@ var MemoryGuardManager = class {
43348
43340
  rollbackMinScore;
43349
43341
  enforce;
43350
43342
  agentPubkeyHex;
43343
+ /**
43344
+ * Memoized org→chain resolution. Reads have to hit the SAME chain
43345
+ * writes did, so an org-scoped guard must resolve `orgName` to
43346
+ * network exactly like `commitMemoryVersion` does. Without this
43347
+ * cache the read path would either (a) hit the SDK-default chain
43348
+ * every time — silently returning "no active memory on chain" when
43349
+ * writes landed on the org's actual chain, or (b) hammer
43350
+ * `/api/org-network` on every read. `undefined` means "not yet
43351
+ * resolved"; a resolved `null` means "no org / use raw chainOpts".
43352
+ */
43353
+ _resolvedChainOpts = void 0;
43354
+ _resolveChainInflight;
43355
+ /**
43356
+ * Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
43357
+ * already does this for writes; without the same call on the read
43358
+ * path, a client on the SDK's baked default chain reads from the wrong
43359
+ * chain and reports "no active memory" for an agent whose writes did
43360
+ * land — on the org's actual chain. An explicit `chainOpts.blockchainRid`
43361
+ * still wins (caller vouched for it); everything else honors the
43362
+ * dashboard's `org_networks` map.
43363
+ */
43364
+ async resolveChainOpts() {
43365
+ if (this._resolvedChainOpts !== void 0) {
43366
+ return this._resolvedChainOpts ?? void 0;
43367
+ }
43368
+ if (this._resolveChainInflight) return this._resolveChainInflight;
43369
+ this._resolveChainInflight = (async () => {
43370
+ if (this.opts.chainOpts?.blockchainRid) {
43371
+ this._resolvedChainOpts = this.opts.chainOpts;
43372
+ return this.opts.chainOpts;
43373
+ }
43374
+ if (!this.opts.orgName) {
43375
+ this._resolvedChainOpts = this.opts.chainOpts ?? null;
43376
+ return this.opts.chainOpts;
43377
+ }
43378
+ try {
43379
+ const atbash = new Atbash(this.opts.auth.privkey, {
43380
+ endpoint: this.opts.judgeEndpoint,
43381
+ verifyPubKey: this.opts.judgeVerifyPubKey,
43382
+ orgName: this.opts.orgName
43383
+ });
43384
+ const resolved = await atbash.resolveChainForOrg(this.opts.orgName);
43385
+ const chainOpts = { ...this.opts.chainOpts, network: resolved.network };
43386
+ this._resolvedChainOpts = chainOpts;
43387
+ this.logger.info(
43388
+ `[atbash] resolved org \u2192 chain \u2014 org=${this.opts.orgName} network=${resolved.network}`
43389
+ );
43390
+ return chainOpts;
43391
+ } catch (err) {
43392
+ const msg = err instanceof Error ? err.message : String(err);
43393
+ this.logger.warn(
43394
+ `[atbash] org \u2192 chain resolution failed (falling back to SDK default): ${msg}`
43395
+ );
43396
+ return this.opts.chainOpts;
43397
+ } finally {
43398
+ this._resolveChainInflight = void 0;
43399
+ }
43400
+ })();
43401
+ return this._resolveChainInflight;
43402
+ }
43351
43403
  /**
43352
43404
  * One-shot chain probe at plugin registration. Refreshes MEMORY.md
43353
43405
  * from chain when drifted and score passes threshold. Fire-and-forget
@@ -43355,11 +43407,12 @@ var MemoryGuardManager = class {
43355
43407
  */
43356
43408
  async runBootProbe() {
43357
43409
  try {
43410
+ const chainOpts = await this.resolveChainOpts();
43358
43411
  const seed = { activeId: null, checkedAt: 0 };
43359
43412
  const result = await syncLocalMemory(this.opts.auth, seed, {
43360
43413
  ttlMs: 0,
43361
43414
  force: true,
43362
- chainOpts: this.opts.chainOpts
43415
+ chainOpts
43363
43416
  });
43364
43417
  if (!result.drifted && result.pointer.activeId == null) {
43365
43418
  this.logger.info(
@@ -43498,9 +43551,10 @@ var MemoryGuardManager = class {
43498
43551
  const pointer = await this.pointerStore.get(this.agentPubkeyHex);
43499
43552
  let result;
43500
43553
  try {
43554
+ const chainOpts = await this.resolveChainOpts();
43501
43555
  result = await syncLocalMemory(this.opts.auth, pointer, {
43502
43556
  ttlMs: this.ttlMs,
43503
- chainOpts: this.opts.chainOpts
43557
+ chainOpts
43504
43558
  });
43505
43559
  } catch (err) {
43506
43560
  if (err instanceof MemoryIntegrityError) {
@@ -43733,6 +43787,7 @@ export {
43733
43787
  getMemoryHistory,
43734
43788
  getRecentAgentMemory,
43735
43789
  getRollbackHistory,
43790
+ gtvToFfiSafe,
43736
43791
  guardMemoryWrite,
43737
43792
  isEnvelope,
43738
43793
  isValidPrivateKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atbash/sdk",
3
- "version": "0.15.1-dev.0",
3
+ "version": "0.16.0-dev.0",
4
4
  "description": "TypeScript SDK for Atbash — the safety layer that evaluates AI agent actions against operator-defined policies before execution.",
5
5
  "keywords": [
6
6
  "atbash",
@@ -89,10 +89,10 @@
89
89
  "typescript-eslint": "^8.62.1"
90
90
  },
91
91
  "optionalDependencies": {
92
- "@atbash/sdk-linux-x64-gnu": "0.15.1-dev.0",
93
- "@atbash/sdk-linux-arm64-gnu": "0.15.1-dev.0",
94
- "@atbash/sdk-linux-x64-musl": "0.15.1-dev.0",
95
- "@atbash/sdk-darwin-arm64": "0.15.1-dev.0",
96
- "@atbash/sdk-win32-x64-msvc": "0.15.1-dev.0"
92
+ "@atbash/sdk-linux-x64-gnu": "0.16.0-dev.0",
93
+ "@atbash/sdk-linux-arm64-gnu": "0.16.0-dev.0",
94
+ "@atbash/sdk-linux-x64-musl": "0.16.0-dev.0",
95
+ "@atbash/sdk-darwin-arm64": "0.16.0-dev.0",
96
+ "@atbash/sdk-win32-x64-msvc": "0.16.0-dev.0"
97
97
  }
98
98
  }