Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: track agent wiki file changes

nash_su823c81b7942e
diff --git a/src-tauri/src/agent/runtime.rs b/src-tauri/src/agent/runtime.rs
index b25d8a6b..ee4b49d0 100644
--- a/src-tauri/src/agent/runtime.rs
+++ b/src-tauri/src/agent/runtime.rs
@@ -394,10 +394,21 @@ impl AgentRuntime {
)
.await
.and_then(|value| {
- serde_json::from_value::<AgentReference>(value)
+ serde_json::from_value::<tools::WikiWriteOutput>(value)
.map_err(|err| format!("Invalid wiki.write_page result: {err}"))
}) {
- Ok(reference) => {
+ Ok(output) => {
+ emit_event(
+ &mut events,
+ &event_sink,
+ AgentEvent::FileChanged {
+ path: output.reference.path.clone(),
+ tool: "wiki.write_page".to_string(),
+ existed_before: output.existed_before,
+ previous_content: output.previous_content,
+ },
+ );
+ let reference = output.reference;
emit_event(
&mut events,
&event_sink,
@@ -2147,8 +2158,19 @@ impl AgentRuntime {
))
}
"wiki.write_page" => {
- let reference: AgentReference = serde_json::from_value(value)
+ let output: tools::WikiWriteOutput = serde_json::from_value(value)
.map_err(|err| format!("Invalid wiki.write_page result: {err}"))?;
+ emit_event(
+ events,
+ event_sink,
+ AgentEvent::FileChanged {
+ path: output.reference.path.clone(),
+ tool: "wiki.write_page".to_string(),
+ existed_before: output.existed_before,
+ previous_content: output.previous_content,
+ },
+ );
+ let reference = output.reference;
let path = reference.path.clone();
push_unique_reference(references, events, event_sink, reference);
Ok(format!("wrote {path}"))
diff --git a/src-tauri/src/agent/tools.rs b/src-tauri/src/agent/tools.rs
index d108b02c..bc74d7fe 100644
--- a/src-tauri/src/agent/tools.rs
+++ b/src-tauri/src/agent/tools.rs
@@ -124,7 +124,7 @@ impl ToolRegistry for BuiltinToolRegistry {
.or_else(|| input.get("allow_overwrite"))
.and_then(Value::as_bool)
.unwrap_or(false);
- serde_json::to_value(write_wiki_page_with_options(
+ serde_json::to_value(write_wiki_page_with_activity(
context.project_path,
path,
content,
@@ -304,6 +304,17 @@ pub struct WorkspaceWriteOutput {
pub previous_content: Option<String>,
}
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct WikiWriteOutput {
+ #[serde(flatten)]
+ pub reference: AgentReference,
+ #[serde(default)]
+ pub existed_before: bool,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub previous_content: Option<String>,
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct WebSearchConfig {
@@ -626,6 +637,15 @@ pub fn write_wiki_page_with_options(
content: &str,
allow_overwrite: bool,
) -> Result<AgentReference, String> {
+ Ok(write_wiki_page_with_activity(project_path, rel_path, content, allow_overwrite)?.reference)
+}
+
+fn write_wiki_page_with_activity(
+ project_path: &str,
+ rel_path: &str,
+ content: &str,
+ allow_overwrite: bool,
+) -> Result<WikiWriteOutput, String> {
if content.len() > MAX_WRITE_PAGE_BYTES {
return Err("wiki.write_page content is too large".to_string());
}
@@ -648,20 +668,26 @@ pub fn write_wiki_page_with_options(
.to_string(),
);
}
+ let existed_before = path.is_file();
+ let previous_content = workspace_rollback_snapshot(&path);
fs::write(&path, content).map_err(|err| format!("Failed to write wiki page: {err}"))?;
- Ok(AgentReference {
- title: extract_markdown_title(content).unwrap_or_else(|| {
- Path::new(&rel)
- .file_stem()
- .and_then(|s| s.to_str())
- .unwrap_or("Wiki page")
- .replace('-', " ")
- }),
- path: rel,
- kind: "wiki".to_string(),
- snippet: Some(trim_text(&collapse_markdown_preview(content), 500))
- .filter(|value| !value.trim().is_empty()),
- score: None,
+ Ok(WikiWriteOutput {
+ reference: AgentReference {
+ title: extract_markdown_title(content).unwrap_or_else(|| {
+ Path::new(&rel)
+ .file_stem()
+ .and_then(|s| s.to_str())
+ .unwrap_or("Wiki page")
+ .replace('-', " ")
+ }),
+ path: rel,
+ kind: "wiki".to_string(),
+ snippet: Some(trim_text(&collapse_markdown_preview(content), 500))
+ .filter(|value| !value.trim().is_empty()),
+ score: None,
+ },
+ existed_before,
+ previous_content,
})
}
@@ -2779,6 +2805,35 @@ mod tests {
let _ = fs::remove_dir_all(root);
}
+ #[test]
+ fn wiki_write_activity_captures_create_and_overwrite_state() {
+ let root =
+ std::env::temp_dir().join(format!("llm-wiki-agent-write-activity-{}", Uuid::new_v4()));
+ fs::create_dir_all(root.join("wiki")).unwrap();
+
+ let created = write_wiki_page_with_activity(
+ root.to_str().unwrap(),
+ "wiki/page.md",
+ "# Original",
+ false,
+ )
+ .unwrap();
+ assert!(!created.existed_before);
+ assert_eq!(created.previous_content, None);
+
+ let modified = write_wiki_page_with_activity(
+ root.to_str().unwrap(),
+ "wiki/page.md",
+ "# Updated",
+ true,
+ )
+ .unwrap();
+ assert!(modified.existed_before);
+ assert_eq!(modified.previous_content.as_deref(), Some("# Original"));
+ assert_eq!(modified.reference.path, "wiki/page.md");
+ let _ = fs::remove_dir_all(root);
+ }
+
#[cfg(unix)]
#[test]
fn write_wiki_page_rejects_symlink_parent_escape_for_new_files() {