notesoup 0.44.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/README.md +1 -0
- package/cordis.patch.yml +14 -0
- 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/budget.d.ts +20 -0
- package/dist/src/dsh/budget.js +34 -0
- package/dist/src/dsh/engine.d.ts +28 -0
- package/dist/src/dsh/engine.js +226 -0
- package/dist/src/dsh/history.d.ts +6 -0
- package/dist/src/dsh/history.js +73 -0
- package/dist/src/dsh/index.d.ts +22 -0
- package/dist/src/dsh/index.js +63 -0
- package/dist/src/dsh/tools.d.ts +3 -0
- package/dist/src/dsh/tools.js +111 -0
- package/dist/src/dsh/window.d.ts +46 -0
- package/dist/src/dsh/window.js +122 -0
- 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 +63 -1
- package/dist/test/dsh-cli.test.d.ts +1 -0
- package/dist/test/dsh-cli.test.js +44 -0
- package/dist/test/dsh-compaction-parity.test.d.ts +1 -0
- package/dist/test/dsh-compaction-parity.test.js +143 -0
- package/dist/test/dsh.test.d.ts +1 -0
- package/dist/test/dsh.test.js +323 -0
- package/dist/test/helpers/dependency-graph.d.ts +3 -3
- package/dist/test/helpers/dependency-graph.js +64 -14
- package/dist/test/helpers/dsh-messages.d.ts +29 -0
- package/dist/test/helpers/dsh-messages.js +33 -0
- package/dist/test/helpers/dsh.d.ts +17 -0
- package/dist/test/helpers/dsh.js +50 -0
- 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/docs/architecture.md +4 -1
- package/docs/dsh.md +61 -0
- package/docs/dsh.profile.patch.yml +34 -0
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +649 -651
- package/package.json +63 -4
- package/src/boot/text.ts +8 -0
- package/src/claude/helper.ts +3 -10
- package/src/dsh/budget.ts +35 -0
- package/src/dsh/engine.ts +186 -0
- package/src/dsh/history.ts +57 -0
- package/src/dsh/index.ts +69 -0
- package/src/dsh/tools.ts +106 -0
- package/src/dsh/window.ts +124 -0
- 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/pi/tool-names.d.ts +0 -7
- package/dist/src/pi/tool-names.js +0 -7
- package/mods/pi-context/dist/claude/helper.js +0 -9324
- package/src/pi/tool-names.ts +0 -9
|
@@ -3,9 +3,23 @@ import { readFileSync, realpathSync } from "node:fs";
|
|
|
3
3
|
import { relative, resolve, sep } from "node:path";
|
|
4
4
|
import ts from "typescript";
|
|
5
5
|
const builtins = new Set(builtinModules.map((name) => name.replace(/^node:/, "")));
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function packageAdapter(specifier) {
|
|
7
|
+
if (/^@(?:earendil-works|mariozechner)\//.test(specifier))
|
|
8
|
+
return "pi";
|
|
9
|
+
if (/^@deepseek-ai\//.test(specifier))
|
|
10
|
+
return "dsh";
|
|
11
|
+
if (/^(?:claude-code|@anthropic-ai\/[^/]+)(?:\/|$)/.test(specifier))
|
|
12
|
+
return "claude";
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
/** All AST edges enforce boundaries; emitted edges alone determine runtime cycles. */
|
|
16
|
+
export function moduleReferences(source, runtimeOnly = false) {
|
|
17
|
+
if (runtimeOnly) {
|
|
18
|
+
if (source.isDeclarationFile)
|
|
19
|
+
return [];
|
|
20
|
+
const emitted = ts.transpileModule(source.text, { fileName: source.fileName, compilerOptions: { module: ts.ModuleKind.Preserve, target: ts.ScriptTarget.ES2022 } }).outputText;
|
|
21
|
+
source = ts.createSourceFile(source.fileName + ".js", emitted, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
22
|
+
}
|
|
9
23
|
const references = new Set();
|
|
10
24
|
const add = (node) => {
|
|
11
25
|
if (node && ts.isStringLiteralLike(node))
|
|
@@ -28,31 +42,41 @@ export function moduleReferences(source) {
|
|
|
28
42
|
function packageName(specifier) {
|
|
29
43
|
return specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
30
44
|
}
|
|
31
|
-
/** Resolve
|
|
45
|
+
/** Resolve reachable edges, preserving each importing module's core/adapter ownership. */
|
|
32
46
|
export function dependencyViolations(root, entries, options, runtimeDependencies) {
|
|
33
47
|
root = realpathSync(root);
|
|
34
48
|
const violations = [];
|
|
35
49
|
const visited = new Set();
|
|
50
|
+
const runtime = new Map();
|
|
36
51
|
const cache = ts.createModuleResolutionCache(root, (path) => path, options);
|
|
37
52
|
const sourceRoot = resolve(root, "src");
|
|
53
|
+
const rootEntry = resolve(sourceRoot, "index.ts");
|
|
54
|
+
const notesEntry = resolve(sourceRoot, "notes/index.ts");
|
|
38
55
|
const display = (path) => relative(root, path).split(sep).join("/");
|
|
39
|
-
const
|
|
56
|
+
const local = (file) => file.startsWith(sourceRoot + sep) || file.startsWith(resolve(root, "mods/notesoup") + sep);
|
|
57
|
+
const adapter = (file) => {
|
|
58
|
+
const path = display(file);
|
|
59
|
+
return file === rootEntry ? "pi" : /^src\/(pi|claude|dsh)\//.exec(path)?.[1]
|
|
60
|
+
?? (path.startsWith("mods/notesoup/") ? "claude" : packageAdapter(file.split(sep).join("/").split("/node_modules/").at(-1)));
|
|
61
|
+
};
|
|
40
62
|
const walk = (file, chain) => {
|
|
41
63
|
file = realpathSync(file);
|
|
42
|
-
if (native(file)) {
|
|
43
|
-
violations.push([...chain, display(file)].join(" -> "));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
64
|
if (visited.has(file))
|
|
47
65
|
return;
|
|
48
66
|
visited.add(file);
|
|
49
67
|
const here = [...chain, display(file)];
|
|
68
|
+
const owner = adapter(file);
|
|
50
69
|
const source = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.Latest, true);
|
|
70
|
+
const emitted = new Set(local(file) ? moduleReferences(source, true) : []);
|
|
71
|
+
if (local(file))
|
|
72
|
+
runtime.set(file, []);
|
|
51
73
|
for (const specifier of moduleReferences(source)) {
|
|
52
74
|
if (specifier.startsWith("node:") || builtins.has(specifier))
|
|
53
75
|
continue;
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
const sdk = packageAdapter(specifier);
|
|
77
|
+
if (sdk) {
|
|
78
|
+
if (owner !== sdk)
|
|
79
|
+
violations.push([...here, specifier].join(" -> "));
|
|
56
80
|
continue;
|
|
57
81
|
}
|
|
58
82
|
const resolution = ts.resolveModuleName(specifier, file, options, ts.sys, cache).resolvedModule;
|
|
@@ -60,14 +84,40 @@ export function dependencyViolations(root, entries, options, runtimeDependencies
|
|
|
60
84
|
violations.push([...here, `unresolved ${specifier}`].join(" -> "));
|
|
61
85
|
continue;
|
|
62
86
|
}
|
|
63
|
-
|
|
64
|
-
|
|
87
|
+
const target = realpathSync(resolution.resolvedFileName);
|
|
88
|
+
const targetOwner = adapter(target);
|
|
89
|
+
if (target === rootEntry || (targetOwner && targetOwner !== owner) ||
|
|
90
|
+
(owner && target.startsWith(resolve(sourceRoot, "notes") + sep) && target !== notesEntry) ||
|
|
91
|
+
(owner === "dsh" && target.startsWith(resolve(sourceRoot, "dream") + sep))) {
|
|
92
|
+
violations.push([...here, display(target)].join(" -> "));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Core dependencies must be intentional, not accidentally supplied by a host.
|
|
96
|
+
if (!owner && file.startsWith(sourceRoot + sep) && resolution.isExternalLibraryImport && !runtimeDependencies.has(packageName(specifier))) {
|
|
65
97
|
violations.push([...here, `undeclared runtime dependency ${specifier}`].join(" -> "));
|
|
66
98
|
}
|
|
67
|
-
|
|
99
|
+
if (emitted.has(specifier) && local(target))
|
|
100
|
+
runtime.get(file).push(target);
|
|
101
|
+
if (!targetOwner || local(target))
|
|
102
|
+
walk(target, here);
|
|
68
103
|
}
|
|
69
104
|
};
|
|
70
105
|
for (const entry of entries)
|
|
71
106
|
walk(resolve(root, entry), []);
|
|
107
|
+
const checked = new Set();
|
|
108
|
+
const cycles = (file, path) => {
|
|
109
|
+
const start = path.indexOf(file);
|
|
110
|
+
if (start >= 0) {
|
|
111
|
+
violations.push(`runtime cycle: ${[...path.slice(start), file].map(display).join(" -> ")}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (checked.has(file))
|
|
115
|
+
return;
|
|
116
|
+
checked.add(file);
|
|
117
|
+
for (const target of runtime.get(file) ?? [])
|
|
118
|
+
cycles(target, [...path, file]);
|
|
119
|
+
};
|
|
120
|
+
for (const file of runtime.keys())
|
|
121
|
+
cycles(file, []);
|
|
72
122
|
return violations;
|
|
73
123
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type Behavior = {
|
|
2
|
+
text: string;
|
|
3
|
+
inputTokens?: number;
|
|
4
|
+
} | {
|
|
5
|
+
tool: string;
|
|
6
|
+
input: unknown;
|
|
7
|
+
inputTokens?: number;
|
|
8
|
+
} | {
|
|
9
|
+
error: string;
|
|
10
|
+
};
|
|
11
|
+
export type WireRequest = {
|
|
12
|
+
system?: string | {
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
messages: {
|
|
16
|
+
role: string;
|
|
17
|
+
content: unknown;
|
|
18
|
+
}[];
|
|
19
|
+
tools?: {
|
|
20
|
+
name: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
/** Same Messages/SSE approach as /tmp/dsh-spike/mock/llm-server.mjs; no credentials or external traffic. */
|
|
24
|
+
export declare function messagesServer(): Promise<{
|
|
25
|
+
requests: WireRequest[];
|
|
26
|
+
script: Behavior[];
|
|
27
|
+
url: string;
|
|
28
|
+
close: () => Promise<void>;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
/** Same Messages/SSE approach as /tmp/dsh-spike/mock/llm-server.mjs; no credentials or external traffic. */
|
|
3
|
+
export async function messagesServer() {
|
|
4
|
+
const requests = [];
|
|
5
|
+
const script = [];
|
|
6
|
+
const server = createServer(async (request, response) => {
|
|
7
|
+
let body = "";
|
|
8
|
+
for await (const chunk of request)
|
|
9
|
+
body += chunk;
|
|
10
|
+
if (request.method !== "POST" || !request.url?.endsWith("/messages")) {
|
|
11
|
+
response.writeHead(404).end();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
requests.push(JSON.parse(body));
|
|
15
|
+
const behavior = script.shift() ?? { text: "finished" };
|
|
16
|
+
if ("error" in behavior) {
|
|
17
|
+
response.writeHead(400, { "content-type": "application/json" }).end(JSON.stringify({ type: "error", error: { type: "invalid_request_error", message: behavior.error } }));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
response.writeHead(200, { "content-type": "text/event-stream" });
|
|
21
|
+
const send = (value) => response.write(`event: ${value.type}\ndata: ${JSON.stringify(value)}\n\n`);
|
|
22
|
+
send({ type: "message_start", message: { id: `msg-${requests.length}`, type: "message", role: "assistant", model: "mock", content: [], usage: { input_tokens: behavior.inputTokens ?? 10, output_tokens: 0 } } });
|
|
23
|
+
const tool = "tool" in behavior;
|
|
24
|
+
send({ type: "content_block_start", index: 0, content_block: tool ? { type: "tool_use", id: `call-${requests.length}`, name: behavior.tool, input: {} } : { type: "text", text: "" } });
|
|
25
|
+
send({ type: "content_block_delta", index: 0, delta: tool ? { type: "input_json_delta", partial_json: JSON.stringify(behavior.input) } : { type: "text_delta", text: behavior.text } });
|
|
26
|
+
send({ type: "content_block_stop", index: 0 });
|
|
27
|
+
send({ type: "message_delta", delta: { stop_reason: tool ? "tool_use" : "end_turn", stop_sequence: null }, usage: { output_tokens: 20 } });
|
|
28
|
+
send({ type: "message_stop" });
|
|
29
|
+
response.end();
|
|
30
|
+
});
|
|
31
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
32
|
+
return { requests, script, url: `http://127.0.0.1:${server.address().port}`, close: () => new Promise((resolve, reject) => { server.closeAllConnections(); server.close((error) => error ? reject(error) : resolve()); }) };
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TestContext } from "node:test";
|
|
2
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import { type SessionEvent } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import NotesoupEngine, { type EngineConfig } from "../../src/dsh/engine.js";
|
|
5
|
+
export declare function dshFixture(t: TestContext, config?: EngineConfig): Promise<{
|
|
6
|
+
ctx: Context;
|
|
7
|
+
engine: NotesoupEngine;
|
|
8
|
+
engineFiber: import("@deepseek-ai/cordis").Fiber;
|
|
9
|
+
directory: string;
|
|
10
|
+
mock: {
|
|
11
|
+
requests: import("./dsh-messages.js").WireRequest[];
|
|
12
|
+
script: import("./dsh-messages.js").Behavior[];
|
|
13
|
+
url: string;
|
|
14
|
+
close: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
create: (seed?: readonly SessionEvent[], id?: string) => Promise<import("@deepseek-ai/dsh-agent").Agent>;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
6
|
+
import Agents from "@deepseek-ai/dsh-agent";
|
|
7
|
+
import AgentLoop from "@deepseek-ai/dsh-agent-loop";
|
|
8
|
+
import Llm from "@deepseek-ai/dsh-llm";
|
|
9
|
+
import * as DeepSeek from "@deepseek-ai/dsh-llm-deepseek-api-key";
|
|
10
|
+
import Sessions, { SessionId } from "@deepseek-ai/dsh-session";
|
|
11
|
+
import Projections from "@deepseek-ai/dsh-session-projection";
|
|
12
|
+
import SystemPrompt from "@deepseek-ai/dsh-system-prompt";
|
|
13
|
+
import Tools from "@deepseek-ai/dsh-tools";
|
|
14
|
+
import Meter from "@deepseek-ai/dsh-token-meter";
|
|
15
|
+
import Query from "@deepseek-ai/dsh-session-query-sqlite";
|
|
16
|
+
import { createLaunchEnvironmentSnapshot } from "@deepseek-ai/dsh-launch-environment";
|
|
17
|
+
import NotesoupEngine from "../../src/dsh/engine.js";
|
|
18
|
+
import notesoup from "../../src/dsh/index.js";
|
|
19
|
+
import { messagesServer } from "./dsh-messages.js";
|
|
20
|
+
export async function dshFixture(t, config = {}) {
|
|
21
|
+
const directory = await mkdtemp(join(tmpdir(), "ns-dsh-test-"));
|
|
22
|
+
const mock = await messagesServer();
|
|
23
|
+
const ctx = new Context();
|
|
24
|
+
const fibers = [];
|
|
25
|
+
t.after(async () => { for (const fiber of fibers.reverse())
|
|
26
|
+
await fiber.dispose(); await mock.close(); await ctx.fiber.dispose(); await rm(directory, { recursive: true, force: true }); });
|
|
27
|
+
ctx.provide("launchEnvironment", createLaunchEnvironmentSnapshot([{ source: "process", values: { DEEPSEEK_API_KEY: "mock-key" } }]));
|
|
28
|
+
fibers.push(await ctx.plugin(Sessions));
|
|
29
|
+
fibers.push(await ctx.plugin(Projections));
|
|
30
|
+
fibers.push(await ctx.plugin(Agents));
|
|
31
|
+
fibers.push(await ctx.plugin(Llm));
|
|
32
|
+
fibers.push(await ctx.plugin(SystemPrompt, { includeRuntimeContext: false }));
|
|
33
|
+
fibers.push(await ctx.plugin(Tools, {}));
|
|
34
|
+
fibers.push(await ctx.plugin(Meter, {}));
|
|
35
|
+
fibers.push(await ctx.plugin(Query, { path: ":memory:" }));
|
|
36
|
+
fibers.push(await ctx.plugin(DeepSeek, { baseURL: mock.url, models: [{ id: "mock-flash", name: "Mock", contextWindow: 200000, maxTokens: 8192 }] }));
|
|
37
|
+
const engineFiber = await ctx.plugin(NotesoupEngine, { notesHome: join(directory, "notes"), ...config });
|
|
38
|
+
fibers.push(engineFiber);
|
|
39
|
+
assert.ok(ctx.compaction instanceof NotesoupEngine);
|
|
40
|
+
const engine = ctx.compaction;
|
|
41
|
+
fibers.push(await ctx.plugin(notesoup));
|
|
42
|
+
fibers.push(await ctx.plugin(AgentLoop, { agents: [], maxParallelToolCalls: 10 }));
|
|
43
|
+
let count = 0;
|
|
44
|
+
const create = async (seed, id = `session-test-${++count}`) => {
|
|
45
|
+
const handle = await ctx.agents.create({ sessionId: SessionId(id), meta: { cwd: directory }, agentOptions: { provider: "deepseek-official", model: "mock-flash" }, ...(seed ? { seed } : {}) });
|
|
46
|
+
fibers.push(handle);
|
|
47
|
+
return handle.agent;
|
|
48
|
+
};
|
|
49
|
+
return { ctx, engine, engineFiber, directory, mock, create };
|
|
50
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notesIdentityFromPi } from "../../src/pi/notes/adapter.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
|
|
3
3
|
import assert from "node:assert/strict";
|
|
4
4
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -135,7 +135,7 @@ export function makeExtension(sessionManager, settingsManager) {
|
|
|
135
135
|
}
|
|
136
136
|
export async function explicitBoot(ctx, currentWindowId, previousWindowId) {
|
|
137
137
|
return renderBootBlock({
|
|
138
|
-
tools:
|
|
138
|
+
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
139
139
|
agentName: agentSlug(),
|
|
140
140
|
modelName: modelSlug(ctx),
|
|
141
141
|
firstWindowId: rootWindowId(ctx.sessionManager.getSessionId()),
|
|
@@ -191,6 +191,11 @@ test("shared note operations return canonical outcomes with a body-only read win
|
|
|
191
191
|
}));
|
|
192
192
|
assert.equal(updated.change_kind, "body");
|
|
193
193
|
assert.equal(updated.diff, "caller-rendered-diff");
|
|
194
|
+
const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] }, notesIdentity));
|
|
195
|
+
assert.equal(defaultReceipt.diff, "note body");
|
|
196
|
+
const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] }, notesIdentity));
|
|
197
|
+
assert.equal(unchanged.change_kind, "none");
|
|
198
|
+
assert.equal(unchanged.diff, "");
|
|
194
199
|
// Frontmatter is metadata, not body: the window addresses the body and counts only the body.
|
|
195
200
|
const stored = await createNotesStore(notesIdentity).read("@project/test.md");
|
|
196
201
|
assert.ok(stored, "the note is on disk");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_BOOT_TOOL_NAMES } from "../src/boot/text.js";
|
|
3
3
|
import assert from "node:assert/strict";
|
|
4
4
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname } from "node:path";
|
|
@@ -179,7 +179,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
179
179
|
});
|
|
180
180
|
assert.deepEqual([...calls.entries()], [["session", 1], ["project", 1], ["human", 1], ["agent", 1], ["model", 1]], "each selected home is loaded exactly once");
|
|
181
181
|
const renderData = {
|
|
182
|
-
tools:
|
|
182
|
+
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
183
183
|
agentName: "root",
|
|
184
184
|
modelName: "default",
|
|
185
185
|
firstWindowId: "pcw:test:root",
|
|
@@ -237,7 +237,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
237
237
|
});
|
|
238
238
|
assert.deepEqual(oneFailed.unavailable.map((home) => home.label), ["@human"]);
|
|
239
239
|
const oneFailedText = renderBootBlock({
|
|
240
|
-
tools:
|
|
240
|
+
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
241
241
|
agentName: "root",
|
|
242
242
|
modelName: "default",
|
|
243
243
|
firstWindowId: "pcw:test:root",
|
|
@@ -252,7 +252,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
252
252
|
});
|
|
253
253
|
assert.equal(allFailed.unavailable.length, 5);
|
|
254
254
|
const allFailedText = renderBootBlock({
|
|
255
|
-
tools:
|
|
255
|
+
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
256
256
|
agentName: "root",
|
|
257
257
|
modelName: "default",
|
|
258
258
|
firstWindowId: "pcw:test:root",
|
package/dist/test/notes.test.js
CHANGED
|
@@ -13,7 +13,7 @@ import { join } from "node:path";
|
|
|
13
13
|
import test from "node:test";
|
|
14
14
|
import { Check } from "typebox/value";
|
|
15
15
|
import { parseNote } from "../src/notes/frontmatter.js";
|
|
16
|
-
import { projectKey } from "../src/notes/
|
|
16
|
+
import { projectKey } from "../src/notes/index.js";
|
|
17
17
|
import { globToRegExp } from "../src/notes/address.js";
|
|
18
18
|
import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
|
|
19
19
|
import { notesList, notesSearch } from "../src/tools/notes.js";
|
package/docs/architecture.md
CHANGED
|
@@ -16,6 +16,7 @@ notesoup uses Pi's session branch as the durable source of truth. It does not ma
|
|
|
16
16
|
| `tools/notes.ts`, `tools/history.ts`, `tools/schema.ts`, `tools/result.ts`, `tools/output.ts` | Schema-derived outcomes, note/history operations, bounded result selection and pure text rendering | Explicit identity/projection; one bounded result feeds both text and structured output |
|
|
17
17
|
| `settings.ts`, `dream/settings.ts` | Settings keys, per-key merge and dreamer validation | Parsed values only; no SDK or I/O |
|
|
18
18
|
| `dream/` | Jail, crumpled-only physical deletion, locks, gates, Git audit, doctor, playbook and result/report logic | Independent filesystem/policy functions; no reverse import into Pi |
|
|
19
|
+
| `dsh/` | Cordis registration, frozen prompt sections, plugin records/checkpoint recovery, token-meter budget, native reset transaction and session-query decoding | Host adapter; imports shared domains, never Pi or Claude |
|
|
19
20
|
| `pi/extension.ts`, `pi/runtime.ts` | Compose registration, lifecycle hooks, commands, provider operations and UI | Public Pi SDK |
|
|
20
21
|
| `pi/entries.ts` | Persisted native custom-entry/message tags | Pi persistence vocabulary, not an omnibus protocol barrel |
|
|
21
22
|
| `pi/window.ts`, `pi/session-reader.ts` | Native `WindowMarker`, checkpoint validation, root/fork identity, branch scans, provider projection and usage | Pi entries/messages and read-only native session traversal |
|
|
@@ -26,10 +27,12 @@ notesoup uses Pi's session branch as the durable source of truth. It does not ma
|
|
|
26
27
|
| `pi/reset/artifacts.ts`, `pi/reset/committed.ts` | Construct boundaries, repair only safe suffixes, independently confirm committed native boundaries | Active native branch; no shadow commit database |
|
|
27
28
|
| `pi/dream/` | Pi dream sessions, native tool wrappers, settings reads and executable CLI composition | Pi backend over independent dream policy/filesystem functions |
|
|
28
29
|
|
|
29
|
-
Dependencies flow from
|
|
30
|
+
Dependencies flow from host composition into the domains, never back. Shared code cannot import an SDK, `src/pi`, `src/claude`, `src/dsh`, or the root entry, even through erased types, re-exports, literal dynamic/import-type edges or intermediate modules. `test/dependencies.test.ts` uses TypeScript resolution and AST traversal, checks every shared source (including root settings/text matching; excludes the three host adapters), and tests rejecting indirect/aliased paths. Shared external packages must be declared in the package manifest. `typebox` is declared as a peer and development dependency rather than imported through Pi's SDK.
|
|
30
31
|
|
|
31
32
|
The configured extension is `src/index.ts`, loaded straight from TypeScript — no bundling step, so git installs work without a build. Its `pi-ai/utils/estimate` dependency is vendored in `src/pi/estimate.ts` because Pi's root-package aliases misresolve that public subpath on source loads; host-owned SDK APIs stay external. `/notes` is the intentional standalone library API. The CLI is `dist/src/pi/dream/cli.js`. Old internal bags, `NotesContext`, root history helpers and the deep-entry export alias are removed. This breaks source/import paths, not storage: note homes, metadata, session paths and raw history remain intact. There is no universal Harness, host-event emulator, registry, daemon or speculative second backend. No `src/window` exists because the current window responsibilities are genuinely native.
|
|
32
33
|
|
|
34
|
+
For the native dsh reset transaction, prompt ordering, capability checks and limits, see [DeepSeek Harness](dsh.md). Its adapter keeps the shared domains unchanged and uses only dsh public services.
|
|
35
|
+
|
|
33
36
|
## State and persistence
|
|
34
37
|
|
|
35
38
|
`pi/reset/lifecycle.ts` is the sole `turn_end` composer: it accepts incoming drafts, drains budget-owned guidance/warning drafts, and appends a reset boundary for an explicit tool request or the hard-reserve safety path. Manual and budget close-outs stay armed across note/tool turns and commit from `agent_before_settle` after a successful stop with queued work drained; a manual close-out stops the run while a budget close-out continues in the fresh window. Repeated requests for the same window deduplicate. See [reset lifecycle](reset-lifecycle.md).
|
package/docs/dsh.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# DeepSeek Harness adapter
|
|
2
|
+
|
|
3
|
+
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh notebook when context runs low: frozen boot text, the five notes homes, eight notes/history tools, `get_context_remaining`, and `clear_memory`. A reset makes **zero model calls**. The old conversation leaves the model surface and remains in the session log for history reads. Dream is not registered on dsh.
|
|
4
|
+
|
|
5
|
+
Install the package in your chosen dsh profile with `dsh plugin --profile <profile> add notesoup`, then copy the model declaration from [the profile patch example](dsh.profile.patch.yml) into `$DSH_HOME/profiles/<profile>/cordis.patch.yml`. The package bundle patch disables `compaction-basic` and inserts `notesoup-engine` and `notesoup`. Do not duplicate those rows when adding the model declaration. A source checkout needs `npm ci --ignore-scripts` and `npm run build`; use absolute `file:///.../dist/src/dsh/engine.js` and `file:///.../dist/src/dsh/index.js` module names. The example shows all rows for a profile assembled without the package bundle.
|
|
6
|
+
|
|
7
|
+
Declare explicit `models` for `llm-deepseek`, with `contextWindow` and `maxTokens` appropriate to your provider. The shipped `deepseek-flash` declaration uses `systemPromptUpdate: in-history`; changing the boot under that route can leave an earlier system prompt in the leading slot. The example uses **200000 context tokens and 8192 output tokens**. Those numbers are test inputs, not a promise about your provider's capacity.
|
|
8
|
+
|
|
9
|
+
On load and before requests, preflight probes `systemPrompt.section`, `tools.register`, `sessionQuery.readSession`, `tokenMeter.measure`, and `llm.resolveModelInfo`. It requires our compaction service and its automatic listener. It inspects public loader entries when available and rejects an enabled `compaction-basic` row or registered `BasicCompactionEngine` fiber. An error names the row or capability to fix. Peer dependencies use `*`, so a newer preview is tested by capability rather than silently skipped by an upper version bound. Cordis can contain a plugin-load failure and continue loading other plugins: inspect startup errors before using a profile.
|
|
10
|
+
|
|
11
|
+
## Notes, boot and history
|
|
12
|
+
|
|
13
|
+
`notesHome` defaults to `~/.agents/notes`; `agentName` defaults to `dsh`. The filesystem layout and addressing match Pi and Claude: bare paths are session notes, with `@project`, `@human`, `@self`, and `@model` durable homes. Project identity uses the shared `resolveProjectHome(cwd, notesHome)` resolver: readable slug homes with a `.project` marker, including repository/worktree and origin identity. Other marked projects are readable through `@projects/<name>/`; named-home reads do not update access metadata and named-home writes are refused. Receipts, boot protocol (including MAP Cheatsheets), and bounds come from the shared modules, not dsh copies. A model change changes subsequent tools' `@model` identity; the boot remains frozen until reset.
|
|
14
|
+
|
|
15
|
+
The boot is a `systemPrompt.section` at order **2450**, with `interpolate: false`. Shared snapshot/render functions read the five homes once, using a captured timestamp. Rendering is deterministic for those inputs. A `plugin:notesoup/window` record stores the ordinal, id, timestamp, digest and exact boot text. `agent/created` adopts it before the first assembly. Notes written later appear in the next window's boot. Missing records reconstruct from the notesoup compact checkpoint, or from the marked root system section. Neither path rereads notes or regenerates a summary. Records are informational; checkpoints control the model surface.
|
|
16
|
+
|
|
17
|
+
`history_windows`, `history_list`, and `history_read` obtain the full raw log through `ctx.sessionQuery.readSession`, then feed the shared pairing, paging and literal-search operations. Public history seq **1** is native dsh seq **0**; always use the seq a notesoup tool returns. A fork's selected seed prefix is available in its history; no sibling or parent suffix is fetched. Tool results are paired at their call seq. Text blocks are verbatim; other recorded blocks are shown as JSON. These tools browse one session, not the host's entire session corpus.
|
|
18
|
+
|
|
19
|
+
## Reset and budget
|
|
20
|
+
|
|
21
|
+
The engine owns the compaction transaction, rather than inheriting a summarizer. It validates the complete balanced surface span at positions **1..last**, acquires `compaction/start`, loads and mints the new notebook, writes `compaction/summary` and the replacement checkpoint synchronously, closes with `compaction/end`, then appends the window record. Node **0** stays host-owned. Nothing from the old conversation is retained on the surface. The checkpoint contains only the frozen boot and continuation protocol. A one-message span can reset even when its replacement is larger.
|
|
22
|
+
|
|
23
|
+
Cancellation or a snapshot/checkpoint failure before replacement restores the old notebook. If replacement has already landed, it is authoritative even if closing or flushing fails; rolling back then would send stale boot text. An unmatched close keeps the durable lock until reload. A lost window record is recoverable from the checkpoint. Manual `compactNow` uses host maintenance and flushes through `ctx.sessions.flush`; the host `/compact` command, when installed, therefore uses this reset engine too.
|
|
24
|
+
|
|
25
|
+
Automatic resets run in the awaited prompt-assembly waterfall. Assembly happens before `agent/pre-step`, so the adapter refreshes its accepted section after reset to make the same request carry the new boot. It never adopts a window in pre-step; that listener always delegates with `return next()`.
|
|
26
|
+
|
|
27
|
+
The host-owned reset line is:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
resetAt = floor(min(contextWindow * thresholdRatio,
|
|
31
|
+
contextWindow - maxTokens - headroomTokens))
|
|
32
|
+
reserve = contextWindow - resetAt
|
|
33
|
+
warning = reserve + 16384
|
|
34
|
+
reminder = reserve + reminderMarginTokens
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining` subtracts the warning line and clamps at zero. Missing model capacity returns null. A profile with no positive reset budget fails with `BUDGET_CONFIG` and the numbers to fix. No independent percentage cutoff is added by notesoup.
|
|
38
|
+
|
|
39
|
+
The adapter uses `tokenMeter.measure`, model context from `resolveModelInfo`, and the mounted engine's resolved `config`. Alpha.2 keeps an old provider-usage anchor across surface replacement; until the fresh window has a response, notesoup uses the meter's current `surfaceTokens` plus its public tool-schema estimator instead of that stale anchor.
|
|
40
|
+
|
|
41
|
+
The reminder and close-out warning go through `agent.steer`. Close-out remains an instruction to write notes and call `clear_memory`; a normal stop alone does not consume the warning runway. `clear_memory` arms a reset after the entire tool batch. Independently, reaching the hard reserve resets at assembly or a successful stopping boundary and continues from the notes. Abort and ordinary errors drop the pending tool request. `auto: false` disables reminders and reserve resets while keeping explicit `clear_memory` and the listener installed.
|
|
42
|
+
|
|
43
|
+
## What this does not promise
|
|
44
|
+
|
|
45
|
+
| Limit | What to expect / next step |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| dsh versions | Tested against **0.2.1-alpha.2**. Capability checks do not establish wire or persistence compatibility with every newer preview. Run the scripted tests before upgrading. |
|
|
48
|
+
| Model calls per reset | **0** auxiliary model calls. The agent's note-writing turns and fresh-window continuation still make ordinary calls. |
|
|
49
|
+
| Retention | Surface node **0**, one boot/continuation checkpoint, and subsequent messages. An unfinished tool batch postpones reset; no partial tool pairs are discarded. |
|
|
50
|
+
| Boot bounds | Up to **4096 code points per MAP** and **3 recent notes per home**, from the shared renderer. Slim large MAPs; follow note addresses for full bodies. |
|
|
51
|
+
| Tool output | Shared **32 KiB** bounds; use `next_offset_chars`, history cursors, or narrower filters. There is no unbounded hidden result. |
|
|
52
|
+
| Warning timing | Steering enters the next step; a large current response/tool batch can spend the runway. The hard reserve protects the next balanced boundary, not an in-flight provider call. |
|
|
53
|
+
| Unknown capacity | Countdown is **null** and automatic reserve checks skip. Add `models[].contextWindow` to `llm-deepseek`; explicit resets still work. |
|
|
54
|
+
| Storage | Raw log remains available while the host keeps it. Notesoup does not back up session files or guarantee that an unflushed append survives a crash. |
|
|
55
|
+
| Plugin records | Best-effort across dsh migrations. Missing records recover from native checkpoints/root system text; unknown future record or checkpoint formats are not migrated by notesoup. |
|
|
56
|
+
| Tools and errors | Full shared TypeBox validation runs in the adapter because dsh supports a smaller schema subset. Expected operation errors become dsh failures with the shared code; successes use the shared bounded value and renderer. |
|
|
57
|
+
| Notifications and commands | No custom UI notifications, settings card, runtime toggle or `/clear-memory` alias is installed. Configure engine rows in the profile/home patch; call `clear_memory` or the host's `/compact`. |
|
|
58
|
+
| Untested host features | Real providers, reasoning/image wire behavior, cache metrics, actual context-overflow retry, HMR, migrations, ACP/Web/SDK profiles and large histories are not established by the scripted tests. |
|
|
59
|
+
| Dream | **No dsh dream backend or dream skill registration.** Use the existing supported host workflow. |
|
|
60
|
+
|
|
61
|
+
Run `npm run typecheck` and `npm test` from a checkout. The dsh tests drive the actual loop and tools with a local Messages/SSE server, temporary notes homes and the SQLite session query service. The compaction parity test runs the installed `BasicCompactionEngine` and our own engine through open-turn and idle success paths and a rejected-checkpoint path. It pins native event/result fields, replacement references, and node-zero preservation; it names the intentional differences (Basic's LLM call fields and retained tail, notesoup's model-free template and ignorable window record). Other tests pin codes, token values, window ordinals and request content rather than prose.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Add to $DSH_HOME/profiles/<profile>/cordis.patch.yml after installing notesoup.
|
|
2
|
+
# For a source checkout, run npm ci --ignore-scripts && npm run build, then replace
|
|
3
|
+
# notesoup/dsh[/engine] below with absolute file:///.../dist/src/dsh/...js paths.
|
|
4
|
+
- id: compaction-basic
|
|
5
|
+
disabled: true
|
|
6
|
+
|
|
7
|
+
# Explicit models avoid the shipped deepseek-flash in-history prompt update.
|
|
8
|
+
# Choose capacity and output limits for your provider; these are the tested values.
|
|
9
|
+
- id: llm-deepseek
|
|
10
|
+
name: '@deepseek-ai/dsh-llm-deepseek-api-key'
|
|
11
|
+
config:
|
|
12
|
+
models:
|
|
13
|
+
- id: deepseek-flash
|
|
14
|
+
name: DeepSeek Flash
|
|
15
|
+
contextWindow: 200000
|
|
16
|
+
maxTokens: 8192
|
|
17
|
+
|
|
18
|
+
- id: agent-default-model
|
|
19
|
+
config:
|
|
20
|
+
provider: deepseek-official
|
|
21
|
+
model: deepseek-flash
|
|
22
|
+
|
|
23
|
+
- insert:
|
|
24
|
+
- id: notesoup-engine
|
|
25
|
+
name: 'notesoup/dsh/engine'
|
|
26
|
+
config:
|
|
27
|
+
auto: true
|
|
28
|
+
thresholdRatio: 0.7
|
|
29
|
+
headroomTokens: 32768
|
|
30
|
+
reminderMarginTokens: 24576
|
|
31
|
+
agentName: dsh
|
|
32
|
+
# notesHome: /absolute/path/to/notes
|
|
33
|
+
- id: notesoup
|
|
34
|
+
name: 'notesoup/dsh'
|