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: attach extracted file content to agent context

nash_su79893720d5f4
diff --git a/src-tauri/src/agent/context.rs b/src-tauri/src/agent/context.rs
index becf5763..1ff2f17a 100644
--- a/src-tauri/src/agent/context.rs
+++ b/src-tauri/src/agent/context.rs
@@ -242,7 +242,7 @@ fn build_user_context(input: AgentContextInput<'_>) -> String {
out
}
-pub fn load_explicit_context_files(
+pub async fn load_explicit_context_files(
project_path: &str,
requested: &[String],
) -> Vec<(String, String)> {
@@ -271,10 +271,21 @@ pub fn load_explicit_context_files(
if !candidate_canon.starts_with(&root_canon) || !candidate_canon.is_file() {
continue;
}
- let Some(content) = read_trimmed(&candidate_canon, MAX_EXPLICIT_FILE_CHARS) else {
+ // Reuse the application's canonical reader so @ attachments support
+ // the same PDF, Office, image, media, and text formats as previews.
+ // read_file moves blocking parsers onto Tauri's blocking pool.
+ let Ok(content) = crate::commands::fs::read_file(
+ candidate_canon.to_string_lossy().into_owned(),
+ Some(false),
+ )
+ .await
+ else {
continue;
};
- let fitted = trim_chars(&content, remaining.min(MAX_EXPLICIT_FILE_CHARS));
+ let fitted = trim_chars(content.trim(), remaining.min(MAX_EXPLICIT_FILE_CHARS));
+ if fitted.is_empty() {
+ continue;
+ }
remaining = remaining.saturating_sub(fitted.chars().count());
// The request uses a project-relative path so callers cannot select an
// arbitrary host file. Only after canonical containment succeeds do we
@@ -340,30 +351,34 @@ mod tests {
use crate::agent::router::route_query;
use crate::agent::types::{AgentMode, AgentToolOptions};
- #[test]
- fn explicit_context_files_are_project_scoped() {
+ #[tokio::test]
+ async fn explicit_context_files_are_project_scoped() {
let root =
std::env::temp_dir().join(format!("llm-wiki-context-files-{}", std::process::id()));
let _ = fs::remove_dir_all(&root);
fs::create_dir_all(root.join("wiki")).unwrap();
fs::create_dir_all(root.join(".llm-wiki")).unwrap();
fs::write(root.join("wiki/page.md"), "selected evidence").unwrap();
+ fs::write(root.join("wiki/figure.png"), [0_u8, 1, 2, 3]).unwrap();
fs::write(root.join(".llm-wiki/secret.md"), "hidden secret").unwrap();
let files = load_explicit_context_files(
root.to_str().unwrap(),
&[
"wiki/page.md".to_string(),
+ "wiki/figure.png".to_string(),
"../outside.md".to_string(),
".llm-wiki/secret.md".to_string(),
],
- );
- assert_eq!(files.len(), 1);
+ )
+ .await;
+ assert_eq!(files.len(), 2);
assert_eq!(
Path::new(&files[0].0).canonicalize().unwrap(),
root.join("wiki/page.md").canonicalize().unwrap()
);
assert_eq!(files[0].1, "selected evidence");
+ assert!(files[1].1.starts_with("[Image: figure.png"));
let _ = fs::remove_dir_all(root);
}
diff --git a/src-tauri/src/agent/runtime.rs b/src-tauri/src/agent/runtime.rs
index d2592d36..b25d8a6b 100644
--- a/src-tauri/src/agent/runtime.rs
+++ b/src-tauri/src/agent/runtime.rs
@@ -1138,7 +1138,7 @@ impl AgentRuntime {
let retrieval_summary = retrieval_parts.join("\n\n");
let project_context = load_project_context(&self.project_path);
let explicit_files =
- load_explicit_context_files(&self.project_path, &request.context_files);
+ load_explicit_context_files(&self.project_path, &request.context_files).await;
let built_context = fit_context_to_model(
build_agent_context(AgentContextInput {
query: message,
@@ -1296,7 +1296,33 @@ impl AgentRuntime {
.structured_task_config(agent_structured_max_tokens(!skills.is_empty()));
let project_context = load_project_context(&self.project_path);
let explicit_files =
- load_explicit_context_files(&self.project_path, &request.context_files);
+ load_explicit_context_files(&self.project_path, &request.context_files).await;
+ if !request.context_files.is_empty() {
+ let detail = format!(
+ "{} of {} selected file(s) attached",
+ explicit_files.len(),
+ request.context_files.len().min(8)
+ );
+ tool_emit_event(
+ &mut tool_events,
+ &mut events,
+ &event_sink,
+ AgentToolEvent {
+ tool: "context.attach".to_string(),
+ status: if explicit_files.is_empty() {
+ "failed".to_string()
+ } else {
+ "completed".to_string()
+ },
+ detail: Some(detail.clone()),
+ },
+ );
+ emit_event(
+ &mut events,
+ &event_sink,
+ AgentEvent::tool_end("context.attach", Some(detail)),
+ );
+ }
let mut observations = Vec::<AgentObservation>::new();
let mut last_prompt_chars = 0usize;
let max_iterations = agent_loop_iteration_budget(request.mode, !skills.is_empty());
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsx
index 59c71afb..31d83e1f 100644
--- a/src/components/chat/chat-panel.tsx
+++ b/src/components/chat/chat-panel.tsx
@@ -324,6 +324,7 @@ function normalizeBackendToolName(tool: string) {
if (normalized === "workspace_write_file") return "project_files" as const
if (normalized === "workspace_append_file") return "project_files" as const
if (normalized === "skills_load") return "project_file_read" as const
+ if (normalized === "context_attach") return "project_file_read" as const
if (normalized === "skill_read_file") return "project_file_read" as const
if (normalized === "source_search") return "project_file_read" as const
if (normalized === "graph_search") return "graph_search" as const