@kliebhan/pi-prompt-autocomplete 0.2.5 → 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/CHANGELOG.md +49 -0
- package/README.md +75 -16
- package/core.ts +1102 -12
- package/index.ts +1855 -456
- package/media/prompt-autocomplete-demo.mp4 +0 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this package are documented here. This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2026-11-12
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Configurable keys: `/prompt-autocomplete set key <action> <key...|default|none>` changes the keys of `accept-word`, `accept-line`, `cycle-next`, and `cycle-prev`, applies them at once, and saves them in the settings file. Keys follow Pi's key syntax and are space-separated. Keys that could never reach an action are rejected: Tab, Escape, Enter, and Backspace with their legacy aliases such as `ctrl+i`, keys Pi's editor handles itself such as `shift+enter` or `ctrl+j`, keys that type text, and keys Pi never recognizes (Escape or F1–F12 with a modifier, Clear with anything but Shift or Ctrl alone). So are keys another action already has; a key that Pi's keymap binds is accepted, with a warning once the editor is active, because Pi keeps it. `Tab` and `Escape` stay fixed.
|
|
10
|
+
- `/prompt-autocomplete keys` shows every action's keys, whether they are the default or saved, saved keys that are ignored, and, once the editor is active, keys Pi's keymap also binds.
|
|
11
|
+
- `accept-line` accepts a suggestion up to and including its first line break; a one-line suggestion is accepted whole. It has no default key.
|
|
12
|
+
- `--prompt-autocomplete-next-prompt`: in RPC mode, after each settled turn, one request predicts the next prompt and hands it to the host with `set_editor_text`, for hosts such as a T3 Code build that shows it as the suggested next prompt. A new turn or session aborts it, and a late result for a busy agent or another branch is dropped; model, budget, and stats apply as in the editor.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Every release is now also verified against Pi `1.5.2`, next to `0.80.6`, `0.83.0`, and `1.2.0`.
|
|
17
|
+
- `Escape` now dismisses a suggestion for as long as you keep typing the same draft, instead of only until the next keystroke. Previously the next character brought the dismissed suggestion back, from the prefix cache or through a new provider request. The dismissal ends for good when the draft no longer extends the dismissed text (for example after `Backspace`, submitting, clearing, or recalling another prompt), when the conversation, the autocomplete model, `max-chars`, or `max-alternatives` changes, or when you press the one-shot key (`cycle-next`, `Ctrl+.` by default), accept, or cycle. An `Escape` on an empty-draft suggestion lasts only while the draft stays empty.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- The word-accept and cycle keys (`Ctrl+Space`, `Ctrl+Tab`, `Ctrl+.`, `Alt+]`, `Ctrl+,`, `Alt+[`) no longer take input that Pi would use. A Pi action you bind to one of them in `keybindings.json`, including history and interrupt, and another extension's shortcut on the same key now get the key as they would without Prompt Autocomplete; previously visible ghost text took it. A pending character jump (`Ctrl+]`) is now cancelled by such a key, as in Pi, before the key's action runs. The check uses Pi's current keymap, so remaps loaded by `/reload` apply at once. Once the editor is active, `/prompt-autocomplete keys` and `status` (`keys-used-by-pi`) list keys your Pi keymap binds; other extensions' shortcuts cannot be listed. Pi's default keymap uses none of them, so nothing changes without remaps.
|
|
22
|
+
- Saving a setting no longer discards decisions another Pi process saved while this one was running, and no longer drops fields a newer version wrote: each save re-reads the settings file and changes only its own decision. A read error other than a missing file aborts the save instead of replacing the file. Two saves that overlap, each between its read and its write, can still lose one decision; there is no lock.
|
|
23
|
+
|
|
24
|
+
### Security
|
|
25
|
+
|
|
26
|
+
- The settings file is replaced atomically through a new temporary file with an unpredictable name that is created exclusively, so a link planted in a shared settings directory is never written through. On POSIX systems the file is now readable by its owner only (`0600`), also when an older version created it.
|
|
27
|
+
|
|
28
|
+
### Upgrading
|
|
29
|
+
|
|
30
|
+
- Version 0.3.0 and earlier drop the saved `keys`, like any other field they do not know, the next time they save a setting; the actions then return to their default keys.
|
|
31
|
+
|
|
32
|
+
## [0.3.0] - 2026-10-13
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- Supports Pi 1.x. Ghost text recognizes Pi 1.x fake-cursor markers next to the inverse-video cursor of Pi 0.x and the `\x1b[27m` variant of forked hosts, so suggestions keep rendering on all three. The compatibility matrix now covers Pi `0.80.6`, `0.83.0`, and `1.2.0`; the supported baseline stays `0.80.6`.
|
|
37
|
+
- On Pi 1.x, autocomplete requests route through the session's model registry instead of the global `pi-ai` compat functions. Those only serve Pi's built-in APIs on Pi 1.x, so a model from a provider that another extension registers with its own streaming implementation failed with "No API provider registered"; the registry serves those providers and resolves each provider's stored credential itself. No pre-resolved key is passed, because an explicit key would make Pi skip the stored credential and with it an OAuth-derived endpoint such as GitHub Copilot Enterprise's; header-only and ambient credentials are accepted on this path. Hosts without a registry entry point keep the compat functions, which still require an API key.
|
|
38
|
+
- On Pi 1.x, autocomplete context follows the model-visible session projection: messages that a `context_edit` omitted or replaced, for example to redact them, are omitted or replaced in autocomplete requests too, so autocomplete never sends what the model itself no longer sees. A failing projection sends no conversation context instead of the raw history. Older hosts, which have no context edits, keep using the raw branch. Besides user and assistant message text, autocomplete context includes only the newest compaction summary (see Added). The projection scans the whole session, so it is rebuilt only when the context-relevant conversation changes, not on every keystroke.
|
|
39
|
+
- Cache and stream currency now follow the newest conversation entry that affects autocomplete context, not Pi's raw leaf. Custom, label, and session-info entries can move the leaf without discarding an otherwise identical cached suggestion.
|
|
40
|
+
- Automatic suggestions wait for `agent_settled` on hosts that emit it, so a retry or queued continuation cannot use unfinished conversation context. Hosts without that event still settle on `agent_end`. Manual `Ctrl+.` remains an explicit one-shot.
|
|
41
|
+
- The read-only commands `status`, `stats`, and `inspect` now also run on hosts that can show notifications but have no interactive editor, such as RPC; there `status` reports `host=non-interactive` and `editor=unavailable`. Commands that change state or touch the editor stay TUI-only, and no provider seam is reachable outside the TUI. An extension enabled on such a host says once per process that it cannot issue requests.
|
|
42
|
+
- When another extension replaces the editor during a request, the request is now released at the first streamed progress or terminal response the old editor observes, instead of running to completion. Its result is never painted and the foreign editor is never touched.
|
|
43
|
+
- The documentation no longer claims that `stream`, `while-streaming`, and `debug-*` decisions survive `/new`: Pi replaces the extension runtime on `/new`, `/resume`, `/fork`, and `/reload`, so these runtime-only decisions end with it, while `on`/`off`, `min-chars`, and `set` persist through the settings file.
|
|
44
|
+
- The Gallery video now records a real Pi 1.2.0 session: streamed ghost text with alternatives, argument completion with runtime tuning, `inspect`, and an exhausted session budget. A local demo provider answers, so the recording needs no credentials and makes no network request.
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
- `/prompt-autocomplete set` persists the remaining runtime knobs (`debounce-ms`, `max-chars`, `max-alternatives`, and `model`) through the settings file that already stores the enable decision and `min-chars`. Bare `set` prints `status`. Interactive out-of-range values are rejected rather than clamped. A dedicated model is validated against the registry and auth before commit; `active` is an explicit sentinel that commits while no active model is known yet but is rejected when the known active model is unusable; mixed-case model identifiers are preserved; a cross-provider change restates the privacy notice, comparing configured destinations so an unusable previous model still triggers it. Request-identity changes cancel in-flight work without starting a replacement; debounce-only changes drop a waiting timer without aborting an in-flight call. `/prompt-autocomplete min-chars` remains the canonical command. Success notices only claim durability when the settings file was actually written.
|
|
49
|
+
- `--prompt-autocomplete-max-requests <n|off>` and `/prompt-autocomplete budget <n|off>` cap provider requests per session; the default `off` preserves existing behaviour. Only real invocations count, including failed and aborted ones and those made while the ceiling was off, while exact-cache hits, prefix reuse, and in-flight joins stay free. The reservation is taken synchronously after auth and immediately before the provider call, so concurrent requests cannot overshoot and a request whose credentials do not resolve consumes nothing. An exhausted budget blocks automatic and manual requests, reports itself once per exhaustion state, and never starts a replacement request. Usage and ceiling are snapshotted into the session's own non-LLM entries — never into `settings.json` — so `/new` and `/fork` start with a fresh usage count while a graceful `/reload` or `/resume` restores usage and ceiling; restoration scans the whole session and never lets usage go backwards, so branch switches cannot buy extra requests. A session that never touched the budget writes no entries. A ceiling set with `/prompt-autocomplete budget` belongs to the session as well: `/reload` and `/resume` restore it, `/new` and `/fork` start from the CLI flag. `status` and `stats` report `used/limit` with its source.
|
|
50
|
+
- `/prompt-autocomplete inspect [draft text]` previews locally what a request would send: resolved and requested model, the conversation sections with sizes and sanitized excerpts, the transmitted draft tail, the exact request size, output and token ceilings, and the shared request policy for automatic and manual requests. It renders the same request snapshot as the provider path, makes no provider request, persists nothing, and never shows credentials or headers. Without draft text it reports the conversation sections only instead of inventing a draft.
|
|
51
|
+
- `/prompt-autocomplete` completes its arguments in Pi's command menu, including nested forms such as `set debounce-ms`, `set model active`, `budget off`, and `stream on`. Values replace the whole argument span; an already complete command such as `stats` or `stream` opens no menu, so one `Enter` still submits it. Completion is local and synchronous and installs no global autocomplete provider. One grammar table now drives command dispatch, the usage texts (unchanged byte for byte), the completions, and a test that the README documents every command and `set` key.
|
|
52
|
+
- After a compaction, autocomplete requests include the newest compaction summary as a separate background section, bounded to 1,500 characters with the middle elided so the goal and the next steps survive. It applies on hosts with Pi's model-visible session projection (Pi 1.x), where the summarized messages are no longer part of the context; older hosts keep sending the raw messages instead. The compaction's system checkpoint, custom messages, and tool results are never sent. The summary is part of the request cache identity, and `/prompt-autocomplete inspect` shows its size and an excerpt.
|
|
53
|
+
|
|
5
54
|
## [0.2.5] - 2026-08-07
|
|
6
55
|
|
|
7
56
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Inline AI completions for the [Pi coding agent](https://github.com/earendil-works/pi-mono), rendered as unobtrusive ghost text in the prompt editor.
|
|
4
4
|
|
|
5
|
-
[Watch the demo](https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.
|
|
5
|
+
[Watch the demo](https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.4.0/prompt-autocomplete-demo.mp4)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ Prompt Autocomplete is **disabled by default**. Enable it explicitly for a proce
|
|
|
24
24
|
pi --prompt-autocomplete
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Or enable it
|
|
27
|
+
Or enable it from inside an interactive session; the decision is saved for later sessions:
|
|
28
28
|
|
|
29
29
|
```text
|
|
30
30
|
/prompt-autocomplete on
|
|
@@ -38,14 +38,33 @@ Or enable it for the current interactive session:
|
|
|
38
38
|
| Accept the next word or chunk | `Ctrl+Space` |
|
|
39
39
|
| Next alternative / manual one-shot | `Ctrl+.` |
|
|
40
40
|
| Previous alternative | `Ctrl+,` |
|
|
41
|
-
|
|
|
41
|
+
| Accept up to the end of the line | none by default; see [Keys](#keys) |
|
|
42
|
+
| Dismiss suggestions while you keep typing this draft | `Escape` |
|
|
42
43
|
| Enable, disable, or inspect configuration | `/prompt-autocomplete on\|off\|toggle\|status` |
|
|
43
|
-
| Show
|
|
44
|
+
| Show in-memory effectiveness and cost counters | `/prompt-autocomplete stats` |
|
|
45
|
+
| Preview what a request would send, locally | `/prompt-autocomplete inspect [draft text]` |
|
|
44
46
|
| Toggle streamed response previews | `/prompt-autocomplete stream on\|off\|toggle` |
|
|
47
|
+
| Allow suggestions while the main agent works | `/prompt-autocomplete while-streaming on\|off\|toggle` |
|
|
45
48
|
| Set and persist the minimum draft length | `/prompt-autocomplete min-chars <n>` |
|
|
49
|
+
| Cap provider requests for this session | `/prompt-autocomplete budget <n\|off>` |
|
|
50
|
+
| Persist remaining runtime knobs | `/prompt-autocomplete set debounce-ms\|max-chars\|max-alternatives\|model` |
|
|
51
|
+
| Inspect effective runtime knobs | `/prompt-autocomplete set` |
|
|
52
|
+
| Show the effective keys of every action | `/prompt-autocomplete keys` |
|
|
53
|
+
| Change and persist an action's keys | `/prompt-autocomplete set key <action> <key...\|default\|none>` |
|
|
54
|
+
| Show or hide the debug status line | `/prompt-autocomplete debug-on\|debug-off\|debug-toggle` |
|
|
46
55
|
|
|
47
56
|
Legacy fallbacks are available for terminals that forward them: `Ctrl+Tab`, `Alt+[`, and `Alt+]`.
|
|
48
57
|
|
|
58
|
+
### Keys
|
|
59
|
+
|
|
60
|
+
`/prompt-autocomplete set key <action> <key...>` changes the keys of `accept-word`, `accept-line`, `cycle-next` (also the manual one-shot), or `cycle-prev`; it applies at once and is saved with the other [persistent settings](#persistent-settings). Separate several keys with spaces, since `,` is a key itself: `set key cycle-prev ctrl+, alt+[`. `default` restores an action's default keys and `none` unbinds it. `accept-line` has no default key; `set key accept-line alt+l` gives it one. Accepting a line inserts the suggestion up to and including its first line break; a one-line suggestion is accepted whole.
|
|
61
|
+
|
|
62
|
+
Keys use Pi's syntax (`ctrl+shift+x`, `alt+l`, `f5`; see Pi's `docs/keybindings.md`). Keys that cannot reach an action are rejected: `Tab`, `Escape`, `Enter`, `Backspace` and their legacy aliases such as `ctrl+i`, keys Pi's editor handles itself such as `shift+enter`, keys that type text such as `a` or `shift+a`, and keys Pi does not recognize: Escape and F1–F12 with a modifier, and Clear with anything but Shift or Ctrl alone. A key another Prompt Autocomplete action has must be freed there first. `Tab` (accept) and `Escape` (dismiss) are fixed. `/prompt-autocomplete keys` shows every action's keys, whether they are the default or saved, and saved keys that are ignored.
|
|
63
|
+
|
|
64
|
+
Pi comes first: if your Pi keymap (`keybindings.json`) binds one of these keys, or another extension registers it as a shortcut, the key does what Pi or that extension defines. Once the editor is active, `keys` and `status` (`keys-used-by-pi`) list the keys your Pi keymap binds, and `set key` warns when you choose one; before that, Pi's keymap is not available to check. Other extensions' shortcuts cannot be listed, but they still win when you press the key. A pending character jump (`Ctrl+]`) is cancelled by such a key, as in Pi, before the key's action runs. `Tab` and `Escape` keep their ghost-text meaning while a suggestion is visible.
|
|
65
|
+
|
|
66
|
+
After `/prompt-autocomplete ` and a few letters, Pi's command menu completes the arguments, including nested forms such as `set debounce-ms` or `set model active`; `Tab` or `Enter` inserts the selection. A command that is already complete, such as `stats` or `stream on`, opens no menu, so `Enter` still submits it at once. Completion is local and installs no global autocomplete provider.
|
|
67
|
+
|
|
49
68
|
Built-in slash-command and file/path completion keeps precedence over ghost suggestions.
|
|
50
69
|
|
|
51
70
|
### Configuration
|
|
@@ -58,7 +77,8 @@ pi \
|
|
|
58
77
|
--prompt-autocomplete-min-chars 1 \
|
|
59
78
|
--prompt-autocomplete-debounce-ms 250 \
|
|
60
79
|
--prompt-autocomplete-max-chars 240 \
|
|
61
|
-
--prompt-autocomplete-max-alternatives 3
|
|
80
|
+
--prompt-autocomplete-max-alternatives 3 \
|
|
81
|
+
--prompt-autocomplete-max-requests off
|
|
62
82
|
```
|
|
63
83
|
|
|
64
84
|
- The active Pi model is used unless `--prompt-autocomplete-model provider/model` selects a dedicated authenticated model; `active` selects the session model explicitly. An explicitly requested model is never substituted: if it is unknown, unauthenticated, or malformed, autocomplete stays inactive and reports why.
|
|
@@ -66,20 +86,35 @@ pi \
|
|
|
66
86
|
- Provider responses stream into the first ghost-text suggestion by default. Use `--prompt-autocomplete-stream off` or `/prompt-autocomplete stream off` to wait for complete responses instead. This changes rendering only: each suggestion request still uses the same context and token budget.
|
|
67
87
|
- Changing `/prompt-autocomplete stream` cancels active autocomplete work but does **not** start a replacement request; the selected path applies to the next edit or manual one-shot.
|
|
68
88
|
- Partial text advances monotonically: Latin text waits for complete word boundaries, while CJK and other no-space scripts remain grapheme-safe. Alternatives appear only after the response finishes.
|
|
69
|
-
- `Tab` accepts all partial text currently visible. `Ctrl+Space` accepts only its next visible word/chunk.
|
|
70
|
-
- Suggestions pause while the **main agent** is
|
|
89
|
+
- `Tab` accepts all partial text currently visible. `Ctrl+Space` accepts only its next visible word/chunk, and `accept-line` its visible text up to and including the first line break. Each cancels that stream, and unlike accepting a completed suggestion, none automatically starts another paid request.
|
|
90
|
+
- Suggestions pause while the **main agent** is working by default, and stay paused until `agent_settled` on hosts that emit it. This is separate from streamed autocomplete responses. Use `--prompt-autocomplete-while-streaming` or `/prompt-autocomplete while-streaming on` to change that behavior.
|
|
91
|
+
- `Escape` dismissal lasts while the draft extends the dismissed text: further typing starts no request and does not bring the suggestion back. It ends for good when the draft stops extending it (`Backspace`, submit, clear, history), when the conversation, autocomplete model, `max-chars`, or `max-alternatives` changes, or on the one-shot key (`cycle-next`, `Ctrl+.` by default), accept, or cycling. Dismissing an empty-draft suggestion lasts only while the draft stays empty.
|
|
71
92
|
- `Ctrl+.` with no active suggestion is an explicit one-shot request and may bypass the main-agent-streaming, cooldown, and minimum-length gates. Model, authentication, slash-command, and path safety checks still apply.
|
|
72
93
|
- Use `--prompt-autocomplete-debug` or `/prompt-autocomplete debug-on` for troubleshooting.
|
|
73
94
|
|
|
74
|
-
Slash-command
|
|
95
|
+
Slash-command decisions outrank the CLI flags. `on`, `off`, `min-chars`, and `set` are also saved for later sessions and processes (see [Persistent settings](#persistent-settings)). `stream`, `while-streaming`, and `debug-*` live only in the current extension runtime: Pi replaces that runtime on `/new`, `/resume`, `/fork`, and `/reload`, after which their flags apply again. `status` labels each value with its source, `(flag)`, `(saved)`, or `(session)`. Settings you never toggled keep following their flag. Interactive `set` values outside the documented range are rejected rather than clamped; CLI flags still clamp.
|
|
96
|
+
|
|
97
|
+
Changing `max-chars`, `max-alternatives`, or `model` cancels in-flight autocomplete work and drops the request caches. It does **not** start a replacement request. Changing `debounce-ms` only drops a waiting timer; an already-started provider call continues. Debug toggles change neither.
|
|
98
|
+
|
|
99
|
+
#### Session request budget
|
|
100
|
+
|
|
101
|
+
`--prompt-autocomplete-max-requests <n|off>` and `/prompt-autocomplete budget <n|off>` cap how many provider requests one session may issue. The default `off` keeps the 0.2 behaviour.
|
|
102
|
+
|
|
103
|
+
- Only real provider invocations count, including failed and aborted ones, and including invocations made while the ceiling was off — enabling a ceiling later cannot hand out an allowance that ignores what the session already spent. Exact-cache hits, prefix reuse, and joining an in-flight request are free and keep working above the ceiling.
|
|
104
|
+
- A request whose credentials do not resolve consumes nothing: the reservation happens after credentials resolve and immediately before the provider call, so two concurrent requests can never overshoot a ceiling of one. If a credential fails only inside the provider call, for example an OAuth token revoked in between, that counts like any failed call.
|
|
105
|
+
- An exhausted budget blocks automatic **and** manual (`Ctrl+.`) requests and reports itself once per exhaustion state. Raise the ceiling with `/prompt-autocomplete budget <n>` or lift it with `/prompt-autocomplete budget off`; neither starts a replacement request.
|
|
106
|
+
- The budget is **session-scoped**, not process-wide: usage and ceiling are snapshotted into the session's own non-LLM entries and never into `settings.json`. `/new` and `/fork` therefore start with a fresh usage count, while a graceful `/reload` or `/resume` of the same session restores usage and ceiling. Restoration scans the whole session rather than the current branch and never lets usage go backwards, so switching branches cannot buy extra requests. A session that never touched the budget writes no entries at all; once a ceiling has been set or restored, accounting stays durable even while the ceiling is off. A crash before the last snapshot, or a host without `pi.appendEntry`, can lose that durability — the in-process ceiling still applies.
|
|
107
|
+
- A ceiling set with `/prompt-autocomplete budget` belongs to the session as well: `/reload` and `/resume` restore it, while `/new` and `/fork` start from the CLI flag or `off`. A CLI flag applies to its invocation, and `status` labels the ceiling `(flag)`, `(saved)`, or `(session)`.
|
|
108
|
+
- Interactive values outside `1`–`100000` are rejected; the CLI flag clamps. `budget` without an argument, `status`, and `stats` all report `used/limit` with the source of the ceiling. The budget counter and the `stats` block have different scopes: `stats` covers the current extension runtime and restarts after a reload, while the budget counter covers the physical session and survives one.
|
|
109
|
+
- This is a request ceiling only: there is no token or dollar budget.
|
|
75
110
|
|
|
76
111
|
#### Persistent settings
|
|
77
112
|
|
|
78
|
-
`/prompt-autocomplete on`, `off`,
|
|
113
|
+
`/prompt-autocomplete on`, `off`, `min-chars <n>`, and `/prompt-autocomplete set` (`debounce-ms`, `max-chars`, `max-alternatives`, `model`, `key`) are durable: the decision is saved to `$XDG_CONFIG_HOME/pi-prompt-autocomplete/settings.json` (falling back to `~/.config`; override the location with `PI_PROMPT_AUTOCOMPLETE_SETTINGS`) and applies to later processes without any CLI flag. `/prompt-autocomplete min-chars` remains the canonical command; `set min-chars` dispatches to it. An explicit CLI flag still outranks the saved value for that invocation — for numeric knobs and the model flag, passing the registered default is indistinguishable from not passing the flag and defers to the saved value. `set model` validates syntax, registry presence, and auth before saving: a dedicated model must resolve, and `active` commits while no active model is known yet but is rejected when the known active model is unusable. `active` is an explicit sentinel for the session model, mixed-case model ids are preserved, and a cross-provider change restates the privacy notice. An enable decision is only recorded when the host actually installs the editor. Prompt Autocomplete writes nothing but these decisions to the file, never conversation, cache, or stats, and keeps fields it does not know; deleting it restores flag-only behaviour. Each save re-reads the file and changes only the decision being saved, so decisions another Pi process saved in the meantime survive, as do fields a newer version wrote; if the file exists but cannot be read, the save is aborted rather than replacing it. On POSIX systems the file is readable by its owner only. Two saves that overlap, each between its read and its write, can still lose one decision; there is no lock. `status` labels each value with its source, and success notices only claim durability when the file was actually written.
|
|
79
114
|
|
|
80
115
|
### Usage and cost accounting
|
|
81
116
|
|
|
82
|
-
`/prompt-autocomplete stats` gives the
|
|
117
|
+
`/prompt-autocomplete stats` gives the in-memory counters a dedicated, readable report:
|
|
83
118
|
|
|
84
119
|
```text
|
|
85
120
|
Prompt Autocomplete — current session
|
|
@@ -88,6 +123,7 @@ Cache: 5 hits (2 exact, 3 prefix)
|
|
|
88
123
|
Suggestions: 8 offered, 3 accepted (2 full, 1 word/chunk)
|
|
89
124
|
Usage: 1832 tokens, estimated cost ~$0.00214
|
|
90
125
|
Mean provider latency: 410 ms (4 samples)
|
|
126
|
+
Budget: 4/25 (session)
|
|
91
127
|
```
|
|
92
128
|
|
|
93
129
|
`/prompt-autocomplete status` keeps its existing compact `usage=4 req, 5 cached, …` field for configuration troubleshooting.
|
|
@@ -95,13 +131,30 @@ Mean provider latency: 410 ms (4 samples)
|
|
|
95
131
|
- `issued` counts provider calls actually made. Cache hits add no provider request, tokens, cost, or latency sample.
|
|
96
132
|
- Cache hits distinguish exact-draft results from prefix reuse while you type through a cached suggestion.
|
|
97
133
|
- `offered` counts active ghost-text suggestions handed to the editor. Streamed revisions of the same active suggestion do not inflate it; cycling to another alternative counts a new offer. A terminal that is too narrow to draw ghost text can still count an offer.
|
|
98
|
-
- Full and word/chunk acceptance are counted separately, including acceptance of visible streamed partials.
|
|
134
|
+
- Full and word/chunk acceptance are counted separately, including acceptance of visible streamed partials. `accept-line` counts as word/chunk, except when it accepts a completed one-line suggestion whole.
|
|
99
135
|
- `failed` includes provider errors and aborted requests. Tokens from a failed response are counted when the provider returns its terminal usage report within the bounded cancellation drain; otherwise `tok+`/`est+` marks the totals incomplete.
|
|
100
136
|
- Mean provider latency measures local elapsed time from each actual provider invocation until it resolves or rejects; cache hits are excluded.
|
|
101
137
|
- Token counts come from the provider.
|
|
102
138
|
- **The cost is an estimate, not an invoice.** Pi derives it locally by multiplying the reported tokens with its own model price table, so it can disagree with what your provider actually bills.
|
|
103
139
|
- A trailing `+` (`1832 tokens+`, `estimated cost ~$0.00214+`; compact `status`: `1832 tok+`, `~$0.00214 est+`) means at least one request did not report that metric, so the true total may be higher than shown. Tokens and cost are marked independently, because a response can report tokens without a cost figure.
|
|
104
|
-
- Counters live only in memory
|
|
140
|
+
- Counters live only in memory and belong to the current extension runtime: they restart whenever Pi replaces it — a new session, `/resume`, `/fork`, or `/reload`. The session request budget is the exception and survives `/reload` and `/resume` (see [Session request budget](#session-request-budget)).
|
|
141
|
+
|
|
142
|
+
### Inspecting a request
|
|
143
|
+
|
|
144
|
+
`/prompt-autocomplete inspect [draft text]` shows locally what an autocomplete request would send. It makes no provider request, persists nothing, and never shows credentials or headers; at most it warms the in-memory context cache that the next request in the same conversation reuses.
|
|
145
|
+
|
|
146
|
+
- The report renders the same request snapshot the provider path uses: the resolved and requested model, the latest assistant and user messages, the recent-conversation summary, the compaction summary, the transmitted draft tail, the exact request size, and the output and token ceilings. Long sections appear as character counts with short sanitized excerpts.
|
|
147
|
+
- Without draft text the report covers the conversation sections only. The slash command replaced the editor text when you submitted it, so the draft a real request would carry cannot be recovered and is not invented; pass one explicitly to preview a complete request. Pi trims trailing whitespace from submitted commands.
|
|
148
|
+
- `Shared policy` evaluates only the gates every editor shares — enabled state, editor ownership, the main-agent gate, model and auth, `min-chars` and slash/path detection for the given draft, and the session budget — separately for automatic requests and the manual `Ctrl+.` one-shot. Cursor position, the built-in autocomplete menu, Escape dismissal, the per-editor error cooldown, and cached responses belong to the live editor and are not evaluated.
|
|
149
|
+
|
|
150
|
+
### Next prompt for RPC hosts (T3 Code)
|
|
151
|
+
|
|
152
|
+
With `--prompt-autocomplete-next-prompt`, Pi in RPC mode predicts your next prompt after each settled turn and sends it to the host with `set_editor_text` (`ctx.ui.setEditorText`). The host decides what to do with it. Upstream T3 Code ignores the call; the T3 Code branch [`KLIEBHAN/t3code@pi-prompt-suggestions`](https://github.com/KLIEBHAN/t3code/tree/pi-prompt-suggestions) shows it as the suggested next prompt when **Suggest next prompt** is on in Settings > Labs.
|
|
153
|
+
|
|
154
|
+
- It applies only to `--mode rpc`, with or without `--prompt-autocomplete`; the TUI keeps its ghost text.
|
|
155
|
+
- Each settled turn makes one request with an empty draft and one alternative. The autocomplete model, `max-chars`, the session budget, and the `stats` counters apply as in the editor. A new turn or session aborts a pending request, and a result that arrives while the agent is busy again or after the conversation moved to another branch is dropped.
|
|
156
|
+
- In T3 Code, add the flag to Settings > Providers > Pi > Launch arguments. T3 Code starts Pi for delegated threads with the same arguments, so those turns cost a request as well, although T3 Code shows no suggestion for them.
|
|
157
|
+
- Hosts that ignore `set_editor_text` still pay for each request, so enable the flag only for a host that shows the suggestion.
|
|
105
158
|
|
|
106
159
|
## Privacy, providers, and cost
|
|
107
160
|
|
|
@@ -109,25 +162,31 @@ Enabling Prompt Autocomplete permits additional model requests. Streaming change
|
|
|
109
162
|
|
|
110
163
|
- the current prompt draft or its bounded tail,
|
|
111
164
|
- the latest user and assistant messages,
|
|
112
|
-
- a bounded recent-conversation summary
|
|
165
|
+
- a bounded recent-conversation summary,
|
|
166
|
+
- on hosts with Pi's model-visible session projection (Pi 1.x), the newest compaction summary, bounded to 1,500 characters with the middle elided.
|
|
113
167
|
|
|
114
|
-
The
|
|
168
|
+
The newest conversation entry that affects autocomplete context is used only in the local in-memory cache key and is not sent to the provider. Custom, label, and session-info entries can move Pi's raw leaf without invalidating that key.
|
|
115
169
|
|
|
116
170
|
By default, requests use the active model. A dedicated `--prompt-autocomplete-model` may send this context to a different provider, so an explicitly requested model that cannot be used suppresses requests instead of falling back to the active one. Requests can incur token charges and consume provider rate limits.
|
|
117
171
|
|
|
118
172
|
Provider errors, raw responses, model identifiers, and host diagnostics are stripped of terminal control sequences and of bidirectional or invisible formatting characters before they are displayed, so untrusted text cannot repaint the terminal, hide output, drive OSC clipboard and hyperlink escapes, or misrepresent what it names.
|
|
119
173
|
|
|
120
|
-
Successful results are cached only in memory for up to 60 seconds; a terminal entry retains its base draft in process memory for the prefix comparison. If the draft then grows by an exact prefix of a cached suggestion, Prompt Autocomplete removes the text you typed and shows the remaining suffix locally instead of issuing another provider request. Prefix reuse is forward-only, stays scoped to the same conversation
|
|
174
|
+
Successful results are cached only in memory for up to 60 seconds; a terminal entry retains its base draft in process memory for the prefix comparison. If the draft then grows by an exact prefix of a cached suggestion, Prompt Autocomplete removes the text you typed and shows the remaining suffix locally instead of issuing another provider request. Prefix reuse is forward-only, stays scoped to the same context-relevant conversation, model, bounded context and output configuration, and never uses partial streamed text. Divergence, expiry or any context change falls through to a fresh request. The caches are bounded and are cleared on session reset or when the extension is disabled. Provider failures are not cached.
|
|
121
175
|
|
|
122
176
|
The extension makes no autocomplete request while disabled. Automatic empty-draft requests are also disabled by default.
|
|
123
177
|
|
|
124
178
|
## Compatibility and editor ownership
|
|
125
179
|
|
|
126
180
|
- Supported baseline: Pi `0.80.6`, Node.js `22.19.0` or newer.
|
|
127
|
-
-
|
|
181
|
+
- Every release is verified against Pi `0.80.6`, `0.83.0`, `1.2.0`, and `1.5.2`. Pi 1.x draws the editor cursor through fake-cursor markers instead of inverse video; ghost text supports both forms.
|
|
182
|
+
- On hosts that expose Pi's model-visible session projection (Pi 1.x), autocomplete context follows it: a message that `context_edit` omitted or replaced, for example to redact it, is omitted or replaced in autocomplete requests too. If that projection fails, requests carry no conversation context rather than the raw history. Besides user and assistant message text, autocomplete sends only the newest compaction summary, so suggestions keep the summarized background after a compaction; custom messages, tool results, and the compaction's system checkpoint are not sent.
|
|
183
|
+
- Interactive ghost text requires Pi's TUI mode. RPC, JSON, and print modes do not install a custom editor and never reach a provider, except RPC mode with [`--prompt-autocomplete-next-prompt`](#next-prompt-for-rpc-hosts-t3-code).
|
|
184
|
+
- The read-only commands `status`, `stats`, and `inspect` also work on hosts that can show notifications, such as RPC; there `status` reports `host=non-interactive` and `editor=unavailable`. Every command that changes state or touches the editor stays TUI-only. If the extension is enabled on such a host, it says once per process that no autocomplete request will be issued.
|
|
128
185
|
- Forks of Pi's extension API whose `ExtensionContext` predates `mode`, such as [prime-agent](https://www.npmjs.com/package/prime-agent), are supported. For those hosts the extension first requires UI availability and a custom-editor slot, and then verifies that the host actually installed the editor. A front-end that accepts an editor factory without installing it, as forked RPC and daemon modes do, is detected on the first attempt and stays inactive: it is not retried, not left enabled, and can neither render ghost text nor issue a provider request.
|
|
186
|
+
- On Pi 1.x, requests go through the session's model registry, which resolves each provider's stored credential itself. Models from providers that other extensions register therefore work as well, as do OAuth credentials that derive their own endpoint (such as GitHub Copilot Enterprise) and header-only or ambient credentials. Older hosts use the simple completion API below and need an API key.
|
|
129
187
|
- The simple completion API is imported from the `@earendil-works/pi-ai` root specifier, which Pi maps to its compat entrypoint and such forks export directly. If a host exposes that module without `streamSimple`, the extension uses the completion path instead of failing requests.
|
|
130
188
|
- Prompt Autocomplete requires exclusive ownership of Pi's custom-editor slot. It refuses to replace another custom editor and never removes a later replacement editor.
|
|
189
|
+
- If another extension replaces the editor while a request runs, the request is released at the next boundary the old editor observes — an edit, streamed progress, or the terminal response — and its result is never painted. Pi exposes no editor-change event, so a provider that never yields cannot be interrupted earlier.
|
|
131
190
|
|
|
132
191
|
## Development
|
|
133
192
|
|