@howaboua/pi-notes-compaction 0.0.11 → 0.0.12
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 +7 -0
- package/README.md +28 -0
- package/package.json +3 -3
- package/src/attachment-sharing.ts +134 -0
- package/src/context-owner.ts +15 -19
- package/src/extension-hooks.ts +2 -2
- package/src/fresh-notes.ts +5 -11
- package/src/history-search.ts +1 -1
- package/src/history-windows.ts +223 -0
- package/src/history.ts +4 -222
- package/src/index.ts +27 -2
- package/src/integrations.ts +3 -1
- package/src/model-role-config.ts +99 -0
- package/src/model-role-editor.ts +40 -0
- package/src/model-role-screen.ts +58 -0
- package/src/model-roles.ts +363 -0
- package/src/note-query.ts +150 -0
- package/src/notes-lookup.ts +1 -1
- package/src/notes.ts +3 -145
- package/src/query-executor.ts +10 -2
- package/src/query-input.ts +115 -0
- package/src/saved-sharing-records.ts +103 -0
- package/src/settings-command.ts +39 -8
- package/src/settings-controls.ts +209 -0
- package/src/settings-screen.ts +23 -211
- package/src/shared-notes.ts +20 -203
- package/src/shared-session-reader.ts +132 -0
- package/src/sharing-service.ts +2 -116
- package/src/tool-contracts.ts +121 -80
- package/src/tools.ts +46 -6
- package/src/window-message.ts +179 -0
- package/src/windows.ts +13 -172
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomMessageEntryDraft,
|
|
3
|
+
ExtensionAPI,
|
|
4
|
+
SessionEntry,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { keyHint } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { Box, Text, TruncatedText } from "@earendil-works/pi-tui";
|
|
8
|
+
import type { WindowIdentity } from "./bridge.js";
|
|
9
|
+
|
|
10
|
+
export const WINDOW_MESSAGE = "notes-compaction:window:v1";
|
|
11
|
+
export const SETTLEMENT_ENTRY = "notes-compaction:settled:v1";
|
|
12
|
+
export interface WindowDetails {
|
|
13
|
+
protocol: 1;
|
|
14
|
+
kind: "window" | "identity" | "reminder" | "urgent" | "task-boundary";
|
|
15
|
+
identity: WindowIdentity;
|
|
16
|
+
trim: boolean;
|
|
17
|
+
}
|
|
18
|
+
const GUIDANCE = `<context_window_guidance>
|
|
19
|
+
Notes are recovery state, not a diary. Write checkpoints and reports to relative paths in your own notes. Delegates do likewise and return their note paths. Keep one concise, authoritative note per task or topic at a stable path. Task checkpoints cover request, constraints, decisions, status, next steps and history IDs. Use write to replace stale state and mark completion. Link to existing notes instead of copying or summarising their contents. Recording isn't permission to implement.
|
|
20
|
+
|
|
21
|
+
You must maintain a task checkpoint, updating it at each meaningful milestone and on completion or before switching substantive tasks, even with context room. Don't save every reply or intermediate step. Before new_context or handoff, save current state and wait for success; include the checkpoint path in handoffs. After rollover, read the checkpoint, then only needed links. Don't reread notes still in context unless they may have changed. Use history for missing details.
|
|
22
|
+
|
|
23
|
+
Previous skill reads don’t carry into this window. Read the skills needed for the current task.
|
|
24
|
+
</context_window_guidance>`;
|
|
25
|
+
|
|
26
|
+
const GPT_GUIDANCE = `<context_window_guidance>
|
|
27
|
+
Notes=recovery state≠diary. Checkpoints/reports→write relative paths in own notes. Delegates→same→return note paths. One concise authoritative note per task/topic, stable path. Task checkpoint=request/constraints/decisions/status/next steps/history IDs. write→replace stale state; mark completion. Existing notes→link≠copy/summarise. Recording≠implementation permission.
|
|
28
|
+
|
|
29
|
+
Must maintain task checkpoint→update@each meaningful milestone + completion/before switching substantive tasks, even with context room. Not every reply/step. Before new_context/handoff: save current state→await success; handoff includes checkpoint path. Post-rollover: read checkpoint→needed links only. In-context notes: reread only if possibly changed. Missing details→history.
|
|
30
|
+
|
|
31
|
+
Prior skill reads≠current context. Read task-relevant skills.
|
|
32
|
+
</context_window_guidance>`;
|
|
33
|
+
|
|
34
|
+
export function registerWindowRenderer(pi: ExtensionAPI): void {
|
|
35
|
+
pi.registerMessageRenderer(
|
|
36
|
+
WINDOW_MESSAGE,
|
|
37
|
+
(message, { expanded, outputPad }, theme) => {
|
|
38
|
+
const details = parseWindowDetails(message.details);
|
|
39
|
+
if (!details || typeof message.content !== "string") return undefined;
|
|
40
|
+
const title =
|
|
41
|
+
details.kind === "task-boundary"
|
|
42
|
+
? "Task-boundary reminder"
|
|
43
|
+
: details.kind === "urgent"
|
|
44
|
+
? "Context nearly full · Save notes and start a new window now"
|
|
45
|
+
: details.kind === "reminder"
|
|
46
|
+
? "Context checkpoint reminder · Save notes and start a new window"
|
|
47
|
+
: `Context window ${details.identity.windowNumber + 1} · Notes and history`;
|
|
48
|
+
const box = new Box(outputPad, 1, (text) =>
|
|
49
|
+
theme.bg("customMessageBg", text),
|
|
50
|
+
);
|
|
51
|
+
box.addChild(
|
|
52
|
+
expanded
|
|
53
|
+
? new Text(theme.fg("customMessageText", message.content), 0, 0)
|
|
54
|
+
: new TruncatedText(
|
|
55
|
+
theme.fg(
|
|
56
|
+
details.kind === "urgent" ? "warning" : "customMessageLabel",
|
|
57
|
+
title,
|
|
58
|
+
) +
|
|
59
|
+
theme.fg(
|
|
60
|
+
"dim",
|
|
61
|
+
` (${keyHint("app.tools.expand", "to expand")})`,
|
|
62
|
+
),
|
|
63
|
+
0,
|
|
64
|
+
0,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
return box;
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function identity(value: unknown): WindowIdentity | undefined {
|
|
73
|
+
if (!value || typeof value !== "object") return;
|
|
74
|
+
const data = value as Partial<WindowIdentity>;
|
|
75
|
+
if (
|
|
76
|
+
typeof data.firstWindowId !== "string" ||
|
|
77
|
+
!data.firstWindowId ||
|
|
78
|
+
typeof data.currentWindowId !== "string" ||
|
|
79
|
+
!data.currentWindowId ||
|
|
80
|
+
!Number.isInteger(data.windowNumber) ||
|
|
81
|
+
data.windowNumber! < 0 ||
|
|
82
|
+
(data.previousWindowId !== undefined &&
|
|
83
|
+
typeof data.previousWindowId !== "string")
|
|
84
|
+
)
|
|
85
|
+
return;
|
|
86
|
+
return data as WindowIdentity;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseWindowDetails(value: unknown): WindowDetails | undefined {
|
|
90
|
+
if (!value || typeof value !== "object") return;
|
|
91
|
+
const details = value as Partial<WindowDetails>;
|
|
92
|
+
const ids = identity(details.identity);
|
|
93
|
+
if (
|
|
94
|
+
details.protocol !== 1 ||
|
|
95
|
+
!ids ||
|
|
96
|
+
!["window", "identity", "reminder", "urgent", "task-boundary"].includes(
|
|
97
|
+
details.kind ?? "",
|
|
98
|
+
) ||
|
|
99
|
+
typeof details.trim !== "boolean"
|
|
100
|
+
)
|
|
101
|
+
return;
|
|
102
|
+
return {
|
|
103
|
+
protocol: 1,
|
|
104
|
+
kind: details.kind!,
|
|
105
|
+
identity: ids,
|
|
106
|
+
trim: details.trim,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Understand previous PCC window IDs for familiar history lookup, without importing its runtime. */
|
|
111
|
+
export function windowDetails(
|
|
112
|
+
entry: SessionEntry | CustomMessageEntryDraft,
|
|
113
|
+
): WindowDetails | undefined {
|
|
114
|
+
if (entry.type !== "custom_message") return;
|
|
115
|
+
return messageWindowDetails(entry.customType, entry.details);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function messageWindowDetails(
|
|
119
|
+
customType: string,
|
|
120
|
+
data: unknown,
|
|
121
|
+
): WindowDetails | undefined {
|
|
122
|
+
if (customType === WINDOW_MESSAGE) return parseWindowDetails(data);
|
|
123
|
+
if (
|
|
124
|
+
customType !== "codex-context-window" ||
|
|
125
|
+
!data ||
|
|
126
|
+
typeof data !== "object" ||
|
|
127
|
+
!("contextManagement" in data)
|
|
128
|
+
)
|
|
129
|
+
return;
|
|
130
|
+
const details = data.contextManagement;
|
|
131
|
+
if (
|
|
132
|
+
!details ||
|
|
133
|
+
typeof details !== "object" ||
|
|
134
|
+
!("kind" in details) ||
|
|
135
|
+
(details.kind !== "window" && details.kind !== "task-boundary")
|
|
136
|
+
)
|
|
137
|
+
return;
|
|
138
|
+
const ids = identity(details);
|
|
139
|
+
return ids
|
|
140
|
+
? {
|
|
141
|
+
protocol: 1,
|
|
142
|
+
kind: details.kind,
|
|
143
|
+
identity: ids,
|
|
144
|
+
trim:
|
|
145
|
+
"trimPreviousWindow" in details &&
|
|
146
|
+
details.trimPreviousWindow === true,
|
|
147
|
+
}
|
|
148
|
+
: undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function windowMessage(
|
|
152
|
+
ids: WindowIdentity,
|
|
153
|
+
agent: string,
|
|
154
|
+
hint: string,
|
|
155
|
+
trim: boolean,
|
|
156
|
+
kind: "window" | "identity" = "window",
|
|
157
|
+
gpt = false,
|
|
158
|
+
): CustomMessageEntryDraft {
|
|
159
|
+
const lines = [
|
|
160
|
+
`Agent name: ${agent}`,
|
|
161
|
+
`First context window id: ${ids.firstWindowId}`,
|
|
162
|
+
`Current context window id: ${ids.currentWindowId}`,
|
|
163
|
+
];
|
|
164
|
+
if (ids.previousWindowId)
|
|
165
|
+
lines.push(`Previous context window id: ${ids.previousWindowId}`);
|
|
166
|
+
if (hint) lines.push(hint);
|
|
167
|
+
return {
|
|
168
|
+
type: "custom_message",
|
|
169
|
+
customType: WINDOW_MESSAGE,
|
|
170
|
+
content: `${gpt ? GPT_GUIDANCE : GUIDANCE}\n\n<context_window>\n${lines.join("\n")}\n</context_window>`,
|
|
171
|
+
display: true,
|
|
172
|
+
details: {
|
|
173
|
+
protocol: 1,
|
|
174
|
+
kind,
|
|
175
|
+
identity: ids,
|
|
176
|
+
trim,
|
|
177
|
+
} satisfies WindowDetails,
|
|
178
|
+
};
|
|
179
|
+
}
|
package/src/windows.ts
CHANGED
|
@@ -3,12 +3,9 @@ import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
|
3
3
|
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
4
4
|
import type {
|
|
5
5
|
CustomMessageEntryDraft,
|
|
6
|
-
ExtensionAPI,
|
|
7
6
|
ExtensionContext,
|
|
8
7
|
SessionEntry,
|
|
9
8
|
} from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import { keyHint } from "@earendil-works/pi-coding-agent";
|
|
11
|
-
import { Box, Text, TruncatedText } from "@earendil-works/pi-tui";
|
|
12
9
|
import type { NotesBridge, WindowIdentity } from "./bridge.js";
|
|
13
10
|
import {
|
|
14
11
|
renderTaskBoundaryReminder,
|
|
@@ -16,176 +13,20 @@ import {
|
|
|
16
13
|
} from "./task-boundary.js";
|
|
17
14
|
import { isWindowCheckpoint } from "./window-checkpoint.js";
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
trim: boolean;
|
|
26
|
-
}
|
|
27
|
-
const GUIDANCE = `<context_window_guidance>
|
|
28
|
-
Notes are recovery state, not a diary. Write checkpoints and reports to relative paths in your own notes. Delegates do likewise and return their note paths. Keep one concise, authoritative note per task or topic at a stable path. Task checkpoints cover request, constraints, decisions, status, next steps and history IDs. Use write_file to replace stale state and mark completion. Link to existing notes instead of copying or summarising their contents. Recording isn't permission to implement.
|
|
29
|
-
|
|
30
|
-
Batch saves at meaningful milestones, not every reply or intermediate step. Before new_context or handoff, save current state and wait for success; include the checkpoint path in handoffs. After rollover, read the checkpoint, then only needed links. Don't reread notes still in context unless they may have changed. Use history for missing details.
|
|
31
|
-
|
|
32
|
-
Previous skill reads don’t carry into this window. Read the skills needed for the current task.
|
|
33
|
-
</context_window_guidance>`;
|
|
34
|
-
|
|
35
|
-
const GPT_GUIDANCE = `<context_window_guidance>
|
|
36
|
-
Notes=recovery state≠diary. Checkpoints/reports→write relative paths in own notes. Delegates→same→return note paths. One concise authoritative note per task/topic, stable path. Task checkpoint=request/constraints/decisions/status/next steps/history IDs. write_file→replace stale state; mark completion. Existing notes→link≠copy/summarise. Recording≠implementation permission.
|
|
37
|
-
|
|
38
|
-
Batch saves@meaningful milestones≠every reply/step. Before new_context/handoff: save current state→await success; handoff includes checkpoint path. Post-rollover: read checkpoint→needed links only. In-context notes: reread only if possibly changed. Missing details→history.
|
|
39
|
-
|
|
40
|
-
Prior skill reads≠current context. Read task-relevant skills.
|
|
41
|
-
</context_window_guidance>`;
|
|
42
|
-
|
|
43
|
-
export function registerWindowRenderer(pi: ExtensionAPI): void {
|
|
44
|
-
pi.registerMessageRenderer(
|
|
45
|
-
WINDOW_MESSAGE,
|
|
46
|
-
(message, { expanded, outputPad }, theme) => {
|
|
47
|
-
const details = parseWindowDetails(message.details);
|
|
48
|
-
if (!details || typeof message.content !== "string") return undefined;
|
|
49
|
-
const title =
|
|
50
|
-
details.kind === "task-boundary"
|
|
51
|
-
? "Task-boundary reminder"
|
|
52
|
-
: details.kind === "urgent"
|
|
53
|
-
? "Context nearly full · Save notes and start a new window now"
|
|
54
|
-
: details.kind === "reminder"
|
|
55
|
-
? "Context checkpoint reminder · Save notes and start a new window"
|
|
56
|
-
: `Context window ${details.identity.windowNumber + 1} · Notes and history`;
|
|
57
|
-
const box = new Box(outputPad, 1, (text) =>
|
|
58
|
-
theme.bg("customMessageBg", text),
|
|
59
|
-
);
|
|
60
|
-
box.addChild(
|
|
61
|
-
expanded
|
|
62
|
-
? new Text(theme.fg("customMessageText", message.content), 0, 0)
|
|
63
|
-
: new TruncatedText(
|
|
64
|
-
theme.fg(
|
|
65
|
-
details.kind === "urgent" ? "warning" : "customMessageLabel",
|
|
66
|
-
title,
|
|
67
|
-
) +
|
|
68
|
-
theme.fg(
|
|
69
|
-
"dim",
|
|
70
|
-
` (${keyHint("app.tools.expand", "to expand")})`,
|
|
71
|
-
),
|
|
72
|
-
0,
|
|
73
|
-
0,
|
|
74
|
-
),
|
|
75
|
-
);
|
|
76
|
-
return box;
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function identity(value: unknown): WindowIdentity | undefined {
|
|
82
|
-
if (!value || typeof value !== "object") return;
|
|
83
|
-
const data = value as Partial<WindowIdentity>;
|
|
84
|
-
if (
|
|
85
|
-
typeof data.firstWindowId !== "string" ||
|
|
86
|
-
!data.firstWindowId ||
|
|
87
|
-
typeof data.currentWindowId !== "string" ||
|
|
88
|
-
!data.currentWindowId ||
|
|
89
|
-
!Number.isInteger(data.windowNumber) ||
|
|
90
|
-
data.windowNumber! < 0 ||
|
|
91
|
-
(data.previousWindowId !== undefined &&
|
|
92
|
-
typeof data.previousWindowId !== "string")
|
|
93
|
-
)
|
|
94
|
-
return;
|
|
95
|
-
return data as WindowIdentity;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function parseWindowDetails(value: unknown): WindowDetails | undefined {
|
|
99
|
-
if (!value || typeof value !== "object") return;
|
|
100
|
-
const details = value as Partial<WindowDetails>;
|
|
101
|
-
const ids = identity(details.identity);
|
|
102
|
-
if (
|
|
103
|
-
details.protocol !== 1 ||
|
|
104
|
-
!ids ||
|
|
105
|
-
!["window", "identity", "reminder", "urgent", "task-boundary"].includes(
|
|
106
|
-
details.kind ?? "",
|
|
107
|
-
) ||
|
|
108
|
-
typeof details.trim !== "boolean"
|
|
109
|
-
)
|
|
110
|
-
return;
|
|
111
|
-
return {
|
|
112
|
-
protocol: 1,
|
|
113
|
-
kind: details.kind!,
|
|
114
|
-
identity: ids,
|
|
115
|
-
trim: details.trim,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Understand previous PCC window IDs for familiar history lookup, without importing its runtime. */
|
|
120
|
-
export function windowDetails(
|
|
121
|
-
entry: SessionEntry | CustomMessageEntryDraft,
|
|
122
|
-
): WindowDetails | undefined {
|
|
123
|
-
if (entry.type !== "custom_message") return;
|
|
124
|
-
return messageWindowDetails(entry.customType, entry.details);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function messageWindowDetails(
|
|
128
|
-
customType: string,
|
|
129
|
-
data: unknown,
|
|
130
|
-
): WindowDetails | undefined {
|
|
131
|
-
if (customType === WINDOW_MESSAGE) return parseWindowDetails(data);
|
|
132
|
-
if (
|
|
133
|
-
customType !== "codex-context-window" ||
|
|
134
|
-
!data ||
|
|
135
|
-
typeof data !== "object" ||
|
|
136
|
-
!("contextManagement" in data)
|
|
137
|
-
)
|
|
138
|
-
return;
|
|
139
|
-
const details = data.contextManagement;
|
|
140
|
-
if (
|
|
141
|
-
!details ||
|
|
142
|
-
typeof details !== "object" ||
|
|
143
|
-
!("kind" in details) ||
|
|
144
|
-
(details.kind !== "window" && details.kind !== "task-boundary")
|
|
145
|
-
)
|
|
146
|
-
return;
|
|
147
|
-
const ids = identity(details);
|
|
148
|
-
return ids
|
|
149
|
-
? {
|
|
150
|
-
protocol: 1,
|
|
151
|
-
kind: details.kind,
|
|
152
|
-
identity: ids,
|
|
153
|
-
trim:
|
|
154
|
-
"trimPreviousWindow" in details &&
|
|
155
|
-
details.trimPreviousWindow === true,
|
|
156
|
-
}
|
|
157
|
-
: undefined;
|
|
158
|
-
}
|
|
16
|
+
import {
|
|
17
|
+
messageWindowDetails,
|
|
18
|
+
WINDOW_MESSAGE,
|
|
19
|
+
type WindowDetails,
|
|
20
|
+
windowDetails,
|
|
21
|
+
} from "./window-message.js";
|
|
159
22
|
|
|
160
|
-
export
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
): CustomMessageEntryDraft {
|
|
168
|
-
const lines = [
|
|
169
|
-
`Agent name: ${agent}`,
|
|
170
|
-
`First context window id: ${ids.firstWindowId}`,
|
|
171
|
-
`Current context window id: ${ids.currentWindowId}`,
|
|
172
|
-
];
|
|
173
|
-
if (ids.previousWindowId)
|
|
174
|
-
lines.push(`Previous context window id: ${ids.previousWindowId}`);
|
|
175
|
-
if (hint) lines.push(hint);
|
|
176
|
-
return {
|
|
177
|
-
type: "custom_message",
|
|
178
|
-
customType: WINDOW_MESSAGE,
|
|
179
|
-
content: `${gpt ? GPT_GUIDANCE : GUIDANCE}\n\n<context_window>\n${lines.join("\n")}\n</context_window>`,
|
|
180
|
-
display: true,
|
|
181
|
-
details: {
|
|
182
|
-
protocol: 1,
|
|
183
|
-
kind,
|
|
184
|
-
identity: ids,
|
|
185
|
-
trim,
|
|
186
|
-
} satisfies WindowDetails,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
23
|
+
export {
|
|
24
|
+
registerWindowRenderer,
|
|
25
|
+
SETTLEMENT_ENTRY,
|
|
26
|
+
WINDOW_MESSAGE,
|
|
27
|
+
windowDetails,
|
|
28
|
+
windowMessage,
|
|
29
|
+
} from "./window-message.js";
|
|
189
30
|
|
|
190
31
|
export class Windows {
|
|
191
32
|
current: WindowIdentity | undefined;
|