@howaboua/pi-notes-compaction 0.0.15 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +21 -0
  3. package/README.md +17 -2
  4. package/index.ts +8 -0
  5. package/package.json +16 -13
  6. package/src/board/context-briefing.ts +245 -0
  7. package/src/board/delivery.ts +85 -0
  8. package/src/guidance.ts +121 -0
  9. package/src/notes/AGENTS.md +27 -0
  10. package/src/{activation.ts → notes/activation.ts} +8 -10
  11. package/src/{attachment-sharing.ts → notes/attachment-sharing.ts} +1 -1
  12. package/src/{attachment-snapshot.ts → notes/attachment-snapshot.ts} +33 -20
  13. package/src/{context-sharing.ts → notes/context-sharing.ts} +7 -2
  14. package/src/{extension-hooks.ts → notes/extension-hooks.ts} +1 -12
  15. package/src/{extension-sharing.ts → notes/extension-sharing.ts} +1 -1
  16. package/src/notes/feature.ts +234 -0
  17. package/src/notes/history-search-pruning.mjs +154 -0
  18. package/src/{history-search-worker.mjs → notes/history-search-worker.mjs} +1 -1
  19. package/src/{history-windows.ts → notes/history-windows.ts} +10 -22
  20. package/src/{history.ts → notes/history.ts} +6 -5
  21. package/src/{index.ts → notes/index.ts} +20 -11
  22. package/src/{integrations.ts → notes/integrations.ts} +19 -3
  23. package/src/{lifecycle.ts → notes/lifecycle.ts} +0 -2
  24. package/src/{note-query.ts → notes/note-query.ts} +3 -5
  25. package/src/notes/note-result.ts +119 -0
  26. package/src/{note-save-marker.ts → notes/note-save-marker.ts} +3 -1
  27. package/src/{notes-lookup.ts → notes/notes-lookup.ts} +1 -1
  28. package/src/{query-executor.ts → notes/query-executor.ts} +7 -2
  29. package/src/{query-input.ts → notes/query-input.ts} +1 -0
  30. package/src/{remote.ts → notes/remote.ts} +1 -1
  31. package/src/{saved-session-access.ts → notes/saved-session-access.ts} +14 -10
  32. package/src/{saved-session.ts → notes/saved-session.ts} +31 -15
  33. package/src/notes/saved-sharing-records.ts +170 -0
  34. package/src/notes/session-pruning-cleanup.mjs +163 -0
  35. package/src/notes/session-pruning-exit.mjs +312 -0
  36. package/src/{session-pruning-screen.ts → notes/session-pruning-screen.ts} +1 -1
  37. package/src/notes/session-pruning-sparse.mjs +133 -0
  38. package/src/notes/session-pruning-state.mjs +123 -0
  39. package/src/{session-pruning.ts → notes/session-pruning.ts} +39 -6
  40. package/src/{settings-command.ts → notes/settings-command.ts} +29 -42
  41. package/src/{settings-controls.ts → notes/settings-controls.ts} +61 -75
  42. package/src/{settings-screen.ts → notes/settings-screen.ts} +25 -11
  43. package/src/{settings.ts → notes/settings.ts} +37 -6
  44. package/src/{shared-notes.ts → notes/shared-notes.ts} +21 -13
  45. package/src/{shared-session-reader.ts → notes/shared-session-reader.ts} +8 -11
  46. package/src/{sharing-service.ts → notes/sharing-service.ts} +1 -1
  47. package/src/{tool-contracts.ts → notes/tool-contracts.ts} +71 -44
  48. package/src/{tools.ts → notes/tools.ts} +2 -2
  49. package/src/{tree-handoff-read.ts → notes/tree-handoff-read.ts} +47 -32
  50. package/src/{window-message.ts → notes/window-message.ts} +8 -25
  51. package/src/settings-navigation.ts +11 -0
  52. package/src/timestamps.ts +3 -0
  53. package/tsconfig.json +9 -0
  54. package/src/history-search-pruning.mjs +0 -120
  55. package/src/note-result.ts +0 -70
  56. package/src/saved-sharing-records.ts +0 -135
  57. /package/src/{agent-identity.ts → notes/agent-identity.ts} +0 -0
  58. /package/src/{binding-startup.ts → notes/binding-startup.ts} +0 -0
  59. /package/src/{bridge.ts → notes/bridge.ts} +0 -0
  60. /package/src/{compaction-projection.ts → notes/compaction-projection.ts} +0 -0
  61. /package/src/{context-owner.ts → notes/context-owner.ts} +0 -0
  62. /package/src/{fresh-checkpoint.ts → notes/fresh-checkpoint.ts} +0 -0
  63. /package/src/{fresh-notes.ts → notes/fresh-notes.ts} +0 -0
  64. /package/src/{history-search-protocol.ts → notes/history-search-protocol.ts} +0 -0
  65. /package/src/{history-search.ts → notes/history-search.ts} +0 -0
  66. /package/src/{idle-admission.ts → notes/idle-admission.ts} +0 -0
  67. /package/src/{model-role-config.ts → notes/model-role-config.ts} +0 -0
  68. /package/src/{model-role-screen.ts → notes/model-role-screen.ts} +0 -0
  69. /package/src/{model-roles.ts → notes/model-roles.ts} +0 -0
  70. /package/src/{notes.ts → notes/notes.ts} +0 -0
  71. /package/src/{rollover.ts → notes/rollover.ts} +0 -0
  72. /package/src/{saved-session-index.mjs → notes/saved-session-index.mjs} +0 -0
  73. /package/src/{saved-session.mjs → notes/saved-session.mjs} +0 -0
  74. /package/src/{session-pruning-content.ts → notes/session-pruning-content.ts} +0 -0
  75. /package/src/{session-pruning-plan.ts → notes/session-pruning-plan.ts} +0 -0
  76. /package/src/{session-pruning-policy.ts → notes/session-pruning-policy.ts} +0 -0
  77. /package/src/{session-pruning-source.ts → notes/session-pruning-source.ts} +0 -0
  78. /package/src/{session-pruning-transaction.ts → notes/session-pruning-transaction.ts} +0 -0
  79. /package/src/{sqlite.mjs → notes/sqlite.mjs} +0 -0
  80. /package/src/{store.ts → notes/store.ts} +0 -0
  81. /package/src/{task-boundary.ts → notes/task-boundary.ts} +0 -0
  82. /package/src/{tree-archive-manifest.mjs → notes/tree-archive-manifest.mjs} +0 -0
  83. /package/src/{tree-archive.ts → notes/tree-archive.ts} +0 -0
  84. /package/src/{tree-checkpoint.ts → notes/tree-checkpoint.ts} +0 -0
  85. /package/src/{window-checkpoint.ts → notes/window-checkpoint.ts} +0 -0
  86. /package/src/{windows.ts → notes/windows.ts} +0 -0
@@ -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";
@@ -44,15 +50,42 @@ export class SessionPruning {
44
50
  return `${ctx.sessionManager.getSessionId()}:${details.identity.currentWindowId}`;
45
51
  }
46
52
  }
53
+ start(ctx: ExtensionContext): void {
54
+ this.epoch++;
55
+ this.observed = this.persistedWindow(ctx);
56
+ this.pending = undefined;
57
+ }
47
58
  register(): void {
48
- this.pi.on("session_start", (_event, ctx) => {
49
- this.epoch++;
50
- this.observed = this.persistedWindow(ctx);
51
- this.pending = undefined;
52
- });
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
@@ -1,34 +1,35 @@
1
1
  import type {
2
- ExtensionAPI,
3
2
  ExtensionCommandContext,
3
+ ExtensionContext,
4
4
  } from "@earendil-works/pi-coding-agent";
5
- import type { NotesActivation } from "./activation.js";
6
- import type { HistorySearch } from "./history-search.js";
7
- import type { NotesLifecycle } from "./lifecycle.js";
8
- import type { createModelRoles } from "./model-roles.js";
5
+ import type { SettingsTab } from "../settings-navigation.js";
6
+ import type { NotesRuntime } from "./index.js";
9
7
  import { sessionRef } from "./notes.js";
10
- import type { SessionPruning } from "./session-pruning.js";
11
8
  import type { NotesSettings } from "./settings.js";
12
9
  import { openNotesSettings } from "./settings-screen.js";
13
10
  import type { NotesStore } from "./store.js";
14
11
 
15
- export function registerNotesSettingsCommand(
16
- pi: ExtensionAPI,
17
- activation: NotesActivation,
18
- lifecycle: NotesLifecycle,
12
+ export interface NotesSettingsOwner {
13
+ readonly settings: NotesSettings;
14
+ readonly runtime: NotesRuntime | undefined;
15
+ save(settings: NotesSettings, ctx: ExtensionContext): Promise<void>;
16
+ start(ctx: ExtensionContext): Promise<NotesRuntime>;
17
+ }
18
+
19
+ export function createNotesSettings(
20
+ owner: NotesSettingsOwner,
19
21
  store: NotesStore,
20
- search: HistorySearch,
21
22
  settingsPath: string,
22
- sessionPruning: SessionPruning,
23
- roles: ReturnType<typeof createModelRoles>,
24
- ): void {
23
+ boardTab = true,
24
+ ) {
25
25
  const open = async (
26
26
  ctx: ExtensionCommandContext,
27
- initial: "notes" | "roles",
28
- ) => {
27
+ initial: "notes" | "roles" = "notes",
28
+ ): Promise<SettingsTab | undefined> => {
29
29
  let tab = initial;
30
30
  while (true) {
31
31
  if (tab === "roles") {
32
+ const { roles } = await owner.start(ctx);
32
33
  if ((await roles.command("", ctx)) !== "notes") return;
33
34
  tab = "notes";
34
35
  }
@@ -36,9 +37,10 @@ export function registerNotesSettingsCommand(
36
37
  ctx.ui.notify("Notes settings require interactive Pi.", "warning");
37
38
  return;
38
39
  }
39
- const save = (value: NotesSettings) => activation.save(value, ctx);
40
+ const save = (value: NotesSettings) => owner.save(value, ctx);
40
41
  const prune = async () => {
41
42
  await ctx.waitForIdle();
43
+ const { search } = await owner.start(ctx);
42
44
  store.updateFile(sessionRef(ctx));
43
45
  const sources = store.sessionFiles();
44
46
  const result = store.prune(ctx.sessionManager.getSessionId());
@@ -53,7 +55,8 @@ export function registerNotesSettingsCommand(
53
55
  };
54
56
  try {
55
57
  const next = await openNotesSettings(ctx, {
56
- settings: () => activation.settings,
58
+ boardTab,
59
+ settings: () => owner.settings,
57
60
  save,
58
61
  settingsPath,
59
62
  prune,
@@ -63,21 +66,24 @@ export function registerNotesSettingsCommand(
63
66
  store.setPruningPolicy(ctx.sessionManager.getSessionId(), value),
64
67
  run: async (interaction) => {
65
68
  await ctx.waitForIdle();
69
+ const { sessionPruning } = await owner.start(ctx);
66
70
  await sessionPruning.run(ctx, true, interaction);
67
71
  },
68
72
  },
69
73
  status: () => {
70
74
  const counts = store.status();
75
+ const activation = owner.runtime?.activation;
76
+ const lifecycle = owner.runtime?.lifecycle;
71
77
  return [
72
- lifecycle.active
78
+ lifecycle?.active
73
79
  ? "Continuity active"
74
- : `Continuity inactive: ${activation.unavailable ?? (activation.ready ? "model not in whitelist" : "not initialized")}`,
80
+ : `Continuity inactive: ${activation?.unavailable ?? (owner.settings.active === "off" ? "off" : "model not in whitelist")}`,
75
81
  `${counts.sessions} sessions · ${counts.revisions} note revisions · ${counts.cachedResponses} cached responses`,
76
- `Hybrid lookup: ${lifecycle.bridge?.lookup ? "available" : "unavailable"} · Encrypted delivery: ${lifecycle.bridge?.projectResult ? "available" : "unavailable"}`,
82
+ `Hybrid lookup: ${lifecycle?.bridge?.lookup ? "available" : "unavailable"} · Encrypted delivery: ${lifecycle?.bridge?.projectResult ? "available" : "unavailable"}`,
77
83
  ];
78
84
  },
79
85
  });
80
- if (next !== "roles") return;
86
+ if (next !== "roles") return next;
81
87
  tab = "roles";
82
88
  } catch (error) {
83
89
  ctx.ui.notify(`Notes settings failed: ${String(error)}`, "error");
@@ -85,24 +91,5 @@ export function registerNotesSettingsCommand(
85
91
  }
86
92
  }
87
93
  };
88
- pi.registerCommand("notes", {
89
- description: "Manage local notes and context rollover",
90
- handler: async (args, ctx) => {
91
- if (args.trim()) {
92
- ctx.ui.notify("Use /notes to open settings.", "info");
93
- return;
94
- }
95
- await open(ctx, "notes");
96
- },
97
- });
98
- pi.registerCommand("roles", {
99
- description: "View model roles and JSON configuration guidance",
100
- handler: async (args, ctx) => {
101
- if (args.trim()) {
102
- await roles.command(args, ctx);
103
- return;
104
- }
105
- await open(ctx, "roles");
106
- },
107
- });
94
+ return open;
108
95
  }
@@ -10,14 +10,20 @@ import {
10
10
  } from "./settings.js";
11
11
  import { TASK_BOUNDARY_PRESETS, taskBoundaryLabel } from "./task-boundary.js";
12
12
 
13
+ export type NotesSettingsAction =
14
+ | "close"
15
+ | "prune"
16
+ | "sessionPruning"
17
+ | "roles"
18
+ | { settings: NotesSettings; selected: string };
19
+
13
20
  export function createNotesSettingsControls(
14
21
  ctx: ExtensionContext,
15
22
  options: {
16
23
  settings: () => NotesSettings;
17
24
  settingsPath: string;
18
- save: (settings: NotesSettings) => void;
19
25
  },
20
- done: (action: "close" | "prune" | "sessionPruning") => void,
26
+ done: (action: NotesSettingsAction) => void,
21
27
  requestRender: () => void,
22
28
  ) {
23
29
  const settings = options.settings();
@@ -29,6 +35,18 @@ export function createNotesSettingsControls(
29
35
  : `${Math.ceil(minutes / 60)}h`;
30
36
  const list = new SettingsList(
31
37
  [
38
+ {
39
+ id: "active",
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.`,
42
+ currentValue:
43
+ settings.active === "off"
44
+ ? "Off"
45
+ : settings.active === "all"
46
+ ? "On"
47
+ : "Whitelist",
48
+ values: ["Off", "On", "Whitelist"],
49
+ },
32
50
  {
33
51
  id: "sessionPruning",
34
52
  label: "Session auto-pruning",
@@ -38,11 +56,10 @@ export function createNotesSettingsControls(
38
56
  "Per-session history limits and Run now. Memory savings require restarting Pi.",
39
57
  },
40
58
  {
41
- id: "active",
42
- label: "Active",
43
- 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"].`,
44
- currentValue: settings.active === "all" ? "All models" : "Whitelist",
45
- values: ["All models", "Whitelist"],
59
+ id: "roles",
60
+ label: "Model roles",
61
+ currentValue: "select…",
62
+ values: ["select…", "view…"],
46
63
  },
47
64
  {
48
65
  id: "sharing",
@@ -113,6 +130,10 @@ export function createNotesSettingsControls(
113
130
  5,
114
131
  getSettingsListTheme(),
115
132
  (id, value) => {
133
+ if (id === "roles") {
134
+ done("roles");
135
+ return;
136
+ }
116
137
  if (id === "sessionPruning") {
117
138
  done("sessionPruning");
118
139
  return;
@@ -130,75 +151,40 @@ export function createNotesSettingsControls(
130
151
  list.updateValue(id, taskBoundaryLabel(current.taskBoundaryReminder));
131
152
  return;
132
153
  }
133
- try {
134
- if (id === "active")
135
- options.save({
136
- ...current,
137
- active: value === "All models" ? "all" : "whitelist",
138
- });
139
- else if (id === "sharing")
140
- options.save({
141
- ...current,
142
- shareSubagentContext: value === "on",
143
- });
144
- else if (id === "noteSaveMarkers")
145
- options.save({ ...current, noteSaveMarkers: value === "on" });
146
- else if (id === "rankedHistorySearch")
147
- options.save({
148
- ...current,
149
- rankedHistorySearch: value === "on",
150
- });
151
- else if (id === "compact")
152
- options.save({ ...current, normalCompaction: value === "on" });
153
- else if (id === "newWindowRequests") {
154
- const newWindowRequests = NEW_WINDOW_REQUESTS.find(
155
- (mode) => mode === value,
156
- );
157
- if (newWindowRequests)
158
- options.save({ ...current, newWindowRequests });
159
- } else if (id === "taskBoundaryReminder")
160
- options.save({
161
- ...current,
162
- taskBoundaryReminder:
163
- TASK_BOUNDARY_PRESETS.find(
164
- (tokens) => taskBoundaryLabel(tokens) === value,
165
- ) ?? current.taskBoundaryReminder,
166
- });
167
- else {
168
- const idleMinutes = IDLE_MINUTES.find(
169
- (minutes) => idleValue(minutes) === value,
170
- );
171
- if (idleMinutes !== undefined)
172
- options.save({ ...current, idleMinutes });
173
- }
174
- } catch (error) {
175
- if (id === "rankedHistorySearch") {
176
- list.updateValue(id, current.rankedHistorySearch ? "on" : "off");
177
- } else
178
- list.updateValue(
179
- id,
180
- id === "active"
181
- ? current.active === "all"
182
- ? "All models"
183
- : "Whitelist"
184
- : id === "taskBoundaryReminder"
185
- ? taskBoundaryLabel(current.taskBoundaryReminder)
186
- : id === "newWindowRequests"
187
- ? current.newWindowRequests
188
- : id === "noteSaveMarkers"
189
- ? current.noteSaveMarkers
190
- ? "on"
191
- : "off"
192
- : id === "compact"
193
- ? current.normalCompaction
194
- ? "on"
195
- : "off"
196
- : idleValue(current.idleMinutes),
197
- );
198
- ctx.ui.notify(
199
- `Could not save notes settings: ${String(error)}`,
200
- "error",
154
+ const save = (settings: NotesSettings) =>
155
+ done({ settings, selected: id });
156
+ if (id === "active")
157
+ save({
158
+ ...current,
159
+ active:
160
+ value === "Off" ? "off" : value === "On" ? "all" : "whitelist",
161
+ });
162
+ else if (id === "sharing")
163
+ save({ ...current, shareSubagentContext: value === "on" });
164
+ else if (id === "noteSaveMarkers")
165
+ save({ ...current, noteSaveMarkers: value === "on" });
166
+ else if (id === "rankedHistorySearch")
167
+ save({ ...current, rankedHistorySearch: value === "on" });
168
+ else if (id === "compact")
169
+ save({ ...current, normalCompaction: value === "on" });
170
+ else if (id === "newWindowRequests") {
171
+ const newWindowRequests = NEW_WINDOW_REQUESTS.find(
172
+ (mode) => mode === value,
173
+ );
174
+ if (newWindowRequests) save({ ...current, newWindowRequests });
175
+ } else if (id === "taskBoundaryReminder")
176
+ save({
177
+ ...current,
178
+ taskBoundaryReminder:
179
+ TASK_BOUNDARY_PRESETS.find(
180
+ (tokens) => taskBoundaryLabel(tokens) === value,
181
+ ) ?? current.taskBoundaryReminder,
182
+ });
183
+ else {
184
+ const idleMinutes = IDLE_MINUTES.find(
185
+ (minutes) => idleValue(minutes) === value,
201
186
  );
187
+ if (idleMinutes !== undefined) save({ ...current, idleMinutes });
202
188
  }
203
189
  requestRender();
204
190
  },
@@ -10,27 +10,33 @@ import {
10
10
  type SessionPruningSettings,
11
11
  } from "./session-pruning-screen.js";
12
12
  import type { NotesSettings } from "./settings.js";
13
- import { createNotesSettingsControls } from "./settings-controls.js";
13
+ import {
14
+ createNotesSettingsControls,
15
+ type NotesSettingsAction,
16
+ } from "./settings-controls.js";
14
17
 
15
- type ScreenAction = "close" | "prune" | "sessionPruning" | "roles";
18
+ type ScreenAction = NotesSettingsAction | "board";
16
19
 
17
20
  export async function openNotesSettings(
18
21
  ctx: ExtensionContext,
19
22
  options: {
23
+ boardTab?: boolean;
20
24
  settings: () => NotesSettings;
21
25
  settingsPath: string;
22
- save: (settings: NotesSettings) => void;
26
+ save: (settings: NotesSettings) => Promise<void>;
23
27
  status: () => string[];
24
28
  prune: () => Promise<void>;
25
29
  sessionPruning: SessionPruningSettings;
26
30
  },
27
- ): Promise<"roles" | undefined> {
31
+ ): Promise<"roles" | "board" | undefined> {
32
+ let selected = "active";
28
33
  while (true) {
29
34
  const action = await ctx.ui.custom<ScreenAction>(
30
35
  (tui, theme, _kb, done) => {
31
36
  const list = createNotesSettingsControls(ctx, options, done, () =>
32
37
  tui.requestRender(),
33
38
  );
39
+ list.selectItem(selected);
34
40
  return {
35
41
  render: (width) => {
36
42
  const wrap = (text: string) =>
@@ -40,7 +46,7 @@ export async function openNotesSettings(
40
46
  const rule = theme.fg("accent", "─".repeat(Math.max(0, width)));
41
47
  return [
42
48
  rule,
43
- ` ${theme.bold("Notes")} / ${theme.fg("dim", "Roles")}`,
49
+ ` ${theme.bold("Notes")} / ${theme.fg("dim", options.boardTab === false ? "Roles" : "Board")}`,
44
50
  "",
45
51
  ...options
46
52
  .status()
@@ -48,10 +54,6 @@ export async function openNotesSettings(
48
54
  wrap(line).map((part) => theme.fg("dim", part)),
49
55
  ),
50
56
  "",
51
- ...wrap(
52
- "This extension works best on GPT6+ models. For other models we recommend switching the active option to whitelist or switching normal compaction on to work alongside the notes system.",
53
- ),
54
- "",
55
57
  ...list.render(width).slice(0, -2),
56
58
  "",
57
59
  ...wrap(
@@ -69,7 +71,7 @@ export async function openNotesSettings(
69
71
  matchesKey(data, Key.tab) ||
70
72
  matchesKey(data, Key.shift(Key.tab))
71
73
  ) {
72
- done("roles");
74
+ done(options.boardTab === false ? "roles" : "board");
73
75
  return;
74
76
  }
75
77
  list.handleInput(data);
@@ -78,8 +80,20 @@ export async function openNotesSettings(
78
80
  };
79
81
  },
80
82
  );
83
+ if (typeof action === "object") {
84
+ selected = action.selected;
85
+ try {
86
+ await options.save(action.settings);
87
+ } catch (error) {
88
+ ctx.ui.notify(
89
+ `Could not save notes settings: ${String(error)}`,
90
+ "error",
91
+ );
92
+ }
93
+ continue;
94
+ }
81
95
  if (action === "close") return;
82
- if (action === "roles") return "roles";
96
+ if (action === "roles" || action === "board") return action;
83
97
  if (action === "sessionPruning") {
84
98
  await openSessionPruningSettings(ctx, options.sessionPruning);
85
99
  continue;
@@ -1,5 +1,10 @@
1
1
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
- import { dirname } from "node:path";
2
+ import { dirname, join } from "node:path";
3
+ import {
4
+ CONFIG_DIR_NAME,
5
+ type ExtensionContext,
6
+ getAgentDir,
7
+ } from "@earendil-works/pi-coding-agent";
3
8
 
4
9
  // Hour presets store their effective duration, with five minutes of headroom.
5
10
  export const IDLE_MINUTES = [0, 25, 55, 115, 355, 715] as const;
@@ -17,7 +22,7 @@ const DEFAULT_MODEL_WHITELIST = [
17
22
  "gpt-6.1-sol",
18
23
  ];
19
24
  export interface NotesSettings {
20
- active: "all" | "whitelist";
25
+ active: "all" | "whitelist" | "off";
21
26
  modelWhitelist: string[];
22
27
  normalCompaction: boolean;
23
28
  noteSaveMarkers: boolean;
@@ -28,7 +33,32 @@ export interface NotesSettings {
28
33
  taskBoundaryReminder: number;
29
34
  }
30
35
 
31
- export function readSettings(
36
+ export function notesSettingsPath(): string {
37
+ return join(getAgentDir(), "notes-compaction", "settings.json");
38
+ }
39
+
40
+ function legacySettingsPaths(ctx: ExtensionContext): string[] {
41
+ return [
42
+ join(getAgentDir(), "pi-codex-conversion.json"),
43
+ ...(ctx.isProjectTrusted()
44
+ ? [join(ctx.cwd, CONFIG_DIR_NAME, "pi-codex-conversion.json")]
45
+ : []),
46
+ ];
47
+ }
48
+
49
+ export function loadNotesSettings(ctx: ExtensionContext): NotesSettings {
50
+ return readSettings(notesSettingsPath(), legacySettingsPaths(ctx));
51
+ }
52
+
53
+ export function legacyNotesConfigured(ctx: ExtensionContext): boolean {
54
+ const { compaction } = readLegacyPreferences(legacySettingsPaths(ctx));
55
+ return (
56
+ compaction["continuity"] === "notes" ||
57
+ compaction["continuity"] === "notes-and-compaction"
58
+ );
59
+ }
60
+
61
+ function readSettings(
32
62
  path: string,
33
63
  legacyPaths: readonly string[] = [],
34
64
  ): NotesSettings {
@@ -67,9 +97,9 @@ export function readSettings(
67
97
  "Invalid notes settings. Save a setting in /notes, then reload Pi.",
68
98
  );
69
99
  const active = "active" in settings ? settings.active : "all";
70
- if (active !== "all" && active !== "whitelist")
100
+ if (active !== "all" && active !== "whitelist" && active !== "off")
71
101
  throw new Error(
72
- `Invalid active setting in ${path}. Use "all" or "whitelist", then reload Pi.`,
102
+ `Invalid active setting in ${path}. Use "all", "whitelist" or "off", then reload Pi.`,
73
103
  );
74
104
  const modelWhitelist =
75
105
  "modelWhitelist" in settings
@@ -140,7 +170,8 @@ export function modelIsActive(
140
170
  ): boolean {
141
171
  return (
142
172
  settings.active === "all" ||
143
- Boolean(model && settings.modelWhitelist.includes(model.id))
173
+ (settings.active === "whitelist" &&
174
+ Boolean(model && settings.modelWhitelist.includes(model.id)))
144
175
  );
145
176
  }
146
177