@denizokcu/haze 0.5.0 → 0.7.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 +36 -1
- package/README.md +101 -24
- package/dist/cli/chat/TaskBar.d.ts +9 -0
- package/dist/cli/chat/TaskBar.js +40 -0
- package/dist/cli/chat/chatMetrics.d.ts +11 -0
- package/dist/cli/chat/chatMetrics.js +50 -0
- package/dist/cli/chat/inputSuggestions.d.ts +16 -0
- package/dist/cli/chat/inputSuggestions.js +55 -0
- package/dist/cli/chat/messages.d.ts +9 -0
- package/dist/cli/chat/messages.js +76 -0
- package/dist/cli/chat/sessionRecorder.d.ts +12 -0
- package/dist/cli/chat/sessionRecorder.js +21 -0
- package/dist/cli/chat/startupInfo.d.ts +4 -0
- package/dist/cli/chat/startupInfo.js +53 -0
- package/dist/cli/chat/turnState.d.ts +5 -0
- package/dist/cli/chat/turnState.js +20 -0
- package/dist/cli/commands/chat.d.ts +0 -1
- package/dist/cli/commands/chat.js +519 -495
- package/dist/cli/commands/chatModes.d.ts +8 -0
- package/dist/cli/commands/chatModes.js +44 -0
- package/dist/cli/commands/commandHelp.d.ts +6 -0
- package/dist/cli/commands/commandHelp.js +25 -0
- package/dist/cli/commands/commands.d.ts +3 -2
- package/dist/cli/commands/commands.js +55 -320
- package/dist/cli/commands/formatters.d.ts +27 -0
- package/dist/cli/commands/formatters.js +149 -4
- package/dist/cli/commands/initCommand.d.ts +2 -0
- package/dist/cli/commands/initCommand.js +19 -0
- package/dist/cli/commands/logsCommand.d.ts +2 -0
- package/dist/cli/commands/logsCommand.js +63 -0
- package/dist/cli/commands/lspWizard.d.ts +14 -0
- package/dist/cli/commands/lspWizard.js +44 -0
- package/dist/cli/commands/mcpWizard.d.ts +15 -0
- package/dist/cli/commands/mcpWizard.js +69 -0
- package/dist/cli/commands/modelCommand.d.ts +2 -0
- package/dist/cli/commands/modelCommand.js +36 -0
- package/dist/cli/commands/providerWizard.d.ts +30 -0
- package/dist/cli/commands/providerWizard.js +114 -0
- package/dist/cli/commands/runCommand.d.ts +16 -0
- package/dist/cli/commands/runCommand.js +170 -0
- package/dist/cli/commands/settingsSummary.d.ts +3 -0
- package/dist/cli/commands/settingsSummary.js +40 -0
- package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
- package/dist/cli/commands/skillConfirmRemove.js +19 -0
- package/dist/cli/commands/skillCreation.d.ts +12 -0
- package/dist/cli/commands/skillCreation.js +14 -0
- package/dist/cli/commands/skillWizard.d.ts +15 -0
- package/dist/cli/commands/skillWizard.js +38 -0
- package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
- package/dist/cli/commands/streaming/assistantText.js +115 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
- package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
- package/dist/cli/commands/streaming/toolResultState.js +25 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
- package/dist/cli/commands/streaming/turnRuntime.js +86 -0
- package/dist/cli/commands/streaming.d.ts +10 -29
- package/dist/cli/commands/streaming.js +249 -911
- package/dist/cli/commands/wizardActions.d.ts +40 -0
- package/dist/cli/commands/wizardActions.js +40 -0
- package/dist/cli/commands/wizardInput.d.ts +4 -0
- package/dist/cli/commands/wizardInput.js +19 -0
- package/dist/cli/commands/wizardPrompts.d.ts +22 -0
- package/dist/cli/commands/wizardPrompts.js +52 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
- package/dist/cli/commands/wizardSuggestions.js +139 -0
- package/dist/cli/index.js +62 -4
- package/dist/config/contextFiles.d.ts +8 -1
- package/dist/config/contextFiles.js +25 -12
- package/dist/config/lspSettings.d.ts +16 -0
- package/dist/config/lspSettings.js +95 -0
- package/dist/config/mcpSettings.d.ts +24 -0
- package/dist/config/mcpSettings.js +100 -0
- package/dist/config/providers.js +4 -4
- package/dist/config/settings.d.ts +34 -0
- package/dist/config/skillSettings.d.ts +15 -0
- package/dist/config/skillSettings.js +32 -0
- package/dist/config/updateCheck.d.ts +44 -0
- package/dist/config/updateCheck.js +83 -0
- package/dist/core/agent/budgets.d.ts +6 -0
- package/dist/core/agent/budgets.js +6 -0
- package/dist/core/agent/compaction.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +0 -7
- package/dist/core/agent/requestAssembly.js +27 -5
- package/dist/core/agent/toolOutputStore.js +5 -4
- package/dist/core/agent/toolResults.d.ts +31 -0
- package/dist/core/agent/toolResults.js +42 -0
- package/dist/core/agent/turnPolicy.d.ts +8 -0
- package/dist/core/agent/turnPolicy.js +23 -0
- package/dist/core/agent/workState.d.ts +18 -5
- package/dist/core/agent/workState.js +39 -20
- package/dist/core/bashOutput/reducers/content.d.ts +1 -0
- package/dist/core/bashOutput/reducers/content.js +1 -1
- package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
- package/dist/core/bashOutput/reducers/gh.js +77 -0
- package/dist/core/bashOutput/registry.js +8 -0
- package/dist/core/goal/sessionGoal.d.ts +6 -30
- package/dist/core/goal/sessionGoal.js +3 -68
- package/dist/core/safety/bashClassifier.js +30 -0
- package/dist/core/safety/urlGuard.d.ts +1 -0
- package/dist/core/safety/urlGuard.js +6 -1
- package/dist/core/session/sessionSlimming.d.ts +5 -0
- package/dist/core/session/sessionSlimming.js +78 -0
- package/dist/core/session/sessionStore.d.ts +23 -3
- package/dist/core/session/sessionStore.js +30 -10
- package/dist/core/subagent/subagentRunner.d.ts +11 -1
- package/dist/core/subagent/subagentRunner.js +1 -0
- package/dist/llm/capabilities.d.ts +12 -0
- package/dist/llm/capabilities.js +10 -0
- package/dist/llm/client.d.ts +1 -0
- package/dist/llm/client.js +11 -2
- package/dist/llm/hazeTools.d.ts +31 -32
- package/dist/llm/hazeTools.js +40 -567
- package/dist/llm/lsp.d.ts +109 -0
- package/dist/llm/lsp.js +241 -0
- package/dist/llm/lspTools.d.ts +104 -0
- package/dist/llm/lspTools.js +115 -0
- package/dist/llm/mcp.d.ts +19 -0
- package/dist/llm/mcp.js +73 -0
- package/dist/llm/requestContext.d.ts +28 -0
- package/dist/llm/requestContext.js +41 -0
- package/dist/llm/systemPrompt.d.ts +5 -1
- package/dist/llm/systemPrompt.js +9 -3
- package/dist/llm/tools/bashTool.d.ts +5 -0
- package/dist/llm/tools/bashTool.js +81 -0
- package/dist/llm/tools/editMatch.d.ts +55 -0
- package/dist/llm/tools/editMatch.js +99 -0
- package/dist/llm/tools/failures.d.ts +36 -0
- package/dist/llm/tools/failures.js +38 -0
- package/dist/llm/tools/fetchTool.d.ts +65 -0
- package/dist/llm/tools/fetchTool.js +45 -0
- package/dist/llm/tools/fileToolShared.d.ts +10 -0
- package/dist/llm/tools/fileToolShared.js +43 -0
- package/dist/llm/tools/grepParse.d.ts +13 -0
- package/dist/llm/tools/grepParse.js +67 -0
- package/dist/llm/tools/outputCap.d.ts +53 -0
- package/dist/llm/tools/outputCap.js +67 -0
- package/dist/llm/tools/storedOutputTool.d.ts +10 -0
- package/dist/llm/tools/storedOutputTool.js +17 -0
- package/dist/llm/tools/taskTool.d.ts +28 -0
- package/dist/llm/tools/taskTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +69 -0
- package/dist/llm/tools/toolContext.js +187 -0
- package/dist/llm/tools/workspaceFile.d.ts +33 -0
- package/dist/llm/tools/workspaceFile.js +27 -0
- package/dist/llm/webFetch.d.ts +13 -1
- package/dist/llm/webFetch.js +91 -7
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +24 -45
- package/dist/ui/components/TextInput.d.ts +1 -1
- package/dist/ui/components/TextInput.js +1 -99
- package/dist/ui/inputBuffer.d.ts +28 -0
- package/dist/ui/inputBuffer.js +99 -0
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/collections.js +9 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +40 -0
- package/dist/utils/version.d.ts +20 -0
- package/dist/utils/version.js +72 -0
- package/package.json +2 -2
- package/dist/cli/commands/skills.d.ts +0 -4
- package/dist/cli/commands/skills.js +0 -38
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { readContextFiles } from '../../config/contextFiles.js';
|
|
2
|
+
import { runAgentTurn } from './streaming.js';
|
|
3
|
+
import { EMPTY_TOKEN_USAGE, accumulateTokenUsage } from '../chat/turnState.js';
|
|
4
|
+
import { readSettings } from '../../config/settings.js';
|
|
5
|
+
import { activeModel, modelSelector, resolveModelSelector } from '../../config/providers.js';
|
|
6
|
+
import { createLog, endLog } from '../../core/log/llmLog.js';
|
|
7
|
+
function debug(line) {
|
|
8
|
+
if (process.env.HAZE_DEBUG)
|
|
9
|
+
process.stderr.write(`[haze] ${line}\n`);
|
|
10
|
+
}
|
|
11
|
+
function pinnedUsage(usage) {
|
|
12
|
+
// Normalize every field to a number: TokenUsage seeds most fields to 0 but
|
|
13
|
+
// inputTokens/outputTokens may be undefined until the first report. A uniform ?? 0
|
|
14
|
+
// keeps the documented CI contract literal (all five fields always present).
|
|
15
|
+
return {
|
|
16
|
+
inputTokens: usage.inputTokens ?? 0,
|
|
17
|
+
outputTokens: usage.outputTokens ?? 0,
|
|
18
|
+
cacheReadTokens: usage.cacheReadTokens ?? 0,
|
|
19
|
+
cacheWriteTokens: usage.cacheWriteTokens ?? 0,
|
|
20
|
+
reasoningTokens: usage.reasoningTokens ?? 0,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function errorText(error) {
|
|
24
|
+
return error instanceof Error ? error.message : String(error);
|
|
25
|
+
}
|
|
26
|
+
function toHeadlessStreamEvent(event) {
|
|
27
|
+
switch (event.type) {
|
|
28
|
+
case 'turn_start':
|
|
29
|
+
return { type: 'turn_start', request: event.request, at: event.at };
|
|
30
|
+
case 'turn_end':
|
|
31
|
+
return { type: 'turn_end', request: event.request, status: event.status, at: event.at };
|
|
32
|
+
case 'message_start':
|
|
33
|
+
return { type: 'message_start', id: event.id, role: event.role, at: event.at };
|
|
34
|
+
case 'message_update':
|
|
35
|
+
return { type: 'message_update', id: event.id, text: event.text, at: event.at };
|
|
36
|
+
case 'message_end':
|
|
37
|
+
return { ...(event.hidden === undefined ? {} : { hidden: event.hidden }), type: 'message_end', id: event.id, text: event.text, at: event.at };
|
|
38
|
+
case 'tool_start':
|
|
39
|
+
// Intentionally omit raw tool input: stdout is often persisted by harnesses/CI.
|
|
40
|
+
return { type: 'tool_start', id: event.id, name: event.name, at: event.at };
|
|
41
|
+
case 'tool_end':
|
|
42
|
+
return { type: 'tool_end', id: event.id, name: event.name, success: event.success, durationMs: event.durationMs, ...(event.error === undefined ? {} : { error: errorText(event.error) }), at: event.at };
|
|
43
|
+
case 'retry':
|
|
44
|
+
return { type: 'retry', attempt: event.attempt, maxAttempts: event.maxAttempts, delayMs: event.delayMs, error: event.error, at: event.at };
|
|
45
|
+
case 'context_overflow':
|
|
46
|
+
return { type: 'context_overflow', recovered: event.recovered, error: event.error, at: event.at };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeNdjson(value) {
|
|
50
|
+
process.stdout.write(`${JSON.stringify(value)}\n`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the model the run will use *before* invoking the agent, so a bad `--model`
|
|
54
|
+
* selector or a missing provider produces a precise error (not the generic no-provider
|
|
55
|
+
* message) with a non-zero exit. Returns an error string when the run cannot proceed.
|
|
56
|
+
*/
|
|
57
|
+
async function resolveModelOrError(modelOverride) {
|
|
58
|
+
const settings = await readSettings();
|
|
59
|
+
const override = modelOverride?.trim();
|
|
60
|
+
if (override) {
|
|
61
|
+
const resolved = resolveModelSelector(settings, override);
|
|
62
|
+
if (resolved.status === 'ambiguous') {
|
|
63
|
+
return `Model ${resolved.model} exists on multiple providers: ${resolved.providers.map((provider) => modelSelector(provider, resolved.model)).join(', ')}`;
|
|
64
|
+
}
|
|
65
|
+
if (resolved.status === 'missing') {
|
|
66
|
+
return `No configured model named ${override}. Run /provider, select a provider, then add models.`;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
if (!activeModel(settings)) {
|
|
71
|
+
return 'No model provider configured. Run /provider to choose or add a provider.';
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
export async function runHeadless(options) {
|
|
76
|
+
const modelError = await resolveModelOrError(options.modelOverride);
|
|
77
|
+
if (modelError) {
|
|
78
|
+
process.stderr.write(`${modelError}\n`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
const contextFiles = await readContextFiles(process.cwd());
|
|
82
|
+
const session = { start: new Date(), cwd: process.cwd() };
|
|
83
|
+
let conversation = [];
|
|
84
|
+
// Assistant text is delivered in two stages by runAgentTurn: an initial streaming
|
|
85
|
+
// `addMessage`, then a finalizing `updateMessage` with the complete text. We key
|
|
86
|
+
// segments by id and patch them on update so finalized (and multi-segment) text is captured.
|
|
87
|
+
const segments = [];
|
|
88
|
+
let lastAssistantText = '';
|
|
89
|
+
let usage = { ...EMPTY_TOKEN_USAGE };
|
|
90
|
+
let log;
|
|
91
|
+
if (options.debug)
|
|
92
|
+
log = await createLog();
|
|
93
|
+
let emittedTurnStart = false;
|
|
94
|
+
const emitStreamEvent = options.output === 'stream-json'
|
|
95
|
+
? (event) => {
|
|
96
|
+
// runAgentTurn emits nested turn_start/turn_end pairs for retries; expose one clean
|
|
97
|
+
// headless turn and emit the authoritative turn_end after the run settles.
|
|
98
|
+
if (event.type === 'turn_start') {
|
|
99
|
+
if (emittedTurnStart)
|
|
100
|
+
return;
|
|
101
|
+
emittedTurnStart = true;
|
|
102
|
+
}
|
|
103
|
+
else if (event.type === 'turn_end') {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const headlessEvent = toHeadlessStreamEvent(event);
|
|
107
|
+
if (headlessEvent)
|
|
108
|
+
writeNdjson(headlessEvent);
|
|
109
|
+
}
|
|
110
|
+
: undefined;
|
|
111
|
+
const callbacks = {
|
|
112
|
+
addMessage: (msg) => {
|
|
113
|
+
if (msg.role === 'assistant')
|
|
114
|
+
segments.push({ id: msg.id, text: msg.text, hidden: msg.hidden });
|
|
115
|
+
},
|
|
116
|
+
updateMessage: (id, update) => {
|
|
117
|
+
const segment = segments.find((s) => s.id === id);
|
|
118
|
+
if (!segment)
|
|
119
|
+
return;
|
|
120
|
+
if (update.text !== undefined)
|
|
121
|
+
segment.text = update.text;
|
|
122
|
+
if (update.hidden !== undefined)
|
|
123
|
+
segment.hidden = update.hidden;
|
|
124
|
+
},
|
|
125
|
+
setConversation: (msgs) => {
|
|
126
|
+
conversation = msgs;
|
|
127
|
+
},
|
|
128
|
+
setBusy: () => undefined,
|
|
129
|
+
setBusyLabel: () => undefined,
|
|
130
|
+
debugLog: debug,
|
|
131
|
+
getConversation: () => conversation,
|
|
132
|
+
getLastAssistantText: () => lastAssistantText,
|
|
133
|
+
setLastAssistantText: (text) => {
|
|
134
|
+
lastAssistantText = text;
|
|
135
|
+
},
|
|
136
|
+
recordTokenUsage: (u) => {
|
|
137
|
+
usage = accumulateTokenUsage(usage, u);
|
|
138
|
+
},
|
|
139
|
+
onEvent: emitStreamEvent,
|
|
140
|
+
log,
|
|
141
|
+
};
|
|
142
|
+
let status;
|
|
143
|
+
let result;
|
|
144
|
+
try {
|
|
145
|
+
({ status } = await runAgentTurn(options.prompt, options.prompt, contextFiles, callbacks, 0, false, false, session, options.modelOverride));
|
|
146
|
+
result = segments.filter((s) => !s.hidden && s.text).map((s) => s.text).join('\n');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
status = 'failed';
|
|
150
|
+
result = error instanceof Error ? error.message : String(error);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (log)
|
|
154
|
+
await endLog(log).catch(() => undefined);
|
|
155
|
+
}
|
|
156
|
+
if (options.output === 'json' || options.output === 'stream-json') {
|
|
157
|
+
if (options.output === 'stream-json')
|
|
158
|
+
writeNdjson({ type: 'turn_end', request: options.prompt, status, at: new Date().toISOString() });
|
|
159
|
+
// For stream-json the agent events have already streamed above; this is the terminal line.
|
|
160
|
+
// It is byte-identical to the --output json envelope, so harnesses can parse the last line the same way.
|
|
161
|
+
writeNdjson({ type: 'result', status, result, usage: pinnedUsage(usage) });
|
|
162
|
+
}
|
|
163
|
+
else if (status === 'complete') {
|
|
164
|
+
process.stdout.write(result + (result.endsWith('\n') ? '' : '\n'));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
process.stderr.write(`${result || `Turn ${status}.`}\n`);
|
|
168
|
+
}
|
|
169
|
+
return status === 'complete' ? 0 : 1;
|
|
170
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { contextFileDiagnostics, summarizeContextDiagnostics } from '../../config/contextFiles.js';
|
|
2
|
+
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
3
|
+
import { configuredMcpServers } from '../../config/mcpSettings.js';
|
|
4
|
+
import { activeProvider as resolveActiveProvider, configuredProviders, providerHasKey } from '../../config/providers.js';
|
|
5
|
+
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
6
|
+
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
7
|
+
export async function formatSettingsSummary(settings, contextFiles) {
|
|
8
|
+
const providers = configuredProviders(settings);
|
|
9
|
+
const activeProvider = resolveActiveProvider(settings);
|
|
10
|
+
const contextDiagnostics = contextFileDiagnostics(contextFiles);
|
|
11
|
+
const contextTokens = contextDiagnostics.reduce((sum, file) => sum + file.estimatedTokens, 0);
|
|
12
|
+
const summary = summarizeContextDiagnostics(contextFiles);
|
|
13
|
+
const notes = [];
|
|
14
|
+
if (summary.exceedsBudget === true && summary.windowSize) {
|
|
15
|
+
const sharePct = Math.round((summary.budgetShare ?? 0) * 100);
|
|
16
|
+
const thresholdPct = Math.round(summary.budgetThreshold * 100);
|
|
17
|
+
notes.push(`project context exceeds ${thresholdPct}% budget (${sharePct}% of ${Math.round(summary.windowSize / 1000)}k window)`);
|
|
18
|
+
}
|
|
19
|
+
if (summary.duplicateGroups.length > 0) {
|
|
20
|
+
const duplicateTotal = summary.duplicateFileCount;
|
|
21
|
+
notes.push(`${summary.duplicateGroups.length} duplicate group${summary.duplicateGroups.length === 1 ? '' : 's'} (${duplicateTotal} file${duplicateTotal === 1 ? '' : 's'} with identical content)`);
|
|
22
|
+
}
|
|
23
|
+
const lspServers = configuredLspServers(settings);
|
|
24
|
+
const installedSkills = [...(await loadSkillRegistry()).skills.values()];
|
|
25
|
+
const skillNames = installedSkills.map(skill => `${skill.name}${isSkillEnabled(settings, skill.name) ? '' : ' (disabled)'}`).join(', ');
|
|
26
|
+
const lines = [
|
|
27
|
+
`Provider: ${activeProvider?.name ?? 'not configured'}`,
|
|
28
|
+
`Model: ${settings.model ?? 'not set'}`,
|
|
29
|
+
`Base URL: ${activeProvider?.url ?? settings.baseURL ?? 'not configured'}`,
|
|
30
|
+
`API key: ${activeProvider && providerHasKey(settings, activeProvider) ? 'saved' : 'missing'}`,
|
|
31
|
+
`Configured providers: ${providers.map(provider => provider.name).join(', ') || 'none'}`,
|
|
32
|
+
`LSP servers: ${lspServers.map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
33
|
+
`MCP servers: ${configuredMcpServers(settings).map(server => `${server.name}${server.enabled === false ? ' (disabled)' : ''}`).join(', ') || 'none'}`,
|
|
34
|
+
`Skills: ${skillNames || 'none'}`,
|
|
35
|
+
`Context files: ${contextFiles.length ? `${contextFiles.map(file => file.path).join(', ')} (~${contextTokens} tokens)` : 'none'}`,
|
|
36
|
+
];
|
|
37
|
+
if (notes.length > 0)
|
|
38
|
+
lines.push(`Context note: ${notes.join('; ')}`);
|
|
39
|
+
return lines.join(' | ');
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { LoadedSkill } from '../../skills/types.js';
|
|
3
|
+
export type SkillConfirmRemoveResult = {
|
|
4
|
+
message?: string;
|
|
5
|
+
mode?: 'chat';
|
|
6
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
7
|
+
removedDir?: string;
|
|
8
|
+
selectedName?: string;
|
|
9
|
+
skill?: LoadedSkill;
|
|
10
|
+
};
|
|
11
|
+
export declare function skillConfirmRemoveResult(settings: HazeSettings, skills: LoadedSkill[], selectedName: string | undefined, value: string): SkillConfirmRemoveResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { removeSkillSetting } from '../../config/skillSettings.js';
|
|
2
|
+
import { isYesConfirmation } from './wizardInput.js';
|
|
3
|
+
export function skillConfirmRemoveResult(settings, skills, selectedName, value) {
|
|
4
|
+
if (!selectedName)
|
|
5
|
+
return { mode: 'chat' };
|
|
6
|
+
if (!isYesConfirmation(value))
|
|
7
|
+
return { mode: 'chat', selectedName: undefined, message: 'Cancelled. Skill not removed.' };
|
|
8
|
+
const skill = skills.find(candidate => candidate.name === selectedName);
|
|
9
|
+
if (!skill)
|
|
10
|
+
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
11
|
+
return {
|
|
12
|
+
mode: 'chat',
|
|
13
|
+
selectedName: undefined,
|
|
14
|
+
skill,
|
|
15
|
+
removedDir: skill.dir,
|
|
16
|
+
settingsPatch: { skills: removeSkillSetting(settings, selectedName) },
|
|
17
|
+
message: `Removed skill ${selectedName}.`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type SkillCreationResult = {
|
|
2
|
+
busy?: boolean;
|
|
3
|
+
busyLabel?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
draftName?: string;
|
|
7
|
+
mode?: 'chat';
|
|
8
|
+
clearDraft?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function captureSkillDescription(value: string, draftName: string | undefined): SkillCreationResult;
|
|
11
|
+
export declare function skillCreationMessage(name: string, file: string): string;
|
|
12
|
+
export declare function skillCreationFailure(error: unknown): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function captureSkillDescription(value, draftName) {
|
|
2
|
+
const description = value.trim();
|
|
3
|
+
if (!description)
|
|
4
|
+
return { message: 'Description is required. Try again, or press ESC to cancel.' };
|
|
5
|
+
if (!draftName)
|
|
6
|
+
return { mode: 'chat', clearDraft: true, message: 'Skill wizard lost the name. Start over with /skills.' };
|
|
7
|
+
return { description, draftName, busy: true, busyLabel: 'Creating skill' };
|
|
8
|
+
}
|
|
9
|
+
export function skillCreationMessage(name, file) {
|
|
10
|
+
return `Created skill ${name} at ${file}. Invoke it with /${name}. Edit SKILL.md to refine its workflow.`;
|
|
11
|
+
}
|
|
12
|
+
export function skillCreationFailure(error) {
|
|
13
|
+
return `Skill creation failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HazeSettings } from '../../config/settings.js';
|
|
2
|
+
import type { LoadedSkill } from '../../skills/types.js';
|
|
3
|
+
export type SkillWizardResult = {
|
|
4
|
+
message?: string;
|
|
5
|
+
mode?: 'chat' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsConfirmRemove';
|
|
6
|
+
selectedName?: string;
|
|
7
|
+
settingsPatch?: Partial<HazeSettings>;
|
|
8
|
+
clearDraft?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function selectSkillResult(skills: LoadedSkill[], name: string): SkillWizardResult;
|
|
11
|
+
export declare function skillInfoMessage(settings: HazeSettings, skill: LoadedSkill): string;
|
|
12
|
+
export declare function selectSkillActionResult(settings: HazeSettings, skills: LoadedSkill[], selectedName: string | undefined, action: string): SkillWizardResult & {
|
|
13
|
+
skill?: LoadedSkill;
|
|
14
|
+
validate?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isSkillEnabled, setSkillEnabled } from '../../config/skillSettings.js';
|
|
2
|
+
import { COMMON_ACTIONS, SKILL_ACTIONS, SKILL_CHOICES } from './wizardActions.js';
|
|
3
|
+
export function selectSkillResult(skills, name) {
|
|
4
|
+
if (name === SKILL_CHOICES.addSkill)
|
|
5
|
+
return { mode: 'skillsAddName', clearDraft: true, message: 'Name the skill (kebab-case, e.g. security-review). ESC cancels.' };
|
|
6
|
+
const skill = skills.find(candidate => candidate.name === name);
|
|
7
|
+
if (!skill)
|
|
8
|
+
return { mode: 'chat', message: `No skill named ${name}. Use /skills and choose add skill.` };
|
|
9
|
+
return { mode: 'skillsAction', selectedName: skill.name, message: `${skill.name}: choose an action.` };
|
|
10
|
+
}
|
|
11
|
+
export function skillInfoMessage(settings, skill) {
|
|
12
|
+
return [
|
|
13
|
+
`${skill.name}`,
|
|
14
|
+
skill.description,
|
|
15
|
+
'',
|
|
16
|
+
`References: ${skill.references.length}`,
|
|
17
|
+
`Path: ${skill.dir}`,
|
|
18
|
+
`State: ${isSkillEnabled(settings, skill.name) ? 'enabled' : 'disabled'}`,
|
|
19
|
+
].join('\n');
|
|
20
|
+
}
|
|
21
|
+
export function selectSkillActionResult(settings, skills, selectedName, action) {
|
|
22
|
+
if (!selectedName)
|
|
23
|
+
return { mode: 'skills' };
|
|
24
|
+
const skill = skills.find(candidate => candidate.name === selectedName);
|
|
25
|
+
if (!skill)
|
|
26
|
+
return { mode: 'chat', selectedName: undefined, message: `Skill ${selectedName} not found.` };
|
|
27
|
+
if (action === COMMON_ACTIONS.enable || action === COMMON_ACTIONS.disable) {
|
|
28
|
+
const enabled = action === COMMON_ACTIONS.enable;
|
|
29
|
+
return { mode: 'chat', selectedName: undefined, settingsPatch: { skills: setSkillEnabled(settings, selectedName, enabled) }, message: `Skill ${selectedName} ${enabled ? 'enabled' : 'disabled'}.`, skill };
|
|
30
|
+
}
|
|
31
|
+
if (action === SKILL_ACTIONS.showInfo)
|
|
32
|
+
return { message: skillInfoMessage(settings, skill), skill };
|
|
33
|
+
if (action === SKILL_ACTIONS.validate)
|
|
34
|
+
return { validate: true, skill };
|
|
35
|
+
if (action === SKILL_ACTIONS.removeSkill)
|
|
36
|
+
return { mode: 'skillsConfirmRemove', message: `Remove skill ${selectedName}? This deletes ~/.haze/skills/${selectedName}. Type "yes" to confirm. Esc to cancel.`, skill };
|
|
37
|
+
return { message: `Unknown skill action: ${action}`, skill };
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure heuristics for gating and normalizing streamed assistant text.
|
|
3
|
+
*
|
|
4
|
+
* These decide when an assistant segment is "substantive" enough to show,
|
|
5
|
+
* whether a fragment is an unfinished markdown/bridge prefix that should stay
|
|
6
|
+
* hidden, and how to strip synthetic tool-call markup. None of them touch
|
|
7
|
+
* agent/callback state, which keeps them trivially unit-testable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sanitizeAssistantText(text: string): string;
|
|
10
|
+
export declare function isSubstantiveAssistantText(text: string): boolean;
|
|
11
|
+
export declare function isShortLeadInBeforeTool(text: string): boolean;
|
|
12
|
+
export declare function isShortUnfinishedLeadIn(text: string): boolean;
|
|
13
|
+
export declare function isHiddenAssistantFragment(text: string): boolean;
|
|
14
|
+
export declare function isHiddenUnstartedFinalText(text: string): boolean;
|
|
15
|
+
export declare function shouldStartAssistantStream(text: string, startedAt: number): boolean;
|
|
16
|
+
export declare function assistantDisplayText(text: string): string;
|
|
17
|
+
export declare function normalizeAssistantText(text: string): string;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure heuristics for gating and normalizing streamed assistant text.
|
|
3
|
+
*
|
|
4
|
+
* These decide when an assistant segment is "substantive" enough to show,
|
|
5
|
+
* whether a fragment is an unfinished markdown/bridge prefix that should stay
|
|
6
|
+
* hidden, and how to strip synthetic tool-call markup. None of them touch
|
|
7
|
+
* agent/callback state, which keeps them trivially unit-testable.
|
|
8
|
+
*/
|
|
9
|
+
export function sanitizeAssistantText(text) {
|
|
10
|
+
return [...text].filter(char => {
|
|
11
|
+
const code = char.charCodeAt(0);
|
|
12
|
+
return !(code <= 8 || code === 11 || code === 12 || (code >= 14 && code <= 31) || code === 127 || code === 155);
|
|
13
|
+
}).join('');
|
|
14
|
+
}
|
|
15
|
+
function hideSyntheticToolCallMarkup(text) {
|
|
16
|
+
return text
|
|
17
|
+
.replace(/(^|\n)\s*(?:```(?:xml)?\s*)?(?:xml\s*)?<tool_call>[\s\S]*?<\/tool_call>\s*(?:```)?/gi, '$1')
|
|
18
|
+
.replace(/(^|\n)\s*(?:```(?:xml)?\s*)?(?:xml\s*)?<tool_call>[\s\S]*$/i, '$1');
|
|
19
|
+
}
|
|
20
|
+
function isWordChar(char) {
|
|
21
|
+
return char.toLowerCase() !== char.toUpperCase() || (char >= '0' && char <= '9');
|
|
22
|
+
}
|
|
23
|
+
function wordCount(text) {
|
|
24
|
+
let count = 0;
|
|
25
|
+
let inWord = false;
|
|
26
|
+
for (const char of text) {
|
|
27
|
+
if (isWordChar(char)) {
|
|
28
|
+
if (!inWord)
|
|
29
|
+
count += 1;
|
|
30
|
+
inWord = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
inWord = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return count;
|
|
37
|
+
}
|
|
38
|
+
function endsWithSentenceBoundary(text) {
|
|
39
|
+
const trimmed = text.trim();
|
|
40
|
+
if (!trimmed || wordCount(trimmed) === 0)
|
|
41
|
+
return false;
|
|
42
|
+
const last = trimmed.at(-1) ?? '';
|
|
43
|
+
return last === '.' || last === '!' || last === '?' || last === ':' || last === ';' || last === ')';
|
|
44
|
+
}
|
|
45
|
+
function isNonSubstantiveAssistantText(text) {
|
|
46
|
+
return wordCount(text) === 0;
|
|
47
|
+
}
|
|
48
|
+
export function isSubstantiveAssistantText(text) {
|
|
49
|
+
const trimmed = text.trim();
|
|
50
|
+
const words = wordCount(trimmed);
|
|
51
|
+
if (words === 0)
|
|
52
|
+
return false;
|
|
53
|
+
if (trimmed.length >= 24)
|
|
54
|
+
return true;
|
|
55
|
+
if (endsWithSentenceBoundary(trimmed))
|
|
56
|
+
return true;
|
|
57
|
+
return words >= 4;
|
|
58
|
+
}
|
|
59
|
+
function isIncompleteAssistantFragment(text) {
|
|
60
|
+
const trimmed = text.trim();
|
|
61
|
+
return !isSubstantiveAssistantText(trimmed) && wordCount(trimmed) <= 2 && !endsWithSentenceBoundary(trimmed);
|
|
62
|
+
}
|
|
63
|
+
function isLikelyUnfinishedMarkdownFragment(text) {
|
|
64
|
+
const trimmed = text.trim();
|
|
65
|
+
if (!trimmed.includes('\n'))
|
|
66
|
+
return false;
|
|
67
|
+
const last = trimmed.at(-1) ?? '';
|
|
68
|
+
return last === '-' || last === '*' || last === '#' || last === '`' || last === '>';
|
|
69
|
+
}
|
|
70
|
+
// Procedural pre-tool lead-ins (e.g. "Confirmed:", "Files written.", "Now let me",
|
|
71
|
+
// "I checked the tests.") are short preambles the model emits before calling a tool; they
|
|
72
|
+
// should stay hidden so they don't surface as standalone bubbles. The ceiling is kept well
|
|
73
|
+
// below the length of genuine multi-segment answer content: a substantive sentence of ~12
|
|
74
|
+
// words preceding a tool call is real answer text and must be preserved (see the
|
|
75
|
+
// multi-segment headless integration test). Empirically procedural lead-ins are <=5 words,
|
|
76
|
+
// so 6 catches them while leaving real content visible.
|
|
77
|
+
const LEAD_IN_WORD_CEILING = 6;
|
|
78
|
+
export function isShortLeadInBeforeTool(text) {
|
|
79
|
+
const trimmed = text.trim();
|
|
80
|
+
return trimmed.length > 0 && wordCount(trimmed) <= LEAD_IN_WORD_CEILING && !isLikelyUnfinishedMarkdownFragment(trimmed);
|
|
81
|
+
}
|
|
82
|
+
export function isShortUnfinishedLeadIn(text) {
|
|
83
|
+
const trimmed = text.trim();
|
|
84
|
+
const words = wordCount(trimmed);
|
|
85
|
+
return words >= 3
|
|
86
|
+
&& words <= 4
|
|
87
|
+
&& !isSubstantiveAssistantText(trimmed)
|
|
88
|
+
&& !endsWithSentenceBoundary(trimmed)
|
|
89
|
+
&& !isLikelyUnfinishedMarkdownFragment(trimmed);
|
|
90
|
+
}
|
|
91
|
+
function isHiddenAssistantText(text) {
|
|
92
|
+
return text.length === 0 || isNonSubstantiveAssistantText(text);
|
|
93
|
+
}
|
|
94
|
+
export function isHiddenAssistantFragment(text) {
|
|
95
|
+
return isHiddenAssistantText(text) || isIncompleteAssistantFragment(text) || isLikelyUnfinishedMarkdownFragment(text);
|
|
96
|
+
}
|
|
97
|
+
export function isHiddenUnstartedFinalText(text) {
|
|
98
|
+
return isHiddenAssistantText(text) || isLikelyUnfinishedMarkdownFragment(text);
|
|
99
|
+
}
|
|
100
|
+
const ASSISTANT_STREAM_DEBOUNCE_MS = 200;
|
|
101
|
+
export function shouldStartAssistantStream(text, startedAt) {
|
|
102
|
+
if (isHiddenAssistantFragment(text))
|
|
103
|
+
return false;
|
|
104
|
+
return isSubstantiveAssistantText(text) || Date.now() - startedAt >= ASSISTANT_STREAM_DEBOUNCE_MS;
|
|
105
|
+
}
|
|
106
|
+
export function assistantDisplayText(text) {
|
|
107
|
+
return hideSyntheticToolCallMarkup(text).trim();
|
|
108
|
+
}
|
|
109
|
+
export function normalizeAssistantText(text) {
|
|
110
|
+
return assistantDisplayText(text)
|
|
111
|
+
.replace(/[`*_~#>\-–—:;,.!?()[\]{}"']/g, '')
|
|
112
|
+
.replace(/\s+/g, ' ')
|
|
113
|
+
.trim()
|
|
114
|
+
.toLowerCase();
|
|
115
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type AgentEventSink } from '../../../core/agent/events.js';
|
|
2
|
+
import { type LlmLog } from '../../../core/log/llmLog.js';
|
|
3
|
+
/**
|
|
4
|
+
* Live "tool group" renderer for the agent turn: batches concurrent/sequential
|
|
5
|
+
* tool calls into one rolling `tool` chat message with a summary header and a
|
|
6
|
+
* per-call line (icon, summary, result, duration). Holds its own mutable state
|
|
7
|
+
* (the active group + a 1s refresh timer) so `runAgentTurn` stays linear.
|
|
8
|
+
*/
|
|
9
|
+
export type NativeToolCall = {
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
toolName: string;
|
|
12
|
+
input: unknown;
|
|
13
|
+
};
|
|
14
|
+
export type ToolDisplayItem = {
|
|
15
|
+
id: string;
|
|
16
|
+
summary: string;
|
|
17
|
+
status: 'running' | 'success' | 'error';
|
|
18
|
+
result?: string;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
finishedAt?: number;
|
|
21
|
+
durationMs?: number;
|
|
22
|
+
showResult?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export interface ToolGroupRendererDeps {
|
|
25
|
+
addMessage: (msg: {
|
|
26
|
+
id: string;
|
|
27
|
+
role: 'tool';
|
|
28
|
+
text: string;
|
|
29
|
+
streaming: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
updateMessage: (id: string, update: {
|
|
32
|
+
text?: string;
|
|
33
|
+
streaming?: boolean;
|
|
34
|
+
}) => void;
|
|
35
|
+
debugLog: (line: string) => void;
|
|
36
|
+
onEvent?: AgentEventSink;
|
|
37
|
+
log?: LlmLog;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolGroupRenderer {
|
|
40
|
+
/** Find or create the display item for a tool call (rendering + logging on first sight). */
|
|
41
|
+
ensureToolItem: (toolCall: NativeToolCall) => ToolDisplayItem;
|
|
42
|
+
/** Re-render the active group (e.g. after mutating an item's status/result). */
|
|
43
|
+
updateToolGroup: (streaming?: boolean) => void;
|
|
44
|
+
/** Finalize the current group and start a fresh one (used when text resumes). */
|
|
45
|
+
startFreshToolGroup: () => void;
|
|
46
|
+
/** Final, non-streaming render of the active group if not already finalized. */
|
|
47
|
+
finalizeToolGroup: () => void;
|
|
48
|
+
/** Stop the 1s refresh timer. */
|
|
49
|
+
stopToolTimer: () => void;
|
|
50
|
+
/** Attach a dim caption line above the next tool group. */
|
|
51
|
+
setGroupCaption: (text: string) => void;
|
|
52
|
+
/** Add a scoped context-file read to the active tool group display. */
|
|
53
|
+
addContextFileRead: (path: string) => void;
|
|
54
|
+
}
|
|
55
|
+
export declare function createToolGroupRenderer(deps: ToolGroupRendererDeps): ToolGroupRenderer;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { agentEvent } from '../../../core/agent/events.js';
|
|
2
|
+
import { appendLogEntry as logAppend } from '../../../core/log/llmLog.js';
|
|
3
|
+
import { toolCallSummary, compact, formatElapsedTimeWhole, formatSeconds } from '../formatters.js';
|
|
4
|
+
function logEntry(log, entry) {
|
|
5
|
+
if (log)
|
|
6
|
+
void logAppend(log, entry).catch(() => undefined);
|
|
7
|
+
}
|
|
8
|
+
const createToolGroup = () => ({ id: `tools-${Date.now()}-${Math.random().toString(36).slice(2)}`, items: [], started: false, finalized: false });
|
|
9
|
+
export function createToolGroupRenderer(deps) {
|
|
10
|
+
let toolGroup = createToolGroup();
|
|
11
|
+
let toolTimer;
|
|
12
|
+
let pendingCaption;
|
|
13
|
+
const setGroupCaption = (text) => { pendingCaption = text.trim() || undefined; };
|
|
14
|
+
const renderToolGroup = (group) => {
|
|
15
|
+
const running = group.items.some(item => item.status === 'running');
|
|
16
|
+
const failures = group.items.filter(item => item.status === 'error').length;
|
|
17
|
+
const changes = group.items.filter(item => /^(editFile|replaceLines|writeFile)\b/.test(item.summary)).length;
|
|
18
|
+
const elapsedMs = group.items.length > 0
|
|
19
|
+
? (running ? Date.now() : Math.max(...group.items.map(item => item.finishedAt ?? item.startedAt))) - Math.min(...group.items.map(item => item.startedAt))
|
|
20
|
+
: 0;
|
|
21
|
+
const summaryParts = [`${group.items.length} calls`, `${changes} changes`];
|
|
22
|
+
if (failures > 0)
|
|
23
|
+
summaryParts.push(`${failures} failed`);
|
|
24
|
+
summaryParts.push(formatElapsedTimeWhole(elapsedMs));
|
|
25
|
+
const lines = [summaryParts.join(' · '), ...group.items.map(item => {
|
|
26
|
+
const icon = item.status === 'running' ? '…' : item.status === 'success' ? '✓' : '✗';
|
|
27
|
+
const result = item.status === 'running' || item.showResult === false ? '' : ` — ${item.result ?? item.status}${item.durationMs == null ? '' : ` in ${formatSeconds(item.durationMs)}`}`;
|
|
28
|
+
return ` ${icon} ${item.summary}${result}`;
|
|
29
|
+
})];
|
|
30
|
+
return (group.caption ? [group.caption, ...lines] : lines).join('\n');
|
|
31
|
+
};
|
|
32
|
+
const updateToolGroup = (streaming = true, group = toolGroup) => {
|
|
33
|
+
const text = renderToolGroup(group);
|
|
34
|
+
if (!group.started) {
|
|
35
|
+
group.started = true;
|
|
36
|
+
group.finalized = !streaming;
|
|
37
|
+
deps.addMessage({ id: group.id, role: 'tool', text, streaming });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
group.finalized = !streaming;
|
|
41
|
+
deps.updateMessage(group.id, { text, streaming });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const finalizeToolGroup = (group = toolGroup) => {
|
|
45
|
+
if (!group.started || group.finalized)
|
|
46
|
+
return;
|
|
47
|
+
updateToolGroup(false, group);
|
|
48
|
+
};
|
|
49
|
+
const stopToolTimer = () => {
|
|
50
|
+
if (!toolTimer)
|
|
51
|
+
return;
|
|
52
|
+
clearInterval(toolTimer);
|
|
53
|
+
toolTimer = undefined;
|
|
54
|
+
};
|
|
55
|
+
const startToolTimer = () => {
|
|
56
|
+
if (toolTimer)
|
|
57
|
+
return;
|
|
58
|
+
toolTimer = setInterval(() => {
|
|
59
|
+
if (toolGroup.items.some(item => item.status === 'running'))
|
|
60
|
+
updateToolGroup(true);
|
|
61
|
+
else
|
|
62
|
+
stopToolTimer();
|
|
63
|
+
}, 1000);
|
|
64
|
+
};
|
|
65
|
+
const ensureToolItem = (toolCall) => {
|
|
66
|
+
if (toolGroup.finalized)
|
|
67
|
+
toolGroup = createToolGroup();
|
|
68
|
+
if (pendingCaption && toolGroup.items.length === 0) {
|
|
69
|
+
toolGroup.caption = pendingCaption;
|
|
70
|
+
pendingCaption = undefined;
|
|
71
|
+
}
|
|
72
|
+
let item = toolGroup.items.find(candidate => candidate.id === toolCall.toolCallId);
|
|
73
|
+
if (!item) {
|
|
74
|
+
item = { id: toolCall.toolCallId, summary: toolCallSummary(toolCall.toolName, toolCall.input), status: 'running', startedAt: Date.now() };
|
|
75
|
+
toolGroup.items.push(item);
|
|
76
|
+
deps.onEvent?.(agentEvent({ type: 'tool_start', id: toolCall.toolCallId, name: toolCall.toolName, input: toolCall.input }));
|
|
77
|
+
logEntry(deps.log, { at: new Date().toISOString(), type: 'tool_call', stream: 'main', toolCall: { id: toolCall.toolCallId, name: toolCall.toolName, input: toolCall.input } });
|
|
78
|
+
deps.debugLog(`tool start: ${toolCall.toolName} ${compact(toolCall.input)}`);
|
|
79
|
+
startToolTimer();
|
|
80
|
+
updateToolGroup(true);
|
|
81
|
+
}
|
|
82
|
+
return item;
|
|
83
|
+
};
|
|
84
|
+
const startFreshToolGroup = () => {
|
|
85
|
+
if (!toolGroup.started || toolGroup.items.some(item => item.status === 'running'))
|
|
86
|
+
return;
|
|
87
|
+
finalizeToolGroup(toolGroup);
|
|
88
|
+
toolGroup = createToolGroup();
|
|
89
|
+
};
|
|
90
|
+
const addContextFileRead = (path) => {
|
|
91
|
+
if (toolGroup.finalized)
|
|
92
|
+
toolGroup = createToolGroup();
|
|
93
|
+
if (pendingCaption && toolGroup.items.length === 0) {
|
|
94
|
+
toolGroup.caption = pendingCaption;
|
|
95
|
+
pendingCaption = undefined;
|
|
96
|
+
}
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
toolGroup.items.push({ id: `context-file-${now}-${Math.random().toString(36).slice(2)}`, summary: `understanding: ${path}`, status: 'success', startedAt: now, finishedAt: now, durationMs: 0, showResult: false });
|
|
99
|
+
updateToolGroup(true);
|
|
100
|
+
};
|
|
101
|
+
return { ensureToolItem, updateToolGroup, startFreshToolGroup, finalizeToolGroup, stopToolTimer, setGroupCaption, addContextFileRead };
|
|
102
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ToolResultState {
|
|
2
|
+
mutatingToolSucceeded: boolean;
|
|
3
|
+
editRecoveryPath?: string;
|
|
4
|
+
editRecoveryReadSatisfied: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function initialToolResultState(): ToolResultState;
|
|
7
|
+
export declare function applyToolResultState(state: ToolResultState, event: {
|
|
8
|
+
toolName: string;
|
|
9
|
+
input: unknown;
|
|
10
|
+
output: unknown;
|
|
11
|
+
ok: boolean;
|
|
12
|
+
}): ToolResultState;
|
|
13
|
+
export declare function isMutatingToolName(toolName: string): boolean;
|