Skip to content

Commit 9d06468

Browse files
committed
fix(cli): implement --share flag to display share URL
Fixes bounty issue #1248 The --share flag was defined but not implemented, only printing a message that sharing was not yet implemented when verbose mode was enabled. This change implements the session sharing functionality by: - Adding cortex-share as a dependency - Using ShareManager to share the session after successful completion - Printing the share URL to stdout for the user
1 parent 7a104aa commit 9d06468

4 files changed

Lines changed: 37 additions & 19 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ cortex-storage = { path = "cortex-storage" }
131131
cortex-core = { path = "cortex-core" }
132132
cortex-tui = { path = "cortex-tui" }
133133
cortex-update = { path = "cortex-update" }
134+
cortex-share = { path = "cortex-share" }
134135

135136
# OpenTUI crates
136137
opentui = { path = "opentui-rs" }

cortex-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cortex-common = { workspace = true, features = ["cli"] }
3030
cortex-login = { workspace = true }
3131
cortex-process-hardening = { workspace = true }
3232
cortex-app-server = { workspace = true }
33+
cortex-share = { workspace = true }
3334

3435
clap = { workspace = true }
3536
clap_complete = { workspace = true }

cortex-cli/src/run_cmd.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,17 @@ impl RunCli {
241241
pub async fn run(self) -> Result<()> {
242242
// Validate temperature if provided
243243
if let Some(temp) = self.temperature
244-
&& !(0.0..=2.0).contains(&temp) {
245-
bail!("Temperature must be between 0.0 and 2.0, got {temp}");
246-
}
244+
&& !(0.0..=2.0).contains(&temp)
245+
{
246+
bail!("Temperature must be between 0.0 and 2.0, got {temp}");
247+
}
247248

248249
// Validate top_p if provided
249250
if let Some(top_p) = self.top_p
250-
&& !(0.0..=1.0).contains(&top_p) {
251-
bail!("top-p must be between 0.0 and 1.0, got {top_p}");
252-
}
251+
&& !(0.0..=1.0).contains(&top_p)
252+
{
253+
bail!("top-p must be between 0.0 and 1.0, got {top_p}");
254+
}
253255

254256
// Check if original message args are all whitespace (before quote-wrapping)
255257
// This catches cases like `cortex run " "` which would otherwise pass validation
@@ -460,9 +462,10 @@ impl RunCli {
460462
SessionMode::New { title } => {
461463
let id = uuid::Uuid::new_v4().to_string();
462464
if let Some(ref t) = title
463-
&& self.verbose {
464-
eprintln!("New session: {id} (title: {t})");
465-
}
465+
&& self.verbose
466+
{
467+
eprintln!("New session: {id} (title: {t})");
468+
}
466469
id
467470
}
468471
};
@@ -558,11 +561,12 @@ impl RunCli {
558561
while let Ok(event) = handle.event_rx.recv().await {
559562
// Check timeout
560563
if let Some(timeout) = timeout_duration
561-
&& start_time.elapsed() > timeout {
562-
eprintln!("Timeout reached after {} seconds", self.timeout);
563-
error_occurred = true;
564-
break;
565-
}
564+
&& start_time.elapsed() > timeout
565+
{
566+
eprintln!("Timeout reached after {} seconds", self.timeout);
567+
error_occurred = true;
568+
break;
569+
}
566570

567571
event_count += 1;
568572

@@ -745,11 +749,22 @@ impl RunCli {
745749
send_notification(&session_id, !error_occurred)?;
746750
}
747751

748-
// Share session if requested
749-
if self.share {
750-
// TODO: Implement session sharing when API is available
751-
if self.verbose {
752-
eprintln!("Session sharing requested but not yet implemented");
752+
// Share session if requested and no error occurred
753+
if self.share && !error_occurred {
754+
let share_manager = cortex_share::ShareManager::new();
755+
match share_manager.share(&session_id).await {
756+
Ok(shared_session) => {
757+
// Print the share URL to stdout for the user
758+
println!("Share URL: {}", shared_session.url);
759+
}
760+
Err(e) => {
761+
eprintln!(
762+
"{}Warning:{} Failed to share session: {}",
763+
TermColor::Yellow.ansi_code(),
764+
TermColor::Default.ansi_code(),
765+
e
766+
);
767+
}
753768
}
754769
}
755770

0 commit comments

Comments
 (0)