@denizokcu/haze 1.7.10 → 1.7.11
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 +7 -0
- package/README.md +18 -8
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +2 -1
- package/dist/cli/chat/BusyBar.js +2 -2
- package/dist/cli/chat/chatMetrics.d.ts +25 -0
- package/dist/cli/chat/chatMetrics.js +36 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +27 -18
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +25 -8
- package/dist/cli/chat/transcriptPartition.js +10 -4
- package/dist/cli/chat/wizard/providerHandlers.js +57 -9
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +5 -1
- package/dist/cli/commands/chat.js +39 -7
- package/dist/cli/commands/commandHelp.js +2 -2
- package/dist/cli/commands/providerWizard.js +9 -17
- package/dist/cli/commands/reasoningCommand.d.ts +1 -0
- package/dist/cli/commands/reasoningCommand.js +32 -4
- package/dist/cli/commands/runCommand.js +7 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +5 -1
- package/dist/cli/commands/streaming/attemptSetup.js +5 -3
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +1 -1
- package/dist/cli/commands/streaming/goalSupervisor.js +20 -1
- package/dist/cli/commands/streaming/streamLoop.js +11 -10
- package/dist/cli/commands/streaming.d.ts +2 -0
- package/dist/cli/commands/wizardFlow.d.ts +1 -0
- package/dist/cli/commands/wizardFlow.js +10 -4
- package/dist/cli/index.js +5 -3
- package/dist/config/hazeBuild.d.ts +2 -2
- package/dist/config/hazeBuild.js +2 -2
- package/dist/config/modelDiscovery.d.ts +1 -1
- package/dist/config/modelDiscovery.js +8 -8
- package/dist/config/{modelCatalog.d.ts → providerModelFacts.d.ts} +13 -2
- package/dist/config/{modelCatalog.js → providerModelFacts.js} +145 -21
- package/dist/config/providerPresets.d.ts +8 -19
- package/dist/config/providerPresets.js +86 -555
- package/dist/config/providerReasoning.d.ts +16 -0
- package/dist/config/providerReasoning.js +56 -0
- package/dist/config/providers.d.ts +4 -0
- package/dist/config/providers.js +19 -2
- package/dist/config/settings.d.ts +14 -0
- package/dist/config/settings.js +5 -0
- package/dist/core/agent/events.d.ts +1 -1
- package/dist/core/agent/providerTransition.d.ts +8 -0
- package/dist/core/agent/providerTransition.js +47 -0
- package/dist/core/agent/reasoningPolicy.d.ts +1 -1
- package/dist/core/agent/reasoningPolicy.js +4 -2
- package/dist/core/limits.d.ts +0 -2
- package/dist/core/limits.js +0 -2
- package/dist/core/providerContracts.d.ts +9 -8
- package/dist/core/providerContracts.js +21 -1
- package/dist/core/safety/redaction.js +12 -2
- package/dist/core/session/sessionSlimming.js +5 -59
- package/dist/core/session/sessionStore.d.ts +4 -0
- package/dist/core/session/sessionStore.js +149 -9
- package/dist/core/session/snapshotCodec.d.ts +5 -0
- package/dist/core/session/snapshotCodec.js +47 -0
- package/dist/core/shellOutput/registry.js +2 -46
- package/dist/core/subagent/executionProfiles.js +4 -1
- package/dist/core/toolOutput/reduction.d.ts +55 -2
- package/dist/core/toolOutput/reduction.js +77 -2
- package/dist/llm/client.d.ts +4 -2
- package/dist/llm/client.js +104 -55
- package/dist/llm/hazeTools.d.ts +16 -16
- package/dist/llm/mistralReasoning.d.ts +2 -0
- package/dist/llm/mistralReasoning.js +17 -0
- package/dist/llm/mistralVibeAuth.d.ts +5 -0
- package/dist/llm/mistralVibeAuth.js +63 -0
- package/dist/llm/requestContext.js +8 -7
- package/dist/llm/subagentRunner.js +15 -7
- package/dist/llm/toolResultTypes.js +7 -1
- package/dist/llm/tools/fetchTool.d.ts +16 -16
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -11
- package/dist/llm/tools/replaceInFiles.js +5 -0
- package/package.json +14 -8
|
@@ -4,6 +4,7 @@ import fs from 'node:fs/promises';
|
|
|
4
4
|
import { pathExists } from '../../utils/fs.js';
|
|
5
5
|
import { HAZE_DIR } from '../../config/paths.js';
|
|
6
6
|
import { prepareSessionEntryForWrite, repairRestoredConversation } from './sessionSlimming.js';
|
|
7
|
+
import { decodeSnapshotMessages, encodeSnapshotMessages } from './snapshotCodec.js';
|
|
7
8
|
import { appendPrivateFile, ensurePrivateDir, tightenPrivateFile, writePrivateFileAtomic } from '../../config/privateStorage.js';
|
|
8
9
|
import { JSONL_LINE_BYTES } from '../limits.js';
|
|
9
10
|
import { iterateBoundedUtf8Lines } from '../io/boundedRead.js';
|
|
@@ -84,6 +85,51 @@ function entryMakesSessionResumable(entry) {
|
|
|
84
85
|
return entry.text.trim().length > 0;
|
|
85
86
|
return entry.type === 'conversation_snapshot' && entry.messages.length > 0;
|
|
86
87
|
}
|
|
88
|
+
// A snapshot is one logical record, but large opaque provider data must not
|
|
89
|
+
// exceed the line reader's bound. The commit line makes incomplete writes
|
|
90
|
+
// invisible; the digest prevents a damaged snapshot from being replayed.
|
|
91
|
+
const SNAPSHOT_CHUNK_BYTES = 256 * 1024;
|
|
92
|
+
const MAX_SNAPSHOT_BYTES = 64 * 1024 * 1024;
|
|
93
|
+
function serializeSessionEntry(entry) {
|
|
94
|
+
const serializable = entry.type === 'conversation_snapshot' ? { ...entry, messages: encodeSnapshotMessages(entry.messages) } : entry;
|
|
95
|
+
const json = JSON.stringify(serializable);
|
|
96
|
+
const bytes = Buffer.from(json, 'utf8');
|
|
97
|
+
if (bytes.length <= JSONL_LINE_BYTES - 1)
|
|
98
|
+
return `${json}\n`;
|
|
99
|
+
if (entry.type !== 'conversation_snapshot')
|
|
100
|
+
throw new Error(`Session ${entry.type} exceeds the ${JSONL_LINE_BYTES} byte line limit`);
|
|
101
|
+
if (bytes.length > MAX_SNAPSHOT_BYTES)
|
|
102
|
+
throw new Error(`Session snapshot exceeds the ${MAX_SNAPSHOT_BYTES} byte limit`);
|
|
103
|
+
const id = crypto.randomUUID();
|
|
104
|
+
const count = Math.ceil(bytes.length / SNAPSHOT_CHUNK_BYTES);
|
|
105
|
+
const digest = crypto.createHash('sha256').update(bytes).digest('hex');
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (let index = 0; index < count; index++) {
|
|
108
|
+
lines.push(JSON.stringify({ type: 'snapshot_chunk', id, index, count, data: bytes.subarray(index * SNAPSHOT_CHUNK_BYTES, (index + 1) * SNAPSHOT_CHUNK_BYTES).toString('base64') }));
|
|
109
|
+
}
|
|
110
|
+
lines.push(JSON.stringify({ type: 'snapshot_commit', id, count, bytes: bytes.length, digest }));
|
|
111
|
+
return `${lines.join('\n')}\n`;
|
|
112
|
+
}
|
|
113
|
+
async function hasUnterminatedTail(file) {
|
|
114
|
+
const handle = await fs.open(file, 'r').catch(error => {
|
|
115
|
+
if (error.code === 'ENOENT')
|
|
116
|
+
return undefined;
|
|
117
|
+
throw error;
|
|
118
|
+
});
|
|
119
|
+
if (!handle)
|
|
120
|
+
return false;
|
|
121
|
+
try {
|
|
122
|
+
const { size } = await handle.stat();
|
|
123
|
+
if (!size)
|
|
124
|
+
return false;
|
|
125
|
+
const last = Buffer.alloc(1);
|
|
126
|
+
await handle.read(last, 0, 1, size - 1);
|
|
127
|
+
return last[0] !== 10;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
await handle.close();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
87
133
|
export async function appendSessionEntry(session, entry) {
|
|
88
134
|
const file = validatedSessionFile(session);
|
|
89
135
|
const prepared = prepareSessionEntryForWrite(entry, { redactSecrets: session.redactSecrets === true });
|
|
@@ -96,11 +142,21 @@ export async function appendSessionEntry(session, entry) {
|
|
|
96
142
|
return;
|
|
97
143
|
}
|
|
98
144
|
const entries = [deferred.header, ...deferred.entries, prepared];
|
|
99
|
-
await appendPrivateFile(file, entries.map(
|
|
145
|
+
await appendPrivateFile(file, entries.map(serializeSessionEntry).join(''));
|
|
100
146
|
session.deferredWrite = undefined;
|
|
147
|
+
session.tailChecked = true;
|
|
101
148
|
return;
|
|
102
149
|
}
|
|
103
|
-
await
|
|
150
|
+
const separator = !session.tailChecked && await hasUnterminatedTail(file) ? '\n' : '';
|
|
151
|
+
try {
|
|
152
|
+
await appendPrivateFile(file, separator + serializeSessionEntry(prepared));
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
// A failed append can leave a partial JSONL line even in this process.
|
|
156
|
+
session.tailChecked = false;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
session.tailChecked = true;
|
|
104
160
|
// Snapshot deduplication runs inside the same serialized writer as the
|
|
105
161
|
// append, so ordering with subsequent entries is preserved (F-03).
|
|
106
162
|
await vacuumSessionFileIfLarge(session).catch(() => undefined);
|
|
@@ -168,7 +224,7 @@ export async function vacuumSessionFileIfLarge(session, thresholdBytes = effecti
|
|
|
168
224
|
const droppedGoalBytes = entries
|
|
169
225
|
.filter((entry, index) => entry.type === 'goal' && !keepGoal.has(index))
|
|
170
226
|
.reduce((sum, entry) => sum + Buffer.byteLength(JSON.stringify(entry), 'utf8'), 0);
|
|
171
|
-
const serialized = kept.map(
|
|
227
|
+
const serialized = kept.map(serializeSessionEntry).join('');
|
|
172
228
|
// Only rewrite when it meaningfully shrinks the file (otherwise a single
|
|
173
229
|
// dominant snapshot would trigger a full rewrite on every append), or when
|
|
174
230
|
// the goal-ledger trim alone has accumulated enough to amortize the rewrite.
|
|
@@ -250,15 +306,18 @@ function parseSessionEntry(value) {
|
|
|
250
306
|
case 'conversation_snapshot':
|
|
251
307
|
if (typeof value.at !== 'string' || !Array.isArray(value.messages))
|
|
252
308
|
return invalid('conversation_snapshot messages must be an array');
|
|
309
|
+
if (value.selection !== undefined && (!isRecord(value.selection) || typeof value.selection.provider !== 'string' || !value.selection.provider.trim() || typeof value.selection.model !== 'string' || !value.selection.model.trim() || (value.selection.endpointFingerprint !== undefined && (typeof value.selection.endpointFingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(value.selection.endpointFingerprint)))))
|
|
310
|
+
return invalid('invalid conversation_snapshot selection');
|
|
253
311
|
if (!value.messages.every((message) => isRecord(message)
|
|
254
312
|
&& typeof message.role === 'string'
|
|
255
313
|
&& MODEL_MESSAGE_ROLES.has(message.role)))
|
|
256
314
|
return invalid('conversation_snapshot contains an invalid message role');
|
|
257
|
-
return value;
|
|
315
|
+
return { ...value, messages: decodeSnapshotMessages(value.messages) };
|
|
258
316
|
case 'model_selection':
|
|
259
317
|
if (typeof value.at !== 'string' || !isRecord(value.selection)
|
|
260
318
|
|| typeof value.selection.provider !== 'string' || !value.selection.provider.trim()
|
|
261
|
-
|| typeof value.selection.model !== 'string' || !value.selection.model.trim()
|
|
319
|
+
|| typeof value.selection.model !== 'string' || !value.selection.model.trim()
|
|
320
|
+
|| (value.selection.endpointFingerprint !== undefined && (typeof value.selection.endpointFingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(value.selection.endpointFingerprint))))
|
|
262
321
|
return invalid('invalid model_selection');
|
|
263
322
|
return value;
|
|
264
323
|
case 'work_state_snapshot':
|
|
@@ -305,20 +364,95 @@ async function scanSessionEntries(session, onEntry) {
|
|
|
305
364
|
else
|
|
306
365
|
omittedErrors++;
|
|
307
366
|
};
|
|
367
|
+
let pending;
|
|
368
|
+
let legacyReader;
|
|
369
|
+
const recoverLegacySnapshot = async (lineNumber) => {
|
|
370
|
+
legacyReader ??= iterateBoundedUtf8Lines(file, MAX_SNAPSHOT_BYTES);
|
|
371
|
+
for (;;) {
|
|
372
|
+
const next = await legacyReader.next();
|
|
373
|
+
if (next.done || next.value.lineNumber > lineNumber)
|
|
374
|
+
return undefined;
|
|
375
|
+
if (next.value.lineNumber < lineNumber)
|
|
376
|
+
continue;
|
|
377
|
+
if (next.value.oversized)
|
|
378
|
+
return undefined;
|
|
379
|
+
try {
|
|
380
|
+
const value = JSON.parse(next.value.line);
|
|
381
|
+
if (!isRecord(value) || value.type !== 'conversation_snapshot')
|
|
382
|
+
return undefined;
|
|
383
|
+
return parseSessionEntry(value);
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
};
|
|
308
390
|
for await (const { line, lineNumber, oversized } of iterateBoundedUtf8Lines(file, JSONL_LINE_BYTES)) {
|
|
309
391
|
if (!line && !oversized)
|
|
310
392
|
continue;
|
|
311
393
|
if (oversized) {
|
|
394
|
+
if (pending) {
|
|
395
|
+
report(`Line ${pending.line}: incomplete snapshot`);
|
|
396
|
+
pending = undefined;
|
|
397
|
+
}
|
|
398
|
+
const legacy = await recoverLegacySnapshot(lineNumber);
|
|
399
|
+
if (legacy) {
|
|
400
|
+
onEntry(legacy);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
312
403
|
report(`Line ${lineNumber}: exceeds ${JSONL_LINE_BYTES} byte limit`);
|
|
313
404
|
continue;
|
|
314
405
|
}
|
|
315
406
|
try {
|
|
316
|
-
|
|
407
|
+
const value = JSON.parse(line);
|
|
408
|
+
if (isRecord(value) && value.type === 'snapshot_chunk') {
|
|
409
|
+
if (typeof value.id !== 'string' || !Number.isInteger(value.index) || !Number.isInteger(value.count) || typeof value.data !== 'string' || !/^[A-Za-z0-9+/]*={0,2}$/.test(value.data))
|
|
410
|
+
throw new Error('invalid snapshot chunk');
|
|
411
|
+
const index = value.index;
|
|
412
|
+
const count = value.count;
|
|
413
|
+
if (count < 1 || count > Math.ceil(MAX_SNAPSHOT_BYTES / SNAPSHOT_CHUNK_BYTES) || index < 0 || index >= count || value.data.length > Math.ceil(SNAPSHOT_CHUNK_BYTES / 3) * 4)
|
|
414
|
+
throw new Error('snapshot chunk out of bounds');
|
|
415
|
+
if (index === 0) {
|
|
416
|
+
if (pending)
|
|
417
|
+
report(`Line ${pending.line}: incomplete snapshot`);
|
|
418
|
+
pending = { id: value.id, count, chunks: [], bytes: 0, line: lineNumber };
|
|
419
|
+
}
|
|
420
|
+
if (!pending || pending.id !== value.id || pending.count !== count || pending.chunks.length !== index)
|
|
421
|
+
throw new Error('snapshot chunks out of order');
|
|
422
|
+
const chunk = Buffer.from(value.data, 'base64');
|
|
423
|
+
pending.bytes += chunk.length;
|
|
424
|
+
if (chunk.length > SNAPSHOT_CHUNK_BYTES || pending.bytes > MAX_SNAPSHOT_BYTES)
|
|
425
|
+
throw new Error('snapshot exceeds size limit');
|
|
426
|
+
pending.chunks.push(chunk);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (isRecord(value) && value.type === 'snapshot_commit') {
|
|
430
|
+
if (!pending || value.id !== pending.id || value.count !== pending.count || pending.chunks.length !== pending.count || value.bytes !== pending.bytes || typeof value.digest !== 'string')
|
|
431
|
+
throw new Error('invalid snapshot commit');
|
|
432
|
+
const bytes = Buffer.concat(pending.chunks, pending.bytes);
|
|
433
|
+
if (crypto.createHash('sha256').update(bytes).digest('hex') !== value.digest)
|
|
434
|
+
throw new Error('snapshot checksum mismatch');
|
|
435
|
+
const entry = parseSessionEntry(JSON.parse(bytes.toString('utf8')));
|
|
436
|
+
if (entry.type !== 'conversation_snapshot')
|
|
437
|
+
throw new Error('chunked entry is not a conversation snapshot');
|
|
438
|
+
pending = undefined;
|
|
439
|
+
onEntry(entry);
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (pending) {
|
|
443
|
+
report(`Line ${pending.line}: incomplete snapshot`);
|
|
444
|
+
pending = undefined;
|
|
445
|
+
}
|
|
446
|
+
onEntry(parseSessionEntry(value));
|
|
317
447
|
}
|
|
318
448
|
catch (error) {
|
|
449
|
+
pending = undefined;
|
|
319
450
|
report(`Line ${lineNumber}: ${error instanceof Error ? error.message : String(error)}`);
|
|
320
451
|
}
|
|
321
452
|
}
|
|
453
|
+
await legacyReader?.return(undefined);
|
|
454
|
+
if (pending)
|
|
455
|
+
report(`Line ${pending.line}: incomplete snapshot`);
|
|
322
456
|
if (omittedErrors > 0)
|
|
323
457
|
parseErrors.push(`${omittedErrors} additional parse errors omitted.`);
|
|
324
458
|
return parseErrors;
|
|
@@ -390,8 +524,11 @@ export async function restoreSessionState(session) {
|
|
|
390
524
|
// Legacy slim markers (pre-envelope-fix) are re-wrapped so the restored
|
|
391
525
|
// conversation is a protocol-safe ModelMessage[] for the next provider
|
|
392
526
|
// request (F-09).
|
|
393
|
-
if (entry.type === 'conversation_snapshot')
|
|
527
|
+
if (entry.type === 'conversation_snapshot') {
|
|
394
528
|
messages = repairRestoredConversation(entry.messages);
|
|
529
|
+
if (entry.selection)
|
|
530
|
+
modelSelection = entry.selection;
|
|
531
|
+
}
|
|
395
532
|
// SU-02: a durable clear marker means "no conversation after this line";
|
|
396
533
|
// later snapshots (if any) re-materialize it, otherwise restore yields [].
|
|
397
534
|
if (entry.type === 'event' && entry.name === 'clear') {
|
|
@@ -466,8 +603,11 @@ async function summarizeSession(session, stat) {
|
|
|
466
603
|
messageCount = entry.messages.length;
|
|
467
604
|
if (!firstUserPreview) {
|
|
468
605
|
const firstUser = entry.messages.find(message => message.role === 'user');
|
|
469
|
-
if (firstUser)
|
|
470
|
-
|
|
606
|
+
if (firstUser) {
|
|
607
|
+
const content = firstUser.content;
|
|
608
|
+
const text = typeof content === 'string' ? content : content.flatMap(part => part.type === 'text' ? [part.text] : []).join(' ');
|
|
609
|
+
firstUserPreview = previewText(text || '[attachment]');
|
|
610
|
+
}
|
|
471
611
|
}
|
|
472
612
|
}
|
|
473
613
|
if (entry.type === 'event' && entry.name === 'turn_end' && entry.text) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
/** Convert binary and URL file data into an unambiguous JSON representation. */
|
|
3
|
+
export declare function encodeSnapshotMessages(messages: ModelMessage[]): ModelMessage[];
|
|
4
|
+
/** Reconstruct file data before passing restored messages back to the SDK. */
|
|
5
|
+
export declare function decodeSnapshotMessages(messages: ModelMessage[]): ModelMessage[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const FILE_DATA_TAG = '__haze_file_data_v1';
|
|
2
|
+
/** Convert binary and URL file data into an unambiguous JSON representation. */
|
|
3
|
+
export function encodeSnapshotMessages(messages) {
|
|
4
|
+
return mapFileData(messages, data => {
|
|
5
|
+
if (data instanceof Uint8Array)
|
|
6
|
+
return { [FILE_DATA_TAG]: 'bytes', value: Buffer.from(data).toString('base64') };
|
|
7
|
+
if (data instanceof ArrayBuffer)
|
|
8
|
+
return { [FILE_DATA_TAG]: 'array-buffer', value: Buffer.from(data).toString('base64') };
|
|
9
|
+
if (data instanceof URL)
|
|
10
|
+
return { [FILE_DATA_TAG]: 'url', value: data.href };
|
|
11
|
+
return data;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** Reconstruct file data before passing restored messages back to the SDK. */
|
|
15
|
+
export function decodeSnapshotMessages(messages) {
|
|
16
|
+
return mapFileData(messages, data => {
|
|
17
|
+
if (typeof data !== 'object' || data === null || !(FILE_DATA_TAG in data))
|
|
18
|
+
return data;
|
|
19
|
+
const marker = data;
|
|
20
|
+
if (typeof marker.value !== 'string')
|
|
21
|
+
throw new Error('invalid snapshot file data');
|
|
22
|
+
if (marker[FILE_DATA_TAG] === 'url')
|
|
23
|
+
return new URL(marker.value);
|
|
24
|
+
if ((marker[FILE_DATA_TAG] !== 'bytes' && marker[FILE_DATA_TAG] !== 'array-buffer') || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(marker.value))
|
|
25
|
+
throw new Error('invalid snapshot file data');
|
|
26
|
+
const bytes = Uint8Array.from(Buffer.from(marker.value, 'base64'));
|
|
27
|
+
return marker[FILE_DATA_TAG] === 'array-buffer' ? bytes.buffer : bytes;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function mapFileData(messages, map) {
|
|
31
|
+
const mapValue = (value) => {
|
|
32
|
+
const mapped = map(value);
|
|
33
|
+
if (mapped !== value || typeof value !== 'object' || value === null)
|
|
34
|
+
return mapped;
|
|
35
|
+
const record = value;
|
|
36
|
+
if (record.type === 'data' && 'data' in record)
|
|
37
|
+
return { ...record, data: map(record.data) };
|
|
38
|
+
if (record.type === 'url' && 'url' in record)
|
|
39
|
+
return { ...record, url: map(record.url) };
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
return messages.map(message => {
|
|
43
|
+
if (!Array.isArray(message.content))
|
|
44
|
+
return message;
|
|
45
|
+
return { ...message, content: message.content.map(part => part.type === 'file' ? { ...part, data: mapValue(part.data) } : part.type === 'image' ? { ...part, image: mapValue(part.image) } : part) };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -5,7 +5,7 @@ import { reduceGitOutput } from './reducers/git.js';
|
|
|
5
5
|
import { reduceGhOutput } from './reducers/gh.js';
|
|
6
6
|
import { reduceSearchOutput } from './reducers/search.js';
|
|
7
7
|
import { reduceGenericLogOutput, reduceJsonOutput, reduceUnifiedDiffOutput } from './reducers/content.js';
|
|
8
|
-
import { capOutputForProcessing,
|
|
8
|
+
import { capOutputForProcessing, makeStreamReduction, passthroughReduction } from '../toolOutput/reduction.js';
|
|
9
9
|
const builtInLineFilters = [
|
|
10
10
|
{ name: 'markdownlint', matchCommand: /(^|[;&|]\s*)markdownlint\b/, stripAnsi: true, truncateLinesAt: 200, maxLines: 80, onEmpty: 'markdownlint: ok' },
|
|
11
11
|
{ name: 'shellcheck', matchCommand: /(^|[;&|]\s*)shellcheck\b/, stripAnsi: true, stripLinesMatching: [/^In .* line \d+:/], truncateLinesAt: 200, maxLines: 100, onEmpty: 'shellcheck: ok' },
|
|
@@ -16,51 +16,7 @@ const builtInLineFilters = [
|
|
|
16
16
|
{ name: 'system-list', matchCommand: /(^|[;&|]\s*)(?:du|df|ps)\b/, stripAnsi: true, truncateLinesAt: 180, maxLines: 50 },
|
|
17
17
|
];
|
|
18
18
|
function makeReduction(raw, text, filtered, filterName, input, warning, contentKind = 'generic') {
|
|
19
|
-
|
|
20
|
-
let handle;
|
|
21
|
-
let truncated = false;
|
|
22
|
-
if (finalText.length > input.compactMaxChars) {
|
|
23
|
-
const compacted = input.fallbackCompact(finalText, input.compactMaxChars);
|
|
24
|
-
finalText = compacted.text;
|
|
25
|
-
handle = compacted.handle;
|
|
26
|
-
truncated = compacted.truncated;
|
|
27
|
-
}
|
|
28
|
-
const lossy = filtered && finalText !== raw;
|
|
29
|
-
const rawHandle = lossy && input.storeRawOutput ? input.storeRawOutput(raw) : handle;
|
|
30
|
-
if (filtered && contentKind !== 'validation' && raw.length > 2000 && isInflating(raw, finalText))
|
|
31
|
-
return passthroughReduction(raw, input);
|
|
32
|
-
if (lossy && rawHandle && !finalText.includes(rawHandle))
|
|
33
|
-
finalText = `${finalText}\n\n[${retrievalHint(rawHandle)}]`;
|
|
34
|
-
const metrics = reductionMetrics(raw, finalText);
|
|
35
|
-
return {
|
|
36
|
-
text: finalText,
|
|
37
|
-
truncated,
|
|
38
|
-
filtered,
|
|
39
|
-
...(filterName ? { filterName, reducerName: filterName } : {}),
|
|
40
|
-
contentKind,
|
|
41
|
-
lossy,
|
|
42
|
-
parseTier: warning ? 'degraded' : filtered ? 'full' : 'passthrough',
|
|
43
|
-
...(warning ? { warning } : {}),
|
|
44
|
-
...(handle ?? rawHandle ? { handle: handle ?? rawHandle } : {}),
|
|
45
|
-
...(rawHandle ? { rawHandle } : {}),
|
|
46
|
-
omittedChars: Math.max(0, raw.length - finalText.length),
|
|
47
|
-
...metrics,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function passthroughReduction(raw, input) {
|
|
51
|
-
const compacted = input.fallbackCompact(raw, input.compactMaxChars);
|
|
52
|
-
return {
|
|
53
|
-
text: compacted.text,
|
|
54
|
-
truncated: compacted.truncated,
|
|
55
|
-
filtered: false,
|
|
56
|
-
reducerName: 'generic-cap',
|
|
57
|
-
contentKind: 'generic',
|
|
58
|
-
lossy: compacted.truncated,
|
|
59
|
-
parseTier: 'passthrough',
|
|
60
|
-
...(compacted.handle ? { handle: compacted.handle, rawHandle: compacted.handle } : {}),
|
|
61
|
-
omittedChars: compacted.omittedChars ?? Math.max(0, raw.length - compacted.text.length),
|
|
62
|
-
...reductionMetrics(raw, compacted.text),
|
|
63
|
-
};
|
|
19
|
+
return makeStreamReduction(raw, text, filtered, filterName, input, warning, contentKind);
|
|
64
20
|
}
|
|
65
21
|
export function filterShellOutput(input) {
|
|
66
22
|
try {
|
|
@@ -17,7 +17,10 @@ export const COMPATIBILITY_PROFILE = {
|
|
|
17
17
|
deadlineMs: SUBAGENT_DEFAULT_DEADLINE_MS, maxRetries: 2,
|
|
18
18
|
};
|
|
19
19
|
export const BUILT_IN_SUBAGENT_PROFILES = {
|
|
20
|
-
|
|
20
|
+
// Ceiling only: the effective cap is the deployment manifest's native-worker
|
|
21
|
+
// allowance (requestContext clamps to it), so a 3-sequence server raises the
|
|
22
|
+
// fleet to 3 and a future multi-tenant server lowers it without a release.
|
|
23
|
+
'haze-build': { ...COMPATIBILITY_PROFILE, name: 'haze-build', maxConcurrency: 5, maxInputTokens: 48_000, maxOutputTokens: 6_144, maxRetries: 0 },
|
|
21
24
|
'local-safe': { ...COMPATIBILITY_PROFILE, name: 'local-safe', maxConcurrency: 1, maxSteps: 32, maxToolCalls: 24, maxOutputTokens: 4_096, maxInputTokens: 40_000, maxRetries: 0 },
|
|
22
25
|
'local-throughput': { ...COMPATIBILITY_PROFILE, name: 'local-throughput', maxConcurrency: 2, maxSteps: 40, maxToolCalls: 32, maxOutputTokens: 6_144, maxInputTokens: 48_000, maxRetries: 0 },
|
|
23
26
|
'cloud-balanced': { ...COMPATIBILITY_PROFILE, name: 'cloud-balanced', maxConcurrency: 3, deadlineMs: 360_000 },
|
|
@@ -9,7 +9,60 @@ export interface ReductionMetrics {
|
|
|
9
9
|
estimatedSavedTokens: number;
|
|
10
10
|
savingsPct: number;
|
|
11
11
|
}
|
|
12
|
+
export interface StreamReduction {
|
|
13
|
+
text: string;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
filtered: boolean;
|
|
16
|
+
reducerName?: string;
|
|
17
|
+
filterName?: string;
|
|
18
|
+
contentKind: ReductionContentKind;
|
|
19
|
+
lossy: boolean;
|
|
20
|
+
parseTier: ReductionParseTier;
|
|
21
|
+
warning?: string;
|
|
22
|
+
handle?: string;
|
|
23
|
+
rawHandle?: string;
|
|
24
|
+
omittedChars: number;
|
|
25
|
+
rawChars: number;
|
|
26
|
+
returnedChars: number;
|
|
27
|
+
rawTokensEstimate: number;
|
|
28
|
+
returnedTokensEstimate: number;
|
|
29
|
+
estimatedSavedTokens: number;
|
|
30
|
+
savingsPct: number;
|
|
31
|
+
}
|
|
12
32
|
export declare function capOutputForProcessing(text: string, maxChars?: number): string;
|
|
13
33
|
export declare function reductionMetrics(raw: string, returned: string): ReductionMetrics;
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Compact output for storage, keeping head + tail and storing the full text behind a handle.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compactOutput(text: string, maxChars: number, storeRawOutput?: (text: string) => string): {
|
|
38
|
+
text: string;
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
handle?: string;
|
|
41
|
+
omittedChars?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Create a stream reduction result for shell output.
|
|
45
|
+
*/
|
|
46
|
+
export declare function makeStreamReduction(raw: string, text: string, filtered: boolean, reducerName: string | undefined, input: {
|
|
47
|
+
storeRawOutput?: (text: string) => string;
|
|
48
|
+
compactMaxChars: number;
|
|
49
|
+
fallbackCompact?: (text: string, maxChars: number) => {
|
|
50
|
+
text: string;
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
handle?: string;
|
|
53
|
+
omittedChars?: number;
|
|
54
|
+
};
|
|
55
|
+
}, warning?: string, contentKind?: ReductionContentKind): StreamReduction;
|
|
56
|
+
/**
|
|
57
|
+
* Fallback reduction for passthrough output.
|
|
58
|
+
*/
|
|
59
|
+
export declare function passthroughReduction(raw: string, input: {
|
|
60
|
+
storeRawOutput?: (text: string) => string;
|
|
61
|
+
compactMaxChars: number;
|
|
62
|
+
fallbackCompact?: (text: string, maxChars: number) => {
|
|
63
|
+
text: string;
|
|
64
|
+
truncated: boolean;
|
|
65
|
+
handle?: string;
|
|
66
|
+
omittedChars?: number;
|
|
67
|
+
};
|
|
68
|
+
}): StreamReduction;
|
|
@@ -27,9 +27,84 @@ export function reductionMetrics(raw, returned) {
|
|
|
27
27
|
savingsPct,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
function retrievalHint(handle) {
|
|
31
31
|
return `Use readToolOutput with handle ${handle} for the original output.`;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
function isInflating(raw, returned) {
|
|
34
34
|
return raw.trim().length > 0 && returned.length > raw.length;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Compact output for storage, keeping head + tail and storing the full text behind a handle.
|
|
38
|
+
*/
|
|
39
|
+
export function compactOutput(text, maxChars, storeRawOutput) {
|
|
40
|
+
if (text.length <= maxChars)
|
|
41
|
+
return { text, truncated: false };
|
|
42
|
+
const handle = storeRawOutput?.(text);
|
|
43
|
+
const headChars = Math.floor(maxChars * 0.4);
|
|
44
|
+
const tailChars = maxChars - headChars;
|
|
45
|
+
const omitted = text.length - maxChars;
|
|
46
|
+
return {
|
|
47
|
+
text: `${text.slice(0, headChars)}\n\n[... ${omitted} characters omitted${handle ? `; use readToolOutput with handle ${handle}` : ''} ...]\n\n${text.slice(-tailChars)}`,
|
|
48
|
+
truncated: true,
|
|
49
|
+
omittedChars: omitted,
|
|
50
|
+
handle,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a stream reduction result for shell output.
|
|
55
|
+
*/
|
|
56
|
+
export function makeStreamReduction(raw, text, filtered, reducerName, input, warning, contentKind = 'generic') {
|
|
57
|
+
let finalText = text;
|
|
58
|
+
let handle;
|
|
59
|
+
let truncated = false;
|
|
60
|
+
const compactFn = input.fallbackCompact ?? ((value, max) => compactOutput(value, max, input.storeRawOutput));
|
|
61
|
+
if (finalText.length > input.compactMaxChars) {
|
|
62
|
+
const compacted = compactFn(finalText, input.compactMaxChars);
|
|
63
|
+
finalText = compacted.text;
|
|
64
|
+
handle = compacted.handle;
|
|
65
|
+
truncated = compacted.truncated;
|
|
66
|
+
}
|
|
67
|
+
const lossy = filtered && finalText !== raw;
|
|
68
|
+
const rawHandle = lossy && input.storeRawOutput ? input.storeRawOutput(raw) : handle;
|
|
69
|
+
if (filtered && contentKind !== 'validation' && raw.length > 2000 && isInflating(raw, finalText)) {
|
|
70
|
+
return passthroughReduction(raw, input);
|
|
71
|
+
}
|
|
72
|
+
if (lossy && rawHandle && !finalText.includes(rawHandle)) {
|
|
73
|
+
finalText = `${finalText}\n\n[${retrievalHint(rawHandle)}]`;
|
|
74
|
+
}
|
|
75
|
+
const metrics = reductionMetrics(raw, finalText);
|
|
76
|
+
return {
|
|
77
|
+
text: finalText,
|
|
78
|
+
truncated,
|
|
79
|
+
filtered,
|
|
80
|
+
...(reducerName ? { reducerName, filterName: reducerName } : {}),
|
|
81
|
+
contentKind,
|
|
82
|
+
lossy,
|
|
83
|
+
parseTier: warning ? 'degraded' : filtered ? 'full' : 'passthrough',
|
|
84
|
+
...(warning ? { warning } : {}),
|
|
85
|
+
...(handle ?? rawHandle ? { handle: handle ?? rawHandle } : {}),
|
|
86
|
+
...(rawHandle ? { rawHandle } : {}),
|
|
87
|
+
omittedChars: Math.max(0, raw.length - finalText.length),
|
|
88
|
+
...metrics,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Fallback reduction for passthrough output.
|
|
93
|
+
*/
|
|
94
|
+
export function passthroughReduction(raw, input) {
|
|
95
|
+
const compactFn = input.fallbackCompact ?? ((value, max) => compactOutput(value, max, input.storeRawOutput));
|
|
96
|
+
const compacted = compactFn(raw, input.compactMaxChars);
|
|
97
|
+
const metrics = reductionMetrics(raw, compacted.text);
|
|
98
|
+
return {
|
|
99
|
+
text: compacted.text,
|
|
100
|
+
truncated: compacted.truncated,
|
|
101
|
+
filtered: false,
|
|
102
|
+
reducerName: 'generic-cap',
|
|
103
|
+
contentKind: 'generic',
|
|
104
|
+
lossy: compacted.truncated,
|
|
105
|
+
parseTier: 'passthrough',
|
|
106
|
+
...(compacted.handle ? { handle: compacted.handle, rawHandle: compacted.handle } : {}),
|
|
107
|
+
omittedChars: compacted.omittedChars ?? Math.max(0, raw.length - compacted.text.length),
|
|
108
|
+
...metrics,
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ModelRuntimeConfig {
|
|
|
13
13
|
providerName: string;
|
|
14
14
|
providerKind?: HazeProviderSettings['kind'];
|
|
15
15
|
baseURL: string;
|
|
16
|
+
isLocal?: boolean;
|
|
16
17
|
modelName: string;
|
|
17
18
|
cacheKey: string;
|
|
18
19
|
capabilities: ProviderCapabilities;
|
|
@@ -24,8 +25,8 @@ export interface ModelRuntimeConfig {
|
|
|
24
25
|
* (128K hosted / 32K local) so `contextWindowSource` can flag the guess.
|
|
25
26
|
*/
|
|
26
27
|
contextWindowTokens: number;
|
|
27
|
-
/** Where
|
|
28
|
-
contextWindowSource: 'settings' | 'catalog' | 'user-fallback' | 'default-fallback' | 'deployment';
|
|
28
|
+
/** Where the context window came from. */
|
|
29
|
+
contextWindowSource: 'settings' | 'discovery' | 'preset' | 'catalog' | 'user-fallback' | 'default-fallback' | 'deployment';
|
|
29
30
|
deployment?: HazeBuildManifest;
|
|
30
31
|
warnings?: string[];
|
|
31
32
|
/** Optional output-token limit metadata for request budgeting (RH-005). */
|
|
@@ -33,6 +34,7 @@ export interface ModelRuntimeConfig {
|
|
|
33
34
|
}
|
|
34
35
|
/** True for loopback/local inference servers, whose effective window is server-configured (often far below the model's). */
|
|
35
36
|
export declare function isLocalProviderUrl(url: string): boolean;
|
|
37
|
+
export declare function isLocalProvider(provider: Pick<HazeProviderSettings, 'url' | 'location'>): boolean;
|
|
36
38
|
export declare function modelWithConfig(session?: {
|
|
37
39
|
cwd?: string;
|
|
38
40
|
modelSelector?: string;
|