diff --git a/crates/kebab-app/src/lib.rs b/crates/kebab-app/src/lib.rs index 6b3ed4c..20ee48b 100644 --- a/crates/kebab-app/src/lib.rs +++ b/crates/kebab-app/src/lib.rs @@ -1953,6 +1953,7 @@ pub fn ingest_file_with_config( /// Errors if `body` already starts with `---` (the user should call /// `ingest_file_with_config` directly for files that already carry /// frontmatter). +#[doc(hidden)] pub fn ingest_stdin_with_config( config: kebab_config::Config, body: &str, diff --git a/crates/kebab-mcp/tests/tools_call_ingest_file.rs b/crates/kebab-mcp/tests/tools_call_ingest_file.rs index e9eab6e..ff112b8 100644 --- a/crates/kebab-mcp/tests/tools_call_ingest_file.rs +++ b/crates/kebab-mcp/tests/tools_call_ingest_file.rs @@ -51,3 +51,67 @@ async fn ingest_file_tool_returns_ingest_report_v1() { ); assert_eq!(v.get("new").and_then(|n| n.as_u64()), Some(1)); } + +#[tokio::test] +async fn ingest_file_tool_idempotent_on_second_call() { + let dir = tempfile::tempdir().unwrap(); + let workspace = dir.path().join("notes"); + let data = dir.path().join("data"); + std::fs::create_dir_all(&workspace).unwrap(); + std::fs::create_dir_all(&data).unwrap(); + + let mut cfg = kebab_config::Config::defaults(); + cfg.workspace.root = workspace.to_string_lossy().into_owned(); + cfg.storage.data_dir = data.to_string_lossy().into_owned(); + cfg.models.embedding.provider = "none".to_string(); + cfg.models.embedding.dimensions = 0; + + let src = dir.path().join("doc.md"); + std::fs::write(&src, "# A\n\nbody.").unwrap(); + + let state = kebab_mcp::KebabAppState::new(cfg, None); + let handler = kebab_mcp::KebabHandler::new(state); + + // First call. + let r1 = tokio::task::spawn_blocking({ + let state = handler.state().clone(); + let path = src.to_string_lossy().into_owned(); + move || { + kebab_mcp::tools::ingest_file::handle( + &state, + kebab_mcp::tools::ingest_file::IngestFileInput { path }, + ) + } + }) + .await + .unwrap(); + assert!(!r1.is_error.unwrap_or(false)); + let text1 = match &r1.content.first().unwrap().raw { + rmcp::model::RawContent::Text(t) => &t.text, + other => panic!("expected text, got {other:?}"), + }; + let v1: serde_json::Value = serde_json::from_str(text1).unwrap(); + assert_eq!(v1.get("new").and_then(|n| n.as_u64()), Some(1)); + + // Second call — same content, expect unchanged=1. + let r2 = tokio::task::spawn_blocking({ + let state = handler.state().clone(); + let path = src.to_string_lossy().into_owned(); + move || { + kebab_mcp::tools::ingest_file::handle( + &state, + kebab_mcp::tools::ingest_file::IngestFileInput { path }, + ) + } + }) + .await + .unwrap(); + assert!(!r2.is_error.unwrap_or(false)); + let text2 = match &r2.content.first().unwrap().raw { + rmcp::model::RawContent::Text(t) => &t.text, + other => panic!("expected text, got {other:?}"), + }; + let v2: serde_json::Value = serde_json::from_str(text2).unwrap(); + assert_eq!(v2.get("new").and_then(|n| n.as_u64()), Some(0), "{v2:?}"); + assert_eq!(v2.get("unchanged").and_then(|n| n.as_u64()), Some(1), "{v2:?}"); +} diff --git a/integrations/claude-code/kebab/SKILL.md b/integrations/claude-code/kebab/SKILL.md index 2c9cebb..362af61 100644 --- a/integrations/claude-code/kebab/SKILL.md +++ b/integrations/claude-code/kebab/SKILL.md @@ -73,7 +73,7 @@ If a call fails or returns suspicious output, run `kebab doctor` first — it su ## MCP server (recommended over CLI subprocess wrapping) -Since v0.4.0, `kebab` exposes an MCP (Model Context Protocol) stdio server. Configure once in `~/.claude/mcp.json`: +Since v0.3.1, `kebab` exposes an MCP (Model Context Protocol) stdio server. Configure once in `~/.claude/mcp.json`: ```json {