@denizokcu/haze 0.9.0 → 0.10.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 +57 -17
- package/README.md +119 -64
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +44 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +91 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/sessionLifecycle.d.ts +58 -0
- package/dist/cli/chat/sessionLifecycle.js +155 -0
- package/dist/cli/chat/sessionRecorder.js +7 -9
- package/dist/cli/chat/startupInfo.d.ts +1 -0
- package/dist/cli/chat/startupInfo.js +11 -0
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +645 -0
- package/dist/cli/commands/chat.d.ts +1 -0
- package/dist/cli/commands/chat.js +181 -700
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +3 -2
- package/dist/cli/commands/commands.js +12 -13
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +33 -6
- package/dist/cli/commands/logsCommand.js +1 -7
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/providerWizard.d.ts +1 -0
- package/dist/cli/commands/providerWizard.js +13 -0
- package/dist/cli/commands/runCommand.d.ts +1 -0
- package/dist/cli/commands/runCommand.js +25 -5
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +6 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +4 -2
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +13 -1
- package/dist/cli/commands/streaming.js +42 -19
- package/dist/cli/commands/wizardActions.d.ts +6 -0
- package/dist/cli/commands/wizardActions.js +6 -0
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +60 -12
- package/dist/cli/commands/wizardTransition.d.ts +4 -0
- package/dist/cli/commands/wizardTransition.js +1 -2
- package/dist/cli/index.js +17 -3
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +12 -18
- package/dist/config/modelDiscovery.d.ts +20 -0
- package/dist/config/modelDiscovery.js +51 -0
- package/dist/config/providerPresets.d.ts +16 -4
- package/dist/config/providerPresets.js +263 -34
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +7 -0
- package/dist/config/settings.d.ts +22 -0
- package/dist/config/settings.js +29 -1
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/core/agent/budgets.d.ts +26 -0
- package/dist/core/agent/budgets.js +34 -0
- package/dist/core/agent/compaction.js +17 -3
- package/dist/core/agent/contextBudget.d.ts +8 -0
- package/dist/core/agent/contextBudget.js +29 -0
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/toolOutputStore.d.ts +5 -0
- package/dist/core/agent/toolOutputStore.js +18 -1
- package/dist/core/agent/workState.d.ts +1 -1
- package/dist/core/agent/workState.js +0 -4
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.js +76 -29
- package/dist/core/limits/byteBudgets.d.ts +5 -0
- package/dist/core/limits/byteBudgets.js +5 -0
- package/dist/core/limits/textBudgets.d.ts +23 -0
- package/dist/core/limits/textBudgets.js +23 -0
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +194 -0
- package/dist/core/process/runBoundedProcess.d.ts +3 -0
- package/dist/core/process/runBoundedProcess.js +65 -29
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +37 -0
- package/dist/core/session/sessionStore.js +95 -9
- package/dist/core/subagent/contracts.d.ts +116 -0
- package/dist/core/subagent/contracts.js +54 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +74 -0
- package/dist/core/subagent/subagentCoordinator.js +134 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +228 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +20 -29
- package/dist/llm/client.js +29 -28
- package/dist/llm/hazeTools.d.ts +2013 -78
- package/dist/llm/hazeTools.js +16 -7
- package/dist/llm/lsp.d.ts +2 -0
- package/dist/llm/lsp.js +18 -3
- package/dist/llm/requestContext.d.ts +22 -1
- package/dist/llm/requestContext.js +45 -5
- package/dist/llm/systemPrompt.d.ts +4 -1
- package/dist/llm/systemPrompt.js +14 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/bashTool.d.ts +874 -32
- package/dist/llm/tools/bashTool.js +25 -4
- package/dist/llm/tools/fetchTool.d.ts +26 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +2 -1
- package/dist/llm/tools/fileToolShared.js +5 -5
- package/dist/llm/tools/grepRunner.d.ts +5 -0
- package/dist/llm/tools/grepRunner.js +52 -71
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +8 -0
- package/dist/llm/tools/toolContext.js +22 -11
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.js +24 -11
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +43 -13
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +6 -1
- package/dist/ui/components/TextInput.d.ts +5 -2
- package/dist/ui/components/TextInput.js +76 -8
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +0 -1
- package/dist/utils/fs.js +0 -4
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +9 -0
- package/package.json +1 -1
|
@@ -2,7 +2,6 @@ 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
4
|
import { promisify } from 'node:util';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
5
|
import { Box, render, Static, Text, useApp, useStdout } from 'ink';
|
|
7
6
|
import Spinner from 'ink-spinner';
|
|
8
7
|
import { readContextFiles } from '../../config/contextFiles.js';
|
|
@@ -10,47 +9,37 @@ import { checkForUpdate } from '../../config/updateCheck.js';
|
|
|
10
9
|
import { addInputHistoryItem, readInputHistory } from '../../config/inputHistory.js';
|
|
11
10
|
import { loadTasks as loadTasksFromStore, clearTasks as clearTasksFromStore } from '../../core/tasks/taskStorage.js';
|
|
12
11
|
import { readSettings, updateSettings } from '../../config/settings.js';
|
|
13
|
-
import { activeModel,
|
|
14
|
-
import { removeLspServer } from '../../config/lspSettings.js';
|
|
15
|
-
import { removeMcpServer } from '../../config/mcpSettings.js';
|
|
12
|
+
import { activeModel, activeProvider } from '../../config/providers.js';
|
|
16
13
|
import { isSkillEnabled } from '../../config/skillSettings.js';
|
|
17
14
|
import { Header } from '../../ui/components/Header.js';
|
|
18
15
|
import { TextInput } from '../../ui/components/TextInput.js';
|
|
19
16
|
import { theme } from '../../ui/theme.js';
|
|
20
17
|
import { handleSlashCommand } from './commands.js';
|
|
21
18
|
import { runAgentTurn } from './streaming.js';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
19
|
+
import { formatElapsedTimeWhole, imageAttachmentLine } from './formatters.js';
|
|
20
|
+
import { imageCapabilityError, IMAGE_ONLY_PROMPT_TEXT, resolveImageAttachments } from '../../core/attachments/imageAttachments.js';
|
|
21
|
+
import { resolveReadBlessings } from '../../core/attachments/readBlessings.js';
|
|
22
|
+
import { endLog as endLlmLog } from '../../core/log/llmLog.js';
|
|
24
23
|
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
25
|
-
import {
|
|
26
|
-
import { findPreset } from '../../config/providerPresets.js';
|
|
27
|
-
import { createSession, formatSession, latestSession, restoreConversation, restoreWorkState } from '../../core/session/sessionStore.js';
|
|
28
|
-
import { compactModelMessages } from '../../core/agent/compaction.js';
|
|
29
|
-
import { contextBreakdown } from '../../core/agent/contextBudget.js';
|
|
30
|
-
import { stripSyntheticControls } from '../../core/agent/requestAssembly.js';
|
|
31
|
-
import { modelWithConfig } from '../../llm/client.js';
|
|
32
|
-
import { assembleRequestContext } from '../../llm/requestContext.js';
|
|
33
|
-
import { closeMcpClients } from '../../llm/mcp.js';
|
|
24
|
+
import { formatSession, listSessions } from '../../core/session/sessionStore.js';
|
|
34
25
|
import { MAX_VISIBLE_TASKS, TaskBar } from '../chat/TaskBar.js';
|
|
35
|
-
import { clearToolOutputs } from '../../core/agent/toolOutputStore.js';
|
|
36
26
|
import { MessageView, messageKey, orderedDisplayMessages } from '../chat/messages.js';
|
|
37
27
|
import { createSessionRecorder } from '../chat/sessionRecorder.js';
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
28
|
+
import { createSessionLifecycle } from '../chat/sessionLifecycle.js';
|
|
29
|
+
import { createWizardDispatch } from '../chat/wizardDispatch.js';
|
|
30
|
+
import { buildContextReport } from '../chat/contextReport.js';
|
|
31
|
+
import { startupContextInfo, startupInputTips, startupProviderInfo } from '../chat/startupInfo.js';
|
|
32
|
+
import { TIPS, randomTipIndex, tipsEnabled } from '../chat/tips.js';
|
|
33
|
+
import { fileMentionSuggestions } from '../chat/fileMentionSuggestions.js';
|
|
34
|
+
import { compactHomePath, formatTokenCount, statusBarMetrics } from '../chat/chatMetrics.js';
|
|
40
35
|
import { accumulateTokenUsage, EMPTY_TOKEN_USAGE, shouldClearCompletedTasks } from '../chat/turnState.js';
|
|
41
36
|
import { MASKED_MODES, PICKER_MODES, SUBMIT_EMPTY_MODES, placeholderForMode } from './chatModes.js';
|
|
42
37
|
import { inputSuggestionsForState } from '../chat/inputSuggestions.js';
|
|
43
38
|
import { modelThinkingLabel } from '../../utils/modelName.js';
|
|
44
|
-
import { PROVIDER_ACTIONS, PROVIDER_CHOICES, SERVER_CHOICES } from './wizardActions.js';
|
|
45
|
-
import { captureLspName } from './wizardPrompts.js';
|
|
46
39
|
import { transitionMcpField, transitionProviderField } from './wizardTransition.js';
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
import { selectSkillActionResult, selectSkillResult } from './skillWizard.js';
|
|
51
|
-
import { captureSkillDescription as captureSkillDescriptionResult, skillCreationFailure, skillCreationMessage } from './skillCreation.js';
|
|
52
|
-
import { skillConfirmRemoveResult as skillConfirmRemove } from './skillConfirmRemove.js';
|
|
53
|
-
import { commandParts, isYesConfirmation } from './wizardInput.js';
|
|
40
|
+
import { commandParts } from './wizardInput.js';
|
|
41
|
+
import { backgroundProcessCount, subscribeBackgroundProcesses, teardownBackgroundProcesses } from '../../core/process/backgroundRegistry.js';
|
|
42
|
+
import { MAX_SESSION_PICKER_RESULTS } from './sessionPicker.js';
|
|
54
43
|
const execFile = promisify(execFileCallback);
|
|
55
44
|
async function currentBranchName() {
|
|
56
45
|
try {
|
|
@@ -71,7 +60,7 @@ function busyElapsedLabel(startedAt) {
|
|
|
71
60
|
function thinkingLabelForSettings(settings) {
|
|
72
61
|
return modelThinkingLabel(activeModel(settings)?.model);
|
|
73
62
|
}
|
|
74
|
-
function ChatScreen({ debug = false, version, continueSession = false, noSession = false }) {
|
|
63
|
+
function ChatScreen({ debug = false, version, continueSession = false, resumeSessionId, noSession = false }) {
|
|
75
64
|
const { exit } = useApp();
|
|
76
65
|
const { stdout } = useStdout();
|
|
77
66
|
const width = stdout.columns ?? process.stdout.columns ?? 80;
|
|
@@ -111,13 +100,17 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
111
100
|
const llmLogRef = useRef(undefined);
|
|
112
101
|
const persistenceWarningShownRef = useRef(false);
|
|
113
102
|
const skillErrorSignatureRef = useRef('');
|
|
103
|
+
const projectSkillSignatureRef = useRef('');
|
|
114
104
|
const contextFileSignaturesRef = useRef(new Map());
|
|
115
105
|
const followUpQueueRef = useRef([]);
|
|
116
106
|
const [inputHistory, setInputHistory] = useState([]);
|
|
117
107
|
const [debugLogs, setDebugLogs] = useState([]);
|
|
118
108
|
const [contextFiles, setContextFiles] = useState([]);
|
|
119
109
|
const [mode, setMode] = useState('chat');
|
|
110
|
+
const [sessions, setSessions] = useState([]);
|
|
111
|
+
const [selectedSessionId, setSelectedSessionId] = useState();
|
|
120
112
|
const [busy, setBusy] = useState(false);
|
|
113
|
+
const [backgroundCount, setBackgroundCount] = useState(backgroundProcessCount);
|
|
121
114
|
const [busyLabel, setBusyLabel] = useState(() => thinkingLabelForSettings(settings));
|
|
122
115
|
// Heartbeat for the busy indicator: ticks every second while haze is working
|
|
123
116
|
// so the developer always sees rolling activity (elapsed turn time) even when
|
|
@@ -132,6 +125,8 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
132
125
|
const [skills, setSkills] = useState([]);
|
|
133
126
|
const [branchName, setBranchName] = useState();
|
|
134
127
|
const [modelProviderFilter, setModelProviderFilter] = useState();
|
|
128
|
+
const [discoveredModels, setDiscoveredModels] = useState([]);
|
|
129
|
+
const [suggestedModels, setSuggestedModels] = useState([]);
|
|
135
130
|
const [selectedProviderName, setSelectedProviderName] = useState();
|
|
136
131
|
const [providerDraft, setProviderDraft] = useState({});
|
|
137
132
|
const [skillDraft, setSkillDraft] = useState({});
|
|
@@ -151,12 +146,32 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
151
146
|
turnStartedAtRef.current = undefined;
|
|
152
147
|
setBusy(nextBusy);
|
|
153
148
|
};
|
|
149
|
+
useEffect(() => subscribeBackgroundProcesses(() => setBackgroundCount(backgroundProcessCount())), []);
|
|
154
150
|
useEffect(() => {
|
|
155
151
|
if (!busy)
|
|
156
152
|
return;
|
|
157
153
|
const heartbeat = setInterval(() => setBusyTick(tick => tick + 1), 1000);
|
|
158
154
|
return () => clearInterval(heartbeat);
|
|
159
155
|
}, [busy]);
|
|
156
|
+
// One tip per thinking section, shown under the busy label while the model
|
|
157
|
+
// is purely thinking (no tool running) and the user has not disabled tips.
|
|
158
|
+
// A fresh tip is picked each time the model enters thinking mode; no
|
|
159
|
+
// rotation during a single thinking section.
|
|
160
|
+
const [tipIndex, setTipIndex] = useState(() => randomTipIndex());
|
|
161
|
+
const thinkingLabel = thinkingLabelForSettings(settings);
|
|
162
|
+
const showingTip = busy && busyLabel === thinkingLabel && tipsEnabled(settings);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!showingTip)
|
|
165
|
+
return;
|
|
166
|
+
setTipIndex(current => randomTipIndex(current));
|
|
167
|
+
}, [showingTip]);
|
|
168
|
+
// Refresh the branch at turn boundaries so switching branches during a turn
|
|
169
|
+
// shows up promptly without tight idle polling (CR-026).
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (busy)
|
|
172
|
+
return;
|
|
173
|
+
currentBranchName().then(setBranchName).catch(() => setBranchName(undefined));
|
|
174
|
+
}, [busy]);
|
|
160
175
|
useEffect(() => {
|
|
161
176
|
Promise.all([
|
|
162
177
|
readSettings().then(value => ({ value, error: undefined })).catch(error => ({ value: {}, error: error instanceof Error ? error.message : String(error) })),
|
|
@@ -171,7 +186,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
171
186
|
contextFileSignaturesRef.current = new Map(files.flatMap(file => file.signature ? [[file.path, file.signature]] : []));
|
|
172
187
|
setMessages(m => [...m, { role: 'system', text: settingsResult.error ? settingsResult.error : `${startupProviderInfo(next)}\n\n${startupContextInfo(files)}` }]);
|
|
173
188
|
}).catch(() => undefined);
|
|
174
|
-
initializeSession().catch(error => {
|
|
189
|
+
sessionLifecycle.initializeSession().catch(error => {
|
|
175
190
|
const text = error instanceof Error ? error.message : String(error);
|
|
176
191
|
setMessages(m => [...m, { role: 'system', text: `Session disabled: ${text}` }]);
|
|
177
192
|
});
|
|
@@ -189,7 +204,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
189
204
|
}
|
|
190
205
|
const branchTimer = setInterval(() => {
|
|
191
206
|
currentBranchName().then(setBranchName).catch(() => setBranchName(undefined));
|
|
192
|
-
},
|
|
207
|
+
}, 15_000);
|
|
193
208
|
return () => clearInterval(branchTimer);
|
|
194
209
|
}, []);
|
|
195
210
|
function persistInputHistory(value) {
|
|
@@ -197,9 +212,15 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
197
212
|
}
|
|
198
213
|
async function refreshSkills() {
|
|
199
214
|
const registry = await loadSkillRegistry();
|
|
200
|
-
const nextSkills = [...registry.skills.values()];
|
|
215
|
+
const nextSkills = registry.candidates ?? [...registry.skills.values()];
|
|
201
216
|
setSkills(nextSkills);
|
|
202
|
-
const
|
|
217
|
+
const projectSkills = nextSkills.filter(skill => skill.source === 'project');
|
|
218
|
+
const projectSignature = projectSkills.map(skill => `${skill.name}:${skill.path}`).join('\n');
|
|
219
|
+
if (projectSignature && projectSignature !== projectSkillSignatureRef.current) {
|
|
220
|
+
setMessages(messages => [...messages, { role: 'system', text: `Project skills discovered (repository-provided, untrusted content): ${projectSkills.map(skill => skill.name).join(', ')}` }]);
|
|
221
|
+
}
|
|
222
|
+
projectSkillSignatureRef.current = projectSignature;
|
|
223
|
+
const errorSignature = registry.errors.map(error => `${error.source ? `${error.source}/` : ''}${error.directory}: ${error.message}`).join('\n');
|
|
203
224
|
if (errorSignature && errorSignature !== skillErrorSignatureRef.current) {
|
|
204
225
|
setMessages(messages => [...messages, { role: 'system', text: `Invalid skills were isolated:\n${errorSignature}` }]);
|
|
205
226
|
}
|
|
@@ -212,10 +233,10 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
212
233
|
const [name, ...args] = commandParts(value.slice(1));
|
|
213
234
|
if (!name)
|
|
214
235
|
return undefined;
|
|
215
|
-
const skill = skills.find(candidate => candidate.name === name);
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
return skill
|
|
236
|
+
const skill = skills.find(candidate => candidate.name === name && isSkillEnabled(settings, candidate.name, candidate.source));
|
|
237
|
+
// Candidates are ordered project-first, so disabling a project collision
|
|
238
|
+
// automatically re-surfaces the enabled global skill.
|
|
239
|
+
return skill ? { skill, args: args.join(' ') } : undefined;
|
|
219
240
|
}
|
|
220
241
|
function debugLog(line) {
|
|
221
242
|
if (!debug)
|
|
@@ -229,135 +250,43 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
229
250
|
const text = error instanceof Error ? error.message : String(error);
|
|
230
251
|
setMessages(messages => [...messages, { role: 'system', text: `Persistence warning: ${text}` }]);
|
|
231
252
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
// Session lifecycle (init/continue/resume/new/clear/compact) lives in a
|
|
254
|
+
// dedicated controller so this component stays orchestration glue (CR-006).
|
|
255
|
+
const sessionLifecycle = createSessionLifecycle({
|
|
256
|
+
version,
|
|
257
|
+
continueSession,
|
|
258
|
+
resumeSessionId,
|
|
259
|
+
noSession,
|
|
260
|
+
debug,
|
|
261
|
+
contextFiles: () => contextFiles,
|
|
262
|
+
sessionRef,
|
|
263
|
+
sessionRecorder: () => sessionRecorderRef.current,
|
|
264
|
+
sessionStartRef,
|
|
265
|
+
conversationRef,
|
|
266
|
+
workStateRef,
|
|
267
|
+
lastAssistantTextRef,
|
|
268
|
+
llmLogRef,
|
|
269
|
+
contextFileSignaturesRef,
|
|
270
|
+
setMessages,
|
|
271
|
+
setLiveMessagesState,
|
|
272
|
+
setTokenUsage,
|
|
273
|
+
debugLog,
|
|
274
|
+
showPersistenceWarning,
|
|
275
|
+
});
|
|
276
|
+
const { clearConversation, compactConversation } = sessionLifecycle;
|
|
277
|
+
async function openSessionPicker() {
|
|
243
278
|
await sessionRecorderRef.current?.flush().catch(showPersistenceWarning);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const session = await createSession({ hazeVersion: version });
|
|
253
|
-
sessionRef.current = session;
|
|
254
|
-
setTokenUsage({ ...EMPTY_TOKEN_USAGE });
|
|
255
|
-
await startNewLog();
|
|
256
|
-
setMessages(m => [...m, { role: 'system', text: `${message}\nSession saved: ${session.file}` }]);
|
|
257
|
-
}
|
|
258
|
-
async function initializeSession() {
|
|
259
|
-
if (noSession) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (continueSession) {
|
|
263
|
-
const session = await latestSession();
|
|
264
|
-
if (session) {
|
|
265
|
-
const { messages: conversation, parseErrors: conversationErrors } = await restoreConversation(session);
|
|
266
|
-
sessionRef.current = session;
|
|
267
|
-
sessionStartRef.current = new Date();
|
|
268
|
-
conversationRef.current = conversation;
|
|
269
|
-
setLiveMessagesState(() => []);
|
|
270
|
-
const restoredMessages = displayMessagesFromConversation(conversation);
|
|
271
|
-
setTokenUsage({ ...EMPTY_TOKEN_USAGE, messages: estimateConversationTokens(restoredMessages).input, outputEstimate: estimateConversationTokens(restoredMessages).output });
|
|
272
|
-
const { state: workState, parseErrors: workStateErrors } = await restoreWorkState(session);
|
|
273
|
-
workStateRef.current = workState;
|
|
274
|
-
for (const error of [...conversationErrors, ...workStateErrors]) {
|
|
275
|
-
debugLog(`Session parse error: ${error}`);
|
|
276
|
-
}
|
|
277
|
-
setMessages(m => [...m, { role: 'system', text: `Resumed session: ${formatSession(session)}` }, ...restoredMessages]);
|
|
278
|
-
await startNewLog();
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
await startNewSession(continueSession ? 'No previous session found. Started a new session.' : 'Started a new session.');
|
|
283
|
-
}
|
|
284
|
-
async function clearConversation() {
|
|
285
|
-
clearToolOutputs();
|
|
286
|
-
conversationRef.current = [];
|
|
287
|
-
lastAssistantTextRef.current = '';
|
|
288
|
-
setTokenUsage({ ...EMPTY_TOKEN_USAGE });
|
|
289
|
-
workStateRef.current = undefined;
|
|
290
|
-
setLiveMessagesState(() => []);
|
|
291
|
-
setMessages([{ role: 'system', text: 'Cleared. The void is productive.' }]);
|
|
292
|
-
sessionRecorderRef.current?.recordNamedEvent('clear', 'Conversation cleared');
|
|
293
|
-
await sessionRecorderRef.current?.flush().catch(showPersistenceWarning);
|
|
294
|
-
await startNewLog().catch(showPersistenceWarning);
|
|
295
|
-
}
|
|
296
|
-
function compactConversation(instructions) {
|
|
297
|
-
const result = compactModelMessages(conversationRef.current, { instructions, tokenBudget: 40_000, workState: workStateRef.current });
|
|
298
|
-
if (!result.compacted) {
|
|
299
|
-
setMessages(m => [...m, { role: 'system', text: `Compaction skipped: only ${result.keptCount} model messages in context.` }]);
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
conversationRef.current = result.messages;
|
|
303
|
-
sessionRecorderRef.current?.recordNamedEvent('compact', `Compacted ${result.olderCount} messages; kept ${result.keptCount}.`);
|
|
304
|
-
sessionRecorderRef.current?.recordConversation(result.messages);
|
|
305
|
-
setMessages(m => [...m, { role: 'system', text: `Compacted context: summarized ${result.olderCount} older model messages and kept the last ${result.keptCount}.` }]);
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
async function resumeLatestSession() {
|
|
309
|
-
await sessionRecorderRef.current?.flush().catch(showPersistenceWarning);
|
|
310
|
-
const session = await latestSession();
|
|
311
|
-
if (!session) {
|
|
312
|
-
setMessages(m => [...m, { role: 'system', text: 'No previous session found for this workspace.' }]);
|
|
279
|
+
const next = await listSessions();
|
|
280
|
+
setSessions(next);
|
|
281
|
+
setSelectedSessionId(undefined);
|
|
282
|
+
if (next.length === 0) {
|
|
283
|
+
setMessages(m => [...m, { role: 'system', text: 'No saved sessions found for this workspace.' }]);
|
|
284
|
+
setMode('chat');
|
|
313
285
|
return;
|
|
314
286
|
}
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
debugLog(`Session parse error: ${error}`);
|
|
319
|
-
}
|
|
320
|
-
clearToolOutputs();
|
|
321
|
-
sessionRef.current = session;
|
|
322
|
-
conversationRef.current = conversation;
|
|
323
|
-
workStateRef.current = workState;
|
|
324
|
-
setTokenUsage({ ...EMPTY_TOKEN_USAGE });
|
|
325
|
-
setLiveMessagesState(() => []);
|
|
326
|
-
setMessages([{ role: 'system', text: `Resumed session: ${formatSession(session)}` }, ...displayMessagesFromConversation(conversation)]);
|
|
327
|
-
}
|
|
328
|
-
async function buildContextReport() {
|
|
329
|
-
const runtime = await modelWithConfig({ cwd: process.cwd() });
|
|
330
|
-
if (!runtime?.model) {
|
|
331
|
-
return 'No model provider configured. Run /provider to choose or add a provider before /context can estimate tokens.';
|
|
332
|
-
}
|
|
333
|
-
const session = { start: sessionStartRef.current, cwd: process.cwd() };
|
|
334
|
-
const assembled = await assembleRequestContext({ contextFiles, session, model: runtime.model });
|
|
335
|
-
try {
|
|
336
|
-
const messages = stripSyntheticControls(conversationRef.current);
|
|
337
|
-
const breakdown = contextBreakdown({ system: assembled.systemPrompt, contextFiles, messages, tools: assembled.availableTools });
|
|
338
|
-
const tools = breakdown.toolSchemas.map(tool => ({
|
|
339
|
-
name: tool.name,
|
|
340
|
-
tokens: tool.tokens,
|
|
341
|
-
category: assembled.toolCategories.get(tool.name) ?? 'builtin',
|
|
342
|
-
}));
|
|
343
|
-
return formatContextReport({
|
|
344
|
-
modelLabel: `${runtime.config.providerName}:${runtime.config.modelName}`,
|
|
345
|
-
systemTokens: breakdown.system,
|
|
346
|
-
projectContext: breakdown.projectContext,
|
|
347
|
-
tools,
|
|
348
|
-
messagesByRole: breakdown.messagesByRole,
|
|
349
|
-
toolResults: breakdown.toolResults,
|
|
350
|
-
toolInputs: breakdown.toolInputs,
|
|
351
|
-
syntheticControl: breakdown.syntheticControl,
|
|
352
|
-
logicalInputEstimate: breakdown.logicalInputEstimate,
|
|
353
|
-
messageCount: messages.length,
|
|
354
|
-
mcpErrors: assembled.loadedMcp?.errors ?? [],
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
finally {
|
|
358
|
-
if (assembled.loadedMcp?.clients.length)
|
|
359
|
-
await closeMcpClients(assembled.loadedMcp.clients);
|
|
360
|
-
}
|
|
287
|
+
setMode('sessions');
|
|
288
|
+
const hidden = Math.max(0, next.length - MAX_SESSION_PICKER_RESULTS);
|
|
289
|
+
setMessages(m => [...m, { role: 'system', text: `Choose a saved session (newest first)${hidden ? `. Showing ${MAX_SESSION_PICKER_RESULTS} of ${next.length}; ${hidden} older sessions are hidden.` : '.'}` }]);
|
|
361
290
|
}
|
|
362
291
|
function cancelThinking() {
|
|
363
292
|
if (!busy)
|
|
@@ -381,7 +310,11 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
381
310
|
function closeInputList() {
|
|
382
311
|
if (mode !== 'chat') {
|
|
383
312
|
setMode('chat');
|
|
313
|
+
setSessions([]);
|
|
314
|
+
setSelectedSessionId(undefined);
|
|
384
315
|
setModelProviderFilter(undefined);
|
|
316
|
+
setDiscoveredModels([]);
|
|
317
|
+
setSuggestedModels([]);
|
|
385
318
|
setSelectedProviderName(undefined);
|
|
386
319
|
setProviderDraft({});
|
|
387
320
|
setSkillDraft({});
|
|
@@ -392,321 +325,26 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
392
325
|
setMcpDraft({});
|
|
393
326
|
}
|
|
394
327
|
}
|
|
395
|
-
async function selectProvider(providerName) {
|
|
396
|
-
if (providerName === PROVIDER_CHOICES.addProvider) {
|
|
397
|
-
setProviderDraft({});
|
|
398
|
-
setMode('providerAddPreset');
|
|
399
|
-
setMessages(m => [...m, { role: 'system', text: 'Choose a provider preset, or select "custom" to enter details manually.' }]);
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
const provider = findProvider(settings, providerName);
|
|
403
|
-
if (!provider) {
|
|
404
|
-
setMessages(m => [...m, { role: 'system', text: `No provider named ${providerName}. Use /provider and choose add provider.` }]);
|
|
405
|
-
setMode('chat');
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
setSelectedProviderName(provider.name);
|
|
409
|
-
setMode('providerAction');
|
|
410
|
-
setMessages(m => [...m, { role: 'system', text: `${provider.name}: choose an action.` }]);
|
|
411
|
-
}
|
|
412
|
-
async function selectPreset(presetId) {
|
|
413
|
-
if (presetId === PROVIDER_CHOICES.custom) {
|
|
414
|
-
setProviderDraft({});
|
|
415
|
-
setMode('providerAddName');
|
|
416
|
-
setMessages(m => [...m, { role: 'system', text: 'Provider name? Example: openrouter, local, lmstudio.' }]);
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
const preset = findPreset(presetId);
|
|
420
|
-
if (!preset) {
|
|
421
|
-
setMessages(m => [...m, { role: 'system', text: `Unknown preset: ${presetId}.` }]);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
// Check if a provider with this name already exists
|
|
425
|
-
const existingName = settings.providers?.some(p => p.name === preset.name) ? preset.id : preset.name;
|
|
426
|
-
const nameConflict = settings.providers?.some(p => p.name === existingName);
|
|
427
|
-
if (nameConflict) {
|
|
428
|
-
setMessages(m => [...m, { role: 'system', text: `Provider ${existingName} already exists. Use /provider to manage existing providers.` }]);
|
|
429
|
-
setMode('chat');
|
|
430
|
-
setProviderDraft({});
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
setProviderDraft({ name: existingName, url: preset.baseUrl });
|
|
434
|
-
if (preset.needsApiKey) {
|
|
435
|
-
setMode('providerAddKey');
|
|
436
|
-
setMessages(m => [...m, { role: 'system', text: `${preset.name} (${preset.baseUrl})\nAPI key${preset.apiKeyHint ? ` (${preset.apiKeyHint})` : ''}?` }]);
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
// Local/keyless: skip API key, go straight to models
|
|
440
|
-
setMode('providerAddModels');
|
|
441
|
-
const hint = preset.suggestedModels?.length ? ` Example: ${preset.suggestedModels.join(', ')}` : '';
|
|
442
|
-
setMessages(m => [...m, { role: 'system', text: `${preset.name} (${preset.baseUrl}) — no API key needed.\nComma-separated model names?${hint}` }]);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async function useProvider(providerName) {
|
|
446
|
-
const provider = findProvider(settings, providerName);
|
|
447
|
-
if (!provider) {
|
|
448
|
-
setMessages(m => [...m, { role: 'system', text: `No provider named ${providerName}.` }]);
|
|
449
|
-
setMode('chat');
|
|
450
|
-
setSelectedProviderName(undefined);
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
const next = await updateSettings({ provider: provider.name });
|
|
454
|
-
setSettings(next);
|
|
455
|
-
setSelectedProviderName(undefined);
|
|
456
|
-
setModelProviderFilter(provider.name);
|
|
457
|
-
setMode('model');
|
|
458
|
-
setMessages(m => [...m, { role: 'system', text: `Provider set to ${provider.name}. Choose a model.` }]);
|
|
459
|
-
}
|
|
460
|
-
async function selectProviderAction(action) {
|
|
461
|
-
if (!selectedProviderName) {
|
|
462
|
-
setMode('provider');
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
const provider = findProvider(settings, selectedProviderName);
|
|
466
|
-
if (!provider) {
|
|
467
|
-
setMessages(m => [...m, { role: 'system', text: `Provider ${selectedProviderName} not found.` }]);
|
|
468
|
-
setMode('chat');
|
|
469
|
-
setSelectedProviderName(undefined);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
if (action === PROVIDER_ACTIONS.useProvider) {
|
|
473
|
-
await useProvider(selectedProviderName);
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const actionResult = providerActionResult(action, provider);
|
|
477
|
-
if (actionResult.selectedName === undefined)
|
|
478
|
-
setSelectedProviderName(undefined);
|
|
479
|
-
if (actionResult.mode)
|
|
480
|
-
setMode(actionResult.mode);
|
|
481
|
-
showWizardMessage(actionResult.message);
|
|
482
|
-
}
|
|
483
|
-
async function selectModel(selector) {
|
|
484
|
-
const scopedSelector = modelProviderFilter ? `${modelProviderFilter}:${selector}` : selector;
|
|
485
|
-
const resolved = resolveModelSelector(settings, scopedSelector);
|
|
486
|
-
if (resolved.status === 'ambiguous') {
|
|
487
|
-
setMessages(m => [...m, { role: 'system', text: `Model ${resolved.model} exists on multiple providers: ${resolved.providers.map(provider => modelSelector(provider, resolved.model)).join(', ')}` }]);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
if (resolved.status === 'missing') {
|
|
491
|
-
setMessages(m => [...m, { role: 'system', text: `No configured model named ${selector}. Use /provider, select a provider, then choose add models.` }]);
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
const next = await updateSettings({ provider: resolved.provider.name, model: resolved.model });
|
|
495
|
-
setSettings(next);
|
|
496
|
-
setModelProviderFilter(undefined);
|
|
497
|
-
setMode('chat');
|
|
498
|
-
setMessages(m => [...m, { role: 'system', text: `Model set to ${resolved.model} on ${resolved.provider.name}.\n\n${startupProviderInfo(next)}` }]);
|
|
499
|
-
}
|
|
500
|
-
async function appendModelsToProvider(modelsValue) {
|
|
501
|
-
const result = providerAppendModels(settings, selectedProviderName, modelsValue);
|
|
502
|
-
if (!result.provider) {
|
|
503
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
504
|
-
setMode('chat');
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (!result.settingsPatch) {
|
|
508
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const next = await updateSettings(result.settingsPatch);
|
|
512
|
-
setSettings(next);
|
|
513
|
-
setSelectedProviderName(undefined);
|
|
514
|
-
setModelProviderFilter(result.provider.name);
|
|
515
|
-
setMode('model');
|
|
516
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
517
|
-
}
|
|
518
|
-
async function finishProviderAdd(modelsValue) {
|
|
519
|
-
const result = providerFinishAdd(settings, providerDraft, modelsValue);
|
|
520
|
-
if (!result.provider || !result.settingsPatch) {
|
|
521
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
522
|
-
setMode('chat');
|
|
523
|
-
setProviderDraft({});
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const next = await updateSettings(result.settingsPatch);
|
|
527
|
-
setSettings(next);
|
|
528
|
-
setProviderDraft({});
|
|
529
|
-
setModelProviderFilter(result.provider.name);
|
|
530
|
-
setMode('model');
|
|
531
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
532
|
-
}
|
|
533
|
-
// --- LSP wizard handlers (mirror the provider wizard) ---
|
|
534
328
|
function showWizardMessage(message) {
|
|
535
329
|
if (message)
|
|
536
330
|
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
537
331
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
if (result.settingsPatch)
|
|
555
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
556
|
-
if (result.mode)
|
|
557
|
-
setMode(result.mode);
|
|
558
|
-
showWizardMessage(result.message);
|
|
559
|
-
}
|
|
560
|
-
async function selectLspAction(action) {
|
|
561
|
-
const result = selectLspActionResult(settings, selectedLspName, action);
|
|
562
|
-
if (result.settingsPatch)
|
|
563
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
564
|
-
if ('selectedName' in result)
|
|
565
|
-
setSelectedLspName(result.selectedName);
|
|
566
|
-
if (result.mode)
|
|
567
|
-
setMode(result.mode);
|
|
568
|
-
showWizardMessage(result.message);
|
|
569
|
-
}
|
|
570
|
-
async function finishLspCustom(commandLine) {
|
|
571
|
-
const result = finishLspCustomResult(settings, lspDraft.name, commandLine);
|
|
572
|
-
if (result.settingsPatch)
|
|
573
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
574
|
-
if (result.clearDraft)
|
|
575
|
-
setLspDraft({});
|
|
576
|
-
if (result.mode)
|
|
577
|
-
setMode(result.mode);
|
|
578
|
-
showWizardMessage(result.message);
|
|
579
|
-
}
|
|
580
|
-
// --- MCP wizard handlers (mirror the provider wizard) ---
|
|
581
|
-
async function selectMcpServer(serverName) {
|
|
582
|
-
const result = selectMcpServerResult(settings, serverName);
|
|
583
|
-
if (result.clearDraft)
|
|
584
|
-
setMcpDraft({});
|
|
585
|
-
if (serverName === SERVER_CHOICES.addServer)
|
|
586
|
-
setMode('mcpAddPreset');
|
|
587
|
-
else if (result.mode)
|
|
588
|
-
setMode(result.mode);
|
|
589
|
-
if (result.selectedName !== undefined)
|
|
590
|
-
setSelectedMcpName(result.selectedName);
|
|
591
|
-
showWizardMessage(result.message);
|
|
592
|
-
}
|
|
593
|
-
async function selectMcpPreset(presetId) {
|
|
594
|
-
const result = selectMcpPresetResult(settings, presetId);
|
|
595
|
-
if (result.clearDraft)
|
|
596
|
-
setMcpDraft({});
|
|
597
|
-
if (result.draft)
|
|
598
|
-
setMcpDraft(result.draft);
|
|
599
|
-
if (result.mode)
|
|
600
|
-
setMode(result.mode);
|
|
601
|
-
showWizardMessage(result.message);
|
|
602
|
-
}
|
|
603
|
-
async function selectMcpAction(action) {
|
|
604
|
-
const result = selectMcpActionResult(settings, selectedMcpName, action);
|
|
605
|
-
if (result.settingsPatch)
|
|
606
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
607
|
-
if ('selectedName' in result)
|
|
608
|
-
setSelectedMcpName(result.selectedName);
|
|
609
|
-
if (result.mode)
|
|
610
|
-
setMode(result.mode);
|
|
611
|
-
showWizardMessage(result.message);
|
|
612
|
-
}
|
|
613
|
-
async function finishMcpCustom(keyValue, draft = mcpDraft) {
|
|
614
|
-
const result = finishMcpCustomResult(settings, draft, keyValue);
|
|
615
|
-
if (result.settingsPatch)
|
|
616
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
617
|
-
if (result.clearDraft)
|
|
618
|
-
setMcpDraft({});
|
|
619
|
-
if (result.mode)
|
|
620
|
-
setMode(result.mode);
|
|
621
|
-
showWizardMessage(result.message);
|
|
622
|
-
}
|
|
623
|
-
async function setMcpServerKey(keyValue) {
|
|
624
|
-
const result = setMcpServerKeyResult(settings, selectedMcpName, keyValue);
|
|
625
|
-
if (result.settingsPatch)
|
|
626
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
627
|
-
if ('selectedName' in result)
|
|
628
|
-
setSelectedMcpName(result.selectedName);
|
|
629
|
-
if (result.mode)
|
|
630
|
-
setMode(result.mode);
|
|
631
|
-
showWizardMessage(result.message);
|
|
632
|
-
}
|
|
633
|
-
// --- Skills wizard handlers (mirror the provider/LSP/MCP wizards) ---
|
|
634
|
-
async function selectSkill(name) {
|
|
635
|
-
const result = selectSkillResult(skills, name);
|
|
636
|
-
if (result.clearDraft)
|
|
637
|
-
setSkillDraft({});
|
|
638
|
-
if ('selectedName' in result)
|
|
639
|
-
setSelectedSkillName(result.selectedName);
|
|
640
|
-
if (result.mode)
|
|
641
|
-
setMode(result.mode);
|
|
642
|
-
showWizardMessage(result.message);
|
|
643
|
-
}
|
|
644
|
-
async function selectSkillAction(action) {
|
|
645
|
-
const result = selectSkillActionResult(settings, skills, selectedSkillName, action);
|
|
646
|
-
if (result.settingsPatch)
|
|
647
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
648
|
-
if ('selectedName' in result)
|
|
649
|
-
setSelectedSkillName(result.selectedName);
|
|
650
|
-
if (result.mode)
|
|
651
|
-
setMode(result.mode);
|
|
652
|
-
if (result.validate && result.skill) {
|
|
653
|
-
const { loadSkill } = await import('../../skills/SkillLoader.js');
|
|
654
|
-
try {
|
|
655
|
-
const loaded = await loadSkill(result.skill.dir, 'global');
|
|
656
|
-
showWizardMessage(loaded ? `Valid: ${loaded.name}` : 'No SKILL.md found');
|
|
657
|
-
}
|
|
658
|
-
catch (error) {
|
|
659
|
-
const text = error instanceof Error ? error.message : String(error);
|
|
660
|
-
showWizardMessage(`Invalid skill: ${text}`);
|
|
661
|
-
}
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
showWizardMessage(result.message);
|
|
665
|
-
}
|
|
666
|
-
async function captureSkillName(value) {
|
|
667
|
-
const dirName = toSkillDirName(value);
|
|
668
|
-
if (!dirName) {
|
|
669
|
-
setMessages(m => [...m, { role: 'system', text: 'Skill name must contain at least one letter or number. Try again, or press ESC to cancel.' }]);
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
const registry = await loadSkillRegistry();
|
|
673
|
-
if (registry.skills.has(dirName)) {
|
|
674
|
-
setMessages(m => [...m, { role: 'system', text: `A skill named "${dirName}" already exists. Pick another name, or press ESC to cancel.` }]);
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
setSkillDraft(d => ({ ...d, name: dirName }));
|
|
678
|
-
setMode('skillsAddDescription');
|
|
679
|
-
setMessages(m => [...m, { role: 'system', text: `Describe what "${dirName}" should do. This is the work the LLM will expand into the skill body.` }]);
|
|
680
|
-
}
|
|
681
|
-
async function captureSkillDescription(value) {
|
|
682
|
-
const result = captureSkillDescriptionResult(value, skillDraft.name);
|
|
683
|
-
if (result.message) {
|
|
684
|
-
const message = result.message;
|
|
685
|
-
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
686
|
-
}
|
|
687
|
-
if (result.mode === 'chat')
|
|
688
|
-
setMode('chat');
|
|
689
|
-
if (result.clearDraft)
|
|
690
|
-
setSkillDraft({});
|
|
691
|
-
if (result.description && result.draftName) {
|
|
692
|
-
const name = result.draftName;
|
|
693
|
-
const description = result.description;
|
|
694
|
-
setBusyLabel(result.busyLabel ?? 'Creating skill');
|
|
695
|
-
setBusyWithHeartbeat(true);
|
|
696
|
-
try {
|
|
697
|
-
const created = await createSkill({ name, description });
|
|
698
|
-
setMessages(m => [...m, { role: 'system', text: skillCreationMessage(created.name, created.file) }]);
|
|
699
|
-
await refreshSkills();
|
|
700
|
-
}
|
|
701
|
-
catch (error) {
|
|
702
|
-
setMessages(m => [...m, { role: 'system', text: skillCreationFailure(error) }]);
|
|
703
|
-
}
|
|
704
|
-
finally {
|
|
705
|
-
setBusyWithHeartbeat(false);
|
|
706
|
-
setBusyLabel(thinkingLabelForSettings(settings));
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
332
|
+
// Wizard/picker submit dispatch lives in one table-driven module with a
|
|
333
|
+
// shared settings-patch applier (CR-006). Rebuilt every render so handlers
|
|
334
|
+
// see current state without new React state.
|
|
335
|
+
const wizard = createWizardDispatch({
|
|
336
|
+
settings, skills, modelProviderFilter, selectedProviderName, selectedSkillName, selectedLspName, selectedMcpName,
|
|
337
|
+
sessions, selectedSessionId,
|
|
338
|
+
providerDraft, lspDraft, mcpDraft, skillDraft,
|
|
339
|
+
setMode, setSettings,
|
|
340
|
+
setSelectedProviderName, setSelectedSkillName, setSelectedLspName, setSelectedMcpName, setSelectedSessionId,
|
|
341
|
+
resumeSessionById: sessionLifecycle.resumeSessionById,
|
|
342
|
+
forkSessionById: sessionLifecycle.forkSessionById,
|
|
343
|
+
setModelProviderFilter, setProviderDraft, setSkillDraft, setLspDraft, setMcpDraft, setDiscoveredModels, setSuggestedModels,
|
|
344
|
+
showMessage: showWizardMessage, refreshSkills,
|
|
345
|
+
setBusyLabel, setBusy: setBusyWithHeartbeat,
|
|
346
|
+
idleBusyLabel: thinkingLabelForSettings(settings),
|
|
347
|
+
});
|
|
710
348
|
async function submit(value) {
|
|
711
349
|
if (settingsError) {
|
|
712
350
|
try {
|
|
@@ -728,7 +366,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
728
366
|
queueFollowUp(value);
|
|
729
367
|
return;
|
|
730
368
|
}
|
|
731
|
-
const providerEffects = transitionProviderField({ mode, value, settings });
|
|
369
|
+
const providerEffects = transitionProviderField({ mode, value, settings, draft: providerDraft });
|
|
732
370
|
if (providerEffects) {
|
|
733
371
|
for (const effect of providerEffects) {
|
|
734
372
|
if (effect.type === 'message')
|
|
@@ -741,6 +379,11 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
741
379
|
else
|
|
742
380
|
setProviderDraft(draft => ({ ...draft, ...effect.patch }));
|
|
743
381
|
}
|
|
382
|
+
else if (effect.type === 'discover-provider-models') {
|
|
383
|
+
// The draft patch above is still pending React state, so discovery
|
|
384
|
+
// receives the merged draft explicitly (same pattern as MCP stdio).
|
|
385
|
+
await wizard.discoverProviderModelsForDraft(effect.draft);
|
|
386
|
+
}
|
|
744
387
|
}
|
|
745
388
|
return;
|
|
746
389
|
}
|
|
@@ -754,209 +397,12 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
754
397
|
else if (effect.type === 'mcp-draft')
|
|
755
398
|
setMcpDraft(draft => ({ ...draft, ...effect.patch }));
|
|
756
399
|
else if (effect.type === 'finish-mcp-stdio')
|
|
757
|
-
await finishMcpCustom(undefined, effect.draft);
|
|
400
|
+
await wizard.finishMcpCustom(undefined, effect.draft);
|
|
758
401
|
}
|
|
759
402
|
return;
|
|
760
403
|
}
|
|
761
|
-
if (mode
|
|
762
|
-
await selectSkill(value);
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
if (mode === 'skillsAction') {
|
|
766
|
-
await selectSkillAction(value);
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
|
-
if (mode === 'skillsAddName') {
|
|
770
|
-
await captureSkillName(value);
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
if (mode === 'skillsAddDescription') {
|
|
774
|
-
await captureSkillDescription(value);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
if (mode === 'skillsConfirmRemove') {
|
|
778
|
-
const result = skillConfirmRemove(settings, skills, selectedSkillName, value);
|
|
779
|
-
if (result.message) {
|
|
780
|
-
const message = result.message;
|
|
781
|
-
setMessages(m => [...m, { role: 'system', text: message }]);
|
|
782
|
-
}
|
|
783
|
-
if (result.selectedName === undefined)
|
|
784
|
-
setSelectedSkillName(undefined);
|
|
785
|
-
if (result.mode === 'chat')
|
|
786
|
-
setMode('chat');
|
|
787
|
-
if (result.removedDir)
|
|
788
|
-
await fs.remove(result.removedDir);
|
|
789
|
-
if (result.settingsPatch)
|
|
790
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
791
|
-
if (result.removedDir)
|
|
792
|
-
await refreshSkills();
|
|
793
|
-
return;
|
|
794
|
-
}
|
|
795
|
-
if (mode === 'provider') {
|
|
796
|
-
await selectProvider(value);
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
if (mode === 'providerAction') {
|
|
800
|
-
await selectProviderAction(value);
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
if (mode === 'providerAddPreset') {
|
|
804
|
-
await selectPreset(value);
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
if (mode === 'model') {
|
|
808
|
-
await selectModel(value);
|
|
404
|
+
if (await wizard.dispatch(mode, value))
|
|
809
405
|
return;
|
|
810
|
-
}
|
|
811
|
-
if (mode === 'providerAddModels') {
|
|
812
|
-
await finishProviderAdd(value);
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
if (mode === 'providerAppendModels') {
|
|
816
|
-
await appendModelsToProvider(value);
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
if (mode === 'providerSetKey') {
|
|
820
|
-
const result = providerSetKey(settings, selectedProviderName, value);
|
|
821
|
-
if (!result.provider) {
|
|
822
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
823
|
-
setMode('chat');
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
if (!result.settingsPatch) {
|
|
827
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
setSettings(await updateSettings(result.settingsPatch));
|
|
831
|
-
setSelectedProviderName(undefined);
|
|
832
|
-
setMode('chat');
|
|
833
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
if (mode === 'providerRemoveModels') {
|
|
837
|
-
const result = providerRemoveModels(settings, selectedProviderName, value);
|
|
838
|
-
if (!result.provider) {
|
|
839
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
840
|
-
setMode('chat');
|
|
841
|
-
return;
|
|
842
|
-
}
|
|
843
|
-
if (!result.settingsPatch) {
|
|
844
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
const next = await updateSettings(result.settingsPatch);
|
|
848
|
-
setSettings(next);
|
|
849
|
-
setSelectedProviderName(undefined);
|
|
850
|
-
setMode('chat');
|
|
851
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
if (mode === 'providerConfirmRemove') {
|
|
855
|
-
const provider = selectedProviderName ? findProvider(settings, selectedProviderName) : undefined;
|
|
856
|
-
if (!provider) {
|
|
857
|
-
setMessages(m => [...m, { role: 'system', text: 'No provider selected.' }]);
|
|
858
|
-
setMode('chat');
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
if (!isYesConfirmation(value)) {
|
|
862
|
-
setMessages(m => [...m, { role: 'system', text: 'Cancelled. Provider not removed.' }]);
|
|
863
|
-
setSelectedProviderName(undefined);
|
|
864
|
-
setMode('chat');
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
const result = providerRemove(settings, selectedProviderName);
|
|
868
|
-
const next = await updateSettings(result.settingsPatch ?? {});
|
|
869
|
-
setSettings(next);
|
|
870
|
-
setSelectedProviderName(undefined);
|
|
871
|
-
setMode('chat');
|
|
872
|
-
setMessages(m => [...m, { role: 'system', text: result.message }]);
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
|
-
if (mode === 'lsp') {
|
|
876
|
-
await selectLspServer(value);
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
if (mode === 'lspAction') {
|
|
880
|
-
await selectLspAction(value);
|
|
881
|
-
return;
|
|
882
|
-
}
|
|
883
|
-
if (mode === 'lspAddPreset') {
|
|
884
|
-
await selectLspPreset(value);
|
|
885
|
-
return;
|
|
886
|
-
}
|
|
887
|
-
if (mode === 'lspAddName') {
|
|
888
|
-
const result = captureLspName(settings, value);
|
|
889
|
-
if (result.message) {
|
|
890
|
-
showWizardMessage(result.message);
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
if (result.draft)
|
|
894
|
-
setLspDraft({ name: result.draft.name });
|
|
895
|
-
if (result.nextMode)
|
|
896
|
-
setMode(result.nextMode);
|
|
897
|
-
showWizardMessage(result.systemMessage);
|
|
898
|
-
return;
|
|
899
|
-
}
|
|
900
|
-
if (mode === 'lspAddCommand') {
|
|
901
|
-
await finishLspCustom(value);
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
if (mode === 'lspConfirmRemove') {
|
|
905
|
-
if (!selectedLspName) {
|
|
906
|
-
setMode('chat');
|
|
907
|
-
return;
|
|
908
|
-
}
|
|
909
|
-
if (!isYesConfirmation(value)) {
|
|
910
|
-
setMessages(m => [...m, { role: 'system', text: 'Cancelled. LSP server not removed.' }]);
|
|
911
|
-
setSelectedLspName(undefined);
|
|
912
|
-
setMode('chat');
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
915
|
-
const next = await updateSettings({ lspServers: removeLspServer(settings, selectedLspName) });
|
|
916
|
-
setSettings(next);
|
|
917
|
-
setMessages(m => [...m, { role: 'system', text: `Removed LSP server ${selectedLspName}.` }]);
|
|
918
|
-
setSelectedLspName(undefined);
|
|
919
|
-
setMode('chat');
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
if (mode === 'mcp') {
|
|
923
|
-
await selectMcpServer(value);
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
if (mode === 'mcpAction') {
|
|
927
|
-
await selectMcpAction(value);
|
|
928
|
-
return;
|
|
929
|
-
}
|
|
930
|
-
if (mode === 'mcpAddPreset') {
|
|
931
|
-
await selectMcpPreset(value);
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
if (mode === 'mcpAddKey') {
|
|
935
|
-
await finishMcpCustom(value);
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
if (mode === 'mcpSetKey') {
|
|
939
|
-
await setMcpServerKey(value);
|
|
940
|
-
return;
|
|
941
|
-
}
|
|
942
|
-
if (mode === 'mcpConfirmRemove') {
|
|
943
|
-
if (!selectedMcpName) {
|
|
944
|
-
setMode('chat');
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
if (!isYesConfirmation(value)) {
|
|
948
|
-
setMessages(m => [...m, { role: 'system', text: 'Cancelled. MCP server not removed.' }]);
|
|
949
|
-
setSelectedMcpName(undefined);
|
|
950
|
-
setMode('chat');
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
const next = await updateSettings({ mcpServers: removeMcpServer(settings, selectedMcpName) });
|
|
954
|
-
setSettings(next);
|
|
955
|
-
setMessages(m => [...m, { role: 'system', text: `Removed MCP server ${selectedMcpName}.` }]);
|
|
956
|
-
setSelectedMcpName(undefined);
|
|
957
|
-
setMode('chat');
|
|
958
|
-
return;
|
|
959
|
-
}
|
|
960
406
|
const invokedSkill = skillInvocation(value);
|
|
961
407
|
if (invokedSkill) {
|
|
962
408
|
const argumentText = invokedSkill.args ? `\nUser-provided skill arguments: ${invokedSkill.args}` : '';
|
|
@@ -975,12 +421,17 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
975
421
|
lastAssistantTextRef.current = '';
|
|
976
422
|
setLiveMessagesState(() => []);
|
|
977
423
|
setMessages([{ role: 'system', text: 'Started fresh. The fog parts.' }]);
|
|
978
|
-
await startNewSession('Started a new session.');
|
|
424
|
+
await sessionLifecycle.startNewSession('Started a new session.');
|
|
425
|
+
},
|
|
426
|
+
resumeSession: noSession ? undefined : async (id) => {
|
|
427
|
+
if (id)
|
|
428
|
+
await sessionLifecycle.resumeSessionById(id);
|
|
429
|
+
else
|
|
430
|
+
await openSessionPicker();
|
|
979
431
|
},
|
|
980
|
-
resumeSession: resumeLatestSession,
|
|
981
432
|
sessionInfo: () => sessionRef.current ? formatSession(sessionRef.current) : 'Session persistence is off.',
|
|
982
433
|
compactConversation,
|
|
983
|
-
runAgentTurn: (prompt, displayValue) => doAgentTurn(prompt, displayValue),
|
|
434
|
+
runAgentTurn: (prompt, displayValue, options) => doAgentTurn(prompt, displayValue, options),
|
|
984
435
|
refreshContextFiles: async () => {
|
|
985
436
|
const files = await readContextFiles().catch(() => contextFiles);
|
|
986
437
|
setContextFiles(files);
|
|
@@ -992,7 +443,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
992
443
|
setSettings(next);
|
|
993
444
|
return next;
|
|
994
445
|
},
|
|
995
|
-
getContextReport:
|
|
446
|
+
getContextReport: () => buildContextReport({ sessionStart: sessionStartRef.current, contextFiles, conversation: conversationRef.current }),
|
|
996
447
|
};
|
|
997
448
|
let result;
|
|
998
449
|
try {
|
|
@@ -1004,6 +455,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1004
455
|
return;
|
|
1005
456
|
}
|
|
1006
457
|
if (result === 'exit') {
|
|
458
|
+
await teardownBackgroundProcesses().catch(showPersistenceWarning);
|
|
1007
459
|
await sessionRecorderRef.current?.flush().catch(showPersistenceWarning);
|
|
1008
460
|
if (llmLogRef.current)
|
|
1009
461
|
await endLlmLog(llmLogRef.current).catch(showPersistenceWarning);
|
|
@@ -1015,9 +467,43 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1015
467
|
}
|
|
1016
468
|
return;
|
|
1017
469
|
}
|
|
1018
|
-
await
|
|
470
|
+
const prepared = await prepareUserInput(value);
|
|
471
|
+
if (!prepared)
|
|
472
|
+
return;
|
|
473
|
+
await doAgentTurn(prepared.value, prepared.displayValue, prepared.options);
|
|
474
|
+
}
|
|
475
|
+
// F03: resolve @image mentions in a prompt the user typed into attachments and
|
|
476
|
+
// gate them on the active provider's explicit capability before any model call.
|
|
477
|
+
// Applied only to genuine user input (direct chat and queued follow-ups), never
|
|
478
|
+
// to synthetic control prompts (/init, /fleet, skill invocations). Resolution
|
|
479
|
+
// errors and capability rejections surface an actionable system message and
|
|
480
|
+
// return undefined instead of starting a turn.
|
|
481
|
+
async function prepareUserInput(value) {
|
|
482
|
+
let resolved;
|
|
483
|
+
try {
|
|
484
|
+
resolved = await resolveImageAttachments(value);
|
|
485
|
+
}
|
|
486
|
+
catch (error) {
|
|
487
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
488
|
+
setMessages(m => [...m, { role: 'system', text }]);
|
|
489
|
+
return undefined;
|
|
490
|
+
}
|
|
491
|
+
const blessed = await resolveReadBlessings(resolved.text);
|
|
492
|
+
if (resolved.attachments.length === 0 && blessed.blessedPaths.length === 0)
|
|
493
|
+
return { value, options: {} };
|
|
494
|
+
const gateError = imageCapabilityError(activeProvider(settings));
|
|
495
|
+
if (resolved.attachments.length > 0 && gateError) {
|
|
496
|
+
setMessages(m => [...m, { role: 'system', text: gateError }]);
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|
|
499
|
+
const displayValue = [resolved.text, ...resolved.attachments.map(imageAttachmentLine)].filter(Boolean).join('\n');
|
|
500
|
+
return {
|
|
501
|
+
value: resolved.text || IMAGE_ONLY_PROMPT_TEXT,
|
|
502
|
+
displayValue,
|
|
503
|
+
options: { attachments: resolved.attachments, blessedPaths: blessed.blessedPaths },
|
|
504
|
+
};
|
|
1019
505
|
}
|
|
1020
|
-
async function doAgentTurn(value, displayValue) {
|
|
506
|
+
async function doAgentTurn(value, displayValue, turnOptions = {}) {
|
|
1021
507
|
setDebugLogs([]);
|
|
1022
508
|
// When every task is already completed, start the new turn with a clean
|
|
1023
509
|
// slate: the task bar clears (nothing shown for simple questions) and the
|
|
@@ -1028,16 +514,19 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1028
514
|
setTaskBarPadding(0);
|
|
1029
515
|
await clearTasksFromStore().catch(() => undefined);
|
|
1030
516
|
}
|
|
1031
|
-
await runSingleAgentTurn(value, displayValue);
|
|
517
|
+
await runSingleAgentTurn(value, displayValue, turnOptions);
|
|
1032
518
|
while (followUpQueueRef.current.length > 0) {
|
|
1033
519
|
const next = followUpQueueRef.current[0];
|
|
1034
520
|
followUpQueueRef.current = followUpQueueRef.current.slice(1);
|
|
1035
521
|
setQueuedFollowUps(followUpQueueRef.current);
|
|
1036
522
|
setMessages(m => [...m, { role: 'system', text: `Running queued follow-up: ${next}` }]);
|
|
1037
|
-
await
|
|
523
|
+
const preparedFollowUp = await prepareUserInput(next);
|
|
524
|
+
if (!preparedFollowUp)
|
|
525
|
+
continue;
|
|
526
|
+
await runSingleAgentTurn(preparedFollowUp.value, preparedFollowUp.displayValue, preparedFollowUp.options);
|
|
1038
527
|
}
|
|
1039
528
|
}
|
|
1040
|
-
async function runSingleAgentTurn(value, displayValue) {
|
|
529
|
+
async function runSingleAgentTurn(value, displayValue, turnOptions = {}) {
|
|
1041
530
|
const sessionRecorder = sessionRecorderRef.current;
|
|
1042
531
|
const finalizeMessage = (msg) => {
|
|
1043
532
|
if (msg.hidden)
|
|
@@ -1094,7 +583,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1094
583
|
onTasksChanged: () => { loadTasksFromStore().then(t => { setVisibleTasks(t); setTaskBarPadding(0); }).catch(() => undefined); },
|
|
1095
584
|
contextFileSignatures: contextFileSignaturesRef.current,
|
|
1096
585
|
log: llmLogRef.current,
|
|
1097
|
-
}, 0, false, false, { start: sessionStartRef.current, cwd: process.cwd() });
|
|
586
|
+
}, 0, false, false, { start: sessionStartRef.current, cwd: process.cwd() }, undefined, turnOptions);
|
|
1098
587
|
await sessionRecorder.flush().catch(showPersistenceWarning);
|
|
1099
588
|
await llmLogRef.current?.writer?.flush().catch(showPersistenceWarning);
|
|
1100
589
|
}
|
|
@@ -1112,26 +601,17 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1112
601
|
'Start with simple chat, then teach haze your habits with skills:',
|
|
1113
602
|
'/skills — add, enable/disable, validate, or remove Markdown skills.',
|
|
1114
603
|
'',
|
|
604
|
+
startupInputTips(),
|
|
605
|
+
'',
|
|
1115
606
|
'The most adaptive workflow is the one you shape as you go.',
|
|
1116
607
|
'',
|
|
1117
608
|
'Guardrails are light: haze lets the LLM work from the terminal almost like you,',
|
|
1118
609
|
'while trying to stay scoped to this project.',
|
|
1119
610
|
].join('\n');
|
|
1120
611
|
const workspaceLabel = `${compactHomePath(process.cwd())}${branchName ? ` (${branchName})` : ''}`;
|
|
1121
|
-
const
|
|
1122
|
-
const
|
|
1123
|
-
const
|
|
1124
|
-
const fallbackTokens = estimateConversationTokens(allDisplayMessages);
|
|
1125
|
-
const estimatedLogicalInput = tokenUsage.logicalInputEstimate || fallbackTokens.input || 0;
|
|
1126
|
-
const providerInput = tokenUsage.inputTokens;
|
|
1127
|
-
const effectiveInput = providerInput == null ? estimatedLogicalInput : Math.max(providerInput, estimatedLogicalInput);
|
|
1128
|
-
const effectiveOutput = tokenUsage.outputTokens ?? (fallbackTokens.output || 0);
|
|
1129
|
-
const inputEstimated = providerInput == null || effectiveInput !== providerInput;
|
|
1130
|
-
const outputEstimated = tokenUsage.outputTokens == null;
|
|
1131
|
-
const enabledSkills = skills.filter(skill => isSkillEnabled(settings, skill.name));
|
|
1132
|
-
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'}`;
|
|
1133
|
-
const hasTokenBreakdown = tokenUsage.systemPrompt > 0 || tokenUsage.messages > 0 || tokenUsage.toolSchemas > 0 || effectiveInput > 0 || effectiveOutput > 0;
|
|
1134
|
-
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, selectedProviderName, modelProviderFilter, selectedSkillName, selectedLspName, selectedMcpName });
|
|
612
|
+
const enabledSkillCount = new Set(skills.filter(skill => isSkillEnabled(settings, skill.name, skill.source)).map(skill => skill.name)).size;
|
|
613
|
+
const metrics = statusBarMetrics({ messages: [...messages, ...liveMessages], tokenUsage, enabledSkillCount, backgroundProcessCount: backgroundCount });
|
|
614
|
+
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, sessions, selectedProviderName, modelProviderFilter, providerDraftName: providerDraft.name, discoveredModels, suggestedModels, selectedSkillName, selectedLspName, selectedMcpName });
|
|
1135
615
|
const staticItems = [
|
|
1136
616
|
{ kind: 'header', key: `header-${activeModelName}`, subtitle: headerSubtitle },
|
|
1137
617
|
...transcriptItems.map(item => ({ kind: 'message', ...item })),
|
|
@@ -1139,7 +619,7 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1139
619
|
const busyElapsed = busyElapsedLabel(turnStartedAtRef.current);
|
|
1140
620
|
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: staticItems, children: item => item.kind === 'header'
|
|
1141
621
|
? _jsx(Header, { subtitle: item.subtitle, version: version }, item.key)
|
|
1142
|
-
: _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 &&
|
|
622
|
+
: _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 && _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [_jsx(Box, { children: _jsxs(Text, { children: [_jsxs(Text, { color: theme.orange, bold: true, children: [_jsx(Spinner, { type: "dots" }), " ", busyLabel, busyElapsed ? _jsxs(Text, { color: theme.muted, dimColor: true, children: [" \u00B7 ", busyElapsed] }) : null] }), _jsx(Text, { color: theme.muted, dimColor: true, children: " \u00B7 type to queue follow-up \u00B7 esc to interrupt" })] }) }), showingTip && (_jsx(Box, { children: _jsxs(Text, { color: theme.muted, children: [_jsx(Text, { bold: true, children: "Tip:" }), " ", TIPS[tipIndex] ?? ''] }) }))] }), _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), getMentionSuggestions: fileMentionSuggestions, onHistoryAdd: persistInputHistory, onToggleTasks: () => {
|
|
1143
623
|
if (!tasksExpanded) {
|
|
1144
624
|
setTaskBarPadding(0);
|
|
1145
625
|
setTasksExpanded(true);
|
|
@@ -1155,14 +635,15 @@ function ChatScreen({ debug = false, version, continueSession = false, noSession
|
|
|
1155
635
|
cancelThinking();
|
|
1156
636
|
else
|
|
1157
637
|
closeInputList();
|
|
1158
|
-
}, onSubmit: submit }) }) }), debug && hasTokenBreakdown && _jsxs(Box, { flexShrink: 0, flexDirection: "column", paddingX: 1, children: [_jsxs(Text, { color: theme.muted, bold: true, children: ["Token usage ", inputEstimated || outputEstimated ? '(estimated)' : '(precise)'] }), _jsxs(Text, { color: theme.muted, children: [" in=", formatTokenCount(effectiveInput), " out=", formatTokenCount(effectiveOutput), tokenUsage.cacheReadTokens > 0 ? ` cached=${formatTokenCount(tokenUsage.cacheReadTokens)}` : '', tokenUsage.noCacheTokens > 0 ? ` uncached=${formatTokenCount(tokenUsage.noCacheTokens)}` : '', tokenUsage.cacheWriteTokens > 0 ? ` cache_write=${formatTokenCount(tokenUsage.cacheWriteTokens)}` : '', tokenUsage.reasoningTokens > 0 ? ` reasoning=${formatTokenCount(tokenUsage.reasoningTokens)}` : ''] }), _jsxs(Text, { color: theme.muted, children: [" logical=", formatTokenCount(tokenUsage.logicalInputEstimate), tokenUsage.effectiveNonCachedInput != null ? ` effective_non_cached=${formatTokenCount(tokenUsage.effectiveNonCachedInput)}` : ''] }), _jsxs(Text, { color: theme.muted, children: [" system=", formatTokenCount(tokenUsage.systemPrompt), " messages=", formatTokenCount(tokenUsage.messages), " tools=", formatTokenCount(tokenUsage.toolSchemas), " output=", formatTokenCount(tokenUsage.outputEstimate)] })] }), _jsxs(Box, { flexShrink: 0, justifyContent: "space-between", children: [_jsxs(Box, { flexDirection: "column", flexShrink: 1, minWidth: 0, children: [_jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-end", children: workspaceLabel }), _jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-end", children: statusDetailLabel })] }), _jsx(Box, { flexShrink: 0, marginLeft: 2, children: _jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-start", children: activeModelName }) })] })] });
|
|
638
|
+
}, onSubmit: submit }) }) }), debug && metrics.hasTokenBreakdown && _jsxs(Box, { flexShrink: 0, flexDirection: "column", paddingX: 1, children: [_jsxs(Text, { color: theme.muted, bold: true, children: ["Token usage ", metrics.inputEstimated || metrics.outputEstimated ? '(estimated)' : '(precise)'] }), _jsxs(Text, { color: theme.muted, children: [" in=", formatTokenCount(metrics.effectiveInput), " out=", formatTokenCount(metrics.effectiveOutput), tokenUsage.cacheReadTokens > 0 ? ` cached=${formatTokenCount(tokenUsage.cacheReadTokens)}` : '', tokenUsage.noCacheTokens > 0 ? ` uncached=${formatTokenCount(tokenUsage.noCacheTokens)}` : '', tokenUsage.cacheWriteTokens > 0 ? ` cache_write=${formatTokenCount(tokenUsage.cacheWriteTokens)}` : '', tokenUsage.reasoningTokens > 0 ? ` reasoning=${formatTokenCount(tokenUsage.reasoningTokens)}` : ''] }), _jsxs(Text, { color: theme.muted, children: [" logical=", formatTokenCount(tokenUsage.logicalInputEstimate), tokenUsage.effectiveNonCachedInput != null ? ` effective_non_cached=${formatTokenCount(tokenUsage.effectiveNonCachedInput)}` : ''] }), _jsxs(Text, { color: theme.muted, children: [" system=", formatTokenCount(tokenUsage.systemPrompt), " messages=", formatTokenCount(tokenUsage.messages), " tools=", formatTokenCount(tokenUsage.toolSchemas), " output=", formatTokenCount(tokenUsage.outputEstimate)] })] }), _jsxs(Box, { flexShrink: 0, justifyContent: "space-between", children: [_jsxs(Box, { flexDirection: "column", flexShrink: 1, minWidth: 0, children: [_jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-end", children: workspaceLabel }), _jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-end", children: metrics.statusDetailLabel })] }), _jsx(Box, { flexShrink: 0, marginLeft: 2, children: _jsx(Text, { color: theme.muted, dimColor: true, wrap: "truncate-start", children: activeModelName }) })] })] });
|
|
1159
639
|
}
|
|
1160
640
|
export async function chatCommand(options = {}) {
|
|
1161
641
|
if (process.stdout.isTTY) {
|
|
1162
642
|
process.stdout.write('\u001B[2J\u001B[3J\u001B[H');
|
|
1163
643
|
}
|
|
1164
644
|
await clearTasksFromStore().catch(() => undefined);
|
|
1165
|
-
const app = render(_jsx(ChatScreen, { debug: options.debug, version: options.version, continueSession: options.continueSession, noSession: options.noSession }));
|
|
645
|
+
const app = render(_jsx(ChatScreen, { debug: options.debug, version: options.version, continueSession: options.continueSession, resumeSessionId: options.resumeSessionId, noSession: options.noSession }));
|
|
1166
646
|
await app.waitUntilExit();
|
|
647
|
+
await teardownBackgroundProcesses().catch(() => undefined);
|
|
1167
648
|
await clearTasksFromStore().catch(() => undefined);
|
|
1168
649
|
}
|