@denizokcu/haze 1.1.0 → 1.2.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.
Files changed (149) hide show
  1. package/CHANGELOG.md +49 -1
  2. package/README.md +17 -10
  3. package/SECURITY.md +1 -1
  4. package/dist/buildInfo.json +3 -3
  5. package/dist/cli/chat/busyIndicator.d.ts +11 -0
  6. package/dist/cli/chat/busyIndicator.js +34 -0
  7. package/dist/cli/chat/chatMetrics.d.ts +0 -1
  8. package/dist/cli/chat/chatMetrics.js +1 -7
  9. package/dist/cli/chat/followUpQueue.d.ts +11 -0
  10. package/dist/cli/chat/followUpQueue.js +38 -0
  11. package/dist/cli/chat/messages.d.ts +0 -22
  12. package/dist/cli/chat/messages.js +40 -85
  13. package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
  14. package/dist/cli/chat/sessionLifecycle.js +8 -1
  15. package/dist/cli/chat/sessionRecorder.d.ts +9 -0
  16. package/dist/cli/chat/sessionRecorder.js +12 -0
  17. package/dist/cli/chat/startupSequence.d.ts +29 -0
  18. package/dist/cli/chat/startupSequence.js +59 -0
  19. package/dist/cli/chat/transcriptPartition.d.ts +23 -0
  20. package/dist/cli/chat/transcriptPartition.js +78 -0
  21. package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
  22. package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
  23. package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
  24. package/dist/cli/chat/wizard/lspHandlers.js +85 -0
  25. package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
  26. package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
  27. package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
  28. package/dist/cli/chat/wizard/providerHandlers.js +420 -0
  29. package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
  30. package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
  31. package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
  32. package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
  33. package/dist/cli/chat/wizard/types.d.ts +63 -0
  34. package/dist/cli/chat/wizard/types.js +24 -0
  35. package/dist/cli/chat/wizard/uiState.d.ts +56 -0
  36. package/dist/cli/chat/wizard/uiState.js +15 -0
  37. package/dist/cli/chat/wizardDispatch.d.ts +11 -113
  38. package/dist/cli/chat/wizardDispatch.js +41 -815
  39. package/dist/cli/commands/chat.js +69 -110
  40. package/dist/cli/commands/formatters.d.ts +0 -3
  41. package/dist/cli/commands/formatters.js +0 -29
  42. package/dist/cli/commands/runCommand.d.ts +2 -0
  43. package/dist/cli/commands/runCommand.js +73 -4
  44. package/dist/cli/commands/streaming/agentAttempt.d.ts +11 -1
  45. package/dist/cli/commands/streaming/agentAttempt.js +9 -5
  46. package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
  47. package/dist/cli/commands/streaming/assistantSegments.js +48 -0
  48. package/dist/cli/commands/streaming/attemptOutcome.d.ts +25 -5
  49. package/dist/cli/commands/streaming/attemptOutcome.js +69 -16
  50. package/dist/cli/commands/streaming/attemptSetup.d.ts +10 -3
  51. package/dist/cli/commands/streaming/attemptSetup.js +30 -13
  52. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
  53. package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
  54. package/dist/cli/commands/streaming/goalSupervisor.d.ts +18 -3
  55. package/dist/cli/commands/streaming/goalSupervisor.js +71 -12
  56. package/dist/cli/commands/streaming/prepareStep.d.ts +40 -0
  57. package/dist/cli/commands/streaming/prepareStep.js +116 -0
  58. package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
  59. package/dist/cli/commands/streaming/recoverySlices.js +29 -0
  60. package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
  61. package/dist/cli/commands/streaming/stallRecovery.js +2 -6
  62. package/dist/cli/commands/streaming/streamLoop.d.ts +31 -4
  63. package/dist/cli/commands/streaming/streamLoop.js +283 -268
  64. package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
  65. package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
  66. package/dist/cli/commands/streaming/toolPartHandlers.js +108 -0
  67. package/dist/cli/commands/streaming/turnRuntime.d.ts +1 -1
  68. package/dist/cli/commands/streaming/turnRuntime.js +3 -2
  69. package/dist/cli/commands/streaming.d.ts +12 -1
  70. package/dist/cli/commands/streaming.js +20 -25
  71. package/dist/cli/index.js +6 -3
  72. package/dist/config/modelCatalog.d.ts +32 -0
  73. package/dist/config/modelCatalog.js +84 -0
  74. package/dist/config/providerPresets.d.ts +7 -0
  75. package/dist/config/providerPresets.js +195 -391
  76. package/dist/config/settings.d.ts +10 -2
  77. package/dist/config/settings.js +3 -0
  78. package/dist/core/agent/budgets.d.ts +10 -0
  79. package/dist/core/agent/budgets.js +10 -0
  80. package/dist/core/agent/compaction.d.ts +42 -3
  81. package/dist/core/agent/compaction.js +53 -5
  82. package/dist/core/agent/completionController.d.ts +16 -7
  83. package/dist/core/agent/completionController.js +13 -6
  84. package/dist/core/agent/contextBudget.d.ts +56 -0
  85. package/dist/core/agent/contextBudget.js +53 -0
  86. package/dist/core/agent/errors.js +2 -2
  87. package/dist/core/agent/events.d.ts +36 -1
  88. package/dist/core/agent/goalPolicy.d.ts +4 -3
  89. package/dist/core/agent/goalPolicy.js +9 -4
  90. package/dist/core/agent/overflow.d.ts +45 -0
  91. package/dist/core/agent/overflow.js +91 -0
  92. package/dist/core/agent/requestAssembly.d.ts +7 -0
  93. package/dist/core/agent/requestAssembly.js +15 -7
  94. package/dist/core/agent/workState.d.ts +25 -15
  95. package/dist/core/agent/workState.js +84 -44
  96. package/dist/core/safety/shellClassifier.d.ts +16 -0
  97. package/dist/core/safety/shellClassifier.js +31 -0
  98. package/dist/core/session/sessionSlimming.js +8 -0
  99. package/dist/core/session/sessionStore.d.ts +71 -1
  100. package/dist/core/session/sessionStore.js +121 -6
  101. package/dist/core/validation/outputParser.d.ts +1 -1
  102. package/dist/core/validation/outputParser.js +6 -1
  103. package/dist/llm/client.d.ts +2 -2
  104. package/dist/llm/client.js +14 -6
  105. package/dist/llm/hazeTools.d.ts +64 -208
  106. package/dist/llm/tools/shellTool.js +27 -8
  107. package/dist/llm/tools/taskTool.d.ts +64 -208
  108. package/dist/llm/tools/taskTool.js +22 -10
  109. package/dist/ui/components/TextInput.d.ts +18 -1
  110. package/dist/ui/components/TextInput.js +50 -73
  111. package/dist/ui/components/useInputSuggestions.d.ts +27 -0
  112. package/dist/ui/components/useInputSuggestions.js +98 -0
  113. package/dist/ui/theme.d.ts +8 -8
  114. package/dist/ui/theme.js +11 -12
  115. package/dist/ui/themes/registry.d.ts +5 -0
  116. package/dist/ui/themes/registry.js +436 -0
  117. package/dist/utils/format.d.ts +10 -0
  118. package/dist/utils/format.js +45 -0
  119. package/package.json +16 -15
  120. package/dist/ui/themes/af-magic.d.ts +0 -7
  121. package/dist/ui/themes/af-magic.js +0 -25
  122. package/dist/ui/themes/agnoster.d.ts +0 -10
  123. package/dist/ui/themes/agnoster.js +0 -40
  124. package/dist/ui/themes/bira.d.ts +0 -10
  125. package/dist/ui/themes/bira.js +0 -28
  126. package/dist/ui/themes/bureau.d.ts +0 -10
  127. package/dist/ui/themes/bureau.js +0 -28
  128. package/dist/ui/themes/clean.d.ts +0 -9
  129. package/dist/ui/themes/clean.js +0 -27
  130. package/dist/ui/themes/cloud.d.ts +0 -6
  131. package/dist/ui/themes/cloud.js +0 -24
  132. package/dist/ui/themes/dst.d.ts +0 -10
  133. package/dist/ui/themes/dst.js +0 -28
  134. package/dist/ui/themes/fishy.d.ts +0 -7
  135. package/dist/ui/themes/fishy.js +0 -25
  136. package/dist/ui/themes/index.d.ts +0 -8
  137. package/dist/ui/themes/index.js +0 -36
  138. package/dist/ui/themes/light.d.ts +0 -3
  139. package/dist/ui/themes/light.js +0 -21
  140. package/dist/ui/themes/purple.d.ts +0 -7
  141. package/dist/ui/themes/purple.js +0 -26
  142. package/dist/ui/themes/robbyrussell.d.ts +0 -8
  143. package/dist/ui/themes/robbyrussell.js +0 -26
  144. package/dist/ui/themes/solarized-dark.d.ts +0 -16
  145. package/dist/ui/themes/solarized-dark.js +0 -44
  146. package/dist/ui/themes/solarized-light.d.ts +0 -12
  147. package/dist/ui/themes/solarized-light.js +0 -40
  148. package/dist/ui/themes/steeef.d.ts +0 -11
  149. package/dist/ui/themes/steeef.js +0 -29
@@ -0,0 +1,29 @@
1
+ import { type ContextFile } from '../../config/contextFiles.js';
2
+ import { type HazeSettings } from '../../config/settings.js';
3
+ /** Current git branch name for the workspace header, or undefined outside a repo/branch. */
4
+ export declare function currentBranchName(): Promise<string | undefined>;
5
+ /** What the startup sequence loaded from disk, handed to the screen before the slower steps run. */
6
+ export interface StartupLoadedState {
7
+ settings: HazeSettings;
8
+ settingsError?: string;
9
+ branchName?: string;
10
+ contextFiles: ContextFile[];
11
+ }
12
+ export interface StartupSequenceOptions {
13
+ /** CLI version; when set, an update check runs and outdated builds are reported. */
14
+ version?: string;
15
+ /** Receives the loaded settings/branch/context files as soon as they are read. */
16
+ onLoaded: (loaded: StartupLoadedState) => void;
17
+ /** Session init/continue/resume controller from the screen. */
18
+ initializeSession: () => Promise<void>;
19
+ /** Reloads the skill registry (also reports project-skill and error signatures). */
20
+ refreshSkills: () => Promise<unknown>;
21
+ addSystemMessage: (text: string) => void;
22
+ }
23
+ /**
24
+ * The chat screen's startup sequence, extracted so ChatScreen stays rendering
25
+ * glue: load settings/branch/context files, show the startup banner, initialize
26
+ * the session, load skills, check for updates, and surface runtime diagnostics.
27
+ * Every step degrades to a system message instead of blocking startup.
28
+ */
29
+ export declare function runStartupSequence(options: StartupSequenceOptions): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import { execFile as execFileCallback } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { readContextFiles } from '../../config/contextFiles.js';
4
+ import { readSettings } from '../../config/settings.js';
5
+ import { checkForUpdate } from '../../config/updateCheck.js';
6
+ import { detectCheckoutMismatch, formatMismatchWarning, runtimeCapabilities } from '../../utils/buildInfo.js';
7
+ import { startupContextInfo, startupProviderInfo } from './startupInfo.js';
8
+ const execFile = promisify(execFileCallback);
9
+ /** Current git branch name for the workspace header, or undefined outside a repo/branch. */
10
+ export async function currentBranchName() {
11
+ try {
12
+ const { stdout } = await execFile('git', ['branch', '--show-current'], { cwd: process.cwd() });
13
+ return stdout.trim() || undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ /**
20
+ * The chat screen's startup sequence, extracted so ChatScreen stays rendering
21
+ * glue: load settings/branch/context files, show the startup banner, initialize
22
+ * the session, load skills, check for updates, and surface runtime diagnostics.
23
+ * Every step degrades to a system message instead of blocking startup.
24
+ */
25
+ export async function runStartupSequence(options) {
26
+ const [settingsResult, branch, files] = await Promise.all([
27
+ readSettings().then(value => ({ value, error: undefined })).catch(error => ({ value: {}, error: error instanceof Error ? error.message : String(error) })),
28
+ currentBranchName().catch(() => undefined),
29
+ readContextFiles().catch(() => []),
30
+ ]);
31
+ options.onLoaded({
32
+ settings: settingsResult.value,
33
+ settingsError: settingsResult.error,
34
+ branchName: branch,
35
+ contextFiles: files,
36
+ });
37
+ const next = settingsResult.value;
38
+ options.addSystemMessage(settingsResult.error ? settingsResult.error : `${startupProviderInfo(next)}\n\n${startupContextInfo(files)}`);
39
+ await options.initializeSession().catch(error => {
40
+ const text = error instanceof Error ? error.message : String(error);
41
+ options.addSystemMessage(`Session disabled: ${text}`);
42
+ });
43
+ await options.refreshSkills().catch(() => undefined);
44
+ if (options.version) {
45
+ const result = await checkForUpdate({ currentVersion: options.version, packageName: '@denizokcu/haze' }).catch(() => undefined);
46
+ if (result?.isOutdated) {
47
+ options.addSystemMessage(`A new version of haze is available: ${result.latestVersion} (you have ${options.version}). Update with: npm i -g @denizokcu/haze`);
48
+ }
49
+ }
50
+ // Runtime/installation diagnostics: never switch runtimes silently, but
51
+ // make a stale binary serving a workspace with a newer checkout unmistakable.
52
+ const mismatch = detectCheckoutMismatch();
53
+ if (mismatch) {
54
+ options.addSystemMessage(formatMismatchWarning(mismatch));
55
+ }
56
+ else if (!runtimeCapabilities().goalSupervisorAvailable) {
57
+ options.addSystemMessage('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).');
58
+ }
59
+ }
@@ -0,0 +1,23 @@
1
+ import type { Message } from '../commands/streaming.js';
2
+ export type TranscriptStaticItem = {
3
+ kind: 'message';
4
+ key: string;
5
+ message: Message;
6
+ } | {
7
+ kind: 'assistant-markdown';
8
+ key: string;
9
+ message: Message;
10
+ content: string;
11
+ first: boolean;
12
+ final: boolean;
13
+ };
14
+ export type TranscriptStreamingItem = {
15
+ key: string;
16
+ message: Message;
17
+ showHeader?: boolean;
18
+ };
19
+ /** Partition display messages into append-only static Markdown roots and the active streaming tail. */
20
+ export declare function partitionDisplayMessages(messages: Message[]): {
21
+ staticItems: TranscriptStaticItem[];
22
+ streamingItems: TranscriptStreamingItem[];
23
+ };
@@ -0,0 +1,78 @@
1
+ import { markdownRootChunks } from '../../ui/components/MarkdownText.js';
2
+ /**
3
+ * Pure partitioning of the display transcript into append-only static output
4
+ * and the active dynamic tail (see messages.tsx for the rendering side). Kept
5
+ * free of React so the ordering rules are unit-testable in isolation.
6
+ */
7
+ function messageKey(message, index) {
8
+ return message.id ?? `${index}-${message.role}-${message.text}`;
9
+ }
10
+ function orderedDisplayMessages(messages) {
11
+ return messages
12
+ .map((message, index) => ({ message, index }))
13
+ .sort((a, b) => {
14
+ if (a.message.displayOrder != null && b.message.displayOrder != null && a.message.displayOrder !== b.message.displayOrder) {
15
+ return a.message.displayOrder - b.message.displayOrder;
16
+ }
17
+ return a.index - b.index;
18
+ })
19
+ .map(item => item.message);
20
+ }
21
+ /** Partition display messages into append-only static Markdown roots and the active streaming tail. */
22
+ export function partitionDisplayMessages(messages) {
23
+ const staticItems = [];
24
+ const streamingItems = [];
25
+ let reachedDynamicTail = false;
26
+ orderedDisplayMessages(messages).forEach((message, index) => {
27
+ const key = messageKey(message, index);
28
+ // Static output must remain an ordered prefix. A settled notification that
29
+ // follows live text stays in the dynamic frame until that text is complete.
30
+ if (reachedDynamicTail) {
31
+ streamingItems.push({ key, message });
32
+ return;
33
+ }
34
+ if (message.role !== 'assistant') {
35
+ if (message.streaming) {
36
+ reachedDynamicTail = true;
37
+ streamingItems.push({ key, message });
38
+ }
39
+ else {
40
+ staticItems.push({ kind: 'message', key, message });
41
+ }
42
+ return;
43
+ }
44
+ const chunks = markdownRootChunks(message.text);
45
+ if (chunks.length === 0) {
46
+ if (message.streaming) {
47
+ reachedDynamicTail = true;
48
+ streamingItems.push({ key, message });
49
+ }
50
+ else {
51
+ staticItems.push({ kind: 'message', key, message });
52
+ }
53
+ return;
54
+ }
55
+ // Marked may still reclassify the final root while the stream grows. Keep
56
+ // only that root dynamic; every preceding root is now safe to append once.
57
+ const staticChunkCount = message.streaming ? Math.max(0, chunks.length - 1) : chunks.length;
58
+ for (let chunkIndex = 0; chunkIndex < staticChunkCount; chunkIndex++) {
59
+ staticItems.push({
60
+ kind: 'assistant-markdown',
61
+ key: `${key}-markdown-${chunkIndex}`,
62
+ message,
63
+ content: chunks[chunkIndex] ?? '',
64
+ first: chunkIndex === 0,
65
+ final: !message.streaming && chunkIndex === chunks.length - 1,
66
+ });
67
+ }
68
+ if (message.streaming) {
69
+ reachedDynamicTail = true;
70
+ streamingItems.push({
71
+ key,
72
+ message: { ...message, text: chunks.at(-1) ?? message.text },
73
+ showHeader: staticChunkCount === 0,
74
+ });
75
+ }
76
+ });
77
+ return { staticItems, streamingItems };
78
+ }
@@ -0,0 +1,38 @@
1
+ import type { HazeMcpServer, HazeProviderSettings, HazeSettings } from '../../../config/settings.js';
2
+ import type { Mode } from '../../commands/chatModes.js';
3
+ /** Pure field-transition steps (provider/MCP add flows), applied at the submit boundary. */
4
+ type SharedWizardEffect = {
5
+ type: 'message';
6
+ text?: string;
7
+ } | {
8
+ type: 'mode';
9
+ mode: Mode;
10
+ };
11
+ export type ProviderWizardEffect = SharedWizardEffect | {
12
+ type: 'provider-draft';
13
+ patch: Partial<HazeProviderSettings>;
14
+ replace?: boolean;
15
+ } | {
16
+ type: 'discover-provider-models';
17
+ draft: Partial<HazeProviderSettings>;
18
+ };
19
+ export type McpWizardEffect = SharedWizardEffect | {
20
+ type: 'mcp-draft';
21
+ patch: Partial<HazeMcpServer>;
22
+ } | {
23
+ type: 'finish-mcp-stdio';
24
+ draft: Partial<HazeMcpServer>;
25
+ };
26
+ export declare function transitionProviderField(input: {
27
+ mode: Mode;
28
+ value: string;
29
+ settings: HazeSettings;
30
+ draft: Partial<HazeProviderSettings>;
31
+ }): ProviderWizardEffect[] | undefined;
32
+ export declare function transitionMcpField(input: {
33
+ mode: Mode;
34
+ value: string;
35
+ settings: HazeSettings;
36
+ draft: Partial<HazeMcpServer>;
37
+ }): McpWizardEffect[] | undefined;
38
+ export {};
@@ -0,0 +1,43 @@
1
+ import { captureMcpCommand, captureMcpName, captureMcpTransport, captureMcpUrl, captureProviderName, captureProviderUrl } from '../../commands/wizardFlow.js';
2
+ export function transitionProviderField(input) {
3
+ if (input.mode === 'providerAddKey') {
4
+ const key = input.value.trim();
5
+ return [
6
+ { type: 'provider-draft', patch: key ? { key } : {} },
7
+ { type: 'discover-provider-models', draft: { ...input.draft, ...(key ? { key } : {}) } },
8
+ ];
9
+ }
10
+ const result = input.mode === 'providerAddName' ? captureProviderName(input.settings, input.value)
11
+ : input.mode === 'providerAddUrl' ? captureProviderUrl(input.value)
12
+ : undefined;
13
+ if (!result)
14
+ return undefined;
15
+ if (result.message)
16
+ return [{ type: 'message', text: result.message }];
17
+ const patch = result.draft ?? {};
18
+ return [
19
+ ...(Object.keys(patch).length ? [{ type: 'provider-draft', patch, replace: input.mode === 'providerAddName' }] : []),
20
+ ...(result.nextMode ? [{ type: 'mode', mode: result.nextMode }] : []),
21
+ { type: 'message', text: result.systemMessage },
22
+ ];
23
+ }
24
+ export function transitionMcpField(input) {
25
+ const result = input.mode === 'mcpAddName' ? captureMcpName(input.settings, input.value)
26
+ : input.mode === 'mcpAddTransport' ? captureMcpTransport(input.value)
27
+ : input.mode === 'mcpAddUrl' ? captureMcpUrl(input.value)
28
+ : input.mode === 'mcpAddCommand' ? captureMcpCommand(input.value)
29
+ : undefined;
30
+ if (!result)
31
+ return undefined;
32
+ if (result.message)
33
+ return [{ type: 'message', text: result.message }];
34
+ const patch = result.draft ?? {};
35
+ const nextDraft = { ...input.draft, ...patch };
36
+ if (result.nextMode === 'chat' && input.mode === 'mcpAddCommand')
37
+ return [{ type: 'finish-mcp-stdio', draft: nextDraft }];
38
+ return [
39
+ ...(Object.keys(patch).length ? [{ type: 'mcp-draft', patch }] : []),
40
+ ...(result.nextMode ? [{ type: 'mode', mode: result.nextMode }] : []),
41
+ { type: 'message', text: result.systemMessage },
42
+ ];
43
+ }
@@ -0,0 +1,4 @@
1
+ import type { Mode } from '../../commands/chatModes.js';
2
+ import { type WizardDispatchDeps, type WizardHandler, type WizardSetterContext } from './types.js';
3
+ /** LSP wizard handlers: server picker, presets, actions, custom add, and confirm-remove. */
4
+ export declare function createLspWizardHandlers(deps: WizardDispatchDeps, ctx: WizardSetterContext): Partial<Record<Mode, WizardHandler>>;
@@ -0,0 +1,85 @@
1
+ import { removeLspServer } from '../../../config/lspSettings.js';
2
+ import { SERVER_CHOICES, captureLspName } from '../../commands/wizardFlow.js';
3
+ import { finishLspCustomResult, selectLspActionResult, selectLspPresetResult, selectLspServerResult } from '../../commands/serverWizard.js';
4
+ import { confirmRemoveStep } from './types.js';
5
+ /** LSP wizard handlers: server picker, presets, actions, custom add, and confirm-remove. */
6
+ export function createLspWizardHandlers(deps, ctx) {
7
+ const { setMode, showMessage } = ctx;
8
+ const setLspDraft = ctx.setLspDraft;
9
+ const setSelectedLspName = ctx.setSelectedLspName;
10
+ /** Shared applier for the uniform wizard result shape (CR-006 / useSettingsPatch). */
11
+ async function applyResult(result) {
12
+ if (result.settingsPatch)
13
+ await ctx.applySettings(result.settingsPatch);
14
+ if (result.mode)
15
+ setMode(result.mode);
16
+ showMessage(result.message);
17
+ }
18
+ async function selectLspServer(serverName) {
19
+ const result = selectLspServerResult(deps.settings, serverName);
20
+ if (result.clearDraft)
21
+ setLspDraft({});
22
+ if (serverName === SERVER_CHOICES.addServer)
23
+ setMode('lspAddPreset');
24
+ else if (result.mode)
25
+ setMode(result.mode);
26
+ if (result.selectedName !== undefined)
27
+ setSelectedLspName(result.selectedName);
28
+ showMessage(result.message);
29
+ }
30
+ async function selectLspPreset(presetId) {
31
+ const result = selectLspPresetResult(deps.settings, presetId);
32
+ if (result.clearDraft)
33
+ setLspDraft({});
34
+ await applyResult(result);
35
+ }
36
+ async function selectLspAction(action) {
37
+ const result = selectLspActionResult(deps.settings, deps.wizard.selectedLspName, action);
38
+ if (result.settingsPatch)
39
+ await ctx.applySettings(result.settingsPatch);
40
+ if ('selectedName' in result)
41
+ setSelectedLspName(result.selectedName);
42
+ if (result.mode)
43
+ setMode(result.mode);
44
+ showMessage(result.message);
45
+ }
46
+ async function finishLspCustom(commandLine) {
47
+ const result = finishLspCustomResult(deps.settings, deps.wizard.lspDraft.name, commandLine);
48
+ if (result.settingsPatch)
49
+ await ctx.applySettings(result.settingsPatch);
50
+ if (result.clearDraft)
51
+ setLspDraft({});
52
+ if (result.mode)
53
+ setMode(result.mode);
54
+ showMessage(result.message);
55
+ }
56
+ async function lspAddNameMode(value) {
57
+ const result = captureLspName(deps.settings, value);
58
+ if (result.message) {
59
+ showMessage(result.message);
60
+ return;
61
+ }
62
+ if (result.draft)
63
+ setLspDraft({ name: result.draft.name });
64
+ if (result.nextMode)
65
+ setMode(result.nextMode);
66
+ showMessage(result.systemMessage);
67
+ }
68
+ const lspConfirmRemoveMode = confirmRemoveStep(ctx, {
69
+ selectedName: () => deps.wizard.selectedLspName,
70
+ cancelMessage: 'Cancelled. LSP server not removed.',
71
+ clearSelection: () => setSelectedLspName(undefined),
72
+ remove: async (name) => {
73
+ await ctx.applySettings({ lspServers: removeLspServer(deps.settings, name) });
74
+ return `Removed LSP server ${name}.`;
75
+ },
76
+ });
77
+ return {
78
+ lsp: selectLspServer,
79
+ lspAction: selectLspAction,
80
+ lspAddPreset: selectLspPreset,
81
+ lspAddName: lspAddNameMode,
82
+ lspAddCommand: finishLspCustom,
83
+ lspConfirmRemove: lspConfirmRemoveMode,
84
+ };
85
+ }
@@ -0,0 +1,8 @@
1
+ import type { HazeMcpServer } from '../../../config/settings.js';
2
+ import type { Mode } from '../../commands/chatModes.js';
3
+ import { type WizardDispatchDeps, type WizardHandler, type WizardSetterContext } from './types.js';
4
+ /** MCP wizard handlers: server picker, presets, actions, key steps, and confirm-remove. */
5
+ export declare function createMcpWizardHandlers(deps: WizardDispatchDeps, ctx: WizardSetterContext): {
6
+ handlers: Partial<Record<Mode, WizardHandler>>;
7
+ finishMcpCustom: (keyValue?: string, draft?: Partial<HazeMcpServer>) => Promise<void>;
8
+ };
@@ -0,0 +1,82 @@
1
+ import { removeMcpServer } from '../../../config/mcpSettings.js';
2
+ import { SERVER_CHOICES } from '../../commands/wizardFlow.js';
3
+ import { finishMcpCustomResult, selectMcpActionResult, selectMcpPresetResult, selectMcpServerResult, setMcpServerKeyResult } from '../../commands/serverWizard.js';
4
+ import { confirmRemoveStep } from './types.js';
5
+ /** MCP wizard handlers: server picker, presets, actions, key steps, and confirm-remove. */
6
+ export function createMcpWizardHandlers(deps, ctx) {
7
+ const { setMode, showMessage } = ctx;
8
+ const setMcpDraft = ctx.setMcpDraft;
9
+ const setSelectedMcpName = ctx.setSelectedMcpName;
10
+ async function selectMcpServer(serverName) {
11
+ const result = selectMcpServerResult(deps.settings, serverName);
12
+ if (result.clearDraft)
13
+ setMcpDraft({});
14
+ if (serverName === SERVER_CHOICES.addServer)
15
+ setMode('mcpAddPreset');
16
+ else if (result.mode)
17
+ setMode(result.mode);
18
+ if (result.selectedName !== undefined)
19
+ setSelectedMcpName(result.selectedName);
20
+ showMessage(result.message);
21
+ }
22
+ async function selectMcpPreset(presetId) {
23
+ const result = selectMcpPresetResult(deps.settings, presetId);
24
+ if (result.clearDraft)
25
+ setMcpDraft({});
26
+ if (result.draft)
27
+ setMcpDraft(result.draft);
28
+ if (result.mode)
29
+ setMode(result.mode);
30
+ showMessage(result.message);
31
+ }
32
+ async function selectMcpAction(action) {
33
+ const result = selectMcpActionResult(deps.settings, deps.wizard.selectedMcpName, action);
34
+ if (result.settingsPatch)
35
+ await ctx.applySettings(result.settingsPatch);
36
+ if ('selectedName' in result)
37
+ setSelectedMcpName(result.selectedName);
38
+ if (result.mode)
39
+ setMode(result.mode);
40
+ showMessage(result.message);
41
+ }
42
+ async function finishMcpCustom(keyValue, draft = deps.wizard.mcpDraft) {
43
+ const result = finishMcpCustomResult(deps.settings, draft, keyValue);
44
+ if (result.settingsPatch)
45
+ await ctx.applySettings(result.settingsPatch);
46
+ if (result.clearDraft)
47
+ setMcpDraft({});
48
+ if (result.mode)
49
+ setMode(result.mode);
50
+ showMessage(result.message);
51
+ }
52
+ async function setMcpServerKey(keyValue) {
53
+ const result = setMcpServerKeyResult(deps.settings, deps.wizard.selectedMcpName, keyValue);
54
+ if (result.settingsPatch)
55
+ await ctx.applySettings(result.settingsPatch);
56
+ if ('selectedName' in result)
57
+ setSelectedMcpName(result.selectedName);
58
+ if (result.mode)
59
+ setMode(result.mode);
60
+ showMessage(result.message);
61
+ }
62
+ const mcpConfirmRemoveMode = confirmRemoveStep(ctx, {
63
+ selectedName: () => deps.wizard.selectedMcpName,
64
+ cancelMessage: 'Cancelled. MCP server not removed.',
65
+ clearSelection: () => setSelectedMcpName(undefined),
66
+ remove: async (name) => {
67
+ await ctx.applySettings({ mcpServers: removeMcpServer(deps.settings, name) });
68
+ return `Removed MCP server ${name}.`;
69
+ },
70
+ });
71
+ return {
72
+ handlers: {
73
+ mcp: selectMcpServer,
74
+ mcpAction: selectMcpAction,
75
+ mcpAddPreset: selectMcpPreset,
76
+ mcpAddKey: finishMcpCustom,
77
+ mcpSetKey: setMcpServerKey,
78
+ mcpConfirmRemove: mcpConfirmRemoveMode,
79
+ },
80
+ finishMcpCustom,
81
+ };
82
+ }
@@ -0,0 +1,12 @@
1
+ import type { HazeProviderSettings } from '../../../config/settings.js';
2
+ import type { Mode } from '../../commands/chatModes.js';
3
+ import type { WizardDispatchDeps, WizardHandler, WizardSetterContext } from './types.js';
4
+ /**
5
+ * Provider/model wizard handlers: provider picker and actions, preset-driven
6
+ * add flow (including ChatGPT OAuth), model picker, model discovery, and the
7
+ * add/append/remove-models steps.
8
+ */
9
+ export declare function createProviderWizardHandlers(deps: WizardDispatchDeps, ctx: WizardSetterContext): {
10
+ handlers: Partial<Record<Mode, WizardHandler>>;
11
+ discoverProviderModelsForDraft: (draft: Partial<HazeProviderSettings>) => Promise<void>;
12
+ };