@yanzc/claude-pro 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +342 -318
- package/package.json +1 -2
- package/src/agent.js +80 -14
- package/src/agents.js +3 -2
- package/src/api.js +39 -34
- package/src/browser/broker.js +367 -0
- package/src/browser/cdp.js +114 -0
- package/src/browser/render.js +242 -0
- package/src/browser/session.js +948 -0
- package/src/browser/snapshot.js +212 -0
- package/src/cache.js +1 -1
- package/src/checkpoints.js +1 -0
- package/src/commands.js +169 -67
- package/src/compaction.js +75 -0
- package/src/config.js +145 -144
- package/src/context.js +45 -18
- package/src/filestate.js +3 -2
- package/src/gateway.js +208 -164
- package/src/hooks.js +2 -2
- package/src/keepalive.js +1 -1
- package/src/main.js +52 -40
- package/src/mcp.js +2 -2
- package/src/peers.js +1 -10
- package/src/print.js +9 -3
- package/src/prompt-profiles.js +0 -6
- package/src/prompts.js +7 -63
- package/src/ratelimit.js +2 -4
- package/src/remote.js +76 -14
- package/src/runtime.js +33 -10
- package/src/selfcheck.js +3 -3
- package/src/session.js +93 -3
- package/src/supervisor.js +10 -1
- package/src/tools/bash.js +18 -17
- package/src/tools/browser.js +365 -0
- package/src/tools/code.js +430 -0
- package/src/tools/effort.js +3 -4
- package/src/tools/files.js +368 -45
- package/src/tools/index.js +9 -1
- package/src/tools/notebook.js +11 -4
- package/src/tools/processes.js +274 -0
- package/src/tools/search.js +33 -8
- package/src/tools/web.js +316 -46
- package/src/trace.js +0 -4
- package/src/ui/ansi.js +92 -13
- package/src/ui/dialogs.js +16 -54
- package/src/ui/editor.js +231 -34
- package/src/ui/markdown.js +1 -2
- package/src/ui/render.js +1 -2
- package/src/ui/repl.js +335 -101
- package/src/ui/screen.js +139 -31
- package/src/updater.js +135 -165
- package/src/utils/clipboard.js +5 -3
- package/src/utils/dirs.js +136 -0
- package/src/utils/encoding.js +23 -2
- package/src/utils/paths.js +15 -17
- package/src/utils/shell.js +66 -11
- package/.env.example +0 -29
package/src/utils/shell.js
CHANGED
|
@@ -7,6 +7,14 @@ import { OutputDecoder } from './encoding.js';
|
|
|
7
7
|
const isWin = process.platform === 'win32';
|
|
8
8
|
let shellCache;
|
|
9
9
|
|
|
10
|
+
// The shell findShell found, or undefined before it was looked for.
|
|
11
|
+
export const knownShell = () => shellCache;
|
|
12
|
+
|
|
13
|
+
// Whether a process with this id runs (EPERM: it does, but is not ours to signal).
|
|
14
|
+
export function processAlive(pid) {
|
|
15
|
+
try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; }
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
// Locate the shell used by the Bash tool. On Windows we need Git Bash, like Claude Code.
|
|
11
19
|
export function findShell(config) {
|
|
12
20
|
if (shellCache) return shellCache;
|
|
@@ -63,7 +71,18 @@ export function parsePsRows(text) {
|
|
|
63
71
|
// member of its process group (a child whose parent already exited is no longer linked to it).
|
|
64
72
|
export function msysTree(rows, rootPid) {
|
|
65
73
|
const root = rows.find((r) => r.pid === rootPid);
|
|
66
|
-
if (!root)
|
|
74
|
+
if (!root) {
|
|
75
|
+
// The shell has ended. What it left running in the background stays in its process group, which it led, and has
|
|
76
|
+
// no parent any more (PPID 1): those, and what they started. A group that only has the same number by now is
|
|
77
|
+
// not taken: its leader has a parent.
|
|
78
|
+
const group = rows.filter((r) => r.pgid === rootPid);
|
|
79
|
+
const take = new Set(group.filter((r) => r.ppid === 1).map((r) => r.pid));
|
|
80
|
+
for (let grew = true; grew;) {
|
|
81
|
+
grew = false;
|
|
82
|
+
for (const r of group) if (!take.has(r.pid) && take.has(r.ppid)) { take.add(r.pid); grew = true; }
|
|
83
|
+
}
|
|
84
|
+
return group.filter((r) => take.has(r.pid)).map((r) => r.winpid);
|
|
85
|
+
}
|
|
67
86
|
const children = new Map();
|
|
68
87
|
for (const r of rows) {
|
|
69
88
|
if (!children.has(r.ppid)) children.set(r.ppid, []);
|
|
@@ -118,6 +137,22 @@ function msysDescendants(child, { sync }) {
|
|
|
118
137
|
return runAsync(ps, ['-W'], { timeout: 5000 }).then((r) => (r.code === 0 ? msysTree(parsePsRows(r.out), root) : []));
|
|
119
138
|
}
|
|
120
139
|
|
|
140
|
+
// The trimmed output of a command that succeeded, or null, as run() gives it, without blocking the event loop. An
|
|
141
|
+
// output past maxChars is null too. Never rejects.
|
|
142
|
+
export function runText(cmd, args, { cwd, timeout = 5000, maxChars = 1024 * 1024 } = {}) {
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
let out = '';
|
|
145
|
+
let child;
|
|
146
|
+
try { child = spawn(cmd, args, { cwd, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] }); } catch { resolve(null); return; }
|
|
147
|
+
const timer = setTimeout(() => { try { child.kill(); } catch { /* gone */ } }, timeout);
|
|
148
|
+
const done = (value) => { clearTimeout(timer); resolve(value); };
|
|
149
|
+
child.stdout.setEncoding('utf8');
|
|
150
|
+
child.stdout.on('data', (d) => { out += d; if (out.length > maxChars) try { child.kill(); } catch { /* gone */ } });
|
|
151
|
+
child.on('error', () => done(null));
|
|
152
|
+
child.on('close', (code) => done(code === 0 && out.length <= maxChars ? out.trim() : null));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
121
156
|
// A command's exit code and output, without blocking the event loop. Never rejects.
|
|
122
157
|
function runAsync(cmd, args, { timeout = 5000 } = {}) {
|
|
123
158
|
return new Promise((resolve) => {
|
|
@@ -135,11 +170,17 @@ function runAsync(cmd, args, { timeout = 5000 } = {}) {
|
|
|
135
170
|
// Kill a process and all its children, without blocking the event loop (`ps -W` and taskkill take up to seconds,
|
|
136
171
|
// and Ctrl+C, a timeout or KillShell used to freeze the interface for that long). Resolves when done; never
|
|
137
172
|
// rejects. The tree has to be looked up before anything is killed: once its parents are gone the links are too.
|
|
138
|
-
|
|
139
|
-
|
|
173
|
+
// `orphans`: also when the process itself has ended, for what it left running (a background shell whose `server &`
|
|
174
|
+
// still holds its output open): only the processes found through it then, never its own pid, which may be another
|
|
175
|
+
// process's by now. Only for callers that know something of it still runs (a background shell not closed yet).
|
|
176
|
+
export async function killTree(child, { orphans = false } = {}) {
|
|
177
|
+
if (!child || child.killed) return;
|
|
178
|
+
const ended = child.exitCode !== null || child.signalCode !== null;
|
|
179
|
+
if (ended && !orphans) return;
|
|
140
180
|
try {
|
|
141
181
|
if (isWin) {
|
|
142
|
-
const pids = new Set([child.pid, ...(child.claudeProPidFile ? await msysDescendants(child, { sync: false }) : [])]);
|
|
182
|
+
const pids = new Set([...(ended ? [] : [child.pid]), ...(child.claudeProPidFile ? await msysDescendants(child, { sync: false }) : [])]);
|
|
183
|
+
if (!pids.size) return;
|
|
143
184
|
const args = ['/F', '/T'];
|
|
144
185
|
for (const pid of pids) args.push('/PID', String(pid));
|
|
145
186
|
await runAsync('taskkill', args);
|
|
@@ -148,16 +189,19 @@ export async function killTree(child) {
|
|
|
148
189
|
process.kill(-child.pid, 'SIGKILL');
|
|
149
190
|
}
|
|
150
191
|
} catch {
|
|
151
|
-
try { child.kill('SIGKILL'); } catch { /* ignore */ }
|
|
192
|
+
if (!ended) { try { child.kill('SIGKILL'); } catch { /* ignore */ } }
|
|
152
193
|
}
|
|
153
194
|
}
|
|
154
195
|
|
|
155
196
|
// The same, done before it returns: for the exit, after which nothing would be left to finish the kill.
|
|
156
|
-
export function killTreeSync(child) {
|
|
157
|
-
if (!child || child.
|
|
197
|
+
export function killTreeSync(child, { orphans = false } = {}) {
|
|
198
|
+
if (!child || child.killed) return;
|
|
199
|
+
const ended = child.exitCode !== null || child.signalCode !== null;
|
|
200
|
+
if (ended && !orphans) return;
|
|
158
201
|
try {
|
|
159
202
|
if (isWin) {
|
|
160
|
-
const pids = new Set([child.pid, ...(child.claudeProPidFile ? msysDescendants(child, { sync: true }) : [])]);
|
|
203
|
+
const pids = new Set([...(ended ? [] : [child.pid]), ...(child.claudeProPidFile ? msysDescendants(child, { sync: true }) : [])]);
|
|
204
|
+
if (!pids.size) return;
|
|
161
205
|
const args = ['/F', '/T'];
|
|
162
206
|
for (const pid of pids) args.push('/PID', String(pid));
|
|
163
207
|
spawnSync('taskkill', args, { windowsHide: true, stdio: 'ignore' });
|
|
@@ -166,14 +210,25 @@ export function killTreeSync(child) {
|
|
|
166
210
|
process.kill(-child.pid, 'SIGKILL');
|
|
167
211
|
}
|
|
168
212
|
} catch {
|
|
169
|
-
try { child.kill('SIGKILL'); } catch { /* ignore */ }
|
|
213
|
+
if (!ended) { try { child.kill('SIGKILL'); } catch { /* ignore */ } }
|
|
170
214
|
}
|
|
171
215
|
}
|
|
172
216
|
|
|
173
217
|
// Run a quick command and return stdout (used for git info etc.). Never throws.
|
|
174
|
-
|
|
218
|
+
// The environment of what the program starts (Bash, REPL, hooks, MCP servers): non-interactive and colour free, and
|
|
219
|
+
// without what makes a process a restartable session of this program (a hook that ran `claude-pro -p` was given the
|
|
220
|
+
// Restart tool and the prompt about its own source).
|
|
221
|
+
export function childEnv() {
|
|
222
|
+
const env = { ...process.env };
|
|
223
|
+
Object.assign(env, { GIT_EDITOR: 'true', GIT_PAGER: 'cat', PAGER: 'cat', NO_COLOR: '1', CLAUDE_PRO: '1' });
|
|
224
|
+
delete env.FORCE_COLOR;
|
|
225
|
+
for (const key of ['CLAUDE_PRO_SUPERVISED', 'CLAUDE_PRO_RESTART_FILE', 'CLAUDE_PRO_RESTARTED']) delete env[key];
|
|
226
|
+
return env;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function run(cmd, args, { cwd, timeout = 5000, maxBuffer = 1024 * 1024 } = {}) {
|
|
175
230
|
try {
|
|
176
|
-
const r = spawnSync(cmd, args, { cwd, encoding: 'utf8', timeout, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
231
|
+
const r = spawnSync(cmd, args, { cwd, encoding: 'utf8', timeout, maxBuffer, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
177
232
|
if (r.status !== 0) return null;
|
|
178
233
|
return r.stdout.trim();
|
|
179
234
|
} catch {
|
package/.env.example
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# Optional gateway configuration. /login normally saves the key in
|
|
2
|
-
# ~/.claude-pro/gateway.json, so CLAUDE_PRO_GATEWAY_API_KEY is only needed for
|
|
3
|
-
# headless or automated runs.
|
|
4
|
-
CLAUDE_PRO_PROVIDER=gateway
|
|
5
|
-
CLAUDE_PRO_GATEWAY_URL=https://gw.predix.icu
|
|
6
|
-
CLAUDE_PRO_GATEWAY_API_KEY=gw-your-key
|
|
7
|
-
CLAUDE_PRO_GATEWAY_MODEL=opus
|
|
8
|
-
|
|
9
|
-
# Reasoning and context tuning
|
|
10
|
-
# CLAUDE_CODE_EFFORT_LEVEL=high # default: the model's own
|
|
11
|
-
# CLAUDE_CODE_AUTO_COMPACT_WINDOW=250000 # default: the model's whole window
|
|
12
|
-
# CLAUDE_CODE_MAX_OUTPUT_TOKENS=48000 # gateway default
|
|
13
|
-
# MAX_THINKING_TOKENS=0 # 0 = disable thinking
|
|
14
|
-
# CLAUDE_CODE_PROMPT_CACHE_TTL=1h # 5m or 1h for the main conversation
|
|
15
|
-
# CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL=5m # sub-agents, compaction and side queries
|
|
16
|
-
# ENABLE_PROMPT_CACHING_1H=1 # 1h for both buckets
|
|
17
|
-
# FORCE_PROMPT_CACHING_5M=1 # force 5m for both buckets
|
|
18
|
-
# DISABLE_PROMPT_CACHING=1 # send no cache_control markers
|
|
19
|
-
# CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=90
|
|
20
|
-
# DISABLE_AUTOCOMPACT=1
|
|
21
|
-
|
|
22
|
-
# Request and tool limits
|
|
23
|
-
# API_TIMEOUT_MS=600000
|
|
24
|
-
# CLAUDE_PRO_MAX_RETRIES=6
|
|
25
|
-
# CLAUDE_PRO_RATE_LIMIT_MAX_WAIT_MS=21600000 # 0 = fail instead of waiting
|
|
26
|
-
# BASH_DEFAULT_TIMEOUT_MS=600000
|
|
27
|
-
# BASH_MAX_TIMEOUT_MS=3600000
|
|
28
|
-
# BASH_MAX_OUTPUT_LENGTH=60000
|
|
29
|
-
# CLAUDE_CODE_GIT_BASH_PATH=C:\Program Files\Git\bin\bash.exe
|