Skip to content

Add TCP transport, migrate to tracing logging, and harden CLI flag parsing#43

Open
taweili wants to merge 20 commits into
jackwener:mainfrom
taweili:main
Open

Add TCP transport, migrate to tracing logging, and harden CLI flag parsing#43
taweili wants to merge 20 commits into
jackwener:mainfrom
taweili:main

Conversation

@taweili
Copy link
Copy Markdown

@taweili taweili commented May 13, 2026

感谢那么好的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! to tracing with RUST_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=ADDR flag 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 with tracing macros (info!/warn!/error!/debug!)
┃ - #[tracing::instrument] on key paths: daemon startup, queries, crypto decrypt
┃ - Default log level: info (upgrade via RUST_LOG)
┃ - User-facing CLI output (println!) and test/progress output (eprintln!) preserved

┃ ### Bug Fixes
┃ - --tcp now requires = syntax (--tcp=ADDR) to prevent subcommand collision
┃ - Global --tcp properly passed through to daemon start as fallback
┃ - Fixed unterminated char literal ('\'''\\')
┃ - Added missing cli_dir creation in start_daemon
┃ - Each incoming daemon request logged at info level for diagnostics

taweili added 20 commits May 13, 2026 13:46
- 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
- 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
- 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.
@taweili taweili mentioned this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant