@denizokcu/haze 0.11.0 → 1.1.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 +33 -0
- package/README.md +28 -14
- package/SECURITY.md +5 -3
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/TaskBar.js +1 -1
- package/dist/cli/chat/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/fileMentionSuggestions.js +1 -1
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +10 -41
- package/dist/cli/chat/messages.d.ts +0 -2
- package/dist/cli/chat/messages.js +5 -5
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -1
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +257 -130
- package/dist/cli/commands/chat.js +61 -77
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commandHelp.js +2 -0
- package/dist/cli/commands/commands.js +2 -0
- package/dist/cli/commands/doctor.js +1 -1
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +12 -25
- package/dist/cli/commands/providerWizard.js +2 -3
- package/dist/cli/commands/runCommand.js +1 -1
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/settingsSummary.js +2 -0
- 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 +2 -1
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- 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 +1 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +2 -2
- package/dist/cli/commands/streaming/goalSupervisor.js +9 -6
- 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 +14 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +56 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -1
- 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 +14 -25
- package/dist/cli/commands/streaming.js +43 -754
- package/dist/cli/commands/themesCommand.d.ts +17 -0
- package/dist/cli/commands/themesCommand.js +24 -0
- package/dist/cli/commands/wizardFlow.d.ts +341 -0
- package/dist/cli/commands/wizardFlow.js +397 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.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 +0 -15
- package/dist/config/modelDiscovery.js +1 -1
- package/dist/config/settings.d.ts +9 -0
- package/dist/config/settings.js +4 -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 +63 -1
- package/dist/core/agent/budgets.js +84 -1
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/completionController.d.ts +7 -13
- package/dist/core/agent/completionController.js +17 -8
- package/dist/core/agent/contextBudget.d.ts +0 -4
- package/dist/core/agent/contextBudget.js +3 -3
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +5 -1
- package/dist/core/{goal/completionPolicy.d.ts → agent/goalPolicy.d.ts} +18 -0
- package/dist/core/agent/goalPolicy.js +106 -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 +2 -2
- package/dist/core/agent/toolCapabilities.js +5 -5
- package/dist/core/agent/toolOutputStore.js +1 -1
- package/dist/core/agent/toolResults.js +1 -1
- package/dist/core/agent/workState.d.ts +6 -3
- package/dist/core/agent/workState.js +62 -7
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +0 -6
- package/dist/core/deadline.js +1 -1
- 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 +1 -1
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +10 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/secretPaths.d.ts +18 -0
- package/dist/core/safety/secretPaths.js +115 -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 +1 -0
- package/dist/core/session/sessionStore.js +39 -20
- 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 +2 -14
- package/dist/core/subagent/contracts.js +3 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentRunner.js +3 -4
- 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.js +5 -1
- package/dist/llm/hazeTools.d.ts +139 -124
- package/dist/llm/hazeTools.js +20 -11
- 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 +3824 -570
- package/dist/llm/lspTools.js +65 -1
- package/dist/llm/openaiCodex.d.ts +0 -2
- package/dist/llm/openaiCodex.js +0 -4
- package/dist/llm/openaiCodexOAuth.d.ts +0 -3
- package/dist/llm/openaiCodexOAuth.js +6 -3
- package/dist/llm/requestContext.d.ts +5 -1
- package/dist/llm/requestContext.js +25 -2
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +16 -7
- package/dist/llm/toolResultTypes.d.ts +1 -15
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +0 -9
- package/dist/llm/tools/editMatch.js +1 -1
- package/dist/llm/tools/failures.d.ts +6 -0
- package/dist/llm/tools/failures.js +8 -2
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +4 -2
- package/dist/llm/tools/fileToolShared.js +9 -5
- package/dist/llm/tools/gitIgnore.d.ts +25 -32
- package/dist/llm/tools/gitIgnore.js +216 -98
- 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 +0 -2
- package/dist/llm/tools/readRecovery.js +4 -2
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +123 -107
- package/dist/llm/tools/{bashTool.js → shellTool.js} +18 -14
- package/dist/llm/tools/toolContext.js +5 -5
- package/dist/llm/tools/workspaceFile.d.ts +4 -4
- package/dist/llm/tools/workspaceFile.js +29 -17
- package/dist/llm/webFetch.d.ts +1 -1
- 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/components/Header.js +1 -1
- package/dist/ui/components/MarkdownText.js +10 -10
- package/dist/ui/components/TextInput.d.ts +1 -1
- package/dist/ui/components/TextInput.js +2 -2
- package/dist/ui/terminalColors.d.ts +29 -0
- package/dist/ui/terminalColors.js +47 -0
- package/dist/ui/theme.d.ts +105 -10
- package/dist/ui/theme.js +126 -15
- package/dist/ui/themes/af-magic.d.ts +7 -0
- package/dist/ui/themes/af-magic.js +25 -0
- package/dist/ui/themes/agnoster.d.ts +10 -0
- package/dist/ui/themes/agnoster.js +40 -0
- package/dist/ui/themes/bira.d.ts +10 -0
- package/dist/ui/themes/bira.js +28 -0
- package/dist/ui/themes/bureau.d.ts +10 -0
- package/dist/ui/themes/bureau.js +28 -0
- package/dist/ui/themes/clean.d.ts +9 -0
- package/dist/ui/themes/clean.js +27 -0
- package/dist/ui/themes/cloud.d.ts +6 -0
- package/dist/ui/themes/cloud.js +24 -0
- package/dist/ui/themes/dst.d.ts +10 -0
- package/dist/ui/themes/dst.js +28 -0
- package/dist/ui/themes/fishy.d.ts +7 -0
- package/dist/ui/themes/fishy.js +25 -0
- package/dist/ui/themes/index.d.ts +8 -0
- package/dist/ui/themes/index.js +36 -0
- package/dist/ui/themes/light.d.ts +3 -0
- package/dist/ui/themes/light.js +21 -0
- package/dist/ui/themes/purple.d.ts +7 -0
- package/dist/ui/themes/purple.js +26 -0
- package/dist/ui/themes/robbyrussell.d.ts +8 -0
- package/dist/ui/themes/robbyrussell.js +26 -0
- package/dist/ui/themes/solarized-dark.d.ts +16 -0
- package/dist/ui/themes/solarized-dark.js +44 -0
- package/dist/ui/themes/solarized-light.d.ts +12 -0
- package/dist/ui/themes/solarized-light.js +40 -0
- package/dist/ui/themes/steeef.d.ts +11 -0
- package/dist/ui/themes/steeef.js +29 -0
- package/dist/utils/buildInfo.d.ts +6 -13
- package/dist/utils/buildInfo.js +6 -15
- package/dist/utils/fs.d.ts +7 -5
- package/dist/utils/fs.js +5 -2
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +1 -1
- package/package.json +6 -4
- 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 -27
- package/dist/cli/commands/streaming/turnOutcome.js +0 -29
- package/dist/cli/commands/wizardActions.d.ts +0 -47
- package/dist/cli/commands/wizardActions.js +0 -47
- 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 -58
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -190
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/agent/toolExecutionBudget.d.ts +0 -35
- package/dist/core/agent/toolExecutionBudget.js +0 -49
- package/dist/core/agent/turnBudget.d.ts +0 -35
- package/dist/core/agent/turnBudget.js +0 -27
- 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.js +0 -43
- 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 -20
- package/dist/core/limits/byteBudgets.js +0 -20
- package/dist/core/limits/textBudgets.d.ts +0 -25
- package/dist/core/limits/textBudgets.js +0 -25
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -149
- package/dist/llm/lsp.js +0 -368
- 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
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Capabilities describe what a tool *can do* so turn-policy code can reason
|
|
5
5
|
* about a turn without hard-coding tool names in every decision site. They are
|
|
6
6
|
* metadata for policy/observability, never an execution gate (mirroring the
|
|
7
|
-
*
|
|
8
|
-
* runtime (e.g. a `
|
|
7
|
+
* shell-classifier contract): the actual effect of a call is still determined at
|
|
8
|
+
* runtime (e.g. a `shell` call is only validation when its command is a
|
|
9
9
|
* classifier-confirmed validation command).
|
|
10
10
|
*
|
|
11
11
|
* Kept provider/UI-agnostic (no `ai`/Ink imports) so it is unit-testable in
|
|
@@ -22,10 +22,10 @@ const CAPABILITY_MAP = {
|
|
|
22
22
|
writeFile: ['mutate'],
|
|
23
23
|
editFile: ['mutate'],
|
|
24
24
|
replaceLines: ['mutate'],
|
|
25
|
-
// Process execution. A
|
|
25
|
+
// Process execution. A shell call becomes validation only when its command is
|
|
26
26
|
// a classifier-confirmed validation command (see work state); that runtime
|
|
27
27
|
// fact is tracked separately as a validation event, not as a static trait.
|
|
28
|
-
|
|
28
|
+
shell: ['process'],
|
|
29
29
|
process: ['process'],
|
|
30
30
|
// Coordination / durable state.
|
|
31
31
|
writeTasks: ['coordinate'],
|
|
@@ -49,7 +49,7 @@ export function isMutatingCapability(name) {
|
|
|
49
49
|
}
|
|
50
50
|
/** Tools that can act as a validation step (runtime-classifier dependent). */
|
|
51
51
|
export function isValidationCapable(name) {
|
|
52
|
-
return hasCapability(name, 'validate') || name === '
|
|
52
|
+
return hasCapability(name, 'validate') || name === 'shell';
|
|
53
53
|
}
|
|
54
54
|
/** Read/discovery-only built-in tools (no mutation side effects). */
|
|
55
55
|
export function isReadOrDiscoveryCapability(name) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import { TOOL_OUTPUT_ENTRY_BYTES, TOOL_OUTPUT_TOTAL_BYTES } from '../limits
|
|
2
|
+
import { TOOL_OUTPUT_ENTRY_BYTES, TOOL_OUTPUT_TOTAL_BYTES } from '../limits.js';
|
|
3
3
|
import { truncateUtf8AtBytes } from '../../utils/utf8.js';
|
|
4
4
|
const outputs = new Map();
|
|
5
5
|
const dynamicOutputs = new Map();
|
|
@@ -52,7 +52,7 @@ export function safeToolFailureDetails(output) {
|
|
|
52
52
|
: typeof value.signal === 'string' ? 'process_signal'
|
|
53
53
|
: undefined);
|
|
54
54
|
// Only the dedicated Haze failure shape guarantees that `error` is a bounded
|
|
55
|
-
// local diagnostic.
|
|
55
|
+
// local diagnostic. Shell stderr and third-party fields may contain secrets.
|
|
56
56
|
const error = structuredHazeFailure && typeof value.error === 'string' ? boundedSingleLine(value.error) : undefined;
|
|
57
57
|
return { ...(errorCode ? { errorCode } : {}), ...(error ? { error } : {}), ...(missingExecutable ? { missingExecutable } : {}) };
|
|
58
58
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { RequestIntent } from '
|
|
1
|
+
import type { RequestIntent } from './goalPolicy.js';
|
|
2
2
|
import { type ValidationKind, type ValidationSummary } from '../../llm/toolResultTypes.js';
|
|
3
3
|
export type WorkFileAction = 'read' | 'created' | 'modified';
|
|
4
4
|
export type WorkValidationStatus = 'pending' | 'passed' | 'failed';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type WorkStatus = 'active' | 'needs-user' | 'blocked' | 'complete' | 'aborted';
|
|
6
|
+
type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
|
|
7
7
|
/**
|
|
8
8
|
* Derived validation outcome for a turn, used as bounded completion evidence.
|
|
9
9
|
* - `passed`: a classifier-confirmed validation passed after the latest mutation.
|
|
@@ -113,6 +113,8 @@ export interface WorkToolEvent {
|
|
|
113
113
|
output?: unknown;
|
|
114
114
|
duplicateSkipped?: boolean;
|
|
115
115
|
}
|
|
116
|
+
/** Strictly recognize direct execution of one file changed during this goal. */
|
|
117
|
+
export declare function executedMutatedArtifact(command: string, state: WorkState): string | undefined;
|
|
116
118
|
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
117
119
|
export declare function validationSummaryFromOutput(output: unknown): ValidationSummary | undefined;
|
|
118
120
|
export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
|
|
@@ -124,3 +126,4 @@ export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEv
|
|
|
124
126
|
*/
|
|
125
127
|
export declare function deriveValidationOutcome(state: WorkState): ValidationOutcome;
|
|
126
128
|
export declare function workStatePrompt(state: WorkState): string;
|
|
129
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isValidationSummary } from '../../llm/toolResultTypes.js';
|
|
2
2
|
import { toolInputField, toolOutputOk } from './toolResults.js';
|
|
3
|
+
import { workspacePathKey } from '../../utils/path.js';
|
|
3
4
|
/** Request intents where a missing validation is itself meaningful evidence. */
|
|
4
5
|
export function intentExpectsValidation(intent) {
|
|
5
6
|
return intent === 'implement' || intent === 'fix' || intent === 'test';
|
|
@@ -99,6 +100,56 @@ function upsertValidation(state, command, status, summary, kind) {
|
|
|
99
100
|
else
|
|
100
101
|
state.validationCommands.push({ command, status });
|
|
101
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
|
+
}
|
|
102
153
|
/** Extract a classifier-confirmed validation summary from a tool output, if any. */
|
|
103
154
|
export function validationSummaryFromOutput(output) {
|
|
104
155
|
if (typeof output !== 'object' || output == null)
|
|
@@ -160,15 +211,19 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
|
|
|
160
211
|
state.nextAction = `Read ${path}, then retry the edit with current content.`;
|
|
161
212
|
}
|
|
162
213
|
}
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
if (event.toolName === '
|
|
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') {
|
|
167
218
|
const command = toolInputField(event.input, 'command');
|
|
168
219
|
const summary = validationSummaryFromOutput(event.output);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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');
|
|
172
227
|
state.validationSeq = seq;
|
|
173
228
|
state.phase = 'validating';
|
|
174
229
|
state.lastProgressAt = now;
|
|
@@ -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. */
|
package/dist/core/deadline.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export declare const TOOL_DEADLINE_EXCEEDED = "__hazeToolDeadlineExceeded";
|
|
2
|
-
export interface ToolDeadlineResult {
|
|
3
|
-
ok: false;
|
|
4
|
-
[TOOL_DEADLINE_EXCEEDED]: true;
|
|
5
|
-
error: string;
|
|
6
|
-
}
|
|
7
1
|
/** True when a tool result is the structured "deadline exceeded" placeholder. */
|
|
8
2
|
export declare function isToolDeadlineExceeded(output: unknown): boolean;
|
|
9
3
|
/**
|
package/dist/core/deadline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const TOOL_DEADLINE_EXCEEDED = '__hazeToolDeadlineExceeded';
|
|
2
2
|
/** True when a tool result is the structured "deadline exceeded" placeholder. */
|
|
3
3
|
export function isToolDeadlineExceeded(output) {
|
|
4
4
|
return typeof output === 'object' && output !== null && TOOL_DEADLINE_EXCEEDED in output;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createReadStream } from 'node:fs';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import { StringDecoder } from 'node:string_decoder';
|
|
4
|
-
import { TEXT_LINE_BYTES } from '../limits
|
|
4
|
+
import { TEXT_LINE_BYTES } from '../limits.js';
|
|
5
5
|
async function* iterateBoundedUtf8LinesFrom(file, maxLineBytes, startByte, previousLineNumber) {
|
|
6
6
|
const input = createReadStream(file, startByte > 0 ? { start: startByte } : undefined);
|
|
7
7
|
let lineNumber = previousLineNumber;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized output/resource limits.
|
|
3
|
+
*
|
|
4
|
+
* Byte budgets below bound work performed (process output, file reads, JSONL
|
|
5
|
+
* lines, LSP frames/headers/buffers, stored tool-output handles, skill files,
|
|
6
|
+
* exact-mutation size); the model-facing character caps bound returned/persisted
|
|
7
|
+
* text so callers cite a named constant instead of a magic number (CR-014).
|
|
8
|
+
*
|
|
9
|
+
* Changing a value changes availability/memory behavior; mention user-visible
|
|
10
|
+
* changes in `CHANGELOG.md` and docs.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SHELL_STREAM_BYTES: number;
|
|
13
|
+
export declare const BACKGROUND_PROCESS_OUTPUT_BYTES: number;
|
|
14
|
+
export declare const GREP_STREAM_BYTES: number;
|
|
15
|
+
export declare const PROCESS_STDERR_BYTES: number;
|
|
16
|
+
export declare const TOOL_OUTPUT_ENTRY_BYTES: number;
|
|
17
|
+
export declare const TOOL_OUTPUT_TOTAL_BYTES: number;
|
|
18
|
+
export declare const LSP_DOCUMENT_BYTES: number;
|
|
19
|
+
export declare const LSP_HEADER_BYTES: number;
|
|
20
|
+
export declare const LSP_FRAME_BYTES: number;
|
|
21
|
+
export declare const LSP_BUFFER_BYTES: number;
|
|
22
|
+
export declare const SKILL_MARKDOWN_BYTES: number;
|
|
23
|
+
export declare const EXACT_MUTATION_BYTES: number;
|
|
24
|
+
export declare const JSONL_LINE_BYTES: number;
|
|
25
|
+
export declare const TEXT_LINE_BYTES: number;
|
|
26
|
+
/** Maximum byte size of a prompt read from piped stdin. */
|
|
27
|
+
export declare const STDIN_PROMPT_BYTES: number;
|
|
28
|
+
/** Maximum size of one user-attached image (checked before the read). */
|
|
29
|
+
export declare const IMAGE_ATTACHMENT_BYTES: number;
|
|
30
|
+
/** Maximum number of image attachments in a single user message. */
|
|
31
|
+
export declare const IMAGE_ATTACHMENTS_PER_MESSAGE = 4;
|
|
32
|
+
/** Per-page cap for numbered file content returned by readFile/listFiles-style tools. */
|
|
33
|
+
export declare const MAX_OUTPUT_CHARS = 50000;
|
|
34
|
+
/** Default compact cap for stored shell output shown to the model. */
|
|
35
|
+
export declare const COMPACT_COMMAND_CHARS = 12000;
|
|
36
|
+
/** Compact cap for passing-validation summaries. */
|
|
37
|
+
export declare const SHORT_VALIDATION_CHARS = 2000;
|
|
38
|
+
/** Total rendered size cap for grep match output. */
|
|
39
|
+
export declare const GREP_MAX_OUTPUT_CHARS = 30000;
|
|
40
|
+
/** Per-line cap for rendered grep matches. */
|
|
41
|
+
export declare const GREP_MAX_LINE_CHARS = 500;
|
|
42
|
+
/** Bounded excerpt of older messages kept by /compact-style compaction. */
|
|
43
|
+
export declare const COMPACTION_OLDER_CHARS = 8000;
|
|
44
|
+
/** Bounded older-transcript budget sent to the model for LLM-summarized /compact (F-09). */
|
|
45
|
+
export declare const COMPACTION_LLM_TRANSCRIPT_CHARS = 60000;
|
|
46
|
+
/** Session JSONL values up to this size stay inline; larger ones become previews. */
|
|
47
|
+
export declare const SESSION_INLINE_VALUE_BYTES: number;
|
|
48
|
+
/** Preview length for slimmed session values. */
|
|
49
|
+
export declare const SESSION_PREVIEW_CHARS: number;
|
|
50
|
+
/** Strings longer than this are truncated in session snapshots. */
|
|
51
|
+
export declare const SESSION_LARGE_STRING_CHARS: number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized output/resource limits.
|
|
3
|
+
*
|
|
4
|
+
* Byte budgets below bound work performed (process output, file reads, JSONL
|
|
5
|
+
* lines, LSP frames/headers/buffers, stored tool-output handles, skill files,
|
|
6
|
+
* exact-mutation size); the model-facing character caps bound returned/persisted
|
|
7
|
+
* text so callers cite a named constant instead of a magic number (CR-014).
|
|
8
|
+
*
|
|
9
|
+
* Changing a value changes availability/memory behavior; mention user-visible
|
|
10
|
+
* changes in `CHANGELOG.md` and docs.
|
|
11
|
+
*/
|
|
12
|
+
export const SHELL_STREAM_BYTES = 2 * 1024 * 1024;
|
|
13
|
+
export const BACKGROUND_PROCESS_OUTPUT_BYTES = 256 * 1024;
|
|
14
|
+
export const GREP_STREAM_BYTES = 8 * 1024 * 1024;
|
|
15
|
+
export const PROCESS_STDERR_BYTES = 64 * 1024;
|
|
16
|
+
export const TOOL_OUTPUT_ENTRY_BYTES = 2 * 1024 * 1024;
|
|
17
|
+
export const TOOL_OUTPUT_TOTAL_BYTES = 16 * 1024 * 1024;
|
|
18
|
+
export const LSP_DOCUMENT_BYTES = 2 * 1024 * 1024;
|
|
19
|
+
export const LSP_HEADER_BYTES = 16 * 1024;
|
|
20
|
+
export const LSP_FRAME_BYTES = 8 * 1024 * 1024;
|
|
21
|
+
export const LSP_BUFFER_BYTES = LSP_FRAME_BYTES + LSP_HEADER_BYTES;
|
|
22
|
+
export const SKILL_MARKDOWN_BYTES = 256 * 1024;
|
|
23
|
+
export const EXACT_MUTATION_BYTES = 8 * 1024 * 1024;
|
|
24
|
+
export const JSONL_LINE_BYTES = 4 * 1024 * 1024;
|
|
25
|
+
export const TEXT_LINE_BYTES = 1024 * 1024;
|
|
26
|
+
/** Maximum byte size of a prompt read from piped stdin. */
|
|
27
|
+
export const STDIN_PROMPT_BYTES = 256 * 1024;
|
|
28
|
+
/** Maximum size of one user-attached image (checked before the read). */
|
|
29
|
+
export const IMAGE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
30
|
+
/** Maximum number of image attachments in a single user message. */
|
|
31
|
+
export const IMAGE_ATTACHMENTS_PER_MESSAGE = 4;
|
|
32
|
+
/** Per-page cap for numbered file content returned by readFile/listFiles-style tools. */
|
|
33
|
+
export const MAX_OUTPUT_CHARS = 50_000;
|
|
34
|
+
/** Default compact cap for stored shell output shown to the model. */
|
|
35
|
+
export const COMPACT_COMMAND_CHARS = 12_000;
|
|
36
|
+
/** Compact cap for passing-validation summaries. */
|
|
37
|
+
export const SHORT_VALIDATION_CHARS = 2_000;
|
|
38
|
+
/** Total rendered size cap for grep match output. */
|
|
39
|
+
export const GREP_MAX_OUTPUT_CHARS = 30_000;
|
|
40
|
+
/** Per-line cap for rendered grep matches. */
|
|
41
|
+
export const GREP_MAX_LINE_CHARS = 500;
|
|
42
|
+
/** Bounded excerpt of older messages kept by /compact-style compaction. */
|
|
43
|
+
export const COMPACTION_OLDER_CHARS = 8_000;
|
|
44
|
+
/** Bounded older-transcript budget sent to the model for LLM-summarized /compact (F-09). */
|
|
45
|
+
export const COMPACTION_LLM_TRANSCRIPT_CHARS = 60_000;
|
|
46
|
+
/** Session JSONL values up to this size stay inline; larger ones become previews. */
|
|
47
|
+
export const SESSION_INLINE_VALUE_BYTES = 32 * 1024;
|
|
48
|
+
/** Preview length for slimmed session values. */
|
|
49
|
+
export const SESSION_PREVIEW_CHARS = 4 * 1024;
|
|
50
|
+
/** Strings longer than this are truncated in session snapshots. */
|
|
51
|
+
export const SESSION_LARGE_STRING_CHARS = 8 * 1024;
|
package/dist/core/log/llmLog.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import { HAZE_DIR } from '../../config/paths.js';
|
|
4
4
|
import { appendPrivateFile, ensurePrivateFile, ensurePrivateDir, tightenPrivateFile } from '../../config/privateStorage.js';
|
|
5
5
|
import { OrderedFileWriter } from '../persistence/orderedFileWriter.js';
|
|
6
|
-
import { JSONL_LINE_BYTES } from '../limits
|
|
6
|
+
import { JSONL_LINE_BYTES } from '../limits.js';
|
|
7
7
|
import { iterateBoundedUtf8Lines } from '../io/boundedRead.js';
|
|
8
8
|
const LOGS_DIR = path.join(HAZE_DIR, 'logs');
|
|
9
9
|
function logFileId(now = new Date()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type BackgroundProcessStatus = 'running' | 'exited' | 'failed' | 'killed';
|
|
2
2
|
export interface BackgroundProcessSummary {
|
|
3
3
|
backgroundId: string;
|
|
4
4
|
pid?: number;
|
|
@@ -29,7 +29,6 @@ export declare function killBackgroundProcess(backgroundId: string, killGraceMs?
|
|
|
29
29
|
export declare function teardownBackgroundProcesses(killGraceMs?: number): Promise<BackgroundProcessSummary[]>;
|
|
30
30
|
/** Install CLI-level abnormal-exit teardown for SIGINT and SIGTERM. */
|
|
31
31
|
export declare function installBackgroundProcessSignalHandlers(): void;
|
|
32
|
-
/** Best-effort synchronous safety net for process.exit and otherwise unawaitable exits. */
|
|
33
|
-
export declare function terminateBackgroundProcessesSync(): void;
|
|
34
32
|
/** Test-only reset; callers should normally use teardownBackgroundProcesses. */
|
|
35
33
|
export declare function resetBackgroundProcessesForTests(): Promise<void>;
|
|
34
|
+
export {};
|
|
@@ -2,8 +2,9 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { StringDecoder } from 'node:string_decoder';
|
|
3
3
|
import { BACKGROUND_PROCESS_HISTORY_LIMIT, BACKGROUND_PROCESS_MAX_CONCURRENCY } from '../agent/budgets.js';
|
|
4
4
|
import { registerDynamicToolOutput, unregisterDynamicToolOutput } from '../agent/toolOutputStore.js';
|
|
5
|
-
import { BACKGROUND_PROCESS_OUTPUT_BYTES } from '../limits
|
|
5
|
+
import { BACKGROUND_PROCESS_OUTPUT_BYTES } from '../limits.js';
|
|
6
6
|
import { signalProcessTree } from './runBoundedProcess.js';
|
|
7
|
+
import { shellInvocation } from './userShell.js';
|
|
7
8
|
import { truncateUtf8TailBufferAtBytes } from '../../utils/utf8.js';
|
|
8
9
|
class OutputRing {
|
|
9
10
|
decoder = new StringDecoder('utf8');
|
|
@@ -77,7 +78,8 @@ export function startBackgroundProcess(input) {
|
|
|
77
78
|
}
|
|
78
79
|
installExitHook();
|
|
79
80
|
const backgroundId = `background-${nextId++}`;
|
|
80
|
-
const
|
|
81
|
+
const invocation = shellInvocation(input.command);
|
|
82
|
+
const child = spawn(invocation.command, invocation.args, {
|
|
81
83
|
cwd: input.cwd,
|
|
82
84
|
detached: process.platform !== 'win32',
|
|
83
85
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
@@ -100,10 +102,12 @@ export function startBackgroundProcess(input) {
|
|
|
100
102
|
child.once('error', error => {
|
|
101
103
|
summary.status = 'failed';
|
|
102
104
|
const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
+
// Without the user's shell on PATH, spawn fails with ENOENT; surface a
|
|
106
|
+
// clearer message than the raw syscall error. The default Windows shell is
|
|
107
|
+
// bash (via WSL or Git Bash), so that case keeps the install hint.
|
|
108
|
+
const shellName = invocation.command;
|
|
105
109
|
summary.error = code === 'ENOENT' && process.platform === 'win32'
|
|
106
|
-
?
|
|
110
|
+
? `${shellName} was not found on PATH.${shellName === 'bash' ? ' Install WSL or Git Bash, or run haze on a POSIX shell.' : ''} Underlying error: ${error.message}`
|
|
107
111
|
: error.message;
|
|
108
112
|
notify();
|
|
109
113
|
});
|
|
@@ -184,7 +188,7 @@ export function installBackgroundProcessSignalHandlers() {
|
|
|
184
188
|
handle('SIGTERM', 143);
|
|
185
189
|
}
|
|
186
190
|
/** Best-effort synchronous safety net for process.exit and otherwise unawaitable exits. */
|
|
187
|
-
|
|
191
|
+
function terminateBackgroundProcessesSync() {
|
|
188
192
|
for (const record of activeRecords())
|
|
189
193
|
signalProcessTree(record.child, 'SIGTERM');
|
|
190
194
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ShellDialect = 'posix' | 'fish' | 'csh' | 'powershell' | 'cmd' | 'unknown';
|
|
2
|
+
export declare function shellDialect(shellPath?: string): ShellDialect;
|
|
3
|
+
/** Model-facing syntax guidance for the selected shell. */
|
|
4
|
+
export declare function shellSyntaxGuidance(shellPath?: string): "Use POSIX-compatible shell syntax." | "Use fish syntax; do not use POSIX variable-assignment syntax." | "Use csh/tcsh syntax; do not use POSIX variable-assignment syntax." | "Use PowerShell syntax, cmdlets, quoting, and environment-variable notation." | "Use Windows cmd.exe syntax and environment-variable notation." | "Use syntax supported by this shell; avoid shell-specific constructs when uncertain.";
|
|
5
|
+
/**
|
|
6
|
+
* The shell commands run in: an explicit HAZE_SHELL override, otherwise the
|
|
7
|
+
* user's login shell from the environment, with a bash fallback. On Windows the fallback stays `bash` (via WSL or Git Bash)
|
|
8
|
+
* because commands are written in POSIX syntax; Git Bash terminals export
|
|
9
|
+
* `SHELL` anyway, so the fallback only covers the no-`SHELL` case.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveUserShell(): string;
|
|
12
|
+
/** Spawn target for running `command` under `shellPath` (default: user's shell). */
|
|
13
|
+
export declare function shellInvocation(command: string, shellPath?: string): {
|
|
14
|
+
command: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Shells that accept `-l` (login shell) alongside `-c`. Flags are passed
|
|
2
|
+
// separately (`-l -c`, not `-lc`) because that form is accepted by every
|
|
3
|
+
// login-capable shell including fish.
|
|
4
|
+
const LOGIN_CAPABLE = new Set(['bash', 'zsh', 'ksh', 'ksh93', 'mksh', 'yash', 'fish']);
|
|
5
|
+
function shellName(shellPath) {
|
|
6
|
+
const base = shellPath.split(/[\\/]/).pop() ?? shellPath;
|
|
7
|
+
return base.replace(/\.exe$/i, '').toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
export function shellDialect(shellPath = resolveUserShell()) {
|
|
10
|
+
const name = shellName(shellPath);
|
|
11
|
+
if (['bash', 'zsh', 'sh', 'dash', 'ksh', 'ksh93', 'mksh', 'yash'].includes(name))
|
|
12
|
+
return 'posix';
|
|
13
|
+
if (name === 'fish')
|
|
14
|
+
return 'fish';
|
|
15
|
+
if (name === 'csh' || name === 'tcsh')
|
|
16
|
+
return 'csh';
|
|
17
|
+
if (name === 'pwsh' || name === 'powershell')
|
|
18
|
+
return 'powershell';
|
|
19
|
+
if (name === 'cmd')
|
|
20
|
+
return 'cmd';
|
|
21
|
+
return 'unknown';
|
|
22
|
+
}
|
|
23
|
+
/** Model-facing syntax guidance for the selected shell. */
|
|
24
|
+
export function shellSyntaxGuidance(shellPath = resolveUserShell()) {
|
|
25
|
+
const dialect = shellDialect(shellPath);
|
|
26
|
+
if (dialect === 'posix')
|
|
27
|
+
return 'Use POSIX-compatible shell syntax.';
|
|
28
|
+
if (dialect === 'fish')
|
|
29
|
+
return 'Use fish syntax; do not use POSIX variable-assignment syntax.';
|
|
30
|
+
if (dialect === 'csh')
|
|
31
|
+
return 'Use csh/tcsh syntax; do not use POSIX variable-assignment syntax.';
|
|
32
|
+
if (dialect === 'powershell')
|
|
33
|
+
return 'Use PowerShell syntax, cmdlets, quoting, and environment-variable notation.';
|
|
34
|
+
if (dialect === 'cmd')
|
|
35
|
+
return 'Use Windows cmd.exe syntax and environment-variable notation.';
|
|
36
|
+
return 'Use syntax supported by this shell; avoid shell-specific constructs when uncertain.';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The shell commands run in: an explicit HAZE_SHELL override, otherwise the
|
|
40
|
+
* user's login shell from the environment, with a bash fallback. On Windows the fallback stays `bash` (via WSL or Git Bash)
|
|
41
|
+
* because commands are written in POSIX syntax; Git Bash terminals export
|
|
42
|
+
* `SHELL` anyway, so the fallback only covers the no-`SHELL` case.
|
|
43
|
+
*/
|
|
44
|
+
export function resolveUserShell() {
|
|
45
|
+
const fromEnv = process.env.HAZE_SHELL || process.env.SHELL;
|
|
46
|
+
if (fromEnv)
|
|
47
|
+
return fromEnv;
|
|
48
|
+
return process.platform === 'win32' ? 'bash' : '/bin/bash';
|
|
49
|
+
}
|
|
50
|
+
/** Spawn target for running `command` under `shellPath` (default: user's shell). */
|
|
51
|
+
export function shellInvocation(command, shellPath = resolveUserShell()) {
|
|
52
|
+
const name = shellName(shellPath);
|
|
53
|
+
if (name === 'pwsh' || name === 'powershell')
|
|
54
|
+
return { command: shellPath, args: ['-Command', command] };
|
|
55
|
+
if (name === 'cmd')
|
|
56
|
+
return { command: shellPath, args: ['/c', command] };
|
|
57
|
+
const login = LOGIN_CAPABLE.has(name) ? ['-l'] : [];
|
|
58
|
+
return { command: shellPath, args: [...login, '-c', command] };
|
|
59
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a path points at (or inside) a protected secret file or credential
|
|
3
|
+
* store. Checked against both lexical names and real paths by callers so
|
|
4
|
+
* symlinks cannot rename a secret into reach (`link -> .env`) or a secret
|
|
5
|
+
* name onto other content (`.env -> target`). Pure function; `homeDir` is
|
|
6
|
+
* injectable for tests.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isProtectedSecretPath(candidatePath: string, homeDir?: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Ripgrep exclusion globs for the `grep` tool. Later globs take precedence in
|
|
11
|
+
* ripgrep, so callers must append these AFTER any model-supplied glob — an
|
|
12
|
+
* explicit model glob must not re-include secrets. Exclusions are strictly
|
|
13
|
+
* negated: a positive "re-include" glob would act as a whitelist and narrow
|
|
14
|
+
* the search to only the re-included names. Documentation variants
|
|
15
|
+
* (`.env.example`, `id_*.pub`) therefore stay out of traversal search but
|
|
16
|
+
* remain readable through targeted `readFile` calls.
|
|
17
|
+
*/
|
|
18
|
+
export declare function secretSearchExcludeGlobs(): string[];
|