@sion10032/pi-sessions 0.0.0-stage → 0.2.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/src/picker.ts ADDED
@@ -0,0 +1,526 @@
1
+ /**
2
+ * The `/sessions` TUI picker component.
3
+ *
4
+ * A thin view over `PickerState`: this file decides how the state looks and
5
+ * which keystroke does what, but it never reads the filesystem, archives or
6
+ * restores anything itself. Every action goes through the callbacks in
7
+ * `SessionPickerProps`, so the command layer owns loading, moving files and
8
+ * switching sessions.
9
+ */
10
+ import type { KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
11
+ import {
12
+ Input,
13
+ matchesKey,
14
+ truncateToWidth,
15
+ visibleWidth,
16
+ type Component,
17
+ type KeyId,
18
+ type TUI,
19
+ type TuiMouseEvent,
20
+ type TuiMouseEventResult,
21
+ } from "@earendil-works/pi-tui";
22
+
23
+ import { displayTitle, relativeTime } from "./paths.ts";
24
+ import { hasName } from "./search.ts";
25
+ import type { ArchiveAction, PickerState } from "./picker-state.ts";
26
+ import type { TreeRow } from "./sessions.ts";
27
+ import type { Scope, SessionRecord } from "./types.ts";
28
+
29
+ /** Rows rendered at once, matching the native session picker. */
30
+ const MAX_VISIBLE = 10;
31
+
32
+ /**
33
+ * Per-row expand/collapse keys. Deliberately unset while no dedicated pair is
34
+ * chosen; `setSelectedExpanded` and the handler stay so assigning a pair here
35
+ * restores the feature. `whenSearchEmpty` keeps plain arrows from stealing
36
+ * cursor movement if they are chosen later. Candidates:
37
+ * { collapse: "alt+-", expand: "alt+=" }
38
+ * { collapse: "left", expand: "right", whenSearchEmpty: true }
39
+ */
40
+ const ROW_EXPAND_KEYS:
41
+ | { collapse: KeyId; expand: KeyId; whenSearchEmpty?: boolean }
42
+ | undefined = undefined;
43
+
44
+ const FOOTER_LINE = "ctrl+e mode · ctrl+a archive · enter resume · esc cancel";
45
+
46
+ /** A pending archive or delete action, waiting for Enter to confirm. */
47
+ type Confirmation =
48
+ | {
49
+ kind: "archive";
50
+ record: SessionRecord;
51
+ action: ArchiveAction;
52
+ /** Descendant count captured when the prompt was opened. */
53
+ children: number;
54
+ }
55
+ | {
56
+ kind: "delete";
57
+ record: SessionRecord;
58
+ children: number;
59
+ };
60
+
61
+ export interface SessionPickerProps {
62
+ state: PickerState;
63
+ theme: Theme;
64
+ tui: TUI;
65
+ keybindings: KeybindingsManager;
66
+ /** Resume the selected session, restoring it first when needed. */
67
+ onResume(record: SessionRecord): void;
68
+ /**
69
+ * Rename the record; the owner writes the name and refreshes the rows.
70
+ * Optional so a caller that cannot rename simply gets no `ctrl+r`, the same
71
+ * way the native picker hides rename when it has no handler.
72
+ */
73
+ onRename?(record: SessionRecord, name: string): void;
74
+ /**
75
+ * Delete the record together with its subtree. Optional like `onRename`: no
76
+ * handler means the picker does not claim `ctrl+d`.
77
+ */
78
+ onDelete?(record: SessionRecord): void;
79
+ /** Explain why `ctrl+d` did nothing: the running session, or its subtree. */
80
+ onDeleteRefused?(reason: "current" | "protected"): void;
81
+ /** Archive or unarchive the record; the owner refreshes the rows. */
82
+ onToggleArchive(record: SessionRecord): void;
83
+ onCancel(): void;
84
+ /** Called after a scope switch so the owner can reload that scope. */
85
+ onReload?(scope: Scope): void;
86
+ }
87
+
88
+ /** The tree prefix `TreeRow` describes, copied from the native session list. */
89
+ function treePrefix(row: TreeRow): string {
90
+ if (row.depth === 0) return "";
91
+ const parts = row.ancestorContinues.map((continues) => (continues ? "│ " : " "));
92
+ const branch = row.isLast ? "└─ " : "├─ ";
93
+ return parts.join("") + branch;
94
+ }
95
+
96
+ /**
97
+ * Truncate plain text without emitting ANSI resets. `truncateToWidth` closes
98
+ * its output with a full reset, which would clear the selected row's
99
+ * background before the right-side metadata; titles are plain text anyway.
100
+ */
101
+ function truncatePlain(text: string, maxWidth: number): string {
102
+ if (maxWidth <= 0) return "";
103
+ if (visibleWidth(text) <= maxWidth) return text;
104
+ let result = "";
105
+ for (const char of text) {
106
+ if (visibleWidth(result + char) > maxWidth - 1) break;
107
+ result += char;
108
+ }
109
+ return `${result}…`;
110
+ }
111
+
112
+ function expansionLabel(state: PickerState): string {
113
+ if (state.expansionMode === "collapsed") return "Collapsed";
114
+ if (state.expansionMode === "children") return "Children";
115
+ return "All";
116
+ }
117
+
118
+ function archiveFilterLabel(state: PickerState): string {
119
+ if (state.archiveFilter === "active") return "Active";
120
+ if (state.archiveFilter === "archived") return "Archived";
121
+ return "All";
122
+ }
123
+
124
+ function scopeLabel(state: PickerState): string {
125
+ return state.scope === "current" ? "Current Folder" : "All";
126
+ }
127
+
128
+ function sortLabel(state: PickerState): string {
129
+ if (state.sort === "threaded") return "Threaded";
130
+ if (state.sort === "recent") return "Recent";
131
+ return "Relevance";
132
+ }
133
+
134
+ export class SessionPicker implements Component {
135
+ private readonly props: SessionPickerProps;
136
+ private readonly input: Input;
137
+ /** Set while `ctrl+a` waits for Enter on a parent with children. */
138
+ private confirming: Confirmation | undefined;
139
+ /** Set while `ctrl+r` edits the selected session's name. */
140
+ private rename: { record: SessionRecord; input: Input } | undefined;
141
+ /** Rows rendered last, for mapping a click's row back to the selection. */
142
+ private visibleRows: TreeRow[] = [];
143
+ /** First rendered line of the session list; header and filter precede it. */
144
+ private rowsTop = 0;
145
+ /** Index of the selection inside `visibleRows`, or -1 when off-screen. */
146
+ private selectedVisibleIndex = -1;
147
+
148
+ constructor(props: SessionPickerProps) {
149
+ this.props = props;
150
+ this.input = new Input({ prompt: "> " });
151
+ }
152
+
153
+ handleInput(data: string): void {
154
+ const { keybindings: kb, state, tui } = this.props;
155
+
156
+ // The rename panel owns every key while it is open: Enter saves, Esc
157
+ // cancels, the rest is text.
158
+ if (this.rename !== undefined) {
159
+ if (kb.matches(data, "tui.select.confirm")) {
160
+ const { record, input } = this.rename;
161
+ this.rename = undefined;
162
+ this.props.onRename?.(record, input.getValue());
163
+ } else if (kb.matches(data, "tui.select.cancel") || matchesKey(data, "ctrl+c")) {
164
+ this.rename = undefined;
165
+ } else {
166
+ this.rename.input.handleInput(data);
167
+ }
168
+ tui.requestRender();
169
+ return;
170
+ }
171
+
172
+ // A pending archive owns every key: Enter confirms, Esc cancels, the
173
+ // rest must not leak into the filter or the list.
174
+ if (this.confirming !== undefined) {
175
+ if (kb.matches(data, "tui.select.confirm")) {
176
+ const pending = this.confirming;
177
+ this.confirming = undefined;
178
+ if (pending.kind === "archive") this.props.onToggleArchive(pending.record);
179
+ else this.props.onDelete?.(pending.record);
180
+ } else if (kb.matches(data, "tui.select.cancel") || matchesKey(data, "ctrl+c")) {
181
+ this.confirming = undefined;
182
+ }
183
+ tui.requestRender();
184
+ return;
185
+ }
186
+
187
+ // Claim the custom control keys before `Input` sees them. `matchesKey`
188
+ // covers both legacy control bytes and the Kitty keyboard protocol's
189
+ // CSI-u sequences, so ctrl+e/ctrl+a work in terminals that negotiate it.
190
+ if (matchesKey(data, "ctrl+t")) {
191
+ state.cycleArchiveFilter();
192
+ tui.requestRender();
193
+ return;
194
+ }
195
+ if (matchesKey(data, "ctrl+e")) {
196
+ state.cycleExpansion();
197
+ tui.requestRender();
198
+ return;
199
+ }
200
+ if (matchesKey(data, "ctrl+a")) {
201
+ this.archiveSelected();
202
+ tui.requestRender();
203
+ return;
204
+ }
205
+ // Delete follows the native picker: `ctrl+d` always, and
206
+ // `ctrl+backspace` only while the filter is empty, so the same key can
207
+ // still delete a word inside the query.
208
+ if (this.props.onDelete !== undefined && kb.matches(data, "app.session.delete")) {
209
+ this.deleteSelected();
210
+ tui.requestRender();
211
+ return;
212
+ }
213
+ if (
214
+ this.props.onDelete !== undefined
215
+ && kb.matches(data, "app.session.deleteNoninvasive")
216
+ && this.input.getValue().length === 0
217
+ ) {
218
+ this.deleteSelected();
219
+ tui.requestRender();
220
+ return;
221
+ }
222
+
223
+ // `ctrl+r`: rename in place. The input starts from the session's own
224
+ // name, as the native picker does, so an unnamed session starts empty.
225
+ if (kb.matches(data, "app.session.rename") && this.props.onRename !== undefined) {
226
+ const row = state.selectedRow();
227
+ if (row !== undefined) {
228
+ const input = new Input({ prompt: "> " });
229
+ // Type the name in rather than `setValue`: `setValue` leaves the
230
+ // cursor at 0, so the first typed character would land in front of
231
+ // the existing name instead of after it.
232
+ input.handleInput(row.record.info.name ?? "");
233
+ this.rename = { record: row.record, input };
234
+ }
235
+ tui.requestRender();
236
+ return;
237
+ }
238
+
239
+ if (kb.matches(data, "tui.input.tab")) {
240
+ state.cycleScope();
241
+ // The picker only holds the scope's records it was given; switching
242
+ // to `all` has to be loaded by whoever opened the picker.
243
+ this.props.onReload?.(state.scope);
244
+ tui.requestRender();
245
+ return;
246
+ }
247
+ if (kb.matches(data, "app.session.toggleSort")) {
248
+ state.cycleSort();
249
+ tui.requestRender();
250
+ return;
251
+ }
252
+ if (kb.matches(data, "app.session.toggleNamedFilter")) {
253
+ state.toggleNamed();
254
+ tui.requestRender();
255
+ return;
256
+ }
257
+ if (kb.matches(data, "app.session.togglePath")) {
258
+ state.togglePath();
259
+ tui.requestRender();
260
+ return;
261
+ }
262
+
263
+ // Per-row expand/collapse is intentionally unbound until a dedicated key
264
+ // pair is chosen; the handler and PickerState methods stay in place.
265
+ if (ROW_EXPAND_KEYS !== undefined) {
266
+ const searchEmpty = this.input.getValue().length === 0;
267
+ if (!ROW_EXPAND_KEYS.whenSearchEmpty || searchEmpty) {
268
+ if (matchesKey(data, ROW_EXPAND_KEYS.expand)) {
269
+ state.setSelectedExpanded(true);
270
+ tui.requestRender();
271
+ return;
272
+ }
273
+ if (matchesKey(data, ROW_EXPAND_KEYS.collapse)) {
274
+ state.setSelectedExpanded(false);
275
+ tui.requestRender();
276
+ return;
277
+ }
278
+ }
279
+ }
280
+
281
+ if (kb.matches(data, "tui.select.up")) {
282
+ state.move(-1);
283
+ } else if (kb.matches(data, "tui.select.down")) {
284
+ state.move(1);
285
+ } else if (kb.matches(data, "tui.select.pageUp")) {
286
+ state.move(-MAX_VISIBLE);
287
+ } else if (kb.matches(data, "tui.select.pageDown")) {
288
+ state.move(MAX_VISIBLE);
289
+ } else if (kb.matches(data, "tui.select.confirm")) {
290
+ const row = state.selectedRow();
291
+ if (row !== undefined) this.props.onResume(row.record);
292
+ return;
293
+ } else if (kb.matches(data, "tui.select.cancel")) {
294
+ this.props.onCancel();
295
+ return;
296
+ } else {
297
+ this.input.handleInput(data);
298
+ state.setQuery(this.input.getValue());
299
+ }
300
+ tui.requestRender();
301
+ }
302
+
303
+ handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
304
+ if (event.type === "wheel") {
305
+ const delta = event.wheelDelta ?? 0;
306
+ if (delta === 0) return undefined;
307
+ this.props.state.move(delta);
308
+ return { handled: true, render: true };
309
+ }
310
+ if ((event.type === "press" || event.type === "click") && event.button === "left") {
311
+ const offset = event.y - this.rowsTop;
312
+ if (offset < 0 || offset >= this.visibleRows.length) return undefined;
313
+ if (this.selectedVisibleIndex < 0) return undefined;
314
+ this.props.state.move(offset - this.selectedVisibleIndex);
315
+ return { handled: true, render: true };
316
+ }
317
+ return undefined;
318
+ }
319
+
320
+ render(width: number): string[] {
321
+ const safeWidth = Math.max(1, width);
322
+ const { state, theme } = this.props;
323
+ if (this.rename !== undefined) {
324
+ return [
325
+ theme.bold("Rename Session"),
326
+ ...this.rename.input.render(safeWidth),
327
+ "",
328
+ theme.fg("dim", truncateToWidth("enter to save · esc to cancel", safeWidth, "…")),
329
+ "",
330
+ ];
331
+ }
332
+ const lines = [...this.renderHeader(safeWidth), ...this.input.render(safeWidth)];
333
+ lines.push(this.props.state.loading
334
+ ? theme.fg("dim", truncateToWidth(` ${this.loadingText()}`, safeWidth, "…"))
335
+ : "");
336
+
337
+ const rows = state.rows();
338
+ // `selectedRow()` re-anchors the selection after a filter change; calling
339
+ // it here (not once per row) keeps that work to a single extra pass.
340
+ const selected = state.selectedRow();
341
+ const selectedIndex = selected === undefined
342
+ ? -1
343
+ : rows.findIndex((row) => row.record === selected.record);
344
+ const start = Math.max(0, Math.min(
345
+ selectedIndex - Math.floor(MAX_VISIBLE / 2),
346
+ rows.length - MAX_VISIBLE,
347
+ ));
348
+ const end = Math.min(start + MAX_VISIBLE, rows.length);
349
+ this.rowsTop = lines.length;
350
+ this.visibleRows = rows.slice(start, end);
351
+ this.selectedVisibleIndex = selectedIndex >= start && selectedIndex < end
352
+ ? selectedIndex - start
353
+ : -1;
354
+
355
+ if (rows.length > 0) {
356
+ for (const [offset, row] of this.visibleRows.entries()) {
357
+ lines.push(this.renderRow(row, selectedIndex === start + offset, safeWidth));
358
+ }
359
+ if (start > 0 || end < rows.length) {
360
+ const position = selectedIndex >= 0
361
+ ? `${selectedIndex + 1}/${rows.length}`
362
+ : `${rows.length} sessions`;
363
+ lines.push(theme.fg("dim", truncateToWidth(` (${position})`, safeWidth, "")));
364
+ }
365
+ } else if (!state.loading) {
366
+ const empty = this.props.state.query.trim() !== ""
367
+ || state.archiveFilter !== "active"
368
+ || state.namedOnly
369
+ ? "No sessions match the current filter."
370
+ : state.scope === "current"
371
+ ? "No sessions in current folder. Press Tab to view all."
372
+ : "No sessions found.";
373
+ lines.push(theme.fg("dim", truncateToWidth(` ${empty}`, safeWidth, "…")));
374
+ }
375
+
376
+ lines.push("");
377
+ return lines;
378
+ }
379
+
380
+ private loadingText(): string {
381
+ const { state } = this.props;
382
+ if (state.loadingPhase === "archive" && state.loadingTotal > 0) {
383
+ return `Loading archived folders… ${state.loadingLoaded}/${state.loadingTotal}`;
384
+ }
385
+ const label = state.scope === "all" ? "Loading all sessions" : "Loading sessions";
386
+ const progress = state.loadingTotal > 0 ? ` ${state.loadingLoaded}/${state.loadingTotal}` : "";
387
+ return `${label}…${progress}`;
388
+ }
389
+
390
+ invalidate(): void {
391
+ this.input.invalidate();
392
+ this.visibleRows = [];
393
+ this.selectedVisibleIndex = -1;
394
+ this.rowsTop = 0;
395
+ this.props.tui.requestRender();
396
+ }
397
+
398
+ /** `ctrl+a`: every archive/unarchive action asks for confirmation first. */
399
+ private archiveSelected(): void {
400
+ const { state } = this.props;
401
+ const row = state.selectedRow();
402
+ if (row === undefined) return;
403
+ const action = state.archiveAction();
404
+ if (action === "none") return;
405
+ // Count every loaded descendant, not the visible rows: a query or the
406
+ // recent sort flattens the list and would archive children silently.
407
+ this.confirming = { kind: "archive", record: row.record, action, children: state.descendantCount(row.record) };
408
+ }
409
+
410
+ /** `ctrl+d`: ask first, and never for the session pi is still writing. */
411
+ private deleteSelected(): void {
412
+ const { state } = this.props;
413
+ const row = state.selectedRow();
414
+ if (row === undefined) return;
415
+ const action = state.deleteAction();
416
+ if (action === "none") {
417
+ this.props.onDeleteRefused?.("current");
418
+ return;
419
+ }
420
+ if (action === "protected") {
421
+ this.props.onDeleteRefused?.("protected");
422
+ return;
423
+ }
424
+ // Count every loaded descendant, as the archive prompt does: a query or a
425
+ // hidden subagent subtree must not make the number lie.
426
+ this.confirming = { kind: "delete", record: row.record, children: state.descendantCount(row.record) };
427
+ }
428
+
429
+ /** The title is deliberately omitted: a long title must not hide the action. */
430
+ private confirmationPrompt(): string {
431
+ const pending = this.confirming!;
432
+ if (pending.kind === "delete") {
433
+ const scope = pending.children > 0 ? ` this session and ${pending.children} child sessions?` : " this session?";
434
+ return `Delete${scope} enter confirm · esc/ctrl+c cancel`;
435
+ }
436
+ const { action, children } = pending;
437
+ if (action === "deferred-archive") {
438
+ return "Archive the current session when it closes? enter confirm · esc/ctrl+c cancel";
439
+ }
440
+ const verb = action === "unarchive" ? "Unarchive" : "Archive";
441
+ const scope = children > 0 ? ` this session and ${children} child sessions?` : " this session?";
442
+ return `${verb}${scope} enter confirm · esc/ctrl+c cancel`;
443
+ }
444
+
445
+ private renderHeader(width: number): string[] {
446
+ const { state, theme } = this.props;
447
+ const title = theme.bold(`Sessions (${scopeLabel(state)})`);
448
+ const scope = state.scope === "current"
449
+ ? `${theme.fg("accent", "◉ Current Folder")}${theme.fg("muted", " | ○ All")}`
450
+ : `${theme.fg("muted", "○ Current Folder | ")}${theme.fg("accent", "◉ All")}`;
451
+ const name = `${theme.fg("muted", "Name: ")}${theme.fg("accent", state.namedOnly ? "Named" : "All")}`;
452
+ const sort = `${theme.fg("muted", "Sort: ")}${theme.fg("accent", sortLabel(state))}`;
453
+ const expand = `${theme.fg("muted", "Expand: ")}${theme.fg("accent", expansionLabel(state))}`;
454
+ const filter = `${theme.fg("muted", "Filter: ")}${theme.fg("accent", archiveFilterLabel(state))}`;
455
+ // Keep at least a title stub: the filter row is wide at 80 columns.
456
+ const right = truncateToWidth(`${scope} ${expand} ${name} ${sort} ${filter}`, Math.max(0, width - 22), "");
457
+ const availableLeft = Math.max(0, width - visibleWidth(right) - 1);
458
+ const left = truncateToWidth(title, availableLeft, "");
459
+ const spacing = Math.max(0, width - visibleWidth(left) - visibleWidth(right));
460
+ const titleLine = `${left}${" ".repeat(spacing)}${right}`;
461
+
462
+ if (this.confirming !== undefined) {
463
+ return [
464
+ titleLine,
465
+ theme.fg("error", truncateToWidth(this.confirmationPrompt(), width, "…")),
466
+ "",
467
+ ];
468
+ }
469
+
470
+ const sep = theme.fg("muted", " · ");
471
+ // Match the native picker: dim key names, muted descriptions.
472
+ const keyHint = (key: string, label: string): string =>
473
+ `${theme.fg("dim", key)} ${theme.fg("muted", label)}`;
474
+ const hint1 = `${keyHint("tab", "scope")}${sep}${theme.fg("muted", 're:<pattern> regex · "phrase" exact')}`;
475
+ // Browsing keys and action keys each get a line: one combined line no
476
+ // longer fits 80 columns once rename and delete are listed.
477
+ const hint2 = [
478
+ keyHint("ctrl+e", "mode"),
479
+ keyHint("ctrl+t", "filter"),
480
+ keyHint("ctrl+s", "sort"),
481
+ keyHint("ctrl+n", "named"),
482
+ keyHint("ctrl+p", `path (${state.showPath ? "on" : "off"})`),
483
+ ].join(sep);
484
+ const hint3 = [
485
+ keyHint("ctrl+a", "archive"),
486
+ keyHint("ctrl+r", "rename"),
487
+ keyHint("ctrl+d", "delete"),
488
+ ].join(sep);
489
+ return [
490
+ titleLine,
491
+ truncateToWidth(hint1, width, "…"),
492
+ truncateToWidth(hint2, width, "…"),
493
+ truncateToWidth(hint3, width, "…"),
494
+ ];
495
+ }
496
+
497
+ private renderRow(row: TreeRow, selected: boolean, width: number): string {
498
+ const { state, theme } = this.props;
499
+ const { info } = row.record;
500
+ const cursor = selected ? theme.fg("accent", "› ") : " ";
501
+ const prefix = theme.fg("dim", treePrefix(row));
502
+
503
+ // The `↳N` badge sits right after the message, like a suffix; the right
504
+ // column keeps the message count and age.
505
+ const badge = row.descendantCount > 0 ? ` ↳${row.descendantCount}` : "";
506
+ const rightParts: string[] = [];
507
+ if (row.record.archived) rightParts.push("[archived]");
508
+ if (state.showPath) rightParts.unshift(info.path);
509
+ rightParts.push(String(info.messageCount));
510
+ rightParts.push(relativeTime(row.record.archived ? row.record.archiveDate : info.modified));
511
+ const right = theme.fg("dim", rightParts.join(" "));
512
+
513
+ const leftWidth = visibleWidth(cursor) + visibleWidth(prefix);
514
+ const available = Math.max(10, width - leftWidth - visibleWidth(right) - 2 - visibleWidth(badge));
515
+ let message = truncatePlain(displayTitle(info), available);
516
+ const color = state.isCurrent(row.record) ? "accent" : hasName(info) ? "warning" : undefined;
517
+ if (color !== undefined) message = theme.fg(color, message);
518
+ if (selected) message = theme.bold(message);
519
+
520
+ const left = `${cursor}${prefix}${message}${theme.fg("dim", badge)}`;
521
+ const gap = Math.max(1, width - visibleWidth(left) - visibleWidth(right));
522
+ let line = `${left}${" ".repeat(gap)}${right}`;
523
+ if (selected) line = theme.bg("selectedBg", line);
524
+ return truncateToWidth(line, width);
525
+ }
526
+ }
package/src/rename.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Renaming a session that is not the one pi is running.
3
+ *
4
+ * A session's display name is not stored in its header: it is the latest
5
+ * `session_info` entry in the file, which is exactly what `pi.setSessionName`
6
+ * appends for the running session and what pi's own picker appends through
7
+ * `SessionManager.open(path).appendSessionInfo(name)` for any other one. Doing
8
+ * the same keeps renames visible to `/resume`, `/sessions` and the footer, and
9
+ * works on an archived file without moving it.
10
+ */
11
+ import { SessionManager } from "@earendil-works/pi-coding-agent";
12
+
13
+ /**
14
+ * Append `name` as the session's new display name. Whitespace-only names are
15
+ * ignored (there is no way to clear a name this way, matching the native
16
+ * picker) and return `false`; a write failure throws to the caller.
17
+ */
18
+ export function renameSessionFile(file: string, name: string): boolean {
19
+ const next = name.trim();
20
+ if (next === "") return false;
21
+ SessionManager.open(file).appendSessionInfo(next);
22
+ return true;
23
+ }