docs: Add comprehensive documentation for modes, services, and plugins

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 14:29:16 -03:00
parent d44f3fbb5b
commit 88c7290a7b
6 changed files with 146 additions and 12 deletions

View File

@@ -11,6 +11,22 @@ use crate::services::item_service::ItemService;
use chrono::prelude::*;
use comfy_table::{Cell, Attribute};
/// Displays detailed information about an item or the last item if no ID/tags specified.
///
/// Supports table, JSON, or YAML output formats.
///
/// # Arguments
///
/// * `cmd` - Mutable Clap command for error handling.
/// * `settings` - Application settings.
/// * `ids` - Mutable vector of item IDs (at most one).
/// * `tags` - Mutable vector of tags (mutually exclusive with IDs).
/// * `conn` - Mutable database connection.
/// * `data_path` - Path to data directory.
///
/// # Returns
///
/// `Ok(())` on success, or Result with error.
pub fn mode_info(
cmd: &mut Command,
settings: &config::Settings,
@@ -37,7 +53,8 @@ pub fn mode_info(
}
#[derive(Debug, Serialize, Deserialize)]
struct ItemInfo {
/// Structured representation of item information for JSON/YAML output.
pub struct ItemInfo {
id: i64,
timestamp: String,
path: String,
@@ -55,6 +72,17 @@ fn show_item(
settings: &config::Settings,
data_path: PathBuf,
) -> Result<()> {
/// Displays item information in table format or delegates to structured output.
///
/// # Arguments
///
/// * `item_with_meta` - Item with associated metadata and tags.
/// * `settings` - Application settings for formatting.
/// * `data_path` - Path to data directory for file size calculation.
///
/// # Returns
///
/// `Ok(())` on success.
let output_format = crate::modes::common::settings_output_format(settings);
if output_format != OutputFormat::Table {
@@ -135,6 +163,18 @@ fn show_item_structured(
data_path: PathBuf,
output_format: OutputFormat,
) -> Result<()> {
/// Displays item information in structured JSON or YAML format.
///
/// # Arguments
///
/// * `item_with_meta` - Item with metadata and tags.
/// * `settings` - Settings for size formatting.
/// * `data_path` - Data path for file size.
/// * `output_format` - JSON or YAML.
///
/// # Returns
///
/// `Ok(())` on success.
let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let meta_map = item_with_meta.meta_as_map();
let item = item_with_meta.item;

View File

@@ -5,15 +5,43 @@ use crate::modes::server::common::AppState;
use super::tools::{KeepTools, ToolError};
#[derive(Clone)]
/// Server handler for MCP (Model Context Protocol) requests.
///
/// Routes requests to appropriate tools and handles responses.
pub struct KeepMcpServer {
state: AppState,
}
impl KeepMcpServer {
/// Creates a new `KeepMcpServer` instance.
///
/// # Arguments
///
/// * `state` - The application state containing DB and config.
///
/// # Returns
///
/// A new `KeepMcpServer`.
pub fn new(state: AppState) -> Self {
Self { state }
}
/// Handles an MCP request by routing to the appropriate tool.
///
/// Supports methods like save_item, get_item, etc.
///
/// # Arguments
///
/// * `method` - The MCP method name.
/// * `params` - Optional JSON parameters.
///
/// # Returns
///
/// JSON string response on success, or ToolError.
///
/// # Errors
///
/// Returns ToolError::UnknownTool for unsupported methods.
pub async fn handle_request(&self, method: &str, params: Option<Value>) -> Result<String, ToolError> {
debug!("MCP: Handling request '{}' with params: {:?}", method, params);

View File

@@ -3,7 +3,18 @@ use std::path::PathBuf;
use std::str::FromStr;
use log::debug;
// Helper function to convert serde_json::Value to serde_yaml::Value
/// Helper function to convert serde_json::Value to serde_yaml::Value.
///
/// Recursively converts JSON values to equivalent YAML values, handling null, bool, number,
/// string, array, and object types.
///
/// # Arguments
///
/// * `value` - Reference to the JSON value to convert.
///
/// # Returns
///
/// The equivalent YAML value.
fn convert_json_to_yaml_value(value: &serde_json::Value) -> serde_yaml::Value {
match value {
serde_json::Value::Null => serde_yaml::Value::Null,
@@ -49,6 +60,17 @@ use crate::common::status::{MetaPluginInfo, CompressionInfo};
fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> Table {
/// Builds a formatted table displaying meta plugin information.
///
/// Sorts plugins by name and displays options as YAML and outputs as a list.
///
/// # Arguments
///
/// * `meta_plugin_info` - HashMap of meta plugin information.
///
/// # Returns
///
/// A formatted `comfy_table::Table`.
let mut meta_plugin_table = crate::modes::common::create_table(true);
meta_plugin_table.set_header(vec![
@@ -110,6 +132,15 @@ fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String,
}
fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
/// Builds a formatted table displaying compression plugin information.
///
/// # Arguments
///
/// * `compression_info` - Vector of compression info.
///
/// # Returns
///
/// A formatted `comfy_table::Table`.
let mut compression_table = crate::modes::common::create_table(true);
compression_table.set_header(vec![
@@ -142,6 +173,17 @@ fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
}
fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> Table {
/// Builds a formatted table displaying filter plugin information.
///
/// Sorts plugins by name and formats options as YAML sequence.
///
/// # Arguments
///
/// * `filter_plugins` - Vector of filter plugin info.
///
/// # Returns
///
/// A formatted `comfy_table::Table`.
let mut filter_plugin_table = crate::modes::common::create_table(true);
filter_plugin_table.set_header(vec![