Skip to content

feat(chat-cli): wire up logos-delivery transport and switch to client API#91

Merged
osmaczko merged 1 commit intomainfrom
feat/client-with-waku
Apr 27, 2026
Merged

feat(chat-cli): wire up logos-delivery transport and switch to client API#91
osmaczko merged 1 commit intomainfrom
feat/client-with-waku

Conversation

@osmaczko
Copy link
Copy Markdown
Contributor

@osmaczko osmaczko commented Apr 17, 2026

Replace the direct use of conversations::Context with client::ChatClient,
which is the intended public API for library consumers.

Remove MessageEnvelope and the username-keyed session model. The envelope
was never part of the wire protocol — sender identity was only tracked in the
CLI's local state. Chats are now keyed by conversation ID; add /nickname as
the user-facing replacement for named sessions.

Add a logos-delivery (Waku) transport alongside the existing file transport.
The active transport is selected at compile time: set LOGOS_DELIVERY_LIB_DIR
to link liblogosdelivery, otherwise the file transport is used.

Add logos-delivery as a Nix flake input and expose .#logos-delivery so the
library can be built with nix build and referenced by LOGOS_DELIVERY_LIB_DIR.

CI: rename c-ffi-smoketest to smoketest; add logos-delivery build step
and a --smoketest invocation of chat-cli to verify startup.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new chat-cli workspace crate that serves as an end-to-end example application for libchat, using logos-delivery (Waku-based) as the transport and ratatui/crossterm for a terminal UI.

Changes:

  • Introduces a chat-cli binary with a synchronous TUI event loop for sending/receiving messages.
  • Implements a DeliveryService backed by an embedded logos-delivery node via FFI + a background thread.
  • Adds build/docs tooling (Makefile targets, build.rs linking via LOGOS_DELIVERY_LIB_DIR, README updates) and wires the new crate into the workspace.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/chat-cli/src/tui/render.rs New TUI rendering for message list + input bar and cursor placement.
crates/chat-cli/src/tui/mod.rs New TUI state + main loop integrating keyboard input and inbound message draining.
crates/chat-cli/src/main.rs New CLI entrypoint wiring ChatClient to LogosDeliveryService, logging, and TUI startup.
crates/chat-cli/src/delivery/mod.rs New DeliveryService implementation that runs a logos-delivery node on a background thread and fans out inbound payloads.
crates/chat-cli/src/delivery/sys.rs Raw FFI declarations + trampoline for callbacks into Rust closures.
crates/chat-cli/src/delivery/wrapper.rs “Safe synchronous” wrapper around the raw FFI calls + Drop-based shutdown.
crates/chat-cli/build.rs Links liblogosdelivery (and rpath) when LOGOS_DELIVERY_LIB_DIR is provided.
crates/chat-cli/README.md End-user build/run/test documentation for the example app and logos-delivery dependency.
crates/chat-cli/Cargo.toml New crate manifest and dependencies for TUI/CLI/FFI glue.
README.md Root README updated to point to crates/chat-cli as an example app.
Makefile Adds top-level build helpers (clone/build logos-delivery, build chat-cli, check/test targets).
Cargo.toml Adds crates/chat-cli to workspace members.
Cargo.lock Locks new dependencies brought in by chat-cli.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/chat-cli/src/tui/render.rs Outdated
Comment thread crates/chat-cli/src/tui/mod.rs Outdated
Comment thread crates/chat-cli/src/delivery/mod.rs Outdated
Comment thread crates/chat-cli/src/main.rs Outdated
Comment thread crates/chat-cli/Cargo.toml Outdated
Comment thread bin/chat-cli/src/transport/logos_delivery.rs
@osmaczko osmaczko force-pushed the feat/client-with-waku branch 2 times, most recently from 1c6aa74 to 90a77f7 Compare April 21, 2026 14:11
@osmaczko osmaczko marked this pull request as ready for review April 21, 2026 14:12
@osmaczko osmaczko force-pushed the feat/client-with-waku branch 2 times, most recently from f50a7f7 to 5b4684e Compare April 21, 2026 14:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an example chat-cli binary that can run either on a local file-based transport or (when built with LOGOS_DELIVERY_LIB_DIR) on a logos-delivery (Waku) transport, and wires it into Nix + CI for a basic smoketest.

Changes:

  • Add a logos-delivery-backed client::DeliveryService implementation (FFI + wrapper) and a new file transport compatible with client::ChatClient.
  • Refactor chat-cli to use client::ChatClient, add clap CLI args, and update the TUI/session model (nicknames, scrolling).
  • Extend Nix flake + GitHub Actions CI to build logos-delivery and build/run chat-cli smoketest.

Reviewed changes

Copilot reviewed 12 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
flake.nix Adds logos-delivery input and a patched package output for CI/build usage
flake.lock Locks logos-delivery (and its dependency graph) for Nix builds
bin/chat-cli/src/ui.rs Makes UI generic over transport, updates headers, wrapping, and scrolling behavior
bin/chat-cli/src/transport/logos_delivery/wrapper.rs Safe-ish synchronous wrapper around raw logos-delivery FFI
bin/chat-cli/src/transport/logos_delivery/sys.rs Raw extern declarations + callback trampoline
bin/chat-cli/src/transport/logos_delivery.rs Implements DeliveryService using an embedded node thread + JSON event parsing
bin/chat-cli/src/transport/file.rs New file transport that publishes length-prefixed frames and polls for inbound frames
bin/chat-cli/src/transport.rs Switches transport modules via cfg(logos_delivery)
bin/chat-cli/src/main.rs Adds clap CLI, compile-time transport selection, logging setup, and smoketest mode
bin/chat-cli/src/app.rs Refactors app state around client::ChatClient, conversations by id, nicknames, command output
bin/chat-cli/build.rs Links liblogosdelivery and sets rpath when LOGOS_DELIVERY_LIB_DIR is set
bin/chat-cli/README.md Updates build/run docs for both transports and new CLI flags
bin/chat-cli/Cargo.toml Adds dependencies needed for the new client/transports and cfg linting
README.md Mentions bin/chat-cli as an example app and provides quick build/run snippet
Cargo.lock Updates lockfile for new dependencies (clap, tracing, base64, etc.)
.github/workflows/ci.yml Adds Nix install + builds logos-delivery + builds/runs chat-cli smoketest
Comments suppressed due to low confidence (1)

bin/chat-cli/src/ui.rs:120

  • content.split_at(first_line_width) uses a byte index derived from terminal cell width. If msg.content contains non-ASCII UTF-8, this can panic because split_at requires a char boundary (and even if it doesn’t panic, byte length != display width). Prefer splitting on char_indices() / grapheme clusters and measuring display width (e.g., unicode_width) instead of raw len() bytes.
            let mut items = Vec::new();
            let first_line_width = inner_width.saturating_sub(prefix_len).max(1);

            // First line includes the prefix.
            let (first_chunk, rest): (&str, &str) = if content.len() <= first_line_width {
                (content.as_str(), "")
            } else {
                content.split_at(first_line_width)
            };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bin/chat-cli/src/transport/logos_delivery.rs Outdated
Comment thread bin/chat-cli/build.rs
Comment thread flake.nix Outdated
Comment thread bin/chat-cli/src/ui.rs
Comment thread bin/chat-cli/src/app.rs
@osmaczko osmaczko changed the title feat: add chat-cli example with logos-delivery feat(chat-cli): wire up logos-delivery transport and switch to client API Apr 21, 2026
@jazzz jazzz requested a review from Ivansete-status April 21, 2026 15:47
@osmaczko osmaczko force-pushed the feat/client-with-waku branch 5 times, most recently from 9382bc2 to 7f7bcc0 Compare April 21, 2026 20:51
Comment thread README.md Outdated
Comment thread README.md
Comment thread README.md
Comment thread bin/chat-cli/Cargo.toml Outdated
Comment thread bin/chat-cli/src/transport/logos_delivery/sys.rs Outdated
Comment thread bin/chat-cli/src/transport/logos_delivery.rs Outdated
Comment thread bin/chat-cli/src/transport/logos_delivery.rs Outdated
Comment thread bin/chat-cli/src/transport/logos_delivery.rs Outdated
Comment thread bin/chat-cli/build.rs
return;
};

println!("cargo:rustc-cfg=logos_delivery");
Copy link
Copy Markdown
Contributor

@kaichaosun kaichaosun Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the feature flag for the app is over kill, we can just enable file transport and logos_delivery, and with a param (like --transport) to decide which transport to use.

LOGOS_DELIVERY_LIB_DIR could use the default ones without explicitly set it when set the logos delivery params, and LOGOS_DELIVERY_LIB_DIR can be configurable if need a different path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, let me address it in the followup PR.

Copy link
Copy Markdown
Collaborator

@jazzz jazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it, looks good for a dev app.

Comment thread bin/chat-cli/src/main.rs
Comment on lines +43 to +45
/// Initialize and immediately exit without launching the TUI (for CI).
#[arg(long)]
smoketest: bool,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Dust] This flag seems out of place to me. Naively appears the most value comes from ensuring the build succeeds - if the application returns early.

@osmaczko osmaczko force-pushed the feat/client-with-waku branch from 8537bd7 to 7028c83 Compare April 24, 2026 20:07
Copy link
Copy Markdown
Contributor

@kaichaosun kaichaosun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

… API

Replace the direct use of `conversations::Context` with `client::ChatClient`,
which is the intended public API for library consumers.

Remove `MessageEnvelope` and the username-keyed session model. The envelope
was never part of the wire protocol — sender identity was only tracked in the
CLI's local state. Chats are now keyed by conversation ID; add `/nickname` as
the user-facing replacement for named sessions.

Add a logos-delivery (Waku) transport alongside the existing file transport.
The active transport is selected at compile time: set `LOGOS_DELIVERY_LIB_DIR`
to link liblogosdelivery, otherwise the file transport is used.

Add logos-delivery as a Nix flake input and expose `.#logos-delivery` so the
library can be built with `nix build` and referenced by `LOGOS_DELIVERY_LIB_DIR`.

CI: rename `c-ffi-smoketest` to `smoketest`; add logos-delivery build step
and a `--smoketest` invocation of chat-cli to verify startup.
@osmaczko osmaczko force-pushed the feat/client-with-waku branch from 7028c83 to 2e04fd2 Compare April 27, 2026 11:03
@osmaczko osmaczko merged commit eaeffcd into main Apr 27, 2026
7 checks passed
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.

4 participants