zone-ai-agent 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gittignore +4 -0
- package/README.md +36 -0
- package/dist/api/server.js +136 -0
- package/dist/api/server.js.map +1 -0
- package/dist/apply/applyPatchPlan.js +17 -0
- package/dist/apply/applyPatchPlan.js.map +1 -0
- package/dist/apply/canApplyDecision.js +26 -0
- package/dist/apply/canApplyDecision.js.map +1 -0
- package/dist/apply/patchPlan.js +3 -0
- package/dist/apply/patchPlan.js.map +1 -0
- package/dist/apply/renderApplyResult.js +18 -0
- package/dist/apply/renderApplyResult.js.map +1 -0
- package/dist/apply/runApplyFlow.js +40 -0
- package/dist/apply/runApplyFlow.js.map +1 -0
- package/dist/apply/types.js +3 -0
- package/dist/apply/types.js.map +1 -0
- package/dist/audit/auditDiffIntelligence.js +3 -0
- package/dist/audit/auditDiffIntelligence.js.map +1 -0
- package/dist/audit/auditSnapshot.js +87 -0
- package/dist/audit/auditSnapshot.js.map +1 -0
- package/dist/audit/renderAuditDiff.js +64 -0
- package/dist/audit/renderAuditDiff.js.map +1 -0
- package/dist/audit/snapshotDiff.js +53 -0
- package/dist/audit/snapshotDiff.js.map +1 -0
- package/dist/audit/snapshotReader.js +31 -0
- package/dist/audit/snapshotReader.js.map +1 -0
- package/dist/audit/snapshotWriter.js +59 -0
- package/dist/audit/snapshotWriter.js.map +1 -0
- package/dist/ci/evaluateCiResult.js +142 -0
- package/dist/ci/evaluateCiResult.js.map +1 -0
- package/dist/cli/buildGeneratedPatchPlanPreview.js +65 -0
- package/dist/cli/buildGeneratedPatchPlanPreview.js.map +1 -0
- package/dist/cli/colors.js +28 -0
- package/dist/cli/colors.js.map +1 -0
- package/dist/cli/diffOutput.js +37 -0
- package/dist/cli/diffOutput.js.map +1 -0
- package/dist/cli/index.js +850 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/loadPatchPlan.js +52 -0
- package/dist/cli/loadPatchPlan.js.map +1 -0
- package/dist/cli/output.js +34 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/parseCliArgs.js +3 -0
- package/dist/cli/parseCliArgs.js.map +1 -0
- package/dist/cli/runGeneratedPatchPlanFlow.js +23 -0
- package/dist/cli/runGeneratedPatchPlanFlow.js.map +1 -0
- package/dist/components/LoginForm.js +64 -0
- package/dist/components/LoginForm.js.map +1 -0
- package/dist/core/analyzeCodePatterns.js +3 -0
- package/dist/core/analyzeCodePatterns.js.map +1 -0
- package/dist/core/applyLlmPatches.js +43 -0
- package/dist/core/applyLlmPatches.js.map +1 -0
- package/dist/core/buildConfidenceBreakdownFromSignals.js +33 -0
- package/dist/core/buildConfidenceBreakdownFromSignals.js.map +1 -0
- package/dist/core/buildDecisionAuditSnapshot.js +18 -0
- package/dist/core/buildDecisionAuditSnapshot.js.map +1 -0
- package/dist/core/buildDecisionTrace.js +113 -0
- package/dist/core/buildDecisionTrace.js.map +1 -0
- package/dist/core/buildFallbackPatchPlan.js +23 -0
- package/dist/core/buildFallbackPatchPlan.js.map +1 -0
- package/dist/core/buildFallbackPlan.js +25 -0
- package/dist/core/buildFallbackPlan.js.map +1 -0
- package/dist/core/buildSchemaAwareContext.js +49 -0
- package/dist/core/buildSchemaAwareContext.js.map +1 -0
- package/dist/core/buildTaskExecutionContext.js +70 -0
- package/dist/core/buildTaskExecutionContext.js.map +1 -0
- package/dist/core/ciEvaluator.js +83 -0
- package/dist/core/ciEvaluator.js.map +1 -0
- package/dist/core/computeRiskScore.js +43 -0
- package/dist/core/computeRiskScore.js.map +1 -0
- package/dist/core/computeRiskScoreDetails.js +106 -0
- package/dist/core/computeRiskScoreDetails.js.map +1 -0
- package/dist/core/confidenceGate.js +83 -0
- package/dist/core/confidenceGate.js.map +1 -0
- package/dist/core/decision/buildDecisionExplanation.js +91 -0
- package/dist/core/decision/buildDecisionExplanation.js.map +1 -0
- package/dist/core/decision/buildDecisionReasonCodes.js +65 -0
- package/dist/core/decision/buildDecisionReasonCodes.js.map +1 -0
- package/dist/core/decision/buildReasonSummaryLine.js +24 -0
- package/dist/core/decision/buildReasonSummaryLine.js.map +1 -0
- package/dist/core/decision/buildRecommendation.js +43 -0
- package/dist/core/decision/buildRecommendation.js.map +1 -0
- package/dist/core/decision/decideExecutionMode.js +125 -0
- package/dist/core/decision/decideExecutionMode.js.map +1 -0
- package/dist/core/decision/decisionReasonCodeMeta.js +91 -0
- package/dist/core/decision/decisionReasonCodeMeta.js.map +1 -0
- package/dist/core/decision/renderDecisionSummary.js +115 -0
- package/dist/core/decision/renderDecisionSummary.js.map +1 -0
- package/dist/core/detectResourceStorage.js +78 -0
- package/dist/core/detectResourceStorage.js.map +1 -0
- package/dist/core/formatOutput.js +53 -0
- package/dist/core/formatOutput.js.map +1 -0
- package/dist/core/intentAwareScore.js +35 -0
- package/dist/core/intentAwareScore.js.map +1 -0
- package/dist/core/loadSavedAgentResult.js +18 -0
- package/dist/core/loadSavedAgentResult.js.map +1 -0
- package/dist/core/normalizeIssues.js +50 -0
- package/dist/core/normalizeIssues.js.map +1 -0
- package/dist/core/normalizeSignals.js +40 -0
- package/dist/core/normalizeSignals.js.map +1 -0
- package/dist/core/output/zoneStageTypes.js +3 -0
- package/dist/core/output/zoneStageTypes.js.map +1 -0
- package/dist/core/patchRiskAnalyzer.js +50 -0
- package/dist/core/patchRiskAnalyzer.js.map +1 -0
- package/dist/core/renderRunAgentResult.js +77 -0
- package/dist/core/renderRunAgentResult.js.map +1 -0
- package/dist/core/result/buildApplyStageResult.js +61 -0
- package/dist/core/result/buildApplyStageResult.js.map +1 -0
- package/dist/core/result/buildCliViewModel.js +79 -0
- package/dist/core/result/buildCliViewModel.js.map +1 -0
- package/dist/core/result/buildConversionStageResult.js +62 -0
- package/dist/core/result/buildConversionStageResult.js.map +1 -0
- package/dist/core/result/buildDecisionStageResult.js +61 -0
- package/dist/core/result/buildDecisionStageResult.js.map +1 -0
- package/dist/core/result/buildExecutionResult.js +148 -0
- package/dist/core/result/buildExecutionResult.js.map +1 -0
- package/dist/core/result/buildPreviewStageResult.js +47 -0
- package/dist/core/result/buildPreviewStageResult.js.map +1 -0
- package/dist/core/result/buildSavedDecisionExplanation.js +52 -0
- package/dist/core/result/buildSavedDecisionExplanation.js.map +1 -0
- package/dist/core/result/buildSavedRecommendation.js +39 -0
- package/dist/core/result/buildSavedRecommendation.js.map +1 -0
- package/dist/core/result/buildStageResultV2.js +52 -0
- package/dist/core/result/buildStageResultV2.js.map +1 -0
- package/dist/core/result/renderBundledResult.js +47 -0
- package/dist/core/result/renderBundledResult.js.map +1 -0
- package/dist/core/result/renderCliResult.js +93 -0
- package/dist/core/result/renderCliResult.js.map +1 -0
- package/dist/core/result/scoreTopRisks.js +205 -0
- package/dist/core/result/scoreTopRisks.js.map +1 -0
- package/dist/core/runAgent.js +210 -0
- package/dist/core/runAgent.js.map +1 -0
- package/dist/core/runFeatureAgent.js +684 -0
- package/dist/core/runFeatureAgent.js.map +1 -0
- package/dist/core/runLlmPatchFlow.js +522 -0
- package/dist/core/runLlmPatchFlow.js.map +1 -0
- package/dist/core/saveAgentResult.js +234 -0
- package/dist/core/saveAgentResult.js.map +1 -0
- package/dist/core/scoring/computeConfidenceBreakdown.js +130 -0
- package/dist/core/scoring/computeConfidenceBreakdown.js.map +1 -0
- package/dist/core/scoring/computeConfidenceScore.js +37 -0
- package/dist/core/scoring/computeConfidenceScore.js.map +1 -0
- package/dist/core/scoring/confidenceRules.js +58 -0
- package/dist/core/scoring/confidenceRules.js.map +1 -0
- package/dist/core/scoring/confidenceScore.js +8 -0
- package/dist/core/scoring/confidenceScore.js.map +1 -0
- package/dist/core/selectRelevantBlocks.js +58 -0
- package/dist/core/selectRelevantBlocks.js.map +1 -0
- package/dist/core/selfHealingLoop.js +209 -0
- package/dist/core/selfHealingLoop.js.map +1 -0
- package/dist/core/taskIntentParser.js +165 -0
- package/dist/core/taskIntentParser.js.map +1 -0
- package/dist/core/types/agentResult.js +3 -0
- package/dist/core/types/agentResult.js.map +1 -0
- package/dist/core/types/risk.js +3 -0
- package/dist/core/types/risk.js.map +1 -0
- package/dist/core/validatePatchAgainstSchema.js +100 -0
- package/dist/core/validatePatchAgainstSchema.js.map +1 -0
- package/dist/core/validateSuggestedArchitecture.js +24 -0
- package/dist/core/validateSuggestedArchitecture.js.map +1 -0
- package/dist/engine/buildDecisionExplanation.js +114 -0
- package/dist/engine/buildDecisionExplanation.js.map +1 -0
- package/dist/engine/contradictionDetector.js +40 -0
- package/dist/engine/contradictionDetector.js.map +1 -0
- package/dist/engine/decisionEngine.js +19 -0
- package/dist/engine/decisionEngine.js.map +1 -0
- package/dist/llm/openaiClient.js +19 -0
- package/dist/llm/openaiClient.js.map +1 -0
- package/dist/llm/planFeature.js +57 -0
- package/dist/llm/planFeature.js.map +1 -0
- package/dist/llm/planFix.js +3 -0
- package/dist/llm/planFix.js.map +1 -0
- package/dist/llm/planFullPatch.js +62 -0
- package/dist/llm/planFullPatch.js.map +1 -0
- package/dist/llm/planPatchPreview.js +60 -0
- package/dist/llm/planPatchPreview.js.map +1 -0
- package/dist/llm/prompts.js +131 -0
- package/dist/llm/prompts.js.map +1 -0
- package/dist/llm/schemas.js +28 -0
- package/dist/llm/schemas.js.map +1 -0
- package/dist/patch/apply/formatApplyFlowResult.js +23 -0
- package/dist/patch/apply/formatApplyFlowResult.js.map +1 -0
- package/dist/patch/apply/renderApplyFlowResult.js +15 -0
- package/dist/patch/apply/renderApplyFlowResult.js.map +1 -0
- package/dist/patch/apply/runApplyFlow.js +88 -0
- package/dist/patch/apply/runApplyFlow.js.map +1 -0
- package/dist/patch/applyFlowTypes.js +3 -0
- package/dist/patch/applyFlowTypes.js.map +1 -0
- package/dist/patch/applyPatchPlan.js +117 -0
- package/dist/patch/applyPatchPlan.js.map +1 -0
- package/dist/patch/backupFile.js +23 -0
- package/dist/patch/backupFile.js.map +1 -0
- package/dist/patch/conversion/canConvertGeneratedPlanToPatchPlan.js +57 -0
- package/dist/patch/conversion/canConvertGeneratedPlanToPatchPlan.js.map +1 -0
- package/dist/patch/conversion/convertGeneratedPlanToPatchPlan.js +38 -0
- package/dist/patch/conversion/convertGeneratedPlanToPatchPlan.js.map +1 -0
- package/dist/patch/conversion/formatGeneratedPlanConversionFailure.js +17 -0
- package/dist/patch/conversion/formatGeneratedPlanConversionFailure.js.map +1 -0
- package/dist/patch/conversion/generatedPlanConversionFailureMeta.js +40 -0
- package/dist/patch/conversion/generatedPlanConversionFailureMeta.js.map +1 -0
- package/dist/patch/conversion/generatedPlanConversionTypes.js +3 -0
- package/dist/patch/conversion/generatedPlanConversionTypes.js.map +1 -0
- package/dist/patch/conversion/renderGeneratedPlanConversionFailure.js +16 -0
- package/dist/patch/conversion/renderGeneratedPlanConversionFailure.js.map +1 -0
- package/dist/patch/generatedPlanConversion.js +96 -0
- package/dist/patch/generatedPlanConversion.js.map +1 -0
- package/dist/patch/patchAnchors.js +3 -0
- package/dist/patch/patchAnchors.js.map +1 -0
- package/dist/patch/patchValidationRules.js +116 -0
- package/dist/patch/patchValidationRules.js.map +1 -0
- package/dist/patch/patchValidationTypes.js +3 -0
- package/dist/patch/patchValidationTypes.js.map +1 -0
- package/dist/patch/renderApplyFlowResult.js +26 -0
- package/dist/patch/renderApplyFlowResult.js.map +1 -0
- package/dist/patch/validatePatchPlan.js +148 -0
- package/dist/patch/validatePatchPlan.js.map +1 -0
- package/dist/patch-generation/buildGeneratedPatchPlan.js +94 -0
- package/dist/patch-generation/buildGeneratedPatchPlan.js.map +1 -0
- package/dist/patch-generation/buildPatchOperations.js +41 -0
- package/dist/patch-generation/buildPatchOperations.js.map +1 -0
- package/dist/patch-generation/classifyPatchIntent.js +62 -0
- package/dist/patch-generation/classifyPatchIntent.js.map +1 -0
- package/dist/patch-generation/formatGeneratedPatchPlanPreview.js +25 -0
- package/dist/patch-generation/formatGeneratedPatchPlanPreview.js.map +1 -0
- package/dist/patch-generation/generatePatchPlan.js +74 -0
- package/dist/patch-generation/generatePatchPlan.js.map +1 -0
- package/dist/patch-generation/generatedPatchPlanTypes.js +3 -0
- package/dist/patch-generation/generatedPatchPlanTypes.js.map +1 -0
- package/dist/patch-generation/isIntentAllowed.js +15 -0
- package/dist/patch-generation/isIntentAllowed.js.map +1 -0
- package/dist/patch-generation/renderGeneratedPatchPlan.js +62 -0
- package/dist/patch-generation/renderGeneratedPatchPlan.js.map +1 -0
- package/dist/prompts/developerPrompt.js +213 -0
- package/dist/prompts/developerPrompt.js.map +1 -0
- package/dist/prompts/fullPatchPrompt.js +82 -0
- package/dist/prompts/fullPatchPrompt.js.map +1 -0
- package/dist/prompts/patchPreviewPrompt.js +83 -0
- package/dist/prompts/patchPreviewPrompt.js.map +1 -0
- package/dist/prompts/planFeaturePrompt.js +73 -0
- package/dist/prompts/planFeaturePrompt.js.map +1 -0
- package/dist/prompts/testEngineerContext.js +184 -0
- package/dist/prompts/testEngineerContext.js.map +1 -0
- package/dist/prompts/testEngineerPrompt.js +135 -0
- package/dist/prompts/testEngineerPrompt.js.map +1 -0
- package/dist/repo/analyzeProjectPatterns.js +46 -0
- package/dist/repo/analyzeProjectPatterns.js.map +1 -0
- package/dist/repo/detectProjectStructure.js +45 -0
- package/dist/repo/detectProjectStructure.js.map +1 -0
- package/dist/repo/getGitChangedFiles.js +96 -0
- package/dist/repo/getGitChangedFiles.js.map +1 -0
- package/dist/repo/loadSchemaSnapshot.js +29 -0
- package/dist/repo/loadSchemaSnapshot.js.map +1 -0
- package/dist/repo/rankRelevantFiles.js +306 -0
- package/dist/repo/rankRelevantFiles.js.map +1 -0
- package/dist/repo/readProjectFiles.js +27 -0
- package/dist/repo/readProjectFiles.js.map +1 -0
- package/dist/repo/scanRepo.js +93 -0
- package/dist/repo/scanRepo.js.map +1 -0
- package/dist/repo/validateSuggestedFiles.js +66 -0
- package/dist/repo/validateSuggestedFiles.js.map +1 -0
- package/dist/roles/dataAnalystContext.js +155 -0
- package/dist/roles/dataAnalystContext.js.map +1 -0
- package/dist/roles/detectDataSchema.js +152 -0
- package/dist/roles/detectDataSchema.js.map +1 -0
- package/dist/roles/detectTestComplexity.js +74 -0
- package/dist/roles/detectTestComplexity.js.map +1 -0
- package/dist/roles/detectTestFramework.js +166 -0
- package/dist/roles/detectTestFramework.js.map +1 -0
- package/dist/roles/runDataAnalystFlow.js +221 -0
- package/dist/roles/runDataAnalystFlow.js.map +1 -0
- package/dist/roles/runTestEngineerFlow.js +266 -0
- package/dist/roles/runTestEngineerFlow.js.map +1 -0
- package/dist/roles/testEngineerContext.js +282 -0
- package/dist/roles/testEngineerContext.js.map +1 -0
- package/dist/roles/testOutputValidator.js +474 -0
- package/dist/roles/testOutputValidator.js.map +1 -0
- package/dist/types/agent.js +3 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/analysis.js +3 -0
- package/dist/types/analysis.js.map +1 -0
- package/dist/types/patch.js +3 -0
- package/dist/types/patch.js.map +1 -0
- package/dist/types/project.js +3 -0
- package/dist/types/project.js.map +1 -0
- package/dist/types/schema.js +3 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/utils/executionTracker.js +33 -0
- package/dist/utils/executionTracker.js.map +1 -0
- package/dist/utils/files.js +35 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/logger.js +179 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.js +14 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/trace.js +10 -0
- package/dist/utils/trace.js.map +1 -0
- package/dist/utils/validation.js +24 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +53 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +21 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeConfidenceBreakdown = computeConfidenceBreakdown;
|
|
4
|
+
exports.decideExecutionMode = decideExecutionMode;
|
|
5
|
+
exports.runFeatureAgent = runFeatureAgent;
|
|
6
|
+
const scanRepo_js_1 = require("../repo/scanRepo.js");
|
|
7
|
+
const detectProjectStructure_js_1 = require("../repo/detectProjectStructure.js");
|
|
8
|
+
const rankRelevantFiles_js_1 = require("../repo/rankRelevantFiles.js");
|
|
9
|
+
const readProjectFiles_js_1 = require("../repo/readProjectFiles.js");
|
|
10
|
+
const validateSuggestedFiles_js_1 = require("../repo/validateSuggestedFiles.js");
|
|
11
|
+
const loadSchemaSnapshot_js_1 = require("../repo/loadSchemaSnapshot.js");
|
|
12
|
+
const analyzeProjectPatterns_js_1 = require("../repo/analyzeProjectPatterns.js");
|
|
13
|
+
const planFeature_js_1 = require("../llm/planFeature.js");
|
|
14
|
+
const planPatchPreview_js_1 = require("../llm/planPatchPreview.js");
|
|
15
|
+
const buildFallbackPlan_js_1 = require("./buildFallbackPlan.js");
|
|
16
|
+
const buildFallbackPatchPlan_js_1 = require("./buildFallbackPatchPlan.js");
|
|
17
|
+
const applyPatchPlan_js_1 = require("../patch/applyPatchPlan.js");
|
|
18
|
+
const saveAgentResult_js_1 = require("./saveAgentResult.js");
|
|
19
|
+
const taskIntentParser_js_1 = require("./taskIntentParser.js");
|
|
20
|
+
const patchRiskAnalyzer_js_1 = require("./patchRiskAnalyzer.js");
|
|
21
|
+
const validateSuggestedArchitecture_js_1 = require("./validateSuggestedArchitecture.js");
|
|
22
|
+
const detectResourceStorage_js_1 = require("./detectResourceStorage.js");
|
|
23
|
+
const buildSchemaAwareContext_js_1 = require("./buildSchemaAwareContext.js");
|
|
24
|
+
const validatePatchAgainstSchema_js_1 = require("./validatePatchAgainstSchema.js");
|
|
25
|
+
const validatePatchPlan_js_1 = require("../patch/validatePatchPlan.js");
|
|
26
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
27
|
+
const normalizeIssues_js_1 = require("./normalizeIssues.js");
|
|
28
|
+
const CONFIDENCE_WEIGHTS = {
|
|
29
|
+
intentClarity: 0.24,
|
|
30
|
+
schemaCertainty: 0.23,
|
|
31
|
+
storageCertainty: 0.18,
|
|
32
|
+
patchValidationHealth: 0.35
|
|
33
|
+
};
|
|
34
|
+
const CONFIDENCE_THRESHOLDS = {
|
|
35
|
+
high: 85,
|
|
36
|
+
medium: 60,
|
|
37
|
+
previewMinimum: 70,
|
|
38
|
+
safeToApplyMinimum: 85
|
|
39
|
+
};
|
|
40
|
+
const PENALTY_RULES = {
|
|
41
|
+
intentWarningEach: 4,
|
|
42
|
+
intentWarningCap: 12,
|
|
43
|
+
patchWarningEach: 3,
|
|
44
|
+
patchWarningCap: 12,
|
|
45
|
+
schemaWarningEach: 3,
|
|
46
|
+
schemaWarningCap: 12,
|
|
47
|
+
patchRiskWarningEach: 6,
|
|
48
|
+
patchRiskWarningCap: 24,
|
|
49
|
+
architectureWarningEach: 5,
|
|
50
|
+
architectureWarningCap: 20,
|
|
51
|
+
validatedMissingFileEach: 7,
|
|
52
|
+
validatedMissingFileCap: 21,
|
|
53
|
+
lowSchemaConfidence: 12,
|
|
54
|
+
lowStorageConfidence: 12,
|
|
55
|
+
bothLowConfidenceExtra: 8
|
|
56
|
+
};
|
|
57
|
+
const HEALTH_PENALTIES = {
|
|
58
|
+
patchError: 45,
|
|
59
|
+
schemaError: 40,
|
|
60
|
+
patchWarning: 14,
|
|
61
|
+
schemaWarning: 12
|
|
62
|
+
};
|
|
63
|
+
const CHANGED_FILE_SCORE_BOOST = 25;
|
|
64
|
+
function hasResolvedPath(file) {
|
|
65
|
+
return typeof file.resolvedPath === "string" && file.resolvedPath.length > 0;
|
|
66
|
+
}
|
|
67
|
+
function clamp(value, min, max) {
|
|
68
|
+
return Math.max(min, Math.min(max, value));
|
|
69
|
+
}
|
|
70
|
+
function mapConfidenceLevel(score) {
|
|
71
|
+
if (score >= CONFIDENCE_THRESHOLDS.high)
|
|
72
|
+
return "high";
|
|
73
|
+
if (score >= CONFIDENCE_THRESHOLDS.medium)
|
|
74
|
+
return "medium";
|
|
75
|
+
return "low";
|
|
76
|
+
}
|
|
77
|
+
function uniqueStrings(values = []) {
|
|
78
|
+
return [...new Set(values.map((value) => value.trim()).filter(Boolean))];
|
|
79
|
+
}
|
|
80
|
+
function sumCappedPenalty(count, each, cap) {
|
|
81
|
+
return Math.min(count * each, cap);
|
|
82
|
+
}
|
|
83
|
+
function normalizeRepoPath(filePath) {
|
|
84
|
+
return filePath.replace(/\\/g, "/").trim();
|
|
85
|
+
}
|
|
86
|
+
function boostRelevantFilesWithChangedFiles(relevantFiles, changedFiles = []) {
|
|
87
|
+
if (changedFiles.length === 0) {
|
|
88
|
+
return relevantFiles;
|
|
89
|
+
}
|
|
90
|
+
const changedSet = new Set(changedFiles.map(normalizeRepoPath));
|
|
91
|
+
return [...relevantFiles]
|
|
92
|
+
.map((file) => {
|
|
93
|
+
const normalizedPath = normalizeRepoPath(file.path);
|
|
94
|
+
const isChanged = changedSet.has(normalizedPath);
|
|
95
|
+
return {
|
|
96
|
+
...file,
|
|
97
|
+
score: isChanged ? file.score + CHANGED_FILE_SCORE_BOOST : file.score
|
|
98
|
+
};
|
|
99
|
+
})
|
|
100
|
+
.sort((a, b) => b.score - a.score);
|
|
101
|
+
}
|
|
102
|
+
function buildPenaltyItem(input) {
|
|
103
|
+
if (input.appliedPenalty <= 0) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
code: input.code,
|
|
108
|
+
label: input.label,
|
|
109
|
+
count: input.count,
|
|
110
|
+
perItem: input.perItem,
|
|
111
|
+
cap: input.cap,
|
|
112
|
+
appliedPenalty: input.appliedPenalty
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function buildSchemaAwareSummaryFromContext(input) {
|
|
116
|
+
const entities = [];
|
|
117
|
+
if (input.intent.parentResource) {
|
|
118
|
+
entities.push(input.intent.parentResource);
|
|
119
|
+
}
|
|
120
|
+
if (input.intent.nestedResource) {
|
|
121
|
+
entities.push(input.intent.nestedResource);
|
|
122
|
+
}
|
|
123
|
+
const uniqueEntities = [...new Set(entities)];
|
|
124
|
+
const summaryLines = input.schemaAwareContext.summaryLines ?? [];
|
|
125
|
+
const confidence = input.schemaSnapshot && summaryLines.length > 0
|
|
126
|
+
? "high"
|
|
127
|
+
: summaryLines.length > 0
|
|
128
|
+
? "medium"
|
|
129
|
+
: "low";
|
|
130
|
+
return {
|
|
131
|
+
summary: summaryLines.join(" ").trim() ||
|
|
132
|
+
"Schema-aware analysis could not extract strong structured signals.",
|
|
133
|
+
entities: uniqueEntities,
|
|
134
|
+
relations: [],
|
|
135
|
+
confidence
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function scoreIntentClarity(intent) {
|
|
139
|
+
let score = 25;
|
|
140
|
+
if (intent.action)
|
|
141
|
+
score += 20;
|
|
142
|
+
if (intent.resourceKind)
|
|
143
|
+
score += 15;
|
|
144
|
+
if (intent.scope)
|
|
145
|
+
score += 10;
|
|
146
|
+
if (intent.parentResource)
|
|
147
|
+
score += 10;
|
|
148
|
+
if (intent.nestedResource)
|
|
149
|
+
score += 5;
|
|
150
|
+
if (intent.warnings.length > 0) {
|
|
151
|
+
score -= sumCappedPenalty(intent.warnings.length, PENALTY_RULES.intentWarningEach, PENALTY_RULES.intentWarningCap);
|
|
152
|
+
}
|
|
153
|
+
return clamp(score, 0, 100);
|
|
154
|
+
}
|
|
155
|
+
function scoreSchemaCertainty(confidence) {
|
|
156
|
+
if (confidence === "high")
|
|
157
|
+
return 88;
|
|
158
|
+
if (confidence === "medium")
|
|
159
|
+
return 58;
|
|
160
|
+
return 20;
|
|
161
|
+
}
|
|
162
|
+
function scoreStorageCertainty(confidence) {
|
|
163
|
+
if (confidence === "high")
|
|
164
|
+
return 85;
|
|
165
|
+
if (confidence === "medium")
|
|
166
|
+
return 55;
|
|
167
|
+
return 18;
|
|
168
|
+
}
|
|
169
|
+
function scorePatchValidationHealth(patchIssues, schemaIssues) {
|
|
170
|
+
let score = 100;
|
|
171
|
+
const patchErrors = patchIssues.filter((item) => item.severity === "error").length;
|
|
172
|
+
const patchWarnings = patchIssues.filter((item) => item.severity === "warning").length;
|
|
173
|
+
const schemaErrors = schemaIssues.filter((item) => item.severity === "error").length;
|
|
174
|
+
const schemaWarnings = schemaIssues.filter((item) => item.severity === "warning").length;
|
|
175
|
+
score -= patchErrors * HEALTH_PENALTIES.patchError;
|
|
176
|
+
score -= schemaErrors * HEALTH_PENALTIES.schemaError;
|
|
177
|
+
score -= patchWarnings * HEALTH_PENALTIES.patchWarning;
|
|
178
|
+
score -= schemaWarnings * HEALTH_PENALTIES.schemaWarning;
|
|
179
|
+
return clamp(score, 0, 100);
|
|
180
|
+
}
|
|
181
|
+
function buildConfidenceDetails(input) {
|
|
182
|
+
const penalties = [];
|
|
183
|
+
const patchRiskWarnings = uniqueStrings(input.patchRiskWarnings);
|
|
184
|
+
const architectureWarnings = uniqueStrings(input.architectureWarnings);
|
|
185
|
+
const validatedMissingFileCount = input.validatedSuggestedFiles.filter((file) => file.status === "missing").length;
|
|
186
|
+
const patchWarningCount = input.patchValidationIssues.filter((item) => item.severity === "warning").length;
|
|
187
|
+
const schemaWarningCount = input.schemaPatchWarnings.filter((item) => item.severity === "warning").length;
|
|
188
|
+
const intentPenalty = sumCappedPenalty(input.intent.warnings.length, PENALTY_RULES.intentWarningEach, PENALTY_RULES.intentWarningCap);
|
|
189
|
+
const patchPenalty = sumCappedPenalty(patchWarningCount, PENALTY_RULES.patchWarningEach, PENALTY_RULES.patchWarningCap);
|
|
190
|
+
const schemaPenalty = sumCappedPenalty(schemaWarningCount, PENALTY_RULES.schemaWarningEach, PENALTY_RULES.schemaWarningCap);
|
|
191
|
+
const patchRiskPenalty = sumCappedPenalty(patchRiskWarnings.length, PENALTY_RULES.patchRiskWarningEach, PENALTY_RULES.patchRiskWarningCap);
|
|
192
|
+
const architecturePenalty = sumCappedPenalty(architectureWarnings.length, PENALTY_RULES.architectureWarningEach, PENALTY_RULES.architectureWarningCap);
|
|
193
|
+
const missingFilePenalty = sumCappedPenalty(validatedMissingFileCount, PENALTY_RULES.validatedMissingFileEach, PENALTY_RULES.validatedMissingFileCap);
|
|
194
|
+
const lowSchemaPenalty = input.schemaConfidence === "low" ? PENALTY_RULES.lowSchemaConfidence : 0;
|
|
195
|
+
const lowStoragePenalty = input.storageConfidence === "low" ? PENALTY_RULES.lowStorageConfidence : 0;
|
|
196
|
+
const bothLowPenalty = input.schemaConfidence === "low" && input.storageConfidence === "low"
|
|
197
|
+
? PENALTY_RULES.bothLowConfidenceExtra
|
|
198
|
+
: 0;
|
|
199
|
+
const maybeItems = [
|
|
200
|
+
buildPenaltyItem({
|
|
201
|
+
code: "INTENT_WARNINGS",
|
|
202
|
+
label: "Intent warnings",
|
|
203
|
+
count: input.intent.warnings.length,
|
|
204
|
+
perItem: PENALTY_RULES.intentWarningEach,
|
|
205
|
+
cap: PENALTY_RULES.intentWarningCap,
|
|
206
|
+
appliedPenalty: intentPenalty
|
|
207
|
+
}),
|
|
208
|
+
buildPenaltyItem({
|
|
209
|
+
code: "PATCH_WARNINGS",
|
|
210
|
+
label: "Patch validation warnings",
|
|
211
|
+
count: patchWarningCount,
|
|
212
|
+
perItem: PENALTY_RULES.patchWarningEach,
|
|
213
|
+
cap: PENALTY_RULES.patchWarningCap,
|
|
214
|
+
appliedPenalty: patchPenalty
|
|
215
|
+
}),
|
|
216
|
+
buildPenaltyItem({
|
|
217
|
+
code: "SCHEMA_WARNINGS",
|
|
218
|
+
label: "Schema validation warnings",
|
|
219
|
+
count: schemaWarningCount,
|
|
220
|
+
perItem: PENALTY_RULES.schemaWarningEach,
|
|
221
|
+
cap: PENALTY_RULES.schemaWarningCap,
|
|
222
|
+
appliedPenalty: schemaPenalty
|
|
223
|
+
}),
|
|
224
|
+
buildPenaltyItem({
|
|
225
|
+
code: "PATCH_RISK_WARNINGS",
|
|
226
|
+
label: "Patch risk warnings",
|
|
227
|
+
count: patchRiskWarnings.length,
|
|
228
|
+
perItem: PENALTY_RULES.patchRiskWarningEach,
|
|
229
|
+
cap: PENALTY_RULES.patchRiskWarningCap,
|
|
230
|
+
appliedPenalty: patchRiskPenalty
|
|
231
|
+
}),
|
|
232
|
+
buildPenaltyItem({
|
|
233
|
+
code: "ARCHITECTURE_WARNINGS",
|
|
234
|
+
label: "Architecture warnings",
|
|
235
|
+
count: architectureWarnings.length,
|
|
236
|
+
perItem: PENALTY_RULES.architectureWarningEach,
|
|
237
|
+
cap: PENALTY_RULES.architectureWarningCap,
|
|
238
|
+
appliedPenalty: architecturePenalty
|
|
239
|
+
}),
|
|
240
|
+
buildPenaltyItem({
|
|
241
|
+
code: "MISSING_VALIDATED_FILES",
|
|
242
|
+
label: "Missing validated suggested files",
|
|
243
|
+
count: validatedMissingFileCount,
|
|
244
|
+
perItem: PENALTY_RULES.validatedMissingFileEach,
|
|
245
|
+
cap: PENALTY_RULES.validatedMissingFileCap,
|
|
246
|
+
appliedPenalty: missingFilePenalty
|
|
247
|
+
}),
|
|
248
|
+
buildPenaltyItem({
|
|
249
|
+
code: "LOW_SCHEMA_CONFIDENCE",
|
|
250
|
+
label: "Low schema confidence",
|
|
251
|
+
appliedPenalty: lowSchemaPenalty
|
|
252
|
+
}),
|
|
253
|
+
buildPenaltyItem({
|
|
254
|
+
code: "LOW_STORAGE_CONFIDENCE",
|
|
255
|
+
label: "Low storage confidence",
|
|
256
|
+
appliedPenalty: lowStoragePenalty
|
|
257
|
+
}),
|
|
258
|
+
buildPenaltyItem({
|
|
259
|
+
code: "BOTH_LOW_CONFIDENCE",
|
|
260
|
+
label: "Schema and storage both low confidence",
|
|
261
|
+
appliedPenalty: bothLowPenalty
|
|
262
|
+
})
|
|
263
|
+
];
|
|
264
|
+
for (const item of maybeItems) {
|
|
265
|
+
if (item)
|
|
266
|
+
penalties.push(item);
|
|
267
|
+
}
|
|
268
|
+
const totalPenalty = penalties.reduce((sum, item) => sum + item.appliedPenalty, 0);
|
|
269
|
+
return {
|
|
270
|
+
baseWeightedScore: Math.round(input.baseWeightedScore * 100) / 100,
|
|
271
|
+
totalPenalty,
|
|
272
|
+
penalties
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function computeConfidenceBreakdown(input) {
|
|
276
|
+
const intentClarity = scoreIntentClarity(input.intent);
|
|
277
|
+
const schemaCertainty = scoreSchemaCertainty(input.schemaConfidence);
|
|
278
|
+
const storageCertainty = scoreStorageCertainty(input.storageConfidence);
|
|
279
|
+
const patchValidationHealth = scorePatchValidationHealth(input.patchValidationIssues, input.schemaPatchWarnings);
|
|
280
|
+
const baseWeightedScore = intentClarity * CONFIDENCE_WEIGHTS.intentClarity +
|
|
281
|
+
schemaCertainty * CONFIDENCE_WEIGHTS.schemaCertainty +
|
|
282
|
+
storageCertainty * CONFIDENCE_WEIGHTS.storageCertainty +
|
|
283
|
+
patchValidationHealth * CONFIDENCE_WEIGHTS.patchValidationHealth;
|
|
284
|
+
const confidenceDetails = buildConfidenceDetails({
|
|
285
|
+
baseWeightedScore,
|
|
286
|
+
intent: input.intent,
|
|
287
|
+
patchValidationIssues: input.patchValidationIssues,
|
|
288
|
+
schemaPatchWarnings: input.schemaPatchWarnings,
|
|
289
|
+
patchRiskWarnings: input.patchRiskWarnings,
|
|
290
|
+
architectureWarnings: input.architectureWarnings,
|
|
291
|
+
validatedSuggestedFiles: input.validatedSuggestedFiles,
|
|
292
|
+
schemaConfidence: input.schemaConfidence,
|
|
293
|
+
storageConfidence: input.storageConfidence
|
|
294
|
+
});
|
|
295
|
+
const finalScore = clamp(Math.round(baseWeightedScore - confidenceDetails.totalPenalty), 0, 100);
|
|
296
|
+
return {
|
|
297
|
+
confidence: {
|
|
298
|
+
intentClarity,
|
|
299
|
+
schemaCertainty,
|
|
300
|
+
storageCertainty,
|
|
301
|
+
patchValidationHealth,
|
|
302
|
+
finalScore
|
|
303
|
+
},
|
|
304
|
+
confidenceDetails
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function decideExecutionMode(input) {
|
|
308
|
+
const patchRiskWarnings = uniqueStrings(input.patchRiskWarnings);
|
|
309
|
+
const architectureWarnings = uniqueStrings(input.architectureWarnings);
|
|
310
|
+
const hasMissingValidatedFile = input.validatedSuggestedFiles.some((file) => file.status === "missing");
|
|
311
|
+
const hasPatchError = input.patchValidationIssues.some((item) => item.severity === "error");
|
|
312
|
+
const hasSchemaError = input.schemaPatchWarnings.some((item) => item.severity === "error");
|
|
313
|
+
const hasWarnings = input.patchValidationIssues.some((item) => item.severity === "warning") ||
|
|
314
|
+
input.schemaPatchWarnings.some((item) => item.severity === "warning") ||
|
|
315
|
+
patchRiskWarnings.length > 0 ||
|
|
316
|
+
architectureWarnings.length > 0 ||
|
|
317
|
+
hasMissingValidatedFile;
|
|
318
|
+
if (hasPatchError || hasSchemaError) {
|
|
319
|
+
return {
|
|
320
|
+
mode: "blocked",
|
|
321
|
+
confidenceScore: input.confidence.finalScore,
|
|
322
|
+
reason: "Blocking validation errors were detected."
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (input.confidence.finalScore < CONFIDENCE_THRESHOLDS.previewMinimum) {
|
|
326
|
+
return {
|
|
327
|
+
mode: "preview_only",
|
|
328
|
+
confidenceScore: input.confidence.finalScore,
|
|
329
|
+
reason: "Confidence is below the minimum threshold for safe apply."
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (hasMissingValidatedFile) {
|
|
333
|
+
return {
|
|
334
|
+
mode: "preview_only",
|
|
335
|
+
confidenceScore: input.confidence.finalScore,
|
|
336
|
+
reason: "Some suggested files could not be validated confidently."
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (input.schemaConfidence === "low" || input.storageConfidence === "low") {
|
|
340
|
+
return {
|
|
341
|
+
mode: "preview_only",
|
|
342
|
+
confidenceScore: input.confidence.finalScore,
|
|
343
|
+
reason: "Schema or storage certainty is too low for automatic apply."
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (patchRiskWarnings.length > 0 || architectureWarnings.length > 0) {
|
|
347
|
+
return {
|
|
348
|
+
mode: "preview_only",
|
|
349
|
+
confidenceScore: input.confidence.finalScore,
|
|
350
|
+
reason: "Risk or architecture warnings require manual review."
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
if (hasWarnings) {
|
|
354
|
+
return {
|
|
355
|
+
mode: "preview_only",
|
|
356
|
+
confidenceScore: input.confidence.finalScore,
|
|
357
|
+
reason: "Non-blocking warnings detected. Manual review is required."
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (input.confidence.finalScore < CONFIDENCE_THRESHOLDS.safeToApplyMinimum) {
|
|
361
|
+
return {
|
|
362
|
+
mode: "preview_only",
|
|
363
|
+
confidenceScore: input.confidence.finalScore,
|
|
364
|
+
reason: "Only highly confident clean runs are allowed to apply."
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
mode: "safe_to_apply",
|
|
369
|
+
confidenceScore: input.confidence.finalScore,
|
|
370
|
+
reason: "Validation passed cleanly with high confidence."
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function buildExecutionNotes(input) {
|
|
374
|
+
const missingFiles = input.validatedSuggestedFiles
|
|
375
|
+
.filter((file) => file.status === "missing")
|
|
376
|
+
.map((file) => file.originalPath);
|
|
377
|
+
const notes = uniqueStrings([
|
|
378
|
+
...input.patchRiskWarnings,
|
|
379
|
+
...input.architectureWarnings,
|
|
380
|
+
...missingFiles.map((filePath) => `Suggested file could not be validated: ${filePath}`)
|
|
381
|
+
]);
|
|
382
|
+
const assumptions = [];
|
|
383
|
+
const followUps = [];
|
|
384
|
+
if (input.schemaConfidence === "low") {
|
|
385
|
+
assumptions.push("Schema-aware reasoning was based on limited schema evidence.");
|
|
386
|
+
}
|
|
387
|
+
if (input.storageConfidence === "low") {
|
|
388
|
+
assumptions.push("Storage detection was inferred with limited confidence.");
|
|
389
|
+
}
|
|
390
|
+
if (input.decision.mode === "preview_only") {
|
|
391
|
+
followUps.push("Review the patch preview before applying changes.");
|
|
392
|
+
followUps.push("Do not auto-apply until warnings and uncertainties are resolved.");
|
|
393
|
+
}
|
|
394
|
+
if (input.decision.mode === "blocked") {
|
|
395
|
+
followUps.push("Resolve validation errors and rerun the agent.");
|
|
396
|
+
}
|
|
397
|
+
if (input.patchRiskWarnings.length > 0) {
|
|
398
|
+
followUps.push("Verify multi-tenant safety and resource scoping manually.");
|
|
399
|
+
}
|
|
400
|
+
if (missingFiles.length > 0) {
|
|
401
|
+
followUps.push("Review unresolved or missing suggested files manually.");
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
notes,
|
|
405
|
+
assumptions: uniqueStrings(assumptions),
|
|
406
|
+
followUps: uniqueStrings(followUps)
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function logIssueSummary(label, issues) {
|
|
410
|
+
if (issues.length === 0)
|
|
411
|
+
return;
|
|
412
|
+
const errorCount = issues.filter((issue) => issue.severity === "error").length;
|
|
413
|
+
const warningCount = issues.filter((issue) => issue.severity === "warning").length;
|
|
414
|
+
(0, logger_js_1.logWarn)(`${label}: ${errorCount} error(s), ${warningCount} warning(s)`);
|
|
415
|
+
const preview = issues.slice(0, 3);
|
|
416
|
+
for (const issue of preview) {
|
|
417
|
+
(0, logger_js_1.logWarn)(`- ${issue.message}${issue.file ? ` [${issue.file}]` : ""}`);
|
|
418
|
+
}
|
|
419
|
+
if (issues.length > preview.length) {
|
|
420
|
+
(0, logger_js_1.logWarn)(`- ...and ${issues.length - preview.length} more`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function buildStorageInsight(input) {
|
|
424
|
+
if (!input.resourceStorageInsight) {
|
|
425
|
+
return {
|
|
426
|
+
primaryStorage: "unknown",
|
|
427
|
+
detectedClients: [],
|
|
428
|
+
reasoning: ["No storage insight could be inferred from the current context."],
|
|
429
|
+
confidence: "low"
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const { storageKind, evidence } = input.resourceStorageInsight;
|
|
433
|
+
return {
|
|
434
|
+
primaryStorage: input.schemaSnapshot ? "postgres" : "unknown",
|
|
435
|
+
resourceStorageKind: storageKind,
|
|
436
|
+
detectedClients: [],
|
|
437
|
+
reasoning: [...evidence, `Detected resource storage kind: ${storageKind}`],
|
|
438
|
+
confidence: storageKind === "unknown"
|
|
439
|
+
? "low"
|
|
440
|
+
: evidence.length >= 2
|
|
441
|
+
? "high"
|
|
442
|
+
: "medium"
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
async function runFeatureAgent(input) {
|
|
446
|
+
const mode = input.mode ?? "preview";
|
|
447
|
+
(0, logger_js_1.logInfo)(`Scanning target project: ${input.targetPath}`);
|
|
448
|
+
const allFiles = await (0, scanRepo_js_1.scanRepo)(input.targetPath);
|
|
449
|
+
const structure = (0, detectProjectStructure_js_1.detectProjectStructure)(allFiles);
|
|
450
|
+
const intent = (0, taskIntentParser_js_1.parseTaskIntent)(input.task);
|
|
451
|
+
const rankedFiles = (0, rankRelevantFiles_js_1.rankRelevantFiles)({
|
|
452
|
+
task: input.task,
|
|
453
|
+
files: allFiles,
|
|
454
|
+
projectStructure: structure,
|
|
455
|
+
intent
|
|
456
|
+
});
|
|
457
|
+
const relevantFiles = boostRelevantFilesWithChangedFiles(rankedFiles, input.changedFiles ?? []);
|
|
458
|
+
if ((input.changedFiles ?? []).length > 0) {
|
|
459
|
+
(0, logger_js_1.logInfo)(`Diff-aware mode enabled: ${input.changedFiles?.length ?? 0} changed file(s) boosted.`);
|
|
460
|
+
}
|
|
461
|
+
const summary = [
|
|
462
|
+
`Task: ${input.task}`,
|
|
463
|
+
`Mode: ${mode}`,
|
|
464
|
+
`Intent action: ${intent.action}`,
|
|
465
|
+
`Intent resource kind: ${intent.resourceKind}`,
|
|
466
|
+
`Intent scope: ${intent.scope}`,
|
|
467
|
+
`Parent resource: ${intent.parentResource ?? "unknown"}`,
|
|
468
|
+
`Nested resource: ${intent.nestedResource ?? "unknown"}`,
|
|
469
|
+
...intent.warnings.map((warning) => `Intent warning: ${warning}`),
|
|
470
|
+
`Total scanned files: ${allFiles.length}`,
|
|
471
|
+
`Relevant files found: ${relevantFiles.length}`,
|
|
472
|
+
`React app detected: ${structure.isReactApp ? "yes" : "no"}`,
|
|
473
|
+
`Express app detected: ${structure.isExpressApp ? "yes" : "no"}`
|
|
474
|
+
].join("\n");
|
|
475
|
+
const schemaSnapshot = await (0, loadSchemaSnapshot_js_1.loadSchemaSnapshot)(input.targetPath);
|
|
476
|
+
const analysisFilePaths = relevantFiles.slice(0, 12).map((file) => file.absolutePath);
|
|
477
|
+
const analysisFileContentsMap = await (0, readProjectFiles_js_1.readProjectFiles)(analysisFilePaths);
|
|
478
|
+
const analysisFiles = Object.entries(analysisFileContentsMap).map(([absolutePath, content]) => {
|
|
479
|
+
const repoFile = allFiles.find((file) => file.absolutePath === absolutePath);
|
|
480
|
+
return {
|
|
481
|
+
path: repoFile?.path ?? absolutePath,
|
|
482
|
+
content
|
|
483
|
+
};
|
|
484
|
+
});
|
|
485
|
+
const projectPatternAnalysis = (0, analyzeProjectPatterns_js_1.analyzeProjectPatterns)(analysisFiles);
|
|
486
|
+
const resourceStorageInsight = intent.parentResource
|
|
487
|
+
? (0, detectResourceStorage_js_1.detectResourceStorage)({
|
|
488
|
+
parentResource: intent.parentResource,
|
|
489
|
+
nestedResource: intent.nestedResource,
|
|
490
|
+
files: analysisFiles,
|
|
491
|
+
schema: schemaSnapshot
|
|
492
|
+
})
|
|
493
|
+
: null;
|
|
494
|
+
const schemaAwareContext = (0, buildSchemaAwareContext_js_1.buildSchemaAwareContext)({
|
|
495
|
+
intent,
|
|
496
|
+
schema: schemaSnapshot,
|
|
497
|
+
projectPatterns: projectPatternAnalysis,
|
|
498
|
+
storageInsight: resourceStorageInsight
|
|
499
|
+
});
|
|
500
|
+
let llmPlan;
|
|
501
|
+
try {
|
|
502
|
+
(0, logger_js_1.logInfo)("Generating feature plan...");
|
|
503
|
+
llmPlan = await (0, planFeature_js_1.planFeatureWithLlm)({
|
|
504
|
+
task: input.task,
|
|
505
|
+
intent,
|
|
506
|
+
projectSummary: summary,
|
|
507
|
+
projectNotes: [...structure.notes, ...schemaAwareContext.summaryLines],
|
|
508
|
+
relevantFiles: relevantFiles.map((file) => ({
|
|
509
|
+
path: file.path,
|
|
510
|
+
category: file.category
|
|
511
|
+
})),
|
|
512
|
+
existingFilesSummary: [
|
|
513
|
+
"EXISTING FILES IN REPO (use ONLY these paths, do not invent new ones):",
|
|
514
|
+
...relevantFiles.slice(0, 12).map((file) => `- ${file.path}`)
|
|
515
|
+
].join("\n"),
|
|
516
|
+
schemaAwareSummary: schemaAwareContext.summaryLines
|
|
517
|
+
});
|
|
518
|
+
(0, logger_js_1.logSuccess)("Feature plan created");
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
const message = error instanceof Error ? error.message : "Unknown planning error";
|
|
522
|
+
(0, logger_js_1.logWarn)(`Feature planning failed, using fallback. Reason: ${message}`);
|
|
523
|
+
llmPlan = (0, buildFallbackPlan_js_1.buildFallbackPlan)(input.task, relevantFiles);
|
|
524
|
+
}
|
|
525
|
+
const validatedSuggestedFiles = (0, validateSuggestedFiles_js_1.validateSuggestedFiles)(llmPlan.suggestedFiles, allFiles);
|
|
526
|
+
const architectureValidation = (0, validateSuggestedArchitecture_js_1.validateSuggestedArchitecture)(intent, validatedSuggestedFiles.map((file) => file.resolvedPath || file.originalPath));
|
|
527
|
+
if (architectureValidation.warnings.length > 0) {
|
|
528
|
+
(0, logger_js_1.logWarn)(`Architecture warnings detected: ${architectureValidation.warnings.length}`);
|
|
529
|
+
}
|
|
530
|
+
let patchPlan;
|
|
531
|
+
try {
|
|
532
|
+
const filesToRead = validatedSuggestedFiles
|
|
533
|
+
.filter(hasResolvedPath)
|
|
534
|
+
.filter((file) => file.status !== "missing")
|
|
535
|
+
.map((file) => {
|
|
536
|
+
const match = allFiles.find((repoFile) => repoFile.path === file.resolvedPath);
|
|
537
|
+
return match?.absolutePath;
|
|
538
|
+
})
|
|
539
|
+
.filter((value) => typeof value === "string")
|
|
540
|
+
.slice(0, 6);
|
|
541
|
+
const fileContentsMap = await (0, readProjectFiles_js_1.readProjectFiles)(filesToRead);
|
|
542
|
+
const fileContexts = Object.entries(fileContentsMap).map(([absolutePath, content]) => {
|
|
543
|
+
const repoFile = allFiles.find((file) => file.absolutePath === absolutePath);
|
|
544
|
+
return {
|
|
545
|
+
path: repoFile?.path ?? absolutePath,
|
|
546
|
+
content
|
|
547
|
+
};
|
|
548
|
+
});
|
|
549
|
+
(0, logger_js_1.logInfo)("Generating patch preview...");
|
|
550
|
+
patchPlan = await (0, planPatchPreview_js_1.planPatchPreviewWithLlm)({
|
|
551
|
+
task: input.task,
|
|
552
|
+
intent,
|
|
553
|
+
projectSummary: summary,
|
|
554
|
+
projectNotes: [...structure.notes, ...schemaAwareContext.summaryLines],
|
|
555
|
+
suggestedFiles: validatedSuggestedFiles
|
|
556
|
+
.filter(hasResolvedPath)
|
|
557
|
+
.map((file) => ({
|
|
558
|
+
path: file.resolvedPath,
|
|
559
|
+
action: file.action,
|
|
560
|
+
reason: file.reason
|
|
561
|
+
})),
|
|
562
|
+
fileContexts,
|
|
563
|
+
schemaAwareSummary: schemaAwareContext.summaryLines
|
|
564
|
+
});
|
|
565
|
+
(0, logger_js_1.logSuccess)("Patch preview created");
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
const message = error instanceof Error ? error.message : "Unknown patch planning error";
|
|
569
|
+
(0, logger_js_1.logWarn)(`Patch preview generation failed, using fallback. Reason: ${message}`);
|
|
570
|
+
patchPlan = (0, buildFallbackPatchPlan_js_1.buildFallbackPatchPlan)(input.task, validatedSuggestedFiles);
|
|
571
|
+
}
|
|
572
|
+
const patchTargetValidation = await (0, validatePatchPlan_js_1.validatePatchPlan)({
|
|
573
|
+
targetPath: input.targetPath,
|
|
574
|
+
patchPlan
|
|
575
|
+
});
|
|
576
|
+
const patchValidationIssues = (0, normalizeIssues_js_1.normalizePatchValidationIssues)(patchTargetValidation.issues);
|
|
577
|
+
const patchRiskWarnings = uniqueStrings(patchPlan.patches.flatMap((patch) => (0, patchRiskAnalyzer_js_1.analyzePatchRisk)(intent, patch.contentPreview).warnings));
|
|
578
|
+
const schemaPatchIssues = (0, validatePatchAgainstSchema_js_1.validatePatchAgainstSchema)(patchPlan.patches.map((patch) => ({
|
|
579
|
+
path: patch.path,
|
|
580
|
+
contentPreview: patch.contentPreview
|
|
581
|
+
})), schemaSnapshot);
|
|
582
|
+
const schemaPatchWarnings = (0, normalizeIssues_js_1.normalizeSchemaValidationIssues)(schemaPatchIssues);
|
|
583
|
+
logIssueSummary("Patch validation", patchValidationIssues);
|
|
584
|
+
logIssueSummary("Schema validation", schemaPatchWarnings);
|
|
585
|
+
if (patchRiskWarnings.length > 0) {
|
|
586
|
+
(0, logger_js_1.logWarn)(`Patch risk warnings detected: ${patchRiskWarnings.length}`);
|
|
587
|
+
for (const warning of patchRiskWarnings.slice(0, 3)) {
|
|
588
|
+
(0, logger_js_1.logWarn)(`- ${warning}`);
|
|
589
|
+
}
|
|
590
|
+
if (patchRiskWarnings.length > 3) {
|
|
591
|
+
(0, logger_js_1.logWarn)(`- ...and ${patchRiskWarnings.length - 3} more`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const schemaAwareSummary = buildSchemaAwareSummaryFromContext({
|
|
595
|
+
schemaAwareContext,
|
|
596
|
+
schemaSnapshot,
|
|
597
|
+
intent
|
|
598
|
+
});
|
|
599
|
+
const storageInsight = buildStorageInsight({
|
|
600
|
+
schemaSnapshot,
|
|
601
|
+
resourceStorageInsight
|
|
602
|
+
});
|
|
603
|
+
const { confidence, confidenceDetails } = computeConfidenceBreakdown({
|
|
604
|
+
intent,
|
|
605
|
+
schemaConfidence: schemaAwareSummary.confidence,
|
|
606
|
+
storageConfidence: storageInsight.confidence,
|
|
607
|
+
patchValidationIssues,
|
|
608
|
+
schemaPatchWarnings,
|
|
609
|
+
patchRiskWarnings,
|
|
610
|
+
architectureWarnings: architectureValidation.warnings,
|
|
611
|
+
validatedSuggestedFiles
|
|
612
|
+
});
|
|
613
|
+
const decision = decideExecutionMode({
|
|
614
|
+
confidence,
|
|
615
|
+
patchValidationIssues,
|
|
616
|
+
schemaPatchWarnings,
|
|
617
|
+
patchRiskWarnings,
|
|
618
|
+
architectureWarnings: architectureValidation.warnings,
|
|
619
|
+
validatedSuggestedFiles,
|
|
620
|
+
schemaConfidence: schemaAwareSummary.confidence,
|
|
621
|
+
storageConfidence: storageInsight.confidence
|
|
622
|
+
});
|
|
623
|
+
const executionNotes = buildExecutionNotes({
|
|
624
|
+
schemaConfidence: schemaAwareSummary.confidence,
|
|
625
|
+
storageConfidence: storageInsight.confidence,
|
|
626
|
+
patchRiskWarnings,
|
|
627
|
+
architectureWarnings: architectureValidation.warnings,
|
|
628
|
+
validatedSuggestedFiles,
|
|
629
|
+
decision
|
|
630
|
+
});
|
|
631
|
+
const finalSummary = [
|
|
632
|
+
`Task: ${input.task}`,
|
|
633
|
+
`Mode: ${mode}`,
|
|
634
|
+
`Intent action: ${intent.action}`,
|
|
635
|
+
`Intent resource kind: ${intent.resourceKind}`,
|
|
636
|
+
`Intent scope: ${intent.scope}`,
|
|
637
|
+
`Parent resource: ${intent.parentResource ?? "unknown"}`,
|
|
638
|
+
`Nested resource: ${intent.nestedResource ?? "unknown"}`,
|
|
639
|
+
`Relevant files found: ${relevantFiles.length}`,
|
|
640
|
+
`Confidence score: ${confidence.finalScore}/100 (${mapConfidenceLevel(confidence.finalScore)})`,
|
|
641
|
+
`Decision: ${decision.mode}`
|
|
642
|
+
].join("\n");
|
|
643
|
+
const result = {
|
|
644
|
+
task: input.task,
|
|
645
|
+
targetPath: input.targetPath,
|
|
646
|
+
structure,
|
|
647
|
+
allFiles,
|
|
648
|
+
relevantFiles,
|
|
649
|
+
summary: finalSummary,
|
|
650
|
+
llmPlan,
|
|
651
|
+
validatedSuggestedFiles,
|
|
652
|
+
patchPlan,
|
|
653
|
+
intent,
|
|
654
|
+
architectureWarnings: architectureValidation.warnings,
|
|
655
|
+
patchRiskWarnings,
|
|
656
|
+
schemaAwareSummary,
|
|
657
|
+
storageInsight,
|
|
658
|
+
patchValidationIssues,
|
|
659
|
+
schemaPatchWarnings,
|
|
660
|
+
executionNotes,
|
|
661
|
+
confidence,
|
|
662
|
+
confidenceDetails,
|
|
663
|
+
decision
|
|
664
|
+
};
|
|
665
|
+
if (mode === "dry-run" || mode === "apply") {
|
|
666
|
+
if (decision.mode !== "safe_to_apply") {
|
|
667
|
+
(0, logger_js_1.logWarn)(`Patch execution skipped because decision mode is ${decision.mode}. Only safe_to_apply may execute patches.`);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
(0, logger_js_1.logInfo)(`Executing patch plan in ${mode} mode...`);
|
|
671
|
+
result.applyResults = await (0, applyPatchPlan_js_1.applyPatchPlan)({
|
|
672
|
+
targetPath: input.targetPath,
|
|
673
|
+
patchPlan,
|
|
674
|
+
mode
|
|
675
|
+
});
|
|
676
|
+
(0, logger_js_1.logSuccess)(`Patch execution finished in ${mode} mode`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const cachePath = await (0, saveAgentResult_js_1.saveAgentResult)(result);
|
|
680
|
+
(0, logger_js_1.logInfo)(`Saved agent result: ${cachePath}`);
|
|
681
|
+
(0, logger_js_1.logInfo)(`Run completed with decision=${decision.mode}, confidence=${confidence.finalScore}/100`);
|
|
682
|
+
return result;
|
|
683
|
+
}
|
|
684
|
+
//# sourceMappingURL=runFeatureAgent.js.map
|