@michengai/dsh-simplify 0.1.0 → 0.1.2

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 CHANGED
@@ -2,18 +2,33 @@
2
2
 
3
3
  [简体中文](CHANGELOG.zh-CN.md)
4
4
 
5
+ ## 0.1.2 - 2026-09-06
6
+
7
+ - Fix inherited Git environment settings selecting the wrong repository or staging area, including in linked worktrees.
8
+ - Stop collecting excessively fragmented changes or oversized review lists early and ask for a narrower scope.
9
+ - Clarify that new files before the initial commit are eligible for whole-file simplification.
10
+
11
+ ### Known Issues
12
+
13
+ - When there are no eligible code lines to simplify, the Agent does not start. Some host interfaces may not display the result, making the command appear unresponsive.
14
+
15
+ ## 0.1.1 - 2026-09-06
16
+
17
+ - Update the documentation in the package to focus on features, usage scope, and known issues. Code simplification behavior is unchanged from `0.1.0`.
18
+
19
+ ### Known Issues
20
+
21
+ - When there are no eligible code lines to simplify, the Agent does not start. Some host interfaces may not display the result, making the command appear unresponsive.
22
+
5
23
  ## 0.1.0 - 2026-09-06
6
24
 
7
- - Add `/simplify` for current changes, staged changes, a specified commit, and explicit files or directories.
8
- - Add a Chinese editing-task prompt with scope, behavior, snapshot, and verification requirements.
9
- - Expand simplification guidance, behavior-equivalence checks, project instruction discovery, concurrent-edit handling, and validation reporting to avoid over-abstraction, out-of-scope edits, and unsupported optimizations.
10
- - Use DSH subprocess argument arrays and NUL-delimited parsing for Chinese characters, spaces in paths, and untracked files.
11
- - Prevent queuing on Git failures, cancellation, timeouts, and truncation; bound file counts, content size, and prompt size.
12
- - Add staged consistency checks, HEAD/index/content verification, and previous-commit fallback in default mode only.
13
- - Add real Git regression tests and an optional integration test using real DSH services.
14
- - Parse patch bodies with old/new line-count validation, excluding context lines and rejecting incomplete hunks.
15
- - Initialize the public repository and bilingual documentation under Apache-2.0.
25
+ - Add `/simplify` to ask the current Agent to simplify code and improve readability while preserving existing behavior.
26
+ - Support current changes, staged changes only, changes relative to a specified commit, and selected files or directories.
27
+ - Support untracked new files and file paths containing Chinese characters or spaces.
28
+ - In default mode, review the most recent commit when there are no current changes.
29
+ - Stop the task if Git fails, times out, returns incomplete output, or files change during collection. Retry with a smaller scope or after editing has finished.
30
+ - In staged-only mode, ask you to resolve any unstaged changes in the selected files before proceeding.
16
31
 
17
32
  ### Known Issues
18
33
 
19
- - Some host interfaces do not visibly display the `没有可简化的当前代码行` (no eligible current lines) command result. The backend returns the result without making a model request; feedback visibility remains under investigation.
34
+ - When there are no eligible code lines to simplify, the Agent does not start. Some host interfaces may not display the result, making the command appear unresponsive.
@@ -2,18 +2,33 @@
2
2
 
3
3
  [English](CHANGELOG.md)
4
4
 
5
+ ## 0.1.2 - 2026-09-06
6
+
7
+ - 修复父进程 Git 环境设置导致审查仓库或暂存区选择错误的问题,支持普通仓库与 worktree。
8
+ - 对过于零碎的改动和超大审查清单提前停止,并提示缩小范围,避免收集大量最终无法提交的内容。
9
+ - 明确没有首次提交时新增文件按整文件整理的范围说明。
10
+
11
+ ### 已知问题
12
+
13
+ - 没有可简化的代码行时,不会启动 Agent;部分宿主界面可能未显示结果,看起来像命令没有响应。
14
+
15
+ ## 0.1.1 - 2026-09-06
16
+
17
+ - 更新安装包中的说明文档,聚焦功能、使用范围与已知问题。代码简化行为与 `0.1.0` 一致。
18
+
19
+ ### 已知问题
20
+
21
+ - 没有可简化的代码行时,不会启动 Agent;部分宿主界面可能未显示结果,看起来像命令没有响应。
22
+
5
23
  ## 0.1.0 - 2026-09-06
6
24
 
7
- - 新增 `/simplify`:当前改动、暂存区、指定提交和显式文件或目录范围。
8
- - 新增中文编辑任务提示词,明确范围、行为、快照与验证要求。
9
- - 完善简化检查方向、行为等价判断、项目规范读取、并发编辑保护及验证报告,避免过度抽象、越界修改和无依据的优化。
10
- - 使用 DSH subprocess 参数数组及 NUL 分隔解析,支持中文、空格路径和未跟踪文件。
11
- - Git 错误、取消、超时及截断时阻止入队;提供文件数、内容大小和提示词上限。
12
- - 增加暂存区一致性保护、HEAD/index/内容复核及仅默认模式的上一提交回看。
13
- - 新增真实 Git 回归测试和可选真实 DSH 服务集成测试。
14
- - 按补丁正文核对新旧行数,排除上下文行并拒绝残缺块。
15
- - 初始化公开仓库及双语文档,项目采用 Apache-2.0。
25
+ - 新增 `/simplify`,由当前 Agent 简化代码,改善可读性,并以保持原有功能为前提。
26
+ - 支持当前改动、仅暂存区、相对指定提交的改动,以及指定文件或目录范围。
27
+ - 支持未跟踪的新增文件,以及包含中文、空格的文件路径。
28
+ - 默认模式下,当前没有改动时可回看最近一次提交。
29
+ - Git 执行失败、超时、输出不完整或文件在收集期间发生变化时停止任务;可缩小范围或在编辑结束后重试。
30
+ - 仅暂存区模式下,所选文件若还有未暂存改动,会提示先处理这些改动。
16
31
 
17
32
  ### 已知问题
18
33
 
19
- - 部分宿主界面未明显显示“没有可简化的当前代码行”的命令结果。后端已返回结果且不会发起模型请求,反馈可见性仍待排查。
34
+ - 没有可简化的代码行时,不会启动 Agent;部分宿主界面可能未显示结果,看起来像命令没有响应。
package/README.md CHANGED
@@ -34,9 +34,9 @@ The plugin has its own review prompt, patch-body parser, Git collection, and DSH
34
34
 
35
35
  ## Installation
36
36
 
37
- Requires Node.js >= 22.19, Git on PATH, and DSH `0.1.2-rc.1` with the `commands` and `subprocess` services. The session must have a local Git working directory. Tested on Windows; Linux and macOS have not been verified on those systems.
37
+ Requires Node.js >= 22.19, Git on PATH, and DSH `0.1.2-rc.1` with the `commands` and `subprocess` services. The session must have a local Git working directory. Automated tests, including real host service integration, pass on Windows, Linux, and macOS. Installation in the desktop application has only been verified on Windows.
38
38
 
39
- The current version is `0.1.0`, available through npm, a packaged archive, or source installation. The examples use the `web` profile; replace it for your environment. Disable other plugins that register `/simplify` before installation.
39
+ The current version is `0.1.2`, available through npm, a packaged archive, or source installation. The examples use the `web` profile; replace it for your environment. Disable other plugins that register `/simplify` before installation.
40
40
 
41
41
  ### From npm
42
42
 
@@ -44,7 +44,7 @@ The current version is `0.1.0`, available through npm, a packaged archive, or so
44
44
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
45
45
  $OutputEncoding = [System.Text.Encoding]::UTF8
46
46
 
47
- dsh plugin --profile web add @michengai/dsh-simplify@0.1.0 --registry=https://registry.npmjs.org/
47
+ dsh plugin --profile web add @michengai/dsh-simplify@0.1.2 --registry=https://registry.npmjs.org/
48
48
  ```
49
49
 
50
50
  ### From Source
@@ -64,13 +64,13 @@ The entry point is `lib/index.js`, so build before installing. Keep the source d
64
64
 
65
65
  ### From a Local Package
66
66
 
67
- Download the tgz from the [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.0), or run `npm pack` in the source directory, then run this from the package directory:
67
+ Download the tgz from the [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.2), or run `npm pack` in the source directory, then run this from the package directory:
68
68
 
69
69
  ```powershell
70
70
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
71
71
  $OutputEncoding = [System.Text.Encoding]::UTF8
72
72
 
73
- dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
73
+ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.2.tgz --ignore-scripts
74
74
  ```
75
75
 
76
76
  ### Reload and Verify
@@ -94,7 +94,7 @@ Run `dsh --profile web --dump-config` and confirm that it includes `michengai-si
94
94
  - Paths are relative to the session directory. Absolute paths inside the repository are supported; prompts use paths relative to the repository root.
95
95
  - Single and double quotes group paths containing spaces; backslashes remain path characters. No shell expansion, wildcard expansion, or command substitution is performed.
96
96
  - `--ref` accepts branches, tags, and single-commit expressions, not `a..b` or `a...b`. It cannot be combined with `--staged`.
97
- - New files can be reviewed before the initial commit. A clean repository with only one commit returns no changes.
97
+ - Before the initial commit, files in the selected scope are treated as new and may be simplified in full. Default mode includes staged and untracked files; `--staged` includes only staged files. Select files or directories to narrow the scope; file count and size limits still apply. A clean repository with only one commit returns no changes.
98
98
  - Previous-commit fallback compares HEAD with its first parent. Merge commits do not receive a multi-parent review.
99
99
 
100
100
  ## Command Results
@@ -121,10 +121,14 @@ Run `dsh --profile web --dump-config` and confirm that it includes `michengai-si
121
121
 
122
122
  The plugin performs read-only Git queries and local file reads. It does not automatically run `git add`, commit, reset, or stash. Git arguments are passed through DSH `subprocess` as `argv`, independent of PowerShell or Bash quoting rules.
123
123
 
124
+ The repository and index are determined from the session working directory and Git worktree metadata. Child processes do not inherit repository-local environment overrides such as `GIT_DIR`, `GIT_WORK_TREE`, `GIT_INDEX_FILE`, or temporary configuration overrides. Ordinary user and repository configuration is preserved. The repository returned by Git must contain the session working directory.
125
+
124
126
  Git failures, signals, cancellation, timeouts, truncated output, unresolved conflicts, and stale snapshots prevent prompt delivery. They are not interpreted as an empty diff. The patch parser counts old and new lines against each hunk header, rejects incomplete bodies, and excludes context lines from editable ranges. Explicit paths that do not exist, are ignored, or lie outside the repository return errors.
125
127
 
126
128
  Deleted files, deletion-only hunks, rename-only changes, binary files, non-regular files, and files over 5 MiB are excluded from editable ranges with reasons. Submodules are excluded from diff collection. Skipping all detected changes does not expand the review scope. Limits are 200 changed files, 30 seconds per Git command, and 60 seconds for scope collection, with up to 1 additional second for process termination. Git stdout is capped at 8 MiB, stderr at 64 KiB, and prompts at 128 KiB.
127
129
 
130
+ Across all files, collection is limited to 4,096 separate line ranges and 128 KiB of review metadata, including skipped-file details. Exceeding either limit stops collection instead of submitting a partial review. Consecutive changed lines count as one range. The final prompt is independently checked against its 128 KiB limit; select files or directories to narrow an oversized scope.
131
+
128
132
  `--staged` first checks that selected staged files match the working tree. Before queuing, the plugin rechecks the index, HEAD, and file SHA-256 hashes to avoid applying index line numbers to different working-tree content. The Agent is instructed to verify snapshots again before editing and stop simplifying a file if its content has changed, requiring a new command invocation.
129
133
 
130
134
  **Scope is a prompt instruction, not a file-write permission boundary.** The Agent edits and tests using host tools and user authorization. This plugin does not intercept writes from other tools or guarantee that files remain unchanged after queuing. A queued review is not a completed simplification.
@@ -156,6 +160,8 @@ Tests use real temporary Git repositories to cover paths, untracked files, fallb
156
160
 
157
161
  `tests/host.test.mjs` looks for a DSH runtime at `%USERPROFILE%\.dsh\profiles\node_modules`. Set `DSH_RUNTIME_ROOT` to use another runtime's node_modules path. When detected, it runs isolated integration checks for real service registration, Git execution, message delivery, and disposal; otherwise, that test is explicitly skipped. Tests do not call a model or modify installed profiles.
158
162
 
163
+ GitHub Actions checks types and tests on Windows, Linux, and macOS, using the host runtime from development dependencies through `DSH_RUNTIME_ROOT`. Publishing a stable GitHub Release starts `publish.yml`: it runs all three platform checks, validates the version, bilingual release notes, and package contents, publishes through npm Trusted Publishing, and uploads the same tgz to the Release. Configure `publish.yml` as the workflow filename in npm and allow `npm publish`; no publishing token is required.
164
+
159
165
  | Path | Responsibility |
160
166
  | --- | --- |
161
167
  | `src/args.ts` | Command argument parsing |
package/README.zh-CN.md CHANGED
@@ -34,9 +34,9 @@ DeepSeek Harness 代码简化插件。运行 `/simplify` 后,插件收集 Git
34
34
 
35
35
  ## 安装
36
36
 
37
- 要求 Node.js >= 22.19、PATH 中可执行的 Git,以及提供 `commands`、`subprocess` 服务的 DSH `0.1.2-rc.1`。会话需要关联本地 Git 工作目录。Windows 已实测,Linux/macOS 尚未在对应系统验证。
37
+ 要求 Node.js >= 22.19、PATH 中可执行的 Git,以及提供 `commands`、`subprocess` 服务的 DSH `0.1.2-rc.1`。会话需要关联本地 Git 工作目录。Windows、Linux、macOS 均已通过自动化测试(含真实宿主服务集成);桌面应用中的实际安装仅在 Windows 验证。
38
38
 
39
- 当前版本为 `0.1.0`,支持 npm、安装包和源码安装。以下示例使用 `web` profile,请按实际环境替换。安装前停用其他注册 `/simplify` 的插件。
39
+ 当前版本为 `0.1.2`,支持 npm、安装包和源码安装。以下示例使用 `web` profile,请按实际环境替换。安装前停用其他注册 `/simplify` 的插件。
40
40
 
41
41
  ### 从 npm 安装
42
42
 
@@ -44,7 +44,7 @@ DeepSeek Harness 代码简化插件。运行 `/simplify` 后,插件收集 Git
44
44
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
45
45
  $OutputEncoding = [System.Text.Encoding]::UTF8
46
46
 
47
- dsh plugin --profile web add @michengai/dsh-simplify@0.1.0 --registry=https://registry.npmjs.org/
47
+ dsh plugin --profile web add @michengai/dsh-simplify@0.1.2 --registry=https://registry.npmjs.org/
48
48
  ```
49
49
 
50
50
  ### 从源码安装
@@ -64,13 +64,13 @@ dsh plugin --profile web add . --ignore-scripts
64
64
 
65
65
  ### 从本地安装包安装
66
66
 
67
- 从 [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.0) 下载 tgz,或在源码目录运行 `npm pack` 生成安装包,然后在安装包所在目录执行:
67
+ 从 [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.2) 下载 tgz,或在源码目录运行 `npm pack` 生成安装包,然后在安装包所在目录执行:
68
68
 
69
69
  ```powershell
70
70
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
71
71
  $OutputEncoding = [System.Text.Encoding]::UTF8
72
72
 
73
- dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
73
+ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.2.tgz --ignore-scripts
74
74
  ```
75
75
 
76
76
  ### 重新加载与确认
@@ -94,7 +94,7 @@ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
94
94
  - 路径相对当前会话目录,支持仓库内绝对路径;提示词统一使用仓库根目录相对路径。
95
95
  - 支持单双引号组合带空格路径,反斜杠按路径字符保留;不执行 Shell 展开、通配符或命令替换。
96
96
  - `--ref` 支持分支、标签和单个提交表达式,不支持 `a..b` / `a...b`;不能与 `--staged` 混用。
97
- - 没有首次提交时仍可审查新增文件;只有一个提交且工作区干净时直接返回无变更。
97
+ - 没有首次提交时,所选范围内的文件视为新增文件,允许整文件整理:默认包含暂存与未跟踪文件,`--staged` 仅包含暂存文件。可指定文件或目录缩小范围,文件数量和大小限制仍然生效。只有一个提交且工作区干净时直接返回无变更。
98
98
  - 上一提交回看相对于 HEAD 第一父提交;merge commit 不做多父合并审查。
99
99
 
100
100
  ## 命令结果
@@ -121,10 +121,14 @@ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
121
121
 
122
122
  插件只执行 Git 只读查询和读取本地文件,不自动 `git add`、提交、重置或存储工作区。Git 参数通过 DSH `subprocess` 的 `argv` 传递,不依赖 PowerShell/Bash 引用规则。
123
123
 
124
+ 仓库和索引依据会话工作目录及 Git worktree 元数据确定;子进程不继承 `GIT_DIR`、`GIT_WORK_TREE`、`GIT_INDEX_FILE` 等仓库局部环境或临时配置覆盖,保留普通用户与仓库配置。Git 返回的仓库必须包含当前会话工作目录。
125
+
124
126
  Git 失败、信号终止、取消、超时、输出截断、未解决冲突和过期快照都会阻止提示词投递,不将它们当作无改动。补丁解析器按正文核对每块的新旧行数,拒绝残缺正文,并排除上下文行。显式路径不存在、被忽略或位于仓库外时返回错误。
125
127
 
126
128
  删除文件、纯删除行、仅重命名、二进制文件、非普通文件及大于 5 MiB 的文件不进入可编辑范围,并说明跳过原因。子模块不纳入 diff 收集。已检测到的改动全部被跳过时,不会因此扩大到其他范围。最多收集 200 个变更文件,单次 Git 最多 30 秒,整个范围收集最多 60 秒(进程终止还有最多 1 秒宽限);Git stdout 上限 8 MiB、stderr 64 KiB,提示词上限 128 KiB。
127
129
 
130
+ 所有文件累计最多 4,096 个离散行范围,审查清单元数据(含跳过明细)最多 128 KiB;收集过程中超限即停止,不截取部分文件提交审查。连续修改行按一个范围计数。最终提示词仍独立检查 128 KiB 上限;超限时请指定文件或目录缩小范围。
131
+
128
132
  `--staged` 先确认所选暂存文件与工作区一致,并在入队前再次核对暂存区、HEAD 和文件 SHA-256,避免把 index 行号直接用于不同的工作区内容。Agent 编辑前还需复核内容快照;内容变化时停止该文件的简化并重新运行命令。
129
133
 
130
134
  **修改范围是提示词约束,不是文件写入权限隔离。** Agent 按宿主工具和用户授权执行修改及测试;本插件没有拦截其他工具的写入,也不能保证排队后文件不再变化。不要把“已提交审查”理解成“已完成简化”。
@@ -156,6 +160,8 @@ npm pack --dry-run
156
160
 
157
161
  `tests/host.test.mjs` 检测 `%USERPROFILE%\.dsh\profiles\node_modules` 的 DSH 运行时;也可通过 `DSH_RUNTIME_ROOT` 指定其 node_modules 路径。检测到时执行隔离的真实服务注册、Git 执行、消息投递与卸载测试;缺失时明确标为跳过。测试不调用模型,不修改已安装 profile。
158
162
 
163
+ GitHub Actions 在 Windows、Linux、macOS 上检查类型与测试,并通过 `DSH_RUNTIME_ROOT` 使用开发依赖中的宿主运行时。发布正式 GitHub Release 后,`publish.yml` 先完成三平台检查,再核对版本、双语发布说明及安装包内容,通过 npm Trusted Publishing 发布,并把同一 tgz 上传到 Release。npm 中的工作流文件名需配置为 `publish.yml`,并允许 `npm publish`;不需要发布令牌。
164
+
159
165
  | 目录 | 职责 |
160
166
  | --- | --- |
161
167
  | `src/args.ts` | 命令参数解析 |
package/lib/exec.js CHANGED
@@ -1,3 +1,11 @@
1
+ // 清除 Git 仓库局部环境,交由 cwd 和 .git/worktree 元数据确定仓库;保留常规用户配置。
2
+ const REPOSITORY_ENV = Object.fromEntries([
3
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT',
4
+ 'GIT_OBJECT_DIRECTORY', 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_IMPLICIT_WORK_TREE', 'GIT_GRAFT_FILE',
5
+ 'GIT_INDEX_FILE', 'GIT_NO_REPLACE_OBJECTS', 'GIT_REPLACE_REF_BASE', 'GIT_PREFIX',
6
+ 'GIT_SHALLOW_FILE', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_CEILING_DIRECTORIES',
7
+ 'GIT_DISCOVERY_ACROSS_FILESYSTEM',
8
+ ].map(name => [name, undefined]));
1
9
  export class GitError extends Error {
2
10
  code;
3
11
  constructor(code, message) {
@@ -24,7 +32,7 @@ export function createGitRunner(subprocess, signal, timeoutMs = 30_000) {
24
32
  const handle = subprocess.spawn({
25
33
  argv: ['git', ...args], cwd, signal: combined, graceMs: 1_000,
26
34
  stdio: { stdin: 'ignore', stdout: { maxBytes: 8 * 1024 * 1024 }, stderr: { maxBytes: 64 * 1024 } },
27
- env: { GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0', GIT_PAGER: 'cat' },
35
+ env: { ...REPOSITORY_ENV, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0', GIT_PAGER: 'cat' },
28
36
  });
29
37
  const outcome = await handle.done;
30
38
  checkAbort();
package/lib/exec.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACZ;IAArB,YAAqB,IAA2E,EAAE,OAAe;QAC/G,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,SAAI,GAAJ,IAAI,CAAuE;QAE9F,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,yDAAyD;AACzD,MAAM,UAAU,eAAe,CAAC,UAA4C,EAAE,MAAmB,EAAE,SAAS,GAAG,MAAM;IACnH,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7C,IAAI,MAAM,CAAC,OAAO;YAAE,MAAM,IAAI,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,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I,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5F,MAAM,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACnD,MAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1G,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,QAAQ;gBAAE,MAAM,KAAK,CAAC;YAC3C,MAAM,IAAI,QAAQ,CAAC,aAAa,EAAE,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1G,CAAC;gBAAS,CAAC;YAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';\nimport type { GitRunner } from './git.js';\n\nexport class GitError extends Error {\n constructor(readonly code: 'ABORTED' | 'TIMEOUT' | 'UNAVAILABLE' | 'OUTPUT_TRUNCATED' | 'FAILED', message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** 创建一次命令共用的 Git 执行器;调用者负责整个审查的截止时间,单次 Git 默认最多 30 秒。 */\nexport function createGitRunner(subprocess: Pick<SubprocessRuntime, 'spawn'>, signal: AbortSignal, timeoutMs = 30_000): GitRunner {\n return async (args, cwd, allowedCodes = [0]) => {\n if (signal.aborted) throw new GitError('ABORTED', '简化审查已取消。');\n const timeout = new AbortController();\n const combined = AbortSignal.any([signal, timeout.signal]);\n const timer = setTimeout(() => timeout.abort(), timeoutMs);\n const checkAbort = () => {\n if (signal.aborted) throw new GitError('ABORTED', '简化审查已取消。');\n if (timeout.signal.aborted) throw new GitError('TIMEOUT', `Git 执行超过 ${timeoutMs} 毫秒。`);\n };\n try {\n const handle = subprocess.spawn({\n argv: ['git', ...args], cwd, signal: combined, graceMs: 1_000,\n stdio: { stdin: 'ignore', stdout: { maxBytes: 8 * 1024 * 1024 }, stderr: { maxBytes: 64 * 1024 } },\n env: { GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0', GIT_PAGER: 'cat' },\n });\n const outcome = await handle.done;\n checkAbort();\n const stdout = handle.collected.stdout?.readFrom(0);\n const stderr = handle.collected.stderr?.readFrom(0);\n if (!stdout || stdout.lossy || stderr?.lossy) throw new GitError('OUTPUT_TRUNCATED', 'Git 输出缺失或被截断,请缩小审查范围。');\n if (outcome.exitCode === null || outcome.signal || !allowedCodes.includes(outcome.exitCode)) {\n const detail = stderr?.text.trim().slice(0, 2_000);\n throw new GitError('FAILED', `Git 执行失败(退出码 ${outcome.exitCode ?? '未知'})${detail ? `:${detail}` : '。'}`);\n }\n return { code: outcome.exitCode, stdout: stdout.text };\n } catch (error) {\n checkAbort();\n if (error instanceof GitError) throw error;\n throw new GitError('UNAVAILABLE', `无法执行 Git:${error instanceof Error ? error.message : String(error)}`);\n } finally { clearTimeout(timer); }\n };\n}\n"]}
1
+ {"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":"AAGA,yDAAyD;AACzD,MAAM,cAAc,GAAsB,MAAM,CAAC,WAAW,CAAC;IAC3D,kCAAkC,EAAE,YAAY,EAAE,uBAAuB,EAAE,kBAAkB;IAC7F,sBAAsB,EAAE,SAAS,EAAE,eAAe,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AO,CAAC,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1G,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,QAAQ;gBAAE,MAAM,KAAK,CAAC;YAC3C,MAAM,IAAI,QAAQ,CAAC,aAAa,EAAE,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1G,CAAC;gBAAS,CAAC;YAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';\nimport type { GitRunner } from './git.js';\n\n// 清除 Git 仓库局部环境,交由 cwd 和 .git/worktree 元数据确定仓库;保留常规用户配置。\nconst REPOSITORY_ENV: NodeJS.ProcessEnv = Object.fromEntries([\n 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT',\n 'GIT_OBJECT_DIRECTORY', 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_IMPLICIT_WORK_TREE', 'GIT_GRAFT_FILE',\n 'GIT_INDEX_FILE', 'GIT_NO_REPLACE_OBJECTS', 'GIT_REPLACE_REF_BASE', 'GIT_PREFIX',\n 'GIT_SHALLOW_FILE', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_CEILING_DIRECTORIES',\n 'GIT_DISCOVERY_ACROSS_FILESYSTEM',\n].map(name => [name, undefined]));\n\nexport class GitError extends Error {\n constructor(readonly code: 'ABORTED' | 'TIMEOUT' | 'UNAVAILABLE' | 'OUTPUT_TRUNCATED' | 'FAILED', message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** 创建一次命令共用的 Git 执行器;调用者负责整个审查的截止时间,单次 Git 默认最多 30 秒。 */\nexport function createGitRunner(subprocess: Pick<SubprocessRuntime, 'spawn'>, signal: AbortSignal, timeoutMs = 30_000): GitRunner {\n return async (args, cwd, allowedCodes = [0]) => {\n if (signal.aborted) throw new GitError('ABORTED', '简化审查已取消。');\n const timeout = new AbortController();\n const combined = AbortSignal.any([signal, timeout.signal]);\n const timer = setTimeout(() => timeout.abort(), timeoutMs);\n const checkAbort = () => {\n if (signal.aborted) throw new GitError('ABORTED', '简化审查已取消。');\n if (timeout.signal.aborted) throw new GitError('TIMEOUT', `Git 执行超过 ${timeoutMs} 毫秒。`);\n };\n try {\n const handle = subprocess.spawn({\n argv: ['git', ...args], cwd, signal: combined, graceMs: 1_000,\n stdio: { stdin: 'ignore', stdout: { maxBytes: 8 * 1024 * 1024 }, stderr: { maxBytes: 64 * 1024 } },\n env: { ...REPOSITORY_ENV, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0', GIT_PAGER: 'cat' },\n });\n const outcome = await handle.done;\n checkAbort();\n const stdout = handle.collected.stdout?.readFrom(0);\n const stderr = handle.collected.stderr?.readFrom(0);\n if (!stdout || stdout.lossy || stderr?.lossy) throw new GitError('OUTPUT_TRUNCATED', 'Git 输出缺失或被截断,请缩小审查范围。');\n if (outcome.exitCode === null || outcome.signal || !allowedCodes.includes(outcome.exitCode)) {\n const detail = stderr?.text.trim().slice(0, 2_000);\n throw new GitError('FAILED', `Git 执行失败(退出码 ${outcome.exitCode ?? '未知'})${detail ? `:${detail}` : '。'}`);\n }\n return { code: outcome.exitCode, stdout: stdout.text };\n } catch (error) {\n checkAbort();\n if (error instanceof GitError) throw error;\n throw new GitError('UNAVAILABLE', `无法执行 Git:${error instanceof Error ? error.message : String(error)}`);\n } finally { clearTimeout(timer); }\n };\n}\n"]}
package/lib/git.d.ts CHANGED
@@ -33,8 +33,8 @@ export interface Review {
33
33
  /** 解析 Git -z 文件列表,拒绝不完整记录以免把截断输出当作完整范围。 */
34
34
  export declare function nulFields(text: string): string[];
35
35
  export declare function parseNameStatus(text: string): Change[];
36
- /** 按 unified diff 正文计数,只开放新增行;块计数不一致时抛错。 */
37
- export declare function parseChangedLines(text: string): LineRange[];
36
+ /** 按 unified diff 正文计数;maxRanges 为剩余离散行范围额度,超额或正文不完整时抛错。 */
37
+ export declare function parseChangedLines(text: string, maxRanges?: number): LineRange[];
38
38
  /** 收集可审查文本文件及行号快照;Git 失败、冲突或不可靠范围会抛错,不产生部分成功。 */
39
39
  export declare function collectReview(run: GitRunner, cwd: string, options: SimplifyOptions): Promise<Review>;
40
40
  /** 在提交提示词前复核内容及 HEAD;这不是 Agent 后续写入权限的硬限制。 */
package/lib/git.js CHANGED
@@ -3,6 +3,8 @@ import { lstat, open, realpath } from 'node:fs/promises';
3
3
  import { isAbsolute, relative, resolve, sep } from 'node:path';
4
4
  const MAX_FILES = 200;
5
5
  const MAX_FILE_BYTES = 5 * 1024 * 1024;
6
+ const MAX_REVIEW_RANGES = 4_096;
7
+ const MAX_REVIEW_BYTES = 128 * 1024;
6
8
  const STATUS = { A: 'added', M: 'modified', R: 'renamed', C: 'copied', D: 'deleted', T: 'type-changed', U: 'unmerged', X: 'unknown', B: 'broken' };
7
9
  const DIFF = ['diff', '--no-color', '--no-ext-diff', '--no-textconv', '--no-relative', '--ignore-submodules=all', '--find-renames'];
8
10
  const GLOBAL = ['--no-pager', '--literal-pathspecs', '-c', 'color.ui=false'];
@@ -34,14 +36,19 @@ export function parseNameStatus(text) {
34
36
  }
35
37
  return files;
36
38
  }
37
- /** 按 unified diff 正文计数,只开放新增行;块计数不一致时抛错。 */
38
- export function parseChangedLines(text) {
39
+ /** 按 unified diff 正文计数;maxRanges 为剩余离散行范围额度,超额或正文不完整时抛错。 */
40
+ export function parseChangedLines(text, maxRanges = MAX_REVIEW_RANGES) {
41
+ if (!Number.isSafeInteger(maxRanges) || maxRanges < 0 || maxRanges > MAX_REVIEW_RANGES)
42
+ throw new Error('行范围额度无效。');
39
43
  const result = [];
40
44
  let block;
41
45
  let segment;
42
46
  const flush = () => {
43
- if (segment !== undefined && block)
47
+ if (segment !== undefined && block) {
48
+ if (result.length >= maxRanges)
49
+ throw new Error('审查行范围超过 4096 个,请通过路径缩小审查范围。');
44
50
  result.push({ start: segment, end: block.cursor - 1 });
51
+ }
45
52
  segment = undefined;
46
53
  };
47
54
  const finish = () => {
@@ -50,8 +57,11 @@ export function parseChangedLines(text) {
50
57
  flush();
51
58
  block = undefined;
52
59
  };
53
- const rows = (text.endsWith('\n') ? text.slice(0, -1) : text).split('\n');
54
- for (const row of rows) {
60
+ // 逐行消费已有 diff 字符串,避免先分配整份行数组,再因范围超限丢弃。
61
+ for (let offset = 0; offset < text.length;) {
62
+ const newline = text.indexOf('\n', offset);
63
+ const row = text.slice(offset, newline < 0 ? text.length : newline);
64
+ offset = newline < 0 ? text.length : newline + 1;
55
65
  if (row.startsWith('@@')) {
56
66
  finish();
57
67
  const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: .*)?$/u.exec(row);
@@ -152,6 +162,8 @@ export async function collectReview(run, cwd, options) {
152
162
  const rootResult = await run([...GLOBAL, 'rev-parse', '--show-toplevel'], cwd);
153
163
  const root = await realpath(rootResult.stdout.replace(/\r?\n$/u, ''));
154
164
  const sessionRoot = await realpath(cwd);
165
+ if (!inside(root, sessionRoot))
166
+ throw new Error('当前会话工作目录不在 Git 返回的仓库内。');
155
167
  const paths = options.files.map(path => {
156
168
  const absolute = resolve(sessionRoot, path);
157
169
  if (!inside(root, absolute))
@@ -205,9 +217,22 @@ export async function collectReview(run, cwd, options) {
205
217
  await assertStagedClean(run, root, changes.flatMap(file => file.oldPath ? [file.oldPath, file.path] : [file.path]));
206
218
  const files = [];
207
219
  const skipped = [];
220
+ let rangeCount = 0;
221
+ let metadataBytes = 0;
222
+ const accountMetadata = (value) => {
223
+ metadataBytes += Buffer.byteLength(JSON.stringify(value), 'utf8');
224
+ if (metadataBytes > MAX_REVIEW_BYTES)
225
+ throw new Error('审查清单超过 128 KiB,请通过路径缩小审查范围。');
226
+ };
227
+ accountMetadata({ root, head, base, source, staged: options.staged, paths });
228
+ const skip = (path, reason) => {
229
+ const file = { path, reason };
230
+ accountMetadata(file);
231
+ skipped.push(file);
232
+ };
208
233
  for (const file of changes) {
209
234
  if (['deleted', 'type-changed', 'unmerged', 'unknown', 'broken'].includes(file.status)) {
210
- skipped.push({ path: file.path, reason: `不可编辑的文件状态:${file.status}` });
235
+ skip(file.path, `不可编辑的文件状态:${file.status}`);
211
236
  continue;
212
237
  }
213
238
  let before;
@@ -216,28 +241,31 @@ export async function collectReview(run, cwd, options) {
216
241
  }
217
242
  catch (error) {
218
243
  if (!head && error.code === 'ENOENT') {
219
- skipped.push({ path: file.path, reason: '新仓库中已从工作区删除' });
244
+ skip(file.path, '新仓库中已从工作区删除');
220
245
  continue;
221
246
  }
222
247
  throw error;
223
248
  }
224
249
  if ('reason' in before) {
225
- skipped.push({ path: file.path, reason: before.reason });
250
+ skip(file.path, before.reason);
226
251
  continue;
227
252
  }
228
253
  let ranges = [];
229
254
  if (file.status !== 'added') {
230
255
  const diff = await run([...GLOBAL, ...DIFF, '--unified=0', '--inter-hunk-context=0', ...(options.staged ? ['--cached'] : [base]), '--', ...(file.oldPath ? [file.oldPath] : []), file.path], root);
231
- ranges = parseChangedLines(diff.stdout);
256
+ ranges = parseChangedLines(diff.stdout, MAX_REVIEW_RANGES - rangeCount);
257
+ rangeCount += ranges.length;
232
258
  const after = await fingerprint(root, file.path);
233
259
  if (!('sha256' in after) || after.sha256 !== before.sha256)
234
260
  throw new Error(`文件在收集范围时发生变化:${JSON.stringify(file.path)},请重试。`);
235
261
  if (!ranges.length) {
236
- skipped.push({ path: file.path, reason: '没有可简化的当前行(纯删除、仅重命名或非文本 diff)' });
262
+ skip(file.path, '没有可简化的当前行(纯删除、仅重命名或非文本 diff)');
237
263
  continue;
238
264
  }
239
265
  }
240
- files.push({ ...file, ranges, sha256: before.sha256 });
266
+ const reviewed = { ...file, ranges, sha256: before.sha256 };
267
+ accountMetadata(reviewed);
268
+ files.push(reviewed);
241
269
  }
242
270
  const review = { root, head, base, source, staged: options.staged, paths, indexSnapshot, files, skipped };
243
271
  await verifyReview(run, review);
package/lib/git.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAqB/D,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACvC,MAAM,MAAM,GAA2B,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;AAC3K,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,yBAAyB,EAAE,gBAAgB,CAAC,CAAC;AACpI,MAAM,MAAM,GAAG,CAAC,YAAY,EAAE,qBAAqB,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;AAE7E,2CAA2C;AAC3C,MAAM,UAAU,SAA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AAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACvI,CAAC;AACH,CAAC","sourcesContent":["import type { SimplifyOptions } from './args.js';\nimport { createHash } from 'node:crypto';\nimport { lstat, open, realpath } from 'node:fs/promises';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nexport type GitRunner = (args: readonly string[], cwd: string, allowedCodes?: readonly number[]) => Promise<{ code: number; stdout: string }>;\n\nexport interface LineRange { readonly start: number; readonly end: number }\ninterface Change { readonly path: string; readonly status: string; readonly oldPath?: string }\nexport interface ReviewFile extends Change {\n readonly ranges: readonly LineRange[];\n readonly sha256: string;\n}\nexport interface Review {\n readonly root: string;\n readonly head: string | undefined;\n readonly base: string | undefined;\n readonly staged: boolean;\n readonly paths: readonly string[];\n readonly indexSnapshot: string | undefined;\n readonly source: 'worktree' | 'staged' | 'ref' | 'previous-commit';\n readonly files: readonly ReviewFile[];\n readonly skipped: readonly { path: string; reason: string }[];\n}\nconst MAX_FILES = 200;\nconst MAX_FILE_BYTES = 5 * 1024 * 1024;\nconst STATUS: Record<string, string> = { A: 'added', M: 'modified', R: 'renamed', C: 'copied', D: 'deleted', T: 'type-changed', U: 'unmerged', X: 'unknown', B: 'broken' };\nconst DIFF = ['diff', '--no-color', '--no-ext-diff', '--no-textconv', '--no-relative', '--ignore-submodules=all', '--find-renames'];\nconst GLOBAL = ['--no-pager', '--literal-pathspecs', '-c', 'color.ui=false'];\n\n/** 解析 Git -z 文件列表,拒绝不完整记录以免把截断输出当作完整范围。 */\nexport function nulFields(text: string): string[] {\n if (!text) return [];\n if (!text.endsWith('\\0')) throw new Error('Git 文件列表不完整。');\n return text.slice(0, -1).split('\\0');\n}\n\nexport function parseNameStatus(text: string): Change[] {\n const fields = nulFields(text);\n const files: Change[] = [];\n for (let i = 0; i < fields.length;) {\n const code = fields[i++]!;\n const status = STATUS[code[0]!];\n const first = fields[i++];\n if (!status || !first || !/^[ACDMRTUXB]\\d*$/u.test(code)) throw new Error('Git 文件状态格式无效。');\n if (code.startsWith('R') || code.startsWith('C')) {\n const path = fields[i++];\n if (!path) throw new Error('Git 重命名记录不完整。');\n files.push({ path, oldPath: first, status });\n } else files.push({ path: first, status });\n }\n return files;\n}\n\n/** 按 unified diff 正文计数,只开放新增行;块计数不一致时抛错。 */\nexport function parseChangedLines(text: string): LineRange[] {\n const result: LineRange[] = [];\n let block: { oldLeft: number; newLeft: number; cursor: number } | undefined;\n let segment: number | undefined;\n const flush = (): void => {\n if (segment !== undefined && block) result.push({ start: segment, end: block.cursor - 1 });\n segment = undefined;\n };\n const finish = (): void => {\n if (block && (block.oldLeft !== 0 || block.newLeft !== 0)) throw new Error('Git 补丁正文不完整。');\n flush();\n block = undefined;\n };\n const rows = (text.endsWith('\\n') ? text.slice(0, -1) : text).split('\\n');\n for (const row of rows) {\n if (row.startsWith('@@')) {\n finish();\n const header = /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(?: .*)?$/u.exec(row);\n if (!header) throw new Error('Git 补丁块头无效。');\n const [oldStart, oldLeft, cursor, newLeft] = [Number(header[1]), Number(header[2] ?? 1), Number(header[3]), Number(header[4] ?? 1)];\n for (const [start, count] of [[oldStart!, oldLeft!], [cursor!, newLeft!]]) {\n if (!Number.isSafeInteger(start) || !Number.isSafeInteger(count) || !Number.isSafeInteger(start! + count!) || (count! > 0 && start === 0)) {\n throw new Error('Git 补丁行号超出有效范围。');\n }\n }\n block = { oldLeft: oldLeft!, newLeft: newLeft!, cursor: cursor! };\n continue;\n }\n if (row.startsWith('diff --git ')) { finish(); continue; }\n if (!block) continue;\n if (row === '\\\') continue;\n switch (row[0]) {\n case '+':\n segment ??= block.cursor;\n block.cursor++;\n block.newLeft--;\n break;\n case '-':\n block.oldLeft--;\n break;\n case ' ':\n flush();\n block.cursor++;\n block.oldLeft--;\n block.newLeft--;\n break;\n default:\n throw new Error('Git 补丁正文格式无效。');\n }\n if (block.oldLeft < 0 || block.newLeft < 0) throw new Error('Git 补丁正文超过声明行数。');\n }\n finish();\n return result;\n}\n\nfunction inside(root: string, path: string): boolean {\n const rel = relative(root, path);\n return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);\n}\n\nasync function fingerprint(root: string, path: string): Promise<{ sha256: string } | { reason: string }> {\n const absolute = resolve(root, path);\n if (!inside(root, absolute)) throw new Error('Git 返回了仓库外路径。');\n const stat = await lstat(absolute);\n if (!stat.isFile()) return { reason: '非普通文件(符号链接或子模块等)' };\n if (!inside(root, await realpath(absolute))) return { reason: '路径指向仓库外' };\n if (stat.size > MAX_FILE_BYTES) return { reason: '文件超过 5 MiB' };\n const handle = await open(absolute, 'r');\n try {\n const buffer = Buffer.alloc(Math.min(stat.size + 1, MAX_FILE_BYTES + 1));\n let offset = 0;\n while (offset < buffer.length) {\n const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, null);\n if (!bytesRead) break;\n offset += bytesRead;\n }\n if (offset !== stat.size) throw new Error(`文件在读取时发生变化:${JSON.stringify(path)},请重试。`);\n const content = buffer.subarray(0, offset);\n if (content.includes(0)) return { reason: '二进制文件' };\n return { sha256: createHash('sha256').update(content).digest('hex') };\n } finally { await handle.close(); }\n}\n\nasync function revision(run: GitRunner, root: string, ref: string): Promise<string | undefined> {\n const result = await run([...GLOBAL, 'rev-parse', '--verify', '--quiet', '--end-of-options', `${ref}^{commit}`], root, [0, 1]);\n return result.code === 0 ? result.stdout.trim() : undefined;\n}\n\nasync function assertStagedClean(run: GitRunner, root: string, paths: readonly string[]): Promise<void> {\n if (!paths.length) return;\n const result = await run([...GLOBAL, ...DIFF, '--name-only', '-z', '--', ...paths], root);\n if (result.stdout) throw new Error('待审查的暂存文件还有未暂存改动。请先暂存或自行保存这些改动,再运行 --staged。');\n}\n\n/** 收集可审查文本文件及行号快照;Git 失败、冲突或不可靠范围会抛错,不产生部分成功。 */\nexport async function collectReview(run: GitRunner, cwd: string, options: SimplifyOptions): Promise<Review> {\n if (!cwd) throw new Error('当前会话没有工作目录。');\n const rootResult = await run([...GLOBAL, 'rev-parse', '--show-toplevel'], cwd);\n const root = await realpath(rootResult.stdout.replace(/\\r?\\n$/u, ''));\n const sessionRoot = await realpath(cwd);\n const paths = options.files.map(path => {\n const absolute = resolve(sessionRoot, path);\n if (!inside(root, absolute)) throw new Error(`路径不在当前仓库内:${JSON.stringify(path)}`);\n return relative(root, absolute).split(sep).join('/') || '.';\n });\n const head = await revision(run, root, 'HEAD');\n let base = options.explicitRef ? await revision(run, root, options.ref) : head;\n if (options.explicitRef && !base) throw new Error(`无效的 Git 引用:${options.ref}`);\n let source: Review['source'] = options.staged ? 'staged' : options.explicitRef ? 'ref' : 'worktree';\n const scope = ['--', ...paths];\n const indexSnapshot = options.staged ? (await run([...GLOBAL, 'ls-files', '--stage', '-z', ...scope], root)).stdout : undefined;\n const conflicts = await run([...GLOBAL, 'ls-files', '--unmerged', '-z', ...scope], root);\n if (conflicts.stdout) throw new Error('所选范围存在未解决的 Git 冲突,请先解决冲突。');\n for (const path of paths) {\n const existing = await run([...GLOBAL, 'ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', path], root);\n if (!existing.stdout) throw new Error(`路径不存在、被忽略或未纳入 Git:${JSON.stringify(path)}`);\n }\n const list = async (ref: string | undefined): Promise<Change[]> => {\n if (!ref && !options.staged) {\n const tracked = await run([...GLOBAL, 'ls-files', '--cached', '-z', ...scope], root);\n return [...new Set(nulFields(tracked.stdout))].map(path => ({ path, status: 'added' }));\n }\n const result = await run([...GLOBAL, ...DIFF, '--name-status', '-z', ...(options.staged ? ['--cached'] : [ref!]), ...scope], root);\n return parseNameStatus(result.stdout);\n };\n let changes = await list(base);\n if (!options.staged) {\n const untracked = await run([...GLOBAL, 'ls-files', '--others', '--exclude-standard', '-z', ...scope], root);\n const known = new Set(changes.map(file => file.path));\n for (const path of nulFields(untracked.stdout)) if (!known.has(path)) { changes.push({ path, status: 'added' }); known.add(path); }\n }\n if (!changes.length && head && !options.staged && !options.explicitRef && !paths.length) {\n const parent = await revision(run, root, `${head}^`);\n if (parent) { base = parent; source = 'previous-commit'; changes = await list(base); }\n }\n if (changes.length > MAX_FILES) throw new Error('变更超过 200 个文件,请通过路径缩小审查范围。');\n if (options.staged) await assertStagedClean(run, root, changes.flatMap(file => file.oldPath ? [file.oldPath, file.path] : [file.path]));\n const files: ReviewFile[] = [];\n const skipped: { path: string; reason: string }[] = [];\n for (const file of changes) {\n if (['deleted', 'type-changed', 'unmerged', 'unknown', 'broken'].includes(file.status)) {\n skipped.push({ path: file.path, reason: `不可编辑的文件状态:${file.status}` });\n continue;\n }\n let before;\n try { before = await fingerprint(root, file.path); }\n catch (error) {\n if (!head && (error as NodeJS.ErrnoException).code === 'ENOENT') { skipped.push({ path: file.path, reason: '新仓库中已从工作区删除' }); continue; }\n throw error;\n }\n if ('reason' in before) { skipped.push({ path: file.path, reason: before.reason }); continue; }\n let ranges: LineRange[] = [];\n if (file.status !== 'added') {\n const diff = await run([...GLOBAL, ...DIFF, '--unified=0', '--inter-hunk-context=0', ...(options.staged ? ['--cached'] : [base!]), '--', ...(file.oldPath ? [file.oldPath] : []), file.path], root);\n ranges = parseChangedLines(diff.stdout);\n const after = await fingerprint(root, file.path);\n if (!('sha256' in after) || after.sha256 !== before.sha256) throw new Error(`文件在收集范围时发生变化:${JSON.stringify(file.path)},请重试。`);\n if (!ranges.length) { skipped.push({ path: file.path, reason: '没有可简化的当前行(纯删除、仅重命名或非文本 diff)' }); continue; }\n }\n files.push({ ...file, ranges, sha256: before.sha256 });\n }\n const review: Review = { root, head, base, source, staged: options.staged, paths, indexSnapshot, files, skipped };\n await verifyReview(run, review);\n return review;\n}\n\n/** 在提交提示词前复核内容及 HEAD;这不是 Agent 后续写入权限的硬限制。 */\nexport async function verifyReview(run: GitRunner, review: Review): Promise<void> {\n if (await revision(run, review.root, 'HEAD') !== review.head) throw new Error('HEAD 在收集范围后发生变化,请重新运行 /simplify。');\n if (review.staged) {\n const index = await run([...GLOBAL, 'ls-files', '--stage', '-z', '--', ...review.paths], review.root);\n if (index.stdout !== review.indexSnapshot) throw new Error('暂存区在收集范围后发生变化,请重新运行 /simplify。');\n await assertStagedClean(run, review.root, review.files.map(file => file.path));\n }\n for (const file of review.files) {\n const current = await fingerprint(review.root, file.path);\n if (!('sha256' in current) || current.sha256 !== file.sha256) throw new Error(`文件已变化:${JSON.stringify(file.path)},请重新运行 /simplify。`);\n }\n}\n"]}
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAqB/D,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACvC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC;AACpC,MAAM,MAAM,GAA2B,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;AAC3K,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,eAAe,EA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IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjF,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACvI,CAAC;AACH,CAAC","sourcesContent":["import type { SimplifyOptions } from './args.js';\nimport { createHash } from 'node:crypto';\nimport { lstat, open, realpath } from 'node:fs/promises';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nexport type GitRunner = (args: readonly string[], cwd: string, allowedCodes?: readonly number[]) => Promise<{ code: number; stdout: string }>;\n\nexport interface LineRange { readonly start: number; readonly end: number }\ninterface Change { readonly path: string; readonly status: string; readonly oldPath?: string }\nexport interface ReviewFile extends Change {\n readonly ranges: readonly LineRange[];\n readonly sha256: string;\n}\nexport interface Review {\n readonly root: string;\n readonly head: string | undefined;\n readonly base: string | undefined;\n readonly staged: boolean;\n readonly paths: readonly string[];\n readonly indexSnapshot: string | undefined;\n readonly source: 'worktree' | 'staged' | 'ref' | 'previous-commit';\n readonly files: readonly ReviewFile[];\n readonly skipped: readonly { path: string; reason: string }[];\n}\nconst MAX_FILES = 200;\nconst MAX_FILE_BYTES = 5 * 1024 * 1024;\nconst MAX_REVIEW_RANGES = 4_096;\nconst MAX_REVIEW_BYTES = 128 * 1024;\nconst STATUS: Record<string, string> = { A: 'added', M: 'modified', R: 'renamed', C: 'copied', D: 'deleted', T: 'type-changed', U: 'unmerged', X: 'unknown', B: 'broken' };\nconst DIFF = ['diff', '--no-color', '--no-ext-diff', '--no-textconv', '--no-relative', '--ignore-submodules=all', '--find-renames'];\nconst GLOBAL = ['--no-pager', '--literal-pathspecs', '-c', 'color.ui=false'];\n\n/** 解析 Git -z 文件列表,拒绝不完整记录以免把截断输出当作完整范围。 */\nexport function nulFields(text: string): string[] {\n if (!text) return [];\n if (!text.endsWith('\\0')) throw new Error('Git 文件列表不完整。');\n return text.slice(0, -1).split('\\0');\n}\n\nexport function parseNameStatus(text: string): Change[] {\n const fields = nulFields(text);\n const files: Change[] = [];\n for (let i = 0; i < fields.length;) {\n const code = fields[i++]!;\n const status = STATUS[code[0]!];\n const first = fields[i++];\n if (!status || !first || !/^[ACDMRTUXB]\\d*$/u.test(code)) throw new Error('Git 文件状态格式无效。');\n if (code.startsWith('R') || code.startsWith('C')) {\n const path = fields[i++];\n if (!path) throw new Error('Git 重命名记录不完整。');\n files.push({ path, oldPath: first, status });\n } else files.push({ path: first, status });\n }\n return files;\n}\n\n/** 按 unified diff 正文计数;maxRanges 为剩余离散行范围额度,超额或正文不完整时抛错。 */\nexport function parseChangedLines(text: string, maxRanges = MAX_REVIEW_RANGES): LineRange[] {\n if (!Number.isSafeInteger(maxRanges) || maxRanges < 0 || maxRanges > MAX_REVIEW_RANGES) throw new Error('行范围额度无效。');\n const result: LineRange[] = [];\n let block: { oldLeft: number; newLeft: number; cursor: number } | undefined;\n let segment: number | undefined;\n const flush = (): void => {\n if (segment !== undefined && block) {\n if (result.length >= maxRanges) throw new Error('审查行范围超过 4096 个,请通过路径缩小审查范围。');\n result.push({ start: segment, end: block.cursor - 1 });\n }\n segment = undefined;\n };\n const finish = (): void => {\n if (block && (block.oldLeft !== 0 || block.newLeft !== 0)) throw new Error('Git 补丁正文不完整。');\n flush();\n block = undefined;\n };\n // 逐行消费已有 diff 字符串,避免先分配整份行数组,再因范围超限丢弃。\n for (let offset = 0; offset < text.length;) {\n const newline = text.indexOf('\\n', offset);\n const row = text.slice(offset, newline < 0 ? text.length : newline);\n offset = newline < 0 ? text.length : newline + 1;\n if (row.startsWith('@@')) {\n finish();\n const header = /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(?: .*)?$/u.exec(row);\n if (!header) throw new Error('Git 补丁块头无效。');\n const [oldStart, oldLeft, cursor, newLeft] = [Number(header[1]), Number(header[2] ?? 1), Number(header[3]), Number(header[4] ?? 1)];\n for (const [start, count] of [[oldStart!, oldLeft!], [cursor!, newLeft!]]) {\n if (!Number.isSafeInteger(start) || !Number.isSafeInteger(count) || !Number.isSafeInteger(start! + count!) || (count! > 0 && start === 0)) {\n throw new Error('Git 补丁行号超出有效范围。');\n }\n }\n block = { oldLeft: oldLeft!, newLeft: newLeft!, cursor: cursor! };\n continue;\n }\n if (row.startsWith('diff --git ')) { finish(); continue; }\n if (!block) continue;\n if (row === '\\\') continue;\n switch (row[0]) {\n case '+':\n segment ??= block.cursor;\n block.cursor++;\n block.newLeft--;\n break;\n case '-':\n block.oldLeft--;\n break;\n case ' ':\n flush();\n block.cursor++;\n block.oldLeft--;\n block.newLeft--;\n break;\n default:\n throw new Error('Git 补丁正文格式无效。');\n }\n if (block.oldLeft < 0 || block.newLeft < 0) throw new Error('Git 补丁正文超过声明行数。');\n }\n finish();\n return result;\n}\n\nfunction inside(root: string, path: string): boolean {\n const rel = relative(root, path);\n return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);\n}\n\nasync function fingerprint(root: string, path: string): Promise<{ sha256: string } | { reason: string }> {\n const absolute = resolve(root, path);\n if (!inside(root, absolute)) throw new Error('Git 返回了仓库外路径。');\n const stat = await lstat(absolute);\n if (!stat.isFile()) return { reason: '非普通文件(符号链接或子模块等)' };\n if (!inside(root, await realpath(absolute))) return { reason: '路径指向仓库外' };\n if (stat.size > MAX_FILE_BYTES) return { reason: '文件超过 5 MiB' };\n const handle = await open(absolute, 'r');\n try {\n const buffer = Buffer.alloc(Math.min(stat.size + 1, MAX_FILE_BYTES + 1));\n let offset = 0;\n while (offset < buffer.length) {\n const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, null);\n if (!bytesRead) break;\n offset += bytesRead;\n }\n if (offset !== stat.size) throw new Error(`文件在读取时发生变化:${JSON.stringify(path)},请重试。`);\n const content = buffer.subarray(0, offset);\n if (content.includes(0)) return { reason: '二进制文件' };\n return { sha256: createHash('sha256').update(content).digest('hex') };\n } finally { await handle.close(); }\n}\n\nasync function revision(run: GitRunner, root: string, ref: string): Promise<string | undefined> {\n const result = await run([...GLOBAL, 'rev-parse', '--verify', '--quiet', '--end-of-options', `${ref}^{commit}`], root, [0, 1]);\n return result.code === 0 ? result.stdout.trim() : undefined;\n}\n\nasync function assertStagedClean(run: GitRunner, root: string, paths: readonly string[]): Promise<void> {\n if (!paths.length) return;\n const result = await run([...GLOBAL, ...DIFF, '--name-only', '-z', '--', ...paths], root);\n if (result.stdout) throw new Error('待审查的暂存文件还有未暂存改动。请先暂存或自行保存这些改动,再运行 --staged。');\n}\n\n/** 收集可审查文本文件及行号快照;Git 失败、冲突或不可靠范围会抛错,不产生部分成功。 */\nexport async function collectReview(run: GitRunner, cwd: string, options: SimplifyOptions): Promise<Review> {\n if (!cwd) throw new Error('当前会话没有工作目录。');\n const rootResult = await run([...GLOBAL, 'rev-parse', '--show-toplevel'], cwd);\n const root = await realpath(rootResult.stdout.replace(/\\r?\\n$/u, ''));\n const sessionRoot = await realpath(cwd);\n if (!inside(root, sessionRoot)) throw new Error('当前会话工作目录不在 Git 返回的仓库内。');\n const paths = options.files.map(path => {\n const absolute = resolve(sessionRoot, path);\n if (!inside(root, absolute)) throw new Error(`路径不在当前仓库内:${JSON.stringify(path)}`);\n return relative(root, absolute).split(sep).join('/') || '.';\n });\n const head = await revision(run, root, 'HEAD');\n let base = options.explicitRef ? await revision(run, root, options.ref) : head;\n if (options.explicitRef && !base) throw new Error(`无效的 Git 引用:${options.ref}`);\n let source: Review['source'] = options.staged ? 'staged' : options.explicitRef ? 'ref' : 'worktree';\n const scope = ['--', ...paths];\n const indexSnapshot = options.staged ? (await run([...GLOBAL, 'ls-files', '--stage', '-z', ...scope], root)).stdout : undefined;\n const conflicts = await run([...GLOBAL, 'ls-files', '--unmerged', '-z', ...scope], root);\n if (conflicts.stdout) throw new Error('所选范围存在未解决的 Git 冲突,请先解决冲突。');\n for (const path of paths) {\n const existing = await run([...GLOBAL, 'ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', path], root);\n if (!existing.stdout) throw new Error(`路径不存在、被忽略或未纳入 Git:${JSON.stringify(path)}`);\n }\n const list = async (ref: string | undefined): Promise<Change[]> => {\n if (!ref && !options.staged) {\n const tracked = await run([...GLOBAL, 'ls-files', '--cached', '-z', ...scope], root);\n return [...new Set(nulFields(tracked.stdout))].map(path => ({ path, status: 'added' }));\n }\n const result = await run([...GLOBAL, ...DIFF, '--name-status', '-z', ...(options.staged ? ['--cached'] : [ref!]), ...scope], root);\n return parseNameStatus(result.stdout);\n };\n let changes = await list(base);\n if (!options.staged) {\n const untracked = await run([...GLOBAL, 'ls-files', '--others', '--exclude-standard', '-z', ...scope], root);\n const known = new Set(changes.map(file => file.path));\n for (const path of nulFields(untracked.stdout)) if (!known.has(path)) { changes.push({ path, status: 'added' }); known.add(path); }\n }\n if (!changes.length && head && !options.staged && !options.explicitRef && !paths.length) {\n const parent = await revision(run, root, `${head}^`);\n if (parent) { base = parent; source = 'previous-commit'; changes = await list(base); }\n }\n if (changes.length > MAX_FILES) throw new Error('变更超过 200 个文件,请通过路径缩小审查范围。');\n if (options.staged) await assertStagedClean(run, root, changes.flatMap(file => file.oldPath ? [file.oldPath, file.path] : [file.path]));\n const files: ReviewFile[] = [];\n const skipped: { path: string; reason: string }[] = [];\n let rangeCount = 0;\n let metadataBytes = 0;\n const accountMetadata = (value: unknown): void => {\n metadataBytes += Buffer.byteLength(JSON.stringify(value), 'utf8');\n if (metadataBytes > MAX_REVIEW_BYTES) throw new Error('审查清单超过 128 KiB,请通过路径缩小审查范围。');\n };\n accountMetadata({ root, head, base, source, staged: options.staged, paths });\n const skip = (path: string, reason: string): void => {\n const file = { path, reason };\n accountMetadata(file);\n skipped.push(file);\n };\n for (const file of changes) {\n if (['deleted', 'type-changed', 'unmerged', 'unknown', 'broken'].includes(file.status)) {\n skip(file.path, `不可编辑的文件状态:${file.status}`);\n continue;\n }\n let before;\n try { before = await fingerprint(root, file.path); }\n catch (error) {\n if (!head && (error as NodeJS.ErrnoException).code === 'ENOENT') { skip(file.path, '新仓库中已从工作区删除'); continue; }\n throw error;\n }\n if ('reason' in before) { skip(file.path, before.reason); continue; }\n let ranges: LineRange[] = [];\n if (file.status !== 'added') {\n const diff = await run([...GLOBAL, ...DIFF, '--unified=0', '--inter-hunk-context=0', ...(options.staged ? ['--cached'] : [base!]), '--', ...(file.oldPath ? [file.oldPath] : []), file.path], root);\n ranges = parseChangedLines(diff.stdout, MAX_REVIEW_RANGES - rangeCount);\n rangeCount += ranges.length;\n const after = await fingerprint(root, file.path);\n if (!('sha256' in after) || after.sha256 !== before.sha256) throw new Error(`文件在收集范围时发生变化:${JSON.stringify(file.path)},请重试。`);\n if (!ranges.length) { skip(file.path, '没有可简化的当前行(纯删除、仅重命名或非文本 diff)'); continue; }\n }\n const reviewed = { ...file, ranges, sha256: before.sha256 };\n accountMetadata(reviewed);\n files.push(reviewed);\n }\n const review: Review = { root, head, base, source, staged: options.staged, paths, indexSnapshot, files, skipped };\n await verifyReview(run, review);\n return review;\n}\n\n/** 在提交提示词前复核内容及 HEAD;这不是 Agent 后续写入权限的硬限制。 */\nexport async function verifyReview(run: GitRunner, review: Review): Promise<void> {\n if (await revision(run, review.root, 'HEAD') !== review.head) throw new Error('HEAD 在收集范围后发生变化,请重新运行 /simplify。');\n if (review.staged) {\n const index = await run([...GLOBAL, 'ls-files', '--stage', '-z', '--', ...review.paths], review.root);\n if (index.stdout !== review.indexSnapshot) throw new Error('暂存区在收集范围后发生变化,请重新运行 /simplify。');\n await assertStagedClean(run, review.root, review.files.map(file => file.path));\n }\n for (const file of review.files) {\n const current = await fingerprint(review.root, file.path);\n if (!('sha256' in current) || current.sha256 !== file.sha256) throw new Error(`文件已变化:${JSON.stringify(file.path)},请重新运行 /simplify。`);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michengai/dsh-simplify",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "DSH 代码简化插件:限定 Git 变更范围,支持未跟踪文件、跨平台路径与可靠的 Git 异常处理",
5
5
  "repository": { "type": "git", "url": "git+https://github.com/MichengAI/dsh-simplify.git" },
6
6
  "homepage": "https://github.com/MichengAI/dsh-simplify#readme",
@@ -32,6 +32,7 @@
32
32
  "@deepseek-ai/dsh-commands": "0.1.2-rc.1",
33
33
  "@deepseek-ai/dsh-llm": "0.1.2-rc.1",
34
34
  "@deepseek-ai/dsh-subprocess": "0.1.2-rc.1",
35
+ "@deepseek-ai/dsh-subprocess-local": "0.1.2-rc.1",
35
36
  "@types/node": "^22.19.0",
36
37
  "typescript": "~5.7.2"
37
38
  }