Skip to content

Add idx family of commands for in-memory indexing - #18142

Merged
fdncred merged 9 commits into
nushell:mainfrom
fdncred:idx
May 4, 2026
Merged

fdncred merged 9 commits into
nushell:mainfrom
fdncred:idx

Conversation

@fdncred

@fdncred fdncred commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds the idx command family for in-memory filesystem indexing and search.

Built on fff-search (v0.7.0), which walks the path and stores file and directory metadata in memory arenas. The global runtime lives in a static OnceLock<Mutex<Option<IdxRuntime>>> so a single index is shared across all commands in a session.

The implementation includes:

  • idx init, idx status, idx files, idx dirs, idx find, idx search, idx export, idx import, and idx drop commands
  • Runtime state management through a global singleton with status reporting and scan duration tracking
  • SQLite snapshot persistence for idx export and metadata-driven rehydration for idx import

User-facing changes (Release notes)

Add the idx command family for in-memory filesystem indexing and search.

Commands

idx init <path> [--wait]

Initializes the global idx runtime by scanning <path>. If the runtime is already initialized it is dropped and re-scanned. --wait blocks until the initial scan completes; omitting it returns immediately with a scanning = true status.

idx init .
idx init ~/projects --wait

idx status

Returns a record describing the current runtime: initialized, base_path, watch, scanning, scan_duration_ms, files, dirs, and arena memory usage fields.

idx status

idx dirs

Returns all indexed directories as records with relative_path and full_path columns.

idx dirs
idx dirs | where full_path =~ src

idx files [<path>]

Returns all indexed files as records with relative_path, full_path, file_name, directory, size, and modified columns. If an optional <path> is provided it performs a direct lookup by relative or absolute path.

idx files
idx files src/main.rs
idx files /absolute/path/to/file.rs

idx find <query> [--files] [--dirs] [--verbose] [--limit <n>]

Fuzzy-searches the index using fff-search scoring. By default searches both files and directories. --files or --dirs narrows the search. --verbose adds a score_details column. --limit caps the result count (default 100).

idx find main
idx find config --files --verbose
idx find src --dirs --limit 10

idx search <pattern>... [--regex] [--fuzzy] [--limit <n>]

Searches the contents of indexed files. Plain text is the default. --regex enables regex matching. --fuzzy enables approximate line matching. Multiple patterns are searched with multi_grep. --limit caps matches (default 50).

idx search hello
idx search --regex 'fn \w+'
idx search TODO FIXME HACK

idx export <filepath>

Persists the current runtime to a SQLite database at <filepath>. Returns a record with stored, path, file_count, dir_count, base_path, and format.

idx export ~/my-index.db

idx import <filepath>

Imports a SQLite snapshot created by idx export. Performs true offline restoration by hydrating the index from stored file and directory rows in the database with no filesystem rescanning. Returns a record with restored, source_path, base_path, watch, rehydration_mode, status, restored_files, restored_dirs, and format. The rehydration_mode is offline_from_snapshot_rows, and the status fields (scanning, scan_duration_ms).

idx import ~/my-index.db

idx drop

Drops the current runtime from memory. Returns {dropped: bool, status: record} where status is always the default (zeroed) status after the drop.

idx drop

Additional notes

Right now fff-search uses the ignore crate and there is no way to control what is ignored other than changing/adding .gitignore or .ignore files.

@fdncred

fdncred commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Will fix the CI issues after dmtrKovalenko/fff#430 lands and there's a release. However, this PR still works for anyone who wants to play with it.

@fdncred
fdncred merged commit 6983c91 into nushell:main May 4, 2026
18 checks passed
@fdncred
fdncred deleted the idx branch May 4, 2026 17:38
@github-actions github-actions Bot added this to the v0.113.0 milestone May 4, 2026
@fdncred fdncred added new-command notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section A:commands General additions or changes to commands labels May 5, 2026
@dmtrKovalenko

Copy link
Copy Markdown
Contributor

WOW! I see this one is merged, this is absolutely stoked :)

I see that you figured out your previous problems with watch mode, but PLEASE let me know if something goes wrong or you see any related issues, I am absolutely ready to maintain them and fix any problem related to fff

btw when do you plan release I would love to announce this as well 👉👈

@fdncred

fdncred commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Hey @dmtrKovalenko! Thanks for checking in. Actually I didn't figure out the watch at all. It's hard coded to false right now. No matter what I did (the other day) I couldn't get it to work so I gave up on that part. I noticed you've worked on that stuff quite a bit recently so I may give it another try. It would be uber cool to auto update the index via the built-in watch functionality.

@dmtrKovalenko

Copy link
Copy Markdown
Contributor

I will check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:commands General additions or changes to commands new-command notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants