notesoup 0.39.0 ā 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/src/boot/render.js +2 -2
- package/dist/src/boot/text.d.ts +0 -4
- package/dist/src/boot/text.js +9 -13
- package/dist/src/history/history.d.ts +23 -18
- package/dist/src/history/history.js +37 -20
- package/dist/src/history/query.d.ts +37 -49
- package/dist/src/history/query.js +114 -56
- package/dist/src/notes/store.d.ts +3 -4
- package/dist/src/notes/store.js +12 -16
- package/dist/src/pi/history-tools.d.ts +1 -1
- package/dist/src/pi/history-tools.js +2 -3
- package/dist/src/pi/runtime.js +1 -1
- package/dist/src/pi/tool-names.d.ts +0 -4
- package/dist/src/pi/tool-names.js +0 -4
- package/dist/src/tools/history.d.ts +24 -33
- package/dist/src/tools/history.js +57 -98
- package/dist/src/tools/notes.d.ts +26 -58
- package/dist/src/tools/notes.js +85 -103
- package/dist/src/tools/result.d.ts +16 -13
- package/dist/src/tools/result.js +24 -50
- package/dist/src/tools/schema.d.ts +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +1 -1
- package/dist/test/boot.integration.test.js +1 -1
- package/dist/test/claude-mod.test.js +4 -4
- package/dist/test/dependencies.test.js +1 -1
- package/dist/test/helpers/extension.js +2 -3
- package/dist/test/history.integration.test.js +200 -123
- package/dist/test/host-neutral.test.js +32 -58
- package/dist/test/notes-library.test.js +8 -8
- package/dist/test/notes.integration.test.js +75 -57
- package/dist/test/notes.test.js +44 -42
- package/docs/architecture.md +3 -3
- package/docs/notes-library.md +6 -6
- package/docs/tool-results.md +15 -25
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +119 -178
- package/mods/notesoup/hooks/register.ts +1 -2
- package/package.json +1 -1
- package/skills/memory/SKILL.md +6 -6
- package/src/boot/render.ts +2 -2
- package/src/boot/text.ts +9 -17
- package/src/history/history.ts +36 -20
- package/src/history/query.ts +130 -55
- package/src/notes/store.ts +15 -18
- package/src/pi/history-tools.ts +2 -3
- package/src/pi/runtime.ts +1 -1
- package/src/pi/tool-names.ts +0 -4
- package/src/tools/history.ts +61 -100
- package/src/tools/notes.ts +84 -97
- package/src/tools/result.ts +24 -49
- package/src/tools/schema.ts +3 -3
|
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { Check } from "typebox/value";
|
|
4
4
|
import { earliestMatchOffsetChars, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
5
|
-
import { historyList, historyRead,
|
|
5
|
+
import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
|
|
6
6
|
import { historyDocument, projectHistory } from "../src/history/history.js";
|
|
7
7
|
import { selectPage } from "../src/history/query.js";
|
|
8
8
|
import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
|
|
@@ -28,36 +28,41 @@ function seqs(result) {
|
|
|
28
28
|
function rendered(result) {
|
|
29
29
|
return result.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("");
|
|
30
30
|
}
|
|
31
|
-
test("
|
|
31
|
+
test("history_list exposes bounded paging, `from` and a literal query, while notes use snapshot limits", () => {
|
|
32
32
|
const captured = makeExtension(manager());
|
|
33
33
|
const readSchema = captured.tools.get("history_read")?.parameters;
|
|
34
34
|
const legacyItemKey = ["item", "id"].join("_");
|
|
35
|
-
const legacyOrderingKey = ["recent", "first"].join("_");
|
|
36
35
|
assert.ok(readSchema.properties?.seq);
|
|
37
36
|
assert.deepEqual(readSchema.required, ["seq"]);
|
|
38
37
|
assert.equal(readSchema.properties?.[legacyItemKey], undefined);
|
|
39
38
|
assert.equal(readSchema.properties?.window_id, undefined);
|
|
40
|
-
const listSchema = captured.tools.get("history_list")
|
|
41
|
-
|
|
42
|
-
assert.
|
|
43
|
-
assert.equal(
|
|
44
|
-
assert.
|
|
45
|
-
assert.equal(listSchema
|
|
46
|
-
|
|
47
|
-
assert.
|
|
48
|
-
|
|
49
|
-
assert.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
const listSchema = captured.tools.get("history_list").parameters;
|
|
40
|
+
const properties = listSchema.properties;
|
|
41
|
+
assert.equal(properties.before_seq?.minimum, 1, "bounds are positive seqs");
|
|
42
|
+
assert.equal(properties.after_seq?.minimum, 1);
|
|
43
|
+
assert.equal(Check(listSchema, { before_seq: 0 }), false, "before_seq:0 is refused by the schema, not answered with a silent empty page");
|
|
44
|
+
assert.equal(Check(listSchema, { after_seq: 0 }), false);
|
|
45
|
+
assert.deepEqual(properties.from?.anyOf?.map((item) => item.const), ["newest", "oldest"]);
|
|
46
|
+
assert.ok(properties.query);
|
|
47
|
+
assert.equal(properties.around, undefined);
|
|
48
|
+
assert.equal(properties.tool_name, undefined);
|
|
49
|
+
assert.equal(properties.custom_type, undefined);
|
|
50
|
+
assert.equal(properties.cursor, undefined);
|
|
51
|
+
assert.deepEqual(properties.roles?.items?.anyOf?.map((item) => item.const), ["user", "assistant", "tool", "context"], "the role filter carries the four public roles");
|
|
52
|
+
assert.ok(properties.since, "the time filter has a since param");
|
|
53
|
+
assert.ok(properties.until, "the time filter has an until param");
|
|
54
|
+
assert.equal(Check(listSchema, { since: "2026-10-10", until: "2026-10-10T06:00:00Z" }), true);
|
|
55
|
+
assert.equal(Check(listSchema, { since: "" }), false, "an empty time value is refused by the schema");
|
|
56
|
+
assert.equal(Check(listSchema, { query: "needle", from: "oldest", roles: ["tool"] }), true);
|
|
57
|
+
assert.equal(Check(listSchema, { from: "recent" }), false);
|
|
58
|
+
// The retired names are unknown parameters, refused like any other: `additionalProperties: false`.
|
|
59
|
+
for (const retired of [{ before: 5 }, { after: 5 }, { order: "oldest" }, { limit_chars: 10 }]) {
|
|
60
|
+
assert.equal(Check(listSchema, retired), false, `${Object.keys(retired)[0]} is refused as an unknown parameter`);
|
|
61
|
+
}
|
|
62
|
+
assert.equal(Check(listSchema, { query: "" }), true, "an empty literal is schema-valid; the operation refuses it as invalid_query");
|
|
63
|
+
for (const invalid of [{ roles: ["tool_call"] }, { roles: ["system"] }, { tool_name: "bash" }, { roles: [] }]) {
|
|
64
|
+
assert.equal(Check(listSchema, invalid), false, JSON.stringify(invalid));
|
|
57
65
|
}
|
|
58
|
-
assert.equal(listSchema.properties?.custom_type, undefined);
|
|
59
|
-
assert.equal(listSchema.properties?.cursor, undefined);
|
|
60
|
-
assert.equal(listSchema.properties?.[legacyOrderingKey], undefined);
|
|
61
66
|
const windowsSchema = captured.tools.get("history_windows")?.parameters;
|
|
62
67
|
assert.deepEqual(Object.keys(windowsSchema.properties ?? []), []);
|
|
63
68
|
const notesSchema = captured.tools.get("notes_list")?.parameters;
|
|
@@ -74,9 +79,9 @@ test("every history operation declares a result schema its own payload satisfies
|
|
|
74
79
|
appendText(session, "user", "hello");
|
|
75
80
|
toolCall(session, "call-1", "bash", { command: "pwd" });
|
|
76
81
|
toolResult(session, "call-1", "bash", "/tmp");
|
|
77
|
-
for (const toolName of ["history_windows", "history_list", "
|
|
78
|
-
const operation = { history_windows: historyWindows, history_list: historyList,
|
|
79
|
-
const result = await call(captured, toolName, toolName === "history_read" ? { seq: 1 } : toolName === "
|
|
82
|
+
for (const toolName of ["history_windows", "history_list", "history_read"]) {
|
|
83
|
+
const operation = { history_windows: historyWindows, history_list: historyList, history_read: historyRead }[toolName];
|
|
84
|
+
const result = await call(captured, toolName, toolName === "history_read" ? { seq: 1 } : toolName === "history_list" ? { query: "hello" } : {}, ctx);
|
|
80
85
|
const structured = result.structuredContent;
|
|
81
86
|
assert.ok(structured !== undefined, `${toolName} carries a structured outcome`);
|
|
82
87
|
assert.equal(Check(operation.outputSchema, structured), true, `${toolName} payload satisfies its own outputSchema`);
|
|
@@ -84,7 +89,6 @@ test("every history operation declares a result schema its own payload satisfies
|
|
|
84
89
|
}
|
|
85
90
|
const conversation = await call(captured, "history_list", {}, ctx);
|
|
86
91
|
assert.equal(Check(historyList.outputSchema, conversation.structuredContent), true);
|
|
87
|
-
assert.equal(Check(historySearch.outputSchema, conversation.structuredContent), false, "search schema excludes list-only folds");
|
|
88
92
|
const refusal = await call(captured, "history_read", { seq: 999 }, ctx);
|
|
89
93
|
assert.equal(Check(historyRead.outputSchema, refusal.structuredContent), true, "a refusal satisfies the same result schema");
|
|
90
94
|
});
|
|
@@ -120,53 +124,101 @@ test("a result address consumed by a pairing names its call instead of serving a
|
|
|
120
124
|
const consumed = resultError(await call(captured, "history_read", { seq: 3 }, ctx));
|
|
121
125
|
assert.equal(consumed.code, "not_an_event");
|
|
122
126
|
assert.match(consumed.message, /already shown inside the call at seq 2/);
|
|
123
|
-
assert.equal(consumed.details?.read_seq, 2, "the refusal names the address to read instead");
|
|
124
127
|
const callSeq = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
125
128
|
assert.equal(callSeq.seq, 2);
|
|
126
129
|
assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
|
|
127
130
|
});
|
|
128
|
-
test("
|
|
131
|
+
test("history_list pages from the end `from` names and returns bounded ranges", async () => {
|
|
129
132
|
const session = manager();
|
|
130
133
|
const captured = makeExtension(session);
|
|
131
134
|
const ctx = context(session);
|
|
132
135
|
for (let index = 1; index <= 5; index++)
|
|
133
136
|
appendText(session, "user", `message-${index}`);
|
|
134
|
-
assert.deepEqual(seqs(await call(captured, "history_list", { limit: 2 }, ctx)), [4, 5]);
|
|
137
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { limit: 2 }, ctx)), [4, 5], "the default newest page is the highest seqs, ascending");
|
|
138
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { limit: 2, from: "oldest" }, ctx)), [1, 2], "from oldest takes the other end of the same selection");
|
|
135
139
|
appendText(session, "user", "message-6");
|
|
136
|
-
const older = page(await call(captured, "history_list", {
|
|
140
|
+
const older = page(await call(captured, "history_list", { before_seq: 5, limit: 2 }, ctx));
|
|
137
141
|
assert.deepEqual(older.items.map((item) => item.seq), [3, 4]);
|
|
138
|
-
assert.
|
|
139
|
-
assert.equal(older.
|
|
140
|
-
assert.deepEqual(seqs(await call(captured, "history_list", {
|
|
142
|
+
assert.deepEqual(older.page_older, { before_seq: 3 });
|
|
143
|
+
assert.equal(older.page_newer, null);
|
|
144
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 5, limit: 2, from: "oldest" }, ctx)), [6]);
|
|
141
145
|
for (let index = 7; index <= 10; index++)
|
|
142
146
|
appendText(session, "user", `message-${index}`);
|
|
143
|
-
const range = page(await call(captured, "history_list", {
|
|
147
|
+
const range = page(await call(captured, "history_list", { after_seq: 2, before_seq: 10, limit: 3, from: "oldest" }, ctx));
|
|
144
148
|
assert.deepEqual(range.items.map((item) => item.seq), [3, 4, 5]);
|
|
145
|
-
assert.equal(range.
|
|
146
|
-
assert.
|
|
147
|
-
|
|
149
|
+
assert.equal(range.page_older, null);
|
|
150
|
+
assert.deepEqual(range.page_newer, { after_seq: 5, from: "oldest" }, "both bounds do not imply a direction; the cursor carries one");
|
|
151
|
+
assert.match(rendered(await call(captured, "history_list", { after_seq: 2, before_seq: 10, limit: 3, from: "oldest" }, ctx)), /ā newer: \{"after_seq":5,"from":"oldest"\}/, "the footer prints the exact call to page newer");
|
|
152
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 2, before_seq: 10, limit: 3 }, ctx)), [7, 8, 9], "the same range with the default from starts from the newest end");
|
|
153
|
+
const rangeNext = page(await call(captured, "history_list", { ...range.page_newer, before_seq: 10, limit: 3 }, ctx));
|
|
148
154
|
assert.deepEqual(rangeNext.items.map((item) => item.seq), [6, 7, 8]);
|
|
149
|
-
const rangeLast = page(await call(captured, "history_list", {
|
|
155
|
+
const rangeLast = page(await call(captured, "history_list", { ...rangeNext.page_newer, before_seq: 10, limit: 3 }, ctx));
|
|
150
156
|
assert.deepEqual(rangeLast.items.map((item) => item.seq), [9]);
|
|
151
|
-
assert.equal(rangeLast.
|
|
152
|
-
assert.equal(rangeLast.
|
|
157
|
+
assert.equal(rangeLast.page_older, null);
|
|
158
|
+
assert.equal(rangeLast.page_newer, null);
|
|
153
159
|
assert.equal("has_older" in rangeLast, false);
|
|
154
160
|
assert.equal("has_newer" in rangeLast, false);
|
|
155
|
-
assert.equal((captured.tools.get("history_list")?.parameters).properties?.before?.minimum, undefined, "bounds take any integer; the implementation treats out-of-range values as empty/open");
|
|
156
|
-
assert.equal((captured.tools.get("history_list")?.parameters).properties?.after?.minimum, undefined);
|
|
157
161
|
});
|
|
158
162
|
test("a one-row page budget admits the newest candidate first", () => {
|
|
159
163
|
const windowId = "w1";
|
|
160
164
|
const items = [1, 2, 3].map((seq) => ({ seq, windowId, role: "user", text: `message-${seq}`, createdAt: undefined }));
|
|
161
165
|
const projection = projectHistory([{ windowId, items }], 12, new Set([1, 2, 3]));
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const outcome = selectPage(projection, { limit: 3 }, candidates, false, (candidate) => candidate.items.length <= fitsRows, 200);
|
|
166
|
+
const keptSeqs = (fitsRows, from) => {
|
|
167
|
+
const outcome = selectPage(projection, { limit: 3, ...(from === undefined ? {} : { from }) }, (candidate) => candidate.items.length <= fitsRows, 200);
|
|
165
168
|
assert.equal(outcome.ok, true);
|
|
166
169
|
return outcome.ok ? outcome.data.items.map((item) => ("folded" in item ? item.first_seq : item.seq)) : [];
|
|
167
170
|
};
|
|
168
|
-
assert.deepEqual(
|
|
169
|
-
assert.deepEqual(
|
|
171
|
+
assert.deepEqual(keptSeqs(1), [3], "a budget for one row admits the newest candidate, not the oldest");
|
|
172
|
+
assert.deepEqual(keptSeqs(2), [2, 3], "a truncated prefix is the newest rows, delivered in chronological order");
|
|
173
|
+
assert.deepEqual(keptSeqs(1, "oldest"), [1], "from oldest keeps the other end when the budget is short");
|
|
174
|
+
});
|
|
175
|
+
test("since and until select a half-open time range, compose with query and paging, and refuse bad bounds", async () => {
|
|
176
|
+
const items = [
|
|
177
|
+
{ seq: 1, windowId: "w1", role: "user", text: "first needle", createdAt: "2026-10-10T00:00:00.000Z" },
|
|
178
|
+
{ seq: 2, windowId: "w1", role: "assistant", text: "second", createdAt: "2026-10-10T06:00:00.000Z" },
|
|
179
|
+
{ seq: 3, windowId: "w1", role: "user", text: "third needle", createdAt: "2026-10-10T12:00:00.000Z" },
|
|
180
|
+
{ seq: 4, windowId: "w1", role: "assistant", text: "fourth", createdAt: "2026-10-10T18:00:00.000Z" },
|
|
181
|
+
{ seq: 5, windowId: "w1", role: "user", text: "fifth needle", createdAt: undefined },
|
|
182
|
+
];
|
|
183
|
+
const projection = projectHistory([{ windowId: "w1", items }], 5, new Set([1, 2, 3, 4, 5]));
|
|
184
|
+
const selected = async (params) => {
|
|
185
|
+
const outcome = await historyList.execute(params, projection);
|
|
186
|
+
assert.equal(outcome.ok, true, JSON.stringify(outcome));
|
|
187
|
+
return outcome.ok ? outcome.data.items.map((item) => ("folded" in item ? item.first_seq : item.seq)) : [];
|
|
188
|
+
};
|
|
189
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", since: "2026-10-10T06:00:00Z" }), [2, 3, 4], "since keeps later events and drops one with no time");
|
|
190
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", until: "2026-10-10T12:00:00Z" }), [1, 2], "until is exclusive");
|
|
191
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", since: "2026-10-10T06:00:00Z", until: "2026-10-10T18:00:00Z" }), [2, 3], "both bounds make a half-open range");
|
|
192
|
+
assert.deepEqual(await selected({ query: "needle", from: "oldest", since: "2026-10-10T06:00:00Z" }), [3], "a query composes with the time range");
|
|
193
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", since: "2026-10-10T00:00:00Z", until: "2026-10-10T18:00:00Z", after_seq: 1, before_seq: 4 }), [2, 3], "seq paging composes with the time range");
|
|
194
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", since: "2026-10-10" }), [1, 2, 3, 4], "a date-only since is inclusive UTC midnight, not local midnight");
|
|
195
|
+
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", until: "2026-10-10T12:00" }), [1, 2], "a time without an offset is UTC");
|
|
196
|
+
const malformed = await historyList.execute({ since: "yesterday" }, projection);
|
|
197
|
+
assert.equal(malformed.ok, false);
|
|
198
|
+
if (!malformed.ok) {
|
|
199
|
+
assert.equal(malformed.error.code, "invalid_time");
|
|
200
|
+
assert.match(malformed.error.message, /"yesterday"/, "the refusal names the offending param and value");
|
|
201
|
+
}
|
|
202
|
+
const inverted = await historyList.execute({ since: "2026-10-11", until: "2026-10-10" }, projection);
|
|
203
|
+
assert.equal(inverted.ok, false);
|
|
204
|
+
if (!inverted.ok)
|
|
205
|
+
assert.equal(inverted.error.code, "invalid_time");
|
|
206
|
+
});
|
|
207
|
+
test("time bounds also keep untimed events out of the folded conversation view", async () => {
|
|
208
|
+
const items = [
|
|
209
|
+
{ seq: 1, windowId: "w1", role: "user", text: "before", createdAt: "2026-10-10T00:00:00.000Z" },
|
|
210
|
+
{ seq: 2, windowId: "w1", role: "tool", text: "output", createdAt: undefined },
|
|
211
|
+
{ seq: 3, windowId: "w1", role: "user", text: "after", createdAt: "2026-10-10T12:00:00.000Z" },
|
|
212
|
+
];
|
|
213
|
+
const projection = projectHistory([{ windowId: "w1", items }], 3, new Set([1, 2, 3]));
|
|
214
|
+
const bounded = await historyList.execute({ since: "2026-10-10T00:00:00Z" }, projection);
|
|
215
|
+
assert.equal(bounded.ok, true);
|
|
216
|
+
if (bounded.ok)
|
|
217
|
+
assert.deepEqual(bounded.data.items.map((item) => ("folded" in item ? `folded ${item.count}` : `seq ${item.seq}`)), ["seq 1", "seq 3"], "an untimed tool event is not folded into a bounded selection");
|
|
218
|
+
const unbounded = await historyList.execute({}, projection);
|
|
219
|
+
assert.equal(unbounded.ok, true);
|
|
220
|
+
if (unbounded.ok)
|
|
221
|
+
assert.equal(unbounded.data.items.some((item) => "folded" in item), true, "without bounds the untimed run still folds");
|
|
170
222
|
});
|
|
171
223
|
test("conversation view folds tools and injected messages, while explicit roles expand them", async () => {
|
|
172
224
|
const session = manager();
|
|
@@ -192,22 +244,22 @@ test("conversation view folds tools and injected messages, while explicit roles
|
|
|
192
244
|
assert.equal(conversation.items.some((item) => item.folded === true), true);
|
|
193
245
|
assert.equal(conversation.items.some((item) => item.role === "developer"), false);
|
|
194
246
|
assert.equal(conversation.items.some((item) => item.role === "tool"), false);
|
|
195
|
-
assert.equal(conversation.items.some((item) => item.role === "assistant" && item.
|
|
247
|
+
assert.equal(conversation.items.some((item) => item.role === "assistant" && item.content === ""), false);
|
|
196
248
|
assert.equal(conversation.items.every((item) => legacyItemKey in item === false), true);
|
|
197
249
|
const folded = conversation.items.find((item) => item.folded === true);
|
|
198
250
|
assert.equal(folded.count, 3, "two tool events and one injected context are folded, not the empty assistant message");
|
|
199
251
|
assert.deepEqual(folded.tools, { bash: 1, read: 1 });
|
|
200
252
|
assert.equal("custom_types" in folded, false);
|
|
201
|
-
const empty = page(await call(captured, "history_list", { roles: ["context"],
|
|
253
|
+
const empty = page(await call(captured, "history_list", { roles: ["context"], before_seq: 2 }, ctx));
|
|
202
254
|
assert.deepEqual(empty.items, []);
|
|
203
|
-
const hiddenOnly = page(await call(captured, "history_list", {
|
|
255
|
+
const hiddenOnly = page(await call(captured, "history_list", { after_seq: 2, before_seq: 6 }, ctx));
|
|
204
256
|
assert.deepEqual(hiddenOnly.items, [{ folded: true, first_seq: 3, last_seq: 4, count: 2, tools: { bash: 1, read: 1 } }]);
|
|
205
257
|
const expanded = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
|
|
206
258
|
assert.deepEqual(expanded.items.map((item) => [item.seq, item.role, item.tool, item.tool_status]), [[3, "tool", "bash", "ok"], [4, "tool", "read", "ok"]]);
|
|
207
259
|
assert.equal(expanded.items[0].content, 'bash {"command":"pwd"}\n--- output ---\nok');
|
|
208
260
|
assert.equal(expanded.items[1].content, 'read {"path":"README.md"}\n--- output ---\ncontents');
|
|
209
261
|
assert.equal(expanded.items.every((item) => !("call_seq" in item || "result_seq" in item || "tool_name" in item)), true);
|
|
210
|
-
assert.deepEqual(seqs(await call(captured, "
|
|
262
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { query: "bash", roles: ["tool"] }, ctx)), [3]);
|
|
211
263
|
const injected = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
|
|
212
264
|
assert.deepEqual(injected.items.map((item) => [item.role, item.content]), [["context", "injected event"]]);
|
|
213
265
|
assert.equal(turnId.length > 0, true);
|
|
@@ -229,7 +281,6 @@ test("tool summaries and documents preserve pending, errored, and orphan runs",
|
|
|
229
281
|
assert.equal(events.items[0].content, 'edit {"path":"š.md","oldText":"before"}\n--- output ---\nreplacement OK');
|
|
230
282
|
assert.equal(events.items[1].content, 'edit {"path":"pending.md"}', "an unfinished call claims no output");
|
|
231
283
|
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");
|
|
232
|
-
assert.deepEqual(events.items[2].nested_calls, { call_count: 1, complete: true }, "an orphan's nested records are counted on its row like any other run's");
|
|
233
284
|
const errored = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
234
285
|
assert.equal(errored.tool, "edit");
|
|
235
286
|
assert.equal(errored.tool_status, "error");
|
|
@@ -240,10 +291,10 @@ test("tool summaries and documents preserve pending, errored, and orphan runs",
|
|
|
240
291
|
const orphan = resultRead(await call(captured, "history_read", { seq: 6 }, ctx));
|
|
241
292
|
assert.deepEqual(orphan.nested_calls, { call_count: 1, complete: true });
|
|
242
293
|
assert.equal(orphan.text, events.items[2].content, "an orphan's nested evidence stays readable despite the missing call");
|
|
243
|
-
assert.deepEqual(seqs(await call(captured, "
|
|
244
|
-
assert.deepEqual(seqs(await call(captured, "
|
|
245
|
-
assert.deepEqual(seqs(await call(captured, "
|
|
246
|
-
assert.deepEqual(seqs(await call(captured, "
|
|
294
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { query: "edit", roles: ["tool"] }, ctx)), [2, 5, 6]);
|
|
295
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { query: "pending.md", roles: ["tool"] }, ctx)), [5]);
|
|
296
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { query: "orphan output", roles: ["tool"] }, ctx)), [6]);
|
|
297
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { query: "orphan-nested.md", roles: ["tool"] }, ctx)), [6], "nested evidence stays findable even when the call it belongs to was never recorded");
|
|
247
298
|
});
|
|
248
299
|
test("native nested-call records are searchable, readable, and never gain a result or an address", async () => {
|
|
249
300
|
const session = manager();
|
|
@@ -260,10 +311,8 @@ test("native nested-call records are searchable, readable, and never gain a resu
|
|
|
260
311
|
],
|
|
261
312
|
},
|
|
262
313
|
});
|
|
263
|
-
const found = page(await call(captured, "
|
|
314
|
+
const found = page(await call(captured, "history_list", { query: "nested-needle" }, ctx));
|
|
264
315
|
assert.deepEqual(found.items.map((item) => item.seq), [2], "nested arguments are part of the searchable document");
|
|
265
|
-
const row = found.items[0];
|
|
266
|
-
assert.deepEqual(row.nested_calls, { call_count: 3, complete: false }, "the list row reports counts and the host's own completeness flag");
|
|
267
316
|
const read = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
268
317
|
assert.deepEqual(read.nested_calls, { call_count: 3, complete: false }, "the host's completeness flag stays unchanged");
|
|
269
318
|
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)');
|
|
@@ -281,7 +330,7 @@ test("absent nested calls mean unavailable, not a known-empty record", async ()
|
|
|
281
330
|
toolCall(session, "plain", "read", { path: "a.md" });
|
|
282
331
|
toolResult(session, "plain", "read", "contents");
|
|
283
332
|
const listed = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
|
|
284
|
-
assert.equal("nested_calls" in listed.items[0], false, "
|
|
333
|
+
assert.equal("nested_calls" in listed.items[0], false, "a page row never carries nested-call evidence; one read does");
|
|
285
334
|
const read = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
286
335
|
assert.equal("nested_calls" in read, false);
|
|
287
336
|
assert.equal(read.content.includes("nested calls"), false);
|
|
@@ -298,18 +347,14 @@ test("oversized arguments and long nested records remain fully pageable and sear
|
|
|
298
347
|
calls: Array.from({ length: 400 }, (_, index) => ({ id: `big/${index}`, name: "read", arguments: { path: `p${index}.md` }, status: "ok", durationMs: 1 })),
|
|
299
348
|
},
|
|
300
349
|
});
|
|
301
|
-
|
|
302
|
-
assert.deepEqual(
|
|
303
|
-
let read = resultRead(await call(captured, "history_read", { seq: 2, limit_chars: 50_000 }, ctx));
|
|
304
|
-
assert.deepEqual(read.nested_calls, { call_count: 400, complete: true });
|
|
305
|
-
assert.equal(read.limited_by, "bytes");
|
|
350
|
+
let read = resultRead(await call(captured, "history_read", { seq: 2, max_chars: 50_000 }, ctx));
|
|
351
|
+
assert.deepEqual(read.nested_calls, { call_count: 400, complete: true }, "the read counts every recorded call, not only the records one page can carry");
|
|
306
352
|
let document = read.text;
|
|
307
353
|
while (read.next_offset_chars !== null) {
|
|
308
354
|
const next = read.next_offset_chars;
|
|
309
|
-
const result = await call(captured, "history_read", { seq: 2, offset_chars: next,
|
|
355
|
+
const result = await call(captured, "history_read", { seq: 2, offset_chars: next, max_chars: 50_000 }, ctx);
|
|
310
356
|
assertWithinBudget(result, "bounded document page");
|
|
311
357
|
read = resultRead(result);
|
|
312
|
-
assert.equal(read.offset_chars, next);
|
|
313
358
|
assert.ok(read.text.length > 0, "every continuation makes progress");
|
|
314
359
|
document += read.text;
|
|
315
360
|
}
|
|
@@ -317,19 +362,20 @@ test("oversized arguments and long nested records remain fully pageable and sear
|
|
|
317
362
|
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");
|
|
318
363
|
assertWithinBudget(await call(captured, "history_read", { seq: 2 }, ctx), "bounded first read");
|
|
319
364
|
assertWithinBudget(await call(captured, "history_list", { roles: ["tool"] }, ctx), "bounded list row");
|
|
320
|
-
const
|
|
321
|
-
assert.deepEqual(
|
|
322
|
-
const late = page(await call(captured, "
|
|
365
|
+
const hit = page(await call(captured, "history_list", { query: "big.md", max_chars_per_item: 40 }, ctx));
|
|
366
|
+
assert.deepEqual(hit.items.map((item) => item.seq), [2], "the document still carries the real arguments, so a query still finds them");
|
|
367
|
+
const late = page(await call(captured, "history_list", { query: "p399.md" }, ctx)).items[0];
|
|
323
368
|
assert.equal(late.seq, 2);
|
|
324
369
|
const resumed = resultRead(await call(captured, "history_read", { seq: 2, offset_chars: late.offset_chars }, ctx));
|
|
325
|
-
assert.ok(resumed.text.startsWith("p399.md"), "
|
|
370
|
+
assert.ok(resumed.text.startsWith("p399.md"), "a query can jump directly to evidence beyond the first read");
|
|
326
371
|
});
|
|
327
372
|
test("standalone bash execution retains command, output, and truncation path", async () => {
|
|
328
373
|
const session = manager();
|
|
329
374
|
const captured = makeExtension(session);
|
|
330
375
|
const ctx = context(session);
|
|
331
376
|
append(session, { role: "bashExecution", command: "echo needle", output: "needle output", exitCode: 0, cancelled: false, truncated: true, fullOutputPath: "/tmp/bash-output.txt", timestamp: Date.now() });
|
|
332
|
-
const
|
|
377
|
+
const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
|
|
378
|
+
const found = page(raw);
|
|
333
379
|
assert.equal(found.items.length, 1);
|
|
334
380
|
assert.deepEqual(found.items[0], {
|
|
335
381
|
seq: 1,
|
|
@@ -341,15 +387,32 @@ test("standalone bash execution retains command, output, and truncation path", a
|
|
|
341
387
|
output_truncated: true,
|
|
342
388
|
full_output_path: "/tmp/bash-output.txt",
|
|
343
389
|
truncated: false,
|
|
344
|
-
total_chars: 59,
|
|
345
390
|
content: 'bash {"command":"echo needle"}\n--- output ---\nneedle output',
|
|
346
391
|
});
|
|
347
|
-
|
|
392
|
+
assert.match(rendered(raw), /output truncated, full text at \/tmp\/bash-output\.txt/, "a truncation with a path names both");
|
|
393
|
+
const query = page(await call(captured, "history_list", { roles: ["tool"], query: "NEEDLE OUTPUT" }, ctx));
|
|
348
394
|
assert.deepEqual(query.items.map((item) => item.seq), [1]);
|
|
349
395
|
const read = resultRead(await call(captured, "history_read", { seq: 1, offset_chars: query.items[0].offset_chars }, ctx));
|
|
350
396
|
assert.equal(read.content, "needle output");
|
|
351
397
|
assert.equal(read.seq, 1);
|
|
352
398
|
});
|
|
399
|
+
test("a truncated tool run without a recorded path still reports output_truncated", async () => {
|
|
400
|
+
const session = manager();
|
|
401
|
+
const captured = makeExtension(session);
|
|
402
|
+
const ctx = context(session);
|
|
403
|
+
append(session, { role: "bashExecution", command: "echo big", output: "big output", exitCode: 0, cancelled: false, truncated: true, timestamp: Date.now() });
|
|
404
|
+
const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
|
|
405
|
+
const found = page(raw);
|
|
406
|
+
assert.equal(found.items.length, 1);
|
|
407
|
+
const item = found.items[0];
|
|
408
|
+
assert.equal(item.output_truncated, true, "the truncation is reported even with no path");
|
|
409
|
+
assert.equal("full_output_path" in item, false, "no path is invented");
|
|
410
|
+
assert.match(rendered(raw), /output truncated/, "the header still says the output was truncated");
|
|
411
|
+
assert.equal(rendered(raw).includes("full text at"), false, "the header claims no path");
|
|
412
|
+
const read = resultRead(await call(captured, "history_read", { seq: 1 }, ctx));
|
|
413
|
+
assert.equal(read.output_truncated, true, "the read reports the same truncation");
|
|
414
|
+
assert.equal("full_output_path" in read, false);
|
|
415
|
+
});
|
|
353
416
|
test("list renders paging and fold recipes, read renders a neighborhood call, and @previous resolves", async () => {
|
|
354
417
|
const session = manager();
|
|
355
418
|
const captured = makeExtension(session);
|
|
@@ -359,28 +422,30 @@ test("list renders paging and fold recipes, read renders a neighborhood call, an
|
|
|
359
422
|
session.appendCustomEntry("notesoup/reset-marker", { windowId: "pcw:test:w2" });
|
|
360
423
|
appendText(session, "user", "current window");
|
|
361
424
|
const listed = await call(captured, "history_list", {}, ctx);
|
|
362
|
-
assert.match(rendered(listed), /ā older: \{"
|
|
425
|
+
assert.match(rendered(listed), /ā older: \{"before_seq":\d+\}/, "the footer prints the exact call to page older");
|
|
363
426
|
const windows = resultData(await call(captured, "history_windows", {}, ctx));
|
|
364
427
|
assert.equal(windows.windows.length, 2);
|
|
365
428
|
const previous = page(await call(captured, "history_list", { window_id: "@previous" }, ctx));
|
|
366
429
|
assert.ok(previous.items.length > 0 && previous.items.every((item) => item.window_id === windows.windows[0].window_id), "@previous names the window before the current one");
|
|
367
|
-
const
|
|
368
|
-
assert.ok(
|
|
430
|
+
const previousQuery = page(await call(captured, "history_list", { query: "older window", window_id: "@previous" }, ctx));
|
|
431
|
+
assert.ok(previousQuery.items.length > 0, "a query resolves the alias too");
|
|
369
432
|
toolCall(session, "t1", "bash", { command: "ls" });
|
|
370
433
|
toolResult(session, "t1", "bash", "done");
|
|
371
434
|
appendText(session, "user", "after tools");
|
|
372
435
|
const folded = await call(captured, "history_list", {}, ctx);
|
|
373
|
-
assert.match(rendered(folded), /ā expand: \{"
|
|
436
|
+
assert.match(rendered(folded), /ā expand: \{"after_seq":\d+,"before_seq":\d+,"from":"oldest","roles":\["tool","context"\]\}/, "a folded row prints its own expand recipe");
|
|
374
437
|
appendText(session, "user", "needle read target");
|
|
375
|
-
const hits = page(await call(captured, "
|
|
438
|
+
const hits = page(await call(captured, "history_list", { query: "needle read target" }, ctx));
|
|
376
439
|
const read = await call(captured, "history_read", { seq: hits.items[0].seq }, ctx);
|
|
377
|
-
assert.match(rendered(read), /neighborhood ā history_list
|
|
440
|
+
assert.match(rendered(read), /neighborhood ā `history_list`\(\{"after_seq":\d+,"before_seq":\d+\}\)/, "a read prints the call for surrounding events");
|
|
378
441
|
const solo = manager();
|
|
379
442
|
const soloCaptured = makeExtension(solo);
|
|
380
443
|
appendText(solo, "user", "only window");
|
|
444
|
+
const soloWindows = resultData(await call(soloCaptured, "history_windows", {}, context(solo)));
|
|
381
445
|
const noPrevious = resultError(await call(soloCaptured, "history_list", { window_id: "@previous" }, context(solo)));
|
|
382
446
|
assert.equal(noPrevious.code, "unknown_window_id");
|
|
383
447
|
assert.match(noPrevious.message, /@previous/);
|
|
448
|
+
assert.match(noPrevious.message, new RegExp(`; known: ${soloWindows.windows[0].window_id}$`), "the refusal names the window the session does have");
|
|
384
449
|
});
|
|
385
450
|
test("compaction summary becomes context and is folded in the default list", async () => {
|
|
386
451
|
const session = manager();
|
|
@@ -397,70 +462,84 @@ test("compaction summary becomes context and is folded in the default list", asy
|
|
|
397
462
|
const contextItems = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
|
|
398
463
|
assert.deepEqual(contextItems.items.map((item) => [item.role, item.content]), [["context", "summary needle"]]);
|
|
399
464
|
});
|
|
400
|
-
test("
|
|
465
|
+
test("a query covers every role, carries match offsets and refuses an empty literal", async () => {
|
|
401
466
|
const session = manager();
|
|
402
467
|
const captured = makeExtension(session);
|
|
403
468
|
const ctx = context(session);
|
|
404
469
|
appendText(session, "user", "visible needle");
|
|
405
470
|
session.appendCustomMessageEntry("notesoup/boot", "developer needle", false);
|
|
406
471
|
appendText(session, "assistant", "assistant needle");
|
|
407
|
-
const all = page(await call(captured, "
|
|
472
|
+
const all = page(await call(captured, "history_list", { query: "needle" }, ctx));
|
|
408
473
|
assert.deepEqual(all.items.map((item) => item.role), ["user", "context", "assistant"]);
|
|
409
474
|
assert.ok(all.items.every((item) => typeof item.seq === "number" && typeof item.offset_chars === "number"));
|
|
410
|
-
const developers = page(await call(captured, "
|
|
475
|
+
const developers = page(await call(captured, "history_list", { query: "needle", roles: ["context"] }, ctx));
|
|
411
476
|
assert.deepEqual(developers.items.map((item) => item.role), ["context"]);
|
|
412
477
|
assert.equal("custom_type" in developers.items[0], false);
|
|
413
|
-
const first = page(await call(captured, "
|
|
414
|
-
assert.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
478
|
+
const first = page(await call(captured, "history_list", { query: "needle", after_seq: 1, limit: 1, from: "oldest" }, ctx));
|
|
479
|
+
assert.deepEqual(first.items.map((item) => item.seq), [2]);
|
|
480
|
+
assert.deepEqual(first.page_newer, { after_seq: 2, from: "oldest" });
|
|
481
|
+
const next = page(await call(captured, "history_list", { query: "needle", ...first.page_newer, limit: 2 }, ctx));
|
|
482
|
+
assert.deepEqual(next.items.map((item) => item.seq), [3]);
|
|
483
|
+
const absent = await call(captured, "history_list", { query: "absent" }, ctx);
|
|
418
484
|
assert.deepEqual(page(absent).items, []);
|
|
419
485
|
assert.equal(rendered(absent), "no events match this selection", "an empty page says so instead of rendering nothing");
|
|
420
|
-
assert.deepEqual(resultError(await call(captured, "
|
|
486
|
+
assert.deepEqual(resultError(await call(captured, "history_list", { query: "" }, ctx)).code, "invalid_query");
|
|
421
487
|
});
|
|
422
|
-
test("
|
|
488
|
+
test("page_older and page_newer round-trip a session with no duplicates and no gaps", async () => {
|
|
423
489
|
const session = manager();
|
|
424
490
|
const captured = makeExtension(session);
|
|
425
491
|
const ctx = context(session);
|
|
426
492
|
for (let seq = 1; seq <= 10; seq++)
|
|
427
493
|
appendText(session, "user", `needle ${seq}`);
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
assert.
|
|
431
|
-
assert.equal(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
494
|
+
const forward = [];
|
|
495
|
+
let current = page(await call(captured, "history_list", { query: "needle", from: "oldest", limit: 3 }, ctx));
|
|
496
|
+
assert.deepEqual(current.items.map((item) => item.seq), [1, 2, 3]);
|
|
497
|
+
assert.equal(current.page_older, null, "the first page in `from` oldest has nothing older");
|
|
498
|
+
assert.deepEqual(current.page_newer, { after_seq: 3, from: "oldest" });
|
|
499
|
+
forward.push(...current.items.map((item) => item.seq));
|
|
500
|
+
while (current.page_newer !== null) {
|
|
501
|
+
const cursor = current.page_newer;
|
|
502
|
+
current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
|
|
503
|
+
forward.push(...current.items.map((item) => item.seq));
|
|
504
|
+
}
|
|
505
|
+
assert.deepEqual(forward, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "page_newer visits every event exactly once, in order");
|
|
506
|
+
const backward = [];
|
|
507
|
+
current = page(await call(captured, "history_list", { query: "needle", limit: 3 }, ctx));
|
|
508
|
+
assert.deepEqual(current.items.map((item) => item.seq), [8, 9, 10]);
|
|
509
|
+
assert.deepEqual(current.page_older, { before_seq: 8 });
|
|
510
|
+
backward.push(...current.items.map((item) => item.seq));
|
|
511
|
+
while (current.page_older !== null) {
|
|
512
|
+
const cursor = current.page_older;
|
|
513
|
+
current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
|
|
514
|
+
backward.push(...current.items.map((item) => item.seq));
|
|
515
|
+
}
|
|
516
|
+
assert.deepEqual(backward, [8, 9, 10, 5, 6, 7, 2, 3, 4, 1], "page_older walks back with no duplicates and no gaps");
|
|
517
|
+
assert.equal(current.page_older, null);
|
|
437
518
|
});
|
|
438
|
-
test("
|
|
519
|
+
test("query previews start at case-insensitive literal matches and offsets read the same Unicode document", async () => {
|
|
439
520
|
const session = manager();
|
|
440
521
|
const captured = makeExtension(session);
|
|
441
522
|
const ctx = context(session);
|
|
442
523
|
const prefix = "šÄ°".repeat(1000);
|
|
443
524
|
appendText(session, "user", prefix + "NeEdLe.* trailing");
|
|
444
|
-
const found = page(await call(captured, "
|
|
525
|
+
const found = page(await call(captured, "history_list", { query: ["absent", "needle.*"], max_chars_per_item: 8 }, ctx));
|
|
445
526
|
assert.equal(found.items.length, 1);
|
|
446
527
|
const hit = found.items[0];
|
|
447
528
|
assert.equal(hit.offset_chars, 2000);
|
|
448
529
|
assert.equal("match_offset_chars" in hit, false);
|
|
449
530
|
assert.equal(hit.content, "NeEdLe.*");
|
|
450
531
|
assert.equal(hit.truncated, true);
|
|
451
|
-
|
|
452
|
-
const read = resultRead(await call(captured, "history_read", { seq: hit.seq, offset_chars: hit.offset_chars, limit_chars: 8 }, ctx));
|
|
532
|
+
const read = resultRead(await call(captured, "history_read", { seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 8 }, ctx));
|
|
453
533
|
assert.equal(read.content, hit.content);
|
|
454
534
|
const listed = page(await call(captured, "history_list", { max_chars_per_item: 8 }, ctx));
|
|
455
535
|
assert.equal(listed.items.length, 1);
|
|
456
536
|
assert.equal("offset_chars" in listed.items[0], false, "a list preview reports no match offset");
|
|
457
|
-
const atStart = page(await call(captured, "
|
|
537
|
+
const atStart = page(await call(captured, "history_list", { query: "š", max_chars_per_item: 4 }, ctx));
|
|
458
538
|
const zero = atStart.items[0];
|
|
459
539
|
assert.equal(zero.offset_chars, 0, "a match at the document start reports an explicit zero offset");
|
|
460
540
|
assert.equal(zero.content, "šÄ°šÄ°", "an explicit zero offset still previews from the document start");
|
|
461
541
|
assert.equal(zero.truncated, true);
|
|
462
|
-
assert.
|
|
463
|
-
assert.deepEqual(page(await call(captured, "history_search", { query: "needle.+" }, ctx)).items, []);
|
|
542
|
+
assert.deepEqual(page(await call(captured, "history_list", { query: "needle.+" }, ctx)).items, []);
|
|
464
543
|
});
|
|
465
544
|
test("history_read paginates one document with an accurate limit and a bounded byte cap", async () => {
|
|
466
545
|
const session = manager();
|
|
@@ -471,7 +550,7 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
471
550
|
const seq = seqs(await call(captured, "history_list", { max_chars_per_item: 1 }, ctx))[0];
|
|
472
551
|
// 50k requested chars of 64 KiB of text exceeds the byte cap, so the delivered slice stops short
|
|
473
552
|
// of the request rather than at it.
|
|
474
|
-
const full = await call(captured, "history_read", { seq,
|
|
553
|
+
const full = await call(captured, "history_read", { seq, max_chars: 50_000 }, ctx);
|
|
475
554
|
assertWithinBudget(full, "history_read page");
|
|
476
555
|
const read = resultRead(full);
|
|
477
556
|
assert.equal(read.seq, seq);
|
|
@@ -481,23 +560,21 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
481
560
|
assert.equal(read.next_offset_chars !== null, true);
|
|
482
561
|
const text = full.content[0];
|
|
483
562
|
assert.equal(text.type === "text" && text.text.includes("READ WINDOW"), false, "no READ WINDOW block survives");
|
|
484
|
-
assert.match(text.type === "text" ? text.text : "", /\
|
|
485
|
-
const next = resultRead(await call(captured, "history_read", { seq, offset_chars: read.next_offset_chars,
|
|
563
|
+
assert.match(text.type === "text" ? text.text : "", /\[truncated; continue at offset_chars=\d+\]$/, "a byte-capped window states where to continue");
|
|
564
|
+
const next = resultRead(await call(captured, "history_read", { seq, offset_chars: read.next_offset_chars, max_chars: 50_000 }, ctx));
|
|
486
565
|
assert.equal(read.content + next.content, content.slice(0, read.content.length + next.content.length));
|
|
487
|
-
assert.equal(read.
|
|
488
|
-
const limited = resultRead(await call(captured, "history_read", { seq,
|
|
489
|
-
assert.equal(limited.limited_by, "limit", "a window inside the budget stops at the requested count");
|
|
566
|
+
assert.equal(Array.from(read.content).length, read.next_offset_chars, "the cursor addresses the first undelivered character");
|
|
567
|
+
const limited = resultRead(await call(captured, "history_read", { seq, max_chars: 10 }, ctx));
|
|
490
568
|
assert.equal(limited.content, "z".repeat(10));
|
|
491
|
-
const limitedText = (await call(captured, "history_read", { seq,
|
|
492
|
-
const limitedSuffix =
|
|
493
|
-
assert.equal(limitedText.type === "text" && limitedText.text.endsWith(limitedSuffix), true, "a count-limited window states
|
|
569
|
+
const limitedText = (await call(captured, "history_read", { seq, max_chars: 10 }, ctx)).content[0];
|
|
570
|
+
const limitedSuffix = "\n\n[truncated; continue at offset_chars=10]";
|
|
571
|
+
assert.equal(limitedText.type === "text" && limitedText.text.endsWith(limitedSuffix), true, "a count-limited window states where to resume");
|
|
494
572
|
const tail = resultRead(await call(captured, "history_read", { seq, offset_chars: -10 }, ctx));
|
|
495
|
-
assert.equal(tail.offset_chars, content.length - 10);
|
|
496
573
|
assert.equal(tail.content, "z".repeat(10));
|
|
497
574
|
assert.equal(tail.next_offset_chars, null, "the true end has no continuation");
|
|
498
575
|
const past = resultError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
|
|
499
576
|
assert.equal(past.code, "invalid_offset");
|
|
500
|
-
assert.
|
|
577
|
+
assert.match(past.message, new RegExp(`${content.length} chars`), "the refusal names the real length");
|
|
501
578
|
});
|
|
502
579
|
test("history windows expose stable ranges and session identity", async () => {
|
|
503
580
|
const session = manager();
|
|
@@ -507,7 +584,7 @@ test("history windows expose stable ranges and session identity", async () => {
|
|
|
507
584
|
const windows = resultData(await call(captured, "history_windows", {}, ctx));
|
|
508
585
|
assert.equal(windows.session_id, session.getSessionId());
|
|
509
586
|
assert.equal(windows.windows.length, 1);
|
|
510
|
-
assert.deepEqual(windows.windows[0], { window_id: windows.windows[0].window_id, created_at: null, first_seq: 1, last_seq: 1
|
|
587
|
+
assert.deepEqual(windows.windows[0], { window_id: windows.windows[0].window_id, created_at: null, first_seq: 1, last_seq: 1 });
|
|
511
588
|
});
|
|
512
589
|
test("historyDocument is one deterministic projection of the facts, with no UI header or continuation suffix", async () => {
|
|
513
590
|
const windowId = "w1";
|
|
@@ -526,10 +603,10 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
|
|
|
526
603
|
assert.equal(historyDocument(tool).includes("READ WINDOW"), false);
|
|
527
604
|
assert.equal(historyDocument(tool).includes("offset_chars"), false);
|
|
528
605
|
assert.equal(historyDocument(tool).includes("seq "), false, "the document carries no UI identity block");
|
|
529
|
-
const
|
|
530
|
-
assert.equal(
|
|
531
|
-
if (
|
|
532
|
-
const hit =
|
|
606
|
+
const found = await historyList.execute({ query: "NEEDLE" }, projection);
|
|
607
|
+
assert.equal(found.ok, true);
|
|
608
|
+
if (found.ok) {
|
|
609
|
+
const hit = found.data.items[0];
|
|
533
610
|
assert.equal(hit.seq, 5);
|
|
534
611
|
assert.equal(hit.offset_chars, earliestMatchOffsetChars('read {"path":"one"}\n--- output ---\nš needle', ["NEEDLE"]));
|
|
535
612
|
}
|