@denizokcu/haze 1.1.0 → 1.1.1
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 +24 -1
- package/README.md +9 -5
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/busyIndicator.d.ts +11 -0
- package/dist/cli/chat/busyIndicator.js +34 -0
- package/dist/cli/chat/chatMetrics.d.ts +0 -1
- package/dist/cli/chat/chatMetrics.js +1 -7
- package/dist/cli/chat/followUpQueue.d.ts +11 -0
- package/dist/cli/chat/followUpQueue.js +38 -0
- package/dist/cli/chat/messages.d.ts +0 -22
- package/dist/cli/chat/messages.js +40 -85
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +6 -1
- package/dist/cli/chat/sessionRecorder.d.ts +2 -0
- package/dist/cli/chat/sessionRecorder.js +6 -0
- package/dist/cli/chat/startupSequence.d.ts +29 -0
- package/dist/cli/chat/startupSequence.js +59 -0
- package/dist/cli/chat/transcriptPartition.d.ts +23 -0
- package/dist/cli/chat/transcriptPartition.js +78 -0
- package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
- package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
- package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/lspHandlers.js +85 -0
- package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
- package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
- package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
- package/dist/cli/chat/wizard/providerHandlers.js +420 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
- package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
- package/dist/cli/chat/wizard/types.d.ts +63 -0
- package/dist/cli/chat/wizard/types.js +24 -0
- package/dist/cli/chat/wizard/uiState.d.ts +56 -0
- package/dist/cli/chat/wizard/uiState.js +15 -0
- package/dist/cli/chat/wizardDispatch.d.ts +11 -113
- package/dist/cli/chat/wizardDispatch.js +41 -815
- package/dist/cli/commands/chat.js +45 -108
- package/dist/cli/commands/formatters.d.ts +0 -3
- package/dist/cli/commands/formatters.js +0 -29
- package/dist/cli/commands/runCommand.d.ts +2 -0
- package/dist/cli/commands/runCommand.js +67 -4
- package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
- package/dist/cli/commands/streaming/assistantSegments.js +48 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -2
- package/dist/cli/commands/streaming/attemptOutcome.js +17 -7
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
- package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +17 -2
- package/dist/cli/commands/streaming/goalSupervisor.js +62 -12
- package/dist/cli/commands/streaming/prepareStep.d.ts +35 -0
- package/dist/cli/commands/streaming/prepareStep.js +100 -0
- package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
- package/dist/cli/commands/streaming/recoverySlices.js +29 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
- package/dist/cli/commands/streaming/stallRecovery.js +0 -4
- package/dist/cli/commands/streaming/streamLoop.js +9 -230
- package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
- package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +95 -0
- package/dist/cli/commands/streaming.d.ts +4 -1
- package/dist/cli/commands/streaming.js +6 -21
- package/dist/cli/index.js +3 -1
- package/dist/config/providerPresets.d.ts +7 -0
- package/dist/config/providerPresets.js +195 -391
- package/dist/core/agent/completionController.d.ts +14 -7
- package/dist/core/agent/completionController.js +12 -6
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/goalPolicy.d.ts +4 -3
- package/dist/core/agent/goalPolicy.js +9 -4
- package/dist/core/agent/workState.d.ts +25 -15
- package/dist/core/agent/workState.js +71 -43
- package/dist/core/session/sessionSlimming.js +8 -0
- package/dist/core/session/sessionStore.d.ts +61 -1
- package/dist/core/session/sessionStore.js +115 -6
- package/dist/llm/hazeTools.d.ts +64 -208
- package/dist/llm/tools/taskTool.d.ts +64 -208
- package/dist/llm/tools/taskTool.js +22 -10
- package/dist/ui/components/TextInput.js +6 -67
- package/dist/ui/components/useInputSuggestions.d.ts +27 -0
- package/dist/ui/components/useInputSuggestions.js +98 -0
- package/dist/ui/theme.d.ts +8 -8
- package/dist/ui/theme.js +11 -12
- package/dist/ui/themes/registry.d.ts +5 -0
- package/dist/ui/themes/registry.js +436 -0
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/format.js +45 -0
- package/package.json +1 -1
- package/dist/ui/themes/af-magic.d.ts +0 -7
- package/dist/ui/themes/af-magic.js +0 -25
- package/dist/ui/themes/agnoster.d.ts +0 -10
- package/dist/ui/themes/agnoster.js +0 -40
- package/dist/ui/themes/bira.d.ts +0 -10
- package/dist/ui/themes/bira.js +0 -28
- package/dist/ui/themes/bureau.d.ts +0 -10
- package/dist/ui/themes/bureau.js +0 -28
- package/dist/ui/themes/clean.d.ts +0 -9
- package/dist/ui/themes/clean.js +0 -27
- package/dist/ui/themes/cloud.d.ts +0 -6
- package/dist/ui/themes/cloud.js +0 -24
- package/dist/ui/themes/dst.d.ts +0 -10
- package/dist/ui/themes/dst.js +0 -28
- package/dist/ui/themes/fishy.d.ts +0 -7
- package/dist/ui/themes/fishy.js +0 -25
- package/dist/ui/themes/index.d.ts +0 -8
- package/dist/ui/themes/index.js +0 -36
- package/dist/ui/themes/light.d.ts +0 -3
- package/dist/ui/themes/light.js +0 -21
- package/dist/ui/themes/purple.d.ts +0 -7
- package/dist/ui/themes/purple.js +0 -26
- package/dist/ui/themes/robbyrussell.d.ts +0 -8
- package/dist/ui/themes/robbyrussell.js +0 -26
- package/dist/ui/themes/solarized-dark.d.ts +0 -16
- package/dist/ui/themes/solarized-dark.js +0 -44
- package/dist/ui/themes/solarized-light.d.ts +0 -12
- package/dist/ui/themes/solarized-light.js +0 -40
- package/dist/ui/themes/steeef.d.ts +0 -11
- package/dist/ui/themes/steeef.js +0 -29
|
@@ -43,6 +43,8 @@ export interface TurnExecutionState {
|
|
|
43
43
|
goalContinuationProgress: string | undefined;
|
|
44
44
|
/** Whether the single allowed no-progress corrective nudge has been consumed. */
|
|
45
45
|
goalContinuationCorrectiveUsed: boolean;
|
|
46
|
+
/** Opportunistic red→green state for fix intents. */
|
|
47
|
+
redPair: 'not-required' | 'missing' | 'satisfied' | undefined;
|
|
46
48
|
budgetBoundary: boolean;
|
|
47
49
|
aborted: boolean;
|
|
48
50
|
}
|
|
@@ -64,6 +66,8 @@ export interface TurnCompletionEvidence {
|
|
|
64
66
|
inProgress: number;
|
|
65
67
|
completed: number;
|
|
66
68
|
};
|
|
69
|
+
/** Opportunistic red→green state for fix intents. */
|
|
70
|
+
redPair?: 'not-required' | 'missing' | 'satisfied';
|
|
67
71
|
finishCause: FinishCause | undefined;
|
|
68
72
|
recoveryUsed: {
|
|
69
73
|
length: boolean;
|
|
@@ -86,9 +90,10 @@ export type TurnStatus = 'complete' | 'aborted' | 'failed';
|
|
|
86
90
|
* Reasoned completion readiness from structured current-turn evidence. A
|
|
87
91
|
* voluntary final is acceptable only when the declared work is actually done;
|
|
88
92
|
* prose alone is never evidence of completion (no semantic judge — task,
|
|
89
|
-
* mutation, validation, tool, and budget evidence is
|
|
93
|
+
* mutation, validation, red→green, tool, and budget evidence is
|
|
94
|
+
* authoritative).
|
|
90
95
|
*/
|
|
91
|
-
export type CompletionReadiness = 'ready' | 'pending_tasks' | 'validation_failed' | 'validation_stale' | 'validation_absent_after_mutation' | 'tool_failure' | 'unresolved_tool_input' | 'aborted';
|
|
96
|
+
export type CompletionReadiness = 'ready' | 'pending_tasks' | 'validation_failed' | 'validation_stale' | 'validation_absent_after_mutation' | 'red_check_not_green' | 'tool_failure' | 'unresolved_tool_input' | 'aborted';
|
|
92
97
|
/** Inputs `assessCompletionReadiness` needs; matches the TurnExecutionState projection. */
|
|
93
98
|
export interface CompletionReadinessInput {
|
|
94
99
|
aborted: boolean;
|
|
@@ -96,13 +101,16 @@ export interface CompletionReadinessInput {
|
|
|
96
101
|
mutationCount: number;
|
|
97
102
|
validationOutcome: ValidationOutcome;
|
|
98
103
|
taskProgress: WorkTaskProgress | undefined;
|
|
104
|
+
/** Red→green pair state; absent/not-required disables the gate. */
|
|
105
|
+
redPair?: 'not-required' | 'missing' | 'satisfied';
|
|
99
106
|
}
|
|
100
107
|
/**
|
|
101
108
|
* Pure completion-readiness assessment. Priority: abort, unresolved tool
|
|
102
|
-
* input, failed tool, declared task progress, then intent-sensitive
|
|
103
|
-
* policy (implement/fix/test turns with successful mutations
|
|
104
|
-
* passing validation; plan/review/answer turns never do)
|
|
105
|
-
*
|
|
109
|
+
* input, failed tool, declared task progress, then intent-sensitive
|
|
110
|
+
* validation policy (implement/fix/test turns with successful mutations
|
|
111
|
+
* require fresh passing validation; plan/review/answer turns never do), then
|
|
112
|
+
* the fix-intent red→green pair. A task list is enforced only when this turn
|
|
113
|
+
* declared one via a successful writeTasks call.
|
|
106
114
|
*/
|
|
107
115
|
export declare function assessCompletionReadiness(state: CompletionReadinessInput, evidence: Pick<CompletionEvidence, 'lastToolOk' | 'unresolvedToolInputError'>): CompletionReadiness;
|
|
108
116
|
/** Human-readable, safe (no commands/content) description of a readiness result. */
|
|
@@ -180,7 +188,6 @@ export interface GoalContinuationDecision {
|
|
|
180
188
|
slice: RecoverySlice;
|
|
181
189
|
}
|
|
182
190
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
183
|
-
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
184
191
|
export declare function goalContinuationRecoverable(readiness: CompletionReadiness): boolean;
|
|
185
192
|
/**
|
|
186
193
|
* Terminal classification of a finished attempt against the logical goal.
|
|
@@ -29,6 +29,7 @@ export function createTurnExecutionState() {
|
|
|
29
29
|
validationContinuationUsed: false,
|
|
30
30
|
goalContinuationProgress: undefined,
|
|
31
31
|
goalContinuationCorrectiveUsed: false,
|
|
32
|
+
redPair: undefined,
|
|
32
33
|
budgetBoundary: false,
|
|
33
34
|
aborted: false,
|
|
34
35
|
};
|
|
@@ -41,6 +42,7 @@ export function toCompletionEvidence(state) {
|
|
|
41
42
|
validationAfterMutation: state.validationAfterMutation,
|
|
42
43
|
mutationCount: state.mutationCount,
|
|
43
44
|
...(state.taskProgress ? { taskProgress: { total: state.taskProgress.total, pending: state.taskProgress.pending, inProgress: state.taskProgress.inProgress, completed: state.taskProgress.completed } } : {}),
|
|
45
|
+
...(state.redPair && state.redPair !== 'not-required' ? { redPair: state.redPair } : {}),
|
|
44
46
|
finishCause: state.finishCause,
|
|
45
47
|
recoveryUsed: { length: state.lengthCreditUsed, rescue: state.rescueUsed, goal: state.goalContinuationsUsed },
|
|
46
48
|
budgetBoundary: state.budgetBoundary,
|
|
@@ -48,10 +50,11 @@ export function toCompletionEvidence(state) {
|
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
52
|
* Pure completion-readiness assessment. Priority: abort, unresolved tool
|
|
51
|
-
* input, failed tool, declared task progress, then intent-sensitive
|
|
52
|
-
* policy (implement/fix/test turns with successful mutations
|
|
53
|
-
* passing validation; plan/review/answer turns never do)
|
|
54
|
-
*
|
|
53
|
+
* input, failed tool, declared task progress, then intent-sensitive
|
|
54
|
+
* validation policy (implement/fix/test turns with successful mutations
|
|
55
|
+
* require fresh passing validation; plan/review/answer turns never do), then
|
|
56
|
+
* the fix-intent red→green pair. A task list is enforced only when this turn
|
|
57
|
+
* declared one via a successful writeTasks call.
|
|
55
58
|
*/
|
|
56
59
|
export function assessCompletionReadiness(state, evidence) {
|
|
57
60
|
if (state.aborted)
|
|
@@ -70,6 +73,8 @@ export function assessCompletionReadiness(state, evidence) {
|
|
|
70
73
|
if (state.validationOutcome === 'absent' && state.mutationCount > 0)
|
|
71
74
|
return 'validation_absent_after_mutation';
|
|
72
75
|
}
|
|
76
|
+
if (state.intent === 'fix' && state.redPair === 'missing')
|
|
77
|
+
return 'red_check_not_green';
|
|
73
78
|
return 'ready';
|
|
74
79
|
}
|
|
75
80
|
/** Human-readable, safe (no commands/content) description of a readiness result. */
|
|
@@ -82,6 +87,7 @@ export function describeCompletionReadiness(readiness, taskProgress) {
|
|
|
82
87
|
case 'validation_failed': return 'the latest validation failed and remains unresolved';
|
|
83
88
|
case 'validation_stale': return 'edits landed after the latest validation';
|
|
84
89
|
case 'validation_absent_after_mutation': return 'edits landed without any relevant validation';
|
|
90
|
+
case 'red_check_not_green': return 'the captured pre-edit failing check has not passed after the fix';
|
|
85
91
|
case 'tool_failure': return 'the last tool call failed';
|
|
86
92
|
case 'unresolved_tool_input': return 'a tool call never executed because its input was invalid';
|
|
87
93
|
case 'aborted': return 'the turn was aborted';
|
|
@@ -197,12 +203,12 @@ export function decideRescue(state, evidence, budget, isMutatingRequest) {
|
|
|
197
203
|
const GOAL_CONTINUATION_SLICE = { steps: 6, toolCalls: 12 };
|
|
198
204
|
const VALIDATION_CONTINUATION_SLICE = { steps: 3, toolCalls: 3 };
|
|
199
205
|
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
200
|
-
/** Readiness reasons a bounded continuation can plausibly resolve with more work. */
|
|
201
206
|
export function goalContinuationRecoverable(readiness) {
|
|
202
207
|
return readiness === 'pending_tasks'
|
|
203
208
|
|| readiness === 'validation_failed'
|
|
204
209
|
|| readiness === 'validation_stale'
|
|
205
|
-
|| readiness === 'validation_absent_after_mutation'
|
|
210
|
+
|| readiness === 'validation_absent_after_mutation'
|
|
211
|
+
|| readiness === 'red_check_not_green';
|
|
206
212
|
}
|
|
207
213
|
/**
|
|
208
214
|
* Normal provider finishes that can still represent recoverable unfinished
|
|
@@ -27,6 +27,11 @@ export type AgentEvent = {
|
|
|
27
27
|
goalId: string;
|
|
28
28
|
cycle: number;
|
|
29
29
|
reason: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
at: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'goal_notice';
|
|
34
|
+
text: string;
|
|
30
35
|
at: string;
|
|
31
36
|
} | {
|
|
32
37
|
type: 'goal_end';
|
|
@@ -36,6 +41,13 @@ export type AgentEvent = {
|
|
|
36
41
|
cycles: number;
|
|
37
42
|
stopReason?: string;
|
|
38
43
|
evidence?: TurnCompletionEvidence;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'goal_resume';
|
|
46
|
+
goalId: string;
|
|
47
|
+
at: string;
|
|
48
|
+
relaunch: number;
|
|
49
|
+
stopReason: string;
|
|
50
|
+
reason: string;
|
|
39
51
|
} | {
|
|
40
52
|
type: 'step_start';
|
|
41
53
|
attempt: number;
|
|
@@ -36,12 +36,13 @@ export declare function malformedToolCallPrompt(toolName: string, chunkBytes: nu
|
|
|
36
36
|
* Ephemeral control for a goal-continuation slice or a fresh continuation
|
|
37
37
|
* turn. The model's stop was rejected (or its physical turn hit a budget
|
|
38
38
|
* boundary) while structured evidence — declared task counts, post-edit
|
|
39
|
-
* validation — shows unfinished work; this nudge requires
|
|
40
|
-
* work rather than summarizing
|
|
39
|
+
* validation, or red→green pairs — shows unfinished work; this nudge requires
|
|
40
|
+
* resuming concrete work rather than summarizing
|
|
41
|
+
* again. One-request nudge only.
|
|
41
42
|
*/
|
|
42
43
|
export declare function goalContinuationPrompt(reason: string, taskCounts?: {
|
|
43
44
|
total: number;
|
|
44
45
|
pending: number;
|
|
45
46
|
inProgress: number;
|
|
46
47
|
completed: number;
|
|
47
|
-
}): string;
|
|
48
|
+
}, detail?: string): string;
|
|
@@ -92,15 +92,20 @@ export function malformedToolCallPrompt(toolName, chunkBytes) {
|
|
|
92
92
|
* Ephemeral control for a goal-continuation slice or a fresh continuation
|
|
93
93
|
* turn. The model's stop was rejected (or its physical turn hit a budget
|
|
94
94
|
* boundary) while structured evidence — declared task counts, post-edit
|
|
95
|
-
* validation — shows unfinished work; this nudge requires
|
|
96
|
-
* work rather than summarizing
|
|
95
|
+
* validation, or red→green pairs — shows unfinished work; this nudge requires
|
|
96
|
+
* resuming concrete work rather than summarizing
|
|
97
|
+
* again. One-request nudge only.
|
|
97
98
|
*/
|
|
98
|
-
export function goalContinuationPrompt(reason, taskCounts) {
|
|
99
|
+
export function goalContinuationPrompt(reason, taskCounts, detail) {
|
|
99
100
|
const taskLine = taskCounts
|
|
100
101
|
? ` 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
|
: '';
|
|
102
103
|
const validationLine = reason.includes('validation')
|
|
103
104
|
? ' 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
|
: '';
|
|
105
|
-
|
|
106
|
+
const redLine = reason.includes('failing check')
|
|
107
|
+
? ' Rerun the same validation command that failed before the edit and resolve it; a different check does not close the captured red evidence.'
|
|
108
|
+
: '';
|
|
109
|
+
const detailLine = detail ? ` ${detail}` : '';
|
|
110
|
+
return `Continue the active goal: haze rejected stopping because structured evidence shows this turn is not complete (${reason}).${validationLine}${redLine}${detailLine} 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
111
|
}
|
|
@@ -15,6 +15,19 @@ type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summari
|
|
|
15
15
|
export type ValidationOutcome = 'passed' | 'failed' | 'stale' | 'absent' | 'not_applicable';
|
|
16
16
|
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
17
17
|
export declare function intentExpectsValidation(intent: RequestIntent): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a validation command into a matching key so a green run can be
|
|
20
|
+
* bound to the red repro it must supersede (P4). Whitespace-insensitive; a
|
|
21
|
+
* leading `time`/`env`/`nice` prefix and a trailing `--` separator are noise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validationCommandKey(command: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Opportunistic red→green state for fix intents: no failing repro is required,
|
|
26
|
+
* but when a pre-mutation validation did fail, that same check must pass after
|
|
27
|
+
* the fix. `missing` therefore means "captured red has no matching green", not
|
|
28
|
+
* "no red was captured".
|
|
29
|
+
*/
|
|
30
|
+
export declare function redPairStatus(state: Pick<WorkState, 'normalizedIntent' | 'mutationCount' | 'mutationSeq' | 'redEvidence' | 'validations'>): 'not-required' | 'missing' | 'satisfied';
|
|
18
31
|
export interface WorkState {
|
|
19
32
|
id: string;
|
|
20
33
|
goal: string;
|
|
@@ -37,6 +50,7 @@ export interface WorkState {
|
|
|
37
50
|
command: string;
|
|
38
51
|
status: Exclude<WorkValidationStatus, 'pending'>;
|
|
39
52
|
summary: string;
|
|
53
|
+
revision: number;
|
|
40
54
|
kind?: ValidationKind;
|
|
41
55
|
}>;
|
|
42
56
|
validationCommands: Array<{
|
|
@@ -68,6 +82,8 @@ export interface WorkState {
|
|
|
68
82
|
status: 'passed' | 'failed';
|
|
69
83
|
kind?: ValidationKind;
|
|
70
84
|
};
|
|
85
|
+
/** Captured pre-mutation failing repro for fix goals. Optional, but same-check green is required when present. */
|
|
86
|
+
redEvidence?: RedEvidence;
|
|
71
87
|
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
72
88
|
blockers: string[];
|
|
73
89
|
pending: string[];
|
|
@@ -77,6 +93,12 @@ export interface WorkState {
|
|
|
77
93
|
lastProgressAt: number;
|
|
78
94
|
revision: number;
|
|
79
95
|
}
|
|
96
|
+
/** Captured failing repro observed before the first mutation of a fix goal (P4). Safe metadata: command + status, never output bodies. */
|
|
97
|
+
export interface RedEvidence {
|
|
98
|
+
command: string;
|
|
99
|
+
commandKey: string;
|
|
100
|
+
summary: string;
|
|
101
|
+
}
|
|
80
102
|
/** Compact current-turn task-list evidence parsed from a successful `writeTasks` result. */
|
|
81
103
|
export interface WorkTaskProgress {
|
|
82
104
|
total: number;
|
|
@@ -86,25 +108,11 @@ export interface WorkTaskProgress {
|
|
|
86
108
|
/** WorkState revision when this snapshot was recorded. */
|
|
87
109
|
revision: number;
|
|
88
110
|
}
|
|
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
111
|
export declare function seedCarriedGoalEvidence(state: WorkState, carried: {
|
|
105
112
|
mutationCount: number;
|
|
106
113
|
validationOutcome: ValidationOutcome;
|
|
107
114
|
taskProgress?: WorkTaskProgress;
|
|
115
|
+
redEvidence?: RedEvidence;
|
|
108
116
|
}): void;
|
|
109
117
|
export interface WorkToolEvent {
|
|
110
118
|
toolName: string;
|
|
@@ -119,6 +127,8 @@ export declare function executedMutatedArtifact(command: string, state: WorkStat
|
|
|
119
127
|
export declare function validationSummaryFromOutput(output: unknown): ValidationSummary | undefined;
|
|
120
128
|
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
|
|
121
129
|
export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent, now?: number): WorkState;
|
|
130
|
+
/** Extract bounded task counts from a successful `writeTasks` structured result. */
|
|
131
|
+
export declare function taskProgressFromOutput(output: unknown, revision: number): WorkTaskProgress | undefined;
|
|
122
132
|
/**
|
|
123
133
|
* Derive the bounded validation outcome for completion evidence.
|
|
124
134
|
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
@@ -5,50 +5,36 @@ import { workspacePathKey } from '../../utils/path.js';
|
|
|
5
5
|
export function intentExpectsValidation(intent) {
|
|
6
6
|
return intent === 'implement' || intent === 'fix' || intent === 'test';
|
|
7
7
|
}
|
|
8
|
-
/** Upper bound for parsed task counts; anything larger is treated as malformed. */
|
|
9
|
-
const TASK_COUNT_LIMIT = 10_000;
|
|
10
|
-
function boundedTaskCount(value) {
|
|
11
|
-
if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= TASK_COUNT_LIMIT)
|
|
12
|
-
return value;
|
|
13
|
-
if (typeof value === 'string' && /^(0|[1-9]\d{0,4})$/.test(value))
|
|
14
|
-
return Number(value);
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
8
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* breakdown is ignored (rather than guessed) so partial shapes stay inert.
|
|
9
|
+
* Normalize a validation command into a matching key so a green run can be
|
|
10
|
+
* bound to the red repro it must supersede (P4). Whitespace-insensitive; a
|
|
11
|
+
* leading `time`/`env`/`nice` prefix and a trailing `--` separator are noise.
|
|
22
12
|
*/
|
|
23
|
-
export function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (total === undefined)
|
|
31
|
-
return undefined;
|
|
32
|
-
if (total === 0)
|
|
33
|
-
return { total: 0, pending: 0, inProgress: 0, completed: 0, revision };
|
|
34
|
-
if (typeof candidate.counts !== 'object' || candidate.counts === null)
|
|
35
|
-
return undefined;
|
|
36
|
-
const counts = candidate.counts;
|
|
37
|
-
const pending = boundedTaskCount(counts.pending);
|
|
38
|
-
const inProgress = boundedTaskCount(counts.in_progress);
|
|
39
|
-
const completed = boundedTaskCount(counts.completed);
|
|
40
|
-
if (pending === undefined || inProgress === undefined || completed === undefined)
|
|
41
|
-
return undefined;
|
|
42
|
-
return { total, pending, inProgress, completed, revision };
|
|
13
|
+
export function validationCommandKey(command) {
|
|
14
|
+
const words = command.replace(/\s+/g, ' ').trim().split(' ').filter(Boolean);
|
|
15
|
+
while (words.length > 1 && ['time', 'env', 'nice', '\\'].includes(words[0]))
|
|
16
|
+
words.shift();
|
|
17
|
+
while (words.length > 1 && words.at(-1) === '--')
|
|
18
|
+
words.pop();
|
|
19
|
+
return words.join(' ');
|
|
43
20
|
}
|
|
44
21
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
|
|
50
|
-
* carried `passed`/`failed` outcome stands until this turn mutates or validates.
|
|
22
|
+
* Opportunistic red→green state for fix intents: no failing repro is required,
|
|
23
|
+
* but when a pre-mutation validation did fail, that same check must pass after
|
|
24
|
+
* the fix. `missing` therefore means "captured red has no matching green", not
|
|
25
|
+
* "no red was captured".
|
|
51
26
|
*/
|
|
27
|
+
export function redPairStatus(state) {
|
|
28
|
+
if (state.normalizedIntent !== 'fix' || state.mutationCount === 0)
|
|
29
|
+
return 'not-required';
|
|
30
|
+
const red = state.redEvidence;
|
|
31
|
+
if (!red)
|
|
32
|
+
return 'not-required';
|
|
33
|
+
const green = state.validations.some(validation => validation.status === 'passed'
|
|
34
|
+
&& validation.revision >= state.mutationSeq
|
|
35
|
+
&& validationCommandKey(validation.command) === red.commandKey);
|
|
36
|
+
return green ? 'satisfied' : 'missing';
|
|
37
|
+
}
|
|
52
38
|
export function seedCarriedGoalEvidence(state, carried) {
|
|
53
39
|
if (carried.taskProgress && carried.taskProgress.total > 0) {
|
|
54
40
|
state.taskProgress = { ...carried.taskProgress, revision: 1 };
|
|
@@ -61,6 +47,11 @@ export function seedCarriedGoalEvidence(state, carried) {
|
|
|
61
47
|
state.validationSeq = 1;
|
|
62
48
|
state.carriedValidation = carried.validationOutcome === 'passed' ? { status: 'passed' } : { status: 'failed' };
|
|
63
49
|
}
|
|
50
|
+
// Red→green evidence is goal-scoped and rides the checkpoint across
|
|
51
|
+
// physical turns so a continuation cannot complete while a carried pair
|
|
52
|
+
// stays unsatisfied.
|
|
53
|
+
if (carried.redEvidence)
|
|
54
|
+
state.redEvidence = { ...carried.redEvidence };
|
|
64
55
|
}
|
|
65
56
|
function upsertFile(state, path, action, note) {
|
|
66
57
|
const existing = state.files.find(file => file.path === path);
|
|
@@ -88,12 +79,12 @@ function outputSummary(output) {
|
|
|
88
79
|
return `exit ${String(output.code)}`;
|
|
89
80
|
return '';
|
|
90
81
|
}
|
|
91
|
-
function upsertValidation(state, command, status, summary, kind) {
|
|
82
|
+
function upsertValidation(state, command, status, summary, kind, revision) {
|
|
92
83
|
const existing = state.validations.find(validation => validation.command === command);
|
|
93
84
|
if (existing)
|
|
94
|
-
Object.assign(existing, { status, summary, ...(kind ? { kind } : {}) });
|
|
85
|
+
Object.assign(existing, { status, summary, revision, ...(kind ? { kind } : {}) });
|
|
95
86
|
else
|
|
96
|
-
state.validations.push({ command, status, summary, ...(kind ? { kind } : {}) });
|
|
87
|
+
state.validations.push({ command, status, summary, revision, ...(kind ? { kind } : {}) });
|
|
97
88
|
const existingCommand = state.validationCommands.find(item => item.command === command);
|
|
98
89
|
if (existingCommand)
|
|
99
90
|
existingCommand.status = status;
|
|
@@ -223,12 +214,18 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
223
214
|
const passed = summary ? summary.status === 'passed' : ok && exitCode === 0;
|
|
224
215
|
const status = passed ? 'passed' : 'failed';
|
|
225
216
|
const summaryText = summary?.summaryText ?? (passed ? `Executed changed artifact ${artifact} successfully.` : `Changed artifact ${artifact} exited unsuccessfully.`);
|
|
226
|
-
upsertValidation(state, command, status, summaryText, summary?.kind ?? 'generic');
|
|
217
|
+
upsertValidation(state, command, status, summaryText, summary?.kind ?? 'generic', seq);
|
|
227
218
|
state.validationSeq = seq;
|
|
228
219
|
state.phase = 'validating';
|
|
229
220
|
state.lastProgressAt = now;
|
|
230
221
|
if (status === 'failed') {
|
|
231
222
|
state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
|
|
223
|
+
// Red evidence (P4): the first failing repro observed before any
|
|
224
|
+
// mutation of a fix-intent goal is the red half of the red→green pair.
|
|
225
|
+
// Only consumed as a completion requirement — never a mutation blocker.
|
|
226
|
+
if (state.normalizedIntent === 'fix' && state.mutationSeq === 0 && !state.redEvidence) {
|
|
227
|
+
state.redEvidence = { command, commandKey: validationCommandKey(command), summary: summaryText.slice(0, 200) };
|
|
228
|
+
}
|
|
232
229
|
}
|
|
233
230
|
}
|
|
234
231
|
}
|
|
@@ -245,6 +242,37 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
245
242
|
state.revision = seq;
|
|
246
243
|
return state;
|
|
247
244
|
}
|
|
245
|
+
/** Upper bound for parsed task counts; anything larger is treated as malformed. */
|
|
246
|
+
const TASK_COUNT_LIMIT = 10_000;
|
|
247
|
+
function boundedTaskCount(value) {
|
|
248
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= TASK_COUNT_LIMIT)
|
|
249
|
+
return value;
|
|
250
|
+
if (typeof value === 'string' && /^(0|[1-9]\d{0,4})$/.test(value))
|
|
251
|
+
return Number(value);
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
/** Extract bounded task counts from a successful `writeTasks` structured result. */
|
|
255
|
+
export function taskProgressFromOutput(output, revision) {
|
|
256
|
+
if (typeof output !== 'object' || output == null)
|
|
257
|
+
return undefined;
|
|
258
|
+
const candidate = output;
|
|
259
|
+
if (candidate.ok !== true)
|
|
260
|
+
return undefined;
|
|
261
|
+
const total = boundedTaskCount(candidate.taskCount);
|
|
262
|
+
if (total === undefined)
|
|
263
|
+
return undefined;
|
|
264
|
+
if (total === 0)
|
|
265
|
+
return { total: 0, pending: 0, inProgress: 0, completed: 0, revision };
|
|
266
|
+
if (typeof candidate.counts !== 'object' || candidate.counts === null)
|
|
267
|
+
return undefined;
|
|
268
|
+
const counts = candidate.counts;
|
|
269
|
+
const pending = boundedTaskCount(counts.pending);
|
|
270
|
+
const inProgress = boundedTaskCount(counts.in_progress);
|
|
271
|
+
const completed = boundedTaskCount(counts.completed);
|
|
272
|
+
if (pending === undefined || inProgress === undefined || completed === undefined)
|
|
273
|
+
return undefined;
|
|
274
|
+
return { total, pending, inProgress, completed, revision };
|
|
275
|
+
}
|
|
248
276
|
/**
|
|
249
277
|
* Derive the bounded validation outcome for completion evidence.
|
|
250
278
|
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
@@ -77,6 +77,8 @@ function slimToolStartInput(input) {
|
|
|
77
77
|
}
|
|
78
78
|
return slimmed;
|
|
79
79
|
}
|
|
80
|
+
/** Goal-ledger request text bound; the exact bytes live in conversation snapshots, the ledger needs a resumable copy (P1). */
|
|
81
|
+
const GOAL_LEDGER_REQUEST_CHARS = 1024;
|
|
80
82
|
export function prepareSessionEntryForWrite(entry) {
|
|
81
83
|
if (entry.type === 'event') {
|
|
82
84
|
if (entry.name === 'message_update')
|
|
@@ -116,5 +118,11 @@ export function prepareSessionEntryForWrite(entry) {
|
|
|
116
118
|
if (entry.type === 'conversation_snapshot') {
|
|
117
119
|
return { ...entry, messages: slimConversationSnapshot(entry.messages) };
|
|
118
120
|
}
|
|
121
|
+
// Goal-ledger entries are small bounded metadata; only the request text is
|
|
122
|
+
// capped (a pathological 256 KiB piped prompt must not bloat every boundary
|
|
123
|
+
// append). Everything else passes through so the frontier is never dropped.
|
|
124
|
+
if (entry.type === 'goal' && entry.request.length > GOAL_LEDGER_REQUEST_CHARS) {
|
|
125
|
+
return { ...entry, request: `${entry.request.slice(0, GOAL_LEDGER_REQUEST_CHARS)}…[ledger-truncated]` };
|
|
126
|
+
}
|
|
119
127
|
return entry;
|
|
120
128
|
}
|
|
@@ -29,7 +29,51 @@ export type SessionEntry = {
|
|
|
29
29
|
at: string;
|
|
30
30
|
name: string;
|
|
31
31
|
text?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'goal';
|
|
34
|
+
at: string;
|
|
35
|
+
goalId: string;
|
|
36
|
+
phase: 'goal_start' | 'goal_continue' | 'goal_end';
|
|
37
|
+
request: string;
|
|
38
|
+
requestHash: string;
|
|
39
|
+
intent: string;
|
|
40
|
+
cycle: number;
|
|
41
|
+
mutationCount: number;
|
|
42
|
+
validationOutcome: string;
|
|
43
|
+
progressSignature: string;
|
|
44
|
+
taskCounts?: {
|
|
45
|
+
total: number;
|
|
46
|
+
pending: number;
|
|
47
|
+
inProgress: number;
|
|
48
|
+
completed: number;
|
|
49
|
+
};
|
|
50
|
+
redEvidence?: {
|
|
51
|
+
command: string;
|
|
52
|
+
commandKey: string;
|
|
53
|
+
summary: string;
|
|
54
|
+
};
|
|
55
|
+
stopReason?: string;
|
|
56
|
+
status?: string;
|
|
32
57
|
};
|
|
58
|
+
/** Durable goal-ledger entry (P1): one append per supervisor boundary. */
|
|
59
|
+
export type GoalLedgerEntry = Extract<SessionEntry, {
|
|
60
|
+
type: 'goal';
|
|
61
|
+
}>;
|
|
62
|
+
/** An unterminated goal frontier detected in a session (P1 resume path). */
|
|
63
|
+
export interface GoalLedgerFrontier {
|
|
64
|
+
goalId: string;
|
|
65
|
+
request: string;
|
|
66
|
+
requestHash: string;
|
|
67
|
+
intent: string;
|
|
68
|
+
cycle: number;
|
|
69
|
+
mutationCount: number;
|
|
70
|
+
validationOutcome: string;
|
|
71
|
+
progressSignature: string;
|
|
72
|
+
taskCounts?: GoalLedgerEntry['taskCounts'];
|
|
73
|
+
/** Unresolved red evidence carried so crash resume preserves the pending same-check green requirement. */
|
|
74
|
+
redEvidence?: GoalLedgerEntry['redEvidence'];
|
|
75
|
+
at: string;
|
|
76
|
+
}
|
|
33
77
|
type SessionHeader = Extract<SessionEntry, {
|
|
34
78
|
type: 'header';
|
|
35
79
|
}>;
|
|
@@ -70,6 +114,10 @@ export declare function appendSessionEntry(session: HazeSession, entry: SessionE
|
|
|
70
114
|
export declare const SESSION_VACUUM_THRESHOLD_BYTES: number;
|
|
71
115
|
/** Test-only override for the vacuum trigger; tests restore the original. */
|
|
72
116
|
export declare function setSessionVacuumThresholdForTests(bytes: number): void;
|
|
117
|
+
/** Trailing goal-ledger entries preserved per goal id when the vacuum rewrites (frontier + end + one audit entry). */
|
|
118
|
+
export declare const GOAL_LEDGER_KEEP_PER_GOAL = 3;
|
|
119
|
+
/** Ledger trim must amortize its rewrite: rewrite for goal entries alone only past this many dropped bytes. */
|
|
120
|
+
export declare const GOAL_LEDGER_TRIM_BYTES = 2048;
|
|
73
121
|
export declare function vacuumSessionFileIfLarge(session: HazeSession, thresholdBytes?: number): Promise<boolean>;
|
|
74
122
|
export interface ReadSessionEntriesResult {
|
|
75
123
|
entries: SessionEntry[];
|
|
@@ -84,6 +132,16 @@ export interface ReadSessionEntriesResult {
|
|
|
84
132
|
* loss in debug mode instead of silently dropping messages.
|
|
85
133
|
*/
|
|
86
134
|
export declare function readSessionEntries(session: HazeSession): Promise<ReadSessionEntriesResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Pure frontier detection over parsed session entries (P1): the append-only
|
|
137
|
+
* goal ledger's frontier is the last entry of the most recent goal id that has
|
|
138
|
+
* no `goal_end` entry. A truncated or malformed tail line parses as absent, so
|
|
139
|
+
* a crash mid-write can never resurrect a half-written boundary
|
|
140
|
+
* (autoprompt's "treat half-written artifacts as absent").
|
|
141
|
+
*/
|
|
142
|
+
export declare function findGoalLedgerFrontier(entries: readonly SessionEntry[]): GoalLedgerFrontier | undefined;
|
|
143
|
+
/** Read the goal-ledger frontier of a stored session (one file scan). */
|
|
144
|
+
export declare function readGoalLedgerFrontier(session: HazeSession): Promise<GoalLedgerFrontier | undefined>;
|
|
87
145
|
export interface RestoreConversationResult {
|
|
88
146
|
messages: ModelMessage[];
|
|
89
147
|
parseErrors: string[];
|
|
@@ -92,11 +150,13 @@ export interface RestoreSessionStateResult {
|
|
|
92
150
|
messages: ModelMessage[];
|
|
93
151
|
workState: WorkState | undefined;
|
|
94
152
|
parseErrors: string[];
|
|
153
|
+
/** Unterminated goal frontier from the durable ledger, if any (P1 resume path). */
|
|
154
|
+
goalFrontier: GoalLedgerFrontier | undefined;
|
|
95
155
|
}
|
|
96
156
|
/**
|
|
97
157
|
* Restore conversation and work state in one file scan (CR-013). Session
|
|
98
158
|
* files grow to megabytes in long workspaces; resuming should not parse the
|
|
99
|
-
* JSONL twice.
|
|
159
|
+
* JSONL twice. The goal-ledger frontier rides the same scan (P1).
|
|
100
160
|
*/
|
|
101
161
|
export declare function restoreSessionState(session: HazeSession): Promise<RestoreSessionStateResult>;
|
|
102
162
|
export declare function restoreConversation(session: HazeSession): Promise<RestoreConversationResult>;
|