@trim21/personal-pi-extensions 0.1.558 → 0.1.559

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.558",
3
+ "version": "0.1.559",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -118,6 +118,10 @@ function splitFileLines(content: string): string[] {
118
118
  * 的 `N\t` 前缀——tab 分隔符在 Go 等 tab 缩进语言里会与内容缩进连排,模型
119
119
  * 易误判多一层缩进。limit 未指定时读取全部。无 PARTIAL 提示、无单行截断
120
120
  * (由 execute 层的字节/token 上限兜底)。
121
+ *
122
+ * offset 为负数时从文件末尾倒数(`offset=-5` 等价 `tail -n 5`),超出文件
123
+ * 长度时钳到文件开头(与 tail 一致,不告警)。输出行号始终为绝对行号;
124
+ * offset=0 的「行号从 0 起」是对齐 Claude Code lineOffset 的历史语义。
121
125
  */
122
126
  export function formatReadOutput(
123
127
  content: string,
@@ -138,11 +142,11 @@ export function formatReadOutput(
138
142
  totalLines,
139
143
  };
140
144
  }
141
- // offset=0 时从第一行开始、行号从 0 起(对齐 Claude Code 的 lineOffset 语义)
142
- const startIndex = offset === 0 ? 0 : offset - 1;
145
+ const startIndex = offset === 0 ? 0 : offset > 0 ? offset - 1 : Math.max(totalLines + offset, 0);
146
+ const firstLine = offset === 0 ? 0 : startIndex + 1;
143
147
  const selected =
144
148
  limit === undefined ? lines.slice(startIndex) : lines.slice(startIndex, startIndex + limit);
145
- const text = selected.map((line, index) => `${offset + index}: ${line}`).join("\n");
149
+ const text = selected.map((line, index) => `${firstLine + index}: ${line}`).join("\n");
146
150
  return { text, totalLines };
147
151
  }
148
152
 
@@ -234,6 +238,7 @@ export function registerFileTools(
234
238
  "Reads a file from the local filesystem. You can access any file directly using this tool.",
235
239
  "Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.",
236
240
  "The file_path parameter must be an absolute path. By default, it reads the entire file; files over 256 KB or 25K tokens require offset and limit.",
241
+ "Read parts of files with offset and limit instead of running head/tail via Bash: a positive offset is the starting line number, a negative offset counts from the end of the file (offset=-5 reads the last 5 lines, like tail -n 5).",
237
242
  "Results use cat -n style line numbers starting at 1. Images are returned visually.",
238
243
  "This tool reads files, not directories.",
239
244
  ].join("\n"),
@@ -243,9 +248,12 @@ export function registerFileTools(
243
248
  {
244
249
  file_path: Type.String({ description: "The absolute path to the file to read" }),
245
250
  offset: Type.Optional(
246
- Type.Number({ description: "The line number to start reading from" }),
251
+ Type.Integer({
252
+ description:
253
+ "The line number to start reading from. A negative value counts from the end of the file (offset=-5 starts 5 lines before EOF).",
254
+ }),
247
255
  ),
248
- limit: Type.Optional(Type.Number({ description: "The number of lines to read" })),
256
+ limit: Type.Optional(Type.Integer({ description: "The number of lines to read" })),
249
257
  pages: Type.Optional(
250
258
  Type.String({ description: 'Page range for PDF files (for example "1-5" or "3")' }),
251
259
  ),
@@ -255,11 +263,8 @@ export function registerFileTools(
255
263
  async execute(_id, params, signal, _onUpdate, ctx) {
256
264
  signal?.throwIfAborted();
257
265
  const filePath = requireAbsolutePath(params.file_path);
258
- if (
259
- params.offset !== undefined &&
260
- (!Number.isSafeInteger(params.offset) || params.offset < 0)
261
- ) {
262
- throw new Error("offset must be a non-negative integer");
266
+ if (params.offset !== undefined && !Number.isSafeInteger(params.offset)) {
267
+ throw new Error("offset must be an integer");
263
268
  }
264
269
  if (params.limit !== undefined && (!Number.isSafeInteger(params.limit) || params.limit < 1)) {
265
270
  throw new Error("limit must be a positive integer");
@@ -7,6 +7,7 @@ Usage:
7
7
  - The file_path parameter must be an absolute path, not a relative path
8
8
  - By default, it reads the entire file; files over 256 KB or 25K tokens require offset and limit to read specific portions
9
9
  - When you already know which part of the file you need, only read that part. This can be important for larger files.
10
+ - Do not use head/tail (or sed -n) via the Bash tool to read parts of files — use offset and limit here instead. They are line-based: `offset=5, limit=10` reads 10 lines starting at line 5 (like `sed -n '5,14p'`), and a negative offset counts from the end of the file — `offset=-5` reads the last 5 lines (like `tail -n 5`). Line numbers in the output are always absolute.
10
11
  - Results are returned as `<lineNumber>: <content>` lines, 1-indexed
11
12
  - This tool allows you to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually.
12
13
  - This tool can only read files, not directories. To read a directory, use an ls command via the Bash tool.