proper-base 0.6.0 → 0.8.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 +270 -46
- package/UPDATES.md +129 -0
- package/index.ts +265 -136
- package/package.json +4 -3
- package/src/auto-update/availability.ts +132 -0
- package/src/auto-update/index.ts +403 -0
- package/src/auto-update/inventory.mjs +96 -0
- package/src/auto-update/readiness.ts +94 -0
- package/src/auto-update/runtime.ts +268 -0
- package/src/auto-update/settings.ts +146 -0
- package/src/autocomplete-details.ts +1 -1
- package/src/base-keybindings.ts +114 -0
- package/src/clipboard-selection.ts +310 -0
- package/src/context-tokens.ts +340 -0
- package/src/fast-mode.ts +74 -13
- package/src/footer-colors.ts +56 -3
- package/src/host-interop.ts +49 -0
- package/src/image-preview.ts +75 -66
- package/src/proactive-delegation.ts +47 -17
- package/src/prompt-display-host.ts +166 -0
- package/src/prompt-display.ts +44 -82
- package/src/prompt-sections.ts +16 -0
- package/src/session-list.ts +132 -21
- package/src/settings.ts +94 -30
- package/src/skill-context.ts +238 -159
- package/src/skills.ts +587 -0
- package/src/startup-defaults.ts +4 -122
- package/src/sticky-defaults.ts +199 -0
- package/src/transcript-cleanup.ts +8 -2
- package/src/wheel-scroll.ts +24 -27
package/index.ts
CHANGED
|
@@ -15,19 +15,34 @@ import {
|
|
|
15
15
|
type ExtensionAPI,
|
|
16
16
|
type ExtensionContext,
|
|
17
17
|
getAgentDir,
|
|
18
|
+
type MarkdownTransformer,
|
|
18
19
|
SessionManager,
|
|
19
20
|
} from "@earendil-works/pi-coding-agent";
|
|
20
21
|
import { matchesKey } from "@earendil-works/pi-tui";
|
|
21
|
-
|
|
22
|
+
import { registerAutoUpdates } from "./src/auto-update/index.ts";
|
|
22
23
|
import {
|
|
23
24
|
installAutocompleteDetails,
|
|
24
25
|
installInlineSlashAutocomplete,
|
|
25
26
|
installModelAutocompleteSubmit,
|
|
26
27
|
modelThinkingCommand,
|
|
27
28
|
sortModelAutocompleteDescending,
|
|
29
|
+
THINKING_LEVELS,
|
|
28
30
|
} from "./src/autocomplete-details.ts";
|
|
31
|
+
import { installBaseKeybindings } from "./src/base-keybindings.ts";
|
|
29
32
|
import { installClipboardLeakGuard } from "./src/clipboard-guard.ts";
|
|
33
|
+
import { installClipboardSelection } from "./src/clipboard-selection.ts";
|
|
30
34
|
import { commitGuardReason } from "./src/commit-guard.ts";
|
|
35
|
+
import {
|
|
36
|
+
asTokensSession,
|
|
37
|
+
CONTEXT_TOKENS_ENTRY,
|
|
38
|
+
ContextTokens,
|
|
39
|
+
type ContextTokensMode,
|
|
40
|
+
installTokensScopeCompletion,
|
|
41
|
+
parseTokensArgs,
|
|
42
|
+
TOKENS_USAGE,
|
|
43
|
+
tokensArgumentCompletions,
|
|
44
|
+
tokensNotice,
|
|
45
|
+
} from "./src/context-tokens.ts";
|
|
31
46
|
import { installEditorMouseGuard } from "./src/editor-mouse.ts";
|
|
32
47
|
import {
|
|
33
48
|
installEditorNavigation,
|
|
@@ -65,17 +80,17 @@ import {
|
|
|
65
80
|
createPromptDisplay,
|
|
66
81
|
PROMPT_DISPLAY_ENTRY,
|
|
67
82
|
} from "./src/prompt-display.ts";
|
|
83
|
+
import { installPromptDisplayHost } from "./src/prompt-display-host.ts";
|
|
68
84
|
import { installPromptJump } from "./src/prompt-jump.ts";
|
|
85
|
+
import { appendPromptSection } from "./src/prompt-sections.ts";
|
|
69
86
|
import { installRecorder } from "./src/recorder.ts";
|
|
70
87
|
import { installSelectionDismiss } from "./src/selection-dismiss.ts";
|
|
71
88
|
import { installFastSessionList } from "./src/session-list.ts";
|
|
72
89
|
import { installSettings, type SettingsController } from "./src/settings.ts";
|
|
73
|
-
import {
|
|
90
|
+
import { registerSkillContext } from "./src/skills.ts";
|
|
74
91
|
import { installSmartSelection } from "./src/smart-selection.ts";
|
|
75
|
-
import {
|
|
76
|
-
|
|
77
|
-
persistDefaultThinkingLevel,
|
|
78
|
-
} from "./src/startup-defaults.ts";
|
|
92
|
+
import { stickyDefaultsEnabled } from "./src/startup-defaults.ts";
|
|
93
|
+
import { installStickyDefaultsAdapter } from "./src/sticky-defaults.ts";
|
|
79
94
|
import {
|
|
80
95
|
appendPrompt,
|
|
81
96
|
compactIfNeeded,
|
|
@@ -105,76 +120,6 @@ type EditorFactory = NonNullable<
|
|
|
105
120
|
>;
|
|
106
121
|
|
|
107
122
|
type TaggedFactory = EditorFactory & { [WRAPPED]?: EditorFactory | null };
|
|
108
|
-
type EditorKeybindings = Parameters<EditorFactory>[2];
|
|
109
|
-
|
|
110
|
-
const FULLSCREEN_KEYBINDINGS = Symbol.for(
|
|
111
|
-
"pi-proper-base.fullscreen-keybindings",
|
|
112
|
-
);
|
|
113
|
-
const LEGACY_FULLSCREEN_KEYBINDINGS = Symbol.for(
|
|
114
|
-
"pi-proper-customs.fullscreen-keybindings",
|
|
115
|
-
);
|
|
116
|
-
const FULLSCREEN_KEYS = {
|
|
117
|
-
"tui.altScreen.pageUp": "ctrl+shift+pageUp",
|
|
118
|
-
"tui.altScreen.pageDown": "ctrl+shift+pageDown",
|
|
119
|
-
"tui.altScreen.top": "ctrl+shift+home",
|
|
120
|
-
"tui.altScreen.bottom": "ctrl+shift+end",
|
|
121
|
-
} as const;
|
|
122
|
-
|
|
123
|
-
type KeybindingController = { apply(): void };
|
|
124
|
-
type PatchedKeybindings = EditorKeybindings & {
|
|
125
|
-
[FULLSCREEN_KEYBINDINGS]?: true | KeybindingController;
|
|
126
|
-
[LEGACY_FULLSCREEN_KEYBINDINGS]?: true | KeybindingController;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
function installKeybindings(keybindings: EditorKeybindings): void {
|
|
130
|
-
const patched = keybindings as PatchedKeybindings;
|
|
131
|
-
const apply = () => {
|
|
132
|
-
const imagePasteKeys = [
|
|
133
|
-
...new Set([
|
|
134
|
-
...keybindings.getKeys("app.clipboard.pasteImage"),
|
|
135
|
-
"ctrl+v" as const,
|
|
136
|
-
"ctrl+shift+v" as const,
|
|
137
|
-
]),
|
|
138
|
-
];
|
|
139
|
-
// Shift+Enter is already Pi's `tui.input.newLine` default; only Alt+Enter
|
|
140
|
-
// needs adding, and only because it must leave `app.message.followUp`.
|
|
141
|
-
const newLineKeys = [
|
|
142
|
-
...new Set([
|
|
143
|
-
...keybindings.getKeys("tui.input.newLine"),
|
|
144
|
-
"alt+enter" as const,
|
|
145
|
-
]),
|
|
146
|
-
];
|
|
147
|
-
const followUpKeys = keybindings
|
|
148
|
-
.getKeys("app.message.followUp")
|
|
149
|
-
.filter((key) => key !== "alt+enter");
|
|
150
|
-
keybindings.setUserBindings({
|
|
151
|
-
...keybindings.getUserBindings(),
|
|
152
|
-
...FULLSCREEN_KEYS,
|
|
153
|
-
"app.clipboard.pasteImage": imagePasteKeys,
|
|
154
|
-
"tui.input.newLine": newLineKeys,
|
|
155
|
-
"app.message.followUp": followUpKeys,
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
const existing =
|
|
159
|
-
patched[FULLSCREEN_KEYBINDINGS] ?? patched[LEGACY_FULLSCREEN_KEYBINDINGS];
|
|
160
|
-
if (existing && existing !== true) {
|
|
161
|
-
existing.apply = apply;
|
|
162
|
-
patched[FULLSCREEN_KEYBINDINGS] = existing;
|
|
163
|
-
delete patched[LEGACY_FULLSCREEN_KEYBINDINGS];
|
|
164
|
-
existing.apply();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const reload = keybindings.reload.bind(keybindings);
|
|
169
|
-
const controller: KeybindingController = { apply };
|
|
170
|
-
keybindings.reload = () => {
|
|
171
|
-
reload();
|
|
172
|
-
controller.apply();
|
|
173
|
-
};
|
|
174
|
-
patched[FULLSCREEN_KEYBINDINGS] = controller;
|
|
175
|
-
delete patched[LEGACY_FULLSCREEN_KEYBINDINGS];
|
|
176
|
-
controller.apply();
|
|
177
|
-
}
|
|
178
123
|
|
|
179
124
|
type EditorTui = Parameters<EditorFactory>[0] & {
|
|
180
125
|
scrollToBottom?(): void;
|
|
@@ -236,30 +181,44 @@ function extractSessionTitle(text: string): string | undefined {
|
|
|
236
181
|
);
|
|
237
182
|
}
|
|
238
183
|
|
|
239
|
-
type
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
184
|
+
type ClearSettings = {
|
|
185
|
+
provider: string;
|
|
186
|
+
id: string;
|
|
187
|
+
thinkingLevel: ReturnType<ExtensionAPI["getThinkingLevel"]>;
|
|
188
|
+
sessionFast: boolean;
|
|
189
|
+
contextTokens?: ContextTokensMode | undefined;
|
|
190
|
+
};
|
|
246
191
|
|
|
247
|
-
function
|
|
192
|
+
function decodeClearSettings(value: string): ClearSettings | undefined {
|
|
248
193
|
try {
|
|
249
194
|
const parsed = JSON.parse(
|
|
250
195
|
decodeURIComponent(value.trim()),
|
|
251
|
-
) as Partial<
|
|
196
|
+
) as Partial<ClearSettings> | null;
|
|
252
197
|
if (
|
|
253
198
|
!parsed ||
|
|
254
199
|
typeof parsed.provider !== "string" ||
|
|
255
200
|
!parsed.provider ||
|
|
256
201
|
typeof parsed.id !== "string" ||
|
|
257
|
-
!parsed.id
|
|
202
|
+
!parsed.id ||
|
|
203
|
+
!parsed.thinkingLevel ||
|
|
204
|
+
!THINKING_LEVELS.includes(parsed.thinkingLevel) ||
|
|
205
|
+
typeof parsed.sessionFast !== "boolean" ||
|
|
206
|
+
(parsed.contextTokens !== undefined &&
|
|
207
|
+
parsed.contextTokens !== "max" &&
|
|
208
|
+
parsed.contextTokens !== "default")
|
|
258
209
|
)
|
|
259
210
|
return undefined;
|
|
260
|
-
return {
|
|
261
|
-
|
|
262
|
-
|
|
211
|
+
return {
|
|
212
|
+
provider: parsed.provider,
|
|
213
|
+
id: parsed.id,
|
|
214
|
+
thinkingLevel: parsed.thinkingLevel,
|
|
215
|
+
sessionFast: parsed.sessionFast,
|
|
216
|
+
contextTokens: parsed.contextTokens,
|
|
217
|
+
};
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (error instanceof URIError || error instanceof SyntaxError)
|
|
220
|
+
return undefined;
|
|
221
|
+
throw error;
|
|
263
222
|
}
|
|
264
223
|
}
|
|
265
224
|
|
|
@@ -268,7 +227,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
268
227
|
installClipboardLeakGuard();
|
|
269
228
|
enableScribeCapabilities();
|
|
270
229
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Session listing]]
|
|
271
|
-
installFastSessionList(
|
|
230
|
+
const removeFastSessionList = installFastSessionList(
|
|
231
|
+
SessionManager,
|
|
232
|
+
getAgentDir(),
|
|
233
|
+
);
|
|
234
|
+
const stickyDefaults = installStickyDefaultsAdapter(() =>
|
|
235
|
+
stickyDefaultsEnabled(getAgentDir()),
|
|
236
|
+
);
|
|
237
|
+
const skills = registerSkillContext(pi, getAgentDir(), (ctx) =>
|
|
238
|
+
stickyDefaults.session(ctx.sessionManager),
|
|
239
|
+
);
|
|
272
240
|
|
|
273
241
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Fast tier scopes]]
|
|
274
242
|
const fastOverlay = new FastOverlay(getAgentDir());
|
|
@@ -282,6 +250,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
282
250
|
ctx.ui.notify("Usage: /fast-global", "error");
|
|
283
251
|
return;
|
|
284
252
|
}
|
|
253
|
+
const environmentOverride = fastOverlay.globalEnvironmentOverride();
|
|
254
|
+
if (environmentOverride !== undefined) {
|
|
255
|
+
ctx.ui.notify(
|
|
256
|
+
`Cannot toggle global Fast mode while CLIPROXYAPI_FAST=${environmentOverride ? "true" : "false"} overrides the saved setting.`,
|
|
257
|
+
"warning",
|
|
258
|
+
);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
285
261
|
let enabled: boolean;
|
|
286
262
|
try {
|
|
287
263
|
enabled = fastOverlay.toggleGlobal();
|
|
@@ -300,13 +276,113 @@ export default function (pi: ExtensionAPI) {
|
|
|
300
276
|
},
|
|
301
277
|
});
|
|
302
278
|
|
|
279
|
+
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Context window scopes]]
|
|
280
|
+
const tokenWindows = new ContextTokens(getAgentDir(), () =>
|
|
281
|
+
fastOverlay.providerId(),
|
|
282
|
+
);
|
|
283
|
+
const applyContextTokens = (ctx: ExtensionContext) => {
|
|
284
|
+
const session = asTokensSession(stickyDefaults.session(ctx.sessionManager));
|
|
285
|
+
if (!session) return undefined;
|
|
286
|
+
const applied = tokenWindows.apply(session, ctx.modelRegistry);
|
|
287
|
+
activeTui?.requestRender();
|
|
288
|
+
return applied && { session, ...applied };
|
|
289
|
+
};
|
|
290
|
+
pi.registerCommand?.("tokens", {
|
|
291
|
+
description:
|
|
292
|
+
"Show or set the OpenAI context window: /tokens [max|default] [global]",
|
|
293
|
+
getArgumentCompletions: tokensArgumentCompletions,
|
|
294
|
+
handler: async (args, ctx) => {
|
|
295
|
+
const request = parseTokensArgs(args);
|
|
296
|
+
if (!request) {
|
|
297
|
+
ctx.ui.notify(TOKENS_USAGE, "error");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!asTokensSession(stickyDefaults.session(ctx.sessionManager))) {
|
|
301
|
+
ctx.ui.notify(
|
|
302
|
+
"/tokens is unavailable: this Pi version does not expose the live session model.",
|
|
303
|
+
"error",
|
|
304
|
+
);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const { mode, global } = request;
|
|
308
|
+
if (mode && global) {
|
|
309
|
+
try {
|
|
310
|
+
tokenWindows.setGlobalMode(mode);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
const message =
|
|
313
|
+
error instanceof Error ? error.message : String(error);
|
|
314
|
+
ctx.ui.notify(`Failed to save context window: ${message}`, "error");
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
// This session drops its own choice and follows the new global one.
|
|
318
|
+
if (tokenWindows.sessionMode(ctx.sessionManager.getBranch())) {
|
|
319
|
+
pi.appendEntry(CONTEXT_TOKENS_ENTRY, { mode: null });
|
|
320
|
+
}
|
|
321
|
+
} else if (mode) {
|
|
322
|
+
pi.appendEntry(CONTEXT_TOKENS_ENTRY, { mode });
|
|
323
|
+
}
|
|
324
|
+
const modelId = ctx.model?.id ?? "No model";
|
|
325
|
+
const applied = applyContextTokens(ctx);
|
|
326
|
+
if (!applied) {
|
|
327
|
+
const saved = mode
|
|
328
|
+
? `Context window ${mode} saved ${global ? "for all sessions" : "for this session"}, but `
|
|
329
|
+
: "";
|
|
330
|
+
ctx.ui.notify(
|
|
331
|
+
`${saved}${modelId} has no larger window: /tokens applies to OpenAI models on openai, openai-codex, and CLIProxyAPI whose maximum exceeds the default.`,
|
|
332
|
+
mode ? "warning" : "info",
|
|
333
|
+
);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const branch = ctx.sessionManager.getBranch();
|
|
337
|
+
const sessionMode = tokenWindows.sessionMode(branch);
|
|
338
|
+
const globalMode = tokenWindows.globalMode();
|
|
339
|
+
const notice = tokensNotice({
|
|
340
|
+
modelId,
|
|
341
|
+
mode:
|
|
342
|
+
mode ??
|
|
343
|
+
(sessionMode
|
|
344
|
+
? `${sessionMode}, set for this session`
|
|
345
|
+
: globalMode
|
|
346
|
+
? `${globalMode}, set globally`
|
|
347
|
+
: "default"),
|
|
348
|
+
scope: mode ? (global ? "global" : "session") : "status",
|
|
349
|
+
window: applied.window,
|
|
350
|
+
limits: applied.limits,
|
|
351
|
+
compaction: applied.session.settingsManager.getCompactionSettings(
|
|
352
|
+
applied.session.agent.state.model,
|
|
353
|
+
),
|
|
354
|
+
contextTokens: ctx.getContextUsage()?.tokens,
|
|
355
|
+
});
|
|
356
|
+
ctx.ui.notify(notice.message, notice.level);
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
// Pi reads the session model's window live in every compaction and
|
|
360
|
+
// overflow check. The session_start guard windows every model write; a
|
|
361
|
+
// global choice made in another process lands before each check instead:
|
|
362
|
+
// prompt-time checks run after `input`, continuation and post-run checks
|
|
363
|
+
// after `turn_end`.
|
|
364
|
+
let removeTokensGuard: (() => void) | undefined;
|
|
365
|
+
pi.on("input", (_event, ctx) => {
|
|
366
|
+
applyContextTokens(ctx);
|
|
367
|
+
});
|
|
368
|
+
pi.on("turn_end", (_event, ctx) => {
|
|
369
|
+
applyContextTokens(ctx);
|
|
370
|
+
});
|
|
371
|
+
|
|
303
372
|
let removeFooterColors: (() => void) | undefined;
|
|
373
|
+
let removeKeybindings: (() => void) | undefined;
|
|
374
|
+
let removeWheelScroll: (() => void) | undefined;
|
|
375
|
+
// ctx.ui.addAutocompleteProvider() returns void and stacks permanently, so
|
|
376
|
+
// re-registering on every session_start would leave one live provider per
|
|
377
|
+
// session load. Register the model sort exactly once.
|
|
378
|
+
let autocompleteInstalled = false;
|
|
304
379
|
let removeJumpToBottom: (() => void) | undefined;
|
|
305
380
|
let removePromptJump: (() => void) | undefined;
|
|
306
381
|
let settings: SettingsController | undefined;
|
|
307
382
|
let removeEditorMouseGuard: (() => void) | undefined;
|
|
308
383
|
let removePromptClear: (() => void) | undefined;
|
|
309
384
|
let removeSmartSelection: (() => void) | undefined;
|
|
385
|
+
let removeClipboardSelection: (() => void) | undefined;
|
|
310
386
|
let removeSelectionDismiss: (() => void) | undefined;
|
|
311
387
|
let removeOverlayScroll: (() => void) | undefined;
|
|
312
388
|
let removeOsc8LinkIds: (() => void) | undefined;
|
|
@@ -323,13 +399,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
323
399
|
let sessionTitlePending = false;
|
|
324
400
|
const promptDisplay = createPromptDisplay();
|
|
325
401
|
|
|
326
|
-
|
|
327
|
-
pi.registerMarkdownTransformer?.((markdown, context) => {
|
|
328
|
-
if (context.messageType === "user")
|
|
329
|
-
return promptDisplay.transform(markdown);
|
|
402
|
+
const markdownTransformer: MarkdownTransformer = (markdown, context) => {
|
|
330
403
|
if (context.messageType !== "assistant") return markdown;
|
|
331
404
|
return markdown.replace(SESSION_TITLE_DISPLAY_PATTERN, "");
|
|
332
|
-
}
|
|
405
|
+
};
|
|
406
|
+
pi.registerMarkdownTransformer?.(markdownTransformer);
|
|
407
|
+
const promptDisplayHost = installPromptDisplayHost(
|
|
408
|
+
promptDisplay,
|
|
409
|
+
() => pi.getCommands(),
|
|
410
|
+
markdownTransformer,
|
|
411
|
+
);
|
|
333
412
|
|
|
334
413
|
const findPendingEntry = (ctx: ExtensionContext) => {
|
|
335
414
|
if (!pendingPrompt?.messageTimestamp) return undefined;
|
|
@@ -381,9 +460,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
381
460
|
};
|
|
382
461
|
|
|
383
462
|
pi.registerCommand?.(RESTORE_MODEL_COMMAND, {
|
|
384
|
-
description: "Internal: restore
|
|
463
|
+
description: "Internal: restore model, thinking, and Fast after /clear",
|
|
385
464
|
handler: async (args, ctx) => {
|
|
386
|
-
const reference =
|
|
465
|
+
const reference = decodeClearSettings(args);
|
|
387
466
|
if (!reference) {
|
|
388
467
|
ctx.ui.notify("Could not restore model after /clear", "error");
|
|
389
468
|
return;
|
|
@@ -394,16 +473,38 @@ export default function (pi: ExtensionAPI) {
|
|
|
394
473
|
`Could not restore model ${reference.provider}/${reference.id}`,
|
|
395
474
|
"error",
|
|
396
475
|
);
|
|
476
|
+
return;
|
|
397
477
|
}
|
|
478
|
+
// Model selection reapplies defaults, so restore thinking afterwards.
|
|
479
|
+
pi.setThinkingLevel(reference.thinkingLevel);
|
|
480
|
+
if (fastOverlay.isSessionEnabled() !== reference.sessionFast)
|
|
481
|
+
fastOverlay.toggleSession();
|
|
482
|
+
if (reference.contextTokens) {
|
|
483
|
+
pi.appendEntry(CONTEXT_TOKENS_ENTRY, { mode: reference.contextTokens });
|
|
484
|
+
}
|
|
485
|
+
// Reselecting the same model writes nothing, so apply the new entry.
|
|
486
|
+
applyContextTokens(ctx);
|
|
487
|
+
activeTui?.requestRender();
|
|
398
488
|
},
|
|
399
489
|
});
|
|
400
490
|
|
|
401
491
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Model-preserving clear]]
|
|
402
492
|
pi.registerCommand?.("clear", {
|
|
403
|
-
description:
|
|
493
|
+
description:
|
|
494
|
+
"Start a new session with the current model, thinking, Fast, and context window",
|
|
404
495
|
handler: async (_args, ctx) => {
|
|
405
496
|
const restoreCommand = ctx.model
|
|
406
|
-
? `/${RESTORE_MODEL_COMMAND} ${
|
|
497
|
+
? `/${RESTORE_MODEL_COMMAND} ${encodeURIComponent(
|
|
498
|
+
JSON.stringify({
|
|
499
|
+
provider: ctx.model.provider,
|
|
500
|
+
id: ctx.model.id,
|
|
501
|
+
thinkingLevel: pi.getThinkingLevel(),
|
|
502
|
+
sessionFast: fastOverlay.isSessionEnabled(),
|
|
503
|
+
contextTokens: tokenWindows.sessionMode(
|
|
504
|
+
ctx.sessionManager.getBranch(),
|
|
505
|
+
),
|
|
506
|
+
} satisfies ClearSettings),
|
|
507
|
+
)}`
|
|
407
508
|
: undefined;
|
|
408
509
|
await ctx.newSession(
|
|
409
510
|
restoreCommand
|
|
@@ -443,25 +544,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
443
544
|
},
|
|
444
545
|
});
|
|
445
546
|
|
|
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
|
-
|
|
460
547
|
pi.on("input", (event) => {
|
|
461
548
|
if (event.source === "interactive") {
|
|
462
549
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Pinned transcript scrolling]]
|
|
463
550
|
if (event.text.trim()) activeTui?.scrollToBottom?.();
|
|
464
|
-
promptDisplay.captureInput(event.text, pi.getCommands());
|
|
465
551
|
}
|
|
466
552
|
if (
|
|
467
553
|
event.source === "interactive" &&
|
|
@@ -482,7 +568,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
482
568
|
|
|
483
569
|
pi.on("message_start", (event) => {
|
|
484
570
|
if (event.message.role === "user") {
|
|
485
|
-
promptDisplay.captureUser(event.message);
|
|
486
571
|
if (pendingPrompt) {
|
|
487
572
|
pendingPrompt.messageTimestamp = event.message.timestamp;
|
|
488
573
|
}
|
|
@@ -509,11 +594,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
509
594
|
});
|
|
510
595
|
|
|
511
596
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Model image context]]
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
const messages = pinSkillContext(
|
|
597
|
+
pi.on("context", async (event, ctx) => {
|
|
598
|
+
const messages = await skills.transform(
|
|
515
599
|
omitPriorTurnImages(event.messages),
|
|
516
|
-
ctx
|
|
600
|
+
ctx,
|
|
517
601
|
);
|
|
518
602
|
if (messages !== event.messages) return { messages };
|
|
519
603
|
});
|
|
@@ -523,23 +607,26 @@ export default function (pi: ExtensionAPI) {
|
|
|
523
607
|
if (!readProactiveDelegationEnabled(getAgentDir())) return;
|
|
524
608
|
const tools =
|
|
525
609
|
event.systemPromptOptions?.selectedTools ?? pi.getActiveTools?.() ?? [];
|
|
526
|
-
|
|
527
|
-
event.
|
|
528
|
-
|
|
610
|
+
applyProactiveDelegation(
|
|
611
|
+
event.systemPromptOptions,
|
|
612
|
+
// pi-subagents 0.71+ starts sessions with only its loader active.
|
|
613
|
+
tools.includes("subagent") || tools.includes("subagents_enable"),
|
|
529
614
|
ctx.scopedModels.map((scoped) => scoped.model),
|
|
530
615
|
);
|
|
531
|
-
if (systemPrompt !== undefined) return { systemPrompt };
|
|
532
616
|
});
|
|
533
617
|
|
|
534
618
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Automatic session title]]
|
|
535
619
|
pi.on("before_agent_start", (event) => {
|
|
620
|
+
skills.prepare(event);
|
|
536
621
|
if (!sessionTitlePending || pi.getSessionName?.()) {
|
|
537
622
|
sessionTitlePending = false;
|
|
538
623
|
return;
|
|
539
624
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
625
|
+
appendPromptSection(
|
|
626
|
+
event.systemPromptOptions,
|
|
627
|
+
"proper_base_title",
|
|
628
|
+
SESSION_TITLE_INSTRUCTION,
|
|
629
|
+
);
|
|
543
630
|
});
|
|
544
631
|
|
|
545
632
|
pi.on("message_end", (event) => {
|
|
@@ -643,8 +730,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
643
730
|
});
|
|
644
731
|
|
|
645
732
|
pi.on("session_shutdown", () => {
|
|
733
|
+
removeFastSessionList();
|
|
734
|
+
removeTokensGuard?.();
|
|
735
|
+
removeTokensGuard = undefined;
|
|
736
|
+
stickyDefaults.restore();
|
|
737
|
+
removeKeybindings?.();
|
|
738
|
+
removeKeybindings = undefined;
|
|
739
|
+
removeWheelScroll?.();
|
|
740
|
+
removeWheelScroll = undefined;
|
|
646
741
|
removeFooterColors?.();
|
|
647
742
|
removeFooterColors = undefined;
|
|
743
|
+
fastOverlay.stopDisplayRefresh();
|
|
648
744
|
removeJumpToBottom?.();
|
|
649
745
|
removeJumpToBottom = undefined;
|
|
650
746
|
removePromptJump?.();
|
|
@@ -657,6 +753,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
657
753
|
removePromptClear = undefined;
|
|
658
754
|
removeSmartSelection?.();
|
|
659
755
|
removeSmartSelection = undefined;
|
|
756
|
+
removeClipboardSelection?.();
|
|
757
|
+
removeClipboardSelection = undefined;
|
|
660
758
|
removeSelectionDismiss?.();
|
|
661
759
|
removeSelectionDismiss = undefined;
|
|
662
760
|
removeOverlayScroll?.();
|
|
@@ -677,13 +775,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
677
775
|
pendingPrompt = undefined;
|
|
678
776
|
restoreRequest = undefined;
|
|
679
777
|
sessionTitlePending = false;
|
|
680
|
-
|
|
778
|
+
promptDisplayHost.dispose();
|
|
779
|
+
skills.stop();
|
|
681
780
|
});
|
|
682
781
|
|
|
683
782
|
pi.on("session_start", async (_event, ctx) => {
|
|
684
|
-
|
|
783
|
+
stickyDefaults.activate(ctx.sessionManager);
|
|
784
|
+
skills.start(ctx);
|
|
785
|
+
// /clear restores its captured session Fast after startup completes.
|
|
685
786
|
fastOverlay.resetSession();
|
|
686
|
-
|
|
787
|
+
promptDisplayHost.activate(ctx.sessionManager);
|
|
687
788
|
sessionTitlePending =
|
|
688
789
|
!pi.getSessionName?.() &&
|
|
689
790
|
!ctx.sessionManager
|
|
@@ -724,9 +825,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
724
825
|
ctx.ui.setEditorText(promptText);
|
|
725
826
|
return undefined;
|
|
726
827
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
828
|
+
if (!autocompleteInstalled) {
|
|
829
|
+
autocompleteInstalled = true;
|
|
830
|
+
ctx.ui.addAutocompleteProvider?.((current) =>
|
|
831
|
+
sortModelAutocompleteDescending(current, () => pi.getThinkingLevel?.()),
|
|
832
|
+
);
|
|
833
|
+
}
|
|
730
834
|
|
|
731
835
|
const store = storePath(getAgentDir(), ctx.cwd);
|
|
732
836
|
compactIfNeeded(store);
|
|
@@ -760,14 +864,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
760
864
|
// with extensions that provide their own editor.
|
|
761
865
|
const base = resolveBase(ctx.ui.getEditorComponent());
|
|
762
866
|
const factory: TaggedFactory = (tui, theme, keybindings) => {
|
|
763
|
-
|
|
867
|
+
removeKeybindings?.();
|
|
868
|
+
removeKeybindings = installBaseKeybindings(keybindings);
|
|
764
869
|
const editor =
|
|
765
870
|
base?.(tui, theme, keybindings) ??
|
|
766
871
|
new CustomEditor(tui, theme, keybindings);
|
|
767
872
|
activeEditor = editor as PromptEditor;
|
|
768
873
|
activeTui = tui;
|
|
769
874
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Wheel scroll rate]]
|
|
770
|
-
|
|
875
|
+
removeWheelScroll?.();
|
|
876
|
+
removeWheelScroll = installWheelScrollLines(tui);
|
|
771
877
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Settled transcript]]
|
|
772
878
|
transcriptCleanup?.uninstall();
|
|
773
879
|
transcriptCleanup = installTranscriptCleanup(tui, ctx);
|
|
@@ -776,6 +882,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
776
882
|
removeWidgetTranscript = installWidgetTranscript(tui, editor);
|
|
777
883
|
removeSmartSelection?.();
|
|
778
884
|
removeSmartSelection = installSmartSelection(tui);
|
|
885
|
+
removeClipboardSelection?.();
|
|
886
|
+
removeClipboardSelection = installClipboardSelection(tui);
|
|
779
887
|
removeSelectionDismiss?.();
|
|
780
888
|
// The copy action reads the active selection after this listener runs,
|
|
781
889
|
// so its keystroke must not dismiss the selection it is about to copy.
|
|
@@ -795,7 +903,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
795
903
|
removeJumpToBottom = installJumpToBottom(editor, tui);
|
|
796
904
|
removePromptJump?.();
|
|
797
905
|
settings?.dispose();
|
|
798
|
-
settings = installSettings(tui, editor, getAgentDir())
|
|
906
|
+
settings = installSettings(tui, editor, getAgentDir(), (error) =>
|
|
907
|
+
ctx.ui.notify(
|
|
908
|
+
`Could not save proper-base setting: ${error.message}`,
|
|
909
|
+
"error",
|
|
910
|
+
),
|
|
911
|
+
);
|
|
799
912
|
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Prompt mouse clicks]]
|
|
800
913
|
removeEditorMouseGuard?.();
|
|
801
914
|
removeEditorMouseGuard = installEditorMouseGuard(
|
|
@@ -842,6 +955,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
842
955
|
},
|
|
843
956
|
);
|
|
844
957
|
installModelAutocompleteSubmit(editor, keybindings);
|
|
958
|
+
// @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Context window scopes]]
|
|
959
|
+
installTokensScopeCompletion(editor, keybindings);
|
|
845
960
|
removePromptClear?.();
|
|
846
961
|
removePromptClear = installPromptClear(editor, tui, keybindings, ctx);
|
|
847
962
|
historySearch = installReverseHistorySearch(
|
|
@@ -853,14 +968,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
853
968
|
);
|
|
854
969
|
installAutocompleteDetails(editor, tui, theme);
|
|
855
970
|
removeFooterColors?.();
|
|
971
|
+
fastOverlay.stopDisplayRefresh();
|
|
856
972
|
removeFooterColors = installFooterColors(tui, ctx, () =>
|
|
857
|
-
fastOverlay.
|
|
973
|
+
fastOverlay.isEffectiveForDisplay(ctx.model ?? undefined),
|
|
858
974
|
);
|
|
975
|
+
if (removeFooterColors) {
|
|
976
|
+
fastOverlay.startDisplayRefresh(() => tui.requestRender());
|
|
977
|
+
}
|
|
859
978
|
for (const prompt of seeded) historyGuard?.add(prompt);
|
|
860
979
|
return editor;
|
|
861
980
|
};
|
|
862
981
|
factory[WRAPPED] = base ?? null;
|
|
863
982
|
|
|
864
983
|
ctx.ui.setEditorComponent(factory);
|
|
984
|
+
// Window the restored model now and every model written later.
|
|
985
|
+
removeTokensGuard?.();
|
|
986
|
+
const tokensSession = asTokensSession(
|
|
987
|
+
stickyDefaults.session(ctx.sessionManager),
|
|
988
|
+
);
|
|
989
|
+
removeTokensGuard =
|
|
990
|
+
tokensSession && tokenWindows.guard(tokensSession, ctx.modelRegistry);
|
|
991
|
+
applyContextTokens(ctx);
|
|
865
992
|
});
|
|
993
|
+
// Base setup and cleanup must register before the updater's lifecycle hooks.
|
|
994
|
+
registerAutoUpdates(pi);
|
|
866
995
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proper-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"index.ts",
|
|
38
38
|
"src",
|
|
39
39
|
"README.md",
|
|
40
|
+
"UPDATES.md",
|
|
40
41
|
"LICENSE"
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
@@ -53,8 +54,8 @@
|
|
|
53
54
|
"@earendil-works/pi-tui": "*"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@earendil-works/pi-coding-agent": "
|
|
57
|
-
"@earendil-works/pi-tui": "
|
|
57
|
+
"@earendil-works/pi-coding-agent": "latest",
|
|
58
|
+
"@earendil-works/pi-tui": "latest",
|
|
58
59
|
"@types/node": "25.9.5",
|
|
59
60
|
"typescript": "6.0.2"
|
|
60
61
|
},
|