@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.
- package/CHANGELOG.md +49 -1
- package/README.md +17 -10
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/busyIndicator.d.ts +11 -0
- package/dist/cli/chat/busyIndicator.js +34 -0
- package/dist/cli/chat/chatMetrics.d.ts +0 -1
- package/dist/cli/chat/chatMetrics.js +1 -7
- package/dist/cli/chat/followUpQueue.d.ts +11 -0
- package/dist/cli/chat/followUpQueue.js +38 -0
- package/dist/cli/chat/messages.d.ts +0 -22
- package/dist/cli/chat/messages.js +40 -85
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +8 -1
- package/dist/cli/chat/sessionRecorder.d.ts +9 -0
- package/dist/cli/chat/sessionRecorder.js +12 -0
- package/dist/cli/chat/startupSequence.d.ts +29 -0
- package/dist/cli/chat/startupSequence.js +59 -0
- package/dist/cli/chat/transcriptPartition.d.ts +23 -0
- package/dist/cli/chat/transcriptPartition.js +78 -0
- package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
- package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
- package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/lspHandlers.js +85 -0
- package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
- package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
- package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
- package/dist/cli/chat/wizard/providerHandlers.js +420 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
- package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
- package/dist/cli/chat/wizard/types.d.ts +63 -0
- package/dist/cli/chat/wizard/types.js +24 -0
- package/dist/cli/chat/wizard/uiState.d.ts +56 -0
- package/dist/cli/chat/wizard/uiState.js +15 -0
- package/dist/cli/chat/wizardDispatch.d.ts +11 -113
- package/dist/cli/chat/wizardDispatch.js +41 -815
- package/dist/cli/commands/chat.js +69 -110
- package/dist/cli/commands/formatters.d.ts +0 -3
- package/dist/cli/commands/formatters.js +0 -29
- package/dist/cli/commands/runCommand.d.ts +2 -0
- package/dist/cli/commands/runCommand.js +73 -4
- package/dist/cli/commands/streaming/agentAttempt.d.ts +11 -1
- package/dist/cli/commands/streaming/agentAttempt.js +9 -5
- package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
- package/dist/cli/commands/streaming/assistantSegments.js +48 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +25 -5
- package/dist/cli/commands/streaming/attemptOutcome.js +69 -16
- package/dist/cli/commands/streaming/attemptSetup.d.ts +10 -3
- package/dist/cli/commands/streaming/attemptSetup.js +30 -13
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
- package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +18 -3
- package/dist/cli/commands/streaming/goalSupervisor.js +71 -12
- package/dist/cli/commands/streaming/prepareStep.d.ts +40 -0
- package/dist/cli/commands/streaming/prepareStep.js +116 -0
- package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
- package/dist/cli/commands/streaming/recoverySlices.js +29 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
- package/dist/cli/commands/streaming/stallRecovery.js +2 -6
- package/dist/cli/commands/streaming/streamLoop.d.ts +31 -4
- package/dist/cli/commands/streaming/streamLoop.js +283 -268
- package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
- package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +108 -0
- package/dist/cli/commands/streaming/turnRuntime.d.ts +1 -1
- package/dist/cli/commands/streaming/turnRuntime.js +3 -2
- package/dist/cli/commands/streaming.d.ts +12 -1
- package/dist/cli/commands/streaming.js +20 -25
- package/dist/cli/index.js +6 -3
- package/dist/config/modelCatalog.d.ts +32 -0
- package/dist/config/modelCatalog.js +84 -0
- package/dist/config/providerPresets.d.ts +7 -0
- package/dist/config/providerPresets.js +195 -391
- package/dist/config/settings.d.ts +10 -2
- package/dist/config/settings.js +3 -0
- package/dist/core/agent/budgets.d.ts +10 -0
- package/dist/core/agent/budgets.js +10 -0
- package/dist/core/agent/compaction.d.ts +42 -3
- package/dist/core/agent/compaction.js +53 -5
- package/dist/core/agent/completionController.d.ts +16 -7
- package/dist/core/agent/completionController.js +13 -6
- package/dist/core/agent/contextBudget.d.ts +56 -0
- package/dist/core/agent/contextBudget.js +53 -0
- package/dist/core/agent/errors.js +2 -2
- package/dist/core/agent/events.d.ts +36 -1
- package/dist/core/agent/goalPolicy.d.ts +4 -3
- package/dist/core/agent/goalPolicy.js +9 -4
- package/dist/core/agent/overflow.d.ts +45 -0
- package/dist/core/agent/overflow.js +91 -0
- package/dist/core/agent/requestAssembly.d.ts +7 -0
- package/dist/core/agent/requestAssembly.js +15 -7
- package/dist/core/agent/workState.d.ts +25 -15
- package/dist/core/agent/workState.js +84 -44
- package/dist/core/safety/shellClassifier.d.ts +16 -0
- package/dist/core/safety/shellClassifier.js +31 -0
- package/dist/core/session/sessionSlimming.js +8 -0
- package/dist/core/session/sessionStore.d.ts +71 -1
- package/dist/core/session/sessionStore.js +121 -6
- package/dist/core/validation/outputParser.d.ts +1 -1
- package/dist/core/validation/outputParser.js +6 -1
- package/dist/llm/client.d.ts +2 -2
- package/dist/llm/client.js +14 -6
- package/dist/llm/hazeTools.d.ts +64 -208
- package/dist/llm/tools/shellTool.js +27 -8
- package/dist/llm/tools/taskTool.d.ts +64 -208
- package/dist/llm/tools/taskTool.js +22 -10
- package/dist/ui/components/TextInput.d.ts +18 -1
- package/dist/ui/components/TextInput.js +50 -73
- package/dist/ui/components/useInputSuggestions.d.ts +27 -0
- package/dist/ui/components/useInputSuggestions.js +98 -0
- package/dist/ui/theme.d.ts +8 -8
- package/dist/ui/theme.js +11 -12
- package/dist/ui/themes/registry.d.ts +5 -0
- package/dist/ui/themes/registry.js +436 -0
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/format.js +45 -0
- package/package.json +16 -15
- package/dist/ui/themes/af-magic.d.ts +0 -7
- package/dist/ui/themes/af-magic.js +0 -25
- package/dist/ui/themes/agnoster.d.ts +0 -10
- package/dist/ui/themes/agnoster.js +0 -40
- package/dist/ui/themes/bira.d.ts +0 -10
- package/dist/ui/themes/bira.js +0 -28
- package/dist/ui/themes/bureau.d.ts +0 -10
- package/dist/ui/themes/bureau.js +0 -28
- package/dist/ui/themes/clean.d.ts +0 -9
- package/dist/ui/themes/clean.js +0 -27
- package/dist/ui/themes/cloud.d.ts +0 -6
- package/dist/ui/themes/cloud.js +0 -24
- package/dist/ui/themes/dst.d.ts +0 -10
- package/dist/ui/themes/dst.js +0 -28
- package/dist/ui/themes/fishy.d.ts +0 -7
- package/dist/ui/themes/fishy.js +0 -25
- package/dist/ui/themes/index.d.ts +0 -8
- package/dist/ui/themes/index.js +0 -36
- package/dist/ui/themes/light.d.ts +0 -3
- package/dist/ui/themes/light.js +0 -21
- package/dist/ui/themes/purple.d.ts +0 -7
- package/dist/ui/themes/purple.js +0 -26
- package/dist/ui/themes/robbyrussell.d.ts +0 -8
- package/dist/ui/themes/robbyrussell.js +0 -26
- package/dist/ui/themes/solarized-dark.d.ts +0 -16
- package/dist/ui/themes/solarized-dark.js +0 -44
- package/dist/ui/themes/solarized-light.d.ts +0 -12
- package/dist/ui/themes/solarized-light.js +0 -40
- package/dist/ui/themes/steeef.d.ts +0 -11
- package/dist/ui/themes/steeef.js +0 -29
|
@@ -3,22 +3,52 @@ 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 {
|
|
6
|
+
import { useInputSuggestions } from './useInputSuggestions.js';
|
|
7
7
|
const COMPACT_PASTE_MIN_LINES = 4;
|
|
8
|
-
|
|
8
|
+
// Enhanced-keyboard encodings of Enter with modifiers that some terminals emit
|
|
9
|
+
// verbatim (kitty/CSI-u `u` form and xterm modifyOtherKeys `~` form). Ink 7's
|
|
10
|
+
// keypress parser already resolves the CSI-u variants to `key.return` plus the
|
|
11
|
+
// modifier flags before TextInput sees them; these entries cover pipelines that
|
|
12
|
+
// deliver the raw sequence through `input`.
|
|
13
|
+
const NEWLINE_ESCAPE_INPUTS = new Set([
|
|
14
|
+
'\u001B[13;2u', // shift+enter (kitty protocol / modifyOtherKeys=2)
|
|
15
|
+
'\u001B[13;2~', // shift+enter (xterm modifyOtherKeys=1)
|
|
16
|
+
'\u001B[13;5u', // ctrl+enter (kitty protocol / modifyOtherKeys=2)
|
|
17
|
+
'\u001B[13;5~', // ctrl+enter (xterm modifyOtherKeys=1)
|
|
18
|
+
]);
|
|
9
19
|
export function shouldInsertNewline(input, key) {
|
|
10
|
-
return (key.return === true && (key.shift === true || key.ctrl === true))
|
|
20
|
+
return (key.return === true && (key.shift === true || key.ctrl === true || key.meta === true))
|
|
11
21
|
|| input === '\n'
|
|
12
|
-
||
|
|
22
|
+
|| NEWLINE_ESCAPE_INPUTS.has(input);
|
|
13
23
|
}
|
|
14
|
-
|
|
24
|
+
// Ink's kitty-keyboard auto-detection (enabled via the chat render option)
|
|
25
|
+
// queries the terminal with CSI ? u. The terminal's CSI ? <flags> u response
|
|
26
|
+
// can race Ink's detection listener and leak through the normal input pipeline
|
|
27
|
+
// as literal text (Ink's keypress handling strips the leading ESC), which would
|
|
28
|
+
// type e.g. `[?0u` into an otherwise empty prompt at startup. Drop probe
|
|
29
|
+
// responses instead of inserting them.
|
|
30
|
+
const KITTY_QUERY_RESPONSE_INPUT = /^\[\?\d+(?:;\d+)*u$/;
|
|
31
|
+
export function isKittyQueryResponseInput(input) {
|
|
32
|
+
// Ink's keypress handling strips one leading ESC from unresolved sequences,
|
|
33
|
+
// so the probe response normally arrives as `[?0u`; tolerate the raw
|
|
34
|
+
// ESC-prefixed form as well.
|
|
35
|
+
const stripped = input.startsWith('\u001B') ? input.slice(1) : input;
|
|
36
|
+
return KITTY_QUERY_RESPONSE_INPUT.test(stripped);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ctrl+C terminate check. Legacy terminals deliver the raw \x03 byte (Ink
|
|
40
|
+
* parses it to `c` + ctrl); with the kitty keyboard protocol enabled the
|
|
41
|
+
* terminal reports `CSI 99;5u`, which parses to the same `c` + ctrl shape.
|
|
42
|
+
* Ink 7.1.1's built-in exit-on-CtrlC only recognizes the raw \x03 event, so
|
|
43
|
+
* haze owns the interrupt explicitly (render runs with exitOnCtrlC: false).
|
|
44
|
+
*/
|
|
45
|
+
export function isInterruptInput(input, key) {
|
|
46
|
+
return (input === 'c' && key.ctrl === true) || input === '\x03';
|
|
47
|
+
}
|
|
48
|
+
export function TextInput({ placeholder, disabled, mask, historyItems = [], recordHistory = true, suggestions = [], suggestionMode = 'slash', submitOnEmpty = false, width = 80, getMentionSuggestions, onHistoryAdd, onCancel, onEscape, onToggleTasks, onResumeKey, onInterrupt, onSubmit }) {
|
|
15
49
|
const [value, setValue] = useState('');
|
|
16
50
|
const [cursor, setCursor] = useState(0);
|
|
17
51
|
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
52
|
const history = useRef(historyItems);
|
|
23
53
|
const historyIndex = useRef(null);
|
|
24
54
|
const draft = useRef('');
|
|
@@ -32,19 +62,19 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
32
62
|
setValue('');
|
|
33
63
|
setCursor(0);
|
|
34
64
|
setPasteBlocks([]);
|
|
35
|
-
setSelectedSuggestionIndex(0);
|
|
36
65
|
historyIndex.current = null;
|
|
37
66
|
draft.current = '';
|
|
38
67
|
nextPasteId.current = 1;
|
|
39
68
|
}
|
|
40
69
|
}, [disabled]);
|
|
70
|
+
const suggestionLayers = useInputSuggestions({ value, cursor, suggestions, suggestionMode, mask, getMentionSuggestions });
|
|
71
|
+
const { detectedMention, inMentionMode, filteredSuggestions, mentionList, activeMentionIndex, activeSuggestionIndex, activeSuggestion } = suggestionLayers;
|
|
41
72
|
function setInput(next, nextCursor = next.length, nextPasteBlocks = []) {
|
|
42
73
|
preferredColumn.current = null;
|
|
43
74
|
setValue(next);
|
|
44
75
|
setCursor(Math.max(0, Math.min(nextCursor, next.length)));
|
|
45
76
|
setPasteBlocks(nextPasteBlocks);
|
|
46
|
-
|
|
47
|
-
setMentionSelectedIndex(0);
|
|
77
|
+
suggestionLayers.resetSelection();
|
|
48
78
|
}
|
|
49
79
|
function replaceInput(start, end, inserted) {
|
|
50
80
|
const normalizedInserted = normalizeLineEndings(inserted);
|
|
@@ -61,45 +91,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
61
91
|
historyIndex.current = index;
|
|
62
92
|
setInput(history.current[index] ?? '');
|
|
63
93
|
}
|
|
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
94
|
const displayValue = mask ? '•'.repeat(value.length) : compactPasteBlocksForDisplay(value, pasteBlocks);
|
|
104
95
|
const displayCursor = mask ? cursor : displayCursorForValueCursor(pasteBlocks, cursor);
|
|
105
96
|
const inputWidth = Math.max(1, width - 2);
|
|
@@ -127,6 +118,12 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
127
118
|
onSubmit(submitted);
|
|
128
119
|
}
|
|
129
120
|
useInput((input, key) => {
|
|
121
|
+
if (isKittyQueryResponseInput(input))
|
|
122
|
+
return;
|
|
123
|
+
if (isInterruptInput(input, key)) {
|
|
124
|
+
onInterrupt?.();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
130
127
|
if (disabled) {
|
|
131
128
|
if (key.escape)
|
|
132
129
|
onCancel?.();
|
|
@@ -196,19 +193,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
196
193
|
return;
|
|
197
194
|
}
|
|
198
195
|
if (key.upArrow) {
|
|
199
|
-
if (
|
|
200
|
-
if (activeMentionIndex > 0)
|
|
201
|
-
setMentionSelectedIndex(current => Math.max(0, current - 1));
|
|
196
|
+
if (suggestionLayers.moveSelection(-1))
|
|
202
197
|
return;
|
|
203
|
-
}
|
|
204
|
-
if (filteredSuggestions.length > 0 && activeSuggestionIndex > 0) {
|
|
205
|
-
setSelectedSuggestionIndex(current => Math.max(0, current - 1));
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
198
|
if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(-1))
|
|
209
199
|
return;
|
|
210
|
-
if (inMentionMode)
|
|
211
|
-
return; // no history navigation while completing
|
|
212
200
|
preferredColumn.current = null;
|
|
213
201
|
if (history.current.length === 0)
|
|
214
202
|
return;
|
|
@@ -222,19 +210,10 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
222
210
|
return;
|
|
223
211
|
}
|
|
224
212
|
if (key.downArrow) {
|
|
225
|
-
if (
|
|
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));
|
|
213
|
+
if (suggestionLayers.moveSelection(1))
|
|
232
214
|
return;
|
|
233
|
-
}
|
|
234
215
|
if (filteredSuggestions.length === 0 && !inMentionMode && moveCursorVertically(1))
|
|
235
216
|
return;
|
|
236
|
-
if (inMentionMode)
|
|
237
|
-
return;
|
|
238
217
|
preferredColumn.current = null;
|
|
239
218
|
if (historyIndex.current === null)
|
|
240
219
|
return;
|
|
@@ -269,8 +248,6 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
269
248
|
setCursor(value.length);
|
|
270
249
|
return;
|
|
271
250
|
}
|
|
272
|
-
if (key.ctrl && input === 'c')
|
|
273
|
-
return;
|
|
274
251
|
if (key.ctrl && input === 'o') {
|
|
275
252
|
onToggleTasks?.();
|
|
276
253
|
return;
|
|
@@ -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
|
+
}
|
package/dist/ui/theme.d.ts
CHANGED
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
* values are written in the same vocabulary an oh-my-zsh theme uses:
|
|
21
21
|
* a zsh color name, an xterm-256 index string, or `#rrggbb` hex.
|
|
22
22
|
*
|
|
23
|
-
* The built-in themes live in `src/ui/themes
|
|
24
|
-
* its oh-my-zsh counterpart
|
|
25
|
-
* where `robbyrussell`'s `$fg_bold[green]➜` becomes
|
|
26
|
-
* `$fg[cyan]%c` becomes `command: 'cyan'`, etc. See
|
|
27
|
-
* for the full conversion guide and
|
|
28
|
-
*
|
|
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
29
|
*/
|
|
30
|
-
import {
|
|
31
|
-
export { BUILT_IN_THEME_SPECS };
|
|
30
|
+
import { THEMES } from './themes/registry.js';
|
|
31
|
+
export { THEMES as BUILT_IN_THEME_SPECS };
|
|
32
32
|
/** The theme used when settings name none; also the fallback base for roles another theme omits. */
|
|
33
33
|
export declare const DEFAULT_THEME_NAME = "purple";
|
|
34
34
|
/** zsh `colors` associative-array keys — exactly the names `$fg[...]` accepts. */
|
package/dist/ui/theme.js
CHANGED
|
@@ -20,16 +20,15 @@
|
|
|
20
20
|
* values are written in the same vocabulary an oh-my-zsh theme uses:
|
|
21
21
|
* a zsh color name, an xterm-256 index string, or `#rrggbb` hex.
|
|
22
22
|
*
|
|
23
|
-
* The built-in themes live in `src/ui/themes
|
|
24
|
-
* its oh-my-zsh counterpart
|
|
25
|
-
* where `robbyrussell`'s `$fg_bold[green]➜` becomes
|
|
26
|
-
* `$fg[cyan]%c` becomes `command: 'cyan'`, etc. See
|
|
27
|
-
* for the full conversion guide and
|
|
28
|
-
*
|
|
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
29
|
*/
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
export { BUILT_IN_THEME_SPECS };
|
|
30
|
+
import { BASE_THEME_SPEC, THEMES } from './themes/registry.js';
|
|
31
|
+
export { THEMES as BUILT_IN_THEME_SPECS };
|
|
33
32
|
/** The theme used when settings name none; also the fallback base for roles another theme omits. */
|
|
34
33
|
export const DEFAULT_THEME_NAME = 'purple';
|
|
35
34
|
export const ZSH_COLOR_NAMES = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default'];
|
|
@@ -99,9 +98,9 @@ export function resolveColorSpec(spec, palette = ZSH_NAMED_COLORS) {
|
|
|
99
98
|
}
|
|
100
99
|
/** Resolve a built-in theme name (+ optional role overrides) to a complete `HazeTheme`. Throws with valid names for unknown themes. */
|
|
101
100
|
export function resolveTheme(name, overrides) {
|
|
102
|
-
const spec =
|
|
101
|
+
const spec = THEMES[name ?? DEFAULT_THEME_NAME];
|
|
103
102
|
if (!spec) {
|
|
104
|
-
const validNames = Object.keys(
|
|
103
|
+
const validNames = Object.keys(THEMES).join(', ');
|
|
105
104
|
throw new Error(`Unknown theme name "${name}". Valid themes: ${validNames}`);
|
|
106
105
|
}
|
|
107
106
|
const palette = { ...ZSH_NAMED_COLORS };
|
|
@@ -114,7 +113,7 @@ export function resolveTheme(name, overrides) {
|
|
|
114
113
|
}
|
|
115
114
|
palette[slot] = value.toLowerCase();
|
|
116
115
|
}
|
|
117
|
-
const merged = { ...
|
|
116
|
+
const merged = { ...BASE_THEME_SPEC.roles, ...spec.roles, ...overrides };
|
|
118
117
|
const resolved = {};
|
|
119
118
|
for (const role of THEME_ROLES)
|
|
120
119
|
resolved[role] = resolveColorSpec(String(merged[role] ?? ''), palette);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HazeThemeSpec } from '../theme.js';
|
|
2
|
+
/** Every built-in theme, keyed by its settings name. Key order drives the `/themes` picker listing. */
|
|
3
|
+
export declare const THEMES: Record<string, HazeThemeSpec>;
|
|
4
|
+
/** The base theme other themes inherit omitted roles from (also the default). */
|
|
5
|
+
export declare const BASE_THEME_SPEC: HazeThemeSpec;
|