pi-autosuggestions 0.5.0 → 0.6.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +14 -0
- package/README.md +23 -5
- package/extensions/autosuggestions.ts +187 -5
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{".":"0.
|
|
1
|
+
{".":"0.6.1"}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.1](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.6.0...pi-autosuggestions-v0.6.1) (2026-09-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Documentation
|
|
7
|
+
|
|
8
|
+
* correct cursor description, remove unused theme helpers ([681f22d](https://github.com/0xPlayerOne/pi-autosuggestions/commit/681f22d629b6d5251e8c4543a288814855e633c5))
|
|
9
|
+
|
|
10
|
+
## [0.6.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.5.0...pi-autosuggestions-v0.6.0) (2026-09-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* cross-session history, candidate cycling, theme-aware cursor, new dynamic sources ([71fe236](https://github.com/0xPlayerOne/pi-autosuggestions/commit/71fe236ac272d54432da96aa35e53a919102f657))
|
|
16
|
+
|
|
3
17
|
## [0.5.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.4.0...pi-autosuggestions-v0.5.0) (2026-09-04)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -23,6 +23,12 @@ pi install git:github.com/0xPlayerOne/pi-autosuggestions@pi-autosuggestions-v0.2
|
|
|
23
23
|
pi install npm:pi-autosuggestions
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
`/autosuggest` — toggle cross-session history for ghost suggestions (stored
|
|
29
|
+
in `~/.pi/agent/pi-autosuggestions.json`; applies from the next session).
|
|
30
|
+
Default: off (history is session-scoped).
|
|
31
|
+
|
|
26
32
|
## Scope
|
|
27
33
|
|
|
28
34
|
| Layer | Where it works |
|
|
@@ -32,11 +38,20 @@ pi install npm:pi-autosuggestions
|
|
|
32
38
|
| Command-name completion | **Bash mode only**, first word after `!` |
|
|
33
39
|
| Beam cursor | **Everywhere** |
|
|
34
40
|
|
|
35
|
-
History is **session-scoped**: the ghost
|
|
36
|
-
submitted
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
History is **session-scoped by default**: the ghost suggests prompts you
|
|
42
|
+
submitted in the current session. Opt into **cross-session history** with
|
|
43
|
+
`/autosuggest` — the extension then seeds suggestions from your previous
|
|
44
|
+
pi sessions in the same working directory (read from pi's own session files;
|
|
45
|
+
nothing leaves your machine). If you mostly run `!` commands, the ghost will
|
|
46
|
+
mostly appear in bash mode — it isn't restricted there, it just has nothing
|
|
47
|
+
to suggest elsewhere.
|
|
48
|
+
|
|
49
|
+
**Candidate cycling**: with multiple history matches, `Alt+Down` / `Alt+Up`
|
|
50
|
+
rotate the ghost through the alternatives (most recent first).
|
|
51
|
+
|
|
52
|
+
The cursor is the **terminal's native one** (see the cursor section below):
|
|
53
|
+
white in terminals honoring OSC 12, theme-colored elsewhere — notably Warp
|
|
54
|
+
paints it blue and ignores cursor-color overrides (warpdotdev/Warp#3210).
|
|
40
55
|
|
|
41
56
|
## Features
|
|
42
57
|
|
|
@@ -80,6 +95,9 @@ static table (results cached for 10s):
|
|
|
80
95
|
| `!npm run d` / `!pnpm run` / `!bun d` (implicit for yarn/pnpm/bun) | `scripts` from the nearest `package.json` |
|
|
81
96
|
| `!make d` | targets parsed from the nearest `Makefile` |
|
|
82
97
|
| `!docker compose u` | compose subcommands |
|
|
98
|
+
| `!docker start n` / `logs` / `exec` … | running container names |
|
|
99
|
+
| `!kubectl get p` | resource types |
|
|
100
|
+
| `!ssh ` / `!scp ` | hosts from `~/.ssh/config` |
|
|
83
101
|
|
|
84
102
|
### Command completion (bash mode)
|
|
85
103
|
|
|
@@ -20,8 +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 { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
23
|
+
import { existsSync, readFileSync, realpathSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
24
24
|
import { dirname } from "node:path";
|
|
25
|
+
import { homedir } from "node:os";
|
|
25
26
|
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
26
27
|
|
|
27
28
|
interface EditorInternals {
|
|
@@ -37,6 +38,29 @@ const DIM = "\x1b[2m";
|
|
|
37
38
|
const RESET = "\x1b[0m";
|
|
38
39
|
/** Set at extension load; used for dynamic completion exec calls. */
|
|
39
40
|
let execApi: ExtensionAPI | undefined;
|
|
41
|
+
/** Active pi theme (set at session start) for theme-aware cursor colors. */
|
|
42
|
+
/** Persisted extension settings (~/.pi/agent/pi-autosuggestions.json). */
|
|
43
|
+
interface AutosuggestConfig {
|
|
44
|
+
crossSessionHistory?: boolean;
|
|
45
|
+
}
|
|
46
|
+
let config: AutosuggestConfig = {};
|
|
47
|
+
const configPath = `${homedir()}/.pi/agent/pi-autosuggestions.json`;
|
|
48
|
+
|
|
49
|
+
function loadConfig(): void {
|
|
50
|
+
try {
|
|
51
|
+
config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
52
|
+
} catch {
|
|
53
|
+
config = {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function saveConfig(): void {
|
|
58
|
+
try {
|
|
59
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
60
|
+
} catch {
|
|
61
|
+
// read-only home — settings stay in-memory
|
|
62
|
+
}
|
|
63
|
+
}
|
|
40
64
|
/** Beam cursor: thin vertical bar, bold so it stands out. One cell wide. */
|
|
41
65
|
const BEAM = "\x1b[1m▏\x1b[0m";
|
|
42
66
|
/** Matches the reverse-video block the base renderer emits for the cursor. */
|
|
@@ -177,6 +201,18 @@ const COMPOSE_SUBCOMMANDS = [
|
|
|
177
201
|
|
|
178
202
|
// (SUBCOMMANDS gains more tables below — see SUBCOMMANDS_EXTRA merge point.)
|
|
179
203
|
|
|
204
|
+
const DOCKER_CONTAINER_VERBS = [
|
|
205
|
+
"start", "stop", "restart", "kill", "rm", "logs", "exec", "inspect", "stats",
|
|
206
|
+
"top", "pause", "unpause", "commit",
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
const KUBECTL_RESOURCES = [
|
|
210
|
+
"pods", "po", "deployments", "deploy", "services", "svc", "ingresses", "ing",
|
|
211
|
+
"nodes", "no", "namespaces", "ns", "configmaps", "cm", "secrets", "persistentvolumes",
|
|
212
|
+
"pv", "persistentvolumeclaims", "pvc", "events", "ev", "replicasets", "rs",
|
|
213
|
+
"statefulsets", "sts", "daemonsets", "ds", "jobs", "cronjobs", "hpa", "endpoints", "ep",
|
|
214
|
+
];
|
|
215
|
+
|
|
180
216
|
const BLINK_INTERVAL_MS = 500;
|
|
181
217
|
/** Cursor stays solid for this long after each keystroke, then resumes blinking. */
|
|
182
218
|
const SOLID_AFTER_INPUT_MS = 450;
|
|
@@ -192,6 +228,10 @@ class BashInlineEditor extends CustomEditor {
|
|
|
192
228
|
private ghostAbort?: AbortController;
|
|
193
229
|
/** Submitted prompts, oldest first — the zsh-autosuggestions history strategy. */
|
|
194
230
|
private promptHistory: string[] = [];
|
|
231
|
+
private historyLoaded = false;
|
|
232
|
+
/** History candidates for the current ghost (most recent first). */
|
|
233
|
+
private ghostCandidates: string[] = [];
|
|
234
|
+
private ghostCandidateIndex = 0;
|
|
195
235
|
/** Set by Escape; keeps the ghost dismissed until the next text edit. */
|
|
196
236
|
private ghostSuppressed = false;
|
|
197
237
|
|
|
@@ -279,6 +319,14 @@ class BashInlineEditor extends CustomEditor {
|
|
|
279
319
|
this.acceptGhostWord();
|
|
280
320
|
return;
|
|
281
321
|
}
|
|
322
|
+
if (matchesKey(data, "alt+down")) {
|
|
323
|
+
this.cycleGhostCandidate(1);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (matchesKey(data, "alt+up")) {
|
|
327
|
+
this.cycleGhostCandidate(-1);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
282
330
|
}
|
|
283
331
|
super.handleInput(data);
|
|
284
332
|
if (matchesKey(data, "escape")) {
|
|
@@ -386,7 +434,7 @@ class BashInlineEditor extends CustomEditor {
|
|
|
386
434
|
return st.cursorCol === (st.lines[st.cursorLine] ?? "").length;
|
|
387
435
|
}
|
|
388
436
|
|
|
389
|
-
|
|
437
|
+
/** Suppress the dropdown in bash mode unless the popup is already open. */
|
|
390
438
|
|
|
391
439
|
/**
|
|
392
440
|
* True while the command word after "!" is still being typed (no space
|
|
@@ -528,6 +576,32 @@ class BashInlineEditor extends CustomEditor {
|
|
|
528
576
|
}
|
|
529
577
|
|
|
530
578
|
/** Live sources: git branches, package scripts, make targets, compose. */
|
|
579
|
+
private sshHosts(): Promise<string[]> {
|
|
580
|
+
return this.cached("ssh:hosts", 60_000, async () => {
|
|
581
|
+
const cfg = `${homedir()}/.ssh/config`;
|
|
582
|
+
if (!existsSync(cfg)) {
|
|
583
|
+
return [];
|
|
584
|
+
}
|
|
585
|
+
const hosts: string[] = [];
|
|
586
|
+
for (const lineText of readFileSync(cfg, "utf8").split("\n")) {
|
|
587
|
+
const m = /^\s*[Hh]ost\s+(.+)$/.exec(lineText);
|
|
588
|
+
if (m) {
|
|
589
|
+
for (const host of m[1]!.trim().split(/\s+/)) {
|
|
590
|
+
if (!host.includes("*") && !hosts.includes(host)) {
|
|
591
|
+
hosts.push(host);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return hosts;
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
private dockerContainers(): Promise<string[]> {
|
|
601
|
+
return this.cached("docker:containers", 10_000, async () =>
|
|
602
|
+
await this.runCommand("docker", ["ps", "--format", "{{.Names}}"]));
|
|
603
|
+
}
|
|
604
|
+
|
|
531
605
|
private async dynamicCompletions(
|
|
532
606
|
cmd: string,
|
|
533
607
|
args: string[],
|
|
@@ -553,6 +627,15 @@ class BashInlineEditor extends CustomEditor {
|
|
|
553
627
|
} else if (cmd === "docker" && args[0] === "compose" && args.length === 1) {
|
|
554
628
|
items = COMPOSE_SUBCOMMANDS.filter((sc) => sc.startsWith(token));
|
|
555
629
|
description = "compose subcommand";
|
|
630
|
+
} else if (cmd === "docker" && args.length === 1 && DOCKER_CONTAINER_VERBS.includes(args[0]!)) {
|
|
631
|
+
items = (await this.dockerContainers()).filter((c) => c.startsWith(token));
|
|
632
|
+
description = "container";
|
|
633
|
+
} else if (cmd === "kubectl" && args[0] === "get" && args.length === 1) {
|
|
634
|
+
items = KUBECTL_RESOURCES.filter((r) => r.startsWith(token));
|
|
635
|
+
description = "resource";
|
|
636
|
+
} else if (["ssh", "scp"].includes(cmd) && args.length === 0) {
|
|
637
|
+
items = (await this.sshHosts()).filter((h) => h.startsWith(token));
|
|
638
|
+
description = "host";
|
|
556
639
|
}
|
|
557
640
|
if (!items || items.length === 0) {
|
|
558
641
|
return null;
|
|
@@ -683,22 +766,103 @@ class BashInlineEditor extends CustomEditor {
|
|
|
683
766
|
|
|
684
767
|
/** Most recent history entry extending the current line (history strategy). */
|
|
685
768
|
private historyGhost(): Ghost | null {
|
|
769
|
+
this.loadCrossSessionHistory();
|
|
686
770
|
const st = (this as unknown as EditorInternals).state;
|
|
687
771
|
const line = st.lines[st.cursorLine] ?? "";
|
|
688
772
|
const typed = line.slice(0, st.cursorCol);
|
|
689
773
|
if (!typed.trim()) {
|
|
690
774
|
return null;
|
|
691
775
|
}
|
|
776
|
+
const matches: string[] = [];
|
|
692
777
|
for (let i = this.promptHistory.length - 1; i >= 0; i--) {
|
|
693
778
|
const entry = this.promptHistory[i] ?? "";
|
|
694
779
|
// Suggest only the entry's first line: ghost text renders on a
|
|
695
780
|
// single editor row (full multi-line entries are inserted on accept).
|
|
696
781
|
const firstLine = entry.split("\n", 1)[0] ?? "";
|
|
697
|
-
if (firstLine.length > typed.length && firstLine.startsWith(typed)) {
|
|
698
|
-
|
|
782
|
+
if (firstLine.length > typed.length && firstLine.startsWith(typed) && !matches.includes(firstLine)) {
|
|
783
|
+
matches.push(firstLine);
|
|
699
784
|
}
|
|
700
785
|
}
|
|
701
|
-
|
|
786
|
+
this.ghostCandidates = matches;
|
|
787
|
+
this.ghostCandidateIndex = 0;
|
|
788
|
+
const first = matches[0];
|
|
789
|
+
return first ? { lineIndex: st.cursorLine, typed, suggestion: first, source: "history" } : null;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Seed the history strategy with prompts from previous sessions in this
|
|
794
|
+
* working directory. Opt-in via /autosuggest; runs once per editor.
|
|
795
|
+
*/
|
|
796
|
+
private loadCrossSessionHistory(): void {
|
|
797
|
+
if (this.historyLoaded) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
this.historyLoaded = true;
|
|
801
|
+
if (!config.crossSessionHistory) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
try {
|
|
805
|
+
const sessionsDir = `${homedir()}/.pi/agent/sessions`;
|
|
806
|
+
const encoded = (p: string) => `--${p.split("/").filter(Boolean).join("-")}--`;
|
|
807
|
+
let dir: string | undefined;
|
|
808
|
+
for (const candidate of [process.cwd(), realpathSync(process.cwd())]) {
|
|
809
|
+
const path13 = `${sessionsDir}/${encoded(candidate)}`;
|
|
810
|
+
if (existsSync(path13)) {
|
|
811
|
+
dir = path13;
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (!dir) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
const files = readdirSync(dir)
|
|
819
|
+
.filter((f) => f.endsWith(".jsonl"))
|
|
820
|
+
.sort()
|
|
821
|
+
.slice(-5);
|
|
822
|
+
const prompts: string[] = [];
|
|
823
|
+
for (const file of files) {
|
|
824
|
+
for (const lineText of readFileSync(`${dir}/${file}`, "utf8").split("\n")) {
|
|
825
|
+
try {
|
|
826
|
+
const entry = JSON.parse(lineText) as {
|
|
827
|
+
type?: string;
|
|
828
|
+
message?: { role?: string; content?: string | { type?: string; text?: string }[] };
|
|
829
|
+
};
|
|
830
|
+
if (entry.type !== "message" || entry.message?.role !== "user") {
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
const content = entry.message.content;
|
|
834
|
+
const text =
|
|
835
|
+
typeof content === "string"
|
|
836
|
+
? content
|
|
837
|
+
: (content ?? [])
|
|
838
|
+
.filter((b) => b.type === "text")
|
|
839
|
+
.map((b) => b.text ?? "")
|
|
840
|
+
.join("");
|
|
841
|
+
const firstLine = text.split("\n", 1)[0] ?? "";
|
|
842
|
+
if (firstLine.trim()) {
|
|
843
|
+
prompts.push(firstLine);
|
|
844
|
+
}
|
|
845
|
+
} catch {
|
|
846
|
+
// partial line or unsupported entry
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
// Cross-session entries come before anything typed this session.
|
|
851
|
+
this.promptHistory = [...prompts.reverse(), ...this.promptHistory];
|
|
852
|
+
} catch (e) {
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/** Rotate to the previous/next history candidate (Alt+Up / Alt+Down). */
|
|
857
|
+
private cycleGhostCandidate(dir: 1 | -1): void {
|
|
858
|
+
const ghost = this.activeGhost();
|
|
859
|
+
if (!ghost || ghost.source !== "history" || this.ghostCandidates.length < 2) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
this.ghostCandidateIndex =
|
|
863
|
+
(this.ghostCandidateIndex + dir + this.ghostCandidates.length) % this.ghostCandidates.length;
|
|
864
|
+
this.ghost = { ...ghost, suggestion: this.ghostCandidates[this.ghostCandidateIndex]! };
|
|
865
|
+
(this as unknown as EditorInternals).tui.requestRender();
|
|
702
866
|
}
|
|
703
867
|
|
|
704
868
|
/** Path ghost from provider suggestions (completion strategy, bash mode). */
|
|
@@ -821,9 +985,27 @@ class BashInlineEditor extends CustomEditor {
|
|
|
821
985
|
|
|
822
986
|
export default function (pi: ExtensionAPI): void {
|
|
823
987
|
execApi = pi;
|
|
988
|
+
loadConfig();
|
|
824
989
|
pi.on("session_start", (_event, ctx) => {
|
|
825
990
|
ctx.ui.setEditorComponent((tui, theme, keybindings) => new BashInlineEditor(tui, theme, keybindings));
|
|
826
991
|
});
|
|
992
|
+
pi.registerCommand("autosuggest", {
|
|
993
|
+
description: "Toggle cross-session history for ghost suggestions",
|
|
994
|
+
handler: async (args, ctx) => {
|
|
995
|
+
const arg = (args ?? "").trim().toLowerCase();
|
|
996
|
+
if (arg === "on" || arg === "off") {
|
|
997
|
+
config.crossSessionHistory = arg === "on";
|
|
998
|
+
} else {
|
|
999
|
+
config.crossSessionHistory = !config.crossSessionHistory;
|
|
1000
|
+
}
|
|
1001
|
+
saveConfig();
|
|
1002
|
+
const state = config.crossSessionHistory ? "ON" : "OFF";
|
|
1003
|
+
ctx.ui.notify(
|
|
1004
|
+
`pi-autosuggestions: cross-session history ${state}${config.crossSessionHistory ? " (applies next session)" : ""}`,
|
|
1005
|
+
"info",
|
|
1006
|
+
);
|
|
1007
|
+
},
|
|
1008
|
+
});
|
|
827
1009
|
// Restore the terminal's own cursor color and shape when pi exits so the
|
|
828
1010
|
// shell afterwards isn't left with our forced white bar.
|
|
829
1011
|
process.on("exit", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-autosuggestions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|