working through a review

This commit is contained in:
itsamejms
2026-08-09 13:49:54 +01:00
parent abf3668081
commit 65aee44d6b
21 changed files with 1134 additions and 259 deletions
+41 -1
View File
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api/core";
import { Trash2, ChevronDown, ChevronRight, FileUp } from "lucide-react";
import { open } from "@tauri-apps/plugin-dialog";
import { Trash2, ChevronDown, ChevronRight, FileUp, FolderOpen } from "lucide-react";
import { useToast } from "./Toast";
import { addToLore } from "../lib/lore";
@@ -25,6 +26,7 @@ export function LorePanel() {
const [text, setText] = useState("");
const [sources, setSources] = useState<RagSource[]>([]);
const [adding, setAdding] = useState(false);
const [addingDir, setAddingDir] = useState(false);
const [msg, setMsg] = useState("");
const [query, setQuery] = useState("");
@@ -117,6 +119,34 @@ export function LorePanel() {
if (files.length) addToast(`Indexing ${files.length} file${files.length === 1 ? "" : "s"}`, "info");
}
// ponytail: pick a folder and let Rust walk it (recursive, .md/.txt only).
// Doing the walk in Rust sidesteps the webview fs scope — an external
// world-bible folder needs no fs permission grant this way.
async function addDirectory() {
const selected = await open({ directory: true, multiple: false });
if (!selected || typeof selected !== "string") return;
setAddingDir(true);
try {
const report = await invoke<{ files: number; chunks: number; skipped: string[] }>(
"rag_add_directory",
{ req: { path: selected } },
);
await loadSources();
if (report.files === 0) {
addToast("No .md / .txt files found in that folder", "info");
} else {
addToast(
`Indexed ${report.files} file${report.files === 1 ? "" : "s"} · ${report.chunks} chunks`,
"success",
);
}
for (const s of report.skipped) console.warn("lore dir import skipped:", s);
} catch (e) {
addToast(`Folder import failed: ${e}`, "error");
}
setAddingDir(false);
}
async function search() {
if (!query.trim()) return;
setSearching(true);
@@ -168,6 +198,16 @@ export function LorePanel() {
onChange={onFiles}
/>
</label>
{/* ponytail: directory import — walks every .md/.txt recursively in
Rust (no webview fs-scope needed for an external folder). */}
<button
onClick={addDirectory}
disabled={addingDir}
className="flex items-center gap-2 rounded-lg bg-[var(--color-bg-surface)] border border-[var(--color-border-glass)] px-3 py-2 text-sm text-[var(--color-text-dim)] hover:text-[var(--color-gold-bright)] hover:border-[var(--color-gold-bright)] transition-colors cursor-pointer disabled:opacity-50"
>
<FolderOpen size={14} />
{addingDir ? "Indexing…" : "Add folder…"}
</button>
{msg && <span className="text-xs text-[var(--color-text-secondary)]">{msg}</span>}
</div>