pi-charset 0.1.3 → 0.1.5
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 +59 -0
- package/CHANGELOG.zh-CN.md +59 -0
- package/CONTRIBUTING.md +33 -0
- package/CONTRIBUTING.zh-CN.md +33 -0
- package/README.md +32 -6
- package/README.zh-CN.md +32 -6
- package/docs/ACCEPTANCE.md +30 -2
- package/docs/COMPATIBILITY.md +6 -1
- package/docs/CONFIG-GUIDE.md +4 -1
- package/docs/DESIGN-REVIEW.md +54 -0
- package/docs/EDIT-ENGINE.md +46 -0
- package/docs/EDITING-PLAN.md +16 -0
- package/docs/INSTALL.md +2 -2
- package/docs/MODEL-EVAL.md +92 -0
- package/docs/PROGRESS.md +311 -0
- package/docs/RELEASING.md +4 -2
- package/docs/zh-CN/ACCEPTANCE.md +30 -2
- package/docs/zh-CN/COMPATIBILITY.md +6 -1
- package/docs/zh-CN/CONFIG-GUIDE.md +4 -1
- package/docs/zh-CN/DESIGN-REVIEW.md +54 -0
- package/docs/zh-CN/EDIT-ENGINE.md +46 -0
- package/docs/zh-CN/EDITING-PLAN.md +415 -0
- package/docs/zh-CN/INSTALL.md +2 -2
- package/docs/zh-CN/MODEL-EVAL.md +92 -0
- package/docs/zh-CN/PROGRESS.md +311 -0
- package/docs/zh-CN/RELEASING.md +4 -2
- package/docs/zh-CN/editing-plan-architecture.png +0 -0
- package/examples/all-utf8.jsonc +1 -0
- package/examples/embedded-c.jsonc +1 -0
- package/examples/legacy-java-web.jsonc +1 -0
- package/examples/mixed-repo.jsonc +1 -0
- package/package.json +12 -2
- package/prompts/charset-setup.md +3 -3
- package/schema/pi-charset.schema.json +112 -0
- package/skills/charset-rules/SKILL.md +8 -2
- package/src/config.ts +444 -181
- package/src/edit/apply-patch.ts +388 -0
- package/src/edit/diagnostics.ts +45 -0
- package/src/edit/hashline.ts +438 -0
- package/src/edit/patch.ts +655 -0
- package/src/edit/plan.ts +107 -0
- package/src/edit/tool.ts +488 -0
- package/src/edit-preview.ts +48 -277
- package/src/encoding/classify.ts +246 -60
- package/src/encoding/common-scripts.ts +66 -0
- package/src/encoding/converter.ts +111 -15
- package/src/encoding/fast-codec.ts +469 -0
- package/src/encoding/file-stamp.ts +55 -0
- package/src/encoding/line-endings.ts +66 -73
- package/src/encoding/mime.ts +12 -43
- package/src/encoding/stream-transcode.ts +135 -30
- package/src/grep.ts +433 -170
- package/src/index.ts +458 -49
- package/src/journal.ts +459 -0
- package/src/maintenance.ts +375 -0
- package/src/operations.ts +757 -127
- package/src/read-view.ts +924 -0
- package/src/resolve.ts +124 -80
- package/src/scaffold.ts +9 -4
- package/src/shell-guard.ts +617 -0
- package/src/shell.ts +85 -33
- package/src/sysnote.ts +4 -6
- package/src/version.ts +1 -1
- package/tools/charset-core.mjs +240 -0
- package/tools/pi-charset-cli.mjs +221 -0
- package/tools/scan-encoding.mjs +30 -28
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Exact edit engine
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./zh-CN/EDIT-ENGINE.md)
|
|
4
|
+
|
|
5
|
+
## Contract
|
|
6
|
+
|
|
7
|
+
- Each call edits one existing writable regular file. Links, invalid source bytes, a conflicting read encoding, bare CR, and mixed line endings are rejected. If multiple legacy codecs round-trip, the configured preference and candidate order determine the verdict.
|
|
8
|
+
- `edit` supports four encoding-safe modes against the same immutable snapshot and shared preview (provide exactly one per call):
|
|
9
|
+
- **Search/Replace (`edits`)**: literal unique `oldText -> newText` blocks (default Pi contract).
|
|
10
|
+
- **Hashline (`hashlines`)**: content-addressed line edits (`replace` / `delete` / `insert_after` / `insert_before`) anchored by `<line>:<2-hex>` tags from `read(hashlines=true)`, `read(outline=true)`, or `grep(hashlines=true)` (or `"hashlines": true` in `.pi-charset.json`). Accepts `:`/`#`/`L` anchor dialects, safely strips echoed prefixes, returns updated post-edit anchors + line delta so chained edits need zero re-reads, and detects repeated identical no-op edits (`NOOP_LOOP`). Any shifted or altered line fails with `HASH_MISMATCH` reporting deduplicated ±2 context lines and ±25 shift hints so recovery takes one turn.
|
|
11
|
+
- **Apply Patch (`patch`)**: single-file unified diff (`@@ -a,b +c,d @@`), Codex hunk (`@@ [header]` / `*** End of File`), or Aider `<<<<<<< SEARCH / ======= / >>>>>>> REPLACE` blocks (rejects `*** Move to:` explicitly). Multi-file Codex (`*** Begin Patch`, including `*** Hashline File:`), Aider multi-file `SEARCH/REPLACE`, and `diff --git` patches use the dedicated `apply_patch` tool with all-or-nothing pre-flight validation, deadlock-free sorted path locks, TUI diff rendering, atomic batch `autoCommit`, and batch-level `/charset-undo` (reverting an entire multi-file patch in one command while refusing if any file changed since).
|
|
12
|
+
- **Whole File (`wholeFile`)**: full replacement preserving original encoding, BOM, uniform line endings, and `unchanged` no-op detection.
|
|
13
|
+
- Match `oldText` literally against one original snapshot, using the source's uniform line endings. An empty search, a repeated match (including overlapping occurrences), or overlapping replacements reject the entire batch. An empty replacement deletes the match. Replacements cannot refer to text inserted earlier in the batch.
|
|
14
|
+
- There is no fuzzy, indentation, quote, NFKC, or full-width/half-width rewrite. Suggestions are bounded actual source excerpts, never implicit replacements.
|
|
15
|
+
- The original BOM and encoding are preserved; unaffected text is not changed. For uniform LF/CRLF files, replacement line endings adopt that style. Changes to trailing newlines must be explicit. If the file has no newlines, a replacement may introduce one uniform style. Byte-identical changes return `unchanged` without updating mtime.
|
|
16
|
+
- A successful text read records an observed file version for this extension session. Preview and internal I/O do not refresh that observation. A preview reused at execution stays bound to its original bytes, file identity, and effective configuration. A stale read or plan requires a fresh read and fresh call.
|
|
17
|
+
- Edits and writes serialize by local path within the extension process. The edit verifies encoded output before replacement and reads it back afterward. It checks cancellation before replacement; after replacement starts it reports the actual result. It never automatically replays or rolls back a failed verification.
|
|
18
|
+
- A same-directory temporary file and atomic rename give local-file atomic visibility. The last identity/byte checks reduce but cannot eliminate races with unrelated processes. This is not a multi-file transaction, cross-process CAS, or power-loss durability guarantee. Nonstandard ACLs, streams, and network shares are not qualified.
|
|
19
|
+
|
|
20
|
+
## Failure and recovery
|
|
21
|
+
|
|
22
|
+
| Code | What to do |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| `NOT_FOUND`, `AMBIGUOUS_MATCH`, `OVERLAPPING_EDITS`, `INVALID_INPUT` | Re-read and send a unique exact block or independent non-overlapping edits. |
|
|
25
|
+
| `HASH_MISMATCH` | One or more Hashline `<line>:<2-hex>` anchors no longer match the file. Use the actual current `<line>:<hash>\|...` lines reported in the error to retry. |
|
|
26
|
+
| `STALE_READ`, `STALE_PLAN` | Re-read. Review changed content/configuration before making a new call. |
|
|
27
|
+
| `UNENCODABLE`, `UNSUPPORTED_FILE` | Review the source encoding or revise the replacement. Edits that would make a text file classify as binary are rejected before writing. Explicit conversion belongs to `write`. |
|
|
28
|
+
| `AMBIGUOUS_ENCODING` | The bytes round-trip under more than one encoding family and the real one is undecidable. ASCII-only replacements are allowed; for anything else declare `encoding` in `.pi-charset.json`. Nothing was written. |
|
|
29
|
+
| `CANCELLED` | Replacement had not started. |
|
|
30
|
+
| `TEMP_WRITE_FAILED` | The temporary file could not be prepared. No replacement was attempted. Check disk space or write permissions. |
|
|
31
|
+
| `VERIFY_FAILED`, `COMMIT_UNKNOWN` | Re-read the actual file. Do not repeat or roll back blindly. |
|
|
32
|
+
|
|
33
|
+
## Verify a candidate
|
|
34
|
+
|
|
35
|
+
Run `npm ci` and `npm run verify` using Node 22.19+ or Node 24. Use the pinned Pi host (see lockfile); also smoke-test the Pi version you actually use. A successful Linux run is not evidence that the native Windows locking and local path cases passed. Use a disposable Git checkout and the test fixtures before changing a real legacy workspace.
|
|
36
|
+
|
|
37
|
+
Opt-in end-to-end timing under PowerShell:
|
|
38
|
+
|
|
39
|
+
```powershell
|
|
40
|
+
$env:CHARSET_BENCH_OUT = "$PWD/edit-bench.json"
|
|
41
|
+
npx vitest run test/perf/edit-engine.bench.test.ts
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The fixture generates checked edits for UTF-8, GBK, GB18030 and UTF-16LE at roughly 10 KiB, 100 KiB and 1 MiB, with 1, 5 or 20 replacements. Collect baseline and candidate results on the same machine, filesystem, Node and Pi versions; keep byte validation enabled. The first result per case is reported separately (not a fresh process for each case); the report includes raw warm samples and peak RSS for the test process.
|
|
45
|
+
|
|
46
|
+
`CHARSET_BENCH_SIZES` (KiB) and `CHARSET_BENCH_EDITS` replace the default grid, `CHARSET_BENCH_FILTER` selects cases by `encoding:KiB:edits`, and `CHARSET_PHASES_SIZES` does the same for the stage probe. A 10 MiB size is a stress diagnostic, not a budget target. Search timings have their own opt-in probes: `CHARSET_HITS_TIMINGS` (`test/perf/grep-hits.test.ts`), `CHARSET_GREP_TIMINGS`, `CHARSET_TREE_TIMINGS`, `CHARSET_DENSE_TIMINGS` and `CHARSET_LOOKUP_TIMINGS`. `.github/workflows/bench.yml` runs all of them on hosted Ubuntu and Windows runners on demand and uploads the JSON as artifacts.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Editing engine design and reading guide
|
|
2
|
+
|
|
3
|
+
The [original design, transcribed from the Chinese Word document](zh-CN/EDITING-PLAN.md), was written against pi-charset 0.1.4 at `bed85e5367a7f6d502ac993d46571548e9ce4d63`. It preserves the original estimates, proposals, architecture diagram, test scenarios and pinned sources. Read the [implementation and benchmark record](PROGRESS.md) for measured results.
|
|
4
|
+
|
|
5
|
+
| Task | Contract to preserve |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| T01 | Freeze the Pi host, edit parameters, failure states and baseline corpus. |
|
|
8
|
+
| T02 | Resolve all exact replacements against one snapshot. Count overlapping occurrences and reject ambiguous edits. |
|
|
9
|
+
| T03 | Use one edit plan for preview and execution. |
|
|
10
|
+
| T04 | Scope observed versions to the session. Preview must not approve a newer file. |
|
|
11
|
+
| T05 | Serialize writes per file, verify identity and bytes before replacement, then read back. Preserve encoding, BOM and line endings. |
|
|
12
|
+
| T06 | Return bounded diagnostics from actual source, including the failed edit index and commit state. |
|
|
13
|
+
| T07 | Check original bytes after rejection and untouched bytes after success. Exercise Windows file sharing and the supported host matrix. |
|
|
14
|
+
| T08 | Compare matched cold and warm workloads, retain raw measurements, verify packaging and maintain both documentation languages. |
|
|
15
|
+
|
|
16
|
+
Sections 5–8 of the original give the matching, concurrency, encoding and error contracts. Sections 10–12 describe the release gates and separate engine timing from model-assisted task outcomes. Appendix A provides interface sketches, B records the historical probes, and C identifies the source revisions. Raw byte splicing, Hashline, unified diff input, automatic indentation recovery and multi-file transactions require separate evidence and design.
|
package/docs/INSTALL.md
CHANGED
|
@@ -35,7 +35,7 @@ pi update --extensions
|
|
|
35
35
|
pi install git:github.com/ethan-blue/pi-charset
|
|
36
36
|
|
|
37
37
|
# Pin a specific release tag
|
|
38
|
-
pi install git:github.com/ethan-blue/pi-charset@v0.1.
|
|
38
|
+
pi install git:github.com/ethan-blue/pi-charset@v0.1.4 -l
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
When installing from a `git:` source, Pi clones the repository under `.pi/git/github.com/ethan-blue/pi-charset` (or `~/.pi/agent/git/...`) and runs `npm install` automatically.
|
|
@@ -93,7 +93,7 @@ Restart Pi after creating `.pi-charset.json`.
|
|
|
93
93
|
|
|
94
94
|
## 4. Post-Install Verification
|
|
95
95
|
|
|
96
|
-
1. Run `/charset-status` in Pi to confirm `pi-charset v0.1.
|
|
96
|
+
1. Run `/charset-status` in Pi to confirm `pi-charset v0.1.4` and the active mode or `.pi-charset.json` path.
|
|
97
97
|
2. Edit a Chinese comment in a GBK file, then run `/charset-scan` (or `node <PKG_DIR>/tools/scan-encoding.mjs <file>`) and verify the file remains `cjk/GBK`.
|
|
98
98
|
3. Optionally scan for pre-existing damaged files (`U+FFFD` or `锟斤拷`):
|
|
99
99
|
```text
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Model-task evaluation: Pi native `edit` versus pi-charset
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./zh-CN/MODEL-EVAL.md)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Question and design
|
|
8
|
+
|
|
9
|
+
The [editing plan](EDITING-PLAN.md) separates engine timing from model-assisted task outcomes (§11.2) and asks for evidence that strict exact editing does not cost more model rounds than the host's native tools. This evaluation runs the same Pi host, model, prompt and tools against the same corpus, changing only whether the pi-charset extension is loaded.
|
|
10
|
+
|
|
11
|
+
| Element | Value |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Host | Pi `1.8.0` (`--mode json --print`), tools allowlisted to `read,edit,grep,find`; no bash, no `write`, no MCP, no skills, no context files |
|
|
14
|
+
| Model | Zhipu `glm-5.3-flash`, thinking `low` (follow-ups: thinking `medium`; `glm-5.4`) |
|
|
15
|
+
| Arms | `baseline`: no extension. `charset`: `-e src/index.ts` at `81b4ebd`, zero-config (no `.pi-charset.json`) |
|
|
16
|
+
| Corpus | `github.com/Semi77/2026TI_gimbal` at `b163916` — a National Undergraduate Electronic Design Contest gimbal (two-axis F32C brushless motors, encoders, PID, ADC) with Chinese comments, Keil/CCS on Windows. The same tree naturally mixes 25 GBK files with 35 UTF-8 files and one file of mixed damaged bytes. CRLF throughout. Provenance and encoding census: `test/eval/corpus.json`. The corpus is not redistributed. |
|
|
17
|
+
| Variants | `natural` (bytes as cloned), `utf8` (every GBK file transcoded to UTF-8), `gbk` (every UTF-8 file transcoded to GBK), `natural-config` (natural plus a root `.pi-charset.json` declaring GBK with a narrowed candidate list). The damaged file is left untouched in all of them. |
|
|
18
|
+
| Tasks | 20 single-file edits with deterministic expected bytes: constants, macros, a cast, an operator, arguments, Chinese comments (GBK), a rename across three sites, two occurrences of the same text, disambiguation by neighbouring lines, a Chinese directory path and the damaged file. Reference bytes are produced by byte-level splicing, so untouched regions are the original bytes by construction. Frozen in `test/eval/tasks.json`. |
|
|
19
|
+
| Repetition | 3 runs per task per arm per variant: 6 × 20 × 3 = 360 runs. Each run copies the corpus into a fresh directory and starts a new session. |
|
|
20
|
+
| Outcome | `PASS` (bytes equal reference), `MOJIBAKE_*` (U+FFFD or `EF BF BD` present that was not in the original; `*_ACHIEVED` when the requested text is present), `TIMEOUT` (300 s), `UNCHANGED`, `DRIFT`, `DIVERGED`. `intact` means non-target bytes were preserved. Any change to another `.c`/`.h` file is recorded as collateral. |
|
|
21
|
+
|
|
22
|
+
The prompt names the file, states the change in Chinese, and asks for `read` then `edit` with no other modification. Token figures are provider-reported usage summed over assistant messages: `input`, `cacheRead`, `output`, `reasoning`, `total`.
|
|
23
|
+
|
|
24
|
+
## 2. Results
|
|
25
|
+
|
|
26
|
+
Per arm, 60 runs each (`test/eval/results/<variant>-<tool>.jsonl`):
|
|
27
|
+
|
|
28
|
+
| Variant / arm | PASS | Intact | Mojibake | Timeout | Turns | Edit errors | Tokens in | cacheRead | out | reasoning | total | Wall p50 | Wall mean |
|
|
29
|
+
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
|
|
30
|
+
| natural / baseline | 30 | 33 | 24 | 6 | 4.20 | 36 | 6,517 | 16,808 | 3,400 | 3,167 | 26,726 | 4.6 s | 42.8 s |
|
|
31
|
+
| natural / charset | **60** | **60** | 0 | 0 | 3.10 | 3 | 3,282 | 2,747 | 241 | 153 | **6,271** | 4.5 s | **4.7 s** |
|
|
32
|
+
| utf8 / baseline | 57 | 57 | 3 | 0 | 3.07 | 2 | 1,873 | 4,226 | 242 | 153 | 6,341 | 4.2 s | 4.7 s |
|
|
33
|
+
| utf8 / charset | **60** | **60** | 0 | 0 | 3.05 | 1 | 2,126 | 3,834 | 256 | 161 | 6,217 | 4.5 s | 4.8 s |
|
|
34
|
+
| gbk / baseline | 0 | 5 | 54 | 6 | 3.88 | 16 | 4,590 | 12,115 | 2,962 | 2,765 | 19,668 | 4.6 s | 38.0 s |
|
|
35
|
+
| gbk / charset | **60** | **60** | 0 | 0 | 3.07 | 3 | 1,761 | 4,205 | 239 | 156 | **6,206** | 4.6 s | **4.8 s** |
|
|
36
|
+
|
|
37
|
+
Across all 360 runs the native arm passed 87 of 180 and silently corrupted 81 files; pi-charset passed 180 of 180 with no corruption, no timeout and no collateral change. In the native arm the three `utf8`-variant mojibake runs are the damaged file.
|
|
38
|
+
|
|
39
|
+
**Where the native arm fails.** Every edit to a GBK file is wrong: ASCII-only changes (T01, T03, T05, T07, T08) apply at normal cost but replace every Chinese comment in the file with U+FFFD, and the model reports success. Changes that must type Chinese text (T02, T04, T06, T09) cannot match what the model sees: it re-reads, retries and reasons for 47k–164k tokens per run, then either corrupts the file or hits the 300 s limit. Reasoning tokens average 3,167 against 153 — the model thinks twenty times harder about mojibake.
|
|
40
|
+
|
|
41
|
+
**Where the two arms are equal.** On UTF-8 files where both arms pass, pi-charset is not more expensive: natural variant 6,413 vs 6,609 tokens per run (−3.0%), `utf8` variant 6,274 vs 6,515 (−3.7%), with the same number of turns (3.2 vs 3.2, 3.1 vs 3.1). The measured saving therefore comes entirely from avoided rework on non-UTF-8 files.
|
|
42
|
+
|
|
43
|
+
**Medians hide the tail.** On the natural corpus the native arm's median run costs 6,780 tokens against 6,217, and three turns each; its 90th-percentile wall time is 273 s against 5 s. A typical ASCII-only edit of a GBK file (T01, T03, T05, T07, T08) costs the native arm 6,063 tokens and pi-charset 5,724 — the same money, but 0 of 15 native runs preserve the file. The Chinese-comment family (T02, T04, T06, T09) averages 107k tokens and 8.6 turns for the native arm against 5.6k and 3.0 for pi-charset.
|
|
44
|
+
|
|
45
|
+
**The model does not surface the problem.** Of the 81 corrupted native runs, 78 end with the model stating the change is done ("已完成…"). Only 13 of 120 native runs on non-UTF-8 files mention the encoding or garbled text in their final reply, and 7 of those are timeouts.
|
|
46
|
+
|
|
47
|
+
**Diagnostics.** All seven pi-charset edit errors are the two-occurrence task (T16): `[NOT_FOUND; not_applied] Could not exactly locate edits[0] … Actual source lines …`. The model widened `oldText` on the next call and passed every time. The native arm produced 54 edit errors across the same task set.
|
|
48
|
+
|
|
49
|
+
**The damaged file (T10).** `new/SYSTEM/usart/usart.c` is mostly UTF-8 with every `。` truncated to `E3 80 3F` and four GBK lines in the middle. Only GBK round-trips those bytes, so the classifier reports `cjk:GBK` and the model sees mojibake for the UTF-8 portion. The ASCII edit still writes back byte-exactly (3/3 PASS in every variant), while the native arm corrupts it (9/9). pi-charset guarantees byte preservation here, not a correct view; Chinese-text edits on such a file would not match and were not tested.
|
|
50
|
+
|
|
51
|
+
## 3. Follow-ups: thinking level and a stronger model
|
|
52
|
+
|
|
53
|
+
Two more pairs ran on the natural variant only (60 runs each, `test/eval/results/natural-<tool>-<suffix>.jsonl`):
|
|
54
|
+
|
|
55
|
+
| Natural / arm | PASS | Mojibake | Timeout | Unchanged | Turns | Tokens | Reasoning | Wall mean |
|
|
56
|
+
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
|
|
57
|
+
| baseline, glm-5.3-flash, low (main) | 30 | 24 | 6 | 0 | 4.20 | 26,726 | 3,167 | 42.8 s |
|
|
58
|
+
| baseline, glm-5.3-flash, medium | 30 | 24 | 6 | 0 | 4.10 | 22,575 | 3,046 | 41.5 s |
|
|
59
|
+
| baseline, glm-5.4, low | 30 | 23 | 4 | 3 | 3.88 | 20,256 | 3,068 | 47.4 s |
|
|
60
|
+
| charset, glm-5.3-flash, low (main) | 60 | 0 | 0 | 0 | 3.10 | 6,271 | 153 | 4.7 s |
|
|
61
|
+
| charset, glm-5.3-flash, medium | 60 | 0 | 0 | 0 | 3.07 | 6,270 | 155 | 4.9 s |
|
|
62
|
+
| charset, glm-5.4, low | 60 | 0 | 0 | 0 | 3.05 | 6,091 | 157 | 6.1 s |
|
|
63
|
+
| baseline, glm-5.3-flash, low, `.pi-charset.json` = GBK | 30 | 24 | 6 | 0 | 4.07 | 23,910 | 3,119 | 41.0 s |
|
|
64
|
+
| charset, glm-5.3-flash, low, `.pi-charset.json` = GBK | 60 | 0 | 0 | 0 | 3.05 | 6,706 | 152 | 4.8 s |
|
|
65
|
+
|
|
66
|
+
Neither more thinking nor a stronger model changes the native outcome: the tool rewrites the bytes whatever the model decides, and the model still reports success. Reasoning tokens in the native arm stay near 3,000 at every setting — the extra thinking is triggered by mojibake, not by the level. glm-5.4 gave up without writing in three runs (counted as unchanged) but was still wrong on all 15 ASCII-only GBK edits. pi-charset's cost is flat across both dimensions (6,091–6,271 tokens, 153–157 reasoning, three turns). A configured deployment (`.pi-charset.json` with `sourceEncoding: "GBK"` and a narrowed candidate list at the corpus root, `natural-config` variant) reproduces the split exactly: 30/60 against 60/60, because existing files are still classified by their bytes and the declared encoding only governs ASCII and new files.
|
|
67
|
+
|
|
68
|
+
## 4. Interpretation and limits
|
|
69
|
+
|
|
70
|
+
- Zero-config pi-charset is strictly better on this corpus: 100% byte-correct against 48%, 65% fewer tokens overall (77% on the natural corpus), one-sixth of the wall time overall (one-ninth on the natural corpus), and no measurable overhead on UTF-8 files.
|
|
71
|
+
- The native arm's "successes" on GBK files are the dangerous case: the tool and the model both report completion and the file loses its comments.
|
|
72
|
+
- One contest codebase, one model family, Chinese prompts, single-file deterministic edits, three repetitions. Multi-file refactors, compile or test verification and other models are outside this run. Token counts are provider-reported; monetary cost was not computed.
|
|
73
|
+
- Timeouts count as failures; they are the model still working at 300 s, not a tool crash.
|
|
74
|
+
|
|
75
|
+
## 5. Reproduction
|
|
76
|
+
|
|
77
|
+
The harness lives in `test/eval/` and keeps the corpus and generated files under `%TEMP%\charset-eval` (override with `EVAL_WORK`). It needs a global Pi install with a configured provider; `EVAL_MODEL`, `EVAL_THINKING` and `EVAL_TIMEOUT_MS` override the defaults.
|
|
78
|
+
|
|
79
|
+
```powershell
|
|
80
|
+
$work = Join-Path $env:TEMP 'charset-eval'
|
|
81
|
+
New-Item -ItemType Directory -Force -Path "$work/cand" | Out-Null
|
|
82
|
+
git clone https://github.com/Semi77/2026TI_gimbal.git "$work/cand/Semi77_2026TI_gimbal"
|
|
83
|
+
git -C "$work/cand/Semi77_2026TI_gimbal" checkout b163916211596d0185bfd7147ed2b39e57b37454
|
|
84
|
+
node test/eval/build-tasks.cjs # validates uniqueness and writes tasks.json
|
|
85
|
+
node test/eval/build-variants.cjs # natural / utf8 / gbk plus per-variant task files
|
|
86
|
+
foreach ($v in 'natural','utf8','gbk') { foreach ($t in 'baseline','charset') {
|
|
87
|
+
node test/eval/run.cjs $v $t --reps 3 --workers 4
|
|
88
|
+
} }
|
|
89
|
+
node test/eval/report.cjs "$work/results"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Raw records for the 360 main runs and 360 follow-up runs are committed under `test/eval/results/`. Each line holds the outcome, hashes, tool counts, edit-error excerpts, per-message usage sums and wall time for one run.
|
package/docs/PROGRESS.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# Implementation and benchmark record
|
|
2
|
+
|
|
3
|
+
## First-principles performance, simplification, and formal invariants · 2026-12-05
|
|
4
|
+
|
|
5
|
+
Driven by four checks — make hot paths dramatically faster, cut dead/duplicated code, turn every fixed bug into a property test, and prove or refute implicit invariants:
|
|
6
|
+
|
|
7
|
+
- **Compiled zero-allocation DBCS round-trip DFA & encodability bitset (`src/encoding/fast-codec.ts`)**: Derived directly from `iconv-lite`'s `DBCSCodec` tables (falling back to `iconv-lite` on multi-codepoint sequences such as Big5-HKSCS combining marks and rare 4-byte non-GB18030 entries like GBK `U+E7C7`). Exhaustively verified against `iconv-lite` on all 231,168 1-byte and high-lead 2-byte sequences across all 7 CJK codecs and all 655,360 BMP code units (`test/invariants.test.ts`). Also replaces eager 12,000-call `COMMON_HAN` import work with a lazy 2-buffer decode (`src/encoding/common-scripts.ts`), switches `detectLineEndingKind` / `planEdits` to SIMD `indexOf`, and eliminates redundant full-file re-encodes/re-decodes in `loadSnapshot`, `prepareEditOutput`, `encodeForWrite`, and `verifyWritten`.
|
|
8
|
+
- **O(changed) windowed edit diff (`src/edit/tool.ts`)**: For files over 16 KiB, `buildWindowedEditDiff` locates line-aligned windows around `plan.ranges` in one zero-copy `indexOf("\n")` scan (O(1) ring-buffer memory) and runs `generateDiffString` + `generateUnifiedPatch` only on the changed windows. Verified byte-for-byte identical against full-file host diff/patch on 200 seeded random multi-edit plans (`test/invariants.test.ts`).
|
|
9
|
+
- **Zero-re-read + ConHost-free Windows `grep` (`src/grep.ts`)**: Uses ripgrep's own decoded line text when `context=0` and the pass matches the file's classified family, passes `--no-config`, removes `windowsHide: true` (matching Pi's built-in grep; on Windows `CREATE_NO_WINDOW` added ~15 ms of ConHost setup to every `rg` child), and fixes the `stop` AbortSignal listener leak.
|
|
10
|
+
- **Counterexamples found & fixed**:
|
|
11
|
+
1. `incompleteUtf8Tail` (`src/encoding/stream-transcode.ts`) previously accepted invalid UTF-8 lead bytes `0xC0`, `0xC1`, `0xF5..0xFF` and invalid second bytes (`0xE0 0x80`, `0xED 0xA0`), misclassifying GBK streams cut on `0xC0` (`来`/`老`/`类`) as truncated UTF-8; also mid-stream `sampleBytes` cuts inside a multi-byte CJK character turned valid CJK streams into `unknown`. Both fixed and exhaustively proved against RFC 3629.
|
|
12
|
+
2. `inferFromSiblings` (`src/config.ts`) previously concatenated raw 4 KB prefixes across siblings, losing signal after >4 KB ASCII headers and splicing split multi-byte tails across files; replaced with per-buffer non-ASCII slicing (`decideFamilyFromBuffers`).
|
|
13
|
+
3. Removed dead `bomBytes` in `src/resolve.ts` and deduplicated config parsing, adaptive rule synthesis, write-plan rejection literals, symlink errors, and binary DataView reads across `src/config.ts`, `src/resolve.ts`, `src/operations.ts`, `src/encoding/classify.ts`, and `src/encoding/mime.ts`.
|
|
14
|
+
|
|
15
|
+
| Measured workload (Windows 11, Node 24.18.0, Pi 1.4.0) | Before | After | Speed-up / Result |
|
|
16
|
+
| --- | ---: | ---: | --- |
|
|
17
|
+
| 10 MiB UTF-8 edit total / `diff` phase (5 edits) | 415 / ~357 ms | **67.6 / 6.7 ms** | **6.1× total / ~53× diff** |
|
|
18
|
+
| 10 MiB GBK edit total / `encode` / `diff` (5 edits, ICU decode + raw splice) | 879 / ~100 / 409 ms | **132.8 / 23.6 / 9.9 ms** | **6.6× total / ~41× diff** |
|
|
19
|
+
| 10 MiB GB18030 edit total / `encode` (4-byte astral on every line, raw splice) | 808 / ~123 ms | **184.2 / 32.4 ms** | **4.4× total / 3.8× encode** |
|
|
20
|
+
| 1 MiB UTF-8 / GBK / GB18030 / UTF-16LE edit total (5 edits) | 45–96 ms | **13.1 / 18.5 / 23.1 / 13.9 ms** | **3.5–5.0× faster** (`encode`: **0.2–1.7 ms**, `diff`: **0.6–0.8 ms**) |
|
|
21
|
+
| 1 MiB GBK `read` / verified `write` (`io-latency`) | 25 / 100 ms | **9–12 / 29–42 ms** | **~2.5× / ~3× faster** |
|
|
22
|
+
| Zero-config read: 408 KB GBK / ASCII w/ 16 GBK siblings (cold) | 8.0 / 28.0 ms | **5.7 / 13.7 ms** | **1.4× / 2.0× faster** |
|
|
23
|
+
| 7 MB GBK file deep hit, context 5 (cold classifier) | 100 ms | **48.5 ms** | **2.1× faster** |
|
|
24
|
+
| `grep` UTF-8 tree: ASCII literal / Chinese + context=1 | 37.9 / 33.6 ms | **17.0 / 17.0 ms** | **Ties native Pi grep (16.7 / 16.7 ms)** |
|
|
25
|
+
| `grep` GBK tree: Chinese literal / Chinese + context=1 | 34.2 / 35.1 ms | **19.7 / 19.2 ms** | **3.2× faster than native (63 / 59.8 ms, 0 hits)** |
|
|
26
|
+
|
|
27
|
+
- **Commercial 4-mode editing & OMP/Aider/Codex ergonomics (`src/edit/hashline.ts`, `src/edit/patch.ts`, `src/edit/apply-patch.ts`, `src/edit/tool.ts`, `src/grep.ts`)**: Unified Search/Replace, Hashline (`read`/`grep` `<line>:<2-hex>|` tags, `#`/`L` dialects, safe echoed-prefix absorption, ±25-line shift-hint `HASH_MISMATCH` recovery with deduplicated surrounding context, `NOOP_LOOP` guard), Apply Patch (Codex `*** Begin Patch` / `*** Begin Patch ***`, Aider single & multi-file `SEARCH/REPLACE` blocks, and Git unified diff with all-or-nothing pre-flight validation and deadlock-free sorted multi-path locking), and Whole File into one immutable `PlannedText` IR. Verified by `test/edit-modes.test.ts` and `test/invariants.test.ts` (393k `fastEncodeDbcs`, 98k ICU `fastDecodeDbcs`, and `spliceEditedBytes` proofs).
|
|
28
|
+
- **Atomic batch `/charset-undo`, unified cache evidence, async hot paths & multi-line `read(outline=true)` (`src/journal.ts`, `src/encoding/file-stamp.ts`, `src/read-view.ts`, `src/config.ts`, `src/grep.ts`, `src/operations.ts`, `src/shell.ts`, `src/index.ts`)**: Grouped all operations of a multi-file `apply_patch` under one `batchId` so `/charset-undo` (or `/charset-undo b<id>`) pre-validates every file under sorted path locks and reverts the entire batch atomically (restoring move sources before deleting destinations, guarding against external edits and out-of-order writes, and evicting expired batches as atomic units under the 32 MiB cap). Unified all four caches (`classify`, `config`, `siblingInference`, `grep` `LineSource`) on `FileStamp` (`dev`/`ino`/`size`/`mtimeMs`/`ctimeMs`) with one shared `invalidatePathCaches` hook across `write`/`edit`/`apply_patch`/`undo`, moved sibling inference, ripgrep discovery, config lookups in `read`/`/charset-status`, and Windows `chcp` detection onto non-blocking async paths, and reused cold-miss `raw` bytes inside `grep` so each cold hit file is read once. Upgraded `read(outline=true)` with multi-line signature lookahead, block-comment/nested-comment/Python-docstring/Markdown-fence immunity, and broad language coverage while keeping linear O(N) runtime and exact `<line>:<2-hex>|` anchors (`test/undo.test.ts`, `test/token-engine.test.ts`, `test/cache-consistency.test.ts`).
|
|
29
|
+
|
|
30
|
+
**Fourth hosted run** ([47495906387](https://github.com/ethan-blue/pi-charset/actions/runs/47495906387) at `277203f`, concurrent passes; `hosted-<os>-bench-round4.json`). Regex over the 2,048-file tree 39 → 16 ms on Ubuntu and 266 → 123 ms on hosted Windows; the limit-one query 10 → 8 ms on Ubuntu and 81 → 123 ms on Windows, where the two stopped passes now cost their spawn and teardown. Identifier search 6.7 / 47 ms, cold 60-file literal search 288 / 318 ms.
|
|
31
|
+
|
|
32
|
+
## Native tools versus pi-charset, side by side · 2026-12-05
|
|
33
|
+
|
|
34
|
+
`test/perf/grep-native-vs-charset.test.ts` runs Pi's native `grep` and the encoding-aware `grep` on two identical 200-file trees, one UTF-8 and one GBK, with the same four queries; `test/perf/results/windows-native-vs-charset.json` holds every row. Making the encoding passes concurrent is the change measured here: they are independent ripgrep scans, so a query now waits for the slowest pass instead of the sum, and the first pass to fill the limit stops the others.
|
|
35
|
+
|
|
36
|
+
| Query, warm median ms | Tree | Native | Charset, sequential passes | Charset, concurrent passes | Native result | Charset result |
|
|
37
|
+
| --- | --- | ---: | ---: | ---: | --- | --- |
|
|
38
|
+
| ASCII identifier, literal, limit 20 | UTF-8 | 17.6 | 38.2 | 37.9 | 20 hits | 20 hits |
|
|
39
|
+
| Chinese literal, limit 20 | UTF-8 | 15.8 | 31.4 | 31.4 | 20 hits | 20 hits |
|
|
40
|
+
| Han-class regex, limit 20 | UTF-8 | 58.5 | 148.8 | 92.7 | 0 hits | 0 hits |
|
|
41
|
+
| Chinese literal, context 1, limit 5 | UTF-8 | 16.7 | 33.6 | 33.6 | 5 blocks | 5 blocks |
|
|
42
|
+
| ASCII identifier, literal, limit 20 | GBK | 26.7 | 53.0 | 48.8 | 20 hits, **120 U+FFFD** | 20 hits, no U+FFFD |
|
|
43
|
+
| Chinese literal, limit 20 | GBK | 62.0 | 108.9 | 34.2 | **No matches found** | 20 hits |
|
|
44
|
+
| Han-class regex, limit 20 | GBK | 63.5 | 153.1 | 97.5 | 0 hits | 0 hits |
|
|
45
|
+
| Chinese literal, context 1, limit 5 | GBK | 59.2 | 105.9 | 35.1 | **No matches found** | 5 blocks |
|
|
46
|
+
|
|
47
|
+
On a UTF-8 tree both tools return the same lines and the extension costs 15–35 ms more per query for classification and line access, which is below what a person notices. On a GBK tree the native tool is unusable for Chinese, and for ASCII identifiers it returns every Chinese comment as U+FFFD; the extension is correct and, with concurrent passes, faster than the native tool's failed query. The remaining UTF-8-tree gap is the Han-class regex, where the extension always pays for a GB18030 pass that a pure UTF-8 tree never needs: 93 ms against 58 ms on 200 files.
|
|
48
|
+
|
|
49
|
+
## Reliability round · 2026-12-05
|
|
50
|
+
|
|
51
|
+
Prompted by one standard — a single wrong write is unacceptable — and by Aider's way of making edits safe through git rather than through more machinery ([DESIGN-REVIEW.md](DESIGN-REVIEW.md), section 4).
|
|
52
|
+
|
|
53
|
+
**The write that could go wrong silently.** A probe over the five CJK families showed that the candidate order, not the bytes, was deciding the family: a Big5 file, a Shift_JIS file and an EUC-KR file were all classified GBK in zero-config mode and displayed as mojibake (`琌代刚祘`, `偙傟偼僥僗僩`, `捞巴篮 抛胶飘`), because their bytes also round-trip under GBK. Every gate stayed silent: the untouched bytes are preserved, so only the new text would have been encoded as GBK into a Big5, Japanese or Korean file, mixing encodings. The classifier now scores each round-tripping family by decoding an 8 KB sample from the first non-ASCII byte: common and frequent Han characters for the Chinese families (derived at load time from GB2312 Level 1 and the Big5 common rows, plus hand-written top-frequency lists), kana plus common Japanese kanji for Japanese, and frequency-skewed Hangul for Korean, with minimum evidence counts for the script bonuses. A margin below 0.15 marks the bytes `crossFamilyAmbiguous`: `read` shows the best guess with a warning, and `write`/`edit` refuse non-ASCII content with `AMBIGUOUS_ENCODING`; ASCII replacements stay allowed; a declared `encoding` overrides. Sibling inference uses the same decision, so a Big5 tree writes new files as Big5. Seventeen probe cases, including the same sentence in GBK and Big5, Hong Kong Cantonese in both scripts, three-syllable Korean and GBK containing kana, all resolve correctly (`test/family.test.ts`). Cost: 0.2–0.5 ms per classification for five 8 KB sample decodes, which shows only in the cold classifier search (+30 ms over 60 hit files) and leaves the read path unchanged.
|
|
54
|
+
|
|
55
|
+
**Undo, the Aider way.** Every verified `write` and `edit` records the bytes it replaced in a bounded session journal. `/charset-undo` restores the most recent entry, or the one named by `list`, a sequence number or a path; it removes a file the extension created, and refuses when the file changed or disappeared after the write, mirroring Aider's dirty, missing-in-parent and pushed checks. The restored bytes become the session's observed version so the next edit is not stale. `autoCommit: true` adds Aider's commit step: `git add` the file, `git commit -m … -- <file>`, so other staged work stays staged; a failed commit is a note, never a write failure. Both are covered in `test/undo.test.ts`; the command is registered alongside the other three.
|
|
56
|
+
|
|
57
|
+
## Audit and optimization round · 2026-12-05
|
|
58
|
+
|
|
59
|
+
A full pass over the source after `d2da356`, driven by five questions: raise performance, remove unused code, find edge cases, re-examine the design, polish. The design-level conclusions are in [DESIGN-REVIEW.md](DESIGN-REVIEW.md); this section records what changed and what the measurements say.
|
|
60
|
+
|
|
61
|
+
**Where the time was going.** The classifier computed the exhaustive seven-candidate list for every consumer, although only `/charset-init` reads it, and the same bytes were classified a second time under the inferred rule. The sibling scan that infers the encoding for ASCII and new files ran uncached on every such read or write. A pure-ASCII hit line in `grep` was classified and read although ASCII is identical in every supported encoding.
|
|
62
|
+
|
|
63
|
+
| Change | Before | After |
|
|
64
|
+
| --- | ---: | ---: |
|
|
65
|
+
| Read legacy GBK file (408 KB), zero-config, cold caches | 36 ms | 8 ms |
|
|
66
|
+
| Read ASCII file in a directory with 16 GBK siblings, cold caches | 89 ms | 28 ms |
|
|
67
|
+
| Same read again, directory cache hit | 93 ms every time | 1.9 ms |
|
|
68
|
+
| Read plus one edit on the legacy file, cold caches | 125 ms | 36 ms |
|
|
69
|
+
| Identifier search, ASCII hit lines in 60 GBK files, cold classifier | 293 ms | 44 ms (ripgrep's own scan) |
|
|
70
|
+
|
|
71
|
+
Mechanism: `classifyBuffer` gained `candidateOrder` and a WeakMap verdict memo; `inferAdaptiveRule` classifies narrowest-first with an early stop and records its verdict for the read and write plans to reuse; `inferFromSiblings` tests one candidate at a time across all legacy siblings, narrowest first, which yields the same common encoding as the exhaustive list, and is cached per directory behind a size-and-mtime signature of the selected siblings. `grep` trusts an ASCII-only line from ripgrep without touching the file. Raw samples: `test/perf/results/windows-read-zero-config.json` and the `round2` block of `windows-grep-hits.json`; reproduce with `CHARSET_READ_TIMINGS` / `CHARSET_HITS_TIMINGS`.
|
|
72
|
+
|
|
73
|
+
**Bugs the audit found.** In zero-config mode the second classification under the rule's UTF-8 preference relabelled undecodable bytes as `config/undecidable`, so (a) the UNKNOWN notice never appeared on read and (b) `write` overwrote them as UTF-8 although Gate 3 promises a refusal. Reusing the first verdict fixes both; `test/zero-config.test.ts` now covers the notice, the edit refusal and the write refusal. Also fixed: the hard-link refusal on `write` is reported before the replacement instead of wrapped in a generic write failure, and a file named `..notes` no longer loses its relative path in grep output.
|
|
74
|
+
|
|
75
|
+
**Behaviour change.** A hit on a pure-ASCII line is now shown even when the file's encoding cannot be determined, because the line is exact regardless; non-ASCII lines in such files stay hidden and `context` falls back to the match line alone. Binary files are unaffected because ripgrep emits no matches for them.
|
|
76
|
+
|
|
77
|
+
**Removed.** `verdictForBuffer` (also lacked the cache's limited-entry rule), `planBomBytes`, `detectLineEnding`, `detectLineEndingFromText`, `buildEncodingGroups`, `globDirPrefix`. `sysnote.ts` now traverses asynchronously instead of blocking the host loop at session start.
|
|
78
|
+
|
|
79
|
+
## Candidate acceptance · 2026-12-03
|
|
80
|
+
|
|
81
|
+
The baseline is `bed85e5` (v0.1.4). The implementation starts at local commit `202fc73` (v0.1.5-rc.1), and the acceptance fixes are committed as `8f9e98e`.
|
|
82
|
+
|
|
83
|
+
| Task | Evidence |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| T01 host and contract | Lockfile host and baseline are pinned. The compatibility suite asserts the active Pi version and loads the registered extension. |
|
|
86
|
+
| T02–T03 planning and preview | The shared planner resolves unique non-overlapping ranges in the original snapshot. Preview and execution tests cover stale plans and changing arguments. |
|
|
87
|
+
| T04–T06 observation, commit and diagnostics | Session baselines, identity checks and the atomic replacement path have conflict and fault-injection tests. Added byte-level rejection tests for edits that would classify as binary, and a budget check for JSON-escaped diagnostic excerpts. The edit contract documents recovery codes. |
|
|
88
|
+
| T07 correctness and integration | Windows 11 / Node 24.18.0 passed `npm run verify` on Pi 0.84.0, 1.4.0, 1.7.0 and 1.8.0 (the global install); 354 passing and six skipped per host at `ab27a68`. The native sharing-lock test ran. Skips were two POSIX cases and four opt-in benchmarks. [Hosted CI](https://github.com/ethan-blue/pi-charset/actions/runs/47492178717) on `ab27a68` passed all seven jobs: `ubuntu-latest` with 354 passing and six skipped per job on Node 22 and 24 across Pi 0.84.0, 1.4.0 and 1.7.0, executing the POSIX mode and symlink cases; `windows-latest` with 354 passing and six skipped per job on Node 22 and 24 across Pi 1.4.0 and 1.7.0. Added grep checks for both UTF-16 BOM byte orders and line numbering with bare CR. |
|
|
89
|
+
| T08 performance and packaging | Relative links are checked against the pack list. An actual tarball installed offline in a clean directory exposed all three charset commands through Pi 1.4.0 RPC. Mock GitHub CLI runs exercised the stable and prerelease flags on both create and edit paths. The paired model-task evaluation is recorded in [MODEL-EVAL.md](MODEL-EVAL.md). |
|
|
90
|
+
|
|
91
|
+
The paired model-task evaluation ran 720 headless Pi sessions on a real Chinese contest codebase whose tree mixes GBK and UTF-8 ([MODEL-EVAL.md](MODEL-EVAL.md)): 360 with `glm-5.3-flash` across three corpus variants, and 360 follow-ups on thinking level, `glm-5.4` and a configured `.pi-charset.json`. In the main 360 the native arm passed 87 of 180 runs and silently corrupted 81 files; pi-charset passed 180 of 180 with 65% fewer tokens, no measurable overhead on UTF-8 files, and no collateral change. The follow-ups reproduce the same split at every setting. The owner's own production corpus was not exercised; the contest corpus stands in for it. The candidate has no remote release tag and the owner has decided not to publish it. Raw byte splicing, Hashline, patch input and multi-file transactions remain outside this candidate's scope.
|
|
92
|
+
|
|
93
|
+
### Repeatable edit timing
|
|
94
|
+
|
|
95
|
+
The same byte-checked benchmark ran against v0.1.4 and the candidate in baseline, candidate, candidate, baseline order on Windows 11 with Node 24.18.0, Pi 1.4.0 and local NTFS fixtures. Each of the 36 cases had 60 warm samples per version and separate first observations with uncontrolled OS cache. Across the first sweep, 35 cases met the historical +20% p95 budget. UTF-16LE at 10 KiB with 20 edits measured 12.15 ms before and 14.61 ms after (+20.28%). A focused repeat with 240 warm samples per version measured 11.00 and 12.19 ms (+10.81%). Keep the checks and record both observations.
|
|
96
|
+
|
|
97
|
+
The repository file `test/perf/results/windows-edit-acceptance.json` preserves all four runs, the focused repeat and 12 candidate phase profiles. At 1 MiB with five edits, diff generation had the largest median phase in all four tested codecs. The phase probe includes snapshot I/O in decode and validation in commit. It does not isolate CPU cost from OS I/O. Use the [benchmark command](EDIT-ENGINE.md#verify-a-candidate) with `CHARSET_BENCH_RUNS=32` for each full run. The focused repeat uses `CHARSET_BENCH_FILTER=^UTF-16LE:10:20$` and `CHARSET_BENCH_RUNS=122`.
|
|
98
|
+
|
|
99
|
+
For the baseline runs, extract `git archive bed85e5` to a scratch directory, use the same installed lockfile dependencies as the candidate, and copy only `test/perf/edit-engine.bench.test.ts` into the baseline. The harness imports each checkout's own registered tool.
|
|
100
|
+
|
|
101
|
+
### Search per-hit access
|
|
102
|
+
|
|
103
|
+
A search used to decode every file with a hit in full and to classify it with the exhaustive candidate list that only `/charset-init` needs. On Windows 11 with Node 24.18.0, the first search over 60 GBK files of 236 KB took 985 ms, of which ripgrep accounted for 51 ms and classification for about 750 ms (seven candidate round-trips per file). Two changes: hit files are now classified with `exhaustive: false`, which stops at the first lossless candidate, and lines come from a per-file reader that decodes only the requested line range for files over 64 KB, switching to one whole-file decode after 64 requests so dense context output does not regress. `runRgPass` also carries only the partial last line of each chunk instead of re-slicing the accumulated buffer. The unused `buildEncodingGroups` and `globDirPrefix` helpers were removed.
|
|
104
|
+
|
|
105
|
+
| Workload (median ms) | Before `05675c0` | After | Speed-up |
|
|
106
|
+
| --- | ---: | ---: | ---: |
|
|
107
|
+
| 60 files, literal, context 0, cold classifier | 985 | 271 | 3.6× |
|
|
108
|
+
| 60 files, regex, context 3, cold classifier | 885 | 272 | 3.3× |
|
|
109
|
+
| 60 files, literal, context 0, warm classifier | 249 | 104 | 2.4× |
|
|
110
|
+
| 60 files, regex, context 0, warm classifier | 193 | 122 | 1.6× |
|
|
111
|
+
| 7 MB file, one deep hit, context 5 | 146 | 100 | 1.5× |
|
|
112
|
+
| Dense probe: 3 files × 96 hits, limit 289, context 64 | 48.5 | 49.7 | — |
|
|
113
|
+
|
|
114
|
+
The remaining cold cost is one decode-and-encode round-trip per hit file, which is the price of the exact round-trip guarantee that `read` and `edit` rely on. Output is byte-identical: the dense, Chinese-path, bare-CR and UTF-16 BOM regressions are unchanged. Raw samples: `test/perf/results/windows-grep-hits.json`; reproduce with `CHARSET_HITS_TIMINGS=<json path>` and `npx --no-install vitest run test/perf/grep-hits.test.ts`.
|
|
115
|
+
|
|
116
|
+
### 10 MiB stress diagnostic
|
|
117
|
+
|
|
118
|
+
The plan lists 10 MiB as a diagnostic, not a target. With `CHARSET_BENCH_SIZES=10240` on Windows 11 / Node 24.18.0 / Pi 1.4.0, every cell was byte-exact with zero failures: UTF-8 p50 415 ms (1 edit) and 461 ms (20 edits), GBK 879 / 903 ms, GB18030 808 / 849 ms, UTF-16LE 266 / 284 ms. The phase probe attributes the superlinear growth to the host's `generateDiffString`, which runs a Myers diff over the whole file before pi-charset truncates the display: at 10 MiB it takes 357–409 ms in the legacy codecs against 15–34 ms at 1 MiB, and the native host `edit` pays the same cost. pi-charset's own decode and encode phases grow about 12× per 10× size (`test/perf/results/windows-stress-10mib.json`). Windowing the diff around the planned ranges is the remaining avenue for very large files; it was not needed to meet the 1 MiB budget.
|
|
119
|
+
|
|
120
|
+
### Write path consistency
|
|
121
|
+
|
|
122
|
+
`atomicReplace` now refuses a destination with more than one hard link, as the edit path already did through `assertEditableFile`. A temp-file rename would have given the written path a fresh inode and silently left the other names on the old content. Both `write` and `edit` reject it with a reason and leave every name intact; `test/regressions.test.ts` covers `write` on both platforms.
|
|
123
|
+
|
|
124
|
+
### Hosted timing runs
|
|
125
|
+
|
|
126
|
+
`.github/workflows/bench.yml` runs every timing probe on `ubuntu-latest` and `windows-latest` on demand (`workflow_dispatch`, with `os`, `filter` and `runs` inputs). Run 47376712153 on `6c6f1a0` used 4-vCPU runners with Node 24.22.3 and ripgrep 15.1.0 / 16.0.0. The 36-scenario edit benchmark followed the baseline/candidate/candidate/baseline order against `bed85e5` with 32 runs per cell (60 warm samples per side). Runner timing is a cross-check of the local Windows numbers, not a latency guarantee.
|
|
127
|
+
|
|
128
|
+
| 1 MiB p50 ms, before → after | Ubuntu | Hosted Windows |
|
|
129
|
+
| --- | ---: | ---: |
|
|
130
|
+
| UTF-8, 1 / 5 / 20 edits | 53→42, 80→42, 176→45 | 78→64, 100→65, 193→69 |
|
|
131
|
+
| GBK, 1 / 5 / 20 edits | 132→68, 153→70, 260→77 | 166→92, 176→93, 276→97 |
|
|
132
|
+
| GB18030, 1 / 5 / 20 edits | 145→71, 162→72, 271→75 | 174→95, 182→96, 276→98 |
|
|
133
|
+
| UTF-16LE, 1 / 5 / 20 edits | 39→22, 52→23, 108→27 | 61→43, 73→47, 128→47 |
|
|
134
|
+
|
|
135
|
+
Both runners: zero failures on both sides, 34 of 36 cells within the +20% p95 budget, peak RSS equal or lower (Ubuntu 568→540 MiB, Windows 499→473 MiB for the second run of each side). The two cells over budget were 10 KiB operations whose medians improved. A focused retest (run 47379722842, 122 runs per cell, 240 warm samples per side) brought all three Windows cells inside the budget (+8.0%, −38.7%, −25.9%). On Ubuntu the medians stayed equal or better (UTF-8 1.98 vs 2.04 ms, GBK 2.40 vs 2.99, GB18030 2.23 vs 3.14) while two p95 tails remained 1.4 ms and 2.9 ms higher on operations of 2–3 ms; the stage probe shows commit-phase spikes of 40–50 ms landing on both sides of the shared disk, and the candidate issues a few more `lstat`/`fstat` calls per edit for the snapshot and guard. Both runs are kept: `test/perf/results/hosted-<os>-bench.json` and `hosted-<os>-retest.json`.
|
|
136
|
+
|
|
137
|
+
Search probes on the same run. Ubuntu: first search over the 60-file GBK set 207–210 ms against 44–54 ms warm (the cold classification cost is 4–5× on Linux too), deep hit in a 7 MB file 141 ms, dense context 5–25 ms, wrong-pass regex 35 ms first / 17 ms warm, 2,048-file tree literal 14 / 12 ms and regex 35 / 36 ms, repository samples grep 17.5 / 5.7 ms, read 3.6 ms, edit 6.1 ms. Hosted Windows: 262–300 ms cold against 99–140 ms warm, deep hit 170 ms, dense 45–74 ms, tree literal 74 / 73 ms, regex 225 / 218 ms. Linux is the fast regression environment the plan named; the Windows numbers track the local Altior figures within runner noise.
|
|
138
|
+
|
|
139
|
+
**Second hosted run** ([47458909915](https://github.com/ethan-blue/pi-charset/actions/runs/47458909915) at `aa5c30b`, after the audit round; raw samples in `test/perf/results/hosted-<os>-bench-round2.json`). The edit benchmark now shows 0 of 36 cells over the +20% p95 budget on both runners, with zero failures: the verdict reuse in the snapshot removed the extra candidate round-trips that produced the earlier 10 KiB tails. GBK at 1 MiB with 20 edits: 308 → 91 ms on Ubuntu, 344 → 115 ms on hosted Windows. Read probe on Ubuntu: legacy file 12.9 ms cold, ASCII among 16 GBK siblings 28.9 ms cold and 0.75 ms with the directory cache, read plus one edit 52 ms; hosted Windows 14.8 / 38.3 / 1.8 / 60 ms. Identifier search over the 60 GBK files, cold classifier: 11 ms on Ubuntu and 58 ms on Windows, which is ripgrep's scan. The limit-one regex query over the 2,048-file tree runs one rg child: 10 ms on Ubuntu and 81 ms on Windows, against roughly 380–400 ms with three children in the first run.
|
|
140
|
+
|
|
141
|
+
**Third hosted run** ([47492422939](https://github.com/ethan-blue/pi-charset/actions/runs/47492422939) at `ab27a68`, after the reliability round; `hosted-<os>-bench-round3.json`). The family decision adds five 8 KB sample decodes per hit file and nothing to the edit path: GBK at 1 MiB with 20 edits 244 → 74 ms on Ubuntu and 271 → 97 ms on hosted Windows, 0 of 36 cells over budget on Ubuntu and 1 on Windows (`GB18030:100:1` +25%, a cell that was −26% in the focused retest of round 1). Read probe cold 11 ms with the directory cache at 0.3 / 1.4 ms; identifier search 7 ms on Ubuntu and 46 ms on Windows; cold 60-file literal search 246 / 318 ms against 258 / 358 ms in round 2, so the extra decodes are inside runner noise.
|
|
142
|
+
|
|
143
|
+
## Dense grep handoff · 2026-12-02
|
|
144
|
+
|
|
145
|
+
The registered grep test generates three Chinese-named C files, 96 adjacent matching lines each, CRLF with no final newline, in UTF-8, GBK and GB18030. Six (limit, context) pairs cover (1,1), (95,0), (96,1), (97,2), (289,0), (289,64). It compares the complete tool response and truncation metadata against independently rendered blocks, including overlapping context, paths, order and line numbers. The existing byte-split regression remains in the suite.
|
|
146
|
+
|
|
147
|
+
At context 64, 288 hits expanded to 867,795 UTF-8 bytes and the host returned 51,171 bytes of that text. The formatter now joins at most the 51,200-byte budget plus the first overflowing record, and continues counting the full output for metadata. This bounds the joined text. Peak process memory was not measured.
|
|
148
|
+
|
|
149
|
+
`test/perf/results/windows-dense-search.json` contains two baseline runs (a1/a2) and two modified runs (b1/b2), six sweeps each on Pi 1.4.0. Sample zero is the first sweep in a fresh test process with uncontrolled OS cache. The first high-context observations were 52.51/51.79 ms before and 53.93/52.34 after. For the five warm sweeps, per-run median total time was 47.28/47.98 ms before and 52.29/51.27 after. Child lifetime was 33.71/34.83 → 34.70/34.83 ms, stdout callbacks 9.80/9.58 → 10.27/10.08 ms and post-close work 8.88/9.74 → 10.88/11.13 ms. Child and callback spans overlap. With context zero, modified total was 45.13/43.25 ms and post-close 3.91/4.06 ms. High-context warm runs made five fixture reads over three files. Read time includes I/O; probing and decoding were not separately timed.
|
|
150
|
+
|
|
151
|
+
Run from the repository root to regenerate the fixture and timings:
|
|
152
|
+
|
|
153
|
+
```powershell
|
|
154
|
+
$env:CHARSET_DENSE_TIMINGS = Join-Path $env:TEMP 'dense-search.json'
|
|
155
|
+
npx --no-install vitest run test/host-integration.test.ts -t "checks dense grep"
|
|
156
|
+
Remove-Item Env:CHARSET_DENSE_TIMINGS
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Windows verify passed on Pi 0.84.0, 1.4.0 and 1.7.0 with 318 passed and six skipped per host. The final joined-string size assertion also passed in the working copy. Future performance work should profile byte counting after overflow if representative workloads show a latency issue, retaining exact metadata. Production samples and paid model comparisons remain pending authorization.
|
|
160
|
+
|
|
161
|
+
## Local handoff · 2026-12-02
|
|
162
|
+
|
|
163
|
+
Start with [the historical design](EDITING-PLAN.md), then read the measured results below. The final 0.1.5-rc.1 working-tree source passed the full Windows gate on Pi 0.84.0, 1.4.0 and 1.7.0 separately. Each host passed type checking, 316 tests (six skipped), and package verification covering 25 Markdown files. The suite checks the installed host version against PI_HOST_VERSION. Timings below were measured on Pi 1.4.0.
|
|
164
|
+
|
|
165
|
+
The registered grep UTF-8 boundary regression feeds real rg JSON stdout to the existing stream decoder one byte at a time, including every byte of the Chinese filename and line text. It requires the exact output `控制.c:2: 控制 NEEDLE`. Run `npx --no-install vitest run test/host-integration.test.ts -t "keeps Chinese grep"`. This test-only follow-up passed on Windows Pi 1.4.0 (317 passed, six skipped); the three-host counts above precede this additional assertion.
|
|
166
|
+
|
|
167
|
+
1. Run `git status --short --branch` and `git diff --check`. Include any new implementation and test files when copying a working-tree candidate.
|
|
168
|
+
2. For correctness, run `npm run verify`. To reproduce the host matrix on Altior with its populated npm cache, run the PowerShell block below from the repository root. It installs only inside a fresh local temporary copy.
|
|
169
|
+
3. For search timings, use the workload-specific commands below. The tests synthesize their own fixtures. Raw millisecond samples for eight runs are in `test/perf/results/windows-search.json`: lookup is the 256-file workload, tree is the 2,048-file lifecycle comparison (a = before, b = after), and content is the paired rg replay. In each series the first element is the first observation.
|
|
170
|
+
4. Ordinary literal search, filename lookup, verified result limits, child termination and the low-hit multi-pass regex investigation are closed. Reopen only on a reproducible correctness failure or representative high-hit/context-heavy measurements showing substantial extension-side work. Production samples and paid model comparisons remain outstanding.
|
|
171
|
+
|
|
172
|
+
```powershell
|
|
173
|
+
$root = (Get-Location).Path
|
|
174
|
+
$copy = New-Item -ItemType Directory -Path (Join-Path $env:TEMP ("pi-charset-" + [guid]::NewGuid()))
|
|
175
|
+
git ls-files --cached --others --exclude-standard -- . ':(exclude).alma-snapshots/**' | ForEach-Object {
|
|
176
|
+
if (Test-Path -LiteralPath $_ -PathType Leaf) {
|
|
177
|
+
$target = Join-Path $copy.FullName $_
|
|
178
|
+
[IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($target)) | Out-Null
|
|
179
|
+
[IO.File]::Copy((Join-Path $root $_), $target)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
Push-Location $copy.FullName
|
|
183
|
+
$priorHost = $env:PI_HOST_VERSION
|
|
184
|
+
try {
|
|
185
|
+
npm ci --offline --no-audit --no-fund
|
|
186
|
+
if ($LASTEXITCODE) { throw "npm ci failed" }
|
|
187
|
+
foreach ($v in '1.4.0','0.84.0','1.7.0') {
|
|
188
|
+
if ($v -ne '1.4.0') {
|
|
189
|
+
npm install --offline --no-audit --no-fund --no-save --package-lock=false "@earendil-works/pi-ai@$v" "@earendil-works/pi-tui@$v" "@earendil-works/pi-coding-agent@$v"
|
|
190
|
+
if ($LASTEXITCODE) { throw "install failed for $v" }
|
|
191
|
+
}
|
|
192
|
+
$env:PI_HOST_VERSION = $v
|
|
193
|
+
npm run verify
|
|
194
|
+
if ($LASTEXITCODE) { throw "verify failed for $v" }
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
$env:PI_HOST_VERSION = $priorHost
|
|
198
|
+
Pop-Location
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Editing engine
|
|
203
|
+
|
|
204
|
+
Candidate 0.1.5-rc.1 passed local Windows verification with Pi 0.84.0, 1.4.0 and 1.7.0, each with 312 passing and four skipped tests before the grep change. Native sharing-lock and synthetic GBK/CRLF cases passed. Offline Pi 1.7.0 loaded the extension from the working tree. All 36 edit scenarios met the +20% p95 budget in a baseline/candidate/candidate/baseline comparison (60 warm samples per version per scenario). The largest increase was 12.27 to 12.97 ms. Production samples and paid model comparisons remain pending.
|
|
205
|
+
|
|
206
|
+
After the grep change, the working tree passed type checking, 313 tests (four skipped), and the release check covering 25 Markdown files and package contents.
|
|
207
|
+
|
|
208
|
+
## Search
|
|
209
|
+
|
|
210
|
+
Pi registers `grep` through `createEncodingGrepDefinition`. It discovers ripgrep, applies configured encoding passes, validates each hit against the classified file, and formats context and limits. An unavailable ripgrep or search path delegates to Pi's built-in grep. File-name lookup uses the host's existing tools.
|
|
211
|
+
|
|
212
|
+
The measured change concerns regex hits from a mismatched decoding pass. They are always rejected. Checking regex mode before loading source lines eliminates an entire file read, decode and split on the first such hit per file. Literal verification, file classification and subsequent encoding passes still run as before.
|
|
213
|
+
|
|
214
|
+
| Windows run | First query (ms) | Warm p50 (ms) | Warm p95 (ms) | Warm min–max (ms) |
|
|
215
|
+
| --- | ---: | ---: | ---: | ---: |
|
|
216
|
+
| Before | 425.9 | 364.5 | 378.5 | 351.7–378.5 |
|
|
217
|
+
| After | 116.5 | 81.1 | 96.8 | 76.4–96.8 |
|
|
218
|
+
| After, repeat | 120.0 | 82.1 | 99.6 | 77.9–99.6 |
|
|
219
|
+
|
|
220
|
+
Node 24.18.0, one machine. Each process generated 32 UTF-8 files of 90,000 CRLF filler lines plus one marker, and one GBK file with a real hit. The query deliberately produces wrong-pass hits in UTF-8 files. The first query clears extension caches; OS disk caches are uncontrolled. Each row includes 15 subsequent queries. Nearest-rank p95 is the maximum with this sample size. Timing covers the registered tool's execute method, including rg startup and output formatting. Ordinary single-pass and filename-search workloads were not timed.
|
|
221
|
+
|
|
222
|
+
To reproduce, set `CHARSET_GREP_TIMINGS` to a fresh output JSON path and run `npx --no-install vitest run test/perf/grep-mismatched-pass.test.ts`. Element zero is the first query. Remaining elements are warm timings in milliseconds. Without the variable, the test uses a small fixture and checks exact context, line numbers, the match limit and GBK bytes.
|
|
223
|
+
|
|
224
|
+
<details>
|
|
225
|
+
<summary>Raw query timings (ms)</summary>
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{"before":[425.88,378.46,376.62,358.51,355.17,370.2,363.7,359.76,356.72,369.15,364.53,378.37,351.67,353.49,371.49,365.76],"after":[116.5,79.98,78.58,76.8,76.35,79.04,79.75,81.77,78.98,81.6,96.76,81.06,85.32,88.16,91.26,89.57],"after2":[119.98,80.68,99.58,78.74,80.4,82.14,77.87,80.14,80.26,82.44,82.08,84.92,87.99,99.02,87.07,81.64]}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
</details>
|
|
232
|
+
|
|
233
|
+
## Search limits and ordinary lookups
|
|
234
|
+
|
|
235
|
+
In a GBK fixture, the second byte of 丂 (81 40 hex) resembles an ASCII @. Two such lines preceded real @ characters on lines 3 and 4. The old registered grep returned no match at limit 1. The fixed path validates and deduplicates streamed hits before counting them, stops rg at the accepted limit, and retains decoded lines for at most one file at a time. Regression checks cover limits 1 and 2, CRLF context, bytes, and sorted distinct results across GBK, UTF-8 and ASCII. Windows Pi 1.4.0 verification passed with 314 tests and five skipped; the optional timing test also passed separately.
|
|
236
|
+
|
|
237
|
+
On the same Windows host, 256 synthetic CRLF files (half GBK and half UTF-8) contained one ASCII literal hit and one matching filename. Each of two runs issued one first query and 20 warm queries per tool, alternating extension grep and Pi find. The tools returned the expected path and grep line 2 on every call. The OS filesystem cache was uncontrolled. First-call costs include tool discovery as applicable. Warm quantiles use nearest rank.
|
|
238
|
+
|
|
239
|
+
| Tool | First calls (ms) | Warm p50 (ms) | Warm p95 (ms) |
|
|
240
|
+
| --- | --- | --- | --- |
|
|
241
|
+
| Extension grep, literal NEEDLE | 88.4 / 93.9 | 86.6 / 88.0 | 97.1 / 108.8 |
|
|
242
|
+
| Pi find, needle-*.c | 189.4 / 28.1 | 24.6 / 24.0 | 28.6 / 27.3 |
|
|
243
|
+
|
|
244
|
+
```powershell
|
|
245
|
+
$env:CHARSET_LOOKUP_TIMINGS = Join-Path $env:TEMP "pi-charset-lookup.json"
|
|
246
|
+
npx --no-install vitest run test/host-integration.test.ts -t "measures literal"
|
|
247
|
+
Remove-Item Env:CHARSET_LOOKUP_TIMINGS
|
|
248
|
+
npx --no-install vitest run test/host-integration.test.ts -t "counts only verified"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Large directory tree and process completion
|
|
252
|
+
|
|
253
|
+
On Altior (Windows, Node 24.18.0, Pi 1.4.0), 2,048 synthetic CRLF files were split equally between GBK and UTF-8 in 32 modules three directories deep. One extra ignored file matched both queries. Every search returned exactly the visible target; grep also verified line 2. Each of four fresh test processes ran one first and ten warm queries per tool. The OS cache was uncontrolled.
|
|
254
|
+
|
|
255
|
+
Before the fix, both limit-one regression runs returned after signalling rg but before its close event (0 of 1 closed). After the fix, both returned with 1 of 1 closed. The extension ignores remaining stdout after reaching the verified limit and resolves on close. The previous GBK limit regression still passes. Windows verification: 315 passed, six skipped. The opt-in benchmark passed separately.
|
|
256
|
+
|
|
257
|
+
| Warm median in ms | Before, two runs | After, two runs |
|
|
258
|
+
| --- | --- | --- |
|
|
259
|
+
| Extension literal grep | 152.60 / 154.96 | 151.02 / 153.10 |
|
|
260
|
+
| Host filename find | 26.74 / 28.62 | 27.45 / 27.94 |
|
|
261
|
+
|
|
262
|
+
After the fix, first queries took 164.86 / 153.07 ms for grep and 31.64 / 29.09 ms for find. Warm maxima were 171.01 / 177.66 ms and 30.20 / 29.99 ms respectively. The full-tree query has one visible match and uses the default limit; these timings describe ordinary lookup, not the latency of stopping at the limit.
|
|
263
|
+
|
|
264
|
+
Independent post-fix warm median probes (two runs, ms): uncached rg discovery 0.23 / 0.20, rg --version 8.57 / 8.22, rg --files 18.74 / 19.77, read/decode/split of the tiny GBK target 0.97 / 0.89, host find entry to fd spawn event 4.93 / 5.21, fd --version 12.30 / 12.09. Version probes include process startup and exit. Listing includes traversal and capturing paths. These overlapping probes cannot be added or subtracted to attribute the full search. No stable ordinary-query speedup was established.
|
|
265
|
+
|
|
266
|
+
```powershell
|
|
267
|
+
$env:CHARSET_TREE_TIMINGS = Join-Path $env:TEMP "pi-charset-tree.json"
|
|
268
|
+
npx --no-install vitest run test/perf/search-tree.test.ts
|
|
269
|
+
Remove-Item Env:CHARSET_TREE_TIMINGS
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Paired content-search timing
|
|
273
|
+
|
|
274
|
+
The large-tree benchmark above now captures argv from each actual registered grep child and immediately replays the same executable and arguments against the same fixture. Two independent Windows processes each issued 11 queries per mode. The table gives the two warm medians in milliseconds after dropping the first pair. Each replay ran to completion. Registration, process observation and raw JSON capture are test-only.
|
|
275
|
+
|
|
276
|
+
| Query | Registered grep | Child spawn event to close, per pass | Direct replay, per pass | Synchronous stdout callbacks |
|
|
277
|
+
| --- | --- | --- | --- | --- |
|
|
278
|
+
| ASCII literal | 153.85 / 155.17 | 148.61 / 149.73 | 139.71 / 140.72 | 2.51 / 2.69 |
|
|
279
|
+
| Regex | 466.91 / 467.47 | 151+144+150 / 151+149+155 | 144+139+139 / 139+141+144 | 0.79 / 0.83 |
|
|
280
|
+
| Regex, limit one | 407.16 / 397.53 | 147+146+99 / 149+149+98 | 141+142+136 / 141+141+139 | 2.05 / 2.39 |
|
|
281
|
+
|
|
282
|
+
ASCII literals used one UTF-8 pass. Configured regex ran UTF-8, BIG5 and GB18030 in that order. Each pass produced one raw candidate; only the last pass matched the GBK file's classified encoding. A limit of one stopped that pass after validation. The ignored target stayed out. (Update 2026-12-05: since the ASCII-line fast path the target line is trusted in the first pass. With sequential passes that made the limit-one query a single rg child at 71 ms; since passes now run concurrently all three start, the first fill stops the other two, and the query takes about 117 ms on the same machine. The default-limit regex over the same tree dropped from 463 to 271 ms.) Callback spans include stream parsing and candidate validation and overlap child lifetime. The isolated tiny-file read/decode/split medians were 0.93 / 0.91 ms; cache-hit classification was not isolated from other callback work. OS caches were uncontrolled and replay always followed the registered query.
|
|
283
|
+
|
|
284
|
+
Most elapsed time was inside rg content scans on this tree. The measurements do not justify another change to the matcher or decoded-file cache. Reopen this investigation if a representative synthetic workload shows callback time dominates, for example with many legitimate matches requiring context. The same PowerShell command above reproduces the new measurements. Windows verification passed 316 tests with six skipped, including checks for invalid rg syntax, expired caller deadline, accepted-hit limits and child close.
|
|
285
|
+
|
|
286
|
+
## Formatter memory follow-up
|
|
287
|
+
|
|
288
|
+
Windows, Node 24.18.0 and Pi 1.4.0. The probe executes the formatter extracted from the pinned baseline or working copy with decoded synthetic rows and the installed host truncation code. It omits search and decoding. Each size used eight fresh processes in ABBA ABBA order with one pre-measurement GC. The two variants produced identical content and metadata digests. Run from the repository root:
|
|
289
|
+
|
|
290
|
+
```powershell
|
|
291
|
+
node test/perf/grep-format-memory.mjs
|
|
292
|
+
node --expose-gc test/perf/grep-format-memory.mjs bounded heavy profile
|
|
293
|
+
python -X utf8 test/perf/rg-memory-win.py
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Medians below compare original / bounded. Three files with 96 hits each and context 64 took 5.8 / 7.2 ms. Joined bytes were 867,795 / 51,207. Neither exceeded the process's earlier RSS high-water mark at the median. With 384 hits per file and context 128, elapsed time was 71.0 / 66.7 ms, joined bytes 9,089,699 / 51,230, and increases in process RSS high-water mark 67.01 / 30.97 MiB. Heap-used increases sampled at the join were 8.40 / 7.18 MiB and 50.70 / 2.40 MiB respectively. Heap, external and array-buffer values are point samples subject to GC. External allocation changes cannot be attributed to formatting. Separate standalone rg passes reported observed working-set peaks of 7.55–8.04 MiB across both sizes.
|
|
297
|
+
|
|
298
|
+
The CPU sample attributed 129 ticks to anonymous frames and 13 to appendLine, including possible JIT inlining. It cannot isolate the previous end-to-end latency difference. Keep the bounded implementation. Revisit if repeated representative profiles isolate an actionable cost. Windows verify passed 318 tests, six skipped. `test/perf/results/windows-format-memory.json`, `test/perf/results/windows-format-profile.json`, `test/perf/results/windows-rg-memory.json`.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
## Repository sample acceptance
|
|
302
|
+
|
|
303
|
+
The registered tools processed byte copies of three current working files: src/version.ts, src/grep.ts and docs/CONFIG-GUIDE.md. An independent line scan checked exact literal grep output with zero and one context line, including order, duplicate matches and exclusion of a matching .ignore decoy. A Markdown heading matched on line one. Native Pi find returned exactly the two expected TypeScript paths (membership checked without requiring host traversal order). Read matched normalized text. An isolated comment edit produced the expected bytes, repeating the obsolete edit failed without changing bytes, and the reverse edit restored the original. All three source files compared byte-for-byte equal after testing.
|
|
304
|
+
|
|
305
|
+
Altior Windows, Pi 1.4.0, one targeted run in ms: grep 52.73, context grep 34.62, native find 23.88, Markdown grep 27.14, read 6.66, edit 16.20. These sequential observations do not establish a speed comparison. Full verify passed 319 tests, six skipped, including the synthetic mixed-encoding C regressions. Git listed no tracked C files. Production C and model evaluation remain outside this acceptance.
|
|
306
|
+
|
|
307
|
+
```powershell
|
|
308
|
+
$env:CHARSET_SELF_TIMINGS='1'
|
|
309
|
+
npx --no-install vitest run test/host-integration.test.ts -t 'isolated repository samples'
|
|
310
|
+
Remove-Item Env:CHARSET_SELF_TIMINGS
|
|
311
|
+
```
|
package/docs/RELEASING.md
CHANGED
|
@@ -20,7 +20,7 @@ Every release enforces strict synchronization across five artifacts via `npm run
|
|
|
20
20
|
4. [`CHANGELOG.md`](../CHANGELOG.md) (`## [<version>] - YYYY-MM-DD`)
|
|
21
21
|
5. [`CHANGELOG.zh-CN.md`](../CHANGELOG.zh-CN.md) (`## [<version>] - YYYY-MM-DD`)
|
|
22
22
|
|
|
23
|
-
`npm run check:release` also validates Pi package manifest fields
|
|
23
|
+
`npm run check:release` also validates Pi package manifest fields, relative Markdown links in the checkout and npm tarball, and the `npm pack --dry-run` tarball file list.
|
|
24
24
|
|
|
25
25
|
## Step-by-Step Release Process
|
|
26
26
|
|
|
@@ -57,4 +57,6 @@ git push origin main --follow-tags
|
|
|
57
57
|
Pushing a `v*.*.*` tag triggers `.github/workflows/release.yml`:
|
|
58
58
|
1. **Cross-Platform Verification (`verify`)**: Runs `npm ci`, `node tools/check-release.mjs --tag vX.Y.Z`, `npm run typecheck`, and `npm test` on Ubuntu and Windows.
|
|
59
59
|
2. **GitHub Release (`github-release`)**: Extracts the matching section from `CHANGELOG.md`, builds the `.tgz` package via `npm pack`, and publishes a GitHub Release with the tarball attached.
|
|
60
|
-
3. **Optional npm Registry Publish (`npm-publish`)**:
|
|
60
|
+
3. **Optional npm Registry Publish (`npm-publish`)**: Publishes with provenance via GitHub OIDC Trusted Publishing when `ENABLE_NPM_PUBLISH` is `true`.
|
|
61
|
+
|
|
62
|
+
Tags with a SemVer prerelease suffix (such as `v0.1.5-rc.1`) are marked as prereleases on GitHub and use the `next` dist-tag on npm. Stable releases use `latest`.
|