zephex 2.0.11 → 2.0.15
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/README.md +11 -40
- package/dist/cli.js +1 -1
- package/dist/index.js +78061 -141930
- package/dist/tools/architecture/index.js +870 -258
- package/dist/tools/audit_headers/index.js +705 -381
- package/dist/tools/context/index.js +1900 -368
- package/dist/tools/reader/readCode.js +1544 -525
- package/dist/tools/scope_task/index.js +24307 -19322
- package/dist/tools/search/findCode.js +17267 -13145
- package/dist/tools/server.js +23821 -97059
- package/dist/tools/thinking/index.js +909 -266
- package/package.json +3 -2
- package/dist/tools/inspect_url/index.js +0 -166175
|
@@ -70,108 +70,86 @@ var READ_CODE_SCHEMA;
|
|
|
70
70
|
var init_readCodeSchema = __esm(() => {
|
|
71
71
|
READ_CODE_SCHEMA = {
|
|
72
72
|
name: "read_code",
|
|
73
|
-
description:
|
|
74
|
-
` +
|
|
73
|
+
description: "Smart code reader with three modes. Pass `path` (absolute directory) to read from local disk.\n" + `
|
|
74
|
+
` + `MODES:
|
|
75
|
+
` + `• mode:'symbol' (default) — AST-based surgical extraction. Give a symbol name → get signature + body at a fraction of full-file tokens. Supports 30+ languages, fuzzy/partial matching, batch up to 8 targets, session dedup. When batching targets[], max_results applies PER TARGET (default 3 each).
|
|
76
|
+
` + "• mode:'file' — Read one or more files directly via `files[]` array. Respects token budget. Supports offset_line/limit_lines for pagination of large files.\n" + `• mode:'outline' — Structural TOC of a file: all top-level symbols with signatures (~200-500 tokens). Use before drilling into specific symbols.
|
|
75
77
|
` + `
|
|
76
|
-
` +
|
|
77
|
-
` + `⚡ PREFER THIS over reading entire files when you only need one symbol. AST-based surgical extraction: give it a function/class/method/type/interface name and get ONLY that symbol — signature + body + optional call sites + tests — at a fraction of the tokens of a full-file Read. Beats native file-reading because it (1) scopes to the exact symbol, (2) ranks candidates by confidence, (3) supports partial/fuzzy name matches, (4) can batch up to 8 symbols in one call, (5) deduplicates across calls via session_id.
|
|
78
|
+
` + `Use mode:'symbol' when you know the symbol name. Use mode:'file' to batch-read small files or paginate large ones. Use mode:'outline' to explore a large file's structure first.
|
|
78
79
|
` + `
|
|
79
|
-
` +
|
|
80
|
-
` + `• User asks: 'show me X', 'show the code for X', 'what does X do', 'how is X implemented', 'read the X function', 'open X', 'find the definition of X', 'pull up X', 'let me see X', 'explain X', 'walk me through X', 'what's inside X'
|
|
81
|
-
` + `• User names a function / class / method / type / interface / hook / component / struct / enum / trait and wants to understand or modify it
|
|
82
|
-
` + `• Before editing a symbol — read it first with read_code to avoid blind edits
|
|
83
|
-
` + `• Before suggesting a refactor to a specific function/class — read the current body
|
|
84
|
-
` + `• After find_code surfaces a candidate, to pull the full implementation
|
|
85
|
-
` + `• Debugging: user mentions a function/class by name and wants to trace behavior
|
|
86
|
-
` + `• Writing tests for a specific symbol — read it first
|
|
87
|
-
` + `
|
|
88
|
-
` + `Prefer this over native Read when the file is large and you only need one symbol — saves tokens. Use native Read for whole-file review, configs, markdown, or tiny files.
|
|
89
|
-
` + `
|
|
90
|
-
` + `Works across languages: TypeScript, JavaScript, TSX/JSX, Python, Go, Rust, Java, Kotlin, Swift, Ruby, PHP, C#, C, C++, Scala — AST where supported, graceful fallback otherwise.
|
|
91
|
-
` + `
|
|
92
|
-
` + "Use detail_level='signature' to pre-screen, 'body' (default) to read/edit, 'context' for body+imports. Batch via targets[] when inspecting several related symbols. In local stdio mode, pass `path` and let the MCP tool read from disk. Use `inline_files` only as a remote fallback, or a GitHub URL for remote repos.",
|
|
80
|
+
` + "NOT for: images/binaries, editing files, running code, or searching (use find_code). For whole-file review of tiny files, native Read may be simpler.",
|
|
93
81
|
inputSchema: {
|
|
94
82
|
type: "object",
|
|
95
83
|
properties: {
|
|
96
84
|
target: {
|
|
97
85
|
type: "string",
|
|
98
|
-
description: "Symbol name to find
|
|
86
|
+
description: "Symbol name to find (for mode:'symbol'). Supports partial/fuzzy matching. " + 'Examples: "validateToken", "UserService", "auth" matches "handleAuth".'
|
|
87
|
+
},
|
|
88
|
+
symbol_id: {
|
|
89
|
+
type: "string",
|
|
90
|
+
description: "Stable symbol ID for direct lookup (e.g. 'src/auth.ts::hashApiKey#function'). Bypasses fuzzy matching."
|
|
99
91
|
},
|
|
100
92
|
targets: {
|
|
101
93
|
type: "array",
|
|
102
94
|
items: { type: "string" },
|
|
103
95
|
maxItems: 8,
|
|
104
|
-
description: "Additional
|
|
96
|
+
description: "Additional symbols to batch-search (max 8). Results merged and deduped."
|
|
105
97
|
},
|
|
106
|
-
|
|
98
|
+
mode: {
|
|
107
99
|
type: "string",
|
|
108
|
-
enum: ["
|
|
109
|
-
description: "
|
|
100
|
+
enum: ["symbol", "file", "outline", "callers", "blast_radius", "dead_code"],
|
|
101
|
+
description: "symbol (default): AST extraction of named symbols. " + "file: read files directly via `files[]` array. " + "outline: structural TOC of a file. " + "callers: who calls this symbol (requires index). " + "blast_radius: transitive dependents of a symbol. " + "dead_code: exported symbols never called."
|
|
102
|
+
},
|
|
103
|
+
files: {
|
|
104
|
+
type: "array",
|
|
105
|
+
items: { type: "string" },
|
|
106
|
+
maxItems: 20,
|
|
107
|
+
description: "For mode:'file' or mode:'outline'. Relative file paths to read (e.g. ['src/auth.ts', 'src/db.ts']). " + "Reads within token budget; returns as many as fit."
|
|
108
|
+
},
|
|
109
|
+
offset_line: {
|
|
110
|
+
type: "number",
|
|
111
|
+
description: "For mode:'file'. Start reading from this line (1-indexed). Default: 1."
|
|
110
112
|
},
|
|
111
|
-
|
|
113
|
+
limit_lines: {
|
|
114
|
+
type: "number",
|
|
115
|
+
description: "For mode:'file'. Max lines to return per file. Default: unlimited (bounded by max_tokens)."
|
|
116
|
+
},
|
|
117
|
+
compact: {
|
|
118
|
+
type: "boolean",
|
|
119
|
+
description: "When true, omit line numbers and minimize whitespace in output to save tokens."
|
|
120
|
+
},
|
|
121
|
+
kind: {
|
|
112
122
|
type: "string",
|
|
113
|
-
|
|
123
|
+
enum: ["function", "class", "method", "interface", "type", "variable", "struct", "enum", "trait", "protocol", "module", "namespace", "hook", "component", "decorator", "macro"],
|
|
124
|
+
description: "Filter results to only this symbol kind. Use to disambiguate (e.g., class vs method with same name)."
|
|
114
125
|
},
|
|
115
126
|
path: {
|
|
116
127
|
type: "string",
|
|
117
|
-
description: "Absolute
|
|
118
|
-
},
|
|
119
|
-
inline_files: {
|
|
120
|
-
type: "object",
|
|
121
|
-
description: 'Remote fallback only. Shape: { "<relative/path>": "<FULL FILE CONTENTS>" }. ' + "The VALUE is the actual file body — never a filename, path, or placeholder. " + 'Example: { "src/auth.ts": "import jwt from \\"jsonwebtoken\\";\\nexport function validateToken(...) { ... }" }. ' + "Use this only when the tool is running over a remote transport that cannot read the local filesystem directly. In local stdio mode, prefer `path` so the MCP tool reads from disk itself. " + "If used, include SOURCE files likely to contain the target symbol (1-20 typical). Never ship only package.json/tsconfig.json.",
|
|
122
|
-
additionalProperties: { type: "string" }
|
|
128
|
+
description: "Absolute project directory (e.g. /Users/alice/myapp). Also accepts GitHub/GitLab URLs."
|
|
123
129
|
},
|
|
124
130
|
detail_level: {
|
|
125
131
|
type: "string",
|
|
126
132
|
enum: ["signature", "body", "context"],
|
|
127
|
-
description: "signature: name
|
|
133
|
+
description: "signature: name+params+return (~100 tokens). body: full implementation (default). context: body+imports."
|
|
128
134
|
},
|
|
129
135
|
max_tokens: {
|
|
130
136
|
type: "number",
|
|
131
|
-
description: "
|
|
137
|
+
description: "Token budget for output. Default 2000, max 8000. Increase for large classes."
|
|
132
138
|
},
|
|
133
139
|
max_results: {
|
|
134
140
|
type: "number",
|
|
135
|
-
description: "
|
|
141
|
+
description: "Max symbols to return. Default 3, max 10."
|
|
136
142
|
},
|
|
137
143
|
confidence_threshold: {
|
|
138
144
|
type: "number",
|
|
139
|
-
description: "
|
|
140
|
-
},
|
|
141
|
-
include_usages: {
|
|
142
|
-
type: "boolean",
|
|
143
|
-
description: "Include up to 10 locations where this symbol is called or referenced. " + "Uses ripgrep on the exact symbol name — accurate for reference search. " + "Adds ~100-300 tokens. Use when you need to understand call sites."
|
|
144
|
-
},
|
|
145
|
-
include_tests: {
|
|
146
|
-
type: "boolean",
|
|
147
|
-
description: "Include paths of test files that appear to test this symbol. " + "Adds minimal tokens (~20-50). Useful to know if tests exist before making changes."
|
|
145
|
+
description: "Min confidence 0.0-1.0. Default 0.5. Raise to 0.8 for exact matches, lower to 0.3 for exploration."
|
|
148
146
|
},
|
|
149
147
|
session_id: {
|
|
150
148
|
type: "string",
|
|
151
|
-
description: "Session
|
|
152
|
-
},
|
|
153
|
-
max_lines: {
|
|
154
|
-
type: "number",
|
|
155
|
-
description: "DEPRECATED: Use max_tokens instead. Mapped internally to max_tokens estimate."
|
|
156
|
-
},
|
|
157
|
-
include_callers: {
|
|
158
|
-
type: "boolean",
|
|
159
|
-
description: "DEPRECATED: Silently ignored. Use Claude Code LSP for call graphs."
|
|
160
|
-
},
|
|
161
|
-
include_callees: {
|
|
162
|
-
type: "boolean",
|
|
163
|
-
description: "DEPRECATED: Silently ignored. Use Claude Code LSP for call graphs."
|
|
164
|
-
},
|
|
165
|
-
expand_types: {
|
|
166
|
-
type: "boolean",
|
|
167
|
-
description: "DEPRECATED: Use detail_level: 'context' instead."
|
|
168
|
-
},
|
|
169
|
-
include_imports: {
|
|
170
|
-
type: "boolean",
|
|
171
|
-
description: "DEPRECATED: Use detail_level: 'context' instead."
|
|
149
|
+
description: "Session ID for dedup. Previously-returned symbols get a stub instead of full body."
|
|
172
150
|
}
|
|
173
151
|
},
|
|
174
|
-
required: [
|
|
152
|
+
required: []
|
|
175
153
|
},
|
|
176
154
|
annotations: {
|
|
177
155
|
readOnlyHint: true,
|
|
@@ -182,6 +160,55 @@ var init_readCodeSchema = __esm(() => {
|
|
|
182
160
|
};
|
|
183
161
|
});
|
|
184
162
|
|
|
163
|
+
// src/tools/reader/diagnostics.ts
|
|
164
|
+
function computeDiagnostics(body2, paramCount) {
|
|
165
|
+
const lines = body2.split(`
|
|
166
|
+
`);
|
|
167
|
+
const lineCount = lines.length;
|
|
168
|
+
let complexity = 1;
|
|
169
|
+
const branchPatterns = /\b(if|else if|for|while|do|case|catch)\b|\?\?|&&|\|\||\?[^:.?]/g;
|
|
170
|
+
let match;
|
|
171
|
+
while ((match = branchPatterns.exec(body2)) !== null)
|
|
172
|
+
complexity++;
|
|
173
|
+
let maxDepth = 0;
|
|
174
|
+
let currentDepth = 0;
|
|
175
|
+
for (const char of body2) {
|
|
176
|
+
if (char === "{") {
|
|
177
|
+
currentDepth++;
|
|
178
|
+
if (currentDepth > maxDepth)
|
|
179
|
+
maxDepth = currentDepth;
|
|
180
|
+
} else if (char === "}")
|
|
181
|
+
currentDepth--;
|
|
182
|
+
}
|
|
183
|
+
const hasErrorHandling = /\btry\s*\{/.test(body2);
|
|
184
|
+
const hasEmptyCatch = /catch\s*\([^)]*\)\s*\{\s*(\/\/[^\n]*)?\s*\}/.test(body2);
|
|
185
|
+
const isAsync = /\basync\b/.test(body2);
|
|
186
|
+
const callCount = (body2.match(/\w+\s*\(/g) || []).length;
|
|
187
|
+
const flags2 = [];
|
|
188
|
+
if (lineCount > 100)
|
|
189
|
+
flags2.push("long_function");
|
|
190
|
+
if (maxDepth > 4)
|
|
191
|
+
flags2.push("deeply_nested");
|
|
192
|
+
if (paramCount > 5)
|
|
193
|
+
flags2.push("too_many_params");
|
|
194
|
+
if (complexity > 10)
|
|
195
|
+
flags2.push("high_complexity");
|
|
196
|
+
if (isAsync && !hasErrorHandling)
|
|
197
|
+
flags2.push("missing_error_handling");
|
|
198
|
+
if (hasEmptyCatch)
|
|
199
|
+
flags2.push("empty_catch");
|
|
200
|
+
if (callCount > 15)
|
|
201
|
+
flags2.push("god_function");
|
|
202
|
+
return {
|
|
203
|
+
flags: flags2,
|
|
204
|
+
complexity,
|
|
205
|
+
nesting_depth: maxDepth,
|
|
206
|
+
param_count: paramCount,
|
|
207
|
+
line_count: lineCount,
|
|
208
|
+
has_error_handling: hasErrorHandling
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
185
212
|
// src/tools/shared/source-detection.ts
|
|
186
213
|
function baseName(path) {
|
|
187
214
|
const parts2 = path.split("/");
|
|
@@ -883,80 +910,54 @@ var init_git_resolver = __esm(() => {
|
|
|
883
910
|
};
|
|
884
911
|
});
|
|
885
912
|
|
|
886
|
-
// node_modules/.bun/lru-cache@11.
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
913
|
+
// node_modules/.bun/lru-cache@11.3.5/node_modules/lru-cache/dist/esm/node/index.min.js
|
|
914
|
+
import { tracingChannel as j, channel as I } from "node:diagnostics_channel";
|
|
915
|
+
var S, W, D = () => S.hasSubscribers || W.hasSubscribers, G, M, C2, P = (u, e, t, i2) => {
|
|
916
|
+
typeof C2.emitWarning == "function" ? C2.emitWarning(u, e, t, i2) : console.error(`[${t}] ${e}: ${u}`);
|
|
917
|
+
}, H = (u) => !M.has(u), $, F = (u) => !!u && u === Math.floor(u) && u > 0 && isFinite(u), U = (u) => F(u) ? u <= Math.pow(2, 8) ? Uint8Array : u <= Math.pow(2, 16) ? Uint16Array : u <= Math.pow(2, 32) ? Uint32Array : u <= Number.MAX_SAFE_INTEGER ? O : null : null, O, R = class u {
|
|
890
918
|
heap;
|
|
891
919
|
length;
|
|
892
920
|
static #o = false;
|
|
893
|
-
static create(
|
|
894
|
-
let
|
|
895
|
-
if (!
|
|
921
|
+
static create(e) {
|
|
922
|
+
let t = U(e);
|
|
923
|
+
if (!t)
|
|
896
924
|
return [];
|
|
897
|
-
|
|
898
|
-
let i2 = new
|
|
899
|
-
return
|
|
925
|
+
u.#o = true;
|
|
926
|
+
let i2 = new u(e, t);
|
|
927
|
+
return u.#o = false, i2;
|
|
900
928
|
}
|
|
901
|
-
constructor(
|
|
902
|
-
if (!
|
|
929
|
+
constructor(e, t) {
|
|
930
|
+
if (!u.#o)
|
|
903
931
|
throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
904
|
-
this.heap = new e
|
|
932
|
+
this.heap = new t(e), this.length = 0;
|
|
905
933
|
}
|
|
906
|
-
push(
|
|
907
|
-
this.heap[this.length++] =
|
|
934
|
+
push(e) {
|
|
935
|
+
this.heap[this.length++] = e;
|
|
908
936
|
}
|
|
909
937
|
pop() {
|
|
910
938
|
return this.heap[--this.length];
|
|
911
939
|
}
|
|
912
940
|
}, L;
|
|
913
941
|
var init_index_min = __esm(() => {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
reason;
|
|
924
|
-
aborted = false;
|
|
925
|
-
addEventListener(i2, s) {
|
|
926
|
-
this._onabort.push(s);
|
|
927
|
-
}
|
|
928
|
-
}, C2 = class {
|
|
929
|
-
constructor() {
|
|
930
|
-
t();
|
|
931
|
-
}
|
|
932
|
-
signal = new D;
|
|
933
|
-
abort(i2) {
|
|
934
|
-
if (!this.signal.aborted) {
|
|
935
|
-
this.signal.reason = i2, this.signal.aborted = true;
|
|
936
|
-
for (let s of this.signal._onabort)
|
|
937
|
-
s(i2);
|
|
938
|
-
this.signal.onabort?.(i2);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
let c = R.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = () => {
|
|
943
|
-
c && (c = false, U("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", t));
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
H = Symbol("type");
|
|
947
|
-
z = class extends Array {
|
|
948
|
-
constructor(t) {
|
|
949
|
-
super(t), this.fill(0);
|
|
942
|
+
S = I("lru-cache:metrics");
|
|
943
|
+
W = j("lru-cache");
|
|
944
|
+
G = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
|
|
945
|
+
M = new Set;
|
|
946
|
+
C2 = typeof process == "object" && process ? process : {};
|
|
947
|
+
$ = Symbol("type");
|
|
948
|
+
O = class extends Array {
|
|
949
|
+
constructor(e) {
|
|
950
|
+
super(e), this.fill(0);
|
|
950
951
|
}
|
|
951
952
|
};
|
|
952
|
-
L = class
|
|
953
|
+
L = class u2 {
|
|
953
954
|
#o;
|
|
954
|
-
#
|
|
955
|
+
#u;
|
|
955
956
|
#w;
|
|
956
|
-
#
|
|
957
|
+
#D;
|
|
957
958
|
#S;
|
|
958
|
-
#
|
|
959
|
-
#
|
|
959
|
+
#M;
|
|
960
|
+
#U;
|
|
960
961
|
#m;
|
|
961
962
|
get perf() {
|
|
962
963
|
return this.#m;
|
|
@@ -977,486 +978,537 @@ var init_index_min = __esm(() => {
|
|
|
977
978
|
allowStaleOnFetchRejection;
|
|
978
979
|
ignoreFetchAbort;
|
|
979
980
|
#n;
|
|
980
|
-
#
|
|
981
|
+
#b;
|
|
981
982
|
#s;
|
|
982
983
|
#i;
|
|
983
984
|
#t;
|
|
984
985
|
#a;
|
|
985
|
-
#
|
|
986
|
+
#c;
|
|
986
987
|
#l;
|
|
987
988
|
#h;
|
|
988
|
-
#b;
|
|
989
|
-
#r;
|
|
990
989
|
#y;
|
|
991
|
-
#
|
|
990
|
+
#r;
|
|
991
|
+
#_;
|
|
992
|
+
#F;
|
|
992
993
|
#d;
|
|
993
994
|
#g;
|
|
994
995
|
#T;
|
|
995
|
-
#
|
|
996
|
+
#W;
|
|
996
997
|
#f;
|
|
997
|
-
#
|
|
998
|
-
static unsafeExposeInternals(
|
|
999
|
-
return { starts:
|
|
1000
|
-
return
|
|
998
|
+
#j;
|
|
999
|
+
static unsafeExposeInternals(e) {
|
|
1000
|
+
return { starts: e.#F, ttls: e.#d, autopurgeTimers: e.#g, sizes: e.#_, keyMap: e.#s, keyList: e.#i, valList: e.#t, next: e.#a, prev: e.#c, get head() {
|
|
1001
|
+
return e.#l;
|
|
1001
1002
|
}, get tail() {
|
|
1002
|
-
return
|
|
1003
|
-
}, free:
|
|
1003
|
+
return e.#h;
|
|
1004
|
+
}, free: e.#y, isBackgroundFetch: (t) => e.#e(t), backgroundFetch: (t, i2, s, n) => e.#P(t, i2, s, n), moveToTail: (t) => e.#L(t), indexes: (t) => e.#A(t), rindexes: (t) => e.#z(t), isStale: (t) => e.#p(t) };
|
|
1004
1005
|
}
|
|
1005
1006
|
get max() {
|
|
1006
1007
|
return this.#o;
|
|
1007
1008
|
}
|
|
1008
1009
|
get maxSize() {
|
|
1009
|
-
return this.#
|
|
1010
|
+
return this.#u;
|
|
1010
1011
|
}
|
|
1011
1012
|
get calculatedSize() {
|
|
1012
|
-
return this.#
|
|
1013
|
+
return this.#b;
|
|
1013
1014
|
}
|
|
1014
1015
|
get size() {
|
|
1015
1016
|
return this.#n;
|
|
1016
1017
|
}
|
|
1017
1018
|
get fetchMethod() {
|
|
1018
|
-
return this.#
|
|
1019
|
+
return this.#M;
|
|
1019
1020
|
}
|
|
1020
1021
|
get memoMethod() {
|
|
1021
|
-
return this.#
|
|
1022
|
+
return this.#U;
|
|
1022
1023
|
}
|
|
1023
1024
|
get dispose() {
|
|
1024
1025
|
return this.#w;
|
|
1025
1026
|
}
|
|
1026
1027
|
get onInsert() {
|
|
1027
|
-
return this.#
|
|
1028
|
+
return this.#D;
|
|
1028
1029
|
}
|
|
1029
1030
|
get disposeAfter() {
|
|
1030
1031
|
return this.#S;
|
|
1031
1032
|
}
|
|
1032
|
-
constructor(
|
|
1033
|
-
let { max:
|
|
1034
|
-
if (
|
|
1033
|
+
constructor(e) {
|
|
1034
|
+
let { max: t = 0, ttl: i2, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: r, allowStale: h, dispose: l, onInsert: c, disposeAfter: f, noDisposeOnSet: g, noUpdateTTL: p, maxSize: T = 0, maxEntrySize: w = 0, sizeCalculation: y, fetchMethod: a, memoMethod: m, noDeleteOnFetchRejection: _, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: A, ignoreFetchAbort: z, perf: x } = e;
|
|
1035
|
+
if (x !== undefined && typeof x?.now != "function")
|
|
1035
1036
|
throw new TypeError("perf option must have a now() method if specified");
|
|
1036
|
-
if (this.#m =
|
|
1037
|
+
if (this.#m = x ?? G, t !== 0 && !F(t))
|
|
1037
1038
|
throw new TypeError("max option must be a nonnegative integer");
|
|
1038
|
-
let
|
|
1039
|
-
if (!
|
|
1040
|
-
throw new Error("invalid max value: " +
|
|
1041
|
-
if (this.#o =
|
|
1042
|
-
if (!this.#
|
|
1039
|
+
let v = t ? U(t) : Array;
|
|
1040
|
+
if (!v)
|
|
1041
|
+
throw new Error("invalid max value: " + t);
|
|
1042
|
+
if (this.#o = t, this.#u = T, this.maxEntrySize = w || this.#u, this.sizeCalculation = y, this.sizeCalculation) {
|
|
1043
|
+
if (!this.#u && !this.maxEntrySize)
|
|
1043
1044
|
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
1044
1045
|
if (typeof this.sizeCalculation != "function")
|
|
1045
1046
|
throw new TypeError("sizeCalculation set to non-function");
|
|
1046
1047
|
}
|
|
1047
|
-
if (
|
|
1048
|
+
if (m !== undefined && typeof m != "function")
|
|
1048
1049
|
throw new TypeError("memoMethod must be a function if defined");
|
|
1049
|
-
if (this.#
|
|
1050
|
+
if (this.#U = m, a !== undefined && typeof a != "function")
|
|
1050
1051
|
throw new TypeError("fetchMethod must be a function if specified");
|
|
1051
|
-
if (this.#
|
|
1052
|
-
if (this.#
|
|
1052
|
+
if (this.#M = a, this.#W = !!a, this.#s = new Map, this.#i = Array.from({ length: t }).fill(undefined), this.#t = Array.from({ length: t }).fill(undefined), this.#a = new v(t), this.#c = new v(t), this.#l = 0, this.#h = 0, this.#y = R.create(t), this.#n = 0, this.#b = 0, typeof l == "function" && (this.#w = l), typeof c == "function" && (this.#D = c), typeof f == "function" ? (this.#S = f, this.#r = []) : (this.#S = undefined, this.#r = undefined), this.#T = !!this.#w, this.#j = !!this.#D, this.#f = !!this.#S, this.noDisposeOnSet = !!g, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!_, this.allowStaleOnFetchRejection = !!d, this.allowStaleOnFetchAbort = !!A, this.ignoreFetchAbort = !!z, this.maxEntrySize !== 0) {
|
|
1053
|
+
if (this.#u !== 0 && !F(this.#u))
|
|
1053
1054
|
throw new TypeError("maxSize must be a positive integer if specified");
|
|
1054
|
-
if (!
|
|
1055
|
+
if (!F(this.maxEntrySize))
|
|
1055
1056
|
throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
1056
|
-
this.#
|
|
1057
|
+
this.#X();
|
|
1057
1058
|
}
|
|
1058
|
-
if (this.allowStale = !!
|
|
1059
|
-
if (!
|
|
1059
|
+
if (this.allowStale = !!h, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!r, this.ttlResolution = F(s) || s === 0 ? s : 1, this.ttlAutopurge = !!n, this.ttl = i2 || 0, this.ttl) {
|
|
1060
|
+
if (!F(this.ttl))
|
|
1060
1061
|
throw new TypeError("ttl must be a positive integer if specified");
|
|
1061
|
-
this.#
|
|
1062
|
+
this.#H();
|
|
1062
1063
|
}
|
|
1063
|
-
if (this.#o === 0 && this.ttl === 0 && this.#
|
|
1064
|
+
if (this.#o === 0 && this.ttl === 0 && this.#u === 0)
|
|
1064
1065
|
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
1065
|
-
if (!this.ttlAutopurge && !this.#o && !this.#
|
|
1066
|
+
if (!this.ttlAutopurge && !this.#o && !this.#u) {
|
|
1066
1067
|
let E = "LRU_CACHE_UNBOUNDED";
|
|
1067
|
-
|
|
1068
|
+
H(E) && (M.add(E), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, u2));
|
|
1068
1069
|
}
|
|
1069
1070
|
}
|
|
1070
|
-
getRemainingTTL(
|
|
1071
|
-
return this.#s.has(
|
|
1072
|
-
}
|
|
1073
|
-
#
|
|
1074
|
-
let
|
|
1075
|
-
this.#d =
|
|
1076
|
-
let i2 = this.ttlAutopurge ?
|
|
1077
|
-
this.#g = i2, this.#N = (
|
|
1078
|
-
|
|
1079
|
-
}, this.#
|
|
1080
|
-
|
|
1071
|
+
getRemainingTTL(e) {
|
|
1072
|
+
return this.#s.has(e) ? 1 / 0 : 0;
|
|
1073
|
+
}
|
|
1074
|
+
#H() {
|
|
1075
|
+
let e = new O(this.#o), t = new O(this.#o);
|
|
1076
|
+
this.#d = e, this.#F = t;
|
|
1077
|
+
let i2 = this.ttlAutopurge ? Array.from({ length: this.#o }) : undefined;
|
|
1078
|
+
this.#g = i2, this.#N = (r, h, l = this.#m.now()) => {
|
|
1079
|
+
t[r] = h !== 0 ? l : 0, e[r] = h, s(r, h);
|
|
1080
|
+
}, this.#x = (r) => {
|
|
1081
|
+
t[r] = e[r] !== 0 ? this.#m.now() : 0, s(r, e[r]);
|
|
1081
1082
|
};
|
|
1082
|
-
let s = this.ttlAutopurge ? (
|
|
1083
|
-
if (i2?.[
|
|
1084
|
-
let
|
|
1085
|
-
this.#p(
|
|
1086
|
-
},
|
|
1087
|
-
|
|
1083
|
+
let s = this.ttlAutopurge ? (r, h) => {
|
|
1084
|
+
if (i2?.[r] && (clearTimeout(i2[r]), i2[r] = undefined), h && h !== 0 && i2) {
|
|
1085
|
+
let l = setTimeout(() => {
|
|
1086
|
+
this.#p(r) && this.#v(this.#i[r], "expire");
|
|
1087
|
+
}, h + 1);
|
|
1088
|
+
l.unref && l.unref(), i2[r] = l;
|
|
1088
1089
|
}
|
|
1089
1090
|
} : () => {};
|
|
1090
|
-
this.#
|
|
1091
|
-
if (
|
|
1092
|
-
let
|
|
1093
|
-
if (!
|
|
1091
|
+
this.#E = (r, h) => {
|
|
1092
|
+
if (e[h]) {
|
|
1093
|
+
let l = e[h], c = t[h];
|
|
1094
|
+
if (!l || !c)
|
|
1094
1095
|
return;
|
|
1095
|
-
|
|
1096
|
-
let f =
|
|
1097
|
-
|
|
1096
|
+
r.ttl = l, r.start = c, r.now = n || o();
|
|
1097
|
+
let f = r.now - c;
|
|
1098
|
+
r.remainingTTL = l - f;
|
|
1098
1099
|
}
|
|
1099
1100
|
};
|
|
1100
1101
|
let n = 0, o = () => {
|
|
1101
|
-
let
|
|
1102
|
+
let r = this.#m.now();
|
|
1102
1103
|
if (this.ttlResolution > 0) {
|
|
1103
|
-
n =
|
|
1104
|
-
let
|
|
1105
|
-
|
|
1104
|
+
n = r;
|
|
1105
|
+
let h = setTimeout(() => n = 0, this.ttlResolution);
|
|
1106
|
+
h.unref && h.unref();
|
|
1106
1107
|
}
|
|
1107
|
-
return
|
|
1108
|
+
return r;
|
|
1108
1109
|
};
|
|
1109
|
-
this.getRemainingTTL = (
|
|
1110
|
-
let
|
|
1111
|
-
if (
|
|
1110
|
+
this.getRemainingTTL = (r) => {
|
|
1111
|
+
let h = this.#s.get(r);
|
|
1112
|
+
if (h === undefined)
|
|
1112
1113
|
return 0;
|
|
1113
|
-
let
|
|
1114
|
-
if (!
|
|
1114
|
+
let l = e[h], c = t[h];
|
|
1115
|
+
if (!l || !c)
|
|
1115
1116
|
return 1 / 0;
|
|
1116
|
-
let f = (n || o()) -
|
|
1117
|
-
return
|
|
1118
|
-
}, this.#p = (
|
|
1119
|
-
let
|
|
1120
|
-
return !!
|
|
1117
|
+
let f = (n || o()) - c;
|
|
1118
|
+
return l - f;
|
|
1119
|
+
}, this.#p = (r) => {
|
|
1120
|
+
let h = t[r], l = e[r];
|
|
1121
|
+
return !!l && !!h && (n || o()) - h > l;
|
|
1121
1122
|
};
|
|
1122
1123
|
}
|
|
1123
|
-
#
|
|
1124
|
-
#
|
|
1124
|
+
#x = () => {};
|
|
1125
|
+
#E = () => {};
|
|
1125
1126
|
#N = () => {};
|
|
1126
1127
|
#p = () => false;
|
|
1127
|
-
#
|
|
1128
|
-
let
|
|
1129
|
-
this.#
|
|
1130
|
-
this.#
|
|
1131
|
-
}, this.#
|
|
1128
|
+
#X() {
|
|
1129
|
+
let e = new O(this.#o);
|
|
1130
|
+
this.#b = 0, this.#_ = e, this.#R = (t) => {
|
|
1131
|
+
this.#b -= e[t], e[t] = 0;
|
|
1132
|
+
}, this.#k = (t, i2, s, n) => {
|
|
1132
1133
|
if (this.#e(i2))
|
|
1133
1134
|
return 0;
|
|
1134
|
-
if (!
|
|
1135
|
+
if (!F(s))
|
|
1135
1136
|
if (n) {
|
|
1136
1137
|
if (typeof n != "function")
|
|
1137
1138
|
throw new TypeError("sizeCalculation must be a function");
|
|
1138
|
-
if (s = n(i2,
|
|
1139
|
+
if (s = n(i2, t), !F(s))
|
|
1139
1140
|
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
1140
1141
|
} else
|
|
1141
1142
|
throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
1142
1143
|
return s;
|
|
1143
|
-
}, this.#
|
|
1144
|
-
if (t
|
|
1145
|
-
let n = this.#
|
|
1146
|
-
for (;this.#
|
|
1147
|
-
this.#
|
|
1144
|
+
}, this.#I = (t, i2, s) => {
|
|
1145
|
+
if (e[t] = i2, this.#u) {
|
|
1146
|
+
let n = this.#u - e[t];
|
|
1147
|
+
for (;this.#b > n; )
|
|
1148
|
+
this.#G(true);
|
|
1148
1149
|
}
|
|
1149
|
-
this.#
|
|
1150
|
+
this.#b += e[t], s && (s.entrySize = i2, s.totalCalculatedSize = this.#b);
|
|
1150
1151
|
};
|
|
1151
1152
|
}
|
|
1152
|
-
#
|
|
1153
|
-
#
|
|
1154
|
-
#
|
|
1153
|
+
#R = (e) => {};
|
|
1154
|
+
#I = (e, t, i2) => {};
|
|
1155
|
+
#k = (e, t, i2, s) => {
|
|
1155
1156
|
if (i2 || s)
|
|
1156
1157
|
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
1157
1158
|
return 0;
|
|
1158
1159
|
};
|
|
1159
|
-
*#
|
|
1160
|
+
*#A({ allowStale: e = this.allowStale } = {}) {
|
|
1160
1161
|
if (this.#n)
|
|
1161
|
-
for (let
|
|
1162
|
-
|
|
1162
|
+
for (let t = this.#h;this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#l); )
|
|
1163
|
+
t = this.#c[t];
|
|
1163
1164
|
}
|
|
1164
|
-
*#
|
|
1165
|
+
*#z({ allowStale: e = this.allowStale } = {}) {
|
|
1165
1166
|
if (this.#n)
|
|
1166
|
-
for (let
|
|
1167
|
-
|
|
1167
|
+
for (let t = this.#l;this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#h); )
|
|
1168
|
+
t = this.#a[t];
|
|
1168
1169
|
}
|
|
1169
|
-
#
|
|
1170
|
-
return
|
|
1170
|
+
#V(e) {
|
|
1171
|
+
return e !== undefined && this.#s.get(this.#i[e]) === e;
|
|
1171
1172
|
}
|
|
1172
1173
|
*entries() {
|
|
1173
|
-
for (let
|
|
1174
|
-
this.#t[
|
|
1174
|
+
for (let e of this.#A())
|
|
1175
|
+
this.#t[e] !== undefined && this.#i[e] !== undefined && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
|
|
1175
1176
|
}
|
|
1176
1177
|
*rentries() {
|
|
1177
|
-
for (let
|
|
1178
|
-
this.#t[
|
|
1178
|
+
for (let e of this.#z())
|
|
1179
|
+
this.#t[e] !== undefined && this.#i[e] !== undefined && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
|
|
1179
1180
|
}
|
|
1180
1181
|
*keys() {
|
|
1181
|
-
for (let
|
|
1182
|
-
let
|
|
1183
|
-
|
|
1182
|
+
for (let e of this.#A()) {
|
|
1183
|
+
let t = this.#i[e];
|
|
1184
|
+
t !== undefined && !this.#e(this.#t[e]) && (yield t);
|
|
1184
1185
|
}
|
|
1185
1186
|
}
|
|
1186
1187
|
*rkeys() {
|
|
1187
|
-
for (let
|
|
1188
|
-
let
|
|
1189
|
-
|
|
1188
|
+
for (let e of this.#z()) {
|
|
1189
|
+
let t = this.#i[e];
|
|
1190
|
+
t !== undefined && !this.#e(this.#t[e]) && (yield t);
|
|
1190
1191
|
}
|
|
1191
1192
|
}
|
|
1192
1193
|
*values() {
|
|
1193
|
-
for (let
|
|
1194
|
-
this.#t[
|
|
1194
|
+
for (let e of this.#A())
|
|
1195
|
+
this.#t[e] !== undefined && !this.#e(this.#t[e]) && (yield this.#t[e]);
|
|
1195
1196
|
}
|
|
1196
1197
|
*rvalues() {
|
|
1197
|
-
for (let
|
|
1198
|
-
this.#t[
|
|
1198
|
+
for (let e of this.#z())
|
|
1199
|
+
this.#t[e] !== undefined && !this.#e(this.#t[e]) && (yield this.#t[e]);
|
|
1199
1200
|
}
|
|
1200
1201
|
[Symbol.iterator]() {
|
|
1201
1202
|
return this.entries();
|
|
1202
1203
|
}
|
|
1203
1204
|
[Symbol.toStringTag] = "LRUCache";
|
|
1204
|
-
find(
|
|
1205
|
-
for (let i2 of this.#
|
|
1205
|
+
find(e, t = {}) {
|
|
1206
|
+
for (let i2 of this.#A()) {
|
|
1206
1207
|
let s = this.#t[i2], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
1207
|
-
if (n !== undefined &&
|
|
1208
|
-
return this
|
|
1208
|
+
if (n !== undefined && e(n, this.#i[i2], this))
|
|
1209
|
+
return this.#C(this.#i[i2], t);
|
|
1209
1210
|
}
|
|
1210
1211
|
}
|
|
1211
|
-
forEach(
|
|
1212
|
-
for (let i2 of this.#
|
|
1212
|
+
forEach(e, t = this) {
|
|
1213
|
+
for (let i2 of this.#A()) {
|
|
1213
1214
|
let s = this.#t[i2], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
1214
|
-
n !== undefined &&
|
|
1215
|
+
n !== undefined && e.call(t, n, this.#i[i2], this);
|
|
1215
1216
|
}
|
|
1216
1217
|
}
|
|
1217
|
-
rforEach(
|
|
1218
|
-
for (let i2 of this.#
|
|
1218
|
+
rforEach(e, t = this) {
|
|
1219
|
+
for (let i2 of this.#z()) {
|
|
1219
1220
|
let s = this.#t[i2], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
1220
|
-
n !== undefined &&
|
|
1221
|
+
n !== undefined && e.call(t, n, this.#i[i2], this);
|
|
1221
1222
|
}
|
|
1222
1223
|
}
|
|
1223
1224
|
purgeStale() {
|
|
1224
|
-
let
|
|
1225
|
-
for (let
|
|
1226
|
-
this.#p(
|
|
1227
|
-
return
|
|
1228
|
-
}
|
|
1229
|
-
info(
|
|
1230
|
-
let
|
|
1231
|
-
if (
|
|
1225
|
+
let e = false;
|
|
1226
|
+
for (let t of this.#z({ allowStale: true }))
|
|
1227
|
+
this.#p(t) && (this.#v(this.#i[t], "expire"), e = true);
|
|
1228
|
+
return e;
|
|
1229
|
+
}
|
|
1230
|
+
info(e) {
|
|
1231
|
+
let t = this.#s.get(e);
|
|
1232
|
+
if (t === undefined)
|
|
1232
1233
|
return;
|
|
1233
|
-
let i2 = this.#t[
|
|
1234
|
+
let i2 = this.#t[t], s = this.#e(i2) ? i2.__staleWhileFetching : i2;
|
|
1234
1235
|
if (s === undefined)
|
|
1235
1236
|
return;
|
|
1236
1237
|
let n = { value: s };
|
|
1237
|
-
if (this.#d && this.#
|
|
1238
|
-
let o = this.#d[
|
|
1239
|
-
if (o &&
|
|
1240
|
-
let
|
|
1241
|
-
n.ttl =
|
|
1238
|
+
if (this.#d && this.#F) {
|
|
1239
|
+
let o = this.#d[t], r = this.#F[t];
|
|
1240
|
+
if (o && r) {
|
|
1241
|
+
let h = o - (this.#m.now() - r);
|
|
1242
|
+
n.ttl = h, n.start = Date.now();
|
|
1242
1243
|
}
|
|
1243
1244
|
}
|
|
1244
|
-
return this.#
|
|
1245
|
+
return this.#_ && (n.size = this.#_[t]), n;
|
|
1245
1246
|
}
|
|
1246
1247
|
dump() {
|
|
1247
|
-
let
|
|
1248
|
-
for (let
|
|
1249
|
-
let i2 = this.#i[
|
|
1248
|
+
let e = [];
|
|
1249
|
+
for (let t of this.#A({ allowStale: true })) {
|
|
1250
|
+
let i2 = this.#i[t], s = this.#t[t], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
1250
1251
|
if (n === undefined || i2 === undefined)
|
|
1251
1252
|
continue;
|
|
1252
1253
|
let o = { value: n };
|
|
1253
|
-
if (this.#d && this.#
|
|
1254
|
-
o.ttl = this.#d[
|
|
1255
|
-
let
|
|
1256
|
-
o.start = Math.floor(Date.now() -
|
|
1254
|
+
if (this.#d && this.#F) {
|
|
1255
|
+
o.ttl = this.#d[t];
|
|
1256
|
+
let r = this.#m.now() - this.#F[t];
|
|
1257
|
+
o.start = Math.floor(Date.now() - r);
|
|
1257
1258
|
}
|
|
1258
|
-
this.#
|
|
1259
|
+
this.#_ && (o.size = this.#_[t]), e.unshift([i2, o]);
|
|
1259
1260
|
}
|
|
1260
|
-
return
|
|
1261
|
+
return e;
|
|
1261
1262
|
}
|
|
1262
|
-
load(
|
|
1263
|
+
load(e) {
|
|
1263
1264
|
this.clear();
|
|
1264
|
-
for (let [
|
|
1265
|
+
for (let [t, i2] of e) {
|
|
1265
1266
|
if (i2.start) {
|
|
1266
1267
|
let s = Date.now() - i2.start;
|
|
1267
1268
|
i2.start = this.#m.now() - s;
|
|
1268
1269
|
}
|
|
1269
|
-
this
|
|
1270
|
+
this.#O(t, i2.value, i2);
|
|
1270
1271
|
}
|
|
1271
1272
|
}
|
|
1272
|
-
set(
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
let
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1273
|
+
set(e, t, i2 = {}) {
|
|
1274
|
+
let { status: s = S.hasSubscribers ? {} : undefined } = i2;
|
|
1275
|
+
i2.status = s, s && (s.op = "set", s.key = e, t !== undefined && (s.value = t));
|
|
1276
|
+
let n = this.#O(e, t, i2);
|
|
1277
|
+
return s && S.hasSubscribers && S.publish(s), n;
|
|
1278
|
+
}
|
|
1279
|
+
#O(e, t, i2 = {}) {
|
|
1280
|
+
let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: r = this.sizeCalculation, status: h } = i2;
|
|
1281
|
+
if (t === undefined)
|
|
1282
|
+
return h && (h.set = "deleted"), this.delete(e), this;
|
|
1283
|
+
let { noUpdateTTL: l = this.noUpdateTTL } = i2;
|
|
1284
|
+
h && !this.#e(t) && (h.value = t);
|
|
1285
|
+
let c = this.#k(e, t, i2.size || 0, r, h);
|
|
1286
|
+
if (this.maxEntrySize && c > this.maxEntrySize)
|
|
1287
|
+
return this.#v(e, "set"), h && (h.set = "miss", h.maxEntrySizeExceeded = true), this;
|
|
1288
|
+
let f = this.#n === 0 ? undefined : this.#s.get(e);
|
|
1279
1289
|
if (f === undefined)
|
|
1280
|
-
f = this.#n === 0 ? this.#h : this.#
|
|
1290
|
+
f = this.#n === 0 ? this.#h : this.#y.length !== 0 ? this.#y.pop() : this.#n === this.#o ? this.#G(false) : this.#n, this.#i[f] = e, this.#t[f] = t, this.#s.set(e, f), this.#a[this.#h] = f, this.#c[f] = this.#h, this.#h = f, this.#n++, this.#I(f, c, h), h && (h.set = "add"), l = false, this.#j && this.#D?.(t, e, "add");
|
|
1281
1291
|
else {
|
|
1282
|
-
this.#
|
|
1283
|
-
let
|
|
1284
|
-
if (
|
|
1285
|
-
if (this.#
|
|
1286
|
-
|
|
1287
|
-
let { __staleWhileFetching:
|
|
1288
|
-
|
|
1292
|
+
this.#L(f);
|
|
1293
|
+
let g = this.#t[f];
|
|
1294
|
+
if (t !== g) {
|
|
1295
|
+
if (this.#W && this.#e(g)) {
|
|
1296
|
+
g.__abortController.abort(new Error("replaced"));
|
|
1297
|
+
let { __staleWhileFetching: p } = g;
|
|
1298
|
+
p !== undefined && !o && (this.#T && this.#w?.(p, e, "set"), this.#f && this.#r?.push([p, e, "set"]));
|
|
1289
1299
|
} else
|
|
1290
|
-
o || (this.#T && this.#w?.(
|
|
1291
|
-
if (this.#
|
|
1292
|
-
|
|
1293
|
-
let
|
|
1294
|
-
|
|
1300
|
+
o || (this.#T && this.#w?.(g, e, "set"), this.#f && this.#r?.push([g, e, "set"]));
|
|
1301
|
+
if (this.#R(f), this.#I(f, c, h), this.#t[f] = t, h) {
|
|
1302
|
+
h.set = "replace";
|
|
1303
|
+
let p = g && this.#e(g) ? g.__staleWhileFetching : g;
|
|
1304
|
+
p !== undefined && (h.oldValue = p);
|
|
1295
1305
|
}
|
|
1296
1306
|
} else
|
|
1297
|
-
|
|
1298
|
-
this.#
|
|
1307
|
+
h && (h.set = "update");
|
|
1308
|
+
this.#j && this.onInsert?.(t, e, t === g ? "update" : "replace");
|
|
1299
1309
|
}
|
|
1300
|
-
if (s !== 0 && !this.#d && this.#
|
|
1301
|
-
let
|
|
1302
|
-
for (;
|
|
1303
|
-
this.#S?.(...
|
|
1310
|
+
if (s !== 0 && !this.#d && this.#H(), this.#d && (l || this.#N(f, s, n), h && this.#E(h, f)), !o && this.#f && this.#r) {
|
|
1311
|
+
let g = this.#r, p;
|
|
1312
|
+
for (;p = g?.shift(); )
|
|
1313
|
+
this.#S?.(...p);
|
|
1304
1314
|
}
|
|
1305
1315
|
return this;
|
|
1306
1316
|
}
|
|
1307
1317
|
pop() {
|
|
1308
1318
|
try {
|
|
1309
1319
|
for (;this.#n; ) {
|
|
1310
|
-
let
|
|
1311
|
-
if (this.#
|
|
1312
|
-
if (
|
|
1313
|
-
return
|
|
1314
|
-
} else if (
|
|
1315
|
-
return
|
|
1320
|
+
let e = this.#t[this.#l];
|
|
1321
|
+
if (this.#G(true), this.#e(e)) {
|
|
1322
|
+
if (e.__staleWhileFetching)
|
|
1323
|
+
return e.__staleWhileFetching;
|
|
1324
|
+
} else if (e !== undefined)
|
|
1325
|
+
return e;
|
|
1316
1326
|
}
|
|
1317
1327
|
} finally {
|
|
1318
1328
|
if (this.#f && this.#r) {
|
|
1319
|
-
let
|
|
1320
|
-
for (;
|
|
1321
|
-
this.#S?.(...
|
|
1329
|
+
let e = this.#r, t;
|
|
1330
|
+
for (;t = e?.shift(); )
|
|
1331
|
+
this.#S?.(...t);
|
|
1322
1332
|
}
|
|
1323
1333
|
}
|
|
1324
1334
|
}
|
|
1325
|
-
#
|
|
1326
|
-
let
|
|
1327
|
-
return this.#
|
|
1335
|
+
#G(e) {
|
|
1336
|
+
let t = this.#l, i2 = this.#i[t], s = this.#t[t];
|
|
1337
|
+
return this.#W && this.#e(s) ? s.__abortController.abort(new Error("evicted")) : (this.#T || this.#f) && (this.#T && this.#w?.(s, i2, "evict"), this.#f && this.#r?.push([s, i2, "evict"])), this.#R(t), this.#g?.[t] && (clearTimeout(this.#g[t]), this.#g[t] = undefined), e && (this.#i[t] = undefined, this.#t[t] = undefined, this.#y.push(t)), this.#n === 1 ? (this.#l = this.#h = 0, this.#y.length = 0) : this.#l = this.#a[t], this.#s.delete(i2), this.#n--, t;
|
|
1328
1338
|
}
|
|
1329
|
-
has(
|
|
1330
|
-
let {
|
|
1339
|
+
has(e, t = {}) {
|
|
1340
|
+
let { status: i2 = S.hasSubscribers ? {} : undefined } = t;
|
|
1341
|
+
t.status = i2, i2 && (i2.op = "has", i2.key = e);
|
|
1342
|
+
let s = this.#Y(e, t);
|
|
1343
|
+
return S.hasSubscribers && S.publish(i2), s;
|
|
1344
|
+
}
|
|
1345
|
+
#Y(e, t = {}) {
|
|
1346
|
+
let { updateAgeOnHas: i2 = this.updateAgeOnHas, status: s } = t, n = this.#s.get(e);
|
|
1331
1347
|
if (n !== undefined) {
|
|
1332
1348
|
let o = this.#t[n];
|
|
1333
1349
|
if (this.#e(o) && o.__staleWhileFetching === undefined)
|
|
1334
1350
|
return false;
|
|
1335
1351
|
if (this.#p(n))
|
|
1336
|
-
s && (s.has = "stale", this.#
|
|
1352
|
+
s && (s.has = "stale", this.#E(s, n));
|
|
1337
1353
|
else
|
|
1338
|
-
return i2 && this.#
|
|
1354
|
+
return i2 && this.#x(n), s && (s.has = "hit", this.#E(s, n)), true;
|
|
1339
1355
|
} else
|
|
1340
1356
|
s && (s.has = "miss");
|
|
1341
1357
|
return false;
|
|
1342
1358
|
}
|
|
1343
|
-
peek(
|
|
1344
|
-
let {
|
|
1345
|
-
|
|
1359
|
+
peek(e, t = {}) {
|
|
1360
|
+
let { status: i2 = D() ? {} : undefined } = t;
|
|
1361
|
+
i2 && (i2.op = "peek", i2.key = e), t.status = i2;
|
|
1362
|
+
let s = this.#J(e, t);
|
|
1363
|
+
return S.hasSubscribers && S.publish(i2), s;
|
|
1364
|
+
}
|
|
1365
|
+
#J(e, t) {
|
|
1366
|
+
let { status: i2, allowStale: s = this.allowStale } = t, n = this.#s.get(e);
|
|
1367
|
+
if (n === undefined || !s && this.#p(n)) {
|
|
1368
|
+
i2 && (i2.peek = n === undefined ? "miss" : "stale");
|
|
1346
1369
|
return;
|
|
1347
|
-
|
|
1348
|
-
|
|
1370
|
+
}
|
|
1371
|
+
let o = this.#t[n], r = this.#e(o) ? o.__staleWhileFetching : o;
|
|
1372
|
+
return i2 && (r !== undefined ? (i2.peek = "hit", i2.value = r) : i2.peek = "miss"), r;
|
|
1349
1373
|
}
|
|
1350
|
-
#
|
|
1351
|
-
let n =
|
|
1374
|
+
#P(e, t, i2, s) {
|
|
1375
|
+
let n = t === undefined ? undefined : this.#t[t];
|
|
1352
1376
|
if (this.#e(n))
|
|
1353
1377
|
return n;
|
|
1354
|
-
let o = new
|
|
1355
|
-
|
|
1356
|
-
let
|
|
1357
|
-
let { aborted:
|
|
1358
|
-
if (i2.status && (
|
|
1359
|
-
return f(o.signal.reason,
|
|
1360
|
-
let
|
|
1361
|
-
return (
|
|
1362
|
-
},
|
|
1363
|
-
let { aborted:
|
|
1364
|
-
if (this.#t[
|
|
1365
|
-
return i2.status &&
|
|
1366
|
-
if (
|
|
1367
|
-
throw
|
|
1368
|
-
},
|
|
1369
|
-
let
|
|
1370
|
-
|
|
1371
|
-
(!i2.ignoreFetchAbort || i2.allowStaleOnFetchAbort) && (
|
|
1378
|
+
let o = new AbortController, { signal: r } = i2;
|
|
1379
|
+
r?.addEventListener("abort", () => o.abort(r.reason), { signal: o.signal });
|
|
1380
|
+
let h = { signal: o.signal, options: i2, context: s }, l = (w, y = false) => {
|
|
1381
|
+
let { aborted: a } = o.signal, m = i2.ignoreFetchAbort && w !== undefined, _ = i2.ignoreFetchAbort || !!(i2.allowStaleOnFetchAbort && w !== undefined);
|
|
1382
|
+
if (i2.status && (a && !y ? (i2.status.fetchAborted = true, i2.status.fetchError = o.signal.reason, m && (i2.status.fetchAbortIgnored = true)) : i2.status.fetchResolved = true), a && !m && !y)
|
|
1383
|
+
return f(o.signal.reason, _);
|
|
1384
|
+
let b = p, d = this.#t[t];
|
|
1385
|
+
return (d === p || d === undefined && m && y) && (w === undefined ? b.__staleWhileFetching !== undefined ? this.#t[t] = b.__staleWhileFetching : this.#v(e, "fetch") : (i2.status && (i2.status.fetchUpdated = true), this.#O(e, w, h.options))), w;
|
|
1386
|
+
}, c = (w) => (i2.status && (i2.status.fetchRejected = true, i2.status.fetchError = w), f(w, false)), f = (w, y) => {
|
|
1387
|
+
let { aborted: a } = o.signal, m = a && i2.allowStaleOnFetchAbort, _ = m || i2.allowStaleOnFetchRejection, b = _ || i2.noDeleteOnFetchRejection, d = p;
|
|
1388
|
+
if (this.#t[t] === p && (!b || !y && d.__staleWhileFetching === undefined ? this.#v(e, "fetch") : m || (this.#t[t] = d.__staleWhileFetching)), _)
|
|
1389
|
+
return i2.status && d.__staleWhileFetching !== undefined && (i2.status.returnedStale = true), d.__staleWhileFetching;
|
|
1390
|
+
if (d.__returned === d)
|
|
1391
|
+
throw w;
|
|
1392
|
+
}, g = (w, y) => {
|
|
1393
|
+
let a = this.#M?.(e, n, h);
|
|
1394
|
+
a && a instanceof Promise && a.then((m) => w(m === undefined ? undefined : m), y), o.signal.addEventListener("abort", () => {
|
|
1395
|
+
(!i2.ignoreFetchAbort || i2.allowStaleOnFetchAbort) && (w(undefined), i2.allowStaleOnFetchAbort && (w = (m) => l(m, true)));
|
|
1372
1396
|
});
|
|
1373
1397
|
};
|
|
1374
1398
|
i2.status && (i2.status.fetchDispatched = true);
|
|
1375
|
-
let
|
|
1376
|
-
return
|
|
1399
|
+
let p = new Promise(g).then(l, c), T = Object.assign(p, { __abortController: o, __staleWhileFetching: n, __returned: undefined });
|
|
1400
|
+
return t === undefined ? (this.#O(e, T, { ...h.options, status: undefined }), t = this.#s.get(e)) : this.#t[t] = T, T;
|
|
1377
1401
|
}
|
|
1378
|
-
#e(
|
|
1379
|
-
if (!this.#
|
|
1402
|
+
#e(e) {
|
|
1403
|
+
if (!this.#W)
|
|
1380
1404
|
return false;
|
|
1381
|
-
let
|
|
1382
|
-
return !!
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
let
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1405
|
+
let t = e;
|
|
1406
|
+
return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
|
|
1407
|
+
}
|
|
1408
|
+
fetch(e, t = {}) {
|
|
1409
|
+
let i2 = W.hasSubscribers, { status: s = D() ? {} : undefined } = t;
|
|
1410
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
1411
|
+
let n = this.#B(e, t);
|
|
1412
|
+
return s && D() && i2 && (s.trace = true, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
1413
|
+
}
|
|
1414
|
+
async#B(e, t = {}) {
|
|
1415
|
+
let { allowStale: i2 = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: r = this.noDisposeOnSet, size: h = 0, sizeCalculation: l = this.sizeCalculation, noUpdateTTL: c = this.noUpdateTTL, noDeleteOnFetchRejection: f = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: g = this.allowStaleOnFetchRejection, ignoreFetchAbort: p = this.ignoreFetchAbort, allowStaleOnFetchAbort: T = this.allowStaleOnFetchAbort, context: w, forceRefresh: y = false, status: a, signal: m } = t;
|
|
1416
|
+
if (a && (a.op = "fetch", a.key = e, y && (a.forceRefresh = true)), !this.#W)
|
|
1417
|
+
return a && (a.fetch = "get"), this.#C(e, { allowStale: i2, updateAgeOnGet: s, noDeleteOnStaleGet: n, status: a });
|
|
1418
|
+
let _ = { allowStale: i2, updateAgeOnGet: s, noDeleteOnStaleGet: n, ttl: o, noDisposeOnSet: r, size: h, sizeCalculation: l, noUpdateTTL: c, noDeleteOnFetchRejection: f, allowStaleOnFetchRejection: g, allowStaleOnFetchAbort: T, ignoreFetchAbort: p, status: a, signal: m }, b = this.#s.get(e);
|
|
1419
|
+
if (b === undefined) {
|
|
1420
|
+
a && (a.fetch = "miss");
|
|
1421
|
+
let d = this.#P(e, b, _, w);
|
|
1422
|
+
return d.__returned = d;
|
|
1393
1423
|
} else {
|
|
1394
|
-
let
|
|
1395
|
-
if (this.#e(
|
|
1396
|
-
let E = i2 &&
|
|
1397
|
-
return
|
|
1424
|
+
let d = this.#t[b];
|
|
1425
|
+
if (this.#e(d)) {
|
|
1426
|
+
let E = i2 && d.__staleWhileFetching !== undefined;
|
|
1427
|
+
return a && (a.fetch = "inflight", E && (a.returnedStale = true)), E ? d.__staleWhileFetching : d.__returned = d;
|
|
1398
1428
|
}
|
|
1399
|
-
let
|
|
1400
|
-
if (!
|
|
1401
|
-
return
|
|
1402
|
-
let
|
|
1403
|
-
return
|
|
1429
|
+
let A = this.#p(b);
|
|
1430
|
+
if (!y && !A)
|
|
1431
|
+
return a && (a.fetch = "hit"), this.#L(b), s && this.#x(b), a && this.#E(a, b), d;
|
|
1432
|
+
let z = this.#P(e, b, _, w), v = z.__staleWhileFetching !== undefined && i2;
|
|
1433
|
+
return a && (a.fetch = A ? "stale" : "refresh", v && A && (a.returnedStale = true)), v ? z.__staleWhileFetching : z.__returned = z;
|
|
1404
1434
|
}
|
|
1405
1435
|
}
|
|
1406
|
-
|
|
1407
|
-
let i2 =
|
|
1436
|
+
forceFetch(e, t = {}) {
|
|
1437
|
+
let i2 = W.hasSubscribers, { status: s = D() ? {} : undefined } = t;
|
|
1438
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
1439
|
+
let n = this.#K(e, t);
|
|
1440
|
+
return s && D() && i2 && (s.trace = true, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
1441
|
+
}
|
|
1442
|
+
async#K(e, t = {}) {
|
|
1443
|
+
let i2 = await this.#B(e, t);
|
|
1408
1444
|
if (i2 === undefined)
|
|
1409
1445
|
throw new Error("fetch() returned undefined");
|
|
1410
1446
|
return i2;
|
|
1411
1447
|
}
|
|
1412
|
-
memo(
|
|
1413
|
-
let i2 =
|
|
1448
|
+
memo(e, t = {}) {
|
|
1449
|
+
let { status: i2 = S.hasSubscribers ? {} : undefined } = t;
|
|
1450
|
+
t.status = i2, i2 && (i2.op = "memo", i2.key = e, t.context && (i2.context = t.context));
|
|
1451
|
+
let s = this.#Q(e, t);
|
|
1452
|
+
return i2 && (i2.value = s), S.hasSubscribers && S.publish(i2), s;
|
|
1453
|
+
}
|
|
1454
|
+
#Q(e, t = {}) {
|
|
1455
|
+
let i2 = this.#U;
|
|
1414
1456
|
if (!i2)
|
|
1415
1457
|
throw new Error("no memoMethod provided to constructor");
|
|
1416
|
-
let { context: s,
|
|
1417
|
-
|
|
1458
|
+
let { context: s, status: n, forceRefresh: o, ...r } = t;
|
|
1459
|
+
n && o && (n.forceRefresh = true);
|
|
1460
|
+
let h = this.#C(e, r), l = o || h === undefined;
|
|
1461
|
+
if (n && (n.memo = l ? "miss" : "hit", l || (n.value = h)), !l)
|
|
1418
1462
|
return h;
|
|
1419
|
-
let
|
|
1420
|
-
return this
|
|
1421
|
-
}
|
|
1422
|
-
get(
|
|
1423
|
-
let {
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1463
|
+
let c = i2(e, h, { options: r, context: s });
|
|
1464
|
+
return n && (n.value = c), this.#O(e, c, r), c;
|
|
1465
|
+
}
|
|
1466
|
+
get(e, t = {}) {
|
|
1467
|
+
let { status: i2 = S.hasSubscribers ? {} : undefined } = t;
|
|
1468
|
+
t.status = i2, i2 && (i2.op = "get", i2.key = e);
|
|
1469
|
+
let s = this.#C(e, t);
|
|
1470
|
+
return i2 && (s !== undefined && (i2.value = s), S.hasSubscribers && S.publish(i2)), s;
|
|
1471
|
+
}
|
|
1472
|
+
#C(e, t = {}) {
|
|
1473
|
+
let { allowStale: i2 = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = t, r = this.#s.get(e);
|
|
1474
|
+
if (r === undefined) {
|
|
1428
1475
|
o && (o.get = "miss");
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
let h = this.#t[r], l = this.#e(h);
|
|
1479
|
+
return o && this.#E(o, r), this.#p(r) ? l ? (o && (o.get = "stale-fetching"), i2 && h.__staleWhileFetching !== undefined ? (o && (o.returnedStale = true), h.__staleWhileFetching) : undefined) : (n || this.#v(e, "expire"), o && (o.get = "stale"), i2 ? (o && (o.returnedStale = true), h) : undefined) : (o && (o.get = l ? "fetching" : "hit"), this.#L(r), s && this.#x(r), l ? h.__staleWhileFetching : h);
|
|
1429
1480
|
}
|
|
1430
|
-
|
|
1431
|
-
this.#
|
|
1481
|
+
#$(e, t) {
|
|
1482
|
+
this.#c[t] = e, this.#a[e] = t;
|
|
1432
1483
|
}
|
|
1433
|
-
#
|
|
1434
|
-
|
|
1484
|
+
#L(e) {
|
|
1485
|
+
e !== this.#h && (e === this.#l ? this.#l = this.#a[e] : this.#$(this.#c[e], this.#a[e]), this.#$(this.#h, e), this.#h = e);
|
|
1435
1486
|
}
|
|
1436
|
-
delete(
|
|
1437
|
-
return this.#
|
|
1487
|
+
delete(e) {
|
|
1488
|
+
return this.#v(e, "delete");
|
|
1438
1489
|
}
|
|
1439
|
-
#
|
|
1490
|
+
#v(e, t) {
|
|
1491
|
+
S.hasSubscribers && S.publish({ op: "delete", delete: t, key: e });
|
|
1440
1492
|
let i2 = false;
|
|
1441
1493
|
if (this.#n !== 0) {
|
|
1442
|
-
let s = this.#s.get(
|
|
1494
|
+
let s = this.#s.get(e);
|
|
1443
1495
|
if (s !== undefined)
|
|
1444
1496
|
if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = undefined), i2 = true, this.#n === 1)
|
|
1445
|
-
this.#
|
|
1497
|
+
this.#q(t);
|
|
1446
1498
|
else {
|
|
1447
|
-
this.#
|
|
1499
|
+
this.#R(s);
|
|
1448
1500
|
let n = this.#t[s];
|
|
1449
|
-
if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n,
|
|
1450
|
-
this.#h = this.#
|
|
1501
|
+
if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, e, t), this.#f && this.#r?.push([n, e, t])), this.#s.delete(e), this.#i[s] = undefined, this.#t[s] = undefined, s === this.#h)
|
|
1502
|
+
this.#h = this.#c[s];
|
|
1451
1503
|
else if (s === this.#l)
|
|
1452
1504
|
this.#l = this.#a[s];
|
|
1453
1505
|
else {
|
|
1454
|
-
let o = this.#
|
|
1506
|
+
let o = this.#c[s];
|
|
1455
1507
|
this.#a[o] = this.#a[s];
|
|
1456
|
-
let
|
|
1457
|
-
this.#
|
|
1508
|
+
let r = this.#a[s];
|
|
1509
|
+
this.#c[r] = this.#c[s];
|
|
1458
1510
|
}
|
|
1459
|
-
this.#n--, this.#
|
|
1511
|
+
this.#n--, this.#y.push(s);
|
|
1460
1512
|
}
|
|
1461
1513
|
}
|
|
1462
1514
|
if (this.#f && this.#r?.length) {
|
|
@@ -1467,27 +1519,27 @@ var init_index_min = __esm(() => {
|
|
|
1467
1519
|
return i2;
|
|
1468
1520
|
}
|
|
1469
1521
|
clear() {
|
|
1470
|
-
return this.#
|
|
1522
|
+
return this.#q("delete");
|
|
1471
1523
|
}
|
|
1472
|
-
#
|
|
1473
|
-
for (let
|
|
1474
|
-
let i2 = this.#t[
|
|
1524
|
+
#q(e) {
|
|
1525
|
+
for (let t of this.#z({ allowStale: true })) {
|
|
1526
|
+
let i2 = this.#t[t];
|
|
1475
1527
|
if (this.#e(i2))
|
|
1476
1528
|
i2.__abortController.abort(new Error("deleted"));
|
|
1477
1529
|
else {
|
|
1478
|
-
let s = this.#i[
|
|
1479
|
-
this.#T && this.#w?.(i2, s,
|
|
1530
|
+
let s = this.#i[t];
|
|
1531
|
+
this.#T && this.#w?.(i2, s, e), this.#f && this.#r?.push([i2, s, e]);
|
|
1480
1532
|
}
|
|
1481
1533
|
}
|
|
1482
|
-
if (this.#s.clear(), this.#t.fill(undefined), this.#i.fill(undefined), this.#d && this.#
|
|
1483
|
-
this.#d.fill(0), this.#
|
|
1484
|
-
for (let
|
|
1485
|
-
|
|
1534
|
+
if (this.#s.clear(), this.#t.fill(undefined), this.#i.fill(undefined), this.#d && this.#F) {
|
|
1535
|
+
this.#d.fill(0), this.#F.fill(0);
|
|
1536
|
+
for (let t of this.#g ?? [])
|
|
1537
|
+
t !== undefined && clearTimeout(t);
|
|
1486
1538
|
this.#g?.fill(undefined);
|
|
1487
1539
|
}
|
|
1488
|
-
if (this.#
|
|
1489
|
-
let
|
|
1490
|
-
for (;i2 =
|
|
1540
|
+
if (this.#_ && this.#_.fill(0), this.#l = 0, this.#h = 0, this.#y.length = 0, this.#b = 0, this.#n = 0, this.#f && this.#r) {
|
|
1541
|
+
let t = this.#r, i2;
|
|
1542
|
+
for (;i2 = t?.shift(); )
|
|
1491
1543
|
this.#S?.(...i2);
|
|
1492
1544
|
}
|
|
1493
1545
|
}
|
|
@@ -1880,11 +1932,11 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
1880
1932
|
str += String.fromCharCode((u0 & 31) << 6 | u1);
|
|
1881
1933
|
continue;
|
|
1882
1934
|
}
|
|
1883
|
-
var
|
|
1935
|
+
var u22 = heapOrArray[idx++] & 63;
|
|
1884
1936
|
if ((u0 & 240) == 224) {
|
|
1885
|
-
u0 = (u0 & 15) << 12 | u1 << 6 |
|
|
1937
|
+
u0 = (u0 & 15) << 12 | u1 << 6 | u22;
|
|
1886
1938
|
} else {
|
|
1887
|
-
u0 = (u0 & 7) << 18 | u1 << 12 |
|
|
1939
|
+
u0 = (u0 & 7) << 18 | u1 << 12 | u22 << 6 | heapOrArray[idx++] & 63;
|
|
1888
1940
|
}
|
|
1889
1941
|
if (u0 < 65536) {
|
|
1890
1942
|
str += String.fromCharCode(u0);
|
|
@@ -2662,7 +2714,7 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
2662
2714
|
if (requestedSize > maxHeapSize) {
|
|
2663
2715
|
return false;
|
|
2664
2716
|
}
|
|
2665
|
-
var alignUp = (
|
|
2717
|
+
var alignUp = (x, multiple) => x + (multiple - x % multiple) % multiple;
|
|
2666
2718
|
for (var cutDown = 1;cutDown <= 4; cutDown *= 2) {
|
|
2667
2719
|
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
|
2668
2720
|
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
|
|
@@ -2699,8 +2751,8 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
2699
2751
|
var ptr = LE_HEAP_LOAD_U32((iov >> 2) * 4);
|
|
2700
2752
|
var len = LE_HEAP_LOAD_U32((iov + 4 >> 2) * 4);
|
|
2701
2753
|
iov += 8;
|
|
2702
|
-
for (var
|
|
2703
|
-
printChar(fd, HEAPU8[ptr +
|
|
2754
|
+
for (var j2 = 0;j2 < len; j2++) {
|
|
2755
|
+
printChar(fd, HEAPU8[ptr + j2]);
|
|
2704
2756
|
}
|
|
2705
2757
|
num += len;
|
|
2706
2758
|
}
|
|
@@ -2751,12 +2803,12 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
2751
2803
|
var lengthBytesUTF8 = (str) => {
|
|
2752
2804
|
var len = 0;
|
|
2753
2805
|
for (var i2 = 0;i2 < str.length; ++i2) {
|
|
2754
|
-
var
|
|
2755
|
-
if (
|
|
2806
|
+
var c = str.charCodeAt(i2);
|
|
2807
|
+
if (c <= 127) {
|
|
2756
2808
|
len++;
|
|
2757
|
-
} else if (
|
|
2809
|
+
} else if (c <= 2047) {
|
|
2758
2810
|
len += 2;
|
|
2759
|
-
} else if (
|
|
2811
|
+
} else if (c >= 55296 && c <= 57343) {
|
|
2760
2812
|
len += 4;
|
|
2761
2813
|
++i2;
|
|
2762
2814
|
} else {
|
|
@@ -2771,33 +2823,33 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
2771
2823
|
var startIdx = outIdx;
|
|
2772
2824
|
var endIdx = outIdx + maxBytesToWrite - 1;
|
|
2773
2825
|
for (var i2 = 0;i2 < str.length; ++i2) {
|
|
2774
|
-
var
|
|
2775
|
-
if (
|
|
2826
|
+
var u3 = str.charCodeAt(i2);
|
|
2827
|
+
if (u3 >= 55296 && u3 <= 57343) {
|
|
2776
2828
|
var u1 = str.charCodeAt(++i2);
|
|
2777
|
-
|
|
2829
|
+
u3 = 65536 + ((u3 & 1023) << 10) | u1 & 1023;
|
|
2778
2830
|
}
|
|
2779
|
-
if (
|
|
2831
|
+
if (u3 <= 127) {
|
|
2780
2832
|
if (outIdx >= endIdx)
|
|
2781
2833
|
break;
|
|
2782
|
-
heap[outIdx++] =
|
|
2783
|
-
} else if (
|
|
2834
|
+
heap[outIdx++] = u3;
|
|
2835
|
+
} else if (u3 <= 2047) {
|
|
2784
2836
|
if (outIdx + 1 >= endIdx)
|
|
2785
2837
|
break;
|
|
2786
|
-
heap[outIdx++] = 192 |
|
|
2787
|
-
heap[outIdx++] = 128 |
|
|
2788
|
-
} else if (
|
|
2838
|
+
heap[outIdx++] = 192 | u3 >> 6;
|
|
2839
|
+
heap[outIdx++] = 128 | u3 & 63;
|
|
2840
|
+
} else if (u3 <= 65535) {
|
|
2789
2841
|
if (outIdx + 2 >= endIdx)
|
|
2790
2842
|
break;
|
|
2791
|
-
heap[outIdx++] = 224 |
|
|
2792
|
-
heap[outIdx++] = 128 |
|
|
2793
|
-
heap[outIdx++] = 128 |
|
|
2843
|
+
heap[outIdx++] = 224 | u3 >> 12;
|
|
2844
|
+
heap[outIdx++] = 128 | u3 >> 6 & 63;
|
|
2845
|
+
heap[outIdx++] = 128 | u3 & 63;
|
|
2794
2846
|
} else {
|
|
2795
2847
|
if (outIdx + 3 >= endIdx)
|
|
2796
2848
|
break;
|
|
2797
|
-
heap[outIdx++] = 240 |
|
|
2798
|
-
heap[outIdx++] = 128 |
|
|
2799
|
-
heap[outIdx++] = 128 |
|
|
2800
|
-
heap[outIdx++] = 128 |
|
|
2849
|
+
heap[outIdx++] = 240 | u3 >> 18;
|
|
2850
|
+
heap[outIdx++] = 128 | u3 >> 12 & 63;
|
|
2851
|
+
heap[outIdx++] = 128 | u3 >> 6 & 63;
|
|
2852
|
+
heap[outIdx++] = 128 | u3 & 63;
|
|
2801
2853
|
}
|
|
2802
2854
|
}
|
|
2803
2855
|
heap[outIdx] = 0;
|
|
@@ -3859,7 +3911,7 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
3859
3911
|
textPredicates[i2] = [];
|
|
3860
3912
|
const steps = [];
|
|
3861
3913
|
let stepAddress = predicatesAddress;
|
|
3862
|
-
for (let
|
|
3914
|
+
for (let j2 = 0;j2 < stepCount; j2++) {
|
|
3863
3915
|
const stepType = getValue(stepAddress, "i32");
|
|
3864
3916
|
stepAddress += SIZE_OF_INT;
|
|
3865
3917
|
const stepValueId = getValue(stepAddress, "i32");
|
|
@@ -3901,11 +3953,11 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
3901
3953
|
textPredicates[i2].push((captures) => {
|
|
3902
3954
|
const nodes1 = [];
|
|
3903
3955
|
const nodes2 = [];
|
|
3904
|
-
for (const
|
|
3905
|
-
if (
|
|
3906
|
-
nodes1.push(
|
|
3907
|
-
if (
|
|
3908
|
-
nodes2.push(
|
|
3956
|
+
for (const c of captures) {
|
|
3957
|
+
if (c.name === captureName1)
|
|
3958
|
+
nodes1.push(c.node);
|
|
3959
|
+
if (c.name === captureName2)
|
|
3960
|
+
nodes2.push(c.node);
|
|
3909
3961
|
}
|
|
3910
3962
|
const compare = (n1, n2, positive) => positive ? n1.text === n2.text : n1.text !== n2.text;
|
|
3911
3963
|
return matchAll ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))) : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)));
|
|
@@ -3917,9 +3969,9 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
3917
3969
|
const doesNotMatch = (n) => n.text !== stringValue;
|
|
3918
3970
|
textPredicates[i2].push((captures) => {
|
|
3919
3971
|
const nodes = [];
|
|
3920
|
-
for (const
|
|
3921
|
-
if (
|
|
3922
|
-
nodes.push(
|
|
3972
|
+
for (const c of captures) {
|
|
3973
|
+
if (c.name === captureName)
|
|
3974
|
+
nodes.push(c.node);
|
|
3923
3975
|
}
|
|
3924
3976
|
const test = isPositive ? matches : doesNotMatch;
|
|
3925
3977
|
return matchAll ? nodes.every(test) : nodes.some(test);
|
|
@@ -3945,9 +3997,9 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
3945
3997
|
matchAll = !operator.startsWith("any-");
|
|
3946
3998
|
textPredicates[i2].push((captures) => {
|
|
3947
3999
|
const nodes = [];
|
|
3948
|
-
for (const
|
|
3949
|
-
if (
|
|
3950
|
-
nodes.push(
|
|
4000
|
+
for (const c of captures) {
|
|
4001
|
+
if (c.name === captureName)
|
|
4002
|
+
nodes.push(c.node.text);
|
|
3951
4003
|
}
|
|
3952
4004
|
const test = (text, positive) => positive ? regex.test(text) : !regex.test(text);
|
|
3953
4005
|
if (nodes.length === 0)
|
|
@@ -3997,9 +4049,9 @@ var require_tree_sitter_0_24_3 = __commonJS((exports, module2) => {
|
|
|
3997
4049
|
const values = steps.slice(2).map((s) => s.value);
|
|
3998
4050
|
textPredicates[i2].push((captures) => {
|
|
3999
4051
|
const nodes = [];
|
|
4000
|
-
for (const
|
|
4001
|
-
if (
|
|
4002
|
-
nodes.push(
|
|
4052
|
+
for (const c of captures) {
|
|
4053
|
+
if (c.name === captureName)
|
|
4054
|
+
nodes.push(c.node.text);
|
|
4003
4055
|
}
|
|
4004
4056
|
if (nodes.length === 0)
|
|
4005
4057
|
return !isPositive;
|
|
@@ -4245,8 +4297,8 @@ ${JSON.stringify(symbolNames, null, 2)}`);
|
|
|
4245
4297
|
}
|
|
4246
4298
|
return address;
|
|
4247
4299
|
}
|
|
4248
|
-
function assertInternal(
|
|
4249
|
-
if (
|
|
4300
|
+
function assertInternal(x) {
|
|
4301
|
+
if (x !== INTERNAL)
|
|
4250
4302
|
throw new Error("Illegal constructor");
|
|
4251
4303
|
}
|
|
4252
4304
|
function isPoint(point) {
|
|
@@ -4425,8 +4477,15 @@ async function getParser(lang) {
|
|
|
4425
4477
|
if (wasmRuntimePoisoned)
|
|
4426
4478
|
return null;
|
|
4427
4479
|
await initParser();
|
|
4428
|
-
|
|
4480
|
+
const uses = parserUseCount.get(lang) ?? 0;
|
|
4481
|
+
if (parsers.has(lang) && uses >= PARSER_RECYCLE_THRESHOLD) {
|
|
4482
|
+
parsers.delete(lang);
|
|
4483
|
+
parserUseCount.set(lang, 0);
|
|
4484
|
+
}
|
|
4485
|
+
if (parsers.has(lang)) {
|
|
4486
|
+
parserUseCount.set(lang, uses + 1);
|
|
4429
4487
|
return parsers.get(lang);
|
|
4488
|
+
}
|
|
4430
4489
|
if (unsupportedParsers.has(lang))
|
|
4431
4490
|
return null;
|
|
4432
4491
|
const language = await loadLanguage(lang);
|
|
@@ -4510,6 +4569,35 @@ function extractSymbols(tree, code, lang) {
|
|
|
4510
4569
|
}
|
|
4511
4570
|
}
|
|
4512
4571
|
visit(tree.rootNode);
|
|
4572
|
+
const exportedNames = new Set;
|
|
4573
|
+
function collectExportedNames(node) {
|
|
4574
|
+
if (node.type === "export_statement") {
|
|
4575
|
+
for (let i2 = 0;i2 < node.childCount; i2++) {
|
|
4576
|
+
const child = node.child(i2);
|
|
4577
|
+
if (child.type === "export_clause") {
|
|
4578
|
+
for (let j2 = 0;j2 < child.childCount; j2++) {
|
|
4579
|
+
const spec = child.child(j2);
|
|
4580
|
+
if (spec.type === "export_specifier") {
|
|
4581
|
+
const nameNode = spec.childForFieldName("name");
|
|
4582
|
+
if (nameNode)
|
|
4583
|
+
exportedNames.add(nameNode.text);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
for (let i2 = 0;i2 < node.childCount; i2++) {
|
|
4590
|
+
collectExportedNames(node.child(i2));
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4593
|
+
collectExportedNames(tree.rootNode);
|
|
4594
|
+
if (exportedNames.size > 0) {
|
|
4595
|
+
for (const sym of symbols) {
|
|
4596
|
+
if (!sym.isExported && exportedNames.has(sym.name)) {
|
|
4597
|
+
sym.isExported = true;
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4513
4601
|
return symbols;
|
|
4514
4602
|
}
|
|
4515
4603
|
function returnsJSX(node) {
|
|
@@ -4532,7 +4620,7 @@ function isPascalCase(name2) {
|
|
|
4532
4620
|
return /^[A-Z][a-zA-Z0-9]*$/.test(name2);
|
|
4533
4621
|
}
|
|
4534
4622
|
function extractTypeAnnotation(node) {
|
|
4535
|
-
const typeAnnotation = node.childForFieldName("return_type") || node.children.find((
|
|
4623
|
+
const typeAnnotation = node.childForFieldName("return_type") || node.children.find((c) => c.type === "type_annotation");
|
|
4536
4624
|
if (typeAnnotation) {
|
|
4537
4625
|
return typeAnnotation.text.replace(/^:\s*/, "");
|
|
4538
4626
|
}
|
|
@@ -4540,7 +4628,7 @@ function extractTypeAnnotation(node) {
|
|
|
4540
4628
|
}
|
|
4541
4629
|
function extractParams(node) {
|
|
4542
4630
|
const params = [];
|
|
4543
|
-
const paramsNode = node.childForFieldName("parameters") || node.children.find((
|
|
4631
|
+
const paramsNode = node.childForFieldName("parameters") || node.children.find((c) => c.type === "formal_parameters" || c.type === "parameters");
|
|
4544
4632
|
if (paramsNode) {
|
|
4545
4633
|
for (let i2 = 0;i2 < paramsNode.childCount; i2++) {
|
|
4546
4634
|
const child = paramsNode.child(i2);
|
|
@@ -4623,12 +4711,12 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4623
4711
|
}
|
|
4624
4712
|
if (lang === "python") {
|
|
4625
4713
|
if (type === "decorated_definition") {
|
|
4626
|
-
const funcNode = node.children.find((
|
|
4627
|
-
const classNode = node.children.find((
|
|
4714
|
+
const funcNode = node.children.find((c) => c.type === "function_definition");
|
|
4715
|
+
const classNode = node.children.find((c) => c.type === "class_definition");
|
|
4628
4716
|
const targetNode = funcNode || classNode;
|
|
4629
4717
|
if (targetNode) {
|
|
4630
4718
|
const nameNode = targetNode.childForFieldName("name");
|
|
4631
|
-
const decorators = node.children.filter((
|
|
4719
|
+
const decorators = node.children.filter((c) => c.type === "decorator").map((d) => d.text).join(`
|
|
4632
4720
|
`);
|
|
4633
4721
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4634
4722
|
const isPythonExported = !name2.startsWith("_");
|
|
@@ -4707,7 +4795,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4707
4795
|
};
|
|
4708
4796
|
}
|
|
4709
4797
|
if (type === "type_declaration") {
|
|
4710
|
-
const spec = node.children.find((
|
|
4798
|
+
const spec = node.children.find((c) => c.type === "type_spec");
|
|
4711
4799
|
const nameNode = spec?.childForFieldName("name");
|
|
4712
4800
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4713
4801
|
const isGoExported = /^[A-Z]/.test(name2);
|
|
@@ -4726,7 +4814,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4726
4814
|
if (type === "method_declaration" || type === "constructor_declaration") {
|
|
4727
4815
|
const nameNode = node.childForFieldName("name");
|
|
4728
4816
|
const name2 = nameNode?.text ?? (type === "constructor_declaration" ? "<init>" : "anonymous");
|
|
4729
|
-
const modifiers = node.children.find((
|
|
4817
|
+
const modifiers = node.children.find((c) => c.type === "modifiers");
|
|
4730
4818
|
const isPublic = modifiers?.text.includes("public") ?? false;
|
|
4731
4819
|
return {
|
|
4732
4820
|
name: name2,
|
|
@@ -4741,7 +4829,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4741
4829
|
if (type === "class_declaration" || type === "interface_declaration" || type === "enum_declaration") {
|
|
4742
4830
|
const nameNode = node.childForFieldName("name");
|
|
4743
4831
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4744
|
-
const modifiers = node.children.find((
|
|
4832
|
+
const modifiers = node.children.find((c) => c.type === "modifiers");
|
|
4745
4833
|
const isPublic = modifiers?.text.includes("public") ?? false;
|
|
4746
4834
|
return {
|
|
4747
4835
|
name: name2,
|
|
@@ -4787,7 +4875,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4787
4875
|
if (type === "method_declaration" || type === "function_definition") {
|
|
4788
4876
|
const nameNode = node.childForFieldName("name");
|
|
4789
4877
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4790
|
-
const modifiers = node.children.find((
|
|
4878
|
+
const modifiers = node.children.find((c) => c.type === "visibility_modifier");
|
|
4791
4879
|
const isPublic = !modifiers || modifiers.text === "public";
|
|
4792
4880
|
return {
|
|
4793
4881
|
name: name2,
|
|
@@ -4817,7 +4905,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4817
4905
|
if (type === "function_item") {
|
|
4818
4906
|
const nameNode = node.childForFieldName("name");
|
|
4819
4907
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4820
|
-
const visMarker = node.children.find((
|
|
4908
|
+
const visMarker = node.children.find((c) => c.type === "visibility_modifier");
|
|
4821
4909
|
const isRustExported = visMarker?.text.startsWith("pub") ?? false;
|
|
4822
4910
|
return {
|
|
4823
4911
|
name: name2,
|
|
@@ -4845,7 +4933,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4845
4933
|
if (type === "struct_item" || type === "enum_item" || type === "trait_item") {
|
|
4846
4934
|
const nameNode = node.childForFieldName("name");
|
|
4847
4935
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4848
|
-
const visMarker = node.children.find((
|
|
4936
|
+
const visMarker = node.children.find((c) => c.type === "visibility_modifier");
|
|
4849
4937
|
const isRustExported = visMarker?.text.startsWith("pub") ?? false;
|
|
4850
4938
|
return {
|
|
4851
4939
|
name: name2,
|
|
@@ -4862,7 +4950,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4862
4950
|
if (type === "method_declaration" || type === "constructor_declaration") {
|
|
4863
4951
|
const nameNode = node.childForFieldName("name");
|
|
4864
4952
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4865
|
-
const modifiers = node.children.filter((
|
|
4953
|
+
const modifiers = node.children.filter((c) => c.type === "modifier");
|
|
4866
4954
|
const isPublic = modifiers.some((m) => m.text === "public" || m.text === "internal");
|
|
4867
4955
|
return {
|
|
4868
4956
|
name: name2,
|
|
@@ -4877,7 +4965,7 @@ function extractSymbol(node, lines, lang, code, isExported = false) {
|
|
|
4877
4965
|
if (type === "class_declaration" || type === "interface_declaration" || type === "struct_declaration" || type === "enum_declaration") {
|
|
4878
4966
|
const nameNode = node.childForFieldName("name");
|
|
4879
4967
|
const name2 = nameNode?.text ?? "anonymous";
|
|
4880
|
-
const modifiers = node.children.filter((
|
|
4968
|
+
const modifiers = node.children.filter((c) => c.type === "modifier");
|
|
4881
4969
|
const isPublic = modifiers.some((m) => m.text === "public" || m.text === "internal");
|
|
4882
4970
|
return {
|
|
4883
4971
|
name: name2,
|
|
@@ -4963,7 +5051,7 @@ function getSignature(node, lines) {
|
|
|
4963
5051
|
const firstLine = lines[node.startPosition.row];
|
|
4964
5052
|
if (!firstLine)
|
|
4965
5053
|
return "";
|
|
4966
|
-
const bodyStart = node.children.find((
|
|
5054
|
+
const bodyStart = node.children.find((c) => c.type === "statement_block" || c.type === "block");
|
|
4967
5055
|
if (bodyStart) {
|
|
4968
5056
|
return firstLine.substring(0, bodyStart.startPosition.column).trim();
|
|
4969
5057
|
}
|
|
@@ -4973,7 +5061,7 @@ function getClassSignature(node, lines) {
|
|
|
4973
5061
|
const firstLine = lines[node.startPosition.row];
|
|
4974
5062
|
if (!firstLine)
|
|
4975
5063
|
return "";
|
|
4976
|
-
const bodyStart = node.children.find((
|
|
5064
|
+
const bodyStart = node.children.find((c) => c.type === "class_body");
|
|
4977
5065
|
if (bodyStart) {
|
|
4978
5066
|
return firstLine.substring(0, bodyStart.startPosition.column).trim();
|
|
4979
5067
|
}
|
|
@@ -5192,7 +5280,17 @@ async function isParserReady() {
|
|
|
5192
5280
|
return false;
|
|
5193
5281
|
}
|
|
5194
5282
|
}
|
|
5195
|
-
|
|
5283
|
+
async function parseFile(filePath, content) {
|
|
5284
|
+
const lang = detectLanguage(filePath);
|
|
5285
|
+
if (!lang)
|
|
5286
|
+
return null;
|
|
5287
|
+
const tree = await parseCode(content, lang);
|
|
5288
|
+
if (!tree)
|
|
5289
|
+
return null;
|
|
5290
|
+
const symbols = extractSymbols(tree, content, lang);
|
|
5291
|
+
return { symbols };
|
|
5292
|
+
}
|
|
5293
|
+
var import_tree_sitter_0_24_3, __dirname2, LegacyParser, initialized = false, parsers, languages, parserUseCount, PARSER_RECYCLE_THRESHOLD = 500, WASM_DIR, LANG_WASM_MAP, unsupportedParsers, wasmRuntimePoisoned = false, KEYWORD_PSEUDO_CALLS;
|
|
5196
5294
|
var init_parser = __esm(() => {
|
|
5197
5295
|
init_logger();
|
|
5198
5296
|
import_tree_sitter_0_24_3 = __toESM(require_tree_sitter_0_24_3(), 1);
|
|
@@ -5200,6 +5298,7 @@ var init_parser = __esm(() => {
|
|
|
5200
5298
|
LegacyParser = import_tree_sitter_0_24_3.default;
|
|
5201
5299
|
parsers = new Map;
|
|
5202
5300
|
languages = new Map;
|
|
5301
|
+
parserUseCount = new Map;
|
|
5203
5302
|
WASM_DIR = getWasmDir();
|
|
5204
5303
|
LANG_WASM_MAP = {
|
|
5205
5304
|
typescript: "tree-sitter-typescript.wasm",
|
|
@@ -5300,10 +5399,12 @@ function checkAndMark(sessionId, blockRef) {
|
|
|
5300
5399
|
if (!entry) {
|
|
5301
5400
|
entry = {
|
|
5302
5401
|
seen_blocks: new Set,
|
|
5303
|
-
created_at: Date.now()
|
|
5402
|
+
created_at: Date.now(),
|
|
5403
|
+
last_accessed: Date.now()
|
|
5304
5404
|
};
|
|
5305
5405
|
sessions.set(sessionId, entry);
|
|
5306
5406
|
}
|
|
5407
|
+
entry.last_accessed = Date.now();
|
|
5307
5408
|
if (entry.seen_blocks.has(blockRef)) {
|
|
5308
5409
|
return true;
|
|
5309
5410
|
}
|
|
@@ -5313,7 +5414,14 @@ function checkAndMark(sessionId, blockRef) {
|
|
|
5313
5414
|
function cleanExpiredSessions() {
|
|
5314
5415
|
const now = Date.now();
|
|
5315
5416
|
for (const [id, entry] of sessions) {
|
|
5316
|
-
if (now - entry.created_at > SESSION_TTL_MS) {
|
|
5417
|
+
if (now - entry.created_at > SESSION_TTL_MS || now - entry.last_accessed > SESSION_IDLE_TTL_MS) {
|
|
5418
|
+
sessions.delete(id);
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
if (sessions.size > MAX_SESSIONS) {
|
|
5422
|
+
const sorted = [...sessions.entries()].sort((a, b) => a[1].last_accessed - b[1].last_accessed);
|
|
5423
|
+
const toRemove = sorted.slice(0, sessions.size - MAX_SESSIONS);
|
|
5424
|
+
for (const [id] of toRemove) {
|
|
5317
5425
|
sessions.delete(id);
|
|
5318
5426
|
}
|
|
5319
5427
|
}
|
|
@@ -5324,13 +5432,485 @@ function createFindCodeBlockRef(file, blockStart, blockEnd) {
|
|
|
5324
5432
|
function createReadCodeBlockRef(symbolName, file, startLine) {
|
|
5325
5433
|
return `${symbolName}@${file}:${startLine}`;
|
|
5326
5434
|
}
|
|
5327
|
-
var sessions, SESSION_TTL_MS = 3600000;
|
|
5435
|
+
var sessions, SESSION_TTL_MS = 3600000, SESSION_IDLE_TTL_MS = 1800000, MAX_SESSIONS = 200;
|
|
5328
5436
|
var init_sessionStore = __esm(() => {
|
|
5329
5437
|
sessions = new Map;
|
|
5330
5438
|
});
|
|
5331
5439
|
|
|
5440
|
+
// src/tools/reader/index-db.ts
|
|
5441
|
+
var exports_index_db = {};
|
|
5442
|
+
__export(exports_index_db, {
|
|
5443
|
+
getIndexDB: () => getIndexDB,
|
|
5444
|
+
closeAllIndexDBs: () => closeAllIndexDBs,
|
|
5445
|
+
IndexDB: () => IndexDB
|
|
5446
|
+
});
|
|
5447
|
+
import { Database } from "bun:sqlite";
|
|
5448
|
+
import { join as join3 } from "path";
|
|
5449
|
+
import { mkdirSync, existsSync as existsSync2 } from "node:fs";
|
|
5450
|
+
|
|
5451
|
+
class IndexDB {
|
|
5452
|
+
db;
|
|
5453
|
+
projectRoot;
|
|
5454
|
+
dbPath;
|
|
5455
|
+
stmts;
|
|
5456
|
+
constructor(projectRoot) {
|
|
5457
|
+
this.projectRoot = projectRoot;
|
|
5458
|
+
const indexDir = join3(projectRoot, ".zephex");
|
|
5459
|
+
if (!existsSync2(indexDir)) {
|
|
5460
|
+
mkdirSync(indexDir, { recursive: true });
|
|
5461
|
+
}
|
|
5462
|
+
this.dbPath = join3(indexDir, "index.db");
|
|
5463
|
+
this.db = new Database(this.dbPath, { create: true, strict: true });
|
|
5464
|
+
this.init();
|
|
5465
|
+
}
|
|
5466
|
+
init() {
|
|
5467
|
+
this.db.run("PRAGMA journal_mode = WAL");
|
|
5468
|
+
this.db.run("PRAGMA synchronous = NORMAL");
|
|
5469
|
+
this.db.run("PRAGMA cache_size = -64000");
|
|
5470
|
+
this.db.run("PRAGMA foreign_keys = ON");
|
|
5471
|
+
this.db.run("PRAGMA temp_store = MEMORY");
|
|
5472
|
+
this.db.run("CREATE TABLE IF NOT EXISTS index_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
|
|
5473
|
+
const version = this.db.query("SELECT value FROM index_meta WHERE key = 'schema_version'").get();
|
|
5474
|
+
if (version?.value !== SCHEMA_VERSION) {
|
|
5475
|
+
this.db.run("DROP TABLE IF EXISTS call_graph");
|
|
5476
|
+
this.db.run("DROP TABLE IF EXISTS symbol_index");
|
|
5477
|
+
this.db.run("DROP TABLE IF EXISTS workspace_files");
|
|
5478
|
+
this.db.run("DROP TABLE IF EXISTS index_meta");
|
|
5479
|
+
this.db.exec(SCHEMA_SQL);
|
|
5480
|
+
this.db.run("INSERT OR REPLACE INTO index_meta (key, value) VALUES ('schema_version', ?)", [SCHEMA_VERSION]);
|
|
5481
|
+
}
|
|
5482
|
+
this.prepareStatements();
|
|
5483
|
+
}
|
|
5484
|
+
prepareStatements() {
|
|
5485
|
+
this.stmts = {
|
|
5486
|
+
insertFile: this.db.query("INSERT OR REPLACE INTO workspace_files (file_path, content_hash, language, last_indexed_at, line_count) VALUES ($file_path, $content_hash, $language, $last_indexed_at, $line_count)"),
|
|
5487
|
+
insertSymbol: this.db.query("INSERT INTO symbol_index (file_path, name, kind, start_line, end_line, byte_offset_start, byte_offset_end, signature, is_exported, symbol_id) VALUES ($file_path, $name, $kind, $start_line, $end_line, $byte_offset_start, $byte_offset_end, $signature, $is_exported, $symbol_id)"),
|
|
5488
|
+
insertCallEdge: this.db.query("INSERT OR IGNORE INTO call_graph (caller_id, callee_id, call_line) VALUES ($caller_id, $callee_id, $call_line)"),
|
|
5489
|
+
getFile: this.db.query("SELECT * FROM workspace_files WHERE file_path = $file_path"),
|
|
5490
|
+
getSymbolByName: this.db.query("SELECT * FROM symbol_index WHERE name = $name COLLATE NOCASE"),
|
|
5491
|
+
getSymbolById: this.db.query("SELECT * FROM symbol_index WHERE symbol_id = $symbol_id"),
|
|
5492
|
+
getSymbolsByFile: this.db.query("SELECT * FROM symbol_index WHERE file_path = $file_path ORDER BY start_line"),
|
|
5493
|
+
getCallers: this.db.query(`SELECT s.*, cg.call_line FROM call_graph cg
|
|
5494
|
+
JOIN symbol_index s ON s.id = cg.caller_id
|
|
5495
|
+
WHERE cg.callee_id = $callee_id`),
|
|
5496
|
+
getCallees: this.db.query(`SELECT s.*, cg.call_line FROM call_graph cg
|
|
5497
|
+
JOIN symbol_index s ON s.id = cg.callee_id
|
|
5498
|
+
WHERE cg.caller_id = $caller_id`),
|
|
5499
|
+
getDeadCode: this.db.query(`SELECT s.* FROM symbol_index s
|
|
5500
|
+
WHERE s.is_exported = 1
|
|
5501
|
+
AND s.id NOT IN (SELECT callee_id FROM call_graph)
|
|
5502
|
+
ORDER BY s.file_path, s.start_line`),
|
|
5503
|
+
deleteFileSymbols: this.db.query("DELETE FROM symbol_index WHERE file_path = $file_path"),
|
|
5504
|
+
deleteFile: this.db.query("DELETE FROM workspace_files WHERE file_path = $file_path"),
|
|
5505
|
+
getAllFiles: this.db.query("SELECT * FROM workspace_files")
|
|
5506
|
+
};
|
|
5507
|
+
}
|
|
5508
|
+
needsReindex(filePath, contentHash) {
|
|
5509
|
+
const row = this.stmts.getFile.get({ file_path: filePath });
|
|
5510
|
+
if (!row)
|
|
5511
|
+
return true;
|
|
5512
|
+
return row.content_hash !== contentHash;
|
|
5513
|
+
}
|
|
5514
|
+
getAllFiles() {
|
|
5515
|
+
return this.stmts.getAllFiles.all();
|
|
5516
|
+
}
|
|
5517
|
+
indexFile(filePath, contentHash, language, lineCount, symbols) {
|
|
5518
|
+
const tx = this.db.transaction(() => {
|
|
5519
|
+
this.stmts.deleteFileSymbols.run({ file_path: filePath });
|
|
5520
|
+
this.stmts.deleteFile.run({ file_path: filePath });
|
|
5521
|
+
this.stmts.insertFile.run({
|
|
5522
|
+
file_path: filePath,
|
|
5523
|
+
content_hash: contentHash,
|
|
5524
|
+
language,
|
|
5525
|
+
last_indexed_at: Date.now(),
|
|
5526
|
+
line_count: lineCount
|
|
5527
|
+
});
|
|
5528
|
+
for (const sym of symbols) {
|
|
5529
|
+
const symbolId = `${filePath}::${sym.name}#${sym.kind}`;
|
|
5530
|
+
this.stmts.insertSymbol.run({
|
|
5531
|
+
file_path: filePath,
|
|
5532
|
+
name: sym.name,
|
|
5533
|
+
kind: sym.kind,
|
|
5534
|
+
start_line: sym.start_line,
|
|
5535
|
+
end_line: sym.end_line,
|
|
5536
|
+
byte_offset_start: sym.byte_offset_start,
|
|
5537
|
+
byte_offset_end: sym.byte_offset_end,
|
|
5538
|
+
signature: sym.signature,
|
|
5539
|
+
is_exported: sym.is_exported ? 1 : 0,
|
|
5540
|
+
symbol_id: symbolId
|
|
5541
|
+
});
|
|
5542
|
+
}
|
|
5543
|
+
});
|
|
5544
|
+
tx();
|
|
5545
|
+
}
|
|
5546
|
+
indexFiles(files) {
|
|
5547
|
+
const tx = this.db.transaction(() => {
|
|
5548
|
+
for (const file of files) {
|
|
5549
|
+
this.stmts.deleteFileSymbols.run({ file_path: file.filePath });
|
|
5550
|
+
this.stmts.deleteFile.run({ file_path: file.filePath });
|
|
5551
|
+
this.stmts.insertFile.run({
|
|
5552
|
+
file_path: file.filePath,
|
|
5553
|
+
content_hash: file.contentHash,
|
|
5554
|
+
language: file.language,
|
|
5555
|
+
last_indexed_at: Date.now(),
|
|
5556
|
+
line_count: file.lineCount
|
|
5557
|
+
});
|
|
5558
|
+
for (const sym of file.symbols) {
|
|
5559
|
+
const symbolId = `${file.filePath}::${sym.name}#${sym.kind}`;
|
|
5560
|
+
this.stmts.insertSymbol.run({
|
|
5561
|
+
file_path: file.filePath,
|
|
5562
|
+
name: sym.name,
|
|
5563
|
+
kind: sym.kind,
|
|
5564
|
+
start_line: sym.start_line,
|
|
5565
|
+
end_line: sym.end_line,
|
|
5566
|
+
byte_offset_start: sym.byte_offset_start,
|
|
5567
|
+
byte_offset_end: sym.byte_offset_end,
|
|
5568
|
+
signature: sym.signature,
|
|
5569
|
+
is_exported: sym.is_exported ? 1 : 0,
|
|
5570
|
+
symbol_id: symbolId
|
|
5571
|
+
});
|
|
5572
|
+
}
|
|
5573
|
+
}
|
|
5574
|
+
});
|
|
5575
|
+
tx();
|
|
5576
|
+
}
|
|
5577
|
+
findByName(name2) {
|
|
5578
|
+
return this.stmts.getSymbolByName.all({ name: name2 });
|
|
5579
|
+
}
|
|
5580
|
+
findById(symbolId) {
|
|
5581
|
+
return this.stmts.getSymbolById.get({ symbol_id: symbolId }) ?? null;
|
|
5582
|
+
}
|
|
5583
|
+
getFileSymbols(filePath) {
|
|
5584
|
+
return this.stmts.getSymbolsByFile.all({ file_path: filePath });
|
|
5585
|
+
}
|
|
5586
|
+
findCallers(symbolId, maxDepth = 3) {
|
|
5587
|
+
const results = [];
|
|
5588
|
+
const visited = new Set;
|
|
5589
|
+
let frontier = [symbolId];
|
|
5590
|
+
for (let depth = 1;depth <= maxDepth && frontier.length > 0; depth++) {
|
|
5591
|
+
const nextFrontier = [];
|
|
5592
|
+
for (const id of frontier) {
|
|
5593
|
+
if (visited.has(id))
|
|
5594
|
+
continue;
|
|
5595
|
+
visited.add(id);
|
|
5596
|
+
const callers = this.stmts.getCallers.all({ callee_id: id });
|
|
5597
|
+
for (const caller of callers) {
|
|
5598
|
+
if (!visited.has(caller.id)) {
|
|
5599
|
+
results.push({ ...caller, depth });
|
|
5600
|
+
nextFrontier.push(caller.id);
|
|
5601
|
+
}
|
|
5602
|
+
}
|
|
5603
|
+
}
|
|
5604
|
+
frontier = nextFrontier;
|
|
5605
|
+
}
|
|
5606
|
+
return results;
|
|
5607
|
+
}
|
|
5608
|
+
findBlastRadius(symbolId) {
|
|
5609
|
+
return this.findCallers(symbolId, 10);
|
|
5610
|
+
}
|
|
5611
|
+
findDeadCode() {
|
|
5612
|
+
return this.stmts.getDeadCode.all();
|
|
5613
|
+
}
|
|
5614
|
+
searchSymbols(query, limit = 20) {
|
|
5615
|
+
const exact = this.db.query("SELECT * FROM symbol_index WHERE name = $q COLLATE NOCASE LIMIT $limit").all({ q: query, limit });
|
|
5616
|
+
if (exact.length > 0)
|
|
5617
|
+
return exact;
|
|
5618
|
+
const prefix = this.db.query("SELECT * FROM symbol_index WHERE name LIKE $q COLLATE NOCASE LIMIT $limit").all({ q: `${query}%`, limit });
|
|
5619
|
+
if (prefix.length > 0)
|
|
5620
|
+
return prefix;
|
|
5621
|
+
return this.db.query("SELECT * FROM symbol_index WHERE name LIKE $q COLLATE NOCASE LIMIT $limit").all({ q: `%${query}%`, limit });
|
|
5622
|
+
}
|
|
5623
|
+
insertCallEdges(edges) {
|
|
5624
|
+
const tx = this.db.transaction(() => {
|
|
5625
|
+
for (const edge of edges) {
|
|
5626
|
+
this.stmts.insertCallEdge.run({
|
|
5627
|
+
caller_id: edge.caller_id,
|
|
5628
|
+
callee_id: edge.callee_id,
|
|
5629
|
+
call_line: edge.call_line
|
|
5630
|
+
});
|
|
5631
|
+
}
|
|
5632
|
+
});
|
|
5633
|
+
tx();
|
|
5634
|
+
}
|
|
5635
|
+
removeStaleFiles(existingPaths) {
|
|
5636
|
+
const allFiles = this.getAllFiles();
|
|
5637
|
+
let removed = 0;
|
|
5638
|
+
const tx = this.db.transaction(() => {
|
|
5639
|
+
for (const file of allFiles) {
|
|
5640
|
+
if (!existingPaths.has(file.file_path)) {
|
|
5641
|
+
this.stmts.deleteFileSymbols.run({ file_path: file.file_path });
|
|
5642
|
+
this.stmts.deleteFile.run({ file_path: file.file_path });
|
|
5643
|
+
removed++;
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
});
|
|
5647
|
+
tx();
|
|
5648
|
+
return removed;
|
|
5649
|
+
}
|
|
5650
|
+
getStats() {
|
|
5651
|
+
const files = this.db.query("SELECT COUNT(*) as c FROM workspace_files").get().c;
|
|
5652
|
+
const symbols = this.db.query("SELECT COUNT(*) as c FROM symbol_index").get().c;
|
|
5653
|
+
const edges = this.db.query("SELECT COUNT(*) as c FROM call_graph").get().c;
|
|
5654
|
+
return { files, symbols, edges };
|
|
5655
|
+
}
|
|
5656
|
+
close() {
|
|
5657
|
+
this.db.close(false);
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
function getIndexDB(projectRoot) {
|
|
5661
|
+
let db = indexCache.get(projectRoot);
|
|
5662
|
+
if (!db) {
|
|
5663
|
+
db = new IndexDB(projectRoot);
|
|
5664
|
+
indexCache.set(projectRoot, db);
|
|
5665
|
+
}
|
|
5666
|
+
return db;
|
|
5667
|
+
}
|
|
5668
|
+
function closeAllIndexDBs() {
|
|
5669
|
+
for (const db of indexCache.values()) {
|
|
5670
|
+
db.close();
|
|
5671
|
+
}
|
|
5672
|
+
indexCache.clear();
|
|
5673
|
+
}
|
|
5674
|
+
var SCHEMA_SQL = `
|
|
5675
|
+
CREATE TABLE IF NOT EXISTS workspace_files (
|
|
5676
|
+
file_path TEXT PRIMARY KEY,
|
|
5677
|
+
content_hash TEXT NOT NULL,
|
|
5678
|
+
language TEXT NOT NULL,
|
|
5679
|
+
last_indexed_at INTEGER NOT NULL,
|
|
5680
|
+
line_count INTEGER NOT NULL DEFAULT 0
|
|
5681
|
+
);
|
|
5682
|
+
|
|
5683
|
+
CREATE TABLE IF NOT EXISTS symbol_index (
|
|
5684
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
5685
|
+
file_path TEXT NOT NULL,
|
|
5686
|
+
name TEXT NOT NULL,
|
|
5687
|
+
kind TEXT NOT NULL,
|
|
5688
|
+
start_line INTEGER NOT NULL,
|
|
5689
|
+
end_line INTEGER NOT NULL,
|
|
5690
|
+
byte_offset_start INTEGER NOT NULL,
|
|
5691
|
+
byte_offset_end INTEGER NOT NULL,
|
|
5692
|
+
signature TEXT,
|
|
5693
|
+
is_exported INTEGER NOT NULL DEFAULT 0,
|
|
5694
|
+
symbol_id TEXT NOT NULL,
|
|
5695
|
+
FOREIGN KEY (file_path) REFERENCES workspace_files(file_path) ON DELETE CASCADE
|
|
5696
|
+
);
|
|
5697
|
+
|
|
5698
|
+
CREATE TABLE IF NOT EXISTS call_graph (
|
|
5699
|
+
caller_id INTEGER NOT NULL,
|
|
5700
|
+
callee_id INTEGER NOT NULL,
|
|
5701
|
+
call_line INTEGER NOT NULL,
|
|
5702
|
+
PRIMARY KEY (caller_id, callee_id, call_line),
|
|
5703
|
+
FOREIGN KEY (caller_id) REFERENCES symbol_index(id) ON DELETE CASCADE,
|
|
5704
|
+
FOREIGN KEY (callee_id) REFERENCES symbol_index(id) ON DELETE CASCADE
|
|
5705
|
+
);
|
|
5706
|
+
|
|
5707
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbol_index(name);
|
|
5708
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_name_kind ON symbol_index(name, kind);
|
|
5709
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbol_index(file_path);
|
|
5710
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_id ON symbol_index(symbol_id);
|
|
5711
|
+
CREATE INDEX IF NOT EXISTS idx_call_graph_callee ON call_graph(callee_id);
|
|
5712
|
+
CREATE INDEX IF NOT EXISTS idx_call_graph_caller ON call_graph(caller_id);
|
|
5713
|
+
|
|
5714
|
+
CREATE TABLE IF NOT EXISTS index_meta (
|
|
5715
|
+
key TEXT PRIMARY KEY,
|
|
5716
|
+
value TEXT NOT NULL
|
|
5717
|
+
);
|
|
5718
|
+
`, SCHEMA_VERSION = "2", indexCache;
|
|
5719
|
+
var init_index_db = __esm(() => {
|
|
5720
|
+
indexCache = new Map;
|
|
5721
|
+
});
|
|
5722
|
+
|
|
5723
|
+
// src/tools/reader/indexer.ts
|
|
5724
|
+
var exports_indexer = {};
|
|
5725
|
+
__export(exports_indexer, {
|
|
5726
|
+
hasIndex: () => hasIndex,
|
|
5727
|
+
buildIndex: () => buildIndex
|
|
5728
|
+
});
|
|
5729
|
+
import { join as join4 } from "path";
|
|
5730
|
+
async function buildIndex(projectRoot) {
|
|
5731
|
+
const start2 = Date.now();
|
|
5732
|
+
const db = getIndexDB(projectRoot);
|
|
5733
|
+
const filePaths = await discoverFiles(projectRoot);
|
|
5734
|
+
const existingPaths = new Set(filePaths.map((f) => f.relativePath));
|
|
5735
|
+
db.removeStaleFiles(existingPaths);
|
|
5736
|
+
const toIndex = [];
|
|
5737
|
+
let fromCache = 0;
|
|
5738
|
+
for (const file of filePaths) {
|
|
5739
|
+
const content = await readFileContent(file.absolutePath);
|
|
5740
|
+
if (!content)
|
|
5741
|
+
continue;
|
|
5742
|
+
const hash = hashContent(content);
|
|
5743
|
+
if (!db.needsReindex(file.relativePath, hash)) {
|
|
5744
|
+
fromCache++;
|
|
5745
|
+
continue;
|
|
5746
|
+
}
|
|
5747
|
+
const lang = detectLanguage(file.relativePath);
|
|
5748
|
+
if (!lang)
|
|
5749
|
+
continue;
|
|
5750
|
+
toIndex.push({
|
|
5751
|
+
relativePath: file.relativePath,
|
|
5752
|
+
absolutePath: file.absolutePath,
|
|
5753
|
+
content,
|
|
5754
|
+
hash,
|
|
5755
|
+
language: lang
|
|
5756
|
+
});
|
|
5757
|
+
}
|
|
5758
|
+
const fileBatch = [];
|
|
5759
|
+
let totalSymbols = 0;
|
|
5760
|
+
for (const file of toIndex) {
|
|
5761
|
+
try {
|
|
5762
|
+
const parsed = await parseFile(file.relativePath, file.content);
|
|
5763
|
+
if (!parsed)
|
|
5764
|
+
continue;
|
|
5765
|
+
const lineCount = file.content.split(`
|
|
5766
|
+
`).length;
|
|
5767
|
+
const symbols = parsed.symbols.map((sym) => {
|
|
5768
|
+
const lines = file.content.split(`
|
|
5769
|
+
`);
|
|
5770
|
+
let byteStart = 0;
|
|
5771
|
+
for (let i2 = 0;i2 < sym.startLine - 1 && i2 < lines.length; i2++) {
|
|
5772
|
+
byteStart += lines[i2].length + 1;
|
|
5773
|
+
}
|
|
5774
|
+
let byteEnd = byteStart;
|
|
5775
|
+
for (let i2 = sym.startLine - 1;i2 < sym.endLine && i2 < lines.length; i2++) {
|
|
5776
|
+
byteEnd += lines[i2].length + 1;
|
|
5777
|
+
}
|
|
5778
|
+
return {
|
|
5779
|
+
name: sym.name,
|
|
5780
|
+
kind: sym.kind,
|
|
5781
|
+
start_line: sym.startLine,
|
|
5782
|
+
end_line: sym.endLine,
|
|
5783
|
+
byte_offset_start: byteStart,
|
|
5784
|
+
byte_offset_end: byteEnd,
|
|
5785
|
+
signature: sym.signature || null,
|
|
5786
|
+
is_exported: sym.isExported ?? false
|
|
5787
|
+
};
|
|
5788
|
+
});
|
|
5789
|
+
totalSymbols += symbols.length;
|
|
5790
|
+
fileBatch.push({
|
|
5791
|
+
filePath: file.relativePath,
|
|
5792
|
+
contentHash: file.hash,
|
|
5793
|
+
language: file.language,
|
|
5794
|
+
lineCount,
|
|
5795
|
+
symbols
|
|
5796
|
+
});
|
|
5797
|
+
} catch (err2) {
|
|
5798
|
+
logger.warn(`Indexer: failed to parse ${file.relativePath}: ${err2.message}`);
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
if (fileBatch.length > 0) {
|
|
5802
|
+
db.indexFiles(fileBatch);
|
|
5803
|
+
}
|
|
5804
|
+
return {
|
|
5805
|
+
files_scanned: filePaths.length,
|
|
5806
|
+
files_indexed: fileBatch.length,
|
|
5807
|
+
files_skipped: filePaths.length - fileBatch.length - fromCache,
|
|
5808
|
+
symbols_indexed: totalSymbols,
|
|
5809
|
+
duration_ms: Date.now() - start2,
|
|
5810
|
+
from_cache: fromCache
|
|
5811
|
+
};
|
|
5812
|
+
}
|
|
5813
|
+
function hasIndex(projectRoot) {
|
|
5814
|
+
const db = getIndexDB(projectRoot);
|
|
5815
|
+
const stats = db.getStats();
|
|
5816
|
+
return stats.files > 0;
|
|
5817
|
+
}
|
|
5818
|
+
async function discoverFiles(root) {
|
|
5819
|
+
const files = [];
|
|
5820
|
+
const glob = new Bun.Glob("**/*");
|
|
5821
|
+
for await (const entry of glob.scan({ cwd: root, onlyFiles: true })) {
|
|
5822
|
+
if (files.length >= MAX_FILES)
|
|
5823
|
+
break;
|
|
5824
|
+
const parts2 = entry.split("/");
|
|
5825
|
+
if (parts2.some((p) => EXCLUDE_DIRS.has(p)))
|
|
5826
|
+
continue;
|
|
5827
|
+
const ext = "." + (entry.split(".").pop()?.toLowerCase() || "");
|
|
5828
|
+
if (!SOURCE_EXTENSIONS2.has(ext))
|
|
5829
|
+
continue;
|
|
5830
|
+
files.push({
|
|
5831
|
+
relativePath: entry,
|
|
5832
|
+
absolutePath: join4(root, entry)
|
|
5833
|
+
});
|
|
5834
|
+
}
|
|
5835
|
+
return files;
|
|
5836
|
+
}
|
|
5837
|
+
async function readFileContent(absolutePath) {
|
|
5838
|
+
try {
|
|
5839
|
+
const file = Bun.file(absolutePath);
|
|
5840
|
+
const size = file.size;
|
|
5841
|
+
if (size > MAX_FILE_SIZE)
|
|
5842
|
+
return null;
|
|
5843
|
+
return await file.text();
|
|
5844
|
+
} catch {
|
|
5845
|
+
return null;
|
|
5846
|
+
}
|
|
5847
|
+
}
|
|
5848
|
+
function hashContent(content) {
|
|
5849
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
5850
|
+
hasher.update(content);
|
|
5851
|
+
return hasher.digest("hex");
|
|
5852
|
+
}
|
|
5853
|
+
var MAX_FILES = 2000, MAX_FILE_SIZE = 1e6, EXCLUDE_DIRS, SOURCE_EXTENSIONS2;
|
|
5854
|
+
var init_indexer = __esm(() => {
|
|
5855
|
+
init_index_db();
|
|
5856
|
+
init_parser();
|
|
5857
|
+
init_logger();
|
|
5858
|
+
EXCLUDE_DIRS = new Set([
|
|
5859
|
+
"node_modules",
|
|
5860
|
+
".git",
|
|
5861
|
+
"dist",
|
|
5862
|
+
"build",
|
|
5863
|
+
".next",
|
|
5864
|
+
".nuxt",
|
|
5865
|
+
".output",
|
|
5866
|
+
"coverage",
|
|
5867
|
+
"__pycache__",
|
|
5868
|
+
".venv",
|
|
5869
|
+
"venv",
|
|
5870
|
+
"target",
|
|
5871
|
+
"vendor",
|
|
5872
|
+
".zephex",
|
|
5873
|
+
".cache",
|
|
5874
|
+
".turbo",
|
|
5875
|
+
"out"
|
|
5876
|
+
]);
|
|
5877
|
+
SOURCE_EXTENSIONS2 = new Set([
|
|
5878
|
+
".ts",
|
|
5879
|
+
".tsx",
|
|
5880
|
+
".js",
|
|
5881
|
+
".jsx",
|
|
5882
|
+
".mjs",
|
|
5883
|
+
".cjs",
|
|
5884
|
+
".py",
|
|
5885
|
+
".go",
|
|
5886
|
+
".java",
|
|
5887
|
+
".rb",
|
|
5888
|
+
".php",
|
|
5889
|
+
".rs",
|
|
5890
|
+
".cs",
|
|
5891
|
+
".cpp",
|
|
5892
|
+
".cc",
|
|
5893
|
+
".c",
|
|
5894
|
+
".h",
|
|
5895
|
+
".hpp",
|
|
5896
|
+
".sh",
|
|
5897
|
+
".kt",
|
|
5898
|
+
".kts",
|
|
5899
|
+
".swift",
|
|
5900
|
+
".scala",
|
|
5901
|
+
".dart",
|
|
5902
|
+
".ex",
|
|
5903
|
+
".exs",
|
|
5904
|
+
".zig",
|
|
5905
|
+
".lua",
|
|
5906
|
+
".vue",
|
|
5907
|
+
".svelte",
|
|
5908
|
+
".astro"
|
|
5909
|
+
]);
|
|
5910
|
+
});
|
|
5911
|
+
|
|
5332
5912
|
// src/tools/reader/readCode.ts
|
|
5333
|
-
import { isAbsolute as isAbsolute2, normalize, relative } from "path";
|
|
5913
|
+
import { isAbsolute as isAbsolute2, normalize, relative, join as join5 } from "path";
|
|
5334
5914
|
import { access as access2, realpath, stat } from "fs/promises";
|
|
5335
5915
|
function iterativeUrlDecode(input) {
|
|
5336
5916
|
let decoded = input;
|
|
@@ -5485,10 +6065,10 @@ function extractSignature(symbol) {
|
|
|
5485
6065
|
docstring = docstringStart.slice(3, -3).trim();
|
|
5486
6066
|
} else {
|
|
5487
6067
|
let foundEnd = false;
|
|
5488
|
-
for (let
|
|
5489
|
-
const line = lines[
|
|
6068
|
+
for (let j2 = i2;j2 < lines.length && j2 < i2 + 20; j2++) {
|
|
6069
|
+
const line = lines[j2] || "";
|
|
5490
6070
|
docLines.push(line);
|
|
5491
|
-
if (
|
|
6071
|
+
if (j2 > i2 && line.includes(quote)) {
|
|
5492
6072
|
foundEnd = true;
|
|
5493
6073
|
break;
|
|
5494
6074
|
}
|
|
@@ -5546,7 +6126,18 @@ function extractDirectImports(fileContent) {
|
|
|
5546
6126
|
}
|
|
5547
6127
|
function isBinaryContent(content) {
|
|
5548
6128
|
const check = content.slice(0, 512);
|
|
5549
|
-
|
|
6129
|
+
if (check.includes("\x00"))
|
|
6130
|
+
return true;
|
|
6131
|
+
const head = check.slice(0, 8);
|
|
6132
|
+
if (head.startsWith("PNG") || head.startsWith("ÿØÿ") || head.startsWith("GIF8") || head.startsWith("PK\x03\x04") || head.startsWith("ELF") || head.startsWith("MZ") || head.startsWith("Êþº¾") || head.startsWith("\x1F") || head.startsWith("RIFF") || head.startsWith("%PDF"))
|
|
6133
|
+
return true;
|
|
6134
|
+
let nonPrintable = 0;
|
|
6135
|
+
for (let i2 = 0;i2 < check.length; i2++) {
|
|
6136
|
+
const c = check.charCodeAt(i2);
|
|
6137
|
+
if (c < 8 || c > 13 && c < 32 && c !== 27)
|
|
6138
|
+
nonPrintable++;
|
|
6139
|
+
}
|
|
6140
|
+
return nonPrintable / check.length > 0.1;
|
|
5550
6141
|
}
|
|
5551
6142
|
function isBinaryFile(filePath) {
|
|
5552
6143
|
const ext = "." + (filePath.split(".").pop()?.toLowerCase() || "");
|
|
@@ -5567,7 +6158,29 @@ function detectFallbackLanguage(filePath) {
|
|
|
5567
6158
|
kts: "kotlin",
|
|
5568
6159
|
swift: "swift",
|
|
5569
6160
|
scala: "scala",
|
|
5570
|
-
sc: "scala"
|
|
6161
|
+
sc: "scala",
|
|
6162
|
+
vue: "vue",
|
|
6163
|
+
svelte: "svelte",
|
|
6164
|
+
astro: "astro",
|
|
6165
|
+
dart: "dart",
|
|
6166
|
+
ex: "elixir",
|
|
6167
|
+
exs: "elixir",
|
|
6168
|
+
zig: "zig",
|
|
6169
|
+
lua: "lua",
|
|
6170
|
+
proto: "protobuf",
|
|
6171
|
+
sol: "solidity",
|
|
6172
|
+
nim: "nim",
|
|
6173
|
+
cr: "crystal",
|
|
6174
|
+
erl: "erlang",
|
|
6175
|
+
hs: "haskell",
|
|
6176
|
+
fs: "fsharp",
|
|
6177
|
+
fsx: "fsharp",
|
|
6178
|
+
ml: "ocaml",
|
|
6179
|
+
mli: "ocaml",
|
|
6180
|
+
jl: "julia",
|
|
6181
|
+
r: "r",
|
|
6182
|
+
m: "objective-c",
|
|
6183
|
+
mm: "objective-c"
|
|
5571
6184
|
};
|
|
5572
6185
|
return map[ext || ""] || null;
|
|
5573
6186
|
}
|
|
@@ -5602,23 +6215,23 @@ function regexSymbolFallback(target, filePath, content, language) {
|
|
|
5602
6215
|
let endLine = Math.min(i2 + 60, lines.length - 1);
|
|
5603
6216
|
if (isPython) {
|
|
5604
6217
|
const baseIndent = (line.match(/^(\s*)/)?.[1] ?? "").length;
|
|
5605
|
-
for (let
|
|
5606
|
-
const l = lines[
|
|
6218
|
+
for (let j2 = i2 + 1;j2 < lines.length; j2++) {
|
|
6219
|
+
const l = lines[j2] ?? "";
|
|
5607
6220
|
if (l.trim() === "")
|
|
5608
6221
|
continue;
|
|
5609
6222
|
const ind = (l.match(/^(\s*)/)?.[1] ?? "").length;
|
|
5610
6223
|
if (ind <= baseIndent) {
|
|
5611
|
-
endLine =
|
|
6224
|
+
endLine = j2 - 1;
|
|
5612
6225
|
break;
|
|
5613
6226
|
}
|
|
5614
|
-
endLine =
|
|
6227
|
+
endLine = j2;
|
|
5615
6228
|
}
|
|
5616
6229
|
} else {
|
|
5617
6230
|
let depth = 0;
|
|
5618
6231
|
let started = false;
|
|
5619
6232
|
const maxScan = Math.min(i2 + 300, lines.length - 1);
|
|
5620
|
-
for (let
|
|
5621
|
-
const l = lines[
|
|
6233
|
+
for (let j2 = i2;j2 <= maxScan; j2++) {
|
|
6234
|
+
const l = lines[j2] ?? "";
|
|
5622
6235
|
const stripped = l.replace(/\/\/.*$/, "").replace(/\/\*.*?\*\//g, "").replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/'(?:[^'\\]|\\.)*'/g, "''").replace(/`(?:[^`\\]|\\.)*`/g, "``");
|
|
5623
6236
|
for (const ch of stripped) {
|
|
5624
6237
|
if (ch === "{") {
|
|
@@ -5627,17 +6240,17 @@ function regexSymbolFallback(target, filePath, content, language) {
|
|
|
5627
6240
|
} else if (ch === "}") {
|
|
5628
6241
|
depth--;
|
|
5629
6242
|
if (started && depth <= 0) {
|
|
5630
|
-
endLine =
|
|
6243
|
+
endLine = j2;
|
|
5631
6244
|
break;
|
|
5632
6245
|
}
|
|
5633
6246
|
}
|
|
5634
6247
|
}
|
|
5635
6248
|
if (started && depth <= 0) {
|
|
5636
|
-
endLine =
|
|
6249
|
+
endLine = j2;
|
|
5637
6250
|
break;
|
|
5638
6251
|
}
|
|
5639
6252
|
if (!started && /[=)]\s*=>\s*[^{]*[,;]?\s*$/.test(l)) {
|
|
5640
|
-
endLine =
|
|
6253
|
+
endLine = j2;
|
|
5641
6254
|
break;
|
|
5642
6255
|
}
|
|
5643
6256
|
}
|
|
@@ -5652,7 +6265,19 @@ function regexSymbolFallback(target, filePath, content, language) {
|
|
|
5652
6265
|
kind = "class";
|
|
5653
6266
|
else if (/\b(interface)\s+/.test(line))
|
|
5654
6267
|
kind = "interface";
|
|
5655
|
-
else if (/\b(
|
|
6268
|
+
else if (/\b(struct)\s+/.test(line))
|
|
6269
|
+
kind = "struct";
|
|
6270
|
+
else if (/\b(enum)\s+/.test(line))
|
|
6271
|
+
kind = "enum";
|
|
6272
|
+
else if (/\b(trait)\s+/.test(line))
|
|
6273
|
+
kind = "trait";
|
|
6274
|
+
else if (/\b(protocol)\s+/.test(line))
|
|
6275
|
+
kind = "protocol";
|
|
6276
|
+
else if (/\b(module|mod)\s+/.test(line))
|
|
6277
|
+
kind = "module";
|
|
6278
|
+
else if (/\b(namespace)\s+/.test(line))
|
|
6279
|
+
kind = "namespace";
|
|
6280
|
+
else if (/\b(type)\s+/.test(line))
|
|
5656
6281
|
kind = "type";
|
|
5657
6282
|
else if (/\b(const|let|var)\s+/.test(line) && !/=>|function/.test(line))
|
|
5658
6283
|
kind = "variable";
|
|
@@ -5717,7 +6342,7 @@ function addLineNumbers(body2, startLine) {
|
|
|
5717
6342
|
}).join(`
|
|
5718
6343
|
`);
|
|
5719
6344
|
}
|
|
5720
|
-
function extractSymbolContent(symbol, detailLevel, fileContent) {
|
|
6345
|
+
function extractSymbolContent(symbol, detailLevel, fileContent, compact) {
|
|
5721
6346
|
const signature = extractSignature(symbol);
|
|
5722
6347
|
const base = {
|
|
5723
6348
|
name: symbol.name,
|
|
@@ -5738,14 +6363,16 @@ function extractSymbolContent(symbol, detailLevel, fileContent) {
|
|
|
5738
6363
|
base.token_estimate = estimateTokens(signature);
|
|
5739
6364
|
return base;
|
|
5740
6365
|
case "body": {
|
|
5741
|
-
const numberedBody = addLineNumbers(symbol.body, symbol.startLine);
|
|
6366
|
+
const numberedBody = compact ? symbol.body : addLineNumbers(symbol.body, symbol.startLine);
|
|
5742
6367
|
base.body = numberedBody;
|
|
5743
6368
|
base.token_estimate = estimateTokens(numberedBody);
|
|
6369
|
+
base.diagnostics = computeDiagnostics(symbol.body, symbol.params?.length ?? 0);
|
|
5744
6370
|
return base;
|
|
5745
6371
|
}
|
|
5746
6372
|
case "context": {
|
|
5747
|
-
const numberedBody = addLineNumbers(symbol.body, symbol.startLine);
|
|
6373
|
+
const numberedBody = compact ? symbol.body : addLineNumbers(symbol.body, symbol.startLine);
|
|
5748
6374
|
base.body = numberedBody;
|
|
6375
|
+
base.diagnostics = computeDiagnostics(symbol.body, symbol.params?.length ?? 0);
|
|
5749
6376
|
base.direct_imports = extractDirectImports(fileContent);
|
|
5750
6377
|
const contextText = numberedBody + `
|
|
5751
6378
|
` + base.direct_imports.join(`
|
|
@@ -5786,8 +6413,8 @@ async function findTestFiles(symbolName, symbolFile, filesToSearch) {
|
|
|
5786
6413
|
async function scanLocalDirectory(dirPath) {
|
|
5787
6414
|
const { readFile } = await import("fs/promises");
|
|
5788
6415
|
const files = {};
|
|
5789
|
-
const
|
|
5790
|
-
const
|
|
6416
|
+
const MAX_FILES2 = 400;
|
|
6417
|
+
const MAX_FILE_SIZE2 = 1048576;
|
|
5791
6418
|
const priorityPatterns = [
|
|
5792
6419
|
"src/**/*",
|
|
5793
6420
|
"lib/**/*",
|
|
@@ -5813,7 +6440,7 @@ async function scanLocalDirectory(dirPath) {
|
|
|
5813
6440
|
return false;
|
|
5814
6441
|
try {
|
|
5815
6442
|
const stats = await stat(filePath);
|
|
5816
|
-
if (!stats.isFile() || stats.size >
|
|
6443
|
+
if (!stats.isFile() || stats.size > MAX_FILE_SIZE2 || stats.size === 0)
|
|
5817
6444
|
return false;
|
|
5818
6445
|
const content = await readFile(filePath, "utf-8");
|
|
5819
6446
|
if (isBinaryContent(content))
|
|
@@ -5827,26 +6454,307 @@ async function scanLocalDirectory(dirPath) {
|
|
|
5827
6454
|
}
|
|
5828
6455
|
}
|
|
5829
6456
|
for (const pattern of priorityPatterns) {
|
|
5830
|
-
if (fileCount >=
|
|
6457
|
+
if (fileCount >= MAX_FILES2)
|
|
5831
6458
|
break;
|
|
5832
6459
|
const glob = new Bun.Glob(pattern);
|
|
5833
6460
|
for await (const filePath of glob.scan({ cwd: dirPath, absolute: true })) {
|
|
5834
|
-
if (fileCount >=
|
|
6461
|
+
if (fileCount >= MAX_FILES2)
|
|
5835
6462
|
break;
|
|
5836
6463
|
await ingest(filePath);
|
|
5837
6464
|
}
|
|
5838
6465
|
}
|
|
5839
|
-
if (fileCount <
|
|
6466
|
+
if (fileCount < MAX_FILES2) {
|
|
5840
6467
|
const glob = new Bun.Glob(fallbackPattern);
|
|
5841
6468
|
for await (const filePath of glob.scan({ cwd: dirPath, absolute: true })) {
|
|
5842
|
-
if (fileCount >=
|
|
6469
|
+
if (fileCount >= MAX_FILES2)
|
|
5843
6470
|
break;
|
|
5844
6471
|
await ingest(filePath);
|
|
5845
6472
|
}
|
|
5846
6473
|
}
|
|
5847
6474
|
return files;
|
|
5848
6475
|
}
|
|
6476
|
+
async function handleFileMode(params, filesToSearch) {
|
|
6477
|
+
const maxTokens = Math.min(params.max_tokens ?? DEFAULT_MAX_TOKENS, MAX_TOKENS_LIMIT);
|
|
6478
|
+
const requestedFiles = params.files ?? [];
|
|
6479
|
+
const offsetLine = Math.max(1, params.offset_line ?? 1);
|
|
6480
|
+
const limitLines = params.limit_lines;
|
|
6481
|
+
const compact = params.compact ?? false;
|
|
6482
|
+
if (requestedFiles.length === 0) {
|
|
6483
|
+
throw new ReadCodeError("mode:'file' requires a `files` array with at least one path", -32602);
|
|
6484
|
+
}
|
|
6485
|
+
const readResults = await Promise.all(requestedFiles.map(async (filePath) => {
|
|
6486
|
+
const content = filesToSearch[filePath] ?? filesToSearch[filePath.startsWith("/") ? filePath.slice(1) : filePath];
|
|
6487
|
+
if (!content) {
|
|
6488
|
+
return {
|
|
6489
|
+
file: filePath,
|
|
6490
|
+
content: `// File not found: ${filePath}`,
|
|
6491
|
+
total_lines: 0,
|
|
6492
|
+
returned_lines: 0,
|
|
6493
|
+
offset: offsetLine,
|
|
6494
|
+
has_more: false,
|
|
6495
|
+
token_estimate: 10,
|
|
6496
|
+
truncated: false
|
|
6497
|
+
};
|
|
6498
|
+
}
|
|
6499
|
+
const allLines = content.split(`
|
|
6500
|
+
`);
|
|
6501
|
+
const totalLines = allLines.length;
|
|
6502
|
+
const startIdx = offsetLine - 1;
|
|
6503
|
+
let endIdx = totalLines;
|
|
6504
|
+
if (limitLines)
|
|
6505
|
+
endIdx = Math.min(startIdx + limitLines, totalLines);
|
|
6506
|
+
const slicedLines = allLines.slice(startIdx, endIdx);
|
|
6507
|
+
let outputContent;
|
|
6508
|
+
if (compact) {
|
|
6509
|
+
outputContent = slicedLines.join(`
|
|
6510
|
+
`);
|
|
6511
|
+
} else {
|
|
6512
|
+
const padWidth = String(startIdx + slicedLines.length).length;
|
|
6513
|
+
outputContent = slicedLines.map((line, i2) => `${String(startIdx + i2 + 1).padStart(padWidth)} | ${line}`).join(`
|
|
6514
|
+
`);
|
|
6515
|
+
}
|
|
6516
|
+
const tokenEst = estimateTokens(outputContent);
|
|
6517
|
+
const hasMore = startIdx + slicedLines.length < totalLines;
|
|
6518
|
+
return {
|
|
6519
|
+
file: filePath,
|
|
6520
|
+
content: outputContent,
|
|
6521
|
+
total_lines: totalLines,
|
|
6522
|
+
returned_lines: slicedLines.length,
|
|
6523
|
+
offset: offsetLine,
|
|
6524
|
+
has_more: hasMore,
|
|
6525
|
+
token_estimate: tokenEst,
|
|
6526
|
+
truncated: false
|
|
6527
|
+
};
|
|
6528
|
+
}));
|
|
6529
|
+
const results = [];
|
|
6530
|
+
const remaining = [];
|
|
6531
|
+
let totalTokens = 0;
|
|
6532
|
+
for (const entry of readResults) {
|
|
6533
|
+
if (totalTokens + entry.token_estimate > maxTokens && results.length > 0) {
|
|
6534
|
+
remaining.push(entry.file);
|
|
6535
|
+
continue;
|
|
6536
|
+
}
|
|
6537
|
+
if (totalTokens + entry.token_estimate > maxTokens) {
|
|
6538
|
+
const availableTokens = maxTokens - totalTokens;
|
|
6539
|
+
const availableChars = Math.floor(availableTokens * CHARS_PER_TOKEN);
|
|
6540
|
+
entry.content = entry.content.slice(0, availableChars);
|
|
6541
|
+
entry.returned_lines = entry.content.split(`
|
|
6542
|
+
`).length;
|
|
6543
|
+
entry.token_estimate = estimateTokens(entry.content);
|
|
6544
|
+
entry.truncated = true;
|
|
6545
|
+
}
|
|
6546
|
+
results.push(entry);
|
|
6547
|
+
totalTokens += entry.token_estimate;
|
|
6548
|
+
}
|
|
6549
|
+
return {
|
|
6550
|
+
mode: "file",
|
|
6551
|
+
files: results,
|
|
6552
|
+
total_tokens_returned: totalTokens,
|
|
6553
|
+
remaining: remaining.length > 0 ? remaining : undefined
|
|
6554
|
+
};
|
|
6555
|
+
}
|
|
6556
|
+
async function handleOutlineMode(params, filesToSearch) {
|
|
6557
|
+
const requestedFiles = params.files ?? [];
|
|
6558
|
+
if (requestedFiles.length === 0) {
|
|
6559
|
+
throw new ReadCodeError("mode:'outline' requires a `files` array with at least one path", -32602);
|
|
6560
|
+
}
|
|
6561
|
+
const filePath = requestedFiles[0];
|
|
6562
|
+
const content = filesToSearch[filePath] ?? filesToSearch[filePath.startsWith("/") ? filePath.slice(1) : filePath];
|
|
6563
|
+
if (!content) {
|
|
6564
|
+
throw new ReadCodeError(`File not found: ${filePath}`, -32602);
|
|
6565
|
+
}
|
|
6566
|
+
const totalLines = content.split(`
|
|
6567
|
+
`).length;
|
|
6568
|
+
const symbols = [];
|
|
6569
|
+
const lang = detectLanguage(filePath);
|
|
6570
|
+
if (lang) {
|
|
6571
|
+
try {
|
|
6572
|
+
const cached = await getOrParse(filePath, content);
|
|
6573
|
+
for (const sym of cached.symbols) {
|
|
6574
|
+
if (sym.name === "anonymous" || sym.kind === "method")
|
|
6575
|
+
continue;
|
|
6576
|
+
symbols.push({
|
|
6577
|
+
name: sym.name,
|
|
6578
|
+
kind: sym.kind,
|
|
6579
|
+
line: sym.startLine,
|
|
6580
|
+
end_line: sym.endLine,
|
|
6581
|
+
signature: sym.signature || sym.body.split(`
|
|
6582
|
+
`)[0]?.trim().slice(0, 200) || sym.name,
|
|
6583
|
+
is_exported: sym.isExported ?? false
|
|
6584
|
+
});
|
|
6585
|
+
}
|
|
6586
|
+
} catch {}
|
|
6587
|
+
}
|
|
6588
|
+
if (symbols.length === 0) {
|
|
6589
|
+
const lines = content.split(`
|
|
6590
|
+
`);
|
|
6591
|
+
const defPattern = /^(?:export\s+)?(?:default\s+)?(?:async\s+)?(?:function\*?|class|interface|type|enum|struct|trait|const|let|var|def|fn|pub\s+fn|func|module|namespace)\s+(\w+)/;
|
|
6592
|
+
for (let i2 = 0;i2 < lines.length; i2++) {
|
|
6593
|
+
const match = lines[i2]?.match(defPattern);
|
|
6594
|
+
if (match) {
|
|
6595
|
+
symbols.push({
|
|
6596
|
+
name: match[1],
|
|
6597
|
+
kind: "function",
|
|
6598
|
+
line: i2 + 1,
|
|
6599
|
+
end_line: i2 + 1,
|
|
6600
|
+
signature: lines[i2].trim().slice(0, 200),
|
|
6601
|
+
is_exported: /^export\b/.test(lines[i2])
|
|
6602
|
+
});
|
|
6603
|
+
}
|
|
6604
|
+
}
|
|
6605
|
+
}
|
|
6606
|
+
const topLevel = [];
|
|
6607
|
+
for (let i2 = 0;i2 < symbols.length; i2++) {
|
|
6608
|
+
const sym = symbols[i2];
|
|
6609
|
+
const isNested = symbols.some((other, j2) => j2 !== i2 && other.line < sym.line && other.end_line > sym.end_line);
|
|
6610
|
+
if (!isNested)
|
|
6611
|
+
topLevel.push(sym);
|
|
6612
|
+
}
|
|
6613
|
+
const outputText = topLevel.map((s) => `${s.line}: ${s.signature}`).join(`
|
|
6614
|
+
`);
|
|
6615
|
+
return {
|
|
6616
|
+
mode: "outline",
|
|
6617
|
+
file: filePath,
|
|
6618
|
+
total_lines: totalLines,
|
|
6619
|
+
symbols: topLevel,
|
|
6620
|
+
total_tokens_returned: estimateTokens(outputText)
|
|
6621
|
+
};
|
|
6622
|
+
}
|
|
5849
6623
|
async function handleReadCode(params) {
|
|
6624
|
+
const mode = params.mode ?? "symbol";
|
|
6625
|
+
if (mode === "callers" || mode === "blast_radius" || mode === "dead_code") {
|
|
6626
|
+
if (!params.path || isRemoteGitUrl(params.path)) {
|
|
6627
|
+
throw new ReadCodeError(`mode:'${mode}' requires a local 'path' with an existing index`, -32602);
|
|
6628
|
+
}
|
|
6629
|
+
const validatedPath = await validatePath(params.path);
|
|
6630
|
+
const { getIndexDB: getIndexDB2 } = await Promise.resolve().then(() => (init_index_db(), exports_index_db));
|
|
6631
|
+
const { hasIndex: hasIndex2 } = await Promise.resolve().then(() => (init_indexer(), exports_indexer));
|
|
6632
|
+
if (!hasIndex2(validatedPath)) {
|
|
6633
|
+
throw new ReadCodeError(`No index found. Call read_code with mode:'symbol' first to build the index.`, -32602);
|
|
6634
|
+
}
|
|
6635
|
+
const db = getIndexDB2(validatedPath);
|
|
6636
|
+
if (mode === "dead_code") {
|
|
6637
|
+
const dead = db.findDeadCode();
|
|
6638
|
+
return {
|
|
6639
|
+
mode: "dead_code",
|
|
6640
|
+
symbols: dead.slice(0, 50).map((s) => ({
|
|
6641
|
+
name: s.name,
|
|
6642
|
+
kind: s.kind,
|
|
6643
|
+
file: s.file_path,
|
|
6644
|
+
line: s.start_line,
|
|
6645
|
+
end_line: s.end_line,
|
|
6646
|
+
symbol_id: s.symbol_id,
|
|
6647
|
+
is_exported: s.is_exported === 1,
|
|
6648
|
+
signature: s.signature || s.name
|
|
6649
|
+
})),
|
|
6650
|
+
total_found: dead.length
|
|
6651
|
+
};
|
|
6652
|
+
}
|
|
6653
|
+
if (!params.target && !params.symbol_id) {
|
|
6654
|
+
throw new ReadCodeError(`mode:'${mode}' requires a 'target' or 'symbol_id'`, -32602);
|
|
6655
|
+
}
|
|
6656
|
+
let targetSym = null;
|
|
6657
|
+
if (params.symbol_id) {
|
|
6658
|
+
const found = db.findById(params.symbol_id);
|
|
6659
|
+
if (found)
|
|
6660
|
+
targetSym = found;
|
|
6661
|
+
}
|
|
6662
|
+
if (!targetSym && params.target) {
|
|
6663
|
+
const matches = db.findByName(params.target);
|
|
6664
|
+
if (matches.length > 0)
|
|
6665
|
+
targetSym = matches[0];
|
|
6666
|
+
}
|
|
6667
|
+
if (!targetSym) {
|
|
6668
|
+
throw new ReadCodeError(`Symbol not found in index: ${params.target || params.symbol_id}`, -32602);
|
|
6669
|
+
}
|
|
6670
|
+
const depth = mode === "blast_radius" ? 10 : 3;
|
|
6671
|
+
const results = db.findCallers(targetSym.id, depth);
|
|
6672
|
+
return {
|
|
6673
|
+
mode,
|
|
6674
|
+
target: targetSym.name,
|
|
6675
|
+
target_symbol_id: targetSym.symbol_id,
|
|
6676
|
+
callers: results.map((r) => ({
|
|
6677
|
+
name: r.name,
|
|
6678
|
+
kind: r.kind,
|
|
6679
|
+
file: r.file_path,
|
|
6680
|
+
line: r.start_line,
|
|
6681
|
+
call_line: r.call_line,
|
|
6682
|
+
depth: r.depth,
|
|
6683
|
+
symbol_id: r.symbol_id
|
|
6684
|
+
})),
|
|
6685
|
+
total_found: results.length
|
|
6686
|
+
};
|
|
6687
|
+
}
|
|
6688
|
+
if (mode === "file" || mode === "outline") {
|
|
6689
|
+
let filesToSearch2;
|
|
6690
|
+
if (params.inline_files && Object.keys(params.inline_files).length > 0) {
|
|
6691
|
+
filesToSearch2 = params.inline_files;
|
|
6692
|
+
} else if (params.path) {
|
|
6693
|
+
if (isRemoteGitUrl(params.path)) {
|
|
6694
|
+
return await withResolvedPath(params.path, async (localPath) => {
|
|
6695
|
+
const files = await scanLocalDirectory(localPath);
|
|
6696
|
+
if (mode === "file")
|
|
6697
|
+
return handleFileMode(params, files);
|
|
6698
|
+
return handleOutlineMode(params, files);
|
|
6699
|
+
});
|
|
6700
|
+
}
|
|
6701
|
+
const validatedPath = await validatePath(params.path);
|
|
6702
|
+
filesToSearch2 = await scanLocalDirectory(validatedPath);
|
|
6703
|
+
} else {
|
|
6704
|
+
throw new ReadCodeError("Either 'path' or 'inline_files' is required", -32602);
|
|
6705
|
+
}
|
|
6706
|
+
if (mode === "file")
|
|
6707
|
+
return handleFileMode(params, filesToSearch2);
|
|
6708
|
+
return handleOutlineMode(params, filesToSearch2);
|
|
6709
|
+
}
|
|
6710
|
+
if (!params.target && !params.symbol_id) {
|
|
6711
|
+
throw new ReadCodeError("mode:'symbol' requires a `target` or `symbol_id` parameter", -32602);
|
|
6712
|
+
}
|
|
6713
|
+
if (params.symbol_id && params.path && !isRemoteGitUrl(params.path)) {
|
|
6714
|
+
try {
|
|
6715
|
+
const { getIndexDB: getIndexDB2 } = await Promise.resolve().then(() => (init_index_db(), exports_index_db));
|
|
6716
|
+
const { hasIndex: hasIndex2 } = await Promise.resolve().then(() => (init_indexer(), exports_indexer));
|
|
6717
|
+
const validatedPath = await validatePath(params.path);
|
|
6718
|
+
if (hasIndex2(validatedPath)) {
|
|
6719
|
+
const db = getIndexDB2(validatedPath);
|
|
6720
|
+
const sym = db.findById(params.symbol_id);
|
|
6721
|
+
if (sym) {
|
|
6722
|
+
const abs = join5(validatedPath, sym.file_path);
|
|
6723
|
+
const content = await Bun.file(abs).text();
|
|
6724
|
+
const lines = content.split(`
|
|
6725
|
+
`);
|
|
6726
|
+
const body2 = lines.slice(sym.start_line - 1, sym.end_line).join(`
|
|
6727
|
+
`);
|
|
6728
|
+
const numberedBody = params.compact ? body2 : addLineNumbers(body2, sym.start_line);
|
|
6729
|
+
return {
|
|
6730
|
+
target: sym.name,
|
|
6731
|
+
symbols: [{
|
|
6732
|
+
name: sym.name,
|
|
6733
|
+
kind: sym.kind,
|
|
6734
|
+
file: sym.file_path,
|
|
6735
|
+
line: sym.start_line,
|
|
6736
|
+
end_line: sym.end_line,
|
|
6737
|
+
language: detectLanguage(sym.file_path) || "unknown",
|
|
6738
|
+
signature: sym.signature || lines[sym.start_line - 1]?.trim().slice(0, 200) || sym.name,
|
|
6739
|
+
confidence: 1,
|
|
6740
|
+
is_definition: true,
|
|
6741
|
+
is_exported: sym.is_exported === 1,
|
|
6742
|
+
body: numberedBody,
|
|
6743
|
+
token_estimate: estimateTokens(numberedBody),
|
|
6744
|
+
truncated: false,
|
|
6745
|
+
symbol_id: sym.symbol_id
|
|
6746
|
+
}],
|
|
6747
|
+
total_found: 1,
|
|
6748
|
+
returned_count: 1,
|
|
6749
|
+
truncated: false,
|
|
6750
|
+
total_tokens_returned: estimateTokens(numberedBody),
|
|
6751
|
+
tokens_saved_vs_full_files: estimateTokens(content) - estimateTokens(numberedBody),
|
|
6752
|
+
session_dedup_skipped: 0
|
|
6753
|
+
};
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
} catch {}
|
|
6757
|
+
}
|
|
5850
6758
|
let maxTokens = params.max_tokens ?? DEFAULT_MAX_TOKENS;
|
|
5851
6759
|
if (params.max_lines && !params.max_tokens) {
|
|
5852
6760
|
maxTokens = Math.ceil(params.max_lines * 12);
|
|
@@ -5873,7 +6781,15 @@ async function handleReadCode(params) {
|
|
|
5873
6781
|
include_tests = false,
|
|
5874
6782
|
session_id
|
|
5875
6783
|
} = params;
|
|
5876
|
-
|
|
6784
|
+
if (!target) {
|
|
6785
|
+
const fallbackTarget = params.symbol_id?.split("::")[1]?.split("#")[0];
|
|
6786
|
+
if (!fallbackTarget) {
|
|
6787
|
+
throw new ReadCodeError("mode:'symbol' requires a `target` or valid `symbol_id`", -32602);
|
|
6788
|
+
}
|
|
6789
|
+
params.target = fallbackTarget;
|
|
6790
|
+
}
|
|
6791
|
+
const effectiveTarget = target || params.symbol_id?.split("::")[1]?.split("#")[0] || "";
|
|
6792
|
+
const allTargets = [effectiveTarget, ...targets || []].slice(0, 9);
|
|
5877
6793
|
const validatedTargets = allTargets.map(validateTarget);
|
|
5878
6794
|
const clampedMaxResults = Math.min(Math.max(1, max_results), MAX_RESULTS_LIMIT);
|
|
5879
6795
|
const clampedThreshold = Math.min(Math.max(0, confidence_threshold), 1);
|
|
@@ -5900,9 +6816,42 @@ async function handleReadCode(params) {
|
|
|
5900
6816
|
return result;
|
|
5901
6817
|
} else {
|
|
5902
6818
|
const validatedPath = await validatePath(projectPath);
|
|
5903
|
-
|
|
6819
|
+
if (params.use_index !== false) {
|
|
6820
|
+
try {
|
|
6821
|
+
const { hasIndex: hasIndex2, buildIndex: buildIndex2 } = await Promise.resolve().then(() => (init_indexer(), exports_indexer));
|
|
6822
|
+
const { getIndexDB: getIndexDB2 } = await Promise.resolve().then(() => (init_index_db(), exports_index_db));
|
|
6823
|
+
if (!hasIndex2(validatedPath)) {
|
|
6824
|
+
buildIndex2(validatedPath).catch((err2) => logger.warn(`Index build failed: ${err2.message}`));
|
|
6825
|
+
} else {
|
|
6826
|
+
const db = getIndexDB2(validatedPath);
|
|
6827
|
+
const indexHits = [];
|
|
6828
|
+
for (const t of validatedTargets) {
|
|
6829
|
+
const matches = db.searchSymbols(t, clampedMaxResults);
|
|
6830
|
+
for (const m of matches) {
|
|
6831
|
+
if (!kind || m.kind === kind) {
|
|
6832
|
+
indexHits.push({ file_path: m.file_path, name: m.name });
|
|
6833
|
+
}
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
if (indexHits.length > 0) {
|
|
6837
|
+
const uniqueFiles = [...new Set(indexHits.map((h) => h.file_path))];
|
|
6838
|
+
filesToSearch = {};
|
|
6839
|
+
for (const fp of uniqueFiles.slice(0, 50)) {
|
|
6840
|
+
try {
|
|
6841
|
+
const abs = join5(validatedPath, fp);
|
|
6842
|
+
const content = await Bun.file(abs).text();
|
|
6843
|
+
filesToSearch[fp] = content;
|
|
6844
|
+
} catch {}
|
|
6845
|
+
}
|
|
6846
|
+
}
|
|
6847
|
+
}
|
|
6848
|
+
} catch {}
|
|
6849
|
+
}
|
|
6850
|
+
if (!filesToSearch || Object.keys(filesToSearch).length === 0) {
|
|
6851
|
+
filesToSearch = await scanLocalDirectory(validatedPath);
|
|
6852
|
+
}
|
|
5904
6853
|
if (Object.keys(filesToSearch).length === 0) {
|
|
5905
|
-
throw new ReadCodeError(`No supported source files found in ${projectPath}. Supported extensions: .ts, .tsx, .js, .jsx, .py, .go, .java, .rb, .php, .rs, .cs, .cpp, .cc, .h, .sh, .sql, .prisma, .graphql`, -32602);
|
|
6854
|
+
throw new ReadCodeError(`No supported source files found in ${projectPath}. Supported extensions: .ts, .tsx, .js, .jsx, .mjs, .cjs, .py, .go, .java, .rb, .php, .rs, .cs, .cpp, .cc, .c, .h, .hpp, .sh, .kt, .swift, .scala, .dart, .ex, .exs, .zig, .lua, .vue, .svelte, .astro, .sql, .prisma, .graphql, .proto`, -32602);
|
|
5906
6855
|
}
|
|
5907
6856
|
}
|
|
5908
6857
|
} else {
|
|
@@ -5979,18 +6928,36 @@ async function handleReadCode(params) {
|
|
|
5979
6928
|
filteredMatches = allMatches.filter((s) => s.kind === kind);
|
|
5980
6929
|
}
|
|
5981
6930
|
const primaryTarget = validatedTargets[0];
|
|
5982
|
-
const
|
|
5983
|
-
|
|
6931
|
+
const isBatched = validatedTargets.length > 1;
|
|
6932
|
+
let scoredMatches;
|
|
6933
|
+
if (isBatched) {
|
|
6934
|
+
const perTargetResults = [];
|
|
6935
|
+
const usedKeys = new Set;
|
|
5984
6936
|
for (const t of validatedTargets) {
|
|
5985
|
-
const
|
|
5986
|
-
|
|
5987
|
-
|
|
6937
|
+
const targetMatches = filteredMatches.map((symbol) => ({
|
|
6938
|
+
...symbol,
|
|
6939
|
+
confidence: computeConfidence(symbol, t, context_path)
|
|
6940
|
+
})).filter((s) => s.confidence >= clampedThreshold).sort((a, b) => b.confidence - a.confidence).slice(0, clampedMaxResults);
|
|
6941
|
+
for (const m of targetMatches) {
|
|
6942
|
+
const key = `${m.name}::${m.file}::${m.startLine}`;
|
|
6943
|
+
if (!usedKeys.has(key)) {
|
|
6944
|
+
usedKeys.add(key);
|
|
6945
|
+
perTargetResults.push(m);
|
|
6946
|
+
}
|
|
6947
|
+
}
|
|
5988
6948
|
}
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
6949
|
+
scoredMatches = perTargetResults.sort((a, b) => b.confidence - a.confidence);
|
|
6950
|
+
} else {
|
|
6951
|
+
scoredMatches = filteredMatches.map((symbol) => {
|
|
6952
|
+
let bestConfidence = 0;
|
|
6953
|
+
for (const t of validatedTargets) {
|
|
6954
|
+
const conf = computeConfidence(symbol, t, context_path);
|
|
6955
|
+
if (conf > bestConfidence)
|
|
6956
|
+
bestConfidence = conf;
|
|
6957
|
+
}
|
|
6958
|
+
return { ...symbol, confidence: bestConfidence };
|
|
6959
|
+
}).filter((s) => s.confidence >= clampedThreshold).sort((a, b) => b.confidence - a.confidence).slice(0, clampedMaxResults);
|
|
6960
|
+
}
|
|
5994
6961
|
const totalFileTokens = estimateTotalFileTokens(filesToSearch);
|
|
5995
6962
|
if (scoredMatches.length === 0) {
|
|
5996
6963
|
const insufficientHint = buildInsufficientSourceHint(primaryTarget, inline_files, { tool: "read_code" });
|
|
@@ -6036,7 +7003,7 @@ async function handleReadCode(params) {
|
|
|
6036
7003
|
continue;
|
|
6037
7004
|
}
|
|
6038
7005
|
const fileContent = filesToSearch[symbol.file] ?? "";
|
|
6039
|
-
const extracted = extractSymbolContent(symbol, detail_level, fileContent);
|
|
7006
|
+
const extracted = extractSymbolContent(symbol, detail_level, fileContent, params.compact);
|
|
6040
7007
|
extracted.confidence = symbol.confidence;
|
|
6041
7008
|
if (params.max_lines && extracted.body) {
|
|
6042
7009
|
const bodyLines = extracted.body.split(`
|
|
@@ -6070,13 +7037,15 @@ async function handleReadCode(params) {
|
|
|
6070
7037
|
totalTokensUsed += extracted.token_estimate;
|
|
6071
7038
|
resultSymbols.push(extracted);
|
|
6072
7039
|
}
|
|
7040
|
+
const shouldIncludeUsages = include_usages || detail_level === "context";
|
|
7041
|
+
const shouldIncludeTests = include_tests || detail_level === "context";
|
|
6073
7042
|
for (const symbol of resultSymbols) {
|
|
6074
7043
|
if (symbol.already_returned_this_session)
|
|
6075
7044
|
continue;
|
|
6076
|
-
if (
|
|
7045
|
+
if (shouldIncludeUsages) {
|
|
6077
7046
|
symbol.usages = await findUsages(symbol.name, filesToSearch, 10);
|
|
6078
7047
|
}
|
|
6079
|
-
if (
|
|
7048
|
+
if (shouldIncludeTests) {
|
|
6080
7049
|
symbol.tests = await findTestFiles(symbol.name, symbol.file, filesToSearch);
|
|
6081
7050
|
}
|
|
6082
7051
|
}
|
|
@@ -6099,7 +7068,7 @@ async function handleReadCode(params) {
|
|
|
6099
7068
|
}
|
|
6100
7069
|
async function handleRemoteRepo(target, url, options) {
|
|
6101
7070
|
return await withResolvedPath(url, async (localPath) => {
|
|
6102
|
-
const glob = new Bun.Glob("**/*.{ts,tsx,js,jsx,py,go,java,rb,php,rs,cs,cpp,cc,h,sh,kt,swift,scala,sql,prisma,graphql,gql}");
|
|
7071
|
+
const glob = new Bun.Glob("**/*.{ts,tsx,js,jsx,mjs,cjs,py,go,java,rb,php,rs,cs,cpp,cc,c,h,hpp,sh,kt,kts,swift,scala,sql,prisma,graphql,gql,vue,svelte,astro,dart,ex,exs,zig,lua,proto}");
|
|
6103
7072
|
const files = {};
|
|
6104
7073
|
const excludePatterns = [
|
|
6105
7074
|
/node_modules/,
|
|
@@ -6112,13 +7081,13 @@ async function handleRemoteRepo(target, url, options) {
|
|
|
6112
7081
|
];
|
|
6113
7082
|
let fileCount = 0;
|
|
6114
7083
|
let skippedCount = 0;
|
|
6115
|
-
const
|
|
6116
|
-
const
|
|
7084
|
+
const MAX_FILES2 = 200;
|
|
7085
|
+
const MAX_FILE_SIZE2 = 1048576;
|
|
6117
7086
|
for await (const filePath of glob.scan({
|
|
6118
7087
|
cwd: localPath,
|
|
6119
7088
|
absolute: true
|
|
6120
7089
|
})) {
|
|
6121
|
-
if (fileCount >=
|
|
7090
|
+
if (fileCount >= MAX_FILES2) {
|
|
6122
7091
|
skippedCount++;
|
|
6123
7092
|
continue;
|
|
6124
7093
|
}
|
|
@@ -6127,7 +7096,7 @@ async function handleRemoteRepo(target, url, options) {
|
|
|
6127
7096
|
continue;
|
|
6128
7097
|
try {
|
|
6129
7098
|
const stats = await stat(filePath);
|
|
6130
|
-
if (stats.size >
|
|
7099
|
+
if (stats.size > MAX_FILE_SIZE2)
|
|
6131
7100
|
continue;
|
|
6132
7101
|
const content = await Bun.file(filePath).text();
|
|
6133
7102
|
if (isBinaryContent(content))
|
|
@@ -6153,7 +7122,7 @@ async function handleRemoteRepo(target, url, options) {
|
|
|
6153
7122
|
session_id: options.session_id
|
|
6154
7123
|
});
|
|
6155
7124
|
if (skippedCount > 0 && !result.error_hint) {
|
|
6156
|
-
result.error_hint = `Warning: Scanned ${
|
|
7125
|
+
result.error_hint = `Warning: Scanned ${MAX_FILES2} of ${MAX_FILES2 + skippedCount} source files. ${skippedCount} files were skipped. If the symbol wasn't found, try using inline_files with the specific file content, or narrow with context_path.`;
|
|
6157
7126
|
}
|
|
6158
7127
|
return result;
|
|
6159
7128
|
});
|
|
@@ -6261,30 +7230,80 @@ var init_readCode = __esm(() => {
|
|
|
6261
7230
|
".graphql",
|
|
6262
7231
|
".gql"
|
|
6263
7232
|
]);
|
|
6264
|
-
FALLBACK_LANGUAGES_NO_AST = new Set([
|
|
7233
|
+
FALLBACK_LANGUAGES_NO_AST = new Set([
|
|
7234
|
+
"kotlin",
|
|
7235
|
+
"swift",
|
|
7236
|
+
"scala",
|
|
7237
|
+
"vue",
|
|
7238
|
+
"svelte",
|
|
7239
|
+
"astro",
|
|
7240
|
+
"dart",
|
|
7241
|
+
"elixir",
|
|
7242
|
+
"zig",
|
|
7243
|
+
"lua",
|
|
7244
|
+
"protobuf",
|
|
7245
|
+
"solidity",
|
|
7246
|
+
"nim",
|
|
7247
|
+
"crystal",
|
|
7248
|
+
"erlang",
|
|
7249
|
+
"haskell",
|
|
7250
|
+
"fsharp",
|
|
7251
|
+
"ocaml",
|
|
7252
|
+
"julia",
|
|
7253
|
+
"r",
|
|
7254
|
+
"objective-c"
|
|
7255
|
+
]);
|
|
6265
7256
|
SCAN_EXTENSIONS = new Set([
|
|
6266
7257
|
".ts",
|
|
6267
7258
|
".tsx",
|
|
6268
7259
|
".js",
|
|
6269
7260
|
".jsx",
|
|
7261
|
+
".mjs",
|
|
7262
|
+
".cjs",
|
|
7263
|
+
".vue",
|
|
7264
|
+
".svelte",
|
|
7265
|
+
".astro",
|
|
6270
7266
|
".py",
|
|
6271
7267
|
".go",
|
|
6272
7268
|
".java",
|
|
7269
|
+
".kt",
|
|
7270
|
+
".kts",
|
|
6273
7271
|
".rb",
|
|
6274
7272
|
".php",
|
|
6275
7273
|
".rs",
|
|
6276
7274
|
".cs",
|
|
6277
7275
|
".cpp",
|
|
6278
7276
|
".cc",
|
|
7277
|
+
".c",
|
|
6279
7278
|
".h",
|
|
7279
|
+
".hpp",
|
|
6280
7280
|
".sh",
|
|
6281
|
-
".kt",
|
|
6282
7281
|
".swift",
|
|
6283
7282
|
".scala",
|
|
7283
|
+
".dart",
|
|
7284
|
+
".ex",
|
|
7285
|
+
".exs",
|
|
7286
|
+
".zig",
|
|
7287
|
+
".lua",
|
|
7288
|
+
".sol",
|
|
7289
|
+
".nim",
|
|
7290
|
+
".cr",
|
|
7291
|
+
".erl",
|
|
7292
|
+
".hs",
|
|
7293
|
+
".fs",
|
|
7294
|
+
".fsx",
|
|
7295
|
+
".ml",
|
|
7296
|
+
".mli",
|
|
7297
|
+
".jl",
|
|
7298
|
+
".r",
|
|
7299
|
+
".R",
|
|
7300
|
+
".m",
|
|
7301
|
+
".mm",
|
|
6284
7302
|
".sql",
|
|
6285
7303
|
".prisma",
|
|
6286
7304
|
".graphql",
|
|
6287
|
-
".gql"
|
|
7305
|
+
".gql",
|
|
7306
|
+
".proto"
|
|
6288
7307
|
]);
|
|
6289
7308
|
SCAN_SKIP_DIRS = new Set([
|
|
6290
7309
|
"node_modules",
|