@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
@@ -0,0 +1,13 @@
1
+ import {
2
+ GENERIC_MAX_FILE_CHARS,
3
+ GENERIC_MAX_SYMBOLS_DEFAULT,
4
+ parseGeneric,
5
+ parseSymbols
6
+ } from "./chunk-A6BRWIXN.js";
7
+ export {
8
+ GENERIC_MAX_FILE_CHARS,
9
+ GENERIC_MAX_SYMBOLS_DEFAULT,
10
+ parseGeneric,
11
+ parseSymbols
12
+ };
13
+ //# sourceMappingURL=generic-parser-VUXDIAOZ.js.map
package/dist/git.js CHANGED
@@ -1,383 +1,7 @@
1
- // src/git.ts
2
- import { spawn } from "node:child_process";
3
- import { statSync } from "node:fs";
4
- import { dirname, resolve, sep } from "node:path";
5
- import { assessCommitSafety } from "@wrongstack/core/coordination";
6
- import { buildChildEnv } from "@wrongstack/core/utils";
7
-
8
- // src/_util.ts
9
- import * as Core from "@wrongstack/core/utils";
10
- var COMMAND_OUTPUT_MAX_BYTES = 32768;
11
- var REPEAT_RUN_THRESHOLD = 3;
12
- function collapseCarriageReturns(text) {
13
- const lf = text.replace(/\r\n/g, "\n");
14
- if (!lf.includes("\r")) return lf;
15
- return lf.split("\n").map((line) => line.includes("\r") ? line.slice(line.lastIndexOf("\r") + 1) : line).join("\n");
16
- }
17
- function collapseConsecutiveDuplicates(text, minRun = REPEAT_RUN_THRESHOLD) {
18
- const lines = text.split("\n");
19
- const out = [];
20
- let i = 0;
21
- while (i < lines.length) {
22
- let j = i + 1;
23
- while (j < lines.length && lines[j] === lines[i]) j++;
24
- const run = j - i;
25
- if (run >= minRun) {
26
- out.push(lines[i], `\u2026 \u27E8repeated ${run}\xD7\u27E9`);
27
- } else {
28
- for (let k = i; k < j; k++) out.push(lines[k]);
29
- }
30
- i = j;
31
- }
32
- return out.join("\n");
33
- }
34
- function takeHeadBytes(s, maxBytes) {
35
- if (maxBytes <= 0) return "";
36
- if (Buffer.byteLength(s, "utf8") <= maxBytes) return s;
37
- let lo = 0;
38
- let hi = s.length;
39
- while (lo < hi) {
40
- const mid = Math.ceil((lo + hi) / 2);
41
- if (Buffer.byteLength(s.slice(0, mid), "utf8") <= maxBytes) lo = mid;
42
- else hi = mid - 1;
43
- }
44
- return s.slice(0, lo);
45
- }
46
- function takeTailBytes(s, maxBytes) {
47
- if (maxBytes <= 0) return "";
48
- if (Buffer.byteLength(s, "utf8") <= maxBytes) return s;
49
- let lo = 0;
50
- let hi = s.length;
51
- while (lo < hi) {
52
- const mid = Math.ceil((lo + hi) / 2);
53
- if (Buffer.byteLength(s.slice(s.length - mid), "utf8") <= maxBytes) lo = mid;
54
- else hi = mid - 1;
55
- }
56
- return s.slice(s.length - lo);
57
- }
58
- function truncateHeadTail(s, maxBytes) {
59
- const total = Buffer.byteLength(s, "utf8");
60
- if (total <= maxBytes) return s;
61
- const MARKER_RESERVE = 64;
62
- const avail = Math.max(0, maxBytes - MARKER_RESERVE);
63
- const headBudget = Math.floor(avail * 0.45);
64
- const head = takeHeadBytes(s, headBudget);
65
- const tail = takeTailBytes(s, avail - Buffer.byteLength(head, "utf8"));
66
- const kept = Buffer.byteLength(head, "utf8") + Buffer.byteLength(tail, "utf8");
67
- return `${head}
68
- \u2026[truncated ${total - kept} bytes]\u2026
69
- ${tail}`;
70
- }
71
- function normalizeCommandOutput(raw, opts = {}) {
72
- if (!raw) return raw;
73
- let text = Core.stripAnsi(raw);
74
- text = collapseCarriageReturns(text);
75
- text = text.replace(/[ \t]+$/gm, "");
76
- text = collapseConsecutiveDuplicates(text);
77
- text = text.replace(/\n{3,}/g, "\n\n");
78
- return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);
79
- }
80
-
81
- // src/git.ts
82
- var TIMEOUT_MS = 3e4;
83
- var MAX_OUTPUT = 1e5;
84
- var gitTool = {
85
- name: "git",
86
- category: "Git",
87
- description: "Safe wrapper around common git operations. Supports status, log, diff, commit, branch, checkout, stash, push, pull, fetch, reset, worktree, etc. This is the preferred way to interact with git instead of using the raw `bash` or `exec` tools.",
88
- usageHint: "ALWAYS prefer this tool over raw shell git commands.\n\nKey fields:\n- `command`: one of the supported subcommands (status, log, diff, commit, etc.)\n- Use `message` only for commit operations.\n- Use `files` array for operations that take paths (status, diff, add, etc.).\n- Non-mutating commands (status, log, diff, branch, fetch) are still permission:confirm for safety.\n- For `commit` in a possibly-shared working tree, pass an explicit `files` list scoped to what YOU changed. A bare commit (no `files`) includes ALL staged changes and may capture another agent's half-done work. Heed the `warning` field on the result.\nNever pass raw git flags through `args` for dangerous operations \u2014 use the structured fields.",
89
- permission: "confirm",
90
- icon: "git",
91
- // Conservative: any of these may mutate. The non-mutating commands
92
- // (status/log/diff/branch/fetch) are still gated on `permission: 'confirm'`
93
- // and `MUTATING_SUBCOMMANDS` is consulted at runtime for per-call checks.
94
- // WS-046: gives permission decisions something to key on.
95
- // The git subcommand (status/commit/push) is what a trust rule needs to
96
- // distinguish; `git status` and `git push --force` must not share a subject.
97
- subjectKey: "command",
98
- // `command` is an enum subcommand, so on its own it rendered the subject
99
- // `"push"` — and one "always allow" then covered every push, to any branch,
100
- // with or without `--force`. These are the fields that change what the call
101
- // actually does, so the stored trust rule is as specific as the invocation
102
- // the user approved.
103
- subjectFields: ["branch", "force", "worktreeAction", "worktreePath", "newBranch"],
104
- mutating: true,
105
- capabilities: ["fs.write", "shell.restricted"],
106
- timeoutMs: TIMEOUT_MS,
107
- inputSchema: {
108
- type: "object",
109
- properties: {
110
- command: {
111
- type: "string",
112
- enum: [
113
- "status",
114
- "log",
115
- "diff",
116
- "commit",
117
- "branch",
118
- "checkout",
119
- "stash",
120
- "push",
121
- "pull",
122
- "fetch",
123
- "reset",
124
- "worktree"
125
- ],
126
- description: "Git subcommand"
127
- },
128
- files: {
129
- type: "string",
130
- description: 'File(s) for status/diff: single path, comma-separated list, or "**/*.ts" glob'
131
- },
132
- message: { type: "string", description: "Commit message (required for commit)" },
133
- branch: { type: "string", description: "Branch name for checkout/branch" },
134
- format: {
135
- type: "string",
136
- enum: ["short", "oneline", "stat", "graph"],
137
- description: "Log format (default: short)"
138
- },
139
- limit: { type: "integer", description: "Limit for log (default: 20)" },
140
- dry_run: { type: "boolean", description: "For commit: show what would be committed" },
141
- worktreeAction: {
142
- type: "string",
143
- enum: ["list", "add", "remove", "prune"],
144
- description: "Worktree action: list, add, remove, prune"
145
- },
146
- worktreePath: {
147
- type: "string",
148
- description: 'Path for worktree add/remove (e.g. "../wt-feature-xyz")'
149
- },
150
- newBranch: {
151
- type: "boolean",
152
- description: "Create new branch when adding worktree"
153
- },
154
- force: {
155
- type: "boolean",
156
- description: "Force operation (e.g. worktree remove --force)"
157
- }
158
- },
159
- required: ["command"]
160
- },
161
- async execute(input, ctx, opts) {
162
- if (!input?.command) throw new Error("git: command is required");
163
- if (input.command === "commit" && !input.message) {
164
- return {
165
- command: "commit",
166
- stdout: "",
167
- stderr: "git commit requires a message (-m flag)",
168
- exitCode: 1,
169
- truncated: false
170
- };
171
- }
172
- const branchGuard = validateBranchInput(input);
173
- if (branchGuard) return branchGuard;
174
- if (input.command === "worktree") {
175
- const guard = validateWorktreeInput(input, ctx.projectRoot);
176
- if (guard) return guard;
177
- }
178
- const gitDir = findGitDir(ctx.cwd, ctx.projectRoot);
179
- if (!gitDir) {
180
- return {
181
- command: input.command,
182
- stdout: "",
183
- stderr: "Not in a git repository (within project root)",
184
- exitCode: 128,
185
- truncated: false
186
- };
187
- }
188
- const args = buildArgs(input);
189
- let safetyWarning;
190
- if (input.command === "commit") {
191
- try {
192
- const report = await assessCommitSafety({
193
- cwd: ctx.cwd,
194
- projectRoot: ctx.projectRoot,
195
- sessionId: ctx.session?.id,
196
- signal: opts.signal
197
- });
198
- if (report.warning) {
199
- const scopeNote = input.files ? "" : "\nNote: this commit has no explicit `files` list, so it will include ALL staged changes. Pass `files` to scope the commit to only what you changed.";
200
- safetyWarning = report.warning + scopeNote;
201
- }
202
- } catch {
203
- }
204
- }
205
- let stagedDiff;
206
- if (input.command === "commit" && !input.dry_run) {
207
- try {
208
- const diffResult = await runGit(["diff", "--cached"], gitDir, opts.signal);
209
- if (diffResult.exitCode === 0) {
210
- const MAX_DIFF = 2e4;
211
- stagedDiff = diffResult.stdout.length > MAX_DIFF ? diffResult.stdout.slice(0, MAX_DIFF) + "\n\n... (diff truncated)" : diffResult.stdout;
212
- }
213
- } catch {
214
- }
215
- }
216
- const result = await runGit(args, gitDir, opts.signal);
217
- if (stagedDiff !== void 0) result.diff = stagedDiff;
218
- if (safetyWarning !== void 0) result.warning = safetyWarning;
219
- return result;
220
- }
221
- };
222
- function validateBranchInput(input) {
223
- const branch = input.branch;
224
- if (branch === void 0) return null;
225
- if (!branch.startsWith("-") && !branch.includes(" --")) return null;
226
- return {
227
- command: input.command,
228
- stdout: "",
229
- stderr: `unsafe branch name (parsed as a git option): ${branch}`,
230
- exitCode: 1,
231
- truncated: false
232
- };
233
- }
234
- function validateWorktreeInput(input, projectRoot) {
235
- const reject = (stderr) => ({
236
- command: "worktree",
237
- stdout: "",
238
- stderr,
239
- exitCode: 1,
240
- truncated: false
241
- });
242
- if (input.worktreePath?.startsWith("-")) {
243
- return reject(`unsafe worktree path: ${input.worktreePath}`);
244
- }
245
- if ((input.worktreeAction === "add" || input.worktreeAction === "remove") && input.worktreePath) {
246
- const root = resolve(projectRoot);
247
- const abs = resolve(root, input.worktreePath);
248
- if (abs !== root && !abs.startsWith(root + sep)) {
249
- return reject(`unsafe worktree path (escapes project root): ${input.worktreePath}`);
250
- }
251
- }
252
- return null;
253
- }
254
- function findGitDir(cwd, projectRoot) {
255
- const root = projectRoot;
256
- let dir = cwd;
257
- for (let i = 0; i < 20; i++) {
258
- try {
259
- const stat = statSync(`${dir}/.git`);
260
- if (stat.isDirectory() || stat.isFile()) return dir;
261
- } catch {
262
- }
263
- if (dir === root) break;
264
- const parent = dirname(dir);
265
- if (parent === dir) break;
266
- dir = parent;
267
- }
268
- return null;
269
- }
270
- function buildArgs(input) {
271
- const limit = input.limit ?? 20;
272
- const files = input.files ? (Array.isArray(input.files) ? input.files : input.files.split(",")).map((s) => s.trim()).filter(Boolean) : [];
273
- switch (input.command) {
274
- case "status":
275
- return ["status", ...files.length ? ["--", ...files] : []];
276
- case "log":
277
- return [
278
- "log",
279
- `--max-count=${limit}`,
280
- ...input.format === "oneline" ? ["--oneline"] : [],
281
- ...input.format === "stat" ? ["--stat"] : [],
282
- ...input.format === "graph" ? ["--oneline", "--graph", "--decorate"] : [],
283
- ...input.format === "short" || !input.format ? [] : []
284
- ];
285
- case "diff":
286
- return ["diff", "--no-color", ...files.length ? ["--", ...files] : []];
287
- case "commit":
288
- return [
289
- "commit",
290
- ...input.dry_run ? ["--dry-run", "--porcelain"] : [],
291
- ...input.message ? ["-m", input.message] : [],
292
- ...files.length ? ["--", ...files] : []
293
- ];
294
- case "branch":
295
- return input.branch ? [
296
- "branch",
297
- ...input.branch.startsWith("-") || input.branch.includes(" --") ? [] : [input.branch]
298
- ] : ["branch"];
299
- case "checkout":
300
- if (files.length) return ["checkout", "--", ...files];
301
- return input.branch ? ["checkout", input.branch, "--"] : ["checkout"];
302
- case "stash":
303
- return input.message ? ["stash", "push", "-m", input.message] : ["stash", "push"];
304
- case "push":
305
- return ["push"];
306
- case "pull":
307
- return ["pull"];
308
- case "fetch":
309
- return ["fetch", ...input.branch ? [input.branch] : ["--all"]];
310
- case "reset":
311
- return ["reset", ...files.length ? ["--", ...files] : []];
312
- case "worktree":
313
- switch (input.worktreeAction) {
314
- case "list":
315
- return ["worktree", "list"];
316
- case "add": {
317
- if (!input.worktreePath) return ["worktree", "list"];
318
- const add = ["worktree", "add"];
319
- if (input.newBranch && input.branch) add.push("-b", input.branch);
320
- add.push(input.worktreePath);
321
- if (!input.newBranch && input.branch) add.push(input.branch);
322
- return add;
323
- }
324
- case "remove":
325
- return [
326
- "worktree",
327
- "remove",
328
- ...input.force ? ["--force"] : [],
329
- input.worktreePath ?? ""
330
- ].filter(Boolean);
331
- case "prune":
332
- return ["worktree", "prune"];
333
- default:
334
- return ["worktree", "list"];
335
- }
336
- default:
337
- return [input.command];
338
- }
339
- }
340
- function runGit(args, cwd, signal) {
341
- return new Promise((resolve2) => {
342
- let stdout = "";
343
- let stderr = "";
344
- const child = spawn("git", args, {
345
- cwd,
346
- signal,
347
- env: buildChildEnv(),
348
- stdio: ["ignore", "pipe", "pipe"],
349
- windowsHide: true
350
- });
351
- child.stdout?.on("data", (chunk) => {
352
- if (stdout.length < MAX_OUTPUT) {
353
- stdout += chunk.toString();
354
- }
355
- });
356
- child.stderr?.on("data", (chunk) => {
357
- if (stderr.length < MAX_OUTPUT) {
358
- stderr += chunk.toString();
359
- }
360
- });
361
- child.on("error", (err) => {
362
- resolve2({
363
- command: args[0],
364
- stdout: normalizeCommandOutput(stdout),
365
- stderr: err.message,
366
- exitCode: 1,
367
- truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES
368
- });
369
- });
370
- child.on("close", (code) => {
371
- resolve2({
372
- command: args[0],
373
- stdout: normalizeCommandOutput(stdout),
374
- stderr: normalizeCommandOutput(stderr),
375
- exitCode: code ?? 1,
376
- truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES || Buffer.byteLength(stderr, "utf8") > COMMAND_OUTPUT_MAX_BYTES
377
- });
378
- });
379
- });
380
- }
1
+ import {
2
+ gitTool
3
+ } from "./chunk-RXISBFR5.js";
4
+ import "./chunk-D33S4RQG.js";
381
5
  export {
382
6
  gitTool
383
7
  };
package/dist/glob.js CHANGED
@@ -1,283 +1,9 @@
1
- // src/glob.ts
2
- import * as fs2 from "node:fs/promises";
3
- import * as path3 from "node:path";
4
- import { compileGlob as compileGlob2, DEFAULT_WALK_IGNORE_DIRS } from "@wrongstack/core/utils";
5
- import { ToolValidationError } from "@wrongstack/core/types";
6
-
7
- // src/_concurrency.ts
8
- async function mapWithConcurrency(items, limit, fn) {
9
- if (items.length === 0) return [];
10
- const effectiveLimit = Math.max(1, Math.min(limit | 0, items.length));
11
- const results = new Array(items.length);
12
- let nextIndex = 0;
13
- const worker = async () => {
14
- while (true) {
15
- const i = nextIndex++;
16
- if (i >= items.length) return;
17
- results[i] = await fn(items[i]);
18
- }
19
- };
20
- await Promise.all(Array.from({ length: effectiveLimit }, worker));
21
- return results;
22
- }
23
-
24
- // src/codebase-index/gitignore.ts
25
- import * as fs from "node:fs/promises";
26
- import * as path from "node:path";
27
- import { compileGlob } from "@wrongstack/core/utils";
28
- function globBody(glob) {
29
- return compileGlob(glob).source.replace(/^\^/, "").replace(/\$$/, "");
30
- }
31
- function compileGitignore(lines) {
32
- const rules = [];
33
- for (const raw of lines) {
34
- let line = raw.replace(/\r$/, "");
35
- if (!line.trim() || line.trimStart().startsWith("#")) continue;
36
- line = line.trim();
37
- let negated = false;
38
- if (line.startsWith("!")) {
39
- negated = true;
40
- line = line.slice(1);
41
- }
42
- let dirOnly = false;
43
- if (line.endsWith("/")) {
44
- dirOnly = true;
45
- line = line.slice(0, -1);
46
- }
47
- if (!line) continue;
48
- const anchored = line.startsWith("/") || line.includes("/");
49
- if (line.startsWith("/")) line = line.slice(1);
50
- const body = globBody(line);
51
- const prefix = anchored ? "^" : "(?:^|.*/)";
52
- rules.push({
53
- eqOrUnder: new RegExp(`${prefix}${body}(?:/.*)?$`),
54
- under: new RegExp(`${prefix}${body}/.*$`),
55
- negated,
56
- dirOnly
57
- });
58
- }
59
- return (relPath, isDir) => {
60
- const p = relPath.replace(/\\/g, "/").replace(/^\/+/, "");
61
- let ignored = false;
62
- for (const r of rules) {
63
- const re = r.dirOnly && !isDir ? r.under : r.eqOrUnder;
64
- if (re.test(p)) ignored = !r.negated;
65
- }
66
- return ignored;
67
- };
68
- }
69
- async function loadGitignoreMatcher(projectRoot) {
70
- let lines = [];
71
- try {
72
- const raw = await fs.readFile(path.join(projectRoot, ".gitignore"), "utf8");
73
- lines = raw.split("\n");
74
- } catch {
75
- }
76
- return compileGitignore(lines);
77
- }
78
-
79
- // src/_util.ts
80
- import * as fsp from "node:fs/promises";
81
- import * as path2 from "node:path";
82
- import * as Core from "@wrongstack/core/utils";
83
- function resolvePath(input, ctx) {
84
- return path2.isAbsolute(input) ? path2.normalize(input) : path2.resolve(ctx.workingDir ?? ctx.cwd, input);
85
- }
86
- function allowedRoots(ctx) {
87
- return [path2.resolve(ctx.projectRoot), path2.resolve(Core.wstackGlobalRoot())];
88
- }
89
- function isInsideAny(target, roots) {
90
- return roots.some((root) => {
91
- const rel = path2.relative(root, target);
92
- return rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel);
93
- });
94
- }
95
- function ensureInsideRoot(absPath, ctx) {
96
- const target = path2.resolve(absPath);
97
- if (ctx.allowOutsideProjectRoot) return target;
98
- if (isInsideAny(target, allowedRoots(ctx))) return target;
99
- throw new Error(`Path "${absPath}" is outside project root "${path2.resolve(ctx.projectRoot)}"`);
100
- }
101
- function safeResolve(input, ctx) {
102
- return ensureInsideRoot(resolvePath(input, ctx), ctx);
103
- }
104
- async function assertRealInsideRoot(absPath, ctx) {
105
- await resolveRealInsideRoot(absPath, ctx);
106
- }
107
- async function resolveRealInsideRoot(absPath, ctx) {
108
- if (ctx.allowOutsideProjectRoot) return absPath;
109
- const realRoots = await Promise.all(
110
- allowedRoots(ctx).map((r) => fsp.realpath(r).catch(() => path2.resolve(r)))
111
- );
112
- let probe = absPath;
113
- const pendingTail = [];
114
- for (; ; ) {
115
- let real;
116
- try {
117
- real = await fsp.realpath(probe);
118
- } catch (err) {
119
- if (err.code === "ENOENT") {
120
- const parent = path2.dirname(probe);
121
- if (parent === probe) return absPath;
122
- pendingTail.unshift(path2.basename(probe));
123
- probe = parent;
124
- continue;
125
- }
126
- throw err;
127
- }
128
- const candidate = pendingTail.length > 0 ? path2.join(real, ...pendingTail) : real;
129
- if (isInsideAny(candidate, realRoots)) {
130
- return candidate;
131
- }
132
- throw new Error(
133
- `Path "${absPath}" resolves through a symlink outside project root "${realRoots[0]}"`
134
- );
135
- }
136
- }
137
- async function safeResolveReal(input, ctx) {
138
- const abs = safeResolve(input, ctx);
139
- return await resolveRealInsideRoot(abs, ctx);
140
- }
141
-
142
- // src/glob.ts
143
- var DEFAULT_IGNORE = new Set(DEFAULT_WALK_IGNORE_DIRS);
144
- var WALK_CONCURRENCY = 16;
145
- var globTool = {
146
- name: "glob",
147
- category: "Filesystem",
148
- description: "Find files by path pattern. Results are sorted by modification time, newest first, so when the list is truncated at `limit` it is the oldest files that are dropped (recency-biased). Use index-backed `codebase-search` first for code symbols or concepts when it is live.",
149
- usageHint: "PATH DISCOVERY AND SEARCH SCOPING:\n\n- When `codebase-search` is live, use it first for code concepts; use `glob` for filenames, path patterns, and non-indexed files.\n- Combine with `path` and `limit`.\n- Default ignores common build/dependency directories.\nMuch more efficient than shell `find` for most use cases inside the agent.",
150
- selection: {
151
- doNotUseWhen: "you need to search inside file contents.",
152
- useInstead: ["grep"]
153
- },
154
- permission: "auto",
155
- mutating: false,
156
- capabilities: ["fs.read"],
157
- icon: "folder",
158
- maxOutputBytes: 65536,
159
- timeoutMs: 15e3,
160
- inputSchema: {
161
- type: "object",
162
- properties: {
163
- pattern: {
164
- type: "string",
165
- description: 'Glob pattern to match (e.g. "**/*.ts", "src/**").'
166
- },
167
- path: {
168
- type: "string",
169
- description: "Base directory to search from (defaults to project root)."
170
- },
171
- limit: {
172
- type: "integer",
173
- minimum: 1,
174
- maximum: 5e3,
175
- description: "Maximum number of results to return (default 1000, max 5000). Results are sorted by mtime descending, so truncation keeps the most recently modified files."
176
- }
177
- },
178
- required: ["pattern"]
179
- },
180
- async execute(input, ctx, opts) {
181
- if (!input?.pattern) {
182
- throw new ToolValidationError({
183
- message: "glob: pattern is required",
184
- field: "pattern"
185
- });
186
- }
187
- const signal = opts?.signal;
188
- const base = input.path ? await safeResolveReal(input.path, ctx) : ctx.cwd;
189
- const limit = Math.max(1, Math.min(input.limit ?? 1e3, 5e3));
190
- const isGitIgnored = await loadGitignoreMatcher(base);
191
- const re = compileGlob2(input.pattern);
192
- const results = [];
193
- let truncated = false;
194
- const pushResult = async (full) => {
195
- if (truncated || results.length >= limit) {
196
- truncated = true;
197
- return;
198
- }
199
- try {
200
- const st = await fs2.stat(full);
201
- if (truncated || results.length >= limit) {
202
- truncated = true;
203
- return;
204
- }
205
- results.push({ rel: full, mtime: st.mtimeMs });
206
- if (results.length >= limit) truncated = true;
207
- } catch {
208
- }
209
- };
210
- const walk = async (dir, relPrefix) => {
211
- if (signal?.aborted) {
212
- truncated = true;
213
- return;
214
- }
215
- if (results.length >= limit) {
216
- truncated = true;
217
- return;
218
- }
219
- let entries;
220
- try {
221
- entries = await fs2.readdir(dir, { withFileTypes: true });
222
- } catch {
223
- return;
224
- }
225
- const subdirs = [];
226
- const matchedFiles = [];
227
- for (const e of entries) {
228
- const name = e.name;
229
- if (DEFAULT_IGNORE.has(name)) continue;
230
- const rel = relPrefix ? `${relPrefix}/${name}` : name;
231
- const full = path3.join(dir, name);
232
- if (e.isDirectory()) {
233
- if (isGitIgnored(rel, true)) continue;
234
- subdirs.push({ full, rel });
235
- } else if (e.isFile()) {
236
- if (isGitIgnored(rel, false)) continue;
237
- re.lastIndex = 0;
238
- const relMatch = re.test(rel);
239
- re.lastIndex = 0;
240
- const nameMatch = re.test(name);
241
- if (relMatch || nameMatch) {
242
- matchedFiles.push(full);
243
- }
244
- } else if (e.isSymbolicLink()) {
245
- try {
246
- const st = await fs2.stat(full);
247
- if (st.isDirectory()) {
248
- if (isGitIgnored(rel, true)) continue;
249
- const real = await fs2.realpath(full);
250
- await assertRealInsideRoot(real, ctx);
251
- subdirs.push({ full, rel });
252
- } else if (st.isFile()) {
253
- if (isGitIgnored(rel, false)) continue;
254
- const real = await fs2.realpath(full);
255
- await assertRealInsideRoot(real, ctx);
256
- re.lastIndex = 0;
257
- const relMatch = re.test(rel);
258
- re.lastIndex = 0;
259
- const nameMatch = re.test(name);
260
- if (relMatch || nameMatch) matchedFiles.push(full);
261
- }
262
- } catch {
263
- }
264
- }
265
- if (truncated) return;
266
- }
267
- await mapWithConcurrency(matchedFiles, WALK_CONCURRENCY, pushResult);
268
- if (truncated) return;
269
- const remainingSubdirs = truncated ? [] : subdirs;
270
- await mapWithConcurrency(
271
- remainingSubdirs,
272
- WALK_CONCURRENCY,
273
- ({ full, rel }) => walk(full, rel)
274
- );
275
- };
276
- await walk(base, "");
277
- results.sort((a, b) => b.mtime - a.mtime);
278
- return { files: results.map((r) => r.rel), truncated };
279
- }
280
- };
1
+ import {
2
+ globTool
3
+ } from "./chunk-UNSKG6DC.js";
4
+ import "./chunk-U4D5S3VQ.js";
5
+ import "./chunk-LIJQMYYX.js";
6
+ import "./chunk-D33S4RQG.js";
281
7
  export {
282
8
  globTool
283
9
  };