@hifullmoon/aicommit 2.6.10 → 2.6.12
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/.aicommit.config.example.json +4 -153
- package/CHANGELOG.md +22 -1
- package/README.md +12 -3
- package/README.zh-CN.md +12 -3
- package/docs/distribution.md +1 -1
- package/package.json +1 -1
- package/src/analysis-budget.js +25 -4
- package/src/api.js +84 -24
- package/src/change-analysis.js +75 -9
- package/src/config.js +104 -3
- package/src/generation-ui.js +8 -1
- package/src/local-analysis.js +19 -0
- package/src/main.js +33 -3
- package/src/policy.js +4 -1
- package/src/providers.js +4 -1
- package/src/setup.js +9 -83
- package/src/split.js +39 -23
- package/src/ui.js +33 -17
|
@@ -1,155 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"providerType": "minimax",
|
|
7
|
-
"apiUrl": "https://api.minimaxi.com/v1/chat/completions",
|
|
8
|
-
"apiKeyEnv": "MINIMAX_API_KEY",
|
|
9
|
-
"defaultModel": "default",
|
|
10
|
-
"models": {
|
|
11
|
-
"default": {
|
|
12
|
-
"modelId": "MiniMax-M3",
|
|
13
|
-
"reasoning": {
|
|
14
|
-
"mode": "on",
|
|
15
|
-
"effort": "medium"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"deepseek": {
|
|
21
|
-
"providerType": "deepseek",
|
|
22
|
-
"apiUrl": "https://api.deepseek.com/v1/chat/completions",
|
|
23
|
-
"apiKeyEnv": "DEEPSEEK_API_KEY",
|
|
24
|
-
"defaultModel": "chat",
|
|
25
|
-
"models": {
|
|
26
|
-
"chat": {
|
|
27
|
-
"modelId": "deepseek-v4-flash",
|
|
28
|
-
"reasoning": {
|
|
29
|
-
"mode": "on",
|
|
30
|
-
"effort": "high"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"openrouter": {
|
|
36
|
-
"providerType": "openrouter",
|
|
37
|
-
"apiUrl": "https://openrouter.ai/api/v1/chat/completions",
|
|
38
|
-
"apiKeyEnv": "OPENROUTER_API_KEY",
|
|
39
|
-
"defaultModel": "fast",
|
|
40
|
-
"models": {
|
|
41
|
-
"fast": {
|
|
42
|
-
"modelId": "openai/gpt-4o-mini"
|
|
43
|
-
},
|
|
44
|
-
"quality": {
|
|
45
|
-
"modelId": "openai/gpt-4o"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"kimi-code": {
|
|
50
|
-
"providerType": "custom",
|
|
51
|
-
"apiUrl": "https://api.kimi.com/coding/v1/chat/completions",
|
|
52
|
-
"apiKeyEnv": "KIMI_API_KEY",
|
|
53
|
-
"defaultModel": "default",
|
|
54
|
-
"models": {
|
|
55
|
-
"default": {
|
|
56
|
-
"modelId": "kimi-for-coding"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
"ollama": {
|
|
61
|
-
"providerType": "ollama",
|
|
62
|
-
"apiUrl": "http://127.0.0.1:11434/api/chat",
|
|
63
|
-
"defaultModel": "qwen",
|
|
64
|
-
"models": {
|
|
65
|
-
"qwen": {
|
|
66
|
-
"modelId": "qwen3:8b"
|
|
67
|
-
},
|
|
68
|
-
"deepseek": {
|
|
69
|
-
"modelId": "deepseek-r1:14b"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
"language": "en",
|
|
75
|
-
"commitPolicy": {
|
|
76
|
-
"version": 1,
|
|
77
|
-
"types": ["feat", "fix", "chore", "docs", "refactor", "test", "style", "perf", "ci", "build"],
|
|
78
|
-
"scope": {
|
|
79
|
-
"mode": "optional",
|
|
80
|
-
"values": []
|
|
81
|
-
},
|
|
82
|
-
"subject": {
|
|
83
|
-
"maxLength": 72
|
|
84
|
-
},
|
|
85
|
-
"body": {
|
|
86
|
-
"mode": "optional",
|
|
87
|
-
"maxLines": 8
|
|
88
|
-
},
|
|
89
|
-
"breakingChange": "allow",
|
|
90
|
-
"language": "inherit"
|
|
91
|
-
},
|
|
92
|
-
"allowProjectPrompt": false,
|
|
93
|
-
"prompt": "",
|
|
94
|
-
"repositoryContext": {
|
|
95
|
-
"enabled": true,
|
|
96
|
-
"maxChars": 4000,
|
|
97
|
-
"recentCommits": {
|
|
98
|
-
"enabled": true,
|
|
99
|
-
"count": 12,
|
|
100
|
-
"maxChars": 1000
|
|
101
|
-
},
|
|
102
|
-
"packageBoundaries": {
|
|
103
|
-
"enabled": true,
|
|
104
|
-
"maxEntries": 40,
|
|
105
|
-
"maxChars": 800
|
|
106
|
-
},
|
|
107
|
-
"conventions": {
|
|
108
|
-
"enabled": true,
|
|
109
|
-
"trustedFiles": [],
|
|
110
|
-
"maxFiles": 4,
|
|
111
|
-
"maxChars": 1400
|
|
112
|
-
},
|
|
113
|
-
"commitlint": {
|
|
114
|
-
"enabled": true,
|
|
115
|
-
"maxChars": 800
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
"maxTokens": 1024,
|
|
119
|
-
"timeoutMs": 120000,
|
|
120
|
-
"retry": {
|
|
121
|
-
"maxAttempts": 3,
|
|
122
|
-
"baseDelayMs": 500,
|
|
123
|
-
"maxDelayMs": 5000
|
|
124
|
-
},
|
|
125
|
-
"credentialHelper": {
|
|
126
|
-
"enabled": false,
|
|
127
|
-
"username": "aicommit"
|
|
128
|
-
},
|
|
129
|
-
"maxDiffChars": 30000,
|
|
130
|
-
"maxFileDiffChars": 3000,
|
|
131
|
-
"splitMaxDiffChars": 16000,
|
|
132
|
-
"splitMaxPlanFiles": 100,
|
|
133
|
-
"diffContextLines": 1,
|
|
134
|
-
"regenerateWithDiff": false,
|
|
135
|
-
"reasoning": {
|
|
136
|
-
"mode": "on",
|
|
137
|
-
"effort": "medium",
|
|
138
|
-
"maxTokens": 4096,
|
|
139
|
-
"maxDisplayChars": 12000
|
|
140
|
-
},
|
|
141
|
-
"stripFiles": ["*.min.js", "*.map", "*.snap"],
|
|
142
|
-
"largeChange": {
|
|
143
|
-
"strategy": "auto",
|
|
144
|
-
"chunkInputTokens": 12000,
|
|
145
|
-
"maxTotalTokens": 200000,
|
|
146
|
-
"concurrency": 2,
|
|
147
|
-
"timeoutMs": 180000,
|
|
148
|
-
"cache": {
|
|
149
|
-
"enabled": true,
|
|
150
|
-
"ttlMs": 86400000,
|
|
151
|
-
"maxBytes": 33554432,
|
|
152
|
-
"allowUnprotected": false
|
|
153
|
-
}
|
|
154
|
-
}
|
|
2
|
+
"provider": "minimax",
|
|
3
|
+
"model": "MiniMax-M3.1-Flash",
|
|
4
|
+
"apiKeyEnv": "MINIMAX_API_KEY",
|
|
5
|
+
"language": "zh"
|
|
155
6
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@ This file lists notable user-facing changes. Internal refactors, test-only chang
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [2.6.12] - 2026-11-21
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Single-commit diff capture now uses `maxDiffChars` instead of `splitMaxDiffChars`, strips lockfile and `stripFiles` bodies before size checks, and lets `condenseDiff` handle oversized individual files instead of prematurely falling back to local large-change sampling.
|
|
12
|
+
- Automatic policy-correction retries now include the target language constraint, use a lower deterministic temperature, and disable follow-up reasoning when supported by the provider.
|
|
13
|
+
|
|
14
|
+
## [2.6.11] - 2026-11-19
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Accept a compact provider, model, credential, and language configuration alongside existing provider catalogs. Setup uses the built-in thinking defaults for new profiles and preserves explicit settings on existing profiles.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Large-change split planning respects the configured reasoning budget and sends the selected thinking effort to MiniMax M3.1. An exhausted output budget is reported separately from malformed JSON.
|
|
23
|
+
- Reviewing or editing messages no longer consumes the next generation round's deadline. Token and request limits still apply across rounds.
|
|
24
|
+
- Regeneration uses bounded evidence from the original change snapshot and, in split mode, from the selected group. Truncated responses require recovery or manual editing, and edited messages must pass policy validation before use.
|
|
25
|
+
|
|
7
26
|
## [2.6.10] - 2026-10-21
|
|
8
27
|
|
|
9
28
|
### Fixed
|
|
@@ -302,7 +321,9 @@ This file lists notable user-facing changes. Internal refactors, test-only chang
|
|
|
302
321
|
- Added file-level split planning and execution with Git-state concurrency checks.
|
|
303
322
|
- Added provider presets and user/project configuration boundaries.
|
|
304
323
|
|
|
305
|
-
[Unreleased]: https://github.com/hi-fullmoon/AICommit/compare/v2.6.
|
|
324
|
+
[Unreleased]: https://github.com/hi-fullmoon/AICommit/compare/v2.6.12...HEAD
|
|
325
|
+
[2.6.12]: https://github.com/hi-fullmoon/AICommit/tree/v2.6.12
|
|
326
|
+
[2.6.11]: https://github.com/hi-fullmoon/AICommit/tree/v2.6.11
|
|
306
327
|
[2.6.10]: https://github.com/hi-fullmoon/AICommit/tree/v2.6.10
|
|
307
328
|
[2.6.9]: https://github.com/hi-fullmoon/AICommit/tree/v2.6.9
|
|
308
329
|
[2.6.8]: https://github.com/hi-fullmoon/AICommit/tree/v2.6.8
|
package/README.md
CHANGED
|
@@ -75,7 +75,12 @@ aicommit setup
|
|
|
75
75
|
|
|
76
76
|
It walks you through choosing built-in provider defaults (OpenAI, DeepSeek, OpenRouter, MiniMax, Kimi Code, and Ollama) or entering a custom OpenAI-compatible endpoint, then entering your API key and one or more models, choosing a default model and commit language, and optionally testing the connection. Configuration is written atomically to the user config (`~/.aicommit/config.json`); a malformed or old-format existing file is backed up before replacement. The legacy `~/.aicommit.config.json` path remains readable and `aicommit setup` migrates its settings to the canonical path when saving.
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
For everyday use, configure only the provider, credentials, model, and language. Reasoning defaults to on with medium effort; output budgets, batching, caching, and retries use built-in defaults. The wizard no longer asks per-model reasoning questions and preserves existing explicit settings.
|
|
79
|
+
|
|
80
|
+
Use [.aicommit.config.example.json](.aicommit.config.example.json) as the minimal configuration; advanced fields are optional.
|
|
81
|
+
|
|
82
|
+
<details>
|
|
83
|
+
<summary>Advanced configuration and multiple providers</summary>
|
|
79
84
|
|
|
80
85
|
To configure by hand, start from [.aicommit.config.example.json](.aicommit.config.example.json). User config is loaded first, then allow-listed generation preferences from the project config at `./.aicommit.config.json` are deep-merged over it. Project config may set `language`, `commitPolicy`, `stripFiles`, `temperature`, and lower diff/token/timeout or repository-context ceilings. A project-owned `prompt` is ignored unless the user config explicitly sets `allowProjectPrompt: true`. Connection/provider fields (including `apiKeyEnv`), reasoning request controls, unknown keys, and attempts to raise a ceiling are ignored with a warning. This prevents a cloned repository from redirecting an authenticated request or silently increasing its cost/data scope.
|
|
81
86
|
|
|
@@ -190,7 +195,7 @@ aicommit -p deepseek -m reasoner
|
|
|
190
195
|
|
|
191
196
|
`schemaVersion`, `defaultProvider`, `providers`, and every provider's `providerType`, `apiUrl`, `defaultModel`, and non-empty `models` map are required. Without `-p`, AICommit selects `defaultProvider`; without `-m`, it selects that provider's `defaultModel`. Model profiles inherit global generation settings and provider connection settings, then may override `temperature`, `maxTokens`, `timeoutMs`, `reasoning`, and `extraBody`. Provider and model names are stable local aliases; `modelId` is the identifier sent to the API.
|
|
192
197
|
|
|
193
|
-
|
|
198
|
+
The requirements above apply to the expanded catalog. The compact format shown earlier uses `model` instead of `modelId`. Legacy flat or provider-level `modelId` configurations are still rejected; run `aicommit setup` or migrate them explicitly.
|
|
194
199
|
|
|
195
200
|
| Key | Description |
|
|
196
201
|
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -221,10 +226,12 @@ This is the only supported user-config shape. Earlier flat or provider-level `mo
|
|
|
221
226
|
| `largeChange` | Large-change strategy, budgets, and short-lived chunk recovery cache; personal config only, retaining protected summaries for 24 hours up to 32 MiB by default |
|
|
222
227
|
| `diffContextLines` | Context lines around each diff hunk (`git diff --unified=<n>`); lower values mean fewer tokens (default: `1`) |
|
|
223
228
|
| `stripFiles` | Extra files to stub out of the diff like lock files, matched by basename with `*`/`?` wildcards, e.g. `["*.min.js", "*.map", "*.snap"]` (default: `[]`; project-level entries are merged with user-level ones, not replaced) |
|
|
224
|
-
| `regenerateWithDiff` | `true` re-sends the full diff on every regenerate
|
|
229
|
+
| `regenerateWithDiff` | `true` re-sends the full diff on every regenerate; `false` (default) uses the previous message and up to 6,000 characters of change evidence to correct omissions and wording |
|
|
225
230
|
| `extraBody` | Model-profile JSON fields merged into the request body, except `model`/`messages` (default: `{}`) |
|
|
226
231
|
| `reasoning` | Global or model-profile reasoning controls: `mode` / `effort` (default: `on` / `medium`), `maxTokens`, and `maxDisplayChars` |
|
|
227
232
|
|
|
233
|
+
</details>
|
|
234
|
+
|
|
228
235
|
Works with OpenAI, DeepSeek, [OpenRouter](https://openrouter.ai), MiniMax, [Kimi Code](https://www.kimi.com/code/docs/), Ollama (native `/api/chat` or OpenAI-compatible `/v1/chat/completions`), LiteLLM, and other compatible endpoints. HTTPS is required for remote endpoints; plaintext HTTP is accepted only for localhost/loopback.
|
|
229
236
|
|
|
230
237
|
See the bilingual [provider compatibility table](docs/provider-compatibility.md) for streaming, reasoning, token-budget, usage, and authentication boundaries.
|
|
@@ -513,6 +520,8 @@ The default `largeChange.strategy: "auto"` inventories every file locally, group
|
|
|
513
520
|
|
|
514
521
|
A normal commit typically needs one model request, with no per-file AI calls or recursive model reduction. The inventory contains at most 16 representative groups under a UTF-8 byte budget, prioritizing coverage across code, configuration, tests, and other categories. It explicitly describes sampling limits. Both terminal and JSON output distinguish fully analyzed files, representative excerpts, and metadata-only files. Provider retries, response recovery, policy correction, and user-requested regeneration can still add requests.
|
|
515
522
|
|
|
523
|
+
`largeChange.timeoutMs` bounds each active generation round, including its analysis and automatic retries. Reviewing or editing a message does not consume that time; a user-requested retry or regeneration starts a fresh deadline. Total token and request limits remain cumulative across rounds.
|
|
524
|
+
|
|
516
525
|
Split mode builds local candidates and sends them in bounded batches of at most `splitMaxPlanFiles`, then merges the batch plans hierarchically. When an `auto` inventory exceeds four times that candidate limit, adjacent candidates are first bundled locally by top-level module, file kind, and Git status; the model receives compact counts, examples, and selected excerpts while the complete file mapping stays local. Every file remains represented even when the complete candidate inventory cannot fit one request. Exhausted analysis budgets stop without committing; increase the budget or use smaller batches. If the hierarchy cannot converge while budget remains, an all-files commit message can be generated from local change summaries; non-interactive committing requires `--allow-single-fallback`. Plans omitting files or hunks are rejected instead of creating an automatic "update remaining files" commit. Small changes keep the existing request path.
|
|
517
526
|
|
|
518
527
|
For exhaustive chunk-by-chunk model analysis, opt in through personal configuration:
|
package/README.zh-CN.md
CHANGED
|
@@ -77,7 +77,12 @@ aicommit setup
|
|
|
77
77
|
|
|
78
78
|
向导会引导你选择内置 Provider 默认值(OpenAI、DeepSeek、OpenRouter、MiniMax、Kimi Code 和 Ollama),或填写自定义 OpenAI 兼容端点;随后输入 API Key 和一个或多个模型、选择默认模型和提交信息语言,并可选测试连接。配置会原子写入用户配置文件 `~/.aicommit/config.json`;如果已有文件格式错误或属于旧格式,替换前会先备份。旧路径 `~/.aicommit.config.json` 仍可读取,运行 `aicommit setup` 并保存时会把其中设置迁移到规范路径。
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
日常只需配置 Provider、凭据、模型和语言。思考默认开启、强度为 `medium`,输出预算、分批、缓存与重试采用内置默认值;向导不再逐个询问思考参数,编辑已有模型时会保留显式设置。
|
|
81
|
+
|
|
82
|
+
最小配置见 [.aicommit.config.example.json](.aicommit.config.example.json),无需复制全部高级参数。
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>高级配置与多 Provider 示例</summary>
|
|
81
86
|
|
|
82
87
|
如需手动配置,请从 [.aicommit.config.example.json](.aicommit.config.example.json) 开始。AICommit 先加载用户配置,再将项目配置 `./.aicommit.config.json` 中白名单内的生成偏好深度合并到用户配置之上。项目配置可以设置 `language`、`commitPolicy`、`stripFiles`、`temperature`,也可以降低 diff、token、timeout 或仓库上下文上限。项目拥有的 `prompt` 默认会被忽略,除非用户配置明确设置 `allowProjectPrompt: true`。连接或 Provider 字段(包括 `apiKeyEnv`)、推理请求控制、未知字段,以及任何试图提高上限的配置,都会被忽略并给出警告。这样可以防止克隆的仓库重定向已鉴权请求,或在不知情的情况下扩大成本和数据范围。
|
|
83
88
|
|
|
@@ -192,7 +197,7 @@ aicommit -p deepseek -m reasoner
|
|
|
192
197
|
|
|
193
198
|
`schemaVersion`、`defaultProvider`、`providers`,以及每个 Provider 的 `providerType`、`apiUrl`、`defaultModel` 和非空 `models` 都是必填项。未指定 `-p` 时选择 `defaultProvider`;未指定 `-m` 时选择该 Provider 的 `defaultModel`。模型配置会继承全局生成设置和 Provider 连接设置,并可覆盖 `temperature`、`maxTokens`、`timeoutMs`、`reasoning` 与 `extraBody`。Provider 名和模型名是稳定的本地别名,`modelId` 才是发送给 API 的模型标识。
|
|
194
199
|
|
|
195
|
-
|
|
200
|
+
上述必填项适用于完整的 Provider 配置。前面的精简格式使用 `model`,而不是 `modelId`。旧版扁平配置或 Provider 级 `modelId` 仍会被拒绝;请运行 `aicommit setup` 或手动迁移。
|
|
196
201
|
|
|
197
202
|
| 配置项 | 说明 |
|
|
198
203
|
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -223,10 +228,12 @@ aicommit -p deepseek -m reasoner
|
|
|
223
228
|
| `largeChange` | 大变更策略、预算和短期分块恢复缓存;缓存只接受个人配置,默认保留受保护摘要 24 小时、最多 32 MiB |
|
|
224
229
|
| `diffContextLines` | 每个 diff hunk 周围的上下文行数(`git diff --unified=<n>`);越小越节省 token(默认:`1`) |
|
|
225
230
|
| `stripFiles` | 额外替换为占位的文件,按 basename 使用 `*` / `?` 通配,如 `["*.min.js", "*.map", "*.snap"]`(默认:`[]`;项目项与用户项合并而非覆盖) |
|
|
226
|
-
| `regenerateWithDiff` | `true` 表示每次重写都重发完整 diff
|
|
231
|
+
| `regenerateWithDiff` | `true` 表示每次重写都重发完整 diff;`false`(默认)携带上一条消息和最多 6,000 个字符的变更证据,用于纠正遗漏并调整措辞 |
|
|
227
232
|
| `extraBody` | 模型配置中合并到请求体的 JSON 字段,但不允许覆盖 `model` / `messages`(默认:`{}`) |
|
|
228
233
|
| `reasoning` | 全局或模型级推理控制:`mode` / `effort`(默认:`on` / `medium`)、`maxTokens` 和 `maxDisplayChars` |
|
|
229
234
|
|
|
235
|
+
</details>
|
|
236
|
+
|
|
230
237
|
AICommit 支持 OpenAI、DeepSeek、[OpenRouter](https://openrouter.ai)、MiniMax、[Kimi Code](https://www.kimi.com/code/docs/)、Ollama(原生 `/api/chat` 或 OpenAI 兼容 `/v1/chat/completions`)、LiteLLM,以及其他兼容端点。远程端点必须使用 HTTPS;明文 HTTP 只允许 localhost / loopback。
|
|
231
238
|
|
|
232
239
|
流式输出、推理、token 预算、usage 和鉴权边界,请参阅双语 [Provider 兼容表](docs/provider-compatibility.md)。
|
|
@@ -515,6 +522,8 @@ exec zsh
|
|
|
515
522
|
|
|
516
523
|
普通提交通常只需要一次模型请求,不会为每个文件调用 AI,也不会递归调用模型汇总。摘要最多包含 16 个代表组,并受 UTF-8 字节预算约束;优先覆盖代码、配置和测试等不同类别。摘要明确说明抽样范围,界面和 JSON 分别报告全文分析、代表片段和仅元数据的文件数,不把抽样视为完整理解。提供方重试、响应恢复、格式修正和用户重新生成仍可能增加请求。
|
|
517
524
|
|
|
525
|
+
`largeChange.timeoutMs` 限制每轮实际生成的时间,包括该轮分析和自动重试。阅读或编辑消息不消耗这段时间;用户主动重试或重新生成时会开始新的计时。总 token 限额和请求次数仍跨轮累计。
|
|
526
|
+
|
|
518
527
|
批次提交先在本地建立候选组,再按每批最多 `splitMaxPlanFiles` 个候选发送,并分层合并各批计划。当 `auto` 清单规模超过该候选上限的四倍时,会先按顶层模块、文件类型和 Git 状态在本地归并相邻候选;模型只接收紧凑计数、少量路径示例和代表片段,完整文件映射始终留在本地。完整候选清单放不进一次请求时,仍会保留每个文件。分析预算耗尽时停止提交,保留变更并提示提高预算或减少单批文件。如果分层规划无法收敛且预算仍充足,可根据本地变更摘要生成覆盖全部文件的单次提交;非交互提交需要 `--allow-single-fallback`。遗漏文件或 hunk 的计划会被拒绝,不再自动生成“更新其余文件”。小变更保持原有请求路径。
|
|
519
528
|
|
|
520
529
|
确实需要逐块 AI 分析时,在个人配置中设置:
|
package/docs/distribution.md
CHANGED
|
@@ -33,7 +33,7 @@ The release workflow uses npm Trusted Publishing without a long-lived `NPM_TOKEN
|
|
|
33
33
|
```bash
|
|
34
34
|
workdir=$(mktemp -d)
|
|
35
35
|
cd "$workdir"
|
|
36
|
-
npm install --package-lock-only @hifullmoon/aicommit@2.6.
|
|
36
|
+
npm install --package-lock-only @hifullmoon/aicommit@2.6.12
|
|
37
37
|
npm audit signatures
|
|
38
38
|
```
|
|
39
39
|
|
package/package.json
CHANGED
package/src/analysis-budget.js
CHANGED
|
@@ -21,7 +21,10 @@ export function estimateTokens(text) {
|
|
|
21
21
|
|
|
22
22
|
export function createAnalysisBudget(settings = {}) {
|
|
23
23
|
const limits = { ...DEFAULT_LARGE_CHANGE, ...settings };
|
|
24
|
-
|
|
24
|
+
let started = Date.now();
|
|
25
|
+
let elapsed = 0;
|
|
26
|
+
let roundElapsed = 0;
|
|
27
|
+
let signal = AbortSignal.timeout(limits.timeoutMs);
|
|
25
28
|
let charged = 0;
|
|
26
29
|
let requests = 0;
|
|
27
30
|
let inputTokens = 0;
|
|
@@ -29,19 +32,37 @@ export function createAnalysisBudget(settings = {}) {
|
|
|
29
32
|
let reserveFinal = 0;
|
|
30
33
|
return {
|
|
31
34
|
limits,
|
|
32
|
-
signal
|
|
35
|
+
get signal() {
|
|
36
|
+
return signal;
|
|
37
|
+
},
|
|
38
|
+
startRound() {
|
|
39
|
+
this.endRound();
|
|
40
|
+
started = Date.now();
|
|
41
|
+
roundElapsed = 0;
|
|
42
|
+
signal = AbortSignal.timeout(limits.timeoutMs);
|
|
43
|
+
},
|
|
44
|
+
endRound() {
|
|
45
|
+
if (started !== null) {
|
|
46
|
+
roundElapsed = Date.now() - started;
|
|
47
|
+
elapsed += roundElapsed;
|
|
48
|
+
started = null;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
33
51
|
reserveFinal(tokens) {
|
|
34
52
|
reserveFinal = tokens;
|
|
35
53
|
},
|
|
36
54
|
remainingMs() {
|
|
37
|
-
return Math.max(
|
|
55
|
+
return Math.max(
|
|
56
|
+
0,
|
|
57
|
+
limits.timeoutMs - (started === null ? roundElapsed : Date.now() - started),
|
|
58
|
+
);
|
|
38
59
|
},
|
|
39
60
|
snapshot() {
|
|
40
61
|
return {
|
|
41
62
|
requests,
|
|
42
63
|
budgetedTokens: charged,
|
|
43
64
|
maxTotalTokens: limits.maxTotalTokens,
|
|
44
|
-
elapsedMs: Date.now() - started,
|
|
65
|
+
elapsedMs: elapsed + (started === null ? 0 : Date.now() - started),
|
|
45
66
|
usage: { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens },
|
|
46
67
|
};
|
|
47
68
|
},
|
package/src/api.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
validateCommitCandidate,
|
|
11
11
|
} from './policy.js';
|
|
12
12
|
import { encodeUntrustedData } from './trust.js';
|
|
13
|
+
import { estimateTokens } from './analysis-budget.js';
|
|
13
14
|
|
|
14
15
|
export async function callAPI(
|
|
15
16
|
apiUrl,
|
|
@@ -93,15 +94,27 @@ async function reasoningForFollowUp(config) {
|
|
|
93
94
|
return adapter.reasoningForFollowUp(config.reasoning);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
// Each generation is stateless. Keep bounded evidence from the same protected
|
|
98
|
+
// snapshot so a rewrite can correct an earlier misunderstanding.
|
|
99
|
+
function regenerationEvidence(diff, maxChars = 6000) {
|
|
100
|
+
const chars = Array.from(diff);
|
|
101
|
+
if (chars.length <= maxChars) return diff;
|
|
102
|
+
const marker = '\n... (middle omitted; these excerpts are incomplete evidence) ...\n';
|
|
103
|
+
const available = Math.max(0, maxChars - marker.length);
|
|
104
|
+
const tail = Math.floor(available / 3);
|
|
105
|
+
return (
|
|
106
|
+
chars.slice(0, available - tail).join('') + marker + (tail ? chars.slice(-tail).join('') : '')
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function regeneratePrompt(previousMessage, policy, evidence) {
|
|
101
111
|
return [
|
|
112
|
+
'Reassess the change using these bounded excerpts from the original protected input. ' +
|
|
113
|
+
'They may be incomplete. Correct omissions or mistakes in the previous message; do not infer unsupported behavior.',
|
|
114
|
+
encodeUntrustedData('change_evidence', evidence),
|
|
102
115
|
'You previously generated this commit message for the change:',
|
|
103
116
|
'',
|
|
104
|
-
previousMessage.slice(0, 1000),
|
|
117
|
+
encodeUntrustedData('previous_message', previousMessage.slice(0, 1000)),
|
|
105
118
|
'',
|
|
106
119
|
'Generate a DIFFERENT commit message for the same change — different wording or emphasis. ' +
|
|
107
120
|
`Keep commitPolicy v${policy.version}; allowed types: ${policy.types.join(', ')}. ` +
|
|
@@ -111,6 +124,19 @@ function regeneratePrompt(previousMessage, policy) {
|
|
|
111
124
|
].join('\n');
|
|
112
125
|
}
|
|
113
126
|
|
|
127
|
+
export function assertCompleteResponse(response, usage = null, latencyMs = null) {
|
|
128
|
+
if (hitTokenLimit(response)) {
|
|
129
|
+
throw fail(
|
|
130
|
+
ERROR_CATEGORIES.RESPONSE_FORMAT,
|
|
131
|
+
'Provider response was still truncated after recovery. Increase maxTokens or edit the partial message manually.',
|
|
132
|
+
{
|
|
133
|
+
code: 'response_truncated',
|
|
134
|
+
data: { partialMessage: response.content, usage, latencyMs },
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
114
140
|
// Last-ditch extraction from raw reasoning text: prefer the first line that
|
|
115
141
|
// carries a conventional-commit prefix, else fall back to the last non-empty
|
|
116
142
|
// line.
|
|
@@ -132,7 +158,7 @@ function extractFromReasoning(reasoning, policy) {
|
|
|
132
158
|
// reasoning trace and no content.
|
|
133
159
|
function followupCommitPrompt(policy) {
|
|
134
160
|
return (
|
|
135
|
-
|
|
161
|
+
`Based on your analysis above, output ONLY the final commitPolicy v${policy.version} message. ` +
|
|
136
162
|
`Use one of these types: ${policy.types.join(', ')}. ` +
|
|
137
163
|
'Do not include any other text, explanation, or code fences.'
|
|
138
164
|
);
|
|
@@ -188,6 +214,7 @@ export async function getResponseText(
|
|
|
188
214
|
stream = null,
|
|
189
215
|
responseValidator = null,
|
|
190
216
|
) {
|
|
217
|
+
const started = performance.now();
|
|
191
218
|
let response = await requestGeneration(config, {
|
|
192
219
|
messages,
|
|
193
220
|
temperature,
|
|
@@ -258,7 +285,9 @@ export async function getResponseText(
|
|
|
258
285
|
text = response.content;
|
|
259
286
|
}
|
|
260
287
|
|
|
261
|
-
|
|
288
|
+
const usage = sumUsage(...usages);
|
|
289
|
+
assertCompleteResponse(response, usage, performance.now() - started);
|
|
290
|
+
return { text, data: response.raw, response, reasoning, usage };
|
|
262
291
|
}
|
|
263
292
|
|
|
264
293
|
export function buildCommitMessages(config, diff, regenerateCount = 0, previousMessage = '') {
|
|
@@ -270,16 +299,33 @@ export function buildCommitMessages(config, diff, regenerateCount = 0, previousM
|
|
|
270
299
|
// constraint after the diff where it can't be drowned out by the prompt.
|
|
271
300
|
const langReminder = `\n\n(Remember: the commit message must be in ${targetLang}.)`;
|
|
272
301
|
|
|
273
|
-
//
|
|
274
|
-
// the diff entirely: re-sending it on every regenerate would be the biggest
|
|
275
|
-
// token cost of the whole flow, while the previous message already captures
|
|
276
|
-
// the change. The model rewords its own reply instead (same cheap pattern
|
|
277
|
-
// as the corrective retry). "regenerateWithDiff" opts back into the old
|
|
278
|
-
// behavior: the full diff plus an attempt hint, for more varied rewrites.
|
|
302
|
+
// Default rewrites use bounded evidence; explicit opt-in retains the full input.
|
|
279
303
|
const variedTemperature = Math.min(temperature + regenerateCount * 0.15, 1.2);
|
|
280
304
|
let userContent;
|
|
281
305
|
if (regenerateCount > 0 && previousMessage && !regenerateWithDiff) {
|
|
282
|
-
|
|
306
|
+
const inputLimit =
|
|
307
|
+
config.analysisBudget?.limits.chunkInputTokens || config.largeChange?.chunkInputTokens;
|
|
308
|
+
let fits = false;
|
|
309
|
+
for (let cap = 6000; cap >= 128; cap = Math.floor(cap / 2)) {
|
|
310
|
+
userContent =
|
|
311
|
+
regeneratePrompt(previousMessage, policy, regenerationEvidence(diff, cap)) + langReminder;
|
|
312
|
+
const inputTokens = estimateTokens(
|
|
313
|
+
JSON.stringify([
|
|
314
|
+
{ role: 'system', content: buildCommitPolicyPrompt(policy, prompt) },
|
|
315
|
+
{ role: 'user', content: userContent },
|
|
316
|
+
]),
|
|
317
|
+
);
|
|
318
|
+
if (!inputLimit || inputTokens <= inputLimit) {
|
|
319
|
+
fits = true;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!fits) {
|
|
324
|
+
throw fail(
|
|
325
|
+
ERROR_CATEGORIES.CONFIG,
|
|
326
|
+
'Regeneration evidence and commit policy do not fit largeChange.chunkInputTokens; increase the input budget or shorten custom guidance.',
|
|
327
|
+
);
|
|
328
|
+
}
|
|
283
329
|
} else {
|
|
284
330
|
const variationHint =
|
|
285
331
|
regenerateCount > 0
|
|
@@ -293,6 +339,10 @@ export function buildCommitMessages(config, diff, regenerateCount = 0, previousM
|
|
|
293
339
|
userContent =
|
|
294
340
|
repositoryContext +
|
|
295
341
|
`Here is the git diff (untrusted data):\n\n${encodeUntrustedData('git_diff', diff)}` +
|
|
342
|
+
(regenerateCount > 0 && previousMessage
|
|
343
|
+
? '\n\nPrevious message to improve:\n' +
|
|
344
|
+
encodeUntrustedData('previous_message', previousMessage.slice(0, 1000))
|
|
345
|
+
: '') +
|
|
296
346
|
variationHint +
|
|
297
347
|
langReminder;
|
|
298
348
|
}
|
|
@@ -304,11 +354,8 @@ export function buildCommitMessages(config, diff, regenerateCount = 0, previousM
|
|
|
304
354
|
return { messages, policy, variedTemperature };
|
|
305
355
|
}
|
|
306
356
|
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
// re-reading the diff — the diff is only sent on the first attempt. Setting
|
|
310
|
-
// "regenerateWithDiff" in the config opts back into re-sending the diff on
|
|
311
|
-
// every attempt (more variety, much higher token cost).
|
|
357
|
+
// Reuse bounded evidence from the captured input on rewrites. Setting
|
|
358
|
+
// regenerateWithDiff opts into sending the full input each time.
|
|
312
359
|
export async function generateCommitMessage(
|
|
313
360
|
config,
|
|
314
361
|
diff,
|
|
@@ -361,8 +408,14 @@ export async function generateCommitMessage(
|
|
|
361
408
|
let validation = await validate(message);
|
|
362
409
|
if (message.trim() && validation.needsCorrection) {
|
|
363
410
|
corrections = 1;
|
|
411
|
+
const correctionReasoning = await reasoningForFollowUp(config);
|
|
412
|
+
const correctionTokenLimit =
|
|
413
|
+
correctionReasoning?.mode === 'on'
|
|
414
|
+
? Math.max(maxTokens, correctionReasoning.maxTokens || 4096)
|
|
415
|
+
: maxTokens;
|
|
416
|
+
const correctionTemperature = Math.min(config.temperature ?? 0.3, 0.2);
|
|
364
417
|
const retry = await getResponseText(
|
|
365
|
-
config,
|
|
418
|
+
{ ...config, reasoning: correctionReasoning },
|
|
366
419
|
[
|
|
367
420
|
messages[0],
|
|
368
421
|
{
|
|
@@ -370,11 +423,18 @@ export async function generateCommitMessage(
|
|
|
370
423
|
content: buildPolicyCorrectionPrompt(message, validation.errors, policy),
|
|
371
424
|
},
|
|
372
425
|
],
|
|
373
|
-
|
|
374
|
-
|
|
426
|
+
correctionTemperature,
|
|
427
|
+
correctionTokenLimit,
|
|
375
428
|
followupCommitPrompt(policy),
|
|
376
429
|
stream,
|
|
377
|
-
)
|
|
430
|
+
).catch((error) => {
|
|
431
|
+
if (error.code === 'response_truncated') {
|
|
432
|
+
error.data.usage = sumUsage(usage, error.data.usage);
|
|
433
|
+
error.data.latencyMs = performance.now() - t0;
|
|
434
|
+
error.data.corrections = corrections;
|
|
435
|
+
}
|
|
436
|
+
throw error;
|
|
437
|
+
});
|
|
378
438
|
const fixed = cleanCommitMessage(retry.text);
|
|
379
439
|
// The retry is a real API call that cost tokens regardless of whether it
|
|
380
440
|
// produced a usable message — count its usage unconditionally.
|