@denizokcu/haze 0.10.0 → 0.11.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 +77 -1
- package/README.md +66 -25
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -2
- package/dist/cli/chat/messages.js +216 -33
- package/dist/cli/chat/sessionLifecycle.d.ts +9 -0
- package/dist/cli/chat/sessionLifecycle.js +64 -14
- package/dist/cli/chat/sessionRecorder.js +75 -7
- package/dist/cli/chat/startupInfo.d.ts +0 -1
- package/dist/cli/chat/startupInfo.js +11 -15
- package/dist/cli/chat/wizardDispatch.js +111 -12
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +203 -101
- package/dist/cli/commands/commands.d.ts +2 -0
- package/dist/cli/commands/commands.js +10 -5
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/formatters.js +2 -0
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +9 -2
- package/dist/cli/commands/providerWizard.js +37 -4
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +29 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
- package/dist/cli/commands/streaming/turnOutcome.js +27 -11
- package/dist/cli/commands/streaming.d.ts +70 -3
- package/dist/cli/commands/streaming.js +491 -77
- package/dist/cli/commands/wizardActions.d.ts +1 -0
- package/dist/cli/commands/wizardActions.js +1 -0
- package/dist/cli/commands/wizardPrompts.js +7 -1
- package/dist/cli/commands/wizardSuggestions.js +5 -3
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/modelDiscovery.d.ts +51 -0
- package/dist/config/modelDiscovery.js +164 -1
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +39 -7
- package/dist/config/providerPresets.js +371 -100
- package/dist/config/providers.js +2 -0
- package/dist/config/settings.d.ts +36 -0
- package/dist/config/settings.js +9 -0
- package/dist/core/agent/budgets.d.ts +10 -0
- package/dist/core/agent/budgets.js +10 -0
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +230 -0
- package/dist/core/agent/completionController.js +287 -0
- package/dist/core/agent/contextBudget.d.ts +38 -0
- package/dist/core/agent/contextBudget.js +60 -7
- package/dist/core/agent/events.d.ts +74 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
- package/dist/core/agent/toolExecutionBudget.js +49 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +10 -10
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnBudget.d.ts +35 -0
- package/dist/core/agent/turnBudget.js +27 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +75 -0
- package/dist/core/agent/workState.js +120 -9
- package/dist/core/deadline.d.ts +33 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/goal/completionPolicy.d.ts +27 -0
- package/dist/core/goal/completionPolicy.js +37 -1
- package/dist/core/limits/byteBudgets.d.ts +2 -0
- package/dist/core/limits/byteBudgets.js +2 -0
- package/dist/core/limits/textBudgets.d.ts +2 -0
- package/dist/core/limits/textBudgets.js +2 -0
- package/dist/core/log/llmLog.js +7 -0
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.js +8 -7
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/session/sessionStore.d.ts +37 -0
- package/dist/core/session/sessionStore.js +215 -51
- package/dist/core/subagent/contracts.d.ts +4 -0
- package/dist/core/subagent/contracts.js +1 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +17 -37
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +82 -14
- package/dist/llm/hazeTools.d.ts +554 -80
- package/dist/llm/hazeTools.js +103 -24
- package/dist/llm/lsp.d.ts +24 -4
- package/dist/llm/lsp.js +72 -11
- package/dist/llm/lspTools.d.ts +2366 -0
- package/dist/llm/lspTools.js +87 -79
- package/dist/llm/openaiCodex.d.ts +3 -0
- package/dist/llm/openaiCodex.js +47 -0
- package/dist/llm/openaiCodexOAuth.d.ts +54 -0
- package/dist/llm/openaiCodexOAuth.js +214 -0
- package/dist/llm/requestContext.d.ts +3 -0
- package/dist/llm/requestContext.js +7 -4
- package/dist/llm/systemPrompt.d.ts +11 -0
- package/dist/llm/systemPrompt.js +12 -6
- package/dist/llm/toolResultTypes.d.ts +8 -1
- package/dist/llm/tools/bashTool.d.ts +48 -16
- package/dist/llm/tools/bashTool.js +5 -0
- package/dist/llm/tools/editMatch.d.ts +14 -0
- package/dist/llm/tools/editMatch.js +72 -0
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fileToolShared.d.ts +4 -3
- package/dist/llm/tools/fileToolShared.js +16 -21
- package/dist/llm/tools/gitIgnore.d.ts +49 -0
- package/dist/llm/tools/gitIgnore.js +129 -0
- package/dist/llm/tools/readRecovery.d.ts +10 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +61 -32
- package/dist/llm/webFetch.d.ts +17 -0
- package/dist/llm/webFetch.js +64 -97
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +8 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +104 -0
- package/dist/utils/buildInfo.js +253 -0
- package/dist/utils/fs.d.ts +9 -0
- package/dist/utils/fs.js +87 -25
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +5 -1
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +24 -19
|
@@ -2,7 +2,7 @@ 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 { Box, render, Static, Text, useApp,
|
|
5
|
+
import { Box, render, Static, Text, useApp, useWindowSize } from 'ink';
|
|
6
6
|
import Spinner from 'ink-spinner';
|
|
7
7
|
import { readContextFiles } from '../../config/contextFiles.js';
|
|
8
8
|
import { checkForUpdate } from '../../config/updateCheck.js';
|
|
@@ -15,7 +15,7 @@ import { Header } from '../../ui/components/Header.js';
|
|
|
15
15
|
import { TextInput } from '../../ui/components/TextInput.js';
|
|
16
16
|
import { theme } from '../../ui/theme.js';
|
|
17
17
|
import { handleSlashCommand } from './commands.js';
|
|
18
|
-
import {
|
|
18
|
+
import { runAgentGoal } from './streaming/goalSupervisor.js';
|
|
19
19
|
import { formatElapsedTimeWhole, imageAttachmentLine } from './formatters.js';
|
|
20
20
|
import { imageCapabilityError, IMAGE_ONLY_PROMPT_TEXT, resolveImageAttachments } from '../../core/attachments/imageAttachments.js';
|
|
21
21
|
import { resolveReadBlessings } from '../../core/attachments/readBlessings.js';
|
|
@@ -23,12 +23,12 @@ import { endLog as endLlmLog } from '../../core/log/llmLog.js';
|
|
|
23
23
|
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
24
24
|
import { formatSession, listSessions } from '../../core/session/sessionStore.js';
|
|
25
25
|
import { MAX_VISIBLE_TASKS, TaskBar } from '../chat/TaskBar.js';
|
|
26
|
-
import {
|
|
26
|
+
import { AssistantMarkdownChunkView, MessageView, partitionDisplayMessages } from '../chat/messages.js';
|
|
27
27
|
import { createSessionRecorder } from '../chat/sessionRecorder.js';
|
|
28
28
|
import { createSessionLifecycle } from '../chat/sessionLifecycle.js';
|
|
29
29
|
import { createWizardDispatch } from '../chat/wizardDispatch.js';
|
|
30
30
|
import { buildContextReport } from '../chat/contextReport.js';
|
|
31
|
-
import { startupContextInfo,
|
|
31
|
+
import { startupContextInfo, startupProviderInfo } from '../chat/startupInfo.js';
|
|
32
32
|
import { TIPS, randomTipIndex, tipsEnabled } from '../chat/tips.js';
|
|
33
33
|
import { fileMentionSuggestions } from '../chat/fileMentionSuggestions.js';
|
|
34
34
|
import { compactHomePath, formatTokenCount, statusBarMetrics } from '../chat/chatMetrics.js';
|
|
@@ -36,6 +36,7 @@ import { accumulateTokenUsage, EMPTY_TOKEN_USAGE, shouldClearCompletedTasks } fr
|
|
|
36
36
|
import { MASKED_MODES, PICKER_MODES, SUBMIT_EMPTY_MODES, placeholderForMode } from './chatModes.js';
|
|
37
37
|
import { inputSuggestionsForState } from '../chat/inputSuggestions.js';
|
|
38
38
|
import { modelThinkingLabel } from '../../utils/modelName.js';
|
|
39
|
+
import { detectCheckoutMismatch, formatMismatchWarning, runtimeCapabilities } from '../../utils/buildInfo.js';
|
|
39
40
|
import { transitionMcpField, transitionProviderField } from './wizardTransition.js';
|
|
40
41
|
import { commandParts } from './wizardInput.js';
|
|
41
42
|
import { backgroundProcessCount, subscribeBackgroundProcesses, teardownBackgroundProcesses } from '../../core/process/backgroundRegistry.js';
|
|
@@ -60,10 +61,19 @@ function busyElapsedLabel(startedAt) {
|
|
|
60
61
|
function thinkingLabelForSettings(settings) {
|
|
61
62
|
return modelThinkingLabel(activeModel(settings)?.model);
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Busy indicator isolated in its own component. The Spinner animates on its own
|
|
66
|
+
* internal state (~10 fps) which triggers re-renders inside this subtree; keeping
|
|
67
|
+
* the spinner out of ChatScreen's render scope means those ticks don't propagate
|
|
68
|
+
* to the transcript tree above (where React.memo on MessageView already prevents
|
|
69
|
+
* deep re-renders, but avoiding the reconciliation walk entirely is still cheaper).
|
|
70
|
+
*/
|
|
71
|
+
function BusyBar({ label, elapsed, tip }) {
|
|
72
|
+
return _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [_jsx(Box, { children: _jsxs(Text, { children: [_jsxs(Text, { color: theme.command, bold: true, children: [_jsx(Spinner, { type: "dots" }), " ", label, elapsed ? _jsxs(Text, { color: theme.muted, children: [" \u00B7 ", elapsed] }) : null] }), _jsx(Text, { color: theme.muted, children: " \u00B7 type to queue follow-up \u00B7 esc to interrupt" })] }) }), tip && (_jsx(Box, { children: _jsxs(Text, { color: theme.muted, children: [_jsx(Text, { bold: true, children: "Tip:" }), " ", tip] }) }))] });
|
|
73
|
+
}
|
|
74
|
+
function ChatScreen({ debug = false, version, build, continueSession = false, resumeSessionId, noSession = false }) {
|
|
64
75
|
const { exit } = useApp();
|
|
65
|
-
const {
|
|
66
|
-
const width = stdout.columns ?? process.stdout.columns ?? 80;
|
|
76
|
+
const { columns: width, rows: terminalRows } = useWindowSize();
|
|
67
77
|
const nextDisplayOrderRef = useRef(1);
|
|
68
78
|
const withDisplayOrder = (message) => {
|
|
69
79
|
if (message.displayOrder != null)
|
|
@@ -71,9 +81,7 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
71
81
|
return { ...message, displayOrder: nextDisplayOrderRef.current++ };
|
|
72
82
|
};
|
|
73
83
|
const withDisplayOrders = (next) => next.map(withDisplayOrder);
|
|
74
|
-
const [messages, setMessagesRaw] = useState([
|
|
75
|
-
{ role: 'system', text: 'Welcome to haze. Use /help for commands.', displayOrder: 0 }
|
|
76
|
-
]);
|
|
84
|
+
const [messages, setMessagesRaw] = useState([]);
|
|
77
85
|
const setMessages = (updater) => {
|
|
78
86
|
setMessagesRaw(previous => withDisplayOrders(typeof updater === 'function' ? updater(previous) : updater));
|
|
79
87
|
};
|
|
@@ -96,6 +104,11 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
96
104
|
if (!sessionRecorderRef.current)
|
|
97
105
|
sessionRecorderRef.current = createSessionRecorder(() => sessionRef.current);
|
|
98
106
|
const sessionStartRef = useRef(new Date());
|
|
107
|
+
// Stable PromptSession object across turns so per-session flags (the
|
|
108
|
+
// context-fallback warning key) persist; rebuilt when a new session starts,
|
|
109
|
+
// detected by sessionStartRef identity (the lifecycle controller replaces
|
|
110
|
+
// the Date on new/resume/continue).
|
|
111
|
+
const promptSessionRef = useRef({ identity: undefined, value: { cwd: process.cwd() } });
|
|
99
112
|
const workStateRef = useRef(undefined);
|
|
100
113
|
const llmLogRef = useRef(undefined);
|
|
101
114
|
const persistenceWarningShownRef = useRef(false);
|
|
@@ -122,6 +135,11 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
122
135
|
const [taskBarPadding, setTaskBarPadding] = useState(0);
|
|
123
136
|
const [tokenUsage, setTokenUsage] = useState({ ...EMPTY_TOKEN_USAGE });
|
|
124
137
|
const [queuedFollowUps, setQueuedFollowUps] = useState([]);
|
|
138
|
+
// A genuinely paused goal (no measurable progress, deadline, or a stalled
|
|
139
|
+
// model stream) — automatic continuation has already been attempted by the
|
|
140
|
+
// goal supervisor. Carries what a one-key resume needs; any new submission
|
|
141
|
+
// clears it.
|
|
142
|
+
const [pausedResume, setPausedResume] = useState(undefined);
|
|
125
143
|
const [skills, setSkills] = useState([]);
|
|
126
144
|
const [branchName, setBranchName] = useState();
|
|
127
145
|
const [modelProviderFilter, setModelProviderFilter] = useState();
|
|
@@ -173,11 +191,12 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
173
191
|
currentBranchName().then(setBranchName).catch(() => setBranchName(undefined));
|
|
174
192
|
}, [busy]);
|
|
175
193
|
useEffect(() => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
194
|
+
void (async () => {
|
|
195
|
+
const [settingsResult, branch, files] = await Promise.all([
|
|
196
|
+
readSettings().then(value => ({ value, error: undefined })).catch(error => ({ value: {}, error: error instanceof Error ? error.message : String(error) })),
|
|
197
|
+
currentBranchName().catch(() => undefined),
|
|
198
|
+
readContextFiles().catch(() => []),
|
|
199
|
+
]);
|
|
181
200
|
const next = settingsResult.value;
|
|
182
201
|
setSettings(next);
|
|
183
202
|
setSettingsError(settingsResult.error);
|
|
@@ -185,23 +204,29 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
185
204
|
setContextFiles(files);
|
|
186
205
|
contextFileSignaturesRef.current = new Map(files.flatMap(file => file.signature ? [[file.path, file.signature]] : []));
|
|
187
206
|
setMessages(m => [...m, { role: 'system', text: settingsResult.error ? settingsResult.error : `${startupProviderInfo(next)}\n\n${startupContextInfo(files)}` }]);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
loadTasksFromStore().then(setVisibleTasks).catch(() => undefined);
|
|
196
|
-
if (version) {
|
|
197
|
-
checkForUpdate({ currentVersion: version, packageName: '@denizokcu/haze' })
|
|
198
|
-
.then(result => {
|
|
207
|
+
await sessionLifecycle.initializeSession().catch(error => {
|
|
208
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
209
|
+
setMessages(m => [...m, { role: 'system', text: `Session disabled: ${text}` }]);
|
|
210
|
+
});
|
|
211
|
+
await refreshSkills().catch(() => undefined);
|
|
212
|
+
if (version) {
|
|
213
|
+
const result = await checkForUpdate({ currentVersion: version, packageName: '@denizokcu/haze' }).catch(() => undefined);
|
|
199
214
|
if (result?.isOutdated) {
|
|
200
215
|
setMessages(m => [...m, { role: 'system', text: `A new version of haze is available: ${result.latestVersion} (you have ${version}). Update with: npm i -g @denizokcu/haze` }]);
|
|
201
216
|
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
217
|
+
}
|
|
218
|
+
// Runtime/installation diagnostics: never switch runtimes silently, but
|
|
219
|
+
// make a stale binary serving a workspace with a newer checkout unmistakable.
|
|
220
|
+
const mismatch = detectCheckoutMismatch();
|
|
221
|
+
if (mismatch) {
|
|
222
|
+
setMessages(m => [...m, { role: 'system', text: formatMismatchWarning(mismatch) }]);
|
|
223
|
+
}
|
|
224
|
+
else if (!runtimeCapabilities().logicalGoalSupervisor) {
|
|
225
|
+
setMessages(m => [...m, { role: 'system', text: 'Warning: this haze build lacks the goal supervisor module; exhausting a turn step/tool budget may pause the goal instead of continuing automatically. Reinstall or relink haze (npm run dev:link in the checkout).' }]);
|
|
226
|
+
}
|
|
227
|
+
})().catch(() => undefined);
|
|
228
|
+
readInputHistory().then(setInputHistory).catch(() => undefined);
|
|
229
|
+
loadTasksFromStore().then(setVisibleTasks).catch(() => undefined);
|
|
205
230
|
const branchTimer = setInterval(() => {
|
|
206
231
|
currentBranchName().then(setBranchName).catch(() => setBranchName(undefined));
|
|
207
232
|
}, 15_000);
|
|
@@ -254,6 +279,7 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
254
279
|
// dedicated controller so this component stays orchestration glue (CR-006).
|
|
255
280
|
const sessionLifecycle = createSessionLifecycle({
|
|
256
281
|
version,
|
|
282
|
+
build,
|
|
257
283
|
continueSession,
|
|
258
284
|
resumeSessionId,
|
|
259
285
|
noSession,
|
|
@@ -270,10 +296,11 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
270
296
|
setMessages,
|
|
271
297
|
setLiveMessagesState,
|
|
272
298
|
setTokenUsage,
|
|
299
|
+
manualCompaction: () => settings.manualCompaction ?? 'llm-summary',
|
|
273
300
|
debugLog,
|
|
274
301
|
showPersistenceWarning,
|
|
275
302
|
});
|
|
276
|
-
const { clearConversation, compactConversation } = sessionLifecycle;
|
|
303
|
+
const { clearConversation, compactConversation, compactConversationWithModel } = sessionLifecycle;
|
|
277
304
|
async function openSessionPicker() {
|
|
278
305
|
await sessionRecorderRef.current?.flush().catch(showPersistenceWarning);
|
|
279
306
|
const next = await listSessions();
|
|
@@ -366,6 +393,9 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
366
393
|
queueFollowUp(value);
|
|
367
394
|
return;
|
|
368
395
|
}
|
|
396
|
+
// Any new submission supersedes a paused-task resume affordance.
|
|
397
|
+
if (pausedResume)
|
|
398
|
+
setPausedResume(undefined);
|
|
369
399
|
const providerEffects = transitionProviderField({ mode, value, settings, draft: providerDraft });
|
|
370
400
|
if (providerEffects) {
|
|
371
401
|
for (const effect of providerEffects) {
|
|
@@ -421,7 +451,7 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
421
451
|
lastAssistantTextRef.current = '';
|
|
422
452
|
setLiveMessagesState(() => []);
|
|
423
453
|
setMessages([{ role: 'system', text: 'Started fresh. The fog parts.' }]);
|
|
424
|
-
await sessionLifecycle.startNewSession('
|
|
454
|
+
await sessionLifecycle.startNewSession('New session started.');
|
|
425
455
|
},
|
|
426
456
|
resumeSession: noSession ? undefined : async (id) => {
|
|
427
457
|
if (id)
|
|
@@ -431,6 +461,7 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
431
461
|
},
|
|
432
462
|
sessionInfo: () => sessionRef.current ? formatSession(sessionRef.current) : 'Session persistence is off.',
|
|
433
463
|
compactConversation,
|
|
464
|
+
compactConversationLlm: compactConversationWithModel,
|
|
434
465
|
runAgentTurn: (prompt, displayValue, options) => doAgentTurn(prompt, displayValue, options),
|
|
435
466
|
refreshContextFiles: async () => {
|
|
436
467
|
const files = await readContextFiles().catch(() => contextFiles);
|
|
@@ -526,7 +557,42 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
526
557
|
await runSingleAgentTurn(preparedFollowUp.value, preparedFollowUp.displayValue, preparedFollowUp.options);
|
|
527
558
|
}
|
|
528
559
|
}
|
|
529
|
-
|
|
560
|
+
/**
|
|
561
|
+
* Resume a paused turn against the preserved conversation (no re-added user
|
|
562
|
+
* message). An idle-stall resume continues the same logical turn's bounded
|
|
563
|
+
* retry pool; an incomplete-goal resume starts a fresh logical turn (its
|
|
564
|
+
* budget was exhausted) nudged to pick up the remaining concrete work.
|
|
565
|
+
*/
|
|
566
|
+
/**
|
|
567
|
+
* Explicitly resume a genuinely paused goal (automatic continuation already
|
|
568
|
+
* ran): an idle-stall resume continues the bounded retry pool; an
|
|
569
|
+
* incomplete-goal resume restarts the supervisor from the stored checkpoint.
|
|
570
|
+
* Both ride the preserved conversation — no completed mutations are replayed.
|
|
571
|
+
*/
|
|
572
|
+
async function resumePausedTask() {
|
|
573
|
+
const resume = pausedResume;
|
|
574
|
+
if (!resume || busy)
|
|
575
|
+
return;
|
|
576
|
+
setPausedResume(undefined);
|
|
577
|
+
setMessages(m => [...m, { role: 'system', text: 'Resuming the unfinished goal; completed work is preserved in the conversation.' }]);
|
|
578
|
+
const resumeFrom = resume.kind === 'incomplete-goal' && resume.checkpoint
|
|
579
|
+
? { kind: 'incomplete-goal', checkpoint: resume.checkpoint }
|
|
580
|
+
: { kind: 'model-stream-idle', retryAttempt: resume.retryAttempt };
|
|
581
|
+
await runSingleAgentTurn(resume.request, undefined, {}, resumeFrom);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* The PromptSession shared by every turn of the active session. Returning a
|
|
585
|
+
* stable object (not a fresh literal per turn) is what makes once-per-session
|
|
586
|
+
* affordances actually once-per-session; a new session identity yields a
|
|
587
|
+
* fresh object so they fire again at its start.
|
|
588
|
+
*/
|
|
589
|
+
function currentPromptSession() {
|
|
590
|
+
if (promptSessionRef.current.identity !== sessionStartRef.current) {
|
|
591
|
+
promptSessionRef.current = { identity: sessionStartRef.current, value: { start: sessionStartRef.current, cwd: process.cwd() } };
|
|
592
|
+
}
|
|
593
|
+
return promptSessionRef.current.value;
|
|
594
|
+
}
|
|
595
|
+
async function runSingleAgentTurn(value, displayValue, turnOptions = {}, resumeExisting) {
|
|
530
596
|
const sessionRecorder = sessionRecorderRef.current;
|
|
531
597
|
const finalizeMessage = (msg) => {
|
|
532
598
|
if (msg.hidden)
|
|
@@ -535,91 +601,124 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
535
601
|
setMessages(m => [...m, ordered]);
|
|
536
602
|
sessionRecorder.recordUiMessage(ordered);
|
|
537
603
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
setLiveMessagesState(m => m.filter(msg => msg.id !== id));
|
|
553
|
-
finalizeMessage(updated);
|
|
604
|
+
// The logical-goal supervisor owns this submission: recoverable-incomplete
|
|
605
|
+
// physical turns (including step/tool budget boundaries) continue
|
|
606
|
+
// automatically; per-turn limits stay safety boundaries. An explicit
|
|
607
|
+
// resumeFrom restarts a genuinely paused goal from its checkpoint/pool.
|
|
608
|
+
const goalResult = await runAgentGoal({
|
|
609
|
+
request: value,
|
|
610
|
+
displayValue,
|
|
611
|
+
contextFiles,
|
|
612
|
+
session: currentPromptSession(),
|
|
613
|
+
callbacks: {
|
|
614
|
+
addMessage: msg => {
|
|
615
|
+
const ordered = withDisplayOrder(msg);
|
|
616
|
+
if (ordered.streaming) {
|
|
617
|
+
setLiveMessagesState(m => [...m, ordered]);
|
|
554
618
|
return;
|
|
555
619
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
620
|
+
finalizeMessage(ordered);
|
|
621
|
+
},
|
|
622
|
+
updateMessage: (id, update) => {
|
|
623
|
+
const liveMessage = liveMessagesRef.current.find(msg => msg.id === id);
|
|
624
|
+
if (liveMessage) {
|
|
625
|
+
const updated = { ...liveMessage, ...update };
|
|
626
|
+
if (updated.streaming === false) {
|
|
627
|
+
setLiveMessagesState(m => m.filter(msg => msg.id !== id));
|
|
628
|
+
finalizeMessage(updated);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
setLiveMessagesState(m => m.map(msg => msg.id === id ? { ...msg, ...update } : msg));
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
setMessages(m => m.map(msg => msg.id === id ? { ...msg, ...update } : msg));
|
|
635
|
+
},
|
|
636
|
+
setConversation: msgs => {
|
|
637
|
+
conversationRef.current = msgs;
|
|
638
|
+
sessionRecorder.recordConversation(msgs);
|
|
639
|
+
},
|
|
640
|
+
setBusy: setBusyWithHeartbeat,
|
|
641
|
+
setBusyLabel,
|
|
642
|
+
debugLog,
|
|
643
|
+
getConversation: () => conversationRef.current,
|
|
644
|
+
getLastAssistantText: () => lastAssistantTextRef.current,
|
|
645
|
+
setLastAssistantText: text => { lastAssistantTextRef.current = text; },
|
|
646
|
+
setAbortController: controller => { abortControllerRef.current = controller; },
|
|
647
|
+
setWorkState: state => {
|
|
648
|
+
workStateRef.current = state;
|
|
649
|
+
sessionRecorder.recordWorkState(state);
|
|
650
|
+
},
|
|
651
|
+
compactConversation,
|
|
652
|
+
recordTokenUsage: usage => {
|
|
653
|
+
setTokenUsage(current => accumulateTokenUsage(current, usage));
|
|
654
|
+
},
|
|
655
|
+
onEvent: event => {
|
|
656
|
+
sessionRecorder.recordEvent(event);
|
|
657
|
+
},
|
|
658
|
+
onTasksChanged: () => { loadTasksFromStore().then(t => { setVisibleTasks(t); setTaskBarPadding(0); }).catch(() => undefined); },
|
|
659
|
+
contextFileSignatures: contextFileSignaturesRef.current,
|
|
660
|
+
log: llmLogRef.current,
|
|
582
661
|
},
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}, 0, false, false, { start: sessionStartRef.current, cwd: process.cwd() }, undefined, turnOptions);
|
|
662
|
+
...(resumeExisting ? { resumeFrom: resumeExisting } : {}),
|
|
663
|
+
...(turnOptions.attachments || turnOptions.blessedPaths || turnOptions.ephemeralControl || turnOptions.subagentOverrides ? { turnOptions } : {})
|
|
664
|
+
});
|
|
587
665
|
await sessionRecorder.flush().catch(showPersistenceWarning);
|
|
588
666
|
await llmLogRef.current?.writer?.flush().catch(showPersistenceWarning);
|
|
667
|
+
// Only a genuinely paused goal (supervisor already attempted automatic
|
|
668
|
+
// continuation) exposes the one-key resume affordance; it stays until the
|
|
669
|
+
// user submits something else.
|
|
670
|
+
if (goalResult.resume?.kind === 'model-stream-idle')
|
|
671
|
+
setPausedResume({ kind: 'model-stream-idle', request: goalResult.resume.request, retryAttempt: goalResult.resume.retryAttempt });
|
|
672
|
+
else if (goalResult.resume?.kind === 'incomplete-goal')
|
|
673
|
+
setPausedResume({ kind: 'incomplete-goal', request: goalResult.resume.checkpoint.request, retryAttempt: 0, checkpoint: goalResult.resume.checkpoint });
|
|
674
|
+
else
|
|
675
|
+
setPausedResume(undefined);
|
|
676
|
+
return goalResult;
|
|
589
677
|
}
|
|
590
678
|
const visible = messages.filter(message => !message.hidden);
|
|
591
679
|
const activeLiveMessages = liveMessages.filter(message => !message.hidden);
|
|
592
|
-
const
|
|
593
|
-
const transcriptItems = orderedVisibleMessages.filter(message => !message.streaming).map((message, index) => ({ key: messageKey(message, index), message }));
|
|
594
|
-
const streamingItems = orderedVisibleMessages.filter(message => message.streaming);
|
|
680
|
+
const { staticItems: staticTranscriptItems, streamingItems } = partitionDisplayMessages([...visible, ...activeLiveMessages]);
|
|
595
681
|
const activeSelection = activeModel(settings);
|
|
596
682
|
const placeholder = placeholderForMode(mode, busy);
|
|
597
683
|
const activeModelName = activeSelection ? `${activeSelection.provider.name}:${activeSelection.model}` : 'unconfigured';
|
|
598
|
-
const headerSubtitle = [
|
|
599
|
-
'A minimal LLM harness for growing your own workflows while you work.',
|
|
600
|
-
'',
|
|
601
|
-
'Start with simple chat, then teach haze your habits with skills:',
|
|
602
|
-
'/skills — add, enable/disable, validate, or remove Markdown skills.',
|
|
603
|
-
'',
|
|
604
|
-
startupInputTips(),
|
|
605
|
-
'',
|
|
606
|
-
'The most adaptive workflow is the one you shape as you go.',
|
|
607
|
-
'',
|
|
608
|
-
'Guardrails are light: haze lets the LLM work from the terminal almost like you,',
|
|
609
|
-
'while trying to stay scoped to this project.',
|
|
610
|
-
].join('\n');
|
|
684
|
+
const headerSubtitle = (_jsxs(Text, { children: ['A minimal coding agent for your terminal.\n\nStart with chat. Turn repeated work into Markdown skills:\n', _jsx(Text, { color: theme.command, children: "/skills" }), ' — create, enable, disable, validate, or remove skills.\n\nType ', _jsx(Text, { color: theme.command, children: "@" }), ' to browse workspace files. To grant read-only access to a file or directory outside the workspace for this turn, mention a path containing ', _jsx(Text, { color: theme.command, children: "/" }), ' (for example, ', _jsx(Text, { color: theme.command, children: "@../shared/file.ts" }), ' or ', _jsx(Text, { color: theme.command, children: "/tmp/reference.md" }), ').\n\nImage mentions require a vision-capable model. File edits and writes stay inside the workspace.\n\nhaze runs tool calls without confirmation gates. Supervise consequential work as you would any shell session.\n\nShape haze around your workflow as you go.\n\nUse ', _jsx(Text, { color: theme.command, children: "/help" }), ' for commands.'] }));
|
|
611
685
|
const workspaceLabel = `${compactHomePath(process.cwd())}${branchName ? ` (${branchName})` : ''}`;
|
|
612
686
|
const enabledSkillCount = new Set(skills.filter(skill => isSkillEnabled(settings, skill.name, skill.source)).map(skill => skill.name)).size;
|
|
613
687
|
const metrics = statusBarMetrics({ messages: [...messages, ...liveMessages], tokenUsage, enabledSkillCount, backgroundProcessCount: backgroundCount });
|
|
614
688
|
const inputSuggestions = inputSuggestionsForState({ mode, settings, skills, sessions, selectedProviderName, modelProviderFilter, providerDraftName: providerDraft.name, discoveredModels, suggestedModels, selectedSkillName, selectedLspName, selectedMcpName });
|
|
615
689
|
const staticItems = [
|
|
616
|
-
{ kind: 'header', key:
|
|
617
|
-
...
|
|
690
|
+
{ kind: 'header', key: 'header', subtitle: headerSubtitle },
|
|
691
|
+
...staticTranscriptItems,
|
|
618
692
|
];
|
|
619
693
|
const busyElapsed = busyElapsedLabel(turnStartedAtRef.current);
|
|
620
|
-
|
|
694
|
+
const contentWidth = Math.max(1, width - 2);
|
|
695
|
+
// Live-region budget: once the dynamic frame exceeds the viewport, Ink falls
|
|
696
|
+
// back to clearTerminal + full transcript replay, which wipes scrollback and
|
|
697
|
+
// jumps to the top on every render. Every dynamic section is therefore
|
|
698
|
+
// clamped so the frame stays under one screen (see chat/liveRegion.ts).
|
|
699
|
+
const busyRows = busy ? (showingTip ? 2 : 1) : 0;
|
|
700
|
+
const queuedRows = queuedFollowUps.length > 0 ? 2 + queuedFollowUps.length : 0;
|
|
701
|
+
const collapsedTaskRows = Math.min(visibleTasks.length, MAX_VISIBLE_TASKS);
|
|
702
|
+
const expandedTaskCap = Math.max(MAX_VISIBLE_TASKS, terminalRows - 18);
|
|
703
|
+
const expandedTaskRows = Math.min(visibleTasks.length, expandedTaskCap) + (visibleTasks.length > expandedTaskCap ? 1 : 0);
|
|
704
|
+
const taskRows = visibleTasks.length > 0 ? 2 + taskBarPadding + (tasksExpanded ? expandedTaskRows : collapsedTaskRows) : 0;
|
|
705
|
+
// Debug-only panels are counted conservatively so debug mode cannot overflow either.
|
|
706
|
+
const debugPanelRows = debug && debugLogs.length > 0 ? 4 + debugLogs.length : 0;
|
|
707
|
+
const tokenPanelRows = debug && metrics.hasTokenBreakdown ? 5 : 0;
|
|
708
|
+
// The input box is border (2) + one row; a user-pasted multiline draft can
|
|
709
|
+
// exceed this estimate (accepted: it is transient, user-driven editing state).
|
|
710
|
+
const fixedLiveRows = busyRows + queuedRows + taskRows + debugPanelRows + tokenPanelRows + 3 /* input */ + 2 /* status */ + 2 /* safety */;
|
|
711
|
+
const streamingRowsBudget = Math.max(1, terminalRows - fixedLiveRows);
|
|
712
|
+
const perStreamingItemRows = streamingItems.length > 0 ? Math.max(2, Math.floor(streamingRowsBudget / streamingItems.length)) : 0;
|
|
713
|
+
return _jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Static, { items: staticItems, children: item => item.kind === 'header'
|
|
621
714
|
? _jsx(Header, { subtitle: item.subtitle, version: version }, item.key)
|
|
622
|
-
:
|
|
715
|
+
: item.kind === 'assistant-markdown'
|
|
716
|
+
? _jsx(AssistantMarkdownChunkView, { message: item.message, content: item.content, width: contentWidth, first: item.first, final: item.final }, item.key)
|
|
717
|
+
: _jsx(MessageView, { message: item.message, width: contentWidth }, item.key) }), streamingItems.length > 0 && _jsx(Box, { flexDirection: "column", flexShrink: 0, children: streamingItems.map(item => {
|
|
718
|
+
// One row for the optional header plus one for the item's bottom margin.
|
|
719
|
+
const chrome = (item.showHeader === false ? 0 : 1) + 1;
|
|
720
|
+
return _jsx(MessageView, { message: item.message, width: contentWidth, showHeader: item.showHeader, maxVisibleLines: Math.max(1, perStreamingItemRows - chrome) }, item.key);
|
|
721
|
+
}) }), 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, children: [" ", index + 1, ". ", item] }, `${index}-${item}`))] }), pausedResume && !busy && _jsxs(Box, { flexShrink: 0, marginBottom: 1, children: [_jsxs(Text, { color: theme.muted, children: [pausedResume.kind === 'incomplete-goal' ? 'Unfinished goal paused (no measurable progress)' : 'Unfinished goal paused (model stream stalled)', " \u00B7 "] }), _jsxs(Text, { color: theme.command, bold: true, children: ["Press R to ", pausedResume.kind === 'incomplete-goal' ? 'resume' : 'retry'] }), _jsx(Text, { color: theme.muted, children: " or type a follow-up" })] }), visibleTasks.length > 0 && _jsx(Box, { flexDirection: "column", flexShrink: 0, marginBottom: 1, children: _jsx(TaskBar, { tasks: visibleTasks, width: contentWidth, expanded: tasksExpanded, padding: taskBarPadding, maxRows: expandedTaskCap }) }), busy && _jsx(BusyBar, { label: busyLabel, elapsed: busyElapsed, tip: showingTip ? TIPS[tipIndex] : undefined }), _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, contentWidth - 4), getMentionSuggestions: fileMentionSuggestions, onHistoryAdd: persistInputHistory, onToggleTasks: () => {
|
|
623
722
|
if (!tasksExpanded) {
|
|
624
723
|
setTaskBarPadding(0);
|
|
625
724
|
setTasksExpanded(true);
|
|
@@ -630,19 +729,22 @@ function ChatScreen({ debug = false, version, continueSession = false, resumeSes
|
|
|
630
729
|
setTaskBarPadding(Math.max(0, expandedRows - collapsedRows));
|
|
631
730
|
setTasksExpanded(false);
|
|
632
731
|
}
|
|
633
|
-
}, onCancel: cancelThinking, onEscape: () => {
|
|
732
|
+
}, onCancel: cancelThinking, onResumeKey: pausedResume != null && !busy ? resumePausedTask : undefined, onEscape: () => {
|
|
634
733
|
if (busy)
|
|
635
734
|
cancelThinking();
|
|
636
735
|
else
|
|
637
736
|
closeInputList();
|
|
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,
|
|
737
|
+
}, 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, wrap: "truncate-end", children: workspaceLabel }), _jsx(Text, { color: theme.muted, wrap: "truncate-end", children: metrics.statusDetailLabel })] }), _jsx(Box, { flexShrink: 0, marginLeft: 2, children: _jsx(Text, { color: theme.muted, wrap: "truncate-start", children: activeModelName }) })] })] });
|
|
639
738
|
}
|
|
640
739
|
export async function chatCommand(options = {}) {
|
|
641
740
|
if (process.stdout.isTTY) {
|
|
642
741
|
process.stdout.write('\u001B[2J\u001B[3J\u001B[H');
|
|
643
742
|
}
|
|
644
743
|
await clearTasksFromStore().catch(() => undefined);
|
|
645
|
-
|
|
744
|
+
// Incremental rendering rewrites only changed lines of the live frame, removing
|
|
745
|
+
// the full-frame erase/rewrite flicker while streaming. The fps cap aligns with
|
|
746
|
+
// the ~80ms spinner cadence; faster renders would only repaint unchanged lines.
|
|
747
|
+
const app = render(_jsx(ChatScreen, { debug: options.debug, version: options.version, build: options.build, continueSession: options.continueSession, resumeSessionId: options.resumeSessionId, noSession: options.noSession }), { incrementalRendering: true, maxFps: 15 });
|
|
646
748
|
await app.waitUntilExit();
|
|
647
749
|
await teardownBackgroundProcesses().catch(() => undefined);
|
|
648
750
|
await clearTasksFromStore().catch(() => undefined);
|
|
@@ -13,6 +13,8 @@ export type CommandContext = {
|
|
|
13
13
|
resumeSession?: (id?: string) => Promise<void>;
|
|
14
14
|
sessionInfo?: () => string;
|
|
15
15
|
compactConversation?: (instructions?: string) => boolean;
|
|
16
|
+
/** LLM-summarized /compact (F-09); preferred over `compactConversation` when present. */
|
|
17
|
+
compactConversationLlm?: (instructions?: string) => Promise<boolean>;
|
|
16
18
|
runAgentTurn: (prompt: string, displayValue?: string, options?: TurnExecutionOptions) => Promise<void>;
|
|
17
19
|
refreshContextFiles: () => Promise<ContextFile[]>;
|
|
18
20
|
updateSettings: (patch: Partial<HazeSettings>) => Promise<HazeSettings>;
|
|
@@ -33,15 +33,20 @@ const SLASH_COMMANDS = [
|
|
|
33
33
|
await ctx.newSession();
|
|
34
34
|
else
|
|
35
35
|
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
36
|
-
{ match: exactOrArgs('/compact'), run: (args, ctx) => {
|
|
37
|
-
ctx.
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
{ match: exactOrArgs('/compact'), run: async (args, ctx) => {
|
|
37
|
+
if (ctx.compactConversationLlm)
|
|
38
|
+
await ctx.compactConversationLlm(args || undefined);
|
|
39
|
+
else if (ctx.compactConversation)
|
|
40
|
+
ctx.compactConversation(args || undefined);
|
|
41
|
+
else
|
|
42
|
+
ctx.addSystemMessage('Compaction is unavailable.');
|
|
43
|
+
return HANDLED;
|
|
44
|
+
} },
|
|
40
45
|
{ match: exact('/clear'), run: async (_args, ctx) => { await ctx.clearConversation(); await clearTasks(); return HANDLED; } },
|
|
41
46
|
{ match: exactOrArgs('/logs'), run: async (args, ctx) => await handleLogsCommand(args, ctx) },
|
|
42
47
|
{ match: exactOrArgs('/lsp'), run: (_args, ctx) => { ctx.setMode('lsp'); ctx.addSystemMessage('Choose an LSP server to enable, disable, or remove it. Choose "add server" to add one from presets (e.g. typescript) or enter a custom command.'); return HANDLED; } },
|
|
43
48
|
{ match: exactOrArgs('/mcp'), run: (_args, ctx) => { ctx.setMode('mcp'); ctx.addSystemMessage('Choose an MCP server to enable, disable, remove, or set a key for it. Choose "add server" to add one from presets (e.g. context7) or enter custom details.'); return HANDLED; } },
|
|
44
|
-
{ match: value => value === '/settings open' || value === '/settings edit' ? { args: '' } : false, run: async (_args, ctx) => { const file = await ensureSettingsFile(ctx.settings); openPath(file); ctx.addSystemMessage(`Opened settings file: ${file}`); return HANDLED; } },
|
|
49
|
+
{ match: value => value === '/settings open' || value === '/settings edit' ? { args: '' } : false, run: async (_args, ctx) => { const file = await ensureSettingsFile(ctx.settings); await openPath(file); ctx.addSystemMessage(`Opened settings file: ${file}`); return HANDLED; } },
|
|
45
50
|
{ match: exact('/settings'), run: async (_args, ctx) => { ctx.addSystemMessage(await formatSettingsSummary(ctx.settings, ctx.contextFiles)); return HANDLED; } },
|
|
46
51
|
{ match: exact('/provider'), run: (_args, ctx) => { ctx.setModelProviderFilter?.(undefined); ctx.setMode('provider'); ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose "add provider" to pick from presets or enter custom details.'); return HANDLED; } },
|
|
47
52
|
{ match: exact('/init'), run: async (_args, ctx) => await handleInitCommand(ctx) },
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `haze doctor`: runtime provenance and integrity diagnostics. Reports the
|
|
3
|
+
* version/commit actually executing, verifies compiled artifacts and manifest
|
|
4
|
+
* consistency, prints the capability registry, and warns when a nearby source
|
|
5
|
+
* checkout diverges from the running installation. Pure diagnostics — it
|
|
6
|
+
* never switches or repairs anything.
|
|
7
|
+
*
|
|
8
|
+
* Exit code: 1 when the running build itself is broken (missing artifacts,
|
|
9
|
+
* stale manifest); 0 otherwise (a checkout mismatch is a warning, not a
|
|
10
|
+
* failure of the running runtime).
|
|
11
|
+
*/
|
|
12
|
+
export interface DoctorDeps {
|
|
13
|
+
stdout?: {
|
|
14
|
+
write(line: string): void;
|
|
15
|
+
};
|
|
16
|
+
runtimeRoot?: string;
|
|
17
|
+
cwd?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function runDoctor(deps?: DoctorDeps): Promise<number>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { detectCheckoutMismatch, formatCapabilities, formatMismatchWarning, formatVersionVerbose, gitHeadCommit, GOAL_SUPERVISOR_ARTIFACT, readBuildInfo, readPackageVersionAt, resolveExecutable, resolvePackageRoot, runtimeCapabilities, } from '../../utils/buildInfo.js';
|
|
4
|
+
export async function runDoctor(deps = {}) {
|
|
5
|
+
const out = deps.stdout ?? process.stdout;
|
|
6
|
+
const runtimeRoot = deps.runtimeRoot ?? resolvePackageRoot();
|
|
7
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
8
|
+
const write = (line = '') => out.write(`${line}\n`);
|
|
9
|
+
const version = runtimeRoot ? readPackageVersionAt(runtimeRoot) : undefined;
|
|
10
|
+
const build = runtimeRoot ? readBuildInfo([join(runtimeRoot, 'dist', 'buildInfo.json')]) : undefined;
|
|
11
|
+
const capabilities = runtimeCapabilities(runtimeRoot ?? cwd);
|
|
12
|
+
const headCommit = runtimeRoot ? gitHeadCommit(runtimeRoot) : undefined;
|
|
13
|
+
write(formatVersionVerbose({
|
|
14
|
+
version: build?.version ?? version ?? 'unknown',
|
|
15
|
+
build,
|
|
16
|
+
runtimeRoot,
|
|
17
|
+
executable: resolveExecutable(),
|
|
18
|
+
capabilities,
|
|
19
|
+
}));
|
|
20
|
+
write();
|
|
21
|
+
write('Installation');
|
|
22
|
+
write(` root: ${runtimeRoot ?? 'unknown'}`);
|
|
23
|
+
write(` kind: ${headCommit ? 'development checkout (linked or run in place)' : 'installed package (no git metadata)'}`);
|
|
24
|
+
write();
|
|
25
|
+
write('Capabilities');
|
|
26
|
+
for (const [name, enabled] of Object.entries(capabilities)) {
|
|
27
|
+
write(` ${name}: ${enabled ? 'enabled' : 'disabled'}`);
|
|
28
|
+
}
|
|
29
|
+
write();
|
|
30
|
+
const checks = [];
|
|
31
|
+
for (const artifact of ['dist/cli/index.js', GOAL_SUPERVISOR_ARTIFACT, 'dist/buildInfo.json']) {
|
|
32
|
+
const present = runtimeRoot ? existsSync(join(runtimeRoot, artifact)) : false;
|
|
33
|
+
checks.push({ label: `artifact ${artifact}`, state: present ? 'ok' : 'fail', detail: present ? 'present' : 'missing' });
|
|
34
|
+
}
|
|
35
|
+
if (build && version) {
|
|
36
|
+
checks.push(build.version === version
|
|
37
|
+
? { label: 'package/build version', state: 'ok', detail: `${version} == ${version}` }
|
|
38
|
+
: { label: 'package/build version', state: 'fail', detail: `package.json ${version} vs dist/buildInfo.json ${build.version} — rebuild with npm run build` });
|
|
39
|
+
}
|
|
40
|
+
else if (!build) {
|
|
41
|
+
checks.push({ label: 'build manifest', state: 'fail', detail: 'dist/buildInfo.json missing or unreadable — rebuild with npm run build' });
|
|
42
|
+
}
|
|
43
|
+
if (headCommit) {
|
|
44
|
+
checks.push(build?.commit && build.commit !== headCommit
|
|
45
|
+
? { label: 'build commit', state: 'fail', detail: `built from ${build.commit.slice(0, 7)}, checkout HEAD is ${headCommit.slice(0, 7)} — rebuild with npm run build` }
|
|
46
|
+
: { label: 'build commit', state: 'ok', detail: `${(build?.commit ?? headCommit).slice(0, 7)} matches HEAD` });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
checks.push({ label: 'build commit', state: 'warn', detail: 'no git metadata at the installation root (normal for installed packages)' });
|
|
50
|
+
}
|
|
51
|
+
write('Checks');
|
|
52
|
+
for (const check of checks) {
|
|
53
|
+
const marker = check.state === 'ok' ? 'ok' : check.state === 'warn' ? 'warning' : 'FAIL';
|
|
54
|
+
write(` [${marker}] ${check.label}: ${check.detail}`);
|
|
55
|
+
}
|
|
56
|
+
write();
|
|
57
|
+
const mismatch = detectCheckoutMismatch({ executingRoot: runtimeRoot, cwd });
|
|
58
|
+
if (mismatch) {
|
|
59
|
+
write('Checkout mismatch');
|
|
60
|
+
for (const line of formatMismatchWarning(mismatch).split('\n'))
|
|
61
|
+
write(` ${line}`);
|
|
62
|
+
write();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
write('Checkout mismatch: none');
|
|
66
|
+
write();
|
|
67
|
+
}
|
|
68
|
+
if (!capabilities.logicalGoalSupervisor) {
|
|
69
|
+
write('Warning: the goal supervisor is unavailable in this runtime; exhausting a');
|
|
70
|
+
write("turn's step/tool budget may pause the goal instead of continuing automatically.");
|
|
71
|
+
write();
|
|
72
|
+
}
|
|
73
|
+
write(`capability summary: ${formatCapabilities(capabilities)}`);
|
|
74
|
+
const failed = checks.some(check => check.state === 'fail');
|
|
75
|
+
return failed ? 1 : 0;
|
|
76
|
+
}
|