@howaboua/pi-agent-comms 0.0.0-stage → 0.0.1-dev.13.1.gef1ce49691d6
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/INTEGRATION.md +31 -0
- package/LICENSE +21 -0
- package/PCC-INTEGRATION.md +17 -0
- package/README.md +53 -2
- package/dist/viewer/archive.js +249 -0
- package/dist/viewer/config.js +85 -0
- package/dist/viewer/contracts.js +1 -0
- package/dist/viewer/server.js +177 -0
- package/dist/viewer/source.js +29 -0
- package/dist/viewer/web/app.js +88 -0
- package/dist/viewer/web/index.html +41 -0
- package/dist/viewer/web/navigation.js +72 -0
- package/dist/viewer/web/posts.js +105 -0
- package/dist/viewer/web/render.js +147 -0
- package/dist/viewer/web/session.js +86 -0
- package/dist/viewer/web/style.css +517 -0
- package/dist/viewer/web/updates.js +106 -0
- package/docs/BOARD-CHANGELOG.md +49 -0
- package/docs/BOARD.md +124 -0
- package/docs/NOTES-CHANGELOG.md +127 -0
- package/docs/NOTES.md +122 -0
- package/index.ts +21 -0
- package/package.json +75 -5
- package/src/board/AGENTS.md +12 -0
- package/src/board/activity.ts +274 -0
- package/src/board/archive.ts +118 -0
- package/src/board/awareness.ts +179 -0
- package/src/board/briefing.ts +25 -0
- package/src/board/config.ts +192 -0
- package/src/board/consolidation.ts +32 -0
- package/src/board/context-briefing.ts +245 -0
- package/src/board/contract.ts +254 -0
- package/src/board/delivery.ts +85 -0
- package/src/board/feature.ts +91 -0
- package/src/board/identity.ts +238 -0
- package/src/board/integration.ts +55 -0
- package/src/board/paging.ts +54 -0
- package/src/board/protocol.ts +78 -0
- package/src/board/queries.ts +168 -0
- package/src/board/response.ts +82 -0
- package/src/board/runtime/activation.ts +50 -0
- package/src/board/runtime/catchup.ts +96 -0
- package/src/board/runtime/coordinator.ts +311 -0
- package/src/board/runtime/engine.ts +40 -0
- package/src/board/runtime/index.ts +63 -0
- package/src/board/runtime/owner.ts +168 -0
- package/src/board/runtime/routing.ts +152 -0
- package/src/board/runtime/turns.ts +109 -0
- package/src/board/search.ts +95 -0
- package/src/board/settings/panel.ts +193 -0
- package/src/board/store.ts +427 -0
- package/src/board/summaries.ts +124 -0
- package/src/board/summarizer.ts +201 -0
- package/src/board/tool.ts +27 -0
- package/src/board/viewer/AGENTS.md +1 -0
- package/src/board/viewer/archive.ts +308 -0
- package/src/board/viewer/config.ts +111 -0
- package/src/board/viewer/contracts.ts +98 -0
- package/src/board/viewer/index.ts +162 -0
- package/src/board/viewer/server.ts +204 -0
- package/src/board/viewer/source.ts +33 -0
- package/src/board/viewer/web/app.js +88 -0
- package/src/board/viewer/web/index.html +41 -0
- package/src/board/viewer/web/navigation.js +72 -0
- package/src/board/viewer/web/posts.js +105 -0
- package/src/board/viewer/web/render.js +147 -0
- package/src/board/viewer/web/session.js +86 -0
- package/src/board/viewer/web/style.css +517 -0
- package/src/board/viewer/web/updates.js +106 -0
- package/src/guidance.ts +121 -0
- package/src/notes/AGENTS.md +27 -0
- package/src/notes/activation.ts +150 -0
- package/src/notes/agent-identity.ts +221 -0
- package/src/notes/attachment-sharing.ts +165 -0
- package/src/notes/attachment-snapshot.ts +113 -0
- package/src/notes/binding-startup.ts +30 -0
- package/src/notes/bridge.ts +130 -0
- package/src/notes/compaction-projection.ts +88 -0
- package/src/notes/context-owner.ts +99 -0
- package/src/notes/context-sharing.ts +178 -0
- package/src/notes/extension-hooks.ts +200 -0
- package/src/notes/extension-sharing.ts +133 -0
- package/src/notes/feature.ts +168 -0
- package/src/notes/fresh-checkpoint.ts +143 -0
- package/src/notes/fresh-notes.ts +323 -0
- package/src/notes/history-search-protocol.ts +39 -0
- package/src/notes/history-search-pruning.mjs +120 -0
- package/src/notes/history-search-worker.mjs +258 -0
- package/src/notes/history-search.ts +269 -0
- package/src/notes/history-windows.ts +221 -0
- package/src/notes/history.ts +158 -0
- package/src/notes/idle-admission.ts +201 -0
- package/src/notes/index.ts +125 -0
- package/src/notes/integrations.ts +174 -0
- package/src/notes/lifecycle.ts +308 -0
- package/src/notes/model-role-config.ts +79 -0
- package/src/notes/model-role-screen.ts +74 -0
- package/src/notes/model-roles.ts +225 -0
- package/src/notes/note-query.ts +148 -0
- package/src/notes/note-result.ts +88 -0
- package/src/notes/note-save-marker.ts +128 -0
- package/src/notes/notes-lookup.ts +115 -0
- package/src/notes/notes.ts +302 -0
- package/src/notes/query-executor.ts +242 -0
- package/src/notes/query-input.ts +126 -0
- package/src/notes/remote.ts +376 -0
- package/src/notes/rollover.ts +224 -0
- package/src/notes/saved-session-access.ts +117 -0
- package/src/notes/saved-session-index.mjs +83 -0
- package/src/notes/saved-session.mjs +241 -0
- package/src/notes/saved-session.ts +51 -0
- package/src/notes/saved-sharing-records.ts +135 -0
- package/src/notes/session-pruning-content.ts +237 -0
- package/src/notes/session-pruning-plan.ts +243 -0
- package/src/notes/session-pruning-policy.ts +20 -0
- package/src/notes/session-pruning-screen.ts +204 -0
- package/src/notes/session-pruning-source.ts +44 -0
- package/src/notes/session-pruning-transaction.ts +141 -0
- package/src/notes/session-pruning.ts +155 -0
- package/src/notes/settings-command.ts +95 -0
- package/src/notes/settings-controls.ts +199 -0
- package/src/notes/settings-screen.ts +113 -0
- package/src/notes/settings.ts +287 -0
- package/src/notes/shared-notes.ts +411 -0
- package/src/notes/shared-session-reader.ts +143 -0
- package/src/notes/sharing-service.ts +282 -0
- package/src/notes/sqlite.mjs +33 -0
- package/src/notes/store.ts +283 -0
- package/src/notes/task-boundary.ts +37 -0
- package/src/notes/tool-contracts.ts +312 -0
- package/src/notes/tools.ts +148 -0
- package/src/notes/tree-archive-manifest.mjs +27 -0
- package/src/notes/tree-archive.ts +129 -0
- package/src/notes/tree-checkpoint.ts +170 -0
- package/src/notes/tree-handoff-read.ts +192 -0
- package/src/notes/window-checkpoint.ts +105 -0
- package/src/notes/window-message.ts +185 -0
- package/src/notes/windows.ts +272 -0
- package/src/settings-navigation.ts +11 -0
- package/src/timestamps.ts +3 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
Key,
|
|
4
|
+
matchesKey,
|
|
5
|
+
truncateToWidth,
|
|
6
|
+
wrapTextWithAnsi,
|
|
7
|
+
} from "@earendil-works/pi-tui";
|
|
8
|
+
import {
|
|
9
|
+
openSessionPruningSettings,
|
|
10
|
+
type SessionPruningSettings,
|
|
11
|
+
} from "./session-pruning-screen.js";
|
|
12
|
+
import type { NotesSettings } from "./settings.js";
|
|
13
|
+
import {
|
|
14
|
+
createNotesSettingsControls,
|
|
15
|
+
type NotesSettingsAction,
|
|
16
|
+
} from "./settings-controls.js";
|
|
17
|
+
|
|
18
|
+
type ScreenAction = NotesSettingsAction | "board";
|
|
19
|
+
|
|
20
|
+
export async function openNotesSettings(
|
|
21
|
+
ctx: ExtensionContext,
|
|
22
|
+
options: {
|
|
23
|
+
boardTab?: boolean;
|
|
24
|
+
settings: () => NotesSettings;
|
|
25
|
+
settingsPath: string;
|
|
26
|
+
save: (settings: NotesSettings) => Promise<void>;
|
|
27
|
+
status: () => string[];
|
|
28
|
+
prune: () => Promise<void>;
|
|
29
|
+
sessionPruning: SessionPruningSettings;
|
|
30
|
+
},
|
|
31
|
+
): Promise<"roles" | "board" | undefined> {
|
|
32
|
+
let selected = "sessionPruning";
|
|
33
|
+
while (true) {
|
|
34
|
+
const action = await ctx.ui.custom<ScreenAction>(
|
|
35
|
+
(tui, theme, _kb, done) => {
|
|
36
|
+
const list = createNotesSettingsControls(ctx, options, done, () =>
|
|
37
|
+
tui.requestRender(),
|
|
38
|
+
);
|
|
39
|
+
list.selectItem(selected);
|
|
40
|
+
return {
|
|
41
|
+
render: (width) => {
|
|
42
|
+
const wrap = (text: string) =>
|
|
43
|
+
wrapTextWithAnsi(text, Math.max(1, width - 2)).map(
|
|
44
|
+
(line) => ` ${line}`,
|
|
45
|
+
);
|
|
46
|
+
const rule = theme.fg("accent", "─".repeat(Math.max(0, width)));
|
|
47
|
+
return [
|
|
48
|
+
rule,
|
|
49
|
+
` ${theme.bold("Notes & Compaction")} / ${theme.fg("dim", options.boardTab === false ? "Roles" : "Board")}`,
|
|
50
|
+
"",
|
|
51
|
+
...options
|
|
52
|
+
.status()
|
|
53
|
+
.flatMap((line) =>
|
|
54
|
+
wrap(line).map((part) => theme.fg("dim", part)),
|
|
55
|
+
),
|
|
56
|
+
"",
|
|
57
|
+
...wrap(
|
|
58
|
+
"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.",
|
|
59
|
+
),
|
|
60
|
+
"",
|
|
61
|
+
...list.render(width).slice(0, -2),
|
|
62
|
+
"",
|
|
63
|
+
...wrap(
|
|
64
|
+
"Tab switch tab · ↑/↓ select · Enter/Space change · Esc close",
|
|
65
|
+
).map((line) => theme.fg("dim", line)),
|
|
66
|
+
...wrap("Settings saved immediately").map((line) =>
|
|
67
|
+
theme.fg("dim", line),
|
|
68
|
+
),
|
|
69
|
+
rule,
|
|
70
|
+
].map((line) => truncateToWidth(line, width, ""));
|
|
71
|
+
},
|
|
72
|
+
invalidate: () => list.invalidate(),
|
|
73
|
+
handleInput: (data) => {
|
|
74
|
+
if (
|
|
75
|
+
matchesKey(data, Key.tab) ||
|
|
76
|
+
matchesKey(data, Key.shift(Key.tab))
|
|
77
|
+
) {
|
|
78
|
+
done(options.boardTab === false ? "roles" : "board");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
list.handleInput(data);
|
|
82
|
+
tui.requestRender();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
if (typeof action === "object") {
|
|
88
|
+
selected = action.selected;
|
|
89
|
+
try {
|
|
90
|
+
await options.save(action.settings);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
ctx.ui.notify(
|
|
93
|
+
`Could not save notes settings: ${String(error)}`,
|
|
94
|
+
"error",
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (action === "close") return;
|
|
100
|
+
if (action === "roles" || action === "board") return action;
|
|
101
|
+
if (action === "sessionPruning") {
|
|
102
|
+
await openSessionPruningSettings(ctx, options.sessionPruning);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (
|
|
106
|
+
await ctx.ui.confirm(
|
|
107
|
+
"Prune missing sessions?",
|
|
108
|
+
"Delete local notes, cached responses and history index entries for missing session files? The active session, unknown paths and inaccessible files are retained.",
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
await options.prune();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
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";
|
|
8
|
+
|
|
9
|
+
// Hour presets store their effective duration, with five minutes of headroom.
|
|
10
|
+
export const IDLE_MINUTES = [0, 25, 55, 115, 355, 715] as const;
|
|
11
|
+
export type IdleMinutes = (typeof IDLE_MINUTES)[number] | 5 | 15;
|
|
12
|
+
export const NEW_WINDOW_REQUESTS = [
|
|
13
|
+
"off",
|
|
14
|
+
"pi-limits",
|
|
15
|
+
"unrestricted",
|
|
16
|
+
] as const;
|
|
17
|
+
export type NewWindowRequests = (typeof NEW_WINDOW_REQUESTS)[number];
|
|
18
|
+
const DEFAULT_MODEL_WHITELIST = [
|
|
19
|
+
"gpt-6-astra",
|
|
20
|
+
"gpt-6-sol",
|
|
21
|
+
"gpt-6-luna",
|
|
22
|
+
"gpt-6.1-sol",
|
|
23
|
+
];
|
|
24
|
+
export interface NotesSettings {
|
|
25
|
+
active: "all" | "whitelist" | "off";
|
|
26
|
+
modelWhitelist: string[];
|
|
27
|
+
normalCompaction: boolean;
|
|
28
|
+
noteSaveMarkers: boolean;
|
|
29
|
+
rankedHistorySearch: boolean;
|
|
30
|
+
shareSubagentContext: boolean;
|
|
31
|
+
newWindowRequests: NewWindowRequests;
|
|
32
|
+
idleMinutes: IdleMinutes;
|
|
33
|
+
taskBoundaryReminder: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
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(
|
|
62
|
+
path: string,
|
|
63
|
+
legacyPaths: readonly string[] = [],
|
|
64
|
+
): NotesSettings {
|
|
65
|
+
let legacy: ReturnType<typeof readLegacyPreferences> | undefined;
|
|
66
|
+
const preferences = () => (legacy ??= readLegacyPreferences(legacyPaths));
|
|
67
|
+
let source: string;
|
|
68
|
+
try {
|
|
69
|
+
source = readFileSync(path, "utf8");
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
72
|
+
const migrated = readLegacySettings(preferences());
|
|
73
|
+
return (
|
|
74
|
+
migrated ?? {
|
|
75
|
+
active: "all",
|
|
76
|
+
modelWhitelist: [...DEFAULT_MODEL_WHITELIST],
|
|
77
|
+
normalCompaction: false,
|
|
78
|
+
rankedHistorySearch: false,
|
|
79
|
+
noteSaveMarkers: preferences().noteSaveMarkers,
|
|
80
|
+
shareSubagentContext: false,
|
|
81
|
+
newWindowRequests: "unrestricted",
|
|
82
|
+
idleMinutes: 0,
|
|
83
|
+
taskBoundaryReminder: 0,
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
const settings: unknown = JSON.parse(source);
|
|
90
|
+
if (
|
|
91
|
+
!settings ||
|
|
92
|
+
typeof settings !== "object" ||
|
|
93
|
+
!("normalCompaction" in settings) ||
|
|
94
|
+
typeof settings.normalCompaction !== "boolean"
|
|
95
|
+
)
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Invalid notes settings. Save a setting in /notes, then reload Pi.",
|
|
98
|
+
);
|
|
99
|
+
const active = "active" in settings ? settings.active : "all";
|
|
100
|
+
if (active !== "all" && active !== "whitelist" && active !== "off")
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Invalid active setting in ${path}. Use "all", "whitelist" or "off", then reload Pi.`,
|
|
103
|
+
);
|
|
104
|
+
const modelWhitelist =
|
|
105
|
+
"modelWhitelist" in settings
|
|
106
|
+
? settings.modelWhitelist
|
|
107
|
+
: [...DEFAULT_MODEL_WHITELIST];
|
|
108
|
+
if (
|
|
109
|
+
!Array.isArray(modelWhitelist) ||
|
|
110
|
+
!modelWhitelist.every((id): id is string => typeof id === "string")
|
|
111
|
+
)
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Invalid modelWhitelist in ${path}. Use an array of model ID strings, then reload Pi.`,
|
|
114
|
+
);
|
|
115
|
+
const idleMinutes = "idleMinutes" in settings ? settings.idleMinutes : 0;
|
|
116
|
+
const rankedHistorySearch =
|
|
117
|
+
"rankedHistorySearch" in settings ? settings.rankedHistorySearch : false;
|
|
118
|
+
if (typeof rankedHistorySearch !== "boolean")
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Invalid rankedHistorySearch in ${path}. Use true or false, then reload Pi.`,
|
|
121
|
+
);
|
|
122
|
+
const newWindowRequests =
|
|
123
|
+
"newWindowRequests" in settings
|
|
124
|
+
? settings.newWindowRequests
|
|
125
|
+
: "unrestricted";
|
|
126
|
+
if (!NEW_WINDOW_REQUESTS.some((value) => value === newWindowRequests))
|
|
127
|
+
throw new Error(
|
|
128
|
+
"Invalid new window requests setting. Choose off, pi-limits or unrestricted in /notes.",
|
|
129
|
+
);
|
|
130
|
+
const taskBoundaryReminder =
|
|
131
|
+
"taskBoundaryReminder" in settings ? settings.taskBoundaryReminder : 0;
|
|
132
|
+
if (
|
|
133
|
+
typeof taskBoundaryReminder !== "number" ||
|
|
134
|
+
!Number.isSafeInteger(taskBoundaryReminder) ||
|
|
135
|
+
taskBoundaryReminder < 0
|
|
136
|
+
)
|
|
137
|
+
throw new Error(
|
|
138
|
+
"Invalid task-boundary reminder setting. Save a setting in /notes, then reload Pi.",
|
|
139
|
+
);
|
|
140
|
+
if (
|
|
141
|
+
idleMinutes !== 5 &&
|
|
142
|
+
idleMinutes !== 15 &&
|
|
143
|
+
!IDLE_MINUTES.some((value) => value === idleMinutes)
|
|
144
|
+
)
|
|
145
|
+
throw new Error(
|
|
146
|
+
"Invalid idle rollover interval. Set idleMinutes to 0, 25, 55, 115, 355 or 715, then reload Pi.",
|
|
147
|
+
);
|
|
148
|
+
return {
|
|
149
|
+
active,
|
|
150
|
+
modelWhitelist,
|
|
151
|
+
normalCompaction: settings.normalCompaction,
|
|
152
|
+
rankedHistorySearch,
|
|
153
|
+
noteSaveMarkers:
|
|
154
|
+
"noteSaveMarkers" in settings
|
|
155
|
+
? settings.noteSaveMarkers === true
|
|
156
|
+
: preferences().noteSaveMarkers,
|
|
157
|
+
shareSubagentContext:
|
|
158
|
+
"shareSubagentContext" in settings
|
|
159
|
+
? settings.shareSubagentContext === true
|
|
160
|
+
: preferences().compaction["shareSubagentContext"] === true,
|
|
161
|
+
newWindowRequests: newWindowRequests as NewWindowRequests,
|
|
162
|
+
idleMinutes: idleMinutes as IdleMinutes,
|
|
163
|
+
taskBoundaryReminder,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function modelIsActive(
|
|
168
|
+
settings: NotesSettings,
|
|
169
|
+
model?: { id: string },
|
|
170
|
+
): boolean {
|
|
171
|
+
return (
|
|
172
|
+
settings.active === "all" ||
|
|
173
|
+
(settings.active === "whitelist" &&
|
|
174
|
+
Boolean(model && settings.modelWhitelist.includes(model.id)))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function writeSettings(path: string, settings: NotesSettings): void {
|
|
179
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
180
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
181
|
+
writeFileSync(temporary, `${JSON.stringify(settings, null, 2)}\n`, {
|
|
182
|
+
mode: 0o600,
|
|
183
|
+
});
|
|
184
|
+
renameSync(temporary, path);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Import only on first use. An existing Notes settings file always wins. */
|
|
188
|
+
function readLegacySettings(
|
|
189
|
+
preferences: ReturnType<typeof readLegacyPreferences>,
|
|
190
|
+
): NotesSettings | undefined {
|
|
191
|
+
const value = preferences.compaction;
|
|
192
|
+
if (!["notes", "notes-and-compaction"].includes(String(value["continuity"])))
|
|
193
|
+
return;
|
|
194
|
+
const oldIdle = value["idleNotesRollover"];
|
|
195
|
+
const idle = oldIdle === true ? 25 : oldIdle === false ? 0 : (oldIdle ?? 0);
|
|
196
|
+
const requests =
|
|
197
|
+
"newWindowRequests" in value ? value["newWindowRequests"] : "unrestricted";
|
|
198
|
+
const reminder =
|
|
199
|
+
"taskBoundaryReminder" in value ? value["taskBoundaryReminder"] : 0;
|
|
200
|
+
return {
|
|
201
|
+
active: "all",
|
|
202
|
+
modelWhitelist: [...DEFAULT_MODEL_WHITELIST],
|
|
203
|
+
normalCompaction: value["continuity"] === "notes-and-compaction",
|
|
204
|
+
rankedHistorySearch: false,
|
|
205
|
+
noteSaveMarkers: preferences.noteSaveMarkers,
|
|
206
|
+
shareSubagentContext:
|
|
207
|
+
"shareSubagentContext" in value && value["shareSubagentContext"] === true,
|
|
208
|
+
newWindowRequests: NEW_WINDOW_REQUESTS.some((item) => item === requests)
|
|
209
|
+
? (requests as NewWindowRequests)
|
|
210
|
+
: "unrestricted",
|
|
211
|
+
idleMinutes: [...IDLE_MINUTES, 5, 15].some((item) => item === idle)
|
|
212
|
+
? (idle as IdleMinutes)
|
|
213
|
+
: 0,
|
|
214
|
+
taskBoundaryReminder:
|
|
215
|
+
typeof reminder === "number" &&
|
|
216
|
+
Number.isSafeInteger(reminder) &&
|
|
217
|
+
reminder >= 0
|
|
218
|
+
? reminder
|
|
219
|
+
: 0,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Global first, then the trusted project's explicitly configured values. */
|
|
224
|
+
function readLegacyPreferences(paths: readonly string[]): {
|
|
225
|
+
compaction: Record<string, unknown>;
|
|
226
|
+
noteSaveMarkers: boolean;
|
|
227
|
+
} {
|
|
228
|
+
const compaction: Record<string, unknown> = {};
|
|
229
|
+
let noteSaveMarkers = false;
|
|
230
|
+
for (const path of paths) {
|
|
231
|
+
let document: unknown;
|
|
232
|
+
try {
|
|
233
|
+
document = JSON.parse(readFileSync(path, "utf8"));
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") continue;
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
if (!document || typeof document !== "object" || Array.isArray(document))
|
|
239
|
+
continue;
|
|
240
|
+
if (
|
|
241
|
+
"compaction" in document &&
|
|
242
|
+
document.compaction &&
|
|
243
|
+
typeof document.compaction === "object" &&
|
|
244
|
+
!Array.isArray(document.compaction)
|
|
245
|
+
) {
|
|
246
|
+
// Old PCC releases migrated these axes in memory only. Translate each
|
|
247
|
+
// scope before layering so project opt-outs and current fields win.
|
|
248
|
+
const value = document.compaction as Record<string, unknown>;
|
|
249
|
+
const mode = value["contextManagement"];
|
|
250
|
+
const modeOverride =
|
|
251
|
+
mode === "off" ||
|
|
252
|
+
mode === "local" ||
|
|
253
|
+
mode === "tree" ||
|
|
254
|
+
mode === "remote";
|
|
255
|
+
const inheritedNotes =
|
|
256
|
+
compaction["continuity"] === "notes" ||
|
|
257
|
+
compaction["continuity"] === "notes-and-compaction";
|
|
258
|
+
const notes = modeOverride ? mode !== "off" : inheritedNotes;
|
|
259
|
+
const hybrid =
|
|
260
|
+
typeof value["hybridCompaction"] === "boolean"
|
|
261
|
+
? value["hybridCompaction"]
|
|
262
|
+
: compaction["continuity"] === "notes-and-compaction";
|
|
263
|
+
if (
|
|
264
|
+
modeOverride ||
|
|
265
|
+
(notes && typeof value["hybridCompaction"] === "boolean")
|
|
266
|
+
)
|
|
267
|
+
compaction["continuity"] = notes
|
|
268
|
+
? hybrid
|
|
269
|
+
? "notes-and-compaction"
|
|
270
|
+
: "notes"
|
|
271
|
+
: "compaction";
|
|
272
|
+
Object.assign(compaction, document.compaction);
|
|
273
|
+
}
|
|
274
|
+
for (const key of ["display", "ui"]) {
|
|
275
|
+
const section = (document as Record<string, unknown>)[key];
|
|
276
|
+
if (
|
|
277
|
+
section &&
|
|
278
|
+
typeof section === "object" &&
|
|
279
|
+
"noteSaveMarkers" in section
|
|
280
|
+
) {
|
|
281
|
+
noteSaveMarkers = section.noteSaveMarkers === true;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return { compaction, noteSaveMarkers };
|
|
287
|
+
}
|