@vellumai/assistant 0.11.3-dev.202608181709.1f85a67 → 0.11.3-dev.202608181811.60ef9e5
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/docs/architecture/memory.md +17 -5
- package/openapi.yaml +14 -0
- package/package.json +1 -1
- package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +6 -2
- package/src/__tests__/context-search-memory-v2-source.test.ts +0 -1
- package/src/__tests__/file-ops-service.test.ts +163 -30
- package/src/__tests__/filesystem-tools.test.ts +23 -24
- package/src/__tests__/host-file-read-tool.test.ts +16 -19
- package/src/__tests__/tool-executor.test.ts +5 -1
- package/src/api/events/host-file.ts +2 -2
- package/src/cli/commands/memory/__tests__/memory-v2.test.ts +57 -7
- package/src/cli/commands/memory/index.help.ts +41 -27
- package/src/cli/commands/memory/index.ts +2 -0
- package/src/cli/commands/memory/memory-v2.ts +58 -54
- package/src/cli/commands/memory/memory-validate.ts +18 -0
- package/src/daemon/conversation-runtime-assembly.ts +1 -1
- package/src/persistence/conversation-queries.ts +14 -1
- package/src/plugins/defaults/memory/AGENTS.md +11 -3
- package/src/plugins/defaults/memory/graph-topology/pending-buffer.ts +9 -12
- package/src/plugins/defaults/memory/src/memory-v2-routes.ts +12 -10
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +114 -0
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-prompt-flag-gating-guard.test.ts +8 -0
- package/src/plugins/defaults/memory/substrate/__tests__/edge-index.test.ts +0 -30
- package/src/plugins/defaults/memory/substrate/__tests__/ingest.test.ts +73 -1
- package/src/plugins/defaults/memory/substrate/__tests__/page-index.test.ts +37 -0
- package/src/plugins/defaults/memory/substrate/__tests__/page-links.test.ts +208 -0
- package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +158 -1
- package/src/plugins/defaults/memory/substrate/consolidation-job.ts +68 -6
- package/src/plugins/defaults/memory/substrate/edge-index.ts +0 -31
- package/src/plugins/defaults/memory/substrate/ingest.ts +59 -0
- package/src/plugins/defaults/memory/substrate/page-index.ts +35 -8
- package/src/plugins/defaults/memory/substrate/page-links.ts +133 -0
- package/src/plugins/defaults/memory/substrate/page-store.ts +10 -0
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +124 -34
- package/src/plugins/defaults/memory/v3/card.ts +9 -9
- package/src/plugins/defaults/memory/v3/core-set.test.ts +7 -0
- package/src/plugins/defaults/memory/v3/core-set.ts +5 -1
- package/src/plugins/defaults/memory/v3/edge.ts +13 -57
- package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +133 -0
- package/src/runtime/routes/conversation-list-routes.ts +22 -7
- package/src/subagent/types.ts +7 -7
- package/src/tools/__tests__/tool-input-schemas.test.ts +7 -7
- package/src/tools/filesystem/read.ts +27 -10
- package/src/tools/host-filesystem/read.ts +27 -15
- package/src/tools/shared/filesystem/file-ops-service.ts +63 -35
- package/src/tools/shared/filesystem/legacy-read-args.ts +22 -0
- package/src/tools/shared/filesystem/types.ts +5 -5
|
@@ -99,6 +99,17 @@ graph LR
|
|
|
99
99
|
failure-backoff-respecting);
|
|
100
100
|
- manual "Run now" via `POST /v1/consolidation/run-now`.
|
|
101
101
|
Failed runs enter an exponential backoff (transient vs billing curves).
|
|
102
|
+
- The agent writes pages through the file tools, so nothing validates a
|
|
103
|
+
page at write time. Two corpus-level defects are instead reported by the
|
|
104
|
+
page index and fed back into the next pass's prompt as repair steps:
|
|
105
|
+
pages the index could not parse (`PageIndex.parseFailures`) and
|
|
106
|
+
structural references (`links:`, inline `[[wikilinks]]`, `edges:`) whose
|
|
107
|
+
target page does not exist (`PageIndex.danglingLinks`). The read-side
|
|
108
|
+
graph drops a dangling reference silently, so the job also counts them
|
|
109
|
+
after each run (`danglingLinks` on the outcome, a warn line) without
|
|
110
|
+
withholding the reindex follow-ups: the pages that were written still
|
|
111
|
+
become retrievable. The `memory validate` CLI subcommand reports the same
|
|
112
|
+
list.
|
|
102
113
|
- **Ingestion** (`substrate/ingest.ts`, exposed as `POST /v1/memory/ingest`;
|
|
103
114
|
generated HTTP operation id `memory_ingest_post`, IPC method
|
|
104
115
|
`memory_ingest`) is the second sanctioned writer of
|
|
@@ -110,11 +121,12 @@ graph LR
|
|
|
110
121
|
minute, and its same-minute burst guard falls back to processing the
|
|
111
122
|
whole buffer in a single oversized run. Ingest writes validated pages
|
|
112
123
|
directly instead. Purely mechanical: each page is validated and reported
|
|
113
|
-
individually
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
individually (a `links:`/`[[wikilink]]`/`edges:` target that is neither on
|
|
125
|
+
disk nor in the batch is a per-page warning, not a rejection), writes hold
|
|
126
|
+
the consolidation lock so a batch cannot interleave with a consolidation
|
|
127
|
+
pass, and a batch that wrote at least one page enqueues the same reindex
|
|
128
|
+
follow-ups as consolidation (`memory_v2_reembed`, `memory_v3_maintain`).
|
|
129
|
+
Consolidation remains the only LLM-driven writer.
|
|
118
130
|
|
|
119
131
|
### Ingestion tracks and provenance
|
|
120
132
|
|
package/openapi.yaml
CHANGED
|
@@ -6608,6 +6608,20 @@ paths:
|
|
|
6608
6608
|
predicate behind the unread count and the section index, so a client that keeps no complete conversation
|
|
6609
6609
|
list can ask for exactly the rows its attention surfaces need. Composes with every other filter. Any value
|
|
6610
6610
|
other than "true" is rejected. Omit to span every conversation.'
|
|
6611
|
+
- name: foregroundOnly
|
|
6612
|
+
in: query
|
|
6613
|
+
required: false
|
|
6614
|
+
schema:
|
|
6615
|
+
type: string
|
|
6616
|
+
enum:
|
|
6617
|
+
- "true"
|
|
6618
|
+
description:
|
|
6619
|
+
Pass "true" to return only user-facing foreground conversations, dropping the automated background and
|
|
6620
|
+
scheduled runs the standard listing admits when they are filed in a custom group (a surfaced run stays).
|
|
6621
|
+
This is the same predicate the unread count and the section index apply, so a client can ask for the newest
|
|
6622
|
+
conversation a user can open in one row instead of paging past runs it would skip. Composes with every other
|
|
6623
|
+
filter; a foreground-only first page never has pinned rows appended to it. Any value other than "true" is
|
|
6624
|
+
rejected. Omit to keep every visible row.
|
|
6611
6625
|
responses:
|
|
6612
6626
|
"200":
|
|
6613
6627
|
description: Successful response
|
package/package.json
CHANGED
|
@@ -45,6 +45,10 @@ mock.module("../plugins/defaults/memory/substrate/skill-store.js", () => ({
|
|
|
45
45
|
seedV2SkillEntries: async () => {
|
|
46
46
|
seedCallCount += 1;
|
|
47
47
|
},
|
|
48
|
+
// The validate route builds the page index, which reads the seeded
|
|
49
|
+
// skill catalog; an empty catalog keeps that walk inert here.
|
|
50
|
+
listSkillEntries: () => [],
|
|
51
|
+
SKILL_SLUG_PREFIX: "skills/",
|
|
48
52
|
}));
|
|
49
53
|
|
|
50
54
|
// ---------------------------------------------------------------------------
|
|
@@ -254,7 +258,7 @@ describe("all memory v2 routes — MEMORY_V2_DISABLED gate", () => {
|
|
|
254
258
|
const result = (await route!.handler({ body: {} })) as {
|
|
255
259
|
pageCount: number;
|
|
256
260
|
edgeCount: number;
|
|
257
|
-
|
|
261
|
+
danglingLinks: unknown[];
|
|
258
262
|
oversizedPages: unknown[];
|
|
259
263
|
parseFailures: unknown[];
|
|
260
264
|
};
|
|
@@ -263,7 +267,7 @@ describe("all memory v2 routes — MEMORY_V2_DISABLED gate", () => {
|
|
|
263
267
|
// returned at all (no MEMORY_V2_DISABLED throw).
|
|
264
268
|
expect(result.pageCount).toBe(0);
|
|
265
269
|
expect(result.edgeCount).toBe(0);
|
|
266
|
-
expect(result.
|
|
270
|
+
expect(result.danglingLinks).toEqual([]);
|
|
267
271
|
expect(result.oversizedPages).toEqual([]);
|
|
268
272
|
expect(result.parseFailures).toEqual([]);
|
|
269
273
|
});
|
|
@@ -71,7 +71,6 @@ mock.module("../plugins/defaults/memory/substrate/edge-index.js", () => ({
|
|
|
71
71
|
getEdgeIndex: async (): Promise<EdgeIndex> => edgeIndex,
|
|
72
72
|
invalidateEdgeIndex: () => {},
|
|
73
73
|
getReachable: () => new Set<string>(),
|
|
74
|
-
validateEdgeTargets: () => ({ ok: true, missing: [] }),
|
|
75
74
|
totalEdgeCount: () => 0,
|
|
76
75
|
}));
|
|
77
76
|
|
|
@@ -10,10 +10,11 @@ import { tmpdir } from "node:os";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { afterEach, describe, expect, test } from "bun:test";
|
|
12
12
|
|
|
13
|
+
import { THRESHOLD_CHARS } from "../context/post-turn-tool-result-truncation.js";
|
|
13
14
|
import {
|
|
14
|
-
DEFAULT_READ_LINE_LIMIT,
|
|
15
15
|
FileSystemOps,
|
|
16
16
|
type PathPolicy,
|
|
17
|
+
READ_CHAR_BUDGET,
|
|
17
18
|
} from "../tools/shared/filesystem/file-ops-service.js";
|
|
18
19
|
import { sandboxPolicy } from "../tools/shared/filesystem/path-policy.js";
|
|
19
20
|
|
|
@@ -111,34 +112,28 @@ describe("FileSystemOps.readFileSafe", () => {
|
|
|
111
112
|
expect(result.error.code).toBe("PATH_OUT_OF_BOUNDS");
|
|
112
113
|
});
|
|
113
114
|
|
|
114
|
-
test("respects
|
|
115
|
+
test("respects startIndex and maxChars", async () => {
|
|
115
116
|
const dir = makeTempDir();
|
|
116
117
|
writeFileSync(join(dir, "lines.txt"), "a\nb\nc\nd\ne\n");
|
|
117
118
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
118
119
|
|
|
119
120
|
const result = await ops.readFileSafe({
|
|
120
121
|
path: "lines.txt",
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
startIndex: 2,
|
|
123
|
+
maxChars: 3,
|
|
123
124
|
});
|
|
124
125
|
expect(result.ok).toBe(true);
|
|
125
126
|
if (!result.ok) {
|
|
126
127
|
return;
|
|
127
128
|
}
|
|
128
|
-
// Assert on the numbered lines rather than bare letters: the truncation
|
|
129
|
-
// notice is prose, so a bare `toContain("d")` matches its wording.
|
|
130
129
|
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
131
|
-
expect(body).
|
|
132
|
-
expect(body).toContain(" 3 c");
|
|
133
|
-
expect(body).not.toContain(" 1 a");
|
|
134
|
-
expect(body).not.toContain(" 4 d");
|
|
130
|
+
expect(body).toBe("b\nc");
|
|
135
131
|
});
|
|
136
132
|
|
|
137
|
-
test("caps an unbounded read at the
|
|
133
|
+
test("caps an unbounded read at the character budget and says so", async () => {
|
|
138
134
|
const dir = makeTempDir();
|
|
139
|
-
const total =
|
|
140
|
-
|
|
141
|
-
writeFileSync(join(dir, "big.txt"), lines.join("\n"));
|
|
135
|
+
const total = READ_CHAR_BUDGET + 500;
|
|
136
|
+
writeFileSync(join(dir, "big.txt"), "x".repeat(total));
|
|
142
137
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
143
138
|
|
|
144
139
|
const result = await ops.readFileSafe({ path: "big.txt" });
|
|
@@ -146,36 +141,74 @@ describe("FileSystemOps.readFileSafe", () => {
|
|
|
146
141
|
if (!result.ok) {
|
|
147
142
|
return;
|
|
148
143
|
}
|
|
149
|
-
const
|
|
150
|
-
expect(
|
|
151
|
-
expect(content).
|
|
152
|
-
|
|
153
|
-
`[Truncated: showing through line ${DEFAULT_READ_LINE_LIMIT} of ${total}. Read on with offset=${DEFAULT_READ_LINE_LIMIT + 1}`,
|
|
144
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
145
|
+
expect(body).toHaveLength(READ_CHAR_BUDGET);
|
|
146
|
+
expect(result.value.content).toContain(
|
|
147
|
+
`[Truncated: characters 0-${READ_CHAR_BUDGET} of ${total}. Read on with start_index=${READ_CHAR_BUDGET}.]`,
|
|
154
148
|
);
|
|
155
149
|
});
|
|
156
150
|
|
|
157
|
-
test("
|
|
151
|
+
test("a maxChars above the budget is clamped to it", async () => {
|
|
158
152
|
const dir = makeTempDir();
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
(_, i) => `line${i + 1}`,
|
|
162
|
-
);
|
|
163
|
-
writeFileSync(join(dir, "big.txt"), lines.join("\n"));
|
|
153
|
+
const total = READ_CHAR_BUDGET + 500;
|
|
154
|
+
writeFileSync(join(dir, "big.txt"), "x".repeat(total));
|
|
164
155
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
165
156
|
|
|
166
157
|
const result = await ops.readFileSafe({
|
|
167
158
|
path: "big.txt",
|
|
168
|
-
|
|
159
|
+
maxChars: total,
|
|
169
160
|
});
|
|
170
161
|
expect(result.ok).toBe(true);
|
|
171
162
|
if (!result.ok) {
|
|
172
163
|
return;
|
|
173
164
|
}
|
|
174
|
-
|
|
175
|
-
expect(
|
|
165
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
166
|
+
expect(body).toHaveLength(READ_CHAR_BUDGET);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("a maxChars below the budget is honored as given", async () => {
|
|
170
|
+
const dir = makeTempDir();
|
|
171
|
+
writeFileSync(join(dir, "big.txt"), "x".repeat(500));
|
|
172
|
+
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
173
|
+
|
|
174
|
+
const result = await ops.readFileSafe({ path: "big.txt", maxChars: 10 });
|
|
175
|
+
expect(result.ok).toBe(true);
|
|
176
|
+
if (!result.ok) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
180
|
+
expect(body).toHaveLength(10);
|
|
181
|
+
expect(result.value.content).toContain(
|
|
182
|
+
"[Truncated: characters 0-10 of 500. Read on with start_index=10.]",
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("paging with the offset from a notice returns the next window", async () => {
|
|
187
|
+
const dir = makeTempDir();
|
|
188
|
+
writeFileSync(join(dir, "big.txt"), "abcdefghij");
|
|
189
|
+
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
190
|
+
|
|
191
|
+
const first = await ops.readFileSafe({ path: "big.txt", maxChars: 4 });
|
|
192
|
+
expect(first.ok).toBe(true);
|
|
193
|
+
if (!first.ok) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
expect(first.value.content).toContain("start_index=4");
|
|
197
|
+
|
|
198
|
+
const second = await ops.readFileSafe({
|
|
199
|
+
path: "big.txt",
|
|
200
|
+
startIndex: 4,
|
|
201
|
+
maxChars: 4,
|
|
202
|
+
});
|
|
203
|
+
expect(second.ok).toBe(true);
|
|
204
|
+
if (!second.ok) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const [body] = second.value.content.split("\n\n[Truncated:");
|
|
208
|
+
expect(body).toBe("efgh");
|
|
176
209
|
});
|
|
177
210
|
|
|
178
|
-
test("a read that reaches the
|
|
211
|
+
test("a read that reaches the end carries no truncation notice", async () => {
|
|
179
212
|
const dir = makeTempDir();
|
|
180
213
|
writeFileSync(join(dir, "small.txt"), "a\nb\nc");
|
|
181
214
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
@@ -193,13 +226,113 @@ describe("FileSystemOps.readFileSafe", () => {
|
|
|
193
226
|
writeFileSync(join(dir, "small.txt"), "a\nb\nc");
|
|
194
227
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
195
228
|
|
|
196
|
-
const result = await ops.readFileSafe({
|
|
229
|
+
const result = await ops.readFileSafe({
|
|
230
|
+
path: "small.txt",
|
|
231
|
+
startIndex: 100,
|
|
232
|
+
});
|
|
197
233
|
expect(result.ok).toBe(true);
|
|
198
234
|
if (!result.ok) {
|
|
199
235
|
return;
|
|
200
236
|
}
|
|
201
237
|
expect(result.value.content).not.toContain("[Truncated:");
|
|
202
238
|
});
|
|
239
|
+
|
|
240
|
+
test("a window boundary inside a surrogate pair does not corrupt it", async () => {
|
|
241
|
+
const dir = makeTempDir();
|
|
242
|
+
// "ab" + a 2-unit emoji + "cd": a maxChars of 3 would split the pair.
|
|
243
|
+
writeFileSync(join(dir, "emoji.txt"), `ab\u{1F600}cd`);
|
|
244
|
+
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
245
|
+
|
|
246
|
+
const result = await ops.readFileSafe({ path: "emoji.txt", maxChars: 3 });
|
|
247
|
+
expect(result.ok).toBe(true);
|
|
248
|
+
if (!result.ok) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
252
|
+
expect(body).toBe("ab");
|
|
253
|
+
expect(body).not.toContain("\uFFFD");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("paging across a surrogate pair reassembles the whole file", async () => {
|
|
257
|
+
const dir = makeTempDir();
|
|
258
|
+
const original = `ab\u{1F600}cd`;
|
|
259
|
+
writeFileSync(join(dir, "emoji.txt"), original);
|
|
260
|
+
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
261
|
+
|
|
262
|
+
let assembled = "";
|
|
263
|
+
let startIndex = 0;
|
|
264
|
+
for (let i = 0; i < 10; i++) {
|
|
265
|
+
const result = await ops.readFileSafe({
|
|
266
|
+
path: "emoji.txt",
|
|
267
|
+
startIndex,
|
|
268
|
+
maxChars: 3,
|
|
269
|
+
});
|
|
270
|
+
expect(result.ok).toBe(true);
|
|
271
|
+
if (!result.ok) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
275
|
+
assembled += body;
|
|
276
|
+
const match = /start_index=(\d+)/.exec(result.value.content);
|
|
277
|
+
if (match?.[1] === undefined) {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
startIndex = Number(match[1]);
|
|
281
|
+
}
|
|
282
|
+
expect(assembled).toBe(original);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("a lone-low-surrogate startIndex backs up onto the whole pair", async () => {
|
|
286
|
+
const dir = makeTempDir();
|
|
287
|
+
writeFileSync(join(dir, "emoji.txt"), `ab\u{1F600}cd`);
|
|
288
|
+
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
289
|
+
|
|
290
|
+
// Index 3 (0-indexed) is the low half of the emoji.
|
|
291
|
+
const result = await ops.readFileSafe({
|
|
292
|
+
path: "emoji.txt",
|
|
293
|
+
startIndex: 3,
|
|
294
|
+
maxChars: 2,
|
|
295
|
+
});
|
|
296
|
+
expect(result.ok).toBe(true);
|
|
297
|
+
if (!result.ok) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
301
|
+
expect(body).toBe(`\u{1F600}`);
|
|
302
|
+
expect(body).not.toContain("\uFFFD");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test("legacy offset/limit are rejected rather than silently ignored", async () => {
|
|
306
|
+
const { fileReadTool } = await import("../tools/filesystem/read.js");
|
|
307
|
+
const dir = makeTempDir();
|
|
308
|
+
writeFileSync(join(dir, "big.txt"), "x".repeat(500));
|
|
309
|
+
|
|
310
|
+
const result = await fileReadTool.execute(
|
|
311
|
+
{ path: join(dir, "big.txt"), offset: 2001, limit: 2000 },
|
|
312
|
+
{ workingDir: dir } as never,
|
|
313
|
+
);
|
|
314
|
+
expect(result.isError).toBe(true);
|
|
315
|
+
expect(result.content).toContain("no longer takes");
|
|
316
|
+
expect(result.content).toContain("start_index");
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test("legacy fields alongside current ones do not trigger the guard", async () => {
|
|
320
|
+
const { fileReadTool } = await import("../tools/filesystem/read.js");
|
|
321
|
+
const dir = makeTempDir();
|
|
322
|
+
writeFileSync(join(dir, "big.txt"), "abcdefghij");
|
|
323
|
+
|
|
324
|
+
const result = await fileReadTool.execute(
|
|
325
|
+
{ path: join(dir, "big.txt"), offset: 1, max_chars: 4 },
|
|
326
|
+
{ workingDir: dir } as never,
|
|
327
|
+
);
|
|
328
|
+
expect(result.isError).toBe(false);
|
|
329
|
+
const [body] = result.content.split("\n\n[Truncated:");
|
|
330
|
+
expect(body).toBe("abcd");
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test("the read budget stays under the tool-result spool threshold", () => {
|
|
334
|
+
expect(READ_CHAR_BUDGET).toBeLessThan(THRESHOLD_CHARS);
|
|
335
|
+
});
|
|
203
336
|
});
|
|
204
337
|
|
|
205
338
|
// ---------------------------------------------------------------------------
|
|
@@ -125,16 +125,19 @@ describe("FileSystemOps symlink handling", () => {
|
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
// ===========================================================================
|
|
128
|
-
// FileSystemOps: read
|
|
128
|
+
// FileSystemOps: read character-window edge cases
|
|
129
129
|
// ===========================================================================
|
|
130
130
|
|
|
131
|
-
describe("FileSystemOps read
|
|
132
|
-
test("
|
|
131
|
+
describe("FileSystemOps read character-window edge cases", () => {
|
|
132
|
+
test("startIndex beyond file length returns empty content", async () => {
|
|
133
133
|
const dir = makeTempDir();
|
|
134
134
|
writeFileSync(join(dir, "short.txt"), "a\nb\nc");
|
|
135
135
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
136
136
|
|
|
137
|
-
const result = await ops.readFileSafe({
|
|
137
|
+
const result = await ops.readFileSafe({
|
|
138
|
+
path: "short.txt",
|
|
139
|
+
startIndex: 100,
|
|
140
|
+
});
|
|
138
141
|
expect(result.ok).toBe(true);
|
|
139
142
|
if (!result.ok) {
|
|
140
143
|
return;
|
|
@@ -142,12 +145,12 @@ describe("FileSystemOps read offset/limit edge cases", () => {
|
|
|
142
145
|
expect(result.value.content).toBe("");
|
|
143
146
|
});
|
|
144
147
|
|
|
145
|
-
test("
|
|
148
|
+
test("maxChars of zero returns empty content", async () => {
|
|
146
149
|
const dir = makeTempDir();
|
|
147
150
|
writeFileSync(join(dir, "file.txt"), "a\nb\nc");
|
|
148
151
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
149
152
|
|
|
150
|
-
const result = await ops.readFileSafe({ path: "file.txt",
|
|
153
|
+
const result = await ops.readFileSafe({ path: "file.txt", maxChars: 0 });
|
|
151
154
|
expect(result.ok).toBe(true);
|
|
152
155
|
if (!result.ok) {
|
|
153
156
|
return;
|
|
@@ -155,61 +158,57 @@ describe("FileSystemOps read offset/limit edge cases", () => {
|
|
|
155
158
|
expect(result.value.content).toBe("");
|
|
156
159
|
});
|
|
157
160
|
|
|
158
|
-
test("
|
|
161
|
+
test("startIndex=0 reads from the first character (0-indexed)", async () => {
|
|
159
162
|
const dir = makeTempDir();
|
|
160
163
|
writeFileSync(join(dir, "file.txt"), "first\nsecond\nthird");
|
|
161
164
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
162
165
|
|
|
163
166
|
const result = await ops.readFileSafe({
|
|
164
167
|
path: "file.txt",
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
startIndex: 0,
|
|
169
|
+
maxChars: 5,
|
|
167
170
|
});
|
|
168
171
|
expect(result.ok).toBe(true);
|
|
169
172
|
if (!result.ok) {
|
|
170
173
|
return;
|
|
171
174
|
}
|
|
172
|
-
|
|
173
|
-
expect(
|
|
175
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
176
|
+
expect(body).toBe("first");
|
|
174
177
|
});
|
|
175
178
|
|
|
176
|
-
test("
|
|
179
|
+
test("maxChars exceeding file length returns the rest of the file", async () => {
|
|
177
180
|
const dir = makeTempDir();
|
|
178
181
|
writeFileSync(join(dir, "file.txt"), "a\nb");
|
|
179
182
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
180
183
|
|
|
181
184
|
const result = await ops.readFileSafe({
|
|
182
185
|
path: "file.txt",
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
startIndex: 0,
|
|
187
|
+
maxChars: 1000,
|
|
185
188
|
});
|
|
186
189
|
expect(result.ok).toBe(true);
|
|
187
190
|
if (!result.ok) {
|
|
188
191
|
return;
|
|
189
192
|
}
|
|
190
|
-
expect(result.value.content).
|
|
191
|
-
expect(result.value.content).toContain("b");
|
|
193
|
+
expect(result.value.content).toBe("a\nb");
|
|
192
194
|
});
|
|
193
195
|
|
|
194
|
-
test("
|
|
196
|
+
test("the window starts at startIndex and carries no line numbers", async () => {
|
|
195
197
|
const dir = makeTempDir();
|
|
196
198
|
writeFileSync(join(dir, "file.txt"), "a\nb\nc\nd\ne");
|
|
197
199
|
const ops = new FileSystemOps(sandboxPolicyFor(dir));
|
|
198
200
|
|
|
199
201
|
const result = await ops.readFileSafe({
|
|
200
202
|
path: "file.txt",
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
startIndex: 4,
|
|
204
|
+
maxChars: 3,
|
|
203
205
|
});
|
|
204
206
|
expect(result.ok).toBe(true);
|
|
205
207
|
if (!result.ok) {
|
|
206
208
|
return;
|
|
207
209
|
}
|
|
208
|
-
|
|
209
|
-
expect(
|
|
210
|
-
expect(result.value.content).toContain("4");
|
|
211
|
-
expect(result.value.content).toContain("c");
|
|
212
|
-
expect(result.value.content).toContain("d");
|
|
210
|
+
const [body] = result.value.content.split("\n\n[Truncated:");
|
|
211
|
+
expect(body).toBe("c\nd");
|
|
213
212
|
});
|
|
214
213
|
});
|
|
215
214
|
|
|
@@ -27,7 +27,7 @@ mock.module("../daemon/host-file-proxy.js", () => ({
|
|
|
27
27
|
}));
|
|
28
28
|
|
|
29
29
|
import { hostFileReadTool } from "../tools/host-filesystem/read.js";
|
|
30
|
-
import {
|
|
30
|
+
import { READ_CHAR_BUDGET } from "../tools/shared/filesystem/file-ops-service.js";
|
|
31
31
|
import type { ToolContext } from "../tools/types.js";
|
|
32
32
|
|
|
33
33
|
const testDirs: string[] = [];
|
|
@@ -77,19 +77,19 @@ describe("host_file_read tool", () => {
|
|
|
77
77
|
expect(result.content).toContain("must be absolute");
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
test("reads
|
|
80
|
+
test("reads a character window", async () => {
|
|
81
81
|
const dir = mkdtempSync(join(tmpdir(), "host-file-read-test-"));
|
|
82
82
|
testDirs.push(dir);
|
|
83
83
|
const filePath = join(dir, "sample.txt");
|
|
84
84
|
writeFileSync(filePath, "first\nsecond\nthird\n");
|
|
85
85
|
|
|
86
86
|
const result = await hostFileReadTool.execute(
|
|
87
|
-
{ path: filePath,
|
|
87
|
+
{ path: filePath, start_index: 6, max_chars: 6 },
|
|
88
88
|
makeContext(),
|
|
89
89
|
);
|
|
90
90
|
expect(result.isError).toBe(false);
|
|
91
|
-
expect(result.content).toContain("
|
|
92
|
-
expect(result.content).toContain("
|
|
91
|
+
expect(result.content).toContain("second");
|
|
92
|
+
expect(result.content).not.toContain("first");
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
test("returns error when file does not exist", async () => {
|
|
@@ -128,7 +128,7 @@ describe("host_file_read tool", () => {
|
|
|
128
128
|
expect(result.content).toContain('Invalid input for tool "host_file_read"');
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
test("reads
|
|
131
|
+
test("reads the whole file when no window is specified", async () => {
|
|
132
132
|
const dir = mkdtempSync(join(tmpdir(), "host-file-read-test-"));
|
|
133
133
|
testDirs.push(dir);
|
|
134
134
|
const filePath = join(dir, "full.txt");
|
|
@@ -139,9 +139,7 @@ describe("host_file_read tool", () => {
|
|
|
139
139
|
makeContext(),
|
|
140
140
|
);
|
|
141
141
|
expect(result.isError).toBe(false);
|
|
142
|
-
expect(result.content).
|
|
143
|
-
expect(result.content).toContain("2 line2");
|
|
144
|
-
expect(result.content).toContain("3 line3");
|
|
142
|
+
expect(result.content).toBe("line1\nline2\nline3\n");
|
|
145
143
|
});
|
|
146
144
|
|
|
147
145
|
test("handles empty file", async () => {
|
|
@@ -157,20 +155,19 @@ describe("host_file_read tool", () => {
|
|
|
157
155
|
expect(result.isError).toBe(false);
|
|
158
156
|
});
|
|
159
157
|
|
|
160
|
-
test("
|
|
158
|
+
test("start_index is 0-indexed", async () => {
|
|
161
159
|
const dir = mkdtempSync(join(tmpdir(), "host-file-read-test-"));
|
|
162
160
|
testDirs.push(dir);
|
|
163
161
|
const filePath = join(dir, "lines.txt");
|
|
164
162
|
writeFileSync(filePath, "a\nb\nc\nd\ne\n");
|
|
165
163
|
|
|
166
164
|
const result = await hostFileReadTool.execute(
|
|
167
|
-
{ path: filePath,
|
|
165
|
+
{ path: filePath, start_index: 4, max_chars: 1 },
|
|
168
166
|
makeContext(),
|
|
169
167
|
);
|
|
170
168
|
expect(result.isError).toBe(false);
|
|
171
|
-
|
|
172
|
-
expect(
|
|
173
|
-
expect(result.content).not.toContain("4 d");
|
|
169
|
+
const [body] = result.content.split("\n\n[Truncated:");
|
|
170
|
+
expect(body).toBe("c");
|
|
174
171
|
});
|
|
175
172
|
|
|
176
173
|
test("reads a file with symlinks resolved", async () => {
|
|
@@ -228,15 +225,15 @@ describe("host_file_read image support", () => {
|
|
|
228
225
|
expect(result.isError).toBe(false);
|
|
229
226
|
expect(result.contentBlocks).toHaveLength(1);
|
|
230
227
|
// The proxied request carries the resolved default window, so a host read
|
|
231
|
-
// is bounded by the same
|
|
228
|
+
// is bounded by the same budget as a local one rather than streaming a
|
|
232
229
|
// whole file across the bridge.
|
|
233
230
|
expect(requests).toEqual([
|
|
234
231
|
{
|
|
235
232
|
input: {
|
|
236
233
|
operation: "read",
|
|
237
234
|
path: "/host/screenshot.png",
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
startIndex: undefined,
|
|
236
|
+
maxChars: READ_CHAR_BUDGET,
|
|
240
237
|
},
|
|
241
238
|
conversationId: "test-conversation",
|
|
242
239
|
signal: undefined,
|
|
@@ -306,8 +303,8 @@ describe("host_file_read image support", () => {
|
|
|
306
303
|
);
|
|
307
304
|
|
|
308
305
|
expect(result.isError).toBe(false);
|
|
309
|
-
expect(result.content).toContain("
|
|
310
|
-
expect(result.content).toContain("
|
|
306
|
+
expect(result.content).toContain("hello world");
|
|
307
|
+
expect(result.content).toContain("second line");
|
|
311
308
|
expect((result as any).contentBlocks).toBeUndefined();
|
|
312
309
|
});
|
|
313
310
|
|
|
@@ -1457,7 +1457,11 @@ describe("ToolExecutor input-schema validation gate", () => {
|
|
|
1457
1457
|
const executor = new ToolExecutor(makePrompter());
|
|
1458
1458
|
const result = await executor.execute(
|
|
1459
1459
|
"file_read",
|
|
1460
|
-
{
|
|
1460
|
+
{
|
|
1461
|
+
path: "a.txt",
|
|
1462
|
+
start_index: "not-a-number",
|
|
1463
|
+
activity: "Reading a file",
|
|
1464
|
+
},
|
|
1461
1465
|
makeContext(),
|
|
1462
1466
|
);
|
|
1463
1467
|
|
|
@@ -21,8 +21,8 @@ const HostFileReadRequestSchema = z.object({
|
|
|
21
21
|
targetClientId: z.string().optional(),
|
|
22
22
|
operation: z.literal("read"),
|
|
23
23
|
path: z.string(),
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
startIndex: z.number().optional(),
|
|
25
|
+
maxChars: z.number().optional(),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
const HostFileWriteRequestSchema = z.object({
|