Skip to content

colgrep init: --dry-run lists the files, without loading the model - #190

Closed
paoValle wants to merge 2 commits into
lightonai:mainfrom
paoValle:fix/164-init-dry-run
Closed

paoValle wants to merge 2 commits into
lightonai:mainfrom
paoValle:fix/164-init-dry-run

Conversation

@paoValle

@paoValle paoValle commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Part of #164. colgrep init loads the model and starts encoding before anyone can see which files it picked, and colgrep status only describes an existing index. --dry-run (alias --list-files) prints the resolved file set and exits.

What it does

$ colgrep init . --dry-run | head -3
src/…/main.rs
…
$ colgrep init . --dry-run | wc -l
235 file(s) would be parsed under /path/to/project (4 skipped: too large or outside the root)
235

Paths on stdout (so it pipes into a SAST tool or a file list), the summary on stderr. The set is the one a real init would walk: built-in default exclusions, this project's .gitignore, the persistent settings --ignore patterns and the covered-directory registrations. It returns before ensure_model and before the IndexBuilder is constructed — no model, no encoding, no index write, no config write.

The walk is not duplicated: scan_project_files is the function the indexer itself calls (IndexBuilder::scan_files), now public and re-exported, so the dry run cannot drift from what a real init walks. On the force-include path — a child of an indexed project that the parent's rules exclude — the dry run computes the same list in memory and persists nothing, mirroring add_force_include_dir's no-op when an ancestor registration already covers the subdir.

What it is not

Two of the issue's "would be ideal" items: the per-file reason for inclusion/exclusion, and the summary stats (code units, estimated embeddings). The summary says "would be parsed" rather than "would be indexed" on purpose: a file whose content turns out to be binary or not UTF-8 is listed here and dropped later, at parse time. Happy to do the reason/stats slice next if you want it.

Verification

$ cargo test            # in colgrep/
test result: ok. 691 passed; 0 failed; 1 ignored       (lib)
test result: ok.  72 passed; 0 failed                  (bin)
test result: ok.   2 passed; 0 failed                  (tests/init_dry_run.rs)
$ cargo clippy --all-targets -- -D warnings   # clean
$ cargo fmt --all -- --check                  # clean

tests/init_dry_run.rs runs the binary against an isolated COLGREP_DATA_DIR and pins the command surface and the promise: built-in exclusions respected, --list-files the same command, no index and no config written, and a child of an indexed project reported at the parent's set without persisting the registration. It bites in both directions — leaking a config.save() into the dry-run branch fails it ("must not persist a force-include registration"), dropping the in-memory push fails it ("the uncovered child must be reported"), and renaming the alias fails it. The second test also runs --model /nonexistent/model, which a real init cannot survive, so a regression that reaches ensure_model is a failure and not a warm-cache pass.

On this repository the dry run lists 235 files in 0.15 s.

I used an AI assistant to draft this change; I read #164, reviewed the diff and ran every command quoted above myself.

@paoValle

paoValle commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The Windows CLI E2E failure on the first commit was not the dry run — a debug build of colgrep cannot start on Windows at all. A PE main thread gets a 1 MB stack, and the startup path needs more than that in an unoptimized build: colgrep --version, --help, a bare colgrep all abort with thread 'main' has overflowed its stack. The release build the E2E workflow uses is unaffected, which is why every other job on this PR is green.

Reproduced on macOS by capping the stack, so it is frame usage and not Windows-specific code:

$ (ulimit -s 1024; ./target/debug/colgrep --version)
thread 'main' (24633304) has overflowed its stack
$ (ulimit -s 3072; ./target/debug/colgrep --version)   # fine

Filed as #191 with two ways to fix it (a /STACK link argument for Windows, or main on a thread with an explicit stack size) — happy to do either in its own PR. In the meantime f6302a1 skips the two integration tests on Windows with that reason (the local and Linux/macOS runs still cover them, and the E2E matrix runs the release binary).

paoValle and others added 2 commits October 12, 2026 12:40
Part of lightonai#164. `colgrep init` loads the model and starts encoding before anyone can see which
files it picked, and `colgrep status` only describes an index that already exists. `--dry-run`
(alias `--list-files`) prints the resolved file set — built-in default exclusions, this
project's `.gitignore`, the persistent `settings --ignore` patterns and the covered-directory
registrations — one root-relative path per line on stdout, with the count on stderr, and
returns before `ensure_model` and before the `IndexBuilder` exists.

The walk is not duplicated: `scan_project_files` is the function the indexer itself calls
(`IndexBuilder::scan_files`), so the dry run cannot drift from what a real init walks. The
force-include branch that registers a covered subdirectory for an adopting parent computes the
same list in memory on the dry-run path and persists nothing, mirroring
`add_force_include_dir`'s no-op when an ancestor registration already covers the subdir.

What it is not: the parse-time filtering that happens after the walk (a file whose content turns
out to be binary or not UTF-8 is listed and dropped later), and the issue's "would be ideal"
per-file reason and code-unit/embedding estimates. Those read as a follow-up, and the summary
line says "would be parsed" rather than "would be indexed" for the same reason.

Verification, in colgrep/:

    $ cargo test
    test result: ok. 691 passed; 0 failed; 1 ignored       (lib)
    test result: ok.  72 passed; 0 failed                  (bin)
    test result: ok.   2 passed; 0 failed                  (tests/init_dry_run.rs)
    $ cargo clippy --all-targets -- -D warnings   # clean
    $ cargo fmt --all -- --check                  # clean

    $ colgrep init . --dry-run | wc -l
    235 file(s) would be parsed under ... (4 skipped: too large or outside the root)
    235                                           # 0.15 s, no model, this repository

`tests/init_dry_run.rs` pins the command surface and the promise against an isolated
`COLGREP_DATA_DIR`: the default exclusions are respected, `--list-files` is the same command, no
index and no config are written, and a child of an indexed project reports the parent's set (the
force-include case) without persisting the registration. It is load-bearing in both directions:
leaking a `config.save()` into the dry-run branch fails it ("must not persist a force-include
registration"), dropping the in-memory push fails it ("the uncovered child must be reported"),
and renaming the alias fails it too. The second test also runs `--model /nonexistent/model`,
which a real init cannot survive.

I used an AI assistant to draft this change; I read lightonai#164, reviewed the diff and ran every
command quoted above myself.
The CLI E2E Windows job failed on the previous commit, and it was not the dry run: a debug
build of the binary cannot start on Windows at all. A PE main thread gets a 1 MB stack, the
startup path (`setup_signal_handler`, `init_global_rayon_pool`, `Cli::parse`) needs more than
that in an unoptimized build, and every invocation aborts — `colgrep --version`, `--help`, a
bare `colgrep`, all of them. Reproduced on macOS by capping the stack, 3 MB is enough:

    $ (ulimit -s 1024; ./target/debug/colgrep --version)
    thread 'main' (24633304) has overflowed its stack

So the two tests are `#[ignore]`d on Windows with that reason, and issue lightonai#191
carries the reproduction and two ways to fix it (a `/STACK` link argument, or `main` on a
thread with an explicit stack size). The release build the E2E workflow uses is unaffected,
and the tests run on Linux and macOS, where CI also runs them.

Co-authored-by: Claude <noreply@anthropic.com>
@paoValle
paoValle force-pushed the fix/164-init-dry-run branch from f6302a1 to 7f4cf3c Compare October 12, 2026 10:45
@paoValle

Copy link
Copy Markdown
Contributor Author

Rebased onto current main — the branch's base had fallen 42 commits behind (base d8b590f, main now at c6c091d, Release 1.8.5), which is why the PR showed as conflicting.

One conflict, in colgrep/src/lib.rs's pub use index::{ … }: main added UnitMatch (the --agent code-units feature) while this branch makes scan_project_files public for the --dry-run walk — both are exports, so I kept both. Everything else (the --dry-run change in commands/init.rs and cli.rs) replays cleanly onto the newer init.rs.

Re-ran the gate in colgrep/ on the new head 7f4cf3c:

  • cargo fmt --all -- --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test — ok. 1012 passed; 0 failed (lib), 75 passed; 0 failed (bin), 2 passed; 0 failed (tests/init_dry_run.rs)

The two init_dry_run tests still pass on top of 1.8.5. Mergeability is back to mergeable; CI is re-running on the new head.

@paoValle

Copy link
Copy Markdown
Contributor Author

A quick check on this proposal — is it something you'd like to take? If there's no interest I'll go ahead and close it in ten days or so, no worries at all; I'd just rather keep the queue here tidy than leave it sitting.

For context, the branch is rebased on current main and every check is green, so nothing is blocking a review.

@paoValle

Copy link
Copy Markdown
Contributor Author

No answer since the ping on 23 October, so I'll close this one to keep the queue tidy rather than leave it sitting. The branch stays in my fork and I can reopen it on request.

@paoValle paoValle closed this Nov 13, 2026
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