@denizokcu/haze 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -1
- package/README.md +66 -25
- 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/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -2
- package/dist/cli/chat/messages.js +216 -33
- package/dist/cli/chat/sessionLifecycle.d.ts +9 -0
- 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/wizardDispatch.js +111 -12
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +203 -101
- 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.js +2 -0
- 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 +37 -4
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +29 -0
- 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/turnOutcome.d.ts +17 -0
- package/dist/cli/commands/streaming/turnOutcome.js +27 -11
- package/dist/cli/commands/streaming.d.ts +70 -3
- package/dist/cli/commands/streaming.js +491 -77
- package/dist/cli/commands/wizardActions.d.ts +1 -0
- package/dist/cli/commands/wizardActions.js +1 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.js +5 -3
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/modelDiscovery.d.ts +51 -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 +36 -0
- package/dist/config/settings.js +9 -0
- package/dist/core/agent/budgets.d.ts +10 -0
- package/dist/core/agent/budgets.js +10 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +38 -0
- package/dist/core/agent/contextBudget.js +60 -7
- package/dist/core/agent/events.d.ts +74 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
- package/dist/core/agent/toolExecutionBudget.js +49 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +10 -10
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnBudget.d.ts +35 -0
- package/dist/core/agent/turnBudget.js +27 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +75 -0
- package/dist/core/agent/workState.js +120 -9
- package/dist/core/deadline.d.ts +33 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/goal/completionPolicy.d.ts +27 -0
- package/dist/core/goal/completionPolicy.js +37 -1
- package/dist/core/limits/byteBudgets.d.ts +2 -0
- package/dist/core/limits/byteBudgets.js +2 -0
- package/dist/core/limits/textBudgets.d.ts +2 -0
- package/dist/core/limits/textBudgets.js +2 -0
- package/dist/core/log/llmLog.js +7 -0
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.js +8 -7
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/session/sessionStore.d.ts +37 -0
- package/dist/core/session/sessionStore.js +215 -51
- package/dist/core/subagent/contracts.d.ts +4 -0
- package/dist/core/subagent/contracts.js +1 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +17 -37
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +82 -14
- package/dist/llm/hazeTools.d.ts +554 -80
- package/dist/llm/hazeTools.js +103 -24
- package/dist/llm/lsp.d.ts +24 -4
- package/dist/llm/lsp.js +72 -11
- package/dist/llm/lspTools.d.ts +2366 -0
- package/dist/llm/lspTools.js +87 -79
- package/dist/llm/openaiCodex.d.ts +3 -0
- package/dist/llm/openaiCodex.js +47 -0
- package/dist/llm/openaiCodexOAuth.d.ts +54 -0
- package/dist/llm/openaiCodexOAuth.js +214 -0
- package/dist/llm/requestContext.d.ts +3 -0
- package/dist/llm/requestContext.js +7 -4
- package/dist/llm/systemPrompt.d.ts +11 -0
- package/dist/llm/systemPrompt.js +12 -6
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +48 -16
- package/dist/llm/tools/bashTool.js +5 -0
- package/dist/llm/tools/editMatch.d.ts +14 -0
- package/dist/llm/tools/editMatch.js +72 -0
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fileToolShared.d.ts +4 -3
- package/dist/llm/tools/fileToolShared.js +16 -21
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/readRecovery.d.ts +10 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +61 -32
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +64 -97
- 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 +104 -0
- package/dist/utils/buildInfo.js +253 -0
- package/dist/utils/fs.d.ts +9 -0
- package/dist/utils/fs.js +87 -25
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +5 -1
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +24 -19
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static capability metadata for built-in tools.
|
|
3
|
+
*
|
|
4
|
+
* Capabilities describe what a tool *can do* so turn-policy code can reason
|
|
5
|
+
* about a turn without hard-coding tool names in every decision site. They are
|
|
6
|
+
* metadata for policy/observability, never an execution gate (mirroring the
|
|
7
|
+
* bash-classifier contract): the actual effect of a call is still determined at
|
|
8
|
+
* runtime (e.g. a `bash` call is only validation when its command is a
|
|
9
|
+
* classifier-confirmed validation command).
|
|
10
|
+
*
|
|
11
|
+
* Kept provider/UI-agnostic (no `ai`/Ink imports) so it is unit-testable in
|
|
12
|
+
* `tests/core/**` and reusable by the subagent flow.
|
|
13
|
+
*/
|
|
14
|
+
const CAPABILITY_MAP = {
|
|
15
|
+
// File discovery / inspection.
|
|
16
|
+
listFiles: ['discovery'],
|
|
17
|
+
grep: ['discovery'],
|
|
18
|
+
readFile: ['read'],
|
|
19
|
+
readToolOutput: ['read'],
|
|
20
|
+
fetch: ['read'],
|
|
21
|
+
// File mutation.
|
|
22
|
+
writeFile: ['mutate'],
|
|
23
|
+
editFile: ['mutate'],
|
|
24
|
+
replaceLines: ['mutate'],
|
|
25
|
+
// Process execution. A bash call becomes validation only when its command is
|
|
26
|
+
// a classifier-confirmed validation command (see work state); that runtime
|
|
27
|
+
// fact is tracked separately as a validation event, not as a static trait.
|
|
28
|
+
bash: ['process'],
|
|
29
|
+
process: ['process'],
|
|
30
|
+
// Coordination / durable state.
|
|
31
|
+
writeTasks: ['coordinate'],
|
|
32
|
+
subagent: ['coordinate'],
|
|
33
|
+
// LSP diagnostic reads.
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Capability set for a built-in tool name. Unknown/third-party tool names
|
|
37
|
+
* (MCP) return an empty set: their effects are not statically knowable, so
|
|
38
|
+
* policy code treats them conservatively.
|
|
39
|
+
*/
|
|
40
|
+
export function toolCapability(name) {
|
|
41
|
+
return CAPABILITY_MAP[name] ?? [];
|
|
42
|
+
}
|
|
43
|
+
export function hasCapability(name, capability) {
|
|
44
|
+
return toolCapability(name).includes(capability);
|
|
45
|
+
}
|
|
46
|
+
/** Tools whose successful call introduces a workspace mutation. */
|
|
47
|
+
export function isMutatingCapability(name) {
|
|
48
|
+
return hasCapability(name, 'mutate');
|
|
49
|
+
}
|
|
50
|
+
/** Tools that can act as a validation step (runtime-classifier dependent). */
|
|
51
|
+
export function isValidationCapable(name) {
|
|
52
|
+
return hasCapability(name, 'validate') || name === 'bash';
|
|
53
|
+
}
|
|
54
|
+
/** Read/discovery-only built-in tools (no mutation side effects). */
|
|
55
|
+
export function isReadOrDiscoveryCapability(name) {
|
|
56
|
+
const caps = toolCapability(name);
|
|
57
|
+
return caps.length > 0 && caps.every(capability => capability === 'read' || capability === 'discovery');
|
|
58
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ToolSet } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Marker placed on a structured tool result when the execution-boundary budget
|
|
4
|
+
* blocked the call. The underlying implementation never ran, so callers (goal
|
|
5
|
+
* observers, telemetry) must not treat it as a real tool failure with side
|
|
6
|
+
* effects (RH-003).
|
|
7
|
+
*/
|
|
8
|
+
export declare const TOOL_BUDGET_BLOCKED = "__hazeToolBudgetBlocked";
|
|
9
|
+
export interface ToolExecutionBudgetState {
|
|
10
|
+
/** Number of underlying executions that have actually started. */
|
|
11
|
+
started: number;
|
|
12
|
+
/** Set once a call was blocked so callers can force synthesis. */
|
|
13
|
+
exceeded: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function createToolExecutionBudget(): ToolExecutionBudgetState;
|
|
16
|
+
/** True when a tool result is the structured "budget blocked" placeholder. */
|
|
17
|
+
export declare function isToolBudgetBlocked(output: unknown): boolean;
|
|
18
|
+
export interface BudgetLimit {
|
|
19
|
+
state: ToolExecutionBudgetState;
|
|
20
|
+
limit: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wrap a tool set so each underlying `execute` checks-and-increments one or more
|
|
24
|
+
* shared budgets synchronously at the actual execution boundary. A model-emitted
|
|
25
|
+
* parallel batch enters `execute` sequentially on the JS event loop, so no more
|
|
26
|
+
* than the remaining budget can reach an underlying implementation even within
|
|
27
|
+
* one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
|
|
28
|
+
* and invoking execute.
|
|
29
|
+
*
|
|
30
|
+
* When any supplied limit is exhausted the call is blocked: every limit is
|
|
31
|
+
* marked exceeded, no underlying call runs, and a structured bounded failure is
|
|
32
|
+
* returned so the SDK completes the step and the next prepareStep forces
|
|
33
|
+
* text-only synthesis.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withToolExecutionBudget(tools: ToolSet, ...limits: BudgetLimit[]): ToolSet;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marker placed on a structured tool result when the execution-boundary budget
|
|
3
|
+
* blocked the call. The underlying implementation never ran, so callers (goal
|
|
4
|
+
* observers, telemetry) must not treat it as a real tool failure with side
|
|
5
|
+
* effects (RH-003).
|
|
6
|
+
*/
|
|
7
|
+
export const TOOL_BUDGET_BLOCKED = '__hazeToolBudgetBlocked';
|
|
8
|
+
export function createToolExecutionBudget() {
|
|
9
|
+
return { started: 0, exceeded: false };
|
|
10
|
+
}
|
|
11
|
+
/** True when a tool result is the structured "budget blocked" placeholder. */
|
|
12
|
+
export function isToolBudgetBlocked(output) {
|
|
13
|
+
return typeof output === 'object' && output !== null && TOOL_BUDGET_BLOCKED in output;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wrap a tool set so each underlying `execute` checks-and-increments one or more
|
|
17
|
+
* shared budgets synchronously at the actual execution boundary. A model-emitted
|
|
18
|
+
* parallel batch enters `execute` sequentially on the JS event loop, so no more
|
|
19
|
+
* than the remaining budget can reach an underlying implementation even within
|
|
20
|
+
* one batch (RH-003). Revisit if the AI SDK ever yields between queueing a batch
|
|
21
|
+
* and invoking execute.
|
|
22
|
+
*
|
|
23
|
+
* When any supplied limit is exhausted the call is blocked: every limit is
|
|
24
|
+
* marked exceeded, no underlying call runs, and a structured bounded failure is
|
|
25
|
+
* returned so the SDK completes the step and the next prepareStep forces
|
|
26
|
+
* text-only synthesis.
|
|
27
|
+
*/
|
|
28
|
+
export function withToolExecutionBudget(tools, ...limits) {
|
|
29
|
+
return Object.fromEntries(Object.entries(tools).map(([name, definition]) => {
|
|
30
|
+
if (typeof definition.execute !== 'function')
|
|
31
|
+
return [name, definition];
|
|
32
|
+
const execute = definition.execute;
|
|
33
|
+
return [name, {
|
|
34
|
+
...definition,
|
|
35
|
+
execute: (...args) => {
|
|
36
|
+
for (const { state, limit } of limits) {
|
|
37
|
+
if (state.started >= limit) {
|
|
38
|
+
for (const entry of limits)
|
|
39
|
+
entry.state.exceeded = true;
|
|
40
|
+
return { ok: false, [TOOL_BUDGET_BLOCKED]: true, error: 'Tool-call budget exhausted; execution was blocked before the underlying tool ran.' };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const { state } of limits)
|
|
44
|
+
state.started++;
|
|
45
|
+
return execute(...args);
|
|
46
|
+
},
|
|
47
|
+
}];
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
@@ -16,6 +16,14 @@ export declare function registerDynamicToolOutput(read: () => {
|
|
|
16
16
|
totalBytes: number;
|
|
17
17
|
}): string;
|
|
18
18
|
export declare function unregisterDynamicToolOutput(handle: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Store a tool output and return a handle for later retrieval.
|
|
21
|
+
*
|
|
22
|
+
* Two eviction pressures apply: count (`MAX_STORED_OUTPUTS`) and total bytes
|
|
23
|
+
* (`TOOL_OUTPUT_TOTAL_BYTES`). A single entry that alone exceeds the byte
|
|
24
|
+
* budget is evicted on the next `storeToolOutput` call, so callers should not
|
|
25
|
+
* assume a freshly-stored handle survives beyond the next store.
|
|
26
|
+
*/
|
|
19
27
|
export declare function storeToolOutput(content: string): string;
|
|
20
28
|
export declare function readToolOutput(handle: string, offset?: number, limit?: number, options?: {
|
|
21
29
|
query?: string;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import { TOOL_OUTPUT_ENTRY_BYTES, TOOL_OUTPUT_TOTAL_BYTES } from '../limits/byteBudgets.js';
|
|
3
|
+
import { truncateUtf8AtBytes } from '../../utils/utf8.js';
|
|
3
4
|
const outputs = new Map();
|
|
4
5
|
const dynamicOutputs = new Map();
|
|
5
6
|
const MAX_STORED_OUTPUTS = 100;
|
|
6
7
|
let storedBytes = 0;
|
|
7
|
-
function utf8Prefix(content, maxBytes) {
|
|
8
|
-
const bytes = Buffer.from(content, 'utf8');
|
|
9
|
-
if (bytes.length <= maxBytes)
|
|
10
|
-
return content;
|
|
11
|
-
let end = maxBytes;
|
|
12
|
-
while (end > 0 && (bytes[end] & 0xc0) === 0x80)
|
|
13
|
-
end--;
|
|
14
|
-
return bytes.subarray(0, end).toString('utf8');
|
|
15
|
-
}
|
|
16
8
|
export function registerDynamicToolOutput(read) {
|
|
17
9
|
const handle = `output-${crypto.randomBytes(8).toString('hex')}`;
|
|
18
10
|
dynamicOutputs.set(handle, read);
|
|
@@ -21,10 +13,18 @@ export function registerDynamicToolOutput(read) {
|
|
|
21
13
|
export function unregisterDynamicToolOutput(handle) {
|
|
22
14
|
dynamicOutputs.delete(handle);
|
|
23
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Store a tool output and return a handle for later retrieval.
|
|
18
|
+
*
|
|
19
|
+
* Two eviction pressures apply: count (`MAX_STORED_OUTPUTS`) and total bytes
|
|
20
|
+
* (`TOOL_OUTPUT_TOTAL_BYTES`). A single entry that alone exceeds the byte
|
|
21
|
+
* budget is evicted on the next `storeToolOutput` call, so callers should not
|
|
22
|
+
* assume a freshly-stored handle survives beyond the next store.
|
|
23
|
+
*/
|
|
24
24
|
export function storeToolOutput(content) {
|
|
25
25
|
const handle = `output-${crypto.randomBytes(8).toString('hex')}`;
|
|
26
26
|
const originalBytes = Buffer.byteLength(content, 'utf8');
|
|
27
|
-
const retained =
|
|
27
|
+
const retained = truncateUtf8AtBytes(content, TOOL_OUTPUT_ENTRY_BYTES).text;
|
|
28
28
|
const bytes = Buffer.byteLength(retained, 'utf8');
|
|
29
29
|
outputs.set(handle, { content: retained, bytes, originalBytes });
|
|
30
30
|
storedBytes += bytes;
|
|
@@ -19,11 +19,23 @@ export declare function isFailedToolOutput(output: unknown): boolean;
|
|
|
19
19
|
* counts as OK only when the call succeeded AND did not report `{ok: false}`.
|
|
20
20
|
*/
|
|
21
21
|
export declare function toolOutputOk(output: unknown, success: boolean): boolean;
|
|
22
|
+
export interface SafeToolFailureDetails {
|
|
23
|
+
errorCode?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract a bounded diagnostic from Haze's structured failure shape. Generic
|
|
28
|
+
* third-party tool outputs are intentionally ignored because their error fields
|
|
29
|
+
* may contain arbitrary remote content or secrets.
|
|
30
|
+
*/
|
|
31
|
+
export declare function safeToolFailureDetails(output: unknown): SafeToolFailureDetails;
|
|
22
32
|
/**
|
|
23
33
|
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
24
34
|
* for non-objects, missing keys, or non-string values.
|
|
25
35
|
*/
|
|
26
36
|
export declare function toolInputField(input: unknown, key: string): string | undefined;
|
|
37
|
+
/** A mutation failure needs a fresh file read only when it explicitly says so. */
|
|
38
|
+
export declare function requiresReadFileRecovery(value: unknown): boolean;
|
|
27
39
|
/**
|
|
28
40
|
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
29
41
|
* instead of re-running. Lets observers treat them as no-ops.
|
|
@@ -23,6 +23,39 @@ export function isFailedToolOutput(output) {
|
|
|
23
23
|
export function toolOutputOk(output, success) {
|
|
24
24
|
return success && !isFailedToolOutput(output);
|
|
25
25
|
}
|
|
26
|
+
const MAX_PUBLIC_TOOL_ERROR_CHARS = 500;
|
|
27
|
+
const SAFE_ERROR_CODE = /^[a-z0-9_-]{1,80}$/i;
|
|
28
|
+
function boundedSingleLine(value) {
|
|
29
|
+
const normalized = value.replace(/\p{Cc}+/gu, ' ').replace(/\s+/g, ' ').trim();
|
|
30
|
+
if (normalized.length <= MAX_PUBLIC_TOOL_ERROR_CHARS)
|
|
31
|
+
return normalized;
|
|
32
|
+
return `${normalized.slice(0, MAX_PUBLIC_TOOL_ERROR_CHARS - 1)}…`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract a bounded diagnostic from Haze's structured failure shape. Generic
|
|
36
|
+
* third-party tool outputs are intentionally ignored because their error fields
|
|
37
|
+
* may contain arbitrary remote content or secrets.
|
|
38
|
+
*/
|
|
39
|
+
export function safeToolFailureDetails(output) {
|
|
40
|
+
if (typeof output !== 'object' || output == null)
|
|
41
|
+
return {};
|
|
42
|
+
const value = output;
|
|
43
|
+
if (value.ok !== false)
|
|
44
|
+
return {};
|
|
45
|
+
const structuredHazeFailure = typeof value.toolName === 'string' && typeof value.recoverable === 'boolean';
|
|
46
|
+
const reasonCode = typeof value.reasonCode === 'string' && SAFE_ERROR_CODE.test(value.reasonCode) ? value.reasonCode : undefined;
|
|
47
|
+
const missingExecutable = typeof value.missingExecutable === 'string' && value.missingExecutable.trim() ? boundedSingleLine(value.missingExecutable) : undefined;
|
|
48
|
+
const errorCode = reasonCode
|
|
49
|
+
?? (missingExecutable ? 'missing_executable'
|
|
50
|
+
: value.timedOut === true ? 'command_timed_out'
|
|
51
|
+
: typeof value.exitCode === 'number' && value.exitCode !== 0 ? 'nonzero_exit'
|
|
52
|
+
: typeof value.signal === 'string' ? 'process_signal'
|
|
53
|
+
: undefined);
|
|
54
|
+
// Only the dedicated Haze failure shape guarantees that `error` is a bounded
|
|
55
|
+
// local diagnostic. Bash stderr and third-party fields may contain secrets.
|
|
56
|
+
const error = structuredHazeFailure && typeof value.error === 'string' ? boundedSingleLine(value.error) : undefined;
|
|
57
|
+
return { ...(errorCode ? { errorCode } : {}), ...(error ? { error } : {}), ...(missingExecutable ? { missingExecutable } : {}) };
|
|
58
|
+
}
|
|
26
59
|
/**
|
|
27
60
|
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
28
61
|
* for non-objects, missing keys, or non-string values.
|
|
@@ -33,6 +66,11 @@ export function toolInputField(input, key) {
|
|
|
33
66
|
const value = input[key];
|
|
34
67
|
return typeof value === 'string' ? value : undefined;
|
|
35
68
|
}
|
|
69
|
+
/** A mutation failure needs a fresh file read only when it explicitly says so. */
|
|
70
|
+
export function requiresReadFileRecovery(value) {
|
|
71
|
+
return typeof value === 'object' && value != null && 'recoveryTool' in value
|
|
72
|
+
&& value.recoveryTool === 'readFile';
|
|
73
|
+
}
|
|
36
74
|
/**
|
|
37
75
|
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
38
76
|
* instead of re-running. Lets observers treat them as no-ops.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn-wide budget envelope. Values are the existing global limits — recovery
|
|
3
|
+
* slices count against these and must never increase them.
|
|
4
|
+
*/
|
|
5
|
+
export interface TurnBudget {
|
|
6
|
+
/** Maximum completed model steps across the whole turn (incl. recovery). */
|
|
7
|
+
stepLimit: number;
|
|
8
|
+
/** Maximum completed tool calls across the whole turn (incl. recovery). */
|
|
9
|
+
toolCallLimit: number;
|
|
10
|
+
/** Maximum completed tool-only steps across the whole turn. */
|
|
11
|
+
toolOnlyStepLimit: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function mainTurnBudget(): TurnBudget;
|
|
14
|
+
/** Steps still available to the turn given usage so far (never negative). */
|
|
15
|
+
export declare function remainingSteps(used: number, budget: TurnBudget): number;
|
|
16
|
+
/** Tool calls still available to the turn given usage so far (never negative). */
|
|
17
|
+
export declare function remainingToolCalls(used: number, budget: TurnBudget): number;
|
|
18
|
+
/** True when adding `extra` tool calls would meet or exceed the call budget. */
|
|
19
|
+
export declare function wouldExceedToolCalls(used: number, extra: number, budget: TurnBudget): boolean;
|
|
20
|
+
/** A recovery slice can only run if at least one step and one tool call remain. */
|
|
21
|
+
export declare function hasUsableBudget(used: {
|
|
22
|
+
steps: number;
|
|
23
|
+
toolCalls: number;
|
|
24
|
+
}, budget: TurnBudget): boolean;
|
|
25
|
+
/** Clamp a requested slice size to what the turn budget actually allows. */
|
|
26
|
+
export declare function clampSlice(requested: {
|
|
27
|
+
steps: number;
|
|
28
|
+
toolCalls: number;
|
|
29
|
+
}, remaining: {
|
|
30
|
+
steps: number;
|
|
31
|
+
toolCalls: number;
|
|
32
|
+
}): {
|
|
33
|
+
steps: number;
|
|
34
|
+
toolCalls: number;
|
|
35
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MAIN_STEP_LIMIT, MAIN_TOOL_CALL_LIMIT, MAIN_TOOL_ONLY_STEP_LIMIT } from './budgets.js';
|
|
2
|
+
export function mainTurnBudget() {
|
|
3
|
+
return { stepLimit: MAIN_STEP_LIMIT, toolCallLimit: MAIN_TOOL_CALL_LIMIT, toolOnlyStepLimit: MAIN_TOOL_ONLY_STEP_LIMIT };
|
|
4
|
+
}
|
|
5
|
+
/** Steps still available to the turn given usage so far (never negative). */
|
|
6
|
+
export function remainingSteps(used, budget) {
|
|
7
|
+
return Math.max(0, budget.stepLimit - used);
|
|
8
|
+
}
|
|
9
|
+
/** Tool calls still available to the turn given usage so far (never negative). */
|
|
10
|
+
export function remainingToolCalls(used, budget) {
|
|
11
|
+
return Math.max(0, budget.toolCallLimit - used);
|
|
12
|
+
}
|
|
13
|
+
/** True when adding `extra` tool calls would meet or exceed the call budget. */
|
|
14
|
+
export function wouldExceedToolCalls(used, extra, budget) {
|
|
15
|
+
return used + extra >= budget.toolCallLimit;
|
|
16
|
+
}
|
|
17
|
+
/** A recovery slice can only run if at least one step and one tool call remain. */
|
|
18
|
+
export function hasUsableBudget(used, budget) {
|
|
19
|
+
return used.steps < budget.stepLimit && used.toolCalls < budget.toolCallLimit;
|
|
20
|
+
}
|
|
21
|
+
/** Clamp a requested slice size to what the turn budget actually allows. */
|
|
22
|
+
export function clampSlice(requested, remaining) {
|
|
23
|
+
return {
|
|
24
|
+
steps: Math.max(0, Math.min(requested.steps, remaining.steps)),
|
|
25
|
+
toolCalls: Math.max(0, Math.min(requested.toolCalls, remaining.toolCalls)),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -2,6 +2,17 @@ export declare function uniqueRepeatedToolNames(toolCalls: Array<{
|
|
|
2
2
|
toolName: string;
|
|
3
3
|
input: unknown;
|
|
4
4
|
}>): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Return tool names whose latest-step calls repeat an earlier identical call.
|
|
7
|
+
* Restricting only the immediately following step prevents one duplicate from
|
|
8
|
+
* disabling an entire tool category for the rest of the turn.
|
|
9
|
+
*/
|
|
10
|
+
export declare function latestRepeatedToolNames(steps: Array<{
|
|
11
|
+
toolCalls: Array<{
|
|
12
|
+
toolName: string;
|
|
13
|
+
input: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
}>): string[];
|
|
5
16
|
export declare function toolOnlyStepCount(steps: Array<{
|
|
6
17
|
toolCalls: unknown[];
|
|
7
18
|
text: string;
|
|
@@ -12,6 +12,25 @@ export function uniqueRepeatedToolNames(toolCalls) {
|
|
|
12
12
|
}
|
|
13
13
|
return [...repeated];
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Return tool names whose latest-step calls repeat an earlier identical call.
|
|
17
|
+
* Restricting only the immediately following step prevents one duplicate from
|
|
18
|
+
* disabling an entire tool category for the rest of the turn.
|
|
19
|
+
*/
|
|
20
|
+
export function latestRepeatedToolNames(steps) {
|
|
21
|
+
const latest = steps.at(-1);
|
|
22
|
+
if (!latest)
|
|
23
|
+
return [];
|
|
24
|
+
const seen = new Set(steps.slice(0, -1).flatMap(step => step.toolCalls).map(stableToolKey));
|
|
25
|
+
const repeated = new Set();
|
|
26
|
+
for (const toolCall of latest.toolCalls) {
|
|
27
|
+
const key = stableToolKey(toolCall);
|
|
28
|
+
if (seen.has(key))
|
|
29
|
+
repeated.add(toolCall.toolName);
|
|
30
|
+
seen.add(key);
|
|
31
|
+
}
|
|
32
|
+
return [...repeated];
|
|
33
|
+
}
|
|
15
34
|
export function toolOnlyStepCount(steps) {
|
|
16
35
|
let count = 0;
|
|
17
36
|
for (const step of [...steps].reverse()) {
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { RequestIntent } from '../goal/requestClassifier.js';
|
|
2
|
+
import { type ValidationKind, type ValidationSummary } from '../../llm/toolResultTypes.js';
|
|
2
3
|
export type WorkFileAction = 'read' | 'created' | 'modified';
|
|
3
4
|
export type WorkValidationStatus = 'pending' | 'passed' | 'failed';
|
|
4
5
|
export type WorkStatus = 'active' | 'needs-user' | 'blocked' | 'complete' | 'aborted';
|
|
5
6
|
export type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
|
|
7
|
+
/**
|
|
8
|
+
* Derived validation outcome for a turn, used as bounded completion evidence.
|
|
9
|
+
* - `passed`: a classifier-confirmed validation passed after the latest mutation.
|
|
10
|
+
* - `failed`: a validation failed and is the most recent result.
|
|
11
|
+
* - `stale`: a validation ran but predates the latest mutation (no longer trustworthy).
|
|
12
|
+
* - `absent`: validation was expected for this request but never ran.
|
|
13
|
+
* - `not_applicable`: the request does not call for validation (answer/review/plan).
|
|
14
|
+
*/
|
|
15
|
+
export type ValidationOutcome = 'passed' | 'failed' | 'stale' | 'absent' | 'not_applicable';
|
|
16
|
+
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
17
|
+
export declare function intentExpectsValidation(intent: RequestIntent): boolean;
|
|
6
18
|
export interface WorkState {
|
|
7
19
|
id: string;
|
|
8
20
|
goal: string;
|
|
@@ -25,11 +37,37 @@ export interface WorkState {
|
|
|
25
37
|
command: string;
|
|
26
38
|
status: Exclude<WorkValidationStatus, 'pending'>;
|
|
27
39
|
summary: string;
|
|
40
|
+
kind?: ValidationKind;
|
|
28
41
|
}>;
|
|
29
42
|
validationCommands: Array<{
|
|
30
43
|
command: string;
|
|
31
44
|
status: WorkValidationStatus;
|
|
32
45
|
}>;
|
|
46
|
+
/** Number of successful workspace mutations observed this turn. */
|
|
47
|
+
mutationCount: number;
|
|
48
|
+
/** Monotonic sequence number of the latest successful mutation (0 = none). */
|
|
49
|
+
mutationSeq: number;
|
|
50
|
+
/** Monotonic sequence number of the latest validation (0 = none). */
|
|
51
|
+
validationSeq: number;
|
|
52
|
+
/**
|
|
53
|
+
* Current-turn task-list evidence, recorded only from a successful `writeTasks`
|
|
54
|
+
* result. Counts only — never task titles or raw output — so malformed tool
|
|
55
|
+
* output can never fabricate or erase completion evidence. Absent when the
|
|
56
|
+
* turn never declared a task list (a stale workspace tasks.json from an
|
|
57
|
+
* earlier turn must not block completion).
|
|
58
|
+
*/
|
|
59
|
+
taskProgress?: WorkTaskProgress;
|
|
60
|
+
/**
|
|
61
|
+
* Validation evidence carried from earlier physical turns of the same
|
|
62
|
+
* logical goal (see the goal supervisor). Used by `deriveValidationOutcome`
|
|
63
|
+
* only while this turn itself has recorded no validation; a fresh
|
|
64
|
+
* validation this turn supersedes it. Bounded to status/kind — never a
|
|
65
|
+
* command or output.
|
|
66
|
+
*/
|
|
67
|
+
carriedValidation?: {
|
|
68
|
+
status: 'passed' | 'failed';
|
|
69
|
+
kind?: ValidationKind;
|
|
70
|
+
};
|
|
33
71
|
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
34
72
|
blockers: string[];
|
|
35
73
|
pending: string[];
|
|
@@ -39,6 +77,35 @@ export interface WorkState {
|
|
|
39
77
|
lastProgressAt: number;
|
|
40
78
|
revision: number;
|
|
41
79
|
}
|
|
80
|
+
/** Compact current-turn task-list evidence parsed from a successful `writeTasks` result. */
|
|
81
|
+
export interface WorkTaskProgress {
|
|
82
|
+
total: number;
|
|
83
|
+
pending: number;
|
|
84
|
+
inProgress: number;
|
|
85
|
+
completed: number;
|
|
86
|
+
/** WorkState revision when this snapshot was recorded. */
|
|
87
|
+
revision: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract bounded task counts from a successful `writeTasks` structured result.
|
|
91
|
+
* Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
|
|
92
|
+
* never titles or raw output. A non-empty list without a fully valid counts
|
|
93
|
+
* breakdown is ignored (rather than guessed) so partial shapes stay inert.
|
|
94
|
+
*/
|
|
95
|
+
export declare function taskProgressFromOutput(output: unknown, revision: number): WorkTaskProgress | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Seed a fresh per-turn work state with cumulative evidence from earlier
|
|
98
|
+
* physical turns of the same logical goal, so a new turn cannot complete while
|
|
99
|
+
* previously-declared tasks remain or previously-made edits still lack fresh
|
|
100
|
+
* validation. Seq baselines keep `deriveValidationOutcome` truthful across the
|
|
101
|
+
* boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
|
|
102
|
+
* carried `passed`/`failed` outcome stands until this turn mutates or validates.
|
|
103
|
+
*/
|
|
104
|
+
export declare function seedCarriedGoalEvidence(state: WorkState, carried: {
|
|
105
|
+
mutationCount: number;
|
|
106
|
+
validationOutcome: ValidationOutcome;
|
|
107
|
+
taskProgress?: WorkTaskProgress;
|
|
108
|
+
}): void;
|
|
42
109
|
export interface WorkToolEvent {
|
|
43
110
|
toolName: string;
|
|
44
111
|
input?: unknown;
|
|
@@ -46,6 +113,14 @@ export interface WorkToolEvent {
|
|
|
46
113
|
output?: unknown;
|
|
47
114
|
duplicateSkipped?: boolean;
|
|
48
115
|
}
|
|
116
|
+
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
117
|
+
export declare function validationSummaryFromOutput(output: unknown): ValidationSummary | undefined;
|
|
49
118
|
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
|
|
50
119
|
export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent, now?: number): WorkState;
|
|
120
|
+
/**
|
|
121
|
+
* Derive the bounded validation outcome for completion evidence.
|
|
122
|
+
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
123
|
+
* ordering so a result that predates the latest mutation is `stale`.
|
|
124
|
+
*/
|
|
125
|
+
export declare function deriveValidationOutcome(state: WorkState): ValidationOutcome;
|
|
51
126
|
export declare function workStatePrompt(state: WorkState): string;
|