Skip to content

feat(ck-core): add CK_INDEX_DIR to relocate index directories - #165

Merged
runonthespot merged 1 commit into
BeaconBay:mainfrom
ak2k:ck-index-dir
Jul 7, 2026
Merged

feat(ck-core): add CK_INDEX_DIR to relocate index directories#165
runonthespot merged 1 commit into
BeaconBay:mainfrom
ak2k:ck-index-dir

Conversation

@ak2k

@ak2k ak2k commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

By default ck stores each search root's index in an in-tree .ck/ directory. This adds an opt-in CK_INDEX_DIR environment variable: when set, a search root R is indexed under $CK_INDEX_DIR/<basename(R)>-<hash> (first 8 hex chars of the blake3 hash of R's canonical absolute path, so same-basename roots get distinct directories). When unset, behavior is byte-identical to today.

Motivation

  • Keep repositories free of in-tree .ck/ directories.
  • Cache indexes in CI without polluting the checkout.
  • Share one index across multiple checkouts/worktrees of the same tree.

Implementation

Two documented helpers in ck-core (index_dir, index_exists) plus an INDEX_DIR_ENV const; every <root>/.ck computation routes through them, including the walk-up probes, the tantivy meta file, and the index write lock, so all index state co-locates. The env value is absolutized before use so a relative value can't split the lock from the index. Each relocated index directory carries a root_path marker naming the root it was built for; indexing and search refuse a directory claimed by a different root, surfacing a clear error rather than silently mixing two roots' data in the (unlikely) event of a hash collision.

Notes / limitations

  • Relocated index directories are not garbage-collected when a root is deleted or moved (run ck --clean first, or remove them manually). In-tree .ck disappears with the repo; a relocated index does not.
  • Set the variable consistently across concurrent invocations of the same root, preferring an absolute path.

Tests

ck-core units for unset/set/empty/collision/absolutization/marker; env-touching tests serialized with serial_test (the crate the test suite already uses); cargo test --workspace green both with and without CK_INDEX_DIR set; fmt and clippy clean. README documents the variable under "Index Storage".

…the source tree

By default ck stores each search root's index in an in-tree `.ck/` directory.
That is convenient but not always wanted: it clutters repositories, can't be
shared between multiple checkouts of the same tree, and is awkward to cache in
CI. When `CK_INDEX_DIR` is set, the index for a search root instead lives at
`$CK_INDEX_DIR/<basename>-<hash>`, where `<hash>` is the first 8 hex characters
of the blake3 hash of the root's absolute path so two roots that share a
basename never collide. Unset preserves the existing `<root>/.ck` behavior
exactly.

Introduce two documented helpers in ck-core: `index_dir(root)` returns the
index/sidecar directory for a search root and `index_exists(root)` reports
whether it exists. Both the relocation base and the root are absolutized, so the
returned path is independent of the current directory (a relative CK_INDEX_DIR
is anchored at the launch directory rather than resolved per-process). The
environment variable is read on every call (an empty value is treated as unset)
and never panics. Every call site that computed `<root>/.ck` — across ck-index,
ck-engine, ck-cli, ck-tui, and ck-core's own sidecar and PDF content-cache
paths, including the walk-ups that probe for a nearby index — now routes through
these helpers. The `.ck` default-exclude pattern and sidecar file extensions are
unchanged.

Because an 8-hex hash can in principle collide, a relocated index directory
records its search root in a `root_path` marker file; indexing refuses to write
into a directory claimed by a different root, and searches refuse to serve one,
surfacing a clear error instead of silently returning another root's results.

Tests covering env-dependent paths are serialized with serial_test (already used
elsewhere in ck) and clear the variable so they exercise default behavior
deterministically.

Documented under "Index Storage" in the README.
@runonthespot
runonthespot merged commit 4023f99 into BeaconBay:main Jul 7, 2026
9 checks passed
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.

2 participants