proper-base 0.5.0 → 0.6.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/README.md CHANGED
@@ -20,6 +20,14 @@ and footer layout.
20
20
  keep their names.
21
21
  - `/clear` starts an empty session but restores the exact provider and model
22
22
  selected in the previous one. No messages, name, or branch state carry over.
23
+ - The model you pick in `/model` and the level you pick in `/thinking` become
24
+ Pi's startup defaults, so the next session opens on them. Pi otherwise saves
25
+ those only when you press Ctrl+S in the picker, and because Pi re-derives the
26
+ thinking level from the saved default on every model switch, an unsaved level
27
+ is otherwise lost mid-session at the next `/model`, Ctrl+P, or `/clear`.
28
+ Switching to a model that cannot reach the current level records the level
29
+ you actually get. Resuming a session does not redefine the model. Set
30
+ `"stickyDefaults": false` in `~/.pi/agent/proper-base.json` to turn this off.
23
31
  - Prompt-template expansions remain model-facing, while the transcript shows
24
32
  the slash command you typed, such as `/implement-ready epic-1 4`.
25
33
  - CLIProxyAPI `empty_stream` failures become normal retryable network errors, so
@@ -47,7 +55,9 @@ proper-base records eligible editor submissions on a best-effort basis, not
47
55
  transformed Pi session messages. History uses an encoded key derived from the
48
56
  current working directory.
49
57
 
50
- - Up and Down recall prompts from previous sessions in the same project.
58
+ - Up and Down recall prompts from previous sessions in the same project. Up
59
+ recalls only from an empty prompt; with a draft it only moves the cursor,
60
+ so Home then Up can no longer replace what you typed.
51
61
  - Ctrl+R starts case-sensitive reverse substring search. Press Ctrl+R again for
52
62
  an older match, Backspace or Shift+Backspace to broaden the query, Enter to
53
63
  submit, Esc to keep the match for editing, or Ctrl+G to restore the original
@@ -75,9 +85,18 @@ directory to forget all proper-base history.
75
85
  and URLs.
76
86
  - `/model ` results sort by displayed model ID in descending numeric-aware
77
87
  order. Typed terms must all match when strict matches exist.
78
- - Enter or Tab switches immediately only when the complete prompt is a
79
- single-line `/model ...` command. Inline and multiline slash segments only
80
- receive the completion. Tab keeps its normal behavior elsewhere.
88
+ - `/model` takes an optional thinking level after the model name, as in
89
+ `/model anthropic/claude-opus-4 high`. Once the model name carries a
90
+ provider slash, the next word completes against Pi's thinking levels; a
91
+ word naming no level keeps searching models.
92
+ - Tab-completing a model name submits nothing. It leaves the name, a
93
+ trailing space, and an open level menu led by the level already in
94
+ effect, so you can type a level straight away or press Enter to keep the
95
+ current one.
96
+ - Tab or Enter on a level completion switches immediately: the level is
97
+ the last argument, so `/model gp<Tab>lo<Tab>` picks the model and `low`
98
+ without a further Enter. Either key switches only when the complete
99
+ prompt is a single-line `/model ...` command.
81
100
 
82
101
  ### Fullscreen navigation and selection
83
102
 
@@ -97,18 +116,33 @@ pinned while Pi scrolls the transcript above them.
97
116
  | Home, End, PageUp, PageDown | Stay assigned to the prompt editor. |
98
117
  | Ctrl+Shift+Home or End | Jump the transcript to its top or bottom. |
99
118
  | Ctrl+Shift+PageUp or PageDown | Scroll the transcript by one page. |
119
+
120
+ Wheel and transcript scroll keys keep working while an `ask_user_question`
121
+ questionnaire or other overlay has focus, so earlier context stays reachable.
100
122
  | Double-click | Select a complete one-line URL, path, flag, qualified identifier, or quoted value when possible. |
101
123
 
102
124
  Scrolling away from current output adds a `↓ jump to bottom` row above the
103
125
  prompt. Clicking it returns to the newest output without disabling scrollbar
104
126
  dragging.
105
127
 
128
+ Extension widgets that Pi would pin above the prompt (for example the
129
+ pi-subagents async-agents card) render at the end of the transcript instead, so
130
+ they scroll with the session and shrink as their content does rather than
131
+ holding rows they no longer need.
132
+
106
133
  The transcript's top-right corner carries muted `↑` and `↓` arrows that walk
107
134
  the viewport between your own prompts. Clicking `↓` past the last prompt scrolls
108
135
  to the bottom. While you are scrolled up, a dimmer `position/total` reading sits
109
136
  centred under the arrows and counts the prompts in the session; it disappears
110
137
  once the viewport is following output again.
111
138
 
139
+ Pi 0.85.0 moves the prompt cursor to wherever you click in the prompt. If you
140
+ click the prompt area to focus the terminal or to select text, turn off
141
+ `Prompt mouse clicks` in `/settings`: clicks on the prompt text then leave the
142
+ cursor alone while drag-to-select keeps working. The same menu holds the
143
+ `Session action rail` toggle. Both persist in `~/.pi/agent/proper-base.json`
144
+ as `editorMouse` and `sessionRail`.
145
+
112
146
  ### Clipboard and model image context
113
147
 
114
148
  Ctrl+V and Ctrl+Shift+V both use Pi's image-or-text clipboard action. Readable
@@ -158,7 +192,7 @@ highlight. Custom replacement footers are not changed.
158
192
 
159
193
  ## Install
160
194
 
161
- Node 22.19 or newer is required. The package is tested against Pi 0.84.4.
195
+ Node 22.19 or newer is required. The package is tested against Pi 0.85.1.
162
196
 
163
197
  From npm:
164
198
 
package/index.ts CHANGED
@@ -23,10 +23,12 @@ import {
23
23
  installAutocompleteDetails,
24
24
  installInlineSlashAutocomplete,
25
25
  installModelAutocompleteSubmit,
26
+ modelThinkingCommand,
26
27
  sortModelAutocompleteDescending,
27
28
  } from "./src/autocomplete-details.ts";
28
29
  import { installClipboardLeakGuard } from "./src/clipboard-guard.ts";
29
30
  import { commitGuardReason } from "./src/commit-guard.ts";
31
+ import { installEditorMouseGuard } from "./src/editor-mouse.ts";
30
32
  import {
31
33
  installEditorNavigation,
32
34
  installPromptClear,
@@ -54,20 +56,26 @@ import {
54
56
  } from "./src/image-preview.ts";
55
57
  import { installJumpToBottom } from "./src/jump-to-bottom.ts";
56
58
  import { installOsc8LinkIds } from "./src/osc8-link-ids.ts";
59
+ import { installOverlayScroll } from "./src/overlay-scroll.ts";
60
+ import {
61
+ applyProactiveDelegation,
62
+ readProactiveDelegationEnabled,
63
+ } from "./src/proactive-delegation.ts";
57
64
  import {
58
65
  createPromptDisplay,
59
66
  PROMPT_DISPLAY_ENTRY,
60
67
  } from "./src/prompt-display.ts";
61
68
  import { installPromptJump } from "./src/prompt-jump.ts";
62
- import {
63
- installRailSetting,
64
- type RailSettingController,
65
- } from "./src/rail-setting.ts";
66
69
  import { installRecorder } from "./src/recorder.ts";
67
70
  import { installSelectionDismiss } from "./src/selection-dismiss.ts";
68
71
  import { installFastSessionList } from "./src/session-list.ts";
72
+ import { installSettings, type SettingsController } from "./src/settings.ts";
69
73
  import { pinSkillContext } from "./src/skill-context.ts";
70
74
  import { installSmartSelection } from "./src/smart-selection.ts";
75
+ import {
76
+ persistDefaultModel,
77
+ persistDefaultThinkingLevel,
78
+ } from "./src/startup-defaults.ts";
71
79
  import {
72
80
  appendPrompt,
73
81
  compactIfNeeded,
@@ -80,6 +88,7 @@ import {
80
88
  } from "./src/transcript-cleanup.ts";
81
89
  import { normalizeCpaTransientError } from "./src/transient-retry.ts";
82
90
  import { installWheelScrollLines } from "./src/wheel-scroll.ts";
91
+ import { installWidgetTranscript } from "./src/widget-transcript.ts";
83
92
 
84
93
  /** Prompts seeded into the editor. Older prompts past this point are dropped. */
85
94
  const MAX_ENTRIES = 200;
@@ -294,14 +303,17 @@ export default function (pi: ExtensionAPI) {
294
303
  let removeFooterColors: (() => void) | undefined;
295
304
  let removeJumpToBottom: (() => void) | undefined;
296
305
  let removePromptJump: (() => void) | undefined;
297
- let railSetting: RailSettingController | undefined;
306
+ let settings: SettingsController | undefined;
307
+ let removeEditorMouseGuard: (() => void) | undefined;
298
308
  let removePromptClear: (() => void) | undefined;
299
309
  let removeSmartSelection: (() => void) | undefined;
300
310
  let removeSelectionDismiss: (() => void) | undefined;
311
+ let removeOverlayScroll: (() => void) | undefined;
301
312
  let removeOsc8LinkIds: (() => void) | undefined;
302
313
  let imagePreview: ImagePreviewController | undefined;
303
314
  let removeTerminalInput: (() => void) | undefined;
304
315
  let transcriptCleanup: TranscriptCleanupController | undefined;
316
+ let removeWidgetTranscript: (() => void) | undefined;
305
317
  let activeEditor: PromptEditor | undefined;
306
318
  let activeTui: EditorTui | undefined;
307
319
  let submittedPrompt: string | undefined;
@@ -331,6 +343,43 @@ export default function (pi: ExtensionAPI) {
331
343
  );
332
344
  };
333
345
 
346
+ /**
347
+ * Run a `/model <reference> <level>` submission, if that is the shape.
348
+ *
349
+ * Pi reads a `/model` argument as one model search term, so a thinking level
350
+ * appended to it only widens that search and opens the picker. The command is
351
+ * taken over at the editor instead, and the level is applied after the model:
352
+ * every `setModel` recomputes the level from settings, so setting it first
353
+ * would be discarded. A reference matching no model is left to Pi, whose
354
+ * picker still opens on the raw text.
355
+ */
356
+ const applyModelThinking = (ctx: ExtensionContext, text: string): boolean => {
357
+ const request = modelThinkingCommand(text);
358
+ if (!request) return false;
359
+ const available =
360
+ ctx.scopedModels.length > 0
361
+ ? ctx.scopedModels.map((scoped) => scoped.model)
362
+ : ctx.modelRegistry.getAvailable();
363
+ const model = available.find(
364
+ (candidate) =>
365
+ `${candidate.provider}/${candidate.id}` === request.reference ||
366
+ candidate.id === request.reference,
367
+ );
368
+ if (!model) return false;
369
+ void (async () => {
370
+ if (!(await pi.setModel(model))) {
371
+ ctx.ui.notify(
372
+ `Could not switch to ${model.provider}/${model.id}`,
373
+ "error",
374
+ );
375
+ return;
376
+ }
377
+ pi.setThinkingLevel(request.level);
378
+ ctx.ui.notify(`Model: ${model.id} (thinking: ${request.level})`, "info");
379
+ })();
380
+ return true;
381
+ };
382
+
334
383
  pi.registerCommand?.(RESTORE_MODEL_COMMAND, {
335
384
  description: "Internal: restore the model after /clear",
336
385
  handler: async (args, ctx) => {
@@ -394,6 +443,20 @@ export default function (pi: ExtensionAPI) {
394
443
  },
395
444
  });
396
445
 
446
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Sticky startup defaults]]
447
+ pi.on("model_select", (event) => {
448
+ if (event.source === "restore") return;
449
+ persistDefaultModel(getAgentDir(), event.model);
450
+ });
451
+
452
+ pi.on("thinking_level_select", (event, ctx) => {
453
+ persistDefaultThinkingLevel(
454
+ getAgentDir(),
455
+ event.level,
456
+ ctx.model ?? undefined,
457
+ );
458
+ });
459
+
397
460
  pi.on("input", (event) => {
398
461
  if (event.source === "interactive") {
399
462
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Pinned transcript scrolling]]
@@ -455,6 +518,19 @@ export default function (pi: ExtensionAPI) {
455
518
  if (messages !== event.messages) return { messages };
456
519
  });
457
520
 
521
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Proactive delegation]]
522
+ pi.on("before_agent_start", (event, ctx) => {
523
+ if (!readProactiveDelegationEnabled(getAgentDir())) return;
524
+ const tools =
525
+ event.systemPromptOptions?.selectedTools ?? pi.getActiveTools?.() ?? [];
526
+ const systemPrompt = applyProactiveDelegation(
527
+ event.systemPrompt,
528
+ tools.includes("subagent"),
529
+ ctx.scopedModels.map((scoped) => scoped.model),
530
+ );
531
+ if (systemPrompt !== undefined) return { systemPrompt };
532
+ });
533
+
458
534
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Automatic session title]]
459
535
  pi.on("before_agent_start", (event) => {
460
536
  if (!sessionTitlePending || pi.getSessionName?.()) {
@@ -573,20 +649,26 @@ export default function (pi: ExtensionAPI) {
573
649
  removeJumpToBottom = undefined;
574
650
  removePromptJump?.();
575
651
  removePromptJump = undefined;
576
- railSetting?.dispose();
577
- railSetting = undefined;
652
+ settings?.dispose();
653
+ settings = undefined;
654
+ removeEditorMouseGuard?.();
655
+ removeEditorMouseGuard = undefined;
578
656
  removePromptClear?.();
579
657
  removePromptClear = undefined;
580
658
  removeSmartSelection?.();
581
659
  removeSmartSelection = undefined;
582
660
  removeSelectionDismiss?.();
583
661
  removeSelectionDismiss = undefined;
662
+ removeOverlayScroll?.();
663
+ removeOverlayScroll = undefined;
584
664
  removeOsc8LinkIds?.();
585
665
  removeOsc8LinkIds = undefined;
586
666
  imagePreview?.dispose();
587
667
  imagePreview = undefined;
588
668
  removeTerminalInput?.();
589
669
  removeTerminalInput = undefined;
670
+ removeWidgetTranscript?.();
671
+ removeWidgetTranscript = undefined;
590
672
  transcriptCleanup?.uninstall();
591
673
  transcriptCleanup = undefined;
592
674
  activeEditor = undefined;
@@ -642,7 +724,9 @@ export default function (pi: ExtensionAPI) {
642
724
  ctx.ui.setEditorText(promptText);
643
725
  return undefined;
644
726
  });
645
- ctx.ui.addAutocompleteProvider?.(sortModelAutocompleteDescending);
727
+ ctx.ui.addAutocompleteProvider?.((current) =>
728
+ sortModelAutocompleteDescending(current, () => pi.getThinkingLevel?.()),
729
+ );
646
730
 
647
731
  const store = storePath(getAgentDir(), ctx.cwd);
648
732
  compactIfNeeded(store);
@@ -687,6 +771,9 @@ export default function (pi: ExtensionAPI) {
687
771
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Settled transcript]]
688
772
  transcriptCleanup?.uninstall();
689
773
  transcriptCleanup = installTranscriptCleanup(tui, ctx);
774
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Transcript widgets]]
775
+ removeWidgetTranscript?.();
776
+ removeWidgetTranscript = installWidgetTranscript(tui, editor);
690
777
  removeSmartSelection?.();
691
778
  removeSmartSelection = installSmartSelection(tui);
692
779
  removeSelectionDismiss?.();
@@ -697,6 +784,9 @@ export default function (pi: ExtensionAPI) {
697
784
  .getKeys("app.message.copy")
698
785
  .some((key) => matchesKey(data, key)),
699
786
  );
787
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Overlay transcript scrolling]]
788
+ removeOverlayScroll?.();
789
+ removeOverlayScroll = installOverlayScroll(tui);
700
790
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Hyperlink identity]]
701
791
  removeOsc8LinkIds?.();
702
792
  removeOsc8LinkIds = installOsc8LinkIds(tui);
@@ -704,14 +794,20 @@ export default function (pi: ExtensionAPI) {
704
794
  removeJumpToBottom?.();
705
795
  removeJumpToBottom = installJumpToBottom(editor, tui);
706
796
  removePromptJump?.();
707
- railSetting?.dispose();
708
- railSetting = installRailSetting(tui, editor, getAgentDir());
797
+ settings?.dispose();
798
+ settings = installSettings(tui, editor, getAgentDir());
799
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Prompt mouse clicks]]
800
+ removeEditorMouseGuard?.();
801
+ removeEditorMouseGuard = installEditorMouseGuard(
802
+ editor,
803
+ () => settings?.editorMouse() !== false,
804
+ );
709
805
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Session action rail]]
710
806
  removePromptJump = installPromptJump(tui, {
711
807
  color: (value) => ctx.ui.theme.fg("muted", value),
712
808
  subtle: (value) => ctx.ui.theme.fg("dim", value),
713
809
  outline: () =>
714
- railSetting?.enabled() !== false
810
+ settings?.enabled() !== false
715
811
  ? (transcriptCleanup?.outline() ?? [])
716
812
  : [],
717
813
  });
@@ -730,15 +826,19 @@ export default function (pi: ExtensionAPI) {
730
826
  // provider's global `/fast` can only be repurposed as a session
731
827
  // toggle by consuming it at the editor before pi ever parses it.
732
828
  (text) => {
733
- if (!isFastToggle(text)) return false;
734
- const notice = fastToggleNotice({
735
- scope: "session",
736
- enabled: fastOverlay.toggleSession(),
737
- otherEnabled: fastOverlay.isGlobalEnabled(),
738
- modelSupported: fastOverlay.supportsModel(ctx.model ?? undefined),
739
- });
740
- ctx.ui.notify(notice.message, notice.level);
741
- return true;
829
+ if (isFastToggle(text)) {
830
+ const notice = fastToggleNotice({
831
+ scope: "session",
832
+ enabled: fastOverlay.toggleSession(),
833
+ otherEnabled: fastOverlay.isGlobalEnabled(),
834
+ modelSupported: fastOverlay.supportsModel(ctx.model ?? undefined),
835
+ });
836
+ ctx.ui.notify(notice.message, notice.level);
837
+ tui.requestRender();
838
+ return true;
839
+ }
840
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Model thinking argument]]
841
+ return applyModelThinking(ctx, text);
742
842
  },
743
843
  );
744
844
  installModelAutocompleteSubmit(editor, keybindings);
@@ -753,7 +853,9 @@ export default function (pi: ExtensionAPI) {
753
853
  );
754
854
  installAutocompleteDetails(editor, tui, theme);
755
855
  removeFooterColors?.();
756
- removeFooterColors = installFooterColors(tui, ctx);
856
+ removeFooterColors = installFooterColors(tui, ctx, () =>
857
+ fastOverlay.isEffectiveFor(ctx.model ?? undefined),
858
+ );
757
859
  for (const prompt of seeded) historyGuard?.add(prompt);
758
860
  return editor;
759
861
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proper-base",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Baseline Pi behavior for session naming, history, prompt editing, fullscreen navigation, and footer styling",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -53,8 +53,8 @@
53
53
  "@earendil-works/pi-tui": "*"
54
54
  },
55
55
  "devDependencies": {
56
- "@earendil-works/pi-coding-agent": "0.84.4",
57
- "@earendil-works/pi-tui": "0.84.4",
56
+ "@earendil-works/pi-coding-agent": "0.85.1",
57
+ "@earendil-works/pi-tui": "0.85.1",
58
58
  "@types/node": "25.9.5",
59
59
  "typescript": "6.0.2"
60
60
  },
@@ -64,6 +64,6 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "sharp": "0.35.3"
67
+ "sharp": "0.35.4"
68
68
  }
69
69
  }
@@ -1,5 +1,7 @@
1
1
  import {
2
+ type AutocompleteItem,
2
3
  type AutocompleteProvider,
4
+ type AutocompleteSuggestions,
3
5
  type Component,
4
6
  type OverlayHandle,
5
7
  type OverlayMargin,
@@ -29,6 +31,67 @@ const MODEL_ORDER = new Intl.Collator("en", {
29
31
  sensitivity: "base",
30
32
  });
31
33
 
34
+ /**
35
+ * Pi's thinking levels, weakest first. The extension API exports neither the
36
+ * list nor the per-model subset, and Pi clamps an unsupported level when it
37
+ * applies one, so restating the full list here costs nothing.
38
+ */
39
+ const THINKING_LEVELS = [
40
+ "off",
41
+ "minimal",
42
+ "low",
43
+ "medium",
44
+ "high",
45
+ "xhigh",
46
+ "max",
47
+ ] as const;
48
+
49
+ export type ThinkingArgument = (typeof THINKING_LEVELS)[number];
50
+
51
+ /**
52
+ * `/model <provider>/<id> <level>` before the cursor.
53
+ *
54
+ * The first argument must carry a provider slash, the exact shape a model
55
+ * completion produces, so a multi-term model search such as `/model opus 4`
56
+ * keeps filtering models instead of being read as a level.
57
+ */
58
+ const MODEL_THINKING_ARGUMENT = /^\/model\s+(\S*\/\S*)\s+(\S*)$/;
59
+
60
+ /** Level suggestions for a second `/model` argument, or nothing for any other shape. */
61
+ function thinkingSuggestions(
62
+ activeLine: string,
63
+ current: string | undefined,
64
+ ): AutocompleteSuggestions | undefined {
65
+ const prefix = MODEL_THINKING_ARGUMENT.exec(activeLine)?.[2];
66
+ if (prefix === undefined) return undefined;
67
+ const query = prefix.toLowerCase();
68
+ const matches = THINKING_LEVELS.filter((level) => level.startsWith(query));
69
+ // The level already in effect leads the list, so accepting the menu's
70
+ // default selection keeps the current level instead of the weakest one.
71
+ const items: AutocompleteItem[] = [
72
+ ...matches.filter((level) => level === current),
73
+ ...matches.filter((level) => level !== current),
74
+ ].map((level) => ({ value: level, label: level }));
75
+ return items.length > 0 ? { items, prefix } : undefined;
76
+ }
77
+
78
+ /**
79
+ * A submitted `/model <reference> <level>`, if that is the shape.
80
+ *
81
+ * Pi's own `/model` treats everything after the command as one model search
82
+ * term, so the extra argument has to be split off before Pi ever sees it.
83
+ */
84
+ export function modelThinkingCommand(
85
+ text: string,
86
+ ): { reference: string; level: ThinkingArgument } | undefined {
87
+ const match = /^\/model\s+(\S+)\s+(\S+)$/.exec(text.trim());
88
+ const reference = match?.[1];
89
+ const level = THINKING_LEVELS.find(
90
+ (candidate) => candidate === match?.[2]?.toLowerCase(),
91
+ );
92
+ return reference && level ? { reference, level } : undefined;
93
+ }
94
+
32
95
  type AutocompleteEditor = Component & {
33
96
  autocompleteList?: {
34
97
  getSelectedItem(): { description?: string } | null;
@@ -55,7 +118,7 @@ type ModelAutocompleteEditor = Component & {
55
118
  };
56
119
  getText?(): string;
57
120
  handleInput?(data: string): void;
58
- submitValue?(): void;
121
+ tryTriggerAutocomplete?(): void;
59
122
  [MODEL_SUBMIT_INSTALLED]?: boolean;
60
123
  };
61
124
 
@@ -201,6 +264,7 @@ function createAutocompleteDetailBox(theme: DetailTheme) {
201
264
 
202
265
  export function sortModelAutocompleteDescending(
203
266
  current: AutocompleteProvider,
267
+ thinkingLevel?: () => string | undefined,
204
268
  ): AutocompleteProvider {
205
269
  return {
206
270
  ...(current.triggerCharacters
@@ -208,6 +272,13 @@ export function sortModelAutocompleteDescending(
208
272
  : {}),
209
273
  async getSuggestions(lines, cursorLine, cursorCol, options) {
210
274
  const inline = inlineSlashContext(lines, cursorLine, cursorCol);
275
+ const activeLine =
276
+ inline?.prefix ?? (lines[cursorLine] ?? "").slice(0, cursorCol);
277
+ // Checked before delegating so an explicit Tab, which asks Pi for
278
+ // forced file completion once the argument holds a space, still lists
279
+ // levels rather than paths.
280
+ const thinking = thinkingSuggestions(activeLine, thinkingLevel?.());
281
+ if (thinking) return thinking;
211
282
  const requestLines = inline ? [...lines] : lines;
212
283
  if (inline) requestLines[cursorLine] = inline.prefix;
213
284
  const suggestions = await current.getSuggestions(
@@ -216,8 +287,6 @@ export function sortModelAutocompleteDescending(
216
287
  inline ? inline.prefix.length : cursorCol,
217
288
  inline ? { ...options, force: false } : options,
218
289
  );
219
- const line = lines[cursorLine] ?? "";
220
- const activeLine = inline?.prefix ?? line.slice(0, cursorCol);
221
290
  if (!suggestions || !activeLine.startsWith("/model ")) {
222
291
  return suggestions;
223
292
  }
@@ -285,6 +354,13 @@ export function sortModelAutocompleteDescending(
285
354
  };
286
355
  }
287
356
 
357
+ /** Whether an accepted completion left a runnable `/model` command behind. */
358
+ function completedModelCommand(text: string, value: string): boolean {
359
+ if (!/^\/model [^\n]*$/.test(text)) return false;
360
+ const argument = text.slice("/model ".length);
361
+ return argument === value || argument.endsWith(` ${value}`);
362
+ }
363
+
288
364
  export function installModelAutocompleteSubmit(
289
365
  editor: Component,
290
366
  keybindings: EditorKeybindings,
@@ -299,28 +375,47 @@ export function installModelAutocompleteSubmit(
299
375
  }
300
376
 
301
377
  const handleInput = target.handleInput.bind(target);
378
+ const openThinkingMenu = () => {
379
+ if (
380
+ target.autocompleteList === undefined &&
381
+ MODEL_THINKING_ARGUMENT.test(target.getText?.() ?? "")
382
+ ) {
383
+ target.tryTriggerAutocomplete?.();
384
+ }
385
+ };
302
386
  target.handleInput = (data: string) => {
303
- const selected = target.autocompleteList?.getSelectedItem();
304
- const selectedValue = selected?.value;
387
+ const selectedValue = target.autocompleteList?.getSelectedItem()?.value;
388
+ const accepted =
389
+ typeof selectedValue === "string" &&
390
+ /^\/model [^\n]*$/.test(target.getText?.() ?? "")
391
+ ? selectedValue
392
+ : undefined;
305
393
  const confirm = keybindings.matches(data, "tui.select.confirm");
306
394
  const tab = keybindings.matches(data, "tui.input.tab");
307
- const shouldSubmit =
308
- (confirm || tab) &&
309
- typeof selectedValue === "string" &&
310
- /^\/model [^\n]*$/.test(target.getText?.() ?? "");
311
395
 
312
396
  handleInput(data);
397
+ // Pi reopens suggestions only from typed characters, and the separator
398
+ // before a thinking level is a space, which is not one of them.
399
+ if (data === " ") {
400
+ openThinkingMenu();
401
+ return;
402
+ }
313
403
  if (
314
- shouldSubmit &&
315
- target.autocompleteList === undefined &&
316
- target.getText?.() === `/model ${selectedValue}`
404
+ accepted === undefined ||
405
+ target.autocompleteList !== undefined ||
406
+ !completedModelCommand(target.getText?.() ?? "", accepted)
317
407
  ) {
318
- if (tab) {
319
- if (target.submitValue) target.submitValue();
320
- else handleInput("\r");
321
- } else {
322
- handleInput(data);
323
- }
408
+ return;
409
+ }
410
+ // Tab stops at the model name so a level can follow, and Pi's argument
411
+ // completion appends no separator, so the space and the menu it cannot
412
+ // trigger on its own are supplied here. Tab on the level itself has
413
+ // nothing left to complete, so it submits like Enter.
414
+ if (tab && accepted.includes("/")) {
415
+ handleInput(" ");
416
+ openThinkingMenu();
417
+ } else if (confirm || tab) {
418
+ handleInput("\r");
324
419
  }
325
420
  };
326
421
  target[MODEL_SUBMIT_INSTALLED] = true;
@@ -0,0 +1,69 @@
1
+ import type {
2
+ Component,
3
+ TuiMouseEvent,
4
+ TuiMouseEventResult,
5
+ } from "@earendil-works/pi-tui";
6
+
7
+ const INSTALLED = Symbol.for("pi-proper-base.editor-mouse");
8
+
9
+ type MouseHandler = (event: TuiMouseEvent) => TuiMouseEventResult | undefined;
10
+ type MouseEditor = Component & {
11
+ handleMouse?: MouseHandler;
12
+ renderedVisibleLineCount?: number;
13
+ [INSTALLED]?: () => void;
14
+ };
15
+
16
+ /**
17
+ * Keep prompt clicks from moving the editor cursor while the setting is off.
18
+ *
19
+ * Since Pi 0.85.0 the fullscreen renderer routes mouse input through
20
+ * component `handleMouse` methods, and the editor's own handler turns a left
21
+ * click on a prompt row into a cursor move. That is the wrong default for
22
+ * anyone who clicks the prompt area to focus the terminal or to select text:
23
+ * the cursor jumps away from where typing left it. This wraps the editor
24
+ * instance's `handleMouse` and, while `enabled()` is false, swallows left
25
+ * clicks that land on the prompt's text rows. The event is still reported
26
+ * handled so the click neither falls through to the renderer's selection
27
+ * path nor moves focus, and the drag-to-select gesture is untouched because
28
+ * the editor already leaves press, drag, and release to the renderer.
29
+ *
30
+ * Clicks on the autocomplete rows below the prompt, and on the border rows,
31
+ * keep Pi's native behavior: the guard only covers the text rows Pi itself
32
+ * bounds with `renderedVisibleLineCount`. Editors without a `handleMouse`
33
+ * (Pi before 0.85.0, or a renderer without mouse dispatch) install nothing.
34
+ *
35
+ * @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Prompt mouse clicks]]
36
+ */
37
+ export function installEditorMouseGuard(
38
+ editor: Component,
39
+ enabled: () => boolean,
40
+ ): (() => void) | undefined {
41
+ const target = editor as MouseEditor;
42
+ target[INSTALLED]?.();
43
+ if (typeof target.handleMouse !== "function") return undefined;
44
+
45
+ const hadOwnMethod = Object.hasOwn(target, "handleMouse");
46
+ const original = target.handleMouse;
47
+ const wrapped: MouseHandler = function (this: MouseEditor, event) {
48
+ if (
49
+ !enabled() &&
50
+ event.type === "click" &&
51
+ event.button === "left" &&
52
+ event.y > 0 &&
53
+ event.y <= (target.renderedVisibleLineCount ?? 0)
54
+ ) {
55
+ return { handled: true };
56
+ }
57
+ return original.call(this, event);
58
+ };
59
+ target.handleMouse = wrapped;
60
+
61
+ const dispose = () => {
62
+ if (target.handleMouse !== wrapped) return;
63
+ if (hadOwnMethod) target.handleMouse = original;
64
+ else delete target.handleMouse;
65
+ delete target[INSTALLED];
66
+ };
67
+ target[INSTALLED] = dispose;
68
+ return dispose;
69
+ }