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

feat: add "Cancel all" button to ingest queue

nash_su14e5783fa286
diff --git a/src/components/layout/activity-panel.tsx b/src/components/layout/activity-panel.tsx
index 3aa17bc9..d0623f22 100644
--- a/src/components/layout/activity-panel.tsx
+++ b/src/components/layout/activity-panel.tsx
@@ -7,7 +7,7 @@ import {
import { useActivityStore, type ActivityItem } from "@/stores/activity-store"
import { useWikiStore } from "@/stores/wiki-store"
import { normalizePath, getFileName, isAbsolutePath } from "@/lib/path-utils"
-import { getQueue, getQueueSummary, retryTask, cancelTask, type IngestTask } from "@/lib/ingest-queue"
+import { getQueue, getQueueSummary, retryTask, cancelTask, cancelAllTasks, type IngestTask } from "@/lib/ingest-queue"
const FILE_TYPE_ICONS: Record<string, typeof FileText> = {
sources: BookOpen,
@@ -62,6 +62,18 @@ export function ActivityPanel() {
cancelTask(normalizePath(project.path), taskId)
}, [project])
+ const handleCancelAll = useCallback(() => {
+ if (!project) return
+ const activeCount = queueSummary.pending + queueSummary.processing
+ if (activeCount === 0) return
+ if (!window.confirm(
+ `Cancel all ${activeCount} queued/processing task${activeCount > 1 ? "s" : ""}? ` +
+ `Partial files from the in-progress task will be removed. ` +
+ `Failed tasks will be kept so you can retry them.`,
+ )) return
+ cancelAllTasks(normalizePath(project.path))
+ }, [project, queueSummary.pending, queueSummary.processing])
+
// Auto-expand when a new task starts running
useEffect(() => {
if (runningCount > 0 && prevRunningRef.current === 0) {
@@ -119,9 +131,20 @@ export function ActivityPanel() {
{/* Queue progress bar */}
{hasQueue && (queueSummary.processing > 0 || queueSummary.pending > 0) && (
<div className="px-3 py-1.5 border-b border-border/50">
- <div className="flex items-center justify-between text-[10px] text-muted-foreground mb-1">
+ <div className="flex items-center justify-between text-[10px] text-muted-foreground mb-1 gap-2">
<span>Ingest Queue</span>
- <span>{queueSummary.total - queueSummary.pending - queueSummary.processing}/{queueSummary.total} complete</span>
+ <span className="flex-1 text-right">
+ {queueSummary.total - queueSummary.pending - queueSummary.processing}/{queueSummary.total} complete
+ </span>
+ {queueSummary.pending + queueSummary.processing >= 2 && (
+ <button
+ onClick={handleCancelAll}
+ className="rounded px-1.5 py-0.5 text-[10px] text-destructive hover:bg-destructive/10"
+ title="Cancel all queued and in-progress tasks"
+ >
+ Cancel all
+ </button>
+ )}
</div>
<div className="h-1.5 rounded-full bg-muted overflow-hidden">
<div
diff --git a/src/lib/ingest-queue.test.ts b/src/lib/ingest-queue.test.ts
index d26565c0..a6d15f70 100644
--- a/src/lib/ingest-queue.test.ts
+++ b/src/lib/ingest-queue.test.ts
@@ -25,6 +25,7 @@ import {
enqueueBatch,
retryTask,
cancelTask,
+ cancelAllTasks,
clearCompletedTasks,
clearQueueState,
getQueue,
@@ -171,6 +172,47 @@ describe("ingest-queue — cancel", () => {
})
})
+describe("ingest-queue — cancelAllTasks", () => {
+ it("drops all pending and processing tasks but keeps failed ones", async () => {
+ // Block the processing task so it doesn't finish on its own.
+ mockAutoIngest.mockImplementation(() => new Promise(() => {}))
+
+ await enqueueBatch("/project", [
+ { sourcePath: "a.md", folderContext: "" },
+ { sourcePath: "b.md", folderContext: "" },
+ { sourcePath: "c.md", folderContext: "" },
+ ])
+ await flushMicrotasks(2)
+
+ // Manually set one task to "failed" so we can verify it survives.
+ const failedTask = getQueue()[2]
+ ;(failedTask as { status: string }).status = "failed"
+
+ const removed = await cancelAllTasks("/project")
+
+ expect(removed).toBe(2) // a (processing) + b (pending) gone
+ expect(getQueue()).toHaveLength(1)
+ expect(getQueue()[0].sourcePath).toBe("c.md")
+ expect(getQueue()[0].status).toBe("failed")
+ })
+
+ it("returns 0 when the queue is empty", async () => {
+ const removed = await cancelAllTasks("/project")
+ expect(removed).toBe(0)
+ expect(getQueue()).toHaveLength(0)
+ })
+
+ it("is safe to call after it has already cleared the queue", async () => {
+ mockAutoIngest.mockImplementation(() => new Promise(() => {}))
+ await enqueueIngest("/project", "only.md")
+ await flushMicrotasks(2)
+
+ await cancelAllTasks("/project")
+ const secondCall = await cancelAllTasks("/project")
+ expect(secondCall).toBe(0)
+ })
+})
+
describe("ingest-queue — clearCompletedTasks & summary", () => {
it("getQueueSummary returns accurate counts", async () => {
mockAutoIngest.mockRejectedValue(new Error("fail"))
diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.ts
index 9e1ec861..478925c7 100644
--- a/src/lib/ingest-queue.ts
+++ b/src/lib/ingest-queue.ts
@@ -186,6 +186,48 @@ export async function clearCompletedTasks(projectPath: string): Promise<void> {
await saveQueue(projectPath)
}
+/**
+ * Cancel everything that's not finished: aborts the running task (if any),
+ * cleans up its partial output, and drops every pending + processing item.
+ *
+ * Failed tasks are retained so the user can still see / retry them.
+ * Returns the number of tasks removed from the queue.
+ */
+export async function cancelAllTasks(projectPath: string): Promise<number> {
+ const pp = normalizePath(projectPath)
+
+ // Abort any in-progress LLM call first so it stops burning tokens.
+ if (currentAbortController) {
+ currentAbortController.abort()
+ currentAbortController = null
+ }
+ processing = false
+
+ // Clean up partial files from the task that was processing, if any.
+ if (lastWrittenFiles.length > 0) {
+ const { deleteFile } = await import("@/commands/fs")
+ for (const filePath of lastWrittenFiles) {
+ try {
+ const fullPath = isAbsolutePath(filePath)
+ ? normalizePath(filePath)
+ : `${pp}/${filePath}`
+ await deleteFile(fullPath)
+ } catch {
+ // file may not exist
+ }
+ }
+ lastWrittenFiles = []
+ }
+
+ const before = queue.length
+ queue = queue.filter((t) => t.status === "failed")
+ const removed = before - queue.length
+
+ await saveQueue(pp)
+ console.log(`[Ingest Queue] Cancelled all: ${removed} tasks removed`)
+ return removed
+}
+
/**
* Get current queue state.
*/