@atbash/sdk 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.mjs CHANGED
@@ -10,6 +10,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  if (typeof require !== "undefined") return require.apply(this, arguments);
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
+ var __esm = (fn, res) => function __init() {
14
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
+ };
13
16
  var __commonJS = (cb, mod2) => function __require2() {
14
17
  return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
15
18
  };
@@ -30,10 +33,28 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
30
33
  mod2
31
34
  ));
32
35
 
36
+ // <define:__ATBASH_CHROMIA_NODE_URLS__>
37
+ var define_ATBASH_CHROMIA_NODE_URLS_default;
38
+ var init_define_ATBASH_CHROMIA_NODE_URLS = __esm({
39
+ "<define:__ATBASH_CHROMIA_NODE_URLS__>"() {
40
+ define_ATBASH_CHROMIA_NODE_URLS_default = ["https://node0.testnet.chromia.com:7740", "https://node1.testnet.chromia.com:7740", "https://node3.testnet.chromia.com:7740"];
41
+ }
42
+ });
43
+
44
+ // <define:__ATBASH_PRIVATE_NODE_URLS__>
45
+ var define_ATBASH_PRIVATE_NODE_URLS_default;
46
+ var init_define_ATBASH_PRIVATE_NODE_URLS = __esm({
47
+ "<define:__ATBASH_PRIVATE_NODE_URLS__>"() {
48
+ define_ATBASH_PRIVATE_NODE_URLS_default = ["https://node0-pvn-testnet.dynamic.chromia.dev"];
49
+ }
50
+ });
51
+
33
52
  // (disabled):node_modules/buffer/index.js
34
53
  var require_buffer = __commonJS({
35
54
  "(disabled):node_modules/buffer/index.js"() {
36
55
  "use strict";
56
+ init_define_ATBASH_CHROMIA_NODE_URLS();
57
+ init_define_ATBASH_PRIVATE_NODE_URLS();
37
58
  }
38
59
  });
39
60
 
@@ -41,6 +62,8 @@ var require_buffer = __commonJS({
41
62
  var require_bn = __commonJS({
42
63
  "node_modules/bn.js/lib/bn.js"(exports, module) {
43
64
  "use strict";
65
+ init_define_ATBASH_CHROMIA_NODE_URLS();
66
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44
67
  (function(module2, exports2) {
45
68
  "use strict";
46
69
  function assert2(val, msg) {
@@ -2858,7 +2881,29 @@ var require_bn = __commonJS({
2858
2881
  }
2859
2882
  });
2860
2883
 
2884
+ // src-ts/index.ts
2885
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2886
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2887
+
2888
+ // src-ts/browser/native.ts
2889
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2890
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2891
+
2892
+ // node_modules/@noble/curves/secp256k1.js
2893
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2894
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2895
+
2896
+ // node_modules/@noble/hashes/sha2.js
2897
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2898
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2899
+
2900
+ // node_modules/@noble/hashes/_md.js
2901
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2902
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2903
+
2861
2904
  // node_modules/@noble/hashes/utils.js
2905
+ init_define_ATBASH_CHROMIA_NODE_URLS();
2906
+ init_define_ATBASH_PRIVATE_NODE_URLS();
2862
2907
  function isBytes(a) {
2863
2908
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
2864
2909
  }
@@ -3279,7 +3324,13 @@ var sha256 = /* @__PURE__ */ createHasher(
3279
3324
  /* @__PURE__ */ oidNist(1)
3280
3325
  );
3281
3326
 
3327
+ // node_modules/@noble/curves/abstract/curve.js
3328
+ init_define_ATBASH_CHROMIA_NODE_URLS();
3329
+ init_define_ATBASH_PRIVATE_NODE_URLS();
3330
+
3282
3331
  // node_modules/@noble/curves/utils.js
3332
+ init_define_ATBASH_CHROMIA_NODE_URLS();
3333
+ init_define_ATBASH_PRIVATE_NODE_URLS();
3283
3334
  var abytes2 = (value, length, title) => abytes(value, length, title);
3284
3335
  var anumber2 = anumber;
3285
3336
  var bytesToHex2 = bytesToHex;
@@ -3432,6 +3483,8 @@ function validateObject(object, fields = {}, optFields = {}) {
3432
3483
  }
3433
3484
 
3434
3485
  // node_modules/@noble/curves/abstract/modular.js
3486
+ init_define_ATBASH_CHROMIA_NODE_URLS();
3487
+ init_define_ATBASH_PRIVATE_NODE_URLS();
3435
3488
  var _0n2 = /* @__PURE__ */ BigInt(0);
3436
3489
  var _1n2 = /* @__PURE__ */ BigInt(1);
3437
3490
  var _2n = /* @__PURE__ */ BigInt(2);
@@ -4079,7 +4132,13 @@ function createKeygen(randomSecretKey, getPublicKey) {
4079
4132
  };
4080
4133
  }
4081
4134
 
4135
+ // node_modules/@noble/curves/abstract/weierstrass.js
4136
+ init_define_ATBASH_CHROMIA_NODE_URLS();
4137
+ init_define_ATBASH_PRIVATE_NODE_URLS();
4138
+
4082
4139
  // node_modules/@noble/hashes/hmac.js
4140
+ init_define_ATBASH_CHROMIA_NODE_URLS();
4141
+ init_define_ATBASH_PRIVATE_NODE_URLS();
4083
4142
  var _HMAC = class {
4084
4143
  oHash;
4085
4144
  iHash;
@@ -5111,6 +5170,8 @@ var Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
5111
5170
  var secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
5112
5171
 
5113
5172
  // node_modules/postchain-client/built/esm/index.js
5173
+ init_define_ATBASH_CHROMIA_NODE_URLS();
5174
+ init_define_ATBASH_PRIVATE_NODE_URLS();
5114
5175
  var import_bn = __toESM(require_bn(), 1);
5115
5176
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
5116
5177
  function getDefaultExportFromCjs(x) {
@@ -12065,7 +12126,7 @@ function requireBuffer_list() {
12065
12126
  }
12066
12127
  }, {
12067
12128
  key: "join",
12068
- value: function join2(s2) {
12129
+ value: function join3(s2) {
12069
12130
  if (this.length === 0) return "";
12070
12131
  var p = this.head;
12071
12132
  var ret = "" + p.data;
@@ -16147,7 +16208,7 @@ function requireBufferList() {
16147
16208
  this.head = this.tail = null;
16148
16209
  this.length = 0;
16149
16210
  };
16150
- BufferList2.prototype.join = function join2(s2) {
16211
+ BufferList2.prototype.join = function join3(s2) {
16151
16212
  if (this.length === 0) return "";
16152
16213
  var p = this.head;
16153
16214
  var ret = "" + p.data;
@@ -30311,7 +30372,7 @@ function requireBuffer() {
30311
30372
  }
30312
30373
  }
30313
30374
  buffer.EncoderBuffer = EncoderBuffer2;
30314
- EncoderBuffer2.prototype.join = function join2(out, offset) {
30375
+ EncoderBuffer2.prototype.join = function join3(out, offset) {
30315
30376
  if (!out)
30316
30377
  out = new Buffer5(this.length);
30317
30378
  if (!offset)
@@ -43233,17 +43294,11 @@ var index = /* @__PURE__ */ getDefaultExportFromCjs(builtExports);
43233
43294
 
43234
43295
  // src-ts/browser/native.ts
43235
43296
  var { Buffer: Buffer3, gtx: pcgtx } = index;
43236
- var PROD_ENDPOINT = "https://atbash.ai";
43237
- var PROD_BLOCKCHAIN_RID = "0163241D9AF137638E63E48EFCDE15510F38C2426F7AD5DC726AF60351BF4DFE";
43238
- var PROD_PRIVATE_BLOCKCHAIN_RID = "39FFD3557D0296CB2C57FDC6A3B8C024E95639CF4964DA08141AC20C6344D408";
43239
- var DEFAULT_CHROMIA_NODE_URLS_ARR = [
43240
- "https://node0.testnet.chromia.com:7740",
43241
- "https://node1.testnet.chromia.com:7740",
43242
- "https://node3.testnet.chromia.com:7740"
43243
- ];
43244
- var DEFAULT_PRIVATE_NODE_URLS_ARR = [
43245
- "https://node0-pvn-testnet.dynamic.chromia.dev"
43246
- ];
43297
+ var ATBASH_ENDPOINT = "https://atbash.ai";
43298
+ var ATBASH_BLOCKCHAIN_RID = "0163241D9AF137638E63E48EFCDE15510F38C2426F7AD5DC726AF60351BF4DFE";
43299
+ var ATBASH_PRIVATE_BLOCKCHAIN_RID = "39FFD3557D0296CB2C57FDC6A3B8C024E95639CF4964DA08141AC20C6344D408";
43300
+ var DEFAULT_CHROMIA_NODE_URLS_ARR = define_ATBASH_CHROMIA_NODE_URLS_default;
43301
+ var DEFAULT_PRIVATE_NODE_URLS_ARR = define_ATBASH_PRIVATE_NODE_URLS_default;
43247
43302
  var MERKLE_HASH_VERSION = 2;
43248
43303
  function stripHex(s2) {
43249
43304
  return s2.trim().replace(/^0x/i, "").toLowerCase();
@@ -43394,9 +43449,9 @@ var native = {
43394
43449
  deriveMemoryKey,
43395
43450
  encryptMemoryContent,
43396
43451
  decryptMemoryContent,
43397
- DEFAULT_BLOCKCHAIN_RID: PROD_BLOCKCHAIN_RID,
43398
- DEFAULT_PRIVATE_BLOCKCHAIN_RID: PROD_PRIVATE_BLOCKCHAIN_RID,
43399
- DEFAULT_ENDPOINT: PROD_ENDPOINT,
43452
+ DEFAULT_BLOCKCHAIN_RID: ATBASH_BLOCKCHAIN_RID,
43453
+ DEFAULT_PRIVATE_BLOCKCHAIN_RID: ATBASH_PRIVATE_BLOCKCHAIN_RID,
43454
+ DEFAULT_ENDPOINT: ATBASH_ENDPOINT,
43400
43455
  // Browser has no NAPI channel to Rust's HONEYCOMB_KEY — telemetry
43401
43456
  // silently no-ops. `HONEYCOMB_API_KEY` env var still overrides at runtime.
43402
43457
  HONEYCOMB_KEY: "",
@@ -43456,7 +43511,13 @@ var native = {
43456
43511
  ARG_ID: "id"
43457
43512
  };
43458
43513
 
43514
+ // src-ts/client.ts
43515
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43516
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43517
+
43459
43518
  // src-ts/random.ts
43519
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43520
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43460
43521
  function randomBytes4(size) {
43461
43522
  const buf = new Uint8Array(size);
43462
43523
  globalThis.crypto.getRandomValues(buf);
@@ -43471,7 +43532,13 @@ function randomHex(size) {
43471
43532
  return hex;
43472
43533
  }
43473
43534
 
43535
+ // src-ts/chain-config.ts
43536
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43537
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43538
+
43474
43539
  // src-ts/constants.ts
43540
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43541
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43475
43542
  var DEFAULT_ENDPOINT = native.DEFAULT_ENDPOINT;
43476
43543
  var DEFAULT_CHROMIA_NODE_URLS = Object.freeze(
43477
43544
  native.defaultChromiaNodeUrls()
@@ -43494,7 +43561,17 @@ var PRIVATE_CHAIN = {
43494
43561
  nodeUrls: DEFAULT_PRIVATE_NODE_URLS
43495
43562
  };
43496
43563
 
43564
+ // src-ts/browser/encrypted-toolcall.ts
43565
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43566
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43567
+
43568
+ // src-ts/browser/crypto-ecies.ts
43569
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43570
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43571
+
43497
43572
  // node_modules/@noble/hashes/hkdf.js
43573
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43574
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43498
43575
  function extract(hash3, ikm, salt) {
43499
43576
  ahash(hash3);
43500
43577
  if (salt === void 0)
@@ -43534,7 +43611,17 @@ function expand2(hash3, prk, info2, length = 32) {
43534
43611
  }
43535
43612
  var hkdf = (hash3, ikm, salt, info2, length) => expand2(hash3, extract(hash3, ikm, salt), info2, length);
43536
43613
 
43614
+ // node_modules/@noble/ciphers/aes.js
43615
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43616
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43617
+
43618
+ // node_modules/@noble/ciphers/_polyval.js
43619
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43620
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43621
+
43537
43622
  // node_modules/@noble/ciphers/utils.js
43623
+ init_define_ATBASH_CHROMIA_NODE_URLS();
43624
+ init_define_ATBASH_PRIVATE_NODE_URLS();
43538
43625
  function isBytes3(a) {
43539
43626
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
43540
43627
  }
@@ -44127,6 +44214,8 @@ function encryptedLength(plaintextByteLength) {
44127
44214
  }
44128
44215
 
44129
44216
  // src-ts/crypto/envelope.ts
44217
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44218
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44130
44219
  var PREFIX = "atb1";
44131
44220
  var SEPARATOR = ".";
44132
44221
  function toBase64(bytes) {
@@ -44259,6 +44348,8 @@ function signEncryptedToolCall(toolCallId, action, context, toolName, toolArgsJs
44259
44348
  }
44260
44349
 
44261
44350
  // src-ts/endpoint.ts
44351
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44352
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44262
44353
  function buildAllowedJudgeHosts() {
44263
44354
  return /* @__PURE__ */ new Set([
44264
44355
  "atbash.ai",
@@ -44309,6 +44400,8 @@ function validateJudgeEndpoint(judge) {
44309
44400
  }
44310
44401
 
44311
44402
  // src-ts/errors.ts
44403
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44404
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44312
44405
  var AtbashAPIError = class extends Error {
44313
44406
  /** HTTP status code (or 0 if the request never completed). */
44314
44407
  status;
@@ -44351,6 +44444,8 @@ function enrich(status, body, statusText, endpoint) {
44351
44444
  }
44352
44445
 
44353
44446
  // src-ts/http/client.ts
44447
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44448
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44354
44449
  var HttpClient = class {
44355
44450
  baseUrl;
44356
44451
  timeoutMs;
@@ -44383,11 +44478,73 @@ var HttpClient = class {
44383
44478
  });
44384
44479
  }
44385
44480
  async fetch(url, init4) {
44386
- return fetch(url, { ...init4, signal: AbortSignal.timeout(this.timeoutMs) });
44481
+ try {
44482
+ return await fetch(url, {
44483
+ ...init4,
44484
+ signal: AbortSignal.timeout(this.timeoutMs)
44485
+ });
44486
+ } catch (err) {
44487
+ throw classifyTransportError(err, url, init4.method ?? "GET", this.timeoutMs);
44488
+ }
44387
44489
  }
44388
44490
  };
44491
+ var HttpTransportError = class extends Error {
44492
+ kind;
44493
+ constructor(kind, message, options) {
44494
+ super(message, options);
44495
+ this.name = "HttpTransportError";
44496
+ this.kind = kind;
44497
+ }
44498
+ };
44499
+ function classifyTransportError(err, url, method, timeoutMs) {
44500
+ const name2 = err instanceof Error ? err.name : "";
44501
+ const cause = err instanceof Error ? err.cause : void 0;
44502
+ const code2 = cause && typeof cause === "object" && "code" in cause ? String(cause.code) : "";
44503
+ if (name2 === "TimeoutError") {
44504
+ return new HttpTransportError(
44505
+ "timeout",
44506
+ `${method} ${url} did not respond within ${timeoutMs} ms \u2014 the judge may be slow to boot or the LLM is under load; retry in a moment`,
44507
+ { cause: err }
44508
+ );
44509
+ }
44510
+ if (name2 === "AbortError") {
44511
+ return new HttpTransportError(
44512
+ "aborted",
44513
+ `${method} ${url} was cancelled by the caller`,
44514
+ { cause: err }
44515
+ );
44516
+ }
44517
+ if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
44518
+ return new HttpTransportError(
44519
+ "dns",
44520
+ `could not resolve the judge hostname (${url}) \u2014 check the endpoint and DNS`,
44521
+ { cause: err }
44522
+ );
44523
+ }
44524
+ if (code2 === "ECONNREFUSED") {
44525
+ return new HttpTransportError(
44526
+ "connect_refused",
44527
+ `judge refused the connection (${url}) \u2014 the service may be down or restarting`,
44528
+ { cause: err }
44529
+ );
44530
+ }
44531
+ if (code2 === "ECONNRESET" || code2 === "EPIPE") {
44532
+ return new HttpTransportError(
44533
+ "connection_reset",
44534
+ `judge dropped the connection mid-request (${url}) \u2014 retry once`,
44535
+ { cause: err }
44536
+ );
44537
+ }
44538
+ return new HttpTransportError(
44539
+ "unknown",
44540
+ `${method} ${url} failed: ${err instanceof Error ? err.message : String(err)}`,
44541
+ { cause: err }
44542
+ );
44543
+ }
44389
44544
 
44390
44545
  // src-ts/browser/keyLoader.ts
44546
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44547
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44391
44548
  var NOT_AVAILABLE = "keyLoader is not available in the browser bundle \u2014 pass `agentKey` explicitly to Atbash.fromConfig or use `new Atbash(privkey, opts)`.";
44392
44549
  function resolveKeyPath(_input) {
44393
44550
  throw new Error(NOT_AVAILABLE);
@@ -44397,6 +44554,8 @@ function loadAgentFromFile(_keyPath) {
44397
44554
  }
44398
44555
 
44399
44556
  // src-ts/normalize.ts
44557
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44558
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44400
44559
  function normalizeVerdict(raw2) {
44401
44560
  if (raw2 === null || raw2 === void 0) return "No verdict";
44402
44561
  const v = String(raw2).toUpperCase();
@@ -44422,6 +44581,8 @@ function pubkeyToHex(val) {
44422
44581
  }
44423
44582
 
44424
44583
  // src-ts/browser/opentel/telemetry.ts
44584
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44585
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44425
44586
  function setupTelemetry(_config) {
44426
44587
  }
44427
44588
  function recordCall(_functionName, _source, _agentPubkey) {
@@ -44434,6 +44595,8 @@ async function shutdownTelemetry() {
44434
44595
  }
44435
44596
 
44436
44597
  // src-ts/browser/userConfig.ts
44598
+ init_define_ATBASH_CHROMIA_NODE_URLS();
44599
+ init_define_ATBASH_PRIVATE_NODE_URLS();
44437
44600
  var NOT_AVAILABLE2 = "userConfig file I/O is not available in the browser bundle.";
44438
44601
  function getConfigDir() {
44439
44602
  throw new Error(NOT_AVAILABLE2);
@@ -44470,6 +44633,7 @@ var Atbash = class _Atbash {
44470
44633
  failClosed;
44471
44634
  /** Org key learned from the last agent-exists check, for this agent only. */
44472
44635
  _orgKeyFromChain = null;
44636
+ debug;
44473
44637
  logger;
44474
44638
  http;
44475
44639
  /**
@@ -44483,6 +44647,8 @@ var Atbash = class _Atbash {
44483
44647
  * server-side replay protection windows never expire it mid-session.
44484
44648
  */
44485
44649
  _authBearer = null;
44650
+ /** Guards `logEnvironmentOnce` — hosts construct several clients. */
44651
+ static environmentLogged = false;
44486
44652
  constructor(privkey, options = {}) {
44487
44653
  this.auth = native.loadAgent(privkey);
44488
44654
  this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "") || DEFAULT_ENDPOINT;
@@ -44492,8 +44658,10 @@ var Atbash = class _Atbash {
44492
44658
  this.verifyPubKey = options.verifyPubKey;
44493
44659
  this.orgEncryptionPubKey = options.orgEncryptionPubKey;
44494
44660
  this.failClosed = options.failClosed !== false;
44661
+ this.debug = options.debug === true;
44495
44662
  this.logger = options.logger ?? {};
44496
- this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 3e4);
44663
+ this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 6e4);
44664
+ this.logEnvironmentOnce();
44497
44665
  if (this.endpoint !== DEFAULT_ENDPOINT) {
44498
44666
  this.logger.warn?.("[atbash] running on non-default judge endpoint", {
44499
44667
  endpoint: this.endpoint,
@@ -44501,6 +44669,31 @@ var Atbash = class _Atbash {
44501
44669
  });
44502
44670
  }
44503
44671
  }
44672
+ /**
44673
+ * Say which environment this build talks to, once per process.
44674
+ *
44675
+ * The endpoint and both chain RIDs are compiled in, chosen by the npm tag,
44676
+ * and no configuration repoints a released build. So installing the build
44677
+ * for the wrong environment is invisible: the plugin loads, the hook fires,
44678
+ * and every judge call fails because the agent does not exist on the chain
44679
+ * this build targets. Organisation names are not unique across environments
44680
+ * either, so an org resolving is not evidence the build is right.
44681
+ */
44682
+ logEnvironmentOnce() {
44683
+ if (_Atbash.environmentLogged) return;
44684
+ _Atbash.environmentLogged = true;
44685
+ const brief = (rid) => rid ? `${rid.slice(0, 8)}\u2026` : "(unset)";
44686
+ this.logger.info?.(
44687
+ `[atbash] environment \u2014 judge=${this.endpoint} publicChain=${brief(native.DEFAULT_BLOCKCHAIN_RID)} privateChain=${brief(native.DEFAULT_PRIVATE_BLOCKCHAIN_RID)} activeChain=${brief(this.blockchainRid)} responseSignatureCheck=${this.verifyPubKey ? "on" : "off"}`,
44688
+ {
44689
+ judgeEndpoint: this.endpoint,
44690
+ publicBlockchainRid: native.DEFAULT_BLOCKCHAIN_RID,
44691
+ privateBlockchainRid: native.DEFAULT_PRIVATE_BLOCKCHAIN_RID,
44692
+ activeBlockchainRid: this.blockchainRid,
44693
+ responseSignatureCheck: Boolean(this.verifyPubKey)
44694
+ }
44695
+ );
44696
+ }
44504
44697
  /**
44505
44698
  * Construct from resolved config: explicit overrides → env vars → the
44506
44699
  * `~/.config/atbash/config.json` file (see userConfig.resolve). The private
@@ -44524,6 +44717,9 @@ var Atbash = class _Atbash {
44524
44717
  orgName: options.orgName,
44525
44718
  verifyPubKey: validated.verifyPubKey ?? void 0,
44526
44719
  failClosed: options.failClosed,
44720
+ // ATBASH_DEBUG lets an operator turn diagnostics on without editing a
44721
+ // host's plugin config, which is usually the harder half.
44722
+ debug: options.debug ?? /^(1|true|yes)$/i.test(resolve("debug")),
44527
44723
  logger: options.logger
44528
44724
  });
44529
44725
  }
@@ -44623,11 +44819,15 @@ var Atbash = class _Atbash {
44623
44819
  * response bytes via the Rust core's `verifySignature`.
44624
44820
  */
44625
44821
  async judgeAction(action, context = "", options = {}) {
44626
- return this.track(
44627
- "judgeAction",
44628
- this.auth.pubkey,
44629
- () => this._judgeAction(action, context, options)
44630
- );
44822
+ return this.track("judgeAction", this.auth.pubkey, async () => {
44823
+ try {
44824
+ return await this._judgeAction(action, context, options);
44825
+ } catch (err) {
44826
+ if (!isEncryptionStateMismatch(err)) throw err;
44827
+ this._orgKeyFromChain = null;
44828
+ return await this._judgeAction(action, context, options);
44829
+ }
44830
+ });
44631
44831
  }
44632
44832
  async _judgeAction(action, context, options) {
44633
44833
  if (!action?.trim()) {
@@ -44765,8 +44965,9 @@ var Atbash = class _Atbash {
44765
44965
  });
44766
44966
  if (result.verdict === "No verdict") {
44767
44967
  if (result.status !== "logged") {
44768
- return this.fail(
44968
+ return this.failJudge(
44769
44969
  `judge returned no verdict without an audit-tier marker (status: ${result.status || "absent"})`,
44970
+ void 0,
44770
44971
  result.toolCallId
44771
44972
  );
44772
44973
  }
@@ -44818,16 +45019,38 @@ var Atbash = class _Atbash {
44818
45019
  toolCallId: result.toolCallId
44819
45020
  };
44820
45021
  }
44821
- return this.fail(
45022
+ return this.failJudge(
44822
45023
  "unrecognized action_type from judge",
45024
+ void 0,
44823
45025
  result.toolCallId
44824
45026
  );
44825
45027
  } catch (err) {
44826
- const message = errorMessage(err);
44827
- this.logger.warn?.("[atbash] judge API failed", { reason: message });
44828
- return this.fail(message);
45028
+ return this.failJudge(errorMessage(err), err);
44829
45029
  }
44830
45030
  }
45031
+ /**
45032
+ * One exit for every judge failure.
45033
+ *
45034
+ * Status and reason go in the *message*, not only in the meta object: hosts
45035
+ * print the message and drop the meta, which is why this read as a bare
45036
+ * "judge API failed" while the judge was answering with a precise reason.
45037
+ * The response body follows only under `debug`, since it can echo the action.
45038
+ */
45039
+ failJudge(reason, cause, toolCallId) {
45040
+ const api2 = cause instanceof AtbashAPIError ? cause : null;
45041
+ const status = api2 ? ` status=${api2.status || "no-response"}` : "";
45042
+ const body = this.debug && api2?.body ? ` body=${truncate(api2.body, 500)}` : "";
45043
+ this.logger.warn?.(
45044
+ `[atbash] judge API failed \u2014${status} reason=${truncate(reason, 300)}${body}`,
45045
+ {
45046
+ reason,
45047
+ ...api2 ? { status: api2.status, body: api2.body } : {},
45048
+ endpoint: this.endpoint,
45049
+ ...toolCallId ? { toolCallId } : {}
45050
+ }
45051
+ );
45052
+ return this.fail(reason, toolCallId);
45053
+ }
44831
45054
  fail(reason, toolCallId) {
44832
45055
  return { allow: !this.failClosed, verdict: "ERROR", reason, toolCallId };
44833
45056
  }
@@ -45168,8 +45391,27 @@ var Atbash = class _Atbash {
45168
45391
  this.endpoint
45169
45392
  );
45170
45393
  }
45171
- /** Wrap a *transport* failure (fetch threw, no response) as an AtbashAPIError. */
45394
+ /**
45395
+ * Wrap a transport failure (fetch threw, no response) as an AtbashAPIError.
45396
+ *
45397
+ * `HttpTransportError.kind` names the cause; the message is already
45398
+ * human-readable. `debug` echoes the original exception so operators can
45399
+ * cross-reference with node / undici logs when a class doesn't match.
45400
+ */
45172
45401
  transportError(err) {
45402
+ if (err instanceof HttpTransportError) {
45403
+ if (this.debug) {
45404
+ this.logger.warn?.(
45405
+ `[atbash] transport failed \u2014 kind=${err.kind}`,
45406
+ {
45407
+ kind: err.kind,
45408
+ cause: err.cause instanceof Error ? err.cause.message : String(err.cause ?? ""),
45409
+ endpoint: this.endpoint
45410
+ }
45411
+ );
45412
+ }
45413
+ return new AtbashAPIError(0, err.message, "", this.endpoint);
45414
+ }
45173
45415
  return new AtbashAPIError(0, errorMessage(err), "", this.endpoint);
45174
45416
  }
45175
45417
  async json(resp) {
@@ -45301,6 +45543,10 @@ async function safeText(resp) {
45301
45543
  function errorMessage(err) {
45302
45544
  return err instanceof Error ? err.message : String(err);
45303
45545
  }
45546
+ function isEncryptionStateMismatch(err) {
45547
+ const msg = errorMessage(err);
45548
+ return msg.includes("must be a valid encryption envelope") || msg.includes("must be plaintext");
45549
+ }
45304
45550
  function stringifyArgs(args) {
45305
45551
  if (args === null || args === void 0) return "";
45306
45552
  if (typeof args === "string") return args;
@@ -45311,12 +45557,37 @@ function stringifyArgs(args) {
45311
45557
  }
45312
45558
  }
45313
45559
  var MAX_ACTION_LEN = 4e3;
45314
- function truncate(text) {
45315
- if (text.length <= MAX_ACTION_LEN) return text;
45316
- return text.slice(0, MAX_ACTION_LEN) + "\u2026";
45560
+ function truncate(text, limit = MAX_ACTION_LEN) {
45561
+ if (text.length <= limit) return text;
45562
+ return text.slice(0, limit) + "\u2026";
45563
+ }
45564
+
45565
+ // src-ts/key-path.ts
45566
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45567
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45568
+ import { homedir } from "os";
45569
+ import { join as join2 } from "path";
45570
+ var KEY_DIR_REL = ".config/atbash";
45571
+ var KEY_FILENAMES = ["guard-client-key", "atbash-client-key"];
45572
+ function home() {
45573
+ return process.env.HOME || homedir() || "";
45574
+ }
45575
+ function expandHome(p) {
45576
+ if (!p.startsWith("~/")) return p;
45577
+ return join2(home(), p.slice(2));
45578
+ }
45579
+ function keyPathCandidates() {
45580
+ return KEY_FILENAMES.map((name2) => join2(home(), KEY_DIR_REL, name2));
45581
+ }
45582
+ function chooseKeyPath(input, exists) {
45583
+ if (input) return expandHome(input);
45584
+ const candidates = keyPathCandidates();
45585
+ return candidates.find(exists) ?? candidates[0];
45317
45586
  }
45318
45587
 
45319
45588
  // src-ts/redact.ts
45589
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45590
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45320
45591
  function redactJsonStrings(value) {
45321
45592
  if (typeof value === "string") {
45322
45593
  return native.redactSecrets(value).redacted;
@@ -45335,6 +45606,8 @@ function redactJsonStrings(value) {
45335
45606
  }
45336
45607
 
45337
45608
  // src-ts/signature.ts
45609
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45610
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45338
45611
  function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
45339
45612
  if (!signatureHex) {
45340
45613
  return { ok: false, reason: "missing X-Atbash-Signature header" };
@@ -45356,7 +45629,26 @@ function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
45356
45629
  };
45357
45630
  }
45358
45631
 
45632
+ // src-ts/memory/boot-sync-message.ts
45633
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45634
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45635
+ var BOOT_SYNC_HINT = "check the chain endpoint and orgName if the cause above does not explain it";
45636
+ function bootSyncFailureLine(cause) {
45637
+ const reason = cause instanceof Error ? cause.message : String(cause);
45638
+ const trimmed = reason.trim();
45639
+ return trimmed ? `[atbash] boot memory sync failed: ${trimmed}` : (
45640
+ // No cause to show: fall back to the advice rather than a bare colon.
45641
+ `[atbash] boot memory sync failed \u2014 ${BOOT_SYNC_HINT}`
45642
+ );
45643
+ }
45644
+
45645
+ // src-ts/memory/index.ts
45646
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45647
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45648
+
45359
45649
  // src-ts/browser/memory-crypto.ts
45650
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45651
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45360
45652
  var { Buffer: Buffer4 } = index;
45361
45653
  var HKDF_INFO = new TextEncoder().encode("atbash:memory-encryption");
45362
45654
  var KEY_LEN = 32;
@@ -45431,6 +45723,8 @@ async function decryptMemoryContent2(ciphertext, nonce, key3) {
45431
45723
  }
45432
45724
 
45433
45725
  // src-ts/browser/memory-scan.ts
45726
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45727
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45434
45728
  var STUB_MSG2 = "not available in @atbash/sdk browser bundle \u2014 scan memory server-side";
45435
45729
  async function scanMemory(_entry, _auth, _opts) {
45436
45730
  throw new Error(`scanMemory ${STUB_MSG2}`);
@@ -45440,6 +45734,8 @@ async function scanMemoryBatch(_entries, _auth, _opts) {
45440
45734
  }
45441
45735
 
45442
45736
  // src-ts/browser/memory-chain.ts
45737
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45738
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45443
45739
  var STUB_MSG3 = "not available in @atbash/sdk browser bundle \u2014 commit/rollback memory server-side";
45444
45740
  async function commitMemoryVersion(_plaintext, _auth, _opts) {
45445
45741
  throw new Error(`commitMemoryVersion ${STUB_MSG3}`);
@@ -45467,6 +45763,8 @@ async function rollbackMemory(_toId, _reason, _auth, _opts) {
45467
45763
  }
45468
45764
 
45469
45765
  // src-ts/browser/memory-classifier.ts
45766
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45767
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45470
45768
  var STUB_MSG4 = "not available in @atbash/sdk browser bundle \u2014 classify memory writes server-side";
45471
45769
  var DEFAULT_MEMORY_WRITE_TOOL_NAMES = [
45472
45770
  "write",
@@ -45489,6 +45787,8 @@ function classifyMemoryWrite(_event, _ctx, _opts = {}) {
45489
45787
  }
45490
45788
 
45491
45789
  // src-ts/memory/guard.ts
45790
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45791
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45492
45792
  function emitDebugProbe(event, ctx, memEntry, logger2) {
45493
45793
  if (!logger2?.info) return;
45494
45794
  const ev = event ?? {};
@@ -45585,6 +45885,8 @@ async function guardMemoryWrite(input) {
45585
45885
  }
45586
45886
 
45587
45887
  // src-ts/memory/sync.ts
45888
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45889
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45588
45890
  var MemoryIntegrityError = class extends Error {
45589
45891
  constructor(id, reason) {
45590
45892
  super(`memory integrity check failed on id ${id}: ${reason}`);
@@ -45617,6 +45919,8 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
45617
45919
  }
45618
45920
 
45619
45921
  // src-ts/browser/memory-pointer-store.ts
45922
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45923
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45620
45924
  var unavailable = (name2) => {
45621
45925
  throw new Error(`${name2} is not available in the browser bundle`);
45622
45926
  };
@@ -45635,6 +45939,8 @@ function defaultPointerPath(_workspaceDir) {
45635
45939
  }
45636
45940
 
45637
45941
  // src-ts/browser/memory-file-logger.ts
45942
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45943
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45638
45944
  var unavailable2 = (name2) => {
45639
45945
  throw new Error(`${name2} is not available in the browser bundle`);
45640
45946
  };
@@ -45646,6 +45952,8 @@ function defaultPluginLogPath(_workspaceDir) {
45646
45952
  }
45647
45953
 
45648
45954
  // src-ts/browser/memory-read-classifier.ts
45955
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45956
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45649
45957
  var STUB_MSG5 = "not available in @atbash/sdk browser bundle \u2014 classify memory reads server-side";
45650
45958
  var DEFAULT_MEMORY_READ_TOOL_NAMES = [
45651
45959
  "memory_search",
@@ -45656,6 +45964,8 @@ function classifyMemoryRead(_event, _ctx, _opts = {}) {
45656
45964
  }
45657
45965
 
45658
45966
  // src-ts/browser/memory-guard-manager.ts
45967
+ init_define_ATBASH_CHROMIA_NODE_URLS();
45968
+ init_define_ATBASH_PRIVATE_NODE_URLS();
45659
45969
  var unavailable3 = (name2) => {
45660
45970
  throw new Error(`${name2} is not available in the browser bundle`);
45661
45971
  };
@@ -45737,6 +46047,7 @@ function diffMemorySnapshots2(before, after) {
45737
46047
  export {
45738
46048
  Atbash,
45739
46049
  AtbashAPIError,
46050
+ BOOT_SYNC_HINT,
45740
46051
  DEFAULT_BLOCKCHAIN_RID,
45741
46052
  DEFAULT_CHROMIA_NODE_URLS,
45742
46053
  DEFAULT_ENDPOINT,
@@ -45744,11 +46055,16 @@ export {
45744
46055
  DEFAULT_MEMORY_READ_TOOL_NAMES,
45745
46056
  DEFAULT_MEMORY_WRITE_TOOL_NAMES,
45746
46057
  EciesDomain,
46058
+ HttpClient,
46059
+ HttpTransportError,
46060
+ KEY_FILENAMES,
45747
46061
  MemoryGuardManager,
45748
46062
  MemoryIntegrityError,
45749
46063
  PointerStore,
45750
46064
  SignatureVerificationError,
46065
+ bootSyncFailureLine,
45751
46066
  buildAllowedJudgeHosts,
46067
+ chooseKeyPath,
45752
46068
  claimHashHex,
45753
46069
  classifyMemoryRead,
45754
46070
  classifyMemoryWrite,
@@ -45783,6 +46099,7 @@ export {
45783
46099
  isEnvelope,
45784
46100
  isValidPrivateKey2 as isValidPrivateKey,
45785
46101
  keyFingerprintOf,
46102
+ keyPathCandidates,
45786
46103
  loadAgent2 as loadAgent,
45787
46104
  loadAgentFromFile,
45788
46105
  loadUserConfig,