@yanzc/claude-pro 0.7.0 → 0.7.2
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/.env.example +4 -6
- package/README.md +55 -99
- package/package.json +2 -2
- package/src/agent.js +19 -14
- package/src/api.js +1 -1
- package/src/attach.js +14 -0
- package/src/background.js +102 -12
- package/src/checkpoints.js +4 -2
- package/src/claude-code.js +4 -4
- package/src/commands.js +10 -29
- package/src/config.js +16 -22
- package/src/history.js +69 -0
- package/src/host.js +64 -10
- package/src/main.js +4 -5
- package/src/oauth.js +3 -3
- package/src/print.js +0 -1
- package/src/prompts.js +3 -11
- package/src/ratelimit.js +2 -2
- package/src/runtime.js +2 -6
- package/src/tools/index.js +2 -3
- package/src/tools/interaction.js +2 -30
- package/src/tools/task.js +1 -1
- package/src/ui/ansi.js +0 -1
- package/src/ui/render.js +0 -4
- package/src/ui/repl.js +32 -53
- package/src/modes.js +0 -154
- package/src/qr.js +0 -206
package/src/host.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Protocol (Bearer = the gateway API key; ARCHITECTURE.md 3.1.5):
|
|
9
9
|
// POST /v1/remote/hosts {id, machine, host, platform, version, home, terminal, autostart, sessions, stats}
|
|
10
10
|
// GET /v1/remote/hosts/:id/commands (SSE): online while it is open; {cid, type, body}: list, open, stop,
|
|
11
|
-
// restart, logs, history, update
|
|
11
|
+
// restart, window, logs, history, delete, update
|
|
12
12
|
// POST /v1/remote/hosts/:id/results {cid, ok: true, ...} | {cid, ok: false, error}
|
|
13
13
|
// POST /v1/remote/hosts/:id/state {sessions, stats}: on a change of the sessions, and every minute
|
|
14
14
|
// DELETE /v1/remote/hosts/:id: off the page's list (`host stop`, a logout, another account)
|
|
@@ -30,7 +30,7 @@ import { CONFIG_DIR, INSTALL_DIR, VERSION, GATEWAY_DEFAULT_URL, loadConfig } fro
|
|
|
30
30
|
import { readGatewayLogin, normalizeGatewayUrl } from './gateway.js';
|
|
31
31
|
import { machineName, cleanName, listPeers } from './peers.js';
|
|
32
32
|
import { BackgroundSessions, markEnded, tailFile } from './background.js';
|
|
33
|
-
import { listConversations } from './history.js';
|
|
33
|
+
import { listConversations, deleteConversation, CONVERSATION_ID } from './history.js';
|
|
34
34
|
import { checkForUpdate, installUpdate } from './updater.js';
|
|
35
35
|
import { ENV_SUPERVISED, ENV_RESTART_FILE, ENV_RESTARTED } from './supervisor.js';
|
|
36
36
|
|
|
@@ -444,15 +444,15 @@ function writeEnvFile(sessionId, vars) {
|
|
|
444
444
|
|
|
445
445
|
// How `term` opens a window that runs `node entry ...args` in `cwd`: {cmd, args, options, wait}. `wait`: 'exit'
|
|
446
446
|
// when the command ends once the window is open (its exit code says whether it worked), 'spawn' when it is the
|
|
447
|
-
// terminal itself.
|
|
448
|
-
export function launchCommand(term, { cwd, node = process.execPath, entry = ENTRY, args = [], env = {}, envFile = null, sessionId = '' }) {
|
|
447
|
+
// terminal itself. `title`: the tab's first title, where the terminal takes one (Windows Terminal).
|
|
448
|
+
export function launchCommand(term, { cwd, node = process.execPath, entry = ENTRY, args = [], env = {}, envFile = null, sessionId = '', title = '' }) {
|
|
449
449
|
const program = [node, ...(envFile ? [`--env-file=${envFile}`] : []), entry, ...args];
|
|
450
450
|
const pairs = Object.entries(env).map(([k, v]) => `${k}=${v}`);
|
|
451
451
|
const posix = [...(pairs.length ? ['env', ...pairs] : []), node, entry, ...args];
|
|
452
452
|
const line = posix.map(shQuote).join(' ');
|
|
453
453
|
switch (term.kind) {
|
|
454
454
|
case 'wt': // a new window; wt reads ; as the start of another command
|
|
455
|
-
return { cmd: term.path, args: ['-w', 'new', '-d', cwd, ...program].map((a) => a.replace(/;/g, '\\;')), options: { windowsHide: false }, wait: 'exit' };
|
|
455
|
+
return { cmd: term.path, args: ['-w', 'new', ...(title ? ['--title', title] : []), '-d', cwd, ...program].map((a) => a.replace(/;/g, '\\;')), options: { windowsHide: false }, wait: 'exit' };
|
|
456
456
|
case 'console': { // a console window of its own; Start-Process takes the command line as it is
|
|
457
457
|
// what went wrong: only its message, in UTF-8 (PowerShell writes errors as CLIXML in the system's code page)
|
|
458
458
|
const script = [
|
|
@@ -778,6 +778,8 @@ export class HostService {
|
|
|
778
778
|
else if (cmd.type === 'logs') r = this.logs(body);
|
|
779
779
|
else if (cmd.type === 'history') r = this.history(body);
|
|
780
780
|
else if (cmd.type === 'update') r = await this.update();
|
|
781
|
+
else if (cmd.type === 'window') r = await this.window(body);
|
|
782
|
+
else if (cmd.type === 'delete') r = await this.deleteConversation(body);
|
|
781
783
|
else throw new Error(`这台电脑上的 claude-pro ${VERSION} 不认识命令 ${cmd.type},请升级`);
|
|
782
784
|
result = { cid: cmd.cid, ok: true, ...r };
|
|
783
785
|
} catch (e) {
|
|
@@ -805,6 +807,57 @@ export class HostService {
|
|
|
805
807
|
});
|
|
806
808
|
}
|
|
807
809
|
|
|
810
|
+
// window: a background session brought to the front in a terminal window of this computer, `claude-pro attach` in
|
|
811
|
+
// it (chosen as open's terminal window is). A turn that runs goes on and shows there as it goes; the session stays
|
|
812
|
+
// the service's. Closing the window (its X included: the attach process ends) only detaches it. Each call opens
|
|
813
|
+
// another window. Without a desktop, a tmux session to attach to (`tmux attach -t claude-pro-<id>-…`).
|
|
814
|
+
async window({ sessionId } = {}) {
|
|
815
|
+
if (typeof sessionId !== 'string' || !ID.test(sessionId)) throw new Error('会话 id 不对');
|
|
816
|
+
const rec = this.sessions?.sessions.get(sessionId);
|
|
817
|
+
if (!rec) {
|
|
818
|
+
if (this.sessions?.ended.some((e) => e.sessionId === sessionId)) throw new Error('会话没有在运行');
|
|
819
|
+
throw new Error('这个会话不是这台电脑上的后台会话');
|
|
820
|
+
}
|
|
821
|
+
if (rec.state !== 'running' || !this.sessions.alive(rec)) throw new Error('会话没有在运行');
|
|
822
|
+
const label = rec.name || sessionId;
|
|
823
|
+
const term = this.terminal;
|
|
824
|
+
if (!term) throw new Error(`这台电脑没有可以打开窗口的桌面(可以在终端里运行 claude-pro attach ${label})`);
|
|
825
|
+
let cwd = rec.cwd;
|
|
826
|
+
try { if (!fs.statSync(cwd).isDirectory()) cwd = this.home; } catch { cwd = this.home; }
|
|
827
|
+
const env = passedEnv();
|
|
828
|
+
const key = `${sessionId}-w${Date.now().toString(36)}`; // its own env file and tmux session: one window more each time
|
|
829
|
+
const envFile = process.platform === 'win32' && term.kind === 'wt' ? writeEnvFile(key, env) : null;
|
|
830
|
+
try {
|
|
831
|
+
await this.launch(launchCommand(term, { cwd, args: ['attach', sessionId, '--keep-open'], env, envFile, sessionId: key, title: `${label} · claude-pro` }));
|
|
832
|
+
} catch (e) {
|
|
833
|
+
throw new Error(`无法用 ${term.name} 打开终端:${e.message}`);
|
|
834
|
+
}
|
|
835
|
+
this.log(`opened ${term.name} attached to the background session ${sessionId} (${label})`);
|
|
836
|
+
return { terminal: term.name };
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// delete: what this computer keeps of a conversation (see history.js), for good. Open in a background session of this
|
|
840
|
+
// service, that session is ended first with `stop` (as the stop command does), else it is refused; open in a terminal,
|
|
841
|
+
// it is refused: a terminal the user works in is not closed for them. {files, bytes}
|
|
842
|
+
async deleteConversation({ conversationId, stop = false } = {}) {
|
|
843
|
+
const id = conversationId;
|
|
844
|
+
if (typeof id !== 'string' || !CONVERSATION_ID.test(id)) throw new Error('对话 id 不对');
|
|
845
|
+
const open = listPeers().filter((p) => p.conversationId === id);
|
|
846
|
+
const ours = (p) => p.kind === 'background' && this.sessions?.sessions.has(p.remoteId);
|
|
847
|
+
const terminal = open.find((p) => !ours(p) && p.kind !== 'background');
|
|
848
|
+
if (terminal) throw new Error(`这段对话正开在终端里的会话 &${terminal.name} 里:请先在那台电脑上结束它(/exit)`);
|
|
849
|
+
const other = open.find((p) => !ours(p));
|
|
850
|
+
if (other) throw new Error(`这段对话正开在会话 &${other.name} 里:先结束它`);
|
|
851
|
+
// the service's own sessions with it: those in the registry, and those starting or restarting
|
|
852
|
+
const running = [...(this.sessions?.sessions.values() || [])].filter((r) => (r.conversationId === id || open.some((p) => p.remoteId === r.sessionId)) && this.sessions.alive(r));
|
|
853
|
+
if (running.length && stop !== true) throw new Error(`这段对话正开在会话 &${running[0].name || running[0].sessionId} 里:先结束它`);
|
|
854
|
+
for (const r of running) await this.sessions.stop(r.sessionId);
|
|
855
|
+
const logs = this.sessions ? this.sessions.forgetConversation(id) : [];
|
|
856
|
+
const r = deleteConversation({ projects: path.join(configDir(), 'projects'), id, extra: logs });
|
|
857
|
+
this.log(`deleted the conversation ${id}: ${r.files} files, ${r.bytes} bytes${running.length ? ` (its session ${running.map((x) => x.sessionId).join(', ')} ended first)` : ''}`);
|
|
858
|
+
return { files: r.files, bytes: r.bytes };
|
|
859
|
+
}
|
|
860
|
+
|
|
808
861
|
// The conversations kept on this computer (see history.js), with the session each one is open in.
|
|
809
862
|
history({ query, cwd, limit, before } = {}) {
|
|
810
863
|
if (before != null && Number.isNaN(Date.parse(before))) throw new Error('before 不是时间');
|
|
@@ -1119,7 +1172,7 @@ function statusCommand() {
|
|
|
1119
1172
|
const auto = installedAutostart();
|
|
1120
1173
|
const boot = bootAutostartInstalled();
|
|
1121
1174
|
const lines = [
|
|
1122
|
-
`claude-pro host (
|
|
1175
|
+
`claude-pro host (the web page runs and manages sessions on this computer through it): ${running ? `running, pid ${state.pid}, since ${state.startedAt || '?'}` : state.disabled ? 'stopped (claude-pro host start)' : 'not running (claude-pro host start)'}`,
|
|
1123
1176
|
];
|
|
1124
1177
|
if (running) lines.push(` gateway: ${state.gateway ? `${state.gateway}${state.account ? ` as ${state.account}` : ''} · ${state.online ? 'online' : 'not connected now'}` : 'not logged in (it waits for /login)'}`);
|
|
1125
1178
|
if (state.id) lines.push(` id: ${state.id}${state.machine ? ` · computer: ${state.machine}` : ''}${state.terminal ? ` · opens: ${state.terminal}` : ''}${state.version ? ` · version ${state.version}` : ''}`);
|
|
@@ -1370,10 +1423,11 @@ const USAGE = `Usage: claude-pro host [run | start | stop | status | install | u
|
|
|
1370
1423
|
|
|
1371
1424
|
The computer service: it makes this computer one the gateway's web page (远程控制) runs sessions on. From the
|
|
1372
1425
|
page: new sessions here, in the directory chosen there, in the background without a window (or, when asked, in
|
|
1373
|
-
a terminal window);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1426
|
+
a terminal window); bringing a background session to the front in a terminal window here (also while it works;
|
|
1427
|
+
closing the window sends it back); ending and restarting them; opening a conversation kept here again (history),
|
|
1428
|
+
or deleting it from this computer; their logs and its own; updating claude-pro. A background session that
|
|
1429
|
+
crashes is opened again, and after a restart of the computer the service opens again those that ran (the
|
|
1430
|
+
conversation, not the task that was running). \`claude-pro attach\` shows a background session in a terminal here.
|
|
1377
1431
|
|
|
1378
1432
|
It uses the gateway login of /login or claude-pro connect, and only connects out to the gateway. A session
|
|
1379
1433
|
logged in to the gateway starts it by itself, and /login and connect set it up to start at logon
|
package/src/main.js
CHANGED
|
@@ -5,7 +5,7 @@ import { takeRestartState } from './restart.js';
|
|
|
5
5
|
|
|
6
6
|
const HELP = `Usage: claude-pro [options] [prompt]
|
|
7
7
|
|
|
8
|
-
A
|
|
8
|
+
A command line coding agent: through the gateway, an Anthropic-compatible API, or your Claude subscription.
|
|
9
9
|
Starts an interactive session by default; use -p for non-interactive output.
|
|
10
10
|
|
|
11
11
|
Options:
|
|
@@ -15,7 +15,6 @@ Options:
|
|
|
15
15
|
--provider <backend> api (default) | claude-code (direct HTTP with existing local login)
|
|
16
16
|
--model <model> Model for this session (name or alias: opus, sonnet, haiku)
|
|
17
17
|
--effort <level> Reasoning effort: none|minimal|low|medium|high|xhigh|max
|
|
18
|
-
--plan Start in read-only plan mode (research first, then ExitPlanMode)
|
|
19
18
|
--output-format <format> text | json | stream-json (with --print)
|
|
20
19
|
--verify <command> After the agent edits files, run this (e.g. "npm test") and send failures back to fix
|
|
21
20
|
--append-system-prompt <text> Append text to the system prompt
|
|
@@ -33,7 +32,7 @@ Options:
|
|
|
33
32
|
There are no permission prompts: every tool runs immediately (full access). File edits are
|
|
34
33
|
checkpointed per prompt, and /rewind in a session undoes them. The old flags
|
|
35
34
|
--dangerously-skip-permissions, --permission-mode, --allowedTools and --disallowedTools
|
|
36
|
-
are accepted and ignored
|
|
35
|
+
are accepted and ignored, and so are --plan (there is no plan mode: ask for a plan in the message) and
|
|
37
36
|
--remote-control (--rc): a session is online at the gateway whenever this computer is logged in to it.
|
|
38
37
|
|
|
39
38
|
Commands:
|
|
@@ -71,8 +70,8 @@ function parseArgs(argv) {
|
|
|
71
70
|
case '--model': flags.model = next(); break;
|
|
72
71
|
case '--provider': flags.provider = next(); break;
|
|
73
72
|
case '--effort': flags.effort = next(); break;
|
|
74
|
-
case '--plan':
|
|
75
|
-
case '--permission-mode':
|
|
73
|
+
case '--plan': break; // no plan mode any more: asking for a plan in the message does it
|
|
74
|
+
case '--permission-mode': next(); break;
|
|
76
75
|
case '--dangerously-skip-permissions': break; // nothing to skip: there are no prompts
|
|
77
76
|
case '--allowedTools': case '--allowed-tools': case '--disallowedTools': case '--disallowed-tools': skipRules(); break;
|
|
78
77
|
case '--output-format': flags.outputFormat = next(); break;
|
package/src/oauth.js
CHANGED
|
@@ -209,7 +209,7 @@ async function renew(config, { force }) {
|
|
|
209
209
|
if (!oauth?.refreshToken) return { refreshed: false, reason: 'no refresh token' };
|
|
210
210
|
if (!force && !needsRefresh(oauth)) return { refreshed: false, reason: 'still valid' };
|
|
211
211
|
if (Number(oauth.refreshTokenExpiresAt) > 0 && Number(oauth.refreshTokenExpiresAt) <= timing.now()) {
|
|
212
|
-
throw new Error(`The Claude
|
|
212
|
+
throw new Error(`The Claude subscription login has expired and cannot be renewed: its refresh token ran out. ${SIGN_IN_AGAIN}`);
|
|
213
213
|
}
|
|
214
214
|
const startedWith = oauth.accessToken;
|
|
215
215
|
// somebody else renewed it while we were looking: take theirs
|
|
@@ -221,7 +221,7 @@ async function renew(config, { force }) {
|
|
|
221
221
|
const now = readStoredLogin(file)?.oauth;
|
|
222
222
|
// renewing early failed but the token still works: carry on with it (unless renewing was asked for)
|
|
223
223
|
if (!force && now && !isExpired(now)) return { refreshed: false, reason: why, stillValid: true };
|
|
224
|
-
throw new Error(force ? `The Claude
|
|
224
|
+
throw new Error(force ? `The Claude subscription login could not be renewed: ${why}` : `The Claude subscription access token has expired and could not be renewed: ${why}`);
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
let release;
|
|
@@ -251,7 +251,7 @@ async function renew(config, { force }) {
|
|
|
251
251
|
// new one: look before giving up.
|
|
252
252
|
if (res.status === 400 || res.status === 401 || res.status === 403) {
|
|
253
253
|
if (renewedElsewhere()) return { refreshed: false, reason: 'renewed by another process' };
|
|
254
|
-
throw new Error(`The Claude
|
|
254
|
+
throw new Error(`The Claude subscription login can no longer be renewed (${describeFailure(res.data) || `HTTP ${res.status}`}). ${SIGN_IN_AGAIN}`);
|
|
255
255
|
}
|
|
256
256
|
return failed(`the token server answered HTTP ${res.status}${describeFailure(res.data) ? ` (${describeFailure(res.data)})` : ''}`);
|
|
257
257
|
} finally {
|
package/src/print.js
CHANGED
|
@@ -27,7 +27,6 @@ export async function runPrint({ prompt, flags, cwd, stdout = process.stdout, st
|
|
|
27
27
|
};
|
|
28
28
|
const mainRateLimit = rateLimitReporter();
|
|
29
29
|
const io = {
|
|
30
|
-
approvePlan: async () => 'reject', // non-interactive: a plan is only presented, never executed
|
|
31
30
|
askQuestion: async () => null,
|
|
32
31
|
notice: (text) => err(c.yellow(text)),
|
|
33
32
|
toolStart: (tu, tool, input, agent) => {
|
package/src/prompts.js
CHANGED
|
@@ -50,10 +50,7 @@ export function mainSystemPrompt({ cwd, model, shellName, extra = '', autoMemory
|
|
|
50
50
|
? `\n\n# Memory\nProject and user instructions are shown below: the facts of this project (its environment, mechanisms, commands) and how the user wants to work in it. Where they differ from the defaults above, they win.\n\n${files}`
|
|
51
51
|
: '';
|
|
52
52
|
|
|
53
|
-
return `You are ${APP_NAME}, an interactive command line agent
|
|
54
|
-
|
|
55
|
-
IMPORTANT: Assist with authorized security testing, defensive security, CTF challenges, and educational contexts. Refuse requests for destructive techniques, DoS attacks, mass targeting, supply chain compromise, or detection evasion for malicious purposes. Dual-use security tools (C2 frameworks, credential testing, exploit development) require clear authorization context: pentesting engagements, CTF competitions, security research, or defensive use cases.
|
|
56
|
-
Do not make up URLs. Give a URL only when it came from the user, a file or a tool result, or when you know it exists; when you are not sure of an address, look it up with WebSearch or say that you are not sure.
|
|
53
|
+
return `You are ${APP_NAME}, an interactive command line agent. You help the user with software engineering tasks (solving bugs, adding functionality, refactoring, explaining code, running builds and tests) and with anything else they ask that you can do with your knowledge and the tools on this machine. Use the instructions below and the tools available to you to assist the user.
|
|
57
54
|
|
|
58
55
|
# Communication
|
|
59
56
|
- Your output is shown in a terminal, rendered as GitHub-flavored markdown in a monospace font: keep it scannable.
|
|
@@ -64,7 +61,7 @@ Do not make up URLs. Give a URL only when it came from the user, a file or a too
|
|
|
64
61
|
- If you cannot or will not help with something, say so briefly without lecturing, and offer alternatives if possible.
|
|
65
62
|
|
|
66
63
|
# How you work
|
|
67
|
-
You run on the user's own test machine with full access: tool calls run without asking the user for confirmation, except where a control of the program (
|
|
64
|
+
You run on the user's own test machine with full access: tool calls run without asking the user for confirmation, except where a control of the program (a hook) steps in. Use that freedom to get the job done. Do not ask for permission to read, write, install, run or delete what the task needs, and decide how to go about it (how much to plan, whether to use sub-agents, how to verify) by what the task needs rather than by a fixed procedure.
|
|
68
65
|
- Aim at the user's goal rather than the letter of the steps they described: when you see a clearly better way to reach it, take it and say why, unless they asked for their way specifically. Do not change the goal itself or a constraint they set.
|
|
69
66
|
- When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-argue a decision the user has made, or lay out options you will not pursue; when you weigh a choice, give a recommendation, not a survey.
|
|
70
67
|
- Work end to end: understand, implement, run and verify before reporting back. Do not stop at a plan unless asked for one.
|
|
@@ -86,7 +83,7 @@ You run on the user's own test machine with full access: tool calls run without
|
|
|
86
83
|
# Tools
|
|
87
84
|
- Call independent tools together in one response so that they run in parallel; run dependent ones one after another.
|
|
88
85
|
- Delegate to sub-agents (Task) when that makes the work better, faster or keeps your context small: broad searches, independent subtasks, a second look at risky work. Weigh what it costs first: each agent builds its own context and spends its own tokens (from the user's usage limit too), it does not see what you or other agents know, and agents that edit related files at the same time get in each other's way. Closely coupled work that needs shared state is usually better done yourself. Use run_in_background for long jobs.
|
|
89
|
-
- If a tool call is blocked (by
|
|
86
|
+
- If a tool call is blocked (by a hook or another control of the program), do not retry it or get around it another way: adjust your approach within what is allowed, or tell the user what is in the way.
|
|
90
87
|
- Tool results and user messages may include <system-reminder> tags: information added by the harness, not part of the user's request.
|
|
91
88
|
|
|
92
89
|
${selfRestart ? `# Your own source code
|
|
@@ -137,11 +134,6 @@ ${message}
|
|
|
137
134
|
${current ? 'Does this message start a new topic (a different task or question), or does it continue the current one (a follow-up, "continue", an answer, a correction)? ' : ''}Reply with only a JSON object: {"isNewTopic": ${current ? 'true or false' : 'true'}, "title": ...}. For a new topic, "title" names it in 2 to 6 words (at most about 16 characters in Chinese or Japanese), in the language of the user's message, with no quotes, no emoji and no punctuation at the end. Otherwise "title" is null.`;
|
|
138
135
|
}
|
|
139
136
|
|
|
140
|
-
export const PLAN_MODE_REMINDER = `<system-reminder>
|
|
141
|
-
Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supersedes any other instructions you have received.
|
|
142
|
-
Research the codebase with read-only tools, then present a concise implementation plan by calling the ExitPlanMode tool. Do not ask for approval in plain text; use ExitPlanMode.
|
|
143
|
-
</system-reminder>`;
|
|
144
|
-
|
|
145
137
|
// The system prompt of the plain summary request (see Agent.requestSummary).
|
|
146
138
|
export const SUMMARY_SYSTEM = 'You are a helpful AI assistant tasked with summarizing conversations.';
|
|
147
139
|
|
package/src/ratelimit.js
CHANGED
|
@@ -240,7 +240,7 @@ export function describePause(ev, now = Date.now()) {
|
|
|
240
240
|
if (ev.waitingForLogin) {
|
|
241
241
|
const until = ev.giveUpAt ? ` Giving up at ${formatClock(ev.giveUpAt, now)}.` : '';
|
|
242
242
|
if (ev.renewError) return `The limit has reset, but the login could not be renewed: ${ev.renewError} Trying again every 5 minutes, and this continues by itself as soon as the login is valid.${until}`;
|
|
243
|
-
return `The limit has reset, but the Claude
|
|
243
|
+
return `The limit has reset, but the Claude subscription login has expired and cannot be renewed from here. Waiting for it to be renewed: run claude once, and this continues by itself.${until}`;
|
|
244
244
|
}
|
|
245
245
|
const label = capitalize(ev.label || 'rate limit');
|
|
246
246
|
const left = humanDuration(Math.max(0, ev.resumeAt - now));
|
|
@@ -249,7 +249,7 @@ export function describePause(ev, now = Date.now()) {
|
|
|
249
249
|
? `${label} reached and the server gave no reset time. Checking again at ${formatClock(ev.resumeAt, now)} (in ${left}), and every few minutes after that, then continuing automatically.`
|
|
250
250
|
: `${label} reached. Pausing until ${formatClock(ev.resumeAt, now)} (in ${left}), then continuing automatically.`;
|
|
251
251
|
const warning = ev.loginExpiresAt && ev.loginExpiresAt < ev.resumeAt
|
|
252
|
-
? ` The Claude
|
|
252
|
+
? ` The Claude subscription login expires at ${formatClock(ev.loginExpiresAt, now)}, before that, and it cannot be renewed from here. If no claude command is running to renew it, run claude once after the reset: this continues by itself once the login is valid again.`
|
|
253
253
|
: '';
|
|
254
254
|
return text + warning;
|
|
255
255
|
}
|
package/src/runtime.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
5
|
import { loadConfig, applyRememberedChoices, SOURCE_CHECKOUT } from './config.js';
|
|
6
|
-
import { ModeManager } from './modes.js';
|
|
7
6
|
import { CheckpointStore } from './checkpoints.js';
|
|
8
7
|
import { loadAgents, loadSkills } from './agents.js';
|
|
9
8
|
import { buildTools, toolsForSubagent } from './tools/index.js';
|
|
@@ -25,8 +24,7 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
25
24
|
pruneToolResults(cwd);
|
|
26
25
|
pruneCheckpoints(cwd);
|
|
27
26
|
pruneStaleShellFiles();
|
|
28
|
-
// Full access: nothing is ever asked.
|
|
29
|
-
const modes = new ModeManager(flags.plan ? 'plan' : 'full');
|
|
27
|
+
// Full access: nothing is ever asked.
|
|
30
28
|
const checkpoints = new CheckpointStore(path.join(projectDir(cwd), 'checkpoints', `${Date.now()}-${crypto.randomBytes(3).toString('hex')}`));
|
|
31
29
|
|
|
32
30
|
const agents = loadAgents(cwd);
|
|
@@ -37,7 +35,7 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
37
35
|
const hooks = new HookRunner(config);
|
|
38
36
|
const tasks = new BackgroundTasks();
|
|
39
37
|
const memoryDir = autoMemoryDir(cwd);
|
|
40
|
-
const runtime = { config,
|
|
38
|
+
const runtime = { config, checkpoints, agents, mcp, shell, io, cwd, hooks, tasks, memoryDir };
|
|
41
39
|
runtime.skills = loadSkills(cwd);
|
|
42
40
|
// The self-check builds the Restart tool too, so that a mistake in it is found before a restart relies on it.
|
|
43
41
|
const restartable = canRestart() || process.env.CLAUDE_PRO_SELF_CHECK === '1';
|
|
@@ -116,7 +114,6 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
116
114
|
const depth = (ctx.depth ?? ctx.agent?.depth ?? 0) + 1;
|
|
117
115
|
const sub = new Agent({
|
|
118
116
|
config,
|
|
119
|
-
modes,
|
|
120
117
|
checkpoints,
|
|
121
118
|
depth,
|
|
122
119
|
spawnSubagent: runtime.spawnSubagent,
|
|
@@ -148,7 +145,6 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
148
145
|
|
|
149
146
|
runtime.agent = new Agent({
|
|
150
147
|
config,
|
|
151
|
-
modes,
|
|
152
148
|
checkpoints,
|
|
153
149
|
tools: runtime.tools,
|
|
154
150
|
systemPrompt: runtime.systemPrompt,
|
package/src/tools/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ReadTool, WriteTool, EditTool } from './files.js';
|
|
|
2
2
|
import { makeBashTool, BashOutputTool, KillShellTool } from './bash.js';
|
|
3
3
|
import { GlobTool, GrepTool } from './search.js';
|
|
4
4
|
import { makeWebFetchTool, WebSearchTool } from './web.js';
|
|
5
|
-
import { TodoWriteTool,
|
|
5
|
+
import { TodoWriteTool, AskUserQuestionTool } from './interaction.js';
|
|
6
6
|
import { makeTaskTool, TaskOutputTool, TaskStopTool } from './task.js';
|
|
7
7
|
import { NotebookEditTool } from './notebook.js';
|
|
8
8
|
import { makeSkillTool } from './skill.js';
|
|
@@ -31,7 +31,6 @@ export function buildTools(config, { agents, skills, mcpTools = [], restart = fa
|
|
|
31
31
|
TodoWriteTool,
|
|
32
32
|
BashOutputTool,
|
|
33
33
|
KillShellTool,
|
|
34
|
-
ExitPlanModeTool,
|
|
35
34
|
AskUserQuestionTool,
|
|
36
35
|
makeEffortTool(config),
|
|
37
36
|
...(restart ? [RestartTool] : []),
|
|
@@ -41,7 +40,7 @@ export function buildTools(config, { agents, skills, mcpTools = [], restart = fa
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
// Effort: a sub-agent shares the main agent's settings, so it must not change them.
|
|
44
|
-
const NEVER_FOR_SUBAGENTS = new Set(['TaskOutput', 'TaskStop', 'TodoWrite', '
|
|
43
|
+
const NEVER_FOR_SUBAGENTS = new Set(['TaskOutput', 'TaskStop', 'TodoWrite', 'AskUserQuestion', 'Restart', 'Effort', 'ListPeers', 'MessagePeer']);
|
|
45
44
|
|
|
46
45
|
// Tools for a sub-agent. `allowTask`: it is below the nesting limit, so it may start sub-agents of its own.
|
|
47
46
|
export function toolsForSubagent(allTools, def, { allowTask = false } = {}) {
|
package/src/tools/interaction.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Tools that interact with the session rather than the machine: TodoWrite
|
|
2
|
-
// ExitPlanMode and AskUserQuestion.
|
|
1
|
+
// Tools that interact with the session rather than the machine: TodoWrite and AskUserQuestion.
|
|
3
2
|
|
|
4
3
|
export const TodoWriteTool = {
|
|
5
4
|
name: 'TodoWrite',
|
|
@@ -36,6 +35,7 @@ How:
|
|
|
36
35
|
async call(input, ctx) {
|
|
37
36
|
const todos = Array.isArray(input.todos) ? input.todos.filter((t) => t && t.content) : [];
|
|
38
37
|
ctx.agent.todos = todos.every((t) => t.status === 'completed') ? [] : todos;
|
|
38
|
+
ctx.agent.todosTurn = ctx.agent.userTurns; // see Agent.noteUserTurn
|
|
39
39
|
return {
|
|
40
40
|
content: 'The todo list is updated.',
|
|
41
41
|
display: { todos },
|
|
@@ -43,34 +43,6 @@ How:
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export const ExitPlanModeTool = {
|
|
47
|
-
name: 'ExitPlanMode',
|
|
48
|
-
readOnly: true,
|
|
49
|
-
description: `Use this tool when you are in plan mode and have finished planning the implementation steps of a task that requires writing code, and are ready to code. This will prompt the user to approve your plan.
|
|
50
|
-
Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.`,
|
|
51
|
-
input_schema: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
plan: { type: 'string', description: 'The plan you came up with, that you want to run by the user for approval. Supports markdown. The plan should be pretty concise.' },
|
|
55
|
-
},
|
|
56
|
-
required: ['plan'],
|
|
57
|
-
},
|
|
58
|
-
summarize() { return ''; },
|
|
59
|
-
async call(input, ctx) {
|
|
60
|
-
if (ctx.modes.mode !== 'plan') return { isError: true, content: 'You are not in plan mode. Proceed with the task.' };
|
|
61
|
-
const choice = await ctx.io.approvePlan(input.plan);
|
|
62
|
-
if (choice === 'full') {
|
|
63
|
-
ctx.modes.setMode('full');
|
|
64
|
-
return { content: 'User has approved your plan. You can now start coding. Start with updating your todo list if applicable.', display: { plan: input.plan, approved: true } };
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
content: 'The user wants to keep planning. Do not start implementation. Wait for the user to explain what should change in the plan.',
|
|
68
|
-
display: { plan: input.plan, approved: false },
|
|
69
|
-
stopTurn: true,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
46
|
export const AskUserQuestionTool = {
|
|
75
47
|
name: 'AskUserQuestion',
|
|
76
48
|
readOnly: true,
|
package/src/tools/task.js
CHANGED
|
@@ -96,7 +96,7 @@ Usage notes:
|
|
|
96
96
|
if (input.run_in_background) {
|
|
97
97
|
if (!ctx.tasks) return { isError: true, content: 'Background agents are not available here; run the task in the foreground.' };
|
|
98
98
|
// The task outlives this turn, so it gets its own signal and no live progress display.
|
|
99
|
-
const base = { cwd: ctx.cwd, projectRoot: ctx.projectRoot, config: ctx.config,
|
|
99
|
+
const base = { cwd: ctx.cwd, projectRoot: ctx.projectRoot, config: ctx.config, checkpoints: ctx.checkpoints, io: ctx.io, depth: ctx.agent?.depth ?? 0 };
|
|
100
100
|
const task = ctx.tasks.start({
|
|
101
101
|
description: input.description || def.name,
|
|
102
102
|
subagentType: def.name,
|
package/src/ui/ansi.js
CHANGED
|
@@ -48,7 +48,6 @@ export const c = {
|
|
|
48
48
|
white: hex('#ffffff'),
|
|
49
49
|
claude: hex('#d77757'), // the orange brand accent
|
|
50
50
|
permission: hex('#b1b9f9'),
|
|
51
|
-
plan: hex('#48968c'),
|
|
52
51
|
edits: hex('#af87ff'),
|
|
53
52
|
code: hex('#b1b9f9'),
|
|
54
53
|
userBg: hex('#373737', true), // the band behind the user's messages (see renderUserMessage)
|
package/src/ui/render.js
CHANGED
|
@@ -99,10 +99,6 @@ export function renderToolResult(entry, { verbose = false, width = 100, cwd }) {
|
|
|
99
99
|
return resultLines([...partial.map((l) => c.dim(truncate(l, w))), c.red('Interrupted by user')]);
|
|
100
100
|
}
|
|
101
101
|
if (d.todos) return renderTodos(d.todos);
|
|
102
|
-
if (d.plan !== undefined) {
|
|
103
|
-
const md = renderMarkdown(d.plan, { width: w });
|
|
104
|
-
return resultLines([d.approved ? c.green('User approved the plan') : c.yellow('User asked to keep planning'), ...(verbose ? md : [])]);
|
|
105
|
-
}
|
|
106
102
|
if (d.preview && !r.isError) {
|
|
107
103
|
const lines = [d.summary ? `${d.summary}` : ''];
|
|
108
104
|
if (d.preview.kind === 'create' && !verbose) return resultLines([d.summary || `Created ${displayPath(d.preview.path, cwd)}`]);
|