@denizokcu/haze 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +133 -17
  2. package/README.md +164 -68
  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 +17 -1
  9. package/dist/cli/chat/chatMetrics.js +22 -5
  10. package/dist/cli/chat/contextReport.d.ts +11 -0
  11. package/dist/cli/chat/contextReport.js +46 -0
  12. package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
  13. package/dist/cli/chat/fileMentionSuggestions.js +92 -0
  14. package/dist/cli/chat/inputSuggestions.d.ts +5 -0
  15. package/dist/cli/chat/inputSuggestions.js +17 -3
  16. package/dist/cli/chat/liveRegion.d.ts +25 -0
  17. package/dist/cli/chat/liveRegion.js +48 -0
  18. package/dist/cli/chat/messages.d.ts +33 -2
  19. package/dist/cli/chat/messages.js +216 -33
  20. package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
  21. package/dist/cli/chat/sessionLifecycle.js +205 -0
  22. package/dist/cli/chat/sessionRecorder.js +80 -14
  23. package/dist/cli/chat/startupInfo.js +11 -4
  24. package/dist/cli/chat/tips.d.ts +21 -0
  25. package/dist/cli/chat/tips.js +43 -0
  26. package/dist/cli/chat/wizardDispatch.d.ts +64 -0
  27. package/dist/cli/chat/wizardDispatch.js +744 -0
  28. package/dist/cli/commands/chat.d.ts +6 -0
  29. package/dist/cli/commands/chat.js +373 -790
  30. package/dist/cli/commands/chatModes.d.ts +1 -1
  31. package/dist/cli/commands/chatModes.js +7 -2
  32. package/dist/cli/commands/commandHelp.js +5 -3
  33. package/dist/cli/commands/commands.d.ts +5 -2
  34. package/dist/cli/commands/commands.js +22 -18
  35. package/dist/cli/commands/doctor.d.ts +19 -0
  36. package/dist/cli/commands/doctor.js +76 -0
  37. package/dist/cli/commands/fleetCommand.d.ts +14 -0
  38. package/dist/cli/commands/fleetCommand.js +46 -0
  39. package/dist/cli/commands/formatters.d.ts +5 -0
  40. package/dist/cli/commands/formatters.js +35 -6
  41. package/dist/cli/commands/logsCommand.js +1 -7
  42. package/dist/cli/commands/modelCommand.js +1 -1
  43. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  44. package/dist/cli/commands/ndjsonSink.js +38 -0
  45. package/dist/cli/commands/providerWizard.d.ts +10 -2
  46. package/dist/cli/commands/providerWizard.js +50 -4
  47. package/dist/cli/commands/runCommand.d.ts +4 -0
  48. package/dist/cli/commands/runCommand.js +142 -16
  49. package/dist/cli/commands/sessionPicker.d.ts +9 -0
  50. package/dist/cli/commands/sessionPicker.js +29 -0
  51. package/dist/cli/commands/settingsSummary.js +6 -4
  52. package/dist/cli/commands/skillConfirmRemove.js +4 -3
  53. package/dist/cli/commands/skillWizard.d.ts +2 -0
  54. package/dist/cli/commands/skillWizard.js +16 -6
  55. package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
  56. package/dist/cli/commands/streaming/abortCause.js +16 -0
  57. package/dist/cli/commands/streaming/assistantText.js +9 -2
  58. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  59. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  61. package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
  62. package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
  63. package/dist/cli/commands/streaming/idleTimer.js +24 -0
  64. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
  66. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
  68. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  69. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  70. package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
  71. package/dist/cli/commands/streaming/turnOutcome.js +27 -11
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -4
  73. package/dist/cli/commands/streaming.d.ts +82 -3
  74. package/dist/cli/commands/streaming.js +528 -91
  75. package/dist/cli/commands/wizardActions.d.ts +7 -0
  76. package/dist/cli/commands/wizardActions.js +7 -0
  77. package/dist/cli/commands/wizardPrompts.js +7 -1
  78. package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
  79. package/dist/cli/commands/wizardSuggestions.js +64 -14
  80. package/dist/cli/commands/wizardTransition.d.ts +4 -0
  81. package/dist/cli/commands/wizardTransition.js +1 -2
  82. package/dist/cli/index.js +82 -22
  83. package/dist/cli/terminalTitle.d.ts +6 -0
  84. package/dist/cli/terminalTitle.js +36 -0
  85. package/dist/config/inputHistory.d.ts +3 -3
  86. package/dist/config/inputHistory.js +12 -18
  87. package/dist/config/modelDiscovery.d.ts +71 -0
  88. package/dist/config/modelDiscovery.js +214 -0
  89. package/dist/config/privateStorage.js +28 -2
  90. package/dist/config/providerAuth.d.ts +14 -0
  91. package/dist/config/providerAuth.js +49 -0
  92. package/dist/config/providerPresets.d.ts +49 -5
  93. package/dist/config/providerPresets.js +573 -73
  94. package/dist/config/providers.d.ts +2 -0
  95. package/dist/config/providers.js +9 -0
  96. package/dist/config/settings.d.ts +58 -0
  97. package/dist/config/settings.js +38 -1
  98. package/dist/config/skillSettings.d.ts +6 -13
  99. package/dist/config/skillSettings.js +20 -19
  100. package/dist/core/agent/budgets.d.ts +36 -0
  101. package/dist/core/agent/budgets.js +44 -0
  102. package/dist/core/agent/compaction.d.ts +38 -0
  103. package/dist/core/agent/compaction.js +108 -19
  104. package/dist/core/agent/completionController.d.ts +230 -0
  105. package/dist/core/agent/completionController.js +287 -0
  106. package/dist/core/agent/contextBudget.d.ts +46 -0
  107. package/dist/core/agent/contextBudget.js +89 -7
  108. package/dist/core/agent/errors.js +6 -2
  109. package/dist/core/agent/events.d.ts +86 -0
  110. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  111. package/dist/core/agent/reasoningPolicy.js +27 -0
  112. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  113. package/dist/core/agent/toolCapabilities.js +58 -0
  114. package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
  115. package/dist/core/agent/toolExecutionBudget.js +49 -0
  116. package/dist/core/agent/toolOutputStore.d.ts +13 -0
  117. package/dist/core/agent/toolOutputStore.js +27 -10
  118. package/dist/core/agent/toolResults.d.ts +12 -0
  119. package/dist/core/agent/toolResults.js +38 -0
  120. package/dist/core/agent/turnBudget.d.ts +35 -0
  121. package/dist/core/agent/turnBudget.js +27 -0
  122. package/dist/core/agent/turnPolicy.d.ts +11 -0
  123. package/dist/core/agent/turnPolicy.js +19 -0
  124. package/dist/core/agent/workState.d.ts +76 -1
  125. package/dist/core/agent/workState.js +120 -13
  126. package/dist/core/attachments/imageAttachments.d.ts +90 -0
  127. package/dist/core/attachments/imageAttachments.js +245 -0
  128. package/dist/core/attachments/readBlessings.d.ts +37 -0
  129. package/dist/core/attachments/readBlessings.js +79 -0
  130. package/dist/core/deadline.d.ts +33 -0
  131. package/dist/core/deadline.js +74 -0
  132. package/dist/core/goal/completionPolicy.d.ts +27 -0
  133. package/dist/core/goal/completionPolicy.js +37 -1
  134. package/dist/core/goal/requestClassifier.d.ts +0 -3
  135. package/dist/core/goal/requestClassifier.js +0 -13
  136. package/dist/core/io/boundedRead.js +76 -29
  137. package/dist/core/limits/byteBudgets.d.ts +7 -0
  138. package/dist/core/limits/byteBudgets.js +7 -0
  139. package/dist/core/limits/textBudgets.d.ts +25 -0
  140. package/dist/core/limits/textBudgets.js +25 -0
  141. package/dist/core/log/llmLog.js +7 -0
  142. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  143. package/dist/core/persistence/orderedFileWriter.js +16 -2
  144. package/dist/core/process/backgroundRegistry.d.ts +35 -0
  145. package/dist/core/process/backgroundRegistry.js +195 -0
  146. package/dist/core/process/runBoundedProcess.d.ts +9 -0
  147. package/dist/core/process/runBoundedProcess.js +74 -29
  148. package/dist/core/safety/missingExecutable.d.ts +42 -0
  149. package/dist/core/safety/missingExecutable.js +77 -0
  150. package/dist/core/safety/urlGuard.d.ts +2 -1
  151. package/dist/core/safety/urlGuard.js +3 -2
  152. package/dist/core/session/sessionSlimming.js +47 -4
  153. package/dist/core/session/sessionStore.d.ts +74 -0
  154. package/dist/core/session/sessionStore.js +268 -18
  155. package/dist/core/subagent/contracts.d.ts +120 -0
  156. package/dist/core/subagent/contracts.js +55 -0
  157. package/dist/core/subagent/executionProfiles.d.ts +28 -0
  158. package/dist/core/subagent/executionProfiles.js +45 -0
  159. package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
  160. package/dist/core/subagent/subagentCoordinator.js +164 -0
  161. package/dist/core/subagent/subagentRunner.d.ts +211 -145
  162. package/dist/core/subagent/subagentRunner.js +208 -98
  163. package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
  164. package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
  165. package/dist/core/tasks/taskStorage.js +12 -1
  166. package/dist/llm/client.d.ts +36 -29
  167. package/dist/llm/client.js +102 -33
  168. package/dist/llm/hazeTools.d.ts +2559 -150
  169. package/dist/llm/hazeTools.js +119 -31
  170. package/dist/llm/lsp.d.ts +26 -4
  171. package/dist/llm/lsp.js +90 -14
  172. package/dist/llm/lspTools.d.ts +2366 -0
  173. package/dist/llm/lspTools.js +87 -79
  174. package/dist/llm/openaiCodex.d.ts +3 -0
  175. package/dist/llm/openaiCodex.js +47 -0
  176. package/dist/llm/openaiCodexOAuth.d.ts +54 -0
  177. package/dist/llm/openaiCodexOAuth.js +214 -0
  178. package/dist/llm/requestContext.d.ts +25 -1
  179. package/dist/llm/requestContext.js +51 -8
  180. package/dist/llm/systemPrompt.d.ts +15 -1
  181. package/dist/llm/systemPrompt.js +24 -8
  182. package/dist/llm/toolResultTypes.d.ts +8 -1
  183. package/dist/llm/tools/bashTool.d.ts +906 -32
  184. package/dist/llm/tools/bashTool.js +30 -4
  185. package/dist/llm/tools/editMatch.d.ts +14 -0
  186. package/dist/llm/tools/editMatch.js +72 -0
  187. package/dist/llm/tools/failures.d.ts +2 -0
  188. package/dist/llm/tools/failures.js +1 -0
  189. package/dist/llm/tools/fetchTool.d.ts +42 -26
  190. package/dist/llm/tools/fetchTool.js +1 -1
  191. package/dist/llm/tools/fileToolShared.d.ts +6 -4
  192. package/dist/llm/tools/fileToolShared.js +18 -23
  193. package/dist/llm/tools/gitIgnore.d.ts +49 -0
  194. package/dist/llm/tools/gitIgnore.js +129 -0
  195. package/dist/llm/tools/grepRunner.d.ts +5 -0
  196. package/dist/llm/tools/grepRunner.js +52 -71
  197. package/dist/llm/tools/outputCap.d.ts +2 -6
  198. package/dist/llm/tools/outputCap.js +2 -6
  199. package/dist/llm/tools/processTool.d.ts +1077 -0
  200. package/dist/llm/tools/processTool.js +41 -0
  201. package/dist/llm/tools/readRecovery.d.ts +10 -0
  202. package/dist/llm/tools/readRecovery.js +135 -0
  203. package/dist/llm/tools/toolContext.d.ts +9 -1
  204. package/dist/llm/tools/toolContext.js +83 -43
  205. package/dist/llm/tools/workspaceFile.d.ts +9 -1
  206. package/dist/llm/tools/workspaceFile.js +33 -4
  207. package/dist/llm/webFetch.d.ts +17 -0
  208. package/dist/llm/webFetch.js +66 -86
  209. package/dist/llm/workerContext.d.ts +18 -0
  210. package/dist/llm/workerContext.js +55 -0
  211. package/dist/skills/SkillLoader.d.ts +2 -2
  212. package/dist/skills/SkillRegistry.d.ts +3 -2
  213. package/dist/skills/SkillRegistry.js +43 -13
  214. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  215. package/dist/skills/builder/SkillBuilder.js +23 -5
  216. package/dist/skills/skillTools.js +11 -4
  217. package/dist/skills/types.d.ts +6 -1
  218. package/dist/ui/codeHighlight.d.ts +4 -0
  219. package/dist/ui/codeHighlight.js +31 -0
  220. package/dist/ui/components/Header.d.ts +1 -1
  221. package/dist/ui/components/MarkdownText.d.ts +16 -2
  222. package/dist/ui/components/MarkdownText.js +244 -34
  223. package/dist/ui/components/TextInput.d.ts +12 -2
  224. package/dist/ui/components/TextInput.js +80 -8
  225. package/dist/ui/theme.d.ts +4 -3
  226. package/dist/ui/theme.js +5 -4
  227. package/dist/utils/buildInfo.d.ts +104 -0
  228. package/dist/utils/buildInfo.js +253 -0
  229. package/dist/utils/format.d.ts +2 -0
  230. package/dist/utils/format.js +8 -0
  231. package/dist/utils/fs.d.ts +9 -1
  232. package/dist/utils/fs.js +87 -29
  233. package/dist/utils/openPath.d.ts +2 -0
  234. package/dist/utils/openPath.js +22 -0
  235. package/dist/utils/path.d.ts +2 -0
  236. package/dist/utils/path.js +5 -1
  237. package/dist/utils/utf8.d.ts +22 -0
  238. package/dist/utils/utf8.js +54 -0
  239. package/dist/utils/version.d.ts +9 -3
  240. package/dist/utils/version.js +28 -2
  241. package/package.json +24 -19
@@ -1,15 +1,21 @@
1
1
  import { tool } from 'ai';
2
2
  import { z } from 'zod';
3
3
  import { classifyBashCommand, isValidationClassification } from '../../core/safety/bashClassifier.js';
4
+ import { detectMissingExecutable, missingExecutableFields } from '../../core/safety/missingExecutable.js';
4
5
  import { parseValidationOutput } from '../../core/validation/outputParser.js';
5
6
  import { filterBashOutput } from '../../core/bashOutput/registry.js';
6
7
  import { storeToolOutput } from '../../core/agent/toolOutputStore.js';
7
8
  import { workspaceRoot } from '../../utils/path.js';
8
9
  import { compactStoredOutput, COMPACT_COMMAND_CHARS } from './outputCap.js';
9
- import { hazeToolContextSchema, runDedupedTool } from './toolContext.js';
10
+ import { hazeContext, hazeToolContextSchema, runDedupedTool } from './toolContext.js';
10
11
  import { runBoundedProcess } from '../../core/process/runBoundedProcess.js';
11
12
  import { BASH_STREAM_BYTES } from '../../core/limits/byteBudgets.js';
12
- const SHORT_VALIDATION_CHARS = 2_000;
13
+ import { SHORT_VALIDATION_CHARS } from '../../core/limits/textBudgets.js';
14
+ import { startBackgroundProcess } from '../../core/process/backgroundRegistry.js';
15
+ /** Byte-stat metadata only — the raw stream text must never reach the model context (see code-review CR-001). */
16
+ function streamByteStats(stream) {
17
+ return { totalBytes: stream.totalBytes, retainedBytes: stream.retainedBytes, omittedBytes: stream.omittedBytes };
18
+ }
13
19
  export const bashTool = tool({
14
20
  description: 'Run workspace tests, builds, validation, or inspection. Risk classification is informational; use file tools for edits.',
15
21
  contextSchema: hazeToolContextSchema,
@@ -17,10 +23,26 @@ export const bashTool = tool({
17
23
  command: z.string().min(1).describe('Command to execute with bash -lc'),
18
24
  timeoutSeconds: z.number().int().positive().max(600).optional().describe('Timeout in seconds; defaults to 60'),
19
25
  allowMutation: z.boolean().default(false).describe('Deprecated compatibility flag. Commands run without confirmation; retained for compatibility.'),
26
+ background: z.boolean().default(false).describe('Start a registered long-running process and return immediately. Use process to list, inspect output, or kill it.'),
20
27
  }),
21
- execute: async ({ command, timeoutSeconds }, context) => runDedupedTool('bash', { command, timeoutSeconds }, context, async () => {
28
+ execute: async ({ command, timeoutSeconds, background }, context) => runDedupedTool('bash', { command, timeoutSeconds, background }, context, async () => {
22
29
  const cwd = workspaceRoot();
23
30
  const classification = classifyBashCommand(command);
31
+ if (background) {
32
+ if (hazeContext(context)?.isSubagent) {
33
+ return { ok: false, command, reasonCode: 'background_not_allowed', recoverable: false, error: 'Background processes are available only to the main haze turn, not fleet workers.', suggestedNextStep: 'Run the server from the main conversation.' };
34
+ }
35
+ if (context.abortSignal?.aborted) {
36
+ return { ok: false, command, reasonCode: 'aborted', recoverable: true, error: 'Background process was not started because the turn is already aborted.', suggestedNextStep: 'Retry when the turn is active.' };
37
+ }
38
+ try {
39
+ const started = startBackgroundProcess({ command, cwd });
40
+ return { ok: true, background: true, ...started, classification, hint: `Use readToolOutput with handle ${started.outputHandle} for logs, or process action=kill backgroundId=${started.backgroundId} when done.` };
41
+ }
42
+ catch (error) {
43
+ return { ok: false, background: true, command, reasonCode: 'background_limit', recoverable: true, error: error instanceof Error ? error.message : String(error), suggestedNextStep: 'List background processes and kill one before retrying.' };
44
+ }
45
+ }
24
46
  const timeoutMs = (timeoutSeconds ?? 60) * 1000;
25
47
  const startedAt = Date.now();
26
48
  const processResult = await runBoundedProcess({ command: 'bash', args: ['-lc', command], cwd, timeoutMs, signal: context.abortSignal, maxStdoutBytes: BASH_STREAM_BYTES, maxStderrBytes: BASH_STREAM_BYTES });
@@ -32,12 +54,16 @@ export const bashTool = tool({
32
54
  : undefined;
33
55
  const validationPassed = validationSummary?.status === 'passed';
34
56
  const output = filterBashOutput({ command, code, stdout, stderr, timedOut, classification, validationSummary, storeRawOutput: storeToolOutput, fallbackCompact: compactStoredOutput, compactMaxChars: validationPassed ? SHORT_VALIDATION_CHARS : COMPACT_COMMAND_CHARS });
57
+ // Generic, dependency-agnostic diagnostic for a missing executable. Only the
58
+ // executable name and a generic next step are exposed (never raw stderr).
59
+ const missing = code !== 0 && !processResult.aborted ? detectMissingExecutable({ command, code, stderr }) : undefined;
35
60
  return {
36
61
  ok: code === 0 && !timedOut && !processResult.aborted && !processResult.error,
37
62
  code, command, cwd, classification, durationMs: Date.now() - startedAt, timedOut,
38
63
  aborted: processResult.aborted, signal: processResult.signal, forcedTermination: processResult.forced,
39
64
  stdout: output.stdout, stderr: output.stderr, validationSummary,
40
- stdoutBytes: processResult.stdout, stderrBytes: processResult.stderr,
65
+ stdoutBytes: streamByteStats(processResult.stdout), stderrBytes: streamByteStats(processResult.stderr),
66
+ ...(missing ? { ...missingExecutableFields(missing), missingExecutableStep: missing.suggestedNextStep } : {}),
41
67
  ...(processResult.error ? { error: processResult.error } : {}),
42
68
  };
43
69
  }),
@@ -53,3 +53,17 @@ export declare function replacementDiff(oldText: string, newText: string, oldSta
53
53
  addedLines: number;
54
54
  removedLines: number;
55
55
  };
56
+ /** Build a compact whole-file diff by trimming unchanged leading/trailing lines. */
57
+ export declare function fileDiff(oldText: string, newText: string): {
58
+ diff: ToolDiffLine[];
59
+ addedLines: number;
60
+ removedLines: number;
61
+ };
62
+ /** Keep every mutation visible while bounding the inline result size. */
63
+ export declare function boundedDiff(diff: ToolDiffLine[], maxLines: number): {
64
+ diff: ToolDiffLine[];
65
+ truncated: boolean;
66
+ omittedLines: number;
67
+ };
68
+ /** Render a complete diff as retrievable plain unified-diff-like text. */
69
+ export declare function renderToolDiff(filePath: string, diff: ToolDiffLine[]): string;
@@ -68,6 +68,8 @@ export function findEditRange(original, oldText) {
68
68
  }
69
69
  /** Split text into diff lines, dropping a single trailing newline. */
70
70
  export function splitDiffLines(text) {
71
+ if (text.length === 0)
72
+ return [];
71
73
  const lines = text.split(/\r?\n/);
72
74
  if (text.endsWith('\n') || text.endsWith('\r\n'))
73
75
  lines.pop();
@@ -97,3 +99,73 @@ export function replacementDiff(oldText, newText, oldStartLine, newStartLine, co
97
99
  diff.push({ type: 'context', ...context.after });
98
100
  return { diff, addedLines: newLines.length, removedLines: oldLines.length };
99
101
  }
102
+ /** Build a compact whole-file diff by trimming unchanged leading/trailing lines. */
103
+ export function fileDiff(oldText, newText) {
104
+ if (oldText === newText)
105
+ return { diff: [], addedLines: 0, removedLines: 0 };
106
+ const oldLines = splitDiffLines(oldText);
107
+ const newLines = splitDiffLines(newText);
108
+ let prefixLines = 0;
109
+ while (prefixLines < oldLines.length && prefixLines < newLines.length && oldLines[prefixLines] === newLines[prefixLines])
110
+ prefixLines++;
111
+ let suffixLines = 0;
112
+ while (suffixLines < oldLines.length - prefixLines
113
+ && suffixLines < newLines.length - prefixLines
114
+ && oldLines[oldLines.length - suffixLines - 1] === newLines[newLines.length - suffixLines - 1])
115
+ suffixLines++;
116
+ if (prefixLines === oldLines.length && prefixLines === newLines.length) {
117
+ const lineNumber = Math.max(1, oldLines.length);
118
+ const text = oldLines.at(-1) ?? '';
119
+ const oldHasTrailingNewline = /\r?\n$/.test(oldText);
120
+ const newHasTrailingNewline = /\r?\n$/.test(newText);
121
+ return {
122
+ diff: [
123
+ { type: 'remove', oldLine: lineNumber, text },
124
+ ...(!oldHasTrailingNewline ? [{ type: 'meta', text: 'No newline at end of file' }] : []),
125
+ { type: 'add', newLine: lineNumber, text },
126
+ ...(!newHasTrailingNewline ? [{ type: 'meta', text: 'No newline at end of file' }] : []),
127
+ ],
128
+ addedLines: 1,
129
+ removedLines: 1,
130
+ };
131
+ }
132
+ const oldChanged = oldLines.slice(prefixLines, oldLines.length - suffixLines);
133
+ const newChanged = newLines.slice(prefixLines, newLines.length - suffixLines);
134
+ const startLine = prefixLines + 1;
135
+ const before = prefixLines > 0
136
+ ? { oldLine: prefixLines, newLine: prefixLines, text: oldLines[prefixLines - 1] ?? '' }
137
+ : undefined;
138
+ const after = suffixLines > 0
139
+ ? {
140
+ oldLine: oldLines.length - suffixLines + 1,
141
+ newLine: newLines.length - suffixLines + 1,
142
+ text: oldLines[oldLines.length - suffixLines] ?? '',
143
+ }
144
+ : undefined;
145
+ return replacementDiff(oldChanged.join('\n'), newChanged.join('\n'), startLine, startLine, { before, after });
146
+ }
147
+ /** Keep every mutation visible while bounding the inline result size. */
148
+ export function boundedDiff(diff, maxLines) {
149
+ if (diff.length <= maxLines)
150
+ return { diff, truncated: false, omittedLines: 0 };
151
+ const headLines = Math.ceil(maxLines / 2);
152
+ const tailLines = Math.floor(maxLines / 2);
153
+ const omittedLines = diff.length - headLines - tailLines;
154
+ return {
155
+ diff: [...diff.slice(0, headLines), { type: 'gap', omittedLines }, ...diff.slice(diff.length - tailLines)],
156
+ truncated: true,
157
+ omittedLines,
158
+ };
159
+ }
160
+ /** Render a complete diff as retrievable plain unified-diff-like text. */
161
+ export function renderToolDiff(filePath, diff) {
162
+ const lines = diff.map(line => {
163
+ if (line.type === 'gap')
164
+ return `... ${line.omittedLines} diff lines omitted ...`;
165
+ if (line.type === 'meta')
166
+ return `\\ ${line.text}`;
167
+ const marker = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
168
+ return `${marker}${line.text}`;
169
+ });
170
+ return [`--- a/${filePath}`, `+++ b/${filePath}`, ...lines].join('\n');
171
+ }
@@ -23,7 +23,9 @@ export declare function structuredToolFailure(toolName: string, error: unknown,
23
23
  reasonCode?: ToolFailureReasonCode;
24
24
  recoveryTool?: string;
25
25
  recoveryInput?: unknown;
26
+ suggestedPaths?: string[];
26
27
  }): {
28
+ suggestedPaths?: string[] | undefined;
27
29
  ok: boolean;
28
30
  toolName: string;
29
31
  path: string | undefined;
@@ -34,5 +34,6 @@ export function structuredToolFailure(toolName, error, suggestedNextStep, pathFo
34
34
  suggestedNextStep,
35
35
  recoveryTool: options?.recoveryTool ?? hazeError?.recoveryTool,
36
36
  recoveryInput: options?.recoveryInput ?? hazeError?.recoveryInput,
37
+ ...(options?.suggestedPaths?.length ? { suggestedPaths: options.suggestedPaths } : {}),
37
38
  };
38
39
  }
@@ -4,12 +4,12 @@ export declare const fetchTool: ({
4
4
  metadata?: import("@ai-sdk/provider").JSONObject;
5
5
  inputSchema: import("ai").FlexibleSchema<{
6
6
  url: string;
7
- format: "auto" | "text";
7
+ format: "text" | "auto";
8
8
  }>;
9
9
  contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
10
10
  needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
11
11
  url: string;
12
- format: "auto" | "text";
12
+ format: "text" | "auto";
13
13
  }, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
14
14
  onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
15
15
  onInputDelta?: ((options: {
@@ -18,16 +18,17 @@ export declare const fetchTool: ({
18
18
  onInputAvailable?: ((options: {
19
19
  input: {
20
20
  url: string;
21
- format: "auto" | "text";
21
+ format: "text" | "auto";
22
22
  };
23
23
  } & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
24
24
  toModelOutput?: ((options: {
25
25
  toolCallId: string;
26
26
  input: {
27
27
  url: string;
28
- format: "auto" | "text";
28
+ format: "text" | "auto";
29
29
  };
30
30
  output: NoInfer<{
31
+ suggestedPaths?: string[] | undefined;
31
32
  ok: boolean;
32
33
  toolName: string;
33
34
  path: string | undefined;
@@ -92,6 +93,7 @@ export declare const fetchTool: ({
92
93
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
93
94
  } & {
94
95
  outputSchema?: import("ai").FlexibleSchema<{
96
+ suggestedPaths?: string[] | undefined;
95
97
  ok: boolean;
96
98
  toolName: string;
97
99
  path: string | undefined;
@@ -155,8 +157,9 @@ export declare const fetchTool: ({
155
157
  }> | undefined;
156
158
  execute: import("ai").ToolExecuteFunction<{
157
159
  url: string;
158
- format: "auto" | "text";
160
+ format: "text" | "auto";
159
161
  }, {
162
+ suggestedPaths?: string[] | undefined;
160
163
  ok: boolean;
161
164
  toolName: string;
162
165
  path: string | undefined;
@@ -227,7 +230,7 @@ export declare const fetchTool: ({
227
230
  inputExamples?: {
228
231
  input: NoInfer<{
229
232
  url: string;
230
- format: "auto" | "text";
233
+ format: "text" | "auto";
231
234
  }>;
232
235
  }[] | undefined;
233
236
  id?: never;
@@ -239,8 +242,9 @@ export declare const fetchTool: ({
239
242
  } & {
240
243
  execute: import("ai").ToolExecuteFunction<{
241
244
  url: string;
242
- format: "auto" | "text";
245
+ format: "text" | "auto";
243
246
  }, {
247
+ suggestedPaths?: string[] | undefined;
244
248
  ok: boolean;
245
249
  toolName: string;
246
250
  path: string | undefined;
@@ -308,12 +312,12 @@ export declare const fetchTool: ({
308
312
  metadata?: import("@ai-sdk/provider").JSONObject;
309
313
  inputSchema: import("ai").FlexibleSchema<{
310
314
  url: string;
311
- format: "auto" | "text";
315
+ format: "text" | "auto";
312
316
  }>;
313
317
  contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
314
318
  needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
315
319
  url: string;
316
- format: "auto" | "text";
320
+ format: "text" | "auto";
317
321
  }, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
318
322
  onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
319
323
  onInputDelta?: ((options: {
@@ -322,16 +326,17 @@ export declare const fetchTool: ({
322
326
  onInputAvailable?: ((options: {
323
327
  input: {
324
328
  url: string;
325
- format: "auto" | "text";
329
+ format: "text" | "auto";
326
330
  };
327
331
  } & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
328
332
  toModelOutput?: ((options: {
329
333
  toolCallId: string;
330
334
  input: {
331
335
  url: string;
332
- format: "auto" | "text";
336
+ format: "text" | "auto";
333
337
  };
334
338
  output: NoInfer<{
339
+ suggestedPaths?: string[] | undefined;
335
340
  ok: boolean;
336
341
  toolName: string;
337
342
  path: string | undefined;
@@ -396,6 +401,7 @@ export declare const fetchTool: ({
396
401
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
397
402
  } & {
398
403
  outputSchema?: import("ai").FlexibleSchema<{
404
+ suggestedPaths?: string[] | undefined;
399
405
  ok: boolean;
400
406
  toolName: string;
401
407
  path: string | undefined;
@@ -459,8 +465,9 @@ export declare const fetchTool: ({
459
465
  }> | undefined;
460
466
  execute: import("ai").ToolExecuteFunction<{
461
467
  url: string;
462
- format: "auto" | "text";
468
+ format: "text" | "auto";
463
469
  }, {
470
+ suggestedPaths?: string[] | undefined;
464
471
  ok: boolean;
465
472
  toolName: string;
466
473
  path: string | undefined;
@@ -531,7 +538,7 @@ export declare const fetchTool: ({
531
538
  inputExamples?: {
532
539
  input: NoInfer<{
533
540
  url: string;
534
- format: "auto" | "text";
541
+ format: "text" | "auto";
535
542
  }>;
536
543
  }[] | undefined;
537
544
  id?: never;
@@ -543,8 +550,9 @@ export declare const fetchTool: ({
543
550
  } & {
544
551
  execute: import("ai").ToolExecuteFunction<{
545
552
  url: string;
546
- format: "auto" | "text";
553
+ format: "text" | "auto";
547
554
  }, {
555
+ suggestedPaths?: string[] | undefined;
548
556
  ok: boolean;
549
557
  toolName: string;
550
558
  path: string | undefined;
@@ -612,12 +620,12 @@ export declare const fetchTool: ({
612
620
  metadata?: import("@ai-sdk/provider").JSONObject;
613
621
  inputSchema: import("ai").FlexibleSchema<{
614
622
  url: string;
615
- format: "auto" | "text";
623
+ format: "text" | "auto";
616
624
  }>;
617
625
  contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
618
626
  needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
619
627
  url: string;
620
- format: "auto" | "text";
628
+ format: "text" | "auto";
621
629
  }, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
622
630
  onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
623
631
  onInputDelta?: ((options: {
@@ -626,16 +634,17 @@ export declare const fetchTool: ({
626
634
  onInputAvailable?: ((options: {
627
635
  input: {
628
636
  url: string;
629
- format: "auto" | "text";
637
+ format: "text" | "auto";
630
638
  };
631
639
  } & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
632
640
  toModelOutput?: ((options: {
633
641
  toolCallId: string;
634
642
  input: {
635
643
  url: string;
636
- format: "auto" | "text";
644
+ format: "text" | "auto";
637
645
  };
638
646
  output: NoInfer<{
647
+ suggestedPaths?: string[] | undefined;
639
648
  ok: boolean;
640
649
  toolName: string;
641
650
  path: string | undefined;
@@ -700,6 +709,7 @@ export declare const fetchTool: ({
700
709
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
701
710
  } & {
702
711
  outputSchema?: import("ai").FlexibleSchema<{
712
+ suggestedPaths?: string[] | undefined;
703
713
  ok: boolean;
704
714
  toolName: string;
705
715
  path: string | undefined;
@@ -763,8 +773,9 @@ export declare const fetchTool: ({
763
773
  }> | undefined;
764
774
  execute: import("ai").ToolExecuteFunction<{
765
775
  url: string;
766
- format: "auto" | "text";
776
+ format: "text" | "auto";
767
777
  }, {
778
+ suggestedPaths?: string[] | undefined;
768
779
  ok: boolean;
769
780
  toolName: string;
770
781
  path: string | undefined;
@@ -839,8 +850,9 @@ export declare const fetchTool: ({
839
850
  } & {
840
851
  execute: import("ai").ToolExecuteFunction<{
841
852
  url: string;
842
- format: "auto" | "text";
853
+ format: "text" | "auto";
843
854
  }, {
855
+ suggestedPaths?: string[] | undefined;
844
856
  ok: boolean;
845
857
  toolName: string;
846
858
  path: string | undefined;
@@ -908,12 +920,12 @@ export declare const fetchTool: ({
908
920
  metadata?: import("@ai-sdk/provider").JSONObject;
909
921
  inputSchema: import("ai").FlexibleSchema<{
910
922
  url: string;
911
- format: "auto" | "text";
923
+ format: "text" | "auto";
912
924
  }>;
913
925
  contextSchema?: import("ai").FlexibleSchema<import("./toolContext.js").HazeToolContext> | undefined;
914
926
  needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
915
927
  url: string;
916
- format: "auto" | "text";
928
+ format: "text" | "auto";
917
929
  }, NoInfer<import("./toolContext.js").HazeToolContext>> | undefined;
918
930
  onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
919
931
  onInputDelta?: ((options: {
@@ -922,16 +934,17 @@ export declare const fetchTool: ({
922
934
  onInputAvailable?: ((options: {
923
935
  input: {
924
936
  url: string;
925
- format: "auto" | "text";
937
+ format: "text" | "auto";
926
938
  };
927
939
  } & import("ai").ToolExecutionOptions<NoInfer<import("./toolContext.js").HazeToolContext>>) => void | PromiseLike<void>) | undefined;
928
940
  toModelOutput?: ((options: {
929
941
  toolCallId: string;
930
942
  input: {
931
943
  url: string;
932
- format: "auto" | "text";
944
+ format: "text" | "auto";
933
945
  };
934
946
  output: NoInfer<{
947
+ suggestedPaths?: string[] | undefined;
935
948
  ok: boolean;
936
949
  toolName: string;
937
950
  path: string | undefined;
@@ -996,6 +1009,7 @@ export declare const fetchTool: ({
996
1009
  }) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
997
1010
  } & {
998
1011
  outputSchema?: import("ai").FlexibleSchema<{
1012
+ suggestedPaths?: string[] | undefined;
999
1013
  ok: boolean;
1000
1014
  toolName: string;
1001
1015
  path: string | undefined;
@@ -1059,8 +1073,9 @@ export declare const fetchTool: ({
1059
1073
  }> | undefined;
1060
1074
  execute: import("ai").ToolExecuteFunction<{
1061
1075
  url: string;
1062
- format: "auto" | "text";
1076
+ format: "text" | "auto";
1063
1077
  }, {
1078
+ suggestedPaths?: string[] | undefined;
1064
1079
  ok: boolean;
1065
1080
  toolName: string;
1066
1081
  path: string | undefined;
@@ -1135,8 +1150,9 @@ export declare const fetchTool: ({
1135
1150
  } & {
1136
1151
  execute: import("ai").ToolExecuteFunction<{
1137
1152
  url: string;
1138
- format: "auto" | "text";
1153
+ format: "text" | "auto";
1139
1154
  }, {
1155
+ suggestedPaths?: string[] | undefined;
1140
1156
  ok: boolean;
1141
1157
  toolName: string;
1142
1158
  path: string | undefined;
@@ -4,8 +4,8 @@ import { reductionMetrics } from '../../core/toolOutput/reduction.js';
4
4
  import { fetchUrlContent, BlockedUrlError } from '../webFetch.js';
5
5
  import { structuredToolFailure } from './failures.js';
6
6
  import { compactStoredOutput } from './outputCap.js';
7
+ import { MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
7
8
  import { hazeToolContextSchema, runDedupedTool } from './toolContext.js';
8
- const MAX_OUTPUT_CHARS = 50_000;
9
9
  export const fetchTool = tool({
10
10
  description: 'Fetch a public http(s) URL and return readable content. Use for current docs, API references, error lookups, or CI logs. Private/loopback/metadata hosts are blocked.',
11
11
  contextSchema: hazeToolContextSchema,
@@ -1,8 +1,10 @@
1
- export declare const MAX_OUTPUT_CHARS = 50000;
1
+ import { MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
2
+ import { isGitIgnored } from './gitIgnore.js';
3
+ export { MAX_OUTPUT_CHARS };
2
4
  export declare const DEFAULT_READ_LINES = 300;
3
- /** Inline diff lines beyond this count are omitted (just the count is returned). */
4
- export declare const INLINE_DIFF_LINE_LIMIT = 20;
5
- export declare function isGitIgnored(absolutePath: string): Promise<boolean>;
5
+ /** Maximum real diff rows shown inline; larger diffs retain a head/tail preview and retrieval handle. */
6
+ export declare const INLINE_DIFF_LINE_LIMIT = 8;
7
+ export { isGitIgnored };
6
8
  export declare function assertNotIgnored(absolutePath: string, inputPath: string, allowIgnored?: boolean): Promise<void>;
7
9
  export declare function sourceOutlineEntries(lines: string[], startLine: number): {
8
10
  lineNumber: number;
@@ -1,31 +1,26 @@
1
- import { execFile as execFileCallback } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import { workspaceRelativePath, workspaceRoot } from '../../utils/path.js';
1
+ import { MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
4
2
  import { HazeToolError } from './failures.js';
5
- const execFile = promisify(execFileCallback);
6
- export const MAX_OUTPUT_CHARS = 50_000;
3
+ import { checkGitIgnored, isGitIgnored } from './gitIgnore.js';
4
+ export { MAX_OUTPUT_CHARS };
7
5
  export const DEFAULT_READ_LINES = 300;
8
- /** Inline diff lines beyond this count are omitted (just the count is returned). */
9
- export const INLINE_DIFF_LINE_LIMIT = 20;
10
- export async function isGitIgnored(absolutePath) {
11
- const relative = workspaceRelativePath(absolutePath);
12
- if (relative === '.')
13
- return false;
14
- try {
15
- await execFile('git', ['-C', workspaceRoot(), 'check-ignore', '-q', '--', relative]);
16
- return true;
17
- }
18
- catch (error) {
19
- const status = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
20
- if (status === 1 || status === 128)
21
- return false;
22
- return false;
23
- }
24
- }
6
+ /** Maximum real diff rows shown inline; larger diffs retain a head/tail preview and retrieval handle. */
7
+ export const INLINE_DIFF_LINE_LIMIT = 8;
8
+ // Re-exported so existing import sites keep a single source for ignore checks
9
+ // while traversal uses the batched classifier in `gitIgnore.ts` (RH-001).
10
+ export { isGitIgnored };
25
11
  export async function assertNotIgnored(absolutePath, inputPath, allowIgnored) {
26
- if (!allowIgnored && await isGitIgnored(absolutePath)) {
12
+ if (allowIgnored)
13
+ return;
14
+ // Mutations fail closed when ignore status cannot be verified (F-05): reads
15
+ // failing open is right, but silently proceeding into a possibly-ignored
16
+ // path because Git is missing/broken is the unsafe direction for writes.
17
+ const status = await checkGitIgnored(absolutePath);
18
+ if (status === 'ignored') {
27
19
  throw new HazeToolError(`Path is ignored by .gitignore: ${inputPath}. Set allowIgnored=true only if you explicitly need to access ignored files.`, 'ignored_path', { recoveryTool: 'listFiles' });
28
20
  }
21
+ if (status === 'unknown') {
22
+ throw new HazeToolError(`Could not verify git-ignore status for ${inputPath} (Git unavailable or failed). Set allowIgnored=true to proceed anyway.`, 'ignore_check_unavailable', { recoveryTool: 'listFiles' });
23
+ }
29
24
  }
30
25
  const SOURCE_OUTLINE_PATTERNS = [
31
26
  /^\s*(?:import|from|export|package|namespace|module|using)\b/,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Maximum candidate paths submitted to a single `git check-ignore` invocation.
3
+ * Bounding the batch keeps stdin/stdout bounded while collapsing hundreds of
4
+ * entries into O(batches) subprocesses instead of one process per path
5
+ * (RH-001). 256 candidates comfortably fits a typical directory frontier.
6
+ */
7
+ export declare const GIT_IGNORE_BATCH = 256;
8
+ export interface IgnoreClassification {
9
+ /** Subset of the submitted paths Git reports as ignored. */
10
+ ignored: Set<string>;
11
+ /**
12
+ * False when a Git failure (e.g. git not installed) made the result partial.
13
+ * Reads treat that as "nothing ignored" (fail open); mutation guards treat
14
+ * it as un-verifiable and fail closed instead (F-05).
15
+ */
16
+ checked: boolean;
17
+ }
18
+ export interface IgnoreClassifier {
19
+ /**
20
+ * Classify workspace-relative candidate paths. Returns the subset that Git
21
+ * reports as ignored. Fails open: a non-repository, an operational Git
22
+ * failure, and the "no paths ignored" exit code (1) all resolve to "nothing
23
+ * here is ignored" so workspace reads are never blocked by ignore checks.
24
+ */
25
+ classify(relativePaths: readonly string[]): Promise<Set<string>>;
26
+ /** Like `classify`, but distinguishes "checked" from "could not check" (F-05). */
27
+ classifyChecked(relativePaths: readonly string[]): Promise<IgnoreClassification>;
28
+ /** Number of `git check-ignore` subprocesses started by this classifier. */
29
+ readonly invocationCount: number;
30
+ }
31
+ /**
32
+ * Create a bounded batch ignore classifier rooted at `root` (defaults to the
33
+ * workspace root). One classifier should own an entire listing operation so
34
+ * sibling/frontier candidates share subprocesses.
35
+ */
36
+ export declare function createIgnoreClassifier(root?: string): IgnoreClassifier;
37
+ /** Classify a set of workspace-relative paths in bounded batches. */
38
+ export declare function classifyGitIgnored(relativePaths: readonly string[], root?: string): Promise<Set<string>>;
39
+ /** Distinguish "checked and not ignored" from "could not check" (F-05). */
40
+ export type GitIgnoreStatus = 'ignored' | 'not-ignored' | 'unknown';
41
+ /**
42
+ * Single-path ignore classification (used by mutating-tool guards and other
43
+ * one-off checks). Built on the batch primitive so the fail-open read contract
44
+ * stays identical to batched traversal; `unknown` means Git could not be run
45
+ * at all, so callers that must not fail open (mutations) can fail closed.
46
+ */
47
+ export declare function isGitIgnored(absolutePath: string): Promise<boolean>;
48
+ /** Tri-state single-path check: mutation guards key off `unknown` (F-05). */
49
+ export declare function checkGitIgnored(absolutePath: string): Promise<GitIgnoreStatus>;