@codeyam/codeyam-cli 0.1.7 → 0.1.8
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/astScopes/astScopeAnalyzer.ts +34 -3
- package/analyzer-template/packages/ai/src/lib/completionCall.ts +14 -2
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +27 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.ts +62 -0
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +78 -2
- package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +6 -0
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +9 -1
- package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +0 -6
- package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +12 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +65 -28
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +83 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +23 -4
- package/analyzer-template/packages/aws/package.json +1 -1
- package/analyzer-template/packages/database/index.ts +1 -0
- package/analyzer-template/packages/database/package.json +3 -3
- package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -0
- package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +62 -0
- package/analyzer-template/packages/database/src/lib/loadCommits.ts +31 -20
- package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +0 -5
- package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +151 -135
- package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatus.ts +58 -42
- package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.ts +81 -65
- package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +29 -1
- package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +33 -5
- package/analyzer-template/packages/github/dist/database/index.d.ts +1 -0
- package/analyzer-template/packages/github/dist/database/index.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/index.js +1 -0
- package/analyzer-template/packages/github/dist/database/index.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +5 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +20 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +5 -0
- package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +23 -13
- package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
- package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.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 +100 -89
- package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js +41 -30
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
- package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +1 -0
- package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +10 -0
- package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
- package/analyzer-template/packages/github/package.json +1 -1
- package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
- package/analyzer-template/packages/types/src/types/Scenario.ts +10 -0
- package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +1 -0
- package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +10 -0
- package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
- package/analyzer-template/playwright/captureFromUrl.ts +89 -82
- package/analyzer-template/project/constructMockCode.ts +136 -43
- package/analyzer-template/project/reconcileMockDataKeys.ts +19 -14
- package/analyzer-template/project/start.ts +3 -0
- package/analyzer-template/project/startScenarioCapture.ts +9 -0
- package/analyzer-template/project/writeClientLogRoute.ts +125 -0
- package/analyzer-template/project/writeMockDataTsx.ts +17 -0
- package/analyzer-template/project/writeScenarioComponents.ts +36 -7
- package/analyzer-template/tsconfig.json +13 -1
- package/background/src/lib/virtualized/project/constructMockCode.js +115 -34
- package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +17 -11
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
- package/background/src/lib/virtualized/project/start.js +2 -0
- package/background/src/lib/virtualized/project/start.js.map +1 -1
- package/background/src/lib/virtualized/project/startScenarioCapture.js +5 -0
- package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
- package/background/src/lib/virtualized/project/writeClientLogRoute.js +110 -0
- package/background/src/lib/virtualized/project/writeClientLogRoute.js.map +1 -0
- package/background/src/lib/virtualized/project/writeMockDataTsx.js +12 -0
- package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
- package/background/src/lib/virtualized/project/writeScenarioComponents.js +29 -7
- package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
- package/codeyam-cli/scripts/apply-setup.js +208 -11
- package/codeyam-cli/scripts/apply-setup.js.map +1 -1
- package/codeyam-cli/src/cli.js +2 -0
- package/codeyam-cli/src/cli.js.map +1 -1
- package/codeyam-cli/src/commands/analyze.js +17 -7
- package/codeyam-cli/src/commands/analyze.js.map +1 -1
- package/codeyam-cli/src/commands/default.js +58 -3
- package/codeyam-cli/src/commands/default.js.map +1 -1
- package/codeyam-cli/src/commands/editor.js +1839 -0
- package/codeyam-cli/src/commands/editor.js.map +1 -0
- package/codeyam-cli/src/commands/init.js +40 -11
- package/codeyam-cli/src/commands/init.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +246 -0
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js +126 -0
- package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorJournal.test.js +295 -0
- package/codeyam-cli/src/utils/__tests__/editorJournal.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorMockState.test.js +270 -0
- package/codeyam-cli/src/utils/__tests__/editorMockState.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js +100 -0
- package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorPreview.test.js +147 -0
- package/codeyam-cli/src/utils/__tests__/editorPreview.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +76 -0
- package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/git.editor.test.js +134 -0
- package/codeyam-cli/src/utils/__tests__/git.editor.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js +9 -0
- package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/project.test.js +65 -0
- package/codeyam-cli/src/utils/__tests__/project.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js +121 -0
- package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js.map +1 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +26 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
- package/codeyam-cli/src/utils/backgroundServer.js +19 -3
- package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/utils/buildFlags.js +4 -0
- package/codeyam-cli/src/utils/buildFlags.js.map +1 -0
- package/codeyam-cli/src/utils/devModeEvents.js +40 -0
- package/codeyam-cli/src/utils/devModeEvents.js.map +1 -0
- package/codeyam-cli/src/utils/editorAudit.js +82 -0
- package/codeyam-cli/src/utils/editorAudit.js.map +1 -0
- package/codeyam-cli/src/utils/editorDevServer.js +98 -0
- package/codeyam-cli/src/utils/editorDevServer.js.map +1 -0
- package/codeyam-cli/src/utils/editorJournal.js +137 -0
- package/codeyam-cli/src/utils/editorJournal.js.map +1 -0
- package/codeyam-cli/src/utils/editorMockState.js +248 -0
- package/codeyam-cli/src/utils/editorMockState.js.map +1 -0
- package/codeyam-cli/src/utils/editorPreloadHelpers.js +64 -0
- package/codeyam-cli/src/utils/editorPreloadHelpers.js.map +1 -0
- package/codeyam-cli/src/utils/editorPreview.js +66 -0
- package/codeyam-cli/src/utils/editorPreview.js.map +1 -0
- package/codeyam-cli/src/utils/editorScenarios.js +56 -0
- package/codeyam-cli/src/utils/editorScenarios.js.map +1 -0
- package/codeyam-cli/src/utils/fileMetadata.js +5 -0
- package/codeyam-cli/src/utils/fileMetadata.js.map +1 -1
- package/codeyam-cli/src/utils/fileWatcher.js +25 -9
- package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
- package/codeyam-cli/src/utils/git.js +103 -0
- package/codeyam-cli/src/utils/git.js.map +1 -1
- package/codeyam-cli/src/utils/install-skills.js +55 -13
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/interactiveSyncWatcher.js +126 -0
- package/codeyam-cli/src/utils/interactiveSyncWatcher.js.map +1 -0
- package/codeyam-cli/src/utils/pathIgnoring.js +19 -7
- package/codeyam-cli/src/utils/pathIgnoring.js.map +1 -1
- package/codeyam-cli/src/utils/project.js +15 -5
- package/codeyam-cli/src/utils/project.js.map +1 -1
- package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js +11 -11
- package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js.map +1 -1
- package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +22 -0
- package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
- package/codeyam-cli/src/utils/queue/heartbeat.js +13 -5
- package/codeyam-cli/src/utils/queue/heartbeat.js.map +1 -1
- package/codeyam-cli/src/utils/queue/job.js +70 -1
- package/codeyam-cli/src/utils/queue/job.js.map +1 -1
- package/codeyam-cli/src/utils/queue/manager.js +7 -6
- package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
- package/codeyam-cli/src/utils/scenarioMarkers.js +134 -0
- package/codeyam-cli/src/utils/scenarioMarkers.js.map +1 -0
- package/codeyam-cli/src/utils/serverState.js +27 -2
- package/codeyam-cli/src/utils/serverState.js.map +1 -1
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +45 -4
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
- package/codeyam-cli/src/utils/testRunner.js +158 -0
- package/codeyam-cli/src/utils/testRunner.js.map +1 -0
- package/codeyam-cli/src/utils/webappDetection.js +14 -2
- package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
- package/codeyam-cli/src/webserver/app/lib/database.js +41 -27
- package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
- package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
- package/codeyam-cli/src/webserver/backgroundServer.js +108 -18
- package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{CopyButton-CtmbP4Gl.js → CopyButton-DmJveP3T.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DlMph_Hm.js → EntityItem-C76mRRiF.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-B-0PjGOU.js → EntityTypeBadge-g3saevPb.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-DN9eiJAO.js → EntityTypeIcon-CobE682z.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-rE_fI2h2.js → InteractivePreview-DYFW3lDD.js} +3 -3
- package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CnatsCw2.js → LibraryFunctionPreview-DLeucoVX.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-CSP6DZrh.js → LoadingDots-BU_OAEMP.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-CMK8Q7yk.js → LogViewer-ceAyBX-H.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-TCV_HBjy.js → ReportIssueModal-djPLI-WV.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-CG2uh31y.js → SafeScreenshot-BED4B6sP.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-CU_TDYd8.js → ScenarioViewer-B76aig_2.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +34 -0
- package/codeyam-cli/src/webserver/build/client/assets/Terminal-Dnj5CY9R.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-D7IoaWUW.js → TruncatedFilePath-C8OKAR5x.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{_index-B8z7mjR-.js → _index-C96V0n15.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DZu78RI1.js → activity.(_tab)-BpKzcsJz.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/addon-fit-CUXOrorO.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/addon-web-links-Duc5hnl7.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{agent-transcripts-Dm5RS9il.js → agent-transcripts-D9hemwl6.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/api.dev-mode-events-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-audit-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-capture-scenario-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-client-errors-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-commit-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-dev-server-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-entity-status-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-entry-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-image._-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-screenshot-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-update-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-load-commit-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-refresh-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-register-scenario-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-data-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-image._-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenarios-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-switch-scenario-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-test-results-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{book-open-Bp5FLkd4.js → book-open-D_nMCFmP.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-DQJA9f4o.js → chevron-down-BH2h1Ea2.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{chunk-JZWAC4HX-7VptmeIr.js → chunk-JZWAC4HX-C4pqxYJB.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{circle-check-B6C4LY9o.js → circle-check-DyIKORY6.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{copy-6nzYCu0G.js → copy-NDbZjXao.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-D-QUFOwe.js → createLucideIcon-CMT1jU2q.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BiM6z3Do.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor-D1DAKXtT.js +8 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-C6PQhwY5.js → entity._sha._-CrjR3zZW.js} +8 -8
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-DkzqFzFj.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-C28BiQzt.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-C7ysA4Jq.js → entity._sha_.edit._scenarioId-BMvVHNXU.js} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CU6EUArK.js → entry.client-DTvKq3TY.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-EWpfFU4X.js → fileTableUtils-cPo8LiG3.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{files-CrxAoWIL.js → files-DO4CZ16O.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{git-BldHtKeW.js → git-CFCTYk9I.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/globals-B17TBSS6.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{index-7-1FmlHo.js → index-10oVnAAH.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{index-DuYcwYp_.js → index-BcvgDzbZ.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{labs-CPPVOSWB.js → labs-Zk7ryIM1.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BnDcD54R.js → loader-circle-BAXYRVEO.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-a632de18.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{memory-0wMU4KXe.js → memory-Dg0mvYrI.js} +5 -2
- package/codeyam-cli/src/webserver/build/client/assets/{pause-DhQX2g22.js → pause-DTAcYxBt.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/root-DUKqhFlb.js +67 -0
- package/codeyam-cli/src/webserver/build/client/assets/{search-DborVoKD.js → search-fKo7v0Zo.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{settings-BWunYSXt.js → settings-DfuTtcJP.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{simulations-BtrtCYJg.js → simulations-B3aOzpCZ.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{terminal-Bs4NC-VZ.js → terminal-BG4heKCG.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-DTf3Jojp.js → triangle-alert-DtSmdtM4.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-D_bDZyDU.js → useCustomSizes-ByhSyh0W.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-C14nCb1q.js +2 -0
- package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-BsQb6rFd.js → useReportContext-O-jkvSPx.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{useToast-BOur3mUv.js → useToast-9FIWuYfK.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/xterm-BqvuqXEL.js +27 -0
- package/codeyam-cli/src/webserver/build/server/assets/index-HfLydfDq.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-CUu_F-oo.js +366 -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/devServer.js +39 -5
- package/codeyam-cli/src/webserver/devServer.js.map +1 -1
- package/codeyam-cli/src/webserver/editorProxy.js +440 -0
- package/codeyam-cli/src/webserver/editorProxy.js.map +1 -0
- package/codeyam-cli/src/webserver/scripts/codeyam-preload.mjs +175 -0
- package/codeyam-cli/src/webserver/scripts/journalCapture.ts +140 -0
- package/codeyam-cli/src/webserver/server.js +226 -1
- package/codeyam-cli/src/webserver/server.js.map +1 -1
- package/codeyam-cli/src/webserver/terminalServer.js +698 -0
- package/codeyam-cli/src/webserver/terminalServer.js.map +1 -0
- package/codeyam-cli/templates/codeyam-editor-claude.md +68 -0
- package/codeyam-cli/templates/editor-step-hook.py +147 -0
- package/codeyam-cli/templates/isolation-route/next-app.tsx.template +80 -0
- package/codeyam-cli/templates/isolation-route/next-pages.tsx.template +79 -0
- package/codeyam-cli/templates/isolation-route/vite-react.tsx.template +78 -0
- package/codeyam-cli/templates/msw/browser-setup.ts.template +47 -0
- package/codeyam-cli/templates/msw/handler-router.ts.template +47 -0
- package/codeyam-cli/templates/msw/server-setup.ts.template +52 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/PRISMA_SETUP.md +84 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/api/todos/route.ts +17 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/globals.css +26 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/layout.tsx +34 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +19 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/app/page.tsx +10 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/eslint.config.mjs +11 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/gitignore +43 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/next.config.ts +14 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +35 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/postcss.config.mjs +7 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/schema.prisma +27 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +37 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma.config.ts +12 -0
- package/codeyam-cli/templates/nextjs-prisma-sqlite/tsconfig.json +34 -0
- package/codeyam-cli/templates/skills/codeyam-dev-mode/SKILL.md +237 -0
- package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +69 -0
- package/codeyam-cli/templates/{codeyam-memory.md → skills/codeyam-memory/SKILL.md} +215 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/deprecated-prompt.md +100 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/detect-deprecated-patterns.sh +108 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/find-exports.sh +69 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/misleading-api-prompt.md +117 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/analyze-prompt.md +46 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/cleanup.sh +12 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/filter.jq +45 -0
- package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/preprocess.sh +139 -0
- package/package.json +4 -2
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +22 -4
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
- package/packages/ai/src/lib/completionCall.js +10 -2
- package/packages/ai/src/lib/completionCall.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +21 -0
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js +54 -0
- package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js +34 -0
- package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js.map +1 -0
- package/packages/ai/src/lib/generateEntityScenarioData.js +57 -2
- package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
- package/packages/analyze/src/lib/ProjectAnalyzer.js +3 -0
- package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +8 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +0 -5
- package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +9 -0
- package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +54 -27
- package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +65 -0
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +18 -4
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
- package/packages/database/index.js +1 -0
- package/packages/database/index.js.map +1 -1
- package/packages/database/src/lib/kysely/db.js +5 -0
- package/packages/database/src/lib/kysely/db.js.map +1 -1
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
- package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
- package/packages/database/src/lib/loadCommits.js +23 -13
- package/packages/database/src/lib/loadCommits.js.map +1 -1
- package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
- package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
- package/packages/database/src/lib/updateCommitMetadata.js +100 -89
- package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
- package/packages/database/src/lib/updateFreshAnalysisStatus.js +41 -30
- package/packages/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
- package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
- package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
- package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
- package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
- package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
- package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
- package/scripts/npm-post-install.cjs +34 -0
- package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-C1rIyZdV.js +0 -34
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-DmzSmblj.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-DVTcUnur.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-BVgNO76F.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/globals-CLmFdUae.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-717e346a.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/root-DqfSDjyQ.js +0 -62
- package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-DZp6rrQD.js +0 -2
- package/codeyam-cli/src/webserver/build/server/assets/index-B8jmgmn2.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-9OU4lmvL.js +0 -285
- package/scripts/finalize-analyzer.cjs +0 -13
- /package/codeyam-cli/templates/{codeyam-diagnose.md → commands/codeyam-diagnose.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-debug.md → skills/codeyam-debug/SKILL.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-new-rule.md → skills/codeyam-new-rule/SKILL.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-setup.md → skills/codeyam-setup/SKILL.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-sim.md → skills/codeyam-sim/SKILL.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-test.md → skills/codeyam-test/SKILL.md} +0 -0
- /package/codeyam-cli/templates/{codeyam-verify.md → skills/codeyam-verify/SKILL.md} +0 -0
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
var _a, _b;
|
|
2
|
+
import { WebSocketServer, WebSocket } from 'ws';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import * as pty from 'node-pty';
|
|
7
|
+
import { createMarkerTransformer } from "../utils/scenarioMarkers.js";
|
|
8
|
+
// Use globalThis so the sessions Set is shared across module instances.
|
|
9
|
+
// In Vite dev mode, this file is loaded twice: once by the Vite plugin (Node.js native)
|
|
10
|
+
// and once by the SSR context (ssrLoadModule). Without globalThis, each instance
|
|
11
|
+
// gets its own empty Set — so broadcastPreviewRefresh() called from the SSR instance
|
|
12
|
+
// (via the /api/dev-mode-preview endpoint) would broadcast to 0 sessions.
|
|
13
|
+
const sessions = ((_a = globalThis).__codeyamTerminalSessions ?? (_a.__codeyamTerminalSessions = new Set()));
|
|
14
|
+
// Detached PTYs waiting for reconnection (keyed by sessionId).
|
|
15
|
+
// When a WebSocket drops, the PTY is moved here with a grace timer
|
|
16
|
+
// instead of being killed immediately, allowing the client to reconnect.
|
|
17
|
+
const detachedPtys = ((_b = globalThis).__codeyamDetachedPtys ?? (_b.__codeyamDetachedPtys = new Map()));
|
|
18
|
+
const PING_INTERVAL_MS = 30000;
|
|
19
|
+
const DETACH_GRACE_MS = 60000;
|
|
20
|
+
const OUTPUT_BUFFER_MAX = 8 * 1024; // 8KB
|
|
21
|
+
// Ping interval reference — shared so cleanup can clear it
|
|
22
|
+
let pingInterval = globalThis.__codeyamPingInterval ?? null;
|
|
23
|
+
// Keys to forward from the server env into the PTY shell.
|
|
24
|
+
// Keeps the env clean (no giant CODEYAM_PROJECT JSON blobs) while
|
|
25
|
+
// preserving everything Claude Code and the user's shell need.
|
|
26
|
+
const ENV_PASSTHROUGH_KEYS = [
|
|
27
|
+
'PATH',
|
|
28
|
+
'HOME',
|
|
29
|
+
'USER',
|
|
30
|
+
'LOGNAME',
|
|
31
|
+
'SHELL',
|
|
32
|
+
'TERM',
|
|
33
|
+
'LANG',
|
|
34
|
+
'LC_ALL',
|
|
35
|
+
'LC_CTYPE',
|
|
36
|
+
'EDITOR',
|
|
37
|
+
'VISUAL',
|
|
38
|
+
'TMPDIR',
|
|
39
|
+
'XDG_CONFIG_HOME',
|
|
40
|
+
'XDG_DATA_HOME',
|
|
41
|
+
'XDG_CACHE_HOME',
|
|
42
|
+
// API keys Claude Code may need
|
|
43
|
+
'ANTHROPIC_API_KEY',
|
|
44
|
+
'OPENAI_API_KEY',
|
|
45
|
+
// nvm / fnm / volta node version managers
|
|
46
|
+
'NVM_DIR',
|
|
47
|
+
'NVM_BIN',
|
|
48
|
+
'FNM_DIR',
|
|
49
|
+
'VOLTA_HOME',
|
|
50
|
+
// Homebrew
|
|
51
|
+
'HOMEBREW_PREFIX',
|
|
52
|
+
'HOMEBREW_CELLAR',
|
|
53
|
+
'HOMEBREW_REPOSITORY',
|
|
54
|
+
];
|
|
55
|
+
function buildPtyEnv() {
|
|
56
|
+
const env = {};
|
|
57
|
+
for (const key of ENV_PASSTHROUGH_KEYS) {
|
|
58
|
+
const val = process.env[key];
|
|
59
|
+
if (val != null)
|
|
60
|
+
env[key] = val;
|
|
61
|
+
}
|
|
62
|
+
// Always set TERM for proper terminal behavior
|
|
63
|
+
if (!env.TERM)
|
|
64
|
+
env.TERM = 'xterm-256color';
|
|
65
|
+
return env;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert a name to a safe file name matching CodeYam's convention.
|
|
69
|
+
* e.g. "Default Scenario" -> "Default_Scenario"
|
|
70
|
+
*/
|
|
71
|
+
function safeFileName(name) {
|
|
72
|
+
const safe = name.replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
|
|
73
|
+
return safe.slice(0, 1).toUpperCase() + safe.slice(1);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Find the actual mock data file for a scenario in the tmp project.
|
|
77
|
+
* Tries a fast heuristic (extract app dir from entity file path) first,
|
|
78
|
+
* then falls back to a shallow directory search.
|
|
79
|
+
*/
|
|
80
|
+
function findMockDataFile(projectRoot, entityFilePath, scenarioName) {
|
|
81
|
+
const scenarioSlug = safeFileName(scenarioName);
|
|
82
|
+
const mockFile = `MockData_${scenarioSlug}.tsx`;
|
|
83
|
+
// Heuristic: the __codeyamMocks__ dir lives at the app directory level.
|
|
84
|
+
// Extract "app/" (or "src/", "pages/") from the entity's file path.
|
|
85
|
+
if (entityFilePath) {
|
|
86
|
+
const parts = entityFilePath.split('/');
|
|
87
|
+
for (let i = 0; i < parts.length; i++) {
|
|
88
|
+
if (['app', 'src', 'pages'].includes(parts[i])) {
|
|
89
|
+
const appDir = parts.slice(0, i + 1).join('/');
|
|
90
|
+
const candidate = path.join(projectRoot, appDir, '__codeyamMocks__', mockFile);
|
|
91
|
+
if (fs.existsSync(candidate))
|
|
92
|
+
return candidate;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Fallback: search __codeyamMocks__ directories up to 5 levels deep
|
|
97
|
+
function searchDir(dir, depth) {
|
|
98
|
+
if (depth > 5)
|
|
99
|
+
return null;
|
|
100
|
+
try {
|
|
101
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
102
|
+
if (entry === 'node_modules' ||
|
|
103
|
+
entry === '.git' ||
|
|
104
|
+
entry === 'coverage')
|
|
105
|
+
continue;
|
|
106
|
+
const full = path.join(dir, entry);
|
|
107
|
+
if (entry === '__codeyamMocks__') {
|
|
108
|
+
const candidate = path.join(full, mockFile);
|
|
109
|
+
if (fs.existsSync(candidate))
|
|
110
|
+
return candidate;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
if (fs.statSync(full).isDirectory()) {
|
|
115
|
+
const result = searchDir(full, depth + 1);
|
|
116
|
+
if (result)
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Permission error or broken symlink
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Directory unreadable
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return searchDir(projectRoot, 0);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Write a structured context file for the codeyam-dev-mode skill.
|
|
134
|
+
* The skill reads this file on startup instead of receiving a long CLI argument.
|
|
135
|
+
* Returns true if context was written successfully, false otherwise.
|
|
136
|
+
*/
|
|
137
|
+
function writeDevModeContext(ctx) {
|
|
138
|
+
if (!ctx.entityName)
|
|
139
|
+
return false;
|
|
140
|
+
const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
|
|
141
|
+
const contextDir = path.join(codeyamRoot, '.codeyam');
|
|
142
|
+
const contextPath = path.join(contextDir, 'dev-mode-context.md');
|
|
143
|
+
try {
|
|
144
|
+
fs.mkdirSync(contextDir, { recursive: true });
|
|
145
|
+
const lines = ['# Dev Mode Context', ''];
|
|
146
|
+
// Entity section
|
|
147
|
+
lines.push('## Entity');
|
|
148
|
+
lines.push(`- **Name:** ${ctx.entityName}`);
|
|
149
|
+
if (ctx.entityType)
|
|
150
|
+
lines.push(`- **Type:** ${ctx.entityType}`);
|
|
151
|
+
if (ctx.entitySha)
|
|
152
|
+
lines.push(`- **SHA:** ${ctx.entitySha}`);
|
|
153
|
+
if (ctx.entityFilePath)
|
|
154
|
+
lines.push(`- **Source file:** ${ctx.entityFilePath}`);
|
|
155
|
+
lines.push('');
|
|
156
|
+
// Scenario section
|
|
157
|
+
if (ctx.scenarioName) {
|
|
158
|
+
lines.push('## Scenario');
|
|
159
|
+
lines.push(`- **Name:** ${ctx.scenarioName}`);
|
|
160
|
+
if (ctx.scenarioDescription)
|
|
161
|
+
lines.push(`- **Description:** ${ctx.scenarioDescription}`);
|
|
162
|
+
if (ctx.analysisId)
|
|
163
|
+
lines.push(`- **Analysis ID:** ${ctx.analysisId}`);
|
|
164
|
+
lines.push('');
|
|
165
|
+
}
|
|
166
|
+
// Files section
|
|
167
|
+
lines.push('## Files');
|
|
168
|
+
if (ctx.entityFilePath) {
|
|
169
|
+
lines.push(`- **Source file:** ${ctx.entityFilePath}`);
|
|
170
|
+
}
|
|
171
|
+
if (ctx.projectSlug && ctx.scenarioName) {
|
|
172
|
+
const tmpBase = `/tmp/codeyam/local-dev/${ctx.projectSlug}`;
|
|
173
|
+
const tmpProject = `${tmpBase}/project`;
|
|
174
|
+
const mockDataPath = findMockDataFile(tmpProject, ctx.entityFilePath, ctx.scenarioName);
|
|
175
|
+
if (mockDataPath) {
|
|
176
|
+
lines.push(`- **Mock data:** ${mockDataPath}`);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const scenarioSlug = safeFileName(ctx.scenarioName);
|
|
180
|
+
lines.push(`- **Mock data:** search for \`MockData_${scenarioSlug}.tsx\` in \`__codeyamMocks__\` under ${tmpProject}`);
|
|
181
|
+
}
|
|
182
|
+
lines.push(`- **Dev server project:** ${tmpProject}`);
|
|
183
|
+
lines.push(`- **Server log:** ${tmpBase}/codeyam/log.txt`);
|
|
184
|
+
}
|
|
185
|
+
lines.push('');
|
|
186
|
+
// Database
|
|
187
|
+
lines.push('## Database');
|
|
188
|
+
lines.push(`- **Path:** .codeyam/db.sqlite3`);
|
|
189
|
+
lines.push('');
|
|
190
|
+
// Server
|
|
191
|
+
const serverPort = process.env.CODEYAM_PORT || '3111';
|
|
192
|
+
lines.push('## Server');
|
|
193
|
+
lines.push(`- **Refresh preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-preview\``);
|
|
194
|
+
lines.push('');
|
|
195
|
+
fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
console.error('[terminalServer] Failed to write dev-mode-context.md:', error);
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Write a structured context file for the codeyam-editor skill.
|
|
205
|
+
* Returns true if context was written successfully, false otherwise.
|
|
206
|
+
*/
|
|
207
|
+
function writeEditorModeContext(ctx) {
|
|
208
|
+
if (!ctx.projectSlug)
|
|
209
|
+
return false;
|
|
210
|
+
const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
|
|
211
|
+
const contextDir = path.join(codeyamRoot, '.codeyam');
|
|
212
|
+
const contextPath = path.join(contextDir, 'editor-mode-context.md');
|
|
213
|
+
try {
|
|
214
|
+
fs.mkdirSync(contextDir, { recursive: true });
|
|
215
|
+
const serverPort = process.env.CODEYAM_PORT || '3111';
|
|
216
|
+
const proxyPort = parseInt(serverPort, 10) + 1;
|
|
217
|
+
const lines = [
|
|
218
|
+
'# Editor Mode Context',
|
|
219
|
+
'',
|
|
220
|
+
'## Project',
|
|
221
|
+
`- **Root:** ${codeyamRoot}`,
|
|
222
|
+
`- **Slug:** ${ctx.projectSlug}`,
|
|
223
|
+
'',
|
|
224
|
+
'## Server',
|
|
225
|
+
`- **Port:** ${serverPort}`,
|
|
226
|
+
`- **Dashboard:** http://localhost:${serverPort}/editor`,
|
|
227
|
+
`- **Proxy:** http://localhost:${proxyPort} (used by the browser iframe only — do NOT use for health checks)`,
|
|
228
|
+
'',
|
|
229
|
+
'## Workflow',
|
|
230
|
+
'- **Guided steps:** Run `codeyam editor` for the next step (plan → prototype → confirm → deconstruct → extract → glossary → analyze → app scenarios → user scenarios → verify → journal → review)',
|
|
231
|
+
'- Each feature follows 12 steps: `codeyam editor 1` through `codeyam editor 12`',
|
|
232
|
+
'- Steps 1, 3, and 12 require user confirmation before proceeding',
|
|
233
|
+
'',
|
|
234
|
+
'## Verifying the Dev Server',
|
|
235
|
+
'- Get the dev server URL: `curl -s http://localhost:' +
|
|
236
|
+
serverPort +
|
|
237
|
+
'/api/editor-dev-server` → look at the `"url"` field (e.g., `http://localhost:3000`)',
|
|
238
|
+
'- Check the page loads: `curl -s -o /dev/null -w "%{http_code}" http://localhost:3000` (use the actual dev server URL, NOT the proxy)',
|
|
239
|
+
'- Check API routes work: `curl -s http://localhost:3000/api/your-route` (should return JSON, not "Internal Server Error")',
|
|
240
|
+
'- **NEVER check localhost:' +
|
|
241
|
+
proxyPort +
|
|
242
|
+
' for health** — the proxy returns 200 even when the app is broken',
|
|
243
|
+
'',
|
|
244
|
+
'## API Endpoints',
|
|
245
|
+
`- **Register scenario (auto-captures screenshot):** \`codeyam editor register '{"name":"...","description":"...","mockData":{"routes":{"/api/tasks":{"body":[...]}}}}'\``,
|
|
246
|
+
`- **Get active scenario data:** \`curl http://localhost:${serverPort}/api/editor-scenario-data\``,
|
|
247
|
+
`- **Refresh/navigate preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-preview\` (no body = refresh; with \`{"path":"/route"}\` = navigate; with \`{"scenarioSlug":"..."}\` = switch scenario). Clears logs, waits for HMR, checks SSR health.`,
|
|
248
|
+
`- **Refresh config:** \`curl -X POST http://localhost:${serverPort}/api/editor-refresh\` (also starts dev server if a webapp is detected)`,
|
|
249
|
+
`- **Dev server status:** \`curl http://localhost:${serverPort}/api/editor-dev-server\``,
|
|
250
|
+
`- **Start dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"start"}'\``,
|
|
251
|
+
`- **Restart dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"restart"}'\``,
|
|
252
|
+
`- **Re-capture scenario screenshot:** \`curl -X POST http://localhost:${serverPort}/api/editor-capture-scenario -H 'Content-Type: application/json' -d '{"scenarioId":"...","url":"..."}'\` (for manual re-capture; register auto-captures)`,
|
|
253
|
+
`- **Journal screenshot:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-screenshot -H 'Content-Type: application/json' -d '{"url":"...","filename":"..."}'\``,
|
|
254
|
+
`- **Journal entry:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-entry -H 'Content-Type: application/json' -d '{"title":"...","type":"feature","description":"..."}'\``,
|
|
255
|
+
'',
|
|
256
|
+
'## Scenario Data Format',
|
|
257
|
+
'- Use **route-keyed** mock data: keys are the API paths your app fetches',
|
|
258
|
+
'- Example: `{ "routes": { "/api/tasks": { "body": [...] }, "/api/users": { "body": [...] } } }`',
|
|
259
|
+
'- Error scenarios: `{ "routes": { "/api/tasks": { "status": 500, "body": { "error": "..." } } } }`',
|
|
260
|
+
'- The proxy intercepts GET requests to matching routes and returns the mock data',
|
|
261
|
+
'- POST/PUT/DELETE always go through to the real dev server',
|
|
262
|
+
'',
|
|
263
|
+
'## Component Isolation Routes',
|
|
264
|
+
'- To screenshot individual components, create ONE isolation route per component:',
|
|
265
|
+
' - **Remix:** `app/routes/codeyam-isolate.ComponentName.tsx` → `/codeyam-isolate/ComponentName`',
|
|
266
|
+
' - **Next.js:** `app/codeyam-isolate/ComponentName/page.tsx` → `/codeyam-isolate/ComponentName`',
|
|
267
|
+
'- The route defines a `scenarios` object mapping scenario names to props, reads `?s=ScenarioName` from the URL, and renders the component',
|
|
268
|
+
'- Wrap the component in a centered container: `<div style="display:flex;justify-content:center;align-items:center;min-height:100vh;padding:20px"><div style="width:100%;max-width:...">` — set max-width to match the component\'s real container (e.g. card in 3-col grid → 24rem)',
|
|
269
|
+
'- **Create multiple scenarios per component** (like tests): default/happy path, edge cases (empty data, long text, max items), different visual states (loading, error, disabled)',
|
|
270
|
+
'- Register each scenario: `codeyam editor register \'{"name":"ComponentName - Scenario","componentName":"ComponentName","componentPath":"path/to/file.tsx","url":"/codeyam-isolate/ComponentName?s=Scenario","mockData":{"routes":{"/api/...":{"body":[...]}}}}\'`',
|
|
271
|
+
'- The url is a PATH, not a full URL — the proxy appends it and intercepts API calls the component makes',
|
|
272
|
+
'- `mockData.routes` provides data for any API calls the component makes internally (omit if none)',
|
|
273
|
+
'- Isolation routes stay in the project so the editor preview can display them',
|
|
274
|
+
'- Ensure `.gitignore` includes `**/codeyam-isolate*` so they are not committed',
|
|
275
|
+
'',
|
|
276
|
+
'## Files',
|
|
277
|
+
'- **Scenario data:** .codeyam/editor-scenarios/{scenario-id}.json',
|
|
278
|
+
'- **Scenario screenshots:** .codeyam/editor-scenarios/screenshots/{scenario-id}.png',
|
|
279
|
+
'- **Active scenario:** .codeyam/active-scenario.json',
|
|
280
|
+
'- **Database:** .codeyam/db.sqlite3',
|
|
281
|
+
'- **Journal:** .codeyam/journal/ (daily .md files + index.json + screenshots/)',
|
|
282
|
+
'',
|
|
283
|
+
];
|
|
284
|
+
// Check if package.json exists to give context about project state
|
|
285
|
+
const hasPackageJson = fs.existsSync(path.join(codeyamRoot, 'package.json'));
|
|
286
|
+
if (!hasPackageJson) {
|
|
287
|
+
lines.push('## Status');
|
|
288
|
+
lines.push('- **Empty project** — no package.json found. Ask the user what they want to build.');
|
|
289
|
+
lines.push('');
|
|
290
|
+
}
|
|
291
|
+
fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
console.error('[terminalServer] Failed to write editor-mode-context.md:', error);
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Attach a WebSocket server at /ws/terminal to an existing HTTP server.
|
|
301
|
+
* Each WS connection spawns a PTY running the user's shell, then auto-starts `claude`.
|
|
302
|
+
*
|
|
303
|
+
* Features:
|
|
304
|
+
* - Ping/pong keepalive (30s interval) to detect dead connections
|
|
305
|
+
* - PTY detach/reattach: on WS close the PTY survives for 60s, allowing the client
|
|
306
|
+
* to reconnect with ?reconnectId=<sessionId> and reattach to the same PTY
|
|
307
|
+
* - Session IDs sent to client on connection for reconnect tracking
|
|
308
|
+
*/
|
|
309
|
+
export function attachTerminalServer(httpServer) {
|
|
310
|
+
const wss = new WebSocketServer({ server: httpServer, path: '/ws/terminal' });
|
|
311
|
+
// --- Ping/pong keepalive ---
|
|
312
|
+
// The browser's native WebSocket automatically responds to ping frames with pong.
|
|
313
|
+
if (pingInterval)
|
|
314
|
+
clearInterval(pingInterval);
|
|
315
|
+
pingInterval = setInterval(() => {
|
|
316
|
+
for (const session of sessions) {
|
|
317
|
+
if (!session.isAlive) {
|
|
318
|
+
// Didn't respond to last ping — terminate
|
|
319
|
+
console.log(`[terminalServer] Session ${session.sessionId} ping timeout, terminating`);
|
|
320
|
+
session.ws.terminate();
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
session.isAlive = false;
|
|
324
|
+
session.ws.ping();
|
|
325
|
+
}
|
|
326
|
+
}, PING_INTERVAL_MS);
|
|
327
|
+
globalThis.__codeyamPingInterval = pingInterval;
|
|
328
|
+
wss.on('connection', (ws, req) => {
|
|
329
|
+
// Parse entity context from query params
|
|
330
|
+
const url = new URL(req.url || '', `http://${req.headers.host}`);
|
|
331
|
+
const entityName = url.searchParams.get('entityName') || '';
|
|
332
|
+
const entityType = url.searchParams.get('entityType') || '';
|
|
333
|
+
const entitySha = url.searchParams.get('entitySha') || '';
|
|
334
|
+
const entityFilePath = url.searchParams.get('entityFilePath') || '';
|
|
335
|
+
const scenarioName = url.searchParams.get('scenarioName') || '';
|
|
336
|
+
const scenarioDescription = url.searchParams.get('scenarioDescription') || '';
|
|
337
|
+
const analysisId = url.searchParams.get('analysisId') || '';
|
|
338
|
+
const projectSlug = url.searchParams.get('projectSlug') || '';
|
|
339
|
+
const editorMode = url.searchParams.get('editorMode') === 'true';
|
|
340
|
+
const reconnectId = url.searchParams.get('reconnectId') || '';
|
|
341
|
+
// --- Reconnection: reattach to a detached PTY ---
|
|
342
|
+
if (reconnectId && detachedPtys.has(reconnectId)) {
|
|
343
|
+
const detached = detachedPtys.get(reconnectId);
|
|
344
|
+
clearTimeout(detached.graceTimer);
|
|
345
|
+
detachedPtys.delete(reconnectId);
|
|
346
|
+
console.log(`[terminalServer] Reattaching session ${reconnectId}`);
|
|
347
|
+
const session = {
|
|
348
|
+
ws,
|
|
349
|
+
ptyProcess: detached.ptyProcess,
|
|
350
|
+
sessionId: detached.sessionId,
|
|
351
|
+
isAlive: true,
|
|
352
|
+
};
|
|
353
|
+
sessions.add(session);
|
|
354
|
+
// Send session ID so client can track it
|
|
355
|
+
ws.send(JSON.stringify({ type: 'session-id', sessionId: session.sessionId }));
|
|
356
|
+
// Send buffered output so client catches up
|
|
357
|
+
if (detached.outputBuffer) {
|
|
358
|
+
ws.send(JSON.stringify({ type: 'output', data: detached.outputBuffer }));
|
|
359
|
+
}
|
|
360
|
+
// Re-wire PTY output -> new WebSocket
|
|
361
|
+
// node-pty's onData returns a disposable; the old listener was still attached
|
|
362
|
+
// and was buffering output into detached.outputBuffer. We need to replace it.
|
|
363
|
+
// Unfortunately node-pty doesn't expose removeListener, so we use a closure flag.
|
|
364
|
+
let detachedFlag = false;
|
|
365
|
+
const reconnectPort = process.env.CODEYAM_PORT || '3111';
|
|
366
|
+
const reconnectTransformMarkers = createMarkerTransformer(reconnectPort);
|
|
367
|
+
detached.ptyProcess.onData((data) => {
|
|
368
|
+
if (detachedFlag)
|
|
369
|
+
return; // Superseded by a newer listener
|
|
370
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
371
|
+
if (!detached.hasClearedScreen &&
|
|
372
|
+
detached.hasContext &&
|
|
373
|
+
data.includes('╭')) {
|
|
374
|
+
detached.hasClearedScreen = true;
|
|
375
|
+
ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
|
|
376
|
+
}
|
|
377
|
+
const transformed = reconnectTransformMarkers(data);
|
|
378
|
+
if (transformed.length > 0) {
|
|
379
|
+
ws.send(JSON.stringify({ type: 'output', data: transformed }));
|
|
380
|
+
}
|
|
381
|
+
const stripped = data.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
|
|
382
|
+
if (stripped.includes('Editor Mode \u2014')) {
|
|
383
|
+
console.log('[terminalServer] Detected claude-idle signal (reconnect)');
|
|
384
|
+
ws.send(JSON.stringify({ type: 'claude-idle' }));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
detached.ptyProcess.onExit(() => {
|
|
389
|
+
sessions.delete(session);
|
|
390
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
391
|
+
ws.close();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
// WebSocket messages -> PTY
|
|
395
|
+
ws.on('message', (raw) => {
|
|
396
|
+
try {
|
|
397
|
+
const msg = JSON.parse(raw.toString());
|
|
398
|
+
if (msg.type === 'input') {
|
|
399
|
+
detached.ptyProcess.write(msg.data);
|
|
400
|
+
}
|
|
401
|
+
else if (msg.type === 'resize' && msg.cols && msg.rows) {
|
|
402
|
+
detached.ptyProcess.resize(msg.cols, msg.rows);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
detached.ptyProcess.write(raw.toString());
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
ws.on('pong', () => {
|
|
410
|
+
session.isAlive = true;
|
|
411
|
+
});
|
|
412
|
+
ws.on('close', () => {
|
|
413
|
+
detachedFlag = true;
|
|
414
|
+
detachSession(session, detached.hasContext, detached.hasClearedScreen);
|
|
415
|
+
});
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
// --- New connection: spawn a fresh PTY ---
|
|
419
|
+
const shell = process.env.SHELL || '/bin/zsh';
|
|
420
|
+
const cwd = process.env.CODEYAM_ROOT_PATH || process.cwd();
|
|
421
|
+
// Verify cwd exists, fall back to HOME
|
|
422
|
+
const safeCwd = fs.existsSync(cwd) ? cwd : process.env.HOME || '/tmp';
|
|
423
|
+
// Spawn PTY with a clean env (no giant JSON blobs from CODEYAM_PROJECT etc.)
|
|
424
|
+
let ptyProcess;
|
|
425
|
+
try {
|
|
426
|
+
ptyProcess = pty.spawn(shell, ['-l'], {
|
|
427
|
+
name: 'xterm-256color',
|
|
428
|
+
cols: 120,
|
|
429
|
+
rows: 30,
|
|
430
|
+
cwd: safeCwd,
|
|
431
|
+
env: buildPtyEnv(),
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
console.error('[terminalServer] Failed to spawn PTY:', {
|
|
436
|
+
shell,
|
|
437
|
+
cwd: safeCwd,
|
|
438
|
+
error,
|
|
439
|
+
});
|
|
440
|
+
ws.send(JSON.stringify({
|
|
441
|
+
type: 'output',
|
|
442
|
+
data: `\r\nFailed to start terminal: ${error.message}\r\n`,
|
|
443
|
+
}));
|
|
444
|
+
ws.close();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const sessionId = crypto.randomUUID();
|
|
448
|
+
const session = {
|
|
449
|
+
ws,
|
|
450
|
+
ptyProcess,
|
|
451
|
+
sessionId,
|
|
452
|
+
isAlive: true,
|
|
453
|
+
};
|
|
454
|
+
sessions.add(session);
|
|
455
|
+
// Send session ID so client can use it for reconnection
|
|
456
|
+
ws.send(JSON.stringify({ type: 'session-id', sessionId }));
|
|
457
|
+
// Write context file for the appropriate skill (dev-mode or editor)
|
|
458
|
+
const hasContext = editorMode
|
|
459
|
+
? writeEditorModeContext({ projectSlug })
|
|
460
|
+
: writeDevModeContext({
|
|
461
|
+
entityName,
|
|
462
|
+
entityType,
|
|
463
|
+
entitySha,
|
|
464
|
+
entityFilePath,
|
|
465
|
+
scenarioName,
|
|
466
|
+
scenarioDescription,
|
|
467
|
+
analysisId,
|
|
468
|
+
projectSlug,
|
|
469
|
+
});
|
|
470
|
+
let hasClearedScreen = false;
|
|
471
|
+
// Rolling buffer of trailing text to detect "Editor Mode —" across PTY chunks.
|
|
472
|
+
let idleDetectBuffer = '';
|
|
473
|
+
const IDLE_MARKER = 'Editor Mode \u2014';
|
|
474
|
+
// PTY output -> WebSocket
|
|
475
|
+
const serverPort = process.env.CODEYAM_PORT || '3111';
|
|
476
|
+
// Stateful transformer that buffers partial {{scenario:...}} markers
|
|
477
|
+
// across PTY chunks so they don't appear as raw text.
|
|
478
|
+
const transformMarkers = createMarkerTransformer(serverPort);
|
|
479
|
+
ptyProcess.onData((data) => {
|
|
480
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
481
|
+
// When Claude Code starts (indicated by its box-drawing welcome banner),
|
|
482
|
+
// clear the screen to hide the raw shell command.
|
|
483
|
+
if (!hasClearedScreen && hasContext && data.includes('╭')) {
|
|
484
|
+
hasClearedScreen = true;
|
|
485
|
+
ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
|
|
486
|
+
}
|
|
487
|
+
// Transform {{scenario:Name:ID}} markers into OSC 8 clickable hyperlinks.
|
|
488
|
+
// Uses stateful buffering to handle markers split across PTY chunks.
|
|
489
|
+
const transformed = transformMarkers(data);
|
|
490
|
+
if (transformed.length > 0) {
|
|
491
|
+
ws.send(JSON.stringify({ type: 'output', data: transformed }));
|
|
492
|
+
}
|
|
493
|
+
// Detect the Stop hook output — signals Claude is waiting for user input.
|
|
494
|
+
// The hook outputs "Editor Mode —" when Claude finishes a turn.
|
|
495
|
+
// Strip ANSI escape codes and check buffer+current to handle cross-chunk splits.
|
|
496
|
+
const stripped = data.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
|
|
497
|
+
const combined = idleDetectBuffer + stripped;
|
|
498
|
+
if (combined.includes(IDLE_MARKER)) {
|
|
499
|
+
console.log('[terminalServer] Detected claude-idle signal');
|
|
500
|
+
ws.send(JSON.stringify({ type: 'claude-idle' }));
|
|
501
|
+
idleDetectBuffer = '';
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
// Keep trailing chars in case the marker spans two chunks
|
|
505
|
+
idleDetectBuffer = stripped.slice(-(IDLE_MARKER.length - 1));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
ptyProcess.onExit(() => {
|
|
510
|
+
sessions.delete(session);
|
|
511
|
+
// Also clean up from detachedPtys if it was detached
|
|
512
|
+
if (detachedPtys.has(sessionId)) {
|
|
513
|
+
clearTimeout(detachedPtys.get(sessionId).graceTimer);
|
|
514
|
+
detachedPtys.delete(sessionId);
|
|
515
|
+
}
|
|
516
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
517
|
+
ws.close();
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
// WebSocket messages -> PTY
|
|
521
|
+
ws.on('message', (raw) => {
|
|
522
|
+
try {
|
|
523
|
+
const msg = JSON.parse(raw.toString());
|
|
524
|
+
if (msg.type === 'input') {
|
|
525
|
+
ptyProcess.write(msg.data);
|
|
526
|
+
}
|
|
527
|
+
else if (msg.type === 'resize' && msg.cols && msg.rows) {
|
|
528
|
+
ptyProcess.resize(msg.cols, msg.rows);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
// Non-JSON message, treat as raw input
|
|
533
|
+
ptyProcess.write(raw.toString());
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
ws.on('pong', () => {
|
|
537
|
+
session.isAlive = true;
|
|
538
|
+
});
|
|
539
|
+
ws.on('close', () => {
|
|
540
|
+
detachSession(session, hasContext, hasClearedScreen);
|
|
541
|
+
});
|
|
542
|
+
// Start Claude Code with the appropriate skill.
|
|
543
|
+
// Using a skill avoids shell escaping issues and multi-line paste detection.
|
|
544
|
+
setTimeout(() => {
|
|
545
|
+
if (editorMode && hasContext) {
|
|
546
|
+
ptyProcess.write("claude '/codeyam-editor'\r");
|
|
547
|
+
}
|
|
548
|
+
else if (hasContext) {
|
|
549
|
+
ptyProcess.write("claude '/codeyam-dev-mode'\r");
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
ptyProcess.write('claude\r');
|
|
553
|
+
}
|
|
554
|
+
}, 500);
|
|
555
|
+
});
|
|
556
|
+
console.log('[terminalServer] WebSocket terminal server attached at /ws/terminal');
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Detach a session's PTY instead of killing it, giving the client time to reconnect.
|
|
560
|
+
* The PTY is moved to `detachedPtys` with a grace timer; if the client reconnects
|
|
561
|
+
* within DETACH_GRACE_MS, the PTY is reattached. Otherwise it's killed.
|
|
562
|
+
*/
|
|
563
|
+
function detachSession(session, hasContext = false, hasClearedScreen = false) {
|
|
564
|
+
sessions.delete(session);
|
|
565
|
+
const { sessionId, ptyProcess } = session;
|
|
566
|
+
// If already detached (shouldn't happen), skip
|
|
567
|
+
if (detachedPtys.has(sessionId))
|
|
568
|
+
return;
|
|
569
|
+
let outputBuffer = '';
|
|
570
|
+
// Buffer PTY output during detachment so the client can catch up on reconnect
|
|
571
|
+
ptyProcess.onData((data) => {
|
|
572
|
+
outputBuffer += data;
|
|
573
|
+
// Cap buffer size
|
|
574
|
+
if (outputBuffer.length > OUTPUT_BUFFER_MAX) {
|
|
575
|
+
outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_MAX);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
const graceTimer = setTimeout(() => {
|
|
579
|
+
console.log(`[terminalServer] Grace period expired for session ${sessionId}, killing PTY`);
|
|
580
|
+
detachedPtys.delete(sessionId);
|
|
581
|
+
try {
|
|
582
|
+
ptyProcess.kill();
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
/* already dead */
|
|
586
|
+
}
|
|
587
|
+
}, DETACH_GRACE_MS);
|
|
588
|
+
detachedPtys.set(sessionId, {
|
|
589
|
+
ptyProcess,
|
|
590
|
+
sessionId,
|
|
591
|
+
graceTimer,
|
|
592
|
+
outputBuffer,
|
|
593
|
+
hasContext,
|
|
594
|
+
hasClearedScreen,
|
|
595
|
+
});
|
|
596
|
+
console.log(`[terminalServer] Session ${sessionId} detached, PTY kept alive for ${DETACH_GRACE_MS / 1000}s`);
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Send a refresh-preview message to all connected terminal WebSocket clients.
|
|
600
|
+
* The Terminal component relays this to the parent page to reload the iframe.
|
|
601
|
+
*/
|
|
602
|
+
export function broadcastPreviewRefresh(path) {
|
|
603
|
+
const msg = JSON.stringify({
|
|
604
|
+
type: 'refresh-preview',
|
|
605
|
+
...(path && { path }),
|
|
606
|
+
});
|
|
607
|
+
let count = 0;
|
|
608
|
+
for (const session of sessions) {
|
|
609
|
+
try {
|
|
610
|
+
if (session.ws.readyState === WebSocket.OPEN) {
|
|
611
|
+
session.ws.send(msg);
|
|
612
|
+
count++;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
// Ignore send errors
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return count;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Show the results panel below the terminal in the Build tab.
|
|
623
|
+
* Triggered by Claude at end of step 12.
|
|
624
|
+
*/
|
|
625
|
+
export function broadcastShowResults() {
|
|
626
|
+
const msg = JSON.stringify({ type: 'show-results' });
|
|
627
|
+
let count = 0;
|
|
628
|
+
for (const session of sessions) {
|
|
629
|
+
try {
|
|
630
|
+
if (session.ws.readyState === WebSocket.OPEN) {
|
|
631
|
+
session.ws.send(msg);
|
|
632
|
+
count++;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch {
|
|
636
|
+
// Ignore send errors
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return count;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Hide the results panel (e.g. after Save & Commit).
|
|
643
|
+
*/
|
|
644
|
+
export function broadcastHideResults() {
|
|
645
|
+
const msg = JSON.stringify({ type: 'hide-results' });
|
|
646
|
+
let count = 0;
|
|
647
|
+
for (const session of sessions) {
|
|
648
|
+
try {
|
|
649
|
+
if (session.ws.readyState === WebSocket.OPEN) {
|
|
650
|
+
session.ws.send(msg);
|
|
651
|
+
count++;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
// Ignore send errors
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return count;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Kill all active PTY sessions and detached PTYs. Call during shutdown.
|
|
662
|
+
*/
|
|
663
|
+
export function cleanupAllTerminalSessions() {
|
|
664
|
+
// Clear ping interval
|
|
665
|
+
if (pingInterval) {
|
|
666
|
+
clearInterval(pingInterval);
|
|
667
|
+
pingInterval = null;
|
|
668
|
+
globalThis.__codeyamPingInterval = null;
|
|
669
|
+
}
|
|
670
|
+
// Clean up active sessions
|
|
671
|
+
for (const session of Array.from(sessions)) {
|
|
672
|
+
try {
|
|
673
|
+
session.ptyProcess.kill();
|
|
674
|
+
}
|
|
675
|
+
catch {
|
|
676
|
+
// Already dead
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
session.ws.close();
|
|
680
|
+
}
|
|
681
|
+
catch {
|
|
682
|
+
// Already closed
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
sessions.clear();
|
|
686
|
+
// Clean up detached PTYs
|
|
687
|
+
for (const [, detached] of detachedPtys) {
|
|
688
|
+
clearTimeout(detached.graceTimer);
|
|
689
|
+
try {
|
|
690
|
+
detached.ptyProcess.kill();
|
|
691
|
+
}
|
|
692
|
+
catch {
|
|
693
|
+
// Already dead
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
detachedPtys.clear();
|
|
697
|
+
}
|
|
698
|
+
//# sourceMappingURL=terminalServer.js.map
|