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): recognize prefixed source string literals

DavidShen8357ab482cce
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 6e097f5480..e9bf81bebe 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"
+ + 'path = r"xdt-file:///tmp/python.pdf"\nvar path = @"Open xdt-file:///tmp/csharp.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);
diff --git a/apps/mobile/src/__tests__/pluginResultRendering.test.ts b/apps/mobile/src/__tests__/pluginResultRendering.test.ts
index ef2ab147e9..a16d9c93cb 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"
+ + 'path = r"xdt-file:///tmp/python.pdf"\nvar path = @"Open xdt-file:///tmp/csharp.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 }]) {
diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.ts
index ff7882461c..d5b619a9ea 100644
--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts
+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts
@@ -4,6 +4,23 @@ import { hasVisibleHistoryResult } from '../historyViewProjection.js';
const blob = (ext: string) => `cindy-media://blobs/${'a'.repeat(64)}.${ext}`;
describe('portable plugin results', () => {
+ it.each(['r', 'R', 'f', 'F', 'b', 'u', 'br', 'rb', 'fr', 'rf', '@', '$', '@$', '$@'])('recognizes source literals with prefix %s', (prefix) => {
+ const url = 'xdt-file:///tmp/prefixed.pdf';
+ for (const quote of (prefix.includes('@') || prefix.includes('$') ? ['"'] : ["'", '"'])) {
+ for (const content of [url, 'Open ' + url]) {
+ const literal = prefix + quote + content + quote;
+ for (const source of ['path = ' + literal, 'return ' + literal, 'open(' + literal + ')', 'paths = [' + literal + ']']) {
+ expect(files(source), source).toEqual([]);
+ expect(files(JSON.stringify({ text: source })), source).toEqual([]);
+ expect(files(source + '\nSaved "' + url + '"')).toEqual([{ url, title: 'prefixed.pdf' }]);
+ expect(files(JSON.stringify({ text: source, _xdt_model_files: [{ url, name: 'Prefixed' }] })))
+ .toEqual([{ url, title: 'Prefixed' }]);
+ }
+ }
+ }
+ // A language prefix alone must not turn ordinary output into source code.
+ expect(files('Saved ' + prefix + '"' + url + '"')).toEqual([{ url, title: 'prefixed.pdf' }]);
+ });
it.each([
'// fixture: xdt-file:///tmp/example.pdf',
'const enabled = true; // fixture: xdt-file:///tmp/example.pdf',
diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.ts
index dc1497a2d9..c5beacd028 100644
--- a/packages/maker-shared/src/payloadSummary.ts
+++ b/packages/maker-shared/src/payloadSummary.ts
@@ -553,7 +553,12 @@ function looksLikeQuotedSourceLiteral(text: string, index: number, end: number):
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 conditional).
- const prefix = text.slice(0, index - 1).trimEnd();
+ const rawPrefix = text.slice(0, index - 1);
+ // Python/C# literal markers sit between the source operator and quote.
+ // Only unwrap a recognized, adjacent marker; still require source syntax
+ // before it, and never strip a suffix from an identifier such as "offer".
+ const marker = before === '`' ? null : /(?:\b(?:br|rb|fr|rf|[rubf])|\$@|@\$|[$@])$/i.exec(rawPrefix);
+ const prefix = (marker ? rawPrefix.slice(0, marker.index) : rawPrefix).trimEnd();
return /(?:[=\[(,?]|=>|&&|\|\||\breturn)$/.test(prefix)
// A colon alone is also a prose label ("File:"). Require a preceding
// conditional, allowing indented continuation lines but not new prose.