@vellumai/assistant 0.11.4-staging.3 → 0.11.4-staging.4
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/guardian-request-flow.md +35 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/remote-web-pairing.ts +60 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/remote-web-pairing.ts +60 -0
- package/node_modules/@vellumai/service-contracts/src/remote-web-pairing.ts +60 -0
- package/package.json +1 -1
- package/src/__tests__/conversation-load-history-repair.test.ts +209 -0
- package/src/__tests__/conversation-runtime-assembly.test.ts +53 -0
- 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/daemon/conversation-runtime-assembly.ts +9 -2
- package/src/daemon/conversation.ts +23 -7
- package/src/notifications/AGENTS.md +2 -0
- package/src/notifications/approval-card-data.ts +33 -0
- 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
|
@@ -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({
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
type RenderedSlackTranscriptMessage,
|
|
45
45
|
renderSlackTranscriptWithProvenance,
|
|
46
46
|
} from "../messaging/providers/slack/render-transcript.js";
|
|
47
|
+
import { isGuardianCardRow } from "../notifications/approval-card-data.js";
|
|
47
48
|
import {
|
|
48
49
|
getMessages as defaultGetMessages,
|
|
49
50
|
type MessageRow,
|
|
@@ -520,7 +521,7 @@ function injectActiveSurfaceContext(
|
|
|
520
521
|
"RULES FOR WORKSPACE MODIFICATION:",
|
|
521
522
|
`1. Use \`file_edit\` to make surgical changes to app files. The file path is \`${getAppDirPath(ctx.appId)}/<path>\`.`,
|
|
522
523
|
"2. Use `file_write` to create new files or rewrite files.",
|
|
523
|
-
"3. Use `file_read` to read any file
|
|
524
|
+
"3. Use `file_read` to read any file before editing, and `code_search` when you need a line reference.",
|
|
524
525
|
"4. Use `bash ls` to see all files in the app directory.",
|
|
525
526
|
`5. Call \`app_refresh\` with app_id "${ctx.appId}" ONCE after all changes are complete.`,
|
|
526
527
|
"6. NEVER respond with only text — the user expects a visual update.",
|
|
@@ -1513,10 +1514,16 @@ export function loadSlackChronologicalContext(
|
|
|
1513
1514
|
allRows,
|
|
1514
1515
|
options.trustClass,
|
|
1515
1516
|
);
|
|
1517
|
+
// Applied after the compaction boundary, never before it: that filter
|
|
1518
|
+
// indexes into the row list when no watermark is set, so dropping rows
|
|
1519
|
+
// earlier would shift what it cuts. Same rule and same ordering constraint
|
|
1520
|
+
// as `Conversation.loadFromDb` -- Slack builds the provider history from
|
|
1521
|
+
// rows rather than `this.messages`, so a rule applied only there would
|
|
1522
|
+
// exempt this channel entirely.
|
|
1516
1523
|
const rows = filterRowsAfterSlackCompactionBoundary(
|
|
1517
1524
|
messageRowsToSlackTranscriptRows(scopedRows),
|
|
1518
1525
|
options,
|
|
1519
|
-
);
|
|
1526
|
+
).filter((row) => !isGuardianCardRow(row.content));
|
|
1520
1527
|
return assembleSlackChronologicalContext(rows, capabilities, {
|
|
1521
1528
|
contextSummary: resolveCapabilities(options.trustClass).canAccessMemory
|
|
1522
1529
|
? options.contextSummary
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
derefToolResultReReads,
|
|
42
42
|
postTurnTruncateToolResults,
|
|
43
43
|
} from "../context/post-turn-tool-result-truncation.js";
|
|
44
|
+
import { isGuardianCardRow } from "../notifications/approval-card-data.js";
|
|
44
45
|
import { PermissionPrompter } from "../permissions/prompter.js";
|
|
45
46
|
import { SecretPrompter } from "../permissions/secret-prompter.js";
|
|
46
47
|
import type { UserDecision } from "../permissions/types.js";
|
|
@@ -1341,6 +1342,16 @@ export class Conversation {
|
|
|
1341
1342
|
parsedMessages.length,
|
|
1342
1343
|
);
|
|
1343
1344
|
for (const [index, message] of parsedMessages.entries()) {
|
|
1345
|
+
// Applied after the compaction slice, never before it: the slice and
|
|
1346
|
+
// `rowToHistoryIndex` are both computed against the full row list, so
|
|
1347
|
+
// dropping earlier would shift them. A dropped row maps to a null
|
|
1348
|
+
// history index exactly like a fully-injected user row that strips to
|
|
1349
|
+
// nothing. `index` is shared with `slicedDbMessages`, which
|
|
1350
|
+
// `parsedMessages` maps 1:1.
|
|
1351
|
+
if (isGuardianCardRow(slicedDbMessages[index]?.content)) {
|
|
1352
|
+
preRepairIndexBySlicedRow[index] = null;
|
|
1353
|
+
continue;
|
|
1354
|
+
}
|
|
1344
1355
|
const stripped =
|
|
1345
1356
|
index < preStrippedCount
|
|
1346
1357
|
? stripInjectionsForCompaction([message])
|
|
@@ -1443,7 +1454,7 @@ export class Conversation {
|
|
|
1443
1454
|
messageCount: this.messages.length,
|
|
1444
1455
|
});
|
|
1445
1456
|
|
|
1446
|
-
this.restoreSurfaceStateFromHistory();
|
|
1457
|
+
this.restoreSurfaceStateFromHistory(parsedMessages);
|
|
1447
1458
|
this.graphMemory.restoreState();
|
|
1448
1459
|
|
|
1449
1460
|
// Row→history correspondence for this load: slice offset, then the
|
|
@@ -1475,14 +1486,19 @@ export class Conversation {
|
|
|
1475
1486
|
* populate surfaceState so that findConversationBySurfaceId works for
|
|
1476
1487
|
* surfaces restored from history (e.g. after daemon restart).
|
|
1477
1488
|
*
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1489
|
+
* Scans the live (non-compacted) window only, never all DB rows, because
|
|
1490
|
+
* surface IDs are not globally unique and restoring stale compacted
|
|
1491
|
+
* surfaces would let findConversationBySurfaceId route actions to the wrong
|
|
1492
|
+
* conversation.
|
|
1493
|
+
*
|
|
1494
|
+
* Takes that window as rows rather than reading `this.messages`, because a
|
|
1495
|
+
* surface's lifecycle and the model's context are different questions. A
|
|
1496
|
+
* guardian card is absent from `this.messages`, but it is exactly the card
|
|
1497
|
+
* whose Approve/Reject buttons must still route after a restart.
|
|
1482
1498
|
*/
|
|
1483
|
-
private restoreSurfaceStateFromHistory(): void {
|
|
1499
|
+
private restoreSurfaceStateFromHistory(liveWindow: Message[]): void {
|
|
1484
1500
|
this.surfaceState.clear();
|
|
1485
|
-
for (const msg of
|
|
1501
|
+
for (const msg of liveWindow) {
|
|
1486
1502
|
if (!Array.isArray(msg.content)) {
|
|
1487
1503
|
continue;
|
|
1488
1504
|
}
|
|
@@ -9,3 +9,5 @@ When a notification flow creates a server-side conversation (e.g. guardian quest
|
|
|
9
9
|
Guardian-request producers (access requests, tool approvals, tool-grant escalations, voice questions, trusted-contact confirmations) **MUST** record approval-card deliveries through `recordApprovalCardDelivery` / `recordGuardianRequestDeliveries` in `guardian-delivery-recorder.ts` -- never by calling the gateway client's `createGuardianRequestDelivery` directly. That sink is the single place the card-to-request addressing convention lives (conversation id for the in-app card; chat + channel-native `ts` for channel cards), so the path that writes a delivery row cannot drift from the paths that read it back to withdraw a card or resolve an emoji reaction -- the drift that previously fanned this logic into four divergent copies. (Tests may seed delivery rows directly for fixtures.)
|
|
10
10
|
|
|
11
11
|
Approval-card **source references** (the link back to the channel message that triggered a request) resolve only through `resolveApprovalSourceReference()` in `runtime/approval-source-link.ts` -- producers spread the result into the `guardian.question` context payload and never hand-build links. Channel-format knowledge (id shapes, permalinks, mrkdwn) lives only in `messaging/providers/<channel>/` and `notifications/adapters/<channel>`; the four-layer ownership map is documented at the top of `approval-source-link.ts`. Exception: access-request cards predate the registry and still derive their Slack permalink from payload `messageTs` in `access-request-copy.ts` -- converge them onto the registry rather than adding a third resolution path.
|
|
12
|
+
|
|
13
|
+
Guardian-request card rows are **not conversation history**. `pairDeliveryWithConversation` persists a message row per delivery, and for a guardian card that row is addressed to a conversation the request is _about_ (the vellum card is pinned to the originating conversation; a channel card lands in whatever conversation the guardian's chat binds to). `isGuardianCardRow` in `approval-card-data.ts` is the single definition of which rows those are, derived from the card's own `ui_surface` id rather than a stored marker so old rows need no backfill. **Both** history assemblers must consult it -- `Conversation.loadFromDb` and `loadSlackChronologicalContext`, which re-reads rows rather than using `this.messages` -- or the unfiltered one replays the card between a parked turn's `tool_use` and its `tool_result` and history repair destroys the real result. Surface state is exempt on purpose: the card's buttons must still route after a restart. Full rationale in [docs/guardian-request-flow.md](../../docs/guardian-request-flow.md).
|
|
@@ -75,6 +75,39 @@ export function approvalCardSurfaceId(
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Whether a persisted message row is a guardian card rather than the
|
|
80
|
+
* conversation's own speech.
|
|
81
|
+
*
|
|
82
|
+
* Read off the card's own `ui_surface` id, using the prefixes above. The card
|
|
83
|
+
* builder writes that block on every path (`ensureSeedContentBlocks`), and the
|
|
84
|
+
* withdrawal path already recomputes the same id from the same constants, so
|
|
85
|
+
* the identity is structural rather than sniffed. Deriving it means rows
|
|
86
|
+
* written before this rule existed are recognized on the same terms as new
|
|
87
|
+
* ones, with no marker to backfill.
|
|
88
|
+
*
|
|
89
|
+
* Only a row that LEADS with an approval-card surface counts. A real assistant
|
|
90
|
+
* turn can carry a `ui_surface` block too (a wake card is unshifted onto the
|
|
91
|
+
* turn's own content), and those surfaces do not use these prefixes; requiring
|
|
92
|
+
* the lead position keeps the rule from ever swallowing a turn that has speech
|
|
93
|
+
* in it.
|
|
94
|
+
*/
|
|
95
|
+
export function isGuardianCardRow(
|
|
96
|
+
content: readonly unknown[] | string | null | undefined,
|
|
97
|
+
): boolean {
|
|
98
|
+
if (!Array.isArray(content) || content.length === 0) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const lead = content[0] as { type?: unknown; surfaceId?: unknown };
|
|
102
|
+
if (lead?.type !== "ui_surface" || typeof lead.surfaceId !== "string") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return (
|
|
106
|
+
lead.surfaceId.startsWith(`${ACCESS_REQUEST_SURFACE_PREFIX}-`) ||
|
|
107
|
+
lead.surfaceId.startsWith(`${TOOL_APPROVAL_SURFACE_PREFIX}-`)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
78
111
|
// ── Typed card data ─────────────────────────────────────────────────────────
|
|
79
112
|
|
|
80
113
|
/** Resolved card data for an access-request notification. */
|