modality-kit 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -15597,8 +15597,372 @@ class SimpleCache {
|
|
|
15597
15597
|
}
|
|
15598
15598
|
// src/isTestEnvironment.ts
|
|
15599
15599
|
var isTestEnvironment = globalThis.Bun?.main?.includes?.("test");
|
|
15600
|
+
// src/recursiveScanForFiles.ts
|
|
15601
|
+
var {readdirSync, statSync} = (() => ({}));
|
|
15602
|
+
|
|
15603
|
+
// node:path
|
|
15604
|
+
function assertPath(path) {
|
|
15605
|
+
if (typeof path !== "string")
|
|
15606
|
+
throw TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
15607
|
+
}
|
|
15608
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
15609
|
+
var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
|
|
15610
|
+
for (var i = 0;i <= path.length; ++i) {
|
|
15611
|
+
if (i < path.length)
|
|
15612
|
+
code = path.charCodeAt(i);
|
|
15613
|
+
else if (code === 47)
|
|
15614
|
+
break;
|
|
15615
|
+
else
|
|
15616
|
+
code = 47;
|
|
15617
|
+
if (code === 47) {
|
|
15618
|
+
if (lastSlash === i - 1 || dots === 1)
|
|
15619
|
+
;
|
|
15620
|
+
else if (lastSlash !== i - 1 && dots === 2) {
|
|
15621
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
15622
|
+
if (res.length > 2) {
|
|
15623
|
+
var lastSlashIndex = res.lastIndexOf("/");
|
|
15624
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
15625
|
+
if (lastSlashIndex === -1)
|
|
15626
|
+
res = "", lastSegmentLength = 0;
|
|
15627
|
+
else
|
|
15628
|
+
res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
15629
|
+
lastSlash = i, dots = 0;
|
|
15630
|
+
continue;
|
|
15631
|
+
}
|
|
15632
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
15633
|
+
res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
|
|
15634
|
+
continue;
|
|
15635
|
+
}
|
|
15636
|
+
}
|
|
15637
|
+
if (allowAboveRoot) {
|
|
15638
|
+
if (res.length > 0)
|
|
15639
|
+
res += "/..";
|
|
15640
|
+
else
|
|
15641
|
+
res = "..";
|
|
15642
|
+
lastSegmentLength = 2;
|
|
15643
|
+
}
|
|
15644
|
+
} else {
|
|
15645
|
+
if (res.length > 0)
|
|
15646
|
+
res += "/" + path.slice(lastSlash + 1, i);
|
|
15647
|
+
else
|
|
15648
|
+
res = path.slice(lastSlash + 1, i);
|
|
15649
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
15650
|
+
}
|
|
15651
|
+
lastSlash = i, dots = 0;
|
|
15652
|
+
} else if (code === 46 && dots !== -1)
|
|
15653
|
+
++dots;
|
|
15654
|
+
else
|
|
15655
|
+
dots = -1;
|
|
15656
|
+
}
|
|
15657
|
+
return res;
|
|
15658
|
+
}
|
|
15659
|
+
function _format(sep, pathObject) {
|
|
15660
|
+
var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
15661
|
+
if (!dir)
|
|
15662
|
+
return base;
|
|
15663
|
+
if (dir === pathObject.root)
|
|
15664
|
+
return dir + base;
|
|
15665
|
+
return dir + sep + base;
|
|
15666
|
+
}
|
|
15667
|
+
function resolve() {
|
|
15668
|
+
var resolvedPath = "", resolvedAbsolute = false, cwd;
|
|
15669
|
+
for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
|
|
15670
|
+
var path;
|
|
15671
|
+
if (i >= 0)
|
|
15672
|
+
path = arguments[i];
|
|
15673
|
+
else {
|
|
15674
|
+
if (cwd === undefined)
|
|
15675
|
+
cwd = process.cwd();
|
|
15676
|
+
path = cwd;
|
|
15677
|
+
}
|
|
15678
|
+
if (assertPath(path), path.length === 0)
|
|
15679
|
+
continue;
|
|
15680
|
+
resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
15681
|
+
}
|
|
15682
|
+
if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
|
|
15683
|
+
if (resolvedPath.length > 0)
|
|
15684
|
+
return "/" + resolvedPath;
|
|
15685
|
+
else
|
|
15686
|
+
return "/";
|
|
15687
|
+
else if (resolvedPath.length > 0)
|
|
15688
|
+
return resolvedPath;
|
|
15689
|
+
else
|
|
15690
|
+
return ".";
|
|
15691
|
+
}
|
|
15692
|
+
function normalize(path) {
|
|
15693
|
+
if (assertPath(path), path.length === 0)
|
|
15694
|
+
return ".";
|
|
15695
|
+
var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
15696
|
+
if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
|
|
15697
|
+
path = ".";
|
|
15698
|
+
if (path.length > 0 && trailingSeparator)
|
|
15699
|
+
path += "/";
|
|
15700
|
+
if (isAbsolute)
|
|
15701
|
+
return "/" + path;
|
|
15702
|
+
return path;
|
|
15703
|
+
}
|
|
15704
|
+
function isAbsolute(path) {
|
|
15705
|
+
return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
|
|
15706
|
+
}
|
|
15707
|
+
function join() {
|
|
15708
|
+
if (arguments.length === 0)
|
|
15709
|
+
return ".";
|
|
15710
|
+
var joined;
|
|
15711
|
+
for (var i = 0;i < arguments.length; ++i) {
|
|
15712
|
+
var arg = arguments[i];
|
|
15713
|
+
if (assertPath(arg), arg.length > 0)
|
|
15714
|
+
if (joined === undefined)
|
|
15715
|
+
joined = arg;
|
|
15716
|
+
else
|
|
15717
|
+
joined += "/" + arg;
|
|
15718
|
+
}
|
|
15719
|
+
if (joined === undefined)
|
|
15720
|
+
return ".";
|
|
15721
|
+
return normalize(joined);
|
|
15722
|
+
}
|
|
15723
|
+
function relative(from, to) {
|
|
15724
|
+
if (assertPath(from), assertPath(to), from === to)
|
|
15725
|
+
return "";
|
|
15726
|
+
if (from = resolve(from), to = resolve(to), from === to)
|
|
15727
|
+
return "";
|
|
15728
|
+
var fromStart = 1;
|
|
15729
|
+
for (;fromStart < from.length; ++fromStart)
|
|
15730
|
+
if (from.charCodeAt(fromStart) !== 47)
|
|
15731
|
+
break;
|
|
15732
|
+
var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
|
|
15733
|
+
for (;toStart < to.length; ++toStart)
|
|
15734
|
+
if (to.charCodeAt(toStart) !== 47)
|
|
15735
|
+
break;
|
|
15736
|
+
var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
|
|
15737
|
+
for (;i <= length; ++i) {
|
|
15738
|
+
if (i === length) {
|
|
15739
|
+
if (toLen > length) {
|
|
15740
|
+
if (to.charCodeAt(toStart + i) === 47)
|
|
15741
|
+
return to.slice(toStart + i + 1);
|
|
15742
|
+
else if (i === 0)
|
|
15743
|
+
return to.slice(toStart + i);
|
|
15744
|
+
} else if (fromLen > length) {
|
|
15745
|
+
if (from.charCodeAt(fromStart + i) === 47)
|
|
15746
|
+
lastCommonSep = i;
|
|
15747
|
+
else if (i === 0)
|
|
15748
|
+
lastCommonSep = 0;
|
|
15749
|
+
}
|
|
15750
|
+
break;
|
|
15751
|
+
}
|
|
15752
|
+
var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
|
|
15753
|
+
if (fromCode !== toCode)
|
|
15754
|
+
break;
|
|
15755
|
+
else if (fromCode === 47)
|
|
15756
|
+
lastCommonSep = i;
|
|
15757
|
+
}
|
|
15758
|
+
var out = "";
|
|
15759
|
+
for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
|
|
15760
|
+
if (i === fromEnd || from.charCodeAt(i) === 47)
|
|
15761
|
+
if (out.length === 0)
|
|
15762
|
+
out += "..";
|
|
15763
|
+
else
|
|
15764
|
+
out += "/..";
|
|
15765
|
+
if (out.length > 0)
|
|
15766
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
15767
|
+
else {
|
|
15768
|
+
if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
|
|
15769
|
+
++toStart;
|
|
15770
|
+
return to.slice(toStart);
|
|
15771
|
+
}
|
|
15772
|
+
}
|
|
15773
|
+
function _makeLong(path) {
|
|
15774
|
+
return path;
|
|
15775
|
+
}
|
|
15776
|
+
function dirname(path) {
|
|
15777
|
+
if (assertPath(path), path.length === 0)
|
|
15778
|
+
return ".";
|
|
15779
|
+
var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
|
|
15780
|
+
for (var i = path.length - 1;i >= 1; --i)
|
|
15781
|
+
if (code = path.charCodeAt(i), code === 47) {
|
|
15782
|
+
if (!matchedSlash) {
|
|
15783
|
+
end = i;
|
|
15784
|
+
break;
|
|
15785
|
+
}
|
|
15786
|
+
} else
|
|
15787
|
+
matchedSlash = false;
|
|
15788
|
+
if (end === -1)
|
|
15789
|
+
return hasRoot ? "/" : ".";
|
|
15790
|
+
if (hasRoot && end === 1)
|
|
15791
|
+
return "//";
|
|
15792
|
+
return path.slice(0, end);
|
|
15793
|
+
}
|
|
15794
|
+
function basename(path, ext) {
|
|
15795
|
+
if (ext !== undefined && typeof ext !== "string")
|
|
15796
|
+
throw TypeError('"ext" argument must be a string');
|
|
15797
|
+
assertPath(path);
|
|
15798
|
+
var start = 0, end = -1, matchedSlash = true, i;
|
|
15799
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
15800
|
+
if (ext.length === path.length && ext === path)
|
|
15801
|
+
return "";
|
|
15802
|
+
var extIdx = ext.length - 1, firstNonSlashEnd = -1;
|
|
15803
|
+
for (i = path.length - 1;i >= 0; --i) {
|
|
15804
|
+
var code = path.charCodeAt(i);
|
|
15805
|
+
if (code === 47) {
|
|
15806
|
+
if (!matchedSlash) {
|
|
15807
|
+
start = i + 1;
|
|
15808
|
+
break;
|
|
15809
|
+
}
|
|
15810
|
+
} else {
|
|
15811
|
+
if (firstNonSlashEnd === -1)
|
|
15812
|
+
matchedSlash = false, firstNonSlashEnd = i + 1;
|
|
15813
|
+
if (extIdx >= 0)
|
|
15814
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
15815
|
+
if (--extIdx === -1)
|
|
15816
|
+
end = i;
|
|
15817
|
+
} else
|
|
15818
|
+
extIdx = -1, end = firstNonSlashEnd;
|
|
15819
|
+
}
|
|
15820
|
+
}
|
|
15821
|
+
if (start === end)
|
|
15822
|
+
end = firstNonSlashEnd;
|
|
15823
|
+
else if (end === -1)
|
|
15824
|
+
end = path.length;
|
|
15825
|
+
return path.slice(start, end);
|
|
15826
|
+
} else {
|
|
15827
|
+
for (i = path.length - 1;i >= 0; --i)
|
|
15828
|
+
if (path.charCodeAt(i) === 47) {
|
|
15829
|
+
if (!matchedSlash) {
|
|
15830
|
+
start = i + 1;
|
|
15831
|
+
break;
|
|
15832
|
+
}
|
|
15833
|
+
} else if (end === -1)
|
|
15834
|
+
matchedSlash = false, end = i + 1;
|
|
15835
|
+
if (end === -1)
|
|
15836
|
+
return "";
|
|
15837
|
+
return path.slice(start, end);
|
|
15838
|
+
}
|
|
15839
|
+
}
|
|
15840
|
+
function extname(path) {
|
|
15841
|
+
assertPath(path);
|
|
15842
|
+
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
|
|
15843
|
+
for (var i = path.length - 1;i >= 0; --i) {
|
|
15844
|
+
var code = path.charCodeAt(i);
|
|
15845
|
+
if (code === 47) {
|
|
15846
|
+
if (!matchedSlash) {
|
|
15847
|
+
startPart = i + 1;
|
|
15848
|
+
break;
|
|
15849
|
+
}
|
|
15850
|
+
continue;
|
|
15851
|
+
}
|
|
15852
|
+
if (end === -1)
|
|
15853
|
+
matchedSlash = false, end = i + 1;
|
|
15854
|
+
if (code === 46) {
|
|
15855
|
+
if (startDot === -1)
|
|
15856
|
+
startDot = i;
|
|
15857
|
+
else if (preDotState !== 1)
|
|
15858
|
+
preDotState = 1;
|
|
15859
|
+
} else if (startDot !== -1)
|
|
15860
|
+
preDotState = -1;
|
|
15861
|
+
}
|
|
15862
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
|
|
15863
|
+
return "";
|
|
15864
|
+
return path.slice(startDot, end);
|
|
15865
|
+
}
|
|
15866
|
+
function format(pathObject) {
|
|
15867
|
+
if (pathObject === null || typeof pathObject !== "object")
|
|
15868
|
+
throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
15869
|
+
return _format("/", pathObject);
|
|
15870
|
+
}
|
|
15871
|
+
function parse5(path) {
|
|
15872
|
+
assertPath(path);
|
|
15873
|
+
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
15874
|
+
if (path.length === 0)
|
|
15875
|
+
return ret;
|
|
15876
|
+
var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
|
|
15877
|
+
if (isAbsolute2)
|
|
15878
|
+
ret.root = "/", start = 1;
|
|
15879
|
+
else
|
|
15880
|
+
start = 0;
|
|
15881
|
+
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
|
|
15882
|
+
for (;i >= start; --i) {
|
|
15883
|
+
if (code = path.charCodeAt(i), code === 47) {
|
|
15884
|
+
if (!matchedSlash) {
|
|
15885
|
+
startPart = i + 1;
|
|
15886
|
+
break;
|
|
15887
|
+
}
|
|
15888
|
+
continue;
|
|
15889
|
+
}
|
|
15890
|
+
if (end === -1)
|
|
15891
|
+
matchedSlash = false, end = i + 1;
|
|
15892
|
+
if (code === 46) {
|
|
15893
|
+
if (startDot === -1)
|
|
15894
|
+
startDot = i;
|
|
15895
|
+
else if (preDotState !== 1)
|
|
15896
|
+
preDotState = 1;
|
|
15897
|
+
} else if (startDot !== -1)
|
|
15898
|
+
preDotState = -1;
|
|
15899
|
+
}
|
|
15900
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
15901
|
+
if (end !== -1)
|
|
15902
|
+
if (startPart === 0 && isAbsolute2)
|
|
15903
|
+
ret.base = ret.name = path.slice(1, end);
|
|
15904
|
+
else
|
|
15905
|
+
ret.base = ret.name = path.slice(startPart, end);
|
|
15906
|
+
} else {
|
|
15907
|
+
if (startPart === 0 && isAbsolute2)
|
|
15908
|
+
ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
|
|
15909
|
+
else
|
|
15910
|
+
ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
|
|
15911
|
+
ret.ext = path.slice(startDot, end);
|
|
15912
|
+
}
|
|
15913
|
+
if (startPart > 0)
|
|
15914
|
+
ret.dir = path.slice(0, startPart - 1);
|
|
15915
|
+
else if (isAbsolute2)
|
|
15916
|
+
ret.dir = "/";
|
|
15917
|
+
return ret;
|
|
15918
|
+
}
|
|
15919
|
+
var sep = "/";
|
|
15920
|
+
var delimiter = ":";
|
|
15921
|
+
var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse: parse5, sep, delimiter, win32: null, posix: null });
|
|
15922
|
+
|
|
15923
|
+
// src/recursiveScanForFiles.ts
|
|
15924
|
+
function recursiveScanForFiles(baseDir, options) {
|
|
15925
|
+
const files = [];
|
|
15926
|
+
const {
|
|
15927
|
+
targetFolderName,
|
|
15928
|
+
fileExtensions,
|
|
15929
|
+
fileNameFilter = () => true,
|
|
15930
|
+
excludePatterns = [".", "__"],
|
|
15931
|
+
searchInSubfolders = false
|
|
15932
|
+
} = options;
|
|
15933
|
+
const extensionSet = new Set(fileExtensions);
|
|
15934
|
+
function scanDirectory(dir, relativePath = "", isSearchingForTarget = true) {
|
|
15935
|
+
try {
|
|
15936
|
+
const entries = readdirSync(dir);
|
|
15937
|
+
for (const entry of entries) {
|
|
15938
|
+
if (excludePatterns.some((pattern) => entry.startsWith(pattern))) {
|
|
15939
|
+
continue;
|
|
15940
|
+
}
|
|
15941
|
+
const fullPath = join(dir, entry);
|
|
15942
|
+
const relPath = relativePath ? `${relativePath}/${entry}` : entry;
|
|
15943
|
+
try {
|
|
15944
|
+
const isDirectory = statSync(fullPath).isDirectory();
|
|
15945
|
+
if (isSearchingForTarget) {
|
|
15946
|
+
if (isDirectory) {
|
|
15947
|
+
scanDirectory(fullPath, relPath, entry !== targetFolderName);
|
|
15948
|
+
}
|
|
15949
|
+
} else if (isDirectory) {
|
|
15950
|
+
if (searchInSubfolders) {
|
|
15951
|
+
scanDirectory(fullPath, relPath, false);
|
|
15952
|
+
}
|
|
15953
|
+
} else if ((!fileExtensions || extensionSet.has(extname(entry))) && fileNameFilter(entry)) {
|
|
15954
|
+
files.push({ filename: relPath, fullPath });
|
|
15955
|
+
}
|
|
15956
|
+
} catch (e) {}
|
|
15957
|
+
}
|
|
15958
|
+
} catch (e) {}
|
|
15959
|
+
}
|
|
15960
|
+
scanDirectory(baseDir, "", true);
|
|
15961
|
+
return files.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
15962
|
+
}
|
|
15600
15963
|
export {
|
|
15601
15964
|
withErrorHandling,
|
|
15965
|
+
recursiveScanForFiles,
|
|
15602
15966
|
mergeResponsesContent,
|
|
15603
15967
|
loadVersion,
|
|
15604
15968
|
isTestEnvironment,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -24,3 +24,4 @@ export { SimpleCache } from "./simple-cache";
|
|
|
24
24
|
export { isTestEnvironment } from "./isTestEnvironment";
|
|
25
25
|
export type { SimpleCacheOptions } from "./simple-cache";
|
|
26
26
|
export type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
27
|
+
export { recursiveScanForFiles, type ScannedFile } from "./recursiveScanForFiles";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface ScanOptions {
|
|
2
|
+
targetFolderName: string;
|
|
3
|
+
fileExtensions?: string[];
|
|
4
|
+
fileNameFilter?: (name: string) => boolean;
|
|
5
|
+
excludePatterns?: string[];
|
|
6
|
+
searchInSubfolders?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generic recursive file finder that scans directories for files matching criteria
|
|
10
|
+
* Internal utility for scanning templates, protocols, and other resource types
|
|
11
|
+
*/
|
|
12
|
+
export interface ScannedFile {
|
|
13
|
+
filename: string;
|
|
14
|
+
fullPath: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Recursively scan directory for files in folders matching criteria
|
|
18
|
+
* @param baseDir - Base directory to start scanning from
|
|
19
|
+
* @param options - Scan configuration
|
|
20
|
+
* @returns Array of found files sorted by filename
|
|
21
|
+
*/
|
|
22
|
+
export declare function recursiveScanForFiles(baseDir: string, options: ScanOptions): ScannedFile[];
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.17.0",
|
|
3
3
|
"name": "modality-kit",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
17
|
-
"modality-bun-kit": "^
|
|
17
|
+
"modality-bun-kit": "^1.3.13",
|
|
18
18
|
"zod": "^4.3.6"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|