@criogaid/pi-hashline-edit 0.6.1 → 0.8.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 +78 -369
- package/README.zh-CN.md +162 -0
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/package.json +11 -6
- package/src/core/AGENTS.md +20 -0
- package/src/core/apply.test.ts +328 -161
- package/src/core/apply.ts +129 -95
- package/src/core/case-fold.test.ts +44 -0
- package/src/core/case-fold.ts +77 -0
- package/src/core/character-set.test.ts +103 -0
- package/src/core/character-set.ts +184 -0
- package/src/core/errors.test.ts +23 -0
- package/src/core/errors.ts +70 -4
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +32 -7
- package/src/core/ranges.test.ts +41 -9
- package/src/core/ranges.ts +11 -4
- package/src/core/regex.ts +51 -0
- package/src/core/replace-schema.ts +41 -0
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +40 -56
- package/src/core/search-analysis.test.ts +208 -0
- package/src/core/search-analysis.ts +379 -0
- package/src/core/search-matrix.test.ts +64 -0
- package/src/core/search-matrix.testing.ts +183 -0
- package/src/core/search-schema.ts +18 -0
- package/src/core/search.test.ts +145 -0
- package/src/core/search.ts +119 -0
- package/src/core/text.test.ts +16 -8
- package/src/core/text.ts +26 -6
- package/src/core/types.ts +20 -17
- package/src/index.ts +24 -16
- package/src/integration/config-registration.test.ts +42 -28
- package/src/integration/fusion-dispatch.test.ts +62 -127
- package/src/integration/grep-errors.test.ts +50 -0
- package/src/integration/grep-flags.test.ts +273 -0
- package/src/integration/grep-js-completeness.test.ts +218 -0
- package/src/integration/grep-line-candidates.test.ts +233 -0
- package/src/integration/grep-matrix.test.ts +121 -0
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +133 -0
- package/src/integration/grep-prefilter-coverage.test.ts +189 -0
- package/src/integration/grep-regex.test.ts +407 -0
- package/src/integration/grep-rg.test.ts +294 -436
- package/src/integration/grep-scan-budget.test.ts +111 -0
- package/src/integration/grep-translation.test.ts +206 -0
- package/src/integration/large-text.test.ts +56 -1
- package/src/integration/model-budget-lifecycle.test.ts +137 -0
- package/src/integration/mutation-file-types.test.ts +12 -26
- package/src/integration/mutation-file-types.testing.ts +33 -0
- package/src/integration/npm-package.test.ts +17 -0
- package/src/integration/npm-package.testing.ts +97 -0
- package/src/integration/publication-read-changes.test.ts +376 -0
- package/src/integration/read-changes.test.ts +98 -0
- package/src/integration/replace-package.test.ts +17 -36
- package/src/integration/replace-package.testing.ts +36 -0
- package/src/integration/replace-worker-boundary.test.ts +117 -0
- package/src/integration/report-replay.test.ts +90 -0
- package/src/integration/utf8-errors.test.ts +46 -0
- package/src/pi/AGENTS.md +54 -0
- package/src/pi/action-fusion.test.ts +256 -251
- package/src/pi/action-fusion.ts +121 -332
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +16 -3
- package/src/pi/argument-diagnostics.ts +478 -0
- package/src/pi/argument-error.testing.ts +46 -0
- package/src/pi/argument-error.ts +76 -0
- package/src/pi/argument-format.test.ts +197 -0
- package/src/pi/argument-validation.test.ts +780 -49
- package/src/pi/argument-validation.ts +55 -58
- package/src/pi/budgets.ts +48 -21
- package/src/pi/codemode.test.ts +96 -0
- package/src/pi/config.test.ts +29 -15
- package/src/pi/config.ts +27 -13
- package/src/pi/diagnostic-buffer.test.ts +51 -16
- package/src/pi/diagnostic-buffer.ts +13 -16
- package/src/pi/directory-sync.test.ts +4 -1
- package/src/pi/edit-tool.ts +103 -99
- package/src/pi/error-text.ts +39 -16
- package/src/pi/execute.test.ts +407 -429
- package/src/pi/extension-loading.test.ts +7 -27
- package/src/pi/extension-loading.testing.ts +2 -14
- package/src/pi/failure-context.test.ts +265 -88
- package/src/pi/failure-context.ts +165 -181
- package/src/pi/failure-path.test.ts +179 -117
- package/src/pi/file-commit.test.ts +90 -73
- package/src/pi/file-commit.ts +216 -178
- package/src/pi/file-read.test.ts +29 -0
- package/src/pi/file-read.ts +60 -0
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/file-snapshot.test.ts +1 -1
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +233 -51
- package/src/pi/fusion-card.ts +246 -142
- package/src/pi/grep-candidates.test.ts +127 -0
- package/src/pi/grep-candidates.ts +191 -0
- package/src/pi/grep-matrix.test.ts +83 -0
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +187 -151
- package/src/pi/grep-render.ts +31 -25
- package/src/pi/grep-scope.ts +62 -54
- package/src/pi/grep-search.ts +327 -241
- package/src/pi/grep-tool.ts +126 -147
- package/src/pi/grep-worker.mjs +4 -0
- package/src/pi/grep-worker.ts +14 -0
- package/src/pi/grep.test.ts +813 -713
- package/src/pi/model-budgets.test.ts +43 -0
- package/src/pi/model-budgets.ts +44 -0
- package/src/pi/mutation-outcome.testing.ts +6 -7
- package/src/pi/mutation-result.test.ts +45 -91
- package/src/pi/mutation-result.ts +86 -114
- package/src/pi/mutation-runner.ts +81 -81
- package/src/pi/output-budgets.test.ts +175 -0
- package/src/pi/path.ts +10 -1
- package/src/pi/pi.test.ts +4 -5
- package/src/pi/read-tool.ts +108 -142
- package/src/pi/read.test.ts +155 -96
- package/src/pi/regex-worker-contract.ts +55 -0
- package/src/pi/regex-worker.ts +95 -0
- package/src/pi/registration.test.ts +148 -124
- package/src/pi/render.test.ts +361 -84
- package/src/pi/render.ts +150 -32
- package/src/pi/replace-regex.ts +13 -48
- package/src/pi/replace-tool.ts +52 -158
- package/src/pi/replace-worker-contract.ts +10 -0
- package/src/pi/replace-worker.ts +12 -8
- package/src/pi/replace.test.ts +191 -340
- package/src/pi/report-cause.ts +103 -0
- package/src/pi/report-failure.testing.ts +20 -0
- package/src/pi/report-schema.ts +524 -0
- package/src/pi/report.test.ts +343 -0
- package/src/pi/report.ts +285 -0
- package/src/pi/result-safety.test.ts +216 -481
- package/src/pi/rg-process.test.ts +101 -76
- package/src/pi/rg-process.ts +130 -177
- package/src/pi/rg-regex.test.ts +67 -0
- package/src/pi/rg-regex.ts +715 -0
- package/src/pi/text-stream.test.ts +97 -69
- package/src/pi/text-stream.ts +97 -76
- package/src/pi/tool-call.testing.ts +20 -46
- package/src/pi/write-tool.ts +50 -41
- package/src/pi/write.test.ts +71 -95
- package/src/testing/extension-loader.testing.ts +24 -0
- package/src/testing/installation.testing.ts +77 -0
- package/src/testing/process.testing.ts +33 -0
- package/src/testing/regex-host.testing.ts +20 -0
- package/src/testing/regex-translation-corpus.ts +324 -0
- package/src/testing/rg-line-listing.fixture.mjs +7 -0
- package/src/testing/run-tests.ts +47 -0
- package/src/testing/session.testing.ts +127 -0
- package/src/integration/forget-grep.test.ts +0 -98
- package/src/pi/forget-tool.ts +0 -268
- package/src/pi/forget.test.ts +0 -343
- package/src/pi/forget.testing.ts +0 -273
- package/src/pi/rg-line-ranges.test.ts +0 -66
- package/src/pi/rg-line-ranges.ts +0 -75
- package/src/pi/rg-match-bytes.ts +0 -95
- package/src/pi/rg-text-view.ts +0 -192
- package/src/pi/tool-prompts.ts +0 -15
package/src/pi/read-tool.ts
CHANGED
|
@@ -25,23 +25,20 @@ import { Text } from "@earendil-works/pi-tui";
|
|
|
25
25
|
import { Type } from "typebox";
|
|
26
26
|
import { scanTextLines } from "./text-stream.ts";
|
|
27
27
|
import { createAnchorFormatter, displayCarriageReturns, parseHashline } from "./anchor-format.ts";
|
|
28
|
-
import { canonicalPath } from "./path.ts";
|
|
29
|
-
import { renderToolError } from "./render.ts";
|
|
30
|
-
import {
|
|
31
|
-
type ForgetReceiptDetails,
|
|
32
|
-
readReceipt,
|
|
33
|
-
withoutResultTag,
|
|
34
|
-
withResultTag,
|
|
35
|
-
} from "./forget-tool.ts";
|
|
28
|
+
import { canonicalPath, serializePath } from "./path.ts";
|
|
29
|
+
import { renderToolError, reportLines, splitReport } from "./render.ts";
|
|
36
30
|
import { POSITIVE_SAFE_INTEGER } from "./schema.ts";
|
|
31
|
+
import { errnoCode } from "../core/errors.ts";
|
|
37
32
|
import { throwIfCancelled } from "./error-text.ts";
|
|
38
|
-
import {
|
|
33
|
+
import { reportResult, runTool, type ReportDetails } from "./report.ts";
|
|
34
|
+
import { defaultOutputBudgets, formatByteSize, type OutputBudgetProvider } from "./budgets.ts";
|
|
39
35
|
import type { HashlineEditConfig } from "./config.ts";
|
|
40
36
|
import { createArgumentPreparer } from "./argument-validation.ts";
|
|
41
37
|
|
|
42
38
|
const DEFAULT_OFFSET = 1;
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
/** Pi's read details for a delegated native read; the report states this read's own facts. */
|
|
41
|
+
type ReadDetails = (ReadToolDetails & { nativeRead?: true }) & Partial<ReportDetails>;
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
44
|
* First result line: `<path> · <N> lines`, optionally ` (from line <offset>)` and
|
|
@@ -58,15 +55,14 @@ function formatReadHeader(
|
|
|
58
55
|
const shownFrom = start > DEFAULT_OFFSET ? ` (from line ${start})` : "";
|
|
59
56
|
return `${path} · ${totalLines} lines${shownFrom}${finalNewline ? "" : " · no trailing newline"}`;
|
|
60
57
|
}
|
|
61
|
-
const READ_HEADER = /^(.+?) · (\d+ lines(?: \(from line \d+\))?(?: · no trailing newline)?)
|
|
58
|
+
const READ_HEADER = /^(.+?) · (\d+ lines(?: \(from line \d+\))?(?: · no trailing newline)?)$/s;
|
|
62
59
|
|
|
63
60
|
/**
|
|
64
61
|
* Render the expanded read body for the TUI: color the header, strip the
|
|
65
62
|
* `LINE#HASH│` prefix from every anchor line to ` N: content`, and
|
|
66
63
|
* syntax-highlight the code block by the file's language (falls back to a
|
|
67
64
|
* single `toolOutput` color when the language is unknown or the highlight
|
|
68
|
-
* line count diverges).
|
|
69
|
-
* `warning`.
|
|
65
|
+
* line count diverges). Notices are report facts, rendered from the report.
|
|
70
66
|
*/
|
|
71
67
|
function renderReadBody(raw: string, path: string, theme: Theme): string {
|
|
72
68
|
const lines = raw.split("\n");
|
|
@@ -82,16 +78,12 @@ function renderReadBody(raw: string, path: string, theme: Theme): string {
|
|
|
82
78
|
bodyStart = 1;
|
|
83
79
|
}
|
|
84
80
|
|
|
85
|
-
// Collect anchor rows (full content)
|
|
81
|
+
// Collect anchor rows (full content).
|
|
86
82
|
const lineNos: string[] = [];
|
|
87
83
|
const codeContents: string[] = [];
|
|
88
|
-
let tailStart = lines.length;
|
|
89
84
|
for (let i = bodyStart; i < lines.length; i++) {
|
|
90
85
|
const row = parseHashline(lines[i]);
|
|
91
|
-
if (!row)
|
|
92
|
-
tailStart = i;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
86
|
+
if (!row) break;
|
|
95
87
|
lineNos.push(row.lineNo);
|
|
96
88
|
codeContents.push(row.content);
|
|
97
89
|
}
|
|
@@ -111,9 +103,6 @@ function renderReadBody(raw: string, path: string, theme: Theme): string {
|
|
|
111
103
|
out.push(theme.fg("dim", ` ${lineNos[i]}: `) + rendered[i]);
|
|
112
104
|
}
|
|
113
105
|
|
|
114
|
-
for (let i = tailStart; i < lines.length; i++) {
|
|
115
|
-
out.push(theme.fg("warning", lines[i]));
|
|
116
|
-
}
|
|
117
106
|
return out.join("\n");
|
|
118
107
|
}
|
|
119
108
|
|
|
@@ -121,13 +110,13 @@ function renderReadBody(raw: string, path: string, theme: Theme): string {
|
|
|
121
110
|
export function makeReadOverride(
|
|
122
111
|
cwd: string,
|
|
123
112
|
config: HashlineEditConfig,
|
|
113
|
+
budgets: OutputBudgetProvider = defaultOutputBudgets,
|
|
124
114
|
): ToolDefinition<
|
|
125
115
|
ReturnType<typeof createReadToolDefinition>["parameters"],
|
|
126
116
|
ReadDetails | undefined
|
|
127
117
|
> {
|
|
128
118
|
const { hashLen } = config;
|
|
129
119
|
const { defaultLimit } = config.read;
|
|
130
|
-
const maxBytes = config.read.maxKiB * 1024;
|
|
131
120
|
const builtin = createReadToolDefinition(cwd);
|
|
132
121
|
// A TypeBox object, not a spread of Pi's plain JSON schema: argument diagnostics pick
|
|
133
122
|
// single fields from it, which needs TypeBox's own schema kinds.
|
|
@@ -137,7 +126,7 @@ export function makeReadOverride(
|
|
|
137
126
|
offset: Type.Optional(
|
|
138
127
|
Type.Number({
|
|
139
128
|
...POSITIVE_SAFE_INTEGER,
|
|
140
|
-
description: `1-based line to start from (default ${DEFAULT_OFFSET}).`,
|
|
129
|
+
description: `1-based line to start from (default ${DEFAULT_OFFSET}). For a large file, set offset and limit to read only the relevant section.`,
|
|
141
130
|
}),
|
|
142
131
|
),
|
|
143
132
|
limit: Type.Optional(
|
|
@@ -156,12 +145,8 @@ export function makeReadOverride(
|
|
|
156
145
|
description:
|
|
157
146
|
"Read a file. Text lines show as LINE#HASH│content anchors for edit; CRLF line endings show as LF.",
|
|
158
147
|
promptSnippet: "Read files with editable line anchors",
|
|
159
|
-
promptGuidelines: [
|
|
160
|
-
"Prefer read over shell output for files you intend to edit.",
|
|
161
|
-
"For large files, pass read offset and limit to read only the relevant section.",
|
|
162
|
-
],
|
|
163
148
|
parameters: parameters as typeof builtin.parameters,
|
|
164
|
-
prepareArguments: createArgumentPreparer("read", parameters),
|
|
149
|
+
prepareArguments: createArgumentPreparer("read", parameters, undefined, budgets),
|
|
165
150
|
renderShell: "default" as const,
|
|
166
151
|
|
|
167
152
|
renderCall: builtin.renderCall,
|
|
@@ -169,15 +154,22 @@ export function makeReadOverride(
|
|
|
169
154
|
renderResult(result, options, theme, context) {
|
|
170
155
|
const { isPartial, expanded } = options;
|
|
171
156
|
if (isPartial) return new Text(theme.fg("warning", "Reading…"), 0, 0);
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
if (context?.isError) return renderToolError(result, "read", theme, expanded);
|
|
158
|
+
const { content, report } = splitReport(result);
|
|
174
159
|
if (result.details?.nativeRead)
|
|
175
|
-
return builtin.renderResult!(
|
|
160
|
+
return builtin.renderResult!({ ...result, content }, options, theme, context);
|
|
176
161
|
// Collapsed (not expanded): show nothing — the call line carries the
|
|
177
162
|
// title, matching the built-in read's fold behavior.
|
|
178
163
|
if (!expanded) return new Text("", 0, 0);
|
|
179
|
-
const raw = content?.type === "text" ? content.text : "";
|
|
180
|
-
return new Text(
|
|
164
|
+
const raw = content[0]?.type === "text" ? content[0].text : "";
|
|
165
|
+
return new Text(
|
|
166
|
+
[
|
|
167
|
+
renderReadBody(raw, String(context?.args?.path ?? ""), theme),
|
|
168
|
+
...(report ? reportLines(report, theme) : []),
|
|
169
|
+
].join("\n"),
|
|
170
|
+
0,
|
|
171
|
+
0,
|
|
172
|
+
);
|
|
181
173
|
},
|
|
182
174
|
|
|
183
175
|
async execute(
|
|
@@ -187,120 +179,94 @@ export function makeReadOverride(
|
|
|
187
179
|
onUpdate: AgentToolUpdateCallback<ReadToolDetails | undefined> | undefined,
|
|
188
180
|
ctx: ExtensionToolContext,
|
|
189
181
|
) {
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
()
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
182
|
+
const budget = budgets();
|
|
183
|
+
const maxBytes =
|
|
184
|
+
config.read.maxKiB === undefined ? budget.readBytes : config.read.maxKiB * 1024;
|
|
185
|
+
return runTool("read", { path: params.path, signal, budget }, async () => {
|
|
186
|
+
throwIfCancelled(signal);
|
|
187
|
+
const start = params.offset ?? DEFAULT_OFFSET;
|
|
188
|
+
const limit = params.limit ?? defaultLimit;
|
|
189
|
+
const anchors = createAnchorFormatter(hashLen);
|
|
190
|
+
const report = { tool: "read" as const, path: params.path };
|
|
191
|
+
const readNative = async () => {
|
|
192
|
+
const result = await builtin.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
193
|
+
return reportResult(report, result.content, {
|
|
194
|
+
...result.details,
|
|
195
|
+
nativeRead: true as const,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
207
198
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
199
|
+
const absPath = canonicalPath(cwd, params.path);
|
|
200
|
+
try {
|
|
201
|
+
if (await detectSupportedImageMimeTypeFromFile(absPath)) {
|
|
202
|
+
return readNative();
|
|
203
|
+
}
|
|
204
|
+
} catch {
|
|
211
205
|
return readNative();
|
|
212
206
|
}
|
|
213
|
-
} catch {
|
|
214
|
-
return readNative();
|
|
215
|
-
}
|
|
216
207
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (!signal?.aborted && error instanceof Error && "code" in error) {
|
|
251
|
-
return readNative();
|
|
208
|
+
const rows: string[] = [];
|
|
209
|
+
const crExpansion = Buffer.byteLength(displayCarriageReturns("\r")) - 1;
|
|
210
|
+
let outputBytes = 0;
|
|
211
|
+
let truncated = false;
|
|
212
|
+
let firstLineExceedsLimit = false;
|
|
213
|
+
let stats: Awaited<ReturnType<typeof scanTextLines>>;
|
|
214
|
+
try {
|
|
215
|
+
stats = await scanTextLines(
|
|
216
|
+
absPath,
|
|
217
|
+
(number) => number >= start && number - start < limit,
|
|
218
|
+
(line) => {
|
|
219
|
+
if (truncated) return;
|
|
220
|
+
const rowBytes =
|
|
221
|
+
line.byteLength +
|
|
222
|
+
line.carriageReturns * crExpansion +
|
|
223
|
+
Buffer.byteLength(anchors.row(line.number, ""));
|
|
224
|
+
const nextBytes = outputBytes + rowBytes + (rows.length > 0 ? 1 : 0);
|
|
225
|
+
if (nextBytes > maxBytes) {
|
|
226
|
+
truncated = true;
|
|
227
|
+
firstLineExceedsLimit = rows.length === 0;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
rows.push(anchors.row(line.number, line.text!));
|
|
231
|
+
outputBytes = nextBytes;
|
|
232
|
+
},
|
|
233
|
+
{ signal, maxLineBytes: maxBytes },
|
|
234
|
+
);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
// Keep native filesystem diagnostics without retrying decoding or cancellation failures.
|
|
237
|
+
if (!signal?.aborted && errnoCode(error) !== undefined) {
|
|
238
|
+
return readNative();
|
|
239
|
+
}
|
|
240
|
+
throw error;
|
|
252
241
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
totalBytes,
|
|
271
|
-
outputLines: rows.length,
|
|
272
|
-
outputBytes,
|
|
273
|
-
lastLinePartial: false,
|
|
274
|
-
firstLineExceedsLimit,
|
|
275
|
-
maxLines: totalRows,
|
|
276
|
-
maxBytes,
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const tail = truncation.firstLineExceedsLimit
|
|
280
|
-
? `\n… (line ${start} exceeds ${formatKiB(maxBytes)}; cannot return a complete anchor row. Reducing limit cannot split a physical line; use bash to inspect it in chunks, or replace for a known literal/regex change)`
|
|
281
|
-
: truncation.truncated
|
|
282
|
-
? `\n… (truncated at ${formatKiB(maxBytes)}; use offset/limit to read more)`
|
|
283
|
-
: pagination
|
|
284
|
-
? `\n… (showing lines ${pagination.start}-${pagination.end} of ${pagination.totalLines}; use offset ${pagination.nextOffset} to continue)`
|
|
285
|
-
: "";
|
|
286
|
-
const header = `${formatReadHeader(params.path, stats.totalLines, start, stats.finalNewline)}\n`;
|
|
287
|
-
const body = truncation.content;
|
|
242
|
+
if (stats.hasNul) return readNative();
|
|
243
|
+
// Rows were returned and more remain. A caller's own limit is a chosen window: its header
|
|
244
|
+
// and rows already show where it ends, so only a window the extension cut (default limit
|
|
245
|
+
// or byte budget) gets a report.
|
|
246
|
+
const pagination =
|
|
247
|
+
(params.limit === undefined || truncated) &&
|
|
248
|
+
rows.length > 0 &&
|
|
249
|
+
start + rows.length <= stats.totalLines
|
|
250
|
+
? {
|
|
251
|
+
start,
|
|
252
|
+
end: start + (rows.length - 1),
|
|
253
|
+
totalLines: stats.totalLines,
|
|
254
|
+
nextOffset: start + rows.length,
|
|
255
|
+
}
|
|
256
|
+
: undefined;
|
|
257
|
+
const header = `${formatReadHeader(serializePath(cwd, absPath), stats.totalLines, start, stats.finalNewline)}\n`;
|
|
258
|
+
const limitText = formatByteSize(maxBytes);
|
|
288
259
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
rows.length > 0
|
|
300
|
-
? { start, end: start + rows.length - 1, truncated: truncation.truncated }
|
|
301
|
-
: undefined,
|
|
302
|
-
),
|
|
303
|
-
);
|
|
260
|
+
return reportResult(
|
|
261
|
+
{
|
|
262
|
+
...report,
|
|
263
|
+
pagination,
|
|
264
|
+
outputLimit: truncated && !firstLineExceedsLimit ? limitText : undefined,
|
|
265
|
+
lineTooLong: firstLineExceedsLimit ? { line: start, limit: limitText } : undefined,
|
|
266
|
+
},
|
|
267
|
+
[{ type: "text" as const, text: header + rows.join("\n") }],
|
|
268
|
+
);
|
|
269
|
+
});
|
|
304
270
|
},
|
|
305
271
|
};
|
|
306
272
|
}
|