Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(shared): preserve apostrophes in file references
DavidShen3f861efa1172
diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.tsindex 61d92ee512..cc4da8bed5 100644--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts@@ -95,6 +95,34 @@ describe('portable plugin results', () => {expect(files(source)).toEqual([]);expect(files(JSON.stringify({ text: source }))).toEqual([]);});+ it('keeps adjacent quoted prose references separate while filtering source arrays', () => {+ const first = "xdt-file:///tmp/O'Brien.pdf";+ const second = 'xdt-file:///tmp/second.pdf';+ const list = "'" + first + "','" + second + "'";+ expect(files('Saved ' + list)).toEqual([+ { url: first, title: "O'Brien.pdf" }, { url: second, title: 'second.pdf' },+ ]);+ expect(files('const urls = [' + list + '];')).toEqual([]);+ });+ it.each([+ "xdt-file:///tmp/O'Brien.pdf",+ "xdt-file:///C:/reports/O'Brien.pdf",+ "xdt-file://open?path=/tmp/O'Brien.pdf",+ 'xdt-file://open?path=%2Ftmp%2FO%27Brien.pdf',+ ])('preserves apostrophes inside file names: %s', (url) => {+ const expected = [{ url, title: "O'Brien.pdf" }];+ expect(files('[report](' + url + ')')).toEqual(expected);+ expect(files('Saved ' + url)).toEqual(expected);+ expect(files(JSON.stringify({ note: 'Saved ' + url }))).toEqual(expected);+ expect(files(JSON.stringify([url]))).toEqual(expected);+ for (const quote of ["'", '"', String.fromCharCode(96)]) {+ expect(files('Saved ' + quote + url + quote)).toEqual(expected);+ expect(files('Saved ' + quote + url + quote + ', done')).toEqual(expected);+ }+ const source = 'const urls = ["' + url + '", "xdt-file:///tmp/fixture.pdf"];';+ expect(files(source)).toEqual([]);+ expect(files(JSON.stringify({ text: source }))).toEqual([]);+ });it.each(["'", '"', String.fromCharCode(96)])('keeps prose links quoted with %s without reviving source literals', (quote) => {const url = 'xdt-file:///tmp/report.pdf';const prose = 'Saved ' + quote + url + quote;diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.tsindex 065c881bb6..8e5864d75c 100644--- a/packages/maker-shared/src/payloadSummary.ts+++ b/packages/maker-shared/src/payloadSummary.ts@@ -466,7 +466,7 @@ export function extractPayloadToolCardIds(text: string): string[] {export interface PayloadToolFile { url: string; title: string }-const TOOL_FILE_URL_RE = /xdt-file:\/\/[^\s"'<>\\)`};]+/g;+const TOOL_FILE_URL_RE = /xdt-file:\/\/[^\s"<>\\)`};]+/g;function absoluteToolFilePath(url: string): string | null {try {@@ -523,9 +523,23 @@ export function extractPayloadToolResultFiles(text: string): PayloadToolFile[] {while (pending.length) {const value = pending.pop();if (typeof value === 'string') {- for (const match of value.matchAll(TOOL_FILE_URL_RE)) {- const start = match.index ?? 0;- if (!looksLikeQuotedSourceLiteral(value, start, start + match[0].length)) add(match[0]);+ const urlPattern = new RegExp(TOOL_FILE_URL_RE);+ let previous: { end: number; source: boolean } | undefined;+ for (let match; (match = urlPattern.exec(value));) {+ const start = match.index;+ // An apostrophe is valid inside a file name. Only strip a closing quote+ // when the URL has an opening quote. Keep adjacent quoted references+ // separate, and leave apostrophes within each file name untouched.+ const closingQuote = value[start - 1] === "'"+ ? /'(?=[,.:!?\]]*(?:'xdt-file:\/\/|$))/.exec(match[0])+ : null;+ const url = closingQuote ? match[0].slice(0, closingQuote.index) : match[0];+ urlPattern.lastIndex = start + url.length;+ const source = previous && /^'\s*,\s*'$/.test(value.slice(previous.end, start))+ ? previous.source+ : looksLikeQuotedSourceLiteral(value, start, start + url.length);+ if (!source) add(url);+ previous = { end: start + url.length, source };}} else if (Array.isArray(value)) {for (let i = value.length - 1; i >= 0; i--) pending.push(value[i]);