@ryuenn3123/agentic-senior-core 2.5.15 → 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.
@@ -19,6 +19,7 @@ Use these checklists:
19
19
  6. Enforce context-triggered strict audits: review requests, PR-intent workflows, and major feature completion must run strict security and performance audits; small edits stay lightweight unless strict mode is explicitly forced.
20
20
  7. Enforce cross-session consistency guardian: session handoff must include active architecture contract summary, drift detection must warn before direction changes, and direction changes require explicit user confirmation.
21
21
  8. Enforce explain-on-demand state visibility: default responses must avoid unnecessary state-file internals, state internals are exposed only on explicit request, and diagnostic mode must explain relevant state decisions when needed.
22
+ 9. 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.
22
23
 
23
24
  For EVERY violation found:
24
25
  - State the exact file and line
@@ -124,3 +124,8 @@ VERDICT: PASS / FAIL (X/Y items passed)
124
124
  - [ ] Default responses avoid unnecessary state-file internals
125
125
  - [ ] State internals are exposed only on explicit request
126
126
  - [ ] Diagnostic mode can explain relevant state decisions when needed
127
+
128
+ ### 14. Single Source and Lazy Rule Loading
129
+ - [ ] Canonical rule source is explicitly defined and enforced
130
+ - [ ] Language-specific guidance is loaded lazily based on detected scope
131
+ - [ ] No conflicting duplicate rule instructions during normal flow
@@ -32,6 +32,14 @@ State internals must stay invisible by default.
32
32
  - Diagnostic mode explains relevant state decisions when needed.
33
33
  - Keep default explanations concise and outcome-first; show raw state details only in diagnostic mode.
34
34
 
35
+ ## Single Source of Truth and Lazy Rule Loading
36
+
37
+ - Canonical rule source is .instructions.md.
38
+ - Adapter entry files stay thin and must point to the canonical source.
39
+ - Load language-specific stack guidance lazily based on detected scope.
40
+ - Do not preload unrelated stack profiles during normal flow.
41
+ - Keep rule-loading output deterministic for init and release validation.
42
+
35
43
  ## The Core Principle
36
44
 
37
45
  **Every layer has ONE job. Layer leaks are bugs — not "pragmatic shortcuts."**
@@ -1,5 +1,5 @@
1
1
  {
2
- "generatedAt": "2026-04-17T13:21:48.914Z",
2
+ "generatedAt": "2026-04-18T02:25:05.037Z",
3
3
  "reportName": "memory-continuity-benchmark",
4
4
  "schemaVersion": "1.0.0",
5
5
  "passed": true,
@@ -1,11 +1,20 @@
1
1
  {
2
- "cliVersion": "2.0.1",
3
- "generatedAt": "2026-04-08T14:58:53.636Z",
2
+ "cliVersion": "2.5.16",
3
+ "generatedAt": "2026-04-18T00:00:00.000Z",
4
4
  "operationMode": "upgrade",
5
5
  "selectedProfile": "beginner",
6
6
  "selectedProfilePack": null,
7
7
  "selectedStack": "typescript.md",
8
+ "selectedAdditionalStacks": [],
8
9
  "selectedBlueprint": "api-nextjs.md",
10
+ "selectedAdditionalBlueprints": [],
11
+ "ruleLoadingPolicy": {
12
+ "canonicalSource": ".instructions.md",
13
+ "stackLoadingMode": "lazy",
14
+ "loadedOnDemand": true,
15
+ "primaryStack": "typescript.md",
16
+ "additionalStacks": []
17
+ },
9
18
  "ciGuardrailsEnabled": true,
10
19
  "setupDurationMs": 106,
11
20
  "selectedSkillDomains": [],
package/.cursorrules CHANGED
@@ -1,7 +1,7 @@
1
1
  # AGENTIC-SENIOR-CORE DYNAMIC GOVERNANCE RULESET
2
2
 
3
- Generated by Agentic-Senior-Core CLI v2.5.15
4
- Timestamp: 2026-04-15T00:14:51.184Z
3
+ Generated by Agentic-Senior-Core CLI v2.5.16
4
+ Timestamp: 2026-04-18T00:00:00.000Z
5
5
  Selected profile: beginner
6
6
  Selected policy file: .agent-context/policies/llm-judge-threshold.json
7
7
 
package/.windsurfrules CHANGED
@@ -1,7 +1,7 @@
1
1
  # AGENTIC-SENIOR-CORE DYNAMIC GOVERNANCE RULESET
2
2
 
3
- Generated by Agentic-Senior-Core CLI v2.5.15
4
- Timestamp: 2026-04-15T00:14:51.184Z
3
+ Generated by Agentic-Senior-Core CLI v2.5.16
4
+ Timestamp: 2026-04-18T00:00:00.000Z
5
5
  Selected profile: beginner
6
6
  Selected policy file: .agent-context/policies/llm-judge-threshold.json
7
7
 
@@ -80,6 +80,13 @@ export async function writeOnboardingReport({
80
80
  selectedAdditionalStacks: selectedAdditionalStackFileNames,
81
81
  selectedBlueprint: selectedBlueprintFileName,
82
82
  selectedAdditionalBlueprints: selectedAdditionalBlueprintFileNames,
83
+ ruleLoadingPolicy: {
84
+ canonicalSource: '.instructions.md',
85
+ stackLoadingMode: 'lazy',
86
+ loadedOnDemand: true,
87
+ primaryStack: selectedStackFileName,
88
+ additionalStacks: selectedAdditionalStackFileNames,
89
+ },
83
90
  ciGuardrailsEnabled: includeCiGuardrails,
84
91
  setupDurationMs,
85
92
  selectedSkillDomains,
@@ -174,7 +181,7 @@ export async function buildCompiledRulesContent({
174
181
  '## BOOTSTRAP CHAIN (MANDATORY)',
175
182
  'Load every layer before responding. Do not skip steps:',
176
183
  '1. .agent-context/rules/',
177
- '2. .agent-context/stacks/',
184
+ '2. .agent-context/stacks/ (lazy by task scope)',
178
185
  '3. .agent-context/blueprints/',
179
186
  '4. .agent-context/skills/',
180
187
  '5. .agent-context/prompts/',
@@ -220,6 +227,18 @@ export async function buildCompiledRulesContent({
220
227
  );
221
228
  }
222
229
 
230
+ contextBlocks.push(
231
+ [
232
+ '## LAYER 2 POLICY: LAZY RULE LOADING',
233
+ `Primary stack profile is always loaded for this project: .agent-context/stacks/${selectedStackFileName}`,
234
+ normalizedAdditionalStackFileNames.length > 0
235
+ ? `Additional stack profiles load on demand: ${normalizedAdditionalStackFileNames.map((stackFileName) => `.agent-context/stacks/${stackFileName}`).join(', ')}`
236
+ : 'Additional stack profiles load only when explicitly selected or detected.',
237
+ 'Load stack guidance only when task scope touches that stack.',
238
+ 'Avoid eager loading unrelated stack profiles to prevent instruction conflicts.',
239
+ ].join('\n')
240
+ );
241
+
223
242
  const blueprintFilePath = path.join(selectedBlueprintsDirectoryPath, selectedBlueprintFileName);
224
243
  const blueprintContent = await fs.readFile(blueprintFilePath, 'utf8');
225
244
  const blueprintSummary = firstMarkdownHeading(blueprintContent, selectedBlueprintFileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuenn3123/agentic-senior-core",
3
- "version": "2.5.15",
3
+ "version": "2.5.16",
4
4
  "type": "module",
5
5
  "description": "Force your AI Agent to code like a Staff Engineer, not a Junior.",
6
6
  "bin": {
@@ -47,6 +47,7 @@
47
47
  "audit:context-triggered": "node ./scripts/context-triggered-audit.mjs",
48
48
  "audit:rules-guardian": "node ./scripts/rules-guardian-audit.mjs",
49
49
  "audit:explain-on-demand": "node ./scripts/explain-on-demand-audit.mjs",
50
+ "audit:single-source-lazy-loading": "node ./scripts/single-source-lazy-loading-audit.mjs",
50
51
  "gate:release": "node ./scripts/release-gate.mjs && node ./scripts/forbidden-content-check.mjs",
51
52
  "prepublishOnly": "npm run gate:release",
52
53
  "sbom:generate": "node ./scripts/generate-sbom.mjs",
@@ -34,6 +34,7 @@ const DOCUMENTATION_BOUNDARY_AUDIT_SCRIPT_PATH = 'scripts/documentation-boundary
34
34
  const CONTEXT_TRIGGERED_AUDIT_SCRIPT_PATH = 'scripts/context-triggered-audit.mjs';
35
35
  const RULES_GUARDIAN_AUDIT_SCRIPT_PATH = 'scripts/rules-guardian-audit.mjs';
36
36
  const EXPLAIN_ON_DEMAND_AUDIT_SCRIPT_PATH = 'scripts/explain-on-demand-audit.mjs';
37
+ const SINGLE_SOURCE_LAZY_LOADING_AUDIT_SCRIPT_PATH = 'scripts/single-source-lazy-loading-audit.mjs';
37
38
  const BACKEND_ARCHITECTURE_RULE_PATH = '.agent-context/rules/architecture.md';
38
39
  const BACKEND_REVIEW_CHECKLIST_PATH = '.agent-context/review-checklists/pr-checklist.md';
39
40
  const REFACTOR_PROMPT_PATH = '.agent-context/prompts/refactor.md';
@@ -605,6 +606,73 @@ function runReleaseGate() {
605
606
  }
606
607
  }
607
608
 
609
+ const singleSourceLazyLoadingAuditExecution = runMachineReadableScript(
610
+ SINGLE_SOURCE_LAZY_LOADING_AUDIT_SCRIPT_PATH,
611
+ ['--workflow', 'pr-preparation']
612
+ );
613
+ if (!singleSourceLazyLoadingAuditExecution.report) {
614
+ const failureDetails = singleSourceLazyLoadingAuditExecution.executionErrorMessage
615
+ ? `Single-source lazy-loading audit execution failed before producing a machine-readable report: ${singleSourceLazyLoadingAuditExecution.executionErrorMessage}`
616
+ : 'Single-source lazy-loading audit did not produce machine-readable JSON output';
617
+ pushResult(results, false, 'single-source-lazy-loading-audit', failureDetails);
618
+ } else {
619
+ diagnostics.singleSourceLazyLoadingAudit = singleSourceLazyLoadingAuditExecution.report;
620
+ pushResult(
621
+ results,
622
+ true,
623
+ 'single-source-lazy-loading-audit',
624
+ `single-source-lazy-loading-audit executed (passed=${singleSourceLazyLoadingAuditExecution.report.passed}, failures=${singleSourceLazyLoadingAuditExecution.report.failureCount})`
625
+ );
626
+
627
+ if (singleSourceLazyLoadingAuditExecution.report?.canonicalSource?.enforced === true) {
628
+ pushResult(
629
+ results,
630
+ true,
631
+ 'canonical-rule-source-hard-rule',
632
+ 'Canonical rule source is explicitly defined and enforced'
633
+ );
634
+ } else {
635
+ pushResult(
636
+ results,
637
+ false,
638
+ 'canonical-rule-source-hard-rule',
639
+ 'Canonical rule source enforcement failed in single-source lazy-loading audit'
640
+ );
641
+ }
642
+
643
+ if (singleSourceLazyLoadingAuditExecution.report?.lazyRuleLoading?.enforced === true) {
644
+ pushResult(
645
+ results,
646
+ true,
647
+ 'lazy-rule-loading-hard-rule',
648
+ 'Language-specific guidance is loaded lazily by detected scope'
649
+ );
650
+ } else {
651
+ pushResult(
652
+ results,
653
+ false,
654
+ 'lazy-rule-loading-hard-rule',
655
+ 'Lazy rule loading enforcement failed in single-source lazy-loading audit'
656
+ );
657
+ }
658
+
659
+ if (singleSourceLazyLoadingAuditExecution.report?.duplicationPolicy?.noConflictingDuplicates === true) {
660
+ pushResult(
661
+ results,
662
+ true,
663
+ 'no-conflicting-duplicate-rule-instructions',
664
+ 'No conflicting duplicate rule instructions detected in normal flow'
665
+ );
666
+ } else {
667
+ pushResult(
668
+ results,
669
+ false,
670
+ 'no-conflicting-duplicate-rule-instructions',
671
+ 'Conflicting duplicate rule instructions detected by single-source lazy-loading audit'
672
+ );
673
+ }
674
+ }
675
+
608
676
  const frontendParityChecklistContent = readText(FRONTEND_PARITY_CHECKLIST_PATH);
609
677
  if (!frontendParityChecklistContent) {
610
678
  pushResult(results, false, 'frontend-parity-checklist-exists', `Missing ${FRONTEND_PARITY_CHECKLIST_PATH}`);
@@ -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();
@@ -175,6 +175,7 @@ async function validateRequiredFiles() {
175
175
  'scripts/context-triggered-audit.mjs',
176
176
  'scripts/rules-guardian-audit.mjs',
177
177
  'scripts/explain-on-demand-audit.mjs',
178
+ 'scripts/single-source-lazy-loading-audit.mjs',
178
179
  'scripts/release-gate.mjs',
179
180
  'scripts/generate-sbom.mjs',
180
181
  'scripts/init-project.sh',