pi-syntax-highlight 0.0.0-stage → 0.1.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/CHANGELOG.md +60 -0
- package/README.md +68 -2
- package/extensions/index.ts +22 -0
- package/package.json +35 -4
- package/src/active-theme.ts +26 -0
- package/src/detect-language.ts +294 -0
- package/src/emphasis.ts +160 -0
- package/src/grep-parse.ts +42 -0
- package/src/highlight.ts +109 -0
- package/src/markdown-fence-lang.ts +180 -0
- package/src/markdown-style.ts +134 -0
- package/src/markdown-theme.ts +53 -0
- package/src/render-bash.ts +180 -0
- package/src/render-edit.ts +207 -0
- package/src/render-find.ts +64 -0
- package/src/render-generic.ts +86 -0
- package/src/render-grep.ts +142 -0
- package/src/render-ls.ts +66 -0
- package/src/render-path.ts +54 -0
- package/src/render-read.ts +277 -0
- package/src/render-utils.ts +219 -0
- package/src/render-write.ts +81 -0
- package/src/resolve-renderers.ts +406 -0
- package/src/style-path.ts +48 -0
- package/src/tokens.ts +114 -0
- package/test/unit/active-theme.test.ts +38 -0
- package/test/unit/bash-preview.test.ts +57 -0
- package/test/unit/detect-language.test.ts +124 -0
- package/test/unit/emphasis.test.ts +113 -0
- package/test/unit/extensions-index.test.ts +116 -0
- package/test/unit/grep-parse.test.ts +125 -0
- package/test/unit/highlight.test.ts +107 -0
- package/test/unit/markdown-fence-lang.test.ts +131 -0
- package/test/unit/markdown-pipeline.test.ts +153 -0
- package/test/unit/markdown-render-parity.test.ts +127 -0
- package/test/unit/markdown-style.test.ts +152 -0
- package/test/unit/markdown-theme.test.ts +86 -0
- package/test/unit/render-bash.test.ts +194 -0
- package/test/unit/render-edit.test.ts +214 -0
- package/test/unit/render-find.test.ts +139 -0
- package/test/unit/render-generic.test.ts +152 -0
- package/test/unit/render-grep.test.ts +338 -0
- package/test/unit/render-ls.test.ts +132 -0
- package/test/unit/render-read.test.ts +375 -0
- package/test/unit/render-utils.test.ts +324 -0
- package/test/unit/render-write.test.ts +143 -0
- package/test/unit/resolve-renderers.test.ts +474 -0
- package/test/unit/style-path.test.ts +74 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, getPackageDir } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { setCapabilityOverrides } from "@earendil-works/pi-tui";
|
|
8
|
+
import type { HighlightFn } from "../../src/highlight.ts";
|
|
9
|
+
import {
|
|
10
|
+
buildReadCallText,
|
|
11
|
+
buildReadResultText,
|
|
12
|
+
readLimit,
|
|
13
|
+
readOffset,
|
|
14
|
+
readPath,
|
|
15
|
+
splitReadNotice,
|
|
16
|
+
type ReadCallInput,
|
|
17
|
+
type ReadResultInput,
|
|
18
|
+
} from "../../src/render-read.ts";
|
|
19
|
+
import { BOLD_OFF, BOLD_ON, TOKEN } from "../../src/tokens.ts";
|
|
20
|
+
|
|
21
|
+
const fakeTheme = {
|
|
22
|
+
fg: (c: string, t: string) => `<${c}>${t}</${c}>`,
|
|
23
|
+
bg: (c: string, t: string) => `<bg:${c}>${t}</bg:${c}>`,
|
|
24
|
+
bold: (t: string) => `<b>${t}</b>`,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const EXPAND_HINT = "<hint>";
|
|
28
|
+
const FOOTER_2 = "<muted>\n... (2 more lines,</muted> <hint><muted>)</muted>";
|
|
29
|
+
// `keyText` reads the live keybinding table, which a test process has not
|
|
30
|
+
// registered, so the compact header falls back to the built-in default key.
|
|
31
|
+
const COMPACT_HINT = "<dim> (ctrl+o to expand)</dim>";
|
|
32
|
+
|
|
33
|
+
// The header always links unless the terminal is told it cannot; the gate is
|
|
34
|
+
// pinned here so the assertions read the styled text and the link is exercised
|
|
35
|
+
// in its own test.
|
|
36
|
+
setCapabilityOverrides({ hyperlinks: false });
|
|
37
|
+
|
|
38
|
+
interface HighlightCall {
|
|
39
|
+
code: string;
|
|
40
|
+
lang: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function makeHighlight(calls: HighlightCall[]): HighlightFn {
|
|
44
|
+
return (code, lang) => {
|
|
45
|
+
calls.push({ code, lang });
|
|
46
|
+
return code.split("\n").map((line) => `<${lang}>${line}</${lang}>`);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readInput(overrides: Partial<ReadResultInput> = {}): ReadResultInput {
|
|
51
|
+
return {
|
|
52
|
+
output: "",
|
|
53
|
+
path: "",
|
|
54
|
+
offset: undefined,
|
|
55
|
+
details: undefined,
|
|
56
|
+
expanded: true,
|
|
57
|
+
isError: false,
|
|
58
|
+
hasImage: false,
|
|
59
|
+
theme: fakeTheme,
|
|
60
|
+
expandHint: EXPAND_HINT,
|
|
61
|
+
highlight: makeHighlight([]),
|
|
62
|
+
...overrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function callInput(overrides: Partial<ReadCallInput> = {}): ReadCallInput {
|
|
67
|
+
return {
|
|
68
|
+
path: "src/a.ts",
|
|
69
|
+
offset: undefined,
|
|
70
|
+
limit: undefined,
|
|
71
|
+
compact: false,
|
|
72
|
+
theme: fakeTheme,
|
|
73
|
+
cwd: "/work",
|
|
74
|
+
...overrides,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function plain(content: string): string {
|
|
79
|
+
return `<toolOutput>${content}</toolOutput>`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The gutter every file body carries: the number right-aligned to the widest one
|
|
83
|
+
// on screen, then the separator, then the content one space away.
|
|
84
|
+
function gutter(number: number, width: number, content: string): string {
|
|
85
|
+
const pad = String(number).padStart(width);
|
|
86
|
+
return content === ""
|
|
87
|
+
? `<syntaxNumber>${pad}</syntaxNumber><dim> |</dim>`
|
|
88
|
+
: `<syntaxNumber>${pad}</syntaxNumber><dim> |</dim> ${content}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function lines(rendered: string[]): string {
|
|
92
|
+
return ["", ...rendered].join("\n");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
test("buildReadResultText: a collapsed result with no failure renders nothing", () => {
|
|
96
|
+
assert.equal(buildReadResultText(readInput({ output: "a\nb", expanded: false })), "");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("buildReadResultText: the gutter counts from line 1 when the call carries no offset", () => {
|
|
100
|
+
const text = buildReadResultText(readInput({ output: "a\nb\nc" }));
|
|
101
|
+
assert.equal(text, lines([gutter(1, 1, plain("a")), gutter(2, 1, plain("b")), gutter(3, 1, plain("c"))]));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("buildReadResultText: the first line number is the call's offset and the width follows the last one", () => {
|
|
105
|
+
const text = buildReadResultText(readInput({ output: "a\nb\nc", offset: 98 }));
|
|
106
|
+
assert.equal(
|
|
107
|
+
text,
|
|
108
|
+
lines([gutter(98, 3, plain("a")), gutter(99, 3, plain("b")), gutter(100, 3, plain("c"))]),
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("buildReadResultText: a file with a grammar is highlighted in a single call", () => {
|
|
113
|
+
const calls: HighlightCall[] = [];
|
|
114
|
+
const output = "const a = 1;\nconst b = 2;";
|
|
115
|
+
const text = buildReadResultText(readInput({ output, path: "a.ts", highlight: makeHighlight(calls) }));
|
|
116
|
+
assert.deepEqual(calls, [{ code: output, lang: "typescript" }]);
|
|
117
|
+
assert.equal(
|
|
118
|
+
text,
|
|
119
|
+
lines([
|
|
120
|
+
gutter(1, 1, "<typescript>const a = 1;</typescript>"),
|
|
121
|
+
gutter(2, 1, "<typescript>const b = 2;</typescript>"),
|
|
122
|
+
]),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("buildReadResultText: a continuation notice leaves the highlighted block and is painted as a notice", () => {
|
|
127
|
+
const notice = "3 more lines in file. Use offset=3 to continue.";
|
|
128
|
+
const calls: HighlightCall[] = [];
|
|
129
|
+
const text = buildReadResultText(
|
|
130
|
+
readInput({ output: `a\nb\n\n[${notice}]`, path: "a.ts", highlight: makeHighlight(calls) }),
|
|
131
|
+
);
|
|
132
|
+
// Only the file's own lines reach the tokenizer: the notice is a message, not
|
|
133
|
+
// code, and painting it as code is what this package fixes.
|
|
134
|
+
assert.deepEqual(calls, [{ code: "a\nb", lang: "typescript" }]);
|
|
135
|
+
assert.equal(
|
|
136
|
+
text,
|
|
137
|
+
lines([gutter(1, 1, "<typescript>a</typescript>"), gutter(2, 1, "<typescript>b</typescript>")]) +
|
|
138
|
+
`\n<warning>[${notice}]</warning>`,
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("buildReadResultText: the truncation continuation notice is recognized with and without the byte limit", () => {
|
|
143
|
+
assert.equal(TOKEN.notice, "warning");
|
|
144
|
+
for (const notice of [
|
|
145
|
+
"Showing lines 1-1 of 5000. Use offset=2 to continue.",
|
|
146
|
+
`Showing lines 1-1 of 5000 (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=2 to continue.`,
|
|
147
|
+
]) {
|
|
148
|
+
const text = buildReadResultText(readInput({ output: `a\n\n[${notice}]` }));
|
|
149
|
+
assert.equal(text, lines([gutter(1, 1, plain("a"))]) + `\n<warning>[${notice}]</warning>`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("splitReadNotice: a bracket block that is not one of the tool's notices stays in the body", () => {
|
|
154
|
+
for (const trailing of ["[not a notice]", "[3 more lines]", "[Showing lines 1-2 of 3]"]) {
|
|
155
|
+
const output = `a\n\n${trailing}`;
|
|
156
|
+
assert.deepEqual(splitReadNotice(output, false), { body: output, notice: undefined });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("splitReadNotice: a notice without the blank separator stays in the body", () => {
|
|
161
|
+
// A file can end with a line that reads exactly like the notice, which is why
|
|
162
|
+
// the separator the tool prints is part of what makes a notice a notice.
|
|
163
|
+
const output = "a\n[3 more lines in file. Use offset=3 to continue.]";
|
|
164
|
+
assert.deepEqual(splitReadNotice(output, false), { body: output, notice: undefined });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("splitReadNotice: the oversized-first-line message is the whole output and loses its brackets", () => {
|
|
168
|
+
const message = "[Line 1 is 8.0KB, exceeds 50.0KB limit. Use bash: sed -n '1p' a.ts | head -c 51200]";
|
|
169
|
+
assert.deepEqual(splitReadNotice(message, true), {
|
|
170
|
+
body: "",
|
|
171
|
+
notice: message.slice(1, -1),
|
|
172
|
+
});
|
|
173
|
+
assert.deepEqual(splitReadNotice("", true), { body: "", notice: undefined });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("buildReadResultText: an oversized first line has no gutter and reports both notices", () => {
|
|
177
|
+
const message = `[Line 1 is 8.0KB, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '1p' a.ts | head -c 51200]`;
|
|
178
|
+
const text = buildReadResultText(
|
|
179
|
+
readInput({
|
|
180
|
+
output: message,
|
|
181
|
+
path: "a.ts",
|
|
182
|
+
details: { truncation: { truncated: true, firstLineExceedsLimit: true, maxBytes: DEFAULT_MAX_BYTES } },
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
assert.equal(
|
|
186
|
+
text,
|
|
187
|
+
`\n<warning>${message}</warning>\n<warning>[First line exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit]</warning>`,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("buildReadResultText: line truncation keeps the built-in wording and its default limit", () => {
|
|
192
|
+
const recorded = buildReadResultText(
|
|
193
|
+
readInput({
|
|
194
|
+
output: "a",
|
|
195
|
+
details: { truncation: { truncated: true, truncatedBy: "lines", outputLines: 10, totalLines: 500, maxLines: 10 } },
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
assert.equal(recorded, lines([gutter(1, 1, plain("a"))]) + "\n<warning>[Truncated: showing 10 of 500 lines (10 line limit)]</warning>");
|
|
199
|
+
|
|
200
|
+
const defaulted = buildReadResultText(
|
|
201
|
+
readInput({ output: "a", details: { truncation: { truncated: true, truncatedBy: "lines", outputLines: 10, totalLines: 500 } } }),
|
|
202
|
+
);
|
|
203
|
+
assert.equal(
|
|
204
|
+
defaulted,
|
|
205
|
+
lines([gutter(1, 1, plain("a"))]) +
|
|
206
|
+
`\n<warning>[Truncated: showing 10 of 500 lines (${DEFAULT_MAX_LINES} line limit)]</warning>`,
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("buildReadResultText: byte truncation reports the shown lines and the limit", () => {
|
|
211
|
+
const text = buildReadResultText(
|
|
212
|
+
readInput({
|
|
213
|
+
output: "a",
|
|
214
|
+
details: { truncation: { truncated: true, truncatedBy: "bytes", outputLines: 7, maxBytes: 1024 } },
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
assert.equal(text, lines([gutter(1, 1, plain("a"))]) + `\n<warning>[Truncated: 7 lines shown (${formatSize(1024)} limit)]</warning>`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("buildReadResultText: an untruncated result carries no truncation line", () => {
|
|
221
|
+
const text = buildReadResultText(readInput({ output: "a", details: { truncation: { truncated: false } } }));
|
|
222
|
+
assert.equal(text, lines([gutter(1, 1, plain("a"))]));
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("buildReadResultText: an expanded error is painted flat, with no gutter and no grammar", () => {
|
|
226
|
+
assert.equal(TOKEN.plain, "toolOutput");
|
|
227
|
+
const calls: HighlightCall[] = [];
|
|
228
|
+
const text = buildReadResultText(
|
|
229
|
+
readInput({ output: "boom\nsecond", path: "a.ts", isError: true, highlight: makeHighlight(calls) }),
|
|
230
|
+
);
|
|
231
|
+
assert.equal(text, lines([plain("boom"), plain("second")]));
|
|
232
|
+
assert.deepEqual(calls, []);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("buildReadResultText: a collapsed error keeps ten lines and counts the rest", () => {
|
|
236
|
+
const output = Array.from({ length: 12 }, (_, index) => `line${index + 1}`).join("\n");
|
|
237
|
+
const visible = Array.from({ length: 10 }, (_, index) => plain(`line${index + 1}`));
|
|
238
|
+
assert.equal(buildReadResultText(readInput({ output, isError: true, expanded: false })), lines(visible) + FOOTER_2);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("buildReadResultText: an image result is not file text, so it loses the gutter", () => {
|
|
242
|
+
const text = buildReadResultText(readInput({ output: "a screenshot", path: "a.png", hasImage: true }));
|
|
243
|
+
assert.equal(text, lines([plain("a screenshot")]));
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("buildReadResultText: a path with no known grammar never reaches the highlighter", () => {
|
|
247
|
+
const calls: HighlightCall[] = [];
|
|
248
|
+
const text = buildReadResultText(readInput({ output: "plain text", path: "notes", highlight: makeHighlight(calls) }));
|
|
249
|
+
assert.equal(text, lines([gutter(1, 1, plain("plain text"))]));
|
|
250
|
+
assert.deepEqual(calls, []);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("buildReadResultText: trailing empty lines are dropped from the body and the count", () => {
|
|
254
|
+
const text = buildReadResultText(readInput({ output: "a\nb\n\n\n" }));
|
|
255
|
+
assert.equal(text, lines([gutter(1, 1, plain("a")), gutter(2, 1, plain("b"))]));
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("buildReadResultText: a blank line in the middle is numbered and has no trailing space", () => {
|
|
259
|
+
const text = buildReadResultText(readInput({ output: "a\n\nb" }));
|
|
260
|
+
assert.equal(text, lines([gutter(1, 1, plain("a")), gutter(2, 1, ""), gutter(3, 1, plain("b"))]));
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("buildReadResultText: tabs are expanded before the line is painted", () => {
|
|
264
|
+
const text = buildReadResultText(readInput({ output: "\tindented" }));
|
|
265
|
+
assert.equal(text, lines([gutter(1, 1, plain(" indented"))]));
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("buildReadResultText: a highlighter that throws still renders the body", () => {
|
|
269
|
+
const failing: HighlightFn = () => {
|
|
270
|
+
throw new Error("no grammar");
|
|
271
|
+
};
|
|
272
|
+
const text = buildReadResultText(readInput({ output: "const a = 1;", path: "a.ts", highlight: failing }));
|
|
273
|
+
assert.equal(text, lines([gutter(1, 1, plain("const a = 1;"))]));
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("readOffset: numbers and numeric strings are read, everything else is unset", () => {
|
|
277
|
+
assert.equal(readOffset({ offset: 5 }), 5);
|
|
278
|
+
assert.equal(readOffset({ offset: "5" }), 5);
|
|
279
|
+
// The tool is 1-based, so anything below it is clamped instead of shifting the
|
|
280
|
+
// gutter into line zero.
|
|
281
|
+
assert.equal(readOffset({ offset: 0 }), 1);
|
|
282
|
+
assert.equal(readOffset({ offset: -3 }), 1);
|
|
283
|
+
assert.equal(readOffset({ offset: 2.7 }), 2);
|
|
284
|
+
assert.equal(readOffset({ offset: Number.NaN }), undefined);
|
|
285
|
+
assert.equal(readOffset({ offset: "abc" }), undefined);
|
|
286
|
+
assert.equal(readOffset({}), undefined);
|
|
287
|
+
assert.equal(readOffset(undefined), undefined);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("readLimit: the limit is read the same way as the offset", () => {
|
|
291
|
+
assert.equal(readLimit({ limit: 7 }), 7);
|
|
292
|
+
assert.equal(readLimit({ limit: "7" }), 7);
|
|
293
|
+
assert.equal(readLimit({ limit: 0 }), 1);
|
|
294
|
+
assert.equal(readLimit({}), undefined);
|
|
295
|
+
assert.equal(readLimit(undefined), undefined);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("readPath: file_path wins over path and a non-string argument is no path at all", () => {
|
|
299
|
+
assert.equal(readPath({ file_path: "a.ts" }), "a.ts");
|
|
300
|
+
assert.equal(readPath({ path: "b.ts" }), "b.ts");
|
|
301
|
+
assert.equal(readPath({ file_path: "a.ts", path: "b.ts" }), "a.ts");
|
|
302
|
+
assert.equal(readPath({ path: 42 }), "");
|
|
303
|
+
assert.equal(readPath({}), "");
|
|
304
|
+
assert.equal(readPath(undefined), "");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("buildReadCallText: the expanded header carries the title, the path and the range", () => {
|
|
308
|
+
assert.equal(TOKEN.path, "accent");
|
|
309
|
+
assert.equal(buildReadCallText(callInput()), "<toolTitle><b>read</b></toolTitle> <accent>src/a.ts</accent>");
|
|
310
|
+
assert.equal(
|
|
311
|
+
buildReadCallText(callInput({ offset: 10, limit: 5 })),
|
|
312
|
+
"<toolTitle><b>read</b></toolTitle> <accent>src/a.ts</accent><warning>:10-14</warning>",
|
|
313
|
+
);
|
|
314
|
+
assert.equal(
|
|
315
|
+
buildReadCallText(callInput({ offset: 10 })),
|
|
316
|
+
"<toolTitle><b>read</b></toolTitle> <accent>src/a.ts</accent><warning>:10</warning>",
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("buildReadCallText: a path under the home directory is shown with a tilde", () => {
|
|
321
|
+
const path = join(homedir(), "notes.md");
|
|
322
|
+
assert.equal(
|
|
323
|
+
buildReadCallText(callInput({ path, cwd: undefined })),
|
|
324
|
+
"<toolTitle><b>read</b></toolTitle> <accent>~/notes.md</accent>",
|
|
325
|
+
);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("buildReadCallText: the header links the shortened text to the absolute path", () => {
|
|
329
|
+
setCapabilityOverrides({ hyperlinks: true });
|
|
330
|
+
try {
|
|
331
|
+
const href = pathToFileURL(join("/work", "src/a.ts")).href;
|
|
332
|
+
const text = buildReadCallText(callInput());
|
|
333
|
+
assert.equal(
|
|
334
|
+
text,
|
|
335
|
+
`<toolTitle><b>read</b></toolTitle> \x1b]8;;${href}\x1b\\<accent>src/a.ts</accent>\x1b]8;;\x1b\\`,
|
|
336
|
+
);
|
|
337
|
+
} finally {
|
|
338
|
+
setCapabilityOverrides({ hyperlinks: false });
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("buildReadCallText: a compact skill header names the directory instead of the path", () => {
|
|
343
|
+
const text = buildReadCallText(callInput({ path: "skills/pdf/SKILL.md", compact: true }));
|
|
344
|
+
assert.equal(
|
|
345
|
+
text,
|
|
346
|
+
`<customMessageLabel>${BOLD_ON}[skill]${BOLD_OFF} </customMessageLabel><customMessageText>pdf</customMessageText>${COMPACT_HINT}`,
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test("buildReadCallText: a compact resource header is the relative path of an agent file", () => {
|
|
351
|
+
for (const name of ["AGENTS.md", "CLAUDE.md"]) {
|
|
352
|
+
const text = buildReadCallText(callInput({ path: name, cwd: "/work", compact: true }));
|
|
353
|
+
assert.equal(text, `<toolTitle><b>read resource</b></toolTitle> <accent>${name}</accent>${COMPACT_HINT}`);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("buildReadCallText: a file of pi's own documentation is a compact resource", () => {
|
|
358
|
+
const path = join(getPackageDir(), "docs", "tools.md");
|
|
359
|
+
assert.equal(
|
|
360
|
+
buildReadCallText(callInput({ path, cwd: "/work", compact: true })),
|
|
361
|
+
`<toolTitle><b>read resource</b></toolTitle> <accent>docs/tools.md</accent>${COMPACT_HINT}`,
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("buildReadCallText: the compact header keeps the line range and only collapses known files", () => {
|
|
366
|
+
assert.equal(
|
|
367
|
+
buildReadCallText(callInput({ path: "AGENTS.md", offset: 3, limit: 2, compact: true })),
|
|
368
|
+
"<toolTitle><b>read resource</b></toolTitle> <accent>AGENTS.md</accent><warning>:3-4</warning>" + COMPACT_HINT,
|
|
369
|
+
);
|
|
370
|
+
// Every other file keeps the full header even when the transcript is collapsed.
|
|
371
|
+
assert.equal(
|
|
372
|
+
buildReadCallText(callInput({ path: "src/a.ts", compact: true })),
|
|
373
|
+
"<toolTitle><b>read</b></toolTitle> <accent>src/a.ts</accent>",
|
|
374
|
+
);
|
|
375
|
+
});
|