@michengai/dsh-simplify 0.1.1 → 0.1.3
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 +19 -0
- package/CHANGELOG.zh-CN.md +19 -0
- package/README.md +70 -24
- package/README.zh-CN.md +70 -24
- package/lib/exec.js +9 -1
- package/lib/exec.js.map +1 -1
- package/lib/git.d.ts +2 -2
- package/lib/git.js +39 -11
- package/lib/git.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
[简体中文](CHANGELOG.zh-CN.md)
|
|
4
4
|
|
|
5
|
+
## 0.1.3 - 2026-09-10
|
|
6
|
+
|
|
7
|
+
- Update the development host to DSH `0.1.5-rc.1` and explicitly support `0.1.0-rc.8`, `0.1.1-rc.2`, `0.1.2-rc.1`, and `0.1.5-rc.1` as peers. All four hosts pass isolated type, 41-test, package installation, and import checks on Windows.
|
|
8
|
+
- Resolve host integration tests from project dependencies by default to avoid testing against a different personal DSH installation.
|
|
9
|
+
- Validate one live-model headless simplification scenario on each supported host, including target edits, behavior preservation, and file scope; document full-host setup and Web UI validation limits.
|
|
10
|
+
- The two earliest hosts required explicit peer setup after npm resolution stalled; headless validation does not cover ordinary full-host installation or Web UI behavior.
|
|
11
|
+
- Align npm, Release archive, and source installation instructions with `0.1.3`, restore npmjs lockfile URLs without changing package versions or integrity, and ignore local CodeGraph files.
|
|
12
|
+
- Require valid, matching release dates in both changelogs before publishing; add seven release validation regression cases.
|
|
13
|
+
|
|
14
|
+
## 0.1.2 - 2026-09-06
|
|
15
|
+
|
|
16
|
+
- Fix inherited Git environment settings selecting the wrong repository or staging area, including in linked worktrees.
|
|
17
|
+
- Stop collecting excessively fragmented changes or oversized review lists early and ask for a narrower scope.
|
|
18
|
+
- Clarify that new files before the initial commit are eligible for whole-file simplification.
|
|
19
|
+
|
|
20
|
+
### Known Issues
|
|
21
|
+
|
|
22
|
+
- 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.
|
|
23
|
+
|
|
5
24
|
## 0.1.1 - 2026-09-06
|
|
6
25
|
|
|
7
26
|
- Update the documentation in the package to focus on features, usage scope, and known issues. Code simplification behavior is unchanged from `0.1.0`.
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CHANGELOG.md)
|
|
4
4
|
|
|
5
|
+
## 0.1.3 - 2026-09-10
|
|
6
|
+
|
|
7
|
+
- 开发宿主升级至 DSH `0.1.5-rc.1`,peer 显式支持 `0.1.0-rc.8`、`0.1.1-rc.2`、`0.1.2-rc.1`、`0.1.5-rc.1`;四个版本均通过 Windows 隔离类型检查、41 项测试、打包安装及导入检查。
|
|
8
|
+
- 宿主集成测试默认使用项目依赖,避免误用个人 DSH 安装中的其他版本。
|
|
9
|
+
- 四个支持版本各完成一例真实模型 headless 简化验收,核对实际修改、行为不变及文件范围,并说明完整宿主准备和 Web 界面验证边界。
|
|
10
|
+
- 两个最早版本的宿主因 npm 解析停滞而显式补齐 peer;headless 验收不覆盖普通完整宿主安装或 Web 界面行为。
|
|
11
|
+
- 将 npm、Release 安装包及源码安装说明统一为 `0.1.3`;锁文件恢复 npmjs 地址,保持版本及 integrity 不变,并忽略本地 CodeGraph 文件。
|
|
12
|
+
- 发布前要求双语变更记录填写有效且一致的日期,新增七个发布校验回归用例。
|
|
13
|
+
|
|
14
|
+
## 0.1.2 - 2026-09-06
|
|
15
|
+
|
|
16
|
+
- 修复父进程 Git 环境设置导致审查仓库或暂存区选择错误的问题,支持普通仓库与 worktree。
|
|
17
|
+
- 对过于零碎的改动和超大审查清单提前停止,并提示缩小范围,避免收集大量最终无法提交的内容。
|
|
18
|
+
- 明确没有首次提交时新增文件按整文件整理的范围说明。
|
|
19
|
+
|
|
20
|
+
### 已知问题
|
|
21
|
+
|
|
22
|
+
- 没有可简化的代码行时,不会启动 Agent;部分宿主界面可能未显示结果,看起来像命令没有响应。
|
|
23
|
+
|
|
5
24
|
## 0.1.1 - 2026-09-06
|
|
6
25
|
|
|
7
26
|
- 更新安装包中的说明文档,聚焦功能、使用范围与已知问题。代码简化行为与 `0.1.0` 一致。
|
package/README.md
CHANGED
|
@@ -16,27 +16,54 @@
|
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Use `/simplify` in DeepSeek Harness to make recently changed code easier to read and maintain.
|
|
20
20
|
|
|
21
21
|
This is a community-maintained plugin, not an official DeepSeek AI product. It supports DSH Web and desktop apps that include DSH Web.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Command messages and prompts are in Simplified Chinese.
|
|
24
|
+
|
|
25
|
+
Compatibility: supports DSH `0.1.0-rc.8`, `0.1.1-rc.2`, `0.1.2-rc.1`, and `0.1.5-rc.1`; development dependencies are pinned to `0.1.5-rc.1`.
|
|
24
26
|
|
|
25
27
|
## Features
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
29
|
+
After a round of coding, use `/simplify` to ask the current Agent to improve the clarity of your changes while preserving behavior.
|
|
30
|
+
|
|
31
|
+
- **Focus on your changes**: use the Git change scope to keep the request centered on relevant code.
|
|
32
|
+
- **Include new files**: review new files in full, including repositories without an initial commit.
|
|
33
|
+
- **Choose the right scope**: review workspace changes by default, or select staged changes, a commit, or paths.
|
|
34
|
+
- **Review after committing**: when the workspace is clean, the default mode can review the most recent commit.
|
|
35
|
+
- **Stop when the scope is unreliable**: conflicts, file changes, or read failures return a reason so you can fix the issue and retry.
|
|
36
|
+
|
|
37
|
+
The command queues a simplification task. Check the Agent’s subsequent response and actual diff to confirm edits and validation are complete.
|
|
38
|
+
|
|
39
|
+
## DSH product ecosystem
|
|
40
|
+
|
|
41
|
+
For a ready-to-use workbench, download [DSH Codex Desktop](https://github.com/MichengAI/dsh-codex-desktop/releases). If you already use [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness), install any of these eight plugins individually. The desktop app includes all eight.
|
|
42
|
+
|
|
43
|
+
| Plugin | What you can do |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| [Codex UI](https://github.com/MichengAI/dsh-codex-ui) | Organize projects and conversations, search tasks, and navigate chat turns |
|
|
46
|
+
| [IM Connect](https://github.com/MichengAI/dsh-im-connect) | Send tasks and receive replies through your usual messenger |
|
|
47
|
+
| [Automation](https://github.com/MichengAI/dsh-automation) | Schedule tasks and review each run |
|
|
48
|
+
| [Skills Manager](https://github.com/MichengAI/dsh-skills-manager) | Find, enable, create, and import local skills |
|
|
49
|
+
| [Archive Manager](https://github.com/MichengAI/dsh-archive-manager) | Search, restore, or clean up archived conversations |
|
|
50
|
+
| [Agency Agents](https://github.com/MichengAI/dsh-agency-agents) | Choose and summon specialists for your task |
|
|
51
|
+
| [BTW](https://github.com/MichengAI/dsh-btw) | Ask side questions without interrupting the main task |
|
|
52
|
+
| [Simplify](https://github.com/MichengAI/dsh-simplify) | Use /simplify to improve code within your Git changes |
|
|
34
53
|
|
|
35
54
|
## Installation
|
|
36
55
|
|
|
37
|
-
Requires Node.js >= 22.19, Git on PATH, and DSH
|
|
56
|
+
Requires Node.js >= 22.19, Git on PATH, and DSH with the `commands` and `subprocess` services. The session must have a local Git working directory. Plugin `0.1.3` supports the four host versions listed above.
|
|
57
|
+
|
|
58
|
+
The current version is `0.1.3`, 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.
|
|
59
|
+
|
|
60
|
+
### Ask an agent to install it (recommended)
|
|
61
|
+
|
|
62
|
+
Send the prompt below to any agent that can run terminal commands on your computer. Replace `web` with your actual profile. Once installed, use the plugin in DSH.
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
```text
|
|
65
|
+
Install the DSH plugin @michengai/dsh-simplify into my local web profile by running: dsh plugin --profile web add @michengai/dsh-simplify@0.1.3 --registry=https://registry.npmjs.org/. Then run dsh --profile web --dump-config, confirm the configuration includes michengai-simplify, and explain how to reload DSH and start using the plugin.
|
|
66
|
+
```
|
|
40
67
|
|
|
41
68
|
### From npm
|
|
42
69
|
|
|
@@ -44,33 +71,33 @@ The current version is `0.1.1`, available through npm, a packaged archive, or so
|
|
|
44
71
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
45
72
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
46
73
|
|
|
47
|
-
dsh plugin --profile web add @michengai/dsh-simplify@0.1.
|
|
74
|
+
dsh plugin --profile web add @michengai/dsh-simplify@0.1.3 --registry=https://registry.npmjs.org/
|
|
48
75
|
```
|
|
49
76
|
|
|
50
|
-
### From
|
|
77
|
+
### From a Local Package
|
|
78
|
+
|
|
79
|
+
Download the published tgz from the [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.3), then run this from the package directory:
|
|
51
80
|
|
|
52
81
|
```powershell
|
|
53
82
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
54
83
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
55
84
|
|
|
56
|
-
|
|
57
|
-
Set-Location dsh-simplify
|
|
58
|
-
npm ci --ignore-scripts
|
|
59
|
-
npm run check
|
|
60
|
-
dsh plugin --profile web add . --ignore-scripts
|
|
85
|
+
dsh plugin --profile web add .\michengai-dsh-simplify-0.1.3.tgz --ignore-scripts
|
|
61
86
|
```
|
|
62
87
|
|
|
63
|
-
|
|
88
|
+
### Build from Source
|
|
64
89
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Download the tgz from the [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.1), or run `npm pack` in the source directory, then run this from the package directory:
|
|
90
|
+
Run from the repository root:
|
|
68
91
|
|
|
69
92
|
```powershell
|
|
70
93
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
71
94
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
72
95
|
|
|
73
|
-
|
|
96
|
+
npm ci
|
|
97
|
+
if ($LASTEXITCODE -ne 0) { throw 'npm ci failed' }
|
|
98
|
+
npm pack
|
|
99
|
+
if ($LASTEXITCODE -ne 0) { throw 'npm pack failed' }
|
|
100
|
+
dsh plugin --profile web add .\michengai-dsh-simplify-0.1.3.tgz --ignore-scripts
|
|
74
101
|
```
|
|
75
102
|
|
|
76
103
|
### Reload and Verify
|
|
@@ -94,7 +121,7 @@ Run `dsh --profile web --dump-config` and confirm that it includes `michengai-si
|
|
|
94
121
|
- Paths are relative to the session directory. Absolute paths inside the repository are supported; prompts use paths relative to the repository root.
|
|
95
122
|
- Single and double quotes group paths containing spaces; backslashes remain path characters. No shell expansion, wildcard expansion, or command substitution is performed.
|
|
96
123
|
- `--ref` accepts branches, tags, and single-commit expressions, not `a..b` or `a...b`. It cannot be combined with `--staged`.
|
|
97
|
-
-
|
|
124
|
+
- 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
125
|
- Previous-commit fallback compares HEAD with its first parent. Merge commits do not receive a multi-parent review.
|
|
99
126
|
|
|
100
127
|
## Command Results
|
|
@@ -121,10 +148,14 @@ Run `dsh --profile web --dump-config` and confirm that it includes `michengai-si
|
|
|
121
148
|
|
|
122
149
|
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
150
|
|
|
151
|
+
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.
|
|
152
|
+
|
|
124
153
|
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
154
|
|
|
126
155
|
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
156
|
|
|
157
|
+
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.
|
|
158
|
+
|
|
128
159
|
`--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
160
|
|
|
130
161
|
**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.
|
|
@@ -144,6 +175,21 @@ Reload DSH manually if the desktop app does not reload automatically. Uninstalli
|
|
|
144
175
|
|
|
145
176
|
## Development and Verification
|
|
146
177
|
|
|
178
|
+
### From Source
|
|
179
|
+
|
|
180
|
+
```powershell
|
|
181
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
182
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
183
|
+
|
|
184
|
+
git clone https://github.com/MichengAI/dsh-simplify.git
|
|
185
|
+
Set-Location dsh-simplify
|
|
186
|
+
npm ci --ignore-scripts
|
|
187
|
+
npm run check
|
|
188
|
+
dsh plugin --profile web add . --ignore-scripts
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The entry point is `lib/index.js`, so build before installing. Keep the source directory when the profile uses a local link.
|
|
192
|
+
|
|
147
193
|
```powershell
|
|
148
194
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
149
195
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
package/README.zh-CN.md
CHANGED
|
@@ -16,27 +16,54 @@
|
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
DeepSeek Harness
|
|
19
|
+
DeepSeek Harness 代码简化插件。用 `/simplify` 整理刚改过的代码,让后续阅读和维护更轻松。
|
|
20
20
|
|
|
21
21
|
本项目为社区插件,并非 DeepSeek AI 官方产品。支持 DSH Web 及集成 DSH Web 的桌面应用。
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
命令文案及提示词使用简体中文。
|
|
24
|
+
|
|
25
|
+
兼容性:支持 DSH `0.1.0-rc.8`、`0.1.1-rc.2`、`0.1.2-rc.1`、`0.1.5-rc.1`,开发依赖固定为 `0.1.5-rc.1`。
|
|
24
26
|
|
|
25
27
|
## 功能概览
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
29
|
+
写完一轮代码后,用 `/simplify` 请当前 Agent 整理刚改过的部分,改善可读性并保持原有功能。
|
|
30
|
+
|
|
31
|
+
- **聚焦本次改动**:按 Git 变更范围整理代码,避免把需求扩大到无关文件。
|
|
32
|
+
- **覆盖新增文件**:新文件可以整份审查,也支持尚无首次提交的仓库。
|
|
33
|
+
- **选择适合的范围**:默认检查工作区改动,也可仅检查暂存区、指定提交或路径。
|
|
34
|
+
- **提交后也能回看**:默认模式在工作区没有改动时,可回看最近一次提交。
|
|
35
|
+
- **范围不可靠时停止**:遇到冲突、文件变化或读取失败时返回原因,便于修正后重试。
|
|
36
|
+
|
|
37
|
+
命令提交的是简化任务;是否完成修改和验证,应以 Agent 后续回复和实际差异为准。
|
|
38
|
+
|
|
39
|
+
## DSH 产品生态
|
|
40
|
+
|
|
41
|
+
想直接使用完整工作台,可下载 [DSH Codex Desktop](https://github.com/MichengAI/dsh-codex-desktop/releases);已有 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 环境,可按需独立安装以下 8 个自研插件。桌面端已随附这些插件。
|
|
42
|
+
|
|
43
|
+
| 插件 | 你可以用它做什么 |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| [Codex UI](https://github.com/MichengAI/dsh-codex-ui) | 整理项目与会话、搜索任务、跳转对话轮次 |
|
|
46
|
+
| [IM Connect](https://github.com/MichengAI/dsh-im-connect) | 从微信、飞书、钉钉等消息平台下任务、收回复 |
|
|
47
|
+
| [Automation](https://github.com/MichengAI/dsh-automation) | 按计划执行任务,查看每次运行的结果 |
|
|
48
|
+
| [Skills Manager](https://github.com/MichengAI/dsh-skills-manager) | 统一查找、启停、创建和导入本机技能 |
|
|
49
|
+
| [Archive Manager](https://github.com/MichengAI/dsh-archive-manager) | 搜索、恢复或清理已归档会话 |
|
|
50
|
+
| [Agency Agents](https://github.com/MichengAI/dsh-agency-agents) | 按任务选择并召唤专业角色 |
|
|
51
|
+
| [BTW](https://github.com/MichengAI/dsh-btw) | 在当前上下文中临时旁问,不打断主任务 |
|
|
52
|
+
| [Simplify](https://github.com/MichengAI/dsh-simplify) | 用 /simplify 整理 Git 改动范围内的代码 |
|
|
34
53
|
|
|
35
54
|
## 安装
|
|
36
55
|
|
|
37
|
-
要求 Node.js >= 22.19、PATH 中可执行的 Git,以及提供 `commands`、`subprocess` 服务的 DSH `0.1.
|
|
56
|
+
要求 Node.js >= 22.19、PATH 中可执行的 Git,以及提供 `commands`、`subprocess` 服务的 DSH。会话需要关联本地 Git 工作目录。插件 `0.1.3` 支持上文列出的四个宿主版本。
|
|
57
|
+
|
|
58
|
+
当前版本为 `0.1.3`,支持 npm、安装包和源码安装。以下示例使用 `web` profile,请按实际环境替换。安装前停用其他注册 `/simplify` 的插件。
|
|
59
|
+
|
|
60
|
+
### 让 Agent 帮你安装(推荐)
|
|
61
|
+
|
|
62
|
+
把下面这段话发给任意能够执行本机终端命令的 Agent。将 `web` 替换为实际使用的 profile;安装完成后,在 DSH 中使用本插件。
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
```text
|
|
65
|
+
请将 DSH 插件 @michengai/dsh-simplify 安装到本机 web profile,执行:dsh plugin --profile web add @michengai/dsh-simplify@0.1.3 --registry=https://registry.npmjs.org/。安装后执行 dsh --profile web --dump-config,确认配置包含 michengai-simplify,并告诉我如何重新加载 DSH 和开始使用。
|
|
66
|
+
```
|
|
40
67
|
|
|
41
68
|
### 从 npm 安装
|
|
42
69
|
|
|
@@ -44,33 +71,33 @@ DeepSeek Harness 代码简化插件。运行 `/simplify` 后,插件收集 Git
|
|
|
44
71
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
45
72
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
46
73
|
|
|
47
|
-
dsh plugin --profile web add @michengai/dsh-simplify@0.1.
|
|
74
|
+
dsh plugin --profile web add @michengai/dsh-simplify@0.1.3 --registry=https://registry.npmjs.org/
|
|
48
75
|
```
|
|
49
76
|
|
|
50
|
-
###
|
|
77
|
+
### 从本地安装包安装
|
|
78
|
+
|
|
79
|
+
从 [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.3) 下载已发布的 tgz,然后在安装包所在目录执行:
|
|
51
80
|
|
|
52
81
|
```powershell
|
|
53
82
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
54
83
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
55
84
|
|
|
56
|
-
|
|
57
|
-
Set-Location dsh-simplify
|
|
58
|
-
npm ci --ignore-scripts
|
|
59
|
-
npm run check
|
|
60
|
-
dsh plugin --profile web add . --ignore-scripts
|
|
85
|
+
dsh plugin --profile web add .\michengai-dsh-simplify-0.1.3.tgz --ignore-scripts
|
|
61
86
|
```
|
|
62
87
|
|
|
63
|
-
|
|
88
|
+
### 从源码打包安装
|
|
64
89
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
从 [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.1) 下载 tgz,或在源码目录运行 `npm pack` 生成安装包,然后在安装包所在目录执行:
|
|
90
|
+
在仓库根目录执行:
|
|
68
91
|
|
|
69
92
|
```powershell
|
|
70
93
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
71
94
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
72
95
|
|
|
73
|
-
|
|
96
|
+
npm ci
|
|
97
|
+
if ($LASTEXITCODE -ne 0) { throw 'npm ci failed' }
|
|
98
|
+
npm pack
|
|
99
|
+
if ($LASTEXITCODE -ne 0) { throw 'npm pack failed' }
|
|
100
|
+
dsh plugin --profile web add .\michengai-dsh-simplify-0.1.3.tgz --ignore-scripts
|
|
74
101
|
```
|
|
75
102
|
|
|
76
103
|
### 重新加载与确认
|
|
@@ -94,7 +121,7 @@ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.1.tgz --ignore-scripts
|
|
|
94
121
|
- 路径相对当前会话目录,支持仓库内绝对路径;提示词统一使用仓库根目录相对路径。
|
|
95
122
|
- 支持单双引号组合带空格路径,反斜杠按路径字符保留;不执行 Shell 展开、通配符或命令替换。
|
|
96
123
|
- `--ref` 支持分支、标签和单个提交表达式,不支持 `a..b` / `a...b`;不能与 `--staged` 混用。
|
|
97
|
-
-
|
|
124
|
+
- 没有首次提交时,所选范围内的文件视为新增文件,允许整文件整理:默认包含暂存与未跟踪文件,`--staged` 仅包含暂存文件。可指定文件或目录缩小范围,文件数量和大小限制仍然生效。只有一个提交且工作区干净时直接返回无变更。
|
|
98
125
|
- 上一提交回看相对于 HEAD 第一父提交;merge commit 不做多父合并审查。
|
|
99
126
|
|
|
100
127
|
## 命令结果
|
|
@@ -121,10 +148,14 @@ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.1.tgz --ignore-scripts
|
|
|
121
148
|
|
|
122
149
|
插件只执行 Git 只读查询和读取本地文件,不自动 `git add`、提交、重置或存储工作区。Git 参数通过 DSH `subprocess` 的 `argv` 传递,不依赖 PowerShell/Bash 引用规则。
|
|
123
150
|
|
|
151
|
+
仓库和索引依据会话工作目录及 Git worktree 元数据确定;子进程不继承 `GIT_DIR`、`GIT_WORK_TREE`、`GIT_INDEX_FILE` 等仓库局部环境或临时配置覆盖,保留普通用户与仓库配置。Git 返回的仓库必须包含当前会话工作目录。
|
|
152
|
+
|
|
124
153
|
Git 失败、信号终止、取消、超时、输出截断、未解决冲突和过期快照都会阻止提示词投递,不将它们当作无改动。补丁解析器按正文核对每块的新旧行数,拒绝残缺正文,并排除上下文行。显式路径不存在、被忽略或位于仓库外时返回错误。
|
|
125
154
|
|
|
126
155
|
删除文件、纯删除行、仅重命名、二进制文件、非普通文件及大于 5 MiB 的文件不进入可编辑范围,并说明跳过原因。子模块不纳入 diff 收集。已检测到的改动全部被跳过时,不会因此扩大到其他范围。最多收集 200 个变更文件,单次 Git 最多 30 秒,整个范围收集最多 60 秒(进程终止还有最多 1 秒宽限);Git stdout 上限 8 MiB、stderr 64 KiB,提示词上限 128 KiB。
|
|
127
156
|
|
|
157
|
+
所有文件累计最多 4,096 个离散行范围,审查清单元数据(含跳过明细)最多 128 KiB;收集过程中超限即停止,不截取部分文件提交审查。连续修改行按一个范围计数。最终提示词仍独立检查 128 KiB 上限;超限时请指定文件或目录缩小范围。
|
|
158
|
+
|
|
128
159
|
`--staged` 先确认所选暂存文件与工作区一致,并在入队前再次核对暂存区、HEAD 和文件 SHA-256,避免把 index 行号直接用于不同的工作区内容。Agent 编辑前还需复核内容快照;内容变化时停止该文件的简化并重新运行命令。
|
|
129
160
|
|
|
130
161
|
**修改范围是提示词约束,不是文件写入权限隔离。** Agent 按宿主工具和用户授权执行修改及测试;本插件没有拦截其他工具的写入,也不能保证排队后文件不再变化。不要把“已提交审查”理解成“已完成简化”。
|
|
@@ -144,6 +175,21 @@ dsh plugin --profile web remove @michengai/dsh-simplify
|
|
|
144
175
|
|
|
145
176
|
## 开发与验证
|
|
146
177
|
|
|
178
|
+
### 从源码安装
|
|
179
|
+
|
|
180
|
+
```powershell
|
|
181
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
182
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
183
|
+
|
|
184
|
+
git clone https://github.com/MichengAI/dsh-simplify.git
|
|
185
|
+
Set-Location dsh-simplify
|
|
186
|
+
npm ci --ignore-scripts
|
|
187
|
+
npm run check
|
|
188
|
+
dsh plugin --profile web add . --ignore-scripts
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
入口为 `lib/index.js`,必须先构建再安装;profile 使用本地链接时需要保留源码目录。
|
|
192
|
+
|
|
147
193
|
```powershell
|
|
148
194
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
149
195
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
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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Q,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
|
-
|
|
54
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
244
|
+
skip(file.path, '新仓库中已从工作区删除');
|
|
220
245
|
continue;
|
|
221
246
|
}
|
|
222
247
|
throw error;
|
|
223
248
|
}
|
|
224
249
|
if ('reason' in before) {
|
|
225
|
-
|
|
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
|
-
|
|
262
|
+
skip(file.path, '没有可简化的当前行(纯删除、仅重命名或非文本 diff)');
|
|
237
263
|
continue;
|
|
238
264
|
}
|
|
239
265
|
}
|
|
240
|
-
|
|
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,GAA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,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACtG,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,aAAa;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC7F,MAAM,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,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 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,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CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAClH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACtG,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,aAAa;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC7F,MAAM,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,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.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
26
|
-
"@deepseek-ai/dsh-commands": "0.1.2-rc.1",
|
|
27
|
-
"@deepseek-ai/dsh-llm": "0.1.2-rc.1",
|
|
28
|
-
"@deepseek-ai/dsh-subprocess": "0.1.2-rc.1"
|
|
26
|
+
"@deepseek-ai/dsh-commands": "0.1.0-rc.8 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1",
|
|
27
|
+
"@deepseek-ai/dsh-llm": "0.1.0-rc.8 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1",
|
|
28
|
+
"@deepseek-ai/dsh-subprocess": "0.1.0-rc.8 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@deepseek-ai/cordis": "4.0.2",
|
|
32
|
-
"@deepseek-ai/dsh-commands": "0.1.
|
|
33
|
-
"@deepseek-ai/dsh-llm": "0.1.
|
|
34
|
-
"@deepseek-ai/dsh-subprocess": "0.1.
|
|
35
|
-
"@deepseek-ai/dsh-subprocess-local": "0.1.
|
|
32
|
+
"@deepseek-ai/dsh-commands": "0.1.5-rc.1",
|
|
33
|
+
"@deepseek-ai/dsh-llm": "0.1.5-rc.1",
|
|
34
|
+
"@deepseek-ai/dsh-subprocess": "0.1.5-rc.1",
|
|
35
|
+
"@deepseek-ai/dsh-subprocess-local": "0.1.5-rc.1",
|
|
36
36
|
"@types/node": "^22.19.0",
|
|
37
37
|
"typescript": "~5.7.2"
|
|
38
38
|
}
|