opencode-codebase-index 0.17.0 → 0.18.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,13 +6,7 @@ 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 __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() {
9
+ var __commonJS = (cb, mod) => function __require() {
16
10
  try {
17
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
12
  } catch (e) {
@@ -656,467 +650,6 @@ var require_ignore = __commonJS({
656
650
  }
657
651
  });
658
652
 
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
-
1120
653
  // src/index.ts
1121
654
  import * as os6 from "os";
1122
655
  import * as path23 from "path";
@@ -1137,7 +670,8 @@ var DEFAULT_INCLUDE = [
1137
670
  "**/*.{sh,bash,zsh}",
1138
671
  "**/*.{txt,html,htm}",
1139
672
  "**/*.zig",
1140
- "**/*.gd"
673
+ "**/*.gd",
674
+ "**/*.metal"
1141
675
  ];
1142
676
  var DEFAULT_EXCLUDE = [
1143
677
  "**/node_modules/**",
@@ -1328,6 +862,9 @@ function isValidProvider(value) {
1328
862
  return typeof value === "string" && Object.keys(EMBEDDING_MODELS).includes(value);
1329
863
  }
1330
864
  function isValidModel(value, provider) {
865
+ if (typeof value === "string" && provider === "ollama" && value.trim().length > 0) {
866
+ return true;
867
+ }
1331
868
  return typeof value === "string" && Object.keys(EMBEDDING_MODELS[provider]).includes(value);
1332
869
  }
1333
870
  function isValidScope(value) {
@@ -1510,7 +1047,7 @@ var autoDetectProviders = AUTO_DETECT_PROVIDER_ORDER.filter(
1510
1047
  );
1511
1048
 
1512
1049
  // src/config/merger.ts
1513
- import { existsSync as existsSync4, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
1050
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
1514
1051
  import * as path6 from "path";
1515
1052
 
1516
1053
  // src/config/paths.ts
@@ -1692,16 +1229,6 @@ function resolveWorktreeFallbackPath(projectRoot, relativePath) {
1692
1229
  const fallbackPath = path3.join(mainRepoRoot, relativePath);
1693
1230
  return existsSync3(fallbackPath) ? fallbackPath : null;
1694
1231
  }
1695
- function resolveWorktreeFallbackProjectIndexPath(projectRoot, host) {
1696
- const inheritedHostPath = resolveWorktreeFallbackPath(projectRoot, getProjectIndexRelativePath(host));
1697
- if (inheritedHostPath) {
1698
- return inheritedHostPath;
1699
- }
1700
- if (host !== "opencode") {
1701
- return resolveWorktreeFallbackPath(projectRoot, OPENCODE_PROJECT_INDEX_RELATIVE_PATH);
1702
- }
1703
- return null;
1704
- }
1705
1232
  function getHostProjectConfigRelativePath(host) {
1706
1233
  return getProjectConfigRelativePath(host);
1707
1234
  }
@@ -1806,6 +1333,9 @@ function resolveProjectIndexPath(projectRoot, scope, host = "opencode") {
1806
1333
  if (hasHostProjectConfig(projectRoot, host)) {
1807
1334
  return localIndexPath;
1808
1335
  }
1336
+ if (resolveWorktreeMainRepoRoot(projectRoot)) {
1337
+ return localIndexPath;
1338
+ }
1809
1339
  const hostFallback = resolveWorktreeFallbackPath(projectRoot, getProjectIndexRelativePath(host));
1810
1340
  if (hostFallback) {
1811
1341
  return hostFallback;
@@ -1978,12 +1508,6 @@ function loadJsonFile(filePath) {
1978
1508
  function loadConfigFile(filePath) {
1979
1509
  return loadJsonFile(filePath);
1980
1510
  }
1981
- function materializeLocalProjectConfig(projectRoot, config, host = "opencode") {
1982
- const localConfigPath = resolveWritableProjectConfigPath(projectRoot, host);
1983
- mkdirSync(path6.dirname(localConfigPath), { recursive: true });
1984
- writeFileSync(localConfigPath, JSON.stringify(config, null, 2), "utf-8");
1985
- return localConfigPath;
1986
- }
1987
1511
  function loadProjectConfigLayer(projectRoot, host = "opencode") {
1988
1512
  const projectConfigPath = resolveProjectConfigPath(projectRoot, host);
1989
1513
  const projectConfig = loadJsonFile(projectConfigPath);
@@ -2059,13 +1583,13 @@ import { randomUUID } from "crypto";
2059
1583
  import {
2060
1584
  existsSync as existsSync5,
2061
1585
  lstatSync,
2062
- mkdirSync as mkdirSync2,
1586
+ mkdirSync,
2063
1587
  readFileSync as readFileSync4,
2064
1588
  readdirSync as readdirSync2,
2065
1589
  realpathSync,
2066
1590
  renameSync,
2067
1591
  rmSync,
2068
- writeFileSync as writeFileSync2
1592
+ writeFileSync
2069
1593
  } from "fs";
2070
1594
  import * as os2 from "os";
2071
1595
  import * as path7 from "path";
@@ -2176,13 +1700,13 @@ function sameReclaimOwner(left, right) {
2176
1700
  function publishJsonDirectory(finalPath, value) {
2177
1701
  const candidatePath = `${finalPath}.candidate.${process.pid}.${randomUUID()}`;
2178
1702
  try {
2179
- mkdirSync2(candidatePath, { mode: 448 });
1703
+ mkdirSync(candidatePath, { mode: 448 });
2180
1704
  } catch (error) {
2181
1705
  if (getErrorCode(error) === "ENOENT") return false;
2182
1706
  throw error;
2183
1707
  }
2184
1708
  try {
2185
- writeFileSync2(path7.join(candidatePath, OWNER_FILE_NAME), JSON.stringify(value), {
1709
+ writeFileSync(path7.join(candidatePath, OWNER_FILE_NAME), JSON.stringify(value), {
2186
1710
  encoding: "utf-8",
2187
1711
  flag: "wx",
2188
1712
  mode: 384
@@ -2352,7 +1876,7 @@ function isTransientIndexLockContention(error) {
2352
1876
  return error.reason === "active" || error.reason === "reclaiming";
2353
1877
  }
2354
1878
  function acquireIndexLock(indexPath, operation) {
2355
- mkdirSync2(indexPath, { recursive: true });
1879
+ mkdirSync(indexPath, { recursive: true });
2356
1880
  const canonicalIndexPath = realpathSync.native(indexPath);
2357
1881
  const lockPath = path7.join(canonicalIndexPath, "indexing.lock");
2358
1882
  cleanupDeadPublicationCandidates(canonicalIndexPath);
@@ -2422,40 +1946,6 @@ function releaseIndexLock(lease) {
2422
1946
  }
2423
1947
  return true;
2424
1948
  }
2425
- async function withIndexLock(indexPath, operation, callback, options = {}) {
2426
- const lease = acquireIndexLock(indexPath, operation);
2427
- let result;
2428
- let callbackError;
2429
- let callbackFailed = false;
2430
- try {
2431
- result = await callback(lease);
2432
- } catch (error) {
2433
- callbackFailed = true;
2434
- callbackError = error;
2435
- }
2436
- if (!callbackFailed && options.completeRecoveries !== false) {
2437
- try {
2438
- completeLeaseRecovery(lease);
2439
- } catch (error) {
2440
- callbackFailed = true;
2441
- callbackError = error;
2442
- }
2443
- }
2444
- let releaseError;
2445
- try {
2446
- if (!releaseIndexLock(lease)) {
2447
- releaseError = new Error(`Lost ownership of index mutation lease ${lease.owner.token}`);
2448
- }
2449
- } catch (error) {
2450
- releaseError = error;
2451
- }
2452
- if (releaseError !== void 0) {
2453
- if (callbackFailed) throw new AggregateError([callbackError, releaseError], "Index mutation and lease release both failed");
2454
- throw releaseError;
2455
- }
2456
- if (callbackFailed) throw callbackError;
2457
- return result;
2458
- }
2459
1949
  function createLeaseTemporaryPath(targetPath, owner, kind = "tmp") {
2460
1950
  if (kind === "bak") return `${targetPath}.bak.${owner.pid}.${owner.token}`;
2461
1951
  temporaryCounter += 1;
@@ -2494,7 +1984,7 @@ import { existsSync as existsSync10, realpathSync as realpathSync2, statSync as
2494
1984
  import * as path16 from "path";
2495
1985
 
2496
1986
  // src/indexer/index.ts
2497
- import { existsSync as existsSync8, readFileSync as readFileSync7, statSync as statSync3, writeFileSync as writeFileSync3, renameSync as renameSync2, unlinkSync, mkdirSync as mkdirSync3, promises as fsPromises2 } from "fs";
1987
+ import { existsSync as existsSync8, readFileSync as readFileSync7, statSync as statSync3, writeFileSync as writeFileSync2, renameSync as renameSync2, unlinkSync, mkdirSync as mkdirSync2, promises as fsPromises2 } from "fs";
2498
1988
  import * as path13 from "path";
2499
1989
  import { performance as performance2 } from "perf_hooks";
2500
1990
  import { execFile as execFile3 } from "child_process";
@@ -3562,6 +3052,9 @@ function loadOpenCodeAuth() {
3562
3052
  return {};
3563
3053
  }
3564
3054
  async function detectEmbeddingProvider(preferredProvider, model) {
3055
+ if (preferredProvider === "ollama") {
3056
+ return detectOllamaProvider(model);
3057
+ }
3565
3058
  const credentials = await getProviderCredentials(preferredProvider);
3566
3059
  if (credentials) {
3567
3060
  if (!model) {
@@ -3577,10 +3070,16 @@ async function detectEmbeddingProvider(preferredProvider, model) {
3577
3070
  );
3578
3071
  }
3579
3072
  const providerModels = EMBEDDING_MODELS[preferredProvider];
3073
+ const modelInfo = Object.values(providerModels).find((candidate) => candidate.model === model);
3074
+ if (!modelInfo) {
3075
+ throw new Error(
3076
+ `Model '${model}' is not supported by provider '${preferredProvider}'`
3077
+ );
3078
+ }
3580
3079
  return {
3581
3080
  provider: preferredProvider,
3582
3081
  credentials,
3583
- modelInfo: providerModels[model]
3082
+ modelInfo
3584
3083
  };
3585
3084
  }
3586
3085
  throw new Error(
@@ -3589,6 +3088,13 @@ async function detectEmbeddingProvider(preferredProvider, model) {
3589
3088
  }
3590
3089
  async function tryDetectProvider() {
3591
3090
  for (const provider of autoDetectProviders) {
3091
+ if (provider === "ollama") {
3092
+ const ollamaProvider = await tryDetectOllamaProvider();
3093
+ if (ollamaProvider) {
3094
+ return ollamaProvider;
3095
+ }
3096
+ continue;
3097
+ }
3592
3098
  const credentials = await getProviderCredentials(provider);
3593
3099
  if (credentials) {
3594
3100
  return {
@@ -3656,32 +3162,105 @@ function getGoogleCredentials() {
3656
3162
  }
3657
3163
  return null;
3658
3164
  }
3659
- async function getOllamaCredentials() {
3660
- const baseUrl = process.env.OLLAMA_HOST || "http://localhost:11434";
3165
+ async function fetchOllama(url, init) {
3166
+ const controller = new AbortController();
3167
+ const timeoutId = setTimeout(() => controller.abort(), 2e3);
3661
3168
  try {
3662
- const controller = new AbortController();
3663
- const timeoutId = setTimeout(() => controller.abort(), 2e3);
3664
- const response = await fetch(`${baseUrl}/api/tags`, {
3665
- signal: controller.signal
3666
- });
3169
+ return await fetch(url, { ...init, signal: controller.signal });
3170
+ } finally {
3667
3171
  clearTimeout(timeoutId);
3172
+ }
3173
+ }
3174
+ async function getOllamaCredentials() {
3175
+ const baseUrl = (process.env.OLLAMA_HOST || "http://localhost:11434").replace(/\/+$/, "");
3176
+ try {
3177
+ const response = await fetchOllama(`${baseUrl}/api/tags`);
3668
3178
  if (response.ok) {
3669
- const data = await response.json();
3670
- const hasEmbeddingModel = data.models?.some(
3671
- (m) => m.name.includes("nomic-embed") || m.name.includes("mxbai-embed") || m.name.includes("all-minilm")
3672
- );
3673
- if (hasEmbeddingModel) {
3674
- return {
3675
- provider: "ollama",
3676
- baseUrl
3677
- };
3678
- }
3179
+ return {
3180
+ provider: "ollama",
3181
+ baseUrl
3182
+ };
3679
3183
  }
3680
3184
  } catch {
3681
3185
  return null;
3682
3186
  }
3683
3187
  return null;
3684
3188
  }
3189
+ function findCatalogOllamaModel(model) {
3190
+ const stableName = model.endsWith(":latest") ? model.slice(0, -":latest".length) : model;
3191
+ return Object.values(EMBEDDING_MODELS.ollama).find((candidate) => candidate.model === stableName) ?? null;
3192
+ }
3193
+ function getPositiveIntegerMetadata(modelInfo, suffix) {
3194
+ const values = Object.entries(modelInfo).filter(([key]) => key.endsWith(suffix)).map(([, value]) => value).filter((value) => typeof value === "number" && Number.isInteger(value) && value > 0);
3195
+ return values.length === 1 ? values[0] : null;
3196
+ }
3197
+ async function fetchOllamaModelInfo(credentials, model) {
3198
+ const response = await fetchOllama(`${credentials.baseUrl}/api/show`, {
3199
+ method: "POST",
3200
+ headers: { "Content-Type": "application/json" },
3201
+ body: JSON.stringify({ model })
3202
+ });
3203
+ if (!response.ok) {
3204
+ return null;
3205
+ }
3206
+ const data = await response.json();
3207
+ if (!data.capabilities?.includes("embedding") || !data.model_info) {
3208
+ return null;
3209
+ }
3210
+ const dimensions = getPositiveIntegerMetadata(data.model_info, ".embedding_length");
3211
+ const maxTokens = getPositiveIntegerMetadata(data.model_info, ".context_length");
3212
+ if (!dimensions || !maxTokens) {
3213
+ return null;
3214
+ }
3215
+ return {
3216
+ provider: "ollama",
3217
+ model,
3218
+ dimensions,
3219
+ maxTokens,
3220
+ costPer1MTokens: 0
3221
+ };
3222
+ }
3223
+ async function listOllamaModels(credentials) {
3224
+ const response = await fetchOllama(`${credentials.baseUrl}/api/tags`);
3225
+ if (!response.ok) {
3226
+ return [];
3227
+ }
3228
+ const data = await response.json();
3229
+ return [...new Set((data.models ?? []).map((entry) => entry.name ?? entry.model).filter((name) => typeof name === "string" && name.trim().length > 0))];
3230
+ }
3231
+ async function detectOllamaProvider(model) {
3232
+ const credentials = await getOllamaCredentials();
3233
+ if (!credentials) {
3234
+ throw new Error("Preferred provider 'ollama' is not configured or authenticated");
3235
+ }
3236
+ const requestedModel = model?.trim();
3237
+ if (requestedModel) {
3238
+ const catalogModel = findCatalogOllamaModel(requestedModel);
3239
+ if (catalogModel) {
3240
+ return { provider: "ollama", credentials, modelInfo: catalogModel };
3241
+ }
3242
+ }
3243
+ const candidates = requestedModel ? [requestedModel] : await listOllamaModels(credentials);
3244
+ for (const candidate of candidates) {
3245
+ const modelInfo = await fetchOllamaModelInfo(credentials, candidate);
3246
+ if (modelInfo) {
3247
+ return {
3248
+ provider: "ollama",
3249
+ credentials,
3250
+ modelInfo: findCatalogOllamaModel(candidate) ?? modelInfo
3251
+ };
3252
+ }
3253
+ }
3254
+ const detail = model ? `Model '${model}' is not installed or is not embedding-capable` : "No installed embedding-capable Ollama model was found";
3255
+ throw new Error(detail);
3256
+ }
3257
+ async function tryDetectOllamaProvider() {
3258
+ try {
3259
+ return await detectOllamaProvider();
3260
+ } catch {
3261
+ return null;
3262
+ }
3263
+ }
3685
3264
  function getProviderDisplayName(provider) {
3686
3265
  switch (provider) {
3687
3266
  case "github-copilot":
@@ -4021,6 +3600,7 @@ var GoogleEmbeddingProvider = class _GoogleEmbeddingProvider extends BaseEmbeddi
4021
3600
  // src/embeddings/providers/ollama.ts
4022
3601
  var OllamaEmbeddingProvider = class _OllamaEmbeddingProvider extends BaseEmbeddingProvider {
4023
3602
  static MIN_TRUNCATION_CHARS = 512;
3603
+ static REQUEST_TIMEOUT_MS = 12e4;
4024
3604
  constructor(credentials, modelInfo) {
4025
3605
  super(credentials, modelInfo);
4026
3606
  }
@@ -4095,22 +3675,45 @@ var OllamaEmbeddingProvider = class _OllamaEmbeddingProvider extends BaseEmbeddi
4095
3675
  }
4096
3676
  }
4097
3677
  async embedSingle(text) {
4098
- const response = await fetch(`${this.credentials.baseUrl}/api/embeddings`, {
4099
- method: "POST",
4100
- headers: {
4101
- "Content-Type": "application/json"
4102
- },
4103
- body: JSON.stringify({
4104
- model: this.modelInfo.model,
4105
- prompt: text,
4106
- truncate: false
4107
- })
4108
- });
3678
+ const controller = new AbortController();
3679
+ const timeout = setTimeout(
3680
+ () => controller.abort(),
3681
+ _OllamaEmbeddingProvider.REQUEST_TIMEOUT_MS
3682
+ );
3683
+ let response;
3684
+ try {
3685
+ response = await fetch(`${this.credentials.baseUrl}/api/embeddings`, {
3686
+ method: "POST",
3687
+ headers: {
3688
+ "Content-Type": "application/json"
3689
+ },
3690
+ body: JSON.stringify({
3691
+ model: this.modelInfo.model,
3692
+ prompt: text,
3693
+ truncate: false
3694
+ }),
3695
+ signal: controller.signal
3696
+ });
3697
+ } catch (error) {
3698
+ if (error instanceof Error && error.name === "AbortError") {
3699
+ throw new Error(
3700
+ `Ollama embedding request timed out after ${_OllamaEmbeddingProvider.REQUEST_TIMEOUT_MS}ms`
3701
+ );
3702
+ }
3703
+ throw error;
3704
+ } finally {
3705
+ clearTimeout(timeout);
3706
+ }
4109
3707
  if (!response.ok) {
4110
3708
  const error = (await response.text()).slice(0, 500);
4111
3709
  throw new Error(`Ollama embedding API error: ${response.status} - ${error}`);
4112
3710
  }
4113
3711
  const data = await response.json();
3712
+ if (!Array.isArray(data.embedding) || data.embedding.length !== this.modelInfo.dimensions || data.embedding.some((value) => typeof value !== "number" || !Number.isFinite(value))) {
3713
+ throw new Error(
3714
+ `Ollama returned an invalid embedding; expected ${this.modelInfo.dimensions} finite dimensions`
3715
+ );
3716
+ }
4114
3717
  return {
4115
3718
  embedding: data.embedding,
4116
3719
  tokensUsed: this.estimateTokens(text)
@@ -4973,7 +4576,9 @@ function mapChunk(c) {
4973
4576
  return {
4974
4577
  content: c.content,
4975
4578
  startLine: c.startLine ?? c.start_line,
4579
+ startCol: c.startCol ?? c.start_col,
4976
4580
  endLine: c.endLine ?? c.end_line,
4581
+ endCol: c.endCol ?? c.end_col,
4977
4582
  chunkType: c.chunkType ?? c.chunk_type,
4978
4583
  name: c.name ?? void 0,
4979
4584
  language: c.language
@@ -5094,6 +4699,7 @@ function getEmbeddingHeaderParts(chunk, filePath) {
5094
4699
  javascript: "JavaScript",
5095
4700
  python: "Python",
5096
4701
  rust: "Rust",
4702
+ swift: "Swift",
5097
4703
  go: "Go",
5098
4704
  java: "Java"
5099
4705
  };
@@ -5102,7 +4708,16 @@ function getEmbeddingHeaderParts(chunk, filePath) {
5102
4708
  function: "function",
5103
4709
  arrow_function: "arrow function",
5104
4710
  method_definition: "method",
4711
+ method_declaration: "method",
4712
+ protocol_function_declaration: "protocol requirement",
4713
+ init_declaration: "initializer",
4714
+ deinit_declaration: "deinitializer",
4715
+ subscript_declaration: "subscript",
5105
4716
  class_declaration: "class",
4717
+ actor_declaration: "actor",
4718
+ extension_declaration: "extension",
4719
+ protocol_declaration: "protocol",
4720
+ struct_declaration: "struct",
5106
4721
  interface_declaration: "interface",
5107
4722
  type_alias_declaration: "type alias",
5108
4723
  enum_declaration: "enum",
@@ -5773,8 +5388,18 @@ async function getChunkGitBlame(projectRoot, filePath, startLine, endLine) {
5773
5388
  }
5774
5389
 
5775
5390
  // src/indexer/index.ts
5776
- var CALL_GRAPH_LANGUAGES = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx", "python", "go", "rust", "php", "apex", "zig", "gdscript", "matlab", "bash"]);
5777
- var CASE_INSENSITIVE_LANGUAGES = /* @__PURE__ */ new Set(["apex"]);
5391
+ var CALL_GRAPH_LANGUAGES = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx", "python", "go", "rust", "swift", "php", "apex", "zig", "gdscript", "matlab", "bash", "c", "cpp", "metal"]);
5392
+ var CASE_INSENSITIVE_LANGUAGES = /* @__PURE__ */ new Set(["apex", "php"]);
5393
+ var CALL_GRAPH_RESOLUTION_VERSION = "4";
5394
+ var PHP_FUNCTION_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5395
+ "function_declaration",
5396
+ "function",
5397
+ "function_definition"
5398
+ ]);
5399
+ var PHP_CLASS_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5400
+ "class_declaration",
5401
+ "class_definition"
5402
+ ]);
5778
5403
  var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5779
5404
  "function_declaration",
5780
5405
  "function",
@@ -5787,6 +5412,9 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5787
5412
  "enum_declaration",
5788
5413
  "function_definition",
5789
5414
  "class_definition",
5415
+ "class_specifier",
5416
+ "struct_specifier",
5417
+ "namespace_definition",
5790
5418
  "decorated_definition",
5791
5419
  "method_declaration",
5792
5420
  "type_declaration",
@@ -5802,6 +5430,14 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5802
5430
  "test_declaration",
5803
5431
  "struct_declaration",
5804
5432
  "union_declaration",
5433
+ // Synthetic Swift declarations or declarations specific to tree-sitter-swift.
5434
+ "actor_declaration",
5435
+ "extension_declaration",
5436
+ "protocol_declaration",
5437
+ "protocol_function_declaration",
5438
+ "init_declaration",
5439
+ "deinit_declaration",
5440
+ "subscript_declaration",
5805
5441
  // GDScript declarations whose names participate in the call graph.
5806
5442
  // `function_definition` and `class_definition` are already in the set
5807
5443
  // above (shared with Python/C/Bash and Python, respectively).
@@ -5811,6 +5447,53 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5811
5447
  "const_statement",
5812
5448
  "class_name_statement"
5813
5449
  ]);
5450
+ var C_FAMILY_TYPE_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set(["class_specifier", "struct_specifier"]);
5451
+ function isCompatibleCFamilyCallTarget(language, callType, symbolKind) {
5452
+ if (language !== "c" && language !== "cpp") return true;
5453
+ if (symbolKind === "namespace_definition") return callType === "Import";
5454
+ const isTypeSymbol = C_FAMILY_TYPE_SYMBOL_CHUNK_TYPES.has(symbolKind);
5455
+ if (callType === "Constructor" || callType === "Inherits" || callType === "Implements") {
5456
+ return isTypeSymbol;
5457
+ }
5458
+ return !isTypeSymbol;
5459
+ }
5460
+ var EXECUTABLE_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
5461
+ "function_declaration",
5462
+ "function",
5463
+ "arrow_function",
5464
+ "method_definition",
5465
+ "function_definition",
5466
+ "method_declaration",
5467
+ "function_item",
5468
+ "protocol_function_declaration",
5469
+ "init_declaration",
5470
+ "deinit_declaration",
5471
+ "subscript_declaration",
5472
+ "constructor_definition",
5473
+ "trigger_declaration",
5474
+ "test_declaration"
5475
+ ]);
5476
+ function findEnclosingSymbol(symbols, line, column) {
5477
+ let best;
5478
+ for (const symbol of symbols) {
5479
+ if (line < symbol.startLine || line > symbol.endLine) continue;
5480
+ if (column !== void 0 && (line === symbol.startLine && column < symbol.startCol || line === symbol.endLine && column >= symbol.endCol)) {
5481
+ continue;
5482
+ }
5483
+ if (!best) {
5484
+ best = symbol;
5485
+ continue;
5486
+ }
5487
+ const span = symbol.endLine - symbol.startLine;
5488
+ const bestSpan = best.endLine - best.startLine;
5489
+ const isNarrowerPositionRange = column !== void 0 && span === bestSpan && symbol.startLine === best.startLine && symbol.endLine === best.endLine && symbol.startCol >= best.startCol && symbol.endCol <= best.endCol && (symbol.startCol > best.startCol || symbol.endCol < best.endCol);
5490
+ const isMoreSpecificTie = span === bestSpan && symbol.startLine === best.startLine && EXECUTABLE_SYMBOL_CHUNK_TYPES.has(symbol.kind) && !EXECUTABLE_SYMBOL_CHUNK_TYPES.has(best.kind);
5491
+ if (span < bestSpan || span === bestSpan && symbol.startLine > best.startLine || isNarrowerPositionRange || isMoreSpecificTie) {
5492
+ best = symbol;
5493
+ }
5494
+ }
5495
+ return best;
5496
+ }
5814
5497
  function float32ArrayToBuffer(arr) {
5815
5498
  const float32 = new Float32Array(arr);
5816
5499
  return Buffer.from(float32.buffer);
@@ -5895,6 +5578,8 @@ function hasBlameMetadata(metadata) {
5895
5578
  }
5896
5579
  var INDEX_METADATA_VERSION = "1";
5897
5580
  var EMBEDDING_STRATEGY_VERSION = "2";
5581
+ var SWIFT_PARSER_VERSION = "1";
5582
+ var METAL_PARSER_VERSION = "1";
5898
5583
  var RANKING_TOKEN_CACHE_LIMIT = 4096;
5899
5584
  var RANK_HYBRID_CACHE_LIMIT = 256;
5900
5585
  function createPendingChunkStorageText(texts) {
@@ -6217,15 +5902,25 @@ function chunkTypeBoost(chunkType) {
6217
5902
  case "function_declaration":
6218
5903
  case "method":
6219
5904
  case "method_definition":
5905
+ case "method_declaration":
5906
+ case "protocol_function_declaration":
5907
+ case "init_declaration":
5908
+ case "deinit_declaration":
5909
+ case "subscript_declaration":
6220
5910
  case "class":
6221
5911
  case "class_declaration":
5912
+ case "actor_declaration":
5913
+ case "extension_declaration":
6222
5914
  return 0.2;
6223
5915
  case "interface":
6224
5916
  case "type":
6225
5917
  case "enum":
5918
+ case "enum_declaration":
6226
5919
  case "struct":
5920
+ case "struct_declaration":
6227
5921
  case "impl":
6228
5922
  case "trait":
5923
+ case "protocol_declaration":
6229
5924
  case "module":
6230
5925
  return 0.1;
6231
5926
  default:
@@ -6332,11 +6027,21 @@ function isImplementationChunkType(chunkType) {
6332
6027
  "function_declaration",
6333
6028
  "method",
6334
6029
  "method_definition",
6030
+ "method_declaration",
6031
+ "protocol_function_declaration",
6032
+ "init_declaration",
6033
+ "deinit_declaration",
6034
+ "subscript_declaration",
6335
6035
  "class",
6336
6036
  "class_declaration",
6037
+ "actor_declaration",
6038
+ "extension_declaration",
6337
6039
  "interface",
6040
+ "protocol_declaration",
6338
6041
  "type",
6339
6042
  "enum",
6043
+ "enum_declaration",
6044
+ "struct_declaration",
6340
6045
  "module"
6341
6046
  ].includes(chunkType);
6342
6047
  }
@@ -7288,9 +6993,9 @@ var Indexer = class {
7288
6993
  atomicWriteSync(targetPath, data) {
7289
6994
  const lease = this.requireActiveLease();
7290
6995
  const tempPath = createLeaseTemporaryPath(targetPath, lease.owner, "tmp");
7291
- mkdirSync3(path13.dirname(targetPath), { recursive: true });
6996
+ mkdirSync2(path13.dirname(targetPath), { recursive: true });
7292
6997
  try {
7293
- writeFileSync3(tempPath, data);
6998
+ writeFileSync2(tempPath, data);
7294
6999
  renameSync2(tempPath, targetPath);
7295
7000
  } finally {
7296
7001
  removeLeaseTemporaryPath(tempPath);
@@ -7339,6 +7044,29 @@ var Indexer = class {
7339
7044
  const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
7340
7045
  return `index.forceReembed.${projectHash}`;
7341
7046
  }
7047
+ getCallGraphResolutionMetadataKey() {
7048
+ if (this.config.scope !== "global") {
7049
+ return "index.callGraphResolutionVersion";
7050
+ }
7051
+ const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
7052
+ return `index.callGraphResolutionVersion.${projectHash}`;
7053
+ }
7054
+ getSwiftParserVersionMetadataKey() {
7055
+ const key = "index.parser.swiftVersion";
7056
+ if (this.config.scope !== "global") {
7057
+ return key;
7058
+ }
7059
+ const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
7060
+ return `${key}.${projectHash}`;
7061
+ }
7062
+ getMetalParserVersionMetadataKey() {
7063
+ const key = "index.parser.metalVersion";
7064
+ if (this.config.scope !== "global") {
7065
+ return key;
7066
+ }
7067
+ const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
7068
+ return `${key}.${projectHash}`;
7069
+ }
7342
7070
  hasProjectForceReembedPending() {
7343
7071
  return this.config.scope === "global" && this.database?.getMetadata(this.getProjectForceReembedMetadataKey()) === "true";
7344
7072
  }
@@ -8499,6 +8227,7 @@ var Indexer = class {
8499
8227
  this.database.setMetadata("index.embeddingProvider", provider.provider);
8500
8228
  this.database.setMetadata("index.embeddingModel", provider.modelInfo.model);
8501
8229
  this.database.setMetadata("index.embeddingDimensions", provider.modelInfo.dimensions.toString());
8230
+ this.database.setMetadata(this.getCallGraphResolutionMetadataKey(), CALL_GRAPH_RESOLUTION_VERSION);
8502
8231
  if (this.config.scope === "global") {
8503
8232
  if (completeProjectEmbeddingStrategyReset) {
8504
8233
  this.database.setMetadata(this.getProjectEmbeddingStrategyMetadataKey(), EMBEDDING_STRATEGY_VERSION);
@@ -8686,6 +8415,20 @@ var Indexer = class {
8686
8415
  totalChunks: 0
8687
8416
  });
8688
8417
  this.loadFileHashCache();
8418
+ const swiftParserMetadataKey = this.getSwiftParserVersionMetadataKey();
8419
+ const reparseCachedSwiftFiles = database.getMetadata(swiftParserMetadataKey) !== SWIFT_PARSER_VERSION;
8420
+ const metalParserMetadataKey = this.getMetalParserVersionMetadataKey();
8421
+ const reparseCachedMetalFiles = database.getMetadata(metalParserMetadataKey) !== METAL_PARSER_VERSION;
8422
+ if (reparseCachedSwiftFiles && Array.from(this.fileHashCache.keys()).some(
8423
+ (filePath) => path13.extname(filePath).toLowerCase() === ".swift"
8424
+ )) {
8425
+ this.logger.info("Reindexing cached Swift files for parser support");
8426
+ }
8427
+ if (reparseCachedMetalFiles && Array.from(this.fileHashCache.keys()).some(
8428
+ (filePath) => path13.extname(filePath).toLowerCase() === ".metal"
8429
+ )) {
8430
+ this.logger.info("Reindexing cached Metal files for parser support");
8431
+ }
8689
8432
  const includePatterns = [...this.config.include, ...this.config.additionalInclude];
8690
8433
  const { files, skipped } = await collectFiles(
8691
8434
  this.projectRoot,
@@ -8705,10 +8448,17 @@ var Indexer = class {
8705
8448
  const changedFiles = [];
8706
8449
  const unchangedFilePaths = /* @__PURE__ */ new Set();
8707
8450
  const currentFileHashes = /* @__PURE__ */ new Map();
8451
+ const needsCallGraphResolutionMigration = database.getMetadata(this.getCallGraphResolutionMetadataKey()) !== CALL_GRAPH_RESOLUTION_VERSION;
8708
8452
  for (const f of files) {
8709
8453
  const currentHash = hashFile(f.path);
8710
8454
  currentFileHashes.set(f.path, currentHash);
8711
- if (this.fileHashCache.get(f.path) === currentHash) {
8455
+ const cachedHashMatches = this.fileHashCache.get(f.path) === currentHash;
8456
+ const needsCallGraphRefresh = cachedHashMatches && needsCallGraphResolutionMigration && database.getChunksByFile(f.path).some(
8457
+ (chunk) => chunk.language === "php" || chunk.language === "c" || chunk.language === "cpp"
8458
+ );
8459
+ const requiresSwiftParserUpgrade = reparseCachedSwiftFiles && path13.extname(f.path).toLowerCase() === ".swift";
8460
+ const requiresMetalParserUpgrade = reparseCachedMetalFiles && path13.extname(f.path).toLowerCase() === ".metal";
8461
+ if (cachedHashMatches && !needsCallGraphRefresh && !requiresSwiftParserUpgrade && !requiresMetalParserUpgrade) {
8712
8462
  unchangedFilePaths.add(f.path);
8713
8463
  this.logger.recordCacheHit();
8714
8464
  } else {
@@ -8910,16 +8660,28 @@ var Indexer = class {
8910
8660
  const fileSymbols = [];
8911
8661
  for (const chunk of parsed.chunks) {
8912
8662
  if (!chunk.name || !CALL_GRAPH_SYMBOL_CHUNK_TYPES.has(chunk.chunkType)) continue;
8913
- const symbolId = `sym_${hashContent(parsed.path + ":" + chunk.name + ":" + chunk.chunkType + ":" + chunk.startLine).slice(0, 16)}`;
8663
+ const existingMetalSymbol = chunk.language === "metal" ? fileSymbols.find(
8664
+ (symbol2) => symbol2.name === chunk.name && symbol2.kind === chunk.chunkType && symbol2.startLine <= chunk.endLine && chunk.startLine <= symbol2.endLine
8665
+ ) : void 0;
8666
+ if (existingMetalSymbol) {
8667
+ existingMetalSymbol.startLine = Math.min(existingMetalSymbol.startLine, chunk.startLine);
8668
+ existingMetalSymbol.endLine = Math.max(existingMetalSymbol.endLine, chunk.endLine);
8669
+ existingMetalSymbol.startCol = Math.min(existingMetalSymbol.startCol, chunk.startCol ?? 0);
8670
+ existingMetalSymbol.endCol = Math.max(existingMetalSymbol.endCol, chunk.endCol ?? 0);
8671
+ continue;
8672
+ }
8673
+ const symbolId = `sym_${hashContent(
8674
+ parsed.path + ":" + chunk.name + ":" + chunk.chunkType + ":" + chunk.startLine + ":" + (chunk.startCol ?? 0)
8675
+ ).slice(0, 16)}`;
8914
8676
  const symbol = {
8915
8677
  id: symbolId,
8916
8678
  filePath: parsed.path,
8917
8679
  name: chunk.name,
8918
8680
  kind: chunk.chunkType,
8919
8681
  startLine: chunk.startLine,
8920
- startCol: 0,
8682
+ startCol: chunk.startCol ?? 0,
8921
8683
  endLine: chunk.endLine,
8922
- endCol: 0,
8684
+ endCol: chunk.endCol ?? 0,
8923
8685
  language: chunk.language
8924
8686
  };
8925
8687
  fileSymbols.push(symbol);
@@ -8944,8 +8706,10 @@ var Indexer = class {
8944
8706
  if (callSites.length === 0) continue;
8945
8707
  const edges = [];
8946
8708
  for (const site of callSites) {
8947
- const enclosingSymbol = fileSymbols.find(
8948
- (sym) => site.line >= sym.startLine && site.line <= sym.endLine
8709
+ const enclosingSymbol = findEnclosingSymbol(
8710
+ fileSymbols,
8711
+ site.line,
8712
+ site.column
8949
8713
  );
8950
8714
  if (!enclosingSymbol) continue;
8951
8715
  const edgeId = `edge_${hashContent(enclosingSymbol.id + ":" + site.calleeName + ":" + site.line + ":" + site.column).slice(0, 16)}`;
@@ -8964,7 +8728,21 @@ var Indexer = class {
8964
8728
  if (edges.length > 0) {
8965
8729
  database.upsertCallEdgesBatch(edges);
8966
8730
  for (const edge of edges) {
8967
- const candidates = symbolsByName.get(normalizeSymbolKey(edge.targetName));
8731
+ let candidates = symbolsByName.get(normalizeSymbolKey(edge.targetName));
8732
+ if (fileLanguage === "php" && candidates) {
8733
+ if (edge.callType === "Constructor") {
8734
+ candidates = candidates.filter(
8735
+ (candidate) => PHP_CLASS_SYMBOL_CHUNK_TYPES.has(candidate.kind)
8736
+ );
8737
+ } else if (edge.callType === "Call") {
8738
+ candidates = candidates.filter(
8739
+ (candidate) => PHP_FUNCTION_SYMBOL_CHUNK_TYPES.has(candidate.kind)
8740
+ );
8741
+ }
8742
+ }
8743
+ candidates = candidates?.filter(
8744
+ (symbol) => isCompatibleCFamilyCallTarget(fileLanguage, edge.callType, symbol.kind)
8745
+ );
8968
8746
  if (candidates && candidates.length === 1) {
8969
8747
  database.resolveCallEdge(edge.id, candidates[0].id);
8970
8748
  }
@@ -9019,6 +8797,8 @@ var Indexer = class {
9019
8797
  this.saveFileHashCache();
9020
8798
  this.saveFailedBatches([]);
9021
8799
  }
8800
+ database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
8801
+ database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
9022
8802
  this.saveIndexMetadata(configuredProviderInfo);
9023
8803
  this.indexCompatibility = { compatible: true };
9024
8804
  stats.durationMs = Date.now() - startTime;
@@ -9046,6 +8826,8 @@ var Indexer = class {
9046
8826
  this.saveFileHashCache();
9047
8827
  this.saveFailedBatches([]);
9048
8828
  }
8829
+ database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
8830
+ database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
9049
8831
  this.saveIndexMetadata(configuredProviderInfo);
9050
8832
  this.indexCompatibility = { compatible: true };
9051
8833
  stats.durationMs = Date.now() - startTime;
@@ -9316,6 +9098,8 @@ var Indexer = class {
9316
9098
  if (forceScopedReembed && failedForcedChunkIds.size === 0) {
9317
9099
  database.deleteMetadata(this.getProjectForceReembedMetadataKey());
9318
9100
  }
9101
+ database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
9102
+ database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
9319
9103
  this.saveIndexMetadata(configuredProviderInfo);
9320
9104
  this.indexCompatibility = { compatible: true };
9321
9105
  this.logger.recordIndexingEnd();
@@ -10464,11 +10248,11 @@ function findKnowledgeBasePathIndex(knowledgeBases, inputPath, projectRoot) {
10464
10248
  }
10465
10249
 
10466
10250
  // src/tools/utils.ts
10467
- var import_tiktoken = __toESM(require_tiktoken(), 1);
10251
+ import { get_encoding } from "tiktoken";
10468
10252
  var MIN_CONTEXT_PACK_TOKEN_BUDGET = 128;
10469
10253
  var MAX_CONTEXT_PACK_TOKEN_BUDGET = 4e3;
10470
10254
  var DEFAULT_CONTEXT_PACK_TOKEN_BUDGET = 1200;
10471
- var CONTEXT_TOKENIZER = (0, import_tiktoken.get_encoding)("cl100k_base");
10255
+ var CONTEXT_TOKENIZER = get_encoding("cl100k_base");
10472
10256
  function clampContextPackTokenBudget(tokenBudget) {
10473
10257
  if (tokenBudget === void 0 || !Number.isFinite(tokenBudget)) {
10474
10258
  return DEFAULT_CONTEXT_PACK_TOKEN_BUDGET;
@@ -10870,7 +10654,7 @@ ${truncateContent(r.content)}
10870
10654
  }
10871
10655
 
10872
10656
  // src/tools/config-state.ts
10873
- import { existsSync as existsSync9, mkdirSync as mkdirSync4, writeFileSync as writeFileSync4 } from "fs";
10657
+ import { existsSync as existsSync9, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
10874
10658
  import * as path15 from "path";
10875
10659
  function normalizeKnowledgeBasePaths(config, projectRoot) {
10876
10660
  const normalized = { ...config };
@@ -10901,7 +10685,7 @@ function saveConfig(projectRoot, config, host = "opencode") {
10901
10685
  const configDir = path15.dirname(configPath);
10902
10686
  const configBaseDir = path15.dirname(configDir);
10903
10687
  if (!existsSync9(configDir)) {
10904
- mkdirSync4(configDir, { recursive: true });
10688
+ mkdirSync3(configDir, { recursive: true });
10905
10689
  }
10906
10690
  const serializableConfig = { ...config };
10907
10691
  if (Array.isArray(serializableConfig.knowledgeBases)) {
@@ -10909,7 +10693,7 @@ function saveConfig(projectRoot, config, host = "opencode") {
10909
10693
  (kb) => serializeConfigPathValue(kb, configBaseDir)
10910
10694
  );
10911
10695
  }
10912
- writeFileSync4(configPath, JSON.stringify(serializableConfig, null, 2) + "\n", "utf-8");
10696
+ writeFileSync3(configPath, JSON.stringify(serializableConfig, null, 2) + "\n", "utf-8");
10913
10697
  }
10914
10698
 
10915
10699
  // src/tools/operations.ts
@@ -10976,15 +10760,6 @@ function refreshIndexerForDirectory(projectRoot, host = "opencode", config = par
10976
10760
  indexerCache.set(key, indexer);
10977
10761
  configCache.set(key, config);
10978
10762
  }
10979
- function shouldForceLocalizeProjectIndex(projectRoot, host = "opencode") {
10980
- const root = getProjectRoot(projectRoot, host);
10981
- const localIndexPath = path16.join(root, getHostProjectIndexRelativePath(host));
10982
- if (existsSync10(localIndexPath)) {
10983
- return false;
10984
- }
10985
- const inheritedIndexPath = resolveWorktreeFallbackProjectIndexPath(root, host);
10986
- return inheritedIndexPath !== null;
10987
- }
10988
10763
  async function searchCodebase(projectRoot, host, query, options = {}) {
10989
10764
  const indexer = getIndexerForProject(projectRoot, host);
10990
10765
  return indexer.search(query, options.limit, {
@@ -11034,9 +10809,7 @@ async function getCallGraphPath(projectRoot, host, from, to, maxDepth) {
11034
10809
  }
11035
10810
  async function runIndexCodebase(projectRoot, host, args, onProgress) {
11036
10811
  const root = getProjectRoot(projectRoot, host);
11037
- const key = getIndexerCacheKey(root, host);
11038
- let indexer = getIndexerForProject(root, host);
11039
- const runtimeConfig = configCache.get(key);
10812
+ const indexer = getIndexerForProject(root, host);
11040
10813
  try {
11041
10814
  if (args.estimateOnly) {
11042
10815
  return { kind: "estimate", estimate: await indexer.estimateCost() };
@@ -11057,19 +10830,7 @@ async function runIndexCodebase(projectRoot, host, args, onProgress) {
11057
10830
  return Promise.resolve();
11058
10831
  });
11059
10832
  };
11060
- let stats;
11061
- if (args.force && shouldForceLocalizeProjectIndex(root, host)) {
11062
- const inheritedIndexPath = resolveProjectIndexPath(root, runtimeConfig.scope, host);
11063
- stats = await withIndexLock(inheritedIndexPath, "force-index", async () => {
11064
- materializeLocalProjectConfig(root, loadProjectConfigLayer(root, host), host);
11065
- refreshIndexerForDirectory(root, host, runtimeConfig);
11066
- indexer = getIndexerForProject(root, host);
11067
- return runIndex(indexer);
11068
- }, { completeRecoveries: false });
11069
- } else {
11070
- stats = await runIndex(indexer);
11071
- }
11072
- return { kind: "stats", stats };
10833
+ return { kind: "stats", stats: await runIndex(indexer) };
11073
10834
  } catch (error) {
11074
10835
  const busyResult = getIndexBusyResult(error);
11075
10836
  if (!busyResult) throw error;
@@ -13694,7 +13455,7 @@ async function resolveCodebaseContext(projectRoot, host, input) {
13694
13455
  }
13695
13456
 
13696
13457
  // src/tools/index.ts
13697
- import { writeFileSync as writeFileSync5 } from "fs";
13458
+ import { writeFileSync as writeFileSync4 } from "fs";
13698
13459
  import * as os5 from "os";
13699
13460
  import * as path21 from "path";
13700
13461
 
@@ -14671,7 +14432,7 @@ var index_visualize = tool2({
14671
14432
  }
14672
14433
  const html = generateVisualizationHtml(vizData);
14673
14434
  const outputPath = path21.join(os5.tmpdir(), `call-graph-${Date.now()}.html`);
14674
- writeFileSync5(outputPath, html, "utf-8");
14435
+ writeFileSync4(outputPath, html, "utf-8");
14675
14436
  let result = `Temporal call graph visualization generated: ${outputPath}
14676
14437
 
14677
14438
  `;