@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
@@ -0,0 +1,129 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { workspaceRelativePath, workspaceRoot } from '../../utils/path.js';
3
+ /**
4
+ * Maximum candidate paths submitted to a single `git check-ignore` invocation.
5
+ * Bounding the batch keeps stdin/stdout bounded while collapsing hundreds of
6
+ * entries into O(batches) subprocesses instead of one process per path
7
+ * (RH-001). 256 candidates comfortably fits a typical directory frontier.
8
+ */
9
+ export const GIT_IGNORE_BATCH = 256;
10
+ /**
11
+ * Generous stdout ceiling for a single batch. check-ignore echoes at most the
12
+ * ignored paths it was given, so this is bounded by batch size in practice.
13
+ */
14
+ const CHECK_IGNORE_MAX_BYTES = 8 * 1024 * 1024;
15
+ /**
16
+ * Run one bounded `git check-ignore -z --stdin` invocation. Resolves with the
17
+ * raw NUL-delimited stdout (empty when no paths are ignored or the workspace is
18
+ * not a repository); rejects only on a spawn-level failure such as git missing.
19
+ */
20
+ function runCheckIgnore(root, input) {
21
+ return new Promise((resolve, reject) => {
22
+ const child = spawn('git', ['-C', root, 'check-ignore', '-z', '--stdin'], { windowsHide: true });
23
+ const chunks = [];
24
+ let totalBytes = 0;
25
+ let overflowed = false;
26
+ let settled = false;
27
+ const finish = (stdout) => {
28
+ if (settled)
29
+ return;
30
+ settled = true;
31
+ resolve(stdout);
32
+ };
33
+ const fail = (error) => {
34
+ if (settled)
35
+ return;
36
+ settled = true;
37
+ reject(error);
38
+ };
39
+ child.stdout.on('data', (chunk) => {
40
+ if (overflowed)
41
+ return;
42
+ totalBytes += chunk.length;
43
+ if (totalBytes > CHECK_IGNORE_MAX_BYTES) {
44
+ overflowed = true;
45
+ chunks.length = 0;
46
+ return;
47
+ }
48
+ chunks.push(chunk);
49
+ });
50
+ child.stderr.on('data', () => undefined);
51
+ child.on('error', fail);
52
+ child.on('close', () => {
53
+ // Exit codes: 0 = some ignored, 1 = none ignored, 128 = not a repo. All
54
+ // are resolved with whatever stdout arrived (empty for 1/128); overflow
55
+ // yields empty output so the batch fails open (nothing reported ignored).
56
+ finish(overflowed ? '' : Buffer.concat(chunks).toString('utf8'));
57
+ });
58
+ child.stdin.on('error', () => undefined);
59
+ child.stdin.end(input, 'utf8');
60
+ });
61
+ }
62
+ /**
63
+ * Create a bounded batch ignore classifier rooted at `root` (defaults to the
64
+ * workspace root). One classifier should own an entire listing operation so
65
+ * sibling/frontier candidates share subprocesses.
66
+ */
67
+ export function createIgnoreClassifier(root = workspaceRoot()) {
68
+ let invocationCount = 0;
69
+ const classifyChecked = async (relativePaths) => {
70
+ // De-duplicate and drop meaningless inputs; preserve insertion uniqueness
71
+ // so the returned set keys match caller-supplied relative paths exactly.
72
+ const unique = Array.from(new Set(relativePaths.filter(candidate => candidate && candidate !== '.')));
73
+ if (unique.length === 0)
74
+ return { ignored: new Set(), checked: true };
75
+ const ignored = new Set();
76
+ let checked = true;
77
+ for (let offset = 0; offset < unique.length; offset += GIT_IGNORE_BATCH) {
78
+ const batch = unique.slice(offset, offset + GIT_IGNORE_BATCH);
79
+ const input = `${batch.join('\0')}\0`;
80
+ invocationCount++;
81
+ // check-ignore echoes each ignored path verbatim (NUL-delimited with
82
+ // -z). Matching by exact submitted string preserves spaces, embedded
83
+ // newlines, and unusual names; only ignored entries appear in stdout.
84
+ try {
85
+ const stdout = await runCheckIgnore(root, input);
86
+ for (const part of stdout.split('\0'))
87
+ if (part)
88
+ ignored.add(part);
89
+ }
90
+ catch {
91
+ // Spawn-level failure (e.g. git not installed): whatever was classified
92
+ // so far stands, but the batch could not be checked.
93
+ checked = false;
94
+ return { ignored, checked };
95
+ }
96
+ }
97
+ return { ignored, checked };
98
+ };
99
+ return {
100
+ classifyChecked,
101
+ classify: async (relativePaths) => (await classifyChecked(relativePaths)).ignored,
102
+ get invocationCount() {
103
+ return invocationCount;
104
+ },
105
+ };
106
+ }
107
+ /** Classify a set of workspace-relative paths in bounded batches. */
108
+ export async function classifyGitIgnored(relativePaths, root) {
109
+ return createIgnoreClassifier(root ?? workspaceRoot()).classify(relativePaths);
110
+ }
111
+ /**
112
+ * Single-path ignore classification (used by mutating-tool guards and other
113
+ * one-off checks). Built on the batch primitive so the fail-open read contract
114
+ * stays identical to batched traversal; `unknown` means Git could not be run
115
+ * at all, so callers that must not fail open (mutations) can fail closed.
116
+ */
117
+ export async function isGitIgnored(absolutePath) {
118
+ return (await checkGitIgnored(absolutePath)) === 'ignored';
119
+ }
120
+ /** Tri-state single-path check: mutation guards key off `unknown` (F-05). */
121
+ export async function checkGitIgnored(absolutePath) {
122
+ const relative = workspaceRelativePath(absolutePath);
123
+ if (relative === '.')
124
+ return 'not-ignored';
125
+ const { ignored, checked } = await createIgnoreClassifier(workspaceRoot()).classifyChecked([relative]);
126
+ if (!checked)
127
+ return 'unknown';
128
+ return ignored.has(relative) ? 'ignored' : 'not-ignored';
129
+ }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Line-oriented bounded ripgrep runner built on the shared bounded-process
3
+ * primitive, so spawn/timeout/abort/process-group teardown behavior is
4
+ * identical to bash (CR-004). Match counting and early-stop stay here.
5
+ */
1
6
  export declare function runRipgrepBounded(input: {
2
7
  executable: string;
3
8
  args: string[];
@@ -1,85 +1,66 @@
1
- import { spawn } from 'node:child_process';
2
1
  import { StringDecoder } from 'node:string_decoder';
2
+ import { runBoundedProcess } from '../../core/process/runBoundedProcess.js';
3
3
  import { GREP_STREAM_BYTES, PROCESS_STDERR_BYTES, TEXT_LINE_BYTES } from '../../core/limits/byteBudgets.js';
4
+ /**
5
+ * Line-oriented bounded ripgrep runner built on the shared bounded-process
6
+ * primitive, so spawn/timeout/abort/process-group teardown behavior is
7
+ * identical to bash (CR-004). Match counting and early-stop stay here.
8
+ */
4
9
  export async function runRipgrepBounded(input) {
5
- if (input.signal?.aborted)
6
- return { stdout: '', stderr: '', code: null, capped: false, timedOut: false, aborted: true };
7
- const child = spawn(input.executable, input.args, { cwd: input.cwd, stdio: ['ignore', 'pipe', 'pipe'] });
8
10
  const decoder = new StringDecoder('utf8');
9
- const stderrDecoder = new StringDecoder('utf8');
10
11
  let pending = '';
11
12
  const lines = [];
12
- let stderr = '';
13
13
  let retainedBytes = 0;
14
- let stderrBytes = 0;
15
14
  let matches = 0;
16
15
  let capped = false;
17
- let timedOut = false;
18
- let aborted = false;
19
16
  let protocolError;
20
- let forceTimer;
21
- const stop = () => {
22
- if (!child.killed)
23
- child.kill('SIGTERM');
24
- forceTimer ??= setTimeout(() => child.kill('SIGKILL'), 500);
25
- forceTimer.unref?.();
26
- };
27
- const timer = setTimeout(() => { timedOut = true; stop(); }, input.timeoutMs ?? 30_000);
28
- const abort = () => { aborted = true; stop(); };
29
- input.signal?.addEventListener('abort', abort, { once: true });
30
- child.stdout.on('data', (chunk) => {
31
- pending += decoder.write(chunk);
32
- if (Buffer.byteLength(pending, 'utf8') > TEXT_LINE_BYTES) {
33
- protocolError = `ripgrep JSON line exceeds ${TEXT_LINE_BYTES} bytes`;
34
- stop();
35
- return;
36
- }
37
- const parts = pending.split('\n');
38
- pending = parts.pop() ?? '';
39
- for (const line of parts) {
40
- if (capped)
41
- continue;
42
- const lineBytes = Buffer.byteLength(line, 'utf8') + 1;
43
- if (retainedBytes + lineBytes > GREP_STREAM_BYTES) {
44
- capped = true;
45
- stop();
46
- break;
17
+ const result = await runBoundedProcess({
18
+ command: input.executable,
19
+ args: input.args,
20
+ cwd: input.cwd,
21
+ timeoutMs: input.timeoutMs ?? 30_000,
22
+ signal: input.signal,
23
+ // Raw stdout head is unused: line retention happens in the interceptor.
24
+ maxStdoutBytes: 0,
25
+ maxStderrBytes: PROCESS_STDERR_BYTES,
26
+ onStdoutChunk: chunk => {
27
+ pending += decoder.write(chunk);
28
+ if (Buffer.byteLength(pending, 'utf8') > TEXT_LINE_BYTES) {
29
+ protocolError = `ripgrep JSON line exceeds ${TEXT_LINE_BYTES} bytes`;
30
+ return true;
47
31
  }
48
- lines.push(line);
49
- retainedBytes += lineBytes;
50
- try {
51
- if (JSON.parse(line).type === 'match')
52
- matches++;
32
+ const parts = pending.split('\n');
33
+ pending = parts.pop() ?? '';
34
+ for (const line of parts) {
35
+ if (capped)
36
+ continue;
37
+ const lineBytes = Buffer.byteLength(line, 'utf8') + 1;
38
+ if (retainedBytes + lineBytes > GREP_STREAM_BYTES) {
39
+ capped = true;
40
+ return true;
41
+ }
42
+ lines.push(line);
43
+ retainedBytes += lineBytes;
44
+ try {
45
+ if (JSON.parse(line).type === 'match')
46
+ matches++;
47
+ }
48
+ catch { /* parser reports malformed data later */ }
49
+ // Global match cap is enforced here (source of truth). The `--max-count`
50
+ // flag passed to ripgrep is a per-file safeguard only (CR-021).
51
+ if (matches > input.maxMatches) {
52
+ capped = true;
53
+ return true;
54
+ }
53
55
  }
54
- catch { /* parser reports malformed data later */ }
55
- if (matches > input.maxMatches) {
56
- capped = true;
57
- stop();
58
- }
59
- }
60
- });
61
- child.stderr.on('data', (chunk) => {
62
- const remaining = PROCESS_STDERR_BYTES - stderrBytes;
63
- if (remaining <= 0)
64
- return;
65
- const kept = chunk.subarray(0, remaining);
66
- stderrBytes += kept.length;
67
- stderr += stderrDecoder.write(kept);
68
- });
69
- return await new Promise((resolve, reject) => {
70
- child.once('error', reject);
71
- child.once('close', code => {
72
- clearTimeout(timer);
73
- if (forceTimer)
74
- clearTimeout(forceTimer);
75
- input.signal?.removeEventListener('abort', abort);
76
- const tail = pending + decoder.end();
77
- if (tail && !capped)
78
- lines.push(tail);
79
- stderr += stderrDecoder.end();
80
- if (protocolError)
81
- stderr = `${stderr}${stderr ? '\n' : ''}${protocolError}`;
82
- resolve({ stdout: lines.join('\n'), stderr, code, capped, timedOut, aborted });
83
- });
56
+ return false;
57
+ },
84
58
  });
59
+ if (result.error)
60
+ throw new Error(result.error);
61
+ const tail = pending + decoder.end();
62
+ if (tail && !capped)
63
+ lines.push(tail);
64
+ const stderr = result.stderr.text + (protocolError ? `${result.stderr.text ? '\n' : ''}${protocolError}` : '');
65
+ return { stdout: lines.join('\n'), stderr, code: result.code, capped, timedOut: result.timedOut, aborted: result.aborted };
85
66
  }
@@ -1,9 +1,5 @@
1
- /** Default ceiling for capped tool outputs (bash, fetch). */
2
- export declare const COMPACT_COMMAND_CHARS = 12000;
3
- /** Default ceiling for rendered grep output. */
4
- export declare const GREP_MAX_OUTPUT_CHARS = 30000;
5
- /** Default ceiling for a single grep match line. */
6
- export declare const GREP_MAX_LINE_CHARS = 500;
1
+ import { COMPACT_COMMAND_CHARS, GREP_MAX_LINE_CHARS, GREP_MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
2
+ export { COMPACT_COMMAND_CHARS, GREP_MAX_OUTPUT_CHARS, GREP_MAX_LINE_CHARS };
7
3
  /**
8
4
  * Cap a string to `maxChars` characters, keeping a head + tail and storing the
9
5
  * full text behind a `readToolOutput` handle so nothing is lost.
@@ -1,10 +1,6 @@
1
1
  import { storeToolOutput } from '../../core/agent/toolOutputStore.js';
2
- /** Default ceiling for capped tool outputs (bash, fetch). */
3
- export const COMPACT_COMMAND_CHARS = 12_000;
4
- /** Default ceiling for rendered grep output. */
5
- export const GREP_MAX_OUTPUT_CHARS = 30_000;
6
- /** Default ceiling for a single grep match line. */
7
- export const GREP_MAX_LINE_CHARS = 500;
2
+ import { COMPACT_COMMAND_CHARS, GREP_MAX_LINE_CHARS, GREP_MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
3
+ export { COMPACT_COMMAND_CHARS, GREP_MAX_OUTPUT_CHARS, GREP_MAX_LINE_CHARS };
8
4
  /**
9
5
  * Cap a string to `maxChars` characters, keeping a head + tail and storing the
10
6
  * full text behind a `readToolOutput` handle so nothing is lost.