@denizokcu/haze 0.10.0 → 1.0.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 +100 -1
- package/README.md +77 -27
- 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 +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- 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 -4
- package/dist/cli/chat/messages.js +218 -35
- package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
- package/dist/cli/chat/sessionLifecycle.js +64 -14
- package/dist/cli/chat/sessionRecorder.js +75 -7
- package/dist/cli/chat/startupInfo.d.ts +0 -1
- package/dist/cli/chat/startupInfo.js +11 -15
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +349 -133
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +216 -172
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commands.d.ts +2 -0
- package/dist/cli/commands/commands.js +10 -5
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +8 -25
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +9 -2
- package/dist/cli/commands/providerWizard.js +39 -7
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/skillsWizard.d.ts +41 -0
- package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
- package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
- package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
- package/dist/cli/commands/streaming/attemptSetup.js +167 -0
- 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 +130 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
- package/dist/cli/commands/streaming/stallRecovery.js +105 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
- package/dist/cli/commands/streaming/streamLoop.js +448 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -0
- package/dist/cli/commands/streaming.d.ts +65 -9
- package/dist/cli/commands/streaming.js +133 -430
- package/dist/cli/commands/wizardFlow.d.ts +334 -0
- package/dist/cli/commands/wizardFlow.js +377 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/contextFiles.js +9 -3
- package/dist/config/inputHistory.d.ts +0 -1
- package/dist/config/inputHistory.js +1 -1
- package/dist/config/modelDiscovery.d.ts +36 -0
- package/dist/config/modelDiscovery.js +164 -1
- 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 +39 -7
- package/dist/config/providerPresets.js +371 -100
- package/dist/config/providers.js +2 -0
- package/dist/config/settings.d.ts +43 -0
- package/dist/config/settings.js +12 -0
- package/dist/config/skillSettings.js +4 -4
- package/dist/config/updateCheck.d.ts +0 -1
- package/dist/config/updateCheck.js +1 -1
- package/dist/core/agent/budgets.d.ts +73 -1
- package/dist/core/agent/budgets.js +94 -1
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +224 -0
- package/dist/core/agent/completionController.js +296 -0
- package/dist/core/agent/contextBudget.d.ts +36 -2
- package/dist/core/agent/contextBudget.js +62 -9
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +78 -0
- package/dist/core/agent/goalPolicy.d.ts +47 -0
- package/dist/core/agent/goalPolicy.js +106 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/requestAssembly.d.ts +2 -2
- package/dist/core/agent/requestAssembly.js +16 -4
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +11 -11
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -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 +81 -3
- package/dist/core/agent/workState.js +176 -10
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +27 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/io/boundedRead.js +1 -1
- package/dist/core/limits.d.ts +51 -0
- package/dist/core/limits.js +51 -0
- package/dist/core/log/llmLog.js +8 -1
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +15 -10
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/shellClassifier.d.ts +11 -0
- package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
- package/dist/core/safety/urlGuard.d.ts +1 -1
- package/dist/core/session/sessionSlimming.d.ts +0 -3
- package/dist/core/session/sessionSlimming.js +2 -3
- package/dist/core/session/sessionStore.d.ts +38 -0
- package/dist/core/session/sessionStore.js +242 -59
- package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
- package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
- package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
- package/dist/core/shellOutput/registry.d.ts +2 -0
- package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
- package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
- package/dist/core/subagent/contracts.d.ts +6 -14
- package/dist/core/subagent/contracts.js +4 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +19 -40
- package/dist/core/toolOutput/reduction.d.ts +0 -12
- package/dist/core/toolOutput/reduction.js +1 -1
- package/dist/core/validation/outputParser.d.ts +2 -2
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +86 -14
- package/dist/llm/hazeTools.d.ts +693 -204
- package/dist/llm/hazeTools.js +110 -28
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp/client.d.ts +45 -0
- package/dist/llm/lsp/client.js +195 -0
- package/dist/llm/lsp/pool.d.ts +23 -0
- package/dist/llm/lsp/pool.js +86 -0
- package/dist/llm/lsp/protocol.d.ts +64 -0
- package/dist/llm/lsp/protocol.js +128 -0
- package/dist/llm/lsp/requests.d.ts +94 -0
- package/dist/llm/lsp/requests.js +119 -0
- package/dist/llm/lspTools.d.ts +5653 -33
- package/dist/llm/lspTools.js +152 -80
- package/dist/llm/openaiCodex.d.ts +1 -0
- package/dist/llm/openaiCodex.js +43 -0
- package/dist/llm/openaiCodexOAuth.d.ts +51 -0
- package/dist/llm/openaiCodexOAuth.js +217 -0
- package/dist/llm/requestContext.d.ts +7 -0
- package/dist/llm/requestContext.js +30 -4
- package/dist/llm/systemPrompt.d.ts +12 -0
- package/dist/llm/systemPrompt.js +24 -11
- package/dist/llm/toolResultTypes.d.ts +7 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +14 -9
- package/dist/llm/tools/editMatch.js +73 -1
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +8 -5
- package/dist/llm/tools/fileToolShared.js +22 -23
- package/dist/llm/tools/gitIgnore.d.ts +42 -0
- package/dist/llm/tools/gitIgnore.js +247 -0
- package/dist/llm/tools/grepParse.d.ts +2 -1
- package/dist/llm/tools/grepRunner.d.ts +1 -1
- package/dist/llm/tools/grepRunner.js +2 -2
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -3
- package/dist/llm/tools/processTool.d.ts +16 -16
- package/dist/llm/tools/processTool.js +1 -1
- package/dist/llm/tools/readRecovery.d.ts +8 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
- package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +66 -37
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +18 -1
- package/dist/llm/webFetch.js +64 -97
- package/dist/skills/SkillLoader.d.ts +1 -11
- package/dist/skills/SkillLoader.js +1 -2
- package/dist/skills/types.d.ts +2 -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 +8 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +97 -0
- package/dist/utils/buildInfo.js +244 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.js +91 -26
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +6 -2
- 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 +28 -21
- package/dist/cli/commands/lspWizard.d.ts +0 -14
- package/dist/cli/commands/lspWizard.js +0 -44
- package/dist/cli/commands/mcpWizard.d.ts +0 -15
- package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
- package/dist/cli/commands/skillConfirmRemove.js +0 -20
- package/dist/cli/commands/skillCreation.d.ts +0 -12
- package/dist/cli/commands/skillCreation.js +0 -14
- package/dist/cli/commands/skillWizard.d.ts +0 -17
- package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
- package/dist/cli/commands/streaming/idleTimer.js +0 -24
- package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
- package/dist/cli/commands/streaming/turnOutcome.js +0 -13
- package/dist/cli/commands/wizardActions.d.ts +0 -46
- package/dist/cli/commands/wizardActions.js +0 -46
- package/dist/cli/commands/wizardInput.d.ts +0 -4
- package/dist/cli/commands/wizardInput.js +0 -19
- package/dist/cli/commands/wizardPrompts.d.ts +0 -22
- package/dist/cli/commands/wizardPrompts.js +0 -52
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -188
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/bashOutput/ansi.d.ts +0 -1
- package/dist/core/bashOutput/ansi.js +0 -7
- package/dist/core/bashOutput/registry.d.ts +0 -4
- package/dist/core/goal/completionPolicy.d.ts +0 -2
- package/dist/core/goal/completionPolicy.js +0 -7
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -18
- package/dist/core/goal/sessionGoal.d.ts +0 -8
- package/dist/core/goal/sessionGoal.js +0 -30
- package/dist/core/limits/byteBudgets.d.ts +0 -18
- package/dist/core/limits/byteBudgets.js +0 -18
- package/dist/core/limits/textBudgets.d.ts +0 -23
- package/dist/core/limits/textBudgets.js +0 -23
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -129
- package/dist/llm/lsp.js +0 -307
- package/dist/ui/components/ErrorView.d.ts +0 -4
- package/dist/ui/components/ErrorView.js +0 -7
- package/dist/utils/yaml.d.ts +0 -2
- package/dist/utils/yaml.js +0 -8
- package/examples/skills/files/SKILL.md +0 -16
- package/examples/skills/files/examples/file-editing.md +0 -3
- /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
import type { JSONValue, LanguageModel } from 'ai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
3
|
+
declare const workerModes: readonly ["inspect", "research", "implement", "validate"];
|
|
4
4
|
export type WorkerMode = typeof workerModes[number];
|
|
5
|
-
export declare const subagentTaskInputV2Schema: z.ZodObject<{
|
|
6
|
-
objective: z.ZodString;
|
|
7
|
-
deliverable: z.ZodString;
|
|
8
|
-
mode: z.ZodEnum<{
|
|
9
|
-
inspect: "inspect";
|
|
10
|
-
research: "research";
|
|
11
|
-
implement: "implement";
|
|
12
|
-
validate: "validate";
|
|
13
|
-
}>;
|
|
14
|
-
scope: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
15
|
-
acceptanceCriteria: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
16
|
-
}, z.core.$strip>;
|
|
17
5
|
export declare const subagentInputSchema: z.ZodObject<{
|
|
18
6
|
objective: z.ZodString;
|
|
19
7
|
deliverable: z.ZodString;
|
|
@@ -95,10 +83,14 @@ export interface ProviderCapabilities {
|
|
|
95
83
|
supportsStickySessionId: boolean;
|
|
96
84
|
supportsServerCompaction: boolean;
|
|
97
85
|
supportsTextVerbosity: boolean;
|
|
86
|
+
/** Protocol accepts an OpenAI-style reasoning-effort provider option. */
|
|
87
|
+
supportsReasoningEffort: boolean;
|
|
98
88
|
}
|
|
99
89
|
export interface ProviderRequestOptions {
|
|
100
90
|
providerOptions?: Record<string, Record<string, JSONValue | undefined>>;
|
|
101
91
|
headers?: Record<string, string>;
|
|
92
|
+
/** Codex subscription requests let the provider manage the output limit. */
|
|
93
|
+
omitMaxOutputTokens?: boolean;
|
|
102
94
|
}
|
|
103
95
|
export interface WorkerRuntime {
|
|
104
96
|
model: LanguageModel;
|
|
@@ -112,5 +104,5 @@ export declare function fallbackProviderCapabilities(): ProviderCapabilities;
|
|
|
112
104
|
/** Single source for the placeholder runtime used when only a bare model is available (CR-018). */
|
|
113
105
|
export declare function fallbackWorkerRuntime(model: WorkerRuntime['model'], selector?: string, providerName?: string): WorkerRuntime;
|
|
114
106
|
export declare function normalizeSubagentInput(input: SubagentToolInput, id: string): SubagentTaskCapsule;
|
|
115
|
-
export declare function legacyStatus(termination: WorkerTermination): SubagentExecutionResult['status'];
|
|
116
107
|
export declare function withLegacyProjection(capsule: SubagentResultCapsule, telemetry: SubagentTelemetry, error?: string): SubagentExecutionResult;
|
|
108
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { SUBAGENT_ACCEPTANCE_CHARS, SUBAGENT_ACCEPTANCE_ITEMS, SUBAGENT_DELIVERABLE_CHARS, SUBAGENT_OBJECTIVE_CHARS, SUBAGENT_SCOPE_CHARS, SUBAGENT_SCOPE_ITEMS, } from '../agent/budgets.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const workerModes = ['inspect', 'research', 'implement', 'validate'];
|
|
4
|
+
const subagentTaskInputV2Schema = z.object({
|
|
5
5
|
objective: z.string().trim().min(1).max(SUBAGENT_OBJECTIVE_CHARS).describe('Self-contained outcome for the worker. Keep it under 1000 characters; do not paste conversation history or file contents.'),
|
|
6
6
|
deliverable: z.string().trim().min(1).max(SUBAGENT_DELIVERABLE_CHARS).describe('Exact compact result the worker must return to the main agent.'),
|
|
7
7
|
mode: z.enum(workerModes).describe('inspect/research are read-only; implement may edit; validate may run commands.'),
|
|
@@ -21,6 +21,7 @@ export function fallbackProviderCapabilities() {
|
|
|
21
21
|
supportsStickySessionId: false,
|
|
22
22
|
supportsServerCompaction: false,
|
|
23
23
|
supportsTextVerbosity: false,
|
|
24
|
+
supportsReasoningEffort: false,
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
/** Single source for the placeholder runtime used when only a bare model is available (CR-018). */
|
|
@@ -30,7 +31,7 @@ export function fallbackWorkerRuntime(model, selector = 'active-model', provider
|
|
|
30
31
|
export function normalizeSubagentInput(input, id) {
|
|
31
32
|
return { id, objective: input.objective, deliverable: input.deliverable, mode: input.mode, scope: input.scope ?? [], acceptanceCriteria: input.acceptanceCriteria ?? [] };
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
function legacyStatus(termination) {
|
|
34
35
|
if (termination === 'completed' || termination === 'no_output')
|
|
35
36
|
return 'ok';
|
|
36
37
|
if (termination === 'cancelled')
|
|
@@ -25,8 +25,8 @@ export const BUILT_IN_SUBAGENT_PROFILES = {
|
|
|
25
25
|
export const MODE_TOOL_NAMES = {
|
|
26
26
|
inspect: ['listFiles', 'readFile', 'grep', 'readToolOutput'],
|
|
27
27
|
research: ['listFiles', 'readFile', 'grep', 'readToolOutput', 'fetch'],
|
|
28
|
-
implement: ['listFiles', 'readFile', 'grep', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile', '
|
|
29
|
-
validate: ['listFiles', 'readFile', 'grep', 'readToolOutput', '
|
|
28
|
+
implement: ['listFiles', 'readFile', 'grep', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile', 'shell'],
|
|
29
|
+
validate: ['listFiles', 'readFile', 'grep', 'readToolOutput', 'shell'],
|
|
30
30
|
};
|
|
31
31
|
export function isMutationMode(mode) {
|
|
32
32
|
return mode === 'implement' || mode === 'validate';
|
|
@@ -59,11 +59,15 @@ export declare class SubagentCoordinator {
|
|
|
59
59
|
private readonly queue;
|
|
60
60
|
private running;
|
|
61
61
|
private mutationRunning;
|
|
62
|
+
/** Read-only workers admitted behind a blocked mutation head (RH-010). */
|
|
63
|
+
private bypassRunning;
|
|
62
64
|
private nextId;
|
|
63
65
|
private nextSequence;
|
|
64
66
|
private submissionBatch;
|
|
65
67
|
private admissionScheduled;
|
|
66
68
|
peakConcurrency: number;
|
|
69
|
+
/** Peak read-only workers running concurrently behind a blocked mutation. */
|
|
70
|
+
peakBypass: number;
|
|
67
71
|
constructor(profile: SubagentExecutionProfile, onEvent?: ((event: CoordinatorEvent) => void) | undefined);
|
|
68
72
|
createId(): string;
|
|
69
73
|
submit<T>(input: Omit<Submission<T>, 'resolve' | 'submittedAt' | 'sequence' | 'batch' | 'abortListener'>): Promise<T>;
|
|
@@ -10,11 +10,15 @@ export class SubagentCoordinator {
|
|
|
10
10
|
queue = [];
|
|
11
11
|
running = 0;
|
|
12
12
|
mutationRunning = false;
|
|
13
|
+
/** Read-only workers admitted behind a blocked mutation head (RH-010). */
|
|
14
|
+
bypassRunning = 0;
|
|
13
15
|
nextId = 1;
|
|
14
16
|
nextSequence = 1;
|
|
15
17
|
submissionBatch = 1;
|
|
16
18
|
admissionScheduled = false;
|
|
17
19
|
peakConcurrency = 0;
|
|
20
|
+
/** Peak read-only workers running concurrently behind a blocked mutation. */
|
|
21
|
+
peakBypass = 0;
|
|
18
22
|
constructor(profile, onEvent) {
|
|
19
23
|
this.profile = profile;
|
|
20
24
|
this.onEvent = onEvent;
|
|
@@ -69,6 +73,9 @@ export class SubagentCoordinator {
|
|
|
69
73
|
});
|
|
70
74
|
}
|
|
71
75
|
admit() {
|
|
76
|
+
// FIFO admission from the queue head. A mutation at the head blocks behind
|
|
77
|
+
// another running mutation; everything else is admitted in order while
|
|
78
|
+
// slots remain free.
|
|
72
79
|
while (this.running < this.profile.maxConcurrency) {
|
|
73
80
|
const item = this.queue[0];
|
|
74
81
|
if (!item || (isMutationMode(item.mode) && this.mutationRunning))
|
|
@@ -76,12 +83,33 @@ export class SubagentCoordinator {
|
|
|
76
83
|
this.queue.shift();
|
|
77
84
|
if (item.signal && item.abortListener)
|
|
78
85
|
item.signal.removeEventListener('abort', item.abortListener);
|
|
79
|
-
this.start(item);
|
|
86
|
+
this.start(item, false);
|
|
87
|
+
}
|
|
88
|
+
// Bounded read-only bypass: while a mutation is blocked at the head, let
|
|
89
|
+
// read-only work waiting behind it consume otherwise-idle slots. The cap is
|
|
90
|
+
// maxConcurrency - 1 so a serialized mutation always retains a free slot
|
|
91
|
+
// the moment the running mutation settles, preventing starvation (RH-010).
|
|
92
|
+
const bypassCap = Math.max(0, this.profile.maxConcurrency - 1);
|
|
93
|
+
while (this.running < this.profile.maxConcurrency && this.bypassRunning < bypassCap) {
|
|
94
|
+
const head = this.queue[0];
|
|
95
|
+
if (!head || !(isMutationMode(head.mode) && this.mutationRunning))
|
|
96
|
+
break;
|
|
97
|
+
const index = this.queue.findIndex(item => !isMutationMode(item.mode));
|
|
98
|
+
if (index === -1)
|
|
99
|
+
break;
|
|
100
|
+
const [item] = this.queue.splice(index, 1);
|
|
101
|
+
if (item.signal && item.abortListener)
|
|
102
|
+
item.signal.removeEventListener('abort', item.abortListener);
|
|
103
|
+
this.start(item, true);
|
|
80
104
|
}
|
|
81
105
|
}
|
|
82
|
-
start(item) {
|
|
106
|
+
start(item, bypass) {
|
|
83
107
|
const mutation = isMutationMode(item.mode);
|
|
84
108
|
this.running++;
|
|
109
|
+
if (bypass) {
|
|
110
|
+
this.bypassRunning++;
|
|
111
|
+
this.peakBypass = Math.max(this.peakBypass, this.bypassRunning);
|
|
112
|
+
}
|
|
85
113
|
if (mutation)
|
|
86
114
|
this.mutationRunning = true;
|
|
87
115
|
this.peakConcurrency = Math.max(this.peakConcurrency, this.running);
|
|
@@ -123,6 +151,8 @@ export class SubagentCoordinator {
|
|
|
123
151
|
clearTimeout(timer);
|
|
124
152
|
item.signal?.removeEventListener('abort', parentAbort);
|
|
125
153
|
this.running--;
|
|
154
|
+
if (bypass)
|
|
155
|
+
this.bypassRunning--;
|
|
126
156
|
if (mutation)
|
|
127
157
|
this.mutationRunning = false;
|
|
128
158
|
if (deliveredTermination && abortSource) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateText, isStepCount, tool } from 'ai';
|
|
2
2
|
import { estimateToolSchemas, estimateValueTokens } from '../agent/contextBudget.js';
|
|
3
|
-
import { SUBAGENT_MAX_STEPS, SUBAGENT_MIN_STEPS, SUBAGENT_SYNTHESIS_RESERVE, SUBAGENT_TOOL_ONLY_LIMIT, } from '../agent/budgets.js';
|
|
3
|
+
import { SUBAGENT_MAX_STEPS, SUBAGENT_MIN_STEPS, SUBAGENT_SYNTHESIS_RESERVE, SUBAGENT_TOOL_ONLY_LIMIT, createToolExecutionBudget, isToolBudgetBlocked, withToolExecutionBudget, } from '../agent/budgets.js';
|
|
4
4
|
import { storeToolOutput } from '../agent/toolOutputStore.js';
|
|
5
5
|
import { withSyntheticControl } from '../agent/requestAssembly.js';
|
|
6
6
|
import { toolOnlyStepCount } from '../agent/turnPolicy.js';
|
|
@@ -13,28 +13,6 @@ import { COMPATIBILITY_PROFILE, MODE_TOOL_NAMES } from './executionProfiles.js';
|
|
|
13
13
|
import { SubagentCoordinator } from './subagentCoordinator.js';
|
|
14
14
|
import { resolveWorkspacePath, workspaceRelativePath } from '../../utils/path.js';
|
|
15
15
|
const SYNTHESIS_DIRECTIVE = 'You have reached your tool/step budget. Stop calling tools. Return the requested self-contained deliverable now, including evidence, coverage gaps, changed paths, validation, and precise remaining work. A concise partial deliverable is mandatory and better than an empty response.';
|
|
16
|
-
const TOOL_BUDGET_BLOCKED = '__hazeSubagentToolBudgetBlocked';
|
|
17
|
-
function withToolExecutionBudget(tools, maxToolCalls, state) {
|
|
18
|
-
return Object.fromEntries(Object.entries(tools).map(([name, definition]) => {
|
|
19
|
-
if (typeof definition.execute !== 'function')
|
|
20
|
-
return [name, definition];
|
|
21
|
-
const execute = definition.execute;
|
|
22
|
-
return [name, {
|
|
23
|
-
...definition,
|
|
24
|
-
execute: (...args) => {
|
|
25
|
-
// This check is at the actual execute boundary. Concurrent calls from
|
|
26
|
-
// one emitted batch enter synchronously, so no more than the remaining
|
|
27
|
-
// budget can reach an underlying tool implementation.
|
|
28
|
-
if (state.started >= maxToolCalls) {
|
|
29
|
-
state.exceeded = true;
|
|
30
|
-
return { ok: false, [TOOL_BUDGET_BLOCKED]: true, error: `Subagent tool-call budget of ${maxToolCalls} exhausted; execution was blocked.` };
|
|
31
|
-
}
|
|
32
|
-
state.started++;
|
|
33
|
-
return execute(...args);
|
|
34
|
-
},
|
|
35
|
-
}];
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
16
|
function toolSummary(output) {
|
|
39
17
|
if (typeof output !== 'object' || output == null)
|
|
40
18
|
return 'completed';
|
|
@@ -75,7 +53,7 @@ function changedPathFromOutput(name, output) {
|
|
|
75
53
|
}
|
|
76
54
|
}
|
|
77
55
|
function validationFromOutput(name, output) {
|
|
78
|
-
if (name !== '
|
|
56
|
+
if (name !== 'shell' || typeof output !== 'object' || output == null)
|
|
79
57
|
return undefined;
|
|
80
58
|
const value = output;
|
|
81
59
|
if (typeof value.command !== 'string' || typeof value.validationSummary !== 'object' || value.validationSummary == null)
|
|
@@ -95,7 +73,7 @@ export async function runSubagent(taskInput, options) {
|
|
|
95
73
|
const profile = options.profile ?? COMPATIBILITY_PROFILE;
|
|
96
74
|
const runtime = options.runtime ?? fallbackWorkerRuntime(options.model);
|
|
97
75
|
const task = typeof taskInput === 'string'
|
|
98
|
-
? { id: 'worker', objective: taskInput, deliverable: 'Return a concise self-contained result.', mode: options.allowedTools ? (options.allowedTools.some(name => ['editFile', 'replaceLines', 'writeFile'].includes(name)) ? 'implement' : options.allowedTools.includes('
|
|
76
|
+
? { id: 'worker', objective: taskInput, deliverable: 'Return a concise self-contained result.', mode: options.allowedTools ? (options.allowedTools.some(name => ['editFile', 'replaceLines', 'writeFile'].includes(name)) ? 'implement' : options.allowedTools.includes('shell') ? 'validate' : options.allowedTools.includes('fetch') ? 'research' : 'inspect') : 'implement', scope: [], acceptanceCriteria: [], legacyMaxSteps: options.maxSteps }
|
|
99
77
|
: taskInput;
|
|
100
78
|
const requestedSteps = task.legacyMaxSteps ?? options.maxSteps;
|
|
101
79
|
if (requestedSteps != null && (requestedSteps < SUBAGENT_MIN_STEPS || requestedSteps > SUBAGENT_MAX_STEPS))
|
|
@@ -112,8 +90,8 @@ export async function runSubagent(taskInput, options) {
|
|
|
112
90
|
const validation = [];
|
|
113
91
|
let usageIn;
|
|
114
92
|
let usageOut;
|
|
115
|
-
const toolBudget =
|
|
116
|
-
const budgetedTools = withToolExecutionBudget(bundle.tools, profile.maxToolCalls
|
|
93
|
+
const toolBudget = createToolExecutionBudget();
|
|
94
|
+
const budgetedTools = withToolExecutionBudget(bundle.tools, { state: toolBudget, limit: profile.maxToolCalls });
|
|
117
95
|
const mutationPolicy = options.mutationPolicy;
|
|
118
96
|
const mutationOwner = mutationPolicy?.createOwner();
|
|
119
97
|
const toolExecutionContext = {
|
|
@@ -128,15 +106,16 @@ export async function runSubagent(taskInput, options) {
|
|
|
128
106
|
if (mutationPolicy && mutationOwner && (task.mode === 'implement' || task.mode === 'validate') && !release)
|
|
129
107
|
return terminalResult(task, runtime, profile, options.deadlineExpired?.() ? 'deadline_exceeded' : 'cancelled', 'Worker cancelled before workspace admission.', options.queueMs);
|
|
130
108
|
try {
|
|
109
|
+
const { omitMaxOutputTokens, ...providerRequestOptions } = runtime.requestOptions;
|
|
131
110
|
const result = await generateText({
|
|
132
111
|
model: runtime.model,
|
|
133
112
|
instructions: bundle.systemPrompt,
|
|
134
113
|
messages: [{ role: 'user', content: workerTaskMessage(task) }],
|
|
135
114
|
tools: budgetedTools,
|
|
136
115
|
stopWhen: isStepCount(maxSteps),
|
|
137
|
-
maxOutputTokens: profile.maxOutputTokens,
|
|
116
|
+
...(!omitMaxOutputTokens ? { maxOutputTokens: profile.maxOutputTokens } : {}),
|
|
138
117
|
maxRetries: profile.maxRetries,
|
|
139
|
-
...
|
|
118
|
+
...providerRequestOptions,
|
|
140
119
|
abortSignal: options.abortSignal,
|
|
141
120
|
runtimeContext: toolExecutionContext,
|
|
142
121
|
toolsContext: toolsContextFor(budgetedTools, toolExecutionContext),
|
|
@@ -156,17 +135,17 @@ export async function runSubagent(taskInput, options) {
|
|
|
156
135
|
if (!event.toolCall)
|
|
157
136
|
return;
|
|
158
137
|
const output = event.toolOutput.type === 'tool-result' ? event.toolOutput.output : undefined;
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
138
|
+
if (!isToolBudgetBlocked(output)) {
|
|
139
|
+
const toolError = 'error' in event.toolOutput ? event.toolOutput.error : 'tool execution failed';
|
|
140
|
+
if (toolCallLog.length < profile.maxToolCalls)
|
|
141
|
+
toolCallLog.push({ name: event.toolCall.toolName, summary: output === undefined ? `failed: ${String(toolError).slice(0, 120)}` : toolSummary(output), durationMs: event.toolExecutionMs });
|
|
142
|
+
const changedPath = changedPathFromOutput(event.toolCall.toolName, output);
|
|
143
|
+
if (changedPath)
|
|
144
|
+
changedPaths.add(changedPath);
|
|
145
|
+
const validationRecord = validationFromOutput(event.toolCall.toolName, output);
|
|
146
|
+
if (validationRecord)
|
|
147
|
+
validation.push(validationRecord);
|
|
148
|
+
}
|
|
170
149
|
},
|
|
171
150
|
});
|
|
172
151
|
usageIn = result.usage.inputTokens ?? usageIn;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type ReductionPressure = 'conservative' | 'normal' | 'aggressive';
|
|
2
1
|
export declare const PROCESSING_OUTPUT_CHAR_LIMIT = 200000;
|
|
3
2
|
export type ReductionContentKind = 'validation' | 'log' | 'search' | 'diff' | 'json' | 'table' | 'web' | 'source-outline' | 'generic';
|
|
4
3
|
export type ReductionParseTier = 'full' | 'degraded' | 'passthrough';
|
|
@@ -10,17 +9,6 @@ export interface ReductionMetrics {
|
|
|
10
9
|
estimatedSavedTokens: number;
|
|
11
10
|
savingsPct: number;
|
|
12
11
|
}
|
|
13
|
-
export interface ToolOutputReductionMetadata extends ReductionMetrics {
|
|
14
|
-
reducerName: string;
|
|
15
|
-
contentKind: ReductionContentKind;
|
|
16
|
-
lossy: boolean;
|
|
17
|
-
parseTier: ReductionParseTier;
|
|
18
|
-
rawHandle?: string;
|
|
19
|
-
handle?: string;
|
|
20
|
-
omittedChars: number;
|
|
21
|
-
warning?: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function estimateReductionTokens(text: string): number;
|
|
24
12
|
export declare function capOutputForProcessing(text: string, maxChars?: number): string;
|
|
25
13
|
export declare function reductionMetrics(raw: string, returned: string): ReductionMetrics;
|
|
26
14
|
export declare function retrievalHint(handle: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const PROCESSING_OUTPUT_CHAR_LIMIT = 200_000;
|
|
2
2
|
const PROCESSING_TRUNCATION_MARKER = '\n[... output truncated for processing ...]\n';
|
|
3
|
-
|
|
3
|
+
function estimateReductionTokens(text) {
|
|
4
4
|
return Math.ceil(text.length / 4);
|
|
5
5
|
}
|
|
6
6
|
export function capOutputForProcessing(text, maxChars = PROCESSING_OUTPUT_CHAR_LIMIT) {
|
|
@@ -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;
|
|
@@ -8,5 +8,5 @@ export declare function parseValidationOutput(input: {
|
|
|
8
8
|
timedOut?: boolean;
|
|
9
9
|
stdoutTruncated?: boolean;
|
|
10
10
|
stderrTruncated?: boolean;
|
|
11
|
-
classification?:
|
|
11
|
+
classification?: ShellClassification;
|
|
12
12
|
}): ValidationSummary;
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { readSettings } from '../config/settings.js';
|
|
1
|
+
import { readSettings, type HazeProviderSettings } from '../config/settings.js';
|
|
2
2
|
import type { ProviderCapabilities, ProviderRequestOptions, WorkerRuntime } from '../core/subagent/contracts.js';
|
|
3
|
+
import { type ResolvedReasoningPolicy } from '../core/agent/reasoningPolicy.js';
|
|
3
4
|
export type { ProviderCapabilities, ProviderRequestOptions } from '../core/subagent/contracts.js';
|
|
4
5
|
export interface ModelRuntimeSelection {
|
|
5
6
|
model: WorkerRuntime['model'];
|
|
@@ -8,11 +9,26 @@ export interface ModelRuntimeSelection {
|
|
|
8
9
|
}
|
|
9
10
|
export interface ModelRuntimeConfig {
|
|
10
11
|
providerName: string;
|
|
12
|
+
providerKind?: HazeProviderSettings['kind'];
|
|
11
13
|
baseURL: string;
|
|
12
14
|
modelName: string;
|
|
13
15
|
cacheKey: string;
|
|
14
16
|
capabilities: ProviderCapabilities;
|
|
17
|
+
/** Resolved reasoning policy (requested vs effective); observable, no secrets. */
|
|
18
|
+
reasoningPolicy: ResolvedReasoningPolicy;
|
|
19
|
+
/**
|
|
20
|
+
* Effective context window for request budgeting (RH-005). Always set: the
|
|
21
|
+
* user-configured value when present, otherwise a class-aware fallback
|
|
22
|
+
* (128K hosted / 32K local) so `contextWindowSource` can flag the guess.
|
|
23
|
+
*/
|
|
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';
|
|
27
|
+
/** Optional output-token limit metadata for request budgeting (RH-005). */
|
|
28
|
+
maxOutputTokens?: number;
|
|
15
29
|
}
|
|
30
|
+
/** True for loopback/local inference servers, whose effective window is server-configured (often far below the model's). */
|
|
31
|
+
export declare function isLocalProviderUrl(url: string): boolean;
|
|
16
32
|
export declare function modelWithConfig(session?: {
|
|
17
33
|
cwd?: string;
|
|
18
34
|
modelSelector?: string;
|
package/dist/llm/client.js
CHANGED
|
@@ -3,8 +3,15 @@ import crypto from 'node:crypto';
|
|
|
3
3
|
import { readSettings } from '../config/settings.js';
|
|
4
4
|
import { activeModel, modelSelector, resolveModelSelector } from '../config/providers.js';
|
|
5
5
|
import { assertCredentialedEndpointSecure } from '../config/endpointSecurity.js';
|
|
6
|
+
import { resolveReasoningPolicy } from '../core/agent/reasoningPolicy.js';
|
|
7
|
+
import { FALLBACK_CONTEXT_WINDOW_TOKENS, FALLBACK_LOCAL_CONTEXT_TOKENS } from '../core/agent/contextBudget.js';
|
|
8
|
+
import { createChatGptCodexFetch } from './openaiCodex.js';
|
|
6
9
|
const HAZE_SITE_URL = 'https://denizokcu.github.io/haze/';
|
|
7
10
|
const HAZE_TITLE = 'Haze';
|
|
11
|
+
// The SDK requires a non-empty apiKey even though the OAuth fetch adapter
|
|
12
|
+
// replaces authentication. Generate a non-credential sentinel at runtime so
|
|
13
|
+
// static scanners cannot mistake a fixed placeholder for a shipped secret.
|
|
14
|
+
const OAUTH_SDK_SENTINEL = `oauth-sentinel-${crypto.randomUUID()}`;
|
|
8
15
|
function isOpenRouter(providerName, baseURL) {
|
|
9
16
|
return providerName === 'openrouter' || /openrouter\.ai/i.test(baseURL);
|
|
10
17
|
}
|
|
@@ -16,8 +23,8 @@ function openRouterHeaders(providerName, baseURL) {
|
|
|
16
23
|
'X-Title': HAZE_TITLE,
|
|
17
24
|
};
|
|
18
25
|
}
|
|
19
|
-
function capabilities(providerName, baseURL) {
|
|
20
|
-
const directOpenAI = providerName === 'openai' || /api\.openai\.com/i.test(baseURL);
|
|
26
|
+
function capabilities(providerName, baseURL, providerKind) {
|
|
27
|
+
const directOpenAI = providerKind !== 'chatgpt-codex' && (providerName === 'openai' || /api\.openai\.com/i.test(baseURL));
|
|
21
28
|
const openRouter = isOpenRouter(providerName, baseURL);
|
|
22
29
|
return {
|
|
23
30
|
reportsCacheUsage: directOpenAI || openRouter,
|
|
@@ -26,22 +33,78 @@ function capabilities(providerName, baseURL) {
|
|
|
26
33
|
supportsStickySessionId: openRouter,
|
|
27
34
|
supportsServerCompaction: false,
|
|
28
35
|
supportsTextVerbosity: directOpenAI,
|
|
36
|
+
supportsReasoningEffort: directOpenAI,
|
|
29
37
|
};
|
|
30
38
|
}
|
|
39
|
+
/** True for loopback/local inference servers, whose effective window is server-configured (often far below the model's). */
|
|
40
|
+
export function isLocalProviderUrl(url) {
|
|
41
|
+
try {
|
|
42
|
+
const hostname = new URL(url).hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
43
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' || hostname === '0.0.0.0' || hostname.endsWith('.local');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
31
49
|
function runtimeForSelection(settings, selection, cwd) {
|
|
32
50
|
const baseURL = selection.provider.url;
|
|
33
|
-
const
|
|
51
|
+
const providerKind = selection.provider.kind;
|
|
52
|
+
const configuredKey = providerKind === 'chatgpt-codex' ? undefined : selection.provider.key ?? settings.apiKey;
|
|
34
53
|
assertCredentialedEndpointSecure(baseURL, configuredKey);
|
|
35
54
|
const apiKey = configuredKey ?? 'not-needed';
|
|
36
55
|
const name = selection.model;
|
|
37
56
|
const cacheSeed = cwd ?? process.cwd();
|
|
38
57
|
const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
|
|
58
|
+
const caps = capabilities(selection.provider.name, baseURL, providerKind);
|
|
59
|
+
const requestedReasoning = isReasoningLevel(settings.reasoning) ? settings.reasoning : undefined;
|
|
60
|
+
const reasoningPolicy = resolveReasoningPolicy({ requested: requestedReasoning, capabilities: caps });
|
|
61
|
+
const openai = providerKind === 'chatgpt-codex'
|
|
62
|
+
? createOpenAI({ apiKey: OAUTH_SDK_SENTINEL, baseURL, fetch: createChatGptCodexFetch(selection.provider.name) })
|
|
63
|
+
: createOpenAI({ apiKey, baseURL, headers: openRouterHeaders(selection.provider.name, baseURL) });
|
|
64
|
+
const limits = modelLimitsFor(selection.provider, name);
|
|
65
|
+
// Class-aware fallback so unknown local models (server-configured window,
|
|
66
|
+
// silent truncation) stay conservative while unknown hosted models get the
|
|
67
|
+
// modern 128K floor. A user-set fallback setting overrides the built-in
|
|
68
|
+
// default; the source tag distinguishes an intentional guess (no warning)
|
|
69
|
+
// from the default guess (warned once per session) (RH-005).
|
|
70
|
+
const isLocal = isLocalProviderUrl(baseURL);
|
|
71
|
+
const userFallback = isLocal ? settings.localContextWindowFallbackTokens : settings.contextWindowFallbackTokens;
|
|
72
|
+
const fallbackTokens = userFallback ?? (isLocal ? FALLBACK_LOCAL_CONTEXT_TOKENS : FALLBACK_CONTEXT_WINDOW_TOKENS);
|
|
73
|
+
const contextWindowSource = limits.contextWindowTokens !== undefined
|
|
74
|
+
? 'settings'
|
|
75
|
+
: userFallback !== undefined ? 'user-fallback' : 'default-fallback';
|
|
39
76
|
return {
|
|
40
|
-
model:
|
|
77
|
+
model: providerKind === 'chatgpt-codex' ? openai.responses(name) : openai.chat(name),
|
|
41
78
|
selector: modelSelector(selection.provider, name),
|
|
42
|
-
config: {
|
|
79
|
+
config: {
|
|
80
|
+
providerName: selection.provider.name,
|
|
81
|
+
providerKind,
|
|
82
|
+
baseURL,
|
|
83
|
+
modelName: name,
|
|
84
|
+
cacheKey,
|
|
85
|
+
capabilities: caps,
|
|
86
|
+
reasoningPolicy,
|
|
87
|
+
contextWindowTokens: limits.contextWindowTokens ?? fallbackTokens,
|
|
88
|
+
contextWindowSource,
|
|
89
|
+
...(limits.maxOutputTokens !== undefined ? { maxOutputTokens: limits.maxOutputTokens } : {}),
|
|
90
|
+
},
|
|
43
91
|
};
|
|
44
92
|
}
|
|
93
|
+
/** Resolve optional context-window/output-token metadata for the selected model (RH-005). */
|
|
94
|
+
function modelLimitsFor(provider, modelName) {
|
|
95
|
+
const limits = provider.modelLimits?.[modelName];
|
|
96
|
+
if (!limits)
|
|
97
|
+
return {};
|
|
98
|
+
const out = {};
|
|
99
|
+
if (typeof limits.contextWindowTokens === 'number')
|
|
100
|
+
out.contextWindowTokens = limits.contextWindowTokens;
|
|
101
|
+
if (typeof limits.maxOutputTokens === 'number')
|
|
102
|
+
out.maxOutputTokens = limits.maxOutputTokens;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function isReasoningLevel(value) {
|
|
106
|
+
return value === 'low' || value === 'medium' || value === 'high';
|
|
107
|
+
}
|
|
45
108
|
export async function modelWithConfig(session, settings) {
|
|
46
109
|
// Callers may pass pre-read settings so a turn performs a single settings
|
|
47
110
|
// read (CR-024); otherwise read fresh.
|
|
@@ -69,15 +132,24 @@ export async function resolveWorkerRuntime(input) {
|
|
|
69
132
|
return { status: 'found', runtime: { model: selected.model, selector: selected.selector, providerName: selected.config.providerName, capabilities: selected.config.capabilities, requestOptions: providerRequestSettings(selected.config) } };
|
|
70
133
|
}
|
|
71
134
|
export function providerRequestSettings(config) {
|
|
135
|
+
if (config.providerKind === 'chatgpt-codex') {
|
|
136
|
+
return {
|
|
137
|
+
omitMaxOutputTokens: true,
|
|
138
|
+
providerOptions: { openai: { store: false, include: ['reasoning.encrypted_content'] } },
|
|
139
|
+
headers: { 'session-id': config.cacheKey },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const caps = config.capabilities;
|
|
143
|
+
const openaiOptions = {};
|
|
144
|
+
if (caps.supportsPromptCacheKey)
|
|
145
|
+
openaiOptions.promptCacheKey = config.cacheKey;
|
|
146
|
+
if (caps.supportsTextVerbosity)
|
|
147
|
+
openaiOptions.textVerbosity = 'low';
|
|
148
|
+
if (config.reasoningPolicy.effective !== 'disabled')
|
|
149
|
+
openaiOptions.reasoningEffort = config.reasoningPolicy.effective;
|
|
150
|
+
const providerOptions = Object.keys(openaiOptions).length > 0 ? { openai: openaiOptions } : undefined;
|
|
72
151
|
return {
|
|
73
|
-
...(
|
|
74
|
-
|
|
75
|
-
openai: {
|
|
76
|
-
...(config.capabilities.supportsPromptCacheKey ? { promptCacheKey: config.cacheKey } : {}),
|
|
77
|
-
...(config.capabilities.supportsTextVerbosity ? { textVerbosity: 'low' } : {}),
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
} : {}),
|
|
81
|
-
...(config.capabilities.supportsStickySessionId ? { headers: { 'x-session-id': config.cacheKey } } : {}),
|
|
152
|
+
...(providerOptions ? { providerOptions } : {}),
|
|
153
|
+
...(caps.supportsStickySessionId ? { headers: { 'x-session-id': config.cacheKey } } : {}),
|
|
82
154
|
};
|
|
83
155
|
}
|