@howaboua/pi-notes-compaction 0.0.16 → 0.0.17

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.
@@ -0,0 +1,312 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ readdirSync,
7
+ readFileSync,
8
+ renameSync,
9
+ rmdirSync,
10
+ unlinkSync,
11
+ writeFileSync,
12
+ } from "node:fs";
13
+ import { hostname } from "node:os";
14
+ import { dirname, isAbsolute, join, resolve } from "node:path";
15
+ import { setTimeout } from "node:timers/promises";
16
+ import { fileURLToPath } from "node:url";
17
+ import { cleanSparseSession } from "./session-pruning-cleanup.mjs";
18
+ import {
19
+ cleanupHeader,
20
+ cleanupPaths,
21
+ tryCleanupLock,
22
+ } from "./session-pruning-state.mjs";
23
+
24
+ /** @typedef {{pid:number; host:string; start:string; sessionId:string}} Owner */
25
+ const host = hostname();
26
+
27
+ /** Linux start time prevents a recycled PID from impersonating an owner.
28
+ * @param {number} pid
29
+ */
30
+ function processStart(pid) {
31
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
32
+ return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? "";
33
+ }
34
+
35
+ /** @param {Owner} owner */
36
+ function alive(owner) {
37
+ if (owner.host !== host) return true;
38
+ try {
39
+ return processStart(owner.pid) === owner.start;
40
+ } catch (error) {
41
+ if (missing(error)) return false;
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ /** @param {unknown} error */
47
+ function missing(error) {
48
+ return (
49
+ error instanceof Error &&
50
+ "code" in error &&
51
+ (error.code === "ENOENT" || error.code === "ESRCH")
52
+ );
53
+ }
54
+
55
+ /** @param {unknown} value @returns {value is Owner} */
56
+ function isOwner(value) {
57
+ if (!value || typeof value !== "object") return false;
58
+ const data = /** @type {Record<string,unknown>} */ (value);
59
+ return (
60
+ Number.isSafeInteger(data["pid"]) &&
61
+ Number(data["pid"]) > 0 &&
62
+ typeof data["host"] === "string" &&
63
+ typeof data["start"] === "string" &&
64
+ data["start"].length > 0 &&
65
+ typeof data["sessionId"] === "string"
66
+ );
67
+ }
68
+
69
+ /** Keep a positive claim while a saved session has a live Notes runtime.
70
+ * @param {string|undefined} file @param {string} sessionId
71
+ * @returns {(()=>void)|undefined}
72
+ */
73
+ function registerCleanupOwner(file, sessionId) {
74
+ if (process.platform !== "linux" || !file || !existsSync(file)) return;
75
+ const owner = {
76
+ pid: process.pid,
77
+ host,
78
+ start: processStart(process.pid),
79
+ sessionId,
80
+ };
81
+ const directory = cleanupPaths(file).owners;
82
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
83
+ const entry = join(
84
+ directory,
85
+ `${encodeURIComponent(host)}-${owner.pid}-${owner.start}-${randomUUID()}.json`,
86
+ );
87
+ writeFileSync(entry, JSON.stringify(owner), { mode: 0o600 });
88
+ const release = () => {
89
+ try {
90
+ unlinkSync(entry);
91
+ } catch (error) {
92
+ if (!missing(error)) throw error;
93
+ }
94
+ try {
95
+ rmdirSync(directory);
96
+ } catch (error) {
97
+ if (
98
+ !missing(error) &&
99
+ !(
100
+ error instanceof Error &&
101
+ "code" in error &&
102
+ error.code === "ENOTEMPTY"
103
+ )
104
+ )
105
+ throw error;
106
+ }
107
+ };
108
+ const onExit = () => {
109
+ // A failed best-effort release remains a stale claim; the worker removes
110
+ // it only after proving this PID/start identity has ended.
111
+ try {
112
+ release();
113
+ } catch {
114
+ /* Never turn normal Pi exit into a cleanup failure. */
115
+ }
116
+ };
117
+ process.once("exit", onExit);
118
+ return () => {
119
+ process.off("exit", onExit);
120
+ release();
121
+ };
122
+ }
123
+
124
+ /** @param {unknown} header @param {string} sessionId */
125
+ function generation(header, sessionId) {
126
+ if (
127
+ !header ||
128
+ typeof header !== "object" ||
129
+ !("id" in header) ||
130
+ header.id !== sessionId
131
+ )
132
+ throw new Error("Session identity changed during startup.");
133
+ if (!("notesPruning" in header) || header.notesPruning === undefined) return;
134
+ const marker = header.notesPruning;
135
+ if (
136
+ !marker ||
137
+ typeof marker !== "object" ||
138
+ !("generation" in marker) ||
139
+ typeof marker.generation !== "string"
140
+ )
141
+ throw new Error("Session pruning generation could not be validated.");
142
+ return marker.generation;
143
+ }
144
+
145
+ /** The manager is loaded before extension hooks. Serialize claim establishment
146
+ * with cleanup, then detect a rewrite that won before this startup could claim.
147
+ * @param {string|undefined} file @param {string} sessionId @param {unknown} loadedHeader
148
+ */
149
+ export async function admitSessionCleanup(file, sessionId, loadedHeader) {
150
+ if (process.platform !== "linux" || !file || !existsSync(file)) return;
151
+ const deadline = Date.now() + 120_000;
152
+ let unlock = tryCleanupLock(file);
153
+ while (!unlock) {
154
+ if (Date.now() >= deadline)
155
+ throw new Error(
156
+ `Session cleanup did not release ${JSON.stringify(cleanupPaths(file).lock)}. Verify no cleanup is active before removing a stale lock, then restart Pi.`,
157
+ );
158
+ await setTimeout(25);
159
+ unlock = tryCleanupLock(file);
160
+ }
161
+ try {
162
+ const raw = cleanupHeader(file);
163
+ const release = registerCleanupOwner(file, sessionId);
164
+ return {
165
+ release,
166
+ stale: generation(raw, sessionId) !== generation(loadedHeader, sessionId),
167
+ };
168
+ } finally {
169
+ unlock();
170
+ }
171
+ }
172
+
173
+ /** Do not delete records from another live manager of this exact saved session.
174
+ * Unknown/foreign claims are intentionally conservative. Unregistered foreign
175
+ * JSONL writers are outside the extension's ownership, as with live pruning.
176
+ * @param {string} file
177
+ */
178
+ function checkOwners(file) {
179
+ const directory = cleanupPaths(file).owners;
180
+ let entries;
181
+ try {
182
+ entries = readdirSync(directory);
183
+ } catch (error) {
184
+ if (missing(error)) return;
185
+ throw error;
186
+ }
187
+ for (const name of entries) {
188
+ const path = join(directory, name);
189
+ let owner;
190
+ try {
191
+ owner = JSON.parse(readFileSync(path, "utf8"));
192
+ } catch (error) {
193
+ if (missing(error)) continue;
194
+ throw error;
195
+ }
196
+ if (!isOwner(owner))
197
+ throw new Error(
198
+ "Session cleanup found an unrecognised live-session claim. Retired payloads remain pruned.",
199
+ );
200
+ if (alive(owner))
201
+ throw new Error(
202
+ "Session record cleanup was skipped because another process still owns this session. It will retry when that session exits.",
203
+ );
204
+ try {
205
+ unlinkSync(path);
206
+ } catch (error) {
207
+ if (!missing(error)) throw error;
208
+ }
209
+ }
210
+ }
211
+
212
+ /** @param {string} path @param {string} sessionId */
213
+ export function previousCleanupFailure(path, sessionId) {
214
+ try {
215
+ const value = JSON.parse(readFileSync(path, "utf8"));
216
+ unlinkSync(path);
217
+ return value.sessionId === sessionId && typeof value.error === "string"
218
+ ? value.error
219
+ : undefined;
220
+ } catch (error) {
221
+ if (missing(error)) return;
222
+ throw error;
223
+ }
224
+ }
225
+
226
+ /** @param {string} path @param {string} sessionId @param {unknown} error */
227
+ export function recordCleanupFailure(path, sessionId, error) {
228
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
229
+ const temp = `${path}.${process.pid}.tmp`;
230
+ writeFileSync(
231
+ temp,
232
+ JSON.stringify({
233
+ sessionId,
234
+ timestamp: new Date().toISOString().slice(0, 16) + "Z",
235
+ error: error instanceof Error ? error.message : String(error),
236
+ }),
237
+ { mode: 0o600 },
238
+ );
239
+ renameSync(temp, path);
240
+ }
241
+
242
+ /** Schedule without holding Pi open; this worker does not touch the graph until
243
+ * the real owning process exits, not merely when shutdown hooks finish.
244
+ * @param {string} file @param {string} sessionId @param {string} statusPath
245
+ */
246
+ export async function scheduleSessionCleanup(file, sessionId, statusPath) {
247
+ if (!existsSync(file)) return;
248
+ if (process.platform !== "linux")
249
+ throw new Error(
250
+ "Automatic session record cleanup is unavailable on this platform. Retired payloads remain pruned.",
251
+ );
252
+ const owner = {
253
+ pid: process.pid,
254
+ host,
255
+ start: processStart(process.pid),
256
+ sessionId,
257
+ };
258
+ const child = spawn(
259
+ "node",
260
+ [fileURLToPath(import.meta.url), file, JSON.stringify(owner), statusPath],
261
+ {
262
+ detached: true,
263
+ stdio: "ignore",
264
+ windowsHide: true,
265
+ },
266
+ );
267
+ await new Promise((resolve, reject) => {
268
+ child.once("error", reject);
269
+ child.once("spawn", resolve);
270
+ });
271
+ child.unref();
272
+ }
273
+
274
+ /** @param {string} file @param {Owner} owner @param {string} statusPath */
275
+ async function afterExit(file, owner, statusPath) {
276
+ try {
277
+ const deadline = Date.now() + 120_000;
278
+ while (alive(owner)) {
279
+ if (Date.now() >= deadline)
280
+ throw new Error(
281
+ "Session record cleanup was skipped because Pi did not exit. It will retry on the next normal exit.",
282
+ );
283
+ await setTimeout(250);
284
+ }
285
+ await cleanSparseSession(file, owner.sessionId, () => checkOwners(file));
286
+ try {
287
+ unlinkSync(statusPath);
288
+ } catch (error) {
289
+ if (!missing(error)) throw error;
290
+ }
291
+ } catch (error) {
292
+ recordCleanupFailure(statusPath, owner.sessionId, error);
293
+ }
294
+ }
295
+
296
+ if (
297
+ process.argv[1] &&
298
+ resolve(process.argv[1]) === fileURLToPath(import.meta.url)
299
+ ) {
300
+ const [file, encoded, statusPath] = process.argv.slice(2);
301
+ const owner = encoded && JSON.parse(encoded);
302
+ if (
303
+ !file ||
304
+ !statusPath ||
305
+ !isAbsolute(statusPath) ||
306
+ !isOwner(owner) ||
307
+ owner.host !== host ||
308
+ process.platform !== "linux"
309
+ )
310
+ throw new Error("Invalid after-exit session cleanup request.");
311
+ await afterExit(file, owner, statusPath);
312
+ }
@@ -159,7 +159,7 @@ export async function openSessionPruningSettings(
159
159
  theme.bold(" Session auto-pruning"),
160
160
  "",
161
161
  ...wrap(
162
- "Runs once after a new context window's first completed turn commits its checkpoint. Settings follow this session on resume; new and forked sessions start Off. Forks made before restarting can retain unpruned history.",
162
+ `Retired payloads are pruned after a new window's first completed turn. ${process.platform === "linux" ? "Empty records are removed automatically after Pi exits." : "Physical record cleanup requires Linux."} Settings follow this session on resume; new and forked sessions start Off. Forks made before restarting can retain unpruned history.`,
163
163
  ),
164
164
  "",
165
165
  ...wrap(RESTART_NOTICE),
@@ -0,0 +1,133 @@
1
+ import { createReadStream } from "node:fs";
2
+ import { createInterface } from "node:readline";
3
+ import {
4
+ isTreeArchiveManifestData,
5
+ TREE_ARCHIVE_ENTRY_TYPE,
6
+ } from "./tree-archive-manifest.mjs";
7
+
8
+ /** @typedef {import("@earendil-works/pi-coding-agent").SessionEntry} SessionEntry */
9
+ /** @typedef {import("@earendil-works/pi-coding-agent").SessionHeader & {notesPruning?:{version:number;sessionId:string;generation:string}}} Header */
10
+
11
+ /** A finite complete source, never a live SessionManager.
12
+ * @param {string} path @param {number} size
13
+ * @param {(entry:SessionEntry|Header, raw:string)=>void|Promise<void>} visit
14
+ */
15
+ export async function scanSparseSource(path, size, visit) {
16
+ if (!size) throw new Error("Session file is empty.");
17
+ const input = createReadStream(path, { start: 0, end: size - 1 });
18
+ const lines = createInterface({ input, crlfDelay: Infinity });
19
+ let bytes = 0;
20
+ try {
21
+ for await (const raw of lines) {
22
+ bytes += Buffer.byteLength(raw) + 1;
23
+ const entry = JSON.parse(raw);
24
+ if (
25
+ !entry ||
26
+ typeof entry.id !== "string" ||
27
+ typeof entry.timestamp !== "string" ||
28
+ typeof entry.type !== "string" ||
29
+ (entry.type !== "session" &&
30
+ entry.parentId !== null &&
31
+ typeof entry.parentId !== "string")
32
+ )
33
+ throw new Error("Session contains an invalid record.");
34
+ await visit(entry, raw);
35
+ }
36
+ if (bytes !== size)
37
+ throw new Error("Session requires complete LF-delimited records.");
38
+ } finally {
39
+ lines.close();
40
+ input.destroy();
41
+ }
42
+ }
43
+
44
+ /** Remove only existing retired tombstones; retention/content decisions stay with
45
+ * live Notes pruning. Keep navigation anchors and supported structured references.
46
+ * @param {string} path @param {number} size
47
+ */
48
+ export async function planSparsePruning(path, size) {
49
+ /** @type {Map<string,string|null>} */
50
+ const parents = new Map();
51
+ /** @type {Map<string,number>} */
52
+ const children = new Map();
53
+ const removed = new Set();
54
+ const anchors = new Set();
55
+ /** @type {Header|undefined} */
56
+ let header;
57
+ let last;
58
+ await scanSparseSource(path, size, (entry) => {
59
+ if (entry.type === "session") {
60
+ if (header || parents.size || entry.version !== 3)
61
+ throw new Error("Session requires a single version 3 header first.");
62
+ header = entry;
63
+ return;
64
+ }
65
+ if (
66
+ !header ||
67
+ parents.has(entry.id) ||
68
+ (entry.parentId !== null && !parents.has(entry.parentId))
69
+ )
70
+ throw new Error(
71
+ "Session has duplicate IDs or invalid source-order ancestry.",
72
+ );
73
+ last = entry.id;
74
+ parents.set(entry.id, entry.parentId);
75
+ if (entry.parentId === null) anchors.add(entry.id);
76
+ else children.set(entry.parentId, (children.get(entry.parentId) ?? 0) + 1);
77
+ if (
78
+ entry.type === "custom" &&
79
+ entry.customType === "notes-compaction:pruned:v1"
80
+ )
81
+ removed.add(entry.id);
82
+ for (const id of references(entry)) anchors.add(id);
83
+ });
84
+ if (!header) throw new Error("Session header is missing.");
85
+ const marker = header.notesPruning;
86
+ if (
87
+ marker !== undefined &&
88
+ (!marker ||
89
+ marker.version !== 1 ||
90
+ marker.sessionId !== header.id ||
91
+ typeof marker.generation !== "string")
92
+ )
93
+ throw new Error(
94
+ "The saved session has an invalid pruning generation. Session cleanup was skipped.",
95
+ );
96
+ if (last) anchors.add(last);
97
+ for (const id of parents.keys()) {
98
+ if (children.get(id) !== 1) anchors.add(id);
99
+ }
100
+ for (const id of anchors) removed.delete(id);
101
+ /** @type {Map<string,string|null>} */
102
+ const nearest = new Map();
103
+ for (const [id, parent] of parents) {
104
+ // Source-order ancestry makes this a linear pass, including long chains.
105
+ const ancestor = parent === null ? null : (nearest.get(parent) ?? null);
106
+ nearest.set(id, removed.has(id) ? ancestor : id);
107
+ parents.set(id, ancestor);
108
+ }
109
+ return { removed, parents, header };
110
+ }
111
+
112
+ /** @param {SessionEntry} entry @returns {string[]} */
113
+ function references(entry) {
114
+ if (entry.type === "compaction") return [entry.firstKeptEntryId];
115
+ if (entry.type === "branch_summary") return [entry.fromId];
116
+ if (entry.type === "label" || entry.type === "context_edit")
117
+ return [entry.targetId];
118
+ if (entry.type === "custom" && entry.customType === TREE_ARCHIVE_ENTRY_TYPE) {
119
+ if (!isTreeArchiveManifestData(entry.data))
120
+ throw new Error(
121
+ "Invalid Tree archive metadata; session history was not removed.",
122
+ );
123
+ const data = entry.data;
124
+ return [
125
+ data.boundaryEntryId,
126
+ data.summaryEntryId,
127
+ data.archivedLeafId,
128
+ ...(data.branchBaseId ? [data.branchBaseId] : []),
129
+ ...(data.compactionEntryId ? [data.compactionEntryId] : []),
130
+ ];
131
+ }
132
+ return [];
133
+ }
@@ -0,0 +1,123 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ closeSync,
4
+ lstatSync,
5
+ mkdirSync,
6
+ openSync,
7
+ readSync,
8
+ realpathSync,
9
+ unlinkSync,
10
+ } from "node:fs";
11
+ import { dirname, join, resolve } from "node:path";
12
+
13
+ /** @param {string} root */
14
+ function privateRoot(root) {
15
+ const stat = lstatSync(root);
16
+ if (
17
+ !stat.isDirectory() ||
18
+ stat.uid !== process.getuid?.() ||
19
+ (stat.mode & 0o077) !== 0
20
+ )
21
+ throw new Error(
22
+ `Session cleanup state ${JSON.stringify(root)} must be a private directory owned by this user. Restore its ownership/permissions before restarting Pi.`,
23
+ );
24
+ }
25
+
26
+ /** Exact-file coordination stays outside session directories so inactive Notes
27
+ * never needs to write beside a read-only saved session. No global process scan.
28
+ * @param {string} file
29
+ */
30
+ function cleanupKey(file) {
31
+ let canonical;
32
+ try {
33
+ canonical = realpathSync(file);
34
+ } catch (error) {
35
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
36
+ throw error;
37
+ canonical = resolve(file);
38
+ }
39
+ return createHash("sha256").update(canonical).digest("hex");
40
+ }
41
+
42
+ /** @param {string} file @param {string} storageDirectory */
43
+ export function cleanupStatus(file, storageDirectory) {
44
+ return resolve(
45
+ storageDirectory,
46
+ "session-cleanup",
47
+ `${cleanupKey(file)}.json`,
48
+ );
49
+ }
50
+
51
+ /** @param {string} file */
52
+ export function cleanupPaths(file) {
53
+ // Automatic cleanup is Linux-only. A fixed OS location, not TMPDIR, keeps
54
+ // two local Pi launch environments in the same admission domain.
55
+ const directory = join(
56
+ "/tmp",
57
+ `pi-notes-cleanup-${process.getuid?.() ?? "user"}`,
58
+ cleanupKey(file),
59
+ );
60
+ try {
61
+ privateRoot(dirname(directory));
62
+ } catch (error) {
63
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
64
+ throw error;
65
+ }
66
+ return {
67
+ directory,
68
+ owners: join(directory, "owners"),
69
+ lock: join(directory, "lock"),
70
+ };
71
+ }
72
+
73
+ /** @param {string} file */
74
+ function ensureCleanupState(file) {
75
+ const paths = cleanupPaths(file);
76
+ const root = dirname(paths.directory);
77
+ mkdirSync(root, { recursive: true, mode: 0o700 });
78
+ privateRoot(root);
79
+ mkdirSync(paths.directory, { recursive: true, mode: 0o700 });
80
+ return paths;
81
+ }
82
+
83
+ /** Shared by startup admission and the after-exit writer.
84
+ * @param {string} file @returns {(()=>void)|undefined}
85
+ */
86
+ export function tryCleanupLock(file) {
87
+ const paths = ensureCleanupState(file);
88
+ try {
89
+ const fd = openSync(paths.lock, "wx", 0o600);
90
+ closeSync(fd);
91
+ return () => {
92
+ unlinkSync(paths.lock);
93
+ };
94
+ } catch (error) {
95
+ if (error instanceof Error && "code" in error && error.code === "EEXIST")
96
+ return;
97
+ throw error;
98
+ }
99
+ }
100
+
101
+ /** Pi accepts large headers. Read exactly the first complete source record,
102
+ * accumulating pieces once instead of imposing a smaller extension-only limit.
103
+ * @param {string} file @returns {unknown}
104
+ */
105
+ export function cleanupHeader(file) {
106
+ const fd = openSync(file, "r");
107
+ /** @type {Buffer[]} */
108
+ const pieces = [];
109
+ let position = 0;
110
+ try {
111
+ while (true) {
112
+ const buffer = Buffer.alloc(8192);
113
+ const read = readSync(fd, buffer, 0, buffer.length, position);
114
+ if (!read) throw new Error("The saved session header is incomplete.");
115
+ position += read;
116
+ const end = buffer.subarray(0, read).indexOf(10);
117
+ pieces.push(buffer.subarray(0, end < 0 ? read : end));
118
+ if (end >= 0) return JSON.parse(Buffer.concat(pieces).toString("utf8"));
119
+ }
120
+ } finally {
121
+ closeSync(fd);
122
+ }
123
+ }
@@ -1,10 +1,16 @@
1
+ import { dirname } from "node:path";
1
2
  import type {
2
3
  ExtensionAPI,
3
4
  ExtensionContext,
4
5
  } from "@earendil-works/pi-coding-agent";
5
6
  import type { HistorySearch } from "./history-search.js";
7
+ import {
8
+ recordCleanupFailure,
9
+ scheduleSessionCleanup,
10
+ } from "./session-pruning-exit.mjs";
6
11
  import { planSessionPruning } from "./session-pruning-plan.js";
7
12
  import { RESTART_NOTICE } from "./session-pruning-policy.js";
13
+ import { cleanupStatus } from "./session-pruning-state.mjs";
8
14
  import { commitSessionPruning } from "./session-pruning-transaction.js";
9
15
  import type { NotesStore } from "./store.js";
10
16
  import { windowDetails } from "./windows.js";
@@ -50,9 +56,36 @@ export class SessionPruning {
50
56
  this.pending = undefined;
51
57
  }
52
58
  register(): void {
53
- this.pi.on("session_shutdown", () => {
59
+ this.pi.on("session_shutdown", async (event, ctx) => {
54
60
  this.epoch++;
55
61
  this.pending = undefined;
62
+ if (event.reason !== "quit") {
63
+ return;
64
+ }
65
+ const file = ctx.sessionManager.getSessionFile();
66
+ if (!file) return;
67
+ const statusPath = cleanupStatus(file, dirname(this.store.path));
68
+ try {
69
+ const policy = this.store.pruningPolicy(
70
+ ctx.sessionManager.getSessionId(),
71
+ );
72
+ if (process.platform === "linux" && (policy.windows || policy.days))
73
+ await scheduleSessionCleanup(
74
+ file,
75
+ ctx.sessionManager.getSessionId(),
76
+ statusPath,
77
+ );
78
+ } catch (error) {
79
+ const message = `Session record cleanup could not start: ${String(error)}. Check local session storage and that Node.js is available as node, then exit Pi normally again. Retired payloads remain pruned.`;
80
+ recordCleanupFailure(
81
+ statusPath,
82
+ ctx.sessionManager.getSessionId(),
83
+ new Error(message),
84
+ );
85
+ ctx.ui.notify(message, "warning");
86
+ } finally {
87
+ this.store.close();
88
+ }
56
89
  });
57
90
  this.pi.on("agent_start", (_event, ctx) => {
58
91
  // Pi emits agent_start before persisting incoming messages. Notes already
@@ -35,25 +35,25 @@ export function createNotesSettingsControls(
35
35
  : `${Math.ceil(minutes / 60)}h`;
36
36
  const list = new SettingsList(
37
37
  [
38
- {
39
- id: "sessionPruning",
40
- label: "Session auto-pruning",
41
- currentValue: "select…",
42
- values: ["select…", "settings…"],
43
- description:
44
- "Per-session history limits and Run now. Memory savings require restarting Pi.",
45
- },
46
38
  {
47
39
  id: "active",
48
- label: "Active",
49
- description: `Whitelist matches exact model IDs from any provider. Edit modelWhitelist in ${options.settingsPath}, then reload Pi. Example: ["gpt-6-luna", "gpt-6.1-sol"].`,
40
+ label: "Enabled",
41
+ description: `On uses all models. Whitelist matches exact model IDs from any provider. Edit modelWhitelist in ${options.settingsPath}, then reload Pi.`,
50
42
  currentValue:
51
43
  settings.active === "off"
52
44
  ? "Off"
53
45
  : settings.active === "all"
54
- ? "All models"
46
+ ? "On"
55
47
  : "Whitelist",
56
- values: ["Off", "All models", "Whitelist"],
48
+ values: ["Off", "On", "Whitelist"],
49
+ },
50
+ {
51
+ id: "sessionPruning",
52
+ label: "Session auto-pruning",
53
+ currentValue: "select…",
54
+ values: ["select…", "settings…"],
55
+ description:
56
+ "Per-session history limits and Run now. Memory savings require restarting Pi.",
57
57
  },
58
58
  {
59
59
  id: "roles",
@@ -157,11 +157,7 @@ export function createNotesSettingsControls(
157
157
  save({
158
158
  ...current,
159
159
  active:
160
- value === "Off"
161
- ? "off"
162
- : value === "All models"
163
- ? "all"
164
- : "whitelist",
160
+ value === "Off" ? "off" : value === "On" ? "all" : "whitelist",
165
161
  });
166
162
  else if (id === "sharing")
167
163
  save({ ...current, shareSubagentContext: value === "on" });