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
@@ -1,4 +1,4 @@
//! `memory_get` tool — new architecture (`Tool` trait).
//! `memory_get` tool.
use std::sync::Arc;
@@ -7,17 +7,15 @@ use crate::types::memory_backend::MemoryBackend;
use crate::types::output::ToolOutput;
use crate::types::tool::{ToolKind, ToolNamespace};
/// Format content with line numbers: `{line_num}→{line}`.
///
/// Extracted as a free function so it can be unit-tested independently of
/// the async tool infrastructure. `first_line_num` is the 1-based number
/// for the first line of `content` (accounts for `from` offset).
/// Format content with line numbers: `{line_num}→{line}`. `first_line_num`
/// is the 1-based number of the first line of `content` (accounts for the
/// `from` offset).
///
/// Uses `split('\n')` rather than `lines()` so that content ending with a
/// newline (`"a\n"`) emits a trailing blank numbered line, matching the
/// behavior of the standard `read_file` tool. `lines()` would silently drop
/// that trailing element, causing off-by-one line references for files
/// (virtually all Markdown memory files) that end with a newline.
/// standard `read_file` tool. `lines()` would silently drop that trailing
/// element, causing off-by-one line references for files (virtually all
/// Markdown memory files) that end with a newline.
pub(crate) fn format_with_line_numbers(content: &str, first_line_num: usize) -> String {
if content.is_empty() {
return String::new();
@@ -124,51 +122,42 @@ impl kigi_tool_runtime::Tool for MemoryGetImpl {
mod tests {
use super::*;
/// format_with_line_numbers produces 1-based unpadded output.
#[test]
fn test_format_basic_line_numbers() {
let out = format_with_line_numbers("alpha\nbeta\ngamma", 1);
assert_eq!(out, "1→alpha\n2→beta\n3→gamma");
}
/// The `from` offset shifts the first line number so numbers reflect the
/// actual position in the source file, not the slice position.
#[test]
fn test_format_offset_adjusts_line_numbers() {
// Simulates memory_get called with from=4 (0-based) first displayed
// line should be labelled "5" (1-based).
// from=4 (0-based) makes the first displayed line number 5 (1-based).
let out = format_with_line_numbers("line five\nline six", 5);
assert!(out.starts_with("5→line five"), "got: {out}");
assert!(out.ends_with("6→line six"), "got: {out}");
}
/// Empty content produces empty output (no panic).
#[test]
fn test_format_empty_content() {
let out = format_with_line_numbers("", 1);
assert!(out.is_empty(), "empty input must produce empty output");
}
/// Single-line content produces one numbered line.
#[test]
fn test_format_single_line() {
let out = format_with_line_numbers("only line", 1);
assert_eq!(out, "1→only line");
}
/// Wide line numbers (>= 7 digits) are not truncated.
#[test]
fn test_format_large_line_numbers() {
let out = format_with_line_numbers("x", 1_000_000);
assert!(out.starts_with("1000000→"), "got: {out}");
}
/// Content ending with `\n` emits a trailing blank numbered line.
///
/// Regression test for the `lines()` vs `split('\n')` difference.
/// Virtually all Markdown memory files end with a trailing newline, so
/// without this fix `memory_get` line numbers are off-by-one relative to
/// `read_file` for any file that ends with a newline.
/// Regression test for the `lines()` vs `split('\n')` difference:
/// virtually all Markdown memory files end with a trailing newline, so
/// with `lines()` `memory_get` line numbers would be off-by-one relative
/// to `read_file`.
#[test]
fn test_format_trailing_newline_emits_blank_line() {
let out = format_with_line_numbers("alpha\n", 1);
@@ -178,14 +167,12 @@ mod tests {
);
}
/// Two trailing newlines produce two extra blank lines.
#[test]
fn test_format_double_trailing_newline() {
let out = format_with_line_numbers("a\n\n", 1);
assert_eq!(out, "1→a\n2→\n3→");
}
/// Content without a trailing newline does NOT produce a spurious blank line.
#[test]
fn test_format_no_trailing_newline_no_blank_line() {
let out = format_with_line_numbers("alpha", 1);
@@ -10,13 +10,11 @@ pub mod types;
pub use get_tool::MemoryGetImpl;
pub use search_tool::MemorySearchImpl;
/// Registered name of the `memory_search` tool.
///
/// Single source of truth shared between the tool definition and any
/// gating callers (e.g. shell-side slash-command availability checks).
/// Registered name of the `memory_search` tool. Single source of truth
/// shared between the tool definition and gating callers (e.g. shell-side
/// slash-command availability checks).
pub const MEMORY_SEARCH_TOOL_NAME: &str = "memory_search";
/// Registered name of the `memory_get` tool.
pub const MEMORY_GET_TOOL_NAME: &str = "memory_get";
#[cfg(test)]
@@ -1,4 +1,4 @@
//! `memory_search` tool — new architecture (`Tool` trait).
//! `memory_search` tool.
use std::sync::Arc;