kovence-cli 1.0.3 → 1.3.0
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/CHANGELOG.md +38 -0
- package/README.md +66 -6
- package/nd.js +33 -2
- package/package.json +1 -1
- package/providers.js +527 -52
- package/src/agent/history.js +502 -9
- package/src/agent/project_context.js +219 -24
- package/src/agent/request_logger.js +148 -0
- package/src/agent/resilience.js +296 -46
- package/src/agent/streaming_write.js +167 -0
- package/src/agent/subagent.js +655 -0
- package/src/agent/turn.js +1226 -269
- package/src/cli/args.js +9 -1
- package/src/cli/sinks.js +455 -8
- package/src/commands/handlers.js +254 -8
- package/src/config/model_registry.js +39 -2
- package/src/config/paths.js +30 -9
- package/src/config/sessions.js +54 -2
- package/src/config/skills.js +425 -0
- package/src/permissions/engine.js +22 -6
- package/src/permissions/store.js +4 -1
- package/src/settings/schema.js +314 -12
- package/src/settings/store.js +75 -6
- package/src/tools/browser.js +722 -0
- package/src/tools/edit.js +471 -0
- package/src/tools/exec.js +349 -34
- package/src/tools/patch_git.js +12 -1
- package/src/tools/read_tracker.js +87 -0
- package/src/tools/tasks.js +68 -28
- package/store.js +2 -0
- package/tools.js +779 -172
- package/tui.js +274 -33
- package/ui.js +23 -2
package/src/settings/schema.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const crypto = require("node:crypto");
|
|
4
|
+
|
|
3
5
|
const AGENT_MODES = ["default", "accept-edits", "plan", "auto"];
|
|
4
6
|
const TOOL_PERMISSIONS = ["ask", "allow-reads", "allow-edits", "always-proceed"];
|
|
5
7
|
const NON_WORKSPACE_MODES = ["ask", "allow", "deny"];
|
|
@@ -8,14 +10,111 @@ const LANGUAGES = ["banglish", "bangla", "english"];
|
|
|
8
10
|
const RENDERING_MODES = ["fullscreen", "inline"];
|
|
9
11
|
const QUEUED_MESSAGE_MODES = ["queue", "interrupt"];
|
|
10
12
|
const COLOR_SCHEMES = ["amber", "dark", "light", "terminal"];
|
|
13
|
+
const COMMAND_TIMEOUT_BEHAVIORS = ["background", "kill"];
|
|
14
|
+
const TOOLSET_MODES = ["core", "full"];
|
|
15
|
+
const REASONING_LEVELS = ["off", "low", "medium", "high"];
|
|
11
16
|
|
|
12
|
-
const
|
|
17
|
+
const LEGACY_V1_SYSTEM_PROMPT = [
|
|
13
18
|
"You are Kovence CLI, an advanced multi-step CLI agent harness built by Kovence (https://kovence.com).",
|
|
14
19
|
"Use tools proactively to inspect files, search code, edit cleanly, run tests/commands, download files/installers with download_file and install them with run_command, search online with web_search/google_search, fetch pages with web_fetch, and track multi-step plans with todo_write.",
|
|
15
20
|
"When answering with online search results, synthesize the retrieved context cleanly and cite relevant sources.",
|
|
16
21
|
"MEMORY RULE: Save persistent user preferences ONLY when explicitly requested via save_global_memory. Save temporary current-task notes using save_session_memory.",
|
|
17
22
|
].join("\n");
|
|
18
23
|
|
|
24
|
+
function hashPromptText(text) {
|
|
25
|
+
return crypto
|
|
26
|
+
.createHash("sha256")
|
|
27
|
+
.update(
|
|
28
|
+
String(text || "")
|
|
29
|
+
.replace(/\r\n/g, "\n")
|
|
30
|
+
.trim()
|
|
31
|
+
)
|
|
32
|
+
.digest("hex");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const LEGACY_DEFAULT_PROMPT_HASHES = new Set([hashPromptText(LEGACY_V1_SYSTEM_PROMPT)]);
|
|
36
|
+
|
|
37
|
+
const MEMORY_RULE_LINE =
|
|
38
|
+
"MEMORY RULE: Save persistent user preferences ONLY when explicitly requested via save_global_memory. Save temporary current-task notes using save_session_memory.";
|
|
39
|
+
|
|
40
|
+
const DEFAULT_SYSTEM_PROMPT = [
|
|
41
|
+
"You are Kovence CLI, a coding agent working inside the user's workspace. You help with software engineering tasks: understanding code, fixing bugs, adding features, refactoring, running and fixing tests.",
|
|
42
|
+
"",
|
|
43
|
+
"# Workflow",
|
|
44
|
+
"1. Understand the request. Ask ONE short question only if something essential is missing and cannot be found in the code.",
|
|
45
|
+
"2. Explore with read-only tools first (list_dir, glob_files, search_files, read_file). Never guess file contents or paths.",
|
|
46
|
+
"3. For work with 3 or more steps, write a plan with todo_write and keep it current: one item in progress, mark items done as soon as they finish.",
|
|
47
|
+
"4. Implement with small, targeted edits.",
|
|
48
|
+
"5. Verify: run the project's tests, lint, typecheck or build with run_command when they exist. Fix failures before you report completion.",
|
|
49
|
+
"6. Report.",
|
|
50
|
+
"",
|
|
51
|
+
"# Tool rules",
|
|
52
|
+
"- Always read a file with read_file before you edit it.",
|
|
53
|
+
"- Prefer edit_file / multi_edit for existing files. Use write_file only for new files or complete rewrites; write large files in parts.",
|
|
54
|
+
"- Use search_files / glob_files / list_dir instead of shell grep, find, cat or ls.",
|
|
55
|
+
"- When several tool calls are independent, issue them in the SAME message so they run in parallel.",
|
|
56
|
+
"- Do not repeat an identical tool call. Do not re-read a file that has not changed and is still in context.",
|
|
57
|
+
"- If an edit fails, read the error: it shows the closest match. Re-read that region and retry with exact text.",
|
|
58
|
+
"- For long-running commands use background:true and poll with command_output.",
|
|
59
|
+
"- Use web_search / web_fetch only when the task needs information that is not in the workspace.",
|
|
60
|
+
"",
|
|
61
|
+
"# Editing rules",
|
|
62
|
+
"- Follow the existing conventions (style, naming, structure, libraries). Look at neighbouring files first.",
|
|
63
|
+
"- Make the smallest change that solves the task. Do not refactor unrelated code. Do not create files unless needed.",
|
|
64
|
+
"",
|
|
65
|
+
"# Verification and honesty",
|
|
66
|
+
"- Never claim that something works without evidence from a command you ran. If tests fail or you could not run them, say so plainly.",
|
|
67
|
+
"",
|
|
68
|
+
"# Output",
|
|
69
|
+
"- Be concise and direct. No filler, no restating the request.",
|
|
70
|
+
"- Refer to code as path:line.",
|
|
71
|
+
"- Final answer: what changed and what you verified (commands and results). Mention anything left undone.",
|
|
72
|
+
"",
|
|
73
|
+
"# Safety",
|
|
74
|
+
"- Respect the permission system. In plan mode do not modify anything.",
|
|
75
|
+
"- Do not run destructive commands (rm -rf, force pushes, dropping data) without a clear need.",
|
|
76
|
+
"",
|
|
77
|
+
MEMORY_RULE_LINE,
|
|
78
|
+
].join("\n");
|
|
79
|
+
|
|
80
|
+
const CURRENT_SETTINGS_VERSION = 2;
|
|
81
|
+
const CURRENT_PROMPT_VERSION = 2;
|
|
82
|
+
|
|
83
|
+
const DEFAULT_AGENTS_SETTINGS = {
|
|
84
|
+
maxParallel: 3,
|
|
85
|
+
parallelGeneral: false,
|
|
86
|
+
explore: { model: "", provider: "", maxSteps: 30 },
|
|
87
|
+
general: { model: "", provider: "", maxSteps: 30 },
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
function normalizeAgentRoleConfig(raw, fallbackMaxSteps = 30) {
|
|
91
|
+
const src = raw && typeof raw === "object" ? raw : {};
|
|
92
|
+
const maxRaw = Number.parseInt(String(src.maxSteps ?? ""), 10);
|
|
93
|
+
const maxSteps = Number.isSafeInteger(maxRaw) && maxRaw >= 1 && maxRaw <= 200 ? maxRaw : fallbackMaxSteps;
|
|
94
|
+
return {
|
|
95
|
+
model: typeof src.model === "string" ? src.model.trim() : "",
|
|
96
|
+
provider: typeof src.provider === "string" ? src.provider.trim() : "",
|
|
97
|
+
maxSteps,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeAgentsConfig(raw) {
|
|
102
|
+
const src = raw && typeof raw === "object" ? raw : {};
|
|
103
|
+
const maxPRaw = Number.parseInt(String(src.maxParallel ?? ""), 10);
|
|
104
|
+
const maxParallel =
|
|
105
|
+
Number.isSafeInteger(maxPRaw) && maxPRaw >= 1 && maxPRaw <= 10 ? maxPRaw : DEFAULT_AGENTS_SETTINGS.maxParallel;
|
|
106
|
+
const parallelGeneral =
|
|
107
|
+
typeof src.parallelGeneral === "boolean"
|
|
108
|
+
? src.parallelGeneral
|
|
109
|
+
: /^(true|on|1|yes)$/i.test(String(src.parallelGeneral ?? "").trim());
|
|
110
|
+
return {
|
|
111
|
+
maxParallel,
|
|
112
|
+
parallelGeneral,
|
|
113
|
+
explore: normalizeAgentRoleConfig(src.explore, DEFAULT_AGENTS_SETTINGS.explore.maxSteps),
|
|
114
|
+
general: normalizeAgentRoleConfig(src.general, DEFAULT_AGENTS_SETTINGS.general.maxSteps),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
19
118
|
const DEFAULT_SETTINGS = {
|
|
20
119
|
agentMode: "default",
|
|
21
120
|
toolPermission: "ask",
|
|
@@ -23,10 +122,15 @@ const DEFAULT_SETTINGS = {
|
|
|
23
122
|
model: "",
|
|
24
123
|
provider: "",
|
|
25
124
|
toolsEnabled: true,
|
|
26
|
-
autoSummarize:
|
|
27
|
-
maxToolSteps:
|
|
28
|
-
maxHistoryMessages:
|
|
29
|
-
contextWindow:
|
|
125
|
+
autoSummarize: false,
|
|
126
|
+
maxToolSteps: 100,
|
|
127
|
+
maxHistoryMessages: null,
|
|
128
|
+
contextWindow: null,
|
|
129
|
+
contextReserveTokens: null,
|
|
130
|
+
pruneThreshold: 0.75,
|
|
131
|
+
compactThreshold: 0.85,
|
|
132
|
+
pruneProtectTokens: 40000,
|
|
133
|
+
pruneMinSavings: 20000,
|
|
30
134
|
temperature: null,
|
|
31
135
|
maxTokens: null,
|
|
32
136
|
verbosity: "normal",
|
|
@@ -37,7 +141,18 @@ const DEFAULT_SETTINGS = {
|
|
|
37
141
|
showActiveTasks: true,
|
|
38
142
|
notifications: true,
|
|
39
143
|
colorScheme: "amber",
|
|
144
|
+
commandTimeoutMs: 120000,
|
|
145
|
+
commandTimeoutMaxMs: 600000,
|
|
146
|
+
commandTimeoutBehavior: "background",
|
|
147
|
+
toolset: "core",
|
|
148
|
+
checkAfterEdit: false,
|
|
149
|
+
checkCommand: "",
|
|
150
|
+
checkTimeoutMs: 30000,
|
|
151
|
+
checkMaxLines: 30,
|
|
152
|
+
reasoning: "off",
|
|
153
|
+
agents: normalizeAgentsConfig(DEFAULT_AGENTS_SETTINGS),
|
|
40
154
|
systemPrompt: DEFAULT_SYSTEM_PROMPT,
|
|
155
|
+
chatHistoryRetentionDays: 30,
|
|
41
156
|
};
|
|
42
157
|
|
|
43
158
|
/**
|
|
@@ -91,31 +206,72 @@ const SETTINGS_SCHEMA = [
|
|
|
91
206
|
key: "autoSummarize",
|
|
92
207
|
label: "Auto Summarize",
|
|
93
208
|
type: "boolean",
|
|
94
|
-
description:
|
|
209
|
+
description:
|
|
210
|
+
"'on': update rolling session summary after each turn; 'off': manual /compact & auto-compaction only.",
|
|
95
211
|
},
|
|
96
212
|
{
|
|
97
213
|
key: "maxToolSteps",
|
|
98
214
|
label: "Max Tool Steps",
|
|
99
215
|
type: "integer",
|
|
100
216
|
min: 1,
|
|
101
|
-
max:
|
|
102
|
-
description: "Maximum consecutive tool-calling loop iterations per user turn (1-
|
|
217
|
+
max: 1000,
|
|
218
|
+
description: "Maximum consecutive tool-calling loop iterations per user turn (1-1000).",
|
|
103
219
|
},
|
|
104
220
|
{
|
|
105
221
|
key: "maxHistoryMessages",
|
|
106
222
|
label: "Max History Messages",
|
|
107
|
-
type: "
|
|
223
|
+
type: "nullableInteger",
|
|
108
224
|
min: 2,
|
|
109
225
|
max: 500,
|
|
110
|
-
description: "
|
|
226
|
+
description: "Optional hard message-count cap (2-500), or 'null' for unlimited token-budget management.",
|
|
111
227
|
},
|
|
112
228
|
{
|
|
113
229
|
key: "contextWindow",
|
|
114
230
|
label: "Context Window",
|
|
115
|
-
type: "
|
|
231
|
+
type: "nullableInteger",
|
|
116
232
|
min: 1024,
|
|
117
233
|
max: 2000000,
|
|
118
|
-
description: "Model context window
|
|
234
|
+
description: "Model context window in tokens, or 'null' to auto-detect from model registry (32k if unknown).",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
key: "contextReserveTokens",
|
|
238
|
+
label: "Context Reserve Tokens",
|
|
239
|
+
type: "nullableInteger",
|
|
240
|
+
min: 1024,
|
|
241
|
+
max: 500000,
|
|
242
|
+
description: "Output headroom reserved from context window, or 'null' for max(20000, maxOutputTokens).",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
key: "pruneThreshold",
|
|
246
|
+
label: "Prune Threshold",
|
|
247
|
+
type: "nullableFloat",
|
|
248
|
+
min: 0.1,
|
|
249
|
+
max: 0.95,
|
|
250
|
+
description: "Fraction of usable context that triggers old tool-output pruning (default 0.75).",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "compactThreshold",
|
|
254
|
+
label: "Compact Threshold",
|
|
255
|
+
type: "nullableFloat",
|
|
256
|
+
min: 0.2,
|
|
257
|
+
max: 0.99,
|
|
258
|
+
description: "Fraction of usable context that triggers structured compaction after pruning (default 0.85).",
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
key: "pruneProtectTokens",
|
|
262
|
+
label: "Prune Protect Tokens",
|
|
263
|
+
type: "integer",
|
|
264
|
+
min: 1000,
|
|
265
|
+
max: 500000,
|
|
266
|
+
description: "Recent tool-output tokens protected from Zone B pruning (default 40000).",
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
key: "pruneMinSavings",
|
|
270
|
+
label: "Prune Min Savings",
|
|
271
|
+
type: "integer",
|
|
272
|
+
min: 500,
|
|
273
|
+
max: 500000,
|
|
274
|
+
description: "Minimum token savings required before Zone B pruning activates (default 20000).",
|
|
119
275
|
},
|
|
120
276
|
{
|
|
121
277
|
key: "temperature",
|
|
@@ -188,12 +344,72 @@ const SETTINGS_SCHEMA = [
|
|
|
188
344
|
options: COLOR_SCHEMES,
|
|
189
345
|
description: "UI palette: 'amber' (Kovence orange/amber), 'dark', 'light', or 'terminal' (minimal ANSI).",
|
|
190
346
|
},
|
|
347
|
+
{
|
|
348
|
+
key: "commandTimeoutMs",
|
|
349
|
+
label: "Command Timeout (ms)",
|
|
350
|
+
type: "integer",
|
|
351
|
+
min: 500,
|
|
352
|
+
max: 600000,
|
|
353
|
+
description: "Default run_command timeout in milliseconds (default 120000 = 120s).",
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
key: "commandTimeoutMaxMs",
|
|
357
|
+
label: "Max Command Timeout (ms)",
|
|
358
|
+
type: "integer",
|
|
359
|
+
min: 1000,
|
|
360
|
+
max: 3600000,
|
|
361
|
+
description: "Maximum allowed run_command timeout in milliseconds (default 600000 = 600s).",
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
key: "commandTimeoutBehavior",
|
|
365
|
+
label: "Command Timeout Behavior",
|
|
366
|
+
type: "enum",
|
|
367
|
+
options: COMMAND_TIMEOUT_BEHAVIORS,
|
|
368
|
+
description: "'background': promote timed-out command to a background task; 'kill': terminate process group.",
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
key: "toolset",
|
|
372
|
+
label: "Toolset",
|
|
373
|
+
type: "enum",
|
|
374
|
+
options: TOOLSET_MODES,
|
|
375
|
+
description:
|
|
376
|
+
"'core': focused coding tools (default); 'full': also includes download_file, memory, move_file, mkdir, delete_file, ask_user.",
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
key: "checkAfterEdit",
|
|
380
|
+
label: "Check After Edit",
|
|
381
|
+
type: "boolean",
|
|
382
|
+
description: "'on': run user-level checkCommand after successful file edits; 'off': skip post-edit checks.",
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
key: "checkCommand",
|
|
386
|
+
label: "Post-Edit Check Command",
|
|
387
|
+
type: "string",
|
|
388
|
+
description: "User-level shell command run after file edits (supports {file}; never read from repo files).",
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
key: "reasoning",
|
|
392
|
+
label: "Reasoning Effort",
|
|
393
|
+
type: "enum",
|
|
394
|
+
options: REASONING_LEVELS,
|
|
395
|
+
description:
|
|
396
|
+
"Extended reasoning/thinking budget ('off', 'low', 'medium', 'high') for Anthropic & reasoning models.",
|
|
397
|
+
},
|
|
191
398
|
{
|
|
192
399
|
key: "systemPrompt",
|
|
193
400
|
label: "Edit System Prompt",
|
|
194
401
|
type: "multilineString",
|
|
195
402
|
description: "Base system instructions injected at the start of every request (press Enter to edit).",
|
|
196
403
|
},
|
|
404
|
+
{
|
|
405
|
+
key: "chatHistoryRetentionDays",
|
|
406
|
+
label: "Chat History Retention (Days)",
|
|
407
|
+
type: "nullableInteger",
|
|
408
|
+
min: 0,
|
|
409
|
+
max: 3650,
|
|
410
|
+
description:
|
|
411
|
+
"Auto-delete sessions older than N days on startup (0 = never delete). Default: 30. Set to 'null' to disable.",
|
|
412
|
+
},
|
|
197
413
|
{
|
|
198
414
|
key: "managePermissions",
|
|
199
415
|
label: "Manage Permissions",
|
|
@@ -226,7 +442,19 @@ const KEY_ALIASES = {
|
|
|
226
442
|
show_tips: "showTips",
|
|
227
443
|
show_active_tasks: "showActiveTasks",
|
|
228
444
|
color_scheme: "colorScheme",
|
|
445
|
+
command_timeout_ms: "commandTimeoutMs",
|
|
446
|
+
command_timeout_max_ms: "commandTimeoutMaxMs",
|
|
447
|
+
command_timeout_behavior: "commandTimeoutBehavior",
|
|
448
|
+
tool_set: "toolset",
|
|
449
|
+
check_after_edit: "checkAfterEdit",
|
|
450
|
+
check_command: "checkCommand",
|
|
451
|
+
check_timeout_ms: "checkTimeoutMs",
|
|
452
|
+
check_max_lines: "checkMaxLines",
|
|
453
|
+
reasoning_effort: "reasoning",
|
|
229
454
|
system_prompt: "systemPrompt",
|
|
455
|
+
chat_history_retention: "chatHistoryRetentionDays",
|
|
456
|
+
chat_history_retention_days: "chatHistoryRetentionDays",
|
|
457
|
+
retention_days: "chatHistoryRetentionDays",
|
|
230
458
|
};
|
|
231
459
|
|
|
232
460
|
const PERSISTABLE_KEYS = new Set(Object.keys(DEFAULT_SETTINGS));
|
|
@@ -245,14 +473,70 @@ function canonicalSettingKey(rawKey) {
|
|
|
245
473
|
return null;
|
|
246
474
|
}
|
|
247
475
|
|
|
476
|
+
function parseAgentSubsetting(rawKey, rawValue) {
|
|
477
|
+
const clean = String(rawKey || "").trim();
|
|
478
|
+
const parts = clean.split(".");
|
|
479
|
+
if (parts[0] !== "agents" || parts.length < 2 || parts.length > 3) return null;
|
|
480
|
+
|
|
481
|
+
if (parts.length === 2 && parts[1] === "maxParallel") {
|
|
482
|
+
const str = String(rawValue ?? "").trim();
|
|
483
|
+
if (!/^\d+$/.test(str)) return { ok: false, error: "agents.maxParallel must be an integer (1-10)." };
|
|
484
|
+
const n = Number.parseInt(str, 10);
|
|
485
|
+
if (n < 1 || n > 10) return { ok: false, error: "agents.maxParallel must be between 1 and 10." };
|
|
486
|
+
return { ok: true, key: "agents", subPath: ["maxParallel"], value: n };
|
|
487
|
+
}
|
|
488
|
+
if (parts.length === 2 && parts[1] === "parallelGeneral") {
|
|
489
|
+
const str = String(rawValue ?? "").trim();
|
|
490
|
+
if (/^(true|on|1|yes)$/i.test(str)) {
|
|
491
|
+
return { ok: true, key: "agents", subPath: ["parallelGeneral"], value: true };
|
|
492
|
+
}
|
|
493
|
+
if (/^(false|off|0|no)$/i.test(str)) {
|
|
494
|
+
return { ok: true, key: "agents", subPath: ["parallelGeneral"], value: false };
|
|
495
|
+
}
|
|
496
|
+
return { ok: false, error: "agents.parallelGeneral expects on/off or true/false." };
|
|
497
|
+
}
|
|
498
|
+
if (parts.length === 3 && (parts[1] === "explore" || parts[1] === "general")) {
|
|
499
|
+
const role = parts[1];
|
|
500
|
+
const field = parts[2];
|
|
501
|
+
if (field === "model" || field === "provider") {
|
|
502
|
+
const val =
|
|
503
|
+
rawValue === null || /^(null|none|default|unset)$/i.test(String(rawValue ?? "").trim())
|
|
504
|
+
? ""
|
|
505
|
+
: String(rawValue ?? "").trim();
|
|
506
|
+
return { ok: true, key: "agents", subPath: [role, field], value: val };
|
|
507
|
+
}
|
|
508
|
+
if (field === "maxSteps") {
|
|
509
|
+
const str = String(rawValue ?? "").trim();
|
|
510
|
+
if (!/^\d+$/.test(str)) return { ok: false, error: `agents.${role}.maxSteps must be an integer (1-200).` };
|
|
511
|
+
const n = Number.parseInt(str, 10);
|
|
512
|
+
if (n < 1 || n > 200) return { ok: false, error: `agents.${role}.maxSteps must be between 1 and 200.` };
|
|
513
|
+
return { ok: true, key: "agents", subPath: [role, "maxSteps"], value: n };
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return { ok: false, error: `Unknown agent setting '${clean}'.` };
|
|
517
|
+
}
|
|
518
|
+
|
|
248
519
|
/**
|
|
249
520
|
* Parse and strictly validate a raw input value for a setting key.
|
|
250
521
|
*/
|
|
251
522
|
function parseSettingValue(rawKey, rawValue) {
|
|
523
|
+
if (
|
|
524
|
+
String(rawKey || "")
|
|
525
|
+
.trim()
|
|
526
|
+
.startsWith("agents.")
|
|
527
|
+
) {
|
|
528
|
+
return parseAgentSubsetting(rawKey, rawValue);
|
|
529
|
+
}
|
|
252
530
|
const key = canonicalSettingKey(rawKey);
|
|
253
531
|
if (!key) {
|
|
254
532
|
return { ok: false, error: `Unknown setting '${rawKey}'.` };
|
|
255
533
|
}
|
|
534
|
+
if (key === "agents") {
|
|
535
|
+
if (!rawValue || typeof rawValue !== "object" || Array.isArray(rawValue)) {
|
|
536
|
+
return { ok: false, error: "agents must be a configuration object." };
|
|
537
|
+
}
|
|
538
|
+
return { ok: true, key: "agents", value: normalizeAgentsConfig(rawValue) };
|
|
539
|
+
}
|
|
256
540
|
const meta = SCHEMA_BY_KEY.get(key);
|
|
257
541
|
if (!meta || meta.type === "action") {
|
|
258
542
|
return { ok: false, error: `'${key}' cannot be set directly.` };
|
|
@@ -318,6 +602,13 @@ function parseSettingValue(rawKey, rawValue) {
|
|
|
318
602
|
return { ok: true, key, value: n };
|
|
319
603
|
}
|
|
320
604
|
|
|
605
|
+
if (meta.type === "multilineString") {
|
|
606
|
+
if (rawValue === null || /^(null|default|reset)$/i.test(str)) {
|
|
607
|
+
return { ok: true, key, value: DEFAULT_SYSTEM_PROMPT };
|
|
608
|
+
}
|
|
609
|
+
return { ok: true, key, value: typeof rawValue === "string" ? rawValue : str };
|
|
610
|
+
}
|
|
611
|
+
|
|
321
612
|
return { ok: true, key, value: typeof rawValue === "string" ? rawValue : str };
|
|
322
613
|
}
|
|
323
614
|
|
|
@@ -330,8 +621,19 @@ module.exports = {
|
|
|
330
621
|
RENDERING_MODES,
|
|
331
622
|
QUEUED_MESSAGE_MODES,
|
|
332
623
|
COLOR_SCHEMES,
|
|
624
|
+
COMMAND_TIMEOUT_BEHAVIORS,
|
|
625
|
+
TOOLSET_MODES,
|
|
626
|
+
REASONING_LEVELS,
|
|
627
|
+
LEGACY_V1_SYSTEM_PROMPT,
|
|
628
|
+
LEGACY_DEFAULT_PROMPT_HASHES,
|
|
629
|
+
MEMORY_RULE_LINE,
|
|
333
630
|
DEFAULT_SYSTEM_PROMPT,
|
|
631
|
+
CURRENT_SETTINGS_VERSION,
|
|
632
|
+
CURRENT_PROMPT_VERSION,
|
|
633
|
+
DEFAULT_AGENTS_SETTINGS,
|
|
334
634
|
DEFAULT_SETTINGS,
|
|
635
|
+
normalizeAgentsConfig,
|
|
636
|
+
hashPromptText,
|
|
335
637
|
SETTINGS_SCHEMA,
|
|
336
638
|
SCHEMA_BY_KEY,
|
|
337
639
|
PERSISTABLE_KEYS,
|
package/src/settings/store.js
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { ensureStorageDirs, readJsonSafe, atomicWriteJson, resolvePaths } = require("../config/paths");
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
CURRENT_SETTINGS_VERSION,
|
|
6
|
+
CURRENT_PROMPT_VERSION,
|
|
7
|
+
DEFAULT_SETTINGS,
|
|
8
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
9
|
+
LEGACY_DEFAULT_PROMPT_HASHES,
|
|
10
|
+
PERSISTABLE_KEYS,
|
|
11
|
+
SCHEMA_BY_KEY,
|
|
12
|
+
normalizeAgentsConfig,
|
|
13
|
+
hashPromptText,
|
|
14
|
+
parseSettingValue,
|
|
15
|
+
} = require("./schema");
|
|
16
|
+
|
|
17
|
+
function isCustomSystemPrompt(settings) {
|
|
18
|
+
const cur = String(settings?.systemPrompt || "").trim();
|
|
19
|
+
if (!cur) return false;
|
|
20
|
+
return hashPromptText(cur) !== hashPromptText(DEFAULT_SYSTEM_PROMPT);
|
|
21
|
+
}
|
|
5
22
|
|
|
6
23
|
/**
|
|
7
24
|
* Normalize loaded settings object against schema defaults without introducing runtime-only keys.
|
|
8
25
|
*/
|
|
9
26
|
function sanitizePersistedObject(raw) {
|
|
10
|
-
const out = {
|
|
27
|
+
const out = {
|
|
28
|
+
...DEFAULT_SETTINGS,
|
|
29
|
+
agents: normalizeAgentsConfig(DEFAULT_SETTINGS.agents),
|
|
30
|
+
settingsVersion: CURRENT_SETTINGS_VERSION,
|
|
31
|
+
promptVersion: CURRENT_PROMPT_VERSION,
|
|
32
|
+
};
|
|
11
33
|
if (!raw || typeof raw !== "object") return out;
|
|
12
34
|
|
|
35
|
+
const storedVersion = Number(raw.settingsVersion) || 1;
|
|
36
|
+
|
|
13
37
|
// Legacy compatibility: read old autoApprove=true only when agentMode was not explicitly stored.
|
|
14
38
|
if (raw.autoApprove === true && raw.agentMode === undefined) {
|
|
15
39
|
out.agentMode = "auto";
|
|
@@ -17,6 +41,34 @@ function sanitizePersistedObject(raw) {
|
|
|
17
41
|
|
|
18
42
|
for (const key of PERSISTABLE_KEYS) {
|
|
19
43
|
if (raw[key] === undefined) continue;
|
|
44
|
+
// Migrate v1 shipped defaults that would otherwise lock users into message-count truncation.
|
|
45
|
+
if (storedVersion < 2) {
|
|
46
|
+
if (key === "maxHistoryMessages" && Number(raw[key]) === 24) {
|
|
47
|
+
out[key] = null;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (key === "contextWindow" && Number(raw[key]) === 128000) {
|
|
51
|
+
out[key] = null;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (key === "systemPrompt") {
|
|
56
|
+
if (raw[key] === null || String(raw[key]).trim() === "") {
|
|
57
|
+
out.systemPrompt = DEFAULT_SYSTEM_PROMPT;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const h = hashPromptText(raw[key]);
|
|
61
|
+
if (LEGACY_DEFAULT_PROMPT_HASHES.has(h)) {
|
|
62
|
+
out.systemPrompt = DEFAULT_SYSTEM_PROMPT;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
out.systemPrompt = String(raw[key]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (key === "agents") {
|
|
69
|
+
out.agents = normalizeAgentsConfig(raw[key]);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
20
72
|
const parsed = parseSettingValue(key, raw[key]);
|
|
21
73
|
if (parsed.ok) {
|
|
22
74
|
out[key] = parsed.value;
|
|
@@ -38,9 +90,15 @@ function loadPersistedSettings(paths = resolvePaths()) {
|
|
|
38
90
|
*/
|
|
39
91
|
function savePersistedSettings(settings, paths = resolvePaths()) {
|
|
40
92
|
ensureStorageDirs(paths);
|
|
41
|
-
const clean = sanitizePersistedObject(
|
|
93
|
+
const clean = sanitizePersistedObject({
|
|
94
|
+
...(settings && typeof settings === "object" ? settings : {}),
|
|
95
|
+
settingsVersion: settings?.settingsVersion ?? CURRENT_SETTINGS_VERSION,
|
|
96
|
+
});
|
|
42
97
|
// Explicitly strip legacy autoApprove from disk whenever settings are written.
|
|
43
|
-
const toWrite = {
|
|
98
|
+
const toWrite = {
|
|
99
|
+
settingsVersion: CURRENT_SETTINGS_VERSION,
|
|
100
|
+
promptVersion: CURRENT_PROMPT_VERSION,
|
|
101
|
+
};
|
|
44
102
|
for (const key of PERSISTABLE_KEYS) {
|
|
45
103
|
toWrite[key] = clean[key];
|
|
46
104
|
}
|
|
@@ -55,7 +113,17 @@ function updatePersistedSetting(key, rawValue, paths = resolvePaths()) {
|
|
|
55
113
|
const parsed = parseSettingValue(key, rawValue);
|
|
56
114
|
if (!parsed.ok) return parsed;
|
|
57
115
|
const currentPersisted = loadPersistedSettings(paths);
|
|
58
|
-
|
|
116
|
+
if (Array.isArray(parsed.subPath) && parsed.key === "agents") {
|
|
117
|
+
const nextAgents = normalizeAgentsConfig(currentPersisted.agents);
|
|
118
|
+
if (parsed.subPath.length === 1) {
|
|
119
|
+
nextAgents[parsed.subPath[0]] = parsed.value;
|
|
120
|
+
} else if (parsed.subPath.length === 2) {
|
|
121
|
+
nextAgents[parsed.subPath[0]][parsed.subPath[1]] = parsed.value;
|
|
122
|
+
}
|
|
123
|
+
currentPersisted.agents = nextAgents;
|
|
124
|
+
} else {
|
|
125
|
+
currentPersisted[parsed.key] = parsed.value;
|
|
126
|
+
}
|
|
59
127
|
const saved = savePersistedSettings(currentPersisted, paths);
|
|
60
128
|
return {
|
|
61
129
|
ok: true,
|
|
@@ -85,7 +153,7 @@ function stepSettingValue(key, currentValue, direction = 1) {
|
|
|
85
153
|
*/
|
|
86
154
|
function resolveEffectiveSettings(persisted, runtimeOverrides = {}) {
|
|
87
155
|
const base = sanitizePersistedObject(persisted);
|
|
88
|
-
const effective = { ...base };
|
|
156
|
+
const effective = { ...base, agents: normalizeAgentsConfig(base.agents) };
|
|
89
157
|
|
|
90
158
|
if (runtimeOverrides.cliAuto === true) {
|
|
91
159
|
effective.agentMode = "auto";
|
|
@@ -126,6 +194,7 @@ function resolveEffectiveModel({
|
|
|
126
194
|
}
|
|
127
195
|
|
|
128
196
|
module.exports = {
|
|
197
|
+
isCustomSystemPrompt,
|
|
129
198
|
sanitizePersistedObject,
|
|
130
199
|
loadPersistedSettings,
|
|
131
200
|
savePersistedSettings,
|