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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +45 -8
- package/THIRD_PARTY_LICENSES.md +64 -0
- package/dist/cli.cjs +561 -792
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +568 -805
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +343 -576
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +359 -598
- package/dist/index.js.map +1 -1
- package/dist/pi-extension.cjs +736 -967
- package/dist/pi-extension.cjs.map +1 -1
- package/dist/pi-extension.js +700 -937
- package/dist/pi-extension.js.map +1 -1
- package/native/codebase-index-native.darwin-arm64.node +0 -0
- package/native/codebase-index-native.darwin-x64.node +0 -0
- package/native/codebase-index-native.linux-arm64-gnu.node +0 -0
- package/native/codebase-index-native.linux-x64-gnu.node +0 -0
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -655,467 +655,6 @@ var require_ignore = __commonJS({
|
|
|
655
655
|
}
|
|
656
656
|
});
|
|
657
657
|
|
|
658
|
-
// node_modules/tiktoken/tiktoken_bg.cjs
|
|
659
|
-
var require_tiktoken_bg = __commonJS({
|
|
660
|
-
"node_modules/tiktoken/tiktoken_bg.cjs"(exports2, module3) {
|
|
661
|
-
"use strict";
|
|
662
|
-
var wasm;
|
|
663
|
-
module3.exports.__wbg_set_wasm = function(val) {
|
|
664
|
-
wasm = val;
|
|
665
|
-
};
|
|
666
|
-
var lTextDecoder = typeof TextDecoder === "undefined" ? (0, module3.require)("util").TextDecoder : TextDecoder;
|
|
667
|
-
var cachedTextDecoder = new lTextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
668
|
-
cachedTextDecoder.decode();
|
|
669
|
-
var cachedUint8ArrayMemory0 = null;
|
|
670
|
-
function getUint8ArrayMemory0() {
|
|
671
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
672
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
673
|
-
}
|
|
674
|
-
return cachedUint8ArrayMemory0;
|
|
675
|
-
}
|
|
676
|
-
function getStringFromWasm0(ptr, len) {
|
|
677
|
-
ptr = ptr >>> 0;
|
|
678
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
679
|
-
}
|
|
680
|
-
var heap = new Array(128).fill(void 0);
|
|
681
|
-
heap.push(void 0, null, true, false);
|
|
682
|
-
var heap_next = heap.length;
|
|
683
|
-
function addHeapObject(obj) {
|
|
684
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
685
|
-
const idx = heap_next;
|
|
686
|
-
heap_next = heap[idx];
|
|
687
|
-
heap[idx] = obj;
|
|
688
|
-
return idx;
|
|
689
|
-
}
|
|
690
|
-
function handleError(f, args) {
|
|
691
|
-
try {
|
|
692
|
-
return f.apply(this, args);
|
|
693
|
-
} catch (e) {
|
|
694
|
-
wasm.__wbindgen_export_0(addHeapObject(e));
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
function getObject(idx) {
|
|
698
|
-
return heap[idx];
|
|
699
|
-
}
|
|
700
|
-
function dropObject(idx) {
|
|
701
|
-
if (idx < 132) return;
|
|
702
|
-
heap[idx] = heap_next;
|
|
703
|
-
heap_next = idx;
|
|
704
|
-
}
|
|
705
|
-
function takeObject(idx) {
|
|
706
|
-
const ret = getObject(idx);
|
|
707
|
-
dropObject(idx);
|
|
708
|
-
return ret;
|
|
709
|
-
}
|
|
710
|
-
var WASM_VECTOR_LEN = 0;
|
|
711
|
-
var lTextEncoder = typeof TextEncoder === "undefined" ? (0, module3.require)("util").TextEncoder : TextEncoder;
|
|
712
|
-
var cachedTextEncoder = new lTextEncoder("utf-8");
|
|
713
|
-
var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
|
|
714
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
715
|
-
} : function(arg, view) {
|
|
716
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
717
|
-
view.set(buf);
|
|
718
|
-
return {
|
|
719
|
-
read: arg.length,
|
|
720
|
-
written: buf.length
|
|
721
|
-
};
|
|
722
|
-
};
|
|
723
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
724
|
-
if (realloc === void 0) {
|
|
725
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
726
|
-
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
727
|
-
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
728
|
-
WASM_VECTOR_LEN = buf.length;
|
|
729
|
-
return ptr2;
|
|
730
|
-
}
|
|
731
|
-
let len = arg.length;
|
|
732
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
733
|
-
const mem = getUint8ArrayMemory0();
|
|
734
|
-
let offset = 0;
|
|
735
|
-
for (; offset < len; offset++) {
|
|
736
|
-
const code = arg.charCodeAt(offset);
|
|
737
|
-
if (code > 127) break;
|
|
738
|
-
mem[ptr + offset] = code;
|
|
739
|
-
}
|
|
740
|
-
if (offset !== len) {
|
|
741
|
-
if (offset !== 0) {
|
|
742
|
-
arg = arg.slice(offset);
|
|
743
|
-
}
|
|
744
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
745
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
746
|
-
const ret = encodeString(arg, view);
|
|
747
|
-
offset += ret.written;
|
|
748
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
749
|
-
}
|
|
750
|
-
WASM_VECTOR_LEN = offset;
|
|
751
|
-
return ptr;
|
|
752
|
-
}
|
|
753
|
-
function isLikeNone(x) {
|
|
754
|
-
return x === void 0 || x === null;
|
|
755
|
-
}
|
|
756
|
-
var cachedDataViewMemory0 = null;
|
|
757
|
-
function getDataViewMemory0() {
|
|
758
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
759
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
760
|
-
}
|
|
761
|
-
return cachedDataViewMemory0;
|
|
762
|
-
}
|
|
763
|
-
var cachedUint32ArrayMemory0 = null;
|
|
764
|
-
function getUint32ArrayMemory0() {
|
|
765
|
-
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
766
|
-
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
767
|
-
}
|
|
768
|
-
return cachedUint32ArrayMemory0;
|
|
769
|
-
}
|
|
770
|
-
function getArrayU32FromWasm0(ptr, len) {
|
|
771
|
-
ptr = ptr >>> 0;
|
|
772
|
-
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
773
|
-
}
|
|
774
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
775
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
776
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
777
|
-
WASM_VECTOR_LEN = arg.length;
|
|
778
|
-
return ptr;
|
|
779
|
-
}
|
|
780
|
-
function passArray32ToWasm0(arg, malloc) {
|
|
781
|
-
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
782
|
-
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
783
|
-
WASM_VECTOR_LEN = arg.length;
|
|
784
|
-
return ptr;
|
|
785
|
-
}
|
|
786
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
787
|
-
ptr = ptr >>> 0;
|
|
788
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
789
|
-
}
|
|
790
|
-
module3.exports.get_encoding = function(encoding, extend_special_tokens) {
|
|
791
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
792
|
-
try {
|
|
793
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
794
|
-
const ptr0 = passStringToWasm0(encoding, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
795
|
-
const len0 = WASM_VECTOR_LEN;
|
|
796
|
-
wasm.get_encoding(retptr, ptr0, len0, addHeapObject(extend_special_tokens));
|
|
797
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
798
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
799
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
800
|
-
if (r2) {
|
|
801
|
-
throw takeObject(r1);
|
|
802
|
-
}
|
|
803
|
-
return Tiktoken.__wrap(r0);
|
|
804
|
-
} finally {
|
|
805
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
module3.exports.encoding_for_model = function(model, extend_special_tokens) {
|
|
809
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
810
|
-
try {
|
|
811
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
812
|
-
const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
813
|
-
const len0 = WASM_VECTOR_LEN;
|
|
814
|
-
wasm.encoding_for_model(retptr, ptr0, len0, addHeapObject(extend_special_tokens));
|
|
815
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
816
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
817
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
818
|
-
if (r2) {
|
|
819
|
-
throw takeObject(r1);
|
|
820
|
-
}
|
|
821
|
-
return Tiktoken.__wrap(r0);
|
|
822
|
-
} finally {
|
|
823
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
|
-
module3.exports.get_encoding_name_for_model = function(model) {
|
|
827
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
828
|
-
let deferred3_0;
|
|
829
|
-
let deferred3_1;
|
|
830
|
-
try {
|
|
831
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
832
|
-
const ptr0 = passStringToWasm0(model, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
833
|
-
const len0 = WASM_VECTOR_LEN;
|
|
834
|
-
wasm.get_encoding_name_for_model(retptr, ptr0, len0);
|
|
835
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
836
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
837
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
838
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
839
|
-
var ptr2 = r0;
|
|
840
|
-
var len2 = r1;
|
|
841
|
-
if (r3) {
|
|
842
|
-
ptr2 = 0;
|
|
843
|
-
len2 = 0;
|
|
844
|
-
throw takeObject(r2);
|
|
845
|
-
}
|
|
846
|
-
deferred3_0 = ptr2;
|
|
847
|
-
deferred3_1 = len2;
|
|
848
|
-
return getStringFromWasm0(ptr2, len2);
|
|
849
|
-
} finally {
|
|
850
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
851
|
-
wasm.__wbindgen_export_3(deferred3_0, deferred3_1, 1);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
var TiktokenFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
855
|
-
}, unregister: () => {
|
|
856
|
-
} } : new FinalizationRegistry((ptr) => wasm.__wbg_tiktoken_free(ptr >>> 0, 1));
|
|
857
|
-
var Tiktoken = class _Tiktoken {
|
|
858
|
-
/**
|
|
859
|
-
* @param {string} tiktoken_bfe
|
|
860
|
-
* @param {any} special_tokens
|
|
861
|
-
* @param {string} pat_str
|
|
862
|
-
*/
|
|
863
|
-
constructor(tiktoken_bfe, special_tokens, pat_str) {
|
|
864
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
865
|
-
const ptr0 = passStringToWasm0(tiktoken_bfe, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
866
|
-
const len0 = WASM_VECTOR_LEN;
|
|
867
|
-
const ptr1 = passStringToWasm0(pat_str, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
868
|
-
const len1 = WASM_VECTOR_LEN;
|
|
869
|
-
const ret = wasm.tiktoken_new(ptr0, len0, addHeapObject(special_tokens), ptr1, len1);
|
|
870
|
-
this.__wbg_ptr = ret >>> 0;
|
|
871
|
-
TiktokenFinalization.register(this, this.__wbg_ptr, this);
|
|
872
|
-
return this;
|
|
873
|
-
}
|
|
874
|
-
/** @returns {string | undefined} */
|
|
875
|
-
get name() {
|
|
876
|
-
try {
|
|
877
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
878
|
-
wasm.tiktoken_name(retptr, this.__wbg_ptr);
|
|
879
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
880
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
881
|
-
let v1;
|
|
882
|
-
if (r0 !== 0) {
|
|
883
|
-
v1 = getStringFromWasm0(r0, r1).slice();
|
|
884
|
-
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
885
|
-
}
|
|
886
|
-
return v1;
|
|
887
|
-
} finally {
|
|
888
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
static __wrap(ptr) {
|
|
892
|
-
ptr = ptr >>> 0;
|
|
893
|
-
const obj = Object.create(_Tiktoken.prototype);
|
|
894
|
-
obj.__wbg_ptr = ptr;
|
|
895
|
-
TiktokenFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
896
|
-
return obj;
|
|
897
|
-
}
|
|
898
|
-
__destroy_into_raw() {
|
|
899
|
-
const ptr = this.__wbg_ptr;
|
|
900
|
-
this.__wbg_ptr = 0;
|
|
901
|
-
TiktokenFinalization.unregister(this);
|
|
902
|
-
return ptr;
|
|
903
|
-
}
|
|
904
|
-
free() {
|
|
905
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
906
|
-
const ptr = this.__destroy_into_raw();
|
|
907
|
-
wasm.__wbg_tiktoken_free(ptr, 0);
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* @param {string} text
|
|
911
|
-
* @param {any} allowed_special
|
|
912
|
-
* @param {any} disallowed_special
|
|
913
|
-
* @returns {Uint32Array}
|
|
914
|
-
*/
|
|
915
|
-
encode(text, allowed_special, disallowed_special) {
|
|
916
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
917
|
-
try {
|
|
918
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
919
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
920
|
-
const len0 = WASM_VECTOR_LEN;
|
|
921
|
-
wasm.tiktoken_encode(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(allowed_special), addHeapObject(disallowed_special));
|
|
922
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
923
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
924
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
925
|
-
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
926
|
-
if (r3) {
|
|
927
|
-
throw takeObject(r2);
|
|
928
|
-
}
|
|
929
|
-
var v2 = getArrayU32FromWasm0(r0, r1).slice();
|
|
930
|
-
wasm.__wbindgen_export_3(r0, r1 * 4, 4);
|
|
931
|
-
return v2;
|
|
932
|
-
} finally {
|
|
933
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* @param {string} text
|
|
938
|
-
* @returns {Uint32Array}
|
|
939
|
-
*/
|
|
940
|
-
encode_ordinary(text) {
|
|
941
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
942
|
-
try {
|
|
943
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
944
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
945
|
-
const len0 = WASM_VECTOR_LEN;
|
|
946
|
-
wasm.tiktoken_encode_ordinary(retptr, this.__wbg_ptr, ptr0, len0);
|
|
947
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
948
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
949
|
-
var v2 = getArrayU32FromWasm0(r0, r1).slice();
|
|
950
|
-
wasm.__wbindgen_export_3(r0, r1 * 4, 4);
|
|
951
|
-
return v2;
|
|
952
|
-
} finally {
|
|
953
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* @param {string} text
|
|
958
|
-
* @param {any} allowed_special
|
|
959
|
-
* @param {any} disallowed_special
|
|
960
|
-
* @returns {any}
|
|
961
|
-
*/
|
|
962
|
-
encode_with_unstable(text, allowed_special, disallowed_special) {
|
|
963
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
964
|
-
try {
|
|
965
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
966
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
967
|
-
const len0 = WASM_VECTOR_LEN;
|
|
968
|
-
wasm.tiktoken_encode_with_unstable(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(allowed_special), addHeapObject(disallowed_special));
|
|
969
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
970
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
971
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
972
|
-
if (r2) {
|
|
973
|
-
throw takeObject(r1);
|
|
974
|
-
}
|
|
975
|
-
return takeObject(r0);
|
|
976
|
-
} finally {
|
|
977
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* @param {Uint8Array} bytes
|
|
982
|
-
* @returns {number}
|
|
983
|
-
*/
|
|
984
|
-
encode_single_token(bytes) {
|
|
985
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
986
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export_1);
|
|
987
|
-
const len0 = WASM_VECTOR_LEN;
|
|
988
|
-
const ret = wasm.tiktoken_encode_single_token(this.__wbg_ptr, ptr0, len0);
|
|
989
|
-
return ret >>> 0;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* @param {Uint32Array} tokens
|
|
993
|
-
* @returns {Uint8Array}
|
|
994
|
-
*/
|
|
995
|
-
decode(tokens) {
|
|
996
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
997
|
-
try {
|
|
998
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
999
|
-
const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_export_1);
|
|
1000
|
-
const len0 = WASM_VECTOR_LEN;
|
|
1001
|
-
wasm.tiktoken_decode(retptr, this.__wbg_ptr, ptr0, len0);
|
|
1002
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1003
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1004
|
-
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1005
|
-
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
1006
|
-
return v2;
|
|
1007
|
-
} finally {
|
|
1008
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* @param {number} token
|
|
1013
|
-
* @returns {Uint8Array}
|
|
1014
|
-
*/
|
|
1015
|
-
decode_single_token_bytes(token) {
|
|
1016
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
1017
|
-
try {
|
|
1018
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1019
|
-
wasm.tiktoken_decode_single_token_bytes(retptr, this.__wbg_ptr, token);
|
|
1020
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1021
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1022
|
-
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1023
|
-
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
1024
|
-
return v1;
|
|
1025
|
-
} finally {
|
|
1026
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
/** @returns {any} */
|
|
1030
|
-
token_byte_values() {
|
|
1031
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
1032
|
-
const ret = wasm.tiktoken_token_byte_values(this.__wbg_ptr);
|
|
1033
|
-
return takeObject(ret);
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
module3.exports.Tiktoken = Tiktoken;
|
|
1037
|
-
module3.exports.__wbg_parse_def2e24ef1252aff = function() {
|
|
1038
|
-
return handleError(function(arg0, arg1) {
|
|
1039
|
-
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
1040
|
-
return addHeapObject(ret);
|
|
1041
|
-
}, arguments);
|
|
1042
|
-
};
|
|
1043
|
-
module3.exports.__wbg_stringify_f7ed6987935b4a24 = function() {
|
|
1044
|
-
return handleError(function(arg0) {
|
|
1045
|
-
const ret = JSON.stringify(getObject(arg0));
|
|
1046
|
-
return addHeapObject(ret);
|
|
1047
|
-
}, arguments);
|
|
1048
|
-
};
|
|
1049
|
-
module3.exports.__wbindgen_error_new = function(arg0, arg1) {
|
|
1050
|
-
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1051
|
-
return addHeapObject(ret);
|
|
1052
|
-
};
|
|
1053
|
-
module3.exports.__wbindgen_is_undefined = function(arg0) {
|
|
1054
|
-
const ret = getObject(arg0) === void 0;
|
|
1055
|
-
return ret;
|
|
1056
|
-
};
|
|
1057
|
-
module3.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
1058
|
-
takeObject(arg0);
|
|
1059
|
-
};
|
|
1060
|
-
module3.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
1061
|
-
if (wasm == null) throw new Error("tiktoken: WASM binary has not been propery initialized.");
|
|
1062
|
-
const obj = getObject(arg1);
|
|
1063
|
-
const ret = typeof obj === "string" ? obj : void 0;
|
|
1064
|
-
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
1065
|
-
var len1 = WASM_VECTOR_LEN;
|
|
1066
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1067
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1068
|
-
};
|
|
1069
|
-
module3.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
1070
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1071
|
-
};
|
|
1072
|
-
}
|
|
1073
|
-
});
|
|
1074
|
-
|
|
1075
|
-
// node_modules/tiktoken/tiktoken.cjs
|
|
1076
|
-
var require_tiktoken = __commonJS({
|
|
1077
|
-
"node_modules/tiktoken/tiktoken.cjs"(exports2) {
|
|
1078
|
-
"use strict";
|
|
1079
|
-
var wasm = require_tiktoken_bg();
|
|
1080
|
-
var imports = {};
|
|
1081
|
-
imports["./tiktoken_bg.js"] = wasm;
|
|
1082
|
-
var path24 = require("path");
|
|
1083
|
-
var fs = require("fs");
|
|
1084
|
-
var candidates = __dirname.split(path24.sep).reduce((memo, _, index, array) => {
|
|
1085
|
-
const prefix = array.slice(0, index + 1).join(path24.sep) + path24.sep;
|
|
1086
|
-
if (!prefix.includes("node_modules" + path24.sep)) {
|
|
1087
|
-
memo.unshift(
|
|
1088
|
-
path24.join(
|
|
1089
|
-
prefix,
|
|
1090
|
-
"node_modules",
|
|
1091
|
-
"tiktoken",
|
|
1092
|
-
"",
|
|
1093
|
-
"./tiktoken_bg.wasm"
|
|
1094
|
-
)
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
return memo;
|
|
1098
|
-
}, []);
|
|
1099
|
-
candidates.unshift(path24.join(__dirname, "./tiktoken_bg.wasm"));
|
|
1100
|
-
var bytes = null;
|
|
1101
|
-
for (const candidate of candidates) {
|
|
1102
|
-
try {
|
|
1103
|
-
bytes = fs.readFileSync(candidate);
|
|
1104
|
-
break;
|
|
1105
|
-
} catch {
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
if (bytes == null) throw new Error("Missing tiktoken_bg.wasm");
|
|
1109
|
-
var wasmModule = new WebAssembly.Module(bytes);
|
|
1110
|
-
var wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
1111
|
-
wasm.__wbg_set_wasm(wasmInstance.exports);
|
|
1112
|
-
exports2["get_encoding"] = wasm["get_encoding"];
|
|
1113
|
-
exports2["encoding_for_model"] = wasm["encoding_for_model"];
|
|
1114
|
-
exports2["get_encoding_name_for_model"] = wasm["get_encoding_name_for_model"];
|
|
1115
|
-
exports2["Tiktoken"] = wasm["Tiktoken"];
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
|
|
1119
658
|
// src/index.ts
|
|
1120
659
|
var index_exports = {};
|
|
1121
660
|
__export(index_exports, {
|
|
@@ -1141,7 +680,8 @@ var DEFAULT_INCLUDE = [
|
|
|
1141
680
|
"**/*.{sh,bash,zsh}",
|
|
1142
681
|
"**/*.{txt,html,htm}",
|
|
1143
682
|
"**/*.zig",
|
|
1144
|
-
"**/*.gd"
|
|
683
|
+
"**/*.gd",
|
|
684
|
+
"**/*.metal"
|
|
1145
685
|
];
|
|
1146
686
|
var DEFAULT_EXCLUDE = [
|
|
1147
687
|
"**/node_modules/**",
|
|
@@ -1332,6 +872,9 @@ function isValidProvider(value) {
|
|
|
1332
872
|
return typeof value === "string" && Object.keys(EMBEDDING_MODELS).includes(value);
|
|
1333
873
|
}
|
|
1334
874
|
function isValidModel(value, provider) {
|
|
875
|
+
if (typeof value === "string" && provider === "ollama" && value.trim().length > 0) {
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
1335
878
|
return typeof value === "string" && Object.keys(EMBEDDING_MODELS[provider]).includes(value);
|
|
1336
879
|
}
|
|
1337
880
|
function isValidScope(value) {
|
|
@@ -1696,16 +1239,6 @@ function resolveWorktreeFallbackPath(projectRoot, relativePath) {
|
|
|
1696
1239
|
const fallbackPath = path3.join(mainRepoRoot, relativePath);
|
|
1697
1240
|
return (0, import_fs3.existsSync)(fallbackPath) ? fallbackPath : null;
|
|
1698
1241
|
}
|
|
1699
|
-
function resolveWorktreeFallbackProjectIndexPath(projectRoot, host) {
|
|
1700
|
-
const inheritedHostPath = resolveWorktreeFallbackPath(projectRoot, getProjectIndexRelativePath(host));
|
|
1701
|
-
if (inheritedHostPath) {
|
|
1702
|
-
return inheritedHostPath;
|
|
1703
|
-
}
|
|
1704
|
-
if (host !== "opencode") {
|
|
1705
|
-
return resolveWorktreeFallbackPath(projectRoot, OPENCODE_PROJECT_INDEX_RELATIVE_PATH);
|
|
1706
|
-
}
|
|
1707
|
-
return null;
|
|
1708
|
-
}
|
|
1709
1242
|
function getHostProjectConfigRelativePath(host) {
|
|
1710
1243
|
return getProjectConfigRelativePath(host);
|
|
1711
1244
|
}
|
|
@@ -1810,6 +1343,9 @@ function resolveProjectIndexPath(projectRoot, scope, host = "opencode") {
|
|
|
1810
1343
|
if (hasHostProjectConfig(projectRoot, host)) {
|
|
1811
1344
|
return localIndexPath;
|
|
1812
1345
|
}
|
|
1346
|
+
if (resolveWorktreeMainRepoRoot(projectRoot)) {
|
|
1347
|
+
return localIndexPath;
|
|
1348
|
+
}
|
|
1813
1349
|
const hostFallback = resolveWorktreeFallbackPath(projectRoot, getProjectIndexRelativePath(host));
|
|
1814
1350
|
if (hostFallback) {
|
|
1815
1351
|
return hostFallback;
|
|
@@ -1982,12 +1518,6 @@ function loadJsonFile(filePath) {
|
|
|
1982
1518
|
function loadConfigFile(filePath) {
|
|
1983
1519
|
return loadJsonFile(filePath);
|
|
1984
1520
|
}
|
|
1985
|
-
function materializeLocalProjectConfig(projectRoot, config, host = "opencode") {
|
|
1986
|
-
const localConfigPath = resolveWritableProjectConfigPath(projectRoot, host);
|
|
1987
|
-
(0, import_fs4.mkdirSync)(path6.dirname(localConfigPath), { recursive: true });
|
|
1988
|
-
(0, import_fs4.writeFileSync)(localConfigPath, JSON.stringify(config, null, 2), "utf-8");
|
|
1989
|
-
return localConfigPath;
|
|
1990
|
-
}
|
|
1991
1521
|
function loadProjectConfigLayer(projectRoot, host = "opencode") {
|
|
1992
1522
|
const projectConfigPath = resolveProjectConfigPath(projectRoot, host);
|
|
1993
1523
|
const projectConfig = loadJsonFile(projectConfigPath);
|
|
@@ -2416,40 +1946,6 @@ function releaseIndexLock(lease) {
|
|
|
2416
1946
|
}
|
|
2417
1947
|
return true;
|
|
2418
1948
|
}
|
|
2419
|
-
async function withIndexLock(indexPath, operation, callback, options = {}) {
|
|
2420
|
-
const lease = acquireIndexLock(indexPath, operation);
|
|
2421
|
-
let result;
|
|
2422
|
-
let callbackError;
|
|
2423
|
-
let callbackFailed = false;
|
|
2424
|
-
try {
|
|
2425
|
-
result = await callback(lease);
|
|
2426
|
-
} catch (error) {
|
|
2427
|
-
callbackFailed = true;
|
|
2428
|
-
callbackError = error;
|
|
2429
|
-
}
|
|
2430
|
-
if (!callbackFailed && options.completeRecoveries !== false) {
|
|
2431
|
-
try {
|
|
2432
|
-
completeLeaseRecovery(lease);
|
|
2433
|
-
} catch (error) {
|
|
2434
|
-
callbackFailed = true;
|
|
2435
|
-
callbackError = error;
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
let releaseError;
|
|
2439
|
-
try {
|
|
2440
|
-
if (!releaseIndexLock(lease)) {
|
|
2441
|
-
releaseError = new Error(`Lost ownership of index mutation lease ${lease.owner.token}`);
|
|
2442
|
-
}
|
|
2443
|
-
} catch (error) {
|
|
2444
|
-
releaseError = error;
|
|
2445
|
-
}
|
|
2446
|
-
if (releaseError !== void 0) {
|
|
2447
|
-
if (callbackFailed) throw new AggregateError([callbackError, releaseError], "Index mutation and lease release both failed");
|
|
2448
|
-
throw releaseError;
|
|
2449
|
-
}
|
|
2450
|
-
if (callbackFailed) throw callbackError;
|
|
2451
|
-
return result;
|
|
2452
|
-
}
|
|
2453
1949
|
function createLeaseTemporaryPath(targetPath, owner, kind = "tmp") {
|
|
2454
1950
|
if (kind === "bak") return `${targetPath}.bak.${owner.pid}.${owner.token}`;
|
|
2455
1951
|
temporaryCounter += 1;
|
|
@@ -3556,6 +3052,9 @@ function loadOpenCodeAuth() {
|
|
|
3556
3052
|
return {};
|
|
3557
3053
|
}
|
|
3558
3054
|
async function detectEmbeddingProvider(preferredProvider, model) {
|
|
3055
|
+
if (preferredProvider === "ollama") {
|
|
3056
|
+
return detectOllamaProvider(model);
|
|
3057
|
+
}
|
|
3559
3058
|
const credentials = await getProviderCredentials(preferredProvider);
|
|
3560
3059
|
if (credentials) {
|
|
3561
3060
|
if (!model) {
|
|
@@ -3571,10 +3070,16 @@ async function detectEmbeddingProvider(preferredProvider, model) {
|
|
|
3571
3070
|
);
|
|
3572
3071
|
}
|
|
3573
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
|
+
}
|
|
3574
3079
|
return {
|
|
3575
3080
|
provider: preferredProvider,
|
|
3576
3081
|
credentials,
|
|
3577
|
-
modelInfo
|
|
3082
|
+
modelInfo
|
|
3578
3083
|
};
|
|
3579
3084
|
}
|
|
3580
3085
|
throw new Error(
|
|
@@ -3583,6 +3088,13 @@ async function detectEmbeddingProvider(preferredProvider, model) {
|
|
|
3583
3088
|
}
|
|
3584
3089
|
async function tryDetectProvider() {
|
|
3585
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
|
+
}
|
|
3586
3098
|
const credentials = await getProviderCredentials(provider);
|
|
3587
3099
|
if (credentials) {
|
|
3588
3100
|
return {
|
|
@@ -3650,32 +3162,105 @@ function getGoogleCredentials() {
|
|
|
3650
3162
|
}
|
|
3651
3163
|
return null;
|
|
3652
3164
|
}
|
|
3653
|
-
async function
|
|
3654
|
-
const
|
|
3165
|
+
async function fetchOllama(url, init) {
|
|
3166
|
+
const controller = new AbortController();
|
|
3167
|
+
const timeoutId = setTimeout(() => controller.abort(), 2e3);
|
|
3655
3168
|
try {
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
const response = await fetch(`${baseUrl}/api/tags`, {
|
|
3659
|
-
signal: controller.signal
|
|
3660
|
-
});
|
|
3169
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
3170
|
+
} finally {
|
|
3661
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`);
|
|
3662
3178
|
if (response.ok) {
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
if (hasEmbeddingModel) {
|
|
3668
|
-
return {
|
|
3669
|
-
provider: "ollama",
|
|
3670
|
-
baseUrl
|
|
3671
|
-
};
|
|
3672
|
-
}
|
|
3179
|
+
return {
|
|
3180
|
+
provider: "ollama",
|
|
3181
|
+
baseUrl
|
|
3182
|
+
};
|
|
3673
3183
|
}
|
|
3674
3184
|
} catch {
|
|
3675
3185
|
return null;
|
|
3676
3186
|
}
|
|
3677
3187
|
return null;
|
|
3678
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
|
+
}
|
|
3679
3264
|
function getProviderDisplayName(provider) {
|
|
3680
3265
|
switch (provider) {
|
|
3681
3266
|
case "github-copilot":
|
|
@@ -4015,6 +3600,7 @@ var GoogleEmbeddingProvider = class _GoogleEmbeddingProvider extends BaseEmbeddi
|
|
|
4015
3600
|
// src/embeddings/providers/ollama.ts
|
|
4016
3601
|
var OllamaEmbeddingProvider = class _OllamaEmbeddingProvider extends BaseEmbeddingProvider {
|
|
4017
3602
|
static MIN_TRUNCATION_CHARS = 512;
|
|
3603
|
+
static REQUEST_TIMEOUT_MS = 12e4;
|
|
4018
3604
|
constructor(credentials, modelInfo) {
|
|
4019
3605
|
super(credentials, modelInfo);
|
|
4020
3606
|
}
|
|
@@ -4089,22 +3675,45 @@ var OllamaEmbeddingProvider = class _OllamaEmbeddingProvider extends BaseEmbeddi
|
|
|
4089
3675
|
}
|
|
4090
3676
|
}
|
|
4091
3677
|
async embedSingle(text) {
|
|
4092
|
-
const
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
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
|
+
}
|
|
4103
3707
|
if (!response.ok) {
|
|
4104
3708
|
const error = (await response.text()).slice(0, 500);
|
|
4105
3709
|
throw new Error(`Ollama embedding API error: ${response.status} - ${error}`);
|
|
4106
3710
|
}
|
|
4107
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
|
+
}
|
|
4108
3717
|
return {
|
|
4109
3718
|
embedding: data.embedding,
|
|
4110
3719
|
tokensUsed: this.estimateTokens(text)
|
|
@@ -4968,7 +4577,9 @@ function mapChunk(c) {
|
|
|
4968
4577
|
return {
|
|
4969
4578
|
content: c.content,
|
|
4970
4579
|
startLine: c.startLine ?? c.start_line,
|
|
4580
|
+
startCol: c.startCol ?? c.start_col,
|
|
4971
4581
|
endLine: c.endLine ?? c.end_line,
|
|
4582
|
+
endCol: c.endCol ?? c.end_col,
|
|
4972
4583
|
chunkType: c.chunkType ?? c.chunk_type,
|
|
4973
4584
|
name: c.name ?? void 0,
|
|
4974
4585
|
language: c.language
|
|
@@ -5089,6 +4700,7 @@ function getEmbeddingHeaderParts(chunk, filePath) {
|
|
|
5089
4700
|
javascript: "JavaScript",
|
|
5090
4701
|
python: "Python",
|
|
5091
4702
|
rust: "Rust",
|
|
4703
|
+
swift: "Swift",
|
|
5092
4704
|
go: "Go",
|
|
5093
4705
|
java: "Java"
|
|
5094
4706
|
};
|
|
@@ -5097,7 +4709,16 @@ function getEmbeddingHeaderParts(chunk, filePath) {
|
|
|
5097
4709
|
function: "function",
|
|
5098
4710
|
arrow_function: "arrow function",
|
|
5099
4711
|
method_definition: "method",
|
|
4712
|
+
method_declaration: "method",
|
|
4713
|
+
protocol_function_declaration: "protocol requirement",
|
|
4714
|
+
init_declaration: "initializer",
|
|
4715
|
+
deinit_declaration: "deinitializer",
|
|
4716
|
+
subscript_declaration: "subscript",
|
|
5100
4717
|
class_declaration: "class",
|
|
4718
|
+
actor_declaration: "actor",
|
|
4719
|
+
extension_declaration: "extension",
|
|
4720
|
+
protocol_declaration: "protocol",
|
|
4721
|
+
struct_declaration: "struct",
|
|
5101
4722
|
interface_declaration: "interface",
|
|
5102
4723
|
type_alias_declaration: "type alias",
|
|
5103
4724
|
enum_declaration: "enum",
|
|
@@ -5768,8 +5389,18 @@ async function getChunkGitBlame(projectRoot, filePath, startLine, endLine) {
|
|
|
5768
5389
|
}
|
|
5769
5390
|
|
|
5770
5391
|
// src/indexer/index.ts
|
|
5771
|
-
var CALL_GRAPH_LANGUAGES = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx", "python", "go", "rust", "php", "apex", "zig", "gdscript", "matlab", "bash"]);
|
|
5772
|
-
var CASE_INSENSITIVE_LANGUAGES = /* @__PURE__ */ new Set(["apex"]);
|
|
5392
|
+
var CALL_GRAPH_LANGUAGES = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx", "python", "go", "rust", "swift", "php", "apex", "zig", "gdscript", "matlab", "bash", "c", "cpp", "metal"]);
|
|
5393
|
+
var CASE_INSENSITIVE_LANGUAGES = /* @__PURE__ */ new Set(["apex", "php"]);
|
|
5394
|
+
var CALL_GRAPH_RESOLUTION_VERSION = "4";
|
|
5395
|
+
var PHP_FUNCTION_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
5396
|
+
"function_declaration",
|
|
5397
|
+
"function",
|
|
5398
|
+
"function_definition"
|
|
5399
|
+
]);
|
|
5400
|
+
var PHP_CLASS_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
5401
|
+
"class_declaration",
|
|
5402
|
+
"class_definition"
|
|
5403
|
+
]);
|
|
5773
5404
|
var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
5774
5405
|
"function_declaration",
|
|
5775
5406
|
"function",
|
|
@@ -5782,6 +5413,9 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
|
5782
5413
|
"enum_declaration",
|
|
5783
5414
|
"function_definition",
|
|
5784
5415
|
"class_definition",
|
|
5416
|
+
"class_specifier",
|
|
5417
|
+
"struct_specifier",
|
|
5418
|
+
"namespace_definition",
|
|
5785
5419
|
"decorated_definition",
|
|
5786
5420
|
"method_declaration",
|
|
5787
5421
|
"type_declaration",
|
|
@@ -5797,6 +5431,14 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
|
5797
5431
|
"test_declaration",
|
|
5798
5432
|
"struct_declaration",
|
|
5799
5433
|
"union_declaration",
|
|
5434
|
+
// Synthetic Swift declarations or declarations specific to tree-sitter-swift.
|
|
5435
|
+
"actor_declaration",
|
|
5436
|
+
"extension_declaration",
|
|
5437
|
+
"protocol_declaration",
|
|
5438
|
+
"protocol_function_declaration",
|
|
5439
|
+
"init_declaration",
|
|
5440
|
+
"deinit_declaration",
|
|
5441
|
+
"subscript_declaration",
|
|
5800
5442
|
// GDScript declarations whose names participate in the call graph.
|
|
5801
5443
|
// `function_definition` and `class_definition` are already in the set
|
|
5802
5444
|
// above (shared with Python/C/Bash and Python, respectively).
|
|
@@ -5806,6 +5448,53 @@ var CALL_GRAPH_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
|
5806
5448
|
"const_statement",
|
|
5807
5449
|
"class_name_statement"
|
|
5808
5450
|
]);
|
|
5451
|
+
var C_FAMILY_TYPE_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set(["class_specifier", "struct_specifier"]);
|
|
5452
|
+
function isCompatibleCFamilyCallTarget(language, callType, symbolKind) {
|
|
5453
|
+
if (language !== "c" && language !== "cpp") return true;
|
|
5454
|
+
if (symbolKind === "namespace_definition") return callType === "Import";
|
|
5455
|
+
const isTypeSymbol = C_FAMILY_TYPE_SYMBOL_CHUNK_TYPES.has(symbolKind);
|
|
5456
|
+
if (callType === "Constructor" || callType === "Inherits" || callType === "Implements") {
|
|
5457
|
+
return isTypeSymbol;
|
|
5458
|
+
}
|
|
5459
|
+
return !isTypeSymbol;
|
|
5460
|
+
}
|
|
5461
|
+
var EXECUTABLE_SYMBOL_CHUNK_TYPES = /* @__PURE__ */ new Set([
|
|
5462
|
+
"function_declaration",
|
|
5463
|
+
"function",
|
|
5464
|
+
"arrow_function",
|
|
5465
|
+
"method_definition",
|
|
5466
|
+
"function_definition",
|
|
5467
|
+
"method_declaration",
|
|
5468
|
+
"function_item",
|
|
5469
|
+
"protocol_function_declaration",
|
|
5470
|
+
"init_declaration",
|
|
5471
|
+
"deinit_declaration",
|
|
5472
|
+
"subscript_declaration",
|
|
5473
|
+
"constructor_definition",
|
|
5474
|
+
"trigger_declaration",
|
|
5475
|
+
"test_declaration"
|
|
5476
|
+
]);
|
|
5477
|
+
function findEnclosingSymbol(symbols, line, column) {
|
|
5478
|
+
let best;
|
|
5479
|
+
for (const symbol of symbols) {
|
|
5480
|
+
if (line < symbol.startLine || line > symbol.endLine) continue;
|
|
5481
|
+
if (column !== void 0 && (line === symbol.startLine && column < symbol.startCol || line === symbol.endLine && column >= symbol.endCol)) {
|
|
5482
|
+
continue;
|
|
5483
|
+
}
|
|
5484
|
+
if (!best) {
|
|
5485
|
+
best = symbol;
|
|
5486
|
+
continue;
|
|
5487
|
+
}
|
|
5488
|
+
const span = symbol.endLine - symbol.startLine;
|
|
5489
|
+
const bestSpan = best.endLine - best.startLine;
|
|
5490
|
+
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);
|
|
5491
|
+
const isMoreSpecificTie = span === bestSpan && symbol.startLine === best.startLine && EXECUTABLE_SYMBOL_CHUNK_TYPES.has(symbol.kind) && !EXECUTABLE_SYMBOL_CHUNK_TYPES.has(best.kind);
|
|
5492
|
+
if (span < bestSpan || span === bestSpan && symbol.startLine > best.startLine || isNarrowerPositionRange || isMoreSpecificTie) {
|
|
5493
|
+
best = symbol;
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
5496
|
+
return best;
|
|
5497
|
+
}
|
|
5809
5498
|
function float32ArrayToBuffer(arr) {
|
|
5810
5499
|
const float32 = new Float32Array(arr);
|
|
5811
5500
|
return Buffer.from(float32.buffer);
|
|
@@ -5890,6 +5579,8 @@ function hasBlameMetadata(metadata) {
|
|
|
5890
5579
|
}
|
|
5891
5580
|
var INDEX_METADATA_VERSION = "1";
|
|
5892
5581
|
var EMBEDDING_STRATEGY_VERSION = "2";
|
|
5582
|
+
var SWIFT_PARSER_VERSION = "1";
|
|
5583
|
+
var METAL_PARSER_VERSION = "1";
|
|
5893
5584
|
var RANKING_TOKEN_CACHE_LIMIT = 4096;
|
|
5894
5585
|
var RANK_HYBRID_CACHE_LIMIT = 256;
|
|
5895
5586
|
function createPendingChunkStorageText(texts) {
|
|
@@ -6212,15 +5903,25 @@ function chunkTypeBoost(chunkType) {
|
|
|
6212
5903
|
case "function_declaration":
|
|
6213
5904
|
case "method":
|
|
6214
5905
|
case "method_definition":
|
|
5906
|
+
case "method_declaration":
|
|
5907
|
+
case "protocol_function_declaration":
|
|
5908
|
+
case "init_declaration":
|
|
5909
|
+
case "deinit_declaration":
|
|
5910
|
+
case "subscript_declaration":
|
|
6215
5911
|
case "class":
|
|
6216
5912
|
case "class_declaration":
|
|
5913
|
+
case "actor_declaration":
|
|
5914
|
+
case "extension_declaration":
|
|
6217
5915
|
return 0.2;
|
|
6218
5916
|
case "interface":
|
|
6219
5917
|
case "type":
|
|
6220
5918
|
case "enum":
|
|
5919
|
+
case "enum_declaration":
|
|
6221
5920
|
case "struct":
|
|
5921
|
+
case "struct_declaration":
|
|
6222
5922
|
case "impl":
|
|
6223
5923
|
case "trait":
|
|
5924
|
+
case "protocol_declaration":
|
|
6224
5925
|
case "module":
|
|
6225
5926
|
return 0.1;
|
|
6226
5927
|
default:
|
|
@@ -6327,11 +6028,21 @@ function isImplementationChunkType(chunkType) {
|
|
|
6327
6028
|
"function_declaration",
|
|
6328
6029
|
"method",
|
|
6329
6030
|
"method_definition",
|
|
6031
|
+
"method_declaration",
|
|
6032
|
+
"protocol_function_declaration",
|
|
6033
|
+
"init_declaration",
|
|
6034
|
+
"deinit_declaration",
|
|
6035
|
+
"subscript_declaration",
|
|
6330
6036
|
"class",
|
|
6331
6037
|
"class_declaration",
|
|
6038
|
+
"actor_declaration",
|
|
6039
|
+
"extension_declaration",
|
|
6332
6040
|
"interface",
|
|
6041
|
+
"protocol_declaration",
|
|
6333
6042
|
"type",
|
|
6334
6043
|
"enum",
|
|
6044
|
+
"enum_declaration",
|
|
6045
|
+
"struct_declaration",
|
|
6335
6046
|
"module"
|
|
6336
6047
|
].includes(chunkType);
|
|
6337
6048
|
}
|
|
@@ -7334,6 +7045,29 @@ var Indexer = class {
|
|
|
7334
7045
|
const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
|
|
7335
7046
|
return `index.forceReembed.${projectHash}`;
|
|
7336
7047
|
}
|
|
7048
|
+
getCallGraphResolutionMetadataKey() {
|
|
7049
|
+
if (this.config.scope !== "global") {
|
|
7050
|
+
return "index.callGraphResolutionVersion";
|
|
7051
|
+
}
|
|
7052
|
+
const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
|
|
7053
|
+
return `index.callGraphResolutionVersion.${projectHash}`;
|
|
7054
|
+
}
|
|
7055
|
+
getSwiftParserVersionMetadataKey() {
|
|
7056
|
+
const key = "index.parser.swiftVersion";
|
|
7057
|
+
if (this.config.scope !== "global") {
|
|
7058
|
+
return key;
|
|
7059
|
+
}
|
|
7060
|
+
const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
|
|
7061
|
+
return `${key}.${projectHash}`;
|
|
7062
|
+
}
|
|
7063
|
+
getMetalParserVersionMetadataKey() {
|
|
7064
|
+
const key = "index.parser.metalVersion";
|
|
7065
|
+
if (this.config.scope !== "global") {
|
|
7066
|
+
return key;
|
|
7067
|
+
}
|
|
7068
|
+
const projectHash = hashContent(path13.resolve(this.projectRoot)).slice(0, 16);
|
|
7069
|
+
return `${key}.${projectHash}`;
|
|
7070
|
+
}
|
|
7337
7071
|
hasProjectForceReembedPending() {
|
|
7338
7072
|
return this.config.scope === "global" && this.database?.getMetadata(this.getProjectForceReembedMetadataKey()) === "true";
|
|
7339
7073
|
}
|
|
@@ -8494,6 +8228,7 @@ var Indexer = class {
|
|
|
8494
8228
|
this.database.setMetadata("index.embeddingProvider", provider.provider);
|
|
8495
8229
|
this.database.setMetadata("index.embeddingModel", provider.modelInfo.model);
|
|
8496
8230
|
this.database.setMetadata("index.embeddingDimensions", provider.modelInfo.dimensions.toString());
|
|
8231
|
+
this.database.setMetadata(this.getCallGraphResolutionMetadataKey(), CALL_GRAPH_RESOLUTION_VERSION);
|
|
8497
8232
|
if (this.config.scope === "global") {
|
|
8498
8233
|
if (completeProjectEmbeddingStrategyReset) {
|
|
8499
8234
|
this.database.setMetadata(this.getProjectEmbeddingStrategyMetadataKey(), EMBEDDING_STRATEGY_VERSION);
|
|
@@ -8681,6 +8416,20 @@ var Indexer = class {
|
|
|
8681
8416
|
totalChunks: 0
|
|
8682
8417
|
});
|
|
8683
8418
|
this.loadFileHashCache();
|
|
8419
|
+
const swiftParserMetadataKey = this.getSwiftParserVersionMetadataKey();
|
|
8420
|
+
const reparseCachedSwiftFiles = database.getMetadata(swiftParserMetadataKey) !== SWIFT_PARSER_VERSION;
|
|
8421
|
+
const metalParserMetadataKey = this.getMetalParserVersionMetadataKey();
|
|
8422
|
+
const reparseCachedMetalFiles = database.getMetadata(metalParserMetadataKey) !== METAL_PARSER_VERSION;
|
|
8423
|
+
if (reparseCachedSwiftFiles && Array.from(this.fileHashCache.keys()).some(
|
|
8424
|
+
(filePath) => path13.extname(filePath).toLowerCase() === ".swift"
|
|
8425
|
+
)) {
|
|
8426
|
+
this.logger.info("Reindexing cached Swift files for parser support");
|
|
8427
|
+
}
|
|
8428
|
+
if (reparseCachedMetalFiles && Array.from(this.fileHashCache.keys()).some(
|
|
8429
|
+
(filePath) => path13.extname(filePath).toLowerCase() === ".metal"
|
|
8430
|
+
)) {
|
|
8431
|
+
this.logger.info("Reindexing cached Metal files for parser support");
|
|
8432
|
+
}
|
|
8684
8433
|
const includePatterns = [...this.config.include, ...this.config.additionalInclude];
|
|
8685
8434
|
const { files, skipped } = await collectFiles(
|
|
8686
8435
|
this.projectRoot,
|
|
@@ -8700,10 +8449,17 @@ var Indexer = class {
|
|
|
8700
8449
|
const changedFiles = [];
|
|
8701
8450
|
const unchangedFilePaths = /* @__PURE__ */ new Set();
|
|
8702
8451
|
const currentFileHashes = /* @__PURE__ */ new Map();
|
|
8452
|
+
const needsCallGraphResolutionMigration = database.getMetadata(this.getCallGraphResolutionMetadataKey()) !== CALL_GRAPH_RESOLUTION_VERSION;
|
|
8703
8453
|
for (const f of files) {
|
|
8704
8454
|
const currentHash = hashFile(f.path);
|
|
8705
8455
|
currentFileHashes.set(f.path, currentHash);
|
|
8706
|
-
|
|
8456
|
+
const cachedHashMatches = this.fileHashCache.get(f.path) === currentHash;
|
|
8457
|
+
const needsCallGraphRefresh = cachedHashMatches && needsCallGraphResolutionMigration && database.getChunksByFile(f.path).some(
|
|
8458
|
+
(chunk) => chunk.language === "php" || chunk.language === "c" || chunk.language === "cpp"
|
|
8459
|
+
);
|
|
8460
|
+
const requiresSwiftParserUpgrade = reparseCachedSwiftFiles && path13.extname(f.path).toLowerCase() === ".swift";
|
|
8461
|
+
const requiresMetalParserUpgrade = reparseCachedMetalFiles && path13.extname(f.path).toLowerCase() === ".metal";
|
|
8462
|
+
if (cachedHashMatches && !needsCallGraphRefresh && !requiresSwiftParserUpgrade && !requiresMetalParserUpgrade) {
|
|
8707
8463
|
unchangedFilePaths.add(f.path);
|
|
8708
8464
|
this.logger.recordCacheHit();
|
|
8709
8465
|
} else {
|
|
@@ -8905,16 +8661,28 @@ var Indexer = class {
|
|
|
8905
8661
|
const fileSymbols = [];
|
|
8906
8662
|
for (const chunk of parsed.chunks) {
|
|
8907
8663
|
if (!chunk.name || !CALL_GRAPH_SYMBOL_CHUNK_TYPES.has(chunk.chunkType)) continue;
|
|
8908
|
-
const
|
|
8664
|
+
const existingMetalSymbol = chunk.language === "metal" ? fileSymbols.find(
|
|
8665
|
+
(symbol2) => symbol2.name === chunk.name && symbol2.kind === chunk.chunkType && symbol2.startLine <= chunk.endLine && chunk.startLine <= symbol2.endLine
|
|
8666
|
+
) : void 0;
|
|
8667
|
+
if (existingMetalSymbol) {
|
|
8668
|
+
existingMetalSymbol.startLine = Math.min(existingMetalSymbol.startLine, chunk.startLine);
|
|
8669
|
+
existingMetalSymbol.endLine = Math.max(existingMetalSymbol.endLine, chunk.endLine);
|
|
8670
|
+
existingMetalSymbol.startCol = Math.min(existingMetalSymbol.startCol, chunk.startCol ?? 0);
|
|
8671
|
+
existingMetalSymbol.endCol = Math.max(existingMetalSymbol.endCol, chunk.endCol ?? 0);
|
|
8672
|
+
continue;
|
|
8673
|
+
}
|
|
8674
|
+
const symbolId = `sym_${hashContent(
|
|
8675
|
+
parsed.path + ":" + chunk.name + ":" + chunk.chunkType + ":" + chunk.startLine + ":" + (chunk.startCol ?? 0)
|
|
8676
|
+
).slice(0, 16)}`;
|
|
8909
8677
|
const symbol = {
|
|
8910
8678
|
id: symbolId,
|
|
8911
8679
|
filePath: parsed.path,
|
|
8912
8680
|
name: chunk.name,
|
|
8913
8681
|
kind: chunk.chunkType,
|
|
8914
8682
|
startLine: chunk.startLine,
|
|
8915
|
-
startCol: 0,
|
|
8683
|
+
startCol: chunk.startCol ?? 0,
|
|
8916
8684
|
endLine: chunk.endLine,
|
|
8917
|
-
endCol: 0,
|
|
8685
|
+
endCol: chunk.endCol ?? 0,
|
|
8918
8686
|
language: chunk.language
|
|
8919
8687
|
};
|
|
8920
8688
|
fileSymbols.push(symbol);
|
|
@@ -8939,8 +8707,10 @@ var Indexer = class {
|
|
|
8939
8707
|
if (callSites.length === 0) continue;
|
|
8940
8708
|
const edges = [];
|
|
8941
8709
|
for (const site of callSites) {
|
|
8942
|
-
const enclosingSymbol =
|
|
8943
|
-
|
|
8710
|
+
const enclosingSymbol = findEnclosingSymbol(
|
|
8711
|
+
fileSymbols,
|
|
8712
|
+
site.line,
|
|
8713
|
+
site.column
|
|
8944
8714
|
);
|
|
8945
8715
|
if (!enclosingSymbol) continue;
|
|
8946
8716
|
const edgeId = `edge_${hashContent(enclosingSymbol.id + ":" + site.calleeName + ":" + site.line + ":" + site.column).slice(0, 16)}`;
|
|
@@ -8959,7 +8729,21 @@ var Indexer = class {
|
|
|
8959
8729
|
if (edges.length > 0) {
|
|
8960
8730
|
database.upsertCallEdgesBatch(edges);
|
|
8961
8731
|
for (const edge of edges) {
|
|
8962
|
-
|
|
8732
|
+
let candidates = symbolsByName.get(normalizeSymbolKey(edge.targetName));
|
|
8733
|
+
if (fileLanguage === "php" && candidates) {
|
|
8734
|
+
if (edge.callType === "Constructor") {
|
|
8735
|
+
candidates = candidates.filter(
|
|
8736
|
+
(candidate) => PHP_CLASS_SYMBOL_CHUNK_TYPES.has(candidate.kind)
|
|
8737
|
+
);
|
|
8738
|
+
} else if (edge.callType === "Call") {
|
|
8739
|
+
candidates = candidates.filter(
|
|
8740
|
+
(candidate) => PHP_FUNCTION_SYMBOL_CHUNK_TYPES.has(candidate.kind)
|
|
8741
|
+
);
|
|
8742
|
+
}
|
|
8743
|
+
}
|
|
8744
|
+
candidates = candidates?.filter(
|
|
8745
|
+
(symbol) => isCompatibleCFamilyCallTarget(fileLanguage, edge.callType, symbol.kind)
|
|
8746
|
+
);
|
|
8963
8747
|
if (candidates && candidates.length === 1) {
|
|
8964
8748
|
database.resolveCallEdge(edge.id, candidates[0].id);
|
|
8965
8749
|
}
|
|
@@ -9014,6 +8798,8 @@ var Indexer = class {
|
|
|
9014
8798
|
this.saveFileHashCache();
|
|
9015
8799
|
this.saveFailedBatches([]);
|
|
9016
8800
|
}
|
|
8801
|
+
database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
|
|
8802
|
+
database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
|
|
9017
8803
|
this.saveIndexMetadata(configuredProviderInfo);
|
|
9018
8804
|
this.indexCompatibility = { compatible: true };
|
|
9019
8805
|
stats.durationMs = Date.now() - startTime;
|
|
@@ -9041,6 +8827,8 @@ var Indexer = class {
|
|
|
9041
8827
|
this.saveFileHashCache();
|
|
9042
8828
|
this.saveFailedBatches([]);
|
|
9043
8829
|
}
|
|
8830
|
+
database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
|
|
8831
|
+
database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
|
|
9044
8832
|
this.saveIndexMetadata(configuredProviderInfo);
|
|
9045
8833
|
this.indexCompatibility = { compatible: true };
|
|
9046
8834
|
stats.durationMs = Date.now() - startTime;
|
|
@@ -9311,6 +9099,8 @@ var Indexer = class {
|
|
|
9311
9099
|
if (forceScopedReembed && failedForcedChunkIds.size === 0) {
|
|
9312
9100
|
database.deleteMetadata(this.getProjectForceReembedMetadataKey());
|
|
9313
9101
|
}
|
|
9102
|
+
database.setMetadata(swiftParserMetadataKey, SWIFT_PARSER_VERSION);
|
|
9103
|
+
database.setMetadata(metalParserMetadataKey, METAL_PARSER_VERSION);
|
|
9314
9104
|
this.saveIndexMetadata(configuredProviderInfo);
|
|
9315
9105
|
this.indexCompatibility = { compatible: true };
|
|
9316
9106
|
this.logger.recordIndexingEnd();
|
|
@@ -10459,7 +10249,7 @@ function findKnowledgeBasePathIndex(knowledgeBases, inputPath, projectRoot) {
|
|
|
10459
10249
|
}
|
|
10460
10250
|
|
|
10461
10251
|
// src/tools/utils.ts
|
|
10462
|
-
var import_tiktoken =
|
|
10252
|
+
var import_tiktoken = require("tiktoken");
|
|
10463
10253
|
var MIN_CONTEXT_PACK_TOKEN_BUDGET = 128;
|
|
10464
10254
|
var MAX_CONTEXT_PACK_TOKEN_BUDGET = 4e3;
|
|
10465
10255
|
var DEFAULT_CONTEXT_PACK_TOKEN_BUDGET = 1200;
|
|
@@ -10971,15 +10761,6 @@ function refreshIndexerForDirectory(projectRoot, host = "opencode", config = par
|
|
|
10971
10761
|
indexerCache.set(key, indexer);
|
|
10972
10762
|
configCache.set(key, config);
|
|
10973
10763
|
}
|
|
10974
|
-
function shouldForceLocalizeProjectIndex(projectRoot, host = "opencode") {
|
|
10975
|
-
const root = getProjectRoot(projectRoot, host);
|
|
10976
|
-
const localIndexPath = path16.join(root, getHostProjectIndexRelativePath(host));
|
|
10977
|
-
if ((0, import_fs10.existsSync)(localIndexPath)) {
|
|
10978
|
-
return false;
|
|
10979
|
-
}
|
|
10980
|
-
const inheritedIndexPath = resolveWorktreeFallbackProjectIndexPath(root, host);
|
|
10981
|
-
return inheritedIndexPath !== null;
|
|
10982
|
-
}
|
|
10983
10764
|
async function searchCodebase(projectRoot, host, query, options = {}) {
|
|
10984
10765
|
const indexer = getIndexerForProject(projectRoot, host);
|
|
10985
10766
|
return indexer.search(query, options.limit, {
|
|
@@ -11029,9 +10810,7 @@ async function getCallGraphPath(projectRoot, host, from, to, maxDepth) {
|
|
|
11029
10810
|
}
|
|
11030
10811
|
async function runIndexCodebase(projectRoot, host, args, onProgress) {
|
|
11031
10812
|
const root = getProjectRoot(projectRoot, host);
|
|
11032
|
-
const
|
|
11033
|
-
let indexer = getIndexerForProject(root, host);
|
|
11034
|
-
const runtimeConfig = configCache.get(key);
|
|
10813
|
+
const indexer = getIndexerForProject(root, host);
|
|
11035
10814
|
try {
|
|
11036
10815
|
if (args.estimateOnly) {
|
|
11037
10816
|
return { kind: "estimate", estimate: await indexer.estimateCost() };
|
|
@@ -11052,19 +10831,7 @@ async function runIndexCodebase(projectRoot, host, args, onProgress) {
|
|
|
11052
10831
|
return Promise.resolve();
|
|
11053
10832
|
});
|
|
11054
10833
|
};
|
|
11055
|
-
|
|
11056
|
-
if (args.force && shouldForceLocalizeProjectIndex(root, host)) {
|
|
11057
|
-
const inheritedIndexPath = resolveProjectIndexPath(root, runtimeConfig.scope, host);
|
|
11058
|
-
stats = await withIndexLock(inheritedIndexPath, "force-index", async () => {
|
|
11059
|
-
materializeLocalProjectConfig(root, loadProjectConfigLayer(root, host), host);
|
|
11060
|
-
refreshIndexerForDirectory(root, host, runtimeConfig);
|
|
11061
|
-
indexer = getIndexerForProject(root, host);
|
|
11062
|
-
return runIndex(indexer);
|
|
11063
|
-
}, { completeRecoveries: false });
|
|
11064
|
-
} else {
|
|
11065
|
-
stats = await runIndex(indexer);
|
|
11066
|
-
}
|
|
11067
|
-
return { kind: "stats", stats };
|
|
10834
|
+
return { kind: "stats", stats: await runIndex(indexer) };
|
|
11068
10835
|
} catch (error) {
|
|
11069
10836
|
const busyResult = getIndexBusyResult(error);
|
|
11070
10837
|
if (!busyResult) throw error;
|