@ryuenn3123/agentic-senior-core 2.5.15 → 2.5.17
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/init-project.md +1 -1
- package/.agent-context/prompts/review-code.md +1 -0
- package/.agent-context/review-checklists/pr-checklist.md +5 -0
- package/.agent-context/rules/architecture.md +8 -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/README.md +1 -1
- package/lib/cli/commands/init.mjs +4 -4
- package/lib/cli/commands/upgrade.mjs +2 -2
- package/lib/cli/compiler.mjs +20 -1
- package/lib/cli/utils.mjs +1 -1
- package/package.json +2 -1
- package/scripts/release-gate.mjs +68 -0
- package/scripts/single-source-lazy-loading-audit.mjs +535 -0
- package/scripts/validate.mjs +57 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Prompts: Initialize Project
|
|
2
2
|
|
|
3
3
|
> Copy-paste one of these prompts to your AI agent (Cursor, Windsurf, Copilot, Antigravity) right after cloning this repository.
|
|
4
|
-
> V1.4 recommendation: run `bunx @fatidaprilian/agentic-senior-core init` first to compile dynamic
|
|
4
|
+
> V1.4 recommendation: run `bunx @fatidaprilian/agentic-senior-core init` first to compile dynamic rules operations context (Federated Governance baseline).
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -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,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"cliVersion": "2.
|
|
3
|
-
"generatedAt": "2026-04-
|
|
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.
|
|
4
|
-
Timestamp: 2026-04-
|
|
3
|
+
Generated by Agentic-Senior-Core CLI v2.5.17
|
|
4
|
+
Timestamp: 2026-04-18T03: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.
|
|
4
|
-
Timestamp: 2026-04-
|
|
3
|
+
Generated by Agentic-Senior-Core CLI v2.5.17
|
|
4
|
+
Timestamp: 2026-04-18T03:00:00.000Z
|
|
5
5
|
Selected profile: beginner
|
|
6
6
|
Selected policy file: .agent-context/policies/llm-judge-threshold.json
|
|
7
7
|
|
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ If you see `Property $schema is not allowed`, keep `.vscode/mcp.json` without `$
|
|
|
74
74
|
|
|
75
75
|
| Command | Purpose |
|
|
76
76
|
|---------|---------|
|
|
77
|
-
| `agentic-senior-core init` | Initialize
|
|
77
|
+
| `agentic-senior-core init` | Initialize rules operations context (Federated Governance baseline) |
|
|
78
78
|
| `agentic-senior-core upgrade --dry-run` | Preview safe upgrades |
|
|
79
79
|
| `agentic-senior-core optimize --show` | Show token optimization state |
|
|
80
80
|
| `agentic-senior-core skill frontend --tier advance` | Select skill packs |
|
|
@@ -583,7 +583,7 @@ export async function runInitCommand(targetDirectoryArgument, initOptions = {})
|
|
|
583
583
|
}
|
|
584
584
|
|
|
585
585
|
console.log(`\nAgentic-Senior-Core CLI v${CLI_VERSION}`);
|
|
586
|
-
console.log('I will copy
|
|
586
|
+
console.log('I will copy rules operations assets (Federated Governance baseline) into your target folder and compile a single rulebook for your AI tools.');
|
|
587
587
|
|
|
588
588
|
if (selectedPreset) {
|
|
589
589
|
console.log(`Using preset: ${initOptions.preset} (${selectedPreset.description}).`);
|
|
@@ -881,7 +881,7 @@ export async function runInitCommand(targetDirectoryArgument, initOptions = {})
|
|
|
881
881
|
? selectedProfilePack.defaultCi
|
|
882
882
|
: selectedProfile.lockCi
|
|
883
883
|
? selectedProfile.defaultCi
|
|
884
|
-
: await askYesNo('Enable CI/CD guardrails and the LLM Judge policy?', userInterface, selectedProfile.defaultCi);
|
|
884
|
+
: await askYesNo('Enable CI/CD quality checks (guardrails) and the LLM Judge policy?', userInterface, selectedProfile.defaultCi);
|
|
885
885
|
|
|
886
886
|
await copyGovernanceAssetsToTarget(resolvedTargetDirectoryPath, {
|
|
887
887
|
includeMcpTemplate: shouldIncludeMcpTemplate,
|
|
@@ -1078,7 +1078,7 @@ export async function runInitCommand(targetDirectoryArgument, initOptions = {})
|
|
|
1078
1078
|
console.log(`- Additional blueprints: ${selectedAdditionalBlueprintFileNames.map((blueprintFileName) => toTitleCase(blueprintFileName)).join(', ')}`);
|
|
1079
1079
|
}
|
|
1080
1080
|
console.log(`- Runtime environment: ${resolveRuntimeEnvironmentLabelFromKey(selectedRuntimeEnvironmentKey)} (detected: ${detectedRuntimeEnvironment.label})`);
|
|
1081
|
-
console.log(`- CI/CD guardrails: ${includeCiGuardrails ? 'enabled' : 'disabled'}`);
|
|
1081
|
+
console.log(`- CI/CD quality checks (guardrails): ${includeCiGuardrails ? 'enabled' : 'disabled'}`);
|
|
1082
1082
|
console.log(`- Blocking severities: ${formatBlockingSeverities(selectedProfile.blockingSeverities)}`);
|
|
1083
1083
|
console.log(`- Setup time: ${formatDuration(setupDurationMs)}`);
|
|
1084
1084
|
console.log('- Generated files: .cursorrules, .windsurfrules, and .agent-context/state/onboarding-report.json');
|
|
@@ -1099,7 +1099,7 @@ export async function runInitCommand(targetDirectoryArgument, initOptions = {})
|
|
|
1099
1099
|
console.log('- Token optimization policy: disabled (--no-token-optimize)');
|
|
1100
1100
|
}
|
|
1101
1101
|
console.log('\nPlain-language summary:');
|
|
1102
|
-
console.log(`I prepared a ${selectedProfile.displayName.toLowerCase()}
|
|
1102
|
+
console.log(`I prepared a ${selectedProfile.displayName.toLowerCase()} rules operations pack (Federated Governance baseline) for a ${toTitleCase(selectedResolvedStackFileName)} project using the ${toTitleCase(selectedResolvedBlueprintFileName)} blueprint.`);
|
|
1103
1103
|
if (selectedAdditionalStackFileNames.length > 0) {
|
|
1104
1104
|
console.log(`I also included additional stack context for ${selectedAdditionalStackFileNames.map((stackFileName) => toTitleCase(stackFileName)).join(', ')}.`);
|
|
1105
1105
|
}
|
|
@@ -100,7 +100,7 @@ export async function runUpgradeCommand(targetDirectoryArgument, upgradeOptions
|
|
|
100
100
|
|
|
101
101
|
try {
|
|
102
102
|
console.log(`\nAgentic-Senior-Core CLI v${CLI_VERSION}`);
|
|
103
|
-
console.log('Running upgrade assistant for an existing repository.');
|
|
103
|
+
console.log('Running rules operations upgrade assistant (Federated Governance baseline) for an existing repository.');
|
|
104
104
|
|
|
105
105
|
await copyGovernanceAssetsToTarget(resolvedTargetDirectoryPath, {
|
|
106
106
|
includeMcpTemplate: upgradeOptions.includeMcpTemplate === true,
|
|
@@ -193,7 +193,7 @@ export async function runUpgradeCommand(targetDirectoryArgument, upgradeOptions
|
|
|
193
193
|
if (selectedAdditionalBlueprintFileNames.length > 0) {
|
|
194
194
|
console.log(`- Additional blueprints: ${selectedAdditionalBlueprintFileNames.map((blueprintFileName) => toTitleCase(blueprintFileName)).join(', ')}`);
|
|
195
195
|
}
|
|
196
|
-
console.log(`- CI/CD guardrails: ${includeCiGuardrails ? 'enabled' : 'disabled'}`);
|
|
196
|
+
console.log(`- CI/CD quality checks (guardrails): ${includeCiGuardrails ? 'enabled' : 'disabled'}`);
|
|
197
197
|
console.log(`- Existing rules lines: ${currentRuleLineCount}`);
|
|
198
198
|
console.log(`- Planned rules lines: ${plannedRuleLineCount}`);
|
|
199
199
|
console.log(`- Rules changed: ${isRulesContentChanged ? 'yes' : 'no'}`);
|
package/lib/cli/compiler.mjs
CHANGED
|
@@ -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/lib/cli/utils.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export function printUsage() {
|
|
|
49
49
|
console.log(' --project-description Architecture intent text used for stack/blueprint recommendation');
|
|
50
50
|
console.log(' --architect-token-budget Max token estimate used by recommendation research (default: 900)');
|
|
51
51
|
console.log(' --architect-timeout-ms Max recommendation research time in milliseconds (default: 1500)');
|
|
52
|
-
console.log(' --ci Override CI/CD guardrails (true|false)');
|
|
52
|
+
console.log(' --ci Override CI/CD quality checks (guardrails) (true|false)');
|
|
53
53
|
console.log(' --token-optimize Explicitly enable token optimization policy during init (default behavior)');
|
|
54
54
|
console.log(' --token-agent Set token optimization agent target (copilot, claude, cursor, windsurf, gemini, codex, cline)');
|
|
55
55
|
console.log(' --no-token-optimize Disable token optimization policy during init');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuenn3123/agentic-senior-core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.17",
|
|
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",
|
package/scripts/release-gate.mjs
CHANGED
|
@@ -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();
|
package/scripts/validate.mjs
CHANGED
|
@@ -80,6 +80,26 @@ const REQUIRED_HUMAN_WRITING_SNIPPETS = [
|
|
|
80
80
|
],
|
|
81
81
|
},
|
|
82
82
|
];
|
|
83
|
+
const TERMINOLOGY_REFERENCE_PATHS = [
|
|
84
|
+
'README.md',
|
|
85
|
+
'docs/roadmap.md',
|
|
86
|
+
];
|
|
87
|
+
const REQUIRED_TERMINOLOGY_ROW_PATTERNS = [
|
|
88
|
+
{
|
|
89
|
+
label: 'Federated Governance -> Federated Rules Operations',
|
|
90
|
+
pattern: /\|\s*Federated Governance\s*\|\s*Federated Rules Operations\s*\|/u,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: 'Governance Engine -> Rules Engine',
|
|
94
|
+
pattern: /\|\s*Governance Engine\s*\|\s*Rules Engine\s*\|/u,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: 'Guardrails -> Quality Checks',
|
|
98
|
+
pattern: /\|\s*Guardrails\s*\|\s*Quality Checks\s*\|/u,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
const REQUIRED_TERMINOLOGY_RULE_SNIPPET =
|
|
102
|
+
'Rule: on first mention in developer-facing docs, include canonical term in parentheses.';
|
|
83
103
|
|
|
84
104
|
const validationResult = {
|
|
85
105
|
passed: 0,
|
|
@@ -175,6 +195,7 @@ async function validateRequiredFiles() {
|
|
|
175
195
|
'scripts/context-triggered-audit.mjs',
|
|
176
196
|
'scripts/rules-guardian-audit.mjs',
|
|
177
197
|
'scripts/explain-on-demand-audit.mjs',
|
|
198
|
+
'scripts/single-source-lazy-loading-audit.mjs',
|
|
178
199
|
'scripts/release-gate.mjs',
|
|
179
200
|
'scripts/generate-sbom.mjs',
|
|
180
201
|
'scripts/init-project.sh',
|
|
@@ -726,6 +747,41 @@ async function validateDocumentationFlow() {
|
|
|
726
747
|
}
|
|
727
748
|
}
|
|
728
749
|
|
|
750
|
+
async function validateTerminologyMapping() {
|
|
751
|
+
console.log('\nChecking terminology mapping consistency...');
|
|
752
|
+
|
|
753
|
+
for (const terminologyReferencePath of TERMINOLOGY_REFERENCE_PATHS) {
|
|
754
|
+
const absoluteReferencePath = join(ROOT_DIR, terminologyReferencePath);
|
|
755
|
+
|
|
756
|
+
if (!(await fileExists(absoluteReferencePath))) {
|
|
757
|
+
fail(`Missing terminology reference source: ${terminologyReferencePath}`);
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const referenceContent = await readTextFile(absoluteReferencePath);
|
|
762
|
+
|
|
763
|
+
if (referenceContent.includes('Terminology Mapping (Final)')) {
|
|
764
|
+
pass(`${terminologyReferencePath} includes Terminology Mapping (Final)`);
|
|
765
|
+
} else {
|
|
766
|
+
fail(`${terminologyReferencePath} must include Terminology Mapping (Final)`);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
for (const terminologyRowRule of REQUIRED_TERMINOLOGY_ROW_PATTERNS) {
|
|
770
|
+
if (terminologyRowRule.pattern.test(referenceContent)) {
|
|
771
|
+
pass(`${terminologyReferencePath} includes mapping row: ${terminologyRowRule.label}`);
|
|
772
|
+
} else {
|
|
773
|
+
fail(`${terminologyReferencePath} is missing mapping row: ${terminologyRowRule.label}`);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (referenceContent.includes(REQUIRED_TERMINOLOGY_RULE_SNIPPET)) {
|
|
778
|
+
pass(`${terminologyReferencePath} includes first-mention canonical term rule`);
|
|
779
|
+
} else {
|
|
780
|
+
fail(`${terminologyReferencePath} must include first-mention canonical term rule`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
729
785
|
async function validateMcpConfiguration() {
|
|
730
786
|
console.log('\nChecking MCP configuration...');
|
|
731
787
|
|
|
@@ -974,6 +1030,7 @@ async function main() {
|
|
|
974
1030
|
await validatePolicyFile();
|
|
975
1031
|
await validateVersionConsistency();
|
|
976
1032
|
await validateDocumentationFlow();
|
|
1033
|
+
await validateTerminologyMapping();
|
|
977
1034
|
await validateMcpConfiguration();
|
|
978
1035
|
await validateHumanWritingGovernance();
|
|
979
1036
|
await validateInstructionAdapters();
|