@boyingliu01/xp-gate 0.41.10 → 0.41.56
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/adapters/gate-3.sh +28 -1
- package/adapters/gate-6-layers.sh +18 -1
- package/bin/xp-gate.js +13 -0
- package/gate-3.sh +28 -1
- package/gate-6-layers.sh +18 -1
- package/gates/python-health.ts +74 -26
- package/gates/test-layers.ts +94 -9
- package/hooks/gate-3.sh +28 -1
- package/hooks/gate-6-layers.sh +18 -1
- package/hooks/gate-entries/gate-11-entry.sh +21 -0
- package/hooks/gate-entries/gate-2-entry.sh +15 -0
- package/hooks/install.sh +15 -3
- package/hooks/pre-commit +90 -13
- package/hooks/pre-push +10 -1
- package/hooks/sprint-gate.sh +101 -13
- package/lib/check-alignment-runner.cjs +97 -0
- package/lib/check.js +6 -0
- package/lib/crap-cli.js +14 -6
- package/lib/delphi-setup.js +13 -0
- package/lib/doctor-tui.js +205 -102
- package/lib/doctor.js +283 -31
- package/lib/gate-runner.js +14 -3
- package/lib/init-install.js +299 -0
- package/lib/init-languages.js +158 -0
- package/lib/init-manifest.js +165 -0
- package/lib/init-md-injection.js +58 -0
- package/lib/init.js +134 -500
- package/lib/install-skill.js +66 -1
- package/lib/layer-baseline.cjs +94 -0
- package/lib/mattpocock-license-verdict.json +7 -0
- package/lib/uninstall-skills.js +140 -0
- package/lib/uninstall.js +41 -100
- package/lib/update-skill.js +9 -1
- package/package.json +3 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/claude-code/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/claude-code/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/lib/delphi-evidence.d.ts +59 -0
- package/plugins/dsh/lib/delphi-evidence.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-evidence.js +128 -0
- package/plugins/dsh/lib/delphi-finding.d.ts +123 -0
- package/plugins/dsh/lib/delphi-finding.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-finding.js +332 -0
- package/plugins/dsh/lib/delphi-findings-parse.d.ts +29 -0
- package/plugins/dsh/lib/delphi-findings-parse.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-findings-parse.js +138 -0
- package/plugins/dsh/lib/delphi-ledger.d.ts +55 -0
- package/plugins/dsh/lib/delphi-ledger.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-ledger.js +124 -0
- package/plugins/dsh/lib/delphi-run.d.ts +7 -0
- package/plugins/dsh/lib/delphi-run.d.ts.map +1 -1
- package/plugins/dsh/lib/delphi-run.js +48 -18
- package/plugins/dsh/lib/delphi-seats.d.ts +34 -0
- package/plugins/dsh/lib/delphi-seats.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-seats.js +40 -0
- package/plugins/dsh/lib/evidence.d.ts +21 -0
- package/plugins/dsh/lib/evidence.d.ts.map +1 -1
- package/plugins/dsh/lib/evidence.js +3 -0
- package/plugins/dsh/lib/index.d.ts.map +1 -1
- package/plugins/dsh/lib/index.js +12 -0
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/src/delphi-evidence.test.ts +100 -0
- package/plugins/dsh/src/delphi-evidence.ts +201 -0
- package/plugins/dsh/src/delphi-finding.test.ts +333 -0
- package/plugins/dsh/src/delphi-finding.ts +446 -0
- package/plugins/dsh/src/delphi-findings-parse.test.ts +100 -0
- package/plugins/dsh/src/delphi-findings-parse.ts +158 -0
- package/plugins/dsh/src/delphi-findings.test.ts +4 -0
- package/plugins/dsh/src/delphi-ledger.test.ts +210 -0
- package/plugins/dsh/src/delphi-ledger.ts +158 -0
- package/plugins/dsh/src/delphi-run.test.ts +71 -68
- package/plugins/dsh/src/delphi-run.ts +80 -24
- package/plugins/dsh/src/delphi-seats.test.ts +117 -0
- package/plugins/dsh/src/delphi-seats.ts +50 -0
- package/plugins/dsh/src/evidence-findings.test.ts +75 -0
- package/plugins/dsh/src/evidence.ts +25 -0
- package/plugins/dsh/src/index.ts +14 -0
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/opencode/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/opencode/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/INSTALL.md +22 -3
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/plugins/qoder/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/plugins/qoder/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/index.ts +50 -1
- package/scripts/delphi-config-read.cjs +43 -6
- package/scripts/delphi-external-review.cjs +69 -12
- package/scripts/delphi-prompts.cjs +47 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/delphi-review/INSTALL.md +22 -3
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/sprint-flow/references/definition-of-done.md +2 -2
- package/skills/sprint-flow/references/phase-3-build.md +1 -1
- package/skills/sprint-flow/references/phase-4-verify.md +2 -2
- package/skills/sprint-flow/references/phase-6-close.md +17 -0
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/sprint-gate.sh +101 -13
- package/mutation/stryker-types.ts +0 -14
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The finding ledger: how a review's problems stop being written in prose.
|
|
3
|
+
*
|
|
4
|
+
* A Delphi review's cost is in its ROUNDS, and a round is wasted when a seat that
|
|
5
|
+
* already reported a real problem keeps voting REQUEST_CHANGES after the problem
|
|
6
|
+
* was fixed -- the binary verdict cannot say "still the same five issues, all
|
|
7
|
+
* resolved". `parseVerdict` only knows two words, so the itemization lives here:
|
|
8
|
+
* each problem is a finding with a stable identity, and identity is what lets a
|
|
9
|
+
* later round say "this one is closed" instead of "I still disapprove".
|
|
10
|
+
*
|
|
11
|
+
* Why identity is not a hash of the title: the title is natural language, and
|
|
12
|
+
* Chinese wording, punctuation and code snippets change between rounds. A hash
|
|
13
|
+
* that moves takes the freeze with it -- silently, because nothing errors; the
|
|
14
|
+
* review merely grows a round. So identity is a DETERMINISTIC MATCHER, pinned by
|
|
15
|
+
* tests, not a hope that the model says it the same way twice.
|
|
16
|
+
*
|
|
17
|
+
* @test REQ-DSH-016
|
|
18
|
+
* @intent 让"问题已修好"变成可判定的状态(条目已关闭),而不是靠席位改变措辞;
|
|
19
|
+
* 并把字面稳定性从"模型措辞稳定"转移到"确定性匹配器"。
|
|
20
|
+
* @covers AC-DSH-016-03
|
|
21
|
+
*/
|
|
22
|
+
export { validateEvidence } from "./delphi-evidence.js";
|
|
23
|
+
/** Identifiers shorter than this are noise (`if`, `for`, common locals). */
|
|
24
|
+
const MIN_KEYWORD_LEN = 4;
|
|
25
|
+
/** Jaccard overlap at or above this on the SAME path means "the same finding". */
|
|
26
|
+
const SAME_ITEM_JACCARD = 0.5;
|
|
27
|
+
/** Dice overlap that marks a no-keyword-overlap restatement of one defect. */
|
|
28
|
+
const REPHRASE_DICE = 0.75;
|
|
29
|
+
/** Below two keywords, overlap carries no information. */
|
|
30
|
+
const MIN_KEYWORDS_FOR_MATCHING = 2;
|
|
31
|
+
/** Near-identical wording across a MOVED path names the same defect. */
|
|
32
|
+
const CROSS_PATH_DICE = 0.9;
|
|
33
|
+
/** Lower edge of the "uncertain" band: below the same-item bar, above noise. */
|
|
34
|
+
const UNCERTAIN_JACCARD = 0.4;
|
|
35
|
+
/** Lower edge of the uncertain Dice band. */
|
|
36
|
+
const UNCERTAIN_DICE = 0.65;
|
|
37
|
+
/** Width of the zero-padded numeric suffix in an id, e.g. `TC-01`. */
|
|
38
|
+
const ID_PAD = 2;
|
|
39
|
+
/** Severity rank; higher blocks harder. */
|
|
40
|
+
const SEVERITY_RANK = { minor: 0, major: 1, critical: 2 };
|
|
41
|
+
/** Words that appear in every review and therefore identify nothing. */
|
|
42
|
+
const STOPWORDS = new Set([
|
|
43
|
+
"the", "and", "that", "this", "with", "from", "when", "then", "than", "into",
|
|
44
|
+
"does", "doesn", "should", "would", "could", "must", "cannot", "fail", "fails",
|
|
45
|
+
"will", "have", "been", "also", "only", "case", "code", "file", "test", "tests",
|
|
46
|
+
]);
|
|
47
|
+
/** Two upper-case letters naming the seat; unknown seats get `XX`. */
|
|
48
|
+
const SEAT_PREFIXES = {
|
|
49
|
+
architecture: "AR",
|
|
50
|
+
technical: "TC",
|
|
51
|
+
feasibility: "FC",
|
|
52
|
+
};
|
|
53
|
+
/** What a brand-new entry starts as. */
|
|
54
|
+
const FRESH = {
|
|
55
|
+
status: "open",
|
|
56
|
+
statusChangedAtRound: 0,
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Every fragment a title offers as a keyword candidate, lower-cased.
|
|
60
|
+
*
|
|
61
|
+
* Backticks are read first, then bare identifiers, so `restorePyproject(path)`
|
|
62
|
+
* contributes both the whole fragment and its identifier.
|
|
63
|
+
*/
|
|
64
|
+
function keywordCandidates(title) {
|
|
65
|
+
const fragments = [...title.matchAll(/`([^`]+)`/g)].map((m) => m[1].toLowerCase());
|
|
66
|
+
const identifiers = [...title.matchAll(/[A-Za-z_][A-Za-z0-9_]*/g)].map((m) => m[0].toLowerCase());
|
|
67
|
+
return [...fragments, ...identifiers];
|
|
68
|
+
}
|
|
69
|
+
/** Whether a lower-cased fragment is specific enough to identify anything. */
|
|
70
|
+
function isDistinctive(word) {
|
|
71
|
+
return word.length >= MIN_KEYWORD_LEN && !STOPWORDS.has(word);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The identifiers and backticked fragments in a title, lower-cased and deduped.
|
|
75
|
+
*
|
|
76
|
+
* ASCII only, deliberately: Chinese word segmentation is itself unstable, and an
|
|
77
|
+
* unstable key on the secondary index reproduces the drift a hash would have.
|
|
78
|
+
*/
|
|
79
|
+
export function extractKeywords(title) {
|
|
80
|
+
return [...new Set(keywordCandidates(title).filter(isDistinctive))].sort();
|
|
81
|
+
}
|
|
82
|
+
/** Collapse the path forms that name one file into a single comparable string. */
|
|
83
|
+
function collapsePathForms(location) {
|
|
84
|
+
return location.replace(/^\.\//, "").replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A location without its line number.
|
|
88
|
+
*
|
|
89
|
+
* Line numbers move when an unrelated line is inserted above, which would make
|
|
90
|
+
* one finding look like two and defeat the freeze. The path is the stable part.
|
|
91
|
+
*/
|
|
92
|
+
export function normalizeLocation(location) {
|
|
93
|
+
return collapsePathForms(location.replace(/:\d+(?::\d+)?$/, ""));
|
|
94
|
+
}
|
|
95
|
+
/** Whether two keyword sets are both large enough for a ratio to mean anything. */
|
|
96
|
+
function comparable(a, b) {
|
|
97
|
+
return a.length >= MIN_KEYWORDS_FOR_MATCHING && b.length >= MIN_KEYWORDS_FOR_MATCHING;
|
|
98
|
+
}
|
|
99
|
+
/** How many of `b`'s words also appear in `a`. */
|
|
100
|
+
function sharedCount(a, b) {
|
|
101
|
+
const left = new Set(a);
|
|
102
|
+
return b.filter((word) => left.has(word)).length;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Jaccard overlap of two keyword sets (|intersection| / |union|).
|
|
106
|
+
*
|
|
107
|
+
* Returns 0 below the keyword minimum. The guard lives HERE, not only in the
|
|
108
|
+
* caller: a one-keyword set has Jaccard 0 or 1 and nothing between, so a public
|
|
109
|
+
* score reporting 1.0 for two identical single words invites exactly the caller
|
|
110
|
+
* that merges on it.
|
|
111
|
+
*/
|
|
112
|
+
export function keywordOverlap(a, b) {
|
|
113
|
+
if (!comparable(a, b))
|
|
114
|
+
return 0;
|
|
115
|
+
return sharedCount(a, b) / new Set([...a, ...b]).size;
|
|
116
|
+
}
|
|
117
|
+
/** Dice coefficient of two keyword sets; the rephrase detector. */
|
|
118
|
+
/**
|
|
119
|
+
* Dice overlap of two keyword sets; the rephrase detector.
|
|
120
|
+
*
|
|
121
|
+
* Refuses below the keyword minimum for the same reason `keywordOverlap` does:
|
|
122
|
+
* one shared keyword gives Dice 2*1/(1+1) = 1.0, which clears every bar this
|
|
123
|
+
* module has. Measured -- without this guard, EVERY single-keyword finding looked
|
|
124
|
+
* like a re-filing of every disproved one, and the freeze could not be trusted.
|
|
125
|
+
*/
|
|
126
|
+
function keywordDice(a, b) {
|
|
127
|
+
if (!comparable(a, b))
|
|
128
|
+
return 0;
|
|
129
|
+
const total = new Set(a).size + new Set(b).size;
|
|
130
|
+
return total === 0 ? 0 : (2 * sharedCount(a, b)) / total;
|
|
131
|
+
}
|
|
132
|
+
/** Whether a candidate and an entry name the same file. */
|
|
133
|
+
function samePath(candidate, existing) {
|
|
134
|
+
return normalizeLocation(candidate.location) === existing.location;
|
|
135
|
+
}
|
|
136
|
+
/** Keywords for a candidate; a pure function of the title. */
|
|
137
|
+
function keywordsOf(candidate) {
|
|
138
|
+
return extractKeywords(candidate.title);
|
|
139
|
+
}
|
|
140
|
+
/** Same path and overlapping keywords at or above the same-item bar. */
|
|
141
|
+
function isSameItem(candidate, existing) {
|
|
142
|
+
const keys = keywordsOf(candidate);
|
|
143
|
+
if (!comparable(keys, existing.keywords))
|
|
144
|
+
return false;
|
|
145
|
+
return samePath(candidate, existing) && keywordOverlap(keys, existing.keywords) >= SAME_ITEM_JACCARD;
|
|
146
|
+
}
|
|
147
|
+
/** Same path, worded as a restatement of the same identifiers. */
|
|
148
|
+
function isRephrase(candidate, existing) {
|
|
149
|
+
const keys = keywordsOf(candidate);
|
|
150
|
+
if (!comparable(keys, existing.keywords))
|
|
151
|
+
return false;
|
|
152
|
+
return samePath(candidate, existing) && keywordDice(keys, existing.keywords) >= REPHRASE_DICE;
|
|
153
|
+
}
|
|
154
|
+
/** A settled-by-disproof entry this candidate may be re-filing elsewhere. */
|
|
155
|
+
function resemblesDisproved(candidate, ledger) {
|
|
156
|
+
const keys = keywordsOf(candidate);
|
|
157
|
+
return ledger.find((e) => e.status === "disproved" && keywordDice(keys, e.keywords) >= CROSS_PATH_DICE);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The settled entry a candidate sits NEXT TO without clearing either bar.
|
|
161
|
+
*
|
|
162
|
+
* Returning it (instead of merging) is the "uncertain" outcome: a guess must not
|
|
163
|
+
* join two findings, but a human should be told they may be the same.
|
|
164
|
+
*/
|
|
165
|
+
/** One entry's similarity to a candidate, or null when it clears neither bar. */
|
|
166
|
+
function uncertainScore(keys, entry) {
|
|
167
|
+
const jaccard = keywordOverlap(keys, entry.keywords);
|
|
168
|
+
const dice = keywordDice(keys, entry.keywords);
|
|
169
|
+
if (jaccard < UNCERTAIN_JACCARD && dice < UNCERTAIN_DICE)
|
|
170
|
+
return null;
|
|
171
|
+
return Math.max(jaccard, dice);
|
|
172
|
+
}
|
|
173
|
+
/** Higher score wins; equal scores break on id so the choice is ledger-order independent. */
|
|
174
|
+
function isBetterMatch(score, finding, best) {
|
|
175
|
+
if (best === undefined)
|
|
176
|
+
return true;
|
|
177
|
+
if (score !== best.score)
|
|
178
|
+
return score > best.score;
|
|
179
|
+
return finding.id < best.finding.id;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The settled entry a candidate sits NEXT TO without clearing either merge bar.
|
|
183
|
+
*
|
|
184
|
+
* The BEST match wins, not the first one found: `candidateOf` is a hint a human
|
|
185
|
+
* acts on, and pointing it at an arbitrary earlier entry makes the hint depend on
|
|
186
|
+
* ledger order rather than on the code.
|
|
187
|
+
*/
|
|
188
|
+
function nearestUncertain(candidate, ledger) {
|
|
189
|
+
const keys = keywordsOf(candidate);
|
|
190
|
+
return ledger
|
|
191
|
+
.filter((entry) => samePath(candidate, entry))
|
|
192
|
+
.map((entry) => ({ finding: entry, score: uncertainScore(keys, entry) }))
|
|
193
|
+
.reduce((best, row) => (row.score !== null && isBetterMatch(row.score, row.finding, best) ? { finding: row.finding, score: row.score } : best), undefined)?.finding;
|
|
194
|
+
}
|
|
195
|
+
/** Whether an id already belongs to this seat's prefix. */
|
|
196
|
+
function ownsPrefix(finding, prefix) {
|
|
197
|
+
return finding.id.startsWith(`${prefix}-`);
|
|
198
|
+
}
|
|
199
|
+
/** The numeric suffix of an id, or 0 when it has none. */
|
|
200
|
+
function idSuffix(finding) {
|
|
201
|
+
const parsed = Number(finding.id.split("-")[1]);
|
|
202
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
203
|
+
}
|
|
204
|
+
/** The next free id for a seat, e.g. `TC-01`. */
|
|
205
|
+
/**
|
|
206
|
+
* The next free id for a seat, e.g. `TC-01`.
|
|
207
|
+
*
|
|
208
|
+
* Reduced rather than spread: `Math.max(0, ...ids)` passes one argument per
|
|
209
|
+
* entry, and a long review (or a reused ledger) hits the engine's argument limit
|
|
210
|
+
* as a RangeError at the one moment ids must still be assigned.
|
|
211
|
+
*/
|
|
212
|
+
function nextId(seat, ledger) {
|
|
213
|
+
const prefix = SEAT_PREFIXES[seat] ?? "XX";
|
|
214
|
+
const highest = ledger
|
|
215
|
+
.filter((f) => ownsPrefix(f, prefix))
|
|
216
|
+
.reduce((max, f) => Math.max(max, idSuffix(f)), 0);
|
|
217
|
+
return `${prefix}-${String(highest + 1).padStart(ID_PAD, "0")}`;
|
|
218
|
+
}
|
|
219
|
+
/** Only escalate: lowering a severity needs evidence, raising it does not. */
|
|
220
|
+
function highestSeverity(left, right) {
|
|
221
|
+
if (left === undefined)
|
|
222
|
+
return right;
|
|
223
|
+
return SEVERITY_RANK[left] >= SEVERITY_RANK[right] ? left : right;
|
|
224
|
+
}
|
|
225
|
+
/** Widest keyword set, so a later restatement still overlaps. */
|
|
226
|
+
function unionKeywords(candidate, reuse) {
|
|
227
|
+
if (reuse === undefined)
|
|
228
|
+
return keywordsOf(candidate);
|
|
229
|
+
return [...new Set([...reuse.keywords, ...keywordsOf(candidate)])].sort();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The owner set after `seat` joins it: existing contributors, plus this one.
|
|
233
|
+
*
|
|
234
|
+
* A legacy entry without `raisedBy` falls back to its single `seat`, so a ledger
|
|
235
|
+
* recorded before this field existed still closes correctly.
|
|
236
|
+
*/
|
|
237
|
+
function unionSeats(reuse, seat) {
|
|
238
|
+
const existing = reuse.raisedBy ?? (reuse.seat === "multi" ? [] : [reuse.seat]);
|
|
239
|
+
return [...new Set([...existing, seat])];
|
|
240
|
+
}
|
|
241
|
+
/** Whether a second, different seat has now reported the same finding. */
|
|
242
|
+
function reportedByOther(candidate, reuse) {
|
|
243
|
+
if (reuse === undefined || reuse.seat === "multi")
|
|
244
|
+
return false;
|
|
245
|
+
return reuse.seat !== candidate.seat;
|
|
246
|
+
}
|
|
247
|
+
/** `multi` once two seats agree on one id; otherwise the seat that owns it. */
|
|
248
|
+
function seatFor(candidate, reuse) {
|
|
249
|
+
if (reuse === undefined)
|
|
250
|
+
return candidate.seat;
|
|
251
|
+
return reportedByOther(candidate, reuse) ? "multi" : reuse.seat;
|
|
252
|
+
}
|
|
253
|
+
/** Status and history, deliberately carrying NO severity (see `buildFinding`). */
|
|
254
|
+
function historyOf(reuse) {
|
|
255
|
+
if (reuse === undefined)
|
|
256
|
+
return FRESH;
|
|
257
|
+
const { status, statusChangedAtRound } = reuse;
|
|
258
|
+
return { status, statusChangedAtRound };
|
|
259
|
+
}
|
|
260
|
+
/** The fields that describe the finding itself, in both cases. */
|
|
261
|
+
function identityOf(candidate, reuse) {
|
|
262
|
+
return {
|
|
263
|
+
seat: seatFor(candidate, reuse),
|
|
264
|
+
title: candidate.title,
|
|
265
|
+
location: normalizeLocation(candidate.location),
|
|
266
|
+
keywords: unionKeywords(candidate, reuse),
|
|
267
|
+
fix: candidate.fix,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Build the entry for a candidate that reused `reuse`.
|
|
272
|
+
*
|
|
273
|
+
* `severity` is set from `highestSeverity` and NOT carried through `historyOf`:
|
|
274
|
+
* a stored severity riding along with the status once made a "minor -> critical"
|
|
275
|
+
* upgrade silently stay major.
|
|
276
|
+
*/
|
|
277
|
+
function restate(candidate, reuse) {
|
|
278
|
+
return {
|
|
279
|
+
id: reuse.id,
|
|
280
|
+
raisedBy: unionSeats(reuse, candidate.seat),
|
|
281
|
+
...identityOf(candidate, reuse),
|
|
282
|
+
...historyOf(reuse),
|
|
283
|
+
severity: highestSeverity(reuse.severity, candidate.severity),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** The report half of a brand-new entry. */
|
|
287
|
+
function freshReport(candidate) {
|
|
288
|
+
return {
|
|
289
|
+
seat: candidate.seat,
|
|
290
|
+
title: candidate.title,
|
|
291
|
+
location: normalizeLocation(candidate.location),
|
|
292
|
+
keywords: keywordsOf(candidate),
|
|
293
|
+
fix: candidate.fix,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
/** Build the entry for a brand-new candidate. */
|
|
297
|
+
function fresh(candidate, ledger) {
|
|
298
|
+
return {
|
|
299
|
+
id: nextId(candidate.seat, ledger),
|
|
300
|
+
...freshReport(candidate),
|
|
301
|
+
raisedBy: [candidate.seat],
|
|
302
|
+
severity: candidate.severity,
|
|
303
|
+
status: FRESH.status,
|
|
304
|
+
statusChangedAtRound: FRESH.statusChangedAtRound,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** The new entry, annotated with the settled entry it may belong to. */
|
|
308
|
+
function withCandidateOf(finding, uncertain) {
|
|
309
|
+
if (uncertain === undefined)
|
|
310
|
+
return finding;
|
|
311
|
+
return { ...finding, candidateOf: uncertain.id };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Give a candidate its identity, reusing an existing id when it is the same
|
|
315
|
+
* finding.
|
|
316
|
+
*
|
|
317
|
+
* The model's own `id` is never consulted: it is a hint for humans, and letting
|
|
318
|
+
* it be authoritative would let a drifting model reset a frozen id by renaming
|
|
319
|
+
* it.
|
|
320
|
+
*/
|
|
321
|
+
export function matchFinding(candidate, ledger) {
|
|
322
|
+
const matched = ledger.find((e) => isSameItem(candidate, e) || isRephrase(candidate, e));
|
|
323
|
+
if (matched)
|
|
324
|
+
return { finding: restate(candidate, matched), reused: true };
|
|
325
|
+
const settled = resemblesDisproved(candidate, ledger);
|
|
326
|
+
const finding = withCandidateOf(fresh(candidate, ledger), nearestUncertain(candidate, ledger));
|
|
327
|
+
if (settled === undefined)
|
|
328
|
+
return { finding, reused: false };
|
|
329
|
+
return { finding, reused: false, matchingDisproved: settled };
|
|
330
|
+
}
|
|
331
|
+
export { blockingFindings, releaseSeats } from "./delphi-seats.js";
|
|
332
|
+
//# sourceMappingURL=delphi-finding.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the findings a seat reported, out of its markdown `### Findings` table.
|
|
3
|
+
*
|
|
4
|
+
* The table already exists -- the prompt has always asked for
|
|
5
|
+
* `ID | Severity | Description | Location | Fix` -- but nothing ever parsed it,
|
|
6
|
+
* so every round re-derived its problems from prose and threw the table away.
|
|
7
|
+
* This turns that table into the ledger's input.
|
|
8
|
+
*
|
|
9
|
+
* Parsing is deliberately forgiving about FORMAT and unforgiving about
|
|
10
|
+
* MEANING: an unreadable row is dropped rather than guessed at, because a
|
|
11
|
+
* finding invented by a parser is worse than one the seat never raised.
|
|
12
|
+
*
|
|
13
|
+
* @test REQ-DSH-016
|
|
14
|
+
* @intent 把席位已经写在 Findings 表里的问题解析成结构化条目,
|
|
15
|
+
* 让后续轮次能说"这条已关闭"而不是"我仍然反对"。
|
|
16
|
+
* @covers AC-DSH-016-03
|
|
17
|
+
*/
|
|
18
|
+
import type { CandidateFinding } from "./delphi-finding.js";
|
|
19
|
+
/**
|
|
20
|
+
* The candidates a seat's report contains.
|
|
21
|
+
*
|
|
22
|
+
* Returns an empty array both for "the seat reported NONE" and for "there was no
|
|
23
|
+
* table at all" -- the caller must not read either as approval, and
|
|
24
|
+
* `parseVerdict` remains the only thing that decides a verdict.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseFindings(report: string, seat: string): CandidateFinding[];
|
|
27
|
+
/** The column order the prompt requires, for error messages and documentation. */
|
|
28
|
+
export declare const FINDINGS_COLUMNS: readonly ["id", "severity", "description", "location", "fix"];
|
|
29
|
+
//# sourceMappingURL=delphi-findings-parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphi-findings-parse.d.ts","sourceRoot":"","sources":["../src/delphi-findings-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAY,MAAM,qBAAqB,CAAA;AAwHrE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAS9E;AAED,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,+DAAU,CAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the findings a seat reported, out of its markdown `### Findings` table.
|
|
3
|
+
*
|
|
4
|
+
* The table already exists -- the prompt has always asked for
|
|
5
|
+
* `ID | Severity | Description | Location | Fix` -- but nothing ever parsed it,
|
|
6
|
+
* so every round re-derived its problems from prose and threw the table away.
|
|
7
|
+
* This turns that table into the ledger's input.
|
|
8
|
+
*
|
|
9
|
+
* Parsing is deliberately forgiving about FORMAT and unforgiving about
|
|
10
|
+
* MEANING: an unreadable row is dropped rather than guessed at, because a
|
|
11
|
+
* finding invented by a parser is worse than one the seat never raised.
|
|
12
|
+
*
|
|
13
|
+
* @test REQ-DSH-016
|
|
14
|
+
* @intent 把席位已经写在 Findings 表里的问题解析成结构化条目,
|
|
15
|
+
* 让后续轮次能说"这条已关闭"而不是"我仍然反对"。
|
|
16
|
+
* @covers AC-DSH-016-03
|
|
17
|
+
*/
|
|
18
|
+
/** Column order the prompt asks for; a header may also be read by name. */
|
|
19
|
+
const COLUMNS = ["id", "severity", "description", "location", "fix"];
|
|
20
|
+
/** Severities as the seats spell them, mapped onto ours. */
|
|
21
|
+
const SEVERITY_ALIASES = {
|
|
22
|
+
critical: "critical",
|
|
23
|
+
blocker: "critical",
|
|
24
|
+
major: "major",
|
|
25
|
+
high: "major",
|
|
26
|
+
minor: "minor",
|
|
27
|
+
low: "minor",
|
|
28
|
+
};
|
|
29
|
+
/** Split a markdown table row into trimmed cells, dropping the empty edges. */
|
|
30
|
+
function splitRow(line) {
|
|
31
|
+
return line
|
|
32
|
+
.trim()
|
|
33
|
+
.replace(/^\|/, "")
|
|
34
|
+
.replace(/\|$/, "")
|
|
35
|
+
.split("|")
|
|
36
|
+
.map((cell) => cell.trim());
|
|
37
|
+
}
|
|
38
|
+
/** A separator row looks like `|---|---|` and carries no data. */
|
|
39
|
+
function isSeparator(line) {
|
|
40
|
+
return /^\|?\s*:?-{2,}/.test(line.trim());
|
|
41
|
+
}
|
|
42
|
+
/** The `### Findings` section's lines, up to the next heading. */
|
|
43
|
+
function findingsSection(report) {
|
|
44
|
+
const lines = report.split(/\r?\n/);
|
|
45
|
+
const start = lines.findIndex((line) => /^#{1,3}\s*Findings\s*$/i.test(line));
|
|
46
|
+
if (start === -1)
|
|
47
|
+
return [];
|
|
48
|
+
const rest = lines.slice(start + 1);
|
|
49
|
+
const end = rest.findIndex((line) => /^#{1,3}\s/.test(line));
|
|
50
|
+
return end === -1 ? rest : rest.slice(0, end);
|
|
51
|
+
}
|
|
52
|
+
/** The table rows in a findings section, skipping headers and separators. */
|
|
53
|
+
function tableRows(section) {
|
|
54
|
+
const rows = section.filter((line) => line.trim().startsWith("|") && !isSeparator(line)).map(splitRow);
|
|
55
|
+
// A header row names the columns; anything else is data.
|
|
56
|
+
const hasHeader = rows.length > 0 && rows[0].some((cell) => /^id$/i.test(cell));
|
|
57
|
+
return hasHeader ? rows.slice(1) : rows;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a row says "the seat found nothing".
|
|
61
|
+
*
|
|
62
|
+
* The row must SAY so: at least one cell is the literal `NONE`. An all-empty row
|
|
63
|
+
* is not a NONE row -- it is a malformed data row, and treating it as "no
|
|
64
|
+
* findings" would swallow a real problem silently, which is the failure this
|
|
65
|
+
* whole module exists to prevent.
|
|
66
|
+
*/
|
|
67
|
+
function isNoneRow(cells) {
|
|
68
|
+
const named = cells.filter((cell) => /^none$/i.test(cell.trim()));
|
|
69
|
+
if (named.length === 0)
|
|
70
|
+
return false;
|
|
71
|
+
return cells.every((cell) => cell.trim() === "" || /^none$/i.test(cell.trim()));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Map a seat's severity word onto ours.
|
|
75
|
+
*
|
|
76
|
+
* Unknown words fail SAFE: a word this parser does not recognise is treated as
|
|
77
|
+
* MAJOR, not minor. Defaulting to minor let a report escape blocking by spelling
|
|
78
|
+
* "critical" in a way the table does not know, and the whole point of the ledger
|
|
79
|
+
* is that a reported problem cannot be quietly downgraded. Defaulting to critical
|
|
80
|
+
* would also be wrong -- one unrecognised word would block consensus outright.
|
|
81
|
+
*/
|
|
82
|
+
function severityOf(word) {
|
|
83
|
+
return SEVERITY_ALIASES[word.trim().toLowerCase()] ?? UNKNOWN_SEVERITY;
|
|
84
|
+
}
|
|
85
|
+
/** What an unrecognised severity word counts as; see `severityOf`. */
|
|
86
|
+
const UNKNOWN_SEVERITY = "major";
|
|
87
|
+
/** A cell that names no location cannot be matched across rounds. */
|
|
88
|
+
function usableLocation(location) {
|
|
89
|
+
return location !== "" && location !== "-" && location !== "—";
|
|
90
|
+
}
|
|
91
|
+
/** Turn one row into a candidate, or null when it cannot be one. */
|
|
92
|
+
/** A row without a location or a description cannot become a finding. */
|
|
93
|
+
function isUsableRow(row) {
|
|
94
|
+
return usableLocation(row.location) && row.description.trim() !== "";
|
|
95
|
+
}
|
|
96
|
+
function rowToCandidate(row, seat) {
|
|
97
|
+
if (!isUsableRow(row))
|
|
98
|
+
return null;
|
|
99
|
+
return {
|
|
100
|
+
seat,
|
|
101
|
+
severity: severityOf(row.severity),
|
|
102
|
+
title: row.description.trim(),
|
|
103
|
+
location: row.location.trim(),
|
|
104
|
+
fix: row.fix.trim(),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Read the five columns positionally, the order the prompt asks for. */
|
|
108
|
+
function toRawRow(cells) {
|
|
109
|
+
return {
|
|
110
|
+
id: cells[0] ?? "",
|
|
111
|
+
severity: cells[1] ?? "",
|
|
112
|
+
description: cells[2] ?? "",
|
|
113
|
+
location: cells[3] ?? "",
|
|
114
|
+
fix: cells[4] ?? "",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The candidates a seat's report contains.
|
|
119
|
+
*
|
|
120
|
+
* Returns an empty array both for "the seat reported NONE" and for "there was no
|
|
121
|
+
* table at all" -- the caller must not read either as approval, and
|
|
122
|
+
* `parseVerdict` remains the only thing that decides a verdict.
|
|
123
|
+
*/
|
|
124
|
+
export function parseFindings(report, seat) {
|
|
125
|
+
const rows = tableRows(findingsSection(report));
|
|
126
|
+
const candidates = [];
|
|
127
|
+
for (const cells of rows) {
|
|
128
|
+
if (isNoneRow(cells))
|
|
129
|
+
continue;
|
|
130
|
+
const candidate = rowToCandidate(toRawRow(cells), seat);
|
|
131
|
+
if (candidate !== null)
|
|
132
|
+
candidates.push(candidate);
|
|
133
|
+
}
|
|
134
|
+
return candidates;
|
|
135
|
+
}
|
|
136
|
+
/** The column order the prompt requires, for error messages and documentation. */
|
|
137
|
+
export const FINDINGS_COLUMNS = COLUMNS;
|
|
138
|
+
//# sourceMappingURL=delphi-findings-parse.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ledger a review keeps between rounds.
|
|
3
|
+
*
|
|
4
|
+
* One round's reports go in; a ledger plus a prompt section come out. Keeping
|
|
5
|
+
* this out of `runReview` matters for two reasons: `runReview` is already the
|
|
6
|
+
* most complex function in the module, and the ledger's rules (merge, freeze,
|
|
7
|
+
* escalate) must be testable WITHOUT making three model calls.
|
|
8
|
+
*
|
|
9
|
+
* @test REQ-DSH-016
|
|
10
|
+
* @intent 把每轮的席位报告累积成一份跨轮的条目台账,使"这条已关闭"
|
|
11
|
+
* 成为可判定的事实,而不是靠席位改变措辞。
|
|
12
|
+
* @covers AC-DSH-016-03
|
|
13
|
+
*/
|
|
14
|
+
import type { Finding } from "./delphi-finding.js";
|
|
15
|
+
import type { RoundResult } from "./delphi.js";
|
|
16
|
+
/** What one round did to the ledger. */
|
|
17
|
+
export interface LedgerUpdate {
|
|
18
|
+
/** The ledger after this round. */
|
|
19
|
+
readonly findings: readonly Finding[];
|
|
20
|
+
/** Findings that were open before this round and closed by it. */
|
|
21
|
+
readonly closed: readonly Finding[];
|
|
22
|
+
/** Findings that became newly open in this round. */
|
|
23
|
+
readonly opened: readonly Finding[];
|
|
24
|
+
}
|
|
25
|
+
/** The ledger, plus the round it was last updated in. */
|
|
26
|
+
export interface Ledger {
|
|
27
|
+
readonly findings: readonly Finding[];
|
|
28
|
+
readonly round: number;
|
|
29
|
+
}
|
|
30
|
+
/** An empty ledger: nothing has been reported yet. */
|
|
31
|
+
export declare function emptyLedger(): Ledger;
|
|
32
|
+
/**
|
|
33
|
+
* How many of `findings` a fresh approval from `role` would close.
|
|
34
|
+
*
|
|
35
|
+
* Exported so the shared-ownership rule can be asserted without scripting a full
|
|
36
|
+
* review -- a regression here is invisible until a review silently never ends.
|
|
37
|
+
*/
|
|
38
|
+
export declare function closeByAnyOwner(findings: readonly Finding[], role: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* Fold one round's reports into the ledger.
|
|
41
|
+
*
|
|
42
|
+
* Order matters: close what the seats are now satisfied with FIRST, then add
|
|
43
|
+
* this round's rows, so a finding that was just closed does not get reopened by
|
|
44
|
+
* the same report that closed it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function updateLedger(ledger: Ledger, round: RoundResult): LedgerUpdate;
|
|
47
|
+
/**
|
|
48
|
+
* The prompt section a later round receives.
|
|
49
|
+
*
|
|
50
|
+
* Closed rows are listed rather than silently dropped: a seat that reported a
|
|
51
|
+
* problem needs to see that the system recorded it as fixed, otherwise its
|
|
52
|
+
* absence reads as "forgotten" and it re-raises the same issue.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ledgerPrompt(ledger: Ledger): string;
|
|
55
|
+
//# sourceMappingURL=delphi-ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphi-ledger.d.ts","sourceRoot":"","sources":["../src/delphi-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,KAAK,EAAiB,WAAW,EAAE,MAAM,aAAa,CAAA;AAE7D,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;IACrC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;IACnC,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CACpC;AAED,yDAAyD;AACzD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,sDAAsD;AACtD,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AA6BD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAElF;AAQD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,YAAY,CAK7E;AAgCD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGnD"}
|