docs(comments): rewrite comments across all crates to the guidelines

Sweep every first-party crate source (1956 .rs files) to the project comment
guidelines: delete redundant restatements, decorative banners, change
narration, and end-of-line comments; keep and tighten the crucial ones
(invariants, bug rationale, SAFETY blocks, ported-source attribution).

No functional code changed. Every edit is proven comment-only against the
prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a
separate doctest-fence check. Where removing a comment made rustfmt or clippy
want to re-lay-out adjacent code, the minimal triggering comment is restored so
code tokens stay byte-identical.

Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy
--workspace --all-targets (0 warnings).

Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for
these guidelines (flags banners, end-of-line comments, change narration, and
commented-out code).
This commit is contained in:
2026-07-23 16:55:39 -04:00
parent ff0fb56c67
commit a02b555e66
1458 changed files with 10729 additions and 21750 deletions
@@ -13,7 +13,7 @@ use std::sync::OnceLock;
use crate::terminal::{MultiplexerKind, TerminalContext};
/// Cached result of the remote-session check (env vars don't change at runtime).
/// Cached result of the remote-session check (env vars do not alter at runtime).
fn is_remote() -> bool {
static REMOTE: OnceLock<bool> = OnceLock::new();
*REMOTE.get_or_init(kigi_shared::clipboard::is_remote_session)
@@ -270,7 +270,7 @@ pub struct CopyResult {
/// Kind of clipboard copy toast (success route or failure).
///
/// Telemetry labels come from `IntoStaticStr` (`snake_case`); user-facing copy
/// lives in [`ClipboardToastKind::message`] (intentionally different).
/// lives in [`ClipboardToastKind::message`] (deliberately different).
#[derive(Debug, Clone, Copy, Eq, PartialEq, strum::IntoStaticStr)]
#[strum(serialize_all = "snake_case")]
pub(crate) enum ClipboardToastKind {
@@ -442,7 +442,7 @@ pub fn clipboard_text_is_pasteable(text: Option<&str>) -> bool {
}
/// Telemetry when a paste key was pressed but the host clipboard had nothing
/// pasteable. Behavior is unchanged — callers still consume the key.
/// pasteable. Behavior is `unchanged` — callers still consume the key.
/// Emits structured logs and a product analytics event when telemetry is enabled.
pub fn log_paste_key_empty_host_clipboard(surface: &str) {
let terminal = crate::terminal::terminal_context().diagnostics_snapshot();
@@ -619,7 +619,7 @@ fn should_run_attachment_probe(
/// probe; `Some(change_count)` = probe, carrying the pasteboard `changeCount`
/// this gate's OWN snapshot read observed. Enqueue sites thread that baseline
/// into the off-thread probe's staleness check instead of taking a second
/// native read that could land after a clipboard change.
/// native read that could land after a clipboard write.
///
/// Cheap (native snapshot only, no subprocess) so paste handlers can call it on
/// the event loop to decide whether to DEFER the heavy probe to a background
@@ -769,9 +769,7 @@ pub fn system_clipboard_get_image() -> Option<ImageData> {
system_clipboard_get_image_result().unwrap_or(None)
}
// ===========================================================================
// Test support
// ===========================================================================
/// Injectable clipboard reads for driving the paste handlers in tests without
/// spawning `pbpaste` / `osascript`.
@@ -876,7 +874,7 @@ pub mod test_support {
PRIMARY_READS.with(|c| c.set(0));
}
/// Remove the canned clipboard hook and reset the probe counter.
/// Drop the canned clipboard hook and reset the probe counter.
pub fn clear_clipboard_probe_hook() {
HOOK.with(|h| *h.borrow_mut() = None);
PROBE_CALLS.with(|c| c.set(0));
@@ -959,9 +957,7 @@ pub use test_support::{
set_clipboard_probe_hook,
};
// ===========================================================================
// Tests
// ===========================================================================
#[cfg(test)]
mod tests {
@@ -971,7 +967,7 @@ mod tests {
TmuxClientMeta,
};
// -- Context builders for clipboard route tests ---------------------------
// Context builders for clipboard route tests
fn plain_terminal_ctx() -> TerminalContext {
TerminalContext {
@@ -1091,7 +1087,7 @@ mod tests {
);
}
// -- Bracketed payload ↔ clipboard text match ------------------------------
// Bracketed payload ↔ clipboard text match
#[test]
fn bracketed_payload_match_exact_and_normalized() {
@@ -1338,9 +1334,7 @@ mod tests {
}
}
// =====================================================================
// resolve_clipboard_route: pure routing logic
// =====================================================================
#[derive(Debug)]
struct ClipboardRouteCase {
@@ -1421,9 +1415,7 @@ mod tests {
}
}
// =====================================================================
// ClipboardRoute structure
// =====================================================================
#[test]
fn clipboard_route_native_always_true() {
@@ -1501,11 +1493,9 @@ mod tests {
assert!(!resolve_clipboard_route(&plain_terminal_ctx()).osc52_tmux_passthrough);
}
// =====================================================================
// Extended clipboard route matrix (final hardening)
// =====================================================================
// -- Byobu-screen: native only, no tmux buffer, no OSC 52 ----------------
// Byobu-screen: native only, no tmux buffer, no OSC 52
#[test]
fn clipboard_route_byobu_screen_no_tmux_buffer_no_osc52() {
@@ -1518,7 +1508,7 @@ mod tests {
// OSC 52 depends on is_remote(), but tmux_buffer must be false.
}
// -- Plain screen: no tmux buffer -----------------------------------------
// Plain screen: no tmux buffer
#[test]
fn clipboard_route_plain_screen_no_tmux_buffer() {
@@ -1530,7 +1520,7 @@ mod tests {
);
}
// -- Consistency: all environments always have native = true ---------------
// Consistency: all environments always have native = true
#[test]
fn clipboard_route_native_never_disabled() {
@@ -1552,7 +1542,7 @@ mod tests {
}
}
// -- tmux-backed: all three legs are active --------------------------------
// tmux-backed: all three legs are active
#[test]
fn clipboard_route_tmux_backed_all_three_legs() {
@@ -1564,7 +1554,7 @@ mod tests {
}
}
// -- Non-tmux-backed: tmux_buffer always false ----------------------------
// Non-tmux-backed: tmux_buffer always false
#[test]
fn clipboard_route_non_tmux_never_tmux_buffer() {
@@ -64,9 +64,8 @@ pub(crate) fn trusted_osc(
}
/// Toast from legs + env: native → OSC (incl. VS Code remote non-ASCII) → tmux → Failed.
// Pure decision function over independent environment inputs (host OS, display
// server, remote/container/sink flags). Bundling them into a struct would only
// move the argument list elsewhere and churn every call site/test.
// The arguments are independent environment inputs; bundling them into a struct
// would only move the same list to every call site.
#[allow(clippy::too_many_arguments)]
pub(crate) fn resolve_copy_toast(
legs: &ClipboardWriteLegs,
@@ -85,7 +84,8 @@ pub(crate) fn resolve_copy_toast(
if remote && brand.is_vscode_family() && !text.is_ascii() {
return ClipboardToastKind::VsCodeSshNonAscii;
}
// Container before remote (matches prior route-flag toast order).
// A remote container reports the container toast: its fallback hint is
// the actionable one.
if container {
return ClipboardToastKind::CopiedOscContainer;
}
@@ -126,7 +126,6 @@ mod tests {
}
}
/// Same as [`legs`] with the Wayland data-control flag set.
fn legs_data_control(
route_native: bool,
cli_ok: bool,
@@ -249,9 +248,8 @@ mod tests {
);
}
// The enterprise clipboard shape after the fix: no CLI tool installed, but the
// arboard write went through the compositor's data-control protocol, so it
// is trusted native.
// Locked-down enterprise desktop: no clipboard CLI installed, but the
// arboard write reached the compositor via data-control.
#[test]
fn linux_wayland_arboard_data_control_ok() {
let l = legs_data_control(true, false, true, false, true, "");
@@ -268,8 +266,7 @@ mod tests {
);
}
// Without data-control (GNOME <= 47 or kill-switch), an arboard-only write
// keeps the `linux_wayland_arboard_only_fails` semantics.
// GNOME <= 47 or the kill-switch: no data-control protocol available.
#[test]
fn linux_wayland_arboard_without_data_control_still_fails() {
let l = legs(true, false, true, false, false, "");
@@ -286,7 +283,6 @@ mod tests {
);
}
// Data-control grants nothing when the arboard write itself failed.
#[test]
fn linux_wayland_data_control_without_arboard_fails() {
let l = legs_data_control(true, false, false, false, false, "");
@@ -385,7 +381,7 @@ mod tests {
#[test]
fn ssh_iterm2_osc_only_remote_toast() {
// Guards the OSC-52 membership invariant the fix depends on.
// The remote toast only holds while Iterm2 is in the OSC-52 brand set.
assert!(TerminalName::Iterm2.supports_osc52_clipboard());
let l = legs(true, false, false, false, true, "");
assert_eq!(
@@ -550,13 +546,13 @@ mod tests {
);
}
// `kigi wrap` sink: a brand that does NOT natively support OSC 52 (the
// common SSH case where the inner terminal is misdetected as Vte/Unknown)
// is still trusted when an upstream OSC 52 sink is capturing our output.
// The common SSH case: the inner terminal is misdetected as Vte, which does
// not natively support OSC 52, yet the `kigi wrap` sink upstream does.
#[test]
fn wrapped_ssh_vte_osc_trusted_via_sink() {
let l = legs(true, false, false, false, true, "");
// Without the sink: untrusted brand over SSH → Failed.
// Trailing arg is the sink flag: without it, an untrusted brand over
// SSH fails closed.
assert_eq!(
resolve_copy_toast(
&l,
@@ -570,7 +566,7 @@ mod tests {
),
ClipboardToastKind::Failed
);
// With the sink active: trusted → success toast.
// Same inputs with the sink active.
assert_eq!(
resolve_copy_toast(
&l,
@@ -586,8 +582,6 @@ mod tests {
);
}
// Sink trust still requires an actual OSC 52 write to have happened
// (`osc52_ok`); it never fabricates success when no leg fired.
#[test]
fn wrapped_sink_without_osc_write_still_fails() {
let l = legs(true, false, false, false, false, "");
@@ -607,11 +601,9 @@ mod tests {
);
}
// Docker/podman from Windows PowerShell / cmd (or any host terminal):
// brand env vars are not forwarded into the container, so the brand is
// Unknown; native legs cannot work (no display server). The emitted
// OSC 52 is the copy path and must be trusted → hedged container toast,
// not "Copy failed" (regression test for the false-failure report).
// Regression test for the false "Copy failed" toast in docker: the runtime
// does not forward brand env vars, so the brand is Unknown even though the
// outer terminal applies OSC 52 fine. See [`trusted_osc`].
#[test]
fn container_unknown_brand_osc_trusted() {
let l = legs(true, false, false, false, true, "");
@@ -628,7 +620,6 @@ mod tests {
);
}
// Container trust never fabricates success: no OSC 52 write → Failed.
#[test]
fn container_unknown_brand_without_osc_write_fails() {
let l = legs(true, false, false, false, false, "");
@@ -646,8 +637,8 @@ mod tests {
);
}
// A *detected* non-supporting brand stays fail-closed even in a container
// (env was explicitly forwarded, so the detection is authoritative).
// A brand that survived into the container means the env was explicitly
// forwarded, so the detection is authoritative and stays fail-closed.
#[test]
fn container_detected_nonsupporting_brand_fails() {
let l = legs(true, false, false, false, true, "");
@@ -664,8 +655,8 @@ mod tests {
);
}
// Unknown brand over SSH (not container) keeps failing closed — the
// container override is deliberately narrow; `kigi wrap` is the SSH path.
// The container override is deliberately narrow: plain SSH keeps failing
// closed, since `kigi wrap` is the supported SSH path.
#[test]
fn ssh_unknown_brand_osc_only_still_fails() {
let l = legs(true, false, false, false, true, "");
@@ -682,7 +673,6 @@ mod tests {
);
}
// Sink in a container (no display) → container OSC toast.
#[test]
fn wrapped_container_osc_trusted_via_sink() {
let l = legs(true, false, false, false, true, "");