@ryuenn3123/agentic-senior-core 4.4.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/.agents/plugins/agentic-senior-core/plugin.json +3 -0
  2. package/.agents/plugins/agentic-senior-core/rules/agentic-senior-core.md +131 -0
  3. package/.agents/plugins/agentic-senior-core/skills/asc/SKILL.md +16 -0
  4. package/.agents/plugins/agentic-senior-core/skills/asc-audit/SKILL.md +28 -0
  5. package/.agents/plugins/agentic-senior-core/skills/asc-refactor/SKILL.md +35 -0
  6. package/.agents/plugins/agentic-senior-core/skills/asc-review/SKILL.md +54 -0
  7. package/.agents/rules/agentic-senior-core.md +131 -0
  8. package/.claude-plugin/marketplace.json +17 -0
  9. package/.claude-plugin/plugin.json +17 -0
  10. package/.clinerules/agentic-senior-core.md +94 -0
  11. package/.codex-plugin/plugin.json +24 -0
  12. package/.cursor/rules/agentic-senior-core.mdc +99 -0
  13. package/.devin-plugin/plugin.json +13 -0
  14. package/.github/copilot-instructions.md +94 -0
  15. package/.github/plugin/marketplace.json +20 -0
  16. package/.github/plugin/plugin.json +16 -0
  17. package/.kiro/steering/agentic-senior-core.md +94 -0
  18. package/.openclaw/skills/asc/SKILL.md +23 -0
  19. package/.openclaw/skills/asc-audit/SKILL.md +28 -0
  20. package/.openclaw/skills/asc-review/SKILL.md +54 -0
  21. package/.opencode/plugins/agentic-senior-core.mjs +31 -0
  22. package/.windsurf/rules/agentic-senior-core.md +94 -0
  23. package/AGENTS.md +126 -127
  24. package/CONTRIBUTING.md +93 -63
  25. package/README.md +190 -110
  26. package/__init__.py +61 -0
  27. package/bin/agentic-senior-core.js +42 -41
  28. package/commands/asc-audit.md +1 -0
  29. package/commands/asc-audit.toml +2 -0
  30. package/commands/asc-help.md +9 -0
  31. package/commands/asc-help.toml +2 -0
  32. package/commands/asc-refactor.md +1 -0
  33. package/commands/asc-refactor.toml +2 -0
  34. package/commands/asc-review.md +1 -0
  35. package/commands/asc-review.toml +2 -0
  36. package/gemini-extension.json +10 -0
  37. package/hooks/copilot-hooks.json +21 -0
  38. package/hooks/hooks.json +31 -0
  39. package/hooks/session-start.js +36 -0
  40. package/hooks/subagent-start.js +38 -0
  41. package/lib/cli/commands/adapter.mjs +109 -0
  42. package/lib/cli/commands/clean.mjs +63 -0
  43. package/lib/cli/commands/status.mjs +94 -0
  44. package/package.json +43 -60
  45. package/plugin.yaml +16 -0
  46. package/scripts/uninstall.js +38 -0
  47. package/skills/asc/SKILL.md +16 -0
  48. package/skills/asc-audit/SKILL.md +28 -0
  49. package/skills/asc-refactor/SKILL.md +35 -0
  50. package/skills/asc-review/SKILL.md +54 -0
  51. package/.agent-context/policies/llm-judge-threshold.json +0 -29
  52. package/.agent-context/prompts/bootstrap-design.md +0 -63
  53. package/.agent-context/prompts/compact-natural-mode.md +0 -100
  54. package/.agent-context/prompts/init-project.md +0 -60
  55. package/.agent-context/prompts/refactor.md +0 -38
  56. package/.agent-context/prompts/review-code.md +0 -31
  57. package/.agent-context/review-checklists/architecture-review.md +0 -57
  58. package/.agent-context/review-checklists/pr-checklist.md +0 -134
  59. package/.agent-context/rules/api-docs.md +0 -24
  60. package/.agent-context/rules/api-versioning.md +0 -16
  61. package/.agent-context/rules/architecture.md +0 -38
  62. package/.agent-context/rules/background-jobs.md +0 -17
  63. package/.agent-context/rules/config-and-flags.md +0 -16
  64. package/.agent-context/rules/database-design.md +0 -18
  65. package/.agent-context/rules/docker-runtime.md +0 -17
  66. package/.agent-context/rules/error-handling.md +0 -16
  67. package/.agent-context/rules/event-driven.md +0 -16
  68. package/.agent-context/rules/frontend-architecture.md +0 -54
  69. package/.agent-context/rules/microservices.md +0 -16
  70. package/.agent-context/rules/migrations.md +0 -16
  71. package/.agent-context/rules/observability.md +0 -16
  72. package/.agent-context/rules/performance.md +0 -16
  73. package/.agent-context/rules/realtime.md +0 -16
  74. package/.agent-context/rules/resilience.md +0 -18
  75. package/.agent-context/rules/security.md +0 -18
  76. package/.agent-context/rules/testing.md +0 -16
  77. package/.agent-context/state/README.md +0 -25
  78. package/.agent-context/state/architecture-map.md +0 -40
  79. package/.agent-context/state/benchmark-comparison-schema.json +0 -181
  80. package/.agent-context/state/benchmark-reproducibility.json +0 -87
  81. package/.agent-context/state/benchmark-thresholds.json +0 -10
  82. package/.agent-context/state/benchmark-writer-judge-config.json +0 -58
  83. package/.agent-context/state/dependency-map.md +0 -41
  84. package/.agent-context/state/memory-adapter-contract.json +0 -52
  85. package/.agent-context/state/memory-schema-v1.json +0 -88
  86. package/GEMINI.md +0 -1
  87. package/benchmarks/README.md +0 -60
  88. package/benchmarks/compact-natural-mode/fixtures.mjs +0 -359
  89. package/benchmarks/compact-natural-mode/scorer.mjs +0 -331
  90. package/benchmarks/runtime-token-saver/fixtures.mjs +0 -836
  91. package/lib/cli/adaptive-context/catalog.mjs +0 -394
  92. package/lib/cli/adaptive-context/file-signals.mjs +0 -100
  93. package/lib/cli/adaptive-context/implications.mjs +0 -44
  94. package/lib/cli/adaptive-context.mjs +0 -151
  95. package/lib/cli/audits/typography-palette-anti-repeat/color-utils.mjs +0 -156
  96. package/lib/cli/audits/typography-palette-anti-repeat/file-scanner.mjs +0 -103
  97. package/lib/cli/audits/typography-palette-anti-repeat/typography-utils.mjs +0 -70
  98. package/lib/cli/backup.mjs +0 -210
  99. package/lib/cli/commands/context.mjs +0 -140
  100. package/lib/cli/commands/init/project-context.mjs +0 -60
  101. package/lib/cli/commands/init/runtime-environment.mjs +0 -59
  102. package/lib/cli/commands/init/setup-decisions.mjs +0 -83
  103. package/lib/cli/commands/init.mjs +0 -654
  104. package/lib/cli/commands/launch.mjs +0 -76
  105. package/lib/cli/commands/optimize.mjs +0 -284
  106. package/lib/cli/commands/rollback.mjs +0 -64
  107. package/lib/cli/commands/upgrade/token-optimization-state.mjs +0 -51
  108. package/lib/cli/commands/upgrade.mjs +0 -451
  109. package/lib/cli/compiler.mjs +0 -187
  110. package/lib/cli/constants.mjs +0 -136
  111. package/lib/cli/detector/constants.mjs +0 -135
  112. package/lib/cli/detector/design-evidence/collector.mjs +0 -256
  113. package/lib/cli/detector/design-evidence/constants.mjs +0 -39
  114. package/lib/cli/detector/design-evidence/file-traversal.mjs +0 -83
  115. package/lib/cli/detector/design-evidence/structured-attribute-evidence.mjs +0 -117
  116. package/lib/cli/detector/design-evidence/summary.mjs +0 -109
  117. package/lib/cli/detector/design-evidence/utility-helpers.mjs +0 -122
  118. package/lib/cli/detector/design-evidence.mjs +0 -25
  119. package/lib/cli/detector/stack-detection.mjs +0 -243
  120. package/lib/cli/detector/ui-signals.mjs +0 -150
  121. package/lib/cli/detector/workspace-scan.mjs +0 -177
  122. package/lib/cli/detector.mjs +0 -23
  123. package/lib/cli/init-detection-flow.mjs +0 -48
  124. package/lib/cli/init-options.mjs +0 -237
  125. package/lib/cli/init-selection.mjs +0 -29
  126. package/lib/cli/memory-continuity.mjs +0 -537
  127. package/lib/cli/preflight.mjs +0 -76
  128. package/lib/cli/project-scaffolder/constants.mjs +0 -69
  129. package/lib/cli/project-scaffolder/discovery.mjs +0 -272
  130. package/lib/cli/project-scaffolder/prompt-builders.mjs +0 -171
  131. package/lib/cli/project-scaffolder/storage.mjs +0 -144
  132. package/lib/cli/project-scaffolder/ui-scope-detection.mjs +0 -36
  133. package/lib/cli/project-scaffolder.mjs +0 -29
  134. package/lib/cli/rollback.mjs +0 -66
  135. package/lib/cli/token-optimization.mjs +0 -401
  136. package/lib/cli/utils/filesystem.mjs +0 -81
  137. package/lib/cli/utils/managed-surface.mjs +0 -280
  138. package/lib/cli/utils/prompting.mjs +0 -44
  139. package/lib/cli/utils.mjs +0 -479
  140. package/mcp.json +0 -134
  141. package/scripts/adaptive-context/fixtures.mjs +0 -183
  142. package/scripts/adaptive-context-benchmark.mjs +0 -9
  143. package/scripts/ascx-runtime-token-saver-benchmark.mjs +0 -9
  144. package/scripts/benchmark-evidence-bundle.mjs +0 -645
  145. package/scripts/benchmark-gate.mjs +0 -121
  146. package/scripts/benchmark-intelligence.mjs +0 -33
  147. package/scripts/benchmark-writer-judge-matrix.mjs +0 -379
  148. package/scripts/build-release-benchmark-bundle.mjs +0 -202
  149. package/scripts/bump-version.mjs +0 -103
  150. package/scripts/clean-local-artifacts.mjs +0 -78
  151. package/scripts/compact-natural-mode-benchmark.mjs +0 -9
  152. package/scripts/context-triggered-audit.mjs +0 -391
  153. package/scripts/detection-benchmark.mjs +0 -127
  154. package/scripts/docs-quality-drift-report.mjs +0 -358
  155. package/scripts/documentation-boundary-audit.mjs +0 -305
  156. package/scripts/explain-on-demand-audit.mjs +0 -427
  157. package/scripts/forbidden-content-check.mjs +0 -123
  158. package/scripts/frontend-usability-audit.mjs +0 -243
  159. package/scripts/generate-sbom.mjs +0 -61
  160. package/scripts/governance-weekly-report.mjs +0 -466
  161. package/scripts/llm-judge/checklist-loader.mjs +0 -45
  162. package/scripts/llm-judge/constants.mjs +0 -66
  163. package/scripts/llm-judge/diff-collection.mjs +0 -74
  164. package/scripts/llm-judge/prompting.mjs +0 -78
  165. package/scripts/llm-judge/providers.mjs +0 -111
  166. package/scripts/llm-judge/verdict.mjs +0 -134
  167. package/scripts/llm-judge.mjs +0 -200
  168. package/scripts/memory-continuity-benchmark.mjs +0 -322
  169. package/scripts/quality-trend-report.mjs +0 -289
  170. package/scripts/release-gate/audit-checks.mjs +0 -441
  171. package/scripts/release-gate/constants.mjs +0 -53
  172. package/scripts/release-gate/runtime.mjs +0 -63
  173. package/scripts/release-gate/static-checks.mjs +0 -182
  174. package/scripts/release-gate.mjs +0 -42
  175. package/scripts/rules-guardian-audit.mjs +0 -580
  176. package/scripts/single-source-lazy-loading-audit.mjs +0 -449
  177. package/scripts/sync-thin-adapters.mjs +0 -72
  178. package/scripts/token-optimization-benchmark.mjs +0 -252
  179. package/scripts/ui-design-judge/constants.mjs +0 -13
  180. package/scripts/ui-design-judge/design-execution-summary.mjs +0 -81
  181. package/scripts/ui-design-judge/git-input.mjs +0 -134
  182. package/scripts/ui-design-judge/prompting.mjs +0 -52
  183. package/scripts/ui-design-judge/providers.mjs +0 -102
  184. package/scripts/ui-design-judge/reporting.mjs +0 -183
  185. package/scripts/ui-design-judge/rubric-calibration.mjs +0 -214
  186. package/scripts/ui-design-judge/rubric-goldset.json +0 -188
  187. package/scripts/ui-design-judge.mjs +0 -319
  188. package/scripts/ui-rubric-calibration.mjs +0 -35
  189. package/scripts/validate/audits/cache-layer-contract.mjs +0 -230
  190. package/scripts/validate/audits/caching-scope-hygiene.mjs +0 -235
  191. package/scripts/validate/audits/file-size.mjs +0 -158
  192. package/scripts/validate/audits/reflection-citations.mjs +0 -130
  193. package/scripts/validate/audits/release-bundle.mjs +0 -135
  194. package/scripts/validate/audits/rule-id-uniqueness.mjs +0 -278
  195. package/scripts/validate/config.mjs +0 -501
  196. package/scripts/validate/coverage-checks.mjs +0 -446
  197. package/scripts/validate/file-structure.mjs +0 -158
  198. package/scripts/validate/markdown-content.mjs +0 -109
  199. package/scripts/validate/project-metadata.mjs +0 -166
  200. package/scripts/validate/utils.mjs +0 -52
  201. package/scripts/validate.mjs +0 -267
@@ -1,580 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // @file-size-exception: Pre-existing audit script (sequential rules-guardian checks); planned for split in Phase 1.
4
- /**
5
- * rules-guardian-audit.mjs
6
- *
7
- * Cross-session consistency audit for architecture direction.
8
- * Ensures session handoff contains an active architecture contract summary,
9
- * detects direction drift, and requires explicit user confirmation before
10
- * direction changes are applied.
11
- */
12
-
13
- import { existsSync, readFileSync } from 'node:fs';
14
- import { execFileSync } from 'node:child_process';
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 ONBOARDING_REPORT_PATH = '.agent-context/state/onboarding-report.json';
23
- const ARCHITECTURE_RULE_PATH = '.agent-context/rules/architecture.md';
24
- const PR_CHECKLIST_PATH = '.agent-context/review-checklists/pr-checklist.md';
25
- const REVIEW_PROMPT_PATH = '.agent-context/prompts/review-code.md';
26
-
27
- const DEFAULT_WORKFLOW = 'standard';
28
- const SUPPORTED_WORKFLOWS = new Set([
29
- 'auto',
30
- 'standard',
31
- 'review-request',
32
- 'pr-preparation',
33
- 'session-handoff',
34
- 'direction-change',
35
- ]);
36
-
37
- const CORE_PATTERN_SIGNALS = [
38
- {
39
- pattern: 'layer-separation',
40
- snippet: '## ARCH-009: Layer Boundaries (Mandatory)',
41
- },
42
- {
43
- pattern: 'agent-decides-topology',
44
- snippet: 'Do not force a default architecture label before the repo, delivery model, and boundary evidence are clear.',
45
- },
46
- {
47
- pattern: 'feature-based-grouping',
48
- snippet: 'Group code by feature or domain',
49
- },
50
- {
51
- pattern: 'rules-as-guardian-cross-session',
52
- snippet: 'Rules as Guardian (Cross-Session Consistency)',
53
- },
54
- ];
55
-
56
- const REQUIRED_ARCHITECTURE_RULE_SNIPPETS = [
57
- '## ARCH-005: Rules as Guardian (Cross-Session Consistency)',
58
- 'Session handoff must include active architecture contract summary.',
59
- 'Detect drift before changing runtime choices, topology, public contracts, or core patterns.',
60
- 'Direction changes require explicit user confirmation before applying changes.',
61
- ];
62
-
63
- const REQUIRED_PR_CHECKLIST_SNIPPETS = [
64
- 'Session handoff includes active architecture contract summary',
65
- 'Drift detection warns before direction changes',
66
- 'Direction changes require explicit user confirmation',
67
- ];
68
-
69
- const REQUIRED_REVIEW_PROMPT_SNIPPETS = [
70
- 'Review the code with a production-risk mindset.',
71
- 'Do not create stack-specific governance concerns.',
72
- ];
73
-
74
- function pushResult(results, isPassed, checkName, details) {
75
- results.push({
76
- checkName,
77
- passed: isPassed,
78
- details,
79
- });
80
- }
81
-
82
- function normalizeFilePath(filePath) {
83
- return filePath.replace(/\\/g, '/').replace(/^\.\//, '');
84
- }
85
-
86
- function parseGitFileList(rawOutput) {
87
- if (typeof rawOutput !== 'string' || rawOutput.trim().length === 0) {
88
- return [];
89
- }
90
-
91
- return rawOutput
92
- .split(/\r?\n/)
93
- .map((filePath) => filePath.trim())
94
- .filter((filePath) => filePath.length > 0)
95
- .map(normalizeFilePath);
96
- }
97
-
98
- function runGitFileQuery(commandArguments) {
99
- try {
100
- const rawOutput = execFileSync('git', commandArguments, {
101
- cwd: REPOSITORY_ROOT,
102
- encoding: 'utf8',
103
- maxBuffer: 1024 * 1024,
104
- stdio: ['ignore', 'pipe', 'ignore'],
105
- });
106
-
107
- return parseGitFileList(rawOutput);
108
- } catch {
109
- return [];
110
- }
111
- }
112
-
113
- function runGitRawQuery(commandArguments) {
114
- try {
115
- return execFileSync('git', commandArguments, {
116
- cwd: REPOSITORY_ROOT,
117
- encoding: 'utf8',
118
- maxBuffer: 1024 * 1024,
119
- stdio: ['ignore', 'pipe', 'ignore'],
120
- });
121
- } catch {
122
- return '';
123
- }
124
- }
125
-
126
- function uniqueSorted(filePaths) {
127
- return Array.from(new Set(filePaths)).sort((leftPath, rightPath) => leftPath.localeCompare(rightPath));
128
- }
129
-
130
- function collectChangedFiles() {
131
- const workingTreeFiles = runGitFileQuery(['diff', '--name-only']);
132
- const stagedFiles = runGitFileQuery(['diff', '--name-only', '--cached']);
133
- const workingScopeFiles = uniqueSorted([...workingTreeFiles, ...stagedFiles]);
134
-
135
- if (workingScopeFiles.length > 0) {
136
- return {
137
- source: 'working-tree-and-index',
138
- files: workingScopeFiles,
139
- };
140
- }
141
-
142
- const latestCommitRangeFiles = runGitFileQuery(['diff', '--name-only', 'HEAD~1..HEAD']);
143
- if (latestCommitRangeFiles.length > 0) {
144
- return {
145
- source: 'latest-commit-range',
146
- files: uniqueSorted(latestCommitRangeFiles),
147
- };
148
- }
149
-
150
- const headCommitFiles = runGitFileQuery(['show', '--pretty=format:', '--name-only', 'HEAD']);
151
- if (headCommitFiles.length > 0) {
152
- return {
153
- source: 'head-commit',
154
- files: uniqueSorted(headCommitFiles),
155
- };
156
- }
157
-
158
- return {
159
- source: 'none',
160
- files: [],
161
- };
162
- }
163
-
164
- function readText(relativeFilePath) {
165
- const absolutePath = resolve(REPOSITORY_ROOT, relativeFilePath);
166
- if (!existsSync(absolutePath)) {
167
- return '';
168
- }
169
-
170
- return readFileSync(absolutePath, 'utf8');
171
- }
172
-
173
- function readPreviousRevisionText(relativeFilePath) {
174
- const rawOutput = runGitRawQuery(['show', `HEAD~1:${relativeFilePath}`]);
175
- return typeof rawOutput === 'string' && rawOutput.length > 0
176
- ? rawOutput
177
- : '';
178
- }
179
-
180
- function parseOnboardingReport(onboardingReportContent) {
181
- if (typeof onboardingReportContent !== 'string' || onboardingReportContent.trim().length === 0) {
182
- return null;
183
- }
184
-
185
- try {
186
- return JSON.parse(onboardingReportContent);
187
- } catch {
188
- return null;
189
- }
190
- }
191
-
192
- function normalizeCorePatterns(corePatterns) {
193
- if (!Array.isArray(corePatterns)) {
194
- return [];
195
- }
196
-
197
- return Array.from(new Set(corePatterns
198
- .map((patternValue) => String(patternValue || '').trim().toLowerCase())
199
- .filter((patternValue) => patternValue.length > 0))).sort((leftValue, rightValue) => (
200
- leftValue.localeCompare(rightValue)
201
- ));
202
- }
203
-
204
- function detectCorePatterns(architectureRuleContent) {
205
- return CORE_PATTERN_SIGNALS
206
- .filter((signalEntry) => architectureRuleContent.includes(signalEntry.snippet))
207
- .map((signalEntry) => signalEntry.pattern);
208
- }
209
-
210
- function parseCliArguments(argumentList) {
211
- let workflow = DEFAULT_WORKFLOW;
212
- let confirmDirectionChange = false;
213
- let proposedStack = '';
214
- let proposedBlueprint = '';
215
- let proposedCorePatterns = [];
216
-
217
- for (let argumentIndex = 0; argumentIndex < argumentList.length; argumentIndex += 1) {
218
- const argumentValue = argumentList[argumentIndex];
219
-
220
- if (argumentValue === '--confirm-direction-change') {
221
- confirmDirectionChange = true;
222
- continue;
223
- }
224
-
225
- if (argumentValue === '--workflow') {
226
- const nextArgumentValue = argumentList[argumentIndex + 1];
227
- if (nextArgumentValue && !nextArgumentValue.startsWith('--')) {
228
- workflow = nextArgumentValue;
229
- argumentIndex += 1;
230
- }
231
- continue;
232
- }
233
-
234
- if (argumentValue.startsWith('--workflow=')) {
235
- workflow = argumentValue.slice('--workflow='.length);
236
- continue;
237
- }
238
-
239
- if (argumentValue === '--proposed-stack') {
240
- const nextArgumentValue = argumentList[argumentIndex + 1];
241
- if (nextArgumentValue && !nextArgumentValue.startsWith('--')) {
242
- proposedStack = nextArgumentValue;
243
- argumentIndex += 1;
244
- }
245
- continue;
246
- }
247
-
248
- if (argumentValue.startsWith('--proposed-stack=')) {
249
- proposedStack = argumentValue.slice('--proposed-stack='.length);
250
- continue;
251
- }
252
-
253
- if (argumentValue === '--proposed-blueprint') {
254
- const nextArgumentValue = argumentList[argumentIndex + 1];
255
- if (nextArgumentValue && !nextArgumentValue.startsWith('--')) {
256
- proposedBlueprint = nextArgumentValue;
257
- argumentIndex += 1;
258
- }
259
- continue;
260
- }
261
-
262
- if (argumentValue.startsWith('--proposed-blueprint=')) {
263
- proposedBlueprint = argumentValue.slice('--proposed-blueprint='.length);
264
- continue;
265
- }
266
-
267
- if (argumentValue === '--proposed-core-patterns') {
268
- const nextArgumentValue = argumentList[argumentIndex + 1];
269
- if (nextArgumentValue && !nextArgumentValue.startsWith('--')) {
270
- proposedCorePatterns = nextArgumentValue.split(',');
271
- argumentIndex += 1;
272
- }
273
- continue;
274
- }
275
-
276
- if (argumentValue.startsWith('--proposed-core-patterns=')) {
277
- proposedCorePatterns = argumentValue.slice('--proposed-core-patterns='.length).split(',');
278
- }
279
- }
280
-
281
- const normalizedWorkflow = String(workflow).trim().toLowerCase() || DEFAULT_WORKFLOW;
282
-
283
- return {
284
- workflow: SUPPORTED_WORKFLOWS.has(normalizedWorkflow) ? normalizedWorkflow : DEFAULT_WORKFLOW,
285
- confirmDirectionChange,
286
- proposedStack: String(proposedStack || '').trim(),
287
- proposedBlueprint: String(proposedBlueprint || '').trim(),
288
- proposedCorePatterns: normalizeCorePatterns(proposedCorePatterns),
289
- };
290
- }
291
-
292
- function parseBooleanFromEnvironment(rawEnvironmentValue) {
293
- const normalizedEnvironmentValue = String(rawEnvironmentValue || '').trim().toLowerCase();
294
- return normalizedEnvironmentValue === '1'
295
- || normalizedEnvironmentValue === 'true'
296
- || normalizedEnvironmentValue === 'yes'
297
- || normalizedEnvironmentValue === 'y';
298
- }
299
-
300
- function buildArchitectureContract(onboardingReport, corePatterns) {
301
- return {
302
- runtimeDecision: String(onboardingReport?.runtimeDecision?.mode || onboardingReport?.selectedStack || 'unknown').trim() || 'unknown',
303
- architectureDecision: String(onboardingReport?.architectureDecision?.mode || onboardingReport?.selectedBlueprint || 'unknown').trim() || 'unknown',
304
- profile: String(onboardingReport?.selectedProfile || 'unknown').trim() || 'unknown',
305
- corePatterns: normalizeCorePatterns(corePatterns),
306
- };
307
- }
308
-
309
- function toComparableContractValue(value) {
310
- if (Array.isArray(value)) {
311
- return normalizeCorePatterns(value).join(',');
312
- }
313
-
314
- return String(value || '').trim();
315
- }
316
-
317
- function detectContractDrift(baseContract, targetContract, driftSource) {
318
- const driftItems = [];
319
- const fieldNames = ['runtimeDecision', 'architectureDecision', 'profile', 'corePatterns'];
320
-
321
- for (const fieldName of fieldNames) {
322
- const baseValue = toComparableContractValue(baseContract?.[fieldName]);
323
- const targetValue = toComparableContractValue(targetContract?.[fieldName]);
324
-
325
- if (baseValue !== targetValue) {
326
- driftItems.push({
327
- field: fieldName,
328
- from: baseValue,
329
- to: targetValue,
330
- source: driftSource,
331
- });
332
- }
333
- }
334
-
335
- return driftItems;
336
- }
337
-
338
- function buildSessionHandoffSummary(architectureContract) {
339
- const corePatternsSummary = architectureContract.corePatterns.length > 0
340
- ? architectureContract.corePatterns.join(', ')
341
- : 'none';
342
-
343
- return `Architecture contract summary: runtimeDecision=${architectureContract.runtimeDecision}, architectureDecision=${architectureContract.architectureDecision}, profile=${architectureContract.profile}, corePatterns=${corePatternsSummary}.`;
344
- }
345
-
346
- function assertSnippetCoverage(sourceLabel, sourcePath, requiredSnippets, failures, results) {
347
- const sourceContent = readText(sourcePath);
348
-
349
- if (!sourceContent) {
350
- failures.push(`Missing ${sourceLabel} source: ${sourcePath}`);
351
- pushResult(results, false, `${sourceLabel}-source-exists`, `Missing ${sourcePath}`);
352
- return;
353
- }
354
-
355
- pushResult(results, true, `${sourceLabel}-source-exists`, `${sourcePath} is present`);
356
-
357
- const missingSnippets = requiredSnippets.filter((requiredSnippet) => !sourceContent.includes(requiredSnippet));
358
-
359
- if (missingSnippets.length > 0) {
360
- failures.push(`Missing ${sourceLabel} snippets: ${missingSnippets.join(', ')}`);
361
- pushResult(
362
- results,
363
- false,
364
- `${sourceLabel}-source-coverage`,
365
- `Missing snippets in ${sourcePath}: ${missingSnippets.join(', ')}`
366
- );
367
- return;
368
- }
369
-
370
- pushResult(results, true, `${sourceLabel}-source-coverage`, `${sourceLabel} snippets are complete`);
371
- }
372
-
373
- function runAudit() {
374
- const parsedArguments = parseCliArguments(process.argv.slice(2));
375
- const changedScope = collectChangedFiles();
376
- const changedFiles = changedScope.files;
377
- const results = [];
378
- const failures = [];
379
- const warnings = [];
380
-
381
- const envConfirmationFlag = parseBooleanFromEnvironment(process.env.RULES_GUARDIAN_CONFIRM_DIRECTION_CHANGE);
382
- const confirmationProvided = parsedArguments.confirmDirectionChange || envConfirmationFlag;
383
- const confirmationSource = parsedArguments.confirmDirectionChange
384
- ? 'cli-flag'
385
- : (envConfirmationFlag ? 'environment-variable' : 'none');
386
-
387
- pushResult(results, true, 'context-workflow', `workflow=${parsedArguments.workflow}`);
388
- pushResult(
389
- results,
390
- true,
391
- 'direction-change-confirmation-flag',
392
- confirmationProvided
393
- ? `Explicit direction-change confirmation provided via ${confirmationSource}`
394
- : 'Explicit direction-change confirmation not provided'
395
- );
396
-
397
- assertSnippetCoverage(
398
- 'rules-guardian-architecture-rule',
399
- ARCHITECTURE_RULE_PATH,
400
- REQUIRED_ARCHITECTURE_RULE_SNIPPETS,
401
- failures,
402
- results
403
- );
404
-
405
- assertSnippetCoverage(
406
- 'rules-guardian-pr-checklist',
407
- PR_CHECKLIST_PATH,
408
- REQUIRED_PR_CHECKLIST_SNIPPETS,
409
- failures,
410
- results
411
- );
412
-
413
- assertSnippetCoverage(
414
- 'rules-guardian-review-prompt',
415
- REVIEW_PROMPT_PATH,
416
- REQUIRED_REVIEW_PROMPT_SNIPPETS,
417
- failures,
418
- results
419
- );
420
-
421
- const onboardingReportContent = readText(ONBOARDING_REPORT_PATH);
422
- const onboardingReport = parseOnboardingReport(onboardingReportContent);
423
-
424
- if (!onboardingReportContent) {
425
- failures.push(`Missing architecture contract source: ${ONBOARDING_REPORT_PATH}`);
426
- pushResult(results, false, 'architecture-contract-source', `Missing ${ONBOARDING_REPORT_PATH}`);
427
- } else if (!onboardingReport) {
428
- failures.push(`Cannot parse architecture contract source: ${ONBOARDING_REPORT_PATH}`);
429
- pushResult(results, false, 'architecture-contract-source', `Invalid JSON in ${ONBOARDING_REPORT_PATH}`);
430
- } else {
431
- pushResult(results, true, 'architecture-contract-source', `${ONBOARDING_REPORT_PATH} is present and valid`);
432
- }
433
-
434
- const architectureRuleContent = readText(ARCHITECTURE_RULE_PATH);
435
- const activeCorePatterns = detectCorePatterns(architectureRuleContent);
436
-
437
- if (activeCorePatterns.length === 0) {
438
- failures.push('Cannot resolve active core patterns from architecture rule snippets');
439
- pushResult(
440
- results,
441
- false,
442
- 'architecture-core-patterns',
443
- `No core pattern signals detected in ${ARCHITECTURE_RULE_PATH}`
444
- );
445
- } else {
446
- pushResult(
447
- results,
448
- true,
449
- 'architecture-core-patterns',
450
- `Resolved ${activeCorePatterns.length} core pattern signals: ${activeCorePatterns.join(', ')}`
451
- );
452
- }
453
-
454
- const activeContract = buildArchitectureContract(onboardingReport, activeCorePatterns);
455
- const sessionHandoffSummary = buildSessionHandoffSummary(activeContract);
456
- const sessionHandoffIncluded = sessionHandoffSummary.trim().length > 0;
457
-
458
- if (sessionHandoffIncluded) {
459
- pushResult(results, true, 'session-handoff-contract-summary', sessionHandoffSummary);
460
- } else {
461
- failures.push('Session handoff summary is missing');
462
- pushResult(results, false, 'session-handoff-contract-summary', 'Session handoff summary is empty');
463
- }
464
-
465
- const previousOnboardingReport = parseOnboardingReport(readPreviousRevisionText(ONBOARDING_REPORT_PATH));
466
- const previousArchitectureRuleContent = readPreviousRevisionText(ARCHITECTURE_RULE_PATH) || architectureRuleContent;
467
- const previousCorePatterns = detectCorePatterns(previousArchitectureRuleContent);
468
-
469
- const previousContract = buildArchitectureContract(
470
- previousOnboardingReport || onboardingReport,
471
- previousCorePatterns.length > 0 ? previousCorePatterns : activeCorePatterns
472
- );
473
-
474
- const proposedContract = {
475
- runtimeDecision: parsedArguments.proposedStack || activeContract.runtimeDecision,
476
- architectureDecision: parsedArguments.proposedBlueprint || activeContract.architectureDecision,
477
- profile: activeContract.profile,
478
- corePatterns: parsedArguments.proposedCorePatterns.length > 0
479
- ? parsedArguments.proposedCorePatterns
480
- : activeContract.corePatterns,
481
- };
482
-
483
- const persistedContractDrift = detectContractDrift(
484
- previousContract,
485
- activeContract,
486
- 'persisted-change-since-previous-session'
487
- );
488
- const proposedContractDrift = detectContractDrift(
489
- activeContract,
490
- proposedContract,
491
- 'proposed-direction-change'
492
- );
493
-
494
- const driftItems = [...persistedContractDrift, ...proposedContractDrift];
495
- const persistedDriftDetected = persistedContractDrift.length > 0;
496
- const proposedDirectionChangeDetected = proposedContractDrift.length > 0;
497
- const driftDetected = driftItems.length > 0;
498
-
499
- if (driftDetected) {
500
- const driftSummary = driftItems
501
- .map((driftItem) => `${driftItem.field}: ${driftItem.from} -> ${driftItem.to} (${driftItem.source})`)
502
- .join('; ');
503
- warnings.push(`Direction drift detected: ${driftSummary}`);
504
- pushResult(results, true, 'direction-drift-detection', `Drift detected: ${driftSummary}`);
505
- } else {
506
- pushResult(results, true, 'direction-drift-detection', 'No direction drift detected');
507
- }
508
-
509
- if (proposedDirectionChangeDetected && !confirmationProvided) {
510
- failures.push('Direction change detected without explicit user confirmation');
511
- pushResult(
512
- results,
513
- false,
514
- 'direction-change-explicit-confirmation',
515
- 'Direction change detected. Re-run with --confirm-direction-change (or set RULES_GUARDIAN_CONFIRM_DIRECTION_CHANGE=true) after explicit user approval.'
516
- );
517
- } else if (proposedDirectionChangeDetected && confirmationProvided) {
518
- pushResult(
519
- results,
520
- true,
521
- 'direction-change-explicit-confirmation',
522
- `Direction change confirmed explicitly via ${confirmationSource}`
523
- );
524
- } else if (persistedDriftDetected) {
525
- pushResult(
526
- results,
527
- true,
528
- 'direction-change-explicit-confirmation',
529
- 'Persisted drift detected from previous session; explicit confirmation is required only for new proposed direction changes'
530
- );
531
- } else {
532
- pushResult(
533
- results,
534
- true,
535
- 'direction-change-explicit-confirmation',
536
- 'No direction change detected; explicit confirmation not required'
537
- );
538
- }
539
-
540
- const reportPayload = {
541
- generatedAt: new Date().toISOString(),
542
- auditName: 'rules-guardian-audit',
543
- workflow: parsedArguments.workflow,
544
- source: changedScope.source,
545
- changedFileCount: changedFiles.length,
546
- changedFiles,
547
- confirmationPolicy: {
548
- requiresExplicitUserConfirmation: true,
549
- requiredForProposedDirectionChange: true,
550
- confirmationProvided,
551
- confirmationSource,
552
- },
553
- sessionHandoff: {
554
- included: sessionHandoffIncluded,
555
- contractSummary: sessionHandoffSummary,
556
- activeArchitectureContract: activeContract,
557
- previousArchitectureContract: previousContract,
558
- proposedArchitectureContract: proposedContract,
559
- },
560
- driftDetection: {
561
- driftDetected,
562
- persistedDriftDetected,
563
- proposedDirectionChangeDetected,
564
- driftItemCount: driftItems.length,
565
- persistedDriftItemCount: persistedContractDrift.length,
566
- proposedDriftItemCount: proposedContractDrift.length,
567
- driftItems,
568
- },
569
- passed: failures.length === 0,
570
- failureCount: failures.length,
571
- failures,
572
- warnings,
573
- results,
574
- };
575
-
576
- console.log(JSON.stringify(reportPayload, null, 2));
577
- process.exit(reportPayload.passed ? 0 : 1);
578
- }
579
-
580
- runAudit();