Skip to content

feat: add a whole folder to the library and read source code as text - #58

Merged
bencode merged 4 commits into
mainfrom
feat/folder-import
Oct 1, 2026
Merged

bencode merged 4 commits into
mainfrom
feat/folder-import

Conversation

@bencode

@bencode bencode commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Why

Reading source code needs whole folders, with their structure intact. Builds on #52 (paths), #54 (upgrade blocking) and #57 (move).

What changes

Source code reads as text (core/files.ts)

  • The text extensions now cover common source and config files: ts, js, py, go, rs, java, c/cpp, rb, sh, sql, css/scss, vue, svelte, clj, scm, hs and more.
  • Common extensionless names (Makefile, Dockerfile, LICENSE, README…) also read as text.
  • extensionOf now looks only at the file name, so a dot in a folder name (v1.2/README) is no longer read as an extension.
  • The library upgrades to version 8. The existing single migration pass now recomputes the preview kind for everything stored before v8, so .ts and .py files already in the library become readable by the agent. Older open tabs give way to the upgrade thanks to fix: let a newer tab upgrade the library instead of waiting silently #54.

Folder import

  • core/folder-import.ts holds the pure selection rules shared by both pickers:
    • Ignored folders: node_modules dist build out target coverage __pycache__ venv, plus any folder starting with .. The chosen folder itself is never skipped.
    • Hidden files, files over 1 MiB and unreadable formats are left out.
    • Files are sorted by path, so the tree lists them alphabetically.
    • More than 5000 readable files → the whole folder is refused. Medium-sized repositories already pass 1000, for example crosvm at 1323 and gvisor at 3181, so the limit is 5000.
  • features/resources/pick-folder.ts
    • Chromium: showDirectoryPicker({ mode: 'read' }) and a walk that never enters ignored folders. The walk stops as soon as the folder is known to be over the limit. The handle is not kept.
    • Other browsers: a hidden <input webkitdirectory>. Not offered on iPhone or iPad.
  • use-file-library.ts: addFolder(load).
    • Adding files and adding a folder share one pending-import path and one duplicate dialog. The dialog now offers Replace or Skip existing. Keep both is gone: the library holds copies, so numbered duplicates had no use. Re-importing a folder with Replace works as a manual sync. The data layer still numbers duplicates for chat attachments.
    • Like file imports, the status bar stays quiet unless something was refused or left out.
  • Panel: adding files and adding a folder sit under one + menu, so the folder save is the only folder icon in the toolbar. Where a folder cannot be chosen, + adds files directly. The menu lives in add-menu.tsx and uses Radix Popover, which the project already depends on.

Large imports

  • Planning used to check each new path against every other path, which is quadratic. At 5000 files it blocked the page for 0.9 s (replace) to 3.5 s (keep both). The check now uses an index of folder keys: each path is compared only with its own few folders. In a benchmark, 5000 files take ~7 ms and 10,000 take ~13 ms. moveStoredFile uses the same check.
  • Reading and adding report progress in a neutral line under the toolbar (Reading folder… 1,200 files, Adding 4,180 files…).

Not in this PR

  • Dropping a folder onto the panel (still ignored, as before)
  • .gitignore support
  • Removing a folder at once
  • Syntax highlighting beyond the existing ts/js readers

Tests

  • core/folder-import.test.ts: the filtering rules and path order; exactly the limit is accepted and one more is refused.
  • features/resources/pick-folder.test.ts: ignored folders are never opened, the walk stops early, and the input fallback reads webkitRelativePath.
  • data/file-store.test.ts: a v7 .py record stored as unsupported becomes text.
  • file-library-ui integration: a folder with node_modules and .env imports 2 files, reports the 2 left out, and shows them under the folder.
  • Checked by hand in Chromium by importing ui-packages/web/src (206 files). The files listed in order and opened as source.

pnpm check passes. The known flaky "deletes only what this tab asked for" integration test can still fail under full-suite load, as on main.

A new Add folder action copies a chosen folder into the library under its own
name, sorted by path. Dependencies, build output, hidden entries, files over
1 MiB and unreadable formats are left out, and a folder with more than a
thousand readable files is refused as a whole. Source code and common
extensionless project files now count as text, and the library upgrades to
version 8 to re-read the preview kind of files stored before.
Measured repositories of medium size already pass a thousand readable files,
so a folder may now hold up to five thousand. Adding files and adding a folder
share one + menu, leaving the folder save as the only folder icon in the
toolbar; where a folder cannot be chosen, + adds files directly.
…an keep both

Checking each new path against every other one made a five-thousand-file
import block the page for seconds; an index of folder keys checks a path
against its own few folders instead. Reading and adding a folder now report
progress in the panel. Paths already in the library are either replaced or
skipped: the library holds copies, so numbered duplicates had no use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant