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/dist/src/boot/text.d.ts
CHANGED
|
@@ -26,4 +26,11 @@ export type BootToolNames = Readonly<{
|
|
|
26
26
|
*/
|
|
27
27
|
wipeSentence?: string;
|
|
28
28
|
}>;
|
|
29
|
+
export declare const DEFAULT_BOOT_TOOL_NAMES: {
|
|
30
|
+
readonly notes: "notes_*";
|
|
31
|
+
readonly notesList: "notes_list";
|
|
32
|
+
readonly history: "history_*";
|
|
33
|
+
readonly remaining: "get_context_remaining";
|
|
34
|
+
readonly wipe: "clear_memory";
|
|
35
|
+
};
|
|
29
36
|
export declare function renderProtocolBlock(tools: BootToolNames): string;
|
package/dist/src/boot/text.js
CHANGED
|
@@ -53,6 +53,13 @@ Any other @ address is fake. End of discussion. @ addresses are not file paths:
|
|
|
53
53
|
|
|
54
54
|
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each may carry a short Cheatsheet of rules that always apply (about 5 lines); the rest is the note index, with addresses and gists for lookup. Keep each one current.
|
|
55
55
|
${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
|
|
56
|
+
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
57
|
+
notes: "notes_*",
|
|
58
|
+
notesList: "notes_list",
|
|
59
|
+
history: "history_*",
|
|
60
|
+
remaining: "get_context_remaining",
|
|
61
|
+
wipe: "clear_memory",
|
|
62
|
+
};
|
|
56
63
|
export function renderProtocolBlock(tools) {
|
|
57
64
|
const names = {
|
|
58
65
|
"notes_*": tools.notes,
|
|
@@ -7,15 +7,14 @@ import { renderBootBlock } from "../boot/render.js";
|
|
|
7
7
|
import { CLAUDE_WIPE_SENTENCE } from "../boot/text.js";
|
|
8
8
|
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../budget/text.js";
|
|
9
9
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
10
|
-
import {
|
|
11
|
-
import { snapshotNotesIdentity } from "../notes/identity.js";
|
|
10
|
+
import { projectKey, snapshotNotesIdentity } from "../notes/index.js";
|
|
12
11
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
13
12
|
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
14
13
|
const TOOL_NAMES = ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"];
|
|
15
14
|
function identity(input) {
|
|
16
15
|
if (!input || typeof input !== "object" || typeof input.cwd !== "string")
|
|
17
16
|
throw new Error("invalid identity");
|
|
18
|
-
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey:
|
|
17
|
+
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
|
|
19
18
|
}
|
|
20
19
|
/** The first schema violation, named by parameter so the model can fix that one field. */
|
|
21
20
|
function paramProblem(schema, params) {
|
|
@@ -42,13 +41,9 @@ function boundOperation(operation, ...rest) {
|
|
|
42
41
|
},
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
/** Claude has no diff renderer, so an update receipt names the change kind instead of a diff. */
|
|
46
|
-
function claudeDiff(change) {
|
|
47
|
-
return change.kind === "none" ? "" : `note ${change.kind}`;
|
|
48
|
-
}
|
|
49
44
|
const OPERATIONS = {
|
|
50
45
|
notes_write: boundOperation(notesWrite),
|
|
51
|
-
notes_update: boundOperation(notesUpdate
|
|
46
|
+
notes_update: boundOperation(notesUpdate),
|
|
52
47
|
notes_read: boundOperation(notesRead),
|
|
53
48
|
notes_list: boundOperation(notesList),
|
|
54
49
|
notes_search: boundOperation(notesSearch),
|
package/dist/src/dsh/engine.d.ts
CHANGED
|
@@ -20,3 +20,9 @@ export declare class NotesoupCompactionEngine extends CompactionEngine {
|
|
|
20
20
|
private transaction;
|
|
21
21
|
}
|
|
22
22
|
export default NotesoupCompactionEngine;
|
|
23
|
+
export declare class PreflightError extends Error {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
constructor(code: string, message: string);
|
|
26
|
+
}
|
|
27
|
+
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
28
|
+
export declare function preflight(ctx: Context): NotesoupCompactionEngine;
|
package/dist/src/dsh/engine.js
CHANGED
|
@@ -4,7 +4,6 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
|
4
4
|
import { appendPluginRecord } from "@deepseek-ai/dsh-session";
|
|
5
5
|
import { measureBudget } from "./budget.js";
|
|
6
6
|
import { checkpointText, Windows, WINDOW_RECORD } from "./window.js";
|
|
7
|
-
import { preflight } from "./preflight.js";
|
|
8
7
|
function resolveConfig(config) {
|
|
9
8
|
const resolved = { ...config, auto: config.auto ?? true, thresholdRatio: config.thresholdRatio ?? 0.8, headroomTokens: config.headroomTokens ?? 65536 };
|
|
10
9
|
if (typeof resolved.auto !== "boolean" || !Number.isFinite(resolved.thresholdRatio) || resolved.thresholdRatio <= 0 || resolved.thresholdRatio > 1 || !Number.isSafeInteger(resolved.headroomTokens) || resolved.headroomTokens < 0 || (resolved.reminderMarginTokens !== undefined && (!Number.isSafeInteger(resolved.reminderMarginTokens) || resolved.reminderMarginTokens <= 0)))
|
|
@@ -191,3 +190,37 @@ export class NotesoupCompactionEngine extends CompactionEngine {
|
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
192
|
export default NotesoupCompactionEngine;
|
|
193
|
+
export class PreflightError extends Error {
|
|
194
|
+
code;
|
|
195
|
+
constructor(code, message) {
|
|
196
|
+
super(`notesoup: ${message}`);
|
|
197
|
+
this.code = code;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
|
|
201
|
+
export function preflight(ctx) {
|
|
202
|
+
for (const [service, method] of [["systemPrompt", "section"], ["tools", "register"], ["sessionQuery", "readSession"], ["tokenMeter", "measure"], ["llm", "resolveModelInfo"]]) {
|
|
203
|
+
const mounted = ctx.get(service);
|
|
204
|
+
if (typeof mounted?.[method] !== "function")
|
|
205
|
+
throw new PreflightError("CAPABILITY", `${service}.${method} is unavailable; enable that service in the profile before using notesoup.`);
|
|
206
|
+
}
|
|
207
|
+
const engine = ctx.get("compaction");
|
|
208
|
+
if (!(engine instanceof NotesoupCompactionEngine))
|
|
209
|
+
throw new PreflightError("ENGINE", "ctx.compaction must be NotesoupCompactionEngine; disable compaction-basic and enable the notesoup-engine row, then restart dsh.");
|
|
210
|
+
const loader = ctx.get("loader");
|
|
211
|
+
if (loader) {
|
|
212
|
+
if (typeof loader.entries !== "function")
|
|
213
|
+
throw new PreflightError("CAPABILITY", "loader.entries is unavailable; this profile cannot be checked for two engines.");
|
|
214
|
+
for (const entry of loader.entries()) {
|
|
215
|
+
if ((entry.options.id === "compaction-basic" || /(?:^|\/)dsh-compaction-basic$/.test(entry.options.name)) && !entry.disabled)
|
|
216
|
+
throw new PreflightError("DOUBLE_ENGINE", "compaction-basic is enabled; set disabled: true on that profile row and restart dsh.");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const [callback, runtime] of ctx.registry.entries()) {
|
|
220
|
+
if (callback.name === "BasicCompactionEngine" && runtime.fibers.length > 0)
|
|
221
|
+
throw new PreflightError("DOUBLE_ENGINE", "a BasicCompactionEngine fiber is mounted; remove it before starting notesoup.");
|
|
222
|
+
}
|
|
223
|
+
if (!engine.automaticListenerPresent)
|
|
224
|
+
throw new PreflightError("AUTO_LISTENER", "the automatic reset listener is missing; reload notesoup-engine before sending another request.");
|
|
225
|
+
return engine;
|
|
226
|
+
}
|
package/dist/src/dsh/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
|
2
2
|
import { CONTINUATION, WARNING_PROMPT, tokenBudgetGuidance } from "../budget/text.js";
|
|
3
3
|
import { measureBudget } from "./budget.js";
|
|
4
4
|
import { BOOT_SECTION, restoreWarnings } from "./window.js";
|
|
5
|
-
import { preflight } from "./
|
|
5
|
+
import { preflight } from "./engine.js";
|
|
6
6
|
import { registerTools } from "./tools.js";
|
|
7
7
|
export const name = "notesoup-dsh";
|
|
8
8
|
export const inject = ["tools", "sessions", "systemPrompt", "llm", "tokenMeter", "sessionQuery", "compaction"];
|
package/dist/src/dsh/tools.d.ts
CHANGED
package/dist/src/dsh/tools.js
CHANGED
|
@@ -7,7 +7,7 @@ import { success } from "../tools/result.js";
|
|
|
7
7
|
import { historyProjection } from "./history.js";
|
|
8
8
|
import { notesIdentity } from "./window.js";
|
|
9
9
|
import { measureBudget } from "./budget.js";
|
|
10
|
-
import { preflight } from "./
|
|
10
|
+
import { preflight } from "./engine.js";
|
|
11
11
|
/** dsh enforces a small schema subset; TypeBox remains the full validator at execution. */
|
|
12
12
|
function hostSchema(schema) {
|
|
13
13
|
const value = JSON.parse(JSON.stringify(schema));
|
|
@@ -77,7 +77,7 @@ export function registerTools(ctx, engine) {
|
|
|
77
77
|
});
|
|
78
78
|
const identity = (agent) => notesIdentity(agent, engine.config);
|
|
79
79
|
register(ctx, notesWrite, (agent) => [identity(agent)]);
|
|
80
|
-
register(ctx, notesUpdate, (agent) => [identity(agent)
|
|
80
|
+
register(ctx, notesUpdate, (agent) => [identity(agent)]);
|
|
81
81
|
register(ctx, notesRead, (agent) => [identity(agent)]);
|
|
82
82
|
register(ctx, notesList, (agent) => [identity(agent)]);
|
|
83
83
|
register(ctx, notesSearch, (agent) => [identity(agent)]);
|
package/dist/src/dsh/window.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
2
2
|
import { type Session, type SessionEvent } from "@deepseek-ai/dsh-session";
|
|
3
|
-
import { type NotesIdentity } from "../notes/
|
|
3
|
+
import { type NotesIdentity } from "../notes/index.js";
|
|
4
4
|
export declare const WINDOW_RECORD = "plugin:notesoup/window";
|
|
5
5
|
export declare const BOOT_SECTION = "notesoup:boot";
|
|
6
6
|
export type WindowSnapshot = Readonly<{
|
package/dist/src/dsh/window.js
CHANGED
|
@@ -5,17 +5,15 @@ import { join } from "node:path";
|
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { loadNotesSnapshot } from "../boot/snapshot.js";
|
|
7
7
|
import { renderBootBlock } from "../boot/render.js";
|
|
8
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
8
9
|
import { CONTINUATION } from "../budget/text.js";
|
|
9
10
|
import { contentText } from "../history/history.js";
|
|
10
|
-
import { slugify } from "../notes/
|
|
11
|
-
import { resolveProjectHome } from "../notes/project-home.js";
|
|
12
|
-
import { snapshotNotesIdentity } from "../notes/identity.js";
|
|
11
|
+
import { projectKey, slugify, snapshotNotesIdentity } from "../notes/index.js";
|
|
13
12
|
export const WINDOW_RECORD = "plugin:notesoup/window";
|
|
14
13
|
export const BOOT_SECTION = "notesoup:boot";
|
|
15
14
|
const BOOT_OPEN = "<notesoup-boot>\n";
|
|
16
15
|
const BOOT_CLOSE = "\n</notesoup-boot>";
|
|
17
16
|
const CHECKPOINT_END = "\n\n<notesoup-continuation>\n";
|
|
18
|
-
const TOOLS = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "clear_memory" };
|
|
19
17
|
export function restoreWarnings(state, events) {
|
|
20
18
|
state.warned = false;
|
|
21
19
|
state.reminded = false;
|
|
@@ -81,7 +79,7 @@ export function notesIdentity(agent, config) {
|
|
|
81
79
|
return snapshotNotesIdentity({
|
|
82
80
|
home,
|
|
83
81
|
sessionId: agent.session.id,
|
|
84
|
-
projectKey:
|
|
82
|
+
projectKey: projectKey(agent.session.header.cwd ?? process.cwd(), home),
|
|
85
83
|
agent: slugify(config.agentName ?? "dsh"),
|
|
86
84
|
model: slugify(agent.session.requestHeader()?.config.model ?? agent.options.model ?? "unknown"),
|
|
87
85
|
});
|
|
@@ -118,7 +116,7 @@ export class Windows {
|
|
|
118
116
|
const notes = await loadNotesSnapshot(identity, openedAt);
|
|
119
117
|
const previous = this.states.get(agent.session)?.snapshot;
|
|
120
118
|
const firstWindowId = previous?.boot.match(/^First context window id: (.+)$/m)?.[1] ?? windowId(agent.session.id, 0);
|
|
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:
|
|
119
|
+
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;
|
|
122
120
|
return Object.freeze({ version: 1, window, windowId: windowId(agent.session.id, window), openedAt, boot, notesDigest: digest(boot) });
|
|
123
121
|
}
|
|
124
122
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
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 { EditOperation, EditOptions, NoteChange, NoteEditResult, NoteMatch, NoteMeta, NoteQueryResult, NoteQueryStatus, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NoteWriteResult, NotesQuery, NotesStore, Origin, Scope, WriteOptions, } from "./store.js";
|
package/dist/src/notes/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
2
|
export { NoteError } from "./errors.js";
|
|
3
|
-
export { projectKey
|
|
3
|
+
export { projectKey } from "./project-home.js";
|
|
4
|
+
export { slugify } from "./paths.js";
|
|
5
|
+
export { snapshotNotesIdentity } from "./identity.js";
|
|
6
|
+
export { isFilesystemError } from "./fs-error.js";
|
package/dist/src/notes/paths.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
export { projectKey } from "./project-home.js";
|
|
4
3
|
import { NoteError, shown } from "./errors.js";
|
|
5
4
|
/** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
6
5
|
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
package/dist/src/pi/boot.d.ts
CHANGED
|
@@ -17,8 +17,3 @@ export type BootMessage = {
|
|
|
17
17
|
export declare function buildBootMessage(ctx: ExtensionContext, windowId: string, previousId: string | undefined, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean): Promise<BootMessage>;
|
|
18
18
|
/** Persist one hidden boot message without triggering a model turn. */
|
|
19
19
|
export declare function sendBoot(pi: ExtensionAPI, boot: BootMessage): void;
|
|
20
|
-
/**
|
|
21
|
-
* Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
|
|
22
|
-
* boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
|
|
23
|
-
*/
|
|
24
|
-
export declare function ensureBoot(pi: ExtensionAPI, ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean): Promise<void>;
|
package/dist/src/pi/boot.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
2
2
|
import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
|
|
3
3
|
import { loadNotesSnapshot, unavailableNotesSnapshot } from "../boot/snapshot.js";
|
|
4
|
-
import { isFilesystemError } from "../notes/
|
|
4
|
+
import { isFilesystemError } from "../notes/index.js";
|
|
5
5
|
import { BOOT_TYPE } from "./entries.js";
|
|
6
6
|
import { renderBootBlock } from "../boot/render.js";
|
|
7
|
-
import {
|
|
8
|
-
import { repairResetTail } from "./reset/artifacts.js";
|
|
7
|
+
import { rootWindowId } from "./window.js";
|
|
9
8
|
/**
|
|
10
9
|
* Acquire one notes snapshot and build the boot custom message for a window. All identity
|
|
11
10
|
* fields are captured synchronously before the first filesystem await.
|
|
@@ -28,7 +27,7 @@ export async function buildBootMessage(ctx, windowId, previousId, notifyIncomple
|
|
|
28
27
|
notifyIncompleteNotes?.(ctx, windowId, notes);
|
|
29
28
|
return {
|
|
30
29
|
customType: BOOT_TYPE,
|
|
31
|
-
content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools:
|
|
30
|
+
content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: DEFAULT_BOOT_TOOL_NAMES }),
|
|
32
31
|
display: false,
|
|
33
32
|
details: { windowId },
|
|
34
33
|
};
|
|
@@ -37,28 +36,3 @@ export async function buildBootMessage(ctx, windowId, previousId, notifyIncomple
|
|
|
37
36
|
export function sendBoot(pi, boot) {
|
|
38
37
|
pi.sendMessage({ customType: boot.customType, content: boot.content, display: boot.display, details: boot.details }, { triggerTurn: false });
|
|
39
38
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
|
|
42
|
-
* boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
|
|
43
|
-
*/
|
|
44
|
-
export async function ensureBoot(pi, ctx, notifyIncompleteNotes, isCurrent = () => true) {
|
|
45
|
-
const sessionId = ctx.sessionManager.getSessionId();
|
|
46
|
-
const reset = currentReset(ctx);
|
|
47
|
-
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
48
|
-
const stillCurrent = () => isCurrent() &&
|
|
49
|
-
ctx.signal?.aborted !== true &&
|
|
50
|
-
ctx.sessionManager.getSessionId() === sessionId &&
|
|
51
|
-
currentWindowId(ctx) === windowId;
|
|
52
|
-
if (reset) {
|
|
53
|
-
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
|
|
57
|
-
return;
|
|
58
|
-
const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
|
|
59
|
-
if (!stillCurrent())
|
|
60
|
-
return;
|
|
61
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
|
|
62
|
-
return;
|
|
63
|
-
sendBoot(pi, boot);
|
|
64
|
-
}
|
package/dist/src/pi/budget.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
|
|
2
2
|
import { remainingBudget } from "../budget/policy.js";
|
|
3
3
|
import { Type } from "@earendil-works/pi-ai";
|
|
4
4
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
@@ -8,7 +8,7 @@ import { readThresholdSettings } from "./thresholds.js";
|
|
|
8
8
|
import { currentWindowId, hasWindowMessage, isWindowMarker, rootWindowId, windowUsage } from "./window.js";
|
|
9
9
|
import { tokenBudgetGuidance } from "../budget/text.js";
|
|
10
10
|
import { arrangeAnchoredReminders } from "./anchored.js";
|
|
11
|
-
import { output } from "
|
|
11
|
+
import { output } from "./tool-result.js";
|
|
12
12
|
/** Remaining tokens in the provider's active window, or null without a usable estimate. */
|
|
13
13
|
function remainingTokens(ctx) {
|
|
14
14
|
const usage = windowUsage(ctx);
|
|
@@ -154,7 +154,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
154
154
|
if (pendingGuidance?.windowId !== windowId) {
|
|
155
155
|
if (remaining > reminder)
|
|
156
156
|
return result();
|
|
157
|
-
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0,
|
|
157
|
+
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
|
|
158
158
|
}
|
|
159
159
|
return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
|
|
160
160
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type
|
|
2
|
+
import { type NotesIdentity } from "../../notes/index.js";
|
|
3
3
|
/** Pi's default notes root; environment access stays on the host side of the library boundary. */
|
|
4
4
|
export declare function notesRoot(): string;
|
|
5
5
|
/** Translate the current Pi runtime into a fresh, explicit identity snapshot. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
-
import { projectKey, slugify } from "../../notes/
|
|
3
|
+
import { projectKey, slugify } from "../../notes/index.js";
|
|
4
4
|
/** Pi's default notes root; environment access stays on the host side of the library boundary. */
|
|
5
5
|
export function notesRoot() {
|
|
6
6
|
const override = process.env.PI_NOTES_HOME;
|
package/dist/src/pi/runtime.js
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 } 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 } 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 } from "./boot.js";
|
|
13
13
|
import { errorMessage } from "../error-message.js";
|
|
14
14
|
function readPackageVersion() {
|
|
15
15
|
for (const up of ["../../package.json", "../../../package.json"]) {
|
|
@@ -26,6 +26,31 @@ const buildLabel = `v${readPackageVersion()}`;
|
|
|
26
26
|
function branchHasWindowMarker(ctx, fromId) {
|
|
27
27
|
return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
|
|
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(pi, ctx, notifyIncompleteNotes, isCurrent = () => true) {
|
|
34
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
35
|
+
const reset = currentReset(ctx);
|
|
36
|
+
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
37
|
+
const stillCurrent = () => isCurrent() &&
|
|
38
|
+
ctx.signal?.aborted !== true &&
|
|
39
|
+
ctx.sessionManager.getSessionId() === sessionId &&
|
|
40
|
+
currentWindowId(ctx) === windowId;
|
|
41
|
+
if (reset) {
|
|
42
|
+
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
|
|
46
|
+
return;
|
|
47
|
+
const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
|
|
48
|
+
if (!stillCurrent())
|
|
49
|
+
return;
|
|
50
|
+
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
|
|
51
|
+
return;
|
|
52
|
+
sendBoot(pi, boot);
|
|
53
|
+
}
|
|
29
54
|
/** Register the context-window runtime and its context-owned commands/tools. */
|
|
30
55
|
export function registerContext(pi, settingsManager) {
|
|
31
56
|
let enabled = true;
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
import { type ExtensionAPI, type ExtensionToolContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import type { Static, TSchema } from "typebox";
|
|
4
4
|
import { type Operation, type Outcome } from "../tools/result.js";
|
|
5
|
+
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
6
|
+
export declare function output(value: unknown, details?: unknown, terminate?: boolean): {
|
|
7
|
+
content: {
|
|
8
|
+
type: "text";
|
|
9
|
+
text: string;
|
|
10
|
+
}[];
|
|
11
|
+
details: unknown;
|
|
12
|
+
terminate: boolean;
|
|
13
|
+
};
|
|
5
14
|
export type ToolNamespace = {
|
|
6
15
|
name: string;
|
|
7
16
|
description: string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** Pi transport for host-neutral operations. */
|
|
2
2
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { wireResult } from "../tools/result.js";
|
|
4
|
+
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
5
|
+
export function output(value, details, terminate = false) {
|
|
6
|
+
return { content: [{ type: "text", text: JSON.stringify(value) }], details, terminate };
|
|
7
|
+
}
|
|
4
8
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
5
9
|
function piOperationResult(render, outcome) {
|
|
6
10
|
return {
|
|
@@ -149,7 +149,7 @@ export declare const notesUpdate: {
|
|
|
149
149
|
code: Type.TString;
|
|
150
150
|
}>]>;
|
|
151
151
|
readonly executionMode: "sequential";
|
|
152
|
-
readonly execute: (params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff
|
|
152
|
+
readonly execute: (params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff?: (change: NoteChange) => string) => Promise<Outcome<NotesUpdateData>>;
|
|
153
153
|
readonly render: typeof renderUpdate;
|
|
154
154
|
};
|
|
155
155
|
export declare const notesReadParameters: Type.TObject<{
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -230,7 +230,7 @@ export const notesUpdate = {
|
|
|
230
230
|
name: "notes_update", label: "Notes update",
|
|
231
231
|
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}`,
|
|
232
232
|
parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
|
|
233
|
-
async execute(params, identity, renderDiff) {
|
|
233
|
+
async execute(params, identity, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
|
|
234
234
|
try {
|
|
235
235
|
const store = createNotesStore(identity);
|
|
236
236
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Shared output budget primitives. */
|
|
2
2
|
export declare const TOOL_OUTPUT_MAX_BYTES: number;
|
|
3
3
|
/** The per-call limit as the model reads it in refusals. */
|
|
4
4
|
export declare const TOOL_OUTPUT_LIMIT = "32 KB";
|
|
@@ -7,16 +7,3 @@ export declare const MAX_READ_WINDOW_CHARS = 50000;
|
|
|
7
7
|
export declare const HISTORY_PREVIEW_CHARS = 1200;
|
|
8
8
|
/** Longest fitting code-point prefix, without inserted markers. Callers report omissions. */
|
|
9
9
|
export declare function prefixFit(text: string, fits: (content: string) => boolean): string;
|
|
10
|
-
/**
|
|
11
|
-
* Encode a structured result through the common tool result boundary. `details` is slim
|
|
12
|
-
* metadata for logs/UI (pi convention: never a second copy of the payload) and stays
|
|
13
|
-
* undefined unless the tool has metadata worth persisting.
|
|
14
|
-
*/
|
|
15
|
-
export declare function output(value: unknown, details?: unknown, terminate?: boolean): {
|
|
16
|
-
content: {
|
|
17
|
-
type: "text";
|
|
18
|
-
text: string;
|
|
19
|
-
}[];
|
|
20
|
-
details: unknown;
|
|
21
|
-
terminate: boolean;
|
|
22
|
-
};
|
package/dist/src/tools/output.js
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`;
|
|
@@ -23,11 +23,3 @@ export function prefixFit(text, fits) {
|
|
|
23
23
|
}
|
|
24
24
|
return chars.slice(0, low).join("");
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Encode a structured result through the common tool result boundary. `details` is slim
|
|
28
|
-
* metadata for logs/UI (pi convention: never a second copy of the payload) and stays
|
|
29
|
-
* undefined unless the tool has metadata worth persisting.
|
|
30
|
-
*/
|
|
31
|
-
export function output(value, details, terminate = false) {
|
|
32
|
-
return { content: [{ type: "text", text: JSON.stringify(value) }], details, terminate };
|
|
33
|
-
}
|
|
@@ -35,24 +35,14 @@ test("all shared domains resolve without any direct or transitive SDK, Pi adapte
|
|
|
35
35
|
assert.equal(manifest.peerDependencies[name], "*", `${name} follows Pi's host dependency contract`);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
test("
|
|
38
|
+
test("each adapter resolves only its own host, shared domains and the public notes entry", () => {
|
|
39
39
|
const root = repository();
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const source = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.Latest, true);
|
|
47
|
-
for (const reference of moduleReferences(source)) {
|
|
48
|
-
assert.ok(!/^@(?:earendil-works|mariozechner)\/pi-/.test(reference), reference);
|
|
49
|
-
const resolved = ts.resolveModuleName(reference, file, options, ts.sys).resolvedModule;
|
|
50
|
-
if (resolved && resolved.resolvedFileName.startsWith(join(root, "src") + "/"))
|
|
51
|
-
inspect(resolved.resolvedFileName);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
for (const file of sources(join(root, "src/dsh")))
|
|
55
|
-
inspect(file);
|
|
40
|
+
for (const adapter of ["pi", "claude", "dsh"]) {
|
|
41
|
+
const entries = sources(join(root, "src", adapter));
|
|
42
|
+
if (adapter === "claude")
|
|
43
|
+
entries.push(...sources(join(root, "mods/notesoup/hooks")));
|
|
44
|
+
assert.deepEqual(dependencyViolations(root, entries, options, new Set(["typebox"])), [], adapter);
|
|
45
|
+
}
|
|
56
46
|
});
|
|
57
47
|
test("dependency guard follows indirect types, re-exports, dynamic imports and import-type edges through resolved aliases", (t) => {
|
|
58
48
|
const root = mkdtempSync(join(tmpdir(), "context-dependencies-"));
|
|
@@ -86,6 +76,52 @@ test("dependency guard follows indirect types, re-exports, dynamic imports and i
|
|
|
86
76
|
put("src/notes/safe.ts", "export type Value = string;");
|
|
87
77
|
assert.deepEqual(dependencyViolations(root, ["src/notes/identity.ts"], fixtureOptions, new Set()), [], "a host-neutral type/re-export chain is allowed");
|
|
88
78
|
});
|
|
79
|
+
test("adapter policies reject foreign hosts and notes internals, including reachable Claude hooks", (t) => {
|
|
80
|
+
const root = mkdtempSync(join(tmpdir(), "context-adapters-"));
|
|
81
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
82
|
+
const put = (path, text) => { mkdirSync(dirname(join(root, path)), { recursive: true }); writeFileSync(join(root, path), text); };
|
|
83
|
+
put("package.json", '{"type":"module"}');
|
|
84
|
+
put("src/notes/index.ts", 'export type { Note } from "./store.js";');
|
|
85
|
+
put("src/notes/store.ts", "export type Note = string;");
|
|
86
|
+
const hosts = ["pi", "claude", "dsh"];
|
|
87
|
+
const sdks = ["@earendil-works/pi-coding-agent", "claude-code", "@deepseek-ai/cordis"];
|
|
88
|
+
for (const host of hosts)
|
|
89
|
+
put(`src/${host}/native.ts`, "export const value = 1;");
|
|
90
|
+
for (const [index, host] of hosts.entries()) {
|
|
91
|
+
const entry = `src/${host}/entry.ts`;
|
|
92
|
+
const check = () => dependencyViolations(root, [entry], options, new Set());
|
|
93
|
+
put(entry, `export type { Note } from "../notes/index.js"; import type { Native } from "${sdks[index]}";`);
|
|
94
|
+
assert.deepEqual(check(), [], `${host} may use its SDK and the notes entry`);
|
|
95
|
+
put(entry, 'export type { Note } from "../notes/store.js";');
|
|
96
|
+
assert.deepEqual(check(), [`${entry} -> src/notes/store.ts`]);
|
|
97
|
+
const other = (index + 1) % hosts.length;
|
|
98
|
+
put(entry, `export { value } from "../${hosts[other]}/native.js";`);
|
|
99
|
+
assert.deepEqual(check(), [`${entry} -> src/${hosts[other]}/native.ts`]);
|
|
100
|
+
put(entry, `export type { Native } from "${sdks[other]}";`);
|
|
101
|
+
assert.deepEqual(check(), [`${entry} -> ${sdks[other]}`]);
|
|
102
|
+
}
|
|
103
|
+
put("src/claude/entry.ts", 'export { value } from "../../mods/notesoup/hooks/register.js";');
|
|
104
|
+
put("mods/notesoup/hooks/register.ts", 'export { value } from "../../../src/pi/native.js";');
|
|
105
|
+
assert.deepEqual(dependencyViolations(root, ["src/claude/entry.ts"], options, new Set()), ["src/claude/entry.ts -> mods/notesoup/hooks/register.ts -> src/pi/native.ts"]);
|
|
106
|
+
put("mods/notesoup/hooks/register.ts", 'export type { Note } from "../../../src/notes/index.js";');
|
|
107
|
+
assert.deepEqual(dependencyViolations(root, ["src/claude/entry.ts"], options, new Set()), []);
|
|
108
|
+
put("src/pi/entry.ts", 'export type { Note } from "@notes-internal";');
|
|
109
|
+
assert.deepEqual(dependencyViolations(root, ["src/pi/entry.ts"], { ...options, baseUrl: root, paths: { "@notes-internal": ["src/notes/store.ts"] } }, new Set()), ["src/pi/entry.ts -> src/notes/store.ts"]);
|
|
110
|
+
});
|
|
111
|
+
test("runtime cycles are rejected but explicit and implicitly erased type edges are allowed", (t) => {
|
|
112
|
+
const root = mkdtempSync(join(tmpdir(), "context-cycles-"));
|
|
113
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
114
|
+
mkdirSync(join(root, "src/boot"), { recursive: true });
|
|
115
|
+
writeFileSync(join(root, "package.json"), '{"type":"module"}');
|
|
116
|
+
writeFileSync(join(root, "src/boot/a.ts"), 'import { b } from "./b.js"; export const a = () => b; export type A = string;');
|
|
117
|
+
const check = () => dependencyViolations(root, ["src/boot/a.ts"], options, new Set());
|
|
118
|
+
writeFileSync(join(root, "src/boot/b.ts"), 'export { a as b } from "./a.js";');
|
|
119
|
+
assert.deepEqual(check(), ["runtime cycle: src/boot/a.ts -> src/boot/b.ts -> src/boot/a.ts"]);
|
|
120
|
+
writeFileSync(join(root, "src/boot/b.ts"), 'export type B = import("./a.js").A; export const b = 1;');
|
|
121
|
+
assert.deepEqual(check(), []);
|
|
122
|
+
writeFileSync(join(root, "src/boot/b.ts"), 'import { A } from "./a.js"; export type B = A; export const b = 1;');
|
|
123
|
+
assert.deepEqual(check(), []);
|
|
124
|
+
});
|
|
89
125
|
test("AST guard sees every literal module edge, not import-like prose or comments", () => {
|
|
90
126
|
const source = ts.createSourceFile("edges.ts", `
|
|
91
127
|
// import("not-an-edge")
|
package/dist/test/dsh.test.js
CHANGED
|
@@ -16,7 +16,7 @@ import { dshFixture } from "./helpers/dsh.js";
|
|
|
16
16
|
import { decodeHistory } from "../src/dsh/history.js";
|
|
17
17
|
import { checkpointSnapshot, notesIdentity, recoverSnapshot, WINDOW_RECORD } from "../src/dsh/window.js";
|
|
18
18
|
import { measureBudget } from "../src/dsh/budget.js";
|
|
19
|
-
import { preflight } from "../src/dsh/
|
|
19
|
+
import { preflight } from "../src/dsh/engine.js";
|
|
20
20
|
import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
|
|
21
21
|
function prompt(text) { return createUserMessage({ content: [{ type: "text", text }], source: { kind: "user" } }); }
|
|
22
22
|
async function run(agent, text) { agent.followup(prompt(text)); await agent.whenIdle(); }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
/** AST edges
|
|
3
|
-
export declare function moduleReferences(source: ts.SourceFile): string[];
|
|
4
|
-
/** Resolve
|
|
2
|
+
/** All AST edges enforce boundaries; emitted edges alone determine runtime cycles. */
|
|
3
|
+
export declare function moduleReferences(source: ts.SourceFile, runtimeOnly?: boolean): string[];
|
|
4
|
+
/** Resolve reachable edges, preserving each importing module's core/adapter ownership. */
|
|
5
5
|
export declare function dependencyViolations(root: string, entries: string[], options: ts.CompilerOptions, runtimeDependencies: Set<string>): string[];
|