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:
ZacharyZhang-NY committed 2026-07-23 16:55:39 -04:00
1 parent ff0fb56c67
commit a02b555e66
1458 files changed
+10729 -21750

No files matched your search

@@ -45,8 +45,6 @@ fn all_user_message_blobs(content: &ContentController) -> Vec<String> {
.collect()
}
/// Mid-turn queue via Enter, then empty Enter cancels the running turn and
/// runs that row as the next turn (cancel-and-send).
pub async fn assert_empty_enter_force_sends_top_queued() -> Result<()> {
let content = ContentController::start()
.await
@@ -79,13 +77,11 @@ pub async fn assert_empty_enter_force_sends_top_queued() -> Result<()> {
.context("queued text visible")?;
harness.inject_keys(b"\r").context("empty Enter send-now")?;
// Cancel-and-send: the shell cancels turn 1 (its held completion is
// irrelevant — the abort wins) and promotes the row to run as turn 2.
// Release the gate so any completion race resolves rather than hangs.
// Release the gate so a completion racing the abort resolves rather than
// hangs.
content.release_agent_completions();
// The promoted row renders as a standard user prompt block ("❯ " prefix
// distinguishes the committed block from the prefix-less queue row) with
// the new turn's reply below it.
// The "❯ " prefix distinguishes the committed prompt block from the
// prefix-less queue row.
harness
.wait_for_text(
"\u{276F} please also check the logs",
@@ -96,8 +92,6 @@ pub async fn assert_empty_enter_force_sends_top_queued() -> Result<()> {
.wait_for_text("TURNTWO", Duration::from_secs(40))
.context("promoted turn reply")?;
// A send-now cancel is silent: no "Turn cancelled by user" marker may
// appear between the partial turn-1 output and the promoted prompt.
if harness.contains_text("Turn cancelled by user") {
bail!(
"send-now cancel must not render a cancelled marker\n{}",
@@ -12,8 +12,7 @@ const IDLE_WINDOW: Duration = Duration::from_secs(3);
pub async fn run(harness: &mut PtyHarness, _content: &ContentController) -> Result<BenchResults> {
wait_for_welcome(harness).await?;
// Let the splash screen animation settle (some of the pager's intro
// screens do a brief fade/animation).
// Let the splash screen's fade animation settle before timing idle frames.
harness.update(Duration::from_secs(1));
harness.reset_timing();
@@ -1,8 +1,6 @@
//! `large_codeblock` — render a large syntax-highlighted Rust code block
//! and scroll through it.
//!
//! What it stresses: `syntect` highlighting cache, wrapping of long source
//! lines, ScratchBuffer copy for a single oversized entry.
//! `large_codeblock` — render a large syntax-highlighted Rust code block and
//! scroll through it. Stresses the `syntect` highlighting cache, wrapping of
//! long source lines, and the ScratchBuffer copy for a single oversized entry.
use std::time::{Duration, Instant};
@@ -1,8 +1,7 @@
//! `mixed_interaction` — scroll while streaming. The real-world worst case.
//!
//! What it stresses: simultaneous cache invalidation (from streaming) and
//! full viewport re-render (from scrolling). Surfaces `dirty_heights` /
//! scroll-offset interactions.
//! `mixed_interaction` — scroll while streaming, the real-world worst case.
//! Stresses simultaneous cache invalidation (from streaming) and full viewport
//! re-render (from scrolling), surfacing `dirty_heights` / scroll-offset
//! interactions.
use std::time::{Duration, Instant};
@@ -16,8 +15,7 @@ const SCROLL_KEYS: usize = 80;
const KEY_INTERVAL: Duration = Duration::from_millis(40);
pub async fn run(harness: &mut PtyHarness, content: &ContentController) -> Result<BenchResults> {
// Same payload shape as streaming_render, but we scroll through it
// while it's still arriving.
// Same payload shape as `streaming_render`.
let mut body = String::from("mixed-bench ");
for i in 0..TARGET_WORDS {
body.push_str("tok");
@@ -21,7 +21,6 @@ pub mod resize_storm;
pub mod scroll_stress;
pub mod streaming_render;
/// Enumerates every benchmark scenario that can be dispatched by name.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Scenario {
@@ -40,7 +39,6 @@ pub enum Scenario {
}
impl Scenario {
/// Every scenario, in dispatch order.
pub const ALL: &'static [Scenario] = &[
Scenario::ScrollStress,
Scenario::StreamingRender,
@@ -62,7 +60,6 @@ impl Scenario {
}
}
/// Dispatch to the scenario implementation.
pub async fn run(
self,
harness: &mut PtyHarness,
@@ -79,11 +76,10 @@ impl Scenario {
}
}
/// Wait for the pager to render the initial welcome screen. All scenarios
/// that prompt / stream content rely on the pager being past startup.
/// Scenarios that prompt or stream content require the pager to be past startup.
pub(crate) async fn wait_for_welcome(harness: &mut PtyHarness) -> Result<()> {
// Menu label on the normal welcome (and gate menus): capital Q — see
// `kigi-tui` `views/welcome/mod.rs` (`"Quit"` in `render_menu`).
// Capital-Q menu label appears on the normal welcome and on gate menus — see
// `render_menu` in `kigi-tui` `views/welcome/mod.rs`.
harness
.wait_for_text("Quit", Duration::from_secs(15))
.map_err(|e| anyhow::anyhow!("pager failed to reach welcome screen: {e}"))
@@ -7,8 +7,8 @@
//! no pager-side disk logic. Approving then leaves plan mode and starts the
//! implement turn.
//!
//! This FAILS without the shell re-park (PR2 product change): no reverse-request
//! reaches the resumed pager, so no approval chrome appears.
//! Without the shell re-park no reverse-request reaches the resumed pager, so no
//! approval chrome appears and this scenario fails.
use std::path::Path;
use std::time::Duration;
@@ -21,8 +21,8 @@ use crate::{ContentController, PtyHarness, pager_binary};
const DEFAULT_ROWS: u16 = 50;
const DEFAULT_COLS: u16 = 120;
const WELCOME_TIMEOUT: Duration = Duration::from_secs(20);
/// Distinct per-turn sentinels: turn 1 seeds the session before quit; turn 2 is
/// the implement turn the shell injects after the resumed approval is approved.
/// Turn 1 seeds the session before quit; turn 2 is the implement turn the shell
/// injects once the resumed approval is approved.
const SETUP_SENTINEL: &str = "GBT3703SETUP";
const IMPLEMENT_SENTINEL: &str = "GBT3703IMPLEMENTED";
@@ -35,15 +35,12 @@ const PLAN_BODY: &str = "\
3. Resume and expect restored approval chrome
";
/// Regression: the shell re-parks `exit_plan_mode` on resume; pressing
/// approve leaves plan mode and starts the implement turn.
pub async fn assert_plan_approval_restored_after_resume() -> Result<()> {
let content = ContentController::start()
.await
.context("start ContentController")?;
// One response per agent turn (FIFO, 2+-tool requests only — aux requests
// never steal one). Turn 1 is consumed by the first pager; turn 2 by the
// implement turn the shell starts after approval.
// One response per agent turn, FIFO; only 2+-tool requests draw from the
// queue, so aux requests never steal a turn.
content.set_turns([
format!("{SETUP_SENTINEL}: drafted a plan for the user to review."),
format!("{IMPLEMENT_SENTINEL}: implementing the approved plan."),
@@ -90,10 +87,8 @@ pub async fn assert_plan_approval_restored_after_resume() -> Result<()> {
)
.context("spawn resumed pager")?;
// The shell re-parks `exit_plan_mode` on resume, so approval chrome can open
// immediately and cover chat history. Prefer the chrome markers (product
// signal) over SETUP_SENTINEL, which may not be visible under the plan viewer.
// Without the shell re-park this times out.
// Approval chrome can open immediately and cover chat history, so key on the
// chrome markers rather than SETUP_SENTINEL, which the plan viewer may hide.
resumed
.wait_for_text("request changes", WELCOME_TIMEOUT)
.context("restored approval 'request changes' after --continue")?;
@@ -104,8 +99,8 @@ pub async fn assert_plan_approval_restored_after_resume() -> Result<()> {
if !screen.contains("approve") {
bail!("expected approval primary action after resume\n{screen}");
}
// History was seeded before quit; plan body from disk is a stronger signal
// that the session was restored when chrome already covers the transcript.
// Any one of these proves the session was restored: with chrome covering the
// transcript the plan body from disk is often the only visible evidence.
if !screen.contains("GBT3703Repro")
&& !screen.contains(SETUP_SENTINEL)
&& !screen.contains("Seed plan file on disk")
@@ -116,7 +111,6 @@ pub async fn assert_plan_approval_restored_after_resume() -> Result<()> {
bail!("pager panicked\n{screen}");
}
// Approve: the shell leaves plan mode and injects the implement turn.
resumed.inject_keys(b"a").context("press 'a' to approve")?;
resumed
.wait_for_text(IMPLEMENT_SENTINEL, Duration::from_secs(30))
@@ -126,9 +120,8 @@ pub async fn assert_plan_approval_restored_after_resume() -> Result<()> {
Ok(())
}
/// Mark the persisted session as having a parked plan approval: write `plan.md`
/// and flip `awaiting_plan_approval` to `true` in `plan_mode.json` for every
/// session dir under the sandbox home.
/// Parks a plan approval in every session dir under the sandbox home, since the
/// id of the session the first pager created is not known here.
fn seed_parked_approval(home: &Path) -> Result<usize> {
let sessions_root = home.join(".kigi").join("sessions");
if !sessions_root.is_dir() {
@@ -163,12 +156,9 @@ fn seed_parked_approval(home: &Path) -> Result<usize> {
Ok(seeded)
}
/// Round-trip the shell-written `plan_mode.json` and flip `awaiting_plan_approval`
/// to `true`, preserving every other field. Falls back to a fresh Active
/// snapshot if the shell wrote nothing. The shape mirrors
/// `kigi_shell::session::plan_mode::PlanModeSnapshot`; we only touch the one
/// field (robust to schema growth) rather than depend on the heavy shell crate
/// from this test-only harness.
/// The shape mirrors `kigi_shell::session::plan_mode::PlanModeSnapshot`, but this
/// test-only harness edits it as raw JSON rather than pull in the heavy shell
/// crate; preserving unknown fields keeps that decoupling safe as the schema grows.
fn write_awaiting_plan_mode(path: &Path) -> Result<()> {
let mut value: serde_json::Value = std::fs::read_to_string(path)
.ok()
@@ -18,7 +18,6 @@ pub async fn run(harness: &mut PtyHarness, _content: &ContentController) -> Resu
harness.reset_timing();
let start = Instant::now();
// Oscillate between a narrow and a wide layout.
for i in 0..RESIZES {
let (rows, cols) = if i % 2 == 0 { (35, 100) } else { (55, 160) };
harness.resize(rows, cols)?;
@@ -19,7 +19,6 @@ pub async fn run(harness: &mut PtyHarness, content: &ContentController) -> Resul
// 1. Prime the mock server with a large markdown response.
content.set_response(long_markdown_response(LINES));
// 2. Wait for the pager's splash screen.
wait_for_welcome(harness).await?;
// 3. Submit a prompt so the mock inference server returns the big response.
@@ -18,15 +18,13 @@ pub async fn run(harness: &mut PtyHarness, content: &ContentController) -> Resul
wait_for_welcome(harness).await?;
// Kick off the streamed response.
harness.inject_keys(b"stream\r")?;
// Wait for first delta to hit the screen so we're measuring the
// Wait for the first delta to hit the screen so the measurement covers the
// steady-state streaming path, not startup latency.
harness.wait_for_text("stream-bench", Duration::from_secs(20))?;
harness.reset_timing();
// Collect frames during the streaming window — the mock server paces
// itself naturally via HTTP/SSE; we just let the pipe drain.
// No pacing needed here: the mock server paces the stream over HTTP/SSE.
let start = Instant::now();
while start.elapsed() < STREAM_WINDOW {
harness.update(Duration::from_millis(100));
@@ -41,8 +39,8 @@ pub async fn run(harness: &mut PtyHarness, content: &ContentController) -> Resul
fn build_response(words: usize) -> String {
let mut s = String::with_capacity(words * 10);
// Sentinel token that wait_for_text keys on — guaranteed to appear
// near the very start of the stream.
// Leading sentinel that `wait_for_text` keys on, so it lands in the first
// few deltas of the stream.
s.push_str("stream-bench ");
for i in 0..words {
s.push_str("word");