Add TCP transport, migrate to tracing logging, and harden CLI flag parsing#43
Open
taweili wants to merge 20 commits into
Open
Add TCP transport, migrate to tracing logging, and harden CLI flag parsing#43taweili wants to merge 20 commits into
taweili wants to merge 20 commits into
Conversation
- src/transport/mod.rs - src/main.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S01 - Task: T01 - Created transport module with object-safe Listener/Connector traits, generic handle_connection, and TcpListener/TcpConnector implementations GSD-Task: S01/T01
- src/daemon/server.rs - src/daemon/mod.rs - src/cli/daemon_cmd.rs - src/cli/mod.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S01 - Task: T02 - Wired transport module into daemon server, added TCP listening alongside local transport, and implemented `wx daemon start [--tcp ADDR]` subcommand GSD-Task: S01/T02
- src/cli/mod.rs - src/cli/transport.rs - src/cli/daemon_cmd.rs - src/cli/sessions.rs - src/cli/history.rs - src/cli/search.rs - src/cli/contacts.rs - src/cli/export.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S02 - Task: T01 - Added global --tcp CLI flag and wired TCP transport with 15s connect/120s read-write timeouts, no silent fallback GSD-Task: S02/T01
- src/cli/daemon_cmd.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S02 - Task: T02 - Wired --tcp into daemon stop command with manual-stop warning; status already reports TCP vs local GSD-Task: S02/T02
- (none) GSD context: - Milestone: M001 - TCP Transport - Slice: S02 - Task: T03 - All changes compile on native and Windows targets; 32 unit tests pass including new TCP transport tests GSD-Task: S02/T03
- src/cli/transport.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S03 - Task: T01 - Added 3 integration tests (round-trip, connection refused, liveness check) exercising send_tcp() and is_alive_tcp() against a mock TCP server GSD-Task: S03/T01
- src/cli/transport.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S04 - Task: T01 - Added real TCP daemon integration tests that spawn the actual wx binary, connect via TCP, verify ping round-trip, and test connection refused GSD-Task: S04/T01
- src/cli/transport.rs GSD context: - Milestone: M001 - TCP Transport - Slice: S04 - Task: T02 - Added TCP vs local transport data comparison test that queries sessions via both transports and asserts deep equality GSD-Task: S04/T02
GSD-Unit: M001
GSD-Unit: M001
GSD-Unit: m001
- Add tracing + tracing-subscriber dependencies
- Initialize tracing in main() with env-filter (RUST_LOG support)
- Replace all eprintln! diagnostic messages with tracing macros:
- info! for lifecycle events (daemon startup, cache hits, scan progress)
- warn! for non-fatal errors (skipped DBs, scan limits, connection errors)
- error! for fatal errors (daemon startup failure)
- debug! for cache hits (hidden behind RUST_LOG=debug)
- Add #[tracing::instrument] to key paths:
- daemon::start_daemon — automatic startup timing
- query::{sessions, history, search, new_messages} — per-query timing
- crypto::full_decrypt — per-decrypt timing with page count
- Keep println! for user-facing CLI output (YAML/JSON, status messages)
- Keep eprintln! for test output and CLI progress indicators
# Conflicts: # .gitignore
GSD-Unit: Q3
- Fix '\'' -> '\\' in src/daemon/mod.rs (lines 85, 151) - Replace undefined preflight_cli_dir_writable() with inline config::cli_dir() creation check in src/cli/transport.rs
Add info!(cmd = ?req, "收到请求") in handle_connection so each incoming request is logged with its full Request variant for diagnostics.
--tcp consumed the following subcommand as its value (e.g. 'wx --tcp daemon start' parsed --tcp=daemon). Adding require_equals=true forces --tcp=ADDR syntax so subcommands are parsed correctly.
DaemonCommands::Start had its own --tcp subcommand flag, so 'wx --tcp=ADDR daemon start' ignored the global --tcp and started the daemon with no TCP listener. Now the global --tcp is used as fallback when the subcommand flag is absent.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
感谢那么好的CLI,我的Hermes跑在WSL,微信在Windows上,加了一个TCP的链接让两个环境可以沟通。
Summary
┃
┃ This PR delivers two major features and a round of bug fixes:
┃
┃ 1. TCP Transport — CLI can now connect to the daemon over TCP via
--tcp=ADDR┃ 2. Structured Logging — All diagnostic output migrated from
eprintln!totracingwithRUST_LOG┃ support
┃ 3. Bug Fixes — Flag parsing collision, missing CLI dir, and char literal fixes
┃
┃ ## Changes
┃
┃ ### TCP Transport (
M001)┃ -
wx daemon start [--tcp ADDR]— daemon listens on TCP alongside local transport┃ - Global
--tcp=ADDRflag wired into all subcommands (sessions, history, search, contacts, export, daemon┃ stop)
┃ - 15s connect / 120s read-write timeouts, no silent fallback
┃ - 3 integration tests: round-trip ping, connection refused, liveness check
┃ - Real daemon integration tests spawning actual wx binary
┃ - TCP vs local transport data comparison test (deep equality on sessions)
┃ - All changes compile on native and Windows targets; 32 unit tests pass
┃
┃ ### Structured Logging
┃ - Replaced all
eprintln!diagnostic messages withtracingmacros (info!/warn!/error!/debug!)┃ -
#[tracing::instrument]on key paths: daemon startup, queries, crypto decrypt┃ - Default log level:
info(upgrade viaRUST_LOG)┃ - User-facing CLI output (
println!) and test/progress output (eprintln!) preserved┃
┃ ### Bug Fixes
┃ -
--tcpnow requires=syntax (--tcp=ADDR) to prevent subcommand collision┃ - Global
--tcpproperly passed through todaemon startas fallback┃ - Fixed unterminated char literal (
'\''→'\\')┃ - Added missing
cli_dircreation instart_daemon┃ - Each incoming daemon request logged at info level for diagnostics