notesoup 0.60.1 → 0.62.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/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -10
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.d.ts +5 -0
- package/dist/src/boot/render.js +60 -28
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +27 -26
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/frontmatter.d.ts +4 -0
- package/dist/src/notes/frontmatter.js +15 -1
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +47 -6
- package/dist/src/notes/store.d.ts +14 -0
- package/dist/src/notes/store.js +33 -12
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -91
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +58 -160
- package/dist/src/tools/notes.js +151 -99
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +198 -16
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +65 -2
- package/dist/test/helpers/extension.js +72 -3
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/note-policy.test.js +189 -56
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +4 -4
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +6 -6
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +3 -3
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1129 -549
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18494 -17905
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +3 -3
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +2 -2
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +59 -25
- package/src/boot/text.ts +30 -27
- package/src/budget/text.ts +13 -13
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +1 -1
- package/src/notes/frontmatter.ts +16 -1
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +45 -6
- package/src/notes/store.ts +30 -15
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +150 -112
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
3
4
|
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
4
5
|
import { Type } from "typebox";
|
|
@@ -6,10 +7,10 @@ import { VERSION, defineTool } from "@earendil-works/pi-coding-agent";
|
|
|
6
7
|
import { registerBudget } from "./budget.js";
|
|
7
8
|
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
|
|
8
9
|
import { emptyBrainRenderers } from "./render.js";
|
|
9
|
-
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow,
|
|
10
|
+
import { activeBranchTail, currentReset, currentWindowId, isCheckpointBackedReset, isNotesoupEnabled, isNotesoupSkillPath, isWindowBoot, isWindowBootEntry, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, stripNotesoupProjection } from "./window.js";
|
|
10
11
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
11
12
|
import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
12
|
-
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
13
|
+
import { BOOT_TYPE, ENABLED_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
13
14
|
import { commandWarningContent, PI_PRE_RESET_HINTS } from "./text.js";
|
|
14
15
|
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../src/boot/text.js";
|
|
15
16
|
import { agentSlug } from "./notes/adapter.js";
|
|
@@ -37,33 +38,26 @@ function branchHasWindowMarker(ctx, fromId) {
|
|
|
37
38
|
return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* Resolve notesoup's own `skills/` directory in both layouts: direct TypeScript source
|
|
42
|
+
* (`plugins/pi/runtime.ts`) and the compiled package (`dist/plugins/pi/runtime.js`).
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
53
|
-
return;
|
|
44
|
+
function resolveNotesoupSkillDirs() {
|
|
45
|
+
const dirs = new Set();
|
|
46
|
+
for (const candidate of ["../../skills", "../../../skills"]) {
|
|
47
|
+
try {
|
|
48
|
+
const path = fileURLToPath(new URL(candidate, import.meta.url));
|
|
49
|
+
if (existsSync(path))
|
|
50
|
+
dirs.add(realpathSync(path));
|
|
51
|
+
}
|
|
52
|
+
catch { /* not a source or compiled layout */ }
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
return;
|
|
57
|
-
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
58
|
-
if (!stillCurrent())
|
|
59
|
-
return;
|
|
60
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
|
|
61
|
-
return;
|
|
62
|
-
sendBoot(pi, boot);
|
|
54
|
+
return [...dirs];
|
|
63
55
|
}
|
|
56
|
+
const notesoupSkillDirs = resolveNotesoupSkillDirs();
|
|
64
57
|
/** Register the context-window runtime and its context-owned commands/tools. */
|
|
65
58
|
export function registerContext(pi, settingsManager) {
|
|
66
|
-
|
|
59
|
+
pi.registerFlag("no-notesoup", { description: "Start with notesoup off (/notesoup on overrides)", type: "boolean", default: false });
|
|
60
|
+
const isEnabled = (ctx) => isNotesoupEnabled(pi, ctx);
|
|
67
61
|
let lifecycleGeneration = 0;
|
|
68
62
|
let missingBootNotice;
|
|
69
63
|
const incompleteNotesNotified = new Set();
|
|
@@ -85,11 +79,49 @@ export function registerContext(pi, settingsManager) {
|
|
|
85
79
|
ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
86
80
|
}
|
|
87
81
|
};
|
|
88
|
-
|
|
82
|
+
/** Complete a reset tail that a previous process left half-written. */
|
|
83
|
+
const ensureResetRepair = async (ctx, isCurrent) => {
|
|
84
|
+
const reset = currentReset(ctx);
|
|
85
|
+
if (!reset)
|
|
86
|
+
return;
|
|
87
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
88
|
+
const windowId = reset.data.windowId;
|
|
89
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
90
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
91
|
+
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
92
|
+
};
|
|
93
|
+
/** Root windows (or windows after a native compaction while off) boot lazily before the first provider-facing turn. */
|
|
94
|
+
const buildLazyBoot = async (ctx, isCurrent) => {
|
|
95
|
+
if (currentReset(ctx))
|
|
96
|
+
return undefined;
|
|
97
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
98
|
+
const windowId = currentWindowId(ctx);
|
|
99
|
+
const hasBoot = () => activeBranchTail(ctx.sessionManager.getBranch()).some((entry) => isWindowBootEntry(entry, windowId)) ||
|
|
100
|
+
ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId));
|
|
101
|
+
if (hasBoot())
|
|
102
|
+
return undefined;
|
|
103
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
104
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId && !currentReset(ctx);
|
|
105
|
+
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
106
|
+
if (!stillCurrent() || hasBoot())
|
|
107
|
+
return undefined;
|
|
108
|
+
return boot;
|
|
109
|
+
};
|
|
110
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
111
|
+
if (!isEnabled(ctx)) {
|
|
112
|
+
event.systemPromptOptions.skills = event.systemPromptOptions.skills.filter((skill) => !isNotesoupSkillPath(skill.filePath, notesoupSkillDirs));
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
89
115
|
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
90
116
|
event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
maybeSendMarker(pi, ctx);
|
|
118
|
+
if (!currentReset(ctx) && !(event.messageType === "custom" && event.message.customType === MANUAL_WIPE_TYPE)) {
|
|
119
|
+
const generation = lifecycleGeneration;
|
|
120
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
121
|
+
if (boot)
|
|
122
|
+
return { message: boot };
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
93
125
|
});
|
|
94
126
|
pi.on("turn_start", (_event, ctx) => {
|
|
95
127
|
notifyCommittedResets(ctx);
|
|
@@ -106,21 +138,20 @@ export function registerContext(pi, settingsManager) {
|
|
|
106
138
|
const namespaces = snapshot.unavailable.map((namespace) => namespace.label).join(", ");
|
|
107
139
|
ctx.ui.notify(`🥣 Some notes went missing: ${namespaces}`, "warning");
|
|
108
140
|
};
|
|
109
|
-
const budget = registerBudget(pi, () =>
|
|
141
|
+
const budget = registerBudget(pi, (ctx) => isEnabled(ctx), settingsManager);
|
|
110
142
|
pi.on("session_start", async (_event, ctx) => {
|
|
111
143
|
const generation = ++lifecycleGeneration;
|
|
112
|
-
if (!enabled)
|
|
113
|
-
return;
|
|
114
144
|
missingBootNotice = undefined;
|
|
115
145
|
pendingResetNotices.clear();
|
|
116
|
-
|
|
146
|
+
if (isEnabled(ctx))
|
|
147
|
+
await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
117
148
|
});
|
|
118
149
|
pi.on("session_tree", async (_event, ctx) => {
|
|
119
150
|
const generation = ++lifecycleGeneration;
|
|
120
151
|
missingBootNotice = undefined;
|
|
121
152
|
pendingResetNotices.clear();
|
|
122
|
-
if (
|
|
123
|
-
await
|
|
153
|
+
if (isEnabled(ctx))
|
|
154
|
+
await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
124
155
|
});
|
|
125
156
|
pi.on("session_shutdown", () => {
|
|
126
157
|
lifecycleGeneration++;
|
|
@@ -140,12 +171,10 @@ export function registerContext(pi, settingsManager) {
|
|
|
140
171
|
// root windows only refresh a forked boot identity and retain the copied root transcript.
|
|
141
172
|
pi.on("context_with_system", (event, ctx) => {
|
|
142
173
|
const reset = currentReset(ctx);
|
|
143
|
-
const windowId =
|
|
174
|
+
const windowId = currentWindowId(ctx);
|
|
144
175
|
try {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return { messages: projectRootWindow(event.messages, windowId) };
|
|
176
|
+
const projected = reset ? projectWindow(event.messages, windowId) : projectRootWindow(event.messages, windowId);
|
|
177
|
+
return { messages: isEnabled(ctx) ? projected : stripNotesoupProjection(projected, notesoupSkillDirs) };
|
|
149
178
|
}
|
|
150
179
|
catch (error) {
|
|
151
180
|
if (missingBootNotice !== windowId) {
|
|
@@ -159,7 +188,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
159
188
|
});
|
|
160
189
|
pi.registerCommand("notesoup", {
|
|
161
190
|
description: "Show notesoup status, toggle context windows, or cap their capacity",
|
|
162
|
-
getArgumentCompletions: (prefix) => ["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
191
|
+
getArgumentCompletions: (prefix) => ["on", "off", "reset", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
163
192
|
handler: async (args, cmdCtx) => {
|
|
164
193
|
const arg = args.trim().toLowerCase();
|
|
165
194
|
const parts = arg.split(/\s+/);
|
|
@@ -177,39 +206,40 @@ export function registerContext(pi, settingsManager) {
|
|
|
177
206
|
}
|
|
178
207
|
}
|
|
179
208
|
}
|
|
180
|
-
else if (arg === "on") {
|
|
181
|
-
enabled
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
209
|
+
else if (arg === "on" || arg === "off" || arg === "reset") {
|
|
210
|
+
pi.appendEntry(ENABLED_TYPE, { version: 1, enabled: arg === "reset" ? null : arg === "on" });
|
|
211
|
+
if (isEnabled(cmdCtx)) {
|
|
212
|
+
const generation = ++lifecycleGeneration;
|
|
213
|
+
await ensureResetRepair(cmdCtx, () => generation === lifecycleGeneration && isEnabled(cmdCtx));
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
lifecycleGeneration++;
|
|
217
|
+
pendingResetNotices.clear();
|
|
218
|
+
incompleteNotesNotified.clear();
|
|
219
|
+
missingBootNotice = undefined;
|
|
220
|
+
budget.clear();
|
|
221
|
+
resets.clear();
|
|
222
|
+
}
|
|
193
223
|
}
|
|
194
224
|
else if (arg !== "") {
|
|
195
|
-
cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
|
|
225
|
+
cmdCtx.ui.notify("Usage: /notesoup [on|off|reset|cap [100k|1m|tokens|off]]", "error");
|
|
196
226
|
return;
|
|
197
227
|
}
|
|
198
228
|
const { remaining, cap } = budget.statusFor(cmdCtx);
|
|
199
|
-
cmdCtx.ui.notify(`🥣 notesoup ${
|
|
229
|
+
cmdCtx.ui.notify(`🥣 notesoup ${isEnabled(cmdCtx) ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
200
230
|
},
|
|
201
231
|
});
|
|
202
232
|
const emptyBrainCommand = (name) => ({
|
|
203
233
|
description: "Flush memory to notes, reset, and stop; optional text provides close-out context",
|
|
204
234
|
handler: async (args, cmdCtx) => {
|
|
205
|
-
if (!
|
|
235
|
+
if (!isEnabled(cmdCtx)) {
|
|
206
236
|
cmdCtx.ui.notify("🥣 notesoup is off · no brain to empty", "error");
|
|
207
237
|
return;
|
|
208
238
|
}
|
|
209
239
|
const requestedWindowId = currentWindowId(cmdCtx);
|
|
210
240
|
if (!cmdCtx.isIdle() && !cmdCtx.signal) {
|
|
211
241
|
await cmdCtx.waitForIdle();
|
|
212
|
-
if (!
|
|
242
|
+
if (!isEnabled(cmdCtx) || currentWindowId(cmdCtx) !== requestedWindowId)
|
|
213
243
|
return;
|
|
214
244
|
}
|
|
215
245
|
// Manual wipes close out at settlement, then stop unless later human input arrives. The hidden warning is triggered when idle,
|
|
@@ -238,13 +268,13 @@ export function registerContext(pi, settingsManager) {
|
|
|
238
268
|
label: "Empty Brain",
|
|
239
269
|
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
|
|
240
270
|
parameters: Type.Object({
|
|
241
|
-
last_word: Type.Optional(Type.String({ description: `A tiny sticky note
|
|
242
|
-
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe.
|
|
271
|
+
last_word: Type.Optional(Type.String({ description: `A tiny sticky note (at most ${LAST_WORD_ADVERTISED_CHARS} characters), slapped on your forehead after the wipe.` })),
|
|
272
|
+
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe." })),
|
|
243
273
|
}, { additionalProperties: false }),
|
|
244
274
|
renderCall: emptyBrainRenderers.renderCall,
|
|
245
275
|
renderResult: emptyBrainRenderers.renderResult,
|
|
246
276
|
async execute(_id, params, _signal, _update, ctx) {
|
|
247
|
-
if (!
|
|
277
|
+
if (!isEnabled(ctx))
|
|
248
278
|
return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
249
279
|
const lastWord = sanitizeLastWord(params.last_word);
|
|
250
280
|
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
@@ -254,7 +284,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
254
284
|
},
|
|
255
285
|
}));
|
|
256
286
|
const resets = registerResetLifecycle(pi, {
|
|
257
|
-
isEnabled: () =>
|
|
287
|
+
isEnabled: (ctx) => isEnabled(ctx),
|
|
258
288
|
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin),
|
|
259
289
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
260
290
|
onResetReady: (_ctx, drafts) => {
|
|
@@ -267,4 +297,15 @@ export function registerContext(pi, settingsManager) {
|
|
|
267
297
|
},
|
|
268
298
|
budget,
|
|
269
299
|
});
|
|
300
|
+
// Registered after the reset lifecycle so a reset that swallows this input (`handled`)
|
|
301
|
+
// never gets a root boot for a turn that will not run.
|
|
302
|
+
pi.on("input", async (event, ctx) => {
|
|
303
|
+
if (!ctx.isIdle() || event.streamingBehavior || !isEnabled(ctx) || currentReset(ctx))
|
|
304
|
+
return undefined;
|
|
305
|
+
const generation = lifecycleGeneration;
|
|
306
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
307
|
+
if (boot)
|
|
308
|
+
sendBoot(pi, boot);
|
|
309
|
+
return undefined;
|
|
310
|
+
});
|
|
270
311
|
}
|
|
@@ -8,17 +8,17 @@ export function output(value, details, terminate = false) {
|
|
|
8
8
|
return { content: [{ type: "text", text: JSON.stringify(value) }], details, terminate, ...(refused ? { isError: true } : {}) };
|
|
9
9
|
}
|
|
10
10
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
11
|
-
function piOperationResult(
|
|
11
|
+
function piOperationResult(operation, outcome, details) {
|
|
12
12
|
return {
|
|
13
|
-
content: [{ type: "text", text: render(outcome) }],
|
|
14
|
-
structuredContent: wireResult(outcome),
|
|
13
|
+
content: [{ type: "text", text: operation.render(outcome) }],
|
|
14
|
+
...(operation.outputSchema !== undefined ? { structuredContent: wireResult(outcome) } : {}),
|
|
15
15
|
isError: !outcome.ok,
|
|
16
16
|
details: details,
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the
|
|
19
|
+
export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the notesoup skill." };
|
|
20
20
|
export const DREAM_NAMESPACE = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
|
|
21
|
-
export const HISTORY_NAMESPACE = { name: "history", description: "Session history (this or other local sessions): history_list to browse
|
|
21
|
+
export const HISTORY_NAMESPACE = { name: "history", description: "Session history (this or other local sessions): history_list to browse a timeline or list sessions, history_search to find passages, history_read to read one event." };
|
|
22
22
|
/** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
|
|
23
23
|
export function registerOperation(pi, operation, run, namespace, renderers, exposure) {
|
|
24
24
|
pi.registerTool(defineTool({
|
|
@@ -26,14 +26,14 @@ export function registerOperation(pi, operation, run, namespace, renderers, expo
|
|
|
26
26
|
label: operation.label,
|
|
27
27
|
description: operation.description,
|
|
28
28
|
parameters: operation.parameters,
|
|
29
|
-
outputSchema: operation.outputSchema,
|
|
29
|
+
...(operation.outputSchema ? { outputSchema: operation.outputSchema } : {}),
|
|
30
30
|
executionMode: operation.executionMode,
|
|
31
31
|
...(namespace ? { namespace } : {}),
|
|
32
32
|
...(exposure ? { exposure } : {}),
|
|
33
33
|
...renderers,
|
|
34
34
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
35
35
|
const result = await run(params, ctx);
|
|
36
|
-
return piOperationResult(operation
|
|
36
|
+
return piOperationResult(operation, result, result.details);
|
|
37
37
|
},
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
@@ -15,15 +15,35 @@ export declare function isWindowMarker(entry: SessionEntry): entry is WindowMark
|
|
|
15
15
|
* carried, or with an unreadable one, was the model's own reset.
|
|
16
16
|
*/
|
|
17
17
|
export declare function markerResetOrigin(marker: WindowMarker): ResetOrigin;
|
|
18
|
-
/**
|
|
18
|
+
/** Branch entries after the latest compaction, or the full branch before any compaction. */
|
|
19
|
+
export declare function activeBranchTail(branch: readonly SessionEntry[]): readonly SessionEntry[];
|
|
20
|
+
/** Only a reset marker still ahead of any later native compaction owns the active projection boundary. */
|
|
19
21
|
export declare function currentReset(ctx: SessionReader): WindowMarker | undefined;
|
|
22
|
+
/** The explicit `/notesoup on|off|reset` choice for this branch, or undefined when never chosen. */
|
|
23
|
+
export declare function sessionEnabled(branch: readonly SessionEntry[]): boolean | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Whether pi-souls reports a naked run. Ask the loaded pi-souls extension synchronously first;
|
|
26
|
+
* when it is absent, read the same durable entry it would have consulted.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isNakedSession(pi: {
|
|
29
|
+
events?: {
|
|
30
|
+
emit(channel: string, data: unknown): void;
|
|
31
|
+
};
|
|
32
|
+
}, branch: readonly SessionEntry[]): boolean;
|
|
33
|
+
/** Explicit branch choice wins; otherwise the CLI flag and a naked pi-souls run both disable. */
|
|
34
|
+
export declare function isNotesoupEnabled(pi: {
|
|
35
|
+
getFlag?(name: string): unknown;
|
|
36
|
+
events?: {
|
|
37
|
+
emit(channel: string, data: unknown): void;
|
|
38
|
+
};
|
|
39
|
+
}, ctx: SessionReader): boolean;
|
|
20
40
|
/** A reset is checkpoint-backed only when its marker directly follows a native compaction. */
|
|
21
41
|
export declare function isCheckpointBackedReset(ctx: SessionReader, marker?: WindowMarker | undefined): boolean;
|
|
22
42
|
/** Mint the durable identity of a session's root history window. */
|
|
23
43
|
export declare function rootWindowId(sessionId: string): string;
|
|
24
|
-
/** Persisted messages in the active window, excluding earlier windows
|
|
44
|
+
/** Persisted messages in the active window segment, excluding earlier windows and compacted prefixes. */
|
|
25
45
|
export declare function hasWindowMessage(ctx: SessionReader, customType: string): boolean;
|
|
26
|
-
/** The root or latest durable
|
|
46
|
+
/** The root or latest durable window identity on the active branch, matching history windows. */
|
|
27
47
|
export declare function currentWindowId(ctx: SessionReader): string;
|
|
28
48
|
/** The durable window active just before the marker: the last earlier marker, else the root window. */
|
|
29
49
|
export declare function previousWindowId(ctx: SessionReader, markerId: string): string;
|
|
@@ -48,5 +68,15 @@ export declare function projectWindow(messages: AgentMessage[], windowId: string
|
|
|
48
68
|
* while retaining every user/assistant/tool message from the copied root transcript.
|
|
49
69
|
*/
|
|
50
70
|
export declare function projectRootWindow(messages: AgentMessage[], windowId: string): AgentMessage[];
|
|
71
|
+
/** Every tool the notesoup extension registers. */
|
|
72
|
+
export declare const NOTESOUP_TOOL_NAMES: ReadonlySet<string>;
|
|
73
|
+
/** Whether a skill file lives under notesoup's own `skills/` roots (symlink-resolved). */
|
|
74
|
+
export declare function isNotesoupSkillPath(filePath: string, skillRoots?: readonly string[]): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Provider projection for `/notesoup off`: erase this extension's custom messages, teaching
|
|
77
|
+
* sections, skills and tool declarations so a disabled session looks like a plain Pi session.
|
|
78
|
+
* `CARRIED_INPUT_TYPE` survives because it is the human's withheld input, not notesoup state.
|
|
79
|
+
*/
|
|
80
|
+
export declare function stripNotesoupProjection(messages: AgentMessage[], skillRoots?: readonly string[]): AgentMessage[];
|
|
51
81
|
/** Usage for the selected window, excluding provider usage recorded before its marker. */
|
|
52
82
|
export declare function windowUsage(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">): import("@earendil-works/pi-coding-agent").ContextUsage | undefined;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { resolve, sep } from "node:path";
|
|
2
4
|
import { estimateContextTokens } from "./estimate.js";
|
|
3
5
|
import { convertToLlm } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import { BOOT_TYPE, RESET_MARKER_TYPE } from "./entries.js";
|
|
6
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, ENABLED_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "./entries.js";
|
|
5
7
|
import { NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
|
|
6
8
|
export function isWindowMarker(entry) {
|
|
7
9
|
return entry.type === "custom" && entry.customType === RESET_MARKER_TYPE &&
|
|
@@ -16,16 +18,78 @@ export function isWindowMarker(entry) {
|
|
|
16
18
|
export function markerResetOrigin(marker) {
|
|
17
19
|
return marker.data.origin === "forced" ? "forced" : "normal";
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
function lastWindowMarker(entries) {
|
|
22
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
23
|
+
const entry = entries[i];
|
|
24
|
+
if (entry && isWindowMarker(entry))
|
|
25
|
+
return entry;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Branch entries after the latest compaction, or the full branch before any compaction. */
|
|
30
|
+
export function activeBranchTail(branch) {
|
|
31
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
32
|
+
if (branch[i]?.type === "compaction")
|
|
33
|
+
return branch.slice(i + 1);
|
|
34
|
+
}
|
|
35
|
+
return branch;
|
|
36
|
+
}
|
|
37
|
+
/** Only a reset marker still ahead of any later native compaction owns the active projection boundary. */
|
|
20
38
|
export function currentReset(ctx) {
|
|
21
|
-
|
|
39
|
+
return lastWindowMarker(activeBranchTail(ctx.sessionManager.getBranch()));
|
|
40
|
+
}
|
|
41
|
+
/** The explicit `/notesoup on|off|reset` choice for this branch, or undefined when never chosen. */
|
|
42
|
+
export function sessionEnabled(branch) {
|
|
22
43
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
23
44
|
const entry = branch[i];
|
|
24
|
-
if (entry
|
|
25
|
-
|
|
45
|
+
if (entry.type !== "custom" || entry.customType !== ENABLED_TYPE)
|
|
46
|
+
continue;
|
|
47
|
+
const data = entry.data;
|
|
48
|
+
if (typeof data !== "object" || data === null)
|
|
49
|
+
continue;
|
|
50
|
+
const enabled = data.enabled;
|
|
51
|
+
if (enabled === true)
|
|
52
|
+
return true;
|
|
53
|
+
if (enabled === false)
|
|
54
|
+
return false;
|
|
55
|
+
if (enabled === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
// Malformed data: keep scanning for an older readable choice.
|
|
26
58
|
}
|
|
27
59
|
return undefined;
|
|
28
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether pi-souls reports a naked run. Ask the loaded pi-souls extension synchronously first;
|
|
63
|
+
* when it is absent, read the same durable entry it would have consulted.
|
|
64
|
+
*/
|
|
65
|
+
export function isNakedSession(pi, branch) {
|
|
66
|
+
const query = { branch };
|
|
67
|
+
pi.events?.emit("pi-souls:state", query);
|
|
68
|
+
if (typeof query.naked === "boolean")
|
|
69
|
+
return query.naked;
|
|
70
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
71
|
+
const entry = branch[i];
|
|
72
|
+
if (entry.type !== "custom" || entry.customType !== "pi-souls:naked")
|
|
73
|
+
continue;
|
|
74
|
+
const data = entry.data;
|
|
75
|
+
if (typeof data !== "object" || data === null)
|
|
76
|
+
continue;
|
|
77
|
+
const naked = data.naked;
|
|
78
|
+
if (naked === true)
|
|
79
|
+
return true;
|
|
80
|
+
if (naked === false || naked === null)
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
/** Explicit branch choice wins; otherwise the CLI flag and a naked pi-souls run both disable. */
|
|
86
|
+
export function isNotesoupEnabled(pi, ctx) {
|
|
87
|
+
const branch = ctx.sessionManager.getBranch();
|
|
88
|
+
const explicit = sessionEnabled(branch);
|
|
89
|
+
if (explicit !== undefined)
|
|
90
|
+
return explicit;
|
|
91
|
+
return pi.getFlag?.("no-notesoup") !== true && !isNakedSession(pi, branch);
|
|
92
|
+
}
|
|
29
93
|
/** A reset is checkpoint-backed only when its marker directly follows a native compaction. */
|
|
30
94
|
export function isCheckpointBackedReset(ctx, marker = currentReset(ctx)) {
|
|
31
95
|
if (!marker?.parentId)
|
|
@@ -40,21 +104,23 @@ export function isCheckpointBackedReset(ctx, marker = currentReset(ctx)) {
|
|
|
40
104
|
export function rootWindowId(sessionId) {
|
|
41
105
|
return `pcw:${sessionId.slice(0, 8)}:root`;
|
|
42
106
|
}
|
|
43
|
-
/** Persisted messages in the active window, excluding earlier windows
|
|
107
|
+
/** Persisted messages in the active window segment, excluding earlier windows and compacted prefixes. */
|
|
44
108
|
export function hasWindowMessage(ctx, customType) {
|
|
45
109
|
const branch = ctx.sessionManager.getBranch();
|
|
46
110
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
47
111
|
const entry = branch[i];
|
|
48
|
-
if (
|
|
112
|
+
if (!entry)
|
|
113
|
+
continue;
|
|
114
|
+
if (isWindowMarker(entry) || entry.type === "compaction")
|
|
49
115
|
break;
|
|
50
116
|
if (entry.type === "custom_message" && entry.customType === customType)
|
|
51
117
|
return true;
|
|
52
118
|
}
|
|
53
119
|
return false;
|
|
54
120
|
}
|
|
55
|
-
/** The root or latest durable
|
|
121
|
+
/** The root or latest durable window identity on the active branch, matching history windows. */
|
|
56
122
|
export function currentWindowId(ctx) {
|
|
57
|
-
return
|
|
123
|
+
return lastWindowMarker(ctx.sessionManager.getBranch())?.data.windowId ?? rootWindowId(ctx.sessionManager.getSessionId());
|
|
58
124
|
}
|
|
59
125
|
/** The durable window active just before the marker: the last earlier marker, else the root window. */
|
|
60
126
|
export function previousWindowId(ctx, markerId) {
|
|
@@ -136,6 +202,140 @@ export function projectRootWindow(messages, windowId) {
|
|
|
136
202
|
const withoutBoots = messages.filter((message) => !isWindowBoot(message));
|
|
137
203
|
return [...withoutBoots.slice(0, firstBoot), activeBoot, ...withoutBoots.slice(firstBoot)];
|
|
138
204
|
}
|
|
205
|
+
/** Every tool the notesoup extension registers. */
|
|
206
|
+
export const NOTESOUP_TOOL_NAMES = new Set([
|
|
207
|
+
"empty_brain",
|
|
208
|
+
"get_context_remaining",
|
|
209
|
+
"notes_write",
|
|
210
|
+
"notes_update",
|
|
211
|
+
"notes_read",
|
|
212
|
+
"notes_list",
|
|
213
|
+
"dream_begin",
|
|
214
|
+
"dream_forget",
|
|
215
|
+
"dream_end",
|
|
216
|
+
"history_list",
|
|
217
|
+
"history_search",
|
|
218
|
+
"history_read",
|
|
219
|
+
]);
|
|
220
|
+
const NOTESOUP_MESSAGE_TYPES = new Set([
|
|
221
|
+
BOOT_TYPE,
|
|
222
|
+
GUIDANCE_TYPE,
|
|
223
|
+
WARNING_TYPE,
|
|
224
|
+
MANUAL_WIPE_TYPE,
|
|
225
|
+
CONTINUATION_TYPE,
|
|
226
|
+
RESET_LAST_WORD_TYPE,
|
|
227
|
+
MARKER_TYPE,
|
|
228
|
+
]);
|
|
229
|
+
function normalizedPath(path) {
|
|
230
|
+
try {
|
|
231
|
+
return realpathSync(path);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return resolve(path);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Whether a skill file lives under notesoup's own `skills/` roots (symlink-resolved). */
|
|
238
|
+
export function isNotesoupSkillPath(filePath, skillRoots = []) {
|
|
239
|
+
if (!filePath || skillRoots.length === 0)
|
|
240
|
+
return false;
|
|
241
|
+
const candidate = normalizedPath(filePath);
|
|
242
|
+
return skillRoots.some((root) => {
|
|
243
|
+
const base = normalizedPath(root);
|
|
244
|
+
return candidate === base || candidate.startsWith(base.endsWith(sep) ? base : `${base}${sep}`);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/** Drop notesoup's own `<skill>` blocks; undefined when no skill block survives. */
|
|
248
|
+
function stripNotesoupSkillBlocks(text, skillRoots) {
|
|
249
|
+
const stripped = text.replace(/^[ \t]*<skill>[\s\S]*?<\/skill>[ \t]*$\n?/gm, (block) => {
|
|
250
|
+
const location = /<location>([\s\S]*?)<\/location>/.exec(block)?.[1]?.trim();
|
|
251
|
+
return location !== undefined && isNotesoupSkillPath(location, skillRoots) ? "" : block;
|
|
252
|
+
});
|
|
253
|
+
if (!/<skill>/.test(stripped))
|
|
254
|
+
return undefined;
|
|
255
|
+
return stripped.replace(/\n{3,}/g, "\n\n");
|
|
256
|
+
}
|
|
257
|
+
function isEmptyContent(content) {
|
|
258
|
+
return content === "" || (Array.isArray(content) && content.length === 0);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Provider projection for `/notesoup off`: erase this extension's custom messages, teaching
|
|
262
|
+
* sections, skills and tool declarations so a disabled session looks like a plain Pi session.
|
|
263
|
+
* `CARRIED_INPUT_TYPE` survives because it is the human's withheld input, not notesoup state.
|
|
264
|
+
*/
|
|
265
|
+
export function stripNotesoupProjection(messages, skillRoots = []) {
|
|
266
|
+
const result = [];
|
|
267
|
+
let seenSystem = false;
|
|
268
|
+
let previousSkills;
|
|
269
|
+
for (const message of messages) {
|
|
270
|
+
if (message.role === "custom") {
|
|
271
|
+
if (NOTESOUP_MESSAGE_TYPES.has(message.customType))
|
|
272
|
+
continue;
|
|
273
|
+
result.push(message);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (message.role !== "system") {
|
|
277
|
+
result.push(message);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const cloned = { ...message };
|
|
281
|
+
if (message.toolsAdded) {
|
|
282
|
+
const kept = message.toolsAdded.filter((tool) => !NOTESOUP_TOOL_NAMES.has(tool.name));
|
|
283
|
+
if (kept.length === 0)
|
|
284
|
+
delete cloned.toolsAdded;
|
|
285
|
+
else
|
|
286
|
+
cloned.toolsAdded = kept;
|
|
287
|
+
}
|
|
288
|
+
if (message.toolsRemoved) {
|
|
289
|
+
const kept = message.toolsRemoved.filter((tool) => !NOTESOUP_TOOL_NAMES.has(tool.name));
|
|
290
|
+
if (kept.length === 0)
|
|
291
|
+
delete cloned.toolsRemoved;
|
|
292
|
+
else
|
|
293
|
+
cloned.toolsRemoved = kept;
|
|
294
|
+
}
|
|
295
|
+
let sections;
|
|
296
|
+
if (message.sections) {
|
|
297
|
+
sections = { ...message.sections };
|
|
298
|
+
delete sections.notesoup_tools;
|
|
299
|
+
delete sections.notesoup_protocol;
|
|
300
|
+
const skills = sections.skills;
|
|
301
|
+
if (typeof skills === "string") {
|
|
302
|
+
const cleaned = stripNotesoupSkillBlocks(skills, skillRoots);
|
|
303
|
+
if (cleaned === undefined) {
|
|
304
|
+
if (previousSkills !== undefined) {
|
|
305
|
+
sections.skills = null;
|
|
306
|
+
previousSkills = undefined;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
delete sections.skills;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else if (cleaned === previousSkills) {
|
|
313
|
+
delete sections.skills;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
sections.skills = cleaned;
|
|
317
|
+
previousSkills = cleaned;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else if (skills === null) {
|
|
321
|
+
if (previousSkills === undefined)
|
|
322
|
+
delete sections.skills;
|
|
323
|
+
else
|
|
324
|
+
previousSkills = undefined;
|
|
325
|
+
}
|
|
326
|
+
if (Object.keys(sections).length === 0)
|
|
327
|
+
delete cloned.sections;
|
|
328
|
+
else
|
|
329
|
+
cloned.sections = sections;
|
|
330
|
+
}
|
|
331
|
+
const hasTools = Boolean(cloned.toolsAdded?.length || cloned.toolsRemoved?.length);
|
|
332
|
+
if (seenSystem && isEmptyContent(cloned.content) && !hasTools && cloned.sections === undefined)
|
|
333
|
+
continue;
|
|
334
|
+
result.push(cloned);
|
|
335
|
+
seenSystem = true;
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
139
339
|
/** Usage for the selected window, excluding provider usage recorded before its marker. */
|
|
140
340
|
export function windowUsage(ctx) {
|
|
141
341
|
const reset = currentReset(ctx);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { NotesSnapshot } from "./snapshot.js";
|
|
2
2
|
import { type BootToolNames } from "./text.js";
|
|
3
|
+
/** The shelf index is bounded: enough to find a page, never the whole drawer. */
|
|
4
|
+
export declare const SHELF_INDEX_MAX_ENTRIES = 25;
|
|
5
|
+
export declare const SHELF_INDEX_MAX_CHARS = 4096;
|
|
6
|
+
/** A fallback title is the note's own first heading or line, cut short. */
|
|
7
|
+
export declare const FALLBACK_TITLE_MAX_CHARS = 80;
|
|
3
8
|
export type BootWindowTree = {
|
|
4
9
|
readonly trunk: string;
|
|
5
10
|
readonly windows: ReadonlyArray<{
|