@browsers-cli/se-cli 0.1.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 (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +379 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +14 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config.d.ts +17 -0
  7. package/dist/config.js +80 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/daemon/backend.d.ts +9 -0
  10. package/dist/daemon/backend.js +52 -0
  11. package/dist/daemon/backend.js.map +1 -0
  12. package/dist/daemon/server.d.ts +1 -0
  13. package/dist/daemon/server.js +341 -0
  14. package/dist/daemon/server.js.map +1 -0
  15. package/dist/daemon/tools/check.d.ts +7 -0
  16. package/dist/daemon/tools/check.js +20 -0
  17. package/dist/daemon/tools/check.js.map +1 -0
  18. package/dist/daemon/tools/click.d.ts +4 -0
  19. package/dist/daemon/tools/click.js +14 -0
  20. package/dist/daemon/tools/click.js.map +1 -0
  21. package/dist/daemon/tools/eval.d.ts +5 -0
  22. package/dist/daemon/tools/eval.js +18 -0
  23. package/dist/daemon/tools/eval.js.map +1 -0
  24. package/dist/daemon/tools/fill.d.ts +6 -0
  25. package/dist/daemon/tools/fill.js +25 -0
  26. package/dist/daemon/tools/fill.js.map +1 -0
  27. package/dist/daemon/tools/find.d.ts +5 -0
  28. package/dist/daemon/tools/find.js +84 -0
  29. package/dist/daemon/tools/find.js.map +1 -0
  30. package/dist/daemon/tools/goto.d.ts +4 -0
  31. package/dist/daemon/tools/goto.js +25 -0
  32. package/dist/daemon/tools/goto.js.map +1 -0
  33. package/dist/daemon/tools/index.d.ts +1 -0
  34. package/dist/daemon/tools/index.js +37 -0
  35. package/dist/daemon/tools/index.js.map +1 -0
  36. package/dist/daemon/tools/navigation.d.ts +4 -0
  37. package/dist/daemon/tools/navigation.js +21 -0
  38. package/dist/daemon/tools/navigation.js.map +1 -0
  39. package/dist/daemon/tools/press.d.ts +4 -0
  40. package/dist/daemon/tools/press.js +23 -0
  41. package/dist/daemon/tools/press.js.map +1 -0
  42. package/dist/daemon/tools/screenshot.d.ts +5 -0
  43. package/dist/daemon/tools/screenshot.js +57 -0
  44. package/dist/daemon/tools/screenshot.js.map +1 -0
  45. package/dist/daemon/tools/select.d.ts +5 -0
  46. package/dist/daemon/tools/select.js +13 -0
  47. package/dist/daemon/tools/select.js.map +1 -0
  48. package/dist/daemon/tools/shared.d.ts +4 -0
  49. package/dist/daemon/tools/shared.js +35 -0
  50. package/dist/daemon/tools/shared.js.map +1 -0
  51. package/dist/daemon/tools/snapshot.d.ts +6 -0
  52. package/dist/daemon/tools/snapshot.js +90 -0
  53. package/dist/daemon/tools/snapshot.js.map +1 -0
  54. package/dist/daemon/tools/title.d.ts +2 -0
  55. package/dist/daemon/tools/title.js +8 -0
  56. package/dist/daemon/tools/title.js.map +1 -0
  57. package/dist/daemon/tools/type.d.ts +4 -0
  58. package/dist/daemon/tools/type.js +9 -0
  59. package/dist/daemon/tools/type.js.map +1 -0
  60. package/dist/daemon/tools/url.d.ts +2 -0
  61. package/dist/daemon/tools/url.js +8 -0
  62. package/dist/daemon/tools/url.js.map +1 -0
  63. package/dist/minimist.d.ts +10 -0
  64. package/dist/minimist.js +52 -0
  65. package/dist/minimist.js.map +1 -0
  66. package/dist/output.d.ts +6 -0
  67. package/dist/output.js +32 -0
  68. package/dist/output.js.map +1 -0
  69. package/dist/program.d.ts +2 -0
  70. package/dist/program.js +200 -0
  71. package/dist/program.js.map +1 -0
  72. package/dist/protocol.d.ts +29 -0
  73. package/dist/protocol.js +3 -0
  74. package/dist/protocol.js.map +1 -0
  75. package/dist/registry.d.ts +19 -0
  76. package/dist/registry.js +91 -0
  77. package/dist/registry.js.map +1 -0
  78. package/dist/response.d.ts +23 -0
  79. package/dist/response.js +64 -0
  80. package/dist/response.js.map +1 -0
  81. package/dist/session.d.ts +23 -0
  82. package/dist/session.js +264 -0
  83. package/dist/session.js.map +1 -0
  84. package/dist/snapshot/aria-snapshot.d.ts +1 -0
  85. package/dist/snapshot/aria-snapshot.js +200 -0
  86. package/dist/snapshot/aria-snapshot.js.map +1 -0
  87. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 alaahong
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,379 @@
1
+ <div align="center">
2
+ <img src="site/assets/img/logo.svg" alt="se-cli" width="280" />
3
+ </div>
4
+
5
+ <p align="center">
6
+ Token-efficient Selenium browser automation CLI for AI agents and humans.<br/>
7
+ Inspired by <a href="https://github.com/microsoft/playwright-cli">playwright-cli</a>, ported to the Selenium ecosystem.
8
+ </p>
9
+
10
+ <p align="center">
11
+ <a href="https://www.npmjs.com/package/se-cli"><img src="https://img.shields.io/npm/v/se-cli?color=22C55E&label=npm" alt="npm version" /></a>
12
+ <a href="https://github.com/se-cli/se-cli/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/se-cli/se-cli/ci.yml?branch=main&label=CI&color=22C55E" alt="CI" /></a>
13
+ <a href="https://www.npmjs.com/package/se-cli"><img src="https://img.shields.io/node/v/se-cli?color=22C55E" alt="Node.js" /></a>
14
+ <a href="https://github.com/se-cli/se-cli/blob/main/LICENSE"><img src="https://img.shields.io/github/license/se-cli/se-cli?color=22C55E" alt="License" /></a>
15
+ <a href="https://github.com/se-cli/se-cli"><img src="https://img.shields.io/github/stars/se-cli/se-cli?style=social" alt="Stars" /></a>
16
+ </p>
17
+
18
+ ---
19
+
20
+ ## Why se-cli?
21
+
22
+ Current Selenium MCP implementations consume too many tokens — large tool schemas loaded on every call, full accessibility tree dumps, and no command-line interface. **se-cli** solves this with a CLI + daemon architecture that minimizes token usage while maximizing agent productivity.
23
+
24
+ ### The Problem
25
+
26
+ | Approach | Token Cost | Why |
27
+ |----------|-----------|-----|
28
+ | Selenium MCP | High | Tool schemas (~5KB) loaded per call; verbose JSON-RPC envelope |
29
+ | Selenium scripts | N/A | Can't be driven by AI agents |
30
+ | Raw WebDriver API | N/A | No CLI, no session persistence |
31
+
32
+ ### The Solution
33
+
34
+ **se-cli** uses a short-lived CLI + long-lived daemon architecture:
35
+
36
+ - **Short-lived CLI**: each `se-cli <cmd>` is a stateless process — just sends one JSON line to the daemon, gets one line back, exits. Zero schema overhead.
37
+ - **Long-lived daemon**: holds the WebDriver instance across calls. No reconnection cost, no driver restart overhead.
38
+ - **Aria snapshot + refs**: page state captured as compact YAML with element refs (`e1`, `e2`). Interact by ref instead of verbose selectors.
39
+ - **Code generation**: every action emits the equivalent Selenium code — copy directly into test files.
40
+
41
+ ### Advantages
42
+
43
+ - **10x fewer tokens** than MCP for typical agent workflows (measured via aria snapshot vs full a11y tree)
44
+ - **Multi-browser**: Chrome, Edge, and Firefox support out of the box
45
+ - **Session persistence**: daemon survives across CLI invocations — no browser restart per command
46
+ - **Named sessions**: run multiple browsers in parallel with `-s=name`
47
+ - **Agent-agnostic**: works with any AI agent that can run shell commands (Claude Code, Cursor, Copilot CLI, etc.)
48
+ - **Familiar API**: commands mirror playwright-cli for easy migration
49
+ - **Code generation**: every action produces runnable Selenium code for test files
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ npm install -g se-cli
55
+ ```
56
+
57
+ Or use directly with npx:
58
+
59
+ ```bash
60
+ npx se-cli open https://example.com
61
+ ```
62
+
63
+ After installation, the following commands are available (all aliased to the same binary):
64
+
65
+ | Command | Description |
66
+ |---------|-------------|
67
+ | `se-cli` | Primary command name |
68
+ | `se` | Short alias |
69
+ | `selenium-cli` | Legacy alias for backward compatibility |
70
+
71
+ ### Prerequisites
72
+
73
+ - Node.js 18+
74
+ - One or more browsers installed:
75
+ - Google Chrome
76
+ - Microsoft Edge
77
+ - Mozilla Firefox
78
+
79
+ `selenium-manager` (bundled with `selenium-webdriver`) automatically downloads the correct driver binary.
80
+
81
+ ## Quick Start
82
+
83
+ ```bash
84
+ # Start a session and navigate
85
+ se-cli open https://example.com
86
+
87
+ # Take a snapshot to see the page structure
88
+ se-cli snapshot
89
+ # Output:
90
+ # - document:
91
+ # - heading "Example Domain" [level=1]
92
+ # - paragraph: "This domain is for use in illustrative examples..."
93
+ # - link "More information..." [ref=e1]
94
+
95
+ # Interact by ref
96
+ se-cli click e1
97
+
98
+ # Get page info
99
+ se-cli title
100
+ se-cli url
101
+
102
+ # Close the session
103
+ se-cli close
104
+ ```
105
+
106
+ ## Commands
107
+
108
+ ### Session Management
109
+
110
+ | Command | Description |
111
+ |---------|-------------|
112
+ | `open [url]` | Start daemon + browser, optionally navigate to URL |
113
+ | `close` | Close browser and daemon |
114
+ | `list` | List all sessions |
115
+ | `close-all` | Close all sessions gracefully |
116
+ | `kill-all` | Force-kill all sessions |
117
+
118
+ ### Navigation
119
+
120
+ | Command | Description |
121
+ |---------|-------------|
122
+ | `goto <url>` | Navigate to URL |
123
+ | `go-back` | Browser back |
124
+ | `go-forward` | Browser forward |
125
+ | `reload` | Reload page |
126
+
127
+ ### Interaction
128
+
129
+ | Command | Description |
130
+ |---------|-------------|
131
+ | `click <ref\|selector>` | Click element |
132
+ | `fill <ref\|selector> <text>` | Clear and fill input |
133
+ | `type <text>` | Type into focused element |
134
+ | `press <key>` | Press keyboard key (Enter, Tab, Escape, ArrowDown, ...) |
135
+ | `select <ref> <value>` | Select dropdown option |
136
+ | `check <ref>` | Check checkbox |
137
+ | `uncheck <ref>` | Uncheck checkbox |
138
+
139
+ ### Snapshot & Discovery
140
+
141
+ | Command | Description |
142
+ |---------|-------------|
143
+ | `snapshot [ref]` | Aria snapshot of page or element subtree |
144
+ | `snapshot --depth=N` | Limit snapshot depth |
145
+ | `snapshot --filename=f.yml` | Save snapshot to file |
146
+ | `find <text>` | Search snapshot for text |
147
+ | `find --regex <pattern>` | Search snapshot with regex |
148
+
149
+ ### Save & Execute
150
+
151
+ | Command | Description |
152
+ |---------|-------------|
153
+ | `screenshot [ref]` | Take screenshot (full page or element) |
154
+ | `screenshot --filename=f.png` | Save screenshot to file |
155
+ | `eval "<js>"` | Execute JavaScript, return result |
156
+ | `eval "<js>" <ref>` | Execute JavaScript on element |
157
+ | `title` | Get page title |
158
+ | `url` | Get current URL |
159
+
160
+ ### Flags
161
+
162
+ | Flag | Description |
163
+ |------|-------------|
164
+ | `--raw` | Output only the result value (for scripting) |
165
+ | `--json` | Structured JSON output |
166
+ | `-s=<name>` | Use named session |
167
+ | `--browser=chrome\|edge\|firefox` | Browser selection (default: chrome) |
168
+ | `--headed` | Show browser window (default: headless) |
169
+ | `--cdp=<url>` | Attach to running Chrome via CDP |
170
+
171
+ ## Usage Examples
172
+
173
+ ### Basic Form Submission
174
+
175
+ ```bash
176
+ se-cli open https://example.com/login
177
+ se-cli snapshot
178
+ # - textbox "Email" [ref=e1]
179
+ # - textbox "Password" [ref=e2]
180
+ # - button "Sign in" [ref=e3]
181
+
182
+ se-cli fill e1 "user@example.com"
183
+ se-cli fill e2 "password123"
184
+ se-cli click e3
185
+ se-cli snapshot
186
+ se-cli close
187
+ ```
188
+
189
+ ### Multi-Session (Parallel Browsers)
190
+
191
+ ```bash
192
+ se-cli -s=chrome open https://example.com --browser=chrome
193
+ se-cli -s=firefox open https://example.com --browser=firefox
194
+
195
+ se-cli -s=chrome title
196
+ se-cli -s=firefox title
197
+
198
+ se-cli -s=chrome close
199
+ se-cli -s=firefox close
200
+ ```
201
+
202
+ ### Attach to Running Chrome
203
+
204
+ ```bash
205
+ # Start Chrome with remote debugging
206
+ google-chrome --remote-debugging-port=9222
207
+
208
+ # Attach
209
+ se-cli open --cdp=http://localhost:9222
210
+ ```
211
+
212
+ ### Scripting with --raw
213
+
214
+ ```bash
215
+ # Get title for use in shell scripts
216
+ TITLE=$(se-cli --raw title)
217
+
218
+ # Count elements
219
+ COUNT=$(se-cli --raw eval "document.querySelectorAll('.item').length")
220
+ echo "Found $COUNT items"
221
+ ```
222
+
223
+ ### Code Generation
224
+
225
+ Every interaction command outputs the equivalent Selenium code:
226
+
227
+ ```
228
+ $ se-cli click e1
229
+
230
+ ### Ran Selenium code
231
+ ```js
232
+ await driver.findElement(By.css('[data-se-ref="e1"]')).click();
233
+ ```
234
+
235
+ Copy this directly into your test files.
236
+
237
+ ## AI Agent Integration
238
+
239
+ ### With Claude Code / Cursor / Copilot CLI
240
+
241
+ Place `skill/SKILL.md` into your agent's skills directory:
242
+
243
+ ```bash
244
+ # For Claude Code
245
+ mkdir -p .claude/skills/se-cli
246
+ cp skill/SKILL.md .claude/skills/se-cli/
247
+ ```
248
+
249
+ The agent can then use `se-cli` commands directly:
250
+
251
+ ```
252
+ User: "Check that the login page works"
253
+ Agent: I'll navigate to the login page and test it.
254
+ $ se-cli open https://app.example.com/login
255
+ $ se-cli snapshot
256
+ $ se-cli fill e1 "test@example.com"
257
+ $ se-cli fill e2 "password"
258
+ $ se-cli click e3
259
+ $ se-cli snapshot
260
+ The login succeeded — I can see the dashboard.
261
+ ```
262
+
263
+ ### Why CLI over MCP for agents?
264
+
265
+ | Aspect | MCP | CLI |
266
+ |--------|-----|-----|
267
+ | Token cost per call | ~500-1000 (schema) | ~50-100 (command + output) |
268
+ | Context pollution | Tool schemas fill context | No schemas in context |
269
+ | State persistence | Per-session overhead | Daemon holds state |
270
+ | Agent compatibility | MCP-compatible only | Any agent that runs shell |
271
+
272
+ ## Architecture
273
+
274
+ ```
275
+ ┌─────────────────┐ Unix socket / Win pipe ┌──────────────────────┐
276
+ │ se-cli │ ─── line-delimited JSON ─▶ │ se-cli daemon │
277
+ │ (short-lived) │ ◀── single response ───── │ (holds WebDriver) │
278
+ └─────────────────┘ └──────────────────────┘
279
+
280
+ │ W3C WebDriver HTTP
281
+
282
+ ┌──────────┐
283
+ │ Browser │
284
+ │(Chrome/ │
285
+ │ Edge/FF) │
286
+ └──────────┘
287
+ ```
288
+
289
+ - **CLI process**: spawned per command, sends one JSON line, receives one response, exits
290
+ - **Daemon process**: spawned on first `open`, persists across CLI calls, holds WebDriver
291
+ - **Communication**: line-delimited JSON over Unix socket (Linux/macOS) or Windows named pipe
292
+ - **Session registry**: `.session` JSON files in `<cache>/ms-se-cli/daemon/`
293
+
294
+ ### Aria Snapshot & Refs
295
+
296
+ The `snapshot` command injects a JavaScript script that:
297
+ 1. Walks the DOM tree following ARIA roles
298
+ 2. Generates compact YAML representation
299
+ 3. Assigns `data-se-ref="eN"` attributes to interactive elements
300
+ 4. Returns YAML for the agent to read
301
+
302
+ Refs are valid only within the current snapshot. After navigation or DOM changes, run `snapshot` again.
303
+
304
+ ## Development
305
+
306
+ ```bash
307
+ # Clone
308
+ git clone https://github.com/se-cli/se-cli.git
309
+ cd se-cli
310
+
311
+ # Install
312
+ npm install
313
+
314
+ # Build
315
+ npx tsc
316
+
317
+ # Run unit tests
318
+ npx vitest run tests/unit/
319
+
320
+ # Run integration tests (requires browsers installed)
321
+ SE_CLI_E2E=1 SE_CLI_TEST_CHROME=1 npx vitest run tests/integration/
322
+ ```
323
+
324
+ ### Project Structure
325
+
326
+ ```
327
+ src/
328
+ ├── cli.ts # CLI entry point
329
+ ├── program.ts # Command routing
330
+ ├── session.ts # Daemon spawn + RPC client
331
+ ├── registry.ts # Session file management
332
+ ├── output.ts # Output formatting
333
+ ├── protocol.ts # Message types
334
+ ├── minimist.ts # Argv parser
335
+ ├── config.ts # Paths and hashing
336
+ ├── response.ts # Response serialization
337
+ ├── snapshot/
338
+ │ └── aria-snapshot.ts # Injected JS script
339
+ └── daemon/
340
+ ├── server.ts # Daemon socket server
341
+ ├── backend.ts # Tool dispatcher
342
+ └── tools/ # Tool handlers (17 tools)
343
+ ```
344
+
345
+ ## Browser Support
346
+
347
+ | Browser | Headless | Headed | CDP Attach |
348
+ |---------|----------|--------|------------|
349
+ | Chrome | ✅ | ✅ | ✅ |
350
+ | Edge | ✅ | ✅ | ✅ |
351
+ | Firefox | ✅ | ✅ | ❌ |
352
+
353
+ ## Comparison with playwright-cli
354
+
355
+ | Feature | playwright-cli | se-cli |
356
+ |---------|---------------|--------------|
357
+ | Aria snapshot | Built-in mature | Self-written ~80% coverage |
358
+ | Ref engine | Native `aria-ref` selector | `data-se-ref` attribute |
359
+ | iframe support | Full | Placeholder (v0.3) |
360
+ | Shadow DOM | Full | Placeholder (v0.3) |
361
+ | Test runner attach | Yes (Playwright test) | No (v0.7 exploratory) |
362
+ | Tracing | Full | Not planned |
363
+ | Multi-browser | Chromium only | Chrome + Edge + Firefox |
364
+ | Real Safari | No | Possible via Safari driver |
365
+
366
+ ## Roadmap
367
+
368
+ - **v0.2**: Storage management, tab management, `install --skills`
369
+ - **v0.3**: iframe recursive snapshot, Shadow DOM recursion
370
+ - **v0.4**: Network route mock, console logs, highlight
371
+ - **v0.5**: Code recording mode, role-based locators
372
+ - **v0.6**: Dashboard, browser extension attach
373
+ - **v0.7**: Test runner integration (exploratory)
374
+
375
+ See [docs/spec.md](docs/spec.md) for full roadmap.
376
+
377
+ ## License
378
+
379
+ [Apache License 2.0](LICENSE) - Copyright 2024 alaahong
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const program_1 = require("./program");
5
+ const output_1 = require("./output");
6
+ (0, program_1.main)(process.argv.slice(2)).catch(e => {
7
+ if (e instanceof output_1.CliError) {
8
+ process.stderr.write(e.message + '\n');
9
+ process.exit(1);
10
+ }
11
+ process.stderr.write(`Error: ${e.message}\n`);
12
+ process.exit(1);
13
+ });
14
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AACA,uCAAiC;AACjC,qCAAoC;AACpC,IAAA,cAAI,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACpC,IAAI,CAAC,YAAY,iBAAQ,EAAE,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const defaultSessionName = "default";
2
+ export declare function userHash(): string;
3
+ export declare function workspaceHash(workspaceDir: string): string;
4
+ export declare function makeSocketPath(wsHash: string, sessionName: string): string;
5
+ export declare function baseDaemonDir(): string;
6
+ export declare function sessionFileDir(wsHash: string): string;
7
+ export declare function sessionFilePath(wsHash: string, sessionName: string): string;
8
+ export interface SessionConfig {
9
+ name: string;
10
+ version: string;
11
+ timestamp: number;
12
+ socketPath: string;
13
+ workspaceDir: string;
14
+ persistent: boolean;
15
+ browserName: 'chrome' | 'edge' | 'firefox';
16
+ }
17
+ export declare function outputDir(cwd: string): string;