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:
1 parent
ff0fb56c67
commit
a02b555e66
1458 files changed
+10729
-21750
No files matched your search
@@ -1,7 +1,7 @@
|
||||
//! Item filtering and user-query extraction for history compaction —
|
||||
//! generic over [`CompactionItem`] / [`CompactionItemBuilder`].
|
||||
//!
|
||||
//! Behavior is byte-for-byte identical for Kigi chat (`T = Arc<KigiTurn>`).
|
||||
//! Behavior matches Kigi chat (`T = Arc<KigiTurn>`).
|
||||
|
||||
use tracing::info;
|
||||
|
||||
@@ -48,10 +48,9 @@ pub fn filter_turns_for_inter_compaction<T: CompactionItemBuilder>(turns: &[T])
|
||||
turns
|
||||
.iter()
|
||||
.filter_map(|turn| match turn.role() {
|
||||
// Drop tool and system items.
|
||||
CompactionRole::Tool | CompactionRole::System => None,
|
||||
|
||||
// Keep prior compaction summaries; drop all other developer items.
|
||||
// Keep prior compaction summaries; drop other developer items.
|
||||
CompactionRole::Developer => {
|
||||
if turn.is_compaction_summary() {
|
||||
Some(turn.clone())
|
||||
@@ -60,10 +59,8 @@ pub fn filter_turns_for_inter_compaction<T: CompactionItemBuilder>(turns: &[T])
|
||||
}
|
||||
}
|
||||
|
||||
// Keep user items.
|
||||
CompactionRole::User => Some(turn.clone()),
|
||||
|
||||
// Filter assistant item contents.
|
||||
CompactionRole::Assistant => turn.strip_tool_content(),
|
||||
})
|
||||
.collect()
|
||||
@@ -152,7 +149,8 @@ pub fn truncate_middle(msg: &str, max_chars: usize) -> Option<String> {
|
||||
return None;
|
||||
}
|
||||
let front_len = max_chars / 2;
|
||||
let back_len = max_chars - front_len; // handles odd max_chars
|
||||
// handles odd max_chars
|
||||
let back_len = max_chars - front_len;
|
||||
let front: String = msg.chars().take(front_len).collect();
|
||||
let back: String = msg.chars().skip(char_count - back_len).collect();
|
||||
Some(format!("{}...[truncated]...{}", front, back))
|
||||
@@ -291,10 +289,8 @@ pub fn separate_prior_user_queries<T: CompactionItemBuilder>(
|
||||
None => prior_user_queries = Some(user_sec),
|
||||
}
|
||||
}
|
||||
// Matches inter's previous inline behavior (`if !rest.is_empty()`):
|
||||
// a prior compaction item whose entire content was the
|
||||
// `<kigi_user_queries>` block (and therefore stripped to an empty
|
||||
// `rest`) contributes nothing for the LLM and is dropped here.
|
||||
// Prior compaction whose content was only `<kigi_user_queries>`
|
||||
// (empty `rest` after strip) contributes nothing for the LLM.
|
||||
if !rest.is_empty() {
|
||||
turns_for_llm.push(T::compaction_summary_item(rest));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Conversation history compaction — shared selection/assembly logic for compacting
|
||||
//! prior conversation turns into a summary.
|
||||
//! Shared selection/assembly logic for compacting prior conversation turns
|
||||
//! into a summary.
|
||||
//!
|
||||
//! Everything here is generic over [`CompactionItem`](crate::CompactionItem)
|
||||
//! / [`CompactionItemBuilder`](crate::CompactionItemBuilder) or pure
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
/// Builds the developer prompt to send to the compaction model.
|
||||
pub fn format_compaction_developer_prompt() -> Result<String> {
|
||||
Ok(include_str!("../templates/compaction_developer_prompt.txt").to_string())
|
||||
}
|
||||
|
||||
/// Builds the user prompt to send to the compaction model.
|
||||
pub fn format_compaction_user_prompt() -> Result<String> {
|
||||
Ok(include_str!("../templates/compaction_user_prompt.txt").to_string())
|
||||
}
|
||||
@@ -27,9 +25,8 @@ mod tests {
|
||||
assert!(!user.trim().is_empty(), "user prompt empty");
|
||||
}
|
||||
|
||||
/// Belt-and-suspenders: the developer and user prompts are intentionally
|
||||
/// identical so the model sees the instructions on both turns. If you edit
|
||||
/// one, edit the other — this test catches drift.
|
||||
/// The two templates are separate files that must stay byte-identical; this
|
||||
/// catches drift when only one is edited.
|
||||
#[test]
|
||||
fn compaction_prompts_match() {
|
||||
let dev = format_compaction_developer_prompt().expect("dev prompt renders");
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Strategy for how conversation compaction is performed.
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CompactionStrategy {
|
||||
/// Send all turns to the LLM in one shot (original behaviour).
|
||||
/// Send all turns to the LLM in one shot.
|
||||
#[default]
|
||||
Basic,
|
||||
/// Divide turns into ≤ `dnc_chunk_token_limit` chunks, compact each,
|
||||
|
||||
@@ -44,12 +44,10 @@ pub fn validate_compaction_text(
|
||||
text_content: &str,
|
||||
strategy: &CompactionStrategy,
|
||||
) -> Result<(), CompactionValidationError> {
|
||||
// 1. Non-empty text content
|
||||
if text_content.trim().is_empty() {
|
||||
return Err(CompactionValidationError::EmptyContent);
|
||||
}
|
||||
|
||||
// 2. DnC: validate chunk_summary tags are balanced
|
||||
if matches!(strategy, CompactionStrategy::DivideAndConquer) {
|
||||
let open_count = text_content.matches("<chunk_summary").count();
|
||||
let close_count = text_content.matches("</chunk_summary>").count();
|
||||
|
||||
Reference in new issue
Block a user