@jackwener/opencli 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +4 -4
  2. package/README.zh-CN.md +4 -4
  3. package/dist/cli-manifest.json +222 -4
  4. package/dist/clis/antigravity/model.js +2 -2
  5. package/dist/clis/antigravity/send.js +2 -2
  6. package/dist/clis/chatgpt/ask.d.ts +1 -0
  7. package/dist/clis/chatgpt/ask.js +68 -0
  8. package/dist/clis/chatgpt/send.js +11 -0
  9. package/dist/clis/codex/ask.d.ts +1 -0
  10. package/dist/clis/codex/ask.js +67 -0
  11. package/dist/clis/codex/export.d.ts +1 -0
  12. package/dist/clis/codex/export.js +37 -0
  13. package/dist/clis/codex/history.d.ts +1 -0
  14. package/dist/clis/codex/history.js +43 -0
  15. package/dist/clis/codex/read.js +3 -5
  16. package/dist/clis/codex/screenshot.d.ts +1 -0
  17. package/dist/clis/codex/screenshot.js +27 -0
  18. package/dist/clis/codex/send.js +3 -6
  19. package/dist/clis/codex/status.js +2 -1
  20. package/dist/clis/cursor/ask.d.ts +1 -0
  21. package/dist/clis/cursor/ask.js +69 -0
  22. package/dist/clis/cursor/composer.js +9 -28
  23. package/dist/clis/cursor/export.d.ts +1 -0
  24. package/dist/clis/cursor/export.js +51 -0
  25. package/dist/clis/cursor/history.d.ts +1 -0
  26. package/dist/clis/cursor/history.js +43 -0
  27. package/dist/clis/cursor/new.js +4 -13
  28. package/dist/clis/cursor/screenshot.d.ts +1 -0
  29. package/dist/clis/cursor/screenshot.js +31 -0
  30. package/package.json +1 -1
  31. package/src/clis/antigravity/README.md +2 -3
  32. package/src/clis/antigravity/README.zh-CN.md +2 -3
  33. package/src/clis/antigravity/SKILL.md +1 -1
  34. package/src/clis/antigravity/model.ts +2 -2
  35. package/src/clis/antigravity/send.ts +2 -2
  36. package/src/clis/chatgpt/README.md +25 -16
  37. package/src/clis/chatgpt/README.zh-CN.md +27 -18
  38. package/src/clis/chatgpt/ask.ts +77 -0
  39. package/src/clis/chatgpt/send.ts +12 -0
  40. package/src/clis/codex/ask.ts +77 -0
  41. package/src/clis/codex/export.ts +42 -0
  42. package/src/clis/codex/extract-diff.ts +1 -0
  43. package/src/clis/codex/history.ts +47 -0
  44. package/src/clis/codex/read.ts +5 -6
  45. package/src/clis/codex/screenshot.ts +33 -0
  46. package/src/clis/codex/send.ts +6 -7
  47. package/src/clis/codex/status.ts +4 -2
  48. package/src/clis/cursor/ask.ts +81 -0
  49. package/src/clis/cursor/composer.ts +9 -30
  50. package/src/clis/cursor/export.ts +57 -0
  51. package/src/clis/cursor/history.ts +47 -0
  52. package/src/clis/cursor/new.ts +4 -15
  53. package/src/clis/cursor/screenshot.ts +38 -0
@@ -14,6 +14,13 @@ export const sendCommand = cli({
14
14
  func: async (page: IPage | null, kwargs: any) => {
15
15
  const text = kwargs.text as string;
16
16
  try {
17
+ // Backup current clipboard content
18
+ let clipBackup = '';
19
+ try {
20
+ clipBackup = execSync('pbpaste', { encoding: 'utf-8' });
21
+ } catch { /* clipboard may be empty */ }
22
+
23
+ // Copy text to clipboard
17
24
  spawnSync('pbcopy', { input: text });
18
25
 
19
26
  execSync("osascript -e 'tell application \"ChatGPT\" to activate'");
@@ -28,6 +35,11 @@ export const sendCommand = cli({
28
35
 
29
36
  execSync(cmd);
30
37
 
38
+ // Restore original clipboard content
39
+ if (clipBackup) {
40
+ spawnSync('pbcopy', { input: clipBackup });
41
+ }
42
+
31
43
  return [{ Status: 'Success' }];
32
44
  } catch (err: any) {
33
45
  return [{ Status: "Error: " + err.message }];
@@ -0,0 +1,77 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
3
+
4
+ export const askCommand = cli({
5
+ site: 'codex',
6
+ name: 'ask',
7
+ description: 'Send a prompt and wait for the AI response (send + wait + read)',
8
+ domain: 'localhost',
9
+ strategy: Strategy.UI,
10
+ browser: true,
11
+ args: [
12
+ { name: 'text', required: true, positional: true, help: 'Prompt to send' },
13
+ { name: 'timeout', required: false, help: 'Max seconds to wait for response (default: 60)', default: '60' },
14
+ ],
15
+ columns: ['Role', 'Text'],
16
+ func: async (page: IPage, kwargs: any) => {
17
+ const text = kwargs.text as string;
18
+ const timeout = parseInt(kwargs.timeout as string, 10) || 60;
19
+
20
+ // Snapshot the current content length before sending
21
+ const beforeLen = await page.evaluate(`
22
+ (function() {
23
+ const turns = document.querySelectorAll('[data-content-search-turn-key]');
24
+ return turns.length;
25
+ })()
26
+ `);
27
+
28
+ // Inject and send
29
+ await page.evaluate(`
30
+ (function(text) {
31
+ const editables = Array.from(document.querySelectorAll('[contenteditable="true"]'));
32
+ const composer = editables.length > 0 ? editables[editables.length - 1] : document.querySelector('textarea');
33
+ if (!composer) throw new Error('Could not find Codex input');
34
+ composer.focus();
35
+ document.execCommand('insertText', false, text);
36
+ })(${JSON.stringify(text)})
37
+ `);
38
+ await page.wait(0.5);
39
+ await page.pressKey('Enter');
40
+
41
+ // Poll for new content
42
+ const pollInterval = 3;
43
+ const maxPolls = Math.ceil(timeout / pollInterval);
44
+ let response = '';
45
+
46
+ for (let i = 0; i < maxPolls; i++) {
47
+ await page.wait(pollInterval);
48
+
49
+ const result = await page.evaluate(`
50
+ (function(prevLen) {
51
+ const turns = document.querySelectorAll('[data-content-search-turn-key]');
52
+ if (turns.length <= prevLen) return null;
53
+ const lastTurn = turns[turns.length - 1];
54
+ const text = lastTurn.innerText || lastTurn.textContent;
55
+ return text ? text.trim() : null;
56
+ })(${beforeLen})
57
+ `);
58
+
59
+ if (result) {
60
+ response = result;
61
+ break;
62
+ }
63
+ }
64
+
65
+ if (!response) {
66
+ return [
67
+ { Role: 'User', Text: text },
68
+ { Role: 'System', Text: `No response within ${timeout}s. The agent may still be working.` },
69
+ ];
70
+ }
71
+
72
+ return [
73
+ { Role: 'User', Text: text },
74
+ { Role: 'Assistant', Text: response },
75
+ ];
76
+ },
77
+ });
@@ -0,0 +1,42 @@
1
+ import * as fs from 'node:fs';
2
+ import { cli, Strategy } from '../../registry.js';
3
+ import type { IPage } from '../../types.js';
4
+
5
+ export const exportCommand = cli({
6
+ site: 'codex',
7
+ name: 'export',
8
+ description: 'Export the current Codex conversation to a Markdown file',
9
+ domain: 'localhost',
10
+ strategy: Strategy.UI,
11
+ browser: true,
12
+ args: [
13
+ { name: 'output', required: false, positional: true, help: 'Output file (default: /tmp/codex-export.md)' },
14
+ ],
15
+ columns: ['Status', 'File', 'Messages'],
16
+ func: async (page: IPage, kwargs: any) => {
17
+ const outputPath = (kwargs.output as string) || '/tmp/codex-export.md';
18
+
19
+ const md = await page.evaluate(`
20
+ (function() {
21
+ const turns = document.querySelectorAll('[data-content-search-turn-key]');
22
+ if (turns.length > 0) {
23
+ return Array.from(turns).map((t, i) => '## Turn ' + (i + 1) + '\\n\\n' + (t.innerText || t.textContent).trim()).join('\\n\\n---\\n\\n');
24
+ }
25
+
26
+ const main = document.querySelector('main, [role="main"], [role="log"]');
27
+ if (main) return main.innerText || main.textContent;
28
+ return document.body.innerText;
29
+ })()
30
+ `);
31
+
32
+ fs.writeFileSync(outputPath, '# Codex Conversation Export\\n\\n' + md);
33
+
34
+ return [
35
+ {
36
+ Status: 'Success',
37
+ File: outputPath,
38
+ Messages: md.split('## Turn').length - 1,
39
+ },
40
+ ];
41
+ },
42
+ });
@@ -1,4 +1,5 @@
1
1
  import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
2
3
 
3
4
  export const extractDiffCommand = cli({
4
5
  site: 'codex',
@@ -0,0 +1,47 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
3
+
4
+ export const historyCommand = cli({
5
+ site: 'codex',
6
+ name: 'history',
7
+ description: 'List recent conversation threads in Codex',
8
+ domain: 'localhost',
9
+ strategy: Strategy.UI,
10
+ browser: true,
11
+ args: [],
12
+ columns: ['Index', 'Title'],
13
+ func: async (page: IPage) => {
14
+ const items = await page.evaluate(`
15
+ (function() {
16
+ const results = [];
17
+ // Codex thread list items
18
+ const entries = document.querySelectorAll('[data-testid*="thread"], [class*="thread-list"] a, [role="listbox"] [role="option"]');
19
+
20
+ entries.forEach((item, i) => {
21
+ const title = (item.textContent || item.innerText || '').trim().substring(0, 100);
22
+ if (title) results.push({ Index: i + 1, Title: title });
23
+ });
24
+
25
+ // Fallback: sidebar/nav links
26
+ if (results.length === 0) {
27
+ const nav = document.querySelector('nav, [role="navigation"], aside');
28
+ if (nav) {
29
+ const links = nav.querySelectorAll('a, button');
30
+ links.forEach((link, i) => {
31
+ const text = (link.textContent || '').trim().substring(0, 100);
32
+ if (text && text.length > 3) results.push({ Index: i + 1, Title: text });
33
+ });
34
+ }
35
+ }
36
+
37
+ return results;
38
+ })()
39
+ `);
40
+
41
+ if (items.length === 0) {
42
+ return [{ Index: 0, Title: 'No threads found. Try opening the thread list first.' }];
43
+ }
44
+
45
+ return items;
46
+ },
47
+ });
@@ -1,4 +1,5 @@
1
1
  import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
2
3
 
3
4
  export const readCommand = cli({
4
5
  site: 'codex',
@@ -7,31 +8,29 @@ export const readCommand = cli({
7
8
  domain: 'localhost',
8
9
  strategy: Strategy.UI,
9
10
  browser: true,
10
- columns: ['Thread_Content'],
11
- func: async (page) => {
11
+ args: [],
12
+ columns: ['Content'],
13
+ func: async (page: IPage) => {
12
14
  const historyText = await page.evaluate(`
13
15
  (function() {
14
- // Precise Codex selector for chat messages
15
16
  const turns = Array.from(document.querySelectorAll('[data-content-search-turn-key]'));
16
17
  if (turns.length > 0) {
17
18
  return turns.map(t => t.innerText || t.textContent).join('\\n\\n---\\n\\n');
18
19
  }
19
20
 
20
- // Fallback robust scraping heuristic for chat history panes
21
21
  const threadContainer = document.querySelector('[role="log"], [data-testid="conversation"], .thread-container, .messages-list, main');
22
22
 
23
23
  if (threadContainer) {
24
24
  return threadContainer.innerText || threadContainer.textContent;
25
25
  }
26
26
 
27
- // If specific containers fail, just dump the whole body's readable text minus the navigation
28
27
  return document.body.innerText;
29
28
  })()
30
29
  `);
31
30
 
32
31
  return [
33
32
  {
34
- Thread_Content: historyText,
33
+ Content: historyText,
35
34
  },
36
35
  ];
37
36
  },
@@ -0,0 +1,33 @@
1
+ import * as fs from 'node:fs';
2
+ import { cli, Strategy } from '../../registry.js';
3
+ import type { IPage } from '../../types.js';
4
+
5
+ export const screenshotCommand = cli({
6
+ site: 'codex',
7
+ name: 'screenshot',
8
+ description: 'Capture a snapshot of the current Codex window (DOM + Accessibility tree)',
9
+ domain: 'localhost',
10
+ strategy: Strategy.UI,
11
+ browser: true,
12
+ args: [
13
+ { name: 'output', required: false, positional: true, help: 'Output file path (default: /tmp/codex-snapshot.txt)' },
14
+ ],
15
+ columns: ['Status', 'File'],
16
+ func: async (page: IPage, kwargs: any) => {
17
+ const outputPath = (kwargs.output as string) || '/tmp/codex-snapshot.txt';
18
+
19
+ const snap = await page.snapshot({ compact: true });
20
+ const html = await page.evaluate('document.documentElement.outerHTML');
21
+
22
+ const htmlPath = outputPath.replace(/\.\w+$/, '') + '-dom.html';
23
+ const snapPath = outputPath.replace(/\.\w+$/, '') + '-a11y.txt';
24
+
25
+ fs.writeFileSync(htmlPath, html);
26
+ fs.writeFileSync(snapPath, typeof snap === 'string' ? snap : JSON.stringify(snap, null, 2));
27
+
28
+ return [
29
+ { Status: 'Success', File: htmlPath },
30
+ { Status: 'Success', File: snapPath },
31
+ ];
32
+ },
33
+ });
@@ -1,4 +1,5 @@
1
1
  import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
2
3
 
3
4
  export const sendCommand = cli({
4
5
  site: 'codex',
@@ -9,19 +10,16 @@ export const sendCommand = cli({
9
10
  browser: true,
10
11
  args: [{ name: 'text', required: true, positional: true, help: 'Text, command (e.g. /review), or skill (e.g. $imagegen)' }],
11
12
  columns: ['Status', 'InjectedText'],
12
- func: async (page, kwargs) => {
13
+ func: async (page: IPage, kwargs: any) => {
13
14
  const textToInsert = kwargs.text as string;
14
15
 
15
- // We use evaluate to inject text bypassing complex nested shadow roots or contenteditables
16
16
  await page.evaluate(`
17
17
  (function(text) {
18
- // Attempt 1: Look for standard textarea/composer input
19
18
  let composer = document.querySelector('textarea, [contenteditable="true"]');
20
19
 
21
- // Basic heuristic: prioritize elements that are deeply nested, visible, and have 'composer' or 'input' classes
22
20
  const editables = Array.from(document.querySelectorAll('[contenteditable="true"]'));
23
21
  if (editables.length > 0) {
24
- composer = editables[editables.length - 1]; // Often the active input is appended near the end
22
+ composer = editables[editables.length - 1];
25
23
  }
26
24
 
27
25
  if (!composer) {
@@ -29,12 +27,13 @@ export const sendCommand = cli({
29
27
  }
30
28
 
31
29
  composer.focus();
32
-
33
- // This handles Lexical/ProseMirror/Monaco rich-text editors effectively by mimicking human paste/type deeply.
34
30
  document.execCommand('insertText', false, text);
35
31
  })(${JSON.stringify(textToInsert)})
36
32
  `);
37
33
 
34
+ // Wait for the UI to register the input
35
+ await page.wait(0.5);
36
+
38
37
  // Simulate Enter key to submit
39
38
  await page.pressKey('Enter');
40
39
 
@@ -1,14 +1,16 @@
1
1
  import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
2
3
 
3
4
  export const statusCommand = cli({
4
5
  site: 'codex',
5
6
  name: 'status',
6
7
  description: 'Check active CDP connection to OpenAI Codex App',
7
8
  domain: 'localhost',
8
- strategy: Strategy.UI, // Interactive UI manipulation
9
+ strategy: Strategy.UI,
9
10
  browser: true,
11
+ args: [],
10
12
  columns: ['Status', 'Url', 'Title'],
11
- func: async (page) => {
13
+ func: async (page: IPage) => {
12
14
  const url = await page.evaluate('window.location.href');
13
15
  const title = await page.evaluate('document.title');
14
16
 
@@ -0,0 +1,81 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
3
+
4
+ export const askCommand = cli({
5
+ site: 'cursor',
6
+ name: 'ask',
7
+ description: 'Send a prompt and wait for the AI response (send + wait + read)',
8
+ domain: 'localhost',
9
+ strategy: Strategy.UI,
10
+ browser: true,
11
+ args: [
12
+ { name: 'text', required: true, positional: true, help: 'Prompt to send' },
13
+ { name: 'timeout', required: false, help: 'Max seconds to wait for response (default: 30)', default: '30' },
14
+ ],
15
+ columns: ['Role', 'Text'],
16
+ func: async (page: IPage, kwargs: any) => {
17
+ const text = kwargs.text as string;
18
+ const timeout = parseInt(kwargs.timeout as string, 10) || 30;
19
+
20
+ // Count existing messages before sending
21
+ const beforeCount = await page.evaluate(`
22
+ document.querySelectorAll('[data-message-role]').length
23
+ `);
24
+
25
+ // Inject text into the active editor and submit
26
+ const injected = await page.evaluate(
27
+ `(function(text) {
28
+ let editor = document.querySelector('.aislash-editor-input, [data-lexical-editor="true"], [contenteditable="true"]');
29
+ if (!editor) return false;
30
+ editor.focus();
31
+ document.execCommand('insertText', false, text);
32
+ return true;
33
+ })(${JSON.stringify(text)})`
34
+ );
35
+
36
+ if (!injected) throw new Error('Could not find input element.');
37
+ await page.wait(0.5);
38
+ await page.pressKey('Enter');
39
+
40
+ // Poll until a new assistant message appears or timeout
41
+ const pollInterval = 2; // seconds
42
+ const maxPolls = Math.ceil(timeout / pollInterval);
43
+ let response = '';
44
+
45
+ for (let i = 0; i < maxPolls; i++) {
46
+ await page.wait(pollInterval);
47
+
48
+ const result = await page.evaluate(`
49
+ (function(prevCount) {
50
+ const msgs = document.querySelectorAll('[data-message-role]');
51
+ if (msgs.length <= prevCount) return null;
52
+
53
+ const lastMsg = msgs[msgs.length - 1];
54
+ const role = lastMsg.getAttribute('data-message-role');
55
+ if (role === 'human') return null; // Still waiting for assistant
56
+
57
+ const root = lastMsg.querySelector('.markdown-root');
58
+ const text = root ? root.innerText : lastMsg.innerText;
59
+ return text ? text.trim() : null;
60
+ })(${beforeCount})
61
+ `);
62
+
63
+ if (result) {
64
+ response = result;
65
+ break;
66
+ }
67
+ }
68
+
69
+ if (!response) {
70
+ return [
71
+ { Role: 'User', Text: text },
72
+ { Role: 'System', Text: `No response received within ${timeout}s. The AI may still be generating.` },
73
+ ];
74
+ }
75
+
76
+ return [
77
+ { Role: 'User', Text: text },
78
+ { Role: 'Assistant', Text: response },
79
+ ];
80
+ },
81
+ });
@@ -13,37 +13,18 @@ export const composerCommand = cli({
13
13
  func: async (page: IPage, kwargs: any) => {
14
14
  const textToInsert = kwargs.text as string;
15
15
 
16
- const injected = await page.evaluate(
17
- `(async function() {
18
- let isComposerVisible = document.querySelector('.composer-bar') !== null || document.querySelector('#composer-toolbar-section') !== null;
19
- return isComposerVisible;
20
- })()`
21
- );
22
-
23
- if (!injected) {
24
- await page.pressKey('Meta+I');
25
- await page.wait(1.0);
26
- } else {
27
- // Just focus it if it's open but unfocused (we can't easily know if it's focused without triggering something)
28
- await page.pressKey('Meta+I');
29
- await page.wait(0.2);
30
- const isStillVisible = await page.evaluate('document.querySelector(".composer-bar") !== null');
31
- if (!isStillVisible) {
32
- await page.pressKey('Meta+I'); // Re-open
33
- await page.wait(0.5);
34
- }
35
- }
16
+ // Open/Focus Composer via shortcut — always works regardless of current state
17
+ await page.pressKey('Meta+I');
18
+ await page.wait(1);
36
19
 
37
20
  const typed = await page.evaluate(
38
21
  `(function(text) {
39
- let composer = document.querySelector('.composer-bar [data-lexical-editor="true"], [id*="composer"] [contenteditable="true"], .aislash-editor-input');
40
-
41
- if (!composer) {
42
- composer = document.activeElement;
43
- if (!composer || !composer.isContentEditable) {
44
- return false;
45
- }
22
+ let composer = document.activeElement;
23
+ if (!composer || !composer.isContentEditable) {
24
+ composer = document.querySelector('.composer-bar [data-lexical-editor="true"], [id*="composer"] [contenteditable="true"], .aislash-editor-input');
46
25
  }
26
+
27
+ if (!composer) return false;
47
28
 
48
29
  composer.focus();
49
30
  document.execCommand('insertText', false, text);
@@ -55,15 +36,13 @@ export const composerCommand = cli({
55
36
  throw new Error('Could not find Cursor Composer input element after pressing Cmd+I.');
56
37
  }
57
38
 
58
- // Submit the command. In Cursor Composer, Enter usually submits if it's not a multi-line edit.
59
- // Sometimes Cmd+Enter is needed? We'll just submit standard Enter.
60
39
  await page.wait(0.5);
61
40
  await page.pressKey('Enter');
62
41
  await page.wait(1);
63
42
 
64
43
  return [
65
44
  {
66
- Status: 'Success (Composer)',
45
+ Status: 'Success',
67
46
  InjectedText: textToInsert,
68
47
  },
69
48
  ];
@@ -0,0 +1,57 @@
1
+ import * as fs from 'node:fs';
2
+ import { cli, Strategy } from '../../registry.js';
3
+ import type { IPage } from '../../types.js';
4
+
5
+ function makeExportCommand(site: string, readSelector: string) {
6
+ return cli({
7
+ site,
8
+ name: 'export',
9
+ description: `Export the current ${site} conversation to a Markdown file`,
10
+ domain: 'localhost',
11
+ strategy: Strategy.UI,
12
+ browser: true,
13
+ args: [
14
+ { name: 'output', required: false, positional: true, help: `Output file (default: /tmp/${site}-export.md)` },
15
+ ],
16
+ columns: ['Status', 'File', 'Messages'],
17
+ func: async (page: IPage, kwargs: any) => {
18
+ const outputPath = (kwargs.output as string) || `/tmp/${site}-export.md`;
19
+
20
+ const md = await page.evaluate(`
21
+ (function() {
22
+ const selectors = ${JSON.stringify(readSelector)}.split(',');
23
+ let messages = [];
24
+
25
+ for (const sel of selectors) {
26
+ const nodes = document.querySelectorAll(sel.trim());
27
+ if (nodes.length > 0) {
28
+ messages = Array.from(nodes).map(n => n.innerText || n.textContent);
29
+ break;
30
+ }
31
+ }
32
+
33
+ if (messages.length === 0) {
34
+ const main = document.querySelector('main, [role="main"], .messages-list, [role="log"]');
35
+ if (main) messages = [main.innerText || main.textContent];
36
+ }
37
+
38
+ if (messages.length === 0) messages = [document.body.innerText];
39
+
40
+ return messages.map((m, i) => '## Message ' + (i + 1) + '\\n\\n' + m.trim()).join('\\n\\n---\\n\\n');
41
+ })()
42
+ `);
43
+
44
+ fs.writeFileSync(outputPath, `# ${site} Conversation Export\\n\\n` + md);
45
+
46
+ return [
47
+ {
48
+ Status: 'Success',
49
+ File: outputPath,
50
+ Messages: md.split('## Message').length - 1,
51
+ },
52
+ ];
53
+ },
54
+ });
55
+ }
56
+
57
+ export const cursorExport = makeExportCommand('cursor', '[data-message-role]');
@@ -0,0 +1,47 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import type { IPage } from '../../types.js';
3
+
4
+ export const historyCommand = cli({
5
+ site: 'cursor',
6
+ name: 'history',
7
+ description: 'List recent chat sessions from the Cursor sidebar',
8
+ domain: 'localhost',
9
+ strategy: Strategy.UI,
10
+ browser: true,
11
+ args: [],
12
+ columns: ['Index', 'Title'],
13
+ func: async (page: IPage) => {
14
+ const items = await page.evaluate(`
15
+ (function() {
16
+ const results = [];
17
+ // Cursor chat history lives in sidebar items
18
+ const entries = document.querySelectorAll('.agent-sidebar-list-item, [data-testid="chat-history-item"], .chat-history-item, .tree-item');
19
+
20
+ entries.forEach((item, i) => {
21
+ const title = (item.textContent || item.innerText || '').trim().substring(0, 100);
22
+ if (title) results.push({ Index: i + 1, Title: title });
23
+ });
24
+
25
+ // Fallback: try to find sidebar text items
26
+ if (results.length === 0) {
27
+ const sidebar = document.querySelector('.sidebar, [class*="sidebar"], .agent-sidebar, .side-bar-container');
28
+ if (sidebar) {
29
+ const links = sidebar.querySelectorAll('a, [role="treeitem"], [role="option"]');
30
+ links.forEach((link, i) => {
31
+ const text = (link.textContent || '').trim().substring(0, 100);
32
+ if (text) results.push({ Index: i + 1, Title: text });
33
+ });
34
+ }
35
+ }
36
+
37
+ return results;
38
+ })()
39
+ `);
40
+
41
+ if (items.length === 0) {
42
+ return [{ Index: 0, Title: 'No chat history found. Open the AI sidebar first.' }];
43
+ }
44
+
45
+ return items;
46
+ },
47
+ });
@@ -8,23 +8,12 @@ export const newCommand = cli({
8
8
  domain: 'localhost',
9
9
  strategy: Strategy.UI,
10
10
  browser: true,
11
+ args: [],
11
12
  columns: ['Status'],
12
13
  func: async (page: IPage) => {
13
- const success = await page.evaluate(`
14
- (function() {
15
- const newChatButton = document.querySelector('[aria-label="New Chat"], [aria-label="New Chat (⌘N)"], .agent-sidebar-new-agent-button');
16
- if (newChatButton) {
17
- newChatButton.click();
18
- return true;
19
- }
20
- return false;
21
- })()
22
- `);
23
-
24
- if (!success) {
25
- throw new Error('Could not find New Chat button in Cursor DOM.');
26
- }
27
-
14
+ // Use keyboard shortcut — most robust approach, avoids brittle DOM selectors
15
+ const isMac = process.platform === 'darwin';
16
+ await page.pressKey(isMac ? 'Meta+N' : 'Control+N');
28
17
  await page.wait(1);
29
18
 
30
19
  return [{ Status: 'Success' }];
@@ -0,0 +1,38 @@
1
+ import * as fs from 'node:fs';
2
+ import { cli, Strategy } from '../../registry.js';
3
+ import type { IPage } from '../../types.js';
4
+
5
+ function makeScreenshotCommand(site: string) {
6
+ return cli({
7
+ site,
8
+ name: 'screenshot',
9
+ description: `Capture a snapshot of the current ${site} window (DOM + Accessibility tree)`,
10
+ domain: 'localhost',
11
+ strategy: Strategy.UI,
12
+ browser: true,
13
+ args: [
14
+ { name: 'output', required: false, positional: true, help: `Output file path (default: /tmp/${site}-snapshot.txt)` },
15
+ ],
16
+ columns: ['Status', 'File'],
17
+ func: async (page: IPage, kwargs: any) => {
18
+ const outputPath = (kwargs.output as string) || `/tmp/${site}-snapshot.txt`;
19
+
20
+ // Get both the accessibility snapshot and the raw DOM HTML
21
+ const snap = await page.snapshot({ compact: true });
22
+ const html = await page.evaluate('document.documentElement.outerHTML');
23
+
24
+ const htmlPath = outputPath.replace(/\.\w+$/, '') + '-dom.html';
25
+ const snapPath = outputPath.replace(/\.\w+$/, '') + '-a11y.txt';
26
+
27
+ fs.writeFileSync(htmlPath, html);
28
+ fs.writeFileSync(snapPath, typeof snap === 'string' ? snap : JSON.stringify(snap, null, 2));
29
+
30
+ return [
31
+ { Status: 'Success', File: htmlPath },
32
+ { Status: 'Success', File: snapPath },
33
+ ];
34
+ },
35
+ });
36
+ }
37
+
38
+ export const screenshotCursor = makeScreenshotCommand('cursor');