@yanzc/claude-pro 0.5.2 → 0.5.3

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
@@ -28,7 +28,7 @@ npm install -g @yanzc/claude-pro
28
28
  claude-pro # 在任意项目目录里运行
29
29
  ```
30
30
 
31
- 自动更新(与 Claude Code 一样):用 npm 全局安装的版本每 6 小时最多查一次 npm 上的最新版,有新版就在后台 `npm install -g @yanzc/claude-pro@新版本`,装好后在会话空闲时自动重启加载,对话保留。`/update` 立即检查;`CLAUDE_PRO_AUTO_UPDATE=0` 或 `DISABLE_AUTOUPDATER=1` 关闭。从源码运行(git 检出)的副本从不自动更新。
31
+ 自动更新(与 Claude Code 一样):用 npm 全局安装的版本在启动时、以及运行中**每 5 分钟**查一次 npm 上的最新版(同一台电脑上的所有会话共用这个间隔;查询绕过 npm 的 CDN 缓存),有新版就在后台 `npm install -g --prefer-online @yanzc/claude-pro@新版本`,装好后在会话空闲时自动重启加载,对话保留;同一台电脑上其他开着的会话看到文件变了,也会在空闲时自动重启。所以发布后几分钟内各个客户端就会用上新版(npm 刚发布时安装包要几分钟才能下载,期间安装失败会在 1 分钟后重试)。`/update` 立即检查;`CLAUDE_PRO_AUTO_UPDATE=0` 或 `DISABLE_AUTOUPDATER=1` 关闭。从源码运行(git 检出)的副本从不自动更新。
32
32
 
33
33
  从源码运行:
34
34
 
@@ -234,7 +234,7 @@ claude-pro config set ANTHROPIC_MODEL deepseek-pro --project
234
234
  - 流式 Markdown 渲染(代码高亮、表格、中文宽度对齐),思考过程折叠显示(`ctrl+o` 展开)
235
235
  - `Esc` 中断;忙碌时输入的消息会排队并插入当前任务
236
236
  - `!` Bash 模式、`#` 写入记忆(CLAUDE.md)、`\`+回车 或 `ctrl+j` 换行、粘贴大段文本折叠为 `[Pasted text #1 +42 lines]`
237
- - **全屏模式(默认,和 Claude Code 的 `/tui fullscreen` 一样)**:程序画在终端的备用屏幕上(像 vim),输入框固定在窗口最底下,不随输出或终端滚动条移动;对话在程序里滚动:鼠标滚轮(每格 `CLAUDE_PRO_SCROLL_SPEED` 行,默认 3)、`PgUp`/`PgDn`(半屏)、`Ctrl+Home`(对话开头)、`Ctrl+End`(回到最新)。往上翻时新输出不会把画面拉回底部,底部浮着 `Jump to bottom (ctrl+End) ↓ · N new lines`,**点它**或按 `Ctrl+End` 回到底部;发消息时自动回到底部。**选中文字直接用鼠标拖**(不用按 Shift),松开就复制到剪贴板;双击选一个词,三击选一整行;拖到对话区上下边缘会跟着滚动。选中的部分反色显示,点一下别处、按 `Esc` 或任意键就消失;有选中时 `Ctrl+C` 是复制(不会中断任务)。仍可按住 Shift 拖动用终端自己的选中。退出后终端回到启动前的样子(对话不留在终端滚动记录里)。`/tui default` 切回经典模式(对话写进终端自己的滚动记录,输入框在窗口底部、靠空行顶到底;`CLAUDE_PRO_PIN_INPUT=0` 让它紧跟在输出下面),`/tui fullscreen` 切回全屏,选择会记住(`CLAUDE_PRO_TUI`)
237
+ - **全屏模式(默认,和 Claude Code 的 `/tui fullscreen` 一样)**:程序画在终端的备用屏幕上(像 vim),输入框固定在窗口最底下,不随输出或终端滚动条移动;对话在程序里滚动:鼠标滚轮(每格 `CLAUDE_PRO_SCROLL_SPEED` 行,默认 3)、`PgUp`/`PgDn`(半屏)、`Ctrl+Home`(对话开头)、`Ctrl+End`(回到最新)。往上翻时新输出不会把画面拉回底部,底部浮着 `Jump to bottom (ctrl+End) ↓ · N new lines`,**点它**或按 `Ctrl+End` 回到底部;发消息时自动回到底部。**选中文字直接用鼠标拖**(不用按 Shift),松开就复制到剪贴板;双击选一个词,三击选一整行;拖到对话区上下边缘会跟着滚动。选中的部分反色显示,点一下别处、按 `Esc` 或任意键就消失;有选中时 `Ctrl+C` 是复制(不会中断任务)。**右键**和在终端里一样:有选中时复制,没有时把剪贴板的文字粘贴进输入框(和 `Ctrl+V` 相同)。仍可按住 Shift 拖动用终端自己的选中。退出后终端回到启动前的样子(对话不留在终端滚动记录里)。`/tui default` 切回经典模式(对话写进终端自己的滚动记录,输入框在窗口底部、靠空行顶到底;`CLAUDE_PRO_PIN_INPUT=0` 让它紧跟在输出下面),`/tui fullscreen` 切回全屏,选择会记住(`CLAUDE_PRO_TUI`)
238
238
  - `ctrl+c` 或连按两次 `Esc` 清掉的草稿不会丢:在空输入框按 `↑` 找回(连同粘贴的文本和图片),中间发过别的消息也可以
239
239
  - `@文件` 补全并附加内容:走的就是 `Read` 工具,等于模型自己读了这个文件。最多带前 2000 行(被截断时会明确告诉模型,并把该文件记为"只读了一部分",之后 `Write` 不会去覆盖没给它看过的行);图片作为图片附加;二进制文件和超过 512KB 的文本会被跳过并提示原因;`@目录` 列出目录内容
240
240
  - `alt+v` 粘贴剪贴板里的图片(截图用 `Win+Shift+S`),输入框里显示为 `[Image #1]`;超过 1568px 的图会自动缩小。把图片文件拖进终端(或粘贴图片路径)也会作为图片附加
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanzc/claude-pro",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
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/selfcheck.js CHANGED
@@ -10,6 +10,9 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
10
  async function check() {
11
11
  const problems = [];
12
12
  const fail = (text) => problems.push(text);
13
+ // The App starts as a session does (the fullscreen renderer, the update timer, ...), so that code only a real
14
+ // start runs is checked too, but this process must not show up as a session, go online or install an update.
15
+ Object.assign(process.env, { CLAUDE_PRO_PEERS: '0', CLAUDE_PRO_ONLINE: '0', CLAUDE_PRO_AUTO_UPDATE: '0' });
13
16
 
14
17
  let App;
15
18
  try {
@@ -25,7 +28,7 @@ async function check() {
25
28
  const stdin = new PassThrough();
26
29
  Object.assign(stdin, { isTTY: true, setRawMode() {} });
27
30
 
28
- const app = new App({ flags: { noMcp: true }, cwd: process.cwd(), stdin, stdout, noProcessExit: true });
31
+ const app = new App({ flags: { noMcp: true }, cwd: process.cwd(), stdin, stdout, selfCheck: true });
29
32
  let exited;
30
33
  try {
31
34
  exited = app.start('');
package/src/ui/repl.js CHANGED
@@ -27,11 +27,11 @@ import { ripgrepPath } from '../utils/shell.js';
27
27
  import { describePause, formatClock, humanDuration, resumeText, shouldAnnounce } from '../ratelimit.js';
28
28
  import { shutdownBackgroundShells, listBackgroundShells } from '../tools/bash.js';
29
29
  import { estimateTokens } from '../agent.js';
30
- import { readClipboardImage, imageFromFile, watchClipboard, writeClipboard } from '../utils/clipboard.js';
30
+ import { readClipboardImage, imageFromFile, watchClipboard, writeClipboard, readClipboardText } from '../utils/clipboard.js';
31
31
  import { fitImagesIn } from '../utils/images.js';
32
32
  import { downloadsDir, filesToSend, formatBytes } from '../utils/downloads.js';
33
33
  import { copyUnique } from '../transfer.js';
34
- import { checkForUpdate } from '../updater.js';
34
+ import { checkForUpdate, CHECK_EVERY_MS } from '../updater.js';
35
35
  import { PeerNode, peersEnabled, findPeer, resolvePeer, machineName, cleanName, peerMessagePrompt } from '../peers.js';
36
36
  import { RemoteControl, transcriptItems, onlineEnabled, REMOTE_WIDTH } from '../remote.js';
37
37
  import { qrLines } from '../qr.js';
@@ -143,12 +143,16 @@ class FileIndex {
143
143
  }
144
144
 
145
145
  export class App {
146
- constructor({ flags, cwd, stdin = process.stdin, stdout = process.stdout, noProcessExit = false }) {
146
+ // `noProcessExit`: the tests, which drive the App themselves; it never ends the process, and it has no peers, no
147
+ // gateway connection, no update checks and the default renderer. `selfCheck` (see selfcheck.js): it never ends the
148
+ // process either, but otherwise starts as a session does, so that code only a real start runs is checked too.
149
+ constructor({ flags, cwd, stdin = process.stdin, stdout = process.stdout, noProcessExit = false, selfCheck = false }) {
147
150
  this.flags = flags;
148
151
  this.cwd = cwd;
149
152
  this.stdin = stdin;
150
153
  this.stdout = stdout;
151
- this.noProcessExit = noProcessExit;
154
+ this.noProcessExit = noProcessExit || selfCheck;
155
+ this.driven = noProcessExit;
152
156
  this.screen = new Screen(stdout);
153
157
  this.busy = false;
154
158
  this.controller = null;
@@ -249,6 +253,7 @@ export class App {
249
253
  // Keys typed while starting up stay buffered in stdin until we listen. Mouse reports (fullscreen: the wheel)
250
254
  // are taken out before the keys are read.
251
255
  const keys = mouseFilter(stdin, (m) => this.onMouse(m));
256
+ this.keys = keys;
252
257
  readline.emitKeypressEvents(keys);
253
258
  keys.on('keypress', (str, key) => {
254
259
  if (/^\x1b\[\d+;\d+R$/.test(key?.sequence || '')) return; // a late answer to the cursor position query, not a key
@@ -279,7 +284,12 @@ export class App {
279
284
  }
280
285
  this.fileIndex.refresh();
281
286
  this.startSourceWatch();
282
- if (!this.noProcessExit && !this.flags.restart) this.autoUpdate();
287
+ if (!this.driven) {
288
+ if (!this.flags.restart) this.autoUpdate();
289
+ // and every few minutes while it runs, so that a release reaches a session that stays open for days
290
+ this.updateTimer = setInterval(() => { if (!this.exiting) this.autoUpdate({ quiet: true }); }, CHECK_EVERY_MS);
291
+ this.updateTimer.unref?.();
292
+ }
283
293
  return new Promise((resolve) => { this.resolveExit = resolve; });
284
294
  }
285
295
 
@@ -388,7 +398,7 @@ export class App {
388
398
  // Register this session so that the other sessions on the machine can send it tasks. Not in the tests
389
399
  // (which drive the App themselves) and not with CLAUDE_PRO_PEERS=0.
390
400
  async startPeer() {
391
- if (this.noProcessExit || !peersEnabled()) return;
401
+ if (this.driven || !peersEnabled()) return;
392
402
  try {
393
403
  this.peers = await new PeerNode({ cwd: this.cwd, name: this.flags.restart?.peerName, id: this.flags.restart?.peerId, onMessage: (msg) => this.onPeerMessage(msg) }).start();
394
404
  } catch (e) {
@@ -706,12 +716,12 @@ export class App {
706
716
  // Online at the gateway (see remote.js) from the start: by itself when this computer is logged in to the gateway
707
717
  // (CLAUDE_PRO_ONLINE=0 turns that off), with --rc (which prints the link too), and after a restart as before (with
708
718
  // the same id, so that open pages and messages on their way find it again). It does not hold up the start. Never
709
- // in the tests and the self-check, which drive the App themselves.
719
+ // in the tests, which drive the App themselves, nor in the self-check, which sets CLAUDE_PRO_ONLINE=0.
710
720
  autoStartRemote(restart) {
711
721
  const carried = restart?.remote;
712
722
  if (carried?.off) { this.remoteStopped = true; return; }
713
723
  const explicit = Boolean(this.flags.remoteControl);
714
- if (this.noProcessExit && !explicit) return;
724
+ if (this.driven && !explicit) return;
715
725
  if (!explicit && !carried?.id && !(onlineEnabled(this.config.env) && readGatewayLogin(this.config.gatewayUrl))) return;
716
726
  this.startRemote({ id: carried?.id, quiet: !explicit || Boolean(carried?.id), persistent: !explicit }).catch((e) => {
717
727
  this.notice(`${explicit ? 'Remote control could not start' : 'This session could not go online at the gateway'}: ${e.message}${e.code === 'NO_GATEWAY_LOGIN' ? '' : ' (/rc tries again)'}`, 'warn');
@@ -1000,7 +1010,8 @@ export class App {
1000
1010
 
1001
1011
  // A newer version on npm is installed in the background (see updater.js) and loaded by a restart once the
1002
1012
  // session is idle. `force`: the /update command, which also says when there is nothing to do.
1003
- async autoUpdate({ force = false } = {}) {
1013
+ // `quiet`: a periodic check, which says nothing when the install fails (it is tried again in a minute).
1014
+ async autoUpdate({ force = false, quiet = false } = {}) {
1004
1015
  if (this.updating) { if (force) this.notice('An update is already being installed.'); return; }
1005
1016
  let r;
1006
1017
  try {
@@ -1016,7 +1027,7 @@ export class App {
1016
1027
  if (canRestart()) { this.sourceChanged = true; if (!this.busy) this.maybeAutoReload(); }
1017
1028
  else this.notice('Restart the program to use it.');
1018
1029
  } else if (r.status === 'failed') {
1019
- if (force || r.version) this.notice(`Could not update ${APP_NAME}${r.version ? ` to ${r.version}` : ''}: ${r.error}`, 'warn');
1030
+ if (force || (r.version && !quiet)) this.notice(`Could not update ${APP_NAME}${r.version ? ` to ${r.version}` : ''}: ${r.error}`, 'warn');
1020
1031
  } else if (force) {
1021
1032
  this.notice(r.status === 'dev' ? `This copy runs from a source checkout (${INSTALL_DIR}): update it with git.` : `${APP_NAME} ${VERSION} is the latest version.`);
1022
1033
  }
@@ -1073,7 +1084,7 @@ export class App {
1073
1084
  // Fullscreen (see screen.js) unless CLAUDE_PRO_TUI=default, as Claude Code's /tui: the input box fixed at the
1074
1085
  // bottom of the window, the conversation scrolled inside the program. Not in the tests that drive the App.
1075
1086
  fullscreenWanted() {
1076
- const mode = String(this.config.env.CLAUDE_PRO_TUI || (this.noProcessExit ? 'default' : 'fullscreen')).toLowerCase();
1087
+ const mode = String(this.config.env.CLAUDE_PRO_TUI || (this.driven ? 'default' : 'fullscreen')).toLowerCase();
1077
1088
  return mode === 'fullscreen' && this.stdout.isTTY !== false;
1078
1089
  }
1079
1090
 
@@ -1087,6 +1098,22 @@ export class App {
1087
1098
  this.screen.scrollBy(m.button & 1 ? -speed : speed);
1088
1099
  return;
1089
1100
  }
1101
+ // A right click, which the terminal no longer gets: what it did there. With a selection it copies it;
1102
+ // without one it pastes the clipboard's text, as the terminal's own paste (ctrl+v) arrives, so that it is
1103
+ // handled the same way (long text folded, an image path attached, into a dialog's answer box).
1104
+ if ((m.button & 3) === 2 && !(m.button & 32) && !m.release) {
1105
+ if (this.screen.selection) {
1106
+ this.copyText(this.screen.selectedText());
1107
+ this.screen.clearSelection();
1108
+ return;
1109
+ }
1110
+ readClipboardText().then((text) => {
1111
+ if (!text || this.exiting) return;
1112
+ const clean = text.replace(/\x1b\[20[01]~/g, '').replace(/\r\n|\n/g, '\r');
1113
+ this.keys.write(`\x1b[200~${clean}\x1b[201~`);
1114
+ });
1115
+ return;
1116
+ }
1090
1117
  const r = this.screen.mouse(m);
1091
1118
  if (r?.copy) this.copyText(r.copy);
1092
1119
  }
package/src/updater.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Auto-update, as in Claude Code: an interactive session installed with `npm i -g claude-pro` looks for a newer
2
- // version on the npm registry (at most once every few hours), installs it in the background, and the session
3
- // then loads it with a restart once it is idle (the conversation carries over). A git checkout (the
2
+ // version on the npm registry (when it starts and every few minutes while it runs; the sessions of a machine share
3
+ // the interval), installs it in the background, and the session then loads it with a restart once it is idle (the
4
+ // conversation carries over). The other sessions of the machine see the files change and restart too (see
5
+ // App.startSourceWatch). A git checkout (the
4
6
  // development copy) is never touched. Off with CLAUDE_PRO_AUTO_UPDATE=0 or DISABLE_AUTOUPDATER=1.
5
7
 
6
8
  import fs from 'node:fs';
@@ -12,7 +14,8 @@ import { CONFIG_DIR, INSTALL_DIR, VERSION } from './config.js';
12
14
  // The name on npm (scoped: npm refused plain `claude-pro` as too close to another package's name).
13
15
  export const PACKAGE_NAME = JSON.parse(fs.readFileSync(path.join(INSTALL_DIR, 'package.json'), 'utf8')).name;
14
16
  const STATE_FILE = path.join(CONFIG_DIR, 'update-check.json');
15
- const CHECK_EVERY_MS = 6 * 3600_000;
17
+ export const CHECK_EVERY_MS = 5 * 60_000; // a release reaches the running sessions within minutes
18
+ const RETRY_FAILED_MS = 60_000; // a release's tarball can take minutes to be downloadable after it is published
16
19
 
17
20
  export function autoUpdateEnabled(env = process.env) {
18
21
  if (/^(1|true|yes)$/i.test(env.DISABLE_AUTOUPDATER || '')) return false;
@@ -44,7 +47,9 @@ function writeState(s) { try { fs.mkdirSync(CONFIG_DIR, { recursive: true }); fs
44
47
 
45
48
  export function latestVersion({ timeoutMs = 10_000 } = {}) {
46
49
  return new Promise((resolve, reject) => {
47
- const req = https.get(`https://registry.npmjs.org/${PACKAGE_NAME.replace('/', '%2f')}/latest`, { headers: { accept: 'application/json' }, timeout: timeoutMs }, (res) => {
50
+ // past the registry's CDN cache, which can answer with the version before the one just published
51
+ const url = `https://registry.npmjs.org/${PACKAGE_NAME.replace('/', '%2f')}/latest?t=${Date.now()}`;
52
+ const req = https.get(url, { headers: { accept: 'application/json', 'cache-control': 'no-cache' }, timeout: timeoutMs }, (res) => {
48
53
  let body = '';
49
54
  res.setEncoding('utf8');
50
55
  res.on('data', (d) => { body += d; });
@@ -86,8 +91,12 @@ export async function checkForUpdate({ force = false, env = process.env, onInsta
86
91
  return { status: 'failed', version: latest, error: `this copy (${INSTALL_DIR}) is not the global npm install; update it with npm yourself` };
87
92
  }
88
93
  onInstalling?.(latest);
89
- const r = await runNpm(['install', '-g', `${PACKAGE_NAME}@${latest}`]);
90
- if (!r.ok) return { status: 'failed', version: latest, error: r.output.split('\n').slice(-5).join('\n') };
94
+ // --prefer-online: not npm's own cache of the package's versions, which may not know this one yet
95
+ const r = await runNpm(['install', '-g', '--prefer-online', `${PACKAGE_NAME}@${latest}`]);
96
+ if (!r.ok) {
97
+ writeState({ ...readState(), checkedAt: Date.now() - CHECK_EVERY_MS + RETRY_FAILED_MS }); // again in a minute
98
+ return { status: 'failed', version: latest, error: r.output.split('\n').slice(-5).join('\n') };
99
+ }
91
100
  writeState({ checkedAt: Date.now(), installed: latest });
92
101
  return { status: 'updated', version: latest };
93
102
  }
@@ -164,6 +164,35 @@ export async function writeClipboard(text) {
164
164
  return false;
165
165
  }
166
166
 
167
+ // The text on the system clipboard ('' when there is none), for a right click in the fullscreen renderer, which
168
+ // gets the mouse instead of the terminal: Windows PowerShell (written out as UTF-8), pbpaste on macOS,
169
+ // wl-paste / xclip / xsel elsewhere.
170
+ export async function readClipboardText() {
171
+ const tries = process.platform === 'win32'
172
+ ? [['powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', '$t = Get-Clipboard -Raw; if ($t) { $b = [Text.Encoding]::UTF8.GetBytes($t); $o = [Console]::OpenStandardOutput(); $o.Write($b, 0, $b.Length) }']]]
173
+ : process.platform === 'darwin'
174
+ ? [['pbpaste', []]]
175
+ : [['wl-paste', ['--no-newline']], ['xclip', ['-selection', 'clipboard', '-o']], ['xsel', ['--clipboard', '--output']]];
176
+ for (const [cmd, args] of tries) {
177
+ const text = await new Promise((resolve) => {
178
+ const chunks = [];
179
+ let child;
180
+ try {
181
+ child = spawn(cmd, args, { windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
182
+ } catch {
183
+ resolve(null);
184
+ return;
185
+ }
186
+ const timer = setTimeout(() => child.kill(), 10_000);
187
+ child.stdout.on('data', (d) => chunks.push(d));
188
+ child.on('error', () => { clearTimeout(timer); resolve(null); });
189
+ child.on('close', (code) => { clearTimeout(timer); resolve(code === 0 ? Buffer.concat(chunks).toString('utf8') : null); });
190
+ });
191
+ if (text !== null) return text;
192
+ }
193
+ return '';
194
+ }
195
+
167
196
  // Returns {image} on success, {error: string} on failure, or {error: null} when the clipboard has no image.
168
197
  export async function readClipboardImage({ source } = {}) {
169
198
  if (process.platform === 'win32') return readWindows(source);