@denizokcu/haze 0.10.0 → 1.0.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 +100 -1
- package/README.md +77 -27
- 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 +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- 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 -4
- package/dist/cli/chat/messages.js +218 -35
- package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
- package/dist/cli/chat/sessionLifecycle.js +64 -14
- package/dist/cli/chat/sessionRecorder.js +75 -7
- package/dist/cli/chat/startupInfo.d.ts +0 -1
- package/dist/cli/chat/startupInfo.js +11 -15
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +349 -133
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +216 -172
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commands.d.ts +2 -0
- package/dist/cli/commands/commands.js +10 -5
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +8 -25
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +9 -2
- package/dist/cli/commands/providerWizard.js +39 -7
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/skillsWizard.d.ts +41 -0
- package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
- package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
- package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
- package/dist/cli/commands/streaming/attemptSetup.js +167 -0
- 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 +130 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
- package/dist/cli/commands/streaming/stallRecovery.js +105 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
- package/dist/cli/commands/streaming/streamLoop.js +448 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -0
- package/dist/cli/commands/streaming.d.ts +65 -9
- package/dist/cli/commands/streaming.js +133 -430
- package/dist/cli/commands/wizardFlow.d.ts +334 -0
- package/dist/cli/commands/wizardFlow.js +377 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/contextFiles.js +9 -3
- package/dist/config/inputHistory.d.ts +0 -1
- package/dist/config/inputHistory.js +1 -1
- package/dist/config/modelDiscovery.d.ts +36 -0
- package/dist/config/modelDiscovery.js +164 -1
- 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 +39 -7
- package/dist/config/providerPresets.js +371 -100
- package/dist/config/providers.js +2 -0
- package/dist/config/settings.d.ts +43 -0
- package/dist/config/settings.js +12 -0
- package/dist/config/skillSettings.js +4 -4
- package/dist/config/updateCheck.d.ts +0 -1
- package/dist/config/updateCheck.js +1 -1
- package/dist/core/agent/budgets.d.ts +73 -1
- package/dist/core/agent/budgets.js +94 -1
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +224 -0
- package/dist/core/agent/completionController.js +296 -0
- package/dist/core/agent/contextBudget.d.ts +36 -2
- package/dist/core/agent/contextBudget.js +62 -9
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +78 -0
- package/dist/core/agent/goalPolicy.d.ts +47 -0
- package/dist/core/agent/goalPolicy.js +106 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/requestAssembly.d.ts +2 -2
- package/dist/core/agent/requestAssembly.js +16 -4
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +11 -11
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -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 +81 -3
- package/dist/core/agent/workState.js +176 -10
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +27 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/io/boundedRead.js +1 -1
- package/dist/core/limits.d.ts +51 -0
- package/dist/core/limits.js +51 -0
- package/dist/core/log/llmLog.js +8 -1
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +15 -10
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/shellClassifier.d.ts +11 -0
- package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
- package/dist/core/safety/urlGuard.d.ts +1 -1
- package/dist/core/session/sessionSlimming.d.ts +0 -3
- package/dist/core/session/sessionSlimming.js +2 -3
- package/dist/core/session/sessionStore.d.ts +38 -0
- package/dist/core/session/sessionStore.js +242 -59
- package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
- package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
- package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
- package/dist/core/shellOutput/registry.d.ts +2 -0
- package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
- package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
- package/dist/core/subagent/contracts.d.ts +6 -14
- package/dist/core/subagent/contracts.js +4 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +19 -40
- package/dist/core/toolOutput/reduction.d.ts +0 -12
- package/dist/core/toolOutput/reduction.js +1 -1
- package/dist/core/validation/outputParser.d.ts +2 -2
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +86 -14
- package/dist/llm/hazeTools.d.ts +693 -204
- package/dist/llm/hazeTools.js +110 -28
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp/client.d.ts +45 -0
- package/dist/llm/lsp/client.js +195 -0
- package/dist/llm/lsp/pool.d.ts +23 -0
- package/dist/llm/lsp/pool.js +86 -0
- package/dist/llm/lsp/protocol.d.ts +64 -0
- package/dist/llm/lsp/protocol.js +128 -0
- package/dist/llm/lsp/requests.d.ts +94 -0
- package/dist/llm/lsp/requests.js +119 -0
- package/dist/llm/lspTools.d.ts +5653 -33
- package/dist/llm/lspTools.js +152 -80
- package/dist/llm/openaiCodex.d.ts +1 -0
- package/dist/llm/openaiCodex.js +43 -0
- package/dist/llm/openaiCodexOAuth.d.ts +51 -0
- package/dist/llm/openaiCodexOAuth.js +217 -0
- package/dist/llm/requestContext.d.ts +7 -0
- package/dist/llm/requestContext.js +30 -4
- package/dist/llm/systemPrompt.d.ts +12 -0
- package/dist/llm/systemPrompt.js +24 -11
- package/dist/llm/toolResultTypes.d.ts +7 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +14 -9
- package/dist/llm/tools/editMatch.js +73 -1
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +8 -5
- package/dist/llm/tools/fileToolShared.js +22 -23
- package/dist/llm/tools/gitIgnore.d.ts +42 -0
- package/dist/llm/tools/gitIgnore.js +247 -0
- package/dist/llm/tools/grepParse.d.ts +2 -1
- package/dist/llm/tools/grepRunner.d.ts +1 -1
- package/dist/llm/tools/grepRunner.js +2 -2
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -3
- package/dist/llm/tools/processTool.d.ts +16 -16
- package/dist/llm/tools/processTool.js +1 -1
- package/dist/llm/tools/readRecovery.d.ts +8 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
- package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +66 -37
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +18 -1
- package/dist/llm/webFetch.js +64 -97
- package/dist/skills/SkillLoader.d.ts +1 -11
- package/dist/skills/SkillLoader.js +1 -2
- package/dist/skills/types.d.ts +2 -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 +8 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +97 -0
- package/dist/utils/buildInfo.js +244 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.js +91 -26
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +6 -2
- 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 +28 -21
- package/dist/cli/commands/lspWizard.d.ts +0 -14
- package/dist/cli/commands/lspWizard.js +0 -44
- package/dist/cli/commands/mcpWizard.d.ts +0 -15
- package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
- package/dist/cli/commands/skillConfirmRemove.js +0 -20
- package/dist/cli/commands/skillCreation.d.ts +0 -12
- package/dist/cli/commands/skillCreation.js +0 -14
- package/dist/cli/commands/skillWizard.d.ts +0 -17
- package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
- package/dist/cli/commands/streaming/idleTimer.js +0 -24
- package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
- package/dist/cli/commands/streaming/turnOutcome.js +0 -13
- package/dist/cli/commands/wizardActions.d.ts +0 -46
- package/dist/cli/commands/wizardActions.js +0 -46
- package/dist/cli/commands/wizardInput.d.ts +0 -4
- package/dist/cli/commands/wizardInput.js +0 -19
- package/dist/cli/commands/wizardPrompts.d.ts +0 -22
- package/dist/cli/commands/wizardPrompts.js +0 -52
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -188
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/bashOutput/ansi.d.ts +0 -1
- package/dist/core/bashOutput/ansi.js +0 -7
- package/dist/core/bashOutput/registry.d.ts +0 -4
- package/dist/core/goal/completionPolicy.d.ts +0 -2
- package/dist/core/goal/completionPolicy.js +0 -7
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -18
- package/dist/core/goal/sessionGoal.d.ts +0 -8
- package/dist/core/goal/sessionGoal.js +0 -30
- package/dist/core/limits/byteBudgets.d.ts +0 -18
- package/dist/core/limits/byteBudgets.js +0 -18
- package/dist/core/limits/textBudgets.d.ts +0 -23
- package/dist/core/limits/textBudgets.js +0 -23
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -129
- package/dist/llm/lsp.js +0 -307
- package/dist/ui/components/ErrorView.d.ts +0 -4
- package/dist/ui/components/ErrorView.js +0 -7
- package/dist/utils/yaml.d.ts +0 -2
- package/dist/utils/yaml.js +0 -8
- package/examples/skills/files/SKILL.md +0 -16
- package/examples/skills/files/examples/file-editing.md +0 -3
- /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
|
+
import { assertRealPathInsideWorkspace, workspaceRelativePath } from '../../utils/path.js';
|
|
4
|
+
/**
|
|
5
|
+
* Pure LSP protocol helpers: language/URI mapping, 1-indexed range conversion,
|
|
6
|
+
* location/symbol/diagnostic shaping. No client, process, or filesystem state
|
|
7
|
+
* beyond workspace-relative path resolution.
|
|
8
|
+
*/
|
|
9
|
+
export function languageId(filePath) {
|
|
10
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
11
|
+
if (ext === '.ts')
|
|
12
|
+
return 'typescript';
|
|
13
|
+
if (ext === '.tsx')
|
|
14
|
+
return 'typescriptreact';
|
|
15
|
+
if (ext === '.js')
|
|
16
|
+
return 'javascript';
|
|
17
|
+
if (ext === '.jsx')
|
|
18
|
+
return 'javascriptreact';
|
|
19
|
+
if (ext === '.rs')
|
|
20
|
+
return 'rust';
|
|
21
|
+
if (ext === '.py')
|
|
22
|
+
return 'python';
|
|
23
|
+
if (ext === '.go')
|
|
24
|
+
return 'go';
|
|
25
|
+
return ext.replace(/^\./, '') || 'plaintext';
|
|
26
|
+
}
|
|
27
|
+
export function toUri(absolutePath) {
|
|
28
|
+
return pathToFileURL(absolutePath).toString();
|
|
29
|
+
}
|
|
30
|
+
export function fromUri(uri) {
|
|
31
|
+
if (!uri.startsWith('file://'))
|
|
32
|
+
return uri;
|
|
33
|
+
try {
|
|
34
|
+
return workspaceRelativePath(fileURLToPath(uri));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return uri;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function isObject(value) {
|
|
41
|
+
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
export function asRange(value) {
|
|
44
|
+
if (!isObject(value) || !isObject(value.start) || !isObject(value.end))
|
|
45
|
+
return undefined;
|
|
46
|
+
const start = value.start;
|
|
47
|
+
const end = value.end;
|
|
48
|
+
return {
|
|
49
|
+
start: { line: typeof start.line === 'number' ? start.line + 1 : 1, character: typeof start.character === 'number' ? start.character + 1 : 1 },
|
|
50
|
+
end: { line: typeof end.line === 'number' ? end.line + 1 : 1, character: typeof end.character === 'number' ? end.character + 1 : 1 },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function locationToResult(value) {
|
|
54
|
+
if (!isObject(value))
|
|
55
|
+
return undefined;
|
|
56
|
+
const uri = typeof value.uri === 'string' ? value.uri : (typeof value.targetUri === 'string' ? value.targetUri : undefined);
|
|
57
|
+
const range = asRange(value.range ?? value.targetSelectionRange ?? value.targetRange);
|
|
58
|
+
if (!uri || !range)
|
|
59
|
+
return undefined;
|
|
60
|
+
const resultPath = fromUri(uri);
|
|
61
|
+
const external = !uri.startsWith('file://') || resultPath.startsWith('..') || path.isAbsolute(resultPath);
|
|
62
|
+
return { path: resultPath, range, ...(external ? { external: true } : {}) };
|
|
63
|
+
}
|
|
64
|
+
export async function locationToWorkspaceResult(value) {
|
|
65
|
+
const result = locationToResult(value);
|
|
66
|
+
if (!result || result.external)
|
|
67
|
+
return result;
|
|
68
|
+
if (!isObject(value))
|
|
69
|
+
return undefined;
|
|
70
|
+
const uri = typeof value.uri === 'string' ? value.uri : (typeof value.targetUri === 'string' ? value.targetUri : undefined);
|
|
71
|
+
if (!uri?.startsWith('file://'))
|
|
72
|
+
return result;
|
|
73
|
+
try {
|
|
74
|
+
const absolutePath = fileURLToPath(uri);
|
|
75
|
+
await assertRealPathInsideWorkspace(absolutePath, uri);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { ...result, path: uri, external: true };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function flattenSymbols(symbols, filePath, limit) {
|
|
83
|
+
const out = [];
|
|
84
|
+
const visit = (items) => {
|
|
85
|
+
for (const item of items) {
|
|
86
|
+
if (out.length >= limit || !isObject(item))
|
|
87
|
+
return;
|
|
88
|
+
if (typeof item.name === 'string') {
|
|
89
|
+
out.push({
|
|
90
|
+
name: item.name,
|
|
91
|
+
kind: typeof item.kind === 'number' ? item.kind : undefined,
|
|
92
|
+
path: filePath,
|
|
93
|
+
range: asRange(item.range),
|
|
94
|
+
selectionRange: asRange(item.selectionRange),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(item.children))
|
|
98
|
+
visit(item.children);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
visit(symbols);
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
const DIAGNOSTIC_SEVERITIES = ['error', 'warning', 'information', 'hint'];
|
|
105
|
+
export function toDiagnostic(value) {
|
|
106
|
+
if (!isObject(value))
|
|
107
|
+
return undefined;
|
|
108
|
+
const range = asRange(value.range);
|
|
109
|
+
if (!range)
|
|
110
|
+
return undefined;
|
|
111
|
+
const severity = typeof value.severity === 'number' && value.severity >= 1 && value.severity <= 4
|
|
112
|
+
? DIAGNOSTIC_SEVERITIES[value.severity - 1]
|
|
113
|
+
: 'information';
|
|
114
|
+
const code = typeof value.code === 'number' || typeof value.code === 'string' ? String(value.code) : undefined;
|
|
115
|
+
const source = typeof value.source === 'string' ? value.source : undefined;
|
|
116
|
+
return { severity, range, message: typeof value.message === 'string' ? value.message : '', ...(code ? { code } : {}), ...(source ? { source } : {}) };
|
|
117
|
+
}
|
|
118
|
+
export function diagnosticsFrom(values, limit) {
|
|
119
|
+
const out = [];
|
|
120
|
+
for (const value of values) {
|
|
121
|
+
if (out.length >= limit)
|
|
122
|
+
break;
|
|
123
|
+
const diagnostic = toDiagnostic(value);
|
|
124
|
+
if (diagnostic)
|
|
125
|
+
out.push(diagnostic);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { HazeLspServer } from '../../config/lspSettings.js';
|
|
2
|
+
import { type LspDiagnostic } from './protocol.js';
|
|
3
|
+
import type { LspPool } from './pool.js';
|
|
4
|
+
export declare function lspDocumentSymbols(server: HazeLspServer, filePath: string, limit: number, pool?: LspPool): Promise<{
|
|
5
|
+
name: string;
|
|
6
|
+
kind?: number;
|
|
7
|
+
path: string;
|
|
8
|
+
range?: ReturnType<typeof import("./protocol.js").asRange>;
|
|
9
|
+
selectionRange?: ReturnType<typeof import("./protocol.js").asRange>;
|
|
10
|
+
}[]>;
|
|
11
|
+
export declare function lspDefinition(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
12
|
+
external?: boolean | undefined;
|
|
13
|
+
path: string;
|
|
14
|
+
range: {
|
|
15
|
+
start: {
|
|
16
|
+
line: number;
|
|
17
|
+
character: number;
|
|
18
|
+
};
|
|
19
|
+
end: {
|
|
20
|
+
line: number;
|
|
21
|
+
character: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}[]>;
|
|
25
|
+
export declare function lspTypeDefinition(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
26
|
+
external?: boolean | undefined;
|
|
27
|
+
path: string;
|
|
28
|
+
range: {
|
|
29
|
+
start: {
|
|
30
|
+
line: number;
|
|
31
|
+
character: number;
|
|
32
|
+
};
|
|
33
|
+
end: {
|
|
34
|
+
line: number;
|
|
35
|
+
character: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}[]>;
|
|
39
|
+
export declare function lspImplementation(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
40
|
+
external?: boolean | undefined;
|
|
41
|
+
path: string;
|
|
42
|
+
range: {
|
|
43
|
+
start: {
|
|
44
|
+
line: number;
|
|
45
|
+
character: number;
|
|
46
|
+
};
|
|
47
|
+
end: {
|
|
48
|
+
line: number;
|
|
49
|
+
character: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}[]>;
|
|
53
|
+
export declare function lspReferences(server: HazeLspServer, filePath: string, line: number, character: number, limit: number, pool?: LspPool): Promise<{
|
|
54
|
+
external?: boolean | undefined;
|
|
55
|
+
path: string;
|
|
56
|
+
range: {
|
|
57
|
+
start: {
|
|
58
|
+
line: number;
|
|
59
|
+
character: number;
|
|
60
|
+
};
|
|
61
|
+
end: {
|
|
62
|
+
line: number;
|
|
63
|
+
character: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Diagnostics for one document: pull (`textDocument/documentDiagnostic`) when the
|
|
69
|
+
* server advertises it, otherwise the latest push-published set after didOpen.
|
|
70
|
+
* A timed-out pull falls back to push instead of failing the whole request.
|
|
71
|
+
*/
|
|
72
|
+
export declare function lspDiagnostics(server: HazeLspServer, filePath: string, limit: number, pool?: LspPool): Promise<{
|
|
73
|
+
ok: true;
|
|
74
|
+
diagnostics: LspDiagnostic[];
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
error: string;
|
|
78
|
+
}>;
|
|
79
|
+
export declare function lspWorkspaceSymbols(server: HazeLspServer, query: string, limit: number, pool?: LspPool): Promise<{
|
|
80
|
+
external?: boolean | undefined;
|
|
81
|
+
path: string;
|
|
82
|
+
range: {
|
|
83
|
+
start: {
|
|
84
|
+
line: number;
|
|
85
|
+
character: number;
|
|
86
|
+
};
|
|
87
|
+
end: {
|
|
88
|
+
line: number;
|
|
89
|
+
character: number;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
name: string;
|
|
93
|
+
kind: number | undefined;
|
|
94
|
+
}[]>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { workspaceRelativePath } from '../../utils/path.js';
|
|
2
|
+
import { prepareWorkspaceRead } from '../tools/workspaceFile.js';
|
|
3
|
+
import { diagnosticsFrom, flattenSymbols, isObject, locationToWorkspaceResult, toUri } from './protocol.js';
|
|
4
|
+
import { LspError, StdioLspClient } from './client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Workspace-safe LSP request facades: document symbols, definitions,
|
|
7
|
+
* implementations, references, diagnostics, and workspace symbols. Each facade
|
|
8
|
+
* resolves the path through workspace-read confinement, then runs on a pooled
|
|
9
|
+
* client (or a single-call fallback lifecycle). This module is the seam the
|
|
10
|
+
* AI-SDK tools (`lspTools.ts`) and their tests program against.
|
|
11
|
+
*/
|
|
12
|
+
async function withLspClient(server, filePath, pool, fn) {
|
|
13
|
+
const absolutePath = await prepareWorkspaceRead(filePath, false);
|
|
14
|
+
if (pool) {
|
|
15
|
+
const client = await pool.getClient(server, absolutePath);
|
|
16
|
+
await pool.ensureOpen(server, client, absolutePath);
|
|
17
|
+
return fn(client, absolutePath);
|
|
18
|
+
}
|
|
19
|
+
// Single-call fallback (no pool): full server lifecycle per invocation.
|
|
20
|
+
const client = StdioLspClient.start(server);
|
|
21
|
+
try {
|
|
22
|
+
await client.initialize();
|
|
23
|
+
await client.openDocument(absolutePath);
|
|
24
|
+
return await fn(client, absolutePath);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await client.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function lspDocumentSymbols(server, filePath, limit, pool) {
|
|
31
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
32
|
+
const result = await client.request('textDocument/documentSymbol', { textDocument: { uri: toUri(absolutePath) } });
|
|
33
|
+
const symbols = Array.isArray(result) ? result : [];
|
|
34
|
+
return flattenSymbols(symbols, workspaceRelativePath(absolutePath), limit);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function requestLocations(client, absolutePath, method, line, character, limit) {
|
|
38
|
+
const result = await client.request(method, { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 } });
|
|
39
|
+
const values = Array.isArray(result) ? result : result ? [result] : [];
|
|
40
|
+
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
41
|
+
}
|
|
42
|
+
export async function lspDefinition(server, filePath, line, character, limit, pool) {
|
|
43
|
+
return await withLspClient(server, filePath, pool, (client, absolutePath) => requestLocations(client, absolutePath, 'textDocument/definition', line, character, limit));
|
|
44
|
+
}
|
|
45
|
+
export async function lspTypeDefinition(server, filePath, line, character, limit, pool) {
|
|
46
|
+
return await withLspClient(server, filePath, pool, (client, absolutePath) => requestLocations(client, absolutePath, 'textDocument/typeDefinition', line, character, limit));
|
|
47
|
+
}
|
|
48
|
+
export async function lspImplementation(server, filePath, line, character, limit, pool) {
|
|
49
|
+
return await withLspClient(server, filePath, pool, (client, absolutePath) => requestLocations(client, absolutePath, 'textDocument/implementation', line, character, limit));
|
|
50
|
+
}
|
|
51
|
+
export async function lspReferences(server, filePath, line, character, limit, pool) {
|
|
52
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
53
|
+
const result = await client.request('textDocument/references', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 }, context: { includeDeclaration: true } });
|
|
54
|
+
const values = Array.isArray(result) ? result : [];
|
|
55
|
+
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function pullDiagnostics(client, absolutePath, limit) {
|
|
59
|
+
const result = await client.request('textDocument/documentDiagnostic', { textDocument: { uri: toUri(absolutePath) } }, 15000);
|
|
60
|
+
const items = isObject(result) && Array.isArray(result.items) ? result.items : [];
|
|
61
|
+
return diagnosticsFrom(items, limit);
|
|
62
|
+
}
|
|
63
|
+
/** Wait briefly for `textDocument/publishDiagnostics` push diagnostics after didOpen. */
|
|
64
|
+
async function awaitPushDiagnostics(client, absolutePath, limit, waitMs) {
|
|
65
|
+
const uri = toUri(absolutePath);
|
|
66
|
+
const deadline = Date.now() + waitMs;
|
|
67
|
+
while (true) {
|
|
68
|
+
const published = client.publishedDiagnostics(uri);
|
|
69
|
+
if (published)
|
|
70
|
+
return diagnosticsFrom(published, limit);
|
|
71
|
+
if (Date.now() >= deadline)
|
|
72
|
+
return [];
|
|
73
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(100, deadline - Date.now())));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Diagnostics for one document: pull (`textDocument/documentDiagnostic`) when the
|
|
78
|
+
* server advertises it, otherwise the latest push-published set after didOpen.
|
|
79
|
+
* A timed-out pull falls back to push instead of failing the whole request.
|
|
80
|
+
*/
|
|
81
|
+
export async function lspDiagnostics(server, filePath, limit, pool) {
|
|
82
|
+
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
83
|
+
if (client.diagnosticPullSupported()) {
|
|
84
|
+
try {
|
|
85
|
+
return { ok: true, diagnostics: await pullDiagnostics(client, absolutePath, limit) };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!(error instanceof LspError) || !/timed out/.test(error.message))
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { ok: true, diagnostics: await awaitPushDiagnostics(client, absolutePath, limit, 500) };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export async function lspWorkspaceSymbols(server, query, limit, pool) {
|
|
96
|
+
const run = async (client) => {
|
|
97
|
+
const result = await client.request('workspace/symbol', { query });
|
|
98
|
+
const values = Array.isArray(result) ? result : [];
|
|
99
|
+
const locations = await Promise.all(values.map(async (value) => {
|
|
100
|
+
if (!isObject(value) || typeof value.name !== 'string')
|
|
101
|
+
return [];
|
|
102
|
+
const location = await locationToWorkspaceResult(value.location);
|
|
103
|
+
if (!location)
|
|
104
|
+
return [];
|
|
105
|
+
return [{ name: value.name, kind: typeof value.kind === 'number' ? value.kind : undefined, ...location }];
|
|
106
|
+
}));
|
|
107
|
+
return locations.flat().slice(0, limit);
|
|
108
|
+
};
|
|
109
|
+
if (pool)
|
|
110
|
+
return run(await pool.getClient(server));
|
|
111
|
+
const client = StdioLspClient.start(server);
|
|
112
|
+
try {
|
|
113
|
+
await client.initialize();
|
|
114
|
+
return await run(client);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
await client.close();
|
|
118
|
+
}
|
|
119
|
+
}
|