@kliebhan/pi-prompt-autocomplete 0.1.2 → 0.2.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.
Files changed (5) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +41 -6
  3. package/core.ts +619 -26
  4. package/index.ts +460 -61
  5. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
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.2.0] - 2026-07-31
6
+
7
+ ### Added
8
+
9
+ - Streamed ghost text for the first suggestion, enabled by default without additional provider requests. Partial Latin text advances only at stable word boundaries, no-space scripts remain grapheme-safe, and ranked alternatives appear after the terminal response.
10
+ - `--prompt-autocomplete-stream on|off` and `/prompt-autocomplete stream on|off|toggle` select between streamed previews and complete-response rendering. The slash-command choice survives later session starts in the same process.
11
+ - Accepting visible partial text cancels its stream and does not automatically issue a second paid request.
12
+ - Forward prefix reuse serves the remaining suffix of a still-valid terminal cache entry while the user types through it, avoiding another provider request without crossing model, branch, context, output-configuration, TTL, or grapheme boundaries.
13
+ - Session accounting for autocomplete requests: `/prompt-autocomplete status` now reports issued requests, requests served from the cache, failed requests, provider-reported tokens, and an estimated cost derived from pi's local model price table. Tokens and cost are marked independently with a trailing `+` when a request did not report that metric.
14
+ - `/prompt-autocomplete stats` presents current-session requests, failures, exact and prefix cache hits, active suggestions offered, full and word/chunk acceptance, token/cost totals, and mean provider latency without a live overlay or persistence.
15
+ - Status output now names the source of each toggle, so a session override is distinguishable from a CLI flag.
16
+
17
+ ### Security
18
+
19
+ - Strip terminal C0/C1 control characters and reject unpaired UTF-16 surrogates before suggestions reach the TUI; length limits now truncate only at complete grapheme boundaries.
20
+
21
+ ### Fixed
22
+
23
+ - `/prompt-autocomplete on`, `off`, `while-streaming`, and the debug toggles no longer revert to their CLI-flag values when a new session starts.
24
+
5
25
  ## [0.1.2] - 2026-07-24
6
26
 
7
27
  ### Fixed
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.1.2/prompt-autocomplete-demo.mp4)
5
+ [Watch the demo](https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.2.0/prompt-autocomplete-demo.mp4)
6
6
 
7
7
  ## Install
8
8
 
@@ -39,7 +39,9 @@ Or enable it for the current interactive session:
39
39
  | Next alternative / manual one-shot | `Ctrl+.` |
40
40
  | Previous alternative | `Ctrl+,` |
41
41
  | Dismiss the suggestion for this draft | `Escape` |
42
- | Enable, disable, or inspect | `/prompt-autocomplete on\|off\|toggle\|status` |
42
+ | Enable, disable, or inspect configuration | `/prompt-autocomplete on\|off\|toggle\|status` |
43
+ | Show current-session effectiveness and cost | `/prompt-autocomplete stats` |
44
+ | Toggle streamed response previews | `/prompt-autocomplete stream on\|off\|toggle` |
43
45
 
44
46
  Legacy fallbacks are available for terminals that forward them: `Ctrl+Tab`, `Alt+[`, and `Alt+]`.
45
47
 
@@ -51,6 +53,7 @@ Built-in slash-command and file/path completion keeps precedence over ghost sugg
51
53
  pi \
52
54
  --prompt-autocomplete \
53
55
  --prompt-autocomplete-model openai/gpt-5.4-mini \
56
+ --prompt-autocomplete-stream on \
54
57
  --prompt-autocomplete-min-chars 1 \
55
58
  --prompt-autocomplete-debounce-ms 250 \
56
59
  --prompt-autocomplete-max-chars 240 \
@@ -59,13 +62,45 @@ pi \
59
62
 
60
63
  - The active Pi model is used unless `--prompt-autocomplete-model provider/model` selects a dedicated authenticated model.
61
64
  - Automatic suggestions require at least one non-whitespace draft character by default. Set `--prompt-autocomplete-min-chars 0` to opt into empty-draft suggestions.
62
- - Suggestions pause while the main agent is streaming by default. Use `--prompt-autocomplete-while-streaming` or `/prompt-autocomplete while-streaming on` to change that behavior.
63
- - `Ctrl+.` with no active suggestion is an explicit one-shot request and may bypass the streaming, cooldown, and minimum-length gates. Model, authentication, slash-command, and path safety checks still apply.
65
+ - 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.
66
+ - 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.
67
+ - 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.
68
+ - `Tab` accepts all partial text currently visible. `Ctrl+Space` accepts only its next visible word/chunk. Both cancel that stream, and unlike accepting a completed suggestion, neither automatically starts another paid request.
69
+ - Suggestions pause while the **main agent** is streaming by default. This is separate from streamed autocomplete responses. Use `--prompt-autocomplete-while-streaming` or `/prompt-autocomplete while-streaming on` to change that behavior.
70
+ - `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.
64
71
  - Use `--prompt-autocomplete-debug` or `/prompt-autocomplete debug-on` for troubleshooting.
65
72
 
73
+ Slash-command toggles (`on`, `off`, `stream`, `while-streaming`, `debug-*`) outrank the CLI flags for the rest of the process, including in sessions started later. `status` labels each toggle with its source, `(flag)` or `(session)`. Settings you never toggled keep following their flag.
74
+
75
+ ### Usage and cost accounting
76
+
77
+ `/prompt-autocomplete stats` gives the current session a dedicated, readable report:
78
+
79
+ ```text
80
+ Prompt Autocomplete — current session
81
+ Requests: 4 issued, 1 failed
82
+ Cache: 5 hits (2 exact, 3 prefix)
83
+ Suggestions: 8 offered, 3 accepted (2 full, 1 word/chunk)
84
+ Usage: 1832 tokens, estimated cost ~$0.00214
85
+ Mean provider latency: 410 ms (4 samples)
86
+ ```
87
+
88
+ `/prompt-autocomplete status` keeps its existing compact `usage=4 req, 5 cached, …` field for configuration troubleshooting.
89
+
90
+ - `issued` counts provider calls actually made. Cache hits add no provider request, tokens, cost, or latency sample.
91
+ - Cache hits distinguish exact-draft results from prefix reuse while you type through a cached suggestion.
92
+ - `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.
93
+ - Full and word/chunk acceptance are counted separately, including acceptance of visible streamed partials.
94
+ - `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.
95
+ - Mean provider latency measures local elapsed time from each actual provider invocation until it resolves or rejects; cache hits are excluded.
96
+ - Token counts come from the provider.
97
+ - **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.
98
+ - 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.
99
+ - Counters live only in memory, are scoped to the current session, and reset when a new session starts.
100
+
66
101
  ## Privacy, providers, and cost
67
102
 
68
- Enabling Prompt Autocomplete permits additional model requests. A request can contain:
103
+ Enabling Prompt Autocomplete permits additional model requests. Streaming changes only when the same response becomes visible; it does not add a second request. A request can contain:
69
104
 
70
105
  - the current prompt draft or its bounded tail,
71
106
  - the latest user and assistant messages,
@@ -75,7 +110,7 @@ The active conversation leaf identity is used only in the local in-memory cache
75
110
 
76
111
  By default, requests use the active model. A dedicated `--prompt-autocomplete-model` may send this context to a different provider. Requests can incur token charges and consume provider rate limits.
77
112
 
78
- Successful results are cached only in memory for up to 60 seconds. The cache is bounded and is cleared on session reset or when the extension is disabled. Provider failures are not cached.
113
+ 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 leaf, 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.
79
114
 
80
115
  The extension makes no autocomplete request while disabled. Automatic empty-draft requests are also disabled by default.
81
116