@kliebhan/pi-prompt-autocomplete 0.5.0 → 0.7.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 CHANGED
@@ -2,6 +2,18 @@
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.7.0] - 2026-11-17
6
+
7
+ ### Added
8
+
9
+ - RPC draft completion accepts `fresh` to ask the model again instead of reusing a cached result for the same request; the new result replaces the cached one.
10
+
11
+ ## [0.6.0] - 2026-11-17
12
+
13
+ ### Added
14
+
15
+ - RPC draft completion accepts `alternatives` for ranked, distinct continuations in one model request and `manual` to bypass minimum draft length, including full prompt predictions from an empty draft. Every reply includes `completions`; `completion` remains the first alternative or null. Cache entries separate alternative counts and manual mode.
16
+
5
17
  ## [0.5.0] - 2026-11-17
6
18
 
7
19
  ### 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.0/prompt-autocomplete-demo.mp4)
5
+ [Watch the demo](https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.7.0/prompt-autocomplete-demo.mp4)
6
6
 
7
7
  ## Install
8
8
 
@@ -157,7 +157,9 @@ pi --mode rpc --no-session --no-tools --prompt-autocomplete-model provider/model
157
157
 
158
158
  Send an RPC `prompt` with message `/prompt-autocomplete complete <json>`. The JSON is `{"id":"unique-request-id","draft":"Write","context":{"lastUser":"…","lastAssistant":"…"}}`; `context` and both of its fields are optional. Supply the host thread's latest messages when the sidecar has no session. They use the existing bounded conversation snapshot, not the sidecar's conversation.
159
159
 
160
- Each request receives one fire-and-forget `ctx.ui.setWidget("prompt-autocomplete-completion", [JSON.stringify(result)])`, where `result` is `{"id":"unique-request-id","completion":" the tests"}`. The completion is text to **append**, normalized like ghost text, first alternative only and bounded by `max-chars`. It is `null` for short drafts, exhausted budgets, unusable output, superseded requests, or errors; errors also carry a short, sanitized `error` string. Malformed requests with a string `id` receive an error; invalid JSON or missing/non-string ids cannot be correlated and receive no widget.
160
+ Optional request fields: `alternatives` (finite number, default `1`, rounded down and clamped to `1..max-alternatives`; configured by `--prompt-autocomplete-max-alternatives`, default `3`) asks for distinct alternatives in one model request. `manual` (boolean, default `false`) bypasses `min-chars`; with an empty draft, alternatives are complete prompts predicted from `context`. Cache entries distinguish alternative counts and manual mode; budget and cancellation rules are unchanged. `fresh` (boolean, default `false`) asks the model again instead of reusing a cached result for the same request, and the new result replaces the cached one.
161
+
162
+ Each request receives one fire-and-forget `ctx.ui.setWidget("prompt-autocomplete-completion", [JSON.stringify(result)])`, where `result` is `{"id":"unique-request-id","completion":" the tests","completions":[" the tests"]}`. `completions` contains all distinct normalized alternatives in order, each bounded by `max-chars` and ready to **append**. `completion` always equals `completions[0]` or `null`. Every reply includes `completions`, empty for short automatic drafts, exhausted budgets, unusable output, superseded requests, or errors; errors also carry a short, sanitized `error` string. Requests without the new fields still return at most one alternative. Malformed requests with a string `id` receive an error; invalid JSON or missing/non-string ids cannot be correlated and receive no widget.
161
163
 
162
164
  Use a unique id per request. A new request aborts the previous one and immediately replies `null` for its id, even if the provider is slow to stop. Requests share model selection, result cache, request budget, and stats with the existing path. This command does not write editor text or cancel next-prompt requests. It is RPC-only and omitted from argument completions.
163
165
 
package/core.ts CHANGED
@@ -2349,6 +2349,7 @@ export function renderPromptAutocompleteUserText(snapshot: PromptAutocompleteReq
2349
2349
  `Task: propose up to ${snapshot.maxAlternatives} ranked continuations to insert at the cursor.`,
2350
2350
  "Each item must be only the text after the cursor; never restate text the user already typed.",
2351
2351
  "If the draft ends inside a partially typed word, complete that word directly without a leading space.",
2352
+ "If the draft ends with a complete word, start each item with the single space that separates it from that word.",
2352
2353
  ].join("\n"),
2353
2354
  );
2354
2355
  }
package/index.ts CHANGED
@@ -2656,10 +2656,13 @@ async function completeRpcDraft(ctx: ExtensionContext, shared: PromptAutocomplet
2656
2656
  const controller = new AbortController();
2657
2657
  shared.draftCompletionAbort = controller;
2658
2658
  let replied = false;
2659
- const reply = (completion: string | null, error?: string) => {
2659
+ const reply = (suggestions: string[] | null, error?: string) => {
2660
2660
  if (replied) return;
2661
2661
  replied = true;
2662
- ctx.ui.setWidget("prompt-autocomplete-completion", [JSON.stringify({ id, completion, ...(error ? { error } : {}) })]);
2662
+ const completions = suggestions ?? [];
2663
+ ctx.ui.setWidget("prompt-autocomplete-completion", [JSON.stringify({
2664
+ id, completion: completions[0] ?? null, completions, ...(error ? { error } : {}),
2665
+ })]);
2663
2666
  };
2664
2667
  const onAbort = () => reply(null);
2665
2668
  controller.signal.addEventListener("abort", onAbort, { once: true });
@@ -2668,6 +2671,17 @@ async function completeRpcDraft(ctx: ExtensionContext, shared: PromptAutocomplet
2668
2671
  reply(null, "Invalid completion request");
2669
2672
  return;
2670
2673
  }
2674
+ const alternatives = "alternatives" in value ? value.alternatives : 1;
2675
+ const manual = "manual" in value ? value.manual : false;
2676
+ const fresh = "fresh" in value ? value.fresh : false;
2677
+ if (
2678
+ typeof alternatives !== "number" || !Number.isFinite(alternatives)
2679
+ || typeof manual !== "boolean" || typeof fresh !== "boolean"
2680
+ ) {
2681
+ reply(null, "Invalid completion request");
2682
+ return;
2683
+ }
2684
+ const maxAlternatives = Math.max(1, Math.min(shared.config.maxAlternatives, Math.floor(alternatives)));
2671
2685
  const context = "context" in value ? value.context : undefined;
2672
2686
  const branch: unknown[] = [];
2673
2687
  if (context !== undefined) {
@@ -2686,19 +2700,22 @@ async function completeRpcDraft(ctx: ExtensionContext, shared: PromptAutocomplet
2686
2700
  if (text) branch.push({ type: "message", message: { role, content: text } });
2687
2701
  }
2688
2702
  }
2689
- if (value.draft.trim().length < shared.config.minPromptChars) {
2703
+ if (!manual && value.draft.trim().length < shared.config.minPromptChars) {
2690
2704
  reply(null);
2691
2705
  return;
2692
2706
  }
2693
- const request = buildSuggestionRequest(shared, value.draft, shared.activationId, 1, branch);
2707
+ const request = buildSuggestionRequest(shared, value.draft, shared.activationId, maxAlternatives, branch);
2694
2708
  if (!request) {
2695
2709
  reply(null, "Completion model unavailable");
2696
2710
  return;
2697
2711
  }
2698
- let entry = getCachedRequest(shared, request.cacheKey);
2712
+ // Count and context are already in the key; keep manual results separate too.
2713
+ request.cacheKey = JSON.stringify([request.cacheKey, manual]);
2714
+ // `fresh` asks the model again instead of reusing a cached result for the same request.
2715
+ let entry = fresh ? undefined : getCachedRequest(shared, request.cacheKey);
2699
2716
  if (entry) shared.usageStats.cacheHits += 1;
2700
2717
  else entry = await fetchSuggestionUncached(shared, { ...request, useStreaming: false }, controller.signal, () => undefined);
2701
- reply(controller.signal.aborted ? null : entry.suggestions[0] ?? null);
2718
+ reply(controller.signal.aborted ? null : entry.suggestions);
2702
2719
  } catch (error) {
2703
2720
  reply(null, controller.signal.aborted || error instanceof PromptAutocompleteBudgetExhaustedError
2704
2721
  ? undefined : "Completion request failed");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kliebhan/pi-prompt-autocomplete",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Privacy-conscious inline AI prompt completion for the Pi coding agent",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "extensions": [
27
27
  "./index.ts"
28
28
  ],
29
- "video": "https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.5.0/prompt-autocomplete-demo.mp4"
29
+ "video": "https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.7.0/prompt-autocomplete-demo.mp4"
30
30
  },
31
31
  "engines": {
32
32
  "node": ">=22.19.0"