fix: strip timestamp tags from cursor

This commit is contained in:
Haileyesus
2026-07-03 13:34:02 +03:00
parent 84fe5758fc
commit 9713fff12b
2 changed files with 18 additions and 8 deletions

View File

@@ -141,7 +141,13 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
}
const text = typeof data.message?.content?.[0]?.text === 'string' ? data.message.content[0].text : '';
const firstLine = text.replace(/<\/?user_query>/g, '').trim().split('\n')[0];
// Drop Cursor's `<timestamp>…</timestamp>` prefix and `<user_query>` tags
// so the session name comes from the actual first line the user typed.
const firstLine = text
.replace(/<timestamp>[\s\S]*?<\/timestamp>/g, '')
.replace(/<\/?user_query>/g, '')
.trim()
.split('\n')[0];
return {
sessionId,

View File

@@ -59,17 +59,21 @@ function unwrapUserQueryText(value: string, role: 'user' | 'assistant'): string
return value;
}
const normalized = value.trimStart();
// Cursor wraps user turns as `<timestamp>…</timestamp>\n<user_query>…</user_query>`.
// Show only the `<user_query>` content, trimmed so there are no blank lines
// at the top/bottom and the `<timestamp>` prefix is dropped entirely.
const openTag = '<user_query>';
const closeTag = '</user_query>';
if (!normalized.startsWith(openTag)) {
return value;
const openIndex = value.indexOf(openTag);
if (openIndex >= 0) {
const afterOpen = value.slice(openIndex + openTag.length);
const closeIndex = afterOpen.lastIndexOf(closeTag);
const inner = closeIndex >= 0 ? afterOpen.slice(0, closeIndex) : afterOpen;
return inner.trim();
}
const afterOpen = normalized.slice(openTag.length);
const closeIndex = afterOpen.lastIndexOf(closeTag);
const inner = closeIndex >= 0 ? afterOpen.slice(0, closeIndex) : afterOpen;
return inner.trim();
// No `<user_query>` wrapper: still strip a leading `<timestamp>…</timestamp>`.
return value.replace(/^\s*<timestamp>[\s\S]*?<\/timestamp>\s*/, '').trim();
}
function normalizeToolId(value: unknown): string | null {