@wrongstack/tools 0.310.1 → 0.313.1

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.
Files changed (135) hide show
  1. package/dist/_shell-pick.d.ts +5 -10
  2. package/dist/audit.js +10 -4055
  3. package/dist/bash.js +9 -2332
  4. package/dist/batch-tool-use.js +2 -187
  5. package/dist/browser/index.js +25 -1339
  6. package/dist/builtin.js +69 -33985
  7. package/dist/chunk-2CTB3UK5.js +197 -0
  8. package/dist/chunk-2ME7ZWDD.js +1272 -0
  9. package/dist/chunk-2TFQDEPU.js +113 -0
  10. package/dist/chunk-2ZCJNKFE.js +315 -0
  11. package/dist/chunk-3PVYQFRQ.js +472 -0
  12. package/dist/chunk-3QMQBO5Z.js +89 -0
  13. package/dist/chunk-42AKKX7O.js +385 -0
  14. package/dist/chunk-42SKEETB.js +113 -0
  15. package/dist/chunk-4BHUSMNL.js +104 -0
  16. package/dist/chunk-4I4LWFOO.js +431 -0
  17. package/dist/chunk-553IQUMO.js +478 -0
  18. package/dist/chunk-55KF77OK.js +1944 -0
  19. package/dist/chunk-6HLZK37X.js +359 -0
  20. package/dist/chunk-6RNIFLG4.js +305 -0
  21. package/dist/chunk-A6BRWIXN.js +317 -0
  22. package/dist/chunk-AHHDWNXC.js +200 -0
  23. package/dist/chunk-B2CIOKWP.js +899 -0
  24. package/dist/chunk-BTSFTGIL.js +7 -0
  25. package/dist/chunk-D33S4RQG.js +222 -0
  26. package/dist/chunk-DIJKHSUO.js +134 -0
  27. package/dist/chunk-DPL47QGS.js +3515 -0
  28. package/dist/chunk-EMRGN4KM.js +170 -0
  29. package/dist/chunk-FGOABE4Z.js +955 -0
  30. package/dist/chunk-FW65TP4G.js +520 -0
  31. package/dist/chunk-GOIZNNOA.js +221 -0
  32. package/dist/chunk-H5MJUAA6.js +295 -0
  33. package/dist/chunk-H5OHH6F4.js +223 -0
  34. package/dist/chunk-HC5RM4WY.js +199 -0
  35. package/dist/chunk-HEQFMLZ7.js +190 -0
  36. package/dist/chunk-HFXSNKCV.js +196 -0
  37. package/dist/chunk-HXSBQ2SE.js +1723 -0
  38. package/dist/chunk-ILESNGNM.js +163 -0
  39. package/dist/chunk-INF5CGAO.js +137 -0
  40. package/dist/chunk-IWDFZ6XR.js +337 -0
  41. package/dist/chunk-IXMNTNW5.js +238 -0
  42. package/dist/chunk-J4SRJKBW.js +428 -0
  43. package/dist/chunk-J5SKD6LN.js +235 -0
  44. package/dist/chunk-JRJJX3L5.js +424 -0
  45. package/dist/chunk-KXNDHMUB.js +366 -0
  46. package/dist/chunk-LIJQMYYX.js +59 -0
  47. package/dist/chunk-MAN26PZ5.js +260 -0
  48. package/dist/chunk-MKRQMLZA.js +474 -0
  49. package/dist/chunk-NBDZMMG2.js +169 -0
  50. package/dist/chunk-NHA6BEIH.js +101 -0
  51. package/dist/chunk-OA6YJIWL.js +4412 -0
  52. package/dist/chunk-OZC255IC.js +2830 -0
  53. package/dist/chunk-PUR6WU2B.js +154 -0
  54. package/dist/chunk-Q5JPPCZC.js +12 -0
  55. package/dist/chunk-QBV725YG.js +128 -0
  56. package/dist/chunk-QHVW4AAM.js +892 -0
  57. package/dist/chunk-QNJ7AQ4B.js +1000 -0
  58. package/dist/chunk-RGISBZBD.js +231 -0
  59. package/dist/chunk-RJZQWEMS.js +84 -0
  60. package/dist/chunk-RP2ZA47V.js +15 -0
  61. package/dist/chunk-RXISBFR5.js +315 -0
  62. package/dist/chunk-S5CCLZL3.js +99 -0
  63. package/dist/chunk-TVTCSBJF.js +122 -0
  64. package/dist/chunk-U4D5S3VQ.js +21 -0
  65. package/dist/chunk-U4VAATKP.js +193 -0
  66. package/dist/chunk-UKU2ZX4C.js +203 -0
  67. package/dist/chunk-UNSKG6DC.js +159 -0
  68. package/dist/chunk-URFKEIHM.js +1091 -0
  69. package/dist/chunk-UTV7YAW7.js +178 -0
  70. package/dist/chunk-V43EQ6VR.js +68 -0
  71. package/dist/chunk-VB3MJGCV.js +610 -0
  72. package/dist/chunk-WHIIIREL.js +223 -0
  73. package/dist/chunk-XMIFYKUT.js +1371 -0
  74. package/dist/chunk-YF2RSV34.js +54 -0
  75. package/dist/chunk-Z6DAKQ3U.js +1 -0
  76. package/dist/chunk-ZIGAZFWE.js +522 -0
  77. package/dist/circuit-breaker.js +3 -191
  78. package/dist/codebase-index/index.js +84 -13688
  79. package/dist/codebase-index/parser-worker-script.js +8 -3995
  80. package/dist/codebase-index/project-server.js +60 -8548
  81. package/dist/codebase-index/worker.js +20 -8416
  82. package/dist/design.js +2 -299
  83. package/dist/diff.js +4 -256
  84. package/dist/document.js +4 -222
  85. package/dist/e2e.js +5 -476
  86. package/dist/edit.js +14 -10200
  87. package/dist/exec.js +16 -3131
  88. package/dist/fetch.js +8 -398
  89. package/dist/format.js +10 -3750
  90. package/dist/generic-parser-VUXDIAOZ.js +13 -0
  91. package/dist/git.js +4 -380
  92. package/dist/glob.js +6 -280
  93. package/dist/go-parser-6CA77WZ4.js +469 -0
  94. package/dist/grep.js +7 -604
  95. package/dist/index.js +318 -35423
  96. package/dist/install.js +10 -4091
  97. package/dist/json-parser-7YMDJSBJ.js +213 -0
  98. package/dist/json.js +4 -665
  99. package/dist/kanban.js +3 -2096
  100. package/dist/languages/index.js +23 -4664
  101. package/dist/legacy-bridge-7UKZT46G.js +18 -0
  102. package/dist/lint.js +10 -3706
  103. package/dist/logs.js +4 -287
  104. package/dist/memory.js +6 -215
  105. package/dist/mode.js +3 -99
  106. package/dist/outdated.js +4 -5170
  107. package/dist/pack.js +65 -33933
  108. package/dist/parser-dispatch-VPOFDO2U.js +14 -0
  109. package/dist/patch.js +13 -9935
  110. package/dist/plan.js +5 -3286
  111. package/dist/process-registry.js +8 -651
  112. package/dist/ps-slash.js +12 -1439
  113. package/dist/py-parser-GPM5VYRG.js +16 -0
  114. package/dist/read.js +13 -9816
  115. package/dist/replace.js +15 -10014
  116. package/dist/rs-parser-WVQ4KYCX.js +81 -0
  117. package/dist/scaffold.js +4 -253
  118. package/dist/search.js +5 -585
  119. package/dist/session-kanban.js +30 -972
  120. package/dist/skill.js +2 -215
  121. package/dist/task.js +5 -3410
  122. package/dist/test.js +10 -3773
  123. package/dist/todo.js +4 -2891
  124. package/dist/tool-help.js +3 -123
  125. package/dist/tool-search.js +3 -79
  126. package/dist/tool-tier.js +68 -34020
  127. package/dist/tool-use.js +2 -93
  128. package/dist/tree-sitter-parser-YCILHGZD.js +17 -0
  129. package/dist/tree.js +4 -288
  130. package/dist/ts-parser-YH4ZMWMH.js +232 -0
  131. package/dist/typecheck.js +10 -3753
  132. package/dist/win32.js +6 -60
  133. package/dist/write.js +14 -9882
  134. package/dist/yaml-parser-GFAOKV53.js +157 -0
  135. package/package.json +5 -5
package/dist/tool-use.js CHANGED
@@ -1,97 +1,6 @@
1
- // src/tool-use.ts
2
1
  import {
3
- GOVERNED_TOOL_EXECUTOR_META_KEY
4
- } from "@wrongstack/core/types";
5
- var toolUseTool = {
6
- name: "tool_use",
7
- category: "Meta",
8
- description: "Directly execute any registered tool by its exact name, bypassing normal discovery. This is a powerful meta-tool intended for cases where the agent has a clear plan and knows precisely which tool to invoke.",
9
- usageHint: "ADVANCED META TOOL \u2014 USE WITH CARE:\n\n- Only use when you are certain of the exact tool name and its expected input shape.\n- Prefer using the normal tool calling mechanism when possible.\n- Very useful in batch-tool-use or when orchestrating complex workflows programmatically.\n- The call still goes through full permission checks and capability validation.",
10
- permission: "confirm",
11
- // WS-046: gives permission decisions something to key on.
12
- // The tool being invoked through this indirection — the whole point of a
13
- // permission decision here is WHICH tool is being reached.
14
- subjectKey: "tool",
15
- mutating: true,
16
- timeoutMs: 6e4,
17
- capabilities: ["tool.mutate.any"],
18
- icon: "meta",
19
- inputSchema: {
20
- type: "object",
21
- properties: {
22
- tool: {
23
- type: "string",
24
- description: 'The exact registered name of the tool to invoke (e.g. "bash", "read", "codebase-search").'
25
- },
26
- input: {
27
- type: "object",
28
- description: "The input object matching the target tool's inputSchema."
29
- }
30
- },
31
- required: ["tool"]
32
- },
33
- async execute(input, ctx) {
34
- const start = Date.now();
35
- if (!input?.tool) {
36
- return {
37
- tool: "unknown",
38
- success: false,
39
- error: "tool_use: tool name is required",
40
- executionMs: 0
41
- };
42
- }
43
- const tool = (ctx.catalogTools ?? ctx.tools).find((t) => t.name === input.tool);
44
- if (!tool) {
45
- return {
46
- tool: input.tool,
47
- success: false,
48
- error: `tool_use: tool "${input.tool}" not found`,
49
- executionMs: Date.now() - start
50
- };
51
- }
52
- if (tool.name === toolUseTool.name) {
53
- return {
54
- tool: input.tool,
55
- success: false,
56
- error: "tool_use: recursive meta-tool execution is not allowed",
57
- executionMs: Date.now() - start
58
- };
59
- }
60
- if (tool.permission === "deny") {
61
- return {
62
- tool: input.tool,
63
- success: false,
64
- error: `tool_use: tool "${input.tool}" is denied by policy`,
65
- executionMs: Date.now() - start
66
- };
67
- }
68
- const governedExecute = ctx.meta[GOVERNED_TOOL_EXECUTOR_META_KEY];
69
- if (typeof governedExecute !== "function") {
70
- return {
71
- tool: input.tool,
72
- success: false,
73
- error: "tool_use: governed nested execution is unavailable; call the tool directly",
74
- executionMs: Date.now() - start
75
- };
76
- }
77
- try {
78
- const result = await governedExecute(input.tool, input.input ?? {});
79
- return {
80
- tool: input.tool,
81
- success: result.success,
82
- ...result.success ? { result: result.result } : { error: result.error ?? "nested tool failed" },
83
- executionMs: Date.now() - start
84
- };
85
- } catch (e) {
86
- return {
87
- tool: input.tool,
88
- success: false,
89
- error: e instanceof Error ? e.message : String(e),
90
- executionMs: Date.now() - start
91
- };
92
- }
93
- }
94
- };
2
+ toolUseTool
3
+ } from "./chunk-S5CCLZL3.js";
95
4
  export {
96
5
  toolUseTool
97
6
  };
@@ -0,0 +1,17 @@
1
+ import {
2
+ __smokeRootType,
3
+ getGrammarWasmPath,
4
+ isTreeSitterSupported,
5
+ loadTreeSitterLanguage,
6
+ parseSymbols,
7
+ parseTreeSitterAst
8
+ } from "./chunk-B2CIOKWP.js";
9
+ export {
10
+ __smokeRootType,
11
+ getGrammarWasmPath,
12
+ isTreeSitterSupported,
13
+ loadTreeSitterLanguage,
14
+ parseSymbols,
15
+ parseTreeSitterAst
16
+ };
17
+ //# sourceMappingURL=tree-sitter-parser-YCILHGZD.js.map
package/dist/tree.js CHANGED
@@ -1,291 +1,7 @@
1
- // src/tree.ts
2
- import * as fs from "node:fs/promises";
3
- import * as path2 from "node:path";
4
- import { DEFAULT_WALK_IGNORE_DIRS, compileGlob, expectDefined } from "@wrongstack/core/utils";
5
-
6
- // src/_util.ts
7
- import * as fsp from "node:fs/promises";
8
- import * as path from "node:path";
9
- import * as Core from "@wrongstack/core/utils";
10
- function resolvePath(input, ctx) {
11
- return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.workingDir ?? ctx.cwd, input);
12
- }
13
- function allowedRoots(ctx) {
14
- return [path.resolve(ctx.projectRoot), path.resolve(Core.wstackGlobalRoot())];
15
- }
16
- function isInsideAny(target, roots) {
17
- return roots.some((root) => {
18
- const rel = path.relative(root, target);
19
- return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
20
- });
21
- }
22
- function ensureInsideRoot(absPath, ctx) {
23
- const target = path.resolve(absPath);
24
- if (ctx.allowOutsideProjectRoot) return target;
25
- if (isInsideAny(target, allowedRoots(ctx))) return target;
26
- throw new Error(`Path "${absPath}" is outside project root "${path.resolve(ctx.projectRoot)}"`);
27
- }
28
- function safeResolve(input, ctx) {
29
- return ensureInsideRoot(resolvePath(input, ctx), ctx);
30
- }
31
- async function resolveRealInsideRoot(absPath, ctx) {
32
- if (ctx.allowOutsideProjectRoot) return absPath;
33
- const realRoots = await Promise.all(
34
- allowedRoots(ctx).map((r) => fsp.realpath(r).catch(() => path.resolve(r)))
35
- );
36
- let probe = absPath;
37
- const pendingTail = [];
38
- for (; ; ) {
39
- let real;
40
- try {
41
- real = await fsp.realpath(probe);
42
- } catch (err) {
43
- if (err.code === "ENOENT") {
44
- const parent = path.dirname(probe);
45
- if (parent === probe) return absPath;
46
- pendingTail.unshift(path.basename(probe));
47
- probe = parent;
48
- continue;
49
- }
50
- throw err;
51
- }
52
- const candidate = pendingTail.length > 0 ? path.join(real, ...pendingTail) : real;
53
- if (isInsideAny(candidate, realRoots)) {
54
- return candidate;
55
- }
56
- throw new Error(
57
- `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`
58
- );
59
- }
60
- }
61
- async function safeResolveReal(input, ctx) {
62
- const abs = safeResolve(input, ctx);
63
- return await resolveRealInsideRoot(abs, ctx);
64
- }
65
-
66
- // src/tree.ts
67
- var DEFAULT_IGNORE = /* @__PURE__ */ new Set([
68
- ...DEFAULT_WALK_IGNORE_DIRS,
69
- ".wrongstack",
70
- ".ssh",
71
- ".gnupg",
72
- ".aws"
73
- ]);
74
- var DEFAULT_MAX_ENTRIES = 5e3;
75
- var MAX_TREE_OUTPUT_BYTES = 256 * 1024;
76
- var treeTool = {
77
- name: "tree",
78
- category: "Filesystem",
79
- description: "Display a project or subpath directory tree. Use it for structural layout; use index-backed `codebase-search` first for code understanding when it is live.",
80
- usageHint: "DIRECTORY-LAYOUT EXPLORATION:\n\n- When `codebase-search` is live, use it first for symbols and concepts; use `tree` when the directory hierarchy itself matters.\n- Tune `depth` (default 3) and use `glob`/`exclude` to focus the view.\n- Prefer this over raw `bash find` or `glob` + manual reading when you need a quick structural overview.\nOutput is truncated for very large trees.",
81
- permission: "auto",
82
- mutating: false,
83
- capabilities: ["fs.read"],
84
- icon: "tree",
85
- maxOutputBytes: 262144,
86
- timeoutMs: 15e3,
87
- inputSchema: {
88
- type: "object",
89
- properties: {
90
- path: {
91
- type: "string",
92
- description: "Root directory to display the tree from (defaults to project root)."
93
- },
94
- depth: {
95
- type: "integer",
96
- description: "Maximum directory depth to traverse (default 3, use 0 for unlimited).",
97
- minimum: 0,
98
- maximum: 20
99
- },
100
- glob: {
101
- type: "string",
102
- description: "Only include files matching this glob pattern."
103
- },
104
- exclude: {
105
- type: "array",
106
- items: { type: "string" },
107
- description: "List of directory names to completely ignore."
108
- },
109
- show_files: {
110
- type: "boolean",
111
- description: "Whether to show individual files (default true)."
112
- },
113
- show_dirs: {
114
- type: "boolean",
115
- description: "Whether to show directories (default true)."
116
- },
117
- show_hidden: {
118
- type: "boolean",
119
- description: "Show hidden files starting with . (default: false)"
120
- },
121
- max_entries: {
122
- type: "integer",
123
- description: `Maximum entries retained in the rendered tree (default ${DEFAULT_MAX_ENTRIES}).`,
124
- minimum: 1,
125
- maximum: 5e4
126
- }
127
- }
128
- },
129
- async execute(input, ctx, opts) {
130
- let final;
131
- const executeStream = treeTool.executeStream;
132
- if (!executeStream) throw new Error("treeTool: stream execution unavailable");
133
- for await (const ev of executeStream(input, ctx, opts)) {
134
- if (ev.type === "final") final = ev.output;
135
- }
136
- if (!final) throw new Error("tree: stream ended without final event");
137
- return final;
138
- },
139
- async *executeStream(input, ctx, opts) {
140
- const basePath = input.path ? await safeResolveReal(input.path, ctx) : ctx.cwd;
141
- const maxDepth = input.depth ?? 3;
142
- const showFiles = input.show_files ?? true;
143
- const showDirs = input.show_dirs ?? true;
144
- const showHidden = input.show_hidden ?? false;
145
- const exclude = /* @__PURE__ */ new Set([...DEFAULT_IGNORE, ...input.exclude ?? []]);
146
- const globRe = input.glob ? compileGlob(input.glob) : void 0;
147
- const maxEntries = input.max_entries ?? DEFAULT_MAX_ENTRIES;
148
- const signal = opts?.signal ?? ctx.signal ?? new AbortController().signal;
149
- const lines = [basePath];
150
- const totals = { totalFiles: { value: 0 }, totalDirs: { value: 0 } };
151
- const retention = {
152
- entries: 0,
153
- outputBytes: Buffer.byteLength(basePath, "utf8"),
154
- maxEntries,
155
- maxOutputBytes: MAX_TREE_OUTPUT_BYTES,
156
- truncated: false
157
- };
158
- const queue = [];
159
- const FLUSH_EVERY = 200;
160
- let lastEmittedTotal = 0;
161
- const tickProgress = () => {
162
- const seen = totals.totalFiles.value + totals.totalDirs.value;
163
- if (seen - lastEmittedTotal >= FLUSH_EVERY) {
164
- queue.push({
165
- type: "metric",
166
- text: `${seen} entries`,
167
- data: { files: totals.totalFiles.value, dirs: totals.totalDirs.value }
168
- });
169
- lastEmittedTotal = seen;
170
- }
171
- };
172
- const walkPromise = walkDir(basePath, 0, {
173
- maxDepth,
174
- exclude,
175
- showFiles,
176
- showDirs,
177
- showHidden,
178
- globRe,
179
- basePath,
180
- lines,
181
- prefix: "",
182
- isLast: true,
183
- totalFiles: totals.totalFiles,
184
- totalDirs: totals.totalDirs,
185
- onProgress: tickProgress,
186
- retention,
187
- signal
188
- });
189
- let walkDone = false;
190
- void walkPromise.then(
191
- () => {
192
- walkDone = true;
193
- },
194
- () => {
195
- walkDone = true;
196
- }
197
- );
198
- while (!walkDone || queue.length > 0) {
199
- if (queue.length > 0) {
200
- yield expectDefined(queue.shift());
201
- } else {
202
- let pollTimer;
203
- const poll = new Promise((r) => {
204
- pollTimer = setTimeout(r, 50);
205
- });
206
- try {
207
- await Promise.race([walkPromise, poll]).catch(() => void 0);
208
- } finally {
209
- if (pollTimer) clearTimeout(pollTimer);
210
- }
211
- }
212
- }
213
- await walkPromise;
214
- yield {
215
- type: "final",
216
- output: {
217
- tree: lines.join("\n"),
218
- total_files: totals.totalFiles.value,
219
- total_dirs: totals.totalDirs.value,
220
- truncated: retention.truncated,
221
- path: basePath
222
- }
223
- };
224
- }
225
- };
226
- function matchesTreeGlob(globRe, fileName, absPath, basePath) {
227
- if (globRe.test(fileName)) return true;
228
- const rel = path2.relative(basePath, absPath);
229
- const posixRel = !rel || rel.startsWith("..") || path2.isAbsolute(rel) ? absPath.split(path2.sep).join("/") : rel.split(path2.sep).join("/");
230
- return globRe.test(posixRel);
231
- }
232
- async function walkDir(dir, depth, opts) {
233
- opts.signal.throwIfAborted();
234
- if (opts.retention.truncated) return;
235
- const entries = await fs.readdir(dir, { withFileTypes: true }).catch(() => []);
236
- const filtered = entries.filter((e) => {
237
- if (!opts.showHidden && e.name.startsWith(".")) return false;
238
- if (opts.exclude.has(e.name)) return false;
239
- if (e.isFile() && opts.globRe) {
240
- const abs = path2.join(dir, e.name);
241
- if (!matchesTreeGlob(opts.globRe, e.name, abs, opts.basePath)) return false;
242
- }
243
- return true;
244
- });
245
- let dirCount = 0;
246
- let fileCount = 0;
247
- for (const e of filtered) {
248
- if (e.isDirectory()) dirCount++;
249
- else if (e.isFile()) fileCount++;
250
- }
251
- opts.totalDirs.value += dirCount;
252
- opts.totalFiles.value += fileCount;
253
- opts.onProgress?.();
254
- const items = filtered.sort((a, b) => {
255
- if (a.isDirectory() && !b.isDirectory()) return -1;
256
- if (!a.isDirectory() && b.isDirectory()) return 1;
257
- return a.name.localeCompare(b.name);
258
- });
259
- for (let i = 0; i < items.length; i++) {
260
- opts.signal.throwIfAborted();
261
- if (opts.retention.truncated) return;
262
- const entry = items[i];
263
- if (!entry) continue;
264
- const isLast = i === items.length - 1;
265
- const connector = opts.isLast ? " " : "\u2502 ";
266
- const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
267
- const displayName = entry.name + (entry.isDirectory() ? "/" : "");
268
- if (!opts.showDirs && entry.isDirectory()) continue;
269
- if (!opts.showFiles && entry.isFile()) continue;
270
- const line = opts.prefix + branch + displayName;
271
- const lineBytes = Buffer.byteLength(line, "utf8") + 1;
272
- if (opts.retention.entries >= opts.retention.maxEntries || opts.retention.outputBytes + lineBytes > opts.retention.maxOutputBytes) {
273
- opts.retention.truncated = true;
274
- return;
275
- }
276
- opts.lines.push(line);
277
- opts.retention.entries++;
278
- opts.retention.outputBytes += lineBytes;
279
- if (entry.isDirectory() && (opts.maxDepth === 0 || depth < opts.maxDepth)) {
280
- const childPrefix = opts.prefix + connector;
281
- await walkDir(path2.join(dir, entry.name), depth + 1, {
282
- ...opts,
283
- prefix: childPrefix,
284
- isLast
285
- });
286
- }
287
- }
288
- }
1
+ import {
2
+ treeTool
3
+ } from "./chunk-J5SKD6LN.js";
4
+ import "./chunk-D33S4RQG.js";
289
5
  export {
290
6
  treeTool
291
7
  };
@@ -0,0 +1,232 @@
1
+ import {
2
+ detectLang
3
+ } from "./chunk-ILESNGNM.js";
4
+
5
+ // src/codebase-index/ts-parser.ts
6
+ var ts;
7
+ var tsLoad = null;
8
+ function loadTypescript() {
9
+ tsLoad ??= import("@typescript/typescript6").then((m) => {
10
+ ts = m.default ?? m;
11
+ return ts;
12
+ });
13
+ return tsLoad;
14
+ }
15
+ var kindMapCache = null;
16
+ function kindMap() {
17
+ kindMapCache ??= {
18
+ [ts.SyntaxKind.ClassDeclaration]: "class",
19
+ [ts.SyntaxKind.InterfaceDeclaration]: "interface",
20
+ [ts.SyntaxKind.EnumDeclaration]: "enum",
21
+ [ts.SyntaxKind.TypeAliasDeclaration]: "type",
22
+ [ts.SyntaxKind.FunctionDeclaration]: "function",
23
+ [ts.SyntaxKind.MethodDeclaration]: "method",
24
+ [ts.SyntaxKind.GetAccessor]: "property",
25
+ [ts.SyntaxKind.SetAccessor]: "property",
26
+ [ts.SyntaxKind.PropertyDeclaration]: "property",
27
+ [ts.SyntaxKind.Parameter]: "parameter",
28
+ [ts.SyntaxKind.NamespaceExportDeclaration]: "namespace"
29
+ };
30
+ return kindMapCache;
31
+ }
32
+ function kindOf(node) {
33
+ if (ts.isVariableDeclaration(node)) {
34
+ const parent = node.parent;
35
+ if (ts.isVariableDeclarationList(parent)) {
36
+ const flags = parent.flags;
37
+ if (flags & ts.NodeFlags.Let) return "let";
38
+ if (flags & ts.NodeFlags.Const) return "const";
39
+ return "var";
40
+ }
41
+ }
42
+ if (ts.isModuleDeclaration(node)) return "namespace";
43
+ return kindMap()[node.kind] ?? null;
44
+ }
45
+ function getSignature(printer, node, sourceFile) {
46
+ const raw = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
47
+ return raw.replace(/\s+/g, " ").slice(0, 500);
48
+ }
49
+ function getJsDoc(node, sourceFile) {
50
+ const fullText = sourceFile.getFullText();
51
+ const nodePos = node.getFullStart();
52
+ const comments = ts.getLeadingCommentRanges(fullText, nodePos);
53
+ if (!comments) return "";
54
+ for (const range of comments) {
55
+ const commentText = fullText.slice(range.pos, range.end);
56
+ const trimmed = commentText.trim();
57
+ if (trimmed.startsWith("/**") && trimmed.endsWith("*/")) {
58
+ const inner = trimmed.slice(3, -2).replace(/^[ \t]*\*[ ]?/gm, "").trim();
59
+ return inner.split("\n")[0]?.trim().slice(0, 200) ?? "";
60
+ }
61
+ }
62
+ return "";
63
+ }
64
+ function pushScopeName(node, parts) {
65
+ if (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isEnumDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
66
+ parts.push(node.name?.text ?? "Anon");
67
+ } else if (ts.isMethodDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node) || ts.isPropertyDeclaration(node) || ts.isFunctionDeclaration(node)) {
68
+ if (node.name && ts.isIdentifier(node.name)) {
69
+ parts.push(node.name.text);
70
+ }
71
+ }
72
+ }
73
+ async function parseSymbols(opts) {
74
+ const { file, content, lang } = opts;
75
+ await loadTypescript();
76
+ let sourceFile;
77
+ try {
78
+ sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
79
+ } catch {
80
+ return { file, lang, symbols: [], mtimeMs: Date.now() };
81
+ }
82
+ const symbols = [];
83
+ const refs = [];
84
+ const printer = ts.createPrinter({});
85
+ function visit(node, funcDepth, scopeParts) {
86
+ const kind = kindOf(node);
87
+ if (kind) {
88
+ if ((kind === "const" || kind === "let" || kind === "var" || kind === "parameter") && funcDepth > 0) {
89
+ } else {
90
+ const nameNode = node.name;
91
+ if (!nameNode || !ts.isIdentifier(nameNode)) {
92
+ return;
93
+ }
94
+ const name = nameNode.text;
95
+ const pos2 = nameNode.getStart(sourceFile);
96
+ const { line: line2, character } = sourceFile.getLineAndCharacterOfPosition(pos2);
97
+ const scope = scopeParts.join(".");
98
+ const signature = getSignature(printer, node, sourceFile);
99
+ const docComment = getJsDoc(node, sourceFile);
100
+ const text = [name, signature, docComment].filter(Boolean).join(" | ");
101
+ symbols.push({
102
+ id: 0,
103
+ lang,
104
+ kind,
105
+ name,
106
+ file,
107
+ line: line2 + 1,
108
+ col: character,
109
+ signature,
110
+ docComment,
111
+ scope,
112
+ text
113
+ });
114
+ }
115
+ }
116
+ const pos = node.getStart(sourceFile);
117
+ const { line } = sourceFile.getLineAndCharacterOfPosition(pos);
118
+ const lineNum = line + 1;
119
+ if (ts.isCallExpression(node)) {
120
+ const expr = node.expression;
121
+ if (ts.isIdentifier(expr)) {
122
+ refs.push({ fromId: 0, toName: expr.text, callType: "call", line: lineNum });
123
+ }
124
+ } else if (ts.isPropertyAccessExpression(node)) {
125
+ if (ts.isIdentifier(node.expression)) {
126
+ refs.push({ fromId: 0, toName: node.expression.text, callType: "call", line: lineNum });
127
+ }
128
+ } else if (ts.isTypeReferenceNode(node)) {
129
+ const name = getTypeName(node.typeName);
130
+ if (name) refs.push({ fromId: 0, toName: name, callType: "type_ref", line: lineNum });
131
+ } else if (ts.isHeritageClause(node)) {
132
+ for (const t of node.types) {
133
+ const name = getTypeName(t.expression);
134
+ if (name)
135
+ refs.push({
136
+ fromId: 0,
137
+ toName: name,
138
+ callType: node.token === ts.SyntaxKind.ExtendsKeyword ? "inherit" : "implement",
139
+ line: lineNum
140
+ });
141
+ }
142
+ } else if (ts.isImportDeclaration(node)) {
143
+ emitImportSpecifierRefs(node, refs, lineNum);
144
+ } else if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
145
+ emitExportSpecifierRefs(node, refs, lineNum);
146
+ }
147
+ const scopeIdx = scopeParts.length;
148
+ pushScopeName(node, scopeParts);
149
+ const childFuncDepth = ts.isFunctionLike(node) ? funcDepth + 1 : funcDepth;
150
+ ts.forEachChild(node, (child) => visit(child, childFuncDepth, scopeParts));
151
+ scopeParts.length = scopeIdx;
152
+ }
153
+ visit(sourceFile, 0, []);
154
+ return { file, lang, symbols, refs: deduplicateRefs(refs), mtimeMs: Date.now() };
155
+ }
156
+ function getTypeName(name) {
157
+ if (ts.isIdentifier(name)) return name.text;
158
+ if (ts.isQualifiedName(name)) return `${getTypeName(name.left)}.${name.right.text}`;
159
+ return "";
160
+ }
161
+ function deduplicateRefs(refs) {
162
+ const seen = /* @__PURE__ */ new Set();
163
+ return refs.filter((r) => {
164
+ const key = `${r.toName}:${r.callType}:${r.line}:${r.module ?? ""}`;
165
+ if (seen.has(key)) return false;
166
+ seen.add(key);
167
+ return true;
168
+ });
169
+ }
170
+ function getImportSpecifierName(spec) {
171
+ return spec.propertyName?.text ?? spec.name.text;
172
+ }
173
+ function emitImportSpecifierRefs(node, refs, lineNum) {
174
+ const module = moduleSpecifierOf(node.moduleSpecifier);
175
+ const clause = node.importClause;
176
+ if (!clause) {
177
+ if (module) {
178
+ refs.push({ fromId: 0, toName: module, callType: "import", line: lineNum, module });
179
+ }
180
+ return;
181
+ }
182
+ if (clause.name) {
183
+ refs.push({ fromId: 0, toName: clause.name.text, callType: "import", line: lineNum, module });
184
+ }
185
+ const bindings = clause.namedBindings;
186
+ if (!bindings) return;
187
+ if (ts.isNamedImports(bindings)) {
188
+ for (const element of bindings.elements) {
189
+ refs.push({
190
+ fromId: 0,
191
+ toName: getImportSpecifierName(element),
192
+ callType: "import",
193
+ line: lineNum,
194
+ module
195
+ });
196
+ }
197
+ } else if (ts.isNamespaceImport(bindings)) {
198
+ refs.push({
199
+ fromId: 0,
200
+ toName: bindings.name.text,
201
+ callType: "import",
202
+ line: lineNum,
203
+ module
204
+ });
205
+ }
206
+ }
207
+ function moduleSpecifierOf(node) {
208
+ return node && ts.isStringLiteral(node) ? node.text : void 0;
209
+ }
210
+ function emitExportSpecifierRefs(node, refs, lineNum) {
211
+ const module = moduleSpecifierOf(node.moduleSpecifier);
212
+ const clause = node.exportClause;
213
+ if (clause && ts.isNamespaceExport(clause)) {
214
+ refs.push({ fromId: 0, toName: clause.name.text, callType: "import", line: lineNum, module });
215
+ return;
216
+ }
217
+ if (clause && ts.isNamedExports(clause)) {
218
+ for (const element of clause.elements) {
219
+ const originalName = element.propertyName?.text ?? element.name.text;
220
+ refs.push({ fromId: 0, toName: originalName, callType: "import", line: lineNum, module });
221
+ }
222
+ return;
223
+ }
224
+ if (module) {
225
+ refs.push({ fromId: 0, toName: module, callType: "import", line: lineNum, module });
226
+ }
227
+ }
228
+ export {
229
+ detectLang,
230
+ parseSymbols
231
+ };
232
+ //# sourceMappingURL=ts-parser-YH4ZMWMH.js.map