@denizokcu/haze 0.11.0 → 1.1.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 +33 -0
- package/README.md +28 -14
- package/SECURITY.md +5 -3
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/TaskBar.js +1 -1
- package/dist/cli/chat/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/fileMentionSuggestions.js +1 -1
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +10 -41
- package/dist/cli/chat/messages.d.ts +0 -2
- package/dist/cli/chat/messages.js +5 -5
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -1
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +257 -130
- package/dist/cli/commands/chat.js +61 -77
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commandHelp.js +2 -0
- package/dist/cli/commands/commands.js +2 -0
- package/dist/cli/commands/doctor.js +1 -1
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +12 -25
- package/dist/cli/commands/providerWizard.js +2 -3
- package/dist/cli/commands/runCommand.js +1 -1
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/settingsSummary.js +2 -0
- 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 +2 -1
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- 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 +1 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +2 -2
- package/dist/cli/commands/streaming/goalSupervisor.js +9 -6
- 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 +14 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +56 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -1
- 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 +14 -25
- package/dist/cli/commands/streaming.js +43 -754
- package/dist/cli/commands/themesCommand.d.ts +17 -0
- package/dist/cli/commands/themesCommand.js +24 -0
- package/dist/cli/commands/wizardFlow.d.ts +341 -0
- package/dist/cli/commands/wizardFlow.js +397 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.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 +0 -15
- package/dist/config/modelDiscovery.js +1 -1
- package/dist/config/settings.d.ts +9 -0
- package/dist/config/settings.js +4 -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 +63 -1
- package/dist/core/agent/budgets.js +84 -1
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/completionController.d.ts +7 -13
- package/dist/core/agent/completionController.js +17 -8
- package/dist/core/agent/contextBudget.d.ts +0 -4
- package/dist/core/agent/contextBudget.js +3 -3
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +5 -1
- package/dist/core/{goal/completionPolicy.d.ts → agent/goalPolicy.d.ts} +18 -0
- package/dist/core/agent/goalPolicy.js +106 -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 +2 -2
- package/dist/core/agent/toolCapabilities.js +5 -5
- package/dist/core/agent/toolOutputStore.js +1 -1
- package/dist/core/agent/toolResults.js +1 -1
- package/dist/core/agent/workState.d.ts +6 -3
- package/dist/core/agent/workState.js +62 -7
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +0 -6
- package/dist/core/deadline.js +1 -1
- 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 +1 -1
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +10 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/secretPaths.d.ts +18 -0
- package/dist/core/safety/secretPaths.js +115 -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 +1 -0
- package/dist/core/session/sessionStore.js +39 -20
- 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 +2 -14
- package/dist/core/subagent/contracts.js +3 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentRunner.js +3 -4
- 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.js +5 -1
- package/dist/llm/hazeTools.d.ts +139 -124
- package/dist/llm/hazeTools.js +20 -11
- 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 +3824 -570
- package/dist/llm/lspTools.js +65 -1
- package/dist/llm/openaiCodex.d.ts +0 -2
- package/dist/llm/openaiCodex.js +0 -4
- package/dist/llm/openaiCodexOAuth.d.ts +0 -3
- package/dist/llm/openaiCodexOAuth.js +6 -3
- package/dist/llm/requestContext.d.ts +5 -1
- package/dist/llm/requestContext.js +25 -2
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +16 -7
- package/dist/llm/toolResultTypes.d.ts +1 -15
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +0 -9
- package/dist/llm/tools/editMatch.js +1 -1
- package/dist/llm/tools/failures.d.ts +6 -0
- package/dist/llm/tools/failures.js +8 -2
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +4 -2
- package/dist/llm/tools/fileToolShared.js +9 -5
- package/dist/llm/tools/gitIgnore.d.ts +25 -32
- package/dist/llm/tools/gitIgnore.js +216 -98
- 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 +0 -2
- package/dist/llm/tools/readRecovery.js +4 -2
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +123 -107
- package/dist/llm/tools/{bashTool.js → shellTool.js} +18 -14
- package/dist/llm/tools/toolContext.js +5 -5
- package/dist/llm/tools/workspaceFile.d.ts +4 -4
- package/dist/llm/tools/workspaceFile.js +29 -17
- package/dist/llm/webFetch.d.ts +1 -1
- 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/components/Header.js +1 -1
- package/dist/ui/components/MarkdownText.js +10 -10
- package/dist/ui/components/TextInput.d.ts +1 -1
- package/dist/ui/components/TextInput.js +2 -2
- package/dist/ui/terminalColors.d.ts +29 -0
- package/dist/ui/terminalColors.js +47 -0
- package/dist/ui/theme.d.ts +105 -10
- package/dist/ui/theme.js +126 -15
- package/dist/ui/themes/af-magic.d.ts +7 -0
- package/dist/ui/themes/af-magic.js +25 -0
- package/dist/ui/themes/agnoster.d.ts +10 -0
- package/dist/ui/themes/agnoster.js +40 -0
- package/dist/ui/themes/bira.d.ts +10 -0
- package/dist/ui/themes/bira.js +28 -0
- package/dist/ui/themes/bureau.d.ts +10 -0
- package/dist/ui/themes/bureau.js +28 -0
- package/dist/ui/themes/clean.d.ts +9 -0
- package/dist/ui/themes/clean.js +27 -0
- package/dist/ui/themes/cloud.d.ts +6 -0
- package/dist/ui/themes/cloud.js +24 -0
- package/dist/ui/themes/dst.d.ts +10 -0
- package/dist/ui/themes/dst.js +28 -0
- package/dist/ui/themes/fishy.d.ts +7 -0
- package/dist/ui/themes/fishy.js +25 -0
- package/dist/ui/themes/index.d.ts +8 -0
- package/dist/ui/themes/index.js +36 -0
- package/dist/ui/themes/light.d.ts +3 -0
- package/dist/ui/themes/light.js +21 -0
- package/dist/ui/themes/purple.d.ts +7 -0
- package/dist/ui/themes/purple.js +26 -0
- package/dist/ui/themes/robbyrussell.d.ts +8 -0
- package/dist/ui/themes/robbyrussell.js +26 -0
- package/dist/ui/themes/solarized-dark.d.ts +16 -0
- package/dist/ui/themes/solarized-dark.js +44 -0
- package/dist/ui/themes/solarized-light.d.ts +12 -0
- package/dist/ui/themes/solarized-light.js +40 -0
- package/dist/ui/themes/steeef.d.ts +11 -0
- package/dist/ui/themes/steeef.js +29 -0
- package/dist/utils/buildInfo.d.ts +6 -13
- package/dist/utils/buildInfo.js +6 -15
- package/dist/utils/fs.d.ts +7 -5
- package/dist/utils/fs.js +5 -2
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +1 -1
- package/package.json +6 -4
- 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 -27
- package/dist/cli/commands/streaming/turnOutcome.js +0 -29
- package/dist/cli/commands/wizardActions.d.ts +0 -47
- package/dist/cli/commands/wizardActions.js +0 -47
- 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 -58
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -190
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/agent/toolExecutionBudget.d.ts +0 -35
- package/dist/core/agent/toolExecutionBudget.js +0 -49
- package/dist/core/agent/turnBudget.d.ts +0 -35
- package/dist/core/agent/turnBudget.js +0 -27
- 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.js +0 -43
- 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 -20
- package/dist/core/limits/byteBudgets.js +0 -20
- package/dist/core/limits/textBudgets.d.ts +0 -25
- package/dist/core/limits/textBudgets.js +0 -25
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -149
- package/dist/llm/lsp.js +0 -368
- 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,3 +1,4 @@
|
|
|
1
|
+
import type { ToolSet } from 'ai';
|
|
1
2
|
export declare const DEFAULT_MAX_OUTPUT_TOKENS = 16384;
|
|
2
3
|
/** Keep generated file payloads comfortably below a model's output-token ceiling. */
|
|
3
4
|
export declare const WRITE_FILE_CHUNK_BYTES: number;
|
|
@@ -13,7 +14,6 @@ export declare const MAX_TURN_DEADLINE_MS: number;
|
|
|
13
14
|
export declare const MAIN_STEP_LIMIT = 64;
|
|
14
15
|
export declare const MAIN_TOOL_CALL_LIMIT = 120;
|
|
15
16
|
export declare const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
16
|
-
export declare const ACTIVE_CONTEXT_TOKEN_BUDGET = 40000;
|
|
17
17
|
export declare const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
|
|
18
18
|
export declare const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
|
|
19
19
|
export declare const SUBAGENT_OBJECTIVE_CHARS = 4000;
|
|
@@ -40,3 +40,65 @@ export declare const SUBAGENT_MIN_DEADLINE_MS = 1000;
|
|
|
40
40
|
export declare const SUBAGENT_MAX_DEADLINE_MS: number;
|
|
41
41
|
export declare const SUBAGENT_MAX_CONCURRENCY = 10;
|
|
42
42
|
export declare const SUBAGENT_MAX_RETRIES = 5;
|
|
43
|
+
/** Default size of the shared bounded model-retry pool for transient model errors and idle-stream stalls, per turn. Configurable via the `modelRetries` setting (0 disables automatic retries). */
|
|
44
|
+
export declare const DEFAULT_MODEL_RETRIES = 2;
|
|
45
|
+
/** Upper bound accepted for the `modelRetries` setting (mirrors the settings schema). */
|
|
46
|
+
export declare const MAX_MODEL_RETRIES_SETTING = 10;
|
|
47
|
+
export interface TurnBudget {
|
|
48
|
+
/** Maximum completed model steps across the whole turn (incl. recovery). */
|
|
49
|
+
stepLimit: number;
|
|
50
|
+
/** Maximum completed tool calls across the whole turn (incl. recovery). */
|
|
51
|
+
toolCallLimit: number;
|
|
52
|
+
/** Maximum completed tool-only steps across the whole turn. */
|
|
53
|
+
toolOnlyStepLimit: number;
|
|
54
|
+
}
|
|
55
|
+
export declare function mainTurnBudget(): TurnBudget;
|
|
56
|
+
/** Steps still available to the turn given usage so far (never negative). */
|
|
57
|
+
export declare function remainingSteps(used: number, budget: TurnBudget): number;
|
|
58
|
+
/** Tool calls still available to the turn given usage so far (never negative). */
|
|
59
|
+
export declare function remainingToolCalls(used: number, budget: TurnBudget): number;
|
|
60
|
+
/** True when adding `extra` tool calls would meet or exceed the call budget. */
|
|
61
|
+
export declare function wouldExceedToolCalls(used: number, extra: number, budget: TurnBudget): boolean;
|
|
62
|
+
/** A recovery slice can only run if at least one step and one tool call remain. */
|
|
63
|
+
export declare function hasUsableBudget(used: {
|
|
64
|
+
steps: number;
|
|
65
|
+
toolCalls: number;
|
|
66
|
+
}, budget: TurnBudget): boolean;
|
|
67
|
+
/** Clamp a requested slice size to what the turn budget actually allows. */
|
|
68
|
+
export declare function clampSlice(requested: {
|
|
69
|
+
steps: number;
|
|
70
|
+
toolCalls: number;
|
|
71
|
+
}, remaining: {
|
|
72
|
+
steps: number;
|
|
73
|
+
toolCalls: number;
|
|
74
|
+
}): {
|
|
75
|
+
steps: number;
|
|
76
|
+
toolCalls: number;
|
|
77
|
+
};
|
|
78
|
+
export interface ToolExecutionBudgetState {
|
|
79
|
+
/** Number of underlying executions that have actually started. */
|
|
80
|
+
started: number;
|
|
81
|
+
/** Set once a call was blocked so callers can force synthesis. */
|
|
82
|
+
exceeded: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare function createToolExecutionBudget(): ToolExecutionBudgetState;
|
|
85
|
+
/** True when a tool result is the structured "budget blocked" placeholder. */
|
|
86
|
+
export declare function isToolBudgetBlocked(output: unknown): boolean;
|
|
87
|
+
export interface BudgetLimit {
|
|
88
|
+
state: ToolExecutionBudgetState;
|
|
89
|
+
limit: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Wrap a tool set so each underlying `execute` checks-and-increments one or more
|
|
93
|
+
* shared budgets synchronously at the actual execution boundary. A model-emitted
|
|
94
|
+
* parallel batch enters `execute` sequentially on the JS event loop, so no more
|
|
95
|
+
* than the remaining budget can reach an underlying implementation even within
|
|
96
|
+
* one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
|
|
97
|
+
* and invoking execute.
|
|
98
|
+
*
|
|
99
|
+
* When any supplied limit is exhausted the call is blocked: every limit is
|
|
100
|
+
* marked exceeded, no underlying call runs, and a structured bounded failure is
|
|
101
|
+
* returned so the SDK completes the step and the next prepareStep forces
|
|
102
|
+
* text-only synthesis.
|
|
103
|
+
*/
|
|
104
|
+
export declare function withToolExecutionBudget(tools: ToolSet, ...limits: BudgetLimit[]): ToolSet;
|
|
@@ -13,7 +13,6 @@ export const MAX_TURN_DEADLINE_MS = 24 * 60 * 60_000;
|
|
|
13
13
|
export const MAIN_STEP_LIMIT = 64;
|
|
14
14
|
export const MAIN_TOOL_CALL_LIMIT = 120;
|
|
15
15
|
export const MAIN_TOOL_ONLY_STEP_LIMIT = 24;
|
|
16
|
-
export const ACTIVE_CONTEXT_TOKEN_BUDGET = 40_000;
|
|
17
16
|
export const BACKGROUND_PROCESS_MAX_CONCURRENCY = 5;
|
|
18
17
|
export const BACKGROUND_PROCESS_HISTORY_LIMIT = 20;
|
|
19
18
|
// Disposable worker/task-capsule limits. Keep these centralized so model-facing
|
|
@@ -48,3 +47,87 @@ export const SUBAGENT_MIN_DEADLINE_MS = 1_000;
|
|
|
48
47
|
export const SUBAGENT_MAX_DEADLINE_MS = 30 * 60_000;
|
|
49
48
|
export const SUBAGENT_MAX_CONCURRENCY = 10;
|
|
50
49
|
export const SUBAGENT_MAX_RETRIES = 5;
|
|
50
|
+
/** Default size of the shared bounded model-retry pool for transient model errors and idle-stream stalls, per turn. Configurable via the `modelRetries` setting (0 disables automatic retries). */
|
|
51
|
+
export const DEFAULT_MODEL_RETRIES = 2;
|
|
52
|
+
/** Upper bound accepted for the `modelRetries` setting (mirrors the settings schema). */
|
|
53
|
+
export const MAX_MODEL_RETRIES_SETTING = 10;
|
|
54
|
+
export function mainTurnBudget() {
|
|
55
|
+
return { stepLimit: MAIN_STEP_LIMIT, toolCallLimit: MAIN_TOOL_CALL_LIMIT, toolOnlyStepLimit: MAIN_TOOL_ONLY_STEP_LIMIT };
|
|
56
|
+
}
|
|
57
|
+
/** Steps still available to the turn given usage so far (never negative). */
|
|
58
|
+
export function remainingSteps(used, budget) {
|
|
59
|
+
return Math.max(0, budget.stepLimit - used);
|
|
60
|
+
}
|
|
61
|
+
/** Tool calls still available to the turn given usage so far (never negative). */
|
|
62
|
+
export function remainingToolCalls(used, budget) {
|
|
63
|
+
return Math.max(0, budget.toolCallLimit - used);
|
|
64
|
+
}
|
|
65
|
+
/** True when adding `extra` tool calls would meet or exceed the call budget. */
|
|
66
|
+
export function wouldExceedToolCalls(used, extra, budget) {
|
|
67
|
+
return used + extra >= budget.toolCallLimit;
|
|
68
|
+
}
|
|
69
|
+
/** A recovery slice can only run if at least one step and one tool call remain. */
|
|
70
|
+
export function hasUsableBudget(used, budget) {
|
|
71
|
+
return used.steps < budget.stepLimit && used.toolCalls < budget.toolCallLimit;
|
|
72
|
+
}
|
|
73
|
+
/** Clamp a requested slice size to what the turn budget actually allows. */
|
|
74
|
+
export function clampSlice(requested, remaining) {
|
|
75
|
+
return {
|
|
76
|
+
steps: Math.max(0, Math.min(requested.steps, remaining.steps)),
|
|
77
|
+
toolCalls: Math.max(0, Math.min(requested.toolCalls, remaining.toolCalls)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// ── Tool execution-boundary budget ──────────────────────────────────────────
|
|
81
|
+
/**
|
|
82
|
+
* Marker placed on a structured tool result when the execution-boundary budget
|
|
83
|
+
* blocked the call. The underlying implementation never ran, so callers (goal
|
|
84
|
+
* observers, telemetry) must not treat it as a real tool failure with side
|
|
85
|
+
* effects (RH-003).
|
|
86
|
+
*/
|
|
87
|
+
const TOOL_BUDGET_BLOCKED = '__hazeToolBudgetBlocked';
|
|
88
|
+
export function createToolExecutionBudget() {
|
|
89
|
+
return { started: 0, exceeded: false };
|
|
90
|
+
}
|
|
91
|
+
/** True when a tool result is the structured "budget blocked" placeholder. */
|
|
92
|
+
export function isToolBudgetBlocked(output) {
|
|
93
|
+
return typeof output === 'object' && output !== null && TOOL_BUDGET_BLOCKED in output;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wrap a tool set so each underlying `execute` checks-and-increments one or more
|
|
97
|
+
* shared budgets synchronously at the actual execution boundary. A model-emitted
|
|
98
|
+
* parallel batch enters `execute` sequentially on the JS event loop, so no more
|
|
99
|
+
* than the remaining budget can reach an underlying implementation even within
|
|
100
|
+
* one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
|
|
101
|
+
* and invoking execute.
|
|
102
|
+
*
|
|
103
|
+
* When any supplied limit is exhausted the call is blocked: every limit is
|
|
104
|
+
* marked exceeded, no underlying call runs, and a structured bounded failure is
|
|
105
|
+
* returned so the SDK completes the step and the next prepareStep forces
|
|
106
|
+
* text-only synthesis.
|
|
107
|
+
*/
|
|
108
|
+
export function withToolExecutionBudget(tools, ...limits) {
|
|
109
|
+
return Object.fromEntries(Object.entries(tools).map(([name, definition]) => {
|
|
110
|
+
if (typeof definition.execute !== 'function')
|
|
111
|
+
return [name, definition];
|
|
112
|
+
const execute = definition.execute;
|
|
113
|
+
return [name, {
|
|
114
|
+
...definition,
|
|
115
|
+
// Async so the wrapper always returns a thenable — outer wrappers (e.g.
|
|
116
|
+
// the tool deadline) assume `execute` yields a promise — while the
|
|
117
|
+
// check-and-increment below still runs synchronously at call time, so a
|
|
118
|
+
// model-emitted parallel batch cannot overshoot on the event loop.
|
|
119
|
+
execute: async (...args) => {
|
|
120
|
+
for (const { state, limit } of limits) {
|
|
121
|
+
if (state.started >= limit) {
|
|
122
|
+
for (const entry of limits)
|
|
123
|
+
entry.state.exceeded = true;
|
|
124
|
+
return { ok: false, [TOOL_BUDGET_BLOCKED]: true, error: 'Tool-call budget exhausted; execution was blocked before the underlying tool ran.' };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const { state } of limits)
|
|
128
|
+
state.started++;
|
|
129
|
+
return execute(...args);
|
|
130
|
+
},
|
|
131
|
+
}];
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { estimateModelMessageTokens } from './contextBudget.js';
|
|
2
2
|
import { workStatePrompt } from './workState.js';
|
|
3
|
-
import { COMPACTION_LLM_TRANSCRIPT_CHARS, COMPACTION_OLDER_CHARS } from '../limits
|
|
3
|
+
import { COMPACTION_LLM_TRANSCRIPT_CHARS, COMPACTION_OLDER_CHARS } from '../limits.js';
|
|
4
4
|
/**
|
|
5
5
|
* Decide which trailing messages survive compaction and which are folded into
|
|
6
6
|
* the summary. Returns undefined when there is nothing older to compact (the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ValidationKind } from '../../llm/toolResultTypes.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type TurnBudget } from './budgets.js';
|
|
3
3
|
import { type ValidationOutcome, type WorkTaskProgress } from './workState.js';
|
|
4
|
-
import type { RequestIntent } from '
|
|
4
|
+
import type { RequestIntent } from './goalPolicy.js';
|
|
5
5
|
/**
|
|
6
6
|
* Normalized reason a model stream finished. Derived from the AI SDK
|
|
7
7
|
* `finishReason` string so policy code never branches on raw provider strings.
|
|
@@ -37,6 +37,8 @@ export interface TurnExecutionState {
|
|
|
37
37
|
taskProgress: WorkTaskProgress | undefined;
|
|
38
38
|
/** Goal-continuation cycles issued this turn (bounded by the global budget + progress guard). */
|
|
39
39
|
goalContinuationsUsed: number;
|
|
40
|
+
/** Whether the single focused post-edit validation-repair slice was admitted. */
|
|
41
|
+
validationContinuationUsed: boolean;
|
|
40
42
|
/** Work/task evidence signature recorded when the latest goal continuation was issued. */
|
|
41
43
|
goalContinuationProgress: string | undefined;
|
|
42
44
|
/** Whether the single allowed no-progress corrective nudge has been consumed. */
|
|
@@ -130,8 +132,8 @@ export declare function hasRemainingRecoveryBudget(state: Pick<TurnExecutionStat
|
|
|
130
132
|
* recovery credit is both available and warranted).
|
|
131
133
|
*/
|
|
132
134
|
export declare function decideTerminalStatus(state: TurnExecutionState, evidence: CompletionEvidence, budgetExhausted: boolean): TurnStatus;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
type RecoveryAction = 'continue' | 'stop';
|
|
136
|
+
interface RecoverySlice {
|
|
135
137
|
steps: number;
|
|
136
138
|
toolCalls: number;
|
|
137
139
|
}
|
|
@@ -146,12 +148,6 @@ export interface RescueRecoveryDecision {
|
|
|
146
148
|
reason: string;
|
|
147
149
|
slice: RecoverySlice;
|
|
148
150
|
}
|
|
149
|
-
/** Length-continuation slice cap: four model steps / four tool calls (global). */
|
|
150
|
-
export declare const LENGTH_RECOVERY_SLICE: RecoverySlice;
|
|
151
|
-
/** Completion-rescue slice: one tool-bearing step (≤2 calls) + one synthesis step. */
|
|
152
|
-
export declare const RESCUE_SLICE: RecoverySlice;
|
|
153
|
-
/** Number of trailing tool-only slots reserved for the rescue slice. */
|
|
154
|
-
export declare const RESCUE_RESERVE = 1;
|
|
155
151
|
/** Tool-only boundary at which rescue becomes eligible (normal exploration stops here). */
|
|
156
152
|
export declare const RESCUE_BOUNDARY: number;
|
|
157
153
|
/**
|
|
@@ -177,8 +173,6 @@ export declare function rescueEligibleRequest(intent: RequestIntent): boolean;
|
|
|
177
173
|
* extends the global budget.
|
|
178
174
|
*/
|
|
179
175
|
export declare function decideRescue(state: TurnExecutionState, evidence: CompletionEvidence, budget: TurnBudget, isMutatingRequest: boolean): RescueRecoveryDecision;
|
|
180
|
-
/** Goal-continuation slice: real per-cycle work headroom, clamped to remaining global budget. */
|
|
181
|
-
export declare const GOAL_CONTINUATION_SLICE: RecoverySlice;
|
|
182
176
|
export interface GoalContinuationDecision {
|
|
183
177
|
action: RecoveryAction;
|
|
184
178
|
reason: string;
|
|
@@ -188,7 +182,6 @@ export interface GoalContinuationDecision {
|
|
|
188
182
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
189
183
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
190
184
|
export declare function goalContinuationRecoverable(readiness: CompletionReadiness): boolean;
|
|
191
|
-
export declare function isRecoverableFinishCause(finishCause: FinishCause | undefined): boolean;
|
|
192
185
|
/**
|
|
193
186
|
* Terminal classification of a finished attempt against the logical goal.
|
|
194
187
|
* - `goal-complete`: readiness satisfied, substantive answer, clean stop.
|
|
@@ -228,3 +221,4 @@ export declare function decideGoalContinuation(state: TurnExecutionState, eviden
|
|
|
228
221
|
* Used by recovery guards so a normal successful turn makes no extra model call.
|
|
229
222
|
*/
|
|
230
223
|
export declare function hasSatisfactoryTerminalOutcome(state: TurnExecutionState, evidence: CompletionEvidence): boolean;
|
|
224
|
+
export {};
|
|
@@ -26,6 +26,7 @@ export function createTurnExecutionState() {
|
|
|
26
26
|
intent: 'unknown',
|
|
27
27
|
taskProgress: undefined,
|
|
28
28
|
goalContinuationsUsed: 0,
|
|
29
|
+
validationContinuationUsed: false,
|
|
29
30
|
goalContinuationProgress: undefined,
|
|
30
31
|
goalContinuationCorrectiveUsed: false,
|
|
31
32
|
budgetBoundary: false,
|
|
@@ -130,11 +131,11 @@ export function decideTerminalStatus(state, evidence, budgetExhausted) {
|
|
|
130
131
|
return evidence.assistantText.trim().length > 0 ? 'complete' : 'failed';
|
|
131
132
|
}
|
|
132
133
|
/** Length-continuation slice cap: four model steps / four tool calls (global). */
|
|
133
|
-
|
|
134
|
+
const LENGTH_RECOVERY_SLICE = { steps: 4, toolCalls: 4 };
|
|
134
135
|
/** Completion-rescue slice: one tool-bearing step (≤2 calls) + one synthesis step. */
|
|
135
|
-
|
|
136
|
+
const RESCUE_SLICE = { steps: 2, toolCalls: 2 };
|
|
136
137
|
/** Number of trailing tool-only slots reserved for the rescue slice. */
|
|
137
|
-
|
|
138
|
+
const RESCUE_RESERVE = 1;
|
|
138
139
|
/** Tool-only boundary at which rescue becomes eligible (normal exploration stops here). */
|
|
139
140
|
export const RESCUE_BOUNDARY = MAIN_TOOL_ONLY_STEP_LIMIT - RESCUE_RESERVE;
|
|
140
141
|
/**
|
|
@@ -192,8 +193,9 @@ export function decideRescue(state, evidence, budget, isMutatingRequest) {
|
|
|
192
193
|
return stop('global budget exhausted');
|
|
193
194
|
return { action: 'continue', reason: 'near tool-only boundary with no substantive answer', slice: RESCUE_SLICE };
|
|
194
195
|
}
|
|
195
|
-
/**
|
|
196
|
-
|
|
196
|
+
/** Pending-task continuation keeps room for implementation; evidence repair is deliberately smaller. */
|
|
197
|
+
const GOAL_CONTINUATION_SLICE = { steps: 6, toolCalls: 12 };
|
|
198
|
+
const VALIDATION_CONTINUATION_SLICE = { steps: 3, toolCalls: 3 };
|
|
197
199
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
198
200
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
199
201
|
export function goalContinuationRecoverable(readiness) {
|
|
@@ -210,7 +212,7 @@ export function goalContinuationRecoverable(readiness) {
|
|
|
210
212
|
* `content-filter` stay hard: they are provider failures, not work states.
|
|
211
213
|
*/
|
|
212
214
|
const RECOVERABLE_FINISH_CAUSES = new Set(['stop', 'tool-calls', 'length', 'unknown']);
|
|
213
|
-
|
|
215
|
+
function isRecoverableFinishCause(finishCause) {
|
|
214
216
|
return finishCause != null && RECOVERABLE_FINISH_CAUSES.has(finishCause);
|
|
215
217
|
}
|
|
216
218
|
export function classifyTerminalOutcome(state, evidence) {
|
|
@@ -227,7 +229,11 @@ export function classifyTerminalOutcome(state, evidence) {
|
|
|
227
229
|
/** Compact signature of measurable work: mutations, validation outcome/kind, task counts. */
|
|
228
230
|
export function goalProgressSignature(state) {
|
|
229
231
|
const tasks = state.taskProgress;
|
|
230
|
-
|
|
232
|
+
// Mutation counters and task revisions are monotonic activity signals, not
|
|
233
|
+
// proof of net progress: edit→revert and rewriting identical task counts must
|
|
234
|
+
// not keep an unfinished goal alive. Track only whether work exists plus
|
|
235
|
+
// validation/task outcomes that can actually move toward readiness.
|
|
236
|
+
return JSON.stringify([state.mutationCount > 0, state.validationOutcome, state.validationKind ?? '', tasks ? [tasks.pending, tasks.inProgress, tasks.completed] : null]);
|
|
231
237
|
}
|
|
232
238
|
/**
|
|
233
239
|
* Record that a goal-continuation slice was issued. Progress since the previous
|
|
@@ -264,12 +270,15 @@ export function decideGoalContinuation(state, evidence, budget) {
|
|
|
264
270
|
return stop('completion readiness satisfied');
|
|
265
271
|
if (!goalContinuationRecoverable(readiness))
|
|
266
272
|
return stop(`readiness '${readiness}' is not autonomously recoverable`);
|
|
273
|
+
const validationRepair = readiness === 'validation_failed' || readiness === 'validation_stale' || readiness === 'validation_absent_after_mutation';
|
|
274
|
+
if (validationRepair && state.validationContinuationUsed)
|
|
275
|
+
return stop('focused validation-repair continuation already used');
|
|
267
276
|
if (!hasRemainingRecoveryBudget(state, budget))
|
|
268
277
|
return stop('global budget exhausted');
|
|
269
278
|
if (state.goalContinuationProgress != null && goalProgressSignature(state) === state.goalContinuationProgress && state.goalContinuationCorrectiveUsed) {
|
|
270
279
|
return stop('no measurable progress after the corrective nudge');
|
|
271
280
|
}
|
|
272
|
-
return { action: 'continue', reason: `premature final rejected: ${readiness}`, slice: GOAL_CONTINUATION_SLICE };
|
|
281
|
+
return { action: 'continue', reason: `premature final rejected: ${readiness}`, slice: validationRepair ? VALIDATION_CONTINUATION_SLICE : GOAL_CONTINUATION_SLICE };
|
|
273
282
|
}
|
|
274
283
|
/**
|
|
275
284
|
* Does the turn have a satisfactory terminal outcome that should stop recovery?
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
2
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
|
-
export declare const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
4
3
|
/**
|
|
5
4
|
* Conservative fallback context window for a hosted model with no metadata
|
|
6
5
|
* (RH-005). 128K is the floor for current capable hosted models (GPT-4o class,
|
|
@@ -13,8 +12,6 @@ export declare const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
|
13
12
|
export declare const FALLBACK_CONTEXT_WINDOW_TOKENS = 128000;
|
|
14
13
|
/** Fallback window for unknown models on local (localhost) inference servers. */
|
|
15
14
|
export declare const FALLBACK_LOCAL_CONTEXT_TOKENS = 32768;
|
|
16
|
-
/** Safety margin reserved below the computed budget to absorb estimate drift. */
|
|
17
|
-
export declare const CONTEXT_SAFETY_MARGIN_TOKENS = 1000;
|
|
18
15
|
/**
|
|
19
16
|
* Rough vision estimate for attached images: providers bill images by
|
|
20
17
|
* resolution, not by serialized bytes. ~750 bytes per token matches common
|
|
@@ -39,7 +36,6 @@ export interface ContextBreakdown {
|
|
|
39
36
|
syntheticControl: number;
|
|
40
37
|
}
|
|
41
38
|
export declare function estimateTextTokens(text: string): number;
|
|
42
|
-
export declare function estimateImagePartTokens(part: unknown): number;
|
|
43
39
|
export declare function estimateValueTokens(value: unknown): number;
|
|
44
40
|
export declare function estimateModelMessageTokens(message: ModelMessage): number;
|
|
45
41
|
/** Sum of per-message estimates for a history array, memoized per message object. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { imageFilePartBytes, isImageFilePart } from '../attachments/imageAttachments.js';
|
|
3
|
-
|
|
3
|
+
const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
4
4
|
/**
|
|
5
5
|
* Conservative fallback context window for a hosted model with no metadata
|
|
6
6
|
* (RH-005). 128K is the floor for current capable hosted models (GPT-4o class,
|
|
@@ -14,7 +14,7 @@ export const FALLBACK_CONTEXT_WINDOW_TOKENS = 128_000;
|
|
|
14
14
|
/** Fallback window for unknown models on local (localhost) inference servers. */
|
|
15
15
|
export const FALLBACK_LOCAL_CONTEXT_TOKENS = 32_768;
|
|
16
16
|
/** Safety margin reserved below the computed budget to absorb estimate drift. */
|
|
17
|
-
|
|
17
|
+
const CONTEXT_SAFETY_MARGIN_TOKENS = 1_000;
|
|
18
18
|
/**
|
|
19
19
|
* Rough vision estimate for attached images: providers bill images by
|
|
20
20
|
* resolution, not by serialized bytes. ~750 bytes per token matches common
|
|
@@ -25,7 +25,7 @@ export const IMAGE_BYTES_PER_TOKEN_ESTIMATE = 750;
|
|
|
25
25
|
export function estimateTextTokens(text) {
|
|
26
26
|
return Math.ceil(text.length / DEFAULT_CHARS_PER_TOKEN);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
function estimateImagePartTokens(part) {
|
|
29
29
|
if (!isImageFilePart(part))
|
|
30
30
|
return 0;
|
|
31
31
|
const bytes = imageFilePartBytes(part.data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TurnCompletionEvidence } from './completionController.js';
|
|
2
2
|
import type { EffectiveReasoning, ReasoningLevel } from './reasoningPolicy.js';
|
|
3
|
-
|
|
3
|
+
interface AgentStepUsage {
|
|
4
4
|
inputTokens: number;
|
|
5
5
|
outputTokens: number;
|
|
6
6
|
cacheReadTokens: number;
|
|
@@ -48,6 +48,7 @@ export type AgentEvent = {
|
|
|
48
48
|
finishReason: string;
|
|
49
49
|
toolCallCount: number;
|
|
50
50
|
usage: AgentStepUsage;
|
|
51
|
+
responseModel?: string;
|
|
51
52
|
at: string;
|
|
52
53
|
} | {
|
|
53
54
|
type: 'message_start';
|
|
@@ -123,6 +124,8 @@ export type AgentEvent = {
|
|
|
123
124
|
workPhase?: string;
|
|
124
125
|
/** Whether the stall rides the bounded model-retry pool. */
|
|
125
126
|
retryEligible?: boolean;
|
|
127
|
+
/** Size of the bounded model-retry pool in effect (`modelRetries` setting). */
|
|
128
|
+
maxRetries?: number;
|
|
126
129
|
at: string;
|
|
127
130
|
} | {
|
|
128
131
|
type: 'subagent_state';
|
|
@@ -142,3 +145,4 @@ export type AgentEventInput = AgentEvent extends infer Event ? Event extends {
|
|
|
142
145
|
at: string;
|
|
143
146
|
} ? Omit<Event, 'at'> : never : never;
|
|
144
147
|
export declare function agentEvent(event: AgentEventInput): AgentEvent;
|
|
148
|
+
export {};
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal policy: request-intent classification, session-goal state, and the
|
|
3
|
+
* model-facing completion/continuation control prompts (CR-006 home for the
|
|
4
|
+
* former `core/goal/` directory).
|
|
5
|
+
*
|
|
6
|
+
* Classifiers are hints, not hard authorization. Avoid preventing legitimate
|
|
7
|
+
* work solely because of a heuristic. Plan-only requests should not lead to
|
|
8
|
+
* source mutations unless the user asks for implementation.
|
|
9
|
+
*/
|
|
10
|
+
import { observeWorkToolEvent, type WorkState } from './workState.js';
|
|
11
|
+
export type RequestIntent = 'implement' | 'fix' | 'test' | 'review' | 'plan' | 'answer' | 'unknown';
|
|
12
|
+
export declare function isPlanOnlyRequest(value: string): boolean;
|
|
13
|
+
export declare function classifyRequestIntent(value: string): RequestIntent;
|
|
14
|
+
export type SessionGoal = WorkState;
|
|
15
|
+
export type GoalToolEvent = Parameters<typeof observeWorkToolEvent>[1];
|
|
16
|
+
export declare function createSessionGoal(request: string, now?: number): SessionGoal;
|
|
17
|
+
export declare function observeGoalToolEvent(goal: SessionGoal, event: GoalToolEvent, now?: number): WorkState;
|
|
18
|
+
export declare function formatGoalStatus(goal: SessionGoal): string;
|
|
1
19
|
export declare function toolLoopBudgetPrompt(): string;
|
|
2
20
|
export declare function repeatedToolCallPrompt(toolNames: string[]): string;
|
|
3
21
|
/**
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal policy: request-intent classification, session-goal state, and the
|
|
3
|
+
* model-facing completion/continuation control prompts (CR-006 home for the
|
|
4
|
+
* former `core/goal/` directory).
|
|
5
|
+
*
|
|
6
|
+
* Classifiers are hints, not hard authorization. Avoid preventing legitimate
|
|
7
|
+
* work solely because of a heuristic. Plan-only requests should not lead to
|
|
8
|
+
* source mutations unless the user asks for implementation.
|
|
9
|
+
*/
|
|
10
|
+
import { createWorkState, observeWorkToolEvent } from './workState.js';
|
|
11
|
+
export function isPlanOnlyRequest(value) {
|
|
12
|
+
return /\b(create|make|write|draft|outline)\s+(?:a\s+)?plan\b|\bplan\s+(?:for|to)\b/i.test(value) && !/\bimplement|execute|do\b/i.test(value);
|
|
13
|
+
}
|
|
14
|
+
export function classifyRequestIntent(value) {
|
|
15
|
+
if (isPlanOnlyRequest(value))
|
|
16
|
+
return 'plan';
|
|
17
|
+
if (/\b(review|audit|inspect|analy[sz]e|compare)\b/i.test(value))
|
|
18
|
+
return 'review';
|
|
19
|
+
if (/\b(fix|repair|resolve|debug)\b/i.test(value))
|
|
20
|
+
return 'fix';
|
|
21
|
+
if (/\b(run|verify|check|validate)\b/i.test(value) || /\btests?\b/i.test(value) && !/\b(add|create|write)\b/i.test(value))
|
|
22
|
+
return 'test';
|
|
23
|
+
if (/\b(add|create|write|implement|update|change|support|wire|document|docs|documentation)\b/i.test(value))
|
|
24
|
+
return 'implement';
|
|
25
|
+
if (/\b(what|why|how|explain|tell me)\b/i.test(value))
|
|
26
|
+
return 'answer';
|
|
27
|
+
return 'unknown';
|
|
28
|
+
}
|
|
29
|
+
function shortRequest(value) {
|
|
30
|
+
return value.replace(/\s+/g, ' ').trim().slice(0, 160) || 'current request';
|
|
31
|
+
}
|
|
32
|
+
export function createSessionGoal(request, now = Date.now()) {
|
|
33
|
+
const intent = classifyRequestIntent(request);
|
|
34
|
+
const successCriteria = intent === 'plan'
|
|
35
|
+
? ['Create or update the requested plan artifact/answer', 'Do not implement source changes unless asked']
|
|
36
|
+
: intent === 'test'
|
|
37
|
+
? ['Run the requested validation or closest relevant check', 'Report pass/fail accurately']
|
|
38
|
+
: intent === 'review'
|
|
39
|
+
? ['Inspect the relevant current project state', 'Return evidence-based findings with file paths']
|
|
40
|
+
: intent === 'answer'
|
|
41
|
+
? ['Answer the user using current project context when needed']
|
|
42
|
+
: ['Inspect the relevant files', 'Make the requested change when needed', 'Validate the change when practical', 'Summarize only current-task changes and validation'];
|
|
43
|
+
return createWorkState(request, intent, successCriteria, now);
|
|
44
|
+
}
|
|
45
|
+
export function observeGoalToolEvent(goal, event, now = Date.now()) {
|
|
46
|
+
return observeWorkToolEvent(goal, event, now);
|
|
47
|
+
}
|
|
48
|
+
export function formatGoalStatus(goal) {
|
|
49
|
+
const action = goal.phase === 'starting' ? 'starting'
|
|
50
|
+
: goal.phase === 'inspecting' ? 'inspecting'
|
|
51
|
+
: goal.phase === 'editing' ? `${goal.touchedFiles.length} file${goal.touchedFiles.length === 1 ? '' : 's'} changed`
|
|
52
|
+
: goal.phase === 'validating' ? `validation ${goal.validationCommands.at(-1)?.status ?? 'running'}`
|
|
53
|
+
: goal.phase === 'summarizing' ? 'summarizing'
|
|
54
|
+
: 'done';
|
|
55
|
+
return `Goal: ${shortRequest(goal.originalUserRequest)} · ${action}`;
|
|
56
|
+
}
|
|
57
|
+
// ── Completion/continuation control prompts ─────────────────────────────────
|
|
58
|
+
// Keep these small and reusable; prefer one shared helper over embedding
|
|
59
|
+
// near-identical model-facing control text in multiple loops. They are
|
|
60
|
+
// one-request nudges, never durable conversation history.
|
|
61
|
+
export function toolLoopBudgetPrompt() {
|
|
62
|
+
return 'Tool slice reached for this model step — tools are no longer callable in this turn. Stop attempting to describe or announce tool calls (e.g. "Let me install", "Now I\'ll run", "Let me X"); those phrases imply tool use you cannot perform. Answer once with a bounded progress checkpoint: what is done so far (changes + validation evidence) and, if work remains, the single next concrete unfinished action. haze continues the active goal automatically from that line — do not manufacture a completion summary and do not treat this as the end of the task. Do not repeat yourself, do not loop, do not emit XML/JSON tool-call syntax.';
|
|
63
|
+
}
|
|
64
|
+
export function repeatedToolCallPrompt(toolNames) {
|
|
65
|
+
const names = [...new Set(toolNames)].join(', ');
|
|
66
|
+
return `You already called ${names || 'a tool'} with identical input in this turn. Do not call the same tool again with the same arguments. Use the existing tool result already in the conversation, choose a different concrete tool/input if genuinely needed, or give the final/blocked status now.`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Ephemeral control appended to continue a response truncated by an
|
|
70
|
+
* output-length finish. Asks the model to resume from where it stopped and
|
|
71
|
+
* complete the requested artifact/answer. One-request nudge only.
|
|
72
|
+
*/
|
|
73
|
+
export function lengthContinuationPrompt() {
|
|
74
|
+
return 'Your previous response was truncated by the output-token limit before it finished. Continue exactly from where you stopped and complete the requested artifact or answer. Do not repeat what you already produced; finish the in-progress work and then stop.';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Ephemeral control for the single completion-rescue slice. Only mutation and
|
|
78
|
+
* validation tools are available; discovery must not be reopened. The model gets
|
|
79
|
+
* one tool-bearing step (at most two tool calls) to apply a concrete remaining
|
|
80
|
+
* deliverable you already discovered, then one final tool-free synthesis.
|
|
81
|
+
*/
|
|
82
|
+
export function completionRescuePrompt() {
|
|
83
|
+
return 'You reached the tool-boundary without a substantive final answer. Only edit/write and validation tools are available now. Use at most two tool calls to apply the single most important remaining concrete deliverable you already discovered (do not explore or read new files), then give the final status: current-task changes plus validation evidence, or a single short line stating the next unfinished action. Do not loop.';
|
|
84
|
+
}
|
|
85
|
+
export function malformedToolCallPrompt(toolName, chunkBytes) {
|
|
86
|
+
const chunkGuidance = toolName === 'writeFile'
|
|
87
|
+
? ` Keep content below ${chunkBytes} UTF-8 bytes per call: write the first chunk normally, then continue the same file with append=true.`
|
|
88
|
+
: '';
|
|
89
|
+
return `The ${toolName} call had invalid, malformed, or truncated JSON input and did not execute. Retry it now with valid smaller arguments; do not merely announce that you will retry.${chunkGuidance}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ephemeral control for a goal-continuation slice or a fresh continuation
|
|
93
|
+
* turn. The model's stop was rejected (or its physical turn hit a budget
|
|
94
|
+
* boundary) while structured evidence — declared task counts, post-edit
|
|
95
|
+
* validation — shows unfinished work; this nudge requires resuming concrete
|
|
96
|
+
* work rather than summarizing again. One-request nudge only.
|
|
97
|
+
*/
|
|
98
|
+
export function goalContinuationPrompt(reason, taskCounts) {
|
|
99
|
+
const taskLine = taskCounts
|
|
100
|
+
? ` The task list currently shows ${taskCounts.pending + taskCounts.inProgress} open item${taskCounts.pending + taskCounts.inProgress === 1 ? '' : 's'} of ${taskCounts.total}; update writeTasks as you complete them.`
|
|
101
|
+
: '';
|
|
102
|
+
const validationLine = reason.includes('validation')
|
|
103
|
+
? ' No recognized post-edit validation was recorded. Run one standard test/build command, directly execute the changed artifact as one unchained command, or call shell with purpose=validation for a custom assertion check.'
|
|
104
|
+
: '';
|
|
105
|
+
return `Continue the active goal: haze rejected stopping because structured evidence shows this turn is not complete (${reason}).${validationLine} Do not summarize again or restate what remains — resume the next concrete unfinished task now.${taskLine} If you declared a task list with writeTasks, its pending and in-progress items are commitments: complete them and update writeTasks at each meaningful phase change and at completion. After any further edits, run the smallest relevant validation and report its real outcome. Report a blocker only when it is a concrete external tool, permission, dependency, or environment failure; unfinished work is not a blocker.`;
|
|
106
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
|
-
export declare const SYNTHETIC_CONTROL_OPEN = "<haze_control>";
|
|
3
|
-
export declare function isSyntheticControlMessage(message: ModelMessage): boolean;
|
|
4
2
|
export declare function stripSyntheticControls(messages: ModelMessage[]): ModelMessage[];
|
|
5
3
|
export declare function withoutSystemMessages(messages: ModelMessage[]): ModelMessage[];
|
|
6
4
|
export declare function withSyntheticControl(messages: ModelMessage[], control: string): ModelMessage[];
|
|
5
|
+
/** Drop only a trailing text-only assistant final that completion policy rejected. */
|
|
6
|
+
export declare function withoutRejectedAssistantFinal(messages: ModelMessage[]): ModelMessage[];
|
|
7
7
|
export declare function compactToolHistory(messages: ModelMessage[], options?: {
|
|
8
8
|
keepRecentResults?: number;
|
|
9
9
|
minResultTokens?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { estimateValueTokens } from './contextBudget.js';
|
|
2
2
|
import { isFailedToolOutput } from './toolResults.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const SYNTHETIC_CONTROL_OPEN = '<haze_control>';
|
|
4
|
+
function isSyntheticControlMessage(message) {
|
|
5
5
|
return message.role === 'user'
|
|
6
6
|
&& typeof message.content === 'string'
|
|
7
7
|
&& message.content.startsWith(SYNTHETIC_CONTROL_OPEN);
|
|
@@ -28,6 +28,18 @@ export function withSyntheticControl(messages, control) {
|
|
|
28
28
|
{ role: 'user', content: `${SYNTHETIC_CONTROL_OPEN}\n${control}\n</haze_control>` },
|
|
29
29
|
];
|
|
30
30
|
}
|
|
31
|
+
/** Drop only a trailing text-only assistant final that completion policy rejected. */
|
|
32
|
+
export function withoutRejectedAssistantFinal(messages) {
|
|
33
|
+
const last = messages.at(-1);
|
|
34
|
+
if (!last || last.role !== 'assistant')
|
|
35
|
+
return messages;
|
|
36
|
+
if (typeof last.content === 'string')
|
|
37
|
+
return messages.slice(0, -1);
|
|
38
|
+
if (!Array.isArray(last.content))
|
|
39
|
+
return messages;
|
|
40
|
+
const hasToolCall = last.content.some(part => typeof part === 'object' && part != null && part.type === 'tool-call');
|
|
41
|
+
return hasToolCall ? messages : messages.slice(0, -1);
|
|
42
|
+
}
|
|
31
43
|
function resultValue(output) {
|
|
32
44
|
return typeof output === 'object' && output != null && 'value' in output
|
|
33
45
|
? output.value
|
|
@@ -91,7 +103,7 @@ function compactResultOutput(output, toolName) {
|
|
|
91
103
|
return { ...typed, value: `[Older successful ${toolName} result omitted from active context.]` };
|
|
92
104
|
return output;
|
|
93
105
|
}
|
|
94
|
-
const COMPACTABLE_INPUT_TOOLS = new Set(['writeFile', 'editFile', 'replaceLines', '
|
|
106
|
+
const COMPACTABLE_INPUT_TOOLS = new Set(['writeFile', 'editFile', 'replaceLines', 'shell']);
|
|
95
107
|
const BASH_COMMAND_TRUNCATE_THRESHOLD = 200;
|
|
96
108
|
const BASH_COMMAND_KEEP_CHARS = 150;
|
|
97
109
|
function compactToolCallInput(input, toolName) {
|
|
@@ -130,7 +142,7 @@ function compactToolCallInput(input, toolName) {
|
|
|
130
142
|
content: `[Compacted: original ${bytes} bytes. Use readFile on "${path}" to inspect.]`,
|
|
131
143
|
};
|
|
132
144
|
}
|
|
133
|
-
if (toolName === '
|
|
145
|
+
if (toolName === 'shell' && typeof source.command === 'string' && source.command.length > BASH_COMMAND_TRUNCATE_THRESHOLD) {
|
|
134
146
|
const total = source.command.length;
|
|
135
147
|
const truncated = source.command.slice(0, BASH_COMMAND_KEEP_CHARS).replace(/\s+/g, ' ').trim();
|
|
136
148
|
return {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Capabilities describe what a tool *can do* so turn-policy code can reason
|
|
5
5
|
* about a turn without hard-coding tool names in every decision site. They are
|
|
6
6
|
* metadata for policy/observability, never an execution gate (mirroring the
|
|
7
|
-
*
|
|
8
|
-
* runtime (e.g. a `
|
|
7
|
+
* shell-classifier contract): the actual effect of a call is still determined at
|
|
8
|
+
* runtime (e.g. a `shell` call is only validation when its command is a
|
|
9
9
|
* classifier-confirmed validation command).
|
|
10
10
|
*
|
|
11
11
|
* Kept provider/UI-agnostic (no `ai`/Ink imports) so it is unit-testable in
|