@codeyam/codeyam-cli 0.1.0-staging.2a88920 → 0.1.0-staging.4684848
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 +4 -4
- package/analyzer-template/packages/ai/index.ts +1 -0
- package/analyzer-template/packages/ai/package.json +2 -2
- package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +23 -1
- package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
- package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +101 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +6 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +330 -9
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +11 -2
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +2 -2
- 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 +20 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +84 -19
- package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
- package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +299 -5
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +38 -2
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +359 -142
- 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/promptGenerators/collapseNullableObjects.ts +118 -0
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
- package/analyzer-template/packages/analyze/index.ts +2 -0
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +69 -3
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +5 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +4 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +59 -26
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +194 -15
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +372 -57
- package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
- 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 +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/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/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 +3 -0
- 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/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/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/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/types/src/types/ProjectMetadata.ts +7 -0
- 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/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/src/lib/fs/rsyncCopy.ts +108 -2
- package/analyzer-template/project/constructMockCode.ts +36 -1
- package/analyzer-template/project/writeMockDataTsx.ts +174 -12
- package/analyzer-template/project/writeScenarioComponents.ts +60 -12
- package/analyzer-template/project/writeSimpleRoot.ts +21 -11
- 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/constructMockCode.js +30 -1
- package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
- package/background/src/lib/virtualized/project/writeMockDataTsx.js +156 -8
- package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
- package/background/src/lib/virtualized/project/writeScenarioComponents.js +60 -15
- 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 +2 -0
- 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 +2 -0
- 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 +17 -26
- package/codeyam-cli/src/commands/memory.js.map +1 -1
- 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__/setupClaudeCodeSettings.test.js +128 -86
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.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 +9 -0
- 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 +57 -54
- 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/progress.js +7 -0
- package/codeyam-cli/src/utils/progress.js.map +1 -1
- package/codeyam-cli/src/utils/queue/job.js +4 -0
- package/codeyam-cli/src/utils/queue/job.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 +75 -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 +378 -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 +115 -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 +1 -0
- package/codeyam-cli/src/utils/rules/index.js.map +1 -1
- package/codeyam-cli/src/utils/rules/parser.js +2 -25
- package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
- 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 +16 -11
- package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
- 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 -44
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
- package/codeyam-cli/src/webserver/app/lib/database.js +15 -3
- package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
- package/codeyam-cli/src/webserver/backgroundServer.js +24 -0
- package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CQ-wF3Tv.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DsN1wKrm.js → EntityItem-HdckCi0m.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-Dh5RJMOE.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-BnjjBHJu.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-CUSfu6W5.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-Coll1aD6.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-lYMY8h-y.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-ay8XeA59.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-Dpul1_ik.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-OApQuNyq.js → ReportIssueModal-CRBCfV2W.js} +3 -8
- package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-DRTFDNFt.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DzccYyI8.js → ScenarioViewer-d6PSFxhS.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-DDEOQ6Iw.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-CkziGg5F.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BwavGCpm.js → activity.(_tab)-B2v1pm9w.js} +6 -11
- package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-BXIaK8Md.js +11 -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.labs-unlock-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-qbapxy6o.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-C-mKrwr1.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-BAvUl1nT.js} +12 -12
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-DlrT-SzI.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/copy-clIxnCqQ.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-B931Etud.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{dev.empty-BBnGWYga.js → dev.empty-BoPM6KnE.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-oVRMh9Hl.js +16 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-BjyzwQ7H.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-DxuyDmZA.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-DESSZGQp.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-D5Yb90Ad.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-DuObVYgh.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{files-CJ6lTdTA.js → files-CDfz4Y-i.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{git-CPTZZ-JZ.js → git-D6jOlDQw.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/globals-CKT08Djd.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-DvOt1KIt.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-WfQFdoWK.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/labs-BbGyC1RY.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-Bb7Y9k5O.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-fd06e67a.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/memory-BXebUPaL.js +78 -0
- package/codeyam-cli/src/webserver/build/client/assets/pause-DaAHX2on.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/root-CvNE9MaT.js +62 -0
- package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-DIqAPIrO.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-DCIzBZM9.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-C6n_fNQY.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/terminal-CmPsszJy.js +11 -0
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-Beg-oV50.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-D7TLbP3M.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-Ce5rnai3.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-B4D3wj27.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-BDt_-DnY.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/{index-BM6TDT1Y.js → index-DDr9Cp9M.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-DjwiujaU.js +257 -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} +1 -1
- package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
- package/codeyam-cli/templates/codeyam-memory-hook.sh +19 -20
- package/codeyam-cli/templates/codeyam-memory.md +392 -0
- package/codeyam-cli/templates/{codeyam:new-rule.md → codeyam-new-rule.md} +2 -2
- 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 +554 -87
- package/codeyam-cli/templates/rules-instructions.md +63 -24
- package/package.json +10 -10
- package/packages/ai/index.js +1 -1
- package/packages/ai/index.js.map +1 -1
- package/packages/ai/src/lib/analyzeScope.js +21 -1
- package/packages/ai/src/lib/analyzeScope.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/processExpression.js +78 -1
- 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/dataStructure/ScopeDataStructure.js +262 -8
- 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/helpers/cleanKnownObjectFunctions.js +11 -2
- package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +2 -2
- 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 +15 -1
- package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +78 -17
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
- package/packages/ai/src/lib/dataStructureChunking.js +26 -11
- package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
- 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 +212 -3
- package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlows.js +16 -2
- package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +242 -81
- package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
- 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/promptGenerators/collapseNullableObjects.js +97 -0
- package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
- package/packages/analyze/index.js +1 -0
- package/packages/analyze/index.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +52 -2
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +3 -0
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.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 +5 -1
- package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +51 -14
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +116 -13
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +310 -45
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.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/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 +3 -0
- package/packages/database/src/lib/kysely/db.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/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/utils/src/lib/fs/rsyncCopy.js +93 -2
- package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
- package/scripts/finalize-analyzer.cjs +8 -76
- package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-BJUiQqZF.js +0 -23
- package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-a78b90a2.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/memory--GCbFsBE.js +0 -92
- package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +0 -62
- package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-dYC34MHw.js +0 -257
- package/codeyam-cli/templates/codeyam:diagnose.md +0 -803
- package/codeyam-cli/templates/codeyam:memory.md +0 -341
|
@@ -1,5 +1,97 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
1
|
+
import { spawn, execSync } from 'child_process';
|
|
2
|
+
import { existsSync, readdirSync, rmSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Try to use APFS copy-on-write clones on macOS for near-instant directory copies.
|
|
6
|
+
* Falls back to rsync on non-macOS or if the clone fails.
|
|
7
|
+
*
|
|
8
|
+
* Returns true if the clone succeeded (caller can skip rsync).
|
|
9
|
+
*/
|
|
10
|
+
function tryApfsClone({ sourcePath, destinationPath, excludes, silent, }) {
|
|
11
|
+
if (process.platform !== 'darwin')
|
|
12
|
+
return false;
|
|
13
|
+
// APFS clone requires the destination to not exist.
|
|
14
|
+
// If it exists and is empty, remove it so we can clone into it.
|
|
15
|
+
if (existsSync(destinationPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const contents = readdirSync(destinationPath);
|
|
18
|
+
if (contents.length > 0) {
|
|
19
|
+
// Destination is non-empty — can't use clone, fall back to rsync
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
rmSync(destinationPath, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
// cp -c -R: APFS copy-on-write clone (faster than rsync, avoids data copy)
|
|
30
|
+
execSync(`cp -c -R "${sourcePath}" "${destinationPath}"`, {
|
|
31
|
+
stdio: 'pipe',
|
|
32
|
+
timeout: 300000, // 5 min safety timeout
|
|
33
|
+
});
|
|
34
|
+
// Remove excluded items from the clone
|
|
35
|
+
for (const exclude of excludes) {
|
|
36
|
+
if (exclude.includes('*')) {
|
|
37
|
+
// Glob pattern — use shell expansion
|
|
38
|
+
try {
|
|
39
|
+
execSync(`rm -rf "${join(destinationPath, exclude)}"`, {
|
|
40
|
+
stdio: 'pipe',
|
|
41
|
+
shell: '/bin/sh',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Glob matched nothing — fine
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const excludePath = join(destinationPath, exclude);
|
|
50
|
+
if (existsSync(excludePath)) {
|
|
51
|
+
rmSync(excludePath, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!silent) {
|
|
56
|
+
console.log(`Directory cloned (APFS CoW) from ${sourcePath} to ${destinationPath}`);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Clone failed (cross-volume, non-APFS, etc.) — fall back to rsync
|
|
62
|
+
// Clean up any partial clone
|
|
63
|
+
if (existsSync(destinationPath)) {
|
|
64
|
+
try {
|
|
65
|
+
rmSync(destinationPath, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Best effort cleanup
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
2
74
|
export default async function rsyncCopy({ sourcePath, destinationPath, excludes = [], keepExisting = false, silent = false, extraArgs = [], }) {
|
|
75
|
+
const startTime = Date.now();
|
|
76
|
+
// On macOS, try APFS copy-on-write clone first (near-instant).
|
|
77
|
+
// Skip when extraArgs are provided since those are rsync-specific flags
|
|
78
|
+
// that the clone path can't honor.
|
|
79
|
+
if (!keepExisting && extraArgs.length === 0) {
|
|
80
|
+
const cloned = tryApfsClone({
|
|
81
|
+
sourcePath,
|
|
82
|
+
destinationPath,
|
|
83
|
+
excludes,
|
|
84
|
+
silent,
|
|
85
|
+
});
|
|
86
|
+
if (cloned) {
|
|
87
|
+
if (!silent) {
|
|
88
|
+
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
89
|
+
console.log(`Directory synced from ${sourcePath} to ${destinationPath} [Time: ${duration}s]`);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Fall back to rsync
|
|
3
95
|
return new Promise((resolve, reject) => {
|
|
4
96
|
const source = sourcePath.endsWith('/') ? sourcePath : `${sourcePath}/`;
|
|
5
97
|
const dest = destinationPath.endsWith('/')
|
|
@@ -16,7 +108,6 @@ export default async function rsyncCopy({ sourcePath, destinationPath, excludes
|
|
|
16
108
|
rsyncArgs.push(`--exclude=${exclude}`);
|
|
17
109
|
}
|
|
18
110
|
rsyncArgs.push(source, dest);
|
|
19
|
-
const startTime = Date.now();
|
|
20
111
|
const rsyncProcess = spawn('rsync', rsyncArgs);
|
|
21
112
|
rsyncProcess.on('exit', (code) => {
|
|
22
113
|
if (code === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsyncCopy.js","sourceRoot":"","sources":["../../../../../src/lib/fs/rsyncCopy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"rsyncCopy.js","sourceRoot":"","sources":["../../../../../src/lib/fs/rsyncCopy.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,87 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
1
|
+
import { spawn, execSync } from 'child_process';
|
|
2
|
+
import { existsSync, readdirSync, rmSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Try to use APFS copy-on-write clones on macOS for near-instant directory copies.
|
|
7
|
+
* Falls back to rsync on non-macOS or if the clone fails.
|
|
8
|
+
*
|
|
9
|
+
* Returns true if the clone succeeded (caller can skip rsync).
|
|
10
|
+
*/
|
|
11
|
+
function tryApfsClone({
|
|
12
|
+
sourcePath,
|
|
13
|
+
destinationPath,
|
|
14
|
+
excludes,
|
|
15
|
+
silent,
|
|
16
|
+
}: {
|
|
17
|
+
sourcePath: string;
|
|
18
|
+
destinationPath: string;
|
|
19
|
+
excludes: string[];
|
|
20
|
+
silent: boolean;
|
|
21
|
+
}): boolean {
|
|
22
|
+
if (process.platform !== 'darwin') return false;
|
|
23
|
+
|
|
24
|
+
// APFS clone requires the destination to not exist.
|
|
25
|
+
// If it exists and is empty, remove it so we can clone into it.
|
|
26
|
+
if (existsSync(destinationPath)) {
|
|
27
|
+
try {
|
|
28
|
+
const contents = readdirSync(destinationPath);
|
|
29
|
+
if (contents.length > 0) {
|
|
30
|
+
// Destination is non-empty — can't use clone, fall back to rsync
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
rmSync(destinationPath, { recursive: true });
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
// cp -c -R: APFS copy-on-write clone (faster than rsync, avoids data copy)
|
|
41
|
+
execSync(`cp -c -R "${sourcePath}" "${destinationPath}"`, {
|
|
42
|
+
stdio: 'pipe',
|
|
43
|
+
timeout: 300_000, // 5 min safety timeout
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Remove excluded items from the clone
|
|
47
|
+
for (const exclude of excludes) {
|
|
48
|
+
if (exclude.includes('*')) {
|
|
49
|
+
// Glob pattern — use shell expansion
|
|
50
|
+
try {
|
|
51
|
+
execSync(`rm -rf "${join(destinationPath, exclude)}"`, {
|
|
52
|
+
stdio: 'pipe',
|
|
53
|
+
shell: '/bin/sh',
|
|
54
|
+
});
|
|
55
|
+
} catch {
|
|
56
|
+
// Glob matched nothing — fine
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const excludePath = join(destinationPath, exclude);
|
|
60
|
+
if (existsSync(excludePath)) {
|
|
61
|
+
rmSync(excludePath, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!silent) {
|
|
67
|
+
console.log(
|
|
68
|
+
`Directory cloned (APFS CoW) from ${sourcePath} to ${destinationPath}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
} catch {
|
|
73
|
+
// Clone failed (cross-volume, non-APFS, etc.) — fall back to rsync
|
|
74
|
+
// Clean up any partial clone
|
|
75
|
+
if (existsSync(destinationPath)) {
|
|
76
|
+
try {
|
|
77
|
+
rmSync(destinationPath, { recursive: true });
|
|
78
|
+
} catch {
|
|
79
|
+
// Best effort cleanup
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
2
85
|
|
|
3
86
|
export default async function rsyncCopy({
|
|
4
87
|
sourcePath,
|
|
@@ -15,6 +98,30 @@ export default async function rsyncCopy({
|
|
|
15
98
|
silent?: boolean;
|
|
16
99
|
extraArgs?: string[];
|
|
17
100
|
}): Promise<void> {
|
|
101
|
+
const startTime = Date.now();
|
|
102
|
+
|
|
103
|
+
// On macOS, try APFS copy-on-write clone first (near-instant).
|
|
104
|
+
// Skip when extraArgs are provided since those are rsync-specific flags
|
|
105
|
+
// that the clone path can't honor.
|
|
106
|
+
if (!keepExisting && extraArgs.length === 0) {
|
|
107
|
+
const cloned = tryApfsClone({
|
|
108
|
+
sourcePath,
|
|
109
|
+
destinationPath,
|
|
110
|
+
excludes,
|
|
111
|
+
silent,
|
|
112
|
+
});
|
|
113
|
+
if (cloned) {
|
|
114
|
+
if (!silent) {
|
|
115
|
+
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
116
|
+
console.log(
|
|
117
|
+
`Directory synced from ${sourcePath} to ${destinationPath} [Time: ${duration}s]`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Fall back to rsync
|
|
18
125
|
return new Promise((resolve, reject) => {
|
|
19
126
|
const source = sourcePath.endsWith('/') ? sourcePath : `${sourcePath}/`;
|
|
20
127
|
const dest = destinationPath.endsWith('/')
|
|
@@ -37,7 +144,6 @@ export default async function rsyncCopy({
|
|
|
37
144
|
|
|
38
145
|
rsyncArgs.push(source, dest);
|
|
39
146
|
|
|
40
|
-
const startTime = Date.now();
|
|
41
147
|
const rsyncProcess = spawn('rsync', rsyncArgs);
|
|
42
148
|
|
|
43
149
|
rsyncProcess.on('exit', (code) => {
|
|
@@ -1413,6 +1413,17 @@ export default function constructMockCode(
|
|
|
1413
1413
|
.replace(/,\s*$/, '');
|
|
1414
1414
|
returnValueContents = `${arrayBasePath}?.map((__item__, __idx__) => (\n${indent(trimmedContent)}\n))`;
|
|
1415
1415
|
} else {
|
|
1416
|
+
// When generating object-wrapped .map(), ensure original item data is preserved.
|
|
1417
|
+
// If no data spread was included (e.g., because this is a plain array property,
|
|
1418
|
+
// not a function return), add ...__item__ to spread the original item properties.
|
|
1419
|
+
// Without this, the .map() would create new objects with only nested function
|
|
1420
|
+
// properties, losing data like filePath, frontmatter, body, etc.
|
|
1421
|
+
const hasDataSpread =
|
|
1422
|
+
mappedContents.includes('...scenarios()') ||
|
|
1423
|
+
mappedContents.includes('...__item__');
|
|
1424
|
+
if (!hasDataSpread) {
|
|
1425
|
+
mappedContents = `...__item__,\n${mappedContents}`;
|
|
1426
|
+
}
|
|
1416
1427
|
returnValueContents = `${arrayBasePath}?.map((__item__, __idx__) => ({\n${indent(mappedContents)}\n}))`;
|
|
1417
1428
|
}
|
|
1418
1429
|
} // Close the empty content check else block
|
|
@@ -1479,6 +1490,17 @@ export default function constructMockCode(
|
|
|
1479
1490
|
mappedContents = filterOutArrowFunctions(mappedContents);
|
|
1480
1491
|
mappedContents = filterOutBareObjects(mappedContents, true);
|
|
1481
1492
|
mappedContents = cleanupContent(mappedContents);
|
|
1493
|
+
// Same as needsWrapper branch: ensure item data is preserved in .map()
|
|
1494
|
+
const hasDataSpreadInner =
|
|
1495
|
+
mappedContents.includes('...scenarios()') ||
|
|
1496
|
+
mappedContents.includes('...__item__');
|
|
1497
|
+
if (!hasDataSpreadInner && mappedContents.trim().length > 0) {
|
|
1498
|
+
// Insert ...__item__ after the opening brace
|
|
1499
|
+
mappedContents = mappedContents.replace(
|
|
1500
|
+
/^\s*\{/,
|
|
1501
|
+
'{\n...__item__,',
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1482
1504
|
returnValueContents = `${arrayBasePath}?.map((__item__, __idx__) => (\n${indent(mappedContents)}\n))`;
|
|
1483
1505
|
}
|
|
1484
1506
|
} else {
|
|
@@ -2428,7 +2450,20 @@ export default function constructMockCode(
|
|
|
2428
2450
|
const safeReturnValue = isSimpleDataPath
|
|
2429
2451
|
? `${returnValue} ?? {}`
|
|
2430
2452
|
: returnValue;
|
|
2431
|
-
|
|
2453
|
+
const refName = `_${safeFunctionName}Ref`;
|
|
2454
|
+
const assignment = `${refName}.current = ${safeReturnValue};`;
|
|
2455
|
+
const ifBlock = `if (!${refName}.current) {\n${indent(assignment)}\n}`;
|
|
2456
|
+
const body = `${ifBlock}\nreturn ${refName}.current;`;
|
|
2457
|
+
|
|
2458
|
+
return [
|
|
2459
|
+
`// PATCHED: memoize to return stable reference (prevents infinite useEffect re-triggers)`,
|
|
2460
|
+
`const ${refName} = {`,
|
|
2461
|
+
` current: null,`,
|
|
2462
|
+
`};`,
|
|
2463
|
+
`${isRootAsyncFunction ? 'async ' : ''}function ${safeFunctionName}(...args) {`,
|
|
2464
|
+
indent(body),
|
|
2465
|
+
`}`,
|
|
2466
|
+
].join('\n');
|
|
2432
2467
|
} else {
|
|
2433
2468
|
// Generate safe const name:
|
|
2434
2469
|
// 1. For call signatures: use derivedFunctionName
|
|
@@ -192,6 +192,36 @@ const safeString = (s: string, level: number) => {
|
|
|
192
192
|
return s?.replace ? s.replace(/"/g, "'").replace(/\n/g, '\\n') : s;
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Clean up malformed LLM-generated function values.
|
|
197
|
+
* The LLM sometimes generates function values with an invalid "(function)" prefix like:
|
|
198
|
+
* - "(function)() => {}"
|
|
199
|
+
* - "(function)(event) => {}"
|
|
200
|
+
* - "(function)(id) => {}"
|
|
201
|
+
*
|
|
202
|
+
* This strips the prefix and adds TypeScript `any` type annotations to parameters.
|
|
203
|
+
* Returns null if the value doesn't match the malformed pattern.
|
|
204
|
+
*/
|
|
205
|
+
const cleanMalformedFunctionValue = (value: string): string | null => {
|
|
206
|
+
// Match "(function)" followed by optional params in parens, then "=>"
|
|
207
|
+
const match = value.match(/^\(function\)(\([^)]*\))\s*=>\s*(.*)$/);
|
|
208
|
+
if (!match) return null;
|
|
209
|
+
|
|
210
|
+
const [, paramsWithParens, body] = match;
|
|
211
|
+
|
|
212
|
+
// Extract parameter names and add `: any` type annotation
|
|
213
|
+
// e.g., "(event)" -> "(event: any)", "()" -> "()"
|
|
214
|
+
const params = paramsWithParens.slice(1, -1).trim(); // Remove outer parens
|
|
215
|
+
const typedParams = params
|
|
216
|
+
? params
|
|
217
|
+
.split(',')
|
|
218
|
+
.map((p) => `${p.trim()}: any`)
|
|
219
|
+
.join(', ')
|
|
220
|
+
: '';
|
|
221
|
+
|
|
222
|
+
return `(${typedParams}) => ${body}`;
|
|
223
|
+
};
|
|
224
|
+
|
|
195
225
|
/**
|
|
196
226
|
* Check if a mock key's schema indicates it should be instantiated as a Map.
|
|
197
227
|
* A Map is indicated by:
|
|
@@ -310,6 +340,38 @@ function extractAllKeys(obj: JsonTypeDefinition | undefined): string[] {
|
|
|
310
340
|
*/
|
|
311
341
|
const BARE_TYPE_MARKERS = ['function', 'async-function'];
|
|
312
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Check if a string is a TypeScript arrow function type annotation rather than
|
|
345
|
+
* a valid JavaScript arrow function expression.
|
|
346
|
+
*
|
|
347
|
+
* TypeScript arrow types look like function expressions (they contain '=>') but
|
|
348
|
+
* their "body" is a type name, not a JS expression:
|
|
349
|
+
* - "() => void"
|
|
350
|
+
* - "(event: MouseEvent) => void"
|
|
351
|
+
* - "() => string"
|
|
352
|
+
* - "() => Promise<void>"
|
|
353
|
+
* - "(id: string, name: string) => boolean"
|
|
354
|
+
*
|
|
355
|
+
* Valid JS arrow functions have actual expression bodies:
|
|
356
|
+
* - "() => {}"
|
|
357
|
+
* - "() => 'hello'"
|
|
358
|
+
* - "(x) => x + 1"
|
|
359
|
+
* - "() => { console.log('hi'); }"
|
|
360
|
+
*/
|
|
361
|
+
const ARROW_TYPE_RETURN_TYPES =
|
|
362
|
+
/^(void|string|number|boolean|any|unknown|never|null|undefined|object|Date|Promise<\w+>)$/i;
|
|
363
|
+
|
|
364
|
+
const isArrowFunctionTypeAnnotation = (value: string): boolean => {
|
|
365
|
+
const arrowIndex = value.indexOf('=>');
|
|
366
|
+
if (arrowIndex === -1) return false;
|
|
367
|
+
|
|
368
|
+
const body = value.slice(arrowIndex + 2).trim();
|
|
369
|
+
|
|
370
|
+
// A real JS function would have {}, an expression, a string literal, etc.
|
|
371
|
+
// A type annotation has a bare type keyword as the "body".
|
|
372
|
+
return ARROW_TYPE_RETURN_TYPES.test(body);
|
|
373
|
+
};
|
|
374
|
+
|
|
313
375
|
/**
|
|
314
376
|
* Check if a value is a bare function type marker that should be filtered out.
|
|
315
377
|
* These markers indicate the LLM detected a function but couldn't generate meaningful mock data.
|
|
@@ -336,6 +398,59 @@ const isBareTypeMarker = (value: unknown): boolean => {
|
|
|
336
398
|
return false;
|
|
337
399
|
};
|
|
338
400
|
|
|
401
|
+
/**
|
|
402
|
+
* Escape newlines that appear inside string literals within a code string,
|
|
403
|
+
* while preserving structural newlines (those between statements/lines of code).
|
|
404
|
+
*
|
|
405
|
+
* This handles cases where LLM generates function bodies like:
|
|
406
|
+
* - "() => { console.log('line1\nline2'); }" - escape the \n inside the string
|
|
407
|
+
* - "() => {\n console.log('x');\n}" - preserve structural \n between statements
|
|
408
|
+
* - "() => Promise.resolve('a\nb')" - escape the \n inside the string argument
|
|
409
|
+
*
|
|
410
|
+
* The algorithm tracks whether we're inside a string literal (single, double, or
|
|
411
|
+
* backtick quotes) and only escapes newlines that appear within quotes.
|
|
412
|
+
*/
|
|
413
|
+
const escapeNewlinesInStringLiterals = (code: string): string => {
|
|
414
|
+
let result = '';
|
|
415
|
+
let inString = false;
|
|
416
|
+
let stringChar = ''; // The quote character that started the current string
|
|
417
|
+
|
|
418
|
+
for (let i = 0; i < code.length; i++) {
|
|
419
|
+
const char = code[i];
|
|
420
|
+
const prevChar = i > 0 ? code[i - 1] : '';
|
|
421
|
+
|
|
422
|
+
// Check for string literal boundaries (single, double, or backtick quotes)
|
|
423
|
+
// Skip escaped quotes (preceded by backslash)
|
|
424
|
+
if ((char === '"' || char === "'" || char === '`') && prevChar !== '\\') {
|
|
425
|
+
if (!inString) {
|
|
426
|
+
// Starting a string literal
|
|
427
|
+
inString = true;
|
|
428
|
+
stringChar = char;
|
|
429
|
+
} else if (char === stringChar) {
|
|
430
|
+
// Ending the current string literal
|
|
431
|
+
inString = false;
|
|
432
|
+
stringChar = '';
|
|
433
|
+
}
|
|
434
|
+
// If char is a different quote type while in a string, it's just a character
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Escape newlines only when inside a string literal
|
|
438
|
+
if (char === '\n') {
|
|
439
|
+
if (inString) {
|
|
440
|
+
// Inside a string literal - escape the newline
|
|
441
|
+
result += '\\n';
|
|
442
|
+
} else {
|
|
443
|
+
// Outside string - keep the structural newline
|
|
444
|
+
result += char;
|
|
445
|
+
}
|
|
446
|
+
} else {
|
|
447
|
+
result += char;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return result;
|
|
452
|
+
};
|
|
453
|
+
|
|
339
454
|
/**
|
|
340
455
|
* Normalize mock data by merging entries that have the same normalized function name.
|
|
341
456
|
* e.g., "useLastLogLine(projectSlug, !!simulatingEntitySha)" and
|
|
@@ -758,15 +873,49 @@ const jsonToCode = (
|
|
|
758
873
|
`CodeYam: Nested func transform (string->function): "${key}" -> "${funcName}": () => {}`,
|
|
759
874
|
);
|
|
760
875
|
} else if (looksLikeFunction) {
|
|
761
|
-
//
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
876
|
+
// Check for "[native code]" in function body — this is what
|
|
877
|
+
// Function.prototype.toString() returns for built-in functions.
|
|
878
|
+
// The LLM sometimes generates "function () { [native code] }" which
|
|
879
|
+
// is not valid JavaScript (the "[" is parsed as array destructuring).
|
|
880
|
+
if (stringValue.includes('[native code]')) {
|
|
881
|
+
outputValue = '() => {}';
|
|
882
|
+
console.log(
|
|
883
|
+
`CodeYam: Nested func transform (native-code->noop): "${key}" -> "${funcName}": () => {}`,
|
|
884
|
+
);
|
|
885
|
+
} else if (cleanMalformedFunctionValue(stringValue)) {
|
|
886
|
+
// Check for malformed LLM-generated function values like "(function)() => {}"
|
|
887
|
+
// These have an invalid "(function)" prefix that must be stripped
|
|
888
|
+
outputValue = cleanMalformedFunctionValue(stringValue)!;
|
|
889
|
+
console.log(
|
|
890
|
+
`CodeYam: Nested func transform (malformed->clean): "${key}" -> "${funcName}": ${outputValue}`,
|
|
891
|
+
);
|
|
892
|
+
} else if (isArrowFunctionTypeAnnotation(stringValue)) {
|
|
893
|
+
// TypeScript arrow function type annotations like "() => void",
|
|
894
|
+
// "(event: MouseEvent) => void", "() => Promise<void>" contain '=>'
|
|
895
|
+
// so they pass the looksLikeFunction check, but they are TYPE syntax,
|
|
896
|
+
// not valid JavaScript expressions. Convert to a no-op function.
|
|
897
|
+
outputValue = '() => {}';
|
|
898
|
+
console.log(
|
|
899
|
+
`CodeYam: Nested func transform (type-annotation->function): "${key}" -> "${funcName}": () => {}`,
|
|
900
|
+
);
|
|
901
|
+
} else {
|
|
902
|
+
// Handle newlines in function expressions:
|
|
903
|
+
// - Newlines inside string literals must be escaped to avoid
|
|
904
|
+
// "unterminated string literal" errors
|
|
905
|
+
// - Structural newlines (between statements) should be kept as-is
|
|
906
|
+
// to produce valid multi-line JavaScript
|
|
907
|
+
//
|
|
908
|
+
// We escape ONLY newlines that appear inside string literals (single,
|
|
909
|
+
// double, or template quotes). Structural newlines are preserved.
|
|
910
|
+
if (hasNewlines) {
|
|
911
|
+
outputValue = escapeNewlinesInStringLiterals(stringValue);
|
|
912
|
+
} else {
|
|
913
|
+
outputValue = stringValue;
|
|
914
|
+
}
|
|
915
|
+
console.log(
|
|
916
|
+
`CodeYam: Nested func transform (string): "${key}" -> "${funcName}": ${stringValue.substring(0, 30)}...`,
|
|
917
|
+
);
|
|
918
|
+
}
|
|
770
919
|
} else {
|
|
771
920
|
// Plain string value - must be quoted
|
|
772
921
|
outputValue = `"${safeString(stringValue, level)}"`;
|
|
@@ -794,9 +943,22 @@ const jsonToCode = (
|
|
|
794
943
|
if (isBareTypeMarker(stringValue)) {
|
|
795
944
|
continue;
|
|
796
945
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
946
|
+
// Check for malformed LLM-generated function values like "(function)(id) => {}"
|
|
947
|
+
// These can appear on plain keys (e.g., "closeToast") and need to be output as
|
|
948
|
+
// actual functions, not quoted strings
|
|
949
|
+
const cleanedPlainKeyFn = cleanMalformedFunctionValue(stringValue);
|
|
950
|
+
if (cleanedPlainKeyFn) {
|
|
951
|
+
keyStrings.push(
|
|
952
|
+
`${levelSpacing}"${safeString(key, level)}": ${cleanedPlainKeyFn}`,
|
|
953
|
+
);
|
|
954
|
+
console.log(
|
|
955
|
+
`CodeYam: Plain key func transform (malformed->clean): "${key}": ${cleanedPlainKeyFn}`,
|
|
956
|
+
);
|
|
957
|
+
} else {
|
|
958
|
+
keyStrings.push(
|
|
959
|
+
`${levelSpacing}"${safeString(key, level)}": "${safeString(stringValue, level)}"`,
|
|
960
|
+
);
|
|
961
|
+
}
|
|
800
962
|
}
|
|
801
963
|
} else {
|
|
802
964
|
// Skip plain keys that have function-call versions (at the same nesting level where
|
|
@@ -987,10 +987,19 @@ function addMockToContent(
|
|
|
987
987
|
/[.*+?^${}()|[\]\\]/g,
|
|
988
988
|
'\\$&',
|
|
989
989
|
);
|
|
990
|
-
// Create regex that matches the call (with optional whitespace variations)
|
|
990
|
+
// Create regex that matches the call (with optional whitespace variations).
|
|
991
|
+
// TypeScript formatters commonly break type parameters across lines, e.g.:
|
|
992
|
+
// useLoaderData<
|
|
993
|
+
// typeof loader
|
|
994
|
+
// >()
|
|
995
|
+
// So we allow optional whitespace around < and > delimiters, not just
|
|
996
|
+
// where whitespace already exists in the call signature string.
|
|
991
997
|
const callRegex = new RegExp(
|
|
992
|
-
escapedCallSignature
|
|
993
|
-
|
|
998
|
+
escapedCallSignature
|
|
999
|
+
.replace(/\s+/g, '\\s*')
|
|
1000
|
+
.replace(/</g, '\\s*<\\s*')
|
|
1001
|
+
.replace(/>/g, '\\s*>\\s*'),
|
|
1002
|
+
'gs',
|
|
994
1003
|
);
|
|
995
1004
|
fileContent = fileContent.replace(callRegex, `${mockFunctionName}()`);
|
|
996
1005
|
}
|
|
@@ -1012,15 +1021,29 @@ function addMockToContent(
|
|
|
1012
1021
|
rootAnalysis.metadata?.scenariosDataStructure?.dataForMocks;
|
|
1013
1022
|
|
|
1014
1023
|
// Find matching call signature key in dataForMocks
|
|
1024
|
+
// IMPORTANT: First try exact match with type parameters (e.g., "useLoaderData<LoaderData>()")
|
|
1025
|
+
// to avoid picking the wrong variant (e.g., "useLoaderData<typeof loader>()" which may
|
|
1026
|
+
// have different properties). Fall back to base name matching only if exact match fails.
|
|
1015
1027
|
const hookBaseName = importedExport.name.split(/[<(]/)[0];
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1028
|
+
const expectedKey = importedExport.calls?.[0];
|
|
1029
|
+
let callSignatureKey: string | undefined;
|
|
1030
|
+
|
|
1031
|
+
if (dataForMocks) {
|
|
1032
|
+
const keys = Object.keys(dataForMocks);
|
|
1033
|
+
|
|
1034
|
+
// First try exact match with the expected call signature
|
|
1035
|
+
if (expectedKey && keys.includes(expectedKey)) {
|
|
1036
|
+
callSignatureKey = expectedKey;
|
|
1037
|
+
} else {
|
|
1038
|
+
// Fall back to base name matching
|
|
1039
|
+
callSignatureKey = keys.find((key) => {
|
|
1018
1040
|
// Split on ., <, or ( to get the true base name
|
|
1019
1041
|
// This handles both "useFlags()" -> "useFlags" and "trpc.useUtils()" -> "trpc"
|
|
1020
1042
|
const keyBaseName = key.split(/[.<(]/)[0];
|
|
1021
1043
|
return keyBaseName === hookBaseName;
|
|
1022
|
-
})
|
|
1023
|
-
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1024
1047
|
|
|
1025
1048
|
// Use the call signature if found, otherwise construct it
|
|
1026
1049
|
const dataKey =
|
|
@@ -1061,18 +1084,36 @@ function addMockToContent(
|
|
|
1061
1084
|
// IMPORTANT: We inline scenarios().data() inside the function rather than
|
|
1062
1085
|
// storing in a const - see comment in constructMockCode.ts for why.
|
|
1063
1086
|
if (!mockCode) {
|
|
1064
|
-
mockCode =
|
|
1065
|
-
|
|
1087
|
+
mockCode = `// PATCHED: memoize to return stable reference (prevents infinite useEffect re-triggers)
|
|
1088
|
+
const _${importedExport.name}Ref = {
|
|
1089
|
+
current: null,
|
|
1090
|
+
};
|
|
1091
|
+
function ${importedExport.name}(...args) {
|
|
1092
|
+
if (!_${importedExport.name}Ref.current) {
|
|
1093
|
+
_${importedExport.name}Ref.current = scenarios().data()?.["${dataKey}"];
|
|
1094
|
+
}
|
|
1095
|
+
return _${importedExport.name}Ref.current;
|
|
1066
1096
|
}`;
|
|
1067
1097
|
}
|
|
1068
1098
|
} else {
|
|
1069
1099
|
// Helper to find matching call signature key from dataForMocks
|
|
1100
|
+
// IMPORTANT: First try exact match with type parameters (e.g., "useLoaderData<LoaderData>()")
|
|
1101
|
+
// to avoid picking the wrong variant. Fall back to base name matching only if needed.
|
|
1070
1102
|
const hookBaseName = importedExport.name.split(/[<(]/)[0];
|
|
1103
|
+
const expectedKey = importedExport.calls?.[0];
|
|
1071
1104
|
const findMatchingKey = (
|
|
1072
1105
|
dataForMocks: Record<string, unknown> | undefined,
|
|
1073
1106
|
): string | undefined => {
|
|
1074
1107
|
if (!dataForMocks) return undefined;
|
|
1075
|
-
|
|
1108
|
+
const keys = Object.keys(dataForMocks);
|
|
1109
|
+
|
|
1110
|
+
// First try exact match with the expected call signature
|
|
1111
|
+
if (expectedKey && keys.includes(expectedKey)) {
|
|
1112
|
+
return expectedKey;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// Fall back to base name matching
|
|
1116
|
+
return keys.find((key) => {
|
|
1076
1117
|
// Split on ., <, or ( to get the true base name
|
|
1077
1118
|
// This handles both "useFlags()" -> "useFlags" and "trpc.useUtils()" -> "trpc"
|
|
1078
1119
|
const keyBaseName = key.split(/[.<(]/)[0];
|
|
@@ -1131,8 +1172,15 @@ function addMockToContent(
|
|
|
1131
1172
|
// IMPORTANT: We inline scenarios().data() inside the function rather than
|
|
1132
1173
|
// storing in a const - see comment in constructMockCode.ts for why.
|
|
1133
1174
|
if (!mockCode && dataKey) {
|
|
1134
|
-
mockCode =
|
|
1135
|
-
|
|
1175
|
+
mockCode = `// PATCHED: memoize to return stable reference (prevents infinite useEffect re-triggers)
|
|
1176
|
+
const _${importedExport.name}Ref = {
|
|
1177
|
+
current: null,
|
|
1178
|
+
};
|
|
1179
|
+
function ${importedExport.name}(...args) {
|
|
1180
|
+
if (!_${importedExport.name}Ref.current) {
|
|
1181
|
+
_${importedExport.name}Ref.current = scenarios().data()?.["${dataKey}"];
|
|
1182
|
+
}
|
|
1183
|
+
return _${importedExport.name}Ref.current;
|
|
1136
1184
|
}`;
|
|
1137
1185
|
}
|
|
1138
1186
|
}
|