pi-charset 0.1.5 → 0.1.7
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 +32 -0
- package/CHANGELOG.zh-CN.md +32 -0
- package/README.md +3 -0
- package/README.zh-CN.md +3 -0
- package/dist/config.js +943 -0
- package/dist/edit/apply-patch-core.js +274 -0
- package/dist/edit/diagnostics.js +46 -0
- package/dist/edit/hashline.js +400 -0
- package/dist/edit/patch.js +634 -0
- package/dist/edit/paths.js +48 -0
- package/dist/edit/plan.js +90 -0
- package/dist/encoding/classify.js +430 -0
- package/dist/encoding/common-scripts.js +58 -0
- package/dist/encoding/converter.js +311 -0
- package/dist/encoding/fast-codec.js +476 -0
- package/dist/encoding/file-stamp.js +32 -0
- package/dist/encoding/line-endings.js +118 -0
- package/dist/encoding/mime.js +88 -0
- package/dist/encoding/stream-transcode.js +287 -0
- package/dist/grep-core.js +730 -0
- package/dist/journal.js +494 -0
- package/dist/maintenance.js +333 -0
- package/dist/mcp/server.js +866 -0
- package/dist/notify.js +60 -0
- package/dist/operations.js +1021 -0
- package/dist/path-key.js +10 -0
- package/dist/read-view.js +927 -0
- package/dist/resolve.js +325 -0
- package/dist/version.js +2 -0
- package/docs/MCP-AND-MULTI-AGENT.md +119 -0
- package/docs/zh-CN/MCP-AND-MULTI-AGENT.md +119 -0
- package/package.json +18 -4
- package/schema/pi-charset.schema.json +6 -0
- package/src/config.ts +82 -6
- package/src/edit/apply-patch-core.ts +304 -0
- package/src/edit/apply-patch.ts +11 -321
- package/src/edit/diagnostics.ts +5 -2
- package/src/edit/paths.ts +42 -0
- package/src/edit/tool.ts +2 -39
- package/src/encoding/classify.ts +13 -1
- package/src/encoding/converter.ts +3 -1
- package/src/grep-core.ts +729 -0
- package/src/grep.ts +21 -714
- package/src/index.ts +8 -5
- package/src/journal.ts +167 -42
- package/src/mcp/server.ts +923 -0
- package/src/operations.ts +198 -67
- package/src/read-view.ts +111 -8
- package/src/resolve.ts +1 -0
- package/src/shell-guard.ts +38 -1
- package/src/version.ts +1 -1
- package/tools/charset-core.mjs +13 -2
- package/tools/pi-charset-cli.mjs +548 -114
- package/tools/pi-charset-mcp.mjs +140 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,38 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [Unreleased]
|
|
11
|
+
|
|
12
|
+
## [0.1.7] - 2026-12-06
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **P0 — Compiled ESM delivery (`dist/`) for installed `node_modules/` packages**: Compile all Pi-independent core + MCP + CLI modules into standard Node ESM under `dist/` (`tsconfig.build.json`, `tools/build.mjs`) and mark Pi peer dependencies as optional in `peerDependenciesMeta`, eliminating `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` after `npm install pi-charset` / `npx -p pi-charset pi-charset-mcp` and cutting standalone install footprint from ~131 packages to direct runtime dependencies only. Added an automated isolated `node_modules/pi-charset/` tarball install + stdio MCP handshake + GBK read/edit/write smoke gate to `tools/check-release.mjs`.
|
|
17
|
+
- **P1 — Zero-side-effect `dryRun: true` undo & strict boolean validation**: `undoWrite(..., { dryRun: true })` and `charset_fix(action="undo", dryRun=true)` now perform read-only verification without modifying disk, consuming journal entries, or mutating baselines; non-boolean safety flags (e.g. `dryRun: "true"`) are rejected with `[INVALID_INPUT; not_applied]`.
|
|
18
|
+
- **P1 — Pre-write NUL guard & Gate 2 before `autoCommit`**: `encodeForWrite` now rejects NUL-bearing content before touching disk (shared across `write` and `apply_patch add`), and `writeEncodedLocked` / `apply_patch add` now verify Gate 2 BEFORE calling `autoCommit` so unverified or tampered writes never enter Git history.
|
|
19
|
+
- **P1 — Safe Git `autoCommit` pathspecs & index preservation**: All Git mutations in `src/journal.ts` now pass `--literal-pathspecs` (preventing bracket filenames like `motor[1].c` from glob-matching `motor1.c`), skip `autoCommit` safely when a target file already has user-staged changes (preserving partial staging), and snapshot/restore exact index stage entries on commit/hook failure without affecting other staged work.
|
|
20
|
+
- **P1 — True Git staged-blob checking, Chinese/special paths & `core.hooksPath`**: Rebuilt `tools/pi-charset-cli.mjs` directly on the compiled shared core (`dist/`, eliminating CLI/core classifier drift). `pi-charset check --staged` now reads actual index stage-0 blobs via `git diff --cached --raw -z` + `git cat-file blob` (honoring `.gitattributes` `text`/`eol`/`working-tree-encoding` and non-ASCII/Chinese filenames without quoting or trimming bugs), and `pi-charset install-hook` now resolves active `core.hooksPath` before falling back to `--git-common-dir`.
|
|
21
|
+
- **P1 — Shell guard infinite-loop fix**: Handled single `<` input redirections, here-strings (`<<<`), fd redirections (`0<`), and process substitutions (`<(...)` / `>(...)`, inspecting nested commands) with an unbreakable loop-progress invariant in `src/shell-guard.ts`, and short-circuited `shellGuard: "off"` before parsing.
|
|
22
|
+
- **P1 — `apply_patch` Move source re-verification before unlink**: Re-checks source file `lstat` identity and exact bytes immediately prior to unlinking so external modifications landing during the move window are preserved rather than deleted.
|
|
23
|
+
- **P2 — Gate 2 known-encoding verification, strict output budgets, Pi `read` `outputSchema`, `grep` error propagation & EUC-KR coverage, MCP JSON-RPC hardening**: Stopped `verifyWritten` from re-guessing UTF-8 against known GBK targets (eliminating false failures on GBK `"漏"` `c2 a9`); enforced strict byte budgets even on 1 MiB single-line files across MCP `charset_read` and Pi/MCP `ranges`; aligned Pi `read` `structuredContent` with Pi 1.4.0's `readOutputSchema`; propagated ripgrep syntax/execution failures explicitly (`status: "failed"` / `isError: true` / thrown error) and fixed zero-config ASCII/regex search across `EUC-KR`/`Big5`/`Shift_JIS`/`EUC-JP`; added JSON-RPC 2.0 envelope validation, per-request error isolation, `notifications/cancelled` aborts, bounded request queue, and clean stdout backpressure drain on EOF.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Add request-level `expectedVersion` optimistic concurrency on `charset_write` / `charset_edit` (safe across multiple logical agents sharing one MCP instance) and machine-readable `structuredContent` (`applied`, `verified`, `committed`, `undoId`, `version`, `encoding`, `bom`, `eol`, `bytesOnDisk`) across MCP tools.
|
|
28
|
+
- Add `pi-charset --version`, `pi-charset doctor`, `pi-charset explain <file>`, `mcp-config --help` / `--client cursor|windsurf` / `--local`, and strict CLI option validation.
|
|
29
|
+
|
|
30
|
+
## [0.1.6] - 2026-12-06
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- Add same-core zero-dependency stdio MCP server (`src/mcp/server.ts`, `tools/pi-charset-mcp.mjs`, `bin.pi-charset-mcp`) exposing `charset_read`, `charset_write`, `charset_edit`, `charset_apply_patch`, `charset_grep`, `charset_check`, and `charset_fix` so Codex, Antigravity, Claude Code, and Cursor run on the exact same Pi-independent core (`src/grep-core.ts`, `src/edit/paths.ts`, `src/edit/apply-patch-core.ts`) with **zero `.pi-charset.json` files required** (supports pure zero-config mode plus optional CLI flags `--encoding`/`--eol`/`--prefer-legacy`/`--hashlines`/`--auto-commit` and `PI_CHARSET_*` env vars, MCP `initialize.instructions`, `resources/list` & `prompts/list` probes, JSON-RPC batch arrays, `EPIPE` safe exit, and defensive LLM `file_path`/JSON-string argument coercion).
|
|
35
|
+
- Add opt-in `preferSourceOverUtf8` config/override option (and JSON Schema + CLI parity) to prevent tiny BOM-less GBK headers whose bytes accidentally satisfy UTF-8 grammar from being hijacked as UTF-8.
|
|
36
|
+
- Add `pi-charset install-hook [--strict-eol] [--force]` (worktree-safe Git `pre-commit` gate installer) and `pi-charset mcp-config [--client codex|antigravity|claude|generic]` to `tools/pi-charset-cli.mjs`, plus bilingual multi-agent guide (`docs/MCP-AND-MULTI-AGENT.md` / `docs/zh-CN/MCP-AND-MULTI-AGENT.md`).
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- Fix `tools/charset-core.mjs` to honor an explicitly declared multi-byte `sourceEncoding` directly when it round-trips losslessly (matching `src/encoding/classify.ts` and preventing short GBK comments from being misclassified as `EUC-KR` by `pi-charset check`).
|
|
41
|
+
|
|
10
42
|
## [0.1.5] - 2026-12-06
|
|
11
43
|
|
|
12
44
|
### Changed
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -6,6 +6,38 @@
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
## [0.1.7] - 2026-12-06
|
|
12
|
+
|
|
13
|
+
### 修复
|
|
14
|
+
|
|
15
|
+
- **P0 — 发布编译后纯标准 ESM 核心产物(`dist/`)解决 `node_modules` 安装后 MCP 启动阻断**:新增 `tsconfig.build.json` 与 `tools/build.mjs` 将全部 Pi 无关核心、MCP 与 CLI 依赖编译为标准 Node ESM(`dist/`),并在 `package.json` 的 `peerDependenciesMeta` 中将 Pi peer 依赖标记为可选,彻底消除标准 npm 安装后的 `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` 并将独立安装体积由 ~131 包缩减为仅含直接运行依赖;同时在 `tools/check-release.mjs` 新增「真实 `.tgz` 解包至隔离 `node_modules/pi-charset/`(零 Pi 依赖)→ 真实 stdio MCP 握手 → GBK/CRLF 读写改逐字节断言」发布门禁。
|
|
16
|
+
- **P1 — 修复 `dryRun: true` 撤销实际改盘与布尔参数容错隐患**:为 `undoWrite` 与 `charset_fix(action="undo", dryRun=true)` 补齐只读预览路径,保证零磁盘改动、不消费 journal 且不修改基线;对 `dryRun`/`bom`/`outline`/`hashlines` 等布尔参数改为严格类型校验,拒绝把 `"true"` 静默当作 `false`。
|
|
17
|
+
- **P1 — 修复 `write` 写前 NUL 预检缺失与 `autoCommit` 先于 Gate 2 执行**:在 `encodeForWrite` 中统一前置拦截会产生二进制 NUL 的写入(覆盖 `write` 与 `apply_patch add`),并将 `writeEncodedLocked` 与 `apply_patch add` 改为 Gate 2 验证通过后才允许执行 `autoCommit`,彻底杜绝未校验或遭篡改字节进入 Git 历史。
|
|
18
|
+
- **P1 — 修复 `autoCommit` 方括号路径通配误提交与失败时破坏部分暂存**:`src/journal.ts` 全部涉及路径的 Git 命令统一使用 `--literal-pathspecs`(修复 `motor[1].c` 误带入 `motor1.c`);写前检测目标文件若已有用户部分暂存改动则跳过自动提交以保护原暂存区,并在提交或钩子失败时按 `ls-files --stage` 快照精确恢复暂存条目而不影响其它已暂存文件。
|
|
19
|
+
- **P1 — 修复 CLI `--staged` 读工作树、中文路径漏检、`core.hooksPath` 忽略与分类器漂移**:重构 `tools/pi-charset-cli.mjs` 直接复用 `dist/` 同源核心;`check --staged` 改为 `git diff --cached --raw -z` + `git cat-file blob` 校验真实暂存区 stage-0 快照(完整支持中文及特殊文件名,并感知 `.gitattributes` 的 `text`/`eol`/`working-tree-encoding`);`install-hook` 优先解析 `core.hooksPath` 再回退 `--git-common-dir`。
|
|
20
|
+
- **P1 — 修复 `shell-guard.ts` 遇到单 `<` 输入重定向死循环**:补齐 `<`、`0<`、`<>`、`<<<` 与 `<(...)`/`>(...)` 进程替换解析(并递归检查进程替换内的命令)与不可破坏的循环推进不变量,`shellGuard: "off"` 提前短路返回。
|
|
21
|
+
- **P1 — 修复 `apply_patch` Move 删源前并发窗口**:在删除源文件前再次复核 `lstat` 文件身份与精确字节,若移动窗口内源文件遭外部修改则保留外部版本并报告部分完成状态与可撤回批次号。
|
|
22
|
+
- **P2 — 全面修复已知目标编码 Gate 2 误报、超长首行预算绕过、Pi `read` `outputSchema` 不匹配、`grep` 失败掩盖与 EUC-KR 漏搜、MCP JSON-RPC 韧性与 EOF 排空**:`verifyWritten` 在目标编码已知时不再重猜 UTF-8(消除 GBK `"漏"` `c2 a9` 误报);统一 `sliceLinesBounded` 与 `formatLineRanges` 严格预算使 1 MiB 单行不再突破 50 KB 上限;对齐 Pi 1.4.0 `readOutputSchema`;显式传播 ripgrep 语法/执行错误并补齐零配置对 `EUC-KR`/`Big5`/`Shift_JIS`/`EUC-JP` 的正则与词搜索;为 MCP 补齐 JSON-RPC 2.0 信封校验、单请求异常隔离、`notifications/cancelled` 取消、有界请求队列与 EOF 输出排空。
|
|
23
|
+
|
|
24
|
+
### 新增
|
|
25
|
+
|
|
26
|
+
- 为 `charset_write` 与 `charset_edit` 增加请求级 `expectedVersion` 乐观并发版本锁(多 Agent 共享单 MCP 实例时防过期覆盖),并为 MCP 工具补齐机器可读 `structuredContent`(`applied`、`verified`、`committed`、`undoId`、`version`、`encoding`、`bom`、`eol`、`bytesOnDisk`)。
|
|
27
|
+
- 新增 `pi-charset --version`、`pi-charset doctor`、`pi-charset explain <file>`、`mcp-config --help` / `--client cursor|windsurf` / `--local` 与严格的 CLI 参数校验。
|
|
28
|
+
|
|
29
|
+
## [0.1.6] - 2026-12-06
|
|
30
|
+
|
|
31
|
+
### 新增
|
|
32
|
+
|
|
33
|
+
- 新增同源零依赖 Stdio MCP 服务(`src/mcp/server.ts`、`tools/pi-charset-mcp.mjs`、`bin.pi-charset-mcp`),对外暴露 `charset_read`、`charset_write`、`charset_edit`、`charset_apply_patch`、`charset_grep`、`charset_check` 与 `charset_fix`,让 Codex、Antigravity、Claude Code 与 Cursor **无需安装 Pi 也无需仓库内放 `.pi-charset.json`** 即可直连同一套确定性内核(支持纯零配置自适应及可选命令行参数 `--encoding`/`--eol`/`--prefer-legacy`/`--hashlines`/`--auto-commit` 与 `PI_CHARSET_*` 环境变量,并补齐 MCP `initialize.instructions`、`resources/list`/`prompts/list` 探测、JSON-RPC 批处理、`EPIPE` 优雅退出与 `file_path`/JSON 字符串参数容错)。
|
|
34
|
+
- 新增可选配置项 `preferSourceOverUtf8`(支持根配置、目录 override、JSON Schema 与 CLI 门禁),防止仅含寥寥几个汉字的无 BOM 极短 GBK 头文件因字节偶发符合 UTF-8 语法而被误判锁定为 UTF-8。
|
|
35
|
+
- 在 `tools/pi-charset-cli.mjs` 新增 `pi-charset install-hook [--strict-eol] [--force]`(兼容 `git worktree` 的 `pre-commit` 编码质检钩子一键安装)与 `pi-charset mcp-config [--client codex|antigravity|claude|generic]`,并新增中英文多工具协同文档(`docs/MCP-AND-MULTI-AGENT.md` / `docs/zh-CN/MCP-AND-MULTI-AGENT.md`)。
|
|
36
|
+
|
|
37
|
+
### 修复
|
|
38
|
+
|
|
39
|
+
- 修复 `tools/charset-core.mjs` 在显式指定多字节 `sourceEncoding` 且无损回环时仍走跨家族启发式导致极短 GBK 注释被 `pi-charset check` 误判为 `EUC-KR` 的问题(与 `src/encoding/classify.ts` 保持完全一致)。
|
|
40
|
+
|
|
9
41
|
## [0.1.5] - 2026-12-06
|
|
10
42
|
|
|
11
43
|
### 变更
|
package/README.md
CHANGED
|
@@ -148,6 +148,8 @@ Run in CI or Git pre-commit hooks (uses the same `.pi-charset.json` rules, plus
|
|
|
148
148
|
|
|
149
149
|
```bash
|
|
150
150
|
npx pi-charset check --staged --strict-eol # Fail CI/pre-commit on damaged bytes, mixed EOL, or encoding drift
|
|
151
|
+
npx pi-charset install-hook --strict-eol # Install managed Git pre-commit gate (worktree-safe)
|
|
152
|
+
npx pi-charset mcp-config # Print Codex / Antigravity / Claude Code MCP config for pi-charset-mcp
|
|
151
153
|
npx pi-charset hints # Show .editorconfig / .gitattributes / pom.xml / CMakeLists.txt hints
|
|
152
154
|
```
|
|
153
155
|
|
|
@@ -166,6 +168,7 @@ Atomic replacement avoids partially written files, but it is not a cross-process
|
|
|
166
168
|
|
|
167
169
|
- [Installation Guide](./docs/INSTALL.md)
|
|
168
170
|
- [Configuration Guide](./docs/CONFIG-GUIDE.md)
|
|
171
|
+
- [Multi-Agent & Same-Core MCP Guide](./docs/MCP-AND-MULTI-AGENT.md)
|
|
169
172
|
- [Host Compatibility Matrix](./docs/COMPATIBILITY.md)
|
|
170
173
|
- [Acceptance & Test Matrix](./docs/ACCEPTANCE.md)
|
|
171
174
|
- [Release Guide](./docs/RELEASING.md)
|
package/README.zh-CN.md
CHANGED
|
@@ -148,6 +148,8 @@ node tools/scan-encoding.mjs /path/to/project --init
|
|
|
148
148
|
|
|
149
149
|
```bash
|
|
150
150
|
npx pi-charset check --staged --strict-eol # 拦截损坏字节、混合换行或编码漂移
|
|
151
|
+
npx pi-charset install-hook --strict-eol # 一键安装 Git pre-commit 编码质检钩子(自动兼容 git worktree)
|
|
152
|
+
npx pi-charset mcp-config # 输出 Codex / Antigravity / Claude Code 的 pi-charset-mcp 配置
|
|
151
153
|
npx pi-charset hints # 读取 .editorconfig / .gitattributes / pom.xml / CMakeLists.txt 线索
|
|
152
154
|
```
|
|
153
155
|
|
|
@@ -166,6 +168,7 @@ npx pi-charset hints # 读取 .editorconfig / .gita
|
|
|
166
168
|
|
|
167
169
|
- [安装说明](./docs/zh-CN/INSTALL.md)
|
|
168
170
|
- [配置指南](./docs/zh-CN/CONFIG-GUIDE.md)
|
|
171
|
+
- [多工具协同与同源 MCP 指南](./docs/zh-CN/MCP-AND-MULTI-AGENT.md)
|
|
169
172
|
- [宿主兼容矩阵](./docs/zh-CN/COMPATIBILITY.md)
|
|
170
173
|
- [验收与测试矩阵](./docs/zh-CN/ACCEPTANCE.md)
|
|
171
174
|
- [发布规范](./docs/zh-CN/RELEASING.md)
|