
























@@ -115,6 +115,37 @@ function formatFindResult(
115115return text;
116116}
117117118+function buildFindResult(params: {
119+relativized: string[];
120+effectiveLimit: number;
121+limitNotice: string;
122+}): {
123+content: Array<{ type: "text"; text: string }>;
124+details: FindToolDetails | undefined;
125+} {
126+const resultLimitReached = params.relativized.length >= params.effectiveLimit;
127+const rawOutput = params.relativized.join("\n");
128+const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
129+let resultOutput = truncation.content;
130+const details: FindToolDetails = {};
131+const notices: string[] = [];
132+if (resultLimitReached) {
133+notices.push(params.limitNotice);
134+details.resultLimitReached = params.effectiveLimit;
135+}
136+if (truncation.truncated) {
137+notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
138+details.truncation = truncation;
139+}
140+if (notices.length > 0) {
141+resultOutput += `\n\n[${notices.join(". ")}]`;
142+}
143+return {
144+content: [{ type: "text", text: resultOutput }],
145+details: Object.keys(details).length > 0 ? details : undefined,
146+};
147+}
148+118149export function createFindToolDefinition(
119150cwd: string,
120151options?: FindToolOptions,
@@ -200,28 +231,14 @@ export function createFindToolDefinition(
200231}
201232return toPosixPath(path.relative(searchPath, p));
202233});
203-const resultLimitReached = relativized.length >= effectiveLimit;
204-const rawOutput = relativized.join("\n");
205-const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
206-let resultOutput = truncation.content;
207-const details: FindToolDetails = {};
208-const notices: string[] = [];
209-if (resultLimitReached) {
210-notices.push(`${effectiveLimit} results limit reached`);
211-details.resultLimitReached = effectiveLimit;
212-}
213-if (truncation.truncated) {
214-notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
215-details.truncation = truncation;
216-}
217-if (notices.length > 0) {
218-resultOutput += `\n\n[${notices.join(". ")}]`;
219-}
220234settle(() =>
221-resolve({
222-content: [{ type: "text", text: resultOutput }],
223-details: Object.keys(details).length > 0 ? details : undefined,
224-}),
235+resolve(
236+buildFindResult({
237+ relativized,
238+ effectiveLimit,
239+limitNotice: `${effectiveLimit} results limit reached`,
240+}),
241+),
225242);
226243return;
227244}
@@ -332,30 +349,14 @@ export function createFindToolDefinition(
332349relativized.push(toPosixPath(relativePath));
333350}
334351335-const resultLimitReached = relativized.length >= effectiveLimit;
336-const rawOutput = relativized.join("\n");
337-const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
338-let resultOutput = truncation.content;
339-const details: FindToolDetails = {};
340-const notices: string[] = [];
341-if (resultLimitReached) {
342-notices.push(
343-`${effectiveLimit} results limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`,
344-);
345-details.resultLimitReached = effectiveLimit;
346-}
347-if (truncation.truncated) {
348-notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
349-details.truncation = truncation;
350-}
351-if (notices.length > 0) {
352-resultOutput += `\n\n[${notices.join(". ")}]`;
353-}
354352settle(() =>
355-resolve({
356-content: [{ type: "text", text: resultOutput }],
357-details: Object.keys(details).length > 0 ? details : undefined,
358-}),
353+resolve(
354+buildFindResult({
355+ relativized,
356+ effectiveLimit,
357+limitNotice: `${effectiveLimit} results limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`,
358+}),
359+),
359360);
360361});
361362} catch (e) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。