@denizokcu/haze 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -1
- package/README.md +23 -10
- package/SECURITY.md +1 -1
- package/bin/haze.js +27 -7
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +7 -0
- package/dist/cli/chat/BusyBar.js +8 -0
- package/dist/cli/chat/DynamicFrame.d.ts +37 -0
- package/dist/cli/chat/DynamicFrame.js +43 -0
- package/dist/cli/chat/busyIndicator.d.ts +3 -1
- package/dist/cli/chat/busyIndicator.js +11 -9
- package/dist/cli/chat/chatMetrics.d.ts +1 -1
- package/dist/cli/chat/chatMetrics.js +3 -3
- package/dist/cli/chat/inputSuggestions.js +4 -0
- package/dist/cli/chat/liveMessages.d.ts +36 -0
- package/dist/cli/chat/liveMessages.js +64 -0
- package/dist/cli/chat/liveRegion.js +1 -1
- package/dist/cli/chat/messages.js +27 -16
- package/dist/cli/chat/sessionLifecycle.d.ts +5 -2
- package/dist/cli/chat/sessionLifecycle.js +36 -4
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +8 -0
- package/dist/cli/chat/shutdown.d.ts +27 -0
- package/dist/cli/chat/shutdown.js +79 -0
- package/dist/cli/chat/terminalControl.d.ts +45 -0
- package/dist/cli/chat/terminalControl.js +107 -0
- package/dist/cli/chat/tips.js +1 -0
- package/dist/cli/chat/userInput.d.ts +43 -0
- package/dist/cli/chat/userInput.js +63 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +1 -1
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +24 -1
- package/dist/cli/chat/wizard/types.d.ts +8 -1
- package/dist/cli/chat/wizardDispatch.js +1 -1
- package/dist/cli/commands/chat.js +277 -193
- package/dist/cli/commands/commandHelp.js +6 -0
- package/dist/cli/commands/commands.d.ts +8 -0
- package/dist/cli/commands/commands.js +13 -0
- package/dist/cli/commands/formatters.d.ts +1 -1
- package/dist/cli/commands/formatters.js +25 -3
- package/dist/cli/commands/logsCommand.js +21 -2
- package/dist/cli/commands/ndjsonSink.d.ts +12 -0
- package/dist/cli/commands/ndjsonSink.js +29 -0
- package/dist/cli/commands/reasoningCommand.d.ts +44 -0
- package/dist/cli/commands/reasoningCommand.js +79 -0
- package/dist/cli/commands/runCommand.d.ts +14 -0
- package/dist/cli/commands/runCommand.js +56 -22
- package/dist/cli/commands/settingsSummary.js +2 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +3 -0
- package/dist/cli/commands/streaming/agentAttempt.js +2 -2
- package/dist/cli/commands/streaming/assistantSegments.d.ts +0 -7
- package/dist/cli/commands/streaming/assistantSegments.js +1 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +13 -9
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +24 -9
- package/dist/cli/commands/streaming/attemptSetup.d.ts +4 -0
- package/dist/cli/commands/streaming/attemptSetup.js +21 -7
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +14 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +4 -2
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +9 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +51 -10
- package/dist/cli/commands/streaming/prepareStep.d.ts +0 -3
- package/dist/cli/commands/streaming/prepareStep.js +14 -5
- package/dist/cli/commands/streaming/streamLoop.d.ts +5 -0
- package/dist/cli/commands/streaming/streamLoop.js +3 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +6 -0
- package/dist/cli/commands/streaming.d.ts +8 -3
- package/dist/cli/commands/streaming.js +46 -21
- package/dist/cli/commands/wizardFlow.d.ts +10 -0
- package/dist/cli/commands/wizardFlow.js +34 -5
- package/dist/cli/index.js +22 -2
- package/dist/config/contextFiles.d.ts +9 -0
- package/dist/config/contextFiles.js +21 -1
- package/dist/config/modelCatalog.d.ts +3 -0
- package/dist/config/modelCatalog.js +29 -0
- package/dist/config/modelDiscovery.js +68 -5
- package/dist/config/providerPresets.d.ts +1 -1
- package/dist/config/providerPresets.js +42 -3
- package/dist/config/settings.d.ts +14 -6
- package/dist/config/settings.js +16 -1
- package/dist/core/agent/budgets.d.ts +13 -17
- package/dist/core/agent/budgets.js +15 -19
- package/dist/core/agent/completionController.d.ts +14 -2
- package/dist/core/agent/completionController.js +48 -3
- package/dist/core/agent/events.d.ts +2 -1
- package/dist/core/agent/goalPolicy.d.ts +17 -0
- package/dist/core/agent/goalPolicy.js +53 -6
- package/dist/core/agent/projectPreflight.d.ts +2 -0
- package/dist/core/agent/projectPreflight.js +56 -0
- package/dist/core/agent/reasoningPolicy.d.ts +76 -10
- package/dist/core/agent/reasoningPolicy.js +72 -9
- package/dist/core/agent/toolCapabilities.d.ts +3 -3
- package/dist/core/agent/toolCapabilities.js +31 -7
- package/dist/core/agent/workState.d.ts +14 -4
- package/dist/core/agent/workState.js +229 -34
- package/dist/core/deadline.js +22 -24
- package/dist/core/providerContracts.d.ts +29 -0
- package/dist/core/providerContracts.js +1 -0
- package/dist/core/safety/secretPaths.js +10 -7
- package/dist/core/safety/shellClassifier.d.ts +2 -0
- package/dist/core/safety/shellClassifier.js +9 -1
- package/dist/core/session/sessionReport.d.ts +33 -0
- package/dist/core/session/sessionReport.js +121 -0
- package/dist/core/session/sessionSlimming.d.ts +2 -0
- package/dist/core/session/sessionSlimming.js +59 -4
- package/dist/core/session/sessionStore.d.ts +16 -8
- package/dist/core/session/sessionStore.js +71 -34
- package/dist/core/shellOutput/reducers/git.js +7 -2
- package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
- package/dist/core/shellOutput/reducers/validation.js +14 -1
- package/dist/core/shellOutput/registry.js +3 -2
- package/dist/core/subagent/contracts.d.ts +3 -18
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/tasks/taskStorage.js +8 -1
- package/dist/core/validation/outputParser.d.ts +6 -1
- package/dist/core/validation/outputParser.js +30 -2
- package/dist/llm/client.d.ts +6 -3
- package/dist/llm/client.js +28 -11
- package/dist/llm/hazeTools.d.ts +9161 -7135
- package/dist/llm/hazeTools.js +6 -462
- package/dist/llm/lsp/client.d.ts +7 -1
- package/dist/llm/lsp/client.js +58 -9
- package/dist/llm/lsp/pool.d.ts +11 -0
- package/dist/llm/lsp/pool.js +61 -4
- package/dist/llm/lsp/protocol.d.ts +6 -23
- package/dist/llm/lsp/requests.d.ts +54 -60
- package/dist/llm/lsp/requests.js +152 -28
- package/dist/llm/lsp/symbols.d.ts +16 -0
- package/dist/llm/lsp/symbols.js +70 -0
- package/dist/llm/lsp/workspaceEdit.d.ts +43 -0
- package/dist/llm/lsp/workspaceEdit.js +117 -0
- package/dist/llm/lspTools.d.ts +7518 -2859
- package/dist/llm/lspTools.js +195 -110
- package/dist/llm/mcp.js +3 -0
- package/dist/llm/requestContext.d.ts +4 -3
- package/dist/llm/requestContext.js +9 -5
- package/dist/{core/subagent → llm}/subagentRunner.d.ts +13 -9
- package/dist/{core/subagent → llm}/subagentRunner.js +54 -49
- package/dist/llm/systemPrompt.d.ts +11 -1
- package/dist/llm/systemPrompt.js +4 -13
- package/dist/llm/tools/fetchTool.d.ts +34 -30
- package/dist/llm/tools/fileTools.d.ts +7768 -0
- package/dist/llm/tools/fileTools.js +510 -0
- package/dist/llm/tools/processTool.d.ts +34 -30
- package/dist/llm/tools/replaceInFiles.d.ts +105 -0
- package/dist/llm/tools/replaceInFiles.js +131 -0
- package/dist/llm/tools/shellTool.d.ts +34 -30
- package/dist/llm/tools/shellTool.js +8 -4
- package/dist/llm/tools/storedOutputTool.d.ts +4 -0
- package/dist/llm/tools/taskTool.d.ts +4 -0
- package/dist/llm/tools/toolContext.d.ts +3 -29
- package/dist/llm/tools/toolContext.js +56 -53
- package/dist/llm/tools/toolContextState.d.ts +40 -0
- package/dist/llm/tools/toolContextState.js +34 -0
- package/dist/llm/workerContext.d.ts +7 -0
- package/dist/llm/workerContext.js +18 -1
- package/dist/skills/SkillLoader.js +30 -4
- package/dist/skills/SkillRegistry.js +3 -3
- package/dist/skills/builder/SkillBuilder.js +3 -3
- package/dist/skills/confinement.d.ts +7 -0
- package/dist/skills/confinement.js +15 -0
- package/dist/ui/codeHighlight.js +4 -4
- package/dist/ui/components/MarkdownText.js +7 -8
- package/dist/ui/components/NativeIndicators.d.ts +15 -0
- package/dist/ui/components/NativeIndicators.js +32 -0
- package/dist/ui/components/StreamingMarkdownText.d.ts +9 -0
- package/dist/ui/components/StreamingMarkdownText.js +38 -0
- package/dist/ui/components/TextInput.d.ts +7 -2
- package/dist/ui/components/TextInput.js +103 -46
- package/dist/ui/components/WizardChoices.d.ts +18 -0
- package/dist/ui/components/WizardChoices.js +32 -0
- package/dist/ui/components/useInputSuggestions.js +18 -6
- package/dist/ui/inputBuffer.js +12 -6
- package/dist/ui/textGeometry.d.ts +14 -0
- package/dist/ui/textGeometry.js +31 -0
- package/dist/utils/buildInfo.js +29 -8
- package/dist/utils/fs.js +5 -1
- package/package.json +23 -22
- /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
- /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
|
@@ -60,7 +60,14 @@ export const shellTool = tool({
|
|
|
60
60
|
const { code, timedOut } = processResult;
|
|
61
61
|
const stdout = processResult.stdout.text;
|
|
62
62
|
const stderr = processResult.stderr.text;
|
|
63
|
-
|
|
63
|
+
// A spawn failure (executable missing / not found, exit 127) is an
|
|
64
|
+
// environment blocker, not a failed check: nothing ran, so there is no
|
|
65
|
+
// pass/fail evidence to record (observed 2026-10-04: a `missing_executable`
|
|
66
|
+
// shell result was recorded as a failed `test` validation and rode a goal
|
|
67
|
+
// checkpoint as an unresolvable red). Diagnose it below and keep the
|
|
68
|
+
// validation summary absent.
|
|
69
|
+
const missing = code !== 0 && !processResult.aborted ? detectMissingExecutable({ command, code, stderr }) : undefined;
|
|
70
|
+
const validationSummary = isValidationCommand && !missing
|
|
64
71
|
? parseValidationOutput({ command, code, stdout, stderr, timedOut, stdoutTruncated: processResult.stdout.omittedBytes > 0, stderrTruncated: processResult.stderr.omittedBytes > 0, classification })
|
|
65
72
|
: undefined;
|
|
66
73
|
// Evidence truthfulness: a passing validation whose command shape can
|
|
@@ -77,9 +84,6 @@ export const shellTool = tool({
|
|
|
77
84
|
: undefined;
|
|
78
85
|
const validationPassed = confirmedValidationSummary?.status === 'passed';
|
|
79
86
|
const output = filterShellOutput({ command, code, stdout, stderr, timedOut, classification, validationSummary: confirmedValidationSummary, storeRawOutput: storeToolOutput, fallbackCompact: compactStoredOutput, compactMaxChars: validationPassed ? SHORT_VALIDATION_CHARS : COMPACT_COMMAND_CHARS });
|
|
80
|
-
// Generic, dependency-agnostic diagnostic for a missing executable. Only the
|
|
81
|
-
// executable name and a generic next step are exposed (never raw stderr).
|
|
82
|
-
const missing = code !== 0 && !processResult.aborted ? detectMissingExecutable({ command, code, stderr }) : undefined;
|
|
83
87
|
return {
|
|
84
88
|
ok: code === 0 && !timedOut && !processResult.aborted && !processResult.error,
|
|
85
89
|
code, command, purpose, cwd, classification, durationMs: Date.now() - startedAt, timedOut,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const readToolOutputTool: ({
|
|
2
|
+
deferLoading?: boolean;
|
|
2
3
|
title?: string;
|
|
3
4
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
4
5
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -92,6 +93,7 @@ export declare const readToolOutputTool: ({
|
|
|
92
93
|
error: string;
|
|
93
94
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
94
95
|
}) | ({
|
|
96
|
+
deferLoading?: boolean;
|
|
95
97
|
title?: string;
|
|
96
98
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
97
99
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -185,6 +187,7 @@ export declare const readToolOutputTool: ({
|
|
|
185
187
|
error: string;
|
|
186
188
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
187
189
|
}) | ({
|
|
190
|
+
deferLoading?: boolean;
|
|
188
191
|
title?: string;
|
|
189
192
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
190
193
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -267,6 +270,7 @@ export declare const readToolOutputTool: ({
|
|
|
267
270
|
error: string;
|
|
268
271
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
269
272
|
}) | ({
|
|
273
|
+
deferLoading?: boolean;
|
|
270
274
|
title?: string;
|
|
271
275
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
272
276
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const writeTasksTool: ({
|
|
2
|
+
deferLoading?: boolean;
|
|
2
3
|
title?: string;
|
|
3
4
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
4
5
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -125,6 +126,7 @@ export declare const writeTasksTool: ({
|
|
|
125
126
|
error?: undefined;
|
|
126
127
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
127
128
|
}) | ({
|
|
129
|
+
deferLoading?: boolean;
|
|
128
130
|
title?: string;
|
|
129
131
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
130
132
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -251,6 +253,7 @@ export declare const writeTasksTool: ({
|
|
|
251
253
|
error?: undefined;
|
|
252
254
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
253
255
|
}) | ({
|
|
256
|
+
deferLoading?: boolean;
|
|
254
257
|
title?: string;
|
|
255
258
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
256
259
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -367,6 +370,7 @@ export declare const writeTasksTool: ({
|
|
|
367
370
|
error?: undefined;
|
|
368
371
|
}, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
369
372
|
}) | ({
|
|
373
|
+
deferLoading?: boolean;
|
|
370
374
|
title?: string;
|
|
371
375
|
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
372
376
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { ToolFailureReasonCode } from '../toolResultTypes.js';
|
|
3
2
|
import { type ContextFile } from '../../config/contextFiles.js';
|
|
4
|
-
import type
|
|
5
|
-
|
|
3
|
+
import { type HazeToolContext, type ToolExecutionContext } from './toolContextState.js';
|
|
4
|
+
export type { HazeToolContext, PostMutationDiagnostics, ToolExecutionContext } from './toolContextState.js';
|
|
5
|
+
export { hazeContext, isHazeToolContext } from './toolContextState.js';
|
|
6
6
|
/**
|
|
7
7
|
* Turn-scoped tool-call orchestration shared by every built-in tool: in-flight
|
|
8
8
|
* and completed-call deduplication, a mutation epoch that invalidates read
|
|
@@ -13,33 +13,7 @@ import type { WorkspaceMutationOwner, WorkspaceMutationPolicy } from '../../core
|
|
|
13
13
|
* passes to the AI SDK. Tests and older callers may still provide the legacy
|
|
14
14
|
* `experimental_context` shape. Nothing here is persisted.
|
|
15
15
|
*/
|
|
16
|
-
export type ToolExecutionContext = {
|
|
17
|
-
abortSignal?: AbortSignal;
|
|
18
|
-
context?: unknown;
|
|
19
|
-
experimental_context?: unknown;
|
|
20
|
-
};
|
|
21
|
-
export type HazeToolContext = {
|
|
22
|
-
inFlightToolCalls?: Map<string, Promise<unknown>>;
|
|
23
|
-
completedToolCalls?: Map<string, number>;
|
|
24
|
-
mutationEpoch?: number;
|
|
25
|
-
failedMutationPaths?: Set<string>;
|
|
26
|
-
failedMutationReasons?: Map<string, ToolFailureReasonCode | undefined>;
|
|
27
|
-
pathsReadAfterFailedMutation?: Set<string>;
|
|
28
|
-
inFlightMutationPaths?: Set<string>;
|
|
29
|
-
loadedContextFilePaths?: Set<string>;
|
|
30
|
-
loadedContextFileSignatures?: Map<string, string>;
|
|
31
|
-
pendingContextFiles?: ContextFile[];
|
|
32
|
-
scopedContextDiscovery?: Promise<void>;
|
|
33
|
-
onContextFileRead?: (path: string) => void;
|
|
34
|
-
mutationPolicy?: WorkspaceMutationPolicy;
|
|
35
|
-
mutationOwner?: WorkspaceMutationOwner;
|
|
36
|
-
/** True in disposable worker contexts; background processes are main-turn-only. */
|
|
37
|
-
isSubagent?: boolean;
|
|
38
|
-
/** Real paths the user mentioned this turn; read tools may escape workspace for them. */
|
|
39
|
-
blessedPaths?: readonly BlessedPath[];
|
|
40
|
-
};
|
|
41
16
|
export declare const hazeToolContextSchema: z.ZodCustom<HazeToolContext, HazeToolContext>;
|
|
42
|
-
export declare function hazeContext(context: ToolExecutionContext): HazeToolContext | undefined;
|
|
43
17
|
export declare function toolsContextFor<T extends Record<string, unknown>>(tools: T, context: HazeToolContext): Partial<Record<keyof T, HazeToolContext>>;
|
|
44
18
|
/**
|
|
45
19
|
* Lazily load scoped CLAUDE.md/AGENTS.md files that apply to `filePath` and
|
|
@@ -1,61 +1,24 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { changedPathsFromTool, isMutatingCapability } from '../../core/agent/toolCapabilities.js';
|
|
2
3
|
import { readScopedContextFilesForPath } from '../../config/contextFiles.js';
|
|
3
4
|
import { workspacePathKey, workspaceRoot } from '../../utils/path.js';
|
|
4
5
|
import { isFailedToolOutput, requiresReadFileRecovery, toolInputField } from '../../core/agent/toolResults.js';
|
|
5
6
|
import { HazeToolError } from './failures.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return JSON.stringify(value) ?? 'undefined';
|
|
19
|
-
}
|
|
20
|
-
function toolCallKey(toolName, input) {
|
|
21
|
-
return `${toolName}:${stableJsonStringify(input)}`;
|
|
22
|
-
}
|
|
23
|
-
function isRecord(value) {
|
|
24
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
25
|
-
}
|
|
26
|
-
function isMutationPolicy(value) {
|
|
27
|
-
return isRecord(value) && typeof value.acquire === 'function' && typeof value.createOwner === 'function';
|
|
28
|
-
}
|
|
29
|
-
function isHazeToolContext(value) {
|
|
30
|
-
if (!isRecord(value))
|
|
31
|
-
return false;
|
|
32
|
-
const validOptional = (key, predicate) => value[key] === undefined || predicate(value[key]);
|
|
33
|
-
return validOptional('inFlightToolCalls', field => field instanceof Map)
|
|
34
|
-
&& validOptional('completedToolCalls', field => field instanceof Map)
|
|
35
|
-
&& validOptional('mutationEpoch', field => typeof field === 'number' && Number.isSafeInteger(field) && field >= 0)
|
|
36
|
-
&& validOptional('failedMutationPaths', field => field instanceof Set)
|
|
37
|
-
&& validOptional('failedMutationReasons', field => field instanceof Map)
|
|
38
|
-
&& validOptional('pathsReadAfterFailedMutation', field => field instanceof Set)
|
|
39
|
-
&& validOptional('inFlightMutationPaths', field => field instanceof Set)
|
|
40
|
-
&& validOptional('loadedContextFilePaths', field => field instanceof Set)
|
|
41
|
-
&& validOptional('loadedContextFileSignatures', field => field instanceof Map)
|
|
42
|
-
&& validOptional('pendingContextFiles', field => Array.isArray(field))
|
|
43
|
-
&& validOptional('scopedContextDiscovery', field => field instanceof Promise)
|
|
44
|
-
&& validOptional('onContextFileRead', field => typeof field === 'function')
|
|
45
|
-
&& validOptional('mutationPolicy', isMutationPolicy)
|
|
46
|
-
&& validOptional('mutationOwner', field => typeof field === 'symbol')
|
|
47
|
-
&& validOptional('isSubagent', field => typeof field === 'boolean')
|
|
48
|
-
&& validOptional('blessedPaths', field => Array.isArray(field) && field.every(item => isRecord(item) && typeof item.realPath === 'string' && typeof item.isDirectory === 'boolean'));
|
|
49
|
-
}
|
|
7
|
+
import { hazeContext, isHazeToolContext } from './toolContextState.js';
|
|
8
|
+
export { hazeContext, isHazeToolContext } from './toolContextState.js';
|
|
9
|
+
/**
|
|
10
|
+
* Turn-scoped tool-call orchestration shared by every built-in tool: in-flight
|
|
11
|
+
* and completed-call deduplication, a mutation epoch that invalidates read
|
|
12
|
+
* caches after writes, edit-recovery gating, and lazy discovery of scoped
|
|
13
|
+
* project instructions (CLAUDE.md / AGENTS.md below the cwd).
|
|
14
|
+
*
|
|
15
|
+
* All state lives on per-tool `context` values, which the agent turn owns and
|
|
16
|
+
* passes to the AI SDK. Tests and older callers may still provide the legacy
|
|
17
|
+
* `experimental_context` shape. Nothing here is persisted.
|
|
18
|
+
*/
|
|
50
19
|
export const hazeToolContextSchema = z.custom(isHazeToolContext, 'Invalid haze tool context');
|
|
51
|
-
export function hazeContext(context) {
|
|
52
|
-
const value = typeof context.context === 'object' && context.context != null
|
|
53
|
-
? context.context
|
|
54
|
-
: context.experimental_context;
|
|
55
|
-
return isHazeToolContext(value) ? value : undefined;
|
|
56
|
-
}
|
|
57
20
|
export function toolsContextFor(tools, context) {
|
|
58
|
-
const hazeToolNames = new Set(['listFiles', 'readFile', 'grep', 'replaceLines', 'writeFile', 'editFile', 'shell', 'process', 'fetch']);
|
|
21
|
+
const hazeToolNames = new Set(['listFiles', 'readFile', 'grep', 'replaceInFiles', 'replaceLines', 'writeFile', 'editFile', 'shell', 'process', 'fetch', 'lspRenameSymbol', 'lspSafeDeleteSymbol']);
|
|
59
22
|
return Object.fromEntries(Object.keys(tools).filter(name => hazeToolNames.has(name)).map(name => [name, context]));
|
|
60
23
|
}
|
|
61
24
|
/**
|
|
@@ -113,10 +76,33 @@ export function scopedContextMutationStop(toolName, filePath, files) {
|
|
|
113
76
|
applicableProjectInstructions: files,
|
|
114
77
|
};
|
|
115
78
|
}
|
|
79
|
+
// Shared effects policy keeps diagnostics and completion evidence in agreement.
|
|
116
80
|
function isMutatingTool(toolName) {
|
|
117
81
|
// Shell execution is conservatively workspace-mutation-capable. Classification remains
|
|
118
82
|
// informational and is not a sandbox boundary.
|
|
119
|
-
return
|
|
83
|
+
return isMutatingCapability(toolName) || toolName === 'shell';
|
|
84
|
+
}
|
|
85
|
+
/** Paths actually changed by a successful dedicated file-mutation result. */
|
|
86
|
+
function changedPathsForDiagnostics(toolName, input, result) {
|
|
87
|
+
return changedPathsFromTool(toolName, input, result);
|
|
88
|
+
}
|
|
89
|
+
async function attachPostMutationDiagnostics(toolName, input, result, diagnostics) {
|
|
90
|
+
if (!diagnostics)
|
|
91
|
+
return result;
|
|
92
|
+
const paths = changedPathsForDiagnostics(toolName, input, result);
|
|
93
|
+
if (paths.length === 0 || !isRecordValue(result))
|
|
94
|
+
return result;
|
|
95
|
+
try {
|
|
96
|
+
const lspDiagnostics = await diagnostics(paths);
|
|
97
|
+
return lspDiagnostics === undefined ? result : { ...result, lspDiagnostics };
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
101
|
+
return { ...result, lspDiagnostics: { ok: false, error: `Automatic LSP diagnostics failed: ${message.split('\n')[0]}` } };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isRecordValue(value) {
|
|
105
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
120
106
|
}
|
|
121
107
|
function isReadOnlyFileTool(toolName) {
|
|
122
108
|
return ['listFiles', 'readFile', 'grep'].includes(toolName);
|
|
@@ -127,6 +113,23 @@ function isReadOnlyFileTool(toolName) {
|
|
|
127
113
|
function isDeduplicableReadOnlyTool(toolName) {
|
|
128
114
|
return isReadOnlyFileTool(toolName) || toolName === 'fetch';
|
|
129
115
|
}
|
|
116
|
+
function stableJsonStringify(value, seen = new WeakSet()) {
|
|
117
|
+
if (Array.isArray(value))
|
|
118
|
+
return `[${value.map(item => stableJsonStringify(item, seen)).join(',')}]`;
|
|
119
|
+
if (value && typeof value === 'object') {
|
|
120
|
+
if (seen.has(value))
|
|
121
|
+
throw new Error('Circular tool input');
|
|
122
|
+
seen.add(value);
|
|
123
|
+
const entries = Object.entries(value)
|
|
124
|
+
.filter(([, entryValue]) => entryValue !== undefined)
|
|
125
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
126
|
+
return `{${entries.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableJsonStringify(entryValue, seen)}`).join(',')}}`;
|
|
127
|
+
}
|
|
128
|
+
return JSON.stringify(value) ?? 'undefined';
|
|
129
|
+
}
|
|
130
|
+
function toolCallKey(toolName, input) {
|
|
131
|
+
return `${toolName}:${stableJsonStringify(input)}`;
|
|
132
|
+
}
|
|
130
133
|
/**
|
|
131
134
|
* Wrap a tool's execution with turn-scoped deduplication and edit-recovery:
|
|
132
135
|
* - skip concurrent mutations of the same path;
|
|
@@ -217,7 +220,7 @@ export async function runDedupedTool(toolName, input, context, execute) {
|
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
222
|
ctx.completedToolCalls.set(key, ctx.mutationEpoch);
|
|
220
|
-
return result;
|
|
223
|
+
return await attachPostMutationDiagnostics(toolName, input, result, ctx.postMutationDiagnostics);
|
|
221
224
|
}
|
|
222
225
|
catch (error) {
|
|
223
226
|
if (isMutatingTool(toolName) && mutationPathKey && requiresReadFileRecovery(error)) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ContextFile } from '../../config/contextFiles.js';
|
|
2
|
+
import type { ToolFailureReasonCode } from '../toolResultTypes.js';
|
|
3
|
+
import type { BlessedPath } from '../../core/attachments/readBlessings.js';
|
|
4
|
+
import type { WorkspaceMutationOwner, WorkspaceMutationPolicy } from '../../core/subagent/workspaceMutationPolicy.js';
|
|
5
|
+
/**
|
|
6
|
+
* The turn-scoped tool execution state schema and guards, split from
|
|
7
|
+
* `toolContext.ts` so the widely-imported context type stops dragging the
|
|
8
|
+
* dedup/mutation runtime with it. `toolContext.ts` re-exports everything below
|
|
9
|
+
* for existing importers; new code imports from here.
|
|
10
|
+
*/
|
|
11
|
+
export type ToolExecutionContext = {
|
|
12
|
+
abortSignal?: AbortSignal;
|
|
13
|
+
context?: unknown;
|
|
14
|
+
experimental_context?: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type PostMutationDiagnostics = (paths: readonly string[]) => Promise<unknown | undefined>;
|
|
17
|
+
export type HazeToolContext = {
|
|
18
|
+
inFlightToolCalls?: Map<string, Promise<unknown>>;
|
|
19
|
+
completedToolCalls?: Map<string, number>;
|
|
20
|
+
mutationEpoch?: number;
|
|
21
|
+
failedMutationPaths?: Set<string>;
|
|
22
|
+
failedMutationReasons?: Map<string, ToolFailureReasonCode | undefined>;
|
|
23
|
+
pathsReadAfterFailedMutation?: Set<string>;
|
|
24
|
+
inFlightMutationPaths?: Set<string>;
|
|
25
|
+
loadedContextFilePaths?: Set<string>;
|
|
26
|
+
loadedContextFileSignatures?: Map<string, string>;
|
|
27
|
+
pendingContextFiles?: ContextFile[];
|
|
28
|
+
scopedContextDiscovery?: Promise<void>;
|
|
29
|
+
onContextFileRead?: (path: string) => void;
|
|
30
|
+
mutationPolicy?: WorkspaceMutationPolicy;
|
|
31
|
+
mutationOwner?: WorkspaceMutationOwner;
|
|
32
|
+
/** True in disposable worker contexts; background processes are main-turn-only. */
|
|
33
|
+
isSubagent?: boolean;
|
|
34
|
+
/** Real paths the user mentioned this turn; read tools may escape workspace for them. */
|
|
35
|
+
blessedPaths?: readonly BlessedPath[];
|
|
36
|
+
/** Runs LSP diagnostics after successful file mutations and embeds them in that tool result. */
|
|
37
|
+
postMutationDiagnostics?: PostMutationDiagnostics;
|
|
38
|
+
};
|
|
39
|
+
export declare function isHazeToolContext(value: unknown): value is HazeToolContext;
|
|
40
|
+
export declare function hazeContext(context: ToolExecutionContext): HazeToolContext | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function isMutationPolicy(value) {
|
|
5
|
+
return isRecord(value) && typeof value.acquire === 'function' && typeof value.createOwner === 'function';
|
|
6
|
+
}
|
|
7
|
+
export function isHazeToolContext(value) {
|
|
8
|
+
if (!isRecord(value))
|
|
9
|
+
return false;
|
|
10
|
+
const validOptional = (key, predicate) => value[key] === undefined || predicate(value[key]);
|
|
11
|
+
return validOptional('inFlightToolCalls', field => field instanceof Map)
|
|
12
|
+
&& validOptional('completedToolCalls', field => field instanceof Map)
|
|
13
|
+
&& validOptional('mutationEpoch', field => typeof field === 'number' && Number.isSafeInteger(field) && field >= 0)
|
|
14
|
+
&& validOptional('failedMutationPaths', field => field instanceof Set)
|
|
15
|
+
&& validOptional('failedMutationReasons', field => field instanceof Map)
|
|
16
|
+
&& validOptional('pathsReadAfterFailedMutation', field => field instanceof Set)
|
|
17
|
+
&& validOptional('inFlightMutationPaths', field => field instanceof Set)
|
|
18
|
+
&& validOptional('loadedContextFilePaths', field => field instanceof Set)
|
|
19
|
+
&& validOptional('loadedContextFileSignatures', field => field instanceof Map)
|
|
20
|
+
&& validOptional('pendingContextFiles', field => Array.isArray(field))
|
|
21
|
+
&& validOptional('scopedContextDiscovery', field => field instanceof Promise)
|
|
22
|
+
&& validOptional('onContextFileRead', field => typeof field === 'function')
|
|
23
|
+
&& validOptional('mutationPolicy', isMutationPolicy)
|
|
24
|
+
&& validOptional('mutationOwner', field => typeof field === 'symbol')
|
|
25
|
+
&& validOptional('isSubagent', field => typeof field === 'boolean')
|
|
26
|
+
&& validOptional('blessedPaths', field => Array.isArray(field) && field.every(item => isRecord(item) && typeof item.realPath === 'string' && typeof item.isDirectory === 'boolean'))
|
|
27
|
+
&& validOptional('postMutationDiagnostics', field => typeof field === 'function');
|
|
28
|
+
}
|
|
29
|
+
export function hazeContext(context) {
|
|
30
|
+
const value = typeof context.context === 'object' && context.context != null
|
|
31
|
+
? context.context
|
|
32
|
+
: context.experimental_context;
|
|
33
|
+
return isHazeToolContext(value) ? value : undefined;
|
|
34
|
+
}
|
|
@@ -16,3 +16,10 @@ export interface WorkerContextBundle {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function workerTaskMessage(task: SubagentTaskCapsule): string;
|
|
18
18
|
export declare function assembleWorkerContext(task: SubagentTaskCapsule, profile: SubagentExecutionProfile, session?: PromptSession): Promise<WorkerContextBundle>;
|
|
19
|
+
/**
|
|
20
|
+
* Legacy compatibility bundle for callers (e.g. `/fleet`) that pass explicit
|
|
21
|
+
* context files and an optional tool allowlist instead of letting the worker
|
|
22
|
+
* resolve its own context. Moved from `llm/subagentRunner.ts` so the
|
|
23
|
+
* runner stays free of `llm` imports.
|
|
24
|
+
*/
|
|
25
|
+
export declare function compatibilityBundle(task: SubagentTaskCapsule, profile: SubagentExecutionProfile, contextFiles: ContextFile[], allowedTools: readonly string[] | undefined, session: PromptSession | undefined): Promise<WorkerContextBundle>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readContextFiles, readScopedContextFilesForPath } from '../config/contextFiles.js';
|
|
2
2
|
import { estimateTextTokens, estimateToolSchemas, estimateValueTokens } from '../core/agent/contextBudget.js';
|
|
3
3
|
import { MODE_TOOL_NAMES } from '../core/subagent/executionProfiles.js';
|
|
4
|
-
import { hazeTools } from './hazeTools.js';
|
|
5
4
|
import { buildSubagentPrompt } from './systemPrompt.js';
|
|
5
|
+
import { hazeTools } from './hazeTools.js';
|
|
6
6
|
import { resolveWorkspacePath, workspaceRelativePath } from '../utils/path.js';
|
|
7
7
|
export function workerTaskMessage(task) {
|
|
8
8
|
return JSON.stringify({
|
|
@@ -53,3 +53,20 @@ export async function assembleWorkerContext(task, profile, session) {
|
|
|
53
53
|
return { instructions: [], loadedPaths: new Set(), loadedSignatures: new Map(), systemPrompt: '', tools: {}, estimatedTokens: 0, taskTokens: estimateValueTokens(workerTaskMessage(task)), validatedScope: [], policyBlock: reason };
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Legacy compatibility bundle for callers (e.g. `/fleet`) that pass explicit
|
|
58
|
+
* context files and an optional tool allowlist instead of letting the worker
|
|
59
|
+
* resolve its own context. Moved from `llm/subagentRunner.ts` so the
|
|
60
|
+
* runner stays free of `llm` imports.
|
|
61
|
+
*/
|
|
62
|
+
export async function compatibilityBundle(task, profile, contextFiles, allowedTools, session) {
|
|
63
|
+
const instructions = contextFiles;
|
|
64
|
+
const systemPrompt = buildSubagentPrompt(instructions, session, task.mode, profile);
|
|
65
|
+
const tools = {};
|
|
66
|
+
for (const name of allowedTools ?? MODE_TOOL_NAMES[task.mode])
|
|
67
|
+
if (name in hazeTools)
|
|
68
|
+
tools[name] = hazeTools[name];
|
|
69
|
+
const taskTokens = estimateValueTokens(workerTaskMessage(task));
|
|
70
|
+
const estimatedTokens = estimateTextTokens(systemPrompt) + taskTokens + estimateToolSchemas(tools).reduce((sum, value) => sum + value.tokens, 0);
|
|
71
|
+
return { instructions, systemPrompt, tools, taskTokens, estimatedTokens, validatedScope: [], loadedPaths: new Set(instructions.map(file => file.path)), loadedSignatures: new Map(instructions.flatMap(file => file.signature ? [[file.path, file.signature]] : [])), ...(estimatedTokens > profile.maxInputTokens ? { policyBlock: `Worker input estimate ${estimatedTokens} exceeds profile ${profile.name} limit ${profile.maxInputTokens}.` } : {}) };
|
|
72
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import YAML from 'yaml';
|
|
4
|
-
import {
|
|
4
|
+
import { confinedResolve } from './confinement.js';
|
|
5
5
|
import { SKILL_MARKDOWN_BYTES } from '../core/limits.js';
|
|
6
6
|
import { readUtf8Prefix } from '../core/io/boundedRead.js';
|
|
7
|
+
import { isProtectedSecretPath } from '../core/safety/secretPaths.js';
|
|
7
8
|
const MAX_REFERENCE_BYTES = 50_000;
|
|
9
|
+
/** CI-04: aggregate bounds so a dense skill cannot allocate unbounded memory. */
|
|
10
|
+
const MAX_REFERENCES = 20;
|
|
11
|
+
const MAX_TOTAL_REFERENCE_BYTES = 200_000;
|
|
8
12
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
9
13
|
const MARKDOWN_LINK_RE = /\[[^\]]*\]\(([^)]+)\)/g;
|
|
10
14
|
const PLAIN_REFERENCE_RE = /(?:^|\n)\s*(?:[-*]\s+)?((?:[A-Za-z0-9_.-]+\/)+[A-Za-z0-9_.-]+\.[A-Za-z0-9]+)\s*(?=\n|$)/g;
|
|
@@ -52,7 +56,14 @@ async function loadReference(dir, referencePath) {
|
|
|
52
56
|
const relative = path.relative(dir, absolutePath);
|
|
53
57
|
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
54
58
|
throw new Error(`Skill reference escapes skill directory: ${referencePath}`);
|
|
55
|
-
|
|
59
|
+
// CI-03: the shared secret policy applies to skill bodies and references —
|
|
60
|
+
// confinement alone does not; a protected name inside the skill directory is
|
|
61
|
+
// refused before any filesystem access. Errors carry path metadata only.
|
|
62
|
+
if (isProtectedSecretPath(absolutePath))
|
|
63
|
+
throw new Error(`Skill reference is a protected secret file: ${referencePath}`);
|
|
64
|
+
const realPath = await confinedResolve(dir, absolutePath, referencePath, 'skill directory');
|
|
65
|
+
if (isProtectedSecretPath(realPath))
|
|
66
|
+
throw new Error(`Skill reference is a protected secret file: ${referencePath}`);
|
|
56
67
|
const stat = await fs.stat(realPath);
|
|
57
68
|
if (!stat.isFile())
|
|
58
69
|
throw new Error(`Skill reference is not a file: ${referencePath}`);
|
|
@@ -65,7 +76,9 @@ export async function loadSkill(dir, source = 'global') {
|
|
|
65
76
|
const skillPath = path.join(dir, 'SKILL.md');
|
|
66
77
|
if (!(await fs.pathExists(skillPath)))
|
|
67
78
|
return null;
|
|
68
|
-
const realSkillPath = await
|
|
79
|
+
const realSkillPath = await confinedResolve(dir, skillPath, 'SKILL.md', 'skill directory');
|
|
80
|
+
if (isProtectedSecretPath(realSkillPath))
|
|
81
|
+
throw new Error('SKILL.md is a protected secret file');
|
|
69
82
|
const stat = await fs.stat(realSkillPath);
|
|
70
83
|
if (!stat.isFile())
|
|
71
84
|
throw new Error('SKILL.md is not a file');
|
|
@@ -74,6 +87,19 @@ export async function loadSkill(dir, source = 'global') {
|
|
|
74
87
|
throw new Error(`SKILL.md exceeds ${SKILL_MARKDOWN_BYTES} byte limit`);
|
|
75
88
|
const content = prefix.content;
|
|
76
89
|
const { frontmatter, body } = parseSkillMarkdown(content);
|
|
77
|
-
const
|
|
90
|
+
const referencePaths = referencedPaths(body);
|
|
91
|
+
if (referencePaths.length > MAX_REFERENCES)
|
|
92
|
+
throw new Error(`Skill declares ${referencePaths.length} references; the maximum is ${MAX_REFERENCES}.`);
|
|
93
|
+
// Sequential bounded loading (CI-04): no unbounded Promise.all fan-out, and
|
|
94
|
+
// the aggregate byte budget fails loudly instead of growing silently.
|
|
95
|
+
const references = [];
|
|
96
|
+
let totalReferenceBytes = 0;
|
|
97
|
+
for (const ref of referencePaths) {
|
|
98
|
+
const loaded = await loadReference(dir, ref);
|
|
99
|
+
totalReferenceBytes += Buffer.byteLength(loaded.content);
|
|
100
|
+
if (totalReferenceBytes > MAX_TOTAL_REFERENCE_BYTES)
|
|
101
|
+
throw new Error(`Skill references exceed the aggregate ${MAX_TOTAL_REFERENCE_BYTES} byte limit`);
|
|
102
|
+
references.push(loaded);
|
|
103
|
+
}
|
|
78
104
|
return { dir, path: realSkillPath, name: frontmatter.name, description: frontmatter.description, body, references, source };
|
|
79
105
|
}
|
|
@@ -2,13 +2,13 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { GLOBAL_SKILLS_DIR } from '../config/paths.js';
|
|
4
4
|
import { loadSkill } from './SkillLoader.js';
|
|
5
|
-
import {
|
|
5
|
+
import { confinedResolve } from './confinement.js';
|
|
6
6
|
async function loadRoot(root, containmentRoot, source, errors) {
|
|
7
7
|
if (!(await fs.pathExists(root)))
|
|
8
8
|
return [];
|
|
9
9
|
if (source === 'project') {
|
|
10
10
|
try {
|
|
11
|
-
await
|
|
11
|
+
await confinedResolve(containmentRoot, root, '.haze/skills', 'workspace');
|
|
12
12
|
}
|
|
13
13
|
catch (error) {
|
|
14
14
|
errors.push({ directory: '.haze/skills', source, message: error instanceof Error ? error.message : String(error) });
|
|
@@ -22,7 +22,7 @@ async function loadRoot(root, containmentRoot, source, errors) {
|
|
|
22
22
|
try {
|
|
23
23
|
// Project-controlled symlinks must remain inside the workspace, not merely
|
|
24
24
|
// inside a possibly symlinked .haze/skills directory.
|
|
25
|
-
await
|
|
25
|
+
await confinedResolve(containmentRoot, dir, name, source === 'project' ? 'workspace' : 'skills root');
|
|
26
26
|
if (!(await fs.stat(dir)).isDirectory())
|
|
27
27
|
continue;
|
|
28
28
|
const skill = await loadSkill(dir, source);
|
|
@@ -5,7 +5,7 @@ import YAML from 'yaml';
|
|
|
5
5
|
import { GLOBAL_SKILLS_DIR } from '../../config/paths.js';
|
|
6
6
|
import { modelWithConfig } from '../../llm/client.js';
|
|
7
7
|
import { loadSkill } from '../SkillLoader.js';
|
|
8
|
-
import {
|
|
8
|
+
import { confinedResolve } from '../confinement.js';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
const STANDARD_SKILL_REQUIREMENTS = `
|
|
11
11
|
|
|
@@ -240,10 +240,10 @@ async function skillTargetRoot(input) {
|
|
|
240
240
|
const cwd = path.resolve(input.cwd ?? process.cwd());
|
|
241
241
|
const hazeDir = path.join(cwd, '.haze');
|
|
242
242
|
if (await fs.pathExists(hazeDir))
|
|
243
|
-
await
|
|
243
|
+
await confinedResolve(cwd, hazeDir, '.haze', 'workspace');
|
|
244
244
|
const root = path.join(hazeDir, 'skills');
|
|
245
245
|
await fs.ensureDir(root);
|
|
246
|
-
await
|
|
246
|
+
await confinedResolve(cwd, root, '.haze/skills', 'workspace');
|
|
247
247
|
return { root, source: 'project' };
|
|
248
248
|
}
|
|
249
249
|
export async function createSkill(input) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared real-path confinement wrapper for skills: resolves `candidate`
|
|
3
|
+
* inside `root` or throws a ready-to-report error message. Collapses the
|
|
4
|
+
* hand-rolled try/catch formatting previously duplicated across the registry,
|
|
5
|
+
* loader, and builder.
|
|
6
|
+
*/
|
|
7
|
+
export declare function confinedResolve(root: string, candidate: string, label: string, rootLabel: string): Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { assertRealPathInsideRoot } from '../utils/path.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shared real-path confinement wrapper for skills: resolves `candidate`
|
|
4
|
+
* inside `root` or throws a ready-to-report error message. Collapses the
|
|
5
|
+
* hand-rolled try/catch formatting previously duplicated across the registry,
|
|
6
|
+
* loader, and builder.
|
|
7
|
+
*/
|
|
8
|
+
export async function confinedResolve(root, candidate, label, rootLabel) {
|
|
9
|
+
try {
|
|
10
|
+
return await assertRealPathInsideRoot(root, candidate, label, rootLabel);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
throw new Error(error instanceof Error ? error.message : String(error), { cause: error });
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/ui/codeHighlight.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { highlight, supportsLanguage } from 'cli-highlight';
|
|
2
|
-
import
|
|
2
|
+
import { cellWidth, clipCells } from './textGeometry.js';
|
|
3
3
|
/** Map a source path to a cli-highlight language when its extension is known. */
|
|
4
4
|
export function languageForPath(filePath) {
|
|
5
5
|
const extension = /\.([^./]+)$/.exec(filePath)?.[1]?.toLowerCase();
|
|
@@ -16,8 +16,8 @@ export function languageForPath(filePath) {
|
|
|
16
16
|
export function highlightedCodeLine(code, width, language) {
|
|
17
17
|
const safeWidth = Math.max(1, width);
|
|
18
18
|
const singleLine = code.replace(/\t/g, ' ');
|
|
19
|
-
const fitted = singleLine
|
|
20
|
-
? `${singleLine
|
|
19
|
+
const fitted = cellWidth(singleLine) > safeWidth
|
|
20
|
+
? `${clipCells(singleLine, safeWidth - 1)}…`
|
|
21
21
|
: singleLine;
|
|
22
22
|
let rendered = fitted;
|
|
23
23
|
try {
|
|
@@ -26,6 +26,6 @@ export function highlightedCodeLine(code, width, language) {
|
|
|
26
26
|
catch {
|
|
27
27
|
// Unknown or malformed source still renders as plain text.
|
|
28
28
|
}
|
|
29
|
-
const padding = Math.max(0, safeWidth -
|
|
29
|
+
const padding = Math.max(0, safeWidth - cellWidth(rendered));
|
|
30
30
|
return `${rendered}${' '.repeat(padding)}`;
|
|
31
31
|
}
|
|
@@ -2,13 +2,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Box, Text } from 'ink';
|
|
4
4
|
import { marked } from 'marked';
|
|
5
|
-
import
|
|
5
|
+
import { cellWidth } from '../textGeometry.js';
|
|
6
|
+
import { wrapDisplayValue } from '../inputBuffer.js';
|
|
6
7
|
import { theme } from '../theme.js';
|
|
7
8
|
import { highlightedCodeLine } from '../codeHighlight.js';
|
|
8
9
|
const MARKED_OPTIONS = { gfm: true, breaks: true };
|
|
9
10
|
export const MarkdownText = React.memo(function MarkdownText({ content, width }) {
|
|
10
11
|
const tokens = marked.lexer(content, MARKED_OPTIONS);
|
|
11
|
-
const contentWidth = Math.max(
|
|
12
|
+
const contentWidth = Math.max(1, width - 2);
|
|
12
13
|
return _jsx(Box, { flexDirection: "column", children: tokens.map((token, index) => {
|
|
13
14
|
const codeLead = token.type === 'paragraph' || token.type === 'text' ? codeLeadForFollowingFence(tokens, index) : undefined;
|
|
14
15
|
if (token.type === 'space' && bridgesCodeLeadToFence(tokens, index))
|
|
@@ -150,7 +151,7 @@ function ListItemBlock({ token, marker, markerWidth, width }) {
|
|
|
150
151
|
// Block-level content (code, nested list, blockquote, table). The marker
|
|
151
152
|
// sits on its own line when this is the first block; the block then renders
|
|
152
153
|
// indented to align with the marker.
|
|
153
|
-
return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.accent, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(
|
|
154
|
+
return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.accent, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(1, width - markerWidth) }) })] });
|
|
154
155
|
}
|
|
155
156
|
function HeadingBlock({ heading, width }) {
|
|
156
157
|
const title = stripInline(heading.text).trim();
|
|
@@ -376,8 +377,7 @@ function wrapTableCell(text, width) {
|
|
|
376
377
|
if (!word)
|
|
377
378
|
continue;
|
|
378
379
|
if (!current && visibleLength(word) > width) {
|
|
379
|
-
|
|
380
|
-
lines.push(word.slice(index, index + width));
|
|
380
|
+
lines.push(...wrapDisplayValue(word, width).map(line => line.text));
|
|
381
381
|
continue;
|
|
382
382
|
}
|
|
383
383
|
const next = current ? `${current} ${word}` : word;
|
|
@@ -386,8 +386,7 @@ function wrapTableCell(text, width) {
|
|
|
386
386
|
else {
|
|
387
387
|
flush();
|
|
388
388
|
if (visibleLength(word) > width) {
|
|
389
|
-
|
|
390
|
-
lines.push(word.slice(index, index + width));
|
|
389
|
+
lines.push(...wrapDisplayValue(word, width).map(line => line.text));
|
|
391
390
|
}
|
|
392
391
|
else {
|
|
393
392
|
current = word;
|
|
@@ -423,7 +422,7 @@ function stripInline(text) {
|
|
|
423
422
|
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
|
|
424
423
|
}
|
|
425
424
|
function visibleLength(value) {
|
|
426
|
-
return
|
|
425
|
+
return cellWidth(value);
|
|
427
426
|
}
|
|
428
427
|
function padAnsi(value, width) {
|
|
429
428
|
const visible = visibleLength(value);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type HazeTheme } from '../theme.js';
|
|
3
|
+
export type NoticeVariant = 'success' | 'error' | 'warning' | 'info';
|
|
4
|
+
/** Map library indicators to the current palette, never its default colors. */
|
|
5
|
+
export declare function indicatorTheme(palette: HazeTheme): {
|
|
6
|
+
components: Record<string, import("@inkjs/ui").ComponentTheme>;
|
|
7
|
+
};
|
|
8
|
+
/** A layout element: render beside Text, not nested inside it. */
|
|
9
|
+
export declare function ActivitySpinner({ color }: {
|
|
10
|
+
color?: string;
|
|
11
|
+
}): React.JSX.Element;
|
|
12
|
+
export declare function StatusNotice({ variant, children }: {
|
|
13
|
+
variant: NoticeVariant;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}): React.JSX.Element;
|