couchloop-eq-mcp 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -11
- package/dist/clients/shrinkChatClient.js +1 -1
- package/dist/clients/shrinkChatClient.js.map +1 -1
- package/dist/developer/analyzers/bloat-detector.d.ts +89 -0
- package/dist/developer/analyzers/bloat-detector.d.ts.map +1 -0
- package/dist/developer/analyzers/bloat-detector.js +483 -0
- package/dist/developer/analyzers/bloat-detector.js.map +1 -0
- package/dist/developer/backup/auto-backup.d.ts +96 -0
- package/dist/developer/backup/auto-backup.d.ts.map +1 -0
- package/dist/developer/backup/auto-backup.js +346 -0
- package/dist/developer/backup/auto-backup.js.map +1 -0
- package/dist/developer/blockers/package-blocker.d.ts +33 -0
- package/dist/developer/blockers/package-blocker.d.ts.map +1 -0
- package/dist/developer/blockers/package-blocker.js +224 -0
- package/dist/developer/blockers/package-blocker.js.map +1 -0
- package/dist/developer/evaluators/ai-error-preventer.d.ts +54 -0
- package/dist/developer/evaluators/ai-error-preventer.d.ts.map +1 -0
- package/dist/developer/evaluators/ai-error-preventer.js +270 -0
- package/dist/developer/evaluators/ai-error-preventer.js.map +1 -0
- package/dist/developer/evaluators/build-context-detector.d.ts +44 -0
- package/dist/developer/evaluators/build-context-detector.d.ts.map +1 -0
- package/dist/developer/evaluators/build-context-detector.js +258 -0
- package/dist/developer/evaluators/build-context-detector.js.map +1 -0
- package/dist/developer/evaluators/package-evaluator.d.ts +37 -0
- package/dist/developer/evaluators/package-evaluator.d.ts.map +1 -0
- package/dist/developer/evaluators/package-evaluator.js +278 -0
- package/dist/developer/evaluators/package-evaluator.js.map +1 -0
- package/dist/developer/guards/file-guardian.d.ts +79 -0
- package/dist/developer/guards/file-guardian.d.ts.map +1 -0
- package/dist/developer/guards/file-guardian.js +309 -0
- package/dist/developer/guards/file-guardian.js.map +1 -0
- package/dist/developer/managers/context-manager.d.ts +61 -0
- package/dist/developer/managers/context-manager.d.ts.map +1 -0
- package/dist/developer/managers/context-manager.js +302 -0
- package/dist/developer/managers/context-manager.js.map +1 -0
- package/dist/developer/metrics/complexity-calculator.d.ts +52 -0
- package/dist/developer/metrics/complexity-calculator.d.ts.map +1 -0
- package/dist/developer/metrics/complexity-calculator.js +259 -0
- package/dist/developer/metrics/complexity-calculator.js.map +1 -0
- package/dist/developer/reports/review-summary.d.ts +49 -0
- package/dist/developer/reports/review-summary.d.ts.map +1 -0
- package/dist/developer/reports/review-summary.js +249 -0
- package/dist/developer/reports/review-summary.js.map +1 -0
- package/dist/developer/scanners/review-assistant.d.ts +41 -0
- package/dist/developer/scanners/review-assistant.d.ts.map +1 -0
- package/dist/developer/scanners/review-assistant.js +374 -0
- package/dist/developer/scanners/review-assistant.js.map +1 -0
- package/dist/developer/scanners/secret-scanner.d.ts +66 -0
- package/dist/developer/scanners/secret-scanner.d.ts.map +1 -0
- package/dist/developer/scanners/secret-scanner.js +287 -0
- package/dist/developer/scanners/secret-scanner.js.map +1 -0
- package/dist/developer/scanners/sql-injection-detector.d.ts +54 -0
- package/dist/developer/scanners/sql-injection-detector.d.ts.map +1 -0
- package/dist/developer/scanners/sql-injection-detector.js +174 -0
- package/dist/developer/scanners/sql-injection-detector.js.map +1 -0
- package/dist/developer/scanners/xss-detector.d.ts +60 -0
- package/dist/developer/scanners/xss-detector.d.ts.map +1 -0
- package/dist/developer/scanners/xss-detector.js +229 -0
- package/dist/developer/scanners/xss-detector.js.map +1 -0
- package/dist/developer/types/ai-errors.d.ts +34 -0
- package/dist/developer/types/ai-errors.d.ts.map +1 -0
- package/dist/developer/types/ai-errors.js +271 -0
- package/dist/developer/types/ai-errors.js.map +1 -0
- package/dist/developer/types/package.d.ts +32 -0
- package/dist/developer/types/package.d.ts.map +1 -0
- package/dist/developer/types/package.js +5 -0
- package/dist/developer/types/package.js.map +1 -0
- package/dist/developer/updaters/dependency-updater.d.ts +102 -0
- package/dist/developer/updaters/dependency-updater.d.ts.map +1 -0
- package/dist/developer/updaters/dependency-updater.js +472 -0
- package/dist/developer/updaters/dependency-updater.js.map +1 -0
- package/dist/developer/validators/cargo.d.ts +14 -0
- package/dist/developer/validators/cargo.d.ts.map +1 -0
- package/dist/developer/validators/cargo.js +132 -0
- package/dist/developer/validators/cargo.js.map +1 -0
- package/dist/developer/validators/gem.d.ts +14 -0
- package/dist/developer/validators/gem.d.ts.map +1 -0
- package/dist/developer/validators/gem.js +85 -0
- package/dist/developer/validators/gem.js.map +1 -0
- package/dist/developer/validators/go.d.ts +14 -0
- package/dist/developer/validators/go.d.ts.map +1 -0
- package/dist/developer/validators/go.js +138 -0
- package/dist/developer/validators/go.js.map +1 -0
- package/dist/developer/validators/maven.d.ts +14 -0
- package/dist/developer/validators/maven.d.ts.map +1 -0
- package/dist/developer/validators/maven.js +99 -0
- package/dist/developer/validators/maven.js.map +1 -0
- package/dist/developer/validators/npm.d.ts +14 -0
- package/dist/developer/validators/npm.d.ts.map +1 -0
- package/dist/developer/validators/npm.js +96 -0
- package/dist/developer/validators/npm.js.map +1 -0
- package/dist/developer/validators/nuget.d.ts +15 -0
- package/dist/developer/validators/nuget.d.ts.map +1 -0
- package/dist/developer/validators/nuget.js +107 -0
- package/dist/developer/validators/nuget.js.map +1 -0
- package/dist/developer/validators/pypi.d.ts +14 -0
- package/dist/developer/validators/pypi.d.ts.map +1 -0
- package/dist/developer/validators/pypi.js +118 -0
- package/dist/developer/validators/pypi.js.map +1 -0
- package/dist/developer/validators/registry-manager.d.ts +37 -0
- package/dist/developer/validators/registry-manager.d.ts.map +1 -0
- package/dist/developer/validators/registry-manager.js +89 -0
- package/dist/developer/validators/registry-manager.js.map +1 -0
- package/dist/developer/validators/version-checker.d.ts +145 -0
- package/dist/developer/validators/version-checker.d.ts.map +1 -0
- package/dist/developer/validators/version-checker.js +529 -0
- package/dist/developer/validators/version-checker.js.map +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware/auth.d.ts +7 -9
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/middleware/auth.js.map +1 -1
- package/dist/tools/check-versions.d.ts +100 -0
- package/dist/tools/check-versions.d.ts.map +1 -0
- package/dist/tools/check-versions.js +328 -0
- package/dist/tools/check-versions.js.map +1 -0
- package/dist/tools/detect-code-smell.d.ts +9 -0
- package/dist/tools/detect-code-smell.d.ts.map +1 -0
- package/dist/tools/detect-code-smell.js +231 -0
- package/dist/tools/detect-code-smell.js.map +1 -0
- package/dist/tools/index.d.ts +471 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +178 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/journey.js +1 -1
- package/dist/tools/journey.js.map +1 -1
- package/dist/tools/pre-review-code.d.ts +71 -0
- package/dist/tools/pre-review-code.d.ts.map +1 -0
- package/dist/tools/pre-review-code.js +159 -0
- package/dist/tools/pre-review-code.js.map +1 -0
- package/dist/tools/preserve-context.d.ts +27 -0
- package/dist/tools/preserve-context.d.ts.map +1 -0
- package/dist/tools/preserve-context.js +98 -0
- package/dist/tools/preserve-context.js.map +1 -0
- package/dist/tools/protect-files.d.ts +224 -0
- package/dist/tools/protect-files.d.ts.map +1 -0
- package/dist/tools/protect-files.js +286 -0
- package/dist/tools/protect-files.js.map +1 -0
- package/dist/tools/scan-security.d.ts +38 -0
- package/dist/tools/scan-security.d.ts.map +1 -0
- package/dist/tools/scan-security.js +237 -0
- package/dist/tools/scan-security.js.map +1 -0
- package/dist/tools/validate_packages.d.ts +8 -0
- package/dist/tools/validate_packages.d.ts.map +1 -0
- package/dist/tools/validate_packages.js +159 -0
- package/dist/tools/validate_packages.js.map +1 -0
- package/dist/types/auth.d.ts +18 -18
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +91 -36
- package/dist/types/auth.js.map +1 -1
- package/dist/types/context.d.ts +46 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +17 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/file-protection.d.ts +50 -0
- package/dist/types/file-protection.d.ts.map +1 -0
- package/dist/types/file-protection.js +9 -0
- package/dist/types/file-protection.js.map +1 -0
- package/dist/utils/errorHandler.d.ts.map +1 -1
- package/dist/utils/errorHandler.js +2 -1
- package/dist/utils/errorHandler.js.map +1 -1
- package/package.json +23 -2
- package/dist/db/migrate.d.ts +0 -4
- package/dist/db/migrate.d.ts.map +0 -1
- package/dist/db/migrate.js +0 -34
- package/dist/db/migrate.js.map +0 -1
- package/dist/db/migrations/schema.d.ts +0 -1074
- package/dist/db/migrations/schema.d.ts.map +0 -1
- package/dist/db/migrations/schema.js +0 -160
- package/dist/db/migrations/schema.js.map +0 -1
- package/dist/db/schema.d.ts +0 -1576
- package/dist/db/schema.d.ts.map +0 -1
- package/dist/db/schema.js +0 -204
- package/dist/db/schema.js.map +0 -1
- package/dist/db/seed.d.ts +0 -4
- package/dist/db/seed.d.ts.map +0 -1
- package/dist/db/seed.js +0 -57
- package/dist/db/seed.js.map +0 -1
- package/dist/db/seedOAuth.d.ts +0 -4
- package/dist/db/seedOAuth.d.ts.map +0 -1
- package/dist/db/seedOAuth.js +0 -76
- package/dist/db/seedOAuth.js.map +0 -1
- package/dist/governance/config.d.ts +0 -66
- package/dist/governance/config.d.ts.map +0 -1
- package/dist/governance/config.js +0 -238
- package/dist/governance/config.js.map +0 -1
- package/dist/governance/detectors/hallucination.d.ts +0 -61
- package/dist/governance/detectors/hallucination.d.ts.map +0 -1
- package/dist/governance/detectors/hallucination.js +0 -338
- package/dist/governance/detectors/hallucination.js.map +0 -1
- package/dist/governance/detectors/inconsistency.d.ts +0 -99
- package/dist/governance/detectors/inconsistency.d.ts.map +0 -1
- package/dist/governance/detectors/inconsistency.js +0 -548
- package/dist/governance/detectors/inconsistency.js.map +0 -1
- package/dist/governance/detectors/toneDrift.d.ts +0 -63
- package/dist/governance/detectors/toneDrift.d.ts.map +0 -1
- package/dist/governance/detectors/toneDrift.js +0 -421
- package/dist/governance/detectors/toneDrift.js.map +0 -1
- package/dist/governance/detectors/unsafeReasoning.d.ts +0 -54
- package/dist/governance/detectors/unsafeReasoning.d.ts.map +0 -1
- package/dist/governance/detectors/unsafeReasoning.js +0 -473
- package/dist/governance/detectors/unsafeReasoning.js.map +0 -1
- package/dist/governance/evaluationEngine.d.ts +0 -112
- package/dist/governance/evaluationEngine.d.ts.map +0 -1
- package/dist/governance/evaluationEngine.js +0 -265
- package/dist/governance/evaluationEngine.js.map +0 -1
- package/dist/governance/intervention.d.ts +0 -81
- package/dist/governance/intervention.d.ts.map +0 -1
- package/dist/governance/intervention.js +0 -405
- package/dist/governance/intervention.js.map +0 -1
- package/dist/server/oauth/anomalyDetection.d.ts +0 -146
- package/dist/server/oauth/anomalyDetection.d.ts.map +0 -1
- package/dist/server/oauth/anomalyDetection.js +0 -405
- package/dist/server/oauth/anomalyDetection.js.map +0 -1
- package/dist/server/oauth/authServer.d.ts +0 -61
- package/dist/server/oauth/authServer.d.ts.map +0 -1
- package/dist/server/oauth/authServer.js +0 -283
- package/dist/server/oauth/authServer.js.map +0 -1
- package/dist/server/oauth/dpop.d.ts +0 -135
- package/dist/server/oauth/dpop.d.ts.map +0 -1
- package/dist/server/oauth/dpop.js +0 -338
- package/dist/server/oauth/dpop.js.map +0 -1
- package/dist/server/oauth/gdpr/consent.d.ts +0 -173
- package/dist/server/oauth/gdpr/consent.d.ts.map +0 -1
- package/dist/server/oauth/gdpr/consent.js +0 -388
- package/dist/server/oauth/gdpr/consent.js.map +0 -1
- package/dist/server/oauth/gdpr/dataPortability.d.ts +0 -214
- package/dist/server/oauth/gdpr/dataPortability.d.ts.map +0 -1
- package/dist/server/oauth/gdpr/dataPortability.js +0 -486
- package/dist/server/oauth/gdpr/dataPortability.js.map +0 -1
- package/dist/server/oauth/gdpr/index.d.ts +0 -103
- package/dist/server/oauth/gdpr/index.d.ts.map +0 -1
- package/dist/server/oauth/gdpr/index.js +0 -273
- package/dist/server/oauth/gdpr/index.js.map +0 -1
- package/dist/server/oauth/gdpr/rightToErasure.d.ts +0 -184
- package/dist/server/oauth/gdpr/rightToErasure.d.ts.map +0 -1
- package/dist/server/oauth/gdpr/rightToErasure.js +0 -527
- package/dist/server/oauth/gdpr/rightToErasure.js.map +0 -1
- package/dist/server/oauth/monitoring/securityMonitor.d.ts +0 -218
- package/dist/server/oauth/monitoring/securityMonitor.d.ts.map +0 -1
- package/dist/server/oauth/monitoring/securityMonitor.js +0 -615
- package/dist/server/oauth/monitoring/securityMonitor.js.map +0 -1
- package/dist/server/oauth/pkce.d.ts +0 -61
- package/dist/server/oauth/pkce.d.ts.map +0 -1
- package/dist/server/oauth/pkce.js +0 -157
- package/dist/server/oauth/pkce.js.map +0 -1
- package/dist/server/oauth/providers/base.d.ts +0 -147
- package/dist/server/oauth/providers/base.d.ts.map +0 -1
- package/dist/server/oauth/providers/base.js +0 -312
- package/dist/server/oauth/providers/base.js.map +0 -1
- package/dist/server/oauth/providers/github.d.ts +0 -55
- package/dist/server/oauth/providers/github.d.ts.map +0 -1
- package/dist/server/oauth/providers/github.js +0 -225
- package/dist/server/oauth/providers/github.js.map +0 -1
- package/dist/server/oauth/providers/google.d.ts +0 -49
- package/dist/server/oauth/providers/google.d.ts.map +0 -1
- package/dist/server/oauth/providers/google.js +0 -153
- package/dist/server/oauth/providers/google.js.map +0 -1
- package/dist/server/oauth/providers/index.d.ts +0 -9
- package/dist/server/oauth/providers/index.d.ts.map +0 -1
- package/dist/server/oauth/providers/index.js +0 -24
- package/dist/server/oauth/providers/index.js.map +0 -1
- package/dist/server/oauth/refreshTokenRotation.d.ts +0 -114
- package/dist/server/oauth/refreshTokenRotation.d.ts.map +0 -1
- package/dist/server/oauth/refreshTokenRotation.js +0 -344
- package/dist/server/oauth/refreshTokenRotation.js.map +0 -1
- package/dist/server/oauth/security.d.ts +0 -101
- package/dist/server/oauth/security.d.ts.map +0 -1
- package/dist/server/oauth/security.js +0 -268
- package/dist/server/oauth/security.js.map +0 -1
- package/dist/server/oauth/tokenEncryption.d.ts +0 -80
- package/dist/server/oauth/tokenEncryption.d.ts.map +0 -1
- package/dist/server/oauth/tokenEncryption.js +0 -218
- package/dist/server/oauth/tokenEncryption.js.map +0 -1
- package/dist/tools/sendMessage-complex-backup.d.ts +0 -6
- package/dist/tools/sendMessage-complex-backup.d.ts.map +0 -1
- package/dist/tools/sendMessage-complex-backup.js +0 -545
- package/dist/tools/sendMessage-complex-backup.js.map +0 -1
- package/dist/tools/sendMessage-revised.d.ts +0 -11
- package/dist/tools/sendMessage-revised.d.ts.map +0 -1
- package/dist/tools/sendMessage-revised.js +0 -429
- package/dist/tools/sendMessage-revised.js.map +0 -1
- package/dist/tools/sendMessage-truly-simple.d.ts +0 -8
- package/dist/tools/sendMessage-truly-simple.d.ts.map +0 -1
- package/dist/tools/sendMessage-truly-simple.js +0 -299
- package/dist/tools/sendMessage-truly-simple.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Error Preventer
|
|
3
|
+
* Intercepts and prevents common AI coding errors before they cause problems
|
|
4
|
+
*/
|
|
5
|
+
import { AIErrorPattern } from '../types/ai-errors.js';
|
|
6
|
+
import { BuildContext } from './build-context-detector.js';
|
|
7
|
+
export interface ErrorPreventionResult {
|
|
8
|
+
code: string;
|
|
9
|
+
errors: Array<{
|
|
10
|
+
pattern: AIErrorPattern;
|
|
11
|
+
locations: Array<{
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
snippet: string;
|
|
15
|
+
}>;
|
|
16
|
+
fixed: boolean;
|
|
17
|
+
suggestion?: string;
|
|
18
|
+
}>;
|
|
19
|
+
warnings: string[];
|
|
20
|
+
fixed: boolean;
|
|
21
|
+
fixedCode?: string;
|
|
22
|
+
preventedErrors: string[];
|
|
23
|
+
buildContext?: BuildContext;
|
|
24
|
+
}
|
|
25
|
+
export declare class AIErrorPreventer {
|
|
26
|
+
private buildDetector;
|
|
27
|
+
private packageEvaluator;
|
|
28
|
+
constructor(projectRoot?: string);
|
|
29
|
+
/**
|
|
30
|
+
* Prevent AI errors in generated code
|
|
31
|
+
*/
|
|
32
|
+
preventErrors(code: string, language: string, options?: {
|
|
33
|
+
autoFix?: boolean;
|
|
34
|
+
checkBuildContext?: boolean;
|
|
35
|
+
patterns?: string[];
|
|
36
|
+
}): Promise<ErrorPreventionResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Detect a specific error pattern in code
|
|
39
|
+
*/
|
|
40
|
+
private detectPattern;
|
|
41
|
+
/**
|
|
42
|
+
* Fix a specific error pattern
|
|
43
|
+
*/
|
|
44
|
+
private fixPattern;
|
|
45
|
+
/**
|
|
46
|
+
* Fix import statements to add .js extensions for ESM
|
|
47
|
+
*/
|
|
48
|
+
private fixImportExtensions;
|
|
49
|
+
/**
|
|
50
|
+
* Generate report of prevented errors
|
|
51
|
+
*/
|
|
52
|
+
generateReport(result: ErrorPreventionResult): string;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=ai-error-preventer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-error-preventer.d.ts","sourceRoot":"","sources":["../../../src/developer/evaluators/ai-error-preventer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAoB,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAwB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGjF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC;QACZ,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACpE,KAAK,EAAE,OAAO,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,WAAW,CAAC,EAAE,MAAM;IAKhC;;OAEG;IACG,aAAa,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;QACP,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KAChB,GACL,OAAO,CAAC,qBAAqB,CAAC;IAuFjC;;OAEG;YACW,aAAa;IAgG3B;;OAEG;YACW,UAAU;IAiDxB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM;CAwDtD"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Error Preventer
|
|
3
|
+
* Intercepts and prevents common AI coding errors before they cause problems
|
|
4
|
+
*/
|
|
5
|
+
import { AI_ERROR_CATALOG, getCriticalErrors } from '../types/ai-errors.js';
|
|
6
|
+
import { BuildContextDetector } from './build-context-detector.js';
|
|
7
|
+
import { PackageEvaluator } from './package-evaluator.js';
|
|
8
|
+
export class AIErrorPreventer {
|
|
9
|
+
buildDetector;
|
|
10
|
+
packageEvaluator;
|
|
11
|
+
constructor(projectRoot) {
|
|
12
|
+
this.buildDetector = new BuildContextDetector(projectRoot);
|
|
13
|
+
this.packageEvaluator = new PackageEvaluator();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Prevent AI errors in generated code
|
|
17
|
+
*/
|
|
18
|
+
async preventErrors(code, language, options = {}) {
|
|
19
|
+
const result = {
|
|
20
|
+
code,
|
|
21
|
+
errors: [],
|
|
22
|
+
warnings: [],
|
|
23
|
+
fixed: false,
|
|
24
|
+
preventedErrors: []
|
|
25
|
+
};
|
|
26
|
+
// Step 1: Detect build context if requested
|
|
27
|
+
if (options.checkBuildContext) {
|
|
28
|
+
result.buildContext = await this.buildDetector.detect();
|
|
29
|
+
// Apply build context fixes
|
|
30
|
+
if (result.buildContext.requiresJsExtensions) {
|
|
31
|
+
code = this.fixImportExtensions(code, language);
|
|
32
|
+
result.preventedErrors.push('build-context-blindness');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Step 2: Check for critical error patterns
|
|
36
|
+
const patternsToCheck = options.patterns
|
|
37
|
+
? AI_ERROR_CATALOG.filter(p => options.patterns?.includes(p.id) || false)
|
|
38
|
+
: getCriticalErrors();
|
|
39
|
+
for (const pattern of patternsToCheck) {
|
|
40
|
+
const detection = await this.detectPattern(code, pattern, language);
|
|
41
|
+
if (detection.found) {
|
|
42
|
+
result.errors.push({
|
|
43
|
+
pattern,
|
|
44
|
+
locations: detection.locations,
|
|
45
|
+
fixed: false,
|
|
46
|
+
suggestion: detection.suggestion
|
|
47
|
+
});
|
|
48
|
+
if (options.autoFix === true && pattern.autoFixable) {
|
|
49
|
+
const fixedCode = await this.fixPattern(code, pattern, language);
|
|
50
|
+
if (fixedCode !== code) {
|
|
51
|
+
code = fixedCode;
|
|
52
|
+
const lastError = result.errors[result.errors.length - 1];
|
|
53
|
+
if (lastError) {
|
|
54
|
+
lastError.fixed = true;
|
|
55
|
+
}
|
|
56
|
+
result.preventedErrors.push(pattern.id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Step 3: Package validation (always check)
|
|
62
|
+
const languageWithTs = language;
|
|
63
|
+
const packages = this.packageEvaluator.extractPackages(code, languageWithTs);
|
|
64
|
+
if (packages.length > 0) {
|
|
65
|
+
const validationResults = await this.packageEvaluator.evaluateBatch(packages, { language: languageWithTs });
|
|
66
|
+
const invalidPackages = validationResults.filter(r => r.blocked);
|
|
67
|
+
if (invalidPackages.length > 0) {
|
|
68
|
+
result.warnings.push(`Found ${invalidPackages.length} invalid packages`);
|
|
69
|
+
result.preventedErrors.push('package-hallucination');
|
|
70
|
+
// Auto-fix package names if possible
|
|
71
|
+
if (options.autoFix === true) {
|
|
72
|
+
for (const pkg of invalidPackages) {
|
|
73
|
+
if (pkg.suggestions && pkg.suggestions.length === 1) {
|
|
74
|
+
code = code.replace(new RegExp(`(['"])${pkg.package.name}(['"])`, 'g'), `$1${pkg.suggestions[0]}$2`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Return final result
|
|
81
|
+
if (code !== result.code) {
|
|
82
|
+
result.fixed = true;
|
|
83
|
+
result.fixedCode = code;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Detect a specific error pattern in code
|
|
89
|
+
*/
|
|
90
|
+
async detectPattern(code, pattern, _language) {
|
|
91
|
+
const locations = [];
|
|
92
|
+
switch (pattern.id) {
|
|
93
|
+
case 'async-await-confusion': {
|
|
94
|
+
// Look for Promise-returning functions without await
|
|
95
|
+
const lines = code.split('\n');
|
|
96
|
+
lines.forEach((line, index) => {
|
|
97
|
+
if (line.includes('fetch(') || line.includes('axios') || line.includes('query')) {
|
|
98
|
+
if (!line.includes('await') && !line.includes('.then')) {
|
|
99
|
+
locations.push({
|
|
100
|
+
line: index + 1,
|
|
101
|
+
column: line.indexOf('fetch') || line.indexOf('axios') || 0,
|
|
102
|
+
snippet: line.trim()
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'sql-injection-prone': {
|
|
110
|
+
// Check for string concatenation in SQL queries
|
|
111
|
+
const sqlPattern = /(?:query|execute|prepare)\s*\(\s*[`'"].*?\$\{.*?\}|(?:query|execute|prepare)\s*\(\s*.*?\+/gi;
|
|
112
|
+
let match;
|
|
113
|
+
while ((match = sqlPattern.exec(code)) !== null) {
|
|
114
|
+
const line = code.substring(0, match.index).split('\n').length;
|
|
115
|
+
locations.push({
|
|
116
|
+
line,
|
|
117
|
+
column: match.index,
|
|
118
|
+
snippet: match[0]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'hardcoded-secrets': {
|
|
124
|
+
// Detect common secret patterns
|
|
125
|
+
const secretPatterns = [
|
|
126
|
+
/(?:api[_-]?key|apikey|secret|password|token)\s*[:=]\s*['"][^'"]{10,}['"]/gi,
|
|
127
|
+
/sk-[a-zA-Z0-9]{20,}/g,
|
|
128
|
+
/mongodb:\/\/[^:]+:[^@]+@/g
|
|
129
|
+
];
|
|
130
|
+
for (const secretPattern of secretPatterns) {
|
|
131
|
+
let match;
|
|
132
|
+
while ((match = secretPattern.exec(code)) !== null) {
|
|
133
|
+
const line = code.substring(0, match.index).split('\n').length;
|
|
134
|
+
locations.push({
|
|
135
|
+
line,
|
|
136
|
+
column: match.index,
|
|
137
|
+
snippet: match[0]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 'null-reference-error': {
|
|
144
|
+
// Look for property access chains without null checks
|
|
145
|
+
const chainPattern = /\b\w+(?:\.\w+){2,}/g;
|
|
146
|
+
let chainMatch;
|
|
147
|
+
while ((chainMatch = chainPattern.exec(code)) !== null) {
|
|
148
|
+
const chain = chainMatch[0];
|
|
149
|
+
// Check if there's optional chaining or null check nearby
|
|
150
|
+
const lineStart = code.lastIndexOf('\n', chainMatch.index) + 1;
|
|
151
|
+
const lineEnd = code.indexOf('\n', chainMatch.index);
|
|
152
|
+
const line = code.substring(lineStart, lineEnd === -1 ? undefined : lineEnd);
|
|
153
|
+
if (!line.includes('?.') && !line.includes('if (') && !line.includes('&& ')) {
|
|
154
|
+
locations.push({
|
|
155
|
+
line: code.substring(0, chainMatch.index).split('\n').length,
|
|
156
|
+
column: chainMatch.index - lineStart,
|
|
157
|
+
snippet: chain
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
found: locations.length > 0,
|
|
166
|
+
locations,
|
|
167
|
+
suggestion: pattern.prevention
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Fix a specific error pattern
|
|
172
|
+
*/
|
|
173
|
+
async fixPattern(code, pattern, _language) {
|
|
174
|
+
switch (pattern.id) {
|
|
175
|
+
case 'async-await-confusion':
|
|
176
|
+
// Add await to common async functions
|
|
177
|
+
code = code.replace(/(\s+)(fetch\()/g, '$1await $2');
|
|
178
|
+
code = code.replace(/(\s+)(axios\.\w+\()/g, '$1await $2');
|
|
179
|
+
break;
|
|
180
|
+
case 'sql-injection-prone':
|
|
181
|
+
// Convert to parameterized queries (basic example)
|
|
182
|
+
code = code.replace(/query\(`SELECT \* FROM (\w+) WHERE (\w+) = \$\{([^}]+)\}`\)/g, 'query("SELECT * FROM $1 WHERE $2 = ?", [$3])');
|
|
183
|
+
break;
|
|
184
|
+
case 'hardcoded-secrets':
|
|
185
|
+
// Replace with environment variables
|
|
186
|
+
code = code.replace(/(?:const|let|var)\s+(\w*(?:api[_-]?key|apikey|secret|password|token)\w*)\s*=\s*['"]([^'"]+)['"]/gi, 'const $1 = process.env.$1');
|
|
187
|
+
break;
|
|
188
|
+
case 'null-reference-error':
|
|
189
|
+
// Add optional chaining
|
|
190
|
+
code = code.replace(/(\b\w+)((?:\.\w+){2,})/g, (match, obj, chain) => {
|
|
191
|
+
// Don't modify if it's already using optional chaining
|
|
192
|
+
if (code[code.indexOf(match) - 1] === '?')
|
|
193
|
+
return match;
|
|
194
|
+
// Convert to optional chaining
|
|
195
|
+
return obj + chain.replace(/\./g, '?.');
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
case 'build-context-blindness':
|
|
199
|
+
// This is handled by fixImportExtensions
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
return code;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Fix import statements to add .js extensions for ESM
|
|
206
|
+
*/
|
|
207
|
+
fixImportExtensions(code, language) {
|
|
208
|
+
if (language !== 'javascript' && language !== 'typescript') {
|
|
209
|
+
return code;
|
|
210
|
+
}
|
|
211
|
+
// Fix import statements
|
|
212
|
+
code = code.replace(/from\s+['"](\.[^'"]+?)(?<!\.js|\.mjs|\.json|\.node)['"](\s|;|$)/g, 'from "$1.js"$2');
|
|
213
|
+
// Fix dynamic imports
|
|
214
|
+
code = code.replace(/import\s*\(\s*['"](\.[^'"]+?)(?<!\.js|\.mjs|\.json|\.node)['"]\s*\)/g, 'import("$1.js")');
|
|
215
|
+
return code;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Generate report of prevented errors
|
|
219
|
+
*/
|
|
220
|
+
generateReport(result) {
|
|
221
|
+
const lines = [
|
|
222
|
+
'🛡️ AI Error Prevention Report',
|
|
223
|
+
'='.repeat(40),
|
|
224
|
+
''
|
|
225
|
+
];
|
|
226
|
+
if (result.buildContext) {
|
|
227
|
+
lines.push('📦 Build Context:');
|
|
228
|
+
lines.push(` Language: ${result.buildContext.language}`);
|
|
229
|
+
lines.push(` Module System: ${result.buildContext.moduleSystem || 'unknown'}`);
|
|
230
|
+
lines.push(` Package Manager: ${result.buildContext.packageManager || 'unknown'}`);
|
|
231
|
+
if (result.buildContext.requiresJsExtensions) {
|
|
232
|
+
lines.push(' ⚠️ Requires .js extensions in imports');
|
|
233
|
+
}
|
|
234
|
+
lines.push('');
|
|
235
|
+
}
|
|
236
|
+
if (result.preventedErrors.length > 0) {
|
|
237
|
+
lines.push(`✅ Prevented ${result.preventedErrors.length} AI Errors:`);
|
|
238
|
+
for (const errorId of result.preventedErrors) {
|
|
239
|
+
const pattern = AI_ERROR_CATALOG.find(p => p.id === errorId);
|
|
240
|
+
if (pattern) {
|
|
241
|
+
lines.push(` • ${pattern.name} (${pattern.impact} impact)`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
lines.push('');
|
|
245
|
+
}
|
|
246
|
+
if (result.errors.length > 0) {
|
|
247
|
+
const unfixed = result.errors.filter(e => !e.fixed);
|
|
248
|
+
if (unfixed.length > 0) {
|
|
249
|
+
lines.push(`⚠️ ${unfixed.length} Issues Need Manual Review:`);
|
|
250
|
+
for (const error of unfixed) {
|
|
251
|
+
lines.push(` • ${error.pattern.name}`);
|
|
252
|
+
if (error.suggestion) {
|
|
253
|
+
lines.push(` Fix: ${error.suggestion}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (result.warnings.length > 0) {
|
|
259
|
+
lines.push('');
|
|
260
|
+
lines.push('📝 Warnings:');
|
|
261
|
+
result.warnings.forEach(w => lines.push(` • ${w}`));
|
|
262
|
+
}
|
|
263
|
+
lines.push('');
|
|
264
|
+
lines.push('-'.repeat(40));
|
|
265
|
+
lines.push(`Total Errors Prevented: ${result.preventedErrors.length}`);
|
|
266
|
+
lines.push(`Code Modified: ${result.fixed ? 'Yes' : 'No'}`);
|
|
267
|
+
return lines.join('\n');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=ai-error-preventer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-error-preventer.js","sourceRoot":"","sources":["../../../src/developer/evaluators/ai-error-preventer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAkB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAgB,MAAM,6BAA6B,CAAC;A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AC,UAAU,EAAE,CAAC;wBACrB,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;oBAC7C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,2BAA2B,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;QACvE,KAAK,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAE5D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build Context Detector - Prevents "Build Context Blindness" errors
|
|
3
|
+
* Detects project configuration to prevent AI agents from making incorrect assumptions
|
|
4
|
+
*/
|
|
5
|
+
export interface BuildContext {
|
|
6
|
+
language: 'javascript' | 'typescript' | 'python' | 'java' | 'unknown';
|
|
7
|
+
moduleSystem?: 'commonjs' | 'esm' | 'umd' | 'amd';
|
|
8
|
+
packageManager?: 'npm' | 'yarn' | 'pnpm' | 'pip' | 'maven' | 'gradle';
|
|
9
|
+
buildTool?: string;
|
|
10
|
+
tsConfig?: {
|
|
11
|
+
moduleResolution?: string;
|
|
12
|
+
module?: string;
|
|
13
|
+
target?: string;
|
|
14
|
+
strict?: boolean;
|
|
15
|
+
esModuleInterop?: boolean;
|
|
16
|
+
};
|
|
17
|
+
pythonVersion?: string;
|
|
18
|
+
nodeVersion?: string;
|
|
19
|
+
hasTypeScript: boolean;
|
|
20
|
+
requiresJsExtensions: boolean;
|
|
21
|
+
errors: string[];
|
|
22
|
+
warnings: string[];
|
|
23
|
+
aiGuidance: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare class BuildContextDetector {
|
|
26
|
+
private projectRoot;
|
|
27
|
+
constructor(projectRoot?: string);
|
|
28
|
+
/**
|
|
29
|
+
* Detect full build context to prevent AI errors
|
|
30
|
+
*/
|
|
31
|
+
detect(): Promise<BuildContext>;
|
|
32
|
+
private detectNodeContext;
|
|
33
|
+
private detectTypeScriptContext;
|
|
34
|
+
private detectPythonContext;
|
|
35
|
+
private detectJavaContext;
|
|
36
|
+
private generateAIGuidance;
|
|
37
|
+
private fileExists;
|
|
38
|
+
private findFirstExisting;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a build command based on detected context
|
|
41
|
+
*/
|
|
42
|
+
generateBuildCommand(context: BuildContext): string;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=build-context-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-context-detector.d.ts","sourceRoot":"","sources":["../../../src/developer/evaluators/build-context-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IACtE,YAAY,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAClD,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE;QACT,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,WAAW,CAAS;gBAEhB,WAAW,GAAE,MAAsB;IAI/C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;YA4BvB,iBAAiB;YA4DjB,uBAAuB;YA0CvB,mBAAmB;YAqCnB,iBAAiB;IAuB/B,OAAO,CAAC,kBAAkB;YAiCZ,UAAU;YASV,iBAAiB;IAS/B;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;CAkBpD"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build Context Detector - Prevents "Build Context Blindness" errors
|
|
3
|
+
* Detects project configuration to prevent AI agents from making incorrect assumptions
|
|
4
|
+
*/
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
export class BuildContextDetector {
|
|
8
|
+
projectRoot;
|
|
9
|
+
constructor(projectRoot = process.cwd()) {
|
|
10
|
+
this.projectRoot = projectRoot;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Detect full build context to prevent AI errors
|
|
14
|
+
*/
|
|
15
|
+
async detect() {
|
|
16
|
+
const context = {
|
|
17
|
+
language: 'unknown',
|
|
18
|
+
hasTypeScript: false,
|
|
19
|
+
requiresJsExtensions: false,
|
|
20
|
+
errors: [],
|
|
21
|
+
warnings: [],
|
|
22
|
+
aiGuidance: []
|
|
23
|
+
};
|
|
24
|
+
// Check for package.json (Node.js projects)
|
|
25
|
+
await this.detectNodeContext(context);
|
|
26
|
+
// Check for TypeScript
|
|
27
|
+
await this.detectTypeScriptContext(context);
|
|
28
|
+
// Check for Python
|
|
29
|
+
await this.detectPythonContext(context);
|
|
30
|
+
// Check for Java
|
|
31
|
+
await this.detectJavaContext(context);
|
|
32
|
+
// Generate AI guidance based on detected context
|
|
33
|
+
this.generateAIGuidance(context);
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
async detectNodeContext(context) {
|
|
37
|
+
try {
|
|
38
|
+
const packageJsonPath = path.join(this.projectRoot, 'package.json');
|
|
39
|
+
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
40
|
+
const pkg = JSON.parse(content);
|
|
41
|
+
context.language = 'javascript';
|
|
42
|
+
// Detect module system
|
|
43
|
+
if (pkg.type === 'module') {
|
|
44
|
+
context.moduleSystem = 'esm';
|
|
45
|
+
context.requiresJsExtensions = true;
|
|
46
|
+
context.aiGuidance.push('⚠️ ESM project: Use .js extensions in imports, even for TypeScript files');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
context.moduleSystem = 'commonjs';
|
|
50
|
+
}
|
|
51
|
+
// Detect package manager
|
|
52
|
+
const hasYarnLock = await this.fileExists('yarn.lock');
|
|
53
|
+
const hasPnpmLock = await this.fileExists('pnpm-lock.yaml');
|
|
54
|
+
if (hasPnpmLock) {
|
|
55
|
+
context.packageManager = 'pnpm';
|
|
56
|
+
}
|
|
57
|
+
else if (hasYarnLock) {
|
|
58
|
+
context.packageManager = 'yarn';
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
context.packageManager = 'npm';
|
|
62
|
+
}
|
|
63
|
+
// Check for TypeScript dependency
|
|
64
|
+
if (pkg.devDependencies?.typescript || pkg.dependencies?.typescript) {
|
|
65
|
+
context.hasTypeScript = true;
|
|
66
|
+
context.language = 'typescript';
|
|
67
|
+
}
|
|
68
|
+
// Detect build tools
|
|
69
|
+
if (pkg.scripts?.build) {
|
|
70
|
+
const buildScript = pkg.scripts.build;
|
|
71
|
+
if (buildScript.includes('tsc')) {
|
|
72
|
+
context.buildTool = 'tsc';
|
|
73
|
+
}
|
|
74
|
+
else if (buildScript.includes('webpack')) {
|
|
75
|
+
context.buildTool = 'webpack';
|
|
76
|
+
}
|
|
77
|
+
else if (buildScript.includes('vite')) {
|
|
78
|
+
context.buildTool = 'vite';
|
|
79
|
+
}
|
|
80
|
+
else if (buildScript.includes('rollup')) {
|
|
81
|
+
context.buildTool = 'rollup';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Extract Node version requirement
|
|
85
|
+
if (pkg.engines?.node) {
|
|
86
|
+
context.nodeVersion = pkg.engines.node;
|
|
87
|
+
context.aiGuidance.push(`Node version requirement: ${pkg.engines.node}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// Not a Node.js project
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async detectTypeScriptContext(context) {
|
|
95
|
+
try {
|
|
96
|
+
const tsconfigPath = path.join(this.projectRoot, 'tsconfig.json');
|
|
97
|
+
const content = await fs.readFile(tsconfigPath, 'utf-8');
|
|
98
|
+
// Remove comments for parsing
|
|
99
|
+
const jsonString = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
|
|
100
|
+
const tsconfig = JSON.parse(jsonString);
|
|
101
|
+
context.hasTypeScript = true;
|
|
102
|
+
context.language = 'typescript';
|
|
103
|
+
const compilerOptions = tsconfig.compilerOptions || {};
|
|
104
|
+
context.tsConfig = {
|
|
105
|
+
moduleResolution: compilerOptions.moduleResolution,
|
|
106
|
+
module: compilerOptions.module,
|
|
107
|
+
target: compilerOptions.target,
|
|
108
|
+
strict: compilerOptions.strict,
|
|
109
|
+
esModuleInterop: compilerOptions.esModuleInterop
|
|
110
|
+
};
|
|
111
|
+
// Critical: Check if .js extensions are required
|
|
112
|
+
if (compilerOptions.moduleResolution === 'node16' ||
|
|
113
|
+
compilerOptions.moduleResolution === 'nodenext' ||
|
|
114
|
+
compilerOptions.module === 'node16' ||
|
|
115
|
+
compilerOptions.module === 'nodenext') {
|
|
116
|
+
context.requiresJsExtensions = true;
|
|
117
|
+
context.warnings.push('TypeScript requires .js extensions in imports (ESM mode)');
|
|
118
|
+
context.aiGuidance.push('🚨 CRITICAL: Import all local modules with .js extension, not .ts!');
|
|
119
|
+
context.aiGuidance.push('Example: import { foo } from "./bar.js" (NOT "./bar" or "./bar.ts")');
|
|
120
|
+
}
|
|
121
|
+
// Check for strict mode
|
|
122
|
+
if (compilerOptions.strict) {
|
|
123
|
+
context.aiGuidance.push('Strict mode enabled: Type all variables and handle null/undefined');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
// No TypeScript config
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async detectPythonContext(context) {
|
|
131
|
+
try {
|
|
132
|
+
// Check for Python project files
|
|
133
|
+
const hasRequirements = await this.fileExists('requirements.txt');
|
|
134
|
+
const hasPipfile = await this.fileExists('Pipfile');
|
|
135
|
+
const hasSetupPy = await this.fileExists('setup.py');
|
|
136
|
+
const hasPyproject = await this.fileExists('pyproject.toml');
|
|
137
|
+
if (hasRequirements || hasPipfile || hasSetupPy || hasPyproject) {
|
|
138
|
+
context.language = 'python';
|
|
139
|
+
context.packageManager = 'pip';
|
|
140
|
+
if (hasPipfile) {
|
|
141
|
+
context.aiGuidance.push('Uses Pipenv for dependency management');
|
|
142
|
+
}
|
|
143
|
+
if (hasPyproject) {
|
|
144
|
+
const content = await fs.readFile(path.join(this.projectRoot, 'pyproject.toml'), 'utf-8');
|
|
145
|
+
if (content.includes('[tool.poetry]')) {
|
|
146
|
+
context.packageManager = 'pip'; // Could be poetry
|
|
147
|
+
context.aiGuidance.push('Uses Poetry for dependency management');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Try to detect Python version from .python-version or runtime.txt
|
|
151
|
+
const versionFile = await this.findFirstExisting(['.python-version', 'runtime.txt']);
|
|
152
|
+
if (versionFile) {
|
|
153
|
+
const version = await fs.readFile(path.join(this.projectRoot, versionFile), 'utf-8');
|
|
154
|
+
context.pythonVersion = version.trim();
|
|
155
|
+
context.aiGuidance.push(`Python version: ${context.pythonVersion}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
// Not a Python project
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async detectJavaContext(context) {
|
|
164
|
+
try {
|
|
165
|
+
const hasPom = await this.fileExists('pom.xml');
|
|
166
|
+
const hasGradle = await this.fileExists('build.gradle') || await this.fileExists('build.gradle.kts');
|
|
167
|
+
if (hasPom || hasGradle) {
|
|
168
|
+
context.language = 'java';
|
|
169
|
+
if (hasPom) {
|
|
170
|
+
context.packageManager = 'maven';
|
|
171
|
+
context.buildTool = 'maven';
|
|
172
|
+
context.aiGuidance.push('Maven project: Use mvn commands for building');
|
|
173
|
+
}
|
|
174
|
+
else if (hasGradle) {
|
|
175
|
+
context.packageManager = 'gradle';
|
|
176
|
+
context.buildTool = 'gradle';
|
|
177
|
+
context.aiGuidance.push('Gradle project: Use gradle or ./gradlew commands');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// Not a Java project
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
generateAIGuidance(context) {
|
|
186
|
+
// Add guidance to prevent common AI errors
|
|
187
|
+
if (context.requiresJsExtensions) {
|
|
188
|
+
context.errors.push('AI COMMON ERROR: Forgetting .js extensions in TypeScript ESM projects');
|
|
189
|
+
}
|
|
190
|
+
if (context.hasTypeScript && !context.tsConfig?.strict) {
|
|
191
|
+
context.warnings.push('TypeScript without strict mode - AI may generate unsafe code');
|
|
192
|
+
}
|
|
193
|
+
if (context.moduleSystem === 'esm') {
|
|
194
|
+
context.aiGuidance.push('Use "import" syntax, not "require"');
|
|
195
|
+
context.aiGuidance.push('Add "type": "module" in package.json if missing');
|
|
196
|
+
}
|
|
197
|
+
if (context.moduleSystem === 'commonjs') {
|
|
198
|
+
context.aiGuidance.push('Use "require" for CommonJS, or configure for ESM if needed');
|
|
199
|
+
}
|
|
200
|
+
// Package manager specific guidance
|
|
201
|
+
if (context.packageManager) {
|
|
202
|
+
const commands = {
|
|
203
|
+
npm: 'npm install',
|
|
204
|
+
yarn: 'yarn add',
|
|
205
|
+
pnpm: 'pnpm add',
|
|
206
|
+
pip: 'pip install',
|
|
207
|
+
maven: 'mvn dependency:get',
|
|
208
|
+
gradle: 'gradle dependencies'
|
|
209
|
+
};
|
|
210
|
+
context.aiGuidance.push(`Use "${commands[context.packageManager]}" for installing packages`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async fileExists(filename) {
|
|
214
|
+
try {
|
|
215
|
+
await fs.access(path.join(this.projectRoot, filename));
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async findFirstExisting(filenames) {
|
|
223
|
+
for (const filename of filenames) {
|
|
224
|
+
if (await this.fileExists(filename)) {
|
|
225
|
+
return filename;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Generate a build command based on detected context
|
|
232
|
+
*/
|
|
233
|
+
generateBuildCommand(context) {
|
|
234
|
+
if (context.buildTool === 'tsc') {
|
|
235
|
+
return 'npx tsc';
|
|
236
|
+
}
|
|
237
|
+
else if (context.packageManager === 'npm' && context.language === 'typescript') {
|
|
238
|
+
return 'npm run build';
|
|
239
|
+
}
|
|
240
|
+
else if (context.packageManager === 'yarn') {
|
|
241
|
+
return 'yarn build';
|
|
242
|
+
}
|
|
243
|
+
else if (context.packageManager === 'pnpm') {
|
|
244
|
+
return 'pnpm build';
|
|
245
|
+
}
|
|
246
|
+
else if (context.packageManager === 'maven') {
|
|
247
|
+
return 'mvn compile';
|
|
248
|
+
}
|
|
249
|
+
else if (context.packageManager === 'gradle') {
|
|
250
|
+
return './gradlew build';
|
|
251
|
+
}
|
|
252
|
+
else if (context.language === 'python') {
|
|
253
|
+
return 'python -m py_compile ./**/*.py';
|
|
254
|
+
}
|
|
255
|
+
return 'echo "No build step detected"';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=build-context-detector.js.map
|