@denizokcu/haze 0.9.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 +133 -17
- package/README.md +164 -68
- 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 +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +46 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +92 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- 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 +67 -0
- package/dist/cli/chat/sessionLifecycle.js +205 -0
- package/dist/cli/chat/sessionRecorder.js +80 -14
- package/dist/cli/chat/startupInfo.js +11 -4
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +744 -0
- package/dist/cli/commands/chat.d.ts +6 -0
- package/dist/cli/commands/chat.js +373 -790
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +5 -2
- package/dist/cli/commands/commands.js +22 -18
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +35 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +10 -2
- package/dist/cli/commands/providerWizard.js +50 -4
- package/dist/cli/commands/runCommand.d.ts +4 -0
- package/dist/cli/commands/runCommand.js +142 -16
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- 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/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -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 +31 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
- 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/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +82 -3
- package/dist/cli/commands/streaming.js +528 -91
- package/dist/cli/commands/wizardActions.d.ts +7 -0
- package/dist/cli/commands/wizardActions.js +7 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +64 -14
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +82 -22
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +71 -0
- package/dist/config/modelDiscovery.js +214 -0
- 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 +49 -5
- package/dist/config/providerPresets.js +573 -73
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +9 -0
- package/dist/config/settings.d.ts +58 -0
- package/dist/config/settings.js +38 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +36 -0
- package/dist/core/agent/budgets.js +44 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +108 -19
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +46 -0
- package/dist/core/agent/contextBudget.js +89 -7
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +86 -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 +13 -0
- package/dist/core/agent/toolOutputStore.js +27 -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 +76 -1
- package/dist/core/agent/workState.js +120 -13
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- 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/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +7 -0
- package/dist/core/limits/byteBudgets.js +7 -0
- package/dist/core/limits/textBudgets.d.ts +25 -0
- package/dist/core/limits/textBudgets.js +25 -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.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +195 -0
- package/dist/core/process/runBoundedProcess.d.ts +9 -0
- package/dist/core/process/runBoundedProcess.js +74 -29
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +74 -0
- package/dist/core/session/sessionStore.js +268 -18
- package/dist/core/subagent/contracts.d.ts +120 -0
- package/dist/core/subagent/contracts.js +55 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
- package/dist/core/subagent/subagentCoordinator.js +164 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +208 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +36 -29
- package/dist/llm/client.js +102 -33
- package/dist/llm/hazeTools.d.ts +2559 -150
- package/dist/llm/hazeTools.js +119 -31
- package/dist/llm/lsp.d.ts +26 -4
- package/dist/llm/lsp.js +90 -14
- 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 +25 -1
- package/dist/llm/requestContext.js +51 -8
- package/dist/llm/systemPrompt.d.ts +15 -1
- package/dist/llm/systemPrompt.js +24 -8
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +906 -32
- package/dist/llm/tools/bashTool.js +30 -4
- 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 +42 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +6 -4
- package/dist/llm/tools/fileToolShared.js +18 -23
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -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 +9 -1
- package/dist/llm/tools/toolContext.js +83 -43
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +66 -86
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -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 +12 -2
- package/dist/ui/components/TextInput.js +80 -8
- 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/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +9 -1
- package/dist/utils/fs.js +87 -29
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +22 -0
- 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,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,20 +37,75 @@ 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
|
+
};
|
|
71
|
+
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
33
72
|
blockers: string[];
|
|
34
73
|
pending: string[];
|
|
35
74
|
nextAction?: string;
|
|
36
75
|
status: WorkStatus;
|
|
37
76
|
phase: WorkPhase;
|
|
38
|
-
blocker?: string;
|
|
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;
|
|
@@ -1,4 +1,66 @@
|
|
|
1
|
+
import { isValidationSummary } from '../../llm/toolResultTypes.js';
|
|
1
2
|
import { toolInputField, toolOutputOk } from './toolResults.js';
|
|
3
|
+
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
4
|
+
export function intentExpectsValidation(intent) {
|
|
5
|
+
return intent === 'implement' || intent === 'fix' || intent === 'test';
|
|
6
|
+
}
|
|
7
|
+
/** Upper bound for parsed task counts; anything larger is treated as malformed. */
|
|
8
|
+
const TASK_COUNT_LIMIT = 10_000;
|
|
9
|
+
function boundedTaskCount(value) {
|
|
10
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= TASK_COUNT_LIMIT)
|
|
11
|
+
return value;
|
|
12
|
+
if (typeof value === 'string' && /^(0|[1-9]\d{0,4})$/.test(value))
|
|
13
|
+
return Number(value);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extract bounded task counts from a successful `writeTasks` structured result.
|
|
18
|
+
* Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
|
|
19
|
+
* never titles or raw output. A non-empty list without a fully valid counts
|
|
20
|
+
* breakdown is ignored (rather than guessed) so partial shapes stay inert.
|
|
21
|
+
*/
|
|
22
|
+
export function taskProgressFromOutput(output, revision) {
|
|
23
|
+
if (typeof output !== 'object' || output == null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const candidate = output;
|
|
26
|
+
if (candidate.ok !== true)
|
|
27
|
+
return undefined;
|
|
28
|
+
const total = boundedTaskCount(candidate.taskCount);
|
|
29
|
+
if (total === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (total === 0)
|
|
32
|
+
return { total: 0, pending: 0, inProgress: 0, completed: 0, revision };
|
|
33
|
+
if (typeof candidate.counts !== 'object' || candidate.counts === null)
|
|
34
|
+
return undefined;
|
|
35
|
+
const counts = candidate.counts;
|
|
36
|
+
const pending = boundedTaskCount(counts.pending);
|
|
37
|
+
const inProgress = boundedTaskCount(counts.in_progress);
|
|
38
|
+
const completed = boundedTaskCount(counts.completed);
|
|
39
|
+
if (pending === undefined || inProgress === undefined || completed === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
return { total, pending, inProgress, completed, revision };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Seed a fresh per-turn work state with cumulative evidence from earlier
|
|
45
|
+
* physical turns of the same logical goal, so a new turn cannot complete while
|
|
46
|
+
* previously-declared tasks remain or previously-made edits still lack fresh
|
|
47
|
+
* validation. Seq baselines keep `deriveValidationOutcome` truthful across the
|
|
48
|
+
* boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
|
|
49
|
+
* carried `passed`/`failed` outcome stands until this turn mutates or validates.
|
|
50
|
+
*/
|
|
51
|
+
export function seedCarriedGoalEvidence(state, carried) {
|
|
52
|
+
if (carried.taskProgress && carried.taskProgress.total > 0) {
|
|
53
|
+
state.taskProgress = { ...carried.taskProgress, revision: 1 };
|
|
54
|
+
}
|
|
55
|
+
if (carried.mutationCount > 0) {
|
|
56
|
+
state.mutationCount = carried.mutationCount;
|
|
57
|
+
state.mutationSeq = 1;
|
|
58
|
+
}
|
|
59
|
+
if (carried.validationOutcome === 'passed' || carried.validationOutcome === 'failed') {
|
|
60
|
+
state.validationSeq = 1;
|
|
61
|
+
state.carriedValidation = carried.validationOutcome === 'passed' ? { status: 'passed' } : { status: 'failed' };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
2
64
|
function upsertFile(state, path, action, note) {
|
|
3
65
|
const existing = state.files.find(file => file.path === path);
|
|
4
66
|
if (existing) {
|
|
@@ -25,18 +87,25 @@ function outputSummary(output) {
|
|
|
25
87
|
return `exit ${String(output.code)}`;
|
|
26
88
|
return '';
|
|
27
89
|
}
|
|
28
|
-
function upsertValidation(state, command, status, summary) {
|
|
90
|
+
function upsertValidation(state, command, status, summary, kind) {
|
|
29
91
|
const existing = state.validations.find(validation => validation.command === command);
|
|
30
92
|
if (existing)
|
|
31
|
-
Object.assign(existing, { status, summary });
|
|
93
|
+
Object.assign(existing, { status, summary, ...(kind ? { kind } : {}) });
|
|
32
94
|
else
|
|
33
|
-
state.validations.push({ command, status, summary });
|
|
95
|
+
state.validations.push({ command, status, summary, ...(kind ? { kind } : {}) });
|
|
34
96
|
const existingCommand = state.validationCommands.find(item => item.command === command);
|
|
35
97
|
if (existingCommand)
|
|
36
98
|
existingCommand.status = status;
|
|
37
99
|
else
|
|
38
100
|
state.validationCommands.push({ command, status });
|
|
39
101
|
}
|
|
102
|
+
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
103
|
+
export function validationSummaryFromOutput(output) {
|
|
104
|
+
if (typeof output !== 'object' || output == null)
|
|
105
|
+
return undefined;
|
|
106
|
+
const candidate = output.validationSummary;
|
|
107
|
+
return isValidationSummary(candidate) ? candidate : undefined;
|
|
108
|
+
}
|
|
40
109
|
export function createWorkState(goal, intent, successCriteria, now = Date.now()) {
|
|
41
110
|
return {
|
|
42
111
|
id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
|
|
@@ -51,6 +120,9 @@ export function createWorkState(goal, intent, successCriteria, now = Date.now())
|
|
|
51
120
|
touchedFiles: [],
|
|
52
121
|
validations: [],
|
|
53
122
|
validationCommands: [],
|
|
123
|
+
mutationCount: 0,
|
|
124
|
+
mutationSeq: 0,
|
|
125
|
+
validationSeq: 0,
|
|
54
126
|
blockers: [],
|
|
55
127
|
pending: [],
|
|
56
128
|
status: 'active',
|
|
@@ -64,6 +136,9 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
64
136
|
return state;
|
|
65
137
|
const ok = toolOutputOk(event.output, event.success);
|
|
66
138
|
const path = toolInputField(event.input, 'path');
|
|
139
|
+
// Monotonic turn-wide clock. mutationSeq/validationSeq snapshot this value so
|
|
140
|
+
// a validation that predates the latest mutation can be marked stale.
|
|
141
|
+
const seq = state.revision + 1;
|
|
67
142
|
if (ok && path && ['listFiles', 'readFile', 'grep'].includes(event.toolName)) {
|
|
68
143
|
if (event.toolName === 'readFile')
|
|
69
144
|
upsertFile(state, path, 'read');
|
|
@@ -77,32 +152,64 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
77
152
|
state.phase = 'editing';
|
|
78
153
|
state.lastProgressAt = now;
|
|
79
154
|
state.blockers = state.blockers.filter(blocker => !blocker.includes(path));
|
|
80
|
-
|
|
81
|
-
|
|
155
|
+
state.mutationCount += 1;
|
|
156
|
+
state.mutationSeq = seq;
|
|
82
157
|
}
|
|
83
158
|
else {
|
|
84
|
-
state.blocker = `File edit failed for ${path}; recovery read is required before retry.`;
|
|
85
159
|
state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
|
|
86
160
|
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
87
161
|
}
|
|
88
162
|
}
|
|
163
|
+
// Only a classifier-confirmed bash command is a validation step. An arbitrary
|
|
164
|
+
// shell call (inspection, mkdir, echo) is process work, not validation; the
|
|
165
|
+
// bash tool embeds a `validationSummary` exactly when the classifier says so.
|
|
89
166
|
if (event.toolName === 'bash') {
|
|
90
167
|
const command = toolInputField(event.input, 'command');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
upsertValidation(state, command, status, summary);
|
|
168
|
+
const summary = validationSummaryFromOutput(event.output);
|
|
169
|
+
if (command && summary) {
|
|
170
|
+
const status = summary.status === 'passed' ? 'passed' : 'failed';
|
|
171
|
+
upsertValidation(state, command, status, summary.summaryText, summary.kind);
|
|
172
|
+
state.validationSeq = seq;
|
|
95
173
|
state.phase = 'validating';
|
|
96
174
|
state.lastProgressAt = now;
|
|
97
|
-
if (
|
|
98
|
-
state.blocker = `Validation command failed: ${command}`;
|
|
175
|
+
if (status === 'failed') {
|
|
99
176
|
state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
|
|
100
177
|
}
|
|
101
178
|
}
|
|
102
179
|
}
|
|
103
|
-
|
|
180
|
+
// Task-list coordination: a successful writeTasks result records bounded
|
|
181
|
+
// current-turn task counts as completion evidence. It is not a file mutation,
|
|
182
|
+
// and a failed call leaves prior evidence untouched.
|
|
183
|
+
if (ok && event.toolName === 'writeTasks') {
|
|
184
|
+
const progress = taskProgressFromOutput(event.output, seq);
|
|
185
|
+
if (progress) {
|
|
186
|
+
state.taskProgress = progress;
|
|
187
|
+
state.lastProgressAt = now;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
state.revision = seq;
|
|
104
191
|
return state;
|
|
105
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Derive the bounded validation outcome for completion evidence.
|
|
195
|
+
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
196
|
+
* ordering so a result that predates the latest mutation is `stale`.
|
|
197
|
+
*/
|
|
198
|
+
export function deriveValidationOutcome(state) {
|
|
199
|
+
const hasValidation = state.validationSeq > 0;
|
|
200
|
+
if (!hasValidation) {
|
|
201
|
+
return intentExpectsValidation(state.normalizedIntent) ? 'absent' : 'not_applicable';
|
|
202
|
+
}
|
|
203
|
+
// A validation is stale when a mutation happened after it. `mutationSeq === 0`
|
|
204
|
+
// means no mutation occurred (e.g. a pure test/run request), so the latest
|
|
205
|
+
// validation stands on its own. With no validation this turn, a carried
|
|
206
|
+
// outcome from an earlier physical turn of the same logical goal stands in.
|
|
207
|
+
const stale = state.mutationSeq > 0 && state.validationSeq < state.mutationSeq;
|
|
208
|
+
if (stale)
|
|
209
|
+
return 'stale';
|
|
210
|
+
const latest = state.validations.at(-1) ?? state.carriedValidation;
|
|
211
|
+
return latest?.status === 'passed' ? 'passed' : 'failed';
|
|
212
|
+
}
|
|
106
213
|
export function workStatePrompt(state) {
|
|
107
214
|
return `<work_state>\n${JSON.stringify(state)}\n</work_state>`;
|
|
108
215
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* User-attached images for one prompt (F03).
|
|
4
|
+
*
|
|
5
|
+
* Attachments are resolved from `@path` mentions typed by the user in the
|
|
6
|
+
* interactive chat: host-path allowed (workspace-relative, absolute, or `~/`),
|
|
7
|
+
* real-path deduped, extension-allowlisted, byte-bounded. The module is UI-
|
|
8
|
+
* and provider-agnostic (constitution VI): the capability gate takes the
|
|
9
|
+
* provider shape explicitly, never settings I/O.
|
|
10
|
+
*/
|
|
11
|
+
/** Extension allowlist → media type. Only these image kinds can be attached. */
|
|
12
|
+
export declare const IMAGE_MEDIA_TYPES: Readonly<Record<string, string>>;
|
|
13
|
+
export declare const IMAGE_EXTENSIONS: string[];
|
|
14
|
+
export interface ImageAttachment {
|
|
15
|
+
/** Display path: workspace-relative inside the project, `~/…` under the home directory, absolute otherwise. */
|
|
16
|
+
displayPath: string;
|
|
17
|
+
absolutePath: string;
|
|
18
|
+
fileName: string;
|
|
19
|
+
mediaType: string;
|
|
20
|
+
bytes: number;
|
|
21
|
+
data: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
export interface ResolvedImageAttachments {
|
|
24
|
+
/** Prompt text with attached mentions removed. */
|
|
25
|
+
text: string;
|
|
26
|
+
attachments: ImageAttachment[];
|
|
27
|
+
}
|
|
28
|
+
export interface PathMention {
|
|
29
|
+
/** Full match as it appears in the prompt (`@path` for explicit mentions, the path itself for bare). */
|
|
30
|
+
mention: string;
|
|
31
|
+
/** The path token after the `@`, or the bare path itself. */
|
|
32
|
+
token: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract path-like attachment candidates from prompt text. Two forms are
|
|
36
|
+
* recognised:
|
|
37
|
+
*
|
|
38
|
+
* - Explicit `@token` mentions: any path-like token after `@`. A candidate
|
|
39
|
+
* must contain a `.` or `/` so bare handles (`@here`) are skipped.
|
|
40
|
+
* - Bare paths: a token that ends in an allowlisted image extension AND
|
|
41
|
+
* contains `/`. The separator keeps prose like "I named it cat.png" out;
|
|
42
|
+
* the existence check during resolution is the final gate.
|
|
43
|
+
*
|
|
44
|
+
* Whether a candidate is really an attachment is decided during resolution.
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractPathMentions(text: string): PathMention[];
|
|
47
|
+
/**
|
|
48
|
+
* Resolve `@path` mentions into image attachments.
|
|
49
|
+
*
|
|
50
|
+
* - Mentions that do not resolve to an existing file stay literal
|
|
51
|
+
* prompt text (emails, handles, typos) — no error.
|
|
52
|
+
* - Existing paths with a non-image extension stay literal text too; the
|
|
53
|
+
* read-blessing resolver picks them up so the model can `readFile` them.
|
|
54
|
+
* - Existing image-extension paths that are not regular files (e.g. a
|
|
55
|
+
* directory named `foo.png`) fail loudly — that is a genuine attach-intent
|
|
56
|
+
* mismatch, not silent drop.
|
|
57
|
+
* - An `@` mention is an explicit user-typed reference, so any host path
|
|
58
|
+
* works: workspace-relative (including `../`), absolute, or `~/`. The real
|
|
59
|
+
* path dedupes aliases (symlinks, `..` segments) instead of confining
|
|
60
|
+
* reads; `.gitignore` is not enforced here (documented in AGENTS.md).
|
|
61
|
+
* - Size and per-message count are bounded by named limits; errors name them.
|
|
62
|
+
* - The same file mentioned twice is attached once; both mentions are stripped.
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveImageAttachments(text: string): Promise<ResolvedImageAttachments>;
|
|
65
|
+
/** Build the turn's user message: plain string without attachments, multipart with. */
|
|
66
|
+
export declare function userTurnMessage(text: string, attachments: readonly ImageAttachment[]): ModelMessage;
|
|
67
|
+
/** Minimal prompt text used when a message contains only images. */
|
|
68
|
+
export declare const IMAGE_ONLY_PROMPT_TEXT = "See the attached image.";
|
|
69
|
+
/** Minimal provider shape the capability gate needs (no settings I/O). */
|
|
70
|
+
export interface ImageCapableProviderLike {
|
|
71
|
+
name: string;
|
|
72
|
+
capabilities?: {
|
|
73
|
+
images?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Loud capability gate (constitution VII): images only go to providers the
|
|
78
|
+
* user explicitly marked image-capable. Returns undefined when the provider
|
|
79
|
+
* may receive image parts, otherwise an actionable error message.
|
|
80
|
+
*/
|
|
81
|
+
export declare function imageCapabilityError(provider: ImageCapableProviderLike | undefined): string | undefined;
|
|
82
|
+
/** Guard for AI SDK `file` parts carrying images, in any message role. */
|
|
83
|
+
export declare function isImageFilePart(value: unknown): value is {
|
|
84
|
+
type: 'file';
|
|
85
|
+
mediaType: string;
|
|
86
|
+
data?: unknown;
|
|
87
|
+
filename?: unknown;
|
|
88
|
+
};
|
|
89
|
+
/** Byte size of a file part's data without serializing it. */
|
|
90
|
+
export declare function imageFilePartBytes(data: unknown): number;
|