@jackwener/opencli 0.9.6 → 1.0.0

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 (307) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +83 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +42 -0
  4. package/.github/ISSUE_TEMPLATE/new_site_adapter.yml +57 -0
  5. package/.github/dependabot.yml +27 -0
  6. package/.github/pull_request_template.md +24 -0
  7. package/.github/workflows/ci.yml +14 -8
  8. package/.github/workflows/e2e-headed.yml +6 -2
  9. package/.github/workflows/pkg-pr-new.yml +2 -2
  10. package/.github/workflows/release-please.yml +25 -0
  11. package/.github/workflows/release.yml +2 -2
  12. package/.github/workflows/security.yml +36 -0
  13. package/CDP.md +1 -1
  14. package/CDP.zh-CN.md +1 -1
  15. package/CLI-ELECTRON.md +89 -36
  16. package/CLI-EXPLORER.md +4 -4
  17. package/CONTRIBUTING.md +167 -0
  18. package/README.md +113 -89
  19. package/README.zh-CN.md +114 -91
  20. package/SKILL.md +10 -8
  21. package/TESTING.md +7 -7
  22. package/dist/browser/daemon-client.d.ts +37 -0
  23. package/dist/browser/daemon-client.js +82 -0
  24. package/dist/browser/discover.d.ts +11 -34
  25. package/dist/browser/discover.js +15 -190
  26. package/dist/browser/errors.d.ts +6 -20
  27. package/dist/browser/errors.js +24 -63
  28. package/dist/browser/index.d.ts +2 -11
  29. package/dist/browser/index.js +5 -11
  30. package/dist/browser/mcp.d.ts +9 -18
  31. package/dist/browser/mcp.js +70 -284
  32. package/dist/browser/page.d.ts +28 -6
  33. package/dist/browser/page.js +210 -85
  34. package/dist/browser.test.js +4 -202
  35. package/dist/build-manifest.d.ts +26 -0
  36. package/dist/build-manifest.js +132 -60
  37. package/dist/build-manifest.test.d.ts +1 -0
  38. package/dist/build-manifest.test.js +26 -0
  39. package/dist/cli-manifest.json +1582 -29
  40. package/dist/clis/bilibili/download.d.ts +10 -0
  41. package/dist/clis/bilibili/download.js +135 -0
  42. package/dist/clis/chatwise/ask.d.ts +1 -0
  43. package/dist/clis/chatwise/ask.js +76 -0
  44. package/dist/clis/chatwise/export.d.ts +1 -0
  45. package/dist/clis/chatwise/export.js +46 -0
  46. package/dist/clis/chatwise/history.d.ts +1 -0
  47. package/dist/clis/chatwise/history.js +43 -0
  48. package/dist/clis/chatwise/model.d.ts +1 -0
  49. package/dist/clis/chatwise/model.js +81 -0
  50. package/dist/clis/chatwise/new.d.ts +1 -0
  51. package/dist/clis/chatwise/new.js +18 -0
  52. package/dist/clis/chatwise/read.d.ts +1 -0
  53. package/dist/clis/chatwise/read.js +39 -0
  54. package/dist/clis/chatwise/screenshot.d.ts +1 -0
  55. package/dist/clis/chatwise/screenshot.js +27 -0
  56. package/dist/clis/chatwise/send.d.ts +1 -0
  57. package/dist/clis/chatwise/send.js +45 -0
  58. package/dist/clis/chatwise/status.d.ts +1 -0
  59. package/dist/clis/chatwise/status.js +22 -0
  60. package/dist/clis/discord-app/channels.d.ts +1 -0
  61. package/dist/clis/discord-app/channels.js +45 -0
  62. package/dist/clis/discord-app/members.d.ts +1 -0
  63. package/dist/clis/discord-app/members.js +38 -0
  64. package/dist/clis/discord-app/read.d.ts +1 -0
  65. package/dist/clis/discord-app/read.js +45 -0
  66. package/dist/clis/discord-app/search.d.ts +1 -0
  67. package/dist/clis/discord-app/search.js +56 -0
  68. package/dist/clis/discord-app/send.d.ts +1 -0
  69. package/dist/clis/discord-app/send.js +27 -0
  70. package/dist/clis/discord-app/servers.d.ts +1 -0
  71. package/dist/clis/discord-app/servers.js +36 -0
  72. package/dist/clis/discord-app/status.d.ts +1 -0
  73. package/dist/clis/discord-app/status.js +16 -0
  74. package/dist/clis/feishu/new.d.ts +1 -0
  75. package/dist/clis/feishu/new.js +27 -0
  76. package/dist/clis/feishu/read.d.ts +1 -0
  77. package/dist/clis/feishu/read.js +40 -0
  78. package/dist/clis/feishu/search.d.ts +1 -0
  79. package/dist/clis/feishu/search.js +30 -0
  80. package/dist/clis/feishu/send.d.ts +1 -0
  81. package/dist/clis/feishu/send.js +39 -0
  82. package/dist/clis/feishu/status.d.ts +1 -0
  83. package/dist/clis/feishu/status.js +28 -0
  84. package/dist/clis/grok/ask.d.ts +1 -0
  85. package/dist/clis/grok/ask.js +82 -0
  86. package/dist/clis/grok/debug.d.ts +1 -0
  87. package/dist/clis/grok/debug.js +45 -0
  88. package/dist/clis/jimeng/generate.yaml +84 -0
  89. package/dist/clis/jimeng/history.yaml +47 -0
  90. package/dist/clis/linux-do/categories.yaml +41 -0
  91. package/dist/clis/linux-do/category.yaml +49 -0
  92. package/dist/clis/linux-do/hot.yaml +50 -0
  93. package/dist/clis/linux-do/latest.yaml +40 -0
  94. package/dist/clis/linux-do/search.yaml +45 -0
  95. package/dist/clis/linux-do/topic.yaml +38 -0
  96. package/dist/clis/neteasemusic/like.d.ts +1 -0
  97. package/dist/clis/neteasemusic/like.js +25 -0
  98. package/dist/clis/neteasemusic/lyrics.d.ts +1 -0
  99. package/dist/clis/neteasemusic/lyrics.js +47 -0
  100. package/dist/clis/neteasemusic/next.d.ts +1 -0
  101. package/dist/clis/neteasemusic/next.js +26 -0
  102. package/dist/clis/neteasemusic/play.d.ts +1 -0
  103. package/dist/clis/neteasemusic/play.js +26 -0
  104. package/dist/clis/neteasemusic/playing.d.ts +1 -0
  105. package/dist/clis/neteasemusic/playing.js +59 -0
  106. package/dist/clis/neteasemusic/playlist.d.ts +1 -0
  107. package/dist/clis/neteasemusic/playlist.js +46 -0
  108. package/dist/clis/neteasemusic/prev.d.ts +1 -0
  109. package/dist/clis/neteasemusic/prev.js +25 -0
  110. package/dist/clis/neteasemusic/search.d.ts +1 -0
  111. package/dist/clis/neteasemusic/search.js +52 -0
  112. package/dist/clis/neteasemusic/status.d.ts +1 -0
  113. package/dist/clis/neteasemusic/status.js +16 -0
  114. package/dist/clis/neteasemusic/volume.d.ts +1 -0
  115. package/dist/clis/neteasemusic/volume.js +54 -0
  116. package/dist/clis/notion/export.d.ts +1 -0
  117. package/dist/clis/notion/export.js +31 -0
  118. package/dist/clis/notion/favorites.d.ts +1 -0
  119. package/dist/clis/notion/favorites.js +84 -0
  120. package/dist/clis/notion/new.d.ts +1 -0
  121. package/dist/clis/notion/new.js +34 -0
  122. package/dist/clis/notion/read.d.ts +1 -0
  123. package/dist/clis/notion/read.js +30 -0
  124. package/dist/clis/notion/search.d.ts +1 -0
  125. package/dist/clis/notion/search.js +46 -0
  126. package/dist/clis/notion/sidebar.d.ts +1 -0
  127. package/dist/clis/notion/sidebar.js +41 -0
  128. package/dist/clis/notion/status.d.ts +1 -0
  129. package/dist/clis/notion/status.js +16 -0
  130. package/dist/clis/notion/write.d.ts +1 -0
  131. package/dist/clis/notion/write.js +40 -0
  132. package/dist/clis/twitter/download.d.ts +8 -0
  133. package/dist/clis/twitter/download.js +204 -0
  134. package/dist/clis/wechat/chats.d.ts +1 -0
  135. package/dist/clis/wechat/chats.js +28 -0
  136. package/dist/clis/wechat/contacts.d.ts +1 -0
  137. package/dist/clis/wechat/contacts.js +28 -0
  138. package/dist/clis/wechat/read.d.ts +1 -0
  139. package/dist/clis/wechat/read.js +58 -0
  140. package/dist/clis/wechat/search.d.ts +1 -0
  141. package/dist/clis/wechat/search.js +31 -0
  142. package/dist/clis/wechat/send.d.ts +1 -0
  143. package/dist/clis/wechat/send.js +42 -0
  144. package/dist/clis/wechat/status.d.ts +1 -0
  145. package/dist/clis/wechat/status.js +29 -0
  146. package/dist/clis/xiaohongshu/creator-note-detail.d.ts +10 -0
  147. package/dist/clis/xiaohongshu/creator-note-detail.js +88 -0
  148. package/dist/clis/xiaohongshu/creator-notes.d.ts +11 -0
  149. package/dist/clis/xiaohongshu/creator-notes.js +109 -0
  150. package/dist/clis/xiaohongshu/creator-profile.d.ts +10 -0
  151. package/dist/clis/xiaohongshu/creator-profile.js +54 -0
  152. package/dist/clis/xiaohongshu/creator-stats.d.ts +10 -0
  153. package/dist/clis/xiaohongshu/creator-stats.js +74 -0
  154. package/dist/clis/xiaohongshu/download.d.ts +7 -0
  155. package/dist/clis/xiaohongshu/download.js +155 -0
  156. package/dist/clis/xiaohongshu/search.js +1 -1
  157. package/dist/clis/xiaohongshu/user-helpers.d.ts +15 -0
  158. package/dist/clis/xiaohongshu/user-helpers.js +67 -0
  159. package/dist/clis/xiaohongshu/user-helpers.test.d.ts +1 -0
  160. package/dist/clis/xiaohongshu/user-helpers.test.js +81 -0
  161. package/dist/clis/xiaohongshu/user.js +46 -29
  162. package/dist/clis/zhihu/download.d.ts +11 -0
  163. package/dist/clis/zhihu/download.js +186 -0
  164. package/dist/clis/zhihu/download.test.d.ts +1 -0
  165. package/dist/clis/zhihu/download.test.js +10 -0
  166. package/dist/daemon.d.ts +13 -0
  167. package/dist/daemon.js +187 -0
  168. package/dist/doctor.d.ts +27 -61
  169. package/dist/doctor.js +70 -601
  170. package/dist/doctor.test.js +30 -170
  171. package/dist/download/index.d.ts +79 -0
  172. package/dist/download/index.js +325 -0
  173. package/dist/download/progress.d.ts +36 -0
  174. package/dist/download/progress.js +111 -0
  175. package/dist/engine.test.js +15 -0
  176. package/dist/main.js +22 -28
  177. package/dist/pipeline/executor.test.js +1 -0
  178. package/dist/pipeline/registry.js +2 -0
  179. package/dist/pipeline/steps/browser.js +2 -2
  180. package/dist/pipeline/steps/download.d.ts +34 -0
  181. package/dist/pipeline/steps/download.js +251 -0
  182. package/dist/pipeline/steps/intercept.js +1 -2
  183. package/dist/pipeline/template.js +28 -0
  184. package/dist/setup.d.ts +6 -0
  185. package/dist/setup.js +46 -160
  186. package/dist/types.d.ts +6 -0
  187. package/extension/icons/icon-128.png +0 -0
  188. package/extension/icons/icon-16.png +0 -0
  189. package/extension/icons/icon-32.png +0 -0
  190. package/extension/icons/icon-48.png +0 -0
  191. package/extension/manifest.json +31 -0
  192. package/extension/package.json +16 -0
  193. package/extension/src/background.ts +293 -0
  194. package/extension/src/cdp.ts +125 -0
  195. package/extension/src/protocol.ts +57 -0
  196. package/extension/store-assets/screenshot-1280x800.png +0 -0
  197. package/extension/tsconfig.json +15 -0
  198. package/extension/vite.config.ts +18 -0
  199. package/package.json +8 -7
  200. package/scripts/test-site.mjs +70 -0
  201. package/src/browser/daemon-client.ts +113 -0
  202. package/src/browser/discover.ts +18 -216
  203. package/src/browser/errors.ts +30 -100
  204. package/src/browser/index.ts +6 -12
  205. package/src/browser/mcp.ts +78 -278
  206. package/src/browser/page.ts +222 -88
  207. package/src/browser.test.ts +3 -210
  208. package/src/build-manifest.test.ts +28 -0
  209. package/src/build-manifest.ts +147 -57
  210. package/src/clis/bilibili/download.ts +161 -0
  211. package/src/clis/chatgpt/README.md +1 -1
  212. package/src/clis/chatgpt/README.zh-CN.md +1 -1
  213. package/src/clis/chatwise/README.md +38 -0
  214. package/src/clis/chatwise/README.zh-CN.md +38 -0
  215. package/src/clis/chatwise/ask.ts +87 -0
  216. package/src/clis/chatwise/export.ts +51 -0
  217. package/src/clis/chatwise/history.ts +47 -0
  218. package/src/clis/chatwise/model.ts +87 -0
  219. package/src/clis/chatwise/new.ts +21 -0
  220. package/src/clis/chatwise/read.ts +42 -0
  221. package/src/clis/chatwise/screenshot.ts +33 -0
  222. package/src/clis/chatwise/send.ts +50 -0
  223. package/src/clis/chatwise/status.ts +25 -0
  224. package/src/clis/discord-app/README.md +28 -0
  225. package/src/clis/discord-app/README.zh-CN.md +28 -0
  226. package/src/clis/discord-app/channels.ts +48 -0
  227. package/src/clis/discord-app/members.ts +41 -0
  228. package/src/clis/discord-app/read.ts +49 -0
  229. package/src/clis/discord-app/search.ts +64 -0
  230. package/src/clis/discord-app/send.ts +32 -0
  231. package/src/clis/discord-app/servers.ts +39 -0
  232. package/src/clis/discord-app/status.ts +18 -0
  233. package/src/clis/feishu/README.md +20 -0
  234. package/src/clis/feishu/README.zh-CN.md +20 -0
  235. package/src/clis/feishu/new.ts +32 -0
  236. package/src/clis/feishu/read.ts +48 -0
  237. package/src/clis/feishu/search.ts +35 -0
  238. package/src/clis/feishu/send.ts +46 -0
  239. package/src/clis/feishu/status.ts +34 -0
  240. package/src/clis/grok/ask.ts +90 -0
  241. package/src/clis/grok/debug.ts +49 -0
  242. package/src/clis/jimeng/generate.yaml +84 -0
  243. package/src/clis/jimeng/history.yaml +47 -0
  244. package/src/clis/linux-do/categories.yaml +41 -0
  245. package/src/clis/linux-do/category.yaml +49 -0
  246. package/src/clis/linux-do/hot.yaml +50 -0
  247. package/src/clis/linux-do/latest.yaml +40 -0
  248. package/src/clis/linux-do/search.yaml +45 -0
  249. package/src/clis/linux-do/topic.yaml +38 -0
  250. package/src/clis/neteasemusic/README.md +31 -0
  251. package/src/clis/neteasemusic/README.zh-CN.md +31 -0
  252. package/src/clis/neteasemusic/like.ts +28 -0
  253. package/src/clis/neteasemusic/lyrics.ts +53 -0
  254. package/src/clis/neteasemusic/next.ts +30 -0
  255. package/src/clis/neteasemusic/play.ts +30 -0
  256. package/src/clis/neteasemusic/playing.ts +62 -0
  257. package/src/clis/neteasemusic/playlist.ts +51 -0
  258. package/src/clis/neteasemusic/prev.ts +29 -0
  259. package/src/clis/neteasemusic/search.ts +58 -0
  260. package/src/clis/neteasemusic/status.ts +18 -0
  261. package/src/clis/neteasemusic/volume.ts +61 -0
  262. package/src/clis/notion/README.md +29 -0
  263. package/src/clis/notion/README.zh-CN.md +29 -0
  264. package/src/clis/notion/export.ts +36 -0
  265. package/src/clis/notion/favorites.ts +87 -0
  266. package/src/clis/notion/new.ts +39 -0
  267. package/src/clis/notion/read.ts +33 -0
  268. package/src/clis/notion/search.ts +54 -0
  269. package/src/clis/notion/sidebar.ts +44 -0
  270. package/src/clis/notion/status.ts +18 -0
  271. package/src/clis/notion/write.ts +45 -0
  272. package/src/clis/twitter/download.ts +227 -0
  273. package/src/clis/wechat/README.md +28 -0
  274. package/src/clis/wechat/README.zh-CN.md +28 -0
  275. package/src/clis/wechat/chats.ts +33 -0
  276. package/src/clis/wechat/contacts.ts +33 -0
  277. package/src/clis/wechat/read.ts +72 -0
  278. package/src/clis/wechat/search.ts +36 -0
  279. package/src/clis/wechat/send.ts +49 -0
  280. package/src/clis/wechat/status.ts +35 -0
  281. package/src/clis/xiaohongshu/creator-note-detail.ts +95 -0
  282. package/src/clis/xiaohongshu/creator-notes.ts +116 -0
  283. package/src/clis/xiaohongshu/creator-profile.ts +60 -0
  284. package/src/clis/xiaohongshu/creator-stats.ts +81 -0
  285. package/src/clis/xiaohongshu/download.ts +173 -0
  286. package/src/clis/xiaohongshu/search.ts +1 -1
  287. package/src/clis/xiaohongshu/user-helpers.test.ts +106 -0
  288. package/src/clis/xiaohongshu/user-helpers.ts +85 -0
  289. package/src/clis/xiaohongshu/user.ts +52 -32
  290. package/src/clis/zhihu/download.test.ts +12 -0
  291. package/src/clis/zhihu/download.ts +223 -0
  292. package/src/daemon.ts +217 -0
  293. package/src/doctor.test.ts +32 -193
  294. package/src/doctor.ts +74 -668
  295. package/src/download/index.ts +395 -0
  296. package/src/download/progress.ts +125 -0
  297. package/src/engine.test.ts +17 -0
  298. package/src/main.ts +18 -26
  299. package/src/pipeline/executor.test.ts +1 -0
  300. package/src/pipeline/registry.ts +2 -0
  301. package/src/pipeline/steps/browser.ts +2 -2
  302. package/src/pipeline/steps/download.ts +310 -0
  303. package/src/pipeline/steps/intercept.ts +1 -2
  304. package/src/pipeline/template.ts +26 -0
  305. package/src/setup.ts +47 -183
  306. package/src/types.ts +1 -0
  307. package/tests/e2e/browser-auth.test.ts +25 -0
@@ -1,197 +1,22 @@
1
1
  /**
2
- * MCP server path discovery and argument building.
2
+ * Daemon discovery — simplified from MCP server path discovery.
3
+ *
4
+ * Only needs to check if the daemon is running. No more file system
5
+ * scanning for @playwright/mcp locations.
3
6
  */
4
- import { execSync } from 'node:child_process';
5
- import { fileURLToPath } from 'node:url';
6
- import * as fs from 'node:fs';
7
- import * as os from 'node:os';
8
- import * as path from 'node:path';
9
- let _cachedMcpServerPath;
10
- let _existsSync = fs.existsSync;
11
- let _execSync = execSync;
12
- export function resetMcpServerPathCache() {
13
- _cachedMcpServerPath = undefined;
14
- }
15
- export function setMcpDiscoveryTestHooks(input) {
16
- _existsSync = input?.existsSync ?? fs.existsSync;
17
- _execSync = input?.execSync ?? execSync;
18
- }
19
- export function findMcpServerPath() {
20
- if (_cachedMcpServerPath !== undefined)
21
- return _cachedMcpServerPath;
22
- const envMcp = process.env.OPENCLI_MCP_SERVER_PATH;
23
- if (envMcp && _existsSync(envMcp)) {
24
- _cachedMcpServerPath = envMcp;
25
- return _cachedMcpServerPath;
26
- }
27
- // Check local node_modules first (@playwright/mcp is the modern package)
28
- const localMcp = path.resolve('node_modules', '@playwright', 'mcp', 'cli.js');
29
- if (_existsSync(localMcp)) {
30
- _cachedMcpServerPath = localMcp;
31
- return _cachedMcpServerPath;
32
- }
33
- // Check project-relative path
34
- const __dirname2 = path.dirname(fileURLToPath(import.meta.url));
35
- const projectMcp = path.resolve(__dirname2, '..', '..', 'node_modules', '@playwright', 'mcp', 'cli.js');
36
- if (_existsSync(projectMcp)) {
37
- _cachedMcpServerPath = projectMcp;
38
- return _cachedMcpServerPath;
39
- }
40
- // Check global npm/yarn locations derived from current Node runtime.
41
- const nodePrefix = path.resolve(path.dirname(process.execPath), '..');
42
- const globalNodeModules = path.join(nodePrefix, 'lib', 'node_modules');
43
- const globalMcp = path.join(globalNodeModules, '@playwright', 'mcp', 'cli.js');
44
- if (_existsSync(globalMcp)) {
45
- _cachedMcpServerPath = globalMcp;
46
- return _cachedMcpServerPath;
47
- }
48
- // Check npm global root directly.
49
- try {
50
- const npmRootGlobal = _execSync('npm root -g 2>/dev/null', {
51
- encoding: 'utf-8',
52
- timeout: 5000,
53
- }).trim();
54
- const npmGlobalMcp = path.join(npmRootGlobal, '@playwright', 'mcp', 'cli.js');
55
- if (npmRootGlobal && _existsSync(npmGlobalMcp)) {
56
- _cachedMcpServerPath = npmGlobalMcp;
57
- return _cachedMcpServerPath;
58
- }
59
- }
60
- catch { }
61
- // Check common locations
62
- const candidates = [
63
- path.join(os.homedir(), '.npm', '_npx'),
64
- path.join(os.homedir(), 'node_modules', '.bin'),
65
- '/usr/local/lib/node_modules',
66
- ];
67
- // Try npx resolution (legacy package name)
68
- try {
69
- const result = _execSync('npx -y --package=@playwright/mcp which mcp-server-playwright 2>/dev/null', { encoding: 'utf-8', timeout: 10000 }).trim();
70
- if (result && _existsSync(result)) {
71
- _cachedMcpServerPath = result;
72
- return _cachedMcpServerPath;
73
- }
74
- }
75
- catch { }
76
- // Try which
77
- try {
78
- const result = _execSync('which mcp-server-playwright 2>/dev/null', { encoding: 'utf-8', timeout: 5000 }).trim();
79
- if (result && _existsSync(result)) {
80
- _cachedMcpServerPath = result;
81
- return _cachedMcpServerPath;
82
- }
83
- }
84
- catch { }
85
- // Search in common npx cache
86
- for (const base of candidates) {
87
- if (!_existsSync(base))
88
- continue;
89
- try {
90
- const found = _execSync(`find "${base}" -name "cli.js" -path "*playwright*mcp*" 2>/dev/null | head -1`, { encoding: 'utf-8', timeout: 5000 }).trim();
91
- if (found) {
92
- _cachedMcpServerPath = found;
93
- return _cachedMcpServerPath;
94
- }
95
- }
96
- catch { }
97
- }
98
- _cachedMcpServerPath = null;
99
- return _cachedMcpServerPath;
100
- }
7
+ import { isDaemonRunning } from './daemon-client.js';
8
+ export { isDaemonRunning };
101
9
  /**
102
- * Chrome 144+ auto-discovery: read DevToolsActivePort file to get CDP endpoint.
103
- *
104
- * Starting with Chrome 144, users can enable remote debugging from
105
- * chrome://inspect#remote-debugging without any command-line flags.
106
- * Chrome writes the active port and browser GUID to a DevToolsActivePort file
107
- * in the user data directory, which we read to construct the WebSocket endpoint.
10
+ * Check daemon status and return connection info.
108
11
  */
109
- export function discoverChromeEndpoint() {
110
- const candidates = [];
111
- // User-specified Chrome data dir takes highest priority
112
- if (process.env.CHROME_USER_DATA_DIR) {
113
- candidates.push(path.join(process.env.CHROME_USER_DATA_DIR, 'DevToolsActivePort'));
114
- }
115
- // Standard Chrome/Edge user data dirs per platform
116
- if (process.platform === 'win32') {
117
- const localAppData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), 'AppData', 'Local');
118
- candidates.push(path.join(localAppData, 'Google', 'Chrome', 'User Data', 'DevToolsActivePort'));
119
- candidates.push(path.join(localAppData, 'Microsoft', 'Edge', 'User Data', 'DevToolsActivePort'));
120
- }
121
- else if (process.platform === 'darwin') {
122
- candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome', 'DevToolsActivePort'));
123
- candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Microsoft Edge', 'DevToolsActivePort'));
124
- }
125
- else {
126
- candidates.push(path.join(os.homedir(), '.config', 'google-chrome', 'DevToolsActivePort'));
127
- candidates.push(path.join(os.homedir(), '.config', 'chromium', 'DevToolsActivePort'));
128
- candidates.push(path.join(os.homedir(), '.config', 'microsoft-edge', 'DevToolsActivePort'));
129
- }
130
- for (const filePath of candidates) {
131
- try {
132
- const content = fs.readFileSync(filePath, 'utf-8').trim();
133
- const lines = content.split('\n');
134
- if (lines.length >= 2) {
135
- const port = parseInt(lines[0], 10);
136
- const browserPath = lines[1]; // e.g. /devtools/browser/<GUID>
137
- if (port > 0 && browserPath.startsWith('/devtools/browser/')) {
138
- return `ws://127.0.0.1:${port}${browserPath}`;
139
- }
140
- }
141
- }
142
- catch { }
143
- }
144
- return null;
145
- }
146
- export function resolveCdpEndpoint() {
147
- const envVal = process.env.OPENCLI_CDP_ENDPOINT;
148
- if (envVal === '1' || envVal?.toLowerCase() === 'true') {
149
- const autoDiscovered = discoverChromeEndpoint();
150
- return { endpoint: autoDiscovered ?? envVal, requestedCdp: true };
151
- }
152
- if (envVal) {
153
- return { endpoint: envVal, requestedCdp: true };
154
- }
155
- // Fallback to auto-discovery if not explicitly set
156
- const autoDiscovered = discoverChromeEndpoint();
157
- if (autoDiscovered) {
158
- return { endpoint: autoDiscovered, requestedCdp: true };
159
- }
160
- return { requestedCdp: false };
161
- }
162
- function buildRuntimeArgs(input) {
163
- const args = [];
164
- // Priority 1: CDP endpoint (remote Chrome debugging or local Auto-Discovery)
165
- if (input?.cdpEndpoint) {
166
- args.push('--cdp-endpoint', input.cdpEndpoint);
167
- return args;
168
- }
169
- // Priority 2: Extension mode (local Chrome with MCP Bridge extension)
170
- if (!process.env.CI) {
171
- args.push('--extension');
172
- }
173
- // CI/standalone mode: @playwright/mcp launches its own browser (headed by default).
174
- // xvfb provides a virtual display for headed mode in GitHub Actions.
175
- if (input?.executablePath) {
176
- args.push('--executable-path', input.executablePath);
12
+ export async function checkDaemonStatus() {
13
+ try {
14
+ const port = parseInt(process.env.OPENCLI_DAEMON_PORT ?? '19825', 10);
15
+ const res = await fetch(`http://127.0.0.1:${port}/status`);
16
+ const data = await res.json();
17
+ return { running: true, extensionConnected: data.extensionConnected };
177
18
  }
178
- return args;
179
- }
180
- export function buildMcpArgs(input) {
181
- return [input.mcpPath, ...buildRuntimeArgs(input)];
182
- }
183
- export function buildMcpLaunchSpec(input) {
184
- const runtimeArgs = buildRuntimeArgs(input);
185
- if (input.mcpPath) {
186
- return {
187
- command: 'node',
188
- args: [input.mcpPath, ...runtimeArgs],
189
- usedNpxFallback: false,
190
- };
19
+ catch {
20
+ return { running: false, extensionConnected: false };
191
21
  }
192
- return {
193
- command: 'npx',
194
- args: ['-y', '@playwright/mcp@latest', ...runtimeArgs],
195
- usedNpxFallback: true,
196
- };
197
22
  }
@@ -1,22 +1,8 @@
1
1
  /**
2
- * Browser connection error classification and formatting.
2
+ * Browser connection error helpers.
3
+ *
4
+ * Simplified — no more token/extension/CDP classification.
5
+ * The daemon architecture has a single failure mode: daemon not reachable or extension not connected.
3
6
  */
4
- export type ConnectFailureKind = 'missing-token' | 'extension-timeout' | 'extension-not-installed' | 'mcp-init' | 'process-exit' | 'cdp-connection-failed' | 'unknown';
5
- export type ConnectFailureInput = {
6
- kind: ConnectFailureKind;
7
- timeout: number;
8
- hasExtensionToken: boolean;
9
- tokenFingerprint?: string | null;
10
- stderr?: string;
11
- exitCode?: number | null;
12
- rawMessage?: string;
13
- };
14
- export declare function getTokenFingerprint(token: string | undefined): string | null;
15
- export declare function formatBrowserConnectError(input: ConnectFailureInput): Error;
16
- export declare function inferConnectFailureKind(args: {
17
- hasExtensionToken: boolean;
18
- stderr: string;
19
- rawMessage?: string;
20
- exited?: boolean;
21
- isCdpMode?: boolean;
22
- }): ConnectFailureKind;
7
+ export type ConnectFailureKind = 'daemon-not-running' | 'extension-not-connected' | 'command-failed' | 'unknown';
8
+ export declare function formatBrowserConnectError(kind: ConnectFailureKind, detail?: string): Error;
@@ -1,67 +1,28 @@
1
1
  /**
2
- * Browser connection error classification and formatting.
2
+ * Browser connection error helpers.
3
+ *
4
+ * Simplified — no more token/extension/CDP classification.
5
+ * The daemon architecture has a single failure mode: daemon not reachable or extension not connected.
3
6
  */
4
- import { createHash } from 'node:crypto';
5
- export function getTokenFingerprint(token) {
6
- if (!token)
7
- return null;
8
- return createHash('sha256').update(token).digest('hex').slice(0, 8);
9
- }
10
- export function formatBrowserConnectError(input) {
11
- const stderr = input.stderr?.trim();
12
- const suffix = stderr ? `\n\nMCP stderr:\n${stderr}` : '';
13
- const tokenHint = input.tokenFingerprint ? ` Token fingerprint: ${input.tokenFingerprint}.` : '';
14
- if (input.kind === 'cdp-connection-failed') {
15
- return new Error(`Failed to connect to remote Chrome via CDP endpoint.\n\n` +
16
- `Check if Chrome is running with remote debugging enabled (--remote-debugging-port=9222) or DevToolsActivePort is available under chrome://inspect#remote-debugging.\n` +
17
- `If you specified OPENCLI_CDP_ENDPOINT=1, auto-discovery might have failed.` +
18
- suffix);
19
- }
20
- if (input.kind === 'missing-token') {
21
- return new Error('Failed to connect to Playwright MCP Bridge: PLAYWRIGHT_MCP_EXTENSION_TOKEN is not set.\n\n' +
22
- 'Without this token, Chrome will show a manual approval dialog for every new MCP connection. ' +
23
- 'Copy the token from the Playwright MCP Bridge extension and set it in BOTH your shell environment and MCP client config.' +
24
- suffix);
25
- }
26
- if (input.kind === 'extension-not-installed') {
27
- return new Error('Failed to connect to Playwright MCP Bridge: the browser extension did not attach.\n\n' +
28
- 'Make sure Chrome is running and the "Playwright MCP Bridge" extension is installed and enabled. ' +
29
- 'If Chrome shows an approval dialog, click Allow.' +
30
- suffix);
31
- }
32
- if (input.kind === 'extension-timeout') {
33
- const likelyCause = input.hasExtensionToken
34
- ? `The most likely cause is that PLAYWRIGHT_MCP_EXTENSION_TOKEN does not match the token currently shown by the browser extension.${tokenHint} Re-copy the token from the extension and update BOTH your shell environment and MCP client config.`
35
- : 'PLAYWRIGHT_MCP_EXTENSION_TOKEN is not configured, so the extension may be waiting for manual approval.';
36
- return new Error(`Timed out connecting to Playwright MCP Bridge (${input.timeout}s).\n\n` +
37
- `${likelyCause} If a browser prompt is visible, click Allow.` +
38
- suffix);
39
- }
40
- if (input.kind === 'mcp-init') {
41
- return new Error(`Failed to initialize Playwright MCP: ${input.rawMessage ?? 'unknown error'}${suffix}`);
42
- }
43
- if (input.kind === 'process-exit') {
44
- return new Error(`Playwright MCP process exited before the browser connection was established${input.exitCode == null ? '' : ` (code ${input.exitCode})`}.` +
45
- suffix);
46
- }
47
- return new Error(input.rawMessage ?? 'Failed to connect to browser');
48
- }
49
- export function inferConnectFailureKind(args) {
50
- const haystack = `${args.rawMessage ?? ''}\n${args.stderr}`.toLowerCase();
51
- if (args.isCdpMode) {
52
- if (args.rawMessage?.startsWith('MCP init failed:'))
53
- return 'mcp-init';
54
- if (args.exited)
55
- return 'cdp-connection-failed';
56
- return 'cdp-connection-failed';
7
+ export function formatBrowserConnectError(kind, detail) {
8
+ switch (kind) {
9
+ case 'daemon-not-running':
10
+ return new Error('Cannot connect to opencli daemon.\n\n' +
11
+ 'The daemon should start automatically. If it doesn\'t, try:\n' +
12
+ ' node dist/daemon.js\n' +
13
+ 'Make sure port 19825 is available.' +
14
+ (detail ? `\n\n${detail}` : ''));
15
+ case 'extension-not-connected':
16
+ return new Error('opencli Browser Bridge extension is not connected.\n\n' +
17
+ 'Please install the extension:\n' +
18
+ ' 1. Download from GitHub Releases\n' +
19
+ ' 2. Open chrome://extensions/ Enable Developer Mode\n' +
20
+ ' 3. Click "Load unpacked" select the extension folder\n' +
21
+ ' 4. Make sure Chrome is running' +
22
+ (detail ? `\n\n${detail}` : ''));
23
+ case 'command-failed':
24
+ return new Error(`Browser command failed: ${detail ?? 'unknown error'}`);
25
+ default:
26
+ return new Error(detail ?? 'Failed to connect to browser');
57
27
  }
58
- if (!args.hasExtensionToken)
59
- return 'missing-token';
60
- if (haystack.includes('extension connection timeout') || haystack.includes('playwright mcp bridge'))
61
- return 'extension-not-installed';
62
- if (args.rawMessage?.startsWith('MCP init failed:'))
63
- return 'mcp-init';
64
- if (args.exited)
65
- return 'process-exit';
66
- return 'extension-timeout';
67
28
  }
@@ -6,22 +6,13 @@
6
6
  */
7
7
  export { Page } from './page.js';
8
8
  export { PlaywrightMCP } from './mcp.js';
9
- export { getTokenFingerprint, formatBrowserConnectError } from './errors.js';
10
- export type { ConnectFailureKind, ConnectFailureInput } from './errors.js';
11
- export { resolveCdpEndpoint } from './discover.js';
12
- import { createJsonRpcRequest } from './mcp.js';
9
+ export { isDaemonRunning } from './daemon-client.js';
10
+ export declare function getTokenFingerprint(_token: string | undefined): string | null;
13
11
  import { extractTabEntries, diffTabIndexes, appendLimited } from './tabs.js';
14
- import { buildMcpArgs, buildMcpLaunchSpec, findMcpServerPath, resetMcpServerPathCache, setMcpDiscoveryTestHooks } from './discover.js';
15
12
  import { withTimeoutMs } from '../runtime.js';
16
13
  export declare const __test__: {
17
- createJsonRpcRequest: typeof createJsonRpcRequest;
18
14
  extractTabEntries: typeof extractTabEntries;
19
15
  diffTabIndexes: typeof diffTabIndexes;
20
16
  appendLimited: typeof appendLimited;
21
- buildMcpArgs: typeof buildMcpArgs;
22
- buildMcpLaunchSpec: typeof buildMcpLaunchSpec;
23
- findMcpServerPath: typeof findMcpServerPath;
24
- resetMcpServerPathCache: typeof resetMcpServerPathCache;
25
- setMcpDiscoveryTestHooks: typeof setMcpDiscoveryTestHooks;
26
17
  withTimeoutMs: typeof withTimeoutMs;
27
18
  };
@@ -6,22 +6,16 @@
6
6
  */
7
7
  export { Page } from './page.js';
8
8
  export { PlaywrightMCP } from './mcp.js';
9
- export { getTokenFingerprint, formatBrowserConnectError } from './errors.js';
10
- export { resolveCdpEndpoint } from './discover.js';
11
- // Test-only helpers — exposed for unit tests
12
- import { createJsonRpcRequest } from './mcp.js';
9
+ export { isDaemonRunning } from './daemon-client.js';
10
+ // Backward compatibility: getTokenFingerprint is no longer needed but kept as no-op export
11
+ export function getTokenFingerprint(_token) {
12
+ return null;
13
+ }
13
14
  import { extractTabEntries, diffTabIndexes, appendLimited } from './tabs.js';
14
- import { buildMcpArgs, buildMcpLaunchSpec, findMcpServerPath, resetMcpServerPathCache, setMcpDiscoveryTestHooks } from './discover.js';
15
15
  import { withTimeoutMs } from '../runtime.js';
16
16
  export const __test__ = {
17
- createJsonRpcRequest,
18
17
  extractTabEntries,
19
18
  diffTabIndexes,
20
19
  appendLimited,
21
- buildMcpArgs,
22
- buildMcpLaunchSpec,
23
- findMcpServerPath,
24
- resetMcpServerPathCache,
25
- setMcpDiscoveryTestHooks,
26
20
  withTimeoutMs,
27
21
  };
@@ -1,33 +1,24 @@
1
1
  /**
2
- * Playwright MCP process manager.
3
- * Handles lifecycle management, JSON-RPC communication, and browser session orchestration.
2
+ * Browser session manager — auto-spawns daemon and provides IPage.
3
+ *
4
+ * Replaces the old PlaywrightMCP class. Still exports as PlaywrightMCP
5
+ * for backward compatibility with main.ts and other consumers.
4
6
  */
5
7
  import type { IPage } from '../types.js';
6
8
  export type PlaywrightMCPState = 'idle' | 'connecting' | 'connected' | 'closing' | 'closed';
7
- export declare function createJsonRpcRequest(method: string, params?: Record<string, unknown>): {
8
- id: number;
9
- message: string;
10
- };
11
9
  /**
12
- * Playwright MCP process manager.
10
+ * Browser factory: manages daemon lifecycle and provides IPage instances.
11
+ *
12
+ * Kept as `PlaywrightMCP` class name for backward compatibility.
13
13
  */
14
14
  export declare class PlaywrightMCP {
15
- private static _activeInsts;
16
- private static _cleanupRegistered;
17
- private static _registerGlobalCleanup;
18
- private _proc;
19
- private _buffer;
20
- private _pending;
21
- private _initialTabIdentities;
22
- private _closingPromise;
23
15
  private _state;
24
16
  private _page;
17
+ private _daemonProc;
25
18
  get state(): PlaywrightMCPState;
26
- private _sendRequest;
27
- private _rejectPendingRequests;
28
- private _resetAfterFailedConnect;
29
19
  connect(opts?: {
30
20
  timeout?: number;
31
21
  }): Promise<IPage>;
32
22
  close(): Promise<void>;
23
+ private _ensureDaemon;
33
24
  }