@codeyam/codeyam-cli 0.1.0-staging.323686 → 0.1.0-staging.483fdc2
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 +7 -7
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +2 -2
- package/analyzer-template/packages/ai/index.ts +6 -1
- package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +39 -17
- package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
- package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +308 -50
- package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +15 -6
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +664 -242
- 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 +20 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +35 -13
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +160 -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 +289 -83
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +269 -1
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +11 -3
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +297 -7
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
- package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
- package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
- package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
- package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
- 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/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 +20 -6
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +14 -4
- package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
- package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
- 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/enrichArrayTypesFromChildSignatures.ts +57 -13
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +29 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +35 -4
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +199 -17
- 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/utils/getFileByPath.ts +19 -0
- package/analyzer-template/packages/aws/package.json +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
- 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/package.json +1 -1
- package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
- package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
- package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
- 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/project/constructMockCode.ts +54 -9
- package/analyzer-template/project/writeMockDataTsx.ts +73 -2
- package/background/src/lib/virtualized/project/constructMockCode.js +45 -3
- package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
- package/background/src/lib/virtualized/project/writeMockDataTsx.js +71 -2
- package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
- package/codeyam-cli/scripts/apply-setup.js +146 -0
- package/codeyam-cli/scripts/apply-setup.js.map +1 -1
- package/codeyam-cli/src/commands/debug.js +7 -5
- package/codeyam-cli/src/commands/debug.js.map +1 -1
- package/codeyam-cli/src/utils/install-skills.js +22 -0
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/reviewedRules.js +92 -0
- package/codeyam-cli/src/utils/reviewedRules.js.map +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-CX9f-5xM.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{manifest-7522edd4.js → manifest-bba56ec1.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/memory-DuTFSyJ2.js +92 -0
- package/codeyam-cli/src/webserver/build/client/assets/{root-eVAaavTS.js → root-DTfSQARG.js} +6 -6
- package/codeyam-cli/src/webserver/build/server/assets/{index-DVzYx8PN.js → index-TD1f-DHV.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-BQ-1XyEa.js +258 -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:memory.md +174 -233
- package/codeyam-cli/templates/codeyam:new-rule.md +41 -2
- package/codeyam-cli/templates/rule-reflection-hook.py +161 -0
- package/codeyam-cli/templates/rules-instructions.md +126 -0
- package/package.json +1 -1
- package/packages/ai/index.js +2 -1
- package/packages/ai/index.js.map +1 -1
- package/packages/ai/src/lib/analyzeScope.js +29 -12
- package/packages/ai/src/lib/analyzeScope.js.map +1 -1
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
- package/packages/ai/src/lib/astScopes/processExpression.js +239 -43
- package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +503 -165
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.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 +22 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +34 -9
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +159 -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 +237 -73
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarioData.js +195 -1
- package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
- package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlows.js +10 -2
- package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +209 -3
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.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/gatherAttributesMap.js +10 -4
- package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
- package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
- package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
- package/packages/ai/src/lib/worker/SerializableDataStructure.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/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 +13 -5
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +14 -4
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.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 +0 -3
- 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/enrichArrayTypesFromChildSignatures.js +52 -10
- package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +25 -8
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +34 -4
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +168 -9
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.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/utils/getFileByPath.js +12 -0
- package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/memory-yxFcrxBX.js +0 -92
- package/codeyam-cli/src/webserver/build/server/assets/server-build-4Cr0uToj.js +0 -257
package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts
CHANGED
|
@@ -65,6 +65,10 @@ export default async function generateExecutionFlows({
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
if (!analysis.metadata.executionFlows) {
|
|
68
|
+
console.log(
|
|
69
|
+
`[GenerateExecutionFlows] Starting for ${entity.name} (${entity.filePath})`,
|
|
70
|
+
);
|
|
71
|
+
|
|
68
72
|
// Build childEntityMetadata from dependentAnalyses for child flow merging
|
|
69
73
|
// This maps child component names to their metadata (specifically isolatedDataStructure)
|
|
70
74
|
const childEntityMetadata = buildChildEntityMetadata(
|
|
@@ -72,6 +76,16 @@ export default async function generateExecutionFlows({
|
|
|
72
76
|
dependentAnalyses,
|
|
73
77
|
);
|
|
74
78
|
|
|
79
|
+
const childCount = Object.keys(childEntityMetadata).length;
|
|
80
|
+
console.log(
|
|
81
|
+
`[GenerateExecutionFlows] Built childEntityMetadata with ${childCount} children`,
|
|
82
|
+
);
|
|
83
|
+
if (childCount > 0) {
|
|
84
|
+
console.log(
|
|
85
|
+
`[GenerateExecutionFlows] Will merge flows from children: [${Object.keys(childEntityMetadata).join(', ')}]`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
const {
|
|
76
90
|
result: { executionFlows, llmCall: executionFlowsLLMCall },
|
|
77
91
|
} = await measureAndReportExecutionTime(
|
|
@@ -80,15 +94,24 @@ export default async function generateExecutionFlows({
|
|
|
80
94
|
entity,
|
|
81
95
|
mergedDataStructure: analysis.metadata.mergedDataStructure,
|
|
82
96
|
model,
|
|
83
|
-
childEntityMetadata:
|
|
84
|
-
Object.keys(childEntityMetadata).length > 0
|
|
85
|
-
? childEntityMetadata
|
|
86
|
-
: undefined,
|
|
97
|
+
childEntityMetadata: childCount > 0 ? childEntityMetadata : undefined,
|
|
87
98
|
}),
|
|
88
99
|
`Generating execution flows`,
|
|
89
100
|
updateProgress,
|
|
90
101
|
);
|
|
91
102
|
|
|
103
|
+
console.log(
|
|
104
|
+
`[GenerateExecutionFlows] Generated ${executionFlows.length} execution flows for ${entity.name}`,
|
|
105
|
+
);
|
|
106
|
+
for (const flow of executionFlows) {
|
|
107
|
+
const reqValues = flow.requiredValues
|
|
108
|
+
.map((rv) => `${rv.attributePath}=${rv.value}`)
|
|
109
|
+
.join(', ');
|
|
110
|
+
console.log(
|
|
111
|
+
`[GenerateExecutionFlows] - Flow '${flow.id}': ${flow.name} [${reqValues}]`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
92
115
|
analysis.metadata.executionFlows = executionFlows;
|
|
93
116
|
|
|
94
117
|
if (executionFlowsLLMCall) {
|
|
@@ -114,7 +137,14 @@ export function buildChildEntityMetadata(
|
|
|
114
137
|
): Record<string, Entity['metadata']> {
|
|
115
138
|
const childEntityMetadata: Record<string, Entity['metadata']> = {};
|
|
116
139
|
|
|
140
|
+
console.log(
|
|
141
|
+
`[BuildChildMetadata] Starting for entity: ${entity.name} (${entity.filePath})`,
|
|
142
|
+
);
|
|
143
|
+
|
|
117
144
|
if (!dependentAnalyses) {
|
|
145
|
+
console.log(
|
|
146
|
+
`[BuildChildMetadata] No dependentAnalyses provided, returning empty`,
|
|
147
|
+
);
|
|
118
148
|
return childEntityMetadata;
|
|
119
149
|
}
|
|
120
150
|
|
|
@@ -122,18 +152,54 @@ export function buildChildEntityMetadata(
|
|
|
122
152
|
entity.metadata?.isolatedDataStructure?.childBoundaryGatingConditions;
|
|
123
153
|
|
|
124
154
|
if (!childBoundaryGatingConditions) {
|
|
155
|
+
console.log(
|
|
156
|
+
`[BuildChildMetadata] No childBoundaryGatingConditions found in isolatedDataStructure`,
|
|
157
|
+
);
|
|
158
|
+
console.log(
|
|
159
|
+
`[BuildChildMetadata] isolatedDataStructure keys: ${Object.keys(entity.metadata?.isolatedDataStructure ?? {}).join(', ') || 'none'}`,
|
|
160
|
+
);
|
|
125
161
|
return childEntityMetadata;
|
|
126
162
|
}
|
|
127
163
|
|
|
164
|
+
const childNames = Object.keys(childBoundaryGatingConditions);
|
|
165
|
+
console.log(
|
|
166
|
+
`[BuildChildMetadata] Found ${childNames.length} children in childBoundaryGatingConditions: [${childNames.join(', ')}]`,
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// Log gating conditions for each child
|
|
170
|
+
for (const [childName, conditions] of Object.entries(
|
|
171
|
+
childBoundaryGatingConditions,
|
|
172
|
+
)) {
|
|
173
|
+
const isUnconditional = conditions.some(
|
|
174
|
+
(c) => c.location === 'unconditional',
|
|
175
|
+
);
|
|
176
|
+
console.log(
|
|
177
|
+
`[BuildChildMetadata] Child '${childName}': ${conditions.length} gating conditions, unconditional=${isUnconditional}`,
|
|
178
|
+
);
|
|
179
|
+
for (const condition of conditions) {
|
|
180
|
+
console.log(
|
|
181
|
+
`[BuildChildMetadata] - path='${condition.path}' location='${condition.location}' isNegated=${condition.isNegated ?? false}`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
128
186
|
const importedExports = entity.metadata?.importedExports ?? [];
|
|
187
|
+
console.log(
|
|
188
|
+
`[BuildChildMetadata] Entity has ${importedExports.length} importedExports`,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
for (const childName of childNames) {
|
|
192
|
+
console.log(`[BuildChildMetadata] Looking up child '${childName}'...`);
|
|
129
193
|
|
|
130
|
-
for (const childName of Object.keys(childBoundaryGatingConditions)) {
|
|
131
194
|
// Find the child in importedExports to get its file path
|
|
132
195
|
const importedExport = importedExports.find(
|
|
133
196
|
(ie) => ie.name === childName || ie.resolvedName === childName,
|
|
134
197
|
);
|
|
135
198
|
|
|
136
199
|
if (!importedExport) {
|
|
200
|
+
console.log(
|
|
201
|
+
`[BuildChildMetadata] Child '${childName}' NOT FOUND in importedExports`,
|
|
202
|
+
);
|
|
137
203
|
continue;
|
|
138
204
|
}
|
|
139
205
|
|
|
@@ -142,15 +208,57 @@ export function buildChildEntityMetadata(
|
|
|
142
208
|
importedExport.resolvedFilePath ?? importedExport.filePath;
|
|
143
209
|
const lookupName = importedExport.resolvedName ?? importedExport.name;
|
|
144
210
|
|
|
211
|
+
console.log(
|
|
212
|
+
`[BuildChildMetadata] Child '${childName}' found in importedExports: lookupPath='${lookupPath}' lookupName='${lookupName}'`,
|
|
213
|
+
);
|
|
214
|
+
|
|
145
215
|
// Look up the child's analysis in dependentAnalyses
|
|
146
216
|
const childAnalysis = dependentAnalyses[lookupPath]?.[lookupName];
|
|
147
217
|
|
|
148
|
-
if (childAnalysis
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
218
|
+
if (!childAnalysis) {
|
|
219
|
+
console.log(
|
|
220
|
+
`[BuildChildMetadata] Child '${childName}' analysis NOT FOUND in dependentAnalyses[${lookupPath}][${lookupName}]`,
|
|
221
|
+
);
|
|
222
|
+
console.log(
|
|
223
|
+
`[BuildChildMetadata] Available paths in dependentAnalyses: [${Object.keys(dependentAnalyses).slice(0, 10).join(', ')}...]`,
|
|
224
|
+
);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!childAnalysis.entity?.metadata) {
|
|
229
|
+
console.log(
|
|
230
|
+
`[BuildChildMetadata] Child '${childName}' analysis found but entity.metadata is missing`,
|
|
231
|
+
);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Log what we found in the child's metadata
|
|
236
|
+
const childIsolated = childAnalysis.entity.metadata.isolatedDataStructure;
|
|
237
|
+
const childConditionalUsages = childIsolated?.conditionalUsages ?? {};
|
|
238
|
+
const childConditionalCount = Object.keys(childConditionalUsages).length;
|
|
239
|
+
|
|
240
|
+
console.log(
|
|
241
|
+
`[BuildChildMetadata] Child '${childName}' FOUND with metadata:`,
|
|
242
|
+
);
|
|
243
|
+
console.log(
|
|
244
|
+
`[BuildChildMetadata] - conditionalUsages: ${childConditionalCount} paths`,
|
|
245
|
+
);
|
|
246
|
+
if (childConditionalCount > 0) {
|
|
247
|
+
for (const [path, usages] of Object.entries(childConditionalUsages)) {
|
|
248
|
+
console.log(
|
|
249
|
+
`[BuildChildMetadata] - '${path}': ${(usages as any[]).length} usages`,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
152
252
|
}
|
|
253
|
+
|
|
254
|
+
// Cast to mutable type - the metadata is only read, not modified
|
|
255
|
+
childEntityMetadata[childName] = childAnalysis.entity
|
|
256
|
+
.metadata as Entity['metadata'];
|
|
153
257
|
}
|
|
154
258
|
|
|
259
|
+
console.log(
|
|
260
|
+
`[BuildChildMetadata] RESULT: Found metadata for ${Object.keys(childEntityMetadata).length} children: [${Object.keys(childEntityMetadata).join(', ')}]`,
|
|
261
|
+
);
|
|
262
|
+
|
|
155
263
|
return childEntityMetadata;
|
|
156
264
|
}
|
package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts
CHANGED
|
@@ -40,6 +40,52 @@ function getTypeParameter(functionName: string): string | null {
|
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// Primitive types that should not have child paths
|
|
44
|
+
const PRIMITIVE_TYPES = new Set([
|
|
45
|
+
'number',
|
|
46
|
+
'string',
|
|
47
|
+
'boolean',
|
|
48
|
+
'null',
|
|
49
|
+
'undefined',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
// Check if a type string represents a primitive type
|
|
53
|
+
// Handles union types like "string | undefined" or "number | null"
|
|
54
|
+
function isPrimitiveType(typeStr: string): boolean {
|
|
55
|
+
if (PRIMITIVE_TYPES.has(typeStr)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// Check union types - if ALL parts of the union are primitives, it's primitive
|
|
59
|
+
// e.g., "string | undefined" -> ["string", "undefined"] -> both are primitive -> true
|
|
60
|
+
// e.g., "object | null" -> ["object", "null"] -> object is not primitive -> false
|
|
61
|
+
if (typeStr.includes('|')) {
|
|
62
|
+
const parts = typeStr.split('|').map((p) => p.trim());
|
|
63
|
+
return parts.every((part) => PRIMITIVE_TYPES.has(part));
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Check if a new schema path would go through a primitive type
|
|
69
|
+
// e.g., if schema has 'entities[].scenarioCount': 'number', then
|
|
70
|
+
// 'entities[].scenarioCount.sha' would go through a primitive and should be rejected
|
|
71
|
+
function wouldGoThroughPrimitive(
|
|
72
|
+
newPath: string,
|
|
73
|
+
schema: { [key: string]: string },
|
|
74
|
+
): boolean {
|
|
75
|
+
const pathParts = splitOutsideParenthesesAndArrays(newPath);
|
|
76
|
+
|
|
77
|
+
// Check each prefix of the path (excluding the full path itself)
|
|
78
|
+
for (let i = 1; i < pathParts.length; i++) {
|
|
79
|
+
const prefixPath = joinParenthesesAndArrays(pathParts.slice(0, i));
|
|
80
|
+
const prefixType = schema[prefixPath];
|
|
81
|
+
if (prefixType && isPrimitiveType(prefixType)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
43
89
|
// Check if schemaPathPart matches or is a function call variant of pathPart
|
|
44
90
|
// e.g., 'isEntityBeingAnalyzed(entity.sha)' matches 'isEntityBeingAnalyzed'
|
|
45
91
|
function pathPartMatches(pathPart: string, schemaPathPart: string): boolean {
|
|
@@ -57,10 +103,14 @@ function bestValueFromOptions(options: Array<string | undefined>) {
|
|
|
57
103
|
options = options.filter(Boolean) as string[];
|
|
58
104
|
|
|
59
105
|
const known = options.find((o) => !o.includes('unknown'));
|
|
60
|
-
if (known)
|
|
106
|
+
if (known) {
|
|
107
|
+
return known;
|
|
108
|
+
}
|
|
61
109
|
|
|
62
110
|
const notUnknown = options.find((o) => o !== 'unknown');
|
|
63
|
-
if (notUnknown)
|
|
111
|
+
if (notUnknown) {
|
|
112
|
+
return notUnknown;
|
|
113
|
+
}
|
|
64
114
|
|
|
65
115
|
return options[0] ?? 'unknown';
|
|
66
116
|
}
|
|
@@ -152,10 +202,21 @@ export default function mergeInDependentDataStructure({
|
|
|
152
202
|
equivalentPostfixes: Record<string, string>;
|
|
153
203
|
}[] = [];
|
|
154
204
|
|
|
205
|
+
// Pre-build a lookup map from cleaned function name to dependency for O(1) lookups.
|
|
206
|
+
// This avoids O(n) linear search in findRelevantDependency which was causing O(n²) performance.
|
|
207
|
+
const dependencyByCleanedName = new Map<
|
|
208
|
+
string,
|
|
209
|
+
(typeof importedExports)[0]
|
|
210
|
+
>();
|
|
211
|
+
for (const dep of importedExports) {
|
|
212
|
+
const cleanedName = cleanFunctionName(dep.name);
|
|
213
|
+
if (!dependencyByCleanedName.has(cleanedName)) {
|
|
214
|
+
dependencyByCleanedName.set(cleanedName, dep);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
155
218
|
const findRelevantDependency = (functionName: any) => {
|
|
156
|
-
return
|
|
157
|
-
(d) => cleanFunctionName(d.name) === cleanFunctionName(functionName),
|
|
158
|
-
);
|
|
219
|
+
return dependencyByCleanedName.get(cleanFunctionName(functionName));
|
|
159
220
|
};
|
|
160
221
|
|
|
161
222
|
const findRelevantDependentDataStructure = (functionName: any) => {
|
|
@@ -291,16 +352,16 @@ export default function mergeInDependentDataStructure({
|
|
|
291
352
|
} else {
|
|
292
353
|
equivalentSchemaPathsEntry.equivalentRoots.push(...equivalentRoots);
|
|
293
354
|
}
|
|
355
|
+
|
|
356
|
+
// Deduplicate roots using a Set for O(n) instead of O(n²)
|
|
357
|
+
const seenRoots = new Set<string>();
|
|
294
358
|
equivalentSchemaPathsEntry.equivalentRoots =
|
|
295
|
-
equivalentSchemaPathsEntry.equivalentRoots.filter(
|
|
296
|
-
(er
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
e.function?.name === er.function?.name,
|
|
302
|
-
),
|
|
303
|
-
);
|
|
359
|
+
equivalentSchemaPathsEntry.equivalentRoots.filter((er) => {
|
|
360
|
+
const key = er.schemaRootPath + '::' + (er.function?.name ?? '');
|
|
361
|
+
if (seenRoots.has(key)) return false;
|
|
362
|
+
seenRoots.add(key);
|
|
363
|
+
return true;
|
|
364
|
+
});
|
|
304
365
|
|
|
305
366
|
return equivalentSchemaPathsEntry;
|
|
306
367
|
};
|
|
@@ -880,7 +941,44 @@ export default function mergeInDependentDataStructure({
|
|
|
880
941
|
equivalentSchemaPaths = mergeAllEquivalentSchemaPaths();
|
|
881
942
|
|
|
882
943
|
for (const esp of equivalentSchemaPaths) {
|
|
883
|
-
|
|
944
|
+
// Pre-compute which postfixes have children to avoid O(n²) lookups in the inner loop.
|
|
945
|
+
// A postfix "has children" if there are other postfixes that extend it.
|
|
946
|
+
const postfixesWithChildren = new Set<string>();
|
|
947
|
+
const postfixKeys = Object.keys(esp.equivalentPostfixes);
|
|
948
|
+
|
|
949
|
+
// Check for empty postfix having children (any other postfixes exist)
|
|
950
|
+
if (postfixKeys.length > 1 && '' in esp.equivalentPostfixes) {
|
|
951
|
+
postfixesWithChildren.add('');
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// Check for array element postfixes having children using a prefix set.
|
|
955
|
+
// This avoids O(n²) scans across large postfix lists.
|
|
956
|
+
// e.g., 'currentEntities[]' has children if a path like 'currentEntities[].sha' exists.
|
|
957
|
+
const postfixPrefixSet = new Set<string>();
|
|
958
|
+
for (const postfixPath of postfixKeys) {
|
|
959
|
+
if (!postfixPath) continue;
|
|
960
|
+
const parts = splitOutsideParenthesesAndArrays(postfixPath);
|
|
961
|
+
for (let i = 1; i < parts.length; i++) {
|
|
962
|
+
postfixPrefixSet.add(joinParenthesesAndArrays(parts.slice(0, i)));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
for (const postfixPath of postfixKeys) {
|
|
966
|
+
if (postfixPath.endsWith('[]') && postfixPrefixSet.has(postfixPath)) {
|
|
967
|
+
postfixesWithChildren.add(postfixPath);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Deduplicate equivalentRoots that would write to the same schema paths.
|
|
972
|
+
// Roots with the same (function, schemaRootPath, postfix) are redundant.
|
|
973
|
+
const seenRootKeys = new Set<string>();
|
|
974
|
+
const uniqueRoots = esp.equivalentRoots.filter((root) => {
|
|
975
|
+
const key = `${root.function?.filePath ?? ''}::${root.function?.name ?? ''}::${root.schemaRootPath}::${root.postfix ?? ''}`;
|
|
976
|
+
if (seenRootKeys.has(key)) return false;
|
|
977
|
+
seenRootKeys.add(key);
|
|
978
|
+
return true;
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
for (const equivalentRoot of uniqueRoots) {
|
|
884
982
|
let merged:
|
|
885
983
|
| {
|
|
886
984
|
signatureSchema: { [key: string]: string };
|
|
@@ -905,9 +1003,21 @@ export default function mergeInDependentDataStructure({
|
|
|
905
1003
|
)) {
|
|
906
1004
|
let relevantPostfix = postfixPath;
|
|
907
1005
|
if (equivalentRoot.postfix) {
|
|
1006
|
+
// Check if postfixPath starts with equivalentRoot.postfix at a path boundary.
|
|
1007
|
+
// Must ensure exact path part match - "entityCode" should NOT match "entity" prefix.
|
|
1008
|
+
// Valid: "entity.foo" starts with "entity" (boundary at '.')
|
|
1009
|
+
// Valid: "entity[0]" starts with "entity" (boundary at '[')
|
|
1010
|
+
// Invalid: "entityCode" starts with "entity" (no boundary, different property)
|
|
908
1011
|
if (!postfixPath.startsWith(equivalentRoot.postfix)) {
|
|
909
1012
|
continue;
|
|
910
1013
|
}
|
|
1014
|
+
// Additional check: ensure the match is at a path boundary
|
|
1015
|
+
const nextChar = postfixPath[equivalentRoot.postfix.length];
|
|
1016
|
+
if (nextChar !== undefined && nextChar !== '.' && nextChar !== '[') {
|
|
1017
|
+
// The postfixPath continues with more characters that aren't a path separator.
|
|
1018
|
+
// This means "entity" matched "entityCode" which is wrong - they're different properties.
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
911
1021
|
|
|
912
1022
|
const postFixPathParts =
|
|
913
1023
|
splitOutsideParenthesesAndArrays(postfixPath);
|
|
@@ -924,6 +1034,44 @@ export default function mergeInDependentDataStructure({
|
|
|
924
1034
|
relevantPostfix,
|
|
925
1035
|
]);
|
|
926
1036
|
|
|
1037
|
+
// Skip paths that would go through a primitive type
|
|
1038
|
+
// e.g., if schema has 'entities[].scenarioCount': 'number', skip 'entities[].scenarioCount.sha'
|
|
1039
|
+
if (wouldGoThroughPrimitive(newSchemaPath, schema)) {
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
// Skip setting primitive type when there are child postfixes that indicate structure.
|
|
1044
|
+
// This prevents downgrading an object/array element to a primitive type.
|
|
1045
|
+
// Uses pre-computed postfixesWithChildren Set for O(1) lookup instead of O(n) iteration.
|
|
1046
|
+
const hasChildPostfixes =
|
|
1047
|
+
(relevantPostfix === '' || relevantPostfix.endsWith('[]')) &&
|
|
1048
|
+
postfixesWithChildren.has(postfixPath);
|
|
1049
|
+
if (PRIMITIVE_TYPES.has(postfixValue) && hasChildPostfixes) {
|
|
1050
|
+
continue;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// Don't overwrite a more specific type with a less specific one
|
|
1054
|
+
// This can happen when nested roots share entries with their parent roots
|
|
1055
|
+
const existingType = schema[newSchemaPath];
|
|
1056
|
+
if (existingType) {
|
|
1057
|
+
// Don't overwrite a primitive type with 'object' or 'array'
|
|
1058
|
+
// e.g., if schema has 'entities[].scenarioCount': 'number', don't overwrite with 'object'
|
|
1059
|
+
if (
|
|
1060
|
+
PRIMITIVE_TYPES.has(existingType) &&
|
|
1061
|
+
(postfixValue === 'object' || postfixValue === 'array')
|
|
1062
|
+
) {
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
// Don't overwrite a complex/union type with a primitive
|
|
1066
|
+
// e.g., if schema has 'scenarios[]': 'Scenario | null', don't overwrite with 'string'
|
|
1067
|
+
if (
|
|
1068
|
+
!PRIMITIVE_TYPES.has(existingType) &&
|
|
1069
|
+
PRIMITIVE_TYPES.has(postfixValue)
|
|
1070
|
+
) {
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
927
1075
|
schema[newSchemaPath] = postfixValue;
|
|
928
1076
|
}
|
|
929
1077
|
|
|
@@ -1254,6 +1402,40 @@ export default function mergeInDependentDataStructure({
|
|
|
1254
1402
|
cleanSchema(depSchema.returnValueSchema);
|
|
1255
1403
|
}
|
|
1256
1404
|
|
|
1405
|
+
// TYPE REFINEMENT: Check if dependentAnalyses has a more specific type for this dependency.
|
|
1406
|
+
// When a parent passes `entity.filePath` (string | undefined) to a child component
|
|
1407
|
+
// that requires `filePath: string`, we should use the child's more specific type.
|
|
1408
|
+
// This prevents mock data from having undefined values for required props.
|
|
1409
|
+
//
|
|
1410
|
+
// This runs REGARDLESS of whether equivalencies already processed the schema,
|
|
1411
|
+
// because equivalencies copy the parent's type (string | undefined), not the child's
|
|
1412
|
+
// required type (string).
|
|
1413
|
+
const depSchema = findOrCreateDependentSchemas({ filePath, name });
|
|
1414
|
+
const childAnalysis = dependentAnalyses[filePath]?.[name];
|
|
1415
|
+
const childSignatureSchema =
|
|
1416
|
+
childAnalysis?.metadata?.mergedDataStructure?.signatureSchema;
|
|
1417
|
+
|
|
1418
|
+
if (childSignatureSchema) {
|
|
1419
|
+
for (const path in depSchema.signatureSchema) {
|
|
1420
|
+
const parentType = depSchema.signatureSchema[path];
|
|
1421
|
+
const childType = childSignatureSchema[path];
|
|
1422
|
+
|
|
1423
|
+
if (parentType && childType) {
|
|
1424
|
+
// Check if parent has optional type and child has required type
|
|
1425
|
+
const parentIsOptional =
|
|
1426
|
+
parentType.includes('| undefined') ||
|
|
1427
|
+
parentType.includes('| null');
|
|
1428
|
+
const childIsOptional =
|
|
1429
|
+
childType.includes('| undefined') || childType.includes('| null');
|
|
1430
|
+
|
|
1431
|
+
// If child requires a more specific type (not optional), use it
|
|
1432
|
+
if (parentIsOptional && !childIsOptional) {
|
|
1433
|
+
depSchema.signatureSchema[path] = childType;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1257
1439
|
// For functions with multiple different type parameters, also create separate entries
|
|
1258
1440
|
// for each type-parameterized variant. This allows gatherDataForMocks to look up
|
|
1259
1441
|
// the specific schema for each call signature.
|
|
@@ -1352,8 +1534,8 @@ export default function mergeInDependentDataStructure({
|
|
|
1352
1534
|
// Merge in the nested dependency schemas
|
|
1353
1535
|
for (const path in nestedDepSchema.returnValueSchema) {
|
|
1354
1536
|
if (!(path in targetDepSchema.returnValueSchema)) {
|
|
1355
|
-
|
|
1356
|
-
|
|
1537
|
+
const value = nestedDepSchema.returnValueSchema[path];
|
|
1538
|
+
targetDepSchema.returnValueSchema[path] = value;
|
|
1357
1539
|
}
|
|
1358
1540
|
}
|
|
1359
1541
|
|