@denizokcu/haze 1.4.0 → 1.5.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.
- package/CHANGELOG.md +48 -1
- package/README.md +28 -12
- package/SECURITY.md +1 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +7 -0
- package/dist/cli/chat/BusyBar.js +8 -0
- package/dist/cli/chat/DynamicFrame.d.ts +37 -0
- package/dist/cli/chat/DynamicFrame.js +48 -0
- package/dist/cli/chat/busyIndicator.d.ts +3 -1
- package/dist/cli/chat/busyIndicator.js +11 -9
- package/dist/cli/chat/chatMetrics.d.ts +1 -1
- package/dist/cli/chat/chatMetrics.js +3 -3
- package/dist/cli/chat/inputSuggestions.js +2 -1
- package/dist/cli/chat/liveRegion.js +1 -1
- package/dist/cli/chat/messages.js +27 -16
- package/dist/cli/chat/resizeGuard.d.ts +20 -0
- package/dist/cli/chat/resizeGuard.js +25 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +13 -2
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +8 -0
- package/dist/cli/chat/shutdown.d.ts +27 -0
- package/dist/cli/chat/shutdown.js +79 -0
- package/dist/cli/chat/terminalControl.d.ts +45 -0
- package/dist/cli/chat/terminalControl.js +107 -0
- package/dist/cli/chat/tips.js +1 -0
- package/dist/cli/chat/userInput.d.ts +43 -0
- package/dist/cli/chat/userInput.js +63 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +14 -6
- package/dist/cli/chat/wizard/types.d.ts +8 -1
- package/dist/cli/chat/wizardDispatch.js +1 -1
- package/dist/cli/commands/chat.js +258 -172
- package/dist/cli/commands/commandHelp.js +6 -2
- package/dist/cli/commands/commands.d.ts +8 -0
- package/dist/cli/commands/commands.js +11 -0
- package/dist/cli/commands/formatters.d.ts +1 -1
- package/dist/cli/commands/formatters.js +20 -2
- package/dist/cli/commands/logsCommand.js +21 -2
- package/dist/cli/commands/reasoningCommand.d.ts +23 -14
- package/dist/cli/commands/reasoningCommand.js +53 -20
- package/dist/cli/commands/runCommand.js +19 -11
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +11 -6
- package/dist/cli/commands/streaming/attemptSetup.d.ts +1 -0
- package/dist/cli/commands/streaming/attemptSetup.js +11 -5
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +8 -1
- package/dist/cli/commands/streaming/goalCheckpoint.js +3 -2
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +4 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +43 -7
- package/dist/cli/commands/streaming/prepareStep.js +7 -3
- package/dist/cli/commands/streaming/streamLoop.d.ts +5 -0
- package/dist/cli/commands/streaming/streamLoop.js +3 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +6 -0
- package/dist/cli/commands/streaming.d.ts +1 -1
- package/dist/cli/commands/streaming.js +23 -17
- package/dist/cli/commands/wizardFlow.d.ts +5 -2
- package/dist/cli/commands/wizardFlow.js +17 -10
- package/dist/cli/index.js +17 -1
- package/dist/config/contextFiles.d.ts +9 -0
- package/dist/config/contextFiles.js +21 -1
- package/dist/config/modelCatalog.d.ts +3 -0
- package/dist/config/modelCatalog.js +29 -0
- package/dist/config/providerPresets.d.ts +1 -1
- package/dist/config/providerPresets.js +42 -3
- package/dist/config/settings.d.ts +11 -4
- package/dist/config/settings.js +9 -0
- package/dist/core/agent/budgets.d.ts +13 -15
- package/dist/core/agent/budgets.js +15 -17
- package/dist/core/agent/completionController.d.ts +6 -2
- package/dist/core/agent/completionController.js +16 -3
- package/dist/core/agent/goalPolicy.d.ts +10 -0
- package/dist/core/agent/goalPolicy.js +44 -6
- package/dist/core/agent/projectPreflight.d.ts +2 -0
- package/dist/core/agent/projectPreflight.js +56 -0
- package/dist/core/agent/reasoningPolicy.d.ts +34 -4
- package/dist/core/agent/reasoningPolicy.js +27 -4
- package/dist/core/agent/workState.d.ts +8 -0
- package/dist/core/agent/workState.js +191 -8
- package/dist/core/providerContracts.d.ts +32 -0
- package/dist/core/providerContracts.js +1 -0
- package/dist/core/session/sessionReport.d.ts +33 -0
- package/dist/core/session/sessionReport.js +121 -0
- package/dist/core/session/sessionSlimming.js +9 -3
- package/dist/core/session/sessionStore.d.ts +12 -0
- package/dist/core/session/sessionStore.js +20 -4
- package/dist/core/subagent/contracts.d.ts +3 -25
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/validation/outputParser.d.ts +6 -1
- package/dist/core/validation/outputParser.js +6 -2
- package/dist/llm/client.d.ts +4 -2
- package/dist/llm/client.js +44 -16
- package/dist/llm/hazeTools.d.ts +8553 -8550
- package/dist/llm/hazeTools.js +6 -503
- package/dist/llm/lspTools.d.ts +120 -120
- package/dist/llm/mcp.js +3 -0
- package/dist/llm/requestContext.d.ts +1 -1
- package/dist/llm/requestContext.js +1 -1
- package/dist/{core/subagent → llm}/subagentRunner.d.ts +9 -9
- package/dist/{core/subagent → llm}/subagentRunner.js +22 -25
- package/dist/llm/systemPrompt.d.ts +11 -1
- package/dist/llm/systemPrompt.js +2 -11
- package/dist/llm/tools/fetchTool.d.ts +30 -30
- package/dist/llm/tools/fileTools.d.ts +7768 -0
- package/dist/llm/tools/fileTools.js +510 -0
- package/dist/llm/tools/processTool.d.ts +30 -30
- package/dist/llm/tools/shellTool.d.ts +30 -30
- package/dist/llm/tools/shellTool.js +8 -4
- package/dist/llm/tools/toolContext.d.ts +3 -32
- package/dist/llm/tools/toolContext.js +33 -52
- package/dist/llm/tools/toolContextState.d.ts +40 -0
- package/dist/llm/tools/toolContextState.js +34 -0
- package/dist/llm/workerContext.d.ts +7 -0
- package/dist/llm/workerContext.js +18 -1
- package/dist/skills/SkillLoader.js +3 -3
- package/dist/skills/SkillRegistry.js +3 -3
- package/dist/skills/builder/SkillBuilder.js +3 -3
- package/dist/skills/confinement.d.ts +7 -0
- package/dist/skills/confinement.js +15 -0
- package/dist/ui/codeHighlight.js +4 -4
- package/dist/ui/components/MarkdownText.js +7 -8
- package/dist/ui/components/NativeIndicators.d.ts +15 -0
- package/dist/ui/components/NativeIndicators.js +32 -0
- package/dist/ui/components/StreamingMarkdownText.d.ts +9 -0
- package/dist/ui/components/StreamingMarkdownText.js +38 -0
- package/dist/ui/components/TextInput.d.ts +7 -2
- package/dist/ui/components/TextInput.js +103 -46
- package/dist/ui/components/WizardChoices.d.ts +18 -0
- package/dist/ui/components/WizardChoices.js +32 -0
- package/dist/ui/inputBuffer.js +12 -6
- package/dist/ui/textGeometry.d.ts +14 -0
- package/dist/ui/textGeometry.js +31 -0
- package/package.json +14 -13
- /package/dist/cli/{contextReport.d.ts → contextReportCli.d.ts} +0 -0
- /package/dist/cli/{contextReport.js → contextReportCli.js} +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import { Box, Text, measureElement, useCursor, useInput, useIsScreenReaderEnabled, usePaste } from 'ink';
|
|
4
|
+
import { cellWidth, graphemes, nextBoundary, offsetAtColumn, previousBoundary, safeInputDisplay } from '../textGeometry.js';
|
|
4
5
|
import { theme } from '../theme.js';
|
|
5
6
|
import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
|
|
6
7
|
import { useInputSuggestions } from './useInputSuggestions.js';
|
|
8
|
+
import { WizardChoices } from './WizardChoices.js';
|
|
7
9
|
const COMPACT_PASTE_MIN_LINES = 4;
|
|
8
10
|
// Enhanced-keyboard encodings of Enter with modifiers that some terminals emit
|
|
9
|
-
// verbatim (kitty/CSI-u `u` form and xterm modifyOtherKeys `~` form). Ink
|
|
11
|
+
// verbatim (kitty/CSI-u `u` form and xterm modifyOtherKeys `~` form). Ink's
|
|
10
12
|
// keypress parser already resolves the CSI-u variants to `key.return` plus the
|
|
11
13
|
// modifier flags before TextInput sees them; these entries cover pipelines that
|
|
12
14
|
// deliver the raw sequence through `input`.
|
|
@@ -21,20 +23,6 @@ export function shouldInsertNewline(input, key) {
|
|
|
21
23
|
|| input === '\n'
|
|
22
24
|
|| NEWLINE_ESCAPE_INPUTS.has(input);
|
|
23
25
|
}
|
|
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
26
|
/**
|
|
39
27
|
* Ctrl+C terminate check. Legacy terminals deliver the raw \x03 byte (Ink
|
|
40
28
|
* parses it to `c` + ctrl); with the kitty keyboard protocol enabled the
|
|
@@ -45,15 +33,40 @@ export function isKittyQueryResponseInput(input) {
|
|
|
45
33
|
export function isInterruptInput(input, key) {
|
|
46
34
|
return (input === 'c' && key.ctrl === true) || input === '\x03';
|
|
47
35
|
}
|
|
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 }) {
|
|
36
|
+
export function TextInput({ placeholder, disabled, mask, historyItems = [], recordHistory = true, suggestions = [], suggestionMode = 'slash', submitOnEmpty = false, width = 80, inputRows = 4, suggestionRows = 6, onRowsChange, getMentionSuggestions, onHistoryAdd, onCancel, onEscape, onToggleTasks, onResumeKey, onInterrupt, onSubmit }) {
|
|
49
37
|
const [value, setValue] = useState('');
|
|
50
38
|
const [cursor, setCursor] = useState(0);
|
|
51
39
|
const [pasteBlocks, setPasteBlocks] = useState([]);
|
|
40
|
+
// IME support (Ink 8): position the real terminal cursor at the editing
|
|
41
|
+
// point so composing text (CJK input methods) appears where the user is
|
|
42
|
+
// looking instead of at the frame bottom. Measured after layout commits.
|
|
43
|
+
const cursorHostRef = useRef(null);
|
|
44
|
+
const { setCursorPosition } = useCursor();
|
|
45
|
+
// The terminal cursor position for IME composition must use frame-origin
|
|
46
|
+
// coordinates (Ink's cursor basis). `useBoxMetrics`' left/top are
|
|
47
|
+
// parent-relative — (0,0) here, since this box sits inside DynamicFrame's
|
|
48
|
+
// bordered, padded input box — which pinned the hardware cursor one row
|
|
49
|
+
// above the input and cells behind the editing point. `measureElement()`
|
|
50
|
+
// accumulates ancestor offsets into frame coordinates; it is read after
|
|
51
|
+
// commit, when Yoga layout is final. The ref targets the input-line box (not
|
|
52
|
+
// the whole host), so suggestion rows rendered above it are already included
|
|
53
|
+
// in the measured origin.
|
|
54
|
+
const [inputOrigin, setInputOrigin] = useState();
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const node = cursorHostRef.current;
|
|
57
|
+
if (!node)
|
|
58
|
+
return;
|
|
59
|
+
const { x, y } = measureElement(node);
|
|
60
|
+
setInputOrigin(previous => previous && previous.x === x && previous.y === y ? previous : { x, y });
|
|
61
|
+
});
|
|
62
|
+
const screenReaderEnabled = useIsScreenReaderEnabled();
|
|
52
63
|
const history = useRef(historyItems);
|
|
53
64
|
const historyIndex = useRef(null);
|
|
54
65
|
const draft = useRef('');
|
|
55
66
|
const nextPasteId = useRef(1);
|
|
56
67
|
const preferredColumn = useRef(null);
|
|
68
|
+
const inputRef = useRef({ value, cursor, pasteBlocks });
|
|
69
|
+
inputRef.current = { value, cursor, pasteBlocks };
|
|
57
70
|
useEffect(() => {
|
|
58
71
|
history.current = historyItems;
|
|
59
72
|
}, [historyItems]);
|
|
@@ -71,16 +84,19 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
71
84
|
const { detectedMention, inMentionMode, filteredSuggestions, mentionList, activeMentionIndex, activeSuggestionIndex, activeSuggestion } = suggestionLayers;
|
|
72
85
|
function setInput(next, nextCursor = next.length, nextPasteBlocks = []) {
|
|
73
86
|
preferredColumn.current = null;
|
|
87
|
+
const clampedCursor = Math.max(0, Math.min(nextCursor, next.length));
|
|
88
|
+
inputRef.current = { value: next, cursor: clampedCursor, pasteBlocks: nextPasteBlocks };
|
|
74
89
|
setValue(next);
|
|
75
|
-
setCursor(
|
|
90
|
+
setCursor(clampedCursor);
|
|
76
91
|
setPasteBlocks(nextPasteBlocks);
|
|
77
92
|
suggestionLayers.resetSelection();
|
|
78
93
|
}
|
|
79
94
|
function replaceInput(start, end, inserted) {
|
|
80
95
|
const normalizedInserted = normalizeLineEndings(inserted);
|
|
81
|
-
const
|
|
96
|
+
const current = inputRef.current;
|
|
97
|
+
const next = current.value.slice(0, start) + normalizedInserted + current.value.slice(end);
|
|
82
98
|
const insertedLineCount = lineCount(normalizedInserted);
|
|
83
|
-
const updatedPasteBlocks = updatePasteBlocksForReplacement(pasteBlocks, start, end, normalizedInserted.length);
|
|
99
|
+
const updatedPasteBlocks = updatePasteBlocksForReplacement(current.pasteBlocks, start, end, normalizedInserted.length);
|
|
84
100
|
const insertedPasteBlock = !mask && insertedLineCount >= COMPACT_PASTE_MIN_LINES
|
|
85
101
|
? [{ id: nextPasteId.current++, start, end: start + normalizedInserted.length, lineCount: insertedLineCount }]
|
|
86
102
|
: [];
|
|
@@ -91,14 +107,20 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
91
107
|
historyIndex.current = index;
|
|
92
108
|
setInput(history.current[index] ?? '');
|
|
93
109
|
}
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const
|
|
110
|
+
const valueGraphemes = mask ? graphemes(value) : [];
|
|
111
|
+
const displayValue = mask ? '•'.repeat(valueGraphemes.length) : safeInputDisplay(compactPasteBlocksForDisplay(value, pasteBlocks));
|
|
112
|
+
const displayCursor = mask ? valueGraphemes.filter(part => part.end <= cursor).length : displayCursorForValueCursor(pasteBlocks, cursor);
|
|
113
|
+
// Leave a cell for the end-of-line cursor, even on a completely full draft.
|
|
114
|
+
const inputWidth = Math.max(1, width - (width > 2 ? 2 : 0) - 1);
|
|
97
115
|
const wrappedLines = wrapDisplayValue(displayValue, inputWidth);
|
|
98
116
|
const currentCursorPosition = cursorPosition(wrappedLines, displayCursor);
|
|
117
|
+
function moveValueCursor(nextCursor) {
|
|
118
|
+
inputRef.current.cursor = nextCursor;
|
|
119
|
+
setCursor(nextCursor);
|
|
120
|
+
}
|
|
99
121
|
function moveCursorToDisplayPosition(nextDisplayCursor) {
|
|
100
122
|
const clampedDisplayCursor = Math.max(0, Math.min(nextDisplayCursor, displayValue.length));
|
|
101
|
-
|
|
123
|
+
moveValueCursor(mask ? (valueGraphemes[clampedDisplayCursor]?.start ?? value.length) : valueCursorForDisplayCursor(pasteBlocks, clampedDisplayCursor));
|
|
102
124
|
}
|
|
103
125
|
function moveCursorVertically(direction) {
|
|
104
126
|
const targetLine = wrappedLines[currentCursorPosition.lineIndex + direction];
|
|
@@ -106,20 +128,26 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
106
128
|
return false;
|
|
107
129
|
const column = preferredColumn.current ?? currentCursorPosition.column;
|
|
108
130
|
preferredColumn.current = column;
|
|
109
|
-
moveCursorToDisplayPosition(
|
|
131
|
+
moveCursorToDisplayPosition(targetLine.start + offsetAtColumn(targetLine.text, column));
|
|
110
132
|
return true;
|
|
111
133
|
}
|
|
112
134
|
function submitValue(submitted, historyValue = submitted) {
|
|
113
|
-
if (recordHistory && historyValue) {
|
|
135
|
+
if (recordHistory && !mask && historyValue) {
|
|
114
136
|
if (history.current[history.current.length - 1] !== historyValue)
|
|
115
137
|
history.current = [...history.current, historyValue];
|
|
116
138
|
onHistoryAdd?.(historyValue);
|
|
117
139
|
}
|
|
118
140
|
onSubmit(submitted);
|
|
119
141
|
}
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
// Always subscribe: disabled paste is discarded, never re-routed as shortcuts.
|
|
143
|
+
usePaste(text => {
|
|
144
|
+
if (disabled)
|
|
122
145
|
return;
|
|
146
|
+
const current = inputRef.current;
|
|
147
|
+
replaceInput(current.cursor, current.cursor, text);
|
|
148
|
+
});
|
|
149
|
+
useInput((input, key) => {
|
|
150
|
+
const { value, cursor } = inputRef.current;
|
|
123
151
|
if (isInterruptInput(input, key)) {
|
|
124
152
|
onInterrupt?.();
|
|
125
153
|
return;
|
|
@@ -184,12 +212,12 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
184
212
|
}
|
|
185
213
|
if (key.leftArrow) {
|
|
186
214
|
preferredColumn.current = null;
|
|
187
|
-
|
|
215
|
+
moveValueCursor(previousBoundary(value, cursor));
|
|
188
216
|
return;
|
|
189
217
|
}
|
|
190
218
|
if (key.rightArrow) {
|
|
191
219
|
preferredColumn.current = null;
|
|
192
|
-
|
|
220
|
+
moveValueCursor(nextBoundary(value, cursor));
|
|
193
221
|
return;
|
|
194
222
|
}
|
|
195
223
|
if (key.upArrow) {
|
|
@@ -229,45 +257,74 @@ export function TextInput({ placeholder, disabled, mask, historyItems = [], reco
|
|
|
229
257
|
if (key.backspace) {
|
|
230
258
|
if (cursor === 0)
|
|
231
259
|
return;
|
|
232
|
-
replaceInput(cursor
|
|
260
|
+
replaceInput(previousBoundary(value, cursor), cursor, '');
|
|
233
261
|
return;
|
|
234
262
|
}
|
|
235
263
|
if (key.delete) {
|
|
236
264
|
if (cursor >= value.length)
|
|
237
265
|
return;
|
|
238
|
-
replaceInput(cursor, cursor
|
|
266
|
+
replaceInput(cursor, nextBoundary(value, cursor), '');
|
|
239
267
|
return;
|
|
240
268
|
}
|
|
241
269
|
if (key.ctrl && input === 'a') {
|
|
242
270
|
preferredColumn.current = null;
|
|
243
|
-
|
|
271
|
+
moveValueCursor(0);
|
|
244
272
|
return;
|
|
245
273
|
}
|
|
246
274
|
if (key.ctrl && input === 'e') {
|
|
247
275
|
preferredColumn.current = null;
|
|
248
|
-
|
|
276
|
+
moveValueCursor(value.length);
|
|
249
277
|
return;
|
|
250
278
|
}
|
|
251
279
|
if (key.ctrl && input === 'o') {
|
|
252
280
|
onToggleTasks?.();
|
|
253
281
|
return;
|
|
254
282
|
}
|
|
283
|
+
if (key.ctrl)
|
|
284
|
+
return; // Unsupported Ctrl combinations are controls, not text.
|
|
255
285
|
if (input) {
|
|
256
|
-
replaceInput(cursor, cursor, input);
|
|
286
|
+
replaceInput(inputRef.current.cursor, inputRef.current.cursor, input);
|
|
257
287
|
}
|
|
258
288
|
});
|
|
259
|
-
const maxVisibleLines =
|
|
289
|
+
const maxVisibleLines = Math.max(1, inputRows);
|
|
260
290
|
const firstVisibleLine = Math.max(0, Math.min(currentCursorPosition.lineIndex - maxVisibleLines + 1, wrappedLines.length - maxVisibleLines));
|
|
261
291
|
const visibleLines = wrappedLines.slice(firstVisibleLine, firstVisibleLine + maxVisibleLines);
|
|
292
|
+
// Terminal cursor coordinates at the editing point: the input-line box's
|
|
293
|
+
// frame-origin position (measureElement) plus the `› ` prefix and the cell
|
|
294
|
+
// width of the text before the cursor (grapheme-safe via textGeometry).
|
|
295
|
+
let imeCursor;
|
|
296
|
+
if (!disabled && !screenReaderEnabled && inputOrigin) {
|
|
297
|
+
const visibleRow = currentCursorPosition.lineIndex - firstVisibleLine;
|
|
298
|
+
const line = wrappedLines[currentCursorPosition.lineIndex];
|
|
299
|
+
if (value.length === 0) {
|
|
300
|
+
imeCursor = { x: inputOrigin.x + (width > 2 ? 2 : 0), y: inputOrigin.y };
|
|
301
|
+
}
|
|
302
|
+
else if (line && visibleRow >= 0 && visibleRow < visibleLines.length) {
|
|
303
|
+
const lineCursorOffset = Math.max(0, Math.min(displayCursor - line.start, line.text.length));
|
|
304
|
+
imeCursor = {
|
|
305
|
+
x: inputOrigin.x + (width > 2 ? 2 : 0) + cellWidth(line.text.slice(0, lineCursorOffset)),
|
|
306
|
+
y: inputOrigin.y + visibleRow,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
setCursorPosition(imeCursor);
|
|
262
311
|
const displayList = inMentionMode ? mentionList : filteredSuggestions;
|
|
263
312
|
const displayActiveIndex = inMentionMode ? activeMentionIndex : activeSuggestionIndex;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
313
|
+
const suggestionStart = Math.max(0, displayActiveIndex - Math.max(0, suggestionRows - 1));
|
|
314
|
+
const visibleSuggestions = displayList.slice(suggestionStart, suggestionStart + suggestionRows);
|
|
315
|
+
const wantedInputRows = Math.min(4, wrappedLines.length);
|
|
316
|
+
const wantedSuggestionRows = Math.min(5, displayList.length);
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
onRowsChange?.({ input: wantedInputRows, suggestions: wantedSuggestionRows });
|
|
319
|
+
}, [onRowsChange, wantedInputRows, wantedSuggestionRows]);
|
|
320
|
+
return _jsxs(Box, { flexDirection: "column", width: "100%", children: [suggestionMode === 'always' ? _jsx(WizardChoices, { suggestions: displayList, activeIndex: displayActiveIndex, rows: suggestionRows }) : visibleSuggestions.length > 0 && _jsx(Box, { flexDirection: "column", children: visibleSuggestions.map((suggestion, index) => _jsxs(Text, { color: index + suggestionStart === displayActiveIndex ? theme.success : theme.muted, wrap: "truncate-end", children: [index + suggestionStart === displayActiveIndex ? '› ' : ' ', suggestion.value, _jsxs(Text, { color: theme.muted, children: [" ", suggestion.kind ?? 'command', suggestion.description ? ` — ${suggestion.description}` : ''] })] }, suggestion.value)) }), _jsx(Box, { ref: cursorHostRef, flexDirection: "column", width: "100%", children: value.length === 0 ? _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: theme.accent, children: width > 2 ? '› ' : '' }), _jsx(Text, { inverse: true, children: " " }), _jsxs(Text, { color: theme.muted, children: [" ", placeholder ?? 'Type a message...'] })] }) : visibleLines.map((line, index) => {
|
|
321
|
+
const absoluteLineIndex = firstVisibleLine + index;
|
|
322
|
+
const isCursorLine = absoluteLineIndex === currentCursorPosition.lineIndex;
|
|
323
|
+
const lineCursor = isCursorLine ? Math.max(0, Math.min(displayCursor - line.start, line.text.length)) : -1;
|
|
324
|
+
const beforeCursor = isCursorLine ? line.text.slice(0, lineCursor) : line.text;
|
|
325
|
+
const cursorEnd = nextBoundary(line.text, lineCursor);
|
|
326
|
+
const cursorChar = isCursorLine ? line.text.slice(lineCursor, cursorEnd) || ' ' : '';
|
|
327
|
+
const afterCursor = isCursorLine ? line.text.slice(cursorEnd) : '';
|
|
328
|
+
return _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: theme.accent, children: width > 2 ? (absoluteLineIndex === 0 ? '› ' : ' ') : '' }), isCursorLine ? _jsxs(_Fragment, { children: [width > 2 ? beforeCursor : '', _jsx(Text, { inverse: true, children: cellWidth(cursorChar) > inputWidth ? '�' : cursorChar }), width > 2 ? afterCursor : ''] }) : cellWidth(line.text) > inputWidth ? '�' : line.text] }, `${line.start}-${absoluteLineIndex}`);
|
|
329
|
+
}) })] });
|
|
273
330
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type HazeTheme } from '../theme.js';
|
|
3
|
+
import type { TextInputSuggestion } from './TextInput.js';
|
|
4
|
+
/** Rebuild from the live palette; Static transcript and terminal defaults are untouched. */
|
|
5
|
+
export declare function wizardChoiceTheme(palette: HazeTheme): {
|
|
6
|
+
components: Record<string, import("@inkjs/ui").ComponentTheme>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Select's public API has no controlled focus, filter, or Tab completion. Keep
|
|
10
|
+
* one keyboard owner (the existing editor) and project its selected window into
|
|
11
|
+
* a passive library Select. This preserves free-form escape paths and avoids
|
|
12
|
+
* parallel listeners, private imports, and a second wizard state machine.
|
|
13
|
+
*/
|
|
14
|
+
export declare function WizardChoices({ suggestions, activeIndex, rows }: {
|
|
15
|
+
suggestions: TextInputSuggestion[];
|
|
16
|
+
activeIndex: number;
|
|
17
|
+
rows: number;
|
|
18
|
+
}): React.JSX.Element | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Select, ThemeProvider, defaultTheme, extendTheme } from '@inkjs/ui';
|
|
3
|
+
import { theme } from '../theme.js';
|
|
4
|
+
import { safeInputDisplay } from '../textGeometry.js';
|
|
5
|
+
/** Rebuild from the live palette; Static transcript and terminal defaults are untouched. */
|
|
6
|
+
export function wizardChoiceTheme(palette) {
|
|
7
|
+
return extendTheme(defaultTheme, { components: { Select: { styles: {
|
|
8
|
+
container: () => ({ flexDirection: 'column', width: '100%', overflow: 'hidden' }),
|
|
9
|
+
option: () => ({ height: 1, flexShrink: 0, width: '100%', overflow: 'hidden' }),
|
|
10
|
+
label: ({ isSelected }) => ({
|
|
11
|
+
color: isSelected ? palette.success : palette.muted, wrap: 'truncate-end',
|
|
12
|
+
}),
|
|
13
|
+
selectedIndicator: () => ({ display: 'none' }),
|
|
14
|
+
} } } });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Select's public API has no controlled focus, filter, or Tab completion. Keep
|
|
18
|
+
* one keyboard owner (the existing editor) and project its selected window into
|
|
19
|
+
* a passive library Select. This preserves free-form escape paths and avoids
|
|
20
|
+
* parallel listeners, private imports, and a second wizard state machine.
|
|
21
|
+
*/
|
|
22
|
+
export function WizardChoices({ suggestions, activeIndex, rows }) {
|
|
23
|
+
const count = Math.max(0, Math.floor(rows));
|
|
24
|
+
if (count === 0 || suggestions.length === 0)
|
|
25
|
+
return null;
|
|
26
|
+
const start = Math.max(0, activeIndex - Math.max(0, count - 1));
|
|
27
|
+
const options = suggestions.slice(start, start + count).map((suggestion, index) => ({
|
|
28
|
+
value: suggestion.value,
|
|
29
|
+
label: safeInputDisplay(`${index + start === activeIndex ? '› ' : ' '}${suggestion.value} ${suggestion.kind ?? 'command'}${suggestion.description ? ` — ${suggestion.description}` : ''}`),
|
|
30
|
+
}));
|
|
31
|
+
return _jsx(ThemeProvider, { theme: wizardChoiceTheme(theme), children: _jsx(Select, { isDisabled: true, options: options, visibleOptionCount: count, defaultValue: suggestions[activeIndex]?.value }, `${start}:${count}:${suggestions[activeIndex]?.value}`) });
|
|
32
|
+
}
|
package/dist/ui/inputBuffer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cellWidth, graphemes } from './textGeometry.js';
|
|
1
2
|
export function normalizeLineEndings(text) {
|
|
2
3
|
return text.replace(/\r\n|\r/g, '\n');
|
|
3
4
|
}
|
|
@@ -27,7 +28,7 @@ export function displayCursorForValueCursor(blocks, valueCursor) {
|
|
|
27
28
|
if (valueCursor <= block.start)
|
|
28
29
|
break;
|
|
29
30
|
if (valueCursor < block.end)
|
|
30
|
-
return block.start + placeholderLength;
|
|
31
|
+
return block.start - (valueCursor - displayCursor) + placeholderLength;
|
|
31
32
|
displayCursor -= compactedLength;
|
|
32
33
|
}
|
|
33
34
|
return displayCursor;
|
|
@@ -67,20 +68,24 @@ export function wrapDisplayValue(displayValue, width) {
|
|
|
67
68
|
const lines = [];
|
|
68
69
|
let start = 0;
|
|
69
70
|
let text = '';
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
let cells = 0;
|
|
72
|
+
for (const { text: char, start: index } of graphemes(displayValue)) {
|
|
72
73
|
if (char === '\n') {
|
|
73
74
|
lines.push({ text, start, end: index });
|
|
74
75
|
start = index + 1;
|
|
75
76
|
text = '';
|
|
77
|
+
cells = 0;
|
|
76
78
|
continue;
|
|
77
79
|
}
|
|
78
|
-
|
|
80
|
+
const charWidth = cellWidth(char);
|
|
81
|
+
if (text && cells + charWidth > wrapWidth) {
|
|
79
82
|
lines.push({ text, start, end: index });
|
|
80
83
|
start = index;
|
|
81
84
|
text = '';
|
|
85
|
+
cells = 0;
|
|
82
86
|
}
|
|
83
87
|
text += char;
|
|
88
|
+
cells += charWidth;
|
|
84
89
|
}
|
|
85
90
|
lines.push({ text, start, end: displayValue.length });
|
|
86
91
|
return lines;
|
|
@@ -94,6 +99,7 @@ export function cursorPosition(lines, displayCursor) {
|
|
|
94
99
|
return displayCursor >= line.start && (displayCursor < line.end || (nextLineStartsAfterNewline && displayCursor === line.end) || (isLast && displayCursor <= line.end));
|
|
95
100
|
});
|
|
96
101
|
const lineIndex = Math.max(0, foundIndex);
|
|
97
|
-
const line = lines[lineIndex] ?? lines[0] ?? { start: 0, end: 0 };
|
|
98
|
-
|
|
102
|
+
const line = lines[lineIndex] ?? lines[0] ?? { text: '', start: 0, end: 0 };
|
|
103
|
+
const offset = Math.max(0, Math.min(displayCursor - line.start, line.end - line.start));
|
|
104
|
+
return { lineIndex, column: cellWidth(line.text.slice(0, offset)) };
|
|
99
105
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
export declare function graphemes(text: string): {
|
|
3
|
+
text: string;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}[];
|
|
7
|
+
export declare function previousBoundary(text: string, cursor: number): number;
|
|
8
|
+
export declare function nextBoundary(text: string, cursor: number): number;
|
|
9
|
+
/** UTF-16 offsets stay distinct from terminal-cell columns. */
|
|
10
|
+
export declare function offsetAtColumn(text: string, column: number): number;
|
|
11
|
+
export declare function clipCells(text: string, width: number): string;
|
|
12
|
+
/** Display-only replacement keeps offsets stable and cannot execute pasted controls. */
|
|
13
|
+
export declare function safeInputDisplay(text: string): string;
|
|
14
|
+
export { stringWidth as cellWidth };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
3
|
+
export function graphemes(text) {
|
|
4
|
+
return Array.from(segmenter.segment(text), ({ segment, index }) => ({ text: segment, start: index, end: index + segment.length }));
|
|
5
|
+
}
|
|
6
|
+
export function previousBoundary(text, cursor) {
|
|
7
|
+
return graphemes(text).reverse().find(part => part.start < cursor)?.start ?? 0;
|
|
8
|
+
}
|
|
9
|
+
export function nextBoundary(text, cursor) {
|
|
10
|
+
return graphemes(text).find(part => part.end > cursor)?.end ?? text.length;
|
|
11
|
+
}
|
|
12
|
+
/** UTF-16 offsets stay distinct from terminal-cell columns. */
|
|
13
|
+
export function offsetAtColumn(text, column) {
|
|
14
|
+
let cells = 0;
|
|
15
|
+
for (const part of graphemes(text)) {
|
|
16
|
+
const next = cells + stringWidth(part.text);
|
|
17
|
+
if (next > column)
|
|
18
|
+
return part.start;
|
|
19
|
+
cells = next;
|
|
20
|
+
}
|
|
21
|
+
return text.length;
|
|
22
|
+
}
|
|
23
|
+
export function clipCells(text, width) {
|
|
24
|
+
return text.slice(0, offsetAtColumn(text, Math.max(0, width)));
|
|
25
|
+
}
|
|
26
|
+
/** Display-only replacement keeps offsets stable and cannot execute pasted controls. */
|
|
27
|
+
export function safeInputDisplay(text) {
|
|
28
|
+
// eslint-disable-next-line no-control-regex
|
|
29
|
+
return text.replace(/[\x00-\x09\x0b-\x1f\x7f-\x9f]/g, '�');
|
|
30
|
+
}
|
|
31
|
+
export { stringWidth as cellWidth };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denizokcu/haze",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A minimal LLM harness for your terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,27 +41,28 @@
|
|
|
41
41
|
"lint:fix": "eslint src/ --fix",
|
|
42
42
|
"lint:knip": "knip",
|
|
43
43
|
"typecheck": "tsc --noEmit",
|
|
44
|
-
"context:report": "node --import tsx src/cli/
|
|
44
|
+
"context:report": "node --import tsx src/cli/contextReportCli.ts",
|
|
45
45
|
"eval": "node scripts/run-evals.mjs",
|
|
46
46
|
"release:verify": "node scripts/verify-release-metadata.mjs",
|
|
47
47
|
"haze": "tsx src/cli/index.ts",
|
|
48
48
|
"prepublishOnly": "npm run typecheck && npm test && npm run lint && npm run build && npm audit --audit-level=high && npm run release:verify"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@ai-sdk/mcp": "^2.0.
|
|
52
|
-
"@ai-sdk/openai": "4.0.
|
|
51
|
+
"@ai-sdk/mcp": "^2.0.66",
|
|
52
|
+
"@ai-sdk/openai": "4.0.83",
|
|
53
|
+
"@inkjs/ui": "2.0.0",
|
|
53
54
|
"@vscode/ripgrep": "1.18.0",
|
|
54
|
-
"ai": "7.0.
|
|
55
|
+
"ai": "7.0.127",
|
|
55
56
|
"cli-highlight": "2.1.11",
|
|
56
57
|
"commander": "15.0.0",
|
|
57
58
|
"defuddle": "^0.19.4",
|
|
58
59
|
"fs-extra": "11.4.1",
|
|
59
|
-
"ignore": "^7.0.
|
|
60
|
-
"ink": "
|
|
61
|
-
"ink-spinner": "5.0.0",
|
|
60
|
+
"ignore": "^7.0.12",
|
|
61
|
+
"ink": "8.0.0",
|
|
62
62
|
"linkedom": "^0.18.13",
|
|
63
63
|
"marked": "18.0.14",
|
|
64
64
|
"react": "19.3.0",
|
|
65
|
+
"string-width": "8.3.0",
|
|
65
66
|
"strip-ansi": "7.2.0",
|
|
66
67
|
"turndown": "^7.2.4",
|
|
67
68
|
"wrap-ansi": "10.0.2",
|
|
@@ -71,15 +72,15 @@
|
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
"@eslint/js": "^10.0.1",
|
|
73
74
|
"@types/fs-extra": "11.0.4",
|
|
74
|
-
"@types/node": "26.6.
|
|
75
|
+
"@types/node": "26.6.4",
|
|
75
76
|
"@types/react": "19.3.0",
|
|
76
|
-
"eslint": "^10.
|
|
77
|
+
"eslint": "^10.12.0",
|
|
77
78
|
"ink-testing-library": "^4.0.0",
|
|
78
|
-
"knip": "6.
|
|
79
|
+
"knip": "6.39.0",
|
|
79
80
|
"tsx": "4.23.15",
|
|
80
81
|
"typescript": "6.0.3",
|
|
81
|
-
"typescript-eslint": "^8.
|
|
82
|
-
"vitest": "^5.0.
|
|
82
|
+
"typescript-eslint": "^8.71.0",
|
|
83
|
+
"vitest": "^5.0.3"
|
|
83
84
|
},
|
|
84
85
|
"allowScripts": {
|
|
85
86
|
"fsevents@2.3.3": true,
|
|
File without changes
|
|
File without changes
|