@denizokcu/haze 1.1.0 → 1.2.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 +49 -1
- package/README.md +17 -10
- package/SECURITY.md +1 -1
- 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 +8 -1
- package/dist/cli/chat/sessionRecorder.d.ts +9 -0
- package/dist/cli/chat/sessionRecorder.js +12 -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 +69 -110
- 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 +73 -4
- package/dist/cli/commands/streaming/agentAttempt.d.ts +11 -1
- package/dist/cli/commands/streaming/agentAttempt.js +9 -5
- 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 +25 -5
- package/dist/cli/commands/streaming/attemptOutcome.js +69 -16
- package/dist/cli/commands/streaming/attemptSetup.d.ts +10 -3
- package/dist/cli/commands/streaming/attemptSetup.js +30 -13
- 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 +18 -3
- package/dist/cli/commands/streaming/goalSupervisor.js +71 -12
- package/dist/cli/commands/streaming/prepareStep.d.ts +40 -0
- package/dist/cli/commands/streaming/prepareStep.js +116 -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 +2 -6
- package/dist/cli/commands/streaming/streamLoop.d.ts +31 -4
- package/dist/cli/commands/streaming/streamLoop.js +283 -268
- 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 +108 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +1 -1
- package/dist/cli/commands/streaming/turnRuntime.js +3 -2
- package/dist/cli/commands/streaming.d.ts +12 -1
- package/dist/cli/commands/streaming.js +20 -25
- package/dist/cli/index.js +6 -3
- package/dist/config/modelCatalog.d.ts +32 -0
- package/dist/config/modelCatalog.js +84 -0
- package/dist/config/providerPresets.d.ts +7 -0
- package/dist/config/providerPresets.js +195 -391
- package/dist/config/settings.d.ts +10 -2
- package/dist/config/settings.js +3 -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 +42 -3
- package/dist/core/agent/compaction.js +53 -5
- package/dist/core/agent/completionController.d.ts +16 -7
- package/dist/core/agent/completionController.js +13 -6
- package/dist/core/agent/contextBudget.d.ts +56 -0
- package/dist/core/agent/contextBudget.js +53 -0
- package/dist/core/agent/errors.js +2 -2
- package/dist/core/agent/events.d.ts +36 -1
- package/dist/core/agent/goalPolicy.d.ts +4 -3
- package/dist/core/agent/goalPolicy.js +9 -4
- package/dist/core/agent/overflow.d.ts +45 -0
- package/dist/core/agent/overflow.js +91 -0
- package/dist/core/agent/requestAssembly.d.ts +7 -0
- package/dist/core/agent/requestAssembly.js +15 -7
- package/dist/core/agent/workState.d.ts +25 -15
- package/dist/core/agent/workState.js +84 -44
- package/dist/core/safety/shellClassifier.d.ts +16 -0
- package/dist/core/safety/shellClassifier.js +31 -0
- package/dist/core/session/sessionSlimming.js +8 -0
- package/dist/core/session/sessionStore.d.ts +71 -1
- package/dist/core/session/sessionStore.js +121 -6
- package/dist/core/validation/outputParser.d.ts +1 -1
- package/dist/core/validation/outputParser.js +6 -1
- package/dist/llm/client.d.ts +2 -2
- package/dist/llm/client.js +14 -6
- package/dist/llm/hazeTools.d.ts +64 -208
- package/dist/llm/tools/shellTool.js +27 -8
- package/dist/llm/tools/taskTool.d.ts +64 -208
- package/dist/llm/tools/taskTool.js +22 -10
- package/dist/ui/components/TextInput.d.ts +18 -1
- package/dist/ui/components/TextInput.js +50 -73
- 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 +16 -15
- 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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider context-overflow classification (Pillar 1.2 of the Pi learning
|
|
3
|
+
* roadmap). Three overflow modes exist and each routes to different recovery:
|
|
4
|
+
*
|
|
5
|
+
* 1. **Error overflow**: the provider rejects an oversized request with a
|
|
6
|
+
* provider-specific error message (`errorIndicatesContextOverflow`).
|
|
7
|
+
* 2. **Silent overflow**: some gateways (z.ai-style) accept the oversized
|
|
8
|
+
* request and answer normally; only the reported usage exceeds the window
|
|
9
|
+
* (`isSilentContextOverflow`).
|
|
10
|
+
* 3. **Length-stop overflow**: some local servers truncate the input to fill
|
|
11
|
+
* the window, leaving no room for output — a `length` finish with ~zero
|
|
12
|
+
* output and input filling the window (`isLengthStopOverflow`).
|
|
13
|
+
*
|
|
14
|
+
* Pattern families are battle-tested against the providers listed per regex;
|
|
15
|
+
* keep this file a pure data table so tests can pin it (like the theme
|
|
16
|
+
* registry). Additive changes only.
|
|
17
|
+
*/
|
|
18
|
+
/** Does an error text indicate a provider context-window overflow? */
|
|
19
|
+
export declare function errorIndicatesContextOverflow(text: string): boolean;
|
|
20
|
+
export interface OverflowUsageInput {
|
|
21
|
+
inputTokens: number | undefined;
|
|
22
|
+
cacheReadTokens: number;
|
|
23
|
+
contextWindowTokens: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Silent overflow: the request succeeded but the reported input already
|
|
27
|
+
* exceeded the model's context window (some gateways accept and stream an
|
|
28
|
+
* answer anyway; the next request will fail or be truncated). The input-like
|
|
29
|
+
* term is convention-robust (see `inputLikeTokens`): subset-style cached
|
|
30
|
+
* tokens inside `inputTokens` are never double counted, so a cache-heavy
|
|
31
|
+
* successful finish cannot false-positive.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isSilentContextOverflow(input: OverflowUsageInput): boolean;
|
|
34
|
+
export interface LengthStopOverflowInput extends OverflowUsageInput {
|
|
35
|
+
finishReason: string | undefined;
|
|
36
|
+
outputTokens: number | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Length-stop overflow: the server truncated the oversized input to fit the
|
|
40
|
+
* window, leaving no room to generate — a `length` finish with zero output and
|
|
41
|
+
* input filling (≥99% of) the window.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isLengthStopOverflow(input: LengthStopOverflowInput): boolean;
|
|
44
|
+
/** Overflow patterns exposed for pinning tests. */
|
|
45
|
+
export declare function getOverflowPatterns(): readonly RegExp[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider context-overflow classification (Pillar 1.2 of the Pi learning
|
|
3
|
+
* roadmap). Three overflow modes exist and each routes to different recovery:
|
|
4
|
+
*
|
|
5
|
+
* 1. **Error overflow**: the provider rejects an oversized request with a
|
|
6
|
+
* provider-specific error message (`errorIndicatesContextOverflow`).
|
|
7
|
+
* 2. **Silent overflow**: some gateways (z.ai-style) accept the oversized
|
|
8
|
+
* request and answer normally; only the reported usage exceeds the window
|
|
9
|
+
* (`isSilentContextOverflow`).
|
|
10
|
+
* 3. **Length-stop overflow**: some local servers truncate the input to fill
|
|
11
|
+
* the window, leaving no room for output — a `length` finish with ~zero
|
|
12
|
+
* output and input filling the window (`isLengthStopOverflow`).
|
|
13
|
+
*
|
|
14
|
+
* Pattern families are battle-tested against the providers listed per regex;
|
|
15
|
+
* keep this file a pure data table so tests can pin it (like the theme
|
|
16
|
+
* registry). Additive changes only.
|
|
17
|
+
*/
|
|
18
|
+
import { inputLikeTokens } from './contextBudget.js';
|
|
19
|
+
/** Provider error shapes that indicate the request exceeded the context window. */
|
|
20
|
+
const OVERFLOW_PATTERNS = [
|
|
21
|
+
/prompt is too long/i, // Anthropic: "prompt is too long: 213462 tokens > 200000 maximum"
|
|
22
|
+
/request_too_large/i, // Anthropic HTTP 413 request_too_large
|
|
23
|
+
/input is too long for requested model/i, // Amazon Bedrock
|
|
24
|
+
/exceeds the context window/i, // OpenAI (Completions & Responses)
|
|
25
|
+
/exceeds (?:the )?(?:model'?s )?maximum context length/i, // OpenAI/LiteLLM
|
|
26
|
+
/input token count.*exceeds the maximum/i, // Google Gemini
|
|
27
|
+
/maximum prompt length is \d+/i, // xAI Grok
|
|
28
|
+
/reduce the length of the messages/i, // Groq
|
|
29
|
+
/maximum context length is \d+ tokens/i, // OpenRouter (most backends)
|
|
30
|
+
/exceeds (?:the )?maximum allowed input length/i, // OpenRouter/Poolside
|
|
31
|
+
/input \(\d+ tokens\) is longer than the model'?s context length/i, // Together AI
|
|
32
|
+
/exceeds the limit of \d+/i, // GitHub Copilot
|
|
33
|
+
/exceeds the available context size/i, // llama.cpp server
|
|
34
|
+
/greater than the context length/i, // LM Studio
|
|
35
|
+
/context window exceeds limit/i, // MiniMax
|
|
36
|
+
/exceeded model token limit/i, // Kimi
|
|
37
|
+
/too large for model with \d+ maximum context length/i, // Mistral
|
|
38
|
+
/prompt has [\d,]+ tokens?, but the configured context size is/i, // DS4
|
|
39
|
+
/model_context_window_exceeded/i, // z.ai finish_reason surfaced as error text
|
|
40
|
+
/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow
|
|
41
|
+
/range of input length should be/i, // DashScope / Qwen
|
|
42
|
+
/context[_ ]length[_ ]exceeded/i, // Generic fallback
|
|
43
|
+
/too many tokens/i, // Generic fallback
|
|
44
|
+
/token limit exceeded/i, // Generic fallback
|
|
45
|
+
/^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i, // Cerebras: 400/413 with no body
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Error shapes that look like overflow but are not (rate limiting and other
|
|
49
|
+
* transient throttles). Checked before the overflow patterns so a throttling
|
|
50
|
+
* message containing "too many tokens" cannot trigger compaction.
|
|
51
|
+
*/
|
|
52
|
+
const NON_OVERFLOW_PATTERNS = [
|
|
53
|
+
/^(?:throttling|service unavailable)/i, // AWS Bedrock throttling/unavailable prefixes (raw ThrottlingException and formatted variants)
|
|
54
|
+
/rate limit/i,
|
|
55
|
+
/too many requests/i,
|
|
56
|
+
];
|
|
57
|
+
/** Does an error text indicate a provider context-window overflow? */
|
|
58
|
+
export function errorIndicatesContextOverflow(text) {
|
|
59
|
+
if (NON_OVERFLOW_PATTERNS.some(pattern => pattern.test(text)))
|
|
60
|
+
return false;
|
|
61
|
+
return OVERFLOW_PATTERNS.some(pattern => pattern.test(text));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Silent overflow: the request succeeded but the reported input already
|
|
65
|
+
* exceeded the model's context window (some gateways accept and stream an
|
|
66
|
+
* answer anyway; the next request will fail or be truncated). The input-like
|
|
67
|
+
* term is convention-robust (see `inputLikeTokens`): subset-style cached
|
|
68
|
+
* tokens inside `inputTokens` are never double counted, so a cache-heavy
|
|
69
|
+
* successful finish cannot false-positive.
|
|
70
|
+
*/
|
|
71
|
+
export function isSilentContextOverflow(input) {
|
|
72
|
+
if (input.contextWindowTokens <= 0)
|
|
73
|
+
return false;
|
|
74
|
+
return inputLikeTokens(input) > input.contextWindowTokens;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Length-stop overflow: the server truncated the oversized input to fit the
|
|
78
|
+
* window, leaving no room to generate — a `length` finish with zero output and
|
|
79
|
+
* input filling (≥99% of) the window.
|
|
80
|
+
*/
|
|
81
|
+
export function isLengthStopOverflow(input) {
|
|
82
|
+
if (input.finishReason !== 'length' || (input.outputTokens ?? 0) > 0)
|
|
83
|
+
return false;
|
|
84
|
+
if (input.contextWindowTokens <= 0)
|
|
85
|
+
return false;
|
|
86
|
+
return inputLikeTokens(input) >= input.contextWindowTokens * 0.99;
|
|
87
|
+
}
|
|
88
|
+
/** Overflow patterns exposed for pinning tests. */
|
|
89
|
+
export function getOverflowPatterns() {
|
|
90
|
+
return OVERFLOW_PATTERNS;
|
|
91
|
+
}
|
|
@@ -2,6 +2,13 @@ import type { ModelMessage } from 'ai';
|
|
|
2
2
|
export declare function stripSyntheticControls(messages: ModelMessage[]): ModelMessage[];
|
|
3
3
|
export declare function withoutSystemMessages(messages: ModelMessage[]): ModelMessage[];
|
|
4
4
|
export declare function withSyntheticControl(messages: ModelMessage[], control: string): ModelMessage[];
|
|
5
|
+
/**
|
|
6
|
+
* Append a per-step control without rewriting an already-sent provider prefix.
|
|
7
|
+
* Active/session conversation state still removes every tagged control through
|
|
8
|
+
* `stripSyntheticControls`; this variant exists only for an in-flight logical
|
|
9
|
+
* turn whose next provider request should remain cache-prefix compatible.
|
|
10
|
+
*/
|
|
11
|
+
export declare function appendSyntheticControl(messages: ModelMessage[], control: string): ModelMessage[];
|
|
5
12
|
/** Drop only a trailing text-only assistant final that completion policy rejected. */
|
|
6
13
|
export declare function withoutRejectedAssistantFinal(messages: ModelMessage[]): ModelMessage[];
|
|
7
14
|
export declare function compactToolHistory(messages: ModelMessage[], options?: {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { estimateValueTokens } from './contextBudget.js';
|
|
1
|
+
import { estimateValueTokens, SYNTHETIC_CONTROL_MARKER } from './contextBudget.js';
|
|
2
2
|
import { isFailedToolOutput } from './toolResults.js';
|
|
3
|
-
const SYNTHETIC_CONTROL_OPEN = '<haze_control>';
|
|
4
3
|
function isSyntheticControlMessage(message) {
|
|
5
4
|
return message.role === 'user'
|
|
6
5
|
&& typeof message.content === 'string'
|
|
7
|
-
&& message.content.startsWith(
|
|
6
|
+
&& message.content.startsWith(SYNTHETIC_CONTROL_MARKER);
|
|
8
7
|
}
|
|
9
8
|
export function stripSyntheticControls(messages) {
|
|
10
9
|
return messages.filter(message => !isSyntheticControlMessage(message));
|
|
@@ -22,11 +21,20 @@ function modelMessageTextForContext(message) {
|
|
|
22
21
|
return JSON.stringify(content);
|
|
23
22
|
return content.map(part => typeof part === 'object' && part != null && 'text' in part && typeof part.text === 'string' ? part.text : JSON.stringify(part)).join('\n');
|
|
24
23
|
}
|
|
24
|
+
function syntheticControlMessage(control) {
|
|
25
|
+
return { role: 'user', content: `${SYNTHETIC_CONTROL_MARKER}\n${control}\n</haze_control>` };
|
|
26
|
+
}
|
|
25
27
|
export function withSyntheticControl(messages, control) {
|
|
26
|
-
return [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
return [...stripSyntheticControls(messages), syntheticControlMessage(control)];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Append a per-step control without rewriting an already-sent provider prefix.
|
|
32
|
+
* Active/session conversation state still removes every tagged control through
|
|
33
|
+
* `stripSyntheticControls`; this variant exists only for an in-flight logical
|
|
34
|
+
* turn whose next provider request should remain cache-prefix compatible.
|
|
35
|
+
*/
|
|
36
|
+
export function appendSyntheticControl(messages, control) {
|
|
37
|
+
return [...messages, syntheticControlMessage(control)];
|
|
30
38
|
}
|
|
31
39
|
/** Drop only a trailing text-only assistant final that completion policy rejected. */
|
|
32
40
|
export function withoutRejectedAssistantFinal(messages) {
|
|
@@ -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
|
|
@@ -263,7 +291,19 @@ export function deriveValidationOutcome(state) {
|
|
|
263
291
|
if (stale)
|
|
264
292
|
return 'stale';
|
|
265
293
|
const latest = state.validations.at(-1) ?? state.carriedValidation;
|
|
266
|
-
|
|
294
|
+
if (latest?.status !== 'passed')
|
|
295
|
+
return 'failed';
|
|
296
|
+
// A self-declared custom check (generic kind, `purpose=validation`) cannot
|
|
297
|
+
// clear a failed classifier-confirmed validation: known test/build commands
|
|
298
|
+
// are the authoritative completion evidence, custom checks supplement them
|
|
299
|
+
// (found by the honest-impossibility eval — a model ran `npm test` red, then
|
|
300
|
+
// passed an unrelated self-written script and claimed completion). A failed
|
|
301
|
+
// validation carried from a goal checkpoint counts as confirmed too.
|
|
302
|
+
const confirmedFailed = state.validations.some(entry => entry.kind !== 'generic' && entry.status === 'failed')
|
|
303
|
+
|| (state.carriedValidation?.status === 'failed' && state.carriedValidation.kind !== 'generic');
|
|
304
|
+
if (latest.kind === 'generic' && confirmedFailed)
|
|
305
|
+
return 'failed';
|
|
306
|
+
return 'passed';
|
|
267
307
|
}
|
|
268
308
|
export function workStatePrompt(state) {
|
|
269
309
|
return `<work_state>\n${JSON.stringify(state)}\n</work_state>`;
|
|
@@ -8,4 +8,20 @@ export type ShellClassification = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare function classifyShellCommand(command: string): ShellClassification;
|
|
10
10
|
export declare function isValidationClassification(classification: ShellClassification): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Approximate quoted-span removal ('…', "…", `…`). Used to keep command-shape
|
|
13
|
+
* heuristics (validation kind, exit masking) from firing on text the model
|
|
14
|
+
* authored inside quoted payloads. False positives only make decisions more
|
|
15
|
+
* conservative, never the reverse.
|
|
16
|
+
*/
|
|
17
|
+
export declare function stripQuotedSpans(command: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a command's final exit status can mask an earlier failing stage.
|
|
20
|
+
* POSIX list operators `;`, `||`, and single `&` end a list with the *last*
|
|
21
|
+
* command's status, so `npm test > out.txt; cat out.txt` exits 0 even when
|
|
22
|
+
* the suite failed (found by the honest-impossibility eval). Redirections
|
|
23
|
+
* (`2>&1`, `&>`, `<&`) are not list operators and are excluded. Pipelines are
|
|
24
|
+
* covered separately by `pipefail`; `&&` propagates failures.
|
|
25
|
+
*/
|
|
26
|
+
export declare function commandMasksValidationExit(command: string): boolean;
|
|
11
27
|
export {};
|
|
@@ -81,3 +81,34 @@ export function classifyShellCommand(command) {
|
|
|
81
81
|
export function isValidationClassification(classification) {
|
|
82
82
|
return classification.traits.includes('runs_tests') || classification.traits.includes('runs_build');
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Approximate quoted-span removal ('…', "…", `…`). Used to keep command-shape
|
|
86
|
+
* heuristics (validation kind, exit masking) from firing on text the model
|
|
87
|
+
* authored inside quoted payloads. False positives only make decisions more
|
|
88
|
+
* conservative, never the reverse.
|
|
89
|
+
*/
|
|
90
|
+
export function stripQuotedSpans(command) {
|
|
91
|
+
return command
|
|
92
|
+
.replace(/'[^']*'/g, ' ')
|
|
93
|
+
.replace(/"[^"]*"/g, ' ')
|
|
94
|
+
.replace(/`[^`]*`/g, ' ');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether a command's final exit status can mask an earlier failing stage.
|
|
98
|
+
* POSIX list operators `;`, `||`, and single `&` end a list with the *last*
|
|
99
|
+
* command's status, so `npm test > out.txt; cat out.txt` exits 0 even when
|
|
100
|
+
* the suite failed (found by the honest-impossibility eval). Redirections
|
|
101
|
+
* (`2>&1`, `&>`, `<&`) are not list operators and are excluded. Pipelines are
|
|
102
|
+
* covered separately by `pipefail`; `&&` propagates failures.
|
|
103
|
+
*/
|
|
104
|
+
export function commandMasksValidationExit(command) {
|
|
105
|
+
const unquoted = stripQuotedSpans(command);
|
|
106
|
+
if (unquoted.includes(';'))
|
|
107
|
+
return true;
|
|
108
|
+
if (/(?<!\|)\|\|(?!\|)/.test(unquoted))
|
|
109
|
+
return true;
|
|
110
|
+
// Single `&` that is not part of `&&` and not a redirection (`>&`, `<&`, `&>`).
|
|
111
|
+
if (/(?<![<>&])&(?![&>])/.test(unquoted))
|
|
112
|
+
return true;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
@@ -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,61 @@ export type SessionEntry = {
|
|
|
29
29
|
at: string;
|
|
30
30
|
name: string;
|
|
31
31
|
text?: string;
|
|
32
|
+
}
|
|
33
|
+
/** First-class compaction audit entry (Pillar 1.7): conversation snapshots remain the restore source of truth; this records what was compacted, when, and how. */
|
|
34
|
+
| {
|
|
35
|
+
type: 'compact';
|
|
36
|
+
at: string;
|
|
37
|
+
method: 'heuristic' | 'llm';
|
|
38
|
+
olderCount: number;
|
|
39
|
+
keptCount: number;
|
|
40
|
+
instructions?: string;
|
|
41
|
+
summary: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'goal';
|
|
44
|
+
at: string;
|
|
45
|
+
goalId: string;
|
|
46
|
+
phase: 'goal_start' | 'goal_continue' | 'goal_end';
|
|
47
|
+
request: string;
|
|
48
|
+
requestHash: string;
|
|
49
|
+
intent: string;
|
|
50
|
+
cycle: number;
|
|
51
|
+
mutationCount: number;
|
|
52
|
+
validationOutcome: string;
|
|
53
|
+
progressSignature: string;
|
|
54
|
+
taskCounts?: {
|
|
55
|
+
total: number;
|
|
56
|
+
pending: number;
|
|
57
|
+
inProgress: number;
|
|
58
|
+
completed: number;
|
|
59
|
+
};
|
|
60
|
+
redEvidence?: {
|
|
61
|
+
command: string;
|
|
62
|
+
commandKey: string;
|
|
63
|
+
summary: string;
|
|
64
|
+
};
|
|
65
|
+
stopReason?: string;
|
|
66
|
+
status?: string;
|
|
32
67
|
};
|
|
68
|
+
/** Durable goal-ledger entry (P1): one append per supervisor boundary. */
|
|
69
|
+
export type GoalLedgerEntry = Extract<SessionEntry, {
|
|
70
|
+
type: 'goal';
|
|
71
|
+
}>;
|
|
72
|
+
/** An unterminated goal frontier detected in a session (P1 resume path). */
|
|
73
|
+
export interface GoalLedgerFrontier {
|
|
74
|
+
goalId: string;
|
|
75
|
+
request: string;
|
|
76
|
+
requestHash: string;
|
|
77
|
+
intent: string;
|
|
78
|
+
cycle: number;
|
|
79
|
+
mutationCount: number;
|
|
80
|
+
validationOutcome: string;
|
|
81
|
+
progressSignature: string;
|
|
82
|
+
taskCounts?: GoalLedgerEntry['taskCounts'];
|
|
83
|
+
/** Unresolved red evidence carried so crash resume preserves the pending same-check green requirement. */
|
|
84
|
+
redEvidence?: GoalLedgerEntry['redEvidence'];
|
|
85
|
+
at: string;
|
|
86
|
+
}
|
|
33
87
|
type SessionHeader = Extract<SessionEntry, {
|
|
34
88
|
type: 'header';
|
|
35
89
|
}>;
|
|
@@ -70,6 +124,10 @@ export declare function appendSessionEntry(session: HazeSession, entry: SessionE
|
|
|
70
124
|
export declare const SESSION_VACUUM_THRESHOLD_BYTES: number;
|
|
71
125
|
/** Test-only override for the vacuum trigger; tests restore the original. */
|
|
72
126
|
export declare function setSessionVacuumThresholdForTests(bytes: number): void;
|
|
127
|
+
/** Trailing goal-ledger entries preserved per goal id when the vacuum rewrites (frontier + end + one audit entry). */
|
|
128
|
+
export declare const GOAL_LEDGER_KEEP_PER_GOAL = 3;
|
|
129
|
+
/** Ledger trim must amortize its rewrite: rewrite for goal entries alone only past this many dropped bytes. */
|
|
130
|
+
export declare const GOAL_LEDGER_TRIM_BYTES = 2048;
|
|
73
131
|
export declare function vacuumSessionFileIfLarge(session: HazeSession, thresholdBytes?: number): Promise<boolean>;
|
|
74
132
|
export interface ReadSessionEntriesResult {
|
|
75
133
|
entries: SessionEntry[];
|
|
@@ -84,6 +142,16 @@ export interface ReadSessionEntriesResult {
|
|
|
84
142
|
* loss in debug mode instead of silently dropping messages.
|
|
85
143
|
*/
|
|
86
144
|
export declare function readSessionEntries(session: HazeSession): Promise<ReadSessionEntriesResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Pure frontier detection over parsed session entries (P1): the append-only
|
|
147
|
+
* goal ledger's frontier is the last entry of the most recent goal id that has
|
|
148
|
+
* no `goal_end` entry. A truncated or malformed tail line parses as absent, so
|
|
149
|
+
* a crash mid-write can never resurrect a half-written boundary
|
|
150
|
+
* (autoprompt's "treat half-written artifacts as absent").
|
|
151
|
+
*/
|
|
152
|
+
export declare function findGoalLedgerFrontier(entries: readonly SessionEntry[]): GoalLedgerFrontier | undefined;
|
|
153
|
+
/** Read the goal-ledger frontier of a stored session (one file scan). */
|
|
154
|
+
export declare function readGoalLedgerFrontier(session: HazeSession): Promise<GoalLedgerFrontier | undefined>;
|
|
87
155
|
export interface RestoreConversationResult {
|
|
88
156
|
messages: ModelMessage[];
|
|
89
157
|
parseErrors: string[];
|
|
@@ -92,11 +160,13 @@ export interface RestoreSessionStateResult {
|
|
|
92
160
|
messages: ModelMessage[];
|
|
93
161
|
workState: WorkState | undefined;
|
|
94
162
|
parseErrors: string[];
|
|
163
|
+
/** Unterminated goal frontier from the durable ledger, if any (P1 resume path). */
|
|
164
|
+
goalFrontier: GoalLedgerFrontier | undefined;
|
|
95
165
|
}
|
|
96
166
|
/**
|
|
97
167
|
* Restore conversation and work state in one file scan (CR-013). Session
|
|
98
168
|
* files grow to megabytes in long workspaces; resuming should not parse the
|
|
99
|
-
* JSONL twice.
|
|
169
|
+
* JSONL twice. The goal-ledger frontier rides the same scan (P1).
|
|
100
170
|
*/
|
|
101
171
|
export declare function restoreSessionState(session: HazeSession): Promise<RestoreSessionStateResult>;
|
|
102
172
|
export declare function restoreConversation(session: HazeSession): Promise<RestoreConversationResult>;
|