pi-charset 0.1.6 → 0.1.8

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/CHANGELOG.zh-CN.md +28 -0
  3. package/dist/config.js +943 -0
  4. package/dist/diagnostics/incidents.js +436 -0
  5. package/dist/edit/apply-patch-core.js +274 -0
  6. package/dist/edit/diagnostics.js +73 -0
  7. package/dist/edit/hashline.js +400 -0
  8. package/dist/edit/patch.js +634 -0
  9. package/dist/edit/paths.js +48 -0
  10. package/dist/edit/plan.js +90 -0
  11. package/dist/encoding/classify.js +430 -0
  12. package/dist/encoding/common-scripts.js +58 -0
  13. package/dist/encoding/converter.js +311 -0
  14. package/dist/encoding/fast-codec.js +476 -0
  15. package/dist/encoding/file-stamp.js +32 -0
  16. package/dist/encoding/line-endings.js +118 -0
  17. package/dist/encoding/mime.js +88 -0
  18. package/dist/encoding/stream-transcode.js +287 -0
  19. package/dist/faults.js +67 -0
  20. package/dist/grep-core.js +730 -0
  21. package/dist/journal.js +494 -0
  22. package/dist/maintenance.js +333 -0
  23. package/dist/mcp/server.js +959 -0
  24. package/dist/notify.js +60 -0
  25. package/dist/operations.js +1155 -0
  26. package/dist/path-key.js +10 -0
  27. package/dist/read-view.js +927 -0
  28. package/dist/resolve.js +325 -0
  29. package/dist/setup/adapters.js +524 -0
  30. package/dist/version.js +2 -0
  31. package/docs/MCP-AND-MULTI-AGENT.md +43 -20
  32. package/docs/zh-CN/MCP-AND-MULTI-AGENT.md +43 -20
  33. package/package.json +14 -2
  34. package/src/diagnostics/incidents.ts +474 -0
  35. package/src/edit/apply-patch-core.ts +32 -3
  36. package/src/edit/diagnostics.ts +31 -0
  37. package/src/faults.ts +165 -0
  38. package/src/grep-core.ts +50 -8
  39. package/src/grep.ts +9 -1
  40. package/src/index.ts +8 -5
  41. package/src/journal.ts +167 -42
  42. package/src/mcp/server.ts +597 -179
  43. package/src/operations.ts +370 -100
  44. package/src/read-view.ts +111 -8
  45. package/src/setup/adapters.ts +613 -0
  46. package/src/shell-guard.ts +38 -1
  47. package/src/version.ts +1 -1
  48. package/tools/pi-charset-cli.mjs +664 -168
  49. package/tools/pi-charset-mcp.mjs +81 -42
package/CHANGELOG.md CHANGED
@@ -9,6 +9,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.1.8] - 2026-12-06
13
+
14
+ ### Added
15
+
16
+ - **Unified Typed Fault Contract (`src/faults.ts`)**: Replaced ad-hoc string errors across core I/O (`src/operations.ts`), edit/patch diagnostics (`src/edit/diagnostics.ts`), and MCP (`src/mcp/server.ts`) with typed `CharsetFault` / `FaultMetadata` (`code`, `category`, `phase`, `outcome`, `retryable`, `actionHint`) and a consistent machine-readable MCP error envelope (`status: "failed"`, `error`, `applied`, `verified`, `committed`, `outcome`, `actionHint`) on every failure branch.
17
+ - **Privacy-First Local Incident Recorder (`src/diagnostics/incidents.ts`) & `pi-charset feedback`**: Integrated a zero-network, bounded, allowlist-only local diagnostic recorder (never records source code, paths, raw exception strings, prompts, or secrets; ignores expected operational rejections; deduplicates across independent OS processes with daily slot caps, 14-day retention pruning, fingerprint tamper verification, and safe fallback on filesystems without hard-link support; disable via `PI_CHARSET_DIAGNOSTICS=0`). Added `pi-charset feedback list | preview <fp> | issue-url <fp> | prune | clear`.
18
+ - **Host Adapter Registry & One-Command `pi-charset setup` (`src/setup/adapters.ts`)**: Added idempotent, atomic, non-destructive setup, `--dry-run`, `--uninstall`, and `--rollback` for Codex (`~/.codex/config.toml`), Antigravity (`~/.gemini/config/mcp_config.json`), Claude Code, and Cursor using permanent absolute `node` + `pi-charset-mcp.mjs` entrypoints (preserving all third-party MCP servers and refusing to overwrite invalid JSON), paired with an isolated temp-dir synthetic GBK+CRLF `read`/`edit`/`undo` smoke test.
19
+ - **Upgraded `pi-charset doctor --json` / `--fix` & Selective AGY `_meta`**: `doctor --json` now reports Node compatibility, live MCP smoke verification, honest per-client status (`not_installed` / `unregistered` / `registered` / `handshake_verified` / `degraded`), Git hook enforcement, and local diagnostics state; `doctor --fix` repairs only broken `pi-charset`-owned MCP entries. Added selective `_meta: { "antigravity/alwaysLoad": true }` to the 3 high-frequency core MCP tools (`charset_read`, `charset_edit`, `charset_grep`).
20
+ - **Cross-Process & Windows Path Hardening Tests**: Added independent multi-OS-process `pi-charset-mcp` concurrency tests (`expectedVersion` across separate processes), complex Chinese/space/parenthesis/bracket path tests, full privacy/dedup/retention tests, and isolated `HOME` adapter setup/rollback tests (`test/diagnostics-incidents.test.ts`, `test/setup-adapters.test.ts`, `test/cross-process-and-faults.test.ts`).
21
+
22
+ ## [0.1.7] - 2026-12-06
23
+
24
+ ### Fixed
25
+
26
+ - **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`.
27
+ - **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]`.
28
+ - **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.
29
+ - **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.
30
+ - **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`.
31
+ - **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.
32
+ - **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.
33
+ - **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.
34
+
35
+ ### Added
36
+
37
+ - 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.
38
+ - Add `pi-charset --version`, `pi-charset doctor`, `pi-charset explain <file>`, `mcp-config --help` / `--client cursor|windsurf` / `--local`, and strict CLI option validation.
39
+
12
40
  ## [0.1.6] - 2026-12-06
13
41
 
14
42
  ### Added
@@ -8,6 +8,34 @@
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.1.8] - 2026-12-06
12
+
13
+ ### 新增
14
+
15
+ - **统一类型化故障契约(`src/faults.ts`)**:在核心 I/O(`src/operations.ts`)、编辑诊断(`src/edit/diagnostics.ts`)与 MCP 服务(`src/mcp/server.ts`)全链路落地 `CharsetFault` / `FaultMetadata`(`code`、`category`、`phase`、`outcome`、`retryable`、`actionHint`),确保所有失败分支均返回稳定结构化错误信封(`status: "failed"`、`error`、`applied`、`verified`、`committed`、`outcome`、`actionHint`),彻底消除从人类文本反推错误码。
16
+ - **隐私优先本地诊断记录器(`src/diagnostics/incidents.ts`)与 `pi-charset feedback`**:集成零联网、有界内存与磁盘配额的纯白名单本地故障记录器(严禁记录源码、路径、原始异常文本、提示词或凭据;自动忽略正常安全拒绝;支持独立 OS 进程跨进程去重、每日槽位上限、14 天留存清理、篡改指纹校验及无 hardlink 文件系统安全回退;设 `PI_CHARSET_DIAGNOSTICS=0` 可彻底关闭),并在 CLI 新增 `pi-charset feedback list | preview <指纹> | issue-url <指纹> | prune | clear`。
17
+ - **Host Adapter Registry 与真正的一键 `pi-charset setup`(`src/setup/adapters.ts`)**:为 Codex(`~/.codex/config.toml`)、Antigravity(`~/.gemini/config/mcp_config.json`)、Claude Code 与 Cursor 提供幂等、原子、无损的 `setup` / `--dry-run` / `--uninstall` / `--rollback`,写入永久绝对路径的 `node` + `pi-charset-mcp.mjs` 入口(完整保留第三方 MCP 配置,遇非法 JSON 拒绝覆盖),并在隔离临时目录执行合成 GBK+CRLF `read`/`edit`/`undo` 端到端自检。
18
+ - **升级 `pi-charset doctor --json` / `--fix` 与 AGY 选择性 `_meta`**:`doctor --json` 输出稳定的机器可读诊断状态(严格区分 `not_installed` / `unregistered` / `registered` / `handshake_verified` / `degraded` 与真实防护边界);`doctor --fix` 仅安全修复 `pi-charset` 自有失效条目,绝不触碰用户源码或自定义钩子;在 3 个高频核心 MCP 工具(`charset_read`、`charset_edit`、`charset_grep`)上选择性标记 `_meta: { "antigravity/alwaysLoad": true }`。
19
+ - **独立多进程并发与全套硬化回归测试**:新增双独立 OS 进程 `pi-charset-mcp` 并发 `expectedVersion` 验证、中文/空格/括号/方括号复杂路径测试、隐私与跨进程去重测试以及隔离 `HOME` 安装/回滚/卸载测试(`test/diagnostics-incidents.test.ts`、`test/setup-adapters.test.ts`、`test/cross-process-and-faults.test.ts`)。
20
+
21
+ ## [0.1.7] - 2026-12-06
22
+
23
+ ### 修复
24
+
25
+ - **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 读写改逐字节断言」发布门禁。
26
+ - **P1 — 修复 `dryRun: true` 撤销实际改盘与布尔参数容错隐患**:为 `undoWrite` 与 `charset_fix(action="undo", dryRun=true)` 补齐只读预览路径,保证零磁盘改动、不消费 journal 且不修改基线;对 `dryRun`/`bom`/`outline`/`hashlines` 等布尔参数改为严格类型校验,拒绝把 `"true"` 静默当作 `false`。
27
+ - **P1 — 修复 `write` 写前 NUL 预检缺失与 `autoCommit` 先于 Gate 2 执行**:在 `encodeForWrite` 中统一前置拦截会产生二进制 NUL 的写入(覆盖 `write` 与 `apply_patch add`),并将 `writeEncodedLocked` 与 `apply_patch add` 改为 Gate 2 验证通过后才允许执行 `autoCommit`,彻底杜绝未校验或遭篡改字节进入 Git 历史。
28
+ - **P1 — 修复 `autoCommit` 方括号路径通配误提交与失败时破坏部分暂存**:`src/journal.ts` 全部涉及路径的 Git 命令统一使用 `--literal-pathspecs`(修复 `motor[1].c` 误带入 `motor1.c`);写前检测目标文件若已有用户部分暂存改动则跳过自动提交以保护原暂存区,并在提交或钩子失败时按 `ls-files --stage` 快照精确恢复暂存条目而不影响其它已暂存文件。
29
+ - **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`。
30
+ - **P1 — 修复 `shell-guard.ts` 遇到单 `<` 输入重定向死循环**:补齐 `<`、`0<`、`<>`、`<<<` 与 `<(...)`/`>(...)` 进程替换解析(并递归检查进程替换内的命令)与不可破坏的循环推进不变量,`shellGuard: "off"` 提前短路返回。
31
+ - **P1 — 修复 `apply_patch` Move 删源前并发窗口**:在删除源文件前再次复核 `lstat` 文件身份与精确字节,若移动窗口内源文件遭外部修改则保留外部版本并报告部分完成状态与可撤回批次号。
32
+ - **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 输出排空。
33
+
34
+ ### 新增
35
+
36
+ - 为 `charset_write` 与 `charset_edit` 增加请求级 `expectedVersion` 乐观并发版本锁(多 Agent 共享单 MCP 实例时防过期覆盖),并为 MCP 工具补齐机器可读 `structuredContent`(`applied`、`verified`、`committed`、`undoId`、`version`、`encoding`、`bom`、`eol`、`bytesOnDisk`)。
37
+ - 新增 `pi-charset --version`、`pi-charset doctor`、`pi-charset explain <file>`、`mcp-config --help` / `--client cursor|windsurf` / `--local` 与严格的 CLI 参数校验。
38
+
11
39
  ## [0.1.6] - 2026-12-06
12
40
 
13
41
  ### 新增