airband 0.0.1 → 0.0.3

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/airband-mcp.js CHANGED
@@ -940,10 +940,10 @@ var require_codegen = __commonJS({
940
940
  return this._leafNode(new Throw(error62));
941
941
  }
942
942
  // start self-balancing block
943
- block(body2, nodeCount) {
943
+ block(body3, nodeCount) {
944
944
  this._blockStarts.push(this._nodes.length);
945
- if (body2)
946
- this.code(body2).endBlock(nodeCount);
945
+ if (body3)
946
+ this.code(body3).endBlock(nodeCount);
947
947
  return this;
948
948
  }
949
949
  // end the current self-balancing block
@@ -2383,15 +2383,15 @@ var require_validate = __commonJS({
2383
2383
  validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
2384
2384
  }
2385
2385
  exports2.validateFunctionCode = validateFunctionCode;
2386
- function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body2) {
2386
+ function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body3) {
2387
2387
  if (opts.code.es5) {
2388
2388
  gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
2389
2389
  gen.code((0, codegen_1._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
2390
2390
  destructureValCxtES5(gen, opts);
2391
- gen.code(body2);
2391
+ gen.code(body3);
2392
2392
  });
2393
2393
  } else {
2394
- gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body2));
2394
+ gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body3));
2395
2395
  }
2396
2396
  }
2397
2397
  function destructureValCxt(opts) {
@@ -3022,7 +3022,7 @@ var require_compile = __commonJS({
3022
3022
  const schOrFunc = root2.refs[ref];
3023
3023
  if (schOrFunc)
3024
3024
  return schOrFunc;
3025
- let _sch = resolve4.call(this, root2, ref);
3025
+ let _sch = resolve5.call(this, root2, ref);
3026
3026
  if (_sch === void 0) {
3027
3027
  const schema = (_a3 = root2.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
3028
3028
  const { schemaId } = this.opts;
@@ -3049,7 +3049,7 @@ var require_compile = __commonJS({
3049
3049
  function sameSchemaEnv(s1, s2) {
3050
3050
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
3051
3051
  }
3052
- function resolve4(root2, ref) {
3052
+ function resolve5(root2, ref) {
3053
3053
  let sch;
3054
3054
  while (typeof (sch = this.refs[ref]) == "string")
3055
3055
  ref = sch;
@@ -3301,8 +3301,8 @@ var require_utils = __commonJS({
3301
3301
  }
3302
3302
  return ind;
3303
3303
  }
3304
- function removeDotSegments(path12) {
3305
- let input2 = path12;
3304
+ function removeDotSegments(path13) {
3305
+ let input2 = path13;
3306
3306
  const output2 = [];
3307
3307
  let nextSlash = -1;
3308
3308
  let len = 0;
@@ -3712,8 +3712,8 @@ var require_schemes = __commonJS({
3712
3712
  }
3713
3713
  if (wsComponent.resourceName) {
3714
3714
  const queryIndex = wsComponent.resourceName.indexOf("?");
3715
- const path12 = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
3716
- wsComponent.path = path12 && path12 !== "/" ? path12 : void 0;
3715
+ const path13 = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
3716
+ wsComponent.path = path13 && path13 !== "/" ? path13 : void 0;
3717
3717
  wsComponent.query = queryIndex === -1 ? void 0 : wsComponent.resourceName.slice(queryIndex + 1);
3718
3718
  wsComponent.resourceName = void 0;
3719
3719
  }
@@ -3882,7 +3882,7 @@ var require_fast_uri = __commonJS({
3882
3882
  }
3883
3883
  return uri;
3884
3884
  }
3885
- function resolve4(baseURI, relativeURI, options) {
3885
+ function resolve5(baseURI, relativeURI, options) {
3886
3886
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3887
3887
  const {
3888
3888
  parsed: baseParsed,
@@ -4251,7 +4251,7 @@ var require_fast_uri = __commonJS({
4251
4251
  var fastUri = {
4252
4252
  SCHEMES,
4253
4253
  normalize,
4254
- resolve: resolve4,
4254
+ resolve: resolve5,
4255
4255
  resolveComponent,
4256
4256
  equal,
4257
4257
  serialize,
@@ -7272,12 +7272,12 @@ var require_dist = __commonJS({
7272
7272
  throw new Error(`Unknown format "${name2}"`);
7273
7273
  return f;
7274
7274
  };
7275
- function addFormats(ajv, list, fs16, exportName) {
7275
+ function addFormats(ajv, list, fs17, exportName) {
7276
7276
  var _a3;
7277
7277
  var _b;
7278
7278
  (_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 ? _a3 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
7279
7279
  for (const f of list)
7280
- ajv.addFormat(f, fs16[f]);
7280
+ ajv.addFormat(f, fs17[f]);
7281
7281
  }
7282
7282
  module2.exports = exports2 = formatsPlugin;
7283
7283
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -9326,10 +9326,10 @@ var require_tree_sitter = __commonJS({
9326
9326
  if (response.ok) {
9327
9327
  return new Uint8Array(buffer);
9328
9328
  } else {
9329
- const body2 = new TextDecoder("utf-8").decode(buffer);
9329
+ const body22 = new TextDecoder("utf-8").decode(buffer);
9330
9330
  throw new Error(`Language.load failed with status ${response.status}.
9331
9331
 
9332
- ${body2}`);
9332
+ ${body22}`);
9333
9333
  }
9334
9334
  }));
9335
9335
  }
@@ -9352,8 +9352,8 @@ ${JSON.stringify(symbolNames, null, 2)}`);
9352
9352
  var moduleRtn;
9353
9353
  var Module = moduleArg;
9354
9354
  var readyPromiseResolve, readyPromiseReject;
9355
- var readyPromise = new Promise((resolve4, reject) => {
9356
- readyPromiseResolve = resolve4;
9355
+ var readyPromise = new Promise((resolve5, reject) => {
9356
+ readyPromiseResolve = resolve5;
9357
9357
  readyPromiseReject = reject;
9358
9358
  });
9359
9359
  var ENVIRONMENT_IS_WEB = typeof window == "object";
@@ -9375,11 +9375,11 @@ ${JSON.stringify(symbolNames, null, 2)}`);
9375
9375
  throw toThrow;
9376
9376
  }, "quit_");
9377
9377
  var scriptDirectory = "";
9378
- function locateFile(path12) {
9378
+ function locateFile(path13) {
9379
9379
  if (Module["locateFile"]) {
9380
- return Module["locateFile"](path12, scriptDirectory);
9380
+ return Module["locateFile"](path13, scriptDirectory);
9381
9381
  }
9382
- return scriptDirectory + path12;
9382
+ return scriptDirectory + path13;
9383
9383
  }
9384
9384
  __name(locateFile, "locateFile");
9385
9385
  var readAsync, readBinary;
@@ -9394,10 +9394,10 @@ ${JSON.stringify(symbolNames, null, 2)}`);
9394
9394
  }, "readBinary");
9395
9395
  readAsync = /* @__PURE__ */ __name((filename, binary2 = true) => {
9396
9396
  filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
9397
- return new Promise((resolve4, reject) => {
9397
+ return new Promise((resolve5, reject) => {
9398
9398
  fs.readFile(filename, binary2 ? void 0 : "utf8", (err2, data) => {
9399
9399
  if (err2) reject(err2);
9400
- else resolve4(binary2 ? data.buffer : data);
9400
+ else resolve5(binary2 ? data.buffer : data);
9401
9401
  });
9402
9402
  });
9403
9403
  }, "readAsync");
@@ -9438,13 +9438,13 @@ ${JSON.stringify(symbolNames, null, 2)}`);
9438
9438
  }
9439
9439
  readAsync = /* @__PURE__ */ __name((url2) => {
9440
9440
  if (isFileURI(url2)) {
9441
- return new Promise((reject, resolve4) => {
9441
+ return new Promise((reject, resolve5) => {
9442
9442
  var xhr = new XMLHttpRequest();
9443
9443
  xhr.open("GET", url2, true);
9444
9444
  xhr.responseType = "arraybuffer";
9445
9445
  xhr.onload = () => {
9446
9446
  if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
9447
- resolve4(xhr.response);
9447
+ resolve5(xhr.response);
9448
9448
  }
9449
9449
  reject(xhr.status);
9450
9450
  };
@@ -10458,8 +10458,8 @@ ${JSON.stringify(symbolNames, null, 2)}`);
10458
10458
  }
10459
10459
  var libFile = locateFile(libName2);
10460
10460
  if (flags2.loadAsync) {
10461
- return new Promise(function(resolve4, reject) {
10462
- asyncLoad(libFile, resolve4, reject);
10461
+ return new Promise(function(resolve5, reject) {
10462
+ asyncLoad(libFile, resolve5, reject);
10463
10463
  });
10464
10464
  }
10465
10465
  if (!readBinary) {
@@ -11336,8 +11336,8 @@ ${JSON.stringify(symbolNames, null, 2)}`);
11336
11336
 
11337
11337
  // src/mcp/server.ts
11338
11338
  init_define_AIRBAND_GRAMMARS();
11339
- var fs15 = __toESM(require("node:fs"));
11340
- var path11 = __toESM(require("node:path"));
11339
+ var fs16 = __toESM(require("node:fs"));
11340
+ var path12 = __toESM(require("node:path"));
11341
11341
 
11342
11342
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
11343
11343
  init_define_AIRBAND_GRAMMARS();
@@ -11736,8 +11736,8 @@ function getErrorMap() {
11736
11736
  // node_modules/zod/v3/helpers/parseUtil.js
11737
11737
  init_define_AIRBAND_GRAMMARS();
11738
11738
  var makeIssue = (params) => {
11739
- const { data, path: path12, errorMaps, issueData } = params;
11740
- const fullPath2 = [...path12, ...issueData.path || []];
11739
+ const { data, path: path13, errorMaps, issueData } = params;
11740
+ const fullPath2 = [...path13, ...issueData.path || []];
11741
11741
  const fullIssue = {
11742
11742
  ...issueData,
11743
11743
  path: fullPath2
@@ -11750,8 +11750,8 @@ var makeIssue = (params) => {
11750
11750
  };
11751
11751
  }
11752
11752
  let errorMessage = "";
11753
- const maps = errorMaps.filter((m) => !!m).slice().reverse();
11754
- for (const map2 of maps) {
11753
+ const maps2 = errorMaps.filter((m) => !!m).slice().reverse();
11754
+ for (const map2 of maps2) {
11755
11755
  errorMessage = map2(fullIssue, { data, defaultError: errorMessage }).message;
11756
11756
  }
11757
11757
  return {
@@ -11856,11 +11856,11 @@ var errorUtil;
11856
11856
 
11857
11857
  // node_modules/zod/v3/types.js
11858
11858
  var ParseInputLazyPath = class {
11859
- constructor(parent, value, path12, key2) {
11859
+ constructor(parent, value, path13, key2) {
11860
11860
  this._cachedPath = [];
11861
11861
  this.parent = parent;
11862
11862
  this.data = value;
11863
- this._path = path12;
11863
+ this._path = path13;
11864
11864
  this._key = key2;
11865
11865
  }
11866
11866
  get path() {
@@ -15823,10 +15823,10 @@ function mergeDefs(...defs) {
15823
15823
  function cloneDef(schema) {
15824
15824
  return mergeDefs(schema._zod.def);
15825
15825
  }
15826
- function getElementAtPath(obj, path12) {
15827
- if (!path12)
15826
+ function getElementAtPath(obj, path13) {
15827
+ if (!path13)
15828
15828
  return obj;
15829
- return path12.reduce((acc, key2) => acc?.[key2], obj);
15829
+ return path13.reduce((acc, key2) => acc?.[key2], obj);
15830
15830
  }
15831
15831
  function promiseAllObject(promisesObj) {
15832
15832
  const keys = Object.keys(promisesObj);
@@ -16166,11 +16166,11 @@ function explicitlyAborted(x, startIndex = 0) {
16166
16166
  }
16167
16167
  return false;
16168
16168
  }
16169
- function prefixIssues(path12, issues) {
16169
+ function prefixIssues(path13, issues) {
16170
16170
  return issues.map((iss) => {
16171
16171
  var _a3;
16172
16172
  (_a3 = iss).path ?? (_a3.path = []);
16173
- iss.path.unshift(path12);
16173
+ iss.path.unshift(path13);
16174
16174
  return iss;
16175
16175
  });
16176
16176
  }
@@ -16636,16 +16636,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
16636
16636
  }
16637
16637
  function formatError(error62, mapper = (issue2) => issue2.message) {
16638
16638
  const fieldErrors = { _errors: [] };
16639
- const processError = (error63, path12 = []) => {
16639
+ const processError = (error63, path13 = []) => {
16640
16640
  for (const issue2 of error63.issues) {
16641
16641
  if (issue2.code === "invalid_union" && issue2.errors.length) {
16642
- issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
16642
+ issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
16643
16643
  } else if (issue2.code === "invalid_key") {
16644
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
16644
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
16645
16645
  } else if (issue2.code === "invalid_element") {
16646
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
16646
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
16647
16647
  } else {
16648
- const fullpath = [...path12, ...issue2.path];
16648
+ const fullpath = [...path13, ...issue2.path];
16649
16649
  if (fullpath.length === 0) {
16650
16650
  fieldErrors._errors.push(mapper(issue2));
16651
16651
  } else {
@@ -16684,17 +16684,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
16684
16684
  }
16685
16685
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
16686
16686
  const result = { errors: [] };
16687
- const processError = (error63, path12 = []) => {
16687
+ const processError = (error63, path13 = []) => {
16688
16688
  var _a3;
16689
16689
  for (const issue2 of error63.issues) {
16690
16690
  if (issue2.code === "invalid_union" && issue2.errors.length) {
16691
- issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
16691
+ issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
16692
16692
  } else if (issue2.code === "invalid_key") {
16693
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
16693
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
16694
16694
  } else if (issue2.code === "invalid_element") {
16695
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
16695
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
16696
16696
  } else {
16697
- const fullpath = [...path12, ...issue2.path];
16697
+ const fullpath = [...path13, ...issue2.path];
16698
16698
  if (fullpath.length === 0) {
16699
16699
  result.errors.push(mapper(issue2));
16700
16700
  continue;
@@ -16733,8 +16733,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
16733
16733
  }
16734
16734
  function toDotPath(_path) {
16735
16735
  const segs = [];
16736
- const path12 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
16737
- for (const seg of path12) {
16736
+ const path13 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
16737
+ for (const seg of path13) {
16738
16738
  if (typeof seg === "number")
16739
16739
  segs.push(`[${seg}]`);
16740
16740
  else if (typeof seg === "symbol")
@@ -20087,7 +20087,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
20087
20087
  var NONE = 0;
20088
20088
  var ASSUMED = 1;
20089
20089
  var PROVEN = 2;
20090
- function isRecursive(inst, stack, resolve4) {
20090
+ function isRecursive(inst, stack, resolve5) {
20091
20091
  const cached2 = recursive.get(inst);
20092
20092
  if (cached2 !== void 0)
20093
20093
  return cached2 ? PROVEN : NONE;
@@ -20097,7 +20097,7 @@ function isRecursive(inst, stack, resolve4) {
20097
20097
  let result = NONE;
20098
20098
  const check2 = (child) => {
20099
20099
  if (result !== PROVEN && child?._zod) {
20100
- const answer = isRecursive(child, stack, resolve4);
20100
+ const answer = isRecursive(child, stack, resolve5);
20101
20101
  if (answer > result)
20102
20102
  result = answer;
20103
20103
  }
@@ -20108,7 +20108,7 @@ function isRecursive(inst, stack, resolve4) {
20108
20108
  const desc = Object.getOwnPropertyDescriptor(sh, key2);
20109
20109
  if (spread && !desc.enumerable)
20110
20110
  continue;
20111
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve4) : NONE;
20111
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
20112
20112
  if (child > answer)
20113
20113
  answer = child;
20114
20114
  }
@@ -20172,7 +20172,7 @@ function isRecursive(inst, stack, resolve4) {
20172
20172
  break;
20173
20173
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
20174
20174
  case "lazy": {
20175
- const inner = def._cachedInner ?? (resolve4 ? inst._zod.innerType : void 0);
20175
+ const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
20176
20176
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
20177
20177
  break;
20178
20178
  }
@@ -25778,8 +25778,8 @@ var error43 = () => {
25778
25778
  case "not_multiple_of":
25779
25779
  return `N\xFAmero inv\xE1lido: deve ser m\xFAltiplo de ${issue2.divisor}`;
25780
25780
  case "unrecognized_keys": {
25781
- const plural2 = issue2.keys.length > 1 ? "s" : "";
25782
- return `Chave${plural2} inv\xE1lida${plural2}: ${joinValues(issue2.keys, ", ")}`;
25781
+ const plural3 = issue2.keys.length > 1 ? "s" : "";
25782
+ return `Chave${plural3} inv\xE1lida${plural3}: ${joinValues(issue2.keys, ", ")}`;
25783
25783
  }
25784
25784
  case "invalid_key":
25785
25785
  return `Entrada inv\xE1lida n${translateOriginWithArticle(issue2.origin, "definite")}`;
@@ -25924,8 +25924,8 @@ var error44 = () => {
25924
25924
  case "not_multiple_of":
25925
25925
  return `N\xFAmero inv\xE1lido: deve ser m\xFAltiplo de ${issue2.divisor}`;
25926
25926
  case "unrecognized_keys": {
25927
- const plural2 = issue2.keys.length > 1 ? "s" : "";
25928
- return `Chave${plural2} inv\xE1lida${plural2}: ${joinValues(issue2.keys, ", ")}`;
25927
+ const plural3 = issue2.keys.length > 1 ? "s" : "";
25928
+ return `Chave${plural3} inv\xE1lida${plural3}: ${joinValues(issue2.keys, ", ")}`;
25929
25929
  }
25930
25930
  case "invalid_key":
25931
25931
  return `Entrada inv\xE1lida n${translateOriginWithArticle(issue2.origin, "definite")}`;
@@ -29447,7 +29447,7 @@ function generateRecordCheck(doc, ctx, schema, accessor) {
29447
29447
  }, `return INVALID;`);
29448
29448
  return outputVar;
29449
29449
  }
29450
- function emitOwnKeys(doc, ctx, accessor, kVar, body2, onSymbol) {
29450
+ function emitOwnKeys(doc, ctx, accessor, kVar, body3, onSymbol) {
29451
29451
  const propIsEnumerableConst = addConstant(ctx, Object.prototype.propertyIsEnumerable);
29452
29452
  const symsVar = newVar(ctx);
29453
29453
  const keysVar = newVar(ctx);
@@ -29458,7 +29458,7 @@ function emitOwnKeys(doc, ctx, accessor, kVar, body2, onSymbol) {
29458
29458
  doc.indented((d) => {
29459
29459
  d.write(`const ${kVar} = ${keysVar}[${iVar}];`);
29460
29460
  d.write(`if (${kVar} === "__proto__" || !${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
29461
- body2(d);
29461
+ body3(d);
29462
29462
  });
29463
29463
  doc.write(`}`);
29464
29464
  doc.write(`for (let ${iVar} = 0; ${iVar} < ${symsVar}.length; ${iVar}++) {`);
@@ -29468,7 +29468,7 @@ function emitOwnKeys(doc, ctx, accessor, kVar, body2, onSymbol) {
29468
29468
  if (onSymbol)
29469
29469
  d.write(onSymbol);
29470
29470
  else
29471
- body2(d);
29471
+ body3(d);
29472
29472
  });
29473
29473
  doc.write(`}`);
29474
29474
  }
@@ -32375,11 +32375,11 @@ function normalizeObjectSchema(schema) {
32375
32375
  }
32376
32376
  return void 0;
32377
32377
  }
32378
- function getDotPath(path12) {
32379
- if (path12.length === 0) {
32378
+ function getDotPath(path13) {
32379
+ if (path13.length === 0) {
32380
32380
  return "object root";
32381
32381
  }
32382
- return path12.reduce((acc, seg, index) => {
32382
+ return path13.reduce((acc, seg, index) => {
32383
32383
  if (index === 0) {
32384
32384
  return String(seg);
32385
32385
  }
@@ -34621,13 +34621,13 @@ function resolveRef(ref, ctx) {
34621
34621
  if (!ref.startsWith("#")) {
34622
34622
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
34623
34623
  }
34624
- const path12 = ref.slice(1).split("/").filter(Boolean);
34625
- if (path12.length === 0) {
34624
+ const path13 = ref.slice(1).split("/").filter(Boolean);
34625
+ if (path13.length === 0) {
34626
34626
  return ctx.rootSchema;
34627
34627
  }
34628
34628
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
34629
- if (path12[0] === defsKey) {
34630
- const key2 = path12[1] === void 0 ? void 0 : decodeJSONPointerSegment(path12[1]);
34629
+ if (path13[0] === defsKey) {
34630
+ const key2 = path13[1] === void 0 ? void 0 : decodeJSONPointerSegment(path13[1]);
34631
34631
  if (!key2 || !ctx.defs[key2]) {
34632
34632
  throw new Error(`Reference not found: ${ref}`);
34633
34633
  }
@@ -38765,7 +38765,7 @@ var Protocol = class {
38765
38765
  return;
38766
38766
  }
38767
38767
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
38768
- await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
38768
+ await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
38769
38769
  options?.signal?.throwIfAborted();
38770
38770
  }
38771
38771
  } catch (error62) {
@@ -38782,7 +38782,7 @@ var Protocol = class {
38782
38782
  */
38783
38783
  request(request, resultSchema, options) {
38784
38784
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
38785
- return new Promise((resolve4, reject) => {
38785
+ return new Promise((resolve5, reject) => {
38786
38786
  const earlyReject = (error62) => {
38787
38787
  reject(error62);
38788
38788
  };
@@ -38860,7 +38860,7 @@ var Protocol = class {
38860
38860
  if (!parseResult.success) {
38861
38861
  reject(parseResult.error);
38862
38862
  } else {
38863
- resolve4(parseResult.data);
38863
+ resolve5(parseResult.data);
38864
38864
  }
38865
38865
  } catch (error62) {
38866
38866
  reject(error62);
@@ -39122,12 +39122,12 @@ var Protocol = class {
39122
39122
  }
39123
39123
  } catch {
39124
39124
  }
39125
- return new Promise((resolve4, reject) => {
39125
+ return new Promise((resolve5, reject) => {
39126
39126
  if (signal.aborted) {
39127
39127
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
39128
39128
  return;
39129
39129
  }
39130
- const timeoutId = setTimeout(resolve4, interval);
39130
+ const timeoutId = setTimeout(resolve5, interval);
39131
39131
  signal.addEventListener("abort", () => {
39132
39132
  clearTimeout(timeoutId);
39133
39133
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -40270,7 +40270,7 @@ var McpServer = class {
40270
40270
  let task = createTaskResult.task;
40271
40271
  const pollInterval = task.pollInterval ?? 5e3;
40272
40272
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
40273
- await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
40273
+ await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
40274
40274
  const updatedTask = await extra.taskStore.getTask(taskId);
40275
40275
  if (!updatedTask) {
40276
40276
  throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
@@ -40936,12 +40936,12 @@ var StdioServerTransport = class {
40936
40936
  this.onclose?.();
40937
40937
  }
40938
40938
  send(message) {
40939
- return new Promise((resolve4) => {
40939
+ return new Promise((resolve5) => {
40940
40940
  const json2 = serializeMessage(message);
40941
40941
  if (this._stdout.write(json2)) {
40942
- resolve4();
40942
+ resolve5();
40943
40943
  } else {
40944
- this._stdout.once("drain", resolve4);
40944
+ this._stdout.once("drain", resolve5);
40945
40945
  }
40946
40946
  });
40947
40947
  }
@@ -41243,8 +41243,8 @@ function codexMessages(lines) {
41243
41243
  ${text2}`;
41244
41244
  else messages.push({ id: `codex-${n++}`, who, text: text2 });
41245
41245
  } else if ((item.type === "function_call" || item.type === "custom_tool_call") && /patch/.test(String(item.name ?? ""))) {
41246
- const body2 = String(item.arguments ?? item.input ?? "");
41247
- for (const m of body2.matchAll(/\*\*\* (?:Add|Update|Delete) File: ([^\n\\"]+)/g)) files.add(m[1].trim());
41246
+ const body3 = String(item.arguments ?? item.input ?? "");
41247
+ for (const m of body3.matchAll(/\*\*\* (?:Add|Update|Delete) File: ([^\n\\"]+)/g)) files.add(m[1].trim());
41248
41248
  }
41249
41249
  }
41250
41250
  return { messages, files: [...files] };
@@ -41361,7 +41361,7 @@ init_define_AIRBAND_GRAMMARS();
41361
41361
  var ASK_MAX = 600;
41362
41362
  var DID_MAX = 400;
41363
41363
  var OPEN_MAX = 200;
41364
- var REFS_MAX = 8;
41364
+ var REFS_MAX = 12;
41365
41365
  var HOOK_START_MAX = 8 * 1024 * 1024;
41366
41366
  var HOOK_STEP_MAX = 16 * 1024 * 1024;
41367
41367
  var dir = () => airbandFile("flightlogs");
@@ -41405,11 +41405,41 @@ function listHeads() {
41405
41405
  }
41406
41406
  var PR_URL = /github\.com\/[\w.-]+\/[\w.-]+\/pull\/(\d+)/g;
41407
41407
  var PR_WORD = /\b(?:PR|pull request) #(\d{1,6})\b/gi;
41408
+ var ISSUE_URL = /github\.com\/[\w.-]+\/[\w.-]+\/issues\/(\d+)/g;
41409
+ var ISSUE_WORD = /\bissue #(\d{1,6})\b/gi;
41410
+ var HASH_NUMBER = /(?<![\w&/#])#(\d{2,6})(?![\w-])/g;
41411
+ var COLOUR_NEAR = /colou?r|css|hex|rgb|background|fill|stroke|border|text-\[|bg-\[/i;
41412
+ var TICKET = /(?<![\w-])(([A-Z][A-Z0-9]{1,9})-\d{1,6})(?![\w-])/g;
41413
+ var NOT_TICKETS = new Set("UTF SHA ISO ES GPT HTTP RFC CVE COVID MD AES RSA TLS SSL IPV ECMA PEP WCAG CSS HTML ARM UTC GMT IST PST CET EST ID OS AI TS JS UI UX API URL SQL NS IE PS RS XP UTF8 H2 R2 S3 EC2 K8S".split(" "));
41414
+ var TICKET_URL = /(?:linear\.app\/[\w-]+\/issue|atlassian\.net\/browse)\/([A-Za-z][A-Za-z0-9]{1,9}-\d{1,6})/g;
41415
+ var FIGMA_URL = /figma\.com\/(?:design|file|board|proto|make|slides)\/([A-Za-z0-9]{10,})(?:\/([^\s?#)\]"'`]+))?(?:\?[^\s)\]"'`]*?node-id=([\d]+[-:][\d]+))?/g;
41416
+ function figmaRef(m) {
41417
+ let name2 = m[2];
41418
+ try {
41419
+ name2 = name2 ? decodeURIComponent(name2) : void 0;
41420
+ } catch {
41421
+ }
41422
+ const node2 = m[3] ? ` node ${m[3].replace("-", ":")}` : "";
41423
+ return `Figma ${(name2 ?? m[1]).slice(0, 40)}${node2}`;
41424
+ }
41408
41425
  var COMMIT_LINE = /\[[\w./-]+ ([0-9a-f]{7,12})\][^\[]{0,300}?(?:\n|\\n) ?\d+ files? changed/g;
41409
41426
  var COMMIT_QUOTED = /`([0-9a-f]{7,12})`/g;
41410
41427
  function refsIn(text2, into, raw) {
41411
41428
  for (const m of text2.matchAll(PR_URL)) into.add(`PR #${m[1]}`);
41412
- if (!raw) for (const m of text2.matchAll(PR_WORD)) into.add(`PR #${m[1]}`);
41429
+ for (const m of text2.matchAll(ISSUE_URL)) into.add(`issue #${m[1]}`);
41430
+ for (const m of text2.matchAll(TICKET_URL)) into.add(m[1].toUpperCase());
41431
+ for (const m of text2.matchAll(FIGMA_URL)) into.add(figmaRef(m));
41432
+ if (!raw) {
41433
+ for (const m of text2.matchAll(PR_WORD)) into.add(`PR #${m[1]}`);
41434
+ for (const m of text2.matchAll(ISSUE_WORD)) into.add(`issue #${m[1]}`);
41435
+ for (const m of text2.matchAll(TICKET)) if (!NOT_TICKETS.has(m[2])) into.add(m[1]);
41436
+ for (const m of text2.matchAll(HASH_NUMBER)) {
41437
+ const n = m[1];
41438
+ if (into.has(`PR #${n}`) || into.has(`issue #${n}`)) continue;
41439
+ if (COLOUR_NEAR.test(text2.slice(Math.max(0, (m.index ?? 0) - 40), (m.index ?? 0) + 12))) continue;
41440
+ into.add(`#${n}`);
41441
+ }
41442
+ }
41413
41443
  for (const m of text2.matchAll(raw ? COMMIT_LINE : COMMIT_QUOTED)) if (/\d/.test(m[1]) && /[a-f]/.test(m[1])) into.add(m[1].slice(0, 9));
41414
41444
  }
41415
41445
  var SYSTEM_TURN = /^(<task-notification>|<agent-message|<local-command-|Stop hook feedback|Another Claude session sent a message|\[Request interrupted|Caveat: The messages below|<system-reminder>|\[(?:Airband|Crosstalk|Relay)\])/;
@@ -41516,6 +41546,7 @@ function openItem(reply) {
41516
41546
  }
41517
41547
  function toAsk(e, n) {
41518
41548
  const refs = /* @__PURE__ */ new Set();
41549
+ refsIn(e.ask, refs, false);
41519
41550
  refsIn(e.reply, refs, false);
41520
41551
  for (const r of e.refs) refs.add(r);
41521
41552
  const ask = {
@@ -41656,8 +41687,8 @@ function exchangeText(id, n, max = 2e4) {
41656
41687
 
41657
41688
  // src/codemap/index.ts
41658
41689
  init_define_AIRBAND_GRAMMARS();
41659
- var fs12 = __toESM(require("node:fs"));
41660
- var path9 = __toESM(require("node:path"));
41690
+ var fs13 = __toESM(require("node:fs"));
41691
+ var path10 = __toESM(require("node:path"));
41661
41692
 
41662
41693
  // src/codemap/extract.ts
41663
41694
  init_define_AIRBAND_GRAMMARS();
@@ -41740,14 +41771,14 @@ function bundledDir() {
41740
41771
  }
41741
41772
  }
41742
41773
  function httpsGet(url2, redirects = 3) {
41743
- return new Promise((resolve4, reject) => {
41774
+ return new Promise((resolve5, reject) => {
41744
41775
  const req = https.get(url2, { timeout: 3e4, headers: { "user-agent": "airband" } }, (res) => {
41745
41776
  const status = res.statusCode ?? 0;
41746
41777
  if (status >= 300 && status < 400 && res.headers.location && redirects > 0) {
41747
41778
  res.resume();
41748
41779
  const next = new URL(res.headers.location, url2);
41749
41780
  if (next.protocol !== "https:") return reject(new Error("refused a redirect away from https"));
41750
- return resolve4(httpsGet(next.toString(), redirects - 1));
41781
+ return resolve5(httpsGet(next.toString(), redirects - 1));
41751
41782
  }
41752
41783
  if (status !== 200) {
41753
41784
  res.resume();
@@ -41760,7 +41791,7 @@ function httpsGet(url2, redirects = 3) {
41760
41791
  if (size > 8 * 1024 * 1024) req.destroy(new Error("too large"));
41761
41792
  else chunks.push(c);
41762
41793
  });
41763
- res.on("end", () => resolve4(Buffer.concat(chunks)));
41794
+ res.on("end", () => resolve5(Buffer.concat(chunks)));
41764
41795
  res.on("error", reject);
41765
41796
  });
41766
41797
  const deadline = setTimeout(() => req.destroy(new Error("timed out")), 3e4);
@@ -41829,7 +41860,7 @@ var nameField = (n) => field(n, "name")?.text;
41829
41860
  var unquote = (t) => t.replace(/^[`'"]|[`'"]$/g, "");
41830
41861
  var hasChild = (n, test) => n.children.some((c) => !!c && test(c));
41831
41862
  var modifiersText = (n) => n.children.filter((c) => !!c && /modifier/.test(c.type)).map((c) => c.text).join(" ");
41832
- var typeKind = (body2) => body2?.type === "interface_type" ? "interface" : body2?.type === "struct_type" ? "class" : "type";
41863
+ var typeKind = (body3) => body3?.type === "interface_type" ? "interface" : body3?.type === "struct_type" ? "class" : "type";
41833
41864
  var TABLES = {
41834
41865
  go: {
41835
41866
  defs: { function_declaration: "function", method_declaration: "method", type_spec: "type", const_spec: "const" },
@@ -41911,8 +41942,8 @@ var TABLES = {
41911
41942
  if (f?.type === "identifier") return [void 0, f.text];
41912
41943
  if (f?.type === "scoped_identifier") {
41913
41944
  const name2 = field(f, "name")?.text;
41914
- const path12 = field(f, "path")?.text.split("::").pop();
41915
- if (path12 && /^[A-Z]\w*$/.test(path12)) return [void 0, path12];
41945
+ const path13 = field(f, "path")?.text.split("::").pop();
41946
+ if (path13 && /^[A-Z]\w*$/.test(path13)) return [void 0, path13];
41916
41947
  if (name2) return [void 0, name2];
41917
41948
  }
41918
41949
  }
@@ -42274,8 +42305,8 @@ function tsDecls(root2, jsx, isLocal) {
42274
42305
  if (re) imp.re = true;
42275
42306
  imports.push(imp);
42276
42307
  };
42277
- const classBody = (body2, cls, exported) => {
42278
- for (const m of body2?.namedChildren ?? []) {
42308
+ const classBody = (body3, cls, exported) => {
42309
+ for (const m of body3?.namedChildren ?? []) {
42279
42310
  if (!m) continue;
42280
42311
  if (m.type === "method_definition" || m.type === "method_signature" || m.type === "abstract_method_signature") {
42281
42312
  const name2 = m.childForFieldName("name")?.text;
@@ -43262,7 +43293,7 @@ function parseDoc(text2) {
43262
43293
  }
43263
43294
  return { head, body: m[2].trim() };
43264
43295
  }
43265
- function render(head, body2) {
43296
+ function render(head, body3) {
43266
43297
  const lines = [`module: ${head.module}`, `status: ${head.status}`];
43267
43298
  if (head.code) lines.push(`code: ${head.code}`);
43268
43299
  if (head.approved) lines.push(`approved: ${head.approved}`);
@@ -43270,7 +43301,7 @@ function render(head, body2) {
43270
43301
  ${lines.join("\n")}
43271
43302
  ---
43272
43303
 
43273
- ${body2.trim()}
43304
+ ${body3.trim()}
43274
43305
  `;
43275
43306
  }
43276
43307
  function snapshotPath(storeDir2) {
@@ -43292,9 +43323,9 @@ function readModuleDoc(root2, module2, files, storeDir2) {
43292
43323
  } catch {
43293
43324
  return { module: module2.id, file: file2, status: "missing", currentCode, body: "" };
43294
43325
  }
43295
- const { head, body: body2 } = parseDoc(text2);
43326
+ const { head, body: body3 } = parseDoc(text2);
43296
43327
  const status = head.status === "approved" ? "approved" : "draft";
43297
- const doc = { module: module2.id, file: file2, status, approvedCode: head.code, currentCode, approvedOn: head.approved, body: body2 };
43328
+ const doc = { module: module2.id, file: file2, status, approvedCode: head.code, currentCode, approvedOn: head.approved, body: body3 };
43298
43329
  if (status === "approved" && head.code && head.code !== currentCode) {
43299
43330
  const snap = readSnapshots(storeDir2)[module2.id];
43300
43331
  if (snap) {
@@ -43308,9 +43339,9 @@ function readModuleDoc(root2, module2, files, storeDir2) {
43308
43339
  }
43309
43340
  function approveModuleDoc(root2, module2, files, storeDir2, today2 = /* @__PURE__ */ new Date()) {
43310
43341
  const file2 = docPath(root2, module2.id);
43311
- const { body: body2 } = parseDoc(fs9.readFileSync(file2, "utf8"));
43342
+ const { body: body3 } = parseDoc(fs9.readFileSync(file2, "utf8"));
43312
43343
  const code = codeFingerprint(module2, files);
43313
- fs9.writeFileSync(file2, render({ module: module2.id, status: "approved", code, approved: today2.toISOString().slice(0, 10) }, body2));
43344
+ fs9.writeFileSync(file2, render({ module: module2.id, status: "approved", code, approved: today2.toISOString().slice(0, 10) }, body3));
43314
43345
  const snaps = readSnapshots(storeDir2);
43315
43346
  snaps[module2.id] = Object.fromEntries(module2.files.map((p) => [p, files.get(p)?.h ?? ""]));
43316
43347
  fs9.mkdirSync(storeDir2, { recursive: true });
@@ -43561,12 +43592,17 @@ function makeResolver(root2, files) {
43561
43592
 
43562
43593
  // src/codemap/store.ts
43563
43594
  init_define_AIRBAND_GRAMMARS();
43595
+ var crypto5 = __toESM(require("node:crypto"));
43596
+ var fs12 = __toESM(require("node:fs"));
43597
+ var path9 = __toESM(require("node:path"));
43598
+ var zlib = __toESM(require("node:zlib"));
43599
+ var import_node_child_process = require("node:child_process");
43600
+
43601
+ // src/codemap/where.ts
43602
+ init_define_AIRBAND_GRAMMARS();
43564
43603
  var crypto4 = __toESM(require("node:crypto"));
43565
43604
  var fs11 = __toESM(require("node:fs"));
43566
43605
  var path8 = __toESM(require("node:path"));
43567
- var zlib = __toESM(require("node:zlib"));
43568
- var import_node_child_process = require("node:child_process");
43569
- var STORE_VERSION = 1;
43570
43606
  function folderId(root2) {
43571
43607
  let real = root2;
43572
43608
  try {
@@ -43579,14 +43615,49 @@ function folderId(root2) {
43579
43615
  function storeDir(root2) {
43580
43616
  return airbandFile("codemap", folderId(root2));
43581
43617
  }
43582
- var filesPath = (root2) => path8.join(storeDir(root2), "files.jsonl.gz");
43583
- var metaPath = (root2) => path8.join(storeDir(root2), "meta.json");
43618
+ function mappedProjects() {
43619
+ const out2 = [];
43620
+ let dirs = [];
43621
+ try {
43622
+ dirs = fs11.readdirSync(airbandFile("codemap"));
43623
+ } catch {
43624
+ return out2;
43625
+ }
43626
+ for (const d of dirs) {
43627
+ try {
43628
+ const meta3 = JSON.parse(fs11.readFileSync(airbandFile("codemap", d, "meta.json"), "utf8"));
43629
+ if (meta3.root && fs11.existsSync(meta3.root)) out2.push({ name: path8.basename(meta3.root), root: meta3.root, files: meta3.files ?? 0, builtAt: meta3.builtAt ?? 0 });
43630
+ } catch {
43631
+ }
43632
+ }
43633
+ return out2.sort((a, b) => b.builtAt - a.builtAt);
43634
+ }
43635
+ function findProject(name2, from = process.cwd()) {
43636
+ const q = name2.trim();
43637
+ const all = mappedProjects();
43638
+ const asPath = path8.resolve(from, q.replace(/^~(?=$|\/)/, process.env.HOME ?? "~"));
43639
+ const byPath = all.find((p) => p.root === asPath);
43640
+ if (byPath) return byPath;
43641
+ const lower = q.toLowerCase();
43642
+ const exact = all.filter((p) => p.name.toLowerCase() === lower);
43643
+ const hits = exact.length ? exact : all.filter((p) => p.name.toLowerCase().includes(lower));
43644
+ if (hits.length === 1 || hits.length > 1 && exact.length === 1) return hits[0];
43645
+ if (hits.length > 1) return `Several mapped projects match "${q}": ${hits.map((p) => p.root).join(", ")}. Name one by its path.`;
43646
+ if (fs11.existsSync(asPath) && fs11.statSync(asPath).isDirectory()) return { name: path8.basename(asPath), root: asPath, files: 0, builtAt: 0 };
43647
+ const names = all.map((p) => p.name);
43648
+ return `No mapped project called "${q}".${names.length ? ` Mapped here: ${names.slice(0, 12).join(", ")}.` : ""} Map one first: airband map <folder>.`;
43649
+ }
43650
+
43651
+ // src/codemap/store.ts
43652
+ var STORE_VERSION = 1;
43653
+ var filesPath = (root2) => path9.join(storeDir(root2), "files.jsonl.gz");
43654
+ var metaPath = (root2) => path9.join(storeDir(root2), "meta.json");
43584
43655
  function loadEntries(root2) {
43585
43656
  const out2 = /* @__PURE__ */ new Map();
43586
43657
  try {
43587
- const meta3 = JSON.parse(fs11.readFileSync(metaPath(root2), "utf8"));
43658
+ const meta3 = JSON.parse(fs12.readFileSync(metaPath(root2), "utf8"));
43588
43659
  if (meta3.v !== STORE_VERSION) return out2;
43589
- const text2 = zlib.gunzipSync(fs11.readFileSync(filesPath(root2))).toString("utf8");
43660
+ const text2 = zlib.gunzipSync(fs12.readFileSync(filesPath(root2))).toString("utf8");
43590
43661
  for (const line of text2.split("\n")) {
43591
43662
  if (!line) continue;
43592
43663
  try {
@@ -43607,24 +43678,24 @@ function saveEntries(root2, entries) {
43607
43678
  files++;
43608
43679
  }
43609
43680
  const gz = zlib.gzipSync(lines.join("\n"), { level: 6 });
43610
- fs11.mkdirSync(storeDir(root2), { recursive: true });
43681
+ fs12.mkdirSync(storeDir(root2), { recursive: true });
43611
43682
  const tmp = `${filesPath(root2)}.${process.pid}.${Date.now()}.tmp`;
43612
- fs11.writeFileSync(tmp, gz);
43613
- fs11.renameSync(tmp, filesPath(root2));
43683
+ fs12.writeFileSync(tmp, gz);
43684
+ fs12.renameSync(tmp, filesPath(root2));
43614
43685
  const meta3 = { v: STORE_VERSION, root: root2, builtAt: Date.now(), files, bytes: gz.length };
43615
43686
  writeFileAtomic(metaPath(root2), JSON.stringify(meta3));
43616
43687
  return meta3;
43617
43688
  }
43618
43689
  function readMeta(root2) {
43619
43690
  try {
43620
- const meta3 = JSON.parse(fs11.readFileSync(metaPath(root2), "utf8"));
43691
+ const meta3 = JSON.parse(fs12.readFileSync(metaPath(root2), "utf8"));
43621
43692
  return meta3.v === STORE_VERSION ? meta3 : void 0;
43622
43693
  } catch {
43623
43694
  return void 0;
43624
43695
  }
43625
43696
  }
43626
43697
  function contentHash(text2) {
43627
- return crypto4.createHash("sha1").update(text2).digest("hex").slice(0, 16);
43698
+ return crypto5.createHash("sha1").update(text2).digest("hex").slice(0, 16);
43628
43699
  }
43629
43700
  var SKIP_DIR = /(^|\/)(node_modules|\.git|\.next|\.nuxt|\.svelte-kit|\.turbo|\.vercel|\.cache|dist|build|out|out-test|coverage|vendor|venv|\.venv|env|__pycache__|\.mypy_cache|\.pytest_cache|\.tox|site-packages|bower_components|\.airband|\.context|\.claude|\.codex|\.gemini|storybook-static|playwright-report|test-results)(\/|$)/;
43630
43701
  var SKIP_FILE = /(\.min\.(js|mjs|cjs)|\.bundle\.js|\.chunk\.js|-lock\.json|\.map|\.generated\.(ts|js)|\.gen\.(ts|js)|_pb2(_grpc)?\.py)$/;
@@ -43633,12 +43704,12 @@ function mappable(rel) {
43633
43704
  return !!langOf(rel) && !SKIP_DIR.test(rel) && !TABLE_SKIP_DIR.test(rel) && !SKIP_FILE.test(rel);
43634
43705
  }
43635
43706
  async function listFiles(root2) {
43636
- const fromGit = await new Promise((resolve4) => {
43707
+ const fromGit = await new Promise((resolve5) => {
43637
43708
  (0, import_node_child_process.execFile)(
43638
43709
  "git",
43639
43710
  ["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
43640
43711
  { cwd: root2, maxBuffer: 256 * 1024 * 1024 },
43641
- (err2, stdout) => resolve4(err2 ? void 0 : stdout.split("\0").filter(Boolean))
43712
+ (err2, stdout) => resolve5(err2 ? void 0 : stdout.split("\0").filter(Boolean))
43642
43713
  );
43643
43714
  });
43644
43715
  if (fromGit) return [...new Set(fromGit)].filter(mappable).sort();
@@ -43647,14 +43718,14 @@ async function listFiles(root2) {
43647
43718
  if (depth > 20 || out2.length > 5e4) return;
43648
43719
  let items;
43649
43720
  try {
43650
- items = fs11.readdirSync(dir2, { withFileTypes: true });
43721
+ items = fs12.readdirSync(dir2, { withFileTypes: true });
43651
43722
  } catch {
43652
43723
  return;
43653
43724
  }
43654
43725
  for (const it of items) {
43655
43726
  const r = rel ? `${rel}/${it.name}` : it.name;
43656
43727
  if (it.isDirectory()) {
43657
- if (!SKIP_DIR.test(`${r}/`) && !it.name.startsWith(".")) walk(path8.join(dir2, it.name), r, depth + 1);
43728
+ if (!SKIP_DIR.test(`${r}/`) && !it.name.startsWith(".")) walk(path9.join(dir2, it.name), r, depth + 1);
43658
43729
  } else if (it.isFile() && mappable(r)) out2.push(r);
43659
43730
  }
43660
43731
  };
@@ -43731,7 +43802,7 @@ var CodeMap = class {
43731
43802
  nameExists(name2) {
43732
43803
  this.load();
43733
43804
  const rel = name2.replace(/^\.\//, "");
43734
- if (this.files.has(rel) || fs12.existsSync(path9.join(this.root, rel))) return true;
43805
+ if (this.files.has(rel) || fs13.existsSync(path10.join(this.root, rel))) return true;
43735
43806
  for (const f of this.files.values()) if (f.d.some((d) => d.n === name2)) return true;
43736
43807
  return false;
43737
43808
  }
@@ -43782,7 +43853,7 @@ var CodeMap = class {
43782
43853
  let removed = 0;
43783
43854
  const listing = full || !this.files.size || Date.now() - this.lastListed > LIST_EVERY_MS || this.foldersChanged();
43784
43855
  if (changed && !full) {
43785
- paths = changed.map((p) => (path9.isAbsolute(p) ? path9.relative(this.root, p) : p).split(path9.sep).join("/")).filter((p) => !p.startsWith(".."));
43856
+ paths = changed.map((p) => (path10.isAbsolute(p) ? path10.relative(this.root, p) : p).split(path10.sep).join("/")).filter((p) => !p.startsWith(".."));
43786
43857
  } else if (listing) {
43787
43858
  paths = await listFiles(this.root);
43788
43859
  this.lastListed = Date.now();
@@ -43803,10 +43874,10 @@ var CodeMap = class {
43803
43874
  let lastYield = Date.now();
43804
43875
  for (const p of paths) {
43805
43876
  if (!langOf(p)) continue;
43806
- const abs = path9.join(this.root, p);
43877
+ const abs = path10.join(this.root, p);
43807
43878
  let st;
43808
43879
  try {
43809
- st = fs12.lstatSync(abs);
43880
+ st = fs13.lstatSync(abs);
43810
43881
  } catch {
43811
43882
  if (this.files.delete(p)) removed++;
43812
43883
  continue;
@@ -43819,7 +43890,7 @@ var CodeMap = class {
43819
43890
  if (prev && prev.z === st.size && prev.m === Math.floor(st.mtimeMs)) continue;
43820
43891
  let text2;
43821
43892
  try {
43822
- text2 = fs12.readFileSync(abs, "utf8");
43893
+ text2 = fs13.readFileSync(abs, "utf8");
43823
43894
  } catch {
43824
43895
  continue;
43825
43896
  }
@@ -43856,15 +43927,15 @@ var CodeMap = class {
43856
43927
  this.dirTimes.clear();
43857
43928
  const dirs = /* @__PURE__ */ new Set([""]);
43858
43929
  for (const p of paths) {
43859
- let d = path9.posix.dirname(p);
43930
+ let d = path10.posix.dirname(p);
43860
43931
  while (d !== "." && !dirs.has(d)) {
43861
43932
  dirs.add(d);
43862
- d = path9.posix.dirname(d);
43933
+ d = path10.posix.dirname(d);
43863
43934
  }
43864
43935
  }
43865
43936
  for (const d of dirs) {
43866
43937
  try {
43867
- this.dirTimes.set(d, fs12.statSync(path9.join(this.root, d)).mtimeMs);
43938
+ this.dirTimes.set(d, fs13.statSync(path10.join(this.root, d)).mtimeMs);
43868
43939
  } catch {
43869
43940
  }
43870
43941
  }
@@ -43874,7 +43945,7 @@ var CodeMap = class {
43874
43945
  if (!this.dirTimes.size) return false;
43875
43946
  for (const [d, t] of this.dirTimes) {
43876
43947
  try {
43877
- if (fs12.statSync(path9.join(this.root, d)).mtimeMs !== t) return true;
43948
+ if (fs13.statSync(path10.join(this.root, d)).mtimeMs !== t) return true;
43878
43949
  } catch {
43879
43950
  return true;
43880
43951
  }
@@ -43887,7 +43958,7 @@ var CodeMap = class {
43887
43958
  const rank = graph.rank;
43888
43959
  const near = /* @__PURE__ */ new Set();
43889
43960
  for (const f of focus ?? []) {
43890
- const rel = path9.isAbsolute(f) ? path9.relative(this.root, f).split(path9.sep).join("/") : f;
43961
+ const rel = path10.isAbsolute(f) ? path10.relative(this.root, f).split(path10.sep).join("/") : f;
43891
43962
  if (!this.files.has(rel)) continue;
43892
43963
  near.add(rel);
43893
43964
  for (const t of graph.imports.get(rel) ?? []) near.add(t);
@@ -43943,7 +44014,7 @@ var CodeMap = class {
43943
44014
  outline(target, budget = 600) {
43944
44015
  this.load();
43945
44016
  const t = target.trim().replace(/^\.\//, "").replace(/\/$/, "");
43946
- const rel = path9.isAbsolute(t) ? path9.relative(this.root, t).split(path9.sep).join("/") : t;
44017
+ const rel = path10.isAbsolute(t) ? path10.relative(this.root, t).split(path10.sep).join("/") : t;
43947
44018
  const file2 = this.files.get(rel);
43948
44019
  if (file2) return this.fileOutline(file2, budget);
43949
44020
  const prefix = rel === "" || rel === "." ? "" : `${rel}/`;
@@ -43963,7 +44034,7 @@ var CodeMap = class {
43963
44034
  }
43964
44035
  signature(file2, d) {
43965
44036
  try {
43966
- const text2 = fs12.readFileSync(path9.join(this.root, file2.p), "utf8");
44037
+ const text2 = fs13.readFileSync(path10.join(this.root, file2.p), "utf8");
43967
44038
  const lines = text2.split("\n").slice(d.s - 1, Math.min(d.e, d.s + 3));
43968
44039
  let sig = "";
43969
44040
  for (const l of lines) {
@@ -44011,7 +44082,7 @@ var CodeMap = class {
44011
44082
  }
44012
44083
  const rank = (f) => this.graph.rank.get(f.p) ?? 0;
44013
44084
  const out2 = [`${prefix || "./"} ${files.length} files`];
44014
- const mod = this.modules().find((m) => `${m.id}/` === prefix) ?? (prefix && fs12.existsSync(docPath(this.root, prefix.slice(0, -1))) ? this.moduleOrFolder(prefix.slice(0, -1)) : void 0);
44085
+ const mod = this.modules().find((m) => `${m.id}/` === prefix) ?? (prefix && fs13.existsSync(docPath(this.root, prefix.slice(0, -1))) ? this.moduleOrFolder(prefix.slice(0, -1)) : void 0);
44015
44086
  let doc;
44016
44087
  if (mod) {
44017
44088
  if (mod.dependsOn.length) out2.push(`uses: ${mod.dependsOn.join(", ")}`);
@@ -44115,15 +44186,15 @@ ${edgeLines(uses, "to", 10)}`);
44115
44186
  overview(budget = 500) {
44116
44187
  this.load();
44117
44188
  const out2 = [];
44118
- const pkg = readJsonFile(path9.join(this.root, "package.json"));
44189
+ const pkg = readJsonFile(path10.join(this.root, "package.json"));
44119
44190
  if (pkg?.scripts) {
44120
44191
  const keep = Object.keys(pkg.scripts).filter((s) => /^(dev|start|build|test|lint|typecheck|check|e2e|format)(:|$)/.test(s)).slice(0, 8);
44121
44192
  if (keep.length) out2.push(`commands: ${keep.map((s) => `npm run ${s}`).join(" \xB7 ")}`);
44122
44193
  }
44123
- if (fs12.existsSync(path9.join(this.root, "pyproject.toml"))) out2.push("python: pyproject.toml");
44124
- if (fs12.existsSync(path9.join(this.root, "Makefile"))) {
44194
+ if (fs13.existsSync(path10.join(this.root, "pyproject.toml"))) out2.push("python: pyproject.toml");
44195
+ if (fs13.existsSync(path10.join(this.root, "Makefile"))) {
44125
44196
  try {
44126
- const targets = [...fs12.readFileSync(path9.join(this.root, "Makefile"), "utf8").matchAll(/^([a-zA-Z][\w-]*):/gm)].map((m) => m[1]).slice(0, 8);
44197
+ const targets = [...fs13.readFileSync(path10.join(this.root, "Makefile"), "utf8").matchAll(/^([a-zA-Z][\w-]*):/gm)].map((m) => m[1]).slice(0, 8);
44127
44198
  if (targets.length) out2.push(`make: ${targets.join(" \xB7 ")}`);
44128
44199
  } catch {
44129
44200
  }
@@ -44189,7 +44260,7 @@ ${conv.map((c) => ` ${c}`).join("\n")}`);
44189
44260
  for (const f of this.files.values()) {
44190
44261
  let text2;
44191
44262
  try {
44192
- text2 = fs12.readFileSync(path9.join(this.root, f.p), "utf8");
44263
+ text2 = fs13.readFileSync(path10.join(this.root, f.p), "utf8");
44193
44264
  } catch {
44194
44265
  continue;
44195
44266
  }
@@ -44227,7 +44298,7 @@ ${conv.map((c) => ` ${c}`).join("\n")}`);
44227
44298
  };
44228
44299
  function readJsonFile(file2) {
44229
44300
  try {
44230
- return JSON.parse(fs12.readFileSync(file2, "utf8"));
44301
+ return JSON.parse(fs13.readFileSync(file2, "utf8"));
44231
44302
  } catch {
44232
44303
  return void 0;
44233
44304
  }
@@ -44270,9 +44341,213 @@ function clip2(text2, budget) {
44270
44341
  \u2026 (cut to fit; ask about one part for more)`;
44271
44342
  }
44272
44343
 
44344
+ // src/codemap/diff.ts
44345
+ init_define_AIRBAND_GRAMMARS();
44346
+ var import_node_child_process2 = require("node:child_process");
44347
+ var REF = /^[A-Za-z0-9][A-Za-z0-9._/@~^{}-]*$/;
44348
+ var PR_NUMBER = /^(?:#|pr[-/ ]?|pull\/)(\d{1,7})$/i;
44349
+ var FILES_MAX = 40;
44350
+ var FILE_BYTES_MAX = 512 * 1024;
44351
+ var TEST_FILE = /(^|\/)(tests?|__tests__|spec|specs)\/|\.(test|spec)\.[cm]?[jt]sx?$|_test\.(go|py)$|(^|\/)test_[^/]+\.py$|Tests?\.(cs|java)$|_spec\.rb$/;
44352
+ var isTestFile = (p) => TEST_FILE.test(p);
44353
+ function git(root2, args2, maxBuffer = 16 * 1024 * 1024) {
44354
+ return (0, import_node_child_process2.execFileSync)("git", ["-C", root2, ...args2], { encoding: "utf8", maxBuffer, timeout: 2e4, stdio: ["ignore", "pipe", "pipe"] });
44355
+ }
44356
+ function commit(root2, ref) {
44357
+ if (!REF.test(ref)) return void 0;
44358
+ try {
44359
+ return git(root2, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]).trim() || void 0;
44360
+ } catch {
44361
+ return void 0;
44362
+ }
44363
+ }
44364
+ function defaultBranch(root2) {
44365
+ try {
44366
+ const head = git(root2, ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]).trim().replace(/^refs\/remotes\//, "");
44367
+ if (head && commit(root2, head)) return head;
44368
+ } catch {
44369
+ }
44370
+ return ["origin/main", "main", "origin/master", "master", "origin/develop", "develop"].find((b) => commit(root2, b));
44371
+ }
44372
+ function fetchPull(root2, n) {
44373
+ try {
44374
+ git(root2, ["fetch", "--quiet", "--no-tags", "origin", `pull/${n}/head`]);
44375
+ return commit(root2, "FETCH_HEAD");
44376
+ } catch {
44377
+ return void 0;
44378
+ }
44379
+ }
44380
+ function resolveRange(root2, range) {
44381
+ const r = range.trim() || "HEAD";
44382
+ let baseRef;
44383
+ let headRef = r;
44384
+ const two = r.split(/\.{2,3}/);
44385
+ if (two.length === 2) [baseRef, headRef] = [two[0] || "HEAD", two[1] || "HEAD"];
44386
+ let head;
44387
+ const pr = PR_NUMBER.exec(headRef);
44388
+ if (pr) {
44389
+ head = commit(root2, `origin/pr/${pr[1]}`) ?? fetchPull(root2, pr[1]);
44390
+ if (!head) return `Could not get pull request #${pr[1]} from origin. Fetch it (git fetch origin pull/${pr[1]}/head) or name its branch.`;
44391
+ headRef = `#${pr[1]}`;
44392
+ } else {
44393
+ head = commit(root2, headRef);
44394
+ if (!head) return `"${headRef}" is not a branch, tag or commit here. Try git fetch, or name it as origin/${headRef}.`;
44395
+ }
44396
+ baseRef ??= defaultBranch(root2);
44397
+ if (!baseRef) return "No main or master branch to compare with: give a range like main..feature.";
44398
+ const baseTip = commit(root2, baseRef);
44399
+ if (!baseTip) return `"${baseRef}" is not a branch, tag or commit here.`;
44400
+ let base;
44401
+ try {
44402
+ base = git(root2, ["merge-base", baseTip, head]).trim();
44403
+ } catch {
44404
+ return `${baseRef} and ${headRef} share no history.`;
44405
+ }
44406
+ return { base, head, label: `${baseRef}...${headRef}` };
44407
+ }
44408
+ function show(root2, rev, file2) {
44409
+ try {
44410
+ const text2 = git(root2, ["show", `${rev}:${file2}`], FILE_BYTES_MAX * 2);
44411
+ return text2.length > FILE_BYTES_MAX ? void 0 : text2;
44412
+ } catch {
44413
+ return void 0;
44414
+ }
44415
+ }
44416
+ var declKey = (d) => `${memberName(d)}:${d.k}`;
44417
+ var body2 = (lines, d) => lines.slice(d.s - 1, d.e).map((l) => l.trim()).join("\n");
44418
+ async function diffReport(map2, range) {
44419
+ const root2 = map2.root;
44420
+ const ends = resolveRange(root2, range);
44421
+ if (typeof ends === "string") return ends;
44422
+ const { base, head, label } = ends;
44423
+ let listing;
44424
+ try {
44425
+ listing = git(root2, ["diff", "--name-status", "-M", "--no-color", base, head]);
44426
+ } catch (err2) {
44427
+ return `git could not compare them: ${err2 instanceof Error ? err2.message.split("\n")[0] : String(err2)}`;
44428
+ }
44429
+ const report = { base, head, label, decls: [], other: [], testsChanged: [], skipped: [], orphans: [] };
44430
+ const isLocal = (s) => map2.resolver.isLocal(s);
44431
+ let read = 0;
44432
+ for (const line of listing.split("\n").filter(Boolean)) {
44433
+ const [status, a, b] = line.split(" ");
44434
+ const oldPath = a;
44435
+ const newPath = status.startsWith("R") || status.startsWith("C") ? b : a;
44436
+ if (isTestFile(newPath)) {
44437
+ report.testsChanged.push(newPath);
44438
+ continue;
44439
+ }
44440
+ const lang = langOf(newPath) ?? langOf(oldPath);
44441
+ if (!lang) {
44442
+ report.other.push(newPath);
44443
+ continue;
44444
+ }
44445
+ if (read >= FILES_MAX) {
44446
+ report.skipped.push(newPath);
44447
+ continue;
44448
+ }
44449
+ read++;
44450
+ const before = status.startsWith("A") ? "" : show(root2, base, oldPath);
44451
+ const after = status.startsWith("D") ? "" : show(root2, head, newPath);
44452
+ if (before === void 0 || after === void 0) {
44453
+ report.other.push(newPath);
44454
+ continue;
44455
+ }
44456
+ const [was, now] = await Promise.all([before ? extract(lang, before, isLocal) : void 0, after ? extract(lang, after, isLocal) : void 0]);
44457
+ const wasLines = before.split("\n");
44458
+ const nowLines = after.split("\n");
44459
+ const old = new Map((was?.decls ?? []).map((d) => [declKey(d), d]));
44460
+ const fresh = new Map((now?.decls ?? []).map((d) => [declKey(d), d]));
44461
+ const found = [];
44462
+ for (const [k, d] of fresh) {
44463
+ const o = old.get(k);
44464
+ if (!o) found.push({ change: "added", d, file: newPath });
44465
+ else if (body2(wasLines, o) !== body2(nowLines, d)) found.push({ change: "changed", d, file: newPath });
44466
+ }
44467
+ for (const [k, d] of old) if (!fresh.has(k)) found.push({ change: "removed", d, file: oldPath });
44468
+ const parents = new Set(found.filter((f) => f.d.p).map((f) => `${f.file}#${f.d.p}`));
44469
+ for (const f of found) {
44470
+ if (f.change === "changed" && !f.d.p && parents.has(`${f.file}#${f.d.n}`)) continue;
44471
+ report.decls.push({ change: f.change, file: f.file, name: memberName(f.d), kind: f.d.k, s: f.d.s, e: f.d.e, exported: !!f.d.x, ...reach(map2, f.file, memberName(f.d)) });
44472
+ }
44473
+ }
44474
+ for (const gone of report.decls.filter((d) => d.change === "removed")) {
44475
+ const to = report.decls.find((d) => d.change === "added" && d.name === gone.name && d.kind === gone.kind && d.file !== gone.file);
44476
+ if (!to) continue;
44477
+ to.change = "moved";
44478
+ to.from = gone.file;
44479
+ report.decls.splice(report.decls.indexOf(gone), 1);
44480
+ }
44481
+ report.orphans = orphansOf(map2, report.decls);
44482
+ return report;
44483
+ }
44484
+ function orphansOf(map2, decls) {
44485
+ const gone = new Set(decls.filter((d) => d.change === "removed").map((d) => `${d.file}#${d.name}`));
44486
+ if (!gone.size) return [];
44487
+ const out2 = /* @__PURE__ */ new Map();
44488
+ for (const g of gone) {
44489
+ const [file2, name2] = [g.slice(0, g.indexOf("#")), g.slice(g.indexOf("#") + 1)];
44490
+ for (const e of map2.graph.uses(file2, name2)) {
44491
+ const k = `${e.to.file}#${e.to.name}`;
44492
+ if (gone.has(k) || out2.has(k) || isTestFile(e.to.file)) continue;
44493
+ const others = map2.graph.usedBy(e.to.file, e.to.name).filter((c) => !gone.has(`${c.from.file}#${c.from.name}`) && `${c.from.file}#${c.from.name}` !== k);
44494
+ if (others.length) continue;
44495
+ const was = map2.graph.usedBy(e.to.file, e.to.name).filter((c) => gone.has(`${c.from.file}#${c.from.name}`)).map((c) => c.from.name);
44496
+ out2.set(k, { file: e.to.file, name: e.to.name, was: [...new Set(was)] });
44497
+ }
44498
+ }
44499
+ return [...out2.values()];
44500
+ }
44501
+ function reach(map2, file2, name2) {
44502
+ const callers = map2.graph.usedBy(file2, name2).filter((e) => !(e.from.file === file2 && e.from.name === name2));
44503
+ const tests = new Set(callers.map((e) => e.from.file).filter(isTestFile));
44504
+ const top = name2.split(".")[0];
44505
+ const importing = [...map2.graph.importers.get(file2) ?? []].filter(isTestFile);
44506
+ for (const f of importing) if (map2.file(f)?.i.some((imp) => imp.n?.includes(top) || imp.n?.includes("*"))) tests.add(f);
44507
+ const fileTests = tests.size ? [] : importing;
44508
+ return { callers, tests: [...tests], fileTests };
44509
+ }
44510
+ var plural2 = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
44511
+ function callerList(edges, n) {
44512
+ const seen = /* @__PURE__ */ new Set();
44513
+ const uniq = edges.filter((e) => !seen.has(`${e.from.file}#${e.from.name}`) && seen.add(`${e.from.file}#${e.from.name}`));
44514
+ const shown = uniq.slice(0, n).map((e) => `${e.from.name} ${e.from.file}`);
44515
+ return `${shown.join(", ")}${uniq.length > n ? `, \u2026 ${uniq.length - n} more` : ""}`;
44516
+ }
44517
+ function renderDiff(r, budget = 900) {
44518
+ const out2 = [];
44519
+ const files = new Set(r.decls.map((d) => d.file));
44520
+ out2.push(`${r.label} (${r.base.slice(0, 9)} \u2192 ${r.head.slice(0, 9)}): ${plural2(r.decls.length, "declaration")} changed in ${plural2(files.size, "file")}. Callers are from this checkout's map.`);
44521
+ const order = { removed: 0, changed: 1, moved: 2, added: 3 };
44522
+ for (const file2 of files) {
44523
+ out2.push(file2);
44524
+ const decls = r.decls.filter((d) => d.file === file2).sort((a, b) => order[a.change] - order[b.change] || a.s - b.s);
44525
+ for (const d of decls) {
44526
+ const where = d.change === "removed" ? `was :${d.s}-${d.e}` : d.from ? `:${d.s}-${d.e} from ${d.from}` : `:${d.s}-${d.e}`;
44527
+ let reachText;
44528
+ if (d.change === "removed") reachText = d.callers.length ? `still used by ${d.callers.length}: ${callerList(d.callers, 4)} (check these)` : "used by nothing now";
44529
+ else reachText = d.callers.length ? `used by ${d.callers.length}: ${callerList(d.callers, 4)}` : d.exported && d.change !== "added" ? "used by nothing in this map" : "";
44530
+ const few = (t) => `${t.slice(0, 3).join(", ")}${t.length > 3 ? ` +${t.length - 3}` : ""}`;
44531
+ const tests = d.tests.length ? ` \xB7 tests: ${few(d.tests)}` : !d.exported || d.change === "removed" ? "" : d.fileTests.length ? ` \xB7 no test names it (tests import its file: ${few(d.fileTests)})` : d.change === "added" ? "" : " \xB7 no test reaches it";
44532
+ out2.push(` ${d.change.padEnd(7)} ${d.name} ${d.kind} ${where}${reachText ? ` \xB7 ${reachText}` : ""}${tests}`);
44533
+ }
44534
+ }
44535
+ if (r.orphans.length) out2.push(`Left with no caller (only removed code used it): ${r.orphans.slice(0, 8).map((o) => `${o.name} ${o.file}`).join(", ")}${r.orphans.length > 8 ? `, \u2026 ${r.orphans.length - 8} more` : ""}`);
44536
+ if (r.testsChanged.length) out2.push(`Tests changed: ${r.testsChanged.slice(0, 8).join(", ")}${r.testsChanged.length > 8 ? `, \u2026 ${r.testsChanged.length - 8} more` : ""}`);
44537
+ if (r.other.length) out2.push(`Other files: ${r.other.slice(0, 10).join(", ")}${r.other.length > 10 ? `, \u2026 ${r.other.length - 10} more` : ""}`);
44538
+ if (r.skipped.length) out2.push(`Not read (over ${FILES_MAX} code files): ${r.skipped.slice(0, 10).join(", ")}${r.skipped.length > 10 ? ` \u2026 ${r.skipped.length - 10} more` : ""}`);
44539
+ if (!r.decls.length && !r.other.length && !r.testsChanged.length) out2.push("No files differ.");
44540
+ const text2 = out2.join("\n");
44541
+ const max = budget * 4;
44542
+ if (text2.length <= max) return text2;
44543
+ const cut = text2.lastIndexOf("\n", max - 40);
44544
+ return `${text2.slice(0, cut > 0 ? cut : max - 40)}
44545
+ \u2026 (cut to fit; outline or graph one file for more)`;
44546
+ }
44547
+
44273
44548
  // src/core/tokens.ts
44274
44549
  init_define_AIRBAND_GRAMMARS();
44275
- var fs13 = __toESM(require("node:fs"));
44550
+ var fs14 = __toESM(require("node:fs"));
44276
44551
  var SEARCH_CMD = /^\s*(cd [^&;]+(&&|;)\s*)?(grep|rg|ag|ack|find|fd|ls|tree|git (grep|ls-files))\b/;
44277
44552
  var READ_CMD = /^\s*(cd [^&;]+(&&|;)\s*)?(cat|head|tail|sed -n|less|bat|nl|wc|git (show|log|diff|blame))\b/;
44278
44553
  var tokensOf2 = (chars) => Math.round(chars / 4);
@@ -44295,14 +44570,14 @@ function resultText(content) {
44295
44570
  return "";
44296
44571
  }
44297
44572
  function eachLine(file2, fn, maxBytes = 512 * 1024 * 1024) {
44298
- const fd = fs13.openSync(file2, "r");
44573
+ const fd = fs14.openSync(file2, "r");
44299
44574
  try {
44300
- const size = Math.min(fs13.fstatSync(fd).size, maxBytes);
44575
+ const size = Math.min(fs14.fstatSync(fd).size, maxBytes);
44301
44576
  const chunk = Buffer.alloc(4 * 1024 * 1024);
44302
44577
  let pos = 0;
44303
44578
  let rest = Buffer.alloc(0);
44304
44579
  while (pos < size) {
44305
- const n = fs13.readSync(fd, chunk, 0, Math.min(chunk.length, size - pos), pos);
44580
+ const n = fs14.readSync(fd, chunk, 0, Math.min(chunk.length, size - pos), pos);
44306
44581
  if (n <= 0) break;
44307
44582
  pos += n;
44308
44583
  let buf = Buffer.concat([rest, chunk.subarray(0, n)]);
@@ -44316,7 +44591,7 @@ function eachLine(file2, fn, maxBytes = 512 * 1024 * 1024) {
44316
44591
  }
44317
44592
  if (rest.length) fn(rest.toString("utf8"));
44318
44593
  } finally {
44319
- fs13.closeSync(fd);
44594
+ fs14.closeSync(fd);
44320
44595
  }
44321
44596
  }
44322
44597
  function tokenReport(tool, file2) {
@@ -44346,13 +44621,13 @@ function tokenReport(tool, file2) {
44346
44621
  pt.tokens += t;
44347
44622
  pt.calls++;
44348
44623
  perTool.set(name2, pt);
44349
- const path12 = call && (call.input.file_path ?? call.input.absolute_path ?? call.input.path);
44350
- if (call && typeof path12 === "string" && /^(Read|read_file)$/.test(name2)) {
44351
- const rd = reads.get(path12) ?? { times: 0, tokens: 0, whole: 0 };
44624
+ const path13 = call && (call.input.file_path ?? call.input.absolute_path ?? call.input.path);
44625
+ if (call && typeof path13 === "string" && /^(Read|read_file)$/.test(name2)) {
44626
+ const rd = reads.get(path13) ?? { times: 0, tokens: 0, whole: 0 };
44352
44627
  rd.times++;
44353
44628
  rd.tokens += t;
44354
44629
  if (!call.input.offset && !call.input.limit) rd.whole = Math.max(rd.whole, t);
44355
- reads.set(path12, rd);
44630
+ reads.set(path13, rd);
44356
44631
  }
44357
44632
  };
44358
44633
  eachLine(file2, (line) => {
@@ -44448,8 +44723,8 @@ function renderTokenReport(r, name2) {
44448
44723
 
44449
44724
  // src/library/index.ts
44450
44725
  init_define_AIRBAND_GRAMMARS();
44451
- var fs14 = __toESM(require("node:fs"));
44452
- var path10 = __toESM(require("node:path"));
44726
+ var fs15 = __toESM(require("node:fs"));
44727
+ var path11 = __toESM(require("node:path"));
44453
44728
 
44454
44729
  // src/library/content/ci.md
44455
44730
  var ci_default = "---\nname: ci\ntitle: Fix CI\npack: engineering\ndescription: Find why a CI run or deployment failed from its logs, and fix the cause rather than the symptom.\nargs: run = Failing run, PR or job (default: the latest failing run on this branch)\ntriggers: ci failing, fix ci, failing checks, github actions, pipeline failed, build failed, deploy failed, make ci green\n---\nFix the failure in {{run}}.\n\n1. **Read the failure first:** `gh run list --branch <branch> --limit 5`, then `gh run view <id> --log-failed`. Find the first real error, not the last line.\n2. **Reproduce locally** with the same command the job runs (read the workflow file for it). If it passes locally, compare versions, environment variables, caches and the files CI checks out.\n3. **Classify:** our code broke \xB7 a test is wrong or flaky (prove which: run it ten times) \xB7 environment or dependency changed \xB7 the workflow itself.\n4. **Fix the cause.** Never skip, retry-until-green, or loosen a check to get past it; if a check is truly wrong, say so and change it in its own commit with the reason.\n5. Run the same command again and show it passing. Ask before pushing.\n\nReport: the cause in one line, the fix, and how you verified it.\n";
@@ -44679,16 +44954,16 @@ function userCommands() {
44679
44954
  const read = (d, depth) => {
44680
44955
  let items;
44681
44956
  try {
44682
- items = fs14.readdirSync(d, { withFileTypes: true });
44957
+ items = fs15.readdirSync(d, { withFileTypes: true });
44683
44958
  } catch {
44684
44959
  return;
44685
44960
  }
44686
44961
  for (const it of items) {
44687
- const p = path10.join(d, it.name);
44962
+ const p = path11.join(d, it.name);
44688
44963
  if (it.isDirectory() && depth < 1) read(p, depth + 1);
44689
44964
  else if (it.isFile() && it.name.endsWith(".md")) {
44690
44965
  try {
44691
- const c = parseCommand(fs14.readFileSync(p, "utf8"), p);
44966
+ const c = parseCommand(fs15.readFileSync(p, "utf8"), p);
44692
44967
  if (c && c.description !== STARTER_DESCRIPTION) out2.push(c);
44693
44968
  } catch {
44694
44969
  }
@@ -44719,19 +44994,21 @@ var root = process.env.AIRBAND_ROOT || process.cwd();
44719
44994
  var INSTRUCTIONS = [
44720
44995
  "Airband gives this project a map of its code and the records of the person's other AI chats on this computer.",
44721
44996
  "- To find code (where something is defined, what calls or imports it, how a folder is laid out), call airband_map before grep, glob or reading whole files: find for a name or plain words, outline for a file or folder, graph for who uses what, no arguments for an overview. It answers in a few hundred tokens.",
44722
- "- When the person refers to earlier work or another chat (what was done, which chat changed something, what happened while they were away), call airband_flightlog: with query to search every chat, or with chat to read one.",
44997
+ '- To review a branch or pull request, call airband_map with diff first ("main..feature", a branch, or "#128"): what it changed, who calls each change and which tests reach it, without checking it out. Add in to ask another project the person mapped ("my-api").',
44998
+ "- When the person refers to earlier work or another chat (what was done, which chat changed something, what happened while they were away, a ticket like ENG-142, a PR like #128), call airband_flightlog: with query to search every chat, or with chat to read one.",
44723
44999
  "- airband_notes holds notes chats left for this project; read them before working in an unfamiliar area, and save one when you learn something the next chat should know."
44724
45000
  ].join("\n");
44725
- var server = new McpServer({ name: "airband", version: "0.0.1" }, { instructions: INSTRUCTIONS });
45001
+ var server = new McpServer({ name: "airband", version: "0.0.3" }, { instructions: INSTRUCTIONS });
44726
45002
  var text = (t, isError = false) => ({ content: [{ type: "text", text: t }], ...isError ? { isError } : {} });
44727
- var codeMap = new CodeMap(root);
44728
- var lastSweep = 0;
44729
- async function freshMap() {
44730
- if (Date.now() - lastSweep > 1500) {
44731
- await codeMap.refresh();
44732
- lastSweep = Date.now();
45003
+ var maps = /* @__PURE__ */ new Map();
45004
+ async function freshMap(folder = root) {
45005
+ let m = maps.get(folder);
45006
+ if (!m) maps.set(folder, m = { map: new CodeMap(folder), at: 0 });
45007
+ if (Date.now() - m.at > 1500) {
45008
+ await m.map.refresh();
45009
+ m.at = Date.now();
44733
45010
  }
44734
- return codeMap;
45011
+ return m.map;
44735
45012
  }
44736
45013
  function recentFiles() {
44737
45014
  try {
@@ -44745,26 +45022,42 @@ function recentFiles() {
44745
45022
  server.registerTool(
44746
45023
  "airband_map",
44747
45024
  {
44748
- description: "This codebase's map (no AI). find: words or a name \u2192 ranked code with path:start-end; cheaper than grep and reading files. outline: a path or name \u2192 its parts with lines. graph: who uses it, what it uses. check: unused code or stale docs. None: overview.",
45025
+ description: "Code map (no AI), cheaper than grep or reading files. find: words/name \u2192 ranked code, path:start-end. outline: path/name \u2192 parts. graph: its users and uses. check: unused code, stale docs. diff: branch, a..b or #PR \u2192 changes, callers, tests. in: another project. None: overview.",
44749
45026
  inputSchema: {
44750
45027
  find: external_exports.string().optional(),
44751
45028
  outline: external_exports.string().optional(),
44752
45029
  graph: external_exports.string().optional(),
44753
45030
  hops: external_exports.number().int().min(1).max(2).optional(),
44754
- check: external_exports.enum(["unused", "docs"]).optional()
45031
+ check: external_exports.enum(["unused", "docs"]).optional(),
45032
+ diff: external_exports.string().optional(),
45033
+ in: external_exports.string().optional()
44755
45034
  }
44756
45035
  },
44757
- async ({ find, outline, graph, hops, check: check2 }) => {
44758
- const map2 = await freshMap();
44759
- if (check2 === "unused") return text(map2.unusedText());
45036
+ async ({ find, outline, graph, hops, check: check2, diff, in: other }) => {
45037
+ let folder = root;
45038
+ let label = "";
45039
+ if (other) {
45040
+ const p = findProject(other, root);
45041
+ if (typeof p === "string") return text(p, true);
45042
+ folder = p.root;
45043
+ label = folder === root ? "" : `In ${p.name} (${p.root}):
45044
+ `;
45045
+ }
45046
+ const map2 = await freshMap(folder);
45047
+ const answer = (t) => text(label + t);
45048
+ if (diff !== void 0) {
45049
+ const r = await diffReport(map2, diff);
45050
+ return typeof r === "string" ? text(r, true) : answer(renderDiff(r));
45051
+ }
45052
+ if (check2 === "unused") return answer(map2.unusedText());
44760
45053
  if (check2 === "docs") {
44761
45054
  const stale = map2.staleDocs();
44762
- return text(stale.length ? stale.map((d) => `${d.file}:${d.line} names ${d.missing} (${d.kind}), which no longer exists`).join("\n") : "Every file, hook and script the docs name exists.");
45055
+ return answer(stale.length ? stale.map((d) => `${d.file}:${d.line} names ${d.missing} (${d.kind}), which no longer exists`).join("\n") : "Every file, hook and script the docs name exists.");
44763
45056
  }
44764
- if (find) return text(map2.find(find, { focus: recentFiles() }));
44765
- if (outline) return text(map2.outline(outline));
44766
- if (graph) return text(map2.graphOf(graph, hops ?? 1));
44767
- return text(map2.overview());
45057
+ if (find) return answer(map2.find(find, { focus: folder === root ? recentFiles() : [] }));
45058
+ if (outline) return answer(map2.outline(outline));
45059
+ if (graph) return answer(map2.graphOf(graph, hops ?? 1));
45060
+ return answer(map2.overview());
44768
45061
  }
44769
45062
  );
44770
45063
  var when = (at) => new Date(at).toLocaleString("en-GB", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
@@ -44787,7 +45080,7 @@ function askLine(a) {
44787
45080
  server.registerTool(
44788
45081
  "airband_flightlog",
44789
45082
  {
44790
- description: "What AI chats on this computer were asked and did, a line per ask. No chat: lists them; with query, searches all (words or code names). n: one ask in full. tokens: where its tokens went.",
45083
+ description: "What AI chats on this computer were asked and did, a line per ask. No chat: list; query: search all (words, code, tickets, PRs). n: one ask whole. tokens: its token use.",
44791
45084
  inputSchema: {
44792
45085
  chat: external_exports.string().optional(),
44793
45086
  query: external_exports.string().optional(),
@@ -44806,7 +45099,7 @@ server.registerTool(
44806
45099
  if (!chat) {
44807
45100
  const heads = listHeads().slice(0, 25);
44808
45101
  return text(
44809
- heads.length ? heads.map((h2) => `${nameOf(h2)} \xB7 ${h2.cwd ? path11.basename(h2.cwd) : "?"} \xB7 ${h2.n} asks \xB7 ${when(h2.updatedAt)} \xB7 id ${h2.id.slice(0, 8)}`).join("\n") : "No flightlogs yet. Airband starts one for each chat as it replies."
45102
+ heads.length ? heads.map((h2) => `${nameOf(h2)} \xB7 ${h2.cwd ? path12.basename(h2.cwd) : "?"} \xB7 ${h2.n} asks \xB7 ${when(h2.updatedAt)} \xB7 id ${h2.id.slice(0, 8)}`).join("\n") : "No flightlogs yet. Airband starts one for each chat as it replies."
44810
45103
  );
44811
45104
  }
44812
45105
  const found = findRecords(chat);
@@ -44816,7 +45109,7 @@ server.registerTool(
44816
45109
  return words2 ? text(words2) : text(`No ask #${n} in a flightlog matching "${chat}".`, true);
44817
45110
  }
44818
45111
  if (found.length > 1 && !found.some((h2) => h2.id === chat)) {
44819
- const list = found.slice(0, 10).map((h2) => `${nameOf(h2)} \xB7 ${h2.cwd ? path11.basename(h2.cwd) : "?"} \xB7 ${h2.n} asks \xB7 id ${h2.id.slice(0, 8)}`);
45112
+ const list = found.slice(0, 10).map((h2) => `${nameOf(h2)} \xB7 ${h2.cwd ? path12.basename(h2.cwd) : "?"} \xB7 ${h2.n} asks \xB7 id ${h2.id.slice(0, 8)}`);
44820
45113
  if (found.length > 10) list.push(`\u2026 ${found.length - 10} more`);
44821
45114
  return text(`Several chats match; name one by id:
44822
45115
  ${list.join("\n")}`);
@@ -44851,7 +45144,7 @@ async function recall(query2) {
44851
45144
  try {
44852
45145
  const map2 = await freshMap();
44853
45146
  const hits = map2.findHits(query2).filter((h) => h.score > 20).slice(0, 3);
44854
- files = new Set(hits.map((h) => path11.join(root, h.doc.file.p)));
45147
+ files = new Set(hits.map((h) => path12.join(root, h.doc.file.p)));
44855
45148
  } catch {
44856
45149
  }
44857
45150
  const found = [];
@@ -44870,20 +45163,20 @@ async function recall(query2) {
44870
45163
  server.registerTool(
44871
45164
  "airband_notes",
44872
45165
  {
44873
- description: "Notes chats leave for this project. None: list. name: read one. title and text: save one (to hand over work).",
45166
+ description: "Notes chats leave for this project. None: list. name: read one. title and text: save one (a handover).",
44874
45167
  inputSchema: {
44875
45168
  name: external_exports.string().optional(),
44876
45169
  title: external_exports.string().optional(),
44877
45170
  text: external_exports.string().optional()
44878
45171
  }
44879
45172
  },
44880
- async ({ name: name2, title, text: body2 }) => {
44881
- if (title && body2) {
45173
+ async ({ name: name2, title, text: body3 }) => {
45174
+ if (title && body3) {
44882
45175
  let saved;
44883
45176
  try {
44884
45177
  saved = saveNote(root, title, `# ${title}
44885
45178
 
44886
- ${body2.trim()}`);
45179
+ ${body3.trim()}`);
44887
45180
  } catch (err2) {
44888
45181
  return text(err2 instanceof Error ? err2.message : String(err2), true);
44889
45182
  }
@@ -44937,9 +45230,9 @@ setInterval(() => {
44937
45230
  let stamp = "";
44938
45231
  try {
44939
45232
  const dir2 = userLibraryDir();
44940
- for (const f of fs15.readdirSync(dir2, { recursive: true })) {
45233
+ for (const f of fs16.readdirSync(dir2, { recursive: true })) {
44941
45234
  if (!f.endsWith(".md")) continue;
44942
- const st = fs15.statSync(path11.join(dir2, f));
45235
+ const st = fs16.statSync(path12.join(dir2, f));
44943
45236
  stamp += `${f}:${st.mtimeMs}:${st.size};`;
44944
45237
  }
44945
45238
  } catch {