opencode-codebase-index 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJS = (cb, mod) => function __require() {
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
10
16
  try {
11
17
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
18
  } catch (e) {
@@ -650,6 +656,467 @@ var require_ignore = __commonJS({
650
656
  }
651
657
  });
652
658
 
659
+ // node_modules/tiktoken/tiktoken_bg.cjs
660
+ var require_tiktoken_bg = __commonJS({
661
+ "node_modules/tiktoken/tiktoken_bg.cjs"(exports, module2) {
662
+ "use strict";
663
+ var wasm;
664
+ module2.exports.__wbg_set_wasm = function(val) {
665
+ wasm = val;
666
+ };
667
+ var lTextDecoder = typeof TextDecoder === "undefined" ? (0, module2.require)("util").TextDecoder : TextDecoder;
668
+ var cachedTextDecoder = new lTextDecoder("utf-8", { ignoreBOM: true, fatal: true });
669
+ cachedTextDecoder.decode();
670
+ var cachedUint8ArrayMemory0 = null;
671
+ function getUint8ArrayMemory0() {
672
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
673
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
674
+ }
675
+ return cachedUint8ArrayMemory0;
676
+ }
677
+ function getStringFromWasm0(ptr, len) {
678
+ ptr = ptr >>> 0;
679
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
680
+ }
681
+ var heap = new Array(128).fill(void 0);
682
+ heap.push(void 0, null, true, false);
683
+ var heap_next = heap.length;
684
+ function addHeapObject(obj) {
685
+ if (heap_next === heap.length) heap.push(heap.length + 1);
686
+ const idx = heap_next;
687
+ heap_next = heap[idx];
688
+ heap[idx] = obj;
689
+ return idx;
690
+ }
691
+ function handleError(f, args) {
692
+ try {
693
+ return f.apply(this, args);
694
+ } catch (e) {
695
+ wasm.__wbindgen_export_0(addHeapObject(e));
696
+ }
697
+ }
698
+ function getObject(idx) {
699
+ return heap[idx];
700
+ }
701
+ function dropObject(idx) {
702
+ if (idx < 132) return;
703
+ heap[idx] = heap_next;
704
+ heap_next = idx;
705
+ }
706
+ function takeObject(idx) {
707
+ const ret = getObject(idx);
708
+ dropObject(idx);
709
+ return ret;
710
+ }
711
+ var WASM_VECTOR_LEN = 0;
712
+ var lTextEncoder = typeof TextEncoder === "undefined" ? (0, module2.require)("util").TextEncoder : TextEncoder;
713
+ var cachedTextEncoder = new lTextEncoder("utf-8");
714
+ var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
715
+ return cachedTextEncoder.encodeInto(arg, view);
716
+ } : function(arg, view) {
717
+ const buf = cachedTextEncoder.encode(arg);
718
+ view.set(buf);
719
+ return {
720
+ read: arg.length,
721
+ written: buf.length
722
+ };
723
+ };
724
+ function passStringToWasm0(arg, malloc, realloc) {
725
+ if (realloc === void 0) {
726
+ const buf = cachedTextEncoder.encode(arg);
727
+ const ptr2 = malloc(buf.length, 1) >>> 0;
728
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
729
+ WASM_VECTOR_LEN = buf.length;
730
+ return ptr2;
731
+ }
732
+ let len = arg.length;
733
+ let ptr = malloc(len, 1) >>> 0;
734
+ const mem = getUint8ArrayMemory0();
735
+ let offset = 0;
736
+ for (; offset < len; offset++) {
737
+ const code = arg.charCodeAt(offset);
738
+ if (code > 127) break;
739
+ mem[ptr + offset] = code;
740
+ }
741
+ if (offset !== len) {
742
+ if (offset !== 0) {
743
+ arg = arg.slice(offset);
744
+ }
745
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
746
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
747
+ const ret = encodeString(arg, view);
748
+ offset += ret.written;
749
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
750
+ }
751
+ WASM_VECTOR_LEN = offset;
752
+ return ptr;
753
+ }
754
+ function isLikeNone(x) {
755
+ return x === void 0 || x === null;
756
+ }
757
+ var cachedDataViewMemory0 = null;
758
+ function getDataViewMemory0() {
759
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
760
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
761
+ }
762
+ return cachedDataViewMemory0;
763
+ }
764
+ var cachedUint32ArrayMemory0 = null;
765
+ function getUint32ArrayMemory0() {
766
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
767
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
768
+ }
769
+ return cachedUint32ArrayMemory0;
770
+ }
771
+ function getArrayU32FromWasm0(ptr, len) {
772
+ ptr = ptr >>> 0;
773
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
774
+ }
775
+ function passArray8ToWasm0(arg, malloc) {
776
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
777
+ getUint8ArrayMemory0().set(arg, ptr / 1);
778
+ WASM_VECTOR_LEN = arg.length;
779
+ return ptr;
780
+ }
781
+ function passArray32ToWasm0(arg, malloc) {
782
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
783
+ getUint32ArrayMemory0().set(arg, ptr / 4);
784
+ WASM_VECTOR_LEN = arg.length;
785
+ return ptr;
786
+ }
787
+ function getArrayU8FromWasm0(ptr, len) {
788
+ ptr = ptr >>> 0;
789
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
790
+ }
791
+ module2.exports.get_encoding = function(encoding, extend_special_tokens) {
792
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
793
+ try {
794
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
795
+ const ptr0 = passStringToWasm0(encoding, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
796
+ const len0 = WASM_VECTOR_LEN;
797
+ wasm.get_encoding(retptr, ptr0, len0, addHeapObject(extend_special_tokens));
798
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
799
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
800
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
801
+ if (r2) {
802
+ throw takeObject(r1);
803
+ }
804
+ return Tiktoken.__wrap(r0);
805
+ } finally {
806
+ wasm.__wbindgen_add_to_stack_pointer(16);
807
+ }
808
+ };
809
+ module2.exports.encoding_for_model = function(model, extend_special_tokens) {
810
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
811
+ try {
812
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
813
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
814
+ const len0 = WASM_VECTOR_LEN;
815
+ wasm.encoding_for_model(retptr, ptr0, len0, addHeapObject(extend_special_tokens));
816
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
817
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
818
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
819
+ if (r2) {
820
+ throw takeObject(r1);
821
+ }
822
+ return Tiktoken.__wrap(r0);
823
+ } finally {
824
+ wasm.__wbindgen_add_to_stack_pointer(16);
825
+ }
826
+ };
827
+ module2.exports.get_encoding_name_for_model = function(model) {
828
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
829
+ let deferred3_0;
830
+ let deferred3_1;
831
+ try {
832
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
833
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
834
+ const len0 = WASM_VECTOR_LEN;
835
+ wasm.get_encoding_name_for_model(retptr, ptr0, len0);
836
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
837
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
838
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
839
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
840
+ var ptr2 = r0;
841
+ var len2 = r1;
842
+ if (r3) {
843
+ ptr2 = 0;
844
+ len2 = 0;
845
+ throw takeObject(r2);
846
+ }
847
+ deferred3_0 = ptr2;
848
+ deferred3_1 = len2;
849
+ return getStringFromWasm0(ptr2, len2);
850
+ } finally {
851
+ wasm.__wbindgen_add_to_stack_pointer(16);
852
+ wasm.__wbindgen_export_3(deferred3_0, deferred3_1, 1);
853
+ }
854
+ };
855
+ var TiktokenFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
856
+ }, unregister: () => {
857
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_tiktoken_free(ptr >>> 0, 1));
858
+ var Tiktoken = class _Tiktoken {
859
+ /**
860
+ * @param {string} tiktoken_bfe
861
+ * @param {any} special_tokens
862
+ * @param {string} pat_str
863
+ */
864
+ constructor(tiktoken_bfe, special_tokens, pat_str) {
865
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
866
+ const ptr0 = passStringToWasm0(tiktoken_bfe, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
867
+ const len0 = WASM_VECTOR_LEN;
868
+ const ptr1 = passStringToWasm0(pat_str, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
869
+ const len1 = WASM_VECTOR_LEN;
870
+ const ret = wasm.tiktoken_new(ptr0, len0, addHeapObject(special_tokens), ptr1, len1);
871
+ this.__wbg_ptr = ret >>> 0;
872
+ TiktokenFinalization.register(this, this.__wbg_ptr, this);
873
+ return this;
874
+ }
875
+ /** @returns {string | undefined} */
876
+ get name() {
877
+ try {
878
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
879
+ wasm.tiktoken_name(retptr, this.__wbg_ptr);
880
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
881
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
882
+ let v1;
883
+ if (r0 !== 0) {
884
+ v1 = getStringFromWasm0(r0, r1).slice();
885
+ wasm.__wbindgen_export_3(r0, r1 * 1, 1);
886
+ }
887
+ return v1;
888
+ } finally {
889
+ wasm.__wbindgen_add_to_stack_pointer(16);
890
+ }
891
+ }
892
+ static __wrap(ptr) {
893
+ ptr = ptr >>> 0;
894
+ const obj = Object.create(_Tiktoken.prototype);
895
+ obj.__wbg_ptr = ptr;
896
+ TiktokenFinalization.register(obj, obj.__wbg_ptr, obj);
897
+ return obj;
898
+ }
899
+ __destroy_into_raw() {
900
+ const ptr = this.__wbg_ptr;
901
+ this.__wbg_ptr = 0;
902
+ TiktokenFinalization.unregister(this);
903
+ return ptr;
904
+ }
905
+ free() {
906
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
907
+ const ptr = this.__destroy_into_raw();
908
+ wasm.__wbg_tiktoken_free(ptr, 0);
909
+ }
910
+ /**
911
+ * @param {string} text
912
+ * @param {any} allowed_special
913
+ * @param {any} disallowed_special
914
+ * @returns {Uint32Array}
915
+ */
916
+ encode(text, allowed_special, disallowed_special) {
917
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
918
+ try {
919
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
920
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
921
+ const len0 = WASM_VECTOR_LEN;
922
+ wasm.tiktoken_encode(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(allowed_special), addHeapObject(disallowed_special));
923
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
924
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
925
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
926
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
927
+ if (r3) {
928
+ throw takeObject(r2);
929
+ }
930
+ var v2 = getArrayU32FromWasm0(r0, r1).slice();
931
+ wasm.__wbindgen_export_3(r0, r1 * 4, 4);
932
+ return v2;
933
+ } finally {
934
+ wasm.__wbindgen_add_to_stack_pointer(16);
935
+ }
936
+ }
937
+ /**
938
+ * @param {string} text
939
+ * @returns {Uint32Array}
940
+ */
941
+ encode_ordinary(text) {
942
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
943
+ try {
944
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
945
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
946
+ const len0 = WASM_VECTOR_LEN;
947
+ wasm.tiktoken_encode_ordinary(retptr, this.__wbg_ptr, ptr0, len0);
948
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
949
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
950
+ var v2 = getArrayU32FromWasm0(r0, r1).slice();
951
+ wasm.__wbindgen_export_3(r0, r1 * 4, 4);
952
+ return v2;
953
+ } finally {
954
+ wasm.__wbindgen_add_to_stack_pointer(16);
955
+ }
956
+ }
957
+ /**
958
+ * @param {string} text
959
+ * @param {any} allowed_special
960
+ * @param {any} disallowed_special
961
+ * @returns {any}
962
+ */
963
+ encode_with_unstable(text, allowed_special, disallowed_special) {
964
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
965
+ try {
966
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
967
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
968
+ const len0 = WASM_VECTOR_LEN;
969
+ wasm.tiktoken_encode_with_unstable(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(allowed_special), addHeapObject(disallowed_special));
970
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
971
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
972
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
973
+ if (r2) {
974
+ throw takeObject(r1);
975
+ }
976
+ return takeObject(r0);
977
+ } finally {
978
+ wasm.__wbindgen_add_to_stack_pointer(16);
979
+ }
980
+ }
981
+ /**
982
+ * @param {Uint8Array} bytes
983
+ * @returns {number}
984
+ */
985
+ encode_single_token(bytes) {
986
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
987
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export_1);
988
+ const len0 = WASM_VECTOR_LEN;
989
+ const ret = wasm.tiktoken_encode_single_token(this.__wbg_ptr, ptr0, len0);
990
+ return ret >>> 0;
991
+ }
992
+ /**
993
+ * @param {Uint32Array} tokens
994
+ * @returns {Uint8Array}
995
+ */
996
+ decode(tokens) {
997
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
998
+ try {
999
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1000
+ const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_export_1);
1001
+ const len0 = WASM_VECTOR_LEN;
1002
+ wasm.tiktoken_decode(retptr, this.__wbg_ptr, ptr0, len0);
1003
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1004
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1005
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
1006
+ wasm.__wbindgen_export_3(r0, r1 * 1, 1);
1007
+ return v2;
1008
+ } finally {
1009
+ wasm.__wbindgen_add_to_stack_pointer(16);
1010
+ }
1011
+ }
1012
+ /**
1013
+ * @param {number} token
1014
+ * @returns {Uint8Array}
1015
+ */
1016
+ decode_single_token_bytes(token) {
1017
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
1018
+ try {
1019
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1020
+ wasm.tiktoken_decode_single_token_bytes(retptr, this.__wbg_ptr, token);
1021
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1022
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1023
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
1024
+ wasm.__wbindgen_export_3(r0, r1 * 1, 1);
1025
+ return v1;
1026
+ } finally {
1027
+ wasm.__wbindgen_add_to_stack_pointer(16);
1028
+ }
1029
+ }
1030
+ /** @returns {any} */
1031
+ token_byte_values() {
1032
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
1033
+ const ret = wasm.tiktoken_token_byte_values(this.__wbg_ptr);
1034
+ return takeObject(ret);
1035
+ }
1036
+ };
1037
+ module2.exports.Tiktoken = Tiktoken;
1038
+ module2.exports.__wbg_parse_def2e24ef1252aff = function() {
1039
+ return handleError(function(arg0, arg1) {
1040
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
1041
+ return addHeapObject(ret);
1042
+ }, arguments);
1043
+ };
1044
+ module2.exports.__wbg_stringify_f7ed6987935b4a24 = function() {
1045
+ return handleError(function(arg0) {
1046
+ const ret = JSON.stringify(getObject(arg0));
1047
+ return addHeapObject(ret);
1048
+ }, arguments);
1049
+ };
1050
+ module2.exports.__wbindgen_error_new = function(arg0, arg1) {
1051
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1052
+ return addHeapObject(ret);
1053
+ };
1054
+ module2.exports.__wbindgen_is_undefined = function(arg0) {
1055
+ const ret = getObject(arg0) === void 0;
1056
+ return ret;
1057
+ };
1058
+ module2.exports.__wbindgen_object_drop_ref = function(arg0) {
1059
+ takeObject(arg0);
1060
+ };
1061
+ module2.exports.__wbindgen_string_get = function(arg0, arg1) {
1062
+ if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
1063
+ const obj = getObject(arg1);
1064
+ const ret = typeof obj === "string" ? obj : void 0;
1065
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
1066
+ var len1 = WASM_VECTOR_LEN;
1067
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1068
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1069
+ };
1070
+ module2.exports.__wbindgen_throw = function(arg0, arg1) {
1071
+ throw new Error(getStringFromWasm0(arg0, arg1));
1072
+ };
1073
+ }
1074
+ });
1075
+
1076
+ // node_modules/tiktoken/tiktoken.cjs
1077
+ var require_tiktoken = __commonJS({
1078
+ "node_modules/tiktoken/tiktoken.cjs"(exports) {
1079
+ "use strict";
1080
+ var wasm = require_tiktoken_bg();
1081
+ var imports = {};
1082
+ imports["./tiktoken_bg.js"] = wasm;
1083
+ var path24 = __require("path");
1084
+ var fs = __require("fs");
1085
+ var candidates = __dirname.split(path24.sep).reduce((memo, _, index, array) => {
1086
+ const prefix = array.slice(0, index + 1).join(path24.sep) + path24.sep;
1087
+ if (!prefix.includes("node_modules" + path24.sep)) {
1088
+ memo.unshift(
1089
+ path24.join(
1090
+ prefix,
1091
+ "node_modules",
1092
+ "tiktoken",
1093
+ "",
1094
+ "./tiktoken_bg.wasm"
1095
+ )
1096
+ );
1097
+ }
1098
+ return memo;
1099
+ }, []);
1100
+ candidates.unshift(path24.join(__dirname, "./tiktoken_bg.wasm"));
1101
+ var bytes = null;
1102
+ for (const candidate of candidates) {
1103
+ try {
1104
+ bytes = fs.readFileSync(candidate);
1105
+ break;
1106
+ } catch {
1107
+ }
1108
+ }
1109
+ if (bytes == null) throw new Error("Missing tiktoken_bg.wasm");
1110
+ var wasmModule = new WebAssembly.Module(bytes);
1111
+ var wasmInstance = new WebAssembly.Instance(wasmModule, imports);
1112
+ wasm.__wbg_set_wasm(wasmInstance.exports);
1113
+ exports["get_encoding"] = wasm["get_encoding"];
1114
+ exports["encoding_for_model"] = wasm["encoding_for_model"];
1115
+ exports["get_encoding_name_for_model"] = wasm["get_encoding_name_for_model"];
1116
+ exports["Tiktoken"] = wasm["Tiktoken"];
1117
+ }
1118
+ });
1119
+
653
1120
  // src/index.ts
654
1121
  import * as os6 from "os";
655
1122
  import * as path23 from "path";
@@ -1708,7 +2175,12 @@ function sameReclaimOwner(left, right) {
1708
2175
  }
1709
2176
  function publishJsonDirectory(finalPath, value) {
1710
2177
  const candidatePath = `${finalPath}.candidate.${process.pid}.${randomUUID()}`;
1711
- mkdirSync2(candidatePath, { mode: 448 });
2178
+ try {
2179
+ mkdirSync2(candidatePath, { mode: 448 });
2180
+ } catch (error) {
2181
+ if (getErrorCode(error) === "ENOENT") return false;
2182
+ throw error;
2183
+ }
1712
2184
  try {
1713
2185
  writeFileSync2(path7.join(candidatePath, OWNER_FILE_NAME), JSON.stringify(value), {
1714
2186
  encoding: "utf-8",
@@ -1721,8 +2193,12 @@ function publishJsonDirectory(finalPath, value) {
1721
2193
  return true;
1722
2194
  } catch (error) {
1723
2195
  if (existsSync5(finalPath)) return false;
2196
+ if (getErrorCode(error) === "ENOENT") return false;
1724
2197
  throw error;
1725
2198
  }
2199
+ } catch (error) {
2200
+ if (getErrorCode(error) === "ENOENT") return false;
2201
+ throw error;
1726
2202
  } finally {
1727
2203
  if (existsSync5(candidatePath)) rmSync(candidatePath, { recursive: true, force: true });
1728
2204
  }
@@ -6578,6 +7054,27 @@ function mergeTieredResults(symbolLane, hybridLane, limit) {
6578
7054
  }
6579
7055
  return out;
6580
7056
  }
7057
+ function selectChunksWithFileCoverage(chunks, limit) {
7058
+ if (limit <= 0 || chunks.length === 0) {
7059
+ return [];
7060
+ }
7061
+ if (chunks.length <= limit) {
7062
+ return chunks;
7063
+ }
7064
+ if (limit === 1) {
7065
+ return [chunks[Math.floor((chunks.length - 1) / 2)]];
7066
+ }
7067
+ const selected = [];
7068
+ for (let index = 0; index < limit; index++) {
7069
+ const sourceIndex = Math.round(index * (chunks.length - 1) / (limit - 1));
7070
+ selected.push(chunks[sourceIndex]);
7071
+ }
7072
+ return selected;
7073
+ }
7074
+ function selectIndexableChunks(chunks, limit, semanticOnly) {
7075
+ const indexableChunks = semanticOnly ? chunks.filter((chunk) => chunk.chunkType !== "other") : chunks;
7076
+ return selectChunksWithFileCoverage(indexableChunks, limit);
7077
+ }
6581
7078
  function matchesSearchFilters(candidate, options, minScore) {
6582
7079
  if (candidate.score < minScore) return false;
6583
7080
  if (options?.fileType) {
@@ -8316,7 +8813,6 @@ var Indexer = class {
8316
8813
  const relativePath = path13.relative(this.projectRoot, parsed.path);
8317
8814
  stats.parseFailures.push(relativePath);
8318
8815
  }
8319
- let fileChunkCount = 0;
8320
8816
  let chunksToProcess = parsed.chunks;
8321
8817
  if (this.config.indexing.fallbackToTextOnMaxChunks && chunksToProcess.length > this.config.indexing.maxChunksPerFile) {
8322
8818
  const changedFile = changedFiles.find((f) => f.path === parsed.path);
@@ -8325,13 +8821,12 @@ var Indexer = class {
8325
8821
  chunksToProcess = textChunks;
8326
8822
  }
8327
8823
  }
8824
+ chunksToProcess = selectIndexableChunks(
8825
+ chunksToProcess,
8826
+ this.config.indexing.maxChunksPerFile,
8827
+ this.config.indexing.semanticOnly
8828
+ );
8328
8829
  for (const chunk of chunksToProcess) {
8329
- if (fileChunkCount >= this.config.indexing.maxChunksPerFile) {
8330
- break;
8331
- }
8332
- if (this.config.indexing.semanticOnly && chunk.chunkType === "other") {
8333
- continue;
8334
- }
8335
8830
  const id = generateChunkId(parsed.path, chunk);
8336
8831
  const contentHash = generateChunkHash(chunk);
8337
8832
  const existingContentHash = existingChunks.get(id);
@@ -8355,7 +8850,6 @@ var Indexer = class {
8355
8850
  blameSummary: blameMetadata.blameSummary
8356
8851
  });
8357
8852
  if (existingContentHash === contentHash) {
8358
- fileChunkCount++;
8359
8853
  continue;
8360
8854
  }
8361
8855
  const texts = createEmbeddingTexts(chunk, parsed.path, getSafeEmbeddingChunkTokenLimit(configuredProviderInfo)).map((text) => ({
@@ -8380,7 +8874,6 @@ var Indexer = class {
8380
8874
  contentHash,
8381
8875
  metadata
8382
8876
  });
8383
- fileChunkCount++;
8384
8877
  }
8385
8878
  }
8386
8879
  const retryableFailedChunks = this.collectRetryableFailedChunks(
@@ -9971,6 +10464,159 @@ function findKnowledgeBasePathIndex(knowledgeBases, inputPath, projectRoot) {
9971
10464
  }
9972
10465
 
9973
10466
  // src/tools/utils.ts
10467
+ var import_tiktoken = __toESM(require_tiktoken(), 1);
10468
+ var MIN_CONTEXT_PACK_TOKEN_BUDGET = 128;
10469
+ var MAX_CONTEXT_PACK_TOKEN_BUDGET = 4e3;
10470
+ var DEFAULT_CONTEXT_PACK_TOKEN_BUDGET = 1200;
10471
+ var CONTEXT_TOKENIZER = (0, import_tiktoken.get_encoding)("cl100k_base");
10472
+ function clampContextPackTokenBudget(tokenBudget) {
10473
+ if (tokenBudget === void 0 || !Number.isFinite(tokenBudget)) {
10474
+ return DEFAULT_CONTEXT_PACK_TOKEN_BUDGET;
10475
+ }
10476
+ return Math.min(
10477
+ MAX_CONTEXT_PACK_TOKEN_BUDGET,
10478
+ Math.max(MIN_CONTEXT_PACK_TOKEN_BUDGET, Math.floor(tokenBudget))
10479
+ );
10480
+ }
10481
+ function countContextTokens(text) {
10482
+ return CONTEXT_TOKENIZER.encode(text).length;
10483
+ }
10484
+ function fitTextToContextBudget(text, tokenBudget) {
10485
+ const normalizedBudget = clampContextPackTokenBudget(tokenBudget);
10486
+ const tokenEstimate = countContextTokens(text);
10487
+ if (tokenEstimate <= normalizedBudget) {
10488
+ return {
10489
+ text,
10490
+ tokenBudget: normalizedBudget,
10491
+ tokenEstimate,
10492
+ truncated: false
10493
+ };
10494
+ }
10495
+ const suffix = "\n...[truncated to context token budget]";
10496
+ const codePoints = Array.from(text);
10497
+ let low = 0;
10498
+ let high = codePoints.length;
10499
+ while (low < high) {
10500
+ const middle = Math.ceil((low + high) / 2);
10501
+ const candidate = `${codePoints.slice(0, middle).join("").trimEnd()}${suffix}`;
10502
+ if (countContextTokens(candidate) <= normalizedBudget) low = middle;
10503
+ else high = middle - 1;
10504
+ }
10505
+ const fitted = `${codePoints.slice(0, low).join("").trimEnd()}${suffix}`;
10506
+ return {
10507
+ text: fitted,
10508
+ tokenBudget: normalizedBudget,
10509
+ tokenEstimate: countContextTokens(fitted),
10510
+ truncated: true
10511
+ };
10512
+ }
10513
+ function normalizedLineRange(result) {
10514
+ return result.startLine <= result.endLine ? { start: result.startLine, end: result.endLine } : { start: result.endLine, end: result.startLine };
10515
+ }
10516
+ function rankContextCandidates(results) {
10517
+ return results.map((result, originalIndex) => ({ result, originalIndex })).sort((left, right) => right.result.score - left.result.score || left.originalIndex - right.originalIndex);
10518
+ }
10519
+ function deduplicateContextCandidates(candidates) {
10520
+ const acceptedByFile = /* @__PURE__ */ new Map();
10521
+ const deduplicated = [];
10522
+ for (const { result } of candidates) {
10523
+ const range = normalizedLineRange(result);
10524
+ const accepted = acceptedByFile.get(result.filePath) ?? [];
10525
+ if (accepted.some((item) => item.start <= range.end && range.start <= item.end)) {
10526
+ continue;
10527
+ }
10528
+ accepted.push(range);
10529
+ acceptedByFile.set(result.filePath, accepted);
10530
+ deduplicated.push(result);
10531
+ }
10532
+ return deduplicated;
10533
+ }
10534
+ function diversifyContextCandidates(results) {
10535
+ const byFile = /* @__PURE__ */ new Map();
10536
+ for (const result of results) {
10537
+ const bucket = byFile.get(result.filePath) ?? [];
10538
+ bucket.push(result);
10539
+ byFile.set(result.filePath, bucket);
10540
+ }
10541
+ const files = [...byFile.keys()];
10542
+ const diversified = [];
10543
+ for (let depth = 0; diversified.length < results.length; depth += 1) {
10544
+ for (const file of files) {
10545
+ const result = byFile.get(file)?.[depth];
10546
+ if (result) diversified.push(result);
10547
+ }
10548
+ }
10549
+ return diversified;
10550
+ }
10551
+ function compactEvidenceValue(value, maxChars) {
10552
+ const characters = [...value];
10553
+ if (characters.length <= maxChars) return value;
10554
+ return `\u2026${characters.slice(-(maxChars - 1)).join("")}`;
10555
+ }
10556
+ function formatContextEvidence(result, index) {
10557
+ const symbol = result.name ? ` ${JSON.stringify(compactEvidenceValue(result.name, 80))}` : "";
10558
+ const path24 = compactEvidenceValue(result.filePath, 120);
10559
+ return `[${index}] ${result.chunkType}${symbol} in ${path24}:${result.startLine}-${result.endLine} (score ${result.score.toFixed(2)})`;
10560
+ }
10561
+ function formatContextPack(heading, selected, candidateCount, duplicateCount, limitOmittedCount, budgetOmittedCount) {
10562
+ const lines = selected.map((result, index) => formatContextEvidence(result, index + 1));
10563
+ const notes = [];
10564
+ if (duplicateCount > 0) notes.push(`${duplicateCount} overlapping duplicate${duplicateCount === 1 ? "" : "s"} removed`);
10565
+ if (limitOmittedCount > 0) notes.push(`${limitOmittedCount} additional result${limitOmittedCount === 1 ? "" : "s"} excluded by result limit`);
10566
+ if (budgetOmittedCount > 0) notes.push(`${budgetOmittedCount} additional result${budgetOmittedCount === 1 ? "" : "s"} omitted by token budget`);
10567
+ const footer = notes.length > 0 ? `Selected ${selected.length} of ${candidateCount} candidates; ${notes.join("; ")}.` : `Selected ${selected.length} of ${candidateCount} candidates.`;
10568
+ return `${heading}
10569
+
10570
+ ${lines.join("\n")}
10571
+
10572
+ ${footer}`;
10573
+ }
10574
+ function buildContextPack(results, options = {}) {
10575
+ const requestedTokenBudget = options.tokenBudget ?? DEFAULT_CONTEXT_PACK_TOKEN_BUDGET;
10576
+ const tokenBudget = clampContextPackTokenBudget(options.tokenBudget);
10577
+ const heading = compactEvidenceValue(options.heading?.trim() || "Codebase evidence", 160);
10578
+ const maxResults = Math.max(0, Math.floor(options.maxResults ?? results.length));
10579
+ const candidateCount = results.length;
10580
+ const deduplicated = deduplicateContextCandidates(rankContextCandidates(results));
10581
+ const diversified = diversifyContextCandidates(deduplicated);
10582
+ const duplicateCount = candidateCount - deduplicated.length;
10583
+ const selectable = diversified.slice(0, maxResults);
10584
+ const limitOmittedCount = deduplicated.length - selectable.length;
10585
+ let selected = [];
10586
+ let text = formatContextPack(heading, selected, candidateCount, duplicateCount, limitOmittedCount, selectable.length);
10587
+ for (let count = 1; count <= selectable.length; count += 1) {
10588
+ const candidateSelection = selectable.slice(0, count);
10589
+ const budgetOmittedCount2 = selectable.length - candidateSelection.length;
10590
+ const candidateText = formatContextPack(
10591
+ heading,
10592
+ candidateSelection,
10593
+ candidateCount,
10594
+ duplicateCount,
10595
+ limitOmittedCount,
10596
+ budgetOmittedCount2
10597
+ );
10598
+ if (countContextTokens(candidateText) > tokenBudget) break;
10599
+ selected = candidateSelection;
10600
+ text = candidateText;
10601
+ }
10602
+ const fitted = fitTextToContextBudget(text, tokenBudget);
10603
+ const budgetOmittedCount = selectable.length - selected.length;
10604
+ const omittedCount = candidateCount - selected.length;
10605
+ return {
10606
+ requestedTokenBudget,
10607
+ tokenBudget,
10608
+ text: fitted.text,
10609
+ tokenEstimate: fitted.tokenEstimate,
10610
+ results: selected,
10611
+ candidateCount,
10612
+ deduplicatedCount: deduplicated.length,
10613
+ selectedCount: selected.length,
10614
+ omittedCount,
10615
+ duplicateCount,
10616
+ limitOmittedCount,
10617
+ budgetOmittedCount
10618
+ };
10619
+ }
9974
10620
  var MAX_CONTENT_LINES = 30;
9975
10621
  function truncateContent(content) {
9976
10622
  const lines = content.split("\n");
@@ -12800,6 +13446,253 @@ var pr_impact = tool({
12800
13446
  }
12801
13447
  });
12802
13448
 
13449
+ // src/tools/symbol-inference.ts
13450
+ var IDENTIFIER_RE = /[A-Za-z_$][A-Za-z0-9_$]*/g;
13451
+ var QUOTED_BACKTICK_RE = /`([^`]+)`/g;
13452
+ var QUOTED_SINGLE_RE = /'([^'\\]+)'/g;
13453
+ var QUOTED_DOUBLE_RE = /"([^"]+)"/g;
13454
+ var SYMBOL_LIKE_RE = /^(?:[A-Za-z_$][A-Za-z0-9_$]*)$/;
13455
+ var CAMEL_CASE_RE = /^[a-z_][A-Za-z0-9_$]*[A-Z][A-Za-z0-9_$]*$/;
13456
+ var PASCAL_CASE_RE = /^[A-Z][A-Za-z0-9_$]*$/;
13457
+ var SNAKE_CASE_RE = /^[a-z][a-z0-9_]*_[a-z0-9_]+$/;
13458
+ var DEFINITION_INTENT_RE = /\b(where|defined|definition|define|declaration|symbol|function|method|class|interface|type)\b/i;
13459
+ var STOP_WORDS = /* @__PURE__ */ new Set([
13460
+ "a",
13461
+ "an",
13462
+ "and",
13463
+ "are",
13464
+ "at",
13465
+ "for",
13466
+ "find",
13467
+ "how",
13468
+ "i",
13469
+ "in",
13470
+ "is",
13471
+ "it",
13472
+ "of",
13473
+ "on",
13474
+ "that",
13475
+ "the",
13476
+ "definition",
13477
+ "show",
13478
+ "to",
13479
+ "where",
13480
+ "which",
13481
+ "what",
13482
+ "you",
13483
+ "your",
13484
+ "with"
13485
+ ]);
13486
+ function stripCallSuffix(token) {
13487
+ return token.replace(/\(\s*\)$/, "");
13488
+ }
13489
+ function isLikelySymbolName(token) {
13490
+ if (!SYMBOL_LIKE_RE.test(token)) {
13491
+ return false;
13492
+ }
13493
+ if (STOP_WORDS.has(token.toLowerCase())) {
13494
+ return false;
13495
+ }
13496
+ return CAMEL_CASE_RE.test(token) || PASCAL_CASE_RE.test(token) || SNAKE_CASE_RE.test(token);
13497
+ }
13498
+ function extractQuotedIdentifiers(query) {
13499
+ const identifiers = /* @__PURE__ */ new Set();
13500
+ for (const match of query.matchAll(QUOTED_BACKTICK_RE)) {
13501
+ const candidate = stripCallSuffix(match[1].trim());
13502
+ if (candidate && isLikelySymbolName(candidate)) {
13503
+ identifiers.add(candidate);
13504
+ }
13505
+ }
13506
+ for (const match of query.matchAll(QUOTED_SINGLE_RE)) {
13507
+ const candidate = stripCallSuffix(match[1].trim());
13508
+ if (candidate && isLikelySymbolName(candidate)) {
13509
+ identifiers.add(candidate);
13510
+ }
13511
+ }
13512
+ for (const match of query.matchAll(QUOTED_DOUBLE_RE)) {
13513
+ const candidate = stripCallSuffix(match[1].trim());
13514
+ if (candidate && isLikelySymbolName(candidate)) {
13515
+ identifiers.add(candidate);
13516
+ }
13517
+ }
13518
+ return [...identifiers];
13519
+ }
13520
+ function extractBareIdentifiers(query) {
13521
+ const unquoted = query.replace(QUOTED_BACKTICK_RE, " ").replace(QUOTED_SINGLE_RE, " ").replace(QUOTED_DOUBLE_RE, " ");
13522
+ const identifiers = /* @__PURE__ */ new Set();
13523
+ for (const match of unquoted.matchAll(IDENTIFIER_RE)) {
13524
+ const candidate = stripCallSuffix(match[0]);
13525
+ if (isLikelySymbolName(candidate)) {
13526
+ identifiers.add(candidate);
13527
+ }
13528
+ }
13529
+ return [...identifiers];
13530
+ }
13531
+ function isSingleMeaningfulToken(query, symbol) {
13532
+ const tokens = query.replace(/[`'"()]/g, " ").split(/[^A-Za-z0-9_$]+/).map((token) => token.trim().toLowerCase()).filter((token) => token.length > 0).filter((token) => !STOP_WORDS.has(token));
13533
+ return tokens.length === 1 && tokens[0] === symbol.toLowerCase();
13534
+ }
13535
+ function inferExactSymbolFromQuery(query) {
13536
+ const quoted = extractQuotedIdentifiers(query);
13537
+ if (quoted.length === 1) {
13538
+ return quoted[0];
13539
+ }
13540
+ if (quoted.length > 1) {
13541
+ return void 0;
13542
+ }
13543
+ const candidates = extractBareIdentifiers(query);
13544
+ if (candidates.length !== 1) {
13545
+ return void 0;
13546
+ }
13547
+ const candidate = candidates[0];
13548
+ if (DEFINITION_INTENT_RE.test(query)) {
13549
+ return candidate;
13550
+ }
13551
+ if (isSingleMeaningfulToken(query, candidate)) {
13552
+ return candidate;
13553
+ }
13554
+ return void 0;
13555
+ }
13556
+
13557
+ // src/tools/context.ts
13558
+ var MIN_CONTEXT_RESULT_LIMIT = 1;
13559
+ var MAX_CONTEXT_RESULT_LIMIT = 100;
13560
+ var MIN_CONTEXT_PATH_DEPTH = 1;
13561
+ var MAX_CONTEXT_PATH_DEPTH = 100;
13562
+ function locations(results) {
13563
+ return results.map((result) => ({
13564
+ filePath: result.filePath,
13565
+ startLine: result.startLine,
13566
+ endLine: result.endLine,
13567
+ score: result.score,
13568
+ chunkType: result.chunkType,
13569
+ name: result.name
13570
+ }));
13571
+ }
13572
+ function packedResult(route, routedQuery, pack) {
13573
+ return {
13574
+ text: pack.text,
13575
+ details: {
13576
+ route,
13577
+ routedQuery,
13578
+ tokenBudget: pack.tokenBudget,
13579
+ tokenEstimate: pack.tokenEstimate,
13580
+ candidateCount: pack.candidateCount,
13581
+ deduplicatedCount: pack.deduplicatedCount,
13582
+ selectedCount: pack.selectedCount,
13583
+ omittedCount: pack.omittedCount,
13584
+ duplicateCount: pack.duplicateCount,
13585
+ limitOmittedCount: pack.limitOmittedCount,
13586
+ budgetOmittedCount: pack.budgetOmittedCount,
13587
+ results: locations(pack.results)
13588
+ }
13589
+ };
13590
+ }
13591
+ async function resolveSearchContext(input, operations) {
13592
+ const explicitSymbol = input.symbol ?? void 0;
13593
+ const limit = input.limit ?? 10;
13594
+ const tokenBudget = input.tokenBudget ?? void 0;
13595
+ const lookupSymbol = explicitSymbol ?? inferExactSymbolFromQuery(input.query);
13596
+ if (lookupSymbol) {
13597
+ const definitions = await operations.lookup(lookupSymbol, MAX_CONTEXT_RESULT_LIMIT);
13598
+ if (definitions.length > 0) {
13599
+ return packedResult("definition", lookupSymbol, buildContextPack(definitions, {
13600
+ tokenBudget,
13601
+ maxResults: limit,
13602
+ heading: `Definition evidence for ${JSON.stringify(lookupSymbol)}`
13603
+ }));
13604
+ }
13605
+ if (explicitSymbol) {
13606
+ const fitted = fitTextToContextBudget(
13607
+ formatDefinitionLookup(definitions, lookupSymbol),
13608
+ tokenBudget
13609
+ );
13610
+ return { text: fitted.text };
13611
+ }
13612
+ }
13613
+ const results = await operations.search(input.query, MAX_CONTEXT_RESULT_LIMIT);
13614
+ if (results.length === 0) {
13615
+ const fitted = fitTextToContextBudget(
13616
+ "No matching code found. Try a different query or run index_codebase first.",
13617
+ tokenBudget
13618
+ );
13619
+ return { text: fitted.text };
13620
+ }
13621
+ return packedResult("conceptual", input.query, buildContextPack(results, {
13622
+ tokenBudget,
13623
+ maxResults: limit,
13624
+ heading: `Codebase evidence for ${JSON.stringify(input.query)}`
13625
+ }));
13626
+ }
13627
+ function fittedDetails(route, fitted) {
13628
+ return {
13629
+ route,
13630
+ tokenBudget: fitted.tokenBudget,
13631
+ tokenEstimate: fitted.tokenEstimate,
13632
+ truncated: fitted.truncated
13633
+ };
13634
+ }
13635
+ async function resolveCodebaseContext(projectRoot, host, input) {
13636
+ const from = input.from ?? void 0;
13637
+ const to = input.to ?? void 0;
13638
+ const symbol = input.symbol ?? void 0;
13639
+ const limit = input.limit ?? 10;
13640
+ const maxDepth = input.maxDepth ?? 10;
13641
+ const fileType = input.fileType ?? void 0;
13642
+ const directory = input.directory ?? void 0;
13643
+ const tokenBudget = input.tokenBudget ?? void 0;
13644
+ if (from && to) {
13645
+ const path24 = await getCallGraphPath(projectRoot, host, from, to, maxDepth);
13646
+ if (path24.length > 0) {
13647
+ const fitted2 = fitTextToContextBudget(
13648
+ formatCallGraphPath(from, to, path24),
13649
+ tokenBudget
13650
+ );
13651
+ return {
13652
+ text: fitted2.text,
13653
+ details: fittedDetails("path", fitted2)
13654
+ };
13655
+ }
13656
+ const { callers } = await getCallGraphData(projectRoot, host, {
13657
+ name: to,
13658
+ direction: "callers"
13659
+ });
13660
+ const directEdge = callers.find((edge) => edge.fromSymbolName === from);
13661
+ if (directEdge) {
13662
+ const location = directEdge.fromSymbolFilePath ? ` at ${directEdge.fromSymbolFilePath}:${directEdge.line}` : "";
13663
+ const fitted2 = fitTextToContextBudget(
13664
+ `Direct path: ${from} --${directEdge.callType}--> ${to}${location} (edge is ${directEdge.isResolved ? "resolved" : "unresolved"}).`,
13665
+ tokenBudget
13666
+ );
13667
+ return {
13668
+ text: fitted2.text,
13669
+ details: fittedDetails("direct-edge", fitted2)
13670
+ };
13671
+ }
13672
+ const fitted = fitTextToContextBudget(
13673
+ formatCallGraphPath(from, to, path24),
13674
+ tokenBudget
13675
+ );
13676
+ return {
13677
+ text: fitted.text,
13678
+ details: fittedDetails("path", fitted)
13679
+ };
13680
+ }
13681
+ return resolveSearchContext({ query: input.query, symbol, limit, tokenBudget }, {
13682
+ lookup: (lookupSymbol, retrievalLimit) => implementationLookup(projectRoot, host, lookupSymbol, {
13683
+ limit: retrievalLimit,
13684
+ fileType,
13685
+ directory
13686
+ }),
13687
+ search: (query, retrievalLimit) => searchCodebase(projectRoot, host, query, {
13688
+ limit: retrievalLimit,
13689
+ fileType,
13690
+ directory,
13691
+ metadataOnly: true
13692
+ })
13693
+ });
13694
+ }
13695
+
12803
13696
  // src/tools/index.ts
12804
13697
  import { writeFileSync as writeFileSync5 } from "fs";
12805
13698
  import * as os5 from "os";
@@ -13531,6 +14424,23 @@ function initializeTools2(projectRoot, config) {
13531
14424
  function getIndexerForProject2(directory) {
13532
14425
  return getIndexerForProject(directory, DEFAULT_HOST);
13533
14426
  }
14427
+ var codebase_context = tool2({
14428
+ description: "PREFERRED FIRST TOOL for repository questions. Returns a deduplicated, file-diverse evidence pack within tokenBudget. Provide from and to for dependency paths, symbol for definitions, or only query for conceptual discovery.",
14429
+ args: {
14430
+ query: z2.string().describe("The repository question or behavior to locate"),
14431
+ from: z2.string().nullable().optional().describe("Source symbol for a dependency path"),
14432
+ to: z2.string().nullable().optional().describe("Target symbol for a dependency path"),
14433
+ symbol: z2.string().nullable().optional().describe("Exact symbol for authoritative definition lookup"),
14434
+ limit: z2.number().int().min(MIN_CONTEXT_RESULT_LIMIT).max(MAX_CONTEXT_RESULT_LIMIT).nullable().optional().default(10).describe(`Maximum number of results (${MIN_CONTEXT_RESULT_LIMIT}-${MAX_CONTEXT_RESULT_LIMIT})`),
14435
+ maxDepth: z2.number().int().min(MIN_CONTEXT_PATH_DEPTH).max(MAX_CONTEXT_PATH_DEPTH).nullable().optional().default(10).describe(`Maximum call-path traversal depth (${MIN_CONTEXT_PATH_DEPTH}-${MAX_CONTEXT_PATH_DEPTH})`),
14436
+ fileType: z2.string().nullable().optional().describe("Filter by file extension"),
14437
+ directory: z2.string().nullable().optional().describe("Filter by directory path"),
14438
+ tokenBudget: z2.number().int().min(MIN_CONTEXT_PACK_TOKEN_BUDGET).max(MAX_CONTEXT_PACK_TOKEN_BUDGET).nullable().optional().default(DEFAULT_CONTEXT_PACK_TOKEN_BUDGET).describe(`Maximum response tokens (${MIN_CONTEXT_PACK_TOKEN_BUDGET}-${MAX_CONTEXT_PACK_TOKEN_BUDGET})`)
14439
+ },
14440
+ async execute(args, context) {
14441
+ return (await resolveCodebaseContext(context?.worktree, DEFAULT_HOST, args)).text;
14442
+ }
14443
+ });
13534
14444
  var codebase_peek = tool2({
13535
14445
  description: "Quick lookup of code locations by meaning. Returns only metadata (file, line, name, type) WITHOUT code content. Use this first to find WHERE code is, then use Read tool to examine specific files. Saves tokens by not returning full code blocks. Best for: discovery, navigation, finding multiple related locations.",
13536
14446
  args: {
@@ -14213,6 +15123,7 @@ var plugin = async ({ directory, worktree }) => {
14213
15123
  }
14214
15124
  return {
14215
15125
  tool: {
15126
+ codebase_context,
14216
15127
  codebase_search,
14217
15128
  codebase_peek,
14218
15129
  index_codebase,