@denizokcu/haze 0.10.0 → 1.0.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 +100 -1
- package/README.md +77 -27
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -4
- package/dist/cli/chat/messages.js +218 -35
- package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
- package/dist/cli/chat/sessionLifecycle.js +64 -14
- package/dist/cli/chat/sessionRecorder.js +75 -7
- package/dist/cli/chat/startupInfo.d.ts +0 -1
- package/dist/cli/chat/startupInfo.js +11 -15
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +349 -133
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +216 -172
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commands.d.ts +2 -0
- package/dist/cli/commands/commands.js +10 -5
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +8 -25
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +9 -2
- package/dist/cli/commands/providerWizard.js +39 -7
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/skillsWizard.d.ts +41 -0
- package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
- package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
- package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
- package/dist/cli/commands/streaming/attemptSetup.js +167 -0
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +130 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
- package/dist/cli/commands/streaming/stallRecovery.js +105 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
- package/dist/cli/commands/streaming/streamLoop.js +448 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -0
- package/dist/cli/commands/streaming.d.ts +65 -9
- package/dist/cli/commands/streaming.js +133 -430
- package/dist/cli/commands/wizardFlow.d.ts +334 -0
- package/dist/cli/commands/wizardFlow.js +377 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/contextFiles.js +9 -3
- package/dist/config/inputHistory.d.ts +0 -1
- package/dist/config/inputHistory.js +1 -1
- package/dist/config/modelDiscovery.d.ts +36 -0
- package/dist/config/modelDiscovery.js +164 -1
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +39 -7
- package/dist/config/providerPresets.js +371 -100
- package/dist/config/providers.js +2 -0
- package/dist/config/settings.d.ts +43 -0
- package/dist/config/settings.js +12 -0
- package/dist/config/skillSettings.js +4 -4
- package/dist/config/updateCheck.d.ts +0 -1
- package/dist/config/updateCheck.js +1 -1
- package/dist/core/agent/budgets.d.ts +73 -1
- package/dist/core/agent/budgets.js +94 -1
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +224 -0
- package/dist/core/agent/completionController.js +296 -0
- package/dist/core/agent/contextBudget.d.ts +36 -2
- package/dist/core/agent/contextBudget.js +62 -9
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +78 -0
- package/dist/core/agent/goalPolicy.d.ts +47 -0
- package/dist/core/agent/goalPolicy.js +106 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/requestAssembly.d.ts +2 -2
- package/dist/core/agent/requestAssembly.js +16 -4
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +11 -11
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +81 -3
- package/dist/core/agent/workState.js +176 -10
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +27 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/io/boundedRead.js +1 -1
- package/dist/core/limits.d.ts +51 -0
- package/dist/core/limits.js +51 -0
- package/dist/core/log/llmLog.js +8 -1
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +15 -10
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/shellClassifier.d.ts +11 -0
- package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
- package/dist/core/safety/urlGuard.d.ts +1 -1
- package/dist/core/session/sessionSlimming.d.ts +0 -3
- package/dist/core/session/sessionSlimming.js +2 -3
- package/dist/core/session/sessionStore.d.ts +38 -0
- package/dist/core/session/sessionStore.js +242 -59
- package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
- package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
- package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
- package/dist/core/shellOutput/registry.d.ts +2 -0
- package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
- package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
- package/dist/core/subagent/contracts.d.ts +6 -14
- package/dist/core/subagent/contracts.js +4 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +19 -40
- package/dist/core/toolOutput/reduction.d.ts +0 -12
- package/dist/core/toolOutput/reduction.js +1 -1
- package/dist/core/validation/outputParser.d.ts +2 -2
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +86 -14
- package/dist/llm/hazeTools.d.ts +693 -204
- package/dist/llm/hazeTools.js +110 -28
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp/client.d.ts +45 -0
- package/dist/llm/lsp/client.js +195 -0
- package/dist/llm/lsp/pool.d.ts +23 -0
- package/dist/llm/lsp/pool.js +86 -0
- package/dist/llm/lsp/protocol.d.ts +64 -0
- package/dist/llm/lsp/protocol.js +128 -0
- package/dist/llm/lsp/requests.d.ts +94 -0
- package/dist/llm/lsp/requests.js +119 -0
- package/dist/llm/lspTools.d.ts +5653 -33
- package/dist/llm/lspTools.js +152 -80
- package/dist/llm/openaiCodex.d.ts +1 -0
- package/dist/llm/openaiCodex.js +43 -0
- package/dist/llm/openaiCodexOAuth.d.ts +51 -0
- package/dist/llm/openaiCodexOAuth.js +217 -0
- package/dist/llm/requestContext.d.ts +7 -0
- package/dist/llm/requestContext.js +30 -4
- package/dist/llm/systemPrompt.d.ts +12 -0
- package/dist/llm/systemPrompt.js +24 -11
- package/dist/llm/toolResultTypes.d.ts +7 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +14 -9
- package/dist/llm/tools/editMatch.js +73 -1
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +8 -5
- package/dist/llm/tools/fileToolShared.js +22 -23
- package/dist/llm/tools/gitIgnore.d.ts +42 -0
- package/dist/llm/tools/gitIgnore.js +247 -0
- package/dist/llm/tools/grepParse.d.ts +2 -1
- package/dist/llm/tools/grepRunner.d.ts +1 -1
- package/dist/llm/tools/grepRunner.js +2 -2
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -3
- package/dist/llm/tools/processTool.d.ts +16 -16
- package/dist/llm/tools/processTool.js +1 -1
- package/dist/llm/tools/readRecovery.d.ts +8 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
- package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +66 -37
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +18 -1
- package/dist/llm/webFetch.js +64 -97
- package/dist/skills/SkillLoader.d.ts +1 -11
- package/dist/skills/SkillLoader.js +1 -2
- package/dist/skills/types.d.ts +2 -1
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +8 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +97 -0
- package/dist/utils/buildInfo.js +244 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.js +91 -26
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +6 -2
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +28 -21
- package/dist/cli/commands/lspWizard.d.ts +0 -14
- package/dist/cli/commands/lspWizard.js +0 -44
- package/dist/cli/commands/mcpWizard.d.ts +0 -15
- package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
- package/dist/cli/commands/skillConfirmRemove.js +0 -20
- package/dist/cli/commands/skillCreation.d.ts +0 -12
- package/dist/cli/commands/skillCreation.js +0 -14
- package/dist/cli/commands/skillWizard.d.ts +0 -17
- package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
- package/dist/cli/commands/streaming/idleTimer.js +0 -24
- package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
- package/dist/cli/commands/streaming/turnOutcome.js +0 -13
- package/dist/cli/commands/wizardActions.d.ts +0 -46
- package/dist/cli/commands/wizardActions.js +0 -46
- package/dist/cli/commands/wizardInput.d.ts +0 -4
- package/dist/cli/commands/wizardInput.js +0 -19
- package/dist/cli/commands/wizardPrompts.d.ts +0 -22
- package/dist/cli/commands/wizardPrompts.js +0 -52
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -188
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/bashOutput/ansi.d.ts +0 -1
- package/dist/core/bashOutput/ansi.js +0 -7
- package/dist/core/bashOutput/registry.d.ts +0 -4
- package/dist/core/goal/completionPolicy.d.ts +0 -2
- package/dist/core/goal/completionPolicy.js +0 -7
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -18
- package/dist/core/goal/sessionGoal.d.ts +0 -8
- package/dist/core/goal/sessionGoal.js +0 -30
- package/dist/core/limits/byteBudgets.d.ts +0 -18
- package/dist/core/limits/byteBudgets.js +0 -18
- package/dist/core/limits/textBudgets.d.ts +0 -23
- package/dist/core/limits/textBudgets.js +0 -23
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -129
- package/dist/llm/lsp.js +0 -307
- package/dist/ui/components/ErrorView.d.ts +0 -4
- package/dist/ui/components/ErrorView.js +0 -7
- package/dist/utils/yaml.d.ts +0 -2
- package/dist/utils/yaml.js +0 -8
- package/examples/skills/files/SKILL.md +0 -16
- package/examples/skills/files/examples/file-editing.md +0 -3
- /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
|
@@ -19,11 +19,23 @@ export declare function isFailedToolOutput(output: unknown): boolean;
|
|
|
19
19
|
* counts as OK only when the call succeeded AND did not report `{ok: false}`.
|
|
20
20
|
*/
|
|
21
21
|
export declare function toolOutputOk(output: unknown, success: boolean): boolean;
|
|
22
|
+
export interface SafeToolFailureDetails {
|
|
23
|
+
errorCode?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract a bounded diagnostic from Haze's structured failure shape. Generic
|
|
28
|
+
* third-party tool outputs are intentionally ignored because their error fields
|
|
29
|
+
* may contain arbitrary remote content or secrets.
|
|
30
|
+
*/
|
|
31
|
+
export declare function safeToolFailureDetails(output: unknown): SafeToolFailureDetails;
|
|
22
32
|
/**
|
|
23
33
|
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
24
34
|
* for non-objects, missing keys, or non-string values.
|
|
25
35
|
*/
|
|
26
36
|
export declare function toolInputField(input: unknown, key: string): string | undefined;
|
|
37
|
+
/** A mutation failure needs a fresh file read only when it explicitly says so. */
|
|
38
|
+
export declare function requiresReadFileRecovery(value: unknown): boolean;
|
|
27
39
|
/**
|
|
28
40
|
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
29
41
|
* instead of re-running. Lets observers treat them as no-ops.
|
|
@@ -23,6 +23,39 @@ export function isFailedToolOutput(output) {
|
|
|
23
23
|
export function toolOutputOk(output, success) {
|
|
24
24
|
return success && !isFailedToolOutput(output);
|
|
25
25
|
}
|
|
26
|
+
const MAX_PUBLIC_TOOL_ERROR_CHARS = 500;
|
|
27
|
+
const SAFE_ERROR_CODE = /^[a-z0-9_-]{1,80}$/i;
|
|
28
|
+
function boundedSingleLine(value) {
|
|
29
|
+
const normalized = value.replace(/\p{Cc}+/gu, ' ').replace(/\s+/g, ' ').trim();
|
|
30
|
+
if (normalized.length <= MAX_PUBLIC_TOOL_ERROR_CHARS)
|
|
31
|
+
return normalized;
|
|
32
|
+
return `${normalized.slice(0, MAX_PUBLIC_TOOL_ERROR_CHARS - 1)}…`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract a bounded diagnostic from Haze's structured failure shape. Generic
|
|
36
|
+
* third-party tool outputs are intentionally ignored because their error fields
|
|
37
|
+
* may contain arbitrary remote content or secrets.
|
|
38
|
+
*/
|
|
39
|
+
export function safeToolFailureDetails(output) {
|
|
40
|
+
if (typeof output !== 'object' || output == null)
|
|
41
|
+
return {};
|
|
42
|
+
const value = output;
|
|
43
|
+
if (value.ok !== false)
|
|
44
|
+
return {};
|
|
45
|
+
const structuredHazeFailure = typeof value.toolName === 'string' && typeof value.recoverable === 'boolean';
|
|
46
|
+
const reasonCode = typeof value.reasonCode === 'string' && SAFE_ERROR_CODE.test(value.reasonCode) ? value.reasonCode : undefined;
|
|
47
|
+
const missingExecutable = typeof value.missingExecutable === 'string' && value.missingExecutable.trim() ? boundedSingleLine(value.missingExecutable) : undefined;
|
|
48
|
+
const errorCode = reasonCode
|
|
49
|
+
?? (missingExecutable ? 'missing_executable'
|
|
50
|
+
: value.timedOut === true ? 'command_timed_out'
|
|
51
|
+
: typeof value.exitCode === 'number' && value.exitCode !== 0 ? 'nonzero_exit'
|
|
52
|
+
: typeof value.signal === 'string' ? 'process_signal'
|
|
53
|
+
: undefined);
|
|
54
|
+
// Only the dedicated Haze failure shape guarantees that `error` is a bounded
|
|
55
|
+
// local diagnostic. Shell stderr and third-party fields may contain secrets.
|
|
56
|
+
const error = structuredHazeFailure && typeof value.error === 'string' ? boundedSingleLine(value.error) : undefined;
|
|
57
|
+
return { ...(errorCode ? { errorCode } : {}), ...(error ? { error } : {}), ...(missingExecutable ? { missingExecutable } : {}) };
|
|
58
|
+
}
|
|
26
59
|
/**
|
|
27
60
|
* Read a string field from an `unknown` tool input object. Returns undefined
|
|
28
61
|
* for non-objects, missing keys, or non-string values.
|
|
@@ -33,6 +66,11 @@ export function toolInputField(input, key) {
|
|
|
33
66
|
const value = input[key];
|
|
34
67
|
return typeof value === 'string' ? value : undefined;
|
|
35
68
|
}
|
|
69
|
+
/** A mutation failure needs a fresh file read only when it explicitly says so. */
|
|
70
|
+
export function requiresReadFileRecovery(value) {
|
|
71
|
+
return typeof value === 'object' && value != null && 'recoveryTool' in value
|
|
72
|
+
&& value.recoveryTool === 'readFile';
|
|
73
|
+
}
|
|
36
74
|
/**
|
|
37
75
|
* Deduplicated read-only tool calls return a `{duplicateSkipped: true}` marker
|
|
38
76
|
* instead of re-running. Lets observers treat them as no-ops.
|
|
@@ -2,6 +2,17 @@ export declare function uniqueRepeatedToolNames(toolCalls: Array<{
|
|
|
2
2
|
toolName: string;
|
|
3
3
|
input: unknown;
|
|
4
4
|
}>): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Return tool names whose latest-step calls repeat an earlier identical call.
|
|
7
|
+
* Restricting only the immediately following step prevents one duplicate from
|
|
8
|
+
* disabling an entire tool category for the rest of the turn.
|
|
9
|
+
*/
|
|
10
|
+
export declare function latestRepeatedToolNames(steps: Array<{
|
|
11
|
+
toolCalls: Array<{
|
|
12
|
+
toolName: string;
|
|
13
|
+
input: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
}>): string[];
|
|
5
16
|
export declare function toolOnlyStepCount(steps: Array<{
|
|
6
17
|
toolCalls: unknown[];
|
|
7
18
|
text: string;
|
|
@@ -12,6 +12,25 @@ export function uniqueRepeatedToolNames(toolCalls) {
|
|
|
12
12
|
}
|
|
13
13
|
return [...repeated];
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Return tool names whose latest-step calls repeat an earlier identical call.
|
|
17
|
+
* Restricting only the immediately following step prevents one duplicate from
|
|
18
|
+
* disabling an entire tool category for the rest of the turn.
|
|
19
|
+
*/
|
|
20
|
+
export function latestRepeatedToolNames(steps) {
|
|
21
|
+
const latest = steps.at(-1);
|
|
22
|
+
if (!latest)
|
|
23
|
+
return [];
|
|
24
|
+
const seen = new Set(steps.slice(0, -1).flatMap(step => step.toolCalls).map(stableToolKey));
|
|
25
|
+
const repeated = new Set();
|
|
26
|
+
for (const toolCall of latest.toolCalls) {
|
|
27
|
+
const key = stableToolKey(toolCall);
|
|
28
|
+
if (seen.has(key))
|
|
29
|
+
repeated.add(toolCall.toolName);
|
|
30
|
+
seen.add(key);
|
|
31
|
+
}
|
|
32
|
+
return [...repeated];
|
|
33
|
+
}
|
|
15
34
|
export function toolOnlyStepCount(steps) {
|
|
16
35
|
let count = 0;
|
|
17
36
|
for (const step of [...steps].reverse()) {
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import type { RequestIntent } from '
|
|
1
|
+
import type { RequestIntent } from './goalPolicy.js';
|
|
2
|
+
import { type ValidationKind, type ValidationSummary } from '../../llm/toolResultTypes.js';
|
|
2
3
|
export type WorkFileAction = 'read' | 'created' | 'modified';
|
|
3
4
|
export type WorkValidationStatus = 'pending' | 'passed' | 'failed';
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
type WorkStatus = 'active' | 'needs-user' | 'blocked' | 'complete' | 'aborted';
|
|
6
|
+
type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
|
|
7
|
+
/**
|
|
8
|
+
* Derived validation outcome for a turn, used as bounded completion evidence.
|
|
9
|
+
* - `passed`: a classifier-confirmed validation passed after the latest mutation.
|
|
10
|
+
* - `failed`: a validation failed and is the most recent result.
|
|
11
|
+
* - `stale`: a validation ran but predates the latest mutation (no longer trustworthy).
|
|
12
|
+
* - `absent`: validation was expected for this request but never ran.
|
|
13
|
+
* - `not_applicable`: the request does not call for validation (answer/review/plan).
|
|
14
|
+
*/
|
|
15
|
+
export type ValidationOutcome = 'passed' | 'failed' | 'stale' | 'absent' | 'not_applicable';
|
|
16
|
+
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
17
|
+
export declare function intentExpectsValidation(intent: RequestIntent): boolean;
|
|
6
18
|
export interface WorkState {
|
|
7
19
|
id: string;
|
|
8
20
|
goal: string;
|
|
@@ -25,11 +37,37 @@ export interface WorkState {
|
|
|
25
37
|
command: string;
|
|
26
38
|
status: Exclude<WorkValidationStatus, 'pending'>;
|
|
27
39
|
summary: string;
|
|
40
|
+
kind?: ValidationKind;
|
|
28
41
|
}>;
|
|
29
42
|
validationCommands: Array<{
|
|
30
43
|
command: string;
|
|
31
44
|
status: WorkValidationStatus;
|
|
32
45
|
}>;
|
|
46
|
+
/** Number of successful workspace mutations observed this turn. */
|
|
47
|
+
mutationCount: number;
|
|
48
|
+
/** Monotonic sequence number of the latest successful mutation (0 = none). */
|
|
49
|
+
mutationSeq: number;
|
|
50
|
+
/** Monotonic sequence number of the latest validation (0 = none). */
|
|
51
|
+
validationSeq: number;
|
|
52
|
+
/**
|
|
53
|
+
* Current-turn task-list evidence, recorded only from a successful `writeTasks`
|
|
54
|
+
* result. Counts only — never task titles or raw output — so malformed tool
|
|
55
|
+
* output can never fabricate or erase completion evidence. Absent when the
|
|
56
|
+
* turn never declared a task list (a stale workspace tasks.json from an
|
|
57
|
+
* earlier turn must not block completion).
|
|
58
|
+
*/
|
|
59
|
+
taskProgress?: WorkTaskProgress;
|
|
60
|
+
/**
|
|
61
|
+
* Validation evidence carried from earlier physical turns of the same
|
|
62
|
+
* logical goal (see the goal supervisor). Used by `deriveValidationOutcome`
|
|
63
|
+
* only while this turn itself has recorded no validation; a fresh
|
|
64
|
+
* validation this turn supersedes it. Bounded to status/kind — never a
|
|
65
|
+
* command or output.
|
|
66
|
+
*/
|
|
67
|
+
carriedValidation?: {
|
|
68
|
+
status: 'passed' | 'failed';
|
|
69
|
+
kind?: ValidationKind;
|
|
70
|
+
};
|
|
33
71
|
/** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
|
|
34
72
|
blockers: string[];
|
|
35
73
|
pending: string[];
|
|
@@ -39,6 +77,35 @@ export interface WorkState {
|
|
|
39
77
|
lastProgressAt: number;
|
|
40
78
|
revision: number;
|
|
41
79
|
}
|
|
80
|
+
/** Compact current-turn task-list evidence parsed from a successful `writeTasks` result. */
|
|
81
|
+
export interface WorkTaskProgress {
|
|
82
|
+
total: number;
|
|
83
|
+
pending: number;
|
|
84
|
+
inProgress: number;
|
|
85
|
+
completed: number;
|
|
86
|
+
/** WorkState revision when this snapshot was recorded. */
|
|
87
|
+
revision: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract bounded task counts from a successful `writeTasks` structured result.
|
|
91
|
+
* Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
|
|
92
|
+
* never titles or raw output. A non-empty list without a fully valid counts
|
|
93
|
+
* breakdown is ignored (rather than guessed) so partial shapes stay inert.
|
|
94
|
+
*/
|
|
95
|
+
export declare function taskProgressFromOutput(output: unknown, revision: number): WorkTaskProgress | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Seed a fresh per-turn work state with cumulative evidence from earlier
|
|
98
|
+
* physical turns of the same logical goal, so a new turn cannot complete while
|
|
99
|
+
* previously-declared tasks remain or previously-made edits still lack fresh
|
|
100
|
+
* validation. Seq baselines keep `deriveValidationOutcome` truthful across the
|
|
101
|
+
* boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
|
|
102
|
+
* carried `passed`/`failed` outcome stands until this turn mutates or validates.
|
|
103
|
+
*/
|
|
104
|
+
export declare function seedCarriedGoalEvidence(state: WorkState, carried: {
|
|
105
|
+
mutationCount: number;
|
|
106
|
+
validationOutcome: ValidationOutcome;
|
|
107
|
+
taskProgress?: WorkTaskProgress;
|
|
108
|
+
}): void;
|
|
42
109
|
export interface WorkToolEvent {
|
|
43
110
|
toolName: string;
|
|
44
111
|
input?: unknown;
|
|
@@ -46,6 +113,17 @@ export interface WorkToolEvent {
|
|
|
46
113
|
output?: unknown;
|
|
47
114
|
duplicateSkipped?: boolean;
|
|
48
115
|
}
|
|
116
|
+
/** Strictly recognize direct execution of one file changed during this goal. */
|
|
117
|
+
export declare function executedMutatedArtifact(command: string, state: WorkState): string | undefined;
|
|
118
|
+
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
119
|
+
export declare function validationSummaryFromOutput(output: unknown): ValidationSummary | undefined;
|
|
49
120
|
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
|
|
50
121
|
export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent, now?: number): WorkState;
|
|
122
|
+
/**
|
|
123
|
+
* Derive the bounded validation outcome for completion evidence.
|
|
124
|
+
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
125
|
+
* ordering so a result that predates the latest mutation is `stale`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function deriveValidationOutcome(state: WorkState): ValidationOutcome;
|
|
51
128
|
export declare function workStatePrompt(state: WorkState): string;
|
|
129
|
+
export {};
|
|
@@ -1,4 +1,67 @@
|
|
|
1
|
+
import { isValidationSummary } from '../../llm/toolResultTypes.js';
|
|
1
2
|
import { toolInputField, toolOutputOk } from './toolResults.js';
|
|
3
|
+
import { workspacePathKey } from '../../utils/path.js';
|
|
4
|
+
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
5
|
+
export function intentExpectsValidation(intent) {
|
|
6
|
+
return intent === 'implement' || intent === 'fix' || intent === 'test';
|
|
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
|
+
/**
|
|
18
|
+
* Extract bounded task counts from a successful `writeTasks` structured result.
|
|
19
|
+
* Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
|
|
20
|
+
* never titles or raw output. A non-empty list without a fully valid counts
|
|
21
|
+
* breakdown is ignored (rather than guessed) so partial shapes stay inert.
|
|
22
|
+
*/
|
|
23
|
+
export function taskProgressFromOutput(output, revision) {
|
|
24
|
+
if (typeof output !== 'object' || output == null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const candidate = output;
|
|
27
|
+
if (candidate.ok !== true)
|
|
28
|
+
return undefined;
|
|
29
|
+
const total = boundedTaskCount(candidate.taskCount);
|
|
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 };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Seed a fresh per-turn work state with cumulative evidence from earlier
|
|
46
|
+
* physical turns of the same logical goal, so a new turn cannot complete while
|
|
47
|
+
* previously-declared tasks remain or previously-made edits still lack fresh
|
|
48
|
+
* validation. Seq baselines keep `deriveValidationOutcome` truthful across the
|
|
49
|
+
* boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
|
|
50
|
+
* carried `passed`/`failed` outcome stands until this turn mutates or validates.
|
|
51
|
+
*/
|
|
52
|
+
export function seedCarriedGoalEvidence(state, carried) {
|
|
53
|
+
if (carried.taskProgress && carried.taskProgress.total > 0) {
|
|
54
|
+
state.taskProgress = { ...carried.taskProgress, revision: 1 };
|
|
55
|
+
}
|
|
56
|
+
if (carried.mutationCount > 0) {
|
|
57
|
+
state.mutationCount = carried.mutationCount;
|
|
58
|
+
state.mutationSeq = 1;
|
|
59
|
+
}
|
|
60
|
+
if (carried.validationOutcome === 'passed' || carried.validationOutcome === 'failed') {
|
|
61
|
+
state.validationSeq = 1;
|
|
62
|
+
state.carriedValidation = carried.validationOutcome === 'passed' ? { status: 'passed' } : { status: 'failed' };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
2
65
|
function upsertFile(state, path, action, note) {
|
|
3
66
|
const existing = state.files.find(file => file.path === path);
|
|
4
67
|
if (existing) {
|
|
@@ -25,18 +88,75 @@ function outputSummary(output) {
|
|
|
25
88
|
return `exit ${String(output.code)}`;
|
|
26
89
|
return '';
|
|
27
90
|
}
|
|
28
|
-
function upsertValidation(state, command, status, summary) {
|
|
91
|
+
function upsertValidation(state, command, status, summary, kind) {
|
|
29
92
|
const existing = state.validations.find(validation => validation.command === command);
|
|
30
93
|
if (existing)
|
|
31
|
-
Object.assign(existing, { status, summary });
|
|
94
|
+
Object.assign(existing, { status, summary, ...(kind ? { kind } : {}) });
|
|
32
95
|
else
|
|
33
|
-
state.validations.push({ command, status, summary });
|
|
96
|
+
state.validations.push({ command, status, summary, ...(kind ? { kind } : {}) });
|
|
34
97
|
const existingCommand = state.validationCommands.find(item => item.command === command);
|
|
35
98
|
if (existingCommand)
|
|
36
99
|
existingCommand.status = status;
|
|
37
100
|
else
|
|
38
101
|
state.validationCommands.push({ command, status });
|
|
39
102
|
}
|
|
103
|
+
const ARTIFACT_LAUNCHERS = new Set(['node', 'python', 'python3', 'ruby', 'php', 'perl', 'sh', 'bash', 'zsh', 'fish', 'csh', 'tcsh', 'tsx', 'ts-node', 'rscript', 'lua']);
|
|
104
|
+
function shellWords(command) {
|
|
105
|
+
return (command.match(/(?:[^\s"']+|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+/g) ?? [])
|
|
106
|
+
.map(word => ((word.startsWith('"') && word.endsWith('"')) || (word.startsWith("'") && word.endsWith("'")) ? word.slice(1, -1) : word));
|
|
107
|
+
}
|
|
108
|
+
/** Strictly recognize direct execution of one file changed during this goal. */
|
|
109
|
+
export function executedMutatedArtifact(command, state) {
|
|
110
|
+
// Chaining and pipelines can mask the artifact's exit status, so they are not evidence.
|
|
111
|
+
if (/&&|\|\||[;|]/.test(command))
|
|
112
|
+
return undefined;
|
|
113
|
+
const words = shellWords(command.trim());
|
|
114
|
+
if (words.length === 0)
|
|
115
|
+
return undefined;
|
|
116
|
+
const executable = words[0].replace(/^.*[\\/]/, '').toLowerCase();
|
|
117
|
+
let candidate;
|
|
118
|
+
if (ARTIFACT_LAUNCHERS.has(executable)) {
|
|
119
|
+
const args = words.slice(1);
|
|
120
|
+
if (args.some(word => ['-e', '--eval', '-c', '-m'].includes(word)))
|
|
121
|
+
return undefined;
|
|
122
|
+
candidate = args.find(word => !word.startsWith('-'));
|
|
123
|
+
}
|
|
124
|
+
else if (executable === 'go' && words[1] === 'run') {
|
|
125
|
+
candidate = words.slice(2).find(word => !word.startsWith('-'));
|
|
126
|
+
}
|
|
127
|
+
else if (executable === 'pwsh' || executable === 'powershell') {
|
|
128
|
+
const fileIndex = words.findIndex(word => word.toLowerCase() === '-file');
|
|
129
|
+
candidate = fileIndex >= 0 ? words[fileIndex + 1] : undefined;
|
|
130
|
+
}
|
|
131
|
+
else if (executable === 'deno' || executable === 'bun') {
|
|
132
|
+
const args = words[1] === 'run' ? words.slice(2) : words.slice(1);
|
|
133
|
+
candidate = args.find(word => !word.startsWith('-'));
|
|
134
|
+
}
|
|
135
|
+
else if (executable === 'java') {
|
|
136
|
+
const jarIndex = words.indexOf('-jar');
|
|
137
|
+
candidate = jarIndex >= 0 ? words[jarIndex + 1] : undefined;
|
|
138
|
+
}
|
|
139
|
+
else if (words[0].startsWith('./') || words[0].startsWith('../')) {
|
|
140
|
+
candidate = words[0];
|
|
141
|
+
}
|
|
142
|
+
if (!candidate)
|
|
143
|
+
return undefined;
|
|
144
|
+
const candidateKey = workspacePathKey(candidate);
|
|
145
|
+
return state.files.find(file => file.action !== 'read' && workspacePathKey(file.path) === candidateKey)?.path;
|
|
146
|
+
}
|
|
147
|
+
function shellExitCode(output) {
|
|
148
|
+
if (typeof output !== 'object' || output == null)
|
|
149
|
+
return undefined;
|
|
150
|
+
const code = output.code;
|
|
151
|
+
return typeof code === 'number' || code === null ? code : undefined;
|
|
152
|
+
}
|
|
153
|
+
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
154
|
+
export function validationSummaryFromOutput(output) {
|
|
155
|
+
if (typeof output !== 'object' || output == null)
|
|
156
|
+
return undefined;
|
|
157
|
+
const candidate = output.validationSummary;
|
|
158
|
+
return isValidationSummary(candidate) ? candidate : undefined;
|
|
159
|
+
}
|
|
40
160
|
export function createWorkState(goal, intent, successCriteria, now = Date.now()) {
|
|
41
161
|
return {
|
|
42
162
|
id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
|
|
@@ -51,6 +171,9 @@ export function createWorkState(goal, intent, successCriteria, now = Date.now())
|
|
|
51
171
|
touchedFiles: [],
|
|
52
172
|
validations: [],
|
|
53
173
|
validationCommands: [],
|
|
174
|
+
mutationCount: 0,
|
|
175
|
+
mutationSeq: 0,
|
|
176
|
+
validationSeq: 0,
|
|
54
177
|
blockers: [],
|
|
55
178
|
pending: [],
|
|
56
179
|
status: 'active',
|
|
@@ -64,6 +187,9 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
64
187
|
return state;
|
|
65
188
|
const ok = toolOutputOk(event.output, event.success);
|
|
66
189
|
const path = toolInputField(event.input, 'path');
|
|
190
|
+
// Monotonic turn-wide clock. mutationSeq/validationSeq snapshot this value so
|
|
191
|
+
// a validation that predates the latest mutation can be marked stale.
|
|
192
|
+
const seq = state.revision + 1;
|
|
67
193
|
if (ok && path && ['listFiles', 'readFile', 'grep'].includes(event.toolName)) {
|
|
68
194
|
if (event.toolName === 'readFile')
|
|
69
195
|
upsertFile(state, path, 'read');
|
|
@@ -77,28 +203,68 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
77
203
|
state.phase = 'editing';
|
|
78
204
|
state.lastProgressAt = now;
|
|
79
205
|
state.blockers = state.blockers.filter(blocker => !blocker.includes(path));
|
|
206
|
+
state.mutationCount += 1;
|
|
207
|
+
state.mutationSeq = seq;
|
|
80
208
|
}
|
|
81
209
|
else {
|
|
82
210
|
state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
|
|
83
211
|
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
84
212
|
}
|
|
85
213
|
}
|
|
86
|
-
|
|
214
|
+
// Classifier-confirmed test/build commands are validation. A direct execution
|
|
215
|
+
// of a file changed during this goal is also bounded runtime evidence, provided
|
|
216
|
+
// the command is not chained or piped (which could mask its exit status).
|
|
217
|
+
if (event.toolName === 'shell') {
|
|
87
218
|
const command = toolInputField(event.input, 'command');
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
219
|
+
const summary = validationSummaryFromOutput(event.output);
|
|
220
|
+
const artifact = command && !summary ? executedMutatedArtifact(command, state) : undefined;
|
|
221
|
+
if (command && (summary || artifact)) {
|
|
222
|
+
const exitCode = shellExitCode(event.output);
|
|
223
|
+
const passed = summary ? summary.status === 'passed' : ok && exitCode === 0;
|
|
224
|
+
const status = passed ? 'passed' : 'failed';
|
|
225
|
+
const summaryText = summary?.summaryText ?? (passed ? `Executed changed artifact ${artifact} successfully.` : `Changed artifact ${artifact} exited unsuccessfully.`);
|
|
226
|
+
upsertValidation(state, command, status, summaryText, summary?.kind ?? 'generic');
|
|
227
|
+
state.validationSeq = seq;
|
|
92
228
|
state.phase = 'validating';
|
|
93
229
|
state.lastProgressAt = now;
|
|
94
|
-
if (
|
|
230
|
+
if (status === 'failed') {
|
|
95
231
|
state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
|
|
96
232
|
}
|
|
97
233
|
}
|
|
98
234
|
}
|
|
99
|
-
|
|
235
|
+
// Task-list coordination: a successful writeTasks result records bounded
|
|
236
|
+
// current-turn task counts as completion evidence. It is not a file mutation,
|
|
237
|
+
// and a failed call leaves prior evidence untouched.
|
|
238
|
+
if (ok && event.toolName === 'writeTasks') {
|
|
239
|
+
const progress = taskProgressFromOutput(event.output, seq);
|
|
240
|
+
if (progress) {
|
|
241
|
+
state.taskProgress = progress;
|
|
242
|
+
state.lastProgressAt = now;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
state.revision = seq;
|
|
100
246
|
return state;
|
|
101
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Derive the bounded validation outcome for completion evidence.
|
|
250
|
+
* See `ValidationOutcome` for the contract. Honors mutation/validation
|
|
251
|
+
* ordering so a result that predates the latest mutation is `stale`.
|
|
252
|
+
*/
|
|
253
|
+
export function deriveValidationOutcome(state) {
|
|
254
|
+
const hasValidation = state.validationSeq > 0;
|
|
255
|
+
if (!hasValidation) {
|
|
256
|
+
return intentExpectsValidation(state.normalizedIntent) ? 'absent' : 'not_applicable';
|
|
257
|
+
}
|
|
258
|
+
// A validation is stale when a mutation happened after it. `mutationSeq === 0`
|
|
259
|
+
// means no mutation occurred (e.g. a pure test/run request), so the latest
|
|
260
|
+
// validation stands on its own. With no validation this turn, a carried
|
|
261
|
+
// outcome from an earlier physical turn of the same logical goal stands in.
|
|
262
|
+
const stale = state.mutationSeq > 0 && state.validationSeq < state.mutationSeq;
|
|
263
|
+
if (stale)
|
|
264
|
+
return 'stale';
|
|
265
|
+
const latest = state.validations.at(-1) ?? state.carriedValidation;
|
|
266
|
+
return latest?.status === 'passed' ? 'passed' : 'failed';
|
|
267
|
+
}
|
|
102
268
|
export function workStatePrompt(state) {
|
|
103
269
|
return `<work_state>\n${JSON.stringify(state)}\n</work_state>`;
|
|
104
270
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { IMAGE_ATTACHMENT_BYTES, IMAGE_ATTACHMENTS_PER_MESSAGE } from '../limits
|
|
4
|
+
import { IMAGE_ATTACHMENT_BYTES, IMAGE_ATTACHMENTS_PER_MESSAGE } from '../limits.js';
|
|
5
5
|
import { workspaceRoot } from '../../utils/path.js';
|
|
6
6
|
import { formatBytes } from '../../utils/format.js';
|
|
7
7
|
/**
|
|
@@ -22,23 +22,75 @@ export const IMAGE_MEDIA_TYPES = {
|
|
|
22
22
|
'.webp': 'image/webp',
|
|
23
23
|
};
|
|
24
24
|
export const IMAGE_EXTENSIONS = Object.keys(IMAGE_MEDIA_TYPES);
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
/** ASCII path-token characters accepted by the chat mention syntax. */
|
|
26
|
+
function isPathTokenCharacter(character) {
|
|
27
|
+
if (!character)
|
|
28
|
+
return false;
|
|
29
|
+
const code = character.charCodeAt(0);
|
|
30
|
+
return (code >= 48 && code <= 57)
|
|
31
|
+
|| (code >= 65 && code <= 90)
|
|
32
|
+
|| (code >= 97 && code <= 122)
|
|
33
|
+
|| character === '_'
|
|
34
|
+
|| character === '.'
|
|
35
|
+
|| character === '/'
|
|
36
|
+
|| character === '~'
|
|
37
|
+
|| character === '-';
|
|
38
|
+
}
|
|
39
|
+
function isWordCharacter(character) {
|
|
40
|
+
if (!character)
|
|
41
|
+
return false;
|
|
42
|
+
const code = character.charCodeAt(0);
|
|
43
|
+
return (code >= 48 && code <= 57)
|
|
44
|
+
|| (code >= 65 && code <= 90)
|
|
45
|
+
|| (code >= 97 && code <= 122)
|
|
46
|
+
|| character === '_';
|
|
47
|
+
}
|
|
48
|
+
/** Scan one path token, retaining backslash escapes verbatim. */
|
|
49
|
+
function pathTokenEnd(text, start) {
|
|
50
|
+
let index = start;
|
|
51
|
+
while (index < text.length) {
|
|
52
|
+
if (isPathTokenCharacter(text[index])) {
|
|
53
|
+
index++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (text[index] === '\\' && index + 1 < text.length && text[index + 1] !== '\n' && text[index + 1] !== '\r') {
|
|
57
|
+
index += 2;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return index;
|
|
63
|
+
}
|
|
64
|
+
/** Linear-time scanner for explicit `@path` mentions. */
|
|
65
|
+
function explicitPathMentions(text) {
|
|
66
|
+
const mentions = [];
|
|
67
|
+
for (let index = 0; index < text.length; index++) {
|
|
68
|
+
if (text[index] !== '@' || isWordCharacter(text[index - 1]) || text[index - 1] === '@')
|
|
69
|
+
continue;
|
|
70
|
+
const end = pathTokenEnd(text, index + 1);
|
|
71
|
+
const token = text.slice(index + 1, end);
|
|
72
|
+
if (token && (token.includes('.') || token.includes('/')))
|
|
73
|
+
mentions.push({ mention: text.slice(index, end), token, start: index, end });
|
|
74
|
+
index = Math.max(index, end - 1);
|
|
75
|
+
}
|
|
76
|
+
return mentions;
|
|
77
|
+
}
|
|
78
|
+
/** Linear-time scanner for bare path tokens containing `/`. */
|
|
79
|
+
function barePathMentions(text) {
|
|
80
|
+
const mentions = [];
|
|
81
|
+
for (let index = 0; index < text.length; index++) {
|
|
82
|
+
const previous = text[index - 1];
|
|
83
|
+
if (!isPathTokenCharacter(text[index]) || isWordCharacter(previous) || previous === '.' || previous === '@' || previous === '/')
|
|
84
|
+
continue;
|
|
85
|
+
const end = pathTokenEnd(text, index);
|
|
86
|
+
const token = text.slice(index, end);
|
|
87
|
+
const next = text[end];
|
|
88
|
+
if (token.includes('/') && !isWordCharacter(next) && next !== '.' && next !== '-')
|
|
89
|
+
mentions.push({ mention: token, token, start: index, end });
|
|
90
|
+
index = Math.max(index, end - 1);
|
|
91
|
+
}
|
|
92
|
+
return mentions;
|
|
93
|
+
}
|
|
42
94
|
/**
|
|
43
95
|
* Extract path-like attachment candidates from prompt text. Two forms are
|
|
44
96
|
* recognised:
|
|
@@ -54,23 +106,11 @@ const BARE_PATH_PATTERN = /(?<![\w.@/])(?=[\w.~/-]*\/)((?:[\w./~-]|\\.)+)(?![\w.
|
|
|
54
106
|
export function extractPathMentions(text) {
|
|
55
107
|
const mentions = [];
|
|
56
108
|
const seen = new Set();
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
if (!token || (!token.includes('.') && !token.includes('/')))
|
|
60
|
-
continue;
|
|
61
|
-
if (seen.has(match[0]))
|
|
109
|
+
for (const candidate of [...explicitPathMentions(text), ...barePathMentions(text)]) {
|
|
110
|
+
if (seen.has(candidate.mention))
|
|
62
111
|
continue;
|
|
63
|
-
seen.add(
|
|
64
|
-
mentions.push({ mention:
|
|
65
|
-
}
|
|
66
|
-
for (const match of text.matchAll(BARE_PATH_PATTERN)) {
|
|
67
|
-
const token = match[1];
|
|
68
|
-
if (!token || !token.includes('/'))
|
|
69
|
-
continue;
|
|
70
|
-
if (seen.has(match[0]))
|
|
71
|
-
continue;
|
|
72
|
-
seen.add(match[0]);
|
|
73
|
-
mentions.push({ mention: match[0], token });
|
|
112
|
+
seen.add(candidate.mention);
|
|
113
|
+
mentions.push({ mention: candidate.mention, token: candidate.token });
|
|
74
114
|
}
|
|
75
115
|
return mentions;
|
|
76
116
|
}
|
|
@@ -190,14 +230,22 @@ export async function resolveImageAttachments(text) {
|
|
|
190
230
|
}
|
|
191
231
|
if (strippedTokens.size === 0)
|
|
192
232
|
return { text, attachments };
|
|
193
|
-
// Strip attached mentions (explicit `@` and bare)
|
|
194
|
-
// space a mid-line removal can leave behind.
|
|
195
|
-
//
|
|
196
|
-
const
|
|
197
|
-
.
|
|
198
|
-
.
|
|
199
|
-
|
|
200
|
-
|
|
233
|
+
// Strip attached mentions (explicit `@` and bare) by their scanner ranges,
|
|
234
|
+
// then tidy the double space a mid-line removal can leave behind. Sorting is
|
|
235
|
+
// needed because extraction preserves explicit-before-bare compatibility.
|
|
236
|
+
const ranges = [...explicitPathMentions(text), ...barePathMentions(text)]
|
|
237
|
+
.filter(candidate => strippedTokens.has(candidate.token))
|
|
238
|
+
.sort((left, right) => left.start - right.start);
|
|
239
|
+
const chunks = [];
|
|
240
|
+
let cursor = 0;
|
|
241
|
+
for (const range of ranges) {
|
|
242
|
+
if (range.start < cursor)
|
|
243
|
+
continue;
|
|
244
|
+
chunks.push(text.slice(cursor, range.start));
|
|
245
|
+
cursor = range.end;
|
|
246
|
+
}
|
|
247
|
+
chunks.push(text.slice(cursor));
|
|
248
|
+
const cleaned = chunks.join('').replace(/(?<=[^\n])[ \t]{2,}/g, ' ').trim();
|
|
201
249
|
return { text: cleaned, attachments };
|
|
202
250
|
}
|
|
203
251
|
/** Build the turn's user message: plain string without attachments, multipart with. */
|