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
16 changes: 9 additions & 7 deletions crates/jcode-base/src/scratch_maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ fn busy_process_dirs() -> Option<Vec<PathBuf>> {

// If not a single process was inspectable the API is not behaving as expected;
// report that as "unknown" so the caller declines to prune.
if readable == 0 {
None
} else {
Some(dirs)
}
if readable == 0 { None } else { Some(dirs) }
}

/// Any platform without a working cwd probe reports "unknown", which makes
Expand Down Expand Up @@ -521,7 +517,10 @@ mod tests {
temp.path(),
"KCODE_HOME did not redirect storage::jcode_dir"
);
assert!(scratch.is_dir(), "scratch root must exist under the redirected home");
assert!(
scratch.is_dir(),
"scratch root must exist under the redirected home"
);
assert!(
retention_from_env().is_some(),
"retention must be enabled for the pass to run"
Expand Down Expand Up @@ -553,6 +552,9 @@ mod tests {
busy_kept,
"the scheduled pass deleted a directory holding a live process cwd"
);
assert!(stamped, "the pass must record its stamp so it runs once a day");
assert!(
stamped,
"the pass must record its stamp so it runs once a day"
);
}
}
4 changes: 3 additions & 1 deletion crates/jcode-base/src/test_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub fn root() -> PathBuf {

/// Create a temp dir under [`root`], ignoring `TMPDIR`.
pub fn tempdir() -> std::io::Result<tempfile::TempDir> {
tempfile::Builder::new().prefix("kcode-test-").tempdir_in(root())
tempfile::Builder::new()
.prefix("kcode-test-")
.tempdir_in(root())
}

/// Create a prefixed temp dir under [`root`], ignoring `TMPDIR`.
Expand Down
20 changes: 10 additions & 10 deletions crates/jcode-tui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ mod auth;
mod auth_account_picker_saved_accounts;
mod auth_remote;
mod catchup;
mod clipboard_copy;
mod clipboard_notice;
mod commands;
mod commands_cloud;
mod commands_colors;
Expand Down Expand Up @@ -169,10 +171,9 @@ struct PendingLocalTransfer {
}

/// A reasoning trace anchored in the transcript during the current turn
/// (`current` display mode). `wrapped_lines_at_anchor` snapshots the
/// transcript's total wrapped-line count when the trace anchored; once the
/// transcript grows a viewport past that point the trace is provably above
/// the tail-following viewport and can be removed with zero visible motion.
/// (`current` display mode). `wrapped_lines_at_anchor` snapshots the total
/// wrapped-line count at anchor; once the transcript grows a viewport past it,
/// the trace is provably above the tail-following viewport and can be removed.
#[derive(Debug, Clone, Copy)]
struct TurnReasoningTrace {
display_index: usize,
Expand Down Expand Up @@ -212,10 +213,9 @@ pub(in crate::tui::app) struct KvCacheRequestSignature {

#[derive(Debug, Clone)]
struct KvCacheBaseline {
/// Session this baseline was captured for. Baselines must only be diffed
/// against requests from the same session; otherwise a session switch makes
/// the new (often smaller) history look like a broken prefix and produces a
/// spurious `harness:_prefix_changed` miss.
/// Session this baseline was captured for. Diff only against requests from
/// the same session: a switch makes the new (often smaller) history look
/// like a broken prefix and produces a spurious `harness:_prefix_changed` miss.
session_id: Option<String>,
/// Cache-history generation this baseline belongs to. Compaction replaces
/// the provider-facing transcript, so a baseline captured before it must
Expand Down Expand Up @@ -371,8 +371,7 @@ struct PendingFallbackOffer {
remote_resend: Option<FallbackResendPayload>,
}

/// The failed remote turn's payload, held by a [`PendingFallbackOffer`] so a
/// one-keypress accept can resend it after the route switch completes.
/// Payload of the failed remote turn, resent by a one-keypress fallback accept.
#[derive(Debug, Clone)]
struct FallbackResendPayload {
/// Expanded message content that was sent to the server.
Expand Down Expand Up @@ -1583,6 +1582,7 @@ pub struct App {
history_draft: Option<(String, usize)>,
// Short-lived notice for status feedback (model switch, cycle diff mode, etc.)
status_notice: Option<(String, Instant)>,
clipboard: ClipboardState,
// Distinct learned-keybinding nudge ("you keep doing X the slow way, press
// <key>"). Rendered in its own pop-out color, separate from status_notice,
// and shown at most once per session.
Expand Down
9 changes: 3 additions & 6 deletions crates/jcode-tui/src/tui/app/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,12 +1689,9 @@ impl App {
let user_code = device_resp.user_code.clone();
let verification_uri = device_resp.verification_uri.clone();

let clipboard_ok = copy_to_clipboard(&user_code);
let clipboard_msg = if clipboard_ok {
" (copied to clipboard - just paste it!)"
} else {
""
};
let clipboard = copy_to_clipboard(&user_code);
let clipboard_msg =
super::clipboard_notice::login_device_code_suffix(clipboard.outcome);

Bus::global().publish(BusEvent::LoginCompleted(LoginCompleted {
provider: "copilot_code".to_string(),
Expand Down
129 changes: 129 additions & 0 deletions crates/jcode-tui/src/tui/app/clipboard_copy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//! Clipboard copy outcome types (issue #231).
//!
//! A clipboard helper that is still running when the fail-fast window closes has
//! not proven that it owns the selection. These types carry that distinction so
//! a call site can render "sent but unconfirmed" instead of claiming a copy, and
//! can still apply the helper's real exit later, from the idle tick.

/// What a clipboard write established about selection ownership.
///
/// `Copied` means the write was accepted (the helper exited zero, or a native
/// API / OSC 52 accepted it). `Failed` means the write was rejected. Both are
/// observations. `Unconfirmed` means a helper is still running and may or may
/// not own the selection: it is explicitly *not* a copy (issue #231).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum CopyOutcome {
Copied,
Failed,
Unconfirmed,
}

/// The eventual exit of a helper that outlived the fail-fast window.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum HelperExit {
// Constructed by the Linux-only helper module; on Windows/macOS that module
// is not compiled, so the variant is legitimately unused there.
#[cfg_attr(any(windows, target_os = "macos"), allow(dead_code))]
ExitedZero,
ExitedNonZero,
}

/// Receives the late exit of an unconfirmed clipboard helper.
///
/// The detached reaper owns the child and sends its exit here. `try_settle`
/// never blocks, so the UI tick can poll it and apply an honest correction
/// without stalling input handling.
#[derive(Debug)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Suspected compile error — #[derive(Debug)] on ClipboardWatch requires std::sync::mpsc::Receiver<HelperExit>: Debug, which std does not implement. Same derive on ClipboardCopy (line 66) and PendingCopy (line 122) in this file, and on HelperOutcome::Unconfirmed(ClipboardWatch) in clipboard_helper.rs:36 (Linux-only). No struct in the repo derives Debug over an std::sync::mpsc::Receiver. Likely E0277 on every platform, contradicting the claimed clean cargo check. Verify with cargo check -p jcode-tui --all-targets.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: #[derive(Debug)] on ClipboardWatch requires std::sync::mpsc::Receiver<HelperExit>: Debug, which std does not implement. Same derive on ClipboardCopy (line 66) and PendingCopy (line 122), and on HelperOutcome::Unconfirmed(ClipboardWatch) in clipboard_helper.rs. Likely E0277 on every platform. Verify with cargo check -p jcode-tui --all-targets.

pub(super) struct ClipboardWatch {
rx: std::sync::mpsc::Receiver<HelperExit>,
}

impl ClipboardWatch {
// Only the Linux-only helper module opens a watch channel.
#[cfg_attr(any(windows, target_os = "macos"), allow(dead_code))]
pub(super) fn channel() -> (Self, std::sync::mpsc::Sender<HelperExit>) {
let (tx, rx) = std::sync::mpsc::channel();
(Self { rx }, tx)
}

/// Non-blocking: `None` means the helper has not exited yet. A disconnected
/// reaper means the exit will never be reported, so it settles as a
/// non-zero exit: an unconfirmed helper must never be promoted to a copy
/// on missing evidence.
pub(super) fn try_settle(&self) -> Option<HelperExit> {
match self.rx.try_recv() {
Ok(exit) => Some(exit),
Err(std::sync::mpsc::TryRecvError::Empty) => None,
Err(std::sync::mpsc::TryRecvError::Disconnected) => Some(HelperExit::ExitedNonZero),
}
}
}

/// A clipboard write plus the optional watch for an unconfirmed helper.
///
/// `From<bool>` keeps the many existing test seams (`|text| true`) working:
/// they express an already-resolved copy or failure.
#[derive(Debug)]
pub(super) struct ClipboardCopy {
pub(super) outcome: CopyOutcome,
pub(super) watch: Option<ClipboardWatch>,
}

impl ClipboardCopy {
pub(super) fn copied() -> Self {
Self {
outcome: CopyOutcome::Copied,
watch: None,
}
}

pub(super) fn failed() -> Self {
Self {
outcome: CopyOutcome::Failed,
watch: None,
}
}

// Only the Linux-only helper module produces an unconfirmed copy.
#[cfg_attr(any(windows, target_os = "macos"), allow(dead_code))]
pub(super) fn unconfirmed(watch: ClipboardWatch) -> Self {
Self {
outcome: CopyOutcome::Unconfirmed,
watch: Some(watch),
}
}
}

impl From<bool> for ClipboardCopy {
fn from(success: bool) -> Self {
if success {
Self::copied()
} else {
Self::failed()
}
}
}

/// Clipboard notice state owned by `App`.
///
/// One field keeps the state out of the already-oversized `app.rs` struct
/// while still giving tests and production identical isolation.
#[derive(Debug, Default)]
pub(super) struct ClipboardState {
/// A copy whose helper outlived the fail-fast window.
pub(super) pending: Option<PendingCopy>,
/// Monotonic token so a late outcome cannot overwrite a newer copy.
pub(super) token: u64,
}

/// A copy whose helper is still running. The tick poll watches for its late
/// exit and corrects the provisional notice, unless a newer copy (token) or a
/// different notice superseded it.
#[derive(Debug)]
pub(super) struct PendingCopy {
pub(super) token: u64,
pub(super) watch: ClipboardWatch,
pub(super) success_text: String,
pub(super) provisional_text: String,
pub(super) failure_text: String,
}
Loading
Loading