dexbot 1.6.7 → 1.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -1
- package/README.md +3 -3
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +55 -16
- package/dist/market_adapter/core/market_adapter_service.d.ts +81 -1
- package/dist/market_adapter/core/market_adapter_service.js +239 -20
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js +40 -18
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +26 -2
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +132 -29
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +61 -3
- package/dist/market_adapter/core/strategies/regime_gate.js +207 -7
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/interval_utils.d.ts +18 -1
- package/dist/market_adapter/interval_utils.js +31 -1
- package/dist/market_adapter/market_adapter.d.ts +158 -2
- package/dist/market_adapter/market_adapter.js +399 -65
- package/dist/market_adapter/test_helpers.d.ts +2 -2
- package/dist/market_adapter/test_helpers.js +2 -2
- package/dist/market_adapter/utils/file_json_cache.d.ts +29 -0
- package/dist/market_adapter/utils/file_json_cache.js +106 -0
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +7 -0
- package/dist/modules/config.js +2 -0
- package/dist/modules/constants.d.ts +16 -4
- package/dist/modules/constants.js +144 -38
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +21 -0
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +172 -160
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +311 -0
- package/dist/modules/version_notice.js +709 -0
- package/dist/pm2.js +16 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +22 -20
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +18 -2
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +29 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/version_notice.ts - Passive version status + "new version" notice.
|
|
3
|
+
*
|
|
4
|
+
* Reports the INSTALLED version against the published `latest` on every start
|
|
5
|
+
* and in `dexbot stat`, and prints a one-time hint when a newer DEXBot2 release
|
|
6
|
+
* exists — without ever changing code on its own. This is deliberately
|
|
7
|
+
* ORTHOGONAL to `UPDATER.ACTIVE` (the automated updater, default OFF): a bot
|
|
8
|
+
* handling real funds must never silently change its own code, but the
|
|
9
|
+
* operator still deserves to KNOW a fix or a breaking change landed. The
|
|
10
|
+
* opt-out lives in `UPDATER.NOTICE_ENABLED` so it can be tuned independently of
|
|
11
|
+
* the updater.
|
|
12
|
+
*
|
|
13
|
+
* ===============================================================================
|
|
14
|
+
* DESIGN CONSTRAINTS
|
|
15
|
+
* ===============================================================================
|
|
16
|
+
*
|
|
17
|
+
* 1. NEVER BLOCKS STARTUP. `startVersionStatusCheck()` returns a promise
|
|
18
|
+
* immediately and resolves with a `VersionStatus` (or null when the check is
|
|
19
|
+
* disabled). Callers start it early and `await` it late, so the round-trip
|
|
20
|
+
* overlaps work that is already happening (BitShares connection, password
|
|
21
|
+
* prompt).
|
|
22
|
+
* 2. NEVER THROWS. Every failure path — offline, DNS failure, slow registry,
|
|
23
|
+
* unreadable cache, browser — resolves to `null`.
|
|
24
|
+
* 3. NO SUBPROCESSES. Each source is queried with a single HTTPS GET and a
|
|
25
|
+
* hard timeout. `execSync('npm view ...')` (as used by `dexbot update`)
|
|
26
|
+
* costs 1-3s of spawn and hard-depends on the npm CLI, neither of which is
|
|
27
|
+
* acceptable on the launcher critical path.
|
|
28
|
+
* 3b. MULTIPLE SOURCES, FALLBACK NOT FAILURE. One source is a single point of
|
|
29
|
+
* failure: a host that cannot reach registry.npmjs.org (firewall, DNS, a
|
|
30
|
+
* proxy only the npm CLI knows about) reported "unknown" forever even when
|
|
31
|
+
* the release was published on GitHub. Sources are tried in order and the
|
|
32
|
+
* first answer wins, so an unreachable registry degrades to a slower probe
|
|
33
|
+
* instead of a permanent "?". Each source is bounded by an even share of
|
|
34
|
+
* the total budget, so a hanging first source cannot starve the second.
|
|
35
|
+
* 3c. NEVER MYSTERY. Every failure path records WHY (`ENOTFOUND`, `HTTP 403`,
|
|
36
|
+
* `timeout`, `no fetch`, …) and the unknown verdict names it. An operator
|
|
37
|
+
* cannot act on "?" and used to have to guess between DNS, TLS, a proxy and
|
|
38
|
+
* a timeout.
|
|
39
|
+
* 4. THROTTLED + NOTIFY-ONCE. A check runs at most once per
|
|
40
|
+
* `UPDATER.NOTICE_INTERVAL_MS` AFTER A SUCCESS, and once per
|
|
41
|
+
* `UPDATER.NOTICE_RETRY_MS` after a failure (a failure is the observation
|
|
42
|
+
* that decays fastest — see the constant). The same version is announced
|
|
43
|
+
* only once (`notifiedVersion` in the cache) so an ignored notice does not
|
|
44
|
+
* nag on every restart. A new published version resets that latch. The latch
|
|
45
|
+
* is committed by `printVersionStatus` only AFTER the notice is displayed, so a
|
|
46
|
+
* launcher path that returns without printing cannot silently consume it —
|
|
47
|
+
* it is re-offered once the throttle window expires. A throttled run still
|
|
48
|
+
* reports a status (from the cached observation) so `dexbot stat` answers
|
|
49
|
+
* "am I current?" without spending a request.
|
|
50
|
+
* 4a. DEFERRED, NOT DROPPED. Callers that have other work to do (`dexbot stat`
|
|
51
|
+
* prints a process table) start the probe, do their work, and flush the
|
|
52
|
+
* verdict when it lands. Nothing is printed speculatively and nothing is
|
|
53
|
+
* ever truncated by an early `process.exit()`.
|
|
54
|
+
* 4b. ONE IMPLEMENTATION. Every consumer (`unlock`, `pm2`, `dexbot stat`) goes
|
|
55
|
+
* through this module — `startVersionStatusCheck` / `startStagedVersionStatus`
|
|
56
|
+
* → `printVersionStatus`; the colour of the status line, the hint wording
|
|
57
|
+
* and the latch all live here, so no caller can drift from another.
|
|
58
|
+
* 5. SILENT WHEN DISABLED. `Config.DEXBOT_SKIP_VERSION_NOTICE=1` (tests, CI,
|
|
59
|
+
* automation) or `UPDATER.NOTICE_ENABLED: false` short-circuits before any
|
|
60
|
+
* network or filesystem work.
|
|
61
|
+
*
|
|
62
|
+
* Cache layout mirrors `modules/node_health_cache.ts` and lives in the profiles
|
|
63
|
+
* dir (never in the package dir — npm reinstalls wipe that).
|
|
64
|
+
*/
|
|
65
|
+
import { path } from './path_api.js';
|
|
66
|
+
import { UPDATER } from './constants.js';
|
|
67
|
+
import { PATHS, isGlobalNpmPackageDir } from './paths.js';
|
|
68
|
+
import { Config } from './config.js';
|
|
69
|
+
import { hasProcess } from './env.js';
|
|
70
|
+
import { getStorage } from './storage/index.js';
|
|
71
|
+
import { writeJsonFileAtomic } from './bots_file_lock.js';
|
|
72
|
+
import { CLI_COLORS } from './cli_colors.js';
|
|
73
|
+
const storage = getStorage();
|
|
74
|
+
const { readJSON } = storage;
|
|
75
|
+
const CACHE_VERSION = 1;
|
|
76
|
+
/** Matches UPDATER.NOTICE_TIMEOUT_MS default; kept local so a malformed
|
|
77
|
+
* general.settings.json can never turn the probe into an open-ended hang. */
|
|
78
|
+
const MAX_TIMEOUT_MS = 10_000;
|
|
79
|
+
/**
|
|
80
|
+
* Minimal semver comparison for `major.minor.patch` strings.
|
|
81
|
+
* Returns negative when a < b, 0 when equal, positive when a > b.
|
|
82
|
+
*
|
|
83
|
+
* Prerelease and build metadata are stripped: `1.6.7-beta.1` and `1.6.7`
|
|
84
|
+
* compare EQUAL. That is the intended reading for an update hint — a locally
|
|
85
|
+
* built prerelease is not "older" than the published release, and comparing it
|
|
86
|
+
* as `1.6.7.1 > 1.6.7` would permanently hide real updates from anyone
|
|
87
|
+
* running a source checkout. A non-numeric segment degrades to 0 rather than
|
|
88
|
+
* producing NaN ordering.
|
|
89
|
+
*/
|
|
90
|
+
export function compareVersions(a, b) {
|
|
91
|
+
// The leading `v` is stripped because the two sources spell it
|
|
92
|
+
// differently: a GitHub release tag is `v1.6.8`, the npm dist-tag document
|
|
93
|
+
// says `1.6.8`. Without this, `v1.6.8` parsed to [0,6,8] and compared as
|
|
94
|
+
// an ancient version — a source-spelling artefact masquerading as "an
|
|
95
|
+
// update is available".
|
|
96
|
+
const parse = (v) => String(v ?? '').trim().replace(/^[vV]/, '').split(/[-+]/)[0].split('.').map((n) => parseInt(n, 10) || 0);
|
|
97
|
+
const na = parse(a);
|
|
98
|
+
const nb = parse(b);
|
|
99
|
+
const len = Math.max(na.length, nb.length);
|
|
100
|
+
for (let i = 0; i < len; i++) {
|
|
101
|
+
const va = na[i] ?? 0;
|
|
102
|
+
const vb = nb[i] ?? 0;
|
|
103
|
+
if (va !== vb)
|
|
104
|
+
return va < vb ? -1 : 1;
|
|
105
|
+
}
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
/** Classify the running install without spawning anything. */
|
|
109
|
+
export function detectInstallKind(projectRoot = PATHS.PROJECT_ROOT) {
|
|
110
|
+
if (isGlobalNpmPackageDir(projectRoot))
|
|
111
|
+
return 'npm-global';
|
|
112
|
+
try {
|
|
113
|
+
if (storage.exists(path.join(projectRoot, '.git')))
|
|
114
|
+
return 'git';
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
/* fall through to 'other' */
|
|
118
|
+
}
|
|
119
|
+
return 'other';
|
|
120
|
+
}
|
|
121
|
+
/** npm's dist-tag document: `{ "version": "1.6.8", ... }`. */
|
|
122
|
+
const NPM_EXTRACT = (body) => typeof body?.version === 'string' && body.version.trim() ? body.version.trim() : null;
|
|
123
|
+
/**
|
|
124
|
+
* GitHub's latest-release document: `{ "tag_name": "v1.6.8", ... }`. The tag
|
|
125
|
+
* is normalised (leading `v` dropped) by `compareVersions`, so the two
|
|
126
|
+
* sources are directly comparable.
|
|
127
|
+
*/
|
|
128
|
+
const GITHUB_EXTRACT = (body) => {
|
|
129
|
+
const tag = body?.tag_name ?? body?.name;
|
|
130
|
+
return typeof tag === 'string' && tag.trim() ? tag.trim() : null;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Derive the GitHub "latest release" endpoint from the configured repository
|
|
134
|
+
* URL, so a fork or a self-hosted mirror is honoured without a second hardcoded
|
|
135
|
+
* owner/repo. Returns null for anything that is not a github.com repository —
|
|
136
|
+
* a non-GitHub host has a different API shape and guessing it would produce a
|
|
137
|
+
* guaranteed-wrong request on every probe.
|
|
138
|
+
*/
|
|
139
|
+
export function deriveGithubReleaseUrl(repositoryUrl, apiBase) {
|
|
140
|
+
const raw = String(repositoryUrl ?? '').trim();
|
|
141
|
+
if (!raw)
|
|
142
|
+
return null;
|
|
143
|
+
const m = raw.match(/^https?:\/\/(?:[^@/]+@)?github\.com\/([^/]+)\/([^/#?]+?)(?:\.git)?\/?$/i);
|
|
144
|
+
if (!m)
|
|
145
|
+
return null;
|
|
146
|
+
const base = String(apiBase || 'https://api.github.com').replace(/\/+$/, '');
|
|
147
|
+
return `${base}/repos/${m[1]}/${m[2]}/releases/latest`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The probe's sources, in priority order.
|
|
151
|
+
*
|
|
152
|
+
* npm FIRST, GitHub second — measured, and the order is load-bearing:
|
|
153
|
+
*
|
|
154
|
+
* latency a wash. Warm, interleaved: npm p50 21ms / github p50 18ms.
|
|
155
|
+
* Cold process: npm 92-102ms / github 97-99ms. GitHub being
|
|
156
|
+
* ~3ms "faster" is noise, not a reason to reorder.
|
|
157
|
+
* payload npm 8KB vs github 40KB (the release document carries the
|
|
158
|
+
* body, assets and author objects). 5x for the same answer.
|
|
159
|
+
* rate limit the GitHub API is 60 requests/hour per IP unauthenticated
|
|
160
|
+
* and answers 403 when spent; npm has no comparable ceiling.
|
|
161
|
+
* Our own 12h throttle keeps us far below it, but a shared
|
|
162
|
+
* server IP or a retry burst is not ours to control.
|
|
163
|
+
* AUTHORITY the deciding one. The release pipeline creates the GitHub
|
|
164
|
+
* release FIRST and publishes to npm ~4-9 minutes LATER
|
|
165
|
+
* (1.6.8 10:15:14Z vs 10:24:00Z; 1.6.7 09:08:48 vs 09:13:15;
|
|
166
|
+
* 1.6.6 00:49:52 vs 00:54:27). GitHub-first would therefore
|
|
167
|
+
* spend that window telling operators a new version exists
|
|
168
|
+
* while `dexbot update` still installs the old one — a hint
|
|
169
|
+
* that is not merely early but wrong. npm lagging by the same
|
|
170
|
+
* minutes is harmless: it says "up to date" a little longer.
|
|
171
|
+
*
|
|
172
|
+
* The cost of this order is the one case that measurably suffers: on a host
|
|
173
|
+
* that cannot reach the registry at all, the fallback answer arrives after the
|
|
174
|
+
* first source's share of the budget is spent (~1.6s of the 3s), versus ~20ms
|
|
175
|
+
* if GitHub went first. That is the right trade — a slow answer is still an
|
|
176
|
+
* answer, and the alternative is an answer that is wrong for the first minutes
|
|
177
|
+
* of every release.
|
|
178
|
+
*/
|
|
179
|
+
export function resolveReleaseSources(options = {}) {
|
|
180
|
+
const sources = [];
|
|
181
|
+
const npmUrl = options.registryUrl !== undefined ? options.registryUrl : UPDATER?.REGISTRY_URL;
|
|
182
|
+
if (npmUrl)
|
|
183
|
+
sources.push({ id: 'npm', url: String(npmUrl), extract: NPM_EXTRACT });
|
|
184
|
+
const configured = options.githubReleaseUrl !== undefined
|
|
185
|
+
? options.githubReleaseUrl
|
|
186
|
+
: UPDATER?.GITHUB_RELEASE_URL;
|
|
187
|
+
// 'off' (any case) disables the fallback explicitly; an empty value means
|
|
188
|
+
// "derive it from the repository we already know about".
|
|
189
|
+
const disabled = typeof configured === 'string' && ['off', 'none', 'false', 'disabled'].includes(configured.trim().toLowerCase());
|
|
190
|
+
const githubUrl = disabled
|
|
191
|
+
? null
|
|
192
|
+
: (String(configured ?? '').trim() || deriveGithubReleaseUrl(options.repositoryUrl !== undefined ? options.repositoryUrl : UPDATER?.REPOSITORY_URL, options.apiBase ?? UPDATER?.GITHUB_API_BASE ?? 'https://api.github.com'));
|
|
193
|
+
if (githubUrl)
|
|
194
|
+
sources.push({ id: 'github', url: githubUrl, extract: GITHUB_EXTRACT });
|
|
195
|
+
return sources;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The single status line, shared by `dexbot stat` and every launcher start.
|
|
199
|
+
*
|
|
200
|
+
* GREEN when the install matches the published version, ORANGE when a newer
|
|
201
|
+
* release exists, GRAY when the probe could not answer (offline / throttled
|
|
202
|
+
* with no prior observation) — an unknown answer must never be rendered as
|
|
203
|
+
* "up to date". The installed version is always named, so a caller never needs
|
|
204
|
+
* a second "DEXBot2 vX.Y.Z" header of its own. The unknown verdict carries the
|
|
205
|
+
* probe's reason, because an unnamed "?" tells the operator nothing they can
|
|
206
|
+
* act on.
|
|
207
|
+
*/
|
|
208
|
+
export function formatVersionStatusLine(status) {
|
|
209
|
+
const c = CLI_COLORS;
|
|
210
|
+
const current = `DEXBot2 v${status.currentVersion}`;
|
|
211
|
+
if (status.state === 'up-to-date') {
|
|
212
|
+
return `${current} ${c.brightGreen}✓${c.reset} ${c.greenBold}Your version is up to date.${c.reset}`;
|
|
213
|
+
}
|
|
214
|
+
if (status.state === 'update-available') {
|
|
215
|
+
return `${current} ${c.orange}⬆${c.reset} ${c.orange}A new version is available: v${status.latestVersion}.${c.reset}`;
|
|
216
|
+
}
|
|
217
|
+
// The staged wait gave up: say the information is missing. Distinct from
|
|
218
|
+
// the branch below, where a probe ran and told us it failed.
|
|
219
|
+
if (status.exhausted) {
|
|
220
|
+
return `${current} ${c.gray}? No current version information (${status.reason ?? 'no answer'}).${c.reset}`;
|
|
221
|
+
}
|
|
222
|
+
const why = status.reason ? ` (${status.reason})` : '';
|
|
223
|
+
return `${current} ${c.gray}? Could not check for a newer version${why}.${c.reset}`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Hint text. `dexbot update` is the correct verb for BOTH layouts: the npm
|
|
227
|
+
* flow does `npm install -g <pkg>@<latest>`, the git flow does
|
|
228
|
+
* `fetch` + `pull` + rebuild + runtime restart. `update` is only complete
|
|
229
|
+
* once active bots have been restarted onto the new code, which a bare
|
|
230
|
+
* `git pull` in a terminal would not do.
|
|
231
|
+
*/
|
|
232
|
+
function formatVersionHint(installKind) {
|
|
233
|
+
return installKind === 'git'
|
|
234
|
+
? `Run \`dexbot update\` to pull it and restart your bots.`
|
|
235
|
+
: `Run \`dexbot update\` to install it and restart your bots.`;
|
|
236
|
+
}
|
|
237
|
+
function readCache(file) {
|
|
238
|
+
try {
|
|
239
|
+
const payload = readJSON(file);
|
|
240
|
+
if (!payload || payload.version !== CACHE_VERSION)
|
|
241
|
+
return null;
|
|
242
|
+
if (!Number.isFinite(payload.lastCheckMs))
|
|
243
|
+
return null;
|
|
244
|
+
// Reject a foreign schema rather than trusting hand-edited types: a
|
|
245
|
+
// non-string version would otherwise flow into compareVersions.
|
|
246
|
+
if (payload.latestVersion != null && typeof payload.latestVersion !== 'string')
|
|
247
|
+
return null;
|
|
248
|
+
if (payload.notifiedVersion != null && typeof payload.notifiedVersion !== 'string')
|
|
249
|
+
return null;
|
|
250
|
+
return payload;
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function writeCache(file, cache) {
|
|
257
|
+
try {
|
|
258
|
+
writeJsonFileAtomic(file, cache);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
// A read-only or full profiles dir must never fail a startup.
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function resolveTimeoutMs(override) {
|
|
265
|
+
const raw = override !== undefined ? Number(override) : Number(UPDATER?.NOTICE_TIMEOUT_MS);
|
|
266
|
+
if (!Number.isFinite(raw) || raw <= 0)
|
|
267
|
+
return 2_000;
|
|
268
|
+
return Math.min(raw, MAX_TIMEOUT_MS);
|
|
269
|
+
}
|
|
270
|
+
/** Turn a thrown fetch error into something an operator can act on. The
|
|
271
|
+
* `cause.code` is the useful part (`ENOTFOUND`, `ECONNREFUSED`,
|
|
272
|
+
* `CERT_HAS_EXPIRED`, `UND_ERR_SOCKET`); the wrapper message is noise. */
|
|
273
|
+
function describeFetchError(err, source, timeoutMs) {
|
|
274
|
+
const code = err?.cause?.code || err?.code;
|
|
275
|
+
if (code)
|
|
276
|
+
return `${source.id}: ${code}`;
|
|
277
|
+
const name = String(err?.name ?? '');
|
|
278
|
+
if (name === 'AbortError' || name === 'TimeoutError')
|
|
279
|
+
return `${source.id}: timeout after ${timeoutMs}ms`;
|
|
280
|
+
const message = String(err?.message ?? '').trim();
|
|
281
|
+
return message ? `${source.id}: ${message.split('\n')[0].slice(0, 60)}` : `${source.id}: request failed`;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Query ONE source. Resolves with a version or with a reason; never throws and
|
|
285
|
+
* never rejects, so the sequential fallback in `probeReleaseSources` cannot be
|
|
286
|
+
* short-circuited by a single bad source.
|
|
287
|
+
*/
|
|
288
|
+
async function fetchFromSource(source, timeoutMs, fetchImpl) {
|
|
289
|
+
const doFetch = fetchImpl || (typeof fetch === 'function' ? fetch : null);
|
|
290
|
+
if (!doFetch) {
|
|
291
|
+
// Node < 18 (or a stripped runtime) has no global fetch. That is a
|
|
292
|
+
// permanent, not transient, condition — say so instead of "unknown".
|
|
293
|
+
return { sourceId: source.id, version: null, reason: `${source.id}: no fetch available (Node >= 18 required)` };
|
|
294
|
+
}
|
|
295
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
296
|
+
let timedOut = false;
|
|
297
|
+
// The attempt never rejects, so racing it cannot leak an unhandled
|
|
298
|
+
// rejection. The enclosing timeout is a HARD backstop: it resolves even
|
|
299
|
+
// when no AbortController exists or a custom fetch ignores the signal, so
|
|
300
|
+
// the "never blocks startup" guarantee does not depend on either. Without
|
|
301
|
+
// it, a hung registry socket could stall a terminal `flushVersionStatus`
|
|
302
|
+
// ahead of `process.exit()` and freeze `dexbot start`.
|
|
303
|
+
const attempt = (async () => {
|
|
304
|
+
try {
|
|
305
|
+
const res = await doFetch(source.url, {
|
|
306
|
+
method: 'GET',
|
|
307
|
+
headers: { accept: 'application/json' },
|
|
308
|
+
signal: controller?.signal,
|
|
309
|
+
});
|
|
310
|
+
if (!res)
|
|
311
|
+
return { sourceId: source.id, version: null, reason: `${source.id}: empty response` };
|
|
312
|
+
if (res.ok === false)
|
|
313
|
+
return { sourceId: source.id, version: null, reason: `${source.id}: HTTP ${res.status}` };
|
|
314
|
+
const body = await res.json();
|
|
315
|
+
const version = source.extract(body);
|
|
316
|
+
if (!version)
|
|
317
|
+
return { sourceId: source.id, version: null, reason: `${source.id}: no version in response` };
|
|
318
|
+
return { sourceId: source.id, version };
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
return { sourceId: source.id, version: null, reason: describeFetchError(err, source, timeoutMs) };
|
|
322
|
+
}
|
|
323
|
+
})();
|
|
324
|
+
let timer = null;
|
|
325
|
+
const timeout = new Promise((resolve) => {
|
|
326
|
+
timer = setTimeout(() => {
|
|
327
|
+
timedOut = true;
|
|
328
|
+
try {
|
|
329
|
+
controller?.abort();
|
|
330
|
+
}
|
|
331
|
+
catch { /* best-effort cancel */ }
|
|
332
|
+
resolve({ sourceId: source.id, version: null, reason: `${source.id}: timeout after ${timeoutMs}ms` });
|
|
333
|
+
}, timeoutMs);
|
|
334
|
+
});
|
|
335
|
+
try {
|
|
336
|
+
const result = await Promise.race([attempt, timeout]);
|
|
337
|
+
// Prefer the explicit timeout verdict: an aborted fetch usually rejects
|
|
338
|
+
// with a bare "aborted", which is a much worse thing to show.
|
|
339
|
+
return timedOut ? { sourceId: source.id, version: null, reason: `${source.id}: timeout after ${timeoutMs}ms` } : result;
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
if (timer)
|
|
343
|
+
clearTimeout(timer);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Try the sources in order and take the first answer. The total budget is split
|
|
348
|
+
* EVENLY rather than spent first-come: a source that hangs until the deadline
|
|
349
|
+
* would otherwise leave the fallback with no time at all, which is precisely
|
|
350
|
+
* the case the fallback exists for.
|
|
351
|
+
*/
|
|
352
|
+
export async function probeReleaseSources(sources, timeoutMs, fetchImpl) {
|
|
353
|
+
if (!sources.length)
|
|
354
|
+
return { version: null, reasons: ['no version source configured'] };
|
|
355
|
+
const perSource = Math.max(1, Math.floor(timeoutMs / sources.length));
|
|
356
|
+
const reasons = [];
|
|
357
|
+
for (const source of sources) {
|
|
358
|
+
const result = await fetchFromSource(source, perSource, fetchImpl);
|
|
359
|
+
if (result.version)
|
|
360
|
+
return { version: result.version, source: result.sourceId, reasons };
|
|
361
|
+
if (result.reason)
|
|
362
|
+
reasons.push(result.reason);
|
|
363
|
+
}
|
|
364
|
+
return { version: null, reasons };
|
|
365
|
+
}
|
|
366
|
+
/** Assemble a status; `includeNotice` is false on the throttled path, which
|
|
367
|
+
* reports the cached observation but never re-announces. */
|
|
368
|
+
function buildVersionStatus(currentVersion, latestVersion, installKind, cacheFile, includeNotice, extra = {}) {
|
|
369
|
+
const state = !latestVersion
|
|
370
|
+
? 'unknown'
|
|
371
|
+
: compareVersions(currentVersion, latestVersion) < 0 ? 'update-available' : 'up-to-date';
|
|
372
|
+
const notice = state === 'update-available' && includeNotice && latestVersion
|
|
373
|
+
? { currentVersion, latestVersion, installKind, cacheFile }
|
|
374
|
+
: null;
|
|
375
|
+
return { currentVersion, latestVersion, installKind, state, cacheFile, notice, ...extra };
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* How long a cached observation stays valid. A SUCCESS is worth a full
|
|
379
|
+
* `UPDATER.NOTICE_INTERVAL_MS` (12h): the published version does not move under
|
|
380
|
+
* us, and every run consults this cache before spending a request. A FAILURE is
|
|
381
|
+
* re-tried after `UPDATER.NOTICE_RETRY_MS` — throttling a failure for the full
|
|
382
|
+
* success window is what turned one 5s network hiccup into a permanent
|
|
383
|
+
* "could not check", with no retry left to disprove it.
|
|
384
|
+
*/
|
|
385
|
+
function resolveThrottleMs(previous, options) {
|
|
386
|
+
// `NOTICE_INTERVAL_MS: 0` is the documented "check on every start" opt-in.
|
|
387
|
+
// It must disable BOTH windows: leaving the failure backoff in force would
|
|
388
|
+
// silently throttle exactly the case an operator turned throttling off to
|
|
389
|
+
// diagnose.
|
|
390
|
+
if (options.intervalMs === 0 || options.retryMs === 0)
|
|
391
|
+
return 0;
|
|
392
|
+
if (Number(UPDATER?.NOTICE_INTERVAL_MS ?? 0) === 0)
|
|
393
|
+
return 0;
|
|
394
|
+
const failed = !previous || previous.latestVersion == null;
|
|
395
|
+
const override = failed ? options.retryMs : options.intervalMs;
|
|
396
|
+
if (override !== undefined)
|
|
397
|
+
return Math.max(0, Number(override) || 0);
|
|
398
|
+
const configured = failed
|
|
399
|
+
? Number(UPDATER?.NOTICE_RETRY_MS ?? 0)
|
|
400
|
+
: Number(UPDATER?.NOTICE_INTERVAL_MS ?? 0);
|
|
401
|
+
return Number.isFinite(configured) ? configured : 0;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Start the check. Resolves with the installed-vs-published status, plus a
|
|
405
|
+
* `notice` when a NEWER version exists and that version has not been
|
|
406
|
+
* announced yet. Resolves null only when the whole feature is switched off.
|
|
407
|
+
* Rejects never.
|
|
408
|
+
*/
|
|
409
|
+
export function startVersionStatusCheck(options = {}) {
|
|
410
|
+
// Every early return is a resolved null so callers can always await.
|
|
411
|
+
const done = (value) => Promise.resolve(value ?? null);
|
|
412
|
+
if (!hasProcess())
|
|
413
|
+
return done(null);
|
|
414
|
+
if (Config.DEXBOT_SKIP_VERSION_NOTICE)
|
|
415
|
+
return done(null);
|
|
416
|
+
const noticeEnabled = options.enabled ?? UPDATER?.NOTICE_ENABLED !== false;
|
|
417
|
+
if (!noticeEnabled)
|
|
418
|
+
return done(null);
|
|
419
|
+
const cacheFile = options.cacheFile || PATHS.PROFILES.VERSION_CHECK_JSON;
|
|
420
|
+
const now = options.now ?? Date.now();
|
|
421
|
+
const previous = readCache(cacheFile);
|
|
422
|
+
// `??` (not `||`) so an explicitly empty current version is reported as
|
|
423
|
+
// "unknown" and stays silent rather than falling back to a real version.
|
|
424
|
+
const currentVersion = options.currentVersion ?? Config.VERSION;
|
|
425
|
+
if (!currentVersion)
|
|
426
|
+
return done(null);
|
|
427
|
+
const sources = resolveReleaseSources({
|
|
428
|
+
...(options.registryUrl !== undefined ? { registryUrl: options.registryUrl } : {}),
|
|
429
|
+
...(options.githubReleaseUrl !== undefined ? { githubReleaseUrl: options.githubReleaseUrl } : {}),
|
|
430
|
+
});
|
|
431
|
+
if (!sources.length) {
|
|
432
|
+
// No source configured — do not even write a cache entry, so
|
|
433
|
+
// enabling it later takes effect on the very next start.
|
|
434
|
+
return done(null);
|
|
435
|
+
}
|
|
436
|
+
const installKind = options.installKind || detectInstallKind();
|
|
437
|
+
// Throttle: a recent probe means stay quiet, so a node never pays the
|
|
438
|
+
// network timeout on every single restart. The cached observation still
|
|
439
|
+
// answers "am I current?" without spending a request — including when the
|
|
440
|
+
// cached observation is a failure, which is rendered WITH its reason.
|
|
441
|
+
const force = options.force ?? Config.DEXBOT_VERSION_CHECK_FORCE;
|
|
442
|
+
const throttleMs = resolveThrottleMs(previous, options);
|
|
443
|
+
if (!force && throttleMs > 0 && previous) {
|
|
444
|
+
if (now - previous.lastCheckMs < throttleMs) {
|
|
445
|
+
return done(buildVersionStatus(currentVersion, previous.latestVersion, installKind, cacheFile, false, {
|
|
446
|
+
source: previous.source,
|
|
447
|
+
reason: previous.latestVersion == null ? previous.lastError : undefined,
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return (async () => {
|
|
452
|
+
const probe = await probeReleaseSources(sources, resolveTimeoutMs(options.timeoutMs), options.fetchImpl);
|
|
453
|
+
const reason = probe.version ? undefined : (probe.reasons.join('; ') || 'probe failed');
|
|
454
|
+
// Record the observation but DO NOT latch here: `notifiedVersion` is
|
|
455
|
+
// advanced by `printVersionStatus` only once the hint is displayed.
|
|
456
|
+
const base = {
|
|
457
|
+
version: CACHE_VERSION,
|
|
458
|
+
updatedAt: new Date(now).toISOString(),
|
|
459
|
+
lastCheckMs: now,
|
|
460
|
+
latestVersion: probe.version ?? null,
|
|
461
|
+
notifiedVersion: previous?.notifiedVersion ?? null,
|
|
462
|
+
source: probe.source ?? previous?.source,
|
|
463
|
+
lastError: reason,
|
|
464
|
+
};
|
|
465
|
+
writeCache(cacheFile, base);
|
|
466
|
+
const status = buildVersionStatus(currentVersion, probe.version, installKind, cacheFile, true, {
|
|
467
|
+
source: probe.source,
|
|
468
|
+
reason,
|
|
469
|
+
});
|
|
470
|
+
// Same version already announced: keep reporting the state, drop only
|
|
471
|
+
// the one-time hint.
|
|
472
|
+
if (status.notice && previous?.notifiedVersion === status.notice.latestVersion) {
|
|
473
|
+
return { ...status, notice: null };
|
|
474
|
+
}
|
|
475
|
+
return status;
|
|
476
|
+
})().catch(() => null);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Advance the notify-once latch for a notice that was actually displayed.
|
|
480
|
+
* Separate from the probe so a notice the caller never surfaces cannot be
|
|
481
|
+
* silently consumed — the next launcher run re-offers it. The latch only ever
|
|
482
|
+
* moves forward, so a registry that briefly serves an older `latest`
|
|
483
|
+
* (dist-tag rollback) cannot make an already-announced version reappear.
|
|
484
|
+
*/
|
|
485
|
+
function latchVersionNotice(notice) {
|
|
486
|
+
try {
|
|
487
|
+
const existing = readCache(notice.cacheFile);
|
|
488
|
+
const announced = existing?.notifiedVersion ?? null;
|
|
489
|
+
if (announced && compareVersions(announced, notice.latestVersion) >= 0)
|
|
490
|
+
return;
|
|
491
|
+
const next = {
|
|
492
|
+
version: CACHE_VERSION,
|
|
493
|
+
updatedAt: existing?.updatedAt ?? new Date().toISOString(),
|
|
494
|
+
lastCheckMs: existing?.lastCheckMs ?? 0,
|
|
495
|
+
latestVersion: existing?.latestVersion ?? notice.latestVersion,
|
|
496
|
+
notifiedVersion: notice.latestVersion,
|
|
497
|
+
// Diagnostics survive the latch, so a later throttled run can still
|
|
498
|
+
// name the source that answered / why the last probe failed.
|
|
499
|
+
source: existing?.source,
|
|
500
|
+
lastError: existing?.lastError,
|
|
501
|
+
};
|
|
502
|
+
writeCache(notice.cacheFile, next);
|
|
503
|
+
}
|
|
504
|
+
catch {
|
|
505
|
+
// Best-effort: a read-only profiles dir must never fail a startup.
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Print the status line (plus the install hint when a NEW, unannounced
|
|
510
|
+
* version exists) and commit the notify-once latch for that hint. The single
|
|
511
|
+
* print path for every caller, so latching cannot drift from display.
|
|
512
|
+
*/
|
|
513
|
+
export function printVersionStatus(status, options = {}) {
|
|
514
|
+
if (!status)
|
|
515
|
+
return;
|
|
516
|
+
const c = CLI_COLORS;
|
|
517
|
+
const indent = options.indent ?? ' ';
|
|
518
|
+
const surround = options.surround !== false;
|
|
519
|
+
if (surround)
|
|
520
|
+
console.log();
|
|
521
|
+
console.log(`${indent}${formatVersionStatusLine(status)}`);
|
|
522
|
+
if (status.notice) {
|
|
523
|
+
console.log(`${indent} ${c.gray}${formatVersionHint(status.installKind)}${c.reset}`);
|
|
524
|
+
latchVersionNotice(status.notice);
|
|
525
|
+
}
|
|
526
|
+
if (surround)
|
|
527
|
+
console.log();
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* The entry-point renderer: the status line when there is one, the bare
|
|
531
|
+
* installed-version header when the check is switched off.
|
|
532
|
+
*
|
|
533
|
+
* `printVersionStatus(null)` is a deliberate no-op, which is right for a
|
|
534
|
+
* caller that only wants the line — but every CLI entry point must still name
|
|
535
|
+
* the running build when the notice is disabled
|
|
536
|
+
* (`DEXBOT_SKIP_VERSION_NOTICE=1` / `UPDATER.NOTICE_ENABLED=false`), and
|
|
537
|
+
* re-implementing that fallback per entry point is how they drift: `dexbot
|
|
538
|
+
* stat` had it, `dexbot pm2` did not, so a node with the notice off learned its
|
|
539
|
+
* version from one command and not the other. One helper, one behaviour.
|
|
540
|
+
*/
|
|
541
|
+
export function printVersionStatusOrHeader(status, options = {}) {
|
|
542
|
+
if (status) {
|
|
543
|
+
printVersionStatus(status, options);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const indent = options.indent ?? ' ';
|
|
547
|
+
if (options.surround !== false)
|
|
548
|
+
console.log();
|
|
549
|
+
console.log(`${indent}DEXBot2 v${Config.VERSION}`);
|
|
550
|
+
if (options.surround !== false)
|
|
551
|
+
console.log();
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Await an already-started check and print its status. The single flush path
|
|
555
|
+
* for callers (`unlock.ts`, `pm2.ts`) that start the probe early and surface it
|
|
556
|
+
* only at a terminal point, so the await+print pair is not reimplemented per
|
|
557
|
+
* call site.
|
|
558
|
+
*/
|
|
559
|
+
export async function flushVersionStatus(pending) {
|
|
560
|
+
printVersionStatus(await pending);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* The flush counterpart of `printVersionStatusOrHeader`, for callers that start
|
|
564
|
+
* the probe early and surface it at a terminal point (`unlock.ts`, `pm2.ts`).
|
|
565
|
+
* A null status is the "check switched off" signal, so the installed version is
|
|
566
|
+
* still named - the same single behaviour the stat path gets.
|
|
567
|
+
*/
|
|
568
|
+
export async function flushVersionStatusOrHeader(pending) {
|
|
569
|
+
printVersionStatusOrHeader(await pending);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Print the status when the probe settles, WITHOUT awaiting it. For launch
|
|
573
|
+
* paths that must never delay the bot start — the resident process outlives the
|
|
574
|
+
* probe, so there is no `process.exit()` to truncate it.
|
|
575
|
+
*
|
|
576
|
+
* Uses the header-aware renderer: an entry point must name the running build
|
|
577
|
+
* even when the check is switched off, and this is the non-awaited form of the
|
|
578
|
+
* same contract as `flushVersionStatusOrHeader`.
|
|
579
|
+
*/
|
|
580
|
+
export function printVersionStatusWhenReady(pending) {
|
|
581
|
+
void pending.then(printVersionStatusOrHeader, () => { });
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Race `promise` against `ms`. Resolves `{ hit: true, value }` when the
|
|
585
|
+
* promise wins and `{ hit: false }` when the timer does. The timer is always
|
|
586
|
+
* cleared once the promise wins, so a fast answer never leaves a pending timer
|
|
587
|
+
* behind — and nothing is unref'd, because a test awaiting `settled` must not
|
|
588
|
+
* have the process exit from under it.
|
|
589
|
+
*/
|
|
590
|
+
function settleWithin(promise, ms) {
|
|
591
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
592
|
+
return promise.then((value) => ({ hit: true, value }), () => ({ hit: false }));
|
|
593
|
+
}
|
|
594
|
+
return new Promise((resolve) => {
|
|
595
|
+
let done = false;
|
|
596
|
+
const timer = setTimeout(() => {
|
|
597
|
+
if (done)
|
|
598
|
+
return;
|
|
599
|
+
done = true;
|
|
600
|
+
resolve({ hit: false });
|
|
601
|
+
}, ms);
|
|
602
|
+
promise.then((value) => {
|
|
603
|
+
if (done)
|
|
604
|
+
return;
|
|
605
|
+
done = true;
|
|
606
|
+
clearTimeout(timer);
|
|
607
|
+
resolve({ hit: true, value });
|
|
608
|
+
}, () => {
|
|
609
|
+
if (done)
|
|
610
|
+
return;
|
|
611
|
+
done = true;
|
|
612
|
+
clearTimeout(timer);
|
|
613
|
+
resolve({ hit: false });
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function resolveGraceMs(override) {
|
|
618
|
+
const raw = override !== undefined ? Number(override) : Number(UPDATER?.NOTICE_STAGE_GRACE_MS);
|
|
619
|
+
if (!Number.isFinite(raw) || raw <= 0)
|
|
620
|
+
return 1_000;
|
|
621
|
+
return Math.min(raw, MAX_TIMEOUT_MS);
|
|
622
|
+
}
|
|
623
|
+
/** Budget for the final re-probe; falls back to the launcher default so a
|
|
624
|
+
* malformed settings file cannot turn it into an open-ended hang. */
|
|
625
|
+
function resolveFinalTimeoutMs(override, inherited) {
|
|
626
|
+
const raw = override !== undefined
|
|
627
|
+
? Number(override)
|
|
628
|
+
: inherited !== undefined
|
|
629
|
+
? Number(inherited)
|
|
630
|
+
: Number(UPDATER?.NOTICE_STATUS_TIMEOUT_MS ?? UPDATER?.NOTICE_TIMEOUT_MS);
|
|
631
|
+
if (!Number.isFinite(raw) || raw <= 0)
|
|
632
|
+
return 3_000;
|
|
633
|
+
return Math.min(raw, MAX_TIMEOUT_MS);
|
|
634
|
+
}
|
|
635
|
+
/** The explicit "we have no version information" verdict. Distinct from a
|
|
636
|
+
* probe that RAN and failed: here nothing answered at all, and the operator
|
|
637
|
+
* is told the information is missing rather than that the check failed. */
|
|
638
|
+
function buildExhaustedStatus(currentVersion, installKind, cacheFile, sourceLabels, budgetMs) {
|
|
639
|
+
const who = sourceLabels.length ? sourceLabels.join(' / ') : 'the release sources';
|
|
640
|
+
return buildVersionStatus(currentVersion, null, installKind, cacheFile, false, {
|
|
641
|
+
exhausted: true,
|
|
642
|
+
reason: `${who} did not answer within ${budgetMs}ms`,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* The one wording a staged caller shows for "we still do not know".
|
|
647
|
+
*
|
|
648
|
+
* Without this, `dexbot stat` could end on either "could not check
|
|
649
|
+
* (npm: timeout after 2000ms)" or "no current version information" depending
|
|
650
|
+
* on whether the forced re-probe happened to return a failed status or simply
|
|
651
|
+
* never answered. Both are honest, but the operator reads them as two
|
|
652
|
+
* different problems, and neither states what matters after the full
|
|
653
|
+
* escalation: the answer is MISSING. A caller that escalated has waited, so it
|
|
654
|
+
* says so; the inline launcher path, which never escalated, keeps the more
|
|
655
|
+
* specific "could not check (reason)".
|
|
656
|
+
*/
|
|
657
|
+
function asExhausted(status) {
|
|
658
|
+
if (!status || status.exhausted || status.state !== 'unknown')
|
|
659
|
+
return status;
|
|
660
|
+
return { ...status, exhausted: true };
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Start the probe and expose the two moments described above. The first probe
|
|
664
|
+
* is started immediately; `quick` settles within the grace period and `settled`
|
|
665
|
+
* carries the whole escalation.
|
|
666
|
+
*/
|
|
667
|
+
export function startStagedVersionStatus(options = {}) {
|
|
668
|
+
const { graceMs, finalMs, ...probeOptions } = options;
|
|
669
|
+
const grace = resolveGraceMs(graceMs);
|
|
670
|
+
const budget = resolveFinalTimeoutMs(finalMs, probeOptions.timeoutMs);
|
|
671
|
+
// `tracked` records that the FIRST probe reached a verdict of its own
|
|
672
|
+
// (including "the feature is off", which resolves immediately), so the
|
|
673
|
+
// escalation below can tell "no answer yet" from "nothing to report".
|
|
674
|
+
let firstSettled = false;
|
|
675
|
+
const first = startVersionStatusCheck({ ...probeOptions, timeoutMs: budget });
|
|
676
|
+
const tracked = first.then((value) => { firstSettled = true; return value; }, () => { firstSettled = true; return null; });
|
|
677
|
+
const quick = settleWithin(tracked, grace).then((r) => (r.hit ? r.value ?? null : null));
|
|
678
|
+
const settled = (async () => {
|
|
679
|
+
// 1) Landed during the top-of-command grace (or the cache answered).
|
|
680
|
+
const early = await settleWithin(tracked, grace);
|
|
681
|
+
if (early.hit)
|
|
682
|
+
return asExhausted(early.value ?? null);
|
|
683
|
+
// 2) End of the report: one more grace period for the in-flight probe.
|
|
684
|
+
const late = await settleWithin(tracked, grace);
|
|
685
|
+
if (late.hit)
|
|
686
|
+
return asExhausted(late.value ?? null);
|
|
687
|
+
// 3) Nothing yet. A disabled feature always resolves instantly, so
|
|
688
|
+
// still being in flight here means the probe is genuinely slow or
|
|
689
|
+
// the network is broken — ask once more, ignoring the throttle (a
|
|
690
|
+
// cached FAILURE would otherwise be re-reported for the whole
|
|
691
|
+
// retry backoff without a single request being made).
|
|
692
|
+
const retry = settleWithin(startVersionStatusCheck({ ...probeOptions, timeoutMs: budget, force: true }), budget);
|
|
693
|
+
const retried = await retry;
|
|
694
|
+
if (retried.hit) {
|
|
695
|
+
// A null here can only mean the feature was switched off between
|
|
696
|
+
// the two probes; honour it rather than inventing a verdict.
|
|
697
|
+
if (retried.value)
|
|
698
|
+
return asExhausted(retried.value);
|
|
699
|
+
if (firstSettled)
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
return buildExhaustedStatus(probeOptions.currentVersion ?? Config.VERSION, probeOptions.installKind || detectInstallKind(), probeOptions.cacheFile || PATHS.PROFILES.VERSION_CHECK_JSON, resolveReleaseSources({
|
|
703
|
+
...(probeOptions.registryUrl !== undefined ? { registryUrl: probeOptions.registryUrl } : {}),
|
|
704
|
+
...(probeOptions.githubReleaseUrl !== undefined ? { githubReleaseUrl: probeOptions.githubReleaseUrl } : {}),
|
|
705
|
+
}).map((s) => s.id), budget);
|
|
706
|
+
})().catch(() => null);
|
|
707
|
+
return { quick, settled };
|
|
708
|
+
}
|
|
709
|
+
//# sourceMappingURL=version_notice.js.map
|