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
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, mkdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import { zstdCompressSync } from "node:zlib";
|
|
7
|
+
import { Check } from "typebox/value";
|
|
8
|
+
import { localHistoryCorpus } from "../src/history/local.js";
|
|
9
|
+
import { parseSessionSelector } from "../src/history/corpus.js";
|
|
10
|
+
import { allItems, projectHistory } from "../src/history/history.js";
|
|
11
|
+
import { offlineClaudeHead } from "../src/history/claude.js";
|
|
12
|
+
import { piHistoryFromJsonl } from "../src/history/pi.js";
|
|
13
|
+
import { historyList, historyRead } from "../src/tools/history.js";
|
|
14
|
+
import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
15
|
+
const AT = "2026-10-06T01:02:03.000Z";
|
|
16
|
+
const CODEX = "019a0000-0000-7000-8000-000000000001";
|
|
17
|
+
const WINDOW = "019a0000-0000-7000-8000-000000000010";
|
|
18
|
+
const rows = (values) => values.map((value) => JSON.stringify(value) + "\n").join("");
|
|
19
|
+
function data(outcome) { assert.ok(outcome.ok, JSON.stringify(outcome)); return outcome.data; }
|
|
20
|
+
function refusal(outcome, code) { assert.ok(!outcome.ok); assert.equal(outcome.error.code, code); return outcome.error.message; }
|
|
21
|
+
function projection(text = "needle", role = "user") {
|
|
22
|
+
const items = [1, 2, 3, 4, 5].map((seq) => ({ seq, windowId: "w", role, text: `${text} ${seq}`, createdAt: new Date(Date.parse(AT) + seq * 1000).toISOString() }));
|
|
23
|
+
return projectHistory([{ windowId: "w", items }], 5, new Set(items.map((item) => item.seq)));
|
|
24
|
+
}
|
|
25
|
+
function descriptor(harness, id, p = projection()) {
|
|
26
|
+
return { harness, id, modifiedAt: 0, load: async () => ({ projection: p }) };
|
|
27
|
+
}
|
|
28
|
+
function context(sessions, currentHarness = "pi") {
|
|
29
|
+
return { current: () => projection("current"), corpus: { currentHarness, sessions: async () => sessions } };
|
|
30
|
+
}
|
|
31
|
+
async function fixture(t) {
|
|
32
|
+
const home = await mkdtemp(join(tmpdir(), "notesoup-history-corpus-"));
|
|
33
|
+
t.after(() => rm(home, { recursive: true, force: true }));
|
|
34
|
+
const roots = { pi: join(home, ".pi/agent/sessions"), claude: join(home, ".claude/projects"), codex: join(home, ".codex/sessions") };
|
|
35
|
+
async function put(path, content, modified = 1) {
|
|
36
|
+
await mkdir(dirname(path), { recursive: true });
|
|
37
|
+
await writeFile(path, content);
|
|
38
|
+
await utimes(path, modified, modified);
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
const piPath = await put(join(roots.pi, "--workspace--", "2026-10-06T01-02-03_pi-one.jsonl"), rows([
|
|
42
|
+
{ type: "session", version: 3, id: "pi-one", cwd: "/workspace", timestamp: AT },
|
|
43
|
+
{ type: "message", id: "u", parentId: null, timestamp: AT, message: { role: "user", content: "😀 Pi NEEDLE" } },
|
|
44
|
+
{ type: "message", id: "a", parentId: "u", timestamp: "2026-10-06T01:02:05Z", message: { role: "assistant", content: [{ type: "toolCall", id: "t", name: "read", arguments: { path: "needle.md" } }] } },
|
|
45
|
+
{ type: "message", id: "r", parentId: "a", timestamp: "2026-10-06T01:02:06Z", message: { role: "toolResult", toolCallId: "t", toolName: "read", content: [{ type: "text", text: "needle tool output" }] } },
|
|
46
|
+
]), 10);
|
|
47
|
+
const claudePath = await put(join(roots.claude, "--workspace--", "claude-one.jsonl"), rows([
|
|
48
|
+
{ type: "user", uuid: "c1", parentUuid: null, sessionId: "claude-one", timestamp: "2026-10-06T01:02:04Z", message: { role: "user", content: "Claude needle" } },
|
|
49
|
+
{ type: "system", uuid: "c2", parentUuid: "c1", sessionId: "claude-one", timestamp: "2026-10-06T01:02:07Z", content: "Claude context needle" },
|
|
50
|
+
]), 20);
|
|
51
|
+
const codexText = rows([
|
|
52
|
+
{ type: "session_meta", timestamp: AT, payload: { id: CODEX, cwd: "/workspace", cli_version: "0.160.1", context_window: { window_id: WINDOW } } },
|
|
53
|
+
{ type: "response_item", timestamp: "2026-10-06T01:02:08Z", payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: "Codex needle" }] } },
|
|
54
|
+
]);
|
|
55
|
+
const codexPath = await put(join(roots.codex, "2026/10/06", `rollout-2026-10-06T01-02-03-${CODEX}.jsonl.zst`), zstdCompressSync(Buffer.from(codexText)), 30);
|
|
56
|
+
const current = descriptor("pi", "current", projection("current"));
|
|
57
|
+
const corpus = localHistoryCorpus({ home, env: {}, current });
|
|
58
|
+
const ctx = { current: () => projection("current"), corpus };
|
|
59
|
+
return { home, roots, put, ctx, corpus, piPath, claudePath, codexPath, codexText };
|
|
60
|
+
}
|
|
61
|
+
test("session schemas are optional and non-empty, while the current projection keeps its exact wire shape", async () => {
|
|
62
|
+
for (const operation of [historyList, historyRead]) {
|
|
63
|
+
const params = operation === historyRead ? { seq: 1 } : {};
|
|
64
|
+
assert.equal(Check(operation.parameters, params), true);
|
|
65
|
+
assert.equal(Check(operation.parameters, { ...params, session: "" }), false);
|
|
66
|
+
assert.equal(Check(operation.parameters, { ...params, session: "claude:a" }), true);
|
|
67
|
+
}
|
|
68
|
+
const p = projection();
|
|
69
|
+
const page = await historyList.execute({ limit: 1 }, p);
|
|
70
|
+
assert.ok(Check(historyList.outputSchema, page.ok ? page.data : page));
|
|
71
|
+
assert.equal("session" in data(page).items[0], false);
|
|
72
|
+
assert.deepEqual(data(page).page_older, { before_seq: 5 });
|
|
73
|
+
assert.match(historyList.render(page), /^seq 5 \| user/);
|
|
74
|
+
assert.doesNotMatch(historyList.render(page), /session/);
|
|
75
|
+
const read = await historyRead.execute({ seq: 3 }, p);
|
|
76
|
+
assert.equal("session" in data(read), false);
|
|
77
|
+
assert.doesNotMatch(historyRead.render(read), /session/);
|
|
78
|
+
});
|
|
79
|
+
test("single selectors resolve exact before prefix, prefer the current harness, then fall back across harnesses", async () => {
|
|
80
|
+
const ctx = context([descriptor("pi", "same-long"), descriptor("claude", "same"), descriptor("codex", "other-exact"), descriptor("pi", "exact"), descriptor("pi", "exact-long")]);
|
|
81
|
+
assert.equal(data(await historyRead.execute({ session: "same", seq: 1 }, ctx)).session, "pi:same-long");
|
|
82
|
+
assert.equal(data(await historyRead.execute({ session: "claude:same", seq: 1 }, ctx)).session, "claude:same");
|
|
83
|
+
assert.equal(data(await historyRead.execute({ session: "exact", seq: 1 }, ctx)).session, "pi:exact");
|
|
84
|
+
assert.equal(data(await historyRead.execute({ session: "other-", seq: 1 }, ctx)).session, "codex:other-exact");
|
|
85
|
+
refusal(await historyRead.execute({ session: "absent", seq: 1 }, ctx), "unknown_session");
|
|
86
|
+
refusal(await historyList.execute({ session: "dsh:absent" }, ctx), "unknown_session");
|
|
87
|
+
refusal(await historyRead.execute({ session: "pi:exact", seq: 1 }, projection()), "unknown_session");
|
|
88
|
+
for (const session of ["", "wat:id", "pi:", "pi:a:b"]) {
|
|
89
|
+
refusal(await historyList.execute({ session }, ctx), "invalid_session");
|
|
90
|
+
}
|
|
91
|
+
assert.equal(parseSessionSelector("dsh:a").ok, true);
|
|
92
|
+
});
|
|
93
|
+
test("ambiguous selectors name at most five qualified candidates and never load a guessed session", async () => {
|
|
94
|
+
const sessions = Array.from({ length: 7 }, (_, index) => ({ ...descriptor("pi", `prefix-${index}`), load: async () => { throw new Error("must not load"); } }));
|
|
95
|
+
const ctx = context(sessions);
|
|
96
|
+
const message = refusal(await historyList.execute({ session: "prefix" }, ctx), "ambiguous_session");
|
|
97
|
+
for (let index = 0; index < 5; index++)
|
|
98
|
+
assert.ok(message.includes(`pi:prefix-${index}`));
|
|
99
|
+
assert.ok(!message.includes("pi:prefix-5"));
|
|
100
|
+
refusal(await historyRead.execute({ session: "prefix", seq: 1 }, ctx), "ambiguous_session");
|
|
101
|
+
const foreign = context([descriptor("claude", "same"), descriptor("codex", "same")]);
|
|
102
|
+
const across = refusal(await historyList.execute({ session: "same" }, foreign), "ambiguous_session");
|
|
103
|
+
assert.match(across, /claude:same/);
|
|
104
|
+
assert.match(across, /codex:same/);
|
|
105
|
+
});
|
|
106
|
+
test("all single-session recipes preserve the resolved identity, including folded expand and read neighborhood", async () => {
|
|
107
|
+
const p = projectHistory([{ windowId: "w", items: [
|
|
108
|
+
{ seq: 1, windowId: "w", role: "user", text: "first" },
|
|
109
|
+
{ seq: 2, windowId: "w", role: "system", text: "hidden context" },
|
|
110
|
+
{ seq: 3, windowId: "w", role: "user", text: "middle" },
|
|
111
|
+
{ seq: 4, windowId: "w", role: "assistant", text: "last" },
|
|
112
|
+
] }], 4, new Set([1, 2, 3, 4]));
|
|
113
|
+
const ctx = context([descriptor("claude", "target-session", p)]);
|
|
114
|
+
const page = await historyList.execute({ session: "claude:target", limit: 1, after_seq: 1, before_seq: 5 }, ctx);
|
|
115
|
+
assert.deepEqual(data(page).page_older, { session: "claude:target-session", before_seq: 4 });
|
|
116
|
+
const first = await historyList.execute({ session: "target", from: "oldest", limit: 1 }, ctx);
|
|
117
|
+
assert.deepEqual(data(first).page_newer, { session: "claude:target-session", after_seq: 1, from: "oldest" });
|
|
118
|
+
const foldPage = await historyList.execute({ session: "target", limit: 3 }, ctx);
|
|
119
|
+
const expand = /→ expand: (\{[^\n]+\})/.exec(historyList.render(foldPage));
|
|
120
|
+
assert.ok(expand);
|
|
121
|
+
const recipe = JSON.parse(expand[1]);
|
|
122
|
+
assert.equal(recipe.session, "claude:target-session");
|
|
123
|
+
assert.deepEqual(data(await historyList.execute(recipe, ctx)).items.map((item) => "seq" in item ? item.seq : -1), [2]);
|
|
124
|
+
assert.match(historyList.render(foldPage), /session claude:target-session \| seq 1 \| user/);
|
|
125
|
+
const read = await historyRead.execute({ session: "target", seq: 3 }, ctx);
|
|
126
|
+
assert.equal(data(read).session, "claude:target-session");
|
|
127
|
+
assert.match(historyRead.render(read), /^session claude:target-session \| seq 3 \| user/);
|
|
128
|
+
assert.match(historyRead.render(read), /neighborhood.*"session":"claude:target-session"/);
|
|
129
|
+
assert.ok(Check(historyRead.outputSchema, data(read)));
|
|
130
|
+
assert.ok(Check(historyList.outputSchema, data(foldPage)));
|
|
131
|
+
});
|
|
132
|
+
test("wildcard refusals precede discovery, and read accepts no wildcard selector", async () => {
|
|
133
|
+
const ctx = { current: () => { throw new Error("must not load current"); }, corpus: { currentHarness: "pi", sessions: async () => { throw new Error("must not discover"); } } };
|
|
134
|
+
for (const query of [undefined, "", [], ["", ""]]) {
|
|
135
|
+
refusal(await historyList.execute({ session: "*", query }, ctx), "missing_query");
|
|
136
|
+
}
|
|
137
|
+
for (const bounds of [{ before_seq: 10 }, { after_seq: 1 }, { before_seq: 10, after_seq: 1 }]) {
|
|
138
|
+
refusal(await historyList.execute({ session: "*", query: "needle", ...bounds }, ctx), "invalid_bounds");
|
|
139
|
+
}
|
|
140
|
+
for (const session of ["*", "pi:*", "cl*", "dsh:pre*suffix"]) {
|
|
141
|
+
refusal(await historyRead.execute({ session, seq: 1 }, ctx), "invalid_session");
|
|
142
|
+
}
|
|
143
|
+
refusal(await historyList.execute({ session: "*", query: "needle", since: "not-a-date" }, ctx), "invalid_time");
|
|
144
|
+
});
|
|
145
|
+
test("native filesystem discovery decodes three harnesses, compressed Codex, and keeps source bytes/mtime unchanged", async (t) => {
|
|
146
|
+
const f = await fixture(t);
|
|
147
|
+
const paths = [f.piPath, f.claudePath, f.codexPath];
|
|
148
|
+
const before = await Promise.all(paths.map(async (path) => ({ bytes: await readFile(path), time: (await stat(path)).mtimeMs })));
|
|
149
|
+
const sessions = await f.corpus.sessions();
|
|
150
|
+
assert.deepEqual(sessions.map((session) => `${session.harness}:${session.id}`), ["pi:current", `codex:${CODEX}`, "claude:claude-one", "pi:pi-one"]);
|
|
151
|
+
const expected = [["pi:pi-one", 1, "😀 Pi NEEDLE"], ["claude:claude-one", 1, "Claude needle"], [`codex:${CODEX}`, 2, "Codex needle"]];
|
|
152
|
+
for (const [session, seq, text] of expected) {
|
|
153
|
+
const read = await historyRead.execute({ session, seq }, f.ctx);
|
|
154
|
+
assert.equal(data(read).text, text);
|
|
155
|
+
assert.equal(data(read).session, session);
|
|
156
|
+
assert.match(historyRead.render(read), new RegExp(`^session ${session} \\| seq ${seq} \\|`));
|
|
157
|
+
}
|
|
158
|
+
const tool = data(await historyRead.execute({ session: "pi:pi-one", seq: 3 }, f.ctx));
|
|
159
|
+
assert.equal(tool.tool, "read");
|
|
160
|
+
assert.match(tool.text, /needle\.md.*\n--- output ---\nneedle tool output/);
|
|
161
|
+
refusal(await historyRead.execute({ session: "pi:pi-one", seq: 4 }, f.ctx), "not_an_event");
|
|
162
|
+
for (let index = 0; index < paths.length; index++) {
|
|
163
|
+
assert.deepEqual(await readFile(paths[index]), before[index].bytes);
|
|
164
|
+
assert.equal((await stat(paths[index])).mtimeMs, before[index].time);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
test("wildcard query merges every role chronologically, limits from either end, and returns no folds/cursors", async (t) => {
|
|
168
|
+
const { ctx } = await fixture(t);
|
|
169
|
+
const result = await historyList.execute({ session: "*", query: ["", "nEeDlE"], limit: 20 }, ctx);
|
|
170
|
+
const page = data(result);
|
|
171
|
+
assert.deepEqual(page.items.map((item) => "role" in item ? [item.session, item.seq, item.role] : null), [
|
|
172
|
+
["pi:pi-one", 1, "user"], ["claude:claude-one", 1, "user"], ["pi:pi-one", 3, "tool"], ["claude:claude-one", 2, "context"], [`codex:${CODEX}`, 2, "assistant"],
|
|
173
|
+
]);
|
|
174
|
+
assert.equal(page.page_older, null);
|
|
175
|
+
assert.equal(page.page_newer, null);
|
|
176
|
+
const newest = data(await historyList.execute({ session: "*", query: "needle", limit: 2 }, ctx));
|
|
177
|
+
assert.deepEqual(newest.items, page.items.slice(-2));
|
|
178
|
+
const oldest = data(await historyList.execute({ session: "*", query: "needle", limit: 2, from: "oldest" }, ctx));
|
|
179
|
+
assert.deepEqual(oldest.items, page.items.slice(0, 2));
|
|
180
|
+
const filtered = data(await historyList.execute({ session: "*", query: "needle", roles: ["tool", "context"], since: "2026-10-06T01:02:05", until: "2026-10-06T01:02:07Z" }, ctx));
|
|
181
|
+
assert.deepEqual(filtered.items.map((item) => "role" in item ? item.role : "folded"), ["tool"]);
|
|
182
|
+
const harness = data(await historyList.execute({ session: "claude:*", query: "needle" }, ctx));
|
|
183
|
+
assert.ok(harness.items.every((item) => "session" in item && item.session === "claude:claude-one"));
|
|
184
|
+
assert.equal(data(await historyList.execute({ session: "pi:absent*", query: "needle" }, ctx)).items.length, 0);
|
|
185
|
+
assert.ok(Check(historyList.outputSchema, page));
|
|
186
|
+
assert.match(historyList.render(result), /session pi:pi-one \| seq 1 \| user/);
|
|
187
|
+
});
|
|
188
|
+
test("query offsets and text continuation retain cross-session identity and Unicode coordinates", async (t) => {
|
|
189
|
+
const { ctx } = await fixture(t);
|
|
190
|
+
const page = data(await historyList.execute({ session: "pi:*", query: "NEEDLE", roles: ["user"], max_chars_per_item: 3 }, ctx));
|
|
191
|
+
const hit = page.items[0];
|
|
192
|
+
assert.ok("seq" in hit);
|
|
193
|
+
assert.equal(hit.offset_chars, 5);
|
|
194
|
+
assert.equal(hit.content, "NEE");
|
|
195
|
+
const read = data(await historyRead.execute({ session: hit.session, seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 3 }, ctx));
|
|
196
|
+
assert.equal(read.text, hit.content);
|
|
197
|
+
assert.equal(read.next_offset_chars, 8);
|
|
198
|
+
const tail = data(await historyRead.execute({ session: read.session, seq: hit.seq, offset_chars: read.next_offset_chars }, ctx));
|
|
199
|
+
assert.equal(tail.text, "DLE");
|
|
200
|
+
assert.equal(tail.session, "pi:pi-one");
|
|
201
|
+
});
|
|
202
|
+
test("wildcard glob metacharacters other than * stay literal, with deterministic timestamp ties", async () => {
|
|
203
|
+
const ctx = context([descriptor("pi", "a.b"), descriptor("pi", "axb"), descriptor("claude", "a.b")]);
|
|
204
|
+
const page = data(await historyList.execute({ session: "a.*", query: "needle", limit: 500 }, ctx));
|
|
205
|
+
assert.ok(page.items.every((item) => "session" in item && ["pi:a.b", "claude:a.b"].includes(item.session)));
|
|
206
|
+
assert.deepEqual(page.items.slice(0, 2).map((item) => "session" in item ? item.session : ""), ["claude:a.b", "pi:a.b"]);
|
|
207
|
+
});
|
|
208
|
+
test("root overrides/env homes are hermetic, missing roots are empty, and foreign reads never require the current projection", async (t) => {
|
|
209
|
+
const f = await fixture(t);
|
|
210
|
+
const roots = { pi: f.roots.pi, claude: null, codex: null };
|
|
211
|
+
const current = { harness: "dsh", id: "unreadable", load: async () => { throw new Error("current unavailable"); } };
|
|
212
|
+
const ctx = { current: () => { throw new Error("must not read current"); }, corpus: localHistoryCorpus({ roots, env: {}, home: join(f.home, "absent"), current }) };
|
|
213
|
+
assert.equal(data(await historyRead.execute({ session: "pi:pi-one", seq: 1 }, ctx)).session, "pi:pi-one");
|
|
214
|
+
assert.equal(data(await historyList.execute({ session: "pi:*", query: "needle" }, ctx)).items.length, 2);
|
|
215
|
+
const env = { PI_CODING_AGENT_DIR: dirname(f.roots.pi), CLAUDE_CONFIG_DIR: dirname(f.roots.claude), CODEX_HOME: dirname(f.roots.codex) };
|
|
216
|
+
const configured = localHistoryCorpus({ current, home: join(f.home, "absent"), env });
|
|
217
|
+
assert.equal((await configured.sessions()).length, 4);
|
|
218
|
+
const explicit = localHistoryCorpus({ current, home: join(f.home, "absent"), env: { NOTESOUP_HISTORY_PI_ROOT: f.roots.pi, NOTESOUP_HISTORY_CLAUDE_ROOT: f.roots.claude, NOTESOUP_HISTORY_CODEX_ROOT: f.roots.codex } });
|
|
219
|
+
assert.equal((await explicit.sessions()).length, 4);
|
|
220
|
+
refusal(await historyRead.execute({ session: "dsh:unreadable", seq: 1 }, ctx), "history_unavailable");
|
|
221
|
+
});
|
|
222
|
+
test("DSH service descriptors participate in resolution/search only when supplied; a live descriptor wins over disk", async (t) => {
|
|
223
|
+
const f = await fixture(t);
|
|
224
|
+
const corpus = localHistoryCorpus({ home: f.home, env: {}, current: descriptor("pi", "pi-one", projection("live needle")), dshSessions: async () => [descriptor("dsh", "dsh-one", projection("DSH needle", "system"))] });
|
|
225
|
+
const ctx = { current: () => projection(), corpus };
|
|
226
|
+
assert.equal(data(await historyRead.execute({ session: "dsh:dsh", seq: 1 }, ctx)).session, "dsh:dsh-one");
|
|
227
|
+
assert.equal(data(await historyRead.execute({ session: "pi-one", seq: 1 }, ctx)).text, "live needle 1");
|
|
228
|
+
const page = data(await historyList.execute({ session: "dsh:*", query: "needle" }, ctx));
|
|
229
|
+
assert.equal(page.items.length, 5);
|
|
230
|
+
assert.ok(page.items.every((item) => "role" in item && item.role === "context"));
|
|
231
|
+
assert.equal((await corpus.sessions()).filter((session) => session.harness === "pi" && session.id === "pi-one").length, 1);
|
|
232
|
+
});
|
|
233
|
+
test("oversized cross-session reads/searches obey both wire budgets and retain canonical identities", async () => {
|
|
234
|
+
const p = projection("😀".repeat(40_000));
|
|
235
|
+
const ctx = context([descriptor("codex", "long-id", p)]);
|
|
236
|
+
const list = await historyList.execute({ session: "*", query: "😀", max_chars_per_item: 50_000, limit: 500 }, ctx);
|
|
237
|
+
const page = data(list);
|
|
238
|
+
assert.ok(Buffer.byteLength(JSON.stringify(page)) <= TOOL_OUTPUT_MAX_BYTES);
|
|
239
|
+
assert.ok(Buffer.byteLength(historyList.render(list)) <= TOOL_OUTPUT_MAX_BYTES);
|
|
240
|
+
assert.equal(page.items.length, 1);
|
|
241
|
+
assert.equal(page.page_older, null);
|
|
242
|
+
assert.equal(page.page_newer, null);
|
|
243
|
+
const item = page.items[0];
|
|
244
|
+
assert.ok("seq" in item && item.truncated);
|
|
245
|
+
assert.equal(item.session, "codex:long-id");
|
|
246
|
+
const read = await historyRead.execute({ session: item.session, seq: item.seq, max_chars: 50_000 }, ctx);
|
|
247
|
+
assert.ok(Buffer.byteLength(JSON.stringify(data(read))) <= TOOL_OUTPUT_MAX_BYTES);
|
|
248
|
+
assert.ok(Buffer.byteLength(historyRead.render(read)) <= TOOL_OUTPUT_MAX_BYTES);
|
|
249
|
+
assert.equal(data(read).session, "codex:long-id");
|
|
250
|
+
assert.ok(data(read).next_offset_chars > 0);
|
|
251
|
+
});
|
|
252
|
+
test("qualified lookup and current-harness matches do not inspect unrelated roots", async (t) => {
|
|
253
|
+
const f = await fixture(t);
|
|
254
|
+
const notDirectory = join(f.home, "not-a-directory");
|
|
255
|
+
await writeFile(notDirectory, "unrelated root must not be traversed");
|
|
256
|
+
const current = descriptor("pi", "current");
|
|
257
|
+
const ctx = { current: () => projection(), corpus: localHistoryCorpus({ current, roots: { pi: f.roots.pi, claude: notDirectory, codex: null }, env: {} }) };
|
|
258
|
+
assert.equal(data(await historyRead.execute({ session: "pi-one", seq: 1 }, ctx)).session, "pi:pi-one");
|
|
259
|
+
assert.equal(data(await historyRead.execute({ session: "pi:pi-one", seq: 1 }, ctx)).session, "pi:pi-one");
|
|
260
|
+
assert.equal(data(await historyList.execute({ session: "pi:*", query: "needle" }, ctx)).items.length, 7);
|
|
261
|
+
});
|
|
262
|
+
test("cross-session Claude gaps are visible even on an empty page, budgeted, and outside document offsets", async (t) => {
|
|
263
|
+
const f = await fixture(t);
|
|
264
|
+
await f.put(f.claudePath, rows([{ type: "assistant", uuid: "head", parentUuid: "missing", sessionId: "claude-one", timestamp: AT, message: { role: "assistant", content: "😀needle" + "x".repeat(50_000) } }]));
|
|
265
|
+
const empty = await historyList.execute({ session: "claude:claude-one", query: "absent" }, f.ctx);
|
|
266
|
+
assert.equal(data(empty).items.length, 0);
|
|
267
|
+
assert.match(data(empty).notice, /missing ancestor.*"missing"/);
|
|
268
|
+
assert.match(historyList.render(empty), /Only confirmed ancestry.*\n\nNo events/);
|
|
269
|
+
const list = await historyList.execute({ session: "claude:*", query: "needle", max_chars_per_item: 50_000 }, f.ctx);
|
|
270
|
+
assert.ok(Buffer.byteLength(JSON.stringify(data(list))) <= TOOL_OUTPUT_MAX_BYTES);
|
|
271
|
+
assert.ok(Buffer.byteLength(historyList.render(list)) <= TOOL_OUTPUT_MAX_BYTES);
|
|
272
|
+
const hit = data(list).items[0];
|
|
273
|
+
assert.ok("seq" in hit);
|
|
274
|
+
assert.equal(hit.offset_chars, 1);
|
|
275
|
+
const read = await historyRead.execute({ session: hit.session, seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 50_000 }, f.ctx);
|
|
276
|
+
assert.match(data(read).notice, /history is incomplete/);
|
|
277
|
+
assert.ok(data(read).text.startsWith("needle"));
|
|
278
|
+
assert.ok(!data(read).text.includes("missing ancestor"));
|
|
279
|
+
assert.ok(Buffer.byteLength(JSON.stringify(data(read))) <= TOOL_OUTPUT_MAX_BYTES);
|
|
280
|
+
assert.ok(Buffer.byteLength(historyRead.render(read)) <= TOOL_OUTPUT_MAX_BYTES);
|
|
281
|
+
});
|
|
282
|
+
test("invalid persisted sessions refuse visibly instead of fabricating a successful partial corpus", async (t) => {
|
|
283
|
+
const f = await fixture(t);
|
|
284
|
+
await f.put(join(f.roots.pi, "--workspace--", "2026-10-06_broken.jsonl"), "not-json\n");
|
|
285
|
+
const message = refusal(await historyList.execute({ session: "pi:*", query: "needle" }, f.ctx), "history_unavailable");
|
|
286
|
+
assert.match(message, /pi:broken/);
|
|
287
|
+
refusal(await historyRead.execute({ session: "pi:broken", seq: 1 }, f.ctx), "history_unavailable");
|
|
288
|
+
});
|
|
289
|
+
test("offline Pi follows persisted parent links, preserves branch seq holes and rejects corrupt ancestry", async () => {
|
|
290
|
+
const base = { type: "session", version: 3, id: "branch", timestamp: AT };
|
|
291
|
+
const entry = (id, parentId, content) => ({ type: "message", id, parentId, timestamp: AT, message: { role: "user", content } });
|
|
292
|
+
const text = rows([base, entry("root", null, "root"), entry("left", "root", "left"), entry("right", "root", "right")]);
|
|
293
|
+
const p = piHistoryFromJsonl(text + '{"partial":', "branch");
|
|
294
|
+
assert.deepEqual(allItems(p).map((item) => [item.seq, item.text]), [[1, "root"], [3, "right"]]);
|
|
295
|
+
refusal(await historyRead.execute({ seq: 2 }, p), "not_on_branch");
|
|
296
|
+
assert.throws(() => piHistoryFromJsonl(rows([base, entry("gap", "missing", "gap")]), "branch"), /missing parent/);
|
|
297
|
+
assert.throws(() => piHistoryFromJsonl(text + "bad\n", "branch"), /malformed Pi/);
|
|
298
|
+
assert.throws(() => piHistoryFromJsonl(text, "wrong"), /different session/);
|
|
299
|
+
});
|
|
300
|
+
test("offline Claude requires one evidenced leaf, accounts for logical compact links, and never guesses among branches", () => {
|
|
301
|
+
const user = (uuid, parentUuid) => ({ type: "user", uuid, parentUuid, sessionId: "s", message: { role: "user", content: "text" } });
|
|
302
|
+
assert.equal(offlineClaudeHead(rows([user("u", null), user("a", "u")])), "a");
|
|
303
|
+
assert.equal(offlineClaudeHead(rows([user("u", null), { type: "system", uuid: "b", parentUuid: null, logicalParentUuid: "u", subtype: "compact_boundary" }, user("a", "b")])), "a");
|
|
304
|
+
assert.equal(offlineClaudeHead(rows([user("u", null), user("preserved", null), { type: "system", uuid: "b", parentUuid: null, logicalParentUuid: "u", subtype: "compact_boundary", compactMetadata: { preservedSegment: { headUuid: "preserved", tailUuid: "preserved" } } }, user("a", "b")])), "a");
|
|
305
|
+
assert.throws(() => offlineClaudeHead(rows([user("u", null), user("left", "u"), user("right", "u")])), /2 possible heads/);
|
|
306
|
+
assert.throws(() => offlineClaudeHead(""), /0 possible heads/);
|
|
307
|
+
});
|
|
@@ -3,11 +3,15 @@ import test from "node:test";
|
|
|
3
3
|
import { Check } from "typebox/value";
|
|
4
4
|
import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
5
5
|
import { earliestMatchOffsetChars } from "../src/text-match.js";
|
|
6
|
-
import { historyList, historyRead
|
|
6
|
+
import { historyList, historyRead } from "../src/tools/history.js";
|
|
7
7
|
import { historyDocument, projectHistory } from "../src/history/history.js";
|
|
8
8
|
import { selectPage } from "../src/history/query.js";
|
|
9
9
|
import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
|
|
10
10
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
11
|
+
import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
|
|
12
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
11
15
|
installExtensionTestHooks("notesoup-history-v2");
|
|
12
16
|
/** Append a message the way the host records one, without the harness's per-role sugar. */
|
|
13
17
|
function append(session, message) {
|
|
@@ -29,6 +33,22 @@ function seqs(result) {
|
|
|
29
33
|
function rendered(result) {
|
|
30
34
|
return result.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("");
|
|
31
35
|
}
|
|
36
|
+
test("Pi registered tools resolve another persisted session and propagate its identity", async (t) => {
|
|
37
|
+
const home = await mkdtemp(join(tmpdir(), "notesoup-pi-corpus-"));
|
|
38
|
+
t.after(() => rm(home, { recursive: true, force: true }));
|
|
39
|
+
const roots = isolateHistoryRoots(t, home);
|
|
40
|
+
await writePiTranscript(roots.pi, "foreign-pi");
|
|
41
|
+
const session = manager(), captured = makeExtension(session), ctx = context(session);
|
|
42
|
+
appendText(session, "user", "live needle");
|
|
43
|
+
const read = await call(captured, "history_read", { session: "pi:foreign", seq: 1 }, ctx);
|
|
44
|
+
assert.equal(resultData(read).session, "pi:foreign-pi");
|
|
45
|
+
assert.match(rendered(read), /foreign needle/);
|
|
46
|
+
const across = page(await call(captured, "history_list", { session: "pi:*", query: "needle" }, ctx));
|
|
47
|
+
assert.equal(across.items.length, 2);
|
|
48
|
+
assert.ok(across.items.every((item) => typeof item.session === "string"));
|
|
49
|
+
const current = resultData(await call(captured, "history_read", { session: `pi:${session.getSessionId()}`, seq: 1 }, ctx));
|
|
50
|
+
assert.equal(current.session, `pi:${session.getSessionId()}`);
|
|
51
|
+
});
|
|
32
52
|
test("history_list exposes bounded paging, `from` and a literal query, while notes use snapshot limits", () => {
|
|
33
53
|
const captured = makeExtension(manager());
|
|
34
54
|
const readSchema = captured.tools.get("history_read")?.parameters;
|
|
@@ -64,8 +84,8 @@ test("history_list exposes bounded paging, `from` and a literal query, while not
|
|
|
64
84
|
for (const invalid of [{ roles: ["tool_call"] }, { roles: ["system"] }, { tool_name: "bash" }, { roles: [] }]) {
|
|
65
85
|
assert.equal(Check(listSchema, invalid), false, JSON.stringify(invalid));
|
|
66
86
|
}
|
|
67
|
-
|
|
68
|
-
assert.
|
|
87
|
+
assert.deepEqual(Object.keys(properties).sort(), ["session", "query", "roles", "before_seq", "after_seq", "since", "until", "from", "limit", "max_chars_per_item"].sort());
|
|
88
|
+
assert.equal(Check(listSchema, { window_id: "anything" }), false, "unknown filters are rejected before selection");
|
|
69
89
|
const notesSchema = captured.tools.get("notes_list")?.parameters;
|
|
70
90
|
assert.equal(notesSchema.properties?.cursor, undefined);
|
|
71
91
|
assert.ok(notesSchema.properties?.limit);
|
|
@@ -80,12 +100,19 @@ test("every history operation declares a result schema its own payload satisfies
|
|
|
80
100
|
appendText(session, "user", "hello");
|
|
81
101
|
toolCall(session, "call-1", "bash", { command: "pwd" });
|
|
82
102
|
toolResult(session, "call-1", "bash", "/tmp");
|
|
83
|
-
for (const toolName of ["
|
|
84
|
-
const operation = {
|
|
85
|
-
const result = await call(captured, toolName, toolName === "history_read" ? { seq: 1 } :
|
|
103
|
+
for (const toolName of ["history_list", "history_read"]) {
|
|
104
|
+
const operation = { history_list: historyList, history_read: historyRead }[toolName];
|
|
105
|
+
const result = await call(captured, toolName, toolName === "history_read" ? { seq: 1 } : { query: "hello" }, ctx);
|
|
86
106
|
const structured = result.structuredContent;
|
|
87
107
|
assert.ok(structured !== undefined, `${toolName} carries a structured outcome`);
|
|
88
108
|
assert.equal(Check(operation.outputSchema, structured), true, `${toolName} payload satisfies its own outputSchema`);
|
|
109
|
+
assert.equal(rendered(result).split("\n")[0], "seq 1 | user");
|
|
110
|
+
if (toolName === "history_list") {
|
|
111
|
+
assert.deepEqual(page(result).items, [{ seq: 1, role: "user", created_at: page(result).items[0].created_at, content: "hello", truncated: false, offset_chars: 0 }]);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
assert.deepEqual(Object.keys(resultData(result)).sort(), ["seq", "role", "created_at", "text", "total_chars", "next_offset_chars"].sort());
|
|
115
|
+
}
|
|
89
116
|
assertWithinBudget(result, `${toolName} page`);
|
|
90
117
|
}
|
|
91
118
|
const conversation = await call(captured, "history_list", {}, ctx);
|
|
@@ -459,7 +486,6 @@ test("standalone bash execution retains command, output, and truncation path", a
|
|
|
459
486
|
assert.equal(found.items.length, 1);
|
|
460
487
|
assert.deepEqual(found.items[0], {
|
|
461
488
|
seq: 1,
|
|
462
|
-
window_id: found.items[0].window_id,
|
|
463
489
|
role: "tool",
|
|
464
490
|
created_at: found.items[0].created_at,
|
|
465
491
|
tool: "bash",
|
|
@@ -493,7 +519,7 @@ test("a truncated tool run without a recorded path still reports output_truncate
|
|
|
493
519
|
assert.equal(read.output_truncated, true, "the read reports the same truncation");
|
|
494
520
|
assert.equal("full_output_path" in read, false);
|
|
495
521
|
});
|
|
496
|
-
test("list renders paging and fold recipes, read renders a neighborhood call
|
|
522
|
+
test("list renders paging and fold recipes across resets, and read renders a neighborhood call", async () => {
|
|
497
523
|
const session = manager();
|
|
498
524
|
const captured = makeExtension(session);
|
|
499
525
|
const ctx = context(session);
|
|
@@ -503,12 +529,12 @@ test("list renders paging and fold recipes, read renders a neighborhood call, an
|
|
|
503
529
|
appendText(session, "user", "current window");
|
|
504
530
|
const listed = await call(captured, "history_list", {}, ctx);
|
|
505
531
|
assert.match(rendered(listed), /→ older: \{"before_seq":\d+\}/, "the footer prints the exact call to page older");
|
|
506
|
-
const
|
|
507
|
-
assert.
|
|
508
|
-
const
|
|
509
|
-
assert.
|
|
510
|
-
const
|
|
511
|
-
assert.
|
|
532
|
+
const earlier = page(await call(captured, "history_list", { before_seq: 31, from: "oldest", limit: 30 }, ctx));
|
|
533
|
+
assert.deepEqual(earlier.items.map((item) => item.seq), Array.from({ length: 30 }, (_, index) => index + 1));
|
|
534
|
+
const earlierQuery = page(await call(captured, "history_list", { query: "older window", before_seq: 31 }, ctx));
|
|
535
|
+
assert.equal(earlierQuery.items.length, 20, "queries and seq bounds recover earlier windows without a separate address");
|
|
536
|
+
const current = await call(captured, "history_list", { after_seq: 30 }, ctx);
|
|
537
|
+
assert.match(rendered(current), /^seq 31 \| user\ncurrent window$/);
|
|
512
538
|
toolCall(session, "t1", "bash", { command: "ls" });
|
|
513
539
|
toolResult(session, "t1", "bash", "done");
|
|
514
540
|
appendText(session, "user", "after tools");
|
|
@@ -518,14 +544,6 @@ test("list renders paging and fold recipes, read renders a neighborhood call, an
|
|
|
518
544
|
const hits = page(await call(captured, "history_list", { query: "needle read target" }, ctx));
|
|
519
545
|
const read = await call(captured, "history_read", { seq: hits.items[0].seq }, ctx);
|
|
520
546
|
assert.match(rendered(read), /neighborhood → `history_list`\(\{"after_seq":\d+,"before_seq":\d+\}\)/, "a read prints the call for surrounding events");
|
|
521
|
-
const solo = manager();
|
|
522
|
-
const soloCaptured = makeExtension(solo);
|
|
523
|
-
appendText(solo, "user", "only window");
|
|
524
|
-
const soloWindows = resultData(await call(soloCaptured, "history_windows", {}, context(solo)));
|
|
525
|
-
const noPrevious = resultError(await call(soloCaptured, "history_list", { window_id: "@previous" }, context(solo)));
|
|
526
|
-
assert.equal(noPrevious.code, "unknown_window_id");
|
|
527
|
-
assert.match(noPrevious.message, /@previous/);
|
|
528
|
-
assert.match(noPrevious.message, new RegExp(`${soloWindows.windows[0].window_id}\\.$`), "the refusal names the window the session does have");
|
|
529
547
|
});
|
|
530
548
|
test("compaction summary becomes context and is folded in the default list", async () => {
|
|
531
549
|
const session = manager();
|
|
@@ -639,7 +657,6 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
639
657
|
assertWithinBudget(full, "history_read page");
|
|
640
658
|
const read = resultRead(full);
|
|
641
659
|
assert.equal(read.seq, seq);
|
|
642
|
-
assert.ok(read.window_id.length > 0);
|
|
643
660
|
assert.equal(read.total_chars, content.length);
|
|
644
661
|
assert.equal(read.content, content.slice(0, read.content.length), "the delivered slice is a verbatim prefix");
|
|
645
662
|
assert.equal(read.next_offset_chars !== null, true);
|
|
@@ -661,27 +678,6 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
661
678
|
assert.equal(past.code, "invalid_offset");
|
|
662
679
|
assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
|
|
663
680
|
});
|
|
664
|
-
test("history windows expose stable ranges and include host decoration in the complete budget", async () => {
|
|
665
|
-
const session = manager();
|
|
666
|
-
const captured = makeExtension(session);
|
|
667
|
-
const ctx = context(session);
|
|
668
|
-
appendText(session, "user", "before");
|
|
669
|
-
const windows = resultData(await call(captured, "history_windows", {}, ctx));
|
|
670
|
-
assert.equal(windows.session_id, session.getSessionId());
|
|
671
|
-
assert.equal(windows.windows.length, 1);
|
|
672
|
-
assert.deepEqual(windows.windows[0], { window_id: windows.windows[0].window_id, created_at: null, first_seq: 1, last_seq: 1 });
|
|
673
|
-
const projection = projectHistory([0, 1, 2].map((index) => ({ windowId: `w${index}-${"x".repeat(200)}`, items: [] })), 0, new Set());
|
|
674
|
-
const notice = `${"n".repeat(TOOL_OUTPUT_MAX_BYTES - 400)}\n`;
|
|
675
|
-
const wrapText = (text) => notice + text;
|
|
676
|
-
const bounded = await historyWindows.execute({}, projection, "session-x", wrapText);
|
|
677
|
-
assert.ok(bounded.ok);
|
|
678
|
-
assert.equal(bounded.data.windows.length, 1);
|
|
679
|
-
assert.equal(bounded.data.more, 2);
|
|
680
|
-
const text = wrapText(historyWindows.render(bounded));
|
|
681
|
-
assert.ok(Buffer.byteLength(text, "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
682
|
-
assert.ok(text.startsWith(notice), "decoration is measured, never clipped at delivery");
|
|
683
|
-
assert.match(text, /2 more windows not shown/);
|
|
684
|
-
});
|
|
685
681
|
test("historyDocument is one deterministic projection of the facts, with no UI header or continuation suffix", async () => {
|
|
686
682
|
const windowId = "w1";
|
|
687
683
|
const items = [
|
|
@@ -722,8 +718,4 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
|
|
|
722
718
|
assert.equal(listed.ok, true);
|
|
723
719
|
if (listed.ok)
|
|
724
720
|
assert.equal(listed.data.items.some((item) => "folded" in item && item.count === 1), true);
|
|
725
|
-
const windows = await historyWindows.execute({}, projection, "session-x");
|
|
726
|
-
assert.equal(windows.ok, true);
|
|
727
|
-
if (windows.ok)
|
|
728
|
-
assert.equal(windows.data.session_id, "session-x");
|
|
729
721
|
});
|
|
@@ -10,7 +10,8 @@ import { renderBootBlock } from "../src/boot/render.js";
|
|
|
10
10
|
import { HistoryPageItemSchema, HistoryRoleSchema, projectHistory } from "../src/history/history.js";
|
|
11
11
|
import { createNotesStore } from "../src/notes/store.js";
|
|
12
12
|
import { notesWrite, notesUpdate, notesRead } from "../src/tools/notes.js";
|
|
13
|
-
import {
|
|
13
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
14
|
+
import { historyList, historyRead } from "../src/tools/history.js";
|
|
14
15
|
import { historyRoles } from "../src/tools/schema.js";
|
|
15
16
|
import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
16
17
|
import { ERROR_MESSAGE_MAX_CHARS, failure, fitsResult, resultSchema, wireResult, readTextWindow, renderOutcome, renderTextWindow, success, structuredBytes, } from "../src/tools/result.js";
|
|
@@ -181,51 +182,52 @@ test("structuredBytes has no size for a value with no JSON representation", () =
|
|
|
181
182
|
});
|
|
182
183
|
test("shared note operations return canonical outcomes with a body-only read window", async (t) => {
|
|
183
184
|
const notesIdentity = identity(t);
|
|
184
|
-
const
|
|
185
|
+
const toolContext = notesToolContext(notesIdentity, "/work/explicit");
|
|
186
|
+
const written = data(await notesWrite.execute({ address: "@project/test.md", content: "alpha\nbeta" }, toolContext));
|
|
185
187
|
assert.equal(written.address, "@project/test.md");
|
|
186
188
|
assert.equal(written.project_key, notesIdentity.projectKey);
|
|
187
189
|
assert.equal(written.outcome, "created");
|
|
188
|
-
const updated = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "alpha", newText: "gamma" }] },
|
|
190
|
+
const updated = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "alpha", newText: "gamma" }] }, toolContext, (change) => {
|
|
189
191
|
assert.equal(change.kind, "body");
|
|
190
192
|
return "caller-rendered-diff";
|
|
191
193
|
}));
|
|
192
194
|
assert.equal(updated.change_kind, "body");
|
|
193
195
|
assert.equal(updated.diff, "caller-rendered-diff");
|
|
194
|
-
const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] },
|
|
196
|
+
const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] }, toolContext));
|
|
195
197
|
assert.equal(defaultReceipt.diff, "note body");
|
|
196
|
-
await notesWrite.execute({ address: "owned.md", content: "first", origin: "user" },
|
|
197
|
-
await notesWrite.execute({ address: "owned.md", content: "rewritten" },
|
|
198
|
-
assert.equal(data(await notesRead.execute({ address: "owned.md" },
|
|
199
|
-
const invalid = refusal(await notesUpdate.execute({ address: "owned.md", edits: [{ oldText: "", newText: "x" }] },
|
|
198
|
+
await notesWrite.execute({ address: "owned.md", content: "first", origin: "user" }, toolContext);
|
|
199
|
+
await notesWrite.execute({ address: "owned.md", content: "rewritten" }, toolContext);
|
|
200
|
+
assert.equal(data(await notesRead.execute({ address: "owned.md" }, toolContext)).metadata.origin, "user", "tool overwrites preserve an omitted origin");
|
|
201
|
+
const invalid = refusal(await notesUpdate.execute({ address: "owned.md", edits: [{ oldText: "", newText: "x" }] }, toolContext));
|
|
200
202
|
assert.equal(invalid.code, "invalid_edit");
|
|
201
|
-
const moved = data(await notesUpdate.execute({ address: "owned.md", rename_to: "@project/renamed.md", edits: [{ oldText: "rewritten", newText: "final" }], origin: "external" },
|
|
203
|
+
const moved = data(await notesUpdate.execute({ address: "owned.md", rename_to: "@project/renamed.md", edits: [{ oldText: "rewritten", newText: "final" }], origin: "external" }, toolContext));
|
|
202
204
|
assert.equal(moved.change_kind, "moved");
|
|
203
205
|
assert.equal(moved.rename_from, "owned.md");
|
|
204
206
|
assert.match(moved.diff, /rename owned\.md -> @project\/renamed\.md/);
|
|
205
|
-
const renamed = data(await notesRead.execute({ address: moved.address },
|
|
207
|
+
const renamed = data(await notesRead.execute({ address: moved.address }, toolContext));
|
|
206
208
|
assert.equal(renamed.text, "final");
|
|
207
209
|
assert.equal(renamed.metadata.origin, "external");
|
|
208
|
-
const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] },
|
|
210
|
+
const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] }, toolContext));
|
|
209
211
|
assert.equal(unchanged.change_kind, "none");
|
|
210
212
|
assert.equal(unchanged.diff, "");
|
|
211
213
|
// Frontmatter is metadata, not body: the window addresses the body and counts only the body.
|
|
212
214
|
const stored = await createNotesStore(notesIdentity).read("@project/test.md");
|
|
213
215
|
assert.ok(stored, "the note is on disk");
|
|
214
216
|
const body = Array.from(stored.body);
|
|
215
|
-
const read = data(await notesRead.execute({ address: "@project/test.md" },
|
|
217
|
+
const read = data(await notesRead.execute({ address: "@project/test.md" }, toolContext));
|
|
216
218
|
assert.equal(read.text, stored.body, "a complete read is the whole body and nothing else");
|
|
217
219
|
assert.equal(read.total_chars, body.length);
|
|
218
220
|
assert.equal(read.next_offset_chars, null);
|
|
219
221
|
assert.equal(read.metadata.origin, "self");
|
|
220
222
|
assert.equal(notesRead.render(success(read)).includes("READ WINDOW"), false, "a read presents no metadata block");
|
|
221
223
|
// A negative offset resolves against the body, never against the serialized file.
|
|
222
|
-
const tail = data(await notesRead.execute({ address: "@project/test.md", offset_chars: -4 },
|
|
224
|
+
const tail = data(await notesRead.execute({ address: "@project/test.md", offset_chars: -4 }, toolContext));
|
|
223
225
|
assert.equal(tail.text, body.slice(-4).join(""));
|
|
224
226
|
assert.equal(tail.total_chars, body.length, "metadata length never enters the body cursor");
|
|
225
227
|
assert.equal(tail.next_offset_chars, null);
|
|
226
|
-
assert.equal(refusal(await notesRead.execute({ address: "@project/missing.md" },
|
|
227
|
-
assert.equal(refusal(await notesWrite.execute({ address: "../escape", content: "x" },
|
|
228
|
-
assert.equal(refusal(await notesRead.execute({ address: "@project/test.md", offset_chars: 99_999 },
|
|
228
|
+
assert.equal(refusal(await notesRead.execute({ address: "@project/missing.md" }, toolContext)).code, "not_found");
|
|
229
|
+
assert.equal(refusal(await notesWrite.execute({ address: "../escape", content: "x" }, toolContext)).code, "invalid_address");
|
|
230
|
+
assert.equal(refusal(await notesRead.execute({ address: "@project/test.md", offset_chars: 99_999 }, toolContext)).code, "invalid_offset");
|
|
229
231
|
});
|
|
230
232
|
test("shared history operations read typed events through the addresses the adapter allocated", async () => {
|
|
231
233
|
const projection = projectHistory([{ windowId: "root", items: [
|
|
@@ -233,12 +235,8 @@ test("shared history operations read typed events through the addresses the adap
|
|
|
233
235
|
{ seq: 2, windowId: "root", role: "tool_call", text: "", toolName: "read", toolCallId: "call", arguments: { path: "one.md" } },
|
|
234
236
|
{ seq: 3, windowId: "root", role: "tool", text: "😀 needle output", toolName: "read", toolCallId: "call" },
|
|
235
237
|
] }], 3, new Set([1, 2, 3]));
|
|
236
|
-
const windows = data(await historyWindows.execute({}, projection, "explicit-session"));
|
|
237
|
-
assert.equal(windows.session_id, "explicit-session");
|
|
238
|
-
assert.equal(windows.windows.length, 1);
|
|
239
|
-
assert.deepEqual(windows.windows[0], { window_id: "root", created_at: null, first_seq: 1, last_seq: 2 }, "a call and its result are one event, not two");
|
|
240
238
|
const listed = data(await historyList.execute({ roles: ["tool"] }, projection));
|
|
241
|
-
assert.
|
|
239
|
+
assert.deepEqual(listed.items.map((item) => "seq" in item ? item.seq : -1), [2], "a call and its result are one event, not two");
|
|
242
240
|
const item = listed.items[0];
|
|
243
241
|
assert.ok(item && !('folded' in item), "the tool event carries an address");
|
|
244
242
|
const seq = item.seq;
|
|
@@ -264,20 +262,9 @@ test("shared history operations read typed events through the addresses the adap
|
|
|
264
262
|
assert.match(refusal(await historyRead.execute({ seq: 9_999 }, projection)).message, /9,?999/, "an unknown address is refused by name");
|
|
265
263
|
assert.equal(refusal(await historyRead.execute({ seq: 3 }, projection)).code, "not_an_event", "a paired result address is refused");
|
|
266
264
|
});
|
|
267
|
-
test("an unknown window_id names at most five known windows in its message", async () => {
|
|
268
|
-
const windows = Array.from({ length: 7 }, (_, index) => ({ windowId: `pcw:w${index}`, items: [{ seq: index + 1, windowId: `pcw:w${index}`, role: "user", text: `message-${index}` }] }));
|
|
269
|
-
const projection = projectHistory(windows, 7, new Set([1, 2, 3, 4, 5, 6, 7]));
|
|
270
|
-
const outcome = await historyList.execute({ window_id: "pcw:absent" }, projection);
|
|
271
|
-
assert.equal(outcome.ok, false);
|
|
272
|
-
if (!outcome.ok) {
|
|
273
|
-
assert.equal(outcome.error.code, "unknown_window_id");
|
|
274
|
-
assert.match(outcome.error.message, /"pcw:absent".*pcw:w0, pcw:w1, pcw:w2, pcw:w3, pcw:w4\.$/, "the message names the known windows itself");
|
|
275
|
-
assert.equal(outcome.error.message.includes("pcw:w5"), false, "at most five known windows are named");
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
265
|
test("one role schema declares the four public roles for the page item, the read payload, and the role filter", () => {
|
|
279
266
|
const read = (role) => ({
|
|
280
|
-
seq: 1,
|
|
267
|
+
seq: 1, role, created_at: null,
|
|
281
268
|
text: "", total_chars: 0, next_offset_chars: null,
|
|
282
269
|
});
|
|
283
270
|
assert.equal(HistoryPageItemSchema.properties.role, HistoryRoleSchema, "the page item reuses the authoritative role schema");
|