Skip to content

Commit 71eca50

Browse files
Test UserTerraphim AI
andcommitted
docs: add item-level rustdoc to 7 worst-offender crates Refs #2137
248 doc comments added across 30 files: - terraphim_grep: 91 items (95% gap -> <5%) - terraphim-markdown-parser: 45 items (79% gap -> <5%) - terraphim_usage: 68 items (68% gap -> <5%) - terraphim_agent_messaging: 22 items - terraphim_merge_coordinator: 13 items - terraphim_file_search: 6 items - terraphim_middleware: 3 items All clippy/fmt checks pass on affected crates. Co-Authored-By: Terraphim AI <noreply@terraphim.ai>
1 parent 907b964 commit 71eca50

31 files changed

Lines changed: 336 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- **terraphim_grep hybrid searcher** complete implementation: parallel KG + grep execution via `tokio::spawn`, CLI with thesaurus discovery, `Serialize` on `GrepResult`/`GrepStats`/`SufficiencyState` (Refs #1743, PR#1825, 2026-05-24)
1919
- **terraphim_merge_coordinator** minimal skeleton proving crate structure (Refs #1805, PR#1823, 2026-05-23)
2020
- **Config-error circuit-breaker** `ExitClass::ConfigError` quarantines agents after 3 consecutive config failures; `AgentDefinition.enabled` field; memory watchdog systemd units; `bigbox-sync.sh` (Refs #1817, PR#1822, 2026-05-23)
21+
- **Rustdoc gaps resolved** doc comments added to public items in `terraphim_grep` (95% gap, 91 items), `terraphim-markdown-parser` (79% gap, 45 items), `terraphim_usage` (68% gap, 68 items), `terraphim_agent_messaging` (22 items), `terraphim_file_search`, `terraphim_merge_coordinator`, and `terraphim_middleware` -- 248 doc comments added across 30 files (Refs #2137, 2026-06-05)
2122
- **Rustdoc gaps resolved** doc comments added to all public items in `terraphim_types` (`LlmUsage`, `LlmResult`, `ModelPricing`, `ReviewFinding`, `ReviewAgentOutput`, `FindingSeverity`, `FindingCategory`, `DocumentType`, `MarkdownDirectives`, `Scorer`, `Query`, `Similarity`, `ScoreError`, and score sub-modules) -- 93 warnings eliminated (2026-05-30)
2223
- **terraphim_rlm CLI binary** with 6 commands (code, bash, query, context, snapshot, status) for stateless RLM execution (Refs #RLM-CLI, 2026-05-18)
2324
- **MCP server RLM integration** via process spawning — 6 new tools exposed without linking terraphim_rlm (avoids static init hang) (Refs #RLM-CLI, 2026-05-18)

crates/terraphim-markdown-parser/src/chunk.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ use ulid::Ulid;
33
use crate::NormalizedMarkdown;
44
use crate::heading::{HeadingNode, HeadingTree, SectionType};
55

6+
/// Represents a semantically coherent chunk of content under a heading, ready for indexing.
67
#[derive(Debug, Clone)]
78
pub struct ContentChunk {
9+
/// The composite identifier combining content source, section path, and first block ULID.
810
pub chunk_id: String,
11+
/// The identifier of the source document this chunk belongs to.
912
pub content_id: String,
13+
/// The ordered list of block ULIDs whose text makes up this chunk.
1014
pub block_ids: Vec<Ulid>,
15+
/// The chapter number assigned by depth-first traversal order, if applicable.
1116
pub chapter_number: Option<u8>,
17+
/// The dot-separated path of section indices, e.g. `"1.2.3"`.
1218
pub section_path: String,
19+
/// The classified section type for this chunk (main body, sidebar, career, assessment).
1320
pub chunk_type: SectionType,
21+
/// The plain text content of the chunk with block-id comments stripped.
1422
pub text: String,
23+
/// The approximate token count based on whitespace-delimited words.
1524
pub token_count: u32,
1625
}
1726

1827
struct ChunkState {
1928
chapter_counter: u8,
2029
}
2130

31+
/// Builds a flat list of [`ContentChunk`]s by traversing the heading tree depth-first.
2232
pub fn chunk_by_headings(
2333
content_id: &str,
2434
tree: &HeadingTree,

crates/terraphim-markdown-parser/src/heading.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ pub enum MatchStrategy {
1515
Contains,
1616
}
1717

18+
/// Describes the semantic role of a heading section in a document.
1819
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1920
pub enum SectionType {
21+
/// The primary body content of the section.
2022
Main,
23+
/// A named sidebar or callout box, identified by its label.
2124
Sidebar(String),
25+
/// A career-focused section (e.g. "Selling U" textbook sections).
2226
Career,
27+
/// An assessment or review section (e.g. key takeaways, quizzes).
2328
Assessment,
2429
}
2530

@@ -34,19 +39,26 @@ impl std::fmt::Display for SectionType {
3439
}
3540
}
3641

42+
/// Represents a single rule that maps a heading title pattern to a [`SectionType`].
3743
#[derive(Debug, Clone, Serialize, Deserialize)]
3844
pub struct SectionPattern {
45+
/// The string pattern to match against a heading title.
3946
pub pattern: String,
47+
/// The section type to assign when the pattern matches.
4048
pub section_type: SectionType,
49+
/// The strategy used to compare the heading title against `pattern`.
4150
pub match_strategy: MatchStrategy,
4251
}
4352

53+
/// Represents an ordered collection of [`SectionPattern`] rules for classifying headings.
4454
#[derive(Debug, Clone, Serialize, Deserialize)]
4555
pub struct SectionConfig {
56+
/// The ordered list of pattern rules; first match wins.
4657
pub rules: Vec<SectionPattern>,
4758
}
4859

4960
impl SectionConfig {
61+
/// Returns a default [`SectionConfig`] with common textbook section patterns pre-configured.
5062
pub fn textbook_default() -> Self {
5163
Self {
5264
rules: vec![
@@ -86,6 +98,7 @@ impl SectionConfig {
8698
}
8799
}
88100

101+
/// Classifies a heading `title` against the configured rules, returning the matched [`SectionType`].
89102
pub fn classify(&self, title: &str) -> SectionType {
90103
let title_trimmed = title.trim();
91104
for rule in &self.rules {
@@ -107,21 +120,31 @@ impl Default for SectionConfig {
107120
}
108121
}
109122

123+
/// Represents a single node in the heading hierarchy tree.
110124
#[derive(Debug, Clone)]
111125
pub struct HeadingNode {
126+
/// The heading depth level (1 for `#`, 2 for `##`, etc.).
112127
pub level: u8,
128+
/// The plain-text title extracted from the heading.
113129
pub title: String,
130+
/// The classified section type for this heading.
114131
pub section_type: SectionType,
132+
/// The ULIDs of blocks whose content falls directly under this heading.
115133
pub blocks: Vec<Ulid>,
134+
/// The child heading nodes nested beneath this heading.
116135
pub children: Vec<HeadingNode>,
136+
/// The byte range in the source covering this heading and its content.
117137
pub byte_range: Range<usize>,
118138
}
119139

140+
/// Represents the full heading hierarchy extracted from a normalised markdown document.
120141
#[derive(Debug, Clone)]
121142
pub struct HeadingTree {
143+
/// The top-level heading nodes (depth-1 headings or document roots).
122144
pub roots: Vec<HeadingNode>,
123145
}
124146

147+
/// Builds a [`HeadingTree`] from the AST embedded in a [`NormalizedMarkdown`] value.
125148
pub fn build_heading_tree(
126149
normalized: &NormalizedMarkdown,
127150
) -> Result<HeadingTree, MarkdownParserError> {
@@ -134,6 +157,7 @@ pub fn build_heading_tree(
134157
Ok(tree)
135158
}
136159

160+
/// Classifies every node in the heading tree in-place using the provided [`SectionConfig`].
137161
pub fn classify_sections(tree: &mut HeadingTree, config: &SectionConfig) {
138162
for root in &mut tree.roots {
139163
classify_node(root, config);

crates/terraphim-markdown-parser/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use heading::{
2121
build_heading_tree, classify_sections,
2222
};
2323

24+
/// The prefix used inside HTML comments to identify Terraphim block-id anchors.
2425
pub const TERRAPHIM_BLOCK_ID_PREFIX: &str = "terraphim:block-id:";
2526

2627
/// Extract the first H1 heading from markdown content using AST parsing.
@@ -69,15 +70,21 @@ pub(crate) fn collect_text_content(nodes: &[Node]) -> String {
6970
text
7071
}
7172

73+
/// Describes the structural kind of a Terraphim block.
7274
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7375
pub enum BlockKind {
76+
/// A standalone markdown paragraph block.
7477
Paragraph,
78+
/// A markdown list-item block.
7579
ListItem,
7680
}
7781

82+
/// Represents a single annotated content block extracted from normalised markdown.
7883
#[derive(Debug, Clone, PartialEq, Eq)]
7984
pub struct Block {
85+
/// The stable unique identifier assigned to this block.
8086
pub id: Ulid,
87+
/// The structural kind of this block (paragraph or list item).
8188
pub kind: BlockKind,
8289

8390
/// Byte span of the block in the markdown buffer.
@@ -93,13 +100,18 @@ pub struct Block {
93100
pub id_span: Range<usize>,
94101
}
95102

103+
/// Represents markdown content that has been normalised with stable Terraphim block-id anchors.
96104
#[derive(Debug, Clone)]
97105
pub struct NormalizedMarkdown {
106+
/// The normalised markdown source with all block-id comments inserted.
98107
pub markdown: String,
108+
/// The ordered list of blocks extracted from the normalised source.
99109
pub blocks: Vec<Block>,
110+
/// The parsed AST of the normalised markdown, if available.
100111
pub ast: Option<markdown::mdast::Node>,
101112
}
102113

114+
/// Describes errors that can occur during markdown parsing and normalisation.
103115
#[derive(Debug, Error)]
104116
pub enum MarkdownParserError {
105117
#[error("failed to parse markdown: {0}")]

crates/terraphim_agent_messaging/src/delivery.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,30 @@ pub enum DeliveryStatus {
3737
/// Delivery record for tracking message delivery
3838
#[derive(Debug, Clone, Serialize, Deserialize)]
3939
pub struct DeliveryRecord {
40+
/// The unique identifier of the tracked message.
4041
pub message_id: MessageId,
42+
/// The sending agent, if known.
4143
pub from: Option<AgentPid>,
44+
/// The intended recipient agent.
4245
pub to: AgentPid,
46+
/// The current delivery status.
4347
pub status: DeliveryStatus,
48+
/// Number of delivery attempts made so far.
4449
pub attempts: u32,
50+
/// The UTC timestamp when the record was created.
4551
pub created_at: DateTime<Utc>,
52+
/// The UTC timestamp of the most recent delivery attempt.
4653
pub last_attempt: Option<DateTime<Utc>>,
54+
/// The UTC timestamp when the message was delivered.
4755
pub delivered_at: Option<DateTime<Utc>>,
56+
/// The UTC timestamp when the message was acknowledged.
4857
pub acknowledged_at: Option<DateTime<Utc>>,
58+
/// The error description from the most recent failed attempt.
4959
pub error_message: Option<String>,
5060
}
5161

5262
impl DeliveryRecord {
63+
/// Creates a new pending delivery record for the given message.
5364
pub fn new(message_id: MessageId, from: Option<AgentPid>, to: AgentPid) -> Self {
5465
Self {
5566
message_id,
@@ -65,31 +76,37 @@ impl DeliveryRecord {
6576
}
6677
}
6778

79+
/// Transitions the record to `InTransit` and increments the attempt counter.
6880
pub fn mark_in_transit(&mut self) {
6981
self.status = DeliveryStatus::InTransit;
7082
self.attempts += 1;
7183
self.last_attempt = Some(Utc::now());
7284
}
7385

86+
/// Transitions the record to `Delivered` and records the delivery timestamp.
7487
pub fn mark_delivered(&mut self) {
7588
self.status = DeliveryStatus::Delivered;
7689
self.delivered_at = Some(Utc::now());
7790
}
7891

92+
/// Transitions the record to `Acknowledged` and records the acknowledgement timestamp.
7993
pub fn mark_acknowledged(&mut self) {
8094
self.status = DeliveryStatus::Acknowledged;
8195
self.acknowledged_at = Some(Utc::now());
8296
}
8397

98+
/// Transitions the record to `Failed` and stores the error description.
8499
pub fn mark_failed(&mut self, error: String) {
85100
self.status = DeliveryStatus::Failed(error.clone());
86101
self.error_message = Some(error);
87102
}
88103

104+
/// Transitions the record to `Expired`.
89105
pub fn mark_expired(&mut self) {
90106
self.status = DeliveryStatus::Expired;
91107
}
92108

109+
/// Returns `true` if the record is in a terminal state (acknowledged, failed, or expired).
93110
pub fn is_final_state(&self) -> bool {
94111
matches!(
95112
self.status,
@@ -390,6 +407,7 @@ pub struct DeliveryStats {
390407
}
391408

392409
impl DeliveryStats {
410+
/// Returns the fraction of messages that were successfully acknowledged.
393411
pub fn success_rate(&self) -> f64 {
394412
if self.total_messages == 0 {
395413
0.0
@@ -398,6 +416,7 @@ impl DeliveryStats {
398416
}
399417
}
400418

419+
/// Returns the fraction of messages that failed delivery.
401420
pub fn failure_rate(&self) -> f64 {
402421
if self.total_messages == 0 {
403422
0.0
@@ -406,6 +425,7 @@ impl DeliveryStats {
406425
}
407426
}
408427

428+
/// Returns the average number of delivery attempts per message.
409429
pub fn average_attempts(&self) -> f64 {
410430
if self.total_messages == 0 {
411431
0.0

crates/terraphim_agent_messaging/src/mailbox.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@ impl Default for MailboxConfig {
3737
/// Mailbox statistics
3838
#[derive(Debug, Clone, Serialize, Deserialize)]
3939
pub struct MailboxStats {
40+
/// The identifier of the agent owning this mailbox.
4041
pub agent_id: AgentPid,
42+
/// Total number of messages received since creation.
4143
pub total_messages_received: u64,
44+
/// Total number of messages processed since creation.
4245
pub total_messages_processed: u64,
46+
/// Current number of messages waiting in the queue.
4347
pub current_queue_size: usize,
48+
/// Peak queue depth observed since creation.
4449
pub max_queue_size_reached: usize,
50+
/// Timestamp of the most recently received message.
4551
pub last_message_received: Option<DateTime<Utc>>,
52+
/// Timestamp of the most recently processed message.
4653
pub last_message_processed: Option<DateTime<Utc>>,
54+
/// Running average time taken to process each message.
4755
pub average_processing_time: std::time::Duration,
4856
}
4957

5058
impl MailboxStats {
59+
/// Creates zeroed statistics for the given agent.
5160
pub fn new(agent_id: AgentPid) -> Self {
5261
Self {
5362
agent_id,
@@ -61,13 +70,15 @@ impl MailboxStats {
6170
}
6271
}
6372

73+
/// Records the receipt of a new message and updates queue-depth counters.
6474
pub fn record_message_received(&mut self) {
6575
self.total_messages_received += 1;
6676
self.current_queue_size += 1;
6777
self.max_queue_size_reached = self.max_queue_size_reached.max(self.current_queue_size);
6878
self.last_message_received = Some(Utc::now());
6979
}
7080

81+
/// Records a processed message and updates the running average processing time.
7182
pub fn record_message_processed(&mut self, processing_time: std::time::Duration) {
7283
self.total_messages_processed += 1;
7384
self.current_queue_size = self.current_queue_size.saturating_sub(1);

crates/terraphim_agent_messaging/src/message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ use crate::AgentPid;
1717
pub struct MessageId(pub Uuid);
1818

1919
impl MessageId {
20+
/// Creates a new randomly-generated `MessageId`.
2021
pub fn new() -> Self {
2122
Self(Uuid::new_v4())
2223
}
2324

25+
/// Returns the string representation of the message ID.
2426
pub fn as_str(&self) -> String {
2527
self.0.to_string()
2628
}
@@ -295,13 +297,18 @@ impl MessageEnvelope {
295297

296298
/// Typed message wrapper for type-safe messaging
297299
pub struct TypedMessage<T> {
300+
/// The unique identifier for this message.
298301
pub id: MessageId,
302+
/// The sending agent, if known.
299303
pub from: Option<AgentPid>,
304+
/// The typed message payload.
300305
pub payload: T,
306+
/// The UTC timestamp when this message was created.
301307
pub created_at: DateTime<Utc>,
302308
}
303309

304310
impl<T> TypedMessage<T> {
311+
/// Creates a new `TypedMessage` wrapping the given payload.
305312
pub fn new(payload: T) -> Self {
306313
Self {
307314
id: MessageId::new(),
@@ -311,6 +318,7 @@ impl<T> TypedMessage<T> {
311318
}
312319
}
313320

321+
/// Sets the sending agent for this message.
314322
pub fn with_from(mut self, from: AgentPid) -> Self {
315323
self.from = Some(from);
316324
self

crates/terraphim_agent_messaging/src/router.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ use crate::{
1818
/// Message router configuration
1919
#[derive(Debug, Clone)]
2020
pub struct RouterConfig {
21+
/// Delivery guarantee settings used for all routed messages.
2122
pub delivery_config: DeliveryConfig,
23+
/// How often the background task checks for messages to retry.
2224
pub retry_interval: Duration,
25+
/// Maximum number of in-flight deliveries processed concurrently.
2326
pub max_concurrent_deliveries: usize,
27+
/// Whether to collect routing metrics.
2428
pub enable_metrics: bool,
2529
}
2630

@@ -38,10 +42,15 @@ impl Default for RouterConfig {
3842
/// Router statistics
3943
#[derive(Debug, Default, Clone)]
4044
pub struct RouterStats {
45+
/// Total messages submitted to the router.
4146
pub messages_routed: u64,
47+
/// Total messages successfully delivered.
4248
pub messages_delivered: u64,
49+
/// Total messages that failed all delivery attempts.
4350
pub messages_failed: u64,
51+
/// Number of currently registered agent routes.
4452
pub active_routes: usize,
53+
/// Total retry attempts made by the background retry task.
4554
pub retry_attempts: u64,
4655
}
4756

0 commit comments

Comments
 (0)