@denizokcu/haze 0.6.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 +19 -0
- package/README.md +59 -12
- 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 +293 -894
- 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 +1 -1
- package/dist/cli/commands/commands.js +41 -267
- package/dist/cli/commands/formatters.js +12 -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 +9 -25
- package/dist/cli/commands/streaming.js +82 -347
- 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.js +3 -6
- package/dist/config/mcpSettings.js +5 -5
- package/dist/config/providers.js +4 -4
- package/dist/config/skillSettings.js +4 -3
- 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 +46 -1
- package/dist/llm/lsp.js +9 -9
- package/dist/llm/lspTools.d.ts +2 -20
- package/dist/llm/mcp.js +9 -0
- package/dist/llm/requestContext.js +7 -22
- package/dist/llm/systemPrompt.d.ts +1 -0
- package/dist/llm/systemPrompt.js +1 -1
- 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 +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/package.json +1 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { execFile as execFileCallback } from 'node:child_process';
|
|
4
|
-
import os from 'node:os';
|
|
5
4
|
import { promisify } from 'node:util';
|
|
6
5
|
import fs from 'fs-extra';
|
|
7
6
|
import { Box, render, Static, Text, useApp, useStdout } from 'ink';
|
|
@@ -11,38 +10,46 @@ import { checkForUpdate } from '../../config/updateCheck.js';
|
|
|
11
10
|
import { addInputHistoryItem, readInputHistory } from '../../config/inputHistory.js';
|
|
12
11
|
import { loadTasks as loadTasksFromStore, clearTasks as clearTasksFromStore } from '../../core/tasks/taskStorage.js';
|
|
13
12
|
import { readSettings, updateSettings } from '../../config/settings.js';
|
|
14
|
-
import { activeModel,
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { isSkillEnabled
|
|
13
|
+
import { activeModel, findProvider, modelSelector, resolveModelSelector } from '../../config/providers.js';
|
|
14
|
+
import { removeLspServer } from '../../config/lspSettings.js';
|
|
15
|
+
import { removeMcpServer } from '../../config/mcpSettings.js';
|
|
16
|
+
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
18
17
|
import { Header } from '../../ui/components/Header.js';
|
|
19
18
|
import { TextInput } from '../../ui/components/TextInput.js';
|
|
20
|
-
import { MarkdownText } from '../../ui/components/MarkdownText.js';
|
|
21
19
|
import { theme } from '../../ui/theme.js';
|
|
22
20
|
import { handleSlashCommand } from './commands.js';
|
|
23
21
|
import { runAgentTurn } from './streaming.js';
|
|
24
22
|
import { formatContextReport } from './formatters.js';
|
|
25
23
|
import { createLog as createLlmLog, endLog as endLlmLog } from '../../core/log/llmLog.js';
|
|
26
|
-
import { formatElapsedTime, formatElapsedTimeWhole } from './formatters.js';
|
|
27
24
|
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
28
25
|
import { createSkill, toSkillDirName } from '../../skills/builder/SkillBuilder.js';
|
|
29
|
-
import {
|
|
26
|
+
import { findPreset } from '../../config/providerPresets.js';
|
|
30
27
|
import { appendSessionEntry, createSession, formatSession, latestSession, restoreConversation, restoreWorkState } from '../../core/session/sessionStore.js';
|
|
31
|
-
import { compactModelMessages
|
|
28
|
+
import { compactModelMessages } from '../../core/agent/compaction.js';
|
|
32
29
|
import { contextBreakdown } from '../../core/agent/contextBudget.js';
|
|
33
30
|
import { stripSyntheticControls } from '../../core/agent/requestAssembly.js';
|
|
34
31
|
import { modelWithConfig } from '../../llm/client.js';
|
|
35
32
|
import { assembleRequestContext } from '../../llm/requestContext.js';
|
|
36
33
|
import { closeMcpClients } from '../../llm/mcp.js';
|
|
34
|
+
import { MAX_VISIBLE_TASKS, TaskBar } from '../chat/TaskBar.js';
|
|
37
35
|
import { clearToolOutputs } from '../../core/agent/toolOutputStore.js';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
import { MessageView, messageKey, orderedDisplayMessages } from '../chat/messages.js';
|
|
37
|
+
import { createSessionRecorder } from '../chat/sessionRecorder.js';
|
|
38
|
+
import { startupContextInfo, startupProviderInfo } from '../chat/startupInfo.js';
|
|
39
|
+
import { compactHomePath, displayMessagesFromConversation, estimateConversationTokens, formatTokenCount, toolCallCount } from '../chat/chatMetrics.js';
|
|
40
|
+
import { accumulateTokenUsage, EMPTY_TOKEN_USAGE, shouldClearCompletedTasks } from '../chat/turnState.js';
|
|
41
|
+
import { MASKED_MODES, PICKER_MODES, SUBMIT_EMPTY_MODES, placeholderForMode } from './chatModes.js';
|
|
42
|
+
import { inputSuggestionsForState } from '../chat/inputSuggestions.js';
|
|
43
|
+
import { PROVIDER_ACTIONS, PROVIDER_CHOICES, SERVER_CHOICES } from './wizardActions.js';
|
|
44
|
+
import { captureLspName, captureMcpCommand, captureMcpName, captureMcpTransport, captureMcpUrl, captureProviderName, captureProviderUrl } from './wizardPrompts.js';
|
|
45
|
+
import { finishLspCustomResult, selectLspActionResult, selectLspPresetResult, selectLspServerResult } from './lspWizard.js';
|
|
46
|
+
import { finishMcpCustomResult, selectMcpActionResult, selectMcpPresetResult, selectMcpServerResult, setMcpServerKeyResult } from './mcpWizard.js';
|
|
47
|
+
import { providerActionResult, providerAppendModels, providerFinishAdd, providerRemove, providerRemoveModels, providerSetKey } from './providerWizard.js';
|
|
48
|
+
import { selectSkillActionResult, selectSkillResult } from './skillWizard.js';
|
|
49
|
+
import { captureSkillDescription as captureSkillDescriptionResult, skillCreationFailure, skillCreationMessage } from './skillCreation.js';
|
|
50
|
+
import { skillConfirmRemoveResult as skillConfirmRemove } from './skillConfirmRemove.js';
|
|
51
|
+
import { commandParts, isYesConfirmation } from './wizardInput.js';
|
|
44
52
|
const execFile = promisify(execFileCallback);
|
|
45
|
-
const EMPTY_TOKEN_USAGE = { inputTokens: undefined, outputTokens: undefined, systemPrompt: 0, messages: 0, toolSchemas: 0, outputEstimate: 0, cacheReadTokens: 0, cacheWriteTokens: 0, noCacheTokens: 0, reasoningTokens: 0, logicalInputEstimate: 0, effectiveNonCachedInput: undefined };
|
|
46
53
|
async function currentBranchName() {
|
|
47
54
|
try {
|
|
48
55
|
const { stdout } = await execFile('git', ['branch', '--show-current'], { cwd: process.cwd() });
|
|
@@ -52,205 +59,6 @@ async function currentBranchName() {
|
|
|
52
59
|
return undefined;
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
function toolCallCount(messages) {
|
|
56
|
-
return messages.reduce((total, message) => {
|
|
57
|
-
if (message.role !== 'tool')
|
|
58
|
-
return total;
|
|
59
|
-
const headerCount = /Tools: (\d+) calls?/.exec(message.text)?.[1];
|
|
60
|
-
if (headerCount)
|
|
61
|
-
return total + Number(headerCount);
|
|
62
|
-
const rows = message.text.split('\n').filter(line => /^\s+[✓✗…]\s/.test(line));
|
|
63
|
-
return total + rows.reduce((rowTotal, row) => rowTotal + Number(/×(\d+)/.exec(row)?.[1] ?? 1), 0);
|
|
64
|
-
}, 0);
|
|
65
|
-
}
|
|
66
|
-
function estimateTokens(text) {
|
|
67
|
-
return Math.ceil(text.length / 4);
|
|
68
|
-
}
|
|
69
|
-
function compactHomePath(filePath) {
|
|
70
|
-
const home = os.homedir();
|
|
71
|
-
if (filePath === home)
|
|
72
|
-
return '~';
|
|
73
|
-
return filePath.startsWith(`${home}/`) ? `~/${filePath.slice(home.length + 1)}` : filePath;
|
|
74
|
-
}
|
|
75
|
-
function formatTokenCount(tokens) {
|
|
76
|
-
if (tokens >= 1_000_000)
|
|
77
|
-
return `${(tokens / 1_000_000).toFixed(tokens >= 10_000_000 ? 0 : 1).replace(/\.0$/, '')}m`;
|
|
78
|
-
if (tokens >= 1_000)
|
|
79
|
-
return `${(tokens / 1_000).toFixed(tokens >= 10_000 ? 0 : 1).replace(/\.0$/, '')}k`;
|
|
80
|
-
return String(tokens);
|
|
81
|
-
}
|
|
82
|
-
function displayMessagesFromConversation(conversation) {
|
|
83
|
-
return conversation.flatMap(message => {
|
|
84
|
-
if (message.role !== 'user' && message.role !== 'assistant')
|
|
85
|
-
return [];
|
|
86
|
-
const text = modelMessageText(message).trim();
|
|
87
|
-
return text ? [{ role: message.role, text }] : [];
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function estimateConversationTokens(messages) {
|
|
91
|
-
const inputText = messages
|
|
92
|
-
.filter(message => message.role === 'user' || message.role === 'tool')
|
|
93
|
-
.map(message => message.text)
|
|
94
|
-
.join('\n');
|
|
95
|
-
const outputText = messages
|
|
96
|
-
.filter(message => message.role === 'assistant')
|
|
97
|
-
.map(message => message.text)
|
|
98
|
-
.join('\n');
|
|
99
|
-
return {
|
|
100
|
-
input: estimateTokens(inputText),
|
|
101
|
-
output: estimateTokens(outputText),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function fullWidthLines(text, width, leftPadding = 0) {
|
|
105
|
-
const safeWidth = Math.max(1, width);
|
|
106
|
-
const prefix = ' '.repeat(leftPadding);
|
|
107
|
-
return text.replace(/\r\n|\r/g, '\n').split('\n').map(line => `${prefix}${line}`.padEnd(Math.max(safeWidth, line.length + leftPadding)));
|
|
108
|
-
}
|
|
109
|
-
function fullWidthBlankLine(width) {
|
|
110
|
-
return ''.padEnd(Math.max(1, width));
|
|
111
|
-
}
|
|
112
|
-
function ToolMessageText({ text, streaming }) {
|
|
113
|
-
const lines = text.split('\n');
|
|
114
|
-
return _jsx(Box, { flexDirection: "column", children: lines.map((line, index) => {
|
|
115
|
-
const diffRow = /^(\s*\d+\s+)([+-])(.*)$/.exec(line);
|
|
116
|
-
if (diffRow) {
|
|
117
|
-
const [, prefix, marker, rest] = diffRow;
|
|
118
|
-
const isAdd = marker === '+';
|
|
119
|
-
return _jsxs(Text, { color: "white", backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [_jsxs(Text, { color: isAdd ? theme.success : theme.danger, backgroundColor: isAdd ? theme.successBg : theme.dangerBg, children: [prefix, marker] }), rest] }, `${index}-${line}`);
|
|
120
|
-
}
|
|
121
|
-
const contextRow = /^(\s*\d+\s+)\s(.*)$/.exec(line);
|
|
122
|
-
if (contextRow) {
|
|
123
|
-
const [, prefix, rest] = contextRow;
|
|
124
|
-
return _jsxs(Text, { color: "white", children: [_jsxs(Text, { color: theme.muted, children: [prefix, " "] }), rest] }, `${index}-${line}`);
|
|
125
|
-
}
|
|
126
|
-
const row = /^(\s*)([✓✗…])\s+(\S+)(.*)$/.exec(line);
|
|
127
|
-
if (!row) {
|
|
128
|
-
const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(line);
|
|
129
|
-
return _jsxs(Text, { color: theme.muted, children: [index === 0 && streaming ? _jsxs(_Fragment, { children: [_jsx(Spinner, { type: "dots" }), " "] }) : null, timer ? timer[1] : line, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
|
|
130
|
-
}
|
|
131
|
-
const [, indent, icon, toolName, rest] = row;
|
|
132
|
-
const iconColor = icon === '✓' ? theme.success : icon === '✗' ? theme.danger : theme.muted;
|
|
133
|
-
const timer = /(.*) (\([0-9]+(?:h [0-9]+m [0-9]+(?:\.[0-9])?s|m [0-9]+(?:\.[0-9])?s|(?:\.[0-9])?s)\))$/.exec(rest);
|
|
134
|
-
return _jsxs(Text, { color: theme.muted, children: [indent, _jsx(Text, { color: iconColor, children: icon }), " ", _jsx(Text, { color: theme.purple, children: toolName }), timer ? timer[1] : rest, timer ? _jsxs(Text, { color: theme.muted, bold: false, children: [" ", timer[2]] }) : null] }, `${index}-${line}`);
|
|
135
|
-
}) });
|
|
136
|
-
}
|
|
137
|
-
function messageElapsedLabel(message) {
|
|
138
|
-
if (message.startedAt == null)
|
|
139
|
-
return '';
|
|
140
|
-
const end = message.finishedAt ?? (message.streaming ? Date.now() : message.startedAt);
|
|
141
|
-
const elapsed = end - message.startedAt;
|
|
142
|
-
if (message.role === 'assistant' && !message.streaming && message.tokensPerSecond != null) {
|
|
143
|
-
return `✓ Done in ${formatElapsedTime(elapsed)} · ${Math.round(message.tokensPerSecond)} tok/s`;
|
|
144
|
-
}
|
|
145
|
-
return message.streaming ? formatElapsedTimeWhole(elapsed) : formatElapsedTime(elapsed);
|
|
146
|
-
}
|
|
147
|
-
function MessageView({ message, width, suppressAssistantHeader = false }) {
|
|
148
|
-
if (message.role === 'user') {
|
|
149
|
-
return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) }), _jsx(Text, { color: theme.success, bold: true, backgroundColor: theme.quoteBg, children: ' You asked'.padEnd(width) }), fullWidthLines(message.text, width, 2).map((line, lineIndex) => _jsx(Text, { color: "white", backgroundColor: theme.quoteBg, children: line }, lineIndex)), _jsx(Text, { backgroundColor: theme.quoteBg, children: fullWidthBlankLine(width) })] });
|
|
150
|
-
}
|
|
151
|
-
return _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [!suppressAssistantHeader && _jsxs(Text, { children: [_jsx(Text, { color: message.role === 'assistant' ? theme.purple : message.role === 'tool' ? theme.blue : theme.muted, bold: true, children: message.role === 'assistant' ? 'haze' : message.role === 'tool' ? 'Tool' : 'Info' }), messageElapsedLabel(message) ? _jsxs(Text, { color: theme.muted, bold: false, children: [" \u00B7 ", messageElapsedLabel(message)] }) : null] }), message.role === 'tool'
|
|
152
|
-
? _jsx(ToolMessageText, { text: message.text, streaming: message.streaming })
|
|
153
|
-
: message.role === 'assistant' && !message.streaming
|
|
154
|
-
? _jsx(MarkdownText, { content: message.text })
|
|
155
|
-
: _jsx(Text, { children: message.text })] });
|
|
156
|
-
}
|
|
157
|
-
function messageKey(message, index) {
|
|
158
|
-
return message.id ?? `${index}-${message.role}-${message.text}`;
|
|
159
|
-
}
|
|
160
|
-
function orderedDisplayMessages(messages) {
|
|
161
|
-
return messages
|
|
162
|
-
.map((message, index) => ({ message, index }))
|
|
163
|
-
.sort((a, b) => {
|
|
164
|
-
if (a.message.displayOrder != null && b.message.displayOrder != null && a.message.displayOrder !== b.message.displayOrder) {
|
|
165
|
-
return a.message.displayOrder - b.message.displayOrder;
|
|
166
|
-
}
|
|
167
|
-
return a.index - b.index;
|
|
168
|
-
})
|
|
169
|
-
.map(item => item.message);
|
|
170
|
-
}
|
|
171
|
-
function annotateTurnHeaders(messages) {
|
|
172
|
-
return messages.map(message => ({ message, suppressAssistantHeader: false }));
|
|
173
|
-
}
|
|
174
|
-
function startupProviderInfo(settings) {
|
|
175
|
-
const selection = activeModel(settings);
|
|
176
|
-
const configuredCount = configuredProviders(settings).length;
|
|
177
|
-
const lspServers = configuredLspServers(settings);
|
|
178
|
-
const enabledLsp = lspServers.filter(server => server.enabled !== false);
|
|
179
|
-
const lspLine = enabledLsp.length > 0
|
|
180
|
-
? `- LSP: ${enabledLsp.length} configured (${enabledLsp.map(server => server.name).join(', ')}; tools appear only when the command is installed)`
|
|
181
|
-
: '- LSP: none configured (optional: install a language server, then /lsp presets and /lsp add typescript for semantic code navigation)';
|
|
182
|
-
const mcpServers = configuredMcpServers(settings);
|
|
183
|
-
const enabledMcp = mcpServers.filter(server => server.enabled !== false);
|
|
184
|
-
const mcpLine = enabledMcp.length > 0
|
|
185
|
-
? `- MCP: ${enabledMcp.length} configured (${enabledMcp.map(server => server.name).join(', ')}; tools load each turn)`
|
|
186
|
-
: '- MCP: none configured (optional: /mcp add context7 for up-to-date library docs)';
|
|
187
|
-
if (!selection) {
|
|
188
|
-
return [
|
|
189
|
-
'Provider configuration',
|
|
190
|
-
'- Provider: not configured',
|
|
191
|
-
'- Model: not set',
|
|
192
|
-
'- Base URL: not configured',
|
|
193
|
-
'- API key: missing',
|
|
194
|
-
`- Configured providers: ${configuredCount}`,
|
|
195
|
-
lspLine,
|
|
196
|
-
mcpLine,
|
|
197
|
-
'',
|
|
198
|
-
'Run /provider to choose or add a provider, then select a model.',
|
|
199
|
-
].join('\n');
|
|
200
|
-
}
|
|
201
|
-
const model = selection.model;
|
|
202
|
-
const modelSource = settings.model ? 'settings' : 'provider default';
|
|
203
|
-
const baseURL = selection.provider.url;
|
|
204
|
-
const apiKeySource = providerHasKey(settings, selection.provider) ? `provider ${selection.provider.name}` : 'missing';
|
|
205
|
-
const provider = selection.provider.name;
|
|
206
|
-
return [
|
|
207
|
-
'Provider configuration',
|
|
208
|
-
`- Provider: ${provider}`,
|
|
209
|
-
`- Model: ${model} (${modelSource})`,
|
|
210
|
-
`- Base URL: ${baseURL} (settings)`,
|
|
211
|
-
`- API key: ${apiKeySource === 'missing' ? 'not configured; local providers may not need one' : `configured via ${apiKeySource}`}`,
|
|
212
|
-
`- Configured providers: ${configuredCount}`,
|
|
213
|
-
lspLine,
|
|
214
|
-
mcpLine,
|
|
215
|
-
].join('\n');
|
|
216
|
-
}
|
|
217
|
-
const TASK_STATUS_ICON = {
|
|
218
|
-
pending: '\u25CB',
|
|
219
|
-
in_progress: '\u25D0',
|
|
220
|
-
completed: '\u2713',
|
|
221
|
-
};
|
|
222
|
-
function taskStatusColor(status) {
|
|
223
|
-
switch (status) {
|
|
224
|
-
case 'completed': return theme.success;
|
|
225
|
-
case 'in_progress': return theme.warning;
|
|
226
|
-
default: return theme.muted;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const MAX_VISIBLE_TASKS = 5;
|
|
230
|
-
function TaskBarContent({ tasks, width, expanded, padding }) {
|
|
231
|
-
const maxTitleWidth = Math.max(10, width - 6);
|
|
232
|
-
const inProgress = tasks.filter(t => t.status === 'in_progress');
|
|
233
|
-
const pending = tasks.filter(t => t.status === 'pending');
|
|
234
|
-
const completed = tasks.filter(t => t.status === 'completed');
|
|
235
|
-
const limit = expanded ? tasks.length : MAX_VISIBLE_TASKS;
|
|
236
|
-
const ordered = [];
|
|
237
|
-
for (const t of inProgress) {
|
|
238
|
-
if (ordered.length < limit)
|
|
239
|
-
ordered.push(t);
|
|
240
|
-
}
|
|
241
|
-
for (const t of pending) {
|
|
242
|
-
if (ordered.length < limit)
|
|
243
|
-
ordered.push(t);
|
|
244
|
-
}
|
|
245
|
-
for (let i = completed.length - 1; i >= 0 && ordered.length < limit; i--) {
|
|
246
|
-
ordered.push(completed[i]);
|
|
247
|
-
}
|
|
248
|
-
const counts = `${inProgress.length > 0 ? `${inProgress.length} active` : ''}${pending.length > 0 ? `${inProgress.length > 0 ? ', ' : ''}${pending.length} pending` : ''}${completed.length > 0 ? `${inProgress.length + pending.length > 0 ? ', ' : ''}${completed.length} done` : ''}`;
|
|
249
|
-
return (_jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [padding > 0 && Array.from({ length: padding }, (_, i) => _jsx(Text, { children: ' ' }, `pad-${i}`)), _jsxs(Text, { children: [_jsx(Text, { color: theme.purple, bold: true, children: "Tasks" }), counts ? _jsxs(Text, { color: theme.muted, children: [" (", counts, ")"] }) : null, tasks.length > MAX_VISIBLE_TASKS ? _jsxs(Text, { color: theme.muted, dimColor: true, children: [" \u00B7 ctrl+o ", expanded ? 'collapse' : 'expand'] }) : null] }), ordered.map(task => {
|
|
250
|
-
const title = task.title.length > maxTitleWidth ? task.title.slice(0, maxTitleWidth - 1) + '\u2026' : task.title;
|
|
251
|
-
return (_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: taskStatusColor(task.status), children: [TASK_STATUS_ICON[task.status], " "] }), _jsx(Text, { color: task.status === 'completed' ? theme.muted : 'white', children: title })] }, task.id));
|
|
252
|
-
})] }));
|
|
253
|
-
}
|
|
254
62
|
function ChatScreen({ debug = false, version, continueSession = false, noSession = false }) {
|
|
255
63
|
const { exit } = useApp();
|
|
256
64
|
const { stdout } = useStdout();
|
|
@@ -285,6 +93,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
285
93
|
const sessionStartRef = useRef(new Date());
|
|
286
94
|
const workStateRef = useRef(undefined);
|
|
287
95
|
const llmLogRef = useRef(undefined);
|
|
96
|
+
const contextFileSignaturesRef = useRef(new Map());
|
|
288
97
|
const followUpQueueRef = useRef([]);
|
|
289
98
|
const [inputHistory, setInputHistory] = useState([]);
|
|
290
99
|
const [debugLogs, setDebugLogs] = useState([]);
|
|
@@ -292,7 +101,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
292
101
|
const [mode, setMode] = useState('chat');
|
|
293
102
|
const [busy, setBusy] = useState(false);
|
|
294
103
|
const [busyLabel, setBusyLabel] = useState('Haze is thinking');
|
|
295
|
-
const [
|
|
104
|
+
const [, setActiveGoalStatus] = useState();
|
|
296
105
|
const [visibleTasks, setVisibleTasks] = useState([]);
|
|
297
106
|
const [tasksExpanded, setTasksExpanded] = useState(false);
|
|
298
107
|
const [taskBarPadding, setTaskBarPadding] = useState(0);
|
|
@@ -311,24 +120,22 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
311
120
|
const [selectedMcpName, setSelectedMcpName] = useState();
|
|
312
121
|
const [mcpDraft, setMcpDraft] = useState({});
|
|
313
122
|
useEffect(() => {
|
|
314
|
-
Promise.all([
|
|
123
|
+
Promise.all([
|
|
124
|
+
readSettings().catch(() => ({})),
|
|
125
|
+
currentBranchName().catch(() => undefined),
|
|
126
|
+
readContextFiles().catch(() => []),
|
|
127
|
+
]).then(([next, branch, files]) => {
|
|
315
128
|
setSettings(next);
|
|
316
129
|
setBranchName(branch);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
setMessages(m => [...m, { role: 'system', text: startupProviderInfo({}) }]);
|
|
322
|
-
}).catch(() => {
|
|
323
|
-
setMessages(m => [...m, { role: 'system', text: startupProviderInfo({}) }]);
|
|
324
|
-
});
|
|
325
|
-
});
|
|
130
|
+
setContextFiles(files);
|
|
131
|
+
contextFileSignaturesRef.current = new Map(files.flatMap(file => file.signature ? [[file.path, file.signature]] : []));
|
|
132
|
+
setMessages(m => [...m, { role: 'system', text: `${startupProviderInfo(next)}\n\n${startupContextInfo(files)}` }]);
|
|
133
|
+
}).catch(() => undefined);
|
|
326
134
|
initializeSession().catch(error => {
|
|
327
135
|
const text = error instanceof Error ? error.message : String(error);
|
|
328
136
|
setMessages(m => [...m, { role: 'system', text: `Session disabled: ${text}` }]);
|
|
329
137
|
});
|
|
330
138
|
readInputHistory().then(setInputHistory).catch(() => undefined);
|
|
331
|
-
readContextFiles().then(setContextFiles).catch(() => undefined);
|
|
332
139
|
refreshSkills().catch(() => undefined);
|
|
333
140
|
loadTasksFromStore().then(setVisibleTasks).catch(() => undefined);
|
|
334
141
|
if (version) {
|
|
@@ -357,7 +164,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
357
164
|
function skillInvocation(value) {
|
|
358
165
|
if (!value.startsWith('/'))
|
|
359
166
|
return undefined;
|
|
360
|
-
const [name, ...args] = value.slice(1)
|
|
167
|
+
const [name, ...args] = commandParts(value.slice(1));
|
|
361
168
|
if (!name)
|
|
362
169
|
return undefined;
|
|
363
170
|
const skill = skills.find(candidate => candidate.name === name);
|
|
@@ -382,6 +189,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
382
189
|
}
|
|
383
190
|
async function startNewSession(message = 'Started a new session.') {
|
|
384
191
|
clearToolOutputs();
|
|
192
|
+
contextFileSignaturesRef.current = new Map(contextFiles.flatMap(file => file.signature ? [[file.path, file.signature]] : []));
|
|
385
193
|
workStateRef.current = undefined;
|
|
386
194
|
sessionStartRef.current = new Date();
|
|
387
195
|
if (noSession) {
|
|
@@ -404,7 +212,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
404
212
|
if (continueSession) {
|
|
405
213
|
const session = await latestSession();
|
|
406
214
|
if (session) {
|
|
407
|
-
const conversation = await restoreConversation(session);
|
|
215
|
+
const { messages: conversation, parseErrors: conversationErrors } = await restoreConversation(session);
|
|
408
216
|
sessionRef.current = session;
|
|
409
217
|
sessionStartRef.current = new Date();
|
|
410
218
|
conversationRef.current = conversation;
|
|
@@ -412,7 +220,11 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
412
220
|
setLiveMessagesState(() => []);
|
|
413
221
|
const restoredMessages = displayMessagesFromConversation(conversation);
|
|
414
222
|
setTokenUsage({ ...EMPTY_TOKEN_USAGE, messages: estimateConversationTokens(restoredMessages).input, outputEstimate: estimateConversationTokens(restoredMessages).output });
|
|
415
|
-
|
|
223
|
+
const { state: workState, parseErrors: workStateErrors } = await restoreWorkState(session);
|
|
224
|
+
workStateRef.current = workState;
|
|
225
|
+
for (const error of [...conversationErrors, ...workStateErrors]) {
|
|
226
|
+
debugLog(`Session parse error: ${error}`);
|
|
227
|
+
}
|
|
416
228
|
setMessages(m => [...m, { role: 'system', text: `Resumed session: ${formatSession(session)}` }, ...restoredMessages]);
|
|
417
229
|
await startNewLog();
|
|
418
230
|
return;
|
|
@@ -454,11 +266,15 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
454
266
|
setMessages(m => [...m, { role: 'system', text: 'No previous session found for this workspace.' }]);
|
|
455
267
|
return;
|
|
456
268
|
}
|
|
457
|
-
const conversation = await restoreConversation(session);
|
|
269
|
+
const { messages: conversation, parseErrors: conversationErrors } = await restoreConversation(session);
|
|
270
|
+
const { state: workState, parseErrors: workStateErrors } = await restoreWorkState(session);
|
|
271
|
+
for (const error of [...conversationErrors, ...workStateErrors]) {
|
|
272
|
+
debugLog(`Session parse error: ${error}`);
|
|
273
|
+
}
|
|
458
274
|
clearToolOutputs();
|
|
459
275
|
sessionRef.current = session;
|
|
460
276
|
conversationRef.current = conversation;
|
|
461
|
-
workStateRef.current =
|
|
277
|
+
workStateRef.current = workState;
|
|
462
278
|
setSessionLabel(session.id);
|
|
463
279
|
setTokenUsage({ ...EMPTY_TOKEN_USAGE });
|
|
464
280
|
setLiveMessagesState(() => []);
|
|
@@ -531,134 +347,8 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
531
347
|
setMcpDraft({});
|
|
532
348
|
}
|
|
533
349
|
}
|
|
534
|
-
function providerSuggestions() {
|
|
535
|
-
return [
|
|
536
|
-
...configuredProviders(settings).map(provider => ({
|
|
537
|
-
value: provider.name,
|
|
538
|
-
description: `${provider.url} · ${provider.models.length} model${provider.models.length === 1 ? '' : 's'}`,
|
|
539
|
-
kind: 'provider',
|
|
540
|
-
})),
|
|
541
|
-
{ value: 'add provider', description: 'Add a new provider (presets available)', kind: 'provider' },
|
|
542
|
-
];
|
|
543
|
-
}
|
|
544
|
-
function providerActionSuggestions() {
|
|
545
|
-
const provider = selectedProviderName ? findProvider(settings, selectedProviderName) : undefined;
|
|
546
|
-
return [
|
|
547
|
-
{ value: 'use provider', description: 'Set this provider and choose a model', kind: 'provider' },
|
|
548
|
-
{ value: 'add models', description: 'Append comma-separated model names', kind: 'provider' },
|
|
549
|
-
{ value: 'set API key', description: provider?.key ? 'Update the saved API key' : 'Add an API key', kind: 'provider' },
|
|
550
|
-
...(provider?.models?.length ? [{ value: 'remove models', description: 'Remove models from this provider', kind: 'provider' }] : []),
|
|
551
|
-
{ value: 'remove provider', description: 'Delete this provider from settings', kind: 'provider' },
|
|
552
|
-
];
|
|
553
|
-
}
|
|
554
|
-
function presetSuggestions() {
|
|
555
|
-
const cloudPresets = PROVIDER_PRESETS.filter(p => p.category === 'cloud');
|
|
556
|
-
const localPresets = PROVIDER_PRESETS.filter(p => p.category === 'local');
|
|
557
|
-
return [
|
|
558
|
-
...cloudPresets.map(preset => ({
|
|
559
|
-
value: preset.id,
|
|
560
|
-
description: `${preset.baseUrl}${preset.suggestedModels?.length ? ' · e.g. ' + preset.suggestedModels.slice(0, 2).join(', ') : ''}`,
|
|
561
|
-
kind: 'provider',
|
|
562
|
-
})),
|
|
563
|
-
...localPresets.map(preset => ({
|
|
564
|
-
value: preset.id,
|
|
565
|
-
description: `${preset.baseUrl} · local, no API key needed`,
|
|
566
|
-
kind: 'provider',
|
|
567
|
-
})),
|
|
568
|
-
{ value: 'custom', description: 'Enter provider name, URL, and API key manually', kind: 'provider' },
|
|
569
|
-
];
|
|
570
|
-
}
|
|
571
|
-
function modelSuggestions() {
|
|
572
|
-
const providers = configuredProviders(settings).filter(provider => !modelProviderFilter || provider.name === modelProviderFilter);
|
|
573
|
-
return providers.flatMap(provider => provider.models.map(model => ({
|
|
574
|
-
value: modelProviderFilter ? model : modelSelector(provider, model),
|
|
575
|
-
description: provider.name,
|
|
576
|
-
kind: 'model',
|
|
577
|
-
})));
|
|
578
|
-
}
|
|
579
|
-
function lspSuggestions() {
|
|
580
|
-
const servers = configuredLspServers(settings);
|
|
581
|
-
return [{ value: 'add server', description: 'add an LSP server (presets available)', kind: 'lsp' },
|
|
582
|
-
...servers.map(server => ({
|
|
583
|
-
value: server.name,
|
|
584
|
-
description: `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`,
|
|
585
|
-
kind: 'lsp',
|
|
586
|
-
}))];
|
|
587
|
-
}
|
|
588
|
-
function lspActionSuggestions() {
|
|
589
|
-
const server = selectedLspName ? configuredLspServers(settings).find(s => s.name === selectedLspName) : undefined;
|
|
590
|
-
const result = [];
|
|
591
|
-
if (server)
|
|
592
|
-
result.push({ value: server.enabled === false ? 'enable' : 'disable', description: `${server.enabled === false ? 'enable' : 'disable'} this server`, kind: 'lsp' });
|
|
593
|
-
result.push({ value: 'remove server', description: 'remove this server', kind: 'lsp' });
|
|
594
|
-
return result;
|
|
595
|
-
}
|
|
596
|
-
function lspPresetSuggestions() {
|
|
597
|
-
return [
|
|
598
|
-
...Object.values(LSP_PRESETS).map(preset => ({
|
|
599
|
-
value: preset.name,
|
|
600
|
-
description: `${preset.command} ${(preset.args ?? []).join(' ')} [${(preset.extensions ?? []).join(', ')}]`,
|
|
601
|
-
kind: 'lsp',
|
|
602
|
-
})),
|
|
603
|
-
{ value: 'custom', description: 'enter a name and command manually', kind: 'lsp' },
|
|
604
|
-
];
|
|
605
|
-
}
|
|
606
|
-
function mcpSuggestions() {
|
|
607
|
-
const servers = configuredMcpServers(settings);
|
|
608
|
-
return [{ value: 'add server', description: 'add an MCP server (presets available)', kind: 'mcp' },
|
|
609
|
-
...servers.map(server => {
|
|
610
|
-
const location = server.url ?? (server.command ? `${server.command} ${(server.args ?? []).join(' ')}`.trim() : '');
|
|
611
|
-
return { value: server.name, description: `${server.transport}${location ? ` ${location}` : ''} · ${server.enabled === false ? 'disabled' : 'enabled'}`, kind: 'mcp' };
|
|
612
|
-
})];
|
|
613
|
-
}
|
|
614
|
-
function mcpActionSuggestions() {
|
|
615
|
-
const server = selectedMcpName ? findMcpServer(settings, selectedMcpName) : undefined;
|
|
616
|
-
const result = [];
|
|
617
|
-
if (server) {
|
|
618
|
-
result.push({ value: server.enabled === false ? 'enable' : 'disable', description: `${server.enabled === false ? 'enable' : 'disable'} this server`, kind: 'mcp' });
|
|
619
|
-
result.push({ value: 'set API key', description: server.headers?.length ? 'update the saved API key' : 'add an API key', kind: 'mcp' });
|
|
620
|
-
}
|
|
621
|
-
result.push({ value: 'remove server', description: 'remove this server', kind: 'mcp' });
|
|
622
|
-
return result;
|
|
623
|
-
}
|
|
624
|
-
function mcpPresetSuggestions() {
|
|
625
|
-
return [
|
|
626
|
-
...presetIds().map(presetId => {
|
|
627
|
-
const preset = findMcpPreset(presetId);
|
|
628
|
-
return { value: presetId, description: preset.description ?? `${preset.transport} server`, kind: 'mcp' };
|
|
629
|
-
}),
|
|
630
|
-
{ value: 'custom', description: 'enter name, transport, and URL or command manually', kind: 'mcp' },
|
|
631
|
-
];
|
|
632
|
-
}
|
|
633
|
-
function mcpTransportSuggestions() {
|
|
634
|
-
return [
|
|
635
|
-
{ value: 'http', description: 'Streamable HTTP (remote)', kind: 'mcp' },
|
|
636
|
-
{ value: 'sse', description: 'Server-Sent Events (remote)', kind: 'mcp' },
|
|
637
|
-
{ value: 'stdio', description: 'local process', kind: 'mcp' },
|
|
638
|
-
];
|
|
639
|
-
}
|
|
640
|
-
function skillsSuggestions() {
|
|
641
|
-
return [{ value: 'add skill', description: 'describe a new skill for Haze to generate', kind: 'skill' },
|
|
642
|
-
...skills.map(skill => ({
|
|
643
|
-
value: skill.name,
|
|
644
|
-
description: `${skill.description}${isSkillEnabled(settings, skill.name) ? '' : ' · disabled'}`,
|
|
645
|
-
kind: 'skill',
|
|
646
|
-
}))];
|
|
647
|
-
}
|
|
648
|
-
function skillsActionSuggestions() {
|
|
649
|
-
const skill = selectedSkillName ? skills.find(candidate => candidate.name === selectedSkillName) : undefined;
|
|
650
|
-
const result = [];
|
|
651
|
-
if (skill) {
|
|
652
|
-
const enabled = isSkillEnabled(settings, skill.name);
|
|
653
|
-
result.push({ value: enabled ? 'disable' : 'enable', description: `${enabled ? 'disable' : 'enable'} this skill`, kind: 'skill' });
|
|
654
|
-
result.push({ value: 'show info', description: 'show description, references, and path', kind: 'skill' });
|
|
655
|
-
result.push({ value: 'validate', description: 're-load and validate SKILL.md', kind: 'skill' });
|
|
656
|
-
}
|
|
657
|
-
result.push({ value: 'remove skill', description: 'delete this skill directory', kind: 'skill' });
|
|
658
|
-
return result;
|
|
659
|
-
}
|
|
660
350
|
async function selectProvider(providerName) {
|
|
661
|
-
if (providerName ===
|
|
351
|
+
if (providerName === PROVIDER_CHOICES.addProvider) {
|
|
662
352
|
setProviderDraft({});
|
|
663
353
|
setMode('providerAddPreset');
|
|
664
354
|
setMessages(m => [...m, { role: 'system', text: 'Choose a provider preset, or select "custom" to enter details manually.' }]);
|
|
@@ -675,7 +365,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
675
365
|
setMessages(m => [...m, { role: 'system', text: `${provider.name}: choose an action.` }]);
|
|
676
366
|
}
|
|
677
367
|
async function selectPreset(presetId) {
|
|
678
|
-
if (presetId ===
|
|
368
|
+
if (presetId === PROVIDER_CHOICES.custom) {
|
|
679
369
|
setProviderDraft({});
|
|
680
370
|
setMode('providerAddName');
|
|
681
371
|
setMessages(m => [...m, { role: 'system', text: 'Provider name? Example: openrouter, local, lmstudio.' }]);
|
|
@@ -734,31 +424,16 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
734
424
|
setSelectedProviderName(undefined);
|
|
735
425
|
return;
|
|
736
426
|
}
|
|
737
|
-
if (action ===
|
|
427
|
+
if (action === PROVIDER_ACTIONS.useProvider) {
|
|
738
428
|
await useProvider(selectedProviderName);
|
|
739
429
|
return;
|
|
740
430
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
setMode('providerSetKey');
|
|
748
|
-
setMessages(m => [...m, { role: 'system', text: `New API key for ${selectedProviderName}? (current: ${provider.key ? 'saved' : 'not set'})` }]);
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
if (action === 'remove models') {
|
|
752
|
-
setMode('providerRemoveModels');
|
|
753
|
-
setMessages(m => [...m, { role: 'system', text: `Comma-separated model names to remove from ${selectedProviderName}?\nCurrent models: ${provider.models.join(', ')}` }]);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
if (action === 'remove provider') {
|
|
757
|
-
setMode('providerConfirmRemove');
|
|
758
|
-
setMessages(m => [...m, { role: 'system', text: `Remove provider ${selectedProviderName}? Type "yes" to confirm. Esc to cancel.` }]);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown provider action: ${action}` }]);
|
|
431
|
+
const actionResult = providerActionResult(action, provider);
|
|
432
|
+
if (actionResult.selectedName === undefined)
|
|
433
|
+
setSelectedProviderName(undefined);
|
|
434
|
+
if (actionResult.mode)
|
|
435
|
+
setMode(actionResult.mode);
|
|
436
|
+
showWizardMessage(actionResult.message);
|
|
762
437
|
}
|
|
763
438
|
async function selectModel(selector) {
|
|
764
439
|
const scopedSelector = modelProviderFilter ? `${modelProviderFilter}:${selector}` : selector;
|
|
@@ -778,327 +453,170 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
778
453
|
setMessages(m => [...m, { role: 'system', text: `Model set to ${resolved.model} on ${resolved.provider.name}.\n\n${startupProviderInfo(next)}` }]);
|
|
779
454
|
}
|
|
780
455
|
async function appendModelsToProvider(modelsValue) {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
setMessages(m => [...m, { role: 'system', text: 'No provider selected.' }]);
|
|
456
|
+
const result = providerAppendModels(settings, selectedProviderName, modelsValue);
|
|
457
|
+
if (!result.provider) {
|
|
458
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
785
459
|
setMode('chat');
|
|
786
460
|
return;
|
|
787
461
|
}
|
|
788
|
-
if (
|
|
789
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
462
|
+
if (!result.settingsPatch) {
|
|
463
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
790
464
|
return;
|
|
791
465
|
}
|
|
792
|
-
const
|
|
793
|
-
const next = await updateSettings({ providers: upsertProvider(settings, nextProvider), provider: provider.name });
|
|
466
|
+
const next = await updateSettings(result.settingsPatch);
|
|
794
467
|
setSettings(next);
|
|
795
468
|
setSelectedProviderName(undefined);
|
|
796
|
-
setModelProviderFilter(provider.name);
|
|
469
|
+
setModelProviderFilter(result.provider.name);
|
|
797
470
|
setMode('model');
|
|
798
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
471
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
799
472
|
}
|
|
800
473
|
async function finishProviderAdd(modelsValue) {
|
|
801
|
-
const
|
|
802
|
-
if (!
|
|
803
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
474
|
+
const result = providerFinishAdd(settings, providerDraft, modelsValue);
|
|
475
|
+
if (!result.provider || !result.settingsPatch) {
|
|
476
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
804
477
|
setMode('chat');
|
|
805
478
|
setProviderDraft({});
|
|
806
479
|
return;
|
|
807
480
|
}
|
|
808
|
-
const
|
|
809
|
-
name: providerDraft.name,
|
|
810
|
-
url: providerDraft.url,
|
|
811
|
-
...(providerDraft.key ? { key: providerDraft.key } : {}),
|
|
812
|
-
models: [...new Set(models)],
|
|
813
|
-
};
|
|
814
|
-
const next = await updateSettings({ providers: upsertProvider(settings, provider), provider: provider.name });
|
|
481
|
+
const next = await updateSettings(result.settingsPatch);
|
|
815
482
|
setSettings(next);
|
|
816
483
|
setProviderDraft({});
|
|
817
|
-
setModelProviderFilter(provider.name);
|
|
484
|
+
setModelProviderFilter(result.provider.name);
|
|
818
485
|
setMode('model');
|
|
819
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
486
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
820
487
|
}
|
|
821
488
|
// --- LSP wizard handlers (mirror the provider wizard) ---
|
|
489
|
+
function showWizardMessage(message) {
|
|
490
|
+
if (message)
|
|
491
|
+
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
492
|
+
}
|
|
822
493
|
async function selectLspServer(serverName) {
|
|
823
|
-
|
|
494
|
+
const result = selectLspServerResult(settings, serverName);
|
|
495
|
+
if (result.clearDraft)
|
|
824
496
|
setLspDraft({});
|
|
497
|
+
if (serverName === SERVER_CHOICES.addServer)
|
|
825
498
|
setMode('lspAddPreset');
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
setMessages(m => [...m, { role: 'system', text: `No LSP server named ${serverName}. Use /lsp and choose add server.` }]);
|
|
832
|
-
setMode('chat');
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
setSelectedLspName(server.name);
|
|
836
|
-
setMode('lspAction');
|
|
837
|
-
setMessages(m => [...m, { role: 'system', text: `${server.name}: choose an action.` }]);
|
|
499
|
+
else if (result.mode)
|
|
500
|
+
setMode(result.mode);
|
|
501
|
+
if (result.selectedName !== undefined)
|
|
502
|
+
setSelectedLspName(result.selectedName);
|
|
503
|
+
showWizardMessage(result.message);
|
|
838
504
|
}
|
|
839
505
|
async function selectLspPreset(presetId) {
|
|
840
|
-
|
|
506
|
+
const result = selectLspPresetResult(settings, presetId);
|
|
507
|
+
if (result.clearDraft)
|
|
841
508
|
setLspDraft({});
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
if (!preset) {
|
|
848
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown preset: ${presetId}.` }]);
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
if (configuredLspServers(settings).some(s => s.name === preset.name)) {
|
|
852
|
-
setMessages(m => [...m, { role: 'system', text: `LSP server ${preset.name} already exists. Use /lsp to manage existing servers.` }]);
|
|
853
|
-
setMode('chat');
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
const next = await updateSettings({ lspServers: upsertLspServer(settings, preset) });
|
|
857
|
-
setSettings(next);
|
|
858
|
-
setMode('chat');
|
|
859
|
-
setMessages(m => [...m, { role: 'system', text: `Added LSP preset ${preset.name}. Ensure ${preset.command} is installed and on PATH; tools appear once it is.` }]);
|
|
509
|
+
if (result.settingsPatch)
|
|
510
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
511
|
+
if (result.mode)
|
|
512
|
+
setMode(result.mode);
|
|
513
|
+
showWizardMessage(result.message);
|
|
860
514
|
}
|
|
861
515
|
async function selectLspAction(action) {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
if (
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
setSelectedLspName(undefined);
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
if (action === 'enable' || action === 'disable') {
|
|
874
|
-
const next = await updateSettings({ lspServers: setLspServerEnabled(settings, selectedLspName, action === 'enable') });
|
|
875
|
-
setSettings(next);
|
|
876
|
-
setMessages(m => [...m, { role: 'system', text: `LSP server ${selectedLspName} ${action === 'enable' ? 'enabled' : 'disabled'}.` }]);
|
|
877
|
-
setSelectedLspName(undefined);
|
|
878
|
-
setMode('chat');
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
if (action === 'remove server') {
|
|
882
|
-
setMode('lspConfirmRemove');
|
|
883
|
-
setMessages(m => [...m, { role: 'system', text: `Remove LSP server ${selectedLspName}? Type "yes" to confirm. Esc to cancel.` }]);
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown LSP action: ${action}` }]);
|
|
516
|
+
const result = selectLspActionResult(settings, selectedLspName, action);
|
|
517
|
+
if (result.settingsPatch)
|
|
518
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
519
|
+
if ('selectedName' in result)
|
|
520
|
+
setSelectedLspName(result.selectedName);
|
|
521
|
+
if (result.mode)
|
|
522
|
+
setMode(result.mode);
|
|
523
|
+
showWizardMessage(result.message);
|
|
887
524
|
}
|
|
888
525
|
async function finishLspCustom(commandLine) {
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
if (
|
|
893
|
-
setMessages(m => [...m, { role: 'system', text: 'LSP server name and command are required.' }]);
|
|
894
|
-
setMode('chat');
|
|
526
|
+
const result = finishLspCustomResult(settings, lspDraft.name, commandLine);
|
|
527
|
+
if (result.settingsPatch)
|
|
528
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
529
|
+
if (result.clearDraft)
|
|
895
530
|
setLspDraft({});
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
const next = await updateSettings({ lspServers: upsertLspServer(settings, server) });
|
|
900
|
-
setSettings(next);
|
|
901
|
-
setLspDraft({});
|
|
902
|
-
setMode('chat');
|
|
903
|
-
setMessages(m => [...m, { role: 'system', text: `Added LSP server ${name} (${command}${parts.length > 1 ? ` ${parts.slice(1).join(' ')}` : ''}). Add extensions in ~/.haze/settings.json so tools can auto-select it.` }]);
|
|
531
|
+
if (result.mode)
|
|
532
|
+
setMode(result.mode);
|
|
533
|
+
showWizardMessage(result.message);
|
|
904
534
|
}
|
|
905
535
|
// --- MCP wizard handlers (mirror the provider wizard) ---
|
|
906
536
|
async function selectMcpServer(serverName) {
|
|
907
|
-
|
|
537
|
+
const result = selectMcpServerResult(settings, serverName);
|
|
538
|
+
if (result.clearDraft)
|
|
908
539
|
setMcpDraft({});
|
|
540
|
+
if (serverName === SERVER_CHOICES.addServer)
|
|
909
541
|
setMode('mcpAddPreset');
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
setMessages(m => [...m, { role: 'system', text: `No MCP server named ${serverName}. Use /mcp and choose add server.` }]);
|
|
916
|
-
setMode('chat');
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
setSelectedMcpName(server.name);
|
|
920
|
-
setMode('mcpAction');
|
|
921
|
-
setMessages(m => [...m, { role: 'system', text: `${server.name}: choose an action.` }]);
|
|
542
|
+
else if (result.mode)
|
|
543
|
+
setMode(result.mode);
|
|
544
|
+
if (result.selectedName !== undefined)
|
|
545
|
+
setSelectedMcpName(result.selectedName);
|
|
546
|
+
showWizardMessage(result.message);
|
|
922
547
|
}
|
|
923
548
|
async function selectMcpPreset(presetId) {
|
|
924
|
-
|
|
549
|
+
const result = selectMcpPresetResult(settings, presetId);
|
|
550
|
+
if (result.clearDraft)
|
|
925
551
|
setMcpDraft({});
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (!preset) {
|
|
932
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown preset: ${presetId}.` }]);
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
if (findMcpServer(settings, presetId)) {
|
|
936
|
-
setMessages(m => [...m, { role: 'system', text: `MCP server ${presetId} already exists. Use /mcp to manage existing servers.` }]);
|
|
937
|
-
setMode('chat');
|
|
938
|
-
return;
|
|
939
|
-
}
|
|
940
|
-
setMcpDraft({ name: presetId, transport: preset.transport, ...(preset.url ? { url: preset.url } : {}) });
|
|
941
|
-
setMode('mcpAddKey');
|
|
942
|
-
setMessages(m => [...m, { role: 'system', text: `Adding ${presetId} (${preset.transport}${preset.url ? `, ${preset.url}` : ''}).\nOptional API key or auth header value? (Leave blank to skip — Enter works.)` }]);
|
|
552
|
+
if (result.draft)
|
|
553
|
+
setMcpDraft(result.draft);
|
|
554
|
+
if (result.mode)
|
|
555
|
+
setMode(result.mode);
|
|
556
|
+
showWizardMessage(result.message);
|
|
943
557
|
}
|
|
944
558
|
async function selectMcpAction(action) {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
if (
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
setSelectedMcpName(undefined);
|
|
954
|
-
return;
|
|
955
|
-
}
|
|
956
|
-
if (action === 'enable' || action === 'disable') {
|
|
957
|
-
const toggled = toggleMcpServer(settings, selectedMcpName, action === 'enable');
|
|
958
|
-
const next = await updateSettings({ mcpServers: toggled ?? [] });
|
|
959
|
-
setSettings(next);
|
|
960
|
-
setMessages(m => [...m, { role: 'system', text: `MCP server ${selectedMcpName} ${action === 'enable' ? 'enabled' : 'disabled'}.` }]);
|
|
961
|
-
setSelectedMcpName(undefined);
|
|
962
|
-
setMode('chat');
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
if (action === 'set API key') {
|
|
966
|
-
setMode('mcpSetKey');
|
|
967
|
-
setMessages(m => [...m, { role: 'system', text: `New API key for ${selectedMcpName}? (current: ${server.headers?.length ? 'saved' : 'not set'}) Sent as Authorization: Bearer <value>.` }]);
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
if (action === 'remove server') {
|
|
971
|
-
setMode('mcpConfirmRemove');
|
|
972
|
-
setMessages(m => [...m, { role: 'system', text: `Remove MCP server ${selectedMcpName}? Type "yes" to confirm. Esc to cancel.` }]);
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown MCP action: ${action}` }]);
|
|
559
|
+
const result = selectMcpActionResult(settings, selectedMcpName, action);
|
|
560
|
+
if (result.settingsPatch)
|
|
561
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
562
|
+
if ('selectedName' in result)
|
|
563
|
+
setSelectedMcpName(result.selectedName);
|
|
564
|
+
if (result.mode)
|
|
565
|
+
setMode(result.mode);
|
|
566
|
+
showWizardMessage(result.message);
|
|
976
567
|
}
|
|
977
568
|
async function finishMcpCustom(keyValue) {
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
setMode('chat');
|
|
569
|
+
const result = finishMcpCustomResult(settings, mcpDraft, keyValue);
|
|
570
|
+
if (result.settingsPatch)
|
|
571
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
572
|
+
if (result.clearDraft)
|
|
983
573
|
setMcpDraft({});
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
const server = transport === 'stdio'
|
|
988
|
-
? { name, transport, command: mcpDraft.command, args: mcpDraft.args, ...(headers ? { headers } : {}), enabled: true }
|
|
989
|
-
: { name, transport, url: mcpDraft.url, ...(headers ? { headers } : {}), enabled: true };
|
|
990
|
-
// Re-validate the transport-specific required field.
|
|
991
|
-
if (transport === 'stdio' && !server.command) {
|
|
992
|
-
setMessages(m => [...m, { role: 'system', text: 'Command is required for stdio transport.' }]);
|
|
993
|
-
setMode('chat');
|
|
994
|
-
setMcpDraft({});
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
if (transport !== 'stdio' && !server.url) {
|
|
998
|
-
setMessages(m => [...m, { role: 'system', text: `URL is required for ${transport} transport.` }]);
|
|
999
|
-
setMode('chat');
|
|
1000
|
-
setMcpDraft({});
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
1003
|
-
const next = await updateSettings({ mcpServers: upsertMcpServer(settings, server) });
|
|
1004
|
-
setSettings(next);
|
|
1005
|
-
setMcpDraft({});
|
|
1006
|
-
setMode('chat');
|
|
1007
|
-
const location = transport === 'stdio' ? `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''}` : server.url;
|
|
1008
|
-
setMessages(m => [...m, { role: 'system', text: `Added MCP server ${name} (${transport}, ${location}). Tools load on the next turn.` }]);
|
|
574
|
+
if (result.mode)
|
|
575
|
+
setMode(result.mode);
|
|
576
|
+
showWizardMessage(result.message);
|
|
1009
577
|
}
|
|
1010
578
|
async function setMcpServerKey(keyValue) {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
setSelectedMcpName(undefined);
|
|
1020
|
-
return;
|
|
1021
|
-
}
|
|
1022
|
-
const key = keyValue.trim();
|
|
1023
|
-
if (!key) {
|
|
1024
|
-
setMessages(m => [...m, { role: 'system', text: 'API key cannot be empty. Esc to cancel.' }]);
|
|
1025
|
-
return;
|
|
1026
|
-
}
|
|
1027
|
-
const headers = (server.headers ?? []).filter(header => header.name !== 'Authorization');
|
|
1028
|
-
headers.push({ name: 'Authorization', value: `Bearer ${key}` });
|
|
1029
|
-
const next = await updateSettings({ mcpServers: upsertMcpServer(settings, { ...server, headers }) });
|
|
1030
|
-
setSettings(next);
|
|
1031
|
-
setSelectedMcpName(undefined);
|
|
1032
|
-
setMode('chat');
|
|
1033
|
-
setMessages(m => [...m, { role: 'system', text: `API key updated for ${server.name}.` }]);
|
|
579
|
+
const result = setMcpServerKeyResult(settings, selectedMcpName, keyValue);
|
|
580
|
+
if (result.settingsPatch)
|
|
581
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
582
|
+
if ('selectedName' in result)
|
|
583
|
+
setSelectedMcpName(result.selectedName);
|
|
584
|
+
if (result.mode)
|
|
585
|
+
setMode(result.mode);
|
|
586
|
+
showWizardMessage(result.message);
|
|
1034
587
|
}
|
|
1035
588
|
// --- Skills wizard handlers (mirror the provider/LSP/MCP wizards) ---
|
|
1036
589
|
async function selectSkill(name) {
|
|
1037
|
-
|
|
590
|
+
const result = selectSkillResult(skills, name);
|
|
591
|
+
if (result.clearDraft)
|
|
1038
592
|
setSkillDraft({});
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
if (!skill) {
|
|
1045
|
-
setMessages(m => [...m, { role: 'system', text: `No skill named ${name}. Use /skills and choose add skill.` }]);
|
|
1046
|
-
setMode('chat');
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
setSelectedSkillName(skill.name);
|
|
1050
|
-
setMode('skillsAction');
|
|
1051
|
-
setMessages(m => [...m, { role: 'system', text: `${skill.name}: choose an action.` }]);
|
|
593
|
+
if ('selectedName' in result)
|
|
594
|
+
setSelectedSkillName(result.selectedName);
|
|
595
|
+
if (result.mode)
|
|
596
|
+
setMode(result.mode);
|
|
597
|
+
showWizardMessage(result.message);
|
|
1052
598
|
}
|
|
1053
599
|
async function selectSkillAction(action) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
setSelectedSkillName(undefined);
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
if (action === 'enable' || action === 'disable') {
|
|
1066
|
-
const next = await updateSettings({ skills: setSkillEnabled(settings, selectedSkillName, action === 'enable') });
|
|
1067
|
-
setSettings(next);
|
|
1068
|
-
setMessages(m => [...m, { role: 'system', text: `Skill ${selectedSkillName} ${action === 'enable' ? 'enabled' : 'disabled'}.` }]);
|
|
1069
|
-
setSelectedSkillName(undefined);
|
|
1070
|
-
setMode('chat');
|
|
1071
|
-
return;
|
|
1072
|
-
}
|
|
1073
|
-
if (action === 'show info') {
|
|
1074
|
-
setMessages(m => [...m, { role: 'system', text: [
|
|
1075
|
-
`${skill.name}`,
|
|
1076
|
-
skill.description,
|
|
1077
|
-
'',
|
|
1078
|
-
`References: ${skill.references.length}`,
|
|
1079
|
-
`Path: ${skill.dir}`,
|
|
1080
|
-
`State: ${isSkillEnabled(settings, skill.name) ? 'enabled' : 'disabled'}`,
|
|
1081
|
-
].join('\n') }]);
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
if (action === 'validate') {
|
|
600
|
+
const result = selectSkillActionResult(settings, skills, selectedSkillName, action);
|
|
601
|
+
if (result.settingsPatch)
|
|
602
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
603
|
+
if ('selectedName' in result)
|
|
604
|
+
setSelectedSkillName(result.selectedName);
|
|
605
|
+
if (result.mode)
|
|
606
|
+
setMode(result.mode);
|
|
607
|
+
if (result.validate && result.skill) {
|
|
1085
608
|
const { loadSkill } = await import('../../skills/SkillLoader.js');
|
|
1086
609
|
try {
|
|
1087
|
-
const loaded = await loadSkill(skill.dir, 'global');
|
|
1088
|
-
|
|
610
|
+
const loaded = await loadSkill(result.skill.dir, 'global');
|
|
611
|
+
showWizardMessage(loaded ? `Valid: ${loaded.name}` : 'No SKILL.md found');
|
|
1089
612
|
}
|
|
1090
613
|
catch (error) {
|
|
1091
614
|
const text = error instanceof Error ? error.message : String(error);
|
|
1092
|
-
|
|
615
|
+
showWizardMessage(`Invalid skill: ${text}`);
|
|
1093
616
|
}
|
|
1094
617
|
return;
|
|
1095
618
|
}
|
|
1096
|
-
|
|
1097
|
-
setMode('skillsConfirmRemove');
|
|
1098
|
-
setMessages(m => [...m, { role: 'system', text: `Remove skill ${selectedSkillName}? This deletes ~/.haze/skills/${selectedSkillName}. Type "yes" to confirm. Esc to cancel.` }]);
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown skill action: ${action}` }]);
|
|
619
|
+
showWizardMessage(result.message);
|
|
1102
620
|
}
|
|
1103
621
|
async function captureSkillName(value) {
|
|
1104
622
|
const dirName = toSkillDirName(value);
|
|
@@ -1116,34 +634,32 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1116
634
|
setMessages(m => [...m, { role: 'system', text: `Describe what "${dirName}" should do. This is the work the LLM will expand into the skill body.` }]);
|
|
1117
635
|
}
|
|
1118
636
|
async function captureSkillDescription(value) {
|
|
1119
|
-
const
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
|
|
637
|
+
const result = captureSkillDescriptionResult(value, skillDraft.name);
|
|
638
|
+
if (result.message) {
|
|
639
|
+
const message = result.message;
|
|
640
|
+
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
1123
641
|
}
|
|
1124
|
-
|
|
1125
|
-
if (!name) {
|
|
642
|
+
if (result.mode === 'chat')
|
|
1126
643
|
setMode('chat');
|
|
644
|
+
if (result.clearDraft)
|
|
1127
645
|
setSkillDraft({});
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
setBusy(false);
|
|
1146
|
-
setBusyLabel('Haze is thinking');
|
|
646
|
+
if (result.description && result.draftName) {
|
|
647
|
+
const name = result.draftName;
|
|
648
|
+
const description = result.description;
|
|
649
|
+
setBusyLabel(result.busyLabel ?? 'Creating skill');
|
|
650
|
+
setBusy(true);
|
|
651
|
+
try {
|
|
652
|
+
const created = await createSkill({ name, description });
|
|
653
|
+
setMessages(m => [...m, { role: 'system', text: skillCreationMessage(created.name, created.file) }]);
|
|
654
|
+
await refreshSkills();
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
setMessages(m => [...m, { role: 'system', text: skillCreationFailure(error) }]);
|
|
658
|
+
}
|
|
659
|
+
finally {
|
|
660
|
+
setBusy(false);
|
|
661
|
+
setBusyLabel('Haze is thinking');
|
|
662
|
+
}
|
|
1147
663
|
}
|
|
1148
664
|
}
|
|
1149
665
|
async function submit(value) {
|
|
@@ -1169,30 +685,21 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1169
685
|
return;
|
|
1170
686
|
}
|
|
1171
687
|
if (mode === 'skillsConfirmRemove') {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
if (value.trim().toLowerCase() !== 'yes') {
|
|
1177
|
-
setMessages(m => [...m, { role: 'system', text: 'Cancelled. Skill not removed.' }]);
|
|
1178
|
-
setSelectedSkillName(undefined);
|
|
1179
|
-
setMode('chat');
|
|
1180
|
-
return;
|
|
688
|
+
const result = skillConfirmRemove(settings, skills, selectedSkillName, value);
|
|
689
|
+
if (result.message) {
|
|
690
|
+
const message = result.message;
|
|
691
|
+
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
1181
692
|
}
|
|
1182
|
-
|
|
1183
|
-
if (!skill) {
|
|
1184
|
-
setMessages(m => [...m, { role: 'system', text: `Skill ${selectedSkillName} not found.` }]);
|
|
693
|
+
if (result.selectedName === undefined)
|
|
1185
694
|
setSelectedSkillName(undefined);
|
|
695
|
+
if (result.mode === 'chat')
|
|
1186
696
|
setMode('chat');
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
setSelectedSkillName(undefined);
|
|
1194
|
-
setMode('chat');
|
|
1195
|
-
await refreshSkills();
|
|
697
|
+
if (result.removedDir)
|
|
698
|
+
await fs.remove(result.removedDir);
|
|
699
|
+
if (result.settingsPatch)
|
|
700
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
701
|
+
if (result.removedDir)
|
|
702
|
+
await refreshSkills();
|
|
1196
703
|
return;
|
|
1197
704
|
}
|
|
1198
705
|
if (mode === 'provider') {
|
|
@@ -1212,31 +719,29 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1212
719
|
return;
|
|
1213
720
|
}
|
|
1214
721
|
if (mode === 'providerAddName') {
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1217
|
-
|
|
722
|
+
const result = captureProviderName(settings, value);
|
|
723
|
+
if (result.message) {
|
|
724
|
+
showWizardMessage(result.message);
|
|
1218
725
|
return;
|
|
1219
726
|
}
|
|
1220
|
-
if (
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
setMode('providerAddUrl');
|
|
1226
|
-
setMessages(m => [...m, { role: 'system', text: 'OpenAI-compatible base URL? Example: https://openrouter.ai/api/v1 or http://localhost:1234/v1' }]);
|
|
727
|
+
if (result.draft)
|
|
728
|
+
setProviderDraft({ name: result.draft.name });
|
|
729
|
+
if (result.nextMode)
|
|
730
|
+
setMode(result.nextMode);
|
|
731
|
+
showWizardMessage(result.systemMessage);
|
|
1227
732
|
return;
|
|
1228
733
|
}
|
|
1229
734
|
if (mode === 'providerAddUrl') {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
catch {
|
|
1234
|
-
setMessages(m => [...m, { role: 'system', text: 'Enter a valid URL, for example http://localhost:1234/v1.' }]);
|
|
735
|
+
const result = captureProviderUrl(value);
|
|
736
|
+
if (result.message) {
|
|
737
|
+
showWizardMessage(result.message);
|
|
1235
738
|
return;
|
|
1236
739
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
740
|
+
if (result.draft)
|
|
741
|
+
setProviderDraft(draft => ({ ...draft, ...result.draft }));
|
|
742
|
+
if (result.nextMode)
|
|
743
|
+
setMode(result.nextMode);
|
|
744
|
+
showWizardMessage(result.systemMessage);
|
|
1240
745
|
return;
|
|
1241
746
|
}
|
|
1242
747
|
if (mode === 'providerAddKey') {
|
|
@@ -1254,59 +759,38 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1254
759
|
return;
|
|
1255
760
|
}
|
|
1256
761
|
if (mode === 'providerSetKey') {
|
|
1257
|
-
const
|
|
1258
|
-
if (!provider) {
|
|
1259
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
762
|
+
const result = providerSetKey(settings, selectedProviderName, value);
|
|
763
|
+
if (!result.provider) {
|
|
764
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1260
765
|
setMode('chat');
|
|
1261
766
|
return;
|
|
1262
767
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
setMessages(m => [...m, { role: 'system', text: 'API key cannot be empty. Esc to cancel.' }]);
|
|
768
|
+
if (!result.settingsPatch) {
|
|
769
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1266
770
|
return;
|
|
1267
771
|
}
|
|
1268
|
-
|
|
1269
|
-
const next = await updateSettings({ providers: upsertProvider(settings, updated) });
|
|
1270
|
-
setSettings(next);
|
|
772
|
+
setSettings(await updateSettings(result.settingsPatch));
|
|
1271
773
|
setSelectedProviderName(undefined);
|
|
1272
774
|
setMode('chat');
|
|
1273
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
775
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1274
776
|
return;
|
|
1275
777
|
}
|
|
1276
778
|
if (mode === 'providerRemoveModels') {
|
|
1277
|
-
const
|
|
1278
|
-
if (!provider) {
|
|
1279
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
779
|
+
const result = providerRemoveModels(settings, selectedProviderName, value);
|
|
780
|
+
if (!result.provider) {
|
|
781
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1280
782
|
setMode('chat');
|
|
1281
783
|
return;
|
|
1282
784
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
setMessages(m => [...m, { role: 'system', text: 'Enter at least one model name. Esc to cancel.' }]);
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
const remaining = provider.models.filter(m => !toRemove.includes(m));
|
|
1289
|
-
if (remaining.length === 0) {
|
|
1290
|
-
setMessages(m => [...m, { role: 'system', text: 'A provider must have at least one model. Remove the provider instead.' }]);
|
|
785
|
+
if (!result.settingsPatch) {
|
|
786
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1291
787
|
return;
|
|
1292
788
|
}
|
|
1293
|
-
const
|
|
1294
|
-
const notFound = toRemove.filter(m => !provider.models.includes(m));
|
|
1295
|
-
const updated = { ...provider, models: remaining };
|
|
1296
|
-
const wasActive = settings.model && provider.models.includes(settings.model) && !remaining.includes(settings.model);
|
|
1297
|
-
const next = await updateSettings({
|
|
1298
|
-
providers: upsertProvider(settings, updated),
|
|
1299
|
-
...(wasActive ? { model: remaining[0] } : {}),
|
|
1300
|
-
});
|
|
789
|
+
const next = await updateSettings(result.settingsPatch);
|
|
1301
790
|
setSettings(next);
|
|
1302
791
|
setSelectedProviderName(undefined);
|
|
1303
792
|
setMode('chat');
|
|
1304
|
-
|
|
1305
|
-
if (notFound.length)
|
|
1306
|
-
parts.push(`Not found: ${notFound.join(', ')}.`);
|
|
1307
|
-
if (wasActive)
|
|
1308
|
-
parts.push(`Active model updated to ${remaining[0]}.`);
|
|
1309
|
-
setMessages(m => [...m, { role: 'system', text: parts.join(' ') }]);
|
|
793
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1310
794
|
return;
|
|
1311
795
|
}
|
|
1312
796
|
if (mode === 'providerConfirmRemove') {
|
|
@@ -1316,22 +800,18 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1316
800
|
setMode('chat');
|
|
1317
801
|
return;
|
|
1318
802
|
}
|
|
1319
|
-
if (value
|
|
803
|
+
if (!isYesConfirmation(value)) {
|
|
1320
804
|
setMessages(m => [...m, { role: 'system', text: 'Cancelled. Provider not removed.' }]);
|
|
1321
805
|
setSelectedProviderName(undefined);
|
|
1322
806
|
setMode('chat');
|
|
1323
807
|
return;
|
|
1324
808
|
}
|
|
1325
|
-
const
|
|
1326
|
-
const
|
|
1327
|
-
const next = await updateSettings({
|
|
1328
|
-
providers,
|
|
1329
|
-
...(wasActiveProvider ? { provider: providers[0]?.name, model: providers[0]?.models[0] } : {}),
|
|
1330
|
-
});
|
|
809
|
+
const result = providerRemove(settings, selectedProviderName);
|
|
810
|
+
const next = await updateSettings(result.settingsPatch ?? {});
|
|
1331
811
|
setSettings(next);
|
|
1332
812
|
setSelectedProviderName(undefined);
|
|
1333
813
|
setMode('chat');
|
|
1334
|
-
setMessages(m => [...m, { role: 'system', text:
|
|
814
|
+
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
1335
815
|
return;
|
|
1336
816
|
}
|
|
1337
817
|
if (mode === 'lsp') {
|
|
@@ -1347,18 +827,16 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1347
827
|
return;
|
|
1348
828
|
}
|
|
1349
829
|
if (mode === 'lspAddName') {
|
|
1350
|
-
const
|
|
1351
|
-
if (
|
|
1352
|
-
|
|
1353
|
-
return;
|
|
1354
|
-
}
|
|
1355
|
-
if (configuredLspServers(settings).some(s => s.name === name)) {
|
|
1356
|
-
setMessages(m => [...m, { role: 'system', text: `LSP server ${name} already exists. Choose a unique name.` }]);
|
|
830
|
+
const result = captureLspName(settings, value);
|
|
831
|
+
if (result.message) {
|
|
832
|
+
showWizardMessage(result.message);
|
|
1357
833
|
return;
|
|
1358
834
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
835
|
+
if (result.draft)
|
|
836
|
+
setLspDraft({ name: result.draft.name });
|
|
837
|
+
if (result.nextMode)
|
|
838
|
+
setMode(result.nextMode);
|
|
839
|
+
showWizardMessage(result.systemMessage);
|
|
1362
840
|
return;
|
|
1363
841
|
}
|
|
1364
842
|
if (mode === 'lspAddCommand') {
|
|
@@ -1370,7 +848,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1370
848
|
setMode('chat');
|
|
1371
849
|
return;
|
|
1372
850
|
}
|
|
1373
|
-
if (value
|
|
851
|
+
if (!isYesConfirmation(value)) {
|
|
1374
852
|
setMessages(m => [...m, { role: 'system', text: 'Cancelled. LSP server not removed.' }]);
|
|
1375
853
|
setSelectedLspName(undefined);
|
|
1376
854
|
setMode('chat');
|
|
@@ -1396,59 +874,55 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1396
874
|
return;
|
|
1397
875
|
}
|
|
1398
876
|
if (mode === 'mcpAddName') {
|
|
1399
|
-
const
|
|
1400
|
-
if (
|
|
1401
|
-
|
|
877
|
+
const result = captureMcpName(settings, value);
|
|
878
|
+
if (result.message) {
|
|
879
|
+
showWizardMessage(result.message);
|
|
1402
880
|
return;
|
|
1403
881
|
}
|
|
1404
|
-
if (
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
setMode('mcpAddTransport');
|
|
1410
|
-
setMessages(m => [...m, { role: 'system', text: 'Transport type? http (Streamable HTTP), sse (Server-Sent Events), or stdio (local process).' }]);
|
|
882
|
+
if (result.draft)
|
|
883
|
+
setMcpDraft({ name: result.draft.name });
|
|
884
|
+
if (result.nextMode)
|
|
885
|
+
setMode(result.nextMode);
|
|
886
|
+
showWizardMessage(result.systemMessage);
|
|
1411
887
|
return;
|
|
1412
888
|
}
|
|
1413
889
|
if (mode === 'mcpAddTransport') {
|
|
1414
|
-
const
|
|
1415
|
-
if (
|
|
1416
|
-
|
|
890
|
+
const result = captureMcpTransport(value);
|
|
891
|
+
if (result.message) {
|
|
892
|
+
showWizardMessage(result.message);
|
|
1417
893
|
return;
|
|
1418
894
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
else {
|
|
1425
|
-
setMode('mcpAddUrl');
|
|
1426
|
-
setMessages(m => [...m, { role: 'system', text: `MCP server URL? Example: https://mcp.context7.com/mcp for ${transport}.` }]);
|
|
1427
|
-
}
|
|
895
|
+
if (result.draft)
|
|
896
|
+
setMcpDraft(draft => ({ ...draft, ...result.draft }));
|
|
897
|
+
if (result.nextMode)
|
|
898
|
+
setMode(result.nextMode);
|
|
899
|
+
showWizardMessage(result.systemMessage);
|
|
1428
900
|
return;
|
|
1429
901
|
}
|
|
1430
902
|
if (mode === 'mcpAddUrl') {
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
catch {
|
|
1435
|
-
setMessages(m => [...m, { role: 'system', text: 'Enter a valid URL, for example https://mcp.context7.com/mcp.' }]);
|
|
903
|
+
const result = captureMcpUrl(value);
|
|
904
|
+
if (result.message) {
|
|
905
|
+
showWizardMessage(result.message);
|
|
1436
906
|
return;
|
|
1437
907
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
908
|
+
if (result.draft)
|
|
909
|
+
setMcpDraft(draft => ({ ...draft, ...result.draft }));
|
|
910
|
+
if (result.nextMode)
|
|
911
|
+
setMode(result.nextMode);
|
|
912
|
+
showWizardMessage(result.systemMessage);
|
|
1441
913
|
return;
|
|
1442
914
|
}
|
|
1443
915
|
if (mode === 'mcpAddCommand') {
|
|
1444
|
-
const
|
|
1445
|
-
if (
|
|
1446
|
-
|
|
916
|
+
const result = captureMcpCommand(value);
|
|
917
|
+
if (result.message) {
|
|
918
|
+
showWizardMessage(result.message);
|
|
1447
919
|
return;
|
|
1448
920
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
921
|
+
if (result.draft)
|
|
922
|
+
setMcpDraft(draft => ({ ...draft, ...result.draft }));
|
|
923
|
+
if (result.nextMode)
|
|
924
|
+
setMode(result.nextMode);
|
|
925
|
+
showWizardMessage(result.systemMessage);
|
|
1452
926
|
return;
|
|
1453
927
|
}
|
|
1454
928
|
if (mode === 'mcpAddKey') {
|
|
@@ -1464,7 +938,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1464
938
|
setMode('chat');
|
|
1465
939
|
return;
|
|
1466
940
|
}
|
|
1467
|
-
if (value
|
|
941
|
+
if (!isYesConfirmation(value)) {
|
|
1468
942
|
setMessages(m => [...m, { role: 'system', text: 'Cancelled. MCP server not removed.' }]);
|
|
1469
943
|
setSelectedMcpName(undefined);
|
|
1470
944
|
setMode('chat');
|
|
@@ -1501,7 +975,12 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1501
975
|
sessionInfo: () => sessionRef.current ? formatSession(sessionRef.current) : 'Session persistence is off.',
|
|
1502
976
|
compactConversation,
|
|
1503
977
|
runAgentTurn: (prompt, displayValue) => doAgentTurn(prompt, displayValue),
|
|
1504
|
-
refreshContextFiles: async () => {
|
|
978
|
+
refreshContextFiles: async () => {
|
|
979
|
+
const files = await readContextFiles().catch(() => contextFiles);
|
|
980
|
+
setContextFiles(files);
|
|
981
|
+
contextFileSignaturesRef.current = new Map(files.flatMap(file => file.signature ? [[file.path, file.signature]] : []));
|
|
982
|
+
return files;
|
|
983
|
+
},
|
|
1505
984
|
updateSettings: async (patch) => {
|
|
1506
985
|
const next = await updateSettings(patch);
|
|
1507
986
|
setSettings(next);
|
|
@@ -1533,7 +1012,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1533
1012
|
// When every task is already completed, start the new turn with a clean
|
|
1534
1013
|
// slate: the task bar clears (nothing shown for simple questions) and the
|
|
1535
1014
|
// model may create fresh todos via writeTasks if the new question warrants.
|
|
1536
|
-
if (visibleTasks
|
|
1015
|
+
if (shouldClearCompletedTasks(visibleTasks)) {
|
|
1537
1016
|
setVisibleTasks([]);
|
|
1538
1017
|
setTasksExpanded(false);
|
|
1539
1018
|
setTaskBarPadding(0);
|
|
@@ -1549,17 +1028,13 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1549
1028
|
}
|
|
1550
1029
|
}
|
|
1551
1030
|
async function runSingleAgentTurn(value, displayValue) {
|
|
1552
|
-
const
|
|
1553
|
-
const session = sessionRef.current;
|
|
1554
|
-
if (session)
|
|
1555
|
-
void appendSessionEntry(session, { type: 'ui_message', at: new Date().toISOString(), role: msg.role, text: msg.text }).catch(() => undefined);
|
|
1556
|
-
};
|
|
1031
|
+
const sessionRecorder = createSessionRecorder(() => sessionRef.current);
|
|
1557
1032
|
const finalizeMessage = (msg) => {
|
|
1558
1033
|
if (msg.hidden)
|
|
1559
1034
|
return;
|
|
1560
1035
|
const ordered = withDisplayOrder(msg);
|
|
1561
1036
|
setMessages(m => [...m, ordered]);
|
|
1562
|
-
|
|
1037
|
+
sessionRecorder.recordUiMessage(ordered);
|
|
1563
1038
|
};
|
|
1564
1039
|
await runAgentTurn(value, displayValue, contextFiles, {
|
|
1565
1040
|
addMessage: msg => {
|
|
@@ -1586,9 +1061,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1586
1061
|
},
|
|
1587
1062
|
setConversation: msgs => {
|
|
1588
1063
|
conversationRef.current = msgs;
|
|
1589
|
-
|
|
1590
|
-
if (session)
|
|
1591
|
-
void appendSessionEntry(session, { type: 'conversation_snapshot', at: new Date().toISOString(), messages: msgs }).catch(() => undefined);
|
|
1064
|
+
sessionRecorder.recordConversation(msgs);
|
|
1592
1065
|
},
|
|
1593
1066
|
setBusy,
|
|
1594
1067
|
setBusyLabel,
|
|
@@ -1600,80 +1073,27 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1600
1073
|
setGoalStatus: setActiveGoalStatus,
|
|
1601
1074
|
setWorkState: state => {
|
|
1602
1075
|
workStateRef.current = state;
|
|
1603
|
-
|
|
1604
|
-
if (session)
|
|
1605
|
-
void appendSessionEntry(session, { type: 'work_state_snapshot', at: new Date().toISOString(), state }).catch(() => undefined);
|
|
1076
|
+
sessionRecorder.recordWorkState(state);
|
|
1606
1077
|
},
|
|
1607
1078
|
compactConversation,
|
|
1608
1079
|
recordTokenUsage: usage => {
|
|
1609
|
-
setTokenUsage(current => (
|
|
1610
|
-
inputTokens: (current.inputTokens ?? 0) + (usage.inputTokens ?? 0) || usage.inputTokens,
|
|
1611
|
-
outputTokens: (current.outputTokens ?? 0) + (usage.outputTokens ?? 0) || usage.outputTokens,
|
|
1612
|
-
systemPrompt: current.systemPrompt + usage.systemPrompt,
|
|
1613
|
-
messages: current.messages + usage.messages,
|
|
1614
|
-
toolSchemas: current.toolSchemas + usage.toolSchemas,
|
|
1615
|
-
outputEstimate: current.outputEstimate + usage.outputEstimate,
|
|
1616
|
-
cacheReadTokens: current.cacheReadTokens + usage.cacheReadTokens,
|
|
1617
|
-
cacheWriteTokens: current.cacheWriteTokens + usage.cacheWriteTokens,
|
|
1618
|
-
noCacheTokens: current.noCacheTokens + usage.noCacheTokens,
|
|
1619
|
-
reasoningTokens: current.reasoningTokens + usage.reasoningTokens,
|
|
1620
|
-
logicalInputEstimate: current.logicalInputEstimate + usage.logicalInputEstimate,
|
|
1621
|
-
effectiveNonCachedInput: (current.effectiveNonCachedInput ?? 0) + (usage.effectiveNonCachedInput ?? 0) || usage.effectiveNonCachedInput,
|
|
1622
|
-
}));
|
|
1080
|
+
setTokenUsage(current => accumulateTokenUsage(current, usage));
|
|
1623
1081
|
},
|
|
1624
1082
|
onEvent: event => {
|
|
1625
|
-
|
|
1626
|
-
if (session)
|
|
1627
|
-
void appendSessionEntry(session, { type: 'event', at: event.at, name: event.type, text: JSON.stringify(event) }).catch(() => undefined);
|
|
1083
|
+
sessionRecorder.recordEvent(event);
|
|
1628
1084
|
},
|
|
1629
1085
|
onTasksChanged: () => { loadTasksFromStore().then(t => { setVisibleTasks(t); setTaskBarPadding(0); }).catch(() => undefined); },
|
|
1086
|
+
contextFileSignatures: contextFileSignaturesRef.current,
|
|
1630
1087
|
log: llmLogRef.current,
|
|
1631
1088
|
}, 0, false, false, { start: sessionStartRef.current, cwd: process.cwd() });
|
|
1632
1089
|
}
|
|
1633
1090
|
const visible = messages.filter(message => !message.hidden);
|
|
1634
1091
|
const activeLiveMessages = liveMessages.filter(message => !message.hidden);
|
|
1635
1092
|
const orderedVisibleMessages = orderedDisplayMessages([...visible, ...activeLiveMessages]);
|
|
1636
|
-
const
|
|
1637
|
-
const
|
|
1638
|
-
const transcriptItems = staticDisplayItems.map((item, index) => ({ key: messageKey(item.message, index), ...item }));
|
|
1639
|
-
const activeLiveItems = annotatedDisplayMessages.filter(item => item.message.streaming);
|
|
1093
|
+
const transcriptItems = orderedVisibleMessages.filter(message => !message.streaming).map((message, index) => ({ key: messageKey(message, index), message }));
|
|
1094
|
+
const streamingItems = orderedVisibleMessages.filter(message => message.streaming);
|
|
1640
1095
|
const activeSelection = activeModel(settings);
|
|
1641
|
-
const
|
|
1642
|
-
provider: 'Choose provider',
|
|
1643
|
-
providerAction: 'Choose provider action',
|
|
1644
|
-
providerAddPreset: 'Choose a provider preset or custom',
|
|
1645
|
-
model: 'Choose model',
|
|
1646
|
-
providerAddName: 'Provider name',
|
|
1647
|
-
providerAddUrl: 'https://example.com/v1',
|
|
1648
|
-
providerAddKey: 'API key, or blank for local',
|
|
1649
|
-
providerSetKey: 'API key',
|
|
1650
|
-
providerAddModels: 'model-a, model-b',
|
|
1651
|
-
providerAppendModels: 'model-a, model-b',
|
|
1652
|
-
providerRemoveModels: 'model-a, model-b',
|
|
1653
|
-
providerConfirmRemove: 'Type "yes" to confirm',
|
|
1654
|
-
skills: 'Choose a skill or add skill',
|
|
1655
|
-
skillsAction: 'show info, enable, disable, validate, or remove',
|
|
1656
|
-
skillsAddName: 'Skill name (kebab-case, e.g. security-review)',
|
|
1657
|
-
skillsAddDescription: 'Describe what the skill should do',
|
|
1658
|
-
skillsConfirmRemove: 'Type "yes" to confirm',
|
|
1659
|
-
lsp: 'Choose LSP server or add server',
|
|
1660
|
-
lspAction: 'enable, disable, or remove server',
|
|
1661
|
-
lspAddPreset: 'Choose an LSP preset or custom',
|
|
1662
|
-
lspAddName: 'LSP server name (e.g. typescript)',
|
|
1663
|
-
lspAddCommand: 'Command (e.g. typescript-language-server --stdio)',
|
|
1664
|
-
lspConfirmRemove: 'Type "yes" to confirm',
|
|
1665
|
-
mcp: 'Choose MCP server or add server',
|
|
1666
|
-
mcpAction: 'enable, disable, remove, or set key',
|
|
1667
|
-
mcpAddPreset: 'Choose an MCP preset or custom',
|
|
1668
|
-
mcpAddName: 'MCP server name (e.g. context7)',
|
|
1669
|
-
mcpAddTransport: 'http, sse, or stdio',
|
|
1670
|
-
mcpAddUrl: 'https://mcp.example.com/mcp',
|
|
1671
|
-
mcpAddCommand: 'Command (e.g. npx -y @pkg/server)',
|
|
1672
|
-
mcpAddKey: 'API key, or blank to skip',
|
|
1673
|
-
mcpSetKey: 'API key',
|
|
1674
|
-
mcpConfirmRemove: 'Type "yes" to confirm',
|
|
1675
|
-
};
|
|
1676
|
-
const placeholder = PLACEHOLDERS[mode] ?? (busy ? 'Queue a follow-up, or Esc to interrupt' : 'Ask Haze to help build your app');
|
|
1096
|
+
const placeholder = placeholderForMode(mode, busy);
|
|
1677
1097
|
const activeModelName = activeSelection ? `${activeSelection.provider.name}:${activeSelection.model}` : 'unconfigured';
|
|
1678
1098
|
const headerSubtitle = [
|
|
1679
1099
|
'A minimal LLM harness for growing your own workflows while you work.',
|
|
@@ -1700,35 +1120,14 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1700
1120
|
const enabledSkills = skills.filter(skill => isSkillEnabled(settings, skill.name));
|
|
1701
1121
|
const statusDetailLabel = `${hazeMessages} haze message${hazeMessages === 1 ? '' : 's'} / ${toolsUsed} tool call${toolsUsed === 1 ? '' : 's'} / LLM ${inputEstimated ? '~' : ''}↑${formatTokenCount(effectiveInput)} ${outputEstimated ? '~' : ''}↓${formatTokenCount(effectiveOutput)} / ${enabledSkills.length} skill${enabledSkills.length === 1 ? '' : 's'}`;
|
|
1702
1122
|
const hasTokenBreakdown = tokenUsage.systemPrompt > 0 || tokenUsage.messages > 0 || tokenUsage.toolSchemas > 0 || effectiveInput > 0 || effectiveOutput > 0;
|
|
1703
|
-
const
|
|
1704
|
-
// Goal tracking is internal; display removed in favor of task bar
|
|
1705
|
-
void goalText;
|
|
1706
|
-
const inputSuggestions = mode === 'provider' ? providerSuggestions() : mode === 'providerAction' ? providerActionSuggestions() : mode === 'providerAddPreset' ? presetSuggestions() : mode === 'model' ? modelSuggestions() : mode === 'skills' ? skillsSuggestions() : mode === 'skillsAction' ? skillsActionSuggestions() : mode === 'lsp' ? lspSuggestions() : mode === 'lspAction' ? lspActionSuggestions() : mode === 'lspAddPreset' ? lspPresetSuggestions() : mode === 'mcp' ? mcpSuggestions() : mode === 'mcpAction' ? mcpActionSuggestions() : mode === 'mcpAddPreset' ? mcpPresetSuggestions() : mode === 'mcpAddTransport' ? mcpTransportSuggestions() : mode === 'chat' ? [
|
|
1707
|
-
{ value: '/help', description: 'Show commands', kind: 'command' },
|
|
1708
|
-
{ value: '/provider', description: 'Choose a provider', kind: 'command' },
|
|
1709
|
-
{ value: '/model', description: 'Choose a model', kind: 'command' },
|
|
1710
|
-
{ value: '/lsp', description: 'Manage LSP servers (semantic navigation)', kind: 'command' },
|
|
1711
|
-
{ value: '/mcp', description: 'Manage MCP servers (Context7, etc.)', kind: 'command' },
|
|
1712
|
-
{ value: '/settings', description: 'Show provider, model, API key, and context status', kind: 'command' },
|
|
1713
|
-
{ value: '/context', description: 'Show token breakdown of system, tools, MCP, and messages', kind: 'command' },
|
|
1714
|
-
{ value: '/skills', description: 'Manage Markdown skills (add, enable/disable, validate, remove)', kind: 'command' },
|
|
1715
|
-
{ value: '/init', description: 'Create or update AGENTS.md project instructions', kind: 'command' },
|
|
1716
|
-
{ value: '/session', description: 'Show current session path', kind: 'command' },
|
|
1717
|
-
{ value: '/resume', description: 'Resume latest session for this workspace', kind: 'command' },
|
|
1718
|
-
{ value: '/new', description: 'Start a new session', kind: 'command' },
|
|
1719
|
-
{ value: '/compact ', description: 'Summarize older context and keep recent messages', kind: 'command' },
|
|
1720
|
-
{ value: '/clear', description: 'Clear conversation history', kind: 'command' },
|
|
1721
|
-
{ value: '/exit', description: 'Exit Haze', kind: 'command' },
|
|
1722
|
-
{ value: '/quit', description: 'Exit Haze', kind: 'command' },
|
|
1723
|
-
...skills.filter(skill => isSkillEnabled(settings, skill.name)).map(skill => ({ value: `/${skill.name}`, description: skill.description, kind: 'skill' })),
|
|
1724
|
-
] : [];
|
|
1123
|
+
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, selectedProviderName, modelProviderFilter, selectedSkillName, selectedLspName, selectedMcpName });
|
|
1725
1124
|
const staticItems = [
|
|
1726
1125
|
{ kind: 'header', key: `header-${activeModelName}`, subtitle: headerSubtitle },
|
|
1727
1126
|
...transcriptItems.map(item => ({ kind: 'message', ...item })),
|
|
1728
1127
|
];
|
|
1729
1128
|
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: staticItems, children: item => item.kind === 'header'
|
|
1730
1129
|
? _jsx(Header, { subtitle: item.subtitle, version: version }, item.key)
|
|
1731
|
-
: _jsx(MessageView, { message: item.message, width: width
|
|
1130
|
+
: _jsx(MessageView, { message: item.message, width: width }, item.key) }), streamingItems.length > 0 && _jsx(Box, { flexDirection: "column", flexShrink: 0, children: streamingItems.map((message, index) => _jsx(MessageView, { message: message, width: width }, messageKey(message, index))) }), debug && debugLogs.length > 0 && _jsxs(Box, { flexDirection: "column", flexShrink: 0, marginBottom: 1, borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsx(Text, { color: theme.muted, bold: true, children: "Debug" }), debugLogs.map((line, index) => _jsxs(Text, { color: theme.muted, children: ["\u2022 ", line] }, index))] }), queuedFollowUps.length > 0 && _jsxs(Box, { flexDirection: "column", flexShrink: 0, marginBottom: 1, children: [_jsx(Text, { color: theme.muted, children: "Queued follow-ups:" }), queuedFollowUps.map((item, index) => _jsxs(Text, { color: theme.muted, dimColor: true, children: [" ", index + 1, ". ", item] }, `${index}-${item}`))] }), visibleTasks.length > 0 && _jsx(Box, { flexDirection: "column", flexShrink: 0, marginBottom: 1, children: _jsx(TaskBar, { tasks: visibleTasks, width: width, expanded: tasksExpanded, padding: taskBarPadding }) }), busy && _jsx(Box, { flexShrink: 0, children: _jsxs(Text, { children: [_jsxs(Text, { color: theme.orange, bold: true, children: [_jsx(Spinner, { type: "dots" }), " ", busyLabel] }), _jsx(Text, { color: theme.muted, dimColor: true, children: " \u00B7 type to queue follow-up \u00B7 esc to interrupt" })] }) }), _jsx(Box, { borderStyle: "round", borderColor: theme.deepPurple, paddingX: 1, flexShrink: 0, children: _jsx(Box, { flexGrow: 1, minWidth: 0, children: _jsx(TextInput, { placeholder: placeholder, disabled: busy && mode !== 'chat', mask: MASKED_MODES.has(mode), historyItems: inputHistory, recordHistory: mode === 'chat', suggestions: inputSuggestions, suggestionMode: PICKER_MODES.has(mode) ? 'always' : 'slash', submitOnEmpty: SUBMIT_EMPTY_MODES.has(mode), width: Math.max(20, width - 4), onHistoryAdd: persistInputHistory, onToggleTasks: () => {
|
|
1732
1131
|
if (!tasksExpanded) {
|
|
1733
1132
|
setTaskBarPadding(0);
|
|
1734
1133
|
setTasksExpanded(true);
|