pi-autosuggestions 0.1.0 → 0.2.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.
|
@@ -3,10 +3,45 @@ name: Release
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
5
|
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
6
7
|
|
|
7
|
-
permissions:
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
pull-requests: write
|
|
11
|
+
id-token: write
|
|
8
12
|
|
|
9
13
|
jobs:
|
|
10
|
-
release:
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
release-please:
|
|
15
|
+
name: Release Please
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
outputs:
|
|
18
|
+
release_created: ${{ steps.release.outputs.release_created }}
|
|
19
|
+
tag_name: ${{ steps.release.outputs.tag_name }}
|
|
20
|
+
steps:
|
|
21
|
+
- name: Release Please
|
|
22
|
+
id: release
|
|
23
|
+
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v4/v5 pin
|
|
24
|
+
with:
|
|
25
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
26
|
+
config-file: release-please-config.json
|
|
27
|
+
manifest-file: .release-please-manifest.json
|
|
28
|
+
|
|
29
|
+
publish-npm:
|
|
30
|
+
name: Publish npm
|
|
31
|
+
needs: release-please
|
|
32
|
+
if: needs.release-please.outputs.release_created == 'true'
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
steps:
|
|
35
|
+
- name: Checkout release
|
|
36
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
37
|
+
with:
|
|
38
|
+
ref: ${{ needs.release-please.outputs.tag_name }}
|
|
39
|
+
- name: Setup Node
|
|
40
|
+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
|
41
|
+
with:
|
|
42
|
+
node-version: 24
|
|
43
|
+
registry-url: https://registry.npmjs.org
|
|
44
|
+
- name: Publish
|
|
45
|
+
run: npm publish --provenance --access public
|
|
46
|
+
env:
|
|
47
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{".":
|
|
1
|
+
{".":"0.2.1"}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.1](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.2.0...pi-autosuggestions-v0.2.1) (2026-09-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* add repository metadata required for npm provenance ([cfddf8d](https://github.com/0xPlayerOne/pi-autosuggestions/commit/cfddf8d17f9f359b6f73ec9e0fb68b67748de0d6))
|
|
9
|
+
|
|
10
|
+
## [0.2.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.1.0...pi-autosuggestions-v0.2.0) (2026-09-04)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add zsh-autosuggestions history strategy and partial accept ([951cd11](https://github.com/0xPlayerOne/pi-autosuggestions/commit/951cd1148f8ce63230efbbf6d6815d31048cbd03))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### CI
|
|
19
|
+
|
|
20
|
+
* add workflow_dispatch to release workflow ([599b7bb](https://github.com/0xPlayerOne/pi-autosuggestions/commit/599b7bbcb6460fe0550657e26a237652dc358d33))
|
|
21
|
+
* declare root package in release-please config ([7d505b9](https://github.com/0xPlayerOne/pi-autosuggestions/commit/7d505b9a0dcbef26162844baf7c02f09063090c7))
|
|
22
|
+
* match canonical code-foundry release caller shape ([8533336](https://github.com/0xPlayerOne/pi-autosuggestions/commit/85333360daa61d803d19020fad1b87f2d418aa11))
|
|
23
|
+
* minimal reusable workflow call test ([3864ab0](https://github.com/0xPlayerOne/pi-autosuggestions/commit/3864ab07d929fee682c10b6f7dcd005dcb59bf00))
|
|
24
|
+
* self-contained release-please and npm publish flow ([b56cf97](https://github.com/0xPlayerOne/pi-autosuggestions/commit/b56cf978b691f54afd93f739c63ba316ecbd7b84))
|
|
25
|
+
* test v0.39.0 ref ([be7e2d5](https://github.com/0xPlayerOne/pi-autosuggestions/commit/be7e2d503dd6543850ffd926dc0e44efc5c77a9d))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Maintenance
|
|
29
|
+
|
|
30
|
+
* rename package to pi-autosuggestions and adopt code-foundry release flow ([57b7265](https://github.com/0xPlayerOne/pi-autosuggestions/commit/57b7265afd63b4bcb65f5f8ac7ff9507fc820b5c))
|
package/README.md
CHANGED
|
@@ -1,67 +1,88 @@
|
|
|
1
1
|
# pi-autosuggestions
|
|
2
2
|
|
|
3
|
-
[zsh](https://
|
|
4
|
-
[pi coding agent](https://github.com/earendil-works/pi-mono)
|
|
3
|
+
[zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions)-style
|
|
4
|
+
ghost completions for the [pi coding agent](https://github.com/earendil-works/pi-mono),
|
|
5
|
+
with the path-completion layer fish and zsh users expect from a modern setup.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
no Tab required. Press `→`
|
|
8
|
-
|
|
7
|
+
As you type, a suggestion appears **dimmed, inline, right after your cursor** —
|
|
8
|
+
no dropdown, no Tab required. Press `→` to accept it all, `Alt+f` to accept it
|
|
9
|
+
one word at a time.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- **Smart mode switching**:
|
|
15
|
-
- exactly **1 match** → inline ghost
|
|
16
|
-
- **multiple matches** → the stock dropdown appears, fully interactive (arrow keys, Enter, mouse)
|
|
17
|
-
- **0 matches** → just the cursor
|
|
18
|
-
- **Command position aware** — typing `!cd` (no space yet) lists all entries; picking one inserts it as the first argument
|
|
19
|
-
- **Blinking beam cursor** — replaces the block cursor with a thin vertical bar that blinks at ~2 Hz and stays solid while you type
|
|
20
|
-
- **`!!` hidden shell commands** get completions too
|
|
21
|
-
- Zero dependencies — only peer-imports pi's own bundled modules
|
|
11
|
+
```
|
|
12
|
+
you type: !cd Desk
|
|
13
|
+
you see: !cd Desktop/ ( dimmed "top/", first char is your blinking cursor )
|
|
14
|
+
```
|
|
22
15
|
|
|
23
16
|
## Install
|
|
24
17
|
|
|
25
18
|
```bash
|
|
26
|
-
pi install git:github.com/0xPlayerOne/pi-autosuggestions
|
|
19
|
+
pi install git:github.com/0xPlayerOne/pi-autosuggestions
|
|
20
|
+
# or pinned:
|
|
21
|
+
pi install git:github.com/0xPlayerOne/pi-autosuggestions@v0.2.0
|
|
22
|
+
# or from npm:
|
|
23
|
+
pi install npm:pi-autosuggestions
|
|
27
24
|
```
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
## Features
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
pi install /path/to/pi-autosuggestions
|
|
33
|
-
```
|
|
28
|
+
### zsh-autosuggestions behavior
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
- **History strategy** — every prompt you submit is remembered; start typing a
|
|
31
|
+
prefix of a previous prompt and its continuation appears as dimmed ghost text,
|
|
32
|
+
most recent match first. Works everywhere in the editor, not just bash mode —
|
|
33
|
+
exactly like `zsh-autosuggestions` works on every shell line.
|
|
34
|
+
- **`→`** — accept the whole suggestion (`autosuggest-accept`)
|
|
35
|
+
- **`Alt+f` / `Ctrl+→`** — partial accept: take the next word
|
|
36
|
+
(`autosuggest-accept-word`), like zsh's default `alt+f` binding
|
|
37
|
+
- **`Esc`** — dismiss the suggestion until your next edit
|
|
38
|
+
- Suggestion hides when the cursor leaves end-of-line, returns when you come back
|
|
39
|
+
|
|
40
|
+
### Path completion (fish/zsh-completion flavored)
|
|
41
|
+
|
|
42
|
+
In bash mode (`!command`), a second strategy completes **filesystem paths**:
|
|
36
43
|
|
|
37
44
|
| Input | Result |
|
|
38
45
|
|-------|--------|
|
|
39
46
|
| `!cd` | dropdown — all entries |
|
|
40
47
|
| `!cd D` | dropdown — filtered to `D*` |
|
|
41
48
|
| `!cd Dow` | inline ghost `nloads/` |
|
|
42
|
-
| `→` / `Tab` | accept
|
|
43
|
-
|
|
|
49
|
+
| `→` / `Tab` | accept |
|
|
50
|
+
| accept a directory | immediately suggests its first entry (zsh-like chaining) |
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
- **Command position aware** — `!cd` (no space yet) lists everything; picking an
|
|
53
|
+
entry inserts it as the first argument
|
|
54
|
+
- **Priority**: multiple path options → stock dropdown (fully interactive);
|
|
55
|
+
zero or one option → ghost, with history winning over paths
|
|
56
|
+
- Works for `!!` hidden commands and any bash argument, not just `cd`
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
### Beam cursor
|
|
59
|
+
|
|
60
|
+
The block cursor becomes a thin blinking vertical bar (`▏`, ~2 Hz) that stays
|
|
61
|
+
solid while you type. On ghost rows the cursor rides the suggestion's first
|
|
62
|
+
character, zsh-autosuggestions style.
|
|
48
63
|
|
|
49
|
-
|
|
50
|
-
- Hooks pi-tui editor internals that are private in the type declarations; a major
|
|
51
|
-
pi update may require a touch-up. The extension fails visibly (a startup error
|
|
52
|
-
message), never corrupts the session.
|
|
64
|
+
## Attribution
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
This extension reimplements the interaction model of:
|
|
55
67
|
|
|
56
|
-
|
|
68
|
+
- [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions) — the
|
|
69
|
+
ghost-suggestion UX, history strategy, accept/partial-accept widgets
|
|
70
|
+
(`autosuggest-accept`, `autosuggest-accept-word`), and
|
|
71
|
+
[fish](https://fishshell.com/docs/current/interactive.html#autosuggestions),
|
|
72
|
+
which pioneered autosuggestions natively
|
|
73
|
+
- The zsh completion system's menu behavior for the dropdown fallback
|
|
74
|
+
|
|
75
|
+
Differences from the shell originals: suggestions are scoped to the current
|
|
76
|
+
session (pi has no persistent shell history file yet), and history matching is
|
|
77
|
+
line-scoped. Strategy order mirrors zsh-autosuggestions: history first, then
|
|
78
|
+
completions.
|
|
79
|
+
|
|
80
|
+
## Compatibility
|
|
57
81
|
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
from row padding so widths stay exact.
|
|
63
|
-
- The beam cursor swaps the base renderer's reverse-video block at render time; the
|
|
64
|
-
blink is a focused render loop that pauses (solid) briefly after each keystroke.
|
|
82
|
+
- Built and tested against **pi 0.85.0**
|
|
83
|
+
- Hooks pi-tui editor internals that are private in the type declarations; a
|
|
84
|
+
major pi update may require a touch-up. Failures are visible at startup, never
|
|
85
|
+
silent.
|
|
65
86
|
|
|
66
87
|
## License
|
|
67
88
|
|
|
@@ -40,7 +40,8 @@ const BLINK_INTERVAL_MS = 500;
|
|
|
40
40
|
/** Cursor stays solid for this long after each keystroke, then resumes blinking. */
|
|
41
41
|
const SOLID_AFTER_INPUT_MS = 450;
|
|
42
42
|
|
|
43
|
-
type
|
|
43
|
+
type GhostSource = "history" | "path";
|
|
44
|
+
type Ghost = { lineIndex: number; typed: string; suggestion: string; source: GhostSource };
|
|
44
45
|
|
|
45
46
|
class BashInlineEditor extends CustomEditor {
|
|
46
47
|
private realProvider: AutocompleteProvider | undefined;
|
|
@@ -51,6 +52,10 @@ class BashInlineEditor extends CustomEditor {
|
|
|
51
52
|
private cursorOn = true;
|
|
52
53
|
private lastInputAt = 0;
|
|
53
54
|
private blinkTimer?: ReturnType<typeof setInterval>;
|
|
55
|
+
/** Submitted prompts, oldest first — the zsh-autosuggestions history strategy. */
|
|
56
|
+
private promptHistory: string[] = [];
|
|
57
|
+
/** Set by Escape; keeps the ghost dismissed until the next text edit. */
|
|
58
|
+
private ghostSuppressed = false;
|
|
54
59
|
|
|
55
60
|
constructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager) {
|
|
56
61
|
super(tui, theme, keybindings);
|
|
@@ -73,6 +78,28 @@ class BashInlineEditor extends CustomEditor {
|
|
|
73
78
|
external = fn;
|
|
74
79
|
},
|
|
75
80
|
});
|
|
81
|
+
// Capture submitted prompts for the history suggestion strategy
|
|
82
|
+
// (zsh-autosuggestions records everything written to the shell line).
|
|
83
|
+
let externalSubmit: ((text: string) => void) | undefined;
|
|
84
|
+
Object.defineProperty(this, "onSubmit", {
|
|
85
|
+
configurable: true,
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get() {
|
|
88
|
+
if (!externalSubmit) return undefined;
|
|
89
|
+
return (text: string) => {
|
|
90
|
+
if (text.trim()) {
|
|
91
|
+
self.promptHistory.push(text);
|
|
92
|
+
if (self.promptHistory.length > 500) {
|
|
93
|
+
self.promptHistory.shift();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
externalSubmit!(text);
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
set(fn) {
|
|
100
|
+
externalSubmit = fn;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
// Pi installs the shared autocomplete provider here. Wrap it once with
|
|
@@ -90,20 +117,33 @@ class BashInlineEditor extends CustomEditor {
|
|
|
90
117
|
// Solid cursor while typing; blinking resumes after the idle window.
|
|
91
118
|
this.lastInputAt = Date.now();
|
|
92
119
|
this.cursorOn = true;
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
// Accept keys while a ghost suggestion is showing and the cursor sits
|
|
121
|
+
// at end of line (zsh-autosuggestions widget semantics):
|
|
122
|
+
// right → accept the whole suggestion
|
|
123
|
+
// alt+f → accept the next word (partial accept)
|
|
124
|
+
// ctrl+right → accept the next word (partial accept)
|
|
125
|
+
if (matchesKey(data, "escape")) {
|
|
126
|
+
this.ghostSuppressed = true;
|
|
127
|
+
} else {
|
|
128
|
+
this.ghostSuppressed = false;
|
|
129
|
+
}
|
|
130
|
+
if (this.activeGhost() && this.cursorAtLineEnd()) {
|
|
131
|
+
if (matchesKey(data, "right")) {
|
|
132
|
+
this.acceptGhost();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (matchesKey(data, "alt+f") || matchesKey(data, "ctrl+right")) {
|
|
136
|
+
this.acceptGhostWord();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
97
139
|
}
|
|
98
140
|
super.handleInput(data);
|
|
99
141
|
if (matchesKey(data, "escape")) {
|
|
100
142
|
this.ghost = null;
|
|
101
143
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.ghost = null;
|
|
106
|
-
}
|
|
144
|
+
// History suggestions work in every mode; bash mode adds the path
|
|
145
|
+
// strategy (updateGhost clears the ghost itself when nothing matches).
|
|
146
|
+
this.updateGhost();
|
|
107
147
|
}
|
|
108
148
|
|
|
109
149
|
handleTabCompletion(): void {
|
|
@@ -119,9 +159,7 @@ class BashInlineEditor extends CustomEditor {
|
|
|
119
159
|
// @ts-ignore — intentional runtime override of a private base method
|
|
120
160
|
setCursorCol(col: number): void {
|
|
121
161
|
Editor.prototype.setCursorCol.call(this, col);
|
|
122
|
-
|
|
123
|
-
this.updateGhost();
|
|
124
|
-
}
|
|
162
|
+
this.updateGhost();
|
|
125
163
|
}
|
|
126
164
|
|
|
127
165
|
render(width: number): string[] {
|
|
@@ -144,11 +182,12 @@ class BashInlineEditor extends CustomEditor {
|
|
|
144
182
|
if (ghost) {
|
|
145
183
|
// Base row layout: text + cursor cell + padding. Drop the cursor
|
|
146
184
|
// cell (frees 1 col) and render ghost chars into the padding.
|
|
185
|
+
const remainder = ghost.suggestion.slice(ghost.typed.length);
|
|
147
186
|
const pad = / *$/.exec(row.slice(match.index + match[0].length))?.[0].length ?? 0;
|
|
148
187
|
const avail = pad + 1;
|
|
149
188
|
let used = 0;
|
|
150
189
|
const cells: string[] = [];
|
|
151
|
-
for (const ch of [...
|
|
190
|
+
for (const ch of [...remainder]) {
|
|
152
191
|
const w = visibleWidth(ch);
|
|
153
192
|
if (used + w > avail) {
|
|
154
193
|
break;
|
|
@@ -203,12 +242,11 @@ class BashInlineEditor extends CustomEditor {
|
|
|
203
242
|
}
|
|
204
243
|
|
|
205
244
|
/**
|
|
206
|
-
* Wrap the stock provider with bash-mode behavior
|
|
207
|
-
* decision point for both the ghost and the dropdown:
|
|
245
|
+
* Wrap the stock provider with bash-mode behavior:
|
|
208
246
|
* - command position ("!cd", no space yet) → suggest all entries
|
|
209
|
-
* - multiple matches → normal suggestions (stock dropdown shows them)
|
|
210
|
-
* - exactly one match → divert to the inline ghost, close any popup
|
|
211
247
|
* - non-bash text → untouched stock behavior
|
|
248
|
+
* The ghost-vs-dropdown split (one match → ghost, many → dropdown) is
|
|
249
|
+
* decided in updateGhost(), which sees the final suggestion counts.
|
|
212
250
|
*/
|
|
213
251
|
private createBashProvider(current: AutocompleteProvider): AutocompleteProvider {
|
|
214
252
|
const self = this;
|
|
@@ -218,35 +256,17 @@ class BashInlineEditor extends CustomEditor {
|
|
|
218
256
|
return current.getSuggestions(lines, cursorLine, cursorCol, options);
|
|
219
257
|
}
|
|
220
258
|
const before = (lines[cursorLine] ?? "").slice(0, cursorCol);
|
|
221
|
-
const commandPos = self.commandPosition(before);
|
|
222
259
|
let queryLines = lines;
|
|
223
|
-
if (
|
|
260
|
+
if (self.commandPosition(before)) {
|
|
224
261
|
// Neutralize the command word so the provider completes the
|
|
225
262
|
// (empty) argument position: every entry matches.
|
|
226
263
|
queryLines = [...lines];
|
|
227
264
|
queryLines[cursorLine] = before.replace(/![^!\s]*$/, "! ");
|
|
228
265
|
}
|
|
229
|
-
|
|
266
|
+
return current.getSuggestions(queryLines, cursorLine, cursorCol, {
|
|
230
267
|
...options,
|
|
231
268
|
force: true,
|
|
232
269
|
});
|
|
233
|
-
const items = suggestions?.items ?? [];
|
|
234
|
-
if (items.length === 1) {
|
|
235
|
-
// Exactly one option: inline ghost instead of a popup. Returning
|
|
236
|
-
// null makes the stock machinery close/skip the dropdown.
|
|
237
|
-
const prefix = suggestions?.prefix ?? "";
|
|
238
|
-
const value = items[0]?.value ?? "";
|
|
239
|
-
const remainder = value.toLowerCase().startsWith(prefix.toLowerCase())
|
|
240
|
-
? value.slice(prefix.length)
|
|
241
|
-
: "";
|
|
242
|
-
self.ghost = remainder ? { lineIndex: cursorLine, prefix, remainder } : null;
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
if (items.length === 0) {
|
|
246
|
-
self.ghost = null;
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
return suggestions;
|
|
250
270
|
},
|
|
251
271
|
|
|
252
272
|
applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
|
|
@@ -268,22 +288,62 @@ class BashInlineEditor extends CustomEditor {
|
|
|
268
288
|
},
|
|
269
289
|
};
|
|
270
290
|
}
|
|
291
|
+
/** The ghost suggestion, only if it still matches the current editor state. */
|
|
271
292
|
private activeGhost(): Ghost | null {
|
|
272
293
|
const ghost = this.ghost;
|
|
273
|
-
if (!ghost || this.isShowingAutocomplete() || !this.
|
|
294
|
+
if (!ghost || this.isShowingAutocomplete() || !this.cursorAtLineEnd()) {
|
|
274
295
|
return null;
|
|
275
296
|
}
|
|
276
297
|
const st = (this as unknown as EditorInternals).state;
|
|
277
|
-
if (ghost.lineIndex !== st.cursorLine
|
|
298
|
+
if (ghost.lineIndex !== st.cursorLine) {
|
|
278
299
|
return null;
|
|
279
300
|
}
|
|
280
301
|
const line = st.lines[st.cursorLine] ?? "";
|
|
281
|
-
|
|
302
|
+
const before = line.slice(0, st.cursorCol);
|
|
303
|
+
if (before !== ghost.typed || ghost.suggestion.length <= ghost.typed.length) {
|
|
282
304
|
return null;
|
|
283
305
|
}
|
|
284
306
|
return ghost;
|
|
285
307
|
}
|
|
286
308
|
|
|
309
|
+
/** Most recent history entry extending the current line (history strategy). */
|
|
310
|
+
private historyGhost(): Ghost | null {
|
|
311
|
+
const st = (this as unknown as EditorInternals).state;
|
|
312
|
+
const line = st.lines[st.cursorLine] ?? "";
|
|
313
|
+
const typed = line.slice(0, st.cursorCol);
|
|
314
|
+
if (!typed.trim()) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
for (let i = this.promptHistory.length - 1; i >= 0; i--) {
|
|
318
|
+
const entry = this.promptHistory[i] ?? "";
|
|
319
|
+
// Suggest only the entry's first line: ghost text renders on a
|
|
320
|
+
// single editor row (full multi-line entries are inserted on accept).
|
|
321
|
+
const firstLine = entry.split("\n", 1)[0] ?? "";
|
|
322
|
+
if (firstLine.length > typed.length && firstLine.startsWith(typed)) {
|
|
323
|
+
return { lineIndex: st.cursorLine, typed, suggestion: firstLine, source: "history" };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Path ghost from provider suggestions (completion strategy, bash mode). */
|
|
330
|
+
private pathGhost(suggestions: AutocompleteSuggestions | null, lineIndex: number): Ghost | null {
|
|
331
|
+
const st = (this as unknown as EditorInternals).state;
|
|
332
|
+
const line = st.lines[lineIndex] ?? "";
|
|
333
|
+
const before = line.slice(0, st.cursorCol);
|
|
334
|
+
const token = suggestions?.prefix ?? "";
|
|
335
|
+
const value = suggestions?.items[0]?.value ?? "";
|
|
336
|
+
if (!value || !value.toLowerCase().startsWith(token.toLowerCase())) {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
const separator = this.commandPosition(before) ? " " : "";
|
|
340
|
+
const suggestion = before.slice(0, before.length - token.length) + separator + value;
|
|
341
|
+
if (suggestion.length <= before.length) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
return { lineIndex, typed: before, suggestion, source: "path" };
|
|
345
|
+
}
|
|
346
|
+
|
|
287
347
|
private acceptGhost(): void {
|
|
288
348
|
const ghost = this.activeGhost();
|
|
289
349
|
if (!ghost) {
|
|
@@ -292,36 +352,69 @@ class BashInlineEditor extends CustomEditor {
|
|
|
292
352
|
const st = (this as unknown as EditorInternals).state;
|
|
293
353
|
const line = st.lines[ghost.lineIndex] ?? "";
|
|
294
354
|
const col = st.cursorCol;
|
|
295
|
-
const completed = ghost.prefix + ghost.remainder;
|
|
296
|
-
const before = line.slice(0, col);
|
|
297
|
-
// Completing from the command position: the path becomes the first
|
|
298
|
-
// argument, so a leading space is part of the insertion.
|
|
299
|
-
const separator = this.commandPosition(before) ? " " : "";
|
|
300
355
|
(this as unknown as EditorInternals).pushUndoSnapshot();
|
|
301
|
-
st.lines[ghost.lineIndex] = line.slice(0, col - ghost.
|
|
356
|
+
st.lines[ghost.lineIndex] = line.slice(0, col - ghost.typed.length) + ghost.suggestion + line.slice(col);
|
|
302
357
|
this.ghost = null;
|
|
303
|
-
(this as unknown as EditorInternals).setCursorCol(
|
|
304
|
-
|
|
305
|
-
|
|
358
|
+
(this as unknown as EditorInternals).setCursorCol(col - ghost.typed.length + ghost.suggestion.length);
|
|
359
|
+
this.onChange?.(this.getText());
|
|
360
|
+
// Like zsh: after accepting, immediately suggest the next part.
|
|
361
|
+
this.updateGhost();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Partial accept (autosuggest-accept-word): take the next word of the suggestion. */
|
|
365
|
+
private acceptGhostWord(): void {
|
|
366
|
+
const ghost = this.activeGhost();
|
|
367
|
+
if (!ghost) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const remainder = ghost.suggestion.slice(ghost.typed.length);
|
|
371
|
+
const chunk = /^\S+\s*/.exec(remainder)?.[0];
|
|
372
|
+
if (!chunk) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const st = (this as unknown as EditorInternals).state;
|
|
376
|
+
const line = st.lines[ghost.lineIndex] ?? "";
|
|
377
|
+
const col = st.cursorCol;
|
|
378
|
+
(this as unknown as EditorInternals).pushUndoSnapshot();
|
|
379
|
+
st.lines[ghost.lineIndex] = line.slice(0, col) + chunk + line.slice(col);
|
|
380
|
+
this.ghost = { ...ghost, typed: ghost.typed + chunk };
|
|
381
|
+
(this as unknown as EditorInternals).setCursorCol(col + chunk.length);
|
|
306
382
|
this.onChange?.(this.getText());
|
|
307
|
-
// Like zsh: after completing into a directory, suggest its first entry.
|
|
308
383
|
this.updateGhost();
|
|
309
384
|
}
|
|
310
385
|
|
|
311
386
|
private updateGhost(): void {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
if (
|
|
387
|
+
const st = this as unknown as EditorInternals;
|
|
388
|
+
// Dismissed via Escape; stays dismissed until the next text edit.
|
|
389
|
+
if (this.ghostSuppressed) {
|
|
390
|
+
this.ghost = null;
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
// zsh-autosuggestions hides the suggestion once the cursor moves off
|
|
394
|
+
// the end of the buffer.
|
|
395
|
+
if (!this.cursorAtLineEnd()) {
|
|
315
396
|
this.ghost = null;
|
|
316
397
|
return;
|
|
317
398
|
}
|
|
318
|
-
const
|
|
319
|
-
|
|
399
|
+
const history = this.historyGhost();
|
|
400
|
+
if (!this.inBashMode()) {
|
|
401
|
+
// History strategy works everywhere, like zsh-autosuggestions.
|
|
402
|
+
this.ghost = history;
|
|
403
|
+
st.tui.requestRender();
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const provider = this.bashProvider;
|
|
407
|
+
if (!provider) {
|
|
408
|
+
this.ghost = history;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const token = ++this.ghostToken;
|
|
412
|
+
const lineIndex = st.state.cursorLine;
|
|
320
413
|
const controller = new AbortController();
|
|
321
414
|
this.ghostAbort?.abort();
|
|
322
415
|
this.ghostAbort = controller;
|
|
323
416
|
void provider
|
|
324
|
-
.getSuggestions(state.lines, lineIndex, state.cursorCol, {
|
|
417
|
+
.getSuggestions(st.state.lines, lineIndex, st.state.cursorCol, {
|
|
325
418
|
signal: controller.signal,
|
|
326
419
|
force: true,
|
|
327
420
|
})
|
|
@@ -329,13 +422,20 @@ class BashInlineEditor extends CustomEditor {
|
|
|
329
422
|
if (token !== this.ghostToken) {
|
|
330
423
|
return;
|
|
331
424
|
}
|
|
332
|
-
// The wrapper owns ghost state (single matches are diverted to
|
|
333
|
-
// the ghost there); this only triggers the dropdown for >1.
|
|
334
425
|
const items = suggestions?.items ?? [];
|
|
335
|
-
|
|
336
|
-
|
|
426
|
+
if (items.length > 1) {
|
|
427
|
+
// Multiple path options win: show the stock dropdown, no ghost.
|
|
337
428
|
this.ghost = null;
|
|
338
|
-
|
|
429
|
+
if (!this.isShowingAutocomplete()) {
|
|
430
|
+
st.requestAutocomplete({ force: true, explicitTab: false });
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
// Zero or one path option: prefer the history ghost, then the
|
|
434
|
+
// path ghost (zsh-autosuggestions strategy order: history first).
|
|
435
|
+
if (this.isShowingAutocomplete()) {
|
|
436
|
+
st.cancelAutocomplete();
|
|
437
|
+
}
|
|
438
|
+
this.ghost = history ?? this.pathGhost(suggestions, lineIndex);
|
|
339
439
|
}
|
|
340
440
|
st.tui.requestRender();
|
|
341
441
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-autosuggestions",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.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",
|
|
@@ -21,5 +21,11 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@earendil-works/pi-coding-agent": "*",
|
|
23
23
|
"@earendil-works/pi-tui": "*"
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/0xPlayerOne/pi-autosuggestions.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/0xPlayerOne/pi-autosuggestions#readme",
|
|
30
|
+
"bugs": "https://github.com/0xPlayerOne/pi-autosuggestions/issues"
|
|
25
31
|
}
|
|
@@ -2,15 +2,48 @@
|
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
|
|
3
3
|
"bump-minor-pre-major": true,
|
|
4
4
|
"changelog-sections": [
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
{
|
|
6
|
+
"type": "feat",
|
|
7
|
+
"section": "Features"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "fix",
|
|
11
|
+
"section": "Bug Fixes"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "perf",
|
|
15
|
+
"section": "Performance"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "revert",
|
|
19
|
+
"section": "Reverts"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "deps",
|
|
23
|
+
"section": "Dependencies"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "docs",
|
|
27
|
+
"section": "Documentation"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "test",
|
|
31
|
+
"section": "Tests"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "ci",
|
|
35
|
+
"section": "CI"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"type": "refactor",
|
|
39
|
+
"section": "Maintenance"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"type": "chore",
|
|
43
|
+
"section": "Maintenance"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"packages": {
|
|
47
|
+
".": {}
|
|
48
|
+
}
|
|
16
49
|
}
|