opencode-codebase-index 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +5 -3
- package/dist/cli.cjs +2867 -1792
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2874 -1793
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +915 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +922 -11
- package/dist/index.js.map +1 -1
- package/dist/pi-extension.cjs +920 -69
- package/dist/pi-extension.cjs.map +1 -1
- package/dist/pi-extension.js +927 -70
- 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.win32-x64-msvc.node +0 -0
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -655,6 +655,467 @@ 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
|
+
|
|
658
1119
|
// src/index.ts
|
|
659
1120
|
var index_exports = {};
|
|
660
1121
|
__export(index_exports, {
|
|
@@ -1708,7 +2169,12 @@ function sameReclaimOwner(left, right) {
|
|
|
1708
2169
|
}
|
|
1709
2170
|
function publishJsonDirectory(finalPath, value) {
|
|
1710
2171
|
const candidatePath = `${finalPath}.candidate.${process.pid}.${(0, import_crypto.randomUUID)()}`;
|
|
1711
|
-
|
|
2172
|
+
try {
|
|
2173
|
+
(0, import_fs5.mkdirSync)(candidatePath, { mode: 448 });
|
|
2174
|
+
} catch (error) {
|
|
2175
|
+
if (getErrorCode(error) === "ENOENT") return false;
|
|
2176
|
+
throw error;
|
|
2177
|
+
}
|
|
1712
2178
|
try {
|
|
1713
2179
|
(0, import_fs5.writeFileSync)(path7.join(candidatePath, OWNER_FILE_NAME), JSON.stringify(value), {
|
|
1714
2180
|
encoding: "utf-8",
|
|
@@ -1721,8 +2187,12 @@ function publishJsonDirectory(finalPath, value) {
|
|
|
1721
2187
|
return true;
|
|
1722
2188
|
} catch (error) {
|
|
1723
2189
|
if ((0, import_fs5.existsSync)(finalPath)) return false;
|
|
2190
|
+
if (getErrorCode(error) === "ENOENT") return false;
|
|
1724
2191
|
throw error;
|
|
1725
2192
|
}
|
|
2193
|
+
} catch (error) {
|
|
2194
|
+
if (getErrorCode(error) === "ENOENT") return false;
|
|
2195
|
+
throw error;
|
|
1726
2196
|
} finally {
|
|
1727
2197
|
if ((0, import_fs5.existsSync)(candidatePath)) (0, import_fs5.rmSync)(candidatePath, { recursive: true, force: true });
|
|
1728
2198
|
}
|
|
@@ -6579,6 +7049,27 @@ function mergeTieredResults(symbolLane, hybridLane, limit) {
|
|
|
6579
7049
|
}
|
|
6580
7050
|
return out;
|
|
6581
7051
|
}
|
|
7052
|
+
function selectChunksWithFileCoverage(chunks, limit) {
|
|
7053
|
+
if (limit <= 0 || chunks.length === 0) {
|
|
7054
|
+
return [];
|
|
7055
|
+
}
|
|
7056
|
+
if (chunks.length <= limit) {
|
|
7057
|
+
return chunks;
|
|
7058
|
+
}
|
|
7059
|
+
if (limit === 1) {
|
|
7060
|
+
return [chunks[Math.floor((chunks.length - 1) / 2)]];
|
|
7061
|
+
}
|
|
7062
|
+
const selected = [];
|
|
7063
|
+
for (let index = 0; index < limit; index++) {
|
|
7064
|
+
const sourceIndex = Math.round(index * (chunks.length - 1) / (limit - 1));
|
|
7065
|
+
selected.push(chunks[sourceIndex]);
|
|
7066
|
+
}
|
|
7067
|
+
return selected;
|
|
7068
|
+
}
|
|
7069
|
+
function selectIndexableChunks(chunks, limit, semanticOnly) {
|
|
7070
|
+
const indexableChunks = semanticOnly ? chunks.filter((chunk) => chunk.chunkType !== "other") : chunks;
|
|
7071
|
+
return selectChunksWithFileCoverage(indexableChunks, limit);
|
|
7072
|
+
}
|
|
6582
7073
|
function matchesSearchFilters(candidate, options, minScore) {
|
|
6583
7074
|
if (candidate.score < minScore) return false;
|
|
6584
7075
|
if (options?.fileType) {
|
|
@@ -8317,7 +8808,6 @@ var Indexer = class {
|
|
|
8317
8808
|
const relativePath = path13.relative(this.projectRoot, parsed.path);
|
|
8318
8809
|
stats.parseFailures.push(relativePath);
|
|
8319
8810
|
}
|
|
8320
|
-
let fileChunkCount = 0;
|
|
8321
8811
|
let chunksToProcess = parsed.chunks;
|
|
8322
8812
|
if (this.config.indexing.fallbackToTextOnMaxChunks && chunksToProcess.length > this.config.indexing.maxChunksPerFile) {
|
|
8323
8813
|
const changedFile = changedFiles.find((f) => f.path === parsed.path);
|
|
@@ -8326,13 +8816,12 @@ var Indexer = class {
|
|
|
8326
8816
|
chunksToProcess = textChunks;
|
|
8327
8817
|
}
|
|
8328
8818
|
}
|
|
8819
|
+
chunksToProcess = selectIndexableChunks(
|
|
8820
|
+
chunksToProcess,
|
|
8821
|
+
this.config.indexing.maxChunksPerFile,
|
|
8822
|
+
this.config.indexing.semanticOnly
|
|
8823
|
+
);
|
|
8329
8824
|
for (const chunk of chunksToProcess) {
|
|
8330
|
-
if (fileChunkCount >= this.config.indexing.maxChunksPerFile) {
|
|
8331
|
-
break;
|
|
8332
|
-
}
|
|
8333
|
-
if (this.config.indexing.semanticOnly && chunk.chunkType === "other") {
|
|
8334
|
-
continue;
|
|
8335
|
-
}
|
|
8336
8825
|
const id = generateChunkId(parsed.path, chunk);
|
|
8337
8826
|
const contentHash = generateChunkHash(chunk);
|
|
8338
8827
|
const existingContentHash = existingChunks.get(id);
|
|
@@ -8356,7 +8845,6 @@ var Indexer = class {
|
|
|
8356
8845
|
blameSummary: blameMetadata.blameSummary
|
|
8357
8846
|
});
|
|
8358
8847
|
if (existingContentHash === contentHash) {
|
|
8359
|
-
fileChunkCount++;
|
|
8360
8848
|
continue;
|
|
8361
8849
|
}
|
|
8362
8850
|
const texts = createEmbeddingTexts(chunk, parsed.path, getSafeEmbeddingChunkTokenLimit(configuredProviderInfo)).map((text) => ({
|
|
@@ -8381,7 +8869,6 @@ var Indexer = class {
|
|
|
8381
8869
|
contentHash,
|
|
8382
8870
|
metadata
|
|
8383
8871
|
});
|
|
8384
|
-
fileChunkCount++;
|
|
8385
8872
|
}
|
|
8386
8873
|
}
|
|
8387
8874
|
const retryableFailedChunks = this.collectRetryableFailedChunks(
|
|
@@ -9972,6 +10459,159 @@ function findKnowledgeBasePathIndex(knowledgeBases, inputPath, projectRoot) {
|
|
|
9972
10459
|
}
|
|
9973
10460
|
|
|
9974
10461
|
// src/tools/utils.ts
|
|
10462
|
+
var import_tiktoken = __toESM(require_tiktoken(), 1);
|
|
10463
|
+
var MIN_CONTEXT_PACK_TOKEN_BUDGET = 128;
|
|
10464
|
+
var MAX_CONTEXT_PACK_TOKEN_BUDGET = 4e3;
|
|
10465
|
+
var DEFAULT_CONTEXT_PACK_TOKEN_BUDGET = 1200;
|
|
10466
|
+
var CONTEXT_TOKENIZER = (0, import_tiktoken.get_encoding)("cl100k_base");
|
|
10467
|
+
function clampContextPackTokenBudget(tokenBudget) {
|
|
10468
|
+
if (tokenBudget === void 0 || !Number.isFinite(tokenBudget)) {
|
|
10469
|
+
return DEFAULT_CONTEXT_PACK_TOKEN_BUDGET;
|
|
10470
|
+
}
|
|
10471
|
+
return Math.min(
|
|
10472
|
+
MAX_CONTEXT_PACK_TOKEN_BUDGET,
|
|
10473
|
+
Math.max(MIN_CONTEXT_PACK_TOKEN_BUDGET, Math.floor(tokenBudget))
|
|
10474
|
+
);
|
|
10475
|
+
}
|
|
10476
|
+
function countContextTokens(text) {
|
|
10477
|
+
return CONTEXT_TOKENIZER.encode(text).length;
|
|
10478
|
+
}
|
|
10479
|
+
function fitTextToContextBudget(text, tokenBudget) {
|
|
10480
|
+
const normalizedBudget = clampContextPackTokenBudget(tokenBudget);
|
|
10481
|
+
const tokenEstimate = countContextTokens(text);
|
|
10482
|
+
if (tokenEstimate <= normalizedBudget) {
|
|
10483
|
+
return {
|
|
10484
|
+
text,
|
|
10485
|
+
tokenBudget: normalizedBudget,
|
|
10486
|
+
tokenEstimate,
|
|
10487
|
+
truncated: false
|
|
10488
|
+
};
|
|
10489
|
+
}
|
|
10490
|
+
const suffix = "\n...[truncated to context token budget]";
|
|
10491
|
+
const codePoints = Array.from(text);
|
|
10492
|
+
let low = 0;
|
|
10493
|
+
let high = codePoints.length;
|
|
10494
|
+
while (low < high) {
|
|
10495
|
+
const middle = Math.ceil((low + high) / 2);
|
|
10496
|
+
const candidate = `${codePoints.slice(0, middle).join("").trimEnd()}${suffix}`;
|
|
10497
|
+
if (countContextTokens(candidate) <= normalizedBudget) low = middle;
|
|
10498
|
+
else high = middle - 1;
|
|
10499
|
+
}
|
|
10500
|
+
const fitted = `${codePoints.slice(0, low).join("").trimEnd()}${suffix}`;
|
|
10501
|
+
return {
|
|
10502
|
+
text: fitted,
|
|
10503
|
+
tokenBudget: normalizedBudget,
|
|
10504
|
+
tokenEstimate: countContextTokens(fitted),
|
|
10505
|
+
truncated: true
|
|
10506
|
+
};
|
|
10507
|
+
}
|
|
10508
|
+
function normalizedLineRange(result) {
|
|
10509
|
+
return result.startLine <= result.endLine ? { start: result.startLine, end: result.endLine } : { start: result.endLine, end: result.startLine };
|
|
10510
|
+
}
|
|
10511
|
+
function rankContextCandidates(results) {
|
|
10512
|
+
return results.map((result, originalIndex) => ({ result, originalIndex })).sort((left, right) => right.result.score - left.result.score || left.originalIndex - right.originalIndex);
|
|
10513
|
+
}
|
|
10514
|
+
function deduplicateContextCandidates(candidates) {
|
|
10515
|
+
const acceptedByFile = /* @__PURE__ */ new Map();
|
|
10516
|
+
const deduplicated = [];
|
|
10517
|
+
for (const { result } of candidates) {
|
|
10518
|
+
const range = normalizedLineRange(result);
|
|
10519
|
+
const accepted = acceptedByFile.get(result.filePath) ?? [];
|
|
10520
|
+
if (accepted.some((item) => item.start <= range.end && range.start <= item.end)) {
|
|
10521
|
+
continue;
|
|
10522
|
+
}
|
|
10523
|
+
accepted.push(range);
|
|
10524
|
+
acceptedByFile.set(result.filePath, accepted);
|
|
10525
|
+
deduplicated.push(result);
|
|
10526
|
+
}
|
|
10527
|
+
return deduplicated;
|
|
10528
|
+
}
|
|
10529
|
+
function diversifyContextCandidates(results) {
|
|
10530
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
10531
|
+
for (const result of results) {
|
|
10532
|
+
const bucket = byFile.get(result.filePath) ?? [];
|
|
10533
|
+
bucket.push(result);
|
|
10534
|
+
byFile.set(result.filePath, bucket);
|
|
10535
|
+
}
|
|
10536
|
+
const files = [...byFile.keys()];
|
|
10537
|
+
const diversified = [];
|
|
10538
|
+
for (let depth = 0; diversified.length < results.length; depth += 1) {
|
|
10539
|
+
for (const file of files) {
|
|
10540
|
+
const result = byFile.get(file)?.[depth];
|
|
10541
|
+
if (result) diversified.push(result);
|
|
10542
|
+
}
|
|
10543
|
+
}
|
|
10544
|
+
return diversified;
|
|
10545
|
+
}
|
|
10546
|
+
function compactEvidenceValue(value, maxChars) {
|
|
10547
|
+
const characters = [...value];
|
|
10548
|
+
if (characters.length <= maxChars) return value;
|
|
10549
|
+
return `\u2026${characters.slice(-(maxChars - 1)).join("")}`;
|
|
10550
|
+
}
|
|
10551
|
+
function formatContextEvidence(result, index) {
|
|
10552
|
+
const symbol = result.name ? ` ${JSON.stringify(compactEvidenceValue(result.name, 80))}` : "";
|
|
10553
|
+
const path24 = compactEvidenceValue(result.filePath, 120);
|
|
10554
|
+
return `[${index}] ${result.chunkType}${symbol} in ${path24}:${result.startLine}-${result.endLine} (score ${result.score.toFixed(2)})`;
|
|
10555
|
+
}
|
|
10556
|
+
function formatContextPack(heading, selected, candidateCount, duplicateCount, limitOmittedCount, budgetOmittedCount) {
|
|
10557
|
+
const lines = selected.map((result, index) => formatContextEvidence(result, index + 1));
|
|
10558
|
+
const notes = [];
|
|
10559
|
+
if (duplicateCount > 0) notes.push(`${duplicateCount} overlapping duplicate${duplicateCount === 1 ? "" : "s"} removed`);
|
|
10560
|
+
if (limitOmittedCount > 0) notes.push(`${limitOmittedCount} additional result${limitOmittedCount === 1 ? "" : "s"} excluded by result limit`);
|
|
10561
|
+
if (budgetOmittedCount > 0) notes.push(`${budgetOmittedCount} additional result${budgetOmittedCount === 1 ? "" : "s"} omitted by token budget`);
|
|
10562
|
+
const footer = notes.length > 0 ? `Selected ${selected.length} of ${candidateCount} candidates; ${notes.join("; ")}.` : `Selected ${selected.length} of ${candidateCount} candidates.`;
|
|
10563
|
+
return `${heading}
|
|
10564
|
+
|
|
10565
|
+
${lines.join("\n")}
|
|
10566
|
+
|
|
10567
|
+
${footer}`;
|
|
10568
|
+
}
|
|
10569
|
+
function buildContextPack(results, options = {}) {
|
|
10570
|
+
const requestedTokenBudget = options.tokenBudget ?? DEFAULT_CONTEXT_PACK_TOKEN_BUDGET;
|
|
10571
|
+
const tokenBudget = clampContextPackTokenBudget(options.tokenBudget);
|
|
10572
|
+
const heading = compactEvidenceValue(options.heading?.trim() || "Codebase evidence", 160);
|
|
10573
|
+
const maxResults = Math.max(0, Math.floor(options.maxResults ?? results.length));
|
|
10574
|
+
const candidateCount = results.length;
|
|
10575
|
+
const deduplicated = deduplicateContextCandidates(rankContextCandidates(results));
|
|
10576
|
+
const diversified = diversifyContextCandidates(deduplicated);
|
|
10577
|
+
const duplicateCount = candidateCount - deduplicated.length;
|
|
10578
|
+
const selectable = diversified.slice(0, maxResults);
|
|
10579
|
+
const limitOmittedCount = deduplicated.length - selectable.length;
|
|
10580
|
+
let selected = [];
|
|
10581
|
+
let text = formatContextPack(heading, selected, candidateCount, duplicateCount, limitOmittedCount, selectable.length);
|
|
10582
|
+
for (let count = 1; count <= selectable.length; count += 1) {
|
|
10583
|
+
const candidateSelection = selectable.slice(0, count);
|
|
10584
|
+
const budgetOmittedCount2 = selectable.length - candidateSelection.length;
|
|
10585
|
+
const candidateText = formatContextPack(
|
|
10586
|
+
heading,
|
|
10587
|
+
candidateSelection,
|
|
10588
|
+
candidateCount,
|
|
10589
|
+
duplicateCount,
|
|
10590
|
+
limitOmittedCount,
|
|
10591
|
+
budgetOmittedCount2
|
|
10592
|
+
);
|
|
10593
|
+
if (countContextTokens(candidateText) > tokenBudget) break;
|
|
10594
|
+
selected = candidateSelection;
|
|
10595
|
+
text = candidateText;
|
|
10596
|
+
}
|
|
10597
|
+
const fitted = fitTextToContextBudget(text, tokenBudget);
|
|
10598
|
+
const budgetOmittedCount = selectable.length - selected.length;
|
|
10599
|
+
const omittedCount = candidateCount - selected.length;
|
|
10600
|
+
return {
|
|
10601
|
+
requestedTokenBudget,
|
|
10602
|
+
tokenBudget,
|
|
10603
|
+
text: fitted.text,
|
|
10604
|
+
tokenEstimate: fitted.tokenEstimate,
|
|
10605
|
+
results: selected,
|
|
10606
|
+
candidateCount,
|
|
10607
|
+
deduplicatedCount: deduplicated.length,
|
|
10608
|
+
selectedCount: selected.length,
|
|
10609
|
+
omittedCount,
|
|
10610
|
+
duplicateCount,
|
|
10611
|
+
limitOmittedCount,
|
|
10612
|
+
budgetOmittedCount
|
|
10613
|
+
};
|
|
10614
|
+
}
|
|
9975
10615
|
var MAX_CONTENT_LINES = 30;
|
|
9976
10616
|
function truncateContent(content) {
|
|
9977
10617
|
const lines = content.split("\n");
|
|
@@ -12801,6 +13441,253 @@ var pr_impact = (0, import_plugin.tool)({
|
|
|
12801
13441
|
}
|
|
12802
13442
|
});
|
|
12803
13443
|
|
|
13444
|
+
// src/tools/symbol-inference.ts
|
|
13445
|
+
var IDENTIFIER_RE = /[A-Za-z_$][A-Za-z0-9_$]*/g;
|
|
13446
|
+
var QUOTED_BACKTICK_RE = /`([^`]+)`/g;
|
|
13447
|
+
var QUOTED_SINGLE_RE = /'([^'\\]+)'/g;
|
|
13448
|
+
var QUOTED_DOUBLE_RE = /"([^"]+)"/g;
|
|
13449
|
+
var SYMBOL_LIKE_RE = /^(?:[A-Za-z_$][A-Za-z0-9_$]*)$/;
|
|
13450
|
+
var CAMEL_CASE_RE = /^[a-z_][A-Za-z0-9_$]*[A-Z][A-Za-z0-9_$]*$/;
|
|
13451
|
+
var PASCAL_CASE_RE = /^[A-Z][A-Za-z0-9_$]*$/;
|
|
13452
|
+
var SNAKE_CASE_RE = /^[a-z][a-z0-9_]*_[a-z0-9_]+$/;
|
|
13453
|
+
var DEFINITION_INTENT_RE = /\b(where|defined|definition|define|declaration|symbol|function|method|class|interface|type)\b/i;
|
|
13454
|
+
var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
13455
|
+
"a",
|
|
13456
|
+
"an",
|
|
13457
|
+
"and",
|
|
13458
|
+
"are",
|
|
13459
|
+
"at",
|
|
13460
|
+
"for",
|
|
13461
|
+
"find",
|
|
13462
|
+
"how",
|
|
13463
|
+
"i",
|
|
13464
|
+
"in",
|
|
13465
|
+
"is",
|
|
13466
|
+
"it",
|
|
13467
|
+
"of",
|
|
13468
|
+
"on",
|
|
13469
|
+
"that",
|
|
13470
|
+
"the",
|
|
13471
|
+
"definition",
|
|
13472
|
+
"show",
|
|
13473
|
+
"to",
|
|
13474
|
+
"where",
|
|
13475
|
+
"which",
|
|
13476
|
+
"what",
|
|
13477
|
+
"you",
|
|
13478
|
+
"your",
|
|
13479
|
+
"with"
|
|
13480
|
+
]);
|
|
13481
|
+
function stripCallSuffix(token) {
|
|
13482
|
+
return token.replace(/\(\s*\)$/, "");
|
|
13483
|
+
}
|
|
13484
|
+
function isLikelySymbolName(token) {
|
|
13485
|
+
if (!SYMBOL_LIKE_RE.test(token)) {
|
|
13486
|
+
return false;
|
|
13487
|
+
}
|
|
13488
|
+
if (STOP_WORDS.has(token.toLowerCase())) {
|
|
13489
|
+
return false;
|
|
13490
|
+
}
|
|
13491
|
+
return CAMEL_CASE_RE.test(token) || PASCAL_CASE_RE.test(token) || SNAKE_CASE_RE.test(token);
|
|
13492
|
+
}
|
|
13493
|
+
function extractQuotedIdentifiers(query) {
|
|
13494
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
13495
|
+
for (const match of query.matchAll(QUOTED_BACKTICK_RE)) {
|
|
13496
|
+
const candidate = stripCallSuffix(match[1].trim());
|
|
13497
|
+
if (candidate && isLikelySymbolName(candidate)) {
|
|
13498
|
+
identifiers.add(candidate);
|
|
13499
|
+
}
|
|
13500
|
+
}
|
|
13501
|
+
for (const match of query.matchAll(QUOTED_SINGLE_RE)) {
|
|
13502
|
+
const candidate = stripCallSuffix(match[1].trim());
|
|
13503
|
+
if (candidate && isLikelySymbolName(candidate)) {
|
|
13504
|
+
identifiers.add(candidate);
|
|
13505
|
+
}
|
|
13506
|
+
}
|
|
13507
|
+
for (const match of query.matchAll(QUOTED_DOUBLE_RE)) {
|
|
13508
|
+
const candidate = stripCallSuffix(match[1].trim());
|
|
13509
|
+
if (candidate && isLikelySymbolName(candidate)) {
|
|
13510
|
+
identifiers.add(candidate);
|
|
13511
|
+
}
|
|
13512
|
+
}
|
|
13513
|
+
return [...identifiers];
|
|
13514
|
+
}
|
|
13515
|
+
function extractBareIdentifiers(query) {
|
|
13516
|
+
const unquoted = query.replace(QUOTED_BACKTICK_RE, " ").replace(QUOTED_SINGLE_RE, " ").replace(QUOTED_DOUBLE_RE, " ");
|
|
13517
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
13518
|
+
for (const match of unquoted.matchAll(IDENTIFIER_RE)) {
|
|
13519
|
+
const candidate = stripCallSuffix(match[0]);
|
|
13520
|
+
if (isLikelySymbolName(candidate)) {
|
|
13521
|
+
identifiers.add(candidate);
|
|
13522
|
+
}
|
|
13523
|
+
}
|
|
13524
|
+
return [...identifiers];
|
|
13525
|
+
}
|
|
13526
|
+
function isSingleMeaningfulToken(query, symbol) {
|
|
13527
|
+
const tokens = query.replace(/[`'"()]/g, " ").split(/[^A-Za-z0-9_$]+/).map((token) => token.trim().toLowerCase()).filter((token) => token.length > 0).filter((token) => !STOP_WORDS.has(token));
|
|
13528
|
+
return tokens.length === 1 && tokens[0] === symbol.toLowerCase();
|
|
13529
|
+
}
|
|
13530
|
+
function inferExactSymbolFromQuery(query) {
|
|
13531
|
+
const quoted = extractQuotedIdentifiers(query);
|
|
13532
|
+
if (quoted.length === 1) {
|
|
13533
|
+
return quoted[0];
|
|
13534
|
+
}
|
|
13535
|
+
if (quoted.length > 1) {
|
|
13536
|
+
return void 0;
|
|
13537
|
+
}
|
|
13538
|
+
const candidates = extractBareIdentifiers(query);
|
|
13539
|
+
if (candidates.length !== 1) {
|
|
13540
|
+
return void 0;
|
|
13541
|
+
}
|
|
13542
|
+
const candidate = candidates[0];
|
|
13543
|
+
if (DEFINITION_INTENT_RE.test(query)) {
|
|
13544
|
+
return candidate;
|
|
13545
|
+
}
|
|
13546
|
+
if (isSingleMeaningfulToken(query, candidate)) {
|
|
13547
|
+
return candidate;
|
|
13548
|
+
}
|
|
13549
|
+
return void 0;
|
|
13550
|
+
}
|
|
13551
|
+
|
|
13552
|
+
// src/tools/context.ts
|
|
13553
|
+
var MIN_CONTEXT_RESULT_LIMIT = 1;
|
|
13554
|
+
var MAX_CONTEXT_RESULT_LIMIT = 100;
|
|
13555
|
+
var MIN_CONTEXT_PATH_DEPTH = 1;
|
|
13556
|
+
var MAX_CONTEXT_PATH_DEPTH = 100;
|
|
13557
|
+
function locations(results) {
|
|
13558
|
+
return results.map((result) => ({
|
|
13559
|
+
filePath: result.filePath,
|
|
13560
|
+
startLine: result.startLine,
|
|
13561
|
+
endLine: result.endLine,
|
|
13562
|
+
score: result.score,
|
|
13563
|
+
chunkType: result.chunkType,
|
|
13564
|
+
name: result.name
|
|
13565
|
+
}));
|
|
13566
|
+
}
|
|
13567
|
+
function packedResult(route, routedQuery, pack) {
|
|
13568
|
+
return {
|
|
13569
|
+
text: pack.text,
|
|
13570
|
+
details: {
|
|
13571
|
+
route,
|
|
13572
|
+
routedQuery,
|
|
13573
|
+
tokenBudget: pack.tokenBudget,
|
|
13574
|
+
tokenEstimate: pack.tokenEstimate,
|
|
13575
|
+
candidateCount: pack.candidateCount,
|
|
13576
|
+
deduplicatedCount: pack.deduplicatedCount,
|
|
13577
|
+
selectedCount: pack.selectedCount,
|
|
13578
|
+
omittedCount: pack.omittedCount,
|
|
13579
|
+
duplicateCount: pack.duplicateCount,
|
|
13580
|
+
limitOmittedCount: pack.limitOmittedCount,
|
|
13581
|
+
budgetOmittedCount: pack.budgetOmittedCount,
|
|
13582
|
+
results: locations(pack.results)
|
|
13583
|
+
}
|
|
13584
|
+
};
|
|
13585
|
+
}
|
|
13586
|
+
async function resolveSearchContext(input, operations) {
|
|
13587
|
+
const explicitSymbol = input.symbol ?? void 0;
|
|
13588
|
+
const limit = input.limit ?? 10;
|
|
13589
|
+
const tokenBudget = input.tokenBudget ?? void 0;
|
|
13590
|
+
const lookupSymbol = explicitSymbol ?? inferExactSymbolFromQuery(input.query);
|
|
13591
|
+
if (lookupSymbol) {
|
|
13592
|
+
const definitions = await operations.lookup(lookupSymbol, MAX_CONTEXT_RESULT_LIMIT);
|
|
13593
|
+
if (definitions.length > 0) {
|
|
13594
|
+
return packedResult("definition", lookupSymbol, buildContextPack(definitions, {
|
|
13595
|
+
tokenBudget,
|
|
13596
|
+
maxResults: limit,
|
|
13597
|
+
heading: `Definition evidence for ${JSON.stringify(lookupSymbol)}`
|
|
13598
|
+
}));
|
|
13599
|
+
}
|
|
13600
|
+
if (explicitSymbol) {
|
|
13601
|
+
const fitted = fitTextToContextBudget(
|
|
13602
|
+
formatDefinitionLookup(definitions, lookupSymbol),
|
|
13603
|
+
tokenBudget
|
|
13604
|
+
);
|
|
13605
|
+
return { text: fitted.text };
|
|
13606
|
+
}
|
|
13607
|
+
}
|
|
13608
|
+
const results = await operations.search(input.query, MAX_CONTEXT_RESULT_LIMIT);
|
|
13609
|
+
if (results.length === 0) {
|
|
13610
|
+
const fitted = fitTextToContextBudget(
|
|
13611
|
+
"No matching code found. Try a different query or run index_codebase first.",
|
|
13612
|
+
tokenBudget
|
|
13613
|
+
);
|
|
13614
|
+
return { text: fitted.text };
|
|
13615
|
+
}
|
|
13616
|
+
return packedResult("conceptual", input.query, buildContextPack(results, {
|
|
13617
|
+
tokenBudget,
|
|
13618
|
+
maxResults: limit,
|
|
13619
|
+
heading: `Codebase evidence for ${JSON.stringify(input.query)}`
|
|
13620
|
+
}));
|
|
13621
|
+
}
|
|
13622
|
+
function fittedDetails(route, fitted) {
|
|
13623
|
+
return {
|
|
13624
|
+
route,
|
|
13625
|
+
tokenBudget: fitted.tokenBudget,
|
|
13626
|
+
tokenEstimate: fitted.tokenEstimate,
|
|
13627
|
+
truncated: fitted.truncated
|
|
13628
|
+
};
|
|
13629
|
+
}
|
|
13630
|
+
async function resolveCodebaseContext(projectRoot, host, input) {
|
|
13631
|
+
const from = input.from ?? void 0;
|
|
13632
|
+
const to = input.to ?? void 0;
|
|
13633
|
+
const symbol = input.symbol ?? void 0;
|
|
13634
|
+
const limit = input.limit ?? 10;
|
|
13635
|
+
const maxDepth = input.maxDepth ?? 10;
|
|
13636
|
+
const fileType = input.fileType ?? void 0;
|
|
13637
|
+
const directory = input.directory ?? void 0;
|
|
13638
|
+
const tokenBudget = input.tokenBudget ?? void 0;
|
|
13639
|
+
if (from && to) {
|
|
13640
|
+
const path24 = await getCallGraphPath(projectRoot, host, from, to, maxDepth);
|
|
13641
|
+
if (path24.length > 0) {
|
|
13642
|
+
const fitted2 = fitTextToContextBudget(
|
|
13643
|
+
formatCallGraphPath(from, to, path24),
|
|
13644
|
+
tokenBudget
|
|
13645
|
+
);
|
|
13646
|
+
return {
|
|
13647
|
+
text: fitted2.text,
|
|
13648
|
+
details: fittedDetails("path", fitted2)
|
|
13649
|
+
};
|
|
13650
|
+
}
|
|
13651
|
+
const { callers } = await getCallGraphData(projectRoot, host, {
|
|
13652
|
+
name: to,
|
|
13653
|
+
direction: "callers"
|
|
13654
|
+
});
|
|
13655
|
+
const directEdge = callers.find((edge) => edge.fromSymbolName === from);
|
|
13656
|
+
if (directEdge) {
|
|
13657
|
+
const location = directEdge.fromSymbolFilePath ? ` at ${directEdge.fromSymbolFilePath}:${directEdge.line}` : "";
|
|
13658
|
+
const fitted2 = fitTextToContextBudget(
|
|
13659
|
+
`Direct path: ${from} --${directEdge.callType}--> ${to}${location} (edge is ${directEdge.isResolved ? "resolved" : "unresolved"}).`,
|
|
13660
|
+
tokenBudget
|
|
13661
|
+
);
|
|
13662
|
+
return {
|
|
13663
|
+
text: fitted2.text,
|
|
13664
|
+
details: fittedDetails("direct-edge", fitted2)
|
|
13665
|
+
};
|
|
13666
|
+
}
|
|
13667
|
+
const fitted = fitTextToContextBudget(
|
|
13668
|
+
formatCallGraphPath(from, to, path24),
|
|
13669
|
+
tokenBudget
|
|
13670
|
+
);
|
|
13671
|
+
return {
|
|
13672
|
+
text: fitted.text,
|
|
13673
|
+
details: fittedDetails("path", fitted)
|
|
13674
|
+
};
|
|
13675
|
+
}
|
|
13676
|
+
return resolveSearchContext({ query: input.query, symbol, limit, tokenBudget }, {
|
|
13677
|
+
lookup: (lookupSymbol, retrievalLimit) => implementationLookup(projectRoot, host, lookupSymbol, {
|
|
13678
|
+
limit: retrievalLimit,
|
|
13679
|
+
fileType,
|
|
13680
|
+
directory
|
|
13681
|
+
}),
|
|
13682
|
+
search: (query, retrievalLimit) => searchCodebase(projectRoot, host, query, {
|
|
13683
|
+
limit: retrievalLimit,
|
|
13684
|
+
fileType,
|
|
13685
|
+
directory,
|
|
13686
|
+
metadataOnly: true
|
|
13687
|
+
})
|
|
13688
|
+
});
|
|
13689
|
+
}
|
|
13690
|
+
|
|
12804
13691
|
// src/tools/index.ts
|
|
12805
13692
|
var import_fs11 = require("fs");
|
|
12806
13693
|
var os5 = __toESM(require("os"), 1);
|
|
@@ -13532,6 +14419,23 @@ function initializeTools2(projectRoot, config) {
|
|
|
13532
14419
|
function getIndexerForProject2(directory) {
|
|
13533
14420
|
return getIndexerForProject(directory, DEFAULT_HOST);
|
|
13534
14421
|
}
|
|
14422
|
+
var codebase_context = (0, import_plugin2.tool)({
|
|
14423
|
+
description: "PREFERRED FIRST TOOL for repository questions. Returns a deduplicated, file-diverse evidence pack within tokenBudget. Provide from and to for dependency paths, symbol for definitions, or only query for conceptual discovery.",
|
|
14424
|
+
args: {
|
|
14425
|
+
query: z2.string().describe("The repository question or behavior to locate"),
|
|
14426
|
+
from: z2.string().nullable().optional().describe("Source symbol for a dependency path"),
|
|
14427
|
+
to: z2.string().nullable().optional().describe("Target symbol for a dependency path"),
|
|
14428
|
+
symbol: z2.string().nullable().optional().describe("Exact symbol for authoritative definition lookup"),
|
|
14429
|
+
limit: z2.number().int().min(MIN_CONTEXT_RESULT_LIMIT).max(MAX_CONTEXT_RESULT_LIMIT).nullable().optional().default(10).describe(`Maximum number of results (${MIN_CONTEXT_RESULT_LIMIT}-${MAX_CONTEXT_RESULT_LIMIT})`),
|
|
14430
|
+
maxDepth: z2.number().int().min(MIN_CONTEXT_PATH_DEPTH).max(MAX_CONTEXT_PATH_DEPTH).nullable().optional().default(10).describe(`Maximum call-path traversal depth (${MIN_CONTEXT_PATH_DEPTH}-${MAX_CONTEXT_PATH_DEPTH})`),
|
|
14431
|
+
fileType: z2.string().nullable().optional().describe("Filter by file extension"),
|
|
14432
|
+
directory: z2.string().nullable().optional().describe("Filter by directory path"),
|
|
14433
|
+
tokenBudget: z2.number().int().min(MIN_CONTEXT_PACK_TOKEN_BUDGET).max(MAX_CONTEXT_PACK_TOKEN_BUDGET).nullable().optional().default(DEFAULT_CONTEXT_PACK_TOKEN_BUDGET).describe(`Maximum response tokens (${MIN_CONTEXT_PACK_TOKEN_BUDGET}-${MAX_CONTEXT_PACK_TOKEN_BUDGET})`)
|
|
14434
|
+
},
|
|
14435
|
+
async execute(args, context) {
|
|
14436
|
+
return (await resolveCodebaseContext(context?.worktree, DEFAULT_HOST, args)).text;
|
|
14437
|
+
}
|
|
14438
|
+
});
|
|
13535
14439
|
var codebase_peek = (0, import_plugin2.tool)({
|
|
13536
14440
|
description: "Quick lookup of code locations by meaning. Returns only metadata (file, line, name, type) WITHOUT code content. Use this first to find WHERE code is, then use Read tool to examine specific files. Saves tokens by not returning full code blocks. Best for: discovery, navigation, finding multiple related locations.",
|
|
13537
14441
|
args: {
|
|
@@ -14215,6 +15119,7 @@ var plugin = async ({ directory, worktree }) => {
|
|
|
14215
15119
|
}
|
|
14216
15120
|
return {
|
|
14217
15121
|
tool: {
|
|
15122
|
+
codebase_context,
|
|
14218
15123
|
codebase_search,
|
|
14219
15124
|
codebase_peek,
|
|
14220
15125
|
index_codebase,
|