@elizaos/app-core 2.0.0-beta.2 → 2.0.11-beta.5
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/agent-bridge.d.ts +27 -0
- package/agent-bridge.d.ts.map +1 -0
- package/agent-bridge.js +26 -0
- package/api/__tests__/sandbox-test-helpers.js +1 -1
- package/api/auth/audit.js +1 -1
- package/api/auth/auth-context.js +1 -1
- package/api/auth/bootstrap-token.js +2 -2
- package/api/auth/index.d.ts +9 -10
- package/api/auth/index.d.ts.map +1 -1
- package/api/auth/index.js +9 -10
- package/api/auth/passwords.js +2 -2
- package/api/auth/sensitive-rate-limit.d.ts +1 -4
- package/api/auth/sensitive-rate-limit.d.ts.map +1 -1
- package/api/auth/sensitive-rate-limit.js +6 -6
- package/api/auth/sessions.js +2 -2
- package/api/auth-bootstrap-routes.d.ts +6 -13
- package/api/auth-bootstrap-routes.d.ts.map +1 -1
- package/api/auth-bootstrap-routes.js +14 -27
- package/api/auth-pairing-routes.d.ts +17 -0
- package/api/auth-pairing-routes.d.ts.map +1 -0
- package/api/auth-pairing-routes.js +300 -0
- package/api/auth-session-routes.d.ts.map +1 -1
- package/api/auth-session-routes.js +36 -15
- package/api/auth.d.ts +12 -19
- package/api/auth.d.ts.map +1 -1
- package/api/auth.js +32 -27
- package/api/automations-compat-routes.d.ts.map +1 -1
- package/api/automations-compat-routes.js +5 -5
- package/api/background-tasks-routes.d.ts +4 -0
- package/api/background-tasks-routes.d.ts.map +1 -0
- package/api/background-tasks-routes.js +63 -0
- package/api/catalog-routes.js +3 -3
- package/api/cloud-pair-route.d.ts +26 -0
- package/api/cloud-pair-route.d.ts.map +1 -0
- package/api/cloud-pair-route.js +222 -0
- package/api/cloud-voice-routes.d.ts +52 -0
- package/api/cloud-voice-routes.d.ts.map +1 -0
- package/api/cloud-voice-routes.js +50 -0
- package/api/compat-route-shared.d.ts +2 -2
- package/api/compat-route-shared.d.ts.map +1 -1
- package/api/compat-route-shared.js +11 -7
- package/api/credential-resolver.d.ts +2 -2
- package/api/credential-resolver.d.ts.map +1 -1
- package/api/credential-resolver.js +8 -2
- package/api/database-rows-compat-routes.d.ts.map +1 -1
- package/api/database-rows-compat-routes.js +69 -31
- package/api/dev-boot-history.d.ts +26 -0
- package/api/dev-boot-history.d.ts.map +1 -0
- package/api/dev-boot-history.js +69 -0
- package/api/dev-compat-routes.d.ts +5 -0
- package/api/dev-compat-routes.d.ts.map +1 -1
- package/api/dev-compat-routes.js +127 -4
- package/api/dev-console-log.d.ts +2 -2
- package/api/dev-console-log.d.ts.map +1 -1
- package/api/dev-console-log.js +8 -5
- package/api/dev-route-catalog.d.ts +58 -0
- package/api/dev-route-catalog.d.ts.map +1 -0
- package/api/dev-route-catalog.js +447 -0
- package/api/dev-stack.d.ts.map +1 -1
- package/api/dev-stack.js +6 -9
- package/api/first-run-routes.d.ts +4 -0
- package/api/first-run-routes.d.ts.map +1 -0
- package/api/first-run-routes.js +208 -0
- package/api/first-run-tts-route.d.ts +19 -0
- package/api/first-run-tts-route.d.ts.map +1 -0
- package/api/first-run-tts-route.js +59 -0
- package/api/internal-routes.d.ts +23 -0
- package/api/internal-routes.d.ts.map +1 -0
- package/api/internal-routes.js +203 -0
- package/api/ios-local-agent-transport.d.ts +36 -0
- package/api/ios-local-agent-transport.d.ts.map +1 -0
- package/api/ios-local-agent-transport.js +566 -0
- package/api/onboarding-voice-lines.d.ts +23 -0
- package/api/onboarding-voice-lines.d.ts.map +1 -0
- package/api/onboarding-voice-lines.js +8 -0
- package/api/perf-instrument.d.ts +43 -0
- package/api/perf-instrument.d.ts.map +1 -0
- package/api/perf-instrument.js +113 -0
- package/api/response.d.ts.map +1 -1
- package/api/response.js +14 -14
- package/api/runtime-mode-routes.d.ts.map +1 -1
- package/api/runtime-mode-routes.js +2 -2
- package/api/secrets-inventory-routes.js +2 -2
- package/api/secrets-manager-routes.d.ts +1 -1
- package/api/secrets-manager-routes.d.ts.map +1 -1
- package/api/secrets-manager-routes.js +9 -10
- package/api/sensitive-request-routes.d.ts.map +1 -1
- package/api/sensitive-request-routes.js +5 -5
- package/api/sensitive-request-store.d.ts +12 -3
- package/api/sensitive-request-store.d.ts.map +1 -1
- package/api/server-cors.d.ts.map +1 -1
- package/api/server-cors.js +13 -2
- package/api/server-first-run-helpers.d.ts +26 -0
- package/api/server-first-run-helpers.d.ts.map +1 -0
- package/api/server-first-run-helpers.js +271 -0
- package/api/server-security.js +1 -1
- package/api/server-startup.d.ts.map +1 -1
- package/api/server-startup.js +3 -4
- package/api/server-wallet-trade.js +1 -1
- package/api/server.d.ts +4 -4
- package/api/server.d.ts.map +1 -1
- package/api/server.js +222 -88
- package/api/setup-contract.d.ts +63 -0
- package/api/setup-contract.d.ts.map +1 -0
- package/api/setup-contract.js +39 -0
- package/api/training-benchmarks.d.ts +97 -0
- package/api/training-benchmarks.d.ts.map +1 -0
- package/api/training-benchmarks.js +307 -0
- package/api/workbench-compat-routes.js +2 -2
- package/benchmark/cerebras-autowire.d.ts +28 -0
- package/benchmark/cerebras-autowire.d.ts.map +1 -0
- package/benchmark/cerebras-autowire.js +62 -0
- package/benchmark/lifeops-bench-handler.d.ts +36 -0
- package/benchmark/lifeops-bench-handler.d.ts.map +1 -1
- package/benchmark/lifeops-bench-handler.js +63 -1
- package/benchmark/lifeops-fake-backend.d.ts +39 -0
- package/benchmark/lifeops-fake-backend.d.ts.map +1 -1
- package/benchmark/lifeops-fake-backend.js +993 -21
- package/benchmark/mock-plugin.d.ts.map +1 -1
- package/benchmark/mock-plugin.js +0 -24
- package/benchmark/plugin.d.ts +2 -1
- package/benchmark/plugin.d.ts.map +1 -1
- package/benchmark/plugin.js +989 -68
- package/benchmark/replay-capture.d.ts +2 -2
- package/benchmark/replay-capture.d.ts.map +1 -1
- package/benchmark/replay-capture.js +3 -3
- package/benchmark/server-utils.d.ts +162 -9
- package/benchmark/server-utils.d.ts.map +1 -1
- package/benchmark/server-utils.js +625 -62
- package/benchmark/server.d.ts.map +1 -1
- package/benchmark/server.js +1962 -118
- package/boot-profile.d.ts +3 -0
- package/boot-profile.d.ts.map +1 -0
- package/boot-profile.js +30 -0
- package/browser.d.ts +23 -1
- package/browser.d.ts.map +1 -1
- package/browser.js +20 -1
- package/cli/argv.js +1 -1
- package/cli/banner.js +1 -1
- package/cli/command-format.js +2 -2
- package/cli/doctor/checks.d.ts.map +1 -1
- package/cli/doctor/checks.js +6 -6
- package/cli/plugins-cli.d.ts.map +1 -1
- package/cli/plugins-cli.js +77 -32
- package/cli/profile.d.ts.map +1 -1
- package/cli/profile.js +5 -4
- package/cli/program/build-program.js +4 -4
- package/cli/program/command-registry.d.ts.map +1 -1
- package/cli/program/command-registry.js +13 -11
- package/cli/program/help.js +5 -5
- package/cli/program/preaction.js +5 -5
- package/cli/program/register.auth.d.ts.map +1 -1
- package/cli/program/register.auth.js +6 -12
- package/cli/program/register.capability-router.d.ts +29 -0
- package/cli/program/register.capability-router.d.ts.map +1 -0
- package/cli/program/register.capability-router.js +568 -0
- package/cli/program/register.config.js +1 -1
- package/cli/program/register.configure.d.ts.map +1 -1
- package/cli/program/register.configure.js +1 -1
- package/cli/program/register.dashboard.d.ts.map +1 -1
- package/cli/program/register.dashboard.js +6 -7
- package/cli/program/register.db.d.ts.map +1 -1
- package/cli/program/register.db.js +3 -4
- package/cli/program/register.doctor.js +7 -7
- package/cli/program/register.setup.d.ts.map +1 -1
- package/cli/program/register.setup.js +14 -10
- package/cli/program/register.start.d.ts.map +1 -1
- package/cli/program/register.start.js +5 -3
- package/cli/program/register.subclis.js +3 -3
- package/cli/program/register.update.d.ts +6 -0
- package/cli/program/register.update.d.ts.map +1 -1
- package/cli/program/register.update.js +58 -6
- package/cli/program.js +1 -1
- package/cli/run-main.js +4 -4
- package/config/app-config.d.ts +2 -0
- package/config/app-config.d.ts.map +1 -0
- package/config/app-config.js +1 -0
- package/connectors/capacitor-jsc.d.ts.map +1 -1
- package/connectors/capacitor-jsc.js +16 -10
- package/connectors/capacitor-quickjs.d.ts.map +1 -1
- package/connectors/capacitor-quickjs.js +18 -13
- package/connectors/capacitor-sqlite.d.ts.map +1 -1
- package/connectors/capacitor-sqlite.js +27 -12
- package/dispatch/approval-queue.d.ts +37 -0
- package/dispatch/approval-queue.d.ts.map +1 -0
- package/dispatch/approval-queue.js +25 -0
- package/dispatch/channel-registry.d.ts +30 -0
- package/dispatch/channel-registry.d.ts.map +1 -0
- package/dispatch/channel-registry.js +22 -0
- package/dispatch/connector-registry.d.ts +39 -0
- package/dispatch/connector-registry.d.ts.map +1 -0
- package/dispatch/connector-registry.js +24 -0
- package/dispatch/index.d.ts +14 -0
- package/dispatch/index.d.ts.map +1 -0
- package/dispatch/index.js +13 -0
- package/dispatch/send-policy.d.ts +36 -0
- package/dispatch/send-policy.d.ts.map +1 -0
- package/dispatch/send-policy.js +16 -0
- package/entry.js +28 -11
- package/first-run/first-run-config.d.ts +55 -0
- package/first-run/first-run-config.d.ts.map +1 -0
- package/first-run/first-run-config.js +178 -0
- package/first-run/runtime-target.d.ts +4 -0
- package/first-run/runtime-target.d.ts.map +1 -0
- package/first-run/runtime-target.js +13 -0
- package/index.d.ts +16 -3
- package/index.d.ts.map +1 -1
- package/index.js +57 -33
- package/package.json +159 -50
- package/packaging/debian/apt-repo-config/README.md +18 -0
- package/packaging/debian/apt-repo-config/conf/distributions +11 -0
- package/packaging/flatpak/README.md +26 -16
- package/packaging/flatpak/ai.elizaos.App.metainfo.xml +17 -12
- package/packaging/flatpak/ai.elizaos.App.store.yml +5 -5
- package/packaging/flatpak/ai.elizaos.App.yml +10 -24
- package/packaging/flatpak/elizaos-app-wrapper.store.sh +2 -2
- package/packaging/flatpak/generate-sources.sh +74 -0
- package/packaging/flatpak/node-sources.json +7930 -0
- package/packaging/inno/build-inno.ps1 +34 -9
- package/packaging/msix/AppxManifest.store.xml +1 -1
- package/packaging/msix/README.md +39 -19
- package/packaging/msix/build-msix.ps1 +44 -14
- package/packaging/snap/snapcraft.yaml +22 -21
- package/packaging/test-packaging.sh +2 -2
- package/permissions/types.d.ts +1 -1
- package/permissions/types.js +1 -1
- package/platform/elizaos-agent-browser-stub.d.ts +144 -0
- package/platform/elizaos-agent-browser-stub.d.ts.map +1 -0
- package/platform/elizaos-agent-browser-stub.js +158 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.d.ts +34 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.d.ts.map +1 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.js +51 -0
- package/platform/empty-node-module.d.ts +148 -0
- package/platform/empty-node-module.d.ts.map +1 -1
- package/platform/empty-node-module.js +140 -3
- package/platform/ios-runtime-backends.d.ts +83 -0
- package/platform/ios-runtime-backends.d.ts.map +1 -0
- package/platform/ios-runtime-backends.js +133 -0
- package/platform/ios-runtime-bridge.d.ts +15 -0
- package/platform/ios-runtime-bridge.d.ts.map +1 -0
- package/platform/ios-runtime-bridge.js +527 -0
- package/platform/native-library-policy.d.ts +23 -0
- package/platform/native-library-policy.d.ts.map +1 -0
- package/platform/native-library-policy.js +112 -0
- package/platform/native-plugin-entrypoints.d.ts +19 -0
- package/platform/native-plugin-entrypoints.d.ts.map +1 -0
- package/platform/native-plugin-entrypoints.js +29 -0
- package/platforms/android/README.md +68 -10
- package/platforms/android/app/build.gradle +268 -3
- package/platforms/android/app/capacitor.build.gradle +18 -1
- package/platforms/android/app/proguard-rules.pro +17 -2
- package/platforms/android/app/src/androidTest/java/ai/elizaos/app/ElizaOsInstrumentedTest.java +1 -1
- package/platforms/android/app/src/main/AndroidManifest.xml +334 -17
- package/platforms/android/app/src/main/assets/runners/eliza-tasks.js +177 -0
- package/platforms/android/app/src/main/elizavoice-jni/CMakeLists.txt +75 -0
- package/platforms/android/app/src/main/elizavoice-jni/elizavoice-jni.cpp +1045 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/AgentPlugin.java +111 -171
- package/platforms/android/app/src/main/java/ai/elizaos/app/AndroidVirtualizationBridge.java +284 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/BatteryOptimizationPlugin.java +95 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAccessibilityService.java +55 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAgentService.java +1198 -141
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAndroidSystemBridge.java +83 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAssistActivity.java +50 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaBootReceiver.java +90 -8
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaBrowserActivity.java +2 -2
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaCalendarActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaCameraActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaClockActivity.java +2 -2
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaContactsActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaDialActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaInCallService.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaMmsReceiver.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaNativeBridge.java +22 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaNotificationListenerService.java +45 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaQuickActionsWidgetProvider.java +68 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaShareActivity.java +132 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsComposeActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsGatewayService.java +268 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsReceiver.java +12 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaTasksWorker.java +194 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceCaptureService.java +198 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceNative.java +160 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoicePlugin.java +450 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceTileService.java +39 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaWorkScheduler.java +60 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/GatewayConnectionService.java +53 -19
- package/platforms/android/app/src/main/java/ai/elizaos/app/MainActivity.java +160 -33
- package/platforms/android/app/src/main/java/ai/elizaos/app/ResourceProbePlugin.java +169 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/VoiceCapturePlugin.java +119 -0
- package/platforms/android/app/src/main/res/drawable/eliza_widget_background.xml +10 -0
- package/platforms/android/app/src/main/res/drawable/eliza_widget_button_background.xml +13 -0
- package/platforms/android/app/src/main/res/drawable/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-hdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-mdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xxxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-hdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-mdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xxxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/layout/eliza_quick_actions_widget.xml +86 -0
- package/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +2 -1
- package/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +2 -1
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/values/android_app_actions.xml +48 -0
- package/platforms/android/app/src/main/res/values/colors.xml +8 -0
- package/platforms/android/app/src/main/res/values/ic_launcher_background.xml +2 -2
- package/platforms/android/app/src/main/res/values/strings.xml +2 -2
- package/platforms/android/app/src/main/res/values/styles.xml +25 -1
- package/platforms/android/app/src/main/res/xml/eliza_accessibility_service.xml +9 -0
- package/platforms/android/app/src/main/res/xml/eliza_quick_actions_widget.xml +13 -0
- package/platforms/android/app/src/main/res/xml/shortcuts.xml +121 -0
- package/platforms/android/build.gradle +2 -2
- package/platforms/android/capacitor-cordova-android-plugins/build.gradle +9 -3
- package/platforms/android/capacitor-cordova-android-plugins/cordova.variables.gradle +6 -2
- package/platforms/android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml +7 -2
- package/platforms/android/capacitor-cordova-android-plugins/src/main/java/.gitkeep +0 -1
- package/platforms/android/capacitor.settings.gradle +66 -16
- package/platforms/android/gradle.properties +1 -0
- package/platforms/android/update-manifest/generate-manifest.mjs +97 -0
- package/platforms/android/update-manifest/schema.json +26 -0
- package/platforms/apple-store-entitlements.reviewed.json +155 -0
- package/platforms/electrobun/.generated/brand-config.json +3 -2
- package/platforms/electrobun/LICENSE +21 -0
- package/platforms/electrobun/README.md +15 -1
- package/platforms/electrobun/assets/appIcon.icns +0 -0
- package/platforms/electrobun/assets/appIcon.ico +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_128x128.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_128x128@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_16x16.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_16x16@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_256x256.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_256x256@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_32x32.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_32x32@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_512x512.png +0 -0
- package/platforms/electrobun/assets/brand-config.json +6 -6
- package/platforms/electrobun/biome.json +9 -9
- package/platforms/electrobun/docs/capability-collapse-matrix.json +318 -0
- package/platforms/electrobun/docs/capability-collapse-matrix.md +129 -0
- package/platforms/electrobun/docs/capability-routing.md +86 -0
- package/platforms/electrobun/docs/convergence-audit.json +3505 -0
- package/platforms/electrobun/docs/convergence-audit.md +694 -0
- package/platforms/electrobun/docs/database-boot-policy.md +90 -0
- package/platforms/electrobun/docs/riscv64-port.md +175 -0
- package/platforms/electrobun/docs/startup-first-run-cleanup.md +18 -0
- package/platforms/electrobun/docs/trace-first-annotations.md +52 -0
- package/platforms/electrobun/docs/ui-boundary-audit.json +580 -0
- package/platforms/electrobun/docs/ui-boundary-audit.md +257 -0
- package/platforms/electrobun/electrobun.config.ts +592 -364
- package/platforms/electrobun/entitlements/JUSTIFICATIONS.md +141 -0
- package/platforms/electrobun/entitlements/README.md +34 -6
- package/platforms/electrobun/entitlements/mas-bun.entitlements +15 -0
- package/platforms/electrobun/entitlements/mas.entitlements +6 -4
- package/platforms/electrobun/native/macos/window-effects.mm +1522 -0
- package/platforms/electrobun/package.json +18 -12
- package/platforms/electrobun/remotes/fs/README.md +70 -0
- package/platforms/electrobun/remotes/fs/electrobun.config.ts +38 -0
- package/platforms/electrobun/remotes/fs/package.json +12 -0
- package/platforms/electrobun/remotes/fs/plugin.json +25 -0
- package/platforms/electrobun/remotes/fs/src/bun/errors.ts +57 -0
- package/platforms/electrobun/remotes/fs/src/bun/file-limits.ts +50 -0
- package/platforms/electrobun/remotes/fs/src/bun/fs-service.ts +389 -0
- package/platforms/electrobun/remotes/fs/src/bun/path-guard.ts +270 -0
- package/platforms/electrobun/remotes/fs/src/bun/protocol.ts +149 -0
- package/platforms/electrobun/remotes/fs/src/bun/worker.ts +174 -0
- package/platforms/electrobun/remotes/fs/src/dev/phase5-smoke.ts +171 -0
- package/platforms/electrobun/remotes/fs/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/git/README.md +75 -0
- package/platforms/electrobun/remotes/git/electrobun.config.ts +44 -0
- package/platforms/electrobun/remotes/git/package.json +12 -0
- package/platforms/electrobun/remotes/git/plugin.json +31 -0
- package/platforms/electrobun/remotes/git/src/bun/errors.ts +69 -0
- package/platforms/electrobun/remotes/git/src/bun/git-command.ts +156 -0
- package/platforms/electrobun/remotes/git/src/bun/git-service.ts +446 -0
- package/platforms/electrobun/remotes/git/src/bun/operation-history.ts +124 -0
- package/platforms/electrobun/remotes/git/src/bun/protocol.ts +252 -0
- package/platforms/electrobun/remotes/git/src/bun/worker.ts +316 -0
- package/platforms/electrobun/remotes/git/src/dev/phase7-smoke.ts +141 -0
- package/platforms/electrobun/remotes/git/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/local-model/README.md +138 -0
- package/platforms/electrobun/remotes/local-model/electrobun.config.ts +46 -0
- package/platforms/electrobun/remotes/local-model/package.json +12 -0
- package/platforms/electrobun/remotes/local-model/plugin.json +33 -0
- package/platforms/electrobun/remotes/local-model/src/bun/download-state.ts +115 -0
- package/platforms/electrobun/remotes/local-model/src/bun/eliza1-catalog.ts +425 -0
- package/platforms/electrobun/remotes/local-model/src/bun/errors.ts +74 -0
- package/platforms/electrobun/remotes/local-model/src/bun/hf-eliza1-client.ts +169 -0
- package/platforms/electrobun/remotes/local-model/src/bun/local-inference-api-client.ts +245 -0
- package/platforms/electrobun/remotes/local-model/src/bun/model-service.ts +490 -0
- package/platforms/electrobun/remotes/local-model/src/bun/protocol.ts +301 -0
- package/platforms/electrobun/remotes/local-model/src/bun/worker.ts +248 -0
- package/platforms/electrobun/remotes/local-model/src/dev/phase8-smoke.ts +117 -0
- package/platforms/electrobun/remotes/local-model/src/web/index.html +13 -0
- package/platforms/electrobun/remotes/pty/README.md +65 -0
- package/platforms/electrobun/remotes/pty/electrobun.config.ts +47 -0
- package/platforms/electrobun/remotes/pty/package.json +12 -0
- package/platforms/electrobun/remotes/pty/plugin.json +34 -0
- package/platforms/electrobun/remotes/pty/src/bun/errors.ts +57 -0
- package/platforms/electrobun/remotes/pty/src/bun/output-buffer.ts +127 -0
- package/platforms/electrobun/remotes/pty/src/bun/protocol.ts +192 -0
- package/platforms/electrobun/remotes/pty/src/bun/pty-service.ts +562 -0
- package/platforms/electrobun/remotes/pty/src/bun/worker.ts +218 -0
- package/platforms/electrobun/remotes/pty/src/dev/phase6-smoke.ts +127 -0
- package/platforms/electrobun/remotes/pty/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/runtime/README.md +370 -0
- package/platforms/electrobun/remotes/runtime/electrobun.config.ts +48 -0
- package/platforms/electrobun/remotes/runtime/package.json +14 -0
- package/platforms/electrobun/remotes/runtime/plugin.json +30 -0
- package/platforms/electrobun/remotes/runtime/src/bun/api-client.ts +620 -0
- package/platforms/electrobun/remotes/runtime/src/bun/errors.ts +45 -0
- package/platforms/electrobun/remotes/runtime/src/bun/log-buffer.ts +33 -0
- package/platforms/electrobun/remotes/runtime/src/bun/protocol.ts +366 -0
- package/platforms/electrobun/remotes/runtime/src/bun/route-discovery.ts +419 -0
- package/platforms/electrobun/remotes/runtime/src/bun/runtime-manager.ts +423 -0
- package/platforms/electrobun/remotes/runtime/src/bun/sse-parser.ts +99 -0
- package/platforms/electrobun/remotes/runtime/src/bun/stream-manager.ts +887 -0
- package/platforms/electrobun/remotes/runtime/src/bun/worker.ts +1231 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase1-smoke.ts +34 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase2-smoke.ts +86 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase3-smoke.ts +141 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.css +187 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.html +76 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.ts +192 -0
- package/platforms/electrobun/remotes/surface/README.md +201 -0
- package/platforms/electrobun/remotes/surface/electrobun.config.ts +38 -0
- package/platforms/electrobun/remotes/surface/package.json +12 -0
- package/platforms/electrobun/remotes/surface/plugin.json +28 -0
- package/platforms/electrobun/remotes/surface/src/bun/worker.ts +132 -0
- package/platforms/electrobun/remotes/surface/src/dev/phase4-smoke.ts +566 -0
- package/platforms/electrobun/remotes/surface/src/protocol/event-types.ts +84 -0
- package/platforms/electrobun/remotes/surface/src/protocol/runtime-client.ts +673 -0
- package/platforms/electrobun/remotes/surface/src/web/app.ts +595 -0
- package/platforms/electrobun/remotes/surface/src/web/index.css +460 -0
- package/platforms/electrobun/remotes/surface/src/web/index.html +466 -0
- package/platforms/electrobun/remotes/surface/src/web/index.ts +5 -0
- package/platforms/electrobun/remotes/surface/src/web/render.ts +455 -0
- package/platforms/electrobun/remotes/surface/src/web/state.ts +427 -0
- package/platforms/electrobun/scripts/build-macos-effects.sh +4 -0
- package/platforms/electrobun/scripts/ensure-build-folder.ts +28 -0
- package/platforms/electrobun/scripts/ensure-whisper-gguf.sh +55 -0
- package/platforms/electrobun/scripts/ensure-whisper-model.sh +22 -80
- package/platforms/electrobun/scripts/generate-convergence-audit.ts +1203 -0
- package/platforms/electrobun/scripts/local-adhoc-sign-macos.ts +159 -159
- package/platforms/electrobun/scripts/postwrap-diagnostics.ts +424 -339
- package/platforms/electrobun/scripts/postwrap-sign-runtime-macos.ts +302 -271
- package/platforms/electrobun/scripts/smoke-test-windows.ps1 +17 -16
- package/platforms/electrobun/scripts/smoke-test.sh +5 -7
- package/platforms/electrobun/scripts/sync-web-assets.mjs +13 -13
- package/platforms/electrobun/scripts/verify-rpc-handlers.ts +109 -110
- package/platforms/electrobun/scripts/verify-windows-installer-proof.ps1 +3 -8
- package/platforms/electrobun/src/__stubs__/bun-ffi.ts +31 -31
- package/platforms/electrobun/src/__stubs__/electrobun-bun.ts +1 -1
- package/platforms/electrobun/src/agent-ready-state.ts +8 -8
- package/platforms/electrobun/src/agent-reset-from-main.test.ts +162 -0
- package/platforms/electrobun/src/agent-reset-from-main.ts +62 -62
- package/platforms/electrobun/src/agent-status-rpc.test.ts +95 -0
- package/platforms/electrobun/src/agent-status-rpc.ts +156 -0
- package/platforms/electrobun/src/api-base.test.ts +247 -0
- package/platforms/electrobun/src/api-base.ts +202 -93
- package/platforms/electrobun/src/application-menu-action-registry.ts +9 -9
- package/platforms/electrobun/src/application-menu.ts +348 -348
- package/platforms/electrobun/src/background-notice.ts +36 -36
- package/platforms/electrobun/src/boot-progress.test.ts +188 -0
- package/platforms/electrobun/src/boot-progress.ts +111 -0
- package/platforms/electrobun/src/brand-config.test.ts +39 -0
- package/platforms/electrobun/src/brand-config.ts +141 -129
- package/platforms/electrobun/src/bridge/browser-tabs-renderer-registry.ts +28 -28
- package/platforms/electrobun/src/bridge/electrobun-boot-config.ts +42 -0
- package/platforms/electrobun/src/bridge/electrobun-crypto-ready.ts +120 -0
- package/platforms/electrobun/src/bridge/electrobun-direct-rpc.ts +342 -357
- package/platforms/electrobun/src/bridge/electrobun-stub.ts +13 -13
- package/platforms/electrobun/src/browser-workspace-bridge-server.ts +285 -243
- package/platforms/electrobun/src/cloud-auth-window.ts +136 -136
- package/platforms/electrobun/src/cloud-disconnect-from-main.ts +90 -90
- package/platforms/electrobun/src/config-and-auth-rpc.test.ts +256 -0
- package/platforms/electrobun/src/config-and-auth-rpc.ts +302 -0
- package/platforms/electrobun/src/conversations-and-character-rpc.test.ts +185 -0
- package/platforms/electrobun/src/conversations-and-character-rpc.ts +131 -0
- package/platforms/electrobun/src/dashboard-rpc.test.ts +200 -0
- package/platforms/electrobun/src/dashboard-rpc.ts +344 -0
- package/platforms/electrobun/src/database/database-lock.ts +141 -0
- package/platforms/electrobun/src/database/database-mode.ts +149 -0
- package/platforms/electrobun/src/database/database-recovery.ts +72 -0
- package/platforms/electrobun/src/database/database-snapshot.ts +190 -0
- package/platforms/electrobun/src/database/database.test.ts +196 -0
- package/platforms/electrobun/src/database/index.ts +5 -0
- package/platforms/electrobun/src/database/pglite-paths.ts +100 -0
- package/platforms/electrobun/src/desktop-deep-link-events.test.ts +30 -0
- package/platforms/electrobun/src/desktop-deep-link-events.ts +17 -0
- package/platforms/electrobun/src/desktop-http-request.test.ts +73 -73
- package/platforms/electrobun/src/desktop-http-request.ts +85 -85
- package/platforms/electrobun/src/desktop-pill-config.test.ts +27 -0
- package/platforms/electrobun/src/desktop-pill-config.ts +40 -0
- package/platforms/electrobun/src/desktop-test-bridge-server.ts +204 -204
- package/platforms/electrobun/src/desktop-tray-config.test.ts +87 -0
- package/platforms/electrobun/src/desktop-tray-config.ts +84 -0
- package/platforms/electrobun/src/devtools-layout.ts +41 -41
- package/platforms/electrobun/src/diagnostic-format.test.ts +71 -0
- package/platforms/electrobun/src/diagnostic-format.ts +75 -36
- package/platforms/electrobun/src/dynamic-view-rpc-schema.test.ts +37 -0
- package/platforms/electrobun/src/dynamic-views/README.md +44 -0
- package/platforms/electrobun/src/dynamic-views/demo/agent-run-trace.html +135 -0
- package/platforms/electrobun/src/dynamic-views/errors.ts +29 -0
- package/platforms/electrobun/src/dynamic-views/host.test.ts +353 -0
- package/platforms/electrobun/src/dynamic-views/host.ts +332 -0
- package/platforms/electrobun/src/dynamic-views/index.ts +57 -0
- package/platforms/electrobun/src/dynamic-views/kiosk-canvas.ts +89 -0
- package/platforms/electrobun/src/dynamic-views/registry.test.ts +139 -0
- package/platforms/electrobun/src/dynamic-views/registry.ts +196 -0
- package/platforms/electrobun/src/dynamic-views/session-manager.test.ts +355 -0
- package/platforms/electrobun/src/dynamic-views/session-manager.ts +348 -0
- package/platforms/electrobun/src/dynamic-views/types.ts +105 -0
- package/platforms/electrobun/src/electrobun-boot-config.test.ts +50 -0
- package/platforms/electrobun/src/electrobun-config.test.ts +62 -0
- package/platforms/electrobun/src/electrobun-crypto-ready.test.ts +65 -0
- package/platforms/electrobun/src/electrobun-window-options.ts +25 -0
- package/platforms/electrobun/src/extension-rpc.test.ts +88 -0
- package/platforms/electrobun/src/extension-rpc.ts +102 -0
- package/platforms/electrobun/src/fatal-shutdown.test.ts +10 -10
- package/platforms/electrobun/src/fatal-shutdown.ts +1 -1
- package/platforms/electrobun/src/first-party-remotes.test.ts +169 -0
- package/platforms/electrobun/src/first-party-remotes.ts +297 -0
- package/platforms/electrobun/src/first-run-rpc.test.ts +192 -0
- package/platforms/electrobun/src/first-run-rpc.ts +146 -0
- package/platforms/electrobun/src/floating-chat-window.ts +181 -181
- package/platforms/electrobun/src/inbox-rpc.test.ts +123 -0
- package/platforms/electrobun/src/inbox-rpc.ts +158 -0
- package/platforms/electrobun/src/index.ts +2555 -2096
- package/platforms/electrobun/src/kiosk-mode.ts +50 -0
- package/platforms/electrobun/src/launch/index.ts +4 -0
- package/platforms/electrobun/src/launch/launch-dynamic-view.ts +37 -0
- package/platforms/electrobun/src/launch/launch-orchestrator.test.ts +224 -0
- package/platforms/electrobun/src/launch/launch-orchestrator.ts +456 -0
- package/platforms/electrobun/src/launch/launch-store.test.ts +97 -0
- package/platforms/electrobun/src/launch/launch-store.ts +134 -0
- package/platforms/electrobun/src/launch/types.ts +103 -0
- package/platforms/electrobun/src/launch/views/launch-diagnostics.html +205 -0
- package/platforms/electrobun/src/lifecycle/agent-ready-publish.test.ts +50 -0
- package/platforms/electrobun/src/lifecycle/agent-ready-publish.ts +27 -0
- package/platforms/electrobun/src/lifecycle/api-base-owner.ts +42 -31
- package/platforms/electrobun/src/lifecycle/desktop-session-prime.ts +44 -44
- package/platforms/electrobun/src/logger.ts +14 -14
- package/platforms/electrobun/src/main-window-runtime.ts +83 -83
- package/platforms/electrobun/src/main-window-session.test.ts +109 -0
- package/platforms/electrobun/src/main-window-session.ts +87 -51
- package/platforms/electrobun/src/menu-reset-from-main.ts +158 -158
- package/platforms/electrobun/src/native/agent-env.test.ts +52 -0
- package/platforms/electrobun/src/native/agent-runtime-layout.test.ts +42 -0
- package/platforms/electrobun/src/native/agent-state-dir.test.ts +91 -0
- package/platforms/electrobun/src/native/agent.ts +2122 -1682
- package/platforms/electrobun/src/native/auth-bridge.test.ts +67 -0
- package/platforms/electrobun/src/native/auth-bridge.ts +464 -360
- package/platforms/electrobun/src/native/browser-workspace.ts +723 -471
- package/platforms/electrobun/src/native/camera.ts +50 -50
- package/platforms/electrobun/src/native/canvas.ts +444 -445
- package/platforms/electrobun/src/native/credentials.ts +673 -616
- package/platforms/electrobun/src/native/desktop-window.test.ts +300 -0
- package/platforms/electrobun/src/native/desktop.ts +2196 -2156
- package/platforms/electrobun/src/native/editor-bridge.ts +201 -201
- package/platforms/electrobun/src/native/file-watcher.ts +154 -154
- package/platforms/electrobun/src/native/gateway.ts +179 -180
- package/platforms/electrobun/src/native/gpu-window.ts +256 -256
- package/platforms/electrobun/src/native/index.ts +76 -74
- package/platforms/electrobun/src/native/location.test.ts +44 -0
- package/platforms/electrobun/src/native/location.ts +90 -80
- package/platforms/electrobun/src/native/loopback-port.ts +60 -60
- package/platforms/electrobun/src/native/mac-window-effects.ts +166 -104
- package/platforms/electrobun/src/native/music-player.ts +38 -38
- package/platforms/electrobun/src/native/permissions-shared.ts +249 -150
- package/platforms/electrobun/src/native/permissions.ts +301 -208
- package/platforms/electrobun/src/native/power-state.ts +129 -129
- package/platforms/electrobun/src/native/remote-plugin-host.test.ts +1394 -0
- package/platforms/electrobun/src/native/remote-plugin-host.ts +1531 -0
- package/platforms/electrobun/src/native/screencapture.ts +667 -573
- package/platforms/electrobun/src/native/steward.ts +207 -204
- package/platforms/electrobun/src/native/swabble.ts +68 -324
- package/platforms/electrobun/src/native/talkmode.ts +253 -422
- package/platforms/electrobun/src/native/webgpu-browser-support.test.ts +18 -0
- package/platforms/electrobun/src/native/webgpu-browser-support.ts +165 -147
- package/platforms/electrobun/src/native/whisper-env.test.ts +71 -0
- package/platforms/electrobun/src/native/whisper-env.ts +68 -0
- package/platforms/electrobun/src/native-onboarding.ts +270 -0
- package/platforms/electrobun/src/onboarding-overlay-window.ts +141 -0
- package/platforms/electrobun/src/persisted-deployment.ts +91 -0
- package/platforms/electrobun/src/pill-window.test.ts +91 -0
- package/platforms/electrobun/src/pill-window.ts +99 -0
- package/platforms/electrobun/src/preload-validation.ts +44 -44
- package/platforms/electrobun/src/preload.js +1 -1
- package/platforms/electrobun/src/print-electrobun-dev-settings-banner.ts +120 -120
- package/platforms/electrobun/src/renderer-api-proxy.test.ts +73 -0
- package/platforms/electrobun/src/renderer-api-proxy.ts +86 -0
- package/platforms/electrobun/src/renderer-static.test.ts +53 -0
- package/platforms/electrobun/src/renderer-static.ts +144 -57
- package/platforms/electrobun/src/rpc-handler-slices.ts +121 -0
- package/platforms/electrobun/src/rpc-handlers.test.ts +267 -0
- package/platforms/electrobun/src/rpc-handlers.ts +1306 -913
- package/platforms/electrobun/src/rpc-parse-utils.ts +57 -0
- package/platforms/electrobun/src/rpc-port-resolver.test.ts +45 -0
- package/platforms/electrobun/src/rpc-port-resolver.ts +31 -0
- package/platforms/electrobun/src/rpc-schema.ts +2556 -1619
- package/platforms/electrobun/src/runtime-layout.ts +105 -105
- package/platforms/electrobun/src/runtime-permissions.ts +95 -95
- package/platforms/electrobun/src/runtime-rpc.test.ts +126 -0
- package/platforms/electrobun/src/runtime-rpc.ts +237 -0
- package/platforms/electrobun/src/screenshot-dev-server.ts +87 -87
- package/platforms/electrobun/src/settings-mutations-rpc.test.ts +193 -0
- package/platforms/electrobun/src/settings-mutations-rpc.ts +220 -0
- package/platforms/electrobun/src/startup-trace.ts +274 -270
- package/platforms/electrobun/src/subscription-rpc.test.ts +89 -0
- package/platforms/electrobun/src/subscription-rpc.ts +192 -0
- package/platforms/electrobun/src/surface-windows.test.ts +355 -0
- package/platforms/electrobun/src/surface-windows.ts +410 -410
- package/platforms/electrobun/src/trace/README.md +73 -0
- package/platforms/electrobun/src/trace/errors.ts +21 -0
- package/platforms/electrobun/src/trace/index.ts +40 -0
- package/platforms/electrobun/src/trace/trace-dynamic-view.ts +40 -0
- package/platforms/electrobun/src/trace/trace-host-requests.ts +473 -0
- package/platforms/electrobun/src/trace/trace-service.test.ts +186 -0
- package/platforms/electrobun/src/trace/trace-service.ts +324 -0
- package/platforms/electrobun/src/trace/trace-store.test.ts +141 -0
- package/platforms/electrobun/src/trace/trace-store.ts +551 -0
- package/platforms/electrobun/src/trace/types.ts +250 -0
- package/platforms/electrobun/src/trace/views/agent-run-trace.html +311 -0
- package/platforms/electrobun/src/types/web-speech.d.ts +28 -28
- package/platforms/electrobun/src/types.ts +5 -5
- package/platforms/electrobun/src/update-availability.test.ts +72 -0
- package/platforms/electrobun/src/update-availability.ts +90 -0
- package/platforms/electrobun/src/update-rpc.test.ts +83 -0
- package/platforms/electrobun/src/update-rpc.ts +123 -0
- package/platforms/electrobun/src/voice/README.md +184 -0
- package/platforms/electrobun/src/voice/errors.ts +42 -0
- package/platforms/electrobun/src/voice/index.ts +78 -0
- package/platforms/electrobun/src/voice/types.ts +316 -0
- package/platforms/electrobun/src/voice/voice-host-requests.ts +259 -0
- package/platforms/electrobun/src/voice/voice-latency-budget.test.ts +66 -0
- package/platforms/electrobun/src/voice/voice-latency-budget.ts +243 -0
- package/platforms/electrobun/src/voice/voice-live-validation.test.ts +352 -0
- package/platforms/electrobun/src/voice/voice-live-validation.ts +838 -0
- package/platforms/electrobun/src/voice/voice-pipeline.ts +250 -0
- package/platforms/electrobun/src/voice/voice-playback-adapter.ts +31 -0
- package/platforms/electrobun/src/voice/voice-runtime-adapter.test.ts +213 -0
- package/platforms/electrobun/src/voice/voice-runtime-adapter.ts +686 -0
- package/platforms/electrobun/src/voice/voice-service.test.ts +561 -0
- package/platforms/electrobun/src/voice/voice-service.ts +1027 -0
- package/platforms/electrobun/src/voice/voice-stream-coordinator.test.ts +115 -0
- package/platforms/electrobun/src/voice/voice-stream-coordinator.ts +270 -0
- package/platforms/electrobun/src/voice/voice-trace.ts +97 -0
- package/platforms/electrobun/src/voice/voice-tts-chunker.test.ts +91 -0
- package/platforms/electrobun/src/voice/voice-tts-chunker.ts +194 -0
- package/platforms/electrobun/src/windows-cef-profile.ts +88 -88
- package/platforms/electrobun/tsconfig.json +73 -13
- package/platforms/electrobun/update-channels.json +22 -0
- package/platforms/electrobun/vitest.electrobun.config.ts +72 -42
- package/platforms/ios/App/App/App.entitlements +4 -0
- package/platforms/ios/App/App/AppDelegate.swift +80 -18
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ios-marketing-1024.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20x20@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20x20@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29x29@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29x29@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40x40@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40x40@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76x76@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76x76@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83_5x83_5@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20x20@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20x20@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29x29@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29x29@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40x40@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40x40@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60x60@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60x60@3x.png +0 -0
- package/platforms/ios/App/App/Base.lproj/LaunchScreen.storyboard +1 -4
- package/platforms/ios/App/App/ComputerUseBridge.swift +589 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/DeviceActivityMonitorExtension.entitlements +12 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/DeviceActivityMonitorExtension.swift +34 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/Info.plist +29 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/DeviceActivityReportExtension.entitlements +12 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/DeviceActivityReportExtension.swift +53 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/Info.plist +27 -0
- package/platforms/ios/App/App/ElizaAppIntents.swift +183 -0
- package/platforms/ios/App/App/ElizaIntentPlugin.swift +342 -5
- package/platforms/ios/App/App/Info.plist +17 -1
- package/platforms/ios/App/App/runners/eliza-tasks.js +177 -0
- package/platforms/ios/App/App.xcodeproj/project.pbxproj +262 -6
- package/platforms/ios/App/BroadcastExtension/SampleHandler.swift +100 -0
- package/platforms/ios/App/Podfile +5 -0
- package/platforms/ios/App/Podfile.lock +83 -59
- package/register-runtime-hooks.js +11 -5
- package/registry/app-registry.d.ts +14 -0
- package/registry/app-registry.d.ts.map +1 -0
- package/registry/app-registry.js +29 -0
- package/registry/entries/apps/app-polymarket.json +31 -0
- package/registry/entries/apps/clawville.json +27 -0
- package/registry/entries/apps/companion.json +28 -0
- package/registry/entries/apps/database-viewer.json +27 -0
- package/registry/entries/apps/defense-of-the-agents.json +27 -0
- package/registry/entries/apps/documents.json +30 -0
- package/registry/entries/apps/feed.json +27 -0
- package/registry/entries/apps/hyperliquid.json +31 -0
- package/registry/entries/apps/log-viewer.json +27 -0
- package/registry/entries/apps/memory-viewer.json +27 -0
- package/registry/entries/apps/model-tester.json +31 -0
- package/registry/entries/apps/plugin-viewer.json +27 -0
- package/registry/entries/apps/relationship-viewer.json +27 -0
- package/registry/entries/apps/runtime-debugger.json +27 -0
- package/registry/entries/apps/shopify.json +31 -0
- package/registry/entries/apps/skills-viewer.json +27 -0
- package/registry/entries/apps/steward.json +31 -0
- package/registry/entries/apps/training.json +54 -0
- package/registry/entries/apps/trajectory-viewer.json +27 -0
- package/registry/entries/apps/vincent.json +31 -0
- package/registry/entries/connectors/bluebubbles.json +99 -0
- package/registry/entries/connectors/bluesky.json +173 -0
- package/registry/entries/connectors/discord.json +119 -0
- package/registry/entries/connectors/farcaster.json +174 -0
- package/registry/entries/connectors/feishu.json +79 -0
- package/registry/entries/connectors/google-chat.json +120 -0
- package/registry/entries/connectors/google.json +82 -0
- package/registry/entries/connectors/imessage.json +96 -0
- package/registry/entries/connectors/instagram.json +64 -0
- package/registry/entries/connectors/line.json +86 -0
- package/registry/entries/connectors/matrix.json +94 -0
- package/registry/entries/connectors/mattermost.json +110 -0
- package/registry/entries/connectors/msteams.json +104 -0
- package/registry/entries/connectors/nextcloud-talk.json +104 -0
- package/registry/entries/connectors/nostr.json +70 -0
- package/registry/entries/connectors/signal.json +81 -0
- package/registry/entries/connectors/slack.json +102 -0
- package/registry/entries/connectors/telegram.json +71 -0
- package/registry/entries/connectors/tlon.json +94 -0
- package/registry/entries/connectors/twitch.json +110 -0
- package/registry/entries/connectors/whatsapp.json +113 -0
- package/registry/entries/connectors/x.json +231 -0
- package/registry/entries/connectors/zalo.json +112 -0
- package/registry/entries/connectors/zalouser.json +122 -0
- package/registry/entries/plugins/agent-orchestrator.json +33 -0
- package/registry/entries/plugins/agent-skills.json +72 -0
- package/registry/entries/plugins/anthropic.json +73 -0
- package/registry/entries/plugins/app-control.json +23 -0
- package/registry/entries/plugins/auto-trader.json +203 -0
- package/registry/entries/plugins/background-runner.json +26 -0
- package/registry/entries/plugins/blooio.json +102 -0
- package/registry/entries/plugins/browser.json +75 -0
- package/registry/entries/plugins/cli.json +40 -0
- package/registry/entries/plugins/clipboard.json +44 -0
- package/registry/entries/plugins/coding-tools.json +71 -0
- package/registry/entries/plugins/commands.json +63 -0
- package/registry/entries/plugins/computeruse.json +74 -0
- package/registry/entries/plugins/copilot-proxy.json +93 -0
- package/registry/entries/plugins/directives.json +63 -0
- package/registry/entries/plugins/edge-tts.json +97 -0
- package/registry/entries/plugins/elevenlabs.json +169 -0
- package/registry/entries/plugins/elizacloud.json +208 -0
- package/registry/entries/plugins/evm.json +134 -0
- package/registry/entries/plugins/experience.json +34 -0
- package/registry/entries/plugins/facewear.json +131 -0
- package/registry/entries/plugins/form.json +26 -0
- package/registry/entries/plugins/github.json +93 -0
- package/registry/entries/plugins/gmail-watch.json +25 -0
- package/registry/entries/plugins/goals.json +77 -0
- package/registry/entries/plugins/google-genai.json +106 -0
- package/registry/entries/plugins/groq.json +93 -0
- package/registry/entries/plugins/hedera.json +48 -0
- package/registry/entries/plugins/inmemorydb.json +25 -0
- package/registry/entries/plugins/linear.json +51 -0
- package/registry/entries/plugins/local-inference.json +142 -0
- package/registry/entries/plugins/local-storage.json +36 -0
- package/registry/entries/plugins/localdb.json +25 -0
- package/registry/entries/plugins/mcp.json +44 -0
- package/registry/entries/plugins/memory.json +124 -0
- package/registry/entries/plugins/minecraft.json +79 -0
- package/registry/entries/plugins/moltbook.json +83 -0
- package/registry/entries/plugins/music.json +155 -0
- package/registry/entries/plugins/mysticism.json +48 -0
- package/registry/entries/plugins/nearai.json +82 -0
- package/registry/entries/plugins/ngrok.json +69 -0
- package/registry/entries/plugins/ollama.json +96 -0
- package/registry/entries/plugins/openai.json +189 -0
- package/registry/entries/plugins/openrouter.json +188 -0
- package/registry/entries/plugins/pdf.json +26 -0
- package/registry/entries/plugins/plugin-manager.json +23 -0
- package/registry/entries/plugins/prose.json +48 -0
- package/registry/entries/plugins/rlm.json +26 -0
- package/registry/entries/plugins/roblox.json +88 -0
- package/registry/entries/plugins/rss.json +64 -0
- package/registry/entries/plugins/s3-storage.json +91 -0
- package/registry/entries/plugins/scheduling.json +35 -0
- package/registry/entries/plugins/shell.json +94 -0
- package/registry/entries/plugins/social-alpha.json +72 -0
- package/registry/entries/plugins/tailscale.json +81 -0
- package/registry/entries/plugins/tee.json +53 -0
- package/registry/entries/plugins/todos.json +26 -0
- package/registry/entries/plugins/trajectory-logger.json +33 -0
- package/registry/entries/plugins/trust.json +39 -0
- package/registry/entries/plugins/tts.json +71 -0
- package/registry/entries/plugins/tunnel.json +45 -0
- package/registry/entries/plugins/twilio.json +168 -0
- package/registry/entries/plugins/vercel-ai-gateway.json +128 -0
- package/registry/entries/plugins/video.json +23 -0
- package/registry/entries/plugins/vision.json +43 -0
- package/registry/entries/plugins/webhooks.json +23 -0
- package/registry/entries/plugins/workflow.json +25 -0
- package/registry/entries/plugins/xai.json +75 -0
- package/registry/index.d.ts +2 -1
- package/registry/index.d.ts.map +1 -1
- package/registry/index.js +46 -12
- package/registry/loader.d.ts +2 -1
- package/registry/loader.d.ts.map +1 -1
- package/registry/loader.js +49 -2
- package/registry/schema.d.ts +244 -34
- package/registry/schema.d.ts.map +1 -1
- package/registry/schema.js +36 -0
- package/runtime/android-avf-microdroid-bridge.d.ts +29 -0
- package/runtime/android-avf-microdroid-bridge.d.ts.map +1 -0
- package/runtime/android-avf-microdroid-bridge.js +149 -0
- package/runtime/api-dev-settings-banner.d.ts.map +1 -1
- package/runtime/api-dev-settings-banner.js +5 -13
- package/runtime/app-core-runtime-hooks.d.ts +21 -0
- package/runtime/app-core-runtime-hooks.d.ts.map +1 -0
- package/runtime/app-core-runtime-hooks.js +10 -0
- package/runtime/autonomy-policy.d.ts +2 -0
- package/runtime/autonomy-policy.d.ts.map +1 -0
- package/runtime/autonomy-policy.js +4 -0
- package/runtime/desktop/AppWindowRenderer.d.ts +17 -0
- package/runtime/desktop/AppWindowRenderer.d.ts.map +1 -0
- package/runtime/desktop/AppWindowRenderer.js +360 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.d.ts +2 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.d.ts.map +1 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.js +41 -0
- package/runtime/desktop/DesktopTrayRuntime.d.ts +2 -0
- package/runtime/desktop/DesktopTrayRuntime.d.ts.map +1 -0
- package/runtime/desktop/DesktopTrayRuntime.js +174 -0
- package/runtime/desktop/DetachedShellRoot.d.ts +10 -0
- package/runtime/desktop/DetachedShellRoot.d.ts.map +1 -0
- package/runtime/desktop/DetachedShellRoot.js +111 -0
- package/runtime/desktop/index.d.ts +6 -0
- package/runtime/desktop/index.d.ts.map +1 -0
- package/runtime/desktop/index.js +5 -0
- package/runtime/desktop/tray-menu.d.ts +20 -0
- package/runtime/desktop/tray-menu.d.ts.map +1 -0
- package/runtime/desktop/tray-menu.js +143 -0
- package/runtime/dev-server.d.ts +1 -1
- package/runtime/dev-server.d.ts.map +1 -1
- package/runtime/dev-server.js +93 -17
- package/runtime/eliza.d.ts +75 -1
- package/runtime/eliza.d.ts.map +1 -1
- package/runtime/eliza.js +596 -122
- package/runtime/ensure-text-to-speech-handler.d.ts.map +1 -1
- package/runtime/ensure-text-to-speech-handler.js +10 -3
- package/runtime/mobile-safe-runtime.d.ts +181 -2
- package/runtime/mobile-safe-runtime.d.ts.map +1 -1
- package/runtime/mobile-safe-runtime.js +1019 -12
- package/runtime/mode/remote-forwarder.d.ts.map +1 -1
- package/runtime/mode/remote-forwarder.js +2 -2
- package/runtime/mode/route-mode-guard.d.ts +1 -2
- package/runtime/mode/route-mode-guard.d.ts.map +1 -1
- package/runtime/mode/route-mode-guard.js +4 -5
- package/runtime/mode/route-mode-matrix.d.ts.map +1 -1
- package/runtime/mode/route-mode-matrix.js +14 -1
- package/runtime/mode/runtime-mode.d.ts +1 -1
- package/runtime/mode/runtime-mode.d.ts.map +1 -1
- package/runtime/mode/runtime-mode.js +15 -4
- package/runtime/runtime-bootstrap-policy.d.ts.map +1 -1
- package/runtime/runtime-bootstrap-policy.js +14 -2
- package/runtime/telegram-standalone-handler.d.ts.map +1 -1
- package/runtime/telegram-standalone-handler.js +10 -9
- package/runtime/tts-cache-wiring.d.ts +29 -0
- package/runtime/tts-cache-wiring.d.ts.map +1 -0
- package/runtime/tts-cache-wiring.js +114 -0
- package/runtime/voice-warmup.d.ts +81 -0
- package/runtime/voice-warmup.d.ts.map +1 -0
- package/runtime/voice-warmup.js +111 -0
- package/scripts/android-sms-gateway-template.test.mjs +1014 -0
- package/scripts/aosp/README.md +19 -15
- package/scripts/aosp/compile-libllama.mjs +1344 -248
- package/scripts/aosp/compile-shim.mjs +47 -18
- package/scripts/aosp/deploy-pixel.mjs +405 -0
- package/scripts/aosp/lib/load-variant-config.mjs +3 -3
- package/scripts/aosp/llama-cpp-patches/README.md +8 -8
- package/scripts/aosp/llama-cpp-patches/apply-patches.mjs +23 -6
- package/scripts/aosp/llama-cpp-patches/polarquant/README.md +37 -0
- package/scripts/aosp/llama-cpp-patches/qjl/README.md +37 -0
- package/scripts/aosp/seccomp-shim/sigsys-handler-arm64.c +169 -0
- package/scripts/aosp/seccomp-shim/sigsys-handler-riscv64.c +217 -0
- package/scripts/aosp/smoke-cuttlefish.mjs +34 -4
- package/scripts/aosp/stage-default-models.mjs +18 -18
- package/scripts/aosp/variant-config-schema.ts +2 -2
- package/scripts/assert-required-bundled-packages.test.ts +534 -0
- package/scripts/audit-apple-store-sandbox.mjs +146 -0
- package/scripts/audit-live-test-surface.mjs +5 -2
- package/scripts/build-capacitor-app.mjs +21 -0
- package/scripts/build-flatpak.mjs +5 -5
- package/scripts/build-helpers/arm64-simd.mjs +72 -0
- package/scripts/build-helpers/omnivoice-merged.mjs +87 -0
- package/scripts/build-helpers/verify-fused-symbols.mjs +567 -0
- package/scripts/build-image.sh +1 -1
- package/scripts/build-llama-cpp-mtp.mjs +487 -0
- package/scripts/build-native-plugins.mjs +230 -18
- package/scripts/build-patched-electrobun-cli.mjs +68 -10
- package/scripts/build-win.mjs +1 -1
- package/scripts/bun-riscv64/Dockerfile +418 -0
- package/scripts/bun-riscv64/README.md +316 -0
- package/scripts/bun-riscv64/build.sh +469 -0
- package/scripts/bun-riscv64/bun-patches/0001-config-add-riscv64-arch.patch +74 -0
- package/scripts/bun-riscv64/bun-patches/0002-flags-add-riscv64-march-mabi.patch +16 -0
- package/scripts/bun-riscv64/bun-patches/0003-zig-add-riscv64-target-triple-and-cpu.patch +26 -0
- package/scripts/bun-riscv64/bun-patches/0004-webkit-force-local-mode-on-riscv64.patch +33 -0
- package/scripts/bun-riscv64/bun-patches/0005-tinycc-disable-on-riscv64.patch +16 -0
- package/scripts/bun-riscv64/bun-patches/0006-build-add-riscv64-cli-validation.patch +15 -0
- package/scripts/bun-riscv64/bun-patches/0007-deps-per-dep-riscv64-checks.patch +24 -0
- package/scripts/bun-riscv64/bun-patches/0008-source-stabilize-riscv64-musl-build.patch +226 -0
- package/scripts/bun-riscv64/bun-patches/0009-disable-wasm-streaming-hooks-for-c-loop.patch +162 -0
- package/scripts/bun-riscv64/bun-patches/0010-disable-inspector-profiler-for-riscv64-c-loop.patch +80 -0
- package/scripts/bun-riscv64/bun-patches/0011-process-arch-add-riscv64.patch +23 -0
- package/scripts/bun-riscv64/bun-patches/0012-cpu-features-add-riscv64-fallback.patch +13 -0
- package/scripts/bun-riscv64/bun-patches/0013-disable-console-inspector-hooks-for-riscv64-c-loop.patch +43 -0
- package/scripts/bun-riscv64/bun-patches/0014-disable-custom-inspector-dispatchers-on-riscv64.patch +127 -0
- package/scripts/bun-riscv64/bun-patches/0015-disable-jsc-profiler-builtins-on-riscv64.patch +75 -0
- package/scripts/bun-riscv64/bun-patches/0016-node-vm-disable-jit-cached-data-on-riscv64-c-loop.patch +96 -0
- package/scripts/bun-riscv64/bun-patches/0017-disable-performance-domjit-signature-on-riscv64-c-loop.patch +34 -0
- package/scripts/bun-riscv64/bun-patches/0018-fix-serialized-script-identifier-big-endian-path.patch +19 -0
- package/scripts/bun-riscv64/bun-patches/0019-add-wtf-timer-fire-bridge-for-c-loop.patch +24 -0
- package/scripts/bun-riscv64/bun-patches/0020-run-riscv64-smoke-test-under-qemu.patch +13 -0
- package/scripts/bun-riscv64/bun-patches/0021-fix-riscv64-linux-open-flags.patch +25 -0
- package/scripts/bun-riscv64/bun-patches/0022-zlib-riscv64-generic-kernels.patch +25 -0
- package/scripts/bun-riscv64/bun-patches/README.md +127 -0
- package/scripts/bun-riscv64/bun-version.json +202 -0
- package/scripts/bun-riscv64/run-build.sh +162 -0
- package/scripts/bun-riscv64/rust-core/0001-riscv64-rust-core-port.patch +868 -0
- package/scripts/bun-riscv64/rust-core/0002-second-wave-riscv64-source-gaps.patch +130 -0
- package/scripts/bun-riscv64/rust-core/0003-third-wave-riscv64-crash-handler-gaps.patch +78 -0
- package/scripts/bun-riscv64/rust-core/0004-rust-target-cpu-riscv64.patch +39 -0
- package/scripts/bun-riscv64/rust-core/0005-fifth-wave-riscv64-source-gaps.patch +96 -0
- package/scripts/bun-riscv64/rust-core/0006-cpp-wasm-and-inspector-guards-riscv64.patch +91 -0
- package/scripts/bun-riscv64/rust-core/0007-bun-alloc-max-align-t-riscv64.patch +36 -0
- package/scripts/bun-riscv64/rust-core/0008-workspace-lints-warn-not-deny-riscv64.patch +75 -0
- package/scripts/bun-riscv64/rust-core/0009-zigglobalobject-wasm-streaming-guards-riscv64.patch +109 -0
- package/scripts/bun-riscv64/rust-core/0010-tcc-externs-stub-on-riscv64.patch +62 -0
- package/scripts/bun-riscv64/rust-core/0011-clippy-ptr-cast-lints-warn-riscv64.patch +61 -0
- package/scripts/bun-riscv64/rust-core/README.md +80 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0003-disable-dfg-ftl-on-riscv64.patch +60 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0004-riscv64-do-not-force-wasm-in-c-loop.patch +31 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0005-domjit-effect-allow-no-dfg-c-loop.patch +40 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0006-disable-usewasm-when-webassembly-compiled-out.patch +33 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0007-restore-dropped-includes-and-llint-fwd-decl.patch +31 -0
- package/scripts/bun-riscv64/validate.sh +264 -0
- package/scripts/bun-riscv64/webkit-patches/0001-cherry-pick-llint-riscv64.recipe +155 -0
- package/scripts/bun-riscv64/webkit-patches/0002-cherry-pick-baseline-jit-riscv64.recipe +40 -0
- package/scripts/bun-riscv64/webkit-patches/0003-disable-dfg-ftl-on-riscv64.patch +60 -0
- package/scripts/bun-riscv64/webkit-patches/0004-riscv64-do-not-force-wasm-in-c-loop.patch +31 -0
- package/scripts/bun-riscv64/webkit-patches/0005-domjit-effect-allow-no-dfg-c-loop.patch +40 -0
- package/scripts/bun-riscv64/webkit-patches/0006-disable-usewasm-when-webassembly-compiled-out.patch +33 -0
- package/scripts/bun-riscv64/webkit-patches/0007-restore-dropped-includes-and-llint-fwd-decl.patch +72 -0
- package/scripts/bun-riscv64/webkit-patches/README.md +146 -0
- package/scripts/check-homepage-public-readiness.mjs +353 -0
- package/scripts/check-homepage-release-data.mjs +110 -0
- package/scripts/check-i18n.mjs +2 -1
- package/scripts/check-real-local-chat.ts +147 -0
- package/scripts/check-real-local-provisioning.ts +104 -0
- package/scripts/check-real-local-reset.ts +249 -0
- package/scripts/check-sms-gateway-completion-audit.mjs +428 -0
- package/scripts/check-sms-gateway-readiness.mjs +266 -0
- package/scripts/clean-repo.mjs +5 -5
- package/scripts/codesign-mas.mjs +222 -16
- package/scripts/collect-docker-runtime-deps.mjs +229 -0
- package/scripts/continue-sms-gateway-work.mjs +121 -0
- package/scripts/copy-runtime-node-modules.ts +903 -195
- package/scripts/deploy-cloud-api-production-gateway.mjs +52 -0
- package/scripts/desktop-build.mjs +655 -101
- package/scripts/dev-platform.mjs +346 -102
- package/scripts/dev-startup-smoke.mjs +248 -0
- package/scripts/dev-ui.mjs +418 -176
- package/scripts/disable-local-eliza-workspace.mjs +35 -0
- package/scripts/docker-ci-smoke.sh +298 -96
- package/scripts/docker-entrypoint.sh +62 -1
- package/scripts/docker-entrypoint.test.ts +283 -0
- package/scripts/ensure-avatars.mjs +2 -2
- package/scripts/ensure-electrobun-core.mjs +1 -1
- package/scripts/ensure-generated-core-proto-js.mjs +1 -1
- package/scripts/ensure-type-package-aliases.mjs +62 -5
- package/scripts/ensure-vision-deps.mjs +20 -1
- package/scripts/entry.ts +1 -1
- package/scripts/ffi-stub/Makefile +64 -0
- package/scripts/ffi-stub/README.md +391 -0
- package/scripts/ffi-stub/asr-ffi-smoke.ts +139 -0
- package/scripts/ffi-stub/ffi-stub.c +539 -0
- package/scripts/ffi-stub/ffi.h +538 -0
- package/scripts/ffi-stub/libelizainference_stub.so +0 -0
- package/scripts/ffi-stub/tts-stream-ffi-smoke.ts +349 -0
- package/scripts/generate-first-run-voicelines.mjs +194 -0
- package/scripts/generate-plugin-index.js +4 -3
- package/scripts/generate-static-asset-manifest.mjs +1 -1
- package/scripts/i18n-dynamic-keys.json +5 -5
- package/scripts/init-submodules.mjs +2 -2
- package/scripts/install-android-sms-gateway.md +177 -0
- package/scripts/install-android-sms-gateway.mjs +1088 -0
- package/scripts/ios-xcframework/README.md +74 -72
- package/scripts/ios-xcframework/build-xcframework.mjs +204 -43
- package/scripts/ios-xcframework/run-physical-device-smoke.mjs +1943 -0
- package/scripts/ios-xcframework/runtime-symbol-shim.c +450 -0
- package/scripts/kernel-patches/cpu-polar-kernels.mjs +441 -0
- package/scripts/kernel-patches/cpu-simd-kernels.mjs +253 -0
- package/scripts/kernel-patches/cpu-thread-parallelism.mjs +368 -0
- package/scripts/kernel-patches/cuda-kernels.mjs +117 -0
- package/scripts/kernel-patches/metal-kernels.mjs +1698 -109
- package/scripts/kernel-patches/server-omnivoice-route.mjs +718 -0
- package/scripts/kernel-patches/server-structured-output.mjs +279 -0
- package/scripts/kernel-patches/vulkan-dispatch-log.mjs +166 -0
- package/scripts/kernel-patches/vulkan-dispatch-log.test.mjs +50 -0
- package/scripts/kernel-patches/vulkan-dispatch-patches/01-vulkan-shaders-gen.patch +30 -16
- package/scripts/kernel-patches/vulkan-dispatch-patches/02-ggml-vulkan-pipelines.patch +75 -30
- package/scripts/kernel-patches/vulkan-kernels.mjs +800 -49
- package/scripts/lib/agent-source-watcher.mjs +174 -0
- package/scripts/lib/agent-source-watcher.test.mjs +184 -0
- package/scripts/lib/api-supervisor.mjs +78 -9
- package/scripts/lib/api-supervisor.test.mjs +121 -0
- package/scripts/lib/app-dir.mjs +2 -16
- package/scripts/lib/apple-entitlement-audit.mjs +655 -0
- package/scripts/lib/apple-entitlement-audit.test.mjs +144 -0
- package/scripts/lib/bun-version-guard.mjs +13 -13
- package/scripts/lib/capacitor-plugin-build-needed.mjs +4 -3
- package/scripts/lib/capacitor-plugin-names.mjs +30 -14
- package/scripts/lib/desktop-preflight.mjs +9 -5
- package/scripts/lib/desktop-startup-embedding-warmup-policy.mjs +51 -0
- package/scripts/lib/desktop-startup-embedding-warmup-policy.test.mjs +55 -0
- package/scripts/lib/duet-bridge.d.mts +63 -0
- package/scripts/lib/duet-bridge.mjs +193 -0
- package/scripts/lib/node-path-env.mjs +4 -2
- package/scripts/lib/orchestrator-desktop-dev-banner.mjs +12 -3
- package/scripts/lib/patch-bun-exports.mjs +90 -27
- package/scripts/lib/patch-bun-exports.test.mjs +79 -0
- package/scripts/lib/renderer-build-action.mjs +35 -0
- package/scripts/lib/renderer-build-action.test.mjs +70 -0
- package/scripts/lib/stage-android-agent.mjs +748 -99
- package/scripts/lib/sync-eliza-env-aliases.mjs +3 -25
- package/scripts/lib/ui-smoke-stub-decision.mjs +33 -0
- package/scripts/lib/ui-smoke-stub-decision.test.mjs +46 -0
- package/scripts/lib/vite-renderer-dist-stale.mjs +5 -0
- package/scripts/lib/voice-latency-report.mjs +154 -0
- package/scripts/lifeops-prompt-benchmark.ts +21 -12
- package/scripts/link-docker-local-app-packages.mjs +89 -36
- package/scripts/local-stt-bench.ts +192 -0
- package/scripts/maintain-cloud-api-production-gateway.mjs +54 -0
- package/scripts/mas-smoke.mjs +459 -0
- package/scripts/mas-smoke.test.mjs +220 -0
- package/scripts/mobile-auth-simulator-smoke.mjs +0 -1
- package/scripts/normalize-eliza-capture.ts +97 -0
- package/scripts/omnivoice-fuse/prepare.mjs +2543 -23
- package/scripts/pack-upstreams.mjs +65 -5
- package/scripts/package-electrobun-linux.mjs +303 -0
- package/scripts/patch-deps.mjs +5 -3
- package/scripts/patches/llama-mobile-kokoro-tts.patch +480 -0
- package/scripts/playwright-ui-live-stack.ts +194 -49
- package/scripts/playwright-ui-smoke-api-stub.mjs +3501 -109
- package/scripts/pre-review-local.mjs +2 -2
- package/scripts/prepare-ios-cocoapods.sh +41 -3
- package/scripts/release-check.ts +180 -84
- package/scripts/release-workflow-drift.test.ts +57 -0
- package/scripts/relink-workspace-packages-to-dist.mjs +21 -4
- package/scripts/rt.mjs +16 -1
- package/scripts/run-biome-check.mjs +1 -1
- package/scripts/run-coding-agent-e2e.mjs +3 -3
- package/scripts/run-eliza-app-core-script.mjs +34 -0
- package/scripts/run-local-plugin-live-smoke.mjs +71 -2
- package/scripts/run-mobile-build-android-app-actions.test.mjs +426 -0
- package/scripts/run-mobile-build.mjs +4757 -607
- package/scripts/run-node-runtime.mjs +184 -7
- package/scripts/run-node-runtime.test.mjs +167 -0
- package/scripts/run-node-tsx.mjs +80 -33
- package/scripts/run-node.mjs +41 -1
- package/scripts/run-production-build.mjs +34 -27
- package/scripts/run-release-check.mjs +19 -0
- package/scripts/run-release-contract-suite.mjs +107 -14
- package/scripts/run-ui-smoke-playwright-suite.mjs +0 -2
- package/scripts/runtime-package-manifest.ts +21 -3
- package/scripts/setup-upstreams.mjs +42 -1
- package/scripts/sms-gateway-status.mjs +194 -0
- package/scripts/stage-android-agent.test.mjs +97 -0
- package/scripts/stage-elizavoice-lib.mjs +203 -0
- package/scripts/startup-integration-script-drift.test.ts +82 -4
- package/scripts/streaming-pipeline-bench.ts +543 -0
- package/scripts/sync-homepage-porkbun-dns.mjs +262 -0
- package/scripts/test-sms-gateway-software.mjs +100 -0
- package/scripts/type-audit.mjs +1 -1
- package/scripts/validate-bluebubbles-outbound.mjs +293 -0
- package/scripts/validate-cdn-assets.mjs +15 -7
- package/scripts/validate-regression-matrix.mjs +109 -8
- package/scripts/verify-android-sms-gateway-e2e.mjs +362 -0
- package/scripts/verify-bluebubbles-gateway-e2e.mjs +191 -0
- package/scripts/verify-bluebubbles-inbound-readiness.mjs +88 -0
- package/scripts/verify-cloud-api-production-deploy.mjs +87 -0
- package/scripts/verify-cloud-sms-onboarding-flow.mjs +336 -0
- package/scripts/voice/freeze-voice.mjs +521 -0
- package/scripts/voice-attribution-smoke.ts +538 -0
- package/scripts/voice-create-profile.mjs +379 -0
- package/scripts/voice-duet.mjs +1355 -0
- package/scripts/voice-e2e-hardware.ts +871 -0
- package/scripts/voice-interactive.mjs +1750 -0
- package/scripts/voice-latency-report.mjs +96 -0
- package/scripts/voice-latency-report.test.ts +176 -0
- package/scripts/voice-preset/build-default-voice-preset.mjs +249 -0
- package/scripts/voice-preset/build-onboarding-voice.mjs +281 -0
- package/scripts/watch-sms-gateway-readiness.mjs +303 -0
- package/scripts/write-homepage-release-data.mjs +458 -26
- package/security/agent-vault-id.d.ts +1 -1
- package/security/agent-vault-id.js +1 -1
- package/security/hydrate-wallet-keys-from-platform-store.d.ts.map +1 -1
- package/security/hydrate-wallet-keys-from-platform-store.js +23 -14
- package/security/platform-secure-store-node.d.ts +2 -2
- package/security/platform-secure-store-node.js +3 -3
- package/security/wallet-os-store-actions.d.ts +0 -9
- package/security/wallet-os-store-actions.d.ts.map +1 -1
- package/security/wallet-os-store-actions.js +3 -10
- package/services/account-pool.d.ts +23 -14
- package/services/account-pool.d.ts.map +1 -1
- package/services/account-pool.js +86 -24
- package/services/account-usage.d.ts.map +1 -1
- package/services/account-usage.js +2 -5
- package/services/ambient-audio/consent.d.ts +9 -0
- package/services/ambient-audio/consent.d.ts.map +1 -0
- package/services/ambient-audio/consent.js +28 -0
- package/services/ambient-audio/index.d.ts +7 -0
- package/services/ambient-audio/index.d.ts.map +1 -0
- package/services/ambient-audio/index.js +4 -0
- package/services/ambient-audio/replay-buffer.d.ts +14 -0
- package/services/ambient-audio/replay-buffer.d.ts.map +1 -0
- package/services/ambient-audio/replay-buffer.js +66 -0
- package/services/ambient-audio/response-gate.d.ts +3 -0
- package/services/ambient-audio/response-gate.d.ts.map +1 -0
- package/services/ambient-audio/response-gate.js +33 -0
- package/services/ambient-audio/service.d.ts +22 -0
- package/services/ambient-audio/service.d.ts.map +1 -0
- package/services/ambient-audio/service.js +47 -0
- package/services/ambient-audio/types.d.ts +42 -0
- package/services/ambient-audio/types.d.ts.map +1 -0
- package/services/app-updates/update-policy.d.ts +64 -0
- package/services/app-updates/update-policy.d.ts.map +1 -0
- package/services/app-updates/update-policy.js +228 -0
- package/services/auth-store.d.ts +37 -1
- package/services/auth-store.d.ts.map +1 -1
- package/services/auth-store.js +59 -26
- package/services/cloud-jwks-store.d.ts +3 -3
- package/services/cloud-jwks-store.d.ts.map +1 -1
- package/services/cloud-jwks-store.js +5 -8
- package/services/coding-account-bridge.d.ts +71 -0
- package/services/coding-account-bridge.d.ts.map +1 -0
- package/services/coding-account-bridge.js +267 -0
- package/services/connector-target-catalog.d.ts +10 -3
- package/services/connector-target-catalog.d.ts.map +1 -1
- package/services/connector-target-catalog.js +7 -4
- package/services/credential-tunnel-service.d.ts +66 -0
- package/services/credential-tunnel-service.d.ts.map +1 -0
- package/services/credential-tunnel-service.js +227 -0
- package/services/github-credentials.d.ts +1 -1
- package/services/github-credentials.js +1 -1
- package/services/inference-abort.d.ts +47 -0
- package/services/inference-abort.d.ts.map +1 -0
- package/services/inference-abort.js +76 -0
- package/services/persistence.d.ts +2 -3
- package/services/persistence.d.ts.map +1 -1
- package/services/persistence.js +2 -3
- package/services/phrase-chunked-tts.d.ts +136 -0
- package/services/phrase-chunked-tts.d.ts.map +1 -0
- package/services/phrase-chunked-tts.js +208 -0
- package/services/sandbox-registry.d.ts +78 -0
- package/services/sandbox-registry.d.ts.map +1 -0
- package/services/sandbox-registry.js +323 -0
- package/services/secrets-manager-installer.d.ts +8 -1
- package/services/secrets-manager-installer.d.ts.map +1 -1
- package/services/secrets-manager-installer.js +27 -2
- package/services/sensitive-requests/cloud-link-adapter.d.ts +15 -0
- package/services/sensitive-requests/cloud-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/cloud-link-adapter.js +73 -0
- package/services/sensitive-requests/index.d.ts +27 -0
- package/services/sensitive-requests/index.d.ts.map +1 -0
- package/services/sensitive-requests/index.js +51 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.d.ts +14 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.js +22 -0
- package/services/sensitive-requests/owner-app-inline-adapter.d.ts +3 -0
- package/services/sensitive-requests/owner-app-inline-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/owner-app-inline-adapter.js +146 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.d.ts +3 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.js +156 -0
- package/services/sensitive-requests/public-link-adapter.d.ts +14 -0
- package/services/sensitive-requests/public-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/public-link-adapter.js +86 -0
- package/services/sensitive-requests/tunnel-link-adapter.d.ts +17 -0
- package/services/sensitive-requests/tunnel-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/tunnel-link-adapter.js +38 -0
- package/services/steward-credentials.d.ts +1 -1
- package/services/steward-credentials.d.ts.map +1 -1
- package/services/steward-credentials.js +10 -6
- package/services/steward-sidecar/health-check.d.ts.map +1 -1
- package/services/steward-sidecar/health-check.js +4 -3
- package/services/steward-sidecar/process-management.d.ts +1 -1
- package/services/steward-sidecar/process-management.d.ts.map +1 -1
- package/services/steward-sidecar/process-management.js +9 -3
- package/services/steward-sidecar/types.d.ts +1 -1
- package/services/steward-sidecar/types.d.ts.map +1 -1
- package/services/steward-sidecar/wallet-setup.d.ts.map +1 -1
- package/services/steward-sidecar/wallet-setup.js +8 -7
- package/services/steward-sidecar.d.ts +2 -2
- package/services/steward-sidecar.d.ts.map +1 -1
- package/services/steward-sidecar.js +27 -19
- package/services/task-host-capabilities.d.ts +60 -0
- package/services/task-host-capabilities.d.ts.map +1 -0
- package/services/task-host-capabilities.js +122 -0
- package/services/tool-call-cache/index.d.ts +2 -2
- package/services/tool-call-cache/index.d.ts.map +1 -1
- package/services/tool-call-cache/index.js +1 -1
- package/services/trigger-event-bridge.js +1 -1
- package/services/tunnel-to-mobile/index.d.ts +2 -0
- package/services/tunnel-to-mobile/index.d.ts.map +1 -0
- package/services/tunnel-to-mobile/index.js +1 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.d.ts +105 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.d.ts.map +1 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.js +190 -0
- package/services/vault-bootstrap.d.ts.map +1 -1
- package/services/vault-bootstrap.js +48 -21
- package/services/vault-mirror.d.ts +1 -1
- package/services/vault-mirror.d.ts.map +1 -1
- package/services/vault-mirror.js +29 -6
- package/services/voice-profiles/diarization-pipeline.d.ts +6 -0
- package/services/voice-profiles/diarization-pipeline.d.ts.map +1 -0
- package/services/voice-profiles/diarization-pipeline.js +20 -0
- package/services/voice-profiles/index.d.ts +12 -0
- package/services/voice-profiles/index.d.ts.map +1 -0
- package/services/voice-profiles/index.js +5 -0
- package/services/voice-profiles/nickname-evaluator.d.ts +14 -0
- package/services/voice-profiles/nickname-evaluator.d.ts.map +1 -0
- package/services/voice-profiles/nickname-evaluator.js +46 -0
- package/services/voice-profiles/owner-confidence.d.ts +10 -0
- package/services/voice-profiles/owner-confidence.d.ts.map +1 -0
- package/services/voice-profiles/owner-confidence.js +38 -0
- package/services/voice-profiles/private-challenge.d.ts +20 -0
- package/services/voice-profiles/private-challenge.d.ts.map +1 -0
- package/services/voice-profiles/private-challenge.js +44 -0
- package/services/voice-profiles/store.d.ts +21 -0
- package/services/voice-profiles/store.d.ts.map +1 -0
- package/services/voice-profiles/store.js +50 -0
- package/services/voice-profiles/types.d.ts +38 -0
- package/services/voice-profiles/types.d.ts.map +1 -0
- package/services/voice-profiles/types.js +1 -0
- package/styles/electrobun-mac-window-drag.css +4 -4
- package/test/helpers/__tests__/live-agent-test.smoke.test.ts +43 -70
- package/test/helpers/browser-mocks.ts +2 -2
- package/test/helpers/conditional-tests.ts +2 -2
- package/test/helpers/i18n.ts +1 -1
- package/test/helpers/live-agent-test.ts +537 -551
- package/test/helpers/live-provider.test.ts +4 -4
- package/test/helpers/live-provider.ts +41 -7
- package/test/helpers/live-runtime-server.ts +4 -4
- package/test/helpers/pglite-runtime.ts +1 -1
- package/test/helpers/real-runtime.ts +54 -15
- package/test/helpers/trajectory-harness.ts +11 -7
- package/test/scripts/start-eliza-live.ts +9 -0
- package/test/scripts/test-parallel.mjs +1 -1
- package/test/scripts/test-root-unit.mjs +6 -7
- package/ui-compat.d.ts +13 -2
- package/ui-compat.d.ts.map +1 -1
- package/ui-compat.js +19 -3
- package/api/auth-pairing-compat-routes.d.ts +0 -17
- package/api/auth-pairing-compat-routes.d.ts.map +0 -1
- package/api/auth-pairing-compat-routes.js +0 -301
- package/api/local-inference-compat-routes.d.ts +0 -16
- package/api/local-inference-compat-routes.d.ts.map +0 -1
- package/api/local-inference-compat-routes.js +0 -617
- package/api/onboarding-compat-routes.d.ts +0 -4
- package/api/onboarding-compat-routes.d.ts.map +0 -1
- package/api/onboarding-compat-routes.js +0 -207
- package/api/plugins-compat-routes.d.ts +0 -103
- package/api/plugins-compat-routes.d.ts.map +0 -1
- package/api/plugins-compat-routes.js +0 -1181
- package/api/server-onboarding-compat.d.ts +0 -31
- package/api/server-onboarding-compat.d.ts.map +0 -1
- package/api/server-onboarding-compat.js +0 -283
- package/benchmark/cua-routes.d.ts +0 -10
- package/benchmark/cua-routes.d.ts.map +0 -1
- package/benchmark/cua-routes.js +0 -179
- package/benchmark/mock-plugin-base.d.ts +0 -9
- package/benchmark/mock-plugin-base.d.ts.map +0 -1
- package/benchmark/mock-plugin-base.js +0 -325
- package/cli/parse-duration.d.ts +0 -5
- package/cli/parse-duration.d.ts.map +0 -1
- package/cli/parse-duration.js +0 -27
- package/patches/llama-cpp-capacitor@0.1.5.patch +0 -2387
- package/platform/agent-browser-stub.d.ts +0 -27
- package/platform/agent-browser-stub.d.ts.map +0 -1
- package/platform/agent-browser-stub.js +0 -16
- package/platforms/android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java +0 -26
- package/platforms/android/app/src/main/res/drawable/ic_launcher_background.xml +0 -170
- package/platforms/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -34
- package/platforms/android/app/src/test/java/com/getcapacitor/myapp/ExampleUnitTest.java +0 -18
- package/platforms/electrobun/assets/appIcon.iconset/icon_512x512@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.png +0 -0
- package/platforms/electrobun/scripts/build-whisper-universal.sh +0 -137
- package/platforms/electrobun/scripts/build-whisper.sh +0 -95
- package/platforms/electrobun/src/libMacWindowEffects.dylib +0 -0
- package/platforms/electrobun/src/native/whisper.ts +0 -280
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
- package/registry/generate-apps.d.ts +0 -2
- package/registry/generate-apps.d.ts.map +0 -1
- package/registry/generate-apps.js +0 -338
- package/registry/generate.d.ts +0 -2
- package/registry/generate.d.ts.map +0 -1
- package/registry/generate.js +0 -506
- package/runtime/embedding-manager-support.d.ts +0 -77
- package/runtime/embedding-manager-support.d.ts.map +0 -1
- package/runtime/embedding-manager-support.js +0 -309
- package/runtime/embedding-presets.d.ts +0 -5
- package/runtime/embedding-presets.d.ts.map +0 -1
- package/runtime/embedding-presets.js +0 -47
- package/runtime/embedding-warmup-policy.d.ts +0 -13
- package/runtime/embedding-warmup-policy.d.ts.map +0 -1
- package/runtime/embedding-warmup-policy.js +0 -33
- package/runtime/ensure-local-inference-handler.d.ts +0 -25
- package/runtime/ensure-local-inference-handler.d.ts.map +0 -1
- package/runtime/ensure-local-inference-handler.js +0 -389
- package/runtime/mobile-local-inference-gate.d.ts +0 -21
- package/runtime/mobile-local-inference-gate.d.ts.map +0 -1
- package/runtime/mobile-local-inference-gate.js +0 -24
- package/scripts/aosp/avd-test.mjs +0 -403
- package/scripts/aosp/boot-validate.mjs +0 -536
- package/scripts/aosp/build-aosp.mjs +0 -448
- package/scripts/aosp/build-bootanimation.mjs +0 -178
- package/scripts/aosp/capture-screens.mjs +0 -325
- package/scripts/aosp/e2e-validate.mjs +0 -225
- package/scripts/aosp/lint-init-rc.mjs +0 -258
- package/scripts/aosp/llama-shim/eliza_llama_shim.c +0 -276
- package/scripts/aosp/sim.mjs +0 -277
- package/scripts/aosp/sync-to-aosp.mjs +0 -134
- package/scripts/aosp/validate.mjs +0 -1273
- package/scripts/build-llama-cpp-dflash.mjs +0 -1866
- package/scripts/generate-onboarding-voicelines.mjs +0 -194
- package/scripts/generated/static-asset-manifest.json +0 -4
- package/scripts/normalize-parallax-capture.ts +0 -97
- package/scripts/omnivoice-fuse/Makefile +0 -44
- package/scripts/omnivoice-fuse/README.md +0 -266
- package/scripts/omnivoice-fuse/cmake-graft.mjs +0 -180
- package/scripts/omnivoice-fuse/ffi-stub.c +0 -222
- package/scripts/omnivoice-fuse/ffi.h +0 -158
- package/scripts/omnivoice-fuse/libelizainference_stub.dylib +0 -0
- package/scripts/omnivoice-fuse/verify-symbols.mjs +0 -138
- package/security/cloud-secret-store.d.ts +0 -34
- package/security/cloud-secret-store.d.ts.map +0 -1
- package/security/cloud-secret-store.js +0 -65
- package/security/export-guard.d.ts +0 -34
- package/security/export-guard.d.ts.map +0 -1
- package/security/export-guard.js +0 -127
- package/services/local-inference/__stress__/cache-stress-helpers.d.ts +0 -76
- package/services/local-inference/__stress__/cache-stress-helpers.d.ts.map +0 -1
- package/services/local-inference/__stress__/cache-stress-helpers.js +0 -238
- package/services/local-inference/active-model.d.ts +0 -180
- package/services/local-inference/active-model.d.ts.map +0 -1
- package/services/local-inference/active-model.js +0 -362
- package/services/local-inference/assignments.d.ts +0 -58
- package/services/local-inference/assignments.d.ts.map +0 -1
- package/services/local-inference/assignments.js +0 -179
- package/services/local-inference/backend.d.ts +0 -200
- package/services/local-inference/backend.d.ts.map +0 -1
- package/services/local-inference/backend.js +0 -242
- package/services/local-inference/bundled-models.d.ts +0 -34
- package/services/local-inference/bundled-models.d.ts.map +0 -1
- package/services/local-inference/bundled-models.js +0 -104
- package/services/local-inference/cache-bridge.d.ts +0 -184
- package/services/local-inference/cache-bridge.d.ts.map +0 -1
- package/services/local-inference/cache-bridge.js +0 -333
- package/services/local-inference/catalog.d.ts +0 -57
- package/services/local-inference/catalog.d.ts.map +0 -1
- package/services/local-inference/catalog.js +0 -262
- package/services/local-inference/conversation-registry.d.ts +0 -122
- package/services/local-inference/conversation-registry.d.ts.map +0 -1
- package/services/local-inference/conversation-registry.js +0 -182
- package/services/local-inference/device-bridge.d.ts +0 -139
- package/services/local-inference/device-bridge.d.ts.map +0 -1
- package/services/local-inference/device-bridge.js +0 -774
- package/services/local-inference/dflash-doctor.d.ts +0 -27
- package/services/local-inference/dflash-doctor.d.ts.map +0 -1
- package/services/local-inference/dflash-doctor.js +0 -149
- package/services/local-inference/dflash-server.d.ts +0 -248
- package/services/local-inference/dflash-server.d.ts.map +0 -1
- package/services/local-inference/dflash-server.js +0 -1076
- package/services/local-inference/downloader.d.ts +0 -48
- package/services/local-inference/downloader.d.ts.map +0 -1
- package/services/local-inference/downloader.js +0 -688
- package/services/local-inference/engine.d.ts +0 -282
- package/services/local-inference/engine.d.ts.map +0 -1
- package/services/local-inference/engine.js +0 -743
- package/services/local-inference/external-scanner.d.ts +0 -17
- package/services/local-inference/external-scanner.d.ts.map +0 -1
- package/services/local-inference/external-scanner.js +0 -261
- package/services/local-inference/handler-registry.d.ts +0 -72
- package/services/local-inference/handler-registry.d.ts.map +0 -1
- package/services/local-inference/handler-registry.js +0 -159
- package/services/local-inference/hardware.d.ts +0 -26
- package/services/local-inference/hardware.d.ts.map +0 -1
- package/services/local-inference/hardware.js +0 -139
- package/services/local-inference/hf-search.d.ts +0 -19
- package/services/local-inference/hf-search.d.ts.map +0 -1
- package/services/local-inference/hf-search.js +0 -169
- package/services/local-inference/index.d.ts +0 -10
- package/services/local-inference/index.d.ts.map +0 -1
- package/services/local-inference/index.js +0 -7
- package/services/local-inference/llama-server-metrics.d.ts +0 -108
- package/services/local-inference/llama-server-metrics.d.ts.map +0 -1
- package/services/local-inference/llama-server-metrics.js +0 -175
- package/services/local-inference/manifest/index.d.ts +0 -4
- package/services/local-inference/manifest/index.d.ts.map +0 -1
- package/services/local-inference/manifest/index.js +0 -5
- package/services/local-inference/manifest/schema.d.ts +0 -419
- package/services/local-inference/manifest/schema.d.ts.map +0 -1
- package/services/local-inference/manifest/schema.js +0 -227
- package/services/local-inference/manifest/types.d.ts +0 -23
- package/services/local-inference/manifest/types.d.ts.map +0 -1
- package/services/local-inference/manifest/types.js +0 -5
- package/services/local-inference/manifest/validator.d.ts +0 -43
- package/services/local-inference/manifest/validator.d.ts.map +0 -1
- package/services/local-inference/manifest/validator.js +0 -180
- package/services/local-inference/paths.d.ts +0 -8
- package/services/local-inference/paths.d.ts.map +0 -1
- package/services/local-inference/paths.js +0 -7
- package/services/local-inference/providers.d.ts +0 -61
- package/services/local-inference/providers.d.ts.map +0 -1
- package/services/local-inference/providers.js +0 -334
- package/services/local-inference/ram-budget.d.ts +0 -57
- package/services/local-inference/ram-budget.d.ts.map +0 -1
- package/services/local-inference/ram-budget.js +0 -107
- package/services/local-inference/readiness.d.ts +0 -9
- package/services/local-inference/readiness.d.ts.map +0 -1
- package/services/local-inference/readiness.js +0 -153
- package/services/local-inference/recommendation.d.ts +0 -62
- package/services/local-inference/recommendation.d.ts.map +0 -1
- package/services/local-inference/recommendation.js +0 -309
- package/services/local-inference/registry.d.ts +0 -35
- package/services/local-inference/registry.d.ts.map +0 -1
- package/services/local-inference/registry.js +0 -117
- package/services/local-inference/router-handler.d.ts +0 -51
- package/services/local-inference/router-handler.d.ts.map +0 -1
- package/services/local-inference/router-handler.js +0 -165
- package/services/local-inference/routing-policy.d.ts +0 -55
- package/services/local-inference/routing-policy.d.ts.map +0 -1
- package/services/local-inference/routing-policy.js +0 -195
- package/services/local-inference/routing-preferences.d.ts +0 -8
- package/services/local-inference/routing-preferences.d.ts.map +0 -1
- package/services/local-inference/routing-preferences.js +0 -7
- package/services/local-inference/service.d.ts +0 -88
- package/services/local-inference/service.d.ts.map +0 -1
- package/services/local-inference/service.js +0 -210
- package/services/local-inference/session-pool.d.ts +0 -72
- package/services/local-inference/session-pool.d.ts.map +0 -1
- package/services/local-inference/session-pool.js +0 -125
- package/services/local-inference/types.d.ts +0 -309
- package/services/local-inference/types.d.ts.map +0 -1
- package/services/local-inference/types.js +0 -23
- package/services/local-inference/verify.d.ts +0 -8
- package/services/local-inference/verify.d.ts.map +0 -1
- package/services/local-inference/verify.js +0 -7
- package/services/local-inference/voice/barge-in.d.ts +0 -15
- package/services/local-inference/voice/barge-in.d.ts.map +0 -1
- package/services/local-inference/voice/barge-in.js +0 -20
- package/services/local-inference/voice/engine-bridge.d.ts +0 -256
- package/services/local-inference/voice/engine-bridge.d.ts.map +0 -1
- package/services/local-inference/voice/engine-bridge.js +0 -398
- package/services/local-inference/voice/ffi-bindings.d.ts +0 -114
- package/services/local-inference/voice/ffi-bindings.d.ts.map +0 -1
- package/services/local-inference/voice/ffi-bindings.js +0 -281
- package/services/local-inference/voice/index.d.ts +0 -51
- package/services/local-inference/voice/index.d.ts.map +0 -1
- package/services/local-inference/voice/index.js +0 -50
- package/services/local-inference/voice/lifecycle.d.ts +0 -135
- package/services/local-inference/voice/lifecycle.d.ts.map +0 -1
- package/services/local-inference/voice/lifecycle.js +0 -189
- package/services/local-inference/voice/phoneme-tokenizer.d.ts +0 -58
- package/services/local-inference/voice/phoneme-tokenizer.d.ts.map +0 -1
- package/services/local-inference/voice/phoneme-tokenizer.js +0 -53
- package/services/local-inference/voice/phrase-cache.d.ts +0 -24
- package/services/local-inference/voice/phrase-cache.d.ts.map +0 -1
- package/services/local-inference/voice/phrase-cache.js +0 -32
- package/services/local-inference/voice/phrase-chunker.d.ts +0 -20
- package/services/local-inference/voice/phrase-chunker.d.ts.map +0 -1
- package/services/local-inference/voice/phrase-chunker.js +0 -85
- package/services/local-inference/voice/ring-buffer.d.ts +0 -40
- package/services/local-inference/voice/ring-buffer.d.ts.map +0 -1
- package/services/local-inference/voice/ring-buffer.js +0 -85
- package/services/local-inference/voice/rollback-queue.d.ts +0 -24
- package/services/local-inference/voice/rollback-queue.d.ts.map +0 -1
- package/services/local-inference/voice/rollback-queue.js +0 -49
- package/services/local-inference/voice/scheduler.d.ts +0 -47
- package/services/local-inference/voice/scheduler.d.ts.map +0 -1
- package/services/local-inference/voice/scheduler.js +0 -123
- package/services/local-inference/voice/shared-resources.d.ts +0 -119
- package/services/local-inference/voice/shared-resources.d.ts.map +0 -1
- package/services/local-inference/voice/shared-resources.js +0 -83
- package/services/local-inference/voice/speaker-preset-cache.d.ts +0 -28
- package/services/local-inference/voice/speaker-preset-cache.d.ts.map +0 -1
- package/services/local-inference/voice/speaker-preset-cache.js +0 -44
- package/services/local-inference/voice/types.d.ts +0 -80
- package/services/local-inference/voice/types.d.ts.map +0 -1
- package/services/local-inference/voice/voice-preset-format.d.ts +0 -56
- package/services/local-inference/voice/voice-preset-format.d.ts.map +0 -1
- package/services/local-inference/voice/voice-preset-format.js +0 -184
- package/services/plugin-installer.d.ts +0 -22
- package/services/plugin-installer.d.ts.map +0 -1
- package/services/plugin-installer.js +0 -41
- package/test/scripts/task-agent-live-smoke.ts +0 -1335
- /package/services/{local-inference/voice → ambient-audio}/types.js +0 -0
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
* remote -- it simply connects to `http://localhost:{port}`.
|
|
18
18
|
*
|
|
19
19
|
* **Port policy (WHY):** we resolve a **free** loopback desktop API port from
|
|
20
|
-
* `ELIZA_API_PORT
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* restores lsof-based reclaim for single-instance dev.
|
|
20
|
+
* `ELIZA_API_PORT` or `ELIZA_PORT` (see `findFirstAvailableLoopbackPort`)
|
|
21
|
+
* instead of SIGKILL-ing listeners by default, so two desktop apps can run
|
|
22
|
+
* side by side. Optional `ELIZA_AGENT_RECLAIM_STALE_PORT=1` restores
|
|
23
|
+
* lsof-based reclaim for single-instance dev.
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
26
|
import crypto from "node:crypto";
|
|
@@ -29,65 +28,82 @@ import fs from "node:fs";
|
|
|
29
28
|
import os from "node:os";
|
|
30
29
|
import path from "node:path";
|
|
31
30
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
resolveApiToken,
|
|
32
|
+
resolveDesktopApiPort,
|
|
33
|
+
resolveDisableAutoApiToken,
|
|
34
|
+
setApiToken,
|
|
36
35
|
} from "@elizaos/shared";
|
|
37
36
|
import { Utils } from "electrobun/bun";
|
|
38
37
|
import { resolveDesktopRuntimeMode } from "../api-base";
|
|
39
38
|
import { getBrandConfig } from "../brand-config";
|
|
40
39
|
import { DEFAULT_API_PORT } from "../constants";
|
|
40
|
+
import {
|
|
41
|
+
acquireDatabaseStartupLock,
|
|
42
|
+
applyDatabaseResolutionToEnv,
|
|
43
|
+
backupPgliteDirectory,
|
|
44
|
+
classifyDatabaseError,
|
|
45
|
+
createDatabaseSnapshot,
|
|
46
|
+
createUnknownDatabaseSnapshot,
|
|
47
|
+
type DatabaseSnapshot,
|
|
48
|
+
type DatabaseStartupLock,
|
|
49
|
+
ensurePgliteDataDir,
|
|
50
|
+
redactDatabaseTarget,
|
|
51
|
+
resetPgliteDirectory,
|
|
52
|
+
resolveDatabaseMode,
|
|
53
|
+
updateDatabaseSnapshotStatus,
|
|
54
|
+
} from "../database";
|
|
41
55
|
import { logger } from "../logger";
|
|
42
56
|
import { recordStartupPhase, resolveStartupBundlePath } from "../startup-trace";
|
|
43
57
|
import type { SendToWebview } from "../types.js";
|
|
44
58
|
import { findFirstAvailableLoopbackPort } from "./loopback-port";
|
|
59
|
+
import { applyBundledWhisperEnv } from "./whisper-env";
|
|
45
60
|
|
|
46
61
|
// ---------------------------------------------------------------------------
|
|
47
62
|
// Types
|
|
48
63
|
// ---------------------------------------------------------------------------
|
|
49
64
|
|
|
50
65
|
interface AgentStatus {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
state: "not_started" | "starting" | "running" | "stopped" | "error";
|
|
67
|
+
agentName: string | null;
|
|
68
|
+
port: number | null;
|
|
69
|
+
startedAt: number | null;
|
|
70
|
+
error: string | null;
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
export interface StartupDiagnosticsSnapshot {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
state: AgentStatus["state"];
|
|
75
|
+
phase: string;
|
|
76
|
+
updatedAt: string;
|
|
77
|
+
lastError: string | null;
|
|
78
|
+
agentName: string | null;
|
|
79
|
+
port: number | null;
|
|
80
|
+
startedAt: number | null;
|
|
81
|
+
platform: string;
|
|
82
|
+
arch: string;
|
|
83
|
+
configDir: string;
|
|
84
|
+
logPath: string;
|
|
85
|
+
statusPath: string;
|
|
86
|
+
database: DatabaseSnapshot;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
export interface BugReportBundleResult {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
directory: string;
|
|
91
|
+
reportMarkdownPath: string;
|
|
92
|
+
reportJsonPath: string;
|
|
93
|
+
startupLogPath: string | null;
|
|
94
|
+
startupStatusPath: string | null;
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
import type {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
ExistingElizaInstallInfo,
|
|
99
|
+
ExistingElizaInstallSource,
|
|
100
|
+
StateDirMigrationResult,
|
|
85
101
|
} from "../rpc-schema";
|
|
86
102
|
|
|
87
103
|
export type {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
ExistingElizaInstallInfo,
|
|
105
|
+
ExistingElizaInstallSource,
|
|
106
|
+
StateDirMigrationResult,
|
|
91
107
|
};
|
|
92
108
|
|
|
93
109
|
// Subprocess type from Bun.spawn
|
|
@@ -104,283 +120,408 @@ const WINDOWS_ABS_PATH_RE = /^[A-Za-z]:[\\/]/;
|
|
|
104
120
|
const ELIZA_CONFIG_FILENAME = "eliza.json";
|
|
105
121
|
|
|
106
122
|
export function getHealthPollTimeoutMs(
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
124
|
+
platform: string = process.platform,
|
|
109
125
|
): number {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
const raw = env.ELIZA_AGENT_HEALTH_TIMEOUT_MS?.trim();
|
|
127
|
+
if (raw) {
|
|
128
|
+
const parsed = Number.parseInt(raw, 10);
|
|
129
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
130
|
+
return parsed;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Windows packaged first-run startup can include PGLite initialization plus
|
|
135
|
+
// a GGUF embedding model download before /api/health comes online.
|
|
136
|
+
return platform === "win32" ? 240_000 : 120_000;
|
|
121
137
|
}
|
|
122
138
|
|
|
123
139
|
function isPosixAbsolutePath(value: string): boolean {
|
|
124
|
-
|
|
140
|
+
return value.startsWith("/") && !WINDOWS_ABS_PATH_RE.test(value);
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
function resolvePortablePath(value: string): string {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
if (isPosixAbsolutePath(value) || WINDOWS_ABS_PATH_RE.test(value)) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
return path.resolve(value);
|
|
132
148
|
}
|
|
133
149
|
|
|
134
150
|
function dirnamePortable(value: string): string {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
151
|
+
return isPosixAbsolutePath(value)
|
|
152
|
+
? path.posix.dirname(value)
|
|
153
|
+
: path.dirname(value);
|
|
138
154
|
}
|
|
139
155
|
|
|
140
156
|
function joinPortable(base: string, ...parts: string[]): string {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
157
|
+
return isPosixAbsolutePath(base)
|
|
158
|
+
? path.posix.join(base, ...parts)
|
|
159
|
+
: path.join(base, ...parts);
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
function resolveRelativePortable(base: string, relativePath: string): string {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
163
|
+
return isPosixAbsolutePath(base)
|
|
164
|
+
? path.posix.resolve(base, relativePath)
|
|
165
|
+
: path.resolve(base, relativePath);
|
|
150
166
|
}
|
|
151
167
|
|
|
152
168
|
function getDefaultModuleDir(): string {
|
|
153
|
-
|
|
169
|
+
return import.meta.dir;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
function normalizeEnvPath(value: string | undefined): string | null {
|
|
157
|
-
|
|
158
|
-
|
|
173
|
+
const trimmed = value?.trim();
|
|
174
|
+
return trimmed ? resolvePortablePath(trimmed) : null;
|
|
159
175
|
}
|
|
160
176
|
|
|
161
177
|
function isStoreBuildVariant(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
178
|
+
const raw = env.ELIZA_BUILD_VARIANT?.trim();
|
|
179
|
+
return raw?.toLowerCase() === "store";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function resolveBrandAwareNamespace(
|
|
183
|
+
envNamespace: string | undefined,
|
|
184
|
+
brandNamespace = getBrandConfig().namespace || "eliza",
|
|
185
|
+
): string {
|
|
186
|
+
const trimmed = envNamespace?.trim();
|
|
187
|
+
if (!trimmed) return brandNamespace;
|
|
188
|
+
if (trimmed === "eliza" && brandNamespace !== "eliza") return brandNamespace;
|
|
189
|
+
return trimmed;
|
|
165
190
|
}
|
|
166
191
|
|
|
167
192
|
function resolveStateNamespace(env: NodeJS.ProcessEnv = process.env): string {
|
|
168
|
-
|
|
193
|
+
return resolveBrandAwareNamespace(env.ELIZA_NAMESPACE);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function resolveDesktopChildNamespace(
|
|
197
|
+
env: Record<string, string | undefined>,
|
|
198
|
+
brandNamespace?: string,
|
|
199
|
+
): string {
|
|
200
|
+
return resolveBrandAwareNamespace(env.ELIZA_NAMESPACE, brandNamespace);
|
|
169
201
|
}
|
|
170
202
|
|
|
171
203
|
function resolveExplicitStateDir(env: NodeJS.ProcessEnv): string | null {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
204
|
+
return normalizeEnvPath(env.ELIZA_STATE_DIR);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isTruthyDesktopEnv(value: string | undefined): boolean {
|
|
208
|
+
const normalized = value?.trim().toLowerCase();
|
|
209
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function applyPackagedStartupEmbeddingWarmupPolicy(
|
|
213
|
+
childEnv: Record<string, string>,
|
|
214
|
+
packagedRuntime: boolean,
|
|
215
|
+
): void {
|
|
216
|
+
if (!packagedRuntime) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const explicitSkip = childEnv.ELIZA_SKIP_LOCAL_EMBEDDING_WARMUP?.trim();
|
|
221
|
+
if (explicitSkip) {
|
|
222
|
+
childEnv.ELIZA_SKIP_LOCAL_EMBEDDING_WARMUP = explicitSkip;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (
|
|
227
|
+
isTruthyDesktopEnv(childEnv.ELIZA_ENABLE_STARTUP_LOCAL_EMBEDDING_WARMUP)
|
|
228
|
+
) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
childEnv.ELIZA_SKIP_LOCAL_EMBEDDING_WARMUP = "1";
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Default the desktop-spawned agent to deferring the post-ready boot tail so
|
|
237
|
+
* `/api/health` flips `ready:true` (and the renderer reaches first paint /
|
|
238
|
+
* usable chat) before app-route plugins, training hooks, sensitive-request
|
|
239
|
+
* adapters, the trigger bridge, the connector catalog, and voice warmup finish.
|
|
240
|
+
*
|
|
241
|
+
* The trade-off is a brief window after "ready" where feature routes registered
|
|
242
|
+
* by app-route plugins (e.g. lifeops/steward/training) can 404 until the
|
|
243
|
+
* background tail completes — acceptable on desktop where first paint latency is
|
|
244
|
+
* far more visible than a sub-second feature-route gap.
|
|
245
|
+
*
|
|
246
|
+
* Only sets the default when `ELIZA_DEFER_APP_ROUTES` is unset, so an explicit
|
|
247
|
+
* `0`/`1` from the user or a test harness always wins. The production CLI
|
|
248
|
+
* `serve` path (not spawned here) is untouched and keeps the awaited-inline tail.
|
|
249
|
+
*/
|
|
250
|
+
export function applyDesktopDeferAppRoutesPolicy(
|
|
251
|
+
childEnv: Record<string, string>,
|
|
252
|
+
): void {
|
|
253
|
+
if (childEnv.ELIZA_DEFER_APP_ROUTES?.trim()) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
childEnv.ELIZA_DEFER_APP_ROUTES = "1";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function prependDesktopChildPathDirectory(
|
|
260
|
+
childEnv: Record<string, string | undefined>,
|
|
261
|
+
directory: string,
|
|
262
|
+
): boolean {
|
|
263
|
+
const existingPathKey =
|
|
264
|
+
childEnv.PATH !== undefined
|
|
265
|
+
? "PATH"
|
|
266
|
+
: childEnv.Path !== undefined
|
|
267
|
+
? "Path"
|
|
268
|
+
: "PATH";
|
|
269
|
+
const existingPath = childEnv[existingPathKey]?.trim();
|
|
270
|
+
if (!existingPath) {
|
|
271
|
+
childEnv[existingPathKey] = directory;
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
if (existingPath.split(path.delimiter).includes(directory)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
childEnv[existingPathKey] = `${directory}${path.delimiter}${existingPath}`;
|
|
278
|
+
return true;
|
|
176
279
|
}
|
|
177
280
|
|
|
178
281
|
function resolveStoreUserDataStateDir(): string {
|
|
179
|
-
|
|
180
|
-
|
|
282
|
+
const userData = Utils.paths.userData || resolveConfigDir();
|
|
283
|
+
return path.join(userData, "state");
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function resolveXdgStateHome(opts?: {
|
|
287
|
+
env?: NodeJS.ProcessEnv;
|
|
288
|
+
homedir?: string;
|
|
289
|
+
}): string {
|
|
290
|
+
const env = opts?.env ?? process.env;
|
|
291
|
+
const explicit = normalizeEnvPath(env.XDG_STATE_HOME);
|
|
292
|
+
if (explicit) return explicit;
|
|
293
|
+
return joinPortable(opts?.homedir ?? os.homedir(), ".local", "state");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function resolveDefaultDesktopStateDir(opts?: {
|
|
297
|
+
env?: NodeJS.ProcessEnv;
|
|
298
|
+
homedir?: string;
|
|
299
|
+
}): string {
|
|
300
|
+
const env = opts?.env ?? process.env;
|
|
301
|
+
return joinPortable(resolveXdgStateHome(opts), resolveStateNamespace(env));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function resolveLegacyDotStateDir(opts?: {
|
|
305
|
+
env?: NodeJS.ProcessEnv;
|
|
306
|
+
homedir?: string;
|
|
307
|
+
}): string {
|
|
308
|
+
return joinPortable(
|
|
309
|
+
opts?.homedir ?? os.homedir(),
|
|
310
|
+
`.${resolveStateNamespace(opts?.env ?? process.env)}`,
|
|
311
|
+
);
|
|
181
312
|
}
|
|
182
313
|
|
|
183
314
|
export function resolveDesktopChildStateDir(opts?: {
|
|
184
|
-
|
|
185
|
-
|
|
315
|
+
env?: NodeJS.ProcessEnv;
|
|
316
|
+
homedir?: string;
|
|
186
317
|
}): string {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
opts?.homedir ?? os.homedir(),
|
|
193
|
-
`.${resolveStateNamespace(env)}`,
|
|
194
|
-
);
|
|
318
|
+
const env = opts?.env ?? process.env;
|
|
319
|
+
const explicit = resolveExplicitStateDir(env);
|
|
320
|
+
if (explicit) return explicit;
|
|
321
|
+
if (isStoreBuildVariant(env)) return resolveStoreUserDataStateDir();
|
|
322
|
+
return resolveDefaultDesktopStateDir(opts);
|
|
195
323
|
}
|
|
196
324
|
|
|
197
325
|
function applyDesktopChildStateEnv(childEnv: Record<string, string>): void {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
326
|
+
const stateDir = resolveDesktopChildStateDir({
|
|
327
|
+
env: childEnv as NodeJS.ProcessEnv,
|
|
328
|
+
});
|
|
329
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
330
|
+
childEnv.ELIZA_STATE_DIR = stateDir;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function applyWindowsNativeInferenceDefaults(
|
|
334
|
+
childEnv: Record<string, string>,
|
|
335
|
+
platform: NodeJS.Platform = process.platform,
|
|
336
|
+
): void {
|
|
337
|
+
if (platform !== "win32") return;
|
|
338
|
+
|
|
339
|
+
// node-llama-cpp crashes Bun on Windows during packaged startup.
|
|
340
|
+
// Disable local embeddings until upstream fix lands.
|
|
341
|
+
childEnv.ELIZA_DISABLE_LOCAL_EMBEDDINGS = "1";
|
|
342
|
+
|
|
343
|
+
// The fused elizaOS llama.cpp / OmniVoice runtime can trip GGML's
|
|
344
|
+
// uncaught-exception backtrace guard inside packaged Bun unless this is set
|
|
345
|
+
// before any native GGML library is loaded.
|
|
346
|
+
if (!childEnv.GGML_NO_BACKTRACE?.trim()) {
|
|
347
|
+
childEnv.GGML_NO_BACKTRACE = "1";
|
|
348
|
+
}
|
|
205
349
|
}
|
|
206
350
|
|
|
207
351
|
function listStateEntries(stateDir: string): string[] {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
352
|
+
try {
|
|
353
|
+
return fs
|
|
354
|
+
.readdirSync(stateDir)
|
|
355
|
+
.filter(
|
|
356
|
+
(entry) => entry !== "." && entry !== ".." && entry !== ".DS_Store",
|
|
357
|
+
);
|
|
358
|
+
} catch {
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
217
361
|
}
|
|
218
362
|
|
|
219
363
|
function buildExistingElizaInstallCandidates(opts?: {
|
|
220
|
-
|
|
221
|
-
|
|
364
|
+
env?: NodeJS.ProcessEnv;
|
|
365
|
+
homedir?: string;
|
|
222
366
|
}): Array<{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
367
|
+
source: ExistingElizaInstallSource;
|
|
368
|
+
stateDir: string;
|
|
369
|
+
configPath: string;
|
|
226
370
|
}> {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
371
|
+
const env = opts?.env ?? process.env;
|
|
372
|
+
const homedir = opts?.homedir ?? os.homedir();
|
|
373
|
+
const configPathFromEnv = normalizeEnvPath(env.ELIZA_CONFIG_PATH);
|
|
374
|
+
const stateDirFromEnv = resolveExplicitStateDir(env);
|
|
375
|
+
const defaultStateDir = resolveDefaultDesktopStateDir({ env, homedir });
|
|
376
|
+
const legacyStateDir = resolveLegacyDotStateDir({ env, homedir });
|
|
377
|
+
|
|
378
|
+
const candidates = [
|
|
379
|
+
configPathFromEnv
|
|
380
|
+
? {
|
|
381
|
+
source: "config-path-env" as const,
|
|
382
|
+
stateDir: dirnamePortable(configPathFromEnv),
|
|
383
|
+
configPath: configPathFromEnv,
|
|
384
|
+
}
|
|
385
|
+
: null,
|
|
386
|
+
stateDirFromEnv
|
|
387
|
+
? {
|
|
388
|
+
source: "state-dir-env" as const,
|
|
389
|
+
stateDir: stateDirFromEnv,
|
|
390
|
+
configPath: joinPortable(stateDirFromEnv, ELIZA_CONFIG_FILENAME),
|
|
391
|
+
}
|
|
392
|
+
: null,
|
|
393
|
+
{
|
|
394
|
+
source: "default-state-dir" as const,
|
|
395
|
+
stateDir: defaultStateDir,
|
|
396
|
+
configPath: joinPortable(defaultStateDir, ELIZA_CONFIG_FILENAME),
|
|
397
|
+
},
|
|
398
|
+
legacyStateDir !== defaultStateDir
|
|
399
|
+
? {
|
|
400
|
+
source: "legacy-dot-state-dir" as const,
|
|
401
|
+
stateDir: legacyStateDir,
|
|
402
|
+
configPath: joinPortable(legacyStateDir, ELIZA_CONFIG_FILENAME),
|
|
403
|
+
}
|
|
404
|
+
: null,
|
|
405
|
+
].filter((candidate): candidate is NonNullable<typeof candidate> =>
|
|
406
|
+
Boolean(candidate),
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
return candidates.filter(
|
|
410
|
+
(candidate, index, all) =>
|
|
411
|
+
all.findIndex(
|
|
412
|
+
(other) =>
|
|
413
|
+
other.stateDir === candidate.stateDir &&
|
|
414
|
+
other.configPath === candidate.configPath,
|
|
415
|
+
) === index,
|
|
416
|
+
);
|
|
270
417
|
}
|
|
271
418
|
|
|
272
419
|
export function inspectExistingElizaInstall(opts?: {
|
|
273
|
-
|
|
274
|
-
|
|
420
|
+
env?: NodeJS.ProcessEnv;
|
|
421
|
+
homedir?: string;
|
|
275
422
|
}): ExistingElizaInstallInfo {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
configPath: fallback.configPath,
|
|
316
|
-
configExists: false,
|
|
317
|
-
stateDirExists: fs.existsSync(fallback.stateDir),
|
|
318
|
-
hasStateEntries: false,
|
|
319
|
-
source: fallback.source,
|
|
320
|
-
};
|
|
423
|
+
const candidates = buildExistingElizaInstallCandidates(opts);
|
|
424
|
+
|
|
425
|
+
for (const candidate of candidates) {
|
|
426
|
+
const configExists = fs.existsSync(candidate.configPath);
|
|
427
|
+
const stateDirExists = fs.existsSync(candidate.stateDir);
|
|
428
|
+
const hasStateEntries =
|
|
429
|
+
stateDirExists && listStateEntries(candidate.stateDir).length > 0;
|
|
430
|
+
|
|
431
|
+
if (configExists || hasStateEntries) {
|
|
432
|
+
return {
|
|
433
|
+
detected: true,
|
|
434
|
+
stateDir: candidate.stateDir,
|
|
435
|
+
configPath: candidate.configPath,
|
|
436
|
+
configExists,
|
|
437
|
+
stateDirExists,
|
|
438
|
+
hasStateEntries,
|
|
439
|
+
source: candidate.source,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const fallback = candidates[0] ?? {
|
|
445
|
+
source: "default-state-dir" as const,
|
|
446
|
+
stateDir: resolveDefaultDesktopStateDir(opts),
|
|
447
|
+
configPath: joinPortable(
|
|
448
|
+
resolveDefaultDesktopStateDir(opts),
|
|
449
|
+
ELIZA_CONFIG_FILENAME,
|
|
450
|
+
),
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
detected: false,
|
|
455
|
+
stateDir: fallback.stateDir,
|
|
456
|
+
configPath: fallback.configPath,
|
|
457
|
+
configExists: false,
|
|
458
|
+
stateDirExists: fs.existsSync(fallback.stateDir),
|
|
459
|
+
hasStateEntries: false,
|
|
460
|
+
source: fallback.source,
|
|
461
|
+
};
|
|
321
462
|
}
|
|
322
463
|
|
|
323
464
|
export function migrateDesktopStateDirFromPath(
|
|
324
|
-
|
|
325
|
-
|
|
465
|
+
fromPath: string,
|
|
466
|
+
opts?: { env?: NodeJS.ProcessEnv },
|
|
326
467
|
): StateDirMigrationResult {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
468
|
+
const source = resolvePortablePath(fromPath);
|
|
469
|
+
const target = resolveDesktopChildStateDir({ env: opts?.env ?? process.env });
|
|
470
|
+
|
|
471
|
+
if (source === target) {
|
|
472
|
+
return {
|
|
473
|
+
ok: true,
|
|
474
|
+
migrated: false,
|
|
475
|
+
fromPath: source,
|
|
476
|
+
toPath: target,
|
|
477
|
+
skippedReason: "same-path",
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
const stat = fs.statSync(source);
|
|
483
|
+
if (!stat.isDirectory()) {
|
|
484
|
+
return {
|
|
485
|
+
ok: true,
|
|
486
|
+
migrated: false,
|
|
487
|
+
fromPath: source,
|
|
488
|
+
toPath: target,
|
|
489
|
+
skippedReason: "source-not-directory",
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
return {
|
|
494
|
+
ok: true,
|
|
495
|
+
migrated: false,
|
|
496
|
+
fromPath: source,
|
|
497
|
+
toPath: target,
|
|
498
|
+
skippedReason: "source-missing",
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
fs.mkdirSync(target, { recursive: true });
|
|
504
|
+
fs.cpSync(source, target, {
|
|
505
|
+
recursive: true,
|
|
506
|
+
force: false,
|
|
507
|
+
errorOnExist: false,
|
|
508
|
+
dereference: false,
|
|
509
|
+
});
|
|
510
|
+
return {
|
|
511
|
+
ok: true,
|
|
512
|
+
migrated: true,
|
|
513
|
+
fromPath: source,
|
|
514
|
+
toPath: target,
|
|
515
|
+
};
|
|
516
|
+
} catch (err) {
|
|
517
|
+
return {
|
|
518
|
+
ok: false,
|
|
519
|
+
migrated: false,
|
|
520
|
+
fromPath: source,
|
|
521
|
+
toPath: target,
|
|
522
|
+
error: err instanceof Error ? err.message : String(err),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
384
525
|
}
|
|
385
526
|
|
|
386
527
|
// ---------------------------------------------------------------------------
|
|
@@ -396,268 +537,269 @@ export function migrateDesktopStateDirFromPath(
|
|
|
396
537
|
* to mock process globals.
|
|
397
538
|
*/
|
|
398
539
|
export function resolveConfigDir(opts?: {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
540
|
+
platform?: string;
|
|
541
|
+
appdata?: string;
|
|
542
|
+
homedir?: string;
|
|
402
543
|
}): string {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
544
|
+
const platform = opts?.platform ?? process.platform;
|
|
545
|
+
const homedir = opts?.homedir ?? os.homedir();
|
|
546
|
+
const dirName = getBrandConfig().configDirName;
|
|
547
|
+
if (platform === "win32") {
|
|
548
|
+
const roaming =
|
|
549
|
+
opts?.appdata ??
|
|
550
|
+
process.env.APPDATA ??
|
|
551
|
+
joinPortable(homedir, "AppData", "Roaming");
|
|
552
|
+
return joinPortable(roaming, dirName);
|
|
553
|
+
}
|
|
554
|
+
return joinPortable(homedir, ".config", dirName);
|
|
414
555
|
}
|
|
415
556
|
|
|
416
557
|
export function ensureDesktopApiToken(
|
|
417
|
-
|
|
558
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
418
559
|
): string {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
560
|
+
const existingToken = resolveApiToken(env);
|
|
561
|
+
if (existingToken) {
|
|
562
|
+
setApiToken(env, existingToken);
|
|
563
|
+
return existingToken;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (resolveDisableAutoApiToken(env)) {
|
|
567
|
+
return "";
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const generated = crypto.randomBytes(16).toString("hex");
|
|
571
|
+
setApiToken(env, generated);
|
|
572
|
+
return generated;
|
|
432
573
|
}
|
|
433
574
|
|
|
434
575
|
export function configureDesktopLocalApiAuth(
|
|
435
|
-
|
|
576
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
436
577
|
): string {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
578
|
+
const token = ensureDesktopApiToken(env);
|
|
579
|
+
env.ELIZA_PAIRING_DISABLED = "1";
|
|
580
|
+
return token;
|
|
440
581
|
}
|
|
441
582
|
|
|
442
583
|
function getDesktopApiToken(
|
|
443
|
-
|
|
584
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
444
585
|
): string | null {
|
|
445
|
-
|
|
586
|
+
return resolveApiToken(env);
|
|
446
587
|
}
|
|
447
588
|
|
|
448
589
|
function getDesktopApiHeaders(
|
|
449
|
-
|
|
590
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
450
591
|
): Record<string, string> | undefined {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
592
|
+
const token = getDesktopApiToken(env);
|
|
593
|
+
if (!token) return undefined;
|
|
594
|
+
return {
|
|
595
|
+
Authorization: `Bearer ${token}`,
|
|
596
|
+
"X-Api-Key": token,
|
|
597
|
+
"X-Api-Token": token,
|
|
598
|
+
};
|
|
458
599
|
}
|
|
459
600
|
|
|
460
601
|
let diagnosticLogPath: string | null = null;
|
|
461
602
|
let startupStatusPath: string | null = null;
|
|
462
603
|
|
|
463
604
|
export function getDiagnosticLogPath(): string {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
605
|
+
if (diagnosticLogPath !== null) return diagnosticLogPath;
|
|
606
|
+
try {
|
|
607
|
+
const configDir = resolveConfigDir();
|
|
608
|
+
if (!fs.existsSync(configDir)) {
|
|
609
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
610
|
+
}
|
|
611
|
+
diagnosticLogPath = path.join(
|
|
612
|
+
configDir,
|
|
613
|
+
getBrandConfig().startupLogFileName,
|
|
614
|
+
);
|
|
615
|
+
} catch {
|
|
616
|
+
// Fallback to temp dir
|
|
617
|
+
diagnosticLogPath = path.join(
|
|
618
|
+
os.tmpdir(),
|
|
619
|
+
getBrandConfig().startupLogFileName,
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
return diagnosticLogPath;
|
|
482
623
|
}
|
|
483
624
|
|
|
484
625
|
export function getStartupStatusPath(): string {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
626
|
+
if (startupStatusPath !== null) return startupStatusPath;
|
|
627
|
+
try {
|
|
628
|
+
const configDir = resolveConfigDir();
|
|
629
|
+
if (!fs.existsSync(configDir)) {
|
|
630
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
631
|
+
}
|
|
632
|
+
startupStatusPath = path.join(configDir, "startup-status.json");
|
|
633
|
+
} catch {
|
|
634
|
+
startupStatusPath = path.join(os.tmpdir(), "startup-status.json");
|
|
635
|
+
}
|
|
636
|
+
return startupStatusPath;
|
|
496
637
|
}
|
|
497
638
|
|
|
498
639
|
export function diagnosticLog(message: string): void {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
640
|
+
const timestamp = new Date().toISOString();
|
|
641
|
+
const line = `[${timestamp}] ${message}\n`;
|
|
642
|
+
console.log(message);
|
|
643
|
+
try {
|
|
644
|
+
const logPath = getDiagnosticLogPath();
|
|
645
|
+
fs.appendFileSync(logPath, line);
|
|
646
|
+
} catch {
|
|
647
|
+
// Ignore write errors
|
|
648
|
+
}
|
|
508
649
|
}
|
|
509
650
|
|
|
510
651
|
/** One-line, truncated error string safe for UI (status.error). */
|
|
511
652
|
function shortError(err: unknown, maxLen = 280): string {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
653
|
+
const raw =
|
|
654
|
+
err instanceof Error
|
|
655
|
+
? err.message || (err.stack ?? String(err))
|
|
656
|
+
: String(err);
|
|
657
|
+
const oneLine = raw.replace(/\s+/g, " ").trim();
|
|
658
|
+
if (oneLine.length <= maxLen) return oneLine;
|
|
659
|
+
return `${oneLine.slice(0, maxLen)}... (see logs for full details)`;
|
|
519
660
|
}
|
|
520
661
|
|
|
521
662
|
export function redactSensitiveDiagnostics(input: string): string {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
663
|
+
return input
|
|
664
|
+
.replace(
|
|
665
|
+
/(authorization\s*[:=]\s*bearer\s+)([a-z0-9._-]+)/gi,
|
|
666
|
+
"$1[REDACTED]",
|
|
667
|
+
)
|
|
668
|
+
.replace(
|
|
669
|
+
/((?:x-api-key|x-api-token|api[_-]?key|bearer[_-]?token|access[_-]?token|secret|password)\s*[:=]\s*)([^\s]+)/gi,
|
|
670
|
+
"$1[REDACTED]",
|
|
671
|
+
);
|
|
531
672
|
}
|
|
532
673
|
|
|
533
674
|
function readFileTail(filePath: string, maxChars = 16_000): string {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
675
|
+
try {
|
|
676
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
677
|
+
return redactSensitiveDiagnostics(content.slice(-maxChars));
|
|
678
|
+
} catch {
|
|
679
|
+
return "";
|
|
680
|
+
}
|
|
540
681
|
}
|
|
541
682
|
|
|
542
683
|
function writeStartupDiagnosticsSnapshot(
|
|
543
|
-
|
|
684
|
+
snapshot: StartupDiagnosticsSnapshot,
|
|
544
685
|
): void {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
686
|
+
try {
|
|
687
|
+
fs.writeFileSync(
|
|
688
|
+
getStartupStatusPath(),
|
|
689
|
+
`${JSON.stringify(snapshot, null, 2)}\n`,
|
|
690
|
+
"utf8",
|
|
691
|
+
);
|
|
692
|
+
} catch {
|
|
693
|
+
// Ignore write errors
|
|
694
|
+
}
|
|
554
695
|
}
|
|
555
696
|
|
|
556
697
|
export function getStartupDiagnosticsSnapshot(): StartupDiagnosticsSnapshot {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
698
|
+
let parsed: Partial<StartupDiagnosticsSnapshot> | null = null;
|
|
699
|
+
try {
|
|
700
|
+
parsed = JSON.parse(
|
|
701
|
+
fs.readFileSync(getStartupStatusPath(), "utf8"),
|
|
702
|
+
) as Partial<StartupDiagnosticsSnapshot> | null;
|
|
703
|
+
} catch {
|
|
704
|
+
parsed = null;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return {
|
|
708
|
+
state: parsed?.state ?? "not_started",
|
|
709
|
+
phase: parsed?.phase ?? "unknown",
|
|
710
|
+
updatedAt: parsed?.updatedAt ?? new Date().toISOString(),
|
|
711
|
+
lastError: parsed?.lastError ?? null,
|
|
712
|
+
agentName: parsed?.agentName ?? null,
|
|
713
|
+
port: parsed?.port ?? null,
|
|
714
|
+
startedAt: parsed?.startedAt ?? null,
|
|
715
|
+
platform: parsed?.platform ?? process.platform,
|
|
716
|
+
arch: parsed?.arch ?? process.arch,
|
|
717
|
+
configDir: parsed?.configDir ?? resolveConfigDir(),
|
|
718
|
+
logPath: parsed?.logPath ?? getDiagnosticLogPath(),
|
|
719
|
+
statusPath: parsed?.statusPath ?? getStartupStatusPath(),
|
|
720
|
+
database: parsed?.database ?? createUnknownDatabaseSnapshot(),
|
|
721
|
+
};
|
|
580
722
|
}
|
|
581
723
|
|
|
582
724
|
export function getStartupDiagnosticLogTail(maxChars = 16_000): string {
|
|
583
|
-
|
|
725
|
+
return readFileTail(getDiagnosticLogPath(), maxChars);
|
|
584
726
|
}
|
|
585
727
|
|
|
586
728
|
function sanitizeBugReportPrefix(prefix: string | undefined): string {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
729
|
+
const trimmed = prefix?.trim();
|
|
730
|
+
if (!trimmed) return "bug-report";
|
|
731
|
+
|
|
732
|
+
const sanitized = trimmed
|
|
733
|
+
.replace(/[\\/]+/g, "-")
|
|
734
|
+
.replace(/\.\.+/g, "-")
|
|
735
|
+
.replace(/[^a-zA-Z0-9._-]+/g, "-")
|
|
736
|
+
.replace(/-+/g, "-")
|
|
737
|
+
.replace(/^[._-]+|[._-]+$/g, "")
|
|
738
|
+
.slice(0, 64);
|
|
739
|
+
|
|
740
|
+
return sanitized || "bug-report";
|
|
599
741
|
}
|
|
600
742
|
export function createBugReportBundle(options: {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
743
|
+
reportMarkdown: string;
|
|
744
|
+
reportJson: Record<string, unknown>;
|
|
745
|
+
prefix?: string;
|
|
604
746
|
}): BugReportBundleResult {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
747
|
+
const configDir = resolveConfigDir();
|
|
748
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
749
|
+
const prefix = sanitizeBugReportPrefix(options.prefix);
|
|
750
|
+
const directory = path.join(
|
|
751
|
+
configDir,
|
|
752
|
+
"bug-reports",
|
|
753
|
+
`${prefix}-${timestamp}`,
|
|
754
|
+
);
|
|
755
|
+
const reportMarkdownPath = path.join(directory, "report.md");
|
|
756
|
+
const reportJsonPath = path.join(directory, "report.json");
|
|
757
|
+
const logPath = getDiagnosticLogPath();
|
|
758
|
+
const statusPath = getStartupStatusPath();
|
|
759
|
+
const startupLogTarget = path.join(
|
|
760
|
+
directory,
|
|
761
|
+
getBrandConfig().startupLogFileName,
|
|
762
|
+
);
|
|
763
|
+
const startupStatusTarget = path.join(directory, "startup-status.json");
|
|
764
|
+
const startupDiagnostics = getStartupDiagnosticsSnapshot();
|
|
765
|
+
const includeLogTail =
|
|
766
|
+
typeof options.reportJson.attachLogs === "boolean"
|
|
767
|
+
? options.reportJson.attachLogs
|
|
768
|
+
: true;
|
|
769
|
+
const startupLogTail = includeLogTail ? getStartupDiagnosticLogTail() : "";
|
|
770
|
+
const normalizedReportJson = {
|
|
771
|
+
...options.reportJson,
|
|
772
|
+
startupDiagnostics,
|
|
773
|
+
startupLogTail,
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
777
|
+
fs.writeFileSync(reportMarkdownPath, options.reportMarkdown, "utf8");
|
|
778
|
+
fs.writeFileSync(
|
|
779
|
+
reportJsonPath,
|
|
780
|
+
`${JSON.stringify(normalizedReportJson, null, 2)}\n`,
|
|
781
|
+
"utf8",
|
|
782
|
+
);
|
|
783
|
+
|
|
784
|
+
let copiedLogPath: string | null = null;
|
|
785
|
+
let copiedStatusPath: string | null = null;
|
|
786
|
+
|
|
787
|
+
if (fs.existsSync(logPath)) {
|
|
788
|
+
fs.copyFileSync(logPath, startupLogTarget);
|
|
789
|
+
copiedLogPath = startupLogTarget;
|
|
790
|
+
}
|
|
791
|
+
if (fs.existsSync(statusPath)) {
|
|
792
|
+
fs.copyFileSync(statusPath, startupStatusTarget);
|
|
793
|
+
copiedStatusPath = startupStatusTarget;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
return {
|
|
797
|
+
directory,
|
|
798
|
+
reportMarkdownPath,
|
|
799
|
+
reportJsonPath,
|
|
800
|
+
startupLogPath: copiedLogPath,
|
|
801
|
+
startupStatusPath: copiedStatusPath,
|
|
802
|
+
};
|
|
661
803
|
}
|
|
662
804
|
|
|
663
805
|
// ---------------------------------------------------------------------------
|
|
@@ -672,255 +814,260 @@ export function createBugReportBundle(options: {
|
|
|
672
814
|
* 2. Walk up from import.meta.dir to find the runtime dist dir as a sibling
|
|
673
815
|
*/
|
|
674
816
|
export function getRuntimeDistFallbackCandidates(
|
|
675
|
-
|
|
676
|
-
|
|
817
|
+
moduleDir: string = getDefaultModuleDir(),
|
|
818
|
+
execPath: string = process.execPath,
|
|
677
819
|
): string[] {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
820
|
+
const execDir = execPath ? dirnamePortable(execPath) : moduleDir;
|
|
821
|
+
const distDir = getBrandConfig().runtimeDistDirName;
|
|
822
|
+
|
|
823
|
+
return [
|
|
824
|
+
// macOS: inside .app bundle (Contents/Resources/app/<dist>)
|
|
825
|
+
resolveRelativePortable(execDir, `../Resources/app/${distDir}`),
|
|
826
|
+
// Windows NSIS/portable: resources/app/<dist> next to exe
|
|
827
|
+
resolveRelativePortable(execDir, `resources/app/${distDir}`),
|
|
828
|
+
resolveRelativePortable(execDir, `../resources/app/${distDir}`),
|
|
829
|
+
resolveRelativePortable(moduleDir, `app/${distDir}`),
|
|
830
|
+
resolveRelativePortable(moduleDir, `../${distDir}`),
|
|
831
|
+
resolveRelativePortable(moduleDir, `../app/${distDir}`),
|
|
832
|
+
resolveRelativePortable(moduleDir, `../../../${distDir}`),
|
|
833
|
+
// Legacy eliza-dist fallback for existing packaged builds
|
|
834
|
+
resolveRelativePortable(execDir, "../Resources/app/eliza-dist"),
|
|
835
|
+
resolveRelativePortable(execDir, "resources/app/eliza-dist"),
|
|
836
|
+
resolveRelativePortable(moduleDir, "../eliza-dist"),
|
|
837
|
+
resolveRelativePortable(moduleDir, "../../../eliza-dist"),
|
|
838
|
+
].filter((candidate, index, all) => all.indexOf(candidate) === index);
|
|
697
839
|
}
|
|
698
840
|
|
|
699
841
|
export function isPackagedDesktopRuntime(
|
|
700
|
-
|
|
701
|
-
|
|
842
|
+
moduleDir: string = getDefaultModuleDir(),
|
|
843
|
+
execPath: string = process.execPath,
|
|
702
844
|
): boolean {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
845
|
+
const normalizedModuleDir = moduleDir.replaceAll("\\", "/");
|
|
846
|
+
const normalizedExecPath = execPath.replaceAll("\\", "/").toLowerCase();
|
|
847
|
+
const looksLikePackagedExec =
|
|
848
|
+
normalizedExecPath.includes(".app/contents/") ||
|
|
849
|
+
normalizedExecPath.includes("/self-extraction/") ||
|
|
850
|
+
normalizedExecPath.endsWith("/launcher") ||
|
|
851
|
+
normalizedExecPath.endsWith("/launcher.exe");
|
|
852
|
+
if (process.env.ELIZA_DIST_PATH?.trim() && !looksLikePackagedExec) {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
if (!normalizedModuleDir.includes("/src/")) {
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
return looksLikePackagedExec;
|
|
718
860
|
}
|
|
719
861
|
|
|
720
862
|
export function resolveBunExecutablePath(opts?: {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
863
|
+
execPath?: string;
|
|
864
|
+
moduleDir?: string;
|
|
865
|
+
platform?: string;
|
|
724
866
|
}): string {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
867
|
+
const execPath = opts?.execPath ?? process.execPath;
|
|
868
|
+
const moduleDir = opts?.moduleDir ?? getDefaultModuleDir();
|
|
869
|
+
const platform = opts?.platform ?? process.platform;
|
|
870
|
+
const packagedRuntime = isPackagedDesktopRuntime(moduleDir, execPath);
|
|
871
|
+
const looksLikeMacBundleExec = execPath.includes(".app/Contents/MacOS/");
|
|
872
|
+
const executableName =
|
|
873
|
+
platform === "win32" && !looksLikeMacBundleExec ? "bun.exe" : "bun";
|
|
874
|
+
const execDir = execPath ? dirnamePortable(execPath) : "";
|
|
875
|
+
const packagedCandidates = [
|
|
876
|
+
execPath,
|
|
877
|
+
execDir ? joinPortable(execDir, executableName) : "",
|
|
878
|
+
execDir
|
|
879
|
+
? resolveRelativePortable(
|
|
880
|
+
execDir,
|
|
881
|
+
`../Resources/app/bun/${executableName}`,
|
|
882
|
+
)
|
|
883
|
+
: "",
|
|
884
|
+
execDir
|
|
885
|
+
? resolveRelativePortable(
|
|
886
|
+
execDir,
|
|
887
|
+
`../Resources/app/bun/bin/${executableName}`,
|
|
888
|
+
)
|
|
889
|
+
: "",
|
|
890
|
+
moduleDir ? joinPortable(moduleDir, executableName) : "",
|
|
891
|
+
moduleDir ? joinPortable(moduleDir, "bin", executableName) : "",
|
|
892
|
+
moduleDir
|
|
893
|
+
? resolveRelativePortable(moduleDir, `../bun/${executableName}`)
|
|
894
|
+
: "",
|
|
895
|
+
moduleDir
|
|
896
|
+
? resolveRelativePortable(moduleDir, `../bun/bin/${executableName}`)
|
|
897
|
+
: "",
|
|
898
|
+
].filter(Boolean);
|
|
899
|
+
|
|
900
|
+
for (const candidate of packagedCandidates) {
|
|
901
|
+
if (!fs.existsSync(candidate)) continue;
|
|
902
|
+
if (
|
|
903
|
+
path.basename(candidate).toLowerCase() === executableName.toLowerCase()
|
|
904
|
+
) {
|
|
905
|
+
return candidate;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
if (packagedRuntime) {
|
|
910
|
+
return (
|
|
911
|
+
packagedCandidates.find(
|
|
912
|
+
(candidate) =>
|
|
913
|
+
path.basename(candidate).toLowerCase() ===
|
|
914
|
+
executableName.toLowerCase(),
|
|
915
|
+
) ?? executableName
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const _candidates = [
|
|
920
|
+
execPath,
|
|
921
|
+
execDir ? joinPortable(execDir, executableName) : "",
|
|
922
|
+
].filter(Boolean);
|
|
923
|
+
|
|
924
|
+
const bunGlobal = Bun as { which?: (binary: string) => string | null };
|
|
925
|
+
const whichCandidate =
|
|
926
|
+
typeof bunGlobal.which === "function" ? bunGlobal.which("bun") : null;
|
|
927
|
+
if (whichCandidate) return whichCandidate;
|
|
928
|
+
|
|
929
|
+
// Windows: bun is not always on PATH; check well-known install locations.
|
|
930
|
+
if (process.platform === "win32") {
|
|
931
|
+
const localAppData =
|
|
932
|
+
process.env.LOCALAPPDATA ??
|
|
933
|
+
joinPortable(os.homedir(), "AppData", "Local");
|
|
934
|
+
const programFiles = process.env.ProgramFiles ?? "C:\\Program Files";
|
|
935
|
+
const winCandidates = [
|
|
936
|
+
joinPortable(localAppData, "bun", "bun.exe"),
|
|
937
|
+
joinPortable(programFiles, "bun", "bun.exe"),
|
|
938
|
+
joinPortable(os.homedir(), ".bun", "bin", "bun.exe"),
|
|
939
|
+
];
|
|
940
|
+
for (const candidate of winCandidates) {
|
|
941
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
return "bun";
|
|
804
946
|
}
|
|
805
947
|
|
|
806
948
|
export function resolveRuntimeDistPath(opts?: {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
949
|
+
env?: NodeJS.ProcessEnv;
|
|
950
|
+
moduleDir?: string;
|
|
951
|
+
execPath?: string;
|
|
810
952
|
}): string {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
953
|
+
const env = opts?.env ?? process.env;
|
|
954
|
+
const moduleDir = opts?.moduleDir ?? getDefaultModuleDir();
|
|
955
|
+
const execPath = opts?.execPath ?? process.execPath;
|
|
956
|
+
const packagedRuntime = isPackagedDesktopRuntime(moduleDir, execPath);
|
|
957
|
+
const distDir = getBrandConfig().runtimeDistDirName;
|
|
958
|
+
const fallbackCandidates = getRuntimeDistFallbackCandidates(
|
|
959
|
+
moduleDir,
|
|
960
|
+
execPath,
|
|
961
|
+
);
|
|
962
|
+
|
|
963
|
+
if (packagedRuntime) {
|
|
964
|
+
for (const candidate of fallbackCandidates) {
|
|
965
|
+
if (fs.existsSync(candidate)) {
|
|
966
|
+
return candidate;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
const fallback = fallbackCandidates[0];
|
|
970
|
+
diagnosticLog(
|
|
971
|
+
`[Agent] Could not find packaged runtime dist; using fallback: ${fallback}`,
|
|
972
|
+
);
|
|
973
|
+
return fallback;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// 1. Env override
|
|
977
|
+
const envPath = env.ELIZA_DIST_PATH;
|
|
978
|
+
if (envPath) {
|
|
979
|
+
const resolved = resolvePortablePath(envPath);
|
|
980
|
+
if (fs.existsSync(resolved)) {
|
|
981
|
+
return resolved;
|
|
982
|
+
}
|
|
983
|
+
diagnosticLog(
|
|
984
|
+
`[Agent] ELIZA_DIST_PATH set but does not exist: ${resolved}`,
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// 2. Walk up from import.meta.dir looking for runtime dist or dev dist
|
|
989
|
+
let dir = moduleDir;
|
|
990
|
+
const maxDepth = 15;
|
|
991
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
992
|
+
// Packaged: runtime dist sibling
|
|
993
|
+
const runtimeDist = joinPortable(dir, distDir);
|
|
994
|
+
if (fs.existsSync(runtimeDist)) {
|
|
995
|
+
return runtimeDist;
|
|
996
|
+
}
|
|
997
|
+
// Legacy eliza-dist sibling (existing packaged builds)
|
|
998
|
+
const legacyDist = joinPortable(dir, "eliza-dist");
|
|
999
|
+
if (fs.existsSync(legacyDist)) {
|
|
1000
|
+
return legacyDist;
|
|
1001
|
+
}
|
|
1002
|
+
// Dev monorepo: dist/ sibling containing the canonical CLI entrypoint
|
|
1003
|
+
const devDist = joinPortable(dir, "dist");
|
|
1004
|
+
if (fs.existsSync(joinPortable(devDist, "entry.js"))) {
|
|
1005
|
+
return devDist;
|
|
1006
|
+
}
|
|
1007
|
+
const parent = dirnamePortable(dir);
|
|
1008
|
+
if (parent === dir) break; // reached filesystem root
|
|
1009
|
+
dir = parent;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// 3. Packaged/dev fallbacks derived from the launcher path and module dir.
|
|
1013
|
+
for (const candidate of fallbackCandidates) {
|
|
1014
|
+
if (fs.existsSync(candidate)) {
|
|
1015
|
+
diagnosticLog(
|
|
1016
|
+
`[Agent] Could not find runtime dist by walking up; using fallback: ${candidate}`,
|
|
1017
|
+
);
|
|
1018
|
+
return candidate;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const fallback = fallbackCandidates[0];
|
|
1023
|
+
diagnosticLog(
|
|
1024
|
+
`[Agent] Could not find runtime dist by walking up; using fallback: ${fallback}`,
|
|
1025
|
+
);
|
|
1026
|
+
return fallback;
|
|
885
1027
|
}
|
|
886
1028
|
|
|
887
1029
|
export function buildChildNodePaths(
|
|
888
|
-
|
|
889
|
-
|
|
1030
|
+
runtimeDistPath: string,
|
|
1031
|
+
opts?: { packagedRuntime?: boolean },
|
|
890
1032
|
): string[] {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1033
|
+
const nodePaths = new Set<string>();
|
|
1034
|
+
const distModules = joinPortable(runtimeDistPath, "node_modules");
|
|
1035
|
+
if (fs.existsSync(distModules)) {
|
|
1036
|
+
nodePaths.add(distModules);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (opts?.packagedRuntime) {
|
|
1040
|
+
return [...nodePaths];
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
let searchDir = runtimeDistPath;
|
|
1044
|
+
while (searchDir !== dirnamePortable(searchDir)) {
|
|
1045
|
+
const candidate = joinPortable(searchDir, "node_modules");
|
|
1046
|
+
if (fs.existsSync(candidate) && candidate !== distModules) {
|
|
1047
|
+
nodePaths.add(candidate);
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
searchDir = dirnamePortable(searchDir);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
return [...nodePaths];
|
|
912
1054
|
}
|
|
913
1055
|
|
|
914
|
-
function resolveRuntimeEntryPath(
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1056
|
+
export function resolveRuntimeEntryPath(
|
|
1057
|
+
runtimeDistPath: string,
|
|
1058
|
+
): string | null {
|
|
1059
|
+
const candidates = [
|
|
1060
|
+
joinPortable(runtimeDistPath, "entry.js"),
|
|
1061
|
+
joinPortable(runtimeDistPath, "runtime", "entry.js"),
|
|
1062
|
+
];
|
|
1063
|
+
|
|
1064
|
+
for (const candidate of candidates) {
|
|
1065
|
+
if (fs.existsSync(candidate)) {
|
|
1066
|
+
return candidate;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
return null;
|
|
924
1071
|
}
|
|
925
1072
|
|
|
926
1073
|
// ---------------------------------------------------------------------------
|
|
@@ -928,52 +1075,97 @@ function resolveRuntimeEntryPath(runtimeDistPath: string): string | null {
|
|
|
928
1075
|
// ---------------------------------------------------------------------------
|
|
929
1076
|
|
|
930
1077
|
async function waitForHealthy(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1078
|
+
getPort: () => number,
|
|
1079
|
+
timeoutMs: number = getHealthPollTimeoutMs(),
|
|
1080
|
+
childProcess?: BunSubprocess | null,
|
|
1081
|
+
): Promise<boolean> {
|
|
1082
|
+
const deadline = Date.now() + timeoutMs;
|
|
1083
|
+
const headers = getDesktopApiHeaders();
|
|
1084
|
+
|
|
1085
|
+
while (Date.now() < deadline) {
|
|
1086
|
+
// Bail early if the child process has already exited
|
|
1087
|
+
if (childProcess && childProcess.exitCode !== null) {
|
|
1088
|
+
return false;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
const port = getPort();
|
|
1092
|
+
const url = `http://127.0.0.1:${port}/api/health`;
|
|
1093
|
+
try {
|
|
1094
|
+
const response = await fetch(url, {
|
|
1095
|
+
headers,
|
|
1096
|
+
signal: AbortSignal.timeout(2_000),
|
|
1097
|
+
});
|
|
1098
|
+
if (response.ok) {
|
|
1099
|
+
const health = (await response.json().catch(() => null)) as {
|
|
1100
|
+
ready?: boolean;
|
|
1101
|
+
agentState?: string;
|
|
1102
|
+
startup?: { phase?: string };
|
|
1103
|
+
} | null;
|
|
1104
|
+
if (!health) {
|
|
1105
|
+
return true;
|
|
1106
|
+
}
|
|
1107
|
+
if (typeof health.ready === "boolean") {
|
|
1108
|
+
if (health.ready) {
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
} else if (
|
|
1112
|
+
health.agentState !== "starting" &&
|
|
1113
|
+
health.agentState !== "restarting"
|
|
1114
|
+
) {
|
|
1115
|
+
return true;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
if (await isStartupStatusReachable(port, headers)) {
|
|
1119
|
+
return true;
|
|
1120
|
+
}
|
|
1121
|
+
} catch {
|
|
1122
|
+
if (await isStartupStatusReachable(port, headers)) {
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
await Bun.sleep(HEALTH_POLL_INTERVAL_MS);
|
|
1127
|
+
}
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
1132
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function isNonFatalStartupStatus(value: unknown): boolean {
|
|
1136
|
+
if (!isRecord(value)) return false;
|
|
1137
|
+
const startup = value.startup;
|
|
1138
|
+
if (!isRecord(startup)) return false;
|
|
1139
|
+
const phase = startup.phase;
|
|
1140
|
+
if (
|
|
1141
|
+
phase === "fatal" ||
|
|
1142
|
+
phase === "startup_failed" ||
|
|
1143
|
+
phase === "runtime_entry_missing"
|
|
1144
|
+
) {
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
return (
|
|
1148
|
+
typeof phase === "string" ||
|
|
1149
|
+
typeof startup.embeddingPhase === "string" ||
|
|
1150
|
+
typeof startup.embeddingDetail === "string"
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
async function isStartupStatusReachable(
|
|
1155
|
+
port: number,
|
|
1156
|
+
headers: Record<string, string> | undefined,
|
|
934
1157
|
): Promise<boolean> {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
try {
|
|
947
|
-
const response = await fetch(url, {
|
|
948
|
-
headers,
|
|
949
|
-
signal: AbortSignal.timeout(2_000),
|
|
950
|
-
});
|
|
951
|
-
if (response.ok) {
|
|
952
|
-
const health = (await response.json().catch(() => null)) as {
|
|
953
|
-
ready?: boolean;
|
|
954
|
-
agentState?: string;
|
|
955
|
-
startup?: { phase?: string };
|
|
956
|
-
} | null;
|
|
957
|
-
if (!health) {
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
if (typeof health.ready === "boolean") {
|
|
961
|
-
if (health.ready) {
|
|
962
|
-
return true;
|
|
963
|
-
}
|
|
964
|
-
} else if (
|
|
965
|
-
health.agentState !== "starting" &&
|
|
966
|
-
health.agentState !== "restarting"
|
|
967
|
-
) {
|
|
968
|
-
return true;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
} catch {
|
|
972
|
-
// Server not ready yet
|
|
973
|
-
}
|
|
974
|
-
await Bun.sleep(HEALTH_POLL_INTERVAL_MS);
|
|
975
|
-
}
|
|
976
|
-
return false;
|
|
1158
|
+
try {
|
|
1159
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/status`, {
|
|
1160
|
+
headers,
|
|
1161
|
+
signal: AbortSignal.timeout(2_000),
|
|
1162
|
+
});
|
|
1163
|
+
const body = await response.json().catch(() => null);
|
|
1164
|
+
if (response.ok) return true;
|
|
1165
|
+
return isNonFatalStartupStatus(body);
|
|
1166
|
+
} catch {
|
|
1167
|
+
return false;
|
|
1168
|
+
}
|
|
977
1169
|
}
|
|
978
1170
|
|
|
979
1171
|
// ---------------------------------------------------------------------------
|
|
@@ -981,171 +1173,154 @@ async function waitForHealthy(
|
|
|
981
1173
|
// ---------------------------------------------------------------------------
|
|
982
1174
|
|
|
983
1175
|
async function watchStdoutForReady(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1176
|
+
stream: ReadableStream<Uint8Array>,
|
|
1177
|
+
onLine: (line: string) => void,
|
|
1178
|
+
signal: AbortSignal,
|
|
987
1179
|
): Promise<void> {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1180
|
+
const decoder = new TextDecoder();
|
|
1181
|
+
let buffer = "";
|
|
1182
|
+
|
|
1183
|
+
try {
|
|
1184
|
+
const reader = stream.getReader();
|
|
1185
|
+
while (!signal.aborted) {
|
|
1186
|
+
const { done, value } = await reader.read();
|
|
1187
|
+
if (done) break;
|
|
1188
|
+
|
|
1189
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1190
|
+
const lines = buffer.split("\n");
|
|
1191
|
+
buffer = lines.pop() ?? "";
|
|
1192
|
+
|
|
1193
|
+
for (const line of lines) {
|
|
1194
|
+
if (line.trim()) {
|
|
1195
|
+
onLine(line);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
// Flush remaining buffer
|
|
1200
|
+
if (buffer.trim()) {
|
|
1201
|
+
onLine(buffer);
|
|
1202
|
+
}
|
|
1203
|
+
reader.releaseLock();
|
|
1204
|
+
} catch (err) {
|
|
1205
|
+
if (!signal.aborted) {
|
|
1206
|
+
diagnosticLog(
|
|
1207
|
+
`[Agent] stdout watcher error: ${err instanceof Error ? err.message : String(err)}`,
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1019
1211
|
}
|
|
1020
1212
|
|
|
1021
1213
|
async function drainStderrToLog(
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1214
|
+
stream: ReadableStream<Uint8Array>,
|
|
1215
|
+
signal: AbortSignal,
|
|
1216
|
+
onLine?: (line: string) => void,
|
|
1025
1217
|
): Promise<void> {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1218
|
+
const decoder = new TextDecoder();
|
|
1219
|
+
let buffer = "";
|
|
1220
|
+
|
|
1221
|
+
try {
|
|
1222
|
+
const reader = stream.getReader();
|
|
1223
|
+
while (!signal.aborted) {
|
|
1224
|
+
const { done, value } = await reader.read();
|
|
1225
|
+
if (done) break;
|
|
1226
|
+
|
|
1227
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1228
|
+
const lines = buffer.split("\n");
|
|
1229
|
+
buffer = lines.pop() ?? "";
|
|
1230
|
+
|
|
1231
|
+
for (const line of lines) {
|
|
1232
|
+
if (line.trim()) {
|
|
1233
|
+
diagnosticLog(`[Agent][stderr] ${line}`);
|
|
1234
|
+
onLine?.(line);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
if (buffer.trim()) {
|
|
1239
|
+
diagnosticLog(`[Agent][stderr] ${buffer}`);
|
|
1240
|
+
onLine?.(buffer);
|
|
1241
|
+
}
|
|
1242
|
+
reader.releaseLock();
|
|
1243
|
+
} catch (err) {
|
|
1244
|
+
if (!signal.aborted) {
|
|
1245
|
+
diagnosticLog(
|
|
1246
|
+
`[Agent] stderr drain error: ${err instanceof Error ? err.message : String(err)}`,
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1058
1250
|
}
|
|
1059
1251
|
|
|
1060
1252
|
const PGLITE_LOCK_RE =
|
|
1061
|
-
|
|
1253
|
+
/pglite data dir is already in use|database is locked|lock file already exists/i;
|
|
1062
1254
|
const PGLITE_RECOVERY_RE =
|
|
1063
|
-
|
|
1255
|
+
/failed query:\s*(?:create schema if not exists|create table if not exists life_)|aborted\(\)\. build with -sassertions|database disk image is malformed|file is not a database|malformed database schema|checksum mismatch|checkpoint failed|wal file/i;
|
|
1064
1256
|
|
|
1065
1257
|
function shouldAutoRecoverPgliteFailure(line: string): boolean {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1258
|
+
if (PGLITE_LOCK_RE.test(line)) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
return (
|
|
1263
|
+
PGLITE_RECOVERY_RE.test(line) ||
|
|
1264
|
+
(/corrupt/i.test(line) && /pglite|sqlite/i.test(line))
|
|
1265
|
+
);
|
|
1074
1266
|
}
|
|
1075
1267
|
|
|
1076
1268
|
/**
|
|
1077
1269
|
* Opt-in: kill processes listening on `port` (lsof + SIGKILL). Default off so a
|
|
1078
1270
|
* second desktop instance can coexist on the same machine when ports differ.
|
|
1079
|
-
* Set ELIZA_AGENT_RECLAIM_STALE_PORT=1
|
|
1080
|
-
*
|
|
1271
|
+
* Set ELIZA_AGENT_RECLAIM_STALE_PORT=1 to restore the old "take over default
|
|
1272
|
+
* port" behavior.
|
|
1081
1273
|
*/
|
|
1082
1274
|
async function maybeReclaimPortWithSigkill(port: number): Promise<void> {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
function resolvePgliteDataDir(): string {
|
|
1116
|
-
return joinPortable(
|
|
1117
|
-
os.homedir(),
|
|
1118
|
-
`.${getBrandConfig().namespace}`,
|
|
1119
|
-
"workspace",
|
|
1120
|
-
".eliza",
|
|
1121
|
-
".elizadb",
|
|
1122
|
-
);
|
|
1275
|
+
const raw = process.env.ELIZA_AGENT_RECLAIM_STALE_PORT?.trim().toLowerCase();
|
|
1276
|
+
if (raw !== "1" && raw !== "true" && raw !== "yes") {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
try {
|
|
1280
|
+
const lsofResult = Bun.spawnSync(["lsof", "-ti", `tcp:${port}`]);
|
|
1281
|
+
const pids = new TextDecoder()
|
|
1282
|
+
.decode(lsofResult.stdout)
|
|
1283
|
+
.trim()
|
|
1284
|
+
.split("\n")
|
|
1285
|
+
.filter(Boolean);
|
|
1286
|
+
for (const pid of pids) {
|
|
1287
|
+
const numPid = parseInt(pid, 10);
|
|
1288
|
+
if (!Number.isNaN(numPid) && numPid !== process.pid) {
|
|
1289
|
+
diagnosticLog(
|
|
1290
|
+
`[Agent] Reclaim: killing process ${numPid} on port ${port} (ELIZA_AGENT_RECLAIM_STALE_PORT)`,
|
|
1291
|
+
);
|
|
1292
|
+
try {
|
|
1293
|
+
process.kill(numPid, "SIGKILL");
|
|
1294
|
+
} catch {
|
|
1295
|
+
// Process may have already exited
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (pids.length > 0) {
|
|
1300
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1301
|
+
}
|
|
1302
|
+
} catch {
|
|
1303
|
+
// lsof missing — ignore
|
|
1304
|
+
}
|
|
1123
1305
|
}
|
|
1124
1306
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
);
|
|
1143
|
-
}
|
|
1144
|
-
} catch (err) {
|
|
1145
|
-
diagnosticLog(
|
|
1146
|
-
`[Agent] Failed to delete PGLite data dir: ${err instanceof Error ? err.message : String(err)}`,
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1307
|
+
function resolveDatabaseAppStateDir(
|
|
1308
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
1309
|
+
): string {
|
|
1310
|
+
const stateDir = resolveDesktopChildStateDir({ env });
|
|
1311
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
1312
|
+
return stateDir;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function resolveManagedPgliteDataDir(): string | null {
|
|
1316
|
+
const resolution = resolveDatabaseMode({
|
|
1317
|
+
env: process.env as Record<string, string | undefined>,
|
|
1318
|
+
packagedDesktop: isPackagedDesktopRuntime(),
|
|
1319
|
+
appStateDir: resolveDatabaseAppStateDir(process.env),
|
|
1320
|
+
});
|
|
1321
|
+
return resolution.mode === "pglite-persistent"
|
|
1322
|
+
? (resolution.pgliteDataDir ?? null)
|
|
1323
|
+
: null;
|
|
1149
1324
|
}
|
|
1150
1325
|
|
|
1151
1326
|
// ---------------------------------------------------------------------------
|
|
@@ -1153,800 +1328,1065 @@ function deletePgliteDataDir(): void {
|
|
|
1153
1328
|
// ---------------------------------------------------------------------------
|
|
1154
1329
|
|
|
1155
1330
|
export class AgentManager {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1331
|
+
private sendToWebview: SendToWebview | null = null;
|
|
1332
|
+
private readonly statusListeners = new Set<
|
|
1333
|
+
(status: Readonly<AgentStatus>) => void
|
|
1334
|
+
>();
|
|
1335
|
+
private status: AgentStatus = {
|
|
1336
|
+
state: "not_started",
|
|
1337
|
+
agentName: null,
|
|
1338
|
+
port: null,
|
|
1339
|
+
startedAt: null,
|
|
1340
|
+
error: null,
|
|
1341
|
+
};
|
|
1342
|
+
private childProcess: BunSubprocess | null = null;
|
|
1343
|
+
private stdioAbortController: AbortController | null = null;
|
|
1344
|
+
private hasPgliteError = false;
|
|
1345
|
+
private pgliteRecoveryDone = false;
|
|
1346
|
+
private startupPhase = "not_started";
|
|
1347
|
+
private databaseSnapshot: DatabaseSnapshot = createUnknownDatabaseSnapshot();
|
|
1348
|
+
private databaseStartupLock: DatabaseStartupLock | null = null;
|
|
1349
|
+
|
|
1350
|
+
constructor() {
|
|
1351
|
+
this.persistStartupDiagnostics();
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
setSendToWebview(fn: SendToWebview): void {
|
|
1355
|
+
this.sendToWebview = fn;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
onStatusChange(
|
|
1359
|
+
listener: (status: Readonly<AgentStatus>) => void,
|
|
1360
|
+
): () => void {
|
|
1361
|
+
this.statusListeners.add(listener);
|
|
1362
|
+
return () => {
|
|
1363
|
+
this.statusListeners.delete(listener);
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/** Start the agent runtime as a child process. Idempotent. */
|
|
1368
|
+
async start(): Promise<AgentStatus> {
|
|
1369
|
+
recordStartupPhase("agent_start_entered", {
|
|
1370
|
+
pid: process.pid,
|
|
1371
|
+
exec_path: process.execPath,
|
|
1372
|
+
bundle_path: resolveStartupBundlePath(process.execPath),
|
|
1373
|
+
});
|
|
1374
|
+
this.setStartupPhase("start_requested");
|
|
1375
|
+
recordStartupPhase("agent_start_entered", {
|
|
1376
|
+
pid: process.pid,
|
|
1377
|
+
exec_path: process.execPath,
|
|
1378
|
+
bundle_path: resolveStartupBundlePath(process.execPath),
|
|
1379
|
+
});
|
|
1380
|
+
diagnosticLog(
|
|
1381
|
+
`[Agent] start() called, current state: ${this.status.state}`,
|
|
1382
|
+
);
|
|
1383
|
+
diagnosticLog(`[Agent] Diagnostic log file: ${getDiagnosticLogPath()}`);
|
|
1384
|
+
|
|
1385
|
+
if (this.status.state === "running" || this.status.state === "starting") {
|
|
1386
|
+
return this.status;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
const runtimeMode = resolveDesktopRuntimeMode(
|
|
1390
|
+
process.env as Record<string, string | undefined>,
|
|
1391
|
+
);
|
|
1392
|
+
if (runtimeMode.mode !== "local") {
|
|
1393
|
+
const reason =
|
|
1394
|
+
runtimeMode.mode === "external"
|
|
1395
|
+
? `Embedded desktop runtime is disabled because ${runtimeMode.externalApi.source} points at ${runtimeMode.externalApi.base}.`
|
|
1396
|
+
: "Embedded desktop runtime is disabled by ELIZA_DESKTOP_SKIP_EMBEDDED_AGENT=1.";
|
|
1397
|
+
diagnosticLog(`[Agent] ${reason}`);
|
|
1398
|
+
this.setStartupPhase("startup_disabled", reason);
|
|
1399
|
+
throw new Error(reason);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
let packagedRuntime: boolean;
|
|
1403
|
+
let apiPort: number;
|
|
1404
|
+
let preferredPort: number;
|
|
1405
|
+
try {
|
|
1406
|
+
configureDesktopLocalApiAuth();
|
|
1407
|
+
packagedRuntime = isPackagedDesktopRuntime();
|
|
1408
|
+
|
|
1409
|
+
// Reset per-startup flags
|
|
1410
|
+
this.pgliteRecoveryDone = false;
|
|
1411
|
+
|
|
1412
|
+
// Clean up any stale process before starting
|
|
1413
|
+
if (this.childProcess) {
|
|
1414
|
+
await this.killChildProcess();
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
preferredPort = resolveDesktopApiPort(process.env) || DEFAULT_API_PORT;
|
|
1418
|
+
diagnosticLog(
|
|
1419
|
+
`[Agent] Preferred port: ${preferredPort} (packaged: ${packagedRuntime})`,
|
|
1420
|
+
);
|
|
1421
|
+
if (!packagedRuntime) {
|
|
1422
|
+
await maybeReclaimPortWithSigkill(preferredPort);
|
|
1423
|
+
}
|
|
1424
|
+
apiPort = await findFirstAvailableLoopbackPort(preferredPort);
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
const msg =
|
|
1427
|
+
err instanceof Error ? err.message : "Failed during pre-startup";
|
|
1428
|
+
diagnosticLog(`[Agent] ${msg}`);
|
|
1429
|
+
this.status = {
|
|
1430
|
+
state: "error",
|
|
1431
|
+
agentName: null,
|
|
1432
|
+
port: null,
|
|
1433
|
+
startedAt: null,
|
|
1434
|
+
error: msg,
|
|
1435
|
+
};
|
|
1436
|
+
recordStartupPhase("fatal", {
|
|
1437
|
+
port: null,
|
|
1438
|
+
error: msg,
|
|
1439
|
+
});
|
|
1440
|
+
this.setStartupPhase("port_allocation_failed", msg);
|
|
1441
|
+
this.emitStatus();
|
|
1442
|
+
return this.status;
|
|
1443
|
+
}
|
|
1444
|
+
if (apiPort !== preferredPort) {
|
|
1445
|
+
diagnosticLog(
|
|
1446
|
+
`[Agent] Port ${preferredPort} busy — using ${apiPort} for embedded API (set ELIZA_AGENT_RECLAIM_STALE_PORT=1 to try reclaiming the preferred port first)`,
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
recordStartupPhase("port_selected", {
|
|
1450
|
+
port: apiPort,
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
this.status = {
|
|
1454
|
+
state: "starting",
|
|
1455
|
+
agentName: null,
|
|
1456
|
+
port: null,
|
|
1457
|
+
startedAt: null,
|
|
1458
|
+
error: null,
|
|
1459
|
+
};
|
|
1460
|
+
this.setStartupPhase("starting_runtime");
|
|
1461
|
+
this.emitStatus();
|
|
1462
|
+
|
|
1463
|
+
try {
|
|
1464
|
+
// Resolve the bundled runtime dist path.
|
|
1465
|
+
this.setStartupPhase("resolving_runtime");
|
|
1466
|
+
const runtimeDistPath = resolveRuntimeDistPath();
|
|
1467
|
+
diagnosticLog(`[Agent] Resolved runtime dist: ${runtimeDistPath}`);
|
|
1468
|
+
|
|
1469
|
+
// Packaged builds can expose the runnable entry either at the dist root
|
|
1470
|
+
// or under runtime/. Prefer the root file but accept both layouts.
|
|
1471
|
+
const runtimeEntryPath = resolveRuntimeEntryPath(runtimeDistPath);
|
|
1472
|
+
if (!runtimeEntryPath) {
|
|
1473
|
+
const distExists = fs.existsSync(runtimeDistPath);
|
|
1474
|
+
let contents = "<directory missing>";
|
|
1475
|
+
if (distExists) {
|
|
1476
|
+
try {
|
|
1477
|
+
contents = fs.readdirSync(runtimeDistPath).join(", ");
|
|
1478
|
+
} catch {
|
|
1479
|
+
contents = "<unreadable>";
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
const errMsg = `No runnable runtime entry found in ${runtimeDistPath} (checked entry.js; dist exists: ${distExists}, contents: ${contents})`;
|
|
1483
|
+
diagnosticLog(`[Agent] ${errMsg}`);
|
|
1484
|
+
this.status = {
|
|
1485
|
+
state: "error",
|
|
1486
|
+
agentName: null,
|
|
1487
|
+
port: null,
|
|
1488
|
+
startedAt: null,
|
|
1489
|
+
error: errMsg,
|
|
1490
|
+
};
|
|
1491
|
+
recordStartupPhase("fatal", {
|
|
1492
|
+
port: apiPort,
|
|
1493
|
+
error: errMsg,
|
|
1494
|
+
});
|
|
1495
|
+
this.setStartupPhase("runtime_entry_missing", errMsg);
|
|
1496
|
+
recordStartupPhase("fatal", {
|
|
1497
|
+
port: apiPort,
|
|
1498
|
+
error: errMsg,
|
|
1499
|
+
});
|
|
1500
|
+
this.emitStatus();
|
|
1501
|
+
return this.status;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
diagnosticLog(`[Agent] runtime entry: exists (${runtimeEntryPath})`);
|
|
1505
|
+
recordStartupPhase("runtime_path_resolved", {
|
|
1506
|
+
port: apiPort,
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
diagnosticLog(`[Agent] Starting child process on port ${apiPort}...`);
|
|
1510
|
+
this.setStartupPhase("spawning_runtime");
|
|
1511
|
+
|
|
1512
|
+
// Build NODE_PATH so the child can find node_modules
|
|
1513
|
+
const nodePaths = buildChildNodePaths(runtimeDistPath, {
|
|
1514
|
+
packagedRuntime,
|
|
1515
|
+
});
|
|
1516
|
+
if (packagedRuntime && nodePaths.length === 0) {
|
|
1517
|
+
const errMsg =
|
|
1518
|
+
`Packaged runtime is missing bundle-local node_modules under ${runtimeDistPath}; ` +
|
|
1519
|
+
"refusing to inherit the parent NODE_PATH";
|
|
1520
|
+
diagnosticLog(`[Agent] ${errMsg}`);
|
|
1521
|
+
this.status = {
|
|
1522
|
+
state: "error",
|
|
1523
|
+
agentName: null,
|
|
1524
|
+
port: apiPort,
|
|
1525
|
+
startedAt: null,
|
|
1526
|
+
error: errMsg,
|
|
1527
|
+
};
|
|
1528
|
+
recordStartupPhase("fatal", {
|
|
1529
|
+
port: apiPort,
|
|
1530
|
+
error: errMsg,
|
|
1531
|
+
});
|
|
1532
|
+
this.emitStatus();
|
|
1533
|
+
return this.status;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
const childEnv: Record<string, string> = {
|
|
1537
|
+
...(process.env as Record<string, string>),
|
|
1538
|
+
ELIZA_API_PORT: String(apiPort),
|
|
1539
|
+
ELIZA_PORT: String(apiPort),
|
|
1540
|
+
};
|
|
1541
|
+
childEnv.ELIZA_NAMESPACE = resolveDesktopChildNamespace(childEnv);
|
|
1542
|
+
applyDesktopChildStateEnv(childEnv);
|
|
1543
|
+
delete childEnv.ELIZA_PORT;
|
|
1544
|
+
delete childEnv.NODE_PATH;
|
|
1545
|
+
|
|
1546
|
+
const databaseResolution = resolveDatabaseMode({
|
|
1547
|
+
env: childEnv,
|
|
1548
|
+
packagedDesktop: packagedRuntime,
|
|
1549
|
+
appStateDir: childEnv.ELIZA_STATE_DIR,
|
|
1550
|
+
cwd: runtimeDistPath,
|
|
1551
|
+
});
|
|
1552
|
+
applyDatabaseResolutionToEnv(childEnv, databaseResolution);
|
|
1553
|
+
const bundledWhisper = applyBundledWhisperEnv(childEnv, runtimeDistPath);
|
|
1554
|
+
if (bundledWhisper) {
|
|
1555
|
+
diagnosticLog(
|
|
1556
|
+
`[Agent] Bundled Whisper ASR: ${bundledWhisper.libraryPath}`,
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
const effectiveTarget =
|
|
1560
|
+
databaseResolution.mode === "postgres"
|
|
1561
|
+
? redactDatabaseTarget(databaseResolution.postgresUrl)
|
|
1562
|
+
: (databaseResolution.pgliteDataDir ?? null);
|
|
1563
|
+
this.databaseSnapshot = createDatabaseSnapshot({
|
|
1564
|
+
mode: databaseResolution.mode,
|
|
1565
|
+
status: "resolving",
|
|
1566
|
+
postgresUrlSet: databaseResolution.mode === "postgres",
|
|
1567
|
+
databaseUrlMapped: databaseResolution.databaseUrlMapped,
|
|
1568
|
+
pgliteDataDir: databaseResolution.pgliteDataDir ?? null,
|
|
1569
|
+
effectiveTarget,
|
|
1570
|
+
warnings: databaseResolution.warnings,
|
|
1571
|
+
});
|
|
1572
|
+
this.persistStartupDiagnostics();
|
|
1573
|
+
diagnosticLog(
|
|
1574
|
+
`[Agent] Database mode: ${databaseResolution.mode} source=${databaseResolution.source} target=${effectiveTarget ?? "runtime-default"}`,
|
|
1575
|
+
);
|
|
1576
|
+
recordStartupPhase("database_mode_resolved", {
|
|
1577
|
+
port: apiPort,
|
|
1578
|
+
});
|
|
1579
|
+
if (
|
|
1580
|
+
databaseResolution.mode === "pglite-persistent" &&
|
|
1581
|
+
databaseResolution.pgliteDataDir
|
|
1582
|
+
) {
|
|
1583
|
+
try {
|
|
1584
|
+
ensurePgliteDataDir(databaseResolution.pgliteDataDir);
|
|
1585
|
+
const lockResult = acquireDatabaseStartupLock(
|
|
1586
|
+
databaseResolution.pgliteDataDir,
|
|
1587
|
+
);
|
|
1588
|
+
if (!lockResult.ok) {
|
|
1589
|
+
const errMsg = lockResult.error;
|
|
1590
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1591
|
+
this.databaseSnapshot,
|
|
1592
|
+
"locked",
|
|
1593
|
+
{
|
|
1594
|
+
error: errMsg,
|
|
1595
|
+
lock: lockResult.snapshot,
|
|
1596
|
+
},
|
|
1597
|
+
);
|
|
1598
|
+
this.persistStartupDiagnostics(errMsg);
|
|
1599
|
+
this.status = {
|
|
1600
|
+
state: "error",
|
|
1601
|
+
agentName: null,
|
|
1602
|
+
port: apiPort,
|
|
1603
|
+
startedAt: null,
|
|
1604
|
+
error: errMsg,
|
|
1605
|
+
};
|
|
1606
|
+
this.emitStatus();
|
|
1607
|
+
return this.status;
|
|
1608
|
+
}
|
|
1609
|
+
this.databaseStartupLock = lockResult.lock;
|
|
1610
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1611
|
+
this.databaseSnapshot,
|
|
1612
|
+
"starting",
|
|
1613
|
+
{
|
|
1614
|
+
lock: lockResult.lock.snapshot,
|
|
1615
|
+
},
|
|
1616
|
+
);
|
|
1617
|
+
this.persistStartupDiagnostics();
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
const message =
|
|
1620
|
+
error instanceof Error ? error.message : String(error);
|
|
1621
|
+
const status = classifyDatabaseError(message);
|
|
1622
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1623
|
+
this.databaseSnapshot,
|
|
1624
|
+
status,
|
|
1625
|
+
{
|
|
1626
|
+
error: message,
|
|
1627
|
+
},
|
|
1628
|
+
);
|
|
1629
|
+
this.persistStartupDiagnostics(message);
|
|
1630
|
+
this.status = {
|
|
1631
|
+
state: "error",
|
|
1632
|
+
agentName: null,
|
|
1633
|
+
port: apiPort,
|
|
1634
|
+
startedAt: null,
|
|
1635
|
+
error: message,
|
|
1636
|
+
};
|
|
1637
|
+
this.emitStatus();
|
|
1638
|
+
return this.status;
|
|
1639
|
+
}
|
|
1640
|
+
} else if (
|
|
1641
|
+
databaseResolution.mode === "postgres" ||
|
|
1642
|
+
databaseResolution.mode === "pglite-memory"
|
|
1643
|
+
) {
|
|
1644
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1645
|
+
this.databaseSnapshot,
|
|
1646
|
+
"starting",
|
|
1647
|
+
);
|
|
1648
|
+
this.persistStartupDiagnostics();
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
applyWindowsNativeInferenceDefaults(childEnv);
|
|
1652
|
+
applyPackagedStartupEmbeddingWarmupPolicy(childEnv, packagedRuntime);
|
|
1653
|
+
applyDesktopDeferAppRoutesPolicy(childEnv);
|
|
1654
|
+
|
|
1655
|
+
if (nodePaths.length > 0) {
|
|
1656
|
+
childEnv.NODE_PATH = nodePaths.join(path.delimiter);
|
|
1657
|
+
diagnosticLog(`[Agent] Child NODE_PATH: ${childEnv.NODE_PATH}`);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
const bunExecutable = resolveBunExecutablePath();
|
|
1661
|
+
diagnosticLog(`[Agent] Using Bun executable: ${bunExecutable}`);
|
|
1662
|
+
diagnosticLog(
|
|
1663
|
+
`[Agent] Bun exists on disk: ${fs.existsSync(bunExecutable)}`,
|
|
1664
|
+
);
|
|
1665
|
+
|
|
1666
|
+
// Ensure bun's directory is on PATH so child_process.exec calls
|
|
1667
|
+
// (e.g. plugin-manager running `bun add ...`) can find it.
|
|
1668
|
+
const bunDir = path.dirname(bunExecutable);
|
|
1669
|
+
if (prependDesktopChildPathDirectory(childEnv, bunDir)) {
|
|
1670
|
+
diagnosticLog(`[Agent] Prepended bun dir to child PATH: ${bunDir}`);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
// Spawn the child process
|
|
1674
|
+
const spawnTime = Date.now();
|
|
1675
|
+
const proc = Bun.spawn(
|
|
1676
|
+
[bunExecutable, "run", runtimeEntryPath, "start"],
|
|
1677
|
+
{
|
|
1678
|
+
cwd: runtimeDistPath,
|
|
1679
|
+
env: childEnv,
|
|
1680
|
+
stdout: "pipe",
|
|
1681
|
+
stderr: "pipe",
|
|
1682
|
+
},
|
|
1683
|
+
);
|
|
1684
|
+
|
|
1685
|
+
this.childProcess = proc;
|
|
1686
|
+
diagnosticLog(
|
|
1687
|
+
`[Agent] Child spawned pid=${proc.pid} elapsed=${Date.now() - spawnTime}ms`,
|
|
1688
|
+
);
|
|
1689
|
+
recordStartupPhase("child_spawned", {
|
|
1690
|
+
port: apiPort,
|
|
1691
|
+
child_pid: proc.pid,
|
|
1692
|
+
});
|
|
1693
|
+
|
|
1694
|
+
// Set up abort controller for stdio watchers
|
|
1695
|
+
this.stdioAbortController = new AbortController();
|
|
1696
|
+
const { signal } = this.stdioAbortController;
|
|
1697
|
+
|
|
1698
|
+
// Surface the port immediately while waiting for ready
|
|
1699
|
+
this.status = {
|
|
1700
|
+
...this.status,
|
|
1701
|
+
port: apiPort,
|
|
1702
|
+
};
|
|
1703
|
+
this.emitStatus();
|
|
1704
|
+
|
|
1705
|
+
// Track whether we detected the "listening" message from stdout
|
|
1706
|
+
let detectedListening = false;
|
|
1707
|
+
|
|
1708
|
+
// Watch stdout for "listening on port" or similar ready messages
|
|
1709
|
+
if (proc.stdout) {
|
|
1710
|
+
watchStdoutForReady(
|
|
1711
|
+
proc.stdout,
|
|
1712
|
+
(line: string) => {
|
|
1713
|
+
diagnosticLog(`[Agent][stdout] ${line}`);
|
|
1714
|
+
const lower = line.toLowerCase();
|
|
1715
|
+
// Parse dynamic port from "[eliza-api] Listening on http://host:PORT"
|
|
1716
|
+
const portMatch = line.match(
|
|
1717
|
+
/Listening on https?:\/\/[^:]+:(\d+)/i,
|
|
1718
|
+
);
|
|
1719
|
+
if (portMatch) {
|
|
1720
|
+
const parsedPort = parseInt(portMatch[1], 10);
|
|
1721
|
+
if (!Number.isNaN(parsedPort) && parsedPort > 0) {
|
|
1722
|
+
if (parsedPort !== apiPort) {
|
|
1723
|
+
diagnosticLog(
|
|
1724
|
+
`[Agent] Server bound to dynamic port ${parsedPort} (requested ${apiPort})`,
|
|
1725
|
+
);
|
|
1726
|
+
apiPort = parsedPort;
|
|
1727
|
+
}
|
|
1728
|
+
detectedListening = true;
|
|
1729
|
+
}
|
|
1730
|
+
} else if (
|
|
1731
|
+
lower.includes("listening on port") ||
|
|
1732
|
+
lower.includes("server started") ||
|
|
1733
|
+
lower.includes("ready on")
|
|
1734
|
+
) {
|
|
1735
|
+
detectedListening = true;
|
|
1736
|
+
}
|
|
1737
|
+
// Update status port so callers see the actual bound port
|
|
1738
|
+
this.status = { ...this.status, port: apiPort };
|
|
1739
|
+
this.emitStatus();
|
|
1740
|
+
},
|
|
1741
|
+
signal,
|
|
1742
|
+
).catch(() => {
|
|
1743
|
+
// Stream ended or aborted -- expected on shutdown
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
// Drain stderr to diagnostic log; detect PGLite migration failures
|
|
1748
|
+
this.hasPgliteError = false;
|
|
1749
|
+
if (proc.stderr) {
|
|
1750
|
+
drainStderrToLog(proc.stderr, signal, (line) => {
|
|
1751
|
+
this.updateDatabaseSnapshotFromRuntimeLog(line);
|
|
1752
|
+
if (shouldAutoRecoverPgliteFailure(line)) {
|
|
1753
|
+
this.hasPgliteError = true;
|
|
1754
|
+
}
|
|
1755
|
+
}).catch(() => {
|
|
1756
|
+
// Stream ended or aborted -- expected on shutdown
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
// Monitor child process exit
|
|
1761
|
+
this.monitorChildExit(proc);
|
|
1762
|
+
|
|
1763
|
+
// Wait for the health endpoint to respond
|
|
1764
|
+
// Use a getter so the health check follows dynamic port reassignment from stdout
|
|
1765
|
+
diagnosticLog(
|
|
1766
|
+
`[Agent] Waiting for health endpoint at http://127.0.0.1:${apiPort}/api/health ...`,
|
|
1767
|
+
);
|
|
1768
|
+
this.setStartupPhase("waiting_for_health");
|
|
1769
|
+
const healthPollTimeoutMs = getHealthPollTimeoutMs();
|
|
1770
|
+
const healthy = await waitForHealthy(
|
|
1771
|
+
() => apiPort,
|
|
1772
|
+
healthPollTimeoutMs,
|
|
1773
|
+
proc,
|
|
1774
|
+
);
|
|
1775
|
+
|
|
1776
|
+
if (!healthy) {
|
|
1777
|
+
// Check if process already exited
|
|
1778
|
+
if (proc.exitCode !== null) {
|
|
1779
|
+
const errMsg = `Child process exited with code ${proc.exitCode} before becoming healthy`;
|
|
1780
|
+
diagnosticLog(`[Agent] ${errMsg}`);
|
|
1781
|
+
this.childProcess = null;
|
|
1782
|
+
this.status = {
|
|
1783
|
+
state: "error",
|
|
1784
|
+
agentName: null,
|
|
1785
|
+
port: apiPort,
|
|
1786
|
+
startedAt: null,
|
|
1787
|
+
error: errMsg,
|
|
1788
|
+
};
|
|
1789
|
+
recordStartupPhase("fatal", {
|
|
1790
|
+
port: apiPort,
|
|
1791
|
+
child_pid: proc.pid,
|
|
1792
|
+
error: errMsg,
|
|
1793
|
+
exit_code: proc.exitCode,
|
|
1794
|
+
});
|
|
1795
|
+
this.setStartupPhase("startup_failed", errMsg);
|
|
1796
|
+
recordStartupPhase("fatal", {
|
|
1797
|
+
port: apiPort,
|
|
1798
|
+
child_pid: proc.pid,
|
|
1799
|
+
error: errMsg,
|
|
1800
|
+
exit_code: proc.exitCode,
|
|
1801
|
+
});
|
|
1802
|
+
this.releaseDatabaseStartupLock();
|
|
1803
|
+
this.emitStatus();
|
|
1804
|
+
return this.status;
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
const errMsg = detectedListening
|
|
1808
|
+
? "Server reported listening but health check timed out"
|
|
1809
|
+
: `Health check timed out after ${healthPollTimeoutMs}ms`;
|
|
1810
|
+
diagnosticLog(`[Agent] ${errMsg}`);
|
|
1811
|
+
this.status = {
|
|
1812
|
+
state: "error",
|
|
1813
|
+
agentName: null,
|
|
1814
|
+
port: apiPort,
|
|
1815
|
+
startedAt: null,
|
|
1816
|
+
error: errMsg,
|
|
1817
|
+
};
|
|
1818
|
+
recordStartupPhase("fatal", {
|
|
1819
|
+
port: apiPort,
|
|
1820
|
+
child_pid: proc.pid,
|
|
1821
|
+
error: errMsg,
|
|
1822
|
+
});
|
|
1823
|
+
this.setStartupPhase("startup_failed", errMsg);
|
|
1824
|
+
recordStartupPhase("fatal", {
|
|
1825
|
+
port: apiPort,
|
|
1826
|
+
child_pid: proc.pid,
|
|
1827
|
+
error: errMsg,
|
|
1828
|
+
});
|
|
1829
|
+
this.releaseDatabaseStartupLock();
|
|
1830
|
+
this.emitStatus();
|
|
1831
|
+
return this.status;
|
|
1832
|
+
}
|
|
1833
|
+
recordStartupPhase("health_ready", {
|
|
1834
|
+
port: apiPort,
|
|
1835
|
+
child_pid: proc.pid,
|
|
1836
|
+
});
|
|
1837
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1838
|
+
this.databaseSnapshot,
|
|
1839
|
+
"ready",
|
|
1840
|
+
{
|
|
1841
|
+
migrationStatus:
|
|
1842
|
+
this.databaseSnapshot.migrationStatus?.failed === true
|
|
1843
|
+
? this.databaseSnapshot.migrationStatus
|
|
1844
|
+
: {
|
|
1845
|
+
running: false,
|
|
1846
|
+
completed: true,
|
|
1847
|
+
failed: false,
|
|
1848
|
+
},
|
|
1849
|
+
lock: {
|
|
1850
|
+
held: false,
|
|
1851
|
+
},
|
|
1852
|
+
},
|
|
1853
|
+
);
|
|
1854
|
+
this.releaseDatabaseStartupLock();
|
|
1855
|
+
|
|
1856
|
+
this.setStartupPhase("fetching_agent_metadata");
|
|
1857
|
+
const startedAt = Date.now();
|
|
1858
|
+
const startupMs = startedAt - spawnTime;
|
|
1859
|
+
|
|
1860
|
+
this.status = {
|
|
1861
|
+
state: "running",
|
|
1862
|
+
agentName: getBrandConfig().appName,
|
|
1863
|
+
port: apiPort,
|
|
1864
|
+
startedAt,
|
|
1865
|
+
error: null,
|
|
1866
|
+
};
|
|
1867
|
+
this.setStartupPhase("ready", null);
|
|
1868
|
+
this.emitStatus();
|
|
1869
|
+
diagnosticLog(
|
|
1870
|
+
`[Agent] Runtime ready -- port: ${apiPort}, pid: ${proc.pid}, startup_ms: ${startupMs}`,
|
|
1871
|
+
);
|
|
1872
|
+
recordStartupPhase("runtime_ready", {
|
|
1873
|
+
port: apiPort,
|
|
1874
|
+
child_pid: proc.pid,
|
|
1875
|
+
});
|
|
1876
|
+
void this.refreshAgentMetadata(proc, apiPort, startupMs);
|
|
1877
|
+
return this.status;
|
|
1878
|
+
} catch (err) {
|
|
1879
|
+
const errMsg =
|
|
1880
|
+
err instanceof Error ? err.stack || err.message : String(err);
|
|
1881
|
+
diagnosticLog(`[Agent] Failed to start: ${errMsg}`);
|
|
1882
|
+
recordStartupPhase("fatal", {
|
|
1883
|
+
port: this.status.port,
|
|
1884
|
+
error: errMsg,
|
|
1885
|
+
});
|
|
1886
|
+
|
|
1887
|
+
// Clean up child if it was spawned
|
|
1888
|
+
if (this.childProcess) {
|
|
1889
|
+
await this.killChildProcess();
|
|
1890
|
+
}
|
|
1891
|
+
this.releaseDatabaseStartupLock();
|
|
1892
|
+
|
|
1893
|
+
this.status = {
|
|
1894
|
+
state: "error",
|
|
1895
|
+
agentName: null,
|
|
1896
|
+
port: this.status.port, // preserve port if set
|
|
1897
|
+
startedAt: null,
|
|
1898
|
+
error: shortError(err),
|
|
1899
|
+
};
|
|
1900
|
+
this.setStartupPhase("startup_failed", shortError(err));
|
|
1901
|
+
this.emitStatus();
|
|
1902
|
+
return this.status;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
/** Stop the agent runtime. */
|
|
1907
|
+
async stop(): Promise<void> {
|
|
1908
|
+
if (this.status.state !== "running" && this.status.state !== "starting") {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
diagnosticLog("[Agent] Stopping...");
|
|
1913
|
+
this.setStartupPhase("stopping");
|
|
1914
|
+
|
|
1915
|
+
// Abort stdio watchers
|
|
1916
|
+
if (this.stdioAbortController) {
|
|
1917
|
+
this.stdioAbortController.abort();
|
|
1918
|
+
this.stdioAbortController = null;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
await this.killChildProcess();
|
|
1922
|
+
this.releaseDatabaseStartupLock();
|
|
1923
|
+
|
|
1924
|
+
this.status = {
|
|
1925
|
+
state: "stopped",
|
|
1926
|
+
agentName: this.status.agentName,
|
|
1927
|
+
port: null,
|
|
1928
|
+
startedAt: null,
|
|
1929
|
+
error: null,
|
|
1930
|
+
};
|
|
1931
|
+
this.setStartupPhase("stopped", null);
|
|
1932
|
+
this.emitStatus();
|
|
1933
|
+
diagnosticLog("[Agent] Runtime stopped");
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* Restart the agent runtime -- stops the current instance and starts a
|
|
1938
|
+
* fresh one, picking up config/plugin changes.
|
|
1939
|
+
*/
|
|
1940
|
+
async restart(): Promise<AgentStatus> {
|
|
1941
|
+
diagnosticLog("[Agent] Restart requested -- stopping current runtime...");
|
|
1942
|
+
this.setStartupPhase("restart_requested");
|
|
1943
|
+
await this.stop();
|
|
1944
|
+
diagnosticLog("[Agent] Restarting...");
|
|
1945
|
+
return this.start();
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/**
|
|
1949
|
+
* Used after `POST /api/agent/reset`: stop the child, delete local PGLite
|
|
1950
|
+
* (conversations / agent memory under the active state-dir workspace),
|
|
1951
|
+
* then start fresh. Does not remove downloaded **GGUF** models (`MODELS_DIR`,
|
|
1952
|
+
* env-backed wallet keys, or eliza.json (the API reset already rewrote
|
|
1953
|
+
* config on disk).
|
|
1954
|
+
*
|
|
1955
|
+
* When `ELIZA_DESKTOP_API_BASE` points at an external dev API (e.g. :31337),
|
|
1956
|
+
* the embedded child is never used — this is a no-op so the renderer can
|
|
1957
|
+
* bounce the real API via `POST /api/agent/restart` instead.
|
|
1958
|
+
*/
|
|
1959
|
+
async restartClearingLocalDb(): Promise<AgentStatus> {
|
|
1960
|
+
const runtimeMode = resolveDesktopRuntimeMode(
|
|
1961
|
+
process.env as Record<string, string | undefined>,
|
|
1962
|
+
);
|
|
1963
|
+
if (runtimeMode.mode !== "local") {
|
|
1964
|
+
diagnosticLog(
|
|
1965
|
+
`[Agent] restartClearingLocalDb skipped — mode=${runtimeMode.mode} externalBase=${runtimeMode.externalApi.base ?? "n/a"} source=${runtimeMode.externalApi.source ?? "n/a"} (renderer uses POST /api/agent/restart)`,
|
|
1966
|
+
);
|
|
1967
|
+
return this.getStatus();
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
const dataDir = resolveManagedPgliteDataDir();
|
|
1971
|
+
if (!dataDir) {
|
|
1972
|
+
const message =
|
|
1973
|
+
"Local PGlite reset is unavailable for the active database mode.";
|
|
1974
|
+
diagnosticLog(`[Agent] restartClearingLocalDb skipped — ${message}`);
|
|
1975
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1976
|
+
this.databaseSnapshot,
|
|
1977
|
+
"error",
|
|
1978
|
+
{ error: message },
|
|
1979
|
+
);
|
|
1980
|
+
return this.getStatus();
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
diagnosticLog(
|
|
1984
|
+
`[Agent] restartClearingLocalDb: local mode — stop → backup/reset PGLite (${dataDir}) → start`,
|
|
1985
|
+
);
|
|
1986
|
+
await this.stop();
|
|
1987
|
+
this.hasPgliteError = false;
|
|
1988
|
+
this.pgliteRecoveryDone = false;
|
|
1989
|
+
const reset = resetPgliteDirectory(dataDir);
|
|
1990
|
+
diagnosticLog(
|
|
1991
|
+
`[Agent] PGLite backup/reset completed backup=${reset.backup.backupDir ?? "none"} removed=${reset.removed}`,
|
|
1992
|
+
);
|
|
1993
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
1994
|
+
this.databaseSnapshot,
|
|
1995
|
+
"starting",
|
|
1996
|
+
{ error: null },
|
|
1997
|
+
);
|
|
1998
|
+
const next = await this.start();
|
|
1999
|
+
diagnosticLog(
|
|
2000
|
+
`[Agent] restartClearingLocalDb: start() finished state=${next.state} port=${next.port ?? "null"}`,
|
|
2001
|
+
);
|
|
2002
|
+
return next;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
getStatus(): AgentStatus {
|
|
2006
|
+
return { ...this.status };
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
getDatabaseSnapshot(): DatabaseSnapshot {
|
|
2010
|
+
return this.databaseSnapshot;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
previewDatabaseRecovery(): {
|
|
2014
|
+
snapshot: DatabaseSnapshot;
|
|
2015
|
+
actions: DatabaseSnapshot["recoveryActions"];
|
|
2016
|
+
} {
|
|
2017
|
+
return {
|
|
2018
|
+
snapshot: this.databaseSnapshot,
|
|
2019
|
+
actions: this.databaseSnapshot.recoveryActions,
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
backupPgliteDatabase(): ReturnType<typeof backupPgliteDirectory> {
|
|
2024
|
+
const dataDir =
|
|
2025
|
+
this.databaseSnapshot.pgliteDataDir ?? resolveManagedPgliteDataDir();
|
|
2026
|
+
if (!dataDir) {
|
|
2027
|
+
throw new Error("No persistent PGlite data directory is active.");
|
|
2028
|
+
}
|
|
2029
|
+
const result = backupPgliteDirectory(dataDir);
|
|
2030
|
+
diagnosticLog(
|
|
2031
|
+
`[Agent] PGLite backup created: ${result.backupDir ?? "none"} reason=${result.reason ?? "created"}`,
|
|
2032
|
+
);
|
|
2033
|
+
return result;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
async resetPgliteDatabase(params?: {
|
|
2037
|
+
restart?: boolean;
|
|
2038
|
+
}): Promise<
|
|
2039
|
+
ReturnType<typeof resetPgliteDirectory> & { restarted: boolean }
|
|
2040
|
+
> {
|
|
2041
|
+
const dataDir =
|
|
2042
|
+
this.databaseSnapshot.pgliteDataDir ?? resolveManagedPgliteDataDir();
|
|
2043
|
+
if (!dataDir) {
|
|
2044
|
+
throw new Error("No persistent PGlite data directory is active.");
|
|
2045
|
+
}
|
|
2046
|
+
await this.stop();
|
|
2047
|
+
const result = resetPgliteDirectory(dataDir);
|
|
2048
|
+
diagnosticLog(
|
|
2049
|
+
`[Agent] PGLite reset completed backup=${result.backup.backupDir ?? "none"} removed=${result.removed}`,
|
|
2050
|
+
);
|
|
2051
|
+
if (params?.restart === true) {
|
|
2052
|
+
await this.start();
|
|
2053
|
+
return { ...result, restarted: true };
|
|
2054
|
+
}
|
|
2055
|
+
return { ...result, restarted: false };
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
inspectExistingInstall(): ExistingElizaInstallInfo {
|
|
2059
|
+
return inspectExistingElizaInstall();
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
migrateStateDir(params: { fromPath: string }): StateDirMigrationResult {
|
|
2063
|
+
return migrateDesktopStateDirFromPath(params.fromPath);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
getPort(): number | null {
|
|
2067
|
+
return this.status.port;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
/** Clean up on app quit. */
|
|
2071
|
+
async dispose(): Promise<void> {
|
|
2072
|
+
if (this.stdioAbortController) {
|
|
2073
|
+
this.stdioAbortController.abort();
|
|
2074
|
+
this.stdioAbortController = null;
|
|
2075
|
+
}
|
|
2076
|
+
try {
|
|
2077
|
+
await this.killChildProcess();
|
|
2078
|
+
this.releaseDatabaseStartupLock();
|
|
2079
|
+
} catch (err) {
|
|
2080
|
+
logger.warn(
|
|
2081
|
+
`[Agent] dispose error: ${err instanceof Error ? err.message : String(err)}`,
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
// -----------------------------------------------------------------------
|
|
2087
|
+
// Private helpers
|
|
2088
|
+
// -----------------------------------------------------------------------
|
|
2089
|
+
|
|
2090
|
+
private emitStatus(): void {
|
|
2091
|
+
this.persistStartupDiagnostics();
|
|
2092
|
+
if (this.sendToWebview) {
|
|
2093
|
+
this.sendToWebview("agentStatusUpdate", this.status);
|
|
2094
|
+
}
|
|
2095
|
+
const statusSnapshot = { ...this.status };
|
|
2096
|
+
for (const listener of this.statusListeners) {
|
|
2097
|
+
try {
|
|
2098
|
+
listener(statusSnapshot);
|
|
2099
|
+
} catch (err) {
|
|
2100
|
+
logger.warn(
|
|
2101
|
+
`[Agent] status listener failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
2102
|
+
);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
private async refreshAgentMetadata(
|
|
2108
|
+
proc: BunSubprocess,
|
|
2109
|
+
port: number,
|
|
2110
|
+
startupMs: number,
|
|
2111
|
+
): Promise<void> {
|
|
2112
|
+
const agentName = await this.fetchAgentName(port);
|
|
2113
|
+
if (
|
|
2114
|
+
this.childProcess !== proc ||
|
|
2115
|
+
this.status.state !== "running" ||
|
|
2116
|
+
this.status.port !== port
|
|
2117
|
+
) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
if (this.status.agentName !== agentName) {
|
|
2122
|
+
this.status = {
|
|
2123
|
+
...this.status,
|
|
2124
|
+
agentName,
|
|
2125
|
+
};
|
|
2126
|
+
this.emitStatus();
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
diagnosticLog(
|
|
2130
|
+
`[Agent] Runtime started -- agent: ${agentName}, port: ${port}, pid: ${proc.pid}, startup_ms: ${startupMs}`,
|
|
2131
|
+
);
|
|
2132
|
+
recordStartupPhase("metadata_ready", {
|
|
2133
|
+
port,
|
|
2134
|
+
child_pid: proc.pid,
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
private setStartupPhase(phase: string, lastError?: string | null): void {
|
|
2138
|
+
this.startupPhase = phase;
|
|
2139
|
+
this.persistStartupDiagnostics(lastError);
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
private persistStartupDiagnostics(lastError?: string | null): void {
|
|
2143
|
+
writeStartupDiagnosticsSnapshot({
|
|
2144
|
+
state: this.status.state,
|
|
2145
|
+
phase: this.startupPhase,
|
|
2146
|
+
updatedAt: new Date().toISOString(),
|
|
2147
|
+
lastError: lastError ?? this.status.error,
|
|
2148
|
+
agentName: this.status.agentName,
|
|
2149
|
+
port: this.status.port,
|
|
2150
|
+
startedAt: this.status.startedAt,
|
|
2151
|
+
platform: process.platform,
|
|
2152
|
+
arch: process.arch,
|
|
2153
|
+
configDir: resolveConfigDir(),
|
|
2154
|
+
logPath: getDiagnosticLogPath(),
|
|
2155
|
+
statusPath: getStartupStatusPath(),
|
|
2156
|
+
database: this.databaseSnapshot,
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
private releaseDatabaseStartupLock(): void {
|
|
2161
|
+
if (!this.databaseStartupLock) return;
|
|
2162
|
+
this.databaseStartupLock.release();
|
|
2163
|
+
this.databaseStartupLock = null;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
private updateDatabaseSnapshotFromRuntimeLog(line: string): void {
|
|
2167
|
+
const lower = line.toLowerCase();
|
|
2168
|
+
if (lower.includes("starting migrations")) {
|
|
2169
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
2170
|
+
this.databaseSnapshot,
|
|
2171
|
+
"migrating",
|
|
2172
|
+
{
|
|
2173
|
+
migrationStatus: {
|
|
2174
|
+
running: true,
|
|
2175
|
+
completed: false,
|
|
2176
|
+
failed: false,
|
|
2177
|
+
},
|
|
2178
|
+
},
|
|
2179
|
+
);
|
|
2180
|
+
this.persistStartupDiagnostics();
|
|
2181
|
+
recordStartupPhase("database_migration_started", {
|
|
2182
|
+
port: this.status.port,
|
|
2183
|
+
});
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
if (lower.includes("all migrations completed successfully")) {
|
|
2187
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
2188
|
+
this.databaseSnapshot,
|
|
2189
|
+
"starting",
|
|
2190
|
+
{
|
|
2191
|
+
migrationStatus: {
|
|
2192
|
+
running: false,
|
|
2193
|
+
completed: true,
|
|
2194
|
+
failed: false,
|
|
2195
|
+
},
|
|
2196
|
+
},
|
|
2197
|
+
);
|
|
2198
|
+
this.persistStartupDiagnostics();
|
|
2199
|
+
recordStartupPhase("database_migration_completed", {
|
|
2200
|
+
port: this.status.port,
|
|
2201
|
+
});
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
if (
|
|
2205
|
+
lower.includes("migration failed") ||
|
|
2206
|
+
lower.includes("migration(s) failed")
|
|
2207
|
+
) {
|
|
2208
|
+
const pluginMatch = line.match(/pluginName[":=\s]+["']?([^"',\s}]+)/);
|
|
2209
|
+
const error = redactSensitiveDiagnostics(line);
|
|
2210
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
2211
|
+
this.databaseSnapshot,
|
|
2212
|
+
"migration-failed",
|
|
2213
|
+
{
|
|
2214
|
+
error,
|
|
2215
|
+
migrationStatus: {
|
|
2216
|
+
running: false,
|
|
2217
|
+
completed: false,
|
|
2218
|
+
failed: true,
|
|
2219
|
+
failedPlugin: pluginMatch?.[1],
|
|
2220
|
+
error,
|
|
2221
|
+
},
|
|
2222
|
+
},
|
|
2223
|
+
);
|
|
2224
|
+
this.persistStartupDiagnostics(error);
|
|
2225
|
+
recordStartupPhase("database_migration_failed", {
|
|
2226
|
+
port: this.status.port,
|
|
2227
|
+
error,
|
|
2228
|
+
});
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
const status = classifyDatabaseError(line);
|
|
2232
|
+
if (status === "error") return;
|
|
2233
|
+
const error = redactSensitiveDiagnostics(line);
|
|
2234
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
2235
|
+
this.databaseSnapshot,
|
|
2236
|
+
status,
|
|
2237
|
+
{ error },
|
|
2238
|
+
);
|
|
2239
|
+
this.persistStartupDiagnostics(error);
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Monitor the child process for unexpected exits and update status.
|
|
2244
|
+
*/
|
|
2245
|
+
private monitorChildExit(proc: BunSubprocess): void {
|
|
2246
|
+
// Bun.spawn provides an `exited` promise that resolves when the process exits
|
|
2247
|
+
proc.exited
|
|
2248
|
+
.then((exitCode: number) => {
|
|
2249
|
+
// Only update status if this is still our active child process
|
|
2250
|
+
if (this.childProcess !== proc) return;
|
|
2251
|
+
|
|
2252
|
+
const wasRunning = this.status.state === "running";
|
|
2253
|
+
const wasStarting = this.status.state === "starting";
|
|
2254
|
+
|
|
2255
|
+
if (wasRunning || wasStarting) {
|
|
2256
|
+
diagnosticLog(
|
|
2257
|
+
`[Agent] Child process exited unexpectedly with code ${exitCode} (pid: ${proc.pid})`,
|
|
2258
|
+
);
|
|
2259
|
+
recordStartupPhase("fatal", {
|
|
2260
|
+
port: this.status.port,
|
|
2261
|
+
child_pid: proc.pid,
|
|
2262
|
+
error: `Process exited unexpectedly with code ${exitCode}`,
|
|
2263
|
+
exit_code: exitCode,
|
|
2264
|
+
});
|
|
2265
|
+
this.childProcess = null;
|
|
2266
|
+
|
|
2267
|
+
if (this.hasPgliteError && !this.pgliteRecoveryDone) {
|
|
2268
|
+
this.pgliteRecoveryDone = true;
|
|
2269
|
+
const error =
|
|
2270
|
+
"PGLite startup or migration failed. Use database recovery to backup/reset local data or switch to Postgres.";
|
|
2271
|
+
diagnosticLog(`[Agent] ${error}`);
|
|
2272
|
+
this.databaseSnapshot = updateDatabaseSnapshotStatus(
|
|
2273
|
+
this.databaseSnapshot,
|
|
2274
|
+
classifyDatabaseError(error),
|
|
2275
|
+
{ error },
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
this.status = {
|
|
2280
|
+
state: "error",
|
|
2281
|
+
agentName: this.status.agentName,
|
|
2282
|
+
port: this.status.port,
|
|
2283
|
+
startedAt: null,
|
|
2284
|
+
error: `Process exited unexpectedly with code ${exitCode}`,
|
|
2285
|
+
};
|
|
2286
|
+
this.setStartupPhase(
|
|
2287
|
+
"process_exited_unexpectedly",
|
|
2288
|
+
`Process exited unexpectedly with code ${exitCode}`,
|
|
2289
|
+
);
|
|
2290
|
+
this.releaseDatabaseStartupLock();
|
|
2291
|
+
this.emitStatus();
|
|
2292
|
+
} else {
|
|
2293
|
+
// Expected exit (we called stop)
|
|
2294
|
+
this.childProcess = null;
|
|
2295
|
+
this.releaseDatabaseStartupLock();
|
|
2296
|
+
}
|
|
2297
|
+
})
|
|
2298
|
+
.catch((err: unknown) => {
|
|
2299
|
+
if (this.childProcess !== proc) return;
|
|
2300
|
+
diagnosticLog(
|
|
2301
|
+
`[Agent] Child process exited with error: ${err instanceof Error ? err.message : String(err)}`,
|
|
2302
|
+
);
|
|
2303
|
+
recordStartupPhase("fatal", {
|
|
2304
|
+
port: this.status.port,
|
|
2305
|
+
child_pid: proc.pid,
|
|
2306
|
+
error: err instanceof Error ? err.message : String(err),
|
|
2307
|
+
});
|
|
2308
|
+
this.childProcess = null;
|
|
2309
|
+
this.releaseDatabaseStartupLock();
|
|
2310
|
+
if (
|
|
2311
|
+
this.status.state === "running" ||
|
|
2312
|
+
this.status.state === "starting"
|
|
2313
|
+
) {
|
|
2314
|
+
this.status = {
|
|
2315
|
+
state: "error",
|
|
2316
|
+
agentName: this.status.agentName,
|
|
2317
|
+
port: this.status.port,
|
|
2318
|
+
startedAt: null,
|
|
2319
|
+
error: shortError(err),
|
|
2320
|
+
};
|
|
2321
|
+
this.setStartupPhase("process_exit_error", shortError(err));
|
|
2322
|
+
this.emitStatus();
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
/**
|
|
2328
|
+
* Kill the child process gracefully with SIGTERM, escalating to SIGKILL
|
|
2329
|
+
* after a timeout.
|
|
2330
|
+
*/
|
|
2331
|
+
private async killChildProcess(): Promise<void> {
|
|
2332
|
+
const proc = this.childProcess;
|
|
2333
|
+
if (!proc) return;
|
|
2334
|
+
|
|
2335
|
+
this.childProcess = null;
|
|
2336
|
+
|
|
2337
|
+
// Already exited
|
|
2338
|
+
if (proc.exitCode !== null) return;
|
|
2339
|
+
|
|
2340
|
+
diagnosticLog(`[Agent] Sending SIGTERM to pid ${proc.pid}`);
|
|
2341
|
+
proc.kill("SIGTERM");
|
|
2342
|
+
|
|
2343
|
+
// Wait for graceful shutdown or timeout
|
|
2344
|
+
const exited = await Promise.race([
|
|
2345
|
+
proc.exited.then(() => true as const),
|
|
2346
|
+
Bun.sleep(SIGTERM_GRACE_MS).then(() => false as const),
|
|
2347
|
+
]);
|
|
2348
|
+
|
|
2349
|
+
if (!exited) {
|
|
2350
|
+
diagnosticLog(
|
|
2351
|
+
`[Agent] Process did not exit within ${SIGTERM_GRACE_MS}ms, sending SIGKILL`,
|
|
2352
|
+
);
|
|
2353
|
+
try {
|
|
2354
|
+
proc.kill("SIGKILL");
|
|
2355
|
+
} catch {
|
|
2356
|
+
// Process may have already exited between check and kill
|
|
2357
|
+
}
|
|
2358
|
+
// Wait briefly for SIGKILL to take effect
|
|
2359
|
+
await Promise.race([proc.exited.catch(() => {}), Bun.sleep(1_000)]);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
diagnosticLog("[Agent] Child process terminated");
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
/**
|
|
2366
|
+
* Attempt to fetch the agent name from the running API server.
|
|
2367
|
+
* Falls back to the configured desktop app name if the endpoint is unavailable.
|
|
2368
|
+
*/
|
|
2369
|
+
private async fetchAgentName(port: number): Promise<string> {
|
|
2370
|
+
try {
|
|
2371
|
+
const headers = getDesktopApiHeaders();
|
|
2372
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/agents`, {
|
|
2373
|
+
headers,
|
|
2374
|
+
signal: AbortSignal.timeout(AGENT_NAME_FETCH_TIMEOUT_MS),
|
|
2375
|
+
});
|
|
2376
|
+
if (response.ok) {
|
|
2377
|
+
const data = (await response.json()) as
|
|
2378
|
+
| { agents?: Array<{ name?: string }> }
|
|
2379
|
+
| Array<{ name?: string }>;
|
|
2380
|
+
const agents = Array.isArray(data) ? data : data.agents;
|
|
2381
|
+
if (agents && agents.length > 0 && agents[0].name) {
|
|
2382
|
+
return agents[0].name;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
} catch {
|
|
2386
|
+
diagnosticLog("[Agent] Could not fetch agent name, using default");
|
|
2387
|
+
}
|
|
2388
|
+
return getBrandConfig().appName;
|
|
2389
|
+
}
|
|
1950
2390
|
}
|
|
1951
2391
|
|
|
1952
2392
|
// ---------------------------------------------------------------------------
|
|
@@ -1956,8 +2396,8 @@ export class AgentManager {
|
|
|
1956
2396
|
let agentManager: AgentManager | null = null;
|
|
1957
2397
|
|
|
1958
2398
|
export function getAgentManager(): AgentManager {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2399
|
+
if (!agentManager) {
|
|
2400
|
+
agentManager = new AgentManager();
|
|
2401
|
+
}
|
|
2402
|
+
return agentManager;
|
|
1963
2403
|
}
|