@ryuenn3123/agentic-senior-core 2.5.14 → 2.5.16
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/.agent-context/prompts/review-code.md +2 -0
- package/.agent-context/review-checklists/frontend-excellence-rubric.md +12 -2
- package/.agent-context/review-checklists/frontend-usability.md +1 -0
- package/.agent-context/review-checklists/pr-checklist.md +10 -0
- package/.agent-context/rules/architecture.md +17 -0
- package/.agent-context/rules/frontend-architecture.md +7 -0
- package/.agent-context/state/memory-continuity-benchmark.json +1 -1
- package/.agent-context/state/onboarding-report.json +11 -2
- package/.cursorrules +2 -2
- package/.windsurfrules +2 -2
- package/lib/cli/compiler.mjs +20 -1
- package/package.json +3 -1
- package/scripts/explain-on-demand-audit.mjs +426 -0
- package/scripts/frontend-usability-audit.mjs +5 -0
- package/scripts/release-gate.mjs +164 -0
- package/scripts/single-source-lazy-loading-audit.mjs +535 -0
- package/scripts/validate.mjs +2 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* single-source-lazy-loading-audit.mjs
|
|
5
|
+
*
|
|
6
|
+
* Enforces V3.0-010 policy:
|
|
7
|
+
* - One canonical rule source is explicitly defined and enforced.
|
|
8
|
+
* - Language-specific rule guidance loads lazily by detected scope.
|
|
9
|
+
* - Conflicting duplicate instruction paths are prevented.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
13
|
+
import { execFileSync } from 'node:child_process';
|
|
14
|
+
import { createHash } from 'node:crypto';
|
|
15
|
+
import { dirname, resolve } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = dirname(__filename);
|
|
20
|
+
const REPOSITORY_ROOT = resolve(__dirname, '..');
|
|
21
|
+
|
|
22
|
+
const CANONICAL_SOURCE_PATH = '.instructions.md';
|
|
23
|
+
const ADAPTER_PATHS = [
|
|
24
|
+
'AGENTS.md',
|
|
25
|
+
'.github/copilot-instructions.md',
|
|
26
|
+
'.gemini/instructions.md',
|
|
27
|
+
];
|
|
28
|
+
const COMPILER_PATH = 'lib/cli/compiler.mjs';
|
|
29
|
+
const ONBOARDING_REPORT_PATH = '.agent-context/state/onboarding-report.json';
|
|
30
|
+
const ARCHITECTURE_RULE_PATH = '.agent-context/rules/architecture.md';
|
|
31
|
+
const PR_CHECKLIST_PATH = '.agent-context/review-checklists/pr-checklist.md';
|
|
32
|
+
const REVIEW_PROMPT_PATH = '.agent-context/prompts/review-code.md';
|
|
33
|
+
const COMPILED_RULE_PATHS = ['.cursorrules', '.windsurfrules'];
|
|
34
|
+
|
|
35
|
+
const DEFAULT_WORKFLOW = 'standard';
|
|
36
|
+
const SUPPORTED_WORKFLOWS = new Set([
|
|
37
|
+
DEFAULT_WORKFLOW,
|
|
38
|
+
'pr-preparation',
|
|
39
|
+
'review-request',
|
|
40
|
+
'session-handoff',
|
|
41
|
+
'init',
|
|
42
|
+
'upgrade',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const STACK_CATALOG_FILE_NAMES = [
|
|
46
|
+
'typescript.md',
|
|
47
|
+
'python.md',
|
|
48
|
+
'java.md',
|
|
49
|
+
'php.md',
|
|
50
|
+
'go.md',
|
|
51
|
+
'csharp.md',
|
|
52
|
+
'rust.md',
|
|
53
|
+
'ruby.md',
|
|
54
|
+
'flutter.md',
|
|
55
|
+
'react-native.md',
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const MAX_EAGER_STACK_MENTIONS = 4;
|
|
59
|
+
|
|
60
|
+
const REQUIRED_ARCHITECTURE_RULE_SNIPPETS = [
|
|
61
|
+
'## Single Source of Truth and Lazy Rule Loading',
|
|
62
|
+
'Canonical rule source is .instructions.md.',
|
|
63
|
+
'Load language-specific stack guidance lazily based on detected scope.',
|
|
64
|
+
'Do not preload unrelated stack profiles during normal flow.',
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const REQUIRED_PR_CHECKLIST_SNIPPETS = [
|
|
68
|
+
'Canonical rule source is explicitly defined and enforced',
|
|
69
|
+
'Language-specific guidance is loaded lazily based on detected scope',
|
|
70
|
+
'No conflicting duplicate rule instructions during normal flow',
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const REQUIRED_REVIEW_PROMPT_SNIPPETS = [
|
|
74
|
+
'Enforce single-source and lazy-loading policy: canonical rule source must be explicitly enforced, language-specific guidance must load lazily based on detected scope, and conflicting duplicate rule instructions must not appear during normal flow.',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const REQUIRED_COMPILER_SNIPPETS = [
|
|
78
|
+
'## LAYER 2 POLICY: LAZY RULE LOADING',
|
|
79
|
+
'Load stack guidance only when task scope touches that stack.',
|
|
80
|
+
'Avoid eager loading unrelated stack profiles to prevent instruction conflicts.',
|
|
81
|
+
"stackLoadingMode: 'lazy'",
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
function pushResult(results, isPassed, checkName, details) {
|
|
85
|
+
results.push({
|
|
86
|
+
checkName,
|
|
87
|
+
passed: isPassed,
|
|
88
|
+
details,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function normalizeLineEndings(content) {
|
|
93
|
+
return String(content || '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function readText(relativeFilePath) {
|
|
97
|
+
const absolutePath = resolve(REPOSITORY_ROOT, relativeFilePath);
|
|
98
|
+
if (!existsSync(absolutePath)) {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return readFileSync(absolutePath, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function normalizeFilePath(filePath) {
|
|
106
|
+
return filePath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseGitFileList(rawOutput) {
|
|
110
|
+
if (typeof rawOutput !== 'string' || rawOutput.trim().length === 0) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return rawOutput
|
|
115
|
+
.split(/\r?\n/)
|
|
116
|
+
.map((filePath) => filePath.trim())
|
|
117
|
+
.filter((filePath) => filePath.length > 0)
|
|
118
|
+
.map(normalizeFilePath);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function runGitFileQuery(commandArguments) {
|
|
122
|
+
try {
|
|
123
|
+
const rawOutput = execFileSync('git', commandArguments, {
|
|
124
|
+
cwd: REPOSITORY_ROOT,
|
|
125
|
+
encoding: 'utf8',
|
|
126
|
+
maxBuffer: 1024 * 1024,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return parseGitFileList(rawOutput);
|
|
130
|
+
} catch {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function uniqueSorted(filePaths) {
|
|
136
|
+
return Array.from(new Set(filePaths)).sort((leftPath, rightPath) => leftPath.localeCompare(rightPath));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function collectChangedFiles() {
|
|
140
|
+
const workingTreeFiles = runGitFileQuery(['diff', '--name-only']);
|
|
141
|
+
const stagedFiles = runGitFileQuery(['diff', '--name-only', '--cached']);
|
|
142
|
+
const workingScopeFiles = uniqueSorted([...workingTreeFiles, ...stagedFiles]);
|
|
143
|
+
|
|
144
|
+
if (workingScopeFiles.length > 0) {
|
|
145
|
+
return {
|
|
146
|
+
source: 'working-tree-and-index',
|
|
147
|
+
files: workingScopeFiles,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const latestCommitRangeFiles = runGitFileQuery(['diff', '--name-only', 'HEAD~1..HEAD']);
|
|
152
|
+
if (latestCommitRangeFiles.length > 0) {
|
|
153
|
+
return {
|
|
154
|
+
source: 'latest-commit-range',
|
|
155
|
+
files: uniqueSorted(latestCommitRangeFiles),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const headCommitFiles = runGitFileQuery(['show', '--pretty=format:', '--name-only', 'HEAD']);
|
|
160
|
+
if (headCommitFiles.length > 0) {
|
|
161
|
+
return {
|
|
162
|
+
source: 'head-commit',
|
|
163
|
+
files: uniqueSorted(headCommitFiles),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
source: 'none',
|
|
169
|
+
files: [],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function parseCliArguments(argumentList) {
|
|
174
|
+
let workflow = DEFAULT_WORKFLOW;
|
|
175
|
+
|
|
176
|
+
for (let argumentIndex = 0; argumentIndex < argumentList.length; argumentIndex += 1) {
|
|
177
|
+
const argumentValue = argumentList[argumentIndex];
|
|
178
|
+
|
|
179
|
+
if (argumentValue === '--workflow') {
|
|
180
|
+
const nextArgumentValue = argumentList[argumentIndex + 1];
|
|
181
|
+
if (nextArgumentValue && !nextArgumentValue.startsWith('--')) {
|
|
182
|
+
workflow = nextArgumentValue;
|
|
183
|
+
argumentIndex += 1;
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (argumentValue.startsWith('--workflow=')) {
|
|
189
|
+
workflow = argumentValue.slice('--workflow='.length);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const normalizedWorkflow = String(workflow).trim().toLowerCase() || DEFAULT_WORKFLOW;
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
workflow: SUPPORTED_WORKFLOWS.has(normalizedWorkflow) ? normalizedWorkflow : DEFAULT_WORKFLOW,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function assertSnippetCoverage(sourceLabel, sourcePath, requiredSnippets, failures, results) {
|
|
201
|
+
const sourceContent = readText(sourcePath);
|
|
202
|
+
|
|
203
|
+
if (!sourceContent) {
|
|
204
|
+
failures.push(`Missing ${sourceLabel} source: ${sourcePath}`);
|
|
205
|
+
pushResult(results, false, `${sourceLabel}-source-exists`, `Missing ${sourcePath}`);
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
pushResult(results, true, `${sourceLabel}-source-exists`, `${sourcePath} is present`);
|
|
210
|
+
|
|
211
|
+
const missingSnippets = requiredSnippets.filter((requiredSnippet) => !sourceContent.includes(requiredSnippet));
|
|
212
|
+
|
|
213
|
+
if (missingSnippets.length > 0) {
|
|
214
|
+
failures.push(`Missing ${sourceLabel} snippets: ${missingSnippets.join(', ')}`);
|
|
215
|
+
pushResult(
|
|
216
|
+
results,
|
|
217
|
+
false,
|
|
218
|
+
`${sourceLabel}-source-coverage`,
|
|
219
|
+
`Missing snippets in ${sourcePath}: ${missingSnippets.join(', ')}`
|
|
220
|
+
);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
pushResult(results, true, `${sourceLabel}-source-coverage`, `${sourceLabel} snippets are complete`);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function parseJsonSafely(rawText) {
|
|
229
|
+
if (typeof rawText !== 'string' || rawText.trim().length === 0) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
return JSON.parse(rawText);
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function countStackMentions(textContent) {
|
|
241
|
+
return STACK_CATALOG_FILE_NAMES.reduce((mentionCount, stackFileName) => (
|
|
242
|
+
mentionCount + (textContent.includes(stackFileName) ? 1 : 0)
|
|
243
|
+
), 0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function runAudit() {
|
|
247
|
+
const parsedArguments = parseCliArguments(process.argv.slice(2));
|
|
248
|
+
const changedScope = collectChangedFiles();
|
|
249
|
+
const changedFiles = changedScope.files;
|
|
250
|
+
const results = [];
|
|
251
|
+
const failures = [];
|
|
252
|
+
const warnings = [];
|
|
253
|
+
|
|
254
|
+
pushResult(results, true, 'context-workflow', `workflow=${parsedArguments.workflow}`);
|
|
255
|
+
|
|
256
|
+
const canonicalSourceContent = readText(CANONICAL_SOURCE_PATH);
|
|
257
|
+
const canonicalSourceExists = canonicalSourceContent.length > 0;
|
|
258
|
+
|
|
259
|
+
if (!canonicalSourceExists) {
|
|
260
|
+
failures.push(`Missing canonical source: ${CANONICAL_SOURCE_PATH}`);
|
|
261
|
+
pushResult(results, false, 'canonical-source-exists', `Missing ${CANONICAL_SOURCE_PATH}`);
|
|
262
|
+
} else {
|
|
263
|
+
pushResult(results, true, 'canonical-source-exists', `${CANONICAL_SOURCE_PATH} is present`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const canonicalHash = canonicalSourceExists
|
|
267
|
+
? createHash('sha256').update(normalizeLineEndings(canonicalSourceContent)).digest('hex')
|
|
268
|
+
: '';
|
|
269
|
+
|
|
270
|
+
let adapterHashPassCount = 0;
|
|
271
|
+
const adapterChecks = [];
|
|
272
|
+
|
|
273
|
+
for (const adapterPath of ADAPTER_PATHS) {
|
|
274
|
+
const adapterContent = readText(adapterPath);
|
|
275
|
+
|
|
276
|
+
if (!adapterContent) {
|
|
277
|
+
failures.push(`Missing adapter file: ${adapterPath}`);
|
|
278
|
+
pushResult(results, false, 'adapter-file-exists', `Missing ${adapterPath}`);
|
|
279
|
+
adapterChecks.push({
|
|
280
|
+
path: adapterPath,
|
|
281
|
+
exists: false,
|
|
282
|
+
thinAdapterMode: false,
|
|
283
|
+
sourcePointerValid: false,
|
|
284
|
+
hashMatchesCanonical: false,
|
|
285
|
+
});
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
pushResult(results, true, 'adapter-file-exists', `${adapterPath} is present`);
|
|
290
|
+
|
|
291
|
+
const thinAdapterMode = adapterContent.includes('Adapter Mode: thin');
|
|
292
|
+
const sourcePointerValid = adapterContent.includes('Adapter Source: .instructions.md');
|
|
293
|
+
const hashMatch = adapterContent.match(/Canonical Snapshot SHA256:\s*([a-f0-9]{64})/);
|
|
294
|
+
const hashMatchesCanonical = Boolean(hashMatch && canonicalHash && hashMatch[1] === canonicalHash);
|
|
295
|
+
|
|
296
|
+
if (!thinAdapterMode) {
|
|
297
|
+
failures.push(`${adapterPath} must stay in thin adapter mode`);
|
|
298
|
+
pushResult(results, false, 'adapter-thin-mode', `${adapterPath} is missing Adapter Mode: thin metadata`);
|
|
299
|
+
} else {
|
|
300
|
+
pushResult(results, true, 'adapter-thin-mode', `${adapterPath} declares thin adapter mode`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (!sourcePointerValid) {
|
|
304
|
+
failures.push(`${adapterPath} must point to canonical source .instructions.md`);
|
|
305
|
+
pushResult(results, false, 'adapter-canonical-source-pointer', `${adapterPath} is missing canonical source pointer`);
|
|
306
|
+
} else {
|
|
307
|
+
pushResult(results, true, 'adapter-canonical-source-pointer', `${adapterPath} points to canonical source`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!hashMatch) {
|
|
311
|
+
failures.push(`${adapterPath} must declare Canonical Snapshot SHA256`);
|
|
312
|
+
pushResult(results, false, 'adapter-canonical-hash', `${adapterPath} is missing Canonical Snapshot SHA256 metadata`);
|
|
313
|
+
} else if (!hashMatchesCanonical) {
|
|
314
|
+
failures.push(`${adapterPath} canonical hash drift detected`);
|
|
315
|
+
pushResult(results, false, 'adapter-canonical-hash', `${adapterPath} hash does not match ${CANONICAL_SOURCE_PATH}`);
|
|
316
|
+
} else {
|
|
317
|
+
adapterHashPassCount += 1;
|
|
318
|
+
pushResult(results, true, 'adapter-canonical-hash', `${adapterPath} hash matches canonical source`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
adapterChecks.push({
|
|
322
|
+
path: adapterPath,
|
|
323
|
+
exists: true,
|
|
324
|
+
thinAdapterMode,
|
|
325
|
+
sourcePointerValid,
|
|
326
|
+
hashMatchesCanonical,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const architectureCoverageComplete = assertSnippetCoverage(
|
|
331
|
+
'single-source-lazy-loading-architecture-rule',
|
|
332
|
+
ARCHITECTURE_RULE_PATH,
|
|
333
|
+
REQUIRED_ARCHITECTURE_RULE_SNIPPETS,
|
|
334
|
+
failures,
|
|
335
|
+
results
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const checklistCoverageComplete = assertSnippetCoverage(
|
|
339
|
+
'single-source-lazy-loading-pr-checklist',
|
|
340
|
+
PR_CHECKLIST_PATH,
|
|
341
|
+
REQUIRED_PR_CHECKLIST_SNIPPETS,
|
|
342
|
+
failures,
|
|
343
|
+
results
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const reviewPromptCoverageComplete = assertSnippetCoverage(
|
|
347
|
+
'single-source-lazy-loading-review-prompt',
|
|
348
|
+
REVIEW_PROMPT_PATH,
|
|
349
|
+
REQUIRED_REVIEW_PROMPT_SNIPPETS,
|
|
350
|
+
failures,
|
|
351
|
+
results
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
const compilerCoverageComplete = assertSnippetCoverage(
|
|
355
|
+
'single-source-lazy-loading-compiler-policy',
|
|
356
|
+
COMPILER_PATH,
|
|
357
|
+
REQUIRED_COMPILER_SNIPPETS,
|
|
358
|
+
failures,
|
|
359
|
+
results
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
const onboardingReportContent = readText(ONBOARDING_REPORT_PATH);
|
|
363
|
+
const onboardingReport = parseJsonSafely(onboardingReportContent);
|
|
364
|
+
|
|
365
|
+
let onboardingLazyPolicyMode = 'missing';
|
|
366
|
+
let onboardingLazyPolicyValidated = false;
|
|
367
|
+
|
|
368
|
+
if (!onboardingReportContent) {
|
|
369
|
+
warnings.push(`Missing ${ONBOARDING_REPORT_PATH}; fallback lazy policy inference used`);
|
|
370
|
+
pushResult(results, false, 'lazy-loading-onboarding-state', `Missing ${ONBOARDING_REPORT_PATH}`);
|
|
371
|
+
} else if (!onboardingReport) {
|
|
372
|
+
failures.push(`Invalid JSON in ${ONBOARDING_REPORT_PATH}`);
|
|
373
|
+
pushResult(results, false, 'lazy-loading-onboarding-state', `Cannot parse ${ONBOARDING_REPORT_PATH}`);
|
|
374
|
+
} else {
|
|
375
|
+
const lazyPolicy = onboardingReport.ruleLoadingPolicy;
|
|
376
|
+
|
|
377
|
+
if (lazyPolicy
|
|
378
|
+
&& lazyPolicy.canonicalSource === CANONICAL_SOURCE_PATH
|
|
379
|
+
&& lazyPolicy.stackLoadingMode === 'lazy'
|
|
380
|
+
&& lazyPolicy.loadedOnDemand === true) {
|
|
381
|
+
onboardingLazyPolicyMode = 'explicit-lazy-policy';
|
|
382
|
+
onboardingLazyPolicyValidated = true;
|
|
383
|
+
pushResult(results, true, 'lazy-loading-onboarding-state', `${ONBOARDING_REPORT_PATH} exposes explicit lazy loading policy`);
|
|
384
|
+
} else if (typeof onboardingReport.selectedStack === 'string' && onboardingReport.selectedStack.trim().length > 0) {
|
|
385
|
+
onboardingLazyPolicyMode = 'selected-stack-fallback';
|
|
386
|
+
onboardingLazyPolicyValidated = true;
|
|
387
|
+
warnings.push('Onboarding report does not include explicit ruleLoadingPolicy; using selectedStack fallback inference');
|
|
388
|
+
pushResult(
|
|
389
|
+
results,
|
|
390
|
+
true,
|
|
391
|
+
'lazy-loading-onboarding-state',
|
|
392
|
+
`${ONBOARDING_REPORT_PATH} includes selectedStack fallback for lazy loading policy`
|
|
393
|
+
);
|
|
394
|
+
} else {
|
|
395
|
+
onboardingLazyPolicyMode = 'invalid';
|
|
396
|
+
failures.push(`${ONBOARDING_REPORT_PATH} must include selectedStack or explicit ruleLoadingPolicy`);
|
|
397
|
+
pushResult(results, false, 'lazy-loading-onboarding-state', `${ONBOARDING_REPORT_PATH} missing lazy loading policy signals`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
let compiledRulesCanonicalPassCount = 0;
|
|
402
|
+
let eagerLoadingDetected = false;
|
|
403
|
+
const compiledRuleChecks = [];
|
|
404
|
+
|
|
405
|
+
for (const compiledRulePath of COMPILED_RULE_PATHS) {
|
|
406
|
+
const compiledRuleContent = readText(compiledRulePath);
|
|
407
|
+
|
|
408
|
+
if (!compiledRuleContent) {
|
|
409
|
+
failures.push(`Missing compiled rules file: ${compiledRulePath}`);
|
|
410
|
+
pushResult(results, false, 'compiled-rules-file-exists', `Missing ${compiledRulePath}`);
|
|
411
|
+
compiledRuleChecks.push({
|
|
412
|
+
path: compiledRulePath,
|
|
413
|
+
exists: false,
|
|
414
|
+
canonicalBaselineDeclared: false,
|
|
415
|
+
stackMentionCount: 0,
|
|
416
|
+
eagerLoadingDetected: false,
|
|
417
|
+
});
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
pushResult(results, true, 'compiled-rules-file-exists', `${compiledRulePath} is present`);
|
|
422
|
+
|
|
423
|
+
const canonicalBaselineDeclared = compiledRuleContent.includes('Canonical baseline: .instructions.md');
|
|
424
|
+
if (canonicalBaselineDeclared) {
|
|
425
|
+
compiledRulesCanonicalPassCount += 1;
|
|
426
|
+
pushResult(results, true, 'compiled-rules-canonical-baseline', `${compiledRulePath} declares canonical baseline`);
|
|
427
|
+
} else {
|
|
428
|
+
failures.push(`${compiledRulePath} must declare canonical baseline ${CANONICAL_SOURCE_PATH}`);
|
|
429
|
+
pushResult(results, false, 'compiled-rules-canonical-baseline', `${compiledRulePath} is missing canonical baseline declaration`);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const stackMentionCount = countStackMentions(compiledRuleContent);
|
|
433
|
+
const isEagerLoading = stackMentionCount > MAX_EAGER_STACK_MENTIONS;
|
|
434
|
+
|
|
435
|
+
if (isEagerLoading) {
|
|
436
|
+
eagerLoadingDetected = true;
|
|
437
|
+
failures.push(`${compiledRulePath} appears to preload too many stack profiles (${stackMentionCount})`);
|
|
438
|
+
pushResult(
|
|
439
|
+
results,
|
|
440
|
+
false,
|
|
441
|
+
'compiled-rules-lazy-loading-density',
|
|
442
|
+
`${compiledRulePath} has ${stackMentionCount} stack profile mentions; expected <= ${MAX_EAGER_STACK_MENTIONS}`
|
|
443
|
+
);
|
|
444
|
+
} else {
|
|
445
|
+
pushResult(
|
|
446
|
+
results,
|
|
447
|
+
true,
|
|
448
|
+
'compiled-rules-lazy-loading-density',
|
|
449
|
+
`${compiledRulePath} has ${stackMentionCount} stack profile mentions (lazy-loading threshold satisfied)`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
compiledRuleChecks.push({
|
|
454
|
+
path: compiledRulePath,
|
|
455
|
+
exists: true,
|
|
456
|
+
canonicalBaselineDeclared,
|
|
457
|
+
stackMentionCount,
|
|
458
|
+
eagerLoadingDetected: isEagerLoading,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const canonicalSourceEnforced = canonicalSourceExists
|
|
463
|
+
&& adapterHashPassCount === ADAPTER_PATHS.length
|
|
464
|
+
&& compiledRulesCanonicalPassCount === COMPILED_RULE_PATHS.length
|
|
465
|
+
&& architectureCoverageComplete
|
|
466
|
+
&& checklistCoverageComplete
|
|
467
|
+
&& reviewPromptCoverageComplete;
|
|
468
|
+
|
|
469
|
+
if (canonicalSourceEnforced) {
|
|
470
|
+
pushResult(results, true, 'canonical-source-hard-rule', 'Canonical rule source is explicitly defined and enforced');
|
|
471
|
+
} else {
|
|
472
|
+
failures.push('Canonical rule source hard-rule is not fully enforced');
|
|
473
|
+
pushResult(results, false, 'canonical-source-hard-rule', 'Canonical source enforcement failed');
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const lazyRuleLoadingEnforced = compilerCoverageComplete
|
|
477
|
+
&& onboardingLazyPolicyValidated
|
|
478
|
+
&& !eagerLoadingDetected;
|
|
479
|
+
|
|
480
|
+
if (lazyRuleLoadingEnforced) {
|
|
481
|
+
pushResult(results, true, 'lazy-rule-loading-hard-rule', 'Language-specific guidance is loaded lazily by detected scope');
|
|
482
|
+
} else {
|
|
483
|
+
failures.push('Lazy rule loading hard-rule is not fully enforced');
|
|
484
|
+
pushResult(results, false, 'lazy-rule-loading-hard-rule', 'Lazy loading enforcement failed');
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const noConflictingDuplicates = canonicalSourceEnforced && !eagerLoadingDetected;
|
|
488
|
+
|
|
489
|
+
if (noConflictingDuplicates) {
|
|
490
|
+
pushResult(results, true, 'no-conflicting-duplicate-rule-instructions', 'No conflicting duplicate rule instructions detected in normal flow');
|
|
491
|
+
} else {
|
|
492
|
+
failures.push('Conflicting duplicate rule instructions detected in normal flow');
|
|
493
|
+
pushResult(results, false, 'no-conflicting-duplicate-rule-instructions', 'Duplicate/conflicting instruction risk detected');
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const reportPayload = {
|
|
497
|
+
generatedAt: new Date().toISOString(),
|
|
498
|
+
auditName: 'single-source-lazy-loading-audit',
|
|
499
|
+
workflow: parsedArguments.workflow,
|
|
500
|
+
source: changedScope.source,
|
|
501
|
+
changedFileCount: changedFiles.length,
|
|
502
|
+
changedFiles,
|
|
503
|
+
canonicalSource: {
|
|
504
|
+
path: CANONICAL_SOURCE_PATH,
|
|
505
|
+
hash: canonicalHash,
|
|
506
|
+
enforced: canonicalSourceEnforced,
|
|
507
|
+
adapterChecks,
|
|
508
|
+
compiledRuleChecks,
|
|
509
|
+
},
|
|
510
|
+
lazyRuleLoading: {
|
|
511
|
+
enforced: lazyRuleLoadingEnforced,
|
|
512
|
+
compilerPolicySnippetsComplete: compilerCoverageComplete,
|
|
513
|
+
onboardingPolicyMode: onboardingLazyPolicyMode,
|
|
514
|
+
onboardingPolicyValidated: onboardingLazyPolicyValidated,
|
|
515
|
+
eagerLoadingDetected,
|
|
516
|
+
maxAllowedStackMentions: MAX_EAGER_STACK_MENTIONS,
|
|
517
|
+
},
|
|
518
|
+
duplicationPolicy: {
|
|
519
|
+
noConflictingDuplicates,
|
|
520
|
+
conflictingDuplicateSignals: noConflictingDuplicates
|
|
521
|
+
? []
|
|
522
|
+
: ['canonical-source-enforcement-or-lazy-loading-density-failed'],
|
|
523
|
+
},
|
|
524
|
+
passed: failures.length === 0,
|
|
525
|
+
failureCount: failures.length,
|
|
526
|
+
failures,
|
|
527
|
+
warnings,
|
|
528
|
+
results,
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
console.log(JSON.stringify(reportPayload, null, 2));
|
|
532
|
+
process.exit(reportPayload.passed ? 0 : 1);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
runAudit();
|
package/scripts/validate.mjs
CHANGED
|
@@ -174,6 +174,8 @@ async function validateRequiredFiles() {
|
|
|
174
174
|
'scripts/documentation-boundary-audit.mjs',
|
|
175
175
|
'scripts/context-triggered-audit.mjs',
|
|
176
176
|
'scripts/rules-guardian-audit.mjs',
|
|
177
|
+
'scripts/explain-on-demand-audit.mjs',
|
|
178
|
+
'scripts/single-source-lazy-loading-audit.mjs',
|
|
177
179
|
'scripts/release-gate.mjs',
|
|
178
180
|
'scripts/generate-sbom.mjs',
|
|
179
181
|
'scripts/init-project.sh',
|