@hifullmoon/aicommit 2.2.0 → 2.2.1
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 +13 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/docs/distribution.md +1 -1
- package/package.json +1 -1
- package/src/completion.js +7 -3
- package/src/context.js +103 -15
- package/src/git.js +1 -1
- package/src/policy-command.js +13 -2
- package/src/policy.js +76 -2
- package/src/split-plan.js +16 -3
- package/src/split.js +40 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ This file lists notable user-facing changes. Internal refactors, test-only chang
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [2.2.1] - 2026-08-29
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Combined repository commit policies with commitlint constraints without allowing either source to relax the other, including correct `never` and complete-header length handling.
|
|
12
|
+
- Hardened split transactions against changes during snapshot capture, restricted plan exports to safe locations, and prevented existing output files from being overwritten.
|
|
13
|
+
|
|
14
|
+
### Security
|
|
15
|
+
|
|
16
|
+
- Redacted credential assignments with quoted JSON or YAML keys before diffs and untracked previews are sent to a model.
|
|
17
|
+
|
|
7
18
|
## [2.2.0] - 2026-08-28
|
|
8
19
|
|
|
9
20
|
### Added
|
|
@@ -153,7 +164,8 @@ This file lists notable user-facing changes. Internal refactors, test-only chang
|
|
|
153
164
|
- Added file-level split planning and execution with Git-state concurrency checks.
|
|
154
165
|
- Added provider presets and user/project configuration boundaries.
|
|
155
166
|
|
|
156
|
-
[Unreleased]: https://github.com/hi-fullmoon/AICommit/compare/v2.2.
|
|
167
|
+
[Unreleased]: https://github.com/hi-fullmoon/AICommit/compare/v2.2.1...HEAD
|
|
168
|
+
[2.2.1]: https://github.com/hi-fullmoon/AICommit/releases/tag/v2.2.1
|
|
157
169
|
[2.2.0]: https://github.com/hi-fullmoon/AICommit/releases/tag/v2.2.0
|
|
158
170
|
[2.1.0]: https://github.com/hi-fullmoon/AICommit/releases/tag/v2.1.0
|
|
159
171
|
[2.0.1]: https://github.com/hi-fullmoon/AICommit/releases/tag/v2.0.1
|
package/README.md
CHANGED
|
@@ -415,7 +415,7 @@ When reasoning mode is `on` (including via `--reasoning=<level>`), aicommit requ
|
|
|
415
415
|
|
|
416
416
|
`aicommit split` (also available as the explicit `aicommit split run`) asks whether to group the staged index snapshot or all staged, unstaged, and untracked changes into file-level logical commits. Use `--scope=staged` or `--scope=all` when the boundary must be explicit, including every non-interactive run. You can review the plan, regenerate messages for selected groups, or edit the plan as JSON before committing. Sensitive-content detection fails closed before a non-interactive provider request or automatic staging.
|
|
417
417
|
|
|
418
|
-
For an auditable two-step flow, `aicommit split plan --scope=staged|all --file=<path>` exports a versioned JSON artifact, and `aicommit split apply --file=<path>` rechecks its base commit, change set, and content fingerprint before touching the index. Keep plan files outside the worktree or under `.git
|
|
418
|
+
For an auditable two-step flow, `aicommit split plan --scope=staged|all --file=<path>` exports a versioned JSON artifact, and `aicommit split apply --file=<path>` rechecks its base commit, change set, and content fingerprint before touching the index. Keep plan files outside the worktree or under the dedicated `.git/aicommit/` directory so they cannot become part of their own plan. Export never overwrites an existing destination.
|
|
419
419
|
|
|
420
420
|
Execution uses temporary indexes and a code-free checkpoint under `.git/aicommit`. A hook, Git error, interruption, or crash leaves completed commits in history and preserves the pending snapshot; the failure report shows checkpointed, in-flight, pending, and current worktree/index state. Resolve the cause and run `aicommit split resume`. Resume reconciles the possible post-commit crash window before creating anything else, so a completed group is neither duplicated nor omitted. If you intentionally finished or replaced the interrupted work through another Git workflow, run `aicommit split abort`; it removes only the stale checkpoint and never rewrites HEAD, the index, or the worktree. New committing split runs detect a checkpoint before contacting the provider. If planning or preflight fails before the first group, no split commit is created and the real index remains unchanged.
|
|
421
421
|
|
package/README.zh-CN.md
CHANGED
|
@@ -417,7 +417,7 @@ exec zsh
|
|
|
417
417
|
|
|
418
418
|
`aicommit split`(也可以显式写成 `aicommit split run`)会询问是对暂存 index 快照分组,还是对全部已暂存、未暂存和未跟踪变更做文件级分组。边界必须明确时请使用 `--scope=staged` 或 `--scope=all`,所有非交互运行都应显式指定范围。提交前可以审阅计划、为选中的组重新生成消息,或直接编辑 JSON 计划。敏感内容检测会在非交互 Provider 请求或自动暂存前 fail closed。
|
|
419
419
|
|
|
420
|
-
如需可审计的两步流程,使用 `aicommit split plan --scope=staged|all --file=<path>` 导出版本化 JSON 工件,再用 `aicommit split apply --file=<path>` 在接触 index 前重新校验 base commit
|
|
420
|
+
如需可审计的两步流程,使用 `aicommit split plan --scope=staged|all --file=<path>` 导出版本化 JSON 工件,再用 `aicommit split apply --file=<path>` 在接触 index 前重新校验 base commit、变更集和内容指纹。计划文件应保存在工作区之外或专用的 `.git/aicommit/` 目录下,避免被纳入自身计划;导出不会覆盖已有目标文件。
|
|
421
421
|
|
|
422
422
|
执行过程使用临时 index,并在 `.git/aicommit` 下保存不含代码内容的 checkpoint。hook、Git 错误、中断或崩溃发生后,已完成提交仍保留在历史中,待处理快照也会保留;失败报告会显示已 checkpoint、执行中、待处理,以及当前工作区 / index 状态。解决问题后运行 `aicommit split resume`。恢复流程会先协调“提交完成后崩溃”的可能窗口,再创建任何新提交,因此不会重复或遗漏已完成分组。如果你通过其他 Git 流程有意完成或替换了中断工作,请运行 `aicommit split abort`;它只删除过期 checkpoint,绝不会改写 HEAD、index 或工作区。新的 split 提交流程会在联系 Provider 前检测现有 checkpoint。如果规划或预检在第一组之前失败,不会创建任何 split 提交,真实 index 也保持不变。
|
|
423
423
|
|
package/docs/distribution.md
CHANGED
|
@@ -26,7 +26,7 @@ The release workflow uses npm Trusted Publishing without a long-lived `NPM_TOKEN
|
|
|
26
26
|
```bash
|
|
27
27
|
workdir=$(mktemp -d)
|
|
28
28
|
cd "$workdir"
|
|
29
|
-
npm install --package-lock-only @hifullmoon/aicommit@2.2.
|
|
29
|
+
npm install --package-lock-only @hifullmoon/aicommit@2.2.1
|
|
30
30
|
npm audit signatures
|
|
31
31
|
```
|
|
32
32
|
|
package/package.json
CHANGED
package/src/completion.js
CHANGED
|
@@ -46,7 +46,9 @@ complete -F _aicommit aicommit
|
|
|
46
46
|
|
|
47
47
|
const ZSH = `#compdef aicommit
|
|
48
48
|
_aicommit() {
|
|
49
|
+
local curcontext="$curcontext" state state_descr line
|
|
49
50
|
local -a commands options
|
|
51
|
+
typeset -A opt_args
|
|
50
52
|
commands=(
|
|
51
53
|
'setup:interactive configuration wizard'
|
|
52
54
|
'doctor:diagnose configuration and connectivity'
|
|
@@ -71,15 +73,17 @@ _aicommit() {
|
|
|
71
73
|
'--output=[output mode]:output:(text json)'
|
|
72
74
|
'--debug[show debug details]'
|
|
73
75
|
)
|
|
74
|
-
_arguments -C $options '*::argument:->args'
|
|
76
|
+
_arguments -C $options '1:command:->command' '*::argument:->args'
|
|
75
77
|
case $state in
|
|
78
|
+
command)
|
|
79
|
+
_describe 'command' commands
|
|
80
|
+
;;
|
|
76
81
|
args)
|
|
77
|
-
case $
|
|
82
|
+
case $line[1] in
|
|
78
83
|
config) _values 'config action' show validate path ;;
|
|
79
84
|
policy) _values 'policy action' template check ;;
|
|
80
85
|
completion) _values 'shell' bash zsh fish ;;
|
|
81
86
|
split) _values 'split action' run plan apply resume abort ;;
|
|
82
|
-
*) _describe 'command' commands ;;
|
|
83
87
|
esac
|
|
84
88
|
;;
|
|
85
89
|
esac
|
package/src/context.js
CHANGED
|
@@ -381,20 +381,22 @@ function quotedValues(text) {
|
|
|
381
381
|
|
|
382
382
|
function enumRule(text, name) {
|
|
383
383
|
const index = text.search(new RegExp(`['"]?${name}['"]?\\s*:`));
|
|
384
|
-
if (index < 0) return
|
|
384
|
+
if (index < 0) return null;
|
|
385
385
|
const window = text.slice(index, index + 3000);
|
|
386
386
|
const nested = window.match(
|
|
387
|
-
/\[\s*[012]\s*,\s*['"](
|
|
387
|
+
/\[\s*([012])\s*,\s*['"](always|never)['"]\s*,\s*\[([\s\S]*?)\]\s*\]/i,
|
|
388
388
|
);
|
|
389
|
-
|
|
389
|
+
if (!nested || nested[1] === '0') return null;
|
|
390
|
+
return { condition: nested[2].toLowerCase(), values: quotedValues(nested[3]) };
|
|
390
391
|
}
|
|
391
392
|
|
|
392
393
|
function numberRule(text, name) {
|
|
393
394
|
const index = text.search(new RegExp(`['"]?${name}['"]?\\s*:`));
|
|
394
395
|
if (index < 0) return null;
|
|
395
396
|
const window = text.slice(index, index + 500);
|
|
396
|
-
const match = window.match(/\[\s*[012]\s*,\s*['"](
|
|
397
|
-
|
|
397
|
+
const match = window.match(/\[\s*([012])\s*,\s*['"](always|never)['"]\s*,\s*(\d{1,3})\s*\]/i);
|
|
398
|
+
if (!match || match[1] === '0') return null;
|
|
399
|
+
return { condition: match[2].toLowerCase(), value: Number(match[3]) };
|
|
398
400
|
}
|
|
399
401
|
|
|
400
402
|
export function detectCommitlintConstraints(
|
|
@@ -410,22 +412,53 @@ export function detectCommitlintConstraints(
|
|
|
410
412
|
) {
|
|
411
413
|
continue;
|
|
412
414
|
}
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
|
|
415
|
+
const typeRule = enumRule(text, 'type-enum');
|
|
416
|
+
const scopeRule = enumRule(text, 'scope-enum');
|
|
417
|
+
const subjectLengthRule = numberRule(text, 'subject-max-length');
|
|
418
|
+
const headerLengthRule = numberRule(text, 'header-max-length');
|
|
419
|
+
const validTypes = (typeRule?.values || []).filter((value) => /^[a-z][a-z0-9-]*$/.test(value));
|
|
420
|
+
const validScopes = (scopeRule?.values || []).filter((value) => /^[a-z0-9._/-]+$/i.test(value));
|
|
421
|
+
const types = typeRule?.condition === 'always' ? validTypes : [];
|
|
422
|
+
const disallowedTypes = typeRule?.condition === 'never' ? validTypes : [];
|
|
423
|
+
const scopes = scopeRule?.condition === 'always' ? validScopes : [];
|
|
424
|
+
const disallowedScopes = scopeRule?.condition === 'never' ? validScopes : [];
|
|
425
|
+
const subjectMaxLength =
|
|
426
|
+
subjectLengthRule?.condition === 'always' ? subjectLengthRule.value : null;
|
|
427
|
+
const headerMaxLength =
|
|
428
|
+
headerLengthRule?.condition === 'always' ? headerLengthRule.value : null;
|
|
429
|
+
const unsupported = [];
|
|
430
|
+
if (subjectLengthRule?.condition === 'never') unsupported.push('subject-max-length: never');
|
|
431
|
+
if (headerLengthRule?.condition === 'never') unsupported.push('header-max-length: never');
|
|
432
|
+
if (
|
|
433
|
+
!types.length &&
|
|
434
|
+
!disallowedTypes.length &&
|
|
435
|
+
!scopes.length &&
|
|
436
|
+
!disallowedScopes.length &&
|
|
437
|
+
!subjectMaxLength &&
|
|
438
|
+
!headerMaxLength &&
|
|
439
|
+
!unsupported.length
|
|
440
|
+
) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
418
443
|
const lines = [`Detected commitlint constraints from ${path}:`];
|
|
419
444
|
if (types.length) lines.push(`- allowed types: ${types.join(', ')}`);
|
|
445
|
+
if (disallowedTypes.length) lines.push(`- disallowed types: ${disallowedTypes.join(', ')}`);
|
|
420
446
|
if (scopes.length) lines.push(`- allowed scopes: ${scopes.join(', ')}`);
|
|
447
|
+
if (disallowedScopes.length) {
|
|
448
|
+
lines.push(`- disallowed scopes: ${disallowedScopes.join(', ')}`);
|
|
449
|
+
}
|
|
421
450
|
if (subjectMaxLength) lines.push(`- subject max length: ${subjectMaxLength}`);
|
|
422
451
|
if (headerMaxLength) lines.push(`- header max length: ${headerMaxLength}`);
|
|
452
|
+
if (unsupported.length) lines.push(`- unsupported inverted rules: ${unsupported.join(', ')}`);
|
|
423
453
|
return {
|
|
424
454
|
path,
|
|
425
455
|
types,
|
|
456
|
+
disallowedTypes,
|
|
426
457
|
scopes,
|
|
458
|
+
disallowedScopes,
|
|
427
459
|
subjectMaxLength,
|
|
428
460
|
headerMaxLength,
|
|
461
|
+
unsupported,
|
|
429
462
|
text: truncate(lines.join('\n'), settings.maxChars),
|
|
430
463
|
};
|
|
431
464
|
}
|
|
@@ -436,17 +469,72 @@ export function applyCommitlintPolicy(commitPolicy, constraints, fallbackLanguag
|
|
|
436
469
|
if (!constraints) return commitPolicy;
|
|
437
470
|
const current = normalizeCommitPolicy(commitPolicy, fallbackLanguage);
|
|
438
471
|
const patch = {};
|
|
439
|
-
if (constraints.
|
|
472
|
+
if (constraints.unsupported?.length) {
|
|
473
|
+
throw new Error(
|
|
474
|
+
`Invalid config: unsupported inverted commitlint rules: ${constraints.unsupported.join(', ')}.`,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
let types = [...current.types];
|
|
479
|
+
if (constraints.types?.length) {
|
|
480
|
+
types = types.filter((type) => constraints.types.includes(type));
|
|
481
|
+
}
|
|
482
|
+
if (constraints.disallowedTypes?.length) {
|
|
483
|
+
types = types.filter((type) => !constraints.disallowedTypes.includes(type));
|
|
484
|
+
}
|
|
485
|
+
if (!types.length) {
|
|
486
|
+
throw new Error('Invalid config: commitPolicy and commitlint allow no common commit types.');
|
|
487
|
+
}
|
|
488
|
+
if (types.length !== current.types.length) patch.types = types;
|
|
489
|
+
|
|
490
|
+
let scopeMode = current.scope.mode;
|
|
491
|
+
let scopes = [...current.scope.values];
|
|
492
|
+
const disallowedScopes = new Set(current.scope.disallowedValues || []);
|
|
493
|
+
const hasFiniteScopeAllowlist = Boolean(
|
|
494
|
+
current.scope.values.length || constraints.scopes?.length,
|
|
495
|
+
);
|
|
440
496
|
if (constraints.scopes?.length) {
|
|
441
|
-
|
|
497
|
+
scopes = scopes.length
|
|
498
|
+
? scopes.filter((scope) => constraints.scopes.includes(scope))
|
|
499
|
+
: [...constraints.scopes];
|
|
500
|
+
}
|
|
501
|
+
for (const scope of constraints.disallowedScopes || []) disallowedScopes.add(scope);
|
|
502
|
+
if (scopes.length) scopes = scopes.filter((scope) => !disallowedScopes.has(scope));
|
|
503
|
+
if (!scopes.length && hasFiniteScopeAllowlist) {
|
|
504
|
+
if (scopeMode === 'required') {
|
|
505
|
+
throw new Error('Invalid config: commitPolicy and commitlint allow no common scopes.');
|
|
506
|
+
}
|
|
507
|
+
scopeMode = 'forbidden';
|
|
508
|
+
disallowedScopes.clear();
|
|
509
|
+
}
|
|
510
|
+
if (
|
|
511
|
+
scopeMode !== current.scope.mode ||
|
|
512
|
+
JSON.stringify(scopes) !== JSON.stringify(current.scope.values) ||
|
|
513
|
+
JSON.stringify([...disallowedScopes]) !== JSON.stringify(current.scope.disallowedValues || [])
|
|
514
|
+
) {
|
|
515
|
+
const nextScope = {
|
|
442
516
|
...current.scope,
|
|
443
|
-
|
|
517
|
+
mode: scopeMode,
|
|
518
|
+
values: scopes,
|
|
519
|
+
...(disallowedScopes.size ? { disallowedValues: [...disallowedScopes] } : {}),
|
|
444
520
|
};
|
|
521
|
+
if (!disallowedScopes.size) delete nextScope.disallowedValues;
|
|
522
|
+
patch.scope = nextScope;
|
|
445
523
|
}
|
|
446
|
-
if (constraints.subjectMaxLength) {
|
|
524
|
+
if (constraints.subjectMaxLength || constraints.headerMaxLength) {
|
|
447
525
|
patch.subject = {
|
|
448
526
|
...current.subject,
|
|
449
|
-
maxLength:
|
|
527
|
+
maxLength: constraints.subjectMaxLength
|
|
528
|
+
? Math.min(current.subject.maxLength, constraints.subjectMaxLength)
|
|
529
|
+
: current.subject.maxLength,
|
|
530
|
+
...(constraints.headerMaxLength
|
|
531
|
+
? {
|
|
532
|
+
headerMaxLength: Math.min(
|
|
533
|
+
current.subject.headerMaxLength ?? Infinity,
|
|
534
|
+
constraints.headerMaxLength,
|
|
535
|
+
),
|
|
536
|
+
}
|
|
537
|
+
: {}),
|
|
450
538
|
};
|
|
451
539
|
}
|
|
452
540
|
const merged = mergeCommitPolicy(current, patch);
|
package/src/git.js
CHANGED
|
@@ -336,7 +336,7 @@ const SENSITIVE_FILE_RE =
|
|
|
336
336
|
const PRIVATE_KEY_RE = /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/i;
|
|
337
337
|
const AWS_KEY_RE = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
|
|
338
338
|
const ASSIGNED_SECRET_RE =
|
|
339
|
-
/(\b(?:api[_-]?key|access[_-]?token|auth(?:orization)?|client[_-]?secret|password|passwd|secret|token)\b
|
|
339
|
+
/(\b(?:api[_-]?key|access[_-]?token|auth(?:orization)?|client[_-]?secret|password|passwd|secret|token)\b["']?\s*[:=]\s*["']?)([^\s,"'}]{8,})/gi;
|
|
340
340
|
|
|
341
341
|
export function isSensitiveFile(path) {
|
|
342
342
|
const normalized = String(path || '').replace(/\\/g, '/');
|
package/src/policy-command.js
CHANGED
|
@@ -21,8 +21,19 @@ function normalizedPolicyDocument(policy) {
|
|
|
21
21
|
return {
|
|
22
22
|
version: policy.version,
|
|
23
23
|
types: [...policy.types],
|
|
24
|
-
scope: {
|
|
25
|
-
|
|
24
|
+
scope: {
|
|
25
|
+
mode: policy.scope.mode,
|
|
26
|
+
values: [...policy.scope.values],
|
|
27
|
+
...(policy.scope.disallowedValues?.length
|
|
28
|
+
? { disallowedValues: [...policy.scope.disallowedValues] }
|
|
29
|
+
: {}),
|
|
30
|
+
},
|
|
31
|
+
subject: {
|
|
32
|
+
maxLength: policy.subject.maxLength,
|
|
33
|
+
...(policy.subject.headerMaxLength
|
|
34
|
+
? { headerMaxLength: policy.subject.headerMaxLength }
|
|
35
|
+
: {}),
|
|
36
|
+
},
|
|
26
37
|
body: { mode: policy.body.mode, maxLines: policy.body.maxLines },
|
|
27
38
|
breakingChange: policy.breakingChange,
|
|
28
39
|
language: policy.language,
|
package/src/policy.js
CHANGED
|
@@ -46,7 +46,13 @@ function clonePolicy(policy) {
|
|
|
46
46
|
return {
|
|
47
47
|
...policy,
|
|
48
48
|
types: [...policy.types],
|
|
49
|
-
scope: {
|
|
49
|
+
scope: {
|
|
50
|
+
...policy.scope,
|
|
51
|
+
values: [...policy.scope.values],
|
|
52
|
+
...(policy.scope.disallowedValues
|
|
53
|
+
? { disallowedValues: [...policy.scope.disallowedValues] }
|
|
54
|
+
: {}),
|
|
55
|
+
},
|
|
50
56
|
subject: { ...policy.subject },
|
|
51
57
|
body: { ...policy.body },
|
|
52
58
|
};
|
|
@@ -69,6 +75,14 @@ export function mergeCommitPolicy(base = DEFAULT_COMMIT_POLICY, override = {}) {
|
|
|
69
75
|
: base.scope.values,
|
|
70
76
|
}
|
|
71
77
|
: override.scope;
|
|
78
|
+
if (object(scope)) {
|
|
79
|
+
if (Array.isArray(scope.values)) scope.values = [...scope.values];
|
|
80
|
+
if (Array.isArray(scope.disallowedValues)) {
|
|
81
|
+
scope.disallowedValues = [...scope.disallowedValues];
|
|
82
|
+
} else {
|
|
83
|
+
delete scope.disallowedValues;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
72
86
|
const subject =
|
|
73
87
|
override.subject === undefined
|
|
74
88
|
? { ...base.subject }
|
|
@@ -111,6 +125,25 @@ function assertStringArray(values, name, { max = 64, pattern } = {}) {
|
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
127
|
|
|
128
|
+
function assertOptionalStringArray(values, name, { max = 64, pattern } = {}) {
|
|
129
|
+
if (values === undefined) return;
|
|
130
|
+
if (!Array.isArray(values) || values.length > max) {
|
|
131
|
+
throw new Error(`Invalid config "${name}": expected at most ${max} strings.`);
|
|
132
|
+
}
|
|
133
|
+
if (
|
|
134
|
+
values.some(
|
|
135
|
+
(value) =>
|
|
136
|
+
typeof value !== 'string' ||
|
|
137
|
+
!value ||
|
|
138
|
+
value.length > 64 ||
|
|
139
|
+
(pattern && !pattern.test(value)),
|
|
140
|
+
) ||
|
|
141
|
+
new Set(values).size !== values.length
|
|
142
|
+
) {
|
|
143
|
+
throw new Error(`Invalid config "${name}": contains an invalid or duplicate value.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
114
147
|
export function validateCommitPolicyConfig(value) {
|
|
115
148
|
if (!object(value)) throw new Error('Invalid config "commitPolicy": expected an object.');
|
|
116
149
|
if (value.version !== 1) {
|
|
@@ -137,6 +170,14 @@ export function validateCommitPolicyConfig(value) {
|
|
|
137
170
|
) {
|
|
138
171
|
throw new Error('Invalid config "commitPolicy.scope.values": contains an invalid value.');
|
|
139
172
|
}
|
|
173
|
+
assertOptionalStringArray(value.scope.disallowedValues, 'commitPolicy.scope.disallowedValues', {
|
|
174
|
+
pattern: SCOPE_RE,
|
|
175
|
+
});
|
|
176
|
+
if (value.scope.disallowedValues?.some((scope) => value.scope.values.includes(scope))) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
'Invalid config "commitPolicy.scope": allowed and disallowed values must not overlap.',
|
|
179
|
+
);
|
|
180
|
+
}
|
|
140
181
|
|
|
141
182
|
if (!object(value.subject)) {
|
|
142
183
|
throw new Error('Invalid config "commitPolicy.subject": expected an object.');
|
|
@@ -150,6 +191,16 @@ export function validateCommitPolicyConfig(value) {
|
|
|
150
191
|
'Invalid config "commitPolicy.subject.maxLength": expected an integer between 1 and 200.',
|
|
151
192
|
);
|
|
152
193
|
}
|
|
194
|
+
if (
|
|
195
|
+
value.subject.headerMaxLength !== undefined &&
|
|
196
|
+
(!Number.isInteger(value.subject.headerMaxLength) ||
|
|
197
|
+
value.subject.headerMaxLength < 1 ||
|
|
198
|
+
value.subject.headerMaxLength > 1000)
|
|
199
|
+
) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
'Invalid config "commitPolicy.subject.headerMaxLength": expected an integer between 1 and 1000.',
|
|
202
|
+
);
|
|
203
|
+
}
|
|
153
204
|
|
|
154
205
|
if (!object(value.body)) {
|
|
155
206
|
throw new Error('Invalid config "commitPolicy.body": expected an object.');
|
|
@@ -197,7 +248,10 @@ function scopeRule(policy) {
|
|
|
197
248
|
const allowed = policy.scope.values.length
|
|
198
249
|
? `; allowed values: ${policy.scope.values.join(', ')}`
|
|
199
250
|
: '';
|
|
200
|
-
|
|
251
|
+
const disallowed = policy.scope.disallowedValues?.length
|
|
252
|
+
? `; disallowed values: ${policy.scope.disallowedValues.join(', ')}`
|
|
253
|
+
: '';
|
|
254
|
+
return `${policy.scope.mode}${allowed}${disallowed}`;
|
|
201
255
|
}
|
|
202
256
|
|
|
203
257
|
export function buildCommitPolicyPrompt(policy, customPrompt = '') {
|
|
@@ -219,6 +273,9 @@ export function buildCommitPolicyPrompt(policy, customPrompt = '') {
|
|
|
219
273
|
`- Allowed types: ${policy.types.join(', ')}`,
|
|
220
274
|
`- Scope: ${scopeRule(policy)}`,
|
|
221
275
|
`- Subject text: required, at most ${policy.subject.maxLength} characters`,
|
|
276
|
+
...(policy.subject.headerMaxLength
|
|
277
|
+
? [`- Complete header: at most ${policy.subject.headerMaxLength} characters`]
|
|
278
|
+
: []),
|
|
222
279
|
`- Body: ${policy.body.mode}, at most ${policy.body.maxLines} non-empty lines, separated from the subject by a blank line`,
|
|
223
280
|
`- Breaking change: ${policy.breakingChange}; use "!" and/or a "BREAKING CHANGE:" footer`,
|
|
224
281
|
`- Language: ${targetLanguage}`,
|
|
@@ -344,6 +401,9 @@ export function validateCommitCandidate(message, { policy, diff = '' } = {}) {
|
|
|
344
401
|
),
|
|
345
402
|
);
|
|
346
403
|
}
|
|
404
|
+
if (parsed.scope && normalizedPolicy.scope.disallowedValues?.includes(parsed.scope)) {
|
|
405
|
+
issues.push(issue('scope_value', `Scope "${parsed.scope}" is forbidden.`));
|
|
406
|
+
}
|
|
347
407
|
if ([...parsed.subject].length > normalizedPolicy.subject.maxLength) {
|
|
348
408
|
issues.push(
|
|
349
409
|
issue(
|
|
@@ -352,6 +412,17 @@ export function validateCommitCandidate(message, { policy, diff = '' } = {}) {
|
|
|
352
412
|
),
|
|
353
413
|
);
|
|
354
414
|
}
|
|
415
|
+
if (
|
|
416
|
+
normalizedPolicy.subject.headerMaxLength &&
|
|
417
|
+
[...parsedMessage.header].length > normalizedPolicy.subject.headerMaxLength
|
|
418
|
+
) {
|
|
419
|
+
issues.push(
|
|
420
|
+
issue(
|
|
421
|
+
'header_length',
|
|
422
|
+
`Header exceeds ${normalizedPolicy.subject.headerMaxLength} characters.`,
|
|
423
|
+
),
|
|
424
|
+
);
|
|
425
|
+
}
|
|
355
426
|
if (effectiveLanguage === 'zh' && !/\p{Script=Han}/u.test(parsed.subject)) {
|
|
356
427
|
issues.push(issue('language', 'The subject must be written in Simplified Chinese.'));
|
|
357
428
|
}
|
|
@@ -414,6 +485,9 @@ export function buildPolicyCorrectionPrompt(badReply, errors, policy) {
|
|
|
414
485
|
`Allowed types: ${policy.types.join(', ')}`,
|
|
415
486
|
`Scope rule: ${scopeRule(policy)}`,
|
|
416
487
|
`Maximum subject length: ${policy.subject.maxLength}`,
|
|
488
|
+
...(policy.subject.headerMaxLength
|
|
489
|
+
? [`Maximum complete header length: ${policy.subject.headerMaxLength}`]
|
|
490
|
+
: []),
|
|
417
491
|
`Body rule: ${policy.body.mode}, maximum ${policy.body.maxLines} non-empty lines`,
|
|
418
492
|
`Breaking-change rule: ${policy.breakingChange}`,
|
|
419
493
|
'Rewrite it once. Output only the complete corrected commit message; do not include explanations or fences.',
|
package/src/split-plan.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lstat, mkdir, readFile,
|
|
1
|
+
import { link, lstat, mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { normalizeCommitPolicy, validateCommitCandidate } from './policy.js';
|
|
@@ -35,7 +35,13 @@ function clonePolicy(policy, language) {
|
|
|
35
35
|
return {
|
|
36
36
|
version: normalized.version,
|
|
37
37
|
types: [...normalized.types],
|
|
38
|
-
scope: {
|
|
38
|
+
scope: {
|
|
39
|
+
...normalized.scope,
|
|
40
|
+
values: [...normalized.scope.values],
|
|
41
|
+
...(normalized.scope.disallowedValues
|
|
42
|
+
? { disallowedValues: [...normalized.scope.disallowedValues] }
|
|
43
|
+
: {}),
|
|
44
|
+
},
|
|
39
45
|
subject: { ...normalized.subject },
|
|
40
46
|
body: { ...normalized.body },
|
|
41
47
|
breakingChange: normalized.breakingChange,
|
|
@@ -310,12 +316,19 @@ export async function writeSplitPlanArtifact(path, artifact) {
|
|
|
310
316
|
await writeFile(temporary, JSON.stringify(validated, null, 2) + '\n', {
|
|
311
317
|
encoding: 'utf8',
|
|
312
318
|
mode: 0o600,
|
|
319
|
+
flag: 'wx',
|
|
313
320
|
});
|
|
314
|
-
|
|
321
|
+
// A same-directory hard link installs the completed file atomically while
|
|
322
|
+
// failing with EEXIST instead of replacing an unrelated destination.
|
|
323
|
+
await link(temporary, absolute);
|
|
315
324
|
} catch (err) {
|
|
316
325
|
await unlink(temporary).catch(() => {});
|
|
326
|
+
if (err.code === 'EEXIST') {
|
|
327
|
+
throw new Error(`Split plan output already exists: ${absolute}`, { cause: err });
|
|
328
|
+
}
|
|
317
329
|
throw err;
|
|
318
330
|
}
|
|
331
|
+
await unlink(temporary).catch(() => {});
|
|
319
332
|
return absolute;
|
|
320
333
|
}
|
|
321
334
|
|
package/src/split.js
CHANGED
|
@@ -117,17 +117,22 @@ function canonicalDestination(path) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
function safeExportPlanPath(projectRoot, path) {
|
|
120
|
+
export function safeExportPlanPath(projectRoot, path) {
|
|
121
121
|
const absolute = resolve(path);
|
|
122
122
|
const rawGitDir = readGit(['rev-parse', '--git-dir'], projectRoot).trim();
|
|
123
123
|
const gitDir = isAbsolute(rawGitDir) ? rawGitDir : resolve(projectRoot, rawGitDir);
|
|
124
124
|
const canonicalRoot = canonicalExistingPath(projectRoot);
|
|
125
125
|
const canonicalGitDir = canonicalDestination(gitDir);
|
|
126
|
+
const canonicalAicommitDir = canonicalDestination(join(gitDir, 'aicommit'));
|
|
126
127
|
const canonicalPlan = canonicalDestination(absolute);
|
|
127
|
-
|
|
128
|
+
const insideAicommitDir = pathIsWithin(canonicalAicommitDir, canonicalPlan);
|
|
129
|
+
if (
|
|
130
|
+
(pathIsWithin(canonicalRoot, canonicalPlan) && !insideAicommitDir) ||
|
|
131
|
+
(pathIsWithin(canonicalGitDir, canonicalPlan) && !insideAicommitDir)
|
|
132
|
+
) {
|
|
128
133
|
throw fail(
|
|
129
134
|
ERROR_CATEGORIES.CONFIG,
|
|
130
|
-
|
|
135
|
+
"Split plan output must be outside the working tree or inside the repository Git directory's dedicated .git/aicommit/ metadata subdirectory.",
|
|
131
136
|
);
|
|
132
137
|
}
|
|
133
138
|
return absolute;
|
|
@@ -336,8 +341,13 @@ export async function generateSplitPlan(
|
|
|
336
341
|
: []),
|
|
337
342
|
'Rules:',
|
|
338
343
|
`- Each group must represent ONE logical change and use one allowed type: ${policy.types.join(', ')}.`,
|
|
339
|
-
`- Scope mode: ${policy.scope.mode}${policy.scope.values.length ? `; allowed scopes: ${policy.scope.values.join(', ')}` : ''}.`,
|
|
344
|
+
`- Scope mode: ${policy.scope.mode}${policy.scope.values.length ? `; allowed scopes: ${policy.scope.values.join(', ')}` : ''}${policy.scope.disallowedValues?.length ? `; disallowed scopes: ${policy.scope.disallowedValues.join(', ')}` : ''}.`,
|
|
340
345
|
`- Subject text must not exceed ${policy.subject.maxLength} characters.`,
|
|
346
|
+
...(policy.subject.headerMaxLength
|
|
347
|
+
? [
|
|
348
|
+
`- The complete commit header must not exceed ${policy.subject.headerMaxLength} characters.`,
|
|
349
|
+
]
|
|
350
|
+
: []),
|
|
341
351
|
`- Body mode: ${policy.body.mode}; at most ${policy.body.maxLines} non-empty lines.`,
|
|
342
352
|
`- Breaking changes: ${policy.breakingChange}.`,
|
|
343
353
|
'- Give every message a short subject line; when the subject alone does not say it all, add a body of bullet lines (what changed and why), each starting with "- " — the same format the single-commit flow produces.',
|
|
@@ -1277,13 +1287,39 @@ export function executeSplit(
|
|
|
1277
1287
|
groups,
|
|
1278
1288
|
hunkMode: allFiles.some((change) => change.hunks?.length),
|
|
1279
1289
|
});
|
|
1290
|
+
const fingerprintBeforeSnapshot = getSplitStateFingerprint(
|
|
1291
|
+
projectRoot,
|
|
1292
|
+
hasHead(projectRoot),
|
|
1293
|
+
undefined,
|
|
1294
|
+
scope,
|
|
1295
|
+
);
|
|
1296
|
+
if (fingerprintBeforeSnapshot !== plan.fingerprint) {
|
|
1297
|
+
throw fail(
|
|
1298
|
+
ERROR_CATEGORIES.CONCURRENT_MODIFICATION,
|
|
1299
|
+
'Split state changed before the transaction snapshot was captured.',
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
options.faultInjector?.('before_snapshot_capture', { plan });
|
|
1280
1303
|
const snapshots = captureCheckpointSnapshots(projectRoot, scope, allFiles);
|
|
1304
|
+
const fingerprintAfterSnapshot = getSplitStateFingerprint(
|
|
1305
|
+
projectRoot,
|
|
1306
|
+
hasHead(projectRoot),
|
|
1307
|
+
undefined,
|
|
1308
|
+
scope,
|
|
1309
|
+
);
|
|
1310
|
+
if (fingerprintAfterSnapshot !== plan.fingerprint) {
|
|
1311
|
+
throw fail(
|
|
1312
|
+
ERROR_CATEGORIES.CONCURRENT_MODIFICATION,
|
|
1313
|
+
'Split state changed while the transaction snapshot was being captured.',
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1281
1316
|
hunkExecution = validateHunkTransaction(projectRoot, plan, snapshots);
|
|
1282
1317
|
transaction = {
|
|
1283
1318
|
...createSplitCheckpoint(projectRoot, plan, snapshots),
|
|
1284
1319
|
faultInjector: options.faultInjector,
|
|
1285
1320
|
};
|
|
1286
1321
|
} catch (err) {
|
|
1322
|
+
if (err?.category === ERROR_CATEGORIES.CONCURRENT_MODIFICATION) throw err;
|
|
1287
1323
|
throw fail(ERROR_CATEGORIES.GIT_STATE, `Failed to create split checkpoint: ${err.message}`, {
|
|
1288
1324
|
cause: err,
|
|
1289
1325
|
});
|