@codeyam/codeyam-cli 0.1.0-staging.ae0de75 → 0.1.0-staging.b6c4c78
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 +6 -6
- package/analyzer-template/packages/ai/package.json +1 -1
- package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +0 -33
- package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +13 -7
- package/analyzer-template/packages/analyze/src/lib/asts/index.ts +7 -2
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +0 -98
- package/analyzer-template/packages/aws/package.json +1 -1
- package/analyzer-template/packages/database/package.json +1 -1
- package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +92 -0
- package/analyzer-template/packages/database/src/lib/loadEntities.ts +0 -6
- package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +0 -65
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +10 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +92 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +0 -6
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +0 -25
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts +2 -0
- package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js +2 -0
- package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js.map +1 -1
- package/analyzer-template/packages/types/src/enums/ProjectFramework.ts +2 -0
- package/analyzer-template/packages/ui-components/package.json +1 -1
- package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts +2 -0
- package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js +2 -0
- package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js.map +1 -1
- package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js +196 -0
- package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js.map +1 -0
- package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js +114 -0
- package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js.map +1 -0
- package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js +149 -0
- package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js.map +1 -0
- package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +45 -0
- package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js.map +1 -0
- package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js +101 -47
- package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js.map +1 -1
- package/codeyam-cli/src/commands/default.js +3 -46
- package/codeyam-cli/src/commands/default.js.map +1 -1
- package/codeyam-cli/src/commands/editor.js +2629 -329
- package/codeyam-cli/src/commands/editor.js.map +1 -1
- package/codeyam-cli/src/commands/init.js +68 -34
- package/codeyam-cli/src/commands/init.js.map +1 -1
- package/codeyam-cli/src/data/techStacks.js +77 -0
- package/codeyam-cli/src/data/techStacks.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js +173 -0
- package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js +46 -0
- package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/devServerState.test.js +134 -0
- package/codeyam-cli/src/utils/__tests__/devServerState.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorApi.test.js +137 -0
- package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +742 -1
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js +76 -0
- package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorCapture.test.js +93 -0
- package/codeyam-cli/src/utils/__tests__/editorCapture.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js +181 -3
- package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js +124 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +223 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js +294 -0
- package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorJournal.test.js +249 -2
- package/codeyam-cli/src/utils/__tests__/editorJournal.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js +555 -0
- package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorMigration.test.js +430 -0
- package/codeyam-cli/src/utils/__tests__/editorMigration.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js +118 -1
- package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorPreview.test.js +209 -3
- package/codeyam-cli/src/utils/__tests__/editorPreview.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js +153 -0
- package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js +139 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js +221 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +1114 -2
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +280 -0
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js +66 -0
- package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js +53 -0
- package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +1829 -0
- package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js +107 -0
- package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js +129 -0
- package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js +118 -0
- package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js +227 -0
- package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js +454 -0
- package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +26 -5
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js +51 -0
- package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/webappDetection.test.js +142 -0
- package/codeyam-cli/src/utils/__tests__/webappDetection.test.js.map +1 -0
- package/codeyam-cli/src/utils/analysisRunner.js +3 -1
- package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
- package/codeyam-cli/src/utils/analyzer.js +9 -0
- package/codeyam-cli/src/utils/analyzer.js.map +1 -1
- package/codeyam-cli/src/utils/analyzerFinalization.js +100 -0
- package/codeyam-cli/src/utils/analyzerFinalization.js.map +1 -0
- package/codeyam-cli/src/utils/backgroundServer.js +94 -18
- package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/utils/database.js +37 -2
- package/codeyam-cli/src/utils/database.js.map +1 -1
- package/codeyam-cli/src/utils/devServerState.js +71 -0
- package/codeyam-cli/src/utils/devServerState.js.map +1 -0
- package/codeyam-cli/src/utils/editorApi.js +79 -0
- package/codeyam-cli/src/utils/editorApi.js.map +1 -0
- package/codeyam-cli/src/utils/editorAudit.js +135 -7
- package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
- package/codeyam-cli/src/utils/editorBroadcastViewport.js +26 -0
- package/codeyam-cli/src/utils/editorBroadcastViewport.js.map +1 -0
- package/codeyam-cli/src/utils/editorCapture.js +102 -0
- package/codeyam-cli/src/utils/editorCapture.js.map +1 -0
- package/codeyam-cli/src/utils/editorDevServer.js +100 -1
- package/codeyam-cli/src/utils/editorDevServer.js.map +1 -1
- package/codeyam-cli/src/utils/editorEntityChangeStatus.js +44 -0
- package/codeyam-cli/src/utils/editorEntityChangeStatus.js.map +1 -0
- package/codeyam-cli/src/utils/editorEntityHelpers.js +129 -0
- package/codeyam-cli/src/utils/editorEntityHelpers.js.map +1 -0
- package/codeyam-cli/src/utils/editorImageVerifier.js +155 -0
- package/codeyam-cli/src/utils/editorImageVerifier.js.map +1 -0
- package/codeyam-cli/src/utils/editorJournal.js +92 -4
- package/codeyam-cli/src/utils/editorJournal.js.map +1 -1
- package/codeyam-cli/src/utils/editorLoaderHelpers.js +140 -0
- package/codeyam-cli/src/utils/editorLoaderHelpers.js.map +1 -0
- package/codeyam-cli/src/utils/editorMigration.js +224 -0
- package/codeyam-cli/src/utils/editorMigration.js.map +1 -0
- package/codeyam-cli/src/utils/editorMockState.js +1 -1
- package/codeyam-cli/src/utils/editorPreloadHelpers.js +72 -1
- package/codeyam-cli/src/utils/editorPreloadHelpers.js.map +1 -1
- package/codeyam-cli/src/utils/editorPreview.js +72 -1
- package/codeyam-cli/src/utils/editorPreview.js.map +1 -1
- package/codeyam-cli/src/utils/editorScenarioSwitch.js +112 -0
- package/codeyam-cli/src/utils/editorScenarioSwitch.js.map +1 -0
- package/codeyam-cli/src/utils/editorScenarios.js +349 -0
- package/codeyam-cli/src/utils/editorScenarios.js.map +1 -1
- package/codeyam-cli/src/utils/editorSeedAdapter.js +352 -0
- package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -0
- package/codeyam-cli/src/utils/editorShouldRevalidate.js +21 -0
- package/codeyam-cli/src/utils/editorShouldRevalidate.js.map +1 -0
- package/codeyam-cli/src/utils/entityChangeStatus.js +360 -0
- package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -0
- package/codeyam-cli/src/utils/entityChangeStatus.server.js +196 -0
- package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -0
- package/codeyam-cli/src/utils/install-skills.js +10 -1
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/parseRegisterArg.js +31 -0
- package/codeyam-cli/src/utils/parseRegisterArg.js.map +1 -0
- package/codeyam-cli/src/utils/progress.js +2 -2
- package/codeyam-cli/src/utils/progress.js.map +1 -1
- package/codeyam-cli/src/utils/routePatternMatching.js +129 -0
- package/codeyam-cli/src/utils/routePatternMatching.js.map +1 -0
- package/codeyam-cli/src/utils/scenarioCoverage.js +74 -0
- package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -0
- package/codeyam-cli/src/utils/scenariosManifest.js +244 -0
- package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -0
- package/codeyam-cli/src/utils/serverState.js +30 -0
- package/codeyam-cli/src/utils/serverState.js.map +1 -1
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +47 -16
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
- package/codeyam-cli/src/utils/simulationGateMiddleware.js +8 -1
- package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -1
- package/codeyam-cli/src/utils/slugUtils.js +25 -0
- package/codeyam-cli/src/utils/slugUtils.js.map +1 -0
- package/codeyam-cli/src/utils/syncMocksMiddleware.js +2 -2
- package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
- package/codeyam-cli/src/utils/webappDetection.js +21 -0
- package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
- package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js +40 -0
- package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js.map +1 -0
- package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +567 -0
- package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -0
- package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js +146 -0
- package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js.map +1 -0
- package/codeyam-cli/src/webserver/app/lib/clientErrors.js +65 -0
- package/codeyam-cli/src/webserver/app/lib/clientErrors.js.map +1 -0
- package/codeyam-cli/src/webserver/app/lib/git.js +397 -0
- package/codeyam-cli/src/webserver/app/lib/git.js.map +1 -0
- package/codeyam-cli/src/webserver/app/types/editor.js +8 -0
- package/codeyam-cli/src/webserver/app/types/editor.js.map +1 -0
- package/codeyam-cli/src/webserver/backgroundServer.js +18 -4
- package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CzTDWkF2.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-C76mRRiF.js → EntityItem-BFbq6iFk.js} +5 -5
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CQgyEGV-.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-CobE682z.js → EntityTypeIcon-B6OMi58N.js} +9 -9
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-DuYodzo1.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-CXo9EeCl.js +25 -0
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DYCNb2It.js +3 -0
- package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-BU_OAEMP.js → LoadingDots-By5zI316.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-ceAyBX-H.js → LogViewer-CZgY3sxX.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-djPLI-WV.js → ReportIssueModal-CnYYwRDw.js} +4 -4
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-CDoF7ZpU.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-B76aig_2.js → ScenarioViewer-DrnfvaLL.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/Spinner-Df3UCi8k.js +34 -0
- package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CK7-NaPZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-DRKR9T0U.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{_index-C96V0n15.js → _index-ClR-g3tY.js} +4 -4
- package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BpKzcsJz.js → activity.(_tab)-DTH6ydEA.js} +8 -8
- package/codeyam-cli/src/webserver/build/client/assets/addon-canvas-DpzMmAy5.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/addon-fit-YJmn1quW.js +12 -0
- package/codeyam-cli/src/webserver/build/client/assets/{addon-web-links-Duc5hnl7.js → addon-web-links-74hnHF59.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/addon-webgl-DI8QOUvO.js +58 -0
- package/codeyam-cli/src/webserver/build/client/assets/{agent-transcripts-D9hemwl6.js → agent-transcripts-B8CYhCO9.js} +7 -7
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-diff-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-project-info-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-rename-scenario-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-seed-state-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-coverage-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-prompt-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-session-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{book-open-D_nMCFmP.js → book-open-CLaoh4ac.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-BH2h1Ea2.js → chevron-down-BZ2DZxbW.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{chunk-JZWAC4HX-C4pqxYJB.js → chunk-JZWAC4HX-BBXArFPl.js} +13 -21
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-DyIKORY6.js → circle-check-CT4unAk-.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{copy-NDbZjXao.js → copy-zK0B6Nu-.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-DJB0YQJL.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-CkXFP_i-.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor._tab-DPw7NZHc.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-y_5LB2iU.js +58 -0
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-DBa7T2FK.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-CrjR3zZW.js → entity._sha._-BqAN7hyG.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BOi8kpwd.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-Dg1NhIms.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CJX6kkkV.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-BMvVHNXU.js → entity._sha_.edit._scenarioId-BhVjZhKg.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{entry.client-DTvKq3TY.js → entry.client-_gzKltPN.js} +6 -6
- package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-Daa96Fr1.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/files-CV_17tZS.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/git-D-YXmMbR.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-BCTpZEY8.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/index-Blo6EK8G.js +15 -0
- package/codeyam-cli/src/webserver/build/client/assets/{index-10oVnAAH.js → index-BsX0F-9C.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-BcvgDzbZ.js → index-CCrgCshv.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/jsx-runtime-D_zvdyIk.js +9 -0
- package/codeyam-cli/src/webserver/build/client/assets/labs-Byazq8Pv.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BAXYRVEO.js → loader-circle-DVQ0oHR7.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/manifest-5f1c29f5.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/memory-b-VmA2Vj.js +101 -0
- package/codeyam-cli/src/webserver/build/client/assets/{pause-DTAcYxBt.js → pause-DGcndCAa.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/root-BBCQJ_ZM.js +67 -0
- package/codeyam-cli/src/webserver/build/client/assets/{search-fKo7v0Zo.js → search-C0Uw0bcK.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/settings-OoNgHIfW.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/simulations-Bcemfu8a.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{terminal-BG4heKCG.js → terminal-BgMmG7R9.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-DtSmdtM4.js → triangle-alert-Cs87hJYK.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BR3Rs7JY.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-C14nCb1q.js → useLastLogLine-BxxP_XF9.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/useReportContext-BermyNU5.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/useToast-a_QN_W9_.js +1 -0
- package/codeyam-cli/src/webserver/build/client/sound-test.html +98 -0
- package/codeyam-cli/src/webserver/build/server/assets/index-BLKsJR3o.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/init-C2iMAqYu.js +10 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-DR42Xd5a.js +489 -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/src/webserver/editorProxy.js +511 -50
- package/codeyam-cli/src/webserver/editorProxy.js.map +1 -1
- package/codeyam-cli/src/webserver/idleDetector.js +73 -0
- package/codeyam-cli/src/webserver/idleDetector.js.map +1 -0
- package/codeyam-cli/src/webserver/mockStateEvents.js +28 -0
- package/codeyam-cli/src/webserver/mockStateEvents.js.map +1 -0
- package/codeyam-cli/src/webserver/public/sound-test.html +98 -0
- package/codeyam-cli/src/webserver/scripts/codeyam-preload.mjs +242 -3
- package/codeyam-cli/src/webserver/scripts/journalCapture.ts +94 -4
- package/codeyam-cli/src/webserver/server.js +99 -16
- package/codeyam-cli/src/webserver/server.js.map +1 -1
- package/codeyam-cli/src/webserver/terminalServer.js +186 -39
- package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
- package/codeyam-cli/templates/chrome-extension-react/EXTENSION_SETUP.md +75 -0
- package/codeyam-cli/templates/chrome-extension-react/README.md +46 -0
- package/codeyam-cli/templates/chrome-extension-react/gitignore +15 -0
- package/codeyam-cli/templates/chrome-extension-react/index.html +12 -0
- package/codeyam-cli/templates/chrome-extension-react/package.json +27 -0
- package/codeyam-cli/templates/chrome-extension-react/popup.html +12 -0
- package/codeyam-cli/templates/chrome-extension-react/public/manifest.json +15 -0
- package/codeyam-cli/templates/chrome-extension-react/src/background/service-worker.ts +7 -0
- package/codeyam-cli/templates/chrome-extension-react/src/globals.css +6 -0
- package/codeyam-cli/templates/chrome-extension-react/src/lib/storage.ts +37 -0
- package/codeyam-cli/templates/chrome-extension-react/src/popup/App.tsx +12 -0
- package/codeyam-cli/templates/chrome-extension-react/src/popup/main.tsx +10 -0
- package/codeyam-cli/templates/chrome-extension-react/tsconfig.json +24 -0
- package/codeyam-cli/templates/chrome-extension-react/vite.config.ts +41 -0
- package/codeyam-cli/templates/codeyam-editor-claude.md +84 -5
- package/codeyam-cli/templates/editor-step-hook.py +188 -21
- package/codeyam-cli/templates/expo-react-native/MOBILE_SETUP.md +89 -0
- package/codeyam-cli/templates/expo-react-native/README.md +41 -0
- package/codeyam-cli/templates/expo-react-native/app/(tabs)/_layout.tsx +33 -0
- package/codeyam-cli/templates/expo-react-native/app/(tabs)/index.tsx +12 -0
- package/codeyam-cli/templates/expo-react-native/app/(tabs)/settings.tsx +12 -0
- package/codeyam-cli/templates/expo-react-native/app/_layout.tsx +12 -0
- package/codeyam-cli/templates/expo-react-native/app.json +18 -0
- package/codeyam-cli/templates/expo-react-native/babel.config.js +9 -0
- package/codeyam-cli/templates/expo-react-native/gitignore +12 -0
- package/codeyam-cli/templates/expo-react-native/global.css +3 -0
- package/codeyam-cli/templates/expo-react-native/lib/storage.ts +32 -0
- package/codeyam-cli/templates/expo-react-native/metro.config.js +6 -0
- package/codeyam-cli/templates/expo-react-native/nativewind-env.d.ts +1 -0
- package/codeyam-cli/templates/expo-react-native/package.json +38 -0
- package/codeyam-cli/templates/expo-react-native/tailwind.config.js +10 -0
- package/codeyam-cli/templates/expo-react-native/tsconfig.json +10 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_PATTERNS.md +308 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_UPGRADE.md +304 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/DATABASE.md +126 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/FEATURE_PATTERNS.md +37 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/README.md +53 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/codeyam-isolate/layout.tsx +12 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +9 -4
- package/codeyam-cli/templates/nextjs-prisma-sqlite/env +4 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/gitignore +21 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +5 -1
- package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +4 -1
- package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +127 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/vitest.config.ts +13 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/README.md +52 -0
- package/codeyam-cli/templates/{nextjs-prisma-sqlite/PRISMA_SETUP.md → nextjs-prisma-supabase/SUPABASE_SETUP.md} +37 -17
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/api/todos/route.ts +17 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/globals.css +26 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/layout.tsx +34 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/prisma.ts +20 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/supabase.ts +12 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/app/page.tsx +10 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/env +9 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/eslint.config.mjs +11 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/gitignore +40 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/next.config.ts +11 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/package.json +37 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/postcss.config.mjs +7 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/schema.prisma +27 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/seed.ts +39 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/prisma.config.ts +12 -0
- package/codeyam-cli/templates/nextjs-prisma-supabase/tsconfig.json +34 -0
- package/codeyam-cli/templates/seed-adapters/supabase.ts +282 -0
- package/codeyam-cli/templates/skills/codeyam-dev-mode/SKILL.md +2 -2
- package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +159 -17
- package/codeyam-cli/templates/skills/codeyam-memory/SKILL.md +10 -10
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/detect-deprecated-patterns.mjs +139 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/find-exports.mjs +52 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/read-json-field.mjs +61 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/ripgrep-fallback.mjs +155 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/cleanup.mjs +13 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/filter-session.mjs +95 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/preprocess.mjs +160 -0
- package/package.json +15 -10
- package/packages/ai/src/lib/generateExecutionFlows.js +0 -11
- package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
- package/packages/analyze/src/lib/ProjectAnalyzer.js +10 -4
- package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
- package/packages/analyze/src/lib/asts/index.js +4 -2
- package/packages/analyze/src/lib/asts/index.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +0 -40
- package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +92 -0
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
- package/packages/database/src/lib/loadEntities.js +0 -6
- package/packages/database/src/lib/loadEntities.js.map +1 -1
- package/packages/database/src/lib/updateCommitMetadata.js +0 -25
- package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/packages/types/src/enums/ProjectFramework.js +2 -0
- package/packages/types/src/enums/ProjectFramework.js.map +1 -1
- package/scripts/npm-post-install.cjs +22 -0
- package/codeyam-cli/src/webserver/build/client/assets/CopyButton-DmJveP3T.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-g3saevPb.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-DYFW3lDD.js +0 -25
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DLeucoVX.js +0 -3
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-BED4B6sP.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +0 -34
- package/codeyam-cli/src/webserver/build/client/assets/Terminal-wkqC0AQk.js +0 -41
- package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-C8OKAR5x.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/addon-fit-CUXOrorO.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-CMT1jU2q.js +0 -21
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BiM6z3Do.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/editor-CdjF_fX6.js +0 -8
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-D8ILZMR0.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-C28BiQzt.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-cPo8LiG3.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/files-DO4CZ16O.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/git-CFCTYk9I.js +0 -15
- package/codeyam-cli/src/webserver/build/client/assets/globals-B17TBSS6.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/labs-Zk7ryIM1.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-b8fd6b07.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/memory-FweZHj5U.js +0 -93
- package/codeyam-cli/src/webserver/build/client/assets/root-DUKqhFlb.js +0 -67
- package/codeyam-cli/src/webserver/build/client/assets/settings-DfuTtcJP.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/simulations-B3aOzpCZ.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-ByhSyh0W.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useReportContext-O-jkvSPx.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useToast-9FIWuYfK.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/index-BLhjL9Xi.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-DyMuI5mU.js +0 -363
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/detect-deprecated-patterns.sh +0 -108
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/find-exports.sh +0 -69
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/cleanup.sh +0 -12
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/filter.jq +0 -45
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/preprocess.sh +0 -139
|
@@ -4,10 +4,149 @@ import fs from 'fs';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { getProjectRoot } from "../state.js";
|
|
6
6
|
import { createMockStateManager, } from "../utils/editorMockState.js";
|
|
7
|
+
import { computeEditorPorts } from "../utils/editorDevServer.js";
|
|
8
|
+
import { mockStateEventEmitter } from "./mockStateEvents.js";
|
|
9
|
+
/**
|
|
10
|
+
* Normalize a target URL by stripping trailing slashes for consistency.
|
|
11
|
+
*
|
|
12
|
+
* Previously this also replaced `localhost` with `127.0.0.1`, but that broke
|
|
13
|
+
* forwarding to dev servers that bind to IPv6 only (e.g. Vite 6 on macOS
|
|
14
|
+
* binds to `[::1]`). The hostname is now left as-is — `resolveLoopbackAddress`
|
|
15
|
+
* probes the actual target at startup to pick the right address.
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeTargetUrl(url) {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = new URL(url);
|
|
20
|
+
return parsed.toString().replace(/\/$/, '');
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Probe a localhost port to determine the correct loopback address.
|
|
28
|
+
* Dev servers may bind to IPv4 (127.0.0.1), IPv6 (::1), or both.
|
|
29
|
+
* Returns the first address that accepts a TCP connection.
|
|
30
|
+
*/
|
|
31
|
+
export async function resolveLoopbackAddress(port) {
|
|
32
|
+
const candidates = ['127.0.0.1', '::1'];
|
|
33
|
+
for (const host of candidates) {
|
|
34
|
+
try {
|
|
35
|
+
const connected = await new Promise((resolve) => {
|
|
36
|
+
const socket = new net.Socket();
|
|
37
|
+
socket.setTimeout(1000);
|
|
38
|
+
socket.once('connect', () => {
|
|
39
|
+
socket.destroy();
|
|
40
|
+
resolve(true);
|
|
41
|
+
});
|
|
42
|
+
socket.once('error', () => {
|
|
43
|
+
socket.destroy();
|
|
44
|
+
resolve(false);
|
|
45
|
+
});
|
|
46
|
+
socket.once('timeout', () => {
|
|
47
|
+
socket.destroy();
|
|
48
|
+
resolve(false);
|
|
49
|
+
});
|
|
50
|
+
socket.connect(port, host);
|
|
51
|
+
});
|
|
52
|
+
if (connected) {
|
|
53
|
+
return host;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Try next candidate
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
7
62
|
// Global key so the proxy survives HMR
|
|
8
63
|
const GLOBAL_KEY = '__codeyam_editor_proxy__';
|
|
64
|
+
// ─── Live Preview Health ─────────────────────────────────────────────
|
|
65
|
+
const PREVIEW_HEALTH_KEY = '__codeyam_preview_health__';
|
|
66
|
+
function getPreviewHealth() {
|
|
67
|
+
return globalThis[PREVIEW_HEALTH_KEY] ?? null;
|
|
68
|
+
}
|
|
69
|
+
function setPreviewHealth(report) {
|
|
70
|
+
globalThis[PREVIEW_HEALTH_KEY] = report;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the current live preview health report (read by API endpoint).
|
|
74
|
+
*/
|
|
75
|
+
export function getPreviewHealthReport() {
|
|
76
|
+
return getPreviewHealth();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reset preview health state (called when a new HTML page is served).
|
|
80
|
+
*/
|
|
81
|
+
export function resetPreviewHealth() {
|
|
82
|
+
setPreviewHealth(null);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Error-catching script injected into HTML responses.
|
|
86
|
+
* Uses vanilla JS for maximum compatibility.
|
|
87
|
+
*/
|
|
88
|
+
export const PREVIEW_HEALTH_SCRIPT = `<script data-codeyam-health>
|
|
89
|
+
(function() {
|
|
90
|
+
var errors = [];
|
|
91
|
+
var reported = false;
|
|
92
|
+
function report(type, msg, stack) {
|
|
93
|
+
errors.push({ type: type, message: msg, stack: stack, timestamp: Date.now() });
|
|
94
|
+
if (!reported) {
|
|
95
|
+
reported = true;
|
|
96
|
+
setTimeout(function() { flush(); }, 500);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function flush() {
|
|
100
|
+
fetch('/__codeyam__/preview-health', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: { 'Content-Type': 'application/json' },
|
|
103
|
+
body: JSON.stringify({ errors: errors, url: location.href })
|
|
104
|
+
}).catch(function(){});
|
|
105
|
+
reported = false;
|
|
106
|
+
errors = [];
|
|
107
|
+
}
|
|
108
|
+
window.addEventListener('error', function(e) {
|
|
109
|
+
report('error', e.message, e.error && e.error.stack);
|
|
110
|
+
});
|
|
111
|
+
window.addEventListener('unhandledrejection', function(e) {
|
|
112
|
+
report('unhandledrejection', String(e.reason), e.reason && e.reason.stack);
|
|
113
|
+
});
|
|
114
|
+
var origError = console.error;
|
|
115
|
+
console.error = function() {
|
|
116
|
+
report('console.error', Array.prototype.join.call(arguments, ' '));
|
|
117
|
+
origError.apply(console, arguments);
|
|
118
|
+
};
|
|
119
|
+
window.addEventListener('load', function() {
|
|
120
|
+
setTimeout(function() {
|
|
121
|
+
var hasContent = document.body && document.body.innerText.trim().length > 0;
|
|
122
|
+
fetch('/__codeyam__/preview-health', {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
headers: { 'Content-Type': 'application/json' },
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
loaded: true,
|
|
127
|
+
hasContent: hasContent,
|
|
128
|
+
url: location.href,
|
|
129
|
+
errorCount: errors.length
|
|
130
|
+
})
|
|
131
|
+
}).catch(function(){});
|
|
132
|
+
}, 1000);
|
|
133
|
+
});
|
|
134
|
+
})();
|
|
135
|
+
</script>`;
|
|
9
136
|
const CACHE_TTL_MS = 500;
|
|
10
137
|
let scenarioCache = { data: null, timestamp: 0 };
|
|
138
|
+
// Session config extracted from the active scenario — drives cookie injection
|
|
139
|
+
let sessionConfig = undefined;
|
|
140
|
+
/** Session cookies from the seed adapter (e.g. Supabase auth tokens). */
|
|
141
|
+
let seedSessionCookies = undefined;
|
|
142
|
+
// localStorage config extracted from the active scenario — drives HTML injection
|
|
143
|
+
let localStorageConfig = null;
|
|
144
|
+
// Active scenario ID — used to gate localStorage seeding (only re-seed on switch)
|
|
145
|
+
let activeScenarioId = null;
|
|
146
|
+
// Prototype ID — used to gate a one-time localStorage.clear() when a new project is scaffolded
|
|
147
|
+
let currentPrototypeId = null;
|
|
148
|
+
// Current scenario type — 'application'/'user' for seed-based, 'component' for mock-based
|
|
149
|
+
let currentScenarioType = null;
|
|
11
150
|
// Max body size to buffer for mock matching (10MB)
|
|
12
151
|
const MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
13
152
|
function getProxyState() {
|
|
@@ -38,6 +177,12 @@ export function getProxyUrl() {
|
|
|
38
177
|
/**
|
|
39
178
|
* Read the active scenario's mock data from disk, with brief caching.
|
|
40
179
|
* Feeds the data into the MockStateManager.
|
|
180
|
+
*
|
|
181
|
+
* For application/user scenarios (type-aware): only loads `externalApis`
|
|
182
|
+
* into the mock state manager. All DB-backed routes flow through to the
|
|
183
|
+
* real app (database is seeded with real data).
|
|
184
|
+
*
|
|
185
|
+
* For component scenarios (or legacy): loads all routes as before.
|
|
41
186
|
*/
|
|
42
187
|
function readScenarioData() {
|
|
43
188
|
const now = Date.now();
|
|
@@ -55,6 +200,8 @@ function readScenarioData() {
|
|
|
55
200
|
const active = JSON.parse(fs.readFileSync(activeScenarioPath, 'utf-8'));
|
|
56
201
|
const scenarioId = active.scenarioId;
|
|
57
202
|
if (!scenarioId) {
|
|
203
|
+
// No active scenario — but may have a prototypeId for localStorage clearing
|
|
204
|
+
currentPrototypeId = active.prototypeId || null;
|
|
58
205
|
scenarioCache = { data: null, timestamp: now };
|
|
59
206
|
return null;
|
|
60
207
|
}
|
|
@@ -64,11 +211,37 @@ function readScenarioData() {
|
|
|
64
211
|
scenarioCache = { data: null, timestamp: now };
|
|
65
212
|
return null;
|
|
66
213
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
214
|
+
const rawData = JSON.parse(fs.readFileSync(dataFilePath, 'utf-8'));
|
|
215
|
+
// Extract session config for cookie injection
|
|
216
|
+
sessionConfig = rawData.session || null;
|
|
217
|
+
// Extract seed adapter session cookies (e.g. Supabase auth)
|
|
218
|
+
seedSessionCookies = rawData.sessionCookies || undefined;
|
|
219
|
+
// Extract localStorage config for HTML injection
|
|
220
|
+
localStorageConfig = rawData.localStorage || null;
|
|
221
|
+
activeScenarioId = scenarioId;
|
|
222
|
+
// Type-aware: for seed-based scenarios, only serve externalApis via proxy
|
|
223
|
+
const scenarioType = active.type || rawData.type || null;
|
|
224
|
+
currentScenarioType = scenarioType;
|
|
225
|
+
let mockData;
|
|
226
|
+
if ((scenarioType === 'application' || scenarioType === 'user') &&
|
|
227
|
+
rawData.seed) {
|
|
228
|
+
// Seed-based scenario: only load externalApis as routes for the proxy
|
|
229
|
+
if (rawData.externalApis && typeof rawData.externalApis === 'object') {
|
|
230
|
+
mockData = { routes: rawData.externalApis };
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// No external APIs — proxy passes everything through
|
|
234
|
+
mockData = {};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// Component/legacy scenario: load all data
|
|
239
|
+
mockData = rawData;
|
|
240
|
+
}
|
|
241
|
+
scenarioCache = { data: mockData, timestamp: now };
|
|
69
242
|
// Feed into mock state manager (smart reload handles dedup)
|
|
70
|
-
getMockStateManager().loadScenario(
|
|
71
|
-
return
|
|
243
|
+
getMockStateManager().loadScenario(mockData);
|
|
244
|
+
return mockData;
|
|
72
245
|
}
|
|
73
246
|
catch (err) {
|
|
74
247
|
console.warn('[editorProxy] Error reading scenario data:', err);
|
|
@@ -76,39 +249,6 @@ function readScenarioData() {
|
|
|
76
249
|
return null;
|
|
77
250
|
}
|
|
78
251
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Find a matching route in the scenario data.
|
|
81
|
-
*
|
|
82
|
-
* Supports two formats:
|
|
83
|
-
* - New route-keyed: { "routes": { "/api/drinks": { "body": [...] } } }
|
|
84
|
-
* - Legacy key-based: { "drinks": [...] } → matches /api/drinks
|
|
85
|
-
*
|
|
86
|
-
* @deprecated Use MockStateManager.matchRequest() instead for method-aware matching.
|
|
87
|
-
*/
|
|
88
|
-
export function findMatchingRoute(pathname, scenarioData) {
|
|
89
|
-
// New format: check routes map
|
|
90
|
-
const routes = scenarioData.routes;
|
|
91
|
-
if (routes && typeof routes === 'object') {
|
|
92
|
-
const routeEntry = routes[pathname];
|
|
93
|
-
if (routeEntry && typeof routeEntry === 'object') {
|
|
94
|
-
const entry = routeEntry;
|
|
95
|
-
return {
|
|
96
|
-
body: entry.body ?? routeEntry,
|
|
97
|
-
status: typeof entry.status === 'number' ? entry.status : 200,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// Legacy format: key "drinks" matches "/api/drinks"
|
|
102
|
-
// Extract the last segment of the path after /api/
|
|
103
|
-
const apiMatch = pathname.match(/^\/api\/(.+)$/);
|
|
104
|
-
if (apiMatch) {
|
|
105
|
-
const key = apiMatch[1];
|
|
106
|
-
if (key in scenarioData && key !== 'routes') {
|
|
107
|
-
return { body: scenarioData[key], status: 200 };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
252
|
/**
|
|
113
253
|
* Buffer the request body, up to MAX_BODY_SIZE.
|
|
114
254
|
* Returns null if the body exceeds the limit.
|
|
@@ -137,26 +277,67 @@ function bufferRequestBody(req) {
|
|
|
137
277
|
});
|
|
138
278
|
});
|
|
139
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Strip IPv6 bracket notation for use with http.request hostname.
|
|
282
|
+
* URL.hostname returns `[::1]` for IPv6 but http.request needs `::1`.
|
|
283
|
+
*/
|
|
284
|
+
function stripIPv6Brackets(hostname) {
|
|
285
|
+
if (hostname.startsWith('[') && hostname.endsWith(']')) {
|
|
286
|
+
return hostname.slice(1, -1);
|
|
287
|
+
}
|
|
288
|
+
return hostname;
|
|
289
|
+
}
|
|
140
290
|
/**
|
|
141
291
|
* Forward a buffered request to the target dev server.
|
|
142
292
|
* Unlike the streaming forwardRequest, this replays a buffered body.
|
|
143
293
|
*/
|
|
144
294
|
function forwardBufferedRequest(req, res, targetUrl, bodyBuffer) {
|
|
145
295
|
const target = new URL(targetUrl);
|
|
296
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
146
297
|
const headers = { ...req.headers, host: `${target.hostname}:${target.port}` };
|
|
298
|
+
// Remove accept-encoding so the dev server returns uncompressed responses.
|
|
299
|
+
// The proxy injects a health script into HTML — this fails on compressed bodies.
|
|
300
|
+
delete headers['accept-encoding'];
|
|
147
301
|
// Update content-length if we have the body buffer
|
|
148
302
|
if (bodyBuffer) {
|
|
149
303
|
headers['content-length'] = String(bodyBuffer.length);
|
|
150
304
|
}
|
|
151
305
|
const options = {
|
|
152
|
-
hostname
|
|
306
|
+
hostname,
|
|
153
307
|
port: target.port,
|
|
154
308
|
path: req.url,
|
|
155
309
|
method: req.method,
|
|
156
310
|
headers,
|
|
157
311
|
};
|
|
158
312
|
const proxyReq = http.request(options, (proxyRes) => {
|
|
159
|
-
|
|
313
|
+
const status = proxyRes.statusCode || 200;
|
|
314
|
+
if (status >= 400) {
|
|
315
|
+
console.warn(`[editorProxy] Target returned ${status} for ${req.method} ${req.url}`);
|
|
316
|
+
}
|
|
317
|
+
const headers = { ...proxyRes.headers };
|
|
318
|
+
injectSessionCookie(headers);
|
|
319
|
+
// Check if response is HTML — if so, buffer and inject health script
|
|
320
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
321
|
+
if (contentType.includes('text/html')) {
|
|
322
|
+
resetPreviewHealth();
|
|
323
|
+
const chunks = [];
|
|
324
|
+
proxyRes.on('data', (chunk) => chunks.push(chunk));
|
|
325
|
+
proxyRes.on('end', () => {
|
|
326
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
327
|
+
const lsScript = buildLocalStorageScript(localStorageConfig, activeScenarioId || '', currentPrototypeId);
|
|
328
|
+
const injected = injectHealthScript(body, lsScript);
|
|
329
|
+
delete headers['content-length'];
|
|
330
|
+
delete headers['content-encoding'];
|
|
331
|
+
// Prevent browser from caching HTML responses — scenario switches
|
|
332
|
+
// serve different content from the same URL (seed data changes the
|
|
333
|
+
// rendered page but the proxy URL stays the same).
|
|
334
|
+
headers['cache-control'] = 'no-store, must-revalidate';
|
|
335
|
+
res.writeHead(status, headers);
|
|
336
|
+
res.end(injected);
|
|
337
|
+
});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
res.writeHead(status, headers);
|
|
160
341
|
proxyRes.pipe(res, { end: true });
|
|
161
342
|
});
|
|
162
343
|
proxyReq.on('error', (err) => {
|
|
@@ -174,19 +355,58 @@ function forwardBufferedRequest(req, res, targetUrl, bodyBuffer) {
|
|
|
174
355
|
}
|
|
175
356
|
}
|
|
176
357
|
/**
|
|
177
|
-
* Forward an HTTP request to the target dev server
|
|
358
|
+
* Forward an HTTP request to the target dev server.
|
|
359
|
+
* For HTML responses: buffers body to inject health-check script.
|
|
360
|
+
* For non-HTML responses: pipes directly (no buffering).
|
|
178
361
|
*/
|
|
179
362
|
function forwardRequest(req, res, targetUrl) {
|
|
180
363
|
const target = new URL(targetUrl);
|
|
364
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
365
|
+
// Build headers, stripping accept-encoding so the dev server returns uncompressed
|
|
366
|
+
// responses. The proxy injects a health script into HTML — this fails on compressed bodies.
|
|
367
|
+
const { 'accept-encoding': _ae, ...forwardHeaders } = req.headers;
|
|
181
368
|
const options = {
|
|
182
|
-
hostname
|
|
369
|
+
hostname,
|
|
183
370
|
port: target.port,
|
|
184
371
|
path: req.url,
|
|
185
372
|
method: req.method,
|
|
186
|
-
headers: {
|
|
373
|
+
headers: {
|
|
374
|
+
...forwardHeaders,
|
|
375
|
+
host: `${target.hostname}:${target.port}`,
|
|
376
|
+
},
|
|
187
377
|
};
|
|
188
378
|
const proxyReq = http.request(options, (proxyRes) => {
|
|
189
|
-
|
|
379
|
+
const status = proxyRes.statusCode || 200;
|
|
380
|
+
if (status >= 400) {
|
|
381
|
+
console.warn(`[editorProxy] Target returned ${status} for ${req.method} ${req.url}`);
|
|
382
|
+
}
|
|
383
|
+
const headers = { ...proxyRes.headers };
|
|
384
|
+
injectSessionCookie(headers);
|
|
385
|
+
// Check if response is HTML — if so, buffer and inject health script
|
|
386
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
387
|
+
if (contentType.includes('text/html')) {
|
|
388
|
+
// Reset health state for new page loads
|
|
389
|
+
resetPreviewHealth();
|
|
390
|
+
const chunks = [];
|
|
391
|
+
proxyRes.on('data', (chunk) => chunks.push(chunk));
|
|
392
|
+
proxyRes.on('end', () => {
|
|
393
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
394
|
+
const lsScript = buildLocalStorageScript(localStorageConfig, activeScenarioId || '', currentPrototypeId);
|
|
395
|
+
const injected = injectHealthScript(body, lsScript);
|
|
396
|
+
// Remove content-length since body size changed; use chunked transfer
|
|
397
|
+
delete headers['content-length'];
|
|
398
|
+
// Remove content-encoding since we're serving uncompressed
|
|
399
|
+
delete headers['content-encoding'];
|
|
400
|
+
// Prevent browser from caching HTML responses — scenario switches
|
|
401
|
+
// serve different content from the same URL (seed data changes the
|
|
402
|
+
// rendered page but the proxy URL stays the same).
|
|
403
|
+
headers['cache-control'] = 'no-store, must-revalidate';
|
|
404
|
+
res.writeHead(status, headers);
|
|
405
|
+
res.end(injected);
|
|
406
|
+
});
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
res.writeHead(status, headers);
|
|
190
410
|
proxyRes.pipe(res, { end: true });
|
|
191
411
|
});
|
|
192
412
|
proxyReq.on('error', (err) => {
|
|
@@ -198,14 +418,176 @@ function forwardRequest(req, res, targetUrl) {
|
|
|
198
418
|
});
|
|
199
419
|
req.pipe(proxyReq, { end: true });
|
|
200
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Inject or clear the session-token cookie on proxied responses.
|
|
423
|
+
* When a scenario has session.cookieValue, sets the cookie to auto-log the user in.
|
|
424
|
+
* When a scenario has no session field (null), clears any existing session cookie.
|
|
425
|
+
* When sessionConfig is undefined (no scenario loaded yet), does nothing.
|
|
426
|
+
*/
|
|
427
|
+
function injectSessionCookie(headers) {
|
|
428
|
+
const cookies = [];
|
|
429
|
+
// Dev auth cookie (built-in session-token)
|
|
430
|
+
if (sessionConfig !== undefined) {
|
|
431
|
+
if (sessionConfig?.cookieValue) {
|
|
432
|
+
cookies.push(`session-token=${sessionConfig.cookieValue}; Path=/; SameSite=Lax`);
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
cookies.push(`session-token=; Path=/; Max-Age=0`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
// Seed adapter session cookies (e.g. Supabase auth tokens)
|
|
439
|
+
if (seedSessionCookies && seedSessionCookies.length > 0) {
|
|
440
|
+
for (const sc of seedSessionCookies) {
|
|
441
|
+
const cookiePath = sc.path || '/';
|
|
442
|
+
const sameSite = sc.sameSite || 'Lax';
|
|
443
|
+
cookies.push(`${sc.name}=${sc.value}; Path=${cookiePath}; SameSite=${sameSite}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (cookies.length === 0)
|
|
447
|
+
return;
|
|
448
|
+
const existing = headers['set-cookie'];
|
|
449
|
+
if (existing) {
|
|
450
|
+
headers['set-cookie'] = [
|
|
451
|
+
...(Array.isArray(existing) ? existing : [existing]),
|
|
452
|
+
...cookies,
|
|
453
|
+
];
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
headers['set-cookie'] = cookies;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Get the current session config (for testing).
|
|
461
|
+
*/
|
|
462
|
+
export function getSessionConfig() {
|
|
463
|
+
return sessionConfig;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Get the current localStorage config (for testing and script generation).
|
|
467
|
+
*/
|
|
468
|
+
export function getLocalStorageConfig() {
|
|
469
|
+
return localStorageConfig;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Get the active scenario ID (for testing and script generation).
|
|
473
|
+
*/
|
|
474
|
+
export function getActiveScenarioId() {
|
|
475
|
+
return activeScenarioId;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Get the current prototype ID (for testing).
|
|
479
|
+
*/
|
|
480
|
+
export function getCurrentPrototypeId() {
|
|
481
|
+
return currentPrototypeId;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Build a script tag that seeds localStorage with scenario data on first load.
|
|
485
|
+
* Gated by scenario ID — only seeds when the scenario changes, preserving
|
|
486
|
+
* interactive modifications across page reloads / HMR.
|
|
487
|
+
*
|
|
488
|
+
* Returns empty string if no localStorage config is provided.
|
|
489
|
+
*/
|
|
490
|
+
export function buildLocalStorageScript(localStorageConfig, scenarioId, prototypeId) {
|
|
491
|
+
// null/undefined means no localStorage config at all — but if we have a
|
|
492
|
+
// prototypeId, emit a one-time localStorage.clear() to flush stale data
|
|
493
|
+
// from a previous prototype session.
|
|
494
|
+
if (!localStorageConfig || typeof localStorageConfig !== 'object') {
|
|
495
|
+
if (prototypeId) {
|
|
496
|
+
return `<script data-codeyam-ls>
|
|
497
|
+
(function() {
|
|
498
|
+
if (localStorage.getItem('__codeyam_proto__') === ${JSON.stringify(prototypeId)}) return;
|
|
499
|
+
localStorage.clear();
|
|
500
|
+
localStorage.setItem('__codeyam_proto__', ${JSON.stringify(prototypeId)});
|
|
501
|
+
})();
|
|
502
|
+
</script>`;
|
|
503
|
+
}
|
|
504
|
+
return '';
|
|
505
|
+
}
|
|
506
|
+
// Even an empty object needs a cleanup script — switching from a scenario
|
|
507
|
+
// with localStorage data to one without must clear the previous keys.
|
|
508
|
+
const entries = Object.entries(localStorageConfig);
|
|
509
|
+
const keys = entries.map(([k]) => k);
|
|
510
|
+
// Build setItem calls — stringify non-string values
|
|
511
|
+
const setStatements = entries
|
|
512
|
+
.map(([key, value]) => {
|
|
513
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
|
514
|
+
return `localStorage.setItem(${JSON.stringify(key)}, ${JSON.stringify(serialized)});`;
|
|
515
|
+
})
|
|
516
|
+
.join('\n');
|
|
517
|
+
return `<script data-codeyam-ls>
|
|
518
|
+
(function() {
|
|
519
|
+
if (localStorage.getItem('__codeyam_ls_sid__') === ${JSON.stringify(scenarioId)}) return;
|
|
520
|
+
var prev = JSON.parse(localStorage.getItem('__codeyam_ls_keys__') || '[]');
|
|
521
|
+
for (var i = 0; i < prev.length; i++) localStorage.removeItem(prev[i]);
|
|
522
|
+
${setStatements}
|
|
523
|
+
localStorage.setItem('__codeyam_ls_keys__', ${JSON.stringify(JSON.stringify(keys))});
|
|
524
|
+
localStorage.setItem('__codeyam_ls_sid__', ${JSON.stringify(scenarioId)});
|
|
525
|
+
})();
|
|
526
|
+
</script>`;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Inject the health-check script (and optional localStorage script) into an HTML response body.
|
|
530
|
+
* Inserts before </head> if present, otherwise before </body>, otherwise appends.
|
|
531
|
+
* When a localStorageScript is provided, it's injected BEFORE the health script
|
|
532
|
+
* so localStorage is populated before the app loads.
|
|
533
|
+
*/
|
|
534
|
+
export function injectHealthScript(html, localStorageScript) {
|
|
535
|
+
const scripts = (localStorageScript || '') + PREVIEW_HEALTH_SCRIPT;
|
|
536
|
+
if (html.includes('</head>')) {
|
|
537
|
+
return html.replace('</head>', scripts + '</head>');
|
|
538
|
+
}
|
|
539
|
+
if (html.includes('</body>')) {
|
|
540
|
+
return html.replace('</body>', scripts + '</body>');
|
|
541
|
+
}
|
|
542
|
+
return html + scripts;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Handle POST /__codeyam__/preview-health — store health data in globalThis.
|
|
546
|
+
*/
|
|
547
|
+
function handlePreviewHealthPost(req, res) {
|
|
548
|
+
const chunks = [];
|
|
549
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
550
|
+
req.on('end', () => {
|
|
551
|
+
try {
|
|
552
|
+
const body = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
553
|
+
const current = getPreviewHealth() || {
|
|
554
|
+
errors: [],
|
|
555
|
+
loaded: false,
|
|
556
|
+
hasContent: false,
|
|
557
|
+
url: '',
|
|
558
|
+
lastUpdated: 0,
|
|
559
|
+
};
|
|
560
|
+
if (body.errors && Array.isArray(body.errors)) {
|
|
561
|
+
current.errors = current.errors.concat(body.errors);
|
|
562
|
+
}
|
|
563
|
+
if (body.loaded !== undefined) {
|
|
564
|
+
current.loaded = body.loaded;
|
|
565
|
+
}
|
|
566
|
+
if (body.hasContent !== undefined) {
|
|
567
|
+
current.hasContent = body.hasContent;
|
|
568
|
+
}
|
|
569
|
+
if (body.url) {
|
|
570
|
+
current.url = body.url;
|
|
571
|
+
}
|
|
572
|
+
current.lastUpdated = Date.now();
|
|
573
|
+
setPreviewHealth(current);
|
|
574
|
+
}
|
|
575
|
+
catch {
|
|
576
|
+
// Ignore malformed JSON
|
|
577
|
+
}
|
|
578
|
+
res.writeHead(204);
|
|
579
|
+
res.end();
|
|
580
|
+
});
|
|
581
|
+
}
|
|
201
582
|
/**
|
|
202
583
|
* Handle WebSocket upgrade by piping to the target dev server.
|
|
203
584
|
*/
|
|
204
585
|
function handleUpgrade(req, socket, head, targetUrl) {
|
|
205
586
|
const target = new URL(targetUrl);
|
|
587
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
206
588
|
const port = parseInt(target.port, 10) || 80;
|
|
207
|
-
console.log(`[editorProxy] WebSocket upgrade: ${req.url} → ${
|
|
208
|
-
const proxySocket = net.connect(port,
|
|
589
|
+
console.log(`[editorProxy] WebSocket upgrade: ${req.url} → ${hostname}:${port}`);
|
|
590
|
+
const proxySocket = net.connect(port, hostname, () => {
|
|
209
591
|
// Reconstruct the HTTP upgrade request
|
|
210
592
|
const requestLine = `${req.method} ${req.url} HTTP/${req.httpVersion}\r\n`;
|
|
211
593
|
const headers = Object.entries(req.headers)
|
|
@@ -267,10 +649,34 @@ function removeProxyConfig() {
|
|
|
267
649
|
* Supports all HTTP methods (GET, POST, PUT, DELETE, PATCH) with body buffering.
|
|
268
650
|
*/
|
|
269
651
|
export async function startEditorProxy(options) {
|
|
270
|
-
//
|
|
652
|
+
// If proxy is already running, reuse it (prevents second tab from killing first tab's proxy)
|
|
653
|
+
const existing = getProxyState();
|
|
654
|
+
if (existing) {
|
|
655
|
+
console.log(`[editorProxy] Proxy already running on port ${existing.port} → ${existing.targetUrl}`);
|
|
656
|
+
return { port: existing.port };
|
|
657
|
+
}
|
|
658
|
+
// Stop any leftover state (shouldn't happen, but defensive)
|
|
271
659
|
await stopEditorProxy();
|
|
272
|
-
|
|
660
|
+
let targetUrl = normalizeTargetUrl(options.targetUrl);
|
|
273
661
|
let port = options.port;
|
|
662
|
+
// When the target is localhost, probe to find the correct loopback address.
|
|
663
|
+
// Dev servers may bind to IPv4 (127.0.0.1) or IPv6 (::1) — Vite 6 on macOS
|
|
664
|
+
// binds to ::1 by default. We need to match the actual binding.
|
|
665
|
+
try {
|
|
666
|
+
const parsed = new URL(targetUrl);
|
|
667
|
+
if (parsed.hostname === 'localhost') {
|
|
668
|
+
const targetPort = parseInt(parsed.port || '80', 10);
|
|
669
|
+
const resolvedHost = await resolveLoopbackAddress(targetPort);
|
|
670
|
+
if (resolvedHost) {
|
|
671
|
+
parsed.hostname = resolvedHost;
|
|
672
|
+
targetUrl = parsed.toString().replace(/\/$/, '');
|
|
673
|
+
console.log(`[editorProxy] Resolved localhost to ${resolvedHost} for port ${targetPort}`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
catch {
|
|
678
|
+
// Keep original targetUrl
|
|
679
|
+
}
|
|
274
680
|
console.log(`[editorProxy] Starting proxy (requested port ${port}, target ${targetUrl})`);
|
|
275
681
|
const mockState = getMockStateManager();
|
|
276
682
|
const server = http.createServer((req, res) => {
|
|
@@ -289,6 +695,11 @@ export async function startEditorProxy(options) {
|
|
|
289
695
|
res.end();
|
|
290
696
|
return;
|
|
291
697
|
}
|
|
698
|
+
// Intercept preview health reports from the injected script
|
|
699
|
+
if (method === 'POST' && pathname === '/__codeyam__/preview-health') {
|
|
700
|
+
handlePreviewHealthPost(req, res);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
292
703
|
// Load scenario data (also feeds MockStateManager)
|
|
293
704
|
readScenarioData();
|
|
294
705
|
// For methods that may carry a body, buffer it first
|
|
@@ -320,11 +731,17 @@ export async function startEditorProxy(options) {
|
|
|
320
731
|
'Content-Type': 'application/json',
|
|
321
732
|
'Access-Control-Allow-Origin': '*',
|
|
322
733
|
'X-CodeYam-Proxy': 'scenario-data',
|
|
734
|
+
'Cache-Control': 'no-store',
|
|
323
735
|
});
|
|
324
736
|
res.end(match.body != null ? JSON.stringify(match.body) : '');
|
|
325
737
|
return;
|
|
326
738
|
}
|
|
327
739
|
// No mock match — forward with buffered body
|
|
740
|
+
if ((currentScenarioType === 'application' ||
|
|
741
|
+
currentScenarioType === 'user') &&
|
|
742
|
+
pathname.startsWith('/api/')) {
|
|
743
|
+
mockStateEventEmitter.emitDataMutationForwarded(method, pathname);
|
|
744
|
+
}
|
|
328
745
|
forwardBufferedRequest(req, res, targetUrl, bodyBuffer);
|
|
329
746
|
return;
|
|
330
747
|
}
|
|
@@ -336,6 +753,7 @@ export async function startEditorProxy(options) {
|
|
|
336
753
|
'Content-Type': 'application/json',
|
|
337
754
|
'Access-Control-Allow-Origin': '*',
|
|
338
755
|
'X-CodeYam-Proxy': 'scenario-data',
|
|
756
|
+
'Cache-Control': 'no-store',
|
|
339
757
|
});
|
|
340
758
|
res.end(match.body != null ? JSON.stringify(match.body) : '');
|
|
341
759
|
return;
|
|
@@ -360,7 +778,10 @@ export async function startEditorProxy(options) {
|
|
|
360
778
|
resolve();
|
|
361
779
|
});
|
|
362
780
|
});
|
|
363
|
-
port
|
|
781
|
+
// When port 0 is requested, the OS assigns an ephemeral port
|
|
782
|
+
const addr = server.address();
|
|
783
|
+
port =
|
|
784
|
+
typeof addr === 'object' && addr !== null ? addr.port : currentPort;
|
|
364
785
|
const state = { server, port, targetUrl };
|
|
365
786
|
setProxyState(state);
|
|
366
787
|
// Write proxy-config.json for the preload module
|
|
@@ -403,6 +824,41 @@ export async function stopEditorProxy() {
|
|
|
403
824
|
*/
|
|
404
825
|
export function invalidateScenarioCache() {
|
|
405
826
|
scenarioCache = { data: null, timestamp: 0 };
|
|
827
|
+
sessionConfig = undefined;
|
|
828
|
+
seedSessionCookies = undefined;
|
|
829
|
+
localStorageConfig = null;
|
|
830
|
+
activeScenarioId = null;
|
|
831
|
+
currentPrototypeId = null;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Verify that the proxy can successfully forward a request to the target dev server.
|
|
835
|
+
* Makes a HEAD request through the proxy and checks that it gets a response (any status).
|
|
836
|
+
* Returns false if the proxy isn't running or if the request fails entirely.
|
|
837
|
+
*/
|
|
838
|
+
export async function verifyProxyForwarding() {
|
|
839
|
+
const state = getProxyState();
|
|
840
|
+
if (!state) {
|
|
841
|
+
console.warn('[editorProxy] Cannot verify — proxy is not running');
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
try {
|
|
845
|
+
const response = await fetch(`http://127.0.0.1:${state.port}/`, {
|
|
846
|
+
method: 'HEAD',
|
|
847
|
+
signal: AbortSignal.timeout(5000),
|
|
848
|
+
});
|
|
849
|
+
// Any response from the target (even 404) means forwarding works.
|
|
850
|
+
// Only 502 (our own Bad Gateway) means the target is unreachable.
|
|
851
|
+
if (response.status === 502) {
|
|
852
|
+
console.warn(`[editorProxy] Verification failed — proxy returned 502 (target unreachable)`);
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
console.log(`[editorProxy] Verification passed — proxy forwarding to ${state.targetUrl} (status ${response.status})`);
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
catch (err) {
|
|
859
|
+
console.warn(`[editorProxy] Verification failed — could not reach proxy on port ${state.port}`);
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
406
862
|
}
|
|
407
863
|
/**
|
|
408
864
|
* Ensure the proxy is running. If it's not, start it using the current dev server URL.
|
|
@@ -424,9 +880,10 @@ export async function ensureProxyRunning() {
|
|
|
424
880
|
return null;
|
|
425
881
|
}
|
|
426
882
|
const codeyamPort = parseInt(process.env.CODEYAM_PORT || '3111', 10);
|
|
427
|
-
|
|
883
|
+
const { proxyPort } = computeEditorPorts(codeyamPort);
|
|
884
|
+
console.log(`[editorProxy] Proxy not running, starting on-demand (port ${proxyPort}, target ${devServer.url})`);
|
|
428
885
|
const result = await startEditorProxy({
|
|
429
|
-
port:
|
|
886
|
+
port: proxyPort,
|
|
430
887
|
targetUrl: devServer.url,
|
|
431
888
|
});
|
|
432
889
|
if (result) {
|
|
@@ -437,4 +894,8 @@ export async function ensureProxyRunning() {
|
|
|
437
894
|
console.error('[editorProxy] Failed to start on-demand proxy');
|
|
438
895
|
return null;
|
|
439
896
|
}
|
|
897
|
+
/**
|
|
898
|
+
* Test-only export: trigger readScenarioData so tests can verify session config extraction.
|
|
899
|
+
*/
|
|
900
|
+
export const _readScenarioDataForTest = readScenarioData;
|
|
440
901
|
//# sourceMappingURL=editorProxy.js.map
|