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: preserve attached file context in chat

nash_su227602035bee
diff --git a/src-tauri/src/agent/context.rs b/src-tauri/src/agent/context.rs
index 666fd364..becf5763 100644
--- a/src-tauri/src/agent/context.rs
+++ b/src-tauri/src/agent/context.rs
@@ -276,7 +276,10 @@ pub fn load_explicit_context_files(
};
let fitted = trim_chars(&content, remaining.min(MAX_EXPLICIT_FILE_CHARS));
remaining = remaining.saturating_sub(fitted.chars().count());
- out.push((normalized, fitted));
+ // The request uses a project-relative path so callers cannot select an
+ // arbitrary host file. Only after canonical containment succeeds do we
+ // expose the absolute path to the model for unambiguous tool use.
+ out.push((candidate.to_string_lossy().replace('\\', "/"), fitted));
if remaining == 0 {
break;
}
@@ -355,10 +358,12 @@ mod tests {
".llm-wiki/secret.md".to_string(),
],
);
+ assert_eq!(files.len(), 1);
assert_eq!(
- files,
- vec![("wiki/page.md".to_string(), "selected evidence".to_string())]
+ Path::new(&files[0].0).canonicalize().unwrap(),
+ root.join("wiki/page.md").canonicalize().unwrap()
);
+ assert_eq!(files[0].1, "selected evidence");
let _ = fs::remove_dir_all(root);
}
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsx
index 5794ab73..65abb0f2 100644
--- a/src/components/chat/chat-message.tsx
+++ b/src/components/chat/chat-message.tsx
@@ -120,6 +120,20 @@ function ChatMessageImpl({
{isUser ? <User className="h-4 w-4" /> : <Bot className="h-4 w-4" />}
</div>
<div className="max-w-[80%] flex flex-col gap-1.5">
+ {isUser && message.contextFiles && message.contextFiles.length > 0 && (
+ <div className="flex flex-wrap justify-end gap-1">
+ {message.contextFiles.map((path) => (
+ <span
+ key={path}
+ className="inline-flex h-7 max-w-[18rem] items-center gap-1.5 rounded-md border border-blue-500/25 bg-blue-500/10 px-2 text-xs font-medium text-blue-700 dark:text-blue-300"
+ title={path}
+ >
+ <FileText className="h-3 w-3 shrink-0" />
+ <span className="truncate">@{getFileName(path)}</span>
+ </span>
+ ))}
+ </div>
+ )}
{isUser && message.images && message.images.length > 0 && (
<div className={`flex flex-wrap gap-1.5 ${isUser ? "justify-end" : ""}`}>
{message.images.map((img, i) => (
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsx
index f526789e..59c71afb 100644
--- a/src/components/chat/chat-panel.tsx
+++ b/src/components/chat/chat-panel.tsx
@@ -694,7 +694,10 @@ export function ChatPanel() {
}
if (!sendOptions.suppressUserMessage) {
- addMessageToConversation(convId, "user", text, images)
+ const messageContextFiles = project
+ ? sendOptions.contextFiles.map((path) => projectAbsolutePath(project.path, path))
+ : []
+ addMessageToConversation(convId, "user", text, images, messageContextFiles)
}
setStreamingConversationId(convId)
setStreaming(true)
diff --git a/src/lib/persist.integration.test.ts b/src/lib/persist.integration.test.ts
index 80855527..70fa6af0 100644
--- a/src/lib/persist.integration.test.ts
+++ b/src/lib/persist.integration.test.ts
@@ -293,6 +293,20 @@ describe("chat persistence — round-trip (new format)", () => {
expect(raw).toContain("-before\\n+after")
})
+ it("persists user-message context file attachments", async () => {
+ const convs = [makeConv("c1", "Context files")]
+ const msg: DisplayMessage = {
+ ...makeMsg("m1", "c1", "summarize this"),
+ contextFiles: [`${tmp.path}/wiki/overview.md`],
+ }
+
+ await saveChatHistory(tmp.path, convs, [msg])
+ const loaded = await loadChatHistory(tmp.path)
+ expect(loaded.messages[0].contextFiles).toEqual([
+ `${tmp.path}/wiki/overview.md`,
+ ])
+ })
+
it("caps each conversation's persisted messages at 100 (oldest dropped)", async () => {
const convs = [makeConv("c1")]
const msgs = Array.from({ length: 150 }, (_, i) =>
diff --git a/src/stores/chat-store.test.ts b/src/stores/chat-store.test.ts
index 6c502de2..bdb262bd 100644
--- a/src/stores/chat-store.test.ts
+++ b/src/stores/chat-store.test.ts
@@ -142,4 +142,19 @@ describe("chat-store conversation isolation", () => {
useChatStore.getState().setActiveConversation(second)
expect(useChatStore.getState().selectedContextFiles).toEqual(["raw/sources/source.txt"])
})
+
+ it("stores the context file snapshot on the user message", () => {
+ const conversationId = useChatStore.getState().createConversation()
+ useChatStore.getState().addMessageToConversation(
+ conversationId,
+ "user",
+ "summarize this",
+ [],
+ ["/project/wiki/overview.md"],
+ )
+
+ expect(useChatStore.getState().messages[0].contextFiles).toEqual([
+ "/project/wiki/overview.md",
+ ])
+ })
})
diff --git a/src/stores/chat-store.ts b/src/stores/chat-store.ts
index 9db1dc0e..4886fc94 100644
--- a/src/stores/chat-store.ts
+++ b/src/stores/chat-store.ts
@@ -44,6 +44,7 @@ export interface DisplayMessage {
agentFileChanges?: ChatAgentFileChange[] // concrete project files changed by this Agent turn
userInputRequest?: ChatUserInputRequest // dynamic schema-driven form requested by backend Agent
images?: MessageImage[] // images attached to a user message (vision input)
+ contextFiles?: string[] // absolute project files explicitly attached to this user turn
}
interface ChatState {
@@ -70,7 +71,7 @@ interface ChatState {
// Message management
addMessage: (role: DisplayMessage["role"], content: string, images?: MessageImage[]) => void
- addMessageToConversation: (conversationId: string, role: DisplayMessage["role"], content: string, images?: MessageImage[]) => void
+ addMessageToConversation: (conversationId: string, role: DisplayMessage["role"], content: string, images?: MessageImage[], contextFiles?: string[]) => void
setMessages: (messages: DisplayMessage[]) => void
setConversations: (conversations: Conversation[]) => void
setStreaming: (streaming: boolean) => void
@@ -179,7 +180,7 @@ export const useChatStore = create<ChatState>((set, get) => ({
get().addMessageToConversation(activeConversationId, role, content, images)
},
- addMessageToConversation: (conversationId, role, content, images) =>
+ addMessageToConversation: (conversationId, role, content, images, contextFiles) =>
set((state) => {
const { conversations } = state
if (!conversations.some((conversation) => conversation.id === conversationId)) return state
@@ -191,6 +192,7 @@ export const useChatStore = create<ChatState>((set, get) => ({
timestamp: Date.now(),
conversationId,
...(images && images.length > 0 ? { images } : {}),
+ ...(contextFiles && contextFiles.length > 0 ? { contextFiles } : {}),
}
// Auto-set title from first user message (first 50 chars)