notesoup 0.45.0 → 0.45.1
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/dist/src/boot/text.d.ts +7 -0
- package/dist/src/boot/text.js +7 -0
- package/dist/src/claude/helper.js +3 -8
- package/dist/src/dsh/engine.d.ts +6 -0
- package/dist/src/dsh/engine.js +34 -1
- package/dist/src/dsh/index.js +1 -1
- package/dist/src/dsh/tools.d.ts +1 -1
- package/dist/src/dsh/tools.js +2 -2
- package/dist/src/dsh/window.d.ts +1 -1
- package/dist/src/dsh/window.js +4 -6
- package/dist/src/notes/index.d.ts +4 -2
- package/dist/src/notes/index.js +4 -1
- package/dist/src/notes/paths.d.ts +0 -1
- package/dist/src/notes/paths.js +0 -1
- package/dist/src/pi/boot.d.ts +0 -5
- package/dist/src/pi/boot.js +4 -30
- package/dist/src/pi/budget.js +3 -3
- package/dist/src/pi/notes/adapter.d.ts +1 -1
- package/dist/src/pi/notes/adapter.js +1 -1
- package/dist/src/pi/runtime.js +28 -3
- package/dist/src/pi/tool-result.d.ts +9 -0
- package/dist/src/pi/tool-result.js +4 -0
- package/dist/src/tools/notes.d.ts +1 -1
- package/dist/src/tools/notes.js +1 -1
- package/dist/src/tools/output.d.ts +1 -14
- package/dist/src/tools/output.js +1 -9
- package/dist/test/dependencies.test.js +53 -17
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/helpers/dependency-graph.d.ts +3 -3
- package/dist/test/helpers/dependency-graph.js +64 -14
- package/dist/test/helpers/extension.js +2 -2
- package/dist/test/host-neutral.test.js +5 -0
- package/dist/test/notes.integration.test.js +4 -4
- package/dist/test/notes.test.js +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +649 -651
- package/package.json +1 -1
- package/src/boot/text.ts +8 -0
- package/src/claude/helper.ts +3 -10
- package/src/dsh/engine.ts +27 -1
- package/src/dsh/index.ts +1 -1
- package/src/dsh/tools.ts +2 -3
- package/src/dsh/window.ts +4 -6
- package/src/notes/index.ts +4 -2
- package/src/notes/paths.ts +0 -1
- package/src/pi/boot.ts +4 -33
- package/src/pi/budget.ts +3 -3
- package/src/pi/notes/adapter.ts +1 -2
- package/src/pi/notes/tools.ts +1 -1
- package/src/pi/runtime.ts +31 -3
- package/src/pi/tool-result.ts +5 -0
- package/src/tools/notes.ts +1 -1
- package/src/tools/output.ts +1 -10
- package/dist/src/dsh/preflight.d.ts +0 -8
- package/dist/src/dsh/preflight.js +0 -35
- package/dist/src/pi/tool-names.d.ts +0 -7
- package/dist/src/pi/tool-names.js +0 -7
- package/src/dsh/preflight.ts +0 -29
- package/src/pi/tool-names.ts +0 -9
package/package.json
CHANGED
package/src/boot/text.ts
CHANGED
|
@@ -69,6 +69,14 @@ export type BootToolNames = Readonly<{
|
|
|
69
69
|
wipeSentence?: string;
|
|
70
70
|
}>;
|
|
71
71
|
|
|
72
|
+
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
73
|
+
notes: "notes_*",
|
|
74
|
+
notesList: "notes_list",
|
|
75
|
+
history: "history_*",
|
|
76
|
+
remaining: "get_context_remaining",
|
|
77
|
+
wipe: "clear_memory",
|
|
78
|
+
} as const satisfies BootToolNames;
|
|
79
|
+
|
|
72
80
|
export function renderProtocolBlock(tools: BootToolNames): string {
|
|
73
81
|
const names: Record<string, string> = {
|
|
74
82
|
"notes_*": tools.notes,
|
package/src/claude/helper.ts
CHANGED
|
@@ -8,9 +8,7 @@ import { renderBootBlock } from "../boot/render.js";
|
|
|
8
8
|
import { CLAUDE_WIPE_SENTENCE, type BootToolNames } from "../boot/text.js";
|
|
9
9
|
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../budget/text.js";
|
|
10
10
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
11
|
-
import {
|
|
12
|
-
import { snapshotNotesIdentity, type NotesIdentity } from "../notes/identity.js";
|
|
13
|
-
import type { NoteChange } from "../notes/store.js";
|
|
11
|
+
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../notes/index.js";
|
|
14
12
|
import type { Operation, Outcome } from "../tools/result.js";
|
|
15
13
|
|
|
16
14
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
@@ -28,7 +26,7 @@ type BoundOperation = {
|
|
|
28
26
|
|
|
29
27
|
function identity(input: ClaudeIdentityInput): NotesIdentity {
|
|
30
28
|
if (!input || typeof input !== "object" || typeof input.cwd !== "string") throw new Error("invalid identity");
|
|
31
|
-
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey:
|
|
29
|
+
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/** The first schema violation, named by parameter so the model can fix that one field. */
|
|
@@ -59,14 +57,9 @@ function boundOperation<TParams extends TSchema, TData, TRest extends readonly u
|
|
|
59
57
|
};
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
/** Claude has no diff renderer, so an update receipt names the change kind instead of a diff. */
|
|
63
|
-
function claudeDiff(change: NoteChange): string {
|
|
64
|
-
return change.kind === "none" ? "" : `note ${change.kind}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
60
|
const OPERATIONS: Record<ClaudeToolName, BoundOperation> = {
|
|
68
61
|
notes_write: boundOperation(notesWrite),
|
|
69
|
-
notes_update: boundOperation(notesUpdate
|
|
62
|
+
notes_update: boundOperation(notesUpdate),
|
|
70
63
|
notes_read: boundOperation(notesRead),
|
|
71
64
|
notes_list: boundOperation(notesList),
|
|
72
65
|
notes_search: boundOperation(notesSearch),
|
package/src/dsh/engine.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type {} from "@deepseek-ai/cordis-plugin-loader";
|
|
3
4
|
import type { CommandId } from "@deepseek-ai/dsh-commands/brand";
|
|
4
5
|
import { CompactionEngine, CompactionId, ManualCompactionError, compactCheckpointSource, toolPairingBalancedAfter, toolPairingBalancedBefore, type CompactionAgentContext, type CompactionResult, type CompactionTrigger, type ManualCompactAgentContext } from "@deepseek-ai/dsh-compaction";
|
|
5
6
|
import { createUserMessage, type ContentBlock } from "@deepseek-ai/dsh-llm";
|
|
6
7
|
import { appendPluginRecord, type Session, type SessionSeq } from "@deepseek-ai/dsh-session";
|
|
7
8
|
import { measureBudget, type BudgetConfig } from "./budget.js";
|
|
8
9
|
import { checkpointText, Windows, WINDOW_RECORD, type NotesConfig } from "./window.js";
|
|
9
|
-
import { preflight } from "./preflight.js";
|
|
10
10
|
|
|
11
11
|
export type EngineConfig = NotesConfig & Partial<BudgetConfig>;
|
|
12
12
|
export type ResolvedConfig = NotesConfig & BudgetConfig;
|
|
@@ -158,3 +158,29 @@ export class NotesoupCompactionEngine extends CompactionEngine {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
export default NotesoupCompactionEngine;
|
|
161
|
+
|
|
162
|
+
export class PreflightError extends Error {
|
|
163
|
+
constructor(readonly code: string, message: string) { super(`notesoup: ${message}`); }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
167
|
+
export function preflight(ctx: Context): NotesoupCompactionEngine {
|
|
168
|
+
for (const [service, method] of [["systemPrompt", "section"], ["tools", "register"], ["sessionQuery", "readSession"], ["tokenMeter", "measure"], ["llm", "resolveModelInfo"]] as const) {
|
|
169
|
+
const mounted = ctx.get(service) as unknown as Record<string, unknown> | undefined;
|
|
170
|
+
if (typeof mounted?.[method] !== "function") throw new PreflightError("CAPABILITY", `${service}.${method} is unavailable; enable that service in the profile before using notesoup.`);
|
|
171
|
+
}
|
|
172
|
+
const engine = ctx.get("compaction");
|
|
173
|
+
if (!(engine instanceof NotesoupCompactionEngine)) throw new PreflightError("ENGINE", "ctx.compaction must be NotesoupCompactionEngine; disable compaction-basic and enable the notesoup-engine row, then restart dsh.");
|
|
174
|
+
const loader = ctx.get("loader");
|
|
175
|
+
if (loader) {
|
|
176
|
+
if (typeof loader.entries !== "function") throw new PreflightError("CAPABILITY", "loader.entries is unavailable; this profile cannot be checked for two engines.");
|
|
177
|
+
for (const entry of loader.entries()) {
|
|
178
|
+
if ((entry.options.id === "compaction-basic" || /(?:^|\/)dsh-compaction-basic$/.test(entry.options.name)) && !entry.disabled) throw new PreflightError("DOUBLE_ENGINE", "compaction-basic is enabled; set disabled: true on that profile row and restart dsh.");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const [callback, runtime] of ctx.registry.entries()) {
|
|
182
|
+
if (callback.name === "BasicCompactionEngine" && runtime.fibers.length > 0) throw new PreflightError("DOUBLE_ENGINE", "a BasicCompactionEngine fiber is mounted; remove it before starting notesoup.");
|
|
183
|
+
}
|
|
184
|
+
if (!engine.automaticListenerPresent) throw new PreflightError("AUTO_LISTENER", "the automatic reset listener is missing; reload notesoup-engine before sending another request.");
|
|
185
|
+
return engine;
|
|
186
|
+
}
|
package/src/dsh/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
|
4
4
|
import { CONTINUATION, WARNING_PROMPT, tokenBudgetGuidance } from "../budget/text.js";
|
|
5
5
|
import { measureBudget } from "./budget.js";
|
|
6
6
|
import { BOOT_SECTION, restoreWarnings } from "./window.js";
|
|
7
|
-
import { preflight } from "./
|
|
7
|
+
import { preflight } from "./engine.js";
|
|
8
8
|
import { registerTools } from "./tools.js";
|
|
9
9
|
|
|
10
10
|
export const name = "notesoup-dsh";
|
package/src/dsh/tools.ts
CHANGED
|
@@ -10,8 +10,7 @@ import { success, type Operation } from "../tools/result.js";
|
|
|
10
10
|
import { historyProjection } from "./history.js";
|
|
11
11
|
import { notesIdentity } from "./window.js";
|
|
12
12
|
import { measureBudget } from "./budget.js";
|
|
13
|
-
import { preflight } from "./
|
|
14
|
-
import type { NotesoupCompactionEngine } from "./engine.js";
|
|
13
|
+
import { preflight, type NotesoupCompactionEngine } from "./engine.js";
|
|
15
14
|
|
|
16
15
|
/** dsh enforces a small schema subset; TypeBox remains the full validator at execution. */
|
|
17
16
|
function hostSchema(schema: TSchema): JsonSchemaNode {
|
|
@@ -73,7 +72,7 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
|
|
|
73
72
|
});
|
|
74
73
|
const identity = (agent: Agent) => notesIdentity(agent, engine.config);
|
|
75
74
|
register(ctx, notesWrite, (agent) => [identity(agent)] as const);
|
|
76
|
-
register(ctx, notesUpdate, (agent) => [identity(agent)
|
|
75
|
+
register(ctx, notesUpdate, (agent) => [identity(agent)] as const);
|
|
77
76
|
register(ctx, notesRead, (agent) => [identity(agent)] as const);
|
|
78
77
|
register(ctx, notesList, (agent) => [identity(agent)] as const);
|
|
79
78
|
register(ctx, notesSearch, (agent) => [identity(agent)] as const);
|
package/src/dsh/window.ts
CHANGED
|
@@ -6,18 +6,16 @@ import { join } from "node:path";
|
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { loadNotesSnapshot } from "../boot/snapshot.js";
|
|
8
8
|
import { renderBootBlock } from "../boot/render.js";
|
|
9
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
9
10
|
import { CONTINUATION } from "../budget/text.js";
|
|
10
11
|
import { contentText } from "../history/history.js";
|
|
11
|
-
import { slugify } from "../notes/
|
|
12
|
-
import { resolveProjectHome } from "../notes/project-home.js";
|
|
13
|
-
import { snapshotNotesIdentity, type NotesIdentity } from "../notes/identity.js";
|
|
12
|
+
import { projectKey, slugify, snapshotNotesIdentity, type NotesIdentity } from "../notes/index.js";
|
|
14
13
|
|
|
15
14
|
export const WINDOW_RECORD = "plugin:notesoup/window";
|
|
16
15
|
export const BOOT_SECTION = "notesoup:boot";
|
|
17
16
|
const BOOT_OPEN = "<notesoup-boot>\n";
|
|
18
17
|
const BOOT_CLOSE = "\n</notesoup-boot>";
|
|
19
18
|
const CHECKPOINT_END = "\n\n<notesoup-continuation>\n";
|
|
20
|
-
const TOOLS = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "clear_memory" };
|
|
21
19
|
export type WindowSnapshot = Readonly<{ version: 1; window: number; windowId: string; openedAt: number; boot: string; notesDigest: string }>;
|
|
22
20
|
export type WindowState = { snapshot: WindowSnapshot; pendingReset: boolean; warned: boolean; reminded: boolean };
|
|
23
21
|
export type NotesConfig = { notesHome?: string; agentName?: string };
|
|
@@ -88,7 +86,7 @@ export function notesIdentity(agent: Pick<Agent, "session" | "options">, config:
|
|
|
88
86
|
return snapshotNotesIdentity({
|
|
89
87
|
home,
|
|
90
88
|
sessionId: agent.session.id,
|
|
91
|
-
projectKey:
|
|
89
|
+
projectKey: projectKey(agent.session.header.cwd ?? process.cwd(), home),
|
|
92
90
|
agent: slugify(config.agentName ?? "dsh"),
|
|
93
91
|
model: slugify(agent.session.requestHeader()?.config.model ?? agent.options.model ?? "unknown"),
|
|
94
92
|
});
|
|
@@ -120,7 +118,7 @@ export class Windows {
|
|
|
120
118
|
const notes = await loadNotesSnapshot(identity, openedAt);
|
|
121
119
|
const previous = this.states.get(agent.session)?.snapshot;
|
|
122
120
|
const firstWindowId = previous?.boot.match(/^First context window id: (.+)$/m)?.[1] ?? windowId(agent.session.id, 0);
|
|
123
|
-
const boot = BOOT_OPEN + renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId, currentWindowId: windowId(agent.session.id, window), ...(window ? { previousWindowId: previous?.windowId ?? windowId(agent.session.id, window - 1) } : {}), notes, tools:
|
|
121
|
+
const boot = BOOT_OPEN + renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId, currentWindowId: windowId(agent.session.id, window), ...(window ? { previousWindowId: previous?.windowId ?? windowId(agent.session.id, window - 1) } : {}), notes, tools: DEFAULT_BOOT_TOOL_NAMES }) + BOOT_CLOSE;
|
|
124
122
|
return Object.freeze({ version: 1, window, windowId: windowId(agent.session.id, window), openedAt, boot, notesDigest: digest(boot) });
|
|
125
123
|
}
|
|
126
124
|
}
|
package/src/notes/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
2
|
export { NoteError, type NoteErrorCode } from "./errors.js";
|
|
3
|
-
export { projectKey
|
|
4
|
-
export
|
|
3
|
+
export { projectKey } from "./project-home.js";
|
|
4
|
+
export { slugify } from "./paths.js";
|
|
5
|
+
export { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
|
|
6
|
+
export { isFilesystemError } from "./fs-error.js";
|
|
5
7
|
export type {
|
|
6
8
|
EditOperation,
|
|
7
9
|
EditOptions,
|
package/src/notes/paths.ts
CHANGED
package/src/pi/boot.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
2
2
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
|
|
4
4
|
import { loadNotesSnapshot, unavailableNotesSnapshot, type NotesSnapshot } from "../boot/snapshot.js";
|
|
5
|
-
import { isFilesystemError } from "../notes/
|
|
5
|
+
import { isFilesystemError } from "../notes/index.js";
|
|
6
6
|
import { BOOT_TYPE } from "./entries.js";
|
|
7
7
|
import { renderBootBlock } from "../boot/render.js";
|
|
8
|
-
import {
|
|
9
|
-
import { repairResetTail } from "./reset/artifacts.js";
|
|
8
|
+
import { rootWindowId } from "./window.js";
|
|
10
9
|
|
|
11
10
|
export type IncompleteNotesNotifier = (ctx: ExtensionContext, windowId: string, snapshot: NotesSnapshot) => void;
|
|
12
11
|
|
|
@@ -43,7 +42,7 @@ export async function buildBootMessage(
|
|
|
43
42
|
if (isCurrent()) notifyIncompleteNotes?.(ctx, windowId, notes);
|
|
44
43
|
return {
|
|
45
44
|
customType: BOOT_TYPE,
|
|
46
|
-
content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools:
|
|
45
|
+
content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: DEFAULT_BOOT_TOOL_NAMES }),
|
|
47
46
|
display: false,
|
|
48
47
|
details: { windowId },
|
|
49
48
|
};
|
|
@@ -56,31 +55,3 @@ export function sendBoot(pi: ExtensionAPI, boot: BootMessage): void {
|
|
|
56
55
|
{ triggerTurn: false },
|
|
57
56
|
);
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
|
|
62
|
-
* boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
|
|
63
|
-
*/
|
|
64
|
-
export async function ensureBoot(
|
|
65
|
-
pi: ExtensionAPI,
|
|
66
|
-
ctx: ExtensionContext,
|
|
67
|
-
notifyIncompleteNotes?: IncompleteNotesNotifier,
|
|
68
|
-
isCurrent: () => boolean = () => true,
|
|
69
|
-
): Promise<void> {
|
|
70
|
-
const sessionId = ctx.sessionManager.getSessionId();
|
|
71
|
-
const reset = currentReset(ctx);
|
|
72
|
-
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
73
|
-
const stillCurrent = () => isCurrent() &&
|
|
74
|
-
ctx.signal?.aborted !== true &&
|
|
75
|
-
ctx.sessionManager.getSessionId() === sessionId &&
|
|
76
|
-
currentWindowId(ctx) === windowId;
|
|
77
|
-
if (reset) {
|
|
78
|
-
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
82
|
-
const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
|
|
83
|
-
if (!stillCurrent()) return;
|
|
84
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
85
|
-
sendBoot(pi, boot);
|
|
86
|
-
}
|
package/src/pi/budget.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
2
2
|
import { remainingBudget, type ResolvedThresholds } from "../budget/policy.js";
|
|
3
3
|
import { Type } from "@earendil-works/pi-ai";
|
|
4
4
|
import { defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -8,7 +8,7 @@ import { readThresholdSettings, type ThresholdSettingsResolution } from "./thres
|
|
|
8
8
|
import { currentWindowId, hasWindowMessage, isWindowMarker, rootWindowId, windowUsage } from "./window.js";
|
|
9
9
|
import { tokenBudgetGuidance } from "../budget/text.js";
|
|
10
10
|
import { arrangeAnchoredReminders, type AnchorDetails } from "./anchored.js";
|
|
11
|
-
import { output } from "
|
|
11
|
+
import { output } from "./tool-result.js";
|
|
12
12
|
|
|
13
13
|
/** Remaining tokens in the provider's active window, or null without a usable estimate. */
|
|
14
14
|
function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">): number | null {
|
|
@@ -147,7 +147,7 @@ export function registerBudget(
|
|
|
147
147
|
if (hasWindowMessage(ctx, GUIDANCE_TYPE)) return result();
|
|
148
148
|
if (pendingGuidance?.windowId !== windowId) {
|
|
149
149
|
if (remaining > reminder) return result();
|
|
150
|
-
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0,
|
|
150
|
+
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
|
|
151
151
|
}
|
|
152
152
|
return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
|
|
153
153
|
});
|
package/src/pi/notes/adapter.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
|
-
import type
|
|
5
|
-
import { projectKey, slugify } from "../../notes/paths.js";
|
|
4
|
+
import { projectKey, slugify, type NotesIdentity } from "../../notes/index.js";
|
|
6
5
|
|
|
7
6
|
/** Pi's default notes root; environment access stays on the host side of the library boundary. */
|
|
8
7
|
export function notesRoot(): string {
|
package/src/pi/notes/tools.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { generateDiffString, type ExtensionAPI } from "@earendil-works/pi-coding
|
|
|
2
2
|
import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../../tools/notes.js";
|
|
3
3
|
import { notesIdentityFromPi } from "./adapter.js";
|
|
4
4
|
import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
|
|
5
|
-
import type { NoteChange } from "../../notes/
|
|
5
|
+
import type { NoteChange } from "../../notes/index.js";
|
|
6
6
|
|
|
7
7
|
function renderDiff(change: NoteChange): string {
|
|
8
8
|
return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
|
package/src/pi/runtime.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
|
3
3
|
import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
|
|
4
4
|
import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { registerBudget } from "./budget.js";
|
|
6
|
-
import { output } from "
|
|
6
|
+
import { output } from "./tool-result.js";
|
|
7
7
|
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
|
-
import { buildResetDrafts } from "./reset/artifacts.js";
|
|
9
|
+
import { buildResetDrafts, repairResetTail } from "./reset/artifacts.js";
|
|
10
10
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
11
11
|
import { WARNING_CONTENT } from "../budget/text.js";
|
|
12
|
-
import {
|
|
12
|
+
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
|
|
13
13
|
import { errorMessage } from "../error-message.js";
|
|
14
14
|
|
|
15
15
|
function readPackageVersion(): string {
|
|
@@ -26,6 +26,34 @@ function branchHasWindowMarker(ctx: ExtensionContext, fromId?: string): boolean
|
|
|
26
26
|
return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
|
|
31
|
+
* boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
|
|
32
|
+
*/
|
|
33
|
+
async function ensureBoot(
|
|
34
|
+
pi: ExtensionAPI,
|
|
35
|
+
ctx: ExtensionContext,
|
|
36
|
+
notifyIncompleteNotes?: IncompleteNotesNotifier,
|
|
37
|
+
isCurrent: () => boolean = () => true,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
40
|
+
const reset = currentReset(ctx);
|
|
41
|
+
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
42
|
+
const stillCurrent = () => isCurrent() &&
|
|
43
|
+
ctx.signal?.aborted !== true &&
|
|
44
|
+
ctx.sessionManager.getSessionId() === sessionId &&
|
|
45
|
+
currentWindowId(ctx) === windowId;
|
|
46
|
+
if (reset) {
|
|
47
|
+
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
51
|
+
const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
|
|
52
|
+
if (!stillCurrent()) return;
|
|
53
|
+
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
54
|
+
sendBoot(pi, boot);
|
|
55
|
+
}
|
|
56
|
+
|
|
29
57
|
/** Register the context-window runtime and its context-owned commands/tools. */
|
|
30
58
|
export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
|
|
31
59
|
let enabled = true;
|
package/src/pi/tool-result.ts
CHANGED
|
@@ -5,6 +5,11 @@ import type { JsonValue } from "@earendil-works/pi-ai";
|
|
|
5
5
|
import type { Static, TSchema } from "typebox";
|
|
6
6
|
import { wireResult, type Operation, type Outcome, type Renderer } from "../tools/result.js";
|
|
7
7
|
|
|
8
|
+
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
9
|
+
export function output(value: unknown, details?: unknown, terminate = false) {
|
|
10
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(value) }], details, terminate };
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
9
14
|
function piOperationResult<TData>(render: Renderer<TData>, outcome: Outcome<TData>): AgentToolResult<undefined> {
|
|
10
15
|
return {
|
package/src/tools/notes.ts
CHANGED
|
@@ -258,7 +258,7 @@ export const notesUpdate = {
|
|
|
258
258
|
name: "notes_update", label: "Notes update",
|
|
259
259
|
description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
|
|
260
260
|
parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
|
|
261
|
-
async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string): Promise<Outcome<NotesUpdateData>> {
|
|
261
|
+
async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
|
|
262
262
|
try {
|
|
263
263
|
const store = createNotesStore(identity);
|
|
264
264
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
package/src/tools/output.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Shared output budget primitives. */
|
|
2
2
|
export const TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
|
|
3
3
|
/** The per-call limit as the model reads it in refusals. */
|
|
4
4
|
export const TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
|
|
@@ -21,12 +21,3 @@ export function prefixFit(text: string, fits: (content: string) => boolean): str
|
|
|
21
21
|
}
|
|
22
22
|
return chars.slice(0, low).join("");
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Encode a structured result through the common tool result boundary. `details` is slim
|
|
27
|
-
* metadata for logs/UI (pi convention: never a second copy of the payload) and stays
|
|
28
|
-
* undefined unless the tool has metadata worth persisting.
|
|
29
|
-
*/
|
|
30
|
-
export function output(value: unknown, details?: unknown, terminate = false) {
|
|
31
|
-
return { content: [{ type: "text" as const, text: JSON.stringify(value) }], details, terminate };
|
|
32
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import { NotesoupCompactionEngine } from "./engine.js";
|
|
3
|
-
export declare class PreflightError extends Error {
|
|
4
|
-
readonly code: string;
|
|
5
|
-
constructor(code: string, message: string);
|
|
6
|
-
}
|
|
7
|
-
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
8
|
-
export declare function preflight(ctx: Context): NotesoupCompactionEngine;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { NotesoupCompactionEngine } from "./engine.js";
|
|
2
|
-
export class PreflightError extends Error {
|
|
3
|
-
code;
|
|
4
|
-
constructor(code, message) {
|
|
5
|
-
super(`notesoup: ${message}`);
|
|
6
|
-
this.code = code;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
10
|
-
export function preflight(ctx) {
|
|
11
|
-
for (const [service, method] of [["systemPrompt", "section"], ["tools", "register"], ["sessionQuery", "readSession"], ["tokenMeter", "measure"], ["llm", "resolveModelInfo"]]) {
|
|
12
|
-
const mounted = ctx.get(service);
|
|
13
|
-
if (typeof mounted?.[method] !== "function")
|
|
14
|
-
throw new PreflightError("CAPABILITY", `${service}.${method} is unavailable; enable that service in the profile before using notesoup.`);
|
|
15
|
-
}
|
|
16
|
-
const engine = ctx.get("compaction");
|
|
17
|
-
if (!(engine instanceof NotesoupCompactionEngine))
|
|
18
|
-
throw new PreflightError("ENGINE", "ctx.compaction must be NotesoupCompactionEngine; disable compaction-basic and enable the notesoup-engine row, then restart dsh.");
|
|
19
|
-
const loader = ctx.get("loader");
|
|
20
|
-
if (loader) {
|
|
21
|
-
if (typeof loader.entries !== "function")
|
|
22
|
-
throw new PreflightError("CAPABILITY", "loader.entries is unavailable; this profile cannot be checked for two engines.");
|
|
23
|
-
for (const entry of loader.entries()) {
|
|
24
|
-
if ((entry.options.id === "compaction-basic" || /(?:^|\/)dsh-compaction-basic$/.test(entry.options.name)) && !entry.disabled)
|
|
25
|
-
throw new PreflightError("DOUBLE_ENGINE", "compaction-basic is enabled; set disabled: true on that profile row and restart dsh.");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
for (const [callback, runtime] of ctx.registry.entries()) {
|
|
29
|
-
if (callback.name === "BasicCompactionEngine" && runtime.fibers.length > 0)
|
|
30
|
-
throw new PreflightError("DOUBLE_ENGINE", "a BasicCompactionEngine fiber is mounted; remove it before starting notesoup.");
|
|
31
|
-
}
|
|
32
|
-
if (!engine.automaticListenerPresent)
|
|
33
|
-
throw new PreflightError("AUTO_LISTENER", "the automatic reset listener is missing; reload notesoup-engine before sending another request.");
|
|
34
|
-
return engine;
|
|
35
|
-
}
|
package/src/dsh/preflight.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type {} from "@deepseek-ai/cordis-plugin-loader";
|
|
3
|
-
import { NotesoupCompactionEngine } from "./engine.js";
|
|
4
|
-
|
|
5
|
-
export class PreflightError extends Error {
|
|
6
|
-
constructor(readonly code: string, message: string) { super(`notesoup: ${message}`); }
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
10
|
-
export function preflight(ctx: Context): NotesoupCompactionEngine {
|
|
11
|
-
for (const [service, method] of [["systemPrompt", "section"], ["tools", "register"], ["sessionQuery", "readSession"], ["tokenMeter", "measure"], ["llm", "resolveModelInfo"]] as const) {
|
|
12
|
-
const mounted = ctx.get(service) as unknown as Record<string, unknown> | undefined;
|
|
13
|
-
if (typeof mounted?.[method] !== "function") throw new PreflightError("CAPABILITY", `${service}.${method} is unavailable; enable that service in the profile before using notesoup.`);
|
|
14
|
-
}
|
|
15
|
-
const engine = ctx.get("compaction");
|
|
16
|
-
if (!(engine instanceof NotesoupCompactionEngine)) throw new PreflightError("ENGINE", "ctx.compaction must be NotesoupCompactionEngine; disable compaction-basic and enable the notesoup-engine row, then restart dsh.");
|
|
17
|
-
const loader = ctx.get("loader");
|
|
18
|
-
if (loader) {
|
|
19
|
-
if (typeof loader.entries !== "function") throw new PreflightError("CAPABILITY", "loader.entries is unavailable; this profile cannot be checked for two engines.");
|
|
20
|
-
for (const entry of loader.entries()) {
|
|
21
|
-
if ((entry.options.id === "compaction-basic" || /(?:^|\/)dsh-compaction-basic$/.test(entry.options.name)) && !entry.disabled) throw new PreflightError("DOUBLE_ENGINE", "compaction-basic is enabled; set disabled: true on that profile row and restart dsh.");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
for (const [callback, runtime] of ctx.registry.entries()) {
|
|
25
|
-
if (callback.name === "BasicCompactionEngine" && runtime.fibers.length > 0) throw new PreflightError("DOUBLE_ENGINE", "a BasicCompactionEngine fiber is mounted; remove it before starting notesoup.");
|
|
26
|
-
}
|
|
27
|
-
if (!engine.automaticListenerPresent) throw new PreflightError("AUTO_LISTENER", "the automatic reset listener is missing; reload notesoup-engine before sending another request.");
|
|
28
|
-
return engine;
|
|
29
|
-
}
|
package/src/pi/tool-names.ts
DELETED