@denizokcu/haze 1.2.0 → 1.5.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 +86 -1
- package/README.md +23 -10
- package/SECURITY.md +1 -1
- package/bin/haze.js +27 -7
- 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 +43 -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 +4 -0
- package/dist/cli/chat/liveMessages.d.ts +36 -0
- package/dist/cli/chat/liveMessages.js +64 -0
- package/dist/cli/chat/liveRegion.js +1 -1
- package/dist/cli/chat/messages.js +27 -16
- package/dist/cli/chat/sessionLifecycle.d.ts +5 -2
- package/dist/cli/chat/sessionLifecycle.js +36 -4
- 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.d.ts +1 -1
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +24 -1
- package/dist/cli/chat/wizard/types.d.ts +8 -1
- package/dist/cli/chat/wizardDispatch.js +1 -1
- package/dist/cli/commands/chat.js +277 -193
- package/dist/cli/commands/commandHelp.js +6 -0
- package/dist/cli/commands/commands.d.ts +8 -0
- package/dist/cli/commands/commands.js +13 -0
- package/dist/cli/commands/formatters.d.ts +1 -1
- package/dist/cli/commands/formatters.js +25 -3
- package/dist/cli/commands/logsCommand.js +21 -2
- package/dist/cli/commands/ndjsonSink.d.ts +12 -0
- package/dist/cli/commands/ndjsonSink.js +29 -0
- package/dist/cli/commands/reasoningCommand.d.ts +44 -0
- package/dist/cli/commands/reasoningCommand.js +79 -0
- package/dist/cli/commands/runCommand.d.ts +14 -0
- package/dist/cli/commands/runCommand.js +56 -22
- package/dist/cli/commands/settingsSummary.js +2 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +3 -0
- package/dist/cli/commands/streaming/agentAttempt.js +2 -2
- package/dist/cli/commands/streaming/assistantSegments.d.ts +0 -7
- package/dist/cli/commands/streaming/assistantSegments.js +1 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +13 -9
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +24 -9
- package/dist/cli/commands/streaming/attemptSetup.d.ts +4 -0
- package/dist/cli/commands/streaming/attemptSetup.js +21 -7
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +14 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +4 -2
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +9 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +51 -10
- package/dist/cli/commands/streaming/prepareStep.d.ts +0 -3
- package/dist/cli/commands/streaming/prepareStep.js +14 -5
- 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 +8 -3
- package/dist/cli/commands/streaming.js +46 -21
- package/dist/cli/commands/wizardFlow.d.ts +10 -0
- package/dist/cli/commands/wizardFlow.js +34 -5
- package/dist/cli/index.js +22 -2
- 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/modelDiscovery.js +68 -5
- package/dist/config/providerPresets.d.ts +1 -1
- package/dist/config/providerPresets.js +42 -3
- package/dist/config/settings.d.ts +14 -6
- package/dist/config/settings.js +16 -1
- package/dist/core/agent/budgets.d.ts +13 -17
- package/dist/core/agent/budgets.js +15 -19
- package/dist/core/agent/completionController.d.ts +14 -2
- package/dist/core/agent/completionController.js +48 -3
- package/dist/core/agent/events.d.ts +2 -1
- package/dist/core/agent/goalPolicy.d.ts +17 -0
- package/dist/core/agent/goalPolicy.js +53 -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 +76 -10
- package/dist/core/agent/reasoningPolicy.js +72 -9
- package/dist/core/agent/toolCapabilities.d.ts +3 -3
- package/dist/core/agent/toolCapabilities.js +31 -7
- package/dist/core/agent/workState.d.ts +14 -4
- package/dist/core/agent/workState.js +229 -34
- package/dist/core/deadline.js +22 -24
- package/dist/core/providerContracts.d.ts +29 -0
- package/dist/core/providerContracts.js +1 -0
- package/dist/core/safety/secretPaths.js +10 -7
- package/dist/core/safety/shellClassifier.d.ts +2 -0
- package/dist/core/safety/shellClassifier.js +9 -1
- package/dist/core/session/sessionReport.d.ts +33 -0
- package/dist/core/session/sessionReport.js +121 -0
- package/dist/core/session/sessionSlimming.d.ts +2 -0
- package/dist/core/session/sessionSlimming.js +59 -4
- package/dist/core/session/sessionStore.d.ts +16 -8
- package/dist/core/session/sessionStore.js +71 -34
- package/dist/core/shellOutput/reducers/git.js +7 -2
- package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
- package/dist/core/shellOutput/reducers/validation.js +14 -1
- package/dist/core/shellOutput/registry.js +3 -2
- package/dist/core/subagent/contracts.d.ts +3 -18
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/tasks/taskStorage.js +8 -1
- package/dist/core/validation/outputParser.d.ts +6 -1
- package/dist/core/validation/outputParser.js +30 -2
- package/dist/llm/client.d.ts +6 -3
- package/dist/llm/client.js +28 -11
- package/dist/llm/hazeTools.d.ts +9161 -7135
- package/dist/llm/hazeTools.js +6 -462
- package/dist/llm/lsp/client.d.ts +7 -1
- package/dist/llm/lsp/client.js +58 -9
- package/dist/llm/lsp/pool.d.ts +11 -0
- package/dist/llm/lsp/pool.js +61 -4
- package/dist/llm/lsp/protocol.d.ts +6 -23
- package/dist/llm/lsp/requests.d.ts +54 -60
- package/dist/llm/lsp/requests.js +152 -28
- package/dist/llm/lsp/symbols.d.ts +16 -0
- package/dist/llm/lsp/symbols.js +70 -0
- package/dist/llm/lsp/workspaceEdit.d.ts +43 -0
- package/dist/llm/lsp/workspaceEdit.js +117 -0
- package/dist/llm/lspTools.d.ts +7518 -2859
- package/dist/llm/lspTools.js +195 -110
- package/dist/llm/mcp.js +3 -0
- package/dist/llm/requestContext.d.ts +4 -3
- package/dist/llm/requestContext.js +9 -5
- package/dist/{core/subagent → llm}/subagentRunner.d.ts +13 -9
- package/dist/{core/subagent → llm}/subagentRunner.js +54 -49
- package/dist/llm/systemPrompt.d.ts +11 -1
- package/dist/llm/systemPrompt.js +4 -13
- package/dist/llm/tools/fetchTool.d.ts +34 -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 +34 -30
- package/dist/llm/tools/replaceInFiles.d.ts +105 -0
- package/dist/llm/tools/replaceInFiles.js +131 -0
- package/dist/llm/tools/shellTool.d.ts +34 -30
- package/dist/llm/tools/shellTool.js +8 -4
- package/dist/llm/tools/storedOutputTool.d.ts +4 -0
- package/dist/llm/tools/taskTool.d.ts +4 -0
- package/dist/llm/tools/toolContext.d.ts +3 -29
- package/dist/llm/tools/toolContext.js +56 -53
- 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 +30 -4
- 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/components/useInputSuggestions.js +18 -6
- package/dist/ui/inputBuffer.js +12 -6
- package/dist/ui/textGeometry.d.ts +14 -0
- package/dist/ui/textGeometry.js +31 -0
- package/dist/utils/buildInfo.js +29 -8
- package/dist/utils/fs.js +5 -1
- package/package.json +23 -22
- /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
- /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
|
@@ -1,6 +1,10 @@
|
|
|
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';
|
|
5
|
+
import { isSingleForegroundCommand, stripQuotedSpans } from '../safety/shellClassifier.js';
|
|
6
|
+
import { inferValidationKind } from '../validation/outputParser.js';
|
|
7
|
+
import { changedPathsFromTool } from './toolCapabilities.js';
|
|
4
8
|
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
5
9
|
export function intentExpectsValidation(intent) {
|
|
6
10
|
return intent === 'implement' || intent === 'fix' || intent === 'test';
|
|
@@ -8,15 +12,119 @@ export function intentExpectsValidation(intent) {
|
|
|
8
12
|
/**
|
|
9
13
|
* Normalize a validation command into a matching key so a green run can be
|
|
10
14
|
* bound to the red repro it must supersede (P4). Whitespace-insensitive; a
|
|
11
|
-
* leading `time`/`
|
|
15
|
+
* leading `time`/`nice` prefix, `env` with or without `VAR=value` assignments,
|
|
16
|
+
* a lone line-continuation backslash, and a trailing `--` separator are noise.
|
|
12
17
|
*/
|
|
13
18
|
export function validationCommandKey(command) {
|
|
14
19
|
const words = command.replace(/\s+/g, ' ').trim().split(' ').filter(Boolean);
|
|
15
|
-
while (words.length > 1 && ['time', '
|
|
20
|
+
while (words.length > 1 && ['time', 'nice', '\\'].includes(words[0]))
|
|
16
21
|
words.shift();
|
|
22
|
+
// `env` — bare, with flags, or with `VAR=value` assignments — is wrapper
|
|
23
|
+
// noise for pair matching (R2-06): drop it together with any flag tokens
|
|
24
|
+
// and assignments, keeping at least the command word. `env` is handled here
|
|
25
|
+
// only (not in the loop above) so its assignments are stripped too.
|
|
26
|
+
if (words[0] === 'env') {
|
|
27
|
+
let i = 1;
|
|
28
|
+
while (i < words.length && (words[i].startsWith('-') || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i])))
|
|
29
|
+
i++;
|
|
30
|
+
if (i < words.length)
|
|
31
|
+
words.splice(0, i);
|
|
32
|
+
}
|
|
17
33
|
while (words.length > 1 && words.at(-1) === '--')
|
|
18
34
|
words.pop();
|
|
19
|
-
|
|
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;
|
|
20
128
|
}
|
|
21
129
|
/**
|
|
22
130
|
* Opportunistic red→green state for fix intents: no failing repro is required,
|
|
@@ -45,8 +153,12 @@ export function seedCarriedGoalEvidence(state, carried) {
|
|
|
45
153
|
}
|
|
46
154
|
if (carried.validationOutcome === 'passed' || carried.validationOutcome === 'failed') {
|
|
47
155
|
state.validationSeq = 1;
|
|
48
|
-
state.carriedValidation = carried.validationOutcome === 'passed'
|
|
156
|
+
state.carriedValidation = carried.validationOutcome === 'passed'
|
|
157
|
+
? { status: 'passed', ...(carried.validationKind ? { kind: carried.validationKind } : {}) }
|
|
158
|
+
: { status: 'failed', ...(carried.validationKind ? { kind: carried.validationKind } : {}) };
|
|
49
159
|
}
|
|
160
|
+
if (carried.failedCheckIds?.length)
|
|
161
|
+
state.carriedFailedCheckIds = [...carried.failedCheckIds];
|
|
50
162
|
// Red→green evidence is goal-scoped and rides the checkpoint across
|
|
51
163
|
// physical turns so a continuation cannot complete while a carried pair
|
|
52
164
|
// stays unsatisfied.
|
|
@@ -79,17 +191,39 @@ function outputSummary(output) {
|
|
|
79
191
|
return `exit ${String(output.code)}`;
|
|
80
192
|
return '';
|
|
81
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
|
+
}
|
|
82
211
|
function upsertValidation(state, command, status, summary, kind, revision) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
212
|
+
// Keep both evidence and status display in execution order when a check reruns.
|
|
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
|
+
}
|
|
224
|
+
state.validations.push({ command, status, summary, revision, ...(kind ? { kind } : {}) });
|
|
225
|
+
state.validationCommands = state.validationCommands.filter(item => item.command !== command);
|
|
226
|
+
state.validationCommands.push({ command, status });
|
|
93
227
|
}
|
|
94
228
|
const ARTIFACT_LAUNCHERS = new Set(['node', 'python', 'python3', 'ruby', 'php', 'perl', 'sh', 'bash', 'zsh', 'fish', 'csh', 'tcsh', 'tsx', 'ts-node', 'rscript', 'lua']);
|
|
95
229
|
function shellWords(command) {
|
|
@@ -97,9 +231,9 @@ function shellWords(command) {
|
|
|
97
231
|
.map(word => ((word.startsWith('"') && word.endsWith('"')) || (word.startsWith("'") && word.endsWith("'")) ? word.slice(1, -1) : word));
|
|
98
232
|
}
|
|
99
233
|
/** Strictly recognize direct execution of one file changed during this goal. */
|
|
100
|
-
|
|
234
|
+
function executedMutatedArtifact(command, state) {
|
|
101
235
|
// Chaining and pipelines can mask the artifact's exit status, so they are not evidence.
|
|
102
|
-
if (
|
|
236
|
+
if (!isSingleForegroundCommand(command))
|
|
103
237
|
return undefined;
|
|
104
238
|
const words = shellWords(command.trim());
|
|
105
239
|
if (words.length === 0)
|
|
@@ -188,19 +322,20 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
188
322
|
state.phase = 'inspecting';
|
|
189
323
|
state.lastProgressAt = now;
|
|
190
324
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
325
|
+
const changedPaths = changedPathsFromTool(event.toolName, event.input, event.output, event.success);
|
|
326
|
+
for (const changedPath of changedPaths) {
|
|
327
|
+
upsertFile(state, changedPath, event.toolName === 'writeFile' ? 'created' : 'modified');
|
|
328
|
+
state.blockers = state.blockers.filter(blocker => !blocker.includes(changedPath));
|
|
329
|
+
}
|
|
330
|
+
if (changedPaths.length > 0) {
|
|
331
|
+
state.phase = 'editing';
|
|
332
|
+
state.lastProgressAt = now;
|
|
333
|
+
state.mutationCount += changedPaths.length;
|
|
334
|
+
state.mutationSeq = seq;
|
|
335
|
+
}
|
|
336
|
+
if (!ok && path && ['editFile', 'replaceLines', 'writeFile'].includes(event.toolName)) {
|
|
337
|
+
state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
|
|
338
|
+
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
204
339
|
}
|
|
205
340
|
// Classifier-confirmed test/build commands are validation. A direct execution
|
|
206
341
|
// of a file changed during this goal is also bounded runtime evidence, provided
|
|
@@ -214,7 +349,36 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
214
349
|
const passed = summary ? summary.status === 'passed' : ok && exitCode === 0;
|
|
215
350
|
const status = passed ? 'passed' : 'failed';
|
|
216
351
|
const summaryText = summary?.summaryText ?? (passed ? `Executed changed artifact ${artifact} successfully.` : `Changed artifact ${artifact} exited unsuccessfully.`);
|
|
217
|
-
|
|
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
|
+
}
|
|
218
382
|
state.validationSeq = seq;
|
|
219
383
|
state.phase = 'validating';
|
|
220
384
|
state.lastProgressAt = now;
|
|
@@ -281,7 +445,8 @@ export function taskProgressFromOutput(output, revision) {
|
|
|
281
445
|
export function deriveValidationOutcome(state) {
|
|
282
446
|
const hasValidation = state.validationSeq > 0;
|
|
283
447
|
if (!hasValidation) {
|
|
284
|
-
return intentExpectsValidation(state.normalizedIntent)
|
|
448
|
+
return intentExpectsValidation(state.normalizedIntent) || (state.normalizedIntent === 'unknown' && state.mutationCount > 0)
|
|
449
|
+
? 'absent' : 'not_applicable';
|
|
285
450
|
}
|
|
286
451
|
// A validation is stale when a mutation happened after it. `mutationSeq === 0`
|
|
287
452
|
// means no mutation occurred (e.g. a pure test/run request), so the latest
|
|
@@ -293,6 +458,8 @@ export function deriveValidationOutcome(state) {
|
|
|
293
458
|
const latest = state.validations.at(-1) ?? state.carriedValidation;
|
|
294
459
|
if (latest?.status !== 'passed')
|
|
295
460
|
return 'failed';
|
|
461
|
+
if (unresolvedFailedCheckIds(state).length > 0)
|
|
462
|
+
return 'failed';
|
|
296
463
|
// A self-declared custom check (generic kind, `purpose=validation`) cannot
|
|
297
464
|
// clear a failed classifier-confirmed validation: known test/build commands
|
|
298
465
|
// are the authoritative completion evidence, custom checks supplement them
|
|
@@ -300,11 +467,39 @@ export function deriveValidationOutcome(state) {
|
|
|
300
467
|
// passed an unrelated self-written script and claimed completion). A failed
|
|
301
468
|
// validation carried from a goal checkpoint counts as confirmed too.
|
|
302
469
|
const confirmedFailed = state.validations.some(entry => entry.kind !== 'generic' && entry.status === 'failed')
|
|
303
|
-
|| (state.carriedValidation?.status === 'failed' && state.carriedValidation.kind !== 'generic');
|
|
304
|
-
if (
|
|
470
|
+
|| (latest.kind === 'generic' && !state.carriedFailedCheckIds && state.carriedValidation?.status === 'failed' && state.carriedValidation.kind !== 'generic');
|
|
471
|
+
if (confirmedFailed)
|
|
305
472
|
return 'failed';
|
|
306
473
|
return 'passed';
|
|
307
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
|
+
}
|
|
308
481
|
export function workStatePrompt(state) {
|
|
309
|
-
|
|
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>`;
|
|
310
505
|
}
|
package/dist/core/deadline.js
CHANGED
|
@@ -24,37 +24,41 @@ export function withToolDeadline(execute, timeoutMs, signal) {
|
|
|
24
24
|
settled = true;
|
|
25
25
|
if (handle.timer)
|
|
26
26
|
clearTimeout(handle.timer);
|
|
27
|
+
signal?.removeEventListener('abort', onAbort);
|
|
27
28
|
action();
|
|
28
29
|
};
|
|
29
|
-
const quarantineLate = () => {
|
|
30
|
-
// Swallow the eventual resolution/rejection of an abort-ignoring tool so
|
|
31
|
-
// it cannot surface as an unhandled rejection after the wrapper returned.
|
|
32
|
-
work.catch(() => undefined);
|
|
33
|
-
};
|
|
34
30
|
const fire = (message) => settle(() => {
|
|
35
|
-
quarantineLate();
|
|
36
31
|
resolve({ ok: false, [TOOL_DEADLINE_EXCEEDED]: true, error: message });
|
|
37
32
|
});
|
|
38
|
-
const
|
|
33
|
+
const onAbort = () => fire('Tool execution was aborted.');
|
|
34
|
+
if (signal?.aborted)
|
|
35
|
+
return onAbort();
|
|
36
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
39
37
|
handle.timer = setTimeout(() => fire(`Tool execution exceeded the ${timeoutMs}ms deadline.`), timeoutMs);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
// Attach both handlers even when cancellation wins; late rejection is handled.
|
|
39
|
+
try {
|
|
40
|
+
execute().then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
settle(() => reject(error));
|
|
44
44
|
}
|
|
45
|
-
work.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
export function createAbsoluteDeadline(input) {
|
|
49
48
|
const { timeoutMs, signal, onTimeout } = input;
|
|
50
|
-
let
|
|
49
|
+
let disposed = false;
|
|
51
50
|
let timer;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
return;
|
|
55
|
-
fired = true;
|
|
51
|
+
const clear = () => {
|
|
52
|
+
disposed = true;
|
|
56
53
|
if (timer)
|
|
57
54
|
clearTimeout(timer);
|
|
55
|
+
timer = undefined;
|
|
56
|
+
signal?.removeEventListener('abort', fire);
|
|
57
|
+
};
|
|
58
|
+
const fire = () => {
|
|
59
|
+
if (disposed)
|
|
60
|
+
return;
|
|
61
|
+
clear();
|
|
58
62
|
onTimeout();
|
|
59
63
|
};
|
|
60
64
|
timer = setTimeout(fire, timeoutMs);
|
|
@@ -64,11 +68,5 @@ export function createAbsoluteDeadline(input) {
|
|
|
64
68
|
else
|
|
65
69
|
signal.addEventListener('abort', fire, { once: true });
|
|
66
70
|
}
|
|
67
|
-
return {
|
|
68
|
-
clear: () => {
|
|
69
|
-
if (timer)
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
timer = undefined;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
71
|
+
return { clear };
|
|
74
72
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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. The AI SDK maps its top-level
|
|
17
|
+
* `reasoning` parameter per provider; endpoints without native support ignore
|
|
18
|
+
* the field. Kept as a capability so a future provider kind can opt out.
|
|
19
|
+
*/
|
|
20
|
+
supportsReasoningEffort: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ProviderRequestOptions {
|
|
23
|
+
providerOptions?: Record<string, Record<string, JSONValue | undefined>>;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/** AI SDK top-level `reasoning` call setting; omitted when unset/unsupported. */
|
|
26
|
+
reasoning?: ReasoningLevel;
|
|
27
|
+
/** Codex subscription requests let the provider manage the output limit. */
|
|
28
|
+
omitMaxOutputTokens?: boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -105,11 +105,14 @@ export function isProtectedSecretPath(candidatePath, homeDir = os.homedir()) {
|
|
|
105
105
|
* remain readable through targeted `readFile` calls.
|
|
106
106
|
*/
|
|
107
107
|
export function secretSearchExcludeGlobs() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
// Search conservatively excludes home-store names wherever encountered.
|
|
109
|
+
// Negated-only globs cannot express an exception without widening traversal.
|
|
110
|
+
return [...new Set([
|
|
111
|
+
...ENV_STEMS.flatMap(stem => [`!${stem}`, `!${stem}.*`]),
|
|
112
|
+
...SSH_KEY_STEMS.map(stem => `!${stem}*`),
|
|
113
|
+
...PROTECTED_EXTENSIONS.map(extension => `!*${extension}`),
|
|
114
|
+
...[...PROTECTED_BASENAMES].map(name => `!${name}`),
|
|
115
|
+
...PROTECTED_HOME_DIRS.flatMap(directory => [`!**/${directory}`, `!**/${directory}/**`]),
|
|
116
|
+
...PROTECTED_HOME_FILES.map(file => `!**/${file}`),
|
|
117
|
+
])];
|
|
115
118
|
}
|
|
@@ -23,5 +23,7 @@ export declare function stripQuotedSpans(command: string): string;
|
|
|
23
23
|
* (`2>&1`, `&>`, `<&`) are not list operators and are excluded. Pipelines are
|
|
24
24
|
* covered separately by `pipefail`; `&&` propagates failures.
|
|
25
25
|
*/
|
|
26
|
+
/** Conservative output/exit ownership check, not a shell parser or execution gate. */
|
|
27
|
+
export declare function isSingleForegroundCommand(command: string): boolean;
|
|
26
28
|
export declare function commandMasksValidationExit(command: string): boolean;
|
|
27
29
|
export {};
|
|
@@ -101,9 +101,17 @@ export function stripQuotedSpans(command) {
|
|
|
101
101
|
* (`2>&1`, `&>`, `<&`) are not list operators and are excluded. Pipelines are
|
|
102
102
|
* covered separately by `pipefail`; `&&` propagates failures.
|
|
103
103
|
*/
|
|
104
|
+
/** Conservative output/exit ownership check, not a shell parser or execution gate. */
|
|
105
|
+
export function isSingleForegroundCommand(command) {
|
|
106
|
+
// Expansions and escapes can change token boundaries; decline ambiguous shapes.
|
|
107
|
+
if (/[\\`$]/.test(command))
|
|
108
|
+
return false;
|
|
109
|
+
const shape = stripQuotedSpans(command);
|
|
110
|
+
return !commandMasksValidationExit(command) && !/[&|<>\r\n#(){}"']/.test(shape);
|
|
111
|
+
}
|
|
104
112
|
export function commandMasksValidationExit(command) {
|
|
105
113
|
const unquoted = stripQuotedSpans(command);
|
|
106
|
-
if (unquoted
|
|
114
|
+
if (/[;\r\n]/.test(unquoted))
|
|
107
115
|
return true;
|
|
108
116
|
if (/(?<!\|)\|\|(?!\|)/.test(unquoted))
|
|
109
117
|
return true;
|
|
@@ -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;
|