@yanzc/claude-pro 0.9.0 → 0.9.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/README.md +342 -320
- package/package.json +1 -2
- package/src/agent.js +240 -62
- package/src/agents.js +3 -2
- package/src/api.js +83 -41
- 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 +177 -71
- package/src/compaction.js +75 -0
- package/src/config.js +153 -153
- package/src/context.js +45 -18
- package/src/filestate.js +2 -1
- 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 +6 -62
- package/src/ratelimit.js +3 -5
- package/src/remote.js +26 -10
- package/src/restart.js +3 -0
- 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 +19 -18
- 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 +92 -19
- package/src/tools/index.js +6 -0
- package/src/tools/notebook.js +11 -4
- package/src/tools/processes.js +274 -0
- package/src/tools/search.js +104 -21
- 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 +246 -119
- package/src/ui/screen.js +139 -31
- package/src/updater.js +135 -165
- package/src/utils/clipboard.js +5 -3
- package/src/utils/paths.js +15 -17
- package/src/utils/shell.js +75 -21
- package/.env.example +0 -29
- package/src/verify.js +0 -57
package/src/config.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Ordinary settings live at the top level of settings.json; optional advanced keys live in its env block.
|
|
2
|
+
// Sources, lowest precedence first:
|
|
3
3
|
// 1. built-in defaults
|
|
4
|
-
// 2.
|
|
5
|
-
// 3.
|
|
6
|
-
// 4. <project>/.claude-pro/settings.json
|
|
7
|
-
// 5.
|
|
8
|
-
// 6.
|
|
9
|
-
// 7. command line flags (--model, --effort ...)
|
|
4
|
+
// 2. ~/.claude-pro/settings.json
|
|
5
|
+
// 3. <project>/.claude-pro/settings.json
|
|
6
|
+
// 4. <project>/.claude-pro/settings.local.json
|
|
7
|
+
// 5. process environment (advanced keys only)
|
|
8
|
+
// 6. command line flags (--model, --effort ...)
|
|
10
9
|
// The model and effort chosen with /model and /effort are remembered apart from these (see
|
|
11
|
-
// rememberChoice) and win over 1-
|
|
10
|
+
// rememberChoice) and win over 1-5. The gateway key comes from /login alone (gateway.json, see
|
|
11
|
+
// gatewayLogin): there is no variable for it, and no .env file is read.
|
|
12
12
|
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import os from 'node:os';
|
|
16
16
|
import { fileURLToPath } from 'node:url';
|
|
17
17
|
import { normalizeTtl } from './cache.js';
|
|
18
|
-
import { discoverVerifyCommand } from './verify.js';
|
|
19
18
|
|
|
20
19
|
export const INSTALL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
20
|
// A source checkout (a git clone, also when npm links to one), as opposed to a copy installed from npm: the agent
|
|
@@ -23,83 +22,103 @@ export const INSTALL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.u
|
|
|
23
22
|
export const SOURCE_CHECKOUT = fs.existsSync(path.join(INSTALL_DIR, '.git'));
|
|
24
23
|
export const CONFIG_DIR = process.env.CLAUDE_PRO_CONFIG_DIR || path.join(os.homedir(), '.claude-pro');
|
|
25
24
|
export const APP_NAME = 'claude-pro';
|
|
26
|
-
export const PROVIDERS = ['gateway'];
|
|
27
25
|
export const GATEWAY_DEFAULT_URL = 'https://gw.predix.icu';
|
|
28
26
|
export const VERSION = JSON.parse(fs.readFileSync(path.join(INSTALL_DIR, 'package.json'), 'utf8')).version;
|
|
29
27
|
|
|
30
|
-
//
|
|
28
|
+
// The ordinary settings /config shows. `legacy`: the old spelling accepted in settings.json.env and by config
|
|
29
|
+
// commands, but no longer read from the process environment. Writes use only the ordinary spelling.
|
|
30
|
+
export const BASIC_SETTINGS = {
|
|
31
|
+
model: { default: 'opus', legacy: 'CLAUDE_PRO_GATEWAY_MODEL', description: 'Default model; /model and --model override it' },
|
|
32
|
+
effort: { default: 'auto', legacy: 'CLAUDE_CODE_EFFORT_LEVEL', description: 'Reasoning effort; /effort and --effort override it' },
|
|
33
|
+
tui: { default: 'fullscreen', legacy: 'CLAUDE_PRO_TUI', description: 'fullscreen or default; /tui switches and remembers it' },
|
|
34
|
+
promptCacheTtl: { default: '1h', legacy: 'CLAUDE_CODE_PROMPT_CACHE_TTL', description: 'Conversation prompt cache: 5m or 1h' },
|
|
35
|
+
subagentPromptCacheTtl: { default: '5m', legacy: 'CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL', description: 'Sub-agent, compaction and side-query prompt cache: 5m or 1h' },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Advanced keys, shown only by /config advanced (or config list --advanced). Settings files may also carry
|
|
39
|
+
// unrelated env entries; those are left alone, but are not advertised as configuration of this program.
|
|
31
40
|
export const KNOWN_KEYS = {
|
|
32
|
-
CLAUDE_PRO_PROVIDER: 'Authentication backend: gateway only (codex-gateway account, /login)',
|
|
33
41
|
CLAUDE_PRO_GATEWAY_URL: `codex-gateway address (default https://gw.predix.icu)`,
|
|
34
|
-
CLAUDE_PRO_GATEWAY_API_KEY: 'Gateway API key (normally saved by /login in gateway.json)',
|
|
35
|
-
CLAUDE_PRO_GATEWAY_MODEL: 'Model with the gateway provider (default: opus; also sonnet, haiku, gpt-6.1-sol)',
|
|
36
42
|
CLAUDE_PRO_ONLINE: 'Set to 0 to keep interactive sessions off the gateway. Otherwise a session is online on the gateway\'s web page whenever this computer is logged in, and sessions on your other computers can send it tasks (@computer/name)',
|
|
37
43
|
CLAUDE_PRO_REMOTE_COMMANDS: 'Set to 0 to make this computer\'s sessions read-only on the gateway\'s web page: it can watch them, but not send them messages, answer their questions, stop them, switch model or effort, or change their directory (default: on; read when a session goes online)',
|
|
38
44
|
CLAUDE_PRO_MACHINE_NAME: 'This computer\'s name for sessions on your other computers (@公司 ...; default: the host name)',
|
|
39
|
-
CLAUDE_PRO_TUI: 'fullscreen (default: the input box fixed at the bottom, the conversation scrolled inside) or default (classic: it scrolls in the terminal); /tui switches',
|
|
40
|
-
CLAUDE_PRO_AUTO_RESTART: 'Restart by itself when a turn ends and claude-pro\'s own source files changed (default 1; 0 = only on /restart or the Restart tool)',
|
|
41
45
|
|
|
42
|
-
CLAUDE_CODE_EFFORT_LEVEL: 'Reasoning effort: none|minimal|low|medium|high|xhigh|max (sent as output_config.effort)',
|
|
43
|
-
CLAUDE_CODE_AUTO_COMPACT_WINDOW: 'Context size (tokens) used for auto-compaction calculations',
|
|
44
|
-
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: 'Percentage (1-100) of the window at which auto-compaction triggers',
|
|
45
|
-
DISABLE_AUTOCOMPACT: 'Set to 1 to disable auto-compaction',
|
|
46
46
|
CLAUDE_CODE_MAX_OUTPUT_TOKENS: 'max_tokens for each model response (default 48000; lowered automatically if the gateway allows less)',
|
|
47
47
|
MAX_THINKING_TOKENS: 'Thinking budget: 0 disables thinking, N enables with budget N',
|
|
48
|
-
CLAUDE_CODE_PROMPT_CACHE_TTL: 'Prompt cache TTL of the conversation itself: 5m or 1h (default: 1h with the gateway; 1h writes cost more, they pay off when you pause for more than 5 minutes). Also the promptCacheTtl setting',
|
|
49
|
-
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL: 'Prompt cache TTL of everything else (sub-agents, compaction, side queries): 5m (default) or 1h. Also the subagentPromptCacheTtl setting',
|
|
50
|
-
ENABLE_PROMPT_CACHING_1H: 'Set to 1 to request the 1-hour TTL for both (the two TTL variables above win over it)',
|
|
51
|
-
FORCE_PROMPT_CACHING_5M: 'Set to 1 to force the 5-minute TTL for both, over every other TTL setting',
|
|
52
48
|
CLAUDE_PRO_CACHE_KEEPALIVE_HOURS: 'Claude models with the 1-hour TTL: while you are away, refresh the conversation\'s prompt cache shortly before it runs out (a read costs 1/40 of a rewrite), for a pause of up to this many hours (default 8; 0 turns it off)',
|
|
53
49
|
DISABLE_PROMPT_CACHING: 'Set to 1 to send no cache_control markers at all (prompt caching off for every model)',
|
|
54
|
-
DISABLE_PROMPT_CACHING_HAIKU: 'Set to 1 to turn prompt caching off for the model the haiku alias resolves to',
|
|
55
|
-
DISABLE_PROMPT_CACHING_SONNET: 'Set to 1 to turn prompt caching off for the model the sonnet alias resolves to',
|
|
56
|
-
DISABLE_PROMPT_CACHING_OPUS: 'Set to 1 to turn prompt caching off for the model the opus alias resolves to',
|
|
57
|
-
DISABLE_PROMPT_CACHING_FABLE: 'Set to 1 to turn prompt caching off for Fable models',
|
|
58
50
|
API_TIMEOUT_MS: 'Request timeout in milliseconds',
|
|
59
51
|
CLAUDE_PRO_MAX_RETRIES: 'Retries for failed API requests (0 = no retries at all, which also turns off the rate limit wait)',
|
|
60
52
|
CLAUDE_PRO_RATE_LIMIT_MAX_WAIT_MS: 'Longest total time to wait for a rate limit (e.g. the 5-hour window) to reset before continuing by itself (default 21600000 = 6 hours; 0 = report the error instead of waiting)',
|
|
61
|
-
CLAUDE_CODE_OVERLOADED_RETRY_BASE_DELAY_MS: 'First wait before retrying a request refused as overloaded (529); doubled at each retry (default 1000)',
|
|
62
|
-
CLAUDE_CODE_OVERLOADED_RETRY_MAX_DELAY_MS: 'Longest wait between retries of an overloaded (529) request (default 32000)',
|
|
63
|
-
CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS: 'How long to keep retrying an overloaded (529) API once the usual retries are used up, before reporting the error (default: CLAUDE_PRO_RATE_LIMIT_MAX_WAIT_MS, 6 hours; 0 = give up after the retries)',
|
|
64
|
-
BASH_DEFAULT_TIMEOUT_MS: 'Default timeout for Bash commands (default 600000 = 10 minutes)',
|
|
65
|
-
BASH_MAX_TIMEOUT_MS: 'Maximum timeout the model may request for Bash commands (default 3600000 = 1 hour)',
|
|
66
|
-
BASH_MAX_OUTPUT_LENGTH: 'Max characters of Bash output returned to the model; the full text is saved to a file (default 60000)',
|
|
67
53
|
CLAUDE_CODE_GIT_BASH_PATH: 'Windows: path to bash.exe (Git Bash)',
|
|
68
54
|
CLAUDE_PRO_RIPGREP_PATH: 'Path to ripgrep (rg) for Grep and @-file suggestions; "off" forces the built-in JS scanner (default: rg from PATH, else the JS scanner)',
|
|
55
|
+
CLAUDE_PRO_BROWSER: 'The browser the Browser tool drives: auto (default: the first of Edge, Chrome, Brave, Chromium whose remote debugging is turned on, at edge://inspect/#remote-debugging and the like), edge, chrome, brave, chromium, own (claude-pro\'s own Chrome profile, nothing to allow), a DevTools address (ws://…, http://host:port, a port), or off (no Browser tool)',
|
|
56
|
+
CLAUDE_PRO_PYTHON: 'The Python interpreter the REPL tool runs (default: python on Windows, python3 elsewhere, from PATH)',
|
|
69
57
|
CLAUDE_PRO_VERIFY_COMMAND: 'Command run after the agent edits files (e.g. "npm test"); failures are sent back to fix',
|
|
70
58
|
CLAUDE_PRO_DISABLE_AUTO_MEMORY: 'Set to 1 to turn off the persistent per-project memory',
|
|
71
59
|
CLAUDE_PRO_DISABLE_TOPIC_TITLE: 'Set to 1 to stop asking the current model for the current topic after each message (the tab title then shows the first message of the session)',
|
|
72
60
|
CLAUDE_PRO_TRACE: 'Set to 0 to disable the privacy-preserving runtime JSONL trace (enabled by default)',
|
|
73
|
-
CLAUDE_PRO_TRACE_DIR: 'Directory for runtime trace files (default: the project session directory)',
|
|
74
|
-
CLAUDE_PRO_TRACE_MAX_SIZE: 'Maximum size of one runtime trace file in bytes before rotating it (default 20 MB)',
|
|
75
61
|
};
|
|
76
62
|
|
|
77
|
-
|
|
63
|
+
function basicValue(key, value) {
|
|
64
|
+
if (typeof value !== 'string') throw new Error(`${key} must be a string.`);
|
|
65
|
+
const text = value.trim();
|
|
66
|
+
if (key === 'model') {
|
|
67
|
+
if (!text) throw new Error('model must not be empty.');
|
|
68
|
+
return text;
|
|
69
|
+
}
|
|
70
|
+
const normalized = text.toLowerCase();
|
|
71
|
+
if (key === 'effort' && ['auto', 'default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'].includes(normalized)) return normalized;
|
|
72
|
+
if (key === 'tui' && ['fullscreen', 'default'].includes(normalized)) return normalized;
|
|
73
|
+
if ((key === 'promptCacheTtl' || key === 'subagentPromptCacheTtl') && normalizeTtl(normalized)) return normalized;
|
|
74
|
+
throw new Error(`Invalid ${key}: ${text}. ${BASIC_SETTINGS[key].description}.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The supported spelling, or an error instead of saving a setting that will do nothing.
|
|
78
|
+
export function configKey(key) {
|
|
79
|
+
if (Object.hasOwn(BASIC_SETTINGS, key) || Object.hasOwn(KNOWN_KEYS, key)) return key;
|
|
80
|
+
const alias = Object.entries(BASIC_SETTINGS).find(([, spec]) => spec.legacy === key);
|
|
81
|
+
if (alias) return alias[0];
|
|
82
|
+
throw new Error(`Unknown setting: ${key}. Use /config for ordinary settings or /config advanced for advanced settings.`);
|
|
83
|
+
}
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
// Shared by the terminal and slash commands, so both list and write the same settings.
|
|
86
|
+
export function configEntries(config, { advanced = false } = {}) {
|
|
87
|
+
const keys = [...Object.keys(BASIC_SETTINGS), ...(advanced ? Object.keys(KNOWN_KEYS) : [])];
|
|
88
|
+
return keys.map((key) => ({ key, value: config.setting(key), source: config.sources[key] || 'default', description: BASIC_SETTINGS[key]?.description || KNOWN_KEYS[key] }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function writeConfigSetting(file, key, value) {
|
|
92
|
+
key = configKey(key);
|
|
93
|
+
const basic = BASIC_SETTINGS[key];
|
|
94
|
+
const normalized = basic ? basicValue(key, value) : String(value);
|
|
95
|
+
updateSettingsFile(file, (json) => {
|
|
96
|
+
if (basic) {
|
|
97
|
+
json[key] = normalized;
|
|
98
|
+
if (json.env) { delete json.env[basic.legacy]; if (!Object.keys(json.env).length) delete json.env; }
|
|
99
|
+
} else json.env = { ...(json.env || {}), [key]: normalized };
|
|
100
|
+
});
|
|
101
|
+
return key;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function unsetConfigSetting(file, key) {
|
|
105
|
+
// Unknown env names may still be removed, including settings that this program no longer reads.
|
|
106
|
+
try { key = configKey(key); } catch { /* old or unrelated env name */ }
|
|
107
|
+
updateSettingsFile(file, (json) => {
|
|
108
|
+
const basic = Object.hasOwn(BASIC_SETTINGS, key) ? BASIC_SETTINGS[key] : null;
|
|
109
|
+
if (basic) delete json[key];
|
|
110
|
+
if (json.env) {
|
|
111
|
+
delete json.env[basic?.legacy || key];
|
|
112
|
+
if (!Object.keys(json.env).length) delete json.env;
|
|
94
113
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return env;
|
|
114
|
+
});
|
|
115
|
+
return key;
|
|
98
116
|
}
|
|
99
117
|
|
|
100
118
|
function readJson(file) {
|
|
101
119
|
try {
|
|
102
|
-
|
|
120
|
+
// a BOM in front (Windows PowerShell's Set-Content -Encoding UTF8 writes one) made the whole file unreadable
|
|
121
|
+
return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
103
122
|
} catch (e) {
|
|
104
123
|
if (e.code !== 'ENOENT') process.stderr.write(`warning: could not parse ${file}: ${e.message}\n`);
|
|
105
124
|
return null;
|
|
@@ -114,9 +133,8 @@ export function settingsFiles(cwd) {
|
|
|
114
133
|
};
|
|
115
134
|
}
|
|
116
135
|
|
|
117
|
-
const MODEL_KEYS = { gateway: 'CLAUDE_PRO_GATEWAY_MODEL' };
|
|
118
136
|
|
|
119
|
-
export function loadConfig({ cwd = process.cwd(), flags = {}
|
|
137
|
+
export function loadConfig({ cwd = process.cwd(), flags = {} } = {}) {
|
|
120
138
|
const env = {};
|
|
121
139
|
const sources = {};
|
|
122
140
|
const set = (obj, source) => {
|
|
@@ -127,24 +145,23 @@ export function loadConfig({ cwd = process.cwd(), flags = {}, dotEnvFile = path.
|
|
|
127
145
|
}
|
|
128
146
|
};
|
|
129
147
|
|
|
130
|
-
if (fs.existsSync(dotEnvFile)) set(parseDotEnv(fs.readFileSync(dotEnvFile, 'utf8')), dotEnvFile);
|
|
131
|
-
|
|
132
148
|
const files = settingsFiles(cwd);
|
|
133
149
|
// Settings files can still carry "permissions" from other tools; there are no permission rules here, so they are ignored.
|
|
134
150
|
const settings = { mcpServers: {}, hooks: {} };
|
|
135
151
|
for (const [scope, file] of Object.entries(files)) {
|
|
136
152
|
const json = readJson(file);
|
|
137
153
|
if (!json) continue;
|
|
138
|
-
// Claude Code's settings for the prompt cache TTL. They stay settings (the variables rank above them, whichever
|
|
139
|
-
// file they come from; see Config.cacheTtl); a later file's setting replaces an earlier one's.
|
|
140
|
-
if (json.promptCacheTtl !== undefined) settings.promptCacheTtl = json.promptCacheTtl;
|
|
141
|
-
if (json.subagentPromptCacheTtl !== undefined) settings.subagentPromptCacheTtl = json.subagentPromptCacheTtl;
|
|
142
154
|
set(json.env, file);
|
|
155
|
+
for (const [key, spec] of Object.entries(BASIC_SETTINGS)) {
|
|
156
|
+
// A top-level field wins over its legacy spelling in the same file; later files win over earlier ones.
|
|
157
|
+
const value = json[key] ?? json.env?.[spec.legacy];
|
|
158
|
+
if (value == null) continue;
|
|
159
|
+
try { settings[key] = basicValue(key, value); sources[key] = file; } catch { /* invalid: use the earlier value or default */ }
|
|
160
|
+
}
|
|
143
161
|
if (json.mcpServers) Object.assign(settings.mcpServers, json.mcpServers);
|
|
144
162
|
for (const [event, entries] of Object.entries(json.hooks || {})) {
|
|
145
163
|
if (Array.isArray(entries)) (settings.hooks[event] ||= []).push(...entries);
|
|
146
164
|
}
|
|
147
|
-
if (json.model) { env.CLAUDE_PRO_GATEWAY_MODEL = json.model; sources.CLAUDE_PRO_GATEWAY_MODEL = `${file} (model)`; }
|
|
148
165
|
settings[scope] = json;
|
|
149
166
|
}
|
|
150
167
|
// Project level .mcp.json, same format as Claude Code.
|
|
@@ -155,13 +172,9 @@ export function loadConfig({ cwd = process.cwd(), flags = {}, dotEnvFile = path.
|
|
|
155
172
|
for (const k of Object.keys(KNOWN_KEYS)) if (process.env[k] !== undefined && process.env[k] !== '') fromProcess[k] = process.env[k];
|
|
156
173
|
set(fromProcess, 'process environment');
|
|
157
174
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const key = MODEL_KEYS[(env.CLAUDE_PRO_PROVIDER || 'gateway').trim().toLowerCase()] || 'CLAUDE_PRO_GATEWAY_MODEL';
|
|
161
|
-
env[key] = flags.model;
|
|
162
|
-
sources[key] = '--model flag';
|
|
175
|
+
for (const key of ['model', 'effort']) {
|
|
176
|
+
if (flags[key]) { settings[key] = basicValue(key, flags[key]); sources[key] = `--${key} flag`; }
|
|
163
177
|
}
|
|
164
|
-
if (flags.effort) { env.CLAUDE_CODE_EFFORT_LEVEL = flags.effort; sources.CLAUDE_CODE_EFFORT_LEVEL = '--effort flag'; }
|
|
165
178
|
|
|
166
179
|
return new Config(env, sources, settings, cwd);
|
|
167
180
|
}
|
|
@@ -172,6 +185,16 @@ const int = (v, d) => {
|
|
|
172
185
|
};
|
|
173
186
|
const isOn = (v) => /^(1|true|yes)$/i.test(String(v ?? '').trim());
|
|
174
187
|
|
|
188
|
+
// The input window of each model a gateway serves (max_input_tokens in its GET /v1/models, which fetchGatewayModels
|
|
189
|
+
// passes on here), by gateway and model id: what resolveModel takes once the list is in.
|
|
190
|
+
const servedWindows = new Map();
|
|
191
|
+
export function noteServedModels(url, models) {
|
|
192
|
+
for (const m of models || []) {
|
|
193
|
+
const tokens = Number(m?.max_input_tokens);
|
|
194
|
+
if (typeof m?.id === 'string' && Number.isInteger(tokens) && tokens > 0) servedWindows.set(`${url}\n${m.id}`, tokens);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
175
198
|
export class Config {
|
|
176
199
|
constructor(env, sources, settings, cwd) {
|
|
177
200
|
this.env = env;
|
|
@@ -185,12 +208,6 @@ export class Config {
|
|
|
185
208
|
this.verifyOverride = null; // set by /verify or --verify during a session
|
|
186
209
|
}
|
|
187
210
|
|
|
188
|
-
get provider() {
|
|
189
|
-
const value = (this.env.CLAUDE_PRO_PROVIDER || 'gateway').trim().toLowerCase();
|
|
190
|
-
if (value !== 'gateway') throw new Error(`Only the gateway provider is supported. Set CLAUDE_PRO_PROVIDER=gateway (received ${value}).`);
|
|
191
|
-
return 'gateway';
|
|
192
|
-
}
|
|
193
|
-
get usesGateway() { return true; }
|
|
194
211
|
get gatewayUrl() { return (this.env.CLAUDE_PRO_GATEWAY_URL || GATEWAY_DEFAULT_URL).trim().replace(/\/+$/, ''); }
|
|
195
212
|
get endpointLabel() { return `${this.gatewayUrl} (codex-gateway)`; }
|
|
196
213
|
|
|
@@ -198,7 +215,8 @@ export class Config {
|
|
|
198
215
|
return { opus: 'claude-opus-5-5', sonnet: 'claude-sonnet-5-5', haiku: 'claude-haiku-5-5' }[alias] || null;
|
|
199
216
|
}
|
|
200
217
|
|
|
201
|
-
// Resolve a model spec (alias or name, maybe with [1m]) to {id, contextWindow, label}.
|
|
218
|
+
// Resolve a model spec (alias or name, maybe with [1m]) to {id, contextWindow, label}. The window is the model's
|
|
219
|
+
// max_input_tokens from the gateway's model list, once loaded, else what is known of it here; [1m] asks for 1M.
|
|
202
220
|
resolveModel(spec) {
|
|
203
221
|
let name = (spec || '').trim() || 'sonnet';
|
|
204
222
|
let oneM = false;
|
|
@@ -208,19 +226,27 @@ export class Config {
|
|
|
208
226
|
const inner = this.resolveModel(aliased);
|
|
209
227
|
return { ...inner, contextWindow: oneM ? 1_000_000 : inner.contextWindow, label: `${name}${oneM ? '[1m]' : ''} (${inner.label})` };
|
|
210
228
|
}
|
|
229
|
+
const served = servedWindows.get(`${this.gatewayUrl}\n${name}`);
|
|
230
|
+
// GPT models are served by the gateway's Codex backend, whose standard window is 272k. A request above 272k costs
|
|
231
|
+
// twice as much (see pricing.js), but the user wants the gateway's window here too (2026-10-27).
|
|
232
|
+
if (/^gpt-/i.test(name)) return { id: name, contextWindow: served || 272_000, label: name };
|
|
211
233
|
const nativeOneM = /^claude-(?:(?:sonnet|haiku)-5(?:-|$)|opus-(?:5(?:-|$)|4-[78](?:-|$)))/i.test(name);
|
|
212
|
-
|
|
213
|
-
if (/^gpt-/i.test(name)) return { id: name, contextWindow: 272_000, label: name };
|
|
214
|
-
return { id: name, contextWindow: oneM || nativeOneM ? 1_000_000 : 200_000, label: `${name}${oneM ? '[1m]' : ''}` };
|
|
234
|
+
return { id: name, contextWindow: oneM ? 1_000_000 : served || (nativeOneM ? 1_000_000 : 200_000), label: `${name}${oneM ? '[1m]' : ''}` };
|
|
215
235
|
}
|
|
216
236
|
|
|
217
237
|
// The selected model: the configured default unless /model has overridden it for this session.
|
|
218
|
-
get configuredModelSpec() { return this.
|
|
238
|
+
get configuredModelSpec() { return this.setting('model'); }
|
|
239
|
+
get configuredEffort() { return this.setting('effort'); }
|
|
240
|
+
|
|
241
|
+
setting(key) {
|
|
242
|
+
const spec = BASIC_SETTINGS[key];
|
|
243
|
+
return spec ? this.settings[key] ?? spec.default : this.env[key];
|
|
244
|
+
}
|
|
219
245
|
get modelSpec() { return this.modelOverride || this.configuredModelSpec; }
|
|
220
246
|
get model() { return this.resolveModel(this.modelSpec); }
|
|
221
247
|
|
|
222
248
|
get effort() {
|
|
223
|
-
const v = (this.effortBoost ?? this.effortOverride ?? this.
|
|
249
|
+
const v = (this.effortBoost ?? this.effortOverride ?? this.configuredEffort).trim().toLowerCase();
|
|
224
250
|
return v && v !== 'auto' && v !== 'default' ? v : null;
|
|
225
251
|
}
|
|
226
252
|
|
|
@@ -233,62 +259,38 @@ export class Config {
|
|
|
233
259
|
get thinkingBudget() {
|
|
234
260
|
return this.env.MAX_THINKING_TOKENS === undefined ? null : int(this.env.MAX_THINKING_TOKENS, null);
|
|
235
261
|
}
|
|
236
|
-
//
|
|
237
|
-
// is everything else (sub-agents, compaction, side queries). In order: FORCE_PROMPT_CACHING_5M; the bucket's
|
|
238
|
-
// own variable or setting; ENABLE_PROMPT_CACHING_1H; then the gateway default: the conversation's own
|
|
239
|
-
// requests use 1 hour and everything else uses 5 minutes.
|
|
262
|
+
// The conversation uses the main TTL (default 1h); sub-agents, compaction and side queries use the other (5m).
|
|
240
263
|
cacheTtl(bucket = 'main') {
|
|
241
|
-
|
|
242
|
-
// an invalid value is ignored, and the next rule applies (as in Claude Code)
|
|
243
|
-
const own = bucket === 'main'
|
|
244
|
-
? normalizeTtl(this.env.CLAUDE_CODE_PROMPT_CACHE_TTL) || normalizeTtl(this.settings?.promptCacheTtl)
|
|
245
|
-
: normalizeTtl(this.env.CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL) || normalizeTtl(this.settings?.subagentPromptCacheTtl);
|
|
264
|
+
const own = normalizeTtl(this.setting(bucket === 'main' ? 'promptCacheTtl' : 'subagentPromptCacheTtl'));
|
|
246
265
|
if (own) return own;
|
|
247
|
-
if (isOn(this.env.ENABLE_PROMPT_CACHING_1H)) return '1h';
|
|
248
266
|
// The gateway too: measured on its usage records (533 Opus requests), pauses of 5 to 60 minutes rewrote the whole
|
|
249
267
|
// conversation 9 times at 1.25x, $14.77; writing every turn at 2x instead costs $2.80 more.
|
|
250
|
-
return bucket === 'main'
|
|
251
|
-
}
|
|
252
|
-
// DISABLE_PROMPT_CACHING turns it off for everything; the per-model variables only for the model that
|
|
253
|
-
// their alias resolves to (a different version pinned as the model keeps its caching), wherever it runs.
|
|
254
|
-
promptCachingDisabled(modelId) {
|
|
255
|
-
if (isOn(this.env.DISABLE_PROMPT_CACHING)) return true;
|
|
256
|
-
for (const alias of ['haiku', 'sonnet', 'opus']) {
|
|
257
|
-
if (!isOn(this.env[`DISABLE_PROMPT_CACHING_${alias.toUpperCase()}`])) continue;
|
|
258
|
-
const target = this.aliasTarget(alias);
|
|
259
|
-
if (target && this.resolveModel(target).id === modelId) return true;
|
|
260
|
-
}
|
|
261
|
-
return isOn(this.env.DISABLE_PROMPT_CACHING_FABLE) && /fable/i.test(modelId || '');
|
|
268
|
+
return bucket === 'main' ? '1h' : '5m';
|
|
262
269
|
}
|
|
270
|
+
promptCachingDisabled() { return isOn(this.env.DISABLE_PROMPT_CACHING); }
|
|
263
271
|
get apiTimeout() { return int(this.env.API_TIMEOUT_MS, 600_000); }
|
|
264
272
|
get maxRetries() { return int(this.env.CLAUDE_PRO_MAX_RETRIES, 6); }
|
|
265
273
|
get rateLimitMaxWait() { return Math.max(0, int(this.env.CLAUDE_PRO_RATE_LIMIT_MAX_WAIT_MS, 6 * 3_600_000)); }
|
|
266
274
|
// A rate limit that does not say when it resets is tried again at most this far apart.
|
|
267
275
|
get rateLimitPoll() { return 300_000; }
|
|
268
276
|
// An overloaded API (529): the backoff, and how long to keep trying once the retries are used up (see planRetry).
|
|
269
|
-
get overloadedRetryBaseDelay() { return
|
|
270
|
-
get overloadedRetryMaxDelay() { return
|
|
271
|
-
get overloadedMaxWait() { return
|
|
272
|
-
|
|
273
|
-
//
|
|
274
|
-
//
|
|
277
|
+
get overloadedRetryBaseDelay() { return 1000; }
|
|
278
|
+
get overloadedRetryMaxDelay() { return 32_000; }
|
|
279
|
+
get overloadedMaxWait() { return this.rateLimitMaxWait; }
|
|
280
|
+
|
|
281
|
+
// At the model's input window (only sub-agent definitions may ask for a smaller one), less the room the compaction
|
|
282
|
+
// itself takes: its request is the conversation with the instruction at its end, and its reply (the summary and
|
|
283
|
+
// the thinking before it) counts against the window too. With no room left, the summary request of a
|
|
284
|
+
// conversation at the window was refused as too long and the conversation sent again without its cache (895k
|
|
285
|
+
// tokens of plain input on Opus, 2026-11-02; a request that fits reads them from the cache at a twentieth).
|
|
275
286
|
compactWindow(model = this.model, own = 0) {
|
|
276
|
-
const
|
|
277
|
-
return
|
|
278
|
-
}
|
|
279
|
-
get autoCompactEnabled() { return !/^(1|true|yes)$/i.test(this.env.DISABLE_AUTOCOMPACT || ''); }
|
|
280
|
-
autoCompactThreshold(model = this.model, own = 0) {
|
|
281
|
-
const window = this.compactWindow(model, own);
|
|
282
|
-
const pct = int(this.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, 0);
|
|
283
|
-
if (pct > 0 && pct <= 100) return Math.floor(window * pct / 100);
|
|
284
|
-
// Leave room for the summary itself and the next response (replies rarely come close to the
|
|
285
|
-
// max_tokens ceiling, so the reserve is capped; an overflow is handled by compacting on the error).
|
|
286
|
-
return Math.floor(window - Math.min(window * 0.2, Math.max(20_000, Math.min(this.maxOutputTokens, 64_000))));
|
|
287
|
+
const window = own > 0 ? Math.min(own, model.contextWindow) : model.contextWindow;
|
|
288
|
+
return window - Math.min(40_000, Math.round(window * 0.05));
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
get bashDefaultTimeout() { return
|
|
290
|
-
get bashMaxTimeout() { return
|
|
291
|
-
get bashMaxOutput() { return
|
|
291
|
+
get bashDefaultTimeout() { return 600_000; }
|
|
292
|
+
get bashMaxTimeout() { return 3_600_000; }
|
|
293
|
+
get bashMaxOutput() { return 60_000; }
|
|
292
294
|
// Tool results longer than this are saved to a file and only a preview is sent.
|
|
293
295
|
get maxToolResultChars() { return 100_000; }
|
|
294
296
|
// Clearing old tool results after a long pause (see Agent.clearAfterIdle): the gateway prompt cache has
|
|
@@ -302,18 +304,14 @@ export class Config {
|
|
|
302
304
|
// How deep sub-agents may nest: the main agent is depth 0; an agent below this depth gets the Task tool.
|
|
303
305
|
get maxSubagentDepth() { return 2; }
|
|
304
306
|
|
|
305
|
-
// Verification after edits: session
|
|
306
|
-
//
|
|
307
|
+
// Verification after edits, only when asked for: the session's own (/verify, --verify) wins over the setting.
|
|
308
|
+
// With neither there is none. (Until 2026-11-11 the project's test or check script was found and run by itself:
|
|
309
|
+
// a step after every edit that nobody had asked for, minutes long where the tests are; how to verify is the
|
|
310
|
+
// model's choice, in proportion to the change.)
|
|
307
311
|
get verifyCommand() {
|
|
308
|
-
const explicit = this.verifyOverride != null || Object.prototype.hasOwnProperty.call(this.env, 'CLAUDE_PRO_VERIFY_COMMAND');
|
|
309
|
-
if (!explicit) return this.autoVerifyCommand;
|
|
310
312
|
const v = this.verifyOverride ?? this.env.CLAUDE_PRO_VERIFY_COMMAND ?? '';
|
|
311
313
|
return v.trim() && v.trim() !== 'off' ? v.trim() : null;
|
|
312
314
|
}
|
|
313
|
-
get autoVerifyCommand() { return discoverVerifyCommand(this.cwd); }
|
|
314
|
-
get verifyCommandAuto() {
|
|
315
|
-
return this.verifyOverride == null && !Object.prototype.hasOwnProperty.call(this.env, 'CLAUDE_PRO_VERIFY_COMMAND') && Boolean(this.autoVerifyCommand);
|
|
316
|
-
}
|
|
317
315
|
// How many times a failing verify command is sent back before giving up.
|
|
318
316
|
get verifyMaxRounds() { return 3; }
|
|
319
317
|
get autoMemoryEnabled() { return !/^(1|true|yes)$/i.test(this.env.CLAUDE_PRO_DISABLE_AUTO_MEMORY || ''); }
|
|
@@ -321,18 +319,7 @@ export class Config {
|
|
|
321
319
|
const value = this.env.CLAUDE_PRO_TRACE;
|
|
322
320
|
return value === undefined || !/^(0|false|no|off)$/i.test(String(value).trim());
|
|
323
321
|
}
|
|
324
|
-
get traceDir() {
|
|
325
|
-
const value = String(this.env.CLAUDE_PRO_TRACE_DIR || '').trim();
|
|
326
|
-
return value ? path.resolve(this.cwd, value) : null;
|
|
327
|
-
}
|
|
328
|
-
get traceMaxBytes() { return Math.max(100_000, int(this.env.CLAUDE_PRO_TRACE_MAX_SIZE, 20 * 1024 * 1024)); }
|
|
329
322
|
|
|
330
|
-
display(key) {
|
|
331
|
-
const v = this.env[key];
|
|
332
|
-
if (v === undefined) return undefined;
|
|
333
|
-
if (SECRET_KEYS.has(key)) return v.length > 10 ? `${v.slice(0, 5)}…${v.slice(-4)}` : '****';
|
|
334
|
-
return v;
|
|
335
|
-
}
|
|
336
323
|
}
|
|
337
324
|
|
|
338
325
|
// Update the "env" block (or another top level key) of a settings file. A file that is there but is not
|
|
@@ -346,7 +333,17 @@ export function updateSettingsFile(file, mutate) {
|
|
|
346
333
|
}
|
|
347
334
|
mutate(json);
|
|
348
335
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
349
|
-
|
|
336
|
+
// written aside and renamed over it, so that a crash or a full disk does not leave half a settings file; when the
|
|
337
|
+
// rename is refused (Windows: the file held open by another program), written in place as before
|
|
338
|
+
const text2 = JSON.stringify(json, null, 2) + '\n';
|
|
339
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
340
|
+
try {
|
|
341
|
+
fs.writeFileSync(tmp, text2);
|
|
342
|
+
fs.renameSync(tmp, file);
|
|
343
|
+
} catch {
|
|
344
|
+
try { fs.rmSync(tmp, { force: true }); } catch { /* ignore */ }
|
|
345
|
+
fs.writeFileSync(file, text2);
|
|
346
|
+
}
|
|
350
347
|
}
|
|
351
348
|
|
|
352
349
|
// What /model and /effort chose, kept per provider in the "remembered" block of the user settings so that
|
|
@@ -355,14 +352,17 @@ export function updateSettingsFile(file, mutate) {
|
|
|
355
352
|
// the command line win over it, for that run. "/model default" and "/effort default" forget it.
|
|
356
353
|
const userSettingsFile = () => path.join(CONFIG_DIR, 'settings.json');
|
|
357
354
|
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
// Kept under the name of the provider they were made with, from when there were others: the gateway's.
|
|
356
|
+
const REMEMBERED_KEY = 'gateway';
|
|
357
|
+
|
|
358
|
+
function rememberedChoices() {
|
|
359
|
+
const entry = readJson(userSettingsFile())?.remembered?.[REMEMBERED_KEY];
|
|
360
360
|
return entry && typeof entry === 'object' ? entry : {};
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
// patch: {model?, effort?}; null or '' forgets that one. Returns whether the file changed.
|
|
364
|
-
export function rememberChoice(
|
|
365
|
-
const before = rememberedChoices(
|
|
364
|
+
export function rememberChoice(patch) {
|
|
365
|
+
const before = rememberedChoices();
|
|
366
366
|
const after = { ...before };
|
|
367
367
|
for (const [key, value] of Object.entries(patch)) {
|
|
368
368
|
if (value === undefined) continue;
|
|
@@ -372,8 +372,8 @@ export function rememberChoice(provider, patch) {
|
|
|
372
372
|
if (JSON.stringify(after) === JSON.stringify(before)) return false;
|
|
373
373
|
updateSettingsFile(userSettingsFile(), (json) => {
|
|
374
374
|
const all = json.remembered && typeof json.remembered === 'object' ? json.remembered : {};
|
|
375
|
-
if (Object.keys(after).length) all[
|
|
376
|
-
else delete all[
|
|
375
|
+
if (Object.keys(after).length) all[REMEMBERED_KEY] = after;
|
|
376
|
+
else delete all[REMEMBERED_KEY];
|
|
377
377
|
if (Object.keys(all).length) json.remembered = all;
|
|
378
378
|
else delete json.remembered;
|
|
379
379
|
});
|
|
@@ -381,7 +381,7 @@ export function rememberChoice(provider, patch) {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
export function applyRememberedChoices(config, flags = {}) {
|
|
384
|
-
const remembered = rememberedChoices(
|
|
384
|
+
const remembered = rememberedChoices();
|
|
385
385
|
if (!flags.model && typeof remembered.model === 'string' && remembered.model.trim()) config.modelOverride = remembered.model.trim();
|
|
386
386
|
if (!flags.effort && typeof remembered.effort === 'string' && remembered.effort.trim()) config.effortOverride = remembered.effort.trim().toLowerCase();
|
|
387
387
|
return remembered;
|
package/src/context.js
CHANGED
|
@@ -4,22 +4,48 @@
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import { run } from './utils/shell.js';
|
|
7
|
+
import { run, runText } from './utils/shell.js';
|
|
8
8
|
import { CONFIG_DIR } from './config.js';
|
|
9
9
|
|
|
10
|
+
// The git facts of the system prompt, or null outside a git repository. Four commands give them all (status -b
|
|
11
|
+
// names the branch too); seven ran one after another before, about 55 ms each on Windows, blocking the program for
|
|
12
|
+
// 400 ms at each start, /clear and compaction. gitInfoAsync runs them at once without blocking (75 ms).
|
|
13
|
+
// quotepath=false: file names with non-ASCII characters (Chinese ones) are shown as they are, not as "\344\275\240".
|
|
14
|
+
const GIT_STATUS = ['-c', 'core.quotepath=false', 'status', '--porcelain=v1', '-b'];
|
|
15
|
+
const GIT_MAIN = ['for-each-ref', '--format=%(refname:short)', 'refs/heads/main', 'refs/heads/master'];
|
|
16
|
+
const GIT_LOG = ['log', '--oneline', '-n', '5'];
|
|
17
|
+
const GIT_USER = ['config', 'user.name'];
|
|
18
|
+
const GIT_STATUS_MAX = 64 * 1024 * 1024;
|
|
19
|
+
|
|
10
20
|
export function gitInfo(cwd) {
|
|
11
|
-
const
|
|
12
|
-
if (inside !== 'true') return null;
|
|
13
|
-
const branch = run('git', ['branch', '--show-current'], { cwd })
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const status = run('git', GIT_STATUS, { cwd, maxBuffer: GIT_STATUS_MAX });
|
|
22
|
+
if (status === null && run('git', ['rev-parse', '--is-inside-work-tree'], { cwd }) !== 'true') return null;
|
|
23
|
+
const branch = status === null ? run('git', ['branch', '--show-current'], { cwd }) : null;
|
|
24
|
+
return gitFacts(status, run('git', GIT_MAIN, { cwd }), run('git', GIT_LOG, { cwd }), run('git', GIT_USER, { cwd }), branch);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function gitInfoAsync(cwd) {
|
|
28
|
+
const [status, main, log, user] = await Promise.all([GIT_STATUS, GIT_MAIN, GIT_LOG, GIT_USER].map((args) => runText('git', args, { cwd, maxChars: GIT_STATUS_MAX })));
|
|
29
|
+
if (status === null && (await runText('git', ['rev-parse', '--is-inside-work-tree'], { cwd })) !== 'true') return null;
|
|
30
|
+
const branch = status === null ? await runText('git', ['branch', '--show-current'], { cwd }) : null;
|
|
31
|
+
return gitFacts(status, main, log, user, branch);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// `statusOut`: git status -b's output, null when it failed or took too long (a huge tree), which is not a clean
|
|
35
|
+
// tree (status null). `branch`: the branch when status gave none.
|
|
36
|
+
function gitFacts(statusOut, mainOut, log, user, branch) {
|
|
37
|
+
let status = null;
|
|
38
|
+
if (statusOut !== null) {
|
|
39
|
+
const lines = statusOut.split('\n');
|
|
40
|
+
const head = lines[0]?.startsWith('## ') ? lines.shift().slice(3) : '';
|
|
41
|
+
// "main...origin/main [ahead 1]", "main", "No commits yet on main", "HEAD (no branch)"
|
|
42
|
+
branch = /^HEAD \(no branch\)/.test(head) ? '' : /^(?:No commits yet on |Initial commit on )?(.+?)(?:\.\.\.| \[|$)/.exec(head)?.[1] ?? '';
|
|
43
|
+
const changes = lines.filter((l) => l.trim());
|
|
44
|
+
status = changes.length > 40 ? changes.slice(0, 40).join('\n') + `\n... (${changes.length - 40} more lines, run "git status" for the rest)` : changes.join('\n');
|
|
45
|
+
}
|
|
46
|
+
const refs = (mainOut || '').split('\n').map((s) => s.trim());
|
|
47
|
+
const main = refs.includes('main') ? 'main' : refs.includes('master') ? 'master' : null;
|
|
48
|
+
return { branch: branch || '(detached)', main, status, log: log || '', user };
|
|
23
49
|
}
|
|
24
50
|
|
|
25
51
|
// Memory files, lowest priority first: user memory, then project files from the
|
|
@@ -70,10 +96,6 @@ export function listAutoMemories(dir) {
|
|
|
70
96
|
try { return fs.readdirSync(dir).filter((f) => f.endsWith('.md') && f !== 'MEMORY.md'); } catch { return []; }
|
|
71
97
|
}
|
|
72
98
|
|
|
73
|
-
export function projectMemoryFile(cwd) {
|
|
74
|
-
return path.join(cwd, 'CLAUDE.md');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
99
|
// The date where the user is (YYYY-MM-DD). toISOString() would give the UTC date, which for someone in
|
|
78
100
|
// UTC+8 is yesterday's between midnight and 8 o'clock.
|
|
79
101
|
export function localDate(now = new Date()) {
|
|
@@ -88,6 +110,10 @@ export function takeEnvSnapshot(cwd) {
|
|
|
88
110
|
return { date: localDate(), git: gitInfo(cwd) };
|
|
89
111
|
}
|
|
90
112
|
|
|
113
|
+
export async function takeEnvSnapshotAsync(cwd) {
|
|
114
|
+
return { date: localDate(), git: await gitInfoAsync(cwd) };
|
|
115
|
+
}
|
|
116
|
+
|
|
91
117
|
export function environmentBlock(cwd, { model, shellName, snapshot = null }) {
|
|
92
118
|
const { date, git } = snapshot || takeEnvSnapshot(cwd);
|
|
93
119
|
const lines = [
|
|
@@ -108,7 +134,8 @@ export function environmentBlock(cwd, { model, shellName, snapshot = null }) {
|
|
|
108
134
|
// gateway refuses requests carrying that exact line (code 11128, shown as a 529 "overloaded") for its models.
|
|
109
135
|
if (git.main) lines.push(`Main branch: ${git.main}`);
|
|
110
136
|
if (git.user) lines.push(`Git user: ${git.user}`);
|
|
111
|
-
|
|
137
|
+
const status = git.status === null ? '(unknown: git status failed or timed out; run it to see)' : git.status || '(clean)';
|
|
138
|
+
lines.push('', `Status:\n${status}`, '', `Recent commits:\n${git.log || '(none)'}`);
|
|
112
139
|
}
|
|
113
140
|
return lines.join('\n');
|
|
114
141
|
}
|
package/src/filestate.js
CHANGED
|
@@ -21,7 +21,8 @@ const resultText = (content) => (typeof content === 'string' ? content : '');
|
|
|
21
21
|
function readWasPartial(input, text) {
|
|
22
22
|
return Number(input?.offset) > 1
|
|
23
23
|
|| /\(File has \d+ lines total; showing lines /.test(text)
|
|
24
|
-
|| /\[output cut at
|
|
24
|
+
|| /\[output cut at /.test(text) // "… characters" or "about 25k tokens"
|
|
25
|
+
|| /… \[line truncated\]/.test(text);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
// messages: the restored conversation. times: when each message was stored (ms since epoch,
|