@znmin/claude-remote-cli 0.2.3 → 0.2.4
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 +14 -4
- package/package.json +1 -1
- package/scripts/postinstall.js +1 -2
- package/src/cli.js +4 -2
- package/src/client.js +13 -6
- package/src/installer.js +1 -1
- package/src/local/browser.js +3 -2
- package/src/local-mode.js +2 -2
- package/src/ssh-auth.js +5 -5
package/README.md
CHANGED
|
@@ -25,10 +25,10 @@ npm install -g git+https://github.com/znmin/claude-remote-cli.git
|
|
|
25
25
|
也可以从已下载的分发包安装:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npm install -g ./znmin-claude-remote-cli-0.2.
|
|
28
|
+
npm install -g ./znmin-claude-remote-cli-0.2.4.tgz
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
若系统 npm 全局目录不可写,可使用 `npm install -g --prefix "$HOME/.local" ./znmin-claude-remote-cli-0.2.
|
|
31
|
+
若系统 npm 全局目录不可写,可使用 `npm install -g --prefix "$HOME/.local" ./znmin-claude-remote-cli-0.2.4.tgz`,并确保 `~/.local/bin` 在 PATH 中;卸载时也使用相同的 `--prefix`。
|
|
32
32
|
|
|
33
33
|
npm 中不带作用域的 `claude-remote-cli` 属于其他项目。本项目使用独立的 `@znmin/claude-remote-cli` 作用域包名;请安装完整包名,或使用上述 GitHub 地址及本项目分发的 `.tgz` 文件。
|
|
34
34
|
|
|
@@ -181,6 +181,16 @@ CLAUDE_REMOTE_HOST=another-server CLAUDE_REMOTE_PORT=2222 claude
|
|
|
181
181
|
- 不允许同步整个本机用户目录或磁盘根目录。不会同步用户目录中的 Claude 登录信息;远程使用自己的登录状态和工具配置。
|
|
182
182
|
- 本版不提供 tmux 会话恢复。网络中断后文件同步会尝试重连,远程 Claude 进程是否继续运行取决于服务器的进程行为。
|
|
183
183
|
|
|
184
|
+
## 运行提示与调试
|
|
185
|
+
|
|
186
|
+
正常使用时,只显示需要等待或操作的提示,例如首次下载组件、SSH 验证、服务器策略修复结果,以及错误。已配置好的本地模式直接进入 Claude,不重复显示模式说明、项目路径或浏览器缓存检查。服务器同步模式会简短提示“正在同步…”。`configure`、`setup-ssh`、`doctor` 等显式管理命令仍显示操作结果;Claude 自身的界面和 SSH 验证提示不受影响。
|
|
187
|
+
|
|
188
|
+
需要查看连接目标、项目路径、密钥配置过程、缓存检查、同步工具过程输出和错误堆栈时,临时启用:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
CLAUDE_REMOTE_DEBUG=1 claude
|
|
192
|
+
```
|
|
193
|
+
|
|
184
194
|
## 高级环境变量
|
|
185
195
|
|
|
186
196
|
| 变量 | 用途 |
|
|
@@ -194,7 +204,7 @@ CLAUDE_REMOTE_HOST=another-server CLAUDE_REMOTE_PORT=2222 claude
|
|
|
194
204
|
| `CLAUDE_REMOTE_MUTAGEN` | 使用自行准备的 Mutagen 可执行文件绝对路径(应为 0.18.1,并放置配套代理包) |
|
|
195
205
|
| `CLAUDE_REMOTE_PREPARE_SYNC=1` | npm 安装阶段提前准备同步工具,默认按需准备 |
|
|
196
206
|
| `CLAUDE_REMOTE_SKIP_DOWNLOAD=1` | 跳过安装阶段的同步工具准备 |
|
|
197
|
-
| `CLAUDE_REMOTE_DEBUG=1` |
|
|
207
|
+
| `CLAUDE_REMOTE_DEBUG=1` | 显示详细启动过程和错误堆栈 |
|
|
198
208
|
|
|
199
209
|
`npm install --ignore-scripts` 也受支持,首次使用各模式时准备对应组件。无法访问 GitHub 时可自行准备 Mutagen 并使用 `CLAUDE_REMOTE_MUTAGEN`。浏览器缓存由 Playwright 管理,支持其 `PLAYWRIGHT_BROWSERS_PATH` 环境变量。
|
|
200
210
|
|
|
@@ -210,7 +220,7 @@ npm test
|
|
|
210
220
|
CLAUDE_REMOTE_INTEGRATION=1 CLAUDE_REMOTE_BROWSER_TEST=1 npm test
|
|
211
221
|
|
|
212
222
|
npm pack
|
|
213
|
-
npm install -g ./znmin-claude-remote-cli-0.2.
|
|
223
|
+
npm install -g ./znmin-claude-remote-cli-0.2.4.tgz
|
|
214
224
|
|
|
215
225
|
# 确定包名、版本和使用条款后,使用有发布权限的 npm 账号发布
|
|
216
226
|
npm login
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -3,10 +3,9 @@ import { ensureMutagen } from '../src/installer.js';
|
|
|
3
3
|
if (process.env.CLAUDE_REMOTE_PREPARE_SYNC === '1' && process.env.CLAUDE_REMOTE_SKIP_DOWNLOAD !== '1') {
|
|
4
4
|
try {
|
|
5
5
|
await ensureMutagen();
|
|
6
|
-
console.log('claude 已安装。运行 claude-remote configure 用户名@服务器,或直接运行 claude 开始配置。');
|
|
7
6
|
} catch (error) {
|
|
8
7
|
// Offline installation and npm --ignore-scripts remain supported: retry at first use.
|
|
9
8
|
console.warn(`CLI 已安装,同步工具准备未完成:${error.message}\n首次连接时会重试。`);
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
console.log('
|
|
11
|
+
console.log('安装完成,运行 claude 开始。');
|
package/src/cli.js
CHANGED
|
@@ -29,6 +29,7 @@ configure 可选:--mode local|remote、--headless/--headed、--root 远程根
|
|
|
29
29
|
新配置默认使用本地执行;旧配置保持服务器模式,直到显式切换。
|
|
30
30
|
服务器缺少默认 Claude Code 时会自动安装;首次启动需完成认证。
|
|
31
31
|
此工具不提供服务器或 Claude 账号。
|
|
32
|
+
详细诊断:CLAUDE_REMOTE_DEBUG=1 claude
|
|
32
33
|
仅服务器同步模式会在退出后继续后台同步;停止请运行 claude-remote stop。
|
|
33
34
|
`;
|
|
34
35
|
|
|
@@ -101,7 +102,8 @@ export async function main(asClaude, args = process.argv.slice(2), client = new
|
|
|
101
102
|
const { values, positionals } = parseArgs({ args: rest, allowPositionals: true,
|
|
102
103
|
options: { 'enable-pubkey': { type: 'boolean' } } });
|
|
103
104
|
if (positionals.length) throw new Error('用法:claude-remote setup-ssh [--enable-pubkey]');
|
|
104
|
-
await client.ensureSSH(client, await client.settings(), { enablePubkey: Boolean(values['enable-pubkey']) });
|
|
105
|
+
await client.ensureSSH(client, await client.settings(), { enablePubkey: Boolean(values['enable-pubkey']) });
|
|
106
|
+
client.log('SSH 免密登录可用。'); return 0;
|
|
105
107
|
}
|
|
106
108
|
if (rest.length) throw new Error(`${action} 不接受额外参数。`);
|
|
107
109
|
if (action === 'status') {
|
|
@@ -113,7 +115,7 @@ export async function main(asClaude, args = process.argv.slice(2), client = new
|
|
|
113
115
|
if (action === 'install-sync') { console.log('同步工具:' + await ensureMutagen({ env: client.env })); return 0; }
|
|
114
116
|
if (action === 'install-browser') {
|
|
115
117
|
const { installBrowser } = await import('./local/browser.js');
|
|
116
|
-
await installBrowser(client.log); console.log('
|
|
118
|
+
await installBrowser(client.log, { debug: client.debug }); console.log('浏览器已就绪。'); return 0;
|
|
117
119
|
}
|
|
118
120
|
if (action === 'doctor') {
|
|
119
121
|
console.log(`Node.js:${process.version}\n平台:${process.platform}/${process.arch}`);
|
package/src/client.js
CHANGED
|
@@ -63,6 +63,9 @@ export class Client {
|
|
|
63
63
|
this.ensureMutagen = options.ensureMutagen || ensureMutagen;
|
|
64
64
|
this.log = options.log || console.error;
|
|
65
65
|
this.warn = options.warn || console.error;
|
|
66
|
+
this.debug = (...messages) => {
|
|
67
|
+
if (this.env.CLAUDE_REMOTE_DEBUG === '1') this.log(...messages);
|
|
68
|
+
};
|
|
66
69
|
this.tty = options.tty ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
67
70
|
}
|
|
68
71
|
|
|
@@ -74,8 +77,10 @@ export class Client {
|
|
|
74
77
|
ignores: [...DEFAULTS.ignores, ...(input.ignores || [])],
|
|
75
78
|
client_id: old.client_id || randomUUID().replaceAll('-', '').slice(0, 12) });
|
|
76
79
|
await writeJSON(this.configFile, config);
|
|
77
|
-
this.log(
|
|
78
|
-
this.
|
|
80
|
+
this.log(`已保存:${config.host}(${config.mode === 'local' ? '本地执行' : '远程同步'})。`);
|
|
81
|
+
this.debug(`配置文件:${this.configFile}`);
|
|
82
|
+
if (old.host && (old.host !== config.host || (old.mode || 'remote') !== config.mode))
|
|
83
|
+
this.log('停止旧同步:claude-remote stop --all');
|
|
79
84
|
return config;
|
|
80
85
|
});
|
|
81
86
|
}
|
|
@@ -150,6 +155,7 @@ export class Client {
|
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
async launch(config, extra) {
|
|
158
|
+
this.debug(`连接:${config.host}${config.port ? ':' + config.port : ''},模式:${config.mode || 'remote'}`);
|
|
153
159
|
await this.ensureSSH(this, config);
|
|
154
160
|
if (config.mode === 'local') {
|
|
155
161
|
const { launchLocal } = await import('./local-mode.js');
|
|
@@ -178,21 +184,22 @@ export class Client {
|
|
|
178
184
|
await this.remote(config, ensureRemoteClaude(config.claude) +
|
|
179
185
|
'mkdir -p -- ' + remotePath(item.remote), false, { timeout: 600000 });
|
|
180
186
|
if (existing.some(session => session.name === item.name)) {
|
|
181
|
-
await this.sync(['resume', item.name], { timeout: 60000, capture: !this.tty });
|
|
187
|
+
await this.sync(['resume', item.name], { timeout: 60000, capture: this.env.CLAUDE_REMOTE_DEBUG !== '1' || !this.tty });
|
|
182
188
|
} else {
|
|
183
189
|
const endpoint = config.host + ':' + (config.port != null ? config.port + ':' : '') +
|
|
184
190
|
(item.remote.startsWith('/') ? item.remote : '~/' + item.remote);
|
|
185
191
|
const args = ['create', '--name', item.name, '--label', 'claude-remote=true', '--mode', 'two-way-safe',
|
|
186
192
|
'--no-global-configuration', '--no-ignore-vcs', '--watch-polling-interval', '2'];
|
|
187
193
|
for (const pattern of config.ignores) args.push('--ignore', pattern);
|
|
188
|
-
await this.sync([...args, item.local, endpoint], { timeout: 180000, capture: !this.tty });
|
|
194
|
+
await this.sync([...args, item.local, endpoint], { timeout: 180000, capture: this.env.CLAUDE_REMOTE_DEBUG !== '1' || !this.tty });
|
|
189
195
|
}
|
|
190
196
|
registry[item.name] = item;
|
|
191
197
|
await writeJSON(this.registryFile, registry);
|
|
192
198
|
});
|
|
193
|
-
this.
|
|
199
|
+
this.debug(`本地:${item.local}\n远程:${config.host}:${item.remote}`);
|
|
200
|
+
this.log('正在同步…');
|
|
194
201
|
await this.flush(item.name);
|
|
195
|
-
this.
|
|
202
|
+
this.debug('同步完成,启动远程 Claude Code。退出后继续后台同步;停止请运行 claude-remote stop。');
|
|
196
203
|
let code = 1;
|
|
197
204
|
try {
|
|
198
205
|
code = (await this.remote(config, prefix + 'cd -- ' + remotePath(item.remote) +
|
package/src/installer.js
CHANGED
|
@@ -64,7 +64,7 @@ export async function ensureMutagen({ env = process.env, forceDownload = false }
|
|
|
64
64
|
const temporary = await fs.mkdtemp(path.join(path.dirname(destination), '.mutagen-install-'));
|
|
65
65
|
try {
|
|
66
66
|
const archive = path.join(temporary, 'download.tar.gz');
|
|
67
|
-
console.error(
|
|
67
|
+
console.error('正在下载同步工具…');
|
|
68
68
|
await download(`https://github.com/mutagen-io/mutagen/releases/download/v${VERSION}/${archiveName}`, archive);
|
|
69
69
|
await verifyChecksum(archive, checksum);
|
|
70
70
|
// Extract only the two required files from the authenticated archive.
|
package/src/local/browser.js
CHANGED
|
@@ -8,13 +8,14 @@ import { execute, exists, withLock } from '../system.js';
|
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
let preparation;
|
|
10
10
|
|
|
11
|
-
export async function installBrowser(log = console.error) {
|
|
11
|
+
export async function installBrowser(log = console.error, { debug = () => {} } = {}) {
|
|
12
12
|
if (!preparation) preparation = (async () => {
|
|
13
13
|
const cli = path.join(path.dirname(require.resolve('playwright/package.json')), 'cli.js');
|
|
14
14
|
// Keep the lock outside Playwright's cache: its installer replaces browser directories.
|
|
15
15
|
const lock = path.join(process.env.CLAUDE_REMOTE_CACHE_DIR || path.join(os.homedir(), '.cache', 'claude-remote'), 'browser-install');
|
|
16
16
|
await withLock(lock, async () => {
|
|
17
|
-
log('
|
|
17
|
+
if (!await exists(chromium.executablePath())) log('正在下载浏览器…');
|
|
18
|
+
else debug('检查浏览器缓存:' + chromium.executablePath());
|
|
18
19
|
// The CLI checks completion markers and prepares headed AND headless binaries.
|
|
19
20
|
const result = await execute(process.execPath, [cli, 'install', 'chromium'], { capture: true, timeout: 600000 });
|
|
20
21
|
if (!await exists(chromium.executablePath())) throw new Error('浏览器安装未完成:' + result.stderr);
|
package/src/local-mode.js
CHANGED
|
@@ -63,7 +63,7 @@ export async function launchLocal(client, config, extra, dependencies = {}) {
|
|
|
63
63
|
const root = await fs.realpath(client.cwd), home = await fs.realpath(client.home);
|
|
64
64
|
if (root === home || root === path.parse(root).root) throw new Error('请进入具体项目目录,不允许以用户目录或磁盘根目录作为项目。');
|
|
65
65
|
const prepareBrowser = dependencies.installBrowser || installBrowser;
|
|
66
|
-
await prepareBrowser(client.log);
|
|
66
|
+
await prepareBrowser(client.log, { debug: client.debug });
|
|
67
67
|
const gateway = await (dependencies.startLocalServer || startLocalServer)({ root, env: client.env,
|
|
68
68
|
headless: client.env.CLAUDE_REMOTE_HEADLESS === undefined ? Boolean(config.browserHeadless) : client.env.CLAUDE_REMOTE_HEADLESS === '1', log: client.log });
|
|
69
69
|
let tunnel, configFile;
|
|
@@ -82,7 +82,7 @@ export async function launchLocal(client, config, extra, dependencies = {}) {
|
|
|
82
82
|
headers: { Authorization: 'Bearer ' + gateway.token }, timeout: 180000 } } };
|
|
83
83
|
await remote('set -e; umask 077; mkdir -p -- ' + remotePath(remoteDirectory) + '; cat > ' + remotePath(configFile),
|
|
84
84
|
{ input: JSON.stringify(mcp) });
|
|
85
|
-
client.
|
|
85
|
+
client.debug(`本地执行模式:${root}\n文件、命令和浏览器在本机运行;项目文件不通过本模式同步。`);
|
|
86
86
|
const args = localClaudeArguments(path.posix.basename(configFile), root, extra);
|
|
87
87
|
// Keep the parent shell so EXIT can remove the token-bearing temporary config.
|
|
88
88
|
const script = remoteEnvironment + 'cd -- ' + remotePath(remoteDirectory) + ' || exit 1; ' +
|
package/src/ssh-auth.js
CHANGED
|
@@ -39,7 +39,7 @@ export async function ensureSSH(client, config, { enablePubkey = false } = {}) {
|
|
|
39
39
|
const temporary = await fs.mkdtemp(path.join(base, 'ccra-'));
|
|
40
40
|
const socket = path.join(temporary, 'ssh');
|
|
41
41
|
try {
|
|
42
|
-
client.log('
|
|
42
|
+
client.log('请按提示完成 SSH 验证。');
|
|
43
43
|
// Authenticate once; subsequent installation reuses this private socket.
|
|
44
44
|
// Do not capture authentication output or handle passwords in JavaScript.
|
|
45
45
|
await run(['-M', '-S', socket, '-o', 'ControlPersist=no', '-o', 'ControlMaster=yes',
|
|
@@ -47,7 +47,7 @@ export async function ensureSSH(client, config, { enablePubkey = false } = {}) {
|
|
|
47
47
|
const inspect = await run(['-S', socket, config.host, 'sh -c ' + quote(sshPolicyScript({ enable: enablePubkey }))],
|
|
48
48
|
{ capture: true });
|
|
49
49
|
const policy = parseSSHPolicy(inspect.stdout);
|
|
50
|
-
if (policy.backup) client.log('
|
|
50
|
+
if (policy.backup) client.log('已开启公钥登录。配置备份:' + policy.backup);
|
|
51
51
|
if (policy.pubkeyauthentication === 'no')
|
|
52
52
|
throw new Error('服务器关闭了公钥登录(PubkeyAuthentication no),尚未生成或添加密钥。' +
|
|
53
53
|
(policy.uid === '0' ? '如需开启,请运行:claude-remote setup-ssh --enable-pubkey(备份配置、校验后重新加载,保留密码登录)。' :
|
|
@@ -58,14 +58,14 @@ export async function ensureSSH(client, config, { enablePubkey = false } = {}) {
|
|
|
58
58
|
',不允许仅凭公钥登录;请联系管理员确认认证策略。未修改该策略,尚未生成或添加密钥。');
|
|
59
59
|
if (policy.status !== 'ok') {
|
|
60
60
|
if (enablePubkey) throw new Error('无法读取服务器有效 SSH 配置,未自动修改服务器策略;请联系管理员检查。');
|
|
61
|
-
client.
|
|
61
|
+
client.debug('无法读取服务器 SSH 策略,尝试普通公钥授权。');
|
|
62
62
|
}
|
|
63
63
|
const id = createHash('sha256').update(config.host + '\0' + (config.port ?? '')).digest('hex').slice(0, 20);
|
|
64
64
|
const key = path.join(directory, 'id_ed25519_' + id);
|
|
65
65
|
await fs.chmod(directory, 0o700);
|
|
66
66
|
if (!await exists(key)) {
|
|
67
67
|
if (await exists(key + '.pub')) throw new Error('专用 SSH 私钥缺失但公钥仍存在,请检查:' + key);
|
|
68
|
-
client.
|
|
68
|
+
client.debug('创建专用 SSH 密钥:' + key);
|
|
69
69
|
await client.execute('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'claude-remote-cli', '-f', key],
|
|
70
70
|
{ env: client.env, capture: true, timeout: 30000 });
|
|
71
71
|
}
|
|
@@ -91,7 +91,7 @@ export async function ensureSSH(client, config, { enablePubkey = false } = {}) {
|
|
|
91
91
|
});
|
|
92
92
|
if (!previous.includes(block)) await fs.appendFile(configFile, block, { mode: 0o600 });
|
|
93
93
|
if (!await probe()) throw new Error('密钥已授权,但默认 SSH 配置验证失败。请检查 ~/.ssh/config 的 IdentityFile 和 IdentitiesOnly 设置。');
|
|
94
|
-
client.
|
|
94
|
+
client.debug('SSH 免密登录已配置并验证成功。');
|
|
95
95
|
} finally {
|
|
96
96
|
await run(['-S', socket, '-O', 'exit', config.host], { capture: true, check: false, timeout: 5000 }).catch(() => {});
|
|
97
97
|
await fs.rm(temporary, { recursive: true, force: true });
|