@denizokcu/haze 0.9.0 → 0.11.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 +133 -17
- package/README.md +164 -68
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +46 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +92 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -2
- package/dist/cli/chat/messages.js +216 -33
- package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
- package/dist/cli/chat/sessionLifecycle.js +205 -0
- package/dist/cli/chat/sessionRecorder.js +80 -14
- package/dist/cli/chat/startupInfo.js +11 -4
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +744 -0
- package/dist/cli/commands/chat.d.ts +6 -0
- package/dist/cli/commands/chat.js +373 -790
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +5 -2
- package/dist/cli/commands/commands.js +22 -18
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +35 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +10 -2
- package/dist/cli/commands/providerWizard.js +50 -4
- package/dist/cli/commands/runCommand.d.ts +4 -0
- package/dist/cli/commands/runCommand.js +142 -16
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
- package/dist/cli/commands/streaming/turnOutcome.js +27 -11
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +82 -3
- package/dist/cli/commands/streaming.js +528 -91
- package/dist/cli/commands/wizardActions.d.ts +7 -0
- package/dist/cli/commands/wizardActions.js +7 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +64 -14
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +82 -22
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +71 -0
- package/dist/config/modelDiscovery.js +214 -0
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +49 -5
- package/dist/config/providerPresets.js +573 -73
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +9 -0
- package/dist/config/settings.d.ts +58 -0
- package/dist/config/settings.js +38 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +36 -0
- package/dist/core/agent/budgets.js +44 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +108 -19
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +46 -0
- package/dist/core/agent/contextBudget.js +89 -7
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +86 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
- package/dist/core/agent/toolExecutionBudget.js +49 -0
- package/dist/core/agent/toolOutputStore.d.ts +13 -0
- package/dist/core/agent/toolOutputStore.js +27 -10
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnBudget.d.ts +35 -0
- package/dist/core/agent/turnBudget.js +27 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +76 -1
- package/dist/core/agent/workState.js +120 -13
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/deadline.d.ts +33 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/goal/completionPolicy.d.ts +27 -0
- package/dist/core/goal/completionPolicy.js +37 -1
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +7 -0
- package/dist/core/limits/byteBudgets.js +7 -0
- package/dist/core/limits/textBudgets.d.ts +25 -0
- package/dist/core/limits/textBudgets.js +25 -0
- package/dist/core/log/llmLog.js +7 -0
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +195 -0
- package/dist/core/process/runBoundedProcess.d.ts +9 -0
- package/dist/core/process/runBoundedProcess.js +74 -29
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +74 -0
- package/dist/core/session/sessionStore.js +268 -18
- package/dist/core/subagent/contracts.d.ts +120 -0
- package/dist/core/subagent/contracts.js +55 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
- package/dist/core/subagent/subagentCoordinator.js +164 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +208 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +36 -29
- package/dist/llm/client.js +102 -33
- package/dist/llm/hazeTools.d.ts +2559 -150
- package/dist/llm/hazeTools.js +119 -31
- package/dist/llm/lsp.d.ts +26 -4
- package/dist/llm/lsp.js +90 -14
- package/dist/llm/lspTools.d.ts +2366 -0
- package/dist/llm/lspTools.js +87 -79
- package/dist/llm/openaiCodex.d.ts +3 -0
- package/dist/llm/openaiCodex.js +47 -0
- package/dist/llm/openaiCodexOAuth.d.ts +54 -0
- package/dist/llm/openaiCodexOAuth.js +214 -0
- package/dist/llm/requestContext.d.ts +25 -1
- package/dist/llm/requestContext.js +51 -8
- package/dist/llm/systemPrompt.d.ts +15 -1
- package/dist/llm/systemPrompt.js +24 -8
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +906 -32
- package/dist/llm/tools/bashTool.js +30 -4
- package/dist/llm/tools/editMatch.d.ts +14 -0
- package/dist/llm/tools/editMatch.js +72 -0
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +42 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +6 -4
- package/dist/llm/tools/fileToolShared.js +18 -23
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/readRecovery.d.ts +10 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/toolContext.d.ts +9 -1
- package/dist/llm/tools/toolContext.js +83 -43
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +66 -86
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -1
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +12 -2
- package/dist/ui/components/TextInput.js +80 -8
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +104 -0
- package/dist/utils/buildInfo.js +253 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +9 -1
- package/dist/utils/fs.js +87 -29
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +22 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +5 -1
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +24 -19
package/dist/llm/hazeTools.js
CHANGED
|
@@ -12,15 +12,30 @@ import { reductionMetrics } from '../core/toolOutput/reduction.js';
|
|
|
12
12
|
import { HazeToolError, structuredToolFailure } from './tools/failures.js';
|
|
13
13
|
import { compactGrepMatches, renderGrepMatches } from './tools/outputCap.js';
|
|
14
14
|
import { parseRipgrepJsonStream } from './tools/grepParse.js';
|
|
15
|
-
import { findEditRange, splitDiffLines, lineNumberAtOffset, replacementDiff } from './tools/editMatch.js';
|
|
15
|
+
import { boundedDiff, fileDiff, findEditRange, splitDiffLines, lineNumberAtOffset, renderToolDiff, replacementDiff } from './tools/editMatch.js';
|
|
16
16
|
import { runDedupedTool, discoverScopedContext, withScopedContext, hazeToolContextSchema } from './tools/toolContext.js';
|
|
17
17
|
import { prepareWorkspaceMutation, prepareWorkspaceRead, prepareWorkspaceWritePath } from './tools/workspaceFile.js';
|
|
18
18
|
import { fetchTool } from './tools/fetchTool.js';
|
|
19
19
|
import { bashTool } from './tools/bashTool.js';
|
|
20
|
-
import {
|
|
20
|
+
import { processTool } from './tools/processTool.js';
|
|
21
|
+
import { DEFAULT_READ_LINES, INLINE_DIFF_LINE_LIMIT, MAX_OUTPUT_CHARS, sourceOutlineEntries } from './tools/fileToolShared.js';
|
|
22
|
+
import { createIgnoreClassifier } from './tools/gitIgnore.js';
|
|
21
23
|
import { runRipgrepBounded } from './tools/grepRunner.js';
|
|
22
24
|
import { EXACT_MUTATION_BYTES } from '../core/limits/byteBudgets.js';
|
|
25
|
+
import { WRITE_FILE_CHUNK_BYTES } from '../core/agent/budgets.js';
|
|
23
26
|
import { readUtf8LinesPage, readUtf8Prefix } from '../core/io/boundedRead.js';
|
|
27
|
+
import { assertReadableTextFile, readFailureRecovery } from './tools/readRecovery.js';
|
|
28
|
+
function mutationDiffFields(filePath, fullDiff) {
|
|
29
|
+
const preview = boundedDiff(fullDiff, INLINE_DIFF_LINE_LIMIT);
|
|
30
|
+
const diffHandle = preview.truncated ? storeToolOutput(renderToolDiff(filePath, fullDiff)) : undefined;
|
|
31
|
+
return {
|
|
32
|
+
diffLineCount: fullDiff.length,
|
|
33
|
+
diff: preview.diff,
|
|
34
|
+
diffTruncated: preview.truncated,
|
|
35
|
+
diffOmittedLines: preview.omittedLines,
|
|
36
|
+
...(diffHandle ? { diffHandle } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
24
39
|
export const hazeTools = {
|
|
25
40
|
listFiles: tool({
|
|
26
41
|
description: 'List workspace files/directories with pagination. Prefer this to bash for discovery.',
|
|
@@ -35,16 +50,18 @@ export const hazeTools = {
|
|
|
35
50
|
}),
|
|
36
51
|
execute: async ({ path: dirPath, recursive, maxEntries, cursor, includeIgnored, includeSizes }, context) => runDedupedTool('listFiles', { path: dirPath, recursive, maxEntries, cursor, includeIgnored, includeSizes }, context, async () => {
|
|
37
52
|
try {
|
|
38
|
-
const absolutePath = await prepareWorkspaceRead(dirPath, includeIgnored);
|
|
53
|
+
const absolutePath = await prepareWorkspaceRead(dirPath, includeIgnored, context);
|
|
39
54
|
const entries = [];
|
|
40
55
|
let ignoredSkipped = 0;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
// One persistent classifier owns the whole listing so a frontier of
|
|
57
|
+
// candidates collapses to O(visited directories) Git subprocesses
|
|
58
|
+
// instead of one process per walked entry (RH-001). Page-2 cursor
|
|
59
|
+
// resumes do not re-check entries preceding the cursor.
|
|
60
|
+
const ignoreBatch = includeIgnored ? undefined : (relativePaths) => createIgnoreClassifier(workspaceRoot()).classify(relativePaths).then(ignored => {
|
|
61
|
+
ignoredSkipped += ignored.size;
|
|
62
|
+
return ignored;
|
|
63
|
+
});
|
|
64
|
+
const walked = await walkDir(absolutePath, { recursive, maxEntries: maxEntries + 1, cursor, ignoreBatch });
|
|
48
65
|
const page = walked.slice(0, maxEntries);
|
|
49
66
|
const hasMore = walked.length > maxEntries;
|
|
50
67
|
for (const entry of page) {
|
|
@@ -81,10 +98,14 @@ export const hazeTools = {
|
|
|
81
98
|
}),
|
|
82
99
|
execute: async ({ path: filePath, offset, limit, mode, allowIgnored }, context) => runDedupedTool('readFile', { path: filePath, offset, limit, mode, allowIgnored }, context, async () => {
|
|
83
100
|
try {
|
|
84
|
-
const absolutePath = await prepareWorkspaceRead(filePath, allowIgnored);
|
|
101
|
+
const absolutePath = await prepareWorkspaceRead(filePath, allowIgnored, context);
|
|
102
|
+
await assertReadableTextFile(absolutePath, filePath);
|
|
85
103
|
const start = offset == null ? 0 : offset - 1;
|
|
86
104
|
const pageLimit = limit ?? DEFAULT_READ_LINES;
|
|
87
105
|
const page = await readUtf8LinesPage(absolutePath, start + 1, pageLimit);
|
|
106
|
+
if (offset != null && offset > page.totalLines) {
|
|
107
|
+
throw new HazeToolError(`offset ${offset} is beyond end of file (${page.totalLines} lines)`, 'invalid_line_range', { recoveryTool: 'readFile', recoveryInput: { path: filePath, offset: Math.max(1, page.totalLines) } });
|
|
108
|
+
}
|
|
88
109
|
const lines = page.lines;
|
|
89
110
|
const totalLines = page.totalLines;
|
|
90
111
|
const requestedEnd = Math.min(totalLines, start + pageLimit);
|
|
@@ -118,9 +139,16 @@ export const hazeTools = {
|
|
|
118
139
|
const endLine = mode === 'outline'
|
|
119
140
|
? displayLines[Math.max(0, includedLines - 1)]?.lineNumber ?? start + 1
|
|
120
141
|
: start + includedLines;
|
|
142
|
+
const outlineDroppedEntries = mode === 'outline' ? displayLines.length - includedLines : 0;
|
|
121
143
|
const hasMore = mode === 'outline'
|
|
122
|
-
? requestedEnd < totalLines
|
|
144
|
+
? requestedEnd < totalLines || outlineDroppedEntries > 0
|
|
123
145
|
: endLine < totalLines;
|
|
146
|
+
// Outline pages resume after the last *included* entry: the output cap can
|
|
147
|
+
// stop a page before requestedEnd, and jumping to requestedEnd + 1 would
|
|
148
|
+
// silently skip the entries in between (CR-028).
|
|
149
|
+
const nextOffset = hasMore
|
|
150
|
+
? (mode === 'outline' && includedLines > 0 ? endLine + 1 : requestedEnd + 1)
|
|
151
|
+
: undefined;
|
|
124
152
|
const scopedContext = await discoverScopedContext(filePath, context);
|
|
125
153
|
return withScopedContext({
|
|
126
154
|
path: filePath,
|
|
@@ -129,14 +157,15 @@ export const hazeTools = {
|
|
|
129
157
|
endLine,
|
|
130
158
|
totalLines,
|
|
131
159
|
content: numberedLines.join('\n'),
|
|
132
|
-
nextOffset
|
|
160
|
+
nextOffset,
|
|
133
161
|
truncated: hasMore || lineTruncated,
|
|
134
162
|
lineTruncated,
|
|
135
|
-
...(mode === 'outline' ? { outline: true, outlineEntries: includedLines, warning: 'Outline mode is lossy discovery output. Use exact readFile around relevant lines before editing.' } : {}),
|
|
163
|
+
...(mode === 'outline' ? { outline: true, outlineEntries: includedLines, ...(outlineDroppedEntries > 0 ? { outlineDroppedEntries } : {}), warning: 'Outline mode is lossy discovery output. Use exact readFile around relevant lines before editing.' } : {}),
|
|
136
164
|
}, scopedContext);
|
|
137
165
|
}
|
|
138
166
|
catch (error) {
|
|
139
|
-
|
|
167
|
+
const recovery = await readFailureRecovery(filePath, error);
|
|
168
|
+
return structuredToolFailure('readFile', error, recovery.suggestedNextStep, filePath, { reasonCode: recovery.reasonCode, suggestedPaths: recovery.suggestedPaths });
|
|
140
169
|
}
|
|
141
170
|
}),
|
|
142
171
|
}),
|
|
@@ -148,13 +177,13 @@ export const hazeTools = {
|
|
|
148
177
|
path: z.string().default('.').describe('Workspace-relative file or directory'),
|
|
149
178
|
glob: z.string().optional().describe('Optional file glob, e.g. "*.ts"'),
|
|
150
179
|
contextLines: z.number().int().nonnegative().max(5).default(2).describe('Context lines before/after each match'),
|
|
151
|
-
maxMatches: z.number().int().positive().max(200).default(50).describe('Global match limit'),
|
|
180
|
+
maxMatches: z.number().int().positive().max(200).default(50).describe('Global match limit (enforced by the runner; ripgrep also applies it as a per-file cap)'),
|
|
152
181
|
caseInsensitive: z.boolean().default(false).describe('Ignore case'),
|
|
153
182
|
includeIgnored: z.boolean().default(false).describe('Search ignored paths only when explicitly needed'),
|
|
154
183
|
}),
|
|
155
184
|
execute: async ({ pattern, path: searchPath, glob, contextLines, maxMatches, caseInsensitive, includeIgnored }, context) => runDedupedTool('grep', { pattern, path: searchPath, glob, contextLines, maxMatches, caseInsensitive, includeIgnored }, context, async () => {
|
|
156
185
|
try {
|
|
157
|
-
const absolutePath = await prepareWorkspaceRead(searchPath, includeIgnored);
|
|
186
|
+
const absolutePath = await prepareWorkspaceRead(searchPath, includeIgnored, context);
|
|
158
187
|
const args = [
|
|
159
188
|
'--json', '--color=never',
|
|
160
189
|
'--max-count', String(maxMatches),
|
|
@@ -257,10 +286,23 @@ export const hazeTools = {
|
|
|
257
286
|
lines.splice(startLine - 1, effectiveEndLine - startLine + 1, ...replacementLines);
|
|
258
287
|
}
|
|
259
288
|
const updated = lines.join('\n') + (hasTrailingNewline ? '\n' : '');
|
|
260
|
-
const
|
|
261
|
-
const
|
|
289
|
+
const replacement = replacementDiff(removedText, content, startLine, startLine, { before: beforeContext, after: afterContext });
|
|
290
|
+
const changed = updated !== original;
|
|
262
291
|
await fs.writeFile(absolutePath, updated, 'utf8');
|
|
263
|
-
return {
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
path: filePath,
|
|
295
|
+
startLine,
|
|
296
|
+
endLine: effectiveEndLine,
|
|
297
|
+
requestedEndLine: endLine,
|
|
298
|
+
endLineClamped: effectiveEndLine !== endLine,
|
|
299
|
+
replacementLines: replacementLines.length,
|
|
300
|
+
appended: isAppend,
|
|
301
|
+
noChange: !changed,
|
|
302
|
+
addedLines: changed ? replacement.addedLines : 0,
|
|
303
|
+
removedLines: changed ? replacement.removedLines : 0,
|
|
304
|
+
...mutationDiffFields(filePath, changed ? replacement.diff : []),
|
|
305
|
+
};
|
|
264
306
|
}
|
|
265
307
|
catch (error) {
|
|
266
308
|
return structuredToolFailure('replaceLines', error, 'Read the file again for current line numbers, then retry replaceLines with a valid range.', filePath);
|
|
@@ -268,38 +310,74 @@ export const hazeTools = {
|
|
|
268
310
|
}),
|
|
269
311
|
}),
|
|
270
312
|
writeFile: tool({
|
|
271
|
-
description:
|
|
313
|
+
description: `Create, rewrite, or append a UTF-8 file in chunks of at most ${WRITE_FILE_CHUNK_BYTES} bytes. Existing files require explicit rewrite or append approval.`,
|
|
272
314
|
contextSchema: hazeToolContextSchema,
|
|
273
315
|
inputSchema: z.object({
|
|
274
316
|
path: z.string().describe('File path relative to the current workspace'),
|
|
275
|
-
content: z.string().describe(
|
|
276
|
-
overwriteExisting: z.boolean().default(false).describe('Approve
|
|
317
|
+
content: z.string().max(WRITE_FILE_CHUNK_BYTES).describe(`File content chunk, at most ${WRITE_FILE_CHUNK_BYTES} UTF-8 bytes`),
|
|
318
|
+
overwriteExisting: z.boolean().default(false).describe('Approve replacing an existing file with the first chunk of an intentional full rewrite'),
|
|
319
|
+
append: z.boolean().default(false).describe('Append this chunk to an existing file; use after creating or replacing the file with the first chunk'),
|
|
277
320
|
allowIgnored: z.boolean().default(false).describe('Write a .gitignored file only when needed'),
|
|
278
321
|
}),
|
|
279
|
-
execute: async ({ path: filePath, content, overwriteExisting, allowIgnored }, context) => runDedupedTool('writeFile', { path: filePath, content, overwriteExisting, allowIgnored }, context, async () => {
|
|
322
|
+
execute: async ({ path: filePath, content, overwriteExisting, append, allowIgnored }, context) => runDedupedTool('writeFile', { path: filePath, content, overwriteExisting, append, allowIgnored }, context, async () => {
|
|
280
323
|
try {
|
|
324
|
+
const contentBytes = Buffer.byteLength(content, 'utf8');
|
|
325
|
+
if (contentBytes > WRITE_FILE_CHUNK_BYTES) {
|
|
326
|
+
throw new HazeToolError(`Content is ${contentBytes} UTF-8 bytes; writeFile accepts at most ${WRITE_FILE_CHUNK_BYTES} bytes per call. Write the first chunk normally, then use append=true for later chunks.`, 'write_chunk_too_large');
|
|
327
|
+
}
|
|
328
|
+
if (append && overwriteExisting) {
|
|
329
|
+
throw new HazeToolError('append=true and overwriteExisting=true are mutually exclusive', 'conflicting_write_modes');
|
|
330
|
+
}
|
|
281
331
|
const { absolutePath, scopedStop, assertExistingInsideWorkspace, assertWritableInsideWorkspace } = await prepareWorkspaceWritePath('writeFile', filePath, allowIgnored, context);
|
|
282
332
|
if (scopedStop)
|
|
283
333
|
return scopedStop;
|
|
334
|
+
let targetExisted = false;
|
|
335
|
+
let previousContent = '';
|
|
336
|
+
let previousContentTruncated = false;
|
|
337
|
+
let previousContentOmittedBytes = 0;
|
|
284
338
|
try {
|
|
285
339
|
await fs.access(absolutePath);
|
|
340
|
+
targetExisted = true;
|
|
286
341
|
await assertExistingInsideWorkspace();
|
|
287
|
-
if (!overwriteExisting) {
|
|
288
|
-
throw new HazeToolError(`Refusing to overwrite existing file: ${filePath}. Use editFile/replaceLines for targeted edits, or set overwriteExisting=true for an intentional
|
|
342
|
+
if (!overwriteExisting && !append) {
|
|
343
|
+
throw new HazeToolError(`Refusing to overwrite existing file: ${filePath}. Use editFile/replaceLines for targeted edits, set append=true for a later chunk, or set overwriteExisting=true for an intentional rewrite.`, 'existing_file_requires_overwrite', { recoveryTool: 'readFile', recoveryInput: { path: filePath } });
|
|
289
344
|
}
|
|
345
|
+
const previous = await readUtf8Prefix(absolutePath, EXACT_MUTATION_BYTES);
|
|
346
|
+
previousContent = previous.content;
|
|
347
|
+
previousContentTruncated = previous.truncated;
|
|
348
|
+
previousContentOmittedBytes = Math.max(0, previous.totalBytes - Buffer.byteLength(previous.content, 'utf8'));
|
|
290
349
|
}
|
|
291
350
|
catch (error) {
|
|
292
351
|
const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
|
|
293
352
|
if (code !== 'ENOENT')
|
|
294
353
|
throw error;
|
|
354
|
+
if (append)
|
|
355
|
+
throw new HazeToolError(`Cannot append to missing file: ${filePath}. Create its first chunk with append=false.`, 'append_target_missing');
|
|
295
356
|
await assertWritableInsideWorkspace();
|
|
296
357
|
}
|
|
297
358
|
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
298
|
-
|
|
299
|
-
|
|
359
|
+
const updated = append ? `${previousContent}${content}` : content;
|
|
360
|
+
const writeDiff = fileDiff(previousContent, updated);
|
|
361
|
+
if (append)
|
|
362
|
+
await fs.appendFile(absolutePath, content, 'utf8');
|
|
363
|
+
else
|
|
364
|
+
await fs.writeFile(absolutePath, content, 'utf8');
|
|
365
|
+
return {
|
|
366
|
+
ok: true,
|
|
367
|
+
path: filePath,
|
|
368
|
+
bytes: contentBytes,
|
|
369
|
+
overwritten: overwriteExisting,
|
|
370
|
+
appended: append,
|
|
371
|
+
noChange: targetExisted && !previousContentTruncated && previousContent === updated,
|
|
372
|
+
addedLines: writeDiff.addedLines,
|
|
373
|
+
removedLines: writeDiff.removedLines,
|
|
374
|
+
diffComplete: !previousContentTruncated,
|
|
375
|
+
...(previousContentTruncated ? { previousContentOmittedBytes } : {}),
|
|
376
|
+
...mutationDiffFields(filePath, writeDiff.diff),
|
|
377
|
+
};
|
|
300
378
|
}
|
|
301
379
|
catch (error) {
|
|
302
|
-
return structuredToolFailure('writeFile', error,
|
|
380
|
+
return structuredToolFailure('writeFile', error, `Keep each content chunk at or below ${WRITE_FILE_CHUNK_BYTES} UTF-8 bytes. Create or replace the first chunk, then continue with append=true.`, filePath);
|
|
303
381
|
}
|
|
304
382
|
}),
|
|
305
383
|
}),
|
|
@@ -361,9 +439,18 @@ export const hazeTools = {
|
|
|
361
439
|
removedLines += rangeDiff.removedLines;
|
|
362
440
|
lineDelta += rangeDiff.addedLines - rangeDiff.removedLines;
|
|
363
441
|
}
|
|
364
|
-
const
|
|
442
|
+
const changed = updated !== original;
|
|
365
443
|
await fs.writeFile(absolutePath, updated, 'utf8');
|
|
366
|
-
return {
|
|
444
|
+
return {
|
|
445
|
+
ok: true,
|
|
446
|
+
path: filePath,
|
|
447
|
+
edits: edits.length,
|
|
448
|
+
approximateMatches: ranges.filter(range => range.approximate).length,
|
|
449
|
+
noChange: !changed,
|
|
450
|
+
addedLines: changed ? addedLines : 0,
|
|
451
|
+
removedLines: changed ? removedLines : 0,
|
|
452
|
+
...mutationDiffFields(filePath, changed ? diff : []),
|
|
453
|
+
};
|
|
367
454
|
}
|
|
368
455
|
catch (error) {
|
|
369
456
|
return structuredToolFailure('editFile', error, 'Read the file again, then retry with exact current text or use replaceLines with the latest line numbers.', filePath);
|
|
@@ -374,4 +461,5 @@ export const hazeTools = {
|
|
|
374
461
|
readToolOutput: readToolOutputTool,
|
|
375
462
|
fetch: fetchTool,
|
|
376
463
|
bash: bashTool,
|
|
464
|
+
process: processTool,
|
|
377
465
|
};
|
package/dist/llm/lsp.d.ts
CHANGED
|
@@ -62,9 +62,13 @@ export declare class StdioLspClient {
|
|
|
62
62
|
private id;
|
|
63
63
|
private buffer;
|
|
64
64
|
private pending;
|
|
65
|
+
private terminating;
|
|
65
66
|
constructor(server: HazeLspServer, child: ChildProcessWithoutNullStreams);
|
|
66
67
|
static start(server: HazeLspServer): StdioLspClient;
|
|
67
68
|
private rejectAll;
|
|
69
|
+
private terminate;
|
|
70
|
+
/** Whether this client has begun (or completed) teardown and must not be reused. */
|
|
71
|
+
get terminated(): boolean;
|
|
68
72
|
private onData;
|
|
69
73
|
private send;
|
|
70
74
|
request(method: string, params?: Json, timeoutMs?: number): Promise<unknown>;
|
|
@@ -73,14 +77,32 @@ export declare class StdioLspClient {
|
|
|
73
77
|
openDocument(absolutePath: string): Promise<void>;
|
|
74
78
|
close(): Promise<void>;
|
|
75
79
|
}
|
|
76
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Turn-scoped pool of reused LSP clients (RH-009). Autonomous code navigation
|
|
82
|
+
* issues many symbols/definition/references calls per turn; reusing one
|
|
83
|
+
* initialized server and its opened documents avoids repeating expensive
|
|
84
|
+
* startup and indexing on every call. Clients are keyed by server name; a
|
|
85
|
+
* crashed/terminated client is evicted so the next call restarts it.
|
|
86
|
+
*/
|
|
87
|
+
export declare class LspPool {
|
|
88
|
+
private readonly clients;
|
|
89
|
+
private readonly openedDocuments;
|
|
90
|
+
private closed;
|
|
91
|
+
/** Get (or lazily start + initialize) the reusable client for a server. */
|
|
92
|
+
getClient(server: HazeLspServer): Promise<StdioLspClient>;
|
|
93
|
+
/** Open a document once per client; subsequent calls for the same URI are no-ops. */
|
|
94
|
+
ensureOpen(server: HazeLspServer, client: StdioLspClient, absolutePath: string): Promise<void>;
|
|
95
|
+
/** Bounded teardown of every pooled client. Safe to call once. */
|
|
96
|
+
close(): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
export declare function lspDocumentSymbols(server: HazeLspServer, filePath: string, limit: number, pool?: LspPool): Promise<{
|
|
77
99
|
name: string;
|
|
78
100
|
kind?: number;
|
|
79
101
|
path: string;
|
|
80
102
|
range?: ReturnType<typeof asRange>;
|
|
81
103
|
selectionRange?: ReturnType<typeof asRange>;
|
|
82
104
|
}[]>;
|
|
83
|
-
export declare function lspDefinition(server: HazeLspServer, filePath: string, line: number, character: number, limit: number): Promise<{
|
|
105
|
+
export declare function lspDefinition(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
84
106
|
external?: boolean | undefined;
|
|
85
107
|
path: string;
|
|
86
108
|
range: {
|
|
@@ -94,7 +116,7 @@ export declare function lspDefinition(server: HazeLspServer, filePath: string, l
|
|
|
94
116
|
};
|
|
95
117
|
};
|
|
96
118
|
}[]>;
|
|
97
|
-
export declare function lspReferences(server: HazeLspServer, filePath: string, line: number, character: number, limit: number): Promise<{
|
|
119
|
+
export declare function lspReferences(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
98
120
|
external?: boolean | undefined;
|
|
99
121
|
path: string;
|
|
100
122
|
range: {
|
|
@@ -108,7 +130,7 @@ export declare function lspReferences(server: HazeLspServer, filePath: string, l
|
|
|
108
130
|
};
|
|
109
131
|
};
|
|
110
132
|
}[]>;
|
|
111
|
-
export declare function lspWorkspaceSymbols(server: HazeLspServer, query: string, limit: number): Promise<{
|
|
133
|
+
export declare function lspWorkspaceSymbols(server: HazeLspServer, query: string, limit: number, pool?: LspPool): Promise<{
|
|
112
134
|
external?: boolean | undefined;
|
|
113
135
|
path: string;
|
|
114
136
|
range: {
|
package/dist/llm/lsp.js
CHANGED
|
@@ -5,6 +5,7 @@ import { assertRealPathInsideWorkspace, workspaceRelativePath, workspaceRoot } f
|
|
|
5
5
|
import { prepareWorkspaceRead } from './tools/workspaceFile.js';
|
|
6
6
|
import { LSP_BUFFER_BYTES, LSP_DOCUMENT_BYTES, LSP_FRAME_BYTES, LSP_HEADER_BYTES } from '../core/limits/byteBudgets.js';
|
|
7
7
|
import { readUtf8Prefix } from '../core/io/boundedRead.js';
|
|
8
|
+
import { signalProcessTree } from '../core/process/runBoundedProcess.js';
|
|
8
9
|
export class LspError extends Error {
|
|
9
10
|
constructor(message) {
|
|
10
11
|
super(message);
|
|
@@ -116,6 +117,7 @@ export class StdioLspClient {
|
|
|
116
117
|
id = 0;
|
|
117
118
|
buffer = Buffer.alloc(0);
|
|
118
119
|
pending = new Map();
|
|
120
|
+
terminating = false;
|
|
119
121
|
constructor(server, child) {
|
|
120
122
|
this.server = server;
|
|
121
123
|
this.child = child;
|
|
@@ -126,7 +128,7 @@ export class StdioLspClient {
|
|
|
126
128
|
catch (error) {
|
|
127
129
|
const lspError = error instanceof Error ? error : new LspError(String(error));
|
|
128
130
|
this.rejectAll(lspError);
|
|
129
|
-
this.
|
|
131
|
+
this.terminate();
|
|
130
132
|
}
|
|
131
133
|
});
|
|
132
134
|
child.stderr.on('data', () => undefined);
|
|
@@ -136,7 +138,7 @@ export class StdioLspClient {
|
|
|
136
138
|
static start(server) {
|
|
137
139
|
if (!server.command)
|
|
138
140
|
throw new LspError(`LSP server ${server.name} has no command.`);
|
|
139
|
-
const child = spawn(server.command, server.args ?? [], { cwd: workspaceRoot(), stdio: ['pipe', 'pipe', 'pipe'] });
|
|
141
|
+
const child = spawn(server.command, server.args ?? [], { cwd: workspaceRoot(), detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
140
142
|
return new StdioLspClient(server, child);
|
|
141
143
|
}
|
|
142
144
|
rejectAll(error) {
|
|
@@ -146,6 +148,21 @@ export class StdioLspClient {
|
|
|
146
148
|
}
|
|
147
149
|
this.pending.clear();
|
|
148
150
|
}
|
|
151
|
+
terminate() {
|
|
152
|
+
if (this.terminating)
|
|
153
|
+
return;
|
|
154
|
+
this.terminating = true;
|
|
155
|
+
signalProcessTree(this.child, 'SIGTERM');
|
|
156
|
+
const forceTimer = setTimeout(() => signalProcessTree(this.child, 'SIGKILL'), 500);
|
|
157
|
+
forceTimer.unref?.();
|
|
158
|
+
this.child.stdin.destroy?.();
|
|
159
|
+
this.child.stdout.destroy?.();
|
|
160
|
+
this.child.stderr.destroy?.();
|
|
161
|
+
}
|
|
162
|
+
/** Whether this client has begun (or completed) teardown and must not be reused. */
|
|
163
|
+
get terminated() {
|
|
164
|
+
return this.terminating;
|
|
165
|
+
}
|
|
149
166
|
onData(chunk) {
|
|
150
167
|
if (this.buffer.length + chunk.length > LSP_BUFFER_BYTES)
|
|
151
168
|
throw new LspError(`LSP receive buffer exceeds ${LSP_BUFFER_BYTES} bytes.`);
|
|
@@ -228,17 +245,71 @@ export class StdioLspClient {
|
|
|
228
245
|
});
|
|
229
246
|
}
|
|
230
247
|
async close() {
|
|
248
|
+
if (this.terminating)
|
|
249
|
+
return;
|
|
231
250
|
try {
|
|
232
251
|
await this.request('shutdown', null, 2000).catch(() => undefined);
|
|
233
252
|
this.notify('exit');
|
|
234
253
|
}
|
|
235
254
|
finally {
|
|
236
|
-
this.
|
|
255
|
+
this.terminate();
|
|
237
256
|
}
|
|
238
257
|
}
|
|
239
258
|
}
|
|
240
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Turn-scoped pool of reused LSP clients (RH-009). Autonomous code navigation
|
|
261
|
+
* issues many symbols/definition/references calls per turn; reusing one
|
|
262
|
+
* initialized server and its opened documents avoids repeating expensive
|
|
263
|
+
* startup and indexing on every call. Clients are keyed by server name; a
|
|
264
|
+
* crashed/terminated client is evicted so the next call restarts it.
|
|
265
|
+
*/
|
|
266
|
+
export class LspPool {
|
|
267
|
+
clients = new Map();
|
|
268
|
+
openedDocuments = new Map();
|
|
269
|
+
closed = false;
|
|
270
|
+
/** Get (or lazily start + initialize) the reusable client for a server. */
|
|
271
|
+
async getClient(server) {
|
|
272
|
+
const existing = this.clients.get(server.name);
|
|
273
|
+
if (existing && !existing.terminated)
|
|
274
|
+
return existing;
|
|
275
|
+
const client = StdioLspClient.start(server);
|
|
276
|
+
await client.initialize();
|
|
277
|
+
if (this.closed) {
|
|
278
|
+
await client.close();
|
|
279
|
+
throw new LspError('LSP pool closed during initialization.');
|
|
280
|
+
}
|
|
281
|
+
this.clients.set(server.name, client);
|
|
282
|
+
this.openedDocuments.set(server.name, new Set());
|
|
283
|
+
return client;
|
|
284
|
+
}
|
|
285
|
+
/** Open a document once per client; subsequent calls for the same URI are no-ops. */
|
|
286
|
+
async ensureOpen(server, client, absolutePath) {
|
|
287
|
+
const uri = toUri(absolutePath);
|
|
288
|
+
const opened = this.openedDocuments.get(server.name);
|
|
289
|
+
if (opened && opened.has(uri))
|
|
290
|
+
return;
|
|
291
|
+
await client.openDocument(absolutePath);
|
|
292
|
+
opened?.add(uri);
|
|
293
|
+
}
|
|
294
|
+
/** Bounded teardown of every pooled client. Safe to call once. */
|
|
295
|
+
async close() {
|
|
296
|
+
if (this.closed)
|
|
297
|
+
return;
|
|
298
|
+
this.closed = true;
|
|
299
|
+
const clients = [...this.clients.values()];
|
|
300
|
+
this.clients.clear();
|
|
301
|
+
this.openedDocuments.clear();
|
|
302
|
+
await Promise.all(clients.map(client => client.close().catch(() => undefined)));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async function withLspClient(server, filePath, pool, fn) {
|
|
241
306
|
const absolutePath = await prepareWorkspaceRead(filePath, false);
|
|
307
|
+
if (pool) {
|
|
308
|
+
const client = await pool.getClient(server);
|
|
309
|
+
await pool.ensureOpen(server, client, absolutePath);
|
|
310
|
+
return fn(client, absolutePath);
|
|
311
|
+
}
|
|
312
|
+
// Single-call fallback (no pool): full server lifecycle per invocation.
|
|
242
313
|
const client = StdioLspClient.start(server);
|
|
243
314
|
try {
|
|
244
315
|
await client.initialize();
|
|
@@ -249,31 +320,29 @@ async function withLsp(server, filePath, fn) {
|
|
|
249
320
|
await client.close();
|
|
250
321
|
}
|
|
251
322
|
}
|
|
252
|
-
export async function lspDocumentSymbols(server, filePath, limit) {
|
|
253
|
-
return await
|
|
323
|
+
export async function lspDocumentSymbols(server, filePath, limit, pool) {
|
|
324
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
254
325
|
const result = await client.request('textDocument/documentSymbol', { textDocument: { uri: toUri(absolutePath) } });
|
|
255
326
|
const symbols = Array.isArray(result) ? result : [];
|
|
256
327
|
return flattenSymbols(symbols, workspaceRelativePath(absolutePath), limit);
|
|
257
328
|
});
|
|
258
329
|
}
|
|
259
|
-
export async function lspDefinition(server, filePath, line, character, limit) {
|
|
260
|
-
return await
|
|
330
|
+
export async function lspDefinition(server, filePath, line, character, limit, pool) {
|
|
331
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
261
332
|
const result = await client.request('textDocument/definition', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 } });
|
|
262
333
|
const values = Array.isArray(result) ? result : result ? [result] : [];
|
|
263
334
|
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
264
335
|
});
|
|
265
336
|
}
|
|
266
|
-
export async function lspReferences(server, filePath, line, character, limit) {
|
|
267
|
-
return await
|
|
337
|
+
export async function lspReferences(server, filePath, line, character, limit, pool) {
|
|
338
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
268
339
|
const result = await client.request('textDocument/references', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 }, context: { includeDeclaration: true } });
|
|
269
340
|
const values = Array.isArray(result) ? result : [];
|
|
270
341
|
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
271
342
|
});
|
|
272
343
|
}
|
|
273
|
-
export async function lspWorkspaceSymbols(server, query, limit) {
|
|
274
|
-
const
|
|
275
|
-
try {
|
|
276
|
-
await client.initialize();
|
|
344
|
+
export async function lspWorkspaceSymbols(server, query, limit, pool) {
|
|
345
|
+
const run = async (client) => {
|
|
277
346
|
const result = await client.request('workspace/symbol', { query });
|
|
278
347
|
const values = Array.isArray(result) ? result : [];
|
|
279
348
|
const locations = await Promise.all(values.map(async (value) => {
|
|
@@ -285,6 +354,13 @@ export async function lspWorkspaceSymbols(server, query, limit) {
|
|
|
285
354
|
return [{ name: value.name, kind: typeof value.kind === 'number' ? value.kind : undefined, ...location }];
|
|
286
355
|
}));
|
|
287
356
|
return locations.flat().slice(0, limit);
|
|
357
|
+
};
|
|
358
|
+
if (pool)
|
|
359
|
+
return run(await pool.getClient(server));
|
|
360
|
+
const client = StdioLspClient.start(server);
|
|
361
|
+
try {
|
|
362
|
+
await client.initialize();
|
|
363
|
+
return await run(client);
|
|
288
364
|
}
|
|
289
365
|
finally {
|
|
290
366
|
await client.close();
|