notesoup 0.53.1 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- 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 +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
- package/dist/plugins/pi/reset/artifacts.js +2 -2
- package/dist/plugins/pi/runtime.js +11 -8
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- 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/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- 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/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/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +257 -86
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- 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 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/marker.test.js +78 -0
- package/dist/test/model-facing-text.test.js +12 -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 +72 -23
- package/dist/test/notes.test.js +50 -20
- 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/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +13 -8
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- 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 +681 -617
- package/plugins/claude/hooks/register.ts +61 -65
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- 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 +179 -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/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +9 -8
- package/plugins/pi/text.ts +5 -0
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- 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/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 → marker.test.d.ts} +0 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { Check } from "typebox/value";
|
|
9
|
+
import { createNotesStore } from "../src/notes/index.js";
|
|
10
|
+
import { assertAddress } from "../src/notes/address.js";
|
|
11
|
+
import { normalizeRemote, projectKey } from "../src/notes/project-namespace.js";
|
|
12
|
+
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
13
|
+
import { success } from "../src/tools/result.js";
|
|
14
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
15
|
+
const toolContext = (identity) => notesToolContext(identity, "/work/current");
|
|
16
|
+
function fixture(t) {
|
|
17
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "notesoup-project-notebook-")));
|
|
18
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
19
|
+
const home = join(root, "notes");
|
|
20
|
+
const repo = (path, origin) => {
|
|
21
|
+
const cwd = join(root, path);
|
|
22
|
+
mkdirSync(join(cwd, ".git"), { recursive: true });
|
|
23
|
+
writeFileSync(join(cwd, ".git/config"), origin ? `[remote "origin"]\n\turl = ${origin}\n` : "");
|
|
24
|
+
return cwd;
|
|
25
|
+
};
|
|
26
|
+
const marker = (key) => JSON.parse(readFileSync(join(home, "project", key, ".project"), "utf8"));
|
|
27
|
+
const identity = (cwd) => ({ home, projectKey: projectKey(cwd, home), sessionId: "session", agent: "test", model: "test" });
|
|
28
|
+
return { root, home, repo, marker, identity };
|
|
29
|
+
}
|
|
30
|
+
// Each participant imports the real built module and operates on the same disk.
|
|
31
|
+
// Optional pauses widen publication/snapshot windows without faking fs outcomes.
|
|
32
|
+
const claimWorker = `
|
|
33
|
+
import fs from "node:fs";
|
|
34
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
35
|
+
import { join } from "node:path";
|
|
36
|
+
const [cwd, home, control, pause] = process.argv.slice(1);
|
|
37
|
+
const sleep = new Int32Array(new SharedArrayBuffer(4));
|
|
38
|
+
function wait(name) {
|
|
39
|
+
const deadline = Date.now() + 15000;
|
|
40
|
+
while (!fs.existsSync(join(control, name))) {
|
|
41
|
+
if (Date.now() >= deadline) throw new Error("Worker barrier timed out: " + name);
|
|
42
|
+
Atomics.wait(sleep, 0, 0, 5);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function paused() { fs.writeFileSync(join(control, "paused"), ""); wait("continue"); }
|
|
46
|
+
if (pause) {
|
|
47
|
+
const mkdir = fs.mkdirSync, readdir = fs.readdirSync, read = fs.readFileSync;
|
|
48
|
+
fs.mkdirSync = function(path, ...args) {
|
|
49
|
+
const result = mkdir(path, ...args);
|
|
50
|
+
if (pause === "publication" && path === join(home, "project", "api")) paused();
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
fs.readdirSync = function(path, ...args) {
|
|
54
|
+
const result = readdir(path, ...args);
|
|
55
|
+
if (pause === "snapshot" && path === join(home, "project") && args.length === 0) paused();
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
fs.readFileSync = function(path, ...args) {
|
|
59
|
+
try { return read(path, ...args); } catch (error) {
|
|
60
|
+
if (path === join(home, "project", "api", ".project") && error.code === "ENOENT") fs.writeFileSync(join(control, "missing"), "");
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
syncBuiltinESMExports();
|
|
65
|
+
}
|
|
66
|
+
const { projectKey } = await import(${JSON.stringify(new URL("../src/notes/project-namespace.js", import.meta.url).href)});
|
|
67
|
+
fs.writeFileSync(join(control, "ready"), "");
|
|
68
|
+
wait("start");
|
|
69
|
+
const key = projectKey(cwd, home);
|
|
70
|
+
const dir = join(home, "project", key);
|
|
71
|
+
const probe = join(dir, "probe-" + process.pid);
|
|
72
|
+
fs.writeFileSync(probe, "usable");
|
|
73
|
+
console.log(JSON.stringify({ key, marker: JSON.parse(fs.readFileSync(join(dir, ".project"), "utf8")), probe: fs.readFileSync(probe, "utf8") }));
|
|
74
|
+
`;
|
|
75
|
+
async function waitForFile(path) {
|
|
76
|
+
const deadline = Date.now() + 10_000;
|
|
77
|
+
while (!existsSync(path)) {
|
|
78
|
+
assert.ok(Date.now() < deadline, `Timed out waiting for ${path}`);
|
|
79
|
+
await delay(5);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function racer(t, root, cwd, home, pause = "") {
|
|
83
|
+
const control = mkdtempSync(join(root, "racer-"));
|
|
84
|
+
const child = spawn(process.execPath, ["--input-type=module", "--eval", claimWorker, cwd, home, control, pause]);
|
|
85
|
+
t.after(() => { if (child.exitCode === null)
|
|
86
|
+
child.kill(); });
|
|
87
|
+
let stdout = "", stderr = "";
|
|
88
|
+
child.stdout.on("data", chunk => { stdout += chunk; });
|
|
89
|
+
child.stderr.on("data", chunk => { stderr += chunk; });
|
|
90
|
+
const result = new Promise((resolve, reject) => {
|
|
91
|
+
child.on("error", reject);
|
|
92
|
+
child.on("close", code => resolve({ code, stdout, stderr }));
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
result,
|
|
96
|
+
wait: (stage) => waitForFile(join(control, stage)),
|
|
97
|
+
release: (stage) => writeFileSync(join(control, stage), ""),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
test("sixteen first claimants converge on one usable notebook for root and remote identities", async (t) => {
|
|
101
|
+
for (const remote of [false, true])
|
|
102
|
+
await t.test(remote ? "normalized remote across different checkout names" : "canonical root", async (t) => {
|
|
103
|
+
const { root, home, repo, marker } = fixture(t);
|
|
104
|
+
const cwd = repo("api", remote ? "git@HOST:team/api.git" : undefined);
|
|
105
|
+
const other = remote ? repo("another-name", "https://host/team/api.git") : cwd;
|
|
106
|
+
const racers = Array.from({ length: 16 }, (_, i) => racer(t, root, i % 2 ? other : cwd, home));
|
|
107
|
+
await Promise.all(racers.map(worker => worker.wait("ready")));
|
|
108
|
+
for (const worker of racers)
|
|
109
|
+
worker.release("start");
|
|
110
|
+
const results = await Promise.all(racers.map(worker => worker.result));
|
|
111
|
+
const keys = results.map(result => {
|
|
112
|
+
assert.equal(result.code, 0, result.stderr);
|
|
113
|
+
const output = JSON.parse(result.stdout);
|
|
114
|
+
assert.equal(output.probe, "usable");
|
|
115
|
+
assert.equal(output.marker.id, remote ? "host/team/api" : cwd);
|
|
116
|
+
return output.key;
|
|
117
|
+
});
|
|
118
|
+
assert.equal(new Set(keys).size, 1);
|
|
119
|
+
assert.deepEqual(readdirSync(join(home, "project")), [keys[0]]);
|
|
120
|
+
assert.equal(marker(keys[0]).id, remote ? "host/team/api" : cwd);
|
|
121
|
+
assert.equal(existsSync(join(home, ".project-claim")), false);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
test("different concurrent identities retain distinct suffixes", async (t) => {
|
|
125
|
+
const { root, home, repo } = fixture(t);
|
|
126
|
+
const first = racer(t, root, repo("one/api", "https://host/one/api"), home);
|
|
127
|
+
const second = racer(t, root, repo("two/api", "https://host/two/api"), home);
|
|
128
|
+
await Promise.all([first.wait("ready"), second.wait("ready")]);
|
|
129
|
+
first.release("start");
|
|
130
|
+
second.release("start");
|
|
131
|
+
const results = await Promise.all([first.result, second.result]);
|
|
132
|
+
for (const result of results)
|
|
133
|
+
assert.equal(result.code, 0, result.stderr);
|
|
134
|
+
assert.deepEqual(results.map(result => JSON.parse(result.stdout).key).sort(), ["api", "api-1"]);
|
|
135
|
+
assert.deepEqual(readdirSync(join(home, "project")).sort(), ["api", "api-1"]);
|
|
136
|
+
});
|
|
137
|
+
test("a claimant waits for another process between directory creation and marker publication", async (t) => {
|
|
138
|
+
const { root, home, repo } = fixture(t);
|
|
139
|
+
const cwd = repo("api");
|
|
140
|
+
const first = racer(t, root, cwd, home, "publication");
|
|
141
|
+
await first.wait("ready");
|
|
142
|
+
first.release("start");
|
|
143
|
+
await first.wait("paused");
|
|
144
|
+
assert.equal(existsSync(join(home, "project/api/.project")), false);
|
|
145
|
+
const second = racer(t, root, cwd, home);
|
|
146
|
+
await second.wait("ready");
|
|
147
|
+
second.release("start");
|
|
148
|
+
await delay(100);
|
|
149
|
+
assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
|
|
150
|
+
first.release("continue");
|
|
151
|
+
for (const result of await Promise.all([first.result, second.result])) {
|
|
152
|
+
assert.equal(result.code, 0, result.stderr);
|
|
153
|
+
assert.equal(JSON.parse(result.stdout).key, "api");
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
test("a directory appearing after the snapshot waits for its marker before adoption or suffixing", async (t) => {
|
|
157
|
+
for (const same of [true, false])
|
|
158
|
+
await t.test(same ? "adopt matching root as remote" : "suffix a different identity", async (t) => {
|
|
159
|
+
const { root, home, repo, marker } = fixture(t);
|
|
160
|
+
const cwd = repo("api", "https://host/team/api");
|
|
161
|
+
const worker = racer(t, root, cwd, home, "snapshot");
|
|
162
|
+
await worker.wait("ready");
|
|
163
|
+
worker.release("start");
|
|
164
|
+
await worker.wait("paused");
|
|
165
|
+
mkdirSync(join(home, "project/api"));
|
|
166
|
+
worker.release("continue");
|
|
167
|
+
await worker.wait("missing");
|
|
168
|
+
writeFileSync(join(home, "project/api/.project"), JSON.stringify({ id: same ? cwd : "host/other/api", path: "/old/root" }));
|
|
169
|
+
const result = await worker.result;
|
|
170
|
+
assert.equal(result.code, 0, result.stderr);
|
|
171
|
+
const key = same ? "api" : "api-1";
|
|
172
|
+
assert.equal(JSON.parse(result.stdout).key, key);
|
|
173
|
+
assert.deepEqual(marker(key), { id: "host/team/api", path: cwd });
|
|
174
|
+
if (!same)
|
|
175
|
+
assert.deepEqual(marker("api"), { id: "host/other/api", path: "/old/root" });
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
test("an unfinished claim times out without silently allocating another notebook", async (t) => {
|
|
179
|
+
const { root, home, repo } = fixture(t);
|
|
180
|
+
const worker = racer(t, root, repo("api"), home, "snapshot");
|
|
181
|
+
await worker.wait("ready");
|
|
182
|
+
worker.release("start");
|
|
183
|
+
await worker.wait("paused");
|
|
184
|
+
mkdirSync(join(home, "project/api"));
|
|
185
|
+
worker.release("continue");
|
|
186
|
+
const result = await worker.result;
|
|
187
|
+
assert.notEqual(result.code, 0);
|
|
188
|
+
assert.match(result.stderr, /Timed out waiting for project claim.*api/);
|
|
189
|
+
assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
|
|
190
|
+
assert.equal(existsSync(join(home, ".project-claim")), false);
|
|
191
|
+
});
|
|
192
|
+
test("a stuck claim lock has a bounded timeout and is never stolen", async (t) => {
|
|
193
|
+
const { root, home, repo } = fixture(t);
|
|
194
|
+
mkdirSync(join(home, ".project-claim"), { recursive: true });
|
|
195
|
+
const worker = racer(t, root, repo("api"), home);
|
|
196
|
+
await worker.wait("ready");
|
|
197
|
+
worker.release("start");
|
|
198
|
+
const result = await worker.result;
|
|
199
|
+
assert.notEqual(result.code, 0);
|
|
200
|
+
assert.match(result.stderr, /Timed out waiting for project claim.*\.project-claim/);
|
|
201
|
+
assert.deepEqual(readdirSync(join(home, "project")), []);
|
|
202
|
+
assert.equal(existsSync(join(home, ".project-claim")), true);
|
|
203
|
+
});
|
|
204
|
+
test("malformed marker evidence refuses instead of becoming an unmarked legacy notebook", t => {
|
|
205
|
+
const { home, repo } = fixture(t);
|
|
206
|
+
const cwd = repo("api");
|
|
207
|
+
mkdirSync(join(home, "project/api"), { recursive: true });
|
|
208
|
+
for (const raw of ["{", "null", "{}", '{"id":"repo","path":""}']) {
|
|
209
|
+
writeFileSync(join(home, "project/api/.project"), raw);
|
|
210
|
+
assert.throws(() => projectKey(cwd, home), /Invalid project marker.*api/);
|
|
211
|
+
assert.equal(readFileSync(join(home, "project/api/.project"), "utf8"), raw);
|
|
212
|
+
assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
|
|
213
|
+
assert.equal(existsSync(join(home, ".project-claim")), false);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
function data(result) {
|
|
217
|
+
if (!result.ok)
|
|
218
|
+
assert.fail(result.error.message);
|
|
219
|
+
return result.data;
|
|
220
|
+
}
|
|
221
|
+
function refused(result) {
|
|
222
|
+
if (result.ok)
|
|
223
|
+
assert.fail("expected refusal");
|
|
224
|
+
return result.error.message;
|
|
225
|
+
}
|
|
226
|
+
test("origin identity normalizes https, scp and port-less ssh without invoking Git", t => {
|
|
227
|
+
const { home, repo, marker } = fixture(t);
|
|
228
|
+
for (const remote of ["https://user:secret@GitHub.COM/team/api.git/", "git@GitHub.COM:team/api.git", "ssh://git@GitHub.COM/team/api.git"]) {
|
|
229
|
+
assert.equal(normalizeRemote(remote), "github.com/team/api");
|
|
230
|
+
}
|
|
231
|
+
assert.equal(normalizeRemote("ssh://git@EXAMPLE.com:2222/team/api.git"), "example.com:2222/team/api");
|
|
232
|
+
const first = repo("one/api", "git@GitHub.COM:team/api.git");
|
|
233
|
+
const second = repo("two/renamed", "https://github.com/team/api.git");
|
|
234
|
+
assert.equal(projectKey(first, home), "api");
|
|
235
|
+
assert.equal(projectKey(second, home), "api");
|
|
236
|
+
assert.deepEqual(marker("api"), { id: "github.com/team/api", path: second });
|
|
237
|
+
});
|
|
238
|
+
test("same-basename repositories get readable suffixes and unmarked legacy names are taken", t => {
|
|
239
|
+
const { home, repo } = fixture(t);
|
|
240
|
+
const first = repo("one/x", "https://host/one/x");
|
|
241
|
+
const second = repo("two/x", "https://host/two/x");
|
|
242
|
+
assert.equal(projectKey(first, home), "x");
|
|
243
|
+
assert.equal(projectKey(second, home), "x-1");
|
|
244
|
+
mkdirSync(join(home, "project", "legacy"));
|
|
245
|
+
writeFileSync(join(home, "project", "legacy", "keep.md"), "old notes");
|
|
246
|
+
assert.equal(projectKey(repo("legacy"), home), "legacy-1");
|
|
247
|
+
assert.equal(readFileSync(join(home, "project", "legacy", "keep.md"), "utf8"), "old notes");
|
|
248
|
+
});
|
|
249
|
+
test("linked worktrees and nested directories share the main checkout notebook and origin", t => {
|
|
250
|
+
const { root, home, repo, marker } = fixture(t);
|
|
251
|
+
const main = repo("api", "ssh://git@HOST/team/api.git");
|
|
252
|
+
const worktree = join(root, "worktree");
|
|
253
|
+
mkdirSync(worktree);
|
|
254
|
+
mkdirSync(join(main, ".git/worktrees/wt"), { recursive: true });
|
|
255
|
+
writeFileSync(join(worktree, ".git"), `gitdir: ${join(main, ".git/worktrees/wt")}\n`);
|
|
256
|
+
writeFileSync(join(main, ".git/worktrees/wt/commondir"), "../..\n");
|
|
257
|
+
assert.equal(projectKey(main, home), "api");
|
|
258
|
+
assert.equal(projectKey(join(worktree, "missing/subdir"), home), "api");
|
|
259
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: main });
|
|
260
|
+
});
|
|
261
|
+
test("a moved checkout reuses its remote notebook and updates only the display root", async (t) => {
|
|
262
|
+
const { root, home, repo, marker, identity } = fixture(t);
|
|
263
|
+
const old = repo("api", "https://host/team/api.git");
|
|
264
|
+
await createNotesStore(identity(old)).write("@project/decision", "keep me");
|
|
265
|
+
const moved = join(root, "new-name");
|
|
266
|
+
renameSync(old, moved);
|
|
267
|
+
const current = identity(moved);
|
|
268
|
+
assert.equal(current.projectKey, "api");
|
|
269
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: moved });
|
|
270
|
+
assert.equal((await createNotesStore(current).read("@project/decision"))?.body, "keep me");
|
|
271
|
+
assert.equal(projectKey(moved, home), "api");
|
|
272
|
+
});
|
|
273
|
+
test("adding origin adopts the canonical path identity without orphaning notes", async (t) => {
|
|
274
|
+
const { home, repo, marker, identity } = fixture(t);
|
|
275
|
+
const cwd = repo("api");
|
|
276
|
+
await createNotesStore(identity(cwd)).write("@project/decision", "still here");
|
|
277
|
+
assert.deepEqual(marker("api"), { id: cwd, path: cwd });
|
|
278
|
+
writeFileSync(join(cwd, ".git/config"), '[remote "backup"]\nurl = https://host/wrong\n[remote "origin"]\nurl = git@HOST:team/api.git\n');
|
|
279
|
+
assert.equal(projectKey(cwd, home), "api");
|
|
280
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: cwd });
|
|
281
|
+
assert.equal((await createNotesStore(identity(cwd)).read("@project/decision"))?.body, "still here");
|
|
282
|
+
});
|
|
283
|
+
test("named projects read/list/search with root and sibling receipts, without touching stored bytes", async (t) => {
|
|
284
|
+
const { home, repo, identity } = fixture(t);
|
|
285
|
+
const first = repo("one/api", "https://host/one/backend");
|
|
286
|
+
const second = repo("two/api", "https://host/two/service");
|
|
287
|
+
const own = identity(first);
|
|
288
|
+
const other = identity(second);
|
|
289
|
+
await createNotesStore(own).write("@project/decision", "needle first");
|
|
290
|
+
await createNotesStore(other).write("@project/decision", "needle second");
|
|
291
|
+
const address = "@projects/api-1/decision.md";
|
|
292
|
+
const file = join(home, "project/api-1/decision.md");
|
|
293
|
+
const before = readFileSync(file, "utf8");
|
|
294
|
+
const read = data(await notesRead.execute({ address }, toolContext(own)));
|
|
295
|
+
assert.equal(read.text, "needle second");
|
|
296
|
+
assert.equal(read.project_root, second);
|
|
297
|
+
assert.deepEqual(read.project_siblings, [{ name: "api", path: first }]);
|
|
298
|
+
assert.equal(Check(notesRead.outputSchema, read), true);
|
|
299
|
+
assert.match(notesRead.render(success(read)), /Same-basename projects: api \(/);
|
|
300
|
+
const listed = data(await notesList.execute({ glob: "@projects/*/**" }, toolContext(own)));
|
|
301
|
+
assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
|
|
302
|
+
assert.equal(Check(notesList.outputSchema, listed), true);
|
|
303
|
+
const searched = data(await notesSearch.execute({ glob: "@projects/api-1/**", query: "needle" }, toolContext(own)));
|
|
304
|
+
assert.equal(searched.files[0]?.project_root, second);
|
|
305
|
+
assert.equal(Check(notesSearch.outputSchema, searched), true);
|
|
306
|
+
assert.equal(readFileSync(file, "utf8"), before, "named-notebook reads never rewrite access metadata");
|
|
307
|
+
});
|
|
308
|
+
test("named project writes, edits, crumples and both move endpoints refuse, including the current notebook", async (t) => {
|
|
309
|
+
const { repo, identity } = fixture(t);
|
|
310
|
+
const own = identity(repo("api"));
|
|
311
|
+
await createNotesStore(own).write("@project/decision", "body");
|
|
312
|
+
const address = "@projects/api/decision";
|
|
313
|
+
for (const result of [
|
|
314
|
+
await notesWrite.execute({ address, content: "replacement" }, toolContext(own)),
|
|
315
|
+
await notesUpdate.execute({ address, edits: [{ oldText: "body", newText: "changed" }] }, toolContext(own), () => ""),
|
|
316
|
+
await notesUpdate.execute({ address, crumpled: true }, toolContext(own), () => ""),
|
|
317
|
+
await notesUpdate.execute({ address, rename_to: "@project/moved" }, toolContext(own), () => ""),
|
|
318
|
+
await notesUpdate.execute({ address: "@project/decision", rename_to: "@projects/api/moved" }, toolContext(own), () => ""),
|
|
319
|
+
])
|
|
320
|
+
assert.match(refused(result), /read-only; use @project\//);
|
|
321
|
+
assert.equal(data(await notesRead.execute({ address }, toolContext(own))).text, "body");
|
|
322
|
+
assert.throws(() => assertAddress("@projects/api/../decision"));
|
|
323
|
+
assert.throws(() => assertAddress("@projects/api"));
|
|
324
|
+
});
|
|
@@ -910,6 +910,18 @@ test("empty_brain trims the last word, refuses an oversized one, and a blank per
|
|
|
910
910
|
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
911
911
|
assert.equal(boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a blank last word persists no entry");
|
|
912
912
|
});
|
|
913
|
+
test("empty_brain accepts a 500-code-point sticky note without truncation", async () => {
|
|
914
|
+
assert.equal(MAX_LAST_WORD_CHARS, 500);
|
|
915
|
+
const h = harness();
|
|
916
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
917
|
+
const sticky = "🐟".repeat(500);
|
|
918
|
+
const accepted = await h.callTool("empty_brain", { last_word: ` ${sticky} ` });
|
|
919
|
+
assert.notEqual(accepted.isError, true);
|
|
920
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
921
|
+
const entry = boundary.entries.find((row) => row.type === "custom_message" && row.customType === RESET_LAST_WORD_TYPE);
|
|
922
|
+
assert.ok(entry && entry.type === "custom_message");
|
|
923
|
+
assert.equal(entry.content, `${LAST_WORD_PREFIX}${sticky}`);
|
|
924
|
+
});
|
|
913
925
|
test("empty_brain's schema admits whitespace-wrapped notes and leaves length to the handler", async () => {
|
|
914
926
|
const parameters = harness().toolParameters("empty_brain");
|
|
915
927
|
const padded = " ".repeat(300) + "x";
|
package/docs/architecture.md
CHANGED
|
@@ -9,13 +9,14 @@ notesoup uses Pi's session branch as the durable source of truth. It does not ma
|
|
|
9
9
|
| `index.ts` | The curated host-neutral core surface: the notes library, the boot snapshot/renderer and bindings, the shared operations, and the budget prose | Host entry only; the core never imports a plugin |
|
|
10
10
|
| `plugins/pi/index.ts` | The Pi plugin entry: default extension and `createNotesoup` | Pi only; composed from the domains |
|
|
11
11
|
| `plugins/claude/src/` | Claude Code helper, persisted-transcript decoding and threshold derivation | Claude only; alongside the self-contained plugin in `plugins/claude/` |
|
|
12
|
-
| `notes/identity.ts`, `notes/store.ts`, `notes/address.ts`, `notes/paths.ts` | Explicit `NotesIdentity`, filesystem
|
|
13
|
-
| `boot/snapshot.ts` | Load each of the
|
|
12
|
+
| `notes/identity.ts`, `notes/store.ts`, `notes/address.ts`, `notes/paths.ts` | Explicit `NotesIdentity`, filesystem notebooks, metadata, addressing and mutations | Node filesystem, no SDK or host environment identity |
|
|
13
|
+
| `boot/snapshot.ts` | Load each of the five notebooks once; isolate filesystem errno failures | Explicit identity, captured time and optional scope loader |
|
|
14
14
|
| `boot/render.ts`, `boot/text.ts` | Render identity, protocol, maps and recent-note metadata | Explicit snapshot and logical tool-name bindings; no I/O or clock |
|
|
15
15
|
| `history/history.ts` | Project decoded events and pair tool calls/results, preserving supplied addresses | Decoded items and branch visibility; never inference messages |
|
|
16
16
|
| `history/query.ts` | Bounded paging, `from` selection, literal matching, folding and preview rendering | Query projection only; no native session traversal |
|
|
17
17
|
| `budget/constants.ts`, `budget/policy.ts`, `budget/text.ts` | Pure thresholds, unknown/clamped countdown and reminder text | Values supplied by the caller; no settings reads or scheduling |
|
|
18
|
-
| `tools/notes.ts
|
|
18
|
+
| `tools/notes-context.ts` | Host base cwd plus default identity, and one per-call cwd resolver | Shared current-project selection; no host SDK or sticky cwd mutation |
|
|
19
|
+
| `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 tool context/projection; one bounded result feeds both text and structured output |
|
|
19
20
|
| `settings.ts` | The `notesoup` settings key, the plain-object test and the per-key global/project merge | Raw records only; each host names and validates the fields it consumes |
|
|
20
21
|
| `dream/settings.ts` | Dreamer-pattern validation over the merged record | Parsed values only; no SDK or I/O |
|
|
21
22
|
| `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 |
|
|
@@ -30,9 +31,11 @@ notesoup uses Pi's session branch as the durable source of truth. It does not ma
|
|
|
30
31
|
| `plugins/pi/reset/artifacts.ts`, `plugins/pi/reset/committed.ts` | Construct boundaries, repair only safe suffixes, independently confirm committed native boundaries | Active native branch; no shadow commit database |
|
|
31
32
|
| `plugins/pi/dream/` | Pi dream sessions, native tool wrappers, settings reads and executable CLI composition | Pi backend over independent dream policy/filesystem functions |
|
|
32
33
|
|
|
34
|
+
In the notes vocabulary a **namespace** is a note partition: a `Scope` plus its storage directory (`session`, `@project`, `@human`, `@self`, `@model`, or a named `@projects`/`@agents`/`@models` member). Pi's `ToolNamespace` in `plugins/pi/tool-result.ts` is a tool-registration group (`notes`, `history`) and is unrelated; the word "home" is reserved for the store root directory.
|
|
35
|
+
|
|
33
36
|
Dependencies flow from a plugin into the core, never back. Core code under `src/` cannot import an SDK or anything under `plugins/`, and a plugin cannot import another plugin's modules or a foreign host SDK; a plugin reaches note storage only through `src/notes/index.ts`. Each plugin owns its host's words: the Pi-only pre-reset hints, the `last_word` nudge and the `/empty <prompt>` close-out live in `plugins/pi/text.ts`, and the Claude wipe, missing-history and warning prose in `plugins/claude/src/text.ts`. `test/dependencies.test.ts` uses TypeScript resolution and AST traversal over every core source and each plugin tree, and tests rejecting indirect, aliased, dynamic and import-type edges. 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.
|
|
34
37
|
|
|
35
|
-
The configured extension is `plugins/pi/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 `plugins/pi/estimate.ts` because Pi's root-package aliases misresolve that public subpath on source loads; host-owned SDK APIs stay external. The package root `.` exports the host-neutral core, `./pi` the Pi plugin, `/notes` the standalone library, and `./dsh` plus `./dsh/engine` the Cordis rows. The CLI is `dist/plugins/pi/dream/cli.js`, and the Claude Code plugin is the self-contained `plugins/claude/` directory. Old internal bags, `NotesContext`, root history helpers and the deep-entry export alias are removed. This breaks source/import paths, not storage: the on-disk notes layout is unchanged and host-independent — `pi/session/<sessionId>/` is a historical directory name every host still writes to, not a Pi adapter choice, and nothing migrates it. Note
|
|
38
|
+
The configured extension is `plugins/pi/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 `plugins/pi/estimate.ts` because Pi's root-package aliases misresolve that public subpath on source loads; host-owned SDK APIs stay external. The package root `.` exports the host-neutral core, `./pi` the Pi plugin, `/notes` the standalone library, and `./dsh` plus `./dsh/engine` the Cordis rows. The CLI is `dist/plugins/pi/dream/cli.js`, and the Claude Code plugin is the self-contained `plugins/claude/` directory. Old internal bags, `NotesContext`, root history helpers and the deep-entry export alias are removed. This breaks source/import paths, not storage: the on-disk notes layout is unchanged and host-independent — `pi/session/<sessionId>/` is a historical directory name every host still writes to, not a Pi adapter choice, and nothing migrates it. Note notebooks, 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.
|
|
36
39
|
|
|
37
40
|
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.
|
|
38
41
|
|
|
@@ -48,13 +51,15 @@ Boot and reminder deduplication inspect the current branch-local window. Reloadi
|
|
|
48
51
|
|
|
49
52
|
Manual `/fresh-window` stores command settlement policy and sends a hidden warning: idle commands start a model turn, running commands steer it. Tool requests are recorded independently and retained under that policy. A bare command settles and stops unless later human input arrives; a command with text settles and continues, with its text supplied to the closing window and carried verbatim into the fresh window. Budget warnings create no reset state: only an explicit tool request, hard reserve or bounded overflow recovery triggers a reset. Abort and ordinary errors do not count as successful settlement. Hard reserve preserves a bare command's stop in a run-scoped latch; `context_with_system` cancels only an empty tool-batch follow-up after confirming the committed boundary. Queued user input is answered before stopping. See [reset lifecycle](reset-lifecycle.md) for the state and recovery rules.
|
|
50
53
|
|
|
51
|
-
Boot is a fixed snapshot for its window, stored as an extension custom message and converted by Pi to a user-role model message. History internally distinguishes native system summaries and extension-authored custom messages; its public `context` event groups both without implying provider instruction priority. A system-role projection is technically possible through `context_with_system`, but would change the authority of the mixed protocol/MAP content and provider-specific prompt/cache behavior; it is not a prerequisite for persistence. Boot injection is silent, including startup, reload, and boot repair.
|
|
54
|
+
Boot is a fixed snapshot for its window, stored as an extension custom message and converted by Pi to a user-role model message. History internally distinguishes native system summaries and extension-authored custom messages; its public `context` event groups both without implying provider instruction priority. A system-role projection is technically possible through `context_with_system`, but would change the authority of the mixed protocol/MAP content and provider-specific prompt/cache behavior; it is not a prerequisite for persistence. Boot injection is silent, including startup, reload, and boot repair. `/empty` and `/fresh-window` acknowledge a new request with `🥣 Dumping Brain`. Normal reset completion is silent; only forced reset completion produces `🥣 Brain forcibly emptied: overflow` through `ctx.ui.notify`, after the verified checkpoint, marker, boot, and continuation are present in the session. Committed resets are checked at the next turn start or final settlement. `plugins/pi/reset/committed.ts` confirms an ordered hidden boot/continuation after a checkpoint-backed marker even when later conversation exists. That is distinct from `inspectResetTail`, which refuses suffix repair after real work or malformed ordering. Uncommitted reset drafts never announce success. Boot and continuation messages retain `display: false`.
|
|
52
55
|
|
|
53
56
|
The Pi history adapter decodes the selected raw session branch on demand without a cache. It allocates stable seq values from the session's append-order entry list, then selects current-branch-only visibility, so navigation cannot expose a sibling's history. Shared history pairs and queries those decoded events; it neither traverses SessionReader nor reconstructs inference messages. The public stream combines each tool call with its result at the call seq; paired result slots are not public event addresses, and unpaired results retain their own seq. Summaries and injected messages project as `context`. List pages chronologically with seq anchors and an explicit `from`. Tool executions retain structured call/result facts and any native nested-call metadata. A deterministic event document supplies both query-match positions and read windows. Nested calls have no independent seq and never imply that unrecorded child outputs are available.
|
|
54
57
|
|
|
55
|
-
The boot notes index in `boot/snapshot.ts` is a closed snapshot: the current session, project, human, agent, and model
|
|
58
|
+
The boot notes index in `boot/snapshot.ts` is a closed snapshot: the current session, project, human, agent, and model notebooks are each loaded at most once while constructing a boot. `boot/snapshot.ts` takes explicit `NotesIdentity`, captured `openedAt` and an optional notebook loader; `boot/render.ts` renders that snapshot and explicit tool bindings without reading the filesystem or consulting the clock. Pi supplies its unchanged tool names. MAP bodies and pocket metadata are derived from the same snapshot, so a boot cannot mix two filesystem reads. Note storage and notebook traversal use `node:fs/promises`; same-file operations queue by absolute physical filename across store instances in this process, without promising symlink/case-alias or cross-process locking. Known persisted metadata is camelCase. Old snake_case keys are unrecognized extras, not interpreted or migrated; startup does not migrate notes. A missing notebook (`ENOENT`) is normal. A real read failure omits only that notebook's index, preserves healthy notebooks, adds a model-facing `notes_list` recovery notice, and notifies the human once for that window. Boot/reset construction captures session, agent, and model identity before awaiting the snapshot, then checks lifecycle generation, active window, enabled state, and abort status before sending or returning artifacts; stale completions cannot commit into a switched or shut-down session. Boot acquisition uses listing and never updates access metadata. Explicit note reads update `lastAccessed` and `accessCount`; no fallback state is created.
|
|
59
|
+
|
|
60
|
+
Notes remain in their filesystem-backed notebooks, unchanged by session branch navigation. Tool reads expose metadata separately from body windows; search/read code-point offsets are body-relative and do not depend on frontmatter serialization or access-counter changes.
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
Every notes tool accepts an optional per-call `cwd`. The host adapter supplies a `NotesToolContext` containing its base cwd and default `NotesIdentity`; shared tool code resolves a relative override against that base, requires an existing directory, and derives one override `projectKey` through the existing project resolver. Storage, addresses, globs, receipts, and new session-note ownership all consume that same resolved identity. The override neither mutates the context nor changes `NotesIdentity.home`; the standalone store still receives explicit identities and has no cwd-discovery behavior. Dream markers survive resolution, so an override cannot widen dream write permission.
|
|
58
63
|
|
|
59
64
|
Notes/history operations return schema-derived `Outcome<T>` values, not host `content` objects. One bounded candidate is measured against both its complete structured serialization and its text renderer. Pi registers the outcome schema and packages that same value as `structuredContent`, derives `isError` from it and puts rendered text in `content`. Claude uses the same operations and renderers. Neither adapter parses text or independently chooses a page. Read continuation hints follow Pi's native trailing-notice style and are not part of the addressed text. See [tool results](tool-results.md) for the breaking protocol and coordinate contract.
|
|
60
65
|
|
|
@@ -62,7 +67,7 @@ The `/fresh-window` command only waits for idle when the session is busy with no
|
|
|
62
67
|
|
|
63
68
|
## Evidence and limits
|
|
64
69
|
|
|
65
|
-
The retained integration tests use real SessionManager and SettingsManager instances. They check reset-window history retention, seq-addressed and cursor-paged history, bounded history/notes reads with resumable character windows,
|
|
70
|
+
The retained integration tests use real SessionManager and SettingsManager instances. They check reset-window history retention, seq-addressed and cursor-paged history, bounded history/notes reads with resumable character windows, notebook isolation, and settings precedence. The suite is representative rather than exhaustive. Focused host-neutral tests additionally run boot/tool/history/budget logic with explicit inputs and no SDK context; resolved-AST guards enforce the dependency boundary.
|
|
66
71
|
|
|
67
72
|
Scripted SDK tests execute the real Pi agent loop with no model/network request. They inspect provider contexts and durable entries for idle and streaming manual requests, budget close-out, explicit and normal-stop commits, abort/error cleanup, same-window command deduplication, queued steering/follow-up delivery, retain-none checkpoints across two resets and disk reopen, bounded overflow recovery, and settings authority. Smaller dream tests retain lock exclusion/ownership, jailed writes, CLI audit/report failure propagation, and read-only doctor behavior. Removing duplicate scenarios and edge-case matrices reduces coverage; the remaining tests do not establish every malformed-input case, branch interleaving, external-provider behavior, or filesystem failure mode.
|
|
68
73
|
|
package/docs/claude-code-mod.md
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
The package also ships `plugins/claude/`, an early-access Claude Code Mod that registers five notes tools as `mcp__notesoup__notes_*`, three history tools as `mcp__notesoup__history_*`, and `mcp__notesoup__empty_brain` and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `plugins/claude/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
There is no independent proactive automatic clear line: crossing a measured threshold, `session.measure`, or completing an unrequested turn never clears context. `turn.complete` resets only an explicit pending request from `empty_brain`, `/empty`, or `/fresh-window`. Budget warning timing is unchanged and is derived from Claude's own auto-compact threshold instead of a fixed percent, in `plugins/claude/src/thresholds.ts`, and reaches the sandboxed hooks module through the helper's `limits` operation:
|
|
6
6
|
|
|
7
|
-
1. `$.session.usage({breakdown:"summary"}).context.autoCompactThreshold` when it is a positive number, with `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` applied the way Claude applies it (it can only lower the point);
|
|
8
|
-
2. otherwise computed from `$.session.usage().context.window` plus `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `modelSettings.<model>.autoCompactWindow` and `autoCompactWindow` (the smallest configured window wins, capped at the model window), with Claude's 20000-token output reserve and 13000-token summary buffer;
|
|
7
|
+
1. `$.session.usage({breakdown:"summary"}).context.breakdown.autoCompactThreshold` when it is a positive number, with `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` applied the way Claude applies it (it can only lower the point);
|
|
8
|
+
2. otherwise computed from `$.session.usage().context.window` plus `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `modelSettings.<model>.autoCompactWindow` and `autoCompactWindow` (the smallest configured window wins, capped at the model window), with Claude's 20000-token output reserve and 13000-token summary buffer; `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` lowers this fallback point by the same formula. With auto-compaction off, the percent override is ignored;
|
|
9
9
|
3. otherwise the percent fallback, which expresses the same reserves on the classic 200K window.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The warning remains `resetMarginTokens` (default 8192) plus `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below that point. The internal reset-derived intermediate is only warning math, not a clear trigger. With automatic compaction off (`autoCompactEnabled: false` in the merged settings, or `DISABLE_AUTO_COMPACT=1`) the point becomes the effective window minus the output reserve, so the same margins still apply. Every undocumented field is type-guarded and degrades to the next source; an unresolvable point, or missing usage, logs once and skips the budget warning. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, suppresses budget warnings and explicit resets, and makes `/fresh-window` report that it cannot run. The margins are read from the `notesoup` object of Claude's merged `$.settings.read()` (`resetMarginTokens`, `warningRunwayTokens`); any other value is ignored. Setting `NOTESOUP_DISABLED` (presence-style, the same convention as `DISABLE_COMPACT`) turns the whole mod off: `session.start` registers no tools or commands and logs once, every event passes through untouched, and native compaction behaves as if the mod were absent.
|
|
12
12
|
|
|
13
|
-
Once per window, when the measured context crosses the warning point, main-agent tool results or prompt submission carry exactly the same budget warning as Pi, ending with `empty_brain` and the countdown. Delivery is consumed only when the downstream chain accepts the warning. The warned flag resets with the window ordinal. Its own `session.compact` hook answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected handoff paragraph (normal only when the model called `empty_brain`, otherwise forced), selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while `/compact` and precompute are vetoed with a one-line notice. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block binds the shared reset sentence to `mcp__notesoup__empty_brain`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
|
|
13
|
+
Once per window, when the measured context crosses the warning point, main-agent tool results or prompt submission carry exactly the same budget warning as Pi, ending with `empty_brain` and the countdown. Delivery is consumed only when the downstream chain accepts the warning. The warned flag resets with the window ordinal. Its own `session.compact` hook answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected handoff paragraph (normal only when the model called `empty_brain`, otherwise forced), selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while user `/compact` and precompute are vetoed with a one-line notice. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block binds the shared reset sentence to `mcp__notesoup__empty_brain`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
|
|
14
14
|
|
|
15
|
-
The model can request the same reset through `empty_brain`, optionally passing a short `last_word` that is retained after the boot and handoff. The tool queues the reset and tells the model to end its turn; compaction runs at main-agent `turn.complete`, never inside a running tool call. Subagents cannot reset the main brain, and
|
|
15
|
+
The model can request the same reset through `empty_brain`, optionally passing a short `last_word` that is retained after the boot and handoff. The tool queues the reset and tells the model to end its turn; compaction runs at main-agent `turn.complete`, never inside a running tool call. Subagents cannot reset the main brain, and `DISABLE_COMPACT` sessions refuse the tool without queuing a reset. Successful reset or session change clears the pending request and sticky note.
|
|
16
16
|
|
|
17
|
-
`/fresh-window`
|
|
17
|
+
`/empty` and its alias `/fresh-window` request the same reset. While idle it submits one hidden normal-model close-out turn to let the model save notes, then resets at `turn.complete`; while busy it waits for the current turn instead. The close-out prompt is the same shared warning text the automatic path shows. Interactive resets use `$.session.compact`. Headless (`-p` / SDK) resets instead queue the native command with `$.command.run({command:"compact"})` after `turn.complete`; Claude Code 2.1.299 runs this command non-interactively and invokes the same plugin's compact hook. Only that internally initiated command admits the manual trigger; user `/compact` remains vetoed. The command receipt is not a compaction result: successful completion also requires the hook to have prepared the notes boot. Rejected or vetoed resets keep their pending request and sticky note for retry. Native command/caveat/output rows remain in the next request alongside the fresh boot; no compaction model request is made. Boot acquisition failure vetoes reset, leaving the current window intact. A Claude dream backend is not implemented; budget reporting (`get_context_remaining`) remains Pi-only, while the one warning per window follows Claude's own configuration.
|
|
18
18
|
|
|
19
19
|
The notes tools also serve subagent calls, using the same session identity and shared operations. The plugin exposes the shared memory and dream skills and the dream playbook; the build keeps these copies byte-identical to the canonical files.
|
|
20
20
|
|
package/docs/codex.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Codex plugin (native mode)
|
|
2
2
|
|
|
3
|
-
`plugins/codex/` makes notesoup a native Codex plugin: the five
|
|
3
|
+
`plugins/codex/` makes notesoup a native Codex plugin: the five notebooks and the three history tools over a bundled stdio MCP server, plus a SessionStart/SubagentStart hook that writes the notes boot into the window Codex is actually opening. It does not wrap Codex's conversation or replace its context engine. Reset and budget stay native.
|
|
4
4
|
|
|
5
5
|
Targets **Codex 0.160.1 only**, with the rollout format source-checked against the official 0.160.1 tree. No live Codex host or config-parser evidence is claimed at this stage. The rollout decoder rejects any other `cli_version`; it is not a forward-compatible reader. A `.jsonl.zst` rollout needs **Node >=22.15** (`zstdDecompressSync`); the plugin invokes `node`, which must resolve to that version.
|
|
6
6
|
|
|
@@ -37,10 +37,10 @@ Keep the forms separate: `token_budget` is a table here, so do not also write `t
|
|
|
37
37
|
|
|
38
38
|
- **A boot per native window.** The `SessionStart` hook reads the thread's native rollout, binds the thread to this Codex root session, cwd, model, transcript and current window, and returns the shared notes boot with a window marker. The boot is deduped by the host's own persisted `hooks.additional_context` record for that exact thread and window, never by a quoted marker. A compact creates a new native window and therefore a fresh boot.
|
|
39
39
|
- **Codex's `new_context` and `get_context_remaining`.** They remain Codex's tools. notesoup has no MCP reset or budget fallback, and an MCP call cannot trigger a reset.
|
|
40
|
-
- **Five
|
|
40
|
+
- **Five notebooks** through `notes_write`, `notes_update`, `notes_read`, `notes_list` and `notes_search`. `NOTESOUP_HOME` overrides the root (default `~/.agents/notes`); a root thread's agent name is `NOTESOUP_AGENT` or `anonymous`.
|
|
41
41
|
- **Native history** through `history_windows`, `history_list` and `history_read`: the root thread's windows and a child's own ancestry. Window ids are `codex:<thread>:<native-window-uuid>`, and the boot's window tree uses those same UUIDs, so the shared `trunk:shortname` rule names the address history actually serves.
|
|
42
42
|
- **Per-turn model identity.** `@model` follows the current turn's `x-codex-turn-metadata.model`, not the model recorded at thread start. The start model only labels the boot.
|
|
43
|
-
- **Subagents and forks.** `SubagentStart` binds the child or fork to its own transcript while keeping the parent's root session. Its `@self`
|
|
43
|
+
- **Subagents and forks.** `SubagentStart` binds the child or fork to its own transcript while keeping the parent's root session. Its `@self` notebook is the slugged `agent_type` (for example `worker`), not the parent's.
|
|
44
44
|
|
|
45
45
|
Codex may prefix MCP tool names with a server namespace. Use the names that appear in the session's tool list; the boot says the same.
|
|
46
46
|
|
|
@@ -70,7 +70,7 @@ Codex 0.160.1 has no supported child post-compact boot or recovery hook. notesou
|
|
|
70
70
|
| --- | --- |
|
|
71
71
|
| Codex versions | 0.160.1 only; other `cli_version` values are refused. |
|
|
72
72
|
| Node | >=22.15 for compressed rollouts. |
|
|
73
|
-
| Boot size | Local cap 128 KiB. The hook sets `additionalContextLimit: 0` so the host does not spill or silently truncate the boot; an oversized boot becomes a warning and nothing is injected. Slim the
|
|
73
|
+
| Boot size | Local cap 128 KiB. The hook sets `additionalContextLimit: 0` so the host does not spill or silently truncate the boot; an oversized boot becomes a warning and nothing is injected. Slim the notebook MAPs. |
|
|
74
74
|
| Tool output | Shared 32 KiB result bound; use continuation fields or narrower filters. |
|
|
75
75
|
| History sources | Local rollout files only. No app-server history API, no remote history, no text from opaque/encrypted payloads. |
|
|
76
76
|
| Reset/budget | Codex-native only. No MCP fallback, no notesoup budget warning or close-out turn. |
|
package/docs/dsh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DeepSeek Harness adapter
|
|
2
2
|
|
|
3
|
-
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh
|
|
3
|
+
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh page when context runs low: frozen boot text, the five notebooks, eight notes/history tools, `get_context_remaining`, and `empty_brain`. 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
4
|
|
|
5
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/plugins/dsh/engine.js` and `file:///.../dist/plugins/dsh/index.js` module names. The example shows all rows for a profile assembled without the package bundle.
|
|
6
6
|
|
|
@@ -10,17 +10,17 @@ On load and before requests, preflight probes `systemPrompt.section`, `tools.reg
|
|
|
10
10
|
|
|
11
11
|
## Notes, boot and history
|
|
12
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
|
|
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 notebooks. Project identity uses the shared `resolveProjectNamespace(cwd, notesHome)` resolver: readable slug notebooks with a `.project` marker, including repository/worktree and origin identity. Other marked projects are readable through `@projects/<name>/`; named-notebook reads do not update access metadata and named-notebook writes are refused. Receipts, boot protocol (including separate CHEATSHEET.md and MAP.md pages), 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
14
|
|
|
15
|
-
The boot is a `systemPrompt.section` at order **2450**, with `interpolate: false`. Shared snapshot/render functions read the five
|
|
15
|
+
The boot is a `systemPrompt.section` at order **2450**, with `interpolate: false`. Shared snapshot/render functions read the five notebooks 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
16
|
|
|
17
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
18
|
|
|
19
19
|
## Reset and budget
|
|
20
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
|
|
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 page, 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 a complete handoff paragraph, randomly selected once at reset creation. A model reset call selects the normal pool; other resets select the forced pool. The checkpoint and steered copy reuse the same paragraph. A one-message span can reset even when its replacement is larger.
|
|
22
22
|
|
|
23
|
-
Cancellation or a snapshot/checkpoint failure before replacement restores the old
|
|
23
|
+
Cancellation or a snapshot/checkpoint failure before replacement restores the old page. 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
24
|
|
|
25
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
26
|
|
|
@@ -47,15 +47,15 @@ The reminder and close-out warning go through `agent.steer`. Close-out remains a
|
|
|
47
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
48
|
| Model calls per reset | **0** auxiliary model calls. The agent's note-writing turns and fresh-window continuation still make ordinary calls. |
|
|
49
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
|
|
50
|
+
| Boot bounds | Up to **4096 code points per MAP** and **3 recent notes per notebook**, from the shared renderer. Slim large MAPs; follow note addresses for full bodies. |
|
|
51
51
|
| Tool output | Shared **32 KiB** bounds; use `next_offset_chars`, history cursors, or narrower filters. There is no unbounded hidden result. |
|
|
52
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
53
|
| Unknown capacity | Countdown is **null** and automatic reserve checks skip. Add `models[].contextWindow` to `llm-deepseek`; explicit resets still work. |
|
|
54
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
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
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 `/fresh-window`/`/empty` command is installed. Configure engine rows in the profile
|
|
57
|
+
| Notifications and commands | No custom UI notifications, settings card, runtime toggle or `/fresh-window`/`/empty` command is installed. Configure engine rows in the profile patch; call `empty_brain` or the host's `/compact`. |
|
|
58
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
59
|
| Dream | **No dsh dream backend or dream skill registration.** Use the existing supported host workflow. |
|
|
60
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
|
|
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 notebooks 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.
|