@denizokcu/haze 1.4.0 → 1.5.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 +48 -1
- package/README.md +28 -12
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +7 -0
- package/dist/cli/chat/BusyBar.js +8 -0
- package/dist/cli/chat/DynamicFrame.d.ts +37 -0
- package/dist/cli/chat/DynamicFrame.js +48 -0
- package/dist/cli/chat/busyIndicator.d.ts +3 -1
- package/dist/cli/chat/busyIndicator.js +11 -9
- package/dist/cli/chat/chatMetrics.d.ts +1 -1
- package/dist/cli/chat/chatMetrics.js +3 -3
- package/dist/cli/chat/inputSuggestions.js +2 -1
- package/dist/cli/chat/liveRegion.js +1 -1
- package/dist/cli/chat/messages.js +27 -16
- package/dist/cli/chat/resizeGuard.d.ts +20 -0
- package/dist/cli/chat/resizeGuard.js +25 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +13 -2
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +8 -0
- package/dist/cli/chat/shutdown.d.ts +27 -0
- package/dist/cli/chat/shutdown.js +79 -0
- package/dist/cli/chat/terminalControl.d.ts +45 -0
- package/dist/cli/chat/terminalControl.js +107 -0
- package/dist/cli/chat/tips.js +1 -0
- package/dist/cli/chat/userInput.d.ts +43 -0
- package/dist/cli/chat/userInput.js +63 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +14 -6
- package/dist/cli/chat/wizard/types.d.ts +8 -1
- package/dist/cli/chat/wizardDispatch.js +1 -1
- package/dist/cli/commands/chat.js +258 -172
- package/dist/cli/commands/commandHelp.js +6 -2
- package/dist/cli/commands/commands.d.ts +8 -0
- package/dist/cli/commands/commands.js +11 -0
- package/dist/cli/commands/formatters.d.ts +1 -1
- package/dist/cli/commands/formatters.js +20 -2
- package/dist/cli/commands/logsCommand.js +21 -2
- package/dist/cli/commands/reasoningCommand.d.ts +23 -14
- package/dist/cli/commands/reasoningCommand.js +53 -20
- package/dist/cli/commands/runCommand.js +19 -11
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +11 -6
- package/dist/cli/commands/streaming/attemptSetup.d.ts +1 -0
- package/dist/cli/commands/streaming/attemptSetup.js +11 -5
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +8 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +3 -2
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +4 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +43 -7
- package/dist/cli/commands/streaming/prepareStep.js +7 -3
- package/dist/cli/commands/streaming/streamLoop.d.ts +5 -0
- package/dist/cli/commands/streaming/streamLoop.js +3 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +6 -0
- package/dist/cli/commands/streaming.d.ts +1 -1
- package/dist/cli/commands/streaming.js +23 -17
- package/dist/cli/commands/wizardFlow.d.ts +5 -2
- package/dist/cli/commands/wizardFlow.js +17 -10
- package/dist/cli/index.js +17 -1
- package/dist/config/contextFiles.d.ts +9 -0
- package/dist/config/contextFiles.js +21 -1
- package/dist/config/modelCatalog.d.ts +3 -0
- package/dist/config/modelCatalog.js +29 -0
- package/dist/config/providerPresets.d.ts +1 -1
- package/dist/config/providerPresets.js +42 -3
- package/dist/config/settings.d.ts +11 -4
- package/dist/config/settings.js +9 -0
- package/dist/core/agent/budgets.d.ts +13 -15
- package/dist/core/agent/budgets.js +15 -17
- package/dist/core/agent/completionController.d.ts +6 -2
- package/dist/core/agent/completionController.js +16 -3
- package/dist/core/agent/goalPolicy.d.ts +10 -0
- package/dist/core/agent/goalPolicy.js +44 -6
- package/dist/core/agent/projectPreflight.d.ts +2 -0
- package/dist/core/agent/projectPreflight.js +56 -0
- package/dist/core/agent/reasoningPolicy.d.ts +34 -4
- package/dist/core/agent/reasoningPolicy.js +27 -4
- package/dist/core/agent/workState.d.ts +8 -0
- package/dist/core/agent/workState.js +191 -8
- package/dist/core/providerContracts.d.ts +32 -0
- package/dist/core/providerContracts.js +1 -0
- package/dist/core/session/sessionReport.d.ts +33 -0
- package/dist/core/session/sessionReport.js +121 -0
- package/dist/core/session/sessionSlimming.js +9 -3
- package/dist/core/session/sessionStore.d.ts +12 -0
- package/dist/core/session/sessionStore.js +20 -4
- package/dist/core/subagent/contracts.d.ts +3 -25
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/validation/outputParser.d.ts +6 -1
- package/dist/core/validation/outputParser.js +6 -2
- package/dist/llm/client.d.ts +4 -2
- package/dist/llm/client.js +44 -16
- package/dist/llm/hazeTools.d.ts +8553 -8550
- package/dist/llm/hazeTools.js +6 -503
- package/dist/llm/lspTools.d.ts +120 -120
- package/dist/llm/mcp.js +3 -0
- package/dist/llm/requestContext.d.ts +1 -1
- package/dist/llm/requestContext.js +1 -1
- package/dist/{core/subagent → llm}/subagentRunner.d.ts +9 -9
- package/dist/{core/subagent → llm}/subagentRunner.js +22 -25
- package/dist/llm/systemPrompt.d.ts +11 -1
- package/dist/llm/systemPrompt.js +2 -11
- package/dist/llm/tools/fetchTool.d.ts +30 -30
- package/dist/llm/tools/fileTools.d.ts +7768 -0
- package/dist/llm/tools/fileTools.js +510 -0
- package/dist/llm/tools/processTool.d.ts +30 -30
- package/dist/llm/tools/shellTool.d.ts +30 -30
- package/dist/llm/tools/shellTool.js +8 -4
- package/dist/llm/tools/toolContext.d.ts +3 -32
- package/dist/llm/tools/toolContext.js +33 -52
- package/dist/llm/tools/toolContextState.d.ts +40 -0
- package/dist/llm/tools/toolContextState.js +34 -0
- package/dist/llm/workerContext.d.ts +7 -0
- package/dist/llm/workerContext.js +18 -1
- package/dist/skills/SkillLoader.js +3 -3
- package/dist/skills/SkillRegistry.js +3 -3
- package/dist/skills/builder/SkillBuilder.js +3 -3
- package/dist/skills/confinement.d.ts +7 -0
- package/dist/skills/confinement.js +15 -0
- package/dist/ui/codeHighlight.js +4 -4
- package/dist/ui/components/MarkdownText.js +7 -8
- package/dist/ui/components/NativeIndicators.d.ts +15 -0
- package/dist/ui/components/NativeIndicators.js +32 -0
- package/dist/ui/components/StreamingMarkdownText.d.ts +9 -0
- package/dist/ui/components/StreamingMarkdownText.js +38 -0
- package/dist/ui/components/TextInput.d.ts +7 -2
- package/dist/ui/components/TextInput.js +103 -46
- package/dist/ui/components/WizardChoices.d.ts +18 -0
- package/dist/ui/components/WizardChoices.js +32 -0
- package/dist/ui/inputBuffer.js +12 -6
- package/dist/ui/textGeometry.d.ts +14 -0
- package/dist/ui/textGeometry.js +31 -0
- package/package.json +14 -13
- /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
- /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const MAX_PACKAGE_BYTES = 64 * 1024;
|
|
5
|
+
const MAX_CHILD_DIRS = 12;
|
|
6
|
+
const MAX_SCRIPTS = 12;
|
|
7
|
+
async function scriptsAt(file) {
|
|
8
|
+
try {
|
|
9
|
+
// O_NOFOLLOW closes the lstat/read race for a symlinked package file on
|
|
10
|
+
// POSIX. Windows does not expose it, so the bounded read remains best
|
|
11
|
+
// effort there and the prompt still contains names only.
|
|
12
|
+
const noFollow = typeof constants.O_NOFOLLOW === 'number' ? constants.O_NOFOLLOW : 0;
|
|
13
|
+
const handle = await fs.open(file, constants.O_RDONLY | noFollow);
|
|
14
|
+
let content;
|
|
15
|
+
try {
|
|
16
|
+
const stat = await handle.stat();
|
|
17
|
+
if (!stat.isFile() || stat.size > MAX_PACKAGE_BYTES)
|
|
18
|
+
return undefined;
|
|
19
|
+
content = await handle.readFile('utf8');
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
await handle.close();
|
|
23
|
+
}
|
|
24
|
+
const parsed = JSON.parse(content);
|
|
25
|
+
if (typeof parsed !== 'object' || parsed === null || !('scripts' in parsed))
|
|
26
|
+
return [];
|
|
27
|
+
const scripts = parsed.scripts;
|
|
28
|
+
if (typeof scripts !== 'object' || scripts === null || Array.isArray(scripts))
|
|
29
|
+
return [];
|
|
30
|
+
return Object.entries(scripts).filter(([name, value]) => /^[A-Za-z0-9:._/-]{1,80}$/.test(name) && typeof value === 'string').map(([name]) => name).sort().slice(0, MAX_SCRIPTS);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Read-only, bounded hints for a compact-profile model; never runs a command. */
|
|
37
|
+
export async function projectPreflight(cwd) {
|
|
38
|
+
const packages = [];
|
|
39
|
+
const rootScripts = await scriptsAt(path.join(cwd, 'package.json'));
|
|
40
|
+
if (rootScripts)
|
|
41
|
+
packages.push(`.: ${rootScripts.join(', ') || '(no scripts)'}`);
|
|
42
|
+
try {
|
|
43
|
+
const children = (await fs.readdir(cwd, { withFileTypes: true }))
|
|
44
|
+
.filter(entry => entry.isDirectory() && entry.name.length <= 80 && !entry.name.startsWith('.') && entry.name !== 'node_modules')
|
|
45
|
+
.map(entry => entry.name).sort().slice(0, MAX_CHILD_DIRS);
|
|
46
|
+
for (const child of children) {
|
|
47
|
+
const scripts = await scriptsAt(path.join(cwd, child, 'package.json'));
|
|
48
|
+
if (scripts)
|
|
49
|
+
packages.push(`${child}: ${scripts.join(', ') || '(no scripts)'}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// A missing/unreadable workspace remains a normal tool error later.
|
|
54
|
+
}
|
|
55
|
+
return packages.length ? `<project_preflight>Package scripts by directory (names only; verify before running): ${packages.join(' | ')}</project_preflight>` : '';
|
|
56
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ProviderCapabilities } from '../
|
|
1
|
+
import type { ProviderCapabilities } from '../providerContracts.js';
|
|
2
|
+
export type { ProviderCapabilities } from '../providerContracts.js';
|
|
2
3
|
/**
|
|
3
4
|
* Provider-neutral reasoning-depth levels (the AI SDK `reasoning` enum minus
|
|
4
5
|
* `provider-default`). `'none'` is an explicit request to disable reasoning;
|
|
@@ -7,9 +8,10 @@ import type { ProviderCapabilities } from '../subagent/contracts.js';
|
|
|
7
8
|
export type ReasoningLevel = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
8
9
|
export declare const REASONING_LEVELS: readonly ReasoningLevel[];
|
|
9
10
|
/**
|
|
10
|
-
* Level applied when
|
|
11
|
-
*
|
|
12
|
-
* (
|
|
11
|
+
* Level applied when nothing more specific exists: no session per-model
|
|
12
|
+
* override and no `reasoning` settings key. Users opt out with an explicit
|
|
13
|
+
* `none` (reasoning off) or the stored `provider-default` sentinel (written by
|
|
14
|
+
* `/reasoning unset`); key-absent means this default.
|
|
13
15
|
*/
|
|
14
16
|
export declare const DEFAULT_REASONING_LEVEL: ReasoningLevel;
|
|
15
17
|
/** Value the settings file may store: a level or the `provider-default` sentinel. */
|
|
@@ -24,6 +26,21 @@ export declare function isStoredReasoning(value: unknown): value is StoredReason
|
|
|
24
26
|
*/
|
|
25
27
|
export declare function effectiveRequestedReasoning(setting: StoredReasoningSetting | undefined): ReasoningLevel | undefined;
|
|
26
28
|
export type EffectiveReasoning = ReasoningLevel | 'disabled';
|
|
29
|
+
export type ReasoningSource = 'session' | 'settings' | 'default';
|
|
30
|
+
export interface ResolvedReasoningChoice {
|
|
31
|
+
/** The winning stored value, if any (undefined when nothing was set). */
|
|
32
|
+
setting: StoredReasoningSetting | undefined;
|
|
33
|
+
/** The level that will be requested; undefined when the sentinel means "send no parameter". */
|
|
34
|
+
level: ReasoningLevel | undefined;
|
|
35
|
+
/** Where the winner came from. */
|
|
36
|
+
source: ReasoningSource;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Resolve the reasoning choice for one model: the session per-model override
|
|
40
|
+
* (`/reasoning`, keyed `provider:model`) wins, then the global `reasoning`
|
|
41
|
+
* setting, then the built-in default. Pure; callers pass validated values.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveReasoningChoice(sessionOverride: StoredReasoningSetting | undefined, storedSetting: StoredReasoningSetting | undefined): ResolvedReasoningChoice;
|
|
27
44
|
export interface ResolvedReasoningPolicy {
|
|
28
45
|
/** What the user requested, if anything. */
|
|
29
46
|
requested: ReasoningLevel | undefined;
|
|
@@ -49,6 +66,19 @@ export declare function resolveReasoningPolicy(input: {
|
|
|
49
66
|
* stays in the return type for forward compatibility.
|
|
50
67
|
*/
|
|
51
68
|
export declare function reasoningCallSetting(policy: ResolvedReasoningPolicy): ReasoningLevel | 'provider-default' | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The single pure resolver for the full reasoning precedence chain
|
|
71
|
+
* (AGENTS-documented order): run-scoped override → session per-model map
|
|
72
|
+
* (`provider:model`, in-memory only) → saved global `reasoning` setting →
|
|
73
|
+
* built-in default. `llm/client.ts` calls this; `/reasoning` and the status
|
|
74
|
+
* bar call `resolveReasoningChoice` on the same inputs.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveAttemptReasoning(input: {
|
|
77
|
+
modelSelector: string;
|
|
78
|
+
runOverride?: StoredReasoningSetting;
|
|
79
|
+
sessionReasoningByModel?: Record<string, StoredReasoningSetting>;
|
|
80
|
+
globalSetting?: StoredReasoningSetting;
|
|
81
|
+
}): StoredReasoningSetting | undefined;
|
|
52
82
|
export declare function isReasoningLevel(value: unknown): value is ReasoningLevel;
|
|
53
83
|
/** Aliases accepted by CLI paths (`/reasoning`, `--reasoning`) for "send no reasoning parameter". */
|
|
54
84
|
export declare function isReasoningUnsetAlias(value: string): boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export const REASONING_LEVELS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh'];
|
|
2
2
|
/**
|
|
3
|
-
* Level applied when
|
|
4
|
-
*
|
|
5
|
-
* (
|
|
3
|
+
* Level applied when nothing more specific exists: no session per-model
|
|
4
|
+
* override and no `reasoning` settings key. Users opt out with an explicit
|
|
5
|
+
* `none` (reasoning off) or the stored `provider-default` sentinel (written by
|
|
6
|
+
* `/reasoning unset`); key-absent means this default.
|
|
6
7
|
*/
|
|
7
|
-
export const DEFAULT_REASONING_LEVEL = '
|
|
8
|
+
export const DEFAULT_REASONING_LEVEL = 'medium';
|
|
8
9
|
/** Stored sentinel meaning "send no reasoning parameter at all". */
|
|
9
10
|
export const REASONING_PROVIDER_DEFAULT = 'provider-default';
|
|
10
11
|
export function isStoredReasoning(value) {
|
|
@@ -20,6 +21,18 @@ export function effectiveRequestedReasoning(setting) {
|
|
|
20
21
|
return undefined;
|
|
21
22
|
return setting ?? DEFAULT_REASONING_LEVEL;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the reasoning choice for one model: the session per-model override
|
|
26
|
+
* (`/reasoning`, keyed `provider:model`) wins, then the global `reasoning`
|
|
27
|
+
* setting, then the built-in default. Pure; callers pass validated values.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveReasoningChoice(sessionOverride, storedSetting) {
|
|
30
|
+
if (sessionOverride !== undefined)
|
|
31
|
+
return { setting: sessionOverride, level: effectiveRequestedReasoning(sessionOverride), source: 'session' };
|
|
32
|
+
if (storedSetting !== undefined)
|
|
33
|
+
return { setting: storedSetting, level: effectiveRequestedReasoning(storedSetting), source: 'settings' };
|
|
34
|
+
return { setting: undefined, level: DEFAULT_REASONING_LEVEL, source: 'default' };
|
|
35
|
+
}
|
|
23
36
|
/**
|
|
24
37
|
* Resolve a requested reasoning level against provider capabilities. Pure and
|
|
25
38
|
* capability based: only protocols that accept the reasoning parameter receive
|
|
@@ -45,6 +58,16 @@ export function reasoningCallSetting(policy) {
|
|
|
45
58
|
return undefined;
|
|
46
59
|
return policy.effective;
|
|
47
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The single pure resolver for the full reasoning precedence chain
|
|
63
|
+
* (AGENTS-documented order): run-scoped override → session per-model map
|
|
64
|
+
* (`provider:model`, in-memory only) → saved global `reasoning` setting →
|
|
65
|
+
* built-in default. `llm/client.ts` calls this; `/reasoning` and the status
|
|
66
|
+
* bar call `resolveReasoningChoice` on the same inputs.
|
|
67
|
+
*/
|
|
68
|
+
export function resolveAttemptReasoning(input) {
|
|
69
|
+
return input.runOverride ?? input.sessionReasoningByModel?.[input.modelSelector] ?? input.globalSetting;
|
|
70
|
+
}
|
|
48
71
|
export function isReasoningLevel(value) {
|
|
49
72
|
return typeof value === 'string' && REASONING_LEVELS.includes(value);
|
|
50
73
|
}
|
|
@@ -22,6 +22,8 @@ export declare function intentExpectsValidation(intent: RequestIntent): boolean;
|
|
|
22
22
|
* a lone line-continuation backslash, and a trailing `--` separator are noise.
|
|
23
23
|
*/
|
|
24
24
|
export declare function validationCommandKey(command: string): string;
|
|
25
|
+
/** Stable, non-reversible identity safe to carry in a goal checkpoint. */
|
|
26
|
+
export declare function validationCheckId(command: string): string;
|
|
25
27
|
/**
|
|
26
28
|
* Opportunistic red→green state for fix intents: no failing repro is required,
|
|
27
29
|
* but when a pre-mutation validation did fail, that same check must pass after
|
|
@@ -36,6 +38,8 @@ export interface WorkState {
|
|
|
36
38
|
intent: RequestIntent;
|
|
37
39
|
normalizedIntent: RequestIntent;
|
|
38
40
|
successCriteria: string[];
|
|
41
|
+
/** Broad requests must declare and finish an outcome list through writeTasks. */
|
|
42
|
+
requiresTaskLedger?: boolean;
|
|
39
43
|
constraints: string[];
|
|
40
44
|
decisions: Array<{
|
|
41
45
|
decision: string;
|
|
@@ -85,6 +89,8 @@ export interface WorkState {
|
|
|
85
89
|
status: 'passed' | 'failed';
|
|
86
90
|
kind?: ValidationKind;
|
|
87
91
|
};
|
|
92
|
+
/** Failed confirmed checks from earlier physical turns, identified without persisting commands. */
|
|
93
|
+
carriedFailedCheckIds?: string[];
|
|
88
94
|
/** Captured pre-mutation failing repro for fix goals. Optional, but same-check green is required when present. */
|
|
89
95
|
redEvidence?: RedEvidence;
|
|
90
96
|
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
@@ -117,6 +123,7 @@ export declare function seedCarriedGoalEvidence(state: WorkState, carried: {
|
|
|
117
123
|
taskProgress?: WorkTaskProgress;
|
|
118
124
|
redEvidence?: RedEvidence;
|
|
119
125
|
validationKind?: ValidationKind;
|
|
126
|
+
failedCheckIds?: string[];
|
|
120
127
|
}): void;
|
|
121
128
|
export interface WorkToolEvent {
|
|
122
129
|
toolName: string;
|
|
@@ -137,5 +144,6 @@ export declare function taskProgressFromOutput(output: unknown, revision: number
|
|
|
137
144
|
* ordering so a result that predates the latest mutation is `stale`.
|
|
138
145
|
*/
|
|
139
146
|
export declare function deriveValidationOutcome(state: WorkState): ValidationOutcome;
|
|
147
|
+
export declare function unresolvedFailedCheckIds(state: WorkState): string[];
|
|
140
148
|
export declare function workStatePrompt(state: WorkState): string;
|
|
141
149
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import { isValidationSummary } from '../../llm/toolResultTypes.js';
|
|
2
3
|
import { toolInputField, toolOutputOk } from './toolResults.js';
|
|
3
4
|
import { workspacePathKey } from '../../utils/path.js';
|
|
4
|
-
import { isSingleForegroundCommand } from '../safety/shellClassifier.js';
|
|
5
|
+
import { isSingleForegroundCommand, stripQuotedSpans } from '../safety/shellClassifier.js';
|
|
6
|
+
import { inferValidationKind } from '../validation/outputParser.js';
|
|
5
7
|
import { changedPathsFromTool } from './toolCapabilities.js';
|
|
6
8
|
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
7
9
|
export function intentExpectsValidation(intent) {
|
|
@@ -30,7 +32,99 @@ export function validationCommandKey(command) {
|
|
|
30
32
|
}
|
|
31
33
|
while (words.length > 1 && words.at(-1) === '--')
|
|
32
34
|
words.pop();
|
|
33
|
-
|
|
35
|
+
const normalized = words.join(' ');
|
|
36
|
+
// npm's --prefix form and a simple `cd` wrapper address the same package.
|
|
37
|
+
// Keep this deliberately narrow: parsing arbitrary shell syntax would risk
|
|
38
|
+
// treating unrelated checks as interchangeable.
|
|
39
|
+
const cdNpm = /^cd ([A-Za-z0-9_./-]+) && npm (.+)$/.exec(normalized);
|
|
40
|
+
const prefixNpm = /^npm --prefix ([A-Za-z0-9_./-]+) (.+)$/.exec(normalized);
|
|
41
|
+
const match = cdNpm ?? prefixNpm;
|
|
42
|
+
// `cd` changes the directory for subsequent stages; --prefix does not.
|
|
43
|
+
// Only normalize a single npm invocation, never a compound command.
|
|
44
|
+
return match && isSingleForegroundCommand(match[2])
|
|
45
|
+
? `npm@${workspacePathKey(match[1])} ${match[2]}` : normalized;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Split an `&&`-chained command into per-stage validation identities, or
|
|
49
|
+
* undefined when the command must stay whole (R2-08). `&&` means every stage
|
|
50
|
+
* ran to success or the chain stopped at its first failure — so a green `&&`
|
|
51
|
+
* chain is green evidence for every stage, and each stage is separately
|
|
52
|
+
* clearable by kind+scope. Not split:
|
|
53
|
+
* - `cd pkg && npm x` — a single path-scoped invocation already normalized by
|
|
54
|
+
* `validationCommandKey`;
|
|
55
|
+
* - `;`/`||` chains — their stages' exit statuses are independent, so the
|
|
56
|
+
* whole chain keeps one opaque compound identity.
|
|
57
|
+
* A leading `cd DIR` stage is composed into each later stage so
|
|
58
|
+
* `cd web && npm test && npm run lint` keeps web-scoped check identities.
|
|
59
|
+
*/
|
|
60
|
+
function validationStages(command) {
|
|
61
|
+
if (validationCommandKey(command).startsWith('npm@'))
|
|
62
|
+
return undefined;
|
|
63
|
+
const unquoted = stripQuotedSpans(command);
|
|
64
|
+
if (!unquoted.includes('&&') || /;|\|\|/.test(unquoted))
|
|
65
|
+
return undefined;
|
|
66
|
+
// stripQuotedSpans blanked quoted text, so split on it and slice the original
|
|
67
|
+
// by part lengths — quoted `&&` stays inside its stage.
|
|
68
|
+
const parts = unquoted.split('&&');
|
|
69
|
+
const stages = [];
|
|
70
|
+
let index = 0;
|
|
71
|
+
for (const part of parts) {
|
|
72
|
+
const stage = command.slice(index, index + part.length).trim();
|
|
73
|
+
if (stage)
|
|
74
|
+
stages.push(stage);
|
|
75
|
+
index += part.length + 2;
|
|
76
|
+
}
|
|
77
|
+
if (stages.length < 2)
|
|
78
|
+
return undefined;
|
|
79
|
+
const cd = /^cd ([A-Za-z0-9_./-]+)$/.exec(stages[0]);
|
|
80
|
+
return cd ? stages.slice(1).map(stage => `${cd[0]} && ${stage}`) : stages;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Scope identity for failed-check pairing: the check kind plus, for package
|
|
84
|
+
* managers, the package root the check ran against. A failed check stays open
|
|
85
|
+
* until an equivalent check in the same scope passes — the observed failure
|
|
86
|
+
* mode (2026-10-04 goal `on373gg0l1e`) was a red `npm test -- tests/x | tail`
|
|
87
|
+
* and a green bare `npm test` that could never pair because the exact command
|
|
88
|
+
* text differed. Scope deliberately broad: the same suite passed from the same
|
|
89
|
+
* package root is the same check. Arguments are noise a model legitimately
|
|
90
|
+
* varies between runs (`-- tests/foo`, `| tail -25`, `2>&1`).
|
|
91
|
+
*/
|
|
92
|
+
function failedCheckScope(command) {
|
|
93
|
+
// Run on the normalized key so `cd pkg && npm test` and `npm --prefix pkg test`
|
|
94
|
+
// already agree; only then classify the invocation itself.
|
|
95
|
+
const normalized = validationCommandKey(command);
|
|
96
|
+
const scoped = /^npm@(\S+) /.exec(normalized);
|
|
97
|
+
if (scoped)
|
|
98
|
+
return `npm@${scoped[1]}`;
|
|
99
|
+
// `// `&&` compounds are recorded per stage (see andStages)// `&&` compounds are recorded per stage (see andStages)` compounds are recorded per stage (see validationStages), so a stage reaching
|
|
100
|
+
// this function is a single invocation; `;`/`||` chains are a different
|
|
101
|
+
// check than their stages: a red `npm test; npm run lint` must not be cleared
|
|
102
|
+
// by a green bare `npm test`. The compound gets its own hashed (non-reversible)
|
|
103
|
+
// scope.
|
|
104
|
+
if (/;|\|\|/.test(normalized))
|
|
105
|
+
return `compound@${validationCheckId(normalized)}`;
|
|
106
|
+
if (normalized.includes('&&'))
|
|
107
|
+
return `compound@${validationCheckId(normalized)}`;
|
|
108
|
+
const manager = /^(?:npm|npx|pnpm|yarn|bun|bunx|deno)\b/.test(normalized) ? 'npm' : 'direct';
|
|
109
|
+
if (manager === 'npm')
|
|
110
|
+
return `npm@${workspacePathKey('.')}`;
|
|
111
|
+
// Direct commands pair only within the same executable: `cargo test` red
|
|
112
|
+
// pairs with `cargo test` green, never with `pytest`.
|
|
113
|
+
const executable = normalized.split(' ')[0] ?? '';
|
|
114
|
+
return `direct@${workspacePathKey('.')}:${executable}`;
|
|
115
|
+
}
|
|
116
|
+
/** Stable, non-reversible identity safe to carry in a goal checkpoint. */
|
|
117
|
+
export function validationCheckId(command) {
|
|
118
|
+
return crypto.createHash('sha256').update(validationCommandKey(command)).digest('hex').slice(0, 16);
|
|
119
|
+
}
|
|
120
|
+
/** Encode check identity as `scope:kind:hash`. Self-describing so a pass can pair against carried ids without keeping raw commands. */
|
|
121
|
+
function scopedCheckId(command, kind) {
|
|
122
|
+
return `${failedCheckScope(command)}:${kind ?? 'generic'}:${validationCheckId(command)}`;
|
|
123
|
+
}
|
|
124
|
+
/** Scope portion of a check id; unknown/legacy shapes (bare hashes from older checkpoints) map to their own scope so only an exact-text rerun can clear them. */
|
|
125
|
+
function scopeOfCheckId(id) {
|
|
126
|
+
const at = id.indexOf(':');
|
|
127
|
+
return at > 0 ? id.slice(0, at) : id;
|
|
34
128
|
}
|
|
35
129
|
/**
|
|
36
130
|
* Opportunistic red→green state for fix intents: no failing repro is required,
|
|
@@ -63,6 +157,8 @@ export function seedCarriedGoalEvidence(state, carried) {
|
|
|
63
157
|
? { status: 'passed', ...(carried.validationKind ? { kind: carried.validationKind } : {}) }
|
|
64
158
|
: { status: 'failed', ...(carried.validationKind ? { kind: carried.validationKind } : {}) };
|
|
65
159
|
}
|
|
160
|
+
if (carried.failedCheckIds?.length)
|
|
161
|
+
state.carriedFailedCheckIds = [...carried.failedCheckIds];
|
|
66
162
|
// Red→green evidence is goal-scoped and rides the checkpoint across
|
|
67
163
|
// physical turns so a continuation cannot complete while a carried pair
|
|
68
164
|
// stays unsatisfied.
|
|
@@ -95,9 +191,36 @@ function outputSummary(output) {
|
|
|
95
191
|
return `exit ${String(output.code)}`;
|
|
96
192
|
return '';
|
|
97
193
|
}
|
|
194
|
+
/** Kind portion of a check id (`scope:kind:hash`). */
|
|
195
|
+
function kindOfCheckId(id) {
|
|
196
|
+
const parts = id.split(':');
|
|
197
|
+
return parts.length >= 3 ? parts[1] : undefined;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Equivalence rule for failed-check clearing: same package-manager scope and
|
|
201
|
+
* same confirmed kind. Kind matters — a green `npm run build` (build) cannot
|
|
202
|
+
* clear a red `npm test` (test); they are different checks that happen to share
|
|
203
|
+
* the scope. Legacy ids without a kind component only pair with themselves.
|
|
204
|
+
*/
|
|
205
|
+
function checkIdEquivalent(passId, failedId) {
|
|
206
|
+
if (passId === failedId)
|
|
207
|
+
return true;
|
|
208
|
+
const kind = kindOfCheckId(passId);
|
|
209
|
+
return kind != null && kind !== 'generic' && scopeOfCheckId(passId) === scopeOfCheckId(failedId) && kindOfCheckId(failedId) === kind;
|
|
210
|
+
}
|
|
98
211
|
function upsertValidation(state, command, status, summary, kind, revision) {
|
|
99
212
|
// Keep both evidence and status display in execution order when a check reruns.
|
|
100
|
-
|
|
213
|
+
const key = validationCommandKey(command);
|
|
214
|
+
state.validations = state.validations.filter(validation => validationCommandKey(validation.command) !== key);
|
|
215
|
+
// Same-turn failed checks pair across argument variants just like carried ids
|
|
216
|
+
// (R2-07, observed 2026-10-04: a red `npx vitest run tests/x | tail -25` stayed
|
|
217
|
+
// open forever while three green `npm test` runs could never clear it because
|
|
218
|
+
// only the exact command text paired). An authoritative pass clears every
|
|
219
|
+
// equivalent failed entry — same package scope, same confirmed kind.
|
|
220
|
+
if (status === 'passed' && kind && kind !== 'generic') {
|
|
221
|
+
const passId = scopedCheckId(command, kind);
|
|
222
|
+
state.validations = state.validations.filter(validation => !(validation.status === 'failed' && validation.kind != null && validation.kind !== 'generic' && checkIdEquivalent(passId, scopedCheckId(validation.command, validation.kind))));
|
|
223
|
+
}
|
|
101
224
|
state.validations.push({ command, status, summary, revision, ...(kind ? { kind } : {}) });
|
|
102
225
|
state.validationCommands = state.validationCommands.filter(item => item.command !== command);
|
|
103
226
|
state.validationCommands.push({ command, status });
|
|
@@ -226,7 +349,36 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
226
349
|
const passed = summary ? summary.status === 'passed' : ok && exitCode === 0;
|
|
227
350
|
const status = passed ? 'passed' : 'failed';
|
|
228
351
|
const summaryText = summary?.summaryText ?? (passed ? `Executed changed artifact ${artifact} successfully.` : `Changed artifact ${artifact} exited unsuccessfully.`);
|
|
229
|
-
|
|
352
|
+
// `&&` compounds record per stage (R2-08, observed 2026-10-04 goal
|
|
353
|
+
// `78jmtd8ht4r`: red compound `typecheck && eslint && vitest` could never be
|
|
354
|
+
// cleared — a green full chain classified only as its first stage's kind,
|
|
355
|
+
// and the compound scope paired only with byte-identical text, so six green
|
|
356
|
+
// `npm test` runs left the goal permanently `failed` and it paused twice as
|
|
357
|
+
// no-progress). A green `&&` chain proves every stage green, each under its
|
|
358
|
+
// own inferred kind and scope; a red one records every stage failed (the
|
|
359
|
+
// chain stops at the first failure; which stages ran is unverified, so all
|
|
360
|
+
// stages are treated as unresolved — individually clearable by a green rerun).
|
|
361
|
+
const stages = validationStages(command);
|
|
362
|
+
if (stages) {
|
|
363
|
+
for (const stage of stages) {
|
|
364
|
+
upsertValidation(state, stage, status, summaryText, inferValidationKind(stage), seq);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
upsertValidation(state, command, status, summaryText, summary?.kind ?? 'generic', seq);
|
|
369
|
+
}
|
|
370
|
+
if (status === 'passed' && summary && summary.kind !== 'generic') {
|
|
371
|
+
// Clear the failed-check identities this authoritative pass satisfies,
|
|
372
|
+
// not just the exact same command text: a red `npm test -- tests/x | tail`
|
|
373
|
+
// must be cleared by a green bare `npm test` in the same package scope.
|
|
374
|
+
// Generic custom checks never clear — the self-certification guard holds
|
|
375
|
+
// across turn boundaries too. Per-stage `&&` passes clear by their own
|
|
376
|
+
// stage kind/scope.
|
|
377
|
+
const stageIds = stages ? stages.map(stage => scopedCheckId(stage, inferValidationKind(stage))) : [scopedCheckId(command, summary.kind)];
|
|
378
|
+
const passIds = stageIds.filter(id => { const kind = kindOfCheckId(id); return kind != null && kind !== 'generic'; });
|
|
379
|
+
const remaining = state.carriedFailedCheckIds?.filter(id => !passIds.some(passId => checkIdEquivalent(passId, id))) ?? [];
|
|
380
|
+
state.carriedFailedCheckIds = remaining.length ? remaining : undefined;
|
|
381
|
+
}
|
|
230
382
|
state.validationSeq = seq;
|
|
231
383
|
state.phase = 'validating';
|
|
232
384
|
state.lastProgressAt = now;
|
|
@@ -293,7 +445,8 @@ export function taskProgressFromOutput(output, revision) {
|
|
|
293
445
|
export function deriveValidationOutcome(state) {
|
|
294
446
|
const hasValidation = state.validationSeq > 0;
|
|
295
447
|
if (!hasValidation) {
|
|
296
|
-
return intentExpectsValidation(state.normalizedIntent)
|
|
448
|
+
return intentExpectsValidation(state.normalizedIntent) || (state.normalizedIntent === 'unknown' && state.mutationCount > 0)
|
|
449
|
+
? 'absent' : 'not_applicable';
|
|
297
450
|
}
|
|
298
451
|
// A validation is stale when a mutation happened after it. `mutationSeq === 0`
|
|
299
452
|
// means no mutation occurred (e.g. a pure test/run request), so the latest
|
|
@@ -305,6 +458,8 @@ export function deriveValidationOutcome(state) {
|
|
|
305
458
|
const latest = state.validations.at(-1) ?? state.carriedValidation;
|
|
306
459
|
if (latest?.status !== 'passed')
|
|
307
460
|
return 'failed';
|
|
461
|
+
if (unresolvedFailedCheckIds(state).length > 0)
|
|
462
|
+
return 'failed';
|
|
308
463
|
// A self-declared custom check (generic kind, `purpose=validation`) cannot
|
|
309
464
|
// clear a failed classifier-confirmed validation: known test/build commands
|
|
310
465
|
// are the authoritative completion evidence, custom checks supplement them
|
|
@@ -312,11 +467,39 @@ export function deriveValidationOutcome(state) {
|
|
|
312
467
|
// passed an unrelated self-written script and claimed completion). A failed
|
|
313
468
|
// validation carried from a goal checkpoint counts as confirmed too.
|
|
314
469
|
const confirmedFailed = state.validations.some(entry => entry.kind !== 'generic' && entry.status === 'failed')
|
|
315
|
-
|| (state.carriedValidation?.status === 'failed' && state.carriedValidation.kind !== 'generic');
|
|
316
|
-
if (
|
|
470
|
+
|| (latest.kind === 'generic' && !state.carriedFailedCheckIds && state.carriedValidation?.status === 'failed' && state.carriedValidation.kind !== 'generic');
|
|
471
|
+
if (confirmedFailed)
|
|
317
472
|
return 'failed';
|
|
318
473
|
return 'passed';
|
|
319
474
|
}
|
|
475
|
+
export function unresolvedFailedCheckIds(state) {
|
|
476
|
+
const local = state.validations.filter(entry => entry.kind !== 'generic' && entry.status === 'failed').map(entry => scopedCheckId(entry.command, entry.kind));
|
|
477
|
+
// Completion evidence must keep every open identity across turn boundaries.
|
|
478
|
+
// Bound only the model-facing preview, not the authoritative check set.
|
|
479
|
+
return [...new Set([...(state.carriedFailedCheckIds ?? []), ...local])];
|
|
480
|
+
}
|
|
320
481
|
export function workStatePrompt(state) {
|
|
321
|
-
|
|
482
|
+
// Compaction needs a continuity capsule, not a second copy of every file
|
|
483
|
+
// read and validation ever observed. Keep the exact request and open-check
|
|
484
|
+
// identities; the recent conversation still carries detailed tool results.
|
|
485
|
+
const capsule = {
|
|
486
|
+
request: state.originalUserRequest.slice(0, 1_200),
|
|
487
|
+
intent: state.normalizedIntent,
|
|
488
|
+
successCriteria: state.successCriteria.slice(0, 8).map(item => item.slice(0, 160)),
|
|
489
|
+
requiresTaskLedger: state.requiresTaskLedger,
|
|
490
|
+
constraints: state.constraints.slice(0, 8).map(item => item.slice(0, 160)),
|
|
491
|
+
decisions: state.decisions.slice(-5).map(item => ({ decision: item.decision.slice(0, 160), reason: item.reason?.slice(0, 160) })),
|
|
492
|
+
files: state.files.slice(-12).map(file => ({ path: file.path.slice(0, 160), action: file.action })),
|
|
493
|
+
mutationCount: state.mutationCount,
|
|
494
|
+
validationOutcome: deriveValidationOutcome(state),
|
|
495
|
+
openCheckIds: unresolvedFailedCheckIds(state).slice(0, 8),
|
|
496
|
+
openCheckCount: unresolvedFailedCheckIds(state).length,
|
|
497
|
+
// The red-check command is safe checkpoint metadata; without it a compacted
|
|
498
|
+
// model cannot know which command must pass to close the red pair.
|
|
499
|
+
...(state.redEvidence && redPairStatus(state) !== 'satisfied' ? { openRedCheck: state.redEvidence.command.slice(0, 200) } : {}),
|
|
500
|
+
taskProgress: state.taskProgress,
|
|
501
|
+
blockers: state.blockers.slice(-3).map(item => item.slice(0, 160)),
|
|
502
|
+
nextAction: state.nextAction?.slice(0, 200),
|
|
503
|
+
};
|
|
504
|
+
return `<work_state>\n${JSON.stringify(capsule)}\n</work_state>`;
|
|
322
505
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSONValue } from 'ai';
|
|
2
|
+
import type { ReasoningLevel } from './agent/reasoningPolicy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provider protocol capability and request-option types shared by the model
|
|
5
|
+
* client (`llm`), worker runtimes, and reasoning policy. Lives at the core
|
|
6
|
+
* root so neither layer reaches into the other's domain subtrees for them.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProviderCapabilities {
|
|
9
|
+
reportsCacheUsage: boolean;
|
|
10
|
+
supportsPromptCacheKey: boolean;
|
|
11
|
+
supportsExtendedCacheRetention: boolean;
|
|
12
|
+
supportsStickySessionId: boolean;
|
|
13
|
+
supportsServerCompaction: boolean;
|
|
14
|
+
supportsTextVerbosity: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Protocol accepts a reasoning-effort request. Explicit-first: a provider
|
|
17
|
+
* `capabilities.reasoningEffort` override in settings wins. The default is
|
|
18
|
+
* the SDK pass-through (`true`) for hosted OpenAI-compatible endpoints and
|
|
19
|
+
* `false` for loopback/local inference servers, whose own reasoning switches
|
|
20
|
+
* (e.g. LM Studio's `on`/`off`) coerce unsupported levels — even `none` — to
|
|
21
|
+
* `on`, silently inverting the request. `false` omits the parameter entirely.
|
|
22
|
+
*/
|
|
23
|
+
supportsReasoningEffort: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ProviderRequestOptions {
|
|
26
|
+
providerOptions?: Record<string, Record<string, JSONValue | undefined>>;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
/** AI SDK top-level `reasoning` call setting; omitted when unset/unsupported. */
|
|
29
|
+
reasoning?: ReasoningLevel;
|
|
30
|
+
/** Codex subscription requests let the provider manage the output limit. */
|
|
31
|
+
omitMaxOutputTokens?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SessionEntry } from './sessionStore.js';
|
|
2
|
+
export interface SessionReport {
|
|
3
|
+
sessionId?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
models: string[];
|
|
7
|
+
reasoning?: string;
|
|
8
|
+
contextWindowTokens?: number;
|
|
9
|
+
peakInputTokens: number;
|
|
10
|
+
steps: number;
|
|
11
|
+
toolCalls: Record<string, number>;
|
|
12
|
+
failedToolCalls: number;
|
|
13
|
+
failedValidations: Record<string, number>;
|
|
14
|
+
continuations: number;
|
|
15
|
+
compactions: number;
|
|
16
|
+
budgetBoundaries: number;
|
|
17
|
+
goals: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
intent: string;
|
|
20
|
+
cycles: number;
|
|
21
|
+
status: string;
|
|
22
|
+
validation: string;
|
|
23
|
+
openTasks: number;
|
|
24
|
+
mutations: number;
|
|
25
|
+
stopReason?: string;
|
|
26
|
+
gateDecision?: string;
|
|
27
|
+
openCheckCount: number;
|
|
28
|
+
evidenceMismatch?: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
/** Summarize a session without copying prompts, commands, paths, or tool output. */
|
|
32
|
+
export declare function summarizeSessionEntries(entries: readonly SessionEntry[]): SessionReport;
|
|
33
|
+
export declare function formatSessionReport(report: SessionReport, parseErrors?: number): string;
|