@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.
- package/CHANGELOG.md +133 -17
- package/README.md +164 -68
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +46 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +92 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -2
- package/dist/cli/chat/messages.js +216 -33
- package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
- package/dist/cli/chat/sessionLifecycle.js +205 -0
- package/dist/cli/chat/sessionRecorder.js +80 -14
- package/dist/cli/chat/startupInfo.js +11 -4
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +744 -0
- package/dist/cli/commands/chat.d.ts +6 -0
- package/dist/cli/commands/chat.js +373 -790
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +5 -2
- package/dist/cli/commands/commands.js +22 -18
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +35 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +10 -2
- package/dist/cli/commands/providerWizard.js +50 -4
- package/dist/cli/commands/runCommand.d.ts +4 -0
- package/dist/cli/commands/runCommand.js +142 -16
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
- package/dist/cli/commands/streaming/turnOutcome.js +27 -11
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +82 -3
- package/dist/cli/commands/streaming.js +528 -91
- package/dist/cli/commands/wizardActions.d.ts +7 -0
- package/dist/cli/commands/wizardActions.js +7 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +64 -14
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +82 -22
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +71 -0
- package/dist/config/modelDiscovery.js +214 -0
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +49 -5
- package/dist/config/providerPresets.js +573 -73
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +9 -0
- package/dist/config/settings.d.ts +58 -0
- package/dist/config/settings.js +38 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +36 -0
- package/dist/core/agent/budgets.js +44 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +108 -19
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +46 -0
- package/dist/core/agent/contextBudget.js +89 -7
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +86 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
- package/dist/core/agent/toolExecutionBudget.js +49 -0
- package/dist/core/agent/toolOutputStore.d.ts +13 -0
- package/dist/core/agent/toolOutputStore.js +27 -10
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnBudget.d.ts +35 -0
- package/dist/core/agent/turnBudget.js +27 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +76 -1
- package/dist/core/agent/workState.js +120 -13
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/deadline.d.ts +33 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/goal/completionPolicy.d.ts +27 -0
- package/dist/core/goal/completionPolicy.js +37 -1
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +7 -0
- package/dist/core/limits/byteBudgets.js +7 -0
- package/dist/core/limits/textBudgets.d.ts +25 -0
- package/dist/core/limits/textBudgets.js +25 -0
- package/dist/core/log/llmLog.js +7 -0
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +195 -0
- package/dist/core/process/runBoundedProcess.d.ts +9 -0
- package/dist/core/process/runBoundedProcess.js +74 -29
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +74 -0
- package/dist/core/session/sessionStore.js +268 -18
- package/dist/core/subagent/contracts.d.ts +120 -0
- package/dist/core/subagent/contracts.js +55 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
- package/dist/core/subagent/subagentCoordinator.js +164 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +208 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +36 -29
- package/dist/llm/client.js +102 -33
- package/dist/llm/hazeTools.d.ts +2559 -150
- package/dist/llm/hazeTools.js +119 -31
- package/dist/llm/lsp.d.ts +26 -4
- package/dist/llm/lsp.js +90 -14
- package/dist/llm/lspTools.d.ts +2366 -0
- package/dist/llm/lspTools.js +87 -79
- package/dist/llm/openaiCodex.d.ts +3 -0
- package/dist/llm/openaiCodex.js +47 -0
- package/dist/llm/openaiCodexOAuth.d.ts +54 -0
- package/dist/llm/openaiCodexOAuth.js +214 -0
- package/dist/llm/requestContext.d.ts +25 -1
- package/dist/llm/requestContext.js +51 -8
- package/dist/llm/systemPrompt.d.ts +15 -1
- package/dist/llm/systemPrompt.js +24 -8
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +906 -32
- package/dist/llm/tools/bashTool.js +30 -4
- package/dist/llm/tools/editMatch.d.ts +14 -0
- package/dist/llm/tools/editMatch.js +72 -0
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +42 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +6 -4
- package/dist/llm/tools/fileToolShared.js +18 -23
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/readRecovery.d.ts +10 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/toolContext.d.ts +9 -1
- package/dist/llm/tools/toolContext.js +83 -43
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +66 -86
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -1
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +12 -2
- package/dist/ui/components/TextInput.js +80 -8
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +104 -0
- package/dist/utils/buildInfo.js +253 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +9 -1
- package/dist/utils/fs.js +87 -29
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +22 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +5 -1
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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
|
-
|
|
2
|
-
export
|
|
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
|
-
|
|
3
|
-
export
|
|
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.
|