@howaboua/pi-notes-compaction 0.0.8 → 0.0.10
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 +31 -5
- package/PCC-INTEGRATION.md +7 -98
- package/README.md +22 -14
- package/package.json +7 -3
- package/src/activation.ts +152 -0
- package/src/agent-identity.ts +119 -0
- package/src/attachment-snapshot.ts +103 -0
- package/src/binding-startup.ts +30 -0
- package/src/bridge.ts +1 -43
- package/src/compaction-projection.ts +88 -0
- package/src/context-owner.ts +103 -0
- package/src/context-sharing.ts +144 -0
- package/src/extension-hooks.ts +198 -0
- package/src/extension-sharing.ts +118 -0
- package/src/fresh-checkpoint.ts +117 -0
- package/src/fresh-notes.ts +141 -26
- package/src/history-search-protocol.ts +39 -0
- package/src/history-search-pruning.mjs +120 -0
- package/src/history-search-worker.mjs +256 -0
- package/src/history-search.ts +269 -0
- package/src/history.ts +219 -48
- package/src/idle-admission.ts +201 -0
- package/src/index.ts +71 -401
- package/src/integrations.ts +159 -0
- package/src/lifecycle.ts +63 -448
- package/src/note-save-marker.ts +112 -0
- package/src/notes-lookup.ts +112 -0
- package/src/notes.ts +25 -30
- package/src/query-executor.ts +190 -0
- package/src/remote.ts +357 -0
- package/src/rollover.ts +212 -0
- package/src/saved-session.ts +44 -7
- package/src/session-pruning-content.ts +237 -0
- package/src/session-pruning-plan.ts +243 -0
- package/src/session-pruning-policy.ts +20 -0
- package/src/session-pruning-screen.ts +130 -0
- package/src/session-pruning-source.ts +44 -0
- package/src/session-pruning-transaction.ts +141 -0
- package/src/session-pruning.ts +142 -0
- package/src/settings-command.ts +77 -0
- package/src/settings-screen.ts +89 -20
- package/src/settings.ts +152 -15
- package/src/shared-notes.ts +37 -14
- package/src/sharing-service.ts +348 -0
- package/src/store.ts +31 -0
- package/src/task-boundary.ts +6 -1
- package/src/tool-contracts.ts +279 -0
- package/src/tools.ts +19 -556
- package/src/tree-archive.ts +149 -0
- package/src/tree-checkpoint.ts +170 -0
- package/src/tree-handoff-read.ts +192 -0
- package/src/window-checkpoint.ts +105 -0
- package/src/windows.ts +28 -8
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
fsyncSync,
|
|
5
|
+
lstatSync,
|
|
6
|
+
openSync,
|
|
7
|
+
readSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
type Stats,
|
|
10
|
+
statSync,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { open } from "node:fs/promises";
|
|
15
|
+
import type {
|
|
16
|
+
ExtensionAPI,
|
|
17
|
+
ExtensionContext,
|
|
18
|
+
} from "@earendil-works/pi-coding-agent";
|
|
19
|
+
import type { PruningPlan } from "./session-pruning-plan.js";
|
|
20
|
+
import {
|
|
21
|
+
pruningContext,
|
|
22
|
+
transformPruningEntry,
|
|
23
|
+
} from "./session-pruning-plan.js";
|
|
24
|
+
import { scanSession } from "./session-pruning-source.js";
|
|
25
|
+
|
|
26
|
+
const MAX_COMMIT_TAIL = 4 * 1024 * 1024;
|
|
27
|
+
|
|
28
|
+
function sameSource(plan: PruningPlan): Stats {
|
|
29
|
+
const current = lstatSync(plan.path);
|
|
30
|
+
if (
|
|
31
|
+
!current.isFile() ||
|
|
32
|
+
current.dev !== plan.source.dev ||
|
|
33
|
+
current.ino !== plan.source.ino ||
|
|
34
|
+
current.size < plan.source.size ||
|
|
35
|
+
(current.size === plan.source.size &&
|
|
36
|
+
current.mtimeMs !== plan.source.mtimeMs)
|
|
37
|
+
)
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Session changed while pruning was prepared. Run now again.",
|
|
40
|
+
);
|
|
41
|
+
return current;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** SDK writes to this already-flushed path are synchronous appends. No await from
|
|
45
|
+
* final identity check through rename: extension/monitor appends cannot interleave.
|
|
46
|
+
* Fork writes a different path; migration rewrites happen before session_start.
|
|
47
|
+
*/
|
|
48
|
+
export async function commitSessionPruning(
|
|
49
|
+
pi: Pick<ExtensionAPI, "appendEntry">,
|
|
50
|
+
ctx: Pick<ExtensionContext, "sessionManager">,
|
|
51
|
+
plan: PruningPlan,
|
|
52
|
+
checkPolicy: () => void = () => {},
|
|
53
|
+
): Promise<{ before: number; after: number }> {
|
|
54
|
+
const valid = () => {
|
|
55
|
+
checkPolicy();
|
|
56
|
+
if (
|
|
57
|
+
ctx.sessionManager.getSessionId() !== plan.sessionId ||
|
|
58
|
+
ctx.sessionManager.getSessionFile() !== plan.path
|
|
59
|
+
)
|
|
60
|
+
throw new Error("Active session changed. Run now again.");
|
|
61
|
+
for (const id of pruningContext(ctx.sessionManager).protectedIds)
|
|
62
|
+
if (plan.ids.has(id) && !plan.protectedIds.has(id))
|
|
63
|
+
throw new Error("Active context changed. Run now again.");
|
|
64
|
+
return sameSource(plan);
|
|
65
|
+
};
|
|
66
|
+
valid();
|
|
67
|
+
const generation = randomUUID();
|
|
68
|
+
pi.appendEntry("notes-session-prune", {
|
|
69
|
+
version: 1,
|
|
70
|
+
sessionId: plan.sessionId,
|
|
71
|
+
generation,
|
|
72
|
+
});
|
|
73
|
+
const temp = `${plan.path}.prune-${generation}.tmp`;
|
|
74
|
+
let output: Awaited<ReturnType<typeof open>> | undefined;
|
|
75
|
+
try {
|
|
76
|
+
output = await open(temp, "wx", plan.source.mode & 0o777);
|
|
77
|
+
const file = output;
|
|
78
|
+
await scanSession(plan.path, plan.source.size, async (entry, raw) => {
|
|
79
|
+
const transformed =
|
|
80
|
+
entry.type === "session"
|
|
81
|
+
? {
|
|
82
|
+
...entry,
|
|
83
|
+
notesPruning: {
|
|
84
|
+
version: 1,
|
|
85
|
+
sessionId: plan.sessionId,
|
|
86
|
+
generation,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: transformPruningEntry(plan, entry);
|
|
90
|
+
await file.writeFile(
|
|
91
|
+
`${transformed === entry ? raw : JSON.stringify(transformed)}\n`,
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
await file.sync();
|
|
95
|
+
await file.close();
|
|
96
|
+
output = undefined;
|
|
97
|
+
// Bounded synchronous commit includes every append since the preview prefix.
|
|
98
|
+
const current = valid();
|
|
99
|
+
const length = current.size - plan.source.size;
|
|
100
|
+
if (length > MAX_COMMIT_TAIL)
|
|
101
|
+
throw new Error("Session grew too much during pruning. Run now again.");
|
|
102
|
+
const input = openSync(plan.path, "r");
|
|
103
|
+
let tail: Buffer;
|
|
104
|
+
try {
|
|
105
|
+
tail = Buffer.alloc(length);
|
|
106
|
+
let offset = 0;
|
|
107
|
+
while (offset < length) {
|
|
108
|
+
const read = readSync(
|
|
109
|
+
input,
|
|
110
|
+
tail,
|
|
111
|
+
offset,
|
|
112
|
+
length - offset,
|
|
113
|
+
plan.source.size + offset,
|
|
114
|
+
);
|
|
115
|
+
if (!read) throw new Error("Session changed during pruning.");
|
|
116
|
+
offset += read;
|
|
117
|
+
}
|
|
118
|
+
} finally {
|
|
119
|
+
closeSync(input);
|
|
120
|
+
}
|
|
121
|
+
if (tail.length && tail.at(-1) !== 10)
|
|
122
|
+
throw new Error("Session has an incomplete append. Run now again.");
|
|
123
|
+
const fd = openSync(temp, "a");
|
|
124
|
+
try {
|
|
125
|
+
if (tail.length) writeFileSync(fd, tail);
|
|
126
|
+
fsyncSync(fd);
|
|
127
|
+
} finally {
|
|
128
|
+
closeSync(fd);
|
|
129
|
+
}
|
|
130
|
+
const after = statSync(temp).size;
|
|
131
|
+
renameSync(temp, plan.path);
|
|
132
|
+
return { before: current.size, after };
|
|
133
|
+
} finally {
|
|
134
|
+
await output?.close();
|
|
135
|
+
try {
|
|
136
|
+
unlinkSync(temp);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { HistorySearch } from "./history-search.js";
|
|
6
|
+
import { planSessionPruning } from "./session-pruning-plan.js";
|
|
7
|
+
import { RESTART_NOTICE } from "./session-pruning-policy.js";
|
|
8
|
+
import { commitSessionPruning } from "./session-pruning-transaction.js";
|
|
9
|
+
import type { NotesStore } from "./store.js";
|
|
10
|
+
import { windowDetails } from "./windows.js";
|
|
11
|
+
|
|
12
|
+
const bytes = (value: number) => `${(value / 1024 / 1024).toFixed(1)} MiB`;
|
|
13
|
+
|
|
14
|
+
export class SessionPruning {
|
|
15
|
+
private running = false;
|
|
16
|
+
private observed: string | undefined;
|
|
17
|
+
private pending: string | undefined;
|
|
18
|
+
private epoch = 0;
|
|
19
|
+
private readonly pi: ExtensionAPI;
|
|
20
|
+
private readonly store: NotesStore;
|
|
21
|
+
private readonly search: HistorySearch;
|
|
22
|
+
private readonly admittedWindow: () => string | undefined;
|
|
23
|
+
constructor(
|
|
24
|
+
pi: ExtensionAPI,
|
|
25
|
+
store: NotesStore,
|
|
26
|
+
search: HistorySearch,
|
|
27
|
+
admittedWindow: () => string | undefined,
|
|
28
|
+
) {
|
|
29
|
+
this.pi = pi;
|
|
30
|
+
this.store = store;
|
|
31
|
+
this.search = search;
|
|
32
|
+
this.admittedWindow = admittedWindow;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private persistedWindow(ctx: ExtensionContext): string | undefined {
|
|
36
|
+
for (const entry of ctx.sessionManager.getBranch().reverse()) {
|
|
37
|
+
const details = windowDetails(entry);
|
|
38
|
+
if (details?.kind === "window")
|
|
39
|
+
return `${ctx.sessionManager.getSessionId()}:${details.identity.currentWindowId}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
register(): void {
|
|
43
|
+
this.pi.on("session_start", (_event, ctx) => {
|
|
44
|
+
this.epoch++;
|
|
45
|
+
this.observed = this.persistedWindow(ctx);
|
|
46
|
+
this.pending = undefined;
|
|
47
|
+
});
|
|
48
|
+
this.pi.on("session_shutdown", () => {
|
|
49
|
+
this.epoch++;
|
|
50
|
+
this.pending = undefined;
|
|
51
|
+
});
|
|
52
|
+
this.pi.on("agent_start", (_event, ctx) => {
|
|
53
|
+
// Pi emits agent_start before persisting incoming messages. Notes already
|
|
54
|
+
// admitted the successor in before_agent_start; confirm its commit below.
|
|
55
|
+
const window = this.admittedWindow();
|
|
56
|
+
const current = window
|
|
57
|
+
? `${ctx.sessionManager.getSessionId()}:${window}`
|
|
58
|
+
: undefined;
|
|
59
|
+
if (current && current !== this.observed) this.pending = current;
|
|
60
|
+
this.observed = current;
|
|
61
|
+
});
|
|
62
|
+
// The successor marker and complete turn_end checkpoint are now committed.
|
|
63
|
+
// Ordinary turns without a new-window admission do no pruning work.
|
|
64
|
+
this.pi.on("agent_settled", async (_event, ctx) => {
|
|
65
|
+
if (!this.pending) return;
|
|
66
|
+
const pending = this.pending;
|
|
67
|
+
this.pending = undefined;
|
|
68
|
+
if (pending === this.persistedWindow(ctx)) await this.run(ctx, false);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async run(ctx: ExtensionContext, manual: boolean): Promise<void> {
|
|
73
|
+
if (this.running) {
|
|
74
|
+
if (manual) ctx.ui.notify("Session pruning is already running.", "info");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.running = true;
|
|
78
|
+
const epoch = this.epoch;
|
|
79
|
+
let historyPruned = false;
|
|
80
|
+
try {
|
|
81
|
+
const policy = this.store.pruningPolicy(
|
|
82
|
+
ctx.sessionManager.getSessionId(),
|
|
83
|
+
);
|
|
84
|
+
if (!policy.windows && !policy.days) {
|
|
85
|
+
if (manual)
|
|
86
|
+
ctx.ui.notify(
|
|
87
|
+
"Session pruning is off. Choose a history or conversation limit first.",
|
|
88
|
+
"info",
|
|
89
|
+
);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const plan = await planSessionPruning(ctx.sessionManager, policy);
|
|
93
|
+
if (!plan.changed) {
|
|
94
|
+
await this.search.pruneSession(plan.sessionId, plan.path);
|
|
95
|
+
if (manual)
|
|
96
|
+
ctx.ui.notify(
|
|
97
|
+
"Nothing to prune under this session's limits.",
|
|
98
|
+
"info",
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (
|
|
103
|
+
manual &&
|
|
104
|
+
!(await ctx.ui.confirm(
|
|
105
|
+
"Prune this session's history?",
|
|
106
|
+
`${bytes(plan.before)} → about ${bytes(plan.after)}; ${plan.changed} records changed. Current context and saved SQLite notes are protected. Older tool activity, injected instructions and exact execution replay are permanently lost. No backup is kept.${plan.opaque.length ? ` Opaque extension state is retained: ${plan.opaque.join(", ")}.` : ""} ${RESTART_NOTICE}`,
|
|
107
|
+
))
|
|
108
|
+
)
|
|
109
|
+
return;
|
|
110
|
+
const currentPolicy = this.store.pruningPolicy(plan.sessionId);
|
|
111
|
+
if (
|
|
112
|
+
currentPolicy.windows !== policy.windows ||
|
|
113
|
+
currentPolicy.days !== policy.days
|
|
114
|
+
)
|
|
115
|
+
throw new Error("Session pruning settings changed. Run now again.");
|
|
116
|
+
const result = await commitSessionPruning(this.pi, ctx, plan, () => {
|
|
117
|
+
if (this.epoch !== epoch)
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Session changed while pruning was prepared. Run now again.",
|
|
120
|
+
);
|
|
121
|
+
const current = this.store.pruningPolicy(plan.sessionId);
|
|
122
|
+
if (current.windows !== policy.windows || current.days !== policy.days)
|
|
123
|
+
throw new Error("Session pruning settings changed. Run now again.");
|
|
124
|
+
});
|
|
125
|
+
historyPruned = true;
|
|
126
|
+
await this.search.pruneSession(plan.sessionId, plan.path);
|
|
127
|
+
ctx.ui.notify(
|
|
128
|
+
`Pruned session history: ${bytes(result.before)} → ${bytes(result.after)}. Saved notes unchanged. ${RESTART_NOTICE}`,
|
|
129
|
+
"info",
|
|
130
|
+
);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
ctx.ui.notify(
|
|
133
|
+
historyPruned
|
|
134
|
+
? `Session history was pruned, but ranked history cleanup did not complete. Run now again to retry cleanup. ${RESTART_NOTICE}`
|
|
135
|
+
: `Session pruning did not complete: ${error instanceof Error ? error.message : String(error)}`,
|
|
136
|
+
"error",
|
|
137
|
+
);
|
|
138
|
+
} finally {
|
|
139
|
+
this.running = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { NotesActivation } from "./activation.js";
|
|
3
|
+
import type { HistorySearch } from "./history-search.js";
|
|
4
|
+
import type { NotesLifecycle } from "./lifecycle.js";
|
|
5
|
+
import { sessionRef } from "./notes.js";
|
|
6
|
+
import type { SessionPruning } from "./session-pruning.js";
|
|
7
|
+
import type { NotesSettings } from "./settings.js";
|
|
8
|
+
import { openNotesSettings } from "./settings-screen.js";
|
|
9
|
+
import type { NotesStore } from "./store.js";
|
|
10
|
+
|
|
11
|
+
export function registerNotesSettingsCommand(
|
|
12
|
+
pi: ExtensionAPI,
|
|
13
|
+
activation: NotesActivation,
|
|
14
|
+
lifecycle: NotesLifecycle,
|
|
15
|
+
store: NotesStore,
|
|
16
|
+
search: HistorySearch,
|
|
17
|
+
settingsPath: string,
|
|
18
|
+
sessionPruning: SessionPruning,
|
|
19
|
+
): void {
|
|
20
|
+
pi.registerCommand("notes", {
|
|
21
|
+
description: "Manage local notes and context rollover",
|
|
22
|
+
handler: async (args, ctx) => {
|
|
23
|
+
if (args.trim()) {
|
|
24
|
+
ctx.ui.notify("Use /notes to open settings.", "info");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!ctx.hasUI) {
|
|
28
|
+
ctx.ui.notify("Notes settings require interactive Pi.", "warning");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const save = (value: NotesSettings) => activation.save(value, ctx);
|
|
32
|
+
const prune = async () => {
|
|
33
|
+
await ctx.waitForIdle();
|
|
34
|
+
store.updateFile(sessionRef(ctx));
|
|
35
|
+
const sources = store.sessionFiles();
|
|
36
|
+
const result = store.prune(ctx.sessionManager.getSessionId());
|
|
37
|
+
const indexed = await search.prune(
|
|
38
|
+
ctx.sessionManager.getSessionId(),
|
|
39
|
+
sources,
|
|
40
|
+
);
|
|
41
|
+
ctx.ui.notify(
|
|
42
|
+
`Pruned ${result.removed} Notes sessions and ${indexed.removed} indexed sessions. Retained ${result.unknownPaths + indexed.unknownPaths} unknown paths and ${result.inaccessible + indexed.inaccessible} inaccessible files.${indexed.storageBusy ? " Index storage cleanup is pending; run Prune again when other agents are idle." : ""}`,
|
|
43
|
+
"info",
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
await openNotesSettings(ctx, {
|
|
48
|
+
settings: () => activation.settings,
|
|
49
|
+
save,
|
|
50
|
+
settingsPath,
|
|
51
|
+
prune,
|
|
52
|
+
sessionPruning: {
|
|
53
|
+
get: () => store.pruningPolicy(ctx.sessionManager.getSessionId()),
|
|
54
|
+
save: (value) =>
|
|
55
|
+
store.setPruningPolicy(ctx.sessionManager.getSessionId(), value),
|
|
56
|
+
run: async () => {
|
|
57
|
+
await ctx.waitForIdle();
|
|
58
|
+
await sessionPruning.run(ctx, true);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
status: () => {
|
|
62
|
+
const counts = store.status();
|
|
63
|
+
return [
|
|
64
|
+
lifecycle.active
|
|
65
|
+
? "Continuity active"
|
|
66
|
+
: `Continuity inactive: ${activation.unavailable ?? (activation.ready ? "model not in whitelist" : "not initialized")}`,
|
|
67
|
+
`${counts.sessions} sessions · ${counts.revisions} note revisions · ${counts.cachedResponses} cached responses`,
|
|
68
|
+
`Hybrid lookup: ${lifecycle.bridge?.lookup ? "available" : "unavailable"} · Encrypted delivery: ${lifecycle.bridge?.projectResult ? "available" : "unavailable"}`,
|
|
69
|
+
];
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
ctx.ui.notify(`Notes settings failed: ${String(error)}`, "error");
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
package/src/settings-screen.ts
CHANGED
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
truncateToWidth,
|
|
8
8
|
wrapTextWithAnsi,
|
|
9
9
|
} from "@earendil-works/pi-tui";
|
|
10
|
+
import {
|
|
11
|
+
openSessionPruningSettings,
|
|
12
|
+
type SessionPruningSettings,
|
|
13
|
+
} from "./session-pruning-screen.js";
|
|
10
14
|
import {
|
|
11
15
|
IDLE_MINUTES,
|
|
12
16
|
NEW_WINDOW_REQUESTS,
|
|
@@ -22,16 +26,29 @@ export async function openNotesSettings(
|
|
|
22
26
|
save: (settings: NotesSettings) => void;
|
|
23
27
|
status: () => string[];
|
|
24
28
|
prune: () => Promise<void>;
|
|
29
|
+
sessionPruning: SessionPruningSettings;
|
|
25
30
|
},
|
|
26
31
|
): Promise<void> {
|
|
27
32
|
while (true) {
|
|
28
|
-
const action = await ctx.ui.custom<"close" | "prune">(
|
|
33
|
+
const action = await ctx.ui.custom<"close" | "prune" | "sessionPruning">(
|
|
29
34
|
(tui, theme, _kb, done) => {
|
|
30
35
|
const settings = options.settings();
|
|
31
36
|
const idleValue = (minutes: number) =>
|
|
32
|
-
minutes === 0
|
|
37
|
+
minutes === 0
|
|
38
|
+
? "Off"
|
|
39
|
+
: minutes < 60
|
|
40
|
+
? `${minutes}m`
|
|
41
|
+
: `${Math.ceil(minutes / 60)}h`;
|
|
33
42
|
const list = new SettingsList(
|
|
34
43
|
[
|
|
44
|
+
{
|
|
45
|
+
id: "sessionPruning",
|
|
46
|
+
label: "Session auto-pruning",
|
|
47
|
+
currentValue: "select…",
|
|
48
|
+
values: ["select…", "settings…"],
|
|
49
|
+
description:
|
|
50
|
+
"Per-session history limits and Run now. Memory savings require restarting Pi.",
|
|
51
|
+
},
|
|
35
52
|
{
|
|
36
53
|
id: "active",
|
|
37
54
|
label: "Active",
|
|
@@ -40,6 +57,28 @@ export async function openNotesSettings(
|
|
|
40
57
|
settings.active === "all" ? "All models" : "Whitelist",
|
|
41
58
|
values: ["All models", "Whitelist"],
|
|
42
59
|
},
|
|
60
|
+
{
|
|
61
|
+
id: "sharing",
|
|
62
|
+
label: "Share subagent context",
|
|
63
|
+
description:
|
|
64
|
+
"Let new child agents share notes and history. Existing families remain connected when off.",
|
|
65
|
+
currentValue: settings.shareSubagentContext ? "on" : "off",
|
|
66
|
+
values: ["off", "on"],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "rankedHistorySearch",
|
|
70
|
+
label: "Ranked history search",
|
|
71
|
+
description:
|
|
72
|
+
"BM25 for earlier user messages and assistant replies. Skips current context and tool activity.",
|
|
73
|
+
currentValue: settings.rankedHistorySearch ? "on" : "off",
|
|
74
|
+
values: ["off", "on"],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "noteSaveMarkers",
|
|
78
|
+
label: "Note-save markers",
|
|
79
|
+
currentValue: settings.noteSaveMarkers ? "on" : "off",
|
|
80
|
+
values: ["off", "on"],
|
|
81
|
+
},
|
|
43
82
|
{
|
|
44
83
|
id: "compact",
|
|
45
84
|
label: "Normal compaction",
|
|
@@ -79,7 +118,7 @@ export async function openNotesSettings(
|
|
|
79
118
|
id: "prune",
|
|
80
119
|
label: "Prune missing sessions",
|
|
81
120
|
description:
|
|
82
|
-
"Remove
|
|
121
|
+
"Remove notes, cached responses and history index entries for missing session files. Keeps the active session, unknown paths and inaccessible files. Confirmation required.",
|
|
83
122
|
currentValue: "select…",
|
|
84
123
|
values: ["select…", "prune…"],
|
|
85
124
|
},
|
|
@@ -87,6 +126,10 @@ export async function openNotesSettings(
|
|
|
87
126
|
5,
|
|
88
127
|
getSettingsListTheme(),
|
|
89
128
|
(id, value) => {
|
|
129
|
+
if (id === "sessionPruning") {
|
|
130
|
+
done("sessionPruning");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
90
133
|
if (id === "prune") {
|
|
91
134
|
done("prune");
|
|
92
135
|
return;
|
|
@@ -112,6 +155,18 @@ export async function openNotesSettings(
|
|
|
112
155
|
...current,
|
|
113
156
|
active: value === "All models" ? "all" : "whitelist",
|
|
114
157
|
});
|
|
158
|
+
else if (id === "sharing")
|
|
159
|
+
options.save({
|
|
160
|
+
...current,
|
|
161
|
+
shareSubagentContext: value === "on",
|
|
162
|
+
});
|
|
163
|
+
else if (id === "noteSaveMarkers")
|
|
164
|
+
options.save({ ...current, noteSaveMarkers: value === "on" });
|
|
165
|
+
else if (id === "rankedHistorySearch")
|
|
166
|
+
options.save({
|
|
167
|
+
...current,
|
|
168
|
+
rankedHistorySearch: value === "on",
|
|
169
|
+
});
|
|
115
170
|
else if (id === "compact")
|
|
116
171
|
options.save({ ...current, normalCompaction: value === "on" });
|
|
117
172
|
else if (id === "newWindowRequests") {
|
|
@@ -136,22 +191,32 @@ export async function openNotesSettings(
|
|
|
136
191
|
options.save({ ...current, idleMinutes });
|
|
137
192
|
}
|
|
138
193
|
} catch (error) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
194
|
+
if (id === "rankedHistorySearch") {
|
|
195
|
+
list.updateValue(
|
|
196
|
+
id,
|
|
197
|
+
current.rankedHistorySearch ? "on" : "off",
|
|
198
|
+
);
|
|
199
|
+
} else
|
|
200
|
+
list.updateValue(
|
|
201
|
+
id,
|
|
202
|
+
id === "active"
|
|
203
|
+
? current.active === "all"
|
|
204
|
+
? "All models"
|
|
205
|
+
: "Whitelist"
|
|
206
|
+
: id === "taskBoundaryReminder"
|
|
207
|
+
? taskBoundaryLabel(current.taskBoundaryReminder)
|
|
208
|
+
: id === "newWindowRequests"
|
|
209
|
+
? current.newWindowRequests
|
|
210
|
+
: id === "noteSaveMarkers"
|
|
211
|
+
? current.noteSaveMarkers
|
|
212
|
+
? "on"
|
|
213
|
+
: "off"
|
|
214
|
+
: id === "compact"
|
|
215
|
+
? current.normalCompaction
|
|
216
|
+
? "on"
|
|
217
|
+
: "off"
|
|
218
|
+
: idleValue(current.idleMinutes),
|
|
219
|
+
);
|
|
155
220
|
ctx.ui.notify(
|
|
156
221
|
`Could not save notes settings: ${String(error)}`,
|
|
157
222
|
"error",
|
|
@@ -203,10 +268,14 @@ export async function openNotesSettings(
|
|
|
203
268
|
},
|
|
204
269
|
);
|
|
205
270
|
if (action === "close") return;
|
|
271
|
+
if (action === "sessionPruning") {
|
|
272
|
+
await openSessionPruningSettings(ctx, options.sessionPruning);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
206
275
|
if (
|
|
207
276
|
await ctx.ui.confirm(
|
|
208
277
|
"Prune missing sessions?",
|
|
209
|
-
"Delete local notes
|
|
278
|
+
"Delete local notes, cached responses and history index entries for missing session files? The active session, unknown paths and inaccessible files are retained.",
|
|
210
279
|
)
|
|
211
280
|
)
|
|
212
281
|
await options.prune();
|