@yanzc/claude-pro 0.10.0 → 0.12.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.
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  ⎿ PASS
16
16
  ```
17
17
 
18
- > **认证**:`/connect` 里粘贴各家的 API Key。7bit.fun 的 Key 保存在 `~/.claude-pro/gateway.json`,其他厂商的保存在 `~/.claude-pro/providers.json`。远程会话发布只在连接了 7bit.fun 时才有。
18
+ > **认证**:`/connect` 里粘贴各家的 API Key。7bit.fun 的 Key 保存在 `~/.claude-pro/gateway.json`,其他厂商的保存在 `~/.claude-pro/providers.json`。跨电脑互发任务和通讯录只在连接了 7bit.fun 时才有。
19
19
 
20
20
  ## 安装与运行
21
21
 
@@ -133,7 +133,7 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://7bit.fun
133
133
 
134
134
  会话中 `/config` 默认只显示这五项,`/config advanced` 查看高级项;`/config set model sonnet` 等同于 CLI 的 `config set`。普通设置写顶层,高级设置写 `env`。`/config set/unset` 保留 `--project`、`--local`,分别修改项目共享设置或本地设置。`/model`、`/effort` 仍会记住选择;`--model`、`--effort` 可覆盖本次启动。
135
135
 
136
- 设置文件从低到高:`~/.claude-pro/settings.json`、项目 `.claude-pro/settings.json`、`.claude-pro/settings.local.json`。高级项仍兼容进程环境变量(高于设置文件),包括网关地址、远程会话、输出/thinking 预算、缓存总开关、保活、网络重试、工具路径、验证、自动记忆/话题标题和 Trace 开关;普通设置不从进程环境读取。旧 `settings.json.env` 中的 `CLAUDE_PRO_GATEWAY_MODEL`、`CLAUDE_CODE_EFFORT_LEVEL`、`CLAUDE_CODE_PROMPT_CACHE_TTL`、`CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL` 只作为兼容别名读取,同文件顶层新字段优先;用 `config set` 或 `/config set` 设置旧别名,会改写顶层新字段并移除同文件旧别名。没有 `--provider` 或 `CLAUDE_PRO_PROVIDER` 配置:用哪家由模型名决定(`/model`、`--model deepseek/deepseek-v4-pro`、设置 `model`)。
136
+ 设置文件从低到高:`~/.claude-pro/settings.json`、项目 `.claude-pro/settings.json`、`.claude-pro/settings.local.json`。高级项仍兼容进程环境变量(高于设置文件),包括网关地址、是否连网关、输出/thinking 预算、缓存总开关、保活、网络重试、工具路径、验证、自动记忆/话题标题和 Trace 开关;普通设置不从进程环境读取。旧 `settings.json.env` 中的 `CLAUDE_PRO_GATEWAY_MODEL`、`CLAUDE_CODE_EFFORT_LEVEL`、`CLAUDE_CODE_PROMPT_CACHE_TTL`、`CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL` 只作为兼容别名读取,同文件顶层新字段优先;用 `config set` 或 `/config set` 设置旧别名,会改写顶层新字段并移除同文件旧别名。没有 `--provider` 或 `CLAUDE_PRO_PROVIDER` 配置:用哪家由模型名决定(`/model`、`--model deepseek/deepseek-v4-pro`、设置 `model`)。
137
137
 
138
138
  ## 系统提示词
139
139
 
@@ -144,7 +144,7 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://7bit.fun
144
144
  每次请求都要把整个对话发给模型,用 Anthropic 的提示词缓存,重复的历史按缓存价(十分之一)计费,不用配置:
145
145
 
146
146
  - 网关对话默认用 1 小时缓存(停顿一会儿回来不用整段重写);子 agent、压缩等默认用 5 分钟。顶层 `promptCacheTtl`、`subagentPromptCacheTtl` 修改时长;`DISABLE_PROMPT_CACHING` 总开关见 `claude-pro config list --advanced`。旧的强制 5 分钟、启用 1 小时和按模型关闭缓存的变量不再生效。
147
- - 页脚的 `◷ 12m` 是缓存还能保留多久;变红表示已过期,下一条消息会把整个对话重新写入缓存。`/cost` 显示命中率和没命中的原因。
147
+ - `/cost` 显示缓存还能保留多久、命中率和没命中的原因;缓存过期后发下一条消息会把整个对话重新写入缓存。
148
148
  - 缓存还热时 `/model`、`/effort` 会先确认(切换会让缓存失效);离开一个多小时回来时,清掉较早的工具结果,少重写一些。
149
149
  - 人不在时自动保温(Claude 模型):缓存到期前 5 分钟把上一个请求重发一次,只要 1 个输出 token。读缓存会让它再保留一小时,花费是整段重写的 1/40(Opus 上 15 万 token 的对话:约 $0.03,重写约 $1.20)。一次停顿最多保温 8 小时,`CLAUDE_PRO_CACHE_KEEPALIVE_HOURS` 可以改(0 关闭)。`/cost` 显示刷新次数和花费。GPT 模型不需要:网关上的 GPT 缓存停顿几个小时后通常还在。
150
150
 
@@ -165,11 +165,11 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://7bit.fun
165
165
 
166
166
  网关账户的 5 小时和每周限额用完时,不报错停下,而是暂停并显示倒计时(`✻ 5-hour limit reached · resumes at 23:41 (in 2h 13m)`,Esc 可取消),到重置时间重发同一个请求,任务接着做完。暂停期间可以直接输入 `/model <另一个模型>`(暂停时唯一能在任务进行中执行的命令):暂停立即结束,这个请求改发给新模型,不用先按 Esc 再说"继续"。暂停超过一小时、提示词缓存已过期时,重发前会先清掉旧的工具结果和旧工具调用里的大段文本(和离开一小时后回来时一样),避免把整段对话原样重写进缓存。网关过载(529)同样先重试、再暂停等它恢复。最多等 6 小时(`CLAUDE_PRO_RATE_LIMIT_MAX_WAIT_MS`,`0` = 不等直接报错);重置时间更远(比如周限额还有几天)时直接报错,并写明几点重置。
167
167
 
168
- ## 终端标题、页脚与窗口缩放
168
+ ## 终端标题、状态行与窗口缩放
169
169
 
170
170
  - **终端标题**:标签/窗口标题显示 `✳ <会话标题> | <目录> · <模型> · <effort>`(会话标题是**当前话题**:每次发消息后,后台让小模型(haiku)判断是否换了话题,换了就生成一个简短标题;"继续"之类的消息不会改标题。话题记在会话文件里,`/resume`、重启后仍在,`/resume` 列表也显示它。旧会话没有话题时,恢复时按最近一条提问生成。还没生成时显示第一条提问。最多 40 字,保证模型和 effort 不被窄标签截掉。`CLAUDE_PRO_DISABLE_TOPIC_TITLE=1` 关闭,省掉每条消息一次的小请求)。忙碌时前缀在 `⠂`/`⠐` 之间闪动,限流暂停时变 `⏸`,退出时恢复进入前的标题。`/model`、`/effort`、`/clear`、`/resume` 后自动更新。**VS Code**(1.140 起)只对它认得的 AI 命令行(claude/codex/copilot/gemini)把程序设置的标题显示在标签上(`terminal.integrated.tabs.allowAgentCliTitle`,默认开),其余一律显示进程名 `node`;它在 Windows 上靠 `node.exe` 命令行里的 `\claude-code\` 路径段识别它,所以监督进程用 `bin\claude-code\..\claude-pro.js` 启动会话(目录不必存在,Node 自己化简 `..`)。不经过监督进程的启动方式(`CLAUDE_PRO_NO_SUPERVISOR=1`)或 Linux/macOS 上,要在 VS Code 设置里把 `terminal.integrated.tabs.title` 改成 `${sequence}` 才能看到标题。
171
171
  - **用户的提问**:带一条深灰色背景(横跨整个窗口宽度),和回复一眼就能分开。背景条是用当前背景色清除行尾(`\x1b[K`)画出来的,不靠补空格,窗口变宽变窄都正好铺满。
172
- - **页脚**:输入框下方右侧常驻当前模型和 effort(如 `sonnet-5-5 · high`);没发送 effort(auto)或该模型不支持时只显示模型;窄窗口放不下时先让位给"上下文快满"等提示,再不行就不显示。模型前面是**当前对话累计花费**(如 `$1.23 · opus-5-5 · effort high`):按官方价(和网关扣费同一张价目表,含 5 分钟/1 小时缓存写入、长上下文价)把每个请求算进去,子 agent、压缩、话题标题、WebFetch 都算,按 Esc 中断的请求按已读入的输入和估算的已输出部分算;记在会话文件里,重启、`/resume` 后接着累计,`/clear` 从零开始。`/cost` 第一行也显示它,`-p --output-format json` 的结果带本次运行的 `total_cost_usd`。不认识价格的模型(第三方端点的自定义模型)不计;网关上游分组倍率不是 1 的账户以网关流水为准。花费前面是**提示词缓存时钟**:`◷ 12m` 表示对话的缓存估计还能保留 12 分钟(按 5 分钟或 1 小时 TTL 倒数,每次用到缓存的回复重新开始计时);倒数结束后分钟数消失、图标变红,直到下一次回复——这时发下一条消息会把整个对话重新写入缓存,更慢也更贵;压缩之后到下一次回复之前也是红色,因为压缩后的对话还没进缓存。时钟记在会话文件里,重启、`/resume` 后接着显示(压缩后关掉的会话恢复时是冷的);还没有回复报告过缓存用量时不显示。窄窗口先省掉花费,再省掉时钟。
172
+ - **状态行**:终端没有常驻页脚。每次回答结束后打印一行 `✻ Done at 14:05 · worked 1m 3s · $0.12 (total $3.40) · ctx 45k/1M · opus-5-5 max`:完成时间、这一轮用时、这一轮的花费(括号里是对话累计)、上下文用量、模型和 effort。花费按官方价(和网关扣费同一张价目表,含 5 分钟/1 小时缓存写入、长上下文价)把每个请求算进去,子 agent、压缩、话题标题、WebFetch 都算,按 Esc 中断的请求按已读入的输入和估算的已输出部分算;记在会话文件里,重启、`/resume` 后接着累计,`/clear` 从零开始。`/cost` 第一行也显示它,`-p --output-format json` 的结果带本次运行的 `total_cost_usd`。不认识价格的模型(第三方端点的自定义模型)不计;网关上游分组倍率不是 1 的账户以网关流水为准。输入行下面只在需要马上知道时出现一行提示(再按一次 Ctrl-C 退出、本轮结束后重启、正在更新)。
173
173
  - **缩放窗口**:拖动期间不重绘,停下约 80ms 后从左上角整屏绝对重绘一次,输入框不会再留下残影。注意:很短的会话里这次重绘会覆盖终端上方 shell 的内容。
174
174
 
175
175
  ## 自动重启:改了自己的代码马上生效
@@ -177,43 +177,77 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://7bit.fun
177
177
  交互式会话运行在一个很薄的**监督进程**(`src/supervisor.js`,只用 Node 内置模块)之下,所以程序可以自己重启、加载自己刚改过的代码,不需要你退出再启动:
178
178
 
179
179
  - **模型自己重启**:改完 `src/`、`bin/` 里的代码后,模型调用 `Restart` 工具。它先在一个临时进程里把新代码完整启动一遍(所有模块能加载、界面能画出来、工具定义和系统提示词合法)——**启动不起来就不重启**,把错误还给模型去修,修好再调用;通过后在**本回合结束时**重启,对话、待办列表、`/model`、`/effort`、排队的消息、输入框里没发出去的草稿、`/rewind` 检查点都带过去,新进程里模型收到一条"已重启"的提示后接着做(可用 `then` 指定重启后先验证什么)。只在**源码仓库**(有 `.git` 的克隆,包括 `npm link` 到它)里这样做:从 npm 装的副本没有版本控制、下次更新会被覆盖,那里不给模型 `Restart` 工具,系统提示词改成"不要改自己的文件,绕过问题并在最后说明缺陷,方便用户反馈"。
180
- - **改了源码自动重启**:`src/`、`bin/` 下的文件变过,就自动做同样的检查并重启。本会话的回合进行中发生的改动(多半是它自己改的)在回合结束时加载;会话空闲时看到的改动是别处做的(另一个会话在改程序、编辑器),要等源码连续 3 分钟没有再变才加载,页脚会提示,急用可以 `/restart`——否则一个会话每改一步,其余打开的会话都跟着检查、重启一次,加载的还是改到一半的代码。npm 装好的新版本是完整的,不用等。检查不通过只提示错误、不重启。按 Esc 打断的那一回合不会触发。源码自动重启固定开启,旧 `CLAUDE_PRO_AUTO_RESTART` 不再生效。
180
+ - **改了源码自动重启**:`src/`、`bin/` 下的文件变过,就自动做同样的检查并重启。本会话的回合进行中发生的改动(多半是它自己改的)在回合结束时加载;会话空闲时看到的改动是别处做的(另一个会话在改程序、编辑器),要等源码连续 3 分钟没有再变才加载,输入行下面会提示,急用可以 `/restart`——否则一个会话每改一步,其余打开的会话都跟着检查、重启一次,加载的还是改到一半的代码。npm 装好的新版本是完整的,不用等。检查不通过只提示错误、不重启。按 Esc 打断的那一回合不会触发。源码自动重启固定开启,旧 `CLAUDE_PRO_AUTO_RESTART` 不再生效。
181
181
  - **手动**:`/restart`(别名 `/reload`),`/restart force` 跳过检查并无视后台任务。
182
182
  - 后台 agent / 后台 shell 会被重启杀掉,所以有它们在跑时拒绝重启(可 `force`)。5 分钟内重启超过 5 次视为死循环,拒绝。
183
183
  - 重启之间终端保持原样(不退回 shell 提示符,原始模式不关),重启时敲的键不会丢;标签标题也不闪。
184
184
  - 需要真正退出再启动的只有两种情况:改了 `bin/claude-pro.js` 或 `src/supervisor.js`(运行中的监督进程是旧代码);以及新代码启动不起来而你想强行重启。`-p`、管道、`config` 子命令不经过监督进程;`CLAUDE_PRO_NO_SUPERVISOR=1` 也可以关掉它(环境变量,不是配置项)。
185
185
  - `claude-pro --self-check` 可以单独运行那个启动检查。
186
186
 
187
- ## 远程会话:在浏览器里查看和操作
188
-
189
- 本地手动启动的交互式 claude-pro 会话登录网关后自动注册。远程连接只由终端向 `CLAUDE_PRO_GATEWAY_URL` 发出站请求,终端不监听端口;网页经网关查看并操作已经在运行的本地终端会话(不能新建会话)。
190
-
191
- - **自动上线**:`/connect` 连上 7bit.fun 后当前会话立即注册;之后每个交互会话启动时自动注册,断线自动重连;`/disconnect 7bit.fun` 后停止远程连接。`CLAUDE_PRO_ONLINE=0` 可以关闭远程发布。
192
- - **网页能看到**:会话列表、在线/离线/结束状态、模型、目录、机器名、viewer 数、transcript、流式文本和 thinking、工具调用与输出、todos、后台任务、排队消息、问题文本和连接状态。
193
- - **网页能做**:发消息(等同在终端输入框回车:`/命令`、`!shell`、`#记忆`、`@会话`,最多 6 张图片;忙时排队)、回答对话框(选项、多选、“其他”文字、文本框、取消)、停止(等同 Esc,同时取消等待中的问题)、切换 model/effort(发 `/model`、`/effort`)、浏览目录并 `/cd`(会话在新目录重启,网页接着看)、输入补全(`/命令`、`@文件`、`@会话`)、查看某次工具调用的完整输出(最多 1 MB,运行中的也行)。
194
- - **只读开关**:`CLAUDE_PRO_REMOTE_COMMANDS=0`(环境变量,或 `claude-pro config set CLAUDE_PRO_REMOTE_COMMANDS 0`)让这台电脑的会话在网页上只能看、不能操作;会话上线时读取,`/status` 会显示 read-only。
195
- - **网页不能做**:结束、重启会话或更新 claude-pro(网页发来的 `/exit`、`/quit`、`/restart`、`/reload`、`/update` 会被拒绝:“结束、重启会话和更新 claude-pro 只能在终端里操作”,网关也拒绝;自动更新照常),新建会话、打开终端、管理电脑;这些只能在本地终端完成。
196
- - **协议**:远程入口是 `/user#remote`。终端用 `POST /v1/remote/sessions` 注册,并在 `commands` 里声明它接受的指令(`send`、`interrupt`、`dialog`、`options`、`suggest`、`list`、`output`;只读时不带这个字段,网关只转发声明过的类型);`GET .../commands`(SSE)接收 viewer/snapshot/peer 帧和网页的指令 `{cid, type, body}`,用 `POST .../results` 回复 `{cid, ok, …}`;`POST .../events` 发布 snapshot/batch/status/bye。
197
- - **快照与保留**:网关状态在内存中保存;网关重启后终端重新注册并补发 snapshot。每个账户最多 60 个会话,优先淘汰最久未活动的离线会话;事件缓冲最多 3000 个事件或 8 MB;结束会话保留 6 小时,未结束但离线保留 24 小时。
198
- - **权限边界**:网页只能看到和操作同一网关账户的会话(能操作就等于能在这台电脑上运行命令:不需要时用只读开关);会话内容会经网关中转并暂存在内存。撤销建立终端流的 API key 后,终端连接会被断开。
187
+ ## 本机 Web 控制台:claude-pro web
188
+
189
+ 在会话里输入 `/web`,或在终端运行 `claude-pro web`(`--no-open` 只启动不打开浏览器),会在浏览器里打开 `http://127.0.0.1:7878`(端口被占用时换一个随机端口)。它和终端用的是同一份配置和数据,改动对新会话生效。
190
+
191
+ - **布局**:左边是「工作区」,按项目目录分组列出会话,可以搜索和折叠。正在工作或等待回答的会话带状态点;鼠标停留显示目录和状态。右边是选中的会话。
192
+ - **新会话(后台会话)**:选择目录、模型和思考强度,再发送第一条消息(可以带图片)。模型和思考强度只应用于新会话,不修改全局设置。选「其他目录」时,本机 Windows 打开系统目录选择器,远程访问则浏览宿主电脑的目录。没在运行的会话,在它的输入框里发消息就会在后台接着运行。这些会话只在控制台里看和操作,不开任何窗口,也不用“结束”:想做别的就直接点开另一个对话。标题由模型按对话内容自动起,话题变了标题跟着变;对话页顶部的 ⋯ 菜单可以导出 Markdown、归档或删除。压缩上下文是自动的,也可以发 `/compact`;想在终端里接着用,在终端运行 `claude-pro --resume <id>`。工作区里只有正在工作或在等你回答的会话带圆点。这样终端窗口都可以关掉,只用控制台(本机或远程访问)。
193
+ - **都在控制台的进程里运行**(和 DeepSeek Harness 一样):后台会话不再各开一个 claude-pro 进程和监督进程,每个会话省下 100 MB 以上(实测 8 个会话加控制台共约 75 MB),启动只要约 0.1 秒。每个会话的后台命令、REPL 解释器、浏览器标签互相分开,`/bashes` 只列自己的。
194
+ - **加载新代码时一起重启**:源码改了、`/update` 装了新版本、模型调用 Restart、或用了 `/restart`,控制台等所有后台会话都空闲了(没有在回答、没有待回答的提问、没有在跑的后台命令或后台 agent),再整体换成新进程,每个会话接着原来的对话、编号不变,打开的网页自动接上。要求重启的会话会收到提示,说明在等哪些会话。`/cd` 不需要新代码,只重启那一个会话。
195
+ - **不分“运行中”和“已保存”**:点开任何一个对话,控制台就在 0.1 秒内把它接起来,直接是可以发消息、能切模型的实时页面。只是打开看看的对话不花钱:不保温缓存、不请求标题,直到发出第一条消息。没人在看、也没在工作的会话,30 分钟后自动收起(对话已保存,再点开又接上),所以控制台里只留着真正在用的会话。
196
+ - **自动恢复**:正在运行的后台会话记在 `~/.claude-pro/web-running.json`。控制台进程意外退出(崩溃、被结束)后,下次启动时(`claude-pro web`、`/web`,或开着远程访问的会话启动时)把它们全部恢复。控制台只在没有后台会话、没有打开的网页、没开远程访问 30 分钟后才退出。出错记录在 `~/.claude-pro/web-errors.log`。
197
+ - **会话**:运行中的会话实时显示,底部输入框可以发消息、粘贴/拖入/添加图片、停止当前任务、切换模型和推理强度;没在运行的会话显示完整记录,可以「在终端中继续」。
198
+ - **概览**:版本和更新、安装位置、默认模型、7bit.fun 余额、运行中的会话数、会话记录占用的空间。
199
+ - **全部会话**(在左下角头像菜单里):所有项目的对话记录表格,可以搜索(会话名、第一句话、ID、目录)、按项目筛选、按时间/大小/花费排序;点开会话可看完整对话。
200
+ - **工作区菜单**:会话行右侧的 ⋯ 可以归档、复制 Session ID 或删除对话(先移到回收站,保留 7 天,可恢复)。项目行的 ⋯ 可以批量归档非运行中的会话;Windows 上还可以在资源管理器或已安装的 VS Code 中打开目录。远程访问时,窗口开在运行 claude-pro 的电脑上。
201
+ - **归档**:归档的会话从工作区收起,内容完整保留,**不会被按天数自动清理**,`/resume` 照样能找到;在「全部会话 → 已归档」里查看或取消归档。归档标记记在 `~/.claude-pro/archived.json`,对话文件原地不动。
202
+ - 在网页上也能回答会话弹出的问题、展开完整工具输出。终端里启动的会话要在对应终端结束。
203
+ - **手动更新**:通过 npm 全局安装的版本会在网页打开时检查新版;发现更新时,点左上角版本号旁的 ↑,确认后才安装。已有任务运行时请等它们空闲;新版安装完成后控制台会在空闲时接续会话。终端仍可运行 `/update`,源码版用 Git 更新。
204
+ - **模型与供应商**:连接/断开 7bit.fun 和各家供应商(粘贴 Key → 列出模型 → 测试 → 保存,和 /connect 一样),添加自定义的 OpenAI/Anthropic 兼容接口,设置默认模型和推理强度。Key 只显示开头和结尾。
205
+ - **设置**:所有普通和高级设置,中文说明、当前生效的值和它来自哪一层,可以写到用户、项目或项目本地的设置文件,或恢复默认。
206
+ - **记忆与指令**:全局和各项目的 CLAUDE.md、自动记忆,查看、编辑、删除(删除的文件移到 `~/.claude-pro/trash/files`)。
207
+ - **扩展**:技能、子 agent、自定义命令(查看、编辑、新建)、MCP 服务器(添加、修改、删除;环境变量和请求头的值不显示)、hooks。
208
+ - **用量**:近 7/30/90 天按天、模型、项目统计的请求数、tokens 和按价格估算的花费(来自运行 Trace),以及花费最多的会话。
209
+
210
+ 服务是整台电脑共用的一个后台进程,没有页面打开 30 分钟后自动退出,下次 `/web` 再启动;claude-pro 更新(或源码改动)后会自动换成新版本。只监听 127.0.0.1,只接受以 127.0.0.1/localhost 访问的请求,修改类请求必须来自控制台自己的页面;第一次用 `/web` 打开时地址里带一个令牌,之后换成 cookie(令牌在 `~/.claude-pro/web.json`,只有你能读)。控制台不能打开 `gateway.json`、`providers.json` 这类存 Key 的文件,也不能打开会话记录以外的任意文件。
211
+
212
+ ## 远程访问:在手机上用这台电脑的控制台
213
+
214
+ 在会话里运行 `/web remote on`(第一次会让你设一个至少 10 位的密码),控制台就能在 **`https://<你的通讯号>.7bit.fun`** 打开:手机或别的电脑上打开这个地址,输入密码,就能看会话、发任务(可以带图片)、回答问题、改设置。手机上通过左上角菜单打开工作区,聊天和输入区适应小屏幕。通讯号在网关网页「通讯录」里改(只能用小写字母、数字和 `-`),比如改成 `yanzc` 就是 `https://yanzc.7bit.fun`。
215
+
216
+ - **怎么连的**:本机控制台的后台服务主动连一条 WebSocket 到 7bit.fun 网关(用 `/connect` 保存的 Key),网关把这个域名的请求从这条连接转给它。电脑不开任何端口,转过来的请求只能到控制台本身。
217
+ - **密码只在本机校验**:`~/.claude-pro/web-remote.json` 里只存 scrypt 哈希,网关不知道密码。登录页可以选「记住这台设备 30 天」,不勾就只保持 1 天。同一个 IP 连续输错 5 次锁 15 分钟,一小时内总共错 20 次就锁到这个小时结束。每次登录(成功或失败)都有记录。
218
+ - **管理**:`/web remote` 看状态和地址,`/web remote password` 改密码(所有设备退出),`/web remote logout` 让所有设备退出,`/web remote off` 关闭。控制台左边「远程访问」页面也能做这些,并列出登录着的设备和最近的登录。
219
+ - **保持在线**:开启后控制台服务不再空闲退出;电脑休眠、关机时打不开,claude-pro 的任何会话启动时会把它重新接上。
220
+ - **多台电脑**:同一个账号的几台电脑都开了远程访问时,打开地址先让你选电脑(记在 cookie 里),控制台左下角有「切换电脑」。
221
+ - **安全**:能登录就等于能在这台电脑上执行命令,密码要够强;从外网打开时控制台不接受 `/web` 的本机令牌,修改类请求必须来自这个域名的页面。
199
222
 
200
223
  ## 会话之间互发任务(本机和其他电脑)
201
224
 
202
- 每个交互会话都有一个名字(默认是目录名,输入框右上角的 `@名字`),别的会话可以给它发任务,它做完后回答自动发回来。
225
+ 每个交互会话都有一个名字(默认是目录名,`/rename` 不带参数时显示),别的会话可以给它发任务,它做完后回答自动发回来。
203
226
 
204
227
  - **本机**:同一台电脑上开着的会话直接互通(经 127.0.0.1,不经过网络)。
205
228
  - **其他电脑**:同一个网关账户下在线的会话经网关互通。例如公司电脑上开着 claude-pro,在家里输入 `@公司 跑一下测试`,任务送到公司那台的会话,回答自动显示在家里这边。电脑名默认是主机名,用 `CLAUDE_PRO_MACHINE_NAME=公司` 改成好记的名字(支持中文)。
206
- - **输入 `@`** 弹出文件和会话的混合补全(本机的和其他电脑在线的会话都会列出),选文件可引用它,选会话再写任务回车即可:
229
+ - **输入 `@` 后按 Tab** 列出文件和会话的混合补全(本机的和其他电脑在线的会话都会列出),选文件可引用它,选会话再写任务回车即可:
207
230
  - `@文件路径`:引用文件;带空格的路径使用 `@"文件路径"`;
208
231
  - `@名字 任务`:向本机或远程会话发送任务;
209
232
  - `@电脑名/名字 任务`:向其他电脑上的指定会话发送任务;那台电脑只开着一个会话时直接 `@电脑名 任务`。
210
233
  - 文件和会话同名时,行首 `@名字 任务` 按会话处理;要强制引用文件可写 `@./名字`。
211
- - **`@` 可以写在句子中间**:输入时在空格后面打 `@` 也会弹出文件和会话列表;在发给当前 agent 的消息里提到 `@名字`,agent 会被告知那是哪个会话、怎么联系它。文件引用仍会展开为文件内容。输入法打出全角 `&` 不再是会话语法。
234
+ - **`@` 可以写在句子中间**:在空格后面打 `@` 再按 Tab 也会列出文件和会话;在发给当前 agent 的消息里提到 `@名字`,agent 会被告知那是哪个会话、怎么联系它。文件引用仍会展开为文件内容。输入法打出全角 `&` 不再是会话语法。
212
235
  - **`/rename 新名字`**:给当前会话改名(比如 `/rename web-server`),别的会话从此用 `@web-server` 找它;这个名字也成为对话标题(终端标签页、`/resume` 列表、网页),不再自动按话题改;`/resume` 这个对话时名字一起回来。
213
- - **`/peers`**:列出本机和其他电脑上在线的会话。模型也能用 ListPeers / MessagePeer 工具自己找别的会话分派任务。
236
+ - **`/peers`**:列出本机、其他电脑和通讯录好友在线的会话。模型也能用 ListPeers / MessagePeer 工具自己找别的会话分派任务。
214
237
  - 回答会在对方这一轮做完后自动发回;对方正忙时,任务排在它当前工作之后。网关替离线的会话暂存回答(24 小时;网关重启会丢失还没送达的消息)。
215
238
  - **安全**:在线的会话能被同一网关账户执行任何任务。能登录这个账户、或持有它任一 API key 的人,都能在这些电脑上以完全权限执行命令。不需要时 `/disconnect 7bit.fun`。
216
239
 
240
+ ## 通讯录:和别人的会话互发任务
241
+
242
+ 不同网关账户之间,双方同意后,各自的 claude-pro 会话也能互发任务。
243
+
244
+ - **通讯号**:每个账户有一个公开的通讯号(默认随机,如 `cp7k3qxm`),别人用它加你,看不到你的邮箱。`/contacts handle 新名字` 或网关网页「通讯录」里修改(3-20 个小写字母、数字、`_`、`-`,以字母开头)。
245
+ - **加好友**:`/contacts add 对方通讯号` 发出请求;对方在线的会话会提示,对方用 `/contacts accept 你的通讯号` 同意(也可以 `reject`、`block`),或在网页通讯录里点同意。双方互相请求时直接成为好友。`/contacts remove` 删除,`/contacts block` 拉黑(对方不能再请求、不能发任务,也不会被告知)。`/contacts` 列出全部。
246
+ - **发任务**:好友在线的会话在 `/peers` 和 ListPeers 里显示为 `@通讯号:电脑名/会话名`;`@通讯号 任务`(对方只开着一个会话时)或 `@通讯号:电脑名/会话名 任务` 发送,回答自动发回。
247
+ - **确认**:好友发来的任务默认在终端弹窗问你「执行 / 拒绝 / 以后都执行」,拒绝时对方会收到“已拒绝”。`/contacts trust 通讯号 auto` 让这个好友的任务直接执行,`confirm` 改回每条确认。交给模型时会注明这是外人的请求、不是用户的指令,并要求它不泄露密钥和私人文件、不做破坏性操作。
248
+ - **好友能看到什么**:只有你在线会话的名字、电脑名和是否在忙;看不到目录、标题和对话,发来的消息里也不带你的目录。
249
+ - **要求**:双方都要在 claude-pro 里 `/connect` 连上 7bit.fun(模型用别家也可以,这个 key 只用于通讯)。
250
+
217
251
  ## 完全访问与安全网
218
252
 
219
253
  - **没有权限系统**:没有确认弹窗,没有 allow/deny 规则,也没有 `/permissions`。旧参数 `--dangerously-skip-permissions`、`--permission-mode`、`--allowedTools`、`--disallowedTools` 仍被接受但会被忽略,`--plan` 也是;settings 里残留的 `permissions` 字段也会被忽略。
@@ -246,15 +280,15 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://7bit.fun
246
280
  - 流式 Markdown 渲染(代码高亮、表格、中文宽度对齐),所有模型返回的思考过程始终展开显示,恢复会话时也会显示已保存的思考;`/verbose` 只切换工具输出详细度和压缩摘要,不影响思考显示
247
281
  - `Esc` 中断;忙碌时输入的消息会排队并插入当前任务
248
282
  - `!` Bash 模式、`#` 写入记忆(CLAUDE.md)、`\`+回车 或 `ctrl+j` 换行、粘贴大段文本折叠为 `[Pasted text #1 +42 lines]`
249
- - **全屏界面**:程序画在终端的备用屏幕上(像 vim),输入框固定在窗口最底下,不随输出或终端滚动条移动;对话在程序里滚动:鼠标滚轮(每格 3 行)、`PgUp`/`PgDn`(半屏)、`Ctrl+Home`(对话开头)、`Ctrl+End`(回到最新)。往上翻时新输出不会把画面拉回底部,底部浮着 `Jump to bottom (ctrl+End) ↓ · N new lines`,**点它**或按 `Ctrl+End` 回到底部;发消息时自动回到底部。**选中文字直接用鼠标拖**(不用按 Shift),松开只保留反色选择,不会自动复制;双击选一个词,三击选一整行;拖到对话区上下边缘会跟着滚动。选中的部分反色显示,点一下别处、按 `Esc` 或任意键就消失;有选中时只有 `Ctrl+C` 会复制。**输入框里**单击把光标移到那里,拖动、双击、三击选中正在写的文字,`Ctrl+C` 复制(不会打断任务,也不清空输入框);选中后打字不会替换选中的文字。**引用追问**(像 ChatGPT 的“向 ChatGPT 提问”):选中对话里的内容后按 `Ctrl+Q`(终端占用了 `Ctrl+Q` 时用 `Alt+Q`),选中的内容就以 `[Quote #1 +12 lines]` 插进输入框,光标停在下一行,直接写追问。发给模型的是选中的原文,加上它所在的那条工具调用、回复或消息的首行(`<quote source="⏺ Read(src/api.js)">…</quote>`),模型就知道问的是哪一段、哪个文件;对话里只显示引用的前三行。可以连续引用好几段,退格一次删掉整个引用。`Ctrl+V` 粘贴剪贴板文字(剪贴板里只有图片时作为图片附加),`Alt+V` 优先附加剪贴板图片;右键不执行复制或粘贴。仍可按住 Shift 拖动用终端自己的选中。退出后终端回到启动前的样子(对话不留在终端滚动记录里)
283
+ - **简洁的终端界面**:输入行就是一个 `> `(Bash 模式 `!`、记忆模式 `#`),没有边框、浮窗和常驻页脚;输出直接写进终端自己的滚动记录,用终端自己的滚动、选中、复制和查找(Windows Terminal 的 `Ctrl+Shift+F`)。输入行固定在窗口最底下。对话框(选模型、/rewind、提问)是不带边框的编号列表,`↑`/`↓` 或数字选择,`Enter` 确认,`Esc` 取消。**补全按 Tab**(像 shell):只有一个匹配时直接补上,多个时先补上共同前缀并列出候选,再按 `Tab`/`↓` 在候选里移动,`Enter` 选中,`Esc` 关闭;列表打开时继续输入会跟着过滤。`Ctrl+V` 粘贴剪贴板文字(剪贴板里只有图片时作为图片附加),`Alt+V` 优先附加剪贴板图片。项目管理、看会话、改配置用网页控制台(`claude-pro web`)
250
284
  - `ctrl+c` 或连按两次 `Esc` 清掉的草稿不会丢:在空输入框按 `↑` 找回(连同粘贴的文本和图片),中间发过别的消息也可以
251
285
  - `@` 同时补全文件和本机/远程会话:文件引用走 `Read` 工具,等于模型自己读了这个文件。最多带前 2000 行(被截断时会明确告诉模型,并把该文件记为"只读了一部分",之后 `Write` 不会去覆盖没给它看过的行);图片作为图片附加;二进制文件和超过 512KB 的文本会被跳过并提示原因;`@目录` 列出目录内容;行首 `@会话 任务` 把任务发给另一会话
252
286
  - 上下文用满上游输入上限时自动压缩(留出写摘要要用的余量:窗口的 5%,最多 4 万 token,这样摘要请求能读缓存而不是因超长被拒),不再读取 `CLAUDE_CODE_AUTO_COMPACT_WINDOW`;子 agent 定义的 `autoCompactWindow` 仍有效,也可手动 `/compact`
253
287
  - 会话自动保存到 `~/.claude-pro/projects/`,`claude-pro -c` 继续上次,`claude-pro -r` 选择历史会话
254
288
 
255
- **`/cd <目录>`**:换工作目录,对话接着进行。目录可以是绝对路径、`~`、相对当前目录的路径;不存在或不是目录时报错(不会创建)。会话在新目录里重启一次(约一秒),新目录的项目设置、CLAUDE.md、记忆、git 状态、`@` 文件/会话补全、输入历史都换成新目录的;对话、模型、effort、待办、网页上的远程会话(同一个链接)不变。会话记录跟着搬到新目录下,在新目录里 `/resume` 能找到。用 `/rename` 或 `--name` 起过的名字保留,默认按目录取的名字换成新目录名。任务进行中不能切换。
289
+ **`/cd <目录>`**:换工作目录,对话接着进行。目录可以是绝对路径、`~`、相对当前目录的路径;不存在或不是目录时报错(不会创建)。会话在新目录里重启一次(约一秒),新目录的项目设置、CLAUDE.md、记忆、git 状态、`@` 文件/会话补全、输入历史都换成新目录的;对话、模型、effort、待办不变。会话记录跟着搬到新目录下,在新目录里 `/resume` 能找到。用 `/rename` 或 `--name` 起过的名字保留,默认按目录取的名字换成新目录名。任务进行中不能切换。
256
290
 
257
- **斜杠命令**:`/help` `/cd` `/rename` `/peers` `/clear` `/compact` `/config` `/model` `/effort` `/status` `/cost` `/trace` `/context` `/init` `/review` `/memory` `/verify` `/tasks` `/rewind` `/skills` `/resume` `/todos` `/agents` `/mcp` `/bashes` `/verbose` `/export` `/doctor` `/exit`,以及 `.claude/commands/*.md`、`.claude-pro/commands/*.md`、`~/.claude-pro/commands/*.md` 中的自定义命令(支持 `$ARGUMENTS`、`$1`、`` !`cmd` ``)。
291
+ **斜杠命令**:`/help` `/cd` `/rename` `/peers` `/contacts` `/web`(`/web remote …`)`/clear` `/compact` `/config` `/model` `/effort` `/status` `/cost` `/trace` `/context` `/init` `/review` `/memory` `/verify` `/tasks` `/rewind` `/skills` `/resume` `/todos` `/agents` `/mcp` `/bashes` `/verbose` `/export` `/doctor` `/exit`,以及 `.claude/commands/*.md`、`.claude-pro/commands/*.md`、`~/.claude-pro/commands/*.md` 中的自定义命令(支持 `$ARGUMENTS`、`$1`、`` !`cmd` ``)。
258
292
 
259
293
  **记忆**:自动读取 `~/.claude-pro/CLAUDE.md`、项目各级目录的 `CLAUDE.md` / `.claude/CLAUDE.md` / `CLAUDE.local.md`;某一级目录没有 `CLAUDE.md` 时读它的 `AGENTS.md` 代替(两者都有时通常是同一份说明,不重复发送)。
260
294
 
@@ -313,16 +347,13 @@ claude-pro -p "只调研,给出重构方案,不要改文件" # 只出方
313
347
  | `Enter` | 发送 |
314
348
  | `\` + `Enter` / `ctrl+j` / `alt+enter` | 换行 |
315
349
  | `Esc` | 中断当前任务;连按两次:有文字时清空输入,输入框为空时打开回退菜单(同 `/rewind`) |
316
- | `ctrl+c` | 有选中文字时复制;否则中断 / 清空输入 / 连按两次退出 |
317
- | `ctrl+q` / `alt+q` | 有选中文字时把它引用进输入框,在下一行写追问;模型会收到原文和它所在的工具调用或回复 |
350
+ | `ctrl+c` | 中断 / 清空输入 / 连按两次退出 |
318
351
  | `ctrl+v` | 粘贴剪贴板文字(只有图片时附加图片) |
319
352
  | `alt+v` | 附加剪贴板图片(没有图片时粘贴文字) |
320
- | `ctrl+t` | 显示/隐藏 todo 列表 |
321
- | `ctrl+l` | 清屏重绘 |
322
- | `PgUp` / `PgDn`、滚轮、`Ctrl+Home` / `Ctrl+End` | 滚动对话 / 到开头 / 回到最新 |
323
- | `ctrl+f` | 在对话里查找(像 VS Code):输入框的位置换成查找框,边输入边高亮所有匹配(不分大小写,当前这个橙色、其余黄色),右上角显示"第几个/共几个"(`No results` 表示没有)。先跳到视图底部往上最近的一个;`Enter` 或 `↑` 跳到更早的一个,`Shift+Enter` 或 `↓` 跳到更新的一个,到头后绕回;`PgUp`/`PgDn`、滚轮照常滚动;`Esc` 关闭,画面停在当前位置(`Ctrl+End` 回到底部)。再按 `ctrl+f` 会带上上次的关键字(已选中,直接输入就替换);先用鼠标选中文字再按,会搜选中的文字。查找时有新输出,匹配会跟着更新。 |
353
+ | `ctrl+l` | 清屏 |
324
354
  | `↑` / `↓` | 在多行输入(包括自动折行的长文字)里上下移动光标;光标在第一行时 `↑` 先移到开头、再按才翻到上一条历史消息,`↓` 在最后一行同理 |
325
- | `Tab` | 补全命令 / 文件 |
355
+ | `Tab` | 补全 `/命令`、`@文件`、`@会话`:一个匹配直接补上,多个时列出,`Tab`/`↓` 选下一个,`Enter` 选中,`Esc` 关闭 |
356
+ | `?` + `Enter` | 列出快捷键 |
326
357
 
327
358
  ## 开发
328
359
 
@@ -351,7 +382,9 @@ src/prompts.js 系统提示词、压缩提示词、自动记忆提示
351
382
  src/tools/* 各工具实现(含 Skill、NotebookEdit)
352
383
  src/mcp.js MCP 客户端(stdio / HTTP)
353
384
  src/ui/* 终端 UI:屏幕管理、输入框、对话框、Markdown 渲染
354
- src/remote.js 远程会话:发布、网页指令、对话事件模型和终端 peer messaging(applyEvent,网关页面里有同一份)
385
+ src/remote.js 对话事件模型(applyEvent,控制台页面里有同一份)和网关的会话中继连接(跨电脑、通讯录互发任务)
386
+ src/live.js 本机 Web 控制台的实时查看:会话的对话事件流(经会话自己的 127.0.0.1 peer 服务)
387
+ src/web/* 本机 Web 控制台(claude-pro web / /web):服务端、API、页面,远程访问的密码和隧道(remote-access.js)
355
388
  src/commands.js 斜杠命令
356
389
  ```
357
390
 
@@ -359,8 +392,6 @@ src/commands.js 斜杠命令
359
392
 
360
393
  WebSearch 依赖网关:没有网关时只能抓取 DuckDuckGo/Bing 网页,而它们常把程序当爬虫拦下(DuckDuckGo 返回 202,Bing 只按查询的第一个词搜),结果可能离题。GitHub 相关的查询,系统提示词让模型优先用 Bash 跑 `gh`(需要已安装并登录)。检查点只覆盖文件工具的修改,不覆盖 Bash 命令造成的改动。
361
394
 
362
- 提示:鼠标选择不会自动写入剪贴板;使用 `Ctrl+C` 复制、`Ctrl+V` 粘贴,`Ctrl+Q` 引用到输入框里追问。按住 Shift 的终端原生选择行为由终端自身决定。
363
-
364
395
  ## 历史
365
396
 
366
397
  旧名 ccc,最后一版保存在 git 标签 `ccc-last`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanzc/claude-pro",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "claude-pro: a command line coding agent for many model providers (Anthropic, OpenAI, DeepSeek, Kimi, GLM, Qwen, OpenRouter, the 7bit.fun gateway, your own endpoint...). Full access with no permission prompts; file edits are checkpointed and can be rewound.",
5
5
  "type": "module",
6
6
  "repository": {
package/src/agent.js CHANGED
@@ -349,6 +349,16 @@ export function repairToolResults(messages) {
349
349
  return { messages: out, changed, recovered };
350
350
  }
351
351
 
352
+ // The recovered tool calls (repairToolResults) worth a notice: those of the last assistant message, a turn cut off by a
353
+ // crash or a restart, once in a process (`said`). A call the conversation has gone on past was said when it was found
354
+ // and is repaired silently: the set of calls said is this process's, so every restart announced the same old one again
355
+ // (2026-11-20, a Browser call cut off a day before, kept through two compactions).
356
+ export function newlyRecovered(messages, recovered, said = new Set()) {
357
+ const last = messages.findLast((m) => m.role === 'assistant');
358
+ const lastIds = new Set(Array.isArray(last?.content) ? last.content.filter((b) => b.type === 'tool_use').map((b) => b.id) : []);
359
+ return recovered.filter((id) => lastIds.has(id) && !said.has(id));
360
+ }
361
+
352
362
  // Minimal JSON-schema check for required fields and primitive types.
353
363
  function validateInput(schema, input) {
354
364
  if (!schema || typeof input !== 'object' || input === null) return 'Input must be an object';
@@ -683,11 +693,12 @@ export class Agent {
683
693
  return s && { ...s, since: this.keepAlive?.pauseStart || 0 };
684
694
  }
685
695
 
686
- // A loaded conversation whose cache the session file says is still warm: refreshed from here on as well.
687
- restoreCacheState(state) {
696
+ // A loaded conversation whose cache the session file says is still warm: refreshed from here on as well, unless
697
+ // `keepWarm` is false (a conversation only opened to be looked at: its next turn keeps its cache warm again).
698
+ restoreCacheState(state, { keepWarm = true } = {}) {
688
699
  if (!this.cache.restore(state)) return false;
689
700
  this.keepAlive?.noteRequest(state.since || 0);
690
- this.keepAlive?.plan();
701
+ if (keepWarm) this.keepAlive?.plan();
691
702
  return true;
692
703
  }
693
704
 
@@ -931,7 +942,7 @@ export class Agent {
931
942
  const tool = { name: 'Verify', summarize: () => command };
932
943
  const input = { command, timeout: this.config.bashMaxTimeout };
933
944
  const handle = this.io.toolStart?.({ id: `verify_${Date.now()}`, name: 'Verify', input }, tool, input, this) || {};
934
- const ctx = { ...this.makeCtx(signal), cwd: this.projectRoot, setCwd() {} };
945
+ const ctx = { ...this.makeCtx(signal), cwd: this.projectRoot };
935
946
  ctx.onProgress = (p, meta) => handle.progress?.(p, meta);
936
947
  let result;
937
948
  try {
@@ -966,7 +977,7 @@ export class Agent {
966
977
  // the conversation merged and inserted messages, which moved the messages the checkpoints point at, so a
967
978
  // /rewind after a restart cut the conversation in the wrong place.
968
979
  const repaired = repairToolResults(normalizeMessages(this.messages));
969
- const fresh = repaired.recovered.filter((id) => !this.recoveredToolIds.has(id));
980
+ const fresh = newlyRecovered(this.messages, repaired.recovered, this.recoveredToolIds);
970
981
  if (fresh.length) {
971
982
  for (const id of fresh) this.recoveredToolIds.add(id);
972
983
  this.io.notice?.('Recovered an unfinished tool call in the conversation; continuing with an interrupted result.', 'warn');
@@ -1017,7 +1028,6 @@ export class Agent {
1017
1028
  const agent = this;
1018
1029
  return {
1019
1030
  get cwd() { return agent.cwd; },
1020
- setCwd(dir) { agent.cwd = dir; },
1021
1031
  projectRoot: this.projectRoot,
1022
1032
  config: this.config,
1023
1033
  signal,
@@ -866,7 +866,17 @@ class BrowserSession {
866
866
  const fn = isFn ? `function() { return (${script})(this); }` : `function() { return (${script}); }`;
867
867
  r = await this.untilDialog(tab, this.send(tab, 'Runtime.callFunctionOn', { objectId, functionDeclaration: fn, returnByValue: true, awaitPromise: true, userGesture: true }, { timeoutMs: browserLimits.evalMs }));
868
868
  } else {
869
- r = await this.untilDialog(tab, this.send(tab, 'Runtime.evaluate', { expression: isFn ? `(${script})()` : script, returnByValue: true, awaitPromise: true, userGesture: true, replMode: !isFn }, { timeoutMs: browserLimits.evalMs }));
869
+ r = await this.untilDialog(tab, this.send(tab, 'Runtime.evaluate', { expression: isFn ? `(${script})()` : script, returnByValue: !!isFn, awaitPromise: true, userGesture: true, replMode: !isFn }, { timeoutMs: browserLimits.evalMs }));
870
+ // REPL mode waits for the statements, not for a promise they end with (fetch(…).then(…)): that one is
871
+ // awaited here, and an object result is read by value afterwards
872
+ const objectId = !isFn && !r?.exceptionDetails ? r?.result?.objectId : null;
873
+ if (objectId) {
874
+ const read = r.result.subtype === 'promise'
875
+ ? this.send(tab, 'Runtime.awaitPromise', { promiseObjectId: objectId, returnByValue: true }, { timeoutMs: browserLimits.evalMs })
876
+ : this.send(tab, 'Runtime.callFunctionOn', { objectId, functionDeclaration: 'function() { return this; }', returnByValue: true }, { timeoutMs: browserLimits.evalMs });
877
+ r = await this.untilDialog(tab, read);
878
+ this.send(tab, 'Runtime.releaseObject', { objectId }).catch(() => {});
879
+ }
870
880
  }
871
881
  if (!r) return `(no value yet: the script opened ${tab.dialog?.type === 'alert' ? 'an' : 'a'} ${tab.dialog?.type || ''} dialog, ${JSON.stringify(tab.dialog?.message ?? '')}; answer it with dialog)`;
872
882
  if (r.exceptionDetails) throw new BrowserError(`the script threw: ${exceptionText(r.exceptionDetails)}`);
@@ -938,12 +948,32 @@ export const safeUrl = (u) => {
938
948
  } catch { return u; }
939
949
  };
940
950
 
941
- export const browserSession = new BrowserSession();
951
+ export const browserSession = new BrowserSession(); // a session without an owner's
952
+
953
+ // Each session its own (by config.owner): the web console runs several sessions in one process, and each has its
954
+ // own tabs and connection (shared with the others through the broker, see broker.js).
955
+ const owned = new Map();
956
+ export function browserSessionFor(owner) {
957
+ if (!owner) return browserSession;
958
+ let s = owned.get(owner);
959
+ if (!s) owned.set(owner, (s = new BrowserSession()));
960
+ return s;
961
+ }
962
+
963
+ // The session `owner` ends: its connection goes (the browser and its tabs stay).
964
+ export function closeBrowserSession(owner) {
965
+ const s = owned.get(owner);
966
+ if (!s) return;
967
+ owned.delete(owner);
968
+ s.close();
969
+ }
942
970
 
943
971
  // For a process that ends by itself (claude-pro -p): an open connection would keep it alive, and so would the
944
972
  // pipe of WebFetch's headless browser (render.js).
945
973
  export function closeBrowser() {
946
974
  browserSession.close();
975
+ for (const s of owned.values()) s.close();
976
+ owned.clear();
947
977
  closeRenderer();
948
978
  }
949
979
 
package/src/commands.js CHANGED
@@ -19,7 +19,7 @@ import { hasRipgrep } from './utils/shell.js';
19
19
  import { displayPath, normalizeDir, resolvePath } from './utils/paths.js';
20
20
  import { cleanName, machineName } from './peers.js';
21
21
  import { rewind, promptAt } from './checkpoints.js';
22
- import { canRestart, runSelfCheck } from './restart.js';
22
+ import { runSelfCheck } from './restart.js';
23
23
 
24
24
  const EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
25
25
  const isGpt = (modelId) => /^gpt-/i.test(modelId);
@@ -219,7 +219,7 @@ export function buildCommands(app) {
219
219
  argHint: '[force]',
220
220
  description: "Restart to load changes to the program's own source code (the conversation continues)",
221
221
  async run(args) {
222
- if (!canRestart()) {
222
+ if (!app.canRestart()) {
223
223
  out(c.red(`Restarting needs an interactive session started with \`${APP_NAME}\` (not -p, and without CLAUDE_PRO_NO_SUPERVISOR). Quit and start it again.`));
224
224
  return;
225
225
  }
@@ -400,15 +400,11 @@ export function buildCommands(app) {
400
400
  app.screen.schedule();
401
401
  }
402
402
  };
403
- // The gateway connected: this session goes online there at once, for its web page and peer messaging. The page
404
- // can steer the session too (send messages, `!` commands, /cd...) unless CLAUDE_PRO_REMOTE_COMMANDS=0: said as it
405
- // is, since this message called the page read-only.
403
+ // The gateway connected: this session goes online there at once, for tasks from your other computers and contacts.
406
404
  const goOnline = async () => {
407
405
  const remote = await app.syncRemote();
408
406
  if (!remote) return;
409
- const page = remote.commands?.length
410
- ? 'its web page shows it and can send it messages and commands (CLAUDE_PRO_REMOTE_COMMANDS=0 makes the page read-only)'
411
- : 'the read-only web page shows it';
407
+ const page = 'sessions on your other computers and your contacts can send it tasks';
412
408
  out(remote.registered
413
409
  ? `${c.green('⇄')} This session is online at the gateway: ${page}.`
414
410
  : c.dim(`⇄ This session goes online at the gateway as soon as ${remote.base} can be reached.`));
@@ -876,12 +872,13 @@ export function buildCommands(app) {
876
872
  async run(args) {
877
873
  const [action, ...rest] = args.split(/\s+/).filter(Boolean);
878
874
  if (action === 'name' && rest.length) { out(`This session is now ${c.bold('@' + app.renameSession(rest.join('-')))}`); return; }
879
- const { me, local, remote, online } = await app.listAllPeers();
875
+ const { me, local, remote, contacts = [], online } = await app.listAllPeers();
880
876
  out([
881
877
  `This session: ${c.bold('@' + me.name)} ${c.dim(displayPath(me.cwd, app.cwd))}${online ? c.dim(` · from other computers: @${me.label}`) : ''}`,
882
878
  ...local.map((p) => `${c.bold('@' + p.name)} ${c.dim(`${p.cwd} · pid ${p.pid}`)}`),
883
879
  ...(remote.length ? [c.dim('On your other computers, through the gateway:'), ...remote.map((p) => `${c.bold('@' + p.label)} ${c.dim(`${p.cwd}${p.busy ? ' · busy' : ''}`)}`)] : []),
884
- ...(local.length || remote.length ? [] : [c.dim('No other session is running.')]),
880
+ ...(contacts.length ? [c.dim('Of your contacts (other people, /contacts):'), ...contacts.map((p) => `${c.bold('@' + p.label)}${p.busy ? c.dim(' · busy') : ''}`)] : []),
881
+ ...(local.length || remote.length || contacts.length ? [] : [c.dim('No other session is running.')]),
885
882
  c.dim(online
886
883
  ? 'Type "@" for the combined file/session list, "@name task" to send a task; its answer is shown here. On another computer: "@computer/name task", or "@computer task" when it runs one session. /rename names this session. The agent can use ListPeers / MessagePeer too.'
887
884
  : 'Type "@" for the combined file/session list, "@name task" to send a task; its answer is shown here. Sessions on your other computers show up here once this one is online at the gateway (/connect 7bit.fun; /status says why it is not).'),
@@ -889,6 +886,158 @@ export function buildCommands(app) {
889
886
  },
890
887
  });
891
888
 
889
+ // The local web console, and its 远程访问 (https://<通讯号>.7bit.fun with a password, see web/remote-access.js).
890
+ add({
891
+ name: 'web',
892
+ argHint: '[remote [on|off|password|logout]]',
893
+ description: 'Open the web console in your browser; /web remote on reaches it from your phone at <通讯号>.7bit.fun with a password',
894
+ async run(args) {
895
+ const [what = '', action = ''] = args.trim().toLowerCase().split(/\s+/).filter(Boolean);
896
+ const web = await import('./web/server.js');
897
+ if (what === 'remote') return remoteAccess(web, action);
898
+ if (what) { out(c.red('/web, or /web remote [on|off|password|logout]')); return; }
899
+ out(c.dim('Starting the web console…'));
900
+ try {
901
+ const { url, port } = await web.ensureWebServer();
902
+ const opened = web.openBrowser(url);
903
+ out(`${c.green('✔')} Web console: ${c.blue(`http://127.0.0.1:${port}`)}${opened ? c.dim(' (opened in your browser)') : ''}`);
904
+ if (!opened) out(c.dim(`Open this link to log in: ${url}`));
905
+ } catch (e) {
906
+ out(c.red(`Could not start the web console: ${e.message}`));
907
+ }
908
+ },
909
+ });
910
+
911
+ async function askPassword(ra) {
912
+ for (let attempt = 0; attempt < 3; attempt++) {
913
+ const first = await app.showDialog(new TextInputDialog({
914
+ title: '远程访问密码',
915
+ body: [`在手机或别的电脑上打开控制台时要输入它。至少 ${ra.MIN_PASSWORD} 位(空格不算);它能让人在这台电脑上执行命令,请用强密码。`, c.dim('只在这台电脑上保存它的哈希,网关不知道它。')],
916
+ question: '密码:',
917
+ secret: true,
918
+ validate: (t) => (t.replace(/\s+/g, '').length < ra.MIN_PASSWORD ? `至少 ${ra.MIN_PASSWORD} 位` : null),
919
+ }));
920
+ if (first === null) return null;
921
+ const again = await app.showDialog(new TextInputDialog({ title: '远程访问密码', body: ['再输一次。'], question: '密码:', secret: true }));
922
+ if (again === null) return null;
923
+ if (again === first) return first;
924
+ out(c.yellow('两次输入不一样,再来一次。'));
925
+ }
926
+ return null;
927
+ }
928
+
929
+ // What the console server says of 远程访问 (GET /api/remote), started if need be.
930
+ async function remoteStatus(web, { start = true, waitOnline = 0 } = {}) {
931
+ let state = null;
932
+ try { state = JSON.parse(fs.readFileSync(web.stateFile(), 'utf8')); } catch { /* not started */ }
933
+ if (start) state = { ...state, ...(await web.ensureWebServer()) };
934
+ const until = Date.now() + waitOnline;
935
+ for (;;) {
936
+ try {
937
+ const token = JSON.parse(fs.readFileSync(web.stateFile(), 'utf8')).token;
938
+ const res = await fetch(`http://127.0.0.1:${state.port}/api/remote`, { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(3000) });
939
+ const view = await res.json();
940
+ if (Date.now() >= until || view.tunnel?.status === 'online' || view.tunnel?.status === 'error') return view;
941
+ } catch (e) { if (Date.now() >= until) throw e; }
942
+ await new Promise((r) => setTimeout(r, 700));
943
+ }
944
+ }
945
+
946
+ async function remoteAccess(web, action) {
947
+ const ra = await import('./web/remote-access.js');
948
+ const cfg = app.runtime.config;
949
+ if (action === 'off') {
950
+ ra.setEnabled(false);
951
+ out(`${c.green('✔')} 远程访问已关闭:${c.dim('外网打不开这台电脑的控制台了(本机的 /web 照常可用)。')}`);
952
+ return;
953
+ }
954
+ if (action === 'logout') {
955
+ ra.endAllSessions();
956
+ out(`${c.green('✔')} 所有远程登录的设备都已退出,下次要重新输密码。`);
957
+ return;
958
+ }
959
+ if (action === 'password') {
960
+ const pw = await askPassword(ra);
961
+ if (!pw) { out(c.dim('密码没有改。')); return; }
962
+ ra.setPassword(pw);
963
+ out(`${c.green('✔')} 密码已修改,所有远程登录的设备都已退出。`);
964
+ return;
965
+ }
966
+ if (action === 'on') {
967
+ if (!gatewayLogin(cfg.gatewayUrl)) { out(c.red(`远程访问通过 7bit.fun 网关:先 /connect 7bit.fun 连上网关。`)); return; }
968
+ if (!ra.hasPassword()) {
969
+ const pw = await askPassword(ra);
970
+ if (!pw) { out(c.dim('远程访问没有开启。')); return; }
971
+ ra.setPassword(pw);
972
+ }
973
+ ra.setEnabled(true);
974
+ out(c.dim('正在连接网关…'));
975
+ } else if (action) { out(c.red('/web remote [on|off|password|logout]')); return; }
976
+ const d = ra.readRemote();
977
+ if (!d.enabled) {
978
+ out([`远程访问:${c.dim('关闭')}`, c.dim('/web remote on 开启:在手机上打开 https://<你的通讯号>.7bit.fun,输入密码就能用这台电脑的 claude-pro 控制台。')]);
979
+ return;
980
+ }
981
+ let view;
982
+ try { view = await remoteStatus(web, { waitOnline: action === 'on' ? 12_000 : 0 }); } catch (e) { out(c.red(`控制台没有启动:${e.message}`)); return; }
983
+ const t = view.tunnel || {};
984
+ const lines = [];
985
+ if (t.status === 'online') lines.push(`${c.green('✔')} 远程访问已开启:${c.bold(c.blue(`https://${t.host}`))}`, c.dim('在手机上打开它,输入密码。电脑休眠或关机时打不开;claude-pro 的任何会话启动时都会把它重新接上。'));
986
+ else if (t.status === 'error') lines.push(c.red(`远程访问没有接上:${t.error}`));
987
+ else lines.push(c.yellow(`远程访问正在连接网关…${t.error ? c.dim(`(${t.error})`) : ''}`));
988
+ lines.push(c.dim(`登录着的设备 ${view.sessions?.length || 0} 台 · /web remote logout 让它们全部退出 · /web remote password 改密码 · /web remote off 关闭`));
989
+ out(lines);
990
+ }
991
+
992
+ // 通讯录 at the gateway: other people's accounts whose claude-pro sessions and this account's may send each other
993
+ // tasks, once both sides agreed. Each account has a public 通讯号 (handle) that the others add it by.
994
+ const CONTACT_LABELS = { incoming: c.yellow('asks to be your contact'), outgoing: c.dim('waiting for them to accept'), accepted: c.green('contact'), blocked: c.red('blocked') };
995
+ add({
996
+ name: 'contacts',
997
+ argHint: '[add|accept|reject|remove|block|trust|handle] [通讯号] [auto|confirm]',
998
+ description: 'Your contacts at the gateway: other people whose claude-pro sessions and yours may send each other tasks once both agree',
999
+ async run(args) {
1000
+ const [action = '', handle = '', extra = ''] = args.trim().split(/\s+/).filter(Boolean).map((s, i) => (i === 0 ? s.toLowerCase() : s));
1001
+ const remote = await app.syncRemote();
1002
+ if (!remote?.registered) { out(c.red(`Contacts live at the gateway, and this session is not online there: ${app.remoteState().text}`)); return; }
1003
+ const actions = ['add', 'accept', 'reject', 'remove', 'block', 'trust', 'handle'];
1004
+ if (action && !actions.includes(action)) { out(c.red(`Unknown action "${action}". /contacts ${actions.join('|')} 通讯号`)); return; }
1005
+ if (action && !handle) { out(c.red(`/contacts ${action} needs a 通讯号${action === 'handle' ? ' (your new one)' : ''}.`)); return; }
1006
+ const trust = extra.toLowerCase() || 'auto';
1007
+ if (action === 'trust' && !['auto', 'confirm'].includes(trust)) { out(c.red('/contacts trust 通讯号 auto (their tasks run without asking) or confirm (each one is asked).')); return; }
1008
+ let data;
1009
+ try {
1010
+ data = await remote.contacts(action, action === 'trust' ? { handle, trust } : action ? { handle } : undefined);
1011
+ } catch (e) {
1012
+ out(c.red(e.status === 404 && !action ? `The gateway ${remote.base} has no contacts yet (${e.message}).` : e.message));
1013
+ return;
1014
+ }
1015
+ const done = {
1016
+ add: `Asked ${handle}: once they accept, your sessions can send each other tasks.`,
1017
+ accept: `${handle} is your contact now.`,
1018
+ reject: `Declined ${handle}.`,
1019
+ remove: `${handle} is no longer in your contacts.`,
1020
+ block: `Blocked ${handle}: they cannot ask you nor send your sessions tasks.`,
1021
+ trust: trust === 'auto' ? `Tasks from ${handle} run without asking now.` : `Each task from ${handle} is asked about now.`,
1022
+ handle: `Your 通讯号 is ${data.handle} now.`,
1023
+ }[action];
1024
+ const added = action === 'add' && data.contacts?.find((x) => x.handle === handle.toLowerCase().replace(/^@/, ''))?.status === 'accepted';
1025
+ if (done) out(c.green('✔ ') + (added ? `${handle} had asked you already: you are contacts now.` : done));
1026
+ if (action === 'accept' || action === 'remove' || action === 'block' || added) app.refreshRemotePeers();
1027
+ if (action && action !== 'handle') return;
1028
+ const rows = Array.isArray(data.contacts) ? data.contacts : [];
1029
+ out([
1030
+ `Your 通讯号: ${c.bold(data.handle)} ${c.dim('(the name others add you by; /contacts handle NEW changes it)')}`,
1031
+ ...rows.map((x) => {
1032
+ const online = x.status === 'accepted' ? c.dim(` · ${x.online ? `${x.online} session${x.online === 1 ? '' : 's'} online` : 'no session online'} · tasks: ${x.trust === 'auto' ? 'run without asking' : 'asked about each time'}`) : '';
1033
+ return ` ${c.bold(x.handle)} ${CONTACT_LABELS[x.status] || x.status}${online}`;
1034
+ }),
1035
+ ...(rows.length ? [] : [c.dim(' No contacts yet.')]),
1036
+ c.dim('/contacts add 通讯号 asks someone; accept / reject / remove / block 通讯号; trust 通讯号 auto|confirm. A contact sees only the name, computer and state of your online sessions; their tasks are asked about here before they run, unless you set trust to auto. In /peers their sessions show as @通讯号:computer/name.'),
1037
+ ]);
1038
+ },
1039
+ });
1040
+
892
1041
  add({
893
1042
  name: 'rename',
894
1043
  argHint: '<name>',
@@ -1060,7 +1209,7 @@ export function buildCommands(app) {
1060
1209
  name: 'bashes',
1061
1210
  description: 'List background shells',
1062
1211
  run() {
1063
- const list = listBackgroundShells();
1212
+ const list = listBackgroundShells(app.config.owner);
1064
1213
  out(list.length ? list.map((b) => `${c.bold(b.id)} ${b.status}${b.exitCode !== null ? ` (exit ${b.exitCode})` : ''} ${c.dim(truncate(b.command, 60))}`) : [c.dim('No background shells')]);
1065
1214
  },
1066
1215
  });