notesoup 0.53.2 → 0.54.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 +6 -4
- package/dist/plugins/claude/src/helper.d.ts +2 -1
- package/dist/plugins/claude/src/helper.js +21 -24
- package/dist/plugins/claude/src/history.d.ts +3 -14
- package/dist/plugins/claude/src/history.js +2 -298
- package/dist/plugins/claude/src/text.d.ts +0 -1
- package/dist/plugins/claude/src/text.js +0 -1
- package/dist/plugins/codex/src/history.d.ts +3 -8
- package/dist/plugins/codex/src/history.js +2 -238
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +9 -8
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/codex/src/transcript.d.ts +3 -39
- package/dist/plugins/codex/src/transcript.js +2 -313
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/history.d.ts +3 -0
- package/dist/plugins/dsh/history.js +15 -0
- package/dist/plugins/dsh/tools.js +12 -12
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +9 -5
- package/dist/plugins/pi/history.d.ts +2 -3
- package/dist/plugins/pi/history.js +4 -147
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/runtime.js +2 -2
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +9 -11
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +5 -3
- package/dist/src/boot/text.js +18 -10
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/history/claude.d.ts +16 -0
- package/dist/src/history/claude.js +336 -0
- package/dist/src/history/codex-transcript.d.ts +39 -0
- package/dist/src/history/codex-transcript.js +315 -0
- package/dist/src/history/codex.d.ts +8 -0
- package/dist/src/history/codex.js +238 -0
- package/dist/src/history/corpus.d.ts +35 -0
- package/dist/src/history/corpus.js +54 -0
- package/dist/src/history/history.d.ts +4 -8
- package/dist/src/history/history.js +3 -11
- package/dist/src/history/local.d.ts +17 -0
- package/dist/src/history/local.js +101 -0
- package/dist/src/history/pi.d.ts +36 -0
- package/dist/src/history/pi.js +202 -0
- package/dist/src/history/query.d.ts +15 -5
- package/dist/src/history/query.js +42 -13
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.js +6 -4
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/history.d.ts +7 -19
- package/dist/src/tools/history.js +80 -93
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/boot.integration.test.js +2 -3
- package/dist/test/claude-history.test.js +47 -34
- package/dist/test/claude-mod.test.js +96 -50
- package/dist/test/codex-history.test.js +4 -10
- package/dist/test/codex-plugin.test.js +50 -12
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +73 -6
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +88 -19
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -1
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/helpers/history-corpus.d.ts +7 -0
- package/dist/test/helpers/history-corpus.js +26 -0
- package/dist/test/history-corpus.test.js +307 -0
- package/dist/test/history.integration.test.js +40 -48
- package/dist/test/host-neutral.test.js +20 -33
- package/dist/test/model-facing-text.test.js +14 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +73 -24
- package/dist/test/notes.test.js +51 -21
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/docs/architecture.md +19 -12
- package/docs/claude-code-mod.md +7 -5
- package/docs/codex.md +6 -6
- package/docs/dsh.md +9 -9
- package/docs/history-sessions.md +52 -0
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +14 -8
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +2164 -1341
- package/plugins/claude/hooks/register.ts +19 -11
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +9 -7
- package/plugins/claude/src/helper.ts +22 -25
- package/plugins/claude/src/history.ts +3 -257
- package/plugins/claude/src/text.ts +0 -1
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +1582 -969
- package/plugins/codex/src/history.ts +3 -193
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +9 -8
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/codex/src/transcript.ts +3 -275
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/history.ts +17 -0
- package/plugins/dsh/tools.ts +12 -12
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +159 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/history-tools.ts +11 -5
- package/plugins/pi/history.ts +8 -157
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/runtime.ts +2 -2
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +9 -7
- package/src/boot/render.ts +10 -13
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +18 -10
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/history/claude.ts +286 -0
- package/src/history/codex-transcript.ts +276 -0
- package/src/history/codex.ts +193 -0
- package/src/history/corpus.ts +69 -0
- package/src/history/history.ts +5 -12
- package/src/history/local.ts +93 -0
- package/src/history/pi.ts +199 -0
- package/src/history/query.ts +45 -15
- package/src/index.ts +8 -5
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/history.ts +71 -101
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
package/dist/test/dsh.test.js
CHANGED
|
@@ -6,11 +6,12 @@ import { allItems, contentText } from "../src/history/history.js";
|
|
|
6
6
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
-
import {
|
|
9
|
+
import { resolveProjectNamespace } from "../src/notes/project-namespace.js";
|
|
10
10
|
import { renderBootBlock } from "../src/boot/render.js";
|
|
11
11
|
import { loadNotesSnapshot } from "../src/boot/snapshot.js";
|
|
12
12
|
import { WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG } from "../src/boot/text.js";
|
|
13
13
|
import { notesRead } from "../src/tools/notes.js";
|
|
14
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
14
15
|
import { success } from "../src/tools/result.js";
|
|
15
16
|
import { createNotesStore } from "../src/notes/index.js";
|
|
16
17
|
import { dshFixture } from "./helpers/dsh.js";
|
|
@@ -20,12 +21,34 @@ import { measureBudget } from "../plugins/dsh/budget.js";
|
|
|
20
21
|
import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, NORMAL_CONTINUATIONS } from "../src/budget/text.js";
|
|
21
22
|
import { preflight } from "../plugins/dsh/engine.js";
|
|
22
23
|
import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
|
|
24
|
+
import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
|
|
23
25
|
function prompt(text) { return createUserMessage({ content: [{ type: "text", text }], source: { kind: "user" } }); }
|
|
24
26
|
async function run(agent, text) { agent.followup(prompt(text)); await agent.whenIdle(); }
|
|
25
27
|
function system(request) { return typeof request.system === "string" ? request.system : request.system?.map((block) => block.text).join("\n") ?? ""; }
|
|
26
28
|
function code(expected) { return (error) => error?.code === expected; }
|
|
27
29
|
// Critical lifecycle tests exercise the actual loop, DeepSeek HTTP adapter, tool registry,
|
|
28
30
|
// token meter and SQLite query service. Only the provider is a scripted Messages server.
|
|
31
|
+
test("dsh registered tools query other DSH sessions and foreign Pi files through the same session surface", async (t) => {
|
|
32
|
+
const { ctx, create, directory } = await dshFixture(t);
|
|
33
|
+
const roots = isolateHistoryRoots(t, directory);
|
|
34
|
+
await writePiTranscript(roots.pi, "foreign-pi");
|
|
35
|
+
const reader = await create(undefined, "reader"), target = await create(undefined, "target");
|
|
36
|
+
target.session.append("user/message", prompt("DSH needle"), { surfaceOp: "append" });
|
|
37
|
+
const invoke = (name, args) => ctx.tools.execute({ name, arguments: args, agent: reader, callId: ToolCallId("cross-session"), signal: new AbortController().signal });
|
|
38
|
+
const listed = await invoke("history_list", { session: "dsh:tar", query: "needle" });
|
|
39
|
+
assert.equal(listed.isError, false, JSON.stringify(listed));
|
|
40
|
+
const page = listed.value;
|
|
41
|
+
assert.equal(page.items[0].session, "dsh:target");
|
|
42
|
+
const read = await invoke("history_read", { session: page.items[0].session, seq: page.items[0].seq });
|
|
43
|
+
assert.equal(read.isError, false);
|
|
44
|
+
assert.equal(read.value.text, "DSH needle");
|
|
45
|
+
const foreign = await invoke("history_read", { session: "pi:foreign", seq: 1 });
|
|
46
|
+
assert.equal(foreign.isError, false);
|
|
47
|
+
assert.equal(foreign.value.session, "pi:foreign-pi");
|
|
48
|
+
const across = await invoke("history_list", { session: "*", query: "needle" });
|
|
49
|
+
assert.equal(across.isError, false, JSON.stringify(across));
|
|
50
|
+
assert.deepEqual(new Set(across.value.items.map((item) => item.session)), new Set(["dsh:target", "pi:foreign-pi"]));
|
|
51
|
+
});
|
|
29
52
|
test("dsh boot freezes across note writes, rotates before the next wire request, and keeps raw history", async (t) => {
|
|
30
53
|
const { ctx, engine, create, mock } = await dshFixture(t);
|
|
31
54
|
const agent = await create();
|
|
@@ -58,20 +81,20 @@ test("dsh boot freezes across note writes, rotates before the next wire request,
|
|
|
58
81
|
assert.ok(mock.requests[0].tools?.some((tool) => tool.name === "history_list"));
|
|
59
82
|
assert.equal(mock.requests[0].tools?.some((tool) => tool.name === "dream"), false);
|
|
60
83
|
});
|
|
61
|
-
test("dsh reload adopts persisted bytes before first assembly; missing records reconstruct from checkpoints and root system", async (t) => {
|
|
62
|
-
const { engine, create, mock } = await dshFixture(t);
|
|
84
|
+
test("dsh same-session reload adopts persisted bytes before first assembly; missing records reconstruct from checkpoints and root system", async (t) => {
|
|
85
|
+
const { engine, create, reload, mock } = await dshFixture(t);
|
|
63
86
|
const agent = await create();
|
|
64
87
|
mock.script.push({ tool: "empty_brain", input: {} }, { text: "after" });
|
|
65
88
|
await run(agent, "before");
|
|
66
89
|
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
67
90
|
await createNotesStore(notesIdentity(agent, engine.config)).write("@self/later", "not in the frozen boot");
|
|
68
91
|
const seed = agent.session.snapshotEvents();
|
|
69
|
-
const resumed = await
|
|
92
|
+
const resumed = await reload(agent, seed);
|
|
70
93
|
await run(resumed, "continue");
|
|
71
94
|
assert.equal(engine.windows.get(resumed.session).snapshot.boot, snapshot.boot);
|
|
72
95
|
assert.equal(system(mock.requests[2]), system(mock.requests[1]));
|
|
73
96
|
const missing = withoutRecords(seed);
|
|
74
|
-
const reconstructed = await
|
|
97
|
+
const reconstructed = await reload(resumed, missing);
|
|
75
98
|
await run(reconstructed, "continue again");
|
|
76
99
|
assert.equal(engine.windows.get(reconstructed.session).snapshot.window, 1);
|
|
77
100
|
assert.equal(engine.windows.get(reconstructed.session).snapshot.boot, snapshot.boot);
|
|
@@ -80,13 +103,53 @@ test("dsh reload adopts persisted bytes before first assembly; missing records r
|
|
|
80
103
|
await run(root, "root stays");
|
|
81
104
|
const rootBoot = engine.windows.get(root.session).snapshot.boot;
|
|
82
105
|
await createNotesStore(notesIdentity(root, engine.config)).write("@self/later", "changed again");
|
|
83
|
-
const rootReloaded = await
|
|
106
|
+
const rootReloaded = await reload(root, withoutRecords(root.session.snapshotEvents()));
|
|
84
107
|
await run(rootReloaded, "resume root");
|
|
85
108
|
assert.equal(engine.windows.get(rootReloaded.session).snapshot.boot, rootBoot);
|
|
86
109
|
assert.equal(engine.windows.get(rootReloaded.session).snapshot.window, 0);
|
|
87
110
|
});
|
|
88
|
-
test("dsh
|
|
89
|
-
const { engine, create, mock } = await dshFixture(t);
|
|
111
|
+
test("dsh native fork rebinds boot and notes tools to the child without changing inherited history", async (t) => {
|
|
112
|
+
const { ctx, engine, create, fork, mock } = await dshFixture(t);
|
|
113
|
+
const parent = await create();
|
|
114
|
+
const parentNotes = createNotesStore(notesIdentity(parent, engine.config));
|
|
115
|
+
await parentNotes.write("MAP.md", "- parent-handoff.md — parent's session note");
|
|
116
|
+
await parentNotes.write("parent-handoff.md", "parent-only recovery");
|
|
117
|
+
mock.script.push({ tool: "empty_brain", input: {} }, { text: "after" });
|
|
118
|
+
await run(parent, "inherited conversation before reset");
|
|
119
|
+
const parentSnapshot = engine.windows.get(parent.session).snapshot;
|
|
120
|
+
assert.equal(parentSnapshot.window, 1);
|
|
121
|
+
assert.ok(parentSnapshot.boot.includes("parent-handoff.md"));
|
|
122
|
+
const parentEvents = structuredClone(parent.session.snapshotEvents());
|
|
123
|
+
const childId = "session-native-child";
|
|
124
|
+
const childNotes = createNotesStore({ ...notesIdentity(parent, engine.config), sessionId: childId });
|
|
125
|
+
await childNotes.write("MAP.md", "- child-handoff.md — child's session note");
|
|
126
|
+
await childNotes.write("child-handoff.md", "child-only recovery");
|
|
127
|
+
const child = await fork(parent, childId);
|
|
128
|
+
assert.equal(child.session.header.parentSession, parent.session.id);
|
|
129
|
+
assert.equal(child.session.inheritedEventCount, parentEvents.length);
|
|
130
|
+
const snapshot = engine.windows.get(child.session).snapshot;
|
|
131
|
+
assert.equal(snapshot.window, parentSnapshot.window);
|
|
132
|
+
assert.equal(snapshot.windowId, `dsh:${childId}:1`);
|
|
133
|
+
assert.ok(snapshot.boot.includes(`\ndsh:${childId}\n`));
|
|
134
|
+
assert.ok(snapshot.boot.includes("- child-handoff.md — child's session note"));
|
|
135
|
+
assert.equal(snapshot.boot.includes("parent-handoff.md"), false);
|
|
136
|
+
assert.equal(recoverSnapshot(child.session.ownEvents())?.windowId, snapshot.windowId, "the rebound snapshot is persisted in the child");
|
|
137
|
+
assert.deepEqual(child.session.snapshotEvents().slice(0, parentEvents.length), parentEvents);
|
|
138
|
+
const read = await ctx.tools.execute({ name: "notes_read", arguments: { address: "child-handoff.md" }, agent: child, callId: ToolCallId("fork-note"), signal: new AbortController().signal });
|
|
139
|
+
assert.equal(read.isError, false);
|
|
140
|
+
if (!read.isError)
|
|
141
|
+
assert.equal(read.value.text, "child-only recovery");
|
|
142
|
+
const history = await ctx.tools.execute({ name: "history_list", arguments: { query: "inherited conversation before reset", roles: ["user"] }, agent: child, callId: ToolCallId("fork-history"), signal: new AbortController().signal });
|
|
143
|
+
assert.equal(history.isError, false);
|
|
144
|
+
if (!history.isError)
|
|
145
|
+
assert.equal(history.value.items.length, 1);
|
|
146
|
+
await run(child, "continue in child");
|
|
147
|
+
assert.ok(system(mock.requests.at(-1)).includes(snapshot.boot));
|
|
148
|
+
assert.equal(engine.windows.get(parent.session).snapshot, parentSnapshot);
|
|
149
|
+
assert.deepEqual(parent.session.snapshotEvents(), parentEvents);
|
|
150
|
+
});
|
|
151
|
+
test("dsh same-session reload keeps frozen bytes and ordinal from a boot written before the tag rename", async (t) => {
|
|
152
|
+
const { engine, create, reload, mock } = await dshFixture(t);
|
|
90
153
|
const agent = await create();
|
|
91
154
|
mock.script.push({ tool: "empty_brain", input: {} }, { text: "after" });
|
|
92
155
|
await run(agent, "before");
|
|
@@ -94,8 +157,10 @@ test("dsh reload keeps its window ordinal from a boot written before the tag ren
|
|
|
94
157
|
assert.ok(snapshot.boot.includes(WINDOW_IDENTITY_OPEN_TAG), "the current boot carries the renamed tag");
|
|
95
158
|
const legacy = withLegacyIdentityTags(withoutRecords(agent.session.snapshotEvents()));
|
|
96
159
|
assert.ok(JSON.stringify(legacy).includes("<context_window>\\nAgent name: dsh"), "the seed reproduces an old-spelling boot");
|
|
97
|
-
|
|
160
|
+
await createNotesStore(notesIdentity(agent, engine.config)).write("@self/later", "not in the legacy frozen boot");
|
|
161
|
+
const resumed = await reload(agent, legacy);
|
|
98
162
|
await run(resumed, "continue");
|
|
163
|
+
assert.equal(engine.windows.get(resumed.session).snapshot.boot, snapshot.boot.replaceAll(WINDOW_IDENTITY_OPEN_TAG, "<context_window>").replaceAll(WINDOW_IDENTITY_CLOSE_TAG, "</context_window>"));
|
|
99
164
|
assert.equal(engine.windows.get(resumed.session).snapshot.window, 1, "an old-tag boot still yields its window ordinal");
|
|
100
165
|
assert.equal(engine.windows.get(resumed.session).snapshot.windowId, snapshot.windowId, "and its window id");
|
|
101
166
|
});
|
|
@@ -109,9 +174,10 @@ function withLegacyIdentityTags(events) {
|
|
|
109
174
|
.replaceAll(WINDOW_IDENTITY_CLOSE_TAG, "</context_window>");
|
|
110
175
|
return events.map((event) => {
|
|
111
176
|
const copy = structuredClone(event);
|
|
112
|
-
|
|
177
|
+
const message = copy.type === "system/message" ? copy.data.message : copy.type === "user/message" ? copy.data : undefined;
|
|
178
|
+
if (!message)
|
|
113
179
|
return copy;
|
|
114
|
-
const data =
|
|
180
|
+
const data = message;
|
|
115
181
|
if (typeof data.content === "string")
|
|
116
182
|
data.content = legacy(data.content);
|
|
117
183
|
else if (Array.isArray(data.content))
|
|
@@ -179,7 +245,7 @@ test("dsh transaction keeps node zero, resets tiny spans, refuses partial spans,
|
|
|
179
245
|
assert.equal(engine.windows.get(session).snapshot.window, 2);
|
|
180
246
|
session.append("turn/end", { turn: 2, reason: { kind: "completed" } });
|
|
181
247
|
});
|
|
182
|
-
test("dsh cancellation preserves the
|
|
248
|
+
test("dsh cancellation preserves the page; a close failure leaves a durable lock and landed boot recoverable", async (t) => {
|
|
183
249
|
const { engine, create } = await dshFixture(t);
|
|
184
250
|
const agent = await create();
|
|
185
251
|
await run(agent, "one");
|
|
@@ -299,10 +365,10 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
299
365
|
if (!read.isError)
|
|
300
366
|
assert.equal(read.value.text, "raw");
|
|
301
367
|
}
|
|
302
|
-
const
|
|
303
|
-
assert.equal(
|
|
304
|
-
if (
|
|
305
|
-
assert.equal(
|
|
368
|
+
const invalidHistory = await call("history_list", { window_id: "missing" });
|
|
369
|
+
assert.equal(invalidHistory.isError, true);
|
|
370
|
+
if (invalidHistory.isError)
|
|
371
|
+
assert.equal(invalidHistory.error.info?.code, "INVALID_PARAMS");
|
|
306
372
|
const invalid = await call("notes_read", { address: "anything", max_chars: 0 });
|
|
307
373
|
assert.equal(invalid.isError, true);
|
|
308
374
|
if (invalid.isError)
|
|
@@ -314,12 +380,12 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
314
380
|
if (!note.isError)
|
|
315
381
|
assert.equal(note.value.text, "decision");
|
|
316
382
|
const identity = notesIdentity(agent, engine.config);
|
|
317
|
-
assert.equal(identity.projectKey,
|
|
383
|
+
assert.equal(identity.projectKey, resolveProjectNamespace(agent.session.header.cwd, identity.home).name);
|
|
318
384
|
const marker = JSON.parse(await readFile(join(identity.home, "project", identity.projectKey, ".project"), "utf8"));
|
|
319
385
|
assert.equal(typeof marker.id, "string");
|
|
320
386
|
const foreignRoot = await mkdtemp(join(tmpdir(), "ns-dsh-foreign-"));
|
|
321
387
|
t.after(() => rm(foreignRoot, { recursive: true, force: true }));
|
|
322
|
-
const foreign =
|
|
388
|
+
const foreign = resolveProjectNamespace(foreignRoot, identity.home);
|
|
323
389
|
await createNotesStore({ ...identity, projectKey: foreign.name }).write("@project/reference", "foreign paper");
|
|
324
390
|
const foreignFile = join(foreign.dir, "reference.md");
|
|
325
391
|
const before = await readFile(foreignFile, "utf8");
|
|
@@ -328,13 +394,16 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
328
394
|
assert.equal(foreignRead.isError, false);
|
|
329
395
|
if (!foreignRead.isError) {
|
|
330
396
|
assert.equal(foreignRead.value.project_root, foreign.path);
|
|
331
|
-
const shared = await notesRead.execute({ address }, identity);
|
|
397
|
+
const shared = await notesRead.execute({ address }, notesToolContext(identity, agent.session.header.cwd));
|
|
332
398
|
assert.ok(shared.ok);
|
|
333
399
|
assert.deepEqual(foreignRead.value, shared.data);
|
|
334
400
|
assert.equal(foreignRead.content[0]?.type, "text");
|
|
335
401
|
assert.equal(foreignRead.content[0].text, notesRead.render(success(shared.data)));
|
|
336
402
|
}
|
|
337
403
|
assert.equal(await readFile(foreignFile, "utf8"), before);
|
|
404
|
+
const overridden = await call("notes_write", { address: "@project/from-override", content: "selected by dsh", cwd: foreignRoot });
|
|
405
|
+
assert.equal(overridden.isError, false);
|
|
406
|
+
assert.equal((await createNotesStore({ ...identity, projectKey: foreign.name }).read("@project/from-override"))?.body, "selected by dsh");
|
|
338
407
|
const refused = await call("notes_write", { address, content: "no overwrite" });
|
|
339
408
|
assert.equal(refused.isError, true);
|
|
340
409
|
if (refused.isError)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TestContext } from "node:test";
|
|
2
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import { type Agent } from "@deepseek-ai/dsh-agent";
|
|
3
4
|
import { type SessionEvent } from "@deepseek-ai/dsh-session";
|
|
4
5
|
import NotesoupEngine, { type EngineConfig } from "../../plugins/dsh/engine.js";
|
|
5
6
|
export declare function dshFixture(t: TestContext, config?: EngineConfig): Promise<{
|
|
@@ -13,5 +14,7 @@ export declare function dshFixture(t: TestContext, config?: EngineConfig): Promi
|
|
|
13
14
|
url: string;
|
|
14
15
|
close: () => Promise<void>;
|
|
15
16
|
};
|
|
16
|
-
create: (seed?: readonly SessionEvent[], id?: string) => Promise<
|
|
17
|
+
create: (seed?: readonly SessionEvent[], id?: string) => Promise<Agent>;
|
|
18
|
+
reload: (agent: Agent, seed?: readonly SessionEvent[]) => Promise<Agent>;
|
|
19
|
+
fork: (agent: Agent, id?: string) => Promise<Agent>;
|
|
17
20
|
}>;
|
package/dist/test/helpers/dsh.js
CHANGED
|
@@ -7,7 +7,7 @@ import Agents from "@deepseek-ai/dsh-agent";
|
|
|
7
7
|
import AgentLoop from "@deepseek-ai/dsh-agent-loop";
|
|
8
8
|
import Llm from "@deepseek-ai/dsh-llm";
|
|
9
9
|
import * as DeepSeek from "@deepseek-ai/dsh-llm-deepseek-api-key";
|
|
10
|
-
import Sessions, { SessionId } from "@deepseek-ai/dsh-session";
|
|
10
|
+
import Sessions, { buildForkSeed, SessionId, SessionLogOffset } from "@deepseek-ai/dsh-session";
|
|
11
11
|
import Projections from "@deepseek-ai/dsh-session-projection";
|
|
12
12
|
import SystemPrompt from "@deepseek-ai/dsh-system-prompt";
|
|
13
13
|
import Tools from "@deepseek-ai/dsh-tools";
|
|
@@ -41,10 +41,26 @@ export async function dshFixture(t, config = {}) {
|
|
|
41
41
|
fibers.push(await ctx.plugin(notesoup));
|
|
42
42
|
fibers.push(await ctx.plugin(AgentLoop, { agents: [], maxParallelToolCalls: 10 }));
|
|
43
43
|
let count = 0;
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const handles = new Map();
|
|
45
|
+
const make = async (options) => {
|
|
46
|
+
const handle = await ctx.agents.create({ agentOptions: { provider: "deepseek-official", model: "mock-flash" }, ...options });
|
|
46
47
|
fibers.push(handle);
|
|
48
|
+
handles.set(handle.agent, handle);
|
|
47
49
|
return handle.agent;
|
|
48
50
|
};
|
|
49
|
-
|
|
51
|
+
const create = (seed, id = `session-test-${++count}`) => make({ sessionId: SessionId(id), meta: { cwd: directory }, ...(seed ? { seed } : {}) });
|
|
52
|
+
const reload = async (agent, seed = agent.session.snapshotEvents()) => {
|
|
53
|
+
await handles.get(agent).dispose();
|
|
54
|
+
return create(seed, agent.session.id);
|
|
55
|
+
};
|
|
56
|
+
const fork = (agent, id = `session-test-${++count}`) => {
|
|
57
|
+
const events = agent.session.snapshotEvents();
|
|
58
|
+
return make({
|
|
59
|
+
sessionId: SessionId(id),
|
|
60
|
+
meta: { cwd: directory, parentSession: agent.session.id, isSeeded: true },
|
|
61
|
+
seed: buildForkSeed(events, events.at(-1).seq),
|
|
62
|
+
inheritedEventCount: SessionLogOffset(events.length),
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return { ctx, engine, engineFiber, directory, mock, create, reload, fork };
|
|
50
66
|
}
|
|
@@ -75,6 +75,11 @@ export declare function context(sessionManager: SessionManager, compact?: Extens
|
|
|
75
75
|
provider: string;
|
|
76
76
|
id: string;
|
|
77
77
|
}): ExtensionContext;
|
|
78
|
+
/** Real Pi usage accounting over the supplied manager; never issues a model request. */
|
|
79
|
+
export declare function nativeUsageContext(sessionManager: SessionManager, settingsManager: SettingsManager, contextWindow?: number): Promise<{
|
|
80
|
+
ctx: ExtensionContext;
|
|
81
|
+
dispose: () => void;
|
|
82
|
+
}>;
|
|
78
83
|
export declare function noticesOf(ctx: ExtensionContext): Notice[];
|
|
79
84
|
export declare function sentOf(captured: Captured, customType: string): SentMessage[];
|
|
80
85
|
export declare function call(captured: Captured, name: string, params: Record<string, unknown>, ctx: ExtensionContext): Promise<AgentToolResult<unknown>>;
|
|
@@ -95,7 +100,6 @@ export type ReadIdentity = {
|
|
|
95
100
|
metadata?: Record<string, unknown>;
|
|
96
101
|
address?: string;
|
|
97
102
|
seq?: number;
|
|
98
|
-
window_id?: string;
|
|
99
103
|
};
|
|
100
104
|
/** The structured data of a read outcome: the window plus whatever identity the operation adds. */
|
|
101
105
|
export type ReadOutcome<T extends object = ReadIdentity> = TextWindow & T;
|
|
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
|
|
|
5
5
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
|
-
import { SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { createAgentSession, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import notesoup, { createNotesoup } from "../../plugins/pi/extension.js";
|
|
10
10
|
import { loadNotesSnapshot } from "../../src/boot/snapshot.js";
|
|
11
11
|
import { renderBootBlock } from "../../src/boot/render.js";
|
|
@@ -190,6 +190,33 @@ export function context(sessionManager, compact, usage, idle = true, cwd = defau
|
|
|
190
190
|
// Only the members the extension reads; the rest of the ExtensionContext surface is unused.
|
|
191
191
|
return Object.assign(fake, { notices, compactionRequests });
|
|
192
192
|
}
|
|
193
|
+
/** Real Pi usage accounting over the supplied manager; never issues a model request. */
|
|
194
|
+
export async function nativeUsageContext(sessionManager, settingsManager, contextWindow = 100_000) {
|
|
195
|
+
const agentDir = process.env.PI_CODING_AGENT_DIR;
|
|
196
|
+
assert.ok(agentDir, "install the isolated extension test environment first");
|
|
197
|
+
const runtime = await ModelRuntime.create({
|
|
198
|
+
authPath: join(agentDir, "auth.json"), modelsPath: null,
|
|
199
|
+
modelsStorePath: join(agentDir, "models"), refreshOnCreate: false,
|
|
200
|
+
});
|
|
201
|
+
const base = runtime.getModels("openai")[0];
|
|
202
|
+
assert.ok(base, "the installed SDK exposes a model for usage accounting");
|
|
203
|
+
const model = { ...base, contextWindow, maxTokens: 4096 };
|
|
204
|
+
const loader = new DefaultResourceLoader({
|
|
205
|
+
cwd: defaultCwd, agentDir, settingsManager,
|
|
206
|
+
noExtensions: true, noSkills: true, noThemes: true, noPromptTemplates: true,
|
|
207
|
+
agentsFilesOverride: () => ({ agentsFiles: [] }),
|
|
208
|
+
});
|
|
209
|
+
await loader.reload();
|
|
210
|
+
const { session } = await createAgentSession({
|
|
211
|
+
cwd: defaultCwd, agentDir, modelRuntime: runtime, model,
|
|
212
|
+
settingsManager, sessionManager, resourceLoader: loader, tools: [],
|
|
213
|
+
});
|
|
214
|
+
session.agent.streamFunction = async () => { throw new Error("usage fixtures must not request a model"); };
|
|
215
|
+
const ctx = context(sessionManager);
|
|
216
|
+
ctx.model = model;
|
|
217
|
+
ctx.getContextUsage = () => session.getContextUsage();
|
|
218
|
+
return { ctx, dispose: () => session.dispose() };
|
|
219
|
+
}
|
|
193
220
|
export function noticesOf(ctx) {
|
|
194
221
|
return ctx.notices;
|
|
195
222
|
}
|
|
@@ -353,7 +380,11 @@ export async function commitTurnEndBoundary(captured, sessionManager, ctx) {
|
|
|
353
380
|
context: { contextEntries: [], contextMessages: [], llmMessages: [], pendingMessages: [], canContinue: true },
|
|
354
381
|
outcome: "completed",
|
|
355
382
|
turnIndex: 0,
|
|
356
|
-
message: {
|
|
383
|
+
message: {
|
|
384
|
+
role: "assistant", content: [], stopReason: "stop", timestamp: Date.now(),
|
|
385
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0,
|
|
386
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
387
|
+
},
|
|
357
388
|
toolResults: [],
|
|
358
389
|
messageEntryId: "assistant-entry",
|
|
359
390
|
toolResultEntryIds: [],
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TestContext } from "node:test";
|
|
2
|
+
export declare function isolateHistoryRoots(t: TestContext, home: string): {
|
|
3
|
+
pi: string;
|
|
4
|
+
claude: string;
|
|
5
|
+
codex: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function writePiTranscript(root: string, id: string, text?: string): Promise<string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Temporary discovery roots for adapter tests; never scan the operator's real transcripts. */
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
export function isolateHistoryRoots(t, home) {
|
|
5
|
+
const roots = { pi: join(home, "pi-sessions"), claude: join(home, "claude-projects"), codex: join(home, "sessions") };
|
|
6
|
+
for (const [harness, root] of Object.entries(roots)) {
|
|
7
|
+
const key = `NOTESOUP_HISTORY_${harness.toUpperCase()}_ROOT`;
|
|
8
|
+
const previous = process.env[key];
|
|
9
|
+
process.env[key] = root;
|
|
10
|
+
t.after(() => { if (previous === undefined)
|
|
11
|
+
delete process.env[key];
|
|
12
|
+
else
|
|
13
|
+
process.env[key] = previous; });
|
|
14
|
+
}
|
|
15
|
+
return roots;
|
|
16
|
+
}
|
|
17
|
+
export async function writePiTranscript(root, id, text = "foreign needle") {
|
|
18
|
+
const timestamp = "2026-10-06T01:02:03.000Z";
|
|
19
|
+
const path = join(root, "--workspace--", `2026-10-06T01-02-03_${id}.jsonl`);
|
|
20
|
+
await mkdir(dirname(path), { recursive: true });
|
|
21
|
+
await writeFile(path, [
|
|
22
|
+
{ type: "session", version: 3, id, timestamp, cwd: "/workspace" },
|
|
23
|
+
{ type: "message", id: "u", parentId: null, timestamp, message: { role: "user", content: text } },
|
|
24
|
+
].map((row) => JSON.stringify(row) + "\n").join(""));
|
|
25
|
+
return path;
|
|
26
|
+
}
|