@codeyam/codeyam-cli 0.1.0-staging.1669d45 → 0.1.0-staging.1a2737b
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/analyzer-template/.build-info.json +8 -8
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +19 -19
- package/analyzer-template/packages/ai/index.ts +16 -2
- package/analyzer-template/packages/ai/package.json +2 -2
- package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +110 -52
- package/analyzer-template/packages/ai/src/lib/astScopes/arrayDerivationDetector.ts +199 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +98 -9
- package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +139 -23
- package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
- package/analyzer-template/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.ts +6 -126
- package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +656 -28
- package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +94 -7
- package/analyzer-template/packages/ai/src/lib/completionCall.ts +198 -34
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1331 -254
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.ts +205 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.ts +10 -2
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +54 -3
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +124 -17
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +393 -97
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.ts +129 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.ts +35 -0
- package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +183 -0
- package/analyzer-template/packages/ai/src/lib/e2eDataTracking.ts +334 -0
- package/analyzer-template/packages/ai/src/lib/extractCriticalDataKeys.ts +120 -0
- package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +936 -7
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +35 -6
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +515 -6
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +1540 -75
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +239 -0
- package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
- package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
- package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
- package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
- package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChunkPrompt.ts +82 -0
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateCriticalKeysPrompt.ts +103 -0
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +44 -7
- package/analyzer-template/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.ts +391 -0
- package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +179 -45
- package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +26 -4
- package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
- package/analyzer-template/packages/analyze/index.ts +2 -0
- package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
- package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
- package/analyzer-template/packages/analyze/src/lib/analysisContext.ts +44 -4
- package/analyzer-template/packages/analyze/src/lib/asts/nodes/getNodeType.ts +1 -0
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +99 -22
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
- package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
- package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
- package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +33 -10
- package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
- package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +193 -76
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +87 -25
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +269 -22
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +118 -10
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +647 -73
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.ts +56 -11
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
- package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
- package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
- package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
- package/analyzer-template/packages/aws/package.json +10 -10
- package/analyzer-template/packages/database/package.json +1 -1
- package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/kysely/db.ts +14 -1
- package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
- package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
- package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
- package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
- package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
- package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
- package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
- package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
- package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
- package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
- package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
- package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
- package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
- package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +11 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/analysesTable.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
- package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/analyzer-template/packages/github/dist/types/index.d.ts +1 -1
- package/analyzer-template/packages/github/dist/types/index.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/index.js.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts +25 -1
- package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
- package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
- package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +56 -6
- package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
- package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts +9 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js +29 -3
- package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js.map +1 -1
- package/analyzer-template/packages/github/package.json +1 -1
- package/analyzer-template/packages/types/index.ts +1 -0
- package/analyzer-template/packages/types/src/types/Analysis.ts +25 -0
- package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
- package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
- package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +70 -6
- package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
- package/analyzer-template/packages/utils/dist/types/index.d.ts +1 -1
- package/analyzer-template/packages/utils/dist/types/index.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/index.js.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts +25 -1
- package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
- package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
- package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +56 -6
- package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
- package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +93 -2
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts +9 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js +29 -3
- package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js.map +1 -1
- package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +108 -2
- package/analyzer-template/packages/utils/src/lib/safeFileName.ts +48 -3
- package/analyzer-template/playwright/capture.ts +20 -8
- package/analyzer-template/playwright/captureStatic.ts +1 -1
- package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
- package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
- package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
- package/analyzer-template/project/constructMockCode.ts +436 -44
- package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
- package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
- package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
- package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +18 -7
- package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
- package/analyzer-template/project/orchestrateCapture.ts +75 -7
- package/analyzer-template/project/reconcileMockDataKeys.ts +152 -9
- package/analyzer-template/project/runAnalysis.ts +4 -0
- package/analyzer-template/project/start.ts +35 -11
- package/analyzer-template/project/writeMockDataTsx.ts +295 -10
- package/analyzer-template/project/writeScenarioComponents.ts +237 -32
- package/analyzer-template/project/writeSimpleRoot.ts +21 -11
- package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
- package/background/src/lib/local/createLocalAnalyzer.js +1 -1
- package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
- package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
- package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
- package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
- package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
- package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
- package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
- package/background/src/lib/virtualized/project/constructMockCode.js +359 -14
- package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
- package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
- package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
- package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
- package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
- package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
- package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
- package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +7 -5
- package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
- package/background/src/lib/virtualized/project/orchestrateCapture.js +62 -7
- package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +126 -9
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
- package/background/src/lib/virtualized/project/runAnalysis.js +3 -0
- package/background/src/lib/virtualized/project/runAnalysis.js.map +1 -1
- package/background/src/lib/virtualized/project/start.js +32 -11
- package/background/src/lib/virtualized/project/start.js.map +1 -1
- package/background/src/lib/virtualized/project/writeMockDataTsx.js +251 -6
- package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
- package/background/src/lib/virtualized/project/writeScenarioComponents.js +173 -30
- package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
- package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
- package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
- package/codeyam-cli/scripts/apply-setup.js +180 -0
- package/codeyam-cli/scripts/apply-setup.js.map +1 -1
- package/codeyam-cli/src/cli.js +32 -18
- package/codeyam-cli/src/cli.js.map +1 -1
- package/codeyam-cli/src/codeyam-cli.js +18 -2
- package/codeyam-cli/src/codeyam-cli.js.map +1 -1
- package/codeyam-cli/src/commands/analyze.js +4 -2
- package/codeyam-cli/src/commands/analyze.js.map +1 -1
- package/codeyam-cli/src/commands/baseline.js +2 -0
- package/codeyam-cli/src/commands/baseline.js.map +1 -1
- package/codeyam-cli/src/commands/debug.js +9 -5
- package/codeyam-cli/src/commands/debug.js.map +1 -1
- package/codeyam-cli/src/commands/default.js +31 -20
- package/codeyam-cli/src/commands/default.js.map +1 -1
- package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
- package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
- package/codeyam-cli/src/commands/init.js +49 -257
- package/codeyam-cli/src/commands/init.js.map +1 -1
- package/codeyam-cli/src/commands/memory.js +307 -0
- package/codeyam-cli/src/commands/memory.js.map +1 -0
- package/codeyam-cli/src/commands/recapture.js +2 -0
- package/codeyam-cli/src/commands/recapture.js.map +1 -1
- package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
- package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
- package/codeyam-cli/src/commands/setup-simulations.js +284 -0
- package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
- package/codeyam-cli/src/commands/test-startup.js +2 -0
- package/codeyam-cli/src/commands/test-startup.js.map +1 -1
- package/codeyam-cli/src/commands/verify.js +14 -2
- package/codeyam-cli/src/commands/verify.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js +179 -0
- package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -82
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
- package/codeyam-cli/src/utils/analysisRunner.js +21 -2
- package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
- package/codeyam-cli/src/utils/analyzer.js +7 -0
- package/codeyam-cli/src/utils/analyzer.js.map +1 -1
- package/codeyam-cli/src/utils/backgroundServer.js +90 -19
- package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/utils/generateReport.js +2 -2
- package/codeyam-cli/src/utils/install-skills.js +77 -38
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
- package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
- package/codeyam-cli/src/utils/npmVersionCheck.js +76 -0
- package/codeyam-cli/src/utils/npmVersionCheck.js.map +1 -0
- package/codeyam-cli/src/utils/progress.js +7 -0
- package/codeyam-cli/src/utils/progress.js.map +1 -1
- package/codeyam-cli/src/utils/queue/job.js +5 -0
- package/codeyam-cli/src/utils/queue/job.js.map +1 -1
- package/codeyam-cli/src/utils/queue/manager.js +6 -0
- package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
- package/codeyam-cli/src/utils/requireSimulations.js +10 -0
- package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +74 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +376 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +116 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
- package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
- package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
- package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
- package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
- package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
- package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
- package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
- package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
- package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
- package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
- package/codeyam-cli/src/utils/rules/index.js +6 -0
- package/codeyam-cli/src/utils/rules/index.js.map +1 -0
- package/codeyam-cli/src/utils/rules/parser.js +83 -0
- package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
- package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
- package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
- package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
- package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
- package/codeyam-cli/src/utils/rules/staleness.js +137 -0
- package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
- package/codeyam-cli/src/utils/serverState.js +37 -10
- package/codeyam-cli/src/utils/serverState.js.map +1 -1
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -42
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
- package/codeyam-cli/src/utils/simulationGateMiddleware.js +138 -0
- package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -0
- package/codeyam-cli/src/utils/syncMocksMiddleware.js +5 -24
- package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
- package/codeyam-cli/src/utils/versionInfo.js +25 -0
- package/codeyam-cli/src/utils/versionInfo.js.map +1 -1
- package/codeyam-cli/src/webserver/__tests__/dependency-smoke.test.js +66 -0
- package/codeyam-cli/src/webserver/__tests__/dependency-smoke.test.js.map +1 -0
- package/codeyam-cli/src/webserver/app/lib/database.js +22 -6
- package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
- package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
- package/codeyam-cli/src/webserver/backgroundServer.js +50 -0
- package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/webserver/bootstrap.js +51 -0
- package/codeyam-cli/src/webserver/bootstrap.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-jNYXRRNI.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/EntityItem-bwuHPyTa.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-COi5OvsN.js → EntityTypeBadge-CvzqMxcu.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-BwdQv49w.js → EntityTypeIcon-BH0XDim7.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-CEleMv_j.js → InlineSpinner-EhOseatT.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-D68KarMg.js → InteractivePreview-yjIHlOGa.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-L75Wvqgw.js → LibraryFunctionPreview-Cq5o8jL4.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-C53WM8qn.js → LoadingDots-BvMu2i-g.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-CrNkmy4i.js → LogViewer-kgBTLoJD.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-BzPgx-xO.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-CQifa1n-.js → SafeScreenshot-CwZrv-Ok.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-CyaBFX7l.js → ScenarioViewer-BX2Ny2Qj.js} +3 -13
- package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-D36O1rzU.js → TruncatedFilePath-CDpEprKa.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/_index-BRx8ZGZo.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-4S4yPfFw.js +27 -0
- package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DHKuQSmR.js +17 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.health-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.restart-server-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/book-open-D4IPYH_y.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-DgTPh8H-.js → chevron-down-CG65viiV.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-DdQKK6on.js → chunk-JZWAC4HX-DB3aFuEO.js} +12 -12
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-Dmr2bb1R.js → circle-check-igfMr5DY.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/copy-Coc4o_8c.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-Do4ZLUYa.js → createLucideIcon-D1zB-pYc.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-JTAjQ54M.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-CbdFyxZh.js → entity._sha._-B0h9AqE6.js} +12 -12
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-B4iCfs5M.js → entity._sha.scenarios._scenarioId.fullscreen-DjLxr2JB.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-wDWZZO1W.js → entity._sha_.create-scenario-CtYowLOt.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-BMbl7MeQ.js → entity._sha_.edit._scenarioId-PePWg17F.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entry.client-5wRKRIH9.js → entry.client-I-Wo99C_.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DD3SDH7t.js → fileTableUtils-9sMMAiWJ.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/files-Co65J0s3.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{git-zXjT7J0G.js → git-BdHOxVfg.js} +8 -8
- package/codeyam-cli/src/webserver/build/client/assets/globals-BSZfYCkU.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{index-DLbXwndH.js → index-CUM5iXwc.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-gPZ-lad1.js → index-_417gcQW.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/labs-BK0C1H1T.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BsPXJ81F.js → loader-circle-TzRHMVog.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-040dab1c.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/memory-UIDVz141.js +92 -0
- package/codeyam-cli/src/webserver/build/client/assets/pause-hjzB7t2z.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/root-D1WadSdf.js +62 -0
- package/codeyam-cli/src/webserver/build/client/assets/{search-P2FKIUql.js → search-DcAwD_Ln.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-CclxrcPK.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{simulations-L18M6-kN.js → simulations-DVNJVQgD.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/terminal-DbEAHMbA.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-BDz7kbVA.js → triangle-alert-CAD5b1o_.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-29dDmbH8.js → useCustomSizes-BqgrAzs3.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-BUm0UVJm.js → useLastLogLine-DAFqfEDH.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-CkIOKTrZ.js → useReportContext-DZlYx2c4.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useToast-KKw5kTn-.js → useToast-ihdMtlf6.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/index-B3dE0r28.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-DYbfdxa3.js +273 -0
- package/codeyam-cli/src/webserver/build/server/index.js +1 -1
- package/codeyam-cli/src/webserver/build-info.json +5 -5
- package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +48 -4
- package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
- package/codeyam-cli/templates/codeyam-memory-hook.sh +199 -0
- package/codeyam-cli/templates/codeyam-memory.md +396 -0
- package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
- package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
- package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
- package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
- package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
- package/codeyam-cli/templates/rule-notification-hook.py +56 -0
- package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
- package/codeyam-cli/templates/rules-instructions.md +132 -0
- package/package.json +18 -15
- package/packages/ai/index.js +7 -3
- package/packages/ai/index.js.map +1 -1
- package/packages/ai/src/lib/analyzeScope.js +91 -30
- package/packages/ai/src/lib/analyzeScope.js.map +1 -1
- package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js +150 -0
- package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js.map +1 -0
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +78 -8
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
- package/packages/ai/src/lib/astScopes/methodSemantics.js +109 -23
- package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
- package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
- package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
- package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js +1 -102
- package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js.map +1 -1
- package/packages/ai/src/lib/astScopes/processExpression.js +518 -28
- package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
- package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
- package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
- package/packages/ai/src/lib/completionCall.js +161 -30
- package/packages/ai/src/lib/completionCall.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +1061 -174
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js +179 -0
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js +7 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
- package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
- package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +52 -3
- package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +106 -13
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
- package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
- package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
- package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
- package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +333 -86
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js +107 -0
- package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js.map +1 -0
- package/packages/ai/src/lib/dataStructureChunking.js +130 -0
- package/packages/ai/src/lib/dataStructureChunking.js.map +1 -0
- package/packages/ai/src/lib/e2eDataTracking.js +241 -0
- package/packages/ai/src/lib/e2eDataTracking.js.map +1 -0
- package/packages/ai/src/lib/extractCriticalDataKeys.js +96 -0
- package/packages/ai/src/lib/extractCriticalDataKeys.js.map +1 -0
- package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
- package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarioData.js +734 -8
- package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarios.js +26 -2
- package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlows.js +376 -4
- package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +1124 -59
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js +194 -0
- package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js.map +1 -0
- package/packages/ai/src/lib/isolateScopes.js +39 -3
- package/packages/ai/src/lib/isolateScopes.js.map +1 -1
- package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
- package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
- package/packages/ai/src/lib/mergeStatements.js +70 -51
- package/packages/ai/src/lib/mergeStatements.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
- package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
- package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
- package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js +54 -0
- package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js.map +1 -0
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +30 -7
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js +335 -0
- package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js.map +1 -0
- package/packages/ai/src/lib/resolvePathToControllable.js +155 -41
- package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
- package/packages/ai/src/lib/worker/SerializableDataStructure.js +7 -0
- package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
- package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
- package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
- package/packages/analyze/index.js +1 -0
- package/packages/analyze/index.js.map +1 -1
- package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
- package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
- package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
- package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
- package/packages/analyze/src/lib/analysisContext.js +30 -5
- package/packages/analyze/src/lib/analysisContext.js.map +1 -1
- package/packages/analyze/src/lib/asts/nodes/getNodeType.js +1 -0
- package/packages/analyze/src/lib/asts/nodes/getNodeType.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
- package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
- package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
- package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +72 -10
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
- package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
- package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +31 -10
- package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
- package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
- package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
- package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
- package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
- package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +164 -68
- package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +75 -21
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +185 -20
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +57 -9
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +542 -53
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js +46 -9
- package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js.map +1 -1
- package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
- package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
- package/packages/analyze/src/lib/index.js +1 -0
- package/packages/analyze/src/lib/index.js.map +1 -1
- package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
- package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
- package/packages/database/src/lib/analysisBranchToDb.js +1 -1
- package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
- package/packages/database/src/lib/analysisToDb.js +1 -1
- package/packages/database/src/lib/analysisToDb.js.map +1 -1
- package/packages/database/src/lib/branchToDb.js +1 -1
- package/packages/database/src/lib/branchToDb.js.map +1 -1
- package/packages/database/src/lib/commitBranchToDb.js +1 -1
- package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
- package/packages/database/src/lib/commitToDb.js +1 -1
- package/packages/database/src/lib/commitToDb.js.map +1 -1
- package/packages/database/src/lib/fileToDb.js +1 -1
- package/packages/database/src/lib/fileToDb.js.map +1 -1
- package/packages/database/src/lib/kysely/db.js +11 -1
- package/packages/database/src/lib/kysely/db.js.map +1 -1
- package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
- package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
- package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
- package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
- package/packages/database/src/lib/loadAnalyses.js +45 -2
- package/packages/database/src/lib/loadAnalyses.js.map +1 -1
- package/packages/database/src/lib/loadAnalysis.js +8 -0
- package/packages/database/src/lib/loadAnalysis.js.map +1 -1
- package/packages/database/src/lib/loadBranch.js +11 -1
- package/packages/database/src/lib/loadBranch.js.map +1 -1
- package/packages/database/src/lib/loadCommit.js +7 -0
- package/packages/database/src/lib/loadCommit.js.map +1 -1
- package/packages/database/src/lib/loadCommits.js +22 -1
- package/packages/database/src/lib/loadCommits.js.map +1 -1
- package/packages/database/src/lib/loadEntities.js +23 -4
- package/packages/database/src/lib/loadEntities.js.map +1 -1
- package/packages/database/src/lib/loadEntityBranches.js +9 -0
- package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
- package/packages/database/src/lib/projectToDb.js +1 -1
- package/packages/database/src/lib/projectToDb.js.map +1 -1
- package/packages/database/src/lib/saveFiles.js +1 -1
- package/packages/database/src/lib/saveFiles.js.map +1 -1
- package/packages/database/src/lib/scenarioToDb.js +1 -1
- package/packages/database/src/lib/scenarioToDb.js.map +1 -1
- package/packages/database/src/lib/updateCommitMetadata.js +5 -4
- package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/packages/types/index.js.map +1 -1
- package/packages/utils/src/lib/fs/rsyncCopy.js +93 -2
- package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
- package/packages/utils/src/lib/safeFileName.js +29 -3
- package/packages/utils/src/lib/safeFileName.js.map +1 -1
- package/scripts/finalize-analyzer.cjs +8 -76
- package/codeyam-cli/src/webserver/build/client/assets/EntityItem-vauWK972.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-DzJRkCkr.js +0 -11
- package/codeyam-cli/src/webserver/build/client/assets/_index-Be83mo_j.js +0 -11
- package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-BN6wu6Y-.js +0 -37
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-Bn6aCAy_.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/files-DKyMFI90.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/globals-DTTQ3gY7.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-22590fcf.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/root-BsAarjAM.js +0 -57
- package/codeyam-cli/src/webserver/build/client/assets/settings-B2eDuBj8.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/index-BND5I5fv.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-CFXnd7MG.js +0 -228
- package/codeyam-cli/templates/codeyam:diagnose.md +0 -625
|
@@ -79,6 +79,8 @@
|
|
|
79
79
|
* - `helpers/README.md` - Overview of the helper module architecture
|
|
80
80
|
*/
|
|
81
81
|
import fillInSchemaGapsAndUnknowns from "./helpers/fillInSchemaGapsAndUnknowns.js";
|
|
82
|
+
import { clearCleanKnownObjectFunctionsCache } from "./helpers/cleanKnownObjectFunctions.js";
|
|
83
|
+
import { clearCleanNonObjectFunctionsCache } from "./helpers/cleanNonObjectFunctions.js";
|
|
82
84
|
/**
|
|
83
85
|
* Patterns that indicate recursive type structures in schema paths.
|
|
84
86
|
* Used by hasExcessivePatternRepetition() to detect exponential path blowup.
|
|
@@ -120,6 +122,17 @@ export function resetScopeDataStructureMetrics() {
|
|
|
120
122
|
followEquivalenciesEarlyExitPhase1Count = 0;
|
|
121
123
|
followEquivalenciesWithWorkCount = 0;
|
|
122
124
|
addEquivalencyCallCount = 0;
|
|
125
|
+
// Clear module-level caches to prevent unbounded memory growth across entities
|
|
126
|
+
const knownObjectCache = clearCleanKnownObjectFunctionsCache();
|
|
127
|
+
const nonObjectCache = clearCleanNonObjectFunctionsCache();
|
|
128
|
+
if (knownObjectCache.count > 0 || nonObjectCache.count > 0) {
|
|
129
|
+
const totalBytes = knownObjectCache.estimatedBytes + nonObjectCache.estimatedBytes;
|
|
130
|
+
console.log('CodeYam: Cleared analysis caches', {
|
|
131
|
+
knownObjectCache: `${knownObjectCache.count} entries, ${(knownObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
|
|
132
|
+
nonObjectCache: `${nonObjectCache.count} entries, ${(nonObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
|
|
133
|
+
totalKB: `${(totalBytes / 1024).toFixed(1)}KB`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
123
136
|
}
|
|
124
137
|
// Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
|
|
125
138
|
const ALLOWED_EQUIVALENCY_REASONS = new Set([
|
|
@@ -168,6 +181,7 @@ const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
|
|
|
168
181
|
'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
|
|
169
182
|
'transformed non-object function equivalency - Array.from() equivalency',
|
|
170
183
|
'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
|
|
184
|
+
// 'transformed non-object function equivalency - Explicit array deconstruction equivalency value',
|
|
171
185
|
]);
|
|
172
186
|
export class ScopeDataStructure {
|
|
173
187
|
// Getter for backward compatibility - returns the tree structure
|
|
@@ -203,6 +217,11 @@ export class ScopeDataStructure {
|
|
|
203
217
|
* Maps child component name to the conditions that must be true for it to render.
|
|
204
218
|
*/
|
|
205
219
|
this.rawChildBoundaryGatingConditions = {};
|
|
220
|
+
/**
|
|
221
|
+
* JSX rendering usages collected during AST analysis.
|
|
222
|
+
* Tracks arrays rendered via .map() and strings interpolated in JSX.
|
|
223
|
+
*/
|
|
224
|
+
this.rawJsxRenderingUsages = [];
|
|
206
225
|
this.lastAddToSchemaId = 0;
|
|
207
226
|
this.lastEquivalencyId = 0;
|
|
208
227
|
this.lastEquivalencyDatabaseId = 0;
|
|
@@ -457,6 +476,10 @@ export class ScopeDataStructure {
|
|
|
457
476
|
}
|
|
458
477
|
return;
|
|
459
478
|
}
|
|
479
|
+
// PERF: Early exit for paths with repeated function-call signature patterns
|
|
480
|
+
if (this.hasExcessivePatternRepetition(path)) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
460
483
|
// Update chain metadata for database tracking
|
|
461
484
|
if (equivalencyValueChain.length > 0) {
|
|
462
485
|
equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
|
|
@@ -953,6 +976,12 @@ export class ScopeDataStructure {
|
|
|
953
976
|
const value1 = scopeNode.schema[schemaPath];
|
|
954
977
|
const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
|
|
955
978
|
const bestValue = selectBestValue(value1, value2);
|
|
979
|
+
// PERF: Skip paths with repeated function-call signature patterns
|
|
980
|
+
// to prevent recursive type expansion (e.g., string.localeCompare returns string)
|
|
981
|
+
if (this.hasExcessivePatternRepetition(schemaPath) ||
|
|
982
|
+
this.hasExcessivePatternRepetition(equivalentSchemaPath)) {
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
956
985
|
scopeNode.schema[schemaPath] = bestValue;
|
|
957
986
|
equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
|
|
958
987
|
}
|
|
@@ -964,6 +993,10 @@ export class ScopeDataStructure {
|
|
|
964
993
|
equivalentPath,
|
|
965
994
|
...remainingSchemaPathParts,
|
|
966
995
|
]);
|
|
996
|
+
// PERF: Skip paths with repeated function-call signature patterns
|
|
997
|
+
if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
967
1000
|
equivalentScopeNode.schema[newEquivalentPath] =
|
|
968
1001
|
scopeNode.schema[schemaPath];
|
|
969
1002
|
}
|
|
@@ -1045,6 +1078,23 @@ export class ScopeDataStructure {
|
|
|
1045
1078
|
return true;
|
|
1046
1079
|
}
|
|
1047
1080
|
}
|
|
1081
|
+
// Check for repeated function calls that indicate recursive type expansion.
|
|
1082
|
+
// E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
|
|
1083
|
+
// returns a type that again has localeCompare, causing infinite expansion.
|
|
1084
|
+
// We extract all function call patterns like "funcName(args)" and check if
|
|
1085
|
+
// the same normalized call appears more than once.
|
|
1086
|
+
const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
|
|
1087
|
+
const funcCallMatches = path.match(funcCallPattern);
|
|
1088
|
+
if (funcCallMatches && funcCallMatches.length > 1) {
|
|
1089
|
+
const seen = new Set();
|
|
1090
|
+
for (const match of funcCallMatches) {
|
|
1091
|
+
// Strip leading dot and normalize array indices
|
|
1092
|
+
const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
|
|
1093
|
+
if (seen.has(normalized))
|
|
1094
|
+
return true;
|
|
1095
|
+
seen.add(normalized);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1048
1098
|
// For longer paths, detect any repeated multi-part segments we haven't explicitly listed
|
|
1049
1099
|
const pathParts = this.splitPath(path);
|
|
1050
1100
|
if (pathParts.length <= 6) {
|
|
@@ -1070,21 +1120,36 @@ export class ScopeDataStructure {
|
|
|
1070
1120
|
}
|
|
1071
1121
|
setInstantiatedVariables(scopeNode) {
|
|
1072
1122
|
let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
|
|
1073
|
-
for (const [path,
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1123
|
+
for (const [path, rawEquivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
|
|
1124
|
+
// Normalize to array for consistent handling (supports both string and string[])
|
|
1125
|
+
const equivalentPaths = Array.isArray(rawEquivalentPath)
|
|
1126
|
+
? rawEquivalentPath
|
|
1127
|
+
: rawEquivalentPath
|
|
1128
|
+
? [rawEquivalentPath]
|
|
1129
|
+
: [];
|
|
1130
|
+
for (const equivalentPath of equivalentPaths) {
|
|
1131
|
+
if (typeof equivalentPath !== 'string') {
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
if (equivalentPath.startsWith('signature[')) {
|
|
1135
|
+
const equivalentPathParts = this.splitPath(equivalentPath);
|
|
1136
|
+
instantiatedVariables.push(equivalentPathParts[0]);
|
|
1137
|
+
instantiatedVariables.push(path);
|
|
1138
|
+
}
|
|
1081
1139
|
}
|
|
1082
1140
|
const duplicateInstantiated = instantiatedVariables.find((v) => path.split('::cyDuplicateKey')[0] === v.split('::cyDuplicateKey')[0]);
|
|
1083
1141
|
if (duplicateInstantiated) {
|
|
1084
1142
|
instantiatedVariables.push(path);
|
|
1085
1143
|
}
|
|
1086
1144
|
}
|
|
1087
|
-
|
|
1145
|
+
const instantiatedSeen = new Set();
|
|
1146
|
+
instantiatedVariables = instantiatedVariables.filter((varName) => {
|
|
1147
|
+
if (instantiatedSeen.has(varName)) {
|
|
1148
|
+
return false;
|
|
1149
|
+
}
|
|
1150
|
+
instantiatedSeen.add(varName);
|
|
1151
|
+
return true;
|
|
1152
|
+
});
|
|
1088
1153
|
scopeNode.instantiatedVariables = instantiatedVariables;
|
|
1089
1154
|
if (!scopeNode.tree || scopeNode.tree.length === 0) {
|
|
1090
1155
|
return;
|
|
@@ -1096,9 +1161,16 @@ export class ScopeDataStructure {
|
|
|
1096
1161
|
const parentInstantiatedVariables = [
|
|
1097
1162
|
...(parentScopeNode.parentInstantiatedVariables ?? []),
|
|
1098
1163
|
...parentScopeNode.instantiatedVariables.filter((v) => !v.startsWith('signature[') && !v.startsWith('returnValue')),
|
|
1099
|
-
].filter((varName
|
|
1100
|
-
|
|
1101
|
-
|
|
1164
|
+
].filter((varName) => !instantiatedSeen.has(varName));
|
|
1165
|
+
const parentInstantiatedSeen = new Set();
|
|
1166
|
+
const dedupedParentInstantiatedVariables = parentInstantiatedVariables.filter((varName) => {
|
|
1167
|
+
if (parentInstantiatedSeen.has(varName)) {
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1170
|
+
parentInstantiatedSeen.add(varName);
|
|
1171
|
+
return true;
|
|
1172
|
+
});
|
|
1173
|
+
scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
|
|
1102
1174
|
}
|
|
1103
1175
|
trackFunctionCalls(scopeNode) {
|
|
1104
1176
|
this.captureFunctionCalls(scopeNode);
|
|
@@ -1109,116 +1181,136 @@ export class ScopeDataStructure {
|
|
|
1109
1181
|
return;
|
|
1110
1182
|
}
|
|
1111
1183
|
const { isolatedStructure, isolatedEquivalentVariables } = scopeNode.analysis;
|
|
1184
|
+
// Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
|
|
1185
|
+
const flattenedEquivValues = Object.values(isolatedEquivalentVariables || {}).flatMap((v) => (Array.isArray(v) ? v : [v]));
|
|
1112
1186
|
const allPaths = Array.from(new Set([
|
|
1113
1187
|
...Object.keys(isolatedStructure || {}),
|
|
1114
1188
|
...Object.keys(isolatedEquivalentVariables || {}),
|
|
1115
|
-
...
|
|
1189
|
+
...flattenedEquivValues,
|
|
1116
1190
|
]));
|
|
1117
1191
|
for (let path in isolatedEquivalentVariables) {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1192
|
+
const rawEquivalentValue = isolatedEquivalentVariables?.[path];
|
|
1193
|
+
// Normalize to array for consistent handling
|
|
1194
|
+
const equivalentValues = Array.isArray(rawEquivalentValue)
|
|
1195
|
+
? rawEquivalentValue
|
|
1196
|
+
: [rawEquivalentValue];
|
|
1197
|
+
for (let equivalentValue of equivalentValues) {
|
|
1198
|
+
if (equivalentValue && this.isValidPath(equivalentValue)) {
|
|
1199
|
+
// IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
|
|
1200
|
+
// These markers are critical for distinguishing variable reassignments.
|
|
1201
|
+
// For example, with:
|
|
1202
|
+
// let fetcher = useFetcher<ConfigData>();
|
|
1203
|
+
// const configData = fetcher.data?.data;
|
|
1204
|
+
// fetcher = useFetcher<SettingsData>();
|
|
1205
|
+
// const settingsData = fetcher.data?.data;
|
|
1206
|
+
//
|
|
1207
|
+
// mergeStatements creates:
|
|
1208
|
+
// fetcher → useFetcher<ConfigData>()...
|
|
1209
|
+
// fetcher::cyDuplicateKey1:: → useFetcher<SettingsData>()...
|
|
1210
|
+
// configData → fetcher.data.data
|
|
1211
|
+
// settingsData → fetcher::cyDuplicateKey1::.data.data
|
|
1212
|
+
//
|
|
1213
|
+
// If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
|
|
1214
|
+
// to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
|
|
1215
|
+
path = cleanPath(path, allPaths);
|
|
1216
|
+
equivalentValue = cleanPath(equivalentValue, allPaths);
|
|
1217
|
+
this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
|
|
1218
|
+
// Propagate equivalencies involving parent-scope variables to those parent scopes.
|
|
1219
|
+
// This handles patterns like: collected.push({...entity}) where 'collected' is defined
|
|
1220
|
+
// in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
|
|
1221
|
+
// visible when tracing from the parent scope.
|
|
1222
|
+
const rootVariable = this.extractRootVariable(path);
|
|
1223
|
+
const equivalentRootVariable = this.extractRootVariable(equivalentValue);
|
|
1224
|
+
// Skip propagation for self-referential reassignment patterns like:
|
|
1225
|
+
// x = x.method().functionCallReturnValue
|
|
1226
|
+
// where the path IS the variable itself (not a sub-path like x[] or x.prop).
|
|
1227
|
+
// These create circular references since both sides reference the same variable.
|
|
1228
|
+
//
|
|
1229
|
+
// But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
|
|
1230
|
+
// where the path has additional segments beyond the root variable.
|
|
1231
|
+
const pathIsJustRootVariable = path === rootVariable;
|
|
1232
|
+
const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
|
|
1233
|
+
if (rootVariable &&
|
|
1234
|
+
!isSelfReferentialReassignment &&
|
|
1235
|
+
scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
|
|
1236
|
+
// Find the parent scope where this variable is defined
|
|
1237
|
+
for (const parentScopeName of scopeNode.tree || []) {
|
|
1238
|
+
const parentScope = this.scopeNodes[parentScopeName];
|
|
1239
|
+
if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
|
|
1240
|
+
// Add the equivalency to the parent scope as well
|
|
1241
|
+
this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
|
|
1242
|
+
parentScope, // But store it in the parent scope's equivalencies
|
|
1243
|
+
'propagated parent-variable equivalency');
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1166
1246
|
}
|
|
1167
1247
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1248
|
+
// Propagate sub-property equivalencies when the equivalentValue is a simple variable
|
|
1249
|
+
// that has sub-properties defined in the isolatedEquivalentVariables.
|
|
1250
|
+
// This handles cases like: dataItem={{ structure: completeDataStructure }}
|
|
1251
|
+
// where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
|
|
1252
|
+
// We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
|
|
1253
|
+
const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
|
|
1254
|
+
!equivalentValue.includes('functionCallReturnValue') &&
|
|
1255
|
+
!equivalentValue.includes('.') &&
|
|
1256
|
+
!equivalentValue.includes('[');
|
|
1257
|
+
if (isSimpleVariable) {
|
|
1258
|
+
// Look in current scope and all parent scopes for sub-properties
|
|
1259
|
+
const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
|
|
1260
|
+
for (const scopeName of scopesToCheck) {
|
|
1261
|
+
const checkScope = this.scopeNodes[scopeName];
|
|
1262
|
+
if (!checkScope?.analysis?.isolatedEquivalentVariables)
|
|
1263
|
+
continue;
|
|
1264
|
+
for (const [subPath, rawSubValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
|
|
1265
|
+
// Normalize to array for consistent handling
|
|
1266
|
+
const subValues = Array.isArray(rawSubValue)
|
|
1267
|
+
? rawSubValue
|
|
1268
|
+
: rawSubValue
|
|
1269
|
+
? [rawSubValue]
|
|
1270
|
+
: [];
|
|
1271
|
+
// Check if this is a sub-property of the equivalentValue variable
|
|
1272
|
+
// e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
|
|
1273
|
+
const matchesDot = subPath.startsWith(equivalentValue + '.');
|
|
1274
|
+
const matchesBracket = subPath.startsWith(equivalentValue + '[');
|
|
1275
|
+
if (matchesDot || matchesBracket) {
|
|
1276
|
+
const subPropertyPath = subPath.substring(equivalentValue.length);
|
|
1277
|
+
const newPath = cleanPath(path + subPropertyPath, allPaths);
|
|
1278
|
+
for (const subValue of subValues) {
|
|
1279
|
+
if (typeof subValue !== 'string')
|
|
1280
|
+
continue;
|
|
1281
|
+
const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
1282
|
+
if (newEquivalentValue &&
|
|
1283
|
+
this.isValidPath(newEquivalentValue)) {
|
|
1284
|
+
this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
|
|
1285
|
+
scopeNode, 'propagated sub-property equivalency');
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
// Also check if equivalentValue itself maps to a functionCallReturnValue
|
|
1290
|
+
// e.g., result = useMemo(...).functionCallReturnValue
|
|
1291
|
+
for (const subValue of subValues) {
|
|
1292
|
+
if (subPath === equivalentValue &&
|
|
1293
|
+
typeof subValue === 'string' &&
|
|
1294
|
+
subValue.endsWith('.functionCallReturnValue')) {
|
|
1295
|
+
this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
|
|
1296
|
+
}
|
|
1198
1297
|
}
|
|
1199
|
-
}
|
|
1200
|
-
// Also check if equivalentValue itself maps to a functionCallReturnValue
|
|
1201
|
-
// e.g., result = useMemo(...).functionCallReturnValue
|
|
1202
|
-
if (subPath === equivalentValue &&
|
|
1203
|
-
typeof subValue === 'string' &&
|
|
1204
|
-
subValue.endsWith('.functionCallReturnValue')) {
|
|
1205
|
-
this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
|
|
1206
1298
|
}
|
|
1207
1299
|
}
|
|
1208
1300
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1301
|
+
// Handle function call return values by propagating returnValue.* sub-properties
|
|
1302
|
+
// from the callback scope to the usage path
|
|
1303
|
+
if (equivalentValue.endsWith('.functionCallReturnValue')) {
|
|
1304
|
+
this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
|
|
1305
|
+
// Track which variable receives the return value of each function call
|
|
1306
|
+
// This enables generating separate mock data for each call site
|
|
1307
|
+
this.trackReceivingVariable(path, equivalentValue);
|
|
1308
|
+
}
|
|
1309
|
+
// Also track variables that receive destructured properties from function call return values
|
|
1310
|
+
// e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
|
|
1311
|
+
if (equivalentValue.includes('.functionCallReturnValue.')) {
|
|
1312
|
+
this.trackReceivingVariable(path, equivalentValue);
|
|
1313
|
+
}
|
|
1222
1314
|
}
|
|
1223
1315
|
}
|
|
1224
1316
|
}
|
|
@@ -1362,8 +1454,15 @@ export class ScopeDataStructure {
|
|
|
1362
1454
|
const checkScope = this.scopeNodes[scopeName];
|
|
1363
1455
|
if (!checkScope?.analysis?.isolatedEquivalentVariables)
|
|
1364
1456
|
continue;
|
|
1365
|
-
const
|
|
1366
|
-
|
|
1457
|
+
const rawFunctionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
|
|
1458
|
+
// Normalize to array and find first string ending with 'F'
|
|
1459
|
+
const functionRefs = Array.isArray(rawFunctionRef)
|
|
1460
|
+
? rawFunctionRef
|
|
1461
|
+
: rawFunctionRef
|
|
1462
|
+
? [rawFunctionRef]
|
|
1463
|
+
: [];
|
|
1464
|
+
const functionRef = functionRefs.find((r) => typeof r === 'string' && r.endsWith('F'));
|
|
1465
|
+
if (typeof functionRef === 'string') {
|
|
1367
1466
|
callbackScopeName = functionRef.slice(0, -1);
|
|
1368
1467
|
break;
|
|
1369
1468
|
}
|
|
@@ -1386,22 +1485,32 @@ export class ScopeDataStructure {
|
|
|
1386
1485
|
if (!callbackScope.analysis?.isolatedEquivalentVariables)
|
|
1387
1486
|
return;
|
|
1388
1487
|
const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
|
|
1488
|
+
// Get the first returnValue equivalency (normalize array to single value for these checks)
|
|
1489
|
+
const rawReturnValue = isolatedVars.returnValue;
|
|
1490
|
+
const firstReturnValue = Array.isArray(rawReturnValue)
|
|
1491
|
+
? rawReturnValue[0]
|
|
1492
|
+
: rawReturnValue;
|
|
1389
1493
|
// First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
|
|
1390
1494
|
// If so, we need to look for that variable's sub-properties too
|
|
1391
|
-
const returnValueAlias = typeof
|
|
1392
|
-
|
|
1393
|
-
? isolatedVars.returnValue
|
|
1495
|
+
const returnValueAlias = typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
|
|
1496
|
+
? firstReturnValue
|
|
1394
1497
|
: undefined;
|
|
1395
1498
|
// Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
|
|
1396
1499
|
// When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
|
|
1397
1500
|
let reduceSourceVar;
|
|
1398
|
-
if (typeof
|
|
1399
|
-
const reduceMatch =
|
|
1501
|
+
if (typeof firstReturnValue === 'string') {
|
|
1502
|
+
const reduceMatch = firstReturnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
|
|
1400
1503
|
if (reduceMatch) {
|
|
1401
1504
|
reduceSourceVar = reduceMatch[1];
|
|
1402
1505
|
}
|
|
1403
1506
|
}
|
|
1404
|
-
for (const [subPath,
|
|
1507
|
+
for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
|
|
1508
|
+
// Normalize to array for consistent handling
|
|
1509
|
+
const subValues = Array.isArray(rawSubValue)
|
|
1510
|
+
? rawSubValue
|
|
1511
|
+
: rawSubValue
|
|
1512
|
+
? [rawSubValue]
|
|
1513
|
+
: [];
|
|
1405
1514
|
// Check for direct returnValue.* sub-properties
|
|
1406
1515
|
const isReturnValueSub = subPath.startsWith('returnValue.') ||
|
|
1407
1516
|
subPath.startsWith('returnValue[');
|
|
@@ -1413,33 +1522,36 @@ export class ScopeDataStructure {
|
|
|
1413
1522
|
const isReduceSourceSub = reduceSourceVar &&
|
|
1414
1523
|
(subPath.startsWith(reduceSourceVar + '.') ||
|
|
1415
1524
|
subPath.startsWith(reduceSourceVar + '['));
|
|
1416
|
-
if (
|
|
1417
|
-
(!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
|
|
1418
|
-
continue;
|
|
1419
|
-
// Convert alias/reduceSource paths to returnValue paths
|
|
1420
|
-
let effectiveSubPath = subPath;
|
|
1421
|
-
if (isAliasSub && !isReturnValueSub) {
|
|
1422
|
-
// Replace the alias prefix with returnValue
|
|
1423
|
-
effectiveSubPath =
|
|
1424
|
-
'returnValue' + subPath.substring(returnValueAlias.length);
|
|
1425
|
-
}
|
|
1426
|
-
else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
|
|
1427
|
-
// Replace the reduce source prefix with returnValue
|
|
1428
|
-
effectiveSubPath =
|
|
1429
|
-
'returnValue' + subPath.substring(reduceSourceVar.length);
|
|
1430
|
-
}
|
|
1431
|
-
const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
|
|
1432
|
-
const newPath = cleanPath(path + subPropertyPath, allPaths);
|
|
1433
|
-
let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
1434
|
-
// Resolve variable references through parent scope equivalencies
|
|
1435
|
-
const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
|
|
1436
|
-
newEquivalentValue = resolved.resolvedPath;
|
|
1437
|
-
const equivalentScopeName = resolved.scopeName;
|
|
1438
|
-
if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
|
|
1525
|
+
if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
|
|
1439
1526
|
continue;
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1527
|
+
for (const subValue of subValues) {
|
|
1528
|
+
if (typeof subValue !== 'string')
|
|
1529
|
+
continue;
|
|
1530
|
+
// Convert alias/reduceSource paths to returnValue paths
|
|
1531
|
+
let effectiveSubPath = subPath;
|
|
1532
|
+
if (isAliasSub && !isReturnValueSub) {
|
|
1533
|
+
// Replace the alias prefix with returnValue
|
|
1534
|
+
effectiveSubPath =
|
|
1535
|
+
'returnValue' + subPath.substring(returnValueAlias.length);
|
|
1536
|
+
}
|
|
1537
|
+
else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
|
|
1538
|
+
// Replace the reduce source prefix with returnValue
|
|
1539
|
+
effectiveSubPath =
|
|
1540
|
+
'returnValue' + subPath.substring(reduceSourceVar.length);
|
|
1541
|
+
}
|
|
1542
|
+
const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
|
|
1543
|
+
const newPath = cleanPath(path + subPropertyPath, allPaths);
|
|
1544
|
+
let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
1545
|
+
// Resolve variable references through parent scope equivalencies
|
|
1546
|
+
const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
|
|
1547
|
+
newEquivalentValue = resolved.resolvedPath;
|
|
1548
|
+
const equivalentScopeName = resolved.scopeName;
|
|
1549
|
+
if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
|
|
1550
|
+
continue;
|
|
1551
|
+
this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
|
|
1552
|
+
// Ensure the database entry has the usage path
|
|
1553
|
+
this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
|
|
1554
|
+
}
|
|
1443
1555
|
}
|
|
1444
1556
|
}
|
|
1445
1557
|
/**
|
|
@@ -1471,7 +1583,14 @@ export class ScopeDataStructure {
|
|
|
1471
1583
|
const parentScope = this.scopeNodes[parentScopeName];
|
|
1472
1584
|
if (!parentScope?.analysis?.isolatedEquivalentVariables)
|
|
1473
1585
|
continue;
|
|
1474
|
-
const
|
|
1586
|
+
const rawRootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
|
|
1587
|
+
// Normalize to array and use first string value
|
|
1588
|
+
const rootEquivs = Array.isArray(rawRootEquiv)
|
|
1589
|
+
? rawRootEquiv
|
|
1590
|
+
: rawRootEquiv
|
|
1591
|
+
? [rawRootEquiv]
|
|
1592
|
+
: [];
|
|
1593
|
+
const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
|
|
1475
1594
|
if (typeof rootEquiv === 'string') {
|
|
1476
1595
|
return {
|
|
1477
1596
|
resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
|
|
@@ -1665,6 +1784,7 @@ export class ScopeDataStructure {
|
|
|
1665
1784
|
const remainingPath = this.joinPathParts(remainingPathParts);
|
|
1666
1785
|
if (relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
|
|
1667
1786
|
equivalentValue.scopeNodeName === scopeNode.name) {
|
|
1787
|
+
// DEBUG
|
|
1668
1788
|
continue;
|
|
1669
1789
|
}
|
|
1670
1790
|
const newEquivalentPath = this.joinPathParts([schemaPath, remainingPath]);
|
|
@@ -1806,6 +1926,8 @@ export class ScopeDataStructure {
|
|
|
1806
1926
|
return;
|
|
1807
1927
|
}
|
|
1808
1928
|
const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
|
|
1929
|
+
if (!usageScopeNode)
|
|
1930
|
+
continue;
|
|
1809
1931
|
// Guard against infinite recursion by tracking which paths we've already
|
|
1810
1932
|
// added from addComplexSourcePathVariables
|
|
1811
1933
|
if (this.visitedTracker.checkAndMarkComplexSourceVisited(usageScopeNode.name, newUsageEquivalentPath)) {
|
|
@@ -1854,6 +1976,8 @@ export class ScopeDataStructure {
|
|
|
1854
1976
|
continue;
|
|
1855
1977
|
}
|
|
1856
1978
|
const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
|
|
1979
|
+
if (!usageScopeNode)
|
|
1980
|
+
continue;
|
|
1857
1981
|
// This is put in place to avoid propagating array functions like 'filter' through complex equivalencies
|
|
1858
1982
|
// but may cause problems if the funtion call is not on a known object (e.g. string or array)
|
|
1859
1983
|
if (newUsageEquivalentPath.endsWith(')') ||
|
|
@@ -1950,9 +2074,70 @@ export class ScopeDataStructure {
|
|
|
1950
2074
|
// Update inverted index
|
|
1951
2075
|
this.intermediatesOrderIndex.set(pathId, databaseEntry);
|
|
1952
2076
|
if (intermediateIndex === 0) {
|
|
1953
|
-
|
|
2077
|
+
let isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
|
|
1954
2078
|
pathInfo.schemaPath.includes('functionCallReturnValue');
|
|
1955
|
-
if
|
|
2079
|
+
// Check if path STARTS with a spread pattern like [...var]
|
|
2080
|
+
// This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
|
|
2081
|
+
// where the spread source variable needs to be resolved to a signature path.
|
|
2082
|
+
// We do this REGARDLESS of isValidSourceCandidate because even paths containing
|
|
2083
|
+
// functionCallReturnValue may need spread resolution to trace back to the signature.
|
|
2084
|
+
const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
|
|
2085
|
+
if (spreadMatch) {
|
|
2086
|
+
const spreadVar = spreadMatch[1];
|
|
2087
|
+
const spreadPattern = spreadMatch[0]; // The full [...var] match
|
|
2088
|
+
const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
|
|
2089
|
+
if (scopeNode?.equivalencies) {
|
|
2090
|
+
// Follow the equivalency chain to find a signature path
|
|
2091
|
+
// e.g., files (cyScope1) → files (root) → signature[0].files
|
|
2092
|
+
const resolveToSignature = (varName, currentScopeName, visited) => {
|
|
2093
|
+
const visitKey = `${currentScopeName}::${varName}`;
|
|
2094
|
+
if (visited.has(visitKey))
|
|
2095
|
+
return null;
|
|
2096
|
+
visited.add(visitKey);
|
|
2097
|
+
const currentScope = this.scopeNodes[currentScopeName];
|
|
2098
|
+
if (!currentScope?.equivalencies)
|
|
2099
|
+
return null;
|
|
2100
|
+
const varEquivs = currentScope.equivalencies[varName];
|
|
2101
|
+
if (!varEquivs)
|
|
2102
|
+
return null;
|
|
2103
|
+
// First check if any equivalency directly points to a signature path
|
|
2104
|
+
const signatureEquiv = varEquivs.find((eq) => eq.schemaPath.startsWith('signature['));
|
|
2105
|
+
if (signatureEquiv) {
|
|
2106
|
+
return signatureEquiv;
|
|
2107
|
+
}
|
|
2108
|
+
// Otherwise, follow the chain to other scopes
|
|
2109
|
+
for (const equiv of varEquivs) {
|
|
2110
|
+
// If the equivalency points to the same variable in a different scope,
|
|
2111
|
+
// follow the chain
|
|
2112
|
+
if (equiv.schemaPath === varName &&
|
|
2113
|
+
equiv.scopeNodeName !== currentScopeName) {
|
|
2114
|
+
const result = resolveToSignature(varName, equiv.scopeNodeName, visited);
|
|
2115
|
+
if (result)
|
|
2116
|
+
return result;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return null;
|
|
2120
|
+
};
|
|
2121
|
+
const signatureEquiv = resolveToSignature(spreadVar, pathInfo.scopeNodeName, new Set());
|
|
2122
|
+
if (signatureEquiv) {
|
|
2123
|
+
// Replace ONLY the [...var] part with the resolved signature path
|
|
2124
|
+
// This preserves any suffix like .sort(...).functionCallReturnValue[][0]
|
|
2125
|
+
const resolvedPath = pathInfo.schemaPath.replace(spreadPattern, signatureEquiv.schemaPath);
|
|
2126
|
+
// Add the resolved path as a source candidate
|
|
2127
|
+
if (!databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === resolvedPath &&
|
|
2128
|
+
sc.scopeNodeName === pathInfo.scopeNodeName)) {
|
|
2129
|
+
databaseEntry.sourceCandidates.push({
|
|
2130
|
+
scopeNodeName: pathInfo.scopeNodeName,
|
|
2131
|
+
schemaPath: resolvedPath,
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
isValidSourceCandidate = true;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
if (isValidSourceCandidate &&
|
|
2139
|
+
!databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === pathInfo.schemaPath &&
|
|
2140
|
+
sc.scopeNodeName === pathInfo.scopeNodeName)) {
|
|
1956
2141
|
databaseEntry.sourceCandidates.push(pathInfo);
|
|
1957
2142
|
}
|
|
1958
2143
|
}
|
|
@@ -2098,6 +2283,13 @@ export class ScopeDataStructure {
|
|
|
2098
2283
|
delete scopeNode.schema[key];
|
|
2099
2284
|
}
|
|
2100
2285
|
}
|
|
2286
|
+
// Ensure parameter-to-signature equivalencies are fully propagated.
|
|
2287
|
+
// When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
|
|
2288
|
+
// all sub-paths of that variable should also appear under `signature[N]`.
|
|
2289
|
+
// This handles cases where the sub-path was added to the schema via a propagation
|
|
2290
|
+
// chain that already included the variable↔signature equivalency, causing the
|
|
2291
|
+
// cycle detection to prevent the reverse mapping.
|
|
2292
|
+
this.propagateParameterToSignaturePaths(scopeNode);
|
|
2101
2293
|
fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
|
|
2102
2294
|
if (final) {
|
|
2103
2295
|
for (const manager of this.equivalencyManagers) {
|
|
@@ -2109,6 +2301,85 @@ export class ScopeDataStructure {
|
|
|
2109
2301
|
ensureSchemaConsistency(scopeNode.schema);
|
|
2110
2302
|
}
|
|
2111
2303
|
}
|
|
2304
|
+
/**
|
|
2305
|
+
* For each equivalency where a simple variable maps to signature[N],
|
|
2306
|
+
* ensure all sub-paths of that variable are reflected under signature[N].
|
|
2307
|
+
*/
|
|
2308
|
+
propagateParameterToSignaturePaths(scopeNode) {
|
|
2309
|
+
// Helper: check if a type is a concrete scalar that cannot have sub-properties.
|
|
2310
|
+
const SCALAR_TYPES = new Set([
|
|
2311
|
+
'string',
|
|
2312
|
+
'number',
|
|
2313
|
+
'boolean',
|
|
2314
|
+
'bigint',
|
|
2315
|
+
'symbol',
|
|
2316
|
+
'void',
|
|
2317
|
+
'never',
|
|
2318
|
+
]);
|
|
2319
|
+
const isDefinitelyScalar = (type) => {
|
|
2320
|
+
const parts = type.split('|').map((s) => s.trim());
|
|
2321
|
+
const base = parts.filter((s) => s !== 'undefined' && s !== 'null');
|
|
2322
|
+
return base.length > 0 && base.every((b) => SCALAR_TYPES.has(b));
|
|
2323
|
+
};
|
|
2324
|
+
// Find variable → signature[N] equivalencies
|
|
2325
|
+
for (const [varName, equivalencies] of Object.entries(scopeNode.equivalencies)) {
|
|
2326
|
+
// Only process simple variable names (no dots, brackets, or parens)
|
|
2327
|
+
if (varName.includes('.') ||
|
|
2328
|
+
varName.includes('[') ||
|
|
2329
|
+
varName.includes('(')) {
|
|
2330
|
+
continue;
|
|
2331
|
+
}
|
|
2332
|
+
for (const equiv of equivalencies) {
|
|
2333
|
+
if (equiv.scopeNodeName === scopeNode.name &&
|
|
2334
|
+
equiv.schemaPath.startsWith('signature[')) {
|
|
2335
|
+
const signaturePath = equiv.schemaPath;
|
|
2336
|
+
const varPrefix = varName + '.';
|
|
2337
|
+
const varBracketPrefix = varName + '[';
|
|
2338
|
+
// Find all schema keys starting with the variable
|
|
2339
|
+
for (const key in scopeNode.schema) {
|
|
2340
|
+
if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
|
|
2341
|
+
const suffix = key.slice(varName.length);
|
|
2342
|
+
const sigKey = signaturePath + suffix;
|
|
2343
|
+
// Only add if the signature path doesn't already exist
|
|
2344
|
+
if (!scopeNode.schema[sigKey]) {
|
|
2345
|
+
// Check if this path represents variable conflation:
|
|
2346
|
+
// When a standalone variable (e.g., showWorkoutForm from useState)
|
|
2347
|
+
// appears as a sub-property of a scalar-typed ancestor (e.g.,
|
|
2348
|
+
// activity_type = "string"), it's from scope conflation, not real
|
|
2349
|
+
// property access. Block these while allowing legitimate built-in
|
|
2350
|
+
// accesses like string.length or string.slice.
|
|
2351
|
+
let isConflatedPath = false;
|
|
2352
|
+
let checkPos = signaturePath.length;
|
|
2353
|
+
while (true) {
|
|
2354
|
+
checkPos = sigKey.indexOf('.', checkPos + 1);
|
|
2355
|
+
if (checkPos === -1)
|
|
2356
|
+
break;
|
|
2357
|
+
const ancestorPath = sigKey.substring(0, checkPos);
|
|
2358
|
+
const ancestorType = scopeNode.schema[ancestorPath];
|
|
2359
|
+
if (ancestorType && isDefinitelyScalar(ancestorType)) {
|
|
2360
|
+
// Ancestor is scalar — check if the immediate sub-property
|
|
2361
|
+
// is also a standalone variable (indicating conflation)
|
|
2362
|
+
const afterDot = sigKey.substring(checkPos + 1);
|
|
2363
|
+
const nextSep = afterDot.search(/[.\[]/);
|
|
2364
|
+
const subPropName = nextSep === -1
|
|
2365
|
+
? afterDot
|
|
2366
|
+
: afterDot.substring(0, nextSep);
|
|
2367
|
+
if (scopeNode.schema[subPropName] !== undefined) {
|
|
2368
|
+
isConflatedPath = true;
|
|
2369
|
+
break;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
if (!isConflatedPath) {
|
|
2374
|
+
scopeNode.schema[sigKey] = scopeNode.schema[key];
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2112
2383
|
filterAndConvertSchema({ filterPath, newPath, schema, }) {
|
|
2113
2384
|
const filterPathParts = this.splitPath(filterPath);
|
|
2114
2385
|
return Object.keys(schema).reduce((acc, key) => {
|
|
@@ -2168,6 +2439,10 @@ export class ScopeDataStructure {
|
|
|
2168
2439
|
path,
|
|
2169
2440
|
...this.splitPath(key).slice(equivalentValueSchemaPathParts.length),
|
|
2170
2441
|
]);
|
|
2442
|
+
// PERF: Skip keys with repeated function-call signature patterns
|
|
2443
|
+
// to prevent recursive type expansion (e.g., string.localeCompare returns string)
|
|
2444
|
+
if (this.hasExcessivePatternRepetition(newKey))
|
|
2445
|
+
continue;
|
|
2171
2446
|
resolvedSchema[newKey] = value;
|
|
2172
2447
|
}
|
|
2173
2448
|
}
|
|
@@ -2189,6 +2464,9 @@ export class ScopeDataStructure {
|
|
|
2189
2464
|
if (!subSchema)
|
|
2190
2465
|
continue;
|
|
2191
2466
|
for (const resolvedKey in subSchema) {
|
|
2467
|
+
// PERF: Skip keys with repeated function-call signature patterns
|
|
2468
|
+
if (this.hasExcessivePatternRepetition(resolvedKey))
|
|
2469
|
+
continue;
|
|
2192
2470
|
if (!resolvedSchema[resolvedKey] ||
|
|
2193
2471
|
subSchema[resolvedKey] === 'unknown') {
|
|
2194
2472
|
resolvedSchema[resolvedKey] = subSchema[resolvedKey];
|
|
@@ -2362,18 +2640,204 @@ export class ScopeDataStructure {
|
|
|
2362
2640
|
if (!scopeNode) {
|
|
2363
2641
|
return {};
|
|
2364
2642
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2643
|
+
// Collect all descendant scope names (including the scope itself)
|
|
2644
|
+
// This ensures we include external calls from nested scopes like cyScope2
|
|
2645
|
+
const getAllDescendantScopeNames = (node) => {
|
|
2646
|
+
const names = new Set([node.name]);
|
|
2647
|
+
for (const child of node.children) {
|
|
2648
|
+
for (const name of getAllDescendantScopeNames(child)) {
|
|
2649
|
+
names.add(name);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return names;
|
|
2653
|
+
};
|
|
2654
|
+
const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
|
|
2655
|
+
const descendantScopeNames = treeNode
|
|
2656
|
+
? getAllDescendantScopeNames(treeNode)
|
|
2657
|
+
: new Set([scopeNode.name]);
|
|
2658
|
+
// Get all external function calls made from this scope or any descendant scope
|
|
2659
|
+
// This allows us to include prop equivalencies from JSX components
|
|
2660
|
+
// that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
|
|
2661
|
+
const externalCallsFromScope = this.externalFunctionCalls.filter((efc) => descendantScopeNames.has(efc.callScope));
|
|
2662
|
+
const externalCallNames = new Set(externalCallsFromScope.map((efc) => efc.name));
|
|
2663
|
+
// Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
|
|
2664
|
+
const usageMatchesScope = (usage) => descendantScopeNames.has(usage.scopeNodeName) ||
|
|
2665
|
+
externalCallNames.has(usage.scopeNodeName);
|
|
2666
|
+
const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some(usageMatchesScope));
|
|
2667
|
+
// Helper to resolve a source candidate through equivalency chains to find signature paths
|
|
2668
|
+
const resolveToSignature = (source, visited) => {
|
|
2669
|
+
const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
|
|
2670
|
+
if (visited.has(visitKey))
|
|
2671
|
+
return [];
|
|
2672
|
+
visited.add(visitKey);
|
|
2673
|
+
// If already a signature path, return as-is
|
|
2674
|
+
if (source.schemaPath.startsWith('signature[')) {
|
|
2675
|
+
return [source];
|
|
2676
|
+
}
|
|
2677
|
+
const currentScope = this.scopeNodes[source.scopeNodeName];
|
|
2678
|
+
if (!currentScope?.equivalencies)
|
|
2679
|
+
return [source];
|
|
2680
|
+
// Check for direct equivalencies FIRST (full path match)
|
|
2681
|
+
// This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
|
|
2682
|
+
// before prefix matching tries "useMemo(...)" which goes to the useMemo scope
|
|
2683
|
+
const directEquivs = currentScope.equivalencies[source.schemaPath];
|
|
2684
|
+
if (directEquivs?.length > 0) {
|
|
2685
|
+
const results = [];
|
|
2686
|
+
for (const equiv of directEquivs) {
|
|
2687
|
+
const resolved = resolveToSignature({
|
|
2688
|
+
scopeNodeName: equiv.scopeNodeName,
|
|
2689
|
+
schemaPath: equiv.schemaPath,
|
|
2690
|
+
}, visited);
|
|
2691
|
+
results.push(...resolved);
|
|
2692
|
+
}
|
|
2693
|
+
if (results.length > 0)
|
|
2694
|
+
return results;
|
|
2695
|
+
}
|
|
2696
|
+
// Handle spread patterns like [...items].sort().functionCallReturnValue
|
|
2697
|
+
// Extract the spread variable and resolve it through the equivalency chain
|
|
2698
|
+
const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
|
|
2699
|
+
if (spreadMatch) {
|
|
2700
|
+
const spreadVar = spreadMatch[1];
|
|
2701
|
+
const spreadPattern = spreadMatch[0];
|
|
2702
|
+
const varEquivs = currentScope.equivalencies[spreadVar];
|
|
2703
|
+
if (varEquivs?.length > 0) {
|
|
2704
|
+
const results = [];
|
|
2705
|
+
for (const equiv of varEquivs) {
|
|
2706
|
+
// Follow the variable equivalency and then resolve from there
|
|
2707
|
+
const resolvedVar = resolveToSignature({
|
|
2708
|
+
scopeNodeName: equiv.scopeNodeName,
|
|
2709
|
+
schemaPath: equiv.schemaPath,
|
|
2710
|
+
}, visited);
|
|
2711
|
+
// For each resolved variable path, create the full path with array element suffix
|
|
2712
|
+
for (const rv of resolvedVar) {
|
|
2713
|
+
if (rv.schemaPath.startsWith('signature[')) {
|
|
2714
|
+
// Get the suffix after the spread pattern
|
|
2715
|
+
let suffix = source.schemaPath.slice(spreadPattern.length);
|
|
2716
|
+
// Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
|
|
2717
|
+
// These don't change the data identity, just transform it.
|
|
2718
|
+
// Keep only the final element access parts like [0], [1], etc.
|
|
2719
|
+
// Pattern: strip everything from a method call up through functionCallReturnValue[]
|
|
2720
|
+
suffix = suffix.replace(/\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g, '');
|
|
2721
|
+
// Also handle simpler case without nested parens
|
|
2722
|
+
suffix = suffix.replace(/\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g, '');
|
|
2723
|
+
// Add [] to indicate array element access from the spread
|
|
2724
|
+
const resolvedPath = rv.schemaPath + '[]' + suffix;
|
|
2725
|
+
results.push({
|
|
2726
|
+
scopeNodeName: rv.scopeNodeName,
|
|
2727
|
+
schemaPath: resolvedPath,
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
if (results.length > 0)
|
|
2733
|
+
return results;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
// Try to find prefix equivalencies that can resolve this path
|
|
2737
|
+
// For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
|
|
2738
|
+
const pathParts = this.splitPath(source.schemaPath);
|
|
2739
|
+
for (let i = pathParts.length - 1; i > 0; i--) {
|
|
2740
|
+
const prefix = this.joinPathParts(pathParts.slice(0, i));
|
|
2741
|
+
const suffix = this.joinPathParts(pathParts.slice(i));
|
|
2742
|
+
const prefixEquivs = currentScope.equivalencies[prefix];
|
|
2743
|
+
if (prefixEquivs?.length > 0) {
|
|
2744
|
+
const results = [];
|
|
2745
|
+
for (const equiv of prefixEquivs) {
|
|
2746
|
+
const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
|
|
2747
|
+
const resolved = resolveToSignature({ scopeNodeName: equiv.scopeNodeName, schemaPath: newPath }, visited);
|
|
2748
|
+
results.push(...resolved);
|
|
2749
|
+
}
|
|
2750
|
+
if (results.length > 0)
|
|
2751
|
+
return results;
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
return [source];
|
|
2755
|
+
};
|
|
2756
|
+
const acc = entries.reduce((result, entry) => {
|
|
2367
2757
|
var _a;
|
|
2368
2758
|
if (entry.sourceCandidates.length === 0)
|
|
2369
|
-
return
|
|
2370
|
-
const usages = entry.usages.filter(
|
|
2759
|
+
return result;
|
|
2760
|
+
const usages = entry.usages.filter(usageMatchesScope);
|
|
2371
2761
|
for (const usage of usages) {
|
|
2372
|
-
|
|
2373
|
-
|
|
2762
|
+
result[_a = usage.schemaPath] || (result[_a] = []);
|
|
2763
|
+
// Resolve each source candidate through the equivalency chain
|
|
2764
|
+
for (const source of entry.sourceCandidates) {
|
|
2765
|
+
const resolvedSources = resolveToSignature(source, new Set());
|
|
2766
|
+
result[usage.schemaPath].push(...resolvedSources);
|
|
2767
|
+
}
|
|
2374
2768
|
}
|
|
2375
|
-
return
|
|
2769
|
+
return result;
|
|
2376
2770
|
}, {});
|
|
2771
|
+
// Post-processing: enrich useState-backed sources with co-located external
|
|
2772
|
+
// function calls. When a useState value resolves to a setter variable that
|
|
2773
|
+
// lives in the same scope as a fetch/API call, that fetch is a data source.
|
|
2774
|
+
this.enrichUseStateSourcesWithCoLocatedCalls(acc);
|
|
2775
|
+
return acc;
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* For each source that ends at a useState path, check if the setter was called
|
|
2779
|
+
* from a scope that also contains external function calls (like fetch).
|
|
2780
|
+
* If so, add those external calls as additional source candidates.
|
|
2781
|
+
*/
|
|
2782
|
+
enrichUseStateSourcesWithCoLocatedCalls(acc) {
|
|
2783
|
+
const rootScopeName = this.scopeTreeManager.getRootName();
|
|
2784
|
+
const rootScope = this.scopeNodes[rootScopeName];
|
|
2785
|
+
if (!rootScope)
|
|
2786
|
+
return;
|
|
2787
|
+
// Collect all descendants for each scope node
|
|
2788
|
+
const getAllDescendants = (node) => {
|
|
2789
|
+
const names = new Set([node.name]);
|
|
2790
|
+
for (const child of node.children) {
|
|
2791
|
+
for (const name of getAllDescendants(child)) {
|
|
2792
|
+
names.add(name);
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
return names;
|
|
2796
|
+
};
|
|
2797
|
+
for (const [usagePath, sources] of Object.entries(acc)) {
|
|
2798
|
+
const additionalSources = [];
|
|
2799
|
+
for (const source of sources) {
|
|
2800
|
+
// Check if this source is a useState-related terminal path
|
|
2801
|
+
// (e.g., useState(X).functionCallReturnValue[1] or useState(X).signature[0])
|
|
2802
|
+
if (!source.schemaPath.match(/^useState\([^)]*\)\./))
|
|
2803
|
+
continue;
|
|
2804
|
+
// Find the useState call from the source path
|
|
2805
|
+
const useStateCallMatch = source.schemaPath.match(/^(useState\([^)]*\))\./);
|
|
2806
|
+
if (!useStateCallMatch)
|
|
2807
|
+
continue;
|
|
2808
|
+
const useStateCall = useStateCallMatch[1];
|
|
2809
|
+
// Look in the root scope for the useState value equivalency
|
|
2810
|
+
// which tells us where the setter was called from
|
|
2811
|
+
const valuePath = `${useStateCall}.functionCallReturnValue[0]`;
|
|
2812
|
+
const valueEquivs = rootScope.equivalencies[valuePath];
|
|
2813
|
+
if (!valueEquivs)
|
|
2814
|
+
continue;
|
|
2815
|
+
for (const equiv of valueEquivs) {
|
|
2816
|
+
// Find the scope where the setter was called
|
|
2817
|
+
const setterScopeName = equiv.scopeNodeName;
|
|
2818
|
+
const setterScopeTree = this.scopeTreeManager.findNode(setterScopeName);
|
|
2819
|
+
if (!setterScopeTree)
|
|
2820
|
+
continue;
|
|
2821
|
+
// Get all descendant scope names from the setter scope
|
|
2822
|
+
const relatedScopes = getAllDescendants(setterScopeTree);
|
|
2823
|
+
// Find external function calls in those scopes whose return values
|
|
2824
|
+
// are actually consumed (assigned to a variable). This excludes
|
|
2825
|
+
// fire-and-forget calls like analytics.track() or console.log().
|
|
2826
|
+
const coLocatedCalls = this.externalFunctionCalls.filter((efc) => relatedScopes.has(efc.callScope) &&
|
|
2827
|
+
efc.receivingVariableNames &&
|
|
2828
|
+
efc.receivingVariableNames.length > 0);
|
|
2829
|
+
for (const call of coLocatedCalls) {
|
|
2830
|
+
additionalSources.push({
|
|
2831
|
+
scopeNodeName: call.callScope,
|
|
2832
|
+
schemaPath: `${call.callSignature}.functionCallReturnValue`,
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
if (additionalSources.length > 0) {
|
|
2838
|
+
acc[usagePath].push(...additionalSources);
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2377
2841
|
}
|
|
2378
2842
|
getUsageEquivalencies(functionName) {
|
|
2379
2843
|
const scopeNode = this.getScopeOrFunctionCallInfo(functionName);
|
|
@@ -2438,6 +2902,66 @@ export class ScopeDataStructure {
|
|
|
2438
2902
|
}
|
|
2439
2903
|
}
|
|
2440
2904
|
}
|
|
2905
|
+
// Enrich schema with deeply nested paths from internal function call scopes.
|
|
2906
|
+
// When a function call like traverse(tree) exists, and traverse's scope has
|
|
2907
|
+
// signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
|
|
2908
|
+
// we need to map those paths back to the argument variable (tree) in this scope.
|
|
2909
|
+
// This handles cases where cycle detection prevented the equivalency chain from
|
|
2910
|
+
// propagating deep paths during Phase 2 batch queue processing.
|
|
2911
|
+
for (const equivalenceKey in equivalencies ?? {}) {
|
|
2912
|
+
// Look for keys matching function call pattern: funcName(...).signature[N]
|
|
2913
|
+
const funcCallMatch = equivalenceKey.match(/^([^(]+)\(.*?\)\.(signature\[\d+\])$/);
|
|
2914
|
+
if (!funcCallMatch)
|
|
2915
|
+
continue;
|
|
2916
|
+
const calledFunctionName = funcCallMatch[1];
|
|
2917
|
+
const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
|
|
2918
|
+
for (const equivalenceValue of equivalencies[equivalenceKey]) {
|
|
2919
|
+
if (equivalenceValue.scopeNodeName !== scopeName)
|
|
2920
|
+
continue;
|
|
2921
|
+
const targetVariable = equivalenceValue.schemaPath;
|
|
2922
|
+
// Get the called function's schema (includes propagated parameter paths)
|
|
2923
|
+
const childSchema = this.getSchema({
|
|
2924
|
+
scopeName: calledFunctionName,
|
|
2925
|
+
});
|
|
2926
|
+
if (!childSchema)
|
|
2927
|
+
continue;
|
|
2928
|
+
// Map child function's signature paths to parent variable paths
|
|
2929
|
+
const sigPrefix = signatureParam + '.';
|
|
2930
|
+
const sigBracketPrefix = signatureParam + '[';
|
|
2931
|
+
for (const childKey in childSchema) {
|
|
2932
|
+
let suffix = null;
|
|
2933
|
+
if (childKey.startsWith(sigPrefix)) {
|
|
2934
|
+
suffix = childKey.slice(signatureParam.length);
|
|
2935
|
+
}
|
|
2936
|
+
else if (childKey.startsWith(sigBracketPrefix)) {
|
|
2937
|
+
suffix = childKey.slice(signatureParam.length);
|
|
2938
|
+
}
|
|
2939
|
+
if (suffix !== null) {
|
|
2940
|
+
const parentKey = targetVariable + suffix;
|
|
2941
|
+
if (!schema[parentKey]) {
|
|
2942
|
+
schema[parentKey] = childSchema[childKey];
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
// Helper: check if a type is a concrete scalar that cannot have sub-properties.
|
|
2949
|
+
// e.g., "string", "number | undefined", "boolean | null" are scalar.
|
|
2950
|
+
// "object", "array", "function", "unknown", "Workout", etc. are NOT scalar.
|
|
2951
|
+
const SCALAR_TYPES = new Set([
|
|
2952
|
+
'string',
|
|
2953
|
+
'number',
|
|
2954
|
+
'boolean',
|
|
2955
|
+
'bigint',
|
|
2956
|
+
'symbol',
|
|
2957
|
+
'void',
|
|
2958
|
+
'never',
|
|
2959
|
+
]);
|
|
2960
|
+
const isDefinitelyScalarType = (type) => {
|
|
2961
|
+
const parts = type.split('|').map((s) => s.trim());
|
|
2962
|
+
const base = parts.filter((s) => s !== 'undefined' && s !== 'null');
|
|
2963
|
+
return base.length > 0 && base.every((b) => SCALAR_TYPES.has(b));
|
|
2964
|
+
};
|
|
2441
2965
|
// Propagate nested paths from variables to their signature equivalents
|
|
2442
2966
|
// e.g., if workouts = signature[0].workouts, then workouts[].title becomes
|
|
2443
2967
|
// signature[0].workouts[].title
|
|
@@ -2457,7 +2981,67 @@ export class ScopeDataStructure {
|
|
|
2457
2981
|
const signatureKey = signaturePath + suffix;
|
|
2458
2982
|
// Add to schema if not already present
|
|
2459
2983
|
if (!tempScopeNode.schema[signatureKey]) {
|
|
2460
|
-
|
|
2984
|
+
// Check if this path represents variable conflation:
|
|
2985
|
+
// When a standalone variable (e.g., showWorkoutForm from useState)
|
|
2986
|
+
// appears as a sub-property of a scalar-typed ancestor (e.g.,
|
|
2987
|
+
// activity_type = "string"), it's from scope conflation, not real
|
|
2988
|
+
// property access. Block these while allowing legitimate built-in
|
|
2989
|
+
// accesses like string.length or string.slice.
|
|
2990
|
+
let isConflatedPath = false;
|
|
2991
|
+
let checkPos = signaturePath.length;
|
|
2992
|
+
while (true) {
|
|
2993
|
+
checkPos = signatureKey.indexOf('.', checkPos + 1);
|
|
2994
|
+
if (checkPos === -1)
|
|
2995
|
+
break;
|
|
2996
|
+
const ancestorPath = signatureKey.substring(0, checkPos);
|
|
2997
|
+
const ancestorType = tempScopeNode.schema[ancestorPath];
|
|
2998
|
+
if (ancestorType && isDefinitelyScalarType(ancestorType)) {
|
|
2999
|
+
// Ancestor is scalar — check if the immediate sub-property
|
|
3000
|
+
// is also a standalone variable (indicating conflation)
|
|
3001
|
+
const afterDot = signatureKey.substring(checkPos + 1);
|
|
3002
|
+
const nextSep = afterDot.search(/[.\[]/);
|
|
3003
|
+
const subPropName = nextSep === -1 ? afterDot : afterDot.substring(0, nextSep);
|
|
3004
|
+
if (schema[subPropName] !== undefined) {
|
|
3005
|
+
isConflatedPath = true;
|
|
3006
|
+
break;
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
if (!isConflatedPath) {
|
|
3011
|
+
tempScopeNode.schema[signatureKey] = schema[schemaKey];
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
// Post-process: filter out conflated signature paths.
|
|
3018
|
+
// During phase 2 scope analysis, useState(false) conflation can create
|
|
3019
|
+
// bad paths like signature[0].mockWorkouts[].activity_type.showWorkoutForm
|
|
3020
|
+
// directly in scopeNode.schema. These flow through signatureInSchema into
|
|
3021
|
+
// tempScopeNode.schema without any guard. Filter them out here by checking:
|
|
3022
|
+
// 1. An ancestor in the path has a concrete scalar type (string, number, boolean, etc.)
|
|
3023
|
+
// 2. The immediate sub-property of that scalar ancestor is also a standalone
|
|
3024
|
+
// variable in the schema (indicating conflation, not a real property access)
|
|
3025
|
+
for (const key of Object.keys(tempScopeNode.schema)) {
|
|
3026
|
+
if (!key.startsWith('signature['))
|
|
3027
|
+
continue;
|
|
3028
|
+
// Walk through the path looking for scalar-typed ancestors
|
|
3029
|
+
let pos = 0;
|
|
3030
|
+
while (true) {
|
|
3031
|
+
pos = key.indexOf('.', pos + 1);
|
|
3032
|
+
if (pos === -1)
|
|
3033
|
+
break;
|
|
3034
|
+
const ancestorPath = key.substring(0, pos);
|
|
3035
|
+
const ancestorType = tempScopeNode.schema[ancestorPath];
|
|
3036
|
+
if (ancestorType && isDefinitelyScalarType(ancestorType)) {
|
|
3037
|
+
// Found a scalar ancestor — check if the sub-property name
|
|
3038
|
+
// is a standalone variable in the getSchema() result
|
|
3039
|
+
const afterDot = key.substring(pos + 1);
|
|
3040
|
+
const nextSep = afterDot.search(/[.\[]/);
|
|
3041
|
+
const subPropName = nextSep === -1 ? afterDot : afterDot.substring(0, nextSep);
|
|
3042
|
+
if (schema[subPropName] !== undefined) {
|
|
3043
|
+
delete tempScopeNode.schema[key];
|
|
3044
|
+
break;
|
|
2461
3045
|
}
|
|
2462
3046
|
}
|
|
2463
3047
|
}
|
|
@@ -2659,13 +3243,35 @@ export class ScopeDataStructure {
|
|
|
2659
3243
|
getEquivalentSignatureVariables() {
|
|
2660
3244
|
const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
|
|
2661
3245
|
const equivalentSignatureVariables = {};
|
|
3246
|
+
// Helper to add equivalencies - accumulates into array if multiple values for same key
|
|
3247
|
+
// This is critical for OR expressions like `x = a || b` where x should map to both a and b
|
|
3248
|
+
const addEquivalency = (key, value) => {
|
|
3249
|
+
const existing = equivalentSignatureVariables[key];
|
|
3250
|
+
if (existing === undefined) {
|
|
3251
|
+
// First value - store as string
|
|
3252
|
+
equivalentSignatureVariables[key] = value;
|
|
3253
|
+
}
|
|
3254
|
+
else if (typeof existing === 'string') {
|
|
3255
|
+
if (existing !== value) {
|
|
3256
|
+
// Second different value - convert to array
|
|
3257
|
+
equivalentSignatureVariables[key] = [existing, value];
|
|
3258
|
+
}
|
|
3259
|
+
// Same value - no change needed
|
|
3260
|
+
}
|
|
3261
|
+
else {
|
|
3262
|
+
// Already an array - add if not already present
|
|
3263
|
+
if (!existing.includes(value)) {
|
|
3264
|
+
existing.push(value);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
};
|
|
2662
3268
|
for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
|
|
2663
3269
|
for (const equivalentValue of equivalentValues) {
|
|
2664
3270
|
// Case 1: Props/signature equivalencies (existing behavior)
|
|
2665
3271
|
// Maps local variable names to their signature paths
|
|
2666
3272
|
// e.g., "propValue" -> "signature[0].prop"
|
|
2667
3273
|
if (path.startsWith('signature[')) {
|
|
2668
|
-
|
|
3274
|
+
addEquivalency(equivalentValue.schemaPath, path);
|
|
2669
3275
|
}
|
|
2670
3276
|
// Case 2: Hook variable equivalencies (new behavior)
|
|
2671
3277
|
// The equivalencies are stored as: path = variable name, schemaPath = data source
|
|
@@ -2675,11 +3281,25 @@ export class ScopeDataStructure {
|
|
|
2675
3281
|
// "useFetcher<...>().state" for execution flow validation
|
|
2676
3282
|
if (equivalentValue.schemaPath.endsWith('.functionCallReturnValue')) {
|
|
2677
3283
|
// Extract the hook call path (everything before .functionCallReturnValue)
|
|
2678
|
-
|
|
3284
|
+
let hookCallPath = equivalentValue.schemaPath.slice(0, -'.functionCallReturnValue'.length);
|
|
2679
3285
|
// Only include if it looks like a hook call (contains parentheses)
|
|
2680
3286
|
// and the variable name (path) is a simple identifier (no dots)
|
|
2681
3287
|
if (hookCallPath.includes('(') && !path.includes('.')) {
|
|
2682
|
-
|
|
3288
|
+
// Special case: If hookCallPath is a callback scope (cyScope pattern),
|
|
3289
|
+
// trace through it to find what the callback actually returns.
|
|
3290
|
+
// This handles useState(() => { return prop; }) patterns.
|
|
3291
|
+
const cyScopeMatch = hookCallPath.match(/^(cyScope\d+)\(\)$/);
|
|
3292
|
+
if (cyScopeMatch) {
|
|
3293
|
+
// Use the equivalency database to trace the callback's return value
|
|
3294
|
+
// to its actual source (e.g., viewModeFromUrl -> segments -> params -> useParams)
|
|
3295
|
+
const dbEntry = this.getEquivalenciesDatabaseEntry(scopeNode.name, // Component scope
|
|
3296
|
+
path);
|
|
3297
|
+
if (dbEntry?.sourceCandidates?.length > 0) {
|
|
3298
|
+
// Use the traced source instead of the callback scope
|
|
3299
|
+
hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
addEquivalency(path, hookCallPath);
|
|
2683
3303
|
}
|
|
2684
3304
|
}
|
|
2685
3305
|
// Case 3: Destructured variables from local variables
|
|
@@ -2691,10 +3311,15 @@ export class ScopeDataStructure {
|
|
|
2691
3311
|
!equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
|
|
2692
3312
|
!equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
|
|
2693
3313
|
) {
|
|
2694
|
-
//
|
|
2695
|
-
|
|
2696
|
-
|
|
3314
|
+
// Skip bare "returnValue" from child scopes — this is the child's return value,
|
|
3315
|
+
// not a meaningful data source path in the parent scope
|
|
3316
|
+
if (equivalentValue.schemaPath === 'returnValue' &&
|
|
3317
|
+
equivalentValue.scopeNodeName !==
|
|
3318
|
+
this.scopeTreeManager.getRootName()) {
|
|
3319
|
+
continue;
|
|
2697
3320
|
}
|
|
3321
|
+
// Add equivalency (will accumulate if multiple values for OR expressions)
|
|
3322
|
+
addEquivalency(path, equivalentValue.schemaPath);
|
|
2698
3323
|
}
|
|
2699
3324
|
// Case 4: Child component prop mappings (Fix 22)
|
|
2700
3325
|
// When parent renders <ChildComponent prop={value} />, we get equivalencies like:
|
|
@@ -2705,7 +3330,7 @@ export class ScopeDataStructure {
|
|
|
2705
3330
|
if (path.includes('().signature[') &&
|
|
2706
3331
|
!equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
|
|
2707
3332
|
) {
|
|
2708
|
-
|
|
3333
|
+
addEquivalency(path, equivalentValue.schemaPath);
|
|
2709
3334
|
}
|
|
2710
3335
|
// Case 5: Destructured function parameters (Fix 25)
|
|
2711
3336
|
// When a function has destructured props: function Comp({ propA, propB }: Props)
|
|
@@ -2718,7 +3343,7 @@ export class ScopeDataStructure {
|
|
|
2718
3343
|
if (!path.includes('.') && // path is a simple identifier (destructured prop name)
|
|
2719
3344
|
equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
|
|
2720
3345
|
) {
|
|
2721
|
-
|
|
3346
|
+
addEquivalency(path, equivalentValue.schemaPath);
|
|
2722
3347
|
}
|
|
2723
3348
|
// Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
|
|
2724
3349
|
// When we have patterns like:
|
|
@@ -2730,8 +3355,7 @@ export class ScopeDataStructure {
|
|
|
2730
3355
|
// segments -> useParams().functionCallReturnValue['*'].split('/').functionCallReturnValue
|
|
2731
3356
|
if (!path.includes('.') && // path is a simple identifier
|
|
2732
3357
|
equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
|
|
2733
|
-
equivalentValue.schemaPath.includes('.')
|
|
2734
|
-
!(path in equivalentSignatureVariables) // not already captured
|
|
3358
|
+
equivalentValue.schemaPath.includes('.') // has property access (method call)
|
|
2735
3359
|
) {
|
|
2736
3360
|
// Check if this looks like a method call on a variable (not a hook call)
|
|
2737
3361
|
// Hook calls look like: hookName() or hookName<T>()
|
|
@@ -2742,7 +3366,7 @@ export class ScopeDataStructure {
|
|
|
2742
3366
|
const parenPos = hookCallPath.indexOf('(');
|
|
2743
3367
|
if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
|
|
2744
3368
|
// This is a method call like "splat.split('/')", not a hook call
|
|
2745
|
-
|
|
3369
|
+
addEquivalency(path, equivalentValue.schemaPath);
|
|
2746
3370
|
}
|
|
2747
3371
|
}
|
|
2748
3372
|
}
|
|
@@ -2769,8 +3393,9 @@ export class ScopeDataStructure {
|
|
|
2769
3393
|
!equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
|
|
2770
3394
|
) {
|
|
2771
3395
|
// Only add if not already present from the root scope
|
|
3396
|
+
// Root scope values take precedence over child scope values
|
|
2772
3397
|
if (!(path in equivalentSignatureVariables)) {
|
|
2773
|
-
|
|
3398
|
+
addEquivalency(path, equivalentValue.schemaPath);
|
|
2774
3399
|
}
|
|
2775
3400
|
}
|
|
2776
3401
|
}
|
|
@@ -2780,9 +3405,72 @@ export class ScopeDataStructure {
|
|
|
2780
3405
|
// E.g., analysis → currentEntityAnalysis → useLoaderData().functionCallReturnValue.currentEntityAnalysis
|
|
2781
3406
|
// We need multiple passes because resolutions can depend on each other
|
|
2782
3407
|
const maxIterations = 5; // Prevent infinite loops
|
|
3408
|
+
// Helper function to resolve a single source path using equivalencies
|
|
3409
|
+
const resolveSourcePath = (sourcePath, equivMap) => {
|
|
3410
|
+
// Extract base variable from the path
|
|
3411
|
+
const dotIndex = sourcePath.indexOf('.');
|
|
3412
|
+
const bracketIndex = sourcePath.indexOf('[');
|
|
3413
|
+
let baseVar;
|
|
3414
|
+
let rest;
|
|
3415
|
+
if (dotIndex === -1 && bracketIndex === -1) {
|
|
3416
|
+
baseVar = sourcePath;
|
|
3417
|
+
rest = '';
|
|
3418
|
+
}
|
|
3419
|
+
else if (dotIndex === -1) {
|
|
3420
|
+
baseVar = sourcePath.slice(0, bracketIndex);
|
|
3421
|
+
rest = sourcePath.slice(bracketIndex);
|
|
3422
|
+
}
|
|
3423
|
+
else if (bracketIndex === -1) {
|
|
3424
|
+
baseVar = sourcePath.slice(0, dotIndex);
|
|
3425
|
+
rest = sourcePath.slice(dotIndex);
|
|
3426
|
+
}
|
|
3427
|
+
else {
|
|
3428
|
+
const firstIndex = Math.min(dotIndex, bracketIndex);
|
|
3429
|
+
baseVar = sourcePath.slice(0, firstIndex);
|
|
3430
|
+
rest = sourcePath.slice(firstIndex);
|
|
3431
|
+
}
|
|
3432
|
+
// Look up the base variable in equivalencies
|
|
3433
|
+
if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
|
|
3434
|
+
const baseResolved = equivMap[baseVar];
|
|
3435
|
+
// Skip if baseResolved is an array (handle later)
|
|
3436
|
+
if (Array.isArray(baseResolved))
|
|
3437
|
+
return null;
|
|
3438
|
+
// If it resolves to a signature path, build the full resolved path
|
|
3439
|
+
if (baseResolved.startsWith('signature[') ||
|
|
3440
|
+
baseResolved.includes('()')) {
|
|
3441
|
+
if (baseResolved.endsWith('()')) {
|
|
3442
|
+
return baseResolved + '.functionCallReturnValue' + rest;
|
|
3443
|
+
}
|
|
3444
|
+
return baseResolved + rest;
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
return null;
|
|
3448
|
+
};
|
|
2783
3449
|
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
2784
3450
|
let changed = false;
|
|
2785
|
-
for (const [varName,
|
|
3451
|
+
for (const [varName, sourcePathOrArray] of Object.entries(equivalentSignatureVariables)) {
|
|
3452
|
+
// Handle arrays (OR expressions) by resolving each element
|
|
3453
|
+
if (Array.isArray(sourcePathOrArray)) {
|
|
3454
|
+
const resolvedArray = [];
|
|
3455
|
+
let arrayChanged = false;
|
|
3456
|
+
for (const sourcePath of sourcePathOrArray) {
|
|
3457
|
+
// Try to resolve this path using transitive resolution
|
|
3458
|
+
const resolved = resolveSourcePath(sourcePath, equivalentSignatureVariables);
|
|
3459
|
+
if (resolved && resolved !== sourcePath) {
|
|
3460
|
+
resolvedArray.push(resolved);
|
|
3461
|
+
arrayChanged = true;
|
|
3462
|
+
}
|
|
3463
|
+
else {
|
|
3464
|
+
resolvedArray.push(sourcePath);
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
if (arrayChanged) {
|
|
3468
|
+
equivalentSignatureVariables[varName] = resolvedArray;
|
|
3469
|
+
changed = true;
|
|
3470
|
+
}
|
|
3471
|
+
continue;
|
|
3472
|
+
}
|
|
3473
|
+
const sourcePath = sourcePathOrArray;
|
|
2786
3474
|
// Skip if already fully resolved (contains function call syntax)
|
|
2787
3475
|
// BUT first check for computed value patterns that need resolution (Fix 28)
|
|
2788
3476
|
// AND method call patterns that need base variable resolution (Fix 33)
|
|
@@ -2835,6 +3523,9 @@ export class ScopeDataStructure {
|
|
|
2835
3523
|
if (baseVar in equivalentSignatureVariables &&
|
|
2836
3524
|
baseVar !== varName) {
|
|
2837
3525
|
const baseResolved = equivalentSignatureVariables[baseVar];
|
|
3526
|
+
// Skip if baseResolved is an array (OR expression)
|
|
3527
|
+
if (Array.isArray(baseResolved))
|
|
3528
|
+
continue;
|
|
2838
3529
|
// Only resolve if the base resolved to something useful (contains () or .)
|
|
2839
3530
|
if (baseResolved.includes('()') || baseResolved.includes('.')) {
|
|
2840
3531
|
const newPath = baseResolved + rest;
|
|
@@ -2845,6 +3536,34 @@ export class ScopeDataStructure {
|
|
|
2845
3536
|
}
|
|
2846
3537
|
}
|
|
2847
3538
|
}
|
|
3539
|
+
// Fix 38: Handle cyScope lazy initializer return values
|
|
3540
|
+
// When we have viewMode -> cyScope20(), trace through to find what cyScope20 returns.
|
|
3541
|
+
// The lazy initializer's return value should be the controllable data source.
|
|
3542
|
+
// Pattern: cyScopeN() where N is a number
|
|
3543
|
+
const cyScopeMatch = sourcePath.match(/^(cyScope\d+)\(\)$/);
|
|
3544
|
+
if (cyScopeMatch) {
|
|
3545
|
+
const cyScopeName = cyScopeMatch[1];
|
|
3546
|
+
const cyScopeNode = this.scopeNodes[cyScopeName];
|
|
3547
|
+
if (cyScopeNode?.equivalencies) {
|
|
3548
|
+
// Look for returnValue equivalency in the cyScope
|
|
3549
|
+
const returnValueEquivs = cyScopeNode.equivalencies['returnValue'];
|
|
3550
|
+
if (returnValueEquivs && returnValueEquivs.length > 0) {
|
|
3551
|
+
// Get the first return value source
|
|
3552
|
+
const returnSource = returnValueEquivs[0].schemaPath;
|
|
3553
|
+
// If the return source is a simple variable (not a complex path),
|
|
3554
|
+
// resolve varName directly to that variable
|
|
3555
|
+
if (returnSource &&
|
|
3556
|
+
!returnSource.includes('(') &&
|
|
3557
|
+
!returnSource.includes('[')) {
|
|
3558
|
+
// Update varName to point to the return source
|
|
3559
|
+
if (equivalentSignatureVariables[varName] !== returnSource) {
|
|
3560
|
+
equivalentSignatureVariables[varName] = returnSource;
|
|
3561
|
+
changed = true;
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
2848
3567
|
continue;
|
|
2849
3568
|
}
|
|
2850
3569
|
// Check if the source path starts with a variable that's also in the map
|
|
@@ -2862,7 +3581,13 @@ export class ScopeDataStructure {
|
|
|
2862
3581
|
rest = '';
|
|
2863
3582
|
}
|
|
2864
3583
|
if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
|
|
2865
|
-
|
|
3584
|
+
// Handle array case (OR expressions) - use first element
|
|
3585
|
+
const rawBaseResolved = equivalentSignatureVariables[baseVar];
|
|
3586
|
+
const baseResolved = Array.isArray(rawBaseResolved)
|
|
3587
|
+
? rawBaseResolved[0]
|
|
3588
|
+
: rawBaseResolved;
|
|
3589
|
+
if (!baseResolved)
|
|
3590
|
+
continue;
|
|
2866
3591
|
// If the base resolves to a hook call, add .functionCallReturnValue
|
|
2867
3592
|
if (baseResolved.endsWith('()')) {
|
|
2868
3593
|
const newPath = baseResolved + '.functionCallReturnValue' + rest;
|
|
@@ -2931,7 +3656,95 @@ export class ScopeDataStructure {
|
|
|
2931
3656
|
// Replace cyScope placeholders in all external function call data
|
|
2932
3657
|
// This ensures call signatures and schema paths use actual callback text
|
|
2933
3658
|
// instead of internal cyScope names, preventing mock data merge conflicts.
|
|
2934
|
-
|
|
3659
|
+
const rootScopeName = this.scopeTreeManager.getRootName();
|
|
3660
|
+
const rootSchema = this.scopeNodes[rootScopeName]?.schema ?? {};
|
|
3661
|
+
return this.externalFunctionCalls.map((efc) => {
|
|
3662
|
+
const cleaned = this.cleanCyScopeFromFunctionCallInfo(efc);
|
|
3663
|
+
return this.filterConflatedExternalPaths(cleaned, rootSchema);
|
|
3664
|
+
});
|
|
3665
|
+
}
|
|
3666
|
+
/**
|
|
3667
|
+
* Filters out conflated paths from external function call schemas.
|
|
3668
|
+
*
|
|
3669
|
+
* When multiple useState(false) calls create equivalency conflation during
|
|
3670
|
+
* Phase 1 analysis, standalone boolean state variables (like showWorkoutForm,
|
|
3671
|
+
* showGoalForm) can bleed into external function call schemas as sub-properties
|
|
3672
|
+
* of unrelated data fields (like data[].activity_type.showWorkoutForm).
|
|
3673
|
+
*
|
|
3674
|
+
* Detection: group sub-properties by parent path. If 2+ sub-properties of
|
|
3675
|
+
* the same parent all match standalone root scope variable names, treat them
|
|
3676
|
+
* as conflation artifacts and remove them.
|
|
3677
|
+
*/
|
|
3678
|
+
filterConflatedExternalPaths(efc, rootSchema) {
|
|
3679
|
+
// Build a set of top-level root scope variable names (simple names, no dots/brackets)
|
|
3680
|
+
const topLevelRootVars = new Set();
|
|
3681
|
+
for (const key of Object.keys(rootSchema)) {
|
|
3682
|
+
if (!key.includes('.') && !key.includes('[')) {
|
|
3683
|
+
topLevelRootVars.add(key);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
if (topLevelRootVars.size === 0)
|
|
3687
|
+
return efc;
|
|
3688
|
+
// Group sub-property matches by their parent path.
|
|
3689
|
+
// For a path like "...data[].activity_type.showWorkoutForm",
|
|
3690
|
+
// parent = "...data[].activity_type", child = "showWorkoutForm"
|
|
3691
|
+
const parentToConflatedKeys = new Map();
|
|
3692
|
+
for (const key of Object.keys(efc.schema)) {
|
|
3693
|
+
const lastDot = key.lastIndexOf('.');
|
|
3694
|
+
if (lastDot === -1)
|
|
3695
|
+
continue;
|
|
3696
|
+
const parent = key.substring(0, lastDot);
|
|
3697
|
+
const child = key.substring(lastDot + 1);
|
|
3698
|
+
// Skip array access or function call patterns
|
|
3699
|
+
if (child.includes('[') || child.includes('('))
|
|
3700
|
+
continue;
|
|
3701
|
+
// Only consider paths inside array element chains (contains []).
|
|
3702
|
+
// Direct children of functionCallReturnValue are legitimate destructured
|
|
3703
|
+
// return values, not conflation. Conflation happens deeper in the chain
|
|
3704
|
+
// when array element fields get corrupted sub-properties.
|
|
3705
|
+
if (!parent.includes('['))
|
|
3706
|
+
continue;
|
|
3707
|
+
if (topLevelRootVars.has(child)) {
|
|
3708
|
+
if (!parentToConflatedKeys.has(parent)) {
|
|
3709
|
+
parentToConflatedKeys.set(parent, []);
|
|
3710
|
+
}
|
|
3711
|
+
parentToConflatedKeys.get(parent).push(key);
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
// Only filter when 2+ sub-properties of the same parent match root scope vars.
|
|
3715
|
+
// This threshold avoids false positives from coincidental name matches.
|
|
3716
|
+
const keysToRemove = new Set();
|
|
3717
|
+
const parentsToRestore = new Set();
|
|
3718
|
+
for (const [parent, conflatedKeys] of parentToConflatedKeys) {
|
|
3719
|
+
if (conflatedKeys.length >= 2) {
|
|
3720
|
+
for (const key of conflatedKeys) {
|
|
3721
|
+
keysToRemove.add(key);
|
|
3722
|
+
}
|
|
3723
|
+
parentsToRestore.add(parent);
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
if (keysToRemove.size === 0)
|
|
3727
|
+
return efc;
|
|
3728
|
+
// Create a new schema without the conflated paths
|
|
3729
|
+
const newSchema = {};
|
|
3730
|
+
for (const [key, value] of Object.entries(efc.schema)) {
|
|
3731
|
+
if (keysToRemove.has(key))
|
|
3732
|
+
continue;
|
|
3733
|
+
// Restore parent type: if it was changed to "object" because of conflated
|
|
3734
|
+
// sub-properties, and now all those sub-properties are removed, change it
|
|
3735
|
+
// back to "unknown" (we don't know the original type)
|
|
3736
|
+
if (parentsToRestore.has(key) && value === 'object') {
|
|
3737
|
+
// Check if there are any remaining sub-properties
|
|
3738
|
+
const hasRemainingSubProps = Object.keys(efc.schema).some((k) => !keysToRemove.has(k) &&
|
|
3739
|
+
k !== key &&
|
|
3740
|
+
(k.startsWith(key + '.') || k.startsWith(key + '[')));
|
|
3741
|
+
newSchema[key] = hasRemainingSubProps ? value : 'unknown';
|
|
3742
|
+
}
|
|
3743
|
+
else {
|
|
3744
|
+
newSchema[key] = value;
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
return { ...efc, schema: newSchema };
|
|
2935
3748
|
}
|
|
2936
3749
|
/**
|
|
2937
3750
|
* Cleans cyScope placeholder references from a FunctionCallInfo.
|
|
@@ -3152,6 +3965,7 @@ export class ScopeDataStructure {
|
|
|
3152
3965
|
*/
|
|
3153
3966
|
getEnrichedConditionalUsages() {
|
|
3154
3967
|
const enriched = {};
|
|
3968
|
+
console.log(`[getEnrichedConditionalUsages] Processing ${Object.keys(this.rawConditionalUsages).length} conditional paths: [${Object.keys(this.rawConditionalUsages).join(', ')}]`);
|
|
3155
3969
|
for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
|
|
3156
3970
|
// Try to trace this path back to a data source
|
|
3157
3971
|
// First, try the root scope
|
|
@@ -3159,9 +3973,47 @@ export class ScopeDataStructure {
|
|
|
3159
3973
|
const explanation = this.explainPath(rootScopeName, path);
|
|
3160
3974
|
let sourceDataPath;
|
|
3161
3975
|
if (explanation.source) {
|
|
3162
|
-
|
|
3163
|
-
|
|
3976
|
+
const { scope, path: sourcePath } = explanation.source;
|
|
3977
|
+
// Build initial path — avoid redundant prefix when path already contains the scope call
|
|
3978
|
+
let fullPath;
|
|
3979
|
+
if (sourcePath.startsWith(`${scope}(`)) {
|
|
3980
|
+
fullPath = sourcePath;
|
|
3981
|
+
}
|
|
3982
|
+
else {
|
|
3983
|
+
fullPath = `${scope}.${sourcePath}`;
|
|
3984
|
+
}
|
|
3985
|
+
sourceDataPath = fullPath;
|
|
3986
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" explainPath → scope="${scope}", sourcePath="${sourcePath}" → sourceDataPath="${sourceDataPath}"`);
|
|
3987
|
+
}
|
|
3988
|
+
else {
|
|
3989
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" explainPath → no source found`);
|
|
3990
|
+
}
|
|
3991
|
+
// If explainPath didn't find a useful external source (e.g., it traced to
|
|
3992
|
+
// useState or just to the component scope itself), check sourceEquivalencies
|
|
3993
|
+
// for an external function call source like a fetch call
|
|
3994
|
+
const hasExternalSource = sourceDataPath?.includes('.functionCallReturnValue');
|
|
3995
|
+
if (!hasExternalSource) {
|
|
3996
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" no external source (sourceDataPath="${sourceDataPath}"), checking sourceEquivalencies fallback...`);
|
|
3997
|
+
const sourceEquiv = this.getSourceEquivalencies();
|
|
3998
|
+
const returnValueKey = `returnValue.${path}`;
|
|
3999
|
+
const sources = sourceEquiv[returnValueKey];
|
|
4000
|
+
if (sources) {
|
|
4001
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] has ${sources.length} sources: [${sources.map((s) => s.schemaPath).join(', ')}]`);
|
|
4002
|
+
const externalSource = sources.find((s) => s.schemaPath.includes('.functionCallReturnValue') &&
|
|
4003
|
+
!s.schemaPath.startsWith('useState('));
|
|
4004
|
+
if (externalSource) {
|
|
4005
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found external source: "${externalSource.schemaPath}"`);
|
|
4006
|
+
sourceDataPath = externalSource.schemaPath;
|
|
4007
|
+
}
|
|
4008
|
+
else {
|
|
4009
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found no external function call source`);
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
else {
|
|
4013
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] not found`);
|
|
4014
|
+
}
|
|
3164
4015
|
}
|
|
4016
|
+
console.log(`[getEnrichedConditionalUsages] "${path}" FINAL sourceDataPath="${sourceDataPath ?? '(none)'}" (${usages.length} usages)`);
|
|
3165
4017
|
enriched[path] = usages.map((usage) => ({
|
|
3166
4018
|
...usage,
|
|
3167
4019
|
sourceDataPath,
|
|
@@ -3169,6 +4021,26 @@ export class ScopeDataStructure {
|
|
|
3169
4021
|
}
|
|
3170
4022
|
return enriched;
|
|
3171
4023
|
}
|
|
4024
|
+
/**
|
|
4025
|
+
* Add JSX rendering usages from AST analysis.
|
|
4026
|
+
* These track arrays rendered via .map() and strings interpolated in JSX.
|
|
4027
|
+
*/
|
|
4028
|
+
addJsxRenderingUsages(usages) {
|
|
4029
|
+
// Add usages, avoiding duplicates based on path and renderingType
|
|
4030
|
+
for (const usage of usages) {
|
|
4031
|
+
const exists = this.rawJsxRenderingUsages.some((existing) => existing.path === usage.path &&
|
|
4032
|
+
existing.renderingType === usage.renderingType);
|
|
4033
|
+
if (!exists) {
|
|
4034
|
+
this.rawJsxRenderingUsages.push(usage);
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
/**
|
|
4039
|
+
* Get JSX rendering usages collected during analysis.
|
|
4040
|
+
*/
|
|
4041
|
+
getJsxRenderingUsages() {
|
|
4042
|
+
return this.rawJsxRenderingUsages;
|
|
4043
|
+
}
|
|
3172
4044
|
toSerializable() {
|
|
3173
4045
|
// Helper to clean cyScope and cyDuplicateKey from a string for output
|
|
3174
4046
|
const cleanCyScope = (str) => this.replaceCyScopeInString(str).replace(/::cyDuplicateKey\d+::/g, '');
|
|
@@ -3400,11 +4272,21 @@ export class ScopeDataStructure {
|
|
|
3400
4272
|
perVariableSchemas = undefined;
|
|
3401
4273
|
}
|
|
3402
4274
|
}
|
|
4275
|
+
// Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
|
|
4276
|
+
// This ensures the serialized schema has the same type inference as getReturnValue().
|
|
4277
|
+
// Without this, evidence like "entities[].analyses: array" becomes "unknown".
|
|
4278
|
+
const enrichedSchema = { ...efc.schema };
|
|
4279
|
+
const tempScopeNode = {
|
|
4280
|
+
name: efc.name,
|
|
4281
|
+
schema: enrichedSchema,
|
|
4282
|
+
equivalencies: efc.equivalencies ?? {},
|
|
4283
|
+
};
|
|
4284
|
+
fillInSchemaGapsAndUnknowns(tempScopeNode, true);
|
|
3403
4285
|
return {
|
|
3404
4286
|
name: efc.name,
|
|
3405
4287
|
callSignature: efc.callSignature,
|
|
3406
4288
|
callScope: efc.callScope,
|
|
3407
|
-
schema:
|
|
4289
|
+
schema: enrichedSchema,
|
|
3408
4290
|
equivalencies: efc.equivalencies
|
|
3409
4291
|
? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
|
|
3410
4292
|
// Clean cyScope from the key as well as variable properties
|
|
@@ -3553,6 +4435,10 @@ export class ScopeDataStructure {
|
|
|
3553
4435
|
const childBoundaryGatingConditions = Object.keys(enrichedGatingConditions).length > 0
|
|
3554
4436
|
? enrichedGatingConditions
|
|
3555
4437
|
: undefined;
|
|
4438
|
+
// Get JSX rendering usages (arrays via .map(), strings via interpolation)
|
|
4439
|
+
const jsxRenderingUsages = this.rawJsxRenderingUsages.length > 0
|
|
4440
|
+
? this.rawJsxRenderingUsages
|
|
4441
|
+
: undefined;
|
|
3556
4442
|
return {
|
|
3557
4443
|
externalFunctionCalls: deduplicatedExternalFunctionCalls,
|
|
3558
4444
|
rootFunction,
|
|
@@ -3563,6 +4449,7 @@ export class ScopeDataStructure {
|
|
|
3563
4449
|
conditionalEffects,
|
|
3564
4450
|
compoundConditionals,
|
|
3565
4451
|
childBoundaryGatingConditions,
|
|
4452
|
+
jsxRenderingUsages,
|
|
3566
4453
|
};
|
|
3567
4454
|
}
|
|
3568
4455
|
// ═══════════════════════════════════════════════════════════════════════════
|