@yanzc/claude-pro 0.7.4 → 0.7.6
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 +26 -2
- package/package.json +1 -1
- package/src/agent.js +211 -81
- package/src/agents.js +0 -1
- package/src/commands.js +165 -22
- package/src/config.js +27 -12
- package/src/context.js +3 -1
- package/src/host.js +8 -1
- package/src/main.js +6 -2
- package/src/print.js +2 -1
- package/src/prompt-profiles.js +115 -0
- package/src/prompts.js +1 -1
- package/src/runtime.js +16 -9
- package/src/tools/effort.js +1 -1
- package/src/tools/index.js +1 -1
- package/src/tools/task.js +6 -28
- package/src/tools/web.js +4 -4
- package/src/trace.js +477 -0
- package/src/ui/repl.js +31 -21
- package/src/ui/screen.js +32 -1
- package/src/updater.js +4 -7
- package/src/verify.js +57 -0
package/src/runtime.js
CHANGED
|
@@ -16,9 +16,12 @@ import { BackgroundTasks, taskNotification } from './tasks.js';
|
|
|
16
16
|
import { autoMemoryDir, pruneToolResults, pruneCheckpoints, projectDir } from './session.js';
|
|
17
17
|
import { loadAutoMemoryIndex, takeEnvSnapshot, localDate } from './context.js';
|
|
18
18
|
import { canRestart } from './restart.js';
|
|
19
|
+
import { RuntimeTrace } from './trace.js';
|
|
20
|
+
import { loadActivePrompt } from './prompt-profiles.js';
|
|
19
21
|
|
|
20
|
-
export async function createRuntime({ cwd, flags = {}, io }) {
|
|
22
|
+
export async function createRuntime({ cwd, flags = {}, io, sessionId = '' }) {
|
|
21
23
|
const config = loadConfig({ cwd, flags });
|
|
24
|
+
const trace = new RuntimeTrace({ cwd, sessionId, enabled: config.traceEnabled, dir: config.traceDir, maxBytes: config.traceMaxBytes });
|
|
22
25
|
applyRememberedChoices(config, flags); // what /model and /effort chose last time
|
|
23
26
|
if (flags.verify) config.verifyOverride = flags.verify;
|
|
24
27
|
pruneToolResults(cwd);
|
|
@@ -35,7 +38,7 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
35
38
|
const hooks = new HookRunner(config);
|
|
36
39
|
const tasks = new BackgroundTasks();
|
|
37
40
|
const memoryDir = autoMemoryDir(cwd);
|
|
38
|
-
const runtime = { config, checkpoints, agents, mcp, shell, io, cwd, hooks, tasks, memoryDir };
|
|
41
|
+
const runtime = { config, checkpoints, agents, mcp, shell, io, cwd, hooks, tasks, memoryDir, trace };
|
|
39
42
|
runtime.skills = loadSkills(cwd);
|
|
40
43
|
// The self-check builds the Restart tool too, so that a mistake in it is found before a restart relies on it.
|
|
41
44
|
const restartable = canRestart() || process.env.CLAUDE_PRO_SELF_CHECK === '1';
|
|
@@ -59,9 +62,12 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
59
62
|
runtime.systemPrompt = () => {
|
|
60
63
|
if (!promptCache) {
|
|
61
64
|
const autoMemory = config.autoMemoryEnabled ? { dir: memoryDir, index: loadAutoMemoryIndex(memoryDir) } : null;
|
|
65
|
+
const savedPrompt = flags.systemPrompt === undefined ? loadActivePrompt() : null;
|
|
62
66
|
promptCache = flags.systemPrompt !== undefined
|
|
63
67
|
? flags.systemPrompt
|
|
64
|
-
:
|
|
68
|
+
: savedPrompt?.text != null
|
|
69
|
+
? savedPrompt.text
|
|
70
|
+
: mainSystemPrompt({ cwd, model: config.model, shellName: shell.name, extra: flags.appendSystemPrompt || '', autoMemory, mcpInstructions: mcp.promptInstructions(), selfRestart: selfEdit, installedCopy: !SOURCE_CHECKOUT, autoCompact: config.autoCompactEnabled, snapshot: snapshotFor(cwd) });
|
|
65
71
|
promptStale = false;
|
|
66
72
|
}
|
|
67
73
|
return promptCache;
|
|
@@ -84,7 +90,7 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
84
90
|
const extra = flags.appendSystemPrompt || '';
|
|
85
91
|
if (extra && !saved.endsWith(`\n\n${extra}`)) return false;
|
|
86
92
|
const modelIn = (text) => /^You are powered by the model (.+)\.$/m.exec(text)?.[1];
|
|
87
|
-
if (modelIn(saved) !== config.
|
|
93
|
+
if (modelIn(saved) !== config.model.id) return false;
|
|
88
94
|
promptCache = saved;
|
|
89
95
|
promptStale = false;
|
|
90
96
|
const then = /^Today's date: (\d{4}-\d{2}-\d{2})$/m.exec(saved)?.[1];
|
|
@@ -107,10 +113,9 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
107
113
|
return true;
|
|
108
114
|
};
|
|
109
115
|
|
|
110
|
-
//
|
|
111
|
-
runtime.spawnSubagent = async ({ def, prompt, description, ctx,
|
|
112
|
-
const
|
|
113
|
-
const model = spec ? config.resolveModel(spec) : config.subagentModel;
|
|
116
|
+
// Every agent uses the model selected for this session; effort may still be specific to the task.
|
|
117
|
+
runtime.spawnSubagent = async ({ def, prompt, description, ctx, effort }) => {
|
|
118
|
+
const model = config.model;
|
|
114
119
|
const subIo = io.subagentIo ? io.subagentIo({ def, description, parentCtx: ctx }) : {};
|
|
115
120
|
// The main agent is depth 0; an agent below the nesting limit may start sub-agents itself.
|
|
116
121
|
const depth = (ctx.depth ?? ctx.agent?.depth ?? 0) + 1;
|
|
@@ -130,6 +135,7 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
130
135
|
hooks,
|
|
131
136
|
effort: effort || def.effort,
|
|
132
137
|
compactWindow: def.autoCompactWindow,
|
|
138
|
+
trace,
|
|
133
139
|
});
|
|
134
140
|
let result;
|
|
135
141
|
try {
|
|
@@ -152,13 +158,14 @@ export async function createRuntime({ cwd, flags = {}, io }) {
|
|
|
152
158
|
tools: runtime.tools,
|
|
153
159
|
systemPrompt: runtime.systemPrompt,
|
|
154
160
|
io,
|
|
155
|
-
model: () => config.
|
|
161
|
+
model: () => config.model,
|
|
156
162
|
cwd,
|
|
157
163
|
spawnSubagent: runtime.spawnSubagent,
|
|
158
164
|
hooks,
|
|
159
165
|
tasks,
|
|
160
166
|
refreshSystemPrompt: () => runtime.invalidateSystemPrompt(), // a compaction starts the conversation over
|
|
161
167
|
beforeTurn: () => runtime.noteDateChange(),
|
|
168
|
+
trace,
|
|
162
169
|
});
|
|
163
170
|
|
|
164
171
|
// A finished background agent's report is queued for the main agent; the UI decides
|
package/src/tools/effort.js
CHANGED
|
@@ -25,7 +25,7 @@ Do not raise it for routine work, and do not switch back and forth: the prompt c
|
|
|
25
25
|
async call(input) {
|
|
26
26
|
const level = String(input.level || '').trim().toLowerCase();
|
|
27
27
|
if (!EFFORT_LEVELS.includes(level)) return { isError: true, content: `Unknown effort "${input.level}". Use one of: ${EFFORT_LEVELS.join(', ')}.` };
|
|
28
|
-
const shown = () => config.effort || defaultEffort(config.
|
|
28
|
+
const shown = () => config.effort || defaultEffort(config.model.id, config) || 'the model default';
|
|
29
29
|
const before = shown();
|
|
30
30
|
if (level === before) return { content: `The effort is already ${level}.` };
|
|
31
31
|
config.effortBoost = null;
|
package/src/tools/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { ListPeersTool, MessagePeerTool } from './peers.js';
|
|
|
15
15
|
// `peers`: an interactive session, which can talk to the other sessions on this machine.
|
|
16
16
|
export function buildTools(config, { agents, skills, mcpTools = [], restart = false, peers = false }) {
|
|
17
17
|
return [
|
|
18
|
-
makeTaskTool(agents
|
|
18
|
+
makeTaskTool(agents),
|
|
19
19
|
...(skills?.size ? [makeSkillTool(skills)] : []),
|
|
20
20
|
TaskOutputTool,
|
|
21
21
|
TaskStopTool,
|
package/src/tools/task.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import { taskResultText } from '../tasks.js';
|
|
6
6
|
import { EFFORTS } from '../agents.js';
|
|
7
|
-
import { priceOf } from '../pricing.js';
|
|
8
7
|
|
|
9
8
|
// Wait for `promise`, at most `ms`, or until `signal` aborts. The timer is always cleared so a
|
|
10
9
|
// finished wait never keeps the process alive.
|
|
@@ -21,29 +20,9 @@ function waitFor(promise, ms, signal) {
|
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
// aliases stand for, with their prices. Built from the configuration of the moment, so that it follows /model and
|
|
26
|
-
// /login (which start a new prompt cache anyway); it holds nothing that changes otherwise.
|
|
27
|
-
export function modelChoiceText(config) {
|
|
28
|
-
if (!config?.subagentModelChosen) return '';
|
|
29
|
-
const main = config.mainModel.id;
|
|
30
|
-
const option = (alias) => {
|
|
31
|
-
const id = config.resolveModel(alias).id;
|
|
32
|
-
const p = priceOf(id);
|
|
33
|
-
return `${alias} (${id}${id === main ? ', your own model' : ''}${p ? `, $${p.input}/$${p.output} per million input/output tokens` : ''})`;
|
|
34
|
-
};
|
|
35
|
-
return `
|
|
36
|
-
|
|
37
|
-
Choosing the model: there is no fixed sub-agent model. Choose one for each task by how hard it is and how much you will rely on the report, and give it in \`model\`:
|
|
38
|
-
- ${option('haiku')}: mechanical work with a clear target: find where something is defined or used, list files, read files and quote the relevant parts.
|
|
39
|
-
- ${option('sonnet')}: searches across a codebase and well-specified subtasks whose steps are clear: gather the call sites of a function and how they use it, run tests and summarize the failures, make a change that is fully described.
|
|
40
|
-
- ${option('opus')}: work whose quality your answer depends on and that you will not redo yourself: hard debugging, design and trade-offs, reviewing code for subtle bugs, analysis that spans many files.
|
|
41
|
-
A shallow or wrong report that you rely on costs more than the difference in price; a strong model on a lookup only wastes money. Set \`effort\` with it (low suits lookups); without it the agent runs at your session's effort. Without \`model\` an agent runs on its definition's model, else on ${config.subagentModel.id}.`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function makeTaskTool(agents, config = null) {
|
|
23
|
+
export function makeTaskTool(agents) {
|
|
45
24
|
const list = [...agents.values()]
|
|
46
|
-
.map((a) => `- ${a.name}: ${a.description} (Tools: ${a.tools === '*' ? 'All tools' : a.tools.join(', ')})
|
|
25
|
+
.map((a) => `- ${a.name}: ${a.description} (Tools: ${a.tools === '*' ? 'All tools' : a.tools.join(', ')})`)
|
|
47
26
|
.join('\n');
|
|
48
27
|
return {
|
|
49
28
|
name: 'Task',
|
|
@@ -65,9 +44,9 @@ Usage notes:
|
|
|
65
44
|
- When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
|
|
66
45
|
- Each agent invocation is stateless. Your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message.
|
|
67
46
|
- Once you have delegated a search or an investigation, do not also do it yourself: wait for the report, doing other work meanwhile. Never make up or predict the result of an agent that is still running; if the user asks before it is done, say that it is still running.
|
|
68
|
-
-
|
|
47
|
+
- Every agent uses the model currently selected for this session. An agent may still use its own effort level when the task needs it. Use the agent's report to find your way, but before you build an answer or a change on one of its findings, check that finding yourself (read the lines it cites).
|
|
69
48
|
- Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
|
|
70
|
-
- Set run_in_background: true to start the agent and continue working while it runs (e.g. a long investigation, or several independent jobs). You get a task id back immediately, and the agent's final report arrives automatically in a <task-notification> once it finishes; you do not need to poll. Use TaskOutput to check on or wait for it early, and TaskStop to cancel it. Do not start background agents that edit the same files at the same time
|
|
49
|
+
- Set run_in_background: true to start the agent and continue working while it runs (e.g. a long investigation, or several independent jobs). You get a task id back immediately, and the agent's final report arrives automatically in a <task-notification> once it finishes; you do not need to poll. Use TaskOutput to check on or wait for it early, and TaskStop to cancel it. Do not start background agents that edit the same files at the same time.`,
|
|
71
50
|
input_schema: {
|
|
72
51
|
type: 'object',
|
|
73
52
|
properties: {
|
|
@@ -75,13 +54,12 @@ Usage notes:
|
|
|
75
54
|
prompt: { type: 'string', description: 'The task for the agent to perform' },
|
|
76
55
|
subagent_type: { type: 'string', description: 'The type of specialized agent to use for this task' },
|
|
77
56
|
run_in_background: { type: 'boolean', description: 'Run the agent in the background and return immediately with a task id' },
|
|
78
|
-
model: { type: 'string', description: 'Model for this agent: haiku, sonnet, opus or a full model id. Pick it by how hard the task is: a smaller model is cheaper and faster for lookups and clear subtasks, a stronger one is right when you rely on the quality of its report. Defaults to the agent definition\'s model, else the sub-agent default.' },
|
|
79
57
|
effort: { type: 'string', enum: EFFORTS, description: 'Optional effort level for this agent (default: the agent definition\'s, else the session\'s). Low suits quick lookups, high or above hard reasoning.' },
|
|
80
58
|
},
|
|
81
59
|
required: ['description', 'prompt', 'subagent_type'],
|
|
82
60
|
},
|
|
83
61
|
summarize(input) {
|
|
84
|
-
const on =
|
|
62
|
+
const on = input.effort ? `effort ${input.effort}` : '';
|
|
85
63
|
return `${input.description || ''}${on ? ` (${on})` : ''}${input.run_in_background ? ' (background)' : ''}`;
|
|
86
64
|
},
|
|
87
65
|
label(input) { return input.subagent_type && input.subagent_type !== 'general-purpose' ? input.subagent_type : 'Task'; },
|
|
@@ -92,7 +70,7 @@ Usage notes:
|
|
|
92
70
|
}
|
|
93
71
|
const effort = input.effort ? String(input.effort).toLowerCase() : undefined;
|
|
94
72
|
if (effort && !EFFORTS.includes(effort)) return { isError: true, content: `Unknown effort '${input.effort}'. Use one of: ${EFFORTS.join(', ')}.` };
|
|
95
|
-
const choice = {
|
|
73
|
+
const choice = { effort };
|
|
96
74
|
if (input.run_in_background) {
|
|
97
75
|
if (!ctx.tasks) return { isError: true, content: 'Background agents are not available here; run the task in the foreground.' };
|
|
98
76
|
// The task outlives this turn, so it gets its own signal and no live progress display.
|
package/src/tools/web.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// WebFetch (fetch a page, convert to markdown-ish text, answer a prompt about it with the
|
|
2
|
-
//
|
|
2
|
+
// currently selected model) and WebSearch (DuckDuckGo HTML endpoint with a Bing fallback).
|
|
3
3
|
|
|
4
4
|
import { quickQuery } from '../api.js';
|
|
5
5
|
|
|
@@ -140,7 +140,7 @@ export function makeWebFetchTool(config) {
|
|
|
140
140
|
return {
|
|
141
141
|
name: 'WebFetch',
|
|
142
142
|
readOnly: true,
|
|
143
|
-
description: `- Fetches content from a specified URL (any scheme the network allows, including localhost and private addresses), converts HTML to markdown, and answers a prompt about it using
|
|
143
|
+
description: `- Fetches content from a specified URL (any scheme the network allows, including localhost and private addresses), converts HTML to markdown, and answers a prompt about it using the model currently selected for this session
|
|
144
144
|
- Takes a URL and a prompt as input
|
|
145
145
|
- Set raw: true to get the converted page text itself instead of an answer: use it when you need the exact content, code, tables or the whole document (very long pages are saved to a file and previewed; read the file for the rest)
|
|
146
146
|
- Use this tool when you need to retrieve and analyze web content
|
|
@@ -155,7 +155,7 @@ Usage notes:
|
|
|
155
155
|
properties: {
|
|
156
156
|
url: { type: 'string', format: 'uri', description: 'The URL to fetch content from' },
|
|
157
157
|
prompt: { type: 'string', description: 'The prompt to run on the fetched content' },
|
|
158
|
-
raw: { type: 'boolean', description: 'Return the converted page text itself instead of an answer from the
|
|
158
|
+
raw: { type: 'boolean', description: 'Return the converted page text itself instead of an answer from the selected model' },
|
|
159
159
|
},
|
|
160
160
|
required: ['url'],
|
|
161
161
|
},
|
|
@@ -182,7 +182,7 @@ Usage notes:
|
|
|
182
182
|
const content = page.text.length > 400_000 ? page.text.slice(0, 400_000) + '\n\n[content truncated]' : page.text;
|
|
183
183
|
try {
|
|
184
184
|
const answer = await quickQuery(config, {
|
|
185
|
-
model: config.
|
|
185
|
+
model: config.model,
|
|
186
186
|
system: 'You extract information from web pages. Answer only from the provided content. Be complete and precise: include every relevant detail, exact quotes, numbers and code. Keep code blocks intact.',
|
|
187
187
|
prompt: `Web page content from ${page.finalUrl || url.href}:\n---\n${content}\n---\n\n${input.prompt || 'Summarize this page, keeping all important details, code and numbers.'}\n\nRespond based only on the content above.`,
|
|
188
188
|
maxTokens: 16_000,
|