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(mobile): ignore file references inside source comments

DavidShenda9b75053354
diff --git a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts
index f190b06f08..6e097f5480 100644
--- a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts
@@ -32,6 +32,7 @@ describe('mobile tool projection', () => {
+ "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined\n"
+ "const fallback = candidate || 'xdt-file:///tmp/logical.pdf'\n"
+ "const paths = names.map(() => 'Open xdt-file:///tmp/callback.pdf')\n"
+ + '// fixture: xdt-file:///tmp/comment.pdf\n/* example: xdt-file:///tmp/block.pdf */\n'
+ "const list = [/* first */ 'xdt-file:///tmp/a.pdf', // next\n 'xdt-file:///tmp/b.pdf']\n"
+ '// source 中文\n'.repeat(1500);
const row = { ...tool('Read'), role: 'tool_result', content: source };
diff --git a/apps/mobile/src/__tests__/pluginResultRendering.test.ts b/apps/mobile/src/__tests__/pluginResultRendering.test.ts
index afd9698ca2..ef2ab147e9 100644
--- a/apps/mobile/src/__tests__/pluginResultRendering.test.ts
+++ b/apps/mobile/src/__tests__/pluginResultRendering.test.ts
@@ -28,6 +28,7 @@ describe('plugin results are visible outside collapsed tool details', () => {
+ "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined\n"
+ "const fallback = candidate || 'xdt-file:///tmp/logical.pdf'\n"
+ "const paths = names.map(() => 'Open xdt-file:///tmp/callback.pdf')\n"
+ + '// fixture: xdt-file:///tmp/comment.pdf\n/* example: xdt-file:///tmp/block.pdf */\n'
+ "const list = [/* first */ 'xdt-file:///tmp/a.pdf', // next\n 'xdt-file:///tmp/b.pdf']";
for (const content of [source, { text: source }]) {
const rows = messages(content);
diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.ts
index 59b991f85f..ff7882461c 100644
--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts
+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts
@@ -4,6 +4,27 @@ import { hasVisibleHistoryResult } from '../historyViewProjection.js';
const blob = (ext: string) => `cindy-media://blobs/${'a'.repeat(64)}.${ext}`;
describe('portable plugin results', () => {
+ it.each([
+ '// fixture: xdt-file:///tmp/example.pdf',
+ 'const enabled = true; // fixture: xdt-file:///tmp/example.pdf',
+ '/* fixture: xdt-file:///tmp/example.pdf */',
+ '/* example\n * xdt-file:///tmp/example.pdf\n */',
+ '// fixture: "xdt-file:///tmp/example.pdf"',
+ ])('does not extract file deliveries from source comments: %s', (source) => {
+ const url = 'xdt-file:///tmp/actual.pdf';
+ expect(files(source)).toEqual([]);
+ expect(files(JSON.stringify({ text: source }))).toEqual([]);
+ expect(files(source + '\nSaved [report](' + url + ')')).toEqual([{ url, title: 'actual.pdf' }]);
+ expect(files(JSON.stringify({ text: source, _xdt_model_files: [{ url, name: 'Actual' }] })))
+ .toEqual([{ url, title: 'Actual' }]);
+ });
+ it.each(['xdt-file:///tmp/a//report.pdf', 'xdt-file:///tmp/a/*report.pdf'])('does not treat URL path characters as comments: %s', (url) => {
+ const next = 'xdt-file:///tmp/next.pdf';
+ const expected = [{ url, title: url.split('/').pop() }, { url: next, title: 'next.pdf' }];
+ expect(files('Saved ' + url + ' and ' + next)).toEqual(expected);
+ expect(files('[first](' + url + ') [next](' + next + ')')).toEqual(expected);
+ expect(files(JSON.stringify({ text: 'Saved ' + url + ' and ' + next }))).toEqual(expected);
+ });
it.each(["'", '"', String.fromCharCode(96)])('recognizes arrow-function source literals quoted with %s', (quote) => {
const url = 'xdt-file:///tmp/callback.pdf';
for (const content of [url, 'Open ' + url]) {
diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.ts
index 4d9288e4eb..dc1497a2d9 100644
--- a/packages/maker-shared/src/payloadSummary.ts
+++ b/packages/maker-shared/src/payloadSummary.ts
@@ -494,7 +494,17 @@ function* sourceContextTokens(text: string): Generator<{
// Always advance past a token, including unterminated strings/comments.
// An unanchored regex can retry every escaped quote or /* in a long result.
let index = 0;
+ const filePattern = new RegExp(TOOL_FILE_URL_RE.source, 'y');
while (index < text.length) {
+ // Unquoted legacy paths may themselves contain // or /*. Consume the
+ // existing URL alphabet atomically so later deliveries are not commented out.
+ if (text.startsWith('xdt-file://', index)) {
+ filePattern.lastIndex = index;
+ if (filePattern.exec(text)) {
+ index = filePattern.lastIndex;
+ continue;
+ }
+ }
const start = index;
const quote = text[index];
if (quote === '"' || quote === "'" || quote === '`') {
@@ -612,6 +622,8 @@ export function extractPayloadToolResultFiles(text: string): PayloadToolFile[] {
let previous: { end: number; source: boolean } | undefined;
for (let match; (match = urlPattern.exec(value));) {
const start = match.index;
+ // Comment masking preserves offsets; extract URLs only outside it.
+ if (sourceContext[start] !== value[start]) continue;
while (!range.done && range.value.end < start) range = sourceRanges.next();
if (!range.done && range.value.start < start && start < range.value.end) continue;
// Quotes/backticks may be filename characters. Treat one as a delimiter