opencode-codebase-index 0.1.8 → 0.1.10
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.cjs +225 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +214 -256
- package/dist/index.js.map +1 -1
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -491,7 +491,7 @@ var require_ignore = __commonJS({
|
|
|
491
491
|
// path matching.
|
|
492
492
|
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
493
493
|
// @returns {TestResult} true if a file is ignored
|
|
494
|
-
test(
|
|
494
|
+
test(path8, checkUnignored, mode) {
|
|
495
495
|
let ignored = false;
|
|
496
496
|
let unignored = false;
|
|
497
497
|
let matchedRule;
|
|
@@ -500,7 +500,7 @@ var require_ignore = __commonJS({
|
|
|
500
500
|
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
501
501
|
return;
|
|
502
502
|
}
|
|
503
|
-
const matched = rule[mode].test(
|
|
503
|
+
const matched = rule[mode].test(path8);
|
|
504
504
|
if (!matched) {
|
|
505
505
|
return;
|
|
506
506
|
}
|
|
@@ -521,17 +521,17 @@ var require_ignore = __commonJS({
|
|
|
521
521
|
var throwError = (message, Ctor) => {
|
|
522
522
|
throw new Ctor(message);
|
|
523
523
|
};
|
|
524
|
-
var checkPath = (
|
|
525
|
-
if (!isString(
|
|
524
|
+
var checkPath = (path8, originalPath, doThrow) => {
|
|
525
|
+
if (!isString(path8)) {
|
|
526
526
|
return doThrow(
|
|
527
527
|
`path must be a string, but got \`${originalPath}\``,
|
|
528
528
|
TypeError
|
|
529
529
|
);
|
|
530
530
|
}
|
|
531
|
-
if (!
|
|
531
|
+
if (!path8) {
|
|
532
532
|
return doThrow(`path must not be empty`, TypeError);
|
|
533
533
|
}
|
|
534
|
-
if (checkPath.isNotRelative(
|
|
534
|
+
if (checkPath.isNotRelative(path8)) {
|
|
535
535
|
const r = "`path.relative()`d";
|
|
536
536
|
return doThrow(
|
|
537
537
|
`path should be a ${r} string, but got "${originalPath}"`,
|
|
@@ -540,7 +540,7 @@ var require_ignore = __commonJS({
|
|
|
540
540
|
}
|
|
541
541
|
return true;
|
|
542
542
|
};
|
|
543
|
-
var isNotRelative = (
|
|
543
|
+
var isNotRelative = (path8) => REGEX_TEST_INVALID_PATH.test(path8);
|
|
544
544
|
checkPath.isNotRelative = isNotRelative;
|
|
545
545
|
checkPath.convert = (p) => p;
|
|
546
546
|
var Ignore2 = class {
|
|
@@ -570,19 +570,19 @@ var require_ignore = __commonJS({
|
|
|
570
570
|
}
|
|
571
571
|
// @returns {TestResult}
|
|
572
572
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
573
|
-
const
|
|
573
|
+
const path8 = originalPath && checkPath.convert(originalPath);
|
|
574
574
|
checkPath(
|
|
575
|
-
|
|
575
|
+
path8,
|
|
576
576
|
originalPath,
|
|
577
577
|
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
578
578
|
);
|
|
579
|
-
return this._t(
|
|
579
|
+
return this._t(path8, cache, checkUnignored, slices);
|
|
580
580
|
}
|
|
581
|
-
checkIgnore(
|
|
582
|
-
if (!REGEX_TEST_TRAILING_SLASH.test(
|
|
583
|
-
return this.test(
|
|
581
|
+
checkIgnore(path8) {
|
|
582
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path8)) {
|
|
583
|
+
return this.test(path8);
|
|
584
584
|
}
|
|
585
|
-
const slices =
|
|
585
|
+
const slices = path8.split(SLASH2).filter(Boolean);
|
|
586
586
|
slices.pop();
|
|
587
587
|
if (slices.length) {
|
|
588
588
|
const parent = this._t(
|
|
@@ -595,18 +595,18 @@ var require_ignore = __commonJS({
|
|
|
595
595
|
return parent;
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
|
-
return this._rules.test(
|
|
598
|
+
return this._rules.test(path8, false, MODE_CHECK_IGNORE);
|
|
599
599
|
}
|
|
600
|
-
_t(
|
|
601
|
-
if (
|
|
602
|
-
return cache[
|
|
600
|
+
_t(path8, cache, checkUnignored, slices) {
|
|
601
|
+
if (path8 in cache) {
|
|
602
|
+
return cache[path8];
|
|
603
603
|
}
|
|
604
604
|
if (!slices) {
|
|
605
|
-
slices =
|
|
605
|
+
slices = path8.split(SLASH2).filter(Boolean);
|
|
606
606
|
}
|
|
607
607
|
slices.pop();
|
|
608
608
|
if (!slices.length) {
|
|
609
|
-
return cache[
|
|
609
|
+
return cache[path8] = this._rules.test(path8, checkUnignored, MODE_IGNORE);
|
|
610
610
|
}
|
|
611
611
|
const parent = this._t(
|
|
612
612
|
slices.join(SLASH2) + SLASH2,
|
|
@@ -614,29 +614,29 @@ var require_ignore = __commonJS({
|
|
|
614
614
|
checkUnignored,
|
|
615
615
|
slices
|
|
616
616
|
);
|
|
617
|
-
return cache[
|
|
617
|
+
return cache[path8] = parent.ignored ? parent : this._rules.test(path8, checkUnignored, MODE_IGNORE);
|
|
618
618
|
}
|
|
619
|
-
ignores(
|
|
620
|
-
return this._test(
|
|
619
|
+
ignores(path8) {
|
|
620
|
+
return this._test(path8, this._ignoreCache, false).ignored;
|
|
621
621
|
}
|
|
622
622
|
createFilter() {
|
|
623
|
-
return (
|
|
623
|
+
return (path8) => !this.ignores(path8);
|
|
624
624
|
}
|
|
625
625
|
filter(paths) {
|
|
626
626
|
return makeArray(paths).filter(this.createFilter());
|
|
627
627
|
}
|
|
628
628
|
// @returns {TestResult}
|
|
629
|
-
test(
|
|
630
|
-
return this._test(
|
|
629
|
+
test(path8) {
|
|
630
|
+
return this._test(path8, this._testCache, true);
|
|
631
631
|
}
|
|
632
632
|
};
|
|
633
633
|
var factory = (options) => new Ignore2(options);
|
|
634
|
-
var isPathValid = (
|
|
634
|
+
var isPathValid = (path8) => checkPath(path8 && checkPath.convert(path8), path8, RETURN_FALSE);
|
|
635
635
|
var setupWindows = () => {
|
|
636
636
|
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
637
637
|
checkPath.convert = makePosix;
|
|
638
638
|
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
639
|
-
checkPath.isNotRelative = (
|
|
639
|
+
checkPath.isNotRelative = (path8) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path8) || isNotRelative(path8);
|
|
640
640
|
};
|
|
641
641
|
if (
|
|
642
642
|
// Detect `process` so that it can run in browsers.
|
|
@@ -652,8 +652,8 @@ var require_ignore = __commonJS({
|
|
|
652
652
|
});
|
|
653
653
|
|
|
654
654
|
// src/index.ts
|
|
655
|
-
import { existsSync as existsSync5, readFileSync as
|
|
656
|
-
import * as
|
|
655
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
|
|
656
|
+
import * as path7 from "path";
|
|
657
657
|
|
|
658
658
|
// src/config/schema.ts
|
|
659
659
|
var DEFAULT_INCLUDE = [
|
|
@@ -802,8 +802,8 @@ function getDefaultModelForProvider(provider) {
|
|
|
802
802
|
}
|
|
803
803
|
|
|
804
804
|
// src/indexer/index.ts
|
|
805
|
-
import { existsSync as existsSync4, readFileSync as
|
|
806
|
-
import * as
|
|
805
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync2, promises as fsPromises2 } from "fs";
|
|
806
|
+
import * as path5 from "path";
|
|
807
807
|
|
|
808
808
|
// node_modules/eventemitter3/index.mjs
|
|
809
809
|
var import_index = __toESM(require_eventemitter3(), 1);
|
|
@@ -1874,7 +1874,7 @@ function getGitHubCopilotCredentials() {
|
|
|
1874
1874
|
if (!copilotAuth || copilotAuth.type !== "oauth") {
|
|
1875
1875
|
return null;
|
|
1876
1876
|
}
|
|
1877
|
-
const baseUrl = copilotAuth.enterpriseUrl ? `https://copilot-api.${copilotAuth.enterpriseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "")}` : "https://
|
|
1877
|
+
const baseUrl = copilotAuth.enterpriseUrl ? `https://copilot-api.${copilotAuth.enterpriseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "")}` : "https://models.github.ai";
|
|
1878
1878
|
return {
|
|
1879
1879
|
provider: "github-copilot",
|
|
1880
1880
|
baseUrl,
|
|
@@ -1949,9 +1949,6 @@ function getProviderDisplayName(provider) {
|
|
|
1949
1949
|
}
|
|
1950
1950
|
|
|
1951
1951
|
// src/embeddings/provider.ts
|
|
1952
|
-
import { readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
1953
|
-
import * as path2 from "path";
|
|
1954
|
-
import * as os2 from "os";
|
|
1955
1952
|
function createEmbeddingProvider(credentials, modelInfo) {
|
|
1956
1953
|
switch (credentials.provider) {
|
|
1957
1954
|
case "github-copilot":
|
|
@@ -1966,56 +1963,16 @@ function createEmbeddingProvider(credentials, modelInfo) {
|
|
|
1966
1963
|
throw new Error(`Unsupported embedding provider: ${credentials.provider}`);
|
|
1967
1964
|
}
|
|
1968
1965
|
}
|
|
1969
|
-
var COPILOT_HEADERS = {
|
|
1970
|
-
"User-Agent": "GitHubCopilotChat/0.35.0",
|
|
1971
|
-
"Editor-Version": "vscode/1.107.0",
|
|
1972
|
-
"Editor-Plugin-Version": "copilot-chat/0.35.0",
|
|
1973
|
-
"Copilot-Integration-Id": "vscode-chat",
|
|
1974
|
-
"Openai-Intent": "conversation-edits"
|
|
1975
|
-
};
|
|
1976
1966
|
var GitHubCopilotEmbeddingProvider = class {
|
|
1977
1967
|
constructor(credentials, modelInfo) {
|
|
1978
1968
|
this.credentials = credentials;
|
|
1979
1969
|
this.modelInfo = modelInfo;
|
|
1980
|
-
this.accessToken = credentials.accessToken || "";
|
|
1981
|
-
this.tokenExpires = credentials.tokenExpires || 0;
|
|
1982
1970
|
}
|
|
1983
|
-
|
|
1984
|
-
tokenExpires;
|
|
1985
|
-
async ensureValidToken() {
|
|
1986
|
-
if (this.accessToken && this.tokenExpires > Date.now()) {
|
|
1987
|
-
return this.accessToken;
|
|
1988
|
-
}
|
|
1971
|
+
getToken() {
|
|
1989
1972
|
if (!this.credentials.refreshToken) {
|
|
1990
|
-
throw new Error("No
|
|
1991
|
-
}
|
|
1992
|
-
const response = await fetch("https://api.github.com/copilot_internal/v2/token", {
|
|
1993
|
-
headers: {
|
|
1994
|
-
Accept: "application/json",
|
|
1995
|
-
Authorization: `Bearer ${this.credentials.refreshToken}`,
|
|
1996
|
-
...COPILOT_HEADERS
|
|
1997
|
-
}
|
|
1998
|
-
});
|
|
1999
|
-
if (!response.ok) {
|
|
2000
|
-
throw new Error(`Token refresh failed: ${response.status}`);
|
|
2001
|
-
}
|
|
2002
|
-
const tokenData = await response.json();
|
|
2003
|
-
this.accessToken = tokenData.token;
|
|
2004
|
-
this.tokenExpires = tokenData.expires_at * 1e3 - 5 * 60 * 1e3;
|
|
2005
|
-
this.persistToken(tokenData.token, this.tokenExpires);
|
|
2006
|
-
return this.accessToken;
|
|
2007
|
-
}
|
|
2008
|
-
persistToken(token, expires) {
|
|
2009
|
-
try {
|
|
2010
|
-
const authPath = path2.join(os2.homedir(), ".local", "share", "opencode", "auth.json");
|
|
2011
|
-
const authData = JSON.parse(readFileSync2(authPath, "utf-8"));
|
|
2012
|
-
if (authData["github-copilot"]) {
|
|
2013
|
-
authData["github-copilot"].access = token;
|
|
2014
|
-
authData["github-copilot"].expires = expires;
|
|
2015
|
-
writeFileSync(authPath, JSON.stringify(authData, null, 2));
|
|
2016
|
-
}
|
|
2017
|
-
} catch {
|
|
1973
|
+
throw new Error("No OAuth token available for GitHub");
|
|
2018
1974
|
}
|
|
1975
|
+
return this.credentials.refreshToken;
|
|
2019
1976
|
}
|
|
2020
1977
|
async embed(text) {
|
|
2021
1978
|
const result = await this.embedBatch([text]);
|
|
@@ -2025,16 +1982,17 @@ var GitHubCopilotEmbeddingProvider = class {
|
|
|
2025
1982
|
};
|
|
2026
1983
|
}
|
|
2027
1984
|
async embedBatch(texts) {
|
|
2028
|
-
const token =
|
|
2029
|
-
const response = await fetch(`${this.credentials.baseUrl}/embeddings`, {
|
|
1985
|
+
const token = this.getToken();
|
|
1986
|
+
const response = await fetch(`${this.credentials.baseUrl}/inference/embeddings`, {
|
|
2030
1987
|
method: "POST",
|
|
2031
1988
|
headers: {
|
|
2032
1989
|
Authorization: `Bearer ${token}`,
|
|
2033
1990
|
"Content-Type": "application/json",
|
|
2034
|
-
|
|
1991
|
+
Accept: "application/vnd.github+json",
|
|
1992
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
2035
1993
|
},
|
|
2036
1994
|
body: JSON.stringify({
|
|
2037
|
-
model: this.modelInfo.model
|
|
1995
|
+
model: `openai/${this.modelInfo.model}`,
|
|
2038
1996
|
input: texts
|
|
2039
1997
|
})
|
|
2040
1998
|
});
|
|
@@ -2183,8 +2141,8 @@ var OllamaEmbeddingProvider = class {
|
|
|
2183
2141
|
|
|
2184
2142
|
// src/utils/files.ts
|
|
2185
2143
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
2186
|
-
import { existsSync as existsSync2, readFileSync as
|
|
2187
|
-
import * as
|
|
2144
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, promises as fsPromises } from "fs";
|
|
2145
|
+
import * as path2 from "path";
|
|
2188
2146
|
function createIgnoreFilter(projectRoot) {
|
|
2189
2147
|
const ig = (0, import_ignore.default)();
|
|
2190
2148
|
const defaultIgnores = [
|
|
@@ -2201,15 +2159,15 @@ function createIgnoreFilter(projectRoot) {
|
|
|
2201
2159
|
".opencode"
|
|
2202
2160
|
];
|
|
2203
2161
|
ig.add(defaultIgnores);
|
|
2204
|
-
const gitignorePath =
|
|
2162
|
+
const gitignorePath = path2.join(projectRoot, ".gitignore");
|
|
2205
2163
|
if (existsSync2(gitignorePath)) {
|
|
2206
|
-
const gitignoreContent =
|
|
2164
|
+
const gitignoreContent = readFileSync2(gitignorePath, "utf-8");
|
|
2207
2165
|
ig.add(gitignoreContent);
|
|
2208
2166
|
}
|
|
2209
2167
|
return ig;
|
|
2210
2168
|
}
|
|
2211
2169
|
function shouldIncludeFile(filePath, projectRoot, includePatterns, excludePatterns, ignoreFilter) {
|
|
2212
|
-
const relativePath =
|
|
2170
|
+
const relativePath = path2.relative(projectRoot, filePath);
|
|
2213
2171
|
if (ignoreFilter.ignores(relativePath)) {
|
|
2214
2172
|
return false;
|
|
2215
2173
|
}
|
|
@@ -2233,8 +2191,8 @@ function matchGlob(filePath, pattern) {
|
|
|
2233
2191
|
async function* walkDirectory(dir, projectRoot, includePatterns, excludePatterns, ignoreFilter, maxFileSize, skipped) {
|
|
2234
2192
|
const entries = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
2235
2193
|
for (const entry of entries) {
|
|
2236
|
-
const fullPath =
|
|
2237
|
-
const relativePath =
|
|
2194
|
+
const fullPath = path2.join(dir, entry.name);
|
|
2195
|
+
const relativePath = path2.relative(projectRoot, fullPath);
|
|
2238
2196
|
if (ignoreFilter.ignores(relativePath)) {
|
|
2239
2197
|
if (entry.isFile()) {
|
|
2240
2198
|
skipped.push({ path: relativePath, reason: "gitignore" });
|
|
@@ -2357,12 +2315,12 @@ function padRight(str, length) {
|
|
|
2357
2315
|
}
|
|
2358
2316
|
|
|
2359
2317
|
// src/native/index.ts
|
|
2360
|
-
import * as
|
|
2361
|
-
import * as
|
|
2318
|
+
import * as path3 from "path";
|
|
2319
|
+
import * as os2 from "os";
|
|
2362
2320
|
import { fileURLToPath } from "url";
|
|
2363
2321
|
function getNativeBinding() {
|
|
2364
|
-
const platform2 =
|
|
2365
|
-
const arch2 =
|
|
2322
|
+
const platform2 = os2.platform();
|
|
2323
|
+
const arch2 = os2.arch();
|
|
2366
2324
|
let bindingName;
|
|
2367
2325
|
if (platform2 === "darwin" && arch2 === "arm64") {
|
|
2368
2326
|
bindingName = "codebase-index-native.darwin-arm64.node";
|
|
@@ -2379,15 +2337,15 @@ function getNativeBinding() {
|
|
|
2379
2337
|
}
|
|
2380
2338
|
let currentDir;
|
|
2381
2339
|
if (typeof import.meta !== "undefined" && import.meta.url) {
|
|
2382
|
-
currentDir =
|
|
2340
|
+
currentDir = path3.dirname(fileURLToPath(import.meta.url));
|
|
2383
2341
|
} else if (typeof __dirname !== "undefined") {
|
|
2384
2342
|
currentDir = __dirname;
|
|
2385
2343
|
} else {
|
|
2386
2344
|
currentDir = process.cwd();
|
|
2387
2345
|
}
|
|
2388
2346
|
const isDevMode = currentDir.includes("/src/native");
|
|
2389
|
-
const packageRoot = isDevMode ?
|
|
2390
|
-
const nativePath =
|
|
2347
|
+
const packageRoot = isDevMode ? path3.resolve(currentDir, "../..") : path3.resolve(currentDir, "..");
|
|
2348
|
+
const nativePath = path3.join(packageRoot, "native", bindingName);
|
|
2391
2349
|
return __require(nativePath);
|
|
2392
2350
|
}
|
|
2393
2351
|
var native = getNativeBinding();
|
|
@@ -2664,22 +2622,22 @@ function generateChunkHash(chunk) {
|
|
|
2664
2622
|
}
|
|
2665
2623
|
|
|
2666
2624
|
// src/indexer/inverted-index.ts
|
|
2667
|
-
import { existsSync as existsSync3, readFileSync as
|
|
2668
|
-
import * as
|
|
2625
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
2626
|
+
import * as path4 from "path";
|
|
2669
2627
|
var InvertedIndex = class {
|
|
2670
2628
|
indexPath;
|
|
2671
2629
|
termToChunks = /* @__PURE__ */ new Map();
|
|
2672
2630
|
chunkTokens = /* @__PURE__ */ new Map();
|
|
2673
2631
|
totalTokenCount = 0;
|
|
2674
2632
|
constructor(indexPath) {
|
|
2675
|
-
this.indexPath =
|
|
2633
|
+
this.indexPath = path4.join(indexPath, "inverted-index.json");
|
|
2676
2634
|
}
|
|
2677
2635
|
load() {
|
|
2678
2636
|
if (!existsSync3(this.indexPath)) {
|
|
2679
2637
|
return;
|
|
2680
2638
|
}
|
|
2681
2639
|
try {
|
|
2682
|
-
const content =
|
|
2640
|
+
const content = readFileSync3(this.indexPath, "utf-8");
|
|
2683
2641
|
const data = JSON.parse(content);
|
|
2684
2642
|
for (const [term, chunkIds] of Object.entries(data.termToChunks)) {
|
|
2685
2643
|
this.termToChunks.set(term, new Set(chunkIds));
|
|
@@ -2709,7 +2667,7 @@ var InvertedIndex = class {
|
|
|
2709
2667
|
for (const [chunkId, tokens] of this.chunkTokens) {
|
|
2710
2668
|
data.chunkTokens[chunkId] = Object.fromEntries(tokens);
|
|
2711
2669
|
}
|
|
2712
|
-
|
|
2670
|
+
writeFileSync(this.indexPath, JSON.stringify(data));
|
|
2713
2671
|
}
|
|
2714
2672
|
addChunk(chunkId, content) {
|
|
2715
2673
|
const tokens = this.tokenize(content);
|
|
@@ -2813,19 +2771,19 @@ var Indexer = class {
|
|
|
2813
2771
|
this.projectRoot = projectRoot;
|
|
2814
2772
|
this.config = config;
|
|
2815
2773
|
this.indexPath = this.getIndexPath();
|
|
2816
|
-
this.fileHashCachePath =
|
|
2774
|
+
this.fileHashCachePath = path5.join(this.indexPath, "file-hashes.json");
|
|
2817
2775
|
}
|
|
2818
2776
|
getIndexPath() {
|
|
2819
2777
|
if (this.config.scope === "global") {
|
|
2820
2778
|
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
|
|
2821
|
-
return
|
|
2779
|
+
return path5.join(homeDir, ".opencode", "global-index");
|
|
2822
2780
|
}
|
|
2823
|
-
return
|
|
2781
|
+
return path5.join(this.projectRoot, ".opencode", "index");
|
|
2824
2782
|
}
|
|
2825
2783
|
loadFileHashCache() {
|
|
2826
2784
|
try {
|
|
2827
2785
|
if (existsSync4(this.fileHashCachePath)) {
|
|
2828
|
-
const data =
|
|
2786
|
+
const data = readFileSync4(this.fileHashCachePath, "utf-8");
|
|
2829
2787
|
const parsed = JSON.parse(data);
|
|
2830
2788
|
this.fileHashCache = new Map(Object.entries(parsed));
|
|
2831
2789
|
}
|
|
@@ -2838,7 +2796,7 @@ var Indexer = class {
|
|
|
2838
2796
|
for (const [k, v] of this.fileHashCache) {
|
|
2839
2797
|
obj[k] = v;
|
|
2840
2798
|
}
|
|
2841
|
-
|
|
2799
|
+
writeFileSync2(this.fileHashCachePath, JSON.stringify(obj));
|
|
2842
2800
|
}
|
|
2843
2801
|
async initialize() {
|
|
2844
2802
|
this.detectedProvider = await detectEmbeddingProvider(this.config.embeddingProvider);
|
|
@@ -2853,9 +2811,9 @@ var Indexer = class {
|
|
|
2853
2811
|
);
|
|
2854
2812
|
await fsPromises2.mkdir(this.indexPath, { recursive: true });
|
|
2855
2813
|
const dimensions = this.detectedProvider.modelInfo.dimensions;
|
|
2856
|
-
const storePath =
|
|
2814
|
+
const storePath = path5.join(this.indexPath, "vectors");
|
|
2857
2815
|
this.store = new VectorStore(storePath, dimensions);
|
|
2858
|
-
const indexFilePath =
|
|
2816
|
+
const indexFilePath = path5.join(this.indexPath, "vectors.usearch");
|
|
2859
2817
|
if (existsSync4(indexFilePath)) {
|
|
2860
2818
|
this.store.load();
|
|
2861
2819
|
}
|
|
@@ -2958,7 +2916,7 @@ var Indexer = class {
|
|
|
2958
2916
|
for (const parsed of parsedFiles) {
|
|
2959
2917
|
currentFilePaths.add(parsed.path);
|
|
2960
2918
|
if (parsed.chunks.length === 0) {
|
|
2961
|
-
const relativePath =
|
|
2919
|
+
const relativePath = path5.relative(this.projectRoot, parsed.path);
|
|
2962
2920
|
stats.parseFailures.push(relativePath);
|
|
2963
2921
|
}
|
|
2964
2922
|
for (const chunk of parsed.chunks) {
|
|
@@ -3337,7 +3295,7 @@ var ReaddirpStream = class extends Readable {
|
|
|
3337
3295
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
3338
3296
|
const statMethod = opts.lstat ? lstat : stat;
|
|
3339
3297
|
if (wantBigintFsStats) {
|
|
3340
|
-
this._stat = (
|
|
3298
|
+
this._stat = (path8) => statMethod(path8, { bigint: true });
|
|
3341
3299
|
} else {
|
|
3342
3300
|
this._stat = statMethod;
|
|
3343
3301
|
}
|
|
@@ -3362,8 +3320,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
3362
3320
|
const par = this.parent;
|
|
3363
3321
|
const fil = par && par.files;
|
|
3364
3322
|
if (fil && fil.length > 0) {
|
|
3365
|
-
const { path:
|
|
3366
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
3323
|
+
const { path: path8, depth } = par;
|
|
3324
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path8));
|
|
3367
3325
|
const awaited = await Promise.all(slice);
|
|
3368
3326
|
for (const entry of awaited) {
|
|
3369
3327
|
if (!entry)
|
|
@@ -3403,20 +3361,20 @@ var ReaddirpStream = class extends Readable {
|
|
|
3403
3361
|
this.reading = false;
|
|
3404
3362
|
}
|
|
3405
3363
|
}
|
|
3406
|
-
async _exploreDir(
|
|
3364
|
+
async _exploreDir(path8, depth) {
|
|
3407
3365
|
let files;
|
|
3408
3366
|
try {
|
|
3409
|
-
files = await readdir(
|
|
3367
|
+
files = await readdir(path8, this._rdOptions);
|
|
3410
3368
|
} catch (error) {
|
|
3411
3369
|
this._onError(error);
|
|
3412
3370
|
}
|
|
3413
|
-
return { files, depth, path:
|
|
3371
|
+
return { files, depth, path: path8 };
|
|
3414
3372
|
}
|
|
3415
|
-
async _formatEntry(dirent,
|
|
3373
|
+
async _formatEntry(dirent, path8) {
|
|
3416
3374
|
let entry;
|
|
3417
3375
|
const basename3 = this._isDirent ? dirent.name : dirent;
|
|
3418
3376
|
try {
|
|
3419
|
-
const fullPath = presolve(pjoin(
|
|
3377
|
+
const fullPath = presolve(pjoin(path8, basename3));
|
|
3420
3378
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
|
|
3421
3379
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
3422
3380
|
} catch (err) {
|
|
@@ -3816,16 +3774,16 @@ var delFromSet = (main, prop, item) => {
|
|
|
3816
3774
|
};
|
|
3817
3775
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
3818
3776
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
3819
|
-
function createFsWatchInstance(
|
|
3777
|
+
function createFsWatchInstance(path8, options, listener, errHandler, emitRaw) {
|
|
3820
3778
|
const handleEvent = (rawEvent, evPath) => {
|
|
3821
|
-
listener(
|
|
3822
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
3823
|
-
if (evPath &&
|
|
3824
|
-
fsWatchBroadcast(sp.resolve(
|
|
3779
|
+
listener(path8);
|
|
3780
|
+
emitRaw(rawEvent, evPath, { watchedPath: path8 });
|
|
3781
|
+
if (evPath && path8 !== evPath) {
|
|
3782
|
+
fsWatchBroadcast(sp.resolve(path8, evPath), KEY_LISTENERS, sp.join(path8, evPath));
|
|
3825
3783
|
}
|
|
3826
3784
|
};
|
|
3827
3785
|
try {
|
|
3828
|
-
return fs_watch(
|
|
3786
|
+
return fs_watch(path8, {
|
|
3829
3787
|
persistent: options.persistent
|
|
3830
3788
|
}, handleEvent);
|
|
3831
3789
|
} catch (error) {
|
|
@@ -3841,12 +3799,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
3841
3799
|
listener(val1, val2, val3);
|
|
3842
3800
|
});
|
|
3843
3801
|
};
|
|
3844
|
-
var setFsWatchListener = (
|
|
3802
|
+
var setFsWatchListener = (path8, fullPath, options, handlers) => {
|
|
3845
3803
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
3846
3804
|
let cont = FsWatchInstances.get(fullPath);
|
|
3847
3805
|
let watcher;
|
|
3848
3806
|
if (!options.persistent) {
|
|
3849
|
-
watcher = createFsWatchInstance(
|
|
3807
|
+
watcher = createFsWatchInstance(path8, options, listener, errHandler, rawEmitter);
|
|
3850
3808
|
if (!watcher)
|
|
3851
3809
|
return;
|
|
3852
3810
|
return watcher.close.bind(watcher);
|
|
@@ -3857,7 +3815,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
3857
3815
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
3858
3816
|
} else {
|
|
3859
3817
|
watcher = createFsWatchInstance(
|
|
3860
|
-
|
|
3818
|
+
path8,
|
|
3861
3819
|
options,
|
|
3862
3820
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
3863
3821
|
errHandler,
|
|
@@ -3872,7 +3830,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
3872
3830
|
cont.watcherUnusable = true;
|
|
3873
3831
|
if (isWindows && error.code === "EPERM") {
|
|
3874
3832
|
try {
|
|
3875
|
-
const fd = await open(
|
|
3833
|
+
const fd = await open(path8, "r");
|
|
3876
3834
|
await fd.close();
|
|
3877
3835
|
broadcastErr(error);
|
|
3878
3836
|
} catch (err) {
|
|
@@ -3903,7 +3861,7 @@ var setFsWatchListener = (path9, fullPath, options, handlers) => {
|
|
|
3903
3861
|
};
|
|
3904
3862
|
};
|
|
3905
3863
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
3906
|
-
var setFsWatchFileListener = (
|
|
3864
|
+
var setFsWatchFileListener = (path8, fullPath, options, handlers) => {
|
|
3907
3865
|
const { listener, rawEmitter } = handlers;
|
|
3908
3866
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
3909
3867
|
const copts = cont && cont.options;
|
|
@@ -3925,7 +3883,7 @@ var setFsWatchFileListener = (path9, fullPath, options, handlers) => {
|
|
|
3925
3883
|
});
|
|
3926
3884
|
const currmtime = curr.mtimeMs;
|
|
3927
3885
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
3928
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
3886
|
+
foreach(cont.listeners, (listener2) => listener2(path8, curr));
|
|
3929
3887
|
}
|
|
3930
3888
|
})
|
|
3931
3889
|
};
|
|
@@ -3955,13 +3913,13 @@ var NodeFsHandler = class {
|
|
|
3955
3913
|
* @param listener on fs change
|
|
3956
3914
|
* @returns closer for the watcher instance
|
|
3957
3915
|
*/
|
|
3958
|
-
_watchWithNodeFs(
|
|
3916
|
+
_watchWithNodeFs(path8, listener) {
|
|
3959
3917
|
const opts = this.fsw.options;
|
|
3960
|
-
const directory = sp.dirname(
|
|
3961
|
-
const basename3 = sp.basename(
|
|
3918
|
+
const directory = sp.dirname(path8);
|
|
3919
|
+
const basename3 = sp.basename(path8);
|
|
3962
3920
|
const parent = this.fsw._getWatchedDir(directory);
|
|
3963
3921
|
parent.add(basename3);
|
|
3964
|
-
const absolutePath = sp.resolve(
|
|
3922
|
+
const absolutePath = sp.resolve(path8);
|
|
3965
3923
|
const options = {
|
|
3966
3924
|
persistent: opts.persistent
|
|
3967
3925
|
};
|
|
@@ -3971,12 +3929,12 @@ var NodeFsHandler = class {
|
|
|
3971
3929
|
if (opts.usePolling) {
|
|
3972
3930
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
3973
3931
|
options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
|
|
3974
|
-
closer = setFsWatchFileListener(
|
|
3932
|
+
closer = setFsWatchFileListener(path8, absolutePath, options, {
|
|
3975
3933
|
listener,
|
|
3976
3934
|
rawEmitter: this.fsw._emitRaw
|
|
3977
3935
|
});
|
|
3978
3936
|
} else {
|
|
3979
|
-
closer = setFsWatchListener(
|
|
3937
|
+
closer = setFsWatchListener(path8, absolutePath, options, {
|
|
3980
3938
|
listener,
|
|
3981
3939
|
errHandler: this._boundHandleError,
|
|
3982
3940
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -3998,7 +3956,7 @@ var NodeFsHandler = class {
|
|
|
3998
3956
|
let prevStats = stats;
|
|
3999
3957
|
if (parent.has(basename3))
|
|
4000
3958
|
return;
|
|
4001
|
-
const listener = async (
|
|
3959
|
+
const listener = async (path8, newStats) => {
|
|
4002
3960
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
4003
3961
|
return;
|
|
4004
3962
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -4012,11 +3970,11 @@ var NodeFsHandler = class {
|
|
|
4012
3970
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
4013
3971
|
}
|
|
4014
3972
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
4015
|
-
this.fsw._closeFile(
|
|
3973
|
+
this.fsw._closeFile(path8);
|
|
4016
3974
|
prevStats = newStats2;
|
|
4017
3975
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
4018
3976
|
if (closer2)
|
|
4019
|
-
this.fsw._addPathCloser(
|
|
3977
|
+
this.fsw._addPathCloser(path8, closer2);
|
|
4020
3978
|
} else {
|
|
4021
3979
|
prevStats = newStats2;
|
|
4022
3980
|
}
|
|
@@ -4048,7 +4006,7 @@ var NodeFsHandler = class {
|
|
|
4048
4006
|
* @param item basename of this item
|
|
4049
4007
|
* @returns true if no more processing is needed for this entry.
|
|
4050
4008
|
*/
|
|
4051
|
-
async _handleSymlink(entry, directory,
|
|
4009
|
+
async _handleSymlink(entry, directory, path8, item) {
|
|
4052
4010
|
if (this.fsw.closed) {
|
|
4053
4011
|
return;
|
|
4054
4012
|
}
|
|
@@ -4058,7 +4016,7 @@ var NodeFsHandler = class {
|
|
|
4058
4016
|
this.fsw._incrReadyCount();
|
|
4059
4017
|
let linkPath;
|
|
4060
4018
|
try {
|
|
4061
|
-
linkPath = await fsrealpath(
|
|
4019
|
+
linkPath = await fsrealpath(path8);
|
|
4062
4020
|
} catch (e) {
|
|
4063
4021
|
this.fsw._emitReady();
|
|
4064
4022
|
return true;
|
|
@@ -4068,12 +4026,12 @@ var NodeFsHandler = class {
|
|
|
4068
4026
|
if (dir.has(item)) {
|
|
4069
4027
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
4070
4028
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
4071
|
-
this.fsw._emit(EV.CHANGE,
|
|
4029
|
+
this.fsw._emit(EV.CHANGE, path8, entry.stats);
|
|
4072
4030
|
}
|
|
4073
4031
|
} else {
|
|
4074
4032
|
dir.add(item);
|
|
4075
4033
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
4076
|
-
this.fsw._emit(EV.ADD,
|
|
4034
|
+
this.fsw._emit(EV.ADD, path8, entry.stats);
|
|
4077
4035
|
}
|
|
4078
4036
|
this.fsw._emitReady();
|
|
4079
4037
|
return true;
|
|
@@ -4103,9 +4061,9 @@ var NodeFsHandler = class {
|
|
|
4103
4061
|
return;
|
|
4104
4062
|
}
|
|
4105
4063
|
const item = entry.path;
|
|
4106
|
-
let
|
|
4064
|
+
let path8 = sp.join(directory, item);
|
|
4107
4065
|
current.add(item);
|
|
4108
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
4066
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path8, item)) {
|
|
4109
4067
|
return;
|
|
4110
4068
|
}
|
|
4111
4069
|
if (this.fsw.closed) {
|
|
@@ -4114,8 +4072,8 @@ var NodeFsHandler = class {
|
|
|
4114
4072
|
}
|
|
4115
4073
|
if (item === target || !target && !previous.has(item)) {
|
|
4116
4074
|
this.fsw._incrReadyCount();
|
|
4117
|
-
|
|
4118
|
-
this._addToNodeFs(
|
|
4075
|
+
path8 = sp.join(dir, sp.relative(dir, path8));
|
|
4076
|
+
this._addToNodeFs(path8, initialAdd, wh, depth + 1);
|
|
4119
4077
|
}
|
|
4120
4078
|
}).on(EV.ERROR, this._boundHandleError);
|
|
4121
4079
|
return new Promise((resolve4, reject) => {
|
|
@@ -4184,13 +4142,13 @@ var NodeFsHandler = class {
|
|
|
4184
4142
|
* @param depth Child path actually targeted for watch
|
|
4185
4143
|
* @param target Child path actually targeted for watch
|
|
4186
4144
|
*/
|
|
4187
|
-
async _addToNodeFs(
|
|
4145
|
+
async _addToNodeFs(path8, initialAdd, priorWh, depth, target) {
|
|
4188
4146
|
const ready = this.fsw._emitReady;
|
|
4189
|
-
if (this.fsw._isIgnored(
|
|
4147
|
+
if (this.fsw._isIgnored(path8) || this.fsw.closed) {
|
|
4190
4148
|
ready();
|
|
4191
4149
|
return false;
|
|
4192
4150
|
}
|
|
4193
|
-
const wh = this.fsw._getWatchHelpers(
|
|
4151
|
+
const wh = this.fsw._getWatchHelpers(path8);
|
|
4194
4152
|
if (priorWh) {
|
|
4195
4153
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
4196
4154
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -4206,8 +4164,8 @@ var NodeFsHandler = class {
|
|
|
4206
4164
|
const follow = this.fsw.options.followSymlinks;
|
|
4207
4165
|
let closer;
|
|
4208
4166
|
if (stats.isDirectory()) {
|
|
4209
|
-
const absPath = sp.resolve(
|
|
4210
|
-
const targetPath = follow ? await fsrealpath(
|
|
4167
|
+
const absPath = sp.resolve(path8);
|
|
4168
|
+
const targetPath = follow ? await fsrealpath(path8) : path8;
|
|
4211
4169
|
if (this.fsw.closed)
|
|
4212
4170
|
return;
|
|
4213
4171
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -4217,29 +4175,29 @@ var NodeFsHandler = class {
|
|
|
4217
4175
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
4218
4176
|
}
|
|
4219
4177
|
} else if (stats.isSymbolicLink()) {
|
|
4220
|
-
const targetPath = follow ? await fsrealpath(
|
|
4178
|
+
const targetPath = follow ? await fsrealpath(path8) : path8;
|
|
4221
4179
|
if (this.fsw.closed)
|
|
4222
4180
|
return;
|
|
4223
4181
|
const parent = sp.dirname(wh.watchPath);
|
|
4224
4182
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
4225
4183
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
4226
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
4184
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path8, wh, targetPath);
|
|
4227
4185
|
if (this.fsw.closed)
|
|
4228
4186
|
return;
|
|
4229
4187
|
if (targetPath !== void 0) {
|
|
4230
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
4188
|
+
this.fsw._symlinkPaths.set(sp.resolve(path8), targetPath);
|
|
4231
4189
|
}
|
|
4232
4190
|
} else {
|
|
4233
4191
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
4234
4192
|
}
|
|
4235
4193
|
ready();
|
|
4236
4194
|
if (closer)
|
|
4237
|
-
this.fsw._addPathCloser(
|
|
4195
|
+
this.fsw._addPathCloser(path8, closer);
|
|
4238
4196
|
return false;
|
|
4239
4197
|
} catch (error) {
|
|
4240
4198
|
if (this.fsw._handleError(error)) {
|
|
4241
4199
|
ready();
|
|
4242
|
-
return
|
|
4200
|
+
return path8;
|
|
4243
4201
|
}
|
|
4244
4202
|
}
|
|
4245
4203
|
}
|
|
@@ -4282,24 +4240,24 @@ function createPattern(matcher) {
|
|
|
4282
4240
|
}
|
|
4283
4241
|
return () => false;
|
|
4284
4242
|
}
|
|
4285
|
-
function normalizePath(
|
|
4286
|
-
if (typeof
|
|
4243
|
+
function normalizePath(path8) {
|
|
4244
|
+
if (typeof path8 !== "string")
|
|
4287
4245
|
throw new Error("string expected");
|
|
4288
|
-
|
|
4289
|
-
|
|
4246
|
+
path8 = sp2.normalize(path8);
|
|
4247
|
+
path8 = path8.replace(/\\/g, "/");
|
|
4290
4248
|
let prepend = false;
|
|
4291
|
-
if (
|
|
4249
|
+
if (path8.startsWith("//"))
|
|
4292
4250
|
prepend = true;
|
|
4293
|
-
|
|
4251
|
+
path8 = path8.replace(DOUBLE_SLASH_RE, "/");
|
|
4294
4252
|
if (prepend)
|
|
4295
|
-
|
|
4296
|
-
return
|
|
4253
|
+
path8 = "/" + path8;
|
|
4254
|
+
return path8;
|
|
4297
4255
|
}
|
|
4298
4256
|
function matchPatterns(patterns, testString, stats) {
|
|
4299
|
-
const
|
|
4257
|
+
const path8 = normalizePath(testString);
|
|
4300
4258
|
for (let index = 0; index < patterns.length; index++) {
|
|
4301
4259
|
const pattern = patterns[index];
|
|
4302
|
-
if (pattern(
|
|
4260
|
+
if (pattern(path8, stats)) {
|
|
4303
4261
|
return true;
|
|
4304
4262
|
}
|
|
4305
4263
|
}
|
|
@@ -4337,19 +4295,19 @@ var toUnix = (string) => {
|
|
|
4337
4295
|
}
|
|
4338
4296
|
return str;
|
|
4339
4297
|
};
|
|
4340
|
-
var normalizePathToUnix = (
|
|
4341
|
-
var normalizeIgnored = (cwd = "") => (
|
|
4342
|
-
if (typeof
|
|
4343
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
4298
|
+
var normalizePathToUnix = (path8) => toUnix(sp2.normalize(toUnix(path8)));
|
|
4299
|
+
var normalizeIgnored = (cwd = "") => (path8) => {
|
|
4300
|
+
if (typeof path8 === "string") {
|
|
4301
|
+
return normalizePathToUnix(sp2.isAbsolute(path8) ? path8 : sp2.join(cwd, path8));
|
|
4344
4302
|
} else {
|
|
4345
|
-
return
|
|
4303
|
+
return path8;
|
|
4346
4304
|
}
|
|
4347
4305
|
};
|
|
4348
|
-
var getAbsolutePath = (
|
|
4349
|
-
if (sp2.isAbsolute(
|
|
4350
|
-
return
|
|
4306
|
+
var getAbsolutePath = (path8, cwd) => {
|
|
4307
|
+
if (sp2.isAbsolute(path8)) {
|
|
4308
|
+
return path8;
|
|
4351
4309
|
}
|
|
4352
|
-
return sp2.join(cwd,
|
|
4310
|
+
return sp2.join(cwd, path8);
|
|
4353
4311
|
};
|
|
4354
4312
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
4355
4313
|
var DirEntry = class {
|
|
@@ -4414,10 +4372,10 @@ var WatchHelper = class {
|
|
|
4414
4372
|
dirParts;
|
|
4415
4373
|
followSymlinks;
|
|
4416
4374
|
statMethod;
|
|
4417
|
-
constructor(
|
|
4375
|
+
constructor(path8, follow, fsw) {
|
|
4418
4376
|
this.fsw = fsw;
|
|
4419
|
-
const watchPath =
|
|
4420
|
-
this.path =
|
|
4377
|
+
const watchPath = path8;
|
|
4378
|
+
this.path = path8 = path8.replace(REPLACER_RE, "");
|
|
4421
4379
|
this.watchPath = watchPath;
|
|
4422
4380
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
4423
4381
|
this.dirParts = [];
|
|
@@ -4557,20 +4515,20 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4557
4515
|
this._closePromise = void 0;
|
|
4558
4516
|
let paths = unifyPaths(paths_);
|
|
4559
4517
|
if (cwd) {
|
|
4560
|
-
paths = paths.map((
|
|
4561
|
-
const absPath = getAbsolutePath(
|
|
4518
|
+
paths = paths.map((path8) => {
|
|
4519
|
+
const absPath = getAbsolutePath(path8, cwd);
|
|
4562
4520
|
return absPath;
|
|
4563
4521
|
});
|
|
4564
4522
|
}
|
|
4565
|
-
paths.forEach((
|
|
4566
|
-
this._removeIgnoredPath(
|
|
4523
|
+
paths.forEach((path8) => {
|
|
4524
|
+
this._removeIgnoredPath(path8);
|
|
4567
4525
|
});
|
|
4568
4526
|
this._userIgnored = void 0;
|
|
4569
4527
|
if (!this._readyCount)
|
|
4570
4528
|
this._readyCount = 0;
|
|
4571
4529
|
this._readyCount += paths.length;
|
|
4572
|
-
Promise.all(paths.map(async (
|
|
4573
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
4530
|
+
Promise.all(paths.map(async (path8) => {
|
|
4531
|
+
const res = await this._nodeFsHandler._addToNodeFs(path8, !_internal, void 0, 0, _origAdd);
|
|
4574
4532
|
if (res)
|
|
4575
4533
|
this._emitReady();
|
|
4576
4534
|
return res;
|
|
@@ -4592,17 +4550,17 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4592
4550
|
return this;
|
|
4593
4551
|
const paths = unifyPaths(paths_);
|
|
4594
4552
|
const { cwd } = this.options;
|
|
4595
|
-
paths.forEach((
|
|
4596
|
-
if (!sp2.isAbsolute(
|
|
4553
|
+
paths.forEach((path8) => {
|
|
4554
|
+
if (!sp2.isAbsolute(path8) && !this._closers.has(path8)) {
|
|
4597
4555
|
if (cwd)
|
|
4598
|
-
|
|
4599
|
-
|
|
4556
|
+
path8 = sp2.join(cwd, path8);
|
|
4557
|
+
path8 = sp2.resolve(path8);
|
|
4600
4558
|
}
|
|
4601
|
-
this._closePath(
|
|
4602
|
-
this._addIgnoredPath(
|
|
4603
|
-
if (this._watched.has(
|
|
4559
|
+
this._closePath(path8);
|
|
4560
|
+
this._addIgnoredPath(path8);
|
|
4561
|
+
if (this._watched.has(path8)) {
|
|
4604
4562
|
this._addIgnoredPath({
|
|
4605
|
-
path:
|
|
4563
|
+
path: path8,
|
|
4606
4564
|
recursive: true
|
|
4607
4565
|
});
|
|
4608
4566
|
}
|
|
@@ -4666,38 +4624,38 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4666
4624
|
* @param stats arguments to be passed with event
|
|
4667
4625
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
4668
4626
|
*/
|
|
4669
|
-
async _emit(event,
|
|
4627
|
+
async _emit(event, path8, stats) {
|
|
4670
4628
|
if (this.closed)
|
|
4671
4629
|
return;
|
|
4672
4630
|
const opts = this.options;
|
|
4673
4631
|
if (isWindows)
|
|
4674
|
-
|
|
4632
|
+
path8 = sp2.normalize(path8);
|
|
4675
4633
|
if (opts.cwd)
|
|
4676
|
-
|
|
4677
|
-
const args = [
|
|
4634
|
+
path8 = sp2.relative(opts.cwd, path8);
|
|
4635
|
+
const args = [path8];
|
|
4678
4636
|
if (stats != null)
|
|
4679
4637
|
args.push(stats);
|
|
4680
4638
|
const awf = opts.awaitWriteFinish;
|
|
4681
4639
|
let pw;
|
|
4682
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
4640
|
+
if (awf && (pw = this._pendingWrites.get(path8))) {
|
|
4683
4641
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
4684
4642
|
return this;
|
|
4685
4643
|
}
|
|
4686
4644
|
if (opts.atomic) {
|
|
4687
4645
|
if (event === EVENTS.UNLINK) {
|
|
4688
|
-
this._pendingUnlinks.set(
|
|
4646
|
+
this._pendingUnlinks.set(path8, [event, ...args]);
|
|
4689
4647
|
setTimeout(() => {
|
|
4690
|
-
this._pendingUnlinks.forEach((entry,
|
|
4648
|
+
this._pendingUnlinks.forEach((entry, path9) => {
|
|
4691
4649
|
this.emit(...entry);
|
|
4692
4650
|
this.emit(EVENTS.ALL, ...entry);
|
|
4693
|
-
this._pendingUnlinks.delete(
|
|
4651
|
+
this._pendingUnlinks.delete(path9);
|
|
4694
4652
|
});
|
|
4695
4653
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
4696
4654
|
return this;
|
|
4697
4655
|
}
|
|
4698
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
4656
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path8)) {
|
|
4699
4657
|
event = EVENTS.CHANGE;
|
|
4700
|
-
this._pendingUnlinks.delete(
|
|
4658
|
+
this._pendingUnlinks.delete(path8);
|
|
4701
4659
|
}
|
|
4702
4660
|
}
|
|
4703
4661
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -4715,16 +4673,16 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4715
4673
|
this.emitWithAll(event, args);
|
|
4716
4674
|
}
|
|
4717
4675
|
};
|
|
4718
|
-
this._awaitWriteFinish(
|
|
4676
|
+
this._awaitWriteFinish(path8, awf.stabilityThreshold, event, awfEmit);
|
|
4719
4677
|
return this;
|
|
4720
4678
|
}
|
|
4721
4679
|
if (event === EVENTS.CHANGE) {
|
|
4722
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
4680
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path8, 50);
|
|
4723
4681
|
if (isThrottled)
|
|
4724
4682
|
return this;
|
|
4725
4683
|
}
|
|
4726
4684
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
4727
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
4685
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path8) : path8;
|
|
4728
4686
|
let stats2;
|
|
4729
4687
|
try {
|
|
4730
4688
|
stats2 = await stat3(fullPath);
|
|
@@ -4755,23 +4713,23 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4755
4713
|
* @param timeout duration of time to suppress duplicate actions
|
|
4756
4714
|
* @returns tracking object or false if action should be suppressed
|
|
4757
4715
|
*/
|
|
4758
|
-
_throttle(actionType,
|
|
4716
|
+
_throttle(actionType, path8, timeout) {
|
|
4759
4717
|
if (!this._throttled.has(actionType)) {
|
|
4760
4718
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
4761
4719
|
}
|
|
4762
4720
|
const action = this._throttled.get(actionType);
|
|
4763
4721
|
if (!action)
|
|
4764
4722
|
throw new Error("invalid throttle");
|
|
4765
|
-
const actionPath = action.get(
|
|
4723
|
+
const actionPath = action.get(path8);
|
|
4766
4724
|
if (actionPath) {
|
|
4767
4725
|
actionPath.count++;
|
|
4768
4726
|
return false;
|
|
4769
4727
|
}
|
|
4770
4728
|
let timeoutObject;
|
|
4771
4729
|
const clear = () => {
|
|
4772
|
-
const item = action.get(
|
|
4730
|
+
const item = action.get(path8);
|
|
4773
4731
|
const count = item ? item.count : 0;
|
|
4774
|
-
action.delete(
|
|
4732
|
+
action.delete(path8);
|
|
4775
4733
|
clearTimeout(timeoutObject);
|
|
4776
4734
|
if (item)
|
|
4777
4735
|
clearTimeout(item.timeoutObject);
|
|
@@ -4779,7 +4737,7 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4779
4737
|
};
|
|
4780
4738
|
timeoutObject = setTimeout(clear, timeout);
|
|
4781
4739
|
const thr = { timeoutObject, clear, count: 0 };
|
|
4782
|
-
action.set(
|
|
4740
|
+
action.set(path8, thr);
|
|
4783
4741
|
return thr;
|
|
4784
4742
|
}
|
|
4785
4743
|
_incrReadyCount() {
|
|
@@ -4793,44 +4751,44 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4793
4751
|
* @param event
|
|
4794
4752
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
4795
4753
|
*/
|
|
4796
|
-
_awaitWriteFinish(
|
|
4754
|
+
_awaitWriteFinish(path8, threshold, event, awfEmit) {
|
|
4797
4755
|
const awf = this.options.awaitWriteFinish;
|
|
4798
4756
|
if (typeof awf !== "object")
|
|
4799
4757
|
return;
|
|
4800
4758
|
const pollInterval = awf.pollInterval;
|
|
4801
4759
|
let timeoutHandler;
|
|
4802
|
-
let fullPath =
|
|
4803
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
4804
|
-
fullPath = sp2.join(this.options.cwd,
|
|
4760
|
+
let fullPath = path8;
|
|
4761
|
+
if (this.options.cwd && !sp2.isAbsolute(path8)) {
|
|
4762
|
+
fullPath = sp2.join(this.options.cwd, path8);
|
|
4805
4763
|
}
|
|
4806
4764
|
const now = /* @__PURE__ */ new Date();
|
|
4807
4765
|
const writes = this._pendingWrites;
|
|
4808
4766
|
function awaitWriteFinishFn(prevStat) {
|
|
4809
4767
|
statcb(fullPath, (err, curStat) => {
|
|
4810
|
-
if (err || !writes.has(
|
|
4768
|
+
if (err || !writes.has(path8)) {
|
|
4811
4769
|
if (err && err.code !== "ENOENT")
|
|
4812
4770
|
awfEmit(err);
|
|
4813
4771
|
return;
|
|
4814
4772
|
}
|
|
4815
4773
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
4816
4774
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
4817
|
-
writes.get(
|
|
4775
|
+
writes.get(path8).lastChange = now2;
|
|
4818
4776
|
}
|
|
4819
|
-
const pw = writes.get(
|
|
4777
|
+
const pw = writes.get(path8);
|
|
4820
4778
|
const df = now2 - pw.lastChange;
|
|
4821
4779
|
if (df >= threshold) {
|
|
4822
|
-
writes.delete(
|
|
4780
|
+
writes.delete(path8);
|
|
4823
4781
|
awfEmit(void 0, curStat);
|
|
4824
4782
|
} else {
|
|
4825
4783
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
4826
4784
|
}
|
|
4827
4785
|
});
|
|
4828
4786
|
}
|
|
4829
|
-
if (!writes.has(
|
|
4830
|
-
writes.set(
|
|
4787
|
+
if (!writes.has(path8)) {
|
|
4788
|
+
writes.set(path8, {
|
|
4831
4789
|
lastChange: now,
|
|
4832
4790
|
cancelWait: () => {
|
|
4833
|
-
writes.delete(
|
|
4791
|
+
writes.delete(path8);
|
|
4834
4792
|
clearTimeout(timeoutHandler);
|
|
4835
4793
|
return event;
|
|
4836
4794
|
}
|
|
@@ -4841,8 +4799,8 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4841
4799
|
/**
|
|
4842
4800
|
* Determines whether user has asked to ignore this path.
|
|
4843
4801
|
*/
|
|
4844
|
-
_isIgnored(
|
|
4845
|
-
if (this.options.atomic && DOT_RE.test(
|
|
4802
|
+
_isIgnored(path8, stats) {
|
|
4803
|
+
if (this.options.atomic && DOT_RE.test(path8))
|
|
4846
4804
|
return true;
|
|
4847
4805
|
if (!this._userIgnored) {
|
|
4848
4806
|
const { cwd } = this.options;
|
|
@@ -4852,17 +4810,17 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4852
4810
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
4853
4811
|
this._userIgnored = anymatch(list, void 0);
|
|
4854
4812
|
}
|
|
4855
|
-
return this._userIgnored(
|
|
4813
|
+
return this._userIgnored(path8, stats);
|
|
4856
4814
|
}
|
|
4857
|
-
_isntIgnored(
|
|
4858
|
-
return !this._isIgnored(
|
|
4815
|
+
_isntIgnored(path8, stat4) {
|
|
4816
|
+
return !this._isIgnored(path8, stat4);
|
|
4859
4817
|
}
|
|
4860
4818
|
/**
|
|
4861
4819
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
4862
4820
|
* @param path file or directory pattern being watched
|
|
4863
4821
|
*/
|
|
4864
|
-
_getWatchHelpers(
|
|
4865
|
-
return new WatchHelper(
|
|
4822
|
+
_getWatchHelpers(path8) {
|
|
4823
|
+
return new WatchHelper(path8, this.options.followSymlinks, this);
|
|
4866
4824
|
}
|
|
4867
4825
|
// Directory helpers
|
|
4868
4826
|
// -----------------
|
|
@@ -4894,63 +4852,63 @@ var FSWatcher = class extends EventEmitter2 {
|
|
|
4894
4852
|
* @param item base path of item/directory
|
|
4895
4853
|
*/
|
|
4896
4854
|
_remove(directory, item, isDirectory) {
|
|
4897
|
-
const
|
|
4898
|
-
const fullPath = sp2.resolve(
|
|
4899
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
4900
|
-
if (!this._throttle("remove",
|
|
4855
|
+
const path8 = sp2.join(directory, item);
|
|
4856
|
+
const fullPath = sp2.resolve(path8);
|
|
4857
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path8) || this._watched.has(fullPath);
|
|
4858
|
+
if (!this._throttle("remove", path8, 100))
|
|
4901
4859
|
return;
|
|
4902
4860
|
if (!isDirectory && this._watched.size === 1) {
|
|
4903
4861
|
this.add(directory, item, true);
|
|
4904
4862
|
}
|
|
4905
|
-
const wp = this._getWatchedDir(
|
|
4863
|
+
const wp = this._getWatchedDir(path8);
|
|
4906
4864
|
const nestedDirectoryChildren = wp.getChildren();
|
|
4907
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
4865
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path8, nested));
|
|
4908
4866
|
const parent = this._getWatchedDir(directory);
|
|
4909
4867
|
const wasTracked = parent.has(item);
|
|
4910
4868
|
parent.remove(item);
|
|
4911
4869
|
if (this._symlinkPaths.has(fullPath)) {
|
|
4912
4870
|
this._symlinkPaths.delete(fullPath);
|
|
4913
4871
|
}
|
|
4914
|
-
let relPath =
|
|
4872
|
+
let relPath = path8;
|
|
4915
4873
|
if (this.options.cwd)
|
|
4916
|
-
relPath = sp2.relative(this.options.cwd,
|
|
4874
|
+
relPath = sp2.relative(this.options.cwd, path8);
|
|
4917
4875
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
4918
4876
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
4919
4877
|
if (event === EVENTS.ADD)
|
|
4920
4878
|
return;
|
|
4921
4879
|
}
|
|
4922
|
-
this._watched.delete(
|
|
4880
|
+
this._watched.delete(path8);
|
|
4923
4881
|
this._watched.delete(fullPath);
|
|
4924
4882
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
4925
|
-
if (wasTracked && !this._isIgnored(
|
|
4926
|
-
this._emit(eventName,
|
|
4927
|
-
this._closePath(
|
|
4883
|
+
if (wasTracked && !this._isIgnored(path8))
|
|
4884
|
+
this._emit(eventName, path8);
|
|
4885
|
+
this._closePath(path8);
|
|
4928
4886
|
}
|
|
4929
4887
|
/**
|
|
4930
4888
|
* Closes all watchers for a path
|
|
4931
4889
|
*/
|
|
4932
|
-
_closePath(
|
|
4933
|
-
this._closeFile(
|
|
4934
|
-
const dir = sp2.dirname(
|
|
4935
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
4890
|
+
_closePath(path8) {
|
|
4891
|
+
this._closeFile(path8);
|
|
4892
|
+
const dir = sp2.dirname(path8);
|
|
4893
|
+
this._getWatchedDir(dir).remove(sp2.basename(path8));
|
|
4936
4894
|
}
|
|
4937
4895
|
/**
|
|
4938
4896
|
* Closes only file-specific watchers
|
|
4939
4897
|
*/
|
|
4940
|
-
_closeFile(
|
|
4941
|
-
const closers = this._closers.get(
|
|
4898
|
+
_closeFile(path8) {
|
|
4899
|
+
const closers = this._closers.get(path8);
|
|
4942
4900
|
if (!closers)
|
|
4943
4901
|
return;
|
|
4944
4902
|
closers.forEach((closer) => closer());
|
|
4945
|
-
this._closers.delete(
|
|
4903
|
+
this._closers.delete(path8);
|
|
4946
4904
|
}
|
|
4947
|
-
_addPathCloser(
|
|
4905
|
+
_addPathCloser(path8, closer) {
|
|
4948
4906
|
if (!closer)
|
|
4949
4907
|
return;
|
|
4950
|
-
let list = this._closers.get(
|
|
4908
|
+
let list = this._closers.get(path8);
|
|
4951
4909
|
if (!list) {
|
|
4952
4910
|
list = [];
|
|
4953
|
-
this._closers.set(
|
|
4911
|
+
this._closers.set(path8, list);
|
|
4954
4912
|
}
|
|
4955
4913
|
list.push(closer);
|
|
4956
4914
|
}
|
|
@@ -4980,7 +4938,7 @@ function watch(paths, options = {}) {
|
|
|
4980
4938
|
var chokidar_default = { watch, FSWatcher };
|
|
4981
4939
|
|
|
4982
4940
|
// src/watcher/index.ts
|
|
4983
|
-
import * as
|
|
4941
|
+
import * as path6 from "path";
|
|
4984
4942
|
var FileWatcher = class {
|
|
4985
4943
|
watcher = null;
|
|
4986
4944
|
projectRoot;
|
|
@@ -5001,7 +4959,7 @@ var FileWatcher = class {
|
|
|
5001
4959
|
const ignoreFilter = createIgnoreFilter(this.projectRoot);
|
|
5002
4960
|
this.watcher = chokidar_default.watch(this.projectRoot, {
|
|
5003
4961
|
ignored: (filePath) => {
|
|
5004
|
-
const relativePath =
|
|
4962
|
+
const relativePath = path6.relative(this.projectRoot, filePath);
|
|
5005
4963
|
if (!relativePath) return false;
|
|
5006
4964
|
if (ignoreFilter.ignores(relativePath)) {
|
|
5007
4965
|
return true;
|
|
@@ -5045,7 +5003,7 @@ var FileWatcher = class {
|
|
|
5045
5003
|
return;
|
|
5046
5004
|
}
|
|
5047
5005
|
const changes = Array.from(this.pendingChanges.entries()).map(
|
|
5048
|
-
([
|
|
5006
|
+
([path8, type]) => ({ path: path8, type })
|
|
5049
5007
|
);
|
|
5050
5008
|
this.pendingChanges.clear();
|
|
5051
5009
|
try {
|
|
@@ -5237,10 +5195,10 @@ function formatStatus(status) {
|
|
|
5237
5195
|
|
|
5238
5196
|
// src/index.ts
|
|
5239
5197
|
function loadPluginConfig(projectRoot) {
|
|
5240
|
-
const configPath =
|
|
5198
|
+
const configPath = path7.join(projectRoot, ".opencode", "codebase-index.json");
|
|
5241
5199
|
try {
|
|
5242
5200
|
if (existsSync5(configPath)) {
|
|
5243
|
-
const content =
|
|
5201
|
+
const content = readFileSync5(configPath, "utf-8");
|
|
5244
5202
|
return JSON.parse(content);
|
|
5245
5203
|
}
|
|
5246
5204
|
} catch {
|