Skip to content

feat: chat cli demo app#87

Merged
kaichaosun merged 13 commits intomainfrom
chat-cli
Apr 17, 2026
Merged

feat: chat cli demo app#87
kaichaosun merged 13 commits intomainfrom
chat-cli

Conversation

@kaichaosun
Copy link
Copy Markdown
Contributor

@kaichaosun kaichaosun commented Apr 16, 2026

Why this change:

  • we need a app to demo the features and its usage in libchat.
  • this app tests how storage works in different platforms

What changes:

  • terminal ui app
  • local file based transport
  • encrypted storage with default password

Ignore the double ratchet ffi removal, it's in #84

Screenshot of cli app

chat-cli-test

@kaichaosun kaichaosun requested review from jazzz, osmaczko and plopezlpz and removed request for jazzz April 16, 2026 09:19
Copy link
Copy Markdown
Contributor

@osmaczko osmaczko left a comment

Choose a reason for hiding this comment

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

Nice 👍

Works for me as well

Image

Comment thread bin/chat-cli/src/main.rs Outdated
/// Get the data directory (in project folder).
fn get_data_dir() -> PathBuf {
// Use the directory where the binary is or current working directory
let manifest_dir = env!("CARGO_MANIFEST_DIR");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CARGO_MANIFEST_DIR is baked in at compile time and is never empty in practice, making the "." fallback a dead code. Please consider using simply std::env::current_dir() instead.

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.

Overall this looks clean no blockers. I think it will be hard to keep this up to date, but as long as we are cool letting this lag a bit, then I don't see any issues.

My only notes for future consideration:

  • Seems like this should be using crates/client as that is the primary interface for developers.
  • This introduces some language which is in conflict with our existing codebase e.g. Sessions, Alice/Bob. As this resides in this repo the contents become canonical, which means we'll need to update it at some point to bring it in line with the project.

Comment thread bin/chat-cli/src/app.rs

use anyhow::{Context, Result};
use arboard::Clipboard;
use libchat::{ChatStorage, Context as ChatManager, Introduction, StorageConfig};
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.

If this is supposed to mimic a developer example; Rather than using Context, this should use crates/client/src/client.rs

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.

Good point, will figure out the latest client crate status and how to integrate with it in new PR.

Comment thread bin/chat-cli/src/app.rs Outdated
Ok(Some(format!("Connected to {}", remote_user)))
}
"/chats" => {
let sessions: Vec<_> = self.state.sessions.keys().cloned().collect();
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: Collecting this iterator doesn't immediately seem necessary.

if self.state.session.is_empty() { 
...
}

for name in map.keys() {
...
}

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.

Tried this, but got immutable / mutable borrow conflict in for loop.

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.

Ah I see. The state is being mutated while being looped over - I missed that.

Comment thread bin/chat-cli/src/transport.rs Outdated
Comment on lines +138 to +143
fn now() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis() as u64
}
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.

A duplicate function exists in app.rs, its not immediately clear if things would break if the implementations differed. I'd consider unifying them or labelling appropriately

Comment thread bin/chat-cli/README.md
## Features

- End-to-end encrypted messaging using libchat
- File-based transport for local simulation (no network required)
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: Consider using Multicast instead of file-based transport. Files are inherently reliable which hides a class of usage failures.

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.

Multicast sounds a good idea, I remembered tried it before, but switch to file based transport for some reason. Maybe still worth to try it later.
Make the transport switchable looks cool.

@kaichaosun
Copy link
Copy Markdown
Contributor Author

kaichaosun commented Apr 17, 2026

This introduces some language which is in conflict with our existing codebase e.g. Sessions, Alice/Bob.

  • I have renamed sessions to chats.
  • Alice/bob sounds proper solution here, I see there is a spec for participants naming conventions, and i have list my concern there. Overall, alice/bob is the go to names in many scenarios, and I believe this is what most developers expects in this cli demo app.
  • Context is alias as ChatManager in chat-cli which is much more clear in its usage, I hope we can remove/rename Context soon.

@kaichaosun kaichaosun merged commit 6c7b3a4 into main Apr 17, 2026
4 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.

3 participants