9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { EmptyResultError } from '@jackwener/opencli/errors';
|
|
export const readCommand = cli({
|
|
site: 'cursor',
|
|
name: 'read',
|
|
access: 'read',
|
|
description: 'Read the current Cursor chat/composer conversation history',
|
|
domain: 'localhost',
|
|
strategy: Strategy.UI,
|
|
browser: true,
|
|
columns: ['Role', 'Text'],
|
|
func: async (page) => {
|
|
const history = await page.evaluate(`
|
|
(function() {
|
|
const messages = Array.from(document.querySelectorAll('[data-message-role]'));
|
|
|
|
if (messages.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
return messages.map(msg => {
|
|
const role = msg.getAttribute('data-message-role');
|
|
let text = '';
|
|
|
|
// Try to get structured markdown root for AI, or lexical text for human
|
|
const markdownRoot = msg.querySelector('.markdown-root');
|
|
if (markdownRoot) {
|
|
text = markdownRoot.innerText || markdownRoot.textContent;
|
|
} else {
|
|
text = msg.innerText || msg.textContent;
|
|
}
|
|
|
|
return {
|
|
Role: role === 'human' ? 'User' : 'Assistant',
|
|
Text: text.trim()
|
|
};
|
|
});
|
|
})()
|
|
`);
|
|
if (!history || history.length === 0) {
|
|
throw new EmptyResultError('cursor read', 'No conversation history found in Cursor.');
|
|
}
|
|
return history;
|
|
},
|
|
});
|