@codeyam/codeyam-cli 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analyzer-template/.build-info.json +8 -8
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +4 -4
- 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/src/lib/kysely/tables/editorScenariosTable.ts +31 -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 +5 -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 +31 -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 +1619 -243
- package/codeyam-cli/src/commands/editor.js.map +1 -1
- package/codeyam-cli/src/commands/init.js +67 -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 +144 -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 +127 -0
- package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +610 -1
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
- 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 +121 -0
- package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.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 +520 -0
- package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.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 +195 -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 +781 -2
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +213 -0
- package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +1742 -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 +101 -0
- package/codeyam-cli/src/utils/__tests__/parseRegisterArg.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 +300 -0
- package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +25 -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/analyzer.js +9 -0
- package/codeyam-cli/src/utils/analyzer.js.map +1 -1
- package/codeyam-cli/src/utils/analyzerFinalization.js +96 -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 +73 -0
- package/codeyam-cli/src/utils/editorApi.js.map +1 -0
- package/codeyam-cli/src/utils/editorAudit.js +101 -7
- package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
- 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/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 +113 -0
- package/codeyam-cli/src/utils/editorLoaderHelpers.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 +67 -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 +276 -0
- package/codeyam-cli/src/utils/editorScenarios.js.map +1 -1
- package/codeyam-cli/src/utils/editorSeedAdapter.js +173 -0
- package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -0
- package/codeyam-cli/src/utils/entityChangeStatus.js +349 -0
- package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -0
- package/codeyam-cli/src/utils/entityChangeStatus.server.js +158 -0
- package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -0
- package/codeyam-cli/src/utils/install-skills.js +1 -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/scenarioCoverage.js +75 -0
- package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -0
- package/codeyam-cli/src/utils/scenariosManifest.js +159 -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 +46 -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/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/build/client/assets/{CopyButton-DmJveP3T.js → CopyButton-BPXZwM4t.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-C76mRRiF.js → EntityItem-BcgbViKV.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-CobE682z.js → EntityTypeIcon-CQIG2qda.js} +9 -9
- package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-djPLI-WV.js → ReportIssueModal-BzHcG7SE.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-B76aig_2.js → ScenarioViewer-Bd-hxofb.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-oAf2Kqsf.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{_index-C96V0n15.js → _index-DLxKhri3.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BpKzcsJz.js → activity.(_tab)-BcY3q6nt.js} +6 -6
- 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-webgl-DI8QOUvO.js +58 -0
- package/codeyam-cli/src/webserver/build/client/assets/{agent-transcripts-D9hemwl6.js → agent-transcripts-Bni3iiUj.js} +5 -5
- 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-scenario-coverage-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{book-open-D_nMCFmP.js → book-open-BYOypzCa.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-BH2h1Ea2.js → chevron-down-C_Pmso5S.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-DyIKORY6.js → circle-check-BVMi9VA5.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{copy-NDbZjXao.js → copy-n2FB0_Sw.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-CC6AbExI.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BsDh6TSF.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor-PBc_6L9R.js +10 -0
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-4FzHlcNn.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-CrjR3zZW.js → entity._sha._-BsDXNp45.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BgAqUtTZ.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-Bmshgrij.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{files-DO4CZ16O.js → files-BZrlFE1F.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/git-DdZcvjGh.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-B8vTTNy2.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/index-yHOVb4rc.js +15 -0
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BAXYRVEO.js → loader-circle-DaAZ_H2w.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/manifest-65850841.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/memory-9gnxSZlb.js +101 -0
- package/codeyam-cli/src/webserver/build/client/assets/{pause-DTAcYxBt.js → pause-f5-1lKBt.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/root-BwX8YgFb.js +67 -0
- package/codeyam-cli/src/webserver/build/client/assets/{search-fKo7v0Zo.js → search-Di64LWVb.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{settings-DfuTtcJP.js → settings-0OrEMU6J.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{simulations-B3aOzpCZ.js → simulations-DWT-CvLy.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{terminal-BG4heKCG.js → terminal-Br7MOqts.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-DtSmdtM4.js → triangle-alert-BLdiCuG-.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BE43Hjti.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/index-DEEQf4pi.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/init-CkWmyFY2.js +10 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-BHi-9O8W.js +439 -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 +487 -50
- package/codeyam-cli/src/webserver/editorProxy.js.map +1 -1
- 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 +46 -14
- package/codeyam-cli/src/webserver/server.js.map +1 -1
- package/codeyam-cli/src/webserver/terminalServer.js +39 -11
- 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 +97 -8
- 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 +92 -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/skills/codeyam-dev-mode/SKILL.md +2 -2
- package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +96 -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 +14 -9
- 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 +31 -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/codeyam-cli/src/webserver/build/client/assets/Terminal-Dnj5CY9R.js +0 -41
- 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-D1DAKXtT.js +0 -8
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-DkzqFzFj.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/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/manifest-a632de18.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/memory-Dg0mvYrI.js +0 -96
- package/codeyam-cli/src/webserver/build/client/assets/root-DUKqhFlb.js +0 -67
- package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-ByhSyh0W.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/index-HfLydfDq.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-CUu_F-oo.js +0 -366
- 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,144 @@ 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
|
+
/**
|
|
9
|
+
* Normalize a target URL by stripping trailing slashes for consistency.
|
|
10
|
+
*
|
|
11
|
+
* Previously this also replaced `localhost` with `127.0.0.1`, but that broke
|
|
12
|
+
* forwarding to dev servers that bind to IPv6 only (e.g. Vite 6 on macOS
|
|
13
|
+
* binds to `[::1]`). The hostname is now left as-is — `resolveLoopbackAddress`
|
|
14
|
+
* probes the actual target at startup to pick the right address.
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeTargetUrl(url) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = new URL(url);
|
|
19
|
+
return parsed.toString().replace(/\/$/, '');
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Probe a localhost port to determine the correct loopback address.
|
|
27
|
+
* Dev servers may bind to IPv4 (127.0.0.1), IPv6 (::1), or both.
|
|
28
|
+
* Returns the first address that accepts a TCP connection.
|
|
29
|
+
*/
|
|
30
|
+
export async function resolveLoopbackAddress(port) {
|
|
31
|
+
const candidates = ['127.0.0.1', '::1'];
|
|
32
|
+
for (const host of candidates) {
|
|
33
|
+
try {
|
|
34
|
+
const connected = await new Promise((resolve) => {
|
|
35
|
+
const socket = new net.Socket();
|
|
36
|
+
socket.setTimeout(1000);
|
|
37
|
+
socket.once('connect', () => {
|
|
38
|
+
socket.destroy();
|
|
39
|
+
resolve(true);
|
|
40
|
+
});
|
|
41
|
+
socket.once('error', () => {
|
|
42
|
+
socket.destroy();
|
|
43
|
+
resolve(false);
|
|
44
|
+
});
|
|
45
|
+
socket.once('timeout', () => {
|
|
46
|
+
socket.destroy();
|
|
47
|
+
resolve(false);
|
|
48
|
+
});
|
|
49
|
+
socket.connect(port, host);
|
|
50
|
+
});
|
|
51
|
+
if (connected) {
|
|
52
|
+
return host;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Try next candidate
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
7
61
|
// Global key so the proxy survives HMR
|
|
8
62
|
const GLOBAL_KEY = '__codeyam_editor_proxy__';
|
|
63
|
+
// ─── Live Preview Health ─────────────────────────────────────────────
|
|
64
|
+
const PREVIEW_HEALTH_KEY = '__codeyam_preview_health__';
|
|
65
|
+
function getPreviewHealth() {
|
|
66
|
+
return globalThis[PREVIEW_HEALTH_KEY] ?? null;
|
|
67
|
+
}
|
|
68
|
+
function setPreviewHealth(report) {
|
|
69
|
+
globalThis[PREVIEW_HEALTH_KEY] = report;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the current live preview health report (read by API endpoint).
|
|
73
|
+
*/
|
|
74
|
+
export function getPreviewHealthReport() {
|
|
75
|
+
return getPreviewHealth();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reset preview health state (called when a new HTML page is served).
|
|
79
|
+
*/
|
|
80
|
+
export function resetPreviewHealth() {
|
|
81
|
+
setPreviewHealth(null);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Error-catching script injected into HTML responses.
|
|
85
|
+
* Uses vanilla JS for maximum compatibility.
|
|
86
|
+
*/
|
|
87
|
+
export const PREVIEW_HEALTH_SCRIPT = `<script data-codeyam-health>
|
|
88
|
+
(function() {
|
|
89
|
+
var errors = [];
|
|
90
|
+
var reported = false;
|
|
91
|
+
function report(type, msg, stack) {
|
|
92
|
+
errors.push({ type: type, message: msg, stack: stack, timestamp: Date.now() });
|
|
93
|
+
if (!reported) {
|
|
94
|
+
reported = true;
|
|
95
|
+
setTimeout(function() { flush(); }, 500);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function flush() {
|
|
99
|
+
fetch('/__codeyam__/preview-health', {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: { 'Content-Type': 'application/json' },
|
|
102
|
+
body: JSON.stringify({ errors: errors, url: location.href })
|
|
103
|
+
}).catch(function(){});
|
|
104
|
+
reported = false;
|
|
105
|
+
errors = [];
|
|
106
|
+
}
|
|
107
|
+
window.addEventListener('error', function(e) {
|
|
108
|
+
report('error', e.message, e.error && e.error.stack);
|
|
109
|
+
});
|
|
110
|
+
window.addEventListener('unhandledrejection', function(e) {
|
|
111
|
+
report('unhandledrejection', String(e.reason), e.reason && e.reason.stack);
|
|
112
|
+
});
|
|
113
|
+
var origError = console.error;
|
|
114
|
+
console.error = function() {
|
|
115
|
+
report('console.error', Array.prototype.join.call(arguments, ' '));
|
|
116
|
+
origError.apply(console, arguments);
|
|
117
|
+
};
|
|
118
|
+
window.addEventListener('load', function() {
|
|
119
|
+
setTimeout(function() {
|
|
120
|
+
var hasContent = document.body && document.body.innerText.trim().length > 0;
|
|
121
|
+
fetch('/__codeyam__/preview-health', {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
headers: { 'Content-Type': 'application/json' },
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
loaded: true,
|
|
126
|
+
hasContent: hasContent,
|
|
127
|
+
url: location.href,
|
|
128
|
+
errorCount: errors.length
|
|
129
|
+
})
|
|
130
|
+
}).catch(function(){});
|
|
131
|
+
}, 1000);
|
|
132
|
+
});
|
|
133
|
+
})();
|
|
134
|
+
</script>`;
|
|
9
135
|
const CACHE_TTL_MS = 500;
|
|
10
136
|
let scenarioCache = { data: null, timestamp: 0 };
|
|
137
|
+
// Session config extracted from the active scenario — drives cookie injection
|
|
138
|
+
let sessionConfig = undefined;
|
|
139
|
+
// localStorage config extracted from the active scenario — drives HTML injection
|
|
140
|
+
let localStorageConfig = null;
|
|
141
|
+
// Active scenario ID — used to gate localStorage seeding (only re-seed on switch)
|
|
142
|
+
let activeScenarioId = null;
|
|
143
|
+
// Prototype ID — used to gate a one-time localStorage.clear() when a new project is scaffolded
|
|
144
|
+
let currentPrototypeId = null;
|
|
11
145
|
// Max body size to buffer for mock matching (10MB)
|
|
12
146
|
const MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
13
147
|
function getProxyState() {
|
|
@@ -38,6 +172,12 @@ export function getProxyUrl() {
|
|
|
38
172
|
/**
|
|
39
173
|
* Read the active scenario's mock data from disk, with brief caching.
|
|
40
174
|
* Feeds the data into the MockStateManager.
|
|
175
|
+
*
|
|
176
|
+
* For application/user scenarios (type-aware): only loads `externalApis`
|
|
177
|
+
* into the mock state manager. All DB-backed routes flow through to the
|
|
178
|
+
* real app (database is seeded with real data).
|
|
179
|
+
*
|
|
180
|
+
* For component scenarios (or legacy): loads all routes as before.
|
|
41
181
|
*/
|
|
42
182
|
function readScenarioData() {
|
|
43
183
|
const now = Date.now();
|
|
@@ -55,6 +195,8 @@ function readScenarioData() {
|
|
|
55
195
|
const active = JSON.parse(fs.readFileSync(activeScenarioPath, 'utf-8'));
|
|
56
196
|
const scenarioId = active.scenarioId;
|
|
57
197
|
if (!scenarioId) {
|
|
198
|
+
// No active scenario — but may have a prototypeId for localStorage clearing
|
|
199
|
+
currentPrototypeId = active.prototypeId || null;
|
|
58
200
|
scenarioCache = { data: null, timestamp: now };
|
|
59
201
|
return null;
|
|
60
202
|
}
|
|
@@ -64,11 +206,34 @@ function readScenarioData() {
|
|
|
64
206
|
scenarioCache = { data: null, timestamp: now };
|
|
65
207
|
return null;
|
|
66
208
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
209
|
+
const rawData = JSON.parse(fs.readFileSync(dataFilePath, 'utf-8'));
|
|
210
|
+
// Extract session config for cookie injection
|
|
211
|
+
sessionConfig = rawData.session || null;
|
|
212
|
+
// Extract localStorage config for HTML injection
|
|
213
|
+
localStorageConfig = rawData.localStorage || null;
|
|
214
|
+
activeScenarioId = scenarioId;
|
|
215
|
+
// Type-aware: for seed-based scenarios, only serve externalApis via proxy
|
|
216
|
+
const scenarioType = active.type || rawData.type || null;
|
|
217
|
+
let mockData;
|
|
218
|
+
if ((scenarioType === 'application' || scenarioType === 'user') &&
|
|
219
|
+
rawData.seed) {
|
|
220
|
+
// Seed-based scenario: only load externalApis as routes for the proxy
|
|
221
|
+
if (rawData.externalApis && typeof rawData.externalApis === 'object') {
|
|
222
|
+
mockData = { routes: rawData.externalApis };
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// No external APIs — proxy passes everything through
|
|
226
|
+
mockData = {};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// Component/legacy scenario: load all data
|
|
231
|
+
mockData = rawData;
|
|
232
|
+
}
|
|
233
|
+
scenarioCache = { data: mockData, timestamp: now };
|
|
69
234
|
// Feed into mock state manager (smart reload handles dedup)
|
|
70
|
-
getMockStateManager().loadScenario(
|
|
71
|
-
return
|
|
235
|
+
getMockStateManager().loadScenario(mockData);
|
|
236
|
+
return mockData;
|
|
72
237
|
}
|
|
73
238
|
catch (err) {
|
|
74
239
|
console.warn('[editorProxy] Error reading scenario data:', err);
|
|
@@ -76,39 +241,6 @@ function readScenarioData() {
|
|
|
76
241
|
return null;
|
|
77
242
|
}
|
|
78
243
|
}
|
|
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
244
|
/**
|
|
113
245
|
* Buffer the request body, up to MAX_BODY_SIZE.
|
|
114
246
|
* Returns null if the body exceeds the limit.
|
|
@@ -137,26 +269,67 @@ function bufferRequestBody(req) {
|
|
|
137
269
|
});
|
|
138
270
|
});
|
|
139
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Strip IPv6 bracket notation for use with http.request hostname.
|
|
274
|
+
* URL.hostname returns `[::1]` for IPv6 but http.request needs `::1`.
|
|
275
|
+
*/
|
|
276
|
+
function stripIPv6Brackets(hostname) {
|
|
277
|
+
if (hostname.startsWith('[') && hostname.endsWith(']')) {
|
|
278
|
+
return hostname.slice(1, -1);
|
|
279
|
+
}
|
|
280
|
+
return hostname;
|
|
281
|
+
}
|
|
140
282
|
/**
|
|
141
283
|
* Forward a buffered request to the target dev server.
|
|
142
284
|
* Unlike the streaming forwardRequest, this replays a buffered body.
|
|
143
285
|
*/
|
|
144
286
|
function forwardBufferedRequest(req, res, targetUrl, bodyBuffer) {
|
|
145
287
|
const target = new URL(targetUrl);
|
|
288
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
146
289
|
const headers = { ...req.headers, host: `${target.hostname}:${target.port}` };
|
|
290
|
+
// Remove accept-encoding so the dev server returns uncompressed responses.
|
|
291
|
+
// The proxy injects a health script into HTML — this fails on compressed bodies.
|
|
292
|
+
delete headers['accept-encoding'];
|
|
147
293
|
// Update content-length if we have the body buffer
|
|
148
294
|
if (bodyBuffer) {
|
|
149
295
|
headers['content-length'] = String(bodyBuffer.length);
|
|
150
296
|
}
|
|
151
297
|
const options = {
|
|
152
|
-
hostname
|
|
298
|
+
hostname,
|
|
153
299
|
port: target.port,
|
|
154
300
|
path: req.url,
|
|
155
301
|
method: req.method,
|
|
156
302
|
headers,
|
|
157
303
|
};
|
|
158
304
|
const proxyReq = http.request(options, (proxyRes) => {
|
|
159
|
-
|
|
305
|
+
const status = proxyRes.statusCode || 200;
|
|
306
|
+
if (status >= 400) {
|
|
307
|
+
console.warn(`[editorProxy] Target returned ${status} for ${req.method} ${req.url}`);
|
|
308
|
+
}
|
|
309
|
+
const headers = { ...proxyRes.headers };
|
|
310
|
+
injectSessionCookie(headers);
|
|
311
|
+
// Check if response is HTML — if so, buffer and inject health script
|
|
312
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
313
|
+
if (contentType.includes('text/html')) {
|
|
314
|
+
resetPreviewHealth();
|
|
315
|
+
const chunks = [];
|
|
316
|
+
proxyRes.on('data', (chunk) => chunks.push(chunk));
|
|
317
|
+
proxyRes.on('end', () => {
|
|
318
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
319
|
+
const lsScript = buildLocalStorageScript(localStorageConfig, activeScenarioId || '', currentPrototypeId);
|
|
320
|
+
const injected = injectHealthScript(body, lsScript);
|
|
321
|
+
delete headers['content-length'];
|
|
322
|
+
delete headers['content-encoding'];
|
|
323
|
+
// Prevent browser from caching HTML responses — scenario switches
|
|
324
|
+
// serve different content from the same URL (seed data changes the
|
|
325
|
+
// rendered page but the proxy URL stays the same).
|
|
326
|
+
headers['cache-control'] = 'no-store, must-revalidate';
|
|
327
|
+
res.writeHead(status, headers);
|
|
328
|
+
res.end(injected);
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
res.writeHead(status, headers);
|
|
160
333
|
proxyRes.pipe(res, { end: true });
|
|
161
334
|
});
|
|
162
335
|
proxyReq.on('error', (err) => {
|
|
@@ -174,19 +347,58 @@ function forwardBufferedRequest(req, res, targetUrl, bodyBuffer) {
|
|
|
174
347
|
}
|
|
175
348
|
}
|
|
176
349
|
/**
|
|
177
|
-
* Forward an HTTP request to the target dev server
|
|
350
|
+
* Forward an HTTP request to the target dev server.
|
|
351
|
+
* For HTML responses: buffers body to inject health-check script.
|
|
352
|
+
* For non-HTML responses: pipes directly (no buffering).
|
|
178
353
|
*/
|
|
179
354
|
function forwardRequest(req, res, targetUrl) {
|
|
180
355
|
const target = new URL(targetUrl);
|
|
356
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
357
|
+
// Build headers, stripping accept-encoding so the dev server returns uncompressed
|
|
358
|
+
// responses. The proxy injects a health script into HTML — this fails on compressed bodies.
|
|
359
|
+
const { 'accept-encoding': _ae, ...forwardHeaders } = req.headers;
|
|
181
360
|
const options = {
|
|
182
|
-
hostname
|
|
361
|
+
hostname,
|
|
183
362
|
port: target.port,
|
|
184
363
|
path: req.url,
|
|
185
364
|
method: req.method,
|
|
186
|
-
headers: {
|
|
365
|
+
headers: {
|
|
366
|
+
...forwardHeaders,
|
|
367
|
+
host: `${target.hostname}:${target.port}`,
|
|
368
|
+
},
|
|
187
369
|
};
|
|
188
370
|
const proxyReq = http.request(options, (proxyRes) => {
|
|
189
|
-
|
|
371
|
+
const status = proxyRes.statusCode || 200;
|
|
372
|
+
if (status >= 400) {
|
|
373
|
+
console.warn(`[editorProxy] Target returned ${status} for ${req.method} ${req.url}`);
|
|
374
|
+
}
|
|
375
|
+
const headers = { ...proxyRes.headers };
|
|
376
|
+
injectSessionCookie(headers);
|
|
377
|
+
// Check if response is HTML — if so, buffer and inject health script
|
|
378
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
379
|
+
if (contentType.includes('text/html')) {
|
|
380
|
+
// Reset health state for new page loads
|
|
381
|
+
resetPreviewHealth();
|
|
382
|
+
const chunks = [];
|
|
383
|
+
proxyRes.on('data', (chunk) => chunks.push(chunk));
|
|
384
|
+
proxyRes.on('end', () => {
|
|
385
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
386
|
+
const lsScript = buildLocalStorageScript(localStorageConfig, activeScenarioId || '', currentPrototypeId);
|
|
387
|
+
const injected = injectHealthScript(body, lsScript);
|
|
388
|
+
// Remove content-length since body size changed; use chunked transfer
|
|
389
|
+
delete headers['content-length'];
|
|
390
|
+
// Remove content-encoding since we're serving uncompressed
|
|
391
|
+
delete headers['content-encoding'];
|
|
392
|
+
// Prevent browser from caching HTML responses — scenario switches
|
|
393
|
+
// serve different content from the same URL (seed data changes the
|
|
394
|
+
// rendered page but the proxy URL stays the same).
|
|
395
|
+
headers['cache-control'] = 'no-store, must-revalidate';
|
|
396
|
+
res.writeHead(status, headers);
|
|
397
|
+
res.end(injected);
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
res.writeHead(status, headers);
|
|
190
402
|
proxyRes.pipe(res, { end: true });
|
|
191
403
|
});
|
|
192
404
|
proxyReq.on('error', (err) => {
|
|
@@ -198,14 +410,166 @@ function forwardRequest(req, res, targetUrl) {
|
|
|
198
410
|
});
|
|
199
411
|
req.pipe(proxyReq, { end: true });
|
|
200
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* Inject or clear the session-token cookie on proxied responses.
|
|
415
|
+
* When a scenario has session.cookieValue, sets the cookie to auto-log the user in.
|
|
416
|
+
* When a scenario has no session field (null), clears any existing session cookie.
|
|
417
|
+
* When sessionConfig is undefined (no scenario loaded yet), does nothing.
|
|
418
|
+
*/
|
|
419
|
+
function injectSessionCookie(headers) {
|
|
420
|
+
if (sessionConfig === undefined)
|
|
421
|
+
return;
|
|
422
|
+
let cookie;
|
|
423
|
+
if (sessionConfig?.cookieValue) {
|
|
424
|
+
cookie = `session-token=${sessionConfig.cookieValue}; Path=/; SameSite=Lax`;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
// No session config — clear any existing session cookie
|
|
428
|
+
cookie = `session-token=; Path=/; Max-Age=0`;
|
|
429
|
+
}
|
|
430
|
+
const existing = headers['set-cookie'];
|
|
431
|
+
if (existing) {
|
|
432
|
+
headers['set-cookie'] = [
|
|
433
|
+
...(Array.isArray(existing) ? existing : [existing]),
|
|
434
|
+
cookie,
|
|
435
|
+
];
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
headers['set-cookie'] = [cookie];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Get the current session config (for testing).
|
|
443
|
+
*/
|
|
444
|
+
export function getSessionConfig() {
|
|
445
|
+
return sessionConfig;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get the current localStorage config (for testing and script generation).
|
|
449
|
+
*/
|
|
450
|
+
export function getLocalStorageConfig() {
|
|
451
|
+
return localStorageConfig;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Get the active scenario ID (for testing and script generation).
|
|
455
|
+
*/
|
|
456
|
+
export function getActiveScenarioId() {
|
|
457
|
+
return activeScenarioId;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Get the current prototype ID (for testing).
|
|
461
|
+
*/
|
|
462
|
+
export function getCurrentPrototypeId() {
|
|
463
|
+
return currentPrototypeId;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Build a script tag that seeds localStorage with scenario data on first load.
|
|
467
|
+
* Gated by scenario ID — only seeds when the scenario changes, preserving
|
|
468
|
+
* interactive modifications across page reloads / HMR.
|
|
469
|
+
*
|
|
470
|
+
* Returns empty string if no localStorage config is provided.
|
|
471
|
+
*/
|
|
472
|
+
export function buildLocalStorageScript(localStorageConfig, scenarioId, prototypeId) {
|
|
473
|
+
// null/undefined means no localStorage config at all — but if we have a
|
|
474
|
+
// prototypeId, emit a one-time localStorage.clear() to flush stale data
|
|
475
|
+
// from a previous prototype session.
|
|
476
|
+
if (!localStorageConfig || typeof localStorageConfig !== 'object') {
|
|
477
|
+
if (prototypeId) {
|
|
478
|
+
return `<script data-codeyam-ls>
|
|
479
|
+
(function() {
|
|
480
|
+
if (localStorage.getItem('__codeyam_proto__') === ${JSON.stringify(prototypeId)}) return;
|
|
481
|
+
localStorage.clear();
|
|
482
|
+
localStorage.setItem('__codeyam_proto__', ${JSON.stringify(prototypeId)});
|
|
483
|
+
})();
|
|
484
|
+
</script>`;
|
|
485
|
+
}
|
|
486
|
+
return '';
|
|
487
|
+
}
|
|
488
|
+
// Even an empty object needs a cleanup script — switching from a scenario
|
|
489
|
+
// with localStorage data to one without must clear the previous keys.
|
|
490
|
+
const entries = Object.entries(localStorageConfig);
|
|
491
|
+
const keys = entries.map(([k]) => k);
|
|
492
|
+
// Build setItem calls — stringify non-string values
|
|
493
|
+
const setStatements = entries
|
|
494
|
+
.map(([key, value]) => {
|
|
495
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
|
496
|
+
return `localStorage.setItem(${JSON.stringify(key)}, ${JSON.stringify(serialized)});`;
|
|
497
|
+
})
|
|
498
|
+
.join('\n');
|
|
499
|
+
return `<script data-codeyam-ls>
|
|
500
|
+
(function() {
|
|
501
|
+
if (localStorage.getItem('__codeyam_ls_sid__') === ${JSON.stringify(scenarioId)}) return;
|
|
502
|
+
var prev = JSON.parse(localStorage.getItem('__codeyam_ls_keys__') || '[]');
|
|
503
|
+
for (var i = 0; i < prev.length; i++) localStorage.removeItem(prev[i]);
|
|
504
|
+
${setStatements}
|
|
505
|
+
localStorage.setItem('__codeyam_ls_keys__', ${JSON.stringify(JSON.stringify(keys))});
|
|
506
|
+
localStorage.setItem('__codeyam_ls_sid__', ${JSON.stringify(scenarioId)});
|
|
507
|
+
})();
|
|
508
|
+
</script>`;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Inject the health-check script (and optional localStorage script) into an HTML response body.
|
|
512
|
+
* Inserts before </head> if present, otherwise before </body>, otherwise appends.
|
|
513
|
+
* When a localStorageScript is provided, it's injected BEFORE the health script
|
|
514
|
+
* so localStorage is populated before the app loads.
|
|
515
|
+
*/
|
|
516
|
+
export function injectHealthScript(html, localStorageScript) {
|
|
517
|
+
const scripts = (localStorageScript || '') + PREVIEW_HEALTH_SCRIPT;
|
|
518
|
+
if (html.includes('</head>')) {
|
|
519
|
+
return html.replace('</head>', scripts + '</head>');
|
|
520
|
+
}
|
|
521
|
+
if (html.includes('</body>')) {
|
|
522
|
+
return html.replace('</body>', scripts + '</body>');
|
|
523
|
+
}
|
|
524
|
+
return html + scripts;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Handle POST /__codeyam__/preview-health — store health data in globalThis.
|
|
528
|
+
*/
|
|
529
|
+
function handlePreviewHealthPost(req, res) {
|
|
530
|
+
const chunks = [];
|
|
531
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
532
|
+
req.on('end', () => {
|
|
533
|
+
try {
|
|
534
|
+
const body = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
535
|
+
const current = getPreviewHealth() || {
|
|
536
|
+
errors: [],
|
|
537
|
+
loaded: false,
|
|
538
|
+
hasContent: false,
|
|
539
|
+
url: '',
|
|
540
|
+
lastUpdated: 0,
|
|
541
|
+
};
|
|
542
|
+
if (body.errors && Array.isArray(body.errors)) {
|
|
543
|
+
current.errors = current.errors.concat(body.errors);
|
|
544
|
+
}
|
|
545
|
+
if (body.loaded !== undefined) {
|
|
546
|
+
current.loaded = body.loaded;
|
|
547
|
+
}
|
|
548
|
+
if (body.hasContent !== undefined) {
|
|
549
|
+
current.hasContent = body.hasContent;
|
|
550
|
+
}
|
|
551
|
+
if (body.url) {
|
|
552
|
+
current.url = body.url;
|
|
553
|
+
}
|
|
554
|
+
current.lastUpdated = Date.now();
|
|
555
|
+
setPreviewHealth(current);
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
// Ignore malformed JSON
|
|
559
|
+
}
|
|
560
|
+
res.writeHead(204);
|
|
561
|
+
res.end();
|
|
562
|
+
});
|
|
563
|
+
}
|
|
201
564
|
/**
|
|
202
565
|
* Handle WebSocket upgrade by piping to the target dev server.
|
|
203
566
|
*/
|
|
204
567
|
function handleUpgrade(req, socket, head, targetUrl) {
|
|
205
568
|
const target = new URL(targetUrl);
|
|
569
|
+
const hostname = stripIPv6Brackets(target.hostname);
|
|
206
570
|
const port = parseInt(target.port, 10) || 80;
|
|
207
|
-
console.log(`[editorProxy] WebSocket upgrade: ${req.url} → ${
|
|
208
|
-
const proxySocket = net.connect(port,
|
|
571
|
+
console.log(`[editorProxy] WebSocket upgrade: ${req.url} → ${hostname}:${port}`);
|
|
572
|
+
const proxySocket = net.connect(port, hostname, () => {
|
|
209
573
|
// Reconstruct the HTTP upgrade request
|
|
210
574
|
const requestLine = `${req.method} ${req.url} HTTP/${req.httpVersion}\r\n`;
|
|
211
575
|
const headers = Object.entries(req.headers)
|
|
@@ -267,10 +631,34 @@ function removeProxyConfig() {
|
|
|
267
631
|
* Supports all HTTP methods (GET, POST, PUT, DELETE, PATCH) with body buffering.
|
|
268
632
|
*/
|
|
269
633
|
export async function startEditorProxy(options) {
|
|
270
|
-
//
|
|
634
|
+
// If proxy is already running, reuse it (prevents second tab from killing first tab's proxy)
|
|
635
|
+
const existing = getProxyState();
|
|
636
|
+
if (existing) {
|
|
637
|
+
console.log(`[editorProxy] Proxy already running on port ${existing.port} → ${existing.targetUrl}`);
|
|
638
|
+
return { port: existing.port };
|
|
639
|
+
}
|
|
640
|
+
// Stop any leftover state (shouldn't happen, but defensive)
|
|
271
641
|
await stopEditorProxy();
|
|
272
|
-
|
|
642
|
+
let targetUrl = normalizeTargetUrl(options.targetUrl);
|
|
273
643
|
let port = options.port;
|
|
644
|
+
// When the target is localhost, probe to find the correct loopback address.
|
|
645
|
+
// Dev servers may bind to IPv4 (127.0.0.1) or IPv6 (::1) — Vite 6 on macOS
|
|
646
|
+
// binds to ::1 by default. We need to match the actual binding.
|
|
647
|
+
try {
|
|
648
|
+
const parsed = new URL(targetUrl);
|
|
649
|
+
if (parsed.hostname === 'localhost') {
|
|
650
|
+
const targetPort = parseInt(parsed.port || '80', 10);
|
|
651
|
+
const resolvedHost = await resolveLoopbackAddress(targetPort);
|
|
652
|
+
if (resolvedHost) {
|
|
653
|
+
parsed.hostname = resolvedHost;
|
|
654
|
+
targetUrl = parsed.toString().replace(/\/$/, '');
|
|
655
|
+
console.log(`[editorProxy] Resolved localhost to ${resolvedHost} for port ${targetPort}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
// Keep original targetUrl
|
|
661
|
+
}
|
|
274
662
|
console.log(`[editorProxy] Starting proxy (requested port ${port}, target ${targetUrl})`);
|
|
275
663
|
const mockState = getMockStateManager();
|
|
276
664
|
const server = http.createServer((req, res) => {
|
|
@@ -289,6 +677,11 @@ export async function startEditorProxy(options) {
|
|
|
289
677
|
res.end();
|
|
290
678
|
return;
|
|
291
679
|
}
|
|
680
|
+
// Intercept preview health reports from the injected script
|
|
681
|
+
if (method === 'POST' && pathname === '/__codeyam__/preview-health') {
|
|
682
|
+
handlePreviewHealthPost(req, res);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
292
685
|
// Load scenario data (also feeds MockStateManager)
|
|
293
686
|
readScenarioData();
|
|
294
687
|
// For methods that may carry a body, buffer it first
|
|
@@ -320,6 +713,7 @@ export async function startEditorProxy(options) {
|
|
|
320
713
|
'Content-Type': 'application/json',
|
|
321
714
|
'Access-Control-Allow-Origin': '*',
|
|
322
715
|
'X-CodeYam-Proxy': 'scenario-data',
|
|
716
|
+
'Cache-Control': 'no-store',
|
|
323
717
|
});
|
|
324
718
|
res.end(match.body != null ? JSON.stringify(match.body) : '');
|
|
325
719
|
return;
|
|
@@ -336,6 +730,7 @@ export async function startEditorProxy(options) {
|
|
|
336
730
|
'Content-Type': 'application/json',
|
|
337
731
|
'Access-Control-Allow-Origin': '*',
|
|
338
732
|
'X-CodeYam-Proxy': 'scenario-data',
|
|
733
|
+
'Cache-Control': 'no-store',
|
|
339
734
|
});
|
|
340
735
|
res.end(match.body != null ? JSON.stringify(match.body) : '');
|
|
341
736
|
return;
|
|
@@ -360,7 +755,10 @@ export async function startEditorProxy(options) {
|
|
|
360
755
|
resolve();
|
|
361
756
|
});
|
|
362
757
|
});
|
|
363
|
-
port
|
|
758
|
+
// When port 0 is requested, the OS assigns an ephemeral port
|
|
759
|
+
const addr = server.address();
|
|
760
|
+
port =
|
|
761
|
+
typeof addr === 'object' && addr !== null ? addr.port : currentPort;
|
|
364
762
|
const state = { server, port, targetUrl };
|
|
365
763
|
setProxyState(state);
|
|
366
764
|
// Write proxy-config.json for the preload module
|
|
@@ -403,6 +801,40 @@ export async function stopEditorProxy() {
|
|
|
403
801
|
*/
|
|
404
802
|
export function invalidateScenarioCache() {
|
|
405
803
|
scenarioCache = { data: null, timestamp: 0 };
|
|
804
|
+
sessionConfig = undefined;
|
|
805
|
+
localStorageConfig = null;
|
|
806
|
+
activeScenarioId = null;
|
|
807
|
+
currentPrototypeId = null;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Verify that the proxy can successfully forward a request to the target dev server.
|
|
811
|
+
* Makes a HEAD request through the proxy and checks that it gets a response (any status).
|
|
812
|
+
* Returns false if the proxy isn't running or if the request fails entirely.
|
|
813
|
+
*/
|
|
814
|
+
export async function verifyProxyForwarding() {
|
|
815
|
+
const state = getProxyState();
|
|
816
|
+
if (!state) {
|
|
817
|
+
console.warn('[editorProxy] Cannot verify — proxy is not running');
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
try {
|
|
821
|
+
const response = await fetch(`http://127.0.0.1:${state.port}/`, {
|
|
822
|
+
method: 'HEAD',
|
|
823
|
+
signal: AbortSignal.timeout(5000),
|
|
824
|
+
});
|
|
825
|
+
// Any response from the target (even 404) means forwarding works.
|
|
826
|
+
// Only 502 (our own Bad Gateway) means the target is unreachable.
|
|
827
|
+
if (response.status === 502) {
|
|
828
|
+
console.warn(`[editorProxy] Verification failed — proxy returned 502 (target unreachable)`);
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
console.log(`[editorProxy] Verification passed — proxy forwarding to ${state.targetUrl} (status ${response.status})`);
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
catch (err) {
|
|
835
|
+
console.warn(`[editorProxy] Verification failed — could not reach proxy on port ${state.port}`);
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
406
838
|
}
|
|
407
839
|
/**
|
|
408
840
|
* Ensure the proxy is running. If it's not, start it using the current dev server URL.
|
|
@@ -424,9 +856,10 @@ export async function ensureProxyRunning() {
|
|
|
424
856
|
return null;
|
|
425
857
|
}
|
|
426
858
|
const codeyamPort = parseInt(process.env.CODEYAM_PORT || '3111', 10);
|
|
427
|
-
|
|
859
|
+
const { proxyPort } = computeEditorPorts(codeyamPort);
|
|
860
|
+
console.log(`[editorProxy] Proxy not running, starting on-demand (port ${proxyPort}, target ${devServer.url})`);
|
|
428
861
|
const result = await startEditorProxy({
|
|
429
|
-
port:
|
|
862
|
+
port: proxyPort,
|
|
430
863
|
targetUrl: devServer.url,
|
|
431
864
|
});
|
|
432
865
|
if (result) {
|
|
@@ -437,4 +870,8 @@ export async function ensureProxyRunning() {
|
|
|
437
870
|
console.error('[editorProxy] Failed to start on-demand proxy');
|
|
438
871
|
return null;
|
|
439
872
|
}
|
|
873
|
+
/**
|
|
874
|
+
* Test-only export: trigger readScenarioData so tests can verify session config extraction.
|
|
875
|
+
*/
|
|
876
|
+
export const _readScenarioDataForTest = readScenarioData;
|
|
440
877
|
//# sourceMappingURL=editorProxy.js.map
|