cctether 0.0.0-stage → 0.3.1

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.
package/src/text.js ADDED
@@ -0,0 +1,291 @@
1
+ // Terminal text for `setup` and `check` (SPEC §8.1): English and Chinese. The other commands are
2
+ // short and technical and stay English-only.
3
+
4
+ export const REPO_URL = 'https://github.com/guchaorui/cctether';
5
+
6
+ const LINKS = {
7
+ en: {
8
+ extension: `${REPO_URL}#install-the-extension`,
9
+ connect: `${REPO_URL}/blob/main/docs/connect.md`,
10
+ },
11
+ zh: {
12
+ extension: `${REPO_URL}/blob/main/README.zh-CN.md#安装插件`,
13
+ connect: `${REPO_URL}/blob/main/docs/connect.zh-CN.md`,
14
+ },
15
+ };
16
+
17
+ const EN = {
18
+ 'setup.title': 'cctether setup',
19
+ 'setup.tagline': 'Let Claude Code use your browser, over your own connection.',
20
+ 'setup.windows': 'cctether doesn’t run on Windows directly. Run it inside WSL instead: see {connect}',
21
+ 'setup.needTty': 'Setup asks a few questions, so run it in a terminal. To run it from a script, pass --yes and say how the browser connects, e.g. --yes --mode https --url wss://browser.example.com/cctether',
22
+ 'setup.tooManyTries': 'Setup stopped: too many answers it couldn’t use. Nothing after this point was changed.',
23
+ 'setup.needUrl': 'With --yes and --mode https, give the address with --url, e.g. --url wss://browser.example.com/cctether',
24
+ 'setup.yes': 'Y/n',
25
+ 'setup.no': 'y/N',
26
+
27
+ 'step.install': 'Install',
28
+ 'install.ok': '{ok} cctether {version} is installed: {path}',
29
+ 'install.checkout': '{ok} Running from a source folder: {path}. Claude Code will run cctether from there, so keep that folder.',
30
+ 'install.npx.ask': 'You’re running cctether through npx, from a temporary folder that npm may clean up. Install it for this user, so Claude Code can keep starting it? This runs: npm install -g cctether@{version}',
31
+ 'install.npx.found': '{ok} Found cctether {version}, already installed: {path}',
32
+ 'install.npx.update': 'cctether {old} is installed at {path}. Update it to {version}? This runs: npm install -g cctether@{version}',
33
+ 'install.running': 'Running: npm install -g cctether@{version}',
34
+ 'install.done': '{ok} Installed cctether {version}: {path}',
35
+ 'install.failed': '{bad} npm install didn’t work (exit code {code}). Its messages are above.',
36
+ 'install.noNpm': '{bad} npm isn’t available here, so cctether can’t install itself. Install Node.js 22 or newer (it comes with npm), then run: npx cctether@latest setup',
37
+ 'install.noInstall': '{bad} You’re running cctether through npx with --no-install. Claude Code and the background service can’t use npx’s temporary copy, so install it first:\n npm install -g cctether\n cctether setup',
38
+ 'install.noWrite': '{bad} You can’t write to npm’s global folder ({dir}), so cctether can’t install itself. Either install it with sudo:\n sudo npm install -g cctether@{version}\n cctether setup\n or tell npm to install into your home folder, then run setup again:\n npm config set prefix ~/.local\n npx cctether@latest setup\n (~/.local/bin must be on your PATH.)',
39
+ 'install.declined': 'Setup needs cctether installed. Install it with `npm install -g cctether`, then run `cctether setup`.',
40
+ 'install.notOnPath': '{warn} {dir} isn’t on your PATH, so typing `cctether` won’t work in a new terminal yet. Claude Code uses the full path, so cctether works anyway. To fix it, add this line to your shell profile (~/.bashrc or ~/.zshrc):\n export PATH="{dir}:$PATH"',
41
+
42
+ 'step.key': 'Key',
43
+ 'key.created': '{ok} Made a new key (fingerprint {fp}), saved in {path}',
44
+ 'key.exists': '{ok} Using the existing key (fingerprint {fp}) from {path}',
45
+
46
+ 'step.mode': 'How will your browser reach this computer?',
47
+ 'mode.local': 'Chrome runs on this computer',
48
+ 'mode.ssh': 'Through an SSH tunnel, from the computer Chrome runs on',
49
+ 'mode.https': 'Over the internet, through HTTPS (your own domain with Caddy, Cloudflare Tunnel or another reverse proxy)',
50
+ 'mode.choose': 'Choose 1–3',
51
+ 'mode.invalid': 'Type 1, 2 or 3.',
52
+ 'mode.local.note': 'The extension will connect to {url}.',
53
+ 'mode.ssh.note': 'The extension will connect to {url}.\nOn the computer Chrome runs on, add this line under this server’s entry in ~/.ssh/config:\n LocalForward {port} 127.0.0.1:{port}\nor connect with: ssh -L {port}:127.0.0.1:{port} <this server>\nThe browser can only reach cctether while that SSH connection is open.',
54
+ 'mode.https.ask': 'Address the browser will connect to, e.g. wss://browser.example.com/cctether',
55
+ 'mode.https.invalid': 'It must start with wss://, for example wss://browser.example.com/cctether',
56
+ 'mode.https.addedPath': 'Using {url} (added the path /cctether).',
57
+ 'mode.https.otherPath': '{warn} cctether only answers at the path /cctether, so your proxy must rewrite {path} to /cctether (the Caddy example below does).',
58
+ 'mode.https.proxy': 'Your reverse proxy must forward {url} to 127.0.0.1:{port}, with WebSockets allowed. With Caddy, this is the whole site block (/etc/caddy/Caddyfile):',
59
+ 'mode.https.more': 'Cloudflare Tunnel, nginx and others: {connect}',
60
+
61
+ 'step.service': 'Keep it running',
62
+ 'service.ask.remote': 'Install a background service, so the browser stays connected even when Claude Code isn’t running? (Recommended)',
63
+ 'service.ask.local': 'Install a background service? Not needed for this setup: cctether starts by itself when Claude Code uses it.',
64
+ 'service.auto': '{ok} cctether starts by itself when Claude Code uses it.',
65
+ 'service.mac': '{ok} cctether starts by itself when Claude Code uses it. (A background service for macOS isn’t included yet.)',
66
+ 'service.noSystemd': '{ok} cctether starts by itself when Claude Code uses it. (systemd isn’t available for this user, so no background service.)',
67
+ 'service.overwrite': '{path} already exists and is different from what setup would write. Replace it?',
68
+ 'service.otherDir': '{path} runs cctether with the settings in {dir}. Replace it with one for {current}? (The browser paired with the other settings would stop connecting.)',
69
+ 'service.kept': '{ok} Kept your own {path}',
70
+ 'service.ok': '{ok} Background service installed and running (systemd user service “cctether”)',
71
+ 'service.failed': '{bad} The background service didn’t start: {detail}\n Its log: journalctl --user -u cctether',
72
+ 'service.linger.ok': '{ok} It starts when the computer boots, even if you don’t log in',
73
+ 'service.linger.enabled': '{ok} Turned on starting at boot without logging in (loginctl enable-linger)',
74
+ 'service.linger.need': '{warn} Right now it only runs while you’re logged in. To start it at boot, run:\n sudo loginctl enable-linger {user}',
75
+ 'service.skipped': '{ok} No background service. cctether starts by itself when Claude Code uses it.',
76
+
77
+ 'step.claude': 'Claude Code',
78
+ 'claude.added': '{ok} Added cctether to Claude Code, for all your projects. Claude Code sessions that are already open need a restart to see it.',
79
+ 'claude.same': '{ok} Already added to Claude Code',
80
+ 'claude.replace': 'Claude Code already has a server called “cctether” that runs:\n {old}\n Replace it with:\n {new}',
81
+ 'claude.kept': '{ok} Kept the existing “cctether” server in Claude Code',
82
+ 'claude.keptYes': '{warn} Claude Code already has a different “cctether” server:\n {old}\n Kept it: --yes doesn’t replace it. To use this one instead, run setup again without --yes.',
83
+ 'claude.failed': '{bad} `claude mcp add` didn’t work: {detail}',
84
+ 'claude.skipped': '{ok} Skipped. To add it later:\n {cmd}',
85
+ 'claude.mdAsk': 'Should Claude use cctether by itself whenever a task needs a browser? This adds a short note to {path}.',
86
+ 'claude.mdAdded': '{ok} Added a note to {path}: Claude will use cctether whenever a task needs a browser. To undo it, delete the whole note, including its two “cctether” marker lines.',
87
+ 'claude.mdAmbiguous': '{warn} {path} has “cctether” marker lines that don’t form one complete note, so setup left the file alone. Fix or remove them, then run setup again.',
88
+ 'claude.mdReadOnly': 'the file is read-only',
89
+ 'claude.mdUpdated': '{ok} Updated the cctether note in {path}',
90
+ 'claude.mdSame': '{ok} {path} already tells Claude to use cctether for browser tasks',
91
+ 'claude.mdDeclined': '{ok} No note added. Claude uses cctether when you ask it to.',
92
+ 'claude.mdHint': '{dot} Claude uses cctether when you ask it to. To have it do that by itself for every browser task, run setup again with --claude-md.',
93
+ 'claude.mdFailed': '{warn} Couldn’t write {path}: {detail}',
94
+ 'claude.mdComment': 'added by `cctether setup`. To undo, delete this whole note including both marker lines. Edits inside it are replaced when setup runs again.',
95
+ 'claude.mdBody': '## Browser (cctether)\n\nWhen a task needs a web browser (opening or checking a web page, testing a website or a browser extension, reading a page’s console or network requests), use the cctether tools (`mcp__cctether__*`). They work in the user’s own Chrome, in the tabs of its “cctether” tab group: tabs you open join it; ask the user to share any other tab you need. If cctether says no browser is connected, ask the user to check it rather than quietly switching to a different browser tool.',
96
+ 'claude.missing': '{warn} Claude Code (the `claude` command) isn’t on this computer’s PATH. Add cctether to Claude Code later with:\n {cmd}\n Other MCP clients: add a stdio server with this command:\n {json}',
97
+
98
+ 'step.check': 'Check',
99
+ 'check.title': 'cctether check',
100
+ 'check.startFailed': '{bad} The cctether service didn’t start. To see why, run: cctether daemon',
101
+ 'check.started': '{ok} Started the cctether service',
102
+ 'check.restarted': '{ok} Restarted the cctether service to use version {version}',
103
+ 'check.service.down': '{bad} The cctether service isn’t running. It starts by itself when Claude Code uses cctether. To start it now: {how}',
104
+ 'check.service.up': '{ok} The cctether service is running (version {version}, process {pid})',
105
+ 'check.service.old': '{warn} The running service is version {running}, but this is {version}. Restart it to update: {how}',
106
+ 'check.service.port': '{warn} The running service uses port {running}, but the settings say {port}. Restart it: {how}',
107
+ 'check.notSetUp': '{bad} Not set up yet. Run: cctether setup',
108
+ 'check.ok.local': '{ok} {url} answers, and it’s this computer’s cctether',
109
+ 'check.ok.public': '{ok} {url} reaches this computer’s cctether',
110
+ 'check.fail': '{bad} {url}: {why}',
111
+ 'check.why.dns': 'can’t find the address {host}. Check the domain’s DNS record.',
112
+ 'check.why.refused': 'nothing is accepting connections at {host}:{port}.',
113
+ 'check.why.refusedLocal': 'nothing is accepting connections at {host}:{port}. Is the cctether service running?',
114
+ 'check.why.timeout': 'no answer. A firewall may be blocking port {port}, or the address points to the wrong computer.',
115
+ 'check.why.tls': 'the HTTPS certificate isn’t valid ({detail}). Browsers will refuse it too.',
116
+ 'check.why.http': 'the web server answered “HTTP {status}” instead of connecting. Check that the reverse proxy forwards the path {path} to 127.0.0.1:{port}, with WebSockets allowed.',
117
+ 'check.why.http502': 'the reverse proxy answered, but couldn’t reach cctether at 127.0.0.1:{port} (HTTP {status}). Is the cctether service running, and is the port right?',
118
+ 'check.why.wrong_server': 'it reaches a cctether service, but not this one: that one has a different key. Check where the domain points.',
119
+ 'check.why.not_cctether': 'something answered, but it isn’t cctether.',
120
+ 'check.why.origin_rejected': 'the service refused the extension ID {id}. Check "extensionIds" in config.json.',
121
+ 'check.why.rate_limited': 'the service is refusing this computer for a few minutes after several failed attempts. Try again in 5 minutes.',
122
+ 'check.why.update_server': 'the cctether there is older than this one. Update it.',
123
+ 'check.why.update_extension': 'the cctether there is newer than this one. Update this one.',
124
+ 'check.why.closed': 'the connection closed before cctether answered{detail}.',
125
+ 'check.why.error': 'couldn’t connect ({detail}).',
126
+ 'check.hairpin': 'This test runs from this computer. A few cloud servers can’t reach their own public address: if the test fails here but the extension connects, all is well.',
127
+ 'check.later': 'That’s expected if the reverse proxy isn’t set up yet. Once it is, run: cctether check',
128
+ 'check.browser.connected': '{ok} A browser is connected: {browser}, extension {extension}',
129
+ 'check.browser.none': '{dot} No browser is connected right now',
130
+
131
+ 'final.title': 'This computer is ready. Now the browser:',
132
+ 'final.titleProblem': 'Something above needs fixing (marked ✗). Once it’s fixed, the browser part is:',
133
+ 'final.step1': 'Install the cctether extension in Chrome: {extension}',
134
+ 'final.step2': 'Open its settings and paste this connection code:',
135
+ 'final.step2.hidden': 'Open its settings and paste the connection code. It isn’t printed here because this isn’t a terminal: run `cctether pair` in a terminal to see it.',
136
+ 'final.secret': 'Keep the code secret: anyone who has it can control this browser connection.',
137
+ 'final.again': '`cctether pair` shows it again. If it leaks, `cctether rotate` makes a new key.',
138
+ 'final.restart': 'Then restart Claude Code (if it’s open) and ask it to use the browser.',
139
+ };
140
+
141
+ const ZH = {
142
+ 'setup.title': 'cctether 安装向导',
143
+ 'setup.tagline': '让 Claude Code 用上你的浏览器,走你自己的连接。',
144
+ 'setup.windows': 'cctether 不能直接在 Windows 上运行,请在 WSL 里运行。说明见:{connect}',
145
+ 'setup.needTty': '安装向导要问几个问题,请在终端里运行。要在脚本里运行,请加上 --yes,并说明浏览器怎么连,比如:--yes --mode https --url wss://browser.example.com/cctether',
146
+ 'setup.tooManyTries': '安装向导停下了:太多回答用不了。后面的步骤都没有动。',
147
+ 'setup.needUrl': '用了 --yes 和 --mode https,就要用 --url 给出地址,比如 --url wss://browser.example.com/cctether',
148
+ 'setup.yes': 'Y/n',
149
+ 'setup.no': 'y/N',
150
+
151
+ 'step.install': '安装',
152
+ 'install.ok': '{ok} cctether {version} 已经装好:{path}',
153
+ 'install.checkout': '{ok} 正在从源码目录运行:{path}。Claude Code 会从这里启动 cctether,这个文件夹请别删。',
154
+ 'install.npx.ask': '你是用 npx 运行的,程序在 npm 的临时文件夹里,可能会被清掉。要把 cctether 装到当前用户下,让 Claude Code 以后都能启动它吗?会运行:npm install -g cctether@{version}',
155
+ 'install.npx.found': '{ok} 找到已经装好的 cctether {version}:{path}',
156
+ 'install.npx.update': '已经装了 cctether {old}({path})。要更新到 {version} 吗?会运行:npm install -g cctether@{version}',
157
+ 'install.running': '正在运行:npm install -g cctether@{version}',
158
+ 'install.done': '{ok} 装好了 cctether {version}:{path}',
159
+ 'install.failed': '{bad} npm install 没成功(退出码 {code}),原因见上面的输出。',
160
+ 'install.noNpm': '{bad} 这里没有 npm,cctether 没法自己装上。请先装 Node.js 22 或更新的版本(自带 npm),再运行:npx cctether@latest setup',
161
+ 'install.noInstall': '{bad} 你是用 npx 运行的,又加了 --no-install。Claude Code 和后台服务用不了 npx 的临时副本,请先装好:\n npm install -g cctether\n cctether setup',
162
+ 'install.noWrite': '{bad} 你没有 npm 全局文件夹({dir})的写权限,cctether 没法自己装上。两种办法任选一种。用 sudo 装:\n sudo npm install -g cctether@{version}\n cctether setup\n 或者让 npm 装到你的主目录下,再运行一次安装向导:\n npm config set prefix ~/.local\n npx cctether@latest setup\n (~/.local/bin 要在 PATH 里。)',
163
+ 'install.declined': '安装向导需要先装好 cctether。请运行 `npm install -g cctether`,再运行 `cctether setup`。',
164
+ 'install.notOnPath': '{warn} {dir} 不在 PATH 里,所以新开的终端里还不能直接敲 `cctether`。Claude Code 用的是完整路径,不受影响。要修好,把下面这行加到 shell 的配置文件(~/.bashrc 或 ~/.zshrc):\n export PATH="{dir}:$PATH"',
165
+
166
+ 'step.key': '密钥',
167
+ 'key.created': '{ok} 生成了新密钥(指纹 {fp}),存在 {path}',
168
+ 'key.exists': '{ok} 沿用已有的密钥(指纹 {fp}),在 {path}',
169
+
170
+ 'step.mode': '浏览器怎么连到这台电脑?',
171
+ 'mode.local': 'Chrome 就在这台电脑上',
172
+ 'mode.ssh': '从 Chrome 那台电脑经 SSH 隧道连过来',
173
+ 'mode.https': '经公网走 HTTPS(自己的域名,加上 Caddy、Cloudflare 隧道或别的反向代理)',
174
+ 'mode.choose': '选 1–3',
175
+ 'mode.invalid': '请输入 1、2 或 3。',
176
+ 'mode.local.note': '插件会连到 {url}。',
177
+ 'mode.ssh.note': '插件会连到 {url}。\n在 Chrome 那台电脑的 ~/.ssh/config 里,这台服务器那一段下面加一行:\n LocalForward {port} 127.0.0.1:{port}\n或者这样连:ssh -L {port}:127.0.0.1:{port} <这台服务器>\n只有这条 SSH 连接开着的时候,浏览器才连得上 cctether。',
178
+ 'mode.https.ask': '浏览器要连的地址,比如 wss://browser.example.com/cctether',
179
+ 'mode.https.invalid': '要以 wss:// 开头,比如 wss://browser.example.com/cctether',
180
+ 'mode.https.addedPath': '用 {url}(补上了路径 /cctether)。',
181
+ 'mode.https.otherPath': '{warn} cctether 只认路径 /cctether,所以反向代理要把 {path} 改写成 /cctether(下面的 Caddy 示例已经写上了)。',
182
+ 'mode.https.proxy': '反向代理要把 {url} 转给 127.0.0.1:{port},并且允许 WebSocket。用 Caddy 的话,整段配置就是这些(/etc/caddy/Caddyfile):',
183
+ 'mode.https.more': 'Cloudflare 隧道、nginx 等其他做法见:{connect}',
184
+
185
+ 'step.service': '保持运行',
186
+ 'service.ask.remote': '要装成后台服务吗?这样没开 Claude Code 的时候,浏览器也能一直连着。(推荐)',
187
+ 'service.ask.local': '要装成后台服务吗?这种连法用不着:Claude Code 用到 cctether 时会自己启动它。',
188
+ 'service.auto': '{ok} Claude Code 用到 cctether 时会自己启动它。',
189
+ 'service.mac': '{ok} Claude Code 用到 cctether 时会自己启动它。(macOS 的后台服务暂时还没有。)',
190
+ 'service.noSystemd': '{ok} Claude Code 用到 cctether 时会自己启动它。(当前用户用不了 systemd,所以不装后台服务。)',
191
+ 'service.overwrite': '{path} 已经存在,和安装向导要写的内容不一样。要替换吗?',
192
+ 'service.otherDir': '{path} 运行的 cctether 用的是 {dir} 里的设置。要换成用 {current} 的吗?(用原来那套设置配对的浏览器就会连不上。)',
193
+ 'service.kept': '{ok} 保留你自己的 {path}',
194
+ 'service.ok': '{ok} 后台服务装好了,正在运行(systemd 用户服务「cctether」)',
195
+ 'service.failed': '{bad} 后台服务没能启动:{detail}\n 看日志:journalctl --user -u cctether',
196
+ 'service.linger.ok': '{ok} 开机就会启动,不用登录',
197
+ 'service.linger.enabled': '{ok} 已打开「开机不用登录就启动」(loginctl enable-linger)',
198
+ 'service.linger.need': '{warn} 现在只有你登录着的时候它才运行。要开机就启动,请运行:\n sudo loginctl enable-linger {user}',
199
+ 'service.skipped': '{ok} 不装后台服务。Claude Code 用到 cctether 时会自己启动它。',
200
+
201
+ 'step.claude': 'Claude Code',
202
+ 'claude.added': '{ok} 已把 cctether 加到 Claude Code,所有项目都能用。已经开着的 Claude Code 要重开一次才能看到。',
203
+ 'claude.same': '{ok} Claude Code 里已经加好了',
204
+ 'claude.replace': 'Claude Code 里已经有一个叫「cctether」的服务,运行的是:\n {old}\n 要换成:\n {new}',
205
+ 'claude.kept': '{ok} 保留 Claude Code 里原来的「cctether」',
206
+ 'claude.keptYes': '{warn} Claude Code 里已经有一个不一样的「cctether」:\n {old}\n 保留了它:用了 --yes 就不会替换。想换成这个,请不加 --yes 再运行一次安装向导。',
207
+ 'claude.failed': '{bad} `claude mcp add` 没成功:{detail}',
208
+ 'claude.skipped': '{ok} 跳过。以后要加:\n {cmd}',
209
+ 'claude.mdAsk': '以后任务需要用到浏览器时,要 Claude 自己就用 cctether 吗?会在 {path} 里加一小段说明。',
210
+ 'claude.mdAdded': '{ok} 已在 {path} 里加了一段说明:以后任务需要浏览器时,Claude 会自己用 cctether。想撤销,把这一段连同上下两行「cctether」标记一起删掉。',
211
+ 'claude.mdAmbiguous': '{warn} {path} 里的「cctether」标记行凑不成完整的一段,安装向导没有动这个文件。改好或删掉这些标记,再运行一次安装向导。',
212
+ 'claude.mdReadOnly': '文件是只读的',
213
+ 'claude.mdUpdated': '{ok} 更新了 {path} 里关于 cctether 的说明',
214
+ 'claude.mdSame': '{ok} {path} 里已经写了让 Claude 用 cctether 做浏览器的事',
215
+ 'claude.mdDeclined': '{ok} 没加说明。你让 Claude 用 cctether 时它才会用。',
216
+ 'claude.mdHint': '{dot} 你让 Claude 用 cctether 时它才会用。想让它遇到浏览器的事就自己用,加上 --claude-md 再运行一次安装向导。',
217
+ 'claude.mdFailed': '{warn} 写不了 {path}:{detail}',
218
+ 'claude.mdComment': '由 `cctether setup` 添加。想撤销,把这一段连同上下两行标记一起删掉。在里面改的内容,下次运行安装向导会被换回来。',
219
+ 'claude.mdBody': '## 浏览器(cctether)\n\n任务需要用到浏览器时(打开或检查网页、测试网站或浏览器插件、看页面的控制台或网络请求),用 cctether 的工具(`mcp__cctether__*`)。它们操作的是用户自己的 Chrome,只限「cctether」标签组里的标签页:你新开的标签页会自动进组;需要别的标签页时,请用户共享给你。如果 cctether 说没有浏览器连着,请用户去检查,不要悄悄换用别的浏览器工具。',
220
+ 'claude.missing': '{warn} 这台电脑的 PATH 里找不到 Claude Code(`claude` 命令)。以后可以这样加到 Claude Code:\n {cmd}\n 其他 MCP 客户端:添加一个 stdio 服务,命令是:\n {json}',
221
+
222
+ 'step.check': '检查',
223
+ 'check.title': 'cctether 检查',
224
+ 'check.startFailed': '{bad} cctether 服务没能启动。想看原因,请运行:cctether daemon',
225
+ 'check.started': '{ok} 启动了 cctether 服务',
226
+ 'check.restarted': '{ok} 重启了 cctether 服务,换成 {version} 版',
227
+ 'check.service.down': '{bad} cctether 服务没在运行。Claude Code 用到 cctether 时会自己启动它。现在就启动:{how}',
228
+ 'check.service.up': '{ok} cctether 服务正在运行({version} 版,进程 {pid})',
229
+ 'check.service.old': '{warn} 正在运行的服务是 {running} 版,这里是 {version} 版。重启一下就会更新:{how}',
230
+ 'check.service.port': '{warn} 正在运行的服务用的是 {running} 端口,设置里写的是 {port}。重启一下:{how}',
231
+ 'check.notSetUp': '{bad} 还没装好。请运行:cctether setup',
232
+ 'check.ok.local': '{ok} {url} 有回应,是这台电脑上的 cctether',
233
+ 'check.ok.public': '{ok} {url} 能连到这台电脑上的 cctether',
234
+ 'check.fail': '{bad} {url}:{why}',
235
+ 'check.why.dns': '找不到 {host} 这个地址。请检查域名的 DNS 记录。',
236
+ 'check.why.refused': '{host}:{port} 没有程序在接受连接。',
237
+ 'check.why.refusedLocal': '{host}:{port} 没有程序在接受连接。cctether 服务在运行吗?',
238
+ 'check.why.timeout': '没有回应。可能是防火墙挡了 {port} 端口,或者地址指到了别的电脑。',
239
+ 'check.why.tls': 'HTTPS 证书无效({detail}),浏览器也会拒绝。',
240
+ 'check.why.http': '网站服务器回的是「HTTP {status}」,没有接通。请检查反向代理有没有把路径 {path} 转给 127.0.0.1:{port},并且允许 WebSocket。',
241
+ 'check.why.http502': '反向代理有回应,但连不到 127.0.0.1:{port} 上的 cctether(HTTP {status})。cctether 服务在运行吗?端口对吗?',
242
+ 'check.why.wrong_server': '连到了一个 cctether,但不是这台电脑上的:它的密钥不一样。请检查域名指向哪里。',
243
+ 'check.why.not_cctether': '有程序回应了,但不是 cctether。',
244
+ 'check.why.origin_rejected': '服务拒绝了插件 ID {id}。请检查 config.json 里的 "extensionIds"。',
245
+ 'check.why.rate_limited': '失败次数太多,服务暂时拒绝这台电脑。请 5 分钟后再试。',
246
+ 'check.why.update_server': '那边的 cctether 比这里的旧,请更新它。',
247
+ 'check.why.update_extension': '那边的 cctether 比这里的新,请更新这里的。',
248
+ 'check.why.closed': 'cctether 回应之前连接就断了{detail}。',
249
+ 'check.why.error': '连不上({detail})。',
250
+ 'check.hairpin': '这个检查是从这台电脑自己去连的。少数云服务器连不上自己的公网地址:如果这里失败、插件却连得上,就没问题。',
251
+ 'check.later': '如果反向代理还没配好,这是正常的。配好以后运行:cctether check',
252
+ 'check.browser.connected': '{ok} 有浏览器连着:{browser},插件 {extension}',
253
+ 'check.browser.none': '{dot} 现在没有浏览器连着',
254
+
255
+ 'final.title': '这台电脑这边好了。接下来是浏览器:',
256
+ 'final.titleProblem': '上面有标 ✗ 的地方要先处理。处理好以后,浏览器这边是:',
257
+ 'final.step1': '在 Chrome 里装上 cctether 插件:{extension}',
258
+ 'final.step2': '打开插件的设置页,粘贴这个连接码:',
259
+ 'final.step2.hidden': '打开插件的设置页,粘贴连接码。这里不是终端,所以不显示连接码:请在终端里运行 `cctether pair` 查看。',
260
+ 'final.secret': '连接码要保密:谁拿到它,谁就能控制这条浏览器连接。',
261
+ 'final.again': '`cctether pair` 能再显示一次。万一泄露了,`cctether rotate` 会换一把新密钥。',
262
+ 'final.restart': '然后重开 Claude Code(如果开着的话),让它用浏览器就行。',
263
+ };
264
+
265
+ export const MESSAGES = { en: EN, zh: ZH };
266
+
267
+ /** Pick the language: --lang, else the locale environment variables. */
268
+ export function pickLanguage(flag, env = process.env) {
269
+ if (flag === 'zh' || flag === 'en') return flag;
270
+ const loc = env.LC_ALL || env.LC_MESSAGES || env.LANG || '';
271
+ return /^zh/i.test(loc) ? 'zh' : 'en';
272
+ }
273
+
274
+ /**
275
+ * A text function for one language. Glyphs ({ok}, {bad}, {warn}, {dot}) and links ({extension},
276
+ * {connect}) are filled in automatically; style() colours them when the terminal supports it.
277
+ */
278
+ export function createText(lang, style = {}) {
279
+ const table = MESSAGES[lang] ?? EN;
280
+ const fixed = {
281
+ ok: style.ok ?? '✓',
282
+ bad: style.bad ?? '✗',
283
+ warn: style.warn ?? '!',
284
+ dot: style.dot ?? '·',
285
+ ...LINKS[lang] ?? LINKS.en,
286
+ };
287
+ return (key, vars = {}) => {
288
+ const s = table[key] ?? EN[key] ?? key;
289
+ return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : k in fixed ? fixed[k] : m));
290
+ };
291
+ }
package/src/tools.js ADDED
@@ -0,0 +1,329 @@
1
+ // MCP tool definitions. The browser extension implements each tool with the same name and
2
+ // arguments (extension/background/tools/). Keep names short and descriptions tight: every MCP
3
+ // session pays for these tokens.
4
+
5
+ const tab = { type: 'integer', description: 'Tab id from list_tabs. Default: the current tab.' };
6
+ const ref = { type: 'integer', minimum: 1, description: 'Element number from read_page (interactive mode) or find. Invalid after navigation.' };
7
+ const selector = { type: 'string', minLength: 1, maxLength: 2000, description: 'CSS selector (the first visible match, else the first match).' };
8
+ const selectorFirst = { type: 'string', minLength: 1, maxLength: 2000, description: 'CSS selector (the first match, visible or not).' };
9
+ const x = { type: 'number', description: 'Viewport x in CSS pixels (= screenshot pixels unless the screenshot was scaled).' };
10
+ const y = { type: 'number', description: 'Viewport y in CSS pixels.' };
11
+ const timeout = (def, max) => ({ type: 'integer', minimum: 100, maximum: max, description: `Milliseconds, default ${def}.` });
12
+
13
+ const READ = { readOnlyHint: true, destructiveHint: false, openWorldHint: true };
14
+ const ACT = { readOnlyHint: false, destructiveHint: false, openWorldHint: true };
15
+ const DANGER = { readOnlyHint: false, destructiveHint: true, openWorldHint: true };
16
+
17
+ /** @type {Array<{name: string, title: string, description: string, inputSchema: object, annotations: object, timeoutMs?: (args: object) => number}>} */
18
+ export const TOOLS = [
19
+ {
20
+ name: 'list_tabs',
21
+ title: 'List shared tabs',
22
+ description: 'List the tabs shared with you (the browser\'s "cctether" tab group) and browser info. Only these tabs can be used. To use another page, open it with open_tab, or ask the user to share it (cctether toolbar button → "Share this tab").',
23
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
24
+ annotations: READ,
25
+ },
26
+ {
27
+ name: 'open_tab',
28
+ title: 'Open tab',
29
+ description: 'Open a new tab in the cctether group and make it the current tab. Waits for the page to load.',
30
+ inputSchema: {
31
+ type: 'object',
32
+ properties: {
33
+ url: { type: 'string', maxLength: 8192, description: 'Default about:blank.' },
34
+ active: { type: 'boolean', description: 'Bring the tab to the front. Default false, so the user\'s own browsing is not interrupted.' },
35
+ },
36
+ additionalProperties: false,
37
+ },
38
+ annotations: ACT,
39
+ timeoutMs: () => 35000,
40
+ },
41
+ {
42
+ name: 'close_tab',
43
+ title: 'Close tab',
44
+ description: 'Close a tab in the cctether group.',
45
+ inputSchema: { type: 'object', properties: { tab }, required: ['tab'], additionalProperties: false },
46
+ annotations: DANGER,
47
+ },
48
+ {
49
+ name: 'navigate',
50
+ title: 'Navigate',
51
+ description: 'Load a URL in a tab, or go back / forward / reload. Waits for the page to load.',
52
+ inputSchema: {
53
+ type: 'object',
54
+ properties: {
55
+ url: { type: 'string', maxLength: 8192 },
56
+ action: { type: 'string', enum: ['back', 'forward', 'reload'], description: 'Instead of url.' },
57
+ tab,
58
+ timeout_ms: timeout(30000, 120000),
59
+ },
60
+ additionalProperties: false,
61
+ },
62
+ annotations: ACT,
63
+ timeoutMs: (a) => (a.timeout_ms ?? 30000) + 5000,
64
+ },
65
+ {
66
+ name: 'read_page',
67
+ title: 'Read page',
68
+ description: 'Read the page. mode "text" (default): visible text. "interactive": numbered list of links, buttons, inputs etc. — pass a number as `ref` to click/type/hover/select_option/scroll/screenshot. "html": HTML of `selector` (default body). Long output is split: pass the returned offset to continue.',
69
+ inputSchema: {
70
+ type: 'object',
71
+ properties: {
72
+ mode: { type: 'string', enum: ['text', 'interactive', 'html'] },
73
+ selector: { ...selector, description: 'Limit to this element (CSS selector; the first visible match, or for "html" the first match).' },
74
+ offset: { type: 'integer', minimum: 0, description: 'Character offset to continue from.' },
75
+ max_chars: { type: 'integer', minimum: 500, maximum: 100000, description: 'Default 20000.' },
76
+ tab,
77
+ },
78
+ additionalProperties: false,
79
+ },
80
+ annotations: READ,
81
+ },
82
+ {
83
+ name: 'find',
84
+ title: 'Find elements',
85
+ description: 'Find elements by CSS selector. Returns count, and for each: ref number, tag, text, key attributes, position, visibility.',
86
+ inputSchema: {
87
+ type: 'object',
88
+ properties: {
89
+ selector,
90
+ limit: { type: 'integer', minimum: 1, maximum: 200, description: 'Default 20.' },
91
+ tab,
92
+ },
93
+ required: ['selector'],
94
+ additionalProperties: false,
95
+ },
96
+ annotations: READ,
97
+ },
98
+ {
99
+ name: 'screenshot',
100
+ title: 'Screenshot',
101
+ description: 'Screenshot the visible area (default), the full page, or one element (ref or selector).',
102
+ inputSchema: {
103
+ type: 'object',
104
+ properties: {
105
+ full_page: { type: 'boolean' },
106
+ ref,
107
+ selector,
108
+ format: { type: 'string', enum: ['jpeg', 'png'], description: 'Default jpeg.' },
109
+ quality: { type: 'integer', minimum: 1, maximum: 100, description: 'JPEG quality, default 75.' },
110
+ tab,
111
+ },
112
+ additionalProperties: false,
113
+ },
114
+ annotations: READ,
115
+ },
116
+ {
117
+ name: 'click',
118
+ title: 'Click',
119
+ description: 'Click an element (ref or selector) or a point (x, y) with real mouse events. Scrolls the element into view first.',
120
+ inputSchema: {
121
+ type: 'object',
122
+ properties: {
123
+ ref, selector, x, y,
124
+ button: { type: 'string', enum: ['left', 'right', 'middle'] },
125
+ click_count: { type: 'integer', minimum: 1, maximum: 3, description: '2 = double click.' },
126
+ modifiers: { type: 'array', items: { type: 'string', enum: ['Alt', 'Control', 'Meta', 'Shift'] }, maxItems: 4 },
127
+ tab,
128
+ },
129
+ additionalProperties: false,
130
+ },
131
+ annotations: ACT,
132
+ },
133
+ {
134
+ name: 'type',
135
+ title: 'Type text',
136
+ description: 'Type text into an element (ref or selector; it gets focused first) or into the focused element.',
137
+ inputSchema: {
138
+ type: 'object',
139
+ properties: {
140
+ text: { type: 'string', maxLength: 100000 },
141
+ ref, selector,
142
+ clear: { type: 'boolean', description: 'Delete the existing value first.' },
143
+ submit: { type: 'boolean', description: 'Press Enter afterwards.' },
144
+ tab,
145
+ },
146
+ required: ['text'],
147
+ additionalProperties: false,
148
+ },
149
+ annotations: ACT,
150
+ },
151
+ {
152
+ name: 'press_key',
153
+ title: 'Press key',
154
+ description: 'Press a key or combination, e.g. "Enter", "Escape", "Tab", "ArrowDown", "Control+A", "Meta+Shift+P".',
155
+ inputSchema: {
156
+ type: 'object',
157
+ properties: {
158
+ key: { type: 'string', minLength: 1, maxLength: 100 },
159
+ repeat: { type: 'integer', minimum: 1, maximum: 50 },
160
+ tab,
161
+ },
162
+ required: ['key'],
163
+ additionalProperties: false,
164
+ },
165
+ annotations: ACT,
166
+ },
167
+ {
168
+ name: 'scroll',
169
+ title: 'Scroll',
170
+ description: 'Scroll an element into view (ref or selector), or scroll the page — or the scrollable element under (x, y) — in a direction.',
171
+ inputSchema: {
172
+ type: 'object',
173
+ properties: {
174
+ ref, selector,
175
+ direction: { type: 'string', enum: ['up', 'down', 'left', 'right'] },
176
+ amount: { type: 'integer', minimum: 1, maximum: 100000, description: 'Pixels, default 80% of the viewport.' },
177
+ x, y,
178
+ tab,
179
+ },
180
+ additionalProperties: false,
181
+ },
182
+ annotations: ACT,
183
+ },
184
+ {
185
+ name: 'hover',
186
+ title: 'Hover',
187
+ description: 'Move the mouse over an element (ref or selector) or a point (x, y).',
188
+ inputSchema: { type: 'object', properties: { ref, selector, x, y, tab }, additionalProperties: false },
189
+ annotations: ACT,
190
+ },
191
+ {
192
+ name: 'select_option',
193
+ title: 'Select option',
194
+ description: 'Choose option(s) in a <select>, matching each value against option value, then visible label.',
195
+ inputSchema: {
196
+ type: 'object',
197
+ properties: {
198
+ ref, selector: selectorFirst,
199
+ value: { type: ['string', 'array'], items: { type: 'string' }, maxItems: 100, description: 'One value, or several for a multi-select.' },
200
+ tab,
201
+ },
202
+ required: ['value'],
203
+ additionalProperties: false,
204
+ },
205
+ annotations: ACT,
206
+ },
207
+ {
208
+ name: 'wait_for',
209
+ title: 'Wait for',
210
+ description: 'Wait until text appears on the page, or an element matching selector appears (with gone: true, until it disappears).',
211
+ inputSchema: {
212
+ type: 'object',
213
+ properties: {
214
+ text: { type: 'string', minLength: 1, maxLength: 1000 },
215
+ selector,
216
+ gone: { type: 'boolean' },
217
+ timeout_ms: timeout(10000, 120000),
218
+ tab,
219
+ },
220
+ additionalProperties: false,
221
+ },
222
+ annotations: READ,
223
+ timeoutMs: (a) => (a.timeout_ms ?? 10000) + 5000,
224
+ },
225
+ {
226
+ name: 'evaluate',
227
+ title: 'Run JavaScript',
228
+ description: 'Run JavaScript in the page and return the result as JSON. Works like the DevTools console: the value of the last expression is returned, top-level await is allowed. world "page" (default) shares globals with the page; "isolated" sees only the DOM.',
229
+ inputSchema: {
230
+ type: 'object',
231
+ properties: {
232
+ expression: { type: 'string', minLength: 1, maxLength: 200000 },
233
+ world: { type: 'string', enum: ['page', 'isolated'] },
234
+ timeout_ms: timeout(10000, 120000),
235
+ tab,
236
+ },
237
+ required: ['expression'],
238
+ additionalProperties: false,
239
+ },
240
+ annotations: DANGER,
241
+ timeoutMs: (a) => (a.timeout_ms ?? 10000) + 5000,
242
+ },
243
+ {
244
+ name: 'console_messages',
245
+ title: 'Console messages',
246
+ description: 'Read console messages and uncaught errors of a tab, including ones from extension content scripts (labelled with the extension name). Newest last.',
247
+ inputSchema: {
248
+ type: 'object',
249
+ properties: {
250
+ level: { type: 'string', enum: ['error', 'warning', 'all'], description: '"error": errors only; "warning": warnings and errors; default "all".' },
251
+ pattern: { type: 'string', maxLength: 500, description: 'Only messages containing this text (case-insensitive).' },
252
+ limit: { type: 'integer', minimum: 1, maximum: 500, description: 'Default 50 (the newest).' },
253
+ clear: { type: 'boolean', description: 'Clear the buffer after reading.' },
254
+ tab,
255
+ },
256
+ additionalProperties: false,
257
+ },
258
+ annotations: READ,
259
+ },
260
+ {
261
+ name: 'network_requests',
262
+ title: 'Network requests',
263
+ description: 'List network requests of a tab, newest last. With id: headers and body of one request.',
264
+ inputSchema: {
265
+ type: 'object',
266
+ properties: {
267
+ id: { type: 'integer', minimum: 1, description: 'Request number from the list.' },
268
+ pattern: { type: 'string', maxLength: 500, description: 'Only URLs containing this text.' },
269
+ type: { type: 'string', enum: ['document', 'xhr', 'fetch', 'script', 'stylesheet', 'image', 'font', 'media', 'websocket', 'other'] },
270
+ failed: { type: 'boolean', description: 'Only failed requests and HTTP errors (status >= 400).' },
271
+ limit: { type: 'integer', minimum: 1, maximum: 500, description: 'Default 50 (the newest).' },
272
+ clear: { type: 'boolean', description: 'Clear the list after reading.' },
273
+ tab,
274
+ },
275
+ additionalProperties: false,
276
+ },
277
+ annotations: READ,
278
+ },
279
+ {
280
+ name: 'handle_dialog',
281
+ title: 'Handle dialog',
282
+ description: 'Accept or dismiss the alert / confirm / prompt open in a tab. While one is open, the page is frozen and other tools on it fail.',
283
+ inputSchema: {
284
+ type: 'object',
285
+ properties: {
286
+ accept: { type: 'boolean' },
287
+ text: { type: 'string', maxLength: 10000, description: 'Answer for a prompt.' },
288
+ tab,
289
+ },
290
+ required: ['accept'],
291
+ additionalProperties: false,
292
+ },
293
+ annotations: ACT,
294
+ },
295
+ {
296
+ name: 'list_extensions',
297
+ title: 'List extensions',
298
+ description: 'List installed browser extensions. "unpacked" ones are loaded from a folder (in development).',
299
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
300
+ annotations: READ,
301
+ },
302
+ {
303
+ name: 'reload_extension',
304
+ title: 'Reload extension',
305
+ description: 'Reload an extension by turning it off and on. Picks up changed code (background, content scripts, pages) but NOT manifest.json changes — for those, ask the user to click the reload button on chrome://extensions. Reload open tabs to get new content scripts.',
306
+ inputSchema: {
307
+ type: 'object',
308
+ properties: { id: { type: 'string', pattern: '^[a-p]{32}$' } },
309
+ required: ['id'],
310
+ additionalProperties: false,
311
+ },
312
+ annotations: DANGER,
313
+ },
314
+ ];
315
+
316
+ export const TOOL_NAMES = TOOLS.map((t) => t.name);
317
+ export const DEFAULT_TIMEOUT_MS = 30000;
318
+
319
+ export function toolTimeoutMs(name, args) {
320
+ const t = TOOLS.find((x) => x.name === name);
321
+ return t?.timeoutMs ? t.timeoutMs(args) : DEFAULT_TIMEOUT_MS;
322
+ }
323
+
324
+ /** Tool list as sent in MCP tools/list. */
325
+ export function mcpToolList() {
326
+ return TOOLS.map(({ name, title, description, inputSchema, annotations }) => ({
327
+ name, title, description, inputSchema, annotations: { title, ...annotations },
328
+ }));
329
+ }