@denizokcu/haze 1.7.12 → 1.8.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 +38 -0
- package/README.md +30 -6
- package/SECURITY.md +1 -1
- package/bin/haze.js +47 -19
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +1 -2
- package/dist/cli/chat/ChatHeader.d.ts +6 -0
- package/dist/cli/chat/ChatHeader.js +11 -0
- package/dist/cli/chat/ChatScreen.d.ts +16 -0
- package/dist/cli/chat/ChatScreen.js +399 -0
- package/dist/cli/chat/ChatScreenView.d.ts +68 -0
- package/dist/cli/chat/ChatScreenView.js +47 -0
- package/dist/cli/chat/LiveTail.d.ts +11 -0
- package/dist/cli/chat/LiveTail.js +26 -0
- package/dist/cli/chat/TaskBar.d.ts +3 -2
- package/dist/cli/chat/TaskBar.js +4 -0
- package/dist/cli/chat/agentTurnRunner.d.ts +12 -0
- package/dist/cli/chat/agentTurnRunner.js +177 -0
- package/dist/cli/chat/busyIndicator.js +9 -5
- package/dist/cli/chat/chatMetrics.d.ts +7 -0
- package/dist/cli/chat/chatMetrics.js +15 -1
- package/dist/cli/chat/chatViewModel.d.ts +85 -0
- package/dist/cli/chat/chatViewModel.js +66 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +0 -14
- package/dist/cli/chat/fileMentionSuggestions.js +4 -21
- package/dist/cli/chat/liveTheme.d.ts +11 -0
- package/dist/cli/chat/liveTheme.js +26 -0
- package/dist/cli/chat/messageFinalize.d.ts +4 -0
- package/dist/cli/chat/messageFinalize.js +8 -0
- package/dist/cli/chat/messages.js +1 -1
- package/dist/cli/chat/pickerOpeners.d.ts +23 -0
- package/dist/cli/chat/pickerOpeners.js +36 -0
- package/dist/cli/chat/promptSessionState.d.ts +11 -0
- package/dist/cli/chat/promptSessionState.js +39 -0
- package/dist/cli/chat/renderMetrics.d.ts +8 -0
- package/dist/cli/chat/renderMetrics.js +14 -0
- package/dist/cli/chat/resizeGuard.d.ts +11 -0
- package/dist/cli/chat/resizeGuard.js +25 -0
- package/dist/cli/chat/screenDeps.d.ts +116 -0
- package/dist/cli/chat/screenDeps.js +1 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +4 -1
- package/dist/cli/chat/settingsSelection.d.ts +33 -0
- package/dist/cli/chat/settingsSelection.js +46 -0
- package/dist/cli/chat/skillNotices.d.ts +18 -0
- package/dist/cli/chat/skillNotices.js +26 -0
- package/dist/cli/chat/startupInfo.js +1 -1
- package/dist/cli/chat/submitPipeline.d.ts +8 -0
- package/dist/cli/chat/submitPipeline.js +141 -0
- package/dist/cli/chat/terminalControl.js +1 -1
- package/dist/cli/chat/toolSummaries.d.ts +29 -0
- package/dist/cli/chat/toolSummaries.js +268 -0
- package/dist/cli/chat/turnState.d.ts +8 -0
- package/dist/cli/chat/turnState.js +1 -0
- package/dist/cli/chat/userCommandFlow.d.ts +21 -0
- package/dist/cli/chat/userCommandFlow.js +66 -0
- package/dist/cli/chat/userCommandRunner.d.ts +14 -0
- package/dist/cli/chat/userCommandRunner.js +56 -0
- package/dist/cli/chat/wizard/providerHandlers.js +19 -2
- package/dist/cli/chat/wizardTrail.d.ts +22 -0
- package/dist/cli/chat/wizardTrail.js +55 -0
- package/dist/cli/commands/chat.d.ts +1 -13
- package/dist/cli/commands/chat.js +10 -798
- package/dist/cli/commands/commandHelp.js +7 -5
- package/dist/cli/commands/commandSuggest.d.ts +2 -0
- package/dist/cli/commands/commandSuggest.js +35 -0
- package/dist/cli/commands/commands.js +10 -3
- package/dist/cli/commands/formatters.d.ts +1 -23
- package/dist/cli/commands/formatters.js +3 -252
- package/dist/cli/commands/modelCommand.js +11 -7
- package/dist/cli/commands/reasoningCommand.js +3 -3
- package/dist/cli/commands/runCommand.js +6 -2
- package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +7 -2
- package/dist/cli/commands/streaming/attemptSetup.d.ts +1 -0
- package/dist/cli/commands/streaming/attemptSetup.js +26 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +1 -1
- package/dist/cli/commands/streaming/stepProjection.d.ts +59 -0
- package/dist/cli/commands/streaming/stepProjection.js +54 -0
- package/dist/cli/commands/streaming/streamLoop.js +31 -23
- package/dist/cli/commands/streaming/toolGroupRenderer.js +1 -1
- package/dist/cli/commands/streaming/toolPartHandlers.js +1 -1
- package/dist/cli/commands/streaming.d.ts +3 -1
- package/dist/cli/commands/wizardFlow.d.ts +2 -0
- package/dist/cli/commands/wizardFlow.js +3 -0
- package/dist/cli/index.js +8 -4
- package/dist/cli/terminalTitle.js +9 -3
- package/dist/config/contextFiles.d.ts +2 -5
- package/dist/config/contextFiles.js +1 -1
- package/dist/config/inputHistory.js +2 -2
- package/dist/config/providerAuth.js +2 -2
- package/dist/config/providerModelFacts.js +5 -0
- package/dist/config/providerPresets.js +1 -1
- package/dist/config/settings.d.ts +7 -0
- package/dist/config/settings.js +9 -2
- package/dist/config/updateCheck.js +2 -2
- package/dist/core/agent/completionController.d.ts +1 -1
- package/dist/core/agent/contextBudget.d.ts +1 -1
- package/dist/core/agent/goalPolicy.js +8 -2
- package/dist/core/agent/overflow.js +5 -0
- package/dist/core/agent/toolCapabilities.js +14 -0
- package/dist/core/agent/userCommands.d.ts +53 -0
- package/dist/core/agent/userCommands.js +116 -0
- package/dist/core/agent/workState.d.ts +3 -1
- package/dist/core/agent/workState.js +57 -26
- package/dist/core/contextFileTypes.d.ts +12 -0
- package/dist/core/contextFileTypes.js +1 -0
- package/dist/core/graph/buildGraph.js +1 -1
- package/dist/core/graph/store.js +1 -1
- package/dist/core/limits.d.ts +2 -0
- package/dist/core/limits.js +2 -0
- package/dist/core/log/llmLog.js +2 -2
- package/dist/{config → core/persistence}/privateStorage.js +1 -1
- package/dist/core/process/runBoundedProcess.d.ts +7 -4
- package/dist/core/process/runBoundedProcess.js +10 -5
- package/dist/core/safety/redaction.d.ts +2 -0
- package/dist/core/safety/redaction.js +26 -5
- package/dist/core/safety/secretPaths.js +12 -3
- package/dist/core/safety/urlGuard.js +2 -0
- package/dist/core/session/sessionStore.d.ts +8 -1
- package/dist/core/session/sessionStore.js +15 -4
- package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
- package/dist/core/shellOutput/types.d.ts +1 -1
- package/dist/{llm → core}/toolResultTypes.d.ts +1 -1
- package/dist/core/validation/outputParser.d.ts +1 -1
- package/dist/llm/hazeTools.js +2 -0
- package/dist/llm/lsp/pool.js +1 -1
- package/dist/llm/lsp/workspaceEdit.d.ts +1 -1
- package/dist/llm/requestContext.d.ts +3 -0
- package/dist/llm/requestContext.js +20 -8
- package/dist/llm/systemPrompt.js +10 -3
- package/dist/llm/toolGroups.d.ts +534 -0
- package/dist/llm/toolGroups.js +57 -0
- package/dist/llm/tools/editMatch.d.ts +1 -1
- package/dist/llm/tools/failures.d.ts +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +1 -1
- package/dist/llm/tools/fileToolShared.js +1 -1
- package/dist/llm/tools/fileTools.js +1 -1
- package/dist/llm/tools/gitTools.d.ts +12 -0
- package/dist/llm/tools/gitTools.js +527 -0
- package/dist/llm/tools/readRecovery.d.ts +1 -1
- package/dist/llm/tools/replaceInFiles.d.ts +1 -1
- package/dist/llm/tools/replaceInFiles.js +1 -1
- package/dist/llm/tools/taskTool.js +4 -1
- package/dist/llm/tools/toolContext.js +5 -2
- package/dist/llm/tools/toolContextState.d.ts +1 -1
- package/dist/llm/tools/workspaceFile.d.ts +2 -2
- package/dist/llm/tools/workspaceFile.js +10 -5
- package/dist/skills/SkillRegistry.js +1 -1
- package/dist/skills/builder/SkillBuilder.js +1 -1
- package/dist/skills/plugins/installer.js +1 -1
- package/dist/skills/plugins/runtime.js +1 -1
- package/dist/ui/components/MarkdownText.d.ts +14 -0
- package/dist/ui/components/MarkdownText.js +77 -12
- package/dist/ui/components/NativeIndicators.js +5 -1
- package/dist/ui/components/StreamingMarkdownText.d.ts +3 -1
- package/dist/ui/components/StreamingMarkdownText.js +39 -11
- package/dist/ui/components/TextInput.d.ts +1 -2
- package/dist/ui/components/TextInput.js +79 -9
- package/dist/ui/components/WizardChoices.d.ts +1 -2
- package/dist/ui/components/useInputSuggestions.d.ts +1 -1
- package/dist/ui/components/useInputSuggestions.js +1 -1
- package/dist/ui/mentionDetection.d.ts +20 -0
- package/dist/ui/mentionDetection.js +24 -0
- package/dist/ui/terminalColors.d.ts +4 -4
- package/dist/ui/terminalColors.js +23 -6
- package/dist/ui/terminalSanitize.js +8 -3
- package/dist/ui/textGeometry.d.ts +2 -0
- package/dist/ui/textGeometry.js +6 -0
- package/dist/ui/themes/registry.js +33 -33
- package/dist/utils/openPath.js +7 -0
- package/package.json +13 -13
- /package/dist/{llm/tools → core/ignore}/gitIgnore.d.ts +0 -0
- /package/dist/{llm/tools → core/ignore}/gitIgnore.js +0 -0
- /package/dist/{config → core}/paths.d.ts +0 -0
- /package/dist/{config → core}/paths.js +0 -0
- /package/dist/{config → core/persistence}/privateStorage.d.ts +0 -0
- /package/dist/{llm → core}/toolResultTypes.js +0 -0
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
export const COMMAND_HELP_ENTRIES = [
|
|
2
2
|
{ usage: '/help', description: 'Show all available slash commands and what they do.' },
|
|
3
|
+
{ usage: '! <command>', description: 'Run a shell command directly (no model turn) and show its output; the result stays in the conversation for the model. 60s limit, Esc cancels.' },
|
|
4
|
+
{ usage: '\\! <text>', description: 'Send a message that starts with ! as a normal prompt (the backslash is removed).' },
|
|
3
5
|
{ usage: '/provider', description: 'Choose a provider, then use it, add/remove models, set API key, toggle image input, or remove it.' },
|
|
4
6
|
{ usage: '/model', description: 'Choose a model, or add models from a provider\'s models endpoint.' },
|
|
5
|
-
{ usage: '/model <name-or-provider:name>', description: 'Set a model
|
|
7
|
+
{ usage: '/model <name-or-provider:name>', description: 'Set a configured model, or register a new one explicitly as provider:model (a bare unknown name is rejected). Selecting a model also sets its provider.' },
|
|
6
8
|
{ usage: '/model list', description: 'List all configured models across providers.' },
|
|
7
9
|
{ usage: '/settings', description: 'Show the configured provider, model, API key status, LSP/MCP servers, skills, and loaded context files.' },
|
|
8
10
|
{ usage: '/settings open', description: 'Open ~/.haze/settings.json with the OS default app.' },
|
|
9
11
|
{ usage: '/settings edit', description: 'Open ~/.haze/settings.json in $VISUAL/$EDITOR in a fullscreen terminal handoff; falls back to the OS default app when no editor is configured. Restart haze to apply external changes.' },
|
|
10
12
|
{ usage: '/themes', description: 'Choose a terminal theme from the built-in registry (light palettes and oh-my-zsh ports included); applies immediately.' },
|
|
11
13
|
{ usage: '/themes <name>', description: 'Set the theme directly, e.g. /themes robbyrussell. Saved to ~/.haze/settings.json; text already on screen keeps its old colors.' },
|
|
12
|
-
{ usage: '/reasoning', description: 'Choose a reasoning effort level (none, minimal, low, medium, high, xhigh, max) for the active model, for this session; unset sends no parameter, reset falls back to the saved/default level.' },
|
|
13
|
-
{ usage: '/reasoning <level|unset|reset|status>', description: 'Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
14
|
-
{ usage: '/thinking', description: 'Alias for /reasoning. Choose a reasoning effort level (none, minimal, low, medium, high, xhigh, max) for the active model, for this session; unset sends no parameter, reset falls back to the saved/default level.' },
|
|
15
|
-
{ usage: '/thinking <level|unset|reset|status>', description: 'Alias for /reasoning. Set the reasoning effort for the active model for this session, send no parameter with unset, remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
14
|
+
{ usage: '/reasoning', description: 'Choose a reasoning effort level (none, minimal, low, medium, high, xhigh, max) for the active model, for this session; off = none, unset sends no parameter (provider default), reset falls back to the saved/default level.' },
|
|
15
|
+
{ usage: '/reasoning <level|off|unset|reset|status>', description: 'Set the reasoning effort for the active model for this session (off = none), send no parameter with unset (provider default), remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
16
|
+
{ usage: '/thinking', description: 'Alias for /reasoning. Choose a reasoning effort level (none, minimal, low, medium, high, xhigh, max) for the active model, for this session; off = none, unset sends no parameter (provider default), reset falls back to the saved/default level.' },
|
|
17
|
+
{ usage: '/thinking <level|off|unset|reset|status>', description: 'Alias for /reasoning. Set the reasoning effort for the active model for this session (off = none), send no parameter with unset (provider default), remove the override with reset, or show the current level with status. Low is the default. Endpoints without native support ignore the parameter.' },
|
|
16
18
|
{ usage: '/skills', description: 'Manage Markdown skills: generate a custom skill, show info, enable/disable, validate, or remove.' },
|
|
17
19
|
{ usage: '/plugin', description: 'Open the plugin picker: install or inspect a local plugin/collection, or manage installed project plugins. /kit is an alias.' },
|
|
18
20
|
{ usage: '/plugin inspect|install <local-directory> [plugin-name]', description: 'Inspect or install a Claude/Agent Plugins package or a selected local marketplace plugin. Only skills are activated; review source first.' },
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { COMMAND_HELP_ENTRIES } from './commandHelp.js';
|
|
2
|
+
/** Documented command names (the first token of each `/help` usage line) plus aliases that exist only as matchers. */
|
|
3
|
+
const COMMAND_NAMES = [...new Set([...COMMAND_HELP_ENTRIES.map(entry => entry.usage.split(/[\s<[]/)[0] ?? ''), '/kit'])];
|
|
4
|
+
/** Levenshtein distance between two strings. */
|
|
5
|
+
function editDistance(left, right) {
|
|
6
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
7
|
+
for (let leftIndex = 1; leftIndex <= left.length; leftIndex++) {
|
|
8
|
+
const current = [leftIndex];
|
|
9
|
+
for (let rightIndex = 1; rightIndex <= right.length; rightIndex++) {
|
|
10
|
+
const cost = left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1;
|
|
11
|
+
current[rightIndex] = Math.min(current[rightIndex - 1] + 1, previous[rightIndex] + 1, previous[rightIndex - 1] + cost);
|
|
12
|
+
}
|
|
13
|
+
previous = current;
|
|
14
|
+
}
|
|
15
|
+
return previous[right.length];
|
|
16
|
+
}
|
|
17
|
+
/** Closest known command (case-insensitive) by edit distance, within about one edit per three characters and at least two. */
|
|
18
|
+
function suggestCommand(value) {
|
|
19
|
+
const typed = value.trim().split(/\s+/)[0]?.toLowerCase();
|
|
20
|
+
if (!typed)
|
|
21
|
+
return undefined;
|
|
22
|
+
const maxDistance = Math.max(2, Math.floor(typed.length / 3));
|
|
23
|
+
let best;
|
|
24
|
+
for (const name of COMMAND_NAMES) {
|
|
25
|
+
const distance = editDistance(typed, name);
|
|
26
|
+
if (!best || distance < best.distance)
|
|
27
|
+
best = { name, distance };
|
|
28
|
+
}
|
|
29
|
+
return best && best.distance <= maxDistance ? best.name : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** System message for an unrecognized slash command: the closest known command (when near) and a pointer to `/help`. */
|
|
32
|
+
export function unknownCommandMessage(value) {
|
|
33
|
+
const suggestion = suggestCommand(value);
|
|
34
|
+
return `Unknown command: ${value}.${suggestion ? ` Did you mean ${suggestion}?` : ''} Run /help for the list.`;
|
|
35
|
+
}
|
|
@@ -3,6 +3,7 @@ import { SETTINGS_FILE, writeSettings } from '../../config/settings.js';
|
|
|
3
3
|
import { openPath } from '../../utils/openPath.js';
|
|
4
4
|
import { clearTasks } from '../../core/tasks/taskStorage.js';
|
|
5
5
|
import { COMMAND_HELP_ENTRIES, formatCommandHelp } from './commandHelp.js';
|
|
6
|
+
import { unknownCommandMessage } from './commandSuggest.js';
|
|
6
7
|
import { handleFleetCommand } from './fleetCommand.js';
|
|
7
8
|
import { handleInitCommand } from './initCommand.js';
|
|
8
9
|
import { handleLogsCommand } from './logsCommand.js';
|
|
@@ -24,6 +25,10 @@ function exact(command) {
|
|
|
24
25
|
function exactOrArgs(command) {
|
|
25
26
|
return value => value === command ? { args: '' } : value.startsWith(`${command} `) ? { args: value.slice(command.length).trim() } : false;
|
|
26
27
|
}
|
|
28
|
+
async function clearChat(ctx) {
|
|
29
|
+
await ctx.clearConversation();
|
|
30
|
+
await clearTasks();
|
|
31
|
+
}
|
|
27
32
|
const SLASH_COMMANDS = [
|
|
28
33
|
{ match: value => value === '/exit' || value === '/quit' ? { args: '' } : false, run: () => 'exit' },
|
|
29
34
|
{ match: exact('/help'), run: (_args, ctx) => { ctx.addSystemMessage(formatCommandHelp(COMMAND_HELP_ENTRIES)); return HANDLED; } },
|
|
@@ -33,8 +38,10 @@ const SLASH_COMMANDS = [
|
|
|
33
38
|
await ctx.resumeSession(args || undefined);
|
|
34
39
|
else
|
|
35
40
|
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
36
|
-
{ match: exact('/new'), run: async (_args, ctx) => { if (ctx.newSession)
|
|
41
|
+
{ match: exact('/new'), run: async (_args, ctx) => { if (ctx.newSession) {
|
|
42
|
+
await clearChat(ctx);
|
|
37
43
|
await ctx.newSession();
|
|
44
|
+
}
|
|
38
45
|
else
|
|
39
46
|
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
40
47
|
{ match: exactOrArgs('/compact'), run: async (args, ctx) => {
|
|
@@ -46,7 +53,7 @@ const SLASH_COMMANDS = [
|
|
|
46
53
|
ctx.addSystemMessage('Compaction is unavailable.');
|
|
47
54
|
return HANDLED;
|
|
48
55
|
} },
|
|
49
|
-
{ match: exact('/clear'), run: async (_args, ctx) => { await ctx
|
|
56
|
+
{ match: exact('/clear'), run: async (_args, ctx) => { await clearChat(ctx); return HANDLED; } },
|
|
50
57
|
{ match: exactOrArgs('/logs'), run: async (args, ctx) => await handleLogsCommand(args, ctx) },
|
|
51
58
|
{ match: exact('/editor'), run: async (_args, ctx) => {
|
|
52
59
|
if (!ctx.composeInEditor) {
|
|
@@ -100,7 +107,7 @@ export async function handleSlashCommand(value, ctx) {
|
|
|
100
107
|
if (modelResult)
|
|
101
108
|
return modelResult;
|
|
102
109
|
if (value.startsWith('/')) {
|
|
103
|
-
ctx.addSystemMessage(
|
|
110
|
+
ctx.addSystemMessage(unknownCommandMessage(value));
|
|
104
111
|
return 'handled';
|
|
105
112
|
}
|
|
106
113
|
return 'unhandled';
|
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
/**
|
|
3
|
-
* One-line summary of a tool call for the transcript rows. Wraps the raw
|
|
4
|
-
* builder: paths, patterns, and commands are model/repo-derived, so terminal
|
|
5
|
-
* control sequences are stripped at this sink (HZA-3).
|
|
6
|
-
*/
|
|
7
|
-
export declare function toolCallSummary(toolName: string, input: unknown): string;
|
|
8
|
-
/**
|
|
9
|
-
* One-line summary of a tool result for the transcript rows; same terminal
|
|
10
|
-
* control-sequence sink discipline as `toolCallSummary` (HZA-3).
|
|
11
|
-
*/
|
|
12
|
-
export declare function toolResultSummary(event: {
|
|
13
|
-
success: boolean;
|
|
14
|
-
output?: unknown;
|
|
15
|
-
error?: unknown;
|
|
16
|
-
}): string;
|
|
17
|
-
/**
|
|
18
|
-
* A short, human label for the live busy indicator while a tool is running,
|
|
19
|
-
* e.g. "Running npm test", "Reading src/foo.ts", "Searching".
|
|
20
|
-
* Lets the developer see *what* is happening, not just that something is.
|
|
21
|
-
*/
|
|
22
|
-
export declare function busyToolLabel(toolName: string, input: unknown): string;
|
|
1
|
+
export { busyToolLabel, compact, toolCallSummary, toolResultSummary } from '../chat/toolSummaries.js';
|
|
23
2
|
/** Compact transcript row for a user-attached image (F03); never dumps bytes. */
|
|
24
3
|
export declare function imageAttachmentLine(attachment: {
|
|
25
4
|
fileName: string;
|
|
@@ -52,4 +31,3 @@ export interface ContextReportData {
|
|
|
52
31
|
}
|
|
53
32
|
/** Render a detailed, /context-style token breakdown. Pure for testability. */
|
|
54
33
|
export declare function formatContextReport(data: ContextReportData): string;
|
|
55
|
-
export {};
|
|
@@ -1,256 +1,7 @@
|
|
|
1
1
|
import { formatBytes } from '../../utils/format.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (value instanceof Error) {
|
|
6
|
-
text = value.message;
|
|
7
|
-
}
|
|
8
|
-
else if (typeof value === 'string') {
|
|
9
|
-
text = value;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
text = JSON.stringify(value, (_key, nestedValue) => nestedValue instanceof Error ? nestedValue.message : nestedValue);
|
|
13
|
-
}
|
|
14
|
-
if (!text)
|
|
15
|
-
return value === null ? 'null' : value === undefined ? 'undefined' : '';
|
|
16
|
-
if (text === '{}')
|
|
17
|
-
return ''; // empty object: nothing useful to render; avoid "[object Object]"
|
|
18
|
-
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* One-line summary of a tool call for the transcript rows. Wraps the raw
|
|
22
|
-
* builder: paths, patterns, and commands are model/repo-derived, so terminal
|
|
23
|
-
* control sequences are stripped at this sink (HZA-3).
|
|
24
|
-
*/
|
|
25
|
-
export function toolCallSummary(toolName, input) {
|
|
26
|
-
return stripTerminalControlSequences(toolCallSummaryText(toolName, input));
|
|
27
|
-
}
|
|
28
|
-
function toolCallSummaryText(toolName, input) {
|
|
29
|
-
const data = input;
|
|
30
|
-
if (toolName === 'shell' && typeof data?.command === 'string') {
|
|
31
|
-
const mode = data.background === true ? ' (background)' : typeof data.timeoutSeconds === 'number' ? ` (timeout ${data.timeoutSeconds}s)` : '';
|
|
32
|
-
return `shell $ ${data.command}${mode}`;
|
|
33
|
-
}
|
|
34
|
-
if (toolName === 'process' && typeof data?.action === 'string')
|
|
35
|
-
return `process ${data.action}${typeof data.backgroundId === 'string' ? ` ${data.backgroundId}` : ''}`;
|
|
36
|
-
if (toolName === 'grep' && typeof data?.pattern === 'string') {
|
|
37
|
-
const path = typeof data.path === 'string' && data.path !== '.' ? ` in ${data.path}` : '';
|
|
38
|
-
const glob = typeof data.glob === 'string' ? ` (${data.glob})` : '';
|
|
39
|
-
return `grep "${data.pattern}"${path}${glob}`;
|
|
40
|
-
}
|
|
41
|
-
if (toolName === 'listFiles' && typeof data?.path === 'string')
|
|
42
|
-
return `listFiles ${data.path}`;
|
|
43
|
-
if ((toolName === 'readFile' || toolName === 'writeFile')) {
|
|
44
|
-
if (typeof data?.path === 'string')
|
|
45
|
-
return `${toolName} ${data.path}`;
|
|
46
|
-
if (data == null || (typeof data === 'object' && Object.keys(data).length === 0))
|
|
47
|
-
return toolName; // input not yet streamed (tool-input-start) or empty
|
|
48
|
-
}
|
|
49
|
-
if (toolName === 'editFile' && typeof data?.path === 'string') {
|
|
50
|
-
const edits = Array.isArray(data.edits) ? ` (${data.edits.length} edit${data.edits.length === 1 ? '' : 's'})` : '';
|
|
51
|
-
return `${toolName} ${data.path}${edits}`;
|
|
52
|
-
}
|
|
53
|
-
if (toolName === 'replaceInFiles' && typeof data?.needle === 'string')
|
|
54
|
-
return `replaceInFiles "${compact(data.needle, 60)}"${typeof data.path === 'string' && data.path !== '.' ? ` in ${data.path}` : ''}${data.dryRun === false ? '' : ' (dry run)'}`;
|
|
55
|
-
if (toolName === 'replaceLines' && typeof data?.path === 'string')
|
|
56
|
-
return `replaceLines ${data.path}:${data.startLine}-${data.endLine}`;
|
|
57
|
-
if ((toolName === 'editFile' || toolName === 'replaceInFiles' || toolName === 'replaceLines') && (data == null || (typeof data === 'object' && Object.keys(data).length === 0)))
|
|
58
|
-
return toolName;
|
|
59
|
-
if (toolName === 'subagent') {
|
|
60
|
-
const task = typeof data?.objective === 'string' ? data.objective : typeof data?.task === 'string' ? data.task : undefined;
|
|
61
|
-
if (task) {
|
|
62
|
-
const taskPreview = task.length > 60 ? `${task.slice(0, 60).trimEnd()}…` : task;
|
|
63
|
-
return `subagent "${taskPreview}"`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (toolName === 'writeTasks') {
|
|
67
|
-
const tasks = Array.isArray(data?.tasks) ? data.tasks : [];
|
|
68
|
-
return `writeTasks (${tasks.length} task${tasks.length === 1 ? '' : 's'})`;
|
|
69
|
-
}
|
|
70
|
-
if (toolName === 'lspWorkspaceSymbols' && typeof data?.query === 'string')
|
|
71
|
-
return `lspWorkspaceSymbols "${data.query}"`;
|
|
72
|
-
if (toolName === 'lspSymbols' && typeof data?.path === 'string')
|
|
73
|
-
return `lspSymbols ${data.path}`;
|
|
74
|
-
if ((toolName === 'lspFindSymbol' || toolName === 'lspRenameSymbol' || toolName === 'lspSafeDeleteSymbol' || toolName === 'lspDiagnosticsForSymbol') && typeof data?.namePath === 'string')
|
|
75
|
-
return `${toolName} ${typeof data.path === 'string' ? `${data.path}:` : ''}${data.namePath}`;
|
|
76
|
-
if (toolName === 'lspDiagnostics' && typeof data?.path === 'string')
|
|
77
|
-
return `lspDiagnostics ${data.path}`;
|
|
78
|
-
if ((toolName === 'lspDefinition' || toolName === 'lspTypeDefinition' || toolName === 'lspImplementation' || toolName === 'lspReferences') && typeof data?.path === 'string')
|
|
79
|
-
return `${toolName} ${data.path}:${data.line}:${data.column}`;
|
|
80
|
-
if (toolName === 'graphQuery' && typeof data?.question === 'string')
|
|
81
|
-
return `map: query "${compact(data.question, 60)}"`;
|
|
82
|
-
if ((toolName === 'graphExplain' || toolName === 'graphAffected') && typeof data?.symbol === 'string')
|
|
83
|
-
return `map: ${toolName === 'graphExplain' ? 'explain' : 'affected'} ${data.symbol}`;
|
|
84
|
-
if (toolName === 'graphPath' && typeof data?.from === 'string' && typeof data?.to === 'string')
|
|
85
|
-
return `map: path ${data.from} -> ${data.to}`;
|
|
86
|
-
if (toolName === 'graphRebuild')
|
|
87
|
-
return 'map: rebuild';
|
|
88
|
-
return `${toolName} ${compact(input)}`;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* One-line summary of a tool result for the transcript rows; same terminal
|
|
92
|
-
* control-sequence sink discipline as `toolCallSummary` (HZA-3).
|
|
93
|
-
*/
|
|
94
|
-
export function toolResultSummary(event) {
|
|
95
|
-
return stripTerminalControlSequences(toolResultSummaryText(event));
|
|
96
|
-
}
|
|
97
|
-
function toolResultSummaryText(event) {
|
|
98
|
-
const output = event.output;
|
|
99
|
-
if (!event.success)
|
|
100
|
-
return `failed: ${compact(event.error ?? output?.error ?? event.output)}`;
|
|
101
|
-
if (output?.duplicateSkipped === true)
|
|
102
|
-
return 'skipped duplicate';
|
|
103
|
-
if (output?.background === true && typeof output.backgroundId === 'string') {
|
|
104
|
-
return `⏵ ${output.backgroundId} ${compact(output.command, 80)}${typeof output.pid === 'number' ? ` (pid ${output.pid})` : ''}`;
|
|
105
|
-
}
|
|
106
|
-
if (typeof output?.totalMatches === 'number') {
|
|
107
|
-
const count = output.totalMatches;
|
|
108
|
-
return count === 0 ? 'no matches' : `${output.matchCountIsLowerBound === true ? 'at least ' : ''}${count} match${count === 1 ? '' : 'es'}`;
|
|
109
|
-
}
|
|
110
|
-
if (typeof output?.validationSummary === 'object' && output.validationSummary != null && 'summaryText' in output.validationSummary) {
|
|
111
|
-
const summary = output.validationSummary;
|
|
112
|
-
const next = typeof summary.suggestedNextStep === 'string' ? `; next: ${summary.suggestedNextStep}` : '';
|
|
113
|
-
return `${String(summary.summaryText)}${next}`;
|
|
114
|
-
}
|
|
115
|
-
if (typeof output?.code === 'number') {
|
|
116
|
-
const risk = typeof output.classification?.riskLevel === 'string'
|
|
117
|
-
? ` (${output.classification.riskLevel})`
|
|
118
|
-
: '';
|
|
119
|
-
return `exited with code ${output.code}${risk}`;
|
|
120
|
-
}
|
|
121
|
-
const resultOutput = output ?? {};
|
|
122
|
-
const capsule = typeof resultOutput.capsule === 'object' && resultOutput.capsule != null ? resultOutput.capsule : undefined;
|
|
123
|
-
if (capsule && typeof capsule.termination === 'string' && typeof capsule.deliverable === 'string') {
|
|
124
|
-
const summary = capsule.deliverable.split('\n')[0] ?? '';
|
|
125
|
-
const preview = summary.length > 120 ? `${summary.slice(0, 120).trimEnd()}…` : summary;
|
|
126
|
-
const telemetry = typeof resultOutput.telemetry === 'object' && resultOutput.telemetry != null ? resultOutput.telemetry : undefined;
|
|
127
|
-
const calls = typeof telemetry?.toolCallCount === 'number' ? telemetry.toolCallCount : typeof resultOutput.toolCallCount === 'number' ? resultOutput.toolCallCount : 0;
|
|
128
|
-
const durationMs = typeof telemetry?.durationMs === 'number' ? telemetry.durationMs : resultOutput.durationMs;
|
|
129
|
-
const duration = typeof durationMs === 'number' ? ` in ${(durationMs / 1000).toFixed(1)}s` : '';
|
|
130
|
-
const meta = calls > 0 ? ` (${calls} call${calls === 1 ? '' : 's'}${duration})` : '';
|
|
131
|
-
return `${capsule.termination}${capsule.usable === false ? ' · unusable' : ''}${capsule.truncated === true ? ' · truncated' : ''}${meta}: ${preview}`;
|
|
132
|
-
}
|
|
133
|
-
if (typeof output?.status === 'string' && typeof output?.summary === 'string') {
|
|
134
|
-
const summary = output.summary.split('\n')[0] ?? '';
|
|
135
|
-
const preview = summary.length > 120 ? `${summary.slice(0, 120).trimEnd()}…` : summary;
|
|
136
|
-
const calls = typeof output.toolCallCount === 'number' ? output.toolCallCount : output.toolCalls?.length ?? 0;
|
|
137
|
-
const duration = typeof output.durationMs === 'number' ? ` in ${(output.durationMs / 1000).toFixed(1)}s` : '';
|
|
138
|
-
const meta = calls > 0 ? ` (${calls} call${calls === 1 ? '' : 's'}${duration})` : '';
|
|
139
|
-
return `${output.status}${meta}: ${preview}`;
|
|
140
|
-
}
|
|
141
|
-
if (typeof output?.server === 'string' && Array.isArray(output.symbols)) {
|
|
142
|
-
const count = output.symbols.length;
|
|
143
|
-
return `${count} symbol${count === 1 ? '' : 's'} from ${output.server}`;
|
|
144
|
-
}
|
|
145
|
-
if (typeof output?.server === 'string' && Array.isArray(output.locations)) {
|
|
146
|
-
const count = output.locations.length;
|
|
147
|
-
return `${count} location${count === 1 ? '' : 's'} from ${output.server}`;
|
|
148
|
-
}
|
|
149
|
-
if (typeof output?.answer === 'string' && typeof output?.graph === 'object') {
|
|
150
|
-
// graphQuery/graphPath answers
|
|
151
|
-
const stale = output.graph.stale === true ? ' · stale graph' : '';
|
|
152
|
-
const seeds = typeof output.seeds === 'number' ? `${output.seeds} seed${output.seeds === 1 ? '' : 's'}` : typeof output.hops === 'number' ? `${output.hops} hop${output.hops === 1 ? '' : 's'}` : '';
|
|
153
|
-
return `${seeds}${stale}: ${compact(output.answer, 120)}`;
|
|
154
|
-
}
|
|
155
|
-
if (Array.isArray(output?.affected) && typeof output.symbol === 'string') {
|
|
156
|
-
const count = output.affected.length;
|
|
157
|
-
return count === 0 ? `no reverse relationships for ${output.symbol}` : `${count} affected by ${output.symbol}`;
|
|
158
|
-
}
|
|
159
|
-
if (typeof output?.nodes === 'number' && typeof output?.edges === 'number' && output?.toolName === 'graphRebuild') {
|
|
160
|
-
return `graph built: ${output.nodes} nodes · ${output.edges} edges · ${output.files} files`;
|
|
161
|
-
}
|
|
162
|
-
if (typeof output?.ok === 'boolean') {
|
|
163
|
-
// writeTasks result
|
|
164
|
-
if (output.ok && typeof output.summary === 'string') {
|
|
165
|
-
return compact(output.summary, 120);
|
|
166
|
-
}
|
|
167
|
-
if (output.ok) {
|
|
168
|
-
if (output.noChange === true)
|
|
169
|
-
return 'No changes made';
|
|
170
|
-
if (typeof output.addedLines === 'number' || typeof output.removedLines === 'number') {
|
|
171
|
-
const added = typeof output.addedLines === 'number' ? output.addedLines : 0;
|
|
172
|
-
const removed = typeof output.removedLines === 'number' ? output.removedLines : 0;
|
|
173
|
-
return `Added ${added} line${added === 1 ? '' : 's'}, removed ${removed} line${removed === 1 ? '' : 's'}`;
|
|
174
|
-
}
|
|
175
|
-
return 'completed';
|
|
176
|
-
}
|
|
177
|
-
if (output.reasonCode === 'secret_file_protected' || output.reasonCode === 'git_internals_protected') {
|
|
178
|
-
// Protection events are visible but distinct from ordinary failures so
|
|
179
|
-
// the developer can audit them at a glance; never print file contents.
|
|
180
|
-
const protectedPath = typeof output.path === 'string' && output.path ? ` (${compact(output.path, 80)})` : '';
|
|
181
|
-
const kind = output.reasonCode === 'secret_file_protected' ? 'protected secret file' : 'protected git internals';
|
|
182
|
-
return `blocked: ${kind}${protectedPath}`;
|
|
183
|
-
}
|
|
184
|
-
const reason = typeof output.reasonCode === 'string' ? ` (${output.reasonCode})` : '';
|
|
185
|
-
return typeof output.error === 'string' ? `failed${reason}: ${compact(output.error)}` : `failed${reason}`;
|
|
186
|
-
}
|
|
187
|
-
return 'completed';
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* The short head of a shell command for the busy label: the program plus its
|
|
191
|
-
* first non-flag argument ("git diff", "npm test") — enough to identify the
|
|
192
|
-
* action without echoing the full (possibly long or sensitive) command line.
|
|
193
|
-
*/
|
|
194
|
-
function commandHead(command) {
|
|
195
|
-
const parts = command.trim().split(/\s+/);
|
|
196
|
-
const head = [parts[0]];
|
|
197
|
-
for (const part of parts.slice(1)) {
|
|
198
|
-
if (part.startsWith('-'))
|
|
199
|
-
continue;
|
|
200
|
-
head.push(part);
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
return compact(head.filter(Boolean).join(' '), 80);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* A short, human label for the live busy indicator while a tool is running,
|
|
207
|
-
* e.g. "Running npm test", "Reading src/foo.ts", "Searching".
|
|
208
|
-
* Lets the developer see *what* is happening, not just that something is.
|
|
209
|
-
*/
|
|
210
|
-
export function busyToolLabel(toolName, input) {
|
|
211
|
-
const data = input;
|
|
212
|
-
const pathLabel = typeof data?.path === 'string' ? compact(data.path, 80) : undefined;
|
|
213
|
-
switch (toolName) {
|
|
214
|
-
case 'shell':
|
|
215
|
-
if (data?.background === true)
|
|
216
|
-
return 'Starting background process';
|
|
217
|
-
return typeof data?.command === 'string' && data.command ? `Running ${commandHead(data.command)}` : 'Running command';
|
|
218
|
-
case 'process':
|
|
219
|
-
return 'Managing background process';
|
|
220
|
-
case 'grep':
|
|
221
|
-
return 'Searching';
|
|
222
|
-
case 'listFiles':
|
|
223
|
-
return 'Listing files';
|
|
224
|
-
case 'readFile':
|
|
225
|
-
return pathLabel ? `Reading ${pathLabel}` : 'Reading file';
|
|
226
|
-
case 'writeFile':
|
|
227
|
-
return pathLabel ? `Writing ${pathLabel}` : 'Writing file';
|
|
228
|
-
case 'editFile':
|
|
229
|
-
case 'replaceLines':
|
|
230
|
-
return pathLabel ? `Editing ${pathLabel}` : 'Editing file';
|
|
231
|
-
case 'fetch':
|
|
232
|
-
return 'Fetching URL';
|
|
233
|
-
case 'subagent':
|
|
234
|
-
return 'Running subagent';
|
|
235
|
-
case 'writeTasks':
|
|
236
|
-
return 'Updating tasks';
|
|
237
|
-
case 'graphQuery':
|
|
238
|
-
case 'graphExplain':
|
|
239
|
-
case 'graphPath':
|
|
240
|
-
case 'graphAffected':
|
|
241
|
-
return 'Querying code graph';
|
|
242
|
-
case 'graphRebuild':
|
|
243
|
-
return 'Building code graph';
|
|
244
|
-
case 'skill':
|
|
245
|
-
return 'Loading skill';
|
|
246
|
-
default:
|
|
247
|
-
if (toolName.startsWith('lsp'))
|
|
248
|
-
return 'Querying LSP';
|
|
249
|
-
if (toolName.startsWith('mcp'))
|
|
250
|
-
return 'Running MCP tool';
|
|
251
|
-
return `Running ${toolName}`;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
2
|
+
// The one-line tool call/result/busy-label builders live in `chat/toolSummaries.ts`
|
|
3
|
+
// (ARCH-03) and are re-exported here for the transcript formatters' callers.
|
|
4
|
+
export { busyToolLabel, compact, toolCallSummary, toolResultSummary } from '../chat/toolSummaries.js';
|
|
254
5
|
/** Compact transcript row for a user-attached image (F03); never dumps bytes. */
|
|
255
6
|
export function imageAttachmentLine(attachment) {
|
|
256
7
|
return `🖼 ${attachment.fileName} (${formatBytes(attachment.bytes)})`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configuredProviders, modelSelector, resolveModelSelector, upsertProvider } from '../../config/providers.js';
|
|
2
2
|
export async function handleModelCommand(value, ctx) {
|
|
3
3
|
if (value === '/model') {
|
|
4
4
|
ctx.setModelProviderFilter?.(undefined);
|
|
@@ -20,14 +20,18 @@ export async function handleModelCommand(value, ctx) {
|
|
|
20
20
|
return 'handled';
|
|
21
21
|
}
|
|
22
22
|
if (resolved.status === 'missing') {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// UX-10: a bare typo must not be silently registered and persisted — only
|
|
24
|
+
// an explicit `provider:model` selector registers a new model.
|
|
25
|
+
const colon = selector.indexOf(':');
|
|
26
|
+
const namedProvider = colon > 0 ? configuredProviders(ctx.settings).find(candidate => candidate.name === selector.slice(0, colon)) : undefined;
|
|
27
|
+
if (!namedProvider || colon === selector.length - 1) {
|
|
28
|
+
ctx.addSystemMessage(`Unknown model "${selector}". Pick one with /model, list all with /model list, or register a new one explicitly as /model provider:model.`);
|
|
26
29
|
return 'handled';
|
|
27
30
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
ctx.
|
|
31
|
+
const model = selector.slice(colon + 1);
|
|
32
|
+
const nextProvider = namedProvider.models.includes(model) ? namedProvider : { ...namedProvider, models: [...namedProvider.models, model] };
|
|
33
|
+
await ctx.updateSettings({ provider: namedProvider.name, model, providers: upsertProvider(ctx.settings, nextProvider) });
|
|
34
|
+
ctx.addSystemMessage(`Model set to ${model} on ${namedProvider.name}. Saved to ~/.haze/settings.json.`);
|
|
31
35
|
return 'handled';
|
|
32
36
|
}
|
|
33
37
|
await ctx.updateSettings({ provider: resolved.provider.name, model: resolved.model });
|
|
@@ -36,7 +36,7 @@ export function resolveReasoningCommand(args, input) {
|
|
|
36
36
|
if (!value)
|
|
37
37
|
return { action: 'open-picker' };
|
|
38
38
|
if (value === 'status') {
|
|
39
|
-
return { action: 'status', message: `Reasoning effort${scope}: ${describeChoice(input.current)}. Set with /reasoning <level> (this model, this session), /reasoning unset to send no reasoning parameter, or /reasoning reset to fall back to the saved/default level. Levels: ${LEVELS_LIST}.` };
|
|
39
|
+
return { action: 'status', message: `Reasoning effort${scope}: ${describeChoice(input.current)}. Set with /reasoning <level> (this model, this session), /reasoning unset to send no reasoning parameter, or /reasoning reset to fall back to the saved/default level. Levels: ${LEVELS_LIST} (off = none).` };
|
|
40
40
|
}
|
|
41
41
|
if (value === REASONING_RESET) {
|
|
42
42
|
const fallback = resolveReasoningChoice(undefined, input.stored);
|
|
@@ -69,7 +69,7 @@ export async function handleReasoningCommand(args, ctx) {
|
|
|
69
69
|
ctx.addSystemMessage(`No adjustable reasoning levels are known for ${selected.model}. Choose a supported model via /model or configure its reasoning levels; unset sends no parameter.`);
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
ctx.addSystemMessage('Choose a reasoning effort level for the active model, for this session. unset sends no reasoning parameter (provider default); reset falls back to the saved or default level.');
|
|
72
|
+
ctx.addSystemMessage('Choose a reasoning effort level for the active model, for this session. off = none; unset sends no reasoning parameter (provider default); reset falls back to the saved or default level.');
|
|
73
73
|
}
|
|
74
74
|
return 'handled';
|
|
75
75
|
}
|
|
@@ -89,7 +89,7 @@ export async function handleReasoningCommand(args, ctx) {
|
|
|
89
89
|
}
|
|
90
90
|
if (value === 'status') {
|
|
91
91
|
const applied = current.level && levels.includes(current.level) ? describeChoice(current) : 'provider default (no parameter sent)';
|
|
92
|
-
ctx.addSystemMessage(`Reasoning effort for ${modelSelector}: ${applied}. ${levels.length ? `Supported levels: ${levels.join(', ')}.` : support === 'unknown' ? 'Reasoning support is unknown for this model.' : 'Reasoning effort is unsupported for this model.'}`);
|
|
92
|
+
ctx.addSystemMessage(`Reasoning effort for ${modelSelector}: ${applied}. ${levels.length ? `Supported levels: ${levels.join(', ')} (off = none); unset sends no parameter (provider default).` : support === 'unknown' ? 'Reasoning support is unknown for this model.' : 'Reasoning effort is unsupported for this model.'}`);
|
|
93
93
|
return 'handled';
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -13,6 +13,7 @@ import { FALLBACK_CONTEXT_WINDOW_TOKENS } from '../../core/agent/contextBudget.j
|
|
|
13
13
|
import { teardownBackgroundProcesses } from '../../core/process/backgroundRegistry.js';
|
|
14
14
|
import { MAX_TURN_DEADLINE_MS } from '../../core/agent/budgets.js';
|
|
15
15
|
import { NdjsonSink, queueNdjsonWrite } from './ndjsonSink.js';
|
|
16
|
+
import { stripTerminalControlSequences } from '../../ui/terminalSanitize.js';
|
|
16
17
|
function pinnedUsage(usage) {
|
|
17
18
|
// Normalize every field to a number: TokenUsage seeds most fields to 0 but
|
|
18
19
|
// inputTokens/outputTokens may be undefined until the first report. A uniform ?? 0
|
|
@@ -388,10 +389,13 @@ export async function runHeadless(options) {
|
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
391
|
else if (status === 'complete') {
|
|
391
|
-
|
|
392
|
+
// The model answer can quote control sequences from fetched pages or tool
|
|
393
|
+
// output; never let them reach the terminal (JSON modes escape them).
|
|
394
|
+
const text = stripTerminalControlSequences(result);
|
|
395
|
+
process.stdout.write(text + (text.endsWith('\n') ? '' : '\n'));
|
|
392
396
|
}
|
|
393
397
|
else {
|
|
394
|
-
process.stderr.write(`${result || `Turn ${status}.`}\n`);
|
|
398
|
+
process.stderr.write(`${stripTerminalControlSequences(result) || `Turn ${status}.`}\n`);
|
|
395
399
|
}
|
|
396
400
|
return status === 'complete' ? 0 : 1;
|
|
397
401
|
}
|
|
@@ -58,6 +58,7 @@ export function createQuarantinableCallbacks(callbacks) {
|
|
|
58
58
|
compactConversation: callbacks.compactConversation && whileLiveBoolean(callbacks.compactConversation),
|
|
59
59
|
recordCompaction: callbacks.recordCompaction && whileLive(callbacks.recordCompaction),
|
|
60
60
|
recordTokenUsage: callbacks.recordTokenUsage && whileLive(callbacks.recordTokenUsage),
|
|
61
|
+
recordContextUsage: callbacks.recordContextUsage && whileLive(callbacks.recordContextUsage),
|
|
61
62
|
setWorkState: callbacks.setWorkState && whileLive(callbacks.setWorkState),
|
|
62
63
|
onTasksChanged: callbacks.onTasksChanged && whileLive(callbacks.onTasksChanged),
|
|
63
64
|
get log() {
|
|
@@ -3,7 +3,7 @@ import { agentEvent } from '../../../core/agent/events.js';
|
|
|
3
3
|
import { isContextOverflowError, isRetryableModelError } from '../../../core/agent/errors.js';
|
|
4
4
|
import { completionRescuePrompt, goalContinuationPrompt, lengthContinuationPrompt } from '../../../core/agent/goalPolicy.js';
|
|
5
5
|
import { clampSlice, DEFAULT_MODEL_RETRIES, DEFAULT_RETRY_BASE_DELAY_MS, MAX_OVERFLOW_RETRIES, OVERFLOW_SHRINK_FACTOR, remainingSteps, remainingToolCalls, IDLE_TIMEOUT_MS } from '../../../core/agent/budgets.js';
|
|
6
|
-
import { checkKindsOfIds, deriveValidationOutcome, redPairStatus, unresolvedFailedCheckIds } from '../../../core/agent/workState.js';
|
|
6
|
+
import { checkKindsOfIds, deriveValidationOutcome, openFailedCheckCommands, redPairStatus, unresolvedFailedCheckIds } from '../../../core/agent/workState.js';
|
|
7
7
|
import { withoutRejectedAssistantFinal } from '../../../core/agent/requestAssembly.js';
|
|
8
8
|
import { buildIncompleteGoalResume, taskCountsOf } from './goalCheckpoint.js';
|
|
9
9
|
import { formatSeconds } from '../../../utils/format.js';
|
|
@@ -147,7 +147,12 @@ export function finalizeAttemptOutcome(deps) {
|
|
|
147
147
|
discardRejectedFinal();
|
|
148
148
|
if (readiness === 'validation_failed' || readiness === 'validation_stale' || readiness === 'validation_absent_after_mutation')
|
|
149
149
|
turnState.validationContinuationUsed = true;
|
|
150
|
-
|
|
150
|
+
const openChecks = openFailedCheckCommands(goal);
|
|
151
|
+
const openCheckDetail = readiness === 'validation_failed' && openChecks.length
|
|
152
|
+
? `Failed checks still open: ${openChecks.map(command => `\`${command}\``).join('; ')}.`
|
|
153
|
+
: undefined;
|
|
154
|
+
const validationDetail = [openCheckDetail, turnState.redPair === 'missing' ? 'The captured pre-edit failing check still needs the same validation command to pass after the fix.' : undefined].filter(Boolean).join(' ') || undefined;
|
|
155
|
+
return { status: turnStatus, recovery: { kind: 'goal', control: goalContinuationPrompt(describeCompletionReadiness(readiness, turnState.taskProgress, checkKindsOfIds(unresolvedFailedCheckIds(goal))), taskCountsOf(turnState.taskProgress), validationDetail), slice: { maxSteps: goalSlice.steps, maxToolCalls: goalSlice.toolCalls } } };
|
|
151
156
|
}
|
|
152
157
|
else if (rescueSlice && rescueSlice.steps > 0) {
|
|
153
158
|
return { status: turnStatus, recovery: { kind: 'rescue', control: completionRescuePrompt(), slice: { maxSteps: rescueSlice.steps, maxToolCalls: rescueSlice.toolCalls } } };
|
|
@@ -37,6 +37,7 @@ export interface AttemptSetup {
|
|
|
37
37
|
omitMaxOutputTokens: boolean | undefined;
|
|
38
38
|
/** Tools visible to this attempt: rescue-restricted, budget-clamped, and deadline-wrapped. */
|
|
39
39
|
sliceTools: ToolSet;
|
|
40
|
+
activateToolGroups?: () => boolean;
|
|
40
41
|
stepCap: number;
|
|
41
42
|
/** A rescue slice with no qualifying tools must synthesize, never reopen discovery (F-08). */
|
|
42
43
|
rescueWithoutTools: boolean;
|
|
@@ -6,6 +6,7 @@ import { projectPreflight } from '../../../core/agent/projectPreflight.js';
|
|
|
6
6
|
import { formatGoalStatus } from '../../../core/agent/goalPolicy.js';
|
|
7
7
|
import { calculateRequestTokenBudget, estimateConversationTokens } from '../../../core/agent/contextBudget.js';
|
|
8
8
|
import { stripSyntheticControls, withSyntheticControl, withoutSystemMessages } from '../../../core/agent/requestAssembly.js';
|
|
9
|
+
import { foldUserCommandRecords } from '../../../core/agent/userCommands.js';
|
|
9
10
|
import { compactModelMessages } from '../../../core/agent/compaction.js';
|
|
10
11
|
import { withToolDeadline } from '../../../core/deadline.js';
|
|
11
12
|
import { isMutatingCapability, isValidationCapable } from '../../../core/agent/toolCapabilities.js';
|
|
@@ -13,6 +14,7 @@ import { userTurnMessage } from '../../../core/attachments/imageAttachments.js';
|
|
|
13
14
|
import { WorkspaceMutationPolicy } from '../../../core/subagent/workspaceMutationPolicy.js';
|
|
14
15
|
import { modelWithConfig, providerRequestSettings, isLocalProviderUrl } from '../../../llm/client.js';
|
|
15
16
|
import { assembleRequestContext } from '../../../llm/requestContext.js';
|
|
17
|
+
import { toolsInLoadedGroups } from '../../../llm/toolGroups.js';
|
|
16
18
|
import { modelThinkingLabel } from '../../../utils/modelName.js';
|
|
17
19
|
import { estimateInputBreakdown, logEntry } from './turnRuntime.js';
|
|
18
20
|
/**
|
|
@@ -102,10 +104,12 @@ export async function prepareAttempt(deps) {
|
|
|
102
104
|
// to rewrite older successful calls/results here, invalidating provider
|
|
103
105
|
// prompt-cache prefixes before the context budget required compaction.
|
|
104
106
|
// Durable session snapshots preserve this history; only model-aware
|
|
105
|
-
// compaction or an explicit provider transition may rewrite it.
|
|
107
|
+
// compaction or an explicit provider transition may rewrite it. Records of
|
|
108
|
+
// commands the user ran with `!` fold into the new user turn (one user
|
|
109
|
+
// message per turn for providers that require alternation).
|
|
106
110
|
const durableRequestMessages = retryingExistingRequest
|
|
107
111
|
? stripSyntheticControls(callbacks.getConversation())
|
|
108
|
-
:
|
|
112
|
+
: foldUserCommandRecords(stripSyntheticControls(callbacks.getConversation()), userTurnMessage(value, turnOptions.attachments ?? []));
|
|
109
113
|
// Model-aware request budget (RH-005): message allowance is the context
|
|
110
114
|
// window minus system prompt, tool schemas, output reserve, and a safety
|
|
111
115
|
// margin — not a fixed 40K constant. Small contexts get a safe budget; the
|
|
@@ -182,6 +186,25 @@ export async function prepareAttempt(deps) {
|
|
|
182
186
|
const deadlineMs = name === 'subagent' ? SUBAGENT_TOOL_DEADLINE_MS : DEFAULT_TOOL_DEADLINE_MS;
|
|
183
187
|
return [name, { ...definition, execute: (...args) => withToolDeadline(() => execute(...args), deadlineMs, abortController.signal) }];
|
|
184
188
|
}));
|
|
189
|
+
const activateToolGroups = () => {
|
|
190
|
+
if (recoverySlice?.kind === 'rescue' || !assembled.deferredTools)
|
|
191
|
+
return false;
|
|
192
|
+
const candidates = toolsInLoadedGroups(assembled.deferredTools, assembled.executionScope.loadedToolGroups ?? new Set());
|
|
193
|
+
const added = Object.fromEntries(Object.entries(candidates).filter(([name]) => !(name in deadlineWrappedTools)));
|
|
194
|
+
if (Object.keys(added).length === 0)
|
|
195
|
+
return false;
|
|
196
|
+
const budgeted = withToolExecutionBudget(added, { state: globalBudget, limit: turnBudget.toolCallLimit }, { state: sliceBudget, limit: sliceToolCallCap });
|
|
197
|
+
for (const [name, definition] of Object.entries(budgeted)) {
|
|
198
|
+
const execute = definition.execute;
|
|
199
|
+
deadlineWrappedTools[name] = typeof definition.execute !== 'function' ? definition : { ...definition, execute: (...args) => withToolDeadline(() => execute(...args), DEFAULT_TOOL_DEADLINE_MS, abortController.signal) };
|
|
200
|
+
toolCategories.set(name, name.startsWith('lsp') ? 'lsp' : 'builtin');
|
|
201
|
+
}
|
|
202
|
+
Object.assign(requestBudget, calculateRequestTokenBudget({ contextWindowTokens: runtime.config.contextWindowTokens, requestedOutputTokens, system: systemPrompt, tools: deadlineWrappedTools }));
|
|
203
|
+
Object.assign(inputBreakdown, estimateInputBreakdown({ system: systemPrompt, contextFiles: activeContextFiles, messages: requestMessages, tools: deadlineWrappedTools }));
|
|
204
|
+
usageAnchor.current = undefined;
|
|
205
|
+
callbacks.debugLog(`Loaded tool groups: ${Object.keys(added).join(', ')}`);
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
185
208
|
return {
|
|
186
209
|
runtime,
|
|
187
210
|
thinkingLabel,
|
|
@@ -192,6 +215,7 @@ export async function prepareAttempt(deps) {
|
|
|
192
215
|
providerSettings,
|
|
193
216
|
omitMaxOutputTokens,
|
|
194
217
|
sliceTools: deadlineWrappedTools,
|
|
218
|
+
activateToolGroups,
|
|
195
219
|
stepCap,
|
|
196
220
|
rescueWithoutTools,
|
|
197
221
|
toolExecutionContext,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompletionReadiness, TurnExecutionState } from '../../../core/agent/completionController.js';
|
|
2
2
|
import type { RequestIntent } from '../../../core/agent/goalPolicy.js';
|
|
3
3
|
import type { RedEvidence, ValidationOutcome, WorkTaskProgress } from '../../../core/agent/workState.js';
|
|
4
|
-
import type { ValidationKind } from '../../../
|
|
4
|
+
import type { ValidationKind } from '../../../core/toolResultTypes.js';
|
|
5
5
|
import type { GoalLedgerFrontier } from '../../../core/session/sessionStore.js';
|
|
6
6
|
/**
|
|
7
7
|
* Bounded continuation checkpoint for a logical goal whose work is recoverably
|