@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/llm/mcp.js
CHANGED
|
@@ -42,6 +42,15 @@ export async function loadMcpTools(servers, reserved = new Set()) {
|
|
|
42
42
|
}
|
|
43
43
|
return { tools, clients, errors };
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Transport-dispatching wrapper around `createMCPClient` (imported from
|
|
47
|
+
* `@ai-sdk/mcp`, capitalised). Translates a `HazeMcpServer` config into the
|
|
48
|
+
* transport shape the SDK expects — stdio (via `Experimental_StdioMCPTransport`)
|
|
49
|
+
* vs HTTP/SSE — and validates required fields before opening a transport.
|
|
50
|
+
*
|
|
51
|
+
* Not dead code: `loadMcpTools` calls this lowercase wrapper, not the imported
|
|
52
|
+
* `createMCPClient` directly (the import cannot take a `HazeMcpServer`).
|
|
53
|
+
*/
|
|
45
54
|
async function createMcpClient(server) {
|
|
46
55
|
if (server.transport === 'stdio') {
|
|
47
56
|
if (!server.command)
|
|
@@ -9,6 +9,7 @@ import { loadSkillRegistry } from '../skills/SkillRegistry.js';
|
|
|
9
9
|
import { buildSkillTools } from '../skills/skillTools.js';
|
|
10
10
|
import { isSkillEnabled } from '../config/skillSettings.js';
|
|
11
11
|
import { createSubagentTool } from '../core/subagent/subagentRunner.js';
|
|
12
|
+
import { addCapabilityTools } from './capabilities.js';
|
|
12
13
|
/**
|
|
13
14
|
* Assemble the system prompt and full tool set (built-in + LSP + subagent +
|
|
14
15
|
* skills + MCP) for a model request. This is the single source of truth shared
|
|
@@ -24,31 +25,15 @@ export async function assembleRequestContext(input) {
|
|
|
24
25
|
const hasInstalledLsp = (await installedLspServers(settings)).length > 0;
|
|
25
26
|
const toolCategories = new Map();
|
|
26
27
|
const availableTools = {};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
availableTools
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
for (const [name, value] of Object.entries(lspTools)) {
|
|
33
|
-
toolCategories.set(name, 'lsp');
|
|
34
|
-
availableTools[name] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const subagentTool = createSubagentTool({ model: input.model, contextFiles: input.contextFiles, session: input.session });
|
|
38
|
-
toolCategories.set('subagent', 'subagent');
|
|
39
|
-
availableTools.subagent = subagentTool;
|
|
40
|
-
const skillTools = buildSkillTools({ skills: enabledSkills });
|
|
41
|
-
for (const [name, value] of Object.entries(skillTools)) {
|
|
42
|
-
toolCategories.set(name, 'skill');
|
|
43
|
-
availableTools[name] = value;
|
|
44
|
-
}
|
|
28
|
+
addCapabilityTools({ availableTools, toolCategories, loaded: { category: 'builtin', tools: hazeTools } });
|
|
29
|
+
if (hasInstalledLsp)
|
|
30
|
+
addCapabilityTools({ availableTools, toolCategories, loaded: { category: 'lsp', tools: lspTools } });
|
|
31
|
+
addCapabilityTools({ availableTools, toolCategories, loaded: { category: 'subagent', tools: { subagent: createSubagentTool({ model: input.model, contextFiles: input.contextFiles, session: input.session }) } } });
|
|
32
|
+
addCapabilityTools({ availableTools, toolCategories, loaded: { category: 'skill', tools: buildSkillTools({ skills: enabledSkills }) } });
|
|
45
33
|
const mcpServers = configuredMcpServers(settings).filter(server => server.enabled !== false);
|
|
46
34
|
const loadedMcp = mcpServers.length > 0 ? await loadMcpTools(mcpServers, new Set(Object.keys(availableTools))) : undefined;
|
|
47
35
|
if (loadedMcp && Object.keys(loadedMcp.tools).length > 0) {
|
|
48
|
-
|
|
49
|
-
toolCategories.set(name, 'mcp');
|
|
50
|
-
availableTools[name] = value;
|
|
51
|
-
}
|
|
36
|
+
addCapabilityTools({ availableTools, toolCategories, loaded: { category: 'mcp', tools: loadedMcp.tools }, skipCollisions: true });
|
|
52
37
|
}
|
|
53
38
|
const mcpAvailable = Boolean(loadedMcp && Object.keys(loadedMcp.tools).length > 0);
|
|
54
39
|
const systemPrompt = buildSystemPrompt(input.contextFiles, input.session, { lspAvailable: hasInstalledLsp, mcpAvailable });
|
|
@@ -3,6 +3,7 @@ export interface PromptSession {
|
|
|
3
3
|
start?: Date;
|
|
4
4
|
cwd?: string;
|
|
5
5
|
}
|
|
6
|
+
export declare function projectContextSection(contextFiles: ContextFile[]): string;
|
|
6
7
|
export declare function buildSystemPrompt(contextFiles?: ContextFile[], session?: PromptSession, options?: {
|
|
7
8
|
lspAvailable?: boolean;
|
|
8
9
|
mcpAvailable?: boolean;
|
package/dist/llm/systemPrompt.js
CHANGED
|
@@ -3,7 +3,7 @@ function escapeContextContent(content) {
|
|
|
3
3
|
.replaceAll('</project_context>', '<\\/project_context>')
|
|
4
4
|
.replaceAll('</project_instructions>', '<\\/project_instructions>');
|
|
5
5
|
}
|
|
6
|
-
function projectContextSection(contextFiles) {
|
|
6
|
+
export function projectContextSection(contextFiles) {
|
|
7
7
|
if (contextFiles.length === 0)
|
|
8
8
|
return '';
|
|
9
9
|
const files = contextFiles.map(file => `<project_instructions path="${file.path}">\n${escapeContextContent(file.content)}\n</project_instructions>`).join('\n\n');
|
|
@@ -18,7 +18,7 @@ export function buildSystemPrompt(contextFiles = [], session, options = {}) {
|
|
|
18
18
|
const mcpToolRule = options.mcpAvailable
|
|
19
19
|
? '- MCP server tools (e.g. Context7 docs lookup) are available when configured via /mcp. They extend the toolset with external capabilities; use them when the user asks for up-to-date docs or library info those tools expose, instead of guessing from memory.\n'
|
|
20
20
|
: '';
|
|
21
|
-
return `You are
|
|
21
|
+
return `You are haze, an autonomous coding assistant in a terminal. Infer the requested outcome, inspect only what is relevant, make the smallest correct change, validate it when practical, and report status honestly.
|
|
22
22
|
|
|
23
23
|
## Operating rules
|
|
24
24
|
- Action request: continue through inspection, edits, and relevant validation. Do not stop at a plan.
|
|
@@ -39,7 +39,7 @@ ${lspToolRule}${mcpToolRule}- grep locates text patterns and non-semantic matche
|
|
|
39
39
|
- Ignored files require explicit need. Keep file mutations separate from validation commands when practical.
|
|
40
40
|
- File tools may surface scoped AGENTS.md/CLAUDE.md instructions for the target path. Review newly surfaced instructions before mutating that path; prefer the more specific path, and at the same scope AGENTS.md overrides CLAUDE.md.
|
|
41
41
|
- Batch independent tool calls in a single step (e.g. multiple writeFile or read operations that don't depend on each other). Do not narrate each call with phrases like "Now let me X" or "Next, I'll Y" — emit the tool calls directly. Reserve prose for non-obvious decisions, blockers, or final summaries.
|
|
42
|
-
- When the tool set is narrowed (activeTools) or tools are removed (toolChoice: none),
|
|
42
|
+
- When the tool set is narrowed (activeTools) or tools are removed (toolChoice: none), haze is steering recovery or preventing a loop; the constraint is intentional. Do not emit tool-call syntax (XML, JSON, or angle-bracket blocks) as text. If forced to stop mid-task, summarize current-turn changes and validation evidence, then state the single next concrete unfinished action so haze can continue in a fresh step.
|
|
43
43
|
|
|
44
44
|
## Completion
|
|
45
45
|
- After edits, run the smallest relevant test, typecheck, lint, or build command you can identify.
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
export declare const bashTool: ({
|
|
2
|
+
title?: string;
|
|
3
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
4
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
5
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
6
|
+
command: string;
|
|
7
|
+
allowMutation: boolean;
|
|
8
|
+
timeoutSeconds?: number | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
|
|
11
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
12
|
+
command: string;
|
|
13
|
+
allowMutation: boolean;
|
|
14
|
+
timeoutSeconds?: number | undefined;
|
|
15
|
+
}, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
|
|
16
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
17
|
+
onInputDelta?: ((options: {
|
|
18
|
+
inputTextDelta: string;
|
|
19
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
20
|
+
onInputAvailable?: ((options: {
|
|
21
|
+
input: {
|
|
22
|
+
command: string;
|
|
23
|
+
allowMutation: boolean;
|
|
24
|
+
timeoutSeconds?: number | undefined;
|
|
25
|
+
};
|
|
26
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
27
|
+
toModelOutput?: ((options: {
|
|
28
|
+
toolCallId: string;
|
|
29
|
+
input: {
|
|
30
|
+
command: string;
|
|
31
|
+
allowMutation: boolean;
|
|
32
|
+
timeoutSeconds?: number | undefined;
|
|
33
|
+
};
|
|
34
|
+
output: unknown;
|
|
35
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
36
|
+
} & {
|
|
37
|
+
outputSchema?: import("ai").FlexibleSchema<unknown> | undefined;
|
|
38
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
39
|
+
command: string;
|
|
40
|
+
allowMutation: boolean;
|
|
41
|
+
timeoutSeconds?: number | undefined;
|
|
42
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
43
|
+
} & {
|
|
44
|
+
description?: string | ((options: {
|
|
45
|
+
context: NoInfer<import("./toolContext.js").HazeToolContext>;
|
|
46
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
47
|
+
}) => string) | undefined;
|
|
48
|
+
strict?: boolean;
|
|
49
|
+
inputExamples?: {
|
|
50
|
+
input: NoInfer<{
|
|
51
|
+
command: string;
|
|
52
|
+
allowMutation: boolean;
|
|
53
|
+
timeoutSeconds?: number | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
}[] | undefined;
|
|
56
|
+
id?: never;
|
|
57
|
+
isProviderExecuted?: never;
|
|
58
|
+
args?: never;
|
|
59
|
+
supportsDeferredResults?: never;
|
|
60
|
+
} & {
|
|
61
|
+
type?: undefined | "function";
|
|
62
|
+
} & {
|
|
63
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
64
|
+
command: string;
|
|
65
|
+
allowMutation: boolean;
|
|
66
|
+
timeoutSeconds?: number | undefined;
|
|
67
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
68
|
+
}) | ({
|
|
69
|
+
title?: string;
|
|
70
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
71
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
72
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
73
|
+
command: string;
|
|
74
|
+
allowMutation: boolean;
|
|
75
|
+
timeoutSeconds?: number | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
|
|
78
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
79
|
+
command: string;
|
|
80
|
+
allowMutation: boolean;
|
|
81
|
+
timeoutSeconds?: number | undefined;
|
|
82
|
+
}, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
|
|
83
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
84
|
+
onInputDelta?: ((options: {
|
|
85
|
+
inputTextDelta: string;
|
|
86
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
87
|
+
onInputAvailable?: ((options: {
|
|
88
|
+
input: {
|
|
89
|
+
command: string;
|
|
90
|
+
allowMutation: boolean;
|
|
91
|
+
timeoutSeconds?: number | undefined;
|
|
92
|
+
};
|
|
93
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
94
|
+
toModelOutput?: ((options: {
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
input: {
|
|
97
|
+
command: string;
|
|
98
|
+
allowMutation: boolean;
|
|
99
|
+
timeoutSeconds?: number | undefined;
|
|
100
|
+
};
|
|
101
|
+
output: unknown;
|
|
102
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
103
|
+
} & {
|
|
104
|
+
outputSchema?: import("ai").FlexibleSchema<unknown> | undefined;
|
|
105
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
106
|
+
command: string;
|
|
107
|
+
allowMutation: boolean;
|
|
108
|
+
timeoutSeconds?: number | undefined;
|
|
109
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
110
|
+
} & {
|
|
111
|
+
description?: string | ((options: {
|
|
112
|
+
context: NoInfer<import("./toolContext.js").HazeToolContext>;
|
|
113
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
114
|
+
}) => string) | undefined;
|
|
115
|
+
strict?: boolean;
|
|
116
|
+
inputExamples?: {
|
|
117
|
+
input: NoInfer<{
|
|
118
|
+
command: string;
|
|
119
|
+
allowMutation: boolean;
|
|
120
|
+
timeoutSeconds?: number | undefined;
|
|
121
|
+
}>;
|
|
122
|
+
}[] | undefined;
|
|
123
|
+
id?: never;
|
|
124
|
+
isProviderExecuted?: never;
|
|
125
|
+
args?: never;
|
|
126
|
+
supportsDeferredResults?: never;
|
|
127
|
+
} & {
|
|
128
|
+
type: "dynamic";
|
|
129
|
+
} & {
|
|
130
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
131
|
+
command: string;
|
|
132
|
+
allowMutation: boolean;
|
|
133
|
+
timeoutSeconds?: number | undefined;
|
|
134
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
135
|
+
}) | ({
|
|
136
|
+
title?: string;
|
|
137
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
138
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
139
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
140
|
+
command: string;
|
|
141
|
+
allowMutation: boolean;
|
|
142
|
+
timeoutSeconds?: number | undefined;
|
|
143
|
+
}>;
|
|
144
|
+
contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
|
|
145
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
146
|
+
command: string;
|
|
147
|
+
allowMutation: boolean;
|
|
148
|
+
timeoutSeconds?: number | undefined;
|
|
149
|
+
}, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
|
|
150
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
151
|
+
onInputDelta?: ((options: {
|
|
152
|
+
inputTextDelta: string;
|
|
153
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
154
|
+
onInputAvailable?: ((options: {
|
|
155
|
+
input: {
|
|
156
|
+
command: string;
|
|
157
|
+
allowMutation: boolean;
|
|
158
|
+
timeoutSeconds?: number | undefined;
|
|
159
|
+
};
|
|
160
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
161
|
+
toModelOutput?: ((options: {
|
|
162
|
+
toolCallId: string;
|
|
163
|
+
input: {
|
|
164
|
+
command: string;
|
|
165
|
+
allowMutation: boolean;
|
|
166
|
+
timeoutSeconds?: number | undefined;
|
|
167
|
+
};
|
|
168
|
+
output: unknown;
|
|
169
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
170
|
+
} & {
|
|
171
|
+
outputSchema?: import("ai").FlexibleSchema<unknown> | undefined;
|
|
172
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
173
|
+
command: string;
|
|
174
|
+
allowMutation: boolean;
|
|
175
|
+
timeoutSeconds?: number | undefined;
|
|
176
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
177
|
+
} & {
|
|
178
|
+
type: "provider";
|
|
179
|
+
id: `${string}.${string}`;
|
|
180
|
+
args: Record<string, unknown>;
|
|
181
|
+
description?: never;
|
|
182
|
+
strict?: never;
|
|
183
|
+
inputExamples?: never;
|
|
184
|
+
} & {
|
|
185
|
+
isProviderExecuted: false;
|
|
186
|
+
supportsDeferredResults?: never;
|
|
187
|
+
} & {
|
|
188
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
189
|
+
command: string;
|
|
190
|
+
allowMutation: boolean;
|
|
191
|
+
timeoutSeconds?: number | undefined;
|
|
192
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
193
|
+
}) | ({
|
|
194
|
+
title?: string;
|
|
195
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
196
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
197
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
198
|
+
command: string;
|
|
199
|
+
allowMutation: boolean;
|
|
200
|
+
timeoutSeconds?: number | undefined;
|
|
201
|
+
}>;
|
|
202
|
+
contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
|
|
203
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
204
|
+
command: string;
|
|
205
|
+
allowMutation: boolean;
|
|
206
|
+
timeoutSeconds?: number | undefined;
|
|
207
|
+
}, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
|
|
208
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
209
|
+
onInputDelta?: ((options: {
|
|
210
|
+
inputTextDelta: string;
|
|
211
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
212
|
+
onInputAvailable?: ((options: {
|
|
213
|
+
input: {
|
|
214
|
+
command: string;
|
|
215
|
+
allowMutation: boolean;
|
|
216
|
+
timeoutSeconds?: number | undefined;
|
|
217
|
+
};
|
|
218
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
|
|
219
|
+
toModelOutput?: ((options: {
|
|
220
|
+
toolCallId: string;
|
|
221
|
+
input: {
|
|
222
|
+
command: string;
|
|
223
|
+
allowMutation: boolean;
|
|
224
|
+
timeoutSeconds?: number | undefined;
|
|
225
|
+
};
|
|
226
|
+
output: unknown;
|
|
227
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
228
|
+
} & {
|
|
229
|
+
outputSchema?: import("ai").FlexibleSchema<unknown> | undefined;
|
|
230
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
231
|
+
command: string;
|
|
232
|
+
allowMutation: boolean;
|
|
233
|
+
timeoutSeconds?: number | undefined;
|
|
234
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
235
|
+
} & {
|
|
236
|
+
type: "provider";
|
|
237
|
+
id: `${string}.${string}`;
|
|
238
|
+
args: Record<string, unknown>;
|
|
239
|
+
description?: never;
|
|
240
|
+
strict?: never;
|
|
241
|
+
inputExamples?: never;
|
|
242
|
+
} & {
|
|
243
|
+
isProviderExecuted: true;
|
|
244
|
+
supportsDeferredResults?: boolean;
|
|
245
|
+
} & {
|
|
246
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
247
|
+
command: string;
|
|
248
|
+
allowMutation: boolean;
|
|
249
|
+
timeoutSeconds?: number | undefined;
|
|
250
|
+
}, unknown, NoInfer<import("./toolContext.js").HazeToolContext>>;
|
|
251
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { tool } from 'ai';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { classifyBashCommand, isValidationClassification } from '../../core/safety/bashClassifier.js';
|
|
5
|
+
import { parseValidationOutput } from '../../core/validation/outputParser.js';
|
|
6
|
+
import { filterBashOutput } from '../../core/bashOutput/registry.js';
|
|
7
|
+
import { storeToolOutput } from '../../core/agent/toolOutputStore.js';
|
|
8
|
+
import { workspaceRoot } from '../../utils/path.js';
|
|
9
|
+
import { compactStoredOutput, COMPACT_COMMAND_CHARS } from './outputCap.js';
|
|
10
|
+
import { hazeToolContextSchema, runDedupedTool } from './toolContext.js';
|
|
11
|
+
const SHORT_VALIDATION_CHARS = 2_000;
|
|
12
|
+
export const bashTool = tool({
|
|
13
|
+
description: 'Run workspace tests, builds, validation, or inspection. Risk classification is informational; use file tools for edits.',
|
|
14
|
+
contextSchema: hazeToolContextSchema,
|
|
15
|
+
inputSchema: z.object({
|
|
16
|
+
command: z.string().min(1).describe('Command to execute with bash -lc'),
|
|
17
|
+
timeoutSeconds: z.number().int().positive().max(600).optional().describe('Timeout in seconds; defaults to 60'),
|
|
18
|
+
allowMutation: z.boolean().default(false).describe('Deprecated compatibility flag. Commands run without confirmation; retained for compatibility.'),
|
|
19
|
+
}),
|
|
20
|
+
execute: async ({ command, timeoutSeconds }, context) => runDedupedTool('bash', { command, timeoutSeconds }, context, async () => {
|
|
21
|
+
const cwd = workspaceRoot();
|
|
22
|
+
const classification = classifyBashCommand(command);
|
|
23
|
+
const timeoutMs = (timeoutSeconds ?? 60) * 1000;
|
|
24
|
+
const startedAt = Date.now();
|
|
25
|
+
return await new Promise(resolve => {
|
|
26
|
+
const child = spawn('bash', ['-lc', command], { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
27
|
+
let stdout = '';
|
|
28
|
+
let stderr = '';
|
|
29
|
+
let settled = false;
|
|
30
|
+
let timedOut = false;
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
if (!settled) {
|
|
33
|
+
timedOut = true;
|
|
34
|
+
child.kill('SIGTERM');
|
|
35
|
+
}
|
|
36
|
+
}, timeoutMs);
|
|
37
|
+
const abort = () => child.kill('SIGTERM');
|
|
38
|
+
context.abortSignal?.addEventListener('abort', abort, { once: true });
|
|
39
|
+
child.stdout.on('data', data => stdout += data.toString());
|
|
40
|
+
child.stderr.on('data', data => stderr += data.toString());
|
|
41
|
+
child.on('close', code => {
|
|
42
|
+
settled = true;
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
context.abortSignal?.removeEventListener('abort', abort);
|
|
45
|
+
const validationSummary = isValidationClassification(classification)
|
|
46
|
+
? parseValidationOutput({ command, code, stdout, stderr, timedOut, stdoutTruncated: stdout.length > COMPACT_COMMAND_CHARS, stderrTruncated: stderr.length > COMPACT_COMMAND_CHARS, classification })
|
|
47
|
+
: undefined;
|
|
48
|
+
const validationPassed = validationSummary?.status === 'passed';
|
|
49
|
+
const output = filterBashOutput({
|
|
50
|
+
command,
|
|
51
|
+
code,
|
|
52
|
+
stdout,
|
|
53
|
+
stderr,
|
|
54
|
+
timedOut,
|
|
55
|
+
classification,
|
|
56
|
+
validationSummary,
|
|
57
|
+
storeRawOutput: storeToolOutput,
|
|
58
|
+
fallbackCompact: compactStoredOutput,
|
|
59
|
+
compactMaxChars: validationPassed ? SHORT_VALIDATION_CHARS : COMPACT_COMMAND_CHARS,
|
|
60
|
+
});
|
|
61
|
+
resolve({
|
|
62
|
+
ok: code === 0 && !timedOut,
|
|
63
|
+
code,
|
|
64
|
+
command,
|
|
65
|
+
cwd,
|
|
66
|
+
classification,
|
|
67
|
+
durationMs: Date.now() - startedAt,
|
|
68
|
+
timedOut,
|
|
69
|
+
stdout: output.stdout,
|
|
70
|
+
stderr: output.stderr,
|
|
71
|
+
validationSummary,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
child.on('error', error => {
|
|
75
|
+
settled = true;
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
context.abortSignal?.removeEventListener('abort', abort);
|
|
78
|
+
resolve({ ok: false, command, cwd, classification, durationMs: Date.now() - startedAt, error: error.message });
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ToolDiffLine } from '../toolResultTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pure text-matching and diff helpers for the `editFile` / `replaceLines` tools.
|
|
4
|
+
*
|
|
5
|
+
* `findEditRange` locates `oldText` within a file, tolerating readFile
|
|
6
|
+
* line-number prefixes and trailing-whitespace-only differences (only when the
|
|
7
|
+
* match stays unique). Diff helpers render compact before/after line views.
|
|
8
|
+
*/
|
|
9
|
+
/** Strip a readFile-style ` 123 | ` prefix from each line. */
|
|
10
|
+
export declare function stripLineNumberPrefixes(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Locate `oldText` in `original`. Tries an exact match first, then a
|
|
13
|
+
* line-number-prefix-stripped match, finally a trailing-whitespace-tolerant
|
|
14
|
+
* line match. Returns `multiple` when the text is ambiguous (not unique).
|
|
15
|
+
*/
|
|
16
|
+
export declare function findEditRange(original: string, oldText: string): {
|
|
17
|
+
kind: "multiple";
|
|
18
|
+
start?: undefined;
|
|
19
|
+
end?: undefined;
|
|
20
|
+
approximate?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "found";
|
|
23
|
+
start: number;
|
|
24
|
+
end: number;
|
|
25
|
+
approximate: boolean;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "missing";
|
|
28
|
+
start?: undefined;
|
|
29
|
+
end?: undefined;
|
|
30
|
+
approximate?: undefined;
|
|
31
|
+
};
|
|
32
|
+
/** Split text into diff lines, dropping a single trailing newline. */
|
|
33
|
+
export declare function splitDiffLines(text: string): string[];
|
|
34
|
+
/** 1-based line number at a character offset. */
|
|
35
|
+
export declare function lineNumberAtOffset(text: string, offset: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Build a remove/add diff with optional surrounding context lines, plus the
|
|
38
|
+
* added/removed line counts.
|
|
39
|
+
*/
|
|
40
|
+
export declare function replacementDiff(oldText: string, newText: string, oldStartLine: number, newStartLine: number, context?: {
|
|
41
|
+
before?: {
|
|
42
|
+
oldLine: number;
|
|
43
|
+
newLine: number;
|
|
44
|
+
text: string;
|
|
45
|
+
};
|
|
46
|
+
after?: {
|
|
47
|
+
oldLine: number;
|
|
48
|
+
newLine: number;
|
|
49
|
+
text: string;
|
|
50
|
+
};
|
|
51
|
+
}): {
|
|
52
|
+
diff: ToolDiffLine[];
|
|
53
|
+
addedLines: number;
|
|
54
|
+
removedLines: number;
|
|
55
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure text-matching and diff helpers for the `editFile` / `replaceLines` tools.
|
|
3
|
+
*
|
|
4
|
+
* `findEditRange` locates `oldText` within a file, tolerating readFile
|
|
5
|
+
* line-number prefixes and trailing-whitespace-only differences (only when the
|
|
6
|
+
* match stays unique). Diff helpers render compact before/after line views.
|
|
7
|
+
*/
|
|
8
|
+
/** Strip a readFile-style ` 123 | ` prefix from each line. */
|
|
9
|
+
export function stripLineNumberPrefixes(text) {
|
|
10
|
+
return text.replace(/^\s*\d+\s+\| ?/gm, '');
|
|
11
|
+
}
|
|
12
|
+
/** Character offsets of the start of each line (for mapping offsets back to lines). */
|
|
13
|
+
function lineStartOffsets(text) {
|
|
14
|
+
const offsets = [0];
|
|
15
|
+
for (let index = 0; index < text.length; index++) {
|
|
16
|
+
if (text[index] === '\n')
|
|
17
|
+
offsets.push(index + 1);
|
|
18
|
+
}
|
|
19
|
+
return offsets;
|
|
20
|
+
}
|
|
21
|
+
function findLineTrimmedRange(original, oldText) {
|
|
22
|
+
const wantedLines = oldText.replace(/\r\n/g, '\n').split('\n').map(line => line.trimEnd());
|
|
23
|
+
if (wantedLines.at(-1) === '')
|
|
24
|
+
wantedLines.pop();
|
|
25
|
+
if (wantedLines.length === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
const originalLines = original.replace(/\r\n/g, '\n').split('\n');
|
|
28
|
+
const hasTrailingNewline = original.endsWith('\n');
|
|
29
|
+
if (hasTrailingNewline)
|
|
30
|
+
originalLines.pop();
|
|
31
|
+
const offsets = lineStartOffsets(original);
|
|
32
|
+
const matches = [];
|
|
33
|
+
for (let lineIndex = 0; lineIndex <= originalLines.length - wantedLines.length; lineIndex++) {
|
|
34
|
+
const window = originalLines.slice(lineIndex, lineIndex + wantedLines.length).map(line => line.trimEnd());
|
|
35
|
+
if (window.every((line, index) => line === wantedLines[index])) {
|
|
36
|
+
const start = offsets[lineIndex] ?? 0;
|
|
37
|
+
const endLineIndex = lineIndex + wantedLines.length;
|
|
38
|
+
const end = endLineIndex < offsets.length ? (offsets[endLineIndex] ?? original.length) : original.length;
|
|
39
|
+
matches.push({ start, end });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (matches.length !== 1)
|
|
43
|
+
return undefined;
|
|
44
|
+
return matches[0];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Locate `oldText` in `original`. Tries an exact match first, then a
|
|
48
|
+
* line-number-prefix-stripped match, finally a trailing-whitespace-tolerant
|
|
49
|
+
* line match. Returns `multiple` when the text is ambiguous (not unique).
|
|
50
|
+
*/
|
|
51
|
+
export function findEditRange(original, oldText) {
|
|
52
|
+
const candidates = [oldText, stripLineNumberPrefixes(oldText)].filter((candidate, index, all) => candidate.length > 0 && all.indexOf(candidate) === index);
|
|
53
|
+
for (const candidate of candidates) {
|
|
54
|
+
const first = original.indexOf(candidate);
|
|
55
|
+
if (first !== -1) {
|
|
56
|
+
const second = original.indexOf(candidate, first + candidate.length);
|
|
57
|
+
if (second !== -1)
|
|
58
|
+
return { kind: 'multiple' };
|
|
59
|
+
return { kind: 'found', start: first, end: first + candidate.length, approximate: candidate !== oldText };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const candidate of candidates) {
|
|
63
|
+
const range = findLineTrimmedRange(original, candidate);
|
|
64
|
+
if (range)
|
|
65
|
+
return { kind: 'found', ...range, approximate: true };
|
|
66
|
+
}
|
|
67
|
+
return { kind: 'missing' };
|
|
68
|
+
}
|
|
69
|
+
/** Split text into diff lines, dropping a single trailing newline. */
|
|
70
|
+
export function splitDiffLines(text) {
|
|
71
|
+
const lines = text.split(/\r?\n/);
|
|
72
|
+
if (text.endsWith('\n') || text.endsWith('\r\n'))
|
|
73
|
+
lines.pop();
|
|
74
|
+
return lines;
|
|
75
|
+
}
|
|
76
|
+
/** 1-based line number at a character offset. */
|
|
77
|
+
export function lineNumberAtOffset(text, offset) {
|
|
78
|
+
let line = 1;
|
|
79
|
+
for (let index = 0; index < offset; index++) {
|
|
80
|
+
if (text.charCodeAt(index) === 10)
|
|
81
|
+
line += 1;
|
|
82
|
+
}
|
|
83
|
+
return line;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a remove/add diff with optional surrounding context lines, plus the
|
|
87
|
+
* added/removed line counts.
|
|
88
|
+
*/
|
|
89
|
+
export function replacementDiff(oldText, newText, oldStartLine, newStartLine, context) {
|
|
90
|
+
const oldLines = splitDiffLines(oldText);
|
|
91
|
+
const newLines = splitDiffLines(newText);
|
|
92
|
+
const diff = [];
|
|
93
|
+
if (context?.before)
|
|
94
|
+
diff.push({ type: 'context', ...context.before });
|
|
95
|
+
diff.push(...oldLines.map((text, index) => ({ type: 'remove', oldLine: oldStartLine + index, text })), ...newLines.map((text, index) => ({ type: 'add', newLine: newStartLine + index, text })));
|
|
96
|
+
if (context?.after)
|
|
97
|
+
diff.push({ type: 'context', ...context.after });
|
|
98
|
+
return { diff, addedLines: newLines.length, removedLines: oldLines.length };
|
|
99
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ToolFailureReasonCode } from '../toolResultTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown by built-in tools to carry a structured failure reason and an
|
|
4
|
+
* optional recovery hint (next tool + input). Caught and normalized into a
|
|
5
|
+
* structured tool-result object by {@link structuredToolFailure}.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HazeToolError extends Error {
|
|
8
|
+
reasonCode: ToolFailureReasonCode;
|
|
9
|
+
recoveryTool?: string;
|
|
10
|
+
recoveryInput?: unknown;
|
|
11
|
+
constructor(message: string, reasonCode: ToolFailureReasonCode, options?: {
|
|
12
|
+
recoveryTool?: string;
|
|
13
|
+
recoveryInput?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Normalize a thrown error (or raw value) into the structured `{ok: false}`
|
|
18
|
+
* tool-result shape every built-in tool returns on failure. Honors
|
|
19
|
+
* `HazeToolError` reason/recovery hints when present and lets callers override
|
|
20
|
+
* the reason code (e.g. fetch's `blocked_url`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function structuredToolFailure(toolName: string, error: unknown, suggestedNextStep: string, pathForError?: string, options?: {
|
|
23
|
+
reasonCode?: ToolFailureReasonCode;
|
|
24
|
+
recoveryTool?: string;
|
|
25
|
+
recoveryInput?: unknown;
|
|
26
|
+
}): {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
toolName: string;
|
|
29
|
+
path: string | undefined;
|
|
30
|
+
error: string;
|
|
31
|
+
reasonCode: ToolFailureReasonCode | undefined;
|
|
32
|
+
recoverable: boolean;
|
|
33
|
+
suggestedNextStep: string;
|
|
34
|
+
recoveryTool: string | undefined;
|
|
35
|
+
recoveryInput: unknown;
|
|
36
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by built-in tools to carry a structured failure reason and an
|
|
3
|
+
* optional recovery hint (next tool + input). Caught and normalized into a
|
|
4
|
+
* structured tool-result object by {@link structuredToolFailure}.
|
|
5
|
+
*/
|
|
6
|
+
export class HazeToolError extends Error {
|
|
7
|
+
reasonCode;
|
|
8
|
+
recoveryTool;
|
|
9
|
+
recoveryInput;
|
|
10
|
+
constructor(message, reasonCode, options) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'HazeToolError';
|
|
13
|
+
this.reasonCode = reasonCode;
|
|
14
|
+
this.recoveryTool = options?.recoveryTool;
|
|
15
|
+
this.recoveryInput = options?.recoveryInput;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a thrown error (or raw value) into the structured `{ok: false}`
|
|
20
|
+
* tool-result shape every built-in tool returns on failure. Honors
|
|
21
|
+
* `HazeToolError` reason/recovery hints when present and lets callers override
|
|
22
|
+
* the reason code (e.g. fetch's `blocked_url`).
|
|
23
|
+
*/
|
|
24
|
+
export function structuredToolFailure(toolName, error, suggestedNextStep, pathForError, options) {
|
|
25
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
+
const hazeError = error instanceof HazeToolError ? error : undefined;
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
toolName,
|
|
30
|
+
path: pathForError,
|
|
31
|
+
error: message,
|
|
32
|
+
reasonCode: options?.reasonCode ?? hazeError?.reasonCode,
|
|
33
|
+
recoverable: true,
|
|
34
|
+
suggestedNextStep,
|
|
35
|
+
recoveryTool: options?.recoveryTool ?? hazeError?.recoveryTool,
|
|
36
|
+
recoveryInput: options?.recoveryInput ?? hazeError?.recoveryInput,
|
|
37
|
+
};
|
|
38
|
+
}
|