Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

Allow ingesting individual files, not just folders

anirudhkumar-nanonets296a4f9c105e
diff --git a/src/web.ts b/src/web.ts
index 21ac3504..6a67905b 100644
--- a/src/web.ts
+++ b/src/web.ts
@@ -286,20 +286,24 @@ const server = createServer(async (req, res) => {
}
if (req.method === "POST" && url.pathname === "/api/ingest-dir") {
+ // Accepts a directory or a single file on the server's disk.
const { dir } = JSON.parse(await readBody(req)) as { dir?: string };
if (!dir?.trim()) return json(res, 400, { error: "dir is required" });
const abs = resolve(dir);
- if (!existsSync(abs) || !statSync(abs).isDirectory()) {
- return json(res, 400, { error: `not a directory: ${abs}` });
+ if (!existsSync(abs)) {
+ return json(res, 400, { error: `no such file or directory: ${abs}` });
}
+ const isDir = statSync(abs).isDirectory();
// Stream progress as NDJSON so the UI can narrate a long ingest live.
res.writeHead(200, { "content-type": "application/x-ndjson", "cache-control": "no-store" });
const emit = (event: unknown) => res.write(JSON.stringify(event) + "\n");
try {
- const results = await engine.ingestDir(abs, {
- onProgress: (info) => emit({ type: "progress", ...info }),
- });
+ const results = isDir
+ ? await engine.ingestDir(abs, {
+ onProgress: (info) => emit({ type: "progress", ...info }),
+ })
+ : [await engine.ingestFile(abs)];
emit({ type: "done", results, stats: await engine.stats() });
} catch (e) {
emit({ type: "error", error: e instanceof Error ? e.message : String(e) });
diff --git a/src/web/ui.html b/src/web/ui.html
index 46a24502..465fdd3f 100644
--- a/src/web/ui.html
+++ b/src/web/ui.html
@@ -204,6 +204,7 @@
.grow-status { font-family: var(--mono); font-size: 12px; margin-top: 10px; color: var(--ink-soft); white-space: pre-wrap; word-break: break-word; }
.grow-status.ok { color: var(--verdant-deep); }
.grow-status.err { color: #a03b2e; }
+ .picker-row { display: flex; flex-wrap: wrap; gap: 8px; }
details.server-path { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.server-path summary { cursor: pointer; font-size: 12.5px; color: var(--ink-faint); list-style: none; }
details.server-path summary::-webkit-details-marker { display: none; }
@@ -360,16 +361,20 @@
</details>
<details class="grow" id="ingest-panel">
- <summary>Ingest a folder of documents</summary>
+ <summary>Ingest documents</summary>
<div class="grow-body">
- <p class="grow-hint">Pick a folder from your computer (.pdf, .md, .txt) — every file becomes chunks, entities, and relationships, watch the graph grow on the right.</p>
+ <p class="grow-hint">Pick files or a whole folder from your computer (.pdf, .md, .txt) — every file becomes chunks, entities, and relationships, watch the graph grow on the right.</p>
+ <input type="file" id="files-input" multiple accept=".pdf,.md,.markdown,.txt" hidden />
<input type="file" id="folder-input" webkitdirectory multiple hidden />
- <button class="btn" id="choose-folder-btn" type="button">Choose folder…</button>
+ <div class="picker-row">
+ <button class="btn" id="choose-files-btn" type="button">Choose files…</button>
+ <button class="btn" id="choose-folder-btn" type="button">Choose folder…</button>
+ </div>
<details class="server-path">
- <summary>or ingest a folder on the server</summary>
- <p class="grow-hint">Reads files from the server's own disk — in Docker, that's the mounted <code>/docs</code>.</p>
- <input class="dir" id="ingest-input" placeholder="/path/to/your/docs" />
- <button class="btn quiet" id="ingest-btn" type="button">Ingest server folder</button>
+ <summary>or ingest a path on the server</summary>
+ <p class="grow-hint">Reads a file or folder from the server's own disk — in Docker, that's the mounted <code>/docs</code>.</p>
+ <input class="dir" id="ingest-input" placeholder="/path/to/docs or /path/to/file.md" />
+ <button class="btn quiet" id="ingest-btn" type="button">Ingest server path</button>
</details>
<div class="grow-status" id="ingest-status"></div>
</div>
@@ -388,7 +393,7 @@
<div class="atlas-empty hidden" id="atlas-empty">
<div class="inner">
<h3>The ledger is empty.</h3>
- <p>Ingest a folder of documents on the left and this space becomes a map of everything your team knows.</p>
+ <p>Ingest documents on the left — a single file or a whole folder — and this space becomes a map of everything your team knows.</p>
</div>
</div>
<div id="node-card">
@@ -867,22 +872,25 @@ async function fileToPayload(file) {
return { name: file.name, text: await file.text() };
}
+$("choose-files-btn").addEventListener("click", () => $("files-input").click());
$("choose-folder-btn").addEventListener("click", () => $("folder-input").click());
+$("files-input").addEventListener("change", (e) => uploadPicked(e, "files"));
+$("folder-input").addEventListener("change", (e) => uploadPicked(e, "folder"));
-$("folder-input").addEventListener("change", async (e) => {
+async function uploadPicked(e, kind) {
const all = Array.from(e.target.files || []);
const files = all.filter((f) => UPLOAD_ACCEPT.test(f.name));
const status = $("ingest-status");
- e.target.value = ""; // let the user re-pick the same folder later
+ e.target.value = ""; // let the user re-pick the same selection later
if (!files.length) {
status.className = "grow-status err";
status.textContent = all.length
- ? "No .pdf, .md, or .txt files in that folder."
- : "No folder selected.";
+ ? `No .pdf, .md, or .txt files in that ${kind === "folder" ? "folder" : "selection"}.`
+ : `No ${kind === "folder" ? "folder" : "files"} selected.`;
return;
}
- const btn = $("choose-folder-btn");
- btn.disabled = true;
+ const buttons = [$("choose-files-btn"), $("choose-folder-btn")];
+ buttons.forEach((b) => { b.disabled = true; });
status.className = "grow-status";
const lines = [];
let ok = 0, skipped = 0, failed = 0, nodes = 0;
@@ -928,9 +936,9 @@ $("folder-input").addEventListener("change", async (e) => {
await refreshGraph({ diff: true });
await refreshDocs();
} finally {
- btn.disabled = false;
+ buttons.forEach((b) => { b.disabled = false; });
}
-});
+}
/* ---------- documents ---------- */
async function refreshDocs() {