fraim-framework 2.0.64 → 2.0.66

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 (107) hide show
  1. package/bin/fraim-mcp.js +52 -19
  2. package/bin/fraim.js +23 -0
  3. package/dist/src/cli/commands/add-ide.js +53 -14
  4. package/dist/src/cli/commands/doctor.js +12 -24
  5. package/dist/src/cli/commands/init-project.js +0 -3
  6. package/dist/src/cli/commands/init.js +0 -2
  7. package/dist/src/cli/commands/mcp.js +65 -0
  8. package/dist/src/cli/commands/setup.js +17 -1
  9. package/dist/src/cli/commands/sync.js +173 -104
  10. package/dist/src/cli/setup/auto-mcp-setup.js +6 -4
  11. package/dist/src/cli/setup/mcp-config-generator.js +65 -41
  12. package/dist/src/fraim/issue-tracking/ado-provider.js +304 -0
  13. package/dist/src/fraim/issue-tracking/factory.js +63 -0
  14. package/dist/src/fraim/issue-tracking/github-provider.js +200 -0
  15. package/dist/src/fraim/issue-tracking/types.js +7 -0
  16. package/dist/src/fraim/issue-tracking-config.js +83 -0
  17. package/dist/src/local-mcp-server/stdio-server.js +23 -3
  18. package/dist/src/utils/remote-sync.js +130 -0
  19. package/package.json +2 -3
  20. package/dist/src/utils/enforcement-utils.js +0 -239
  21. package/dist/src/utils/validate-workflows.js +0 -101
  22. package/registry/scripts/cleanup-branch.ts +0 -341
  23. package/registry/scripts/code-quality-check.sh +0 -566
  24. package/registry/scripts/comprehensive-explorer.py +0 -297
  25. package/registry/scripts/create-git-labels.sh +0 -49
  26. package/registry/scripts/create-website-structure.js +0 -562
  27. package/registry/scripts/detect-tautological-tests.sh +0 -38
  28. package/registry/scripts/evaluate-code-quality.ts +0 -36
  29. package/registry/scripts/exec-with-timeout.ts +0 -122
  30. package/registry/scripts/generate-engagement-emails.ts +0 -830
  31. package/registry/scripts/interactive-explorer.py +0 -270
  32. package/registry/scripts/markdown-to-pdf.js +0 -395
  33. package/registry/scripts/newsletter-helpers.ts +0 -777
  34. package/registry/scripts/pdf-styles.css +0 -172
  35. package/registry/scripts/prep-issue.sh +0 -548
  36. package/registry/scripts/productivity/build-productivity-csv.mjs +0 -242
  37. package/registry/scripts/productivity/fetch-pr-details.mjs +0 -144
  38. package/registry/scripts/productivity/productivity-report.sh +0 -147
  39. package/registry/scripts/profile-server.ts +0 -426
  40. package/registry/scripts/run-thank-you-workflow.ts +0 -122
  41. package/registry/scripts/scrape-site.py +0 -302
  42. package/registry/scripts/send-newsletter-simple.ts +0 -102
  43. package/registry/scripts/send-thank-you-emails.ts +0 -57
  44. package/registry/scripts/validate-openapi-limits.ts +0 -366
  45. package/registry/scripts/validate-test-coverage.ts +0 -280
  46. package/registry/scripts/verify-pr-comments.sh +0 -74
  47. package/registry/scripts/verify-test-coverage.ts +0 -36
  48. package/registry/stubs/workflows/azure/cost-optimization.md +0 -11
  49. package/registry/stubs/workflows/bootstrap/create-architecture.md +0 -11
  50. package/registry/stubs/workflows/bootstrap/detect-broken-windows.md +0 -11
  51. package/registry/stubs/workflows/bootstrap/evaluate-code-quality.md +0 -11
  52. package/registry/stubs/workflows/bootstrap/verify-test-coverage.md +0 -11
  53. package/registry/stubs/workflows/brainstorming/blue-sky-brainstorming.md +0 -11
  54. package/registry/stubs/workflows/brainstorming/codebase-brainstorming.md +0 -11
  55. package/registry/stubs/workflows/business-development/create-business-plan.md +0 -11
  56. package/registry/stubs/workflows/business-development/ideate-business-opportunity.md +0 -11
  57. package/registry/stubs/workflows/business-development/price-product.md +0 -18
  58. package/registry/stubs/workflows/compliance/detect-compliance-requirements.md +0 -11
  59. package/registry/stubs/workflows/compliance/generate-audit-evidence.md +0 -11
  60. package/registry/stubs/workflows/compliance/soc2-evidence-generator.md +0 -11
  61. package/registry/stubs/workflows/customer-development/insight-analysis.md +0 -11
  62. package/registry/stubs/workflows/customer-development/insight-triage.md +0 -11
  63. package/registry/stubs/workflows/customer-development/interview-preparation.md +0 -11
  64. package/registry/stubs/workflows/customer-development/linkedin-outreach.md +0 -11
  65. package/registry/stubs/workflows/customer-development/strategic-brainstorming.md +0 -11
  66. package/registry/stubs/workflows/customer-development/thank-customers.md +0 -11
  67. package/registry/stubs/workflows/customer-development/user-survey-dispatch.md +0 -11
  68. package/registry/stubs/workflows/customer-development/users-to-target.md +0 -11
  69. package/registry/stubs/workflows/customer-development/weekly-newsletter.md +0 -11
  70. package/registry/stubs/workflows/deploy/cloud-deployment.md +0 -11
  71. package/registry/stubs/workflows/improve-fraim/contribute.md +0 -11
  72. package/registry/stubs/workflows/improve-fraim/file-issue.md +0 -11
  73. package/registry/stubs/workflows/learning/build-skillset.md +0 -11
  74. package/registry/stubs/workflows/learning/synthesize-learnings.md +0 -11
  75. package/registry/stubs/workflows/legal/contract-review-analysis.md +0 -11
  76. package/registry/stubs/workflows/legal/nda.md +0 -11
  77. package/registry/stubs/workflows/legal/patent-filing.md +0 -11
  78. package/registry/stubs/workflows/legal/saas-contract-development.md +0 -11
  79. package/registry/stubs/workflows/legal/trademark-filing.md +0 -11
  80. package/registry/stubs/workflows/marketing/content-creation.md +0 -11
  81. package/registry/stubs/workflows/marketing/convert-to-pdf.md +0 -11
  82. package/registry/stubs/workflows/marketing/create-modern-website.md +0 -11
  83. package/registry/stubs/workflows/marketing/domain-registration.md +0 -11
  84. package/registry/stubs/workflows/marketing/hbr-article.md +0 -11
  85. package/registry/stubs/workflows/marketing/launch-checklist.md +0 -11
  86. package/registry/stubs/workflows/marketing/marketing-strategy.md +0 -11
  87. package/registry/stubs/workflows/marketing/storytelling.md +0 -11
  88. package/registry/stubs/workflows/performance/analyze-performance.md +0 -11
  89. package/registry/stubs/workflows/product-building/design.md +0 -11
  90. package/registry/stubs/workflows/product-building/implement.md +0 -11
  91. package/registry/stubs/workflows/product-building/iterate-on-pr-comments.md +0 -11
  92. package/registry/stubs/workflows/product-building/prep-issue.md +0 -11
  93. package/registry/stubs/workflows/product-building/prototype.md +0 -11
  94. package/registry/stubs/workflows/product-building/resolve.md +0 -11
  95. package/registry/stubs/workflows/product-building/retrospect.md +0 -11
  96. package/registry/stubs/workflows/product-building/spec.md +0 -11
  97. package/registry/stubs/workflows/product-building/test.md +0 -11
  98. package/registry/stubs/workflows/productivity-report/productivity-report.md +0 -11
  99. package/registry/stubs/workflows/quality-assurance/browser-validation.md +0 -11
  100. package/registry/stubs/workflows/quality-assurance/iterative-improvement-cycle.md +0 -11
  101. package/registry/stubs/workflows/replicate/replicate-discovery.md +0 -11
  102. package/registry/stubs/workflows/replicate/replicate-to-issues.md +0 -11
  103. package/registry/stubs/workflows/reviewer/review-implementation-vs-design-spec.md +0 -11
  104. package/registry/stubs/workflows/reviewer/review-implementation-vs-feature-spec.md +0 -11
  105. package/registry/stubs/workflows/startup-credits/aws-activate-application.md +0 -11
  106. package/registry/stubs/workflows/startup-credits/google-cloud-application.md +0 -11
  107. package/registry/stubs/workflows/startup-credits/microsoft-azure-application.md +0 -11
@@ -1,366 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * FRAIM Generic OpenAPI Limits Validator
5
- * This script validates OpenAPI file sizes against specified limits.
6
- *
7
- * Validates ChatGPT limitations for any project:
8
- * - instructions.txt: 8,000 character limit
9
- * - OpenAPI endpoints: 35 endpoint limit
10
- * - OpenAPI descriptions: 300 character limit per operation
11
- * - Missing operationIds
12
- * - Missing schema definitions
13
- * - x-openai-isConsequential on non-GET endpoints
14
- *
15
- * Usage:
16
- * npx tsx scripts/validate-openapi-limits.ts [instructions-file] [openapi-file]
17
- *
18
- * Defaults:
19
- * instructions-file: src/openapi/instructions.txt
20
- * openapi-file: src/openapi/openapi.json
21
- */
22
-
23
- import { readFileSync, existsSync } from 'fs';
24
- import { join } from 'path';
25
-
26
- const INSTRUCTIONS_LIMIT = 8000;
27
- const OPENAPI_ENDPOINT_LIMIT = 35;
28
- const OPENAPI_DESC_LIMIT = 300;
29
-
30
- interface ValidationResult {
31
- passed: boolean;
32
- errors: string[];
33
- warnings: string[];
34
- }
35
-
36
- /**
37
- * Collect all schema references from an object recursively
38
- */
39
- function collectSchemaRefs(obj: any, refs: Set<string> = new Set()): Set<string> {
40
- if (typeof obj !== 'object' || obj === null) {
41
- return refs;
42
- }
43
-
44
- if (Array.isArray(obj)) {
45
- obj.forEach(item => collectSchemaRefs(item, refs));
46
- return refs;
47
- }
48
-
49
- if (obj.$ref && typeof obj.$ref === 'string') {
50
- // Extract schema name from #/components/schemas/SchemaName
51
- const match = obj.$ref.match(/#\/components\/schemas\/(.+)$/);
52
- if (match) {
53
- refs.add(match[1]);
54
- }
55
- }
56
-
57
- Object.values(obj).forEach(value => collectSchemaRefs(value, refs));
58
-
59
- return refs;
60
- }
61
-
62
- /**
63
- * Validate instructions.txt length
64
- */
65
- function validateInstructions(instructionsPath: string): ValidationResult {
66
- const result: ValidationResult = {
67
- passed: true,
68
- errors: [],
69
- warnings: []
70
- };
71
-
72
- if (!existsSync(instructionsPath)) {
73
- result.warnings.push(`instructions.txt not found at ${instructionsPath}`);
74
- return result;
75
- }
76
-
77
- try {
78
- const instructionsContent = readFileSync(instructionsPath, 'utf-8');
79
- const instructionsLength = instructionsContent.length;
80
-
81
- console.log(`📄 instructions.txt: ${instructionsLength} characters (limit: ${INSTRUCTIONS_LIMIT})`);
82
-
83
- if (instructionsLength > INSTRUCTIONS_LIMIT) {
84
- result.passed = false;
85
- result.errors.push(
86
- `instructions.txt exceeds ${INSTRUCTIONS_LIMIT} character limit (${instructionsLength} chars). Move detailed content to KB files.`
87
- );
88
- console.log(` ❌ FAILED: Exceeds limit`);
89
- } else {
90
- console.log(` ✅ PASSED: Within limit\n`);
91
- }
92
- } catch (error: any) {
93
- result.passed = false;
94
- result.errors.push(`Failed to read instructions.txt: ${error.message}`);
95
- }
96
-
97
- return result;
98
- }
99
-
100
- /**
101
- * Validate OpenAPI specification
102
- */
103
- function validateOpenAPI(openapiPath: string): ValidationResult {
104
- const result: ValidationResult = {
105
- passed: true,
106
- errors: [],
107
- warnings: []
108
- };
109
-
110
- if (!existsSync(openapiPath)) {
111
- result.warnings.push(`OpenAPI file not found at ${openapiPath}`);
112
- return result;
113
- }
114
-
115
- try {
116
- const openapiContent = readFileSync(openapiPath, 'utf-8');
117
- const openapiSpec = JSON.parse(openapiContent);
118
-
119
- // Count endpoints (operations) and validate
120
- let endpointCount = 0;
121
- const endpointList: string[] = [];
122
- const longDescriptions: Array<{ path: string; method: string; length: number }> = [];
123
- const missingOperationIds: Array<{ path: string; method: string }> = [];
124
- const allSchemaRefs = new Set<string>();
125
- const missingConsequential: Array<{ path: string; method: string }> = [];
126
- const wrongConsequential: Array<{ path: string; method: string; value: any }> = [];
127
-
128
- if (openapiSpec.paths) {
129
- for (const [path, methods] of Object.entries(openapiSpec.paths)) {
130
- for (const [method, details] of Object.entries(methods as any)) {
131
- if (typeof details === 'object' && details !== null) {
132
- // Skip if it's a parameter definition or response definition
133
- if (['parameters', 'responses', 'requestBody'].includes(method)) {
134
- continue;
135
- }
136
-
137
- endpointCount++;
138
- endpointList.push(`${method.toUpperCase()} ${path}`);
139
-
140
- // Check for operationId
141
- if (!(details as any).operationId) {
142
- missingOperationIds.push({
143
- path,
144
- method: method.toUpperCase()
145
- });
146
- }
147
-
148
- // Check description length
149
- if ((details as any).description) {
150
- const descLength = (details as any).description.length;
151
- if (descLength > OPENAPI_DESC_LIMIT) {
152
- longDescriptions.push({
153
- path,
154
- method: method.toUpperCase(),
155
- length: descLength
156
- });
157
- }
158
- }
159
-
160
- // Collect all schema references from this operation
161
- collectSchemaRefs(details, allSchemaRefs);
162
-
163
- // Check for x-openai-isConsequential on non-GET endpoints
164
- const nonGetMethods = ['post', 'put', 'patch', 'delete'];
165
- if (nonGetMethods.includes(method.toLowerCase())) {
166
- const hasConsequential = details.hasOwnProperty('x-openai-isConsequential');
167
- const consequentialValue = (details as any)['x-openai-isConsequential'];
168
-
169
- // ALL non-GET endpoints should have x-openai-isConsequential: false
170
- if (!hasConsequential) {
171
- missingConsequential.push({
172
- path,
173
- method: method.toUpperCase()
174
- });
175
- } else if (consequentialValue !== false) {
176
- wrongConsequential.push({
177
- path,
178
- method: method.toUpperCase(),
179
- value: consequentialValue
180
- });
181
- }
182
- }
183
- }
184
- }
185
- }
186
- }
187
-
188
- // Also collect schema refs from components/responses and components/parameters if they exist
189
- if (openapiSpec.components) {
190
- if (openapiSpec.components.responses) {
191
- Object.values(openapiSpec.components.responses).forEach((response: any) => {
192
- collectSchemaRefs(response, allSchemaRefs);
193
- });
194
- }
195
- if (openapiSpec.components.parameters) {
196
- Object.values(openapiSpec.components.parameters).forEach((param: any) => {
197
- collectSchemaRefs(param, allSchemaRefs);
198
- });
199
- }
200
- }
201
-
202
- // Check for missing schema definitions
203
- const definedSchemas = new Set<string>();
204
- if (openapiSpec.components && openapiSpec.components.schemas) {
205
- Object.keys(openapiSpec.components.schemas).forEach(schemaName => {
206
- definedSchemas.add(schemaName);
207
- });
208
- }
209
-
210
- const missingSchemas: string[] = [];
211
- allSchemaRefs.forEach(refName => {
212
- if (!definedSchemas.has(refName)) {
213
- missingSchemas.push(refName);
214
- }
215
- });
216
-
217
- // Validate endpoint count
218
- console.log(`📋 OpenAPI endpoints: ${endpointCount} (limit: ${OPENAPI_ENDPOINT_LIMIT})`);
219
-
220
- if (endpointCount > OPENAPI_ENDPOINT_LIMIT) {
221
- result.passed = false;
222
- result.errors.push(
223
- `OpenAPI spec exceeds ${OPENAPI_ENDPOINT_LIMIT} endpoint limit (${endpointCount} endpoints). ChatGPT cannot handle more than ${OPENAPI_ENDPOINT_LIMIT} endpoints.`
224
- );
225
- console.log(` ❌ FAILED: Too many endpoints`);
226
- console.log(` Endpoints:`);
227
- endpointList.slice(0, 10).forEach(ep => console.log(` - ${ep}`));
228
- if (endpointCount > 10) {
229
- console.log(` ... and ${endpointCount - 10} more`);
230
- }
231
- } else {
232
- console.log(` ✅ PASSED: Within limit`);
233
- }
234
-
235
- // Check description lengths
236
- if (longDescriptions.length > 0) {
237
- console.log(`\n📝 OpenAPI descriptions: ${longDescriptions.length} exceed ${OPENAPI_DESC_LIMIT} char limit`);
238
- longDescriptions.forEach(({ path, method, length }) => {
239
- result.passed = false;
240
- result.errors.push(
241
- `OpenAPI operation ${method} ${path} description exceeds ${OPENAPI_DESC_LIMIT} character limit (${length} chars). Shorten description or move details to KB files.`
242
- );
243
- console.log(` ❌ ${method} ${path}: ${length} chars`);
244
- });
245
- } else {
246
- console.log(`\n📝 OpenAPI descriptions: All within ${OPENAPI_DESC_LIMIT} char limit`);
247
- console.log(` ✅ PASSED: All descriptions within limit`);
248
- }
249
-
250
- // Check for missing operationIds
251
- if (missingOperationIds.length > 0) {
252
- console.log(`\n🔑 OpenAPI operationIds: ${missingOperationIds.length} missing`);
253
- missingOperationIds.forEach(({ path, method }) => {
254
- result.passed = false;
255
- result.errors.push(
256
- `OpenAPI operation ${method} ${path} is missing required 'operationId' field. Add a unique operationId (e.g., "getTask", "createTask").`
257
- );
258
- console.log(` ❌ ${method} ${path}: Missing operationId`);
259
- });
260
- } else {
261
- console.log(`\n🔑 OpenAPI operationIds: All operations have operationId`);
262
- console.log(` ✅ PASSED: All operations have operationId`);
263
- }
264
-
265
- // Check for missing schema definitions
266
- if (missingSchemas.length > 0) {
267
- console.log(`\n📚 OpenAPI schemas: ${missingSchemas.length} referenced but not defined`);
268
- missingSchemas.forEach(schemaName => {
269
- result.passed = false;
270
- result.errors.push(
271
- `OpenAPI schema '${schemaName}' is referenced but not defined in components.schemas. Add the schema definition to components.schemas.`
272
- );
273
- console.log(` ❌ Missing schema: ${schemaName}`);
274
- });
275
- } else {
276
- console.log(`\n📚 OpenAPI schemas: All referenced schemas are defined`);
277
- console.log(` ✅ PASSED: All schema references resolve`);
278
- }
279
-
280
- // Check for missing or incorrect x-openai-isConsequential on non-GET endpoints
281
- const allConsequentialIssues = [...missingConsequential, ...wrongConsequential];
282
- if (allConsequentialIssues.length > 0) {
283
- console.log(`\n🔐 OpenAPI x-openai-isConsequential: ${allConsequentialIssues.length} non-GET endpoint(s) missing or incorrectly set`);
284
- missingConsequential.forEach(({ path, method }) => {
285
- result.passed = false;
286
- result.errors.push(
287
- `OpenAPI operation ${method} ${path} is missing required 'x-openai-isConsequential: false' field. Add this field to bypass ChatGPT confirmation prompts.`
288
- );
289
- console.log(` ❌ ${method} ${path}: Missing x-openai-isConsequential`);
290
- });
291
- wrongConsequential.forEach(({ path, method, value }) => {
292
- result.passed = false;
293
- result.errors.push(
294
- `OpenAPI operation ${method} ${path} has x-openai-isConsequential set to ${JSON.stringify(value)} but should be false. Non-GET endpoints should have x-openai-isConsequential: false to bypass ChatGPT confirmation prompts.`
295
- );
296
- console.log(` ❌ ${method} ${path}: x-openai-isConsequential is ${JSON.stringify(value)}, should be false`);
297
- });
298
- } else {
299
- console.log(`\n🔐 OpenAPI x-openai-isConsequential: All non-GET endpoints have x-openai-isConsequential: false`);
300
- console.log(` ✅ PASSED: All non-GET endpoints configured to bypass confirmation`);
301
- }
302
-
303
- } catch (error: any) {
304
- result.passed = false;
305
- result.errors.push(`Failed to parse OpenAPI JSON: ${error.message}`);
306
- console.log(` ❌ ERROR: ${error.message}`);
307
- }
308
-
309
- return result;
310
- }
311
-
312
- /**
313
- * Main validation function
314
- */
315
- export function validateAll(
316
- instructionsPath: string = 'src/openapi/instructions.txt',
317
- openapiPath: string = 'src/openapi/openapi.json'
318
- ): boolean {
319
- console.log('🔍 Validating OpenAPI and instructions limits...\n');
320
-
321
- const instructionsResult = validateInstructions(instructionsPath);
322
- const openapiResult = validateOpenAPI(openapiPath);
323
-
324
- // Combine results
325
- const allErrors = [...instructionsResult.errors, ...openapiResult.errors];
326
- const allWarnings = [...instructionsResult.warnings, ...openapiResult.warnings];
327
- const passed = instructionsResult.passed && openapiResult.passed;
328
-
329
- // Summary
330
- console.log('\n' + '='.repeat(50));
331
- console.log('📊 VALIDATION SUMMARY');
332
- console.log('='.repeat(50));
333
-
334
- if (allWarnings.length > 0) {
335
- console.log('\n⚠️ WARNINGS:');
336
- allWarnings.forEach(w => console.log(` - ${w}`));
337
- }
338
-
339
- if (allErrors.length > 0) {
340
- console.log('\n❌ ERRORS:');
341
- allErrors.forEach(e => console.log(` - ${e}`));
342
- console.log('\n💡 Solutions:');
343
- console.log(' - Move detailed content from instructions.txt to KB files (KB-*.txt)');
344
- console.log(' - Reduce number of OpenAPI endpoints (merge or remove unused endpoints)');
345
- console.log(' - Shorten OpenAPI operation descriptions, reference KB files for details');
346
- console.log(' - Add missing operationId fields to all operations (e.g., "getTask", "createTask")');
347
- console.log(' - Define missing schemas in components.schemas section');
348
- console.log(' - Add x-openai-isConsequential: false to all non-GET endpoints (POST, PUT, PATCH, DELETE)');
349
- console.log('\n❌ BUILD FAILED: Fix errors above before proceeding\n');
350
- return false;
351
- } else {
352
- console.log('\n✅ ALL CHECKS PASSED');
353
- console.log(' Instructions and OpenAPI spec are within ChatGPT limits\n');
354
- return true;
355
- }
356
- }
357
-
358
- // Run if executed directly
359
- // @ts-ignore
360
- if (import.meta.url === `file://${process.argv[1]}`) {
361
- const instructionsPath = process.argv[2] || 'src/openapi/instructions.txt';
362
- const openapiPath = process.argv[3] || 'src/openapi/openapi.json';
363
-
364
- const passed = validateAll(instructionsPath, openapiPath);
365
- process.exit(passed ? 0 : 1);
366
- }
@@ -1,280 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Validation Plan Coverage Checker
4
- *
5
- * Extracts validation plan from spec/design documents and verifies evidence coverage.
6
- * Used by Gate 9 in code-quality-check.sh
7
- *
8
- * Usage: npx tsx <this-script> <issue-number>
9
- */
10
-
11
- import * as fs from 'fs';
12
- import * as path from 'path';
13
-
14
- interface ValidationScenario {
15
- userScenario: string;
16
- expectedOutcome: string;
17
- validationMethod: string;
18
- }
19
-
20
- interface CoverageResult {
21
- complete: boolean;
22
- totalScenarios: number;
23
- coveredScenarios: number;
24
- missingScenarios: ValidationScenario[];
25
- coverage: string; // "X/Y scenarios (Z%)"
26
- }
27
-
28
- /**
29
- * Extract issue number from branch name
30
- */
31
- function extractIssueNumberFromBranch(): number | null {
32
- const branchName = process.env.GIT_BRANCH || '';
33
- const match = branchName.match(/feature\/(\d+)/);
34
- return match ? parseInt(match[1]) : null;
35
- }
36
-
37
- /**
38
- * Find spec or design file for an issue
39
- */
40
- function findSpecOrDesignFile(issueNumber: number): string | null {
41
- const specDir = path.join(process.cwd(), 'docs', 'feature specs');
42
- const rfcDir = path.join(process.cwd(), 'docs', 'rfcs');
43
-
44
- // Try feature specs first
45
- if (fs.existsSync(specDir)) {
46
- const files = fs.readdirSync(specDir);
47
- const specFile = files.find(f => f.startsWith(`${issueNumber}-`) && f.endsWith('.md'));
48
- if (specFile) {
49
- return path.join(specDir, specFile);
50
- }
51
- }
52
-
53
- // Then try RFCs
54
- if (fs.existsSync(rfcDir)) {
55
- const files = fs.readdirSync(rfcDir);
56
- const rfcFile = files.find(f => f.startsWith(`${issueNumber}-`) && f.endsWith('.md'));
57
- if (rfcFile) {
58
- return path.join(rfcDir, rfcFile);
59
- }
60
- }
61
-
62
- return null;
63
- }
64
-
65
- /**
66
- * Extract validation plan table from markdown file
67
- */
68
- function extractValidationPlan(filePath: string): ValidationScenario[] {
69
- const content = fs.readFileSync(filePath, 'utf-8');
70
- const scenarios: ValidationScenario[] = [];
71
-
72
- // Find "## Validation Plan" section (not "Validation Plan Coverage")
73
- const validationPlanMatch = content.match(/##\s+Validation Plan\s*\n[\s\S]*?(?=\n##|$)/i);
74
- if (!validationPlanMatch) {
75
- return scenarios;
76
- }
77
-
78
- const validationSection = validationPlanMatch[0];
79
-
80
- // Look for markdown table - find table header row with "User Scenario"
81
- // Pattern: | User Scenario | Expected outcome | Validation method |
82
- const tablePattern = /\|[\s\*]*User Scenario[\s\*]*\|[\s\*]*Expected outcome[\s\*]*\|[\s\*]*Validation method[\s\*]*\|[\s]*\n\|[\s:\-|]+\|[\s]*\n((?:\|.*?\|[\s]*\n)+)/i;
83
- const tableMatch = validationSection.match(tablePattern);
84
-
85
- if (!tableMatch) {
86
- return scenarios;
87
- }
88
-
89
- const tableRows = tableMatch[1].trim().split('\n').filter(row => row.trim().startsWith('|'));
90
-
91
- for (const row of tableRows) {
92
- // Skip separator rows (all dashes/pipes)
93
- if (row.match(/^\|[\s:\-|]+\|$/)) {
94
- continue;
95
- }
96
-
97
- // Parse table row: | Scenario | Outcome | Method |
98
- // Handle both formats: | **bold** | text | and | text | text |
99
- const cells = row.split('|').map(c => c.trim()).filter(c => c && c !== '');
100
-
101
- if (cells.length >= 2) {
102
- // Remove markdown bold (**text**) from cells
103
- const cleanCell = (cell: string): string => {
104
- return cell
105
- .replace(/^\*\*/, '')
106
- .replace(/\*\*$/, '')
107
- .replace(/^\*\*/g, '')
108
- .replace(/\*\*/g, '')
109
- .trim();
110
- };
111
-
112
- const userScenario = cleanCell(cells[0] || '');
113
- const expectedOutcome = cleanCell(cells[1] || '');
114
- const validationMethod = cleanCell(cells[2] || 'Manual validation');
115
-
116
- // Skip header rows
117
- const scenarioLower = userScenario.toLowerCase();
118
- const outcomeLower = expectedOutcome.toLowerCase();
119
- if (scenarioLower.includes('user scenario') ||
120
- (scenarioLower.includes('scenario') && outcomeLower.includes('expected')) ||
121
- scenarioLower === 'user scenario' ||
122
- outcomeLower === 'expected outcome') {
123
- continue;
124
- }
125
-
126
- // Skip empty rows or separator rows
127
- if (!userScenario || userScenario === '-' || userScenario.length === 0) {
128
- continue;
129
- }
130
-
131
- scenarios.push({
132
- userScenario,
133
- expectedOutcome,
134
- validationMethod
135
- });
136
- }
137
- }
138
-
139
- return scenarios;
140
- }
141
-
142
- /**
143
- * Check if evidence exists for a scenario
144
- * Evidence can be in PR comments, test.log, or other sources
145
- */
146
- function checkEvidenceForScenario(scenario: ValidationScenario, issueNumber: number): boolean {
147
- // Extract key terms from scenario for searching
148
- const scenarioKeywords = scenario.userScenario
149
- .toLowerCase()
150
- .replace(/\*\*/g, '')
151
- .split(/\s+/)
152
- .filter(w => w.length > 3 && !['agent', 'the', 'with', 'without'].includes(w));
153
-
154
- const outcomeKeywords = scenario.expectedOutcome
155
- .toLowerCase()
156
- .replace(/\*\*/g, '')
157
- .split(/\s+/)
158
- .filter(w => w.length > 3);
159
-
160
- // Method 1: Check test.log for scenario keywords
161
- const testLogPath = path.join(process.cwd(), 'test.log');
162
- if (fs.existsSync(testLogPath)) {
163
- const testLogContent = fs.readFileSync(testLogPath, 'utf-8').toLowerCase();
164
- // Check if multiple keywords from scenario appear
165
- const matchingKeywords = scenarioKeywords.filter(kw => testLogContent.includes(kw));
166
- if (matchingKeywords.length >= 2) {
167
- return true;
168
- }
169
- }
170
-
171
- // Method 2: Check for evidence file (created by agent with scenario validation)
172
- const evidenceFiles = ['test-evidence.md', 'validation-evidence.md', 'implementation-evidence.md'];
173
- for (const evidenceFile of evidenceFiles) {
174
- const evidencePath = path.join(process.cwd(), evidenceFile);
175
- if (fs.existsSync(evidencePath)) {
176
- const evidenceContent = fs.readFileSync(evidencePath, 'utf-8').toLowerCase();
177
- const matchingKeywords = scenarioKeywords.filter(kw => evidenceContent.includes(kw));
178
- if (matchingKeywords.length >= 2) {
179
- return true;
180
- }
181
- }
182
- }
183
-
184
- // Method 3: Check server.log for scenario-related activity
185
- const serverLogPath = path.join(process.cwd(), 'server.log');
186
- if (fs.existsSync(serverLogPath)) {
187
- const serverLogContent = fs.readFileSync(serverLogPath, 'utf-8').toLowerCase();
188
- // Look for validation-related keywords
189
- if (scenarioKeywords.some(kw => serverLogContent.includes(kw)) ||
190
- outcomeKeywords.some(kw => serverLogContent.includes('gate') && serverLogContent.includes(kw))) {
191
- return true;
192
- }
193
- }
194
-
195
- // Note: PR comment checking is done in the shell script (Gate 9)
196
- // This TypeScript tool focuses on file-based evidence
197
-
198
- return false; // Conservative: require evidence
199
- }
200
-
201
- /**
202
- * Main function
203
- */
204
- function main(): void {
205
- const issueNumberArg = process.argv[2];
206
- const issueNumber = issueNumberArg ? parseInt(issueNumberArg) : extractIssueNumberFromBranch();
207
-
208
- if (!issueNumber) {
209
- console.error('❌ ERROR: Could not determine issue number');
210
- console.error(' Usage: npx tsx validate-coverage.ts <issue-number>');
211
- console.error(' Or set GIT_BRANCH environment variable with feature/N-* format');
212
- process.exit(1);
213
- }
214
-
215
- const specFile = findSpecOrDesignFile(issueNumber);
216
-
217
- if (!specFile) {
218
- // No spec/design found - Gate 9 warns but doesn't block
219
- console.log('ℹ️ No spec/design found for issue #' + issueNumber);
220
- console.log(' Skipping validation plan coverage check');
221
- console.log(' Gate 9: Validation Plan Coverage - SKIPPED (no spec/design)');
222
- process.exit(0);
223
- }
224
-
225
- console.log(`Found spec/design: ${specFile}`);
226
-
227
- const scenarios = extractValidationPlan(specFile);
228
-
229
- if (scenarios.length === 0) {
230
- console.log('ℹ️ No validation plan table found in spec/design');
231
- console.log(' Gate 9: Validation Plan Coverage - SKIPPED (no validation plan)');
232
- process.exit(0);
233
- }
234
-
235
- console.log(`Found ${scenarios.length} validation scenario(s)`);
236
-
237
- // Check evidence for each scenario
238
- const covered: ValidationScenario[] = [];
239
- const missing: ValidationScenario[] = [];
240
-
241
- for (const scenario of scenarios) {
242
- if (checkEvidenceForScenario(scenario, issueNumber)) {
243
- covered.push(scenario);
244
- } else {
245
- missing.push(scenario);
246
- }
247
- }
248
-
249
- const coverage: CoverageResult = {
250
- complete: missing.length === 0,
251
- totalScenarios: scenarios.length,
252
- coveredScenarios: covered.length,
253
- missingScenarios: missing,
254
- coverage: `${covered.length}/${scenarios.length} scenarios (${Math.round(covered.length / scenarios.length * 100)}%)`
255
- };
256
-
257
- // Output results
258
- console.log('\n📊 Validation Plan Coverage:');
259
- console.log(` ${coverage.coverage}`);
260
-
261
- if (coverage.complete) {
262
- console.log('✅ PASSED: All validation scenarios have evidence');
263
- console.log(' Gate 9: Validation Plan Coverage - PASSED');
264
- process.exit(0);
265
- } else {
266
- console.log('❌ FAILED: Missing evidence for validation scenarios:');
267
- for (const scenario of missing) {
268
- console.log(` - "${scenario.userScenario}"`);
269
- console.log(` Expected: ${scenario.expectedOutcome}`);
270
- console.log(` Method: ${scenario.validationMethod}`);
271
- }
272
- console.log('\n Required: Provide evidence for all validation scenarios before marking PR ready');
273
- console.log(' Evidence can be: PR comment, test output, manual verification log');
274
- console.log(' Gate 9: Validation Plan Coverage - FAILED');
275
- process.exit(1);
276
- }
277
- }
278
-
279
- // Run main function
280
- main();