@denizokcu/haze 1.1.0 → 1.2.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 +49 -1
- package/README.md +17 -10
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/busyIndicator.d.ts +11 -0
- package/dist/cli/chat/busyIndicator.js +34 -0
- package/dist/cli/chat/chatMetrics.d.ts +0 -1
- package/dist/cli/chat/chatMetrics.js +1 -7
- package/dist/cli/chat/followUpQueue.d.ts +11 -0
- package/dist/cli/chat/followUpQueue.js +38 -0
- package/dist/cli/chat/messages.d.ts +0 -22
- package/dist/cli/chat/messages.js +40 -85
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +8 -1
- package/dist/cli/chat/sessionRecorder.d.ts +9 -0
- package/dist/cli/chat/sessionRecorder.js +12 -0
- package/dist/cli/chat/startupSequence.d.ts +29 -0
- package/dist/cli/chat/startupSequence.js +59 -0
- package/dist/cli/chat/transcriptPartition.d.ts +23 -0
- package/dist/cli/chat/transcriptPartition.js +78 -0
- package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
- package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
- package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/lspHandlers.js +85 -0
- package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
- package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
- package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
- package/dist/cli/chat/wizard/providerHandlers.js +420 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
- package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
- package/dist/cli/chat/wizard/types.d.ts +63 -0
- package/dist/cli/chat/wizard/types.js +24 -0
- package/dist/cli/chat/wizard/uiState.d.ts +56 -0
- package/dist/cli/chat/wizard/uiState.js +15 -0
- package/dist/cli/chat/wizardDispatch.d.ts +11 -113
- package/dist/cli/chat/wizardDispatch.js +41 -815
- package/dist/cli/commands/chat.js +69 -110
- package/dist/cli/commands/formatters.d.ts +0 -3
- package/dist/cli/commands/formatters.js +0 -29
- package/dist/cli/commands/runCommand.d.ts +2 -0
- package/dist/cli/commands/runCommand.js +73 -4
- package/dist/cli/commands/streaming/agentAttempt.d.ts +11 -1
- package/dist/cli/commands/streaming/agentAttempt.js +9 -5
- package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
- package/dist/cli/commands/streaming/assistantSegments.js +48 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +25 -5
- package/dist/cli/commands/streaming/attemptOutcome.js +69 -16
- package/dist/cli/commands/streaming/attemptSetup.d.ts +10 -3
- package/dist/cli/commands/streaming/attemptSetup.js +30 -13
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
- package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +18 -3
- package/dist/cli/commands/streaming/goalSupervisor.js +71 -12
- package/dist/cli/commands/streaming/prepareStep.d.ts +40 -0
- package/dist/cli/commands/streaming/prepareStep.js +116 -0
- package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
- package/dist/cli/commands/streaming/recoverySlices.js +29 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
- package/dist/cli/commands/streaming/stallRecovery.js +2 -6
- package/dist/cli/commands/streaming/streamLoop.d.ts +31 -4
- package/dist/cli/commands/streaming/streamLoop.js +283 -268
- package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
- package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +108 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +1 -1
- package/dist/cli/commands/streaming/turnRuntime.js +3 -2
- package/dist/cli/commands/streaming.d.ts +12 -1
- package/dist/cli/commands/streaming.js +20 -25
- package/dist/cli/index.js +6 -3
- package/dist/config/modelCatalog.d.ts +32 -0
- package/dist/config/modelCatalog.js +84 -0
- package/dist/config/providerPresets.d.ts +7 -0
- package/dist/config/providerPresets.js +195 -391
- package/dist/config/settings.d.ts +10 -2
- package/dist/config/settings.js +3 -0
- package/dist/core/agent/budgets.d.ts +10 -0
- package/dist/core/agent/budgets.js +10 -0
- package/dist/core/agent/compaction.d.ts +42 -3
- package/dist/core/agent/compaction.js +53 -5
- package/dist/core/agent/completionController.d.ts +16 -7
- package/dist/core/agent/completionController.js +13 -6
- package/dist/core/agent/contextBudget.d.ts +56 -0
- package/dist/core/agent/contextBudget.js +53 -0
- package/dist/core/agent/errors.js +2 -2
- package/dist/core/agent/events.d.ts +36 -1
- package/dist/core/agent/goalPolicy.d.ts +4 -3
- package/dist/core/agent/goalPolicy.js +9 -4
- package/dist/core/agent/overflow.d.ts +45 -0
- package/dist/core/agent/overflow.js +91 -0
- package/dist/core/agent/requestAssembly.d.ts +7 -0
- package/dist/core/agent/requestAssembly.js +15 -7
- package/dist/core/agent/workState.d.ts +25 -15
- package/dist/core/agent/workState.js +84 -44
- package/dist/core/safety/shellClassifier.d.ts +16 -0
- package/dist/core/safety/shellClassifier.js +31 -0
- package/dist/core/session/sessionSlimming.js +8 -0
- package/dist/core/session/sessionStore.d.ts +71 -1
- package/dist/core/session/sessionStore.js +121 -6
- package/dist/core/validation/outputParser.d.ts +1 -1
- package/dist/core/validation/outputParser.js +6 -1
- package/dist/llm/client.d.ts +2 -2
- package/dist/llm/client.js +14 -6
- package/dist/llm/hazeTools.d.ts +64 -208
- package/dist/llm/tools/shellTool.js +27 -8
- package/dist/llm/tools/taskTool.d.ts +64 -208
- package/dist/llm/tools/taskTool.js +22 -10
- package/dist/ui/components/TextInput.d.ts +18 -1
- package/dist/ui/components/TextInput.js +50 -73
- package/dist/ui/components/useInputSuggestions.d.ts +27 -0
- package/dist/ui/components/useInputSuggestions.js +98 -0
- package/dist/ui/theme.d.ts +8 -8
- package/dist/ui/theme.js +11 -12
- package/dist/ui/themes/registry.d.ts +5 -0
- package/dist/ui/themes/registry.js +436 -0
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/format.js +45 -0
- package/package.json +16 -15
- package/dist/ui/themes/af-magic.d.ts +0 -7
- package/dist/ui/themes/af-magic.js +0 -25
- package/dist/ui/themes/agnoster.d.ts +0 -10
- package/dist/ui/themes/agnoster.js +0 -40
- package/dist/ui/themes/bira.d.ts +0 -10
- package/dist/ui/themes/bira.js +0 -28
- package/dist/ui/themes/bureau.d.ts +0 -10
- package/dist/ui/themes/bureau.js +0 -28
- package/dist/ui/themes/clean.d.ts +0 -9
- package/dist/ui/themes/clean.js +0 -27
- package/dist/ui/themes/cloud.d.ts +0 -6
- package/dist/ui/themes/cloud.js +0 -24
- package/dist/ui/themes/dst.d.ts +0 -10
- package/dist/ui/themes/dst.js +0 -28
- package/dist/ui/themes/fishy.d.ts +0 -7
- package/dist/ui/themes/fishy.js +0 -25
- package/dist/ui/themes/index.d.ts +0 -8
- package/dist/ui/themes/index.js +0 -36
- package/dist/ui/themes/light.d.ts +0 -3
- package/dist/ui/themes/light.js +0 -21
- package/dist/ui/themes/purple.d.ts +0 -7
- package/dist/ui/themes/purple.js +0 -26
- package/dist/ui/themes/robbyrussell.d.ts +0 -8
- package/dist/ui/themes/robbyrussell.js +0 -26
- package/dist/ui/themes/solarized-dark.d.ts +0 -16
- package/dist/ui/themes/solarized-dark.js +0 -44
- package/dist/ui/themes/solarized-light.d.ts +0 -12
- package/dist/ui/themes/solarized-light.js +0 -40
- package/dist/ui/themes/steeef.d.ts +0 -11
- package/dist/ui/themes/steeef.js +0 -29
|
@@ -6,6 +6,15 @@ import { prepareSessionEntryForWrite } from './sessionSlimming.js';
|
|
|
6
6
|
import { appendPrivateFile, ensurePrivateDir, tightenPrivateFile, writePrivateFileAtomic } from '../../config/privateStorage.js';
|
|
7
7
|
import { JSONL_LINE_BYTES } from '../limits.js';
|
|
8
8
|
import { iterateBoundedUtf8Lines } from '../io/boundedRead.js';
|
|
9
|
+
function parseLedgerRedEvidence(value) {
|
|
10
|
+
if (typeof value !== 'object' || value == null)
|
|
11
|
+
return undefined;
|
|
12
|
+
const record = value;
|
|
13
|
+
if (typeof record.command !== 'string' || typeof record.commandKey !== 'string')
|
|
14
|
+
return undefined;
|
|
15
|
+
const summary = typeof record.summary === 'string' ? record.summary : '';
|
|
16
|
+
return { command: record.command.slice(0, 400), commandKey: record.commandKey.slice(0, 400), summary: summary.slice(0, 200) };
|
|
17
|
+
}
|
|
9
18
|
const DEFAULT_SESSIONS_DIR = path.join(HAZE_DIR, 'sessions');
|
|
10
19
|
function cwdHash(cwd = process.cwd()) {
|
|
11
20
|
return crypto.createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 16);
|
|
@@ -110,6 +119,10 @@ let effectiveVacuumThresholdBytes = SESSION_VACUUM_THRESHOLD_BYTES;
|
|
|
110
119
|
export function setSessionVacuumThresholdForTests(bytes) {
|
|
111
120
|
effectiveVacuumThresholdBytes = bytes;
|
|
112
121
|
}
|
|
122
|
+
/** Trailing goal-ledger entries preserved per goal id when the vacuum rewrites (frontier + end + one audit entry). */
|
|
123
|
+
export const GOAL_LEDGER_KEEP_PER_GOAL = 3;
|
|
124
|
+
/** Ledger trim must amortize its rewrite: rewrite for goal entries alone only past this many dropped bytes. */
|
|
125
|
+
export const GOAL_LEDGER_TRIM_BYTES = 2_048;
|
|
113
126
|
export async function vacuumSessionFileIfLarge(session, thresholdBytes = effectiveVacuumThresholdBytes) {
|
|
114
127
|
const file = validatedSessionFile(session);
|
|
115
128
|
if (session.deferredWrite)
|
|
@@ -126,16 +139,36 @@ export async function vacuumSessionFileIfLarge(session, thresholdBytes = effecti
|
|
|
126
139
|
if (entry.type === 'work_state_snapshot')
|
|
127
140
|
lastWorkState = index;
|
|
128
141
|
});
|
|
142
|
+
// Goal-ledger bound (P1): long autonomous goals append one entry per physical
|
|
143
|
+
// turn; intermediate `goal_continue` entries of superseded cycles are audit
|
|
144
|
+
// trail only. Keep the trailing few per goal id — the frontier and the
|
|
145
|
+
// terminal entry are always among them — so a very long-lived session file
|
|
146
|
+
// stays bounded without ever losing a live frontier.
|
|
147
|
+
const keepGoal = new Set();
|
|
148
|
+
const goalIndexesByGoal = new Map();
|
|
149
|
+
entries.forEach((entry, index) => {
|
|
150
|
+
if (entry.type === 'goal')
|
|
151
|
+
goalIndexesByGoal.set(entry.goalId, [...(goalIndexesByGoal.get(entry.goalId) ?? []), index]);
|
|
152
|
+
});
|
|
153
|
+
for (const indexes of goalIndexesByGoal.values()) {
|
|
154
|
+
for (const index of indexes.slice(-GOAL_LEDGER_KEEP_PER_GOAL))
|
|
155
|
+
keepGoal.add(index);
|
|
156
|
+
}
|
|
129
157
|
// Malformed lines are dropped by the rewrite: they were already unusable
|
|
130
158
|
// (and reported as parse errors on read) and keeping them would defeat the
|
|
131
159
|
// size bound the vacuum exists to enforce.
|
|
132
|
-
const
|
|
160
|
+
const candidate = entries.filter((entry, index) => (entry.type !== 'conversation_snapshot' && entry.type !== 'work_state_snapshot')
|
|
133
161
|
|| index === lastConversation
|
|
134
162
|
|| index === lastWorkState);
|
|
163
|
+
const kept = candidate.filter((entry, index) => entry.type !== 'goal' || keepGoal.has(index));
|
|
164
|
+
const droppedGoalBytes = candidate
|
|
165
|
+
.filter((entry, index) => entry.type === 'goal' && !keepGoal.has(index))
|
|
166
|
+
.reduce((sum, entry) => sum + Buffer.byteLength(JSON.stringify(entry), 'utf8'), 0);
|
|
135
167
|
const serialized = kept.map(entry => JSON.stringify(entry)).join('\n') + '\n';
|
|
136
|
-
// Only rewrite when it meaningfully shrinks the file
|
|
137
|
-
// dominant snapshot would trigger a full rewrite on every append
|
|
138
|
-
|
|
168
|
+
// Only rewrite when it meaningfully shrinks the file (otherwise a single
|
|
169
|
+
// dominant snapshot would trigger a full rewrite on every append), or when
|
|
170
|
+
// the goal-ledger trim alone has accumulated enough to amortize the rewrite.
|
|
171
|
+
if (serialized.length > stat.size / 2 && droppedGoalBytes < GOAL_LEDGER_TRIM_BYTES)
|
|
139
172
|
return false;
|
|
140
173
|
await writePrivateFileAtomic(file, serialized);
|
|
141
174
|
return true;
|
|
@@ -155,6 +188,31 @@ function optionalBuildProvenance(value) {
|
|
|
155
188
|
return false;
|
|
156
189
|
return optionalString(value.commit) && optionalString(value.builtAt);
|
|
157
190
|
}
|
|
191
|
+
function optionalTaskCounts(value) {
|
|
192
|
+
if (value === undefined)
|
|
193
|
+
return true;
|
|
194
|
+
if (!isRecord(value))
|
|
195
|
+
return false;
|
|
196
|
+
return ['total', 'pending', 'inProgress', 'completed'].every(key => typeof value[key] === 'number');
|
|
197
|
+
}
|
|
198
|
+
function optionalLedgerRedEvidence(value) {
|
|
199
|
+
return value === undefined || parseLedgerRedEvidence(value) !== undefined;
|
|
200
|
+
}
|
|
201
|
+
function frontierFromGoalEntry(entry) {
|
|
202
|
+
return {
|
|
203
|
+
goalId: entry.goalId,
|
|
204
|
+
request: entry.request,
|
|
205
|
+
requestHash: entry.requestHash,
|
|
206
|
+
intent: entry.intent,
|
|
207
|
+
cycle: entry.cycle,
|
|
208
|
+
mutationCount: entry.mutationCount,
|
|
209
|
+
validationOutcome: entry.validationOutcome,
|
|
210
|
+
progressSignature: entry.progressSignature,
|
|
211
|
+
...(entry.taskCounts ? { taskCounts: entry.taskCounts } : {}),
|
|
212
|
+
...(entry.redEvidence ? { redEvidence: entry.redEvidence } : {}),
|
|
213
|
+
at: entry.at,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
158
216
|
function parseSessionEntry(value) {
|
|
159
217
|
const invalid = (detail) => {
|
|
160
218
|
throw new Error(`unexpected entry shape: ${detail}`);
|
|
@@ -192,6 +250,23 @@ function parseSessionEntry(value) {
|
|
|
192
250
|
if (typeof value.at !== 'string' || typeof value.name !== 'string' || !optionalString(value.text))
|
|
193
251
|
return invalid('invalid event');
|
|
194
252
|
return value;
|
|
253
|
+
case 'compact':
|
|
254
|
+
if (typeof value.at !== 'string' || (value.method !== 'heuristic' && value.method !== 'llm')
|
|
255
|
+
|| typeof value.olderCount !== 'number' || typeof value.keptCount !== 'number'
|
|
256
|
+
|| typeof value.summary !== 'string' || !optionalString(value.instructions))
|
|
257
|
+
return invalid('invalid compact');
|
|
258
|
+
return value;
|
|
259
|
+
case 'goal':
|
|
260
|
+
if (typeof value.at !== 'string' || typeof value.goalId !== 'string'
|
|
261
|
+
|| (value.phase !== 'goal_start' && value.phase !== 'goal_continue' && value.phase !== 'goal_end')
|
|
262
|
+
|| typeof value.request !== 'string' || typeof value.requestHash !== 'string' || typeof value.intent !== 'string'
|
|
263
|
+
|| typeof value.cycle !== 'number' || typeof value.mutationCount !== 'number'
|
|
264
|
+
|| typeof value.validationOutcome !== 'string' || typeof value.progressSignature !== 'string'
|
|
265
|
+
|| !optionalTaskCounts(value.taskCounts)
|
|
266
|
+
|| !optionalString(value.stopReason) || !optionalString(value.status)
|
|
267
|
+
|| !optionalLedgerRedEvidence(value.redEvidence))
|
|
268
|
+
return invalid('invalid goal');
|
|
269
|
+
return value;
|
|
195
270
|
default:
|
|
196
271
|
return invalid(`unknown entry type '${type}'`);
|
|
197
272
|
}
|
|
@@ -239,21 +314,61 @@ export async function readSessionEntries(session) {
|
|
|
239
314
|
const parseErrors = await scanSessionEntries(session, entry => entries.push(entry));
|
|
240
315
|
return { entries, parseErrors };
|
|
241
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Pure frontier detection over parsed session entries (P1): the append-only
|
|
319
|
+
* goal ledger's frontier is the last entry of the most recent goal id that has
|
|
320
|
+
* no `goal_end` entry. A truncated or malformed tail line parses as absent, so
|
|
321
|
+
* a crash mid-write can never resurrect a half-written boundary
|
|
322
|
+
* (autoprompt's "treat half-written artifacts as absent").
|
|
323
|
+
*/
|
|
324
|
+
export function findGoalLedgerFrontier(entries) {
|
|
325
|
+
let frontier;
|
|
326
|
+
for (const entry of entries) {
|
|
327
|
+
if (entry.type !== 'goal')
|
|
328
|
+
continue;
|
|
329
|
+
if (entry.phase === 'goal_end') {
|
|
330
|
+
if (frontier?.goalId === entry.goalId)
|
|
331
|
+
frontier = undefined;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
frontier = frontierFromGoalEntry(entry);
|
|
335
|
+
}
|
|
336
|
+
return frontier;
|
|
337
|
+
}
|
|
338
|
+
/** Read the goal-ledger frontier of a stored session (one file scan). */
|
|
339
|
+
export async function readGoalLedgerFrontier(session) {
|
|
340
|
+
const { entries } = await readSessionEntries(session);
|
|
341
|
+
return findGoalLedgerFrontier(entries);
|
|
342
|
+
}
|
|
242
343
|
/**
|
|
243
344
|
* Restore conversation and work state in one file scan (CR-013). Session
|
|
244
345
|
* files grow to megabytes in long workspaces; resuming should not parse the
|
|
245
|
-
* JSONL twice.
|
|
346
|
+
* JSONL twice. The goal-ledger frontier rides the same scan (P1).
|
|
246
347
|
*/
|
|
247
348
|
export async function restoreSessionState(session) {
|
|
248
349
|
let messages = [];
|
|
249
350
|
let workState;
|
|
351
|
+
let goalFrontier;
|
|
352
|
+
const terminatedGoals = new Set();
|
|
250
353
|
const parseErrors = await scanSessionEntries(session, entry => {
|
|
251
354
|
if (entry.type === 'conversation_snapshot')
|
|
252
355
|
messages = entry.messages;
|
|
253
356
|
if (entry.type === 'work_state_snapshot')
|
|
254
357
|
workState = entry.state;
|
|
358
|
+
if (entry.type === 'goal') {
|
|
359
|
+
if (entry.phase === 'goal_end') {
|
|
360
|
+
terminatedGoals.add(entry.goalId);
|
|
361
|
+
if (goalFrontier?.goalId === entry.goalId)
|
|
362
|
+
goalFrontier = undefined;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
goalFrontier = frontierFromGoalEntry(entry);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
255
368
|
});
|
|
256
|
-
|
|
369
|
+
if (goalFrontier && terminatedGoals.has(goalFrontier.goalId))
|
|
370
|
+
goalFrontier = undefined;
|
|
371
|
+
return { messages, workState, parseErrors, goalFrontier };
|
|
257
372
|
}
|
|
258
373
|
export async function restoreConversation(session) {
|
|
259
374
|
const { messages, parseErrors } = await restoreSessionState(session);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ShellClassification } from '../safety/shellClassifier.js';
|
|
2
2
|
import type { ValidationSummary } from '../../llm/toolResultTypes.js';
|
|
3
3
|
export declare function parseValidationOutput(input: {
|
|
4
4
|
command: string;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { stripQuotedSpans } from '../safety/shellClassifier.js';
|
|
1
2
|
import { capOutputForProcessing } from '../toolOutput/reduction.js';
|
|
2
3
|
function uniq(values) {
|
|
3
4
|
return [...new Set(values.filter(Boolean))];
|
|
4
5
|
}
|
|
5
6
|
function inferKind(command, classification) {
|
|
6
|
-
|
|
7
|
+
// Shape-only inference on the unquoted command: kind authority must come
|
|
8
|
+
// from running a recognized tool, never from words the model authored
|
|
9
|
+
// inside a quoted payload (found by the honest-impossibility eval — a
|
|
10
|
+
// self-written `node -e` script mentioning "test" claimed kind 'test').
|
|
11
|
+
const lower = stripQuotedSpans(command).toLowerCase();
|
|
7
12
|
if (/typecheck|\btsc\b/.test(lower))
|
|
8
13
|
return 'typecheck';
|
|
9
14
|
if (/\beslint\b|\blint\b/.test(lower))
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ export interface ModelRuntimeConfig {
|
|
|
22
22
|
* (128K hosted / 32K local) so `contextWindowSource` can flag the guess.
|
|
23
23
|
*/
|
|
24
24
|
contextWindowTokens: number;
|
|
25
|
-
/** Where contextWindowTokens came from: per-model settings, a user-set fallback, or the built-in default. */
|
|
26
|
-
contextWindowSource: 'settings' | 'user-fallback' | 'default-fallback';
|
|
25
|
+
/** Where contextWindowTokens came from: per-model settings, the curated model catalog, a user-set fallback, or the built-in default. */
|
|
26
|
+
contextWindowSource: 'settings' | 'catalog' | 'user-fallback' | 'default-fallback';
|
|
27
27
|
/** Optional output-token limit metadata for request budgeting (RH-005). */
|
|
28
28
|
maxOutputTokens?: number;
|
|
29
29
|
}
|
package/dist/llm/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
3
|
import { readSettings } from '../config/settings.js';
|
|
4
|
+
import { catalogLimitsFor } from '../config/modelCatalog.js';
|
|
4
5
|
import { activeModel, modelSelector, resolveModelSelector } from '../config/providers.js';
|
|
5
6
|
import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js';
|
|
6
7
|
import { resolveReasoningPolicy } from '../core/agent/reasoningPolicy.js';
|
|
@@ -64,15 +65,22 @@ function runtimeForSelection(settings, selection, cwd) {
|
|
|
64
65
|
const limits = modelLimitsFor(selection.provider, name);
|
|
65
66
|
// Class-aware fallback so unknown local models (server-configured window,
|
|
66
67
|
// silent truncation) stay conservative while unknown hosted models get the
|
|
67
|
-
// modern 128K floor.
|
|
68
|
-
//
|
|
69
|
-
//
|
|
68
|
+
// modern 128K floor. The curated catalog (Pillar 1.8) fills known families
|
|
69
|
+
// before any fallback; local servers never consult it because their
|
|
70
|
+
// effective window is server-configured. A user-set fallback setting
|
|
71
|
+
// overrides the built-in default; the source tag distinguishes an
|
|
72
|
+
// intentional guess (no warning) from the default guess (warned once per
|
|
73
|
+
// session) (RH-005).
|
|
70
74
|
const isLocal = isLocalProviderUrl(baseURL);
|
|
75
|
+
const catalog = isLocal ? undefined : catalogLimitsFor(name);
|
|
71
76
|
const userFallback = isLocal ? settings.localContextWindowFallbackTokens : settings.contextWindowFallbackTokens;
|
|
72
77
|
const fallbackTokens = userFallback ?? (isLocal ? FALLBACK_LOCAL_CONTEXT_TOKENS : FALLBACK_CONTEXT_WINDOW_TOKENS);
|
|
73
78
|
const contextWindowSource = limits.contextWindowTokens !== undefined
|
|
74
79
|
? 'settings'
|
|
75
|
-
:
|
|
80
|
+
: catalog
|
|
81
|
+
? 'catalog'
|
|
82
|
+
: userFallback !== undefined ? 'user-fallback' : 'default-fallback';
|
|
83
|
+
const maxOutputTokens = limits.maxOutputTokens ?? catalog?.maxOutputTokens;
|
|
76
84
|
return {
|
|
77
85
|
model: providerKind === 'chatgpt-codex' ? openai.responses(name) : openai.chat(name),
|
|
78
86
|
selector: modelSelector(selection.provider, name),
|
|
@@ -84,9 +92,9 @@ function runtimeForSelection(settings, selection, cwd) {
|
|
|
84
92
|
cacheKey,
|
|
85
93
|
capabilities: caps,
|
|
86
94
|
reasoningPolicy,
|
|
87
|
-
contextWindowTokens: limits.contextWindowTokens ?? fallbackTokens,
|
|
95
|
+
contextWindowTokens: limits.contextWindowTokens ?? catalog?.contextWindowTokens ?? fallbackTokens,
|
|
88
96
|
contextWindowSource,
|
|
89
|
-
...(
|
|
97
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
90
98
|
},
|
|
91
99
|
};
|
|
92
100
|
}
|