@atbash/sdk 0.16.2-dev.0 → 0.16.3-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.
@@ -1079,6 +1079,13 @@ interface ClassifyMemoryWriteOptions {
1079
1079
  *
1080
1080
  * Empty-content writes return `null`: they can't carry a poisoning
1081
1081
  * payload, and the regular audit path still sees them.
1082
+ *
1083
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1084
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1085
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1086
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1087
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1088
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1082
1089
  */
1083
1090
  declare function classifyMemoryWrite(event: unknown, ctx: unknown, opts?: ClassifyMemoryWriteOptions): MemoryEntry | null;
1084
1091
 
@@ -1247,6 +1254,13 @@ interface ClassifyMemoryReadOptions {
1247
1254
  * Caller-supplied `patterns` are MERGED with the defaults (matches
1248
1255
  * Node's original behavior — extending in one plugin doesn't disable
1249
1256
  * standard coverage).
1257
+ *
1258
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1259
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1260
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1261
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1262
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1263
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1250
1264
  */
1251
1265
  declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
1252
1266
 
package/dist/browser.mjs CHANGED
@@ -44528,6 +44528,13 @@ function classifyTransportError(err, url, method, timeoutMs) {
44528
44528
  { cause: err }
44529
44529
  );
44530
44530
  }
44531
+ if (code2 === "UND_ERR_CONNECT_TIMEOUT") {
44532
+ return new HttpTransportError(
44533
+ "timeout",
44534
+ `${method} ${url} could not establish a connection before the transport deadline \u2014 check the endpoint and network`,
44535
+ { cause: err }
44536
+ );
44537
+ }
44531
44538
  if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
44532
44539
  return new HttpTransportError(
44533
44540
  "dns",
@@ -44792,7 +44799,6 @@ var Atbash = class _Atbash {
44792
44799
  try {
44793
44800
  setupTelemetry({
44794
44801
  enabled: true,
44795
- source: "sdk",
44796
44802
  endpoint: this.endpoint,
44797
44803
  getAuthHeaders: () => this.authHeaders()
44798
44804
  });
@@ -46142,7 +46148,22 @@ async function guardMemoryWrite(input) {
46142
46148
  debug: debug2 = false,
46143
46149
  logger: logger2
46144
46150
  } = input;
46145
- const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
46151
+ let memEntry;
46152
+ try {
46153
+ memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
46154
+ } catch (err) {
46155
+ const why = err instanceof Error ? err.message : String(err);
46156
+ logger2?.warn?.("[atbash] memory classifier refused this tool call's input", { reason: why });
46157
+ if (!enforce) return { handled: false };
46158
+ return {
46159
+ handled: true,
46160
+ decision: {
46161
+ allow: false,
46162
+ block: true,
46163
+ reason: `Memory protection could not read this tool call (${why}); blocked because it could not be checked.`
46164
+ }
46165
+ };
46166
+ }
46146
46167
  if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
46147
46168
  if (!memEntry) return { handled: false };
46148
46169
  let scanResult;
package/dist/index.d.mts CHANGED
@@ -1079,6 +1079,13 @@ interface ClassifyMemoryWriteOptions {
1079
1079
  *
1080
1080
  * Empty-content writes return `null`: they can't carry a poisoning
1081
1081
  * payload, and the regular audit path still sees them.
1082
+ *
1083
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1084
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1085
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1086
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1087
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1088
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1082
1089
  */
1083
1090
  declare function classifyMemoryWrite(event: unknown, ctx: unknown, opts?: ClassifyMemoryWriteOptions): MemoryEntry | null;
1084
1091
 
@@ -1247,6 +1254,13 @@ interface ClassifyMemoryReadOptions {
1247
1254
  * Caller-supplied `patterns` are MERGED with the defaults (matches
1248
1255
  * Node's original behavior — extending in one plugin doesn't disable
1249
1256
  * standard coverage).
1257
+ *
1258
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1259
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1260
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1261
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1262
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1263
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1250
1264
  */
1251
1265
  declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
1252
1266
 
package/dist/index.d.ts CHANGED
@@ -1079,6 +1079,13 @@ interface ClassifyMemoryWriteOptions {
1079
1079
  *
1080
1080
  * Empty-content writes return `null`: they can't carry a poisoning
1081
1081
  * payload, and the regular audit path still sees them.
1082
+ *
1083
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1084
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1085
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1086
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1087
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1088
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1082
1089
  */
1083
1090
  declare function classifyMemoryWrite(event: unknown, ctx: unknown, opts?: ClassifyMemoryWriteOptions): MemoryEntry | null;
1084
1091
 
@@ -1247,6 +1254,13 @@ interface ClassifyMemoryReadOptions {
1247
1254
  * Caller-supplied `patterns` are MERGED with the defaults (matches
1248
1255
  * Node's original behavior — extending in one plugin doesn't disable
1249
1256
  * standard coverage).
1257
+ *
1258
+ * THROWS on host input it cannot read without side effects: a proxy, an accessor where a data
1259
+ * property is expected, a value with no safe projection, or one past the size bounds. Refusing is
1260
+ * deliberate - a silent `null` would report "not a memory write" for a call nobody could classify,
1261
+ * and memory protection would be skipped exactly where the input was strange. Callers that sit in a
1262
+ * host hook MUST catch it and turn it into a decision; `guardMemoryWrite` and
1263
+ * `MemoryGuardManager.handleBeforeToolCall` already do.
1250
1264
  */
1251
1265
  declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
1252
1266
 
package/dist/index.js CHANGED
@@ -3190,6 +3190,13 @@ function classifyTransportError(err, url, method, timeoutMs) {
3190
3190
  { cause: err }
3191
3191
  );
3192
3192
  }
3193
+ if (code2 === "UND_ERR_CONNECT_TIMEOUT") {
3194
+ return new HttpTransportError(
3195
+ "timeout",
3196
+ `${method} ${url} could not establish a connection before the transport deadline \u2014 check the endpoint and network`,
3197
+ { cause: err }
3198
+ );
3199
+ }
3193
3200
  if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
3194
3201
  return new HttpTransportError(
3195
3202
  "dns",
@@ -3354,6 +3361,7 @@ var meterProvider = null;
3354
3361
  var callCounter = null;
3355
3362
  var durationHistogram = null;
3356
3363
  var defaultSource = "sdk";
3364
+ var sourceExplicitlySet = false;
3357
3365
  function isTelemetryOptedOut() {
3358
3366
  const disabled = process.env.ATBASH_TELEMETRY_DISABLED?.trim().toLowerCase();
3359
3367
  if (disabled && ["1", "true", "yes", "on"].includes(disabled)) {
@@ -3377,11 +3385,14 @@ function autoInit() {
3377
3385
  }
3378
3386
  function setupTelemetry(config2) {
3379
3387
  if (!config2.enabled) return;
3380
- if (meterProvider) return;
3381
3388
  if (isTelemetryOptedOut()) return;
3389
+ if (config2.source && !sourceExplicitlySet) {
3390
+ defaultSource = config2.source;
3391
+ sourceExplicitlySet = true;
3392
+ }
3393
+ if (meterProvider) return;
3382
3394
  if (!config2.endpoint || !config2.getAuthHeaders) return;
3383
3395
  if (/^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0)(:|\/|$)/i.test(config2.endpoint)) return;
3384
- defaultSource = config2.source ?? "sdk";
3385
3396
  const proxyUrl = `${config2.endpoint.replace(/\/+$/, "")}/api/telemetry`;
3386
3397
  const getAuthHeaders = config2.getAuthHeaders;
3387
3398
  const exporter = new import_exporter_metrics_otlp_http.OTLPMetricExporter({
@@ -3434,6 +3445,8 @@ async function shutdownTelemetry() {
3434
3445
  meterProvider = null;
3435
3446
  callCounter = null;
3436
3447
  durationHistogram = null;
3448
+ defaultSource = "sdk";
3449
+ sourceExplicitlySet = false;
3437
3450
  }
3438
3451
 
3439
3452
  // src-ts/userConfig.ts
@@ -3624,7 +3637,6 @@ var Atbash = class _Atbash {
3624
3637
  try {
3625
3638
  setupTelemetry({
3626
3639
  enabled: true,
3627
- source: "sdk",
3628
3640
  endpoint: this.endpoint,
3629
3641
  getAuthHeaders: () => this.authHeaders()
3630
3642
  });
@@ -35320,9 +35332,9 @@ var ZodUnion = class extends ZodType {
35320
35332
  }
35321
35333
  };
35322
35334
  types.ZodUnion = ZodUnion;
35323
- ZodUnion.create = (types2, params) => {
35335
+ ZodUnion.create = (types3, params) => {
35324
35336
  return new ZodUnion({
35325
- options: types2,
35337
+ options: types3,
35326
35338
  typeName: ZodFirstPartyTypeKind.ZodUnion,
35327
35339
  ...processCreateParams(params)
35328
35340
  });
@@ -38779,9 +38791,9 @@ _nodeUtil.exports;
38779
38791
  var freeProcess = moduleExports && freeGlobal2.process;
38780
38792
  var nodeUtil2 = (function() {
38781
38793
  try {
38782
- var types2 = freeModule && freeModule.require && freeModule.require("util").types;
38783
- if (types2) {
38784
- return types2;
38794
+ var types3 = freeModule && freeModule.require && freeModule.require("util").types;
38795
+ if (types3) {
38796
+ return types3;
38785
38797
  }
38786
38798
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
38787
38799
  } catch (e) {
@@ -43161,12 +43173,96 @@ async function rollbackMemory(toId, reason, auth, opts) {
43161
43173
  }
43162
43174
 
43163
43175
  // src-ts/memory/_json_safe.ts
43176
+ var import_node_util = require("util");
43177
+ var replacementKeys = [
43178
+ "newText",
43179
+ "new_string",
43180
+ "new_str",
43181
+ "newStr",
43182
+ "replacement"
43183
+ ];
43184
+ var argumentKeys = [
43185
+ "file_path",
43186
+ "path",
43187
+ "filename",
43188
+ "target",
43189
+ "file",
43190
+ "filePath",
43191
+ "content",
43192
+ ...replacementKeys,
43193
+ "value",
43194
+ "text"
43195
+ ];
43196
+ var maxPrototypeDepth = 32;
43197
+ var maxEditSlots = 65536;
43198
+ var maxTextUnits = 16 * 1024 * 1024;
43199
+ function invalid() {
43200
+ throw new TypeError("Unreadable or unsupported memory classifier input");
43201
+ }
43202
+ function dataProperty(value, key3) {
43203
+ let current = value;
43204
+ for (let depth = 0; current !== null; depth++) {
43205
+ if (depth >= maxPrototypeDepth || import_node_util.types.isProxy(current)) invalid();
43206
+ const descriptor = Object.getOwnPropertyDescriptor(current, key3);
43207
+ if (descriptor) {
43208
+ if (!("value" in descriptor)) invalid();
43209
+ return descriptor.value;
43210
+ }
43211
+ current = Object.getPrototypeOf(current);
43212
+ }
43213
+ return void 0;
43214
+ }
43164
43215
  function toJsonSafe(value) {
43165
- try {
43166
- return JSON.parse(JSON.stringify(value ?? null));
43167
- } catch {
43168
- return null;
43216
+ let textUnits = 0;
43217
+ function scalar(input) {
43218
+ if (input == null) return null;
43219
+ if (typeof input === "string") {
43220
+ textUnits += input.length;
43221
+ if (textUnits > maxTextUnits) invalid();
43222
+ return input;
43223
+ }
43224
+ if (typeof input === "boolean") return input;
43225
+ if (typeof input === "number" && Number.isFinite(input)) return input;
43226
+ return invalid();
43227
+ }
43228
+ function project(input, shape) {
43229
+ if (input == null || typeof input !== "object") return scalar(input);
43230
+ if (import_node_util.types.isProxy(input) || Array.isArray(input)) invalid();
43231
+ const output = /* @__PURE__ */ Object.create(null);
43232
+ const keys2 = shape === "envelope" ? ["toolName", "name"] : shape === "tool" ? ["name"] : shape === "args" ? argumentKeys : replacementKeys;
43233
+ for (const key3 of keys2) {
43234
+ const field = dataProperty(input, key3);
43235
+ if (field !== void 0) output[key3] = scalar(field);
43236
+ }
43237
+ if (shape === "envelope") {
43238
+ for (const key3 of ["params", "args", "arguments", "tool"]) {
43239
+ const field = dataProperty(input, key3);
43240
+ if (field !== void 0)
43241
+ output[key3] = project(field, key3 === "tool" ? "tool" : "args");
43242
+ }
43243
+ }
43244
+ if (shape === "args") {
43245
+ const edits = dataProperty(input, "edits");
43246
+ if (edits !== void 0) {
43247
+ if (edits !== null && typeof edits === "object" && import_node_util.types.isProxy(edits))
43248
+ invalid();
43249
+ if (Array.isArray(edits)) {
43250
+ const length = dataProperty(edits, "length");
43251
+ if (typeof length !== "number" || !Number.isInteger(length) || length < 0 || length > maxEditSlots)
43252
+ invalid();
43253
+ const entries = [];
43254
+ for (let index2 = 0; index2 < length; index2++) {
43255
+ entries.push(project(dataProperty(edits, String(index2)), "edit"));
43256
+ }
43257
+ output.edits = entries;
43258
+ } else {
43259
+ output.edits = scalar(edits);
43260
+ }
43261
+ }
43262
+ }
43263
+ return output;
43169
43264
  }
43265
+ return project(value, "envelope");
43170
43266
  }
43171
43267
 
43172
43268
  // src-ts/memory/classifier.ts
@@ -43219,7 +43315,22 @@ async function guardMemoryWrite(input) {
43219
43315
  debug: debug2 = false,
43220
43316
  logger: logger2
43221
43317
  } = input;
43222
- const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
43318
+ let memEntry;
43319
+ try {
43320
+ memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
43321
+ } catch (err) {
43322
+ const why = err instanceof Error ? err.message : String(err);
43323
+ logger2?.warn?.("[atbash] memory classifier refused this tool call's input", { reason: why });
43324
+ if (!enforce) return { handled: false };
43325
+ return {
43326
+ handled: true,
43327
+ decision: {
43328
+ allow: false,
43329
+ block: true,
43330
+ reason: `Memory protection could not read this tool call (${why}); blocked because it could not be checked.`
43331
+ }
43332
+ };
43333
+ }
43223
43334
  if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
43224
43335
  if (!memEntry) return { handled: false };
43225
43336
  let scanResult;
@@ -43563,7 +43674,21 @@ var MemoryGuardManager = class {
43563
43674
  * that allows is a call the host still needs to judge.
43564
43675
  */
43565
43676
  async handleBeforeToolCall(event, ctx) {
43566
- if (classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier)) {
43677
+ let isMemoryRead;
43678
+ try {
43679
+ isMemoryRead = classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier);
43680
+ } catch (err) {
43681
+ const why = err instanceof Error ? err.message : String(err);
43682
+ this.logger.warn("[atbash] memory classifier refused this tool call's input", { reason: why });
43683
+ if (!this.enforce) return null;
43684
+ return {
43685
+ allow: false,
43686
+ block: true,
43687
+ blockReason: `Memory protection could not read this tool call (${why}); blocked because it could not be checked.`,
43688
+ audited: true
43689
+ };
43690
+ }
43691
+ if (isMemoryRead) {
43567
43692
  this.logger.info("[atbash] memory read intercepted \u2014 running sync check");
43568
43693
  return await this.handleMemoryRead(event, ctx);
43569
43694
  }
package/dist/index.mjs CHANGED
@@ -3094,6 +3094,13 @@ function classifyTransportError(err, url, method, timeoutMs) {
3094
3094
  { cause: err }
3095
3095
  );
3096
3096
  }
3097
+ if (code2 === "UND_ERR_CONNECT_TIMEOUT") {
3098
+ return new HttpTransportError(
3099
+ "timeout",
3100
+ `${method} ${url} could not establish a connection before the transport deadline \u2014 check the endpoint and network`,
3101
+ { cause: err }
3102
+ );
3103
+ }
3097
3104
  if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
3098
3105
  return new HttpTransportError(
3099
3106
  "dns",
@@ -3261,6 +3268,7 @@ var meterProvider = null;
3261
3268
  var callCounter = null;
3262
3269
  var durationHistogram = null;
3263
3270
  var defaultSource = "sdk";
3271
+ var sourceExplicitlySet = false;
3264
3272
  function isTelemetryOptedOut() {
3265
3273
  const disabled = process.env.ATBASH_TELEMETRY_DISABLED?.trim().toLowerCase();
3266
3274
  if (disabled && ["1", "true", "yes", "on"].includes(disabled)) {
@@ -3284,11 +3292,14 @@ function autoInit() {
3284
3292
  }
3285
3293
  function setupTelemetry(config2) {
3286
3294
  if (!config2.enabled) return;
3287
- if (meterProvider) return;
3288
3295
  if (isTelemetryOptedOut()) return;
3296
+ if (config2.source && !sourceExplicitlySet) {
3297
+ defaultSource = config2.source;
3298
+ sourceExplicitlySet = true;
3299
+ }
3300
+ if (meterProvider) return;
3289
3301
  if (!config2.endpoint || !config2.getAuthHeaders) return;
3290
3302
  if (/^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0)(:|\/|$)/i.test(config2.endpoint)) return;
3291
- defaultSource = config2.source ?? "sdk";
3292
3303
  const proxyUrl = `${config2.endpoint.replace(/\/+$/, "")}/api/telemetry`;
3293
3304
  const getAuthHeaders = config2.getAuthHeaders;
3294
3305
  const exporter = new OTLPMetricExporter({
@@ -3341,6 +3352,8 @@ async function shutdownTelemetry() {
3341
3352
  meterProvider = null;
3342
3353
  callCounter = null;
3343
3354
  durationHistogram = null;
3355
+ defaultSource = "sdk";
3356
+ sourceExplicitlySet = false;
3344
3357
  }
3345
3358
 
3346
3359
  // src-ts/userConfig.ts
@@ -3537,7 +3550,6 @@ var Atbash = class _Atbash {
3537
3550
  try {
3538
3551
  setupTelemetry({
3539
3552
  enabled: true,
3540
- source: "sdk",
3541
3553
  endpoint: this.endpoint,
3542
3554
  getAuthHeaders: () => this.authHeaders()
3543
3555
  });
@@ -35233,9 +35245,9 @@ var ZodUnion = class extends ZodType {
35233
35245
  }
35234
35246
  };
35235
35247
  types.ZodUnion = ZodUnion;
35236
- ZodUnion.create = (types2, params) => {
35248
+ ZodUnion.create = (types3, params) => {
35237
35249
  return new ZodUnion({
35238
- options: types2,
35250
+ options: types3,
35239
35251
  typeName: ZodFirstPartyTypeKind.ZodUnion,
35240
35252
  ...processCreateParams(params)
35241
35253
  });
@@ -38692,9 +38704,9 @@ _nodeUtil.exports;
38692
38704
  var freeProcess = moduleExports && freeGlobal2.process;
38693
38705
  var nodeUtil2 = (function() {
38694
38706
  try {
38695
- var types2 = freeModule && freeModule.require && freeModule.require("util").types;
38696
- if (types2) {
38697
- return types2;
38707
+ var types3 = freeModule && freeModule.require && freeModule.require("util").types;
38708
+ if (types3) {
38709
+ return types3;
38698
38710
  }
38699
38711
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
38700
38712
  } catch (e) {
@@ -43074,12 +43086,96 @@ async function rollbackMemory(toId, reason, auth, opts) {
43074
43086
  }
43075
43087
 
43076
43088
  // src-ts/memory/_json_safe.ts
43089
+ import { types as types2 } from "util";
43090
+ var replacementKeys = [
43091
+ "newText",
43092
+ "new_string",
43093
+ "new_str",
43094
+ "newStr",
43095
+ "replacement"
43096
+ ];
43097
+ var argumentKeys = [
43098
+ "file_path",
43099
+ "path",
43100
+ "filename",
43101
+ "target",
43102
+ "file",
43103
+ "filePath",
43104
+ "content",
43105
+ ...replacementKeys,
43106
+ "value",
43107
+ "text"
43108
+ ];
43109
+ var maxPrototypeDepth = 32;
43110
+ var maxEditSlots = 65536;
43111
+ var maxTextUnits = 16 * 1024 * 1024;
43112
+ function invalid() {
43113
+ throw new TypeError("Unreadable or unsupported memory classifier input");
43114
+ }
43115
+ function dataProperty(value, key3) {
43116
+ let current = value;
43117
+ for (let depth = 0; current !== null; depth++) {
43118
+ if (depth >= maxPrototypeDepth || types2.isProxy(current)) invalid();
43119
+ const descriptor = Object.getOwnPropertyDescriptor(current, key3);
43120
+ if (descriptor) {
43121
+ if (!("value" in descriptor)) invalid();
43122
+ return descriptor.value;
43123
+ }
43124
+ current = Object.getPrototypeOf(current);
43125
+ }
43126
+ return void 0;
43127
+ }
43077
43128
  function toJsonSafe(value) {
43078
- try {
43079
- return JSON.parse(JSON.stringify(value ?? null));
43080
- } catch {
43081
- return null;
43129
+ let textUnits = 0;
43130
+ function scalar(input) {
43131
+ if (input == null) return null;
43132
+ if (typeof input === "string") {
43133
+ textUnits += input.length;
43134
+ if (textUnits > maxTextUnits) invalid();
43135
+ return input;
43136
+ }
43137
+ if (typeof input === "boolean") return input;
43138
+ if (typeof input === "number" && Number.isFinite(input)) return input;
43139
+ return invalid();
43140
+ }
43141
+ function project(input, shape) {
43142
+ if (input == null || typeof input !== "object") return scalar(input);
43143
+ if (types2.isProxy(input) || Array.isArray(input)) invalid();
43144
+ const output = /* @__PURE__ */ Object.create(null);
43145
+ const keys2 = shape === "envelope" ? ["toolName", "name"] : shape === "tool" ? ["name"] : shape === "args" ? argumentKeys : replacementKeys;
43146
+ for (const key3 of keys2) {
43147
+ const field = dataProperty(input, key3);
43148
+ if (field !== void 0) output[key3] = scalar(field);
43149
+ }
43150
+ if (shape === "envelope") {
43151
+ for (const key3 of ["params", "args", "arguments", "tool"]) {
43152
+ const field = dataProperty(input, key3);
43153
+ if (field !== void 0)
43154
+ output[key3] = project(field, key3 === "tool" ? "tool" : "args");
43155
+ }
43156
+ }
43157
+ if (shape === "args") {
43158
+ const edits = dataProperty(input, "edits");
43159
+ if (edits !== void 0) {
43160
+ if (edits !== null && typeof edits === "object" && types2.isProxy(edits))
43161
+ invalid();
43162
+ if (Array.isArray(edits)) {
43163
+ const length = dataProperty(edits, "length");
43164
+ if (typeof length !== "number" || !Number.isInteger(length) || length < 0 || length > maxEditSlots)
43165
+ invalid();
43166
+ const entries = [];
43167
+ for (let index2 = 0; index2 < length; index2++) {
43168
+ entries.push(project(dataProperty(edits, String(index2)), "edit"));
43169
+ }
43170
+ output.edits = entries;
43171
+ } else {
43172
+ output.edits = scalar(edits);
43173
+ }
43174
+ }
43175
+ }
43176
+ return output;
43082
43177
  }
43178
+ return project(value, "envelope");
43083
43179
  }
43084
43180
 
43085
43181
  // src-ts/memory/classifier.ts
@@ -43132,7 +43228,22 @@ async function guardMemoryWrite(input) {
43132
43228
  debug: debug2 = false,
43133
43229
  logger: logger2
43134
43230
  } = input;
43135
- const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
43231
+ let memEntry;
43232
+ try {
43233
+ memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
43234
+ } catch (err) {
43235
+ const why = err instanceof Error ? err.message : String(err);
43236
+ logger2?.warn?.("[atbash] memory classifier refused this tool call's input", { reason: why });
43237
+ if (!enforce) return { handled: false };
43238
+ return {
43239
+ handled: true,
43240
+ decision: {
43241
+ allow: false,
43242
+ block: true,
43243
+ reason: `Memory protection could not read this tool call (${why}); blocked because it could not be checked.`
43244
+ }
43245
+ };
43246
+ }
43136
43247
  if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
43137
43248
  if (!memEntry) return { handled: false };
43138
43249
  let scanResult;
@@ -43476,7 +43587,21 @@ var MemoryGuardManager = class {
43476
43587
  * that allows is a call the host still needs to judge.
43477
43588
  */
43478
43589
  async handleBeforeToolCall(event, ctx) {
43479
- if (classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier)) {
43590
+ let isMemoryRead;
43591
+ try {
43592
+ isMemoryRead = classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier);
43593
+ } catch (err) {
43594
+ const why = err instanceof Error ? err.message : String(err);
43595
+ this.logger.warn("[atbash] memory classifier refused this tool call's input", { reason: why });
43596
+ if (!this.enforce) return null;
43597
+ return {
43598
+ allow: false,
43599
+ block: true,
43600
+ blockReason: `Memory protection could not read this tool call (${why}); blocked because it could not be checked.`,
43601
+ audited: true
43602
+ };
43603
+ }
43604
+ if (isMemoryRead) {
43480
43605
  this.logger.info("[atbash] memory read intercepted \u2014 running sync check");
43481
43606
  return await this.handleMemoryRead(event, ctx);
43482
43607
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atbash/sdk",
3
- "version": "0.16.2-dev.0",
3
+ "version": "0.16.3-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.16.2-dev.0",
93
- "@atbash/sdk-linux-arm64-gnu": "0.16.2-dev.0",
94
- "@atbash/sdk-linux-x64-musl": "0.16.2-dev.0",
95
- "@atbash/sdk-darwin-arm64": "0.16.2-dev.0",
96
- "@atbash/sdk-win32-x64-msvc": "0.16.2-dev.0"
92
+ "@atbash/sdk-linux-x64-gnu": "0.16.3-dev.0",
93
+ "@atbash/sdk-linux-arm64-gnu": "0.16.3-dev.0",
94
+ "@atbash/sdk-linux-x64-musl": "0.16.3-dev.0",
95
+ "@atbash/sdk-darwin-arm64": "0.16.3-dev.0",
96
+ "@atbash/sdk-win32-x64-msvc": "0.16.3-dev.0"
97
97
  }
98
98
  }