@code-fixer-23/pi-session-manager 1.0.6 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 1.1.0 (2026-08-23)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **pi-session-manager:** persist config through extension settings ([933f395](https://github.com/louiss0/pi-packages/commit/933f395))
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **workspace:** pin typescript to ~6.0.3 across packages ([e11938a](https://github.com/louiss0/pi-packages/commit/e11938a))
10
+ - **pi-session-manager:** align test mocks with strict compiler flags ([fba5182](https://github.com/louiss0/pi-packages/commit/fba5182))
11
+
12
+ ### ❤️ Thank You
13
+
14
+ - louiss0 @louiss0
15
+
1
16
  ## 1.0.6 (2026-07-14)
2
17
 
3
18
  ### 🩹 Fixes
package/README.md CHANGED
@@ -1,76 +1,99 @@
1
- # pi-session-manager
2
-
3
- ![Session Manager](https://raw.githubusercontent.com/louiss0/pi-packages/main/pi-session-manager/assets/Pi-Session_Manager-Big.png)
4
-
5
-
6
- [![npm version](https://img.shields.io/npm/v/@code-fixer-23/pi-session-manager.svg)](https://www.npmjs.com/package/@code-fixer-23/pi-session-manager)
7
- [![downloads](https://img.shields.io/npm/dm/@code-fixer-23/pi-session-manager.svg)](https://www.npmjs.com/package/@code-fixer-23/pi-session-manager)
8
- [![license](https://img.shields.io/npm/l/@code-fixer-23/pi-session-manager.svg)](./LICENSE)
9
- [![CI](https://github.com/louiss0/pi-packages/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/louiss0/pi-packages/actions/workflows/ci.yml)
10
-
11
-
12
- `pi-session-manager` adds local session cleanup and series management workflows to PI. It helps keep session history organized by pruning stale sessions stored on your machine, naming related sessions consistently, and carrying series context forward between sessions. The package plugs into PI's extension lifecycle so it can react when a session starts, restore persisted series metadata, and expose commands that coordinate session creation, continuation, and cleanup.
13
-
14
- ## pi-session-manager
15
-
16
- This package ships a single PI extension in `extensions/index.ts`, supported by a small test suite and a helper script for scaffolding additional extension entry points.
17
-
18
- ### Behavior overview
19
-
20
- The extension centers on two workflows:
21
-
22
- 1. **Session cleanup** — it can remove inactive local sessions automatically on startup or manually through commands.
23
- 2. **Session series management** — it records related sessions under a shared series name, preserves that context across session restarts, and lets you continue or extend a series later.
24
-
25
- On session start, the extension first restores any persisted series data from the temp directory so PI can resume the correct session name and custom entry. When the session starts normally or after a reload, it also loads the package config, checks the cleanup rules, and removes stale local sessions if they exceed the configured age limit.
26
-
27
- If you want a session gone, delete it through the package commands instead of editing the config by hand. The config is an internal coordination file, not a user-edit surface.
28
-
29
- > Warning: do not edit `pi-session-manager.config.json` directly. If you need to remove a series, use `session:series delete` and let the package update its own state.
30
-
31
- ### Commands
32
-
33
- #### `session:clean:inactive`
34
- Deletes local sessions that have been inactive longer than the configured day limit. This command uses the package config stored in the agent directory, so the cleanup window matches the same rule used during startup cleanup. Use this when you want PI to resume with a clean local session set without manually touching files.
35
-
36
- #### `session:clean:older-than <duration>`
37
- Deletes local sessions older than a specific duration. The argument accepts either full units like `5days`, `2weeks`, `12hours` or shorthand forms like `5d`, `2w`, `12h`. This is useful when you want to remove sessions using an ad hoc retention threshold instead of the saved day limit.
38
-
39
- #### `session:delete-last <count>`
40
- Deletes the most recent N local sessions. The argument is an integer from 1 to 10, which makes it a quick recovery tool for removing only the newest session files when you want to clean up by hand.
41
-
42
- #### `session:series <action>`
43
- Coordinates the session-series lifecycle. The available actions are:
44
-
45
- - `create` create a new series and a first session inside it, then persist the resulting session metadata so PI can restore the series context later.
46
- - `new` — add a new session to an existing series and keep the series record updated.
47
- - `continue` — inspect the currently active session entry, recover its series, and start the next session in that same chain.
48
- - `delete` remove a series and all local session files whose names start with that series prefix. This is the safest way to remove a series; avoid editing the config file directly.
49
-
50
- ### Features
51
-
52
- #### Startup lifecycle coordination
53
- The extension listens to PI session startup and reload events to restore persisted session-series data before the rest of the session flow continues. That lets PI reopen the correct session name and custom entry even after a new process starts.
54
-
55
- #### Persistent session-series state
56
- When a series session is created, the extension writes a small temp file in the OS temp directory. On the next session start, it consumes that file, applies the stored session name and entry, and then removes the temp file so the state only applies once.
57
-
58
- #### Configured cleanup rules
59
- The package stores its config in the PI agent directory as `pi-session-manager.config.json`. That config controls the automatic inactivity cleanup threshold and remembers the series/title structure per working directory.
60
-
61
- Treat this file as internal state. Do not edit it manually unless you are debugging the package itself. If you need to remove a series, use `session:series delete` instead of changing the config file.
62
-
63
- The package is designed to work with local session files only, so it should never be treated as a remote or shared-session cleanup tool.
64
-
65
- ### Developer notes
66
-
67
- - Package metadata lives in `package.json` and identifies this as a PI extension package.
68
- - The implementation is in `extensions/index.ts`.
69
- - Tests live alongside the extension in `extensions/index.test.ts`.
70
- - `scripts/create-extension.ts` is a small helper for scaffolding a new extension file under `extensions/`.
71
-
72
- ### Assets in this repository
73
-
74
- - `extensions/` — extension implementation and tests
75
- - `scripts/` helper script for creating new extension files
76
- - No `prompts/`, `skills/`, or `themes/` directories are present in this package
1
+ # pi-session-manager
2
+
3
+ ![Session Manager](https://raw.githubusercontent.com/louiss0/pi-packages/main/pi-session-manager/assets/Pi-Session_Manager-Big.png)
4
+
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@code-fixer-23/pi-session-manager.svg)](https://www.npmjs.com/package/@code-fixer-23/pi-session-manager)
7
+ [![downloads](https://img.shields.io/npm/dm/@code-fixer-23/pi-session-manager.svg)](https://www.npmjs.com/package/@code-fixer-23/pi-session-manager)
8
+ [![license](https://img.shields.io/npm/l/@code-fixer-23/pi-session-manager.svg)](./LICENSE)
9
+ [![CI](https://github.com/louiss0/pi-packages/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/louiss0/pi-packages/actions/workflows/ci.yml)
10
+
11
+
12
+ `pi-session-manager` adds local session cleanup and series management workflows to PI. It helps keep session history organized by pruning stale sessions stored on your machine, naming related sessions consistently, and carrying series context forward between sessions. The package plugs into PI's extension lifecycle so it can react when a session starts, restore persisted series metadata, and expose commands that coordinate session creation, continuation, and cleanup.
13
+
14
+ ## pi-session-manager
15
+
16
+ This package ships a single PI extension in `extensions/index.ts`, supported by a small test suite and a helper script for scaffolding additional extension entry points.
17
+
18
+ ### Behavior overview
19
+
20
+ The extension centers on two workflows:
21
+
22
+ 1. **Session cleanup** — it can remove inactive local sessions automatically on startup or manually through commands.
23
+ 2. **Session series management** — it records related sessions under a shared series name, preserves that context across session restarts, and lets you continue or extend a series later.
24
+
25
+ On session start, the extension first restores any persisted series data from the temp directory so PI can resume the correct session name and custom entry. When the session starts normally or after a reload, it also loads the package config, checks the cleanup rules, and removes stale local sessions if they exceed the configured age limit.
26
+
27
+ If you want a session gone, delete it through the package commands instead of editing the config by hand. The config is an internal coordination file, not a user-edit surface.
28
+
29
+ > Warning: do not edit the extension's stored settings directly. If you need to remove a series, use `session-manager:series delete` and let the package update its own state.
30
+
31
+ ### Commands
32
+
33
+ All commands live under the `session-manager` namespace. Every cleanup command that works on the current project has an `:all` twin that works on **every** session in the sessions area (`~/.pi/agent/sessions/`), no matter which project it belongs to. After any deletion, you are shown the list of deleted sessions grouped and sorted by project name.
34
+
35
+ #### `session-manager:clean:inactive`
36
+ Deletes local sessions that have been inactive longer than the configured day limit. This command reads the day limit from the shared extension settings, so the cleanup window matches the same rule used during startup cleanup. Use this when you want PI to resume with a clean local session set without manually touching files.
37
+
38
+ #### `session-manager:clean:inactive:all`
39
+ The same inactivity rule as `session-manager:clean:inactive`, but applied to every session stored in the sessions area across all projects. This is the tool for pruning outdated sessions from projects you no longer work in.
40
+
41
+ #### `session-manager:clean:older-than <duration>`
42
+ Deletes local sessions older than a specific duration. The argument accepts either full units like `5days`, `2weeks`, `12hours` or shorthand forms like `5d`, `2w`, `12h`. This is useful when you want to remove sessions using an ad hoc retention threshold instead of the saved day limit.
43
+
44
+ #### `session-manager:clean:older-than:all <duration>`
45
+ The same duration rule as `session-manager:clean:older-than`, but applied to all sessions in the sessions area across every project.
46
+
47
+ #### `session-manager:delete-last <count>`
48
+ Deletes the most recent N local sessions. The argument is an integer from 1 to 10, which makes it a quick recovery tool for removing only the newest session files when you want to clean up by hand.
49
+
50
+ #### `session-manager:delete-last:all <count>`
51
+ Deletes the most recent N sessions across every project in the sessions area. Like the local variant, the count is an integer from 1 to 10. A completion hint labels each option as "last N in every project" so it is easy to tell apart from the project-scoped command.
52
+
53
+ #### `session-manager:series <action>`
54
+ Coordinates the session-series lifecycle. The available actions are:
55
+
56
+ - `create` create a new series and a first session inside it, then persist the resulting session metadata so PI can restore the series context later.
57
+ - `new` — add a new session to an existing series and keep the series record updated.
58
+ - `continue` inspect the currently active session entry, recover its series, and start the next session in that same chain.
59
+ - `delete` remove a series and all local session files whose names start with that series prefix. This is the safest way to remove a series; avoid editing the config file directly.
60
+
61
+ ### Deleted session report
62
+ Every manual cleanup command (local and `:all`) finishes by presenting what was removed. Sessions are sorted by project name — derived from the deepest folder segment of each session's working directory — then by modified time inside each project, and rendered as a grouped listing:
63
+
64
+ ```
65
+ Removed 3 session(s):
66
+ project-a
67
+ Refactor Auth--Create JWT Token
68
+ project-b
69
+ Fix Memory Leak--Patch Heap Snapshot
70
+ UI Migration--Move Button Component
71
+ ```
72
+
73
+ ### Features
74
+
75
+ #### Startup lifecycle coordination
76
+ The extension listens to PI session startup and reload events to restore persisted session-series data before the rest of the session flow continues. That lets PI reopen the correct session name and custom entry even after a new process starts.
77
+
78
+ #### Persistent session-series state
79
+ When a series session is created, the extension writes a small temp file in the OS temp directory. On the next session start, it consumes that file, applies the stored session name and entry, and then removes the temp file so the state only applies once.
80
+
81
+ #### Configured cleanup rules
82
+ Settings are persisted through [@juanibiapina/pi-extension-settings](https://www.npmjs.com/package/@juanibiapina/pi-extension-settings). The `Session Deletion Day Limit` setting controls the automatic inactivity cleanup threshold and can be changed from PI with the `/extension-settings` command (default: 3 days). The series/title structure per working directory is remembered in the same store under the `pi-session-manager` extension name.
83
+
84
+ Treat these stored values as internal state. Do not edit them manually unless you are debugging the package itself. If you need to remove a series, use `session-manager:series delete` instead of changing the stored settings.
85
+
86
+ The package is designed to work with local session files only, so it should never be treated as a remote or shared-session cleanup tool.
87
+
88
+ ### Developer notes
89
+
90
+ - Package metadata lives in `package.json` and identifies this as a PI extension package.
91
+ - The implementation is in `extensions/index.ts`.
92
+ - Tests live alongside the extension in `extensions/index.test.ts`.
93
+ - `scripts/create-extension.ts` is a small helper for scaffolding a new extension file under `extensions/`.
94
+
95
+ ### Assets in this repository
96
+
97
+ - `extensions/` — extension implementation and tests
98
+ - `scripts/` — helper script for creating new extension files
99
+ - No `prompts/`, `skills/`, or `themes/` directories are present in this package
@@ -11,6 +11,10 @@ import {
11
11
  handleSessionCleanOlderThan,
12
12
  handleSessionDeleteLast,
13
13
  handleSessionSeries,
14
+ formatDeletedSessionsListing,
15
+ getSessionProjectName,
16
+ sortSessionsByProjectName,
17
+ presentDeletedSessions,
14
18
  getSessionEntryWithSeries,
15
19
  getSessionSeriesDataTempPath,
16
20
  persistSessionSeriesData,
@@ -226,6 +230,131 @@ class SessionManagerConfiguratorMock implements $SessionManagerConfigurator {
226
230
  }
227
231
  }
228
232
 
233
+ describe("deleted session reporting", () => {
234
+ type SessionOverrides = {
235
+ [K in keyof SessionInfo]?: SessionInfo[K] | undefined;
236
+ };
237
+
238
+ const buildSession = (overrides: SessionOverrides = {}): SessionInfo =>
239
+ ({
240
+ path: "/path/to/session",
241
+ id: "session-id",
242
+ cwd: "/user/work/project-a",
243
+ name: "Session A",
244
+ parentSessionPath: "/path/to/parent",
245
+ created: new Date(0),
246
+ modified: new Date(0),
247
+ messageCount: 1,
248
+ firstMessage: "Hello from session A",
249
+ allMessagesText: "Full history for session A",
250
+ ...overrides,
251
+ }) as SessionInfo;
252
+
253
+ it("derives the project name from the deepest cwd segment", () => {
254
+ const posixSession = buildSession({ cwd: "/user/work/project-a" });
255
+ const windowsSession = buildSession({
256
+ cwd: "C:\\Users\\bvlou\\projects\\project-b",
257
+ });
258
+
259
+ expect(getSessionProjectName(posixSession)).toBe("project-a");
260
+ expect(getSessionProjectName(windowsSession)).toBe("project-b");
261
+ });
262
+
263
+ it("sorts sessions by project name before modified time", () => {
264
+ const projectBSession = buildSession({
265
+ id: "project-b-session",
266
+ name: "Project B Session",
267
+ cwd: "/user/work/project-b",
268
+ modified: new Date(1000),
269
+ });
270
+ const projectAOldestSession = buildSession({
271
+ id: "project-a-oldest",
272
+ name: "Project A Oldest",
273
+ cwd: "/user/work/project-a",
274
+ modified: new Date(1000),
275
+ });
276
+ const projectARecentSession = buildSession({
277
+ id: "project-a-recent",
278
+ name: "Project A Recent",
279
+ cwd: "/user/work/project-a",
280
+ modified: new Date(5000),
281
+ });
282
+
283
+ expect(
284
+ sortSessionsByProjectName([
285
+ projectBSession,
286
+ projectARecentSession,
287
+ projectAOldestSession,
288
+ ]),
289
+ ).toEqual([projectAOldestSession, projectARecentSession, projectBSession]);
290
+ });
291
+
292
+ it("formats deleted sessions grouped under sorted project names", () => {
293
+ const projectBSession = buildSession({
294
+ name: "Project B Session",
295
+ cwd: "/user/work/project-b",
296
+ });
297
+ const projectASession = buildSession({
298
+ name: "Project A Session",
299
+ cwd: "/user/work/project-a",
300
+ });
301
+
302
+ expect(
303
+ formatDeletedSessionsListing([projectBSession, projectASession]),
304
+ ).toBe(
305
+ [
306
+ "Removed 2 session(s):",
307
+ "project-a",
308
+ " Project A Session",
309
+ "project-b",
310
+ " Project B Session",
311
+ ].join("\n"),
312
+ );
313
+ });
314
+
315
+ it("falls back to first message then id when a session has no name", () => {
316
+ const unnamedSession = buildSession({ name: undefined });
317
+
318
+ expect(formatDeletedSessionsListing([unnamedSession])).toBe(
319
+ ["Removed 1 session(s):", "project-a", " Hello from session A"].join(
320
+ "\n",
321
+ ),
322
+ );
323
+ });
324
+
325
+ it("notifies nothing was deleted when the deletion list is empty", () => {
326
+ const context = {
327
+ ui: {
328
+ notify: vi.fn<ExtensionUIContext["notify"]>(),
329
+ },
330
+ } satisfies MockExtenstionCommandContext;
331
+
332
+ presentDeletedSessions([], castToExtensionContext(context));
333
+
334
+ expect(context.ui.notify).toHaveBeenCalledWith(
335
+ "No sessions matched, so nothing was deleted.",
336
+ "info",
337
+ );
338
+ });
339
+
340
+ it("presents the formatted listing when sessions were deleted", () => {
341
+ const context = {
342
+ ui: {
343
+ notify: vi.fn<ExtensionUIContext["notify"]>(),
344
+ },
345
+ } satisfies MockExtenstionCommandContext;
346
+
347
+ const deletedSession = buildSession();
348
+
349
+ presentDeletedSessions([deletedSession], castToExtensionContext(context));
350
+
351
+ expect(context.ui.notify).toHaveBeenCalledWith(
352
+ formatDeletedSessionsListing([deletedSession]),
353
+ "info",
354
+ );
355
+ });
356
+ });
357
+
229
358
  // THis is written like this so that I can use the outline to find tests
230
359
  const test = it
231
360
  .extend("sessions", () => {
@@ -449,7 +578,7 @@ describe("handleSessionCleanOlderThan", () => {
449
578
  );
450
579
 
451
580
  expect(context.ui.notify).toHaveBeenCalledWith(
452
- `Deleteing sessions that are from ${durationRecord.integer} ${durationRecord.unit} ago`,
581
+ `Deleting sessions that are from ${durationRecord.integer} ${durationRecord.unit} ago`,
453
582
  );
454
583
 
455
584
  expect(
@@ -551,8 +680,8 @@ describe("handleSessionSeries", () => {
551
680
  getSessionEntryWithSeries() {
552
681
  return undefined;
553
682
  },
554
- removeSessionFiles() {
555
- return;
683
+ removeSessionFiles(sessions) {
684
+ return sessions;
556
685
  },
557
686
  },
558
687
  castToExtensionContext(context),
@@ -609,8 +738,8 @@ describe("handleSessionSeries", () => {
609
738
  getSessionEntryWithSeries() {
610
739
  return undefined;
611
740
  },
612
- removeSessionFiles() {
613
- return;
741
+ removeSessionFiles(sessions) {
742
+ return sessions;
614
743
  },
615
744
  },
616
745
  castToExtensionContext(context),
@@ -644,8 +773,8 @@ describe("handleSessionSeries", () => {
644
773
  getSessionEntryWithSeries() {
645
774
  return undefined;
646
775
  },
647
- removeSessionFiles() {
648
- return;
776
+ removeSessionFiles(sessions) {
777
+ return sessions;
649
778
  },
650
779
  },
651
780
  castToExtensionContext(context),
@@ -711,8 +840,8 @@ describe("handleSessionSeries", () => {
711
840
  getSessionEntryWithSeries() {
712
841
  return undefined;
713
842
  },
714
- removeSessionFiles() {
715
- return;
843
+ removeSessionFiles(sessions) {
844
+ return sessions;
716
845
  },
717
846
  },
718
847
  castToExtensionContext(context),
@@ -936,8 +1065,8 @@ describe("handleSessionSeries", () => {
936
1065
  getSessionEntryWithSeries() {
937
1066
  return undefined;
938
1067
  },
939
- removeSessionFiles() {
940
- return;
1068
+ removeSessionFiles(sessions) {
1069
+ return sessions;
941
1070
  },
942
1071
  },
943
1072
  castToExtensionContext(context),
@@ -1016,8 +1145,8 @@ describe("handleSessionSeries", () => {
1016
1145
  getSessionEntryWithSeries() {
1017
1146
  return undefined;
1018
1147
  },
1019
- removeSessionFiles() {
1020
- return;
1148
+ removeSessionFiles(sessions) {
1149
+ return sessions;
1021
1150
  },
1022
1151
  },
1023
1152
  castToExtensionContext(context),
@@ -1086,8 +1215,8 @@ describe("handleSessionSeries", () => {
1086
1215
  getSessionEntryWithSeries() {
1087
1216
  return undefined;
1088
1217
  },
1089
- removeSessionFiles() {
1090
- return;
1218
+ removeSessionFiles(sessions) {
1219
+ return sessions;
1091
1220
  },
1092
1221
  },
1093
1222
  castToExtensionContext(context),
@@ -1153,8 +1282,8 @@ describe("handleSessionSeries", () => {
1153
1282
  } as SessionSeriesEntry;
1154
1283
  },
1155
1284
  sessionManagerConfigurator: new SessionManagerConfiguratorMock(),
1156
- removeSessionFiles() {
1157
- return;
1285
+ removeSessionFiles(sessions) {
1286
+ return sessions;
1158
1287
  },
1159
1288
  },
1160
1289
  castToExtensionContext(context),
@@ -1245,8 +1374,8 @@ describe("handleSessionSeries", () => {
1245
1374
  getSessionEntryWithSeries,
1246
1375
  sessionManagerConfigurator,
1247
1376
 
1248
- removeSessionFiles() {
1249
- return;
1377
+ removeSessionFiles(sessions) {
1378
+ return sessions;
1250
1379
  },
1251
1380
  },
1252
1381
  castToExtensionContext(context),