@denizokcu/haze 0.6.0 → 0.8.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 +42 -7
- package/README.md +81 -34
- package/dist/cli/chat/TaskBar.d.ts +9 -0
- package/dist/cli/chat/TaskBar.js +40 -0
- package/dist/cli/chat/chatMetrics.d.ts +11 -0
- package/dist/cli/chat/chatMetrics.js +50 -0
- package/dist/cli/chat/inputSuggestions.d.ts +16 -0
- package/dist/cli/chat/inputSuggestions.js +55 -0
- package/dist/cli/chat/messages.d.ts +9 -0
- package/dist/cli/chat/messages.js +76 -0
- package/dist/cli/chat/sessionRecorder.d.ts +12 -0
- package/dist/cli/chat/sessionRecorder.js +21 -0
- package/dist/cli/chat/startupInfo.d.ts +4 -0
- package/dist/cli/chat/startupInfo.js +53 -0
- package/dist/cli/chat/turnState.d.ts +5 -0
- package/dist/cli/chat/turnState.js +20 -0
- package/dist/cli/commands/chat.d.ts +0 -1
- package/dist/cli/commands/chat.js +331 -906
- package/dist/cli/commands/chatModes.d.ts +8 -0
- package/dist/cli/commands/chatModes.js +44 -0
- package/dist/cli/commands/commandHelp.d.ts +6 -0
- package/dist/cli/commands/commandHelp.js +25 -0
- package/dist/cli/commands/commands.d.ts +1 -1
- package/dist/cli/commands/commands.js +41 -267
- package/dist/cli/commands/formatters.d.ts +6 -0
- package/dist/cli/commands/formatters.js +50 -4
- package/dist/cli/commands/initCommand.d.ts +2 -0
- package/dist/cli/commands/initCommand.js +19 -0
- package/dist/cli/commands/logsCommand.d.ts +2 -0
- package/dist/cli/commands/logsCommand.js +63 -0
- package/dist/cli/commands/lspWizard.d.ts +14 -0
- package/dist/cli/commands/lspWizard.js +44 -0
- package/dist/cli/commands/mcpWizard.d.ts +15 -0
- package/dist/cli/commands/mcpWizard.js +69 -0
- package/dist/cli/commands/modelCommand.d.ts +2 -0
- package/dist/cli/commands/modelCommand.js +36 -0
- package/dist/cli/commands/providerWizard.d.ts +30 -0
- package/dist/cli/commands/providerWizard.js +114 -0
- package/dist/cli/commands/runCommand.d.ts +16 -0
- package/dist/cli/commands/runCommand.js +170 -0
- package/dist/cli/commands/settingsSummary.d.ts +3 -0
- package/dist/cli/commands/settingsSummary.js +40 -0
- package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
- package/dist/cli/commands/skillConfirmRemove.js +19 -0
- package/dist/cli/commands/skillCreation.d.ts +12 -0
- package/dist/cli/commands/skillCreation.js +14 -0
- package/dist/cli/commands/skillWizard.d.ts +15 -0
- package/dist/cli/commands/skillWizard.js +38 -0
- package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
- package/dist/cli/commands/streaming/assistantText.js +115 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
- package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
- package/dist/cli/commands/streaming/toolResultState.js +25 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
- package/dist/cli/commands/streaming/turnRuntime.js +86 -0
- package/dist/cli/commands/streaming.d.ts +9 -25
- package/dist/cli/commands/streaming.js +109 -363
- package/dist/cli/commands/wizardActions.d.ts +40 -0
- package/dist/cli/commands/wizardActions.js +40 -0
- package/dist/cli/commands/wizardInput.d.ts +4 -0
- package/dist/cli/commands/wizardInput.js +19 -0
- package/dist/cli/commands/wizardPrompts.d.ts +22 -0
- package/dist/cli/commands/wizardPrompts.js +52 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
- package/dist/cli/commands/wizardSuggestions.js +139 -0
- package/dist/cli/index.js +62 -4
- package/dist/config/contextFiles.d.ts +8 -1
- package/dist/config/contextFiles.js +25 -12
- package/dist/config/lspSettings.js +3 -6
- package/dist/config/mcpSettings.js +5 -5
- package/dist/config/providers.js +8 -12
- package/dist/config/settings.d.ts +1 -0
- package/dist/config/settings.js +54 -2
- package/dist/config/skillSettings.js +4 -3
- package/dist/core/agent/budgets.d.ts +6 -0
- package/dist/core/agent/budgets.js +6 -0
- package/dist/core/agent/compaction.js +3 -3
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +1 -7
- package/dist/core/agent/requestAssembly.js +40 -5
- package/dist/core/agent/toolOutputStore.js +5 -4
- package/dist/core/agent/toolResults.d.ts +31 -0
- package/dist/core/agent/toolResults.js +42 -0
- package/dist/core/agent/turnPolicy.d.ts +8 -0
- package/dist/core/agent/turnPolicy.js +23 -0
- package/dist/core/agent/workState.d.ts +18 -5
- package/dist/core/agent/workState.js +39 -20
- package/dist/core/bashOutput/reducers/content.d.ts +1 -0
- package/dist/core/bashOutput/reducers/content.js +1 -1
- package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
- package/dist/core/bashOutput/reducers/gh.js +77 -0
- package/dist/core/bashOutput/registry.js +18 -8
- package/dist/core/goal/completionPolicy.js +1 -1
- package/dist/core/goal/sessionGoal.d.ts +6 -30
- package/dist/core/goal/sessionGoal.js +3 -68
- package/dist/core/safety/bashClassifier.js +30 -0
- package/dist/core/safety/urlGuard.d.ts +1 -0
- package/dist/core/safety/urlGuard.js +6 -1
- package/dist/core/session/sessionSlimming.d.ts +5 -0
- package/dist/core/session/sessionSlimming.js +78 -0
- package/dist/core/session/sessionStore.d.ts +23 -3
- package/dist/core/session/sessionStore.js +30 -10
- package/dist/core/subagent/subagentRunner.d.ts +258 -5
- package/dist/core/subagent/subagentRunner.js +14 -18
- package/dist/core/toolOutput/reduction.d.ts +2 -0
- package/dist/core/toolOutput/reduction.js +12 -0
- package/dist/core/validation/outputParser.js +5 -3
- package/dist/llm/capabilities.d.ts +12 -0
- package/dist/llm/capabilities.js +10 -0
- package/dist/llm/client.d.ts +3 -2
- package/dist/llm/client.js +26 -4
- package/dist/llm/hazeTools.d.ts +7710 -366
- package/dist/llm/hazeTools.js +46 -567
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp.d.ts +46 -1
- package/dist/llm/lsp.js +19 -10
- package/dist/llm/lspTools.d.ts +2310 -119
- package/dist/llm/mcp.js +9 -0
- package/dist/llm/requestContext.js +7 -22
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +3 -3
- package/dist/llm/tools/bashTool.d.ts +251 -0
- package/dist/llm/tools/bashTool.js +82 -0
- package/dist/llm/tools/editMatch.d.ts +55 -0
- package/dist/llm/tools/editMatch.js +99 -0
- package/dist/llm/tools/failures.d.ts +36 -0
- package/dist/llm/tools/failures.js +38 -0
- package/dist/llm/tools/fetchTool.d.ts +1201 -0
- package/dist/llm/tools/fetchTool.js +46 -0
- package/dist/llm/tools/fileToolShared.d.ts +10 -0
- package/dist/llm/tools/fileToolShared.js +43 -0
- package/dist/llm/tools/grepParse.d.ts +13 -0
- package/dist/llm/tools/grepParse.js +67 -0
- package/dist/llm/tools/outputCap.d.ts +53 -0
- package/dist/llm/tools/outputCap.js +67 -0
- package/dist/llm/tools/storedOutputTool.d.ts +351 -0
- package/dist/llm/tools/storedOutputTool.js +17 -0
- package/dist/llm/tools/taskTool.d.ts +629 -0
- package/dist/llm/tools/taskTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +74 -0
- package/dist/llm/tools/toolContext.js +196 -0
- package/dist/llm/tools/workspaceFile.d.ts +33 -0
- package/dist/llm/tools/workspaceFile.js +27 -0
- package/dist/llm/webFetch.d.ts +13 -1
- package/dist/llm/webFetch.js +122 -28
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +8 -8
- package/dist/ui/components/TextInput.d.ts +7 -0
- package/dist/ui/components/TextInput.js +10 -98
- package/dist/ui/inputBuffer.d.ts +28 -0
- package/dist/ui/inputBuffer.js +99 -0
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/collections.js +9 -0
- package/dist/utils/modelName.d.ts +2 -0
- package/dist/utils/modelName.js +15 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +40 -0
- package/examples/skills/files/SKILL.md +1 -1
- package/package.json +14 -15
package/dist/config/settings.js
CHANGED
|
@@ -1,13 +1,65 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { HAZE_DIR } from './paths.js';
|
|
4
5
|
export const SETTINGS_FILE = path.join(HAZE_DIR, 'settings.json');
|
|
6
|
+
const providerSchema = z.object({
|
|
7
|
+
name: z.string(),
|
|
8
|
+
url: z.string(),
|
|
9
|
+
key: z.string().optional(),
|
|
10
|
+
models: z.array(z.string()),
|
|
11
|
+
}).passthrough();
|
|
12
|
+
const lspServerSchema = z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
command: z.string(),
|
|
15
|
+
args: z.array(z.string()).optional(),
|
|
16
|
+
extensions: z.array(z.string()).optional(),
|
|
17
|
+
rootPatterns: z.array(z.string()).optional(),
|
|
18
|
+
enabled: z.boolean().optional(),
|
|
19
|
+
}).passthrough();
|
|
20
|
+
const mcpHeaderSchema = z.object({ name: z.string(), value: z.string() }).passthrough();
|
|
21
|
+
const mcpServerSchema = z.object({
|
|
22
|
+
name: z.string(),
|
|
23
|
+
transport: z.enum(['http', 'sse', 'stdio']),
|
|
24
|
+
url: z.string().optional(),
|
|
25
|
+
command: z.string().optional(),
|
|
26
|
+
args: z.array(z.string()).optional(),
|
|
27
|
+
headers: z.array(mcpHeaderSchema).optional(),
|
|
28
|
+
enabled: z.boolean().optional(),
|
|
29
|
+
}).passthrough();
|
|
30
|
+
const skillSettingSchema = z.object({ name: z.string(), enabled: z.boolean().optional() }).passthrough();
|
|
31
|
+
const settingsSchema = z.object({
|
|
32
|
+
provider: z.string().optional(),
|
|
33
|
+
model: z.string().optional(),
|
|
34
|
+
providers: z.array(providerSchema).optional(),
|
|
35
|
+
lspServers: z.array(lspServerSchema).optional(),
|
|
36
|
+
mcpServers: z.array(mcpServerSchema).optional(),
|
|
37
|
+
skills: z.array(skillSettingSchema).optional(),
|
|
38
|
+
apiKey: z.string().optional(),
|
|
39
|
+
baseURL: z.string().optional(),
|
|
40
|
+
}).passthrough();
|
|
41
|
+
function settingsReadError(error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
return new Error(`Failed to read Haze settings at ${SETTINGS_FILE}: ${message}. Fix or remove the settings file, then retry.`);
|
|
44
|
+
}
|
|
5
45
|
export async function readSettings() {
|
|
6
|
-
|
|
46
|
+
try {
|
|
47
|
+
const raw = await fs.readJson(SETTINGS_FILE);
|
|
48
|
+
return settingsSchema.parse(raw);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
|
|
52
|
+
if (code === 'ENOENT')
|
|
53
|
+
return {};
|
|
54
|
+
throw settingsReadError(error);
|
|
55
|
+
}
|
|
7
56
|
}
|
|
8
57
|
export async function writeSettings(settings) {
|
|
9
58
|
await fs.ensureDir(HAZE_DIR);
|
|
10
|
-
|
|
59
|
+
const parsed = settingsSchema.parse(settings);
|
|
60
|
+
const tempFile = `${SETTINGS_FILE}.${process.pid}.${Date.now()}.tmp`;
|
|
61
|
+
await fs.writeJson(tempFile, parsed, { spaces: 2 });
|
|
62
|
+
await fs.move(tempFile, SETTINGS_FILE, { overwrite: true });
|
|
11
63
|
}
|
|
12
64
|
export async function updateSettings(patch) {
|
|
13
65
|
const next = { ...await readSettings(), ...patch };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findByName, removeByName } from '../utils/collections.js';
|
|
1
2
|
/**
|
|
2
3
|
* Normalized skill metadata overrides. The list is override-only: only skills that
|
|
3
4
|
* deviate from the default (enabled) appear here, so it never desyncs from disk.
|
|
@@ -14,7 +15,7 @@ export function configuredSkillSettings(settings) {
|
|
|
14
15
|
}
|
|
15
16
|
/** A skill is enabled unless an explicit override disables it. */
|
|
16
17
|
export function isSkillEnabled(settings, name) {
|
|
17
|
-
const entry = configuredSkillSettings(settings)
|
|
18
|
+
const entry = findByName(configuredSkillSettings(settings), name);
|
|
18
19
|
return entry ? entry.enabled !== false : true;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
@@ -22,10 +23,10 @@ export function isSkillEnabled(settings, name) {
|
|
|
22
23
|
* `enabled: false`. Returns the next `skills` array for updateSettings.
|
|
23
24
|
*/
|
|
24
25
|
export function setSkillEnabled(settings, name, enabled) {
|
|
25
|
-
const others = configuredSkillSettings(settings)
|
|
26
|
+
const others = removeByName(configuredSkillSettings(settings), name);
|
|
26
27
|
return enabled ? others : [...others, { name, enabled: false }];
|
|
27
28
|
}
|
|
28
29
|
/** Drop a skill's override entry. Called when a skill directory is removed. */
|
|
29
30
|
export function removeSkillSetting(settings, name) {
|
|
30
|
-
return configuredSkillSettings(settings)
|
|
31
|
+
return removeByName(configuredSkillSettings(settings), name);
|
|
31
32
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
|
|
2
|
+
export declare const IDLE_TIMEOUT_MS: number;
|
|
3
|
+
export declare const MAIN_STEP_LIMIT = 64;
|
|
4
|
+
export declare const MAIN_TOOL_CALL_LIMIT = 120;
|
|
5
|
+
export declare const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
6
|
+
export declare const ACTIVE_CONTEXT_TOKEN_BUDGET = 40000;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
|
|
2
|
+
export const IDLE_TIMEOUT_MS = 5 * 60_000;
|
|
3
|
+
export const MAIN_STEP_LIMIT = 64;
|
|
4
|
+
export const MAIN_TOOL_CALL_LIMIT = 120;
|
|
5
|
+
export const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
6
|
+
export const ACTIVE_CONTEXT_TOKEN_BUDGET = 40_000;
|
|
@@ -34,10 +34,10 @@ export function compactModelMessages(messages, options = {}) {
|
|
|
34
34
|
const recent = messages.slice(recentStart);
|
|
35
35
|
const oldText = older.map(message => {
|
|
36
36
|
const text = modelMessageText(message).replace(/\s+/g, ' ').trim();
|
|
37
|
-
return text ? `- ${message.role}: ${text
|
|
37
|
+
return text ? `- ${message.role}: ${text}` : '';
|
|
38
38
|
}).filter(Boolean).join('\n');
|
|
39
39
|
const summary = [
|
|
40
|
-
'Compacted prior
|
|
40
|
+
'Compacted prior haze conversation. Treat this as continuity context, not a new user request.',
|
|
41
41
|
'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.',
|
|
42
42
|
'Do not treat older tool outputs as current unless the recent conversation confirms they still apply.',
|
|
43
43
|
options.instructions ? `User compaction instructions: ${options.instructions}` : undefined,
|
|
@@ -48,7 +48,7 @@ export function compactModelMessages(messages, options = {}) {
|
|
|
48
48
|
].filter((line) => line !== undefined).join('\n');
|
|
49
49
|
return {
|
|
50
50
|
compacted: true,
|
|
51
|
-
messages: [{ role: '
|
|
51
|
+
messages: [{ role: 'user', content: `<haze_compaction>\n${summary}\n</haze_compaction>` }, ...recent],
|
|
52
52
|
olderCount: older.length,
|
|
53
53
|
keptCount: recent.length,
|
|
54
54
|
summary,
|
|
@@ -9,5 +9,5 @@ export function isRetryableModelError(error) {
|
|
|
9
9
|
const text = errorText(error);
|
|
10
10
|
if (isContextOverflowError(error) || /quota|billing|balance|auth|api key|invalid request|permission|forbidden|401|403|400/.test(text))
|
|
11
11
|
return false;
|
|
12
|
-
return /overload|rate limit|429|500|502|503|504|network|connection|stream|timeout|timed? out|econnreset|etimedout|fetch failed/.test(text);
|
|
12
|
+
return /overload|rate limit|429|500|502|503|504|network|connection|stream|timeout|timed? out|terminated|econnreset|etimedout|fetch failed/.test(text);
|
|
13
13
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
2
|
export declare const SYNTHETIC_CONTROL_OPEN = "<haze_control>";
|
|
3
|
-
export declare function toolRequestSettings<T extends Record<string, unknown>>(tools: T, allowTools: boolean): {
|
|
4
|
-
tools: T;
|
|
5
|
-
toolChoice: "auto";
|
|
6
|
-
} | {
|
|
7
|
-
tools?: undefined;
|
|
8
|
-
toolChoice?: undefined;
|
|
9
|
-
};
|
|
10
3
|
export declare function isSyntheticControlMessage(message: ModelMessage): boolean;
|
|
11
4
|
export declare function stripSyntheticControls(messages: ModelMessage[]): ModelMessage[];
|
|
5
|
+
export declare function withoutSystemMessages(messages: ModelMessage[]): ModelMessage[];
|
|
12
6
|
export declare function withSyntheticControl(messages: ModelMessage[], control: string): ModelMessage[];
|
|
13
7
|
export declare function compactToolHistory(messages: ModelMessage[], options?: {
|
|
14
8
|
keepRecentResults?: number;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { estimateValueTokens } from './contextBudget.js';
|
|
2
|
+
import { isFailedToolOutput } from './toolResults.js';
|
|
2
3
|
export const SYNTHETIC_CONTROL_OPEN = '<haze_control>';
|
|
3
|
-
export function toolRequestSettings(tools, allowTools) {
|
|
4
|
-
return allowTools ? { tools, toolChoice: 'auto' } : {};
|
|
5
|
-
}
|
|
6
4
|
export function isSyntheticControlMessage(message) {
|
|
7
5
|
return message.role === 'user'
|
|
8
6
|
&& typeof message.content === 'string'
|
|
@@ -11,6 +9,19 @@ export function isSyntheticControlMessage(message) {
|
|
|
11
9
|
export function stripSyntheticControls(messages) {
|
|
12
10
|
return messages.filter(message => !isSyntheticControlMessage(message));
|
|
13
11
|
}
|
|
12
|
+
export function withoutSystemMessages(messages) {
|
|
13
|
+
return messages.map(message => message.role === 'system'
|
|
14
|
+
? { ...message, role: 'user', content: `<haze_system_context>\n${modelMessageTextForContext(message)}\n</haze_system_context>` }
|
|
15
|
+
: message);
|
|
16
|
+
}
|
|
17
|
+
function modelMessageTextForContext(message) {
|
|
18
|
+
const content = message.content;
|
|
19
|
+
if (typeof content === 'string')
|
|
20
|
+
return content;
|
|
21
|
+
if (!Array.isArray(content))
|
|
22
|
+
return JSON.stringify(content);
|
|
23
|
+
return content.map(part => typeof part === 'object' && part != null && 'text' in part && typeof part.text === 'string' ? part.text : JSON.stringify(part)).join('\n');
|
|
24
|
+
}
|
|
14
25
|
export function withSyntheticControl(messages, control) {
|
|
15
26
|
return [
|
|
16
27
|
...stripSyntheticControls(messages),
|
|
@@ -29,7 +40,7 @@ function isFailedResult(output) {
|
|
|
29
40
|
if (type === 'error-text' || type === 'error-json' || type === 'execution-denied')
|
|
30
41
|
return true;
|
|
31
42
|
const value = resultValue(output);
|
|
32
|
-
return
|
|
43
|
+
return isFailedToolOutput(value);
|
|
33
44
|
}
|
|
34
45
|
function compactJsonValue(value, toolName) {
|
|
35
46
|
if (typeof value !== 'object' || value == null || Array.isArray(value)) {
|
|
@@ -80,7 +91,7 @@ function compactResultOutput(output, toolName) {
|
|
|
80
91
|
return { ...typed, value: `[Older successful ${toolName} result omitted from active context.]` };
|
|
81
92
|
return output;
|
|
82
93
|
}
|
|
83
|
-
const COMPACTABLE_INPUT_TOOLS = new Set(['writeFile', 'bash']);
|
|
94
|
+
const COMPACTABLE_INPUT_TOOLS = new Set(['writeFile', 'editFile', 'replaceLines', 'bash']);
|
|
84
95
|
const BASH_COMMAND_TRUNCATE_THRESHOLD = 200;
|
|
85
96
|
const BASH_COMMAND_KEEP_CHARS = 150;
|
|
86
97
|
function compactToolCallInput(input, toolName) {
|
|
@@ -95,6 +106,30 @@ function compactToolCallInput(input, toolName) {
|
|
|
95
106
|
content: `[Compacted: original ${bytes} bytes. Use readFile on "${path}" to inspect.]`,
|
|
96
107
|
};
|
|
97
108
|
}
|
|
109
|
+
if (toolName === 'editFile' && Array.isArray(source.edits)) {
|
|
110
|
+
const path = typeof source.path === 'string' ? source.path : '<unknown>';
|
|
111
|
+
const edits = source.edits.map(edit => {
|
|
112
|
+
if (typeof edit !== 'object' || edit == null)
|
|
113
|
+
return edit;
|
|
114
|
+
const entry = edit;
|
|
115
|
+
const oldBytes = typeof entry.oldText === 'string' ? entry.oldText.length : 0;
|
|
116
|
+
const newBytes = typeof entry.newText === 'string' ? entry.newText.length : 0;
|
|
117
|
+
return {
|
|
118
|
+
...entry,
|
|
119
|
+
oldText: `[Compacted: original ${oldBytes} bytes.]`,
|
|
120
|
+
newText: `[Compacted: original ${newBytes} bytes. Use readFile on "${path}" to inspect.]`,
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
return { ...source, edits };
|
|
124
|
+
}
|
|
125
|
+
if (toolName === 'replaceLines' && typeof source.content === 'string') {
|
|
126
|
+
const bytes = source.content.length;
|
|
127
|
+
const path = typeof source.path === 'string' ? source.path : '<unknown>';
|
|
128
|
+
return {
|
|
129
|
+
...source,
|
|
130
|
+
content: `[Compacted: original ${bytes} bytes. Use readFile on "${path}" to inspect.]`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
98
133
|
if (toolName === 'bash' && typeof source.command === 'string' && source.command.length > BASH_COMMAND_TRUNCATE_THRESHOLD) {
|
|
99
134
|
const total = source.command.length;
|
|
100
135
|
const truncated = source.command.slice(0, BASH_COMMAND_KEEP_CHARS).replace(/\s+/g, ' ').trim();
|
|
@@ -4,11 +4,12 @@ const MAX_STORED_OUTPUTS = 100;
|
|
|
4
4
|
export function storeToolOutput(content) {
|
|
5
5
|
const handle = `output-${crypto.randomBytes(8).toString('hex')}`;
|
|
6
6
|
outputs.set(handle, content);
|
|
7
|
-
|
|
7
|
+
// Synchronous, so the check+delete is atomic across async callers — no race.
|
|
8
|
+
// Each call inserts exactly one entry, so a single eviction restores the cap.
|
|
9
|
+
if (outputs.size > MAX_STORED_OUTPUTS) {
|
|
8
10
|
const oldest = outputs.keys().next().value;
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
outputs.delete(oldest);
|
|
11
|
+
if (oldest)
|
|
12
|
+
outputs.delete(oldest);
|
|
12
13
|
}
|
|
13
14
|
return handle;
|
|
14
15
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, protocol-level predicates and accessors for tool outputs and inputs.
|
|
3
|
+
*
|
|
4
|
+
* Tool results across the codebase carry a loose `{ok?: boolean}` convention
|
|
5
|
+
* (built-in hazeTools, subagent summaries, MCP passthrough). Centralizing these
|
|
6
|
+
* checks keeps the semantics identical everywhere they are used: the dedup gate
|
|
7
|
+
* (`hazeTools`), the work-state observer, the agent turn, and request
|
|
8
|
+
* compaction. Keeping them in `core/agent/` (no `ai`/UI imports) preserves
|
|
9
|
+
* auditability.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A structured tool result explicitly reports failure via `{ok: false}`.
|
|
13
|
+
* Returns false for results with no `ok` field (success is implied by the
|
|
14
|
+
* caller's `success` flag) and for non-object outputs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isFailedToolOutput(output: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Combine the provider success flag with the structured `ok` field. A result
|
|
19
|
+
* counts as OK only when the call succeeded AND did not report `{ok: false}`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toolOutputOk(output: unknown, success: boolean): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
24
|
+
* for non-objects, missing keys, or non-string values.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toolInputField(input: unknown, key: string): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
29
|
+
* instead of re-running. Lets observers treat them as no-ops.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isDuplicateSkippedOutput(output: unknown): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, protocol-level predicates and accessors for tool outputs and inputs.
|
|
3
|
+
*
|
|
4
|
+
* Tool results across the codebase carry a loose `{ok?: boolean}` convention
|
|
5
|
+
* (built-in hazeTools, subagent summaries, MCP passthrough). Centralizing these
|
|
6
|
+
* checks keeps the semantics identical everywhere they are used: the dedup gate
|
|
7
|
+
* (`hazeTools`), the work-state observer, the agent turn, and request
|
|
8
|
+
* compaction. Keeping them in `core/agent/` (no `ai`/UI imports) preserves
|
|
9
|
+
* auditability.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A structured tool result explicitly reports failure via `{ok: false}`.
|
|
13
|
+
* Returns false for results with no `ok` field (success is implied by the
|
|
14
|
+
* caller's `success` flag) and for non-object outputs.
|
|
15
|
+
*/
|
|
16
|
+
export function isFailedToolOutput(output) {
|
|
17
|
+
return typeof output === 'object' && output != null && 'ok' in output && output.ok === false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Combine the provider success flag with the structured `ok` field. A result
|
|
21
|
+
* counts as OK only when the call succeeded AND did not report `{ok: false}`.
|
|
22
|
+
*/
|
|
23
|
+
export function toolOutputOk(output, success) {
|
|
24
|
+
return success && !isFailedToolOutput(output);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
28
|
+
* for non-objects, missing keys, or non-string values.
|
|
29
|
+
*/
|
|
30
|
+
export function toolInputField(input, key) {
|
|
31
|
+
if (typeof input !== 'object' || input == null || !(key in input))
|
|
32
|
+
return undefined;
|
|
33
|
+
const value = input[key];
|
|
34
|
+
return typeof value === 'string' ? value : undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
38
|
+
* instead of re-running. Lets observers treat them as no-ops.
|
|
39
|
+
*/
|
|
40
|
+
export function isDuplicateSkippedOutput(output) {
|
|
41
|
+
return typeof output === 'object' && output != null && 'duplicateSkipped' in output && output.duplicateSkipped === true;
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function stableToolKey(toolCall) {
|
|
2
|
+
return `${toolCall.toolName}:${JSON.stringify(toolCall.input)}`;
|
|
3
|
+
}
|
|
4
|
+
export function uniqueRepeatedToolNames(toolCalls) {
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
const repeated = new Set();
|
|
7
|
+
for (const toolCall of toolCalls) {
|
|
8
|
+
const key = stableToolKey(toolCall);
|
|
9
|
+
if (seen.has(key))
|
|
10
|
+
repeated.add(toolCall.toolName);
|
|
11
|
+
seen.add(key);
|
|
12
|
+
}
|
|
13
|
+
return [...repeated];
|
|
14
|
+
}
|
|
15
|
+
export function toolOnlyStepCount(steps) {
|
|
16
|
+
let count = 0;
|
|
17
|
+
for (const step of [...steps].reverse()) {
|
|
18
|
+
if (step.toolCalls.length === 0 || step.text.trim().length > 0)
|
|
19
|
+
break;
|
|
20
|
+
count += 1;
|
|
21
|
+
}
|
|
22
|
+
return count;
|
|
23
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { RequestIntent } from '../goal/requestClassifier.js';
|
|
2
2
|
export type WorkFileAction = 'read' | 'created' | 'modified';
|
|
3
|
-
export type WorkValidationStatus = 'passed' | 'failed';
|
|
3
|
+
export type WorkValidationStatus = 'pending' | 'passed' | 'failed';
|
|
4
|
+
export type WorkStatus = 'active' | 'needs-user' | 'blocked' | 'complete' | 'aborted';
|
|
5
|
+
export type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
|
|
4
6
|
export interface WorkState {
|
|
7
|
+
id: string;
|
|
5
8
|
goal: string;
|
|
9
|
+
originalUserRequest: string;
|
|
6
10
|
intent: RequestIntent;
|
|
11
|
+
normalizedIntent: RequestIntent;
|
|
7
12
|
successCriteria: string[];
|
|
8
13
|
constraints: string[];
|
|
9
14
|
decisions: Array<{
|
|
@@ -15,15 +20,23 @@ export interface WorkState {
|
|
|
15
20
|
action: WorkFileAction;
|
|
16
21
|
note?: string;
|
|
17
22
|
}>;
|
|
23
|
+
touchedFiles: string[];
|
|
18
24
|
validations: Array<{
|
|
19
25
|
command: string;
|
|
20
|
-
status: WorkValidationStatus
|
|
26
|
+
status: Exclude<WorkValidationStatus, 'pending'>;
|
|
21
27
|
summary: string;
|
|
22
28
|
}>;
|
|
29
|
+
validationCommands: Array<{
|
|
30
|
+
command: string;
|
|
31
|
+
status: WorkValidationStatus;
|
|
32
|
+
}>;
|
|
23
33
|
blockers: string[];
|
|
24
34
|
pending: string[];
|
|
25
35
|
nextAction?: string;
|
|
26
|
-
|
|
36
|
+
status: WorkStatus;
|
|
37
|
+
phase: WorkPhase;
|
|
38
|
+
blocker?: string;
|
|
39
|
+
lastProgressAt: number;
|
|
27
40
|
revision: number;
|
|
28
41
|
}
|
|
29
42
|
export interface WorkToolEvent {
|
|
@@ -33,6 +46,6 @@ export interface WorkToolEvent {
|
|
|
33
46
|
output?: unknown;
|
|
34
47
|
duplicateSkipped?: boolean;
|
|
35
48
|
}
|
|
36
|
-
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[]): WorkState;
|
|
37
|
-
export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent): WorkState;
|
|
49
|
+
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
|
|
50
|
+
export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent, now?: number): WorkState;
|
|
38
51
|
export declare function workStatePrompt(state: WorkState): string;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return typeof input === 'object' && input != null && key in input && typeof input[key] === 'string'
|
|
3
|
-
? input[key]
|
|
4
|
-
: undefined;
|
|
5
|
-
}
|
|
1
|
+
import { toolInputField, toolOutputOk } from './toolResults.js';
|
|
6
2
|
function upsertFile(state, path, action, note) {
|
|
7
3
|
const existing = state.files.find(file => file.path === path);
|
|
8
4
|
if (existing) {
|
|
@@ -14,9 +10,8 @@ function upsertFile(state, path, action, note) {
|
|
|
14
10
|
else {
|
|
15
11
|
state.files.push({ path, action, ...(note ? { note } : {}) });
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return success && !(typeof output === 'object' && output != null && 'ok' in output && output.ok === false);
|
|
13
|
+
if (action !== 'read' && !state.touchedFiles.includes(path))
|
|
14
|
+
state.touchedFiles.push(path);
|
|
20
15
|
}
|
|
21
16
|
function outputSummary(output) {
|
|
22
17
|
if (typeof output !== 'object' || output == null)
|
|
@@ -30,55 +25,79 @@ function outputSummary(output) {
|
|
|
30
25
|
return `exit ${String(output.code)}`;
|
|
31
26
|
return '';
|
|
32
27
|
}
|
|
33
|
-
|
|
28
|
+
function upsertValidation(state, command, status, summary) {
|
|
29
|
+
const existing = state.validations.find(validation => validation.command === command);
|
|
30
|
+
if (existing)
|
|
31
|
+
Object.assign(existing, { status, summary });
|
|
32
|
+
else
|
|
33
|
+
state.validations.push({ command, status, summary });
|
|
34
|
+
const existingCommand = state.validationCommands.find(item => item.command === command);
|
|
35
|
+
if (existingCommand)
|
|
36
|
+
existingCommand.status = status;
|
|
37
|
+
else
|
|
38
|
+
state.validationCommands.push({ command, status });
|
|
39
|
+
}
|
|
40
|
+
export function createWorkState(goal, intent, successCriteria, now = Date.now()) {
|
|
34
41
|
return {
|
|
42
|
+
id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
|
|
35
43
|
goal,
|
|
44
|
+
originalUserRequest: goal,
|
|
36
45
|
intent,
|
|
46
|
+
normalizedIntent: intent,
|
|
37
47
|
successCriteria: [...successCriteria],
|
|
38
48
|
constraints: [],
|
|
39
49
|
decisions: [],
|
|
40
50
|
files: [],
|
|
51
|
+
touchedFiles: [],
|
|
41
52
|
validations: [],
|
|
53
|
+
validationCommands: [],
|
|
42
54
|
blockers: [],
|
|
43
55
|
pending: [],
|
|
56
|
+
status: 'active',
|
|
44
57
|
phase: 'starting',
|
|
58
|
+
lastProgressAt: now,
|
|
45
59
|
revision: 0,
|
|
46
60
|
};
|
|
47
61
|
}
|
|
48
|
-
export function observeWorkToolEvent(state, event) {
|
|
62
|
+
export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
49
63
|
if (event.duplicateSkipped)
|
|
50
64
|
return state;
|
|
51
|
-
const ok =
|
|
52
|
-
const path =
|
|
65
|
+
const ok = toolOutputOk(event.output, event.success);
|
|
66
|
+
const path = toolInputField(event.input, 'path');
|
|
53
67
|
if (ok && path && ['listFiles', 'readFile', 'grep'].includes(event.toolName)) {
|
|
54
68
|
if (event.toolName === 'readFile')
|
|
55
69
|
upsertFile(state, path, 'read');
|
|
56
|
-
state.phase
|
|
70
|
+
if (state.phase !== 'editing' && state.phase !== 'validating')
|
|
71
|
+
state.phase = 'inspecting';
|
|
72
|
+
state.lastProgressAt = now;
|
|
57
73
|
}
|
|
58
74
|
if (path && ['editFile', 'replaceLines', 'writeFile'].includes(event.toolName)) {
|
|
59
75
|
if (ok) {
|
|
60
76
|
upsertFile(state, path, event.toolName === 'writeFile' ? 'created' : 'modified');
|
|
61
77
|
state.phase = 'editing';
|
|
78
|
+
state.lastProgressAt = now;
|
|
62
79
|
state.blockers = state.blockers.filter(blocker => !blocker.includes(path));
|
|
80
|
+
if (state.blocker?.includes(path))
|
|
81
|
+
state.blocker = undefined;
|
|
63
82
|
}
|
|
64
83
|
else {
|
|
84
|
+
state.blocker = `File edit failed for ${path}; recovery read is required before retry.`;
|
|
65
85
|
state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
|
|
66
86
|
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
67
87
|
}
|
|
68
88
|
}
|
|
69
89
|
if (event.toolName === 'bash') {
|
|
70
|
-
const command =
|
|
90
|
+
const command = toolInputField(event.input, 'command');
|
|
71
91
|
if (command) {
|
|
72
92
|
const status = ok ? 'passed' : 'failed';
|
|
73
|
-
const existing = state.validations.find(validation => validation.command === command);
|
|
74
93
|
const summary = outputSummary(event.output);
|
|
75
|
-
|
|
76
|
-
Object.assign(existing, { status, summary });
|
|
77
|
-
else
|
|
78
|
-
state.validations.push({ command, status, summary });
|
|
94
|
+
upsertValidation(state, command, status, summary);
|
|
79
95
|
state.phase = 'validating';
|
|
80
|
-
|
|
96
|
+
state.lastProgressAt = now;
|
|
97
|
+
if (!ok) {
|
|
98
|
+
state.blocker = `Validation command failed: ${command}`;
|
|
81
99
|
state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
}
|
|
84
103
|
state.revision += 1;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function clip(line: string, max?: number): string;
|
|
1
2
|
export declare function reduceJsonOutput(stdout: string, stderr: string): string | undefined;
|
|
2
3
|
export declare function reduceUnifiedDiffOutput(stdout: string, stderr: string): string | undefined;
|
|
3
4
|
export declare function reduceGenericLogOutput(stdout: string, stderr: string): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function reduceGhOutput(command: string, stdout: string, stderr: string): string | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { commandCandidates } from '../command.js';
|
|
2
|
+
import { clip, reduceJsonOutput } from './content.js';
|
|
3
|
+
const GH_GROUPS = new Set(['pr', 'issue', 'run', 'release', 'repo', 'workflow']);
|
|
4
|
+
const READ_ONLY = new Set([
|
|
5
|
+
'pr list', 'pr view', 'pr checks',
|
|
6
|
+
'issue list', 'issue view',
|
|
7
|
+
'run list', 'run view',
|
|
8
|
+
'release list', 'release view',
|
|
9
|
+
'repo view',
|
|
10
|
+
]);
|
|
11
|
+
// Extract "<group> <action>" (e.g. "pr list") from a gh command, skipping flags.
|
|
12
|
+
function ghSubcommand(command) {
|
|
13
|
+
for (const candidate of commandCandidates(command)) {
|
|
14
|
+
const words = candidate.toLowerCase().split(/\s+/).filter(Boolean);
|
|
15
|
+
const ghIndex = words.indexOf('gh');
|
|
16
|
+
if (ghIndex === -1)
|
|
17
|
+
continue;
|
|
18
|
+
for (let index = ghIndex + 1; index < words.length; index++) {
|
|
19
|
+
const group = words[index] ?? '';
|
|
20
|
+
if (!GH_GROUPS.has(group))
|
|
21
|
+
continue;
|
|
22
|
+
for (let next = index + 1; next < words.length; next++) {
|
|
23
|
+
const action = words[next] ?? '';
|
|
24
|
+
if (action.startsWith('-'))
|
|
25
|
+
continue;
|
|
26
|
+
return `${group} ${action}`;
|
|
27
|
+
}
|
|
28
|
+
return group;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
// gh *list / pr checks → tab/space separated rows; summarize count + capped sample.
|
|
34
|
+
function reduceGhTable(subcommand, text) {
|
|
35
|
+
const rows = text.split(/\r?\n/).filter(line => line.trim());
|
|
36
|
+
if (rows.length <= 10 && text.length < 2000)
|
|
37
|
+
return undefined;
|
|
38
|
+
const shown = rows.slice(0, 30);
|
|
39
|
+
const output = [`gh ${subcommand}: ${rows.length} row${rows.length === 1 ? '' : 's'}`, ...shown.map(line => ` ${clip(line)}`)];
|
|
40
|
+
if (rows.length > shown.length)
|
|
41
|
+
output.push(` ... ${rows.length - shown.length} more`);
|
|
42
|
+
return output.join('\n');
|
|
43
|
+
}
|
|
44
|
+
// gh * view (non-JSON) → key:value header lines, then `--`, then markdown body.
|
|
45
|
+
function reduceGhView(subcommand, text) {
|
|
46
|
+
if (text.length < 2000)
|
|
47
|
+
return undefined;
|
|
48
|
+
const lines = text.split(/\r?\n/);
|
|
49
|
+
const sepIndex = lines.findIndex(line => line.trim() === '--');
|
|
50
|
+
const header = (sepIndex === -1 ? lines : lines.slice(0, sepIndex)).filter(Boolean);
|
|
51
|
+
const body = (sepIndex === -1 ? [] : lines.slice(sepIndex + 1)).filter(Boolean);
|
|
52
|
+
const bodyShown = body.slice(0, 12);
|
|
53
|
+
const output = [`gh ${subcommand}:`, ...header.slice(0, 30).map(line => ` ${clip(line)}`)];
|
|
54
|
+
if (bodyShown.length) {
|
|
55
|
+
output.push(' --', ...bodyShown.map(line => ` ${clip(line)}`));
|
|
56
|
+
if (body.length > bodyShown.length)
|
|
57
|
+
output.push(` ... ${body.length - bodyShown.length} more body lines`);
|
|
58
|
+
}
|
|
59
|
+
return output.join('\n');
|
|
60
|
+
}
|
|
61
|
+
export function reduceGhOutput(command, stdout, stderr) {
|
|
62
|
+
// `gh run view --log[-failed]` emits raw CI logs (no key/value + `--` body); let
|
|
63
|
+
// the generic log reducer extract end-of-log error signal instead of dropping it.
|
|
64
|
+
if (/\s--log(?:-failed)?\b/.test(command))
|
|
65
|
+
return undefined;
|
|
66
|
+
const subcommand = ghSubcommand(command);
|
|
67
|
+
if (!subcommand || !READ_ONLY.has(subcommand))
|
|
68
|
+
return undefined;
|
|
69
|
+
const text = stdout || stderr;
|
|
70
|
+
if (!text.trim())
|
|
71
|
+
return undefined;
|
|
72
|
+
if (/^\s*[[{]/.test(text))
|
|
73
|
+
return reduceJsonOutput(stdout, stderr); // --json → reuse JSON reducer (undefined for small JSON)
|
|
74
|
+
if (subcommand.endsWith(' view'))
|
|
75
|
+
return reduceGhView(subcommand, text);
|
|
76
|
+
return reduceGhTable(subcommand, text);
|
|
77
|
+
}
|