Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(shared): preserve quoted and array file references

DavidShen210342830b27
diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.ts
index fd0463833b..f4994452cf 100644
--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts
+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts
@@ -73,6 +73,37 @@ describe('portable plugin results', () => {
text: `const example = '${url}';`,
} }))).toEqual([{ url, title: 'Report' }]);
});
+ it.each([
+ 'xdt-file:///tmp/report[final].pdf',
+ 'xdt-file://open?path=/tmp/report[final].pdf',
+ ])('preserves square brackets in file names: %s', (url) => {
+ expect(files('[报告](' + url + ')')).toEqual([{ url, title: 'report[final].pdf' }]);
+ expect(files(JSON.stringify({ note: 'Saved ' + url }))).toEqual([{ url, title: 'report[final].pdf' }]);
+ });
+ 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;
+ expect(files(prose)).toEqual([{ url, title: 'report.pdf' }]);
+ expect(files('File: ' + quote + url + quote)).toEqual([{ url, title: 'report.pdf' }]);
+ expect(files(JSON.stringify({ note: prose }))).toEqual([{ url, title: 'report.pdf' }]);
+ for (const source of [
+ 'const file = ' + quote + url + quote + ';',
+ 'const urls = [\n ' + quote + url + quote + ',\n];',
+ 'open(' + quote + url + quote + ');',
+ 'const fixture = { url: ' + quote + url + quote + ' };',
+ 'const fixture = { "url": ' + quote + url + quote + ' };',
+ 'return ' + quote + url + quote,
+ ]) expect(files(source)).toEqual([]);
+ });
+ it('decodes top-level JSON arrays before identifying source literals', () => {
+ const a = 'xdt-file:///tmp/a.pdf';
+ const b = 'xdt-file://open?path=%2Ftmp%2Fb.pdf';
+ expect(files(JSON.stringify(a))).toEqual([{ url: a, title: 'a.pdf' }]);
+ expect(files(JSON.stringify([a, { text: b }, [a]]))).toEqual([
+ { url: a, title: 'a.pdf' }, { url: b, title: 'b.pdf' },
+ ]);
+ expect(files(JSON.stringify(['const file = "' + a + '";']))).toEqual([]);
+ });
it.each([
'xdt-file://report.pdf',
'xdt-file://open?path=relative%2Freport.pdf',
diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.ts
index 322af56ccc..fdb3ddc0dc 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 {
@@ -483,10 +483,13 @@ function absoluteToolFilePath(url: string): string | null {
function looksLikeQuotedSourceLiteral(text: string, index: number, end: number): boolean {
const before = text[index - 1];
const after = text[end];
- // Tool output often contains source files and test fixtures. A protocol URL
- // surrounded by a string/template delimiter is source text, not a produced file.
- return before === '`' || before === '\'' || before === '"'
- || after === '`' || after === '\'' || after === '"';
+ if (before !== '`' && before !== '\'' && before !== '"') return false;
+ // Quotes alone also occur in prose and inline Markdown. Require source syntax
+ // around the literal (assignment, collection entry, argument or return).
+ const prefix = text.slice(0, index - 1).trimEnd();
+ return /(?:[=\[(,]|\breturn)$/.test(prefix)
+ || /[{,]\s*(?:[\w$]+|["'][^"']+["'])\s*:$/.test(prefix)
+ || (after === before && /^\s*;/.test(text.slice(end + 1)));
}
/** Existing 3D attachments and managed file references retain a usable file entry on Mobile. */
@@ -508,10 +511,15 @@ export function extractPayloadToolResultFiles(text: string): PayloadToolFile[] {
for (const raw of parsed._xdt_model_files) { const file = readPayloadRecord(raw); add(file?.url, file?.name); }
}
if (Array.isArray(parsed?.xdt_media_produced)) for (const url of parsed.xdt_media_produced) add(url);
- // Scan decoded JSON values, not serialized JSON: its quotes are structural,
- // while quotes inside a value can identify source/test literals. Use a stack
- // so deeply nested tool output cannot overflow the call stack.
- const pending: unknown[] = [parsed ?? text];
+ // Decode arrays and scalar strings as well as the object/envelope above.
+ // JSON delimiters must not be mistaken for source literals. Keep declaration
+ // handling tied to the documented object envelope, as before.
+ let content: unknown = parsed ?? text;
+ if (!parsed) {
+ try { content = JSON.parse(text); } catch { /* Plain-text tool output. */ }
+ }
+ // Use a stack so deeply nested tool output cannot overflow the call stack.
+ const pending: unknown[] = [content];
while (pending.length) {
const value = pending.pop();
if (typeof value === 'string') {