@denizokcu/haze 1.0.0 → 1.1.1

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 (116) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +17 -8
  3. package/SECURITY.md +3 -1
  4. package/dist/buildInfo.json +3 -3
  5. package/dist/cli/chat/TaskBar.js +1 -1
  6. package/dist/cli/chat/busyIndicator.d.ts +11 -0
  7. package/dist/cli/chat/busyIndicator.js +34 -0
  8. package/dist/cli/chat/chatMetrics.d.ts +0 -1
  9. package/dist/cli/chat/chatMetrics.js +1 -7
  10. package/dist/cli/chat/followUpQueue.d.ts +11 -0
  11. package/dist/cli/chat/followUpQueue.js +38 -0
  12. package/dist/cli/chat/inputSuggestions.js +1 -0
  13. package/dist/cli/chat/messages.d.ts +0 -22
  14. package/dist/cli/chat/messages.js +42 -87
  15. package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
  16. package/dist/cli/chat/sessionLifecycle.js +6 -1
  17. package/dist/cli/chat/sessionRecorder.d.ts +2 -0
  18. package/dist/cli/chat/sessionRecorder.js +6 -0
  19. package/dist/cli/chat/startupSequence.d.ts +29 -0
  20. package/dist/cli/chat/startupSequence.js +59 -0
  21. package/dist/cli/chat/transcriptPartition.d.ts +23 -0
  22. package/dist/cli/chat/transcriptPartition.js +78 -0
  23. package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
  24. package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
  25. package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
  26. package/dist/cli/chat/wizard/lspHandlers.js +85 -0
  27. package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
  28. package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
  29. package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
  30. package/dist/cli/chat/wizard/providerHandlers.js +420 -0
  31. package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
  32. package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
  33. package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
  34. package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
  35. package/dist/cli/chat/wizard/types.d.ts +63 -0
  36. package/dist/cli/chat/wizard/types.js +24 -0
  37. package/dist/cli/chat/wizard/uiState.d.ts +56 -0
  38. package/dist/cli/chat/wizard/uiState.js +15 -0
  39. package/dist/cli/chat/wizardDispatch.d.ts +11 -113
  40. package/dist/cli/chat/wizardDispatch.js +41 -805
  41. package/dist/cli/commands/chat.js +89 -110
  42. package/dist/cli/commands/commandHelp.js +2 -0
  43. package/dist/cli/commands/commands.js +2 -0
  44. package/dist/cli/commands/formatters.d.ts +0 -3
  45. package/dist/cli/commands/formatters.js +6 -29
  46. package/dist/cli/commands/runCommand.d.ts +2 -0
  47. package/dist/cli/commands/runCommand.js +67 -4
  48. package/dist/cli/commands/settingsSummary.js +2 -0
  49. package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
  50. package/dist/cli/commands/streaming/assistantSegments.js +48 -0
  51. package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -2
  52. package/dist/cli/commands/streaming/attemptOutcome.js +17 -7
  53. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
  54. package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
  55. package/dist/cli/commands/streaming/goalSupervisor.d.ts +17 -2
  56. package/dist/cli/commands/streaming/goalSupervisor.js +62 -12
  57. package/dist/cli/commands/streaming/prepareStep.d.ts +35 -0
  58. package/dist/cli/commands/streaming/prepareStep.js +100 -0
  59. package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
  60. package/dist/cli/commands/streaming/recoverySlices.js +29 -0
  61. package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
  62. package/dist/cli/commands/streaming/stallRecovery.js +0 -4
  63. package/dist/cli/commands/streaming/streamLoop.js +9 -230
  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 +95 -0
  67. package/dist/cli/commands/streaming.d.ts +4 -1
  68. package/dist/cli/commands/streaming.js +6 -21
  69. package/dist/cli/commands/themesCommand.d.ts +17 -0
  70. package/dist/cli/commands/themesCommand.js +24 -0
  71. package/dist/cli/commands/wizardFlow.d.ts +7 -0
  72. package/dist/cli/commands/wizardFlow.js +20 -0
  73. package/dist/cli/index.js +3 -1
  74. package/dist/config/providerPresets.d.ts +7 -0
  75. package/dist/config/providerPresets.js +195 -391
  76. package/dist/config/settings.d.ts +2 -0
  77. package/dist/config/settings.js +1 -0
  78. package/dist/core/agent/completionController.d.ts +14 -7
  79. package/dist/core/agent/completionController.js +12 -6
  80. package/dist/core/agent/events.d.ts +12 -0
  81. package/dist/core/agent/goalPolicy.d.ts +4 -3
  82. package/dist/core/agent/goalPolicy.js +9 -4
  83. package/dist/core/agent/workState.d.ts +25 -15
  84. package/dist/core/agent/workState.js +71 -43
  85. package/dist/core/safety/secretPaths.d.ts +18 -0
  86. package/dist/core/safety/secretPaths.js +115 -0
  87. package/dist/core/session/sessionSlimming.js +8 -0
  88. package/dist/core/session/sessionStore.d.ts +61 -1
  89. package/dist/core/session/sessionStore.js +115 -6
  90. package/dist/llm/hazeTools.d.ts +64 -208
  91. package/dist/llm/hazeTools.js +6 -0
  92. package/dist/llm/systemPrompt.js +3 -1
  93. package/dist/llm/toolResultTypes.d.ts +1 -1
  94. package/dist/llm/tools/failures.d.ts +6 -0
  95. package/dist/llm/tools/failures.js +8 -2
  96. package/dist/llm/tools/readRecovery.js +2 -0
  97. package/dist/llm/tools/shellTool.js +3 -0
  98. package/dist/llm/tools/taskTool.d.ts +64 -208
  99. package/dist/llm/tools/taskTool.js +22 -10
  100. package/dist/llm/tools/workspaceFile.d.ts +4 -3
  101. package/dist/llm/tools/workspaceFile.js +30 -13
  102. package/dist/ui/components/Header.js +1 -1
  103. package/dist/ui/components/MarkdownText.js +10 -10
  104. package/dist/ui/components/TextInput.d.ts +1 -1
  105. package/dist/ui/components/TextInput.js +8 -69
  106. package/dist/ui/components/useInputSuggestions.d.ts +27 -0
  107. package/dist/ui/components/useInputSuggestions.js +98 -0
  108. package/dist/ui/terminalColors.d.ts +29 -0
  109. package/dist/ui/terminalColors.js +47 -0
  110. package/dist/ui/theme.d.ts +105 -10
  111. package/dist/ui/theme.js +125 -15
  112. package/dist/ui/themes/registry.d.ts +5 -0
  113. package/dist/ui/themes/registry.js +436 -0
  114. package/dist/utils/format.d.ts +10 -0
  115. package/dist/utils/format.js +45 -0
  116. package/package.json +1 -1
@@ -102,7 +102,7 @@ function MarkdownBlock({ token, width, source, textOverride, compactAfter }) {
102
102
  case 'space':
103
103
  return _jsx(Text, { children: " " });
104
104
  case 'hr':
105
- return _jsx(Text, { color: theme.deepPurple, children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" });
105
+ return _jsx(Text, { color: theme.accentDim, children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" });
106
106
  case 'blockquote': {
107
107
  const quote = token;
108
108
  return _jsx(Box, { flexDirection: "column", marginY: 1, children: quote.text.split('\n').map((line, index) => _jsx(Text, { backgroundColor: theme.surfaceBg, children: padAnsi(line || ' ', width) }, index)) });
@@ -130,7 +130,7 @@ function ListItemView({ item, ordered, index, width }) {
130
130
  const markerWidth = visibleLength(marker);
131
131
  const blocks = (item.tokens ?? []).filter(child => child.type !== 'space');
132
132
  if (blocks.length === 0) {
133
- return _jsx(Box, { children: _jsx(Text, { color: theme.purple, children: marker }) });
133
+ return _jsx(Box, { children: _jsx(Text, { color: theme.accent, children: marker }) });
134
134
  }
135
135
  return _jsx(Box, { flexDirection: "column", children: blocks.map((block, blockIndex) => (_jsx(ListItemBlock, { token: block, marker: blockIndex === 0 ? marker : null, markerWidth: markerWidth, width: width }, blockIndex))) });
136
136
  }
@@ -145,26 +145,26 @@ function ListItemBlock({ token, marker, markerWidth, width }) {
145
145
  const contentWidth = Math.max(1, width - markerWidth);
146
146
  const lines = wrapInlineAtoms(splitInlineIntoAtoms(tokenizeInline(text)), contentWidth);
147
147
  const prefix = (lineIndex) => lineIndex === 0 ? (marker ?? ' '.repeat(markerWidth)) : ' '.repeat(markerWidth);
148
- return _jsx(Box, { flexDirection: "column", children: lines.map((line, lineIndex) => (_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: theme.purple, children: prefix(lineIndex) }) }), _jsx(Text, { children: line.map((atom, atomIndex) => atom.type === 'space' ? _jsx(Text, { children: ' ' }, atomIndex) : renderInlinePart(atom, atomIndex)) })] }, lineIndex))) });
148
+ return _jsx(Box, { flexDirection: "column", children: lines.map((line, lineIndex) => (_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: theme.accent, children: prefix(lineIndex) }) }), _jsx(Text, { children: line.map((atom, atomIndex) => atom.type === 'space' ? _jsx(Text, { children: ' ' }, atomIndex) : renderInlinePart(atom, atomIndex)) })] }, lineIndex))) });
149
149
  }
150
150
  // Block-level content (code, nested list, blockquote, table). The marker
151
151
  // sits on its own line when this is the first block; the block then renders
152
152
  // indented to align with the marker.
153
- return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.purple, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(20, width - markerWidth) }) })] });
153
+ return _jsxs(Box, { flexDirection: "column", children: [marker ? _jsx(Text, { color: theme.accent, children: marker }) : null, _jsx(Box, { flexDirection: "column", marginLeft: markerWidth, children: _jsx(MarkdownBlock, { token: token, width: Math.max(20, width - markerWidth) }) })] });
154
154
  }
155
155
  function HeadingBlock({ heading, width }) {
156
156
  const title = stripInline(heading.text).trim();
157
157
  if (heading.depth === 1)
158
- return _jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, children: [_jsx(Text, { color: theme.purple, bold: true, children: title.toUpperCase() }), _jsx(Text, { color: theme.deepPurple, children: '─'.repeat(Math.min(width, Math.max(12, visibleLength(title)))) })] });
158
+ return _jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, children: [_jsx(Text, { color: theme.accent, bold: true, children: title.toUpperCase() }), _jsx(Text, { color: theme.accentDim, children: '─'.repeat(Math.min(width, Math.max(12, visibleLength(title)))) })] });
159
159
  if (heading.depth === 2)
160
- return _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { color: theme.purple, bold: true, children: title }) });
161
- return _jsx(Box, { marginTop: heading.depth <= 3 ? 1 : 0, children: _jsx(Text, { color: theme.purple, bold: true, children: title }) });
160
+ return _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { color: theme.accent, bold: true, children: title }) });
161
+ return _jsx(Box, { marginTop: heading.depth <= 3 ? 1 : 0, children: _jsx(Text, { color: theme.accent, bold: true, children: title }) });
162
162
  }
163
163
  function TableLine({ line }) {
164
164
  if (isTableBorder(line))
165
- return _jsx(Text, { color: theme.deepPurple, children: line });
165
+ return _jsx(Text, { color: theme.accentDim, children: line });
166
166
  return _jsx(Text, { children: [...line].map((char, index) => char === '│'
167
- ? _jsx(Text, { color: theme.deepPurple, children: char }, index)
167
+ ? _jsx(Text, { color: theme.accentDim, children: char }, index)
168
168
  : _jsx(Text, { children: char }, index)) });
169
169
  }
170
170
  function CodeBlock({ code, language, source, width }) {
@@ -245,7 +245,7 @@ function renderInlinePart(part, index) {
245
245
  if (part.kind === 'em')
246
246
  return _jsx(Text, { italic: true, children: part.text }, index);
247
247
  if (part.kind === 'link')
248
- return _jsx(Text, { color: theme.purple, children: part.text }, index);
248
+ return _jsx(Text, { color: theme.accent, children: part.text }, index);
249
249
  return _jsx(Text, { children: part.text }, index);
250
250
  }
251
251
  function splitInlineIntoAtoms(parts) {
@@ -8,7 +8,7 @@ export declare function shouldInsertNewline(input: string, key: TextInputKey): b
8
8
  export type TextInputSuggestion = {
9
9
  value: string;
10
10
  description?: string;
11
- kind?: 'command' | 'skill' | 'provider' | 'model' | 'lsp' | 'mcp' | 'session' | 'file';
11
+ kind?: 'command' | 'skill' | 'provider' | 'model' | 'lsp' | 'mcp' | 'session' | 'file' | 'theme';
12
12
  };
13
13
  /** Cursor-aware path completer for `@token` mentions; receives the token verbatim. */
14
14
  export type MentionSuggestionsProvider = (token: string) => Promise<TextInputSuggestion[]> | TextInputSuggestion[];
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
3
3
  import { Box, Text, useInput } from 'ink';
4
4
  import { theme } from '../theme.js';
5
5
  import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
6
- import { detectMentionAtCursor } from '../../cli/chat/fileMentionSuggestions.js';
6
+ import { useInputSuggestions } from './useInputSuggestions.js';
7
7
  const COMPACT_PASTE_MIN_LINES = 4;
8
8
  const CTRL_ENTER_ESCAPE_INPUTS = new Set(['\u001B[13;5u', '\u001B[13;5~']);
9
9
  export function shouldInsertNewline(input, key) {
@@ -15,10 +15,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
15
15
  const [value, setValue] = useState('');
16
16
  const [cursor, setCursor] = useState(0);
17
17
  const [pasteBlocks, setPasteBlocks] = useState([]);
18
- const [selectedSuggestionIndex, setSelectedSuggestionIndex] = useState(0);
19
- const [mentionContext, setMentionContext] = useState();
20
- const [mentionSuggestions, setMentionSuggestions] = useState([]);
21
- const [mentionSelectedIndex, setMentionSelectedIndex] = useState(0);
22
18
  const history = useRef(historyItems);
23
19
  const historyIndex = useRef(null);
24
20
  const draft = useRef('');
@@ -32,19 +28,19 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
32
28
  setValue('');
33
29
  setCursor(0);
34
30
  setPasteBlocks([]);
35
- setSelectedSuggestionIndex(0);
36
31
  historyIndex.current = null;
37
32
  draft.current = '';
38
33
  nextPasteId.current = 1;
39
34
  }
40
35
  }, [disabled]);
36
+ const suggestionLayers = useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions });
37
+ const { detectedMention, inMentionMode, filteredSuggestions, mentionList, activeMentionIndex, activeSuggestionIndex, activeSuggestion } = suggestionLayers;
41
38
  function setInput(next, nextCursor = next.length, nextPasteBlocks = []) {
42
39
  preferredColumn.current = null;
43
40
  setValue(next);
44
41
  setCursor(Math.max(0, Math.min(nextCursor, next.length)));
45
42
  setPasteBlocks(nextPasteBlocks);
46
- setSelectedSuggestionIndex(0);
47
- setMentionSelectedIndex(0);
43
+ suggestionLayers.resetSelection();
48
44
  }
49
45
  function replaceInput(start, end, inserted) {
50
46
  const normalizedInserted = normalizeLineEndings(inserted);
@@ -61,45 +57,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
61
57
  historyIndex.current = index;
62
58
  setInput(history.current[index] ?? '');
63
59
  }
64
- const suggestionQuery = !mask && (suggestionMode === 'always' || value.startsWith('/'))
65
- ? (suggestionMode === 'always' ? value : value.slice(1)).toLowerCase()
66
- : undefined;
67
- const filteredSuggestions = suggestionQuery == null ? [] : suggestions
68
- .filter(suggestion => {
69
- const suggestionValue = suggestionMode === 'always' ? suggestion.value : suggestion.value.slice(1);
70
- return suggestionValue.toLowerCase().includes(suggestionQuery) || suggestion.description?.toLowerCase().includes(suggestionQuery);
71
- })
72
- .slice(0, 20);
73
- // `@token` mention detection — only in chat mode (slash) so wizard pickers
74
- // never grab `@`-prefixed tokens. Detection is sync; suggestion fetch is
75
- // async with cancellation so fast typing does not race stale results.
76
- const detectedMention = !mask && suggestionMode === 'slash' && !value.startsWith('/') && getMentionSuggestions
77
- ? detectMentionAtCursor(value, cursor)
78
- : undefined;
79
- useEffect(() => {
80
- setMentionContext(detectedMention);
81
- }, [detectedMention?.token, detectedMention?.start, detectedMention?.end]);
82
- useEffect(() => {
83
- if (!mentionContext || !getMentionSuggestions) {
84
- if (mentionSuggestions.length > 0)
85
- setMentionSuggestions([]);
86
- return;
87
- }
88
- let cancelled = false;
89
- Promise.resolve(getMentionSuggestions(mentionContext.token))
90
- .then(results => { if (!cancelled) {
91
- setMentionSuggestions(results);
92
- setMentionSelectedIndex(0);
93
- } })
94
- .catch(() => { if (!cancelled)
95
- setMentionSuggestions([]); });
96
- return () => { cancelled = true; };
97
- }, [mentionContext?.token, mentionContext?.start, mentionContext?.end]);
98
- const inMentionMode = !!detectedMention;
99
- const mentionList = inMentionMode ? mentionSuggestions : [];
100
- const activeMentionIndex = Math.min(mentionSelectedIndex, Math.max(0, mentionList.length - 1));
101
- const activeSuggestionIndex = Math.min(selectedSuggestionIndex, Math.max(0, filteredSuggestions.length - 1));
102
- const activeSuggestion = inMentionMode ? mentionList[activeMentionIndex] : filteredSuggestions[activeSuggestionIndex];
103
60
  const displayValue = mask ? '•'.repeat(value.length) : compactPasteBlocksForDisplay(value, pasteBlocks);
104
61
  const displayCursor = mask ? cursor : displayCursorForValueCursor(pasteBlocks, cursor);
105
62
  const inputWidth = Math.max(1, width - 2);
@@ -196,19 +153,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
196
153
  return;
197
154
  }
198
155
  if (key.upArrow) {
199
- if (inMentionMode && mentionList.length > 0) {
200
- if (activeMentionIndex > 0)
201
- setMentionSelectedIndex(current => Math.max(0, current - 1));
202
- return;
203
- }
204
- if (filteredSuggestions.length > 0 && activeSuggestionIndex > 0) {
205
- setSelectedSuggestionIndex(current => Math.max(0, current - 1));
156
+ if (suggestionLayers.moveSelection(-1))
206
157
  return;
207
- }
208
158
  if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(-1))
209
159
  return;
210
- if (inMentionMode)
211
- return; // no history navigation while completing
212
160
  preferredColumn.current = null;
213
161
  if (history.current.length === 0)
214
162
  return;
@@ -222,19 +170,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
222
170
  return;
223
171
  }
224
172
  if (key.downArrow) {
225
- if (inMentionMode && mentionList.length > 0) {
226
- if (activeMentionIndex < mentionList.length - 1)
227
- setMentionSelectedIndex(current => Math.min(mentionList.length - 1, current + 1));
228
- return;
229
- }
230
- if (filteredSuggestions.length > 0 && activeSuggestionIndex < filteredSuggestions.length - 1) {
231
- setSelectedSuggestionIndex(current => Math.min(filteredSuggestions.length - 1, current + 1));
173
+ if (suggestionLayers.moveSelection(1))
232
174
  return;
233
- }
234
175
  if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(1))
235
176
  return;
236
- if (inMentionMode)
237
- return;
238
177
  preferredColumn.current = null;
239
178
  if (historyIndex.current === null)
240
179
  return;
@@ -284,13 +223,13 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
284
223
  const visibleLines = wrappedLines.slice(firstVisibleLine, firstVisibleLine + maxVisibleLines);
285
224
  const displayList = inMentionMode ? mentionList : filteredSuggestions;
286
225
  const displayActiveIndex = inMentionMode ? activeMentionIndex : activeSuggestionIndex;
287
- return _jsxs(Box, { flexDirection: "column", width: "100%", children: [displayList.length > 0 && _jsx(Box, { flexDirection: "column", marginBottom: 1, children: displayList.map((suggestion, index) => _jsxs(Text, { color: index === displayActiveIndex ? theme.success : theme.muted, wrap: "truncate-end", children: [index === displayActiveIndex ? '› ' : ' ', suggestion.value, _jsxs(Text, { color: theme.muted, children: [" ", suggestion.kind ?? 'command', suggestion.description ? ` — ${suggestion.description}` : ''] })] }, suggestion.value)) }), value.length === 0 ? _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: theme.purple, children: "\u203A " }), _jsx(Text, { inverse: true, children: " " }), _jsxs(Text, { color: theme.muted, children: [" ", placeholder ?? 'Type a message...'] })] }) : visibleLines.map((line, index) => {
226
+ return _jsxs(Box, { flexDirection: "column", width: "100%", children: [displayList.length > 0 && _jsx(Box, { flexDirection: "column", marginBottom: 1, children: displayList.map((suggestion, index) => _jsxs(Text, { color: index === displayActiveIndex ? theme.success : theme.muted, wrap: "truncate-end", children: [index === displayActiveIndex ? '› ' : ' ', suggestion.value, _jsxs(Text, { color: theme.muted, children: [" ", suggestion.kind ?? 'command', suggestion.description ? ` — ${suggestion.description}` : ''] })] }, suggestion.value)) }), value.length === 0 ? _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: theme.accent, children: "\u203A " }), _jsx(Text, { inverse: true, children: " " }), _jsxs(Text, { color: theme.muted, children: [" ", placeholder ?? 'Type a message...'] })] }) : visibleLines.map((line, index) => {
288
227
  const absoluteLineIndex = firstVisibleLine + index;
289
228
  const isCursorLine = absoluteLineIndex === currentCursorPosition.lineIndex;
290
229
  const lineCursor = isCursorLine ? Math.max(0, Math.min(displayCursor - line.start, line.text.length)) : -1;
291
230
  const beforeCursor = isCursorLine ? line.text.slice(0, lineCursor) : line.text;
292
231
  const cursorChar = isCursorLine ? line.text[lineCursor] ?? ' ' : '';
293
232
  const afterCursor = isCursorLine ? line.text.slice(lineCursor + 1) : '';
294
- return _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: absoluteLineIndex === 0 ? theme.purple : theme.muted, children: absoluteLineIndex === 0 ? '› ' : ' ' }), isCursorLine ? _jsxs(_Fragment, { children: [beforeCursor, _jsx(Text, { inverse: true, children: cursorChar }), afterCursor] }) : line.text] }, `${line.start}-${absoluteLineIndex}`);
233
+ return _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: theme.accent, children: absoluteLineIndex === 0 ? '› ' : ' ' }), isCursorLine ? _jsxs(_Fragment, { children: [beforeCursor, _jsx(Text, { inverse: true, children: cursorChar }), afterCursor] }) : line.text] }, `${line.start}-${absoluteLineIndex}`);
295
234
  })] });
296
235
  }
@@ -0,0 +1,27 @@
1
+ import { type MentionContext } from '../../cli/chat/fileMentionSuggestions.js';
2
+ import type { MentionSuggestionsProvider, TextInputSuggestion } from './TextInput.js';
3
+ /**
4
+ * The suggestion engine behind TextInput, extracted as a standalone hook:
5
+ * two composable layers — slash-command filtering (sync, prefix/substring
6
+ * match over the caller's suggestion list) and `@token` mention completion
7
+ * (async fetch with cancellation so fast typing never races stale results) —
8
+ * plus the shared selection state the keyboard handler moves through.
9
+ */
10
+ export declare function useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions }: {
11
+ value: string;
12
+ cursor: number;
13
+ suggestions: TextInputSuggestion[];
14
+ suggestionMode: 'slash' | 'always';
15
+ mask?: boolean;
16
+ getMentionSuggestions?: MentionSuggestionsProvider;
17
+ }): {
18
+ detectedMention: MentionContext | undefined;
19
+ inMentionMode: boolean;
20
+ filteredSuggestions: TextInputSuggestion[];
21
+ mentionList: TextInputSuggestion[];
22
+ activeMentionIndex: number;
23
+ activeSuggestionIndex: number;
24
+ activeSuggestion: TextInputSuggestion;
25
+ resetSelection: () => void;
26
+ moveSelection: (direction: -1 | 1) => boolean;
27
+ };
@@ -0,0 +1,98 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { detectMentionAtCursor } from '../../cli/chat/fileMentionSuggestions.js';
3
+ /**
4
+ * The suggestion engine behind TextInput, extracted as a standalone hook:
5
+ * two composable layers — slash-command filtering (sync, prefix/substring
6
+ * match over the caller's suggestion list) and `@token` mention completion
7
+ * (async fetch with cancellation so fast typing never races stale results) —
8
+ * plus the shared selection state the keyboard handler moves through.
9
+ */
10
+ export function useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions }) {
11
+ const [selectedSuggestionIndex, setSelectedSuggestionIndex] = useState(0);
12
+ const [mentionContext, setMentionContext] = useState();
13
+ const [mentionSuggestions, setMentionSuggestions] = useState([]);
14
+ const [mentionSelectedIndex, setMentionSelectedIndex] = useState(0);
15
+ const suggestionQuery = !mask && (suggestionMode === 'always' || value.startsWith('/'))
16
+ ? (suggestionMode === 'always' ? value : value.slice(1)).toLowerCase()
17
+ : undefined;
18
+ const filteredSuggestions = suggestionQuery == null ? [] : suggestions
19
+ .filter(suggestion => {
20
+ const suggestionValue = suggestionMode === 'always' ? suggestion.value : suggestion.value.slice(1);
21
+ return suggestionValue.toLowerCase().includes(suggestionQuery) || suggestion.description?.toLowerCase().includes(suggestionQuery);
22
+ })
23
+ .slice(0, 20);
24
+ // `@token` mention detection — only in chat mode (slash) so wizard pickers
25
+ // never grab `@`-prefixed tokens. Detection is sync; suggestion fetch is
26
+ // async with cancellation so fast typing does not race stale results.
27
+ const detectedMention = !mask && suggestionMode === 'slash' && !value.startsWith('/') && getMentionSuggestions
28
+ ? detectMentionAtCursor(value, cursor)
29
+ : undefined;
30
+ useEffect(() => {
31
+ setMentionContext(detectedMention);
32
+ }, [detectedMention?.token, detectedMention?.start, detectedMention?.end]);
33
+ useEffect(() => {
34
+ if (!mentionContext || !getMentionSuggestions) {
35
+ if (mentionSuggestions.length > 0)
36
+ setMentionSuggestions([]);
37
+ return;
38
+ }
39
+ let cancelled = false;
40
+ Promise.resolve(getMentionSuggestions(mentionContext.token))
41
+ .then(results => { if (!cancelled) {
42
+ setMentionSuggestions(results);
43
+ setMentionSelectedIndex(0);
44
+ } })
45
+ .catch(() => { if (!cancelled)
46
+ setMentionSuggestions([]); });
47
+ return () => { cancelled = true; };
48
+ }, [mentionContext?.token, mentionContext?.start, mentionContext?.end]);
49
+ const inMentionMode = !!detectedMention;
50
+ const mentionList = inMentionMode ? mentionSuggestions : [];
51
+ const activeMentionIndex = Math.min(mentionSelectedIndex, Math.max(0, mentionList.length - 1));
52
+ const activeSuggestionIndex = Math.min(selectedSuggestionIndex, Math.max(0, filteredSuggestions.length - 1));
53
+ const activeSuggestion = inMentionMode ? mentionList[activeMentionIndex] : filteredSuggestions[activeSuggestionIndex];
54
+ /** Reset both selection layers (called whenever the input value is replaced). */
55
+ function resetSelection() {
56
+ setSelectedSuggestionIndex(0);
57
+ setMentionSelectedIndex(0);
58
+ }
59
+ /**
60
+ * Move the active selection for vertical arrows. Returns true when a
61
+ * suggestion layer consumed the key (mention mode always consumes; the
62
+ * slash list consumes while another entry remains in that direction),
63
+ * false when the caller should fall through to cursor/history handling.
64
+ */
65
+ function moveSelection(direction) {
66
+ if (inMentionMode) {
67
+ if (mentionList.length > 0) {
68
+ if (direction < 0)
69
+ setMentionSelectedIndex(current => Math.max(0, current - 1));
70
+ else
71
+ setMentionSelectedIndex(current => Math.min(mentionList.length - 1, current + 1));
72
+ }
73
+ return true;
74
+ }
75
+ if (filteredSuggestions.length > 0) {
76
+ if (direction < 0 && activeSuggestionIndex > 0) {
77
+ setSelectedSuggestionIndex(current => Math.max(0, current - 1));
78
+ return true;
79
+ }
80
+ if (direction > 0 && activeSuggestionIndex < filteredSuggestions.length - 1) {
81
+ setSelectedSuggestionIndex(current => Math.min(filteredSuggestions.length - 1, current + 1));
82
+ return true;
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ return {
88
+ detectedMention,
89
+ inMentionMode,
90
+ filteredSuggestions,
91
+ mentionList,
92
+ activeMentionIndex,
93
+ activeSuggestionIndex,
94
+ activeSuggestion,
95
+ resetSelection,
96
+ moveSelection,
97
+ };
98
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Terminal default color control via OSC escape sequences.
3
+ *
4
+ * A haze theme paints both terminal defaults, not just one side:
5
+ * OSC 10 — default foreground (the theme's `foreground` role)
6
+ * OSC 11 — default background (the theme's `background` role)
7
+ * OSC 110/111 — restore the terminal's own defaults on exit
8
+ *
9
+ * This pairing matters because haze renders plenty of unstyled `<Text>` that
10
+ * inherits the terminal defaults (diff code lines, plain transcript text).
11
+ * Adopting only the background would repaint that text's canvas — e.g. to
12
+ * Solarized Light's cream — while a dark-configured terminal keeps its white
13
+ * default foreground: unreadable. Adopting both sides keeps fg/bg contrast
14
+ * owned by the theme. Supported terminals (iTerm2, kitty, alacritty, wezterm,
15
+ * xterm, gnome-terminal, foot, …) honor the sequences; others ignore them, so
16
+ * haze stays as readable as the terminal's own configuration.
17
+ *
18
+ * Helpers are write-only on purpose: querying current colors (OSC 10/11 ?)
19
+ * would race the Ink app for stdin. Malformed colors never emit anything.
20
+ */
21
+ /** Minimal writable-terminal shape so tests can pass a fake stream. */
22
+ export interface TerminalColorStream {
23
+ write(chunk: string): unknown;
24
+ isTTY?: boolean;
25
+ }
26
+ /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY. */
27
+ export declare function applyTerminalColors(foreground: string, background: string, stream?: TerminalColorStream): void;
28
+ /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY. */
29
+ export declare function resetTerminalColors(stream?: TerminalColorStream): void;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Terminal default color control via OSC escape sequences.
3
+ *
4
+ * A haze theme paints both terminal defaults, not just one side:
5
+ * OSC 10 — default foreground (the theme's `foreground` role)
6
+ * OSC 11 — default background (the theme's `background` role)
7
+ * OSC 110/111 — restore the terminal's own defaults on exit
8
+ *
9
+ * This pairing matters because haze renders plenty of unstyled `<Text>` that
10
+ * inherits the terminal defaults (diff code lines, plain transcript text).
11
+ * Adopting only the background would repaint that text's canvas — e.g. to
12
+ * Solarized Light's cream — while a dark-configured terminal keeps its white
13
+ * default foreground: unreadable. Adopting both sides keeps fg/bg contrast
14
+ * owned by the theme. Supported terminals (iTerm2, kitty, alacritty, wezterm,
15
+ * xterm, gnome-terminal, foot, …) honor the sequences; others ignore them, so
16
+ * haze stays as readable as the terminal's own configuration.
17
+ *
18
+ * Helpers are write-only on purpose: querying current colors (OSC 10/11 ?)
19
+ * would race the Ink app for stdin. Malformed colors never emit anything.
20
+ */
21
+ const HEX_COLOR = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
22
+ /** `#rrggbb` → OSC rgb payload (`rr/gg/bb`), or undefined for malformed input. */
23
+ function oscRgb(color) {
24
+ const match = HEX_COLOR.exec(color.trim());
25
+ if (!match)
26
+ return undefined;
27
+ const [, r = '', g = '', b = ''] = match;
28
+ return `${r.toLowerCase()}/${g.toLowerCase()}/${b.toLowerCase()}`;
29
+ }
30
+ /** Adopt a theme's foreground/background as the terminal defaults (OSC 10 + 11). Malformed parts are skipped; no-op off-TTY. */
31
+ export function applyTerminalColors(foreground, background, stream = process.stdout) {
32
+ if (!stream.isTTY)
33
+ return;
34
+ const fg = oscRgb(foreground);
35
+ const bg = oscRgb(background);
36
+ if (fg)
37
+ stream.write(`\u001B]10;rgb:${fg}\u0007`);
38
+ if (bg)
39
+ stream.write(`\u001B]11;rgb:${bg}\u0007`);
40
+ }
41
+ /** Restore the terminal's own default colors (OSC 110 + 111). No-op off-TTY. */
42
+ export function resetTerminalColors(stream = process.stdout) {
43
+ if (!stream.isTTY)
44
+ return;
45
+ stream.write('\u001B]110\u0007');
46
+ stream.write('\u001B]111\u0007');
47
+ }
@@ -1,16 +1,111 @@
1
- export declare const theme: {
2
- foreground: string;
3
- purple: string;
4
- deepPurple: string;
5
- blue: string;
1
+ /**
2
+ * Haze theming core, aligned with the oh-my-zsh / zsh `colors` vocabulary so
3
+ * that oh-my-zsh themes port over with minimal effort.
4
+ *
5
+ * oh-my-zsh themes never define RGB colors. They reference terminal palette
6
+ * slots using zsh's `colors` vocabulary:
7
+ *
8
+ * $fg[cyan] → the named palette slot `cyan`
9
+ * $fg_bold[green] → named slot `green` (bold is a text attribute, not a color)
10
+ * ${FG[214]} / %F{214} → an xterm-256 color index
11
+ * %F{#ff8800} → truecolor hex
12
+ *
13
+ * Haze themes mirror that split in two layers:
14
+ *
15
+ * 1. Palette — `ZSH_NAMED_COLORS`, one entry per zsh `colors` key
16
+ * (`black red green yellow blue magenta cyan white default`), approximated
17
+ * as RGB because haze cannot assume the host terminal's palette.
18
+ * A theme spec may override slots with `palette`.
19
+ * 2. Roles — semantic haze surfaces (accent, command, warning, …) whose
20
+ * values are written in the same vocabulary an oh-my-zsh theme uses:
21
+ * a zsh color name, an xterm-256 index string, or `#rrggbb` hex.
22
+ *
23
+ * The built-in themes live in `src/ui/themes/registry.ts` — one data entry per
24
+ * theme, named like its oh-my-zsh counterpart — including ports of famous
25
+ * `.zsh-theme` files where `robbyrussell`'s `$fg_bold[green]➜` becomes
26
+ * `accent: 'green'`, its `$fg[cyan]%c` becomes `command: 'cyan'`, etc. See
27
+ * `src/ui/themes/AGENTS.md` for the full conversion guide and the segment →
28
+ * role translation table.
29
+ */
30
+ import { THEMES } from './themes/registry.js';
31
+ export { THEMES as BUILT_IN_THEME_SPECS };
32
+ /** The theme used when settings name none; also the fallback base for roles another theme omits. */
33
+ export declare const DEFAULT_THEME_NAME = "purple";
34
+ /** zsh `colors` associative-array keys — exactly the names `$fg[...]` accepts. */
35
+ export type ZshColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'default';
36
+ export declare const ZSH_COLOR_NAMES: readonly ZshColorName[];
37
+ /**
38
+ * RGB approximation of the terminal palette slots the zsh names reference,
39
+ * based on the Tango palette (GNOME Terminal's classic default) because
40
+ * oh-my-zsh themes leave the actual RGB to the terminal. `default` approximates
41
+ * the terminal's default foreground color.
42
+ */
43
+ export declare const ZSH_NAMED_COLORS: Record<ZshColorName, string>;
44
+ /**
45
+ * A theme color value, written the way oh-my-zsh writes colors:
46
+ * a zsh color name (`'cyan'` for `$fg[cyan]`), an xterm-256 index string
47
+ * (`'214'` for `${FG[214]}`), or truecolor hex (`'#ff8800'` for `%F{#ff8800}`).
48
+ */
49
+ export type ColorSpec = ZshColorName | `#${string}` | `${number}`;
50
+ /**
51
+ * Resolved theme: every role is a normalized `#rrggbb` string Ink accepts.
52
+ * Semantic surfaces haze actually renders; the oh-my-zsh segment each one
53
+ * inherits from when porting is noted per role.
54
+ */
55
+ export interface HazeTheme {
56
+ /** Terminal default background (OSC 11): the canvas behind every haze surface. omz/VS Code/Sublime: the theme's `background`. */
57
+ background: string;
58
+ /** Brand/accent: app header, tool names, markers, links. omz: prompt-symbol segment (`$fg_bold[green]➜`). */
59
+ accent: string;
60
+ /** Dim accent: rules, heading underlines, table borders. omz: separator rules (`${FG[237]}` dashes in af-magic). */
61
+ accentDim: string;
62
+ /** Chrome borders: input box, panels. omz: segment dividers. */
63
+ border: string;
64
+ /** Info/tool headers. omz: secondary segment (`${FG[075]}` git parens in af-magic, `AGNOSTER_STATUS_JOB_FG`). */
65
+ info: string;
66
+ /** Secondary text: hints, timestamps, elisions. omz: muted separators (`${FG[237]}`). */
6
67
  muted: string;
7
- danger: string;
8
- dangerBg: string;
68
+ /** Primary text: task titles, diff code lines. omz: `$fg[default]` body text. */
69
+ foreground: string;
70
+ /** Slash commands, paths, handles. omz: cwd segment (`$fg[cyan]%c` in robbyrussell). */
71
+ command: string;
72
+ /** Success text: ✓ icons, completions. omz: exit-status-ok / clean-git colors. */
9
73
  success: string;
74
+ /** Background paired with `success` (added diff lines). */
10
75
  successBg: string;
76
+ /** Danger text: ✗ icons, removed diff lines. omz: exit-status-fail / `$fg_bold[red]`. */
77
+ danger: string;
78
+ /** Background paired with `danger` (removed diff lines). */
79
+ dangerBg: string;
80
+ /** Warnings, in-progress states. omz: git dirty marker (`$fg[yellow]✗` in robbyrussell). */
11
81
  warning: string;
12
- /** Slash commands, paths, and active terminal work; matches --command in docs/index.html. */
13
- command: string;
82
+ /** Quoted/user message surfaces. */
14
83
  surfaceBg: string;
84
+ /** Code fence / inline code background. */
15
85
  codeBg: string;
16
- };
86
+ }
87
+ export type HazeThemeRole = keyof HazeTheme;
88
+ export declare const THEME_ROLES: readonly HazeThemeRole[];
89
+ /**
90
+ * A theme as authored: role values in oh-my-zsh color vocabulary, plus optional
91
+ * palette overrides for themes whose host terminal palette defines the look
92
+ * (e.g. agnoster under Solarized). Roles omitted here inherit the `purple`
93
+ * theme's values, so partial ports are safe.
94
+ */
95
+ export interface HazeThemeSpec {
96
+ /** Override terminal palette slots; values must be `#rrggbb` hex. */
97
+ palette?: Partial<Record<ZshColorName, string>>;
98
+ roles?: Partial<Record<HazeThemeRole, ColorSpec>>;
99
+ }
100
+ /** xterm-256 index → RGB hex, mirroring zsh's `%F{nnn}` / `${FG[nnn]}` resolution. Base slots 0–7 resolve through the given palette. */
101
+ export declare function xterm256Color(index: number, palette?: Record<ZshColorName, string>): string;
102
+ /**
103
+ * Resolve a color spec (`'cyan'`, `'214'`, `'#ff8800'`) to `#rrggbb` hex.
104
+ * Throws with the accepted vocabulary for unknown values (fail loudly).
105
+ */
106
+ export declare function resolveColorSpec(spec: string, palette?: Record<ZshColorName, string>): string;
107
+ /** Resolve a built-in theme name (+ optional role overrides) to a complete `HazeTheme`. Throws with valid names for unknown themes. */
108
+ export declare function resolveTheme(name?: string, overrides?: Partial<Record<HazeThemeRole, string>>): HazeTheme;
109
+ /** The active theme instance; swap with `setActiveTheme` before rendering (and on future `/theme` switches). */
110
+ export declare let theme: HazeTheme;
111
+ export declare function setActiveTheme(next: HazeTheme): void;