@criogaid/pi-hashline-edit 0.3.0 → 0.3.1

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 CHANGED
@@ -60,7 +60,7 @@ Successful `edit` and `replace` results omit candidate rows whose full content a
60
60
 
61
61
  | Tool | Use it for |
62
62
  | --- | --- |
63
- | `read` | Inspect files with line anchors; images/binary handling delegates to Pi. |
63
+ | `read` | Inspect UTF-8 text with line anchors; Pi-supported images and NUL-containing files use Pi's built-in read. Other invalid UTF-8 is rejected. |
64
64
  | `grep` | Search with bundled ripgrep and return anchored matches/context, file paths, or counts. |
65
65
  | `edit` | Change specific lines or ranges using verified anchors. |
66
66
  | `replace` | Replace every occurrence of a literal string or JavaScript regex across one file. |
@@ -158,7 +158,7 @@ Required: `path`. Optional: 1-based `offset` (default 1) and `limit` (default 20
158
158
 
159
159
  Context is rebuilt from surviving matches. Multiline filtering, counting, and limits remain line-based. Wildcard-only regexes such as `.*` and `^.+$` are accepted; use `literal: true` to search those characters verbatim.
160
160
 
161
- All inclusion/exclusion matching uses bundled ripgrep on the shared LF view, independent of system `rg` or `PATH`. File selection uses original paths, ignore rules, globs, and link settings. Search batches stage up to 64 normalized temporary files or 8 MiB of text (one large file can exceed that threshold); snapshots are removed after each batch and on failure/cancellation. This adds temporary disk I/O. Match paths refer to original files; line and column positions refer to logical text. Searches include hidden files and pass `--no-config`, `--no-crlf`, and `--encoding=none` for snapshot matching so standalone CR and BOM remain content. The default engine is Rust regex; PCRE2 never silently falls back to another engine or literal matching.
161
+ Text inclusion/exclusion matching uses bundled ripgrep on the shared LF view, independent of system `rg` or `PATH`. NUL-containing files are searched as raw bytes; confirmed content-mode hits are rejected before anchoring. File selection uses original paths, ignore rules, globs, and link settings. Search batches stage up to 64 temporary files or 8 MiB of data (one large file can exceed that threshold); snapshots are removed after each batch and on failure/cancellation. This adds temporary disk I/O. Match paths refer to original files; text line and column positions refer to logical text. Searches include hidden files and pass `--no-config`, `--no-crlf`, and `--encoding=none` for snapshot matching so standalone CR and BOM remain content. The default engine is Rust regex; PCRE2 never silently falls back to another engine or literal matching.
162
162
 
163
163
  Search diagnostics are preserved even when a result limit stops ripgrep. Readable, confirmed matches remain available with a `Search incomplete` notice and `details.incomplete: true`; counts then cover only confirmed matches. If no results can be returned, the tool reports an error rather than claiming there are no matches. Exclusion-scan failures still reject the query, because incomplete exclusions could admit incorrect results. Search diagnostics have a separate 4 KiB display budget.
164
164
 
@@ -242,7 +242,7 @@ Fusion serializes each mutation/command sequence for its target and checks the p
242
242
  - **Anchors are checksums, not identities.** Each hash combines the 1-based line number and content. Short hashes can collide and do not prove the model observed a line.
243
243
  - **Validation is local to supplied anchors.** Unrelated in-place changes leave stable anchors usable. A range verifies its supplied start/end anchors, not every interior line.
244
244
  - **Line shifts change anchors.** Insertions/deletions can invalidate later references. Recovery searches within `shiftRadius`, then the rest of the file if no local candidates match. Unique candidates include bounded line content; ambiguous candidates include neighborhoods for comparison. Use `read` when no candidate is found or needed content is omitted. Retries verify again, without fuzzy matching or automatic relocation.
245
- - **Edits preserve text representation.** `edit` preserves existing line endings, untouched separators, and the absence of a final newline. `edit`/`replace` reject invalid UTF-8 source text; all mutations reject NUL and output that cannot be encoded losslessly as UTF-8.
245
+ - **Edits preserve text representation.** `edit` preserves existing line endings, untouched separators, and the absence of a final newline. `edit`/`replace` reject invalid UTF-8 source text; all mutations reject NUL and output that cannot be encoded losslessly as UTF-8. UTF-16 and legacy code pages are not decoded or preserved; a BOM-free file whose bytes happen to be valid UTF-8 may still be misinterpreted.
246
246
  - **Fresh anchors depend on the final observation.** After `then_run`, anchors are shown only for `unchanged` freshness. Without a command, observed and published revisions must agree. Later edits still verify anchors.
247
247
  - **Local queues are not cross-process transactions.** Revision checks bind mutations to the bytes read, but an external writer can still race a check and publication. There is no strict workspace jail or multi-file transaction.
248
248
 
@@ -251,7 +251,7 @@ Fusion serializes each mutation/command sequence for its target and checks the p
251
251
 
252
252
  ### Hashing and BOM handling
253
253
 
254
- `read` computes line hashes only for its requested window; `grep` hashes selected matches/context. Both still read and decode whole files. Mutation revision checks cover actual bytes.
254
+ `read` computes line hashes only for its requested window; `grep` hashes selected matches/context. Anchored text output still requires decoding whole files; grep stages NUL-containing files as raw bytes and rejects confirmed content-mode hits before hashing. Mutation revision checks cover actual bytes.
255
255
 
256
256
  Line boundaries are LF or CRLF; a standalone CR remains line content. Anchored rows display standalone CR as `␍` (U+240D), while hashes use the original content. Edit/replace `details.diff` marks raw CR as `␍`; `details.displayDiff` renders the shared LF view for the TUI, so CRLF boundary markers stay hidden even in mixed-ending files or beside an unterminated last line. Standalone CR and literal `␍` characters remain visible. Unified patches retain the original characters and line endings. The marker is a display aid, not replacement text.
257
257
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@criogaid/pi-hashline-edit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Hashline-style file editing for pi — line-anchored edits verified by content hash, replacing oldText/newText matching",
6
6
  "homepage": "https://github.com/Criogaid/pi-hashline-edit#readme",
@@ -56,6 +56,18 @@ test("read execute: text outputs LINE#HASH│content", async () => {
56
56
  });
57
57
  });
58
58
 
59
+ test("read execute: Pi-supported images without NUL bypass text decoding", async () => withDir(async (dir) => {
60
+ for (const [name, bytes, mime] of [
61
+ ["picture.jpg", Buffer.from([0xff, 0xd8, 0xff, 0xd9]), "image/jpeg"],
62
+ ["picture.gif", Buffer.from("GIF89a"), "image/gif"],
63
+ ] as const) {
64
+ await writeFile(join(dir, name), bytes);
65
+ const result: any = await call(makeReadOverride(dir), { path: name });
66
+ assert.ok(result.content[0].text.startsWith(`Read image file [${mime}]`));
67
+ assert.deepEqual(await readFile(join(dir, name)), bytes);
68
+ }
69
+ }));
70
+
59
71
  test("read execute: a missing final newline is stated in the header", async () => {
60
72
  await withDir(async (dir) => {
61
73
  await writeFile(join(dir, "f.txt"), "line1\nline2");
@@ -563,6 +575,13 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
563
575
  await assert.rejects(call(makeEditOverride(dir), { path: "nul.txt", edits: [{ op: "append", body: ["x"] }] }), /UNSUPPORTED_TEXT/);
564
576
  await assert.rejects(call(makeReplaceTool(dir), { path: "nul.txt", find: "a", replace: "b" }), /UNSUPPORTED_TEXT/);
565
577
  assert.deepEqual(await readFile(nulTarget), nulOriginal);
578
+
579
+ const nativeRead: any = await call(makeReadOverride(dir), { path: "nul.txt" });
580
+ assert.equal(nativeRead.content[0].text, "a\0b");
581
+
582
+ const utf16Target = join(dir, "utf16.txt");
583
+ await writeFile(utf16Target, Buffer.from([0xff, 0xfe, 0x49, 0x6c]));
584
+ await assert.rejects(call(makeReadOverride(dir), { path: "utf16.txt" }), /UNSUPPORTED_ENCODING/);
566
585
  }));
567
586
 
568
587
  test("edit rejects embedded line terminators even when schema validation is bypassed", async () => withDir(async (dir) => {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Override read: text files output "lineNo#hash│content"; non-text (images /
3
- * binary) and read errors delegate to the built-in read.
2
+ * Override read: recognized images and NUL-containing files delegate to Pi's
3
+ * built-in read; valid UTF-8 text outputs "lineNo#hash│content".
4
4
  *
5
5
  * Hashes are computed from the current content on the fly — nothing is stored.
6
6
  * The hash is `(line number, content)`, recomputed and checked at edit time, so
@@ -9,7 +9,10 @@
9
9
  * @module pi-hashline-edit/pi
10
10
  */
11
11
 
12
- import { createReadToolDefinition, getLanguageFromPath, highlightCode, truncateHead } from "@earendil-works/pi-coding-agent";
12
+ import {
13
+ createReadToolDefinition, detectSupportedImageMimeTypeFromFile,
14
+ getLanguageFromPath, highlightCode, truncateHead,
15
+ } from "@earendil-works/pi-coding-agent";
13
16
  import { Text } from "@earendil-works/pi-tui";
14
17
  import { readFile } from "node:fs/promises";
15
18
  import { decodeUtf8 } from "../core/index.ts";
@@ -115,13 +118,16 @@ export function makeReadOverride(cwd: string) {
115
118
  const absPath = canonicalPath(cwd, params.path as string);
116
119
  let buf: Buffer;
117
120
  try {
121
+ if (await detectSupportedImageMimeTypeFromFile(absPath)) {
122
+ return builtin.execute(toolCallId, params, signal, onUpdate, ctx);
123
+ }
118
124
  buf = await readFile(absPath);
119
125
  } catch {
120
126
  // read error → delegate to the built-in (it has polished error messages)
121
127
  return builtin.execute(toolCallId, params, signal, onUpdate, ctx);
122
128
  }
123
129
 
124
- // binary/image detection (null byte) → delegate to the built-in (it uses file-type for images)
130
+ // NUL is a text-safety signal, not an exhaustive binary classifier.
125
131
  if (buf.includes(0)) return builtin.execute(toolCallId, params, signal, onUpdate, ctx);
126
132
 
127
133
  const text = decodeUtf8(buf);