@j0hanz/filesystem-mcp 2.1.8 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +41 -29
  2. package/dist/cli-help.d.ts.map +1 -1
  3. package/dist/cli-help.js +10 -2
  4. package/dist/cli-help.js.map +1 -1
  5. package/dist/cli.d.ts.map +1 -1
  6. package/dist/cli.js +10 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/core/concurrency.d.ts.map +1 -1
  9. package/dist/core/concurrency.js +21 -6
  10. package/dist/core/concurrency.js.map +1 -1
  11. package/dist/core/config.d.ts +2 -0
  12. package/dist/core/config.d.ts.map +1 -1
  13. package/dist/core/config.js.map +1 -1
  14. package/dist/core/cursor.d.ts +11 -0
  15. package/dist/core/cursor.d.ts.map +1 -1
  16. package/dist/core/cursor.js +10 -0
  17. package/dist/core/cursor.js.map +1 -1
  18. package/dist/core/errors.d.ts +6 -9
  19. package/dist/core/errors.d.ts.map +1 -1
  20. package/dist/core/errors.js +58 -102
  21. package/dist/core/errors.js.map +1 -1
  22. package/dist/core/file-uri.d.ts +5 -1
  23. package/dist/core/file-uri.d.ts.map +1 -1
  24. package/dist/core/file-uri.js +6 -2
  25. package/dist/core/file-uri.js.map +1 -1
  26. package/dist/core/fmt.d.ts +0 -1
  27. package/dist/core/fmt.d.ts.map +1 -1
  28. package/dist/core/fmt.js +0 -1
  29. package/dist/core/fmt.js.map +1 -1
  30. package/dist/core/fs.d.ts +31 -1
  31. package/dist/core/fs.d.ts.map +1 -1
  32. package/dist/core/fs.js +142 -2
  33. package/dist/core/fs.js.map +1 -1
  34. package/dist/core/glob.d.ts +4 -13
  35. package/dist/core/glob.d.ts.map +1 -1
  36. package/dist/core/glob.js +14 -14
  37. package/dist/core/glob.js.map +1 -1
  38. package/dist/core/input-required.d.ts +16 -17
  39. package/dist/core/input-required.d.ts.map +1 -1
  40. package/dist/core/input-required.js +42 -47
  41. package/dist/core/input-required.js.map +1 -1
  42. package/dist/core/observability.d.ts +9 -0
  43. package/dist/core/observability.d.ts.map +1 -1
  44. package/dist/core/observability.js +13 -1
  45. package/dist/core/observability.js.map +1 -1
  46. package/dist/core/page-store.d.ts +4 -3
  47. package/dist/core/page-store.d.ts.map +1 -1
  48. package/dist/core/page-store.js +4 -3
  49. package/dist/core/page-store.js.map +1 -1
  50. package/dist/core/primitives.d.ts +7 -0
  51. package/dist/core/primitives.d.ts.map +1 -1
  52. package/dist/core/primitives.js +15 -8
  53. package/dist/core/primitives.js.map +1 -1
  54. package/dist/core/search.d.ts +8 -4
  55. package/dist/core/search.d.ts.map +1 -1
  56. package/dist/core/search.js +23 -24
  57. package/dist/core/search.js.map +1 -1
  58. package/dist/core/sensitive.d.ts +4 -2
  59. package/dist/core/sensitive.d.ts.map +1 -1
  60. package/dist/core/sensitive.js +261 -43
  61. package/dist/core/sensitive.js.map +1 -1
  62. package/dist/core/util.d.ts.map +1 -1
  63. package/dist/core/util.js +2 -11
  64. package/dist/core/util.js.map +1 -1
  65. package/dist/core/watcher-registry.d.ts.map +1 -1
  66. package/dist/core/watcher-registry.js +5 -1
  67. package/dist/core/watcher-registry.js.map +1 -1
  68. package/dist/instructions.js +11 -11
  69. package/dist/instructions.js.map +1 -1
  70. package/dist/resources.d.ts.map +1 -1
  71. package/dist/resources.js +13 -4
  72. package/dist/resources.js.map +1 -1
  73. package/dist/server.d.ts +1 -9
  74. package/dist/server.d.ts.map +1 -1
  75. package/dist/server.js +22 -27
  76. package/dist/server.js.map +1 -1
  77. package/dist/tools/create.d.ts.map +1 -1
  78. package/dist/tools/create.js +163 -14
  79. package/dist/tools/create.js.map +1 -1
  80. package/dist/tools/define.d.ts +6 -1
  81. package/dist/tools/define.d.ts.map +1 -1
  82. package/dist/tools/define.js +29 -9
  83. package/dist/tools/define.js.map +1 -1
  84. package/dist/tools/delete.d.ts +2 -0
  85. package/dist/tools/delete.d.ts.map +1 -0
  86. package/dist/tools/{delete-file.js → delete.js} +12 -15
  87. package/dist/tools/delete.js.map +1 -0
  88. package/dist/tools/edit.d.ts.map +1 -1
  89. package/dist/tools/edit.js +77 -69
  90. package/dist/tools/edit.js.map +1 -1
  91. package/dist/tools/find-files.d.ts +2 -0
  92. package/dist/tools/find-files.d.ts.map +1 -0
  93. package/dist/tools/{search-files.js → find-files.js} +14 -19
  94. package/dist/tools/find-files.js.map +1 -0
  95. package/dist/tools/index.d.ts +7 -6
  96. package/dist/tools/index.d.ts.map +1 -1
  97. package/dist/tools/index.js +16 -15
  98. package/dist/tools/index.js.map +1 -1
  99. package/dist/tools/list-roots.d.ts +2 -0
  100. package/dist/tools/list-roots.d.ts.map +1 -0
  101. package/dist/tools/{roots.js → list-roots.js} +2 -2
  102. package/dist/tools/list-roots.js.map +1 -0
  103. package/dist/tools/list.d.ts.map +1 -1
  104. package/dist/tools/list.js +28 -32
  105. package/dist/tools/list.js.map +1 -1
  106. package/dist/tools/move.d.ts.map +1 -1
  107. package/dist/tools/move.js +17 -36
  108. package/dist/tools/move.js.map +1 -1
  109. package/dist/tools/patch.js +3 -3
  110. package/dist/tools/patch.js.map +1 -1
  111. package/dist/tools/read.d.ts +1 -1
  112. package/dist/tools/read.d.ts.map +1 -1
  113. package/dist/tools/read.js +1 -1
  114. package/dist/tools/read.js.map +1 -1
  115. package/dist/tools/replace-text.d.ts +2 -0
  116. package/dist/tools/replace-text.d.ts.map +1 -0
  117. package/dist/tools/{replace-in-files.js → replace-text.js} +5 -5
  118. package/dist/tools/replace-text.js.map +1 -0
  119. package/dist/tools/search-text.d.ts +2 -0
  120. package/dist/tools/search-text.d.ts.map +1 -0
  121. package/dist/tools/{search-content.js → search-text.js} +71 -13
  122. package/dist/tools/search-text.js.map +1 -0
  123. package/dist/tools/stat.d.ts +1 -1
  124. package/dist/tools/stat.d.ts.map +1 -1
  125. package/dist/tools/stat.js +1 -1
  126. package/dist/tools/stat.js.map +1 -1
  127. package/dist/transport/http.d.ts.map +1 -1
  128. package/dist/transport/http.js +5 -1
  129. package/dist/transport/http.js.map +1 -1
  130. package/dist/transport/stdio.d.ts +1 -0
  131. package/dist/transport/stdio.d.ts.map +1 -1
  132. package/dist/transport/stdio.js +1 -0
  133. package/dist/transport/stdio.js.map +1 -1
  134. package/package.json +6 -9
  135. package/dist/tools/delete-file.d.ts +0 -2
  136. package/dist/tools/delete-file.d.ts.map +0 -1
  137. package/dist/tools/delete-file.js.map +0 -1
  138. package/dist/tools/replace-in-files.d.ts +0 -2
  139. package/dist/tools/replace-in-files.d.ts.map +0 -1
  140. package/dist/tools/replace-in-files.js.map +0 -1
  141. package/dist/tools/roots.d.ts +0 -2
  142. package/dist/tools/roots.d.ts.map +0 -1
  143. package/dist/tools/roots.js.map +0 -1
  144. package/dist/tools/search-content.d.ts +0 -2
  145. package/dist/tools/search-content.d.ts.map +0 -1
  146. package/dist/tools/search-content.js.map +0 -1
  147. package/dist/tools/search-files.d.ts +0 -2
  148. package/dist/tools/search-files.d.ts.map +0 -1
  149. package/dist/tools/search-files.js.map +0 -1
@@ -4,7 +4,7 @@ import { computeDiffStats, unifiedPatch } from '../core/diff.js';
4
4
  import { ErrorCode, FsError } from '../core/errors.js';
5
5
  import { buildWrittenFileMeta } from '../core/file-uri.js';
6
6
  import { escapeRegexLiteral } from '../core/primitives.js';
7
- import { defaultFalseBoolean, FileKind, isBlank, IsoDateTime, NonNegInt, OperationSummarySchema, PerFileErrorSchema, PositiveInt, RequiredPath, singleOrBatchAccessPaths, } from '../core/schema.js';
7
+ import { defaultFalseBoolean, FileKind, isBlank, IsoDateTime, NonNegInt, OperationSummarySchema, PerFileErrorSchema, RequiredPath, singleOrBatchAccessPaths, } from '../core/schema.js';
8
8
  import { compileRegex, execMatches, freeRegex } from '../core/search.js';
9
9
  import { isTotalFailure, runOverPaths } from './batch.js';
10
10
  import { defineTool } from './define.js';
@@ -16,7 +16,7 @@ const EditSpecSchema = z
16
16
  .refine((val) => !isBlank(val), {
17
17
  message: 'oldText cannot be empty or whitespace-only',
18
18
  })
19
- .describe('Exact literal text to locate in the file. Must include 3-5 lines of context to ensure uniqueness and avoid matching the wrong block.')
19
+ .describe('Exact literal text to locate in the file; it must match exactly once. Include 3-5 lines of context so it does — an oldText found in several places fails with their line numbers.')
20
20
  .meta({ examples: ['const x = 1;', 'function oldName('] }),
21
21
  newText: z
22
22
  .string()
@@ -107,10 +107,6 @@ const PerFileResultSchema = z.strictObject({
107
107
  .array(z.string())
108
108
  .optional()
109
109
  .describe('oldText values that did not match any content in the file'),
110
- lineRange: z
111
- .tuple([PositiveInt, PositiveInt])
112
- .optional()
113
- .describe('Line range [firstLine, lastLine] covering all applied edits'),
114
110
  });
115
111
  const EditPerPathSchema = z.strictObject({
116
112
  path: z.string().describe('Requested file path'),
@@ -123,7 +119,22 @@ const EditFileOutputSchema = z.strictObject({
123
119
  .describe('Per-path edit results ordered to match the input paths'),
124
120
  summary: OperationSummarySchema,
125
121
  });
126
- function findEditMatch(content, oldText, ignoreWhitespace) {
122
+ const MAX_REPORTED_MATCH_LINES = 5;
123
+ /**
124
+ * Where `oldText` matches. `count` is non-overlapping occurrences, except that a
125
+ * lone match with a second one overlapping it counts two (`abab` in `ababab`),
126
+ * since either is a span the caller could have meant — the count is exact only
127
+ * when it answers "once or not". Only the count and the first few starts are
128
+ * kept: a short oldText in a large file can match millions of times.
129
+ */
130
+ function findEditMatches(content, oldText, ignoreWhitespace) {
131
+ const found = { first: undefined, count: 0, starts: [] };
132
+ const add = (startIndex, length) => {
133
+ found.first ??= { startIndex, length };
134
+ found.count += 1;
135
+ if (found.starts.length < MAX_REPORTED_MATCH_LINES)
136
+ found.starts.push(startIndex);
137
+ };
127
138
  if (ignoreWhitespace) {
128
139
  // Make whitespace flexible (tolerate indentation/spacing differences)
129
140
  // without letting it cross line boundaries: a whitespace run that contains
@@ -139,68 +150,65 @@ function findEditMatch(content, oldText, ignoreWhitespace) {
139
150
  try {
140
151
  // execMatches resets lastIndex and reports UTF-16 offsets; the raw RE2
141
152
  // index counts code points and would splice off-by-one per emoji.
142
- const { value: match } = execMatches(regex, content).next();
143
- // A zero-length match names an empty span, which cannot be replaced.
144
- if (match === undefined || match.text.length === 0)
145
- return undefined;
146
- return {
147
- startIndex: match.start,
148
- length: match.text.length,
153
+ const scan = (from) => {
154
+ for (const match of execMatches(regex, from === 0 ? content : content.slice(from))) {
155
+ // A zero-length match names an empty span, which cannot be replaced.
156
+ if (match.text.length > 0)
157
+ add(from + match.start, match.text.length);
158
+ if (from > 0)
159
+ return;
160
+ }
149
161
  };
162
+ scan(0);
163
+ // execMatches resumes past each match, so a second match overlapping the
164
+ // first is never reported; look once more from just past its first
165
+ // non-whitespace character. Starting inside the leading whitespace would
166
+ // re-find the same occurrence, since the pattern's leading run is `*`. The
167
+ // pattern carries no anchors, so matching a suffix finds the same spans.
168
+ if (found.count === 1 && found.first) {
169
+ const { startIndex, length } = found.first;
170
+ const lead = content.slice(startIndex, startIndex + length).search(/\S/u);
171
+ scan(afterCodePoint(content, startIndex + lead));
172
+ }
150
173
  }
151
174
  finally {
152
175
  // The compiled pattern owns wasm memory re2-wasm never reclaims on its
153
- // own; its lifetime is this one match.
176
+ // own; its lifetime is this one search.
154
177
  freeRegex(regex);
155
178
  }
179
+ return found;
156
180
  }
157
- const index = content.indexOf(oldText);
158
- if (index === -1) {
159
- return undefined;
181
+ // Non-overlapping, so the scan stays linear on repetitive content; the one
182
+ // overlap that matters — a second match inside the only one — is checked after.
183
+ for (let i = content.indexOf(oldText); i !== -1; i = content.indexOf(oldText, i + oldText.length)) {
184
+ add(i, oldText.length);
160
185
  }
161
- return {
162
- startIndex: index,
163
- length: oldText.length,
164
- };
186
+ if (found.count === 1 && found.first) {
187
+ const overlap = content.indexOf(oldText, afterCodePoint(content, found.first.startIndex));
188
+ if (overlap !== -1)
189
+ add(overlap, oldText.length);
190
+ }
191
+ return found;
192
+ }
193
+ /** The UTF-16 offset just past the code point at `index`, so a surrogate pair is never split. */
194
+ function afterCodePoint(content, index) {
195
+ return index + ((content.codePointAt(index) ?? 0) > 0xffff ? 2 : 1);
196
+ }
197
+ function ambiguousEditError(content, found, editIndex, shifted) {
198
+ const lines = [
199
+ ...new Set(found.starts.map((start) => content.slice(0, start).split('\n').length)),
200
+ ];
201
+ const label = lines.length === 1 ? 'line' : 'lines';
202
+ const more = found.count > found.starts.length ? ', ...' : '';
203
+ // Offsets come from the content as earlier edits in this call left it, which
204
+ // is not the file the caller read once one of them has applied.
205
+ const where = shifted ? ' after earlier edits' : '';
206
+ return new FsError(ErrorCode.INVALID_INPUT, `edits[${String(editIndex)}]: oldText matches ${String(found.count)} places${where} ` +
207
+ `(${label} ${lines.join(', ')}${more}). Add surrounding lines so it matches once.`);
165
208
  }
166
209
  function replaceEditMatch(content, match, newText) {
167
210
  return (content.slice(0, match.startIndex) + newText + content.slice(match.startIndex + match.length));
168
211
  }
169
- /**
170
- * Compute the 1-indexed line range of changed lines in `modified` relative to
171
- * `original`, using a common-prefix/suffix line scan. This is a conservative
172
- * bound (it widens to cover independent changes between matching bookends), but
173
- * it is computed against the FINAL content so it is not skewed by earlier edits
174
- * inserting or removing lines — which the per-edit merge could not account for.
175
- */
176
- function computeChangedLineRange(original, modified) {
177
- const origLines = original.split('\n');
178
- const modLines = modified.split('\n');
179
- const minLen = Math.min(origLines.length, modLines.length);
180
- let firstChanged = -1;
181
- for (let i = 0; i < minLen; i++) {
182
- if (origLines[i] !== modLines[i]) {
183
- firstChanged = i;
184
- break;
185
- }
186
- }
187
- if (firstChanged === -1 && origLines.length === modLines.length)
188
- return undefined;
189
- if (firstChanged === -1)
190
- firstChanged = minLen; // pure append/trim at the tail
191
- let lastChangedMod = modLines.length - 1;
192
- let lastChangedOrig = origLines.length - 1;
193
- while (lastChangedMod > firstChanged &&
194
- lastChangedOrig >= 0 &&
195
- modLines[lastChangedMod] === origLines[lastChangedOrig]) {
196
- lastChangedMod--;
197
- lastChangedOrig--;
198
- }
199
- // When the modified content is a strict prefix of the original (a tail trim on
200
- // a file with no final newline), the loop above never runs and lastChangedMod
201
- // lands one below firstChanged. Clamp so the range is never inverted.
202
- return [firstChanged + 1, Math.max(firstChanged, lastChangedMod) + 1];
203
- }
204
212
  function buildEditFileValue(validPath, meta, modified, result) {
205
213
  return {
206
214
  path: validPath,
@@ -216,10 +224,9 @@ function buildEditFileValue(validPath, meta, modified, result) {
216
224
  : {}),
217
225
  ...(result.unmatchedEdits.length > 0 ? { unmatchedEdits: result.unmatchedEdits } : {}),
218
226
  ...(result.diff ? { diff: result.diff } : {}),
219
- ...(result.lineRange ? { lineRange: result.lineRange } : {}),
220
227
  };
221
228
  }
222
- function finalizeEditResult(originalContent, updatedContent, appliedEdits, unmatchedEdits, lineRange) {
229
+ function finalizeEditResult(originalContent, updatedContent, appliedEdits, unmatchedEdits) {
223
230
  const { linesAdded, linesRemoved } = appliedEdits > 0
224
231
  ? computeDiffStats(originalContent, updatedContent)
225
232
  : { linesAdded: 0, linesRemoved: 0 };
@@ -229,7 +236,6 @@ function finalizeEditResult(originalContent, updatedContent, appliedEdits, unmat
229
236
  unmatchedEdits,
230
237
  linesAdded,
231
238
  linesRemoved,
232
- ...(lineRange ? { lineRange } : {}),
233
239
  };
234
240
  }
235
241
  function buildEditFileMetadata(content, validPath, appliedEdits, resourceStore) {
@@ -247,19 +253,20 @@ function applyEdits(content, edits, ignoreWhitespace) {
247
253
  let newContent = content;
248
254
  let appliedEdits = 0;
249
255
  const unmatchedEdits = [];
250
- for (const edit of edits) {
251
- const match = findEditMatch(newContent, edit.oldText, ignoreWhitespace);
252
- if (!match) {
256
+ for (const [index, edit] of edits.entries()) {
257
+ const found = findEditMatches(newContent, edit.oldText, ignoreWhitespace);
258
+ // A second match is an error rather than a pick: splicing the first would
259
+ // edit a block the caller may not have meant and still report success.
260
+ if (found.count > 1)
261
+ throw ambiguousEditError(newContent, found, index, appliedEdits > 0);
262
+ if (!found.first) {
253
263
  unmatchedEdits.push(edit.oldText);
254
264
  continue;
255
265
  }
256
- newContent = replaceEditMatch(newContent, match, edit.newText);
266
+ newContent = replaceEditMatch(newContent, found.first, edit.newText);
257
267
  appliedEdits += 1;
258
268
  }
259
- // Compute the line range against the final content so earlier edits whose
260
- // lines were shifted by later edits are still covered.
261
- const lineRange = appliedEdits > 0 ? computeChangedLineRange(content, newContent) : undefined;
262
- return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits, lineRange);
269
+ return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits);
263
270
  }
264
271
  async function handleEditFile(filePath, edits, options, ctx) {
265
272
  const { validPath, content } = await ctx.fs.readEditableText(filePath, {
@@ -332,7 +339,8 @@ export const EDIT = defineTool({
332
339
  title: 'Edit Files',
333
340
  description: 'Apply sequential literal string replacements to one or more files (max 5 files per call). ' +
334
341
  'Modes: single-file { path, edits } or per-file { files: [{ path, edits }] }. ' +
335
- 'oldText must match file content exactly; include 3-5 lines of surrounding context to ensure uniqueness. ' +
342
+ 'oldText must match file content exactly and only once; include 3-5 lines of surrounding context, ' +
343
+ 'or the edit fails listing the lines it matched. ' +
336
344
  'Set dryRun=true to preview diffs without writing. ' +
337
345
  'For glob-based bulk regex replacement across many files, use replace_text instead.',
338
346
  input: EditFileInputSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAwB,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,OAAO,EACP,WAAW,EACX,SAAS,EACT,sBA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;gBAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnE,OAAO;YACL,UAAU,EAAE;gBACV,OAAO,EAAE,cAAc;gBACvB,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB;YACD,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC;YACtC,GAAG,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { ContentBlock } from '@modelcontextprotocol/server';\n\nimport { basename } from 'node:path';\n\nimport * as z from 'zod/v4';\n\nimport { computeDiffStats, unifiedPatch } from '../core/diff.js';\nimport { ErrorCode, FsError } from '../core/errors.js';\nimport { buildWrittenFileMeta, type WrittenFileMeta } from '../core/file-uri.js';\nimport { escapeRegexLiteral } from '../core/primitives.js';\nimport {\n defaultFalseBoolean,\n FileKind,\n isBlank,\n IsoDateTime,\n NonNegInt,\n OperationSummarySchema,\n PerFileErrorSchema,\n PositiveInt,\n RequiredPath,\n singleOrBatchAccessPaths,\n} from '../core/schema.js';\nimport { compileRegex, execMatches, freeRegex } from '../core/search.js';\nimport type { ResourceStore } from '../core/store.js';\nimport { isTotalFailure, runOverPaths } from './batch.js';\nimport { defineTool, type ToolCtx } from './define.js';\n\nconst EditSpecSchema = z\n .strictObject({\n oldText: z\n .string()\n .min(1, 'oldText required')\n .refine((val) => !isBlank(val), {\n message: 'oldText cannot be empty or whitespace-only',\n })\n .describe(\n 'Exact literal text to locate in the file. Must include 3-5 lines of context to ensure uniqueness and avoid matching the wrong block.',\n )\n .meta({ examples: ['const x = 1;', 'function oldName('] }),\n newText: z\n .string()\n .describe('Replacement text. Use an empty string to delete the matched oldText.')\n .meta({ examples: ['const x = 2;', 'function newName(', ''] }),\n })\n // The one document in this server where a `$ref` pays: this subschema is used\n // at both `edits` and `files[].edits`, so an `id` hoists it into `$defs` once\n // instead of inlining ~1.3 kB twice. Shared schemas used once per document\n // deliberately carry no `id` — there a `$ref` costs more than it saves.\n .meta({ id: 'EditSpec' });\n\nconst MAX_MULTI_FILES = 5;\nconst MAX_EDITS_PER_FILE = 100;\n\nconst EditFileInputSchema = z\n .strictObject({\n path: RequiredPath.optional().describe('Single file path; mutually exclusive with files'),\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .optional()\n .describe('Replacements applied to path; not allowed when using files'),\n files: z\n .array(\n z.strictObject({\n path: RequiredPath,\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .describe('Replacements to apply to this specific file'),\n }),\n )\n .min(1)\n .max(MAX_MULTI_FILES)\n .optional()\n .describe('Per-file entries (batch mode)'),\n dryRun: defaultFalseBoolean(\n 'Preview diffs without writing to disk (default: false = apply edits)',\n ),\n ignoreWhitespace: defaultFalseBoolean(\n 'Ignore leading/trailing whitespace differences when matching oldText',\n ),\n })\n .superRefine((value, ctx) => {\n const hasPath = value.path !== undefined;\n const hasFiles = value.files !== undefined;\n if (hasPath === hasFiles) {\n ctx.addIssue({\n code: 'custom',\n path: ['path'],\n message: \"Provide exactly one of 'path' or 'files'\",\n input: value,\n });\n }\n if (hasPath && value.edits === undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' required when using 'path'\",\n input: value,\n });\n }\n if (hasFiles && value.edits !== undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' not allowed with 'files'; each file carries its own edits\",\n input: value,\n });\n }\n })\n // Mirror the superRefine on the wire: exactly one input mode, and single-file\n // mode carries its own `edits`. Without `edits` in the first branch, `{ path }`\n // alone validated against the published schema and was then rejected at\n // runtime — the model had no way to see that coming.\n .meta({ oneOf: [{ required: ['path', 'edits'] }, { required: ['files'] }] });\n\nconst PerFileResultSchema = z.strictObject({\n path: z.string().describe('Resolved absolute path of the edited file'),\n size: NonNegInt.describe('File size in bytes after edits'),\n lineCount: NonNegInt.describe('Number of lines in the file after edits'),\n mimeType: z.string().describe('Detected MIME type of the file'),\n kind: FileKind.describe('Broad file kind: text, binary, image, audio, or pdf'),\n resourceUri: z\n .string()\n .optional()\n .describe(\n 'Resource URI pointing to the updated file content; omitted when no edit matched (appliedEdits is 0) and the file was left untouched',\n ),\n modified: IsoDateTime.describe('Last modification timestamp after edits (ISO 8601 UTC)'),\n appliedEdits: NonNegInt.describe('Number of edits successfully applied'),\n linesAdded: NonNegInt.optional().describe('Net lines added by all applied edits'),\n linesRemoved: NonNegInt.optional().describe('Net lines removed by all applied edits'),\n diff: z.string().optional().describe('Unified diff of all changes (present only in dryRun mode)'),\n unmatchedEdits: z\n .array(z.string())\n .optional()\n .describe('oldText values that did not match any content in the file'),\n lineRange: z\n .tuple([PositiveInt, PositiveInt])\n .optional()\n .describe('Line range [firstLine, lastLine] covering all applied edits'),\n});\n\nconst EditPerPathSchema = z.strictObject({\n path: z.string().describe('Requested file path'),\n value: PerFileResultSchema.optional().describe('Edit result; present on success'),\n error: PerFileErrorSchema.optional().describe('Error details; present on failure'),\n});\n\nconst EditFileOutputSchema = z.strictObject({\n results: z\n .array(EditPerPathSchema)\n .describe('Per-path edit results ordered to match the input paths'),\n summary: OperationSummarySchema,\n});\n\ntype EditFileValue = z.infer<typeof PerFileResultSchema>;\n\ninterface TextRange {\n startIndex: number;\n length: number;\n}\n\ninterface EditResult {\n content: string;\n appliedEdits: number;\n unmatchedEdits: string[];\n linesAdded: number;\n linesRemoved: number;\n diff?: string;\n lineRange?: [number, number];\n}\n\nfunction findEditMatch(\n content: string,\n oldText: string,\n ignoreWhitespace: boolean,\n): TextRange | undefined {\n if (ignoreWhitespace) {\n // Make whitespace flexible (tolerate indentation/spacing differences)\n // without letting it cross line boundaries: a whitespace run that contains\n // a newline keeps at least one newline, so a single-line oldText cannot\n // match across a newline and a multi-line oldText cannot collapse onto one\n // line. Horizontal whitespace stays mandatory between word characters so\n // adjacent identifiers are not merged.\n const pattern = escapeRegexLiteral(oldText)\n .replace(/[^\\S\\n]*\\n\\s*/g, '[^\\\\S\\\\n]*\\\\n+[^\\\\S\\\\n]*')\n .replace(/(\\w)[^\\S\\n]+(\\w)/g, '$1[^\\\\S\\\\n]+$2')\n .replace(/[^\\S\\n]+/g, '[^\\\\S\\\\n]*');\n const regex = compileRegex(pattern, { caseSensitive: true });\n try {\n // execMatches resets lastIndex and reports UTF-16 offsets; the raw RE2\n // index counts code points and would splice off-by-one per emoji.\n const { value: match } = execMatches(regex, content).next();\n // A zero-length match names an empty span, which cannot be replaced.\n if (match === undefined || match.text.length === 0) return undefined;\n\n return {\n startIndex: match.start,\n length: match.text.length,\n };\n } finally {\n // The compiled pattern owns wasm memory re2-wasm never reclaims on its\n // own; its lifetime is this one match.\n freeRegex(regex);\n }\n }\n\n const index = content.indexOf(oldText);\n if (index === -1) {\n return undefined;\n }\n\n return {\n startIndex: index,\n length: oldText.length,\n };\n}\n\nfunction replaceEditMatch(content: string, match: TextRange, newText: string): string {\n return (\n content.slice(0, match.startIndex) + newText + content.slice(match.startIndex + match.length)\n );\n}\n\n/**\n * Compute the 1-indexed line range of changed lines in `modified` relative to\n * `original`, using a common-prefix/suffix line scan. This is a conservative\n * bound (it widens to cover independent changes between matching bookends), but\n * it is computed against the FINAL content so it is not skewed by earlier edits\n * inserting or removing lines — which the per-edit merge could not account for.\n */\nfunction computeChangedLineRange(original: string, modified: string): [number, number] | undefined {\n const origLines = original.split('\\n');\n const modLines = modified.split('\\n');\n const minLen = Math.min(origLines.length, modLines.length);\n\n let firstChanged = -1;\n for (let i = 0; i < minLen; i++) {\n if (origLines[i] !== modLines[i]) {\n firstChanged = i;\n break;\n }\n }\n if (firstChanged === -1 && origLines.length === modLines.length) return undefined;\n if (firstChanged === -1) firstChanged = minLen; // pure append/trim at the tail\n\n let lastChangedMod = modLines.length - 1;\n let lastChangedOrig = origLines.length - 1;\n while (\n lastChangedMod > firstChanged &&\n lastChangedOrig >= 0 &&\n modLines[lastChangedMod] === origLines[lastChangedOrig]\n ) {\n lastChangedMod--;\n lastChangedOrig--;\n }\n\n // When the modified content is a strict prefix of the original (a tail trim on\n // a file with no final newline), the loop above never runs and lastChangedMod\n // lands one below firstChanged. Clamp so the range is never inverted.\n return [firstChanged + 1, Math.max(firstChanged, lastChangedMod) + 1];\n}\n\nfunction buildEditFileValue(\n validPath: string,\n meta: EditFileMetadata,\n modified: string,\n result: EditResult,\n): EditFileValue {\n return {\n path: validPath,\n size: meta.size,\n lineCount: meta.lineCount,\n mimeType: meta.mimeType,\n kind: meta.kind,\n ...(meta.resourceUri !== undefined ? { resourceUri: meta.resourceUri } : {}),\n modified,\n appliedEdits: result.appliedEdits,\n ...(result.appliedEdits > 0\n ? { linesAdded: result.linesAdded, linesRemoved: result.linesRemoved }\n : {}),\n ...(result.unmatchedEdits.length > 0 ? { unmatchedEdits: result.unmatchedEdits } : {}),\n ...(result.diff ? { diff: result.diff } : {}),\n ...(result.lineRange ? { lineRange: result.lineRange } : {}),\n };\n}\n\nfunction finalizeEditResult(\n originalContent: string,\n updatedContent: string,\n appliedEdits: number,\n unmatchedEdits: string[],\n lineRange: EditResult['lineRange'],\n): EditResult {\n const { linesAdded, linesRemoved } =\n appliedEdits > 0\n ? computeDiffStats(originalContent, updatedContent)\n : { linesAdded: 0, linesRemoved: 0 };\n\n return {\n content: updatedContent,\n appliedEdits,\n unmatchedEdits,\n linesAdded,\n linesRemoved,\n ...(lineRange ? { lineRange } : {}),\n };\n}\n\n/** {@link WrittenFileMeta}, with `resourceUri` widened: an edit that matched\n * nothing has no updated content to point at. */\ntype EditFileMetadata = Omit<WrittenFileMeta, 'resourceUri'> & {\n resourceUri: string | undefined;\n};\n\nfunction buildEditFileMetadata(\n content: string,\n validPath: string,\n appliedEdits: number,\n resourceStore: ResourceStore | undefined,\n): EditFileMetadata {\n const meta = buildWrittenFileMeta(validPath, content, resourceStore);\n // Omitted rather than empty-stringed when nothing matched: `\"\"` satisfied the\n // schema's `string` and then failed every resources/read a client tried it on.\n const written = appliedEdits > 0;\n return {\n ...meta,\n resourceUri: written ? meta.resourceUri : undefined,\n resourceLink: written ? meta.resourceLink : undefined,\n };\n}\n\nfunction applyEdits(\n content: string,\n edits: z.infer<typeof EditSpecSchema>[],\n ignoreWhitespace: boolean,\n): EditResult {\n let newContent = content;\n let appliedEdits = 0;\n const unmatchedEdits: string[] = [];\n\n for (const edit of edits) {\n const match = findEditMatch(newContent, edit.oldText, ignoreWhitespace);\n\n if (!match) {\n unmatchedEdits.push(edit.oldText);\n continue;\n }\n\n newContent = replaceEditMatch(newContent, match, edit.newText);\n appliedEdits += 1;\n }\n\n // Compute the line range against the final content so earlier edits whose\n // lines were shifted by later edits are still covered.\n const lineRange = appliedEdits > 0 ? computeChangedLineRange(content, newContent) : undefined;\n\n return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits, lineRange);\n}\n\ninterface EditFileOptions {\n dryRun: boolean;\n ignoreWhitespace: boolean;\n}\n\nasync function handleEditFile(\n filePath: string,\n edits: z.infer<typeof EditSpecSchema>[],\n options: EditFileOptions,\n ctx: ToolCtx,\n): Promise<{ file: EditFileValue; resourceLink?: ContentBlock }> {\n const { validPath, content } = await ctx.fs.readEditableText(filePath, {\n signal: ctx.signal,\n });\n const editResult = applyEdits(content, edits, options.ignoreWhitespace);\n\n if (options.dryRun) {\n if (editResult.appliedEdits > 0) {\n editResult.diff = unifiedPatch(basename(validPath), content, editResult.content);\n }\n\n // Nothing was written, so there is no updated content to point a\n // resourceUri or a resource_link at — the file on disk is still the one the\n // caller already has. Same rule the appliedEdits-is-0 case follows: no\n // write, no link.\n const meta = buildEditFileMetadata(editResult.content, validPath, 0, ctx.resourceStore);\n return {\n file: buildEditFileValue(validPath, meta, new Date().toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n }\n\n if (editResult.unmatchedEdits.length > 0) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n `${editResult.unmatchedEdits.length} edit(s) failed to match. Verify oldText matches exact file content.`,\n filePath,\n );\n }\n\n if (editResult.appliedEdits > 0) {\n await ctx.fs.writeFile(filePath, editResult.content, {\n encoding: 'utf-8',\n signal: ctx.signal,\n });\n ctx.log?.(\n 'info',\n `edit: ${filePath} (${editResult.appliedEdits} edits, +${editResult.linesAdded}/-${editResult.linesRemoved})`,\n 'edit',\n );\n }\n\n // `modified` is read from a post-write stat and is advisory: under a concurrent\n // writer it may reflect that writer's mtime while `size`/content below come from\n // this edit's atomic write. The file content itself is always consistent.\n const { stats: fileStats } = await ctx.fs.stat(filePath, { signal: ctx.signal });\n const meta = buildEditFileMetadata(\n editResult.content,\n validPath,\n editResult.appliedEdits,\n ctx.resourceStore,\n );\n return {\n file: buildEditFileValue(validPath, meta, fileStats.mtime.toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n}\n\nfunction formatEditSummary(\n results: readonly z.infer<typeof EditPerPathSchema>[],\n dryRun: boolean,\n): string {\n const tag = dryRun ? ' [dry run]' : '';\n // Single-file failure: say why here rather than making the caller read\n // structuredContent for the one message that can apply.\n const [only] = results;\n if (results.length === 1 && only?.error) {\n return `edit: ${only.path} FAILED — ${only.error.message}${tag}`;\n }\n const tokens = results.map((r) => {\n if (r.error) return `${basename(r.path)} FAILED`;\n const v = r.value;\n if (!v) return `${basename(r.path)} (no result)`;\n if (v.unmatchedEdits && v.unmatchedEdits.length > 0) return `${basename(v.path)} NO MATCH`;\n const added = v.linesAdded ?? 0;\n const removed = v.linesRemoved ?? 0;\n if (added === 0 && removed === 0) return `${basename(v.path)} (no change)`;\n return `${basename(v.path)} +${String(added)} -${String(removed)}`;\n });\n\n const failed = results.filter((r) => r.error !== undefined).length;\n const ok = results.length - failed;\n const ratio = failed > 0 ? ` (${String(ok)}/${String(results.length)} ok)` : '';\n return `edit: ${tokens.join(' · ')}${ratio}${tag}`;\n}\n\nexport const EDIT = defineTool({\n name: 'edit',\n title: 'Edit Files',\n description:\n 'Apply sequential literal string replacements to one or more files (max 5 files per call). ' +\n 'Modes: single-file { path, edits } or per-file { files: [{ path, edits }] }. ' +\n 'oldText must match file content exactly; include 3-5 lines of surrounding context to ensure uniqueness. ' +\n 'Set dryRun=true to preview diffs without writing. ' +\n 'For glob-based bulk regex replacement across many files, use replace_text instead.',\n input: EditFileInputSchema,\n output: EditFileOutputSchema,\n annotations: {\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n },\n progress: (args) => {\n const dryLabel = args.dryRun ? ' [dry run]' : '';\n let subject: string;\n if (args.path !== undefined) {\n subject = basename(args.path);\n } else if (args.files !== undefined) {\n subject = `${args.files.length} files`;\n } else {\n subject = 'files';\n }\n return { label: `Edit${dryLabel}`, subject };\n },\n accessPaths: singleOrBatchAccessPaths,\n run: async (args, ctx) => {\n const sharedEdits = args.edits ?? [];\n const batchInput = args.path !== undefined ? { path: args.path } : { files: args.files ?? [] };\n\n const options: EditFileOptions = {\n dryRun: args.dryRun,\n ignoreWhitespace: args.ignoreWhitespace,\n };\n\n const batch = await runOverPaths<\n { edits: z.infer<typeof EditSpecSchema>[] },\n { file: EditFileValue; resourceLink?: ContentBlock }\n >(\n batchInput,\n ctx,\n ({ path, override }) => handleEditFile(path, override?.edits ?? sharedEdits, options, ctx),\n { defaultErrorCode: ErrorCode.UNKNOWN },\n );\n\n const perPathResults: z.infer<typeof EditPerPathSchema>[] = [];\n const resourceLinks: ContentBlock[] = [];\n for (const r of batch.results) {\n if ('error' in r) {\n perPathResults.push({ path: r.path, error: r.error });\n continue;\n }\n perPathResults.push({ path: r.path, value: r.value.file });\n if (r.value.resourceLink) resourceLinks.push(r.value.resourceLink);\n }\n\n const summaryText = formatEditSummary(perPathResults, args.dryRun);\n\n return {\n structured: {\n results: perPathResults,\n summary: batch.summary,\n },\n text: summaryText,\n isError: isTotalFailure(batch.summary),\n ...(resourceLinks.length > 0 ? { resources: resourceLinks } : {}),\n };\n },\n});\n"]}
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAwB,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,OAAO,EACP,WAAW,EACX,SAAS,EACT,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAgB,MAAM,aAAa,CAAC;AAEvD,MAAM,cAAc,GAAG,CAAC;KACrB,YAAY,CAAC;IACZ,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC;SAC1B,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,EAAE,4CAA4C;KACtD,CAAC;SACD,QAAQ,CACP,mLAAmL,CACpL;SACA,IAAI,CAAC,EAAE,QAAQ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O,EAAE,CACxC,CAAC;QAEF,MAAM,cAAc,GAAwC,EAAE,CAAC;QAC/D,MAAM,aAAa,GAAmB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAC9B,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;gBACjB,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;gBACtD,SAAS;YACX,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3D,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY;gBAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnE,OAAO;YACL,UAAU,EAAE;gBACV,OAAO,EAAE,cAAc;gBACvB,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB;YACD,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC;YACtC,GAAG,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { ContentBlock } from '@modelcontextprotocol/server';\n\nimport { basename } from 'node:path';\n\nimport * as z from 'zod/v4';\n\nimport { computeDiffStats, unifiedPatch } from '../core/diff.js';\nimport { ErrorCode, FsError } from '../core/errors.js';\nimport { buildWrittenFileMeta, type WrittenFileMeta } from '../core/file-uri.js';\nimport { escapeRegexLiteral } from '../core/primitives.js';\nimport {\n defaultFalseBoolean,\n FileKind,\n isBlank,\n IsoDateTime,\n NonNegInt,\n OperationSummarySchema,\n PerFileErrorSchema,\n RequiredPath,\n singleOrBatchAccessPaths,\n} from '../core/schema.js';\nimport { compileRegex, execMatches, freeRegex } from '../core/search.js';\nimport type { ResourceStore } from '../core/store.js';\nimport { isTotalFailure, runOverPaths } from './batch.js';\nimport { defineTool, type ToolCtx } from './define.js';\n\nconst EditSpecSchema = z\n .strictObject({\n oldText: z\n .string()\n .min(1, 'oldText required')\n .refine((val) => !isBlank(val), {\n message: 'oldText cannot be empty or whitespace-only',\n })\n .describe(\n 'Exact literal text to locate in the file; it must match exactly once. Include 3-5 lines of context so it does — an oldText found in several places fails with their line numbers.',\n )\n .meta({ examples: ['const x = 1;', 'function oldName('] }),\n newText: z\n .string()\n .describe('Replacement text. Use an empty string to delete the matched oldText.')\n .meta({ examples: ['const x = 2;', 'function newName(', ''] }),\n })\n // The one document in this server where a `$ref` pays: this subschema is used\n // at both `edits` and `files[].edits`, so an `id` hoists it into `$defs` once\n // instead of inlining ~1.3 kB twice. Shared schemas used once per document\n // deliberately carry no `id` — there a `$ref` costs more than it saves.\n .meta({ id: 'EditSpec' });\n\nconst MAX_MULTI_FILES = 5;\nconst MAX_EDITS_PER_FILE = 100;\n\nconst EditFileInputSchema = z\n .strictObject({\n path: RequiredPath.optional().describe('Single file path; mutually exclusive with files'),\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .optional()\n .describe('Replacements applied to path; not allowed when using files'),\n files: z\n .array(\n z.strictObject({\n path: RequiredPath,\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .describe('Replacements to apply to this specific file'),\n }),\n )\n .min(1)\n .max(MAX_MULTI_FILES)\n .optional()\n .describe('Per-file entries (batch mode)'),\n dryRun: defaultFalseBoolean(\n 'Preview diffs without writing to disk (default: false = apply edits)',\n ),\n ignoreWhitespace: defaultFalseBoolean(\n 'Ignore leading/trailing whitespace differences when matching oldText',\n ),\n })\n .superRefine((value, ctx) => {\n const hasPath = value.path !== undefined;\n const hasFiles = value.files !== undefined;\n if (hasPath === hasFiles) {\n ctx.addIssue({\n code: 'custom',\n path: ['path'],\n message: \"Provide exactly one of 'path' or 'files'\",\n input: value,\n });\n }\n if (hasPath && value.edits === undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' required when using 'path'\",\n input: value,\n });\n }\n if (hasFiles && value.edits !== undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' not allowed with 'files'; each file carries its own edits\",\n input: value,\n });\n }\n })\n // Mirror the superRefine on the wire: exactly one input mode, and single-file\n // mode carries its own `edits`. Without `edits` in the first branch, `{ path }`\n // alone validated against the published schema and was then rejected at\n // runtime — the model had no way to see that coming.\n .meta({ oneOf: [{ required: ['path', 'edits'] }, { required: ['files'] }] });\n\nconst PerFileResultSchema = z.strictObject({\n path: z.string().describe('Resolved absolute path of the edited file'),\n size: NonNegInt.describe('File size in bytes after edits'),\n lineCount: NonNegInt.describe('Number of lines in the file after edits'),\n mimeType: z.string().describe('Detected MIME type of the file'),\n kind: FileKind.describe('Broad file kind: text, binary, image, audio, or pdf'),\n resourceUri: z\n .string()\n .optional()\n .describe(\n 'Resource URI pointing to the updated file content; omitted when no edit matched (appliedEdits is 0) and the file was left untouched',\n ),\n modified: IsoDateTime.describe('Last modification timestamp after edits (ISO 8601 UTC)'),\n appliedEdits: NonNegInt.describe('Number of edits successfully applied'),\n linesAdded: NonNegInt.optional().describe('Net lines added by all applied edits'),\n linesRemoved: NonNegInt.optional().describe('Net lines removed by all applied edits'),\n diff: z.string().optional().describe('Unified diff of all changes (present only in dryRun mode)'),\n unmatchedEdits: z\n .array(z.string())\n .optional()\n .describe('oldText values that did not match any content in the file'),\n});\n\nconst EditPerPathSchema = z.strictObject({\n path: z.string().describe('Requested file path'),\n value: PerFileResultSchema.optional().describe('Edit result; present on success'),\n error: PerFileErrorSchema.optional().describe('Error details; present on failure'),\n});\n\nconst EditFileOutputSchema = z.strictObject({\n results: z\n .array(EditPerPathSchema)\n .describe('Per-path edit results ordered to match the input paths'),\n summary: OperationSummarySchema,\n});\n\ntype EditFileValue = z.infer<typeof PerFileResultSchema>;\n\ninterface TextRange {\n startIndex: number;\n length: number;\n}\n\ninterface EditResult {\n content: string;\n appliedEdits: number;\n unmatchedEdits: string[];\n linesAdded: number;\n linesRemoved: number;\n diff?: string;\n}\n\nconst MAX_REPORTED_MATCH_LINES = 5;\n\ninterface EditMatches {\n /** The first match; undefined when oldText matches nothing. */\n first: TextRange | undefined;\n count: number;\n /** UTF-16 start offsets of the first {@link MAX_REPORTED_MATCH_LINES} matches. */\n starts: number[];\n}\n\n/**\n * Where `oldText` matches. `count` is non-overlapping occurrences, except that a\n * lone match with a second one overlapping it counts two (`abab` in `ababab`),\n * since either is a span the caller could have meant — the count is exact only\n * when it answers \"once or not\". Only the count and the first few starts are\n * kept: a short oldText in a large file can match millions of times.\n */\nfunction findEditMatches(content: string, oldText: string, ignoreWhitespace: boolean): EditMatches {\n const found: EditMatches = { first: undefined, count: 0, starts: [] };\n const add = (startIndex: number, length: number): void => {\n found.first ??= { startIndex, length };\n found.count += 1;\n if (found.starts.length < MAX_REPORTED_MATCH_LINES) found.starts.push(startIndex);\n };\n\n if (ignoreWhitespace) {\n // Make whitespace flexible (tolerate indentation/spacing differences)\n // without letting it cross line boundaries: a whitespace run that contains\n // a newline keeps at least one newline, so a single-line oldText cannot\n // match across a newline and a multi-line oldText cannot collapse onto one\n // line. Horizontal whitespace stays mandatory between word characters so\n // adjacent identifiers are not merged.\n const pattern = escapeRegexLiteral(oldText)\n .replace(/[^\\S\\n]*\\n\\s*/g, '[^\\\\S\\\\n]*\\\\n+[^\\\\S\\\\n]*')\n .replace(/(\\w)[^\\S\\n]+(\\w)/g, '$1[^\\\\S\\\\n]+$2')\n .replace(/[^\\S\\n]+/g, '[^\\\\S\\\\n]*');\n const regex = compileRegex(pattern, { caseSensitive: true });\n try {\n // execMatches resets lastIndex and reports UTF-16 offsets; the raw RE2\n // index counts code points and would splice off-by-one per emoji.\n const scan = (from: number): void => {\n for (const match of execMatches(regex, from === 0 ? content : content.slice(from))) {\n // A zero-length match names an empty span, which cannot be replaced.\n if (match.text.length > 0) add(from + match.start, match.text.length);\n if (from > 0) return;\n }\n };\n scan(0);\n // execMatches resumes past each match, so a second match overlapping the\n // first is never reported; look once more from just past its first\n // non-whitespace character. Starting inside the leading whitespace would\n // re-find the same occurrence, since the pattern's leading run is `*`. The\n // pattern carries no anchors, so matching a suffix finds the same spans.\n if (found.count === 1 && found.first) {\n const { startIndex, length } = found.first;\n const lead = content.slice(startIndex, startIndex + length).search(/\\S/u);\n scan(afterCodePoint(content, startIndex + lead));\n }\n } finally {\n // The compiled pattern owns wasm memory re2-wasm never reclaims on its\n // own; its lifetime is this one search.\n freeRegex(regex);\n }\n return found;\n }\n\n // Non-overlapping, so the scan stays linear on repetitive content; the one\n // overlap that matters — a second match inside the only one — is checked after.\n for (\n let i = content.indexOf(oldText);\n i !== -1;\n i = content.indexOf(oldText, i + oldText.length)\n ) {\n add(i, oldText.length);\n }\n if (found.count === 1 && found.first) {\n const overlap = content.indexOf(oldText, afterCodePoint(content, found.first.startIndex));\n if (overlap !== -1) add(overlap, oldText.length);\n }\n return found;\n}\n\n/** The UTF-16 offset just past the code point at `index`, so a surrogate pair is never split. */\nfunction afterCodePoint(content: string, index: number): number {\n return index + ((content.codePointAt(index) ?? 0) > 0xffff ? 2 : 1);\n}\n\nfunction ambiguousEditError(\n content: string,\n found: EditMatches,\n editIndex: number,\n shifted: boolean,\n): FsError {\n const lines = [\n ...new Set(found.starts.map((start) => content.slice(0, start).split('\\n').length)),\n ];\n const label = lines.length === 1 ? 'line' : 'lines';\n const more = found.count > found.starts.length ? ', ...' : '';\n // Offsets come from the content as earlier edits in this call left it, which\n // is not the file the caller read once one of them has applied.\n const where = shifted ? ' after earlier edits' : '';\n return new FsError(\n ErrorCode.INVALID_INPUT,\n `edits[${String(editIndex)}]: oldText matches ${String(found.count)} places${where} ` +\n `(${label} ${lines.join(', ')}${more}). Add surrounding lines so it matches once.`,\n );\n}\n\nfunction replaceEditMatch(content: string, match: TextRange, newText: string): string {\n return (\n content.slice(0, match.startIndex) + newText + content.slice(match.startIndex + match.length)\n );\n}\n\nfunction buildEditFileValue(\n validPath: string,\n meta: EditFileMetadata,\n modified: string,\n result: EditResult,\n): EditFileValue {\n return {\n path: validPath,\n size: meta.size,\n lineCount: meta.lineCount,\n mimeType: meta.mimeType,\n kind: meta.kind,\n ...(meta.resourceUri !== undefined ? { resourceUri: meta.resourceUri } : {}),\n modified,\n appliedEdits: result.appliedEdits,\n ...(result.appliedEdits > 0\n ? { linesAdded: result.linesAdded, linesRemoved: result.linesRemoved }\n : {}),\n ...(result.unmatchedEdits.length > 0 ? { unmatchedEdits: result.unmatchedEdits } : {}),\n ...(result.diff ? { diff: result.diff } : {}),\n };\n}\n\nfunction finalizeEditResult(\n originalContent: string,\n updatedContent: string,\n appliedEdits: number,\n unmatchedEdits: string[],\n): EditResult {\n const { linesAdded, linesRemoved } =\n appliedEdits > 0\n ? computeDiffStats(originalContent, updatedContent)\n : { linesAdded: 0, linesRemoved: 0 };\n\n return {\n content: updatedContent,\n appliedEdits,\n unmatchedEdits,\n linesAdded,\n linesRemoved,\n };\n}\n\n/** {@link WrittenFileMeta}, with `resourceUri` widened: an edit that matched\n * nothing has no updated content to point at. */\ntype EditFileMetadata = Omit<WrittenFileMeta, 'resourceUri'> & {\n resourceUri: string | undefined;\n};\n\nfunction buildEditFileMetadata(\n content: string,\n validPath: string,\n appliedEdits: number,\n resourceStore: ResourceStore | undefined,\n): EditFileMetadata {\n const meta = buildWrittenFileMeta(validPath, content, resourceStore);\n // Omitted rather than empty-stringed when nothing matched: `\"\"` satisfied the\n // schema's `string` and then failed every resources/read a client tried it on.\n const written = appliedEdits > 0;\n return {\n ...meta,\n resourceUri: written ? meta.resourceUri : undefined,\n resourceLink: written ? meta.resourceLink : undefined,\n };\n}\n\nfunction applyEdits(\n content: string,\n edits: z.infer<typeof EditSpecSchema>[],\n ignoreWhitespace: boolean,\n): EditResult {\n let newContent = content;\n let appliedEdits = 0;\n const unmatchedEdits: string[] = [];\n\n for (const [index, edit] of edits.entries()) {\n const found = findEditMatches(newContent, edit.oldText, ignoreWhitespace);\n\n // A second match is an error rather than a pick: splicing the first would\n // edit a block the caller may not have meant and still report success.\n if (found.count > 1) throw ambiguousEditError(newContent, found, index, appliedEdits > 0);\n\n if (!found.first) {\n unmatchedEdits.push(edit.oldText);\n continue;\n }\n\n newContent = replaceEditMatch(newContent, found.first, edit.newText);\n appliedEdits += 1;\n }\n\n return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits);\n}\n\ninterface EditFileOptions {\n dryRun: boolean;\n ignoreWhitespace: boolean;\n}\n\nasync function handleEditFile(\n filePath: string,\n edits: z.infer<typeof EditSpecSchema>[],\n options: EditFileOptions,\n ctx: ToolCtx,\n): Promise<{ file: EditFileValue; resourceLink?: ContentBlock }> {\n const { validPath, content } = await ctx.fs.readEditableText(filePath, {\n signal: ctx.signal,\n });\n const editResult = applyEdits(content, edits, options.ignoreWhitespace);\n\n if (options.dryRun) {\n if (editResult.appliedEdits > 0) {\n editResult.diff = unifiedPatch(basename(validPath), content, editResult.content);\n }\n\n // Nothing was written, so there is no updated content to point a\n // resourceUri or a resource_link at — the file on disk is still the one the\n // caller already has. Same rule the appliedEdits-is-0 case follows: no\n // write, no link.\n const meta = buildEditFileMetadata(editResult.content, validPath, 0, ctx.resourceStore);\n return {\n file: buildEditFileValue(validPath, meta, new Date().toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n }\n\n if (editResult.unmatchedEdits.length > 0) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n `${editResult.unmatchedEdits.length} edit(s) failed to match. Verify oldText matches exact file content.`,\n filePath,\n );\n }\n\n if (editResult.appliedEdits > 0) {\n await ctx.fs.writeFile(filePath, editResult.content, {\n encoding: 'utf-8',\n signal: ctx.signal,\n });\n ctx.log?.(\n 'info',\n `edit: ${filePath} (${editResult.appliedEdits} edits, +${editResult.linesAdded}/-${editResult.linesRemoved})`,\n 'edit',\n );\n }\n\n // `modified` is read from a post-write stat and is advisory: under a concurrent\n // writer it may reflect that writer's mtime while `size`/content below come from\n // this edit's atomic write. The file content itself is always consistent.\n const { stats: fileStats } = await ctx.fs.stat(filePath, { signal: ctx.signal });\n const meta = buildEditFileMetadata(\n editResult.content,\n validPath,\n editResult.appliedEdits,\n ctx.resourceStore,\n );\n return {\n file: buildEditFileValue(validPath, meta, fileStats.mtime.toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n}\n\nfunction formatEditSummary(\n results: readonly z.infer<typeof EditPerPathSchema>[],\n dryRun: boolean,\n): string {\n const tag = dryRun ? ' [dry run]' : '';\n // Single-file failure: say why here rather than making the caller read\n // structuredContent for the one message that can apply.\n const [only] = results;\n if (results.length === 1 && only?.error) {\n return `edit: ${only.path} FAILED — ${only.error.message}${tag}`;\n }\n const tokens = results.map((r) => {\n if (r.error) return `${basename(r.path)} FAILED`;\n const v = r.value;\n if (!v) return `${basename(r.path)} (no result)`;\n if (v.unmatchedEdits && v.unmatchedEdits.length > 0) return `${basename(v.path)} NO MATCH`;\n const added = v.linesAdded ?? 0;\n const removed = v.linesRemoved ?? 0;\n if (added === 0 && removed === 0) return `${basename(v.path)} (no change)`;\n return `${basename(v.path)} +${String(added)} -${String(removed)}`;\n });\n\n const failed = results.filter((r) => r.error !== undefined).length;\n const ok = results.length - failed;\n const ratio = failed > 0 ? ` (${String(ok)}/${String(results.length)} ok)` : '';\n return `edit: ${tokens.join(' · ')}${ratio}${tag}`;\n}\n\nexport const EDIT = defineTool({\n name: 'edit',\n title: 'Edit Files',\n description:\n 'Apply sequential literal string replacements to one or more files (max 5 files per call). ' +\n 'Modes: single-file { path, edits } or per-file { files: [{ path, edits }] }. ' +\n 'oldText must match file content exactly and only once; include 3-5 lines of surrounding context, ' +\n 'or the edit fails listing the lines it matched. ' +\n 'Set dryRun=true to preview diffs without writing. ' +\n 'For glob-based bulk regex replacement across many files, use replace_text instead.',\n input: EditFileInputSchema,\n output: EditFileOutputSchema,\n annotations: {\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n },\n progress: (args) => {\n const dryLabel = args.dryRun ? ' [dry run]' : '';\n let subject: string;\n if (args.path !== undefined) {\n subject = basename(args.path);\n } else if (args.files !== undefined) {\n subject = `${args.files.length} files`;\n } else {\n subject = 'files';\n }\n return { label: `Edit${dryLabel}`, subject };\n },\n accessPaths: singleOrBatchAccessPaths,\n run: async (args, ctx) => {\n const sharedEdits = args.edits ?? [];\n const batchInput = args.path !== undefined ? { path: args.path } : { files: args.files ?? [] };\n\n const options: EditFileOptions = {\n dryRun: args.dryRun,\n ignoreWhitespace: args.ignoreWhitespace,\n };\n\n const batch = await runOverPaths<\n { edits: z.infer<typeof EditSpecSchema>[] },\n { file: EditFileValue; resourceLink?: ContentBlock }\n >(\n batchInput,\n ctx,\n ({ path, override }) => handleEditFile(path, override?.edits ?? sharedEdits, options, ctx),\n { defaultErrorCode: ErrorCode.UNKNOWN },\n );\n\n const perPathResults: z.infer<typeof EditPerPathSchema>[] = [];\n const resourceLinks: ContentBlock[] = [];\n for (const r of batch.results) {\n if ('error' in r) {\n perPathResults.push({ path: r.path, error: r.error });\n continue;\n }\n perPathResults.push({ path: r.path, value: r.value.file });\n if (r.value.resourceLink) resourceLinks.push(r.value.resourceLink);\n }\n\n const summaryText = formatEditSummary(perPathResults, args.dryRun);\n\n return {\n structured: {\n results: perPathResults,\n summary: batch.summary,\n },\n text: summaryText,\n isError: isTotalFailure(batch.summary),\n ...(resourceLinks.length > 0 ? { resources: resourceLinks } : {}),\n };\n },\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const FIND_FILES: import("./define.js").DefinedTool;
2
+ //# sourceMappingURL=find-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-files.d.ts","sourceRoot":"","sources":["../../src/tools/find-files.ts"],"names":[],"mappings":"AA4LA,eAAO,MAAM,UAAU,mCA+CrB,CAAC"}
@@ -1,9 +1,8 @@
1
1
  import * as z from 'zod/v4';
2
2
  import { SearchStoppedReasonSchema } from '../core/concurrency.js';
3
- import { paginate } from '../core/cursor.js';
3
+ import { pageQueryKey, paginate } from '../core/cursor.js';
4
4
  import { ErrorCode } from '../core/errors.js';
5
5
  import { formatCount, pageTrailer, truncateProgressPattern } from '../core/fmt.js';
6
- import { DEFAULT_EXCLUDE_PATTERNS } from '../core/glob.js';
7
6
  import { toPosixRelative } from '../core/path.js';
8
7
  import { CursorSchema, includeHiddenField, includeIgnoredField, maxDepthField, NextCursorSchema, NonNegInt, OptionalPath, SafeGlobPattern, } from '../core/schema.js';
9
8
  import { searchFiles } from '../core/search.js';
@@ -57,17 +56,6 @@ function buildRelativeResults(basePath, displayResults) {
57
56
  }
58
57
  return relativeResults;
59
58
  }
60
- function searchFilesQueryKey(args, basePath) {
61
- return JSON.stringify({
62
- method: 'find_files',
63
- path: basePath,
64
- pattern: args.pattern,
65
- includeIgnored: args.includeIgnored,
66
- includeHidden: args.includeHidden,
67
- sortBy: args.sortBy,
68
- maxDepth: args.maxDepth,
69
- });
70
- }
71
59
  function searchFilesOutput(results, metadata, nextCursor, resourceUri) {
72
60
  return {
73
61
  root: metadata.root,
@@ -82,7 +70,15 @@ function searchFilesOutput(results, metadata, nextCursor, resourceUri) {
82
70
  }
83
71
  async function handleSearchFiles(args, ctx) {
84
72
  const requestedBasePath = ctx.fs.pathGuard.resolvePathOrRoot(args.path);
85
- const queryKey = searchFilesQueryKey(args, requestedBasePath);
73
+ const queryKey = pageQueryKey({
74
+ method: 'find_files',
75
+ path: requestedBasePath,
76
+ pattern: args.pattern,
77
+ includeIgnored: args.includeIgnored,
78
+ includeHidden: args.includeHidden,
79
+ sortBy: args.sortBy,
80
+ maxDepth: args.maxDepth,
81
+ });
86
82
  const { resourceStore } = ctx;
87
83
  const paged = await paginate({
88
84
  store: ctx.pageStore,
@@ -91,16 +87,15 @@ async function handleSearchFiles(args, ctx) {
91
87
  pageSize: args.maxResults,
92
88
  produce: async () => {
93
89
  const basePath = await ctx.fs.pathGuard.validateExistingDirectory(requestedBasePath);
94
- const excludePatterns = args.includeIgnored ? [] : DEFAULT_EXCLUDE_PATTERNS;
95
90
  const searchOptions = {
96
91
  maxResults: MAX_SEARCH_RESULTS,
97
92
  includeHidden: args.includeHidden,
98
93
  sortBy: args.sortBy,
99
- respectGitignore: !args.includeIgnored,
94
+ skipIgnored: !args.includeIgnored,
100
95
  ...(args.maxDepth !== undefined ? { maxDepth: args.maxDepth } : {}),
101
96
  signal: ctx.signal,
102
97
  };
103
- const result = await searchFiles(basePath, args.pattern, excludePatterns, searchOptions, ctx.fs.pathGuard);
98
+ const result = await searchFiles(basePath, args.pattern, searchOptions, ctx.fs.pathGuard);
104
99
  return {
105
100
  items: buildRelativeResults(result.basePath, result.results),
106
101
  metadata: {
@@ -128,7 +123,7 @@ async function handleSearchFiles(args, ctx) {
128
123
  ...(paged.resource ? { link: paged.resource.link } : {}),
129
124
  };
130
125
  }
131
- export const SEARCH_FILES = defineTool({
126
+ export const FIND_FILES = defineTool({
132
127
  name: 'find_files',
133
128
  title: 'Find Files',
134
129
  description: 'Find files matching a glob pattern. Returns matched paths with optional metadata. ' +
@@ -173,4 +168,4 @@ export const SEARCH_FILES = defineTool({
173
168
  return { structured, text };
174
169
  },
175
170
  });
176
- //# sourceMappingURL=search-files.js.map
171
+ //# sourceMappingURL=find-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-files.js","sourceRoot":"","sources":["../../src/tools/find-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;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AAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF,CAAC,CAAC","sourcesContent":["import * as z from 'zod/v4';\n\nimport { SearchStoppedReasonSchema } from '../core/concurrency.js';\nimport { pageQueryKey, paginate } from '../core/cursor.js';\nimport { ErrorCode } from '../core/errors.js';\nimport { formatCount, pageTrailer, truncateProgressPattern } from '../core/fmt.js';\nimport { toPosixRelative } from '../core/path.js';\nimport {\n CursorSchema,\n includeHiddenField,\n includeIgnoredField,\n maxDepthField,\n NextCursorSchema,\n NonNegInt,\n OptionalPath,\n SafeGlobPattern,\n} from '../core/schema.js';\nimport { searchFiles } from '../core/search.js';\nimport type { JsonResourceResult } from '../core/store.js';\nimport { putJsonResource } from '../core/store.js';\nimport {\n DEFAULT_SEARCH_RESULTS,\n DEFAULT_SEARCH_TIMEOUT_MS,\n MAX_SEARCH_RESULTS,\n} from '../core/util.js';\nimport { defineTool, type ToolCtx } from './define.js';\n\n// ---------------------------------------------------------------------------\n\nconst SearchFilesInputSchema = z.strictObject({\n path: OptionalPath.describe('Base directory to search under (default: first allowed root)'),\n pattern: SafeGlobPattern.describe('Glob pattern to match file paths (e.g. **/*.ts, src/**/*.js)'),\n maxResults: z\n .uint32()\n .min(1)\n .max(MAX_SEARCH_RESULTS)\n .optional()\n .default(DEFAULT_SEARCH_RESULTS)\n .describe('Maximum number of matching files to return per page'),\n includeIgnored: includeIgnoredField(),\n includeHidden: includeHiddenField(),\n sortBy: z\n .enum(['name', 'path'])\n .optional()\n .default('path')\n .describe('Sort order: path = full path (default), name = basename only'),\n maxDepth: maxDepthField(),\n cursor: CursorSchema,\n});\n\nconst SearchFilesOutputSchema = z.strictObject({\n root: z.string().describe('Resolved base directory used as the search root'),\n results: z\n .array(\n z.strictObject({\n path: z.string().describe('File path relative to the search root'),\n }),\n )\n .describe('Matched files ordered by sortBy'),\n totalMatches: NonNegInt.optional().describe('Total number of matching files found'),\n filesScanned: NonNegInt.optional().describe('Total number of files examined during the search'),\n skippedInaccessible: NonNegInt.optional().describe(\n 'Files skipped due to permission or access errors',\n ),\n stoppedReason: SearchStoppedReasonSchema.describe(\n 'Why the search ended early: maxResults = result cap reached, timeout = time limit hit or the request was cancelled. Absent when the scan ran to completion.',\n ),\n resourceUri: z\n .string()\n .optional()\n .describe(\n 'URI to the full results JSON in the resource store; first page only, whenever the response is incomplete — more pages follow, or the result cap cut the search',\n ),\n nextCursor: NextCursorSchema,\n});\n\nfunction buildRelativeResults(\n basePath: string,\n displayResults: readonly { path: string }[],\n): NonNullable<z.infer<typeof SearchFilesOutputSchema>['results']> {\n const relativeResults: NonNullable<z.infer<typeof SearchFilesOutputSchema>['results']> = [];\n for (const entry of displayResults) {\n relativeResults.push({\n path: toPosixRelative(basePath, entry.path),\n });\n }\n return relativeResults;\n}\n\ntype SearchFileResult = NonNullable<z.infer<typeof SearchFilesOutputSchema>['results']>[number];\n\ninterface SearchFilesPageMetadata {\n readonly root: string;\n readonly totalMatches: number;\n readonly filesScanned: number;\n readonly skippedInaccessible?: number;\n readonly stoppedReason?: z.infer<typeof SearchFilesOutputSchema>['stoppedReason'];\n}\n\nfunction searchFilesOutput(\n results: readonly SearchFileResult[],\n metadata: SearchFilesPageMetadata,\n nextCursor: string | undefined,\n resourceUri: string | undefined,\n): z.infer<typeof SearchFilesOutputSchema> {\n return {\n root: metadata.root,\n results: [...results],\n totalMatches: metadata.totalMatches,\n filesScanned: metadata.filesScanned,\n ...(metadata.skippedInaccessible ? { skippedInaccessible: metadata.skippedInaccessible } : {}),\n ...(metadata.stoppedReason !== undefined ? { stoppedReason: metadata.stoppedReason } : {}),\n ...(resourceUri !== undefined ? { resourceUri } : {}),\n ...(nextCursor !== undefined ? { nextCursor } : {}),\n };\n}\n\nasync function handleSearchFiles(\n args: z.infer<typeof SearchFilesInputSchema>,\n ctx: ToolCtx,\n): Promise<{\n structured: z.infer<typeof SearchFilesOutputSchema>;\n offset: number;\n total: number;\n link?: ReturnType<typeof putJsonResource>['link'];\n}> {\n const requestedBasePath = ctx.fs.pathGuard.resolvePathOrRoot(args.path);\n const queryKey = pageQueryKey({\n method: 'find_files',\n path: requestedBasePath,\n pattern: args.pattern,\n includeIgnored: args.includeIgnored,\n includeHidden: args.includeHidden,\n sortBy: args.sortBy,\n maxDepth: args.maxDepth,\n });\n const { resourceStore } = ctx;\n\n const paged = await paginate<SearchFileResult, SearchFilesPageMetadata, JsonResourceResult>({\n store: ctx.pageStore,\n queryKey,\n cursor: args.cursor,\n pageSize: args.maxResults,\n produce: async () => {\n const basePath = await ctx.fs.pathGuard.validateExistingDirectory(requestedBasePath);\n const searchOptions: Parameters<typeof searchFiles>[2] = {\n maxResults: MAX_SEARCH_RESULTS,\n includeHidden: args.includeHidden,\n sortBy: args.sortBy,\n skipIgnored: !args.includeIgnored,\n ...(args.maxDepth !== undefined ? { maxDepth: args.maxDepth } : {}),\n signal: ctx.signal,\n };\n const result = await searchFiles(basePath, args.pattern, searchOptions, ctx.fs.pathGuard);\n return {\n items: buildRelativeResults(result.basePath, result.results),\n metadata: {\n root: result.basePath,\n totalMatches: result.summary.matched,\n filesScanned: result.summary.filesScanned,\n ...(result.summary.skippedInaccessible\n ? { skippedInaccessible: result.summary.skippedInaccessible }\n : {}),\n ...(result.summary.stoppedReason !== undefined\n ? { stoppedReason: result.summary.stoppedReason }\n : {}),\n },\n truncated: result.summary.truncated,\n };\n },\n externalize: resourceStore\n ? (results) => putJsonResource(resourceStore, `${args.pattern} files`, results)\n : undefined,\n });\n\n return {\n structured: searchFilesOutput(\n paged.page,\n paged.metadata,\n paged.nextCursor,\n paged.resource?.entry.uri,\n ),\n offset: paged.offset,\n total: paged.metadata.totalMatches,\n ...(paged.resource ? { link: paged.resource.link } : {}),\n };\n}\n\nexport const FIND_FILES = defineTool({\n name: 'find_files',\n title: 'Find Files',\n description:\n 'Find files matching a glob pattern. Returns matched paths with optional metadata. ' +\n 'Pagination cursors reference a query-bound snapshot that expires after 60 seconds. ' +\n 'For content search use search_text; for bulk regex replacements use replace_text with the same glob.',\n input: SearchFilesInputSchema,\n output: SearchFilesOutputSchema,\n annotations: {\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n timeoutMs: DEFAULT_SEARCH_TIMEOUT_MS,\n defaultErrorCode: ErrorCode.UNKNOWN,\n progress: (args) => ({\n label: 'Find',\n subject: truncateProgressPattern(args.pattern),\n }),\n progressDone: (_args, result) => ({\n detail: formatCount(result.totalMatches ?? 0, 'match', 'matches'),\n }),\n accessPaths: (args) => (args.path ? [args.path] : []),\n run: async (args, ctx) => {\n const { structured, offset, total, link } = await handleSearchFiles(args, ctx);\n const body =\n structured.results.length > 0\n ? structured.results.map((r) => r.path).join('\\n')\n : `No files matching '${args.pattern}'`;\n const text =\n body +\n pageTrailer({\n offset,\n shown: structured.results.length,\n total,\n noun: 'files',\n tool: 'find_files',\n nextCursor: structured.nextCursor,\n stoppedReason: structured.stoppedReason,\n });\n if (link) {\n return { structured, text, resources: [link] };\n }\n return { structured, text };\n },\n});\n"]}
@@ -3,23 +3,24 @@ import type { PageSnapshotStore } from '../core/page-store.js';
3
3
  import type { PathGuard } from '../core/path.js';
4
4
  import type { ResourceStore } from '../core/store.js';
5
5
  import type { DefinedTool } from './define.js';
6
+ import { FIND_FILES } from './find-files.js';
7
+ import { LIST_ROOTS } from './list-roots.js';
6
8
  import { LIST } from './list.js';
7
- import { READ_FILE } from './read.js';
8
- import { LIST_ALLOWED_DIRECTORIES } from './roots.js';
9
- import { SEARCH_CONTENT } from './search-content.js';
10
- import { SEARCH_FILES } from './search-files.js';
11
- import { GET_FILE_INFO } from './stat.js';
9
+ import { READ } from './read.js';
10
+ import { SEARCH_TEXT } from './search-text.js';
11
+ import { STAT } from './stat.js';
12
12
  export declare const ALL_TOOLS: readonly [DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool];
13
13
  export declare const MUTATING_TOOL_NAMES: Set<string>;
14
14
  /** The tools a server registers at this setting — the one owner of the `--read-only` gate. */
15
15
  export declare function registeredTools(readOnly: boolean): readonly DefinedTool[];
16
- export { LIST, LIST_ALLOWED_DIRECTORIES, READ_FILE, SEARCH_CONTENT, SEARCH_FILES, GET_FILE_INFO };
16
+ export { LIST, LIST_ROOTS, READ, SEARCH_TEXT, FIND_FILES, STAT };
17
17
  interface ToolRegistrarDeps {
18
18
  readonly server: McpServer;
19
19
  readonly pathGuard: PathGuard;
20
20
  readonly pageStore: PageSnapshotStore;
21
21
  readonly resourceStore: ResourceStore;
22
22
  readonly readOnly?: boolean;
23
+ readonly era?: 'legacy' | 'modern';
23
24
  }
24
25
  export declare function registerTools(deps: ToolRegistrarDeps): void;
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,eAAO,MAAM,SAAS,oLAcZ,CAAC;AAEX,eAAO,MAAM,mBA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AAEX,eAAO,MAAM,mBAAmB,aAE/B,CAAC;AAEF,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,WAAW,EAAE,CAEzE;AAOD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAEjE,UAAU,iBAAiB;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CACpC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAW3D"}
@@ -1,30 +1,30 @@
1
1
  import { CREATE } from './create.js';
2
- import { DELETE_FILE } from './delete-file.js';
2
+ import { DELETE } from './delete.js';
3
3
  import { DIFF } from './diff.js';
4
4
  import { EDIT } from './edit.js';
5
+ import { FIND_FILES } from './find-files.js';
6
+ import { LIST_ROOTS } from './list-roots.js';
5
7
  import { LIST } from './list.js';
6
8
  import { MOVE } from './move.js';
7
9
  import { PATCH } from './patch.js';
8
- import { READ_FILE } from './read.js';
9
- import { SEARCH_AND_REPLACE } from './replace-in-files.js';
10
- import { LIST_ALLOWED_DIRECTORIES } from './roots.js';
11
- import { SEARCH_CONTENT } from './search-content.js';
12
- import { SEARCH_FILES } from './search-files.js';
13
- import { GET_FILE_INFO } from './stat.js';
10
+ import { READ } from './read.js';
11
+ import { REPLACE_TEXT } from './replace-text.js';
12
+ import { SEARCH_TEXT } from './search-text.js';
13
+ import { STAT } from './stat.js';
14
14
  export const ALL_TOOLS = [
15
15
  CREATE,
16
- DELETE_FILE,
16
+ DELETE,
17
17
  DIFF,
18
18
  EDIT,
19
19
  LIST,
20
20
  MOVE,
21
21
  PATCH,
22
- READ_FILE,
23
- SEARCH_AND_REPLACE,
24
- LIST_ALLOWED_DIRECTORIES,
25
- SEARCH_CONTENT,
26
- SEARCH_FILES,
27
- GET_FILE_INFO,
22
+ READ,
23
+ REPLACE_TEXT,
24
+ LIST_ROOTS,
25
+ SEARCH_TEXT,
26
+ FIND_FILES,
27
+ STAT,
28
28
  ];
29
29
  export const MUTATING_TOOL_NAMES = new Set(ALL_TOOLS.filter((t) => !t.annotations.readOnlyHint).map((t) => t.name));
30
30
  /** The tools a server registers at this setting — the one owner of the `--read-only` gate. */
@@ -36,13 +36,14 @@ export function registeredTools(readOnly) {
36
36
  // Only the read-only tools are named individually: the mutating six are no
37
37
  // longer listed by hand anywhere, so their names reach callers through
38
38
  // MUTATING_TOOL_NAMES and ALL_TOOLS instead.
39
- export { LIST, LIST_ALLOWED_DIRECTORIES, READ_FILE, SEARCH_CONTENT, SEARCH_FILES, GET_FILE_INFO };
39
+ export { LIST, LIST_ROOTS, READ, SEARCH_TEXT, FIND_FILES, STAT };
40
40
  export function registerTools(deps) {
41
41
  const toolDeps = {
42
42
  server: deps.server,
43
43
  pathGuard: deps.pathGuard,
44
44
  pageStore: deps.pageStore,
45
45
  resourceStore: deps.resourceStore,
46
+ ...(deps.era ? { era: deps.era } : {}),
46
47
  };
47
48
  for (const tool of registeredTools(deps.readOnly ?? false)) {
48
49
  tool.register(toolDeps);