@denizokcu/haze 0.10.0 → 1.0.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 +100 -1
- package/README.md +77 -27
- 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/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- 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 -4
- package/dist/cli/chat/messages.js +218 -35
- package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
- 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/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +349 -133
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +216 -172
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- 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.d.ts +3 -3
- package/dist/cli/commands/formatters.js +8 -25
- 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 +39 -7
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/skillsWizard.d.ts +41 -0
- package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
- package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
- package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
- package/dist/cli/commands/streaming/attemptSetup.js +167 -0
- 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 +130 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
- package/dist/cli/commands/streaming/stallRecovery.js +105 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
- package/dist/cli/commands/streaming/streamLoop.js +448 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
- 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/turnRuntime.d.ts +4 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -0
- package/dist/cli/commands/streaming.d.ts +65 -9
- package/dist/cli/commands/streaming.js +133 -430
- package/dist/cli/commands/wizardFlow.d.ts +334 -0
- package/dist/cli/commands/wizardFlow.js +377 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/contextFiles.js +9 -3
- package/dist/config/inputHistory.d.ts +0 -1
- package/dist/config/inputHistory.js +1 -1
- package/dist/config/modelDiscovery.d.ts +36 -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 +43 -0
- package/dist/config/settings.js +12 -0
- package/dist/config/skillSettings.js +4 -4
- package/dist/config/updateCheck.d.ts +0 -1
- package/dist/config/updateCheck.js +1 -1
- package/dist/core/agent/budgets.d.ts +73 -1
- package/dist/core/agent/budgets.js +94 -1
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +224 -0
- package/dist/core/agent/completionController.js +296 -0
- package/dist/core/agent/contextBudget.d.ts +36 -2
- package/dist/core/agent/contextBudget.js +62 -9
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +78 -0
- package/dist/core/agent/goalPolicy.d.ts +47 -0
- package/dist/core/agent/goalPolicy.js +106 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/requestAssembly.d.ts +2 -2
- package/dist/core/agent/requestAssembly.js +16 -4
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +11 -11
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -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 +81 -3
- package/dist/core/agent/workState.js +176 -10
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +27 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/io/boundedRead.js +1 -1
- package/dist/core/limits.d.ts +51 -0
- package/dist/core/limits.js +51 -0
- package/dist/core/log/llmLog.js +8 -1
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +15 -10
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/shellClassifier.d.ts +11 -0
- package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
- package/dist/core/safety/urlGuard.d.ts +1 -1
- package/dist/core/session/sessionSlimming.d.ts +0 -3
- package/dist/core/session/sessionSlimming.js +2 -3
- package/dist/core/session/sessionStore.d.ts +38 -0
- package/dist/core/session/sessionStore.js +242 -59
- package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
- package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
- package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
- package/dist/core/shellOutput/registry.d.ts +2 -0
- package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
- package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
- package/dist/core/subagent/contracts.d.ts +6 -14
- package/dist/core/subagent/contracts.js +4 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +19 -40
- package/dist/core/toolOutput/reduction.d.ts +0 -12
- package/dist/core/toolOutput/reduction.js +1 -1
- package/dist/core/validation/outputParser.d.ts +2 -2
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +86 -14
- package/dist/llm/hazeTools.d.ts +693 -204
- package/dist/llm/hazeTools.js +110 -28
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp/client.d.ts +45 -0
- package/dist/llm/lsp/client.js +195 -0
- package/dist/llm/lsp/pool.d.ts +23 -0
- package/dist/llm/lsp/pool.js +86 -0
- package/dist/llm/lsp/protocol.d.ts +64 -0
- package/dist/llm/lsp/protocol.js +128 -0
- package/dist/llm/lsp/requests.d.ts +94 -0
- package/dist/llm/lsp/requests.js +119 -0
- package/dist/llm/lspTools.d.ts +5653 -33
- package/dist/llm/lspTools.js +152 -80
- package/dist/llm/openaiCodex.d.ts +1 -0
- package/dist/llm/openaiCodex.js +43 -0
- package/dist/llm/openaiCodexOAuth.d.ts +51 -0
- package/dist/llm/openaiCodexOAuth.js +217 -0
- package/dist/llm/requestContext.d.ts +7 -0
- package/dist/llm/requestContext.js +30 -4
- package/dist/llm/systemPrompt.d.ts +12 -0
- package/dist/llm/systemPrompt.js +24 -11
- package/dist/llm/toolResultTypes.d.ts +7 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +14 -9
- package/dist/llm/tools/editMatch.js +73 -1
- 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/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +8 -5
- package/dist/llm/tools/fileToolShared.js +22 -23
- package/dist/llm/tools/gitIgnore.d.ts +42 -0
- package/dist/llm/tools/gitIgnore.js +247 -0
- package/dist/llm/tools/grepParse.d.ts +2 -1
- package/dist/llm/tools/grepRunner.d.ts +1 -1
- package/dist/llm/tools/grepRunner.js +2 -2
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -3
- package/dist/llm/tools/processTool.d.ts +16 -16
- package/dist/llm/tools/processTool.js +1 -1
- package/dist/llm/tools/readRecovery.d.ts +8 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
- package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +66 -37
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +18 -1
- package/dist/llm/webFetch.js +64 -97
- package/dist/skills/SkillLoader.d.ts +1 -11
- package/dist/skills/SkillLoader.js +1 -2
- package/dist/skills/types.d.ts +2 -1
- 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 +97 -0
- package/dist/utils/buildInfo.js +244 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.js +91 -26
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +6 -2
- 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 +28 -21
- package/dist/cli/commands/lspWizard.d.ts +0 -14
- package/dist/cli/commands/lspWizard.js +0 -44
- package/dist/cli/commands/mcpWizard.d.ts +0 -15
- package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
- package/dist/cli/commands/skillConfirmRemove.js +0 -20
- package/dist/cli/commands/skillCreation.d.ts +0 -12
- package/dist/cli/commands/skillCreation.js +0 -14
- package/dist/cli/commands/skillWizard.d.ts +0 -17
- package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
- package/dist/cli/commands/streaming/idleTimer.js +0 -24
- package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
- package/dist/cli/commands/streaming/turnOutcome.js +0 -13
- package/dist/cli/commands/wizardActions.d.ts +0 -46
- package/dist/cli/commands/wizardActions.js +0 -46
- package/dist/cli/commands/wizardInput.d.ts +0 -4
- package/dist/cli/commands/wizardInput.js +0 -19
- package/dist/cli/commands/wizardPrompts.d.ts +0 -22
- package/dist/cli/commands/wizardPrompts.js +0 -52
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -188
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/bashOutput/ansi.d.ts +0 -1
- package/dist/core/bashOutput/ansi.js +0 -7
- package/dist/core/bashOutput/registry.d.ts +0 -4
- package/dist/core/goal/completionPolicy.d.ts +0 -2
- package/dist/core/goal/completionPolicy.js +0 -7
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -18
- package/dist/core/goal/sessionGoal.d.ts +0 -8
- package/dist/core/goal/sessionGoal.js +0 -30
- package/dist/core/limits/byteBudgets.d.ts +0 -18
- package/dist/core/limits/byteBudgets.js +0 -18
- package/dist/core/limits/textBudgets.d.ts +0 -23
- package/dist/core/limits/textBudgets.js +0 -23
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -129
- package/dist/llm/lsp.js +0 -307
- package/dist/ui/components/ErrorView.d.ts +0 -4
- package/dist/ui/components/ErrorView.js +0 -7
- package/dist/utils/yaml.d.ts +0 -2
- package/dist/utils/yaml.js +0 -8
- package/examples/skills/files/SKILL.md +0 -16
- package/examples/skills/files/examples/file-editing.md +0 -3
- /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateText } from 'ai';
|
|
2
|
+
import { buildLlmCompactionPrompt, compactModelMessages, compactModelMessagesWithSummary, splitForCompaction } from '../../core/agent/compaction.js';
|
|
3
|
+
import { FALLBACK_CONTEXT_WINDOW_TOKENS } from '../../core/agent/contextBudget.js';
|
|
2
4
|
import { clearToolOutputs } from '../../core/agent/toolOutputStore.js';
|
|
5
|
+
import { modelWithConfig } from '../../llm/client.js';
|
|
3
6
|
import { createSession, findSession, forkSession, formatSession, latestSession, restoreSessionState } from '../../core/session/sessionStore.js';
|
|
4
7
|
import { createLog as createLlmLog, endLog as endLlmLog } from '../../core/log/llmLog.js';
|
|
5
8
|
import { displayMessagesFromConversation, estimateConversationTokens } from './chatMetrics.js';
|
|
@@ -16,7 +19,7 @@ export function createSessionLifecycle(deps) {
|
|
|
16
19
|
deps.llmLogRef.current = log;
|
|
17
20
|
return log;
|
|
18
21
|
}
|
|
19
|
-
async function startNewSession(message = '
|
|
22
|
+
async function startNewSession(message = 'New session started.', mergeWithPreviousInfo = false) {
|
|
20
23
|
await teardownBackgroundProcesses().catch(deps.showPersistenceWarning);
|
|
21
24
|
await deps.sessionRecorder()?.flush().catch(deps.showPersistenceWarning);
|
|
22
25
|
clearToolOutputs();
|
|
@@ -27,11 +30,18 @@ export function createSessionLifecycle(deps) {
|
|
|
27
30
|
deps.sessionRef.current = undefined;
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
|
-
const session = await createSession({ hazeVersion: deps.version });
|
|
33
|
+
const session = await createSession({ hazeVersion: deps.version, ...(deps.build ? { build: deps.build } : {}) });
|
|
31
34
|
deps.sessionRef.current = session;
|
|
32
35
|
deps.setTokenUsage({ ...EMPTY_TOKEN_USAGE });
|
|
33
36
|
await startNewLog();
|
|
34
|
-
|
|
37
|
+
const status = `${message}\nSession: ${session.file}`;
|
|
38
|
+
deps.setMessages(messages => {
|
|
39
|
+
const previous = messages.at(-1);
|
|
40
|
+
if (mergeWithPreviousInfo && previous?.role === 'system') {
|
|
41
|
+
return [...messages.slice(0, -1), { ...previous, text: `${previous.text}\n\n${status}` }];
|
|
42
|
+
}
|
|
43
|
+
return [...messages, { role: 'system', text: status }];
|
|
44
|
+
});
|
|
35
45
|
}
|
|
36
46
|
async function resumeSession(session, replaceTranscript) {
|
|
37
47
|
const { messages: conversation, workState, parseErrors } = await restoreSessionState(session);
|
|
@@ -49,6 +59,21 @@ export function createSessionLifecycle(deps) {
|
|
|
49
59
|
return replaceTranscript ? restored : [...messages, ...restored];
|
|
50
60
|
});
|
|
51
61
|
}
|
|
62
|
+
/** Heuristic-excerpt compaction shared by the sync path and the LLM fallback (F-09). */
|
|
63
|
+
function compactConversationSync(instructions) {
|
|
64
|
+
// Manual /compact and overflow recovery use the centralized fallback
|
|
65
|
+
// window (RH-005); the live turn path applies the model-aware budget.
|
|
66
|
+
const result = compactModelMessages(deps.conversationRef.current, { instructions, tokenBudget: FALLBACK_CONTEXT_WINDOW_TOKENS, workState: deps.workStateRef.current });
|
|
67
|
+
if (!result.compacted) {
|
|
68
|
+
deps.setMessages(m => [...m, { role: 'system', text: `Compaction skipped: only ${result.keptCount} model messages in context.` }]);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
deps.conversationRef.current = result.messages;
|
|
72
|
+
deps.sessionRecorder()?.recordNamedEvent('compact', `Compacted ${result.olderCount} messages; kept ${result.keptCount}.`);
|
|
73
|
+
deps.sessionRecorder()?.recordConversation(result.messages);
|
|
74
|
+
deps.setMessages(m => [...m, { role: 'system', text: `Compacted context: condensed ${result.olderCount} older model messages into a bounded excerpt and kept the last ${result.keptCount}.` }]);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
52
77
|
return {
|
|
53
78
|
async initializeSession() {
|
|
54
79
|
if (deps.noSession)
|
|
@@ -71,7 +96,7 @@ export function createSessionLifecycle(deps) {
|
|
|
71
96
|
return;
|
|
72
97
|
}
|
|
73
98
|
}
|
|
74
|
-
await startNewSession(deps.continueSession ? 'No previous session found.
|
|
99
|
+
await startNewSession(deps.continueSession ? 'No previous session found. New session started.' : 'New session started.', true);
|
|
75
100
|
},
|
|
76
101
|
startNewSession,
|
|
77
102
|
async resumeLatestSession() {
|
|
@@ -110,7 +135,7 @@ export function createSessionLifecycle(deps) {
|
|
|
110
135
|
}
|
|
111
136
|
let forked;
|
|
112
137
|
try {
|
|
113
|
-
forked = await forkSession(source, { hazeVersion: deps.version });
|
|
138
|
+
forked = await forkSession(source, { hazeVersion: deps.version, ...(deps.build ? { build: deps.build } : {}) });
|
|
114
139
|
}
|
|
115
140
|
catch (error) {
|
|
116
141
|
deps.setMessages(m => [...m, { role: 'system', text: error instanceof Error ? error.message : String(error) }]);
|
|
@@ -140,16 +165,41 @@ export function createSessionLifecycle(deps) {
|
|
|
140
165
|
await startNewLog().catch(deps.showPersistenceWarning);
|
|
141
166
|
},
|
|
142
167
|
compactConversation(instructions) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
168
|
+
return compactConversationSync(instructions);
|
|
169
|
+
},
|
|
170
|
+
async compactConversationWithModel(instructions) {
|
|
171
|
+
if ((deps.manualCompaction?.() ?? 'llm-summary') === 'heuristic')
|
|
172
|
+
return compactConversationSync(instructions);
|
|
173
|
+
const messages = deps.conversationRef.current;
|
|
174
|
+
const split = splitForCompaction(messages, { tokenBudget: FALLBACK_CONTEXT_WINDOW_TOKENS });
|
|
175
|
+
if (!split) {
|
|
176
|
+
deps.setMessages(m => [...m, { role: 'system', text: `Compaction skipped: only ${messages.length} model messages in context.` }]);
|
|
146
177
|
return false;
|
|
147
178
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
179
|
+
try {
|
|
180
|
+
const runtime = await modelWithConfig();
|
|
181
|
+
if (!runtime?.model)
|
|
182
|
+
throw new Error('no model provider configured');
|
|
183
|
+
const summarization = await generateText({
|
|
184
|
+
model: runtime.model,
|
|
185
|
+
prompt: buildLlmCompactionPrompt({ older: split.older, instructions }),
|
|
186
|
+
});
|
|
187
|
+
const summaryText = summarization.text.trim();
|
|
188
|
+
if (!summaryText)
|
|
189
|
+
throw new Error('model returned an empty summary');
|
|
190
|
+
const result = compactModelMessagesWithSummary(messages, { summaryText, tokenBudget: FALLBACK_CONTEXT_WINDOW_TOKENS, instructions, workState: deps.workStateRef.current });
|
|
191
|
+
if (!result.compacted)
|
|
192
|
+
throw new Error('nothing older to compact');
|
|
193
|
+
deps.conversationRef.current = result.messages;
|
|
194
|
+
deps.sessionRecorder()?.recordNamedEvent('compact', `Compacted ${result.olderCount} messages with a model-written summary; kept ${result.keptCount}.`);
|
|
195
|
+
deps.sessionRecorder()?.recordConversation(result.messages);
|
|
196
|
+
deps.setMessages(m => [...m, { role: 'system', text: `Compacted context: replaced ${result.olderCount} older model messages with a model-written summary and kept the last ${result.keptCount}.` }]);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
deps.debugLog(`LLM compaction failed (${error instanceof Error ? error.message : String(error)}); falling back to the heuristic excerpt`);
|
|
201
|
+
return compactConversationSync(instructions);
|
|
202
|
+
}
|
|
153
203
|
},
|
|
154
204
|
};
|
|
155
205
|
}
|
|
@@ -4,31 +4,99 @@ export function createSessionRecorder(getSession) {
|
|
|
4
4
|
// Ordered appends and first-error capture come from the shared writer
|
|
5
5
|
// primitive; entries recorded before a session exists are dropped (CR-005).
|
|
6
6
|
const writer = new OrderedFileWriter(({ session, entry }) => appendSessionEntry(session, entry));
|
|
7
|
-
const
|
|
7
|
+
const appendEntry = (entry) => {
|
|
8
8
|
const session = getSession();
|
|
9
9
|
if (!session)
|
|
10
10
|
return;
|
|
11
11
|
void writer.append({ session, entry });
|
|
12
12
|
};
|
|
13
|
+
// Full-history snapshot coalescing (RH-008). conversation_snapshot and
|
|
14
|
+
// work_state_snapshot entries are large and only the latest of each is ever
|
|
15
|
+
// restored. A long autonomous turn calls setConversation many times; writing
|
|
16
|
+
// the full history on every call makes the JSONL grow quadratically. Keep at
|
|
17
|
+
// most one snapshot of each type in flight: while a write is pending, newer
|
|
18
|
+
// snapshots replace the pending one so only the latest reaches disk.
|
|
19
|
+
let pendingConversation;
|
|
20
|
+
let pendingWorkState;
|
|
21
|
+
let conversationInFlight = false;
|
|
22
|
+
let workStateInFlight = false;
|
|
23
|
+
const writeConversation = (snapshot) => {
|
|
24
|
+
const session = getSession();
|
|
25
|
+
if (!session)
|
|
26
|
+
return;
|
|
27
|
+
conversationInFlight = true;
|
|
28
|
+
void writer
|
|
29
|
+
.append({ session, entry: { type: 'conversation_snapshot', at: snapshot.at, messages: snapshot.messages } })
|
|
30
|
+
.catch(() => undefined)
|
|
31
|
+
.finally(() => {
|
|
32
|
+
conversationInFlight = false;
|
|
33
|
+
drainConversation();
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const drainConversation = () => {
|
|
37
|
+
if (conversationInFlight || !pendingConversation)
|
|
38
|
+
return;
|
|
39
|
+
const snapshot = pendingConversation;
|
|
40
|
+
pendingConversation = undefined;
|
|
41
|
+
writeConversation(snapshot);
|
|
42
|
+
};
|
|
43
|
+
const writeWorkState = (snapshot) => {
|
|
44
|
+
const session = getSession();
|
|
45
|
+
if (!session)
|
|
46
|
+
return;
|
|
47
|
+
workStateInFlight = true;
|
|
48
|
+
void writer
|
|
49
|
+
.append({ session, entry: { type: 'work_state_snapshot', at: snapshot.at, state: snapshot.state } })
|
|
50
|
+
.catch(() => undefined)
|
|
51
|
+
.finally(() => {
|
|
52
|
+
workStateInFlight = false;
|
|
53
|
+
drainWorkState();
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const drainWorkState = () => {
|
|
57
|
+
if (workStateInFlight || !pendingWorkState)
|
|
58
|
+
return;
|
|
59
|
+
const snapshot = pendingWorkState;
|
|
60
|
+
pendingWorkState = undefined;
|
|
61
|
+
writeWorkState(snapshot);
|
|
62
|
+
};
|
|
13
63
|
return {
|
|
14
64
|
recordUiMessage(message) {
|
|
15
|
-
|
|
65
|
+
appendEntry({ type: 'ui_message', at: new Date().toISOString(), role: message.role, text: message.text });
|
|
16
66
|
},
|
|
17
67
|
recordConversation(messages) {
|
|
18
|
-
|
|
68
|
+
pendingConversation = { messages, at: new Date().toISOString() };
|
|
69
|
+
drainConversation();
|
|
19
70
|
},
|
|
20
71
|
recordWorkState(state) {
|
|
21
|
-
|
|
72
|
+
pendingWorkState = { state, at: new Date().toISOString() };
|
|
73
|
+
drainWorkState();
|
|
22
74
|
},
|
|
23
75
|
recordEvent(event) {
|
|
24
|
-
|
|
76
|
+
// message_update is transient UI progress; never persist it (RH-006). It is
|
|
77
|
+
// dropped here, before JSON.stringify, so high-volume streaming updates do
|
|
78
|
+
// not pay serialization or queueing cost in the durable writer.
|
|
79
|
+
if (event.type === 'message_update')
|
|
80
|
+
return;
|
|
81
|
+
appendEntry({ type: 'event', at: event.at, name: event.type, text: JSON.stringify(event) });
|
|
25
82
|
},
|
|
26
83
|
recordNamedEvent(name, text) {
|
|
27
|
-
|
|
84
|
+
appendEntry({ type: 'event', at: new Date().toISOString(), name, text });
|
|
28
85
|
},
|
|
29
86
|
async flush() {
|
|
87
|
+
// Fold coalesced snapshots into the writer queue, then wait for the queue
|
|
88
|
+
// to drain. Loop because a write completing mid-flush may have queued a
|
|
89
|
+
// newer coalesced snapshot from its finally callback.
|
|
90
|
+
let guard = 0;
|
|
91
|
+
while ((pendingConversation || conversationInFlight || pendingWorkState || workStateInFlight) && guard++ < 1000) {
|
|
92
|
+
drainConversation();
|
|
93
|
+
drainWorkState();
|
|
94
|
+
await writer.flush();
|
|
95
|
+
}
|
|
30
96
|
await writer.flush();
|
|
31
97
|
},
|
|
32
|
-
error() {
|
|
98
|
+
error() {
|
|
99
|
+
return writer.error();
|
|
100
|
+
},
|
|
33
101
|
};
|
|
34
102
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { HazeSettings } from '../../config/settings.js';
|
|
2
2
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
3
|
export declare function startupContextInfo(contextFiles: ContextFile[]): string;
|
|
4
|
-
export declare function startupInputTips(): string;
|
|
5
4
|
export declare function startupProviderInfo(settings: HazeSettings): string;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { activeModel, configuredProviders, providerHasKey } from '../../config/providers.js';
|
|
2
2
|
import { configuredLspServers } from '../../config/lspSettings.js';
|
|
3
3
|
import { configuredMcpServers } from '../../config/mcpSettings.js';
|
|
4
|
+
import { chatgptCodexUrlWarning } from '../commands/providerWizard.js';
|
|
4
5
|
export function startupContextInfo(contextFiles) {
|
|
5
6
|
const lines = contextFiles.map(file => `- ${file.path}`);
|
|
6
7
|
return [
|
|
7
|
-
'Context files
|
|
8
|
+
'Context files included with the first request:',
|
|
8
9
|
...(lines.length > 0 ? lines : ['- none']),
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export function startupInputTips() {
|
|
12
|
-
return [
|
|
13
|
-
'Type @path/to/image.png (or any path with a /) to send images to models with vision capabilities.',
|
|
14
|
-
'',
|
|
15
|
-
'Tab through files in your working directory after typing @',
|
|
16
|
-
'',
|
|
17
|
-
'Mentioning a file or directory with @path, or any /-containing path, lets the model read it, even outside the working directory.',
|
|
18
|
-
'',
|
|
19
|
-
'Edits and writes stay inside the workspace.',
|
|
10
|
+
'Nested AGENTS.md and CLAUDE.md files load when haze works in their subfolders.',
|
|
20
11
|
].join('\n');
|
|
21
12
|
}
|
|
22
13
|
export function startupProviderInfo(settings) {
|
|
@@ -26,12 +17,12 @@ export function startupProviderInfo(settings) {
|
|
|
26
17
|
const enabledLsp = lspServers.filter(server => server.enabled !== false);
|
|
27
18
|
const lspLine = enabledLsp.length > 0
|
|
28
19
|
? `- LSP: ${enabledLsp.length} configured (${enabledLsp.map(server => server.name).join(', ')}; tools appear only when the command is installed)`
|
|
29
|
-
: '- LSP:
|
|
20
|
+
: '- LSP: not configured (optional: use /lsp presets, then /lsp add typescript)';
|
|
30
21
|
const mcpServers = configuredMcpServers(settings);
|
|
31
22
|
const enabledMcp = mcpServers.filter(server => server.enabled !== false);
|
|
32
23
|
const mcpLine = enabledMcp.length > 0
|
|
33
24
|
? `- MCP: ${enabledMcp.length} configured (${enabledMcp.map(server => server.name).join(', ')}; tools load each turn)`
|
|
34
|
-
: '- MCP:
|
|
25
|
+
: '- MCP: not configured (optional: use /mcp add context7 for current library docs)';
|
|
35
26
|
if (!selection) {
|
|
36
27
|
return [
|
|
37
28
|
'Provider configuration',
|
|
@@ -51,12 +42,17 @@ export function startupProviderInfo(settings) {
|
|
|
51
42
|
const baseURL = selection.provider.url;
|
|
52
43
|
const apiKeySource = providerHasKey(settings, selection.provider) ? `provider ${selection.provider.name}` : 'missing';
|
|
53
44
|
const provider = selection.provider.name;
|
|
45
|
+
const authLine = selection.provider.kind === 'chatgpt-codex'
|
|
46
|
+
? '- Authentication: ChatGPT OAuth credentials stored separately'
|
|
47
|
+
: `- API key: ${apiKeySource === 'missing' ? 'not configured; local providers may not need one' : `configured via ${apiKeySource}`}`;
|
|
48
|
+
const divergence = chatgptCodexUrlWarning(selection.provider);
|
|
54
49
|
return [
|
|
55
50
|
'Provider configuration',
|
|
56
51
|
`- Provider: ${provider}`,
|
|
57
52
|
`- Model: ${model} (${modelSource})`,
|
|
58
53
|
`- Base URL: ${baseURL} (settings)`,
|
|
59
|
-
|
|
54
|
+
...(divergence ? [divergence] : []),
|
|
55
|
+
authLine,
|
|
60
56
|
`- Configured providers: ${configuredCount}`,
|
|
61
57
|
lspLine,
|
|
62
58
|
mcpLine,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Task } from '../../core/tasks/taskStorage.js';
|
|
2
|
-
import type { TokenUsage } from '../commands/streaming.js';
|
|
2
|
+
import type { TokenUsage } from '../commands/streaming/turnRuntime.js';
|
|
3
3
|
export declare const EMPTY_TOKEN_USAGE: TokenUsage;
|
|
4
4
|
export declare function shouldClearCompletedTasks(tasks: Task[]): boolean;
|
|
5
5
|
export declare function accumulateTokenUsage(current: TokenUsage, usage: TokenUsage): TokenUsage;
|
|
@@ -4,49 +4,110 @@ import type { LoadedSkill, SkillSource } from '../../skills/types.js';
|
|
|
4
4
|
import type { SessionSummary } from '../../core/session/sessionStore.js';
|
|
5
5
|
import type { Mode } from '../commands/chatModes.js';
|
|
6
6
|
/**
|
|
7
|
-
* Wizard submit
|
|
7
|
+
* Wizard submit engine (CR-006): one table-driven entry point for every
|
|
8
8
|
* picker/wizard mode. Handlers call the pure `*Wizard.ts` result functions and
|
|
9
|
-
* apply the shared settingsPatch/mode/message shape
|
|
9
|
+
* apply the shared settingsPatch/mode/message shape; field-capture steps run
|
|
10
|
+
* through the pure transition functions below, so `chat.tsx` stays
|
|
10
11
|
* orchestration glue instead of a 150-line if-chain.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
type SharedWizardEffect = {
|
|
14
|
+
type: 'message';
|
|
15
|
+
text?: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'mode';
|
|
18
|
+
mode: Mode;
|
|
19
|
+
};
|
|
20
|
+
export type ProviderWizardEffect = SharedWizardEffect | {
|
|
21
|
+
type: 'provider-draft';
|
|
22
|
+
patch: Partial<HazeProviderSettings>;
|
|
23
|
+
replace?: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'discover-provider-models';
|
|
26
|
+
draft: Partial<HazeProviderSettings>;
|
|
27
|
+
};
|
|
28
|
+
export type McpWizardEffect = SharedWizardEffect | {
|
|
29
|
+
type: 'mcp-draft';
|
|
30
|
+
patch: Partial<HazeMcpServer>;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'finish-mcp-stdio';
|
|
33
|
+
draft: Partial<HazeMcpServer>;
|
|
34
|
+
};
|
|
35
|
+
export declare function transitionProviderField(input: {
|
|
36
|
+
mode: Mode;
|
|
37
|
+
value: string;
|
|
13
38
|
settings: HazeSettings;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
draft: Partial<HazeProviderSettings>;
|
|
40
|
+
}): ProviderWizardEffect[] | undefined;
|
|
41
|
+
export declare function transitionMcpField(input: {
|
|
42
|
+
mode: Mode;
|
|
43
|
+
value: string;
|
|
44
|
+
settings: HazeSettings;
|
|
45
|
+
draft: Partial<HazeMcpServer>;
|
|
46
|
+
}): McpWizardEffect[] | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The wizard-related React state that used to live in twelve `useState`
|
|
49
|
+
* hooks in `chat.tsx`. Flat field names match the historical deps names so
|
|
50
|
+
* the dispatch body and its tests read the same way.
|
|
51
|
+
*/
|
|
52
|
+
export interface WizardUiState {
|
|
21
53
|
selectedSessionId?: string;
|
|
54
|
+
modelProviderFilter?: string;
|
|
55
|
+
discoveredModels: string[];
|
|
56
|
+
suggestedModels: string[];
|
|
57
|
+
selectedProviderName?: string;
|
|
22
58
|
providerDraft: Partial<HazeProviderSettings>;
|
|
59
|
+
skillDraft: {
|
|
60
|
+
name?: string;
|
|
61
|
+
scope?: SkillSource;
|
|
62
|
+
};
|
|
63
|
+
selectedSkillName?: string;
|
|
64
|
+
selectedLspName?: string;
|
|
23
65
|
lspDraft: Partial<HazeLspServer>;
|
|
66
|
+
selectedMcpName?: string;
|
|
24
67
|
mcpDraft: Partial<HazeMcpServer>;
|
|
25
|
-
|
|
68
|
+
}
|
|
69
|
+
export type WizardUiAction = {
|
|
70
|
+
type: 'set';
|
|
71
|
+
key: 'selectedSessionId' | 'modelProviderFilter' | 'selectedProviderName' | 'selectedSkillName' | 'selectedLspName' | 'selectedMcpName';
|
|
72
|
+
value: string | undefined;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'providerDraft';
|
|
75
|
+
value: Partial<HazeProviderSettings>;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'skillDraft';
|
|
78
|
+
value: {
|
|
26
79
|
name?: string;
|
|
27
80
|
scope?: SkillSource;
|
|
28
81
|
};
|
|
82
|
+
} | {
|
|
83
|
+
type: 'lspDraft';
|
|
84
|
+
value: Partial<HazeLspServer>;
|
|
85
|
+
} | {
|
|
86
|
+
type: 'mcpDraft';
|
|
87
|
+
value: Partial<HazeMcpServer>;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'discoveredModels';
|
|
90
|
+
value: string[];
|
|
91
|
+
} | {
|
|
92
|
+
type: 'suggestedModels';
|
|
93
|
+
value: string[];
|
|
94
|
+
} | {
|
|
95
|
+
type: 'reset';
|
|
96
|
+
};
|
|
97
|
+
export declare function initialWizardUiState(): WizardUiState;
|
|
98
|
+
export declare function wizardUiReducer(state: WizardUiState, action: WizardUiAction): WizardUiState;
|
|
99
|
+
export interface WizardDispatchDeps {
|
|
100
|
+
settings: HazeSettings;
|
|
101
|
+
skills: LoadedSkill[];
|
|
102
|
+
sessions?: SessionSummary[];
|
|
103
|
+
/** Wizard flow UI state (selection, drafts, model discovery). */
|
|
104
|
+
wizard: WizardUiState;
|
|
105
|
+
updateWizard: (action: WizardUiAction) => void;
|
|
29
106
|
setMode: (mode: Mode) => void;
|
|
30
107
|
setSettings: (next: HazeSettings) => void;
|
|
31
|
-
|
|
32
|
-
setSelectedSkillName: (name: string | undefined) => void;
|
|
33
|
-
setSelectedLspName: (name: string | undefined) => void;
|
|
34
|
-
setSelectedMcpName: (name: string | undefined) => void;
|
|
35
|
-
setSelectedSessionId?: (id: string | undefined) => void;
|
|
108
|
+
showMessage: (message: string | undefined) => void;
|
|
36
109
|
resumeSessionById?: (id: string) => Promise<boolean>;
|
|
37
110
|
forkSessionById?: (id: string) => Promise<boolean>;
|
|
38
|
-
setModelProviderFilter: (filter: string | undefined) => void;
|
|
39
|
-
setProviderDraft: (draft: Partial<HazeProviderSettings>) => void;
|
|
40
|
-
setSkillDraft: (draft: {
|
|
41
|
-
name?: string;
|
|
42
|
-
scope?: SkillSource;
|
|
43
|
-
}) => void;
|
|
44
|
-
setLspDraft: (draft: Partial<HazeLspServer>) => void;
|
|
45
|
-
setMcpDraft: (draft: Partial<HazeMcpServer>) => void;
|
|
46
|
-
setDiscoveredModels: (models: string[]) => void;
|
|
47
|
-
/** Curated preset models pinned atop discovered ones; cleared with discovered models. */
|
|
48
|
-
setSuggestedModels: (models: string[]) => void;
|
|
49
|
-
showMessage: (message: string | undefined) => void;
|
|
50
111
|
refreshSkills: () => Promise<unknown>;
|
|
51
112
|
setBusyLabel: (label: string) => void;
|
|
52
113
|
setBusy: (busy: boolean) => void;
|
|
@@ -62,3 +123,4 @@ export interface WizardDispatch {
|
|
|
62
123
|
discoverProviderModelsForDraft: (draft: Partial<HazeProviderSettings>) => Promise<void>;
|
|
63
124
|
}
|
|
64
125
|
export declare function createWizardDispatch(deps: WizardDispatchDeps): WizardDispatch;
|
|
126
|
+
export {};
|