Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cli/cloud_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use crate::{session, storage};
use crate::{cli::terminal::resume_hint, session, storage};

const FORMAT_VERSION: u32 = 1;
const SNAPSHOT_REF_PREFIX: &str = "refs/jcode-cloud";
Expand Down Expand Up @@ -1252,14 +1252,14 @@ pub(crate) fn run_cli(command: super::args::CloudCommand) -> Result<()> {
files.join(", ")
),
};
let resume = resume_hint(&report.session_id);
println!(
"Returned {} from `{}` ({} messages). Code: {merge}.\n Resume: jcode --resume {}",
report.session_id, report.host, report.messages, report.session_id
"Returned {} from `{}` ({} messages). Code: {merge}.\n Resume: {resume}",
report.session_id, report.host, report.messages
);
}
if attach {
let exe = std::env::current_exe()?;
let mut command = Command::new(exe);
let mut command = Command::new(std::env::current_exe()?);
command.arg("--resume").arg(&report.session_id);
let error = crate::platform::replace_process(&mut command);
bail!("failed to resume locally: {error}");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ fn resolve_resume_arg(args: &mut Args) -> Result<()> {
ResumeResolutionFailureAction::Exit => {
eprintln!("Error: {}", e);
if !output::quiet_enabled() {
eprintln!("\nUse `jcode --resume` to list available sessions.");
eprintln!("{}", crate::cli::terminal::resume_picker_hint());
}
std::process::exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ fn report_main_error(error: &anyhow::Error) {
if let Some(session_id) = terminal::get_current_session() {
output::stderr_blank_line();
output::stderr_info("\x1b[33mTo restore this session, run:\x1b[0m");
output::stderr_info(format!(" jcode --resume {}", session_id));
output::stderr_info(format!(" {}", terminal::resume_hint(&session_id)));
output::stderr_blank_line();
}
}
Expand Down
33 changes: 25 additions & 8 deletions src/cli/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,28 @@ pub fn show_crash_resume_hint() {
/// `~/.kcode`, so the session they were told to resume is not in that store -
/// part of the "sessions on reload have issues" report. Matches
/// `ssh::resume_hint`, which already names the kcode binary.
fn resume_binary_stem() -> &'static str {
pub(crate) fn resume_binary_stem() -> &'static str {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Making resume_binary_stem pub(crate) widens the surface for the single-value "kcode" literal, but the invariant that the binary name is never hand-written is not enforced elsewhere:

  • ssh.rs:136 builds its own vec!["kcode", "--ssh", ...]
  • cloud_move.rs:124 remote_binary() defaults to "kcode"
  • args.rs:22 #[command(name = "kcode")]

A future rename of the installed binary updates this helper but leaves those stale, reintroducing the exact mismatch this PR fixes. Consider routing those through resume_binary_stem (or documenting the coupling here) so the helper is the single source of truth.

cc @Kilo-Fix

"kcode"
}

/// `<bin> --resume <id>` - the exact command that resumes `session_id`.
///
/// Callers that print a resume instruction should render it through this helper
/// so the binary name is never hand-written (see `resume_binary_stem`).
pub(crate) fn resume_hint(session_id: &str) -> String {
format!("{} --resume {session_id}", resume_binary_stem())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: crash_resume_hint_lines still renders the command inline via let bin = resume_binary_stem(); (line 362) and format!("... {bin} --resume {id}") (lines 367, 380, 381) instead of calling resume_hint. That leaves the "every hint goes through one helper" claim only partly true and lets the lines drift again. Consider routing them through resume_hint.

cc @Kilo-Fix

}

/// Hint (leading newline included) that bare `--resume` opens the picker.
///
/// Rendered through `resume_binary_stem` so it never names the wrong binary.
pub(crate) fn resume_picker_hint() -> String {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: resume_picker_hint() embeds a leading \n in its return value, so the caller (dispatch.rs:690) must eprintln!("{}", ...) rather than adding its own spacing. That implicit layout contract is easy to break (double blank line or missing separator). Consider returning the message without the leading newline and letting the caller own spacing.

cc @Kilo-Fix

format!(
"\nUse `{} --resume` to list available sessions.",
resume_binary_stem()
)
}

/// Build the crash-resume hint lines for `crashed`, newest first.
///
/// Pure so the wording is testable: the lines are printed to stderr outside the
Expand Down Expand Up @@ -351,7 +369,7 @@ fn crash_resume_hint_lines(
// Always mention the picker. Showing only the ID form reads as
// "write this down or lose the session", when bare
// `jcode --resume` opens a searchable list (issue #690).
format!("{yellow} Or browse all:{reset} jcode --resume"),
format!("{yellow} Or browse all:{reset} {bin} --resume"),
]
} else {
vec![
Expand All @@ -360,14 +378,14 @@ fn crash_resume_hint_lines(
crashed.len()
),
format!("{yellow} Resume with:{reset} {bin} --resume {id}"),
format!("{yellow} List all:{reset} jcode --resume"),
format!("{yellow} List all:{reset} {bin} --resume"),
]
}
}

#[cfg(test)]
mod crash_resume_hint_tests {
use super::crash_resume_hint_lines;
use super::{crash_resume_hint_lines, resume_binary_stem};

fn session(id: &str, name: &str) -> (String, String) {
(id.to_string(), name.to_string())
Expand All @@ -389,10 +407,9 @@ mod crash_resume_hint_tests {
joined.contains("kcode --resume ses_koala_123"),
"the direct resume command must still be offered: {joined}"
);
let picker = format!("Or browse all: {} --resume", resume_binary_stem());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The reworded picker assertion derives its expected string from resume_binary_stem(), so it can no longer catch a wrong binary name — the original defect class. Line 407 still pins the direct form against the literal kcode, but the picker line (the one this PR changed) now has no literal guard. Consider also asserting the rendered line contains the resolved stem literally, e.g. assert against a hard-coded kcode --resume for the picker too, to keep a real regression guard.

cc @Kilo-Fix

assert!(
lines
.iter()
.any(|line| line.contains("Or browse all: jcode --resume")),
lines.iter().any(|line| line.contains(&picker)),
"the picker form (bare --resume) must be mentioned too: {joined}"
);
}
Expand Down Expand Up @@ -632,7 +649,7 @@ fn write_session_resume_hint(mut writer: impl Write, session_id: &str) -> io::Re
if let Some(command) = super::ssh::resume_hint(session_id) {
writeln!(writer, " {command}")?;
} else {
writeln!(writer, " {} --resume {}", resume_binary_stem(), session_id)?;
writeln!(writer, " {}", resume_hint(session_id))?;
}
writeln!(writer)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tui_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ pub fn list_sessions() -> Result<()> {
);
warned_no_terminal = true;
}
eprintln!(" jcode --resume {}", session_id);
eprintln!(" {}", crate::cli::terminal::resume_hint(&session_id));
}
Err(e) => {
eprintln!("Failed to spawn session {}: {}", session_id, e);
Expand Down
Loading