notesoup 0.0.0-stage → 0.39.0
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/LICENSE +21 -0
- package/README.md +91 -2
- package/dist/src/boot/render.d.ts +16 -0
- package/dist/src/boot/render.js +95 -0
- package/dist/src/boot/snapshot.d.ts +32 -0
- package/dist/src/boot/snapshot.js +36 -0
- package/dist/src/boot/text.d.ts +21 -0
- package/dist/src/boot/text.js +52 -0
- package/dist/src/budget/constants.d.ts +9 -0
- package/dist/src/budget/constants.js +9 -0
- package/dist/src/budget/policy.d.ts +19 -0
- package/dist/src/budget/policy.js +36 -0
- package/dist/src/budget/text.d.ts +8 -0
- package/dist/src/budget/text.js +10 -0
- package/dist/src/claude/helper.d.ts +15 -0
- package/dist/src/claude/helper.js +87 -0
- package/dist/src/dream/doctor.d.ts +2 -0
- package/dist/src/dream/doctor.js +160 -0
- package/dist/src/dream/gates.d.ts +10 -0
- package/dist/src/dream/gates.js +26 -0
- package/dist/src/dream/git.d.ts +21 -0
- package/dist/src/dream/git.js +71 -0
- package/dist/src/dream/jail.d.ts +11 -0
- package/dist/src/dream/jail.js +71 -0
- package/dist/src/dream/lock.d.ts +31 -0
- package/dist/src/dream/lock.js +99 -0
- package/dist/src/dream/playbook.d.ts +1 -0
- package/dist/src/dream/playbook.js +2 -0
- package/dist/src/dream/report.d.ts +7 -0
- package/dist/src/dream/report.js +43 -0
- package/dist/src/dream/result.d.ts +9 -0
- package/dist/src/dream/result.js +1 -0
- package/dist/src/dream/settings.d.ts +10 -0
- package/dist/src/dream/settings.js +14 -0
- package/dist/src/history/history.d.ts +151 -0
- package/dist/src/history/history.js +195 -0
- package/dist/src/history/query.d.ts +75 -0
- package/dist/src/history/query.js +143 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/notes/address.d.ts +31 -0
- package/dist/src/notes/address.js +123 -0
- package/dist/src/notes/constants.d.ts +3 -0
- package/dist/src/notes/constants.js +3 -0
- package/dist/src/notes/errors.d.ts +11 -0
- package/dist/src/notes/errors.js +13 -0
- package/dist/src/notes/frontmatter.d.ts +44 -0
- package/dist/src/notes/frontmatter.js +145 -0
- package/dist/src/notes/fs-error.d.ts +2 -0
- package/dist/src/notes/fs-error.js +5 -0
- package/dist/src/notes/identity.d.ts +10 -0
- package/dist/src/notes/identity.js +33 -0
- package/dist/src/notes/index.d.ts +5 -0
- package/dist/src/notes/index.js +3 -0
- package/dist/src/notes/paths.d.ts +21 -0
- package/dist/src/notes/paths.js +113 -0
- package/dist/src/notes/store.d.ts +104 -0
- package/dist/src/notes/store.js +478 -0
- package/dist/src/pi/boot.d.ts +24 -0
- package/dist/src/pi/boot.js +56 -0
- package/dist/src/pi/budget.d.ts +13 -0
- package/dist/src/pi/budget.js +178 -0
- package/dist/src/pi/dream/cli.d.ts +10 -0
- package/dist/src/pi/dream/cli.js +140 -0
- package/dist/src/pi/dream/runner.d.ts +27 -0
- package/dist/src/pi/dream/runner.js +90 -0
- package/dist/src/pi/dream/settings.d.ts +7 -0
- package/dist/src/pi/dream/settings.js +17 -0
- package/dist/src/pi/entries.d.ts +7 -0
- package/dist/src/pi/entries.js +7 -0
- package/dist/src/pi/estimate.d.ts +16 -0
- package/dist/src/pi/estimate.js +99 -0
- package/dist/src/pi/extension.d.ts +10 -0
- package/dist/src/pi/extension.js +24 -0
- package/dist/src/pi/history-tools.d.ts +3 -0
- package/dist/src/pi/history-tools.js +10 -0
- package/dist/src/pi/history.d.ts +4 -0
- package/dist/src/pi/history.js +150 -0
- package/dist/src/pi/notes/adapter.d.ts +10 -0
- package/dist/src/pi/notes/adapter.js +27 -0
- package/dist/src/pi/notes/tools.d.ts +3 -0
- package/dist/src/pi/notes/tools.js +15 -0
- package/dist/src/pi/reset/artifacts.d.ts +24 -0
- package/dist/src/pi/reset/artifacts.js +84 -0
- package/dist/src/pi/reset/committed.d.ts +7 -0
- package/dist/src/pi/reset/committed.js +28 -0
- package/dist/src/pi/reset/lifecycle.d.ts +101 -0
- package/dist/src/pi/reset/lifecycle.js +277 -0
- package/dist/src/pi/reset/text.d.ts +5 -0
- package/dist/src/pi/reset/text.js +6 -0
- package/dist/src/pi/runtime.d.ts +3 -0
- package/dist/src/pi/runtime.js +206 -0
- package/dist/src/pi/session-reader.d.ts +5 -0
- package/dist/src/pi/session-reader.js +1 -0
- package/dist/src/pi/thresholds.d.ts +17 -0
- package/dist/src/pi/thresholds.js +33 -0
- package/dist/src/pi/tool-names.d.ts +11 -0
- package/dist/src/pi/tool-names.js +11 -0
- package/dist/src/pi/tool-result.d.ts +15 -0
- package/dist/src/pi/tool-result.js +29 -0
- package/dist/src/pi/window.d.ts +41 -0
- package/dist/src/pi/window.js +127 -0
- package/dist/src/settings.d.ts +9 -0
- package/dist/src/settings.js +18 -0
- package/dist/src/text-match.d.ts +5 -0
- package/dist/src/text-match.js +16 -0
- package/dist/src/tools/history.d.ts +67 -0
- package/dist/src/tools/history.js +251 -0
- package/dist/src/tools/notes.d.ts +282 -0
- package/dist/src/tools/notes.js +378 -0
- package/dist/src/tools/output.d.ts +23 -0
- package/dist/src/tools/output.js +39 -0
- package/dist/src/tools/result.d.ts +79 -0
- package/dist/src/tools/result.js +130 -0
- package/dist/src/tools/schema.d.ts +18 -0
- package/dist/src/tools/schema.js +31 -0
- package/dist/test/agent-loop.test.d.ts +1 -0
- package/dist/test/agent-loop.test.js +1497 -0
- package/dist/test/boot.integration.test.d.ts +1 -0
- package/dist/test/boot.integration.test.js +294 -0
- package/dist/test/budget-settings.integration.test.d.ts +1 -0
- package/dist/test/budget-settings.integration.test.js +144 -0
- package/dist/test/claude-mod.test.d.ts +1 -0
- package/dist/test/claude-mod.test.js +404 -0
- package/dist/test/dependencies.test.d.ts +1 -0
- package/dist/test/dependencies.test.js +101 -0
- package/dist/test/doctor.test.d.ts +1 -0
- package/dist/test/doctor.test.js +37 -0
- package/dist/test/dream-skill.test.d.ts +1 -0
- package/dist/test/dream-skill.test.js +72 -0
- package/dist/test/dream.test.d.ts +1 -0
- package/dist/test/dream.test.js +136 -0
- package/dist/test/helpers/dependency-graph.d.ts +5 -0
- package/dist/test/helpers/dependency-graph.js +73 -0
- package/dist/test/helpers/extension-test-environment.d.ts +1 -0
- package/dist/test/helpers/extension-test-environment.js +9 -0
- package/dist/test/helpers/extension.d.ts +119 -0
- package/dist/test/helpers/extension.js +368 -0
- package/dist/test/helpers/notes.d.ts +6 -0
- package/dist/test/helpers/notes.js +13 -0
- package/dist/test/history.integration.test.d.ts +1 -0
- package/dist/test/history.integration.test.js +556 -0
- package/dist/test/host-neutral.test.d.ts +1 -0
- package/dist/test/host-neutral.test.js +300 -0
- package/dist/test/notes-library.test.d.ts +1 -0
- package/dist/test/notes-library.test.js +214 -0
- package/dist/test/notes.integration.test.d.ts +1 -0
- package/dist/test/notes.integration.test.js +497 -0
- package/dist/test/notes.test.d.ts +1 -0
- package/dist/test/notes.test.js +528 -0
- package/dist/test/reset-lifecycle.test.d.ts +1 -0
- package/dist/test/reset-lifecycle.test.js +605 -0
- package/docs/architecture.md +63 -0
- package/docs/claude-code-mod.md +9 -0
- package/docs/notes-library.md +74 -0
- package/docs/reset-lifecycle.md +75 -0
- package/docs/sdk-integration.md +39 -0
- package/docs/skills.md +30 -0
- package/docs/tool-results.md +88 -0
- package/mods/notesoup/.claude-plugin/plugin.json +8 -0
- package/mods/notesoup/dist/claude/helper.js +9324 -0
- package/mods/notesoup/hooks/hooks.json +4 -0
- package/mods/notesoup/hooks/register.ts +241 -0
- package/mods/notesoup/playbook.md +34 -0
- package/mods/notesoup/skills/dream/SKILL.md +12 -0
- package/mods/pi-context/dist/claude/helper.js +9324 -0
- package/package.json +89 -5
- package/playbook.md +34 -0
- package/skills/dream/SKILL.md +12 -0
- package/skills/memory/SKILL.md +59 -0
- package/src/boot/render.ts +115 -0
- package/src/boot/snapshot.ts +46 -0
- package/src/boot/text.ts +66 -0
- package/src/budget/constants.ts +9 -0
- package/src/budget/policy.ts +36 -0
- package/src/budget/text.ts +11 -0
- package/src/claude/helper.ts +94 -0
- package/src/dream/doctor.ts +117 -0
- package/src/dream/gates.ts +26 -0
- package/src/dream/git.ts +73 -0
- package/src/dream/jail.ts +62 -0
- package/src/dream/lock.ts +82 -0
- package/src/dream/playbook.ts +3 -0
- package/src/dream/report.ts +36 -0
- package/src/dream/result.ts +2 -0
- package/src/dream/settings.ts +16 -0
- package/src/history/history.ts +270 -0
- package/src/history/query.ts +147 -0
- package/src/index.ts +1 -0
- package/src/notes/address.ts +110 -0
- package/src/notes/constants.ts +3 -0
- package/src/notes/errors.ts +15 -0
- package/src/notes/frontmatter.ts +166 -0
- package/src/notes/fs-error.ts +5 -0
- package/src/notes/identity.ts +40 -0
- package/src/notes/index.ts +24 -0
- package/src/notes/paths.ts +109 -0
- package/src/notes/store.ts +497 -0
- package/src/pi/boot.ts +88 -0
- package/src/pi/budget.ts +178 -0
- package/src/pi/dream/cli.ts +92 -0
- package/src/pi/dream/runner.ts +91 -0
- package/src/pi/dream/settings.ts +17 -0
- package/src/pi/entries.ts +7 -0
- package/src/pi/estimate.ts +116 -0
- package/src/pi/extension.ts +27 -0
- package/src/pi/history-tools.ts +12 -0
- package/src/pi/history.ts +162 -0
- package/src/pi/notes/adapter.ts +33 -0
- package/src/pi/notes/tools.ts +18 -0
- package/src/pi/reset/artifacts.ts +100 -0
- package/src/pi/reset/committed.ts +26 -0
- package/src/pi/reset/lifecycle.ts +342 -0
- package/src/pi/reset/text.ts +10 -0
- package/src/pi/runtime.ts +200 -0
- package/src/pi/session-reader.ts +6 -0
- package/src/pi/thresholds.ts +50 -0
- package/src/pi/tool-names.ts +13 -0
- package/src/pi/tool-result.ts +41 -0
- package/src/pi/window.ts +133 -0
- package/src/settings.ts +22 -0
- package/src/text-match.ts +14 -0
- package/src/tools/history.ts +273 -0
- package/src/tools/notes.ts +394 -0
- package/src/tools/output.ts +41 -0
- package/src/tools/result.ts +169 -0
- package/src/tools/schema.ts +31 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SessionReader } from "./session-reader.js";
|
|
2
|
+
import { type HistoryProjection } from "../history/history.js";
|
|
3
|
+
/** Build stable internal addresses, then project the active branch into public events. */
|
|
4
|
+
export declare function historyFromSession(ctx: SessionReader): HistoryProjection;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { isWindowMarker, rootWindowId } from "./window.js";
|
|
2
|
+
import { contentText, projectHistory } from "../history/history.js";
|
|
3
|
+
function mapRole(role) {
|
|
4
|
+
if (role === "user" || role === "assistant")
|
|
5
|
+
return role;
|
|
6
|
+
if (role === "toolResult" || role === "bashExecution")
|
|
7
|
+
return "tool";
|
|
8
|
+
if (role === "custom")
|
|
9
|
+
return "developer";
|
|
10
|
+
if (role === "compactionSummary" || role === "branchSummary")
|
|
11
|
+
return "system";
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
function isToolCall(part) {
|
|
15
|
+
return typeof part === "object" && part !== null && part.type === "toolCall";
|
|
16
|
+
}
|
|
17
|
+
function mappedMessage(message) {
|
|
18
|
+
return mapRole(message.role) !== undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Seq allocation depends on entry kind and role, never on visible content. */
|
|
21
|
+
function sequenceCount(entry) {
|
|
22
|
+
if (entry.type === "compaction" || entry.type === "branch_summary" || entry.type === "custom_message")
|
|
23
|
+
return 1;
|
|
24
|
+
if (entry.type !== "message" || !mappedMessage(entry.message))
|
|
25
|
+
return 0;
|
|
26
|
+
if (entry.message.role !== "assistant" || !Array.isArray(entry.message.content))
|
|
27
|
+
return 1;
|
|
28
|
+
return 1 + entry.message.content.filter(isToolCall).length;
|
|
29
|
+
}
|
|
30
|
+
function messageContent(message) {
|
|
31
|
+
switch (message.role) {
|
|
32
|
+
case "bashExecution":
|
|
33
|
+
return message.output;
|
|
34
|
+
case "branchSummary":
|
|
35
|
+
case "compactionSummary":
|
|
36
|
+
return message.summary;
|
|
37
|
+
default:
|
|
38
|
+
return contentText(message.content);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pass the host's nested-call record through as recorded. It is evidence about calls this run made,
|
|
43
|
+
* not a second transcript: the host stores no nested results, and this lane invents none.
|
|
44
|
+
*/
|
|
45
|
+
function nestedCallsOf(message) {
|
|
46
|
+
if (message.role !== "toolResult" || message.nestedCalls === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
return { calls: message.nestedCalls.calls, complete: message.nestedCalls.complete };
|
|
49
|
+
}
|
|
50
|
+
function toolInfo(message) {
|
|
51
|
+
if (message.role === "bashExecution") {
|
|
52
|
+
// A standalone bash run records its own outcome, so its status is read here rather than
|
|
53
|
+
// inferred from a result message that will never arrive: a cancelled or nonzero run is an
|
|
54
|
+
// error, and a run with no recorded exit code stays unknown instead of being called ok.
|
|
55
|
+
const status = message.cancelled === true ? "error" : typeof message.exitCode === "number" ? (message.exitCode === 0 ? "ok" : "error") : "unfinished";
|
|
56
|
+
// A truncated run is only half the record without the on-disk path: surface both.
|
|
57
|
+
return { toolName: "bash", arguments: { command: message.command }, recordedStatus: status, outputTruncated: message.truncated || undefined, fullOutputPath: message.truncated ? message.fullOutputPath : undefined };
|
|
58
|
+
}
|
|
59
|
+
if (message.role !== "toolResult")
|
|
60
|
+
return {};
|
|
61
|
+
const nestedCalls = nestedCallsOf(message);
|
|
62
|
+
return {
|
|
63
|
+
toolName: message.toolName,
|
|
64
|
+
toolCallId: message.toolCallId,
|
|
65
|
+
toolError: message.isError === true ? true : undefined,
|
|
66
|
+
...(nestedCalls ? { nestedCalls } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function toolCallItems(windowId, entry, message, entrySeq) {
|
|
70
|
+
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
71
|
+
return [];
|
|
72
|
+
const items = [];
|
|
73
|
+
let callIndex = 0;
|
|
74
|
+
for (const part of message.content) {
|
|
75
|
+
if (!isToolCall(part))
|
|
76
|
+
continue;
|
|
77
|
+
items.push({
|
|
78
|
+
seq: entrySeq + callIndex + 1,
|
|
79
|
+
windowId,
|
|
80
|
+
role: "tool_call",
|
|
81
|
+
text: "",
|
|
82
|
+
createdAt: entry.timestamp,
|
|
83
|
+
toolName: part.name,
|
|
84
|
+
toolCallId: part.id,
|
|
85
|
+
arguments: part.arguments,
|
|
86
|
+
});
|
|
87
|
+
callIndex += 1;
|
|
88
|
+
}
|
|
89
|
+
return items;
|
|
90
|
+
}
|
|
91
|
+
/** Build stable internal addresses, then project the active branch into public events. */
|
|
92
|
+
export function historyFromSession(ctx) {
|
|
93
|
+
const seqByEntryId = new Map();
|
|
94
|
+
let nextSeq = 1;
|
|
95
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
96
|
+
const count = sequenceCount(entry);
|
|
97
|
+
if (count === 0)
|
|
98
|
+
continue;
|
|
99
|
+
seqByEntryId.set(entry.id, nextSeq);
|
|
100
|
+
nextSeq += count;
|
|
101
|
+
}
|
|
102
|
+
const highestSeq = nextSeq - 1;
|
|
103
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
104
|
+
let window = { windowId: rootWindowId(sessionId), items: [] };
|
|
105
|
+
const rawWindows = [window];
|
|
106
|
+
const branchSeqs = new Set();
|
|
107
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
108
|
+
if (isWindowMarker(entry)) {
|
|
109
|
+
window = { windowId: entry.data.windowId, createdAt: entry.timestamp, items: [] };
|
|
110
|
+
rawWindows.push(window);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const entrySeq = seqByEntryId.get(entry.id);
|
|
114
|
+
if (entrySeq === undefined)
|
|
115
|
+
continue;
|
|
116
|
+
branchSeqs.add(entrySeq);
|
|
117
|
+
if (entry.type === "compaction" || entry.type === "branch_summary") {
|
|
118
|
+
window.items.push({ seq: entrySeq, windowId: window.windowId, role: "system", text: entry.summary, createdAt: entry.timestamp });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (entry.type === "message") {
|
|
122
|
+
const role = mapRole(entry.message.role);
|
|
123
|
+
if (!role)
|
|
124
|
+
continue;
|
|
125
|
+
window.items.push({
|
|
126
|
+
seq: entrySeq,
|
|
127
|
+
windowId: window.windowId,
|
|
128
|
+
role,
|
|
129
|
+
text: messageContent(entry.message),
|
|
130
|
+
createdAt: entry.timestamp,
|
|
131
|
+
...toolInfo(entry.message),
|
|
132
|
+
});
|
|
133
|
+
const calls = toolCallItems(window.windowId, entry, entry.message, entrySeq);
|
|
134
|
+
for (const call of calls)
|
|
135
|
+
branchSeqs.add(call.seq);
|
|
136
|
+
window.items.push(...calls);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (entry.type === "custom_message") {
|
|
140
|
+
window.items.push({
|
|
141
|
+
seq: entrySeq,
|
|
142
|
+
windowId: window.windowId,
|
|
143
|
+
role: "developer",
|
|
144
|
+
text: contentText(entry.content),
|
|
145
|
+
createdAt: entry.timestamp,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return projectHistory(rawWindows, highestSeq, branchSeqs);
|
|
150
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { NotesIdentity } from "../../notes/identity.js";
|
|
3
|
+
/** Pi's default notes root; environment access stays on the host side of the library boundary. */
|
|
4
|
+
export declare function notesRoot(): string;
|
|
5
|
+
/** Translate the current Pi runtime into a fresh, explicit identity snapshot. */
|
|
6
|
+
export declare function agentSlug(_ctx: ExtensionContext): string;
|
|
7
|
+
/** Pi's active model identity is resolved live so a mid-session switch retargets @model. */
|
|
8
|
+
export declare function modelSlug(ctx: ExtensionContext): string;
|
|
9
|
+
/** Translate the current Pi runtime into one explicit notes identity snapshot. */
|
|
10
|
+
export declare function notesIdentityFromPi(ctx: ExtensionContext, home?: string): NotesIdentity;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { projectKey, slugify } from "../../notes/paths.js";
|
|
4
|
+
/** Pi's default notes root; environment access stays on the host side of the library boundary. */
|
|
5
|
+
export function notesRoot() {
|
|
6
|
+
const override = process.env.PI_NOTES_HOME;
|
|
7
|
+
return override && override.length > 0 ? resolve(override) : join(homedir(), ".agents", "notes");
|
|
8
|
+
}
|
|
9
|
+
/** Translate the current Pi runtime into a fresh, explicit identity snapshot. */
|
|
10
|
+
export function agentSlug(_ctx) {
|
|
11
|
+
return slugify(process.env.PI_NOTES_AGENT ?? "anonymous");
|
|
12
|
+
}
|
|
13
|
+
/** Pi's active model identity is resolved live so a mid-session switch retargets @model. */
|
|
14
|
+
export function modelSlug(ctx) {
|
|
15
|
+
const id = ctx.model?.id;
|
|
16
|
+
return id ? slugify(id.split("/").pop() ?? id) : "default";
|
|
17
|
+
}
|
|
18
|
+
/** Translate the current Pi runtime into one explicit notes identity snapshot. */
|
|
19
|
+
export function notesIdentityFromPi(ctx, home = notesRoot()) {
|
|
20
|
+
return {
|
|
21
|
+
home,
|
|
22
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
23
|
+
projectKey: projectKey(ctx.cwd),
|
|
24
|
+
agent: agentSlug(ctx),
|
|
25
|
+
model: modelSlug(ctx),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { generateDiffString } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../../tools/notes.js";
|
|
3
|
+
import { notesIdentityFromPi } from "./adapter.js";
|
|
4
|
+
import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
|
|
5
|
+
function renderDiff(change) {
|
|
6
|
+
return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
|
|
7
|
+
}
|
|
8
|
+
/** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */
|
|
9
|
+
export function registerNotesTools(pi) {
|
|
10
|
+
registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
|
|
11
|
+
registerOperation(pi, notesUpdate, (params, ctx) => notesUpdate.execute(params, notesIdentityFromPi(ctx), renderDiff), NOTES_NAMESPACE);
|
|
12
|
+
registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
|
|
13
|
+
registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
|
|
14
|
+
registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type WindowMarker } from "../window.js";
|
|
3
|
+
import { type IncompleteNotesNotifier } from "../boot.js";
|
|
4
|
+
export type ResetTailState = {
|
|
5
|
+
readonly boot: boolean;
|
|
6
|
+
readonly continuation: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Match the hidden continuation entry that carries the one reset message. */
|
|
9
|
+
export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
|
|
10
|
+
/** The single continuation sender: the only reset prose persisted for a window. */
|
|
11
|
+
export declare function sendContinuation(pi: ExtensionAPI): void;
|
|
12
|
+
/**
|
|
13
|
+
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
14
|
+
* continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string): Promise<SessionBoundaryDraft[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Inspect the persisted tail of a reset marker. It reports which reset messages are present
|
|
19
|
+
* only while the tail stays repairable: metadata may follow the marker, but real conversation,
|
|
20
|
+
* a foreign message, a later marker, or a misordered/duplicate reset artifact refuses repair.
|
|
21
|
+
*/
|
|
22
|
+
export declare function inspectResetTail(ctx: ExtensionContext, markerId: string, windowId: string): ResetTailState | undefined;
|
|
23
|
+
/** Emit only the reset artifacts an incomplete tail is missing, in the closed order. */
|
|
24
|
+
export declare function repairResetTail(pi: ExtensionAPI, ctx: ExtensionContext, marker: WindowMarker, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean): Promise<void>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
|
|
3
|
+
import { CONTINUATION } from "./text.js";
|
|
4
|
+
import { currentWindowId, isWindowBootEntry, isWindowMarker, previousWindowId } from "../window.js";
|
|
5
|
+
import { buildBootMessage, sendBoot } from "../boot.js";
|
|
6
|
+
/** Match the hidden continuation entry that carries the one reset message. */
|
|
7
|
+
export function isWindowContinuationEntry(entry) {
|
|
8
|
+
return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
|
|
9
|
+
}
|
|
10
|
+
/** The single continuation sender: the only reset prose persisted for a window. */
|
|
11
|
+
export function sendContinuation(pi) {
|
|
12
|
+
pi.sendMessage({ customType: CONTINUATION_TYPE, content: CONTINUATION, display: false }, { triggerTurn: false });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
16
|
+
* continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
17
|
+
*/
|
|
18
|
+
export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt) {
|
|
19
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
20
|
+
const previousId = currentWindowId(ctx);
|
|
21
|
+
const sessionPrefix = sessionId.slice(0, 8);
|
|
22
|
+
const usedWindowIds = new Set(ctx.sessionManager.getBranch().filter(isWindowMarker).map((entry) => entry.data.windowId));
|
|
23
|
+
let windowId;
|
|
24
|
+
do {
|
|
25
|
+
windowId = `pcw:${sessionPrefix}:${randomUUID().slice(0, 8)}`;
|
|
26
|
+
} while (usedWindowIds.has(windowId));
|
|
27
|
+
const boot = await buildBootMessage(ctx, windowId, previousId, notifyIncompleteNotes, isCurrent);
|
|
28
|
+
return [
|
|
29
|
+
{ type: "compaction", summary: "", firstKeptEntryId: null },
|
|
30
|
+
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
|
|
31
|
+
{ type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
|
|
32
|
+
{ type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
|
|
33
|
+
...(prompt ? [{ type: "custom_message", customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Inspect the persisted tail of a reset marker. It reports which reset messages are present
|
|
38
|
+
* only while the tail stays repairable: metadata may follow the marker, but real conversation,
|
|
39
|
+
* a foreign message, a later marker, or a misordered/duplicate reset artifact refuses repair.
|
|
40
|
+
*/
|
|
41
|
+
export function inspectResetTail(ctx, markerId, windowId) {
|
|
42
|
+
const branch = ctx.sessionManager.getBranch();
|
|
43
|
+
const markerIndex = branch.findIndex((entry) => entry.id === markerId);
|
|
44
|
+
if (markerIndex < 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
let boot = false;
|
|
47
|
+
let continuation = false;
|
|
48
|
+
for (const entry of branch.slice(markerIndex + 1)) {
|
|
49
|
+
if (isWindowBootEntry(entry, windowId)) {
|
|
50
|
+
// The boot is unique and must precede the continuation; a repeat or a late
|
|
51
|
+
// boot would move the provider boundary or misorder the reset shape.
|
|
52
|
+
if (boot || continuation)
|
|
53
|
+
return undefined;
|
|
54
|
+
boot = true;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (isWindowContinuationEntry(entry)) {
|
|
58
|
+
if (continuation || !boot)
|
|
59
|
+
return undefined;
|
|
60
|
+
continuation = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (isWindowMarker(entry) || entry.type === "message" || entry.type === "custom_message" || entry.type === "compaction" || entry.type === "branch_summary") {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { boot, continuation };
|
|
68
|
+
}
|
|
69
|
+
/** Emit only the reset artifacts an incomplete tail is missing, in the closed order. */
|
|
70
|
+
export async function repairResetTail(pi, ctx, marker, notifyIncompleteNotes, isCurrent = () => true) {
|
|
71
|
+
const tail = inspectResetTail(ctx, marker.id, marker.data.windowId);
|
|
72
|
+
if (!tail || (tail.boot && tail.continuation))
|
|
73
|
+
return;
|
|
74
|
+
const boot = tail.boot ? undefined : await buildBootMessage(ctx, marker.data.windowId, previousWindowId(ctx, marker.id), notifyIncompleteNotes, isCurrent);
|
|
75
|
+
if (!isCurrent())
|
|
76
|
+
return;
|
|
77
|
+
const latest = inspectResetTail(ctx, marker.id, marker.data.windowId);
|
|
78
|
+
if (!latest)
|
|
79
|
+
return;
|
|
80
|
+
if (!latest.boot && boot)
|
|
81
|
+
sendBoot(pi, boot);
|
|
82
|
+
if (!latest.continuation && (latest.boot || boot))
|
|
83
|
+
sendContinuation(pi);
|
|
84
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SessionReader } from "../session-reader.js";
|
|
2
|
+
/**
|
|
3
|
+
* Confirm a native boundary on this branch, independent of whether its suffix is still
|
|
4
|
+
* repairable. Later conversation cannot uncommit a checkpoint -> marker -> boot ->
|
|
5
|
+
* continuation already persisted by Pi. No shadow commit state is maintained here.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resetBoundaryCommitted(ctx: SessionReader, markerId: string, windowId: string): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isCheckpointBackedReset, isWindowBootEntry, isWindowMarker } from "../window.js";
|
|
2
|
+
import { isWindowContinuationEntry } from "./artifacts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Confirm a native boundary on this branch, independent of whether its suffix is still
|
|
5
|
+
* repairable. Later conversation cannot uncommit a checkpoint -> marker -> boot ->
|
|
6
|
+
* continuation already persisted by Pi. No shadow commit state is maintained here.
|
|
7
|
+
*/
|
|
8
|
+
export function resetBoundaryCommitted(ctx, markerId, windowId) {
|
|
9
|
+
const branch = ctx.sessionManager.getBranch();
|
|
10
|
+
const markerIndex = branch.findIndex((entry) => entry.id === markerId);
|
|
11
|
+
const marker = branch[markerIndex];
|
|
12
|
+
if (!marker || !isWindowMarker(marker) || marker.data.windowId !== windowId || !isCheckpointBackedReset(ctx, marker))
|
|
13
|
+
return false;
|
|
14
|
+
let boot = false;
|
|
15
|
+
for (const entry of branch.slice(markerIndex + 1)) {
|
|
16
|
+
if (isWindowBootEntry(entry, windowId)) {
|
|
17
|
+
if (boot || entry.type !== "custom_message" || entry.display !== false)
|
|
18
|
+
return false;
|
|
19
|
+
boot = true;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (isWindowContinuationEntry(entry))
|
|
23
|
+
return boot && entry.type === "custom_message" && entry.display === false;
|
|
24
|
+
if (isWindowMarker(entry) || entry.type === "message" || entry.type === "custom_message" || entry.type === "compaction" || entry.type === "branch_summary")
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
type BudgetOwner = {
|
|
3
|
+
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
4
|
+
hardReserveDue: (ctx: ExtensionContext) => boolean;
|
|
5
|
+
consumeTurnEnd: (ctx: ExtensionContext) => SessionBoundaryDraft[];
|
|
6
|
+
clear: () => void;
|
|
7
|
+
};
|
|
8
|
+
type ResetOptions = {
|
|
9
|
+
isEnabled: () => boolean;
|
|
10
|
+
budget: BudgetOwner;
|
|
11
|
+
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
12
|
+
getLifecycleGeneration?: () => number;
|
|
13
|
+
onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
|
|
14
|
+
};
|
|
15
|
+
export type ResetRequestSource = "manual" | "automatic";
|
|
16
|
+
type ToolResetRequestSource = "automatic" | "tool";
|
|
17
|
+
export type ResetRequest = {
|
|
18
|
+
readonly phase: "none";
|
|
19
|
+
} | {
|
|
20
|
+
readonly phase: "stop-pending";
|
|
21
|
+
readonly windowId: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly phase: "close-out";
|
|
24
|
+
readonly windowId: string;
|
|
25
|
+
readonly source: ResetRequestSource;
|
|
26
|
+
readonly prompt?: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly phase: "tool-requested";
|
|
29
|
+
readonly windowId: string;
|
|
30
|
+
readonly source: ToolResetRequestSource;
|
|
31
|
+
};
|
|
32
|
+
export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
|
|
33
|
+
export interface ResetControlState {
|
|
34
|
+
readonly request: ResetRequest;
|
|
35
|
+
readonly overflow: ResetOverflowPhase;
|
|
36
|
+
}
|
|
37
|
+
export declare function initialResetControl(): ResetControlState;
|
|
38
|
+
/** Facts for a completed turn. Guard values stay lazy to preserve policy resolution order. */
|
|
39
|
+
export interface ResetTurnEndFacts {
|
|
40
|
+
readonly windowId: string;
|
|
41
|
+
readonly aborted: boolean;
|
|
42
|
+
readonly overflow: boolean;
|
|
43
|
+
readonly failed: boolean;
|
|
44
|
+
readonly enabled: boolean;
|
|
45
|
+
readonly queued: boolean;
|
|
46
|
+
readonly automaticResetEnabled: boolean;
|
|
47
|
+
readonly hardReserveDue: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Facts for the pre-settlement boundary; policy guards stay lazy for the same reason. */
|
|
50
|
+
export interface ResetBeforeSettleFacts {
|
|
51
|
+
readonly windowId: string;
|
|
52
|
+
readonly queued: boolean;
|
|
53
|
+
readonly enabled: boolean;
|
|
54
|
+
readonly automaticResetEnabled: boolean;
|
|
55
|
+
readonly aborted: boolean;
|
|
56
|
+
readonly failed: boolean;
|
|
57
|
+
}
|
|
58
|
+
export type ResetControlEvent = {
|
|
59
|
+
readonly type: "close_out";
|
|
60
|
+
readonly windowId: string;
|
|
61
|
+
readonly source: ResetRequestSource;
|
|
62
|
+
readonly prompt?: string;
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: "tool_request";
|
|
65
|
+
readonly windowId: string;
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: "turn_end";
|
|
68
|
+
readonly facts: ResetTurnEndFacts;
|
|
69
|
+
} | {
|
|
70
|
+
readonly type: "before_settle";
|
|
71
|
+
readonly facts: ResetBeforeSettleFacts;
|
|
72
|
+
} | {
|
|
73
|
+
readonly type: "settled";
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "abort";
|
|
76
|
+
} | {
|
|
77
|
+
readonly type: "clear";
|
|
78
|
+
};
|
|
79
|
+
export type ResetControlEffect = "none" | "close-out-armed" | "already-pending" | "commit-boundary" | "commit-boundary-stop" | "stop" | "recover-overflow";
|
|
80
|
+
export interface ResetControlResult {
|
|
81
|
+
readonly state: ResetControlState;
|
|
82
|
+
readonly effect: ResetControlEffect;
|
|
83
|
+
readonly prompt?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
|
|
86
|
+
export declare function reduceResetControl(state: ResetControlState, event: ResetControlEvent): ResetControlResult;
|
|
87
|
+
/**
|
|
88
|
+
* Own close-out requests at Pi's public turn and pre-settlement boundaries. Manual and budget
|
|
89
|
+
* close-outs remain armed across note/tool turns. Only manual close-outs commit at a
|
|
90
|
+
* successful agent_before_settle; budget warnings alone never authorize a reset.
|
|
91
|
+
* A hard-reserve safety reset can commit earlier, but preserves a
|
|
92
|
+
* run-scoped manual stop and cancels an otherwise automatic fresh-window request through
|
|
93
|
+
* the public abort API. Direct tool requests commit at turn_end and continue normally.
|
|
94
|
+
* Overflow recovery remains bounded.
|
|
95
|
+
*/
|
|
96
|
+
export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
|
|
97
|
+
closeOut(windowId: string, source: ResetRequestSource, prompt?: string): ResetControlEffect;
|
|
98
|
+
request(windowId: string): "rollover_already_pending" | "rollover_requested";
|
|
99
|
+
clear: () => void;
|
|
100
|
+
};
|
|
101
|
+
export {};
|