@integrity-labs/agt-cli 0.15.22 → 0.15.27

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.
@@ -17,9 +17,9 @@ var __export = (target, all) => {
17
17
  };
18
18
  var __copyProps = (to, from, except, desc) => {
19
19
  if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ for (let key2 of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
22
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
23
23
  }
24
24
  return to;
25
25
  };
@@ -168,15 +168,15 @@ var require_code = __commonJS({
168
168
  return JSON.stringify(x).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
169
169
  }
170
170
  exports.safeStringify = safeStringify;
171
- function getProperty(key) {
172
- return typeof key == "string" && exports.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _`[${key}]`;
171
+ function getProperty(key2) {
172
+ return typeof key2 == "string" && exports.IDENTIFIER.test(key2) ? new _Code(`.${key2}`) : _`[${key2}]`;
173
173
  }
174
174
  exports.getProperty = getProperty;
175
- function getEsmExportName(key) {
176
- if (typeof key == "string" && exports.IDENTIFIER.test(key)) {
177
- return new _Code(`${key}`);
175
+ function getEsmExportName(key2) {
176
+ if (typeof key2 == "string" && exports.IDENTIFIER.test(key2)) {
177
+ return new _Code(`${key2}`);
178
178
  }
179
- throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);
179
+ throw new Error(`CodeGen: invalid export name: ${key2}, use explicit $id name mapping`);
180
180
  }
181
181
  exports.getEsmExportName = getEsmExportName;
182
182
  function regexpCode(rx) {
@@ -803,11 +803,11 @@ var require_codegen = __commonJS({
803
803
  // returns code for object literal for the passed argument list of key-value pairs
804
804
  object(...keyValues) {
805
805
  const code = ["{"];
806
- for (const [key, value] of keyValues) {
806
+ for (const [key2, value] of keyValues) {
807
807
  if (code.length > 1)
808
808
  code.push(",");
809
- code.push(key);
810
- if (key !== value || this.opts.es5) {
809
+ code.push(key2);
810
+ if (key2 !== value || this.opts.es5) {
811
811
  code.push(":");
812
812
  (0, code_1.addCodeArg)(code, value);
813
813
  }
@@ -1082,17 +1082,17 @@ var require_util = __commonJS({
1082
1082
  if (typeof schema === "boolean")
1083
1083
  return;
1084
1084
  const rules = self.RULES.keywords;
1085
- for (const key in schema) {
1086
- if (!rules[key])
1087
- checkStrictMode(it, `unknown keyword: "${key}"`);
1085
+ for (const key2 in schema) {
1086
+ if (!rules[key2])
1087
+ checkStrictMode(it, `unknown keyword: "${key2}"`);
1088
1088
  }
1089
1089
  }
1090
1090
  exports.checkUnknownRules = checkUnknownRules;
1091
1091
  function schemaHasRules(schema, rules) {
1092
1092
  if (typeof schema == "boolean")
1093
1093
  return !schema;
1094
- for (const key in schema)
1095
- if (rules[key])
1094
+ for (const key2 in schema)
1095
+ if (rules[key2])
1096
1096
  return true;
1097
1097
  return false;
1098
1098
  }
@@ -1100,8 +1100,8 @@ var require_util = __commonJS({
1100
1100
  function schemaHasRulesButRef(schema, RULES) {
1101
1101
  if (typeof schema == "boolean")
1102
1102
  return !schema;
1103
- for (const key in schema)
1104
- if (key !== "$ref" && RULES.all[key])
1103
+ for (const key2 in schema)
1104
+ if (key2 !== "$ref" && RULES.all[key2])
1105
1105
  return true;
1106
1106
  return false;
1107
1107
  }
@@ -1679,8 +1679,8 @@ var require_defaults = __commonJS({
1679
1679
  function assignDefaults(it, ty) {
1680
1680
  const { properties, items } = it.schema;
1681
1681
  if (ty === "object" && properties) {
1682
- for (const key in properties) {
1683
- assignDefault(it, key, properties[key].default);
1682
+ for (const key2 in properties) {
1683
+ assignDefault(it, key2, properties[key2].default);
1684
1684
  }
1685
1685
  } else if (ty === "array" && Array.isArray(items)) {
1686
1686
  items.forEach((sch, i) => assignDefault(it, i, sch.default));
@@ -2064,8 +2064,8 @@ var require_fast_deep_equal = __commonJS({
2064
2064
  for (i = length; i-- !== 0; )
2065
2065
  if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
2066
2066
  for (i = length; i-- !== 0; ) {
2067
- var key = keys[i];
2068
- if (!equal(a[key], b[key])) return false;
2067
+ var key2 = keys[i];
2068
+ if (!equal(a[key2], b[key2])) return false;
2069
2069
  }
2070
2070
  return true;
2071
2071
  }
@@ -2137,20 +2137,20 @@ var require_json_schema_traverse = __commonJS({
2137
2137
  function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
2138
2138
  if (schema && typeof schema == "object" && !Array.isArray(schema)) {
2139
2139
  pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
2140
- for (var key in schema) {
2141
- var sch = schema[key];
2140
+ for (var key2 in schema) {
2141
+ var sch = schema[key2];
2142
2142
  if (Array.isArray(sch)) {
2143
- if (key in traverse.arrayKeywords) {
2143
+ if (key2 in traverse.arrayKeywords) {
2144
2144
  for (var i = 0; i < sch.length; i++)
2145
- _traverse(opts, pre, post, sch[i], jsonPtr + "/" + key + "/" + i, rootSchema, jsonPtr, key, schema, i);
2145
+ _traverse(opts, pre, post, sch[i], jsonPtr + "/" + key2 + "/" + i, rootSchema, jsonPtr, key2, schema, i);
2146
2146
  }
2147
- } else if (key in traverse.propsKeywords) {
2147
+ } else if (key2 in traverse.propsKeywords) {
2148
2148
  if (sch && typeof sch == "object") {
2149
2149
  for (var prop in sch)
2150
- _traverse(opts, pre, post, sch[prop], jsonPtr + "/" + key + "/" + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
2150
+ _traverse(opts, pre, post, sch[prop], jsonPtr + "/" + key2 + "/" + escapeJsonPtr(prop), rootSchema, jsonPtr, key2, schema, prop);
2151
2151
  }
2152
- } else if (key in traverse.keywords || opts.allKeys && !(key in traverse.skipKeywords)) {
2153
- _traverse(opts, pre, post, sch, jsonPtr + "/" + key, rootSchema, jsonPtr, key, schema);
2152
+ } else if (key2 in traverse.keywords || opts.allKeys && !(key2 in traverse.skipKeywords)) {
2153
+ _traverse(opts, pre, post, sch, jsonPtr + "/" + key2, rootSchema, jsonPtr, key2, schema);
2154
2154
  }
2155
2155
  }
2156
2156
  post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
@@ -2207,10 +2207,10 @@ var require_resolve = __commonJS({
2207
2207
  "$dynamicAnchor"
2208
2208
  ]);
2209
2209
  function hasRef(schema) {
2210
- for (const key in schema) {
2211
- if (REF_KEYWORDS.has(key))
2210
+ for (const key2 in schema) {
2211
+ if (REF_KEYWORDS.has(key2))
2212
2212
  return true;
2213
- const sch = schema[key];
2213
+ const sch = schema[key2];
2214
2214
  if (Array.isArray(sch) && sch.some(hasRef))
2215
2215
  return true;
2216
2216
  if (typeof sch == "object" && hasRef(sch))
@@ -2220,14 +2220,14 @@ var require_resolve = __commonJS({
2220
2220
  }
2221
2221
  function countKeys(schema) {
2222
2222
  let count = 0;
2223
- for (const key in schema) {
2224
- if (key === "$ref")
2223
+ for (const key2 in schema) {
2224
+ if (key2 === "$ref")
2225
2225
  return Infinity;
2226
2226
  count++;
2227
- if (SIMPLE_INLINED.has(key))
2227
+ if (SIMPLE_INLINED.has(key2))
2228
2228
  continue;
2229
- if (typeof schema[key] == "object") {
2230
- (0, util_1.eachItem)(schema[key], (sch) => count += countKeys(sch));
2229
+ if (typeof schema[key2] == "object") {
2230
+ (0, util_1.eachItem)(schema[key2], (sch) => count += countKeys(sch));
2231
2231
  }
2232
2232
  if (count === Infinity)
2233
2233
  return Infinity;
@@ -2416,8 +2416,8 @@ var require_validate = __commonJS({
2416
2416
  function schemaCxtHasRules({ schema, self }) {
2417
2417
  if (typeof schema == "boolean")
2418
2418
  return !schema;
2419
- for (const key in schema)
2420
- if (self.RULES.all[key])
2419
+ for (const key2 in schema)
2420
+ if (self.RULES.all[key2])
2421
2421
  return true;
2422
2422
  return false;
2423
2423
  }
@@ -4059,7 +4059,7 @@ var require_core = __commonJS({
4059
4059
  }
4060
4060
  }
4061
4061
  // Adds schema to the instance
4062
- addSchema(schema, key, _meta, _validateSchema = this.opts.validateSchema) {
4062
+ addSchema(schema, key2, _meta, _validateSchema = this.opts.validateSchema) {
4063
4063
  if (Array.isArray(schema)) {
4064
4064
  for (const sch of schema)
4065
4065
  this.addSchema(sch, void 0, _meta, _validateSchema);
@@ -4073,15 +4073,15 @@ var require_core = __commonJS({
4073
4073
  throw new Error(`schema ${schemaId} must be string`);
4074
4074
  }
4075
4075
  }
4076
- key = (0, resolve_1.normalizeId)(key || id);
4077
- this._checkUnique(key);
4078
- this.schemas[key] = this._addSchema(schema, _meta, key, _validateSchema, true);
4076
+ key2 = (0, resolve_1.normalizeId)(key2 || id);
4077
+ this._checkUnique(key2);
4078
+ this.schemas[key2] = this._addSchema(schema, _meta, key2, _validateSchema, true);
4079
4079
  return this;
4080
4080
  }
4081
4081
  // Add schema that will be used to validate other schemas
4082
4082
  // options in META_IGNORE_OPTIONS are alway set to false
4083
- addMetaSchema(schema, key, _validateSchema = this.opts.validateSchema) {
4084
- this.addSchema(schema, key, true, _validateSchema);
4083
+ addMetaSchema(schema, key2, _validateSchema = this.opts.validateSchema) {
4084
+ this.addSchema(schema, key2, true, _validateSchema);
4085
4085
  return this;
4086
4086
  }
4087
4087
  // Validate schema against its meta-schema
@@ -4150,8 +4150,8 @@ var require_core = __commonJS({
4150
4150
  return this;
4151
4151
  }
4152
4152
  case "object": {
4153
- const cacheKey = schemaKeyRef;
4154
- this._cache.delete(cacheKey);
4153
+ const cacheKey2 = schemaKeyRef;
4154
+ this._cache.delete(cacheKey2);
4155
4155
  let id = schemaKeyRef[this.opts.schemaId];
4156
4156
  if (id) {
4157
4157
  id = (0, resolve_1.normalizeId)(id);
@@ -4237,14 +4237,14 @@ var require_core = __commonJS({
4237
4237
  let keywords = metaSchema;
4238
4238
  for (const seg of segments)
4239
4239
  keywords = keywords[seg];
4240
- for (const key in rules) {
4241
- const rule = rules[key];
4240
+ for (const key2 in rules) {
4241
+ const rule = rules[key2];
4242
4242
  if (typeof rule != "object")
4243
4243
  continue;
4244
4244
  const { $data } = rule.definition;
4245
- const schema = keywords[key];
4245
+ const schema = keywords[key2];
4246
4246
  if ($data && schema)
4247
- keywords[key] = schemaOrData(schema);
4247
+ keywords[key2] = schemaOrData(schema);
4248
4248
  }
4249
4249
  }
4250
4250
  return metaSchema;
@@ -4317,10 +4317,10 @@ var require_core = __commonJS({
4317
4317
  Ajv2.MissingRefError = ref_error_1.default;
4318
4318
  exports.default = Ajv2;
4319
4319
  function checkOptions(checkOpts, options, msg, log = "error") {
4320
- for (const key in checkOpts) {
4321
- const opt = key;
4320
+ for (const key2 in checkOpts) {
4321
+ const opt = key2;
4322
4322
  if (opt in options)
4323
- this.logger[log](`${msg}: option ${key}. ${checkOpts[opt]}`);
4323
+ this.logger[log](`${msg}: option ${key2}. ${checkOpts[opt]}`);
4324
4324
  }
4325
4325
  }
4326
4326
  function getSchEnv(keyRef) {
@@ -4334,8 +4334,8 @@ var require_core = __commonJS({
4334
4334
  if (Array.isArray(optsSchemas))
4335
4335
  this.addSchema(optsSchemas);
4336
4336
  else
4337
- for (const key in optsSchemas)
4338
- this.addSchema(optsSchemas[key], key);
4337
+ for (const key2 in optsSchemas)
4338
+ this.addSchema(optsSchemas[key2], key2);
4339
4339
  }
4340
4340
  function addInitialFormats() {
4341
4341
  for (const name in this.opts.formats) {
@@ -5383,11 +5383,11 @@ var require_dependencies = __commonJS({
5383
5383
  function splitDependencies({ schema }) {
5384
5384
  const propertyDeps = {};
5385
5385
  const schemaDeps = {};
5386
- for (const key in schema) {
5387
- if (key === "__proto__")
5386
+ for (const key2 in schema) {
5387
+ if (key2 === "__proto__")
5388
5388
  continue;
5389
- const deps = Array.isArray(schema[key]) ? propertyDeps : schemaDeps;
5390
- deps[key] = schema[key];
5389
+ const deps = Array.isArray(schema[key2]) ? propertyDeps : schemaDeps;
5390
+ deps[key2] = schema[key2];
5391
5391
  }
5392
5392
  return [propertyDeps, schemaDeps];
5393
5393
  }
@@ -5464,13 +5464,13 @@ var require_propertyNames = __commonJS({
5464
5464
  if ((0, util_1.alwaysValidSchema)(it, schema))
5465
5465
  return;
5466
5466
  const valid = gen.name("valid");
5467
- gen.forIn("key", data, (key) => {
5468
- cxt.setParams({ propertyName: key });
5467
+ gen.forIn("key", data, (key2) => {
5468
+ cxt.setParams({ propertyName: key2 });
5469
5469
  cxt.subschema({
5470
5470
  keyword: "propertyNames",
5471
- data: key,
5471
+ data: key2,
5472
5472
  dataTypes: ["string"],
5473
- propertyName: key,
5473
+ propertyName: key2,
5474
5474
  compositeRule: true
5475
5475
  }, valid);
5476
5476
  gen.if((0, codegen_1.not)(valid), () => {
@@ -5519,38 +5519,38 @@ var require_additionalProperties = __commonJS({
5519
5519
  checkAdditionalProperties();
5520
5520
  cxt.ok((0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
5521
5521
  function checkAdditionalProperties() {
5522
- gen.forIn("key", data, (key) => {
5522
+ gen.forIn("key", data, (key2) => {
5523
5523
  if (!props.length && !patProps.length)
5524
- additionalPropertyCode(key);
5524
+ additionalPropertyCode(key2);
5525
5525
  else
5526
- gen.if(isAdditional(key), () => additionalPropertyCode(key));
5526
+ gen.if(isAdditional(key2), () => additionalPropertyCode(key2));
5527
5527
  });
5528
5528
  }
5529
- function isAdditional(key) {
5529
+ function isAdditional(key2) {
5530
5530
  let definedProp;
5531
5531
  if (props.length > 8) {
5532
5532
  const propsSchema = (0, util_1.schemaRefOrVal)(it, parentSchema.properties, "properties");
5533
- definedProp = (0, code_1.isOwnProperty)(gen, propsSchema, key);
5533
+ definedProp = (0, code_1.isOwnProperty)(gen, propsSchema, key2);
5534
5534
  } else if (props.length) {
5535
- definedProp = (0, codegen_1.or)(...props.map((p) => (0, codegen_1._)`${key} === ${p}`));
5535
+ definedProp = (0, codegen_1.or)(...props.map((p) => (0, codegen_1._)`${key2} === ${p}`));
5536
5536
  } else {
5537
5537
  definedProp = codegen_1.nil;
5538
5538
  }
5539
5539
  if (patProps.length) {
5540
- definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((p) => (0, codegen_1._)`${(0, code_1.usePattern)(cxt, p)}.test(${key})`));
5540
+ definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((p) => (0, codegen_1._)`${(0, code_1.usePattern)(cxt, p)}.test(${key2})`));
5541
5541
  }
5542
5542
  return (0, codegen_1.not)(definedProp);
5543
5543
  }
5544
- function deleteAdditional(key) {
5545
- gen.code((0, codegen_1._)`delete ${data}[${key}]`);
5544
+ function deleteAdditional(key2) {
5545
+ gen.code((0, codegen_1._)`delete ${data}[${key2}]`);
5546
5546
  }
5547
- function additionalPropertyCode(key) {
5547
+ function additionalPropertyCode(key2) {
5548
5548
  if (opts.removeAdditional === "all" || opts.removeAdditional && schema === false) {
5549
- deleteAdditional(key);
5549
+ deleteAdditional(key2);
5550
5550
  return;
5551
5551
  }
5552
5552
  if (schema === false) {
5553
- cxt.setParams({ additionalProperty: key });
5553
+ cxt.setParams({ additionalProperty: key2 });
5554
5554
  cxt.error();
5555
5555
  if (!allErrors)
5556
5556
  gen.break();
@@ -5559,22 +5559,22 @@ var require_additionalProperties = __commonJS({
5559
5559
  if (typeof schema == "object" && !(0, util_1.alwaysValidSchema)(it, schema)) {
5560
5560
  const valid = gen.name("valid");
5561
5561
  if (opts.removeAdditional === "failing") {
5562
- applyAdditionalSchema(key, valid, false);
5562
+ applyAdditionalSchema(key2, valid, false);
5563
5563
  gen.if((0, codegen_1.not)(valid), () => {
5564
5564
  cxt.reset();
5565
- deleteAdditional(key);
5565
+ deleteAdditional(key2);
5566
5566
  });
5567
5567
  } else {
5568
- applyAdditionalSchema(key, valid);
5568
+ applyAdditionalSchema(key2, valid);
5569
5569
  if (!allErrors)
5570
5570
  gen.if((0, codegen_1.not)(valid), () => gen.break());
5571
5571
  }
5572
5572
  }
5573
5573
  }
5574
- function applyAdditionalSchema(key, valid, errors) {
5574
+ function applyAdditionalSchema(key2, valid, errors) {
5575
5575
  const subschema = {
5576
5576
  keyword: "additionalProperties",
5577
- dataProp: key,
5577
+ dataProp: key2,
5578
5578
  dataPropType: util_1.Type.Str
5579
5579
  };
5580
5580
  if (errors === false) {
@@ -5699,19 +5699,19 @@ var require_patternProperties = __commonJS({
5699
5699
  }
5700
5700
  }
5701
5701
  function validateProperties(pat) {
5702
- gen.forIn("key", data, (key) => {
5703
- gen.if((0, codegen_1._)`${(0, code_1.usePattern)(cxt, pat)}.test(${key})`, () => {
5702
+ gen.forIn("key", data, (key2) => {
5703
+ gen.if((0, codegen_1._)`${(0, code_1.usePattern)(cxt, pat)}.test(${key2})`, () => {
5704
5704
  const alwaysValid = alwaysValidPatterns.includes(pat);
5705
5705
  if (!alwaysValid) {
5706
5706
  cxt.subschema({
5707
5707
  keyword: "patternProperties",
5708
5708
  schemaProp: pat,
5709
- dataProp: key,
5709
+ dataProp: key2,
5710
5710
  dataPropType: util_2.Type.Str
5711
5711
  }, valid);
5712
5712
  }
5713
5713
  if (it.opts.unevaluated && props !== true) {
5714
- gen.assign((0, codegen_1._)`${props}[${key}]`, true);
5714
+ gen.assign((0, codegen_1._)`${props}[${key2}]`, true);
5715
5715
  } else if (!alwaysValid && !it.allErrors) {
5716
5716
  gen.if((0, codegen_1.not)(valid), () => gen.break());
5717
5717
  }
@@ -7364,19 +7364,19 @@ function floatSafeRemainder(val, step) {
7364
7364
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
7365
7365
  return valInt % stepInt / 10 ** decCount;
7366
7366
  }
7367
- function defineLazy(object3, key, getter) {
7367
+ function defineLazy(object3, key2, getter) {
7368
7368
  const set = false;
7369
- Object.defineProperty(object3, key, {
7369
+ Object.defineProperty(object3, key2, {
7370
7370
  get() {
7371
7371
  if (!set) {
7372
7372
  const value = getter();
7373
- object3[key] = value;
7373
+ object3[key2] = value;
7374
7374
  return value;
7375
7375
  }
7376
7376
  throw new Error("cached value already set");
7377
7377
  },
7378
7378
  set(v) {
7379
- Object.defineProperty(object3, key, {
7379
+ Object.defineProperty(object3, key2, {
7380
7380
  value: v
7381
7381
  // configurable: true,
7382
7382
  });
@@ -7395,11 +7395,11 @@ function assignProp(target, prop, value) {
7395
7395
  function getElementAtPath(obj, path) {
7396
7396
  if (!path)
7397
7397
  return obj;
7398
- return path.reduce((acc, key) => acc?.[key], obj);
7398
+ return path.reduce((acc, key2) => acc?.[key2], obj);
7399
7399
  }
7400
7400
  function promiseAllObject(promisesObj) {
7401
7401
  const keys = Object.keys(promisesObj);
7402
- const promises = keys.map((key) => promisesObj[key]);
7402
+ const promises = keys.map((key2) => promisesObj[key2]);
7403
7403
  return Promise.all(promises).then((results) => {
7404
7404
  const resolvedObj = {};
7405
7405
  for (let i = 0; i < keys.length; i++) {
@@ -7452,8 +7452,8 @@ function isPlainObject(o) {
7452
7452
  }
7453
7453
  function numKeys(data) {
7454
7454
  let keyCount = 0;
7455
- for (const key in data) {
7456
- if (Object.prototype.hasOwnProperty.call(data, key)) {
7455
+ for (const key2 in data) {
7456
+ if (Object.prototype.hasOwnProperty.call(data, key2)) {
7457
7457
  keyCount++;
7458
7458
  }
7459
7459
  }
@@ -7589,13 +7589,13 @@ var BIGINT_FORMAT_RANGES = {
7589
7589
  function pick(schema, mask) {
7590
7590
  const newShape = {};
7591
7591
  const currDef = schema._zod.def;
7592
- for (const key in mask) {
7593
- if (!(key in currDef.shape)) {
7594
- throw new Error(`Unrecognized key: "${key}"`);
7592
+ for (const key2 in mask) {
7593
+ if (!(key2 in currDef.shape)) {
7594
+ throw new Error(`Unrecognized key: "${key2}"`);
7595
7595
  }
7596
- if (!mask[key])
7596
+ if (!mask[key2])
7597
7597
  continue;
7598
- newShape[key] = currDef.shape[key];
7598
+ newShape[key2] = currDef.shape[key2];
7599
7599
  }
7600
7600
  return clone(schema, {
7601
7601
  ...schema._zod.def,
@@ -7606,13 +7606,13 @@ function pick(schema, mask) {
7606
7606
  function omit(schema, mask) {
7607
7607
  const newShape = { ...schema._zod.def.shape };
7608
7608
  const currDef = schema._zod.def;
7609
- for (const key in mask) {
7610
- if (!(key in currDef.shape)) {
7611
- throw new Error(`Unrecognized key: "${key}"`);
7609
+ for (const key2 in mask) {
7610
+ if (!(key2 in currDef.shape)) {
7611
+ throw new Error(`Unrecognized key: "${key2}"`);
7612
7612
  }
7613
- if (!mask[key])
7613
+ if (!mask[key2])
7614
7614
  continue;
7615
- delete newShape[key];
7615
+ delete newShape[key2];
7616
7616
  }
7617
7617
  return clone(schema, {
7618
7618
  ...schema._zod.def,
@@ -7653,23 +7653,23 @@ function partial(Class2, schema, mask) {
7653
7653
  const oldShape = schema._zod.def.shape;
7654
7654
  const shape = { ...oldShape };
7655
7655
  if (mask) {
7656
- for (const key in mask) {
7657
- if (!(key in oldShape)) {
7658
- throw new Error(`Unrecognized key: "${key}"`);
7656
+ for (const key2 in mask) {
7657
+ if (!(key2 in oldShape)) {
7658
+ throw new Error(`Unrecognized key: "${key2}"`);
7659
7659
  }
7660
- if (!mask[key])
7660
+ if (!mask[key2])
7661
7661
  continue;
7662
- shape[key] = Class2 ? new Class2({
7662
+ shape[key2] = Class2 ? new Class2({
7663
7663
  type: "optional",
7664
- innerType: oldShape[key]
7665
- }) : oldShape[key];
7664
+ innerType: oldShape[key2]
7665
+ }) : oldShape[key2];
7666
7666
  }
7667
7667
  } else {
7668
- for (const key in oldShape) {
7669
- shape[key] = Class2 ? new Class2({
7668
+ for (const key2 in oldShape) {
7669
+ shape[key2] = Class2 ? new Class2({
7670
7670
  type: "optional",
7671
- innerType: oldShape[key]
7672
- }) : oldShape[key];
7671
+ innerType: oldShape[key2]
7672
+ }) : oldShape[key2];
7673
7673
  }
7674
7674
  }
7675
7675
  return clone(schema, {
@@ -7682,22 +7682,22 @@ function required(Class2, schema, mask) {
7682
7682
  const oldShape = schema._zod.def.shape;
7683
7683
  const shape = { ...oldShape };
7684
7684
  if (mask) {
7685
- for (const key in mask) {
7686
- if (!(key in shape)) {
7687
- throw new Error(`Unrecognized key: "${key}"`);
7685
+ for (const key2 in mask) {
7686
+ if (!(key2 in shape)) {
7687
+ throw new Error(`Unrecognized key: "${key2}"`);
7688
7688
  }
7689
- if (!mask[key])
7689
+ if (!mask[key2])
7690
7690
  continue;
7691
- shape[key] = new Class2({
7691
+ shape[key2] = new Class2({
7692
7692
  type: "nonoptional",
7693
- innerType: oldShape[key]
7693
+ innerType: oldShape[key2]
7694
7694
  });
7695
7695
  }
7696
7696
  } else {
7697
- for (const key in oldShape) {
7698
- shape[key] = new Class2({
7697
+ for (const key2 in oldShape) {
7698
+ shape[key2] = new Class2({
7699
7699
  type: "nonoptional",
7700
- innerType: oldShape[key]
7700
+ innerType: oldShape[key2]
7701
7701
  });
7702
7702
  }
7703
7703
  }
@@ -8893,28 +8893,28 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
8893
8893
  return payload;
8894
8894
  };
8895
8895
  });
8896
- function handleObjectResult(result, final, key) {
8896
+ function handleObjectResult(result, final, key2) {
8897
8897
  if (result.issues.length) {
8898
- final.issues.push(...prefixIssues(key, result.issues));
8898
+ final.issues.push(...prefixIssues(key2, result.issues));
8899
8899
  }
8900
- final.value[key] = result.value;
8900
+ final.value[key2] = result.value;
8901
8901
  }
8902
- function handleOptionalObjectResult(result, final, key, input) {
8902
+ function handleOptionalObjectResult(result, final, key2, input) {
8903
8903
  if (result.issues.length) {
8904
- if (input[key] === void 0) {
8905
- if (key in input) {
8906
- final.value[key] = void 0;
8904
+ if (input[key2] === void 0) {
8905
+ if (key2 in input) {
8906
+ final.value[key2] = void 0;
8907
8907
  } else {
8908
- final.value[key] = result.value;
8908
+ final.value[key2] = result.value;
8909
8909
  }
8910
8910
  } else {
8911
- final.issues.push(...prefixIssues(key, result.issues));
8911
+ final.issues.push(...prefixIssues(key2, result.issues));
8912
8912
  }
8913
8913
  } else if (result.value === void 0) {
8914
- if (key in input)
8915
- final.value[key] = void 0;
8914
+ if (key2 in input)
8915
+ final.value[key2] = void 0;
8916
8916
  } else {
8917
- final.value[key] = result.value;
8917
+ final.value[key2] = result.value;
8918
8918
  }
8919
8919
  }
8920
8920
  var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
@@ -8938,12 +8938,12 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
8938
8938
  defineLazy(inst._zod, "propValues", () => {
8939
8939
  const shape = def.shape;
8940
8940
  const propValues = {};
8941
- for (const key in shape) {
8942
- const field = shape[key]._zod;
8941
+ for (const key2 in shape) {
8942
+ const field = shape[key2]._zod;
8943
8943
  if (field.values) {
8944
- propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
8944
+ propValues[key2] ?? (propValues[key2] = /* @__PURE__ */ new Set());
8945
8945
  for (const v of field.values)
8946
- propValues[key].add(v);
8946
+ propValues[key2].add(v);
8947
8947
  }
8948
8948
  }
8949
8949
  return propValues;
@@ -8951,22 +8951,22 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
8951
8951
  const generateFastpass = (shape) => {
8952
8952
  const doc = new Doc(["shape", "payload", "ctx"]);
8953
8953
  const normalized = _normalized.value;
8954
- const parseStr = (key) => {
8955
- const k = esc(key);
8954
+ const parseStr = (key2) => {
8955
+ const k = esc(key2);
8956
8956
  return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
8957
8957
  };
8958
8958
  doc.write(`const input = payload.value;`);
8959
8959
  const ids = /* @__PURE__ */ Object.create(null);
8960
8960
  let counter = 0;
8961
- for (const key of normalized.keys) {
8962
- ids[key] = `key_${counter++}`;
8961
+ for (const key2 of normalized.keys) {
8962
+ ids[key2] = `key_${counter++}`;
8963
8963
  }
8964
8964
  doc.write(`const newResult = {}`);
8965
- for (const key of normalized.keys) {
8966
- if (normalized.optionalKeys.has(key)) {
8967
- const id = ids[key];
8968
- doc.write(`const ${id} = ${parseStr(key)};`);
8969
- const k = esc(key);
8965
+ for (const key2 of normalized.keys) {
8966
+ if (normalized.optionalKeys.has(key2)) {
8967
+ const id = ids[key2];
8968
+ doc.write(`const ${id} = ${parseStr(key2)};`);
8969
+ const k = esc(key2);
8970
8970
  doc.write(`
8971
8971
  if (${id}.issues.length) {
8972
8972
  if (input[${k}] === undefined) {
@@ -8988,14 +8988,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
8988
8988
  }
8989
8989
  `);
8990
8990
  } else {
8991
- const id = ids[key];
8992
- doc.write(`const ${id} = ${parseStr(key)};`);
8991
+ const id = ids[key2];
8992
+ doc.write(`const ${id} = ${parseStr(key2)};`);
8993
8993
  doc.write(`
8994
8994
  if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
8995
8995
  ...iss,
8996
- path: iss.path ? [${esc(key)}, ...iss.path] : [${esc(key)}]
8996
+ path: iss.path ? [${esc(key2)}, ...iss.path] : [${esc(key2)}]
8997
8997
  })));`);
8998
- doc.write(`newResult[${esc(key)}] = ${id}.value`);
8998
+ doc.write(`newResult[${esc(key2)}] = ${id}.value`);
8999
8999
  }
9000
9000
  }
9001
9001
  doc.write(`payload.value = newResult;`);
@@ -9030,16 +9030,16 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
9030
9030
  } else {
9031
9031
  payload.value = {};
9032
9032
  const shape = value.shape;
9033
- for (const key of value.keys) {
9034
- const el = shape[key];
9035
- const r = el._zod.run({ value: input[key], issues: [] }, ctx);
9033
+ for (const key2 of value.keys) {
9034
+ const el = shape[key2];
9035
+ const r = el._zod.run({ value: input[key2], issues: [] }, ctx);
9036
9036
  const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
9037
9037
  if (r instanceof Promise) {
9038
- proms.push(r.then((r2) => isOptional ? handleOptionalObjectResult(r2, payload, key, input) : handleObjectResult(r2, payload, key)));
9038
+ proms.push(r.then((r2) => isOptional ? handleOptionalObjectResult(r2, payload, key2, input) : handleObjectResult(r2, payload, key2)));
9039
9039
  } else if (isOptional) {
9040
- handleOptionalObjectResult(r, payload, key, input);
9040
+ handleOptionalObjectResult(r, payload, key2, input);
9041
9041
  } else {
9042
- handleObjectResult(r, payload, key);
9042
+ handleObjectResult(r, payload, key2);
9043
9043
  }
9044
9044
  }
9045
9045
  }
@@ -9050,18 +9050,18 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
9050
9050
  const keySet = value.keySet;
9051
9051
  const _catchall = catchall._zod;
9052
9052
  const t = _catchall.def.type;
9053
- for (const key of Object.keys(input)) {
9054
- if (keySet.has(key))
9053
+ for (const key2 of Object.keys(input)) {
9054
+ if (keySet.has(key2))
9055
9055
  continue;
9056
9056
  if (t === "never") {
9057
- unrecognized.push(key);
9057
+ unrecognized.push(key2);
9058
9058
  continue;
9059
9059
  }
9060
- const r = _catchall.run({ value: input[key], issues: [] }, ctx);
9060
+ const r = _catchall.run({ value: input[key2], issues: [] }, ctx);
9061
9061
  if (r instanceof Promise) {
9062
- proms.push(r.then((r2) => handleObjectResult(r2, payload, key)));
9062
+ proms.push(r.then((r2) => handleObjectResult(r2, payload, key2)));
9063
9063
  } else {
9064
- handleObjectResult(r, payload, key);
9064
+ handleObjectResult(r, payload, key2);
9065
9065
  }
9066
9066
  }
9067
9067
  if (unrecognized.length) {
@@ -9223,17 +9223,17 @@ function mergeValues(a, b) {
9223
9223
  }
9224
9224
  if (isPlainObject(a) && isPlainObject(b)) {
9225
9225
  const bKeys = Object.keys(b);
9226
- const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
9226
+ const sharedKeys = Object.keys(a).filter((key2) => bKeys.indexOf(key2) !== -1);
9227
9227
  const newObj = { ...a, ...b };
9228
- for (const key of sharedKeys) {
9229
- const sharedValue = mergeValues(a[key], b[key]);
9228
+ for (const key2 of sharedKeys) {
9229
+ const sharedValue = mergeValues(a[key2], b[key2]);
9230
9230
  if (!sharedValue.valid) {
9231
9231
  return {
9232
9232
  valid: false,
9233
- mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
9233
+ mergeErrorPath: [key2, ...sharedValue.mergeErrorPath]
9234
9234
  };
9235
9235
  }
9236
- newObj[key] = sharedValue.data;
9236
+ newObj[key2] = sharedValue.data;
9237
9237
  }
9238
9238
  return { valid: true, data: newObj };
9239
9239
  }
@@ -9291,29 +9291,29 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
9291
9291
  if (def.keyType._zod.values) {
9292
9292
  const values = def.keyType._zod.values;
9293
9293
  payload.value = {};
9294
- for (const key of values) {
9295
- if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
9296
- const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
9294
+ for (const key2 of values) {
9295
+ if (typeof key2 === "string" || typeof key2 === "number" || typeof key2 === "symbol") {
9296
+ const result = def.valueType._zod.run({ value: input[key2], issues: [] }, ctx);
9297
9297
  if (result instanceof Promise) {
9298
9298
  proms.push(result.then((result2) => {
9299
9299
  if (result2.issues.length) {
9300
- payload.issues.push(...prefixIssues(key, result2.issues));
9300
+ payload.issues.push(...prefixIssues(key2, result2.issues));
9301
9301
  }
9302
- payload.value[key] = result2.value;
9302
+ payload.value[key2] = result2.value;
9303
9303
  }));
9304
9304
  } else {
9305
9305
  if (result.issues.length) {
9306
- payload.issues.push(...prefixIssues(key, result.issues));
9306
+ payload.issues.push(...prefixIssues(key2, result.issues));
9307
9307
  }
9308
- payload.value[key] = result.value;
9308
+ payload.value[key2] = result.value;
9309
9309
  }
9310
9310
  }
9311
9311
  }
9312
9312
  let unrecognized;
9313
- for (const key in input) {
9314
- if (!values.has(key)) {
9313
+ for (const key2 in input) {
9314
+ if (!values.has(key2)) {
9315
9315
  unrecognized = unrecognized ?? [];
9316
- unrecognized.push(key);
9316
+ unrecognized.push(key2);
9317
9317
  }
9318
9318
  }
9319
9319
  if (unrecognized && unrecognized.length > 0) {
@@ -9326,10 +9326,10 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
9326
9326
  }
9327
9327
  } else {
9328
9328
  payload.value = {};
9329
- for (const key of Reflect.ownKeys(input)) {
9330
- if (key === "__proto__")
9329
+ for (const key2 of Reflect.ownKeys(input)) {
9330
+ if (key2 === "__proto__")
9331
9331
  continue;
9332
- const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
9332
+ const keyResult = def.keyType._zod.run({ value: key2, issues: [] }, ctx);
9333
9333
  if (keyResult instanceof Promise) {
9334
9334
  throw new Error("Async schemas not supported in object keys currently");
9335
9335
  }
@@ -9338,24 +9338,24 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
9338
9338
  origin: "record",
9339
9339
  code: "invalid_key",
9340
9340
  issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
9341
- input: key,
9342
- path: [key],
9341
+ input: key2,
9342
+ path: [key2],
9343
9343
  inst
9344
9344
  });
9345
9345
  payload.value[keyResult.value] = keyResult.value;
9346
9346
  continue;
9347
9347
  }
9348
- const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
9348
+ const result = def.valueType._zod.run({ value: input[key2], issues: [] }, ctx);
9349
9349
  if (result instanceof Promise) {
9350
9350
  proms.push(result.then((result2) => {
9351
9351
  if (result2.issues.length) {
9352
- payload.issues.push(...prefixIssues(key, result2.issues));
9352
+ payload.issues.push(...prefixIssues(key2, result2.issues));
9353
9353
  }
9354
9354
  payload.value[keyResult.value] = result2.value;
9355
9355
  }));
9356
9356
  } else {
9357
9357
  if (result.issues.length) {
9358
- payload.issues.push(...prefixIssues(key, result.issues));
9358
+ payload.issues.push(...prefixIssues(key2, result.issues));
9359
9359
  }
9360
9360
  payload.value[keyResult.value] = result.value;
9361
9361
  }
@@ -13457,8 +13457,8 @@ function isPlainObject2(value) {
13457
13457
  }
13458
13458
  function mergeCapabilities(base, additional) {
13459
13459
  const result = { ...base };
13460
- for (const key in additional) {
13461
- const k = key;
13460
+ for (const key2 in additional) {
13461
+ const k = key2;
13462
13462
  const addValue = additional[k];
13463
13463
  if (addValue === void 0)
13464
13464
  continue;
@@ -14192,6 +14192,112 @@ function decideSlackMessageForward(evt) {
14192
14192
  }
14193
14193
  return { forward: true };
14194
14194
  }
14195
+ function decideSlackEngagement(input) {
14196
+ const isExplicitMention = input.type === "app_mention" || input.botUserId.length > 0 && input.text.includes(`<@${input.botUserId}>`);
14197
+ return !(input.isAutoFollowed && !isExplicitMention);
14198
+ }
14199
+
14200
+ // src/slack-loop-throttle.ts
14201
+ var DEFAULT_THROTTLE = {
14202
+ threshold: 3,
14203
+ windowMs: 12e4,
14204
+ ringSize: 8
14205
+ };
14206
+ function decideReplyThrottle(input) {
14207
+ const cfg = input.config ?? DEFAULT_THROTTLE;
14208
+ const cutoff = input.now - cfg.windowMs;
14209
+ const inWindow = input.recentReplyTimestamps.filter((t) => t >= cutoff);
14210
+ if (inWindow.length >= cfg.threshold) {
14211
+ return {
14212
+ allow: false,
14213
+ recentCount: inWindow.length,
14214
+ reason: "throttle_threshold_exceeded"
14215
+ };
14216
+ }
14217
+ return {
14218
+ allow: true,
14219
+ recentCount: inWindow.length,
14220
+ reason: "under_threshold"
14221
+ };
14222
+ }
14223
+ var buffers = /* @__PURE__ */ new Map();
14224
+ function key(channelId, threadKey) {
14225
+ return `${channelId}${threadKey}`;
14226
+ }
14227
+ function recordReply(channelId, threadKey, now, config2 = DEFAULT_THROTTLE) {
14228
+ const k = key(channelId, threadKey);
14229
+ const cutoff = now - config2.windowMs;
14230
+ const cur = buffers.get(k) ?? [];
14231
+ cur.push(now);
14232
+ let pruned = cur.filter((t) => t >= cutoff);
14233
+ if (pruned.length > config2.ringSize) {
14234
+ pruned = pruned.slice(pruned.length - config2.ringSize);
14235
+ }
14236
+ buffers.set(k, pruned);
14237
+ }
14238
+ function getRecentReplies(channelId, threadKey, now, config2 = DEFAULT_THROTTLE) {
14239
+ const k = key(channelId, threadKey);
14240
+ const cutoff = now - config2.windowMs;
14241
+ const cur = buffers.get(k) ?? [];
14242
+ return cur.filter((t) => t >= cutoff);
14243
+ }
14244
+ function resetThread(channelId, threadKey) {
14245
+ buffers.delete(key(channelId, threadKey));
14246
+ }
14247
+ function configFromEnv(env = process.env) {
14248
+ const count = Number(env.SLACK_AGENT_REPLY_THROTTLE_COUNT);
14249
+ const windowMs = Number(env.SLACK_AGENT_REPLY_THROTTLE_WINDOW_MS);
14250
+ return {
14251
+ threshold: Number.isFinite(count) && count > 0 ? count : DEFAULT_THROTTLE.threshold,
14252
+ windowMs: Number.isFinite(windowMs) && windowMs > 0 ? windowMs : DEFAULT_THROTTLE.windowMs,
14253
+ ringSize: DEFAULT_THROTTLE.ringSize
14254
+ };
14255
+ }
14256
+
14257
+ // src/channel-kill-check.ts
14258
+ var CACHE_TTL_MS = 6e4;
14259
+ var cache = /* @__PURE__ */ new Map();
14260
+ function cacheKey(channelType, channelId, threadTs) {
14261
+ return `${channelType}|${channelId}|${threadTs}`;
14262
+ }
14263
+ async function isThreadKilled(opts) {
14264
+ const threadTs = opts.threadTs ?? "";
14265
+ const key2 = cacheKey(opts.channelType, opts.channelId, threadTs);
14266
+ const now = opts.now ? opts.now() : Date.now();
14267
+ const cached2 = cache.get(key2);
14268
+ if (cached2 && cached2.expiresAt > now) {
14269
+ return cached2.killed;
14270
+ }
14271
+ if (!opts.agtHost || !opts.agtApiKey) {
14272
+ cache.set(key2, { killed: false, expiresAt: now + CACHE_TTL_MS });
14273
+ return false;
14274
+ }
14275
+ const fetchImpl = opts.fetchImpl ?? fetch;
14276
+ try {
14277
+ const url = new URL("/host/channels/kill-check", opts.agtHost);
14278
+ url.searchParams.set("channel_type", opts.channelType);
14279
+ url.searchParams.set("channel_id", opts.channelId);
14280
+ if (threadTs) url.searchParams.set("thread_ts", threadTs);
14281
+ const res = await fetchImpl(url.toString(), {
14282
+ method: "GET",
14283
+ headers: { Authorization: `Bearer ${opts.agtApiKey}` },
14284
+ // 5s ceiling — kill check is hot-path. If the API is slow,
14285
+ // fail-open and try again next cache window.
14286
+ signal: AbortSignal.timeout(5e3)
14287
+ });
14288
+ if (!res.ok) {
14289
+ cache.set(key2, { killed: false, expiresAt: now + CACHE_TTL_MS });
14290
+ return false;
14291
+ }
14292
+ const body = await res.json();
14293
+ const killed = !!body.killed;
14294
+ cache.set(key2, { killed, expiresAt: now + CACHE_TTL_MS });
14295
+ return killed;
14296
+ } catch {
14297
+ cache.set(key2, { killed: false, expiresAt: now + CACHE_TTL_MS });
14298
+ return false;
14299
+ }
14300
+ }
14195
14301
 
14196
14302
  // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.27.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
14197
14303
  import process2 from "process";
@@ -14336,20 +14442,20 @@ function loadThreadStore(filePath, opts = {}) {
14336
14442
  }
14337
14443
  const threads = /* @__PURE__ */ new Map();
14338
14444
  let pruned = 0;
14339
- for (const [key, entry] of Object.entries(parsed.threads)) {
14445
+ for (const [key2, entry] of Object.entries(parsed.threads)) {
14340
14446
  if (!isThreadEntry(entry)) continue;
14341
14447
  const seenTs = Date.parse(entry.last_seen_at);
14342
14448
  if (Number.isFinite(seenTs) && now.getTime() - seenTs > ttlMs) {
14343
14449
  pruned++;
14344
14450
  continue;
14345
14451
  }
14346
- threads.set(key, { involvement: entry.involvement, last_seen_at: entry.last_seen_at });
14452
+ threads.set(key2, { involvement: entry.involvement, last_seen_at: entry.last_seen_at });
14347
14453
  }
14348
14454
  return { threads, pruned };
14349
14455
  }
14350
14456
  function serializeThreadStore(threads) {
14351
14457
  const out = { version: FILE_VERSION, threads: {} };
14352
- for (const [key, entry] of threads) out.threads[key] = entry;
14458
+ for (const [key2, entry] of threads) out.threads[key2] = entry;
14353
14459
  return JSON.stringify(out, null, 2);
14354
14460
  }
14355
14461
  function createThreadPersister(opts) {
@@ -14810,9 +14916,9 @@ function startSlackRecoveryOutboxWatcher() {
14810
14916
  }
14811
14917
  startSlackRecoveryOutboxWatcher();
14812
14918
  function trackPendingMessage(channel, threadTs, messageTs) {
14813
- const key = `${channel}:${threadTs}:${messageTs}`;
14919
+ const key2 = `${channel}:${threadTs}:${messageTs}`;
14814
14920
  const timer = setTimeout(async () => {
14815
- pendingMessages.delete(key);
14921
+ pendingMessages.delete(key2);
14816
14922
  try {
14817
14923
  await fetch("https://slack.com/api/chat.postMessage", {
14818
14924
  method: "POST",
@@ -14837,14 +14943,14 @@ function trackPendingMessage(channel, threadTs, messageTs) {
14837
14943
  `);
14838
14944
  clearSlackPendingInboundMarker(channel, threadTs, messageTs);
14839
14945
  }, RESPONSE_TIMEOUT_MS);
14840
- pendingMessages.set(key, timer);
14946
+ pendingMessages.set(key2, timer);
14841
14947
  writeSlackPendingInboundMarker(channel, threadTs, messageTs);
14842
14948
  }
14843
14949
  function clearPendingMessage(channel, threadTs) {
14844
- for (const [key, timer] of pendingMessages) {
14845
- if (key.startsWith(`${channel}:${threadTs}:`)) {
14950
+ for (const [key2, timer] of pendingMessages) {
14951
+ if (key2.startsWith(`${channel}:${threadTs}:`)) {
14846
14952
  clearTimeout(timer);
14847
- pendingMessages.delete(key);
14953
+ pendingMessages.delete(key2);
14848
14954
  }
14849
14955
  }
14850
14956
  clearAllSlackPendingMarkersForThread(channel, threadTs);
@@ -14953,14 +15059,14 @@ function buildThreadKey(channel, threadTs) {
14953
15059
  return `${channel}:${threadTs}`;
14954
15060
  }
14955
15061
  function rememberThread(channel, threadTs, involvement, opts = {}) {
14956
- const key = buildThreadKey(channel, threadTs);
14957
- if (!key) return;
14958
- const existing = trackedThreads.get(key);
15062
+ const key2 = buildThreadKey(channel, threadTs);
15063
+ if (!key2) return;
15064
+ const existing = trackedThreads.get(key2);
14959
15065
  const next = {
14960
15066
  involvement: opts.override || !existing ? involvement : existing.involvement,
14961
15067
  last_seen_at: (/* @__PURE__ */ new Date()).toISOString()
14962
15068
  };
14963
- trackedThreads.set(key, next);
15069
+ trackedThreads.set(key2, next);
14964
15070
  if (isShuttingDown) {
14965
15071
  threadPersister?.flush(trackedThreads);
14966
15072
  } else {
@@ -15215,6 +15321,64 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
15215
15321
  const { name, arguments: args } = req.params;
15216
15322
  if (name === "slack.reply") {
15217
15323
  const { channel, text, thread_ts } = args;
15324
+ if (channel && thread_ts) {
15325
+ const killed = await isThreadKilled({
15326
+ channelType: "slack",
15327
+ channelId: channel,
15328
+ threadTs: thread_ts,
15329
+ agtHost: AGT_HOST,
15330
+ agtApiKey: AGT_API_KEY
15331
+ });
15332
+ if (killed) {
15333
+ process.stderr.write(
15334
+ `slack-channel(${AGENT_CODE_NAME}): reply_killed channel=${redactSlackId(channel)} thread=${redactSlackId(thread_ts)}
15335
+ `
15336
+ );
15337
+ return {
15338
+ content: [
15339
+ {
15340
+ type: "text",
15341
+ text: "This thread has been silenced by /kill. Stop attempting to reply \u2014 the human will /unkill when they want agents back."
15342
+ }
15343
+ ],
15344
+ isError: true
15345
+ };
15346
+ }
15347
+ }
15348
+ const throttleCfg = configFromEnv();
15349
+ const throttleKey = thread_ts ?? channel;
15350
+ const throttleNow = Date.now();
15351
+ const throttleDecision = decideReplyThrottle({
15352
+ recentReplyTimestamps: getRecentReplies(channel, throttleKey, throttleNow, throttleCfg),
15353
+ now: throttleNow,
15354
+ config: throttleCfg
15355
+ });
15356
+ if (!throttleDecision.allow) {
15357
+ process.stderr.write(
15358
+ `slack-channel(${AGENT_CODE_NAME}): reply_throttled channel=${redactSlackId(channel)} thread=${redactSlackId(throttleKey)} count=${throttleDecision.recentCount} window_ms=${throttleCfg.windowMs} threshold=${throttleCfg.threshold}
15359
+ `
15360
+ );
15361
+ if (channel && thread_ts) {
15362
+ fetch("https://slack.com/api/reactions.add", {
15363
+ method: "POST",
15364
+ headers: {
15365
+ "Content-Type": "application/json",
15366
+ Authorization: `Bearer ${BOT_TOKEN}`
15367
+ },
15368
+ body: JSON.stringify({ channel, timestamp: thread_ts, name: "lock" })
15369
+ }).catch(() => {
15370
+ });
15371
+ }
15372
+ return {
15373
+ content: [
15374
+ {
15375
+ type: "text",
15376
+ text: `Reply throttled: ${throttleDecision.recentCount} replies from this agent to this thread within the last ${Math.round(throttleCfg.windowMs / 1e3)}s (threshold ${throttleCfg.threshold}). The thread is paused for this agent until a human posts in it. Stop attempting to reply.`
15377
+ }
15378
+ ],
15379
+ isError: true
15380
+ };
15381
+ }
15218
15382
  if (channel && thread_ts) {
15219
15383
  clearPendingMessage(channel, thread_ts);
15220
15384
  }
@@ -15238,6 +15402,7 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
15238
15402
  isError: true
15239
15403
  };
15240
15404
  }
15405
+ recordReply(channel, throttleKey, throttleNow, throttleCfg);
15241
15406
  if (THREAD_AUTO_FOLLOW !== "off") {
15242
15407
  const trackTs = thread_ts ?? data.ts ?? void 0;
15243
15408
  rememberThread(channel, trackTs, thread_ts ? "mentioned" : "started");
@@ -16094,7 +16259,18 @@ async function connectSocketMode() {
16094
16259
  const ts = evt.ts ?? "";
16095
16260
  const threadTs = evt.thread_ts ?? ts;
16096
16261
  const user = evt.user ?? "unknown";
16097
- if (channel && ts) {
16262
+ const isFromBot = !!evt.bot_id;
16263
+ if (channel && !isFromBot && evt.user !== botUserId) {
16264
+ resetThread(channel, threadTs);
16265
+ }
16266
+ const isAutoFollowed = evt.type === "message" && isThreadReply && !!threadKey && trackedThreads.has(threadKey);
16267
+ const shouldEngage = decideSlackEngagement({
16268
+ type: evt.type ?? "message",
16269
+ text,
16270
+ isAutoFollowed,
16271
+ botUserId
16272
+ });
16273
+ if (channel && ts && shouldEngage) {
16098
16274
  fetch("https://slack.com/api/reactions.add", {
16099
16275
  method: "POST",
16100
16276
  headers: {
@@ -16105,8 +16281,7 @@ async function connectSocketMode() {
16105
16281
  }).catch(() => {
16106
16282
  });
16107
16283
  }
16108
- const isAutoFollowed = evt.type === "message" && isThreadReply && !!threadKey && trackedThreads.has(threadKey);
16109
- if (channel && ts) {
16284
+ if (channel && ts && shouldEngage) {
16110
16285
  trackPendingMessage(channel, threadTs, ts);
16111
16286
  }
16112
16287
  const userName = await resolveUserName(user);
@@ -16186,7 +16361,7 @@ if (THREAD_STORE_PATH) {
16186
16361
  onError: (msg) => process.stderr.write(`${redact(msg)}
16187
16362
  `)
16188
16363
  });
16189
- for (const [key, entry] of threads) trackedThreads.set(key, entry);
16364
+ for (const [key2, entry] of threads) trackedThreads.set(key2, entry);
16190
16365
  threadPersister = createThreadPersister({
16191
16366
  filePath: THREAD_STORE_PATH,
16192
16367
  onError: (msg) => process.stderr.write(`${redact(msg)}