@denizokcu/haze 1.2.0 → 1.5.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 +86 -1
- package/README.md +23 -10
- package/SECURITY.md +1 -1
- package/bin/haze.js +27 -7
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +7 -0
- package/dist/cli/chat/BusyBar.js +8 -0
- package/dist/cli/chat/DynamicFrame.d.ts +37 -0
- package/dist/cli/chat/DynamicFrame.js +43 -0
- package/dist/cli/chat/busyIndicator.d.ts +3 -1
- package/dist/cli/chat/busyIndicator.js +11 -9
- package/dist/cli/chat/chatMetrics.d.ts +1 -1
- package/dist/cli/chat/chatMetrics.js +3 -3
- package/dist/cli/chat/inputSuggestions.js +4 -0
- package/dist/cli/chat/liveMessages.d.ts +36 -0
- package/dist/cli/chat/liveMessages.js +64 -0
- package/dist/cli/chat/liveRegion.js +1 -1
- package/dist/cli/chat/messages.js +27 -16
- package/dist/cli/chat/sessionLifecycle.d.ts +5 -2
- package/dist/cli/chat/sessionLifecycle.js +36 -4
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +8 -0
- package/dist/cli/chat/shutdown.d.ts +27 -0
- package/dist/cli/chat/shutdown.js +79 -0
- package/dist/cli/chat/terminalControl.d.ts +45 -0
- package/dist/cli/chat/terminalControl.js +107 -0
- package/dist/cli/chat/tips.js +1 -0
- package/dist/cli/chat/userInput.d.ts +43 -0
- package/dist/cli/chat/userInput.js +63 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +1 -1
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +24 -1
- package/dist/cli/chat/wizard/types.d.ts +8 -1
- package/dist/cli/chat/wizardDispatch.js +1 -1
- package/dist/cli/commands/chat.js +277 -193
- package/dist/cli/commands/commandHelp.js +6 -0
- package/dist/cli/commands/commands.d.ts +8 -0
- package/dist/cli/commands/commands.js +13 -0
- package/dist/cli/commands/formatters.d.ts +1 -1
- package/dist/cli/commands/formatters.js +25 -3
- package/dist/cli/commands/logsCommand.js +21 -2
- package/dist/cli/commands/ndjsonSink.d.ts +12 -0
- package/dist/cli/commands/ndjsonSink.js +29 -0
- package/dist/cli/commands/reasoningCommand.d.ts +44 -0
- package/dist/cli/commands/reasoningCommand.js +79 -0
- package/dist/cli/commands/runCommand.d.ts +14 -0
- package/dist/cli/commands/runCommand.js +56 -22
- package/dist/cli/commands/settingsSummary.js +2 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +3 -0
- package/dist/cli/commands/streaming/agentAttempt.js +2 -2
- package/dist/cli/commands/streaming/assistantSegments.d.ts +0 -7
- package/dist/cli/commands/streaming/assistantSegments.js +1 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +13 -9
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +24 -9
- package/dist/cli/commands/streaming/attemptSetup.d.ts +4 -0
- package/dist/cli/commands/streaming/attemptSetup.js +21 -7
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +14 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +4 -2
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +9 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +51 -10
- package/dist/cli/commands/streaming/prepareStep.d.ts +0 -3
- package/dist/cli/commands/streaming/prepareStep.js +14 -5
- package/dist/cli/commands/streaming/streamLoop.d.ts +5 -0
- package/dist/cli/commands/streaming/streamLoop.js +3 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +6 -0
- package/dist/cli/commands/streaming.d.ts +8 -3
- package/dist/cli/commands/streaming.js +46 -21
- package/dist/cli/commands/wizardFlow.d.ts +10 -0
- package/dist/cli/commands/wizardFlow.js +34 -5
- package/dist/cli/index.js +22 -2
- package/dist/config/contextFiles.d.ts +9 -0
- package/dist/config/contextFiles.js +21 -1
- package/dist/config/modelCatalog.d.ts +3 -0
- package/dist/config/modelCatalog.js +29 -0
- package/dist/config/modelDiscovery.js +68 -5
- package/dist/config/providerPresets.d.ts +1 -1
- package/dist/config/providerPresets.js +42 -3
- package/dist/config/settings.d.ts +14 -6
- package/dist/config/settings.js +16 -1
- package/dist/core/agent/budgets.d.ts +13 -17
- package/dist/core/agent/budgets.js +15 -19
- package/dist/core/agent/completionController.d.ts +14 -2
- package/dist/core/agent/completionController.js +48 -3
- package/dist/core/agent/events.d.ts +2 -1
- package/dist/core/agent/goalPolicy.d.ts +17 -0
- package/dist/core/agent/goalPolicy.js +53 -6
- package/dist/core/agent/projectPreflight.d.ts +2 -0
- package/dist/core/agent/projectPreflight.js +56 -0
- package/dist/core/agent/reasoningPolicy.d.ts +76 -10
- package/dist/core/agent/reasoningPolicy.js +72 -9
- package/dist/core/agent/toolCapabilities.d.ts +3 -3
- package/dist/core/agent/toolCapabilities.js +31 -7
- package/dist/core/agent/workState.d.ts +14 -4
- package/dist/core/agent/workState.js +229 -34
- package/dist/core/deadline.js +22 -24
- package/dist/core/providerContracts.d.ts +29 -0
- package/dist/core/providerContracts.js +1 -0
- package/dist/core/safety/secretPaths.js +10 -7
- package/dist/core/safety/shellClassifier.d.ts +2 -0
- package/dist/core/safety/shellClassifier.js +9 -1
- package/dist/core/session/sessionReport.d.ts +33 -0
- package/dist/core/session/sessionReport.js +121 -0
- package/dist/core/session/sessionSlimming.d.ts +2 -0
- package/dist/core/session/sessionSlimming.js +59 -4
- package/dist/core/session/sessionStore.d.ts +16 -8
- package/dist/core/session/sessionStore.js +71 -34
- package/dist/core/shellOutput/reducers/git.js +7 -2
- package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
- package/dist/core/shellOutput/reducers/validation.js +14 -1
- package/dist/core/shellOutput/registry.js +3 -2
- package/dist/core/subagent/contracts.d.ts +3 -18
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/tasks/taskStorage.js +8 -1
- package/dist/core/validation/outputParser.d.ts +6 -1
- package/dist/core/validation/outputParser.js +30 -2
- package/dist/llm/client.d.ts +6 -3
- package/dist/llm/client.js +28 -11
- package/dist/llm/hazeTools.d.ts +9161 -7135
- package/dist/llm/hazeTools.js +6 -462
- package/dist/llm/lsp/client.d.ts +7 -1
- package/dist/llm/lsp/client.js +58 -9
- package/dist/llm/lsp/pool.d.ts +11 -0
- package/dist/llm/lsp/pool.js +61 -4
- package/dist/llm/lsp/protocol.d.ts +6 -23
- package/dist/llm/lsp/requests.d.ts +54 -60
- package/dist/llm/lsp/requests.js +152 -28
- package/dist/llm/lsp/symbols.d.ts +16 -0
- package/dist/llm/lsp/symbols.js +70 -0
- package/dist/llm/lsp/workspaceEdit.d.ts +43 -0
- package/dist/llm/lsp/workspaceEdit.js +117 -0
- package/dist/llm/lspTools.d.ts +7518 -2859
- package/dist/llm/lspTools.js +195 -110
- package/dist/llm/mcp.js +3 -0
- package/dist/llm/requestContext.d.ts +4 -3
- package/dist/llm/requestContext.js +9 -5
- package/dist/{core/subagent → llm}/subagentRunner.d.ts +13 -9
- package/dist/{core/subagent → llm}/subagentRunner.js +54 -49
- package/dist/llm/systemPrompt.d.ts +11 -1
- package/dist/llm/systemPrompt.js +4 -13
- package/dist/llm/tools/fetchTool.d.ts +34 -30
- package/dist/llm/tools/fileTools.d.ts +7768 -0
- package/dist/llm/tools/fileTools.js +510 -0
- package/dist/llm/tools/processTool.d.ts +34 -30
- package/dist/llm/tools/replaceInFiles.d.ts +105 -0
- package/dist/llm/tools/replaceInFiles.js +131 -0
- package/dist/llm/tools/shellTool.d.ts +34 -30
- package/dist/llm/tools/shellTool.js +8 -4
- package/dist/llm/tools/storedOutputTool.d.ts +4 -0
- package/dist/llm/tools/taskTool.d.ts +4 -0
- package/dist/llm/tools/toolContext.d.ts +3 -29
- package/dist/llm/tools/toolContext.js +56 -53
- package/dist/llm/tools/toolContextState.d.ts +40 -0
- package/dist/llm/tools/toolContextState.js +34 -0
- package/dist/llm/workerContext.d.ts +7 -0
- package/dist/llm/workerContext.js +18 -1
- package/dist/skills/SkillLoader.js +30 -4
- package/dist/skills/SkillRegistry.js +3 -3
- package/dist/skills/builder/SkillBuilder.js +3 -3
- package/dist/skills/confinement.d.ts +7 -0
- package/dist/skills/confinement.js +15 -0
- package/dist/ui/codeHighlight.js +4 -4
- package/dist/ui/components/MarkdownText.js +7 -8
- package/dist/ui/components/NativeIndicators.d.ts +15 -0
- package/dist/ui/components/NativeIndicators.js +32 -0
- package/dist/ui/components/StreamingMarkdownText.d.ts +9 -0
- package/dist/ui/components/StreamingMarkdownText.js +38 -0
- package/dist/ui/components/TextInput.d.ts +7 -2
- package/dist/ui/components/TextInput.js +103 -46
- package/dist/ui/components/WizardChoices.d.ts +18 -0
- package/dist/ui/components/WizardChoices.js +32 -0
- package/dist/ui/components/useInputSuggestions.js +18 -6
- package/dist/ui/inputBuffer.js +12 -6
- package/dist/ui/textGeometry.d.ts +14 -0
- package/dist/ui/textGeometry.js +31 -0
- package/dist/utils/buildInfo.js +29 -8
- package/dist/utils/fs.js +5 -1
- package/package.json +23 -22
- /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
- /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
package/dist/llm/lspTools.js
CHANGED
|
@@ -2,57 +2,110 @@ import path from 'node:path';
|
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { readSettings } from '../config/settings.js';
|
|
5
|
-
import { configuredLspServers } from '../config/lspSettings.js';
|
|
5
|
+
import { configuredLspServers, installedLspServers } from '../config/lspSettings.js';
|
|
6
6
|
import { pickLspServer } from './lsp/pool.js';
|
|
7
|
-
import { lspDefinition, lspDiagnostics, lspDocumentSymbols, lspImplementation, lspReferences, lspTypeDefinition, lspWorkspaceSymbols } from './lsp/requests.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
import { lspDefinition, lspDiagnostics, lspDiagnosticsForSymbol, lspDocumentSymbols, lspFindSymbols, lspImplementation, lspReferenceLocations, lspReferences, lspRename, lspTypeDefinition, lspWorkspaceSymbols } from './lsp/requests.js';
|
|
8
|
+
import { applyWorkspaceEdit } from './lsp/workspaceEdit.js';
|
|
9
|
+
import { hazeToolContextSchema, runDedupedTool } from './tools/toolContext.js';
|
|
10
|
+
import { prepareWorkspaceRead } from './tools/workspaceFile.js';
|
|
11
|
+
import { toUri } from './lsp/protocol.js';
|
|
12
12
|
function noServer(filePath) {
|
|
13
|
-
return
|
|
13
|
+
return `No enabled LSP server configured for ${path.extname(filePath) || 'this file type'}. Use /lsp presets and /lsp add <preset> to configure one.`;
|
|
14
|
+
}
|
|
15
|
+
function notInstalled(server, filePath) {
|
|
16
|
+
const scope = filePath ? ` for ${path.extname(filePath) || 'this file type'}` : '';
|
|
17
|
+
return `LSP server ${server.name} is enabled${scope} but its command "${server.command}" is not installed (not found on PATH). Install it or reconfigure via /lsp; fall back to grep/readFile meanwhile.`;
|
|
18
|
+
}
|
|
19
|
+
/** Resolve the server for a file: enabled for the extension and actually installed. */
|
|
20
|
+
async function serverFor(filePath) {
|
|
21
|
+
const settings = await readSettings();
|
|
22
|
+
const candidate = pickLspServer(configuredLspServers(settings).filter(server => server.enabled !== false), filePath);
|
|
23
|
+
if (!candidate)
|
|
24
|
+
return { ok: false, error: noServer(filePath) };
|
|
25
|
+
const installed = await installedLspServers(settings);
|
|
26
|
+
return installed.some(server => server.name === candidate.name) ? { ok: true, server: candidate } : { ok: false, error: notInstalled(candidate, filePath) };
|
|
14
27
|
}
|
|
28
|
+
/** Resolve a named server, or the first installed one when unnamed. */
|
|
15
29
|
async function namedOrFirstServer(name) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
const settings = await readSettings();
|
|
31
|
+
const enabled = configuredLspServers(settings).filter(server => server.enabled !== false);
|
|
32
|
+
if (name) {
|
|
33
|
+
const candidate = enabled.find(server => server.name === name);
|
|
34
|
+
if (!candidate)
|
|
35
|
+
return { ok: false, error: `No enabled LSP server named ${name}.` };
|
|
36
|
+
const installed = await installedLspServers(settings);
|
|
37
|
+
return installed.some(server => server.name === candidate.name) ? { ok: true, server: candidate } : { ok: false, error: notInstalled(candidate) };
|
|
38
|
+
}
|
|
39
|
+
const firstInstalled = (await installedLspServers(settings))[0];
|
|
40
|
+
if (firstInstalled)
|
|
41
|
+
return { ok: true, server: firstInstalled };
|
|
42
|
+
return { ok: false, error: enabled.length > 0 ? 'No enabled LSP server is installed (command not found on PATH). Install one or adjust /lsp.' : 'No enabled LSP server configured. Use /lsp add <preset>.' };
|
|
20
43
|
}
|
|
21
44
|
function cleanLspError(message) {
|
|
22
45
|
if (/No Project/i.test(message))
|
|
23
46
|
return 'LSP server reported no project for workspace-symbol search. Use grep/listFiles to find likely files, then try file-scoped lspSymbols on those files; fall back to readFile when needed.';
|
|
24
|
-
return message
|
|
25
|
-
.split('\n')
|
|
26
|
-
.filter(line => line.trim() && !/^\s*at\s/.test(line))
|
|
27
|
-
.slice(0, 2)
|
|
28
|
-
.join('\n');
|
|
47
|
+
return message.split('\n').filter(line => line.trim() && !/^\s*at\s/.test(line)).slice(0, 2).join('\n');
|
|
29
48
|
}
|
|
30
49
|
function lspFailure(error) {
|
|
31
|
-
|
|
32
|
-
return { ok: false, error: cleanLspError(message) };
|
|
50
|
+
return { ok: false, error: cleanLspError(error instanceof Error ? error.message : String(error)) };
|
|
33
51
|
}
|
|
52
|
+
const locationSchema = {
|
|
53
|
+
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
54
|
+
line: z.number().int().positive().describe('1-based line number'),
|
|
55
|
+
column: z.number().int().positive().describe('1-based column/character number'),
|
|
56
|
+
};
|
|
57
|
+
const symbolNameSchema = {
|
|
58
|
+
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
59
|
+
namePath: z.string().min(1).describe('Symbol name or hierarchical name path, such as Class/method'),
|
|
60
|
+
};
|
|
34
61
|
export const lspTools = buildLspTools();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
const AUTOMATIC_DIAGNOSTIC_FILE_LIMIT = 20;
|
|
63
|
+
const AUTOMATIC_DIAGNOSTIC_RESULT_LIMIT = 20;
|
|
64
|
+
/** Build the bounded diagnostics hook attached to successful file-mutation results. */
|
|
65
|
+
export function createPostMutationDiagnostics(servers, pool) {
|
|
66
|
+
return async (paths) => {
|
|
67
|
+
const uniquePaths = [...new Set(paths)];
|
|
68
|
+
const supported = uniquePaths.flatMap(filePath => {
|
|
69
|
+
const server = pickLspServer(servers, filePath);
|
|
70
|
+
return server ? [{ filePath, server }] : [];
|
|
71
|
+
});
|
|
72
|
+
if (supported.length === 0)
|
|
73
|
+
return undefined;
|
|
74
|
+
const files = [];
|
|
75
|
+
let remainingResults = AUTOMATIC_DIAGNOSTIC_RESULT_LIMIT;
|
|
76
|
+
for (const { filePath, server } of supported.slice(0, AUTOMATIC_DIAGNOSTIC_FILE_LIMIT)) {
|
|
77
|
+
if (remainingResults === 0)
|
|
78
|
+
break;
|
|
79
|
+
try {
|
|
80
|
+
const result = await lspDiagnostics(server, filePath, remainingResults, pool);
|
|
81
|
+
if (!result.ok) {
|
|
82
|
+
files.push({ ok: false, path: filePath, server: server.name, error: result.error });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
files.push({ ok: true, path: filePath, server: server.name, diagnostics: result.diagnostics });
|
|
86
|
+
remainingResults -= result.diagnostics.length;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
files.push({ ok: false, path: filePath, server: server.name, error: cleanLspError(error instanceof Error ? error.message : String(error)) });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const truncated = supported.length > files.length || remainingResults === 0;
|
|
93
|
+
return { ok: files.every(file => file.ok === true), files, truncated };
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Build the optional LSP tool set bound to one turn-scoped client pool. */
|
|
40
97
|
export function buildLspTools(pool) {
|
|
41
98
|
return {
|
|
42
99
|
lspWorkspaceSymbols: tool({
|
|
43
|
-
description: 'Use a configured language server to search workspace symbols by name. Read-only. Best first LSP tool when
|
|
44
|
-
inputSchema: z.object({
|
|
45
|
-
query: z.string().min(1).describe('Symbol name or prefix to search for'),
|
|
46
|
-
server: z.string().optional().describe('Optional configured LSP server name. If omitted, the first enabled server is used.'),
|
|
47
|
-
maxSymbols: z.number().int().positive().max(100).default(50).describe('Maximum symbols to return'),
|
|
48
|
-
}),
|
|
100
|
+
description: 'Use a configured language server to search workspace symbols by name. Read-only. Best first LSP tool when you do not know the defining file.',
|
|
101
|
+
inputSchema: z.object({ query: z.string().min(1), server: z.string().optional(), maxSymbols: z.number().int().positive().max(100).default(50) }),
|
|
49
102
|
execute: async ({ query, server: serverName, maxSymbols }) => {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
return
|
|
103
|
+
const resolved = await namedOrFirstServer(serverName);
|
|
104
|
+
if (!resolved.ok)
|
|
105
|
+
return resolved;
|
|
53
106
|
try {
|
|
54
|
-
const symbols = await lspWorkspaceSymbols(server, query, maxSymbols, pool);
|
|
55
|
-
return { ok: true, server: server.name, query, symbols, truncated: symbols.length >= maxSymbols };
|
|
107
|
+
const symbols = await lspWorkspaceSymbols(resolved.server, query, maxSymbols, pool);
|
|
108
|
+
return { ok: true, server: resolved.server.name, query, symbols, truncated: symbols.length >= maxSymbols };
|
|
56
109
|
}
|
|
57
110
|
catch (error) {
|
|
58
111
|
return lspFailure(error);
|
|
@@ -60,123 +113,137 @@ export function buildLspTools(pool) {
|
|
|
60
113
|
},
|
|
61
114
|
}),
|
|
62
115
|
lspSymbols: tool({
|
|
63
|
-
description: '
|
|
64
|
-
inputSchema: z.object({
|
|
65
|
-
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
66
|
-
maxSymbols: z.number().int().positive().max(200).default(80).describe('Maximum symbols to return'),
|
|
67
|
-
}),
|
|
116
|
+
description: 'List semantic symbols in a source file, including hierarchical name paths. Use lspFindSymbol for targeted body/signature retrieval.',
|
|
117
|
+
inputSchema: z.object({ path: z.string().min(1), maxSymbols: z.number().int().positive().max(200).default(80) }),
|
|
68
118
|
execute: async ({ path: filePath, maxSymbols }) => {
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
71
|
-
return
|
|
119
|
+
const resolved = await serverFor(filePath);
|
|
120
|
+
if (!resolved.ok)
|
|
121
|
+
return resolved;
|
|
72
122
|
try {
|
|
73
|
-
const symbols = await lspDocumentSymbols(server, filePath, maxSymbols, pool);
|
|
74
|
-
return { ok: true, server: server.name, path: filePath, symbols, truncated: symbols.length >= maxSymbols };
|
|
123
|
+
const symbols = await lspDocumentSymbols(resolved.server, filePath, maxSymbols, pool);
|
|
124
|
+
return { ok: true, server: resolved.server.name, path: filePath, symbols, truncated: symbols.length >= maxSymbols };
|
|
75
125
|
}
|
|
76
126
|
catch (error) {
|
|
77
127
|
return lspFailure(error);
|
|
78
128
|
}
|
|
79
129
|
},
|
|
80
130
|
}),
|
|
81
|
-
|
|
82
|
-
description: '
|
|
131
|
+
lspFindSymbol: tool({
|
|
132
|
+
description: 'Find a symbol by hierarchical name path. Can scope to a file/directory, retrieve children, exact body text, and hover/signature info.',
|
|
83
133
|
inputSchema: z.object({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
134
|
+
namePath: z.string().min(1),
|
|
135
|
+
path: z.string().optional().describe('Optional workspace-relative file or directory scope'),
|
|
136
|
+
depth: z.number().int().min(0).max(4).default(0),
|
|
137
|
+
includeBody: z.boolean().default(false),
|
|
138
|
+
includeInfo: z.boolean().default(false),
|
|
139
|
+
includeKinds: z.array(z.number().int().positive()).default([]),
|
|
140
|
+
excludeKinds: z.array(z.number().int().positive()).default([]),
|
|
141
|
+
substringMatching: z.boolean().default(false),
|
|
142
|
+
maxResults: z.number().int().positive().max(100).default(20),
|
|
88
143
|
}),
|
|
89
|
-
execute: async (
|
|
90
|
-
const
|
|
91
|
-
if (!
|
|
92
|
-
return
|
|
144
|
+
execute: async (input) => {
|
|
145
|
+
const resolved = input.path && path.extname(input.path) ? await serverFor(input.path) : await namedOrFirstServer();
|
|
146
|
+
if (!resolved.ok)
|
|
147
|
+
return resolved;
|
|
93
148
|
try {
|
|
94
|
-
const
|
|
95
|
-
return { ok: true, server: server.name,
|
|
149
|
+
const result = await lspFindSymbols(resolved.server, input.namePath, input, pool);
|
|
150
|
+
return { ok: true, server: resolved.server.name, ...result, truncated: result.symbols.length >= input.maxResults };
|
|
96
151
|
}
|
|
97
152
|
catch (error) {
|
|
98
153
|
return lspFailure(error);
|
|
99
154
|
}
|
|
100
155
|
},
|
|
101
156
|
}),
|
|
157
|
+
lspDefinition: locationTool('Find the definition at a 1-based source position.', 'definition', lspDefinition, pool),
|
|
158
|
+
lspTypeDefinition: locationTool('Find the type definition at a 1-based source position.', 'type definition', lspTypeDefinition, pool),
|
|
159
|
+
lspImplementation: locationTool('Find implementations at a 1-based source position.', 'implementations', lspImplementation, pool, 100),
|
|
102
160
|
lspReferences: tool({
|
|
103
|
-
description: '
|
|
104
|
-
inputSchema: z.object({
|
|
105
|
-
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
106
|
-
line: z.number().int().positive().describe('1-based line number'),
|
|
107
|
-
column: z.number().int().positive().describe('1-based column/character number'),
|
|
108
|
-
maxResults: z.number().int().positive().max(100).default(50).describe('Maximum locations to return'),
|
|
109
|
-
}),
|
|
161
|
+
description: 'Find references and return each location with its enclosing symbol and a compact source snippet.',
|
|
162
|
+
inputSchema: z.object({ ...locationSchema, maxResults: z.number().int().positive().max(100).default(50) }),
|
|
110
163
|
execute: async ({ path: filePath, line, column, maxResults }) => {
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
113
|
-
return
|
|
164
|
+
const resolved = await serverFor(filePath);
|
|
165
|
+
if (!resolved.ok)
|
|
166
|
+
return resolved;
|
|
114
167
|
try {
|
|
115
|
-
const
|
|
116
|
-
return { ok: true, server: server.name, path: filePath, locations, truncated:
|
|
168
|
+
const references = await lspReferences(resolved.server, filePath, line, column, maxResults, pool);
|
|
169
|
+
return { ok: true, server: resolved.server.name, path: filePath, references, locations: references, truncated: references.length >= maxResults };
|
|
117
170
|
}
|
|
118
171
|
catch (error) {
|
|
119
172
|
return lspFailure(error);
|
|
120
173
|
}
|
|
121
174
|
},
|
|
122
175
|
}),
|
|
123
|
-
|
|
124
|
-
description: '
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
execute: async ({ path: filePath, line, column, maxResults }) => {
|
|
132
|
-
const server = await serverFor(filePath);
|
|
133
|
-
if (!server)
|
|
134
|
-
return noServer(filePath);
|
|
176
|
+
lspRenameSymbol: tool({
|
|
177
|
+
description: 'Rename one symbol across the workspace using the language server. Resolves the symbol by name path immediately before applying the workspace edit.',
|
|
178
|
+
contextSchema: hazeToolContextSchema,
|
|
179
|
+
inputSchema: z.object({ ...symbolNameSchema, newName: z.string().min(1) }),
|
|
180
|
+
execute: async (input, context) => await runDedupedTool('lspRenameSymbol', input, context, async () => {
|
|
181
|
+
const resolved = await serverFor(input.path);
|
|
182
|
+
if (!resolved.ok)
|
|
183
|
+
return resolved;
|
|
135
184
|
try {
|
|
136
|
-
const
|
|
137
|
-
|
|
185
|
+
const found = await lspFindSymbols(resolved.server, input.namePath, { path: input.path, depth: 0, includeBody: false, includeInfo: false, includeKinds: [], excludeKinds: [], substringMatching: false, maxResults: 2 }, pool);
|
|
186
|
+
if (found.symbols.length !== 1)
|
|
187
|
+
return { ok: false, error: `Expected one symbol named ${input.namePath}, found ${found.symbols.length}.` };
|
|
188
|
+
const position = found.symbols[0].selectionRange?.start ?? found.symbols[0].range.start;
|
|
189
|
+
return await applyWorkspaceEdit('lspRenameSymbol', await lspRename(resolved.server, input.path, position.line, position.character, input.newName, pool), context);
|
|
138
190
|
}
|
|
139
191
|
catch (error) {
|
|
140
192
|
return lspFailure(error);
|
|
141
193
|
}
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
lspImplementation: tool({
|
|
145
|
-
description: 'Use a configured language server to find implementations of an interface, abstract member, or generic signature at a 1-based line/column. Read-only.',
|
|
146
|
-
inputSchema: z.object({
|
|
147
|
-
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
148
|
-
line: z.number().int().positive().describe('1-based line number'),
|
|
149
|
-
column: z.number().int().positive().describe('1-based column/character number'),
|
|
150
|
-
maxResults: z.number().int().positive().max(100).default(50).describe('Maximum locations to return'),
|
|
151
194
|
}),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
}),
|
|
196
|
+
lspSafeDeleteSymbol: tool({
|
|
197
|
+
description: 'Delete a symbol only when the language server reports no references. Otherwise returns the blocking reference locations without editing.',
|
|
198
|
+
contextSchema: hazeToolContextSchema,
|
|
199
|
+
inputSchema: z.object(symbolNameSchema),
|
|
200
|
+
execute: async (input, context) => await runDedupedTool('lspSafeDeleteSymbol', input, context, async () => {
|
|
201
|
+
const resolved = await serverFor(input.path);
|
|
202
|
+
if (!resolved.ok)
|
|
203
|
+
return resolved;
|
|
156
204
|
try {
|
|
157
|
-
const
|
|
158
|
-
|
|
205
|
+
const found = await lspFindSymbols(resolved.server, input.namePath, { path: input.path, depth: 0, includeBody: false, includeInfo: false, includeKinds: [], excludeKinds: [], substringMatching: false, maxResults: 2 }, pool);
|
|
206
|
+
if (found.symbols.length !== 1)
|
|
207
|
+
return { ok: false, error: `Expected one symbol named ${input.namePath}, found ${found.symbols.length}.` };
|
|
208
|
+
const symbol = found.symbols[0];
|
|
209
|
+
const position = symbol.selectionRange?.start ?? symbol.range.start;
|
|
210
|
+
const references = await lspReferenceLocations(resolved.server, input.path, position.line, position.character, false, 100, pool);
|
|
211
|
+
if (references.length > 0)
|
|
212
|
+
return { ok: false, error: `Cannot delete ${symbol.namePath}: ${references.length} reference(s) remain.`, references, recoverable: true, suggestedNextStep: 'Remove or migrate the references, then retry safe delete.' };
|
|
213
|
+
const absolutePath = await prepareWorkspaceRead(input.path, false, context);
|
|
214
|
+
const range = { start: { line: symbol.range.start.line - 1, character: symbol.range.start.character - 1 }, end: { line: symbol.range.end.line - 1, character: symbol.range.end.character - 1 } };
|
|
215
|
+
return await applyWorkspaceEdit('lspSafeDeleteSymbol', { changes: { [toUri(absolutePath)]: [{ range, newText: '' }] } }, context);
|
|
159
216
|
}
|
|
160
217
|
catch (error) {
|
|
161
218
|
return lspFailure(error);
|
|
162
219
|
}
|
|
163
|
-
},
|
|
220
|
+
}),
|
|
164
221
|
}),
|
|
165
222
|
lspDiagnostics: tool({
|
|
166
|
-
description: '
|
|
167
|
-
inputSchema: z.object({
|
|
168
|
-
path: z.string().min(1).describe('Workspace-relative source file path'),
|
|
169
|
-
maxResults: z.number().int().positive().max(100).default(50).describe('Maximum diagnostics to return'),
|
|
170
|
-
}),
|
|
223
|
+
description: 'Get diagnostics for one source file. Successful file-mutation results already include automatic diagnostics for supported files; call this only when a fresh standalone check is needed. Prefer the relevant build/test command for authoritative validation.',
|
|
224
|
+
inputSchema: z.object({ path: z.string().min(1), maxResults: z.number().int().positive().max(100).default(50) }),
|
|
171
225
|
execute: async ({ path: filePath, maxResults }) => {
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
return
|
|
226
|
+
const resolved = await serverFor(filePath);
|
|
227
|
+
if (!resolved.ok)
|
|
228
|
+
return resolved;
|
|
175
229
|
try {
|
|
176
|
-
const result = await lspDiagnostics(server, filePath, maxResults, pool);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
230
|
+
const result = await lspDiagnostics(resolved.server, filePath, maxResults, pool);
|
|
231
|
+
return result.ok ? { ok: true, server: resolved.server.name, path: filePath, diagnostics: result.diagnostics, truncated: result.diagnostics.length >= maxResults } : result;
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
return lspFailure(error);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
lspDiagnosticsForSymbol: tool({
|
|
239
|
+
description: 'Get diagnostics owned by a symbol and optionally by symbols that reference it. This is a focused intermediate check, not a replacement for tests/typecheck.',
|
|
240
|
+
inputSchema: z.object({ ...symbolNameSchema, checkReferences: z.boolean().default(false), maxResults: z.number().int().positive().max(100).default(50) }),
|
|
241
|
+
execute: async ({ path: filePath, namePath, checkReferences, maxResults }) => {
|
|
242
|
+
const resolved = await serverFor(filePath);
|
|
243
|
+
if (!resolved.ok)
|
|
244
|
+
return resolved;
|
|
245
|
+
try {
|
|
246
|
+
return { ok: true, server: resolved.server.name, path: filePath, groups: await lspDiagnosticsForSymbol(resolved.server, filePath, namePath, checkReferences, maxResults, pool) };
|
|
180
247
|
}
|
|
181
248
|
catch (error) {
|
|
182
249
|
return lspFailure(error);
|
|
@@ -185,3 +252,21 @@ export function buildLspTools(pool) {
|
|
|
185
252
|
}),
|
|
186
253
|
};
|
|
187
254
|
}
|
|
255
|
+
function locationTool(description, label, request, pool, max = 50) {
|
|
256
|
+
return tool({
|
|
257
|
+
description,
|
|
258
|
+
inputSchema: z.object({ ...locationSchema, maxResults: z.number().int().positive().max(max).default(Math.min(20, max)) }),
|
|
259
|
+
execute: async ({ path: filePath, line, column, maxResults }) => {
|
|
260
|
+
const resolved = await serverFor(filePath);
|
|
261
|
+
if (!resolved.ok)
|
|
262
|
+
return resolved;
|
|
263
|
+
try {
|
|
264
|
+
const locations = await request(resolved.server, filePath, line, column, maxResults, pool);
|
|
265
|
+
return { ok: true, server: resolved.server.name, path: filePath, locations, truncated: locations.length >= maxResults, query: label };
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
return lspFailure(error);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
}
|
package/dist/llm/mcp.js
CHANGED
|
@@ -84,6 +84,9 @@ export async function loadMcpTools(servers, reserved = new Set(), signal) {
|
|
|
84
84
|
errors.push(`${result.server.name}: skipped tool "${name}" (name already in use)`);
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
87
|
+
// MCP tool schemas are discovered at runtime. The MCP package's schema
|
|
88
|
+
// generic is wider than the core AI SDK ToolSet generic, although both
|
|
89
|
+
// expose the same runtime tool contract here.
|
|
87
90
|
taken.add(name);
|
|
88
91
|
tools[name] = toolDef;
|
|
89
92
|
}
|
|
@@ -6,8 +6,9 @@ import { type ModelRuntimeSelection } from './client.js';
|
|
|
6
6
|
import { SubagentCoordinator, type CoordinatorEvent } from '../core/subagent/subagentCoordinator.js';
|
|
7
7
|
import { WorkspaceMutationPolicy } from '../core/subagent/workspaceMutationPolicy.js';
|
|
8
8
|
import { type LoadedMcpTools } from './mcp.js';
|
|
9
|
-
import { createSubagentTool } from '
|
|
9
|
+
import { createSubagentTool } from './subagentRunner.js';
|
|
10
10
|
import type { ContextFile } from '../config/contextFiles.js';
|
|
11
|
+
import type { PostMutationDiagnostics } from './tools/toolContext.js';
|
|
11
12
|
export type ToolCategory = 'builtin' | 'lsp' | 'skill' | 'subagent' | 'mcp';
|
|
12
13
|
/** Model type accepted by the subagent tool; derived so this module stays decoupled. */
|
|
13
14
|
export type RequestModel = NonNullable<Parameters<typeof createSubagentTool>[0]['model']>;
|
|
@@ -21,8 +22,6 @@ export interface TurnExecutionScope {
|
|
|
21
22
|
coordinator: SubagentCoordinator;
|
|
22
23
|
mutationPolicy: WorkspaceMutationPolicy;
|
|
23
24
|
}
|
|
24
|
-
/** Keep the common coding path lean while preserving explicitly relevant capabilities. */
|
|
25
|
-
export declare function selectToolsForRequest(tools: ToolSet, request?: string): ToolSet;
|
|
26
25
|
export interface AssembledRequestContext {
|
|
27
26
|
systemPrompt: string;
|
|
28
27
|
availableTools: ToolSet;
|
|
@@ -31,6 +30,8 @@ export interface AssembledRequestContext {
|
|
|
31
30
|
loadedMcp?: LoadedMcpTools;
|
|
32
31
|
/** Turn-scoped LSP client pool; callers close it once the turn/context is done. */
|
|
33
32
|
lspPool?: LspPool;
|
|
33
|
+
/** Bounded automatic diagnostics attached to successful file-mutation results. */
|
|
34
|
+
postMutationDiagnostics?: PostMutationDiagnostics;
|
|
34
35
|
executionScope: TurnExecutionScope;
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hazeTools } from './hazeTools.js';
|
|
2
|
-
import { buildLspTools } from './lspTools.js';
|
|
2
|
+
import { buildLspTools, createPostMutationDiagnostics } from './lspTools.js';
|
|
3
3
|
import { LspPool } from './lsp/pool.js';
|
|
4
4
|
import { buildSystemPrompt } from './systemPrompt.js';
|
|
5
5
|
import { readSettings } from '../config/settings.js';
|
|
@@ -14,11 +14,11 @@ import { loadMcpTools } from './mcp.js';
|
|
|
14
14
|
import { loadSkillRegistry } from '../skills/SkillRegistry.js';
|
|
15
15
|
import { buildSkillTools } from '../skills/skillTools.js';
|
|
16
16
|
import { isSkillEnabled } from '../config/skillSettings.js';
|
|
17
|
-
import { createSubagentTool } from '
|
|
17
|
+
import { createSubagentTool } from './subagentRunner.js';
|
|
18
18
|
import { addCapabilityTools } from './capabilities.js';
|
|
19
19
|
const ALWAYS_AVAILABLE_TOOLS = new Set(['listFiles', 'readFile', 'grep', 'replaceLines', 'writeFile', 'editFile', 'shell', 'writeTasks', 'readToolOutput', 'skill']);
|
|
20
20
|
/** Keep the common coding path lean while preserving explicitly relevant capabilities. */
|
|
21
|
-
|
|
21
|
+
function selectToolsForRequest(tools, request) {
|
|
22
22
|
if (request === undefined)
|
|
23
23
|
return tools;
|
|
24
24
|
const lower = request.toLowerCase();
|
|
@@ -56,7 +56,8 @@ export async function assembleRequestContext(input) {
|
|
|
56
56
|
if (!isSkillEnabled(settings, name, skill.source))
|
|
57
57
|
enabledSkills.delete(name);
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const installedLsp = await installedLspServers(settings);
|
|
60
|
+
const hasInstalledLsp = installedLsp.length > 0;
|
|
60
61
|
const profileName = input.subagentOverrides?.profile ?? settings.subagents?.defaultProfile;
|
|
61
62
|
const profile = resolveExecutionProfile(profileName, settings.subagents?.profiles, input.subagentOverrides?.maxConcurrency);
|
|
62
63
|
const executionScope = input.executionScope ?? {
|
|
@@ -106,5 +107,8 @@ export async function assembleRequestContext(input) {
|
|
|
106
107
|
const skillErrors = (skillRegistry.errors ?? []).map(error => `${error.source ? `${error.source}/` : ''}${error.directory}: ${error.message}`);
|
|
107
108
|
const model = input.modelRuntime?.config ? { provider: input.modelRuntime.config.providerName, name: input.modelRuntime.config.modelName } : undefined;
|
|
108
109
|
const systemPrompt = `${buildSystemPrompt(input.contextFiles, input.session, { lspAvailable: hasInstalledLsp, mcpAvailable, model, availableTools: new Set(Object.keys(availableTools)) })}${skillErrors.length ? `\n\n<skill-load-errors>\nInvalid skills were isolated:\n${skillErrors.map(error => `- ${error}`).join('\n')}\n</skill-load-errors>` : ''}`;
|
|
109
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
systemPrompt, availableTools, toolCategories, loadedMcp, lspPool, executionScope,
|
|
112
|
+
...(lspPool ? { postMutationDiagnostics: createPostMutationDiagnostics(installedLsp, lspPool) } : {}),
|
|
113
|
+
};
|
|
110
114
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { ContextFile } from '
|
|
2
|
-
import { toolOnlyStepCount } from '../agent/turnPolicy.js';
|
|
3
|
-
import { type
|
|
4
|
-
import type
|
|
5
|
-
import { type
|
|
6
|
-
import { type
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import type { ContextFile } from '../config/contextFiles.js';
|
|
2
|
+
import { toolOnlyStepCount } from '../core/agent/turnPolicy.js';
|
|
3
|
+
import { type HazeToolContext } from './tools/toolContext.js';
|
|
4
|
+
import { type WorkerContextBundle } from './workerContext.js';
|
|
5
|
+
import { type SubagentExecutionResult, type SubagentTaskCapsule, type WorkerRuntime } from '../core/subagent/contracts.js';
|
|
6
|
+
import { type SubagentExecutionProfile } from '../core/subagent/executionProfiles.js';
|
|
7
|
+
import { SubagentCoordinator } from '../core/subagent/subagentCoordinator.js';
|
|
8
|
+
import { WorkspaceMutationPolicy } from '../core/subagent/workspaceMutationPolicy.js';
|
|
9
|
+
import { type PromptSession } from './systemPrompt.js';
|
|
10
10
|
type SubagentStep = {
|
|
11
11
|
toolCalls: unknown[];
|
|
12
12
|
text: string;
|
|
@@ -43,6 +43,7 @@ export declare function createSubagentTool(options: {
|
|
|
43
43
|
contextFiles?: ContextFile[];
|
|
44
44
|
session?: PromptSession;
|
|
45
45
|
}): ({
|
|
46
|
+
deferLoading?: boolean;
|
|
46
47
|
title?: string;
|
|
47
48
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
48
49
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -124,6 +125,7 @@ export declare function createSubagentTool(options: {
|
|
|
124
125
|
acceptanceCriteria?: string[] | undefined;
|
|
125
126
|
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
126
127
|
}) | ({
|
|
128
|
+
deferLoading?: boolean;
|
|
127
129
|
title?: string;
|
|
128
130
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
129
131
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -205,6 +207,7 @@ export declare function createSubagentTool(options: {
|
|
|
205
207
|
acceptanceCriteria?: string[] | undefined;
|
|
206
208
|
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
207
209
|
}) | ({
|
|
210
|
+
deferLoading?: boolean;
|
|
208
211
|
title?: string;
|
|
209
212
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
210
213
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -275,6 +278,7 @@ export declare function createSubagentTool(options: {
|
|
|
275
278
|
acceptanceCriteria?: string[] | undefined;
|
|
276
279
|
}, SubagentExecutionResult, NoInfer<HazeToolContext>>;
|
|
277
280
|
}) | ({
|
|
281
|
+
deferLoading?: boolean;
|
|
278
282
|
title?: string;
|
|
279
283
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
280
284
|
metadata?: import("@ai-sdk/provider").JSONObject;
|