@denizokcu/haze 0.11.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 +23 -0
- package/README.md +23 -14
- package/SECURITY.md +3 -3
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/fileMentionSuggestions.js +1 -1
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- package/dist/cli/chat/messages.d.ts +0 -2
- package/dist/cli/chat/messages.js +2 -2
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -1
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +250 -133
- package/dist/cli/commands/chat.js +14 -72
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/doctor.js +1 -1
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +6 -25
- package/dist/cli/commands/providerWizard.js +2 -3
- package/dist/cli/commands/runCommand.js +1 -1
- 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 +2 -1
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- 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 +1 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +2 -2
- package/dist/cli/commands/streaming/goalSupervisor.js +9 -6
- 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 +14 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +56 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -1
- 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 +14 -25
- package/dist/cli/commands/streaming.js +43 -754
- 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 +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 +0 -15
- package/dist/config/modelDiscovery.js +1 -1
- package/dist/config/settings.d.ts +7 -0
- package/dist/config/settings.js +3 -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 +63 -1
- package/dist/core/agent/budgets.js +84 -1
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/completionController.d.ts +7 -13
- package/dist/core/agent/completionController.js +17 -8
- package/dist/core/agent/contextBudget.d.ts +0 -4
- package/dist/core/agent/contextBudget.js +3 -3
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +5 -1
- package/dist/core/{goal/completionPolicy.d.ts → agent/goalPolicy.d.ts} +18 -0
- package/dist/core/agent/goalPolicy.js +106 -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 +2 -2
- package/dist/core/agent/toolCapabilities.js +5 -5
- package/dist/core/agent/toolOutputStore.js +1 -1
- package/dist/core/agent/toolResults.js +1 -1
- package/dist/core/agent/workState.d.ts +6 -3
- package/dist/core/agent/workState.js +62 -7
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +0 -6
- package/dist/core/deadline.js +1 -1
- 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 +1 -1
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +10 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -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 +1 -0
- package/dist/core/session/sessionStore.js +39 -20
- 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 +2 -14
- package/dist/core/subagent/contracts.js +3 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentRunner.js +3 -4
- 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.js +5 -1
- package/dist/llm/hazeTools.d.ts +139 -124
- package/dist/llm/hazeTools.js +14 -11
- 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 +3824 -570
- package/dist/llm/lspTools.js +65 -1
- package/dist/llm/openaiCodex.d.ts +0 -2
- package/dist/llm/openaiCodex.js +0 -4
- package/dist/llm/openaiCodexOAuth.d.ts +0 -3
- package/dist/llm/openaiCodexOAuth.js +6 -3
- package/dist/llm/requestContext.d.ts +5 -1
- package/dist/llm/requestContext.js +25 -2
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +13 -6
- package/dist/llm/toolResultTypes.d.ts +0 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +0 -9
- package/dist/llm/tools/editMatch.js +1 -1
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +4 -2
- package/dist/llm/tools/fileToolShared.js +9 -5
- package/dist/llm/tools/gitIgnore.d.ts +25 -32
- package/dist/llm/tools/gitIgnore.js +216 -98
- 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 +0 -2
- package/dist/llm/tools/readRecovery.js +2 -2
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +123 -107
- package/dist/llm/tools/{bashTool.js → shellTool.js} +15 -14
- package/dist/llm/tools/toolContext.js +5 -5
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +1 -1
- 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/utils/buildInfo.d.ts +6 -13
- package/dist/utils/buildInfo.js +6 -15
- package/dist/utils/fs.d.ts +7 -5
- package/dist/utils/fs.js +5 -2
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +1 -1
- package/package.json +6 -4
- 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 -27
- package/dist/cli/commands/streaming/turnOutcome.js +0 -29
- package/dist/cli/commands/wizardActions.d.ts +0 -47
- package/dist/cli/commands/wizardActions.js +0 -47
- 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 -58
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -190
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/agent/toolExecutionBudget.d.ts +0 -35
- package/dist/core/agent/toolExecutionBudget.js +0 -49
- package/dist/core/agent/turnBudget.d.ts +0 -35
- package/dist/core/agent/turnBudget.js +0 -27
- 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.js +0 -43
- 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 -20
- package/dist/core/limits/byteBudgets.js +0 -20
- package/dist/core/limits/textBudgets.d.ts +0 -25
- package/dist/core/limits/textBudgets.js +0 -25
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -149
- package/dist/llm/lsp.js +0 -368
- 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
package/dist/llm/lsp.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import { assertRealPathInsideWorkspace, workspaceRelativePath, workspaceRoot } from '../utils/path.js';
|
|
5
|
-
import { prepareWorkspaceRead } from './tools/workspaceFile.js';
|
|
6
|
-
import { LSP_BUFFER_BYTES, LSP_DOCUMENT_BYTES, LSP_FRAME_BYTES, LSP_HEADER_BYTES } from '../core/limits/byteBudgets.js';
|
|
7
|
-
import { readUtf8Prefix } from '../core/io/boundedRead.js';
|
|
8
|
-
import { signalProcessTree } from '../core/process/runBoundedProcess.js';
|
|
9
|
-
export class LspError extends Error {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = 'LspError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export function languageId(filePath) {
|
|
16
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
17
|
-
if (ext === '.ts')
|
|
18
|
-
return 'typescript';
|
|
19
|
-
if (ext === '.tsx')
|
|
20
|
-
return 'typescriptreact';
|
|
21
|
-
if (ext === '.js')
|
|
22
|
-
return 'javascript';
|
|
23
|
-
if (ext === '.jsx')
|
|
24
|
-
return 'javascriptreact';
|
|
25
|
-
if (ext === '.rs')
|
|
26
|
-
return 'rust';
|
|
27
|
-
if (ext === '.py')
|
|
28
|
-
return 'python';
|
|
29
|
-
if (ext === '.go')
|
|
30
|
-
return 'go';
|
|
31
|
-
return ext.replace(/^\./, '') || 'plaintext';
|
|
32
|
-
}
|
|
33
|
-
export function toUri(absolutePath) {
|
|
34
|
-
return pathToFileURL(absolutePath).toString();
|
|
35
|
-
}
|
|
36
|
-
export function fromUri(uri) {
|
|
37
|
-
if (!uri.startsWith('file://'))
|
|
38
|
-
return uri;
|
|
39
|
-
try {
|
|
40
|
-
return workspaceRelativePath(fileURLToPath(uri));
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return uri;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function isObject(value) {
|
|
47
|
-
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
48
|
-
}
|
|
49
|
-
export function asRange(value) {
|
|
50
|
-
if (!isObject(value) || !isObject(value.start) || !isObject(value.end))
|
|
51
|
-
return undefined;
|
|
52
|
-
const start = value.start;
|
|
53
|
-
const end = value.end;
|
|
54
|
-
return {
|
|
55
|
-
start: { line: typeof start.line === 'number' ? start.line + 1 : 1, character: typeof start.character === 'number' ? start.character + 1 : 1 },
|
|
56
|
-
end: { line: typeof end.line === 'number' ? end.line + 1 : 1, character: typeof end.character === 'number' ? end.character + 1 : 1 },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export function locationToResult(value) {
|
|
60
|
-
if (!isObject(value))
|
|
61
|
-
return undefined;
|
|
62
|
-
const uri = typeof value.uri === 'string' ? value.uri : (typeof value.targetUri === 'string' ? value.targetUri : undefined);
|
|
63
|
-
const range = asRange(value.range ?? value.targetSelectionRange ?? value.targetRange);
|
|
64
|
-
if (!uri || !range)
|
|
65
|
-
return undefined;
|
|
66
|
-
const resultPath = fromUri(uri);
|
|
67
|
-
const external = !uri.startsWith('file://') || resultPath.startsWith('..') || path.isAbsolute(resultPath);
|
|
68
|
-
return { path: resultPath, range, ...(external ? { external: true } : {}) };
|
|
69
|
-
}
|
|
70
|
-
export async function locationToWorkspaceResult(value) {
|
|
71
|
-
const result = locationToResult(value);
|
|
72
|
-
if (!result || result.external)
|
|
73
|
-
return result;
|
|
74
|
-
if (!isObject(value))
|
|
75
|
-
return undefined;
|
|
76
|
-
const uri = typeof value.uri === 'string' ? value.uri : (typeof value.targetUri === 'string' ? value.targetUri : undefined);
|
|
77
|
-
if (!uri?.startsWith('file://'))
|
|
78
|
-
return result;
|
|
79
|
-
try {
|
|
80
|
-
const absolutePath = fileURLToPath(uri);
|
|
81
|
-
await assertRealPathInsideWorkspace(absolutePath, uri);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return { ...result, path: uri, external: true };
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export function flattenSymbols(symbols, filePath, limit) {
|
|
89
|
-
const out = [];
|
|
90
|
-
const visit = (items) => {
|
|
91
|
-
for (const item of items) {
|
|
92
|
-
if (out.length >= limit || !isObject(item))
|
|
93
|
-
return;
|
|
94
|
-
if (typeof item.name === 'string') {
|
|
95
|
-
out.push({
|
|
96
|
-
name: item.name,
|
|
97
|
-
kind: typeof item.kind === 'number' ? item.kind : undefined,
|
|
98
|
-
path: filePath,
|
|
99
|
-
range: asRange(item.range),
|
|
100
|
-
selectionRange: asRange(item.selectionRange),
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (Array.isArray(item.children))
|
|
104
|
-
visit(item.children);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
visit(symbols);
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
export function pickLspServer(servers, filePath) {
|
|
111
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
112
|
-
return servers.find(server => server.enabled !== false && (server.extensions ?? []).map(e => e.toLowerCase()).includes(ext));
|
|
113
|
-
}
|
|
114
|
-
export class StdioLspClient {
|
|
115
|
-
server;
|
|
116
|
-
child;
|
|
117
|
-
id = 0;
|
|
118
|
-
buffer = Buffer.alloc(0);
|
|
119
|
-
pending = new Map();
|
|
120
|
-
terminating = false;
|
|
121
|
-
constructor(server, child) {
|
|
122
|
-
this.server = server;
|
|
123
|
-
this.child = child;
|
|
124
|
-
child.stdout.on('data', chunk => {
|
|
125
|
-
try {
|
|
126
|
-
this.onData(chunk);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
const lspError = error instanceof Error ? error : new LspError(String(error));
|
|
130
|
-
this.rejectAll(lspError);
|
|
131
|
-
this.terminate();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
child.stderr.on('data', () => undefined);
|
|
135
|
-
child.on('error', error => this.rejectAll(error instanceof Error ? error : new Error(String(error))));
|
|
136
|
-
child.on('exit', code => this.rejectAll(new LspError(`LSP server exited${code == null ? '' : ` with code ${code}`}`)));
|
|
137
|
-
}
|
|
138
|
-
static start(server) {
|
|
139
|
-
if (!server.command)
|
|
140
|
-
throw new LspError(`LSP server ${server.name} has no command.`);
|
|
141
|
-
const child = spawn(server.command, server.args ?? [], { cwd: workspaceRoot(), detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
142
|
-
return new StdioLspClient(server, child);
|
|
143
|
-
}
|
|
144
|
-
rejectAll(error) {
|
|
145
|
-
for (const pending of this.pending.values()) {
|
|
146
|
-
clearTimeout(pending.timer);
|
|
147
|
-
pending.reject(error);
|
|
148
|
-
}
|
|
149
|
-
this.pending.clear();
|
|
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
|
-
}
|
|
166
|
-
onData(chunk) {
|
|
167
|
-
if (this.buffer.length + chunk.length > LSP_BUFFER_BYTES)
|
|
168
|
-
throw new LspError(`LSP receive buffer exceeds ${LSP_BUFFER_BYTES} bytes.`);
|
|
169
|
-
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
170
|
-
while (true) {
|
|
171
|
-
const headerEnd = this.buffer.indexOf('\r\n\r\n');
|
|
172
|
-
if (headerEnd === -1) {
|
|
173
|
-
if (this.buffer.length > LSP_HEADER_BYTES)
|
|
174
|
-
throw new LspError(`LSP header exceeds ${LSP_HEADER_BYTES} bytes.`);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (headerEnd > LSP_HEADER_BYTES)
|
|
178
|
-
throw new LspError(`LSP header exceeds ${LSP_HEADER_BYTES} bytes.`);
|
|
179
|
-
const header = this.buffer.slice(0, headerEnd).toString('utf8');
|
|
180
|
-
const match = /Content-Length: (\d+)/i.exec(header);
|
|
181
|
-
if (!match)
|
|
182
|
-
throw new LspError('Malformed LSP response: missing Content-Length.');
|
|
183
|
-
const length = Number(match[1]);
|
|
184
|
-
if (!Number.isSafeInteger(length) || length < 0 || length > LSP_FRAME_BYTES)
|
|
185
|
-
throw new LspError(`LSP frame exceeds ${LSP_FRAME_BYTES} bytes.`);
|
|
186
|
-
const bodyStart = headerEnd + 4;
|
|
187
|
-
if (this.buffer.length < bodyStart + length)
|
|
188
|
-
return;
|
|
189
|
-
const raw = this.buffer.slice(bodyStart, bodyStart + length).toString('utf8');
|
|
190
|
-
this.buffer = this.buffer.slice(bodyStart + length);
|
|
191
|
-
const message = JSON.parse(raw);
|
|
192
|
-
if (typeof message.id !== 'number')
|
|
193
|
-
continue;
|
|
194
|
-
const pending = this.pending.get(message.id);
|
|
195
|
-
if (!pending)
|
|
196
|
-
continue;
|
|
197
|
-
this.pending.delete(message.id);
|
|
198
|
-
clearTimeout(pending.timer);
|
|
199
|
-
if (message.error)
|
|
200
|
-
pending.reject(new LspError(message.error.message ?? 'LSP request failed.'));
|
|
201
|
-
else
|
|
202
|
-
pending.resolve(message.result);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
send(message) {
|
|
206
|
-
const body = JSON.stringify({ ...message, jsonrpc: '2.0' });
|
|
207
|
-
this.child.stdin.write(`Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`);
|
|
208
|
-
}
|
|
209
|
-
request(method, params, timeoutMs = 8000) {
|
|
210
|
-
const id = ++this.id;
|
|
211
|
-
this.send({ id, method, params });
|
|
212
|
-
return new Promise((resolve, reject) => {
|
|
213
|
-
const timer = setTimeout(() => {
|
|
214
|
-
this.pending.delete(id);
|
|
215
|
-
reject(new LspError(`LSP request timed out: ${method}`));
|
|
216
|
-
}, timeoutMs);
|
|
217
|
-
this.pending.set(id, { resolve, reject, timer });
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
notify(method, params) {
|
|
221
|
-
this.send({ method, params });
|
|
222
|
-
}
|
|
223
|
-
async initialize() {
|
|
224
|
-
await this.request('initialize', {
|
|
225
|
-
processId: process.pid,
|
|
226
|
-
rootUri: toUri(workspaceRoot()),
|
|
227
|
-
capabilities: {
|
|
228
|
-
textDocument: {
|
|
229
|
-
documentSymbol: { hierarchicalDocumentSymbolSupport: true },
|
|
230
|
-
definition: { linkSupport: true },
|
|
231
|
-
references: {},
|
|
232
|
-
},
|
|
233
|
-
workspace: { symbol: {} },
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
this.notify('initialized', {});
|
|
237
|
-
}
|
|
238
|
-
async openDocument(absolutePath) {
|
|
239
|
-
const document = await readUtf8Prefix(absolutePath, LSP_DOCUMENT_BYTES);
|
|
240
|
-
if (document.truncated)
|
|
241
|
-
throw new LspError(`LSP document exceeds ${LSP_DOCUMENT_BYTES} byte limit.`);
|
|
242
|
-
const text = document.content;
|
|
243
|
-
this.notify('textDocument/didOpen', {
|
|
244
|
-
textDocument: { uri: toUri(absolutePath), languageId: languageId(absolutePath), version: 1, text },
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
async close() {
|
|
248
|
-
if (this.terminating)
|
|
249
|
-
return;
|
|
250
|
-
try {
|
|
251
|
-
await this.request('shutdown', null, 2000).catch(() => undefined);
|
|
252
|
-
this.notify('exit');
|
|
253
|
-
}
|
|
254
|
-
finally {
|
|
255
|
-
this.terminate();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
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) {
|
|
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.
|
|
313
|
-
const client = StdioLspClient.start(server);
|
|
314
|
-
try {
|
|
315
|
-
await client.initialize();
|
|
316
|
-
await client.openDocument(absolutePath);
|
|
317
|
-
return await fn(client, absolutePath);
|
|
318
|
-
}
|
|
319
|
-
finally {
|
|
320
|
-
await client.close();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
export async function lspDocumentSymbols(server, filePath, limit, pool) {
|
|
324
|
-
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
325
|
-
const result = await client.request('textDocument/documentSymbol', { textDocument: { uri: toUri(absolutePath) } });
|
|
326
|
-
const symbols = Array.isArray(result) ? result : [];
|
|
327
|
-
return flattenSymbols(symbols, workspaceRelativePath(absolutePath), limit);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
export async function lspDefinition(server, filePath, line, character, limit, pool) {
|
|
331
|
-
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
332
|
-
const result = await client.request('textDocument/definition', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 } });
|
|
333
|
-
const values = Array.isArray(result) ? result : result ? [result] : [];
|
|
334
|
-
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
export async function lspReferences(server, filePath, line, character, limit, pool) {
|
|
338
|
-
return await withLspClient(server, filePath, pool, async (client, absolutePath) => {
|
|
339
|
-
const result = await client.request('textDocument/references', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 }, context: { includeDeclaration: true } });
|
|
340
|
-
const values = Array.isArray(result) ? result : [];
|
|
341
|
-
return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
export async function lspWorkspaceSymbols(server, query, limit, pool) {
|
|
345
|
-
const run = async (client) => {
|
|
346
|
-
const result = await client.request('workspace/symbol', { query });
|
|
347
|
-
const values = Array.isArray(result) ? result : [];
|
|
348
|
-
const locations = await Promise.all(values.map(async (value) => {
|
|
349
|
-
if (!isObject(value) || typeof value.name !== 'string')
|
|
350
|
-
return [];
|
|
351
|
-
const location = await locationToWorkspaceResult(value.location);
|
|
352
|
-
if (!location)
|
|
353
|
-
return [];
|
|
354
|
-
return [{ name: value.name, kind: typeof value.kind === 'number' ? value.kind : undefined, ...location }];
|
|
355
|
-
}));
|
|
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);
|
|
364
|
-
}
|
|
365
|
-
finally {
|
|
366
|
-
await client.close();
|
|
367
|
-
}
|
|
368
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Text } from 'ink';
|
|
3
|
-
import { theme } from '../theme.js';
|
|
4
|
-
export function ErrorView({ error }) {
|
|
5
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
6
|
-
return _jsxs(Text, { color: theme.danger, children: ["Error: ", message] });
|
|
7
|
-
}
|
package/dist/utils/yaml.d.ts
DELETED
package/dist/utils/yaml.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: files
|
|
3
|
-
description: Use when the user asks for a careful file-inspection or file-editing workflow.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Use haze's built-in file tools rather than shell commands for file discovery and edits.
|
|
7
|
-
|
|
8
|
-
Workflow:
|
|
9
|
-
1. Use `listFiles` for project discovery.
|
|
10
|
-
2. Use `readFile` before editing existing files.
|
|
11
|
-
3. Prefer `editFile` for small exact changes.
|
|
12
|
-
4. Use `replaceLines` when exact replacement is ambiguous.
|
|
13
|
-
5. Use `writeFile` only for new files or intentional complete rewrites.
|
|
14
|
-
|
|
15
|
-
References:
|
|
16
|
-
- examples/file-editing.md
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|