fraim-framework 2.0.52 → 2.0.55

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 (100) hide show
  1. package/dist/registry/scripts/profile-server.js +2 -1
  2. package/dist/src/ai-manager/ai-manager.js +49 -1
  3. package/dist/src/ai-manager/phase-flow.js +68 -0
  4. package/dist/src/utils/digest-utils.js +18 -7
  5. package/dist/tests/test-debug-session.js +6 -2
  6. package/dist/tests/test-enhanced-session-init.js +6 -2
  7. package/dist/tests/test-mcp-lifecycle-methods.js +1 -2
  8. package/dist/tests/test-mcp-template-processing.js +6 -2
  9. package/dist/tests/test-modular-issue-tracking.js +6 -2
  10. package/dist/tests/test-node-compatibility.js +4 -2
  11. package/dist/tests/test-npm-install.js +4 -2
  12. package/dist/tests/test-productivity-integration.js +157 -0
  13. package/dist/tests/test-session-rehydration.js +1 -2
  14. package/dist/tests/test-telemetry.js +1 -2
  15. package/dist/tests/test-users-to-target-workflow.js +253 -0
  16. package/index.js +44 -55
  17. package/package.json +5 -5
  18. package/registry/agent-guardrails.md +62 -62
  19. package/registry/scripts/detect-tautological-tests.sh +38 -38
  20. package/registry/scripts/productivity/build-productivity-csv.mjs +242 -0
  21. package/registry/scripts/productivity/fetch-pr-details.mjs +144 -0
  22. package/registry/scripts/productivity/productivity-report.sh +147 -0
  23. package/registry/scripts/profile-server.ts +1 -1
  24. package/registry/scripts/validate-openapi-limits.ts +366 -366
  25. package/registry/scripts/validate-test-coverage.ts +280 -280
  26. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase1-customer-profiling.md +11 -0
  27. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase1-survey-scoping.md +11 -0
  28. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase2-platform-discovery.md +11 -0
  29. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase2-survey-build-linkedin.md +11 -0
  30. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase3-prospect-qualification.md +11 -0
  31. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase3-survey-build-reddit.md +11 -0
  32. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase4-inventory-compilation.md +11 -0
  33. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase4-survey-build-x.md +11 -0
  34. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase5-survey-build-facebook.md +11 -0
  35. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase6-survey-build-custom.md +11 -0
  36. package/registry/stubs/workflows/customer-development/ai-coach-phases/phase7-survey-dispatch.md +11 -0
  37. package/registry/stubs/workflows/customer-development/templates/customer-persona-template.md +11 -0
  38. package/registry/stubs/workflows/customer-development/templates/search-strategy-template.md +11 -0
  39. package/registry/stubs/workflows/customer-development/user-survey-dispatch.md +11 -0
  40. package/registry/stubs/workflows/customer-development/users-to-target.md +11 -0
  41. package/registry/stubs/workflows/productivity-report/productivity-report.md +11 -0
  42. package/bin/fraim.js +0 -8
  43. package/dist/registry/ai-manager-rules/design-phases/design.md +0 -108
  44. package/dist/registry/ai-manager-rules/design-phases/finalize.md +0 -60
  45. package/dist/registry/ai-manager-rules/design-phases/validate.md +0 -125
  46. package/dist/registry/ai-manager-rules/design.json +0 -97
  47. package/dist/registry/ai-manager-rules/implement-phases/code.md +0 -323
  48. package/dist/registry/ai-manager-rules/implement-phases/completeness-review.md +0 -94
  49. package/dist/registry/ai-manager-rules/implement-phases/finalize.md +0 -177
  50. package/dist/registry/ai-manager-rules/implement-phases/quality-review.md +0 -304
  51. package/dist/registry/ai-manager-rules/implement-phases/regression.md +0 -159
  52. package/dist/registry/ai-manager-rules/implement-phases/repro.md +0 -101
  53. package/dist/registry/ai-manager-rules/implement-phases/scoping.md +0 -93
  54. package/dist/registry/ai-manager-rules/implement-phases/smoke.md +0 -225
  55. package/dist/registry/ai-manager-rules/implement-phases/spike.md +0 -118
  56. package/dist/registry/ai-manager-rules/implement-phases/validate.md +0 -347
  57. package/dist/registry/ai-manager-rules/implement.json +0 -153
  58. package/dist/registry/ai-manager-rules/shared-phases/finalize.md +0 -169
  59. package/dist/registry/ai-manager-rules/spec-phases/finalize.md +0 -60
  60. package/dist/registry/ai-manager-rules/spec-phases/spec.md +0 -102
  61. package/dist/registry/ai-manager-rules/spec-phases/validate.md +0 -118
  62. package/dist/registry/ai-manager-rules/spec.json +0 -112
  63. package/dist/registry/ai-manager-rules/test.json +0 -98
  64. package/dist/registry/scripts/build-scripts-generator.js +0 -205
  65. package/dist/registry/scripts/fraim-config.js +0 -61
  66. package/dist/registry/scripts/generic-issues-api.js +0 -100
  67. package/dist/registry/scripts/openapi-generator.js +0 -664
  68. package/dist/registry/scripts/performance/profile-server.js +0 -390
  69. package/dist/src/ai-manager/evidence-validator.js +0 -309
  70. package/dist/src/fraim/issue-tracking/ado-provider.js +0 -304
  71. package/dist/src/fraim/issue-tracking/factory.js +0 -63
  72. package/dist/src/fraim/issue-tracking/github-provider.js +0 -200
  73. package/dist/src/fraim/issue-tracking/types.js +0 -7
  74. package/dist/src/fraim/issue-tracking-config.js +0 -83
  75. package/dist/src/static-website-middleware.js +0 -75
  76. package/dist/test-utils.js +0 -96
  77. package/dist/tests/esm-compat.js +0 -11
  78. package/dist/tests/test-ai-manager-phase-protocol.js +0 -147
  79. package/dist/tests/test-ai-manager.js +0 -118
  80. package/dist/tests/test-chalk-esm-issue.js +0 -159
  81. package/dist/tests/test-chalk-real-world.js +0 -265
  82. package/dist/tests/test-chalk-regression.js +0 -377
  83. package/dist/tests/test-chalk-resolution-issue.js +0 -304
  84. package/dist/tests/test-evidence-validation.js +0 -221
  85. package/dist/tests/test-first-run-interactive.js +0 -1
  86. package/dist/tests/test-fraim-install-chalk-issue.js +0 -254
  87. package/dist/tests/test-markdown-to-pdf.js +0 -454
  88. package/dist/tests/test-npm-resolution-diagnostic.js +0 -140
  89. package/dist/tests/test-pr-review-integration.js +0 -1
  90. package/dist/website/.nojekyll +0 -0
  91. package/dist/website/404.html +0 -101
  92. package/dist/website/CNAME +0 -1
  93. package/dist/website/README.md +0 -22
  94. package/dist/website/demo.html +0 -604
  95. package/dist/website/images/.gitkeep +0 -1
  96. package/dist/website/images/fraim-logo.png +0 -0
  97. package/dist/website/index.html +0 -290
  98. package/dist/website/pricing.html +0 -414
  99. package/dist/website/script.js +0 -55
  100. package/dist/website/styles.css +0 -2647
@@ -1,366 +1,366 @@
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
+ #!/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
+ }