@howaboua/pi-notes-compaction 0.0.14 → 0.0.16
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 +21 -1
- package/LICENSE +21 -0
- package/README.md +8 -3
- package/index.ts +8 -0
- package/package.json +16 -11
- package/src/board/context-briefing.ts +245 -0
- package/src/board/delivery.ts +85 -0
- package/src/guidance.ts +121 -0
- package/src/notes/AGENTS.md +27 -0
- package/src/{activation.ts → notes/activation.ts} +8 -10
- package/src/{attachment-sharing.ts → notes/attachment-sharing.ts} +1 -1
- package/src/{attachment-snapshot.ts → notes/attachment-snapshot.ts} +33 -20
- package/src/{bridge.ts → notes/bridge.ts} +1 -0
- package/src/{context-sharing.ts → notes/context-sharing.ts} +22 -2
- package/src/{extension-hooks.ts → notes/extension-hooks.ts} +1 -12
- package/src/{extension-sharing.ts → notes/extension-sharing.ts} +2 -1
- package/src/notes/feature.ts +168 -0
- package/src/{history-windows.ts → notes/history-windows.ts} +10 -22
- package/src/{history.ts → notes/history.ts} +6 -5
- package/src/{index.ts → notes/index.ts} +20 -11
- package/src/{integrations.ts → notes/integrations.ts} +19 -3
- package/src/{lifecycle.ts → notes/lifecycle.ts} +0 -2
- package/src/{note-query.ts → notes/note-query.ts} +3 -5
- package/src/notes/note-result.ts +119 -0
- package/src/{note-save-marker.ts → notes/note-save-marker.ts} +3 -1
- package/src/{query-executor.ts → notes/query-executor.ts} +34 -9
- package/src/{query-input.ts → notes/query-input.ts} +1 -0
- package/src/{remote.ts → notes/remote.ts} +1 -1
- package/src/notes/saved-session-access.ts +121 -0
- package/src/notes/saved-session-index.mjs +83 -0
- package/src/notes/saved-session.mjs +241 -0
- package/src/notes/saved-session.ts +67 -0
- package/src/notes/saved-sharing-records.ts +170 -0
- package/src/{session-pruning.ts → notes/session-pruning.ts} +5 -5
- package/src/{settings-command.ts → notes/settings-command.ts} +29 -42
- package/src/{settings-controls.ts → notes/settings-controls.ts} +62 -72
- package/src/{settings-screen.ts → notes/settings-screen.ts} +25 -7
- package/src/{settings.ts → notes/settings.ts} +37 -6
- package/src/notes/shared-notes.ts +419 -0
- package/src/{shared-session-reader.ts → notes/shared-session-reader.ts} +35 -26
- package/src/{sharing-service.ts → notes/sharing-service.ts} +32 -1
- package/src/{store.ts → notes/store.ts} +10 -0
- package/src/{tool-contracts.ts → notes/tool-contracts.ts} +71 -44
- package/src/{tools.ts → notes/tools.ts} +2 -2
- package/src/notes/tree-archive-manifest.mjs +27 -0
- package/src/{tree-archive.ts → notes/tree-archive.ts} +6 -26
- package/src/{tree-handoff-read.ts → notes/tree-handoff-read.ts} +47 -32
- package/src/{window-message.ts → notes/window-message.ts} +15 -20
- package/src/settings-navigation.ts +11 -0
- package/src/timestamps.ts +3 -0
- package/tsconfig.json +9 -0
- package/src/note-result.ts +0 -70
- package/src/saved-session.ts +0 -169
- package/src/saved-sharing-records.ts +0 -112
- package/src/shared-notes.ts +0 -290
- /package/src/{agent-identity.ts → notes/agent-identity.ts} +0 -0
- /package/src/{binding-startup.ts → notes/binding-startup.ts} +0 -0
- /package/src/{compaction-projection.ts → notes/compaction-projection.ts} +0 -0
- /package/src/{context-owner.ts → notes/context-owner.ts} +0 -0
- /package/src/{fresh-checkpoint.ts → notes/fresh-checkpoint.ts} +0 -0
- /package/src/{fresh-notes.ts → notes/fresh-notes.ts} +0 -0
- /package/src/{history-search-protocol.ts → notes/history-search-protocol.ts} +0 -0
- /package/src/{history-search-pruning.mjs → notes/history-search-pruning.mjs} +0 -0
- /package/src/{history-search-worker.mjs → notes/history-search-worker.mjs} +0 -0
- /package/src/{history-search.ts → notes/history-search.ts} +0 -0
- /package/src/{idle-admission.ts → notes/idle-admission.ts} +0 -0
- /package/src/{model-role-config.ts → notes/model-role-config.ts} +0 -0
- /package/src/{model-role-screen.ts → notes/model-role-screen.ts} +0 -0
- /package/src/{model-roles.ts → notes/model-roles.ts} +0 -0
- /package/src/{notes-lookup.ts → notes/notes-lookup.ts} +0 -0
- /package/src/{notes.ts → notes/notes.ts} +0 -0
- /package/src/{rollover.ts → notes/rollover.ts} +0 -0
- /package/src/{session-pruning-content.ts → notes/session-pruning-content.ts} +0 -0
- /package/src/{session-pruning-plan.ts → notes/session-pruning-plan.ts} +0 -0
- /package/src/{session-pruning-policy.ts → notes/session-pruning-policy.ts} +0 -0
- /package/src/{session-pruning-screen.ts → notes/session-pruning-screen.ts} +0 -0
- /package/src/{session-pruning-source.ts → notes/session-pruning-source.ts} +0 -0
- /package/src/{session-pruning-transaction.ts → notes/session-pruning-transaction.ts} +0 -0
- /package/src/{sqlite.mjs → notes/sqlite.mjs} +0 -0
- /package/src/{task-boundary.ts → notes/task-boundary.ts} +0 -0
- /package/src/{tree-checkpoint.ts → notes/tree-checkpoint.ts} +0 -0
- /package/src/{window-checkpoint.ts → notes/window-checkpoint.ts} +0 -0
- /package/src/{windows.ts → notes/windows.ts} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
arr,
|
|
4
|
+
compile,
|
|
5
|
+
nul,
|
|
6
|
+
num,
|
|
7
|
+
obj,
|
|
8
|
+
opt,
|
|
9
|
+
str,
|
|
10
|
+
union,
|
|
11
|
+
} from "@earendil-works/pi-schema";
|
|
12
|
+
|
|
13
|
+
export { readSavedNotesSession } from "./saved-session.mjs";
|
|
14
|
+
export interface SavedNotesSession {
|
|
15
|
+
threadId: string;
|
|
16
|
+
entries: readonly SessionEntry[];
|
|
17
|
+
branch: readonly SessionEntry[];
|
|
18
|
+
savedAt?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const SavedEntry = obj(
|
|
22
|
+
{
|
|
23
|
+
type: str(),
|
|
24
|
+
id: str(),
|
|
25
|
+
parentId: union([str(), nul()]),
|
|
26
|
+
timestamp: str(),
|
|
27
|
+
},
|
|
28
|
+
{ open: true },
|
|
29
|
+
);
|
|
30
|
+
const SavedSession = obj(
|
|
31
|
+
{
|
|
32
|
+
threadId: str({ minLength: 1 }),
|
|
33
|
+
entries: arr(SavedEntry),
|
|
34
|
+
branch: arr(SavedEntry),
|
|
35
|
+
savedAt: opt(num()),
|
|
36
|
+
},
|
|
37
|
+
{ open: true },
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const savedSessionValidator = compile(SavedSession);
|
|
41
|
+
|
|
42
|
+
/** Remote loaders carry data, not authority. Native identity is checked by the graph reader. */
|
|
43
|
+
export function validateSavedNotesSession(value: unknown): SavedNotesSession {
|
|
44
|
+
if (!savedSessionValidator.check(value))
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Saved session response is invalid. Update Notes on the other machine and retry.",
|
|
47
|
+
);
|
|
48
|
+
for (const entry of [...value.entries, ...value.branch]) {
|
|
49
|
+
if (
|
|
50
|
+
entry.type === "custom" &&
|
|
51
|
+
(!("customType" in entry) ||
|
|
52
|
+
typeof entry.customType !== "string" ||
|
|
53
|
+
!("data" in entry))
|
|
54
|
+
)
|
|
55
|
+
throw new Error("Invalid saved session custom record");
|
|
56
|
+
if (
|
|
57
|
+
entry.type === "message" &&
|
|
58
|
+
(!("message" in entry) ||
|
|
59
|
+
!entry.message ||
|
|
60
|
+
typeof entry.message !== "object")
|
|
61
|
+
)
|
|
62
|
+
throw new Error("Invalid saved session message record");
|
|
63
|
+
}
|
|
64
|
+
// The same persisted entry envelope is accepted by the Node reader. Feature readers
|
|
65
|
+
// validate their own custom data, including ownership and note receipts.
|
|
66
|
+
return value as SavedNotesSession;
|
|
67
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
arr,
|
|
3
|
+
compile,
|
|
4
|
+
lit,
|
|
5
|
+
num,
|
|
6
|
+
obj,
|
|
7
|
+
opt,
|
|
8
|
+
type Static,
|
|
9
|
+
str,
|
|
10
|
+
union,
|
|
11
|
+
unknown,
|
|
12
|
+
} from "@earendil-works/pi-schema";
|
|
13
|
+
import {
|
|
14
|
+
CONTEXT_AGENT_PATTERN,
|
|
15
|
+
canonicalAgentName,
|
|
16
|
+
canonicalContextIdentity,
|
|
17
|
+
contextStorageAgentName,
|
|
18
|
+
pinnedContextIdentity,
|
|
19
|
+
} from "./agent-identity.js";
|
|
20
|
+
import type { SavedNotesSession } from "./saved-session.js";
|
|
21
|
+
|
|
22
|
+
const Agent = str({ pattern: CONTEXT_AGENT_PATTERN });
|
|
23
|
+
export const Identity = obj(
|
|
24
|
+
{
|
|
25
|
+
protocol: lit(1),
|
|
26
|
+
sessionId: str(),
|
|
27
|
+
threadId: str(),
|
|
28
|
+
agentName: Agent,
|
|
29
|
+
storageAgentName: opt(Agent),
|
|
30
|
+
storage: opt(union([lit("session"), lit("remote")])),
|
|
31
|
+
routing: opt(unknown()),
|
|
32
|
+
},
|
|
33
|
+
{ open: true },
|
|
34
|
+
);
|
|
35
|
+
export const Member = obj(
|
|
36
|
+
{
|
|
37
|
+
threadId: str(),
|
|
38
|
+
sessionId: str(),
|
|
39
|
+
agentName: Agent,
|
|
40
|
+
machine: str(),
|
|
41
|
+
sessionFile: str(),
|
|
42
|
+
},
|
|
43
|
+
{ open: true },
|
|
44
|
+
);
|
|
45
|
+
export const Plan = obj(
|
|
46
|
+
{
|
|
47
|
+
controllerSessionId: str(),
|
|
48
|
+
targetSessionId: str(),
|
|
49
|
+
context: opt(
|
|
50
|
+
obj(
|
|
51
|
+
{
|
|
52
|
+
controller: Identity,
|
|
53
|
+
target: Identity,
|
|
54
|
+
alias: Agent,
|
|
55
|
+
controllerAlias: Agent,
|
|
56
|
+
controllerFile: opt(str()),
|
|
57
|
+
controllerMachine: opt(str()),
|
|
58
|
+
controllerNotes: unknown(),
|
|
59
|
+
targetNotes: unknown(),
|
|
60
|
+
},
|
|
61
|
+
{ open: true },
|
|
62
|
+
),
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
{ open: true },
|
|
66
|
+
);
|
|
67
|
+
export const Route = obj(
|
|
68
|
+
{
|
|
69
|
+
plan: Plan,
|
|
70
|
+
machine: str(),
|
|
71
|
+
sessionFile: str(),
|
|
72
|
+
phase: union([lit("pending"), lit("ready")]),
|
|
73
|
+
detached: opt(obj({ context: opt(unknown()) }, { open: true })),
|
|
74
|
+
},
|
|
75
|
+
{ open: true },
|
|
76
|
+
);
|
|
77
|
+
export const Detachment = obj(
|
|
78
|
+
{
|
|
79
|
+
plan: Plan,
|
|
80
|
+
context: opt(unknown()),
|
|
81
|
+
},
|
|
82
|
+
{ open: true },
|
|
83
|
+
);
|
|
84
|
+
export const Snapshot = obj(
|
|
85
|
+
{
|
|
86
|
+
protocol: lit(1),
|
|
87
|
+
timestamp: num(),
|
|
88
|
+
files: arr(
|
|
89
|
+
obj(
|
|
90
|
+
{
|
|
91
|
+
path: str(),
|
|
92
|
+
text: str(),
|
|
93
|
+
createdAt: num(),
|
|
94
|
+
updatedAt: num(),
|
|
95
|
+
operation: union([
|
|
96
|
+
lit("local_append_overlay"),
|
|
97
|
+
lit("local_replacement"),
|
|
98
|
+
]),
|
|
99
|
+
},
|
|
100
|
+
{ open: true },
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
},
|
|
104
|
+
{ open: true },
|
|
105
|
+
);
|
|
106
|
+
export const Parent = obj(
|
|
107
|
+
{
|
|
108
|
+
transport: lit("shepherdr"),
|
|
109
|
+
parent: str(),
|
|
110
|
+
savedParent: opt(
|
|
111
|
+
obj({ machine: str(), sessionFile: str() }, { open: true }),
|
|
112
|
+
),
|
|
113
|
+
},
|
|
114
|
+
{ open: true },
|
|
115
|
+
);
|
|
116
|
+
export type Identity = Static<typeof Identity>;
|
|
117
|
+
|
|
118
|
+
const identityValidator = compile(Identity);
|
|
119
|
+
|
|
120
|
+
/** Ordinary family membership is immutable, explicit and native-session owned. */
|
|
121
|
+
export function savedFamilyIdentity(
|
|
122
|
+
session: Pick<SavedNotesSession, "threadId" | "entries">,
|
|
123
|
+
): Identity | undefined {
|
|
124
|
+
const identity = savedNotesIdentity(session);
|
|
125
|
+
if (
|
|
126
|
+
identity.storage === undefined ||
|
|
127
|
+
!session.entries.some(
|
|
128
|
+
(entry) =>
|
|
129
|
+
entry.type === "custom" &&
|
|
130
|
+
entry.customType === "codex-context-agent" &&
|
|
131
|
+
identityValidator.check(entry.data) &&
|
|
132
|
+
entry.data.threadId === session.threadId,
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
return;
|
|
136
|
+
return identity;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Persisted sharing is session-scoped. Forks never inherit the source agent's address. */
|
|
140
|
+
export function savedNotesIdentity(
|
|
141
|
+
session: Pick<SavedNotesSession, "threadId" | "entries">,
|
|
142
|
+
): Identity {
|
|
143
|
+
let found: Identity | undefined;
|
|
144
|
+
for (const entry of session.entries) {
|
|
145
|
+
if (entry.type !== "custom" || entry.customType !== "codex-context-agent")
|
|
146
|
+
continue;
|
|
147
|
+
if (!identityValidator.check(entry.data))
|
|
148
|
+
throw new Error("Invalid saved notes identity");
|
|
149
|
+
if (entry.data.threadId !== session.threadId) continue;
|
|
150
|
+
if (found) throw new Error("Conflicting saved notes identities");
|
|
151
|
+
found = entry.data;
|
|
152
|
+
}
|
|
153
|
+
return canonicalContextIdentity(
|
|
154
|
+
found ??
|
|
155
|
+
pinnedContextIdentity(session.threadId, session.entries) ?? {
|
|
156
|
+
protocol: 1,
|
|
157
|
+
threadId: session.threadId,
|
|
158
|
+
sessionId: session.threadId,
|
|
159
|
+
agentName: canonicalAgentName(session.threadId),
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function sameOwner(a: Identity, b: Identity): boolean {
|
|
165
|
+
return (
|
|
166
|
+
a.threadId === b.threadId &&
|
|
167
|
+
a.sessionId === b.sessionId &&
|
|
168
|
+
contextStorageAgentName(a) === contextStorageAgentName(b)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -44,12 +44,12 @@ export class SessionPruning {
|
|
|
44
44
|
return `${ctx.sessionManager.getSessionId()}:${details.identity.currentWindowId}`;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
start(ctx: ExtensionContext): void {
|
|
48
|
+
this.epoch++;
|
|
49
|
+
this.observed = this.persistedWindow(ctx);
|
|
50
|
+
this.pending = undefined;
|
|
51
|
+
}
|
|
47
52
|
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
53
|
this.pi.on("session_shutdown", () => {
|
|
54
54
|
this.epoch++;
|
|
55
55
|
this.pending = undefined;
|
|
@@ -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 {
|
|
6
|
-
import type {
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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) =>
|
|
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
|
-
|
|
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
|
|
78
|
+
lifecycle?.active
|
|
73
79
|
? "Continuity active"
|
|
74
|
-
: `Continuity inactive: ${activation
|
|
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
|
|
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
|
-
|
|
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:
|
|
26
|
+
done: (action: NotesSettingsAction) => void,
|
|
21
27
|
requestRender: () => void,
|
|
22
28
|
) {
|
|
23
29
|
const settings = options.settings();
|
|
@@ -41,8 +47,19 @@ export function createNotesSettingsControls(
|
|
|
41
47
|
id: "active",
|
|
42
48
|
label: "Active",
|
|
43
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"].`,
|
|
44
|
-
currentValue:
|
|
45
|
-
|
|
50
|
+
currentValue:
|
|
51
|
+
settings.active === "off"
|
|
52
|
+
? "Off"
|
|
53
|
+
: settings.active === "all"
|
|
54
|
+
? "All models"
|
|
55
|
+
: "Whitelist",
|
|
56
|
+
values: ["Off", "All models", "Whitelist"],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
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,44 @@ export function createNotesSettingsControls(
|
|
|
130
151
|
list.updateValue(id, taskBoundaryLabel(current.taskBoundaryReminder));
|
|
131
152
|
return;
|
|
132
153
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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"
|
|
161
|
+
? "off"
|
|
162
|
+
: value === "All models"
|
|
163
|
+
? "all"
|
|
164
|
+
: "whitelist",
|
|
165
|
+
});
|
|
166
|
+
else if (id === "sharing")
|
|
167
|
+
save({ ...current, shareSubagentContext: value === "on" });
|
|
168
|
+
else if (id === "noteSaveMarkers")
|
|
169
|
+
save({ ...current, noteSaveMarkers: value === "on" });
|
|
170
|
+
else if (id === "rankedHistorySearch")
|
|
171
|
+
save({ ...current, rankedHistorySearch: value === "on" });
|
|
172
|
+
else if (id === "compact")
|
|
173
|
+
save({ ...current, normalCompaction: value === "on" });
|
|
174
|
+
else if (id === "newWindowRequests") {
|
|
175
|
+
const newWindowRequests = NEW_WINDOW_REQUESTS.find(
|
|
176
|
+
(mode) => mode === value,
|
|
177
|
+
);
|
|
178
|
+
if (newWindowRequests) save({ ...current, newWindowRequests });
|
|
179
|
+
} else if (id === "taskBoundaryReminder")
|
|
180
|
+
save({
|
|
181
|
+
...current,
|
|
182
|
+
taskBoundaryReminder:
|
|
183
|
+
TASK_BOUNDARY_PRESETS.find(
|
|
184
|
+
(tokens) => taskBoundaryLabel(tokens) === value,
|
|
185
|
+
) ?? current.taskBoundaryReminder,
|
|
186
|
+
});
|
|
187
|
+
else {
|
|
188
|
+
const idleMinutes = IDLE_MINUTES.find(
|
|
189
|
+
(minutes) => idleValue(minutes) === value,
|
|
201
190
|
);
|
|
191
|
+
if (idleMinutes !== undefined) save({ ...current, idleMinutes });
|
|
202
192
|
}
|
|
203
193
|
requestRender();
|
|
204
194
|
},
|
|
@@ -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 {
|
|
13
|
+
import {
|
|
14
|
+
createNotesSettingsControls,
|
|
15
|
+
type NotesSettingsAction,
|
|
16
|
+
} from "./settings-controls.js";
|
|
14
17
|
|
|
15
|
-
type ScreenAction =
|
|
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 = "sessionPruning";
|
|
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 & Compaction")} / ${theme.fg("dim", options.boardTab === false ? "Roles" : "Board")}`,
|
|
44
50
|
"",
|
|
45
51
|
...options
|
|
46
52
|
.status()
|
|
@@ -69,7 +75,7 @@ export async function openNotesSettings(
|
|
|
69
75
|
matchesKey(data, Key.tab) ||
|
|
70
76
|
matchesKey(data, Key.shift(Key.tab))
|
|
71
77
|
) {
|
|
72
|
-
done("roles");
|
|
78
|
+
done(options.boardTab === false ? "roles" : "board");
|
|
73
79
|
return;
|
|
74
80
|
}
|
|
75
81
|
list.handleInput(data);
|
|
@@ -78,8 +84,20 @@ export async function openNotesSettings(
|
|
|
78
84
|
};
|
|
79
85
|
},
|
|
80
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
|
+
}
|
|
81
99
|
if (action === "close") return;
|
|
82
|
-
if (action === "roles") return
|
|
100
|
+
if (action === "roles" || action === "board") return action;
|
|
83
101
|
if (action === "sessionPruning") {
|
|
84
102
|
await openSessionPruningSettings(ctx, options.sessionPruning);
|
|
85
103
|
continue;
|