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(chat): recognize extensionless absolute question references

Liziace2d46e9e6e
diff --git a/packages/maker-shared/src/__tests__/interaction.test.ts b/packages/maker-shared/src/__tests__/interaction.test.ts
index 7884546430..7537289d8e 100644
--- a/packages/maker-shared/src/__tests__/interaction.test.ts
+++ b/packages/maker-shared/src/__tests__/interaction.test.ts
@@ -71,7 +71,24 @@ describe('interaction shared model', () => {
expect(splitQuestionReferences(spacedPath)).toEqual([{ text: spacedPath }]);
expect(splitQuestionReferences('`' + spacedPath + '`')).toEqual([{ text: spacedPath, href: spacedPath }]);
expect(splitQuestionReferences('请查看 /tmp\n然后查看 notes.txt')).toEqual([
- { text: '请查看 /tmp\n然后查看 ' }, { text: 'notes.txt', href: 'notes.txt' },
+ { text: '请查看 ' }, { text: '/tmp', href: '/tmp' },
+ { text: '\n然后查看 ' }, { text: 'notes.txt', href: 'notes.txt' },
+ ]);
+ const windowsHosts = String.raw`C:\Windows\System32\drivers\etc\hosts`;
+ expect(splitQuestionReferences(windowsHosts)).toEqual([{ text: windowsHosts, href: windowsHosts }]);
+ expect(splitQuestionReferences('/etc/hosts 和 /usr/bin/node')).toEqual([
+ { text: '/etc/hosts', href: '/etc/hosts' }, { text: ' 和 ' },
+ { text: '/usr/bin/node', href: '/usr/bin/node' },
+ ]);
+ expect(splitQuestionReferences('/etc/hosts, /usr/bin/node notes.txt')).toEqual([
+ { text: '/etc/hosts', href: '/etc/hosts' }, { text: ', ' },
+ { text: '/usr/bin/node', href: '/usr/bin/node' }, { text: ' ' },
+ { text: 'notes.txt', href: 'notes.txt' },
+ ]);
+ expect(splitQuestionReferences('/etc/hosts 和 `' + windowsHosts + '` 与 [hosts](/etc/hosts)')).toEqual([
+ { text: '/etc/hosts', href: '/etc/hosts' }, { text: ' 和 ' },
+ { text: windowsHosts, href: windowsHosts }, { text: ' 与 ' },
+ { text: 'hosts', href: '/etc/hosts' },
]);
});
it('keeps original questions attached to late answers without including skipped questions', () => {
diff --git a/packages/maker-shared/src/questionReferences.ts b/packages/maker-shared/src/questionReferences.ts
index 9d680b7a03..f45863d5bb 100644
--- a/packages/maker-shared/src/questionReferences.ts
+++ b/packages/maker-shared/src/questionReferences.ts
@@ -17,7 +17,8 @@ function isReference(href: string): boolean {
const withoutLine = href.replace(/:[1-9]\d*(?:-[1-9]\d*)?(?::[1-9]\d*)?$/, '');
if (OTHER_SCHEME.test(withoutLine) && !drivePath && !href.startsWith('file://')) return false;
if (href.startsWith('~/') || (href[0] === '~' && href.charCodeAt(1) === 92)) return false;
- return FILE_REFERENCE.test(href);
+ const absolutePath = withoutLine.startsWith('/') || drivePath || withoutLine.startsWith('file://');
+ return !/[?#\r\n]/.test(href) && (absolutePath || FILE_REFERENCE.test(href));
}
/** Preserve prose and answer keys; recognize labelled links, code and bare files/URLs. */
@@ -61,8 +62,11 @@ export function splitQuestionReferences(text: string): QuestionReferencePart[] {
// trailing fragment into a relative link; code/labelled references can
// preserve the complete spaced path without guessing prose boundaries.
const absoluteFragment = href.startsWith('/') || (/^[A-Za-z]:/.test(href) && (href[2] === '/' || href.charCodeAt(2) === 92));
- unquotedAbsolutePath = (continuesAbsolutePath || absoluteFragment) && !reference;
- append(reference && !continuesAbsolutePath ? { text: href, href } : { text: href });
+ const hasExtension = FILE_REFERENCE.test(href);
+ const spacedAbsolutePrefix = raw === href && absoluteFragment && !hasExtension
+ && /^[ \t]+(?![A-Za-z]:[\\/]|\/|file:\/\/)[^\s]*[\\/]/.test(text.slice(index + raw.length));
+ unquotedAbsolutePath = (continuesAbsolutePath || spacedAbsolutePrefix) && !hasExtension;
+ append(reference && !continuesAbsolutePath && !spacedAbsolutePrefix ? { text: href, href } : { text: href });
append({ text: raw.slice(href.length) });
}
from = index + raw.length;