@yanzc/claude-pro 0.5.9 → 0.6.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 +21 -8
- package/package.json +1 -1
- package/src/agents.js +3 -1
- package/src/commands.js +46 -47
- package/src/config.js +16 -7
- package/src/host.js +1031 -0
- package/src/main.js +19 -4
- package/src/prompts.js +74 -58
- package/src/qr.js +1 -1
- package/src/remote.js +4 -2
- package/src/runtime.js +14 -8
- package/src/session.js +5 -2
- package/src/supervisor.js +1 -1
- package/src/tools/bash.js +3 -8
- package/src/tools/files.js +6 -10
- package/src/tools/index.js +1 -1
- package/src/tools/interaction.js +8 -37
- package/src/tools/search.js +15 -10
- package/src/tools/task.js +29 -7
- package/src/ui/repl.js +89 -45
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ claude-pro config set CLAUDE_PRO_PROVIDER claude-code
|
|
|
80
80
|
什么都没配置时(没有 `CLAUDE_PRO_PROVIDER`,也没有 `ANTHROPIC_BASE_URL`/`ANTHROPIC_AUTH_TOKEN`/`ANTHROPIC_API_KEY`/`ANTHROPIC_MODEL`)默认用**网关**,第一次启动直接弹出登录选择(网关排第一);配置了 API 端点、密钥或模型的老用户仍然默认 `api`。交互界面里 `/login` 选择模型请求发往哪里(记在 `~/.claude-pro/settings.json` 的 `CLAUDE_PRO_PROVIDER`,每个后端各自记住 `/model`、`/effort`):
|
|
81
81
|
|
|
82
82
|
- **Claude 订阅**(`claude-code`):本机 Claude Code 的登录,见上一节。
|
|
83
|
-
- **网关**(`gateway`):[codex-gateway](../codex-gateway) 的账户,默认 `https://gw.predix.icu`(`CLAUDE_PRO_GATEWAY_URL` 可改)。第一次选它会在浏览器打开网关的登录页,登录(或注册)后点“授权”,浏览器被带回本机,claude-pro 用一次性 code 换到这台电脑专用的 API Key,存在 `~/.claude-pro/gateway.json`(仅本人可读)。费用从网关账户余额扣,`/cost` 显示余额,充值和用量在网关的 `/user` 页面。模型默认 `opus`,`/model` 可选 `sonnet`、`haiku`、`gpt-6.1-sol`(网关用它自己的 Codex 登录转发,按 OpenAI 官方价扣费);子 agent 在 Claude
|
|
83
|
+
- **网关**(`gateway`):[codex-gateway](../codex-gateway) 的账户,默认 `https://gw.predix.icu`(`CLAUDE_PRO_GATEWAY_URL` 可改)。第一次选它会在浏览器打开网关的登录页,登录(或注册)后点“授权”,浏览器被带回本机,claude-pro 用一次性 code 换到这台电脑专用的 API Key,存在 `~/.claude-pro/gateway.json`(仅本人可读)。费用从网关账户余额扣,`/cost` 显示余额,充值和用量在网关的 `/user` 页面。模型默认 `opus`,`/model` 可选 `sonnet`、`haiku`、`gpt-6.1-sol`(网关用它自己的 Codex 登录转发,按 OpenAI 官方价扣费);子 agent 在 Claude 主模型下没有固定模型:主 agent 每次调用 `Task` 按任务难易自己选 `haiku`(查找、读文件)、`sonnet`(搜索、步骤清楚的子任务)或 `opus`(难调的 bug、设计、审查等结论要依赖的分析),`Task` 的说明里列着三者的实际模型和价格;没选时用主模型(GPT 主模型下子 agent 用主模型)。网关每次请求按 `max_tokens` 预扣余额,所以这里默认 `max_tokens` 是 48K(Opus 预扣 $0.96,请求结束按实际输出扣费;`CLAUDE_CODE_MAX_OUTPUT_TOKENS` 可改)。每个请求带上会话 ID(`X-Claude-Code-Session-Id`,和 Claude Code 一样;子 agent 用主对话的,`/clear` 换新的,`--resume` 和自动重启沿用原来的),网关据此让同一个对话 1 小时内继续用同一个上游账号,提示词缓存才不会因为换账号而失效。`/logout` 删除本机的网关 Key。
|
|
84
84
|
- **Codex 订阅**(`codex`):本机 `codex login`(ChatGPT 套餐)写下的 `~/.codex/auth.json`(`CODEX_HOME` 可改)。请求直接发往 Codex 后端,Anthropic 格式在本机和 OpenAI Responses 格式互相转换(工具调用、推理、缓存用量都对应上);访问令牌快到期时用同一文件里的刷新令牌续期并写回,Codex CLI 也能接着用。模型默认取 `~/.codex/config.toml` 的 `model`,否则 `gpt-6.1-sol`;不设 effort 时用模型自己的默认值(`models_cache.json` 里写的)。
|
|
85
85
|
|
|
86
86
|
## 配置
|
|
@@ -169,7 +169,7 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
|
|
|
169
169
|
|
|
170
170
|
交互式会话运行在一个很薄的**监督进程**(`src/supervisor.js`,只用 Node 内置模块)之下,所以程序可以自己重启、加载自己刚改过的代码,不需要你退出再启动:
|
|
171
171
|
|
|
172
|
-
- **模型自己重启**:改完 `src/`、`bin/` 里的代码后,模型调用 `Restart` 工具。它先在一个临时进程里把新代码完整启动一遍(所有模块能加载、界面能画出来、工具定义和系统提示词合法)——**启动不起来就不重启**,把错误还给模型去修,修好再调用;通过后在**本回合结束时**重启,对话、待办列表、`/model`、`/effort`、计划模式、排队的消息、输入框里没发出去的草稿、`/rewind` 检查点都带过去,新进程里模型收到一条"已重启"的提示后接着做(可用 `then`
|
|
172
|
+
- **模型自己重启**:改完 `src/`、`bin/` 里的代码后,模型调用 `Restart` 工具。它先在一个临时进程里把新代码完整启动一遍(所有模块能加载、界面能画出来、工具定义和系统提示词合法)——**启动不起来就不重启**,把错误还给模型去修,修好再调用;通过后在**本回合结束时**重启,对话、待办列表、`/model`、`/effort`、计划模式、排队的消息、输入框里没发出去的草稿、`/rewind` 检查点都带过去,新进程里模型收到一条"已重启"的提示后接着做(可用 `then` 指定重启后先验证什么)。只在**源码仓库**(有 `.git` 的克隆,包括 `npm link` 到它)里这样做:从 npm 装的副本没有版本控制、下次更新会被覆盖,那里不给模型 `Restart` 工具,系统提示词改成"不要改自己的文件,绕过问题并在最后说明缺陷,方便用户反馈"。
|
|
173
173
|
- **改了源码自动重启**:一个回合结束(或空闲)时,如果 `src/`、`bin/` 下的文件变过,就自动做同样的检查并重启。检查不通过只提示错误、不重启。按 Esc 打断的那一回合不会触发。`CLAUDE_PRO_AUTO_RESTART=0` 关闭。
|
|
174
174
|
- **手动**:`/restart`(别名 `/reload`),`/restart force` 跳过检查并无视后台任务。
|
|
175
175
|
- 后台 agent / 后台 shell 会被重启杀掉,所以有它们在跑时拒绝重启(可 `force`)。5 分钟内重启超过 5 次视为死循环,拒绝。
|
|
@@ -179,15 +179,28 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
|
|
|
179
179
|
|
|
180
180
|
## 远程控制:在浏览器或手机上看执行过程、下发指令
|
|
181
181
|
|
|
182
|
-
和 Claude Code 的 `/remote-control`
|
|
182
|
+
和 Claude Code 的 `/remote-control` 一样,可以在手机或另一台电脑上看着会话干活,并给它发指令;这里**不用任何命令或设置**。官方版经 Anthropic 中转,这里经**网关**(gw.predix.icu,即 `CLAUDE_PRO_GATEWAY_URL`)中转:claude-pro 只向网关发出站请求,**不监听任何端口,不走局域网**;在网关用户端登录后,左侧菜单"**远程控制**"里按电脑分组列出自己的会话,可以查看、操作,也可以在某台电脑上新建会话(见下面"从网页新建会话")。模型请求走哪个提供方都可以,远程控制只用网关的登录。
|
|
183
183
|
|
|
184
|
-
-
|
|
184
|
+
- **默认在线**:这台电脑登录了网关(`/login` 选网关)以后,每个交互会话启动时自动连上网关(不阻塞启动,断开后自动重连),网页上能看到这台电脑上所有开着的会话,别的电脑也能给它们发任务(见下一节)。`/login` 登录成功后当前会话**马上上线**(不用重启),并打印它的链接;`/logout` 后马上下线;在别的窗口登录或退出,这个窗口几秒内跟上。想让模型请求走 Claude 订阅:先 `/login` 选网关登录,再 `/login` 选 Claude 订阅,网关登录保留,会话照样在线。
|
|
185
|
+
- **链接和二维码**:`/status` 显示这个会话的远程状态(在线、连接中、没登录、key 被拒…)、它在网关上的链接(`https://gw.predix.icu/user#remote/<id>`)和二维码,手机扫码即可打开(没登录时先登录,登录后直接进入这个会话)。所有会话的列表在 `/user#remote`。在线时输入框右上角显示 `⇄ &名字`,有网页在看时页脚显示 `⇄ N watching`。
|
|
185
186
|
- **网页上能看到**:完整对话(用户消息、流式输出的回答、可展开的思考、工具调用和结果,包括 diff 和正在运行的命令的最新几行输出)、斜杠命令和提示的输出、当前状态(正在想/运行多久/多少 token、限流暂停的倒计时)、待办列表、排队中的消息。
|
|
186
187
|
- **网页上能做**:发消息(和在终端里输入完全一样:忙的时候排队插入,`/命令`、`!shell` 都可以)、**Stop**(等于 Esc)、回答模型的提问(`AskUserQuestion`,含多选和"其他")、批准/拒绝计划、以及 `/model`、`/rewind` 之类命令弹出的选择框。终端和网页可以交替使用,两边同步。
|
|
187
188
|
- **安全**:只有同一个网关账户登录后才能看到和操作这个会话;**能登录这个网关账户的人,就能通过它在这台电脑上以完全权限执行命令**。会话内容经网关中转并暂存在网关上。
|
|
188
189
|
- **省流量**:没人打开网页时只上报状态(列表里的标题、忙/闲),不上传对话;有人打开时先发一份完整快照,再实时推送。
|
|
189
190
|
- **重启不断线**:自动重启(改了源码、自动更新)沿用同一个会话 id,网页显示"重启中"后接着看;网关重启丢了状态时,claude-pro 自动重新注册并补发完整对话。
|
|
190
|
-
-
|
|
191
|
+
- 一个会话对应网关上的一个远程会话。每个网关账户最多 20 个(超出时淘汰最久没活动的离线会话);已结束的会话在列表里保留 6 小时,断开但没结束的保留 24 小时。不支持从网页上传图片。
|
|
192
|
+
- 不想在线:`/logout`(这台电脑的会话和电脑服务都会下线)。
|
|
193
|
+
|
|
194
|
+
### 从网页新建会话(电脑服务 `claude-pro host`)
|
|
195
|
+
|
|
196
|
+
在网关"远程控制"页点**新建会话**,选一台电脑、浏览它的目录(上面列出最近用过的目录)、点创建:那台电脑上弹出一个新的终端窗口,在选的目录里运行 claude-pro,网页直接打开这个会话。一台电脑可以开很多个。
|
|
197
|
+
|
|
198
|
+
- **终端窗口**:Windows 用 Windows Terminal(没装时是普通控制台窗口);macOS 用"终端";Linux 桌面上用 x-terminal-emulator / gnome-terminal / konsole / xterm 里第一个有的;没有桌面的 Linux 开一个 tmux 会话(`tmux attach -t claude-pro-<id>` 可以接上,网页照常用)。
|
|
199
|
+
- **靠电脑服务**:每台电脑一个后台进程(`claude-pro host`),用 `/login` 存下的网关 key 连到网关,只发出站请求。**不用手动启动**:登录了网关的会话启动时,发现它没在运行就在后台把它拉起来(不弹窗口),会话关掉后它继续运行,所以电脑上没开着 claude-pro 也能从网页新建。设 `CLAUDE_PRO_HOST=0` 就不自动拉起。
|
|
200
|
+
- **开机自动启动**:`claude-pro host install`(Windows 在"启动"文件夹放一个不弹窗口的 .vbs;macOS 是 LaunchAgent;Linux 桌面是自动启动项,没有桌面时是 systemd 用户服务,要不登录也运行就 `loginctl enable-linger`);`claude-pro host uninstall` 撤销。
|
|
201
|
+
- **其他命令**:`claude-pro host status`(是否在运行、在线、日志位置);`claude-pro host stop`(停掉,并把这台电脑从网页列表里去掉;之后会话不再自动拉起它,`claude-pro host start` 才重新启动);`claude-pro host`(在前台运行,看日志调试用)。日志在 `~/.claude-pro/host.log`,状态在 `~/.claude-pro/host.json`。
|
|
202
|
+
- **跟着登录走**:`/logout` 后服务从网页列表下线并等待;重新 `/login`(也可以是另一个账户)后自动注册上。claude-pro 升级或源码改动后,服务一两分钟内自己换成新版本。
|
|
203
|
+
- **安全**:和远程控制一样,能登录这个网关账户的人,可以在这台电脑上任意目录打开会话、以完全权限执行命令。
|
|
191
204
|
|
|
192
205
|
## 会话之间互发任务(本机和其他电脑)
|
|
193
206
|
|
|
@@ -205,7 +218,7 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
|
|
|
205
218
|
- **`/rename 新名字`**:给当前会话改名(比如 `/rename web-server`),别的会话从此用 `&web-server` 找它;这个名字也成为对话标题(终端标签页、`/resume` 列表、网页),不再自动按话题改;`/resume` 这个对话时名字一起回来。
|
|
206
219
|
- **`/peers`**:列出本机和其他电脑上在线的会话。模型也能用 ListPeers / MessagePeer 工具自己找别的会话分派任务。
|
|
207
220
|
- 回答会在对方这一轮做完后自动发回;对方正忙时,任务排在它当前工作之后。网关替离线的会话暂存回答(24 小时;网关重启会丢失还没送达的消息)。
|
|
208
|
-
- **安全**:在线的会话能被同一网关账户执行任何任务。能登录这个账户、或持有它任一 API key
|
|
221
|
+
- **安全**:在线的会话能被同一网关账户执行任何任务。能登录这个账户、或持有它任一 API key 的人,都能在这些电脑上以完全权限执行命令。不需要时 `/logout`。
|
|
209
222
|
|
|
210
223
|
## 完全访问与安全网
|
|
211
224
|
|
|
@@ -219,7 +232,7 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
|
|
|
219
232
|
|
|
220
233
|
| 项目 | 以前 | 现在 |
|
|
221
234
|
|---|---|---|
|
|
222
|
-
| 单次输出 `max_tokens` | 32000 | 128000
|
|
235
|
+
| 单次输出 `max_tokens` | 32000 | 128000(网关 48000,网关按它预扣余额);如果 API 允许的更少,会从报错里读出真实上限并自动降下来 |
|
|
223
236
|
| Bash 默认 / 最长超时 | 2 分钟 / 10 分钟 | 10 分钟 / 1 小时 |
|
|
224
237
|
| Bash 输出返回给模型的上限 | 30000 字符 | 60000 字符,超出部分的全文保存到文件 |
|
|
225
238
|
| 单个工具结果上限(超出落盘) | 50000 字符 | 100000 字符 |
|
|
@@ -247,7 +260,7 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
|
|
|
247
260
|
- 上下文用量接近阈值时自动压缩(`CLAUDE_CODE_AUTO_COMPACT_WINDOW`),也可手动 `/compact`
|
|
248
261
|
- 会话自动保存到 `~/.claude-pro/projects/`,`claude-pro -c` 继续上次,`claude-pro -r` 选择历史会话
|
|
249
262
|
|
|
250
|
-
**斜杠命令**:`/help` `/tui` `/rename` `/peers` `/sendfile` `/clear` `/compact` `/config` `/model` `/effort` `/status` `/cost` `/context` `/init` `/review` `/memory` `/verify` `/tasks` `/plan` `/rewind` `/skills` `/resume` `/todos` `/agents` `/mcp` `/bashes` `/verbose` `/export` `/doctor` `/
|
|
263
|
+
**斜杠命令**:`/help` `/tui` `/rename` `/peers` `/sendfile` `/clear` `/compact` `/config` `/model` `/effort` `/status` `/cost` `/context` `/init` `/review` `/memory` `/verify` `/tasks` `/plan` `/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` ``)。
|
|
251
264
|
|
|
252
265
|
**记忆**:自动读取 `~/.claude-pro/CLAUDE.md`、项目各级目录的 `CLAUDE.md` / `.claude/CLAUDE.md` / `CLAUDE.local.md`;某一级目录没有 `CLAUDE.md` 时读它的 `AGENTS.md` 代替(与 Claude Code 相同,两者都有时通常是同一份说明,不重复发送)。
|
|
253
266
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanzc/claude-pro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "claude-pro: a self-implemented coding agent for Anthropic-compatible APIs or local Claude Code subscription login. Full access with no permission prompts; file edits are checkpointed and can be rewound.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
package/src/agents.js
CHANGED
|
@@ -20,12 +20,14 @@ export const BUILTIN_AGENTS = [
|
|
|
20
20
|
name: 'Explore',
|
|
21
21
|
description: 'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick", "medium", or "very thorough".',
|
|
22
22
|
tools: READ_ONLY_TOOLS,
|
|
23
|
-
|
|
23
|
+
readOnly: true, // its prompt forbids changes: no boundaries or project instructions in its system prompt
|
|
24
|
+
prompt: 'You are a file search specialist. You excel at thoroughly navigating and exploring codebases.\n\nThis is a READ-ONLY exploration task. You must not create, modify or delete files, and must only run Bash commands that change nothing (such as ls, find, git status, git log, git diff, git show, git blame, or a script that only prints).\n\nUse Glob for broad file pattern matching, Grep for searching file contents with regex, and Read when you know the specific file path. Adapt your search approach to the thoroughness level specified by the caller. Make parallel tool calls wherever possible. Return file paths as absolute paths and report your findings clearly.',
|
|
24
25
|
},
|
|
25
26
|
{
|
|
26
27
|
name: 'Plan',
|
|
27
28
|
description: 'Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.',
|
|
28
29
|
tools: READ_ONLY_TOOLS,
|
|
30
|
+
readOnly: true,
|
|
29
31
|
prompt: 'You are a software architect and planning specialist. Explore the codebase with read-only tools and design an implementation plan.\n\nThis is a READ-ONLY task: do not create, modify or delete files, and only run read-only Bash commands.\n\nProcess: understand the requirements; explore thoroughly (existing patterns, similar features, architecture); design the solution with trade-offs; detail the plan step by step with sequencing and dependencies. End your response with a "Critical Files for Implementation" list of 3-5 files, with a brief reason for each.',
|
|
30
32
|
},
|
|
31
33
|
];
|
package/src/commands.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { c, padEnd, truncate } from './ui/ansi.js';
|
|
5
|
+
import { c, padEnd, truncate, colorEnabled } from './ui/ansi.js';
|
|
6
6
|
import { SelectDialog } from './ui/dialogs.js';
|
|
7
7
|
import { renderTodos, resultLines, formatTokens, formatDuration } from './ui/render.js';
|
|
8
8
|
import { loadConfig, settingsFiles, updateSettingsFile, rememberChoice, applyRememberedChoices, KNOWN_KEYS, VERSION, APP_NAME, CONFIG_DIR } from './config.js';
|
|
9
|
-
import { loginWithBrowser, readGatewayLogin, clearGatewayLogin, fetchGatewayAccount, fetchGatewayModels, cachedGatewayModel, gatewayEfforts, formatUsd
|
|
9
|
+
import { loginWithBrowser, readGatewayLogin, clearGatewayLogin, fetchGatewayAccount, fetchGatewayModels, cachedGatewayModel, gatewayEfforts, formatUsd } from './gateway.js';
|
|
10
10
|
import { codexLoginSummary, codexModels, codexEfforts } from './codex/client.js';
|
|
11
11
|
import { readClaudeCodeLogin } from './claude-code.js';
|
|
12
12
|
import { SessionStore } from './session.js';
|
|
@@ -21,6 +21,8 @@ import { displayPath } from './utils/paths.js';
|
|
|
21
21
|
import { cleanName, machineName } from './peers.js';
|
|
22
22
|
import { rewind, promptAt } from './checkpoints.js';
|
|
23
23
|
import { canRestart, runSelfCheck } from './restart.js';
|
|
24
|
+
import { describeHost } from './host.js';
|
|
25
|
+
import { qrLines } from './qr.js';
|
|
24
26
|
|
|
25
27
|
const EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
26
28
|
const isGpt = (modelId) => /^gpt-/i.test(modelId);
|
|
@@ -327,6 +329,16 @@ export function buildCommands(app) {
|
|
|
327
329
|
};
|
|
328
330
|
const accountLine = (account) => `${account.name || ''}${account.email ? ` <${account.email}>` : ''} · balance ${c.bold(formatUsd(account.available_usd ?? account.balance_usd))}`;
|
|
329
331
|
let pendingLogin = null;
|
|
332
|
+
// Logged in to the gateway: this session goes online there at once (remote control, the other computers'
|
|
333
|
+
// sessions), and the computer service starts (the web page opens new sessions through it).
|
|
334
|
+
const goOnline = async () => {
|
|
335
|
+
const remote = await app.syncRemote();
|
|
336
|
+
app.ensureHost();
|
|
337
|
+
if (!remote) return;
|
|
338
|
+
out(remote.url
|
|
339
|
+
? `${c.green('⇄')} This session is online at the gateway: ${c.blue(remote.url)} ${c.dim('(/status shows it, with a QR code for a phone)')}`
|
|
340
|
+
: c.dim(`⇄ This session goes online at the gateway as soon as ${remote.base} can be reached.`));
|
|
341
|
+
};
|
|
330
342
|
|
|
331
343
|
add({
|
|
332
344
|
name: 'login',
|
|
@@ -381,6 +393,7 @@ export function buildCommands(app) {
|
|
|
381
393
|
const account = await fetchGatewayAccount(saved);
|
|
382
394
|
const note = switchProvider('gateway');
|
|
383
395
|
out([`Using the gateway ${c.bold(url)}: ${cfg.mainModel.label}${note}`, accountLine(account), c.dim(`Top up and usage: ${url}/user · another account: /logout, then /login`)]);
|
|
396
|
+
await goOnline();
|
|
384
397
|
return;
|
|
385
398
|
} catch (e) {
|
|
386
399
|
if (e.status !== 401 && e.status !== 403) { out(c.red(`Cannot reach the gateway ${url}: ${e.message}`)); return; }
|
|
@@ -398,6 +411,7 @@ export function buildCommands(app) {
|
|
|
398
411
|
});
|
|
399
412
|
const note = switchProvider('gateway');
|
|
400
413
|
out([`Logged in to the gateway ${c.bold(url)}: ${cfg.mainModel.label}${note}`, accountLine(login.balance || login.account), c.dim(`Top up and usage: ${url}/user`)]);
|
|
414
|
+
await goOnline();
|
|
401
415
|
} catch (e) {
|
|
402
416
|
if (e.name !== 'AbortError') out(c.red(`Gateway login failed: ${e.message}`));
|
|
403
417
|
} finally {
|
|
@@ -408,11 +422,15 @@ export function buildCommands(app) {
|
|
|
408
422
|
|
|
409
423
|
add({
|
|
410
424
|
name: 'logout',
|
|
411
|
-
description: 'Forget the gateway login of this machine',
|
|
425
|
+
description: 'Forget the gateway login of this machine (its sessions go offline there)',
|
|
412
426
|
run() {
|
|
413
427
|
const cfg = app.runtime.config;
|
|
414
428
|
const had = clearGatewayLogin();
|
|
415
|
-
|
|
429
|
+
const wasOnline = Boolean(app.remote);
|
|
430
|
+
app.stopRemote(); // the other sessions of this computer and its computer service follow within seconds
|
|
431
|
+
out(had
|
|
432
|
+
? `Logged out of the gateway ${cfg.gatewayUrl}.${wasOnline ? ' This session is offline there now.' : ''}${cfg.usesGateway ? ' Run /login to log in again or choose another provider.' : ''}`
|
|
433
|
+
: c.dim('There was no gateway login. (The Claude and Codex subscription logins belong to their own CLIs.)'));
|
|
416
434
|
},
|
|
417
435
|
});
|
|
418
436
|
|
|
@@ -437,7 +455,7 @@ export function buildCommands(app) {
|
|
|
437
455
|
: cfg.usesCodex ? (() => { const s = codexLoginSummary({ ...process.env, ...cfg.env }); return s.ok ? `Codex login${s.email ? ` of ${s.email}` : ''}${s.plan ? ` (${s.plan})` : ''} ${c.dim(s.file)}` : c.red(s.error); })()
|
|
438
456
|
: cfg.authToken ? `ANTHROPIC_AUTH_TOKEN (${cfg.display('ANTHROPIC_AUTH_TOKEN')})` : cfg.apiKey ? `ANTHROPIC_API_KEY (${cfg.display('ANTHROPIC_API_KEY')})` : c.red('none')),
|
|
439
457
|
row('Model', `${cfg.mainModel.label} ${c.dim(`(sent as "${cfg.mainModel.id}", ${formatTokens(cfg.mainModel.contextWindow)} context)`)}`),
|
|
440
|
-
row('Sub-agent model', cfg.subagentModel.label),
|
|
458
|
+
row('Sub-agent model', cfg.subagentModelChosen ? `chosen per task by difficulty ${c.dim(`(haiku, sonnet or opus; not chosen: ${cfg.subagentModel.label})`)}` : cfg.subagentModel.label),
|
|
441
459
|
row('Small model', cfg.smallModel.label),
|
|
442
460
|
row('Effort', cfg.effort || 'auto'),
|
|
443
461
|
row('Max output', formatTokens(cfg.maxOutputTokens)),
|
|
@@ -449,10 +467,32 @@ export function buildCommands(app) {
|
|
|
449
467
|
row('ripgrep', hasRipgrep(cfg) ? 'yes' : 'no (using JS fallback)'),
|
|
450
468
|
row('Memory', mem.length ? mem.map((m) => m.file).join(', ') : c.dim('none')),
|
|
451
469
|
row('MCP servers', mcp.length ? mcp.map((m) => `${m.name} (${m.status})`).join(', ') : c.dim('none')),
|
|
470
|
+
'',
|
|
471
|
+
...remoteLines(row),
|
|
452
472
|
], '');
|
|
453
473
|
},
|
|
454
474
|
});
|
|
455
475
|
|
|
476
|
+
// /status about the gateway: this session there (its page, and a QR code of it for a phone), its name for the
|
|
477
|
+
// sessions on the other computers, and the computer service.
|
|
478
|
+
function remoteLines(row) {
|
|
479
|
+
const cfg = app.runtime.config;
|
|
480
|
+
const remote = app.remoteState();
|
|
481
|
+
const me = app.peerLabel();
|
|
482
|
+
const lines = [
|
|
483
|
+
row('Remote control', remote.text),
|
|
484
|
+
...(remote.url ? [row('', c.blue(remote.url))] : []),
|
|
485
|
+
row('Name', `&${me} ${c.dim(`(on your other computers: &${machineName(cfg.env)}/${me}; /rename changes it)`)}`),
|
|
486
|
+
row('Computer service', describeHost(cfg.env)),
|
|
487
|
+
];
|
|
488
|
+
const qr = remote.url && app.remote?.online ? qrLines(remote.url, { color: colorEnabled }) : null;
|
|
489
|
+
if (qr) {
|
|
490
|
+
lines.push('', c.dim(' Scan with a phone to open this session (log in to the gateway there):'), ...qr.map((l) => ` ${l}`));
|
|
491
|
+
lines.push(c.dim(` Whoever can log in to this gateway account, or holds one of its API keys, can run anything on this computer through it.`));
|
|
492
|
+
}
|
|
493
|
+
return lines;
|
|
494
|
+
}
|
|
495
|
+
|
|
456
496
|
add({
|
|
457
497
|
name: 'cost',
|
|
458
498
|
aliases: ['usage'],
|
|
@@ -594,7 +634,7 @@ export function buildCommands(app) {
|
|
|
594
634
|
...(local.length || remote.length ? [] : [c.dim('No other session is running.')]),
|
|
595
635
|
c.dim(online
|
|
596
636
|
? 'Type "&" for the 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. /sendfile &name file... sends files (saved in its Downloads folder). /rename names this session. The agent can use ListPeers / MessagePeer too.'
|
|
597
|
-
: 'Type "&" for the 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 (/login
|
|
637
|
+
: 'Type "&" for the 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 (/login; /status says why it is not).'),
|
|
598
638
|
]);
|
|
599
639
|
},
|
|
600
640
|
});
|
|
@@ -643,47 +683,6 @@ export function buildCommands(app) {
|
|
|
643
683
|
},
|
|
644
684
|
});
|
|
645
685
|
|
|
646
|
-
add({
|
|
647
|
-
name: 'remote-control',
|
|
648
|
-
aliases: ['rc'],
|
|
649
|
-
argHint: '[stop | open]',
|
|
650
|
-
description: 'Watch and steer this session from a browser or phone, through the gateway (its 远程控制 page): prints the link and a QR code',
|
|
651
|
-
async run(args) {
|
|
652
|
-
const action = args.trim().toLowerCase();
|
|
653
|
-
if (/^(stop|off|disconnect)$/.test(action)) {
|
|
654
|
-
if (!app.remote) { out(c.dim('Remote control is not on.')); return; }
|
|
655
|
-
app.stopRemote();
|
|
656
|
-
out('Remote control is off: the gateway no longer reaches this session.');
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
if (app.remote) log(app.remoteInfo());
|
|
660
|
-
else {
|
|
661
|
-
const url = app.runtime.config.gatewayUrl;
|
|
662
|
-
// It goes through the gateway account: log in to it first (in the browser) when this machine is not; the
|
|
663
|
-
// provider of the model requests stays what it is.
|
|
664
|
-
if (!readGatewayLogin(url)) {
|
|
665
|
-
pendingLogin?.abort();
|
|
666
|
-
const controller = new AbortController();
|
|
667
|
-
pendingLogin = controller;
|
|
668
|
-
try {
|
|
669
|
-
await loginWithBrowser({
|
|
670
|
-
url,
|
|
671
|
-
signal: controller.signal,
|
|
672
|
-
onUrl: (page) => out([`Remote control goes through the gateway ${c.bold(url)}: log in to it in your browser. If it does not open, visit:`, c.blue(page), c.dim('Waiting for the browser (10 minutes at most)…')]),
|
|
673
|
-
});
|
|
674
|
-
} catch (e) {
|
|
675
|
-
if (e.name !== 'AbortError') out(c.red(`Gateway login failed: ${e.message}`));
|
|
676
|
-
return;
|
|
677
|
-
} finally {
|
|
678
|
-
if (pendingLogin === controller) pendingLogin = null;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
try { await app.startRemote(); } catch (e) { out(c.red(`Could not start remote control: ${e.message}`)); return; }
|
|
682
|
-
}
|
|
683
|
-
if (action === 'open' && app.remote.url && !openBrowser(app.remote.url)) out(c.yellow(`Could not open a browser: open ${app.remote.url}`));
|
|
684
|
-
},
|
|
685
|
-
});
|
|
686
|
-
|
|
687
686
|
add({
|
|
688
687
|
name: 'plan',
|
|
689
688
|
description: 'Toggle read-only plan mode (same as shift+tab)',
|
package/src/config.js
CHANGED
|
@@ -18,6 +18,9 @@ import { normalizeTtl } from './cache.js';
|
|
|
18
18
|
import { codexModels, codexConfigDefaults } from './codex/client.js';
|
|
19
19
|
|
|
20
20
|
export const INSTALL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
|
+
// A source checkout (a git clone, also when npm links to one), as opposed to a copy installed from npm: the agent
|
|
22
|
+
// edits its own code only in a checkout, since the next update replaces an installed copy.
|
|
23
|
+
export const SOURCE_CHECKOUT = fs.existsSync(path.join(INSTALL_DIR, '.git'));
|
|
21
24
|
export const CONFIG_DIR = process.env.CLAUDE_PRO_CONFIG_DIR || path.join(os.homedir(), '.claude-pro');
|
|
22
25
|
export const APP_NAME = 'claude-pro';
|
|
23
26
|
export const PROVIDERS = ['api', 'claude-code', 'gateway', 'codex'];
|
|
@@ -36,7 +39,8 @@ export const KNOWN_KEYS = {
|
|
|
36
39
|
CLAUDE_PRO_CLAUDE_CREDENTIALS_FILE: 'Existing Claude Code OAuth credentials file (default: ~/.claude/.credentials.json)',
|
|
37
40
|
CLAUDE_PRO_CLAUDE_CODE_VERSION: 'Claude Code version in the HTTP User-Agent (default: installed npm version)',
|
|
38
41
|
CLAUDE_PRO_DISABLE_TOKEN_REFRESH: 'Set to 1 to stop this program renewing the Claude Code login by itself (it then only reads what the official client keeps up to date)',
|
|
39
|
-
CLAUDE_PRO_ONLINE: '
|
|
42
|
+
CLAUDE_PRO_ONLINE: 'Internal (the self-check and the tests set it): 0 keeps interactive sessions off the gateway. Otherwise a session is online there whenever this computer is logged in to the gateway: its 远程控制 page shows it, and sessions on your other computers can send it tasks (&computer/name)',
|
|
43
|
+
CLAUDE_PRO_HOST: 'Set to 0 so that sessions do not start the computer service (claude-pro host) by themselves; the service lets the gateway\'s 远程控制 page open new sessions on this computer',
|
|
40
44
|
CLAUDE_PRO_DOWNLOAD_DIR: 'Where files that other sessions send this one are saved (default: the Downloads folder)',
|
|
41
45
|
CLAUDE_PRO_MACHINE_NAME: 'This computer\'s name for sessions on your other computers (@公司 ...; default: the host name)',
|
|
42
46
|
CLAUDE_PRO_TUI: 'fullscreen (default: the input box fixed at the bottom, the conversation scrolled inside, like Claude Code\'s /tui fullscreen) or default (classic: it scrolls in the terminal); /tui switches',
|
|
@@ -60,7 +64,7 @@ export const KNOWN_KEYS = {
|
|
|
60
64
|
CLAUDE_CODE_AUTO_COMPACT_WINDOW: 'Context size (tokens) used for auto-compaction calculations',
|
|
61
65
|
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: 'Percentage (1-100) of the window at which auto-compaction triggers',
|
|
62
66
|
DISABLE_AUTOCOMPACT: 'Set to 1 to disable auto-compaction',
|
|
63
|
-
CLAUDE_CODE_MAX_OUTPUT_TOKENS: 'max_tokens for each model response (default 128000; lowered automatically if the API allows less)',
|
|
67
|
+
CLAUDE_CODE_MAX_OUTPUT_TOKENS: 'max_tokens for each model response (default 128000, 48000 with the gateway; lowered automatically if the API allows less)',
|
|
64
68
|
MAX_THINKING_TOKENS: 'Thinking budget: 0 disables thinking, N enables with budget N',
|
|
65
69
|
CLAUDE_CODE_PROMPT_CACHE_TTL: 'Prompt cache TTL of the conversation itself: 5m or 1h (default: 1h with the subscription login, as in Claude Code, and with the gateway, else 5m; 1h writes cost more, they pay off when you pause for more than 5 minutes). Also the promptCacheTtl setting',
|
|
66
70
|
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL: 'Prompt cache TTL of everything else (sub-agents, compaction, side queries): 5m (default) or 1h. Also the subagentPromptCacheTtl setting',
|
|
@@ -313,11 +317,15 @@ export class Config {
|
|
|
313
317
|
// With the subscription login sub-agents run on Sonnet: much cheaper than Opus, and good at the searching and
|
|
314
318
|
// well-specified subtasks they are given. CLAUDE_PRO_CLAUDE_CODE_SUBAGENT_MODEL (or a sub-agent's own model) changes it.
|
|
315
319
|
if (this.usesClaudeCode) return this.resolveModel(this.env.CLAUDE_PRO_CLAUDE_CODE_SUBAGENT_MODEL || 'sonnet');
|
|
316
|
-
// The gateway:
|
|
317
|
-
|
|
320
|
+
// The gateway: no fixed sub-agent model. Under a Claude main model the main agent picks one for each Task by how
|
|
321
|
+
// hard the task is (see subagentModelChosen and the Task tool's description); this is what an agent runs on when
|
|
322
|
+
// it was not given one: the main model. A GPT main model keeps its own.
|
|
323
|
+
if (this.usesGateway) return this.mainModel;
|
|
318
324
|
if (this.usesCodex) return this.mainModel;
|
|
319
325
|
return this.env.CLAUDE_CODE_SUBAGENT_MODEL ? this.resolveModel(this.env.CLAUDE_CODE_SUBAGENT_MODEL) : this.mainModel;
|
|
320
326
|
}
|
|
327
|
+
// The main agent chooses each sub-agent's model (haiku, sonnet, opus) by the task, rather than one being set.
|
|
328
|
+
get subagentModelChosen() { return this.usesGateway && /^claude-/i.test(this.mainModel.id); }
|
|
321
329
|
get smallModel() { return this.resolveModel('haiku'); }
|
|
322
330
|
|
|
323
331
|
get effort() {
|
|
@@ -327,9 +335,10 @@ export class Config {
|
|
|
327
335
|
|
|
328
336
|
// Generous by default so large files can be written in one go; if the API turns out to allow
|
|
329
337
|
// less, streamMessage learns the real limit from the error and clamps (see api.js).
|
|
330
|
-
// The gateway holds back balance for max_tokens of output before each request, so a smaller default there
|
|
331
|
-
//
|
|
332
|
-
|
|
338
|
+
// The gateway holds back balance for max_tokens of output before each request, so a smaller default there keeps a
|
|
339
|
+
// modest balance usable. 48K: in 812 Opus requests through it (2026-10-12) p99 was 14K, three went over 24K (the
|
|
340
|
+
// longest that finished: 27K) and one was cut off at the old 32K; the hold is $0.96 on Opus instead of $0.64.
|
|
341
|
+
get maxOutputTokens() { return int(this.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS, this.usesGateway ? 48_000 : 128_000); }
|
|
333
342
|
get thinkingBudget() {
|
|
334
343
|
return this.env.MAX_THINKING_TOKENS === undefined ? null : int(this.env.MAX_THINKING_TOKENS, null);
|
|
335
344
|
}
|