Files
Kigi-CLI/crates/codegen/kigi-hunk-tracker/src/events.rs
T
ZacharyZhang-NY a02b555e66 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).
2026-07-23 16:55:39 -04:00

75 lines
2.6 KiB
Rust

//! Events emitted by the HunkTrackerActor.
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::sync::Arc;
use crate::types::{Hunk, HunkId, HunkLineInfo, HunkSource};
/// Why the tracker removed a hunk. Used by the LOC sink to decide whether to
/// negate the hunk's accumulated LOC contribution.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum HunkRemovalReason {
/// User accepted the hunk — lines are kept in the file and should
/// still count toward the author's LOC total.
Accepted,
/// User rejected/reverted the hunk — changes are undone, LOC should
/// be zeroed out.
Rejected,
/// Hunk was replaced during recomputation (overlapping edit created
/// a new hunk), baseline reset, or file cleanup. LOC should be
/// zeroed out (the replacement hunk has its own records).
Superseded,
}
/// Events emitted by the HunkTrackerActor when hunks change.
/// Sent via the update_tx channel to subscribers.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum HunkEvent {
/// A new hunk was created
HunkAdded { path: PathBuf, hunk: Arc<Hunk> },
/// A hunk stopped being tracked.
HunkRemoved {
path: PathBuf,
hunk_id: HunkId,
reason: HunkRemovalReason,
},
/// A hunk's position changed but content is the same
HunkMoved {
path: PathBuf,
hunk_id: HunkId,
new_line_info: HunkLineInfo,
},
/// A hunk's content changed in place (overlapping region, same hunk ID).
/// Emitted when an edit modifies a hunk without fully removing/recreating it.
///
/// `trigger_source` is the source of the *edit that triggered* this change
/// (before source-preservation logic). This lets LOC tracking attribute
/// the change correctly even when the hunk's own `source` field was
/// preserved from a prior agent edit.
///
/// `prev_lines_added` / `prev_lines_removed` are the line counts from the
/// previous version of this hunk, so the LOC sink can compute the delta
/// (new - prev) and attribute only the incremental change.
HunkContentChanged {
path: PathBuf,
hunk: Arc<Hunk>,
trigger_source: HunkSource,
prev_lines_added: usize,
prev_lines_removed: usize,
},
/// A file started being tracked
FileAdded { path: PathBuf, is_agent_file: bool },
/// A file stopped being tracked (all hunks gone, not an agent file)
FileRemoved { path: PathBuf },
/// The tracker updated a file's baseline (after accept or commit)
BaselineUpdated { path: PathBuf },
}