@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
|
@@ -2,9 +2,9 @@ import { createReadStream } from 'node:fs';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import { StringDecoder } from 'node:string_decoder';
|
|
4
4
|
import { TEXT_LINE_BYTES } from '../limits/byteBudgets.js';
|
|
5
|
-
|
|
6
|
-
const input = createReadStream(file);
|
|
7
|
-
let lineNumber =
|
|
5
|
+
async function* iterateBoundedUtf8LinesFrom(file, maxLineBytes, startByte, previousLineNumber) {
|
|
6
|
+
const input = createReadStream(file, startByte > 0 ? { start: startByte } : undefined);
|
|
7
|
+
let lineNumber = previousLineNumber;
|
|
8
8
|
let retained = [];
|
|
9
9
|
let retainedBytes = 0;
|
|
10
10
|
let lineBytes = 0;
|
|
@@ -50,37 +50,84 @@ export async function* iterateBoundedUtf8Lines(file, maxLineBytes) {
|
|
|
50
50
|
if (lineBytes > 0 || retainedBytes > 0)
|
|
51
51
|
yield finish();
|
|
52
52
|
}
|
|
53
|
-
export async function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
export async function* iterateBoundedUtf8Lines(file, maxLineBytes) {
|
|
54
|
+
yield* iterateBoundedUtf8LinesFrom(file, maxLineBytes, 0, 0);
|
|
55
|
+
}
|
|
56
|
+
const MAX_LINE_INDEX_FILES = 8;
|
|
57
|
+
const MAX_LINE_CHECKPOINTS = 8_192;
|
|
58
|
+
const lineIndexCache = new Map();
|
|
59
|
+
function sameFileSignature(index, stat) {
|
|
60
|
+
return index.size === stat.size && index.mtimeMs === stat.mtimeMs && index.ctimeMs === stat.ctimeMs;
|
|
61
|
+
}
|
|
62
|
+
async function buildLineIndex(file, stat) {
|
|
63
|
+
let totalLines = 1;
|
|
64
|
+
let byteOffset = 0;
|
|
65
|
+
let stride = 256;
|
|
66
|
+
let trailingNewline = false;
|
|
67
|
+
let checkpoints = [{ lineNumber: 1, byteOffset: 0 }];
|
|
68
|
+
for await (const value of createReadStream(file)) {
|
|
69
|
+
const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
70
|
+
let cursor = 0;
|
|
71
|
+
while (cursor < chunk.length) {
|
|
72
|
+
const newline = chunk.indexOf(10, cursor);
|
|
73
|
+
if (newline === -1)
|
|
74
|
+
break;
|
|
75
|
+
totalLines++;
|
|
76
|
+
const lineStart = byteOffset + newline + 1;
|
|
77
|
+
if ((totalLines - 1) % stride === 0)
|
|
78
|
+
checkpoints.push({ lineNumber: totalLines, byteOffset: lineStart });
|
|
79
|
+
if (checkpoints.length > MAX_LINE_CHECKPOINTS) {
|
|
80
|
+
stride *= 2;
|
|
81
|
+
checkpoints = checkpoints.filter(point => (point.lineNumber - 1) % stride === 0);
|
|
82
|
+
}
|
|
83
|
+
cursor = newline + 1;
|
|
60
84
|
}
|
|
85
|
+
trailingNewline = chunk.length > 0 ? chunk[chunk.length - 1] === 10 : trailingNewline;
|
|
86
|
+
byteOffset += chunk.length;
|
|
61
87
|
}
|
|
88
|
+
return { size: stat.size, mtimeMs: stat.mtimeMs, ctimeMs: stat.ctimeMs, totalLines, trailingNewline, checkpoints };
|
|
89
|
+
}
|
|
90
|
+
async function lineIndex(file) {
|
|
62
91
|
const stat = await fs.stat(file);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
const cached = lineIndexCache.get(file);
|
|
93
|
+
if (cached && sameFileSignature(cached, stat)) {
|
|
94
|
+
lineIndexCache.delete(file);
|
|
95
|
+
lineIndexCache.set(file, cached);
|
|
96
|
+
return cached;
|
|
67
97
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
const index = await buildLineIndex(file, stat);
|
|
99
|
+
lineIndexCache.delete(file);
|
|
100
|
+
lineIndexCache.set(file, index);
|
|
101
|
+
while (lineIndexCache.size > MAX_LINE_INDEX_FILES) {
|
|
102
|
+
const oldest = lineIndexCache.keys().next().value;
|
|
103
|
+
if (oldest == null)
|
|
104
|
+
break;
|
|
105
|
+
lineIndexCache.delete(oldest);
|
|
106
|
+
}
|
|
107
|
+
return index;
|
|
108
|
+
}
|
|
109
|
+
export async function readUtf8LinesPage(file, offset, limit) {
|
|
110
|
+
const index = await lineIndex(file);
|
|
111
|
+
const lines = [];
|
|
112
|
+
if (limit <= 0 || offset > index.totalLines)
|
|
113
|
+
return { lines, totalLines: index.totalLines };
|
|
114
|
+
let checkpoint = index.checkpoints[0];
|
|
115
|
+
for (const candidate of index.checkpoints) {
|
|
116
|
+
if (candidate.lineNumber > offset)
|
|
117
|
+
break;
|
|
118
|
+
checkpoint = candidate;
|
|
119
|
+
}
|
|
120
|
+
for await (const entry of iterateBoundedUtf8LinesFrom(file, TEXT_LINE_BYTES, checkpoint.byteOffset, checkpoint.lineNumber - 1)) {
|
|
121
|
+
if (entry.lineNumber < offset)
|
|
122
|
+
continue;
|
|
123
|
+
lines.push(entry.oversized ? `${entry.line}\n[Line truncated at ${TEXT_LINE_BYTES} bytes]` : entry.line);
|
|
124
|
+
if (lines.length >= limit)
|
|
125
|
+
break;
|
|
82
126
|
}
|
|
83
|
-
|
|
127
|
+
const includesSyntheticLastLine = index.size === 0 || index.trailingNewline;
|
|
128
|
+
if (includesSyntheticLastLine && offset <= index.totalLines && index.totalLines < offset + limit && lines.length < limit)
|
|
129
|
+
lines.push('');
|
|
130
|
+
return { lines, totalLines: index.totalLines };
|
|
84
131
|
}
|
|
85
132
|
export async function readUtf8Prefix(file, maxBytes) {
|
|
86
133
|
const stat = await fs.stat(file);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const BASH_STREAM_BYTES: number;
|
|
2
|
+
export declare const BACKGROUND_PROCESS_OUTPUT_BYTES: number;
|
|
2
3
|
export declare const GREP_STREAM_BYTES: number;
|
|
3
4
|
export declare const PROCESS_STDERR_BYTES: number;
|
|
4
5
|
export declare const TOOL_OUTPUT_ENTRY_BYTES: number;
|
|
@@ -11,3 +12,9 @@ export declare const SKILL_MARKDOWN_BYTES: number;
|
|
|
11
12
|
export declare const EXACT_MUTATION_BYTES: number;
|
|
12
13
|
export declare const JSONL_LINE_BYTES: number;
|
|
13
14
|
export declare const TEXT_LINE_BYTES: number;
|
|
15
|
+
/** Maximum byte size of a prompt read from piped stdin. */
|
|
16
|
+
export declare const STDIN_PROMPT_BYTES: number;
|
|
17
|
+
/** Maximum size of one user-attached image (checked before the read). */
|
|
18
|
+
export declare const IMAGE_ATTACHMENT_BYTES: number;
|
|
19
|
+
/** Maximum number of image attachments in a single user message. */
|
|
20
|
+
export declare const IMAGE_ATTACHMENTS_PER_MESSAGE = 4;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const BASH_STREAM_BYTES = 2 * 1024 * 1024;
|
|
2
|
+
export const BACKGROUND_PROCESS_OUTPUT_BYTES = 256 * 1024;
|
|
2
3
|
export const GREP_STREAM_BYTES = 8 * 1024 * 1024;
|
|
3
4
|
export const PROCESS_STDERR_BYTES = 64 * 1024;
|
|
4
5
|
export const TOOL_OUTPUT_ENTRY_BYTES = 2 * 1024 * 1024;
|
|
@@ -11,3 +12,9 @@ export const SKILL_MARKDOWN_BYTES = 256 * 1024;
|
|
|
11
12
|
export const EXACT_MUTATION_BYTES = 8 * 1024 * 1024;
|
|
12
13
|
export const JSONL_LINE_BYTES = 4 * 1024 * 1024;
|
|
13
14
|
export const TEXT_LINE_BYTES = 1024 * 1024;
|
|
15
|
+
/** Maximum byte size of a prompt read from piped stdin. */
|
|
16
|
+
export const STDIN_PROMPT_BYTES = 256 * 1024;
|
|
17
|
+
/** Maximum size of one user-attached image (checked before the read). */
|
|
18
|
+
export const IMAGE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
19
|
+
/** Maximum number of image attachments in a single user message. */
|
|
20
|
+
export const IMAGE_ATTACHMENTS_PER_MESSAGE = 4;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing text caps (characters). Byte budgets live in `byteBudgets.ts`;
|
|
3
|
+
* these bound the text returned to the model or persisted in previews so
|
|
4
|
+
* callers cite a named constant instead of a magic number (CR-014).
|
|
5
|
+
*/
|
|
6
|
+
/** Per-page cap for numbered file content returned by readFile/listFiles-style tools. */
|
|
7
|
+
export declare const MAX_OUTPUT_CHARS = 50000;
|
|
8
|
+
/** Default compact cap for stored bash output shown to the model. */
|
|
9
|
+
export declare const COMPACT_COMMAND_CHARS = 12000;
|
|
10
|
+
/** Compact cap for passing-validation summaries. */
|
|
11
|
+
export declare const SHORT_VALIDATION_CHARS = 2000;
|
|
12
|
+
/** Total rendered size cap for grep match output. */
|
|
13
|
+
export declare const GREP_MAX_OUTPUT_CHARS = 30000;
|
|
14
|
+
/** Per-line cap for rendered grep matches. */
|
|
15
|
+
export declare const GREP_MAX_LINE_CHARS = 500;
|
|
16
|
+
/** Bounded excerpt of older messages kept by /compact-style compaction. */
|
|
17
|
+
export declare const COMPACTION_OLDER_CHARS = 8000;
|
|
18
|
+
/** Bounded older-transcript budget sent to the model for LLM-summarized /compact (F-09). */
|
|
19
|
+
export declare const COMPACTION_LLM_TRANSCRIPT_CHARS = 60000;
|
|
20
|
+
/** Session JSONL values up to this size stay inline; larger ones become previews. */
|
|
21
|
+
export declare const SESSION_INLINE_VALUE_BYTES: number;
|
|
22
|
+
/** Preview length for slimmed session values. */
|
|
23
|
+
export declare const SESSION_PREVIEW_CHARS: number;
|
|
24
|
+
/** Strings longer than this are truncated in session snapshots. */
|
|
25
|
+
export declare const SESSION_LARGE_STRING_CHARS: number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing text caps (characters). Byte budgets live in `byteBudgets.ts`;
|
|
3
|
+
* these bound the text returned to the model or persisted in previews so
|
|
4
|
+
* callers cite a named constant instead of a magic number (CR-014).
|
|
5
|
+
*/
|
|
6
|
+
/** Per-page cap for numbered file content returned by readFile/listFiles-style tools. */
|
|
7
|
+
export const MAX_OUTPUT_CHARS = 50_000;
|
|
8
|
+
/** Default compact cap for stored bash output shown to the model. */
|
|
9
|
+
export const COMPACT_COMMAND_CHARS = 12_000;
|
|
10
|
+
/** Compact cap for passing-validation summaries. */
|
|
11
|
+
export const SHORT_VALIDATION_CHARS = 2_000;
|
|
12
|
+
/** Total rendered size cap for grep match output. */
|
|
13
|
+
export const GREP_MAX_OUTPUT_CHARS = 30_000;
|
|
14
|
+
/** Per-line cap for rendered grep matches. */
|
|
15
|
+
export const GREP_MAX_LINE_CHARS = 500;
|
|
16
|
+
/** Bounded excerpt of older messages kept by /compact-style compaction. */
|
|
17
|
+
export const COMPACTION_OLDER_CHARS = 8_000;
|
|
18
|
+
/** Bounded older-transcript budget sent to the model for LLM-summarized /compact (F-09). */
|
|
19
|
+
export const COMPACTION_LLM_TRANSCRIPT_CHARS = 60_000;
|
|
20
|
+
/** Session JSONL values up to this size stay inline; larger ones become previews. */
|
|
21
|
+
export const SESSION_INLINE_VALUE_BYTES = 32 * 1024;
|
|
22
|
+
/** Preview length for slimmed session values. */
|
|
23
|
+
export const SESSION_PREVIEW_CHARS = 4 * 1024;
|
|
24
|
+
/** Strings longer than this are truncated in session snapshots. */
|
|
25
|
+
export const SESSION_LARGE_STRING_CHARS = 8 * 1024;
|
package/dist/core/log/llmLog.js
CHANGED
|
@@ -9,6 +9,9 @@ const LOGS_DIR = path.join(HAZE_DIR, 'logs');
|
|
|
9
9
|
function logFileId(now = new Date()) {
|
|
10
10
|
return now.toISOString().replace(/[:.]/g, '-');
|
|
11
11
|
}
|
|
12
|
+
function isSafeLogId(id) {
|
|
13
|
+
return id.length > 0 && path.basename(id) === id && path.win32.basename(id) === id;
|
|
14
|
+
}
|
|
12
15
|
function logFilePath(id) {
|
|
13
16
|
return path.join(LOGS_DIR, `${id}.jsonl`);
|
|
14
17
|
}
|
|
@@ -52,6 +55,8 @@ export async function listLogs() {
|
|
|
52
55
|
return logs.sort((a, b) => b.modified.localeCompare(a.modified));
|
|
53
56
|
}
|
|
54
57
|
export async function readLogEntries(id) {
|
|
58
|
+
if (!isSafeLogId(id))
|
|
59
|
+
return [];
|
|
55
60
|
const file = logFilePath(id);
|
|
56
61
|
const entries = [];
|
|
57
62
|
try {
|
|
@@ -71,6 +76,8 @@ export async function readLogEntries(id) {
|
|
|
71
76
|
return entries;
|
|
72
77
|
}
|
|
73
78
|
export async function summarizeLog(id) {
|
|
79
|
+
if (!isSafeLogId(id))
|
|
80
|
+
return undefined;
|
|
74
81
|
const file = logFilePath(id);
|
|
75
82
|
const summary = { entries: 0, typeCounts: {}, totalInput: 0, totalOutput: 0, toolCallCounts: {} };
|
|
76
83
|
try {
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes async writes so appends land in arrival order, even when an earlier
|
|
3
|
+
* write rejects. Two contract points worth knowing:
|
|
4
|
+
* - The per-`append` promise rejects with the specific error of that write,
|
|
5
|
+
* so awaiting callers see their own failure. Subsequent appends still
|
|
6
|
+
* chain (the queue keeps draining) so a single bad write does not wedge
|
|
7
|
+
* the writer or reject unrelated callers.
|
|
8
|
+
* - `error()` and `flush()` surface the *first* captured error and never
|
|
9
|
+
* clear it; later successful writes do not reset the sticky state.
|
|
10
|
+
*/
|
|
1
11
|
export declare class OrderedFileWriter<T> {
|
|
2
12
|
private readonly write;
|
|
3
13
|
private tail;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes async writes so appends land in arrival order, even when an earlier
|
|
3
|
+
* write rejects. Two contract points worth knowing:
|
|
4
|
+
* - The per-`append` promise rejects with the specific error of that write,
|
|
5
|
+
* so awaiting callers see their own failure. Subsequent appends still
|
|
6
|
+
* chain (the queue keeps draining) so a single bad write does not wedge
|
|
7
|
+
* the writer or reject unrelated callers.
|
|
8
|
+
* - `error()` and `flush()` surface the *first* captured error and never
|
|
9
|
+
* clear it; later successful writes do not reset the sticky state.
|
|
10
|
+
*/
|
|
1
11
|
export class OrderedFileWriter {
|
|
2
12
|
write;
|
|
3
13
|
tail = Promise.resolve();
|
|
@@ -9,10 +19,14 @@ export class OrderedFileWriter {
|
|
|
9
19
|
append(value) {
|
|
10
20
|
if (this.closed)
|
|
11
21
|
return Promise.reject(new Error('Writer is closed.'));
|
|
12
|
-
|
|
22
|
+
// per-call result: rejects only with this append's own write error
|
|
23
|
+
const result = this.tail.then(() => this.write(value)).catch(error => {
|
|
13
24
|
this.firstError ??= error instanceof Error ? error : new Error(String(error));
|
|
25
|
+
throw error;
|
|
14
26
|
});
|
|
15
|
-
|
|
27
|
+
// Chain continues regardless so later appends are not blocked by this one's failure.
|
|
28
|
+
this.tail = result.catch(() => undefined);
|
|
29
|
+
return result;
|
|
16
30
|
}
|
|
17
31
|
async flush() {
|
|
18
32
|
await this.tail;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type BackgroundProcessStatus = 'running' | 'exited' | 'failed' | 'killed';
|
|
2
|
+
export interface BackgroundProcessSummary {
|
|
3
|
+
backgroundId: string;
|
|
4
|
+
pid?: number;
|
|
5
|
+
command: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
startedAt: string;
|
|
8
|
+
status: BackgroundProcessStatus;
|
|
9
|
+
code?: number | null;
|
|
10
|
+
signal?: NodeJS.Signals | null;
|
|
11
|
+
outputHandle: string;
|
|
12
|
+
outputBytes: {
|
|
13
|
+
totalBytes: number;
|
|
14
|
+
retainedBytes: number;
|
|
15
|
+
omittedBytes: number;
|
|
16
|
+
};
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function backgroundProcessCount(): number;
|
|
20
|
+
export declare function subscribeBackgroundProcesses(listener: () => void): () => void;
|
|
21
|
+
export declare function listBackgroundProcesses(): BackgroundProcessSummary[];
|
|
22
|
+
export declare function getBackgroundProcess(backgroundId: string): BackgroundProcessSummary | undefined;
|
|
23
|
+
export declare function startBackgroundProcess(input: {
|
|
24
|
+
command: string;
|
|
25
|
+
cwd: string;
|
|
26
|
+
}): BackgroundProcessSummary;
|
|
27
|
+
export declare function killBackgroundProcess(backgroundId: string, killGraceMs?: number): Promise<BackgroundProcessSummary | undefined>;
|
|
28
|
+
/** Terminate every owned tree and clear the session-local registry and handles. */
|
|
29
|
+
export declare function teardownBackgroundProcesses(killGraceMs?: number): Promise<BackgroundProcessSummary[]>;
|
|
30
|
+
/** Install CLI-level abnormal-exit teardown for SIGINT and SIGTERM. */
|
|
31
|
+
export declare function installBackgroundProcessSignalHandlers(): void;
|
|
32
|
+
/** Best-effort synchronous safety net for process.exit and otherwise unawaitable exits. */
|
|
33
|
+
export declare function terminateBackgroundProcessesSync(): void;
|
|
34
|
+
/** Test-only reset; callers should normally use teardownBackgroundProcesses. */
|
|
35
|
+
export declare function resetBackgroundProcessesForTests(): Promise<void>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
import { BACKGROUND_PROCESS_HISTORY_LIMIT, BACKGROUND_PROCESS_MAX_CONCURRENCY } from '../agent/budgets.js';
|
|
4
|
+
import { registerDynamicToolOutput, unregisterDynamicToolOutput } from '../agent/toolOutputStore.js';
|
|
5
|
+
import { BACKGROUND_PROCESS_OUTPUT_BYTES } from '../limits/byteBudgets.js';
|
|
6
|
+
import { signalProcessTree } from './runBoundedProcess.js';
|
|
7
|
+
import { truncateUtf8TailBufferAtBytes } from '../../utils/utf8.js';
|
|
8
|
+
class OutputRing {
|
|
9
|
+
decoder = new StringDecoder('utf8');
|
|
10
|
+
retained = Buffer.alloc(0);
|
|
11
|
+
totalBytes = 0;
|
|
12
|
+
appendText(completeText) {
|
|
13
|
+
if (!completeText)
|
|
14
|
+
return;
|
|
15
|
+
const bytes = Buffer.from(completeText, 'utf8');
|
|
16
|
+
this.retained = this.retained.length === 0 ? bytes : Buffer.concat([this.retained, bytes]);
|
|
17
|
+
this.retained = truncateUtf8TailBufferAtBytes(this.retained, BACKGROUND_PROCESS_OUTPUT_BYTES).buffer;
|
|
18
|
+
}
|
|
19
|
+
add(chunk) {
|
|
20
|
+
this.totalBytes += chunk.length;
|
|
21
|
+
this.appendText(this.decoder.write(chunk));
|
|
22
|
+
}
|
|
23
|
+
end() {
|
|
24
|
+
this.appendText(this.decoder.end());
|
|
25
|
+
}
|
|
26
|
+
snapshot() {
|
|
27
|
+
return { content: this.retained.toString('utf8'), totalBytes: this.totalBytes };
|
|
28
|
+
}
|
|
29
|
+
stats() {
|
|
30
|
+
return { totalBytes: this.totalBytes, retainedBytes: this.retained.length, omittedBytes: Math.max(0, this.totalBytes - this.retained.length) };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const records = new Map();
|
|
34
|
+
const listeners = new Set();
|
|
35
|
+
let nextId = 1;
|
|
36
|
+
let exitHookInstalled = false;
|
|
37
|
+
function notify() {
|
|
38
|
+
for (const listener of listeners)
|
|
39
|
+
listener();
|
|
40
|
+
}
|
|
41
|
+
function installExitHook() {
|
|
42
|
+
if (exitHookInstalled)
|
|
43
|
+
return;
|
|
44
|
+
exitHookInstalled = true;
|
|
45
|
+
process.once('exit', terminateBackgroundProcessesSync);
|
|
46
|
+
}
|
|
47
|
+
function activeRecords() {
|
|
48
|
+
return [...records.values()].filter(record => record.summary.status === 'running');
|
|
49
|
+
}
|
|
50
|
+
function pruneCompletedRecords() {
|
|
51
|
+
const completed = [...records.values()].filter(record => record.summary.status !== 'running');
|
|
52
|
+
for (const record of completed.slice(0, Math.max(0, completed.length - BACKGROUND_PROCESS_HISTORY_LIMIT))) {
|
|
53
|
+
records.delete(record.summary.backgroundId);
|
|
54
|
+
unregisterDynamicToolOutput(record.summary.outputHandle);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function publicSummary(record) {
|
|
58
|
+
return { ...record.summary, outputBytes: record.ring.stats() };
|
|
59
|
+
}
|
|
60
|
+
export function backgroundProcessCount() {
|
|
61
|
+
return activeRecords().length;
|
|
62
|
+
}
|
|
63
|
+
export function subscribeBackgroundProcesses(listener) {
|
|
64
|
+
listeners.add(listener);
|
|
65
|
+
return () => { listeners.delete(listener); };
|
|
66
|
+
}
|
|
67
|
+
export function listBackgroundProcesses() {
|
|
68
|
+
return [...records.values()].map(publicSummary);
|
|
69
|
+
}
|
|
70
|
+
export function getBackgroundProcess(backgroundId) {
|
|
71
|
+
const record = records.get(backgroundId);
|
|
72
|
+
return record ? publicSummary(record) : undefined;
|
|
73
|
+
}
|
|
74
|
+
export function startBackgroundProcess(input) {
|
|
75
|
+
if (activeRecords().length >= BACKGROUND_PROCESS_MAX_CONCURRENCY) {
|
|
76
|
+
throw new Error(`Background process limit reached (${BACKGROUND_PROCESS_MAX_CONCURRENCY}). Kill an existing process with process action=kill, then retry.`);
|
|
77
|
+
}
|
|
78
|
+
installExitHook();
|
|
79
|
+
const backgroundId = `background-${nextId++}`;
|
|
80
|
+
const child = spawn('bash', ['-lc', input.command], {
|
|
81
|
+
cwd: input.cwd,
|
|
82
|
+
detached: process.platform !== 'win32',
|
|
83
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
84
|
+
});
|
|
85
|
+
const ring = new OutputRing();
|
|
86
|
+
const outputHandle = registerDynamicToolOutput(() => ring.snapshot());
|
|
87
|
+
const summary = {
|
|
88
|
+
backgroundId,
|
|
89
|
+
...(child.pid == null ? {} : { pid: child.pid }),
|
|
90
|
+
command: input.command,
|
|
91
|
+
cwd: input.cwd,
|
|
92
|
+
startedAt: new Date().toISOString(),
|
|
93
|
+
status: 'running',
|
|
94
|
+
outputHandle,
|
|
95
|
+
};
|
|
96
|
+
const record = { child, ring, closed: false, summary };
|
|
97
|
+
records.set(backgroundId, record);
|
|
98
|
+
child.stdout?.on('data', (chunk) => ring.add(chunk));
|
|
99
|
+
child.stderr?.on('data', (chunk) => ring.add(chunk));
|
|
100
|
+
child.once('error', error => {
|
|
101
|
+
summary.status = 'failed';
|
|
102
|
+
const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
|
|
103
|
+
// bash is required on Windows (via WSL or Git Bash). Without it, spawn
|
|
104
|
+
// fails with ENOENT; surface a clearer message than the raw syscall error.
|
|
105
|
+
summary.error = code === 'ENOENT' && process.platform === 'win32'
|
|
106
|
+
? `bash was not found on PATH. Install WSL or Git Bash, or run haze on a POSIX shell. Underlying error: ${error.message}`
|
|
107
|
+
: error.message;
|
|
108
|
+
notify();
|
|
109
|
+
});
|
|
110
|
+
child.once('close', (code, signal) => {
|
|
111
|
+
record.closed = true;
|
|
112
|
+
ring.end();
|
|
113
|
+
summary.code = code;
|
|
114
|
+
summary.signal = signal;
|
|
115
|
+
if (summary.status === 'running')
|
|
116
|
+
summary.status = 'exited';
|
|
117
|
+
child.stdout?.destroy();
|
|
118
|
+
child.stderr?.destroy();
|
|
119
|
+
pruneCompletedRecords();
|
|
120
|
+
notify();
|
|
121
|
+
});
|
|
122
|
+
notify();
|
|
123
|
+
return publicSummary(record);
|
|
124
|
+
}
|
|
125
|
+
function waitForClose(record, timeoutMs) {
|
|
126
|
+
if (record.closed)
|
|
127
|
+
return Promise.resolve(true);
|
|
128
|
+
return new Promise(resolve => {
|
|
129
|
+
const timeout = setTimeout(() => { cleanup(); resolve(false); }, timeoutMs);
|
|
130
|
+
timeout.unref?.();
|
|
131
|
+
const onClose = () => { cleanup(); resolve(true); };
|
|
132
|
+
const cleanup = () => { clearTimeout(timeout); record.child.off('close', onClose); };
|
|
133
|
+
record.child.once('close', onClose);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export async function killBackgroundProcess(backgroundId, killGraceMs = 500) {
|
|
137
|
+
const record = records.get(backgroundId);
|
|
138
|
+
if (!record)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (record.summary.status !== 'running')
|
|
141
|
+
return publicSummary(record);
|
|
142
|
+
signalProcessTree(record.child, 'SIGTERM');
|
|
143
|
+
let closed = await waitForClose(record, killGraceMs);
|
|
144
|
+
if (!closed) {
|
|
145
|
+
signalProcessTree(record.child, 'SIGKILL');
|
|
146
|
+
closed = await waitForClose(record, 100);
|
|
147
|
+
record.child.stdout?.destroy();
|
|
148
|
+
record.child.stderr?.destroy();
|
|
149
|
+
}
|
|
150
|
+
const terminated = closed || record.child.exitCode != null || record.child.signalCode != null;
|
|
151
|
+
if (terminated)
|
|
152
|
+
record.summary.status = 'killed';
|
|
153
|
+
else
|
|
154
|
+
record.summary.error = `Failed to terminate process tree for ${backgroundId}.`;
|
|
155
|
+
notify();
|
|
156
|
+
return publicSummary(record);
|
|
157
|
+
}
|
|
158
|
+
/** Terminate every owned tree and clear the session-local registry and handles. */
|
|
159
|
+
export async function teardownBackgroundProcesses(killGraceMs = 500) {
|
|
160
|
+
const active = activeRecords();
|
|
161
|
+
const results = await Promise.all(active.map(record => killBackgroundProcess(record.summary.backgroundId, killGraceMs)));
|
|
162
|
+
const tornDown = results.filter((result) => result != null);
|
|
163
|
+
const failures = tornDown.filter(result => result.status !== 'killed');
|
|
164
|
+
if (failures.length > 0)
|
|
165
|
+
throw new Error(`Failed to terminate background processes: ${failures.map(result => result.backgroundId).join(', ')}.`);
|
|
166
|
+
for (const record of records.values())
|
|
167
|
+
unregisterDynamicToolOutput(record.summary.outputHandle);
|
|
168
|
+
records.clear();
|
|
169
|
+
notify();
|
|
170
|
+
return tornDown;
|
|
171
|
+
}
|
|
172
|
+
let signalHandlersInstalled = false;
|
|
173
|
+
/** Install CLI-level abnormal-exit teardown for SIGINT and SIGTERM. */
|
|
174
|
+
export function installBackgroundProcessSignalHandlers() {
|
|
175
|
+
if (signalHandlersInstalled)
|
|
176
|
+
return;
|
|
177
|
+
signalHandlersInstalled = true;
|
|
178
|
+
const handle = (signal, exitCode) => {
|
|
179
|
+
process.once(signal, () => {
|
|
180
|
+
void teardownBackgroundProcesses(200).finally(() => process.exit(exitCode));
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
handle('SIGINT', 130);
|
|
184
|
+
handle('SIGTERM', 143);
|
|
185
|
+
}
|
|
186
|
+
/** Best-effort synchronous safety net for process.exit and otherwise unawaitable exits. */
|
|
187
|
+
export function terminateBackgroundProcessesSync() {
|
|
188
|
+
for (const record of activeRecords())
|
|
189
|
+
signalProcessTree(record.child, 'SIGTERM');
|
|
190
|
+
}
|
|
191
|
+
/** Test-only reset; callers should normally use teardownBackgroundProcesses. */
|
|
192
|
+
export async function resetBackgroundProcessesForTests() {
|
|
193
|
+
await teardownBackgroundProcesses(25);
|
|
194
|
+
nextId = 1;
|
|
195
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn, type ChildProcess } from 'node:child_process';
|
|
1
2
|
export interface BoundedStream {
|
|
2
3
|
text: string;
|
|
3
4
|
totalBytes: number;
|
|
@@ -15,6 +16,13 @@ export interface BoundedProcessResult {
|
|
|
15
16
|
durationMs: number;
|
|
16
17
|
error?: string;
|
|
17
18
|
}
|
|
19
|
+
export interface ProcessTreeSignalOptions {
|
|
20
|
+
/** @internal testing seam. */
|
|
21
|
+
platform?: NodeJS.Platform;
|
|
22
|
+
/** @internal testing seam. */
|
|
23
|
+
spawnProcess?: typeof spawn;
|
|
24
|
+
}
|
|
25
|
+
export declare function signalProcessTree(child: Pick<ChildProcess, 'pid' | 'kill'>, signal: NodeJS.Signals, options?: ProcessTreeSignalOptions): void;
|
|
18
26
|
export declare function runBoundedProcess(input: {
|
|
19
27
|
command: string;
|
|
20
28
|
args: string[];
|
|
@@ -24,4 +32,5 @@ export declare function runBoundedProcess(input: {
|
|
|
24
32
|
maxStdoutBytes: number;
|
|
25
33
|
maxStderrBytes: number;
|
|
26
34
|
killGraceMs?: number;
|
|
35
|
+
onStdoutChunk?: (chunk: Buffer) => boolean | void;
|
|
27
36
|
}): Promise<BoundedProcessResult>;
|