@kliebhan/pi-prompt-autocomplete 0.2.3 → 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 +12 -0
- package/README.md +8 -3
- package/core.ts +122 -1
- package/index.ts +203 -5
- package/package.json +2 -2
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.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
|
+
|
|
11
|
+
## [0.2.4] - 2026-08-06
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `/prompt-autocomplete on` and `off` now persist across processes. The decision is saved to `$XDG_CONFIG_HOME/pi-prompt-autocomplete/settings.json` (`~/.config` fallback, `PI_PROMPT_AUTOCOMPLETE_SETTINGS` override) and enables autocomplete in later sessions without the CLI flag. An explicit `--prompt-autocomplete` flag still outranks a saved `off` for that invocation, a decision is only recorded when the host actually installs the editor, a failed save warns without losing the in-process decision, and a malformed file degrades to flag-only behaviour. `status` attributes the setting as `(flag)`, `(saved)`, or `(session)`.
|
|
16
|
+
|
|
5
17
|
## [0.2.3] - 2026-08-06
|
|
6
18
|
|
|
7
19
|
### 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.2.
|
|
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.
|
|
@@ -70,7 +71,11 @@ pi \
|
|
|
70
71
|
- `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.
|
|
71
72
|
- Use `--prompt-autocomplete-debug` or `/prompt-autocomplete debug-on` for troubleshooting.
|
|
72
73
|
|
|
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
|
+
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.
|
|
75
|
+
|
|
76
|
+
#### Persistent settings
|
|
77
|
+
|
|
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.
|
|
74
79
|
|
|
75
80
|
### Usage and cost accounting
|
|
76
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,9 +610,10 @@ export interface PromptAutocompleteRuntimeOverrides {
|
|
|
608
610
|
allowWhileStreaming?: boolean;
|
|
609
611
|
streamResponses?: boolean;
|
|
610
612
|
debug?: boolean;
|
|
613
|
+
minPromptChars?: number;
|
|
611
614
|
}
|
|
612
615
|
|
|
613
|
-
export type PromptAutocompleteSettingSource = "flag" | "session";
|
|
616
|
+
export type PromptAutocompleteSettingSource = "flag" | "saved" | "session";
|
|
614
617
|
|
|
615
618
|
export function resolveOverride<T>(override: T | undefined, flagValue: T): T {
|
|
616
619
|
return override ?? flagValue;
|
|
@@ -620,6 +623,124 @@ export function describeSettingSource(override: unknown): PromptAutocompleteSett
|
|
|
620
623
|
return override === undefined ? "flag" : "session";
|
|
621
624
|
}
|
|
622
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Settings persisted across processes.
|
|
628
|
+
*
|
|
629
|
+
* Only explicit `/prompt-autocomplete on|off` decisions are stored. An absent
|
|
630
|
+
* field defers to the CLI flag, so an empty or missing file behaves exactly
|
|
631
|
+
* like no persisted decision.
|
|
632
|
+
*/
|
|
633
|
+
export interface PromptAutocompletePersistedSettings {
|
|
634
|
+
enabled?: boolean;
|
|
635
|
+
minPromptChars?: number;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Parse persisted settings text defensively.
|
|
640
|
+
*
|
|
641
|
+
* The file is user-editable, so anything malformed — invalid JSON, a non-object
|
|
642
|
+
* payload, or a non-boolean `enabled` — degrades to "no persisted decision"
|
|
643
|
+
* instead of failing extension activation.
|
|
644
|
+
*/
|
|
645
|
+
export function parsePromptAutocompletePersistedSettings(
|
|
646
|
+
text: string | undefined,
|
|
647
|
+
): PromptAutocompletePersistedSettings {
|
|
648
|
+
if (!text) return {};
|
|
649
|
+
let parsed: unknown;
|
|
650
|
+
try {
|
|
651
|
+
parsed = JSON.parse(text);
|
|
652
|
+
} catch {
|
|
653
|
+
return {};
|
|
654
|
+
}
|
|
655
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
|
|
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;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function serializePromptAutocompletePersistedSettings(
|
|
671
|
+
settings: PromptAutocompletePersistedSettings,
|
|
672
|
+
): string {
|
|
673
|
+
const payload: PromptAutocompletePersistedSettings = {};
|
|
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
|
+
}
|
|
683
|
+
return `${JSON.stringify(payload, null, 2)}\n`;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Resolve the effective enabled state and its attribution.
|
|
688
|
+
*
|
|
689
|
+
* Precedence: an in-session slash-command decision outranks everything; an
|
|
690
|
+
* explicit CLI flag outranks the persisted decision because it is scoped to
|
|
691
|
+
* this invocation; the persisted decision outranks the built-in default.
|
|
692
|
+
* pi's boolean extension flags can only be switched on, so `flagEnabled` is
|
|
693
|
+
* true exactly when the flag was passed explicitly.
|
|
694
|
+
*/
|
|
695
|
+
export function resolvePersistedEnabled(
|
|
696
|
+
override: boolean | undefined,
|
|
697
|
+
flagEnabled: boolean,
|
|
698
|
+
saved: boolean | undefined,
|
|
699
|
+
): { enabled: boolean; source: PromptAutocompleteSettingSource } {
|
|
700
|
+
if (override !== undefined) return { enabled: override, source: "session" };
|
|
701
|
+
if (flagEnabled) return { enabled: true, source: "flag" };
|
|
702
|
+
if (saved !== undefined) return { enabled: saved, source: "saved" };
|
|
703
|
+
return { enabled: false, source: "flag" };
|
|
704
|
+
}
|
|
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
|
+
|
|
623
744
|
interface SuggestionPayload {
|
|
624
745
|
completions?: unknown;
|
|
625
746
|
suggestions?: unknown;
|
package/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
1
4
|
import * as piAi from "@earendil-works/pi-ai";
|
|
2
5
|
import type {
|
|
3
6
|
Api,
|
|
@@ -26,6 +29,8 @@ import {
|
|
|
26
29
|
DEFAULT_MAX_SUGGESTION_CHARS,
|
|
27
30
|
DEFAULT_MIN_PROMPT_CHARS,
|
|
28
31
|
DEFAULT_PREFERRED_MODEL,
|
|
32
|
+
MIN_PROMPT_CHARS_MAX,
|
|
33
|
+
MIN_PROMPT_CHARS_MIN,
|
|
29
34
|
DEFAULT_PROMPT_AUTOCOMPLETE_ENABLED,
|
|
30
35
|
DEFAULT_STREAM_RESPONSES,
|
|
31
36
|
ExpiringLruCache,
|
|
@@ -38,8 +43,13 @@ import {
|
|
|
38
43
|
MAX_DRAFT_CONTEXT_CHARS,
|
|
39
44
|
normalizePromptSuggestions,
|
|
40
45
|
parseBoundedIntFlag,
|
|
46
|
+
parseExplicitBoundedIntFlag,
|
|
41
47
|
parsePartialPromptSuggestion,
|
|
42
48
|
parsePromptAutocompleteModelSelection,
|
|
49
|
+
parsePromptAutocompletePersistedSettings,
|
|
50
|
+
resolvePersistedEnabled,
|
|
51
|
+
resolvePersistedNumber,
|
|
52
|
+
serializePromptAutocompletePersistedSettings,
|
|
43
53
|
PROMPT_AUTOCOMPLETE_SYSTEM_PROMPT,
|
|
44
54
|
recordProviderLatency,
|
|
45
55
|
recordProviderUsage,
|
|
@@ -52,6 +62,7 @@ import {
|
|
|
52
62
|
type CoalescedRequestEntry,
|
|
53
63
|
type CoalescedRequestSubscription,
|
|
54
64
|
type PromptAutocompleteModelSelection,
|
|
65
|
+
type PromptAutocompletePersistedSettings,
|
|
55
66
|
type PromptAutocompleteRuntimeOverrides,
|
|
56
67
|
type PromptAutocompleteUsageStats,
|
|
57
68
|
} from "./core.ts";
|
|
@@ -210,6 +221,59 @@ export interface PromptAutocompleteDependencies {
|
|
|
210
221
|
completeSimple?: CompleteSimpleFunction;
|
|
211
222
|
streamSimple?: StreamSimpleFunction;
|
|
212
223
|
now?: () => number;
|
|
224
|
+
/** Store for decisions that survive the process; defaults to a JSON settings file. */
|
|
225
|
+
settingsStore?: PromptAutocompleteSettingsStore;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Persistence boundary for cross-process decisions.
|
|
230
|
+
*
|
|
231
|
+
* `load` runs once per activation and must not throw for a missing or
|
|
232
|
+
* malformed store; `save` may throw and the caller reports the failure.
|
|
233
|
+
*/
|
|
234
|
+
export interface PromptAutocompleteSettingsStore {
|
|
235
|
+
load(): PromptAutocompletePersistedSettings;
|
|
236
|
+
save(settings: PromptAutocompletePersistedSettings): void;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Resolve the persisted settings file path.
|
|
241
|
+
*
|
|
242
|
+
* `PI_PROMPT_AUTOCOMPLETE_SETTINGS` overrides the location outright; otherwise
|
|
243
|
+
* the file lives under `$XDG_CONFIG_HOME/pi-prompt-autocomplete/settings.json`,
|
|
244
|
+
* falling back to `~/.config` when XDG is unset or not absolute as the spec
|
|
245
|
+
* requires.
|
|
246
|
+
*/
|
|
247
|
+
export function resolvePromptAutocompleteSettingsPath(
|
|
248
|
+
env: Record<string, string | undefined> = process.env,
|
|
249
|
+
homeDir: string = homedir(),
|
|
250
|
+
): string {
|
|
251
|
+
const explicit = env.PI_PROMPT_AUTOCOMPLETE_SETTINGS;
|
|
252
|
+
if (explicit) return explicit;
|
|
253
|
+
const xdgConfigHome = env.XDG_CONFIG_HOME;
|
|
254
|
+
const configHome = xdgConfigHome && isAbsolute(xdgConfigHome) ? xdgConfigHome : join(homeDir, ".config");
|
|
255
|
+
return join(configHome, "pi-prompt-autocomplete", "settings.json");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function createFileSettingsStore(path: string): PromptAutocompleteSettingsStore {
|
|
259
|
+
return {
|
|
260
|
+
load(): PromptAutocompletePersistedSettings {
|
|
261
|
+
let text: string;
|
|
262
|
+
try {
|
|
263
|
+
text = readFileSync(path, "utf8");
|
|
264
|
+
} catch {
|
|
265
|
+
return {};
|
|
266
|
+
}
|
|
267
|
+
return parsePromptAutocompletePersistedSettings(text);
|
|
268
|
+
},
|
|
269
|
+
save(settings: PromptAutocompletePersistedSettings): void {
|
|
270
|
+
// Atomic replace so a crash mid-write cannot corrupt the settings file.
|
|
271
|
+
const tempPath = `${path}.tmp`;
|
|
272
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
273
|
+
writeFileSync(tempPath, serializePromptAutocompletePersistedSettings(settings), "utf8");
|
|
274
|
+
renameSync(tempPath, path);
|
|
275
|
+
},
|
|
276
|
+
};
|
|
213
277
|
}
|
|
214
278
|
|
|
215
279
|
interface PromptAutocompleteSharedState {
|
|
@@ -219,6 +283,13 @@ interface PromptAutocompleteSharedState {
|
|
|
219
283
|
config: PromptAutocompleteConfig;
|
|
220
284
|
/** Slash-command decisions that outrank flags for the lifetime of the process. */
|
|
221
285
|
runtimeOverrides: PromptAutocompleteRuntimeOverrides;
|
|
286
|
+
/** Decisions persisted across processes; loaded once per activation. */
|
|
287
|
+
persistedSettings: PromptAutocompletePersistedSettings;
|
|
288
|
+
settingsStore?: PromptAutocompleteSettingsStore;
|
|
289
|
+
/** Last enabled-flag value seen by applyEffectiveConfig, for status attribution. */
|
|
290
|
+
enabledFlagValue: boolean;
|
|
291
|
+
/** Explicit min-chars flag value seen by applyEffectiveConfig, undefined when defaulted. */
|
|
292
|
+
minPromptCharsFlagExplicit?: number;
|
|
222
293
|
/** Session-scoped request accounting; reset together with the cache. */
|
|
223
294
|
usageStats: PromptAutocompleteUsageStats;
|
|
224
295
|
currentModel?: Model<Api>;
|
|
@@ -481,7 +552,18 @@ function applyEffectiveConfig(pi: ExtensionAPI, shared: PromptAutocompleteShared
|
|
|
481
552
|
const flagEnabled = pi.getFlag("prompt-autocomplete") === true;
|
|
482
553
|
const flagConfig = parseConfig(pi);
|
|
483
554
|
|
|
484
|
-
shared.
|
|
555
|
+
shared.enabledFlagValue = flagEnabled;
|
|
556
|
+
shared.enabled = resolvePersistedEnabled(
|
|
557
|
+
shared.runtimeOverrides.enabled,
|
|
558
|
+
flagEnabled,
|
|
559
|
+
shared.persistedSettings.enabled,
|
|
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
|
+
);
|
|
485
567
|
shared.config = {
|
|
486
568
|
...flagConfig,
|
|
487
569
|
allowWhileStreaming: resolveOverride(
|
|
@@ -490,6 +572,12 @@ function applyEffectiveConfig(pi: ExtensionAPI, shared: PromptAutocompleteShared
|
|
|
490
572
|
),
|
|
491
573
|
streamResponses: resolveOverride(shared.runtimeOverrides.streamResponses, flagConfig.streamResponses),
|
|
492
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,
|
|
493
581
|
};
|
|
494
582
|
}
|
|
495
583
|
|
|
@@ -535,7 +623,13 @@ function formatStatus(shared: PromptAutocompleteSharedState): string {
|
|
|
535
623
|
const requestedModel = describePromptAutocompleteModelSelection(shared.config.modelSelection);
|
|
536
624
|
|
|
537
625
|
return [
|
|
538
|
-
`enabled=${shared.enabled ? "yes" : "no"}(${
|
|
626
|
+
`enabled=${shared.enabled ? "yes" : "no"}(${
|
|
627
|
+
resolvePersistedEnabled(
|
|
628
|
+
shared.runtimeOverrides.enabled,
|
|
629
|
+
shared.enabledFlagValue,
|
|
630
|
+
shared.persistedSettings.enabled,
|
|
631
|
+
).source
|
|
632
|
+
})`,
|
|
539
633
|
`editor=${editorState}`,
|
|
540
634
|
shared.editorBlockedReason ? `editor-blocked=${truncateDebug(shared.editorBlockedReason, 90)}` : undefined,
|
|
541
635
|
`model=${truncateDebug(formatModelLabel(resolvedModel), 90)}`,
|
|
@@ -545,7 +639,14 @@ function formatStatus(shared: PromptAutocompleteSharedState): string {
|
|
|
545
639
|
`request-path=${shared.config.streamResponses && shared.streamSimple ? "stream" : shared.config.streamResponses ? "complete-compat" : "complete"}`,
|
|
546
640
|
`debug=${shared.config.debug ? "yes" : "no"}(${describeSettingSource(shared.runtimeOverrides.debug)})`,
|
|
547
641
|
`debounce=${shared.config.debounceMs}ms`,
|
|
548
|
-
`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
|
+
})`,
|
|
549
650
|
`max-suggestion-chars=${shared.config.maxSuggestionChars}`,
|
|
550
651
|
`max-alternatives=${shared.config.maxAlternatives}`,
|
|
551
652
|
`cache-size=${shared.requestCache.size}`,
|
|
@@ -1741,6 +1842,81 @@ function setStreamResponses(
|
|
|
1741
1842
|
}
|
|
1742
1843
|
}
|
|
1743
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
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Record an explicit user decision so later processes honour it.
|
|
1889
|
+
*
|
|
1890
|
+
* The in-memory copy is updated even when the store write fails, so the
|
|
1891
|
+
* current process stays consistent with what the user asked for.
|
|
1892
|
+
*/
|
|
1893
|
+
function persistSettingsDecision(
|
|
1894
|
+
ctx: ExtensionContext,
|
|
1895
|
+
shared: PromptAutocompleteSharedState,
|
|
1896
|
+
patch: Partial<PromptAutocompletePersistedSettings>,
|
|
1897
|
+
): void {
|
|
1898
|
+
shared.persistedSettings = { ...shared.persistedSettings, ...patch };
|
|
1899
|
+
const store = shared.settingsStore;
|
|
1900
|
+
if (!store) return;
|
|
1901
|
+
try {
|
|
1902
|
+
store.save(shared.persistedSettings);
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1905
|
+
ctx.ui.notify(
|
|
1906
|
+
`Prompt autocomplete could not save the setting: ${truncateDebug(reason, 90)}`,
|
|
1907
|
+
"warning",
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
function persistEnabledDecision(
|
|
1913
|
+
ctx: ExtensionContext,
|
|
1914
|
+
shared: PromptAutocompleteSharedState,
|
|
1915
|
+
enabled: boolean,
|
|
1916
|
+
): void {
|
|
1917
|
+
persistSettingsDecision(ctx, shared, { enabled });
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1744
1920
|
function enablePromptAutocomplete(ctx: ExtensionContext, shared: PromptAutocompleteSharedState): boolean {
|
|
1745
1921
|
const previousOverride = shared.runtimeOverrides.enabled;
|
|
1746
1922
|
shared.enabled = true;
|
|
@@ -1846,34 +2022,40 @@ function createPromptAutocompleteCommandHandlers(
|
|
|
1846
2022
|
on: () => {
|
|
1847
2023
|
if (shared.enabled && shared.ownsEditor?.()) {
|
|
1848
2024
|
// Already in the requested state, but the user still expressed intent:
|
|
1849
|
-
// record it so
|
|
2025
|
+
// record it so later sessions and processes do not fall back to the flag.
|
|
1850
2026
|
shared.runtimeOverrides.enabled = true;
|
|
2027
|
+
persistEnabledDecision(ctx, shared, true);
|
|
1851
2028
|
ctx.ui.notify(`Prompt autocomplete already enabled (${formatStatus(shared)})`, "info");
|
|
1852
2029
|
return;
|
|
1853
2030
|
}
|
|
1854
2031
|
|
|
1855
2032
|
if (enablePromptAutocomplete(ctx, shared)) {
|
|
2033
|
+
persistEnabledDecision(ctx, shared, true);
|
|
1856
2034
|
notifyPromptAutocompleteEnabled(ctx, shared, { includeModel: true });
|
|
1857
2035
|
}
|
|
1858
2036
|
},
|
|
1859
2037
|
off: () => {
|
|
1860
2038
|
if (!shared.enabled) {
|
|
1861
2039
|
shared.runtimeOverrides.enabled = false;
|
|
2040
|
+
persistEnabledDecision(ctx, shared, false);
|
|
1862
2041
|
ctx.ui.notify("Prompt autocomplete is already disabled", "info");
|
|
1863
2042
|
return;
|
|
1864
2043
|
}
|
|
1865
2044
|
|
|
1866
2045
|
disablePromptAutocomplete(ctx, shared);
|
|
2046
|
+
persistEnabledDecision(ctx, shared, false);
|
|
1867
2047
|
ctx.ui.notify("Prompt autocomplete disabled", "info");
|
|
1868
2048
|
},
|
|
1869
2049
|
toggle: () => {
|
|
1870
2050
|
if (shared.enabled) {
|
|
1871
2051
|
disablePromptAutocomplete(ctx, shared);
|
|
2052
|
+
persistEnabledDecision(ctx, shared, false);
|
|
1872
2053
|
ctx.ui.notify("Prompt autocomplete disabled", "info");
|
|
1873
2054
|
return;
|
|
1874
2055
|
}
|
|
1875
2056
|
|
|
1876
2057
|
if (enablePromptAutocomplete(ctx, shared)) {
|
|
2058
|
+
persistEnabledDecision(ctx, shared, true);
|
|
1877
2059
|
notifyPromptAutocompleteEnabled(ctx, shared, { includeModel: false });
|
|
1878
2060
|
}
|
|
1879
2061
|
},
|
|
@@ -1893,6 +2075,15 @@ export function createPromptAutocompleteExtension(
|
|
|
1893
2075
|
const now = dependencies.now ?? Date.now;
|
|
1894
2076
|
|
|
1895
2077
|
return function promptAutocompleteExtension(pi: ExtensionAPI): void {
|
|
2078
|
+
const settingsStore = dependencies.settingsStore ?? createFileSettingsStore(resolvePromptAutocompleteSettingsPath());
|
|
2079
|
+
let persistedSettings: PromptAutocompletePersistedSettings;
|
|
2080
|
+
try {
|
|
2081
|
+
persistedSettings = settingsStore.load();
|
|
2082
|
+
} catch {
|
|
2083
|
+
// A store that violates the load contract must not block activation.
|
|
2084
|
+
persistedSettings = {};
|
|
2085
|
+
}
|
|
2086
|
+
|
|
1896
2087
|
pi.registerFlag("prompt-autocomplete", {
|
|
1897
2088
|
description: "Enable inline AI prompt autocomplete in the editor",
|
|
1898
2089
|
type: "boolean",
|
|
@@ -1947,6 +2138,9 @@ export function createPromptAutocompleteExtension(
|
|
|
1947
2138
|
agentStreaming: false,
|
|
1948
2139
|
config: parseConfig(pi),
|
|
1949
2140
|
runtimeOverrides: {},
|
|
2141
|
+
persistedSettings,
|
|
2142
|
+
settingsStore,
|
|
2143
|
+
enabledFlagValue: false,
|
|
1950
2144
|
usageStats: createPromptAutocompleteUsageStats(),
|
|
1951
2145
|
completeSimple: completeSimpleImpl,
|
|
1952
2146
|
streamSimple: streamSimpleImpl,
|
|
@@ -2023,6 +2217,10 @@ export function createPromptAutocompleteExtension(
|
|
|
2023
2217
|
setStreamResponses(ctx, shared, parts[1]);
|
|
2024
2218
|
return;
|
|
2025
2219
|
}
|
|
2220
|
+
if (command === "min-chars") {
|
|
2221
|
+
setMinPromptChars(ctx, shared, parts[1]);
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2026
2224
|
|
|
2027
2225
|
const handlers = createPromptAutocompleteCommandHandlers(ctx, shared);
|
|
2028
2226
|
const handler = handlers[command];
|
|
@@ -2033,7 +2231,7 @@ export function createPromptAutocompleteExtension(
|
|
|
2033
2231
|
}
|
|
2034
2232
|
|
|
2035
2233
|
ctx.ui.notify(
|
|
2036
|
-
"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]",
|
|
2037
2235
|
"warning",
|
|
2038
2236
|
);
|
|
2039
2237
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kliebhan/pi-prompt-autocomplete",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
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"
|