@kliebhan/pi-prompt-autocomplete 0.2.4 → 0.2.5

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,12 @@
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.5] - 2026-08-07
6
+
7
+ ### Added
8
+
9
+ - `/prompt-autocomplete min-chars <n>` sets the minimum draft length for automatic suggestions, applies it immediately, and persists it to the settings file for later processes. An explicit non-default `--prompt-autocomplete-min-chars` flag outranks the saved value for that invocation; the flag's default value defers to the saved setting. Out-of-range or malformed persisted values degrade to the default, and `status` attributes the value as `(flag)`, `(saved)`, or `(session)`.
10
+
5
11
  ## [0.2.4] - 2026-08-06
6
12
 
7
13
  ### 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.2.4/prompt-autocomplete-demo.mp4)
5
+ [Watch the demo](https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.2.5/prompt-autocomplete-demo.mp4)
6
6
 
7
7
  ## Install
8
8
 
@@ -42,6 +42,7 @@ Or enable it for the current interactive session:
42
42
  | Enable, disable, or inspect configuration | `/prompt-autocomplete on\|off\|toggle\|status` |
43
43
  | Show current-session effectiveness and cost | `/prompt-autocomplete stats` |
44
44
  | Toggle streamed response previews | `/prompt-autocomplete stream on\|off\|toggle` |
45
+ | Set and persist the minimum draft length | `/prompt-autocomplete min-chars <n>` |
45
46
 
46
47
  Legacy fallbacks are available for terminals that forward them: `Ctrl+Tab`, `Alt+[`, and `Alt+]`.
47
48
 
@@ -61,7 +62,7 @@ pi \
61
62
  ```
62
63
 
63
64
  - 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.
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.
65
+ - Automatic suggestions require at least one non-whitespace draft character by default. Set `--prompt-autocomplete-min-chars 0` or `/prompt-autocomplete min-chars 0` (persisted) to opt into empty-draft suggestions.
65
66
  - 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
67
  - 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
68
  - 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.
@@ -72,9 +73,9 @@ pi \
72
73
 
73
74
  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)`, `(saved)`, or `(session)`. Settings you never toggled keep following their flag.
74
75
 
75
- #### Persistent enablement
76
+ #### Persistent settings
76
77
 
77
- `/prompt-autocomplete on` and `off` 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. An explicit `--prompt-autocomplete` flag still outranks a saved `off` for that invocation, and a saved decision is only recorded when the host actually installs the editor. The file stores nothing but the boolean decision; deleting it restores flag-only behaviour.
78
+ `/prompt-autocomplete on`, `off`, and `min-chars <n>` 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. An explicit CLI flag still outranks the saved value for that invocation — for `min-chars`, passing the default (`1`) is indistinguishable from not passing the flag and defers to the saved value. An enable decision is only recorded when the host actually installs the editor. The file stores nothing but these decisions; deleting it restores flag-only behaviour. `status` labels each value with its source.
78
79
 
79
80
  ### Usage and cost accounting
80
81
 
package/core.ts CHANGED
@@ -82,6 +82,8 @@ export const DEFAULT_PROMPT_AUTOCOMPLETE_ENABLED = false;
82
82
  export const DEFAULT_STREAM_RESPONSES = true;
83
83
  export const DEFAULT_DEBOUNCE_MS = 350;
84
84
  export const DEFAULT_MIN_PROMPT_CHARS = 1;
85
+ export const MIN_PROMPT_CHARS_MIN = 0;
86
+ export const MIN_PROMPT_CHARS_MAX = 500;
85
87
  export const DEFAULT_MAX_SUGGESTION_CHARS = 160;
86
88
  export const DEFAULT_MAX_ALTERNATIVES = 3;
87
89
  export const MAX_DRAFT_CONTEXT_CHARS = 2_000;
@@ -608,6 +610,7 @@ export interface PromptAutocompleteRuntimeOverrides {
608
610
  allowWhileStreaming?: boolean;
609
611
  streamResponses?: boolean;
610
612
  debug?: boolean;
613
+ minPromptChars?: number;
611
614
  }
612
615
 
613
616
  export type PromptAutocompleteSettingSource = "flag" | "saved" | "session";
@@ -629,6 +632,7 @@ export function describeSettingSource(override: unknown): PromptAutocompleteSett
629
632
  */
630
633
  export interface PromptAutocompletePersistedSettings {
631
634
  enabled?: boolean;
635
+ minPromptChars?: number;
632
636
  }
633
637
 
634
638
  /**
@@ -649,8 +653,18 @@ export function parsePromptAutocompletePersistedSettings(
649
653
  return {};
650
654
  }
651
655
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
652
- const enabled = (parsed as Record<string, unknown>).enabled;
653
- return typeof enabled === "boolean" ? { enabled } : {};
656
+ const record = parsed as Record<string, unknown>;
657
+ const settings: PromptAutocompletePersistedSettings = {};
658
+ if (typeof record.enabled === "boolean") settings.enabled = record.enabled;
659
+ if (
660
+ typeof record.minPromptChars === "number"
661
+ && Number.isInteger(record.minPromptChars)
662
+ && record.minPromptChars >= MIN_PROMPT_CHARS_MIN
663
+ && record.minPromptChars <= MIN_PROMPT_CHARS_MAX
664
+ ) {
665
+ settings.minPromptChars = record.minPromptChars;
666
+ }
667
+ return settings;
654
668
  }
655
669
 
656
670
  export function serializePromptAutocompletePersistedSettings(
@@ -658,6 +672,14 @@ export function serializePromptAutocompletePersistedSettings(
658
672
  ): string {
659
673
  const payload: PromptAutocompletePersistedSettings = {};
660
674
  if (typeof settings.enabled === "boolean") payload.enabled = settings.enabled;
675
+ if (
676
+ typeof settings.minPromptChars === "number"
677
+ && Number.isInteger(settings.minPromptChars)
678
+ && settings.minPromptChars >= MIN_PROMPT_CHARS_MIN
679
+ && settings.minPromptChars <= MIN_PROMPT_CHARS_MAX
680
+ ) {
681
+ payload.minPromptChars = settings.minPromptChars;
682
+ }
661
683
  return `${JSON.stringify(payload, null, 2)}\n`;
662
684
  }
663
685
 
@@ -681,6 +703,44 @@ export function resolvePersistedEnabled(
681
703
  return { enabled: false, source: "flag" };
682
704
  }
683
705
 
706
+ /**
707
+ * Resolve a numeric setting with the same precedence as the enabled decision:
708
+ * an in-session slash-command value outranks an explicitly passed flag, which
709
+ * outranks the persisted value, which outranks the built-in default.
710
+ */
711
+ export function resolvePersistedNumber(
712
+ override: number | undefined,
713
+ explicitFlag: number | undefined,
714
+ saved: number | undefined,
715
+ fallback: number,
716
+ ): { value: number; source: PromptAutocompleteSettingSource } {
717
+ if (override !== undefined) return { value: override, source: "session" };
718
+ if (explicitFlag !== undefined) return { value: explicitFlag, source: "flag" };
719
+ if (saved !== undefined) return { value: saved, source: "saved" };
720
+ return { value: fallback, source: "flag" };
721
+ }
722
+
723
+ /**
724
+ * Parse an integer flag as an explicit user decision.
725
+ *
726
+ * pi pre-fills string flags with their registered default, so a value equal to
727
+ * the default is indistinguishable from an unset flag and yields undefined,
728
+ * deferring to the persisted setting. Invalid input also yields undefined so a
729
+ * typo cannot silently outrank a saved value.
730
+ */
731
+ export function parseExplicitBoundedIntFlag(
732
+ value: boolean | string | undefined,
733
+ defaultValue: number,
734
+ min: number,
735
+ max: number,
736
+ ): number | undefined {
737
+ if (typeof value !== "string") return undefined;
738
+ const parsed = Number.parseInt(value.trim(), 10);
739
+ if (!Number.isFinite(parsed)) return undefined;
740
+ const bounded = Math.max(min, Math.min(max, parsed));
741
+ return bounded === defaultValue ? undefined : bounded;
742
+ }
743
+
684
744
  interface SuggestionPayload {
685
745
  completions?: unknown;
686
746
  suggestions?: unknown;
package/index.ts CHANGED
@@ -29,6 +29,8 @@ import {
29
29
  DEFAULT_MAX_SUGGESTION_CHARS,
30
30
  DEFAULT_MIN_PROMPT_CHARS,
31
31
  DEFAULT_PREFERRED_MODEL,
32
+ MIN_PROMPT_CHARS_MAX,
33
+ MIN_PROMPT_CHARS_MIN,
32
34
  DEFAULT_PROMPT_AUTOCOMPLETE_ENABLED,
33
35
  DEFAULT_STREAM_RESPONSES,
34
36
  ExpiringLruCache,
@@ -41,10 +43,12 @@ import {
41
43
  MAX_DRAFT_CONTEXT_CHARS,
42
44
  normalizePromptSuggestions,
43
45
  parseBoundedIntFlag,
46
+ parseExplicitBoundedIntFlag,
44
47
  parsePartialPromptSuggestion,
45
48
  parsePromptAutocompleteModelSelection,
46
49
  parsePromptAutocompletePersistedSettings,
47
50
  resolvePersistedEnabled,
51
+ resolvePersistedNumber,
48
52
  serializePromptAutocompletePersistedSettings,
49
53
  PROMPT_AUTOCOMPLETE_SYSTEM_PROMPT,
50
54
  recordProviderLatency,
@@ -284,6 +288,8 @@ interface PromptAutocompleteSharedState {
284
288
  settingsStore?: PromptAutocompleteSettingsStore;
285
289
  /** Last enabled-flag value seen by applyEffectiveConfig, for status attribution. */
286
290
  enabledFlagValue: boolean;
291
+ /** Explicit min-chars flag value seen by applyEffectiveConfig, undefined when defaulted. */
292
+ minPromptCharsFlagExplicit?: number;
287
293
  /** Session-scoped request accounting; reset together with the cache. */
288
294
  usageStats: PromptAutocompleteUsageStats;
289
295
  currentModel?: Model<Api>;
@@ -552,6 +558,12 @@ function applyEffectiveConfig(pi: ExtensionAPI, shared: PromptAutocompleteShared
552
558
  flagEnabled,
553
559
  shared.persistedSettings.enabled,
554
560
  ).enabled;
561
+ shared.minPromptCharsFlagExplicit = parseExplicitBoundedIntFlag(
562
+ pi.getFlag("prompt-autocomplete-min-chars"),
563
+ DEFAULT_MIN_PROMPT_CHARS,
564
+ MIN_PROMPT_CHARS_MIN,
565
+ MIN_PROMPT_CHARS_MAX,
566
+ );
555
567
  shared.config = {
556
568
  ...flagConfig,
557
569
  allowWhileStreaming: resolveOverride(
@@ -560,6 +572,12 @@ function applyEffectiveConfig(pi: ExtensionAPI, shared: PromptAutocompleteShared
560
572
  ),
561
573
  streamResponses: resolveOverride(shared.runtimeOverrides.streamResponses, flagConfig.streamResponses),
562
574
  debug: resolveOverride(shared.runtimeOverrides.debug, flagConfig.debug),
575
+ minPromptChars: resolvePersistedNumber(
576
+ shared.runtimeOverrides.minPromptChars,
577
+ shared.minPromptCharsFlagExplicit,
578
+ shared.persistedSettings.minPromptChars,
579
+ flagConfig.minPromptChars,
580
+ ).value,
563
581
  };
564
582
  }
565
583
 
@@ -621,7 +639,14 @@ function formatStatus(shared: PromptAutocompleteSharedState): string {
621
639
  `request-path=${shared.config.streamResponses && shared.streamSimple ? "stream" : shared.config.streamResponses ? "complete-compat" : "complete"}`,
622
640
  `debug=${shared.config.debug ? "yes" : "no"}(${describeSettingSource(shared.runtimeOverrides.debug)})`,
623
641
  `debounce=${shared.config.debounceMs}ms`,
624
- `min-chars=${shared.config.minPromptChars}`,
642
+ `min-chars=${shared.config.minPromptChars}(${
643
+ resolvePersistedNumber(
644
+ shared.runtimeOverrides.minPromptChars,
645
+ shared.minPromptCharsFlagExplicit,
646
+ shared.persistedSettings.minPromptChars,
647
+ DEFAULT_MIN_PROMPT_CHARS,
648
+ ).source
649
+ })`,
625
650
  `max-suggestion-chars=${shared.config.maxSuggestionChars}`,
626
651
  `max-alternatives=${shared.config.maxAlternatives}`,
627
652
  `cache-size=${shared.requestCache.size}`,
@@ -1817,18 +1842,60 @@ function setStreamResponses(
1817
1842
  }
1818
1843
  }
1819
1844
 
1845
+ function setMinPromptChars(
1846
+ ctx: ExtensionContext,
1847
+ shared: PromptAutocompleteSharedState,
1848
+ arg: string | undefined,
1849
+ ): void {
1850
+ if (arg === undefined) {
1851
+ const resolution = resolvePersistedNumber(
1852
+ shared.runtimeOverrides.minPromptChars,
1853
+ shared.minPromptCharsFlagExplicit,
1854
+ shared.persistedSettings.minPromptChars,
1855
+ DEFAULT_MIN_PROMPT_CHARS,
1856
+ );
1857
+ ctx.ui.notify(
1858
+ `Prompt autocomplete min-chars is ${shared.config.minPromptChars} (${resolution.source})`,
1859
+ "info",
1860
+ );
1861
+ return;
1862
+ }
1863
+
1864
+ const parsed = Number.parseInt(arg, 10);
1865
+ if (!Number.isInteger(parsed) || String(parsed) !== arg || parsed < MIN_PROMPT_CHARS_MIN || parsed > MIN_PROMPT_CHARS_MAX) {
1866
+ ctx.ui.notify(
1867
+ `Usage: /prompt-autocomplete min-chars [${MIN_PROMPT_CHARS_MIN}-${MIN_PROMPT_CHARS_MAX}]`,
1868
+ "warning",
1869
+ );
1870
+ return;
1871
+ }
1872
+
1873
+ const changed = shared.config.minPromptChars !== parsed;
1874
+ shared.config.minPromptChars = parsed;
1875
+ shared.runtimeOverrides.minPromptChars = parsed;
1876
+ persistSettingsDecision(ctx, shared, { minPromptChars: parsed });
1877
+ ctx.ui.notify(
1878
+ `Prompt autocomplete min-chars set to ${parsed} (saved for future sessions)`,
1879
+ "info",
1880
+ );
1881
+
1882
+ if (shared.enabled && changed) {
1883
+ refreshEditorImmediately(shared, "ready", `Minimum prompt length set to ${parsed}`);
1884
+ }
1885
+ }
1886
+
1820
1887
  /**
1821
- * Record an explicit enable/disable decision so later processes honour it.
1888
+ * Record an explicit user decision so later processes honour it.
1822
1889
  *
1823
1890
  * The in-memory copy is updated even when the store write fails, so the
1824
1891
  * current process stays consistent with what the user asked for.
1825
1892
  */
1826
- function persistEnabledDecision(
1893
+ function persistSettingsDecision(
1827
1894
  ctx: ExtensionContext,
1828
1895
  shared: PromptAutocompleteSharedState,
1829
- enabled: boolean,
1896
+ patch: Partial<PromptAutocompletePersistedSettings>,
1830
1897
  ): void {
1831
- shared.persistedSettings = { ...shared.persistedSettings, enabled };
1898
+ shared.persistedSettings = { ...shared.persistedSettings, ...patch };
1832
1899
  const store = shared.settingsStore;
1833
1900
  if (!store) return;
1834
1901
  try {
@@ -1836,12 +1903,20 @@ function persistEnabledDecision(
1836
1903
  } catch (error) {
1837
1904
  const reason = error instanceof Error ? error.message : String(error);
1838
1905
  ctx.ui.notify(
1839
- `Prompt autocomplete could not save the enabled setting: ${truncateDebug(reason, 90)}`,
1906
+ `Prompt autocomplete could not save the setting: ${truncateDebug(reason, 90)}`,
1840
1907
  "warning",
1841
1908
  );
1842
1909
  }
1843
1910
  }
1844
1911
 
1912
+ function persistEnabledDecision(
1913
+ ctx: ExtensionContext,
1914
+ shared: PromptAutocompleteSharedState,
1915
+ enabled: boolean,
1916
+ ): void {
1917
+ persistSettingsDecision(ctx, shared, { enabled });
1918
+ }
1919
+
1845
1920
  function enablePromptAutocomplete(ctx: ExtensionContext, shared: PromptAutocompleteSharedState): boolean {
1846
1921
  const previousOverride = shared.runtimeOverrides.enabled;
1847
1922
  shared.enabled = true;
@@ -2142,6 +2217,10 @@ export function createPromptAutocompleteExtension(
2142
2217
  setStreamResponses(ctx, shared, parts[1]);
2143
2218
  return;
2144
2219
  }
2220
+ if (command === "min-chars") {
2221
+ setMinPromptChars(ctx, shared, parts[1]);
2222
+ return;
2223
+ }
2145
2224
 
2146
2225
  const handlers = createPromptAutocompleteCommandHandlers(ctx, shared);
2147
2226
  const handler = handlers[command];
@@ -2152,7 +2231,7 @@ export function createPromptAutocompleteExtension(
2152
2231
  }
2153
2232
 
2154
2233
  ctx.ui.notify(
2155
- "Usage: /prompt-autocomplete [on|off|toggle|status|stats|stream on|off|toggle|while-streaming on|off|toggle|debug-on|debug-off|debug-toggle]",
2234
+ "Usage: /prompt-autocomplete [on|off|toggle|status|stats|min-chars <n>|stream on|off|toggle|while-streaming on|off|toggle|debug-on|debug-off|debug-toggle]",
2156
2235
  "warning",
2157
2236
  );
2158
2237
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kliebhan/pi-prompt-autocomplete",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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.2.4/prompt-autocomplete-demo.mp4"
29
+ "video": "https://github.com/KLIEBHAN/pi-extensions/releases/download/pi-prompt-autocomplete-v0.2.5/prompt-autocomplete-demo.mp4"
30
30
  },
31
31
  "engines": {
32
32
  "node": ">=22.19.0"