pi-autosuggestions 0.2.4 → 0.3.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.
@@ -1 +1 @@
1
- {".":"0.2.4"}
1
+ {".":"0.3.1"}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.1](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.3.0...pi-autosuggestions-v0.3.1) (2026-09-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * keep the character under the cursor visible while the beam blinks ([16833a7](https://github.com/0xPlayerOne/pi-autosuggestions/commit/16833a788d30fb92e99a98fd29927d2ecaed8790))
9
+
10
+ ## [0.3.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.2.4...pi-autosuggestions-v0.3.0) (2026-09-04)
11
+
12
+
13
+ ### Features
14
+
15
+ * command-name completion from PATH at the bash command position ([9b4eef6](https://github.com/0xPlayerOne/pi-autosuggestions/commit/9b4eef62c780979fc972cb2d304eeefe8fd98db7))
16
+
3
17
  ## [0.2.4](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.2.3...pi-autosuggestions-v0.2.4) (2026-09-04)
4
18
 
5
19
 
package/README.md CHANGED
@@ -23,6 +23,21 @@ pi install git:github.com/0xPlayerOne/pi-autosuggestions@pi-autosuggestions-v0.2
23
23
  pi install npm:pi-autosuggestions
24
24
  ```
25
25
 
26
+ ## Scope
27
+
28
+ | Layer | Where it works |
29
+ |-------|----------------|
30
+ | History ghost suggestions | **Everywhere** — normal prompts and `!`/`!!` bash mode |
31
+ | Path completion + dropdown | **Bash mode only** (`!`/`!!` commands) |
32
+ | Command-name completion | **Bash mode only**, first word after `!` |
33
+ | Beam cursor | **Everywhere** |
34
+
35
+ History is **session-scoped**: the ghost can only suggest prompts you already
36
+ submitted *in the current session* (pi has no persistent shell-history file
37
+ across sessions yet). If you mostly run `!` commands, the ghost will mostly
38
+ appear in bash mode — it isn't restricted there, it just has nothing to
39
+ suggest elsewhere.
40
+
26
41
  ## Features
27
42
 
28
43
  ### zsh-autosuggestions behavior
@@ -37,6 +52,20 @@ pi install npm:pi-autosuggestions
37
52
  - **`Esc`** — dismiss the suggestion until your next edit
38
53
  - Suggestion hides when the cursor leaves end-of-line, returns when you come back
39
54
 
55
+ ### Command completion (bash mode)
56
+
57
+ The first word after `!` completes against **executables on your `$PATH`** —
58
+ like zsh's command position, no plugins needed:
59
+
60
+ | Input | Result |
61
+ |-------|--------|
62
+ | `!gi` | dropdown — `git`, `gh`, `gimp`, … (marked `command`) |
63
+ | `!whoa` | inline ghost `mi` → `whoami` |
64
+
65
+ File paths that also match are listed after the commands. Per-command
66
+ *subcommand* completion (`git st` → `status`) is zsh's `compdef` system and is
67
+ out of scope — use history or type it.
68
+
40
69
  ### Path completion (fish/zsh-completion flavored)
41
70
 
42
71
  In bash mode (`!command`), a second strategy completes **filesystem paths**:
@@ -20,6 +20,9 @@ import {
20
20
  } from "@earendil-works/pi-tui";
21
21
 
22
22
  /** Runtime access to Editor internals that are private in the type declarations. */
23
+ import { readdirSync, statSync } from "node:fs";
24
+ import type { AutocompleteItem } from "@earendil-works/pi-tui";
25
+
23
26
  interface EditorInternals {
24
27
  state: { lines: string[]; cursorLine: number; cursorCol: number };
25
28
  autocompleteProvider?: AutocompleteProvider | null;
@@ -200,7 +203,11 @@ class BashInlineEditor extends CustomEditor {
200
203
  return out;
201
204
  }
202
205
  const ch = match[1] || " ";
203
- const cursorCell = this.cursorOn ? BEAM : ch;
206
+ // The beam only replaces empty cells — over a letter it would black
207
+ // the character out every other blink. Cursor over a letter instead
208
+ // renders that letter underlined while visible (zsh bar cursors draw
209
+ // the bar in the same cell; a terminal grid can't, so underline wins).
210
+ const cursorCell = this.cursorOn ? (ch === " " ? BEAM : `\x1b[4m${ch}${RESET}`) : ch;
204
211
  out[rowIdx] = head + cursorCell + row.slice(match.index + match[0].length);
205
212
  return out;
206
213
  }
@@ -248,6 +255,52 @@ class BashInlineEditor extends CustomEditor {
248
255
  * The ghost-vs-dropdown split (one match → ghost, many → dropdown) is
249
256
  * decided in updateGhost(), which sees the final suggestion counts.
250
257
  */
258
+ /** Executable names on $PATH, cached for the session (zsh command completion). */
259
+ private pathCommandCache: string[] | null = null;
260
+
261
+ private getPathCommands(): string[] {
262
+ if (this.pathCommandCache) {
263
+ return this.pathCommandCache;
264
+ }
265
+ const names = new Set<string>();
266
+ for (const dir of (process.env.PATH ?? "").split(":")) {
267
+ if (!dir) {
268
+ continue;
269
+ }
270
+ let entries;
271
+ try {
272
+ entries = readdirSync(dir);
273
+ } catch {
274
+ continue;
275
+ }
276
+ for (const name of entries) {
277
+ if (names.has(name)) {
278
+ continue;
279
+ }
280
+ try {
281
+ // eslint-disable-next-line no-bitwise
282
+ if (statSync(`${dir}/${name}`).mode & 0o111) {
283
+ names.add(name);
284
+ }
285
+ } catch {
286
+ // dangling symlink or unreadable entry
287
+ }
288
+ }
289
+ }
290
+ this.pathCommandCache = [...names].sort();
291
+ return this.pathCommandCache;
292
+ }
293
+
294
+ /** PATH commands starting with the typed command word. */
295
+ private matchingCommands(word: string): string[] {
296
+ if (!word) {
297
+ return [];
298
+ }
299
+ return this.getPathCommands()
300
+ .filter((name) => name.startsWith(word))
301
+ .slice(0, 100);
302
+ }
303
+
251
304
  private createBashProvider(current: AutocompleteProvider): AutocompleteProvider {
252
305
  const self = this;
253
306
  return {
@@ -257,26 +310,54 @@ class BashInlineEditor extends CustomEditor {
257
310
  }
258
311
  const before = (lines[cursorLine] ?? "").slice(0, cursorCol);
259
312
  let queryLines = lines;
313
+ let commandItems: AutocompleteItem[] = [];
314
+ let word = "";
260
315
  if (self.commandPosition(before)) {
261
- // Neutralize the command word so the provider completes the
262
- // (empty) argument position: every entry matches.
316
+ word = before.replace(/^[ \t]*!+/, "");
317
+ const commands = self.matchingCommands(word);
263
318
  queryLines = [...lines];
264
- queryLines[cursorLine] = before.replace(/![^!\s]*$/, "! ");
319
+ if (commands.length > 0) {
320
+ // The typed word is a prefix of real commands: offer them
321
+ // first, plus any matching file paths as fallback.
322
+ commandItems = commands.map((name) => ({
323
+ value: name,
324
+ label: name,
325
+ description: "command",
326
+ }));
327
+ queryLines[cursorLine] = `! ${word}`;
328
+ } else {
329
+ // Neutralize the command word so the provider completes the
330
+ // (empty) argument position: every entry matches.
331
+ queryLines[cursorLine] = before.replace(/![^!\s]*$/, "! ");
332
+ }
265
333
  }
266
- return current.getSuggestions(queryLines, cursorLine, cursorCol, {
334
+ const suggestions = await current.getSuggestions(queryLines, cursorLine, cursorCol, {
267
335
  ...options,
268
336
  force: true,
269
337
  });
338
+ if (commandItems.length === 0) {
339
+ return suggestions;
340
+ }
341
+ return {
342
+ items: [...commandItems, ...(suggestions?.items ?? [])],
343
+ prefix: word,
344
+ };
270
345
  },
271
346
 
272
347
  applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
273
348
  const before = (lines[cursorLine] ?? "").slice(0, cursorCol);
274
349
  if (self.inBashMode() && self.commandPosition(before)) {
275
- // Completing from the command position: insert the chosen path
276
- // as the first argument ("!cd" + AppleStuff/ → "!cd AppleStuff/").
277
350
  const value = item.value ?? "";
278
351
  const line = lines[cursorLine] ?? "";
279
352
  const newLines = [...lines];
353
+ if (item.description === "command") {
354
+ // Completing the command word itself ("!gi" + git → "!git").
355
+ const start = cursorCol - prefix.length;
356
+ newLines[cursorLine] = line.slice(0, start) + value + line.slice(cursorCol);
357
+ return { lines: newLines, cursorLine, cursorCol: start + value.length };
358
+ }
359
+ // Completing from the command position: insert the chosen path
360
+ // as the first argument ("!cd" + AppleStuff/ → "!cd AppleStuff/").
280
361
  newLines[cursorLine] = `${line.slice(0, cursorCol)} ${value}${line.slice(cursorCol)}`;
281
362
  return { lines: newLines, cursorLine, cursorCol: cursorCol + 1 + value.length };
282
363
  }
@@ -336,7 +417,8 @@ class BashInlineEditor extends CustomEditor {
336
417
  if (!value || !value.toLowerCase().startsWith(token.toLowerCase())) {
337
418
  return null;
338
419
  }
339
- const separator = this.commandPosition(before) ? " " : "";
420
+ const isCommand = suggestions?.items[0]?.description === "command";
421
+ const separator = isCommand ? "" : (this.commandPosition(before) ? " " : "");
340
422
  const suggestion = before.slice(0, before.length - token.length) + separator + value;
341
423
  if (suggestion.length <= before.length) {
342
424
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-autosuggestions",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "zsh-autosuggestions-style ghost completions for the pi coding agent — history-based inline suggestions, path completion in bash mode, blinking beam cursor",
5
5
  "keywords": [
6
6
  "pi-package",