mandrel 2.4.0 → 2.5.0
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/.agents/audit-checklists/accessibility.md +29 -0
- package/.agents/audit-checklists/architecture.md +4 -5
- package/.agents/audit-checklists/clean-code.md +10 -0
- package/.agents/audit-checklists/data-model.md +22 -0
- package/.agents/audit-checklists/dependencies.md +11 -2
- package/.agents/audit-checklists/devops.md +4 -0
- package/.agents/audit-checklists/navigability.md +3 -0
- package/.agents/audit-checklists/performance.md +8 -11
- package/.agents/audit-checklists/privacy.md +3 -4
- package/.agents/audit-checklists/quality.md +2 -0
- package/.agents/audit-checklists/security.md +4 -5
- package/.agents/audit-checklists/seo.md +7 -1
- package/.agents/audit-checklists/sre.md +14 -12
- package/.agents/audit-checklists/ux-ui.md +4 -0
- package/.agents/docs/configuration.md +3 -0
- package/.agents/docs/workflows.md +4 -3
- package/.agents/schemas/agentrc.schema.json +17 -0
- package/.agents/schemas/audit-rules.json +134 -19
- package/.agents/schemas/audit-rules.schema.json +6 -2
- package/.agents/scripts/audit-labels-bootstrap.js +4 -4
- package/.agents/scripts/audit-to-stories.js +244 -19
- package/.agents/scripts/lib/audit-suite/checklist-threading.js +26 -3
- package/.agents/scripts/lib/audit-suite/dispatch-checklist.js +132 -0
- package/.agents/scripts/lib/audit-suite/index.js +1 -0
- package/.agents/scripts/lib/audit-suite/selector.js +290 -14
- package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +2 -1
- package/.agents/scripts/lib/audit-to-stories/build-story-body.js +5 -1
- package/.agents/scripts/lib/audit-to-stories/dedupe-against-github.js +23 -3
- package/.agents/scripts/lib/audit-to-stories/finding-adapter.js +38 -0
- package/.agents/scripts/lib/audit-to-stories/ledger.js +256 -0
- package/.agents/scripts/lib/audit-to-stories/parse-audit-md.js +41 -7
- package/.agents/scripts/lib/audit-to-stories/seed-from-findings.js +20 -2
- package/.agents/scripts/lib/command-header.js +1 -1
- package/.agents/scripts/lib/config-settings-schema-delivery.js +21 -0
- package/.agents/scripts/lib/dynamic-workflow/performance-report-contract.js +5 -3
- package/.agents/scripts/lib/feedback-loop/audit-results-graduator.js +56 -0
- package/.agents/scripts/lib/findings/route-finding.js +108 -10
- package/.agents/scripts/lib/orchestration/story-close/phases/local-lens-review.js +81 -1
- package/.agents/scripts/lib/orchestration/story-close/phases/review-core.js +1 -0
- package/.agents/scripts/nav-registry-diff.js +449 -0
- package/.agents/workflows/audit-accessibility.md +243 -0
- package/.agents/workflows/audit-architecture.md +89 -71
- package/.agents/workflows/audit-clean-code.md +87 -53
- package/.agents/workflows/audit-data-model.md +198 -0
- package/.agents/workflows/audit-dependencies.md +143 -28
- package/.agents/workflows/audit-devops.md +109 -18
- package/.agents/workflows/audit-documentation.md +25 -53
- package/.agents/workflows/audit-navigability.md +78 -22
- package/.agents/workflows/audit-performance.md +207 -103
- package/.agents/workflows/audit-privacy.md +51 -13
- package/.agents/workflows/audit-quality.md +71 -61
- package/.agents/workflows/audit-security.md +94 -71
- package/.agents/workflows/audit-seo.md +80 -25
- package/.agents/workflows/audit-sre.md +99 -66
- package/.agents/workflows/audit-to-stories.md +44 -5
- package/.agents/workflows/audit-ux-ui.md +71 -17
- package/.agents/workflows/helpers/audit-dual-path.md +59 -0
- package/.agents/workflows/helpers/audit-self-check.md +70 -0
- package/.agents/workflows/helpers/audit-severity-scale.md +19 -0
- package/.agents/workflows/helpers/deliver-story.md +25 -0
- package/docs/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/.agents/audit-checklists/lighthouse.md +0 -15
- package/.agents/schemas/audit-results.schema.json +0 -69
- package/.agents/workflows/audit-lighthouse.md +0 -269
|
@@ -32,7 +32,12 @@ import crypto from 'node:crypto';
|
|
|
32
32
|
|
|
33
33
|
const SEP = '␟'; // unit separator — keeps fingerprint fields unambiguous
|
|
34
34
|
const MARKER = 'audit-fingerprints:';
|
|
35
|
+
const SEMANTIC_MARKER = 'audit-semantic-keys:';
|
|
35
36
|
const SHA1_RE = /^[0-9a-f]{40}$/;
|
|
37
|
+
// A semantic key round-trips through a comma-joined footer, so it must not
|
|
38
|
+
// carry a comma or a `>` (which would truncate the HTML comment). Both are
|
|
39
|
+
// stripped when the key is built, so this guard is defence-in-depth.
|
|
40
|
+
const SEMANTIC_KEY_RE = /^[^,>]+$/;
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
43
|
* Normalise a single scalar identity field to a stable string.
|
|
@@ -92,6 +97,67 @@ export function fingerprintFinding(finding) {
|
|
|
92
97
|
return { short: full.slice(0, 12), full, components };
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Compute the **location-based semantic key** for a finding. Unlike the
|
|
102
|
+
* fingerprint (which folds in the title, so any prose rewording mints a fresh
|
|
103
|
+
* sha), the semantic key is stable across a reworded title and a re-severitied
|
|
104
|
+
* finding: it is derived solely from the finding's identity *location* —
|
|
105
|
+
* `area` (the audit dimension) plus `primaryFile`. Two scans that describe the
|
|
106
|
+
* same problem at the same location produce the same semantic key even when
|
|
107
|
+
* their titles diverge, so a reworded finding still confirms against the Issue
|
|
108
|
+
* that already tracks that location.
|
|
109
|
+
*
|
|
110
|
+
* Returns the empty string when the location is unknown (no `area` and no
|
|
111
|
+
* `primaryFile`) — an empty key never confirms a match, exactly as an absent
|
|
112
|
+
* fingerprint footer never does.
|
|
113
|
+
*
|
|
114
|
+
* @param {object} finding — canonical finding ({ area, primaryFile, ... }).
|
|
115
|
+
* @returns {string}
|
|
116
|
+
*/
|
|
117
|
+
export function semanticKeyFor(finding) {
|
|
118
|
+
const area = normaliseField(finding?.area);
|
|
119
|
+
const primaryFile = normaliseField(finding?.primaryFile);
|
|
120
|
+
if (!area && !primaryFile) return '';
|
|
121
|
+
const key = `${area}${SEP}${primaryFile}`;
|
|
122
|
+
return SEMANTIC_KEY_RE.test(key) ? key : key.replace(/[,>]/g, ' ').trim();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Render the machine-readable semantic-key footer for one or more keys
|
|
127
|
+
* (`<!-- audit-semantic-keys: key,key,... -->`). Stamped alongside the
|
|
128
|
+
* fingerprint footer by the audit filers so a later reworded finding can
|
|
129
|
+
* confirm identity by location when its fingerprint has drifted. Round-trips
|
|
130
|
+
* through {@link parseSemanticKeyFooter}. Empty keys are dropped.
|
|
131
|
+
*
|
|
132
|
+
* @param {string | string[]} keys — one semantic key or an array of them.
|
|
133
|
+
* @returns {string}
|
|
134
|
+
*/
|
|
135
|
+
export function semanticKeyFooter(keys) {
|
|
136
|
+
const list = (Array.isArray(keys) ? keys : [keys])
|
|
137
|
+
.filter((k) => typeof k === 'string' && k.length > 0)
|
|
138
|
+
.map((k) => k.replace(/[,>]/g, ' ').trim())
|
|
139
|
+
.filter((k) => k.length > 0);
|
|
140
|
+
return `<!-- ${SEMANTIC_MARKER} ${list.join(',')} -->`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Extract semantic keys from an Issue body carrying the semantic-key footer.
|
|
145
|
+
* Internal — the audit filers stamp the footer via {@link semanticKeyFooter};
|
|
146
|
+
* only the confirmation path here reads it back.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} body
|
|
149
|
+
* @returns {string[]}
|
|
150
|
+
*/
|
|
151
|
+
function parseSemanticKeyFooter(body) {
|
|
152
|
+
if (typeof body !== 'string') return [];
|
|
153
|
+
const match = body.match(/<!--\s*audit-semantic-keys:\s*([^>]*?)\s*-->/);
|
|
154
|
+
if (!match) return [];
|
|
155
|
+
return match[1]
|
|
156
|
+
.split(',')
|
|
157
|
+
.map((s) => s.trim())
|
|
158
|
+
.filter((s) => s.length > 0);
|
|
159
|
+
}
|
|
160
|
+
|
|
95
161
|
/**
|
|
96
162
|
* Render the machine-readable fingerprint footer for one or more shas.
|
|
97
163
|
*
|
|
@@ -147,6 +213,21 @@ function issueCarriesFingerprint(issue, sha) {
|
|
|
147
213
|
return parseFingerprintFooter(issue.body).includes(sha);
|
|
148
214
|
}
|
|
149
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Confirm an issue body's footer carries the target semantic key. Unlike
|
|
218
|
+
* {@link issueCarriesFingerprint}, this is strict on a missing body — a
|
|
219
|
+
* location match is only meaningful when the issue actually carries a
|
|
220
|
+
* semantic-key footer to compare against.
|
|
221
|
+
*
|
|
222
|
+
* @param {{ body?: string }} issue
|
|
223
|
+
* @param {string} key
|
|
224
|
+
* @returns {boolean}
|
|
225
|
+
*/
|
|
226
|
+
function issueCarriesSemanticKey(issue, key) {
|
|
227
|
+
if (!key || typeof issue?.body !== 'string') return false;
|
|
228
|
+
return parseSemanticKeyFooter(issue.body).includes(key);
|
|
229
|
+
}
|
|
230
|
+
|
|
150
231
|
/**
|
|
151
232
|
* Decide the route decision from a confirmed matched issue's state.
|
|
152
233
|
* @param {{ state?: string }} issue
|
|
@@ -194,23 +275,29 @@ function decideFromConfirmed(confirmed, sha) {
|
|
|
194
275
|
}
|
|
195
276
|
|
|
196
277
|
/**
|
|
197
|
-
* Keep only the issue records that have the right wire shape AND carry
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
278
|
+
* Keep only the issue records that have the right wire shape AND carry a
|
|
279
|
+
* confirming footer. Confirmation is by the exact **fingerprint** footer and,
|
|
280
|
+
* when a `semanticKey` is supplied (audit dedup opts in via
|
|
281
|
+
* `options.semanticKeyConfirm`), ALSO by the location-based **semantic-key**
|
|
282
|
+
* footer. A semantic candidate that merely *looks* similar but carries neither
|
|
283
|
+
* footer is dropped here — semantic similarity widens the net; a deterministic
|
|
284
|
+
* footer (fingerprint or semantic key) is what confirms identity. The semantic
|
|
285
|
+
* key catches a reworded finding whose fingerprint has drifted but whose
|
|
286
|
+
* location is unchanged.
|
|
201
287
|
*
|
|
202
288
|
* @param {Array<unknown>} hits
|
|
203
|
-
* @param {string}
|
|
289
|
+
* @param {{ sha: string, semanticKey?: string }} identity
|
|
204
290
|
* @returns {Array<{ number: number, state: string }>}
|
|
205
291
|
*/
|
|
206
|
-
function
|
|
292
|
+
function confirmCandidates(hits, { sha, semanticKey = '' }) {
|
|
207
293
|
if (!Array.isArray(hits)) return [];
|
|
208
294
|
return hits.filter(
|
|
209
295
|
(h) =>
|
|
210
296
|
h &&
|
|
211
297
|
typeof h.number === 'number' &&
|
|
212
298
|
typeof h.state === 'string' &&
|
|
213
|
-
issueCarriesFingerprint(h, sha)
|
|
299
|
+
(issueCarriesFingerprint(h, sha) ||
|
|
300
|
+
issueCarriesSemanticKey(h, semanticKey)),
|
|
214
301
|
);
|
|
215
302
|
}
|
|
216
303
|
|
|
@@ -245,11 +332,18 @@ function confirmFingerprint(hits, sha) {
|
|
|
245
332
|
* Meaning-first candidate search over open+closed issues (and Epic
|
|
246
333
|
* sub-issues). When supplied, runs FIRST; its candidates are then
|
|
247
334
|
* fingerprint-confirmed.
|
|
335
|
+
* @param {object} [options]
|
|
336
|
+
* @param {boolean} [options.semanticKeyConfirm=false] — also confirm a
|
|
337
|
+
* candidate by the location-based semantic-key footer, not the fingerprint
|
|
338
|
+
* alone. Opt-in so the audit dedup path catches a reworded finding at an
|
|
339
|
+
* unchanged location while the qa-explore path (which does not stamp
|
|
340
|
+
* semantic-key footers) stays fingerprint-exact and byte-identical.
|
|
248
341
|
* @returns {Promise<{ decision: 'new'|'update-existing'|'duplicate'|'regression-of-closed', matchedIssue: object|null, fingerprint: string }>}
|
|
249
342
|
*/
|
|
250
343
|
export async function routeFinding(
|
|
251
344
|
finding,
|
|
252
345
|
{ searchIssues, searchCandidates } = {},
|
|
346
|
+
options = {},
|
|
253
347
|
) {
|
|
254
348
|
if (
|
|
255
349
|
typeof searchCandidates !== 'function' &&
|
|
@@ -261,6 +355,7 @@ export async function routeFinding(
|
|
|
261
355
|
}
|
|
262
356
|
|
|
263
357
|
const { full: sha } = fingerprintFinding(finding);
|
|
358
|
+
const semanticKey = options.semanticKeyConfirm ? semanticKeyFor(finding) : '';
|
|
264
359
|
|
|
265
360
|
// Stage 1: semantic candidate pass first (when wired); else fingerprint
|
|
266
361
|
// lookup. Both yield a candidate pool drawn from open AND closed issues.
|
|
@@ -269,15 +364,18 @@ export async function routeFinding(
|
|
|
269
364
|
? await searchCandidates(finding)
|
|
270
365
|
: await searchIssues(sha);
|
|
271
366
|
|
|
272
|
-
// Stage 2: confirm identity by fingerprint footer
|
|
273
|
-
|
|
367
|
+
// Stage 2: confirm identity by fingerprint footer (and, when opted in, the
|
|
368
|
+
// location-based semantic-key footer) over the candidate pool.
|
|
369
|
+
const confirmed = confirmCandidates(hits, { sha, semanticKey });
|
|
274
370
|
|
|
275
371
|
return decideFromConfirmed(confirmed, sha);
|
|
276
372
|
}
|
|
277
373
|
|
|
278
374
|
export const __testing = {
|
|
279
375
|
MARKER,
|
|
376
|
+
SEMANTIC_MARKER,
|
|
280
377
|
SEP,
|
|
281
|
-
|
|
378
|
+
confirmCandidates,
|
|
282
379
|
decideFromConfirmed,
|
|
380
|
+
issueCarriesSemanticKey,
|
|
283
381
|
};
|
|
@@ -30,6 +30,58 @@ import { computeChangeSet } from '../../change-set.js';
|
|
|
30
30
|
*/
|
|
31
31
|
const STORY_SCOPE_LENS_DEPTH = 'light';
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Render the host-MUST-walk roster of materialized lens-prompt artifacts
|
|
35
|
+
* (Story #4627). The Story-scope lens pass materializes each matched lens's
|
|
36
|
+
* substituted prompt body to a scoped artifact file; the default review
|
|
37
|
+
* provider is a mechanical sweep that never reads them, so the artifacts are
|
|
38
|
+
* inert unless the close's stdout tells the host to walk them. This mirrors
|
|
39
|
+
* the plan-run audit-roster comment's "host MUST walk each" contract
|
|
40
|
+
* (`run-epilogue.js`): the close names each artifact path and the host reads
|
|
41
|
+
* each one against the diff.
|
|
42
|
+
*
|
|
43
|
+
* Pure: derives the block from the `runAuditSuite` envelope's `workflows[]`,
|
|
44
|
+
* keeping only entries that actually wrote an artifact. Returns `null` when no
|
|
45
|
+
* artifact was written (nothing to walk), so the caller emits nothing.
|
|
46
|
+
*
|
|
47
|
+
* Module-local: an implementation detail of {@link runLocalLensReview}, whose
|
|
48
|
+
* host-MUST-walk output rides out on the `progress` stream. Exercised through
|
|
49
|
+
* that public entry point (assert the progress lines name each artifact path)
|
|
50
|
+
* rather than imported directly, so it adds no production-dead public export.
|
|
51
|
+
*
|
|
52
|
+
* @param {object|null} materialized the `runAuditSuite` result envelope.
|
|
53
|
+
* @returns {string|null} the roster block, or `null` when there is nothing to walk.
|
|
54
|
+
*/
|
|
55
|
+
function renderLensArtifactRoster(materialized) {
|
|
56
|
+
const paths = (materialized?.workflows ?? [])
|
|
57
|
+
.map((w) => w?.artifactPath)
|
|
58
|
+
.filter((p) => typeof p === 'string' && p.length > 0);
|
|
59
|
+
if (paths.length === 0) return null;
|
|
60
|
+
return [
|
|
61
|
+
`Lens prompts materialized (host MUST read/walk each against the Story diff):`,
|
|
62
|
+
...paths.map((p) => ` - ${p}`),
|
|
63
|
+
].join('\n');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Build the `runAuditSuite` substitutions for the Story-scope lens pass
|
|
68
|
+
* (Story #4627). Resolves the `{{changedFiles}}` token from the actual Story
|
|
69
|
+
* diff (newline-joined, the shape the lens templates' `## Scope` block reads)
|
|
70
|
+
* and the `{{ticketId}}` token from the Story id when known. Both are built-in
|
|
71
|
+
* substitution keys (`substitutions.js#BUILT_IN_SUBSTITUTION_KEYS`), so the
|
|
72
|
+
* runner accepts them without a per-lens `substitutionKeys` declaration.
|
|
73
|
+
*
|
|
74
|
+
* @param {{ changedFiles: string[], storyId?: number|string|null }} args
|
|
75
|
+
* @returns {Record<string, string>}
|
|
76
|
+
*/
|
|
77
|
+
function buildLensSubstitutions({ changedFiles, storyId }) {
|
|
78
|
+
const substitutions = { changedFiles: changedFiles.join('\n') };
|
|
79
|
+
if (storyId != null && `${storyId}`.length > 0) {
|
|
80
|
+
substitutions.ticketId = String(storyId);
|
|
81
|
+
}
|
|
82
|
+
return substitutions;
|
|
83
|
+
}
|
|
84
|
+
|
|
33
85
|
/**
|
|
34
86
|
* Enumerate the files changed in the `baseRef...headRef` diff. Thin adapter over
|
|
35
87
|
* the shared {@link computeChangeSet} enumerator (Story #4593) that flattens its
|
|
@@ -120,10 +172,20 @@ function resolveLensChangeSet({
|
|
|
120
172
|
* for standalone callers that supply no list; see {@link resolveLensChangeSet}
|
|
121
173
|
* for the three-state contract.
|
|
122
174
|
*
|
|
175
|
+
* Story #4627 — the pass now delivers lens **content** to a reader. It threads
|
|
176
|
+
* `{{changedFiles}}` / `{{ticketId}}` substitutions and an `artifactPrefix`
|
|
177
|
+
* into `runAuditSuite` so each matched lens's substituted prompt body is
|
|
178
|
+
* written to a scoped artifact under the run's audit output dir, then emits a
|
|
179
|
+
* host-MUST-walk roster of those artifact paths to the close's stdout. Before
|
|
180
|
+
* this the default review provider dropped the materialized envelope, so the
|
|
181
|
+
* pass was a progress log line with no reader.
|
|
182
|
+
*
|
|
123
183
|
* @param {{
|
|
124
184
|
* baseRef: string,
|
|
125
185
|
* headRef: string,
|
|
126
186
|
* changedFiles?: string[]|null,
|
|
187
|
+
* storyId?: number|string|null,
|
|
188
|
+
* artifactPrefix?: string,
|
|
127
189
|
* progress: (tag: string, msg: string) => void,
|
|
128
190
|
* progressTag?: string,
|
|
129
191
|
* gitSpawnFn?: import('../../change-set.js').GitSpawnFn,
|
|
@@ -135,12 +197,15 @@ function resolveLensChangeSet({
|
|
|
135
197
|
* lenses: string[],
|
|
136
198
|
* skipped: boolean,
|
|
137
199
|
* materialized: object|null,
|
|
200
|
+
* artifactPaths: string[],
|
|
138
201
|
* }>}
|
|
139
202
|
*/
|
|
140
203
|
export async function runLocalLensReview({
|
|
141
204
|
baseRef,
|
|
142
205
|
headRef,
|
|
143
206
|
changedFiles: injectedChangedFiles,
|
|
207
|
+
storyId,
|
|
208
|
+
artifactPrefix,
|
|
144
209
|
progress,
|
|
145
210
|
progressTag = 'CODE-REVIEW',
|
|
146
211
|
gitSpawnFn = gitSpawn,
|
|
@@ -152,6 +217,7 @@ export async function runLocalLensReview({
|
|
|
152
217
|
lenses: [],
|
|
153
218
|
skipped: true,
|
|
154
219
|
materialized: null,
|
|
220
|
+
artifactPaths: [],
|
|
155
221
|
};
|
|
156
222
|
try {
|
|
157
223
|
const changedFiles = resolveLensChangeSet({
|
|
@@ -168,16 +234,30 @@ export async function runLocalLensReview({
|
|
|
168
234
|
);
|
|
169
235
|
return empty;
|
|
170
236
|
}
|
|
171
|
-
|
|
237
|
+
// Scope the artifact filenames to this Story so concurrent closes on a
|
|
238
|
+
// shared audit output dir cannot clobber each other's prompts.
|
|
239
|
+
const effectivePrefix =
|
|
240
|
+
artifactPrefix ?? (storyId != null ? `story-${storyId}` : 'story-scope');
|
|
241
|
+
const materialized = await runAuditSuiteFn({
|
|
242
|
+
auditWorkflows: lenses,
|
|
243
|
+
substitutions: buildLensSubstitutions({ changedFiles, storyId }),
|
|
244
|
+
artifactPrefix: effectivePrefix,
|
|
245
|
+
});
|
|
172
246
|
progress(
|
|
173
247
|
progressTag,
|
|
174
248
|
`Ran ${lenses.length} local lens(es) at ${STORY_SCOPE_LENS_DEPTH} depth: ${lenses.join(', ')}.`,
|
|
175
249
|
);
|
|
250
|
+
const roster = renderLensArtifactRoster(materialized);
|
|
251
|
+
if (roster) progress(progressTag, roster);
|
|
252
|
+
const artifactPaths = (materialized?.workflows ?? [])
|
|
253
|
+
.map((w) => w?.artifactPath)
|
|
254
|
+
.filter((p) => typeof p === 'string' && p.length > 0);
|
|
176
255
|
return {
|
|
177
256
|
depth: STORY_SCOPE_LENS_DEPTH,
|
|
178
257
|
lenses,
|
|
179
258
|
skipped: false,
|
|
180
259
|
materialized,
|
|
260
|
+
artifactPaths,
|
|
181
261
|
};
|
|
182
262
|
} catch (err) {
|
|
183
263
|
// The lens pass is advisory: a git or materialization failure must not
|