@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.
Files changed (294) hide show
  1. package/CHANGELOG.md +100 -1
  2. package/README.md +77 -27
  3. package/SECURITY.md +22 -0
  4. package/bin/haze.js +102 -1
  5. package/dist/buildInfo.json +7 -0
  6. package/dist/cli/chat/TaskBar.d.ts +2 -1
  7. package/dist/cli/chat/TaskBar.js +7 -4
  8. package/dist/cli/chat/chatMetrics.d.ts +2 -2
  9. package/dist/cli/chat/chatMetrics.js +1 -1
  10. package/dist/cli/chat/contextReport.js +2 -0
  11. package/dist/cli/chat/fileMentionSuggestions.js +3 -2
  12. package/dist/cli/chat/inputSuggestions.d.ts +8 -16
  13. package/dist/cli/chat/inputSuggestions.js +9 -41
  14. package/dist/cli/chat/liveRegion.d.ts +25 -0
  15. package/dist/cli/chat/liveRegion.js +48 -0
  16. package/dist/cli/chat/messages.d.ts +33 -4
  17. package/dist/cli/chat/messages.js +218 -35
  18. package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
  19. package/dist/cli/chat/sessionLifecycle.js +64 -14
  20. package/dist/cli/chat/sessionRecorder.js +75 -7
  21. package/dist/cli/chat/startupInfo.d.ts +0 -1
  22. package/dist/cli/chat/startupInfo.js +11 -15
  23. package/dist/cli/chat/turnState.d.ts +1 -1
  24. package/dist/cli/chat/wizardDispatch.d.ts +90 -28
  25. package/dist/cli/chat/wizardDispatch.js +349 -133
  26. package/dist/cli/commands/chat.d.ts +5 -0
  27. package/dist/cli/commands/chat.js +216 -172
  28. package/dist/cli/commands/chatModes.d.ts +8 -1
  29. package/dist/cli/commands/chatModes.js +9 -44
  30. package/dist/cli/commands/commands.d.ts +2 -0
  31. package/dist/cli/commands/commands.js +10 -5
  32. package/dist/cli/commands/doctor.d.ts +19 -0
  33. package/dist/cli/commands/doctor.js +76 -0
  34. package/dist/cli/commands/formatters.d.ts +3 -3
  35. package/dist/cli/commands/formatters.js +8 -25
  36. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  37. package/dist/cli/commands/ndjsonSink.js +38 -0
  38. package/dist/cli/commands/providerWizard.d.ts +9 -2
  39. package/dist/cli/commands/providerWizard.js +39 -7
  40. package/dist/cli/commands/runCommand.d.ts +3 -0
  41. package/dist/cli/commands/runCommand.js +117 -11
  42. package/dist/cli/commands/serverWizard.d.ts +34 -0
  43. package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
  44. package/dist/cli/commands/skillsWizard.d.ts +41 -0
  45. package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
  46. package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
  47. package/dist/cli/commands/streaming/abortCause.js +16 -0
  48. package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
  49. package/dist/cli/commands/streaming/agentAttempt.js +79 -0
  50. package/dist/cli/commands/streaming/assistantText.js +9 -2
  51. package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
  52. package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
  53. package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
  54. package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
  55. package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
  56. package/dist/cli/commands/streaming/attemptSetup.js +167 -0
  57. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  58. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  59. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.js +130 -0
  61. package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
  62. package/dist/cli/commands/streaming/stallRecovery.js +105 -0
  63. package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
  64. package/dist/cli/commands/streaming/streamLoop.js +448 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
  66. package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
  68. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
  69. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  70. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  71. package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -0
  73. package/dist/cli/commands/streaming.d.ts +65 -9
  74. package/dist/cli/commands/streaming.js +133 -430
  75. package/dist/cli/commands/wizardFlow.d.ts +334 -0
  76. package/dist/cli/commands/wizardFlow.js +377 -0
  77. package/dist/cli/contextReport.js +3 -0
  78. package/dist/cli/index.js +68 -22
  79. package/dist/cli/terminalTitle.js +1 -1
  80. package/dist/config/contextFiles.js +9 -3
  81. package/dist/config/inputHistory.d.ts +0 -1
  82. package/dist/config/inputHistory.js +1 -1
  83. package/dist/config/modelDiscovery.d.ts +36 -0
  84. package/dist/config/modelDiscovery.js +164 -1
  85. package/dist/config/privateStorage.js +28 -2
  86. package/dist/config/providerAuth.d.ts +14 -0
  87. package/dist/config/providerAuth.js +49 -0
  88. package/dist/config/providerPresets.d.ts +39 -7
  89. package/dist/config/providerPresets.js +371 -100
  90. package/dist/config/providers.js +2 -0
  91. package/dist/config/settings.d.ts +43 -0
  92. package/dist/config/settings.js +12 -0
  93. package/dist/config/skillSettings.js +4 -4
  94. package/dist/config/updateCheck.d.ts +0 -1
  95. package/dist/config/updateCheck.js +1 -1
  96. package/dist/core/agent/budgets.d.ts +73 -1
  97. package/dist/core/agent/budgets.js +94 -1
  98. package/dist/core/agent/compaction.d.ts +38 -0
  99. package/dist/core/agent/compaction.js +92 -17
  100. package/dist/core/agent/completionController.d.ts +224 -0
  101. package/dist/core/agent/completionController.js +296 -0
  102. package/dist/core/agent/contextBudget.d.ts +36 -2
  103. package/dist/core/agent/contextBudget.js +62 -9
  104. package/dist/core/agent/errors.d.ts +0 -1
  105. package/dist/core/agent/errors.js +1 -1
  106. package/dist/core/agent/events.d.ts +78 -0
  107. package/dist/core/agent/goalPolicy.d.ts +47 -0
  108. package/dist/core/agent/goalPolicy.js +106 -0
  109. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  110. package/dist/core/agent/reasoningPolicy.js +27 -0
  111. package/dist/core/agent/requestAssembly.d.ts +2 -2
  112. package/dist/core/agent/requestAssembly.js +16 -4
  113. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  114. package/dist/core/agent/toolCapabilities.js +58 -0
  115. package/dist/core/agent/toolOutputStore.d.ts +8 -0
  116. package/dist/core/agent/toolOutputStore.js +11 -11
  117. package/dist/core/agent/toolResults.d.ts +12 -0
  118. package/dist/core/agent/toolResults.js +38 -0
  119. package/dist/core/agent/turnPolicy.d.ts +11 -0
  120. package/dist/core/agent/turnPolicy.js +19 -0
  121. package/dist/core/agent/workState.d.ts +81 -3
  122. package/dist/core/agent/workState.js +176 -10
  123. package/dist/core/attachments/imageAttachments.js +90 -42
  124. package/dist/core/deadline.d.ts +27 -0
  125. package/dist/core/deadline.js +74 -0
  126. package/dist/core/io/boundedRead.js +1 -1
  127. package/dist/core/limits.d.ts +51 -0
  128. package/dist/core/limits.js +51 -0
  129. package/dist/core/log/llmLog.js +8 -1
  130. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  131. package/dist/core/persistence/orderedFileWriter.js +16 -2
  132. package/dist/core/process/backgroundRegistry.d.ts +2 -3
  133. package/dist/core/process/backgroundRegistry.js +15 -10
  134. package/dist/core/process/runBoundedProcess.d.ts +8 -2
  135. package/dist/core/process/runBoundedProcess.js +15 -6
  136. package/dist/core/process/userShell.d.ts +16 -0
  137. package/dist/core/process/userShell.js +59 -0
  138. package/dist/core/safety/missingExecutable.d.ts +42 -0
  139. package/dist/core/safety/missingExecutable.js +77 -0
  140. package/dist/core/safety/shellClassifier.d.ts +11 -0
  141. package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
  142. package/dist/core/safety/urlGuard.d.ts +1 -1
  143. package/dist/core/session/sessionSlimming.d.ts +0 -3
  144. package/dist/core/session/sessionSlimming.js +2 -3
  145. package/dist/core/session/sessionStore.d.ts +38 -0
  146. package/dist/core/session/sessionStore.js +242 -59
  147. package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
  148. package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
  149. package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
  150. package/dist/core/shellOutput/registry.d.ts +2 -0
  151. package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
  152. package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
  153. package/dist/core/subagent/contracts.d.ts +6 -14
  154. package/dist/core/subagent/contracts.js +4 -3
  155. package/dist/core/subagent/executionProfiles.js +2 -2
  156. package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
  157. package/dist/core/subagent/subagentCoordinator.js +32 -2
  158. package/dist/core/subagent/subagentRunner.js +19 -40
  159. package/dist/core/toolOutput/reduction.d.ts +0 -12
  160. package/dist/core/toolOutput/reduction.js +1 -1
  161. package/dist/core/validation/outputParser.d.ts +2 -2
  162. package/dist/llm/client.d.ts +17 -1
  163. package/dist/llm/client.js +86 -14
  164. package/dist/llm/hazeTools.d.ts +693 -204
  165. package/dist/llm/hazeTools.js +110 -28
  166. package/dist/llm/initPrompt.js +1 -1
  167. package/dist/llm/lsp/client.d.ts +45 -0
  168. package/dist/llm/lsp/client.js +195 -0
  169. package/dist/llm/lsp/pool.d.ts +23 -0
  170. package/dist/llm/lsp/pool.js +86 -0
  171. package/dist/llm/lsp/protocol.d.ts +64 -0
  172. package/dist/llm/lsp/protocol.js +128 -0
  173. package/dist/llm/lsp/requests.d.ts +94 -0
  174. package/dist/llm/lsp/requests.js +119 -0
  175. package/dist/llm/lspTools.d.ts +5653 -33
  176. package/dist/llm/lspTools.js +152 -80
  177. package/dist/llm/openaiCodex.d.ts +1 -0
  178. package/dist/llm/openaiCodex.js +43 -0
  179. package/dist/llm/openaiCodexOAuth.d.ts +51 -0
  180. package/dist/llm/openaiCodexOAuth.js +217 -0
  181. package/dist/llm/requestContext.d.ts +7 -0
  182. package/dist/llm/requestContext.js +30 -4
  183. package/dist/llm/systemPrompt.d.ts +12 -0
  184. package/dist/llm/systemPrompt.js +24 -11
  185. package/dist/llm/toolResultTypes.d.ts +7 -14
  186. package/dist/llm/toolResultTypes.js +1 -4
  187. package/dist/llm/tools/editMatch.d.ts +14 -9
  188. package/dist/llm/tools/editMatch.js +73 -1
  189. package/dist/llm/tools/failures.d.ts +2 -0
  190. package/dist/llm/tools/failures.js +1 -0
  191. package/dist/llm/tools/fetchTool.d.ts +16 -0
  192. package/dist/llm/tools/fetchTool.js +1 -1
  193. package/dist/llm/tools/fileToolShared.d.ts +8 -5
  194. package/dist/llm/tools/fileToolShared.js +22 -23
  195. package/dist/llm/tools/gitIgnore.d.ts +42 -0
  196. package/dist/llm/tools/gitIgnore.js +247 -0
  197. package/dist/llm/tools/grepParse.d.ts +2 -1
  198. package/dist/llm/tools/grepRunner.d.ts +1 -1
  199. package/dist/llm/tools/grepRunner.js +2 -2
  200. package/dist/llm/tools/outputCap.d.ts +2 -7
  201. package/dist/llm/tools/outputCap.js +3 -3
  202. package/dist/llm/tools/processTool.d.ts +16 -16
  203. package/dist/llm/tools/processTool.js +1 -1
  204. package/dist/llm/tools/readRecovery.d.ts +8 -0
  205. package/dist/llm/tools/readRecovery.js +135 -0
  206. package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
  207. package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
  208. package/dist/llm/tools/toolContext.d.ts +1 -1
  209. package/dist/llm/tools/toolContext.js +66 -37
  210. package/dist/llm/tools/workspaceFile.d.ts +0 -1
  211. package/dist/llm/tools/workspaceFile.js +1 -6
  212. package/dist/llm/webFetch.d.ts +18 -1
  213. package/dist/llm/webFetch.js +64 -97
  214. package/dist/skills/SkillLoader.d.ts +1 -11
  215. package/dist/skills/SkillLoader.js +1 -2
  216. package/dist/skills/types.d.ts +2 -1
  217. package/dist/ui/codeHighlight.d.ts +4 -0
  218. package/dist/ui/codeHighlight.js +31 -0
  219. package/dist/ui/components/Header.d.ts +1 -1
  220. package/dist/ui/components/MarkdownText.d.ts +16 -2
  221. package/dist/ui/components/MarkdownText.js +244 -34
  222. package/dist/ui/components/TextInput.d.ts +8 -1
  223. package/dist/ui/components/TextInput.js +6 -2
  224. package/dist/ui/theme.d.ts +4 -3
  225. package/dist/ui/theme.js +5 -4
  226. package/dist/utils/buildInfo.d.ts +97 -0
  227. package/dist/utils/buildInfo.js +244 -0
  228. package/dist/utils/fs.d.ts +11 -0
  229. package/dist/utils/fs.js +91 -26
  230. package/dist/utils/openPath.d.ts +2 -2
  231. package/dist/utils/openPath.js +19 -6
  232. package/dist/utils/path.d.ts +2 -1
  233. package/dist/utils/path.js +6 -2
  234. package/dist/utils/utf8.d.ts +22 -0
  235. package/dist/utils/utf8.js +54 -0
  236. package/dist/utils/version.d.ts +9 -3
  237. package/dist/utils/version.js +28 -2
  238. package/package.json +28 -21
  239. package/dist/cli/commands/lspWizard.d.ts +0 -14
  240. package/dist/cli/commands/lspWizard.js +0 -44
  241. package/dist/cli/commands/mcpWizard.d.ts +0 -15
  242. package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
  243. package/dist/cli/commands/skillConfirmRemove.js +0 -20
  244. package/dist/cli/commands/skillCreation.d.ts +0 -12
  245. package/dist/cli/commands/skillCreation.js +0 -14
  246. package/dist/cli/commands/skillWizard.d.ts +0 -17
  247. package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
  248. package/dist/cli/commands/streaming/idleTimer.js +0 -24
  249. package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
  250. package/dist/cli/commands/streaming/turnOutcome.js +0 -13
  251. package/dist/cli/commands/wizardActions.d.ts +0 -46
  252. package/dist/cli/commands/wizardActions.js +0 -46
  253. package/dist/cli/commands/wizardInput.d.ts +0 -4
  254. package/dist/cli/commands/wizardInput.js +0 -19
  255. package/dist/cli/commands/wizardPrompts.d.ts +0 -22
  256. package/dist/cli/commands/wizardPrompts.js +0 -52
  257. package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
  258. package/dist/cli/commands/wizardSuggestions.js +0 -188
  259. package/dist/cli/commands/wizardTransition.d.ts +0 -37
  260. package/dist/cli/commands/wizardTransition.js +0 -43
  261. package/dist/core/bashOutput/ansi.d.ts +0 -1
  262. package/dist/core/bashOutput/ansi.js +0 -7
  263. package/dist/core/bashOutput/registry.d.ts +0 -4
  264. package/dist/core/goal/completionPolicy.d.ts +0 -2
  265. package/dist/core/goal/completionPolicy.js +0 -7
  266. package/dist/core/goal/requestClassifier.d.ts +0 -3
  267. package/dist/core/goal/requestClassifier.js +0 -18
  268. package/dist/core/goal/sessionGoal.d.ts +0 -8
  269. package/dist/core/goal/sessionGoal.js +0 -30
  270. package/dist/core/limits/byteBudgets.d.ts +0 -18
  271. package/dist/core/limits/byteBudgets.js +0 -18
  272. package/dist/core/limits/textBudgets.d.ts +0 -23
  273. package/dist/core/limits/textBudgets.js +0 -23
  274. package/dist/core/safety/bashClassifier.d.ts +0 -10
  275. package/dist/llm/lsp.d.ts +0 -129
  276. package/dist/llm/lsp.js +0 -307
  277. package/dist/ui/components/ErrorView.d.ts +0 -4
  278. package/dist/ui/components/ErrorView.js +0 -7
  279. package/dist/utils/yaml.d.ts +0 -2
  280. package/dist/utils/yaml.js +0 -8
  281. package/examples/skills/files/SKILL.md +0 -16
  282. package/examples/skills/files/examples/file-editing.md +0 -3
  283. /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
  284. /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
  285. /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
  286. /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
  287. /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
  288. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
  289. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
  290. /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
  291. /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
  292. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
  293. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
  294. /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
package/dist/llm/lsp.js DELETED
@@ -1,307 +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
- onData(chunk) {
163
- if (this.buffer.length + chunk.length > LSP_BUFFER_BYTES)
164
- throw new LspError(`LSP receive buffer exceeds ${LSP_BUFFER_BYTES} bytes.`);
165
- this.buffer = Buffer.concat([this.buffer, chunk]);
166
- while (true) {
167
- const headerEnd = this.buffer.indexOf('\r\n\r\n');
168
- if (headerEnd === -1) {
169
- if (this.buffer.length > LSP_HEADER_BYTES)
170
- throw new LspError(`LSP header exceeds ${LSP_HEADER_BYTES} bytes.`);
171
- return;
172
- }
173
- if (headerEnd > LSP_HEADER_BYTES)
174
- throw new LspError(`LSP header exceeds ${LSP_HEADER_BYTES} bytes.`);
175
- const header = this.buffer.slice(0, headerEnd).toString('utf8');
176
- const match = /Content-Length: (\d+)/i.exec(header);
177
- if (!match)
178
- throw new LspError('Malformed LSP response: missing Content-Length.');
179
- const length = Number(match[1]);
180
- if (!Number.isSafeInteger(length) || length < 0 || length > LSP_FRAME_BYTES)
181
- throw new LspError(`LSP frame exceeds ${LSP_FRAME_BYTES} bytes.`);
182
- const bodyStart = headerEnd + 4;
183
- if (this.buffer.length < bodyStart + length)
184
- return;
185
- const raw = this.buffer.slice(bodyStart, bodyStart + length).toString('utf8');
186
- this.buffer = this.buffer.slice(bodyStart + length);
187
- const message = JSON.parse(raw);
188
- if (typeof message.id !== 'number')
189
- continue;
190
- const pending = this.pending.get(message.id);
191
- if (!pending)
192
- continue;
193
- this.pending.delete(message.id);
194
- clearTimeout(pending.timer);
195
- if (message.error)
196
- pending.reject(new LspError(message.error.message ?? 'LSP request failed.'));
197
- else
198
- pending.resolve(message.result);
199
- }
200
- }
201
- send(message) {
202
- const body = JSON.stringify({ ...message, jsonrpc: '2.0' });
203
- this.child.stdin.write(`Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`);
204
- }
205
- request(method, params, timeoutMs = 8000) {
206
- const id = ++this.id;
207
- this.send({ id, method, params });
208
- return new Promise((resolve, reject) => {
209
- const timer = setTimeout(() => {
210
- this.pending.delete(id);
211
- reject(new LspError(`LSP request timed out: ${method}`));
212
- }, timeoutMs);
213
- this.pending.set(id, { resolve, reject, timer });
214
- });
215
- }
216
- notify(method, params) {
217
- this.send({ method, params });
218
- }
219
- async initialize() {
220
- await this.request('initialize', {
221
- processId: process.pid,
222
- rootUri: toUri(workspaceRoot()),
223
- capabilities: {
224
- textDocument: {
225
- documentSymbol: { hierarchicalDocumentSymbolSupport: true },
226
- definition: { linkSupport: true },
227
- references: {},
228
- },
229
- workspace: { symbol: {} },
230
- },
231
- });
232
- this.notify('initialized', {});
233
- }
234
- async openDocument(absolutePath) {
235
- const document = await readUtf8Prefix(absolutePath, LSP_DOCUMENT_BYTES);
236
- if (document.truncated)
237
- throw new LspError(`LSP document exceeds ${LSP_DOCUMENT_BYTES} byte limit.`);
238
- const text = document.content;
239
- this.notify('textDocument/didOpen', {
240
- textDocument: { uri: toUri(absolutePath), languageId: languageId(absolutePath), version: 1, text },
241
- });
242
- }
243
- async close() {
244
- if (this.terminating)
245
- return;
246
- try {
247
- await this.request('shutdown', null, 2000).catch(() => undefined);
248
- this.notify('exit');
249
- }
250
- finally {
251
- this.terminate();
252
- }
253
- }
254
- }
255
- async function withLsp(server, filePath, fn) {
256
- const absolutePath = await prepareWorkspaceRead(filePath, false);
257
- const client = StdioLspClient.start(server);
258
- try {
259
- await client.initialize();
260
- await client.openDocument(absolutePath);
261
- return await fn(client, absolutePath);
262
- }
263
- finally {
264
- await client.close();
265
- }
266
- }
267
- export async function lspDocumentSymbols(server, filePath, limit) {
268
- return await withLsp(server, filePath, async (client, absolutePath) => {
269
- const result = await client.request('textDocument/documentSymbol', { textDocument: { uri: toUri(absolutePath) } });
270
- const symbols = Array.isArray(result) ? result : [];
271
- return flattenSymbols(symbols, workspaceRelativePath(absolutePath), limit);
272
- });
273
- }
274
- export async function lspDefinition(server, filePath, line, character, limit) {
275
- return await withLsp(server, filePath, async (client, absolutePath) => {
276
- const result = await client.request('textDocument/definition', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 } });
277
- const values = Array.isArray(result) ? result : result ? [result] : [];
278
- return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
279
- });
280
- }
281
- export async function lspReferences(server, filePath, line, character, limit) {
282
- return await withLsp(server, filePath, async (client, absolutePath) => {
283
- const result = await client.request('textDocument/references', { textDocument: { uri: toUri(absolutePath) }, position: { line: line - 1, character: character - 1 }, context: { includeDeclaration: true } });
284
- const values = Array.isArray(result) ? result : [];
285
- return (await Promise.all(values.map(locationToWorkspaceResult))).filter(result => result != null).slice(0, limit);
286
- });
287
- }
288
- export async function lspWorkspaceSymbols(server, query, limit) {
289
- const client = StdioLspClient.start(server);
290
- try {
291
- await client.initialize();
292
- const result = await client.request('workspace/symbol', { query });
293
- const values = Array.isArray(result) ? result : [];
294
- const locations = await Promise.all(values.map(async (value) => {
295
- if (!isObject(value) || typeof value.name !== 'string')
296
- return [];
297
- const location = await locationToWorkspaceResult(value.location);
298
- if (!location)
299
- return [];
300
- return [{ name: value.name, kind: typeof value.kind === 'number' ? value.kind : undefined, ...location }];
301
- }));
302
- return locations.flat().slice(0, limit);
303
- }
304
- finally {
305
- await client.close();
306
- }
307
- }
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- export declare function ErrorView({ error }: {
3
- error: unknown;
4
- }): React.JSX.Element;
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export declare function readYaml<T>(file: string): Promise<T>;
2
- export declare function writeYaml(file: string, value: unknown): Promise<void>;
@@ -1,8 +0,0 @@
1
- import fs from 'fs-extra';
2
- import YAML from 'yaml';
3
- export async function readYaml(file) {
4
- return YAML.parse(await fs.readFile(file, 'utf8'));
5
- }
6
- export async function writeYaml(file, value) {
7
- await fs.writeFile(file, YAML.stringify(value));
8
- }
@@ -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
@@ -1,3 +0,0 @@
1
- # File editing example
2
-
3
- When changing existing files, inspect the current contents first, make the smallest targeted edit, then run the relevant validation command when practical.
File without changes