@ryuenn3123/agentic-senior-core 2.0.5 → 2.0.8

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 (126) hide show
  1. package/.agent-context/blueprints/mobile-app.md +91 -21
  2. package/.agent-context/profiles/platform.md +13 -13
  3. package/.agent-context/profiles/regulated.md +13 -13
  4. package/.agent-context/profiles/startup.md +13 -13
  5. package/.agent-context/prompts/review-code.md +3 -3
  6. package/.agent-context/review-checklists/frontend-skill-parity.md +28 -28
  7. package/.agent-context/review-checklists/frontend-usability.md +33 -33
  8. package/.agent-context/review-checklists/pr-checklist.md +11 -6
  9. package/.agent-context/review-checklists/release-operations.md +29 -29
  10. package/.agent-context/rules/api-docs.md +34 -0
  11. package/.agent-context/skills/README.md +62 -62
  12. package/.agent-context/skills/backend/README.md +67 -67
  13. package/.agent-context/skills/backend/architecture.md +360 -360
  14. package/.agent-context/skills/backend/compatibility-manifest.json +8 -8
  15. package/.agent-context/skills/backend/data-access.md +230 -230
  16. package/.agent-context/skills/backend/errors.md +137 -137
  17. package/.agent-context/skills/backend/validation.md +116 -116
  18. package/.agent-context/skills/backend.md +28 -28
  19. package/.agent-context/skills/cli/README.md +55 -49
  20. package/.agent-context/skills/cli/compatibility-manifest.json +8 -8
  21. package/.agent-context/skills/cli/init.md +37 -37
  22. package/.agent-context/skills/cli/output.md +35 -35
  23. package/.agent-context/skills/cli/safety-telemetry.md +39 -0
  24. package/.agent-context/skills/cli/upgrade.md +37 -37
  25. package/.agent-context/skills/cli.md +31 -28
  26. package/.agent-context/skills/distribution/.evidence/compatibility-manifest.json +9 -0
  27. package/.agent-context/skills/distribution/.evidence/sbom-excerpt.json +6 -0
  28. package/.agent-context/skills/distribution/.evidence/test-report.json +8 -0
  29. package/.agent-context/skills/distribution/CHANGELOG.md +7 -0
  30. package/.agent-context/skills/distribution/README.md +27 -19
  31. package/.agent-context/skills/distribution/compatibility-manifest.json +8 -8
  32. package/.agent-context/skills/distribution/compatibility.md +31 -31
  33. package/.agent-context/skills/distribution/package.json +5 -0
  34. package/.agent-context/skills/distribution/provenance-attestation.md +47 -0
  35. package/.agent-context/skills/distribution/publish.md +36 -36
  36. package/.agent-context/skills/distribution/rollback.md +31 -31
  37. package/.agent-context/skills/distribution/tests/.gitkeep +1 -0
  38. package/.agent-context/skills/distribution.md +31 -28
  39. package/.agent-context/skills/frontend/.evidence/compatibility-manifest.json +9 -0
  40. package/.agent-context/skills/frontend/.evidence/sbom-excerpt.json +6 -0
  41. package/.agent-context/skills/frontend/.evidence/test-report.json +8 -0
  42. package/.agent-context/skills/frontend/CHANGELOG.md +7 -0
  43. package/.agent-context/skills/frontend/README.md +49 -36
  44. package/.agent-context/skills/frontend/accessibility.md +107 -107
  45. package/.agent-context/skills/frontend/compatibility-manifest.json +8 -8
  46. package/.agent-context/skills/frontend/conversion-clarity.md +51 -0
  47. package/.agent-context/skills/frontend/motion.md +66 -66
  48. package/.agent-context/skills/frontend/package.json +5 -0
  49. package/.agent-context/skills/frontend/performance.md +62 -62
  50. package/.agent-context/skills/frontend/responsive-delivery.md +41 -0
  51. package/.agent-context/skills/frontend/tests/.gitkeep +1 -0
  52. package/.agent-context/skills/frontend/ui-architecture.md +128 -128
  53. package/.agent-context/skills/frontend.md +35 -29
  54. package/.agent-context/skills/fullstack/.evidence/compatibility-manifest.json +9 -0
  55. package/.agent-context/skills/fullstack/.evidence/sbom-excerpt.json +6 -0
  56. package/.agent-context/skills/fullstack/.evidence/test-report.json +8 -0
  57. package/.agent-context/skills/fullstack/CHANGELOG.md +7 -0
  58. package/.agent-context/skills/fullstack/README.md +27 -19
  59. package/.agent-context/skills/fullstack/compatibility-manifest.json +8 -8
  60. package/.agent-context/skills/fullstack/contracts.md +52 -52
  61. package/.agent-context/skills/fullstack/end-to-end.md +41 -41
  62. package/.agent-context/skills/fullstack/feature-slicing.md +64 -64
  63. package/.agent-context/skills/fullstack/package.json +5 -0
  64. package/.agent-context/skills/fullstack/release-coordination.md +51 -0
  65. package/.agent-context/skills/fullstack/tests/.gitkeep +1 -0
  66. package/.agent-context/skills/fullstack.md +29 -26
  67. package/.agent-context/skills/index.json +107 -107
  68. package/.agent-context/skills/review-quality/.evidence/compatibility-manifest.json +9 -0
  69. package/.agent-context/skills/review-quality/.evidence/sbom-excerpt.json +6 -0
  70. package/.agent-context/skills/review-quality/.evidence/test-report.json +8 -0
  71. package/.agent-context/skills/review-quality/CHANGELOG.md +7 -0
  72. package/.agent-context/skills/review-quality/README.md +27 -19
  73. package/.agent-context/skills/review-quality/benchmark.md +29 -29
  74. package/.agent-context/skills/review-quality/compatibility-manifest.json +8 -8
  75. package/.agent-context/skills/review-quality/package.json +5 -0
  76. package/.agent-context/skills/review-quality/planning.md +37 -37
  77. package/.agent-context/skills/review-quality/release-decision.md +49 -0
  78. package/.agent-context/skills/review-quality/security.md +33 -33
  79. package/.agent-context/skills/review-quality/tests/.gitkeep +1 -0
  80. package/.agent-context/skills/review-quality.md +33 -27
  81. package/.agent-context/stacks/flutter.md +16 -16
  82. package/.agent-context/stacks/react-native.md +16 -16
  83. package/.agent-context/state/architecture-map.md +25 -25
  84. package/.agent-context/state/benchmark-analysis.json +431 -431
  85. package/.agent-context/state/benchmark-thresholds.json +10 -10
  86. package/.agent-context/state/benchmark-watchlist.json +19 -19
  87. package/.agent-context/state/dependency-map.md +32 -32
  88. package/.agent-context/state/quality-trend-report.json +16 -6
  89. package/.agent-context/state/skill-platform.json +38 -38
  90. package/.agent-context/state/weekly-governance-report.json +126 -0
  91. package/.agent-override.md +36 -36
  92. package/.cursorrules +1 -1
  93. package/.gemini/instructions.md +20 -20
  94. package/.github/ISSUE_TEMPLATE/v1.7-frontend-work-item.yml +54 -54
  95. package/.github/copilot-instructions.md +21 -21
  96. package/.github/workflows/benchmark-detection.yml +38 -38
  97. package/.github/workflows/benchmark-intelligence.yml +50 -50
  98. package/.github/workflows/frontend-usability-gate.yml +36 -36
  99. package/.github/workflows/governance-weekly-report.yml +43 -0
  100. package/.github/workflows/release-gate.yml +32 -32
  101. package/.github/workflows/sbom-compliance.yml +32 -32
  102. package/.windsurfrules +1 -1
  103. package/AGENTS.md +27 -27
  104. package/README.md +389 -368
  105. package/lib/cli/commands/init.mjs +13 -1
  106. package/lib/cli/commands/optimize.mjs +171 -171
  107. package/lib/cli/commands/upgrade.mjs +9 -1
  108. package/lib/cli/compatibility.mjs +124 -124
  109. package/lib/cli/constants.mjs +37 -2
  110. package/lib/cli/token-optimization.mjs +275 -275
  111. package/lib/cli/utils.mjs +24 -3
  112. package/mcp.json +92 -92
  113. package/package.json +2 -1
  114. package/scripts/benchmark-gate.mjs +121 -121
  115. package/scripts/benchmark-intelligence.mjs +140 -140
  116. package/scripts/detection-benchmark.mjs +138 -138
  117. package/scripts/frontend-usability-audit.mjs +87 -87
  118. package/scripts/generate-sbom.mjs +61 -61
  119. package/scripts/governance-weekly-report.mjs +293 -0
  120. package/scripts/init-project.ps1 +104 -104
  121. package/scripts/llm-judge.mjs +664 -664
  122. package/scripts/quality-trend-report.mjs +288 -288
  123. package/scripts/release-gate.mjs +261 -259
  124. package/scripts/skill-tier-policy.mjs +75 -75
  125. package/scripts/token-optimization-benchmark.mjs +252 -252
  126. package/scripts/validate.mjs +942 -865
@@ -1,289 +1,289 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * quality-trend-report.mjs
5
- *
6
- * Generates a machine-readable quality trend artifact that summarizes
7
- * governance gate pass rates, rejection categories, rollback frequency,
8
- * and token-efficiency signals.
9
- */
10
-
11
- import { existsSync, readFileSync } from 'node:fs';
12
- import fs from 'node:fs/promises';
13
- import { spawnSync } from 'node:child_process';
14
- import { dirname, join, resolve } from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
-
17
- const SCRIPT_FILE_PATH = fileURLToPath(import.meta.url);
18
- const SCRIPT_DIR = dirname(SCRIPT_FILE_PATH);
19
- const REPOSITORY_ROOT = resolve(SCRIPT_DIR, '..');
20
- const REPORT_PATH = join(REPOSITORY_ROOT, '.agent-context', 'state', 'quality-trend-report.json');
21
- const TOKEN_BENCHMARK_PATH = join(REPOSITORY_ROOT, '.agent-context', 'state', 'token-optimization-benchmark.json');
22
- const ARGUMENT_FLAGS = new Set(process.argv.slice(2));
23
- const isStdoutOnlyMode = ARGUMENT_FLAGS.has('--stdout-only');
24
- const MAX_SNAPSHOT_HISTORY = 30;
25
- const ROLLBACK_WINDOW_DAYS = 30;
26
-
27
- function runJsonScript(scriptRelativePath) {
28
- const absoluteScriptPath = join(REPOSITORY_ROOT, scriptRelativePath);
29
- const commandResult = spawnSync('node', [absoluteScriptPath], {
30
- cwd: REPOSITORY_ROOT,
31
- encoding: 'utf8',
32
- maxBuffer: 1024 * 1024 * 10,
33
- });
34
-
35
- const standardOutput = (commandResult.stdout || '').trim();
36
- const standardError = (commandResult.stderr || '').trim();
37
- const exitCode = typeof commandResult.status === 'number' ? commandResult.status : 1;
38
-
39
- if (!standardOutput) {
40
- return {
41
- scriptPath: scriptRelativePath,
42
- exitCode,
43
- parsedReport: null,
44
- parseError: 'Script produced no stdout JSON payload',
45
- stderr: standardError,
46
- };
47
- }
48
-
49
- try {
50
- const parsedReport = JSON.parse(standardOutput);
51
- return {
52
- scriptPath: scriptRelativePath,
53
- exitCode,
54
- parsedReport,
55
- parseError: null,
56
- stderr: standardError,
57
- };
58
- } catch (jsonParseError) {
59
- const errorMessage = jsonParseError instanceof Error ? jsonParseError.message : String(jsonParseError);
60
- return {
61
- scriptPath: scriptRelativePath,
62
- exitCode,
63
- parsedReport: null,
64
- parseError: errorMessage,
65
- stderr: standardError,
66
- };
67
- }
68
- }
69
-
70
- function readJsonFileOrNull(filePath) {
71
- if (!existsSync(filePath)) {
72
- return null;
73
- }
74
-
75
- try {
76
- return JSON.parse(readFileSync(filePath, 'utf8'));
77
- } catch {
78
- return null;
79
- }
80
- }
81
-
82
- function summarizeGateExecution(gateExecutionResults) {
83
- const gateSummaries = gateExecutionResults.map((gateExecutionResult) => {
84
- const gateReport = gateExecutionResult.parsedReport;
85
- return {
86
- scriptPath: gateExecutionResult.scriptPath,
87
- gateName: gateReport?.gateName || gateReport?.reportName || gateExecutionResult.scriptPath,
88
- exitCode: gateExecutionResult.exitCode,
89
- passed: typeof gateReport?.passed === 'boolean' ? gateReport.passed : false,
90
- parseError: gateExecutionResult.parseError,
91
- failureCount: typeof gateReport?.failureCount === 'number' ? gateReport.failureCount : null,
92
- generatedAt: gateReport?.generatedAt || null,
93
- };
94
- });
95
-
96
- const availableGateCount = gateSummaries.length;
97
- const passedGateCount = gateSummaries.filter((gateSummary) => gateSummary.passed).length;
98
- const gatePassRatePercent = availableGateCount === 0
99
- ? 0
100
- : Number(((passedGateCount / availableGateCount) * 100).toFixed(2));
101
-
102
- return {
103
- gateSummaries,
104
- availableGateCount,
105
- passedGateCount,
106
- gatePassRatePercent,
107
- };
108
- }
109
-
110
- function collectRejectionCategories(gateExecutionResults) {
111
- const rejectionCategoryMap = new Map();
112
-
113
- for (const gateExecutionResult of gateExecutionResults) {
114
- const gateReport = gateExecutionResult.parsedReport;
115
- const gateName = gateReport?.gateName || gateReport?.reportName || gateExecutionResult.scriptPath;
116
- const gateResults = Array.isArray(gateReport?.results) ? gateReport.results : [];
117
-
118
- for (const checkResult of gateResults) {
119
- if (checkResult?.passed === true) {
120
- continue;
121
- }
122
-
123
- const checkName = typeof checkResult?.checkName === 'string' ? checkResult.checkName : 'unknown-check';
124
- const existingCategory = rejectionCategoryMap.get(checkName) || {
125
- checkName,
126
- count: 0,
127
- gates: new Set(),
128
- };
129
-
130
- existingCategory.count += 1;
131
- existingCategory.gates.add(gateName);
132
- rejectionCategoryMap.set(checkName, existingCategory);
133
- }
134
- }
135
-
136
- return Array.from(rejectionCategoryMap.values())
137
- .map((rejectionCategory) => ({
138
- checkName: rejectionCategory.checkName,
139
- count: rejectionCategory.count,
140
- gates: Array.from(rejectionCategory.gates),
141
- }))
142
- .sort((firstCategory, secondCategory) => secondCategory.count - firstCategory.count);
143
- }
144
-
145
- function calculateRollbackFrequencySnapshot() {
146
- const gitLogResult = spawnSync('git', ['log', `--since=${ROLLBACK_WINDOW_DAYS}.days`, '--pretty=format:%s'], {
147
- cwd: REPOSITORY_ROOT,
148
- encoding: 'utf8',
149
- maxBuffer: 1024 * 1024,
150
- });
151
-
152
- if (gitLogResult.status !== 0) {
153
- return {
154
- windowDays: ROLLBACK_WINDOW_DAYS,
155
- commitCount: 0,
156
- rollbackCommitCount: 0,
157
- rollbackFrequencyPercent: null,
158
- source: 'git-log',
159
- error: (gitLogResult.stderr || 'Failed to read git log').trim(),
160
- };
161
- }
162
-
163
- const commitSubjects = (gitLogResult.stdout || '')
164
- .split(/\r?\n/u)
165
- .map((subjectLine) => subjectLine.trim())
166
- .filter((subjectLine) => subjectLine.length > 0);
167
-
168
- const rollbackCommitCount = commitSubjects.filter((subjectLine) => /rollback/i.test(subjectLine)).length;
169
- const commitCount = commitSubjects.length;
170
- const rollbackFrequencyPercent = commitCount === 0
171
- ? 0
172
- : Number(((rollbackCommitCount / commitCount) * 100).toFixed(2));
173
-
174
- return {
175
- windowDays: ROLLBACK_WINDOW_DAYS,
176
- commitCount,
177
- rollbackCommitCount,
178
- rollbackFrequencyPercent,
179
- source: 'git-log',
180
- error: null,
181
- };
182
- }
183
-
184
- function summarizeTokenBenchmark() {
185
- const tokenBenchmarkReport = readJsonFileOrNull(TOKEN_BENCHMARK_PATH);
186
- if (!tokenBenchmarkReport) {
187
- return {
188
- isAvailable: false,
189
- generatedAt: null,
190
- averageNativeSavingsPercent: null,
191
- averageRtkSavingsPercent: null,
192
- scenarioCount: 0,
193
- };
194
- }
195
-
196
- return {
197
- isAvailable: true,
198
- generatedAt: tokenBenchmarkReport.generatedAt || null,
199
- averageNativeSavingsPercent: tokenBenchmarkReport.summary?.averageNativeSavingsPercent ?? null,
200
- averageRtkSavingsPercent: tokenBenchmarkReport.summary?.averageRtkSavingsPercent ?? null,
201
- scenarioCount: Array.isArray(tokenBenchmarkReport.scenarios) ? tokenBenchmarkReport.scenarios.length : 0,
202
- };
203
- }
204
-
205
- function loadPreviousTrendHistory() {
206
- const previousReport = readJsonFileOrNull(REPORT_PATH);
207
- if (!previousReport || !Array.isArray(previousReport.history)) {
208
- return [];
209
- }
210
-
211
- return previousReport.history;
212
- }
213
-
214
- function buildHistoryEntry(currentSnapshot) {
215
- return {
216
- generatedAt: currentSnapshot.generatedAt,
217
- gatePassRatePercent: currentSnapshot.governanceHealth.gatePassRatePercent,
218
- passedGateCount: currentSnapshot.governanceHealth.passedGateCount,
219
- availableGateCount: currentSnapshot.governanceHealth.availableGateCount,
220
- rollbackFrequencyPercent: currentSnapshot.rollbackSignals.rollbackFrequencyPercent,
221
- averageNativeSavingsPercent: currentSnapshot.tokenEfficiency.averageNativeSavingsPercent,
222
- averageRtkSavingsPercent: currentSnapshot.tokenEfficiency.averageRtkSavingsPercent,
223
- rejectionCategoryCount: currentSnapshot.rejectionCategories.length,
224
- };
225
- }
226
-
227
- function mergeHistory(previousHistoryEntries, currentHistoryEntry) {
228
- const mergedHistoryEntries = [...previousHistoryEntries, currentHistoryEntry];
229
- if (mergedHistoryEntries.length <= MAX_SNAPSHOT_HISTORY) {
230
- return mergedHistoryEntries;
231
- }
232
-
233
- return mergedHistoryEntries.slice(mergedHistoryEntries.length - MAX_SNAPSHOT_HISTORY);
234
- }
235
-
236
- async function runQualityTrendReport() {
237
- const releaseGateExecution = runJsonScript('scripts/release-gate.mjs');
238
- const benchmarkGateExecution = runJsonScript('scripts/benchmark-gate.mjs');
239
- const benchmarkIntelligenceExecution = runJsonScript('scripts/benchmark-intelligence.mjs');
240
- const gateExecutionResults = [releaseGateExecution, benchmarkGateExecution, benchmarkIntelligenceExecution];
241
-
242
- const governanceHealth = summarizeGateExecution(gateExecutionResults);
243
- const rejectionCategories = collectRejectionCategories(gateExecutionResults);
244
- const rollbackSignals = calculateRollbackFrequencySnapshot();
245
- const tokenEfficiency = summarizeTokenBenchmark();
246
-
247
- const qualityTrendSnapshot = {
248
- generatedAt: new Date().toISOString(),
249
- reportName: 'quality-trend-report',
250
- methodology: {
251
- gateSources: gateExecutionResults.map((gateExecutionResult) => gateExecutionResult.scriptPath),
252
- rollbackSource: 'git log commit subjects within 30-day window',
253
- tokenSource: '.agent-context/state/token-optimization-benchmark.json',
254
- },
255
- governanceHealth,
256
- rejectionCategories,
257
- rollbackSignals,
258
- tokenEfficiency,
259
- artifact: {
260
- path: REPORT_PATH,
261
- writeMode: isStdoutOnlyMode ? 'stdout-only' : 'stdout-and-file',
262
- },
263
- };
264
-
265
- const previousHistoryEntries = loadPreviousTrendHistory();
266
- const currentHistoryEntry = buildHistoryEntry(qualityTrendSnapshot);
267
- const history = mergeHistory(previousHistoryEntries, currentHistoryEntry);
268
- const qualityTrendReport = {
269
- ...qualityTrendSnapshot,
270
- history,
271
- };
272
-
273
- if (!isStdoutOnlyMode) {
274
- await fs.mkdir(dirname(REPORT_PATH), { recursive: true });
275
- await fs.writeFile(REPORT_PATH, JSON.stringify(qualityTrendReport, null, 2) + '\n', 'utf8');
276
- }
277
-
278
- return qualityTrendReport;
279
- }
280
-
281
- runQualityTrendReport()
282
- .then((qualityTrendReport) => {
283
- console.log(JSON.stringify(qualityTrendReport, null, 2));
284
- })
285
- .catch((qualityTrendError) => {
286
- const errorMessage = qualityTrendError instanceof Error ? qualityTrendError.message : String(qualityTrendError);
287
- console.error(`Quality trend report failed: ${errorMessage}`);
288
- process.exit(1);
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * quality-trend-report.mjs
5
+ *
6
+ * Generates a machine-readable quality trend artifact that summarizes
7
+ * governance gate pass rates, rejection categories, rollback frequency,
8
+ * and token-efficiency signals.
9
+ */
10
+
11
+ import { existsSync, readFileSync } from 'node:fs';
12
+ import fs from 'node:fs/promises';
13
+ import { spawnSync } from 'node:child_process';
14
+ import { dirname, join, resolve } from 'node:path';
15
+ import { fileURLToPath } from 'node:url';
16
+
17
+ const SCRIPT_FILE_PATH = fileURLToPath(import.meta.url);
18
+ const SCRIPT_DIR = dirname(SCRIPT_FILE_PATH);
19
+ const REPOSITORY_ROOT = resolve(SCRIPT_DIR, '..');
20
+ const REPORT_PATH = join(REPOSITORY_ROOT, '.agent-context', 'state', 'quality-trend-report.json');
21
+ const TOKEN_BENCHMARK_PATH = join(REPOSITORY_ROOT, '.agent-context', 'state', 'token-optimization-benchmark.json');
22
+ const ARGUMENT_FLAGS = new Set(process.argv.slice(2));
23
+ const isStdoutOnlyMode = ARGUMENT_FLAGS.has('--stdout-only');
24
+ const MAX_SNAPSHOT_HISTORY = 30;
25
+ const ROLLBACK_WINDOW_DAYS = 30;
26
+
27
+ function runJsonScript(scriptRelativePath) {
28
+ const absoluteScriptPath = join(REPOSITORY_ROOT, scriptRelativePath);
29
+ const commandResult = spawnSync('node', [absoluteScriptPath], {
30
+ cwd: REPOSITORY_ROOT,
31
+ encoding: 'utf8',
32
+ maxBuffer: 1024 * 1024 * 10,
33
+ });
34
+
35
+ const standardOutput = (commandResult.stdout || '').trim();
36
+ const standardError = (commandResult.stderr || '').trim();
37
+ const exitCode = typeof commandResult.status === 'number' ? commandResult.status : 1;
38
+
39
+ if (!standardOutput) {
40
+ return {
41
+ scriptPath: scriptRelativePath,
42
+ exitCode,
43
+ parsedReport: null,
44
+ parseError: 'Script produced no stdout JSON payload',
45
+ stderr: standardError,
46
+ };
47
+ }
48
+
49
+ try {
50
+ const parsedReport = JSON.parse(standardOutput);
51
+ return {
52
+ scriptPath: scriptRelativePath,
53
+ exitCode,
54
+ parsedReport,
55
+ parseError: null,
56
+ stderr: standardError,
57
+ };
58
+ } catch (jsonParseError) {
59
+ const errorMessage = jsonParseError instanceof Error ? jsonParseError.message : String(jsonParseError);
60
+ return {
61
+ scriptPath: scriptRelativePath,
62
+ exitCode,
63
+ parsedReport: null,
64
+ parseError: errorMessage,
65
+ stderr: standardError,
66
+ };
67
+ }
68
+ }
69
+
70
+ function readJsonFileOrNull(filePath) {
71
+ if (!existsSync(filePath)) {
72
+ return null;
73
+ }
74
+
75
+ try {
76
+ return JSON.parse(readFileSync(filePath, 'utf8'));
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+
82
+ function summarizeGateExecution(gateExecutionResults) {
83
+ const gateSummaries = gateExecutionResults.map((gateExecutionResult) => {
84
+ const gateReport = gateExecutionResult.parsedReport;
85
+ return {
86
+ scriptPath: gateExecutionResult.scriptPath,
87
+ gateName: gateReport?.gateName || gateReport?.reportName || gateExecutionResult.scriptPath,
88
+ exitCode: gateExecutionResult.exitCode,
89
+ passed: typeof gateReport?.passed === 'boolean' ? gateReport.passed : false,
90
+ parseError: gateExecutionResult.parseError,
91
+ failureCount: typeof gateReport?.failureCount === 'number' ? gateReport.failureCount : null,
92
+ generatedAt: gateReport?.generatedAt || null,
93
+ };
94
+ });
95
+
96
+ const availableGateCount = gateSummaries.length;
97
+ const passedGateCount = gateSummaries.filter((gateSummary) => gateSummary.passed).length;
98
+ const gatePassRatePercent = availableGateCount === 0
99
+ ? 0
100
+ : Number(((passedGateCount / availableGateCount) * 100).toFixed(2));
101
+
102
+ return {
103
+ gateSummaries,
104
+ availableGateCount,
105
+ passedGateCount,
106
+ gatePassRatePercent,
107
+ };
108
+ }
109
+
110
+ function collectRejectionCategories(gateExecutionResults) {
111
+ const rejectionCategoryMap = new Map();
112
+
113
+ for (const gateExecutionResult of gateExecutionResults) {
114
+ const gateReport = gateExecutionResult.parsedReport;
115
+ const gateName = gateReport?.gateName || gateReport?.reportName || gateExecutionResult.scriptPath;
116
+ const gateResults = Array.isArray(gateReport?.results) ? gateReport.results : [];
117
+
118
+ for (const checkResult of gateResults) {
119
+ if (checkResult?.passed === true) {
120
+ continue;
121
+ }
122
+
123
+ const checkName = typeof checkResult?.checkName === 'string' ? checkResult.checkName : 'unknown-check';
124
+ const existingCategory = rejectionCategoryMap.get(checkName) || {
125
+ checkName,
126
+ count: 0,
127
+ gates: new Set(),
128
+ };
129
+
130
+ existingCategory.count += 1;
131
+ existingCategory.gates.add(gateName);
132
+ rejectionCategoryMap.set(checkName, existingCategory);
133
+ }
134
+ }
135
+
136
+ return Array.from(rejectionCategoryMap.values())
137
+ .map((rejectionCategory) => ({
138
+ checkName: rejectionCategory.checkName,
139
+ count: rejectionCategory.count,
140
+ gates: Array.from(rejectionCategory.gates),
141
+ }))
142
+ .sort((firstCategory, secondCategory) => secondCategory.count - firstCategory.count);
143
+ }
144
+
145
+ function calculateRollbackFrequencySnapshot() {
146
+ const gitLogResult = spawnSync('git', ['log', `--since=${ROLLBACK_WINDOW_DAYS}.days`, '--pretty=format:%s'], {
147
+ cwd: REPOSITORY_ROOT,
148
+ encoding: 'utf8',
149
+ maxBuffer: 1024 * 1024,
150
+ });
151
+
152
+ if (gitLogResult.status !== 0) {
153
+ return {
154
+ windowDays: ROLLBACK_WINDOW_DAYS,
155
+ commitCount: 0,
156
+ rollbackCommitCount: 0,
157
+ rollbackFrequencyPercent: null,
158
+ source: 'git-log',
159
+ error: (gitLogResult.stderr || 'Failed to read git log').trim(),
160
+ };
161
+ }
162
+
163
+ const commitSubjects = (gitLogResult.stdout || '')
164
+ .split(/\r?\n/u)
165
+ .map((subjectLine) => subjectLine.trim())
166
+ .filter((subjectLine) => subjectLine.length > 0);
167
+
168
+ const rollbackCommitCount = commitSubjects.filter((subjectLine) => /rollback/i.test(subjectLine)).length;
169
+ const commitCount = commitSubjects.length;
170
+ const rollbackFrequencyPercent = commitCount === 0
171
+ ? 0
172
+ : Number(((rollbackCommitCount / commitCount) * 100).toFixed(2));
173
+
174
+ return {
175
+ windowDays: ROLLBACK_WINDOW_DAYS,
176
+ commitCount,
177
+ rollbackCommitCount,
178
+ rollbackFrequencyPercent,
179
+ source: 'git-log',
180
+ error: null,
181
+ };
182
+ }
183
+
184
+ function summarizeTokenBenchmark() {
185
+ const tokenBenchmarkReport = readJsonFileOrNull(TOKEN_BENCHMARK_PATH);
186
+ if (!tokenBenchmarkReport) {
187
+ return {
188
+ isAvailable: false,
189
+ generatedAt: null,
190
+ averageNativeSavingsPercent: null,
191
+ averageRtkSavingsPercent: null,
192
+ scenarioCount: 0,
193
+ };
194
+ }
195
+
196
+ return {
197
+ isAvailable: true,
198
+ generatedAt: tokenBenchmarkReport.generatedAt || null,
199
+ averageNativeSavingsPercent: tokenBenchmarkReport.summary?.averageNativeSavingsPercent ?? null,
200
+ averageRtkSavingsPercent: tokenBenchmarkReport.summary?.averageRtkSavingsPercent ?? null,
201
+ scenarioCount: Array.isArray(tokenBenchmarkReport.scenarios) ? tokenBenchmarkReport.scenarios.length : 0,
202
+ };
203
+ }
204
+
205
+ function loadPreviousTrendHistory() {
206
+ const previousReport = readJsonFileOrNull(REPORT_PATH);
207
+ if (!previousReport || !Array.isArray(previousReport.history)) {
208
+ return [];
209
+ }
210
+
211
+ return previousReport.history;
212
+ }
213
+
214
+ function buildHistoryEntry(currentSnapshot) {
215
+ return {
216
+ generatedAt: currentSnapshot.generatedAt,
217
+ gatePassRatePercent: currentSnapshot.governanceHealth.gatePassRatePercent,
218
+ passedGateCount: currentSnapshot.governanceHealth.passedGateCount,
219
+ availableGateCount: currentSnapshot.governanceHealth.availableGateCount,
220
+ rollbackFrequencyPercent: currentSnapshot.rollbackSignals.rollbackFrequencyPercent,
221
+ averageNativeSavingsPercent: currentSnapshot.tokenEfficiency.averageNativeSavingsPercent,
222
+ averageRtkSavingsPercent: currentSnapshot.tokenEfficiency.averageRtkSavingsPercent,
223
+ rejectionCategoryCount: currentSnapshot.rejectionCategories.length,
224
+ };
225
+ }
226
+
227
+ function mergeHistory(previousHistoryEntries, currentHistoryEntry) {
228
+ const mergedHistoryEntries = [...previousHistoryEntries, currentHistoryEntry];
229
+ if (mergedHistoryEntries.length <= MAX_SNAPSHOT_HISTORY) {
230
+ return mergedHistoryEntries;
231
+ }
232
+
233
+ return mergedHistoryEntries.slice(mergedHistoryEntries.length - MAX_SNAPSHOT_HISTORY);
234
+ }
235
+
236
+ async function runQualityTrendReport() {
237
+ const releaseGateExecution = runJsonScript('scripts/release-gate.mjs');
238
+ const benchmarkGateExecution = runJsonScript('scripts/benchmark-gate.mjs');
239
+ const benchmarkIntelligenceExecution = runJsonScript('scripts/benchmark-intelligence.mjs');
240
+ const gateExecutionResults = [releaseGateExecution, benchmarkGateExecution, benchmarkIntelligenceExecution];
241
+
242
+ const governanceHealth = summarizeGateExecution(gateExecutionResults);
243
+ const rejectionCategories = collectRejectionCategories(gateExecutionResults);
244
+ const rollbackSignals = calculateRollbackFrequencySnapshot();
245
+ const tokenEfficiency = summarizeTokenBenchmark();
246
+
247
+ const qualityTrendSnapshot = {
248
+ generatedAt: new Date().toISOString(),
249
+ reportName: 'quality-trend-report',
250
+ methodology: {
251
+ gateSources: gateExecutionResults.map((gateExecutionResult) => gateExecutionResult.scriptPath),
252
+ rollbackSource: 'git log commit subjects within 30-day window',
253
+ tokenSource: '.agent-context/state/token-optimization-benchmark.json',
254
+ },
255
+ governanceHealth,
256
+ rejectionCategories,
257
+ rollbackSignals,
258
+ tokenEfficiency,
259
+ artifact: {
260
+ path: REPORT_PATH,
261
+ writeMode: isStdoutOnlyMode ? 'stdout-only' : 'stdout-and-file',
262
+ },
263
+ };
264
+
265
+ const previousHistoryEntries = loadPreviousTrendHistory();
266
+ const currentHistoryEntry = buildHistoryEntry(qualityTrendSnapshot);
267
+ const history = mergeHistory(previousHistoryEntries, currentHistoryEntry);
268
+ const qualityTrendReport = {
269
+ ...qualityTrendSnapshot,
270
+ history,
271
+ };
272
+
273
+ if (!isStdoutOnlyMode) {
274
+ await fs.mkdir(dirname(REPORT_PATH), { recursive: true });
275
+ await fs.writeFile(REPORT_PATH, JSON.stringify(qualityTrendReport, null, 2) + '\n', 'utf8');
276
+ }
277
+
278
+ return qualityTrendReport;
279
+ }
280
+
281
+ runQualityTrendReport()
282
+ .then((qualityTrendReport) => {
283
+ console.log(JSON.stringify(qualityTrendReport, null, 2));
284
+ })
285
+ .catch((qualityTrendError) => {
286
+ const errorMessage = qualityTrendError instanceof Error ? qualityTrendError.message : String(qualityTrendError);
287
+ console.error(`Quality trend report failed: ${errorMessage}`);
288
+ process.exit(1);
289
289
  });