notesoup 0.60.1 → 0.62.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/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -10
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.d.ts +5 -0
- package/dist/src/boot/render.js +60 -28
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +27 -26
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/frontmatter.d.ts +4 -0
- package/dist/src/notes/frontmatter.js +15 -1
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +47 -6
- package/dist/src/notes/store.d.ts +14 -0
- package/dist/src/notes/store.js +33 -12
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -91
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +58 -160
- package/dist/src/tools/notes.js +151 -99
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +198 -16
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +65 -2
- package/dist/test/helpers/extension.js +72 -3
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/note-policy.test.js +189 -56
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +4 -4
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +6 -6
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +3 -3
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1129 -549
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18494 -17905
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +3 -3
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +2 -2
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +59 -25
- package/src/boot/text.ts +30 -27
- package/src/budget/text.ts +13 -13
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +1 -1
- package/src/notes/frontmatter.ts +16 -1
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +45 -6
- package/src/notes/store.ts +30 -15
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +150 -112
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
|
@@ -3,11 +3,12 @@ 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 } from "../src/tools/history.js";
|
|
6
|
+
import { historyList, historySearch, historyRead } from "../src/tools/history.js";
|
|
7
7
|
import { historyDocument, projectHistory } from "../src/history/history.js";
|
|
8
|
-
import { CorpusCollector,
|
|
9
|
-
import { appendText, assertWithinBudget, call, context, makeExtension, manager,
|
|
8
|
+
import { CorpusCollector, selectPage } from "../src/history/query.js";
|
|
9
|
+
import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultText, resultTextError, } from "./helpers/extension.js";
|
|
10
10
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
11
|
+
import { historyFromSession } from "../plugins/pi/history.js";
|
|
11
12
|
import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
|
|
12
13
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
13
14
|
import { tmpdir } from "node:os";
|
|
@@ -23,11 +24,20 @@ function toolCall(session, id, name, args) {
|
|
|
23
24
|
function toolResult(session, id, name, text, extra = {}) {
|
|
24
25
|
return append(session, { role: "toolResult", toolCallId: id, toolName: name, content: [{ type: "text", text }], isError: false, timestamp: Date.now(), ...extra });
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
27
|
+
async function listData(session, params = {}) {
|
|
28
|
+
const result = await historyList.execute(params, historyFromSession({ sessionManager: session }));
|
|
29
|
+
assert.ok(result.ok);
|
|
30
|
+
return result.data;
|
|
28
31
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
32
|
+
async function searchData(session, params) {
|
|
33
|
+
const result = await historySearch.execute(params, historyFromSession({ sessionManager: session }));
|
|
34
|
+
assert.ok(result.ok);
|
|
35
|
+
return result.data;
|
|
36
|
+
}
|
|
37
|
+
async function readData(session, params) {
|
|
38
|
+
const result = await historyRead.execute(params, historyFromSession({ sessionManager: session }));
|
|
39
|
+
assert.ok(result.ok);
|
|
40
|
+
return result.data;
|
|
31
41
|
}
|
|
32
42
|
/** What the model reads for one result, so a test can check the text surface directly. */
|
|
33
43
|
function rendered(result) {
|
|
@@ -41,46 +51,39 @@ test("Pi registered tools resolve another persisted session and propagate its id
|
|
|
41
51
|
const session = manager(), captured = makeExtension(session), ctx = context(session);
|
|
42
52
|
appendText(session, "user", "live needle");
|
|
43
53
|
const read = await call(captured, "history_read", { session: "pi:foreign", seq: 1 }, ctx);
|
|
44
|
-
assert.
|
|
54
|
+
assert.match(resultText(read), /session pi:foreign-pi \| seq 1/);
|
|
45
55
|
assert.match(rendered(read), /foreign needle/);
|
|
46
|
-
const across =
|
|
47
|
-
assert.
|
|
48
|
-
assert.ok(across.
|
|
49
|
-
const current =
|
|
50
|
-
assert.
|
|
56
|
+
const across = resultText(await call(captured, "history_search", { session: "pi:*", query: "needle" }, ctx));
|
|
57
|
+
assert.match(across, /=== session pi:foreign-pi ===\nseq 1/);
|
|
58
|
+
assert.ok(across.includes(`session pi:${session.getSessionId()} ===\nseq 1`));
|
|
59
|
+
const current = resultText(await call(captured, "history_read", { session: `pi:${session.getSessionId()}`, seq: 1 }, ctx));
|
|
60
|
+
assert.ok(current.includes(`session pi:${session.getSessionId()} | seq 1`));
|
|
51
61
|
});
|
|
52
62
|
test("Pi registers the shared history schemas", () => {
|
|
53
63
|
const captured = makeExtension(manager());
|
|
54
64
|
const listSchema = captured.tools.get("history_list").parameters;
|
|
55
65
|
assert.deepEqual(listSchema, historyList.parameters);
|
|
56
|
-
assert.ok(Check(listSchema, { after: 0, before:
|
|
66
|
+
assert.ok(Check(listSchema, { after: 0, before: 10 }));
|
|
67
|
+
assert.ok(Check(listSchema, { since: "2026-10-10", until: "2026-10-11" }));
|
|
68
|
+
for (const params of [{ after: "2" }, { before: "2026-10-10" }, { after: -1 }, { query: "needle" }, { context: 1 }])
|
|
69
|
+
assert.equal(Check(listSchema, params), false);
|
|
70
|
+
const searchSchema = captured.tools.get("history_search").parameters;
|
|
71
|
+
assert.deepEqual(searchSchema, historySearch.parameters);
|
|
72
|
+
assert.ok(Check(searchSchema, { since: "2026-10-10", query: "needle", context: 1 }));
|
|
73
|
+
assert.equal(Check(searchSchema, { after: 1 }), false);
|
|
74
|
+
assert.equal(Check(searchSchema, { session: "*" }), false);
|
|
57
75
|
assert.deepEqual(captured.tools.get("history_read").parameters, historyRead.parameters);
|
|
58
76
|
});
|
|
59
|
-
test("
|
|
60
|
-
const session = manager();
|
|
61
|
-
const captured = makeExtension(session);
|
|
62
|
-
const ctx = context(session);
|
|
77
|
+
test("history tools expose bounded plain text and plain-text refusals", async () => {
|
|
78
|
+
const session = manager(), captured = makeExtension(session), ctx = context(session);
|
|
63
79
|
appendText(session, "user", "hello");
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const structured = result.structuredContent;
|
|
70
|
-
assert.ok(structured !== undefined, `${toolName} carries a structured outcome`);
|
|
71
|
-
assert.equal(Check(operation.outputSchema, structured), true, `${toolName} payload satisfies its own outputSchema`);
|
|
72
|
-
if (toolName === "history_list") {
|
|
73
|
-
assert.deepEqual(page(result).items, [{ seq: 1, role: "user", created_at: page(result).items[0].created_at, content: "hello", truncated: false, offset_chars: 0 }]);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
assert.deepEqual(Object.keys(resultData(result)).sort(), ["seq", "role", "created_at", "text", "total_chars", "next_offset_chars"].sort());
|
|
77
|
-
}
|
|
78
|
-
assertWithinBudget(result, `${toolName} page`);
|
|
80
|
+
for (const name of ["history_list", "history_search", "history_read"]) {
|
|
81
|
+
assert.equal(captured.tools.get(name).outputSchema, undefined);
|
|
82
|
+
const result = await call(captured, name, name === "history_read" ? { seq: 1 } : name === "history_search" ? { query: "hello" } : {}, ctx);
|
|
83
|
+
assert.match(resultText(result), /hello/);
|
|
84
|
+
assertWithinBudget(result, name);
|
|
79
85
|
}
|
|
80
|
-
|
|
81
|
-
assert.equal(Check(historyList.outputSchema, conversation.structuredContent), true);
|
|
82
|
-
const refusal = await call(captured, "history_read", { seq: 999 }, ctx);
|
|
83
|
-
assert.equal(Check(historyRead.outputSchema, refusal.structuredContent), true, "a refusal satisfies the same result schema");
|
|
86
|
+
assert.equal(resultTextError(await call(captured, "history_read", { seq: 999 }, ctx)).code, "unknown_seq");
|
|
84
87
|
});
|
|
85
88
|
test("pairing uses append seq rather than the presentation order of unnumbered segments", async () => {
|
|
86
89
|
const projection = projectHistory([
|
|
@@ -102,17 +105,17 @@ test("seq is stable across branch changes, abandoned entries stay unreadable, an
|
|
|
102
105
|
const ctx = context(session);
|
|
103
106
|
const firstId = appendText(session, "user", "first");
|
|
104
107
|
const abandonedId = appendText(session, "assistant", "abandoned reply");
|
|
105
|
-
const before =
|
|
108
|
+
const before = (await listData(session, { roles: ["user", "assistant"] }));
|
|
106
109
|
assert.deepEqual(before.items.map((item) => [item.seq, item.content]), [[1, "first"], [2, "abandoned reply"]]);
|
|
107
110
|
session.branch(firstId);
|
|
108
111
|
const branchId = appendText(session, "user", "new branch");
|
|
109
|
-
const after =
|
|
112
|
+
const after = (await listData(session, { roles: ["user", "assistant"] }));
|
|
110
113
|
assert.deepEqual(after.items.map((item) => [item.seq, item.content]), [[1, "first"], [3, "new branch"]]);
|
|
111
114
|
assert.equal(branchId !== abandonedId, true);
|
|
112
|
-
const offBranch =
|
|
115
|
+
const offBranch = resultTextError(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
113
116
|
assert.equal(offBranch.code, "not_on_branch");
|
|
114
117
|
assert.equal(JSON.stringify(offBranch).includes("abandoned"), false, "the refusal does not leak the abandoned entry's text");
|
|
115
|
-
const unknown =
|
|
118
|
+
const unknown = resultTextError(await call(captured, "history_read", { seq: 4 }, ctx));
|
|
116
119
|
assert.equal(unknown.code, "unknown_seq");
|
|
117
120
|
assert.match(unknown.message, /\b4\b.*\b3\b/);
|
|
118
121
|
});
|
|
@@ -123,19 +126,13 @@ test("a result address consumed by a pairing resolves directly to its call event
|
|
|
123
126
|
toolCall(session, "paired", "edit", { path: "a.md" });
|
|
124
127
|
toolResult(session, "paired", "edit", "edited");
|
|
125
128
|
// The assistant message takes seq 1 and its tool call seq 2; the result at seq 3 is absorbed.
|
|
126
|
-
assert.deepEqual(
|
|
127
|
-
const consumed =
|
|
129
|
+
assert.deepEqual((await listData(session, { roles: ["tool"] })).items.map(item => item.seq), [2], "the pairing is one event at the call's address");
|
|
130
|
+
const consumed = (await readData(session, { seq: 3 }));
|
|
128
131
|
assert.equal(consumed.seq, 2);
|
|
129
|
-
assert.equal(consumed.
|
|
130
|
-
const callSeq =
|
|
132
|
+
assert.equal(consumed.text, 'edit {"path":"a.md"}\n--- output ---\nedited');
|
|
133
|
+
const callSeq = (await readData(session, { seq: 2 }));
|
|
131
134
|
assert.equal(callSeq.seq, 2);
|
|
132
|
-
assert.equal(callSeq.
|
|
133
|
-
});
|
|
134
|
-
test("history page schema exposes plain boolean paging flags", () => {
|
|
135
|
-
for (const field of [HistoryPageSchema.properties.has_older, HistoryPageSchema.properties.has_newer]) {
|
|
136
|
-
assert.equal(field.type, "boolean");
|
|
137
|
-
assert.equal("description" in field, false);
|
|
138
|
-
}
|
|
135
|
+
assert.equal(callSeq.text, 'edit {"path":"a.md"}\n--- output ---\nedited');
|
|
139
136
|
});
|
|
140
137
|
test("history_list pages forward with after and otherwise back from before", async () => {
|
|
141
138
|
const session = manager();
|
|
@@ -143,29 +140,27 @@ test("history_list pages forward with after and otherwise back from before", asy
|
|
|
143
140
|
const ctx = context(session);
|
|
144
141
|
for (let index = 1; index <= 7; index++)
|
|
145
142
|
appendText(session, "user", `message-${index}`);
|
|
146
|
-
const list = (params) =>
|
|
147
|
-
assert.deepEqual(
|
|
148
|
-
assert.deepEqual(
|
|
149
|
-
assert.deepEqual(
|
|
143
|
+
const list = async (params) => (await listData(session, params)).items.map(item => item.seq);
|
|
144
|
+
assert.deepEqual(await list({ limit: 2 }), [6, 7]);
|
|
145
|
+
assert.deepEqual(await list({ after: 0, limit: 2 }), [1, 2]);
|
|
146
|
+
assert.deepEqual(await list({ after: 2, limit: 2 }), [3, 4]);
|
|
150
147
|
const older = await list({ before: 6, limit: 2 });
|
|
151
|
-
assert.deepEqual(
|
|
152
|
-
assert.match(
|
|
153
|
-
assert.deepEqual(
|
|
148
|
+
assert.deepEqual(older, [4, 5]);
|
|
149
|
+
assert.match(resultText(await call(captured, "history_list", { before: 6, limit: 2 }, ctx)), /→ older: \{"limit":2,"before":4\}/);
|
|
150
|
+
assert.deepEqual(await list({ after: 1, before: 5 }), [2, 3, 4]);
|
|
154
151
|
});
|
|
155
|
-
test("
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const result = await call(captured, "history_list", { after: 1, query: "needle", roles: ["user"], limit: 2, context: 1 }, ctx);
|
|
163
|
-
assert.deepEqual(page(result).items.map(item => [item.content, !!item.context]), [
|
|
152
|
+
test("history_search merges visible neighbors outside hit filters without consuming the hit limit", async () => {
|
|
153
|
+
const texts = ["setup", "needle one", "shared reply", "needle two", "follow-up", "unrelated", "needle three"];
|
|
154
|
+
const items = texts.map((text, index) => ({ seq: index + 1, windowId: "w", role: text.startsWith("needle") ? "user" : "assistant", text, createdAt: new Date(Date.UTC(2026, 9, 10, 0, 0, index)).toISOString() }));
|
|
155
|
+
const projection = projectHistory([{ windowId: "w", items }], 7, new Set(items.map(item => item.seq)));
|
|
156
|
+
const result = await historySearch.execute({ since: "2026-10-10", query: "needle", roles: ["user"], limit: 2, context: 1 }, projection);
|
|
157
|
+
assert.ok(result.ok);
|
|
158
|
+
assert.deepEqual(result.data.items.map(item => [item.content, !!item.context]), [
|
|
164
159
|
["setup", true], ["needle one", false], ["shared reply", true], ["needle two", false], ["follow-up", true],
|
|
165
160
|
]);
|
|
166
|
-
assert.
|
|
167
|
-
assert.match(
|
|
168
|
-
assert.
|
|
161
|
+
assert.match(historySearch.render(result), /→ more newer results: narrow with since\/until/);
|
|
162
|
+
assert.match(historySearch.render(result), /seq 3 \| assistant \| [^|\n]+ \| search context/);
|
|
163
|
+
assert.doesNotMatch(historySearch.render(result), /=== session/);
|
|
169
164
|
});
|
|
170
165
|
test("a one-row page budget admits the newest candidate first", () => {
|
|
171
166
|
const windowId = "w1";
|
|
@@ -182,10 +177,10 @@ test("a one-row page budget admits the newest candidate first", () => {
|
|
|
182
177
|
});
|
|
183
178
|
test("query reports budget failures while tools refuse the page", async () => {
|
|
184
179
|
const projection = projectHistory([{ windowId: "w1", items: [{ seq: 1, windowId: "w1", role: "user", text: "message" }] }], 1, new Set([1]));
|
|
185
|
-
assert.deepEqual(selectPage(projection, {}, () => false, 100), { ok: false, pageTooLarge:
|
|
180
|
+
assert.deepEqual(selectPage(projection, {}, () => false, 100), { ok: false, pageTooLarge: true });
|
|
186
181
|
const collector = new CorpusCollector({});
|
|
187
|
-
collector.
|
|
188
|
-
assert.deepEqual(collector.page(() => false, 100), { ok: false, pageTooLarge:
|
|
182
|
+
collector.addRepresentative("pi:budget", projection);
|
|
183
|
+
assert.deepEqual(collector.page(() => false, 100), { ok: false, pageTooLarge: true });
|
|
189
184
|
const context = {
|
|
190
185
|
current: () => projection,
|
|
191
186
|
corpus: { currentHarness: "pi", async sessions() {
|
|
@@ -193,8 +188,10 @@ test("query reports budget failures while tools refuse the page", async () => {
|
|
|
193
188
|
} },
|
|
194
189
|
};
|
|
195
190
|
const wrap = (text) => "x".repeat(TOOL_OUTPUT_MAX_BYTES + 1) + text;
|
|
196
|
-
for (const session of [undefined, "pi:budget", "*"]) {
|
|
197
|
-
const result =
|
|
191
|
+
for (const [operation, session] of [[historyList, undefined], [historyList, "pi:budget"], [historyList, "*"], [historySearch, undefined], [historySearch, "pi:budget"], [historySearch, "*"]]) {
|
|
192
|
+
const result = operation === historyList
|
|
193
|
+
? await historyList.execute({ session }, context, wrap)
|
|
194
|
+
: await historySearch.execute({ session, query: "message" }, context, wrap);
|
|
198
195
|
assert.ok(!result.ok);
|
|
199
196
|
assert.equal(result.error.code, "page_too_large");
|
|
200
197
|
}
|
|
@@ -212,14 +209,14 @@ test("history page selection still charges host wrapping and session notices bef
|
|
|
212
209
|
const wrap = (text) => "host ".repeat(200) + text;
|
|
213
210
|
for (const session of [undefined, "pi:wrapped", "*"]) {
|
|
214
211
|
const params = { session, query: "needle", max_chars_per_item: 50_000 };
|
|
215
|
-
const plain = await
|
|
216
|
-
const wrapped = await
|
|
212
|
+
const plain = await historySearch.execute(params, context);
|
|
213
|
+
const wrapped = await historySearch.execute(params, context, wrap);
|
|
217
214
|
assert.ok(plain.ok && wrapped.ok);
|
|
218
215
|
assert.ok(wrapped.data.items[0].content.length < plain.data.items[0].content.length);
|
|
219
216
|
assert.ok(text.startsWith(wrapped.data.items[0].content), "the preview is still verbatim");
|
|
220
217
|
if (session !== undefined)
|
|
221
218
|
assert.ok(wrapped.data.notice?.includes(notice));
|
|
222
|
-
assert.ok(Buffer.byteLength(wrap(
|
|
219
|
+
assert.ok(Buffer.byteLength(wrap(historySearch.render(wrapped)), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
223
220
|
assert.ok(Buffer.byteLength(JSON.stringify(wrapped.data), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
224
221
|
}
|
|
225
222
|
});
|
|
@@ -270,7 +267,7 @@ test("conversation paging prepares ordered folds once, including during first-ro
|
|
|
270
267
|
assert.ok(attempts > 3, "the first preview exercised repeated budget probes");
|
|
271
268
|
assert.equal(traversals, 1, "shortening also reuses the same prepared folds");
|
|
272
269
|
});
|
|
273
|
-
test("list shortening charges folded rows against
|
|
270
|
+
test("list shortening charges folded rows against the rendered text budget", async () => {
|
|
274
271
|
const windowId = "w1";
|
|
275
272
|
const items = [
|
|
276
273
|
{ seq: 1, windowId, role: "user", text: "older" },
|
|
@@ -293,10 +290,26 @@ test("list shortening charges folded rows against both text and JSON budgets", a
|
|
|
293
290
|
assert.deepEqual(folded.data.folded_after, { first_seq: 3, last_seq: 3, count: 1, tools: { read: 1 } });
|
|
294
291
|
assert.equal(folded.data.has_older, true);
|
|
295
292
|
assert.equal(folded.data.has_newer, false);
|
|
296
|
-
assert.ok(Buffer.byteLength(JSON.stringify(folded.data), "utf8")
|
|
293
|
+
assert.ok(Buffer.byteLength(JSON.stringify(folded.data), "utf8") > TOOL_OUTPUT_MAX_BYTES, "JSON escaping does not shrink a plain-text page");
|
|
297
294
|
assert.ok(Buffer.byteLength(historyList.render(folded), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
298
295
|
});
|
|
299
|
-
test("
|
|
296
|
+
test("escape-heavy history fits by rendered UTF-8 bytes, not JSON bytes", async () => {
|
|
297
|
+
const text = '\n"\\😀'.repeat(4_500);
|
|
298
|
+
const projection = projectHistory([{ windowId: "w", items: [{ seq: 1, windowId: "w", role: "user", text }] }], 1, new Set([1]));
|
|
299
|
+
const list = await historyList.execute({ max_chars_per_item: 50_000 }, projection);
|
|
300
|
+
assert.ok(list.ok);
|
|
301
|
+
assert.equal(list.data.items[0].content, text);
|
|
302
|
+
assert.equal(list.data.items[0].truncated, false);
|
|
303
|
+
assert.ok(Buffer.byteLength(historyList.render(list), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
304
|
+
assert.ok(Buffer.byteLength(JSON.stringify(list.data), "utf8") > TOOL_OUTPUT_MAX_BYTES);
|
|
305
|
+
const read = await historyRead.execute({ seq: 1, max_chars: 50_000 }, projection);
|
|
306
|
+
assert.ok(read.ok);
|
|
307
|
+
assert.equal(read.data.text, text);
|
|
308
|
+
assert.equal(read.data.next_offset_chars, null);
|
|
309
|
+
assert.ok(Buffer.byteLength(historyRead.render(read), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
310
|
+
assert.ok(Buffer.byteLength(JSON.stringify(read.data), "utf8") > TOOL_OUTPUT_MAX_BYTES);
|
|
311
|
+
});
|
|
312
|
+
test("since and until accept exclusive ISO 8601 times, reading offset-less values as host local time", async () => {
|
|
300
313
|
const items = [
|
|
301
314
|
{ seq: 1, windowId: "w1", role: "user", text: "first needle", createdAt: "2026-10-10T00:00:00.000Z" },
|
|
302
315
|
{ seq: 2, windowId: "w1", role: "assistant", text: "second", createdAt: "2026-10-10T06:00:00.000Z" },
|
|
@@ -306,27 +319,54 @@ test("after and before accept exclusive ISO 8601 times and default to UTC", asyn
|
|
|
306
319
|
];
|
|
307
320
|
const projection = projectHistory([{ windowId: "w1", items }], 5, new Set([1, 2, 3, 4, 5]));
|
|
308
321
|
const selected = async (params) => {
|
|
309
|
-
const outcome = await
|
|
322
|
+
const outcome = await historySearch.execute(params, projection);
|
|
310
323
|
assert.equal(outcome.ok, true, JSON.stringify(outcome));
|
|
311
324
|
return outcome.ok ? outcome.data.items.map((item) => item.seq) : [];
|
|
312
325
|
};
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
326
|
+
const all = ["first", "second", "third", "fourth", "fifth"];
|
|
327
|
+
const after = (at) => items.filter((item) => item.createdAt !== undefined && Date.parse(item.createdAt) > at).map((item) => item.seq);
|
|
328
|
+
// No offset means the host wall clock, so the expectation follows the local date constructor.
|
|
329
|
+
assert.deepEqual(await selected({ query: all, since: "2026-10-09T23:00" }), after(new Date(2026, 9, 9, 23, 0).getTime()));
|
|
330
|
+
assert.deepEqual(await selected({ query: all, limit: 1, since: "2026-10-10T06:00" }), after(new Date(2026, 9, 10, 6, 0).getTime()).slice(0, 1));
|
|
331
|
+
// An explicit offset fixes the instant regardless of the host timezone.
|
|
332
|
+
assert.deepEqual(await selected({ query: all, since: "2026-10-10T06:00Z" }), [3, 4]);
|
|
333
|
+
assert.deepEqual(await selected({ query: all, since: "2026-10-10T14:00:00+08:00" }), [3, 4]);
|
|
334
|
+
assert.deepEqual(await selected({ query: all, since: "2026-10-09T00:00:00Z", until: "2026-10-10T06:00Z" }), [1]);
|
|
335
|
+
const listWindow = await historyList.execute({ since: "2026-10-09T00:00:00Z", until: "2026-10-11T00:00:00Z", limit: 2 }, projection);
|
|
336
|
+
assert.equal(listWindow.ok, true);
|
|
337
|
+
if (listWindow.ok) {
|
|
338
|
+
assert.deepEqual(listWindow.data.items.map((item) => item.seq), [1, 2]);
|
|
339
|
+
assert.equal(listWindow.data.has_newer, true);
|
|
340
|
+
const newerMatch = /→ newer: (\{[^\n]+\})/.exec(historyList.render(listWindow));
|
|
341
|
+
assert.ok(newerMatch);
|
|
342
|
+
const next = await historyList.execute(JSON.parse(newerMatch[1]), projection);
|
|
343
|
+
assert.equal(next.ok, true);
|
|
344
|
+
if (next.ok)
|
|
345
|
+
assert.deepEqual(next.data.items.map((item) => item.seq), [3, 4]);
|
|
346
|
+
}
|
|
347
|
+
const malformed = await historySearch.execute({ query: all, since: "yesterday" }, projection);
|
|
316
348
|
assert.ok(!malformed.ok);
|
|
317
|
-
assert.match(malformed.error.message,
|
|
349
|
+
assert.match(malformed.error.message, /since.*"yesterday"/);
|
|
350
|
+
for (const value of ["2026-02-30", "2026-13-01"]) {
|
|
351
|
+
for (const bound of ["since", "until"]) {
|
|
352
|
+
const invalid = await historySearch.execute({ query: all, [bound]: value }, projection);
|
|
353
|
+
assert.ok(!invalid.ok);
|
|
354
|
+
assert.equal(invalid.error.code, "invalid_bounds");
|
|
355
|
+
assert.ok(invalid.error.message.includes(value));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
318
358
|
});
|
|
319
|
-
test("time bounds
|
|
359
|
+
test("time bounds keep untimed matching events out of search", async () => {
|
|
320
360
|
const items = [
|
|
321
361
|
{ seq: 1, windowId: "w1", role: "user", text: "before", createdAt: "2026-10-10T00:00:00.000Z" },
|
|
322
362
|
{ seq: 2, windowId: "w1", role: "tool", text: "output", createdAt: undefined },
|
|
323
363
|
{ seq: 3, windowId: "w1", role: "user", text: "after", createdAt: "2026-10-10T12:00:00.000Z" },
|
|
324
364
|
];
|
|
325
365
|
const projection = projectHistory([{ windowId: "w1", items }], 3, new Set([1, 2, 3]));
|
|
326
|
-
const bounded = await
|
|
366
|
+
const bounded = await historySearch.execute({ query: ["before", "after", "output"], until: "2026-10-11" }, projection);
|
|
327
367
|
assert.equal(bounded.ok, true);
|
|
328
368
|
if (bounded.ok)
|
|
329
|
-
assert.deepEqual(bounded.data.items.map((item) => `seq ${item.seq}`), ["seq 1", "seq 3"], "an untimed
|
|
369
|
+
assert.deepEqual(bounded.data.items.map((item) => `seq ${item.seq}`), ["seq 1", "seq 3"], "an untimed event is excluded by the time bound");
|
|
330
370
|
const unbounded = await historyList.execute({}, projection);
|
|
331
371
|
assert.equal(unbounded.ok, true);
|
|
332
372
|
if (unbounded.ok)
|
|
@@ -351,7 +391,7 @@ test("conversation view folds tools and injected messages, while explicit roles
|
|
|
351
391
|
toolResult(session, "tc-2", "read", "contents");
|
|
352
392
|
session.appendCustomMessageEntry("square", "injected event", false);
|
|
353
393
|
append(session, { role: "assistant", content: [], stopReason: "toolUse", timestamp: Date.now() });
|
|
354
|
-
const conversation =
|
|
394
|
+
const conversation = (await listData(session, {}));
|
|
355
395
|
assert.ok(conversation.folded_after);
|
|
356
396
|
assert.ok(conversation.items.every((item) => "seq" in item && !("folded" in item)));
|
|
357
397
|
assert.equal(conversation.items.some((item) => item.role === "developer"), false);
|
|
@@ -361,18 +401,18 @@ test("conversation view folds tools and injected messages, while explicit roles
|
|
|
361
401
|
assert.equal(folded.count, 3, "two tool events and one injected context are folded, not the empty assistant message");
|
|
362
402
|
assert.deepEqual(folded.tools, { bash: 1, read: 1 });
|
|
363
403
|
assert.equal("custom_types" in folded, false);
|
|
364
|
-
const empty =
|
|
404
|
+
const empty = (await listData(session, { roles: ["context"], before: 2 }));
|
|
365
405
|
assert.deepEqual(empty.items, []);
|
|
366
|
-
const hiddenOnly =
|
|
406
|
+
const hiddenOnly = (await listData(session, { after: 2, before: 6 }));
|
|
367
407
|
assert.deepEqual(hiddenOnly.items, []);
|
|
368
408
|
assert.deepEqual(hiddenOnly.folded_after, { first_seq: 3, last_seq: 4, count: 2, tools: { bash: 1, read: 1 } });
|
|
369
|
-
const expanded =
|
|
409
|
+
const expanded = (await listData(session, { roles: ["tool"] }));
|
|
370
410
|
assert.deepEqual(expanded.items.map((item) => [item.seq, item.role, item.tool, item.tool_status]), [[3, "tool", "bash", "ok"], [4, "tool", "read", "ok"]]);
|
|
371
411
|
assert.equal(expanded.items[0].content, 'bash {"command":"pwd"}\n--- output ---\nok');
|
|
372
412
|
assert.equal(expanded.items[1].content, 'read {"path":"README.md"}\n--- output ---\ncontents');
|
|
373
413
|
assert.equal(expanded.items.every((item) => !("call_seq" in item || "result_seq" in item || "tool_name" in item)), true);
|
|
374
|
-
assert.deepEqual(
|
|
375
|
-
const injected =
|
|
414
|
+
assert.deepEqual((await searchData(session, { query: "bash", roles: ["tool"] })).items.map(item => item.seq), [3]);
|
|
415
|
+
const injected = (await listData(session, { roles: ["context"] }));
|
|
376
416
|
assert.deepEqual(injected.items.map((item) => [item.role, item.content]), [["context", "injected event"]]);
|
|
377
417
|
assert.equal(turnId.length > 0, true);
|
|
378
418
|
});
|
|
@@ -386,27 +426,27 @@ test("tool summaries and documents preserve pending, errored, and orphan runs",
|
|
|
386
426
|
toolResult(session, "orphan", "edit", "orphan output", {
|
|
387
427
|
nestedCalls: { complete: true, calls: [{ id: "orphan/1", name: "read", arguments: { path: "orphan-nested.md" }, status: "ok" }] },
|
|
388
428
|
});
|
|
389
|
-
const events =
|
|
429
|
+
const events = (await listData(session, { roles: ["tool"] }));
|
|
390
430
|
// The orphan result ran and succeeded; nothing about its missing call changes that. Only the
|
|
391
431
|
// pending call, which no result ended, is unfinished.
|
|
392
432
|
assert.deepEqual(events.items.map((item) => [item.seq, item.tool_status]), [[2, "error"], [5, "unfinished"], [6, "ok"]]);
|
|
393
433
|
assert.equal(events.items[0].content, 'edit {"path":"😀.md","oldText":"before"}\n--- output ---\nreplacement OK');
|
|
394
434
|
assert.equal(events.items[1].content, 'edit {"path":"pending.md"}', "an unfinished call claims no output");
|
|
395
435
|
assert.equal(events.items[2].content, 'edit (arguments not recorded)\n--- output ---\norphan output\n--- nested calls (complete, 1 recorded) ---\n- orphan/1 read [ok] {"path":"orphan-nested.md"}', "an orphan result invents no arguments, and keeps the nested evidence the host recorded");
|
|
396
|
-
const errored =
|
|
436
|
+
const errored = (await readData(session, { seq: 2 }));
|
|
397
437
|
assert.equal(errored.tool, "edit");
|
|
398
438
|
assert.equal(errored.tool_status, "error");
|
|
399
439
|
assert.equal(errored.text, events.items[0].content);
|
|
400
440
|
assert.equal("execution" in errored, false, "arguments are delivered once, in the document");
|
|
401
|
-
const pending =
|
|
441
|
+
const pending = (await readData(session, { seq: 5 }));
|
|
402
442
|
assert.equal(pending.tool_status, "unfinished");
|
|
403
|
-
const orphan =
|
|
443
|
+
const orphan = (await readData(session, { seq: 6 }));
|
|
404
444
|
assert.deepEqual(orphan.nested_calls, { call_count: 1, complete: true });
|
|
405
445
|
assert.equal(orphan.text, events.items[2].content, "an orphan's nested evidence stays readable despite the missing call");
|
|
406
|
-
assert.deepEqual(
|
|
407
|
-
assert.deepEqual(
|
|
408
|
-
assert.deepEqual(
|
|
409
|
-
assert.deepEqual(
|
|
446
|
+
assert.deepEqual((await searchData(session, { query: "edit", roles: ["tool"] })).items.map(item => item.seq), [2, 5, 6]);
|
|
447
|
+
assert.deepEqual((await searchData(session, { query: "pending.md", roles: ["tool"] })).items.map(item => item.seq), [5]);
|
|
448
|
+
assert.deepEqual((await searchData(session, { query: "orphan output", roles: ["tool"] })).items.map(item => item.seq), [6]);
|
|
449
|
+
assert.deepEqual((await searchData(session, { query: "orphan-nested.md", roles: ["tool"] })).items.map(item => item.seq), [6], "nested evidence stays findable even when the call it belongs to was never recorded");
|
|
410
450
|
});
|
|
411
451
|
test("native nested-call records are searchable, readable, and never gain a result or an address", async () => {
|
|
412
452
|
const session = manager();
|
|
@@ -423,15 +463,15 @@ test("native nested-call records are searchable, readable, and never gain a resu
|
|
|
423
463
|
],
|
|
424
464
|
},
|
|
425
465
|
});
|
|
426
|
-
const found =
|
|
466
|
+
const found = (await searchData(session, { query: "nested-needle" }));
|
|
427
467
|
assert.deepEqual(found.items.map((item) => item.seq), [2], "nested arguments are part of the searchable document");
|
|
428
|
-
const read =
|
|
468
|
+
const read = (await readData(session, { seq: 2 }));
|
|
429
469
|
assert.deepEqual(read.nested_calls, { call_count: 3, complete: false }, "the host's completeness flag stays unchanged");
|
|
430
470
|
assert.equal(read.text, 'codemode {"script":"run()"}\n--- output ---\nscript finished\n--- nested calls (incomplete, 3 recorded) ---\n- codemode/1 read [ok] 12ms {"path":"nested-needle.md"}\n- codemode/2 bash [error] 4ms error: exit 1 (arguments not recorded)\n- codemode/3 spawn [unfinished] (arguments not recorded)');
|
|
431
471
|
assert.equal(read.next_offset_chars, null);
|
|
432
472
|
assert.equal("execution" in read, false, "nested records are not duplicated outside the document");
|
|
433
|
-
const rendered = read.
|
|
434
|
-
for (const [needle, offset] of [["nested-needle.md", earliestMatchOffsetChars(read.
|
|
473
|
+
const rendered = read.text;
|
|
474
|
+
for (const [needle, offset] of [["nested-needle.md", earliestMatchOffsetChars(read.text, ["nested-needle.md"])], ["exit 1", earliestMatchOffsetChars(read.text, ["exit 1"])], ["unfinished", earliestMatchOffsetChars(read.text, ["unfinished"])]]) {
|
|
435
475
|
assert.ok(offset >= 0 && rendered.slice(offset).startsWith(needle), `nested evidence "${needle}" is readable in the document`);
|
|
436
476
|
}
|
|
437
477
|
});
|
|
@@ -441,11 +481,11 @@ test("absent nested calls mean unavailable, not a known-empty record", async ()
|
|
|
441
481
|
const ctx = context(session);
|
|
442
482
|
toolCall(session, "plain", "read", { path: "a.md" });
|
|
443
483
|
toolResult(session, "plain", "read", "contents");
|
|
444
|
-
const listed =
|
|
484
|
+
const listed = (await listData(session, { roles: ["tool"] }));
|
|
445
485
|
assert.equal("nested_calls" in listed.items[0], false, "a page row never carries nested-call evidence; one read does");
|
|
446
|
-
const read =
|
|
486
|
+
const read = (await readData(session, { seq: 2 }));
|
|
447
487
|
assert.equal("nested_calls" in read, false);
|
|
448
|
-
assert.equal(read.
|
|
488
|
+
assert.equal(read.text.includes("nested calls"), false);
|
|
449
489
|
});
|
|
450
490
|
test("oversized arguments and long nested records remain fully pageable and searchable", async () => {
|
|
451
491
|
const session = manager();
|
|
@@ -459,14 +499,15 @@ test("oversized arguments and long nested records remain fully pageable and sear
|
|
|
459
499
|
calls: Array.from({ length: 400 }, (_, index) => ({ id: `big/${index}`, name: "read", arguments: { path: `p${index}.md` }, status: "ok", durationMs: 1 })),
|
|
460
500
|
},
|
|
461
501
|
});
|
|
462
|
-
let read =
|
|
502
|
+
let read = (await readData(session, { seq: 2, max_chars: 50_000 }));
|
|
463
503
|
assert.deepEqual(read.nested_calls, { call_count: 400, complete: true }, "the read counts every recorded call, not only the records one page can carry");
|
|
464
504
|
let document = read.text;
|
|
465
505
|
while (read.next_offset_chars !== null) {
|
|
466
506
|
const next = read.next_offset_chars;
|
|
467
507
|
const result = await call(captured, "history_read", { seq: 2, offset_chars: next, max_chars: 50_000 }, ctx);
|
|
468
508
|
assertWithinBudget(result, "bounded document page");
|
|
469
|
-
|
|
509
|
+
assert.ok(resultText(result).length > 0);
|
|
510
|
+
read = await readData(session, { seq: 2, offset_chars: next, max_chars: 50_000 });
|
|
470
511
|
assert.ok(read.text.length > 0, "every continuation makes progress");
|
|
471
512
|
document += read.text;
|
|
472
513
|
}
|
|
@@ -474,11 +515,11 @@ test("oversized arguments and long nested records remain fully pageable and sear
|
|
|
474
515
|
assert.equal(document, `write ${JSON.stringify({ path: "big.md", content: huge })}\n--- output ---\nwritten\n--- nested calls (complete, 400 recorded) ---\n${expectedCalls}`, "paging reconstructs all arguments and all recorded calls exactly");
|
|
475
516
|
assertWithinBudget(await call(captured, "history_read", { seq: 2 }, ctx), "bounded first read");
|
|
476
517
|
assertWithinBudget(await call(captured, "history_list", { roles: ["tool"] }, ctx), "bounded list row");
|
|
477
|
-
const hit =
|
|
518
|
+
const hit = (await searchData(session, { query: "big.md", max_chars_per_item: 40 }));
|
|
478
519
|
assert.deepEqual(hit.items.map((item) => item.seq), [2], "the document still carries the real arguments, so a query still finds them");
|
|
479
|
-
const late =
|
|
520
|
+
const late = (await searchData(session, { query: "p399.md" })).items[0];
|
|
480
521
|
assert.equal(late.seq, 2);
|
|
481
|
-
const resumed =
|
|
522
|
+
const resumed = (await readData(session, { seq: 2, offset_chars: late.offset_chars }));
|
|
482
523
|
assert.ok(resumed.text.startsWith("p399.md"), "a query can jump directly to evidence beyond the first read");
|
|
483
524
|
});
|
|
484
525
|
test("standalone bash execution retains command, output, and truncation path", async () => {
|
|
@@ -487,7 +528,8 @@ test("standalone bash execution retains command, output, and truncation path", a
|
|
|
487
528
|
const ctx = context(session);
|
|
488
529
|
append(session, { role: "bashExecution", command: "echo needle", output: "needle output", exitCode: 0, cancelled: false, truncated: true, fullOutputPath: "/tmp/bash-output.txt", timestamp: Date.now() });
|
|
489
530
|
const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
|
|
490
|
-
|
|
531
|
+
assert.match(resultText(raw), /output truncated/);
|
|
532
|
+
const found = await listData(session, { roles: ["tool"] });
|
|
491
533
|
assert.equal(found.items.length, 1);
|
|
492
534
|
assert.deepEqual(found.items[0], {
|
|
493
535
|
seq: 1,
|
|
@@ -500,10 +542,10 @@ test("standalone bash execution retains command, output, and truncation path", a
|
|
|
500
542
|
truncated: false,
|
|
501
543
|
content: 'bash {"command":"echo needle"}\n--- output ---\nneedle output',
|
|
502
544
|
});
|
|
503
|
-
const query =
|
|
545
|
+
const query = (await searchData(session, { roles: ["tool"], query: "NEEDLE OUTPUT" }));
|
|
504
546
|
assert.deepEqual(query.items.map((item) => item.seq), [1]);
|
|
505
|
-
const read =
|
|
506
|
-
assert.equal(read.
|
|
547
|
+
const read = (await readData(session, { seq: 1, offset_chars: query.items[0].offset_chars }));
|
|
548
|
+
assert.equal(read.text, "needle output");
|
|
507
549
|
assert.equal(read.seq, 1);
|
|
508
550
|
});
|
|
509
551
|
test("a truncated tool run without a recorded path still reports output_truncated", async () => {
|
|
@@ -512,12 +554,13 @@ test("a truncated tool run without a recorded path still reports output_truncate
|
|
|
512
554
|
const ctx = context(session);
|
|
513
555
|
append(session, { role: "bashExecution", command: "echo big", output: "big output", exitCode: 0, cancelled: false, truncated: true, timestamp: Date.now() });
|
|
514
556
|
const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
|
|
515
|
-
|
|
557
|
+
assert.match(resultText(raw), /output truncated/);
|
|
558
|
+
const found = await listData(session, { roles: ["tool"] });
|
|
516
559
|
assert.equal(found.items.length, 1);
|
|
517
560
|
const item = found.items[0];
|
|
518
561
|
assert.equal(item.output_truncated, true, "the truncation is reported even with no path");
|
|
519
562
|
assert.equal("full_output_path" in item, false, "no path is invented");
|
|
520
|
-
const read =
|
|
563
|
+
const read = (await readData(session, { seq: 1 }));
|
|
521
564
|
assert.equal(read.output_truncated, true, "the read reports the same truncation");
|
|
522
565
|
assert.equal("full_output_path" in read, false);
|
|
523
566
|
});
|
|
@@ -531,11 +574,11 @@ test("list renders paging and fold recipes across resets, and read renders a nei
|
|
|
531
574
|
appendText(session, "user", "current window");
|
|
532
575
|
const listed = await call(captured, "history_list", {}, ctx);
|
|
533
576
|
assert.match(rendered(listed), /→ older: \{"before":\d+\}/, "the footer prints the call to page older");
|
|
534
|
-
const earlier =
|
|
577
|
+
const earlier = (await listData(session, { before: 31, limit: 30 }));
|
|
535
578
|
assert.deepEqual(earlier.items.map((item) => item.seq), Array.from({ length: 30 }, (_, index) => index + 1));
|
|
536
|
-
const earlierQuery =
|
|
537
|
-
assert.equal(earlierQuery.items.length, 30, "
|
|
538
|
-
const current =
|
|
579
|
+
const earlierQuery = (await searchData(session, { query: "older window", limit: 30 }));
|
|
580
|
+
assert.equal(earlierQuery.items.length, 30, "search recovers earlier windows without a separate address");
|
|
581
|
+
const current = (await listData(session, { after: 30 }));
|
|
539
582
|
assert.deepEqual(current.items.map((item) => [item.seq, item.content]), [[31, "current window"]], "the reset marker consumes no address");
|
|
540
583
|
toolCall(session, "t1", "bash", { command: "ls" });
|
|
541
584
|
toolResult(session, "t1", "bash", "done");
|
|
@@ -543,9 +586,38 @@ test("list renders paging and fold recipes across resets, and read renders a nei
|
|
|
543
586
|
const folded = await call(captured, "history_list", {}, ctx);
|
|
544
587
|
assert.match(rendered(folded), /→ expand: \{"after":\d+,"before":\d+,"roles":\["tool","context"\]\}/, "a folded row prints its own expand recipe");
|
|
545
588
|
appendText(session, "user", "needle read target");
|
|
546
|
-
const hits =
|
|
589
|
+
const hits = (await searchData(session, { query: "needle read target" }));
|
|
547
590
|
const read = await call(captured, "history_read", { seq: hits.items[0].seq }, ctx);
|
|
548
|
-
assert.match(rendered(read),
|
|
591
|
+
assert.match(rendered(read), /→ history_list: \{"after":\d+,"before":\d+\}/, "a read prints the call for surrounding events");
|
|
592
|
+
});
|
|
593
|
+
test("history headers carry local ISO timestamps, and preview markers stay inline", async () => {
|
|
594
|
+
const windowId = "w1";
|
|
595
|
+
const at = new Date(2026, 10, 27, 13, 40, 5, 250).toISOString();
|
|
596
|
+
const items = [
|
|
597
|
+
{ seq: 1, windowId, role: "user", text: "timed needle", createdAt: at },
|
|
598
|
+
{ seq: 2, windowId, role: "assistant", text: "reply without airtime", createdAt: undefined },
|
|
599
|
+
];
|
|
600
|
+
const projection = projectHistory([{ windowId, items }], 2, new Set([1, 2]));
|
|
601
|
+
const stamp = "2026-11-27T13:40:05\\.250[+-]\\d{2}:\\d{2}";
|
|
602
|
+
const listed = await historyList.execute({}, projection);
|
|
603
|
+
assert.ok(listed.ok);
|
|
604
|
+
assert.match(historyList.render(listed), new RegExp(`^seq 1 \\| user \\| ${stamp}\\ntimed needle`), "a timed row prints the local wall clock");
|
|
605
|
+
assert.match(historyList.render(listed), /\nseq 2 \| assistant\nreply without airtime$/, "an untimed row ends at the role");
|
|
606
|
+
const read = await historyRead.execute({ seq: 1 }, projection);
|
|
607
|
+
assert.match(historyRead.render(read), new RegExp(`^seq 1 \\| user \\| ${stamp}\\n→ history_list: \\{"after":0,"before":11\\}`), "a read prints its header and a list recipe");
|
|
608
|
+
const untimedRead = await historyRead.execute({ seq: 2 }, projection);
|
|
609
|
+
assert.match(historyRead.render(untimedRead), /^seq 2 \| assistant\n→ history_list: /);
|
|
610
|
+
// A search match names its start on the header line and marks the cut on the content line.
|
|
611
|
+
const hit = await historySearch.execute({ query: "needle", max_chars_per_item: 5 }, projection);
|
|
612
|
+
assert.ok(hit.ok);
|
|
613
|
+
assert.match(historySearch.render(hit), new RegExp(`^seq 1 \\| user \\| ${stamp} \\| offset_chars 6\\nneedl \\[truncated\\]$`), "a match preview names its start and marks the cut");
|
|
614
|
+
// A match at the document start still prints no offset marker.
|
|
615
|
+
const fromStart = await historySearch.execute({ query: "timed", max_chars_per_item: 5 }, projection);
|
|
616
|
+
assert.ok(fromStart.ok);
|
|
617
|
+
assert.match(historySearch.render(fromStart), new RegExp(`^seq 1 \\| user \\| ${stamp}\\ntimed \\[truncated\\]$`), "a zero offset stays off the header");
|
|
618
|
+
const zeroList = await historyList.execute({ max_chars_per_item: 5 }, projection);
|
|
619
|
+
assert.ok(zeroList.ok);
|
|
620
|
+
assert.doesNotMatch(historyList.render(zeroList), /offset_chars 0/, "a zero offset is not printed");
|
|
549
621
|
});
|
|
550
622
|
test("compaction summary becomes context and is folded in the default list", async () => {
|
|
551
623
|
const session = manager();
|
|
@@ -554,41 +626,34 @@ test("compaction summary becomes context and is folded in the default list", asy
|
|
|
554
626
|
appendText(session, "user", "before checkpoint");
|
|
555
627
|
session.appendCompaction("summary needle", session.getLeafId(), 100);
|
|
556
628
|
appendText(session, "assistant", "after checkpoint");
|
|
557
|
-
const regular =
|
|
629
|
+
const regular = (await listData(session, {}));
|
|
558
630
|
assert.deepEqual(regular.items.map((item) => item.role), ["user", "assistant"]);
|
|
559
631
|
const folded = regular.items[1].folded_before;
|
|
560
632
|
assert.equal(folded.count, 1);
|
|
561
633
|
assert.deepEqual(folded.tools, {});
|
|
562
|
-
const contextItems =
|
|
634
|
+
const contextItems = (await listData(session, { roles: ["context"] }));
|
|
563
635
|
assert.deepEqual(contextItems.items.map((item) => [item.role, item.content]), [["context", "summary needle"]]);
|
|
564
636
|
});
|
|
565
|
-
test("a query covers every role, carries match offsets and
|
|
637
|
+
test("a query covers every role, carries match offsets and returns empty for empty queries", async () => {
|
|
566
638
|
const session = manager();
|
|
567
639
|
const captured = makeExtension(session);
|
|
568
640
|
const ctx = context(session);
|
|
569
641
|
appendText(session, "user", "visible needle");
|
|
570
642
|
session.appendCustomMessageEntry("notesoup/boot", "developer needle", false);
|
|
571
643
|
appendText(session, "assistant", "assistant needle");
|
|
572
|
-
const all =
|
|
644
|
+
const all = (await searchData(session, { query: "needle" }));
|
|
573
645
|
assert.deepEqual(all.items.map((item) => item.role), ["user", "context", "assistant"]);
|
|
574
646
|
assert.ok(all.items.every((item) => typeof item.seq === "number" && typeof item.offset_chars === "number"));
|
|
575
|
-
const developers =
|
|
647
|
+
const developers = (await searchData(session, { query: "needle", roles: ["context"] }));
|
|
576
648
|
assert.deepEqual(developers.items.map((item) => item.role), ["context"]);
|
|
577
649
|
assert.equal("custom_type" in developers.items[0], false);
|
|
578
|
-
const
|
|
579
|
-
assert.deepEqual(
|
|
580
|
-
assert.equal(first.has_newer, true);
|
|
581
|
-
const next = page(await call(captured, "history_list", { query: "needle", after: first.items.at(-1).seq, limit: 2 }, ctx));
|
|
582
|
-
assert.deepEqual(next.items.map((item) => item.seq), [3]);
|
|
583
|
-
const absent = await call(captured, "history_list", { query: "absent" }, ctx);
|
|
584
|
-
assert.deepEqual(page(absent).items, []);
|
|
650
|
+
const absent = await call(captured, "history_search", { query: "absent" }, ctx);
|
|
651
|
+
assert.deepEqual((await searchData(session, { query: "absent" })).items, []);
|
|
585
652
|
assert.notEqual(rendered(absent).trim(), "", "an empty page says so instead of rendering nothing");
|
|
586
653
|
for (const query of ["", [], ["", ""]]) {
|
|
587
|
-
assert.deepEqual(
|
|
588
|
-
const filters = { roles: ["context"], after: 1, before: 3 };
|
|
589
|
-
assert.deepEqual(page(await call(captured, "history_list", { ...filters, query }, ctx)), page(await call(captured, "history_list", filters, ctx)), "other filters still apply");
|
|
654
|
+
assert.deepEqual(await searchData(session, { query, context: 1 }), { items: [], has_older: false, has_newer: false });
|
|
590
655
|
}
|
|
591
|
-
assert.deepEqual(
|
|
656
|
+
assert.deepEqual((await searchData(session, { query: ["", "needle"] })), all, "empty entries do not turn OR into match-all");
|
|
592
657
|
});
|
|
593
658
|
test("has_older and has_newer round-trip a session with no duplicates and no gaps", async () => {
|
|
594
659
|
const session = manager();
|
|
@@ -597,25 +662,25 @@ test("has_older and has_newer round-trip a session with no duplicates and no gap
|
|
|
597
662
|
for (let seq = 1; seq <= 10; seq++)
|
|
598
663
|
appendText(session, "user", `needle ${seq}`);
|
|
599
664
|
const forward = [];
|
|
600
|
-
let current =
|
|
665
|
+
let current = (await listData(session, { after: 0, limit: 3 }));
|
|
601
666
|
assert.deepEqual(current.items.map((item) => item.seq), [1, 2, 3]);
|
|
602
667
|
assert.equal(current.has_older, false, "the first page in `from` oldest has nothing older");
|
|
603
668
|
assert.equal(current.has_newer, true);
|
|
604
669
|
forward.push(...current.items.map((item) => item.seq));
|
|
605
670
|
while (current.has_newer) {
|
|
606
671
|
const cursor = { after: current.items.at(-1).seq };
|
|
607
|
-
current =
|
|
672
|
+
current = (await listData(session, { ...cursor, limit: 3 }));
|
|
608
673
|
forward.push(...current.items.map((item) => item.seq));
|
|
609
674
|
}
|
|
610
675
|
assert.deepEqual(forward, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "has_newer visits every event exactly once, in order");
|
|
611
676
|
const backward = [];
|
|
612
|
-
current =
|
|
677
|
+
current = (await listData(session, { limit: 3 }));
|
|
613
678
|
assert.deepEqual(current.items.map((item) => item.seq), [8, 9, 10]);
|
|
614
679
|
assert.equal(current.has_older, true);
|
|
615
680
|
backward.push(...current.items.map((item) => item.seq));
|
|
616
681
|
while (current.has_older) {
|
|
617
682
|
const cursor = { before: current.items[0].seq };
|
|
618
|
-
current =
|
|
683
|
+
current = (await listData(session, { ...cursor, limit: 3 }));
|
|
619
684
|
backward.push(...current.items.map((item) => item.seq));
|
|
620
685
|
}
|
|
621
686
|
assert.deepEqual(backward, [8, 9, 10, 5, 6, 7, 2, 3, 4, 1], "has_older walks back with no duplicates and no gaps");
|
|
@@ -627,24 +692,24 @@ test("query previews start at case-insensitive literal matches and offsets read
|
|
|
627
692
|
const ctx = context(session);
|
|
628
693
|
const prefix = "😀İ".repeat(1000);
|
|
629
694
|
appendText(session, "user", prefix + "NeEdLe.* trailing");
|
|
630
|
-
const found =
|
|
695
|
+
const found = (await searchData(session, { query: ["absent", "needle.*"], max_chars_per_item: 8 }));
|
|
631
696
|
assert.equal(found.items.length, 1);
|
|
632
697
|
const hit = found.items[0];
|
|
633
698
|
assert.equal(hit.offset_chars, 2000);
|
|
634
699
|
assert.equal("match_offset_chars" in hit, false);
|
|
635
700
|
assert.equal(hit.content, "NeEdLe.*");
|
|
636
701
|
assert.equal(hit.truncated, true);
|
|
637
|
-
const read =
|
|
638
|
-
assert.equal(read.
|
|
639
|
-
const listed =
|
|
702
|
+
const read = (await readData(session, { seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 8 }));
|
|
703
|
+
assert.equal(read.text, hit.content);
|
|
704
|
+
const listed = (await listData(session, { max_chars_per_item: 8 }));
|
|
640
705
|
assert.equal(listed.items.length, 1);
|
|
641
706
|
assert.equal("offset_chars" in listed.items[0], false, "a list preview reports no match offset");
|
|
642
|
-
const atStart =
|
|
707
|
+
const atStart = (await searchData(session, { query: "😀", max_chars_per_item: 4 }));
|
|
643
708
|
const zero = atStart.items[0];
|
|
644
709
|
assert.equal(zero.offset_chars, 0, "a match at the document start reports an explicit zero offset");
|
|
645
710
|
assert.equal(zero.content, "😀İ😀İ", "an explicit zero offset still previews from the document start");
|
|
646
711
|
assert.equal(zero.truncated, true);
|
|
647
|
-
assert.deepEqual(
|
|
712
|
+
assert.deepEqual((await searchData(session, { query: "needle.+" })).items, []);
|
|
648
713
|
});
|
|
649
714
|
test("history_read paginates one document with an accurate limit and a bounded byte cap", async () => {
|
|
650
715
|
const session = manager();
|
|
@@ -652,31 +717,32 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
652
717
|
const ctx = context(session);
|
|
653
718
|
const content = "z".repeat(TOOL_OUTPUT_MAX_BYTES * 2);
|
|
654
719
|
appendText(session, "user", content);
|
|
655
|
-
const seq =
|
|
720
|
+
const seq = (await listData(session, { max_chars_per_item: 1 })).items.map(item => item.seq)[0];
|
|
656
721
|
// 50k requested chars of 64 KiB of text exceeds the byte cap, so the delivered slice stops short
|
|
657
722
|
// of the request rather than at it.
|
|
658
723
|
const full = await call(captured, "history_read", { seq, max_chars: 50_000 }, ctx);
|
|
659
724
|
assertWithinBudget(full, "history_read page");
|
|
660
|
-
|
|
725
|
+
assert.match(resultText(full), /seq 1 \| user/);
|
|
726
|
+
const read = await readData(session, { seq, max_chars: 50_000 });
|
|
661
727
|
assert.equal(read.seq, seq);
|
|
662
728
|
assert.equal(read.total_chars, content.length);
|
|
663
|
-
assert.equal(read.
|
|
729
|
+
assert.equal(read.text, content.slice(0, read.text.length), "the delivered slice is a verbatim prefix");
|
|
664
730
|
assert.equal(read.next_offset_chars !== null, true);
|
|
665
731
|
const text = full.content[0];
|
|
666
732
|
assert.equal(text.type === "text" && text.text.includes("READ WINDOW"), false, "no READ WINDOW block survives");
|
|
667
|
-
assert.match(text.type === "text" ? text.text : "", /\[truncated; continue at offset_chars=\d+\]$/, "a byte-capped window states where to continue");
|
|
668
|
-
const next =
|
|
669
|
-
assert.equal(read.
|
|
670
|
-
assert.equal(Array.from(read.
|
|
671
|
-
const limited =
|
|
672
|
-
assert.equal(limited.
|
|
733
|
+
assert.match(text.type === "text" ? text.text : "", /\[truncated at \d+\/\d+ chars; continue at offset_chars=\d+\]$/, "a byte-capped window states delivered/total and where to continue");
|
|
734
|
+
const next = (await readData(session, { seq, offset_chars: read.next_offset_chars, max_chars: 50_000 }));
|
|
735
|
+
assert.equal(read.text + next.text, content.slice(0, read.text.length + next.text.length));
|
|
736
|
+
assert.equal(Array.from(read.text).length, read.next_offset_chars, "the cursor addresses the first undelivered character");
|
|
737
|
+
const limited = (await readData(session, { seq, max_chars: 10 }));
|
|
738
|
+
assert.equal(limited.text, "z".repeat(10));
|
|
673
739
|
const limitedText = (await call(captured, "history_read", { seq, max_chars: 10 }, ctx)).content[0];
|
|
674
|
-
const limitedSuffix =
|
|
740
|
+
const limitedSuffix = `\n\n[truncated at 10/${content.length} chars; continue at offset_chars=10]`;
|
|
675
741
|
assert.equal(limitedText.type === "text" && limitedText.text.endsWith(limitedSuffix), true, "a count-limited window states where to resume");
|
|
676
|
-
const tail =
|
|
677
|
-
assert.equal(tail.
|
|
742
|
+
const tail = (await readData(session, { seq, offset_chars: -10 }));
|
|
743
|
+
assert.equal(tail.text, "z".repeat(10));
|
|
678
744
|
assert.equal(tail.next_offset_chars, null, "the true end has no continuation");
|
|
679
|
-
const past =
|
|
745
|
+
const past = resultTextError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
|
|
680
746
|
assert.equal(past.code, "invalid_offset");
|
|
681
747
|
assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
|
|
682
748
|
});
|
|
@@ -697,7 +763,7 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
|
|
|
697
763
|
assert.equal(historyDocument(tool).includes("READ WINDOW"), false);
|
|
698
764
|
assert.equal(historyDocument(tool).includes("offset_chars"), false);
|
|
699
765
|
assert.equal(historyDocument(tool).includes("seq "), false, "the document carries no UI identity block");
|
|
700
|
-
const found = await
|
|
766
|
+
const found = await historySearch.execute({ query: "NEEDLE" }, projection);
|
|
701
767
|
assert.equal(found.ok, true);
|
|
702
768
|
if (found.ok) {
|
|
703
769
|
const hit = found.data.items[0];
|