browser-debugger-cli 0.0.1-alpha.0 → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +167 -52
- package/dist/__testfixtures__/cdpMessages.d.ts +43 -0
- package/dist/__testfixtures__/cdpMessages.d.ts.map +1 -0
- package/dist/__testfixtures__/cdpMessages.js +118 -0
- package/dist/__testfixtures__/cdpMessages.js.map +1 -0
- package/dist/__testfixtures__/connectionTargets.d.ts +21 -0
- package/dist/__testfixtures__/connectionTargets.d.ts.map +1 -0
- package/dist/__testfixtures__/connectionTargets.js +59 -0
- package/dist/__testfixtures__/connectionTargets.js.map +1 -0
- package/dist/__tests__/integration/session-files.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/session-files.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/session-files.integration.test.js +66 -0
- package/dist/__tests__/integration/session-files.integration.test.js.map +1 -0
- package/dist/__testutils__/FakeClock.d.ts +67 -0
- package/dist/__testutils__/FakeClock.d.ts.map +1 -0
- package/dist/__testutils__/FakeClock.js +132 -0
- package/dist/__testutils__/FakeClock.js.map +1 -0
- package/dist/__testutils__/FakeWebSocket.d.ts +106 -0
- package/dist/__testutils__/FakeWebSocket.d.ts.map +1 -0
- package/dist/__testutils__/FakeWebSocket.js +213 -0
- package/dist/__testutils__/FakeWebSocket.js.map +1 -0
- package/dist/__testutils__/assertions.d.ts +33 -0
- package/dist/__testutils__/assertions.d.ts.map +1 -0
- package/dist/__testutils__/assertions.js +57 -0
- package/dist/__testutils__/assertions.js.map +1 -0
- package/dist/__testutils__/index.d.ts +15 -0
- package/dist/__testutils__/index.d.ts.map +1 -0
- package/dist/__testutils__/index.js +15 -0
- package/dist/__testutils__/index.js.map +1 -0
- package/dist/__testutils__/testClock.d.ts +28 -0
- package/dist/__testutils__/testClock.d.ts.map +1 -0
- package/dist/__testutils__/testClock.js +81 -0
- package/dist/__testutils__/testClock.js.map +1 -0
- package/dist/__testutils__/testFixtures.d.ts +15 -0
- package/dist/__testutils__/testFixtures.d.ts.map +1 -0
- package/dist/__testutils__/testFixtures.js +23 -0
- package/dist/__testutils__/testFixtures.js.map +1 -0
- package/dist/__testutils__/testProcess.d.ts +46 -0
- package/dist/__testutils__/testProcess.d.ts.map +1 -0
- package/dist/__testutils__/testProcess.js +77 -0
- package/dist/__testutils__/testProcess.js.map +1 -0
- package/dist/cli/collectors/dom.d.ts +8 -0
- package/dist/cli/collectors/dom.d.ts.map +1 -0
- package/dist/cli/collectors/dom.js +361 -0
- package/dist/cli/collectors/dom.js.map +1 -0
- package/dist/cli/collectors/helpers/domCache.d.ts +40 -0
- package/dist/cli/collectors/helpers/domCache.d.ts.map +1 -0
- package/dist/cli/collectors/helpers/domCache.js +79 -0
- package/dist/cli/collectors/helpers/domCache.js.map +1 -0
- package/dist/cli/collectors/helpers/domQuery.d.ts +45 -0
- package/dist/cli/collectors/helpers/domQuery.d.ts.map +1 -0
- package/dist/cli/collectors/helpers/domQuery.js +100 -0
- package/dist/cli/collectors/helpers/domQuery.js.map +1 -0
- package/dist/cli/collectors/helpers/selectorParser.d.ts +20 -0
- package/dist/cli/collectors/helpers/selectorParser.d.ts.map +1 -0
- package/dist/cli/collectors/helpers/selectorParser.js +20 -0
- package/dist/cli/collectors/helpers/selectorParser.js.map +1 -0
- package/dist/cli/commands/__tests__/cdp.contract.test.d.ts +24 -0
- package/dist/cli/commands/__tests__/cdp.contract.test.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/cdp.contract.test.js +467 -0
- package/dist/cli/commands/__tests__/cdp.contract.test.js.map +1 -0
- package/dist/cli/commands/__tests__/ipcTest.test.d.ts +2 -0
- package/dist/cli/commands/__tests__/ipcTest.test.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/ipcTest.test.js +37 -0
- package/dist/cli/commands/__tests__/ipcTest.test.js.map +1 -0
- package/dist/cli/commands/cdp.d.ts +8 -0
- package/dist/cli/commands/cdp.d.ts.map +1 -0
- package/dist/cli/commands/cdp.js +45 -0
- package/dist/cli/commands/cdp.js.map +1 -0
- package/dist/cli/commands/cleanup.d.ts +8 -0
- package/dist/cli/commands/cleanup.d.ts.map +1 -0
- package/dist/cli/commands/cleanup.js +130 -0
- package/dist/cli/commands/cleanup.js.map +1 -0
- package/dist/cli/commands/console.d.ts +8 -0
- package/dist/cli/commands/console.d.ts.map +1 -0
- package/dist/cli/commands/console.js +97 -0
- package/dist/cli/commands/console.js.map +1 -0
- package/dist/cli/commands/details.d.ts +8 -0
- package/dist/cli/commands/details.d.ts.map +1 -0
- package/dist/cli/commands/details.js +68 -0
- package/dist/cli/commands/details.js.map +1 -0
- package/dist/cli/commands/dom/helpers/domCache.d.ts +36 -0
- package/dist/cli/commands/dom/helpers/domCache.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/domCache.js +65 -0
- package/dist/cli/commands/dom/helpers/domCache.js.map +1 -0
- package/dist/cli/commands/dom/helpers/domQuery.d.ts +48 -0
- package/dist/cli/commands/dom/helpers/domQuery.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/domQuery.js +104 -0
- package/dist/cli/commands/dom/helpers/domQuery.js.map +1 -0
- package/dist/cli/commands/dom/helpers/errorHandler.d.ts +45 -0
- package/dist/cli/commands/dom/helpers/errorHandler.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/errorHandler.js +70 -0
- package/dist/cli/commands/dom/helpers/errorHandler.js.map +1 -0
- package/dist/cli/commands/dom/helpers/evalHelpers.d.ts +52 -0
- package/dist/cli/commands/dom/helpers/evalHelpers.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/evalHelpers.js +75 -0
- package/dist/cli/commands/dom/helpers/evalHelpers.js.map +1 -0
- package/dist/cli/commands/dom/helpers/optionsBuilder.d.ts +35 -0
- package/dist/cli/commands/dom/helpers/optionsBuilder.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/optionsBuilder.js +51 -0
- package/dist/cli/commands/dom/helpers/optionsBuilder.js.map +1 -0
- package/dist/cli/commands/dom/helpers/selectorParser.d.ts +20 -0
- package/dist/cli/commands/dom/helpers/selectorParser.d.ts.map +1 -0
- package/dist/cli/commands/dom/helpers/selectorParser.js +20 -0
- package/dist/cli/commands/dom/helpers/selectorParser.js.map +1 -0
- package/dist/cli/commands/dom/index.d.ts +8 -0
- package/dist/cli/commands/dom/index.d.ts.map +1 -0
- package/dist/cli/commands/dom/index.js +257 -0
- package/dist/cli/commands/dom/index.js.map +1 -0
- package/dist/cli/commands/ipcTest.d.ts +23 -0
- package/dist/cli/commands/ipcTest.d.ts.map +1 -0
- package/dist/cli/commands/ipcTest.js +181 -0
- package/dist/cli/commands/ipcTest.js.map +1 -0
- package/dist/cli/commands/network.d.ts +8 -0
- package/dist/cli/commands/network.d.ts.map +1 -0
- package/dist/cli/commands/network.js +40 -0
- package/dist/cli/commands/network.js.map +1 -0
- package/dist/cli/commands/peek.d.ts +8 -0
- package/dist/cli/commands/peek.d.ts.map +1 -0
- package/dist/cli/commands/peek.js +109 -0
- package/dist/cli/commands/peek.js.map +1 -0
- package/dist/cli/commands/query.d.ts +9 -0
- package/dist/cli/commands/query.d.ts.map +1 -0
- package/dist/cli/commands/query.js +127 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/start.d.ts +9 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +78 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +9 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +84 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +8 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +146 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/formatters/detailsFormatter.d.ts +10 -0
- package/dist/cli/formatters/detailsFormatter.d.ts.map +1 -0
- package/dist/cli/formatters/detailsFormatter.js +63 -0
- package/dist/cli/formatters/detailsFormatter.js.map +1 -0
- package/dist/cli/formatters/previewFormatter.d.ts +27 -0
- package/dist/cli/formatters/previewFormatter.d.ts.map +1 -0
- package/dist/cli/formatters/previewFormatter.js +160 -0
- package/dist/cli/formatters/previewFormatter.js.map +1 -0
- package/dist/cli/formatters/statusFormatter.d.ts +34 -0
- package/dist/cli/formatters/statusFormatter.d.ts.map +1 -0
- package/dist/cli/formatters/statusFormatter.js +108 -0
- package/dist/cli/formatters/statusFormatter.js.map +1 -0
- package/dist/cli/handlers/ChromeBootstrap.d.ts +24 -0
- package/dist/cli/handlers/ChromeBootstrap.d.ts.map +1 -0
- package/dist/cli/handlers/ChromeBootstrap.js +50 -0
- package/dist/cli/handlers/ChromeBootstrap.js.map +1 -0
- package/dist/cli/handlers/CommandRunner.d.ts +60 -0
- package/dist/cli/handlers/CommandRunner.d.ts.map +1 -0
- package/dist/cli/handlers/CommandRunner.js +81 -0
- package/dist/cli/handlers/CommandRunner.js.map +1 -0
- package/dist/cli/handlers/OutputBuilder.d.ts +60 -0
- package/dist/cli/handlers/OutputBuilder.d.ts.map +1 -0
- package/dist/cli/handlers/OutputBuilder.js +138 -0
- package/dist/cli/handlers/OutputBuilder.js.map +1 -0
- package/dist/cli/handlers/OutputWriter.d.ts +15 -0
- package/dist/cli/handlers/OutputWriter.d.ts.map +1 -0
- package/dist/cli/handlers/OutputWriter.js +34 -0
- package/dist/cli/handlers/OutputWriter.js.map +1 -0
- package/dist/cli/handlers/PreviewWriter.d.ts +52 -0
- package/dist/cli/handlers/PreviewWriter.d.ts.map +1 -0
- package/dist/cli/handlers/PreviewWriter.js +119 -0
- package/dist/cli/handlers/PreviewWriter.js.map +1 -0
- package/dist/cli/handlers/SessionLock.d.ts +16 -0
- package/dist/cli/handlers/SessionLock.d.ts.map +1 -0
- package/dist/cli/handlers/SessionLock.js +38 -0
- package/dist/cli/handlers/SessionLock.js.map +1 -0
- package/dist/cli/handlers/SessionLoop.d.ts +19 -0
- package/dist/cli/handlers/SessionLoop.d.ts.map +1 -0
- package/dist/cli/handlers/SessionLoop.js +47 -0
- package/dist/cli/handlers/SessionLoop.js.map +1 -0
- package/dist/cli/handlers/ShutdownController.d.ts +38 -0
- package/dist/cli/handlers/ShutdownController.d.ts.map +1 -0
- package/dist/cli/handlers/ShutdownController.js +83 -0
- package/dist/cli/handlers/ShutdownController.js.map +1 -0
- package/dist/cli/handlers/SignalHandler.d.ts +35 -0
- package/dist/cli/handlers/SignalHandler.d.ts.map +1 -0
- package/dist/cli/handlers/SignalHandler.js +81 -0
- package/dist/cli/handlers/SignalHandler.js.map +1 -0
- package/dist/cli/handlers/TargetSetup.d.ts +42 -0
- package/dist/cli/handlers/TargetSetup.d.ts.map +1 -0
- package/dist/cli/handlers/TargetSetup.js +87 -0
- package/dist/cli/handlers/TargetSetup.js.map +1 -0
- package/dist/cli/handlers/commonOptions.d.ts +54 -0
- package/dist/cli/handlers/commonOptions.d.ts.map +1 -0
- package/dist/cli/handlers/commonOptions.js +64 -0
- package/dist/cli/handlers/commonOptions.js.map +1 -0
- package/dist/cli/handlers/daemonSessionController.d.ts +23 -0
- package/dist/cli/handlers/daemonSessionController.d.ts.map +1 -0
- package/dist/cli/handlers/daemonSessionController.js +108 -0
- package/dist/cli/handlers/daemonSessionController.js.map +1 -0
- package/dist/cli/handlers/sessionController.d.ts +21 -0
- package/dist/cli/handlers/sessionController.d.ts.map +1 -0
- package/dist/cli/handlers/sessionController.js +55 -0
- package/dist/cli/handlers/sessionController.js.map +1 -0
- package/dist/cli/registry.d.ts +11 -0
- package/dist/cli/registry.d.ts.map +1 -0
- package/dist/cli/registry.js +46 -0
- package/dist/cli/registry.js.map +1 -0
- package/dist/collectors/__tests__/network.contract.test.d.ts +28 -0
- package/dist/collectors/__tests__/network.contract.test.d.ts.map +1 -0
- package/dist/collectors/__tests__/network.contract.test.js +525 -0
- package/dist/collectors/__tests__/network.contract.test.js.map +1 -0
- package/dist/collectors/console.d.ts +5 -3
- package/dist/collectors/console.d.ts.map +1 -1
- package/dist/collectors/console.js +48 -26
- package/dist/collectors/console.js.map +1 -1
- package/dist/collectors/dom.d.ts +2 -2
- package/dist/collectors/dom.d.ts.map +1 -1
- package/dist/collectors/dom.js +23 -12
- package/dist/collectors/dom.js.map +1 -1
- package/dist/collectors/network.d.ts +18 -4
- package/dist/collectors/network.d.ts.map +1 -1
- package/dist/collectors/network.js +111 -34
- package/dist/collectors/network.js.map +1 -1
- package/dist/connection/__tests__/cdp.contract.test.d.ts +16 -0
- package/dist/connection/__tests__/cdp.contract.test.d.ts.map +1 -0
- package/dist/connection/__tests__/cdp.contract.test.js +378 -0
- package/dist/connection/__tests__/cdp.contract.test.js.map +1 -0
- package/dist/connection/__tests__/finder.contract.test.d.ts +2 -0
- package/dist/connection/__tests__/finder.contract.test.d.ts.map +1 -0
- package/dist/connection/__tests__/finder.contract.test.js +239 -0
- package/dist/connection/__tests__/finder.contract.test.js.map +1 -0
- package/dist/connection/__tests__/tabs.contract.test.d.ts +2 -0
- package/dist/connection/__tests__/tabs.contract.test.d.ts.map +1 -0
- package/dist/connection/__tests__/tabs.contract.test.js +137 -0
- package/dist/connection/__tests__/tabs.contract.test.js.map +1 -0
- package/dist/connection/cdp.d.ts +165 -16
- package/dist/connection/cdp.d.ts.map +1 -1
- package/dist/connection/cdp.js +342 -122
- package/dist/connection/cdp.js.map +1 -1
- package/dist/connection/finder.d.ts +5 -4
- package/dist/connection/finder.d.ts.map +1 -1
- package/dist/connection/finder.js +10 -16
- package/dist/connection/finder.js.map +1 -1
- package/dist/connection/launcher.d.ts +18 -11
- package/dist/connection/launcher.d.ts.map +1 -1
- package/dist/connection/launcher.js +148 -82
- package/dist/connection/launcher.js.map +1 -1
- package/dist/connection/tabs.d.ts +47 -14
- package/dist/connection/tabs.d.ts.map +1 -1
- package/dist/connection/tabs.js +493 -132
- package/dist/connection/tabs.js.map +1 -1
- package/dist/constants.d.ts +209 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +232 -0
- package/dist/constants.js.map +1 -0
- package/dist/daemon/__tests__/ipcServer.contract.test.d.ts +23 -0
- package/dist/daemon/__tests__/ipcServer.contract.test.d.ts.map +1 -0
- package/dist/daemon/__tests__/ipcServer.contract.test.js +401 -0
- package/dist/daemon/__tests__/ipcServer.contract.test.js.map +1 -0
- package/dist/daemon/__tests__/launcher.unit.test.d.ts +8 -0
- package/dist/daemon/__tests__/launcher.unit.test.d.ts.map +1 -0
- package/dist/daemon/__tests__/launcher.unit.test.js +20 -0
- package/dist/daemon/__tests__/launcher.unit.test.js.map +1 -0
- package/dist/daemon/ipcServer.d.ts +83 -0
- package/dist/daemon/ipcServer.d.ts.map +1 -0
- package/dist/daemon/ipcServer.js +670 -0
- package/dist/daemon/ipcServer.js.map +1 -0
- package/dist/daemon/launcher.d.ts +31 -0
- package/dist/daemon/launcher.d.ts.map +1 -0
- package/dist/daemon/launcher.js +137 -0
- package/dist/daemon/launcher.js.map +1 -0
- package/dist/daemon/startSession.d.ts +51 -0
- package/dist/daemon/startSession.d.ts.map +1 -0
- package/dist/daemon/startSession.js +149 -0
- package/dist/daemon/startSession.js.map +1 -0
- package/dist/daemon/worker.d.ts +18 -0
- package/dist/daemon/worker.d.ts.map +1 -0
- package/dist/daemon/worker.js +623 -0
- package/dist/daemon/worker.js.map +1 -0
- package/dist/daemon/workerIpc.d.ts +33 -0
- package/dist/daemon/workerIpc.d.ts.map +1 -0
- package/dist/daemon/workerIpc.js +8 -0
- package/dist/daemon/workerIpc.js.map +1 -0
- package/dist/daemon.d.ts +10 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +32 -0
- package/dist/daemon.js.map +1 -0
- package/dist/index.js +41 -420
- package/dist/index.js.map +1 -1
- package/dist/ipc/__tests__/client.contract.test.d.ts +23 -0
- package/dist/ipc/__tests__/client.contract.test.d.ts.map +1 -0
- package/dist/ipc/__tests__/client.contract.test.js +466 -0
- package/dist/ipc/__tests__/client.contract.test.js.map +1 -0
- package/dist/ipc/client.d.ts +109 -0
- package/dist/ipc/client.d.ts.map +1 -0
- package/dist/ipc/client.js +220 -0
- package/dist/ipc/client.js.map +1 -0
- package/dist/ipc/commands.d.ts +208 -0
- package/dist/ipc/commands.d.ts.map +1 -0
- package/dist/ipc/commands.js +69 -0
- package/dist/ipc/commands.js.map +1 -0
- package/dist/ipc/responseValidator.d.ts +40 -0
- package/dist/ipc/responseValidator.d.ts.map +1 -0
- package/dist/ipc/responseValidator.js +28 -0
- package/dist/ipc/responseValidator.js.map +1 -0
- package/dist/ipc/types.d.ts +193 -0
- package/dist/ipc/types.d.ts.map +1 -0
- package/dist/ipc/types.js +21 -0
- package/dist/ipc/types.js.map +1 -0
- package/dist/session/BdgSession.d.ts +71 -4
- package/dist/session/BdgSession.d.ts.map +1 -1
- package/dist/session/BdgSession.js +173 -75
- package/dist/session/BdgSession.js.map +1 -1
- package/dist/session/chrome.d.ts +46 -0
- package/dist/session/chrome.d.ts.map +1 -0
- package/dist/session/chrome.js +92 -0
- package/dist/session/chrome.js.map +1 -0
- package/dist/session/cleanup.d.ts +45 -0
- package/dist/session/cleanup.d.ts.map +1 -0
- package/dist/session/cleanup.js +230 -0
- package/dist/session/cleanup.js.map +1 -0
- package/dist/session/index.d.ts +15 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +23 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/lock.d.ts +57 -0
- package/dist/session/lock.d.ts.map +1 -0
- package/dist/session/lock.js +154 -0
- package/dist/session/lock.js.map +1 -0
- package/dist/session/metadata.d.ts +59 -0
- package/dist/session/metadata.d.ts.map +1 -0
- package/dist/session/metadata.js +71 -0
- package/dist/session/metadata.js.map +1 -0
- package/dist/session/output.d.ts +18 -0
- package/dist/session/output.d.ts.map +1 -0
- package/dist/session/output.js +24 -0
- package/dist/session/output.js.map +1 -0
- package/dist/session/paths.d.ts +73 -0
- package/dist/session/paths.d.ts.map +1 -0
- package/dist/session/paths.js +84 -0
- package/dist/session/paths.js.map +1 -0
- package/dist/session/pid.d.ts +40 -0
- package/dist/session/pid.d.ts.map +1 -0
- package/dist/session/pid.js +73 -0
- package/dist/session/pid.js.map +1 -0
- package/dist/session/process.d.ts +45 -0
- package/dist/session/process.d.ts.map +1 -0
- package/dist/session/process.js +88 -0
- package/dist/session/process.js.map +1 -0
- package/dist/types.d.ts +114 -38
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/__tests__/filters.unit.test.d.ts +2 -0
- package/dist/utils/__tests__/filters.unit.test.d.ts.map +1 -0
- package/dist/utils/__tests__/filters.unit.test.js +239 -0
- package/dist/utils/__tests__/filters.unit.test.js.map +1 -0
- package/dist/utils/__tests__/session.contract.test.d.ts +2 -0
- package/dist/utils/__tests__/session.contract.test.d.ts.map +1 -0
- package/dist/utils/__tests__/session.contract.test.js +234 -0
- package/dist/utils/__tests__/session.contract.test.js.map +1 -0
- package/dist/utils/atomicFile.d.ts +38 -0
- package/dist/utils/atomicFile.d.ts.map +1 -0
- package/dist/utils/atomicFile.js +71 -0
- package/dist/utils/atomicFile.js.map +1 -0
- package/dist/utils/cdpHandlers.d.ts +31 -0
- package/dist/utils/cdpHandlers.d.ts.map +1 -0
- package/dist/utils/cdpHandlers.js +38 -0
- package/dist/utils/cdpHandlers.js.map +1 -0
- package/dist/utils/chromeDiagnostics.d.ts +28 -0
- package/dist/utils/chromeDiagnostics.d.ts.map +1 -0
- package/dist/utils/chromeDiagnostics.js +88 -0
- package/dist/utils/chromeDiagnostics.js.map +1 -0
- package/dist/utils/errors.d.ts +82 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +88 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/exitCodes.d.ts +32 -0
- package/dist/utils/exitCodes.d.ts.map +1 -0
- package/dist/utils/exitCodes.js +36 -0
- package/dist/utils/exitCodes.js.map +1 -0
- package/dist/utils/filters.d.ts +108 -0
- package/dist/utils/filters.d.ts.map +1 -0
- package/dist/utils/filters.js +304 -0
- package/dist/utils/filters.js.map +1 -0
- package/dist/utils/formatters/network.d.ts +23 -0
- package/dist/utils/formatters/network.d.ts.map +1 -0
- package/dist/utils/formatters/network.js +35 -0
- package/dist/utils/formatters/network.js.map +1 -0
- package/dist/utils/http.d.ts +34 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +48 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/logger.d.ts +42 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +43 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/objects.d.ts +23 -0
- package/dist/utils/objects.d.ts.map +1 -0
- package/dist/utils/objects.js +25 -0
- package/dist/utils/objects.js.map +1 -0
- package/dist/utils/url/safeParseUrl.d.ts +63 -0
- package/dist/utils/url/safeParseUrl.d.ts.map +1 -0
- package/dist/utils/url/safeParseUrl.js +84 -0
- package/dist/utils/url/safeParseUrl.js.map +1 -0
- package/dist/utils/url.d.ts +63 -1
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +152 -2
- package/dist/utils/url.js.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/version.d.ts +3 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +27 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +57 -10
- package/dist/utils/pageLoad.d.ts +0 -21
- package/dist/utils/pageLoad.d.ts.map +0 -1
- package/dist/utils/pageLoad.js +0 -85
- package/dist/utils/pageLoad.js.map +0 -1
- package/dist/utils/session.d.ts +0 -104
- package/dist/utils/session.d.ts.map +0 -1
- package/dist/utils/session.js +0 -244
- package/dist/utils/session.js.map +0 -1
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon IPC Server - Minimal JSONL handshake MVP
|
|
3
|
+
*
|
|
4
|
+
* Starts a Unix domain socket server that:
|
|
5
|
+
* 1. Listens for JSONL frames (newline-delimited JSON messages)
|
|
6
|
+
* 2. Responds only to handshake requests
|
|
7
|
+
* 3. Logs all incoming frames for debugging
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync, writeFileSync, unlinkSync } from 'fs';
|
|
10
|
+
import { createServer } from 'net';
|
|
11
|
+
import { launchSessionInWorker, WorkerStartError } from './startSession.js';
|
|
12
|
+
import { getCommandName, isCommandRequest, isCommandResponse, } from '../ipc/commands.js';
|
|
13
|
+
import { IPCErrorCode } from '../ipc/types.js';
|
|
14
|
+
import { cleanupSession } from '../session/cleanup.js';
|
|
15
|
+
import { releaseDaemonLock } from '../session/lock.js';
|
|
16
|
+
import { readSessionMetadata } from '../session/metadata.js';
|
|
17
|
+
import { ensureSessionDir, getSessionFilePath } from '../session/paths.js';
|
|
18
|
+
import { readPid } from '../session/pid.js';
|
|
19
|
+
import { isProcessAlive } from '../session/process.js';
|
|
20
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
21
|
+
import { fetchCDPTargets } from '../utils/http.js';
|
|
22
|
+
import { filterDefined } from '../utils/objects.js';
|
|
23
|
+
/**
|
|
24
|
+
* Simple JSONL IPC server for daemon communication.
|
|
25
|
+
*/
|
|
26
|
+
export class IPCServer {
|
|
27
|
+
server = null;
|
|
28
|
+
clients = new Set();
|
|
29
|
+
startTime = Date.now();
|
|
30
|
+
workerProcess = null;
|
|
31
|
+
pendingDomRequests = new Map(); // requestId -> pending request
|
|
32
|
+
/**
|
|
33
|
+
* Start the IPC server on Unix domain socket.
|
|
34
|
+
*/
|
|
35
|
+
async start() {
|
|
36
|
+
// Ensure ~/.bdg directory exists
|
|
37
|
+
ensureSessionDir();
|
|
38
|
+
// Clean up stale socket if exists
|
|
39
|
+
const socketPath = getSessionFilePath('DAEMON_SOCKET');
|
|
40
|
+
try {
|
|
41
|
+
unlinkSync(socketPath);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Ignore if socket doesn't exist
|
|
45
|
+
}
|
|
46
|
+
this.server = createServer((socket) => {
|
|
47
|
+
this.handleConnection(socket);
|
|
48
|
+
});
|
|
49
|
+
await new Promise((resolve, reject) => {
|
|
50
|
+
if (!this.server) {
|
|
51
|
+
reject(new Error('Server not initialized'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.server.listen(socketPath, () => {
|
|
55
|
+
console.error(`[daemon] IPC server listening on ${socketPath}`);
|
|
56
|
+
this.writePidFile();
|
|
57
|
+
resolve();
|
|
58
|
+
});
|
|
59
|
+
this.server.on('error', (err) => {
|
|
60
|
+
console.error('[daemon] Server error:', err);
|
|
61
|
+
reject(err);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Handle new client connection.
|
|
67
|
+
*/
|
|
68
|
+
handleConnection(socket) {
|
|
69
|
+
console.error('[daemon] Client connected');
|
|
70
|
+
this.clients.add(socket);
|
|
71
|
+
let buffer = '';
|
|
72
|
+
socket.on('data', (chunk) => {
|
|
73
|
+
buffer += chunk.toString('utf-8');
|
|
74
|
+
// Process complete JSONL frames (separated by newlines)
|
|
75
|
+
const lines = buffer.split('\n');
|
|
76
|
+
buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
|
|
77
|
+
for (const line of lines) {
|
|
78
|
+
if (line.trim()) {
|
|
79
|
+
this.handleMessage(socket, line);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
socket.on('end', () => {
|
|
84
|
+
console.error('[daemon] Client disconnected');
|
|
85
|
+
this.clients.delete(socket);
|
|
86
|
+
});
|
|
87
|
+
socket.on('error', (err) => {
|
|
88
|
+
console.error('[daemon] Socket error:', err);
|
|
89
|
+
this.clients.delete(socket);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Handle incoming JSONL message.
|
|
94
|
+
*/
|
|
95
|
+
handleMessage(socket, line) {
|
|
96
|
+
console.error('[daemon] Raw frame:', line);
|
|
97
|
+
try {
|
|
98
|
+
// Parse message - could be either IPC message or command request
|
|
99
|
+
const message = JSON.parse(line);
|
|
100
|
+
// Check if this is a command request
|
|
101
|
+
if (isCommandRequest(message.type)) {
|
|
102
|
+
this.handleCommandRequest(socket, message);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
switch (message.type) {
|
|
106
|
+
case 'handshake_request':
|
|
107
|
+
this.handleHandshake(socket, message);
|
|
108
|
+
break;
|
|
109
|
+
case 'handshake_response':
|
|
110
|
+
// Response messages are sent by daemon, not received
|
|
111
|
+
console.error('[daemon] Unexpected handshake response from client');
|
|
112
|
+
break;
|
|
113
|
+
case 'status_request':
|
|
114
|
+
this.handleStatusRequest(socket, message);
|
|
115
|
+
break;
|
|
116
|
+
case 'status_response':
|
|
117
|
+
// Response messages are sent by daemon, not received
|
|
118
|
+
console.error('[daemon] Unexpected status response from client');
|
|
119
|
+
break;
|
|
120
|
+
case 'peek_request':
|
|
121
|
+
this.handlePeekRequest(socket, message);
|
|
122
|
+
break;
|
|
123
|
+
case 'peek_response':
|
|
124
|
+
// Response messages are sent by daemon, not received
|
|
125
|
+
console.error('[daemon] Unexpected peek response from client');
|
|
126
|
+
break;
|
|
127
|
+
case 'start_session_request':
|
|
128
|
+
void this.handleStartSessionRequest(socket, message);
|
|
129
|
+
break;
|
|
130
|
+
case 'start_session_response':
|
|
131
|
+
// Response messages are sent by daemon, not received
|
|
132
|
+
console.error('[daemon] Unexpected start session response from client');
|
|
133
|
+
break;
|
|
134
|
+
case 'stop_session_request':
|
|
135
|
+
this.handleStopSessionRequest(socket, message);
|
|
136
|
+
break;
|
|
137
|
+
case 'stop_session_response':
|
|
138
|
+
// Response messages are sent by daemon, not received
|
|
139
|
+
console.error('[daemon] Unexpected stop session response from client');
|
|
140
|
+
break;
|
|
141
|
+
// NOTE: DOM command responses are now handled via command system (see commands.ts)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('[daemon] Failed to parse message:', error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Handle handshake request.
|
|
150
|
+
*/
|
|
151
|
+
handleHandshake(socket, request) {
|
|
152
|
+
console.error(`[daemon] Handshake request received (sessionId: ${request.sessionId})`);
|
|
153
|
+
const response = {
|
|
154
|
+
type: 'handshake_response',
|
|
155
|
+
sessionId: request.sessionId,
|
|
156
|
+
status: 'ok',
|
|
157
|
+
message: 'Handshake successful',
|
|
158
|
+
};
|
|
159
|
+
// Send JSONL response (JSON + newline)
|
|
160
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
161
|
+
console.error('[daemon] Handshake response sent');
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Handle status request.
|
|
165
|
+
*/
|
|
166
|
+
handleStatusRequest(socket, request) {
|
|
167
|
+
console.error(`[daemon] Status request received (sessionId: ${request.sessionId})`);
|
|
168
|
+
try {
|
|
169
|
+
// Gather daemon metadata
|
|
170
|
+
const data = {
|
|
171
|
+
daemonPid: process.pid,
|
|
172
|
+
daemonStartTime: this.startTime,
|
|
173
|
+
socketPath: getSessionFilePath('DAEMON_SOCKET'),
|
|
174
|
+
};
|
|
175
|
+
// Check for active session
|
|
176
|
+
const sessionPid = readPid();
|
|
177
|
+
if (sessionPid && isProcessAlive(sessionPid)) {
|
|
178
|
+
data.sessionPid = sessionPid;
|
|
179
|
+
// Try to read session metadata
|
|
180
|
+
const metadata = readSessionMetadata({ warnOnCorruption: true });
|
|
181
|
+
if (metadata) {
|
|
182
|
+
data.sessionMetadata = filterDefined({
|
|
183
|
+
bdgPid: metadata.bdgPid,
|
|
184
|
+
chromePid: metadata.chromePid,
|
|
185
|
+
startTime: metadata.startTime,
|
|
186
|
+
port: metadata.port,
|
|
187
|
+
targetId: metadata.targetId,
|
|
188
|
+
webSocketDebuggerUrl: metadata.webSocketDebuggerUrl,
|
|
189
|
+
activeCollectors: metadata.activeCollectors,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const response = {
|
|
194
|
+
type: 'status_response',
|
|
195
|
+
sessionId: request.sessionId,
|
|
196
|
+
status: 'ok',
|
|
197
|
+
data,
|
|
198
|
+
};
|
|
199
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
200
|
+
console.error('[daemon] Status response sent');
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const response = {
|
|
204
|
+
type: 'status_response',
|
|
205
|
+
sessionId: request.sessionId,
|
|
206
|
+
status: 'error',
|
|
207
|
+
error: `Failed to gather status: ${getErrorMessage(error)}`,
|
|
208
|
+
};
|
|
209
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
210
|
+
console.error('[daemon] Status error response sent');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Handle peek request - forward to worker via IPC.
|
|
215
|
+
*/
|
|
216
|
+
handlePeekRequest(socket, request) {
|
|
217
|
+
console.error(`[daemon] Peek request received (sessionId: ${request.sessionId})`);
|
|
218
|
+
// Check for active worker process
|
|
219
|
+
if (!this.workerProcess?.stdin) {
|
|
220
|
+
const response = {
|
|
221
|
+
type: 'peek_response',
|
|
222
|
+
sessionId: request.sessionId,
|
|
223
|
+
status: 'error',
|
|
224
|
+
error: 'No active worker process',
|
|
225
|
+
};
|
|
226
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
227
|
+
console.error('[daemon] Peek error response sent (no worker)');
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// Generate unique request ID
|
|
231
|
+
const requestId = `worker_peek_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
232
|
+
// Set timeout for worker response
|
|
233
|
+
const timeout = setTimeout(() => {
|
|
234
|
+
this.pendingDomRequests.delete(requestId);
|
|
235
|
+
const response = {
|
|
236
|
+
type: 'peek_response',
|
|
237
|
+
sessionId: request.sessionId,
|
|
238
|
+
status: 'error',
|
|
239
|
+
error: 'Worker response timeout (5s)',
|
|
240
|
+
};
|
|
241
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
242
|
+
console.error('[daemon] Peek timeout response sent');
|
|
243
|
+
}, 5000);
|
|
244
|
+
// Track pending request
|
|
245
|
+
this.pendingDomRequests.set(requestId, { socket, sessionId: request.sessionId, timeout });
|
|
246
|
+
// Forward to worker
|
|
247
|
+
const workerRequest = {
|
|
248
|
+
type: 'worker_peek_request',
|
|
249
|
+
requestId,
|
|
250
|
+
lastN: 10, // TODO: Extract from PeekRequest if needed
|
|
251
|
+
};
|
|
252
|
+
this.workerProcess.stdin.write(JSON.stringify(workerRequest) + '\n');
|
|
253
|
+
console.error(`[daemon] Forwarded worker_peek_request to worker (requestId: ${requestId})`);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Handle start session request.
|
|
257
|
+
*/
|
|
258
|
+
async handleStartSessionRequest(socket, request) {
|
|
259
|
+
console.error(`[daemon] Start session request received (sessionId: ${request.sessionId}, url: ${request.url})`);
|
|
260
|
+
try {
|
|
261
|
+
// Check for existing session (concurrency guard)
|
|
262
|
+
const sessionPid = readPid();
|
|
263
|
+
if (sessionPid && isProcessAlive(sessionPid)) {
|
|
264
|
+
// Read session metadata to provide helpful error context
|
|
265
|
+
const metadata = readSessionMetadata({ warnOnCorruption: false });
|
|
266
|
+
const startTime = metadata?.startTime;
|
|
267
|
+
const duration = startTime ? Math.floor((Date.now() - startTime) / 1000) : undefined;
|
|
268
|
+
// Try to get target URL from CDP
|
|
269
|
+
let targetUrl;
|
|
270
|
+
if (metadata?.port && metadata?.targetId) {
|
|
271
|
+
try {
|
|
272
|
+
const targets = await fetchCDPTargets(metadata.port);
|
|
273
|
+
const target = targets.find((t) => t.id === metadata.targetId);
|
|
274
|
+
if (target) {
|
|
275
|
+
targetUrl = target.url;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
// Ignore CDP fetch errors
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const response = {
|
|
283
|
+
type: 'start_session_response',
|
|
284
|
+
sessionId: request.sessionId,
|
|
285
|
+
status: 'error',
|
|
286
|
+
message: `Session already running (PID ${sessionPid}). Stop it first with stop_session_request.`,
|
|
287
|
+
errorCode: IPCErrorCode.SESSION_ALREADY_RUNNING,
|
|
288
|
+
existingSession: {
|
|
289
|
+
pid: sessionPid,
|
|
290
|
+
...(targetUrl && { targetUrl }),
|
|
291
|
+
...(startTime && { startTime }),
|
|
292
|
+
...(duration !== undefined && { duration }),
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
296
|
+
console.error('[daemon] Start session error response sent (session already running)');
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
// Launch worker
|
|
300
|
+
console.error('[daemon] Launching worker...');
|
|
301
|
+
try {
|
|
302
|
+
const metadata = await launchSessionInWorker(request.url, filterDefined({
|
|
303
|
+
port: request.port,
|
|
304
|
+
timeout: request.timeout,
|
|
305
|
+
collectors: request.collectors,
|
|
306
|
+
includeAll: request.includeAll,
|
|
307
|
+
userDataDir: request.userDataDir,
|
|
308
|
+
maxBodySize: request.maxBodySize,
|
|
309
|
+
}));
|
|
310
|
+
console.error('[daemon] Worker launched successfully');
|
|
311
|
+
// Store worker process for IPC
|
|
312
|
+
this.workerProcess = metadata.workerProcess;
|
|
313
|
+
// Set up worker stdout listener for DOM responses
|
|
314
|
+
this.setupWorkerListener(metadata.workerProcess);
|
|
315
|
+
// Build response data
|
|
316
|
+
const data = {
|
|
317
|
+
workerPid: metadata.workerPid,
|
|
318
|
+
chromePid: metadata.chromePid,
|
|
319
|
+
port: metadata.port,
|
|
320
|
+
targetUrl: metadata.targetUrl,
|
|
321
|
+
...(metadata.targetTitle !== undefined && { targetTitle: metadata.targetTitle }),
|
|
322
|
+
};
|
|
323
|
+
const response = {
|
|
324
|
+
type: 'start_session_response',
|
|
325
|
+
sessionId: request.sessionId,
|
|
326
|
+
status: 'ok',
|
|
327
|
+
data,
|
|
328
|
+
message: 'Session started successfully',
|
|
329
|
+
};
|
|
330
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
331
|
+
console.error('[daemon] Start session response sent');
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
// Map worker errors to IPC error codes
|
|
335
|
+
let errorCode = IPCErrorCode.WORKER_START_FAILED;
|
|
336
|
+
let errorMessage = 'Failed to start worker';
|
|
337
|
+
if (error instanceof WorkerStartError) {
|
|
338
|
+
// Include error details (contains worker stderr) for debugging
|
|
339
|
+
errorMessage = error.details ? `${error.message}\n${error.details}` : error.message;
|
|
340
|
+
switch (error.code) {
|
|
341
|
+
case 'SPAWN_FAILED':
|
|
342
|
+
case 'WORKER_CRASH':
|
|
343
|
+
case 'INVALID_READY_MESSAGE':
|
|
344
|
+
errorCode = IPCErrorCode.WORKER_START_FAILED;
|
|
345
|
+
break;
|
|
346
|
+
case 'READY_TIMEOUT':
|
|
347
|
+
errorCode = IPCErrorCode.CDP_TIMEOUT;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
errorMessage = getErrorMessage(error);
|
|
353
|
+
}
|
|
354
|
+
const response = {
|
|
355
|
+
type: 'start_session_response',
|
|
356
|
+
sessionId: request.sessionId,
|
|
357
|
+
status: 'error',
|
|
358
|
+
message: errorMessage,
|
|
359
|
+
errorCode,
|
|
360
|
+
};
|
|
361
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
362
|
+
console.error(`[daemon] Start session error response sent (${errorCode})`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
const response = {
|
|
367
|
+
type: 'start_session_response',
|
|
368
|
+
sessionId: request.sessionId,
|
|
369
|
+
status: 'error',
|
|
370
|
+
message: `Daemon error: ${getErrorMessage(error)}`,
|
|
371
|
+
errorCode: IPCErrorCode.DAEMON_ERROR,
|
|
372
|
+
};
|
|
373
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
374
|
+
console.error('[daemon] Start session error response sent (daemon error)');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Handle stop session request.
|
|
379
|
+
*/
|
|
380
|
+
handleStopSessionRequest(socket, request) {
|
|
381
|
+
console.error(`[daemon] Stop session request received (sessionId: ${request.sessionId})`);
|
|
382
|
+
try {
|
|
383
|
+
// Check for active session
|
|
384
|
+
const sessionPid = readPid();
|
|
385
|
+
if (!sessionPid || !isProcessAlive(sessionPid)) {
|
|
386
|
+
const response = {
|
|
387
|
+
type: 'stop_session_response',
|
|
388
|
+
sessionId: request.sessionId,
|
|
389
|
+
status: 'error',
|
|
390
|
+
message: 'No active session found',
|
|
391
|
+
errorCode: IPCErrorCode.NO_SESSION,
|
|
392
|
+
};
|
|
393
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
394
|
+
console.error('[daemon] Stop session error response sent (no session)');
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
// Capture Chrome PID BEFORE cleanup (so CLI can kill Chrome if needed)
|
|
398
|
+
const metadata = readSessionMetadata({ warnOnCorruption: true });
|
|
399
|
+
const chromePid = metadata?.chromePid;
|
|
400
|
+
if (chromePid) {
|
|
401
|
+
console.error(`[daemon] Captured Chrome PID ${chromePid} before cleanup`);
|
|
402
|
+
}
|
|
403
|
+
// Kill the session process (use SIGTERM for graceful shutdown)
|
|
404
|
+
try {
|
|
405
|
+
process.kill(sessionPid, 'SIGTERM');
|
|
406
|
+
console.error(`[daemon] Sent SIGTERM to session process (PID ${sessionPid})`);
|
|
407
|
+
}
|
|
408
|
+
catch (killError) {
|
|
409
|
+
const errorMessage = killError instanceof Error ? killError.message : String(killError);
|
|
410
|
+
const response = {
|
|
411
|
+
type: 'stop_session_response',
|
|
412
|
+
sessionId: request.sessionId,
|
|
413
|
+
status: 'error',
|
|
414
|
+
message: `Failed to kill session process: ${errorMessage}`,
|
|
415
|
+
errorCode: IPCErrorCode.SESSION_KILL_FAILED,
|
|
416
|
+
};
|
|
417
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
418
|
+
console.error('[daemon] Stop session error response sent (kill failed)');
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
// Clean up session files
|
|
422
|
+
cleanupSession();
|
|
423
|
+
console.error('[daemon] Cleaned up session files');
|
|
424
|
+
// Clear worker process reference
|
|
425
|
+
this.workerProcess = null;
|
|
426
|
+
console.error('[daemon] Cleared worker process reference');
|
|
427
|
+
const response = {
|
|
428
|
+
type: 'stop_session_response',
|
|
429
|
+
sessionId: request.sessionId,
|
|
430
|
+
status: 'ok',
|
|
431
|
+
message: 'Session stopped successfully',
|
|
432
|
+
...(chromePid !== undefined && { chromePid }),
|
|
433
|
+
};
|
|
434
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
435
|
+
console.error('[daemon] Stop session response sent');
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
const response = {
|
|
439
|
+
type: 'stop_session_response',
|
|
440
|
+
sessionId: request.sessionId,
|
|
441
|
+
status: 'error',
|
|
442
|
+
message: `Failed to stop session: ${getErrorMessage(error)}`,
|
|
443
|
+
errorCode: IPCErrorCode.DAEMON_ERROR,
|
|
444
|
+
};
|
|
445
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
446
|
+
console.error('[daemon] Stop session error response sent');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Set up worker stdout listener for IPC responses.
|
|
451
|
+
*/
|
|
452
|
+
setupWorkerListener(worker) {
|
|
453
|
+
let buffer = '';
|
|
454
|
+
if (!worker.stdout) {
|
|
455
|
+
console.error('[daemon] Warning: Worker stdout not available');
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
worker.stdout.on('data', (chunk) => {
|
|
459
|
+
buffer += chunk.toString('utf-8');
|
|
460
|
+
// Process complete JSONL frames (separated by newlines)
|
|
461
|
+
const lines = buffer.split('\n');
|
|
462
|
+
buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
|
|
463
|
+
for (const line of lines) {
|
|
464
|
+
if (!line.trim())
|
|
465
|
+
continue;
|
|
466
|
+
try {
|
|
467
|
+
// Parse message - could be either lifecycle signal or command response
|
|
468
|
+
const message = JSON.parse(line);
|
|
469
|
+
this.handleWorkerResponse(message);
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
// Ignore parse errors, may be log messages
|
|
473
|
+
console.error(`[daemon] Failed to parse worker stdout line: ${getErrorMessage(error)}`);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
console.error('[daemon] Worker stdout listener set up');
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Handle response from worker (lifecycle signals or command responses).
|
|
481
|
+
*/
|
|
482
|
+
handleWorkerResponse(message) {
|
|
483
|
+
console.error(`[daemon] Received worker response: ${message.type} (requestId: ${message.requestId})`);
|
|
484
|
+
// Check for ready signal (not a command response)
|
|
485
|
+
if (message.type === 'worker_ready') {
|
|
486
|
+
console.error('[daemon] Worker ready signal (already processed during launch)');
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
// Check if this is a command response
|
|
490
|
+
if (isCommandResponse(message.type)) {
|
|
491
|
+
// Look up pending request
|
|
492
|
+
const pending = this.pendingDomRequests.get(message.requestId);
|
|
493
|
+
if (!pending) {
|
|
494
|
+
console.error(`[daemon] No pending request found for requestId: ${message.requestId}`);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
// Clear timeout and remove from pending
|
|
498
|
+
clearTimeout(pending.timeout);
|
|
499
|
+
this.pendingDomRequests.delete(message.requestId);
|
|
500
|
+
// Forward response to client
|
|
501
|
+
this.forwardCommandResponse(pending.socket, pending.sessionId, message);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Generic forwarder for all command responses.
|
|
506
|
+
*/
|
|
507
|
+
forwardCommandResponse(socket, sessionId, workerResponse) {
|
|
508
|
+
const commandName = getCommandName(workerResponse.type);
|
|
509
|
+
if (!commandName) {
|
|
510
|
+
console.error(`[daemon] Invalid worker response type: ${workerResponse.type}`);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
// Special handling for worker_peek - transform to PeekResponse format
|
|
514
|
+
if (commandName === 'worker_peek') {
|
|
515
|
+
const { requestId: _requestId, success, data, error, } = workerResponse;
|
|
516
|
+
const peekResponse = {
|
|
517
|
+
type: 'peek_response',
|
|
518
|
+
sessionId,
|
|
519
|
+
status: success ? 'ok' : 'error',
|
|
520
|
+
...(success &&
|
|
521
|
+
data && {
|
|
522
|
+
data: {
|
|
523
|
+
sessionPid: readPid() ?? 0,
|
|
524
|
+
preview: {
|
|
525
|
+
version: data.version,
|
|
526
|
+
success: true,
|
|
527
|
+
timestamp: new Date(data.startTime).toISOString(),
|
|
528
|
+
duration: data.duration,
|
|
529
|
+
target: data.target,
|
|
530
|
+
data: {
|
|
531
|
+
network: data.network,
|
|
532
|
+
console: data.console,
|
|
533
|
+
},
|
|
534
|
+
partial: true,
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
}),
|
|
538
|
+
...(error && { error }),
|
|
539
|
+
};
|
|
540
|
+
socket.write(JSON.stringify(peekResponse) + '\n');
|
|
541
|
+
console.error('[daemon] Forwarded worker_peek_response to client (transformed to PeekResponse)');
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
// Default handling for other commands
|
|
545
|
+
const { requestId: _requestId, success, ...rest } = workerResponse;
|
|
546
|
+
const response = {
|
|
547
|
+
...rest,
|
|
548
|
+
type: `${commandName}_response`,
|
|
549
|
+
sessionId,
|
|
550
|
+
status: success ? 'ok' : 'error',
|
|
551
|
+
};
|
|
552
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
553
|
+
console.error(`[daemon] Forwarded ${commandName}_response to client`);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Generic handler for all command requests.
|
|
557
|
+
*/
|
|
558
|
+
handleCommandRequest(socket, request) {
|
|
559
|
+
const commandName = getCommandName(request.type);
|
|
560
|
+
if (!commandName) {
|
|
561
|
+
console.error(`[daemon] Invalid command type: ${request.type}`);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
console.error(`[daemon] ${commandName} request received (sessionId: ${request.sessionId})`);
|
|
565
|
+
if (!this.workerProcess?.stdin) {
|
|
566
|
+
const response = {
|
|
567
|
+
type: `${commandName}_response`,
|
|
568
|
+
sessionId: request.sessionId,
|
|
569
|
+
status: 'error',
|
|
570
|
+
error: 'No active worker process',
|
|
571
|
+
};
|
|
572
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
573
|
+
console.error(`[daemon] ${commandName} error response sent (no worker)`);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const requestId = `${commandName}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
577
|
+
const timeout = setTimeout(() => {
|
|
578
|
+
this.pendingDomRequests.delete(requestId);
|
|
579
|
+
const response = {
|
|
580
|
+
type: `${commandName}_response`,
|
|
581
|
+
sessionId: request.sessionId,
|
|
582
|
+
status: 'error',
|
|
583
|
+
error: 'Worker response timeout (10s)',
|
|
584
|
+
};
|
|
585
|
+
socket.write(JSON.stringify(response) + '\n');
|
|
586
|
+
console.error(`[daemon] ${commandName} timeout response sent`);
|
|
587
|
+
}, 10000);
|
|
588
|
+
this.pendingDomRequests.set(requestId, { socket, sessionId: request.sessionId, timeout });
|
|
589
|
+
// Extract only sessionId, keep all other fields including 'type' param if it exists
|
|
590
|
+
const { sessionId: _sessionId, type: _ipcType, ...params } = request;
|
|
591
|
+
const workerRequest = {
|
|
592
|
+
type: `${commandName}_request`,
|
|
593
|
+
requestId,
|
|
594
|
+
...params,
|
|
595
|
+
};
|
|
596
|
+
this.workerProcess.stdin.write(JSON.stringify(workerRequest) + '\n');
|
|
597
|
+
console.error(`[daemon] Forwarded ${commandName}_request to worker (requestId: ${requestId})`);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Stop the IPC server and cleanup.
|
|
601
|
+
*/
|
|
602
|
+
async stop() {
|
|
603
|
+
// Close all client connections
|
|
604
|
+
for (const socket of this.clients) {
|
|
605
|
+
socket.destroy();
|
|
606
|
+
}
|
|
607
|
+
this.clients.clear();
|
|
608
|
+
// Close server
|
|
609
|
+
if (this.server) {
|
|
610
|
+
await new Promise((resolve) => {
|
|
611
|
+
this.server?.close(() => {
|
|
612
|
+
console.error('[daemon] IPC server stopped');
|
|
613
|
+
resolve();
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
this.server = null;
|
|
617
|
+
}
|
|
618
|
+
// Cleanup files
|
|
619
|
+
const socketPath = getSessionFilePath('DAEMON_SOCKET');
|
|
620
|
+
try {
|
|
621
|
+
unlinkSync(socketPath);
|
|
622
|
+
}
|
|
623
|
+
catch {
|
|
624
|
+
// Ignore if already deleted
|
|
625
|
+
}
|
|
626
|
+
const pidPath = getSessionFilePath('DAEMON_PID');
|
|
627
|
+
try {
|
|
628
|
+
unlinkSync(pidPath);
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
// Ignore if already deleted
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Write daemon PID to file for tracking.
|
|
636
|
+
*/
|
|
637
|
+
writePidFile() {
|
|
638
|
+
const pidPath = getSessionFilePath('DAEMON_PID');
|
|
639
|
+
try {
|
|
640
|
+
writeFileSync(pidPath, process.pid.toString(), 'utf-8');
|
|
641
|
+
releaseDaemonLock(); // Release lock after PID is written (P0 Fix #1)
|
|
642
|
+
console.error(`[daemon] PID file written: ${pidPath}`);
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
console.error('[daemon] Failed to write PID file:', error);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Check if daemon is already running.
|
|
650
|
+
*/
|
|
651
|
+
static isRunning() {
|
|
652
|
+
const pidPath = getSessionFilePath('DAEMON_PID');
|
|
653
|
+
try {
|
|
654
|
+
const pid = parseInt(readFileSync(pidPath, 'utf-8').trim(), 10);
|
|
655
|
+
// Check if process is alive
|
|
656
|
+
process.kill(pid, 0);
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Get socket path for client connections.
|
|
665
|
+
*/
|
|
666
|
+
static getSocketPath() {
|
|
667
|
+
return getSessionFilePath('DAEMON_SOCKET');
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
//# sourceMappingURL=ipcServer.js.map
|