notesoup 0.0.0-stage → 0.40.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 +94 -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 +17 -0
- package/dist/src/boot/text.js +48 -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 +156 -0
- package/dist/src/history/history.js +212 -0
- package/dist/src/history/query.d.ts +63 -0
- package/dist/src/history/query.js +201 -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 +103 -0
- package/dist/src/notes/store.js +474 -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 +9 -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 +7 -0
- package/dist/src/pi/tool-names.js +7 -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 +58 -0
- package/dist/src/tools/history.js +210 -0
- package/dist/src/tools/notes.d.ts +250 -0
- package/dist/src/tools/notes.js +360 -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 +82 -0
- package/dist/src/tools/result.js +104 -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 +367 -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 +633 -0
- package/dist/test/host-neutral.test.d.ts +1 -0
- package/dist/test/host-neutral.test.js +274 -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 +515 -0
- package/dist/test/notes.test.d.ts +1 -0
- package/dist/test/notes.test.js +530 -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 +78 -0
- package/mods/notesoup/.claude-plugin/plugin.json +8 -0
- package/mods/notesoup/dist/claude/helper.js +9265 -0
- package/mods/notesoup/hooks/hooks.json +4 -0
- package/mods/notesoup/hooks/register.ts +240 -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 +58 -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 +286 -0
- package/src/history/query.ts +222 -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 +494 -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 +11 -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 +9 -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 +234 -0
- package/src/tools/notes.ts +381 -0
- package/src/tools/output.ts +41 -0
- package/src/tools/result.ts +144 -0
- package/src/tools/schema.ts +31 -0
package/src/pi/budget.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { PI_TOOL_NAMES } from "./tool-names.js";
|
|
2
|
+
import { remainingBudget, type ResolvedThresholds } from "../budget/policy.js";
|
|
3
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
4
|
+
import { defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
|
|
6
|
+
import { WARNING_CONTENT } from "./reset/text.js";
|
|
7
|
+
import { readThresholdSettings, type ThresholdSettingsResolution } from "./thresholds.js";
|
|
8
|
+
import { currentWindowId, hasWindowMessage, isWindowMarker, rootWindowId, windowUsage } from "./window.js";
|
|
9
|
+
import { tokenBudgetGuidance } from "../budget/text.js";
|
|
10
|
+
import { output } from "../tools/output.js";
|
|
11
|
+
|
|
12
|
+
/** Remaining tokens in the provider's active window, or null without a usable estimate. */
|
|
13
|
+
export function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">): number | null {
|
|
14
|
+
const usage = windowUsage(ctx);
|
|
15
|
+
return !usage || usage.tokens === null ? null : Math.max(0, usage.contextWindow - usage.tokens);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function registerBudget(
|
|
19
|
+
pi: ExtensionAPI,
|
|
20
|
+
isEnabled: () => boolean,
|
|
21
|
+
settingsManager?: SettingsManager,
|
|
22
|
+
onCloseOut: (windowId: string) => void = () => {},
|
|
23
|
+
) {
|
|
24
|
+
let cachedPolicy: { thresholds: ResolvedThresholds; automatic: boolean } | undefined;
|
|
25
|
+
const notifiedWarnings = new Set<string>();
|
|
26
|
+
const resolvePolicy = (ctx: ExtensionContext): ThresholdSettingsResolution => {
|
|
27
|
+
if (!settingsManager && cachedPolicy) return { ...cachedPolicy, warnings: [] };
|
|
28
|
+
const resolution = readThresholdSettings(ctx, settingsManager);
|
|
29
|
+
for (const warning of resolution.warnings) {
|
|
30
|
+
if (notifiedWarnings.has(warning)) continue;
|
|
31
|
+
notifiedWarnings.add(warning);
|
|
32
|
+
ctx.ui.notify(warning, "warning");
|
|
33
|
+
}
|
|
34
|
+
if (!settingsManager) cachedPolicy = { thresholds: resolution.thresholds, automatic: resolution.automatic };
|
|
35
|
+
return resolution;
|
|
36
|
+
};
|
|
37
|
+
const thresholdsFor = (ctx: ExtensionContext): ResolvedThresholds => {
|
|
38
|
+
return resolvePolicy(ctx).thresholds;
|
|
39
|
+
};
|
|
40
|
+
const automaticResetEnabled = (ctx: ExtensionContext): boolean => {
|
|
41
|
+
return resolvePolicy(ctx).automatic;
|
|
42
|
+
};
|
|
43
|
+
const hardReserveDue = (ctx: ExtensionContext): boolean => {
|
|
44
|
+
if (!automaticResetEnabled(ctx)) return false;
|
|
45
|
+
const usage = windowUsage(ctx);
|
|
46
|
+
return usage !== undefined && usage.tokens !== null && usage.contextWindow - usage.tokens <= thresholdsFor(ctx).reserve;
|
|
47
|
+
};
|
|
48
|
+
const invalidateThresholds = () => { cachedPolicy = undefined; };
|
|
49
|
+
let pendingGuidance: { windowId: string; content: string } | undefined;
|
|
50
|
+
let pendingWarning: { windowId: string; content: string } | undefined;
|
|
51
|
+
let pendingNotices = new Map<string, { sessionId: string; windowId: string }>();
|
|
52
|
+
const noticeKey = (sessionId: string, windowId: string) => `${sessionId}:${windowId}`;
|
|
53
|
+
const warningCommittedInWindow = (ctx: ExtensionContext, notice: { sessionId: string; windowId: string }): boolean => {
|
|
54
|
+
if (ctx.sessionManager.getSessionId() !== notice.sessionId) return false;
|
|
55
|
+
let windowId = rootWindowId(notice.sessionId);
|
|
56
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
57
|
+
if (isWindowMarker(entry)) {
|
|
58
|
+
windowId = entry.data.windowId;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (windowId === notice.windowId && entry.type === "custom_message" && entry.customType === WARNING_TYPE) return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
const notifyCommittedWarnings = (ctx: ExtensionContext, settled = false) => {
|
|
66
|
+
for (const [key, notice] of pendingNotices) {
|
|
67
|
+
if (warningCommittedInWindow(ctx, notice)) {
|
|
68
|
+
pendingNotices.delete(key);
|
|
69
|
+
ctx.ui.notify("notesoup: context almost full; close out the current memory window.", "warning");
|
|
70
|
+
} else if (settled) {
|
|
71
|
+
// An uncommitted draft must not be matched to a later manual warning.
|
|
72
|
+
pendingNotices.delete(key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const clearStaged = () => {
|
|
78
|
+
pendingGuidance = undefined;
|
|
79
|
+
pendingWarning = undefined;
|
|
80
|
+
};
|
|
81
|
+
const resetForTransition = () => {
|
|
82
|
+
clearStaged();
|
|
83
|
+
pendingNotices.clear();
|
|
84
|
+
invalidateThresholds();
|
|
85
|
+
notifiedWarnings.clear();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const consumeTurnEnd = (ctx: ExtensionContext): SessionBoundaryDraft[] => {
|
|
89
|
+
const staged = [
|
|
90
|
+
pendingGuidance ? { ...pendingGuidance, customType: GUIDANCE_TYPE } : undefined,
|
|
91
|
+
pendingWarning ? { ...pendingWarning, customType: WARNING_TYPE } : undefined,
|
|
92
|
+
];
|
|
93
|
+
clearStaged();
|
|
94
|
+
const windowId = currentWindowId(ctx);
|
|
95
|
+
const drafts = staged.filter((draft): draft is NonNullable<typeof draft> => draft !== undefined && draft.windowId === windowId);
|
|
96
|
+
if (drafts.some((draft) => draft.customType === WARNING_TYPE)) {
|
|
97
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
98
|
+
pendingNotices.set(noticeKey(sessionId, windowId), { sessionId, windowId });
|
|
99
|
+
}
|
|
100
|
+
return drafts.map((draft) => ({
|
|
101
|
+
type: "custom_message" as const,
|
|
102
|
+
customType: draft.customType,
|
|
103
|
+
content: draft.content,
|
|
104
|
+
display: false,
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
pi.on("session_start", (_event, ctx) => { resetForTransition(); thresholdsFor(ctx); });
|
|
109
|
+
pi.on("session_tree", resetForTransition);
|
|
110
|
+
pi.on("model_select", resetForTransition);
|
|
111
|
+
pi.on("session_shutdown", resetForTransition);
|
|
112
|
+
// A warning can be committed at turn_end, before a tool turn or a reset changes the
|
|
113
|
+
// active window. Observe the active branch at public lifecycle boundaries and match
|
|
114
|
+
// the candidate against its originating window segment, not only the current window.
|
|
115
|
+
pi.on("turn_start", (_event, ctx) => notifyCommittedWarnings(ctx));
|
|
116
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
117
|
+
notifyCommittedWarnings(ctx, true);
|
|
118
|
+
clearStaged();
|
|
119
|
+
});
|
|
120
|
+
pi.on("context", (_event, ctx) => {
|
|
121
|
+
if (!isEnabled()) return undefined;
|
|
122
|
+
// The early reminder persists once per window the first time remaining crosses
|
|
123
|
+
// reserve+margin. It never edits the outgoing request.
|
|
124
|
+
const remaining = remainingTokens(ctx);
|
|
125
|
+
if (remaining === null) return undefined;
|
|
126
|
+
const windowId = currentWindowId(ctx);
|
|
127
|
+
const { reminder, warning } = thresholdsFor(ctx);
|
|
128
|
+
if (remaining <= warning && automaticResetEnabled(ctx)) {
|
|
129
|
+
// Re-arm close-out on each eligible request. A prior request may have aborted
|
|
130
|
+
// after persisting the warning, so warning deduplication must not own this state.
|
|
131
|
+
onCloseOut(windowId);
|
|
132
|
+
if (hasWindowMessage(ctx, WARNING_TYPE) || pendingWarning?.windowId === windowId) return undefined;
|
|
133
|
+
// The critical close-out starts at reserve + runway, not at the hard reserve.
|
|
134
|
+
pendingGuidance = undefined;
|
|
135
|
+
const content = WARNING_CONTENT;
|
|
136
|
+
pendingWarning = { windowId, content };
|
|
137
|
+
const warningMessage = {
|
|
138
|
+
role: "custom" as const,
|
|
139
|
+
customType: WARNING_TYPE,
|
|
140
|
+
content,
|
|
141
|
+
display: false,
|
|
142
|
+
timestamp: Date.now(),
|
|
143
|
+
};
|
|
144
|
+
return { messages: [..._event.messages, warningMessage] };
|
|
145
|
+
}
|
|
146
|
+
if (hasWindowMessage(ctx, WARNING_TYPE) || pendingWarning?.windowId === windowId) return undefined;
|
|
147
|
+
if (hasWindowMessage(ctx, GUIDANCE_TYPE) || pendingGuidance?.windowId === windowId) return undefined;
|
|
148
|
+
if (remaining <= reminder) {
|
|
149
|
+
// Persist at turn_end, before any reset drafts. A queued sendMessage could
|
|
150
|
+
// otherwise cross the marker and leak the old window's reminder forward.
|
|
151
|
+
const left = Math.max(0, remaining - warning);
|
|
152
|
+
pendingGuidance = { windowId, content: tokenBudgetGuidance(left, PI_TOOL_NAMES.wipe) };
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
pi.registerTool(defineTool({
|
|
158
|
+
name: "get_context_remaining",
|
|
159
|
+
label: "Get context remaining",
|
|
160
|
+
description: "Return estimated context tokens left before your memory is wiped; null when Pi cannot estimate usage.",
|
|
161
|
+
parameters: Type.Object({}, { additionalProperties: false }),
|
|
162
|
+
async execute(_id, _params, _signal, _update, ctx) {
|
|
163
|
+
// The countdown the model sees ends at the warning line (reserve + runway);
|
|
164
|
+
// the runway below it is overdraft the model never sees. See budget/constants.ts.
|
|
165
|
+
const remaining = remainingTokens(ctx);
|
|
166
|
+
return output({ remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx as ExtensionContext).warning) });
|
|
167
|
+
},
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
automaticResetEnabled,
|
|
172
|
+
hardReserveDue,
|
|
173
|
+
consumeTurnEnd,
|
|
174
|
+
/** The same close-out countdown the model sees, for user-facing status; null when usage is unknown. */
|
|
175
|
+
statusFor: (ctx: ExtensionContext): { remaining: number | null } => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).warning) }),
|
|
176
|
+
clear: () => { clearStaged(); pendingNotices.clear(); },
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { finishDream } from "../../dream/report.js";
|
|
3
|
+
import type { DreamerSetting } from "../../dream/settings.js";
|
|
4
|
+
import { loadPlaybook } from "../../dream/playbook.js";
|
|
5
|
+
import type { DreamResult } from "../../dream/result.js";
|
|
6
|
+
import { existsSync, mkdirSync, realpathSync, statSync } from "node:fs";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { acquireLock, failLock, lastRunPath, releaseLock } from "../../dream/lock.js";
|
|
10
|
+
import { materialGate, timeGate } from "../../dream/gates.js";
|
|
11
|
+
import { runDreamer, type DreamerSessionFactory } from "./runner.js";
|
|
12
|
+
import { gitCommit } from "../../dream/git.js";
|
|
13
|
+
import { readDreamerSettings } from "./settings.js";
|
|
14
|
+
import { doctor } from "../../dream/doctor.js";
|
|
15
|
+
import { notesRoot } from "../notes/adapter.js";
|
|
16
|
+
|
|
17
|
+
function args(argv: string[]) { const out: Record<string, string | boolean> = {}; for (let i=0;i<argv.length;i++) { const a=argv[i]!; if (a === "--force" || a === "--help") out[a.slice(2)] = true; else if (a.startsWith("--")) out[a.slice(2)] = argv[++i] ?? ""; } return out; }
|
|
18
|
+
function packageRoot(): string {
|
|
19
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
while (true) { if (existsSync(join(dir, "package.json"))) return dir; const parent = dirname(dir); if (parent === dir) throw new Error("could not locate installed package root"); dir = parent; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Injection seams used by tests; production uses the defaults. */
|
|
24
|
+
export type DreamDependencies = {
|
|
25
|
+
sessionFactory?: DreamerSessionFactory;
|
|
26
|
+
dreamerSettings?: (cwd?: string) => DreamerSetting;
|
|
27
|
+
runDreamer?: typeof runDreamer;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export async function main(argv = process.argv.slice(2), deps: DreamDependencies = {}): Promise<number> {
|
|
31
|
+
if (argv[0] === "doctor") {
|
|
32
|
+
const options = args(argv.slice(1));
|
|
33
|
+
if (options.help) { console.log("dream doctor [--notes-home <dir>] — read-only diagnostics; no model or repairs"); return 0; }
|
|
34
|
+
const home = resolve(String(options["notes-home"] ?? notesRoot()));
|
|
35
|
+
const issues = doctor(home);
|
|
36
|
+
console.log(issues.length ? issues.join("\n") : `dream doctor: OK (${home})`);
|
|
37
|
+
return issues.length ? 1 : 0;
|
|
38
|
+
}
|
|
39
|
+
const a = args(argv); if (a.help) { console.log("dream doctor [--notes-home <dir>] — read-only diagnostics\ndream --notes-home <dir> [--min-hours 24] [--min-sessions 3] [--force] [--dreamer <model pattern>] [--playbook <path>]\nDreamer model: --dreamer wins, else notesoup.dreamer from settings, else the automatic model. Default playbook: <installed package root>/playbook.md; --playbook overrides it."); return 0; }
|
|
40
|
+
const home = resolve(String(a["notes-home"] ?? notesRoot())); process.env.PI_NOTES_HOME = home; mkdirSync(home, { recursive: true });
|
|
41
|
+
const lockPath = join(home, ".dream.lock"); const stampPath = lastRunPath(lockPath);
|
|
42
|
+
const minHours = Number(a["min-hours"] ?? 24); const minSessions = Number(a["min-sessions"] ?? 3);
|
|
43
|
+
const time = timeGate(stampPath, minHours); console.log(time.reason); if (!a.force && !time.ok) return 0;
|
|
44
|
+
const since = existsSync(stampPath) ? statSync(stampPath).mtimeMs : 0;
|
|
45
|
+
const material = materialGate(home, since, minSessions); console.log(material.reason); if (!a.force && !material.ok) return 0;
|
|
46
|
+
let lock; try { lock = acquireLock(lockPath); } catch (e) { console.log(`lock gate: ${e instanceof Error ? e.message : e}`); return 0; } if (!lock.held) { console.log(lock.reason); return 0; }
|
|
47
|
+
const stamp = new Date(lock.startedAt).toISOString().replace(/[:.]/g, "-"); const reportPath = join(home, "dreams", `${stamp}.md`);
|
|
48
|
+
let succeeded = false;
|
|
49
|
+
try {
|
|
50
|
+
// CLI --dreamer wins over settings; settings win over the automatic model fallback.
|
|
51
|
+
let modelPattern: string | undefined;
|
|
52
|
+
if (a.dreamer) modelPattern = String(a.dreamer);
|
|
53
|
+
else {
|
|
54
|
+
const settings = (deps.dreamerSettings ?? readDreamerSettings)();
|
|
55
|
+
for (const warning of settings.warnings) console.error(warning);
|
|
56
|
+
modelPattern = settings.pattern;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The baseline snapshot is required: without it the human gate has nothing to inspect.
|
|
60
|
+
const baseline = gitCommit(home, `baseline ${stamp}`);
|
|
61
|
+
if (!baseline.ok) { console.error(`dream: baseline audit failed: ${baseline.error}`); return 1; }
|
|
62
|
+
|
|
63
|
+
const defaultBook = join(packageRoot(), "playbook.md");
|
|
64
|
+
const playbookPath = String(a.playbook ?? defaultBook);
|
|
65
|
+
let result: DreamResult;
|
|
66
|
+
try {
|
|
67
|
+
const playbook = loadPlaybook(playbookPath);
|
|
68
|
+
result = await (deps.runDreamer ?? runDreamer)(playbook, home, { modelPattern, sessionFactory: deps.sessionFactory });
|
|
69
|
+
} catch (e) {
|
|
70
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
71
|
+
console.error(message);
|
|
72
|
+
return finishDream(home, stamp, reportPath, true, message, []);
|
|
73
|
+
}
|
|
74
|
+
if (result.error) {
|
|
75
|
+
console.error(result.error);
|
|
76
|
+
return finishDream(home, stamp, reportPath, true, result.error, result.writes);
|
|
77
|
+
}
|
|
78
|
+
const code = finishDream(home, stamp, reportPath, false, result.report, result.writes);
|
|
79
|
+
if (code === 0) { succeeded = true; console.log(reportPath); }
|
|
80
|
+
return code;
|
|
81
|
+
} finally {
|
|
82
|
+
// Only the holder's own lock is released; a successor's lock is never touched.
|
|
83
|
+
if (succeeded) releaseLock(lock); else failLock(lock);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isEntryPoint(): boolean {
|
|
88
|
+
const entry = process.argv[1];
|
|
89
|
+
if (!entry) return false;
|
|
90
|
+
try { return realpathSync(resolve(entry)) === realpathSync(fileURLToPath(import.meta.url)); } catch { return false; }
|
|
91
|
+
}
|
|
92
|
+
if (isEntryPoint()) main().then((code) => { process.exitCode = code; });
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jailWritePath, deleteCrumpledNote } from "../../dream/jail.js";
|
|
2
|
+
import type { DreamResult, DreamWrite } from "../../dream/result.js";
|
|
3
|
+
import { createAgentSession, createEditToolDefinition, createWriteToolDefinition, ModelRuntime, resolveModelScopeWithDiagnostics, SessionManager, type AgentSession, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Type, type Api, type Model } from "@earendil-works/pi-ai";
|
|
5
|
+
import { contentText } from "../../history/history.js";
|
|
6
|
+
|
|
7
|
+
export type DreamerSession = Pick<AgentSession, "prompt" | "subscribe" | "dispose">;
|
|
8
|
+
export type DreamerSessionFactory = (options: { cwd: string; modelPattern?: string; tools: string[] }) => Promise<DreamerSession>;
|
|
9
|
+
export const DREAMER_TOOLS = ["read", "grep", "find", "ls", "write", "edit"];
|
|
10
|
+
|
|
11
|
+
function jailToolDefinition<T extends ToolDefinition<any, any, any>>(definition: T, notesHome: string): T {
|
|
12
|
+
const execute = definition.execute;
|
|
13
|
+
return {
|
|
14
|
+
...definition,
|
|
15
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
16
|
+
await jailWritePath(notesHome, (params as { path: string }).path);
|
|
17
|
+
return execute(toolCallId, params, signal, onUpdate, ctx);
|
|
18
|
+
},
|
|
19
|
+
} as T;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The dream session's custom definitions: jailed versions of the two write built-ins, plus the jailed delete below. */
|
|
23
|
+
export function dreamerWriteToolDefinitions(notesHome: string): ToolDefinition<any, any, any>[] {
|
|
24
|
+
return [
|
|
25
|
+
jailToolDefinition(createWriteToolDefinition(notesHome), notesHome),
|
|
26
|
+
jailToolDefinition(createEditToolDefinition(notesHome), notesHome),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DELETE_PARAMETERS = Type.Object({ path: Type.String({ description: "Path of the crumpled note file, relative to the notes home." }) }, { additionalProperties: false });
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The dreamer's physical delete, jailed like the writes and restricted to crumpled notes: the
|
|
34
|
+
* playbook's wastebasket rule is the only legitimate target, so a live note refuses here even
|
|
35
|
+
* before policy is consulted. The time window itself stays playbook policy, not tool law.
|
|
36
|
+
*/
|
|
37
|
+
export function dreamerDeleteToolDefinition(notesHome: string): ToolDefinition<any, any, any> {
|
|
38
|
+
return {
|
|
39
|
+
name: "delete",
|
|
40
|
+
label: "delete",
|
|
41
|
+
description: "Physically delete one crumpled note file inside the notes home. Reserved for the playbook's wastebasket rule: a crumpled note whose full retention window has passed. Live notes refuse. Deletion is permanent beyond the Git audit.",
|
|
42
|
+
parameters: DELETE_PARAMETERS,
|
|
43
|
+
async execute(_toolCallId: string, params: { path: string }, _signal: AbortSignal | undefined, _onUpdate: unknown, _ctx: unknown) {
|
|
44
|
+
return deleteCrumpledNote(notesHome, params.path);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const defaultDreamerSessionFactory: DreamerSessionFactory = async ({ cwd, modelPattern, tools }) => {
|
|
50
|
+
let model: Model<Api> | undefined;
|
|
51
|
+
if (modelPattern) {
|
|
52
|
+
const runtime = await ModelRuntime.create({ allowModelNetwork: false, refreshOnCreate: false });
|
|
53
|
+
const result = await resolveModelScopeWithDiagnostics([modelPattern], runtime);
|
|
54
|
+
model = result.scopedModels[0]?.model;
|
|
55
|
+
if (!model) throw new Error(`dreamer model pattern "${modelPattern}" did not resolve to an available model`);
|
|
56
|
+
}
|
|
57
|
+
const { session } = await createAgentSession({ cwd, sessionManager: SessionManager.inMemory(cwd), tools, customTools: [...dreamerWriteToolDefinitions(cwd), dreamerDeleteToolDefinition(cwd)], noTools: "all", model, thinkingLevel: "off" });
|
|
58
|
+
return session;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Run one dream turn. A dreamer failure is returned as `error` together with the partial
|
|
63
|
+
* writes observed so far, so the caller can record partial state instead of losing it;
|
|
64
|
+
* only a failure to even start the session throws.
|
|
65
|
+
*/
|
|
66
|
+
export async function runDreamer(playbook: string, cwd: string, options: { modelPattern?: string; sessionFactory?: DreamerSessionFactory } = {}): Promise<DreamResult> {
|
|
67
|
+
const session = await (options.sessionFactory ?? defaultDreamerSessionFactory)({ cwd, modelPattern: options.modelPattern, tools: DREAMER_TOOLS });
|
|
68
|
+
let answer = "";
|
|
69
|
+
let providerError: string | undefined;
|
|
70
|
+
const writes: DreamWrite[] = [];
|
|
71
|
+
const unsubscribe = session.subscribe((event: any) => {
|
|
72
|
+
const tool = event.toolName ?? event.tool?.name;
|
|
73
|
+
const args = event.args ?? event.arguments ?? event.tool?.arguments;
|
|
74
|
+
if ((tool === "write" || tool === "edit" || tool === "delete") && args && typeof args === "object" && typeof args.path === "string") writes.push({ tool, path: args.path });
|
|
75
|
+
if (event.type !== "message_end" || event.message?.role !== "assistant") return;
|
|
76
|
+
if (event.message.stopReason === "error") { providerError = event.message.errorMessage ?? "unknown provider error"; return; }
|
|
77
|
+
answer = contentText(event.message.content);
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
try {
|
|
81
|
+
await session.prompt(playbook);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return { report: answer, writes, error: error instanceof Error ? error.message : String(error) };
|
|
84
|
+
}
|
|
85
|
+
if (providerError) return { report: answer, writes, error: `dreamer failed: ${providerError}` };
|
|
86
|
+
return { report: answer, writes };
|
|
87
|
+
} finally {
|
|
88
|
+
unsubscribe?.();
|
|
89
|
+
session.dispose();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { deriveDreamer, type DreamerSetting } from "../../dream/settings.js";
|
|
2
|
+
import { SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { mergeNotesoupSettings } from "../../settings.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the configurable dreamer model from Pi settings for a CLI invocation: global
|
|
7
|
+
* `~/.pi/agent/settings.json` merged with the project's `.pi/settings.json`, project
|
|
8
|
+
* values winning per key. A settings read failure degrades to no pattern with one warning.
|
|
9
|
+
*/
|
|
10
|
+
export function readDreamerSettings(cwd = process.cwd()): DreamerSetting {
|
|
11
|
+
try {
|
|
12
|
+
const settingsManager = SettingsManager.create(cwd, undefined, { projectTrusted: true });
|
|
13
|
+
return deriveDreamer(mergeNotesoupSettings(settingsManager.getGlobalSettings(), settingsManager.getProjectSettings()));
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return { warnings: [`notesoup: could not read settings; using the automatic dreamer model (${String(error)}).`] };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const BOOT_TYPE = "notesoup/boot";
|
|
2
|
+
export const GUIDANCE_TYPE = "notesoup/guidance";
|
|
3
|
+
export const WARNING_TYPE = "notesoup/warning";
|
|
4
|
+
export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
|
|
5
|
+
export const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
6
|
+
export const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
|
+
export const RESET_PROMPT_TYPE = "notesoup/reset-prompt";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from @earendil-works/pi-ai `utils/estimate` (Pi 1.1.0). The package's
|
|
3
|
+
* root does not re-export these functions, and Pi's extension loader aliases
|
|
4
|
+
* package roots, so the public `utils/estimate` subpath misresolves when the
|
|
5
|
+
* extension is loaded from source. Keep the logic byte-faithful to upstream.
|
|
6
|
+
*/
|
|
7
|
+
import { getSystemMessageText } from "@earendil-works/pi-ai";
|
|
8
|
+
import type { ImageContent, Message, TextContent, TranscriptContext, Usage } from "@earendil-works/pi-ai";
|
|
9
|
+
|
|
10
|
+
const CHARS_PER_TOKEN = 3.5;
|
|
11
|
+
const ESTIMATED_IMAGE_CHARS = 4800;
|
|
12
|
+
|
|
13
|
+
export interface ContextUsageEstimate {
|
|
14
|
+
/** Estimated total context tokens. */
|
|
15
|
+
tokens: number;
|
|
16
|
+
/** Tokens reported by the most recent applicable assistant usage block. */
|
|
17
|
+
usageTokens: number;
|
|
18
|
+
/** Estimated tokens after the most recent applicable assistant usage block. */
|
|
19
|
+
trailingTokens: number;
|
|
20
|
+
/** Index of the applicable message that provided usage, or null when none exists. */
|
|
21
|
+
lastUsageIndex: number | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function calculateContextTokens(usage: Usage): number {
|
|
25
|
+
return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function safeJsonStringify(value: unknown): string {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.stringify(value) ?? "undefined";
|
|
31
|
+
} catch {
|
|
32
|
+
return "[unserializable]";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function estimateTextAndImageContentChars(content: string | Array<TextContent | ImageContent>): number {
|
|
37
|
+
if (typeof content === "string") return content.length;
|
|
38
|
+
let chars = 0;
|
|
39
|
+
for (const block of content) chars += block.type === "text" ? block.text.length : ESTIMATED_IMAGE_CHARS;
|
|
40
|
+
return chars;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function estimateTextTokens(text: string): number {
|
|
44
|
+
return Math.ceil(text.length / CHARS_PER_TOKEN);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function estimateTextAndImageContentTokens(content: string | Array<TextContent | ImageContent>): number {
|
|
48
|
+
return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function estimateMessageTokens(message: Message): number {
|
|
52
|
+
let chars = 0;
|
|
53
|
+
if (message.role === "system") {
|
|
54
|
+
return (
|
|
55
|
+
estimateTextTokens(getSystemMessageText(message)) +
|
|
56
|
+
estimateToolsTokens(message.toolsAdded) +
|
|
57
|
+
estimateToolsTokens(message.toolsRemoved)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (message.role === "user") return estimateTextAndImageContentTokens(message.content);
|
|
61
|
+
if (message.role === "toolResult") return estimateTextAndImageContentTokens(message.content);
|
|
62
|
+
for (const block of message.content) {
|
|
63
|
+
if (block.type === "text") {
|
|
64
|
+
chars += block.text.length;
|
|
65
|
+
} else if (block.type === "thinking") {
|
|
66
|
+
chars += block.thinking.length;
|
|
67
|
+
} else {
|
|
68
|
+
chars += block.name.length + safeJsonStringify(block.arguments).length;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getLastAssistantUsageInfo(messages: readonly Message[]): { usage: Usage; index: number } | undefined {
|
|
75
|
+
let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;
|
|
76
|
+
let usageInfo: { usage: Usage; index: number } | undefined;
|
|
77
|
+
for (let i = 0; i < messages.length; i++) {
|
|
78
|
+
const message = messages[i]!;
|
|
79
|
+
if (message.role === "assistant") {
|
|
80
|
+
// A newer prefix message was inserted after this response (for example, a
|
|
81
|
+
// compaction summary), so its usage cannot describe the current prefix.
|
|
82
|
+
const usageAppliesToPrefix = message.timestamp >= latestPrefixTimestamp;
|
|
83
|
+
if (
|
|
84
|
+
usageAppliesToPrefix &&
|
|
85
|
+
message.stopReason !== "aborted" &&
|
|
86
|
+
message.stopReason !== "error" &&
|
|
87
|
+
calculateContextTokens(message.usage) > 0
|
|
88
|
+
) {
|
|
89
|
+
usageInfo = { usage: message.usage, index: i };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);
|
|
93
|
+
}
|
|
94
|
+
return usageInfo;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function estimateContextTokens(context: TranscriptContext | readonly Message[]): ContextUsageEstimate {
|
|
98
|
+
const messages = "messages" in context ? context.messages : context;
|
|
99
|
+
const usageInfo = getLastAssistantUsageInfo(messages);
|
|
100
|
+
if (usageInfo) {
|
|
101
|
+
const usageTokens = calculateContextTokens(usageInfo.usage);
|
|
102
|
+
let trailingTokens = 0;
|
|
103
|
+
for (let i = usageInfo.index + 1; i < messages.length; i++) {
|
|
104
|
+
trailingTokens += estimateMessageTokens(messages[i]!);
|
|
105
|
+
}
|
|
106
|
+
return { tokens: usageTokens + trailingTokens, usageTokens, trailingTokens, lastUsageIndex: usageInfo.index };
|
|
107
|
+
}
|
|
108
|
+
let tokens = 0;
|
|
109
|
+
for (const message of messages) tokens += estimateMessageTokens(message);
|
|
110
|
+
return { tokens, usageTokens: 0, trailingTokens: tokens, lastUsageIndex: null };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function estimateToolsTokens(tools: unknown): number {
|
|
114
|
+
if (!tools || (Array.isArray(tools) && tools.length === 0)) return 0;
|
|
115
|
+
return estimateTextTokens(safeJsonStringify(tools));
|
|
116
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { VERSION, type ExtensionAPI, type ExtensionFactory, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { registerHistoryTools } from "./history-tools.js";
|
|
3
|
+
import { registerNotesTools } from "./notes/tools.js";
|
|
4
|
+
import { registerContext } from "./runtime.js";
|
|
5
|
+
|
|
6
|
+
function registerNotesoup(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
|
|
7
|
+
const [major, minor] = VERSION.split(".").map(Number);
|
|
8
|
+
if (!(major > 0 || (major === 0 && minor >= 87))) {
|
|
9
|
+
throw new Error(`notesoup requires Pi >= 0.87.0; running ${VERSION}. Upgrade Pi and restart the process; /reload only reloads extensions.`);
|
|
10
|
+
}
|
|
11
|
+
registerContext(pi, settingsManager);
|
|
12
|
+
registerHistoryTools(pi);
|
|
13
|
+
registerNotesTools(pi);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create an extension factory bound to an SDK settings authority. The host must pass
|
|
18
|
+
* the same manager to createAgentSession and to this factory's resource loader.
|
|
19
|
+
*/
|
|
20
|
+
export function createNotesoup(options: { settingsManager?: SettingsManager } = {}): ExtensionFactory {
|
|
21
|
+
return (pi) => registerNotesoup(pi, options.settingsManager);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The Pi-discovered extension keeps the standard file-backed settings behavior. */
|
|
25
|
+
export default function notesoup(pi: ExtensionAPI): void {
|
|
26
|
+
registerNotesoup(pi);
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { historyWindows, historyList, historyRead } from "../tools/history.js";
|
|
3
|
+
import { historyFromSession } from "./history.js";
|
|
4
|
+
import { HISTORY_NAMESPACE, registerOperation } from "./tool-result.js";
|
|
5
|
+
|
|
6
|
+
/** Register the three shared history operations; the adapter allocates addresses and supplies them. */
|
|
7
|
+
export function registerHistoryTools(pi: ExtensionAPI) {
|
|
8
|
+
registerOperation(pi, historyWindows, (params, ctx) => historyWindows.execute(params, historyFromSession(ctx), ctx.sessionManager.getSessionId()), HISTORY_NAMESPACE);
|
|
9
|
+
registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE);
|
|
10
|
+
registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE);
|
|
11
|
+
}
|