hintshell 0.3.15 → 0.4.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/README.md +60 -14
- package/package.json +1 -1
- package/scripts/test-marker-conpty.sh +55 -0
- package/scripts/test-marker-gate.sh +68 -0
- package/scripts/test-overlay-interactive.ps1 +23 -0
- package/scripts/test-overlay-layout.ps1 +181 -4
package/README.md
CHANGED
|
@@ -94,9 +94,21 @@ source ~/.bashrc
|
|
|
94
94
|
|
|
95
95
|
After `hs init`, opening a normal interactive Git Bash or WSL2 Bash session automatically starts `hintshell bash`, which renders a local live overlay as you type. `fzf` is not required for this live mode.
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
| Key | Behaviour |
|
|
98
|
+
|---|---|
|
|
99
|
+
| **↑ / ↓** | Move through the suggestion list. With no overlay open they stay Bash's own history keys. |
|
|
100
|
+
| **Alt+↑ / Alt+↓** | Bash readline history, so the panel never competes with history for the same arrow. |
|
|
101
|
+
| **Tab** | Accept a compatible command suggestion. Path input such as `cd src/comp`, flags such as `git --ver`, and empty overlays are forwarded to Bash's native completion. |
|
|
102
|
+
| **→ / End** | Accept the inline ghost hint — the rest of the top compatible suggestion. Never for a destructive command, which needs the visible Tab path. |
|
|
103
|
+
| **Alt+→ / Ctrl+→** | Accept only the next word, Fish-style. |
|
|
104
|
+
| **Esc** | Hide the panel for the current line. It stays hidden until **Enter** or **Ctrl+Space**, so it does not pop back on the next keystroke. |
|
|
105
|
+
| **Ctrl+Space** | Bring the panel back and re-query without typing another character. |
|
|
106
|
+
| **Enter** | Execute through Bash. |
|
|
107
|
+
|
|
108
|
+
Everything else reaches Bash untouched: readline chords (**Ctrl+R**, **Ctrl+D**, **Ctrl+L**, **Ctrl+A/E/W/U/K/Y**, **Ctrl+P/N**), Meta bindings (**Alt+B**, **Alt+F**, **Alt+D**, **Alt+U**…), word motions (**Ctrl+←/→**), **Shift+Tab**, **Insert**, **PageUp/PageDown** and **F1–F12**.
|
|
109
|
+
|
|
110
|
+
- The overlay adapts to the terminal: it caps its width so no row wraps, drops the description column when narrow, shows fewer rows near the bottom, and falls back to a single inline ghost hint when a full frame would not fit (obeying `ghost_text`).
|
|
111
|
+
- A continued line (`PS2`, for example an unclosed quote) clears the panel instead of suggesting against a stale buffer, and the working directory is reported at every prompt, so `cd` changes are reflected in contextual suggestions.
|
|
100
112
|
- To bypass the wrapper for one shell, run:
|
|
101
113
|
|
|
102
114
|
```bash
|
|
@@ -143,6 +155,7 @@ hs init
|
|
|
143
155
|
|
|
144
156
|
Open a new terminal after initialization. The wrapper starts the same shell as a child through the Unix pseudo-terminal backend. It preserves the opening directory and synchronizes the current directory after each prompt, so contextual suggestions follow `cd` changes.
|
|
145
157
|
|
|
158
|
+
- The key bindings are the Git Bash table above: **↑/↓** and **Alt+↑/↓**, **Tab**, **→** (inline hint), **Alt+→** (next word), **Esc** (sticky hide) and **Ctrl+Space** (re-open).
|
|
146
159
|
- **Tab** keeps native Bash/Zsh path and flag completion authoritative; HintShell accepts only compatible command-prefix suggestions.
|
|
147
160
|
- **Interactive programs** such as `gh auth login`, `fzf`, `vim`, and `nano` receive raw terminal input while running; the overlay resumes automatically at the next prompt.
|
|
148
161
|
- **Bash escape hatch:** `HINTSHELL_DISABLE_AUTO_BASH=1 bash`
|
|
@@ -167,27 +180,59 @@ Each request includes the current working directory and shell. HintShell merges
|
|
|
167
180
|
|
|
168
181
|
### 🎨 Customization (`~/.hintshell/config.toml`)
|
|
169
182
|
|
|
170
|
-
HintShell creates a configuration file at `~/.hintshell/config.toml` automatically on initial setup
|
|
183
|
+
HintShell creates a configuration file at `~/.hintshell/config.toml` automatically on initial setup. **The same file styles the live Bash/Zsh overlay and the PowerShell module**, so one edit applies to every surface.
|
|
171
184
|
|
|
172
185
|
```toml
|
|
173
|
-
#
|
|
174
|
-
# - "apple"
|
|
175
|
-
# - "rainbow"
|
|
176
|
-
# - Solid tones: "purple" (default)
|
|
186
|
+
# Frame colour. Aliases are accepted; an unknown name falls back to purple and `hs config` says so.
|
|
187
|
+
# - Apple-style glow (24-bit gradient): "apple" | "siri" | "apple-intelligence" | "glow" | "neon"
|
|
188
|
+
# - Multi-colour spectrum (24-bit gradient): "rainbow" | "gemini" | "gradient" | "aurora"
|
|
189
|
+
# - Solid tones: "purple" (default) | "blue" | "cyan" | "green" | "yellow" | "gold" | "orange"
|
|
190
|
+
# "pink" | "rose" | "magenta" | "red" | "minimal" | "gray" | "grey"
|
|
177
191
|
border_color = "apple"
|
|
178
192
|
|
|
179
|
-
#
|
|
193
|
+
# Rows shown in the overlay (default: 6). Clamped to 3..=10; anything outside is reported.
|
|
180
194
|
max_visible = 6
|
|
181
195
|
|
|
182
|
-
#
|
|
196
|
+
# Inline ghost text next to the cursor. Also the fallback used when the terminal is too
|
|
197
|
+
# short or too narrow to draw a full frame (default: true).
|
|
183
198
|
ghost_text = true
|
|
184
199
|
```
|
|
185
200
|
|
|
201
|
+
```bash
|
|
202
|
+
hs config # effective values, the palette, 24-bit support, and any setting being ignored
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Gradient presets are painted with 24-bit colour. When `COLORTERM` does not advertise `truecolor`/`24bit` (legacy conhost, `TERM=xterm-256color`), the frame degrades to the closest 256-colour code instead of showing escape-sequence noise.
|
|
206
|
+
|
|
207
|
+
### 🔎 How to read a suggestion row
|
|
208
|
+
|
|
209
|
+
The right-hand column answers "where did this come from?", "how did it match?" and "how often?". The same vocabulary is used in Bash, Zsh and PowerShell.
|
|
210
|
+
|
|
211
|
+
| Marker | Meaning |
|
|
212
|
+
|---|---|
|
|
213
|
+
| `here` | You ran it in this directory before — the strongest signal. |
|
|
214
|
+
| `history` | You ran it somewhere else before. |
|
|
215
|
+
| `most used` | One of your most frequent commands. |
|
|
216
|
+
| `starter` | From the built-in catalogue of 600+ documented commands. |
|
|
217
|
+
| `path` `scripts` `git` `docker` `ssh hosts` `folders` `cargo` | Contextual candidate generated from a real path, project script, branch, container, host, folder or crate. |
|
|
218
|
+
| *(no tag)* | Your input is an actual prefix of the command. |
|
|
219
|
+
| `~` | Substring or fuzzy match — letters present but not adjacent; read the row before accepting. |
|
|
220
|
+
| `≈` | Typo-tolerant match (`gti` → `git`). |
|
|
221
|
+
| `Nx` | Used N times (only shown when the counter is real; contextual candidates show none). |
|
|
222
|
+
| `!` and `[!] risky` | Destructive command (`rm -rf`, `git reset --hard`, `docker system prune -af`, `terraform destroy`…). **→** and **Alt+→** refuse it: use **Tab** on the visible row so you have read it first. |
|
|
223
|
+
|
|
224
|
+
The description line explains what the selected command does, and falls back to `used Nx · here` or `no description` so it is never an empty gap.
|
|
225
|
+
|
|
186
226
|
### PowerShell (Windows/Unix)
|
|
187
|
-
|
|
188
|
-
-
|
|
189
|
-
|
|
190
|
-
-
|
|
227
|
+
|
|
228
|
+
**Real-time Overlay**: Suggestions appear automatically as a floating panel beneath your cursor as you type, using the same `~/.hintshell/config.toml`, the same labels and the same tiers as the Bash overlay.
|
|
229
|
+
|
|
230
|
+
- **↑ / ↓** navigate the list; with no panel open they stay history keys.
|
|
231
|
+
- **Tab** accept · **→** accept the inline hint · **Alt+→** accept one word.
|
|
232
|
+
- **Esc** hides the panel for the current line (sticky); **Ctrl+Space** brings it back.
|
|
233
|
+
- **Ctrl+R** is still PowerShell's own history search, and non-ASCII input (e.g. Vietnamese folder names) is suggested like anything else.
|
|
234
|
+
|
|
235
|
+
Text uses bold/dim and underline as well as colour, and the panel no longer forces a bright foreground, so rows stay readable on light themes.
|
|
191
236
|
|
|
192
237
|
---
|
|
193
238
|
|
|
@@ -240,6 +285,7 @@ npm uninstall -g hintshell
|
|
|
240
285
|
hs status # Check if the daemon is running and see stats
|
|
241
286
|
hs start # Manually start the daemon
|
|
242
287
|
hs stop # Stop the daemon
|
|
288
|
+
hs config # Show the effective overlay config and report values it ignores
|
|
243
289
|
hs update # Stop daemon, npm install -g, init, restart
|
|
244
290
|
hs uninstall # Completely remove shell integration and binaries
|
|
245
291
|
```
|
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# End-to-end marker check through a real pseudo-console.
|
|
3
|
+
#
|
|
4
|
+
# The unit tests cover the filters, but the defect this guards against lived one layer lower:
|
|
5
|
+
# Windows ConPTY re-maps bare control bytes through the console codepage (0x1e becomes the
|
|
6
|
+
# glyph "▲"), so a filter matching raw bytes can pass every unit test and still print marker
|
|
7
|
+
# garbage on a real terminal. Here the wrapper pumps a genuine session and we inspect the very
|
|
8
|
+
# bytes it would send to the screen.
|
|
9
|
+
#
|
|
10
|
+
# Usage: bash scripts/test-marker-conpty.sh [path-to-hintshell]
|
|
11
|
+
set -uo pipefail
|
|
12
|
+
|
|
13
|
+
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
14
|
+
bin="${1:-}"
|
|
15
|
+
if [ -z "$bin" ]; then
|
|
16
|
+
for candidate in "$repo/target/release/hintshell.exe" "$repo/target/release/hintshell" \
|
|
17
|
+
"$repo/target/debug/hintshell.exe" "$repo/target/debug/hintshell"; do
|
|
18
|
+
[ -x "$candidate" ] && bin="$candidate" && break
|
|
19
|
+
done
|
|
20
|
+
fi
|
|
21
|
+
[ -n "$bin" ] || { echo "FAIL: hintshell binary not found (run cargo build --release first)"; exit 1; }
|
|
22
|
+
|
|
23
|
+
out="$(mktemp)"; err="$(mktemp)"
|
|
24
|
+
trap 'rm -f "$out" "$err"' EXIT
|
|
25
|
+
|
|
26
|
+
# The wrapper exits when the piped session ends; a timeout keeps a hung run from blocking CI.
|
|
27
|
+
printf 'pwd\nexit\n' | timeout 30 "$bin" bash --login -i > "$out" 2> "$err" || true
|
|
28
|
+
|
|
29
|
+
fail=0
|
|
30
|
+
# Prove the pump actually rendered the session, otherwise the checks below are vacuous.
|
|
31
|
+
if [ "$(wc -c < "$out")" -lt 40 ]; then
|
|
32
|
+
echo "FAIL: the pumped session produced no output, this test proves nothing"
|
|
33
|
+
sed -n '1,5p' "$err"
|
|
34
|
+
fail=1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
if LC_ALL=C grep -qa 'HINTSHELL' "$out"; then
|
|
38
|
+
echo "FAIL: marker text reached the screen"
|
|
39
|
+
LC_ALL=C grep -a -o '.\{0,40\}HINTSHELL.\{0,40\}' "$out" | head -2
|
|
40
|
+
fail=1
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
if LC_ALL=C grep -qa '5522' "$out"; then
|
|
44
|
+
echo "FAIL: an OSC marker survived the filters"
|
|
45
|
+
fail=1
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# 0x1e and 0x1f rendered through the console codepage arrive as these two glyphs.
|
|
49
|
+
if LC_ALL=C grep -qa $'\xe2\x96\xb2\|\xe2\x96\xbc' "$out"; then
|
|
50
|
+
echo "FAIL: a control byte was re-mapped into a ▲/▼ glyph on the screen stream"
|
|
51
|
+
fail=1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
[ "$fail" -eq 0 ] && echo "CONPTY MARKER STREAM OK"
|
|
55
|
+
exit "$fail"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Regression test for the marker protocol gate.
|
|
3
|
+
#
|
|
4
|
+
# The live overlay reads protocol markers out of the shell's own output: OSC 5522 payloads
|
|
5
|
+
# for the working directory, end-of-prompt, continuation and startup phase. A marker emitted
|
|
6
|
+
# by a shell nobody is pumping reaches the terminal literally, and the user sees garbage like
|
|
7
|
+
# "▲HINTSHELL_CWD:C:\Users\ADMIN▼" plus an overlay that flickers because it never receives a
|
|
8
|
+
# prompt event. So: only the wrapper's own shell may emit them.
|
|
9
|
+
#
|
|
10
|
+
# Markers must stay inside an escape sequence. A bare 0x1e byte is re-mapped by Windows
|
|
11
|
+
# ConPTY through the console codepage into the printable glyph "▲", which no wrapper can
|
|
12
|
+
# recognise; an OSC that a terminal does not implement is ignored instead of printed.
|
|
13
|
+
#
|
|
14
|
+
# Usage: bash scripts/test-marker-gate.sh [path-to-hintshell]
|
|
15
|
+
set -euo pipefail
|
|
16
|
+
|
|
17
|
+
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
18
|
+
bin="${1:-}"
|
|
19
|
+
if [ -z "$bin" ]; then
|
|
20
|
+
for candidate in "$repo/target/release/hintshell.exe" "$repo/target/release/hintshell" \
|
|
21
|
+
"$repo/target/debug/hintshell.exe" "$repo/target/debug/hintshell"; do
|
|
22
|
+
[ -x "$candidate" ] && bin="$candidate" && break
|
|
23
|
+
done
|
|
24
|
+
fi
|
|
25
|
+
[ -n "$bin" ] || { echo "FAIL: hintshell binary not found (run cargo build --release first)"; exit 1; }
|
|
26
|
+
|
|
27
|
+
hookfile="$(mktemp)"
|
|
28
|
+
trap 'rm -f "$hookfile"' EXIT
|
|
29
|
+
"$bin" hook bash > "$hookfile" 2>/dev/null
|
|
30
|
+
|
|
31
|
+
# cat -v renders ESC as ^[ and BEL as ^G, so the assertions below also prove the markers are
|
|
32
|
+
# escape-sequenced rather than plain printable text.
|
|
33
|
+
emit() { cat -v | tr -d '\n\r'; }
|
|
34
|
+
# `|| true` matters: in the quiet cases the marker function is deliberately undefined, and a
|
|
35
|
+
# 127 from the inner shell must not abort the script before the assertions get to judge it.
|
|
36
|
+
run() { bash -c "source '$hookfile'; $1" 2>/dev/null | emit || true; }
|
|
37
|
+
|
|
38
|
+
wrapped="$(HINTSHELL_LIVE_BASH=1 HINTSHELL_MARKER_TOKEN=999 run '_hintshell_emit_prompt')"
|
|
39
|
+
old_wrapper="$(HINTSHELL_LIVE_BASH=1 run '_hintshell_emit_prompt')"
|
|
40
|
+
nested="$(HINTSHELL_LIVE_BASH=1 HINTSHELL_MARKER_TOKEN=999 \
|
|
41
|
+
run "bash -c \"source '$hookfile'; _hintshell_emit_prompt\"")"
|
|
42
|
+
resourced="$(HINTSHELL_LIVE_BASH=1 HINTSHELL_MARKER_TOKEN=999 run "source '$hookfile'; _hintshell_emit_prompt")"
|
|
43
|
+
unwrapped="$(run '_hintshell_emit_prompt')"
|
|
44
|
+
continuation="$(HINTSHELL_LIVE_BASH=1 HINTSHELL_MARKER_TOKEN=999 run 'printf %s "$PS2"')"
|
|
45
|
+
plain_continuation="$(HINTSHELL_LIVE_BASH=1 run 'printf %s "$PS2"')"
|
|
46
|
+
|
|
47
|
+
echo "wrapper's own shell : [$wrapped]"
|
|
48
|
+
echo "old wrapper (no token): [$old_wrapper]"
|
|
49
|
+
echo "nested bash : [$nested]"
|
|
50
|
+
echo "re-sourced shell : [$resourced]"
|
|
51
|
+
echo "unwrapped bash : [$unwrapped]"
|
|
52
|
+
echo "PS2 with token : [$continuation]"
|
|
53
|
+
echo "PS2 without token : [$plain_continuation]"
|
|
54
|
+
|
|
55
|
+
fail=0
|
|
56
|
+
expect_markers() { case "$2" in *'^[]5522;hintshell_cwd='*'^[]5522;hintshell_prompt^G'*) ;; *) echo "FAIL: $1 emitted no OSC markers"; fail=1;; esac; }
|
|
57
|
+
expect_quiet() { [ -z "$2" ] || { echo "FAIL: $1 emitted markers nobody filters"; fail=1; }; }
|
|
58
|
+
|
|
59
|
+
expect_markers "wrapper's own shell" "$wrapped"
|
|
60
|
+
expect_markers "re-sourced shell" "$resourced"
|
|
61
|
+
expect_quiet "old wrapper (no token)" "$old_wrapper"
|
|
62
|
+
expect_quiet "nested bash" "$nested"
|
|
63
|
+
expect_quiet "unwrapped bash" "$unwrapped"
|
|
64
|
+
case "$continuation" in *'^[]5522;hintshell_continuation^G'*) ;; *) echo "FAIL: no continuation marker with a token"; fail=1;; esac
|
|
65
|
+
expect_quiet "PS2 without token" "$plain_continuation"
|
|
66
|
+
|
|
67
|
+
[ "$fail" -eq 0 ] && echo "MARKER GATE OK"
|
|
68
|
+
exit "$fail"
|
|
@@ -59,6 +59,7 @@ try {
|
|
|
59
59
|
if ($moduleText -notmatch 'Test-HSDaemonAlive\s+-TimeoutMs') { throw 'Daemon timeout source check failed' }
|
|
60
60
|
if ($timeoutMs -lt 100 -or $timeoutMs -gt 10000) { throw "Timeout sanity check failed: $timeoutMs ms" }
|
|
61
61
|
Write-Host "OK source/timeout sanity (daemon timeout=$timeoutMs ms)" -ForegroundColor Green
|
|
62
|
+
Write-Host 'Static source rules are pinned by scripts/test-overlay-layout.ps1; this harness only checks what a human must see.' -ForegroundColor DarkGray
|
|
62
63
|
|
|
63
64
|
$psReadLine = Get-Module -ListAvailable -Name PSReadLine | Select-Object -First 1
|
|
64
65
|
if (-not $psReadLine) { throw 'PSReadLine is not available' }
|
|
@@ -70,17 +71,39 @@ try {
|
|
|
70
71
|
New-Item -ItemType Directory -Path $tempDataHome -Force | Out-Null
|
|
71
72
|
$env:HINTSHELL_HOME = $tempHome
|
|
72
73
|
$env:HINTSHELL_DATA_HOME = $tempDataHome
|
|
74
|
+
# Deterministic config so the "4 rows / red frame" check below means something.
|
|
75
|
+
@(
|
|
76
|
+
'border_color = "red"',
|
|
77
|
+
'max_visible = 4',
|
|
78
|
+
'ghost_text = true'
|
|
79
|
+
) | Set-Content -LiteralPath (Join-Path $tempHome 'config.toml') -Encoding utf8
|
|
80
|
+
Write-Host "Config under test: border_color=red max_visible=4 ghost_text=true ($tempHome)" -ForegroundColor DarkGray
|
|
73
81
|
Import-Module $manifest -Force -DisableNameChecking -ErrorAction Stop
|
|
74
82
|
$imported = $true
|
|
75
83
|
Start-HintShell -Force -Quiet
|
|
76
84
|
Write-Host 'OK HintShell module imported and startup completed.' -ForegroundColor Green
|
|
77
85
|
|
|
86
|
+
Add-OperatorResult 'Config is honoured' 'Type `git` and count the suggestion rows. Expect at most 4 rows and a red frame, matching the config.toml written above and `hs config`.'
|
|
78
87
|
Add-OperatorResult 'Slow typing' 'Type a short command one character at a time, pausing between keys. Confirm suggestions/overlay remain stable and the line stays editable.'
|
|
79
88
|
Add-OperatorResult 'Fast typing' 'Type a short command quickly. Confirm the overlay does not corrupt, lag indefinitely, or consume characters.'
|
|
80
89
|
Add-OperatorResult 'Single-line paste' 'Paste one short command. Confirm it is inserted as one line and does not trigger one suggestion request per pasted character.'
|
|
81
90
|
Add-OperatorResult 'Multiline paste' 'Paste text containing a newline. Confirm multiline input remains usable and the overlay is suppressed or behaves safely.'
|
|
82
91
|
Add-OperatorResult 'Enter with daemon available' 'Type a harmless command such as `Write-Output overlay-test`, press Enter, and confirm the line is accepted once without a stuck overlay. The harness captures it but does not execute it.'
|
|
83
92
|
|
|
93
|
+
# --- Presentation and key-affordance matrix (the new UI contract) ---
|
|
94
|
+
Add-OperatorResult 'Non-ASCII input still suggests' 'Type a command containing Vietnamese or other non-ASCII text, for example: Write-Output tài liệu. Confirm suggestions still appear for the rest of the line: the old ASCII-only guard is gone.'
|
|
95
|
+
Add-OperatorResult 'Typo tolerance is visible' 'Type `gti` (a transposition of git). Confirm at least one row appears and carries the ~= typo tag rather than vanishing.'
|
|
96
|
+
Add-OperatorResult 'Substring and fuzzy rows are not filtered' 'Type `com` or `sh`. Confirm rows whose command does not start with that text are still listed instead of an empty panel.'
|
|
97
|
+
Add-OperatorResult 'Source labels' 'Type `git ` and read the right-hand column. Confirm labels such as here / history / most used / starter / path instead of raw source keys.'
|
|
98
|
+
Add-OperatorResult 'Right arrow accepts the inline hint' 'Type `git st`, wait for the hint, then press Right once. Confirm the suffix is inserted onto the line and nothing is executed.'
|
|
99
|
+
Add-OperatorResult 'Alt+Right accepts one word' 'Type `git ` with a multi-word suggestion visible, press Alt+Right. Confirm exactly one word is inserted, then repeat.'
|
|
100
|
+
Add-OperatorResult 'Destructive rows are marked and refused by arrow' 'Select a risky row such as `rm -rf` or `git reset --hard` (navigate with Up/Down). Confirm it shows ! and "[!] risky", and that Right does NOT insert it; Tab still accepts it deliberately.'
|
|
101
|
+
Add-OperatorResult 'Escape is sticky' 'With the panel open press Escape, then keep typing two or three characters. Confirm the panel does not reappear. Press Ctrl+Space and confirm it comes back.'
|
|
102
|
+
Add-OperatorResult 'Counter and more indicator' 'Type something with many matches (for example `git`), then shrink the terminal height until only 2-3 rows fit. Confirm a visible N/total counter or more-marker so hidden matches are discoverable.'
|
|
103
|
+
Add-OperatorResult 'Narrow terminal layout' 'Resize the window to about 40 columns and type `git `. Confirm no row wraps to a second line and the frame stays inside the window; the description column may disappear.'
|
|
104
|
+
Add-OperatorResult 'Ghost fallback when a frame cannot fit' 'With ghost_text=true, put the cursor near the bottom so fewer than 3 rows remain. Confirm an inline grey hint still appears instead of nothing at all.'
|
|
105
|
+
Add-OperatorResult 'Light theme readability' 'Switch the terminal to a light colour scheme and open the panel. Confirm every row is readable: no forced bright-white text, selected row distinguishable without colour alone.'
|
|
106
|
+
|
|
84
107
|
Write-Host "`n[Daemon unavailable]" -ForegroundColor Cyan
|
|
85
108
|
Write-Host 'The next command stops this test daemon through the module cleanup path. Do not stop unrelated HintShell daemons.'
|
|
86
109
|
hs stop
|
|
@@ -4,8 +4,9 @@ Set-Location $repo
|
|
|
4
4
|
|
|
5
5
|
$overlay = Join-Path $repo 'integrations/powershell/HintShellModule/HintShellOverlay.ps1'
|
|
6
6
|
$handlers = Join-Path $repo 'integrations/powershell/HintShellModule/HintShellHandlers.ps1'
|
|
7
|
+
$module = Join-Path $repo 'integrations/powershell/HintShellModule/HintShellModule.psm1'
|
|
7
8
|
|
|
8
|
-
foreach ($f in @($overlay, $handlers)) {
|
|
9
|
+
foreach ($f in @($overlay, $handlers, $module)) {
|
|
9
10
|
$tokens = $null; $errors = $null
|
|
10
11
|
$null = [System.Management.Automation.Language.Parser]::ParseFile($f, [ref]$tokens, [ref]$errors)
|
|
11
12
|
if ($errors -and $errors.Count -gt 0) {
|
|
@@ -16,6 +17,49 @@ foreach ($f in @($overlay, $handlers)) {
|
|
|
16
17
|
Write-Host "OK parse $f"
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
# --- source contract ---------------------------------------------------------------
|
|
21
|
+
# These rules are invisible in a screenshot but cheap to pin: if someone re-adds a
|
|
22
|
+
# client-side filter or a bright-white foreground, the review that removed it is undone.
|
|
23
|
+
$overlayText = Get-Content -LiteralPath $overlay -Raw
|
|
24
|
+
$handlerText = Get-Content -LiteralPath $handlers -Raw
|
|
25
|
+
$moduleText = Get-Content -LiteralPath $module -Raw
|
|
26
|
+
$contract = @(
|
|
27
|
+
@{ Name = 'module binds RightArrow hint accept'; Text = $moduleText; MustMatch = '-Key RightArrow\s' }
|
|
28
|
+
@{ Name = 'module binds Alt+RightArrow word accept'; Text = $moduleText; MustMatch = 'Alt\+RightArrow' }
|
|
29
|
+
@{ Name = 'module binds Ctrl+Space re-open'; Text = $moduleText; MustMatch = 'Ctrl\+Spacebar' }
|
|
30
|
+
@{ Name = 'overlay reads the shared config.toml'; Text = $overlayText; MustMatch = 'Get-HSConfig' }
|
|
31
|
+
@{ Name = 'overlay does not force a bright foreground'; Text = $overlayText; MustNotMatch = '38;5;255' }
|
|
32
|
+
@{ Name = 'overlay keeps the daemon ranking (no prefix filter)'; Text = $overlayText; MustNotMatch = '-like\s"\$Typed' }
|
|
33
|
+
@{ Name = 'handlers do not reject non-ASCII input'; Text = $handlerText; MustNotMatch = '\[\^\\x00-\\x7F\]' }
|
|
34
|
+
@{ Name = 'handlers honour a dismissed panel'; Text = $handlerText; MustMatch = 'HS\.Dismissed' }
|
|
35
|
+
# A closure copies the module's $script:HS, so keypresses would move a private clone and
|
|
36
|
+
# the visible panel would never change. Up/Down and Right get their mode from the key.
|
|
37
|
+
@{ Name = 'no handler factory clones module state with GetNewClosure'; Text = $handlerText; MustNotMatch = '\.GetNewClosure\(\)' }
|
|
38
|
+
@{ Name = 'navigation binds one shared scriptblock'; Text = $moduleText; MustNotMatch = '-Direction' }
|
|
39
|
+
@{ Name = 'word-accept binds one shared scriptblock'; Text = $moduleText; MustNotMatch = 'Get-HSHintAcceptHandler -Word' }
|
|
40
|
+
)
|
|
41
|
+
foreach ($rule in $contract) {
|
|
42
|
+
if ($rule.ContainsKey('MustNotMatch')) {
|
|
43
|
+
if ($rule.Text -match $rule.MustNotMatch) { throw "contract broken: $($rule.Name)" }
|
|
44
|
+
} elseif ($rule.Text -notmatch $rule.MustMatch) {
|
|
45
|
+
throw "contract missing: $($rule.Name)"
|
|
46
|
+
}
|
|
47
|
+
Write-Host "OK contract $($rule.Name)"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# Deterministic config: the overlay now reads the same ~/.hintshell/config.toml as the
|
|
51
|
+
# Rust side, so the tests pin it instead of inheriting the developer's theme.
|
|
52
|
+
$configHome = Join-Path ([System.IO.Path]::GetTempPath()) ("hs-layout-test-" + [guid]::NewGuid().ToString('N'))
|
|
53
|
+
$previousHome = $env:HINTSHELL_HOME
|
|
54
|
+
New-Item -ItemType Directory -Path $configHome -Force | Out-Null
|
|
55
|
+
Set-Content -LiteralPath (Join-Path $configHome 'config.toml') -Value @(
|
|
56
|
+
'border_color = "apple"',
|
|
57
|
+
'max_visible = 99',
|
|
58
|
+
'ghost_text = false'
|
|
59
|
+
)
|
|
60
|
+
$env:HINTSHELL_HOME = $configHome
|
|
61
|
+
|
|
62
|
+
try {
|
|
19
63
|
. $overlay
|
|
20
64
|
function script:Invoke-HSDaemon { param($Query, $Limit) @() }
|
|
21
65
|
|
|
@@ -33,9 +77,142 @@ if ($ml2) { throw 'single-line false positive' }
|
|
|
33
77
|
$tw = Get-HSDisplayWidth -Text $t1
|
|
34
78
|
if ($tw -gt 10) { throw "trunc too wide: $tw" }
|
|
35
79
|
|
|
36
|
-
#
|
|
80
|
+
# --- configuration is shared with the Rust overlay -------------------------------
|
|
81
|
+
$config = Get-HSConfig
|
|
82
|
+
if ($config.BorderColor -ne 'apple') { throw "border_color not read: $($config.BorderColor)" }
|
|
83
|
+
if ($config.MaxVisible -ne 10) { throw "max_visible not clamped to 10: $($config.MaxVisible)" }
|
|
84
|
+
if ($config.GhostText) { throw 'ghost_text=false not honoured' }
|
|
85
|
+
if ((Get-HSAccentCode -Name 'apple') -ne '51') { throw 'apple accent' }
|
|
86
|
+
if ((Get-HSAccentCode -Name 'rainbow') -ne '141') { throw 'rainbow accent' }
|
|
87
|
+
if ((Get-HSAccentCode -Name 'nonsense') -ne '141') { throw 'unknown accent must fall back' }
|
|
88
|
+
|
|
37
89
|
$budget = Get-HSLayoutBudget -CursorTop 0
|
|
38
90
|
if ($budget.W -lt 20) { throw "W too small $($budget.W)" }
|
|
39
91
|
if ($budget.VpMax -lt 1) { throw "vpMax invalid $($budget.VpMax)" }
|
|
40
|
-
|
|
41
|
-
Write-Host
|
|
92
|
+
if ($budget.VpMax -gt 10) { throw "vpMax ignored config clamp: $($budget.VpMax)" }
|
|
93
|
+
Write-Host "budget W=$($budget.W) compact=$($budget.Compact) vp=$($budget.VpMax) rows=$($budget.AvailableRows) accent=$($budget.Accent)"
|
|
94
|
+
|
|
95
|
+
# --- one vocabulary for every surface --------------------------------------------
|
|
96
|
+
if ((Get-HSSourceLabel -Source 'history-local') -ne 'here') { throw 'source label here' }
|
|
97
|
+
if ((Get-HSSourceLabel -Source 'zoxide') -ne 'folders') { throw 'source label folders' }
|
|
98
|
+
if ((Get-HSSourceLabel -Source 'wat') -ne 'history') { throw 'source label fallback' }
|
|
99
|
+
if ((Get-HSTierTag -Tier 0) -ne '') { throw 'tier 0 must be silent' }
|
|
100
|
+
if ((Get-HSTierTag -Tier 3) -ne ([string][char]0x2248)) { throw 'tier 3 typo tag' }
|
|
101
|
+
if ((Get-HSTierTag -Tier 4) -ne '~') { throw 'tier 4 fuzzy tag' }
|
|
102
|
+
|
|
103
|
+
# --- no invented usage counts, and risky items are marked without colour only ----
|
|
104
|
+
$contextual = [PSCustomObject]@{ command = 'cd src/'; description = 'directory'; frequency = 0; source = 'path'; tier = 1; risk = 'normal' }
|
|
105
|
+
$info = Get-HSItemInfo -Suggestion $contextual
|
|
106
|
+
if ($info -match '1x') { throw "contextual candidate invented a count: '$info'" }
|
|
107
|
+
if ($info -ne 'path') { throw "unexpected info: '$info'" }
|
|
108
|
+
|
|
109
|
+
$history = [PSCustomObject]@{ command = 'git status'; description = $null; frequency = 12; source = 'history-global'; tier = 0; risk = 'normal' }
|
|
110
|
+
if ((Get-HSItemInfo -Suggestion $history) -ne 'history 12x') { throw 'history info' }
|
|
111
|
+
if ((Get-HSFooterText -Suggestion $history) -ne 'used 12x . history') { throw "footer from usage: '$(Get-HSFooterText -Suggestion $history)'" }
|
|
112
|
+
|
|
113
|
+
$risky = [PSCustomObject]@{ command = 'rm -rf build'; description = 'Force remove'; frequency = 1; source = 'history-global'; tier = 0; risk = 'destructive' }
|
|
114
|
+
if (-not (Test-HSDestructive -Suggestion $risky)) { throw 'destructive not detected' }
|
|
115
|
+
if ((Get-HSItemInfo -Suggestion $risky) -notmatch '^! ') { throw 'risky info marker missing' }
|
|
116
|
+
if ((Get-HSFooterText -Suggestion $risky) -notmatch '^\[!\] risky') { throw 'risky footer missing' }
|
|
117
|
+
# Older daemons send no risk field at all: that must read as safe, not crash.
|
|
118
|
+
$legacy = [PSCustomObject]@{ command = 'git status'; description = 'x'; frequency = 1; source = 'history' }
|
|
119
|
+
if (Test-HSDestructive -Suggestion $legacy) { throw 'missing risk field must be safe' }
|
|
120
|
+
# ...but a missing field must not talk the panel out of warning about real damage.
|
|
121
|
+
$legacyRisky = [PSCustomObject]@{ command = 'rm -rf build'; description = 'x'; frequency = 1; source = 'history' }
|
|
122
|
+
if (-not (Test-HSDestructive -Suggestion $legacyRisky)) { throw 'legacy daemon lost the safety fallback' }
|
|
123
|
+
if ((Test-HSDestructive -Suggestion $risky) -ne $true) { throw 'explicit destructive marker lost' }
|
|
124
|
+
$safeMarked = [PSCustomObject]@{ command = 'git status'; description = 'x'; frequency = 1; source = 'history'; tier = 0; risk = 'normal' }
|
|
125
|
+
if (Test-HSDestructive -Suggestion $safeMarked) { throw 'daemon said normal, panel must believe it' }
|
|
126
|
+
|
|
127
|
+
# --- daemon metadata survives the projection -----------------------------------------
|
|
128
|
+
# tier and risk used to be dropped when rows were rebuilt, so no row could ever show the
|
|
129
|
+
# match-quality tag or the risky marker even though the daemon sent both.
|
|
130
|
+
function script:Invoke-HSDaemon {
|
|
131
|
+
param($Query, $Limit)
|
|
132
|
+
@(
|
|
133
|
+
[PSCustomObject]@{ command = 'rm -rf build'; description = ''; frequency = 3; source = 'history-global'; tier = 0; risk = 'destructive' },
|
|
134
|
+
[PSCustomObject]@{ command = 'gti status'; description = ''; frequency = 2; source = 'history-global'; tier = 3; risk = 'normal' },
|
|
135
|
+
[PSCustomObject]@{ command = 'docker system prune -af'; description = ''; frequency = 1; source = 'history-global' }
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
$rows = @(Get-HSSuggestions -Typed 'x')
|
|
139
|
+
if ($rows.Count -ne 3) { throw "projection changed the row count: $($rows.Count)" }
|
|
140
|
+
if (-not (Test-HSDestructive -Suggestion $rows[0])) { throw 'daemon risk marker lost in projection' }
|
|
141
|
+
if ([int]$rows[1].tier -ne 3) { throw "daemon tier lost in projection: $($rows[1].tier)" }
|
|
142
|
+
if ((Get-HSItemInfo -Suggestion $rows[1]) -notmatch [regex]::Escape([string][char]0x2248)) { throw 'typo tag never reached the info column' }
|
|
143
|
+
if (-not (Test-HSDestructive -Suggestion $rows[2])) { throw 'legacy daemon row lost the safety fallback' }
|
|
144
|
+
if (Get-HSTierTag -Tier $rows[2].tier) { throw 'a daemon without tiers must not claim match quality' }
|
|
145
|
+
function script:Invoke-HSDaemon { param($Query, $Limit) @() }
|
|
146
|
+
|
|
147
|
+
$noDescription = [PSCustomObject]@{ command = 'git status'; description = ''; frequency = 0; source = 'history'; tier = 0; risk = 'normal' }
|
|
148
|
+
if ((Get-HSFooterText -Suggestion $noDescription) -ne 'no description') { throw 'footer fallback' }
|
|
149
|
+
|
|
150
|
+
# --- inline preview and word-wise acceptance -------------------------------------
|
|
151
|
+
if ((Get-HSGhostSuffix -Command 'git checkout main' -Typed 'git ') -ne 'checkout main') { throw 'ghost suffix' }
|
|
152
|
+
if ((Get-HSGhostSuffix -Command 'git checkout main' -Typed 'GIT ') -ne 'checkout main') { throw 'ghost suffix case' }
|
|
153
|
+
if ((Get-HSGhostSuffix -Command 'rm -rf build' -Typed 'ru') -ne '') { throw 'ghost must refuse non-prefix' }
|
|
154
|
+
# One word at a time, no trailing space: same as the live Bash overlay's Alt+Right.
|
|
155
|
+
if ((Get-HSNextWordSuffix -Command 'git checkout main' -Typed 'git ') -ne 'checkout') { throw "next word: '$(Get-HSNextWordSuffix -Command 'git checkout main' -Typed 'git ')'" }
|
|
156
|
+
if ((Get-HSNextWordSuffix -Command 'git status' -Typed 'docker') -ne '') { throw 'next word must refuse non-prefix' }
|
|
157
|
+
|
|
158
|
+
$parts = Split-HSMatchedCommand -Command 'git status' -Typed 'stat'
|
|
159
|
+
if ($parts.Matched -ne 'stat' -or $parts.Before -ne 'git ' -or $parts.After -ne 'us') { throw "substring match split: $($parts | ConvertTo-Json -Compress)" }
|
|
160
|
+
$typo = Split-HSMatchedCommand -Command 'git status' -Typed 'gti'
|
|
161
|
+
if ($typo.Matched -ne '') { throw 'typo candidate must not fake a literal highlight' }
|
|
162
|
+
if ($typo.After -ne 'git status') { throw 'typo candidate must still show the command' }
|
|
163
|
+
|
|
164
|
+
# --- row arithmetic can never exceed the terminal width -------------------------
|
|
165
|
+
foreach ($width in 20..100) {
|
|
166
|
+
$row = Get-HSRowLayout -Width $width -Info 'history 12x'
|
|
167
|
+
if ($row.Total -gt $width) { throw "row overflows at W=$width (Total=$($row.Total))" }
|
|
168
|
+
$compactRow = Get-HSRowLayout -Width $width -Compact -Info 'history 12x'
|
|
169
|
+
if ($compactRow.Total -gt $width) { throw "compact row overflows at W=$width" }
|
|
170
|
+
if ($compactRow.InfoW -ne 0) { throw 'compact layout must drop the info column' }
|
|
171
|
+
}
|
|
172
|
+
$wide = Get-HSRowLayout -Width 70 -Info 'history 12x'
|
|
173
|
+
if ($wide.InfoW -eq 0) { throw 'wide layout lost the explanation column' }
|
|
174
|
+
if ($wide.CmdW -lt 30) { throw "command still too short at W=70: $($wide.CmdW)" }
|
|
175
|
+
|
|
176
|
+
# --- behaviour: the bound arrow key really moves the visible selection ------------------
|
|
177
|
+
# The regression this catches: with a closure the handler incremented SelectedIndex inside a
|
|
178
|
+
# copy of $script:HS, so Down did nothing the user could see.
|
|
179
|
+
. $handlers
|
|
180
|
+
$script:HSDrawSelected = $null
|
|
181
|
+
function script:Draw-HSOverlay { param($Suggestions, $SelectedIndex, $TypedSoFar) $script:HSDrawSelected = $SelectedIndex }
|
|
182
|
+
|
|
183
|
+
$script:HS.IsVisible = $true
|
|
184
|
+
$script:HS.Dismissed = $false
|
|
185
|
+
$script:HS.ScrollOffset = 0
|
|
186
|
+
$script:HS.ViewportSize = 3
|
|
187
|
+
$script:HS.CurrentInput = 'git '
|
|
188
|
+
$script:HS.Suggestions = @(1..5 | ForEach-Object { [PSCustomObject]@{ command = "git c$_"; description = ''; frequency = 0; source = 'history'; tier = 0; risk = 'normal' } })
|
|
189
|
+
$script:HS.SelectedIndex = 0
|
|
190
|
+
|
|
191
|
+
$down = [ConsoleKeyInfo]::new([char]0, [ConsoleKey]::DownArrow, $false, $false, $false)
|
|
192
|
+
$up = [ConsoleKeyInfo]::new([char]0, [ConsoleKey]::UpArrow, $false, $false, $false)
|
|
193
|
+
if ((Get-HSNavigationDirection -Key $down) -ne 'Down') { throw 'DownArrow mapped to the wrong direction' }
|
|
194
|
+
if ((Get-HSNavigationDirection -Key $up) -ne 'Up') { throw 'UpArrow mapped to the wrong direction' }
|
|
195
|
+
|
|
196
|
+
$navigation = Get-HSNavigationHandler
|
|
197
|
+
& $navigation $down $null
|
|
198
|
+
if ($script:HS.SelectedIndex -ne 1) { throw "Down did not move the shared state: $($script:HS.SelectedIndex)" }
|
|
199
|
+
if ($script:HSDrawSelected -ne 1) { throw "Down did not redraw the panel with the new row: $($script:HSDrawSelected)" }
|
|
200
|
+
& $navigation $down $null
|
|
201
|
+
& $navigation $up $null
|
|
202
|
+
if ($script:HS.SelectedIndex -ne 1) { throw "Up did not move back: $($script:HS.SelectedIndex)" }
|
|
203
|
+
|
|
204
|
+
# One scriptblock serves both arrows, exactly as the module installs it.
|
|
205
|
+
if ((Get-HSNavigationHandler).ToString() -notmatch 'Get-HSNavigationDirection') { throw 'navigation handler lost its key-driven direction' }
|
|
206
|
+
|
|
207
|
+
$plainRight = [ConsoleKeyInfo]::new([char]0, [ConsoleKey]::RightArrow, $false, $false, $false)
|
|
208
|
+
$altRight = [ConsoleKeyInfo]::new([char]0, [ConsoleKey]::RightArrow, $false, $true, $false)
|
|
209
|
+
if (Test-HSWordAcceptKey -Key $plainRight) { throw 'plain Right must accept the whole inline hint' }
|
|
210
|
+
if (-not (Test-HSWordAcceptKey -Key $altRight)) { throw 'Alt+Right must accept a single word' }
|
|
211
|
+
Write-Host 'OK behaviour arrow keys move the shared selection state'
|
|
212
|
+
|
|
213
|
+
Write-Host 'UNIT OK'
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
Remove-Item -LiteralPath $configHome -Recurse -Force -ErrorAction SilentlyContinue
|
|
217
|
+
$env:HINTSHELL_HOME = $previousHome
|
|
218
|
+
}
|