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
package/plugins/pi/runtime.ts
CHANGED
|
@@ -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,18 +7,19 @@ import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, t
|
|
|
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, type WindowMarker } 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";
|
|
16
|
-
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
|
|
17
|
+
import { buildBootMessage, sendBoot, type BootMessage, type IncompleteNotesNotifier } from "./boot.js";
|
|
17
18
|
import { maybeSendMarker } from "./marker.js";
|
|
18
19
|
import { nextHistorySeq } from "./history.js";
|
|
19
20
|
import { errorMessage } from "../../src/error-message.js";
|
|
20
21
|
import { parseContextCap } from "../../src/budget/cap.js";
|
|
22
|
+
import type { SessionReader } from "./session-reader.js";
|
|
21
23
|
|
|
22
24
|
function readPackageVersion(): string {
|
|
23
25
|
for (const up of ["../../package.json", "../../../package.json"]) {
|
|
@@ -37,36 +39,26 @@ function branchHasWindowMarker(ctx: ExtensionContext, fromId?: string): boolean
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
+
* Resolve notesoup's own `skills/` directory in both layouts: direct TypeScript source
|
|
43
|
+
* (`plugins/pi/runtime.ts`) and the compiled package (`dist/plugins/pi/runtime.js`).
|
|
42
44
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const reset = currentReset(ctx);
|
|
51
|
-
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
52
|
-
const stillCurrent = () => isCurrent() &&
|
|
53
|
-
ctx.signal?.aborted !== true &&
|
|
54
|
-
ctx.sessionManager.getSessionId() === sessionId &&
|
|
55
|
-
currentWindowId(ctx) === windowId;
|
|
56
|
-
if (reset) {
|
|
57
|
-
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
58
|
-
return;
|
|
45
|
+
function resolveNotesoupSkillDirs(): string[] {
|
|
46
|
+
const dirs = new Set<string>();
|
|
47
|
+
for (const candidate of ["../../skills", "../../../skills"]) {
|
|
48
|
+
try {
|
|
49
|
+
const path = fileURLToPath(new URL(candidate, import.meta.url));
|
|
50
|
+
if (existsSync(path)) dirs.add(realpathSync(path));
|
|
51
|
+
} catch { /* not a source or compiled layout */ }
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
62
|
-
if (!stillCurrent()) return;
|
|
63
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
64
|
-
sendBoot(pi, boot);
|
|
53
|
+
return [...dirs];
|
|
65
54
|
}
|
|
66
55
|
|
|
56
|
+
const notesoupSkillDirs = resolveNotesoupSkillDirs();
|
|
57
|
+
|
|
67
58
|
/** Register the context-window runtime and its context-owned commands/tools. */
|
|
68
59
|
export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
|
|
69
|
-
|
|
60
|
+
pi.registerFlag("no-notesoup", { description: "Start with notesoup off (/notesoup on overrides)", type: "boolean", default: false });
|
|
61
|
+
const isEnabled = (ctx: SessionReader) => isNotesoupEnabled(pi, ctx);
|
|
70
62
|
let lifecycleGeneration = 0;
|
|
71
63
|
let missingBootNotice: string | undefined;
|
|
72
64
|
const incompleteNotesNotified = new Set<string>();
|
|
@@ -84,10 +76,46 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
84
76
|
if (markerResetOrigin(marker) === "forced") ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
85
77
|
}
|
|
86
78
|
};
|
|
87
|
-
|
|
79
|
+
/** Complete a reset tail that a previous process left half-written. */
|
|
80
|
+
const ensureResetRepair = async (ctx: ExtensionContext, isCurrent: () => boolean): Promise<void> => {
|
|
81
|
+
const reset = currentReset(ctx);
|
|
82
|
+
if (!reset) return;
|
|
83
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
84
|
+
const windowId = reset.data.windowId;
|
|
85
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
86
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
87
|
+
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
88
|
+
};
|
|
89
|
+
/** Root windows (or windows after a native compaction while off) boot lazily before the first provider-facing turn. */
|
|
90
|
+
const buildLazyBoot = async (ctx: ExtensionContext, isCurrent: () => boolean): Promise<BootMessage | undefined> => {
|
|
91
|
+
if (currentReset(ctx)) return undefined;
|
|
92
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
93
|
+
const windowId = currentWindowId(ctx);
|
|
94
|
+
const hasBoot = () =>
|
|
95
|
+
activeBranchTail(ctx.sessionManager.getBranch()).some((entry) => isWindowBootEntry(entry, windowId)) ||
|
|
96
|
+
ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId));
|
|
97
|
+
if (hasBoot()) return undefined;
|
|
98
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
99
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId && !currentReset(ctx);
|
|
100
|
+
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
101
|
+
if (!stillCurrent() || hasBoot()) return undefined;
|
|
102
|
+
return boot;
|
|
103
|
+
};
|
|
104
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
105
|
+
if (!isEnabled(ctx)) {
|
|
106
|
+
event.systemPromptOptions.skills = event.systemPromptOptions.skills.filter((skill) =>
|
|
107
|
+
!isNotesoupSkillPath(skill.filePath, notesoupSkillDirs));
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
88
110
|
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
89
111
|
event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
|
|
90
|
-
|
|
112
|
+
maybeSendMarker(pi, ctx);
|
|
113
|
+
if (!currentReset(ctx) && !(event.messageType === "custom" && event.message.customType === MANUAL_WIPE_TYPE)) {
|
|
114
|
+
const generation = lifecycleGeneration;
|
|
115
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
116
|
+
if (boot) return { message: boot };
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
91
119
|
});
|
|
92
120
|
pi.on("turn_start", (_event, ctx) => {
|
|
93
121
|
notifyCommittedResets(ctx);
|
|
@@ -102,20 +130,19 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
102
130
|
const namespaces = snapshot.unavailable.map((namespace) => namespace.label).join(", ");
|
|
103
131
|
ctx.ui.notify(`🥣 Some notes went missing: ${namespaces}`, "warning");
|
|
104
132
|
};
|
|
105
|
-
const budget = registerBudget(pi, () =>
|
|
133
|
+
const budget = registerBudget(pi, (ctx) => isEnabled(ctx), settingsManager);
|
|
106
134
|
|
|
107
135
|
pi.on("session_start", async (_event, ctx) => {
|
|
108
136
|
const generation = ++lifecycleGeneration;
|
|
109
|
-
if (!enabled) return;
|
|
110
137
|
missingBootNotice = undefined;
|
|
111
138
|
pendingResetNotices.clear();
|
|
112
|
-
await
|
|
139
|
+
if (isEnabled(ctx)) await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
113
140
|
});
|
|
114
141
|
pi.on("session_tree", async (_event, ctx) => {
|
|
115
142
|
const generation = ++lifecycleGeneration;
|
|
116
143
|
missingBootNotice = undefined;
|
|
117
144
|
pendingResetNotices.clear();
|
|
118
|
-
if (
|
|
145
|
+
if (isEnabled(ctx)) await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
119
146
|
});
|
|
120
147
|
pi.on("session_shutdown", () => {
|
|
121
148
|
lifecycleGeneration++;
|
|
@@ -135,12 +162,10 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
135
162
|
// root windows only refresh a forked boot identity and retain the copied root transcript.
|
|
136
163
|
pi.on("context_with_system", (event, ctx) => {
|
|
137
164
|
const reset = currentReset(ctx);
|
|
138
|
-
const windowId =
|
|
165
|
+
const windowId = currentWindowId(ctx);
|
|
139
166
|
try {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
return { messages: projectRootWindow(event.messages, windowId) };
|
|
167
|
+
const projected = reset ? projectWindow(event.messages, windowId) : projectRootWindow(event.messages, windowId);
|
|
168
|
+
return { messages: isEnabled(ctx) ? projected : stripNotesoupProjection(projected, notesoupSkillDirs) };
|
|
144
169
|
} catch (error) {
|
|
145
170
|
if (missingBootNotice !== windowId) {
|
|
146
171
|
missingBootNotice = windowId;
|
|
@@ -155,7 +180,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
155
180
|
pi.registerCommand("notesoup", {
|
|
156
181
|
description: "Show notesoup status, toggle context windows, or cap their capacity",
|
|
157
182
|
getArgumentCompletions: (prefix) =>
|
|
158
|
-
["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
183
|
+
["on", "off", "reset", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
159
184
|
handler: async (args, cmdCtx) => {
|
|
160
185
|
const arg = args.trim().toLowerCase();
|
|
161
186
|
const parts = arg.split(/\s+/);
|
|
@@ -169,38 +194,39 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
169
194
|
const error = budget.setCap(value ?? undefined, cmdCtx);
|
|
170
195
|
if (error) { cmdCtx.ui.notify(`🥣 ${error}`, "error"); return; }
|
|
171
196
|
}
|
|
172
|
-
} else if (arg === "on") {
|
|
173
|
-
enabled
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
} else if (arg === "on" || arg === "off" || arg === "reset") {
|
|
198
|
+
pi.appendEntry(ENABLED_TYPE, { version: 1, enabled: arg === "reset" ? null : arg === "on" });
|
|
199
|
+
if (isEnabled(cmdCtx)) {
|
|
200
|
+
const generation = ++lifecycleGeneration;
|
|
201
|
+
await ensureResetRepair(cmdCtx, () => generation === lifecycleGeneration && isEnabled(cmdCtx));
|
|
202
|
+
} else {
|
|
203
|
+
lifecycleGeneration++;
|
|
204
|
+
pendingResetNotices.clear();
|
|
205
|
+
incompleteNotesNotified.clear();
|
|
206
|
+
missingBootNotice = undefined;
|
|
207
|
+
budget.clear();
|
|
208
|
+
resets.clear();
|
|
209
|
+
}
|
|
184
210
|
} else if (arg !== "") {
|
|
185
|
-
cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
|
|
211
|
+
cmdCtx.ui.notify("Usage: /notesoup [on|off|reset|cap [100k|1m|tokens|off]]", "error");
|
|
186
212
|
return;
|
|
187
213
|
}
|
|
188
214
|
const { remaining, cap } = budget.statusFor(cmdCtx);
|
|
189
|
-
cmdCtx.ui.notify(`🥣 notesoup ${
|
|
215
|
+
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");
|
|
190
216
|
},
|
|
191
217
|
});
|
|
192
218
|
|
|
193
219
|
const emptyBrainCommand = (name: "empty" | "fresh-window") => ({
|
|
194
220
|
description: "Flush memory to notes, reset, and stop; optional text provides close-out context",
|
|
195
221
|
handler: async (args: string, cmdCtx: ExtensionCommandContext) => {
|
|
196
|
-
if (!
|
|
222
|
+
if (!isEnabled(cmdCtx)) {
|
|
197
223
|
cmdCtx.ui.notify("🥣 notesoup is off · no brain to empty", "error");
|
|
198
224
|
return;
|
|
199
225
|
}
|
|
200
226
|
const requestedWindowId = currentWindowId(cmdCtx);
|
|
201
227
|
if (!cmdCtx.isIdle() && !cmdCtx.signal) {
|
|
202
228
|
await cmdCtx.waitForIdle();
|
|
203
|
-
if (!
|
|
229
|
+
if (!isEnabled(cmdCtx) || currentWindowId(cmdCtx) !== requestedWindowId) return;
|
|
204
230
|
}
|
|
205
231
|
// Manual wipes close out at settlement, then stop unless later human input arrives. The hidden warning is triggered when idle,
|
|
206
232
|
// steered into the running turn when busy — so the agent closes out promptly
|
|
@@ -228,13 +254,13 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
228
254
|
label: "Empty Brain",
|
|
229
255
|
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.",
|
|
230
256
|
parameters: Type.Object({
|
|
231
|
-
last_word: Type.Optional(Type.String({ description: `A tiny sticky note
|
|
232
|
-
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe.
|
|
257
|
+
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.` })),
|
|
258
|
+
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe." })),
|
|
233
259
|
}, { additionalProperties: false }),
|
|
234
260
|
renderCall: emptyBrainRenderers.renderCall,
|
|
235
261
|
renderResult: emptyBrainRenderers.renderResult,
|
|
236
262
|
async execute(_id, params, _signal, _update, ctx) {
|
|
237
|
-
if (!
|
|
263
|
+
if (!isEnabled(ctx)) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
238
264
|
const lastWord = sanitizeLastWord(params.last_word);
|
|
239
265
|
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
240
266
|
if (length > MAX_LAST_WORD_CHARS) return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
|
|
@@ -243,7 +269,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
243
269
|
}));
|
|
244
270
|
|
|
245
271
|
const resets = registerResetLifecycle(pi, {
|
|
246
|
-
isEnabled: () =>
|
|
272
|
+
isEnabled: (ctx) => isEnabled(ctx),
|
|
247
273
|
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin),
|
|
248
274
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
249
275
|
onResetReady: (_ctx, drafts) => {
|
|
@@ -255,4 +281,14 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
255
281
|
},
|
|
256
282
|
budget,
|
|
257
283
|
});
|
|
284
|
+
|
|
285
|
+
// Registered after the reset lifecycle so a reset that swallows this input (`handled`)
|
|
286
|
+
// never gets a root boot for a turn that will not run.
|
|
287
|
+
pi.on("input", async (event, ctx) => {
|
|
288
|
+
if (!ctx.isIdle() || event.streamingBehavior || !isEnabled(ctx) || currentReset(ctx)) return undefined;
|
|
289
|
+
const generation = lifecycleGeneration;
|
|
290
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
291
|
+
if (boot) sendBoot(pi, boot);
|
|
292
|
+
return undefined;
|
|
293
|
+
});
|
|
258
294
|
}
|
|
@@ -4,7 +4,7 @@ import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
|
4
4
|
import type { JsonValue } from "@earendil-works/pi-ai";
|
|
5
5
|
import type { Static, TSchema } from "typebox";
|
|
6
6
|
import type { Outcome } from "../../src/result.js";
|
|
7
|
-
import { wireResult, type Operation
|
|
7
|
+
import { wireResult, type Operation } from "../../src/tools/result.js";
|
|
8
8
|
|
|
9
9
|
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
10
10
|
export function output(value: unknown, details?: unknown, terminate = false) {
|
|
@@ -14,19 +14,19 @@ export function output(value: unknown, details?: unknown, terminate = false) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
17
|
-
function piOperationResult<TData, TDetails = undefined>(
|
|
17
|
+
function piOperationResult<TData, TDetails = undefined>(operation: Pick<Operation<TSchema, TData, []>, "render" | "outputSchema">, outcome: Outcome<TData>, details?: TDetails): AgentToolResult<TDetails> {
|
|
18
18
|
return {
|
|
19
|
-
content: [{ type: "text", text: render(outcome) }],
|
|
20
|
-
structuredContent: wireResult(outcome) as unknown as JsonValue,
|
|
19
|
+
content: [{ type: "text", text: operation.render(outcome) }],
|
|
20
|
+
...(operation.outputSchema !== undefined ? { structuredContent: wireResult(outcome) as unknown as JsonValue } : {}),
|
|
21
21
|
isError: !outcome.ok,
|
|
22
22
|
details: details as TDetails,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export type ToolNamespace = { name: string; description: string };
|
|
27
|
-
export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the
|
|
27
|
+
export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the notesoup skill." };
|
|
28
28
|
export const DREAM_NAMESPACE: ToolNamespace = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
|
|
29
|
-
export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "Session history (this or other local sessions): history_list to browse
|
|
29
|
+
export const HISTORY_NAMESPACE: ToolNamespace = { 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." };
|
|
30
30
|
|
|
31
31
|
/** Optional TUI renderers; without them the host draws its default call line and receipt text. */
|
|
32
32
|
export type OperationRenderers<TParams extends TSchema, TDetails = undefined> = Pick<ToolDefinition<TParams, TDetails>, "renderCall" | "renderResult">;
|
|
@@ -45,14 +45,14 @@ export function registerOperation<TParams extends TSchema, TData, TRest extends
|
|
|
45
45
|
label: operation.label,
|
|
46
46
|
description: operation.description,
|
|
47
47
|
parameters: operation.parameters,
|
|
48
|
-
outputSchema: operation.outputSchema,
|
|
48
|
+
...(operation.outputSchema ? { outputSchema: operation.outputSchema } : {}),
|
|
49
49
|
executionMode: operation.executionMode,
|
|
50
50
|
...(namespace ? { namespace } : {}),
|
|
51
51
|
...(exposure ? { exposure } : {}),
|
|
52
52
|
...renderers,
|
|
53
53
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
54
54
|
const result = await run(params, ctx);
|
|
55
|
-
return piOperationResult(operation
|
|
55
|
+
return piOperationResult(operation, result, result.details);
|
|
56
56
|
},
|
|
57
57
|
}));
|
|
58
58
|
}
|
package/plugins/pi/window.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { SystemMessage, Tool, ToolReference } from "@earendil-works/pi-ai";
|
|
2
3
|
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
5
|
+
import { resolve, sep } from "node:path";
|
|
3
6
|
import { estimateContextTokens } from "./estimate.js";
|
|
4
7
|
import { convertToLlm, type CustomEntry, type ExtensionContext, type SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { BOOT_TYPE, RESET_MARKER_TYPE } from "./entries.js";
|
|
8
|
+
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";
|
|
6
9
|
import type { ResetOrigin } from "../../src/budget/text.js";
|
|
7
10
|
import { NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
|
|
8
11
|
import type { SessionReader } from "./session-reader.js";
|
|
@@ -25,16 +28,77 @@ export function markerResetOrigin(marker: WindowMarker): ResetOrigin {
|
|
|
25
28
|
return marker.data.origin === "forced" ? "forced" : "normal";
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
function lastWindowMarker(entries: readonly SessionEntry[]): WindowMarker | undefined {
|
|
32
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
33
|
+
const entry = entries[i];
|
|
34
|
+
if (entry && isWindowMarker(entry)) return entry;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Branch entries after the latest compaction, or the full branch before any compaction. */
|
|
40
|
+
export function activeBranchTail(branch: readonly SessionEntry[]): readonly SessionEntry[] {
|
|
41
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
42
|
+
if (branch[i]?.type === "compaction") return branch.slice(i + 1);
|
|
43
|
+
}
|
|
44
|
+
return branch;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Only a reset marker still ahead of any later native compaction owns the active projection boundary. */
|
|
29
48
|
export function currentReset(ctx: SessionReader): WindowMarker | undefined {
|
|
30
|
-
|
|
49
|
+
return lastWindowMarker(activeBranchTail(ctx.sessionManager.getBranch()));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The explicit `/notesoup on|off|reset` choice for this branch, or undefined when never chosen. */
|
|
53
|
+
export function sessionEnabled(branch: readonly SessionEntry[]): boolean | undefined {
|
|
31
54
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
32
|
-
const entry = branch[i]
|
|
33
|
-
if (entry
|
|
55
|
+
const entry = branch[i]!;
|
|
56
|
+
if (entry.type !== "custom" || entry.customType !== ENABLED_TYPE) continue;
|
|
57
|
+
const data = entry.data;
|
|
58
|
+
if (typeof data !== "object" || data === null) continue;
|
|
59
|
+
const enabled = (data as { enabled?: unknown }).enabled;
|
|
60
|
+
if (enabled === true) return true;
|
|
61
|
+
if (enabled === false) return false;
|
|
62
|
+
if (enabled === null) return undefined;
|
|
63
|
+
// Malformed data: keep scanning for an older readable choice.
|
|
34
64
|
}
|
|
35
65
|
return undefined;
|
|
36
66
|
}
|
|
37
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Whether pi-souls reports a naked run. Ask the loaded pi-souls extension synchronously first;
|
|
70
|
+
* when it is absent, read the same durable entry it would have consulted.
|
|
71
|
+
*/
|
|
72
|
+
export function isNakedSession(
|
|
73
|
+
pi: { events?: { emit(channel: string, data: unknown): void } },
|
|
74
|
+
branch: readonly SessionEntry[],
|
|
75
|
+
): boolean {
|
|
76
|
+
const query: { branch: readonly SessionEntry[]; naked?: boolean } = { branch };
|
|
77
|
+
pi.events?.emit("pi-souls:state", query);
|
|
78
|
+
if (typeof query.naked === "boolean") return query.naked;
|
|
79
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
80
|
+
const entry = branch[i]!;
|
|
81
|
+
if (entry.type !== "custom" || entry.customType !== "pi-souls:naked") continue;
|
|
82
|
+
const data = entry.data;
|
|
83
|
+
if (typeof data !== "object" || data === null) continue;
|
|
84
|
+
const naked = (data as { naked?: unknown }).naked;
|
|
85
|
+
if (naked === true) return true;
|
|
86
|
+
if (naked === false || naked === null) return false;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Explicit branch choice wins; otherwise the CLI flag and a naked pi-souls run both disable. */
|
|
92
|
+
export function isNotesoupEnabled(
|
|
93
|
+
pi: { getFlag?(name: string): unknown; events?: { emit(channel: string, data: unknown): void } },
|
|
94
|
+
ctx: SessionReader,
|
|
95
|
+
): boolean {
|
|
96
|
+
const branch = ctx.sessionManager.getBranch();
|
|
97
|
+
const explicit = sessionEnabled(branch);
|
|
98
|
+
if (explicit !== undefined) return explicit;
|
|
99
|
+
return pi.getFlag?.("no-notesoup") !== true && !isNakedSession(pi, branch);
|
|
100
|
+
}
|
|
101
|
+
|
|
38
102
|
/** A reset is checkpoint-backed only when its marker directly follows a native compaction. */
|
|
39
103
|
export function isCheckpointBackedReset(ctx: SessionReader, marker = currentReset(ctx)): boolean {
|
|
40
104
|
if (!marker?.parentId) return false;
|
|
@@ -50,20 +114,21 @@ export function rootWindowId(sessionId: string): string {
|
|
|
50
114
|
return `pcw:${sessionId.slice(0, 8)}:root`;
|
|
51
115
|
}
|
|
52
116
|
|
|
53
|
-
/** Persisted messages in the active window, excluding earlier windows
|
|
117
|
+
/** Persisted messages in the active window segment, excluding earlier windows and compacted prefixes. */
|
|
54
118
|
export function hasWindowMessage(ctx: SessionReader, customType: string): boolean {
|
|
55
119
|
const branch = ctx.sessionManager.getBranch();
|
|
56
120
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
57
121
|
const entry = branch[i];
|
|
58
|
-
if (
|
|
122
|
+
if (!entry) continue;
|
|
123
|
+
if (isWindowMarker(entry) || entry.type === "compaction") break;
|
|
59
124
|
if (entry.type === "custom_message" && entry.customType === customType) return true;
|
|
60
125
|
}
|
|
61
126
|
return false;
|
|
62
127
|
}
|
|
63
128
|
|
|
64
|
-
/** The root or latest durable
|
|
129
|
+
/** The root or latest durable window identity on the active branch, matching history windows. */
|
|
65
130
|
export function currentWindowId(ctx: SessionReader): string {
|
|
66
|
-
return
|
|
131
|
+
return lastWindowMarker(ctx.sessionManager.getBranch())?.data.windowId ?? rootWindowId(ctx.sessionManager.getSessionId());
|
|
67
132
|
}
|
|
68
133
|
|
|
69
134
|
/** The durable window active just before the marker: the last earlier marker, else the root window. */
|
|
@@ -145,6 +210,130 @@ export function projectRootWindow(messages: AgentMessage[], windowId: string): A
|
|
|
145
210
|
return [...withoutBoots.slice(0, firstBoot), activeBoot, ...withoutBoots.slice(firstBoot)];
|
|
146
211
|
}
|
|
147
212
|
|
|
213
|
+
/** Every tool the notesoup extension registers. */
|
|
214
|
+
export const NOTESOUP_TOOL_NAMES: ReadonlySet<string> = new Set([
|
|
215
|
+
"empty_brain",
|
|
216
|
+
"get_context_remaining",
|
|
217
|
+
"notes_write",
|
|
218
|
+
"notes_update",
|
|
219
|
+
"notes_read",
|
|
220
|
+
"notes_list",
|
|
221
|
+
"dream_begin",
|
|
222
|
+
"dream_forget",
|
|
223
|
+
"dream_end",
|
|
224
|
+
"history_list",
|
|
225
|
+
"history_search",
|
|
226
|
+
"history_read",
|
|
227
|
+
]);
|
|
228
|
+
|
|
229
|
+
const NOTESOUP_MESSAGE_TYPES: ReadonlySet<string> = new Set([
|
|
230
|
+
BOOT_TYPE,
|
|
231
|
+
GUIDANCE_TYPE,
|
|
232
|
+
WARNING_TYPE,
|
|
233
|
+
MANUAL_WIPE_TYPE,
|
|
234
|
+
CONTINUATION_TYPE,
|
|
235
|
+
RESET_LAST_WORD_TYPE,
|
|
236
|
+
MARKER_TYPE,
|
|
237
|
+
]);
|
|
238
|
+
|
|
239
|
+
function normalizedPath(path: string): string {
|
|
240
|
+
try { return realpathSync(path); }
|
|
241
|
+
catch { return resolve(path); }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Whether a skill file lives under notesoup's own `skills/` roots (symlink-resolved). */
|
|
245
|
+
export function isNotesoupSkillPath(filePath: string, skillRoots: readonly string[] = []): boolean {
|
|
246
|
+
if (!filePath || skillRoots.length === 0) return false;
|
|
247
|
+
const candidate = normalizedPath(filePath);
|
|
248
|
+
return skillRoots.some((root) => {
|
|
249
|
+
const base = normalizedPath(root);
|
|
250
|
+
return candidate === base || candidate.startsWith(base.endsWith(sep) ? base : `${base}${sep}`);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Drop notesoup's own `<skill>` blocks; undefined when no skill block survives. */
|
|
255
|
+
function stripNotesoupSkillBlocks(text: string, skillRoots: readonly string[]): string | undefined {
|
|
256
|
+
const stripped = text.replace(/^[ \t]*<skill>[\s\S]*?<\/skill>[ \t]*$\n?/gm, (block) => {
|
|
257
|
+
const location = /<location>([\s\S]*?)<\/location>/.exec(block)?.[1]?.trim();
|
|
258
|
+
return location !== undefined && isNotesoupSkillPath(location, skillRoots) ? "" : block;
|
|
259
|
+
});
|
|
260
|
+
if (!/<skill>/.test(stripped)) return undefined;
|
|
261
|
+
return stripped.replace(/\n{3,}/g, "\n\n");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function isEmptyContent(content: string | readonly unknown[]): boolean {
|
|
265
|
+
return content === "" || (Array.isArray(content) && content.length === 0);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Provider projection for `/notesoup off`: erase this extension's custom messages, teaching
|
|
270
|
+
* sections, skills and tool declarations so a disabled session looks like a plain Pi session.
|
|
271
|
+
* `CARRIED_INPUT_TYPE` survives because it is the human's withheld input, not notesoup state.
|
|
272
|
+
*/
|
|
273
|
+
export function stripNotesoupProjection(messages: AgentMessage[], skillRoots: readonly string[] = []): AgentMessage[] {
|
|
274
|
+
const result: AgentMessage[] = [];
|
|
275
|
+
let seenSystem = false;
|
|
276
|
+
let previousSkills: string | undefined;
|
|
277
|
+
for (const message of messages) {
|
|
278
|
+
if (message.role === "custom") {
|
|
279
|
+
if (NOTESOUP_MESSAGE_TYPES.has(message.customType)) continue;
|
|
280
|
+
result.push(message);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (message.role !== "system") {
|
|
284
|
+
result.push(message);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const cloned: SystemMessage = { ...message };
|
|
289
|
+
if (message.toolsAdded) {
|
|
290
|
+
const kept: Tool[] = message.toolsAdded.filter((tool) => !NOTESOUP_TOOL_NAMES.has(tool.name));
|
|
291
|
+
if (kept.length === 0) delete cloned.toolsAdded;
|
|
292
|
+
else cloned.toolsAdded = kept;
|
|
293
|
+
}
|
|
294
|
+
if (message.toolsRemoved) {
|
|
295
|
+
const kept: ToolReference[] = message.toolsRemoved.filter((tool) => !NOTESOUP_TOOL_NAMES.has(tool.name));
|
|
296
|
+
if (kept.length === 0) delete cloned.toolsRemoved;
|
|
297
|
+
else cloned.toolsRemoved = kept;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
let sections: Record<string, string | null> | undefined;
|
|
301
|
+
if (message.sections) {
|
|
302
|
+
sections = { ...message.sections };
|
|
303
|
+
delete sections.notesoup_tools;
|
|
304
|
+
delete sections.notesoup_protocol;
|
|
305
|
+
const skills = sections.skills;
|
|
306
|
+
if (typeof skills === "string") {
|
|
307
|
+
const cleaned = stripNotesoupSkillBlocks(skills, skillRoots);
|
|
308
|
+
if (cleaned === undefined) {
|
|
309
|
+
if (previousSkills !== undefined) {
|
|
310
|
+
sections.skills = null;
|
|
311
|
+
previousSkills = undefined;
|
|
312
|
+
} else {
|
|
313
|
+
delete sections.skills;
|
|
314
|
+
}
|
|
315
|
+
} else if (cleaned === previousSkills) {
|
|
316
|
+
delete sections.skills;
|
|
317
|
+
} else {
|
|
318
|
+
sections.skills = cleaned;
|
|
319
|
+
previousSkills = cleaned;
|
|
320
|
+
}
|
|
321
|
+
} else if (skills === null) {
|
|
322
|
+
if (previousSkills === undefined) delete sections.skills;
|
|
323
|
+
else previousSkills = undefined;
|
|
324
|
+
}
|
|
325
|
+
if (Object.keys(sections).length === 0) delete cloned.sections;
|
|
326
|
+
else cloned.sections = sections;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const hasTools = Boolean(cloned.toolsAdded?.length || cloned.toolsRemoved?.length);
|
|
330
|
+
if (seenSystem && isEmptyContent(cloned.content) && !hasTools && cloned.sections === undefined) continue;
|
|
331
|
+
result.push(cloned);
|
|
332
|
+
seenSystem = true;
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
|
|
148
337
|
/** Usage for the selected window, excluding provider usage recorded before its marker. */
|
|
149
338
|
export function windowUsage(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">) {
|
|
150
339
|
const reset = currentReset(ctx);
|
package/skills/dream/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dream
|
|
3
|
-
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates,
|
|
3
|
+
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates, audit descriptions, or promote durable findings.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Dream
|
|
7
7
|
|
|
8
|
-
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md
|
|
8
|
+
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate compact `CHEATSHEET.md`, the one default-pinned page; it loads every window when live unless explicitly unpinned. Every durable note carries a short one-line `description` saying what it holds and when to open it — boot renders each notebook's index from these, so a missing or stale description is an index defect. Pages carry UTF-8 byte budgets (4 KB for `CHEATSHEET.md`, 8 KB for ordinary notes, overridable in frontmatter); overflow warns, and boot truncates over-budget pinned bodies. Respect soft readonly locks; explicitly unlock with `readonly:false` before changing a locked note.
|
|
9
9
|
|
|
10
10
|
Dream in this agent's current session. Do not start another agent or model unless the human asks.
|
|
11
11
|
|