@fantasticit/sumi 0.14.22 → 0.15.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/dist/cli.js +15 -2
- package/dist/cli.js.map +1 -1
- package/dist/hub/server.d.ts +10 -1
- package/dist/hub/server.js +25 -5
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/start.d.ts +3 -0
- package/dist/hub/start.js +6 -3
- package/dist/hub/start.js.map +1 -1
- package/dist/hub/state.d.ts +11 -3
- package/dist/hub/state.js +20 -1
- package/dist/hub/state.js.map +1 -1
- package/dist/instructions.js +2 -2
- package/dist/launcher.cjs +119 -72
- package/dist/run-stats.d.ts +2 -0
- package/dist/run-stats.js +9 -0
- package/dist/run-stats.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/create/template/control/flows/check.flow.yaml +2 -2
- package/node_modules/@sumi/create/template/control/rubrics/behavior.yaml +2 -2
- package/node_modules/@sumi/create/template/control/rubrics/omission.yaml +1 -1
- package/node_modules/@sumi/create/template/control/rules/development.md +8 -0
- package/node_modules/@sumi/create/template/openspec/config.yaml +3 -0
- package/node_modules/@sumi/kernel/dist/brief.d.ts +4 -0
- package/node_modules/@sumi/kernel/dist/brief.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/config.js +2 -3
- package/node_modules/@sumi/kernel/dist/config.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/covered-run.d.ts +10 -0
- package/node_modules/@sumi/kernel/dist/covered-run.js +49 -0
- package/node_modules/@sumi/kernel/dist/covered-run.js.map +1 -0
- package/node_modules/@sumi/kernel/dist/default-base.d.ts +10 -0
- package/node_modules/@sumi/kernel/dist/default-base.js +63 -0
- package/node_modules/@sumi/kernel/dist/default-base.js.map +1 -0
- package/node_modules/@sumi/kernel/dist/engine.js +112 -30
- package/node_modules/@sumi/kernel/dist/engine.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/flow.js +4 -3
- package/node_modules/@sumi/kernel/dist/flow.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/record.d.ts +17 -0
- package/node_modules/@sumi/kernel/dist/record.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/registry.js +9 -0
- package/node_modules/@sumi/kernel/dist/registry.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/resume.d.ts +4 -1
- package/node_modules/@sumi/kernel/dist/resume.js +24 -16
- package/node_modules/@sumi/kernel/dist/resume.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/runner.d.ts +2 -0
- package/node_modules/@sumi/kernel/dist/runner.js +10 -1
- package/node_modules/@sumi/kernel/dist/runner.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/step-cache.d.ts +4 -0
- package/node_modules/@sumi/kernel/dist/step-cache.js +16 -16
- package/node_modules/@sumi/kernel/dist/step-cache.js.map +1 -1
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/env.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js +14 -1
- package/node_modules/@sumi/plugin-sdk/dist/env.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/index.d.ts +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/project.d.ts +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js +3 -1
- package/node_modules/@sumi/plugin-sdk/dist/project.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/protocol.d.ts +3 -1
- package/node_modules/@sumi/plugin-sdk/dist/protocol.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/repository-view.d.ts +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/repository-view.js +37 -0
- package/node_modules/@sumi/plugin-sdk/dist/repository-view.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.d.ts +10 -0
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js +105 -12
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/validate.js +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/validate.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/instructions/bugfix.md +3 -3
- package/node_modules/@sumi/plugins-core/instructions/feature.md +4 -3
- package/node_modules/@sumi/plugins-core/package.json +3 -3
- package/node_modules/@sumi/plugins-governance/dist/boundary.js +12 -3
- package/node_modules/@sumi/plugins-governance/dist/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.d.ts +1 -1
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js +4 -4
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/checkout.d.ts +26 -3
- package/node_modules/@sumi/plugins-governance/dist/checkout.js +210 -29
- package/node_modules/@sumi/plugins-governance/dist/checkout.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/default-base.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/default-base.js +8 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/default-base.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js +92 -54
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js +17 -3
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/push.js +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/push.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/run-complete.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/run-complete.js +32 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/run-complete.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/comparison-base.d.ts +24 -0
- package/node_modules/@sumi/plugins-governance/dist/comparison-base.js +89 -0
- package/node_modules/@sumi/plugins-governance/dist/comparison-base.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.d.ts +6 -0
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js +95 -4
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/index.js +2 -0
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.d.ts +4 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js +15 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js +21 -7
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.d.ts +10 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js +29 -2
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/preflight.d.ts +9 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js +23 -16
- package/node_modules/@sumi/plugins-governance/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/push-base.d.ts +2 -1
- package/node_modules/@sumi/plugins-governance/dist/push-base.js +3 -2
- package/node_modules/@sumi/plugins-governance/dist/push-base.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/review-handoff.d.ts +20 -0
- package/node_modules/@sumi/plugins-governance/dist/review-handoff.js +13 -0
- package/node_modules/@sumi/plugins-governance/dist/review-handoff.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/runtime-carryover.d.ts +21 -0
- package/node_modules/@sumi/plugins-governance/dist/runtime-carryover.js +155 -0
- package/node_modules/@sumi/plugins-governance/dist/runtime-carryover.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-command.d.ts +7 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-command.js +15 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-command.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-runs.d.ts +9 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-runs.js +23 -0
- package/node_modules/@sumi/plugins-governance/dist/workspace-runs.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/boundary.md +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/push.md +8 -3
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-governance/sumi-plugins.yaml +14 -0
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-openspec/sumi-plugins.yaml +2 -0
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-precedent/sumi-plugins.yaml +5 -0
- package/node_modules/@sumi/plugins-review/dist/convergence.d.ts +1 -1
- package/node_modules/@sumi/plugins-review/dist/convergence.js +43 -21
- package/node_modules/@sumi/plugins-review/dist/convergence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/cost-advice.js +10 -3
- package/node_modules/@sumi/plugins-review/dist/cost-advice.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/dispatch.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js +2 -1
- package/node_modules/@sumi/plugins-review/dist/dispatch.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/dispute.js +23 -7
- package/node_modules/@sumi/plugins-review/dist/dispute.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/finding-scope.d.ts +14 -0
- package/node_modules/@sumi/plugins-review/dist/finding-scope.js +95 -0
- package/node_modules/@sumi/plugins-review/dist/finding-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/fix-list.d.ts +22 -0
- package/node_modules/@sumi/plugins-review/dist/fix-list.js +109 -0
- package/node_modules/@sumi/plugins-review/dist/fix-list.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/gate-edits.d.ts +8 -0
- package/node_modules/@sumi/plugins-review/dist/gate-edits.js +90 -0
- package/node_modules/@sumi/plugins-review/dist/gate-edits.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/instructions.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/instructions.js +5 -3
- package/node_modules/@sumi/plugins-review/dist/instructions.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/dispatch.js +45 -10
- package/node_modules/@sumi/plugins-review/dist/plugins/dispatch.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js +3 -0
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js +1 -1
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/preflight.d.ts +3 -11
- package/node_modules/@sumi/plugins-review/dist/preflight.js +24 -11
- package/node_modules/@sumi/plugins-review/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/recheck.js +3 -11
- package/node_modules/@sumi/plugins-review/dist/recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/report.d.ts +13 -1
- package/node_modules/@sumi/plugins-review/dist/report.js +25 -2
- package/node_modules/@sumi/plugins-review/dist/report.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review-rounds.d.ts +10 -0
- package/node_modules/@sumi/plugins-review/dist/review-rounds.js +56 -0
- package/node_modules/@sumi/plugins-review/dist/review-rounds.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +59 -10
- package/node_modules/@sumi/plugins-review/dist/review.js +220 -30
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/reviewer-view.d.ts +6 -0
- package/node_modules/@sumi/plugins-review/dist/reviewer-view.js +1 -0
- package/node_modules/@sumi/plugins-review/dist/reviewer-view.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +34 -21
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/stats.d.ts +6 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js +18 -4
- package/node_modules/@sumi/plugins-review/dist/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submission.js +18 -6
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submit-files.d.ts +1 -1
- package/node_modules/@sumi/plugins-review/dist/submit-files.js +33 -5
- package/node_modules/@sumi/plugins-review/dist/submit-files.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/node_modules/@sumi/plugins-review/sumi-plugins.yaml +5 -0
- package/package.json +10 -10
|
@@ -3,7 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
6
|
-
import { pruneStaleEntries, touchEntry, configFile, GIT_MAX_BUFFER, gitPaths, isSourceFile, isToolConfig, withFileLock, writeFileAtomic, } from '@sumi/plugin-sdk';
|
|
6
|
+
import { repositoryRef, repositoryText, pruneStaleEntries, touchEntry, configFile, GIT_MAX_BUFFER, gitPaths, isSourceFile, isToolConfig, withFileLock, writeFileAtomic, } from '@sumi/plugin-sdk';
|
|
7
7
|
import { stateDir } from '@sumi/plugins-governance';
|
|
8
8
|
import picomatch from 'picomatch';
|
|
9
9
|
import { parse } from 'yaml';
|
|
@@ -51,7 +51,17 @@ export function pureMoves(root, base) {
|
|
|
51
51
|
return moved;
|
|
52
52
|
try {
|
|
53
53
|
const inZone = scopeMatcher(projectZones(root).openspec ?? []);
|
|
54
|
-
const args = [
|
|
54
|
+
const args = [
|
|
55
|
+
'diff',
|
|
56
|
+
'-M100%',
|
|
57
|
+
'-l0',
|
|
58
|
+
'-z',
|
|
59
|
+
'--name-status',
|
|
60
|
+
'--relative',
|
|
61
|
+
'--diff-filter=R',
|
|
62
|
+
base,
|
|
63
|
+
...(repositoryRef(root) ? [repositoryRef(root)] : []),
|
|
64
|
+
];
|
|
55
65
|
const fields = execFileSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, windowsHide: true }).split('\0');
|
|
56
66
|
for (let at = 0; at + 2 < fields.length; at += 3) {
|
|
57
67
|
const [oldPath, newPath] = [fields[at + 1], fields[at + 2]];
|
|
@@ -66,7 +76,7 @@ export function pureMoves(root, base) {
|
|
|
66
76
|
}
|
|
67
77
|
function readConfig(root) {
|
|
68
78
|
const file = configFile(root);
|
|
69
|
-
return file ? parse(
|
|
79
|
+
return file ? parse(repositoryText(root, file)) : null;
|
|
70
80
|
}
|
|
71
81
|
const globList = (value) => (Array.isArray(value) ? value.filter((g) => typeof g === 'string') : []);
|
|
72
82
|
function zonesOf(config) {
|
|
@@ -164,9 +174,9 @@ export function isDispatchGroup(value) {
|
|
|
164
174
|
}
|
|
165
175
|
export function loadRubric(root, id) {
|
|
166
176
|
const path = join(root, 'control', 'rubrics', `${id}.yaml`);
|
|
167
|
-
|
|
177
|
+
const text = repositoryText(root, `control/rubrics/${id}.yaml`);
|
|
178
|
+
if (text === null)
|
|
168
179
|
throw new Error(`找不到评审准则 ${path}`);
|
|
169
|
-
const text = readFileSync(path, 'utf8');
|
|
170
180
|
const rubric = parse(text);
|
|
171
181
|
if (rubric.dispatchGroup !== undefined && !isDispatchGroup(rubric.dispatchGroup))
|
|
172
182
|
throw new Error(`准则 ${id} 的 dispatchGroup 无效`);
|
|
@@ -184,6 +194,15 @@ export function loadRubric(root, id) {
|
|
|
184
194
|
*/
|
|
185
195
|
export function fileBlobs(root, files) {
|
|
186
196
|
const sorted = [...new Set(files)].sort();
|
|
197
|
+
const ref = repositoryRef(root);
|
|
198
|
+
if (ref) {
|
|
199
|
+
const entries = gitPaths(root, ['ls-tree', '-r', ref, '--', '.']);
|
|
200
|
+
const blobs = new Map(entries.flatMap((entry) => {
|
|
201
|
+
const match = /^\d+ blob ([a-f0-9]+)\t([\s\S]+)$/.exec(entry);
|
|
202
|
+
return match ? [[match[2], match[1]]] : [];
|
|
203
|
+
}));
|
|
204
|
+
return new Map(sorted.map((file) => [file, blobs.get(file) ?? '-']));
|
|
205
|
+
}
|
|
187
206
|
// 子模块在工作区中是目录,与内核的内容摘要一致不纳入
|
|
188
207
|
const present = sorted.filter((f) => existsSync(join(root, f)) && !statSync(join(root, f)).isDirectory());
|
|
189
208
|
const blobs = present.length
|
|
@@ -219,7 +238,8 @@ export function fileIdentities(root, files, base, blobs = fileBlobs(root, files)
|
|
|
219
238
|
};
|
|
220
239
|
try {
|
|
221
240
|
// 树到工作区的 raw 会把未合并路径显示为 M,先批量核对索引,避免将冲突补丁当成普通修改。
|
|
222
|
-
const
|
|
241
|
+
const ref = repositoryRef(root);
|
|
242
|
+
const unmerged = ref ? '' : execFileSync('git', ['ls-files', '--unmerged', '-z', '--', ...files], { ...options, windowsHide: true });
|
|
223
243
|
if (unmerged)
|
|
224
244
|
return new Map(blobs);
|
|
225
245
|
const diff = execFileSync('git', [
|
|
@@ -236,6 +256,7 @@ export function fileIdentities(root, files, base, blobs = fileBlobs(root, files)
|
|
|
236
256
|
'--diff-algorithm=myers',
|
|
237
257
|
'--no-indent-heuristic',
|
|
238
258
|
base,
|
|
259
|
+
...(ref ? [ref] : []),
|
|
239
260
|
'--',
|
|
240
261
|
...files,
|
|
241
262
|
],
|
|
@@ -798,8 +819,95 @@ export function supersedesReviewItem(root, replacement, previous, item) {
|
|
|
798
819
|
}
|
|
799
820
|
return false;
|
|
800
821
|
}
|
|
822
|
+
const REPAIR_WINDOW = 3;
|
|
823
|
+
const repairKey = (file, blob) => `${file}\0${blob}`;
|
|
824
|
+
/** 同一开发线已接受结果中要求修复的问题位置:阻断与 should 的全部问题,跨准则合并。 */
|
|
825
|
+
export function repairLocations(root) {
|
|
826
|
+
const line = currentLineage(root);
|
|
827
|
+
const locations = new Map();
|
|
828
|
+
for (const key of coverageCandidates(root)) {
|
|
829
|
+
const accepted = readAccepted(root, key);
|
|
830
|
+
const coverage = coverageForAccepted(root, key, accepted);
|
|
831
|
+
if (!accepted || !isCoverage(coverage) || !onCurrentLine(coverage.lineage, line))
|
|
832
|
+
continue;
|
|
833
|
+
for (const verdict of accepted.verdicts) {
|
|
834
|
+
if (!isBlocking(verdict) && verdict.priority !== 'should')
|
|
835
|
+
continue;
|
|
836
|
+
for (const finding of verdictFindings(verdict)) {
|
|
837
|
+
const blob = coverage.blobs[finding.file];
|
|
838
|
+
if (!blob)
|
|
839
|
+
continue;
|
|
840
|
+
const id = repairKey(finding.file, blob);
|
|
841
|
+
locations.set(id, [...(locations.get(id) ?? []), finding.line]);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return locations;
|
|
846
|
+
}
|
|
847
|
+
/** 补丁在来源内容中的改动位置:删除与修改取旧行号,纯插入取插入点。 */
|
|
848
|
+
function changedSourceLines(patch) {
|
|
849
|
+
const lines = [];
|
|
850
|
+
let old = null;
|
|
851
|
+
for (const text of patch.split('\n')) {
|
|
852
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+\d+(?:,\d+)? @@/.exec(text);
|
|
853
|
+
if (hunk)
|
|
854
|
+
old = Math.max(Number(hunk[1]), 1);
|
|
855
|
+
else if (old === null)
|
|
856
|
+
continue;
|
|
857
|
+
else if (text.startsWith('-'))
|
|
858
|
+
lines.push(old++);
|
|
859
|
+
else if (text.startsWith('+'))
|
|
860
|
+
lines.push(old);
|
|
861
|
+
else if (text.startsWith(' '))
|
|
862
|
+
old++;
|
|
863
|
+
}
|
|
864
|
+
return lines;
|
|
865
|
+
}
|
|
866
|
+
const near = (line, targets) => targets.some((target) => Math.abs(target - line) <= REPAIR_WINDOW);
|
|
867
|
+
/**
|
|
868
|
+
* 非阻断结论在条目文件只按修复要求改动时沿用:每个变化文件的改动都落在按同一来源内容给出的问题位置上下 3 行内,
|
|
869
|
+
* 且本条目自己的问题不在这些改动附近(问题所在条目须复评核对修复)。行号对不上或无法计算差异时不沿用。
|
|
870
|
+
*/
|
|
871
|
+
function repairCovered(root, coverage, item, identities, verdict, repair) {
|
|
872
|
+
const reviewed = coverage.items.find((entry) => entry.id === item.id);
|
|
873
|
+
if (!reviewed || !item.files.every((file) => reviewed.files.includes(file)))
|
|
874
|
+
return false;
|
|
875
|
+
if (item.areas?.some((area) => !reviewed.areas?.some((old) => old.id === area.id && area.files.every((file) => old.files.includes(file)))))
|
|
876
|
+
return false;
|
|
877
|
+
const own = verdict.verdict === 'fail' ? verdictFindings(verdict) : [];
|
|
878
|
+
const changed = item.files.filter((file) => (coverage.fileIdentities ?? coverage.blobs)[file] !== identities.get(file));
|
|
879
|
+
return changed.every((file) => {
|
|
880
|
+
const blob = coverage.blobs[file];
|
|
881
|
+
const current = repair.current.get(file);
|
|
882
|
+
if (!blob || !current)
|
|
883
|
+
return false;
|
|
884
|
+
const locations = repair.locations().get(repairKey(file, blob));
|
|
885
|
+
if (!locations?.length)
|
|
886
|
+
return false;
|
|
887
|
+
const cache = (repair.changes ??= new Map());
|
|
888
|
+
const id = repairKey(file, blob);
|
|
889
|
+
if (!cache.has(id)) {
|
|
890
|
+
try {
|
|
891
|
+
cache.set(id, changedSourceLines(verifiedPatch(root, file, reviewedContent(root, file, blob, coverage.contents?.[file]), current)));
|
|
892
|
+
}
|
|
893
|
+
catch {
|
|
894
|
+
cache.set(id, null);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
const lines = cache.get(id);
|
|
898
|
+
if (!lines?.length)
|
|
899
|
+
return false;
|
|
900
|
+
const ownLines = own.filter((finding) => finding.file === file).map((finding) => finding.line);
|
|
901
|
+
return lines.every((line) => near(line, locations)) && !ownLines.some((line) => near(line, lines));
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
/** 条目沿用的统一判断:内容未变,或非阻断结论只经历了修复轮改动。规划与提交共用,避免两边口径不一。 */
|
|
905
|
+
export function carriedItemCovered(root, coverage, item, identities, verdict, repair, identity) {
|
|
906
|
+
return (itemCovered(coverage, item, identities, identity) ||
|
|
907
|
+
Boolean(repair && !isBlocking(verdict) && repairCovered(root, coverage, item, identities, verdict, repair)));
|
|
908
|
+
}
|
|
801
909
|
/** 来源选择逐项进行,保留原始接受快照;索引或最近一次来源不决定复用资格。 */
|
|
802
|
-
export function findItemReviews(root, request, identities, targetScopes, usable, unresolved) {
|
|
910
|
+
export function findItemReviews(root, request, identities, targetScopes, usable, unresolved, repair) {
|
|
803
911
|
const selected = new Map();
|
|
804
912
|
for (const key of coverageCandidates(root).sort()) {
|
|
805
913
|
const accepted = readAccepted(root, key);
|
|
@@ -814,11 +922,11 @@ export function findItemReviews(root, request, identities, targetScopes, usable,
|
|
|
814
922
|
const identity = coverage.itemContents[item.id];
|
|
815
923
|
if (!identity || identity.definition !== request.itemContents?.[item.id]?.definition)
|
|
816
924
|
continue;
|
|
817
|
-
if (!itemCovered(coverage, item, identities, request.itemContents?.[item.id]))
|
|
818
|
-
continue;
|
|
819
925
|
const verdict = accepted.verdicts.find((entry) => entry.item === item.id);
|
|
820
926
|
if (!verdict)
|
|
821
927
|
continue;
|
|
928
|
+
if (!carriedItemCovered(root, coverage, item, identities, verdict, repair, request.itemContents?.[item.id]))
|
|
929
|
+
continue;
|
|
822
930
|
// 失败只按完全相同的条目内容采用;窄投影不能把范围外的问题带入本次。
|
|
823
931
|
if (isBlocking(verdict) && identity.key !== request.itemContents?.[item.id]?.key)
|
|
824
932
|
continue;
|
|
@@ -915,7 +1023,7 @@ function objectContent(root, args) {
|
|
|
915
1023
|
* 已评审版本的原文:优先用覆盖记录保存的原文并按 blob 校验;记录因大小上限未保存时,从对象库按 blob 读取。
|
|
916
1024
|
* 保存的原文与 blob 不符说明记录被改写,抛错而不改从对象库读取。
|
|
917
1025
|
*/
|
|
918
|
-
function reviewedContent(root, file, blob, encoded) {
|
|
1026
|
+
export function reviewedContent(root, file, blob, encoded) {
|
|
919
1027
|
if (!isBlob(blob))
|
|
920
1028
|
throw new Error('缺少 blob');
|
|
921
1029
|
if (encoded) {
|
|
@@ -940,7 +1048,7 @@ function baseContent(root, file, base) {
|
|
|
940
1048
|
* 生成单个文件从起点原文到当前版本的补丁。两侧内容都须是有效 UTF-8 文本,当前内容须与请求 blob 一致,
|
|
941
1049
|
* 补丁文件头改写为仓库路径;任何一项不满足都抛错,调用方据此退回完整评审。
|
|
942
1050
|
*/
|
|
943
|
-
function verifiedPatch(root, file, raw, after) {
|
|
1051
|
+
export function verifiedPatch(root, file, raw, after) {
|
|
944
1052
|
if (!isBlob(after))
|
|
945
1053
|
throw new Error('缺少 blob');
|
|
946
1054
|
const currentRaw = readFileSync(join(root, file));
|
|
@@ -1086,16 +1194,20 @@ export function findIncrementalReview(root, rubricDigest, items, current, base,
|
|
|
1086
1194
|
return null;
|
|
1087
1195
|
}
|
|
1088
1196
|
/** 同一分支、基准与准则的结论按接受时间排列,沿用现有覆盖键与开发线归档。 */
|
|
1089
|
-
export function reviewHistory(root, rubricDigest, base, current = currentLineage(root)) {
|
|
1197
|
+
export function reviewHistory(root, rubricDigest, base, current = currentLineage(root), acrossBases = false) {
|
|
1090
1198
|
return coverageCandidates(root)
|
|
1091
1199
|
.flatMap((key) => {
|
|
1092
1200
|
const accepted = readAccepted(root, key);
|
|
1093
1201
|
const coverage = coverageForAccepted(root, key, accepted);
|
|
1094
|
-
if (!accepted ||
|
|
1202
|
+
if (!accepted ||
|
|
1203
|
+
!isCoverage(coverage) ||
|
|
1204
|
+
(rubricDigest !== null && coverage.rubricDigest !== rubricDigest) ||
|
|
1205
|
+
(!acrossBases && (coverage.base ?? null) !== base))
|
|
1095
1206
|
return [];
|
|
1096
1207
|
if (coverageKey(coverage) !== key || !onCurrentLine(coverage.lineage, current))
|
|
1097
1208
|
return [];
|
|
1098
|
-
|
|
1209
|
+
// 旧格式的覆盖证据单独返回,不改写已接受结果及其摘要身份。
|
|
1210
|
+
return [{ key, result: accepted, coverage, time: accepted.acceptedAt ?? statSync(join(reviewsDir(root), `${key}.json`)).mtimeMs }];
|
|
1099
1211
|
})
|
|
1100
1212
|
.sort((a, b) => b.time - a.time || b.key.localeCompare(a.key));
|
|
1101
1213
|
}
|
|
@@ -1142,24 +1254,55 @@ export function resolvedBlockingFindings(history, root = '.') {
|
|
|
1142
1254
|
}
|
|
1143
1255
|
return [...resolved.values()];
|
|
1144
1256
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
export function failRounds(root, rubricDigest, base, items, history = reviewHistory(root,
|
|
1257
|
+
/** 开发线跨基准、跨条目累计,各准则取最大值。支持范围由调用方过滤。 */
|
|
1258
|
+
export function failRounds(root, rubricDigest, base, items, history = reviewHistory(root, null, base, currentLineage(root), true)) {
|
|
1147
1259
|
const counts = new Map();
|
|
1148
|
-
const finished = new Set();
|
|
1149
1260
|
for (const { result } of history) {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
if (!verdict)
|
|
1155
|
-
continue;
|
|
1156
|
-
if (isBlocking(verdict))
|
|
1157
|
-
counts.set(item.id, (counts.get(item.id) ?? 0) + 1);
|
|
1158
|
-
else
|
|
1159
|
-
finished.add(item.id);
|
|
1160
|
-
}
|
|
1261
|
+
if (!result.verdicts.some(isBlocking))
|
|
1262
|
+
continue;
|
|
1263
|
+
const rubric = result.coverage?.rubric ?? result.coverage?.rubricDigest ?? rubricDigest;
|
|
1264
|
+
counts.set(rubric, (counts.get(rubric) ?? 0) + 1);
|
|
1161
1265
|
}
|
|
1162
|
-
|
|
1266
|
+
const count = Math.max(0, ...counts.values());
|
|
1267
|
+
return new Map(items.map((item) => [item.id, count]));
|
|
1268
|
+
}
|
|
1269
|
+
/** 沿用旧结果的单定位形状;新结果每条问题形成独立发现。 */
|
|
1270
|
+
export function verdictFindings(verdict) {
|
|
1271
|
+
return verdict.findings?.length
|
|
1272
|
+
? verdict.findings
|
|
1273
|
+
: [
|
|
1274
|
+
{
|
|
1275
|
+
file: verdict.file ?? '',
|
|
1276
|
+
line: verdict.line ?? 1,
|
|
1277
|
+
summary: verdict.reason,
|
|
1278
|
+
quote: verdict.quotes?.find((quote) => quote.file === verdict.file)?.text,
|
|
1279
|
+
cause: verdict.cause,
|
|
1280
|
+
category: verdict.category,
|
|
1281
|
+
},
|
|
1282
|
+
];
|
|
1283
|
+
}
|
|
1284
|
+
export function reviewFindings(rubric, verdicts) {
|
|
1285
|
+
return verdicts
|
|
1286
|
+
.filter(isBlocking)
|
|
1287
|
+
.flatMap((verdict) => {
|
|
1288
|
+
const findings = verdict.findings?.length
|
|
1289
|
+
? verdict.findings.map((finding) => ({ file: finding.file, line: finding.line, message: finding.summary }))
|
|
1290
|
+
: [{ file: verdict.file, line: verdict.line, message: verdict.reason }];
|
|
1291
|
+
return findings.map((finding) => ({
|
|
1292
|
+
id: '',
|
|
1293
|
+
rule: `${rubric}#${verdict.item}`,
|
|
1294
|
+
severity: 'error',
|
|
1295
|
+
message: finding.message,
|
|
1296
|
+
file: finding.file,
|
|
1297
|
+
line: finding.line,
|
|
1298
|
+
...(verdict.classification ? { classification: verdict.classification } : {}),
|
|
1299
|
+
}));
|
|
1300
|
+
})
|
|
1301
|
+
.map((finding, index) => ({ ...finding, id: `F${index + 1}` }));
|
|
1302
|
+
}
|
|
1303
|
+
export function primaryVerdict(verdict) {
|
|
1304
|
+
const first = verdict.findings?.[0];
|
|
1305
|
+
return first ? { ...verdict, file: first.file, line: first.line } : verdict;
|
|
1163
1306
|
}
|
|
1164
1307
|
export function resultDigest(result) {
|
|
1165
1308
|
return sha256(JSON.stringify(result));
|
|
@@ -1204,6 +1347,29 @@ function optionalFieldErrors(item, verdict) {
|
|
|
1204
1347
|
[value.command, value.test].some((text) => typeof text === 'string' && !!text.trim()),
|
|
1205
1348
|
'含 entrypoint 和 command 或 test 的真实入口复现证据',
|
|
1206
1349
|
],
|
|
1350
|
+
[
|
|
1351
|
+
'priority',
|
|
1352
|
+
(value) => value === 'should' && verdict.verdict === 'fail' && verdict.classification === 'follow-up',
|
|
1353
|
+
'should,且 classification 必须为 follow-up',
|
|
1354
|
+
],
|
|
1355
|
+
['cause', (value) => isRecord(value) && isQuote({ ...value, text: '定位' }), '含 file 与正整数 line 的定位'],
|
|
1356
|
+
[
|
|
1357
|
+
'category',
|
|
1358
|
+
(value) => ['data-loss', 'authz', 'security', 'gate-bypass'].includes(String(value)),
|
|
1359
|
+
'data-loss、authz、security 或 gate-bypass',
|
|
1360
|
+
],
|
|
1361
|
+
[
|
|
1362
|
+
'findings',
|
|
1363
|
+
(value) => verdict.verdict === 'fail' &&
|
|
1364
|
+
Array.isArray(value) &&
|
|
1365
|
+
value.length > 0 &&
|
|
1366
|
+
value.every((finding) => isRecord(finding) &&
|
|
1367
|
+
isQuote({ ...finding, text: finding.summary }) &&
|
|
1368
|
+
(finding.quote === undefined || (typeof finding.quote === 'string' && !!finding.quote.trim())) &&
|
|
1369
|
+
(finding.cause === undefined || (isRecord(finding.cause) && isQuote({ ...finding.cause, text: '定位' }))) &&
|
|
1370
|
+
(finding.category === undefined || ['data-loss', 'authz', 'security', 'gate-bypass'].includes(String(finding.category)))),
|
|
1371
|
+
'每条含 file、正整数 line 与非空 summary 的非空问题数组',
|
|
1372
|
+
],
|
|
1207
1373
|
['uncertain', (value) => typeof value === 'boolean', '布尔值'],
|
|
1208
1374
|
];
|
|
1209
1375
|
return rules.flatMap(([field, valid, expected]) => verdict[field] === undefined || valid(verdict[field]) ? [] : [`条目 ${item} 的 ${field} 必须是${expected}`]);
|
|
@@ -1244,7 +1410,7 @@ export function validateReviewResult(request, value) {
|
|
|
1244
1410
|
errors.push(`条目 ${item.id} 缺少理由`);
|
|
1245
1411
|
else if (request.requireEvidence && v.verdict === 'pass' && (typeof v.evidence !== 'string' || !v.evidence.trim()))
|
|
1246
1412
|
errors.push(`条目 ${item.id} 通过时缺少核查证据`);
|
|
1247
|
-
else if (v.verdict === 'fail' && (typeof v.file !== 'string' || !v.file.trim()))
|
|
1413
|
+
else if (v.verdict === 'fail' && !Array.isArray(v.findings) && (typeof v.file !== 'string' || !v.file.trim()))
|
|
1248
1414
|
errors.push(`条目 ${item.id} 判为 fail 时必须给出文件定位`);
|
|
1249
1415
|
if (v?.verdict === 'fail' && request.classificationRequired && v.classification === undefined && !isCarried(request, v))
|
|
1250
1416
|
errors.push(`条目 ${item.id} 判为 fail 时必须填写 classification(blocking 或 follow-up)`);
|
|
@@ -1282,6 +1448,30 @@ export function validateReviewResult(request, value) {
|
|
|
1282
1448
|
errors.push(`条目 ${item.id} 缺少区域 ${area.id} 的核查证据`);
|
|
1283
1449
|
}
|
|
1284
1450
|
}
|
|
1451
|
+
if (v &&
|
|
1452
|
+
!isCarried(request, v) &&
|
|
1453
|
+
v.verdict === 'fail' &&
|
|
1454
|
+
request.classificationRequired &&
|
|
1455
|
+
v.classification !== 'follow-up' &&
|
|
1456
|
+
v.uncertain !== true &&
|
|
1457
|
+
!(item.id === 'precedent-coverage' && item.obligationTargets?.some((target) => typeof target.catalog === 'string'))) {
|
|
1458
|
+
const primary = Array.isArray(v.findings) && isRecord(v.findings[0]) ? v.findings[0] : v;
|
|
1459
|
+
if (typeof primary.file !== 'string' || !primary.file.trim())
|
|
1460
|
+
errors.push(`条目 ${item.id} blocking 缺少 file`);
|
|
1461
|
+
if (!Number.isSafeInteger(primary.line) || Number(primary.line) < 1)
|
|
1462
|
+
errors.push(`条目 ${item.id} blocking 缺少正整数 line`);
|
|
1463
|
+
if (!Array.isArray(v.quotes) || !v.quotes.some((quote) => isRecord(quote) && quote.file === primary.file && isQuote(quote)))
|
|
1464
|
+
errors.push(`条目 ${item.id} blocking 缺少位于 file 的 quotes 引文`);
|
|
1465
|
+
if (!v.reproduction)
|
|
1466
|
+
errors.push(`条目 ${item.id} blocking 缺少 reproduction(entrypoint 与 command 或 test)`);
|
|
1467
|
+
if (typeof v.evidence !== 'string' || !v.evidence.trim())
|
|
1468
|
+
errors.push(`条目 ${item.id} blocking 缺少非空 evidence`);
|
|
1469
|
+
if (Array.isArray(v.findings))
|
|
1470
|
+
v.findings.forEach((finding, index) => {
|
|
1471
|
+
if (!isRecord(finding) || typeof finding.quote !== 'string' || !finding.quote.trim())
|
|
1472
|
+
errors.push(`条目 ${item.id} findings[${index}] blocking 缺少 quote 引文`);
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1285
1475
|
if (v?.uncertain === true && v.verdict !== 'fail')
|
|
1286
1476
|
errors.push(`条目 ${item.id} 无法判定时必须判为 fail`);
|
|
1287
1477
|
}
|