@denizokcu/haze 0.9.0 → 0.10.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 +57 -17
- package/README.md +119 -64
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +44 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +91 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/sessionLifecycle.d.ts +58 -0
- package/dist/cli/chat/sessionLifecycle.js +155 -0
- package/dist/cli/chat/sessionRecorder.js +7 -9
- package/dist/cli/chat/startupInfo.d.ts +1 -0
- package/dist/cli/chat/startupInfo.js +11 -0
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +645 -0
- package/dist/cli/commands/chat.d.ts +1 -0
- package/dist/cli/commands/chat.js +181 -700
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +3 -2
- package/dist/cli/commands/commands.js +12 -13
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +33 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/providerWizard.d.ts +1 -0
- package/dist/cli/commands/providerWizard.js +13 -0
- package/dist/cli/commands/runCommand.d.ts +1 -0
- package/dist/cli/commands/runCommand.js +25 -5
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +4 -2
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +13 -1
- package/dist/cli/commands/streaming.js +42 -19
- package/dist/cli/commands/wizardActions.d.ts +6 -0
- package/dist/cli/commands/wizardActions.js +6 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +60 -12
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +17 -3
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +20 -0
- package/dist/config/modelDiscovery.js +51 -0
- package/dist/config/providerPresets.d.ts +16 -4
- package/dist/config/providerPresets.js +263 -34
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +7 -0
- package/dist/config/settings.d.ts +22 -0
- package/dist/config/settings.js +29 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +26 -0
- package/dist/core/agent/budgets.js +34 -0
- package/dist/core/agent/compaction.js +17 -3
- package/dist/core/agent/contextBudget.d.ts +8 -0
- package/dist/core/agent/contextBudget.js +29 -0
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/toolOutputStore.d.ts +5 -0
- package/dist/core/agent/toolOutputStore.js +18 -1
- package/dist/core/agent/workState.d.ts +1 -1
- package/dist/core/agent/workState.js +0 -4
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +5 -0
- package/dist/core/limits/byteBudgets.js +5 -0
- package/dist/core/limits/textBudgets.d.ts +23 -0
- package/dist/core/limits/textBudgets.js +23 -0
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +194 -0
- package/dist/core/process/runBoundedProcess.d.ts +3 -0
- package/dist/core/process/runBoundedProcess.js +65 -29
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +37 -0
- package/dist/core/session/sessionStore.js +95 -9
- package/dist/core/subagent/contracts.d.ts +116 -0
- package/dist/core/subagent/contracts.js +54 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +74 -0
- package/dist/core/subagent/subagentCoordinator.js +134 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +228 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +20 -29
- package/dist/llm/client.js +29 -28
- package/dist/llm/hazeTools.d.ts +2013 -78
- package/dist/llm/hazeTools.js +16 -7
- package/dist/llm/lsp.d.ts +2 -0
- package/dist/llm/lsp.js +18 -3
- package/dist/llm/requestContext.d.ts +22 -1
- package/dist/llm/requestContext.js +45 -5
- package/dist/llm/systemPrompt.d.ts +4 -1
- package/dist/llm/systemPrompt.js +14 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/bashTool.d.ts +874 -32
- package/dist/llm/tools/bashTool.js +25 -4
- package/dist/llm/tools/fetchTool.d.ts +26 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +2 -1
- package/dist/llm/tools/fileToolShared.js +5 -5
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +8 -0
- package/dist/llm/tools/toolContext.js +22 -11
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.js +24 -11
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -1
- package/dist/ui/components/TextInput.d.ts +5 -2
- package/dist/ui/components/TextInput.js +76 -8
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +0 -1
- package/dist/utils/fs.js +0 -4
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +9 -0
- package/package.json +1 -1
package/dist/config/settings.js
CHANGED
|
@@ -3,12 +3,17 @@ import path from 'node:path';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { HAZE_DIR } from './paths.js';
|
|
5
5
|
import { tightenPrivateFile, writePrivateJsonAtomic } from './privateStorage.js';
|
|
6
|
+
import { customProfileSchema } from '../core/subagent/executionProfiles.js';
|
|
6
7
|
export const SETTINGS_FILE = path.join(HAZE_DIR, 'settings.json');
|
|
8
|
+
const providerCapabilitiesSchema = z.object({
|
|
9
|
+
images: z.boolean().optional(),
|
|
10
|
+
}).passthrough();
|
|
7
11
|
const providerSchema = z.object({
|
|
8
12
|
name: z.string(),
|
|
9
13
|
url: z.string(),
|
|
10
14
|
key: z.string().optional(),
|
|
11
15
|
models: z.array(z.string()),
|
|
16
|
+
capabilities: providerCapabilitiesSchema.optional(),
|
|
12
17
|
}).passthrough();
|
|
13
18
|
const lspServerSchema = z.object({
|
|
14
19
|
name: z.string(),
|
|
@@ -28,7 +33,12 @@ const mcpServerSchema = z.object({
|
|
|
28
33
|
headers: z.array(mcpHeaderSchema).optional(),
|
|
29
34
|
enabled: z.boolean().optional(),
|
|
30
35
|
}).passthrough();
|
|
31
|
-
const skillSettingSchema = z.object({ name: z.string(), enabled: z.boolean().optional() }).passthrough();
|
|
36
|
+
const skillSettingSchema = z.object({ name: z.string(), scope: z.enum(['global', 'project']).optional(), enabled: z.boolean().optional() }).passthrough();
|
|
37
|
+
const subagentSettingsSchema = z.object({
|
|
38
|
+
workerModel: z.string().trim().min(1).optional(),
|
|
39
|
+
defaultProfile: z.string().trim().min(1).optional(),
|
|
40
|
+
profiles: z.record(z.string().min(1), customProfileSchema).optional(),
|
|
41
|
+
}).passthrough();
|
|
32
42
|
const settingsSchema = z.object({
|
|
33
43
|
provider: z.string().optional(),
|
|
34
44
|
model: z.string().optional(),
|
|
@@ -36,6 +46,8 @@ const settingsSchema = z.object({
|
|
|
36
46
|
lspServers: z.array(lspServerSchema).optional(),
|
|
37
47
|
mcpServers: z.array(mcpServerSchema).optional(),
|
|
38
48
|
skills: z.array(skillSettingSchema).optional(),
|
|
49
|
+
subagents: subagentSettingsSchema.optional(),
|
|
50
|
+
tips: z.object({ enabled: z.boolean().optional() }).optional(),
|
|
39
51
|
apiKey: z.string().optional(),
|
|
40
52
|
baseURL: z.string().optional(),
|
|
41
53
|
}).passthrough();
|
|
@@ -66,3 +78,19 @@ export async function updateSettings(patch) {
|
|
|
66
78
|
await writeSettings(next);
|
|
67
79
|
return next;
|
|
68
80
|
}
|
|
81
|
+
/** Patch subagent settings without dropping unknown nested/profile fields. */
|
|
82
|
+
export async function updateSubagentSettings(patch) {
|
|
83
|
+
const current = await readSettings();
|
|
84
|
+
const currentSubagents = current.subagents ?? {};
|
|
85
|
+
const profiles = patch.profiles
|
|
86
|
+
? Object.fromEntries(Object.entries(patch.profiles).map(([name, value]) => [name, { ...(currentSubagents.profiles?.[name] ?? {}), ...value }]))
|
|
87
|
+
: undefined;
|
|
88
|
+
const subagents = {
|
|
89
|
+
...currentSubagents,
|
|
90
|
+
...patch,
|
|
91
|
+
...(profiles ? { profiles: { ...(currentSubagents.profiles ?? {}), ...profiles } } : {}),
|
|
92
|
+
};
|
|
93
|
+
const next = { ...current, subagents };
|
|
94
|
+
await writeSettings(next);
|
|
95
|
+
return next;
|
|
96
|
+
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import type { HazeSettings, HazeSkillSetting } from './settings.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* deviate from the default (enabled) appear here, so it never desyncs from disk.
|
|
5
|
-
*/
|
|
2
|
+
import type { SkillSource } from '../skills/types.js';
|
|
3
|
+
/** Normalized override-only skill settings. Legacy entries apply to global skills. */
|
|
6
4
|
export declare function configuredSkillSettings(settings: HazeSettings): HazeSkillSetting[];
|
|
7
|
-
/** A skill is enabled unless an explicit override disables it. */
|
|
8
|
-
export declare function isSkillEnabled(settings: HazeSettings, name: string): boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* `enabled: false`. Returns the next `skills` array for updateSettings.
|
|
12
|
-
*/
|
|
13
|
-
export declare function setSkillEnabled(settings: HazeSettings, name: string, enabled: boolean): HazeSkillSetting[];
|
|
14
|
-
/** Drop a skill's override entry. Called when a skill directory is removed. */
|
|
15
|
-
export declare function removeSkillSetting(settings: HazeSettings, name: string): HazeSkillSetting[];
|
|
5
|
+
/** A skill is enabled unless an explicit scope-aware override disables it. */
|
|
6
|
+
export declare function isSkillEnabled(settings: HazeSettings, name: string, scope?: SkillSource): boolean;
|
|
7
|
+
export declare function setSkillEnabled(settings: HazeSettings, name: string, enabled: boolean, scope?: SkillSource): HazeSkillSetting[];
|
|
8
|
+
export declare function removeSkillSetting(settings: HazeSettings, name: string, scope?: SkillSource): HazeSkillSetting[];
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Normalized skill metadata overrides. The list is override-only: only skills that
|
|
4
|
-
* deviate from the default (enabled) appear here, so it never desyncs from disk.
|
|
5
|
-
*/
|
|
1
|
+
/** Normalized override-only skill settings. Legacy entries apply to global skills. */
|
|
6
2
|
export function configuredSkillSettings(settings) {
|
|
7
3
|
const result = [];
|
|
8
4
|
for (const entry of settings.skills ?? []) {
|
|
9
5
|
const name = entry.name?.trim();
|
|
10
6
|
if (!name)
|
|
11
7
|
continue;
|
|
12
|
-
result.push({
|
|
8
|
+
result.push({
|
|
9
|
+
name,
|
|
10
|
+
...(entry.scope ? { scope: entry.scope } : {}),
|
|
11
|
+
...(entry.enabled === false ? { enabled: false } : {}),
|
|
12
|
+
});
|
|
13
13
|
}
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function settingScope(entry) {
|
|
17
|
+
return entry.scope ?? 'global';
|
|
18
|
+
}
|
|
19
|
+
function matches(entry, name, scope) {
|
|
20
|
+
return entry.name === name && settingScope(entry) === scope;
|
|
21
|
+
}
|
|
22
|
+
/** A skill is enabled unless an explicit scope-aware override disables it. */
|
|
23
|
+
export function isSkillEnabled(settings, name, scope = 'global') {
|
|
24
|
+
const entry = configuredSkillSettings(settings).find(candidate => matches(candidate, name, scope));
|
|
19
25
|
return entry ? entry.enabled !== false : true;
|
|
20
26
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
export function setSkillEnabled(settings, name, enabled) {
|
|
26
|
-
const others = removeByName(configuredSkillSettings(settings), name);
|
|
27
|
-
return enabled ? others : [...others, { name, enabled: false }];
|
|
27
|
+
export function setSkillEnabled(settings, name, enabled, scope = 'global') {
|
|
28
|
+
const others = configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
|
|
29
|
+
return enabled ? others : [...others, { name, ...(scope === 'project' ? { scope } : {}), enabled: false }];
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return removeByName(configuredSkillSettings(settings), name);
|
|
31
|
+
export function removeSkillSetting(settings, name, scope = 'global') {
|
|
32
|
+
return configuredSkillSettings(settings).filter(entry => !matches(entry, name, scope));
|
|
32
33
|
}
|
|
@@ -4,3 +4,29 @@ export declare const MAIN_STEP_LIMIT = 64;
|
|
|
4
4
|
export declare const MAIN_TOOL_CALL_LIMIT = 120;
|
|
5
5
|
export declare const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
6
6
|
export declare const ACTIVE_CONTEXT_TOKEN_BUDGET = 40000;
|
|
7
|
+
export declare const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
|
|
8
|
+
export declare const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
|
|
9
|
+
export declare const SUBAGENT_OBJECTIVE_CHARS = 4000;
|
|
10
|
+
export declare const SUBAGENT_DELIVERABLE_CHARS = 600;
|
|
11
|
+
export declare const SUBAGENT_SCOPE_ITEMS = 32;
|
|
12
|
+
export declare const SUBAGENT_SCOPE_CHARS = 240;
|
|
13
|
+
export declare const SUBAGENT_ACCEPTANCE_ITEMS = 8;
|
|
14
|
+
export declare const SUBAGENT_ACCEPTANCE_CHARS = 300;
|
|
15
|
+
export declare const SUBAGENT_MIN_STEPS = 4;
|
|
16
|
+
export declare const SUBAGENT_DEFAULT_STEPS = 25;
|
|
17
|
+
export declare const SUBAGENT_MAX_STEPS = 50;
|
|
18
|
+
export declare const SUBAGENT_DEFAULT_TOOL_CALLS = 20;
|
|
19
|
+
export declare const SUBAGENT_MAX_TOOL_CALLS = 50;
|
|
20
|
+
export declare const SUBAGENT_TOOL_ONLY_LIMIT = 12;
|
|
21
|
+
export declare const SUBAGENT_SYNTHESIS_RESERVE = 2;
|
|
22
|
+
export declare const SUBAGENT_DEFAULT_OUTPUT_TOKENS = 4096;
|
|
23
|
+
export declare const SUBAGENT_MAX_OUTPUT_TOKENS = 16384;
|
|
24
|
+
export declare const SUBAGENT_DEFAULT_SUMMARY_CHARS = 4000;
|
|
25
|
+
export declare const SUBAGENT_MAX_SUMMARY_CHARS = 12000;
|
|
26
|
+
export declare const SUBAGENT_DEFAULT_INPUT_TOKENS = 40000;
|
|
27
|
+
export declare const SUBAGENT_MAX_INPUT_TOKENS = 200000;
|
|
28
|
+
export declare const SUBAGENT_DEFAULT_DEADLINE_MS = 300000;
|
|
29
|
+
export declare const SUBAGENT_MIN_DEADLINE_MS = 1000;
|
|
30
|
+
export declare const SUBAGENT_MAX_DEADLINE_MS: number;
|
|
31
|
+
export declare const SUBAGENT_MAX_CONCURRENCY = 10;
|
|
32
|
+
export declare const SUBAGENT_MAX_RETRIES = 5;
|
|
@@ -4,3 +4,37 @@ export const MAIN_STEP_LIMIT = 64;
|
|
|
4
4
|
export const MAIN_TOOL_CALL_LIMIT = 120;
|
|
5
5
|
export const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
6
6
|
export const ACTIVE_CONTEXT_TOKEN_BUDGET = 40_000;
|
|
7
|
+
export const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
|
|
8
|
+
export const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
|
|
9
|
+
// Disposable worker/task-capsule limits. Keep these centralized so model-facing
|
|
10
|
+
// schemas and runtime enforcement cannot drift.
|
|
11
|
+
// Keep validation tolerant of verbose tool callers while prompt guidance asks
|
|
12
|
+
// models to stay below 1,000 chars. Strict 1,200-char rejection caused capable
|
|
13
|
+
// models to waste an entire parallel fleet wave before self-repairing.
|
|
14
|
+
export const SUBAGENT_OBJECTIVE_CHARS = 4_000;
|
|
15
|
+
export const SUBAGENT_DELIVERABLE_CHARS = 600;
|
|
16
|
+
// Prompt guidance asks for at most 12 concise scope hints, but tolerate a
|
|
17
|
+
// pre-mapped file list so verbose models do not waste a full fleet wave on a
|
|
18
|
+
// recoverable schema error.
|
|
19
|
+
export const SUBAGENT_SCOPE_ITEMS = 32;
|
|
20
|
+
export const SUBAGENT_SCOPE_CHARS = 240;
|
|
21
|
+
export const SUBAGENT_ACCEPTANCE_ITEMS = 8;
|
|
22
|
+
export const SUBAGENT_ACCEPTANCE_CHARS = 300;
|
|
23
|
+
export const SUBAGENT_MIN_STEPS = 4;
|
|
24
|
+
export const SUBAGENT_DEFAULT_STEPS = 25;
|
|
25
|
+
export const SUBAGENT_MAX_STEPS = 50;
|
|
26
|
+
export const SUBAGENT_DEFAULT_TOOL_CALLS = 20;
|
|
27
|
+
export const SUBAGENT_MAX_TOOL_CALLS = 50;
|
|
28
|
+
export const SUBAGENT_TOOL_ONLY_LIMIT = 12;
|
|
29
|
+
export const SUBAGENT_SYNTHESIS_RESERVE = 2;
|
|
30
|
+
export const SUBAGENT_DEFAULT_OUTPUT_TOKENS = 4_096;
|
|
31
|
+
export const SUBAGENT_MAX_OUTPUT_TOKENS = 16_384;
|
|
32
|
+
export const SUBAGENT_DEFAULT_SUMMARY_CHARS = 4_000;
|
|
33
|
+
export const SUBAGENT_MAX_SUMMARY_CHARS = 12_000;
|
|
34
|
+
export const SUBAGENT_DEFAULT_INPUT_TOKENS = 40_000;
|
|
35
|
+
export const SUBAGENT_MAX_INPUT_TOKENS = 200_000;
|
|
36
|
+
export const SUBAGENT_DEFAULT_DEADLINE_MS = 300_000;
|
|
37
|
+
export const SUBAGENT_MIN_DEADLINE_MS = 1_000;
|
|
38
|
+
export const SUBAGENT_MAX_DEADLINE_MS = 30 * 60_000;
|
|
39
|
+
export const SUBAGENT_MAX_CONCURRENCY = 10;
|
|
40
|
+
export const SUBAGENT_MAX_RETRIES = 5;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { estimateValueTokens } from './contextBudget.js';
|
|
2
2
|
import { workStatePrompt } from './workState.js';
|
|
3
|
+
import { COMPACTION_OLDER_CHARS } from '../limits/textBudgets.js';
|
|
3
4
|
export function modelMessageText(message) {
|
|
4
5
|
const content = message.content;
|
|
5
6
|
if (typeof content === 'string')
|
|
@@ -32,10 +33,22 @@ export function compactModelMessages(messages, options = {}) {
|
|
|
32
33
|
return { compacted: false, messages, olderCount: 0, keptCount: messages.length };
|
|
33
34
|
const older = messages.slice(0, recentStart);
|
|
34
35
|
const recent = messages.slice(recentStart);
|
|
35
|
-
const
|
|
36
|
+
const olderEntries = older.map(message => {
|
|
36
37
|
const text = modelMessageText(message).replace(/\s+/g, ' ').trim();
|
|
37
38
|
return text ? `- ${message.role}: ${text}` : '';
|
|
38
|
-
}).filter(Boolean)
|
|
39
|
+
}).filter(Boolean);
|
|
40
|
+
// Keep the excerpt bounded, favoring the most recent older messages (CR-008).
|
|
41
|
+
const keptEntries = [];
|
|
42
|
+
let excerptChars = 0;
|
|
43
|
+
for (let index = olderEntries.length - 1; index >= 0; index--) {
|
|
44
|
+
const entry = olderEntries[index];
|
|
45
|
+
if (excerptChars + entry.length + 1 > COMPACTION_OLDER_CHARS && keptEntries.length > 0)
|
|
46
|
+
break;
|
|
47
|
+
keptEntries.unshift(entry);
|
|
48
|
+
excerptChars += entry.length + 1;
|
|
49
|
+
}
|
|
50
|
+
const omittedEntries = olderEntries.length - keptEntries.length;
|
|
51
|
+
const oldText = keptEntries.join('\n');
|
|
39
52
|
const summary = [
|
|
40
53
|
'Compacted prior haze conversation. Treat this as continuity context, not a new user request.',
|
|
41
54
|
'Preserve especially: current user goal and success condition; explicit user constraints/preferences/decisions; files created/changed/read; validation commands and pass/fail results; blockers or pending product decisions; exact next action if work was unfinished.',
|
|
@@ -43,8 +56,9 @@ export function compactModelMessages(messages, options = {}) {
|
|
|
43
56
|
options.instructions ? `User compaction instructions: ${options.instructions}` : undefined,
|
|
44
57
|
options.workState ? workStatePrompt(options.workState) : undefined,
|
|
45
58
|
'',
|
|
46
|
-
'Older context
|
|
59
|
+
'Older context excerpt (whitespace-collapsed, most recent first within a bounded budget):',
|
|
47
60
|
oldText || '- Older messages were tool-only or non-text.',
|
|
61
|
+
omittedEntries > 0 ? `[${omittedEntries} older message(s) omitted from the excerpt to keep compaction bounded; rely on the preserved points above.]` : undefined,
|
|
48
62
|
].filter((line) => line !== undefined).join('\n');
|
|
49
63
|
return {
|
|
50
64
|
compacted: true,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
2
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
3
|
export declare const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
4
|
+
/**
|
|
5
|
+
* Rough vision estimate for attached images: providers bill images by
|
|
6
|
+
* resolution, not by serialized bytes. ~750 bytes per token matches common
|
|
7
|
+
* screenshot encodings closely enough for budget/display estimates. Labeled
|
|
8
|
+
* as an estimate wherever it surfaces.
|
|
9
|
+
*/
|
|
10
|
+
export declare const IMAGE_BYTES_PER_TOKEN_ESTIMATE = 750;
|
|
4
11
|
export interface ContextBreakdown {
|
|
5
12
|
logicalInputEstimate: number;
|
|
6
13
|
system: number;
|
|
@@ -18,6 +25,7 @@ export interface ContextBreakdown {
|
|
|
18
25
|
syntheticControl: number;
|
|
19
26
|
}
|
|
20
27
|
export declare function estimateTextTokens(text: string): number;
|
|
28
|
+
export declare function estimateImagePartTokens(part: unknown): number;
|
|
21
29
|
export declare function estimateValueTokens(value: unknown): number;
|
|
22
30
|
export declare function estimateToolSchemas(tools?: Record<string, unknown>): {
|
|
23
31
|
name: string;
|
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { imageFilePartBytes, isImageFilePart } from '../attachments/imageAttachments.js';
|
|
2
3
|
export const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
4
|
+
/**
|
|
5
|
+
* Rough vision estimate for attached images: providers bill images by
|
|
6
|
+
* resolution, not by serialized bytes. ~750 bytes per token matches common
|
|
7
|
+
* screenshot encodings closely enough for budget/display estimates. Labeled
|
|
8
|
+
* as an estimate wherever it surfaces.
|
|
9
|
+
*/
|
|
10
|
+
export const IMAGE_BYTES_PER_TOKEN_ESTIMATE = 750;
|
|
3
11
|
export function estimateTextTokens(text) {
|
|
4
12
|
return Math.ceil(text.length / DEFAULT_CHARS_PER_TOKEN);
|
|
5
13
|
}
|
|
14
|
+
export function estimateImagePartTokens(part) {
|
|
15
|
+
if (!isImageFilePart(part))
|
|
16
|
+
return 0;
|
|
17
|
+
const bytes = imageFilePartBytes(part.data);
|
|
18
|
+
return bytes > 0 ? Math.max(1, Math.ceil(bytes / IMAGE_BYTES_PER_TOKEN_ESTIMATE)) : 1;
|
|
19
|
+
}
|
|
6
20
|
export function estimateValueTokens(value) {
|
|
7
21
|
if (typeof value === 'string')
|
|
8
22
|
return estimateTextTokens(value);
|
|
23
|
+
// Image parts are estimated from their byte size; serializing megabytes of
|
|
24
|
+
// image data as JSON would blow up both memory and the token estimate.
|
|
25
|
+
if (isImageFilePart(value))
|
|
26
|
+
return estimateImagePartTokens(value);
|
|
27
|
+
if (Array.isArray(value))
|
|
28
|
+
return value.reduce((sum, item) => sum + estimateValueTokens(item), 0);
|
|
29
|
+
if (typeof value === 'object' && value != null && Array.isArray(value.content)) {
|
|
30
|
+
const message = value;
|
|
31
|
+
const envelope = {};
|
|
32
|
+
for (const [key, item] of Object.entries(message))
|
|
33
|
+
if (key !== 'content')
|
|
34
|
+
envelope[key] = item;
|
|
35
|
+
return estimateTextTokens(JSON.stringify(envelope))
|
|
36
|
+
+ message.content.reduce((sum, part) => sum + estimateValueTokens(part), 0);
|
|
37
|
+
}
|
|
9
38
|
try {
|
|
10
39
|
return estimateTextTokens(JSON.stringify(value));
|
|
11
40
|
}
|
|
@@ -7,7 +7,11 @@ export function isContextOverflowError(error) {
|
|
|
7
7
|
}
|
|
8
8
|
export function isRetryableModelError(error) {
|
|
9
9
|
const text = errorText(error);
|
|
10
|
-
if (isContextOverflowError(error)
|
|
10
|
+
if (isContextOverflowError(error))
|
|
11
11
|
return false;
|
|
12
|
-
|
|
12
|
+
// Status codes are matched as whole words so "15000 tokens" or "processed
|
|
13
|
+
// 5000 files" are not misclassified (CR-020).
|
|
14
|
+
if (/\b(?:400|401|403)\b/.test(text) || /quota|billing|balance|auth|api key|invalid request|permission|forbidden/.test(text))
|
|
15
|
+
return false;
|
|
16
|
+
return /\b(?:429|500|502|503|504)\b/.test(text) || /overload|rate limit|network|connection|timeout|timed? out|terminated|econnreset|etimedout|fetch failed|stream disconnected|stream closed|stream aborted|stream error/.test(text);
|
|
13
17
|
}
|
|
@@ -50,6 +50,18 @@ export type AgentEvent = {
|
|
|
50
50
|
recovered: boolean;
|
|
51
51
|
error: string;
|
|
52
52
|
at: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'subagent_state';
|
|
55
|
+
id: string;
|
|
56
|
+
state: 'queued' | 'started' | 'terminal' | 'settled';
|
|
57
|
+
mode: string;
|
|
58
|
+
queued?: number;
|
|
59
|
+
running: number;
|
|
60
|
+
queueMs?: number;
|
|
61
|
+
durationMs?: number;
|
|
62
|
+
termination?: string;
|
|
63
|
+
execution?: 'settled' | 'quarantined';
|
|
64
|
+
at: string;
|
|
53
65
|
};
|
|
54
66
|
export type AgentEventSink = (event: AgentEvent) => void;
|
|
55
67
|
export type AgentEventInput = AgentEvent extends infer Event ? Event extends {
|
|
@@ -11,6 +11,11 @@ export interface StoredToolOutputPage {
|
|
|
11
11
|
query?: string;
|
|
12
12
|
matches?: number;
|
|
13
13
|
}
|
|
14
|
+
export declare function registerDynamicToolOutput(read: () => {
|
|
15
|
+
content: string;
|
|
16
|
+
totalBytes: number;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function unregisterDynamicToolOutput(handle: string): void;
|
|
14
19
|
export declare function storeToolOutput(content: string): string;
|
|
15
20
|
export declare function readToolOutput(handle: string, offset?: number, limit?: number, options?: {
|
|
16
21
|
query?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import { TOOL_OUTPUT_ENTRY_BYTES, TOOL_OUTPUT_TOTAL_BYTES } from '../limits/byteBudgets.js';
|
|
3
3
|
const outputs = new Map();
|
|
4
|
+
const dynamicOutputs = new Map();
|
|
4
5
|
const MAX_STORED_OUTPUTS = 100;
|
|
5
6
|
let storedBytes = 0;
|
|
6
7
|
function utf8Prefix(content, maxBytes) {
|
|
@@ -12,6 +13,14 @@ function utf8Prefix(content, maxBytes) {
|
|
|
12
13
|
end--;
|
|
13
14
|
return bytes.subarray(0, end).toString('utf8');
|
|
14
15
|
}
|
|
16
|
+
export function registerDynamicToolOutput(read) {
|
|
17
|
+
const handle = `output-${crypto.randomBytes(8).toString('hex')}`;
|
|
18
|
+
dynamicOutputs.set(handle, read);
|
|
19
|
+
return handle;
|
|
20
|
+
}
|
|
21
|
+
export function unregisterDynamicToolOutput(handle) {
|
|
22
|
+
dynamicOutputs.delete(handle);
|
|
23
|
+
}
|
|
15
24
|
export function storeToolOutput(content) {
|
|
16
25
|
const handle = `output-${crypto.randomBytes(8).toString('hex')}`;
|
|
17
26
|
const originalBytes = Buffer.byteLength(content, 'utf8');
|
|
@@ -57,9 +66,17 @@ function searchOutput(output, query, limit, contextLines = 2) {
|
|
|
57
66
|
return { offset: 0, totalChars: output.length, content: content.slice(0, limit), truncated: content.length > limit, query, matches: ranges.length };
|
|
58
67
|
}
|
|
59
68
|
export function readToolOutput(handle, offset = 0, limit = 12_000, options) {
|
|
60
|
-
const
|
|
69
|
+
const dynamic = dynamicOutputs.get(handle)?.();
|
|
70
|
+
const stored = dynamic
|
|
71
|
+
? { content: dynamic.content, bytes: Buffer.byteLength(dynamic.content, 'utf8'), originalBytes: dynamic.totalBytes }
|
|
72
|
+
: outputs.get(handle);
|
|
61
73
|
if (stored == null)
|
|
62
74
|
return undefined;
|
|
75
|
+
// Refresh recency so reads protect entries from LRU eviction (CR-019).
|
|
76
|
+
if (!dynamic) {
|
|
77
|
+
outputs.delete(handle);
|
|
78
|
+
outputs.set(handle, stored);
|
|
79
|
+
}
|
|
63
80
|
const output = stored.content;
|
|
64
81
|
if (options?.query?.trim()) {
|
|
65
82
|
const result = searchOutput(output, options.query.trim(), limit, options.contextLines);
|
|
@@ -30,12 +30,12 @@ export interface WorkState {
|
|
|
30
30
|
command: string;
|
|
31
31
|
status: WorkValidationStatus;
|
|
32
32
|
}>;
|
|
33
|
+
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
33
34
|
blockers: string[];
|
|
34
35
|
pending: string[];
|
|
35
36
|
nextAction?: string;
|
|
36
37
|
status: WorkStatus;
|
|
37
38
|
phase: WorkPhase;
|
|
38
|
-
blocker?: string;
|
|
39
39
|
lastProgressAt: number;
|
|
40
40
|
revision: number;
|
|
41
41
|
}
|
|
@@ -77,11 +77,8 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
77
77
|
state.phase = 'editing';
|
|
78
78
|
state.lastProgressAt = now;
|
|
79
79
|
state.blockers = state.blockers.filter(blocker => !blocker.includes(path));
|
|
80
|
-
if (state.blocker?.includes(path))
|
|
81
|
-
state.blocker = undefined;
|
|
82
80
|
}
|
|
83
81
|
else {
|
|
84
|
-
state.blocker = `File edit failed for ${path}; recovery read is required before retry.`;
|
|
85
82
|
state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
|
|
86
83
|
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
87
84
|
}
|
|
@@ -95,7 +92,6 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
95
92
|
state.phase = 'validating';
|
|
96
93
|
state.lastProgressAt = now;
|
|
97
94
|
if (!ok) {
|
|
98
|
-
state.blocker = `Validation command failed: ${command}`;
|
|
99
95
|
state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
|
|
100
96
|
}
|
|
101
97
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* User-attached images for one prompt (F03).
|
|
4
|
+
*
|
|
5
|
+
* Attachments are resolved from `@path` mentions typed by the user in the
|
|
6
|
+
* interactive chat: host-path allowed (workspace-relative, absolute, or `~/`),
|
|
7
|
+
* real-path deduped, extension-allowlisted, byte-bounded. The module is UI-
|
|
8
|
+
* and provider-agnostic (constitution VI): the capability gate takes the
|
|
9
|
+
* provider shape explicitly, never settings I/O.
|
|
10
|
+
*/
|
|
11
|
+
/** Extension allowlist → media type. Only these image kinds can be attached. */
|
|
12
|
+
export declare const IMAGE_MEDIA_TYPES: Readonly<Record<string, string>>;
|
|
13
|
+
export declare const IMAGE_EXTENSIONS: string[];
|
|
14
|
+
export interface ImageAttachment {
|
|
15
|
+
/** Display path: workspace-relative inside the project, `~/…` under the home directory, absolute otherwise. */
|
|
16
|
+
displayPath: string;
|
|
17
|
+
absolutePath: string;
|
|
18
|
+
fileName: string;
|
|
19
|
+
mediaType: string;
|
|
20
|
+
bytes: number;
|
|
21
|
+
data: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
export interface ResolvedImageAttachments {
|
|
24
|
+
/** Prompt text with attached mentions removed. */
|
|
25
|
+
text: string;
|
|
26
|
+
attachments: ImageAttachment[];
|
|
27
|
+
}
|
|
28
|
+
export interface PathMention {
|
|
29
|
+
/** Full match as it appears in the prompt (`@path` for explicit mentions, the path itself for bare). */
|
|
30
|
+
mention: string;
|
|
31
|
+
/** The path token after the `@`, or the bare path itself. */
|
|
32
|
+
token: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract path-like attachment candidates from prompt text. Two forms are
|
|
36
|
+
* recognised:
|
|
37
|
+
*
|
|
38
|
+
* - Explicit `@token` mentions: any path-like token after `@`. A candidate
|
|
39
|
+
* must contain a `.` or `/` so bare handles (`@here`) are skipped.
|
|
40
|
+
* - Bare paths: a token that ends in an allowlisted image extension AND
|
|
41
|
+
* contains `/`. The separator keeps prose like "I named it cat.png" out;
|
|
42
|
+
* the existence check during resolution is the final gate.
|
|
43
|
+
*
|
|
44
|
+
* Whether a candidate is really an attachment is decided during resolution.
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractPathMentions(text: string): PathMention[];
|
|
47
|
+
/**
|
|
48
|
+
* Resolve `@path` mentions into image attachments.
|
|
49
|
+
*
|
|
50
|
+
* - Mentions that do not resolve to an existing file stay literal
|
|
51
|
+
* prompt text (emails, handles, typos) — no error.
|
|
52
|
+
* - Existing paths with a non-image extension stay literal text too; the
|
|
53
|
+
* read-blessing resolver picks them up so the model can `readFile` them.
|
|
54
|
+
* - Existing image-extension paths that are not regular files (e.g. a
|
|
55
|
+
* directory named `foo.png`) fail loudly — that is a genuine attach-intent
|
|
56
|
+
* mismatch, not silent drop.
|
|
57
|
+
* - An `@` mention is an explicit user-typed reference, so any host path
|
|
58
|
+
* works: workspace-relative (including `../`), absolute, or `~/`. The real
|
|
59
|
+
* path dedupes aliases (symlinks, `..` segments) instead of confining
|
|
60
|
+
* reads; `.gitignore` is not enforced here (documented in AGENTS.md).
|
|
61
|
+
* - Size and per-message count are bounded by named limits; errors name them.
|
|
62
|
+
* - The same file mentioned twice is attached once; both mentions are stripped.
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveImageAttachments(text: string): Promise<ResolvedImageAttachments>;
|
|
65
|
+
/** Build the turn's user message: plain string without attachments, multipart with. */
|
|
66
|
+
export declare function userTurnMessage(text: string, attachments: readonly ImageAttachment[]): ModelMessage;
|
|
67
|
+
/** Minimal prompt text used when a message contains only images. */
|
|
68
|
+
export declare const IMAGE_ONLY_PROMPT_TEXT = "See the attached image.";
|
|
69
|
+
/** Minimal provider shape the capability gate needs (no settings I/O). */
|
|
70
|
+
export interface ImageCapableProviderLike {
|
|
71
|
+
name: string;
|
|
72
|
+
capabilities?: {
|
|
73
|
+
images?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Loud capability gate (constitution VII): images only go to providers the
|
|
78
|
+
* user explicitly marked image-capable. Returns undefined when the provider
|
|
79
|
+
* may receive image parts, otherwise an actionable error message.
|
|
80
|
+
*/
|
|
81
|
+
export declare function imageCapabilityError(provider: ImageCapableProviderLike | undefined): string | undefined;
|
|
82
|
+
/** Guard for AI SDK `file` parts carrying images, in any message role. */
|
|
83
|
+
export declare function isImageFilePart(value: unknown): value is {
|
|
84
|
+
type: 'file';
|
|
85
|
+
mediaType: string;
|
|
86
|
+
data?: unknown;
|
|
87
|
+
filename?: unknown;
|
|
88
|
+
};
|
|
89
|
+
/** Byte size of a file part's data without serializing it. */
|
|
90
|
+
export declare function imageFilePartBytes(data: unknown): number;
|