pi-autosuggestions 0.4.0 → 0.5.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +7 -0
- package/README.md +16 -2
- package/extensions/autosuggestions.ts +211 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{".":"0.
|
|
1
|
+
{".":"0.5.0"}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.4.0...pi-autosuggestions-v0.5.0) (2026-09-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* dynamic completions and expanded command tables ([4e99186](https://github.com/0xPlayerOne/pi-autosuggestions/commit/4e991868049694c1f973bc8ab2069af433c8bf4c))
|
|
9
|
+
|
|
3
10
|
## [0.4.0](https://github.com/0xPlayerOne/pi-autosuggestions/compare/pi-autosuggestions-v0.3.3...pi-autosuggestions-v0.4.0) (2026-09-04)
|
|
4
11
|
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -64,8 +64,22 @@ subcommand table instead of the filesystem:
|
|
|
64
64
|
| `!git zz` | no subcommand match → falls back to path completion |
|
|
65
65
|
|
|
66
66
|
Covered commands: `git`, `npm`, `pnpm`, `yarn`, `bun`, `docker`, `kubectl`,
|
|
67
|
-
`cargo`, `brew`, `gh
|
|
68
|
-
|
|
67
|
+
`cargo`, `brew`, `gh`, `go`, `uv`, `pip`, `poetry`, `terraform`, `helm`,
|
|
68
|
+
`wrangler`, `vercel`, `mise`, `asdf`, `systemctl`, `apt`, `pacman`.
|
|
69
|
+
Deeper arguments (flags, file args) still complete from history or the
|
|
70
|
+
filesystem.
|
|
71
|
+
|
|
72
|
+
### Dynamic completions (bash mode)
|
|
73
|
+
|
|
74
|
+
Some completions are **live** — the extension reads your project instead of a
|
|
75
|
+
static table (results cached for 10s):
|
|
76
|
+
|
|
77
|
+
| Input | Source |
|
|
78
|
+
|-------|--------|
|
|
79
|
+
| `!git checkout f` / `!git switch` / `!git merge` / `!git rebase` | branch names from `git branch` |
|
|
80
|
+
| `!npm run d` / `!pnpm run` / `!bun d` (implicit for yarn/pnpm/bun) | `scripts` from the nearest `package.json` |
|
|
81
|
+
| `!make d` | targets parsed from the nearest `Makefile` |
|
|
82
|
+
| `!docker compose u` | compose subcommands |
|
|
69
83
|
|
|
70
84
|
### Command completion (bash mode)
|
|
71
85
|
|
|
@@ -20,7 +20,8 @@ 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";
|
|
23
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
24
|
+
import { dirname } from "node:path";
|
|
24
25
|
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
25
26
|
|
|
26
27
|
interface EditorInternals {
|
|
@@ -34,6 +35,8 @@ interface EditorInternals {
|
|
|
34
35
|
|
|
35
36
|
const DIM = "\x1b[2m";
|
|
36
37
|
const RESET = "\x1b[0m";
|
|
38
|
+
/** Set at extension load; used for dynamic completion exec calls. */
|
|
39
|
+
let execApi: ExtensionAPI | undefined;
|
|
37
40
|
/** Beam cursor: thin vertical bar, bold so it stands out. One cell wide. */
|
|
38
41
|
const BEAM = "\x1b[1m▏\x1b[0m";
|
|
39
42
|
/** Matches the reverse-video block the base renderer emits for the cursor. */
|
|
@@ -103,8 +106,77 @@ const SUBCOMMANDS: Record<string, string[]> = {
|
|
|
103
106
|
"extension", "gist", "gpg-key", "issue", "label", "org", "pr", "project", "release",
|
|
104
107
|
"repo", "run", "search", "secret", "ssh-key", "status", "variable", "workflow",
|
|
105
108
|
],
|
|
109
|
+
go: [
|
|
110
|
+
"bug", "build", "clean", "doc", "env", "fix", "fmt", "generate", "get", "help",
|
|
111
|
+
"install", "list", "mod", "run", "test", "tool", "version", "vet", "work",
|
|
112
|
+
],
|
|
113
|
+
uv: [
|
|
114
|
+
"add", "build", "cache", "export", "help", "init", "lock", "pip", "publish", "python",
|
|
115
|
+
"remove", "run", "self", "sync", "tool", "tree", "venv", "version",
|
|
116
|
+
],
|
|
117
|
+
pip: [
|
|
118
|
+
"cache", "check", "config", "debug", "download", "freeze", "hash", "index", "inspect",
|
|
119
|
+
"install", "list", "show", "uninstall", "wheel",
|
|
120
|
+
],
|
|
121
|
+
poetry: [
|
|
122
|
+
"add", "build", "cache", "check", "config", "env", "export", "init", "install",
|
|
123
|
+
"list", "lock", "new", "publish", "remove", "run", "search", "self", "shell",
|
|
124
|
+
"show", "source", "update", "version",
|
|
125
|
+
],
|
|
126
|
+
terraform: [
|
|
127
|
+
"apply", "console", "destroy", "fmt", "get", "graph", "import", "init", "output",
|
|
128
|
+
"plan", "providers", "refresh", "show", "state", "taint", "test", "untaint",
|
|
129
|
+
"validate", "version", "workspace",
|
|
130
|
+
],
|
|
131
|
+
helm: [
|
|
132
|
+
"completion", "create", "dependency", "env", "get", "help", "history", "install",
|
|
133
|
+
"lint", "list", "package", "plugin", "pull", "push", "registry", "repo", "rollback",
|
|
134
|
+
"search", "show", "status", "template", "test", "uninstall", "upgrade", "verify",
|
|
135
|
+
],
|
|
136
|
+
wrangler: [
|
|
137
|
+
"ai", "d1", "delete", "deploy", "dev", "dispatch", "init", "kv", "login", "logout",
|
|
138
|
+
"logs", "r2", "rollback", "secret", "subdomain", "tail", "triggers", "types",
|
|
139
|
+
"versions", "whoami",
|
|
140
|
+
],
|
|
141
|
+
vercel: [
|
|
142
|
+
"alias", "build", "deploy", "dev", "dns", "domains", "env", "init", "inspect",
|
|
143
|
+
"link", "login", "logout", "logs", "ls", "projects", "pull", "remove", "switch",
|
|
144
|
+
"teams", "telemetry", "whoami",
|
|
145
|
+
],
|
|
146
|
+
mise: [
|
|
147
|
+
"activate", "current", "deactivate", "doctor", "exec", "global", "install", "link",
|
|
148
|
+
"list", "local", "ls", "outdated", "prune", "reshim", "run", "settings", "tasks",
|
|
149
|
+
"uninstall", "upgrade", "use", "which",
|
|
150
|
+
],
|
|
151
|
+
asdf: [
|
|
152
|
+
"current", "exec", "global", "info", "install", "latest", "list", "list-all",
|
|
153
|
+
"local", "plugin", "reshim", "shell", "uninstall", "update", "version", "where",
|
|
154
|
+
"which",
|
|
155
|
+
],
|
|
156
|
+
systemctl: [
|
|
157
|
+
"cat", "disable", "enable", "is-active", "is-enabled", "isolate", "kill", "list",
|
|
158
|
+
"list-dependencies", "list-timers", "list-units", "mask", "reload", "reload-or-restart",
|
|
159
|
+
"restart", "set-default", "show", "start", "status", "stop", "unmask",
|
|
160
|
+
],
|
|
161
|
+
apt: [
|
|
162
|
+
"autoclean", "autopurge", "autoremove", "build-dep", "cache", "check", "clean",
|
|
163
|
+
"download", "edit-sources", "full-upgrade", "help", "install", "list", "purge",
|
|
164
|
+
"reinstall", "remove", "satisfy", "search", "show", "source", "update", "upgrade",
|
|
165
|
+
],
|
|
166
|
+
pacman: [
|
|
167
|
+
"-Q", "-R", "-S", "-T", "-U", "-F", "clean", "deps", "files", "help", "query",
|
|
168
|
+
"remove", "sync", "test", "upgrade", "version",
|
|
169
|
+
],
|
|
106
170
|
};
|
|
107
171
|
|
|
172
|
+
const COMPOSE_SUBCOMMANDS = [
|
|
173
|
+
"build", "config", "create", "down", "events", "exec", "images", "kill", "logs", "ls",
|
|
174
|
+
"pause", "port", "ps", "pull", "push", "restart", "rm", "run", "start", "stop", "top",
|
|
175
|
+
"unpause", "up", "version", "wait", "watch",
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
// (SUBCOMMANDS gains more tables below — see SUBCOMMANDS_EXTRA merge point.)
|
|
179
|
+
|
|
108
180
|
const BLINK_INTERVAL_MS = 500;
|
|
109
181
|
/** Cursor stays solid for this long after each keystroke, then resumes blinking. */
|
|
110
182
|
const SOLID_AFTER_INPUT_MS = 450;
|
|
@@ -377,6 +449,117 @@ class BashInlineEditor extends CustomEditor {
|
|
|
377
449
|
.slice(0, 100);
|
|
378
450
|
}
|
|
379
451
|
|
|
452
|
+
private dynCache = new Map<string, { at: number; data: string[] }>();
|
|
453
|
+
|
|
454
|
+
private cached(key: string, ttl: number, fetch: () => Promise<string[]>): Promise<string[]> {
|
|
455
|
+
const hit = this.dynCache.get(key);
|
|
456
|
+
if (hit && Date.now() - hit.at < ttl) {
|
|
457
|
+
return hit.data;
|
|
458
|
+
}
|
|
459
|
+
return fetch()
|
|
460
|
+
.then((data) => {
|
|
461
|
+
this.dynCache.set(key, { at: Date.now(), data });
|
|
462
|
+
return data;
|
|
463
|
+
})
|
|
464
|
+
.catch(() => []);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private async runCommand(cmd: string, args: string[], timeout = 4000): Promise<string[]> {
|
|
468
|
+
if (!execApi) {
|
|
469
|
+
return [];
|
|
470
|
+
}
|
|
471
|
+
const result = await execApi.exec(cmd, args, { cwd: process.cwd(), timeout });
|
|
472
|
+
if (result.code !== 0) {
|
|
473
|
+
return [];
|
|
474
|
+
}
|
|
475
|
+
return result.stdout.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
private findUp(name: string): string | null {
|
|
479
|
+
let dir = process.cwd();
|
|
480
|
+
for (;;) {
|
|
481
|
+
const candidate = `${dir}/${name}`;
|
|
482
|
+
if (existsSync(candidate)) {
|
|
483
|
+
return candidate;
|
|
484
|
+
}
|
|
485
|
+
const parent = dirname(dir);
|
|
486
|
+
if (parent === dir) {
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
dir = parent;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
private gitBranches(): Promise<string[]> {
|
|
494
|
+
return this.cached("git:branches", 10_000, async () =>
|
|
495
|
+
(await this.runCommand("git", ["branch", "--list"]))
|
|
496
|
+
.map((l) => l.replace(/^\*?\s*/, ""))
|
|
497
|
+
.filter((l) => l && !l.includes(" ")));
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private npmScripts(): Promise<string[]> {
|
|
501
|
+
return this.cached("npm:scripts", 10_000, async () => {
|
|
502
|
+
const pkg = this.findUp("package.json");
|
|
503
|
+
if (!pkg) {
|
|
504
|
+
return [];
|
|
505
|
+
}
|
|
506
|
+
const parsed: { scripts?: Record<string, string> } = JSON.parse(readFileSync(pkg, "utf8"));
|
|
507
|
+
return Object.keys(parsed.scripts ?? {});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
private makeTargets(): Promise<string[]> {
|
|
512
|
+
return this.cached("make:targets", 10_000, async () => {
|
|
513
|
+
const file = this.findUp("Makefile") ?? this.findUp("makefile");
|
|
514
|
+
if (!file) {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
const targets = new Set<string>();
|
|
518
|
+
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
519
|
+
const m = /^([a-zA-Z0-9][^\s=$#]*(?:\s+[a-zA-Z0-9][^\s=$#]*)?):(?!=)/.exec(line);
|
|
520
|
+
if (m) {
|
|
521
|
+
for (const t of m[1]!.trim().split(/\s+/)) {
|
|
522
|
+
targets.add(t);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return [...targets];
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** Live sources: git branches, package scripts, make targets, compose. */
|
|
531
|
+
private async dynamicCompletions(
|
|
532
|
+
cmd: string,
|
|
533
|
+
args: string[],
|
|
534
|
+
token: string,
|
|
535
|
+
): Promise<{ items: string[]; description: string } | null> {
|
|
536
|
+
let items: string[] | null = null;
|
|
537
|
+
let description = "";
|
|
538
|
+
if (cmd === "git" && args.length === 1 && ["checkout", "switch", "merge", "rebase"].includes(args[0]!)) {
|
|
539
|
+
items = (await this.gitBranches()).filter((b) => b.startsWith(token));
|
|
540
|
+
description = "branch";
|
|
541
|
+
} else if (cmd === "git" && args[0] === "branch" && args.length === 1) {
|
|
542
|
+
items = (await this.gitBranches()).filter((b) => b.startsWith(token));
|
|
543
|
+
description = "branch";
|
|
544
|
+
} else if (
|
|
545
|
+
["npm", "pnpm", "yarn", "bun"].includes(cmd) &&
|
|
546
|
+
((args[0] === "run" && args.length === 1) || (cmd !== "npm" && args.length === 0))
|
|
547
|
+
) {
|
|
548
|
+
items = (await this.npmScripts()).filter((sc) => sc.startsWith(token));
|
|
549
|
+
description = "script";
|
|
550
|
+
} else if ((cmd === "make" || cmd === "gmake") && args.length === 0) {
|
|
551
|
+
items = (await this.makeTargets()).filter((t) => t.startsWith(token));
|
|
552
|
+
description = "make target";
|
|
553
|
+
} else if (cmd === "docker" && args[0] === "compose" && args.length === 1) {
|
|
554
|
+
items = COMPOSE_SUBCOMMANDS.filter((sc) => sc.startsWith(token));
|
|
555
|
+
description = "compose subcommand";
|
|
556
|
+
}
|
|
557
|
+
if (!items || items.length === 0) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
return { items: items.slice(0, 50), description };
|
|
561
|
+
}
|
|
562
|
+
|
|
380
563
|
private createBashProvider(current: AutocompleteProvider): AutocompleteProvider {
|
|
381
564
|
const self = this;
|
|
382
565
|
return {
|
|
@@ -392,21 +575,32 @@ class BashInlineEditor extends CustomEditor {
|
|
|
392
575
|
const cmd = arg[1]!;
|
|
393
576
|
const token = arg[2] ?? "";
|
|
394
577
|
const subs = SUBCOMMANDS[cmd];
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
578
|
+
const staticMatches = (subs ?? []).filter((sc) => sc.startsWith(token)).slice(0, 50);
|
|
579
|
+
const dynamic = await self.dynamicCompletions(cmd, [], token);
|
|
580
|
+
const dynamicItems = dynamic?.items.filter((d) => !staticMatches.includes(d)) ?? [];
|
|
581
|
+
if (staticMatches.length > 0 || dynamicItems.length > 0) {
|
|
582
|
+
return {
|
|
583
|
+
items: [
|
|
584
|
+
...staticMatches.map((sc) => ({ value: sc, label: sc, description: `${cmd} subcommand` })),
|
|
585
|
+
...dynamicItems.map((sc) => ({ value: sc, label: sc, description: dynamic!.description })),
|
|
586
|
+
],
|
|
587
|
+
prefix: token,
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
// Nothing matched: fall through to paths.
|
|
591
|
+
}
|
|
592
|
+
// Second-argument dynamic completion (branches, scripts, compose…).
|
|
593
|
+
const words = before.replace(/^[\t ]*!+/, "").split(/[ \t]+/);
|
|
594
|
+
if (words.length >= 2) {
|
|
595
|
+
const cmd = words[0]!;
|
|
596
|
+
const token = words[words.length - 1]!;
|
|
597
|
+
const args = words.slice(1, -1).filter(Boolean);
|
|
598
|
+
const dyn = await self.dynamicCompletions(cmd, args, token);
|
|
599
|
+
if (dyn && dyn.items.length > 0) {
|
|
600
|
+
return {
|
|
601
|
+
items: dyn.items.map((sc) => ({ value: sc, label: sc, description: dyn.description })),
|
|
602
|
+
prefix: token,
|
|
603
|
+
};
|
|
410
604
|
}
|
|
411
605
|
}
|
|
412
606
|
let queryLines = lines;
|
|
@@ -626,6 +820,7 @@ class BashInlineEditor extends CustomEditor {
|
|
|
626
820
|
}
|
|
627
821
|
|
|
628
822
|
export default function (pi: ExtensionAPI): void {
|
|
823
|
+
execApi = pi;
|
|
629
824
|
pi.on("session_start", (_event, ctx) => {
|
|
630
825
|
ctx.ui.setEditorComponent((tui, theme, keybindings) => new BashInlineEditor(tui, theme, keybindings));
|
|
631
826
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-autosuggestions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|