Skip to content

feat(cli): search bootstraps itself on first use - #84

Merged
yanxue06 merged 4 commits into
mainfrom
feat/zero-config-first-run
Aug 12, 2026
Merged

feat(cli): search bootstraps itself on first use#84
yanxue06 merged 4 commits into
mainfrom
feat/zero-config-first-run

Conversation

@yanxue06

Copy link
Copy Markdown
Owner

Getting a first result took three commands, and the first one a new user reached for was the wrong one. search answered with an error telling them to run index; index answered with an error telling them to run init.

None of those steps needed a human. The model download location is fixed and the index mode has a default, so search does them:

$ git-semantic search "race condition in auth"
No index for this repository yet — building one (one-time).
For a faster, message-only index instead: git-semantic index --quick

📚 Indexing repository (full mode): /path/to/repo
Found 4,211 commits to index
[00:00:38] ========================================  4211/4211 ✅ Commits indexed

🎯 Most Relevant Commits for: "race condition in auth"
...

init and index still exist for warming a machine ahead of time or picking a mode. init's closing message no longer recites a three-step sequence that is no longer required.

Decisions worth flagging

Full mode, not quick. Quick is faster, but its index is not a superset of full — switching to full later requires re-embedding every commit, and the tool already warns about that. Bootstrapping into quick would quietly commit the user to the weaker option.

Progress on stderr. A first run can happen underneath --json, and a progress line inside a JSON document is not parseable. Indexing driven by index still reports on stdout as before; the new Progress channel is what keeps those two cases apart.

Testing

Verified by hand end to end: a machine with no model, searching from a nested subdirectory of an unindexed repository, downloads the model, indexes, and answers.

Not covered by an automated test — exercising this path needs the 130 MB model, which CI does not have and should not fetch. No existing test invokes search, index, or init beyond --help, so nothing in the suite starts downloading as a side effect of this change.


Third of four stacked PRs, on top of #83.

yanxue06 and others added 4 commits August 12, 2026 00:55
`RepositoryParser` discovers the repository the way git does, walking up
from wherever it was invoked. `IndexStorage` did not — it looked for
`./.git` and gave up. So every command worked from the repository root
and reported "not a git repository" one directory down, which is where
most people actually are:

    $ cd src && git-semantic search "race condition"
    error: not a git repository: .git directory not found

Discovery also resolves the `gitdir:` pointer in a linked worktree's or
submodule's `.git` file. Submodules write that pointer relative to the
submodule directory (`gitdir: ../.git/modules/<name>`); reading the file
by hand resolved it against the process's working directory instead and
put the index outside the repository.

`InvalidGitFile` now marks a `.git` entry that exists but does not
resolve, so a broken worktree keeps its own hint instead of being told it
is not in a repository.

The storage tests built a bare `.git` directory that no git tool would
accept. They now initialize real repositories, which is what the file
headers claimed all along.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`git-semantic completions <shell>` writes a completion script for bash,
zsh, fish, elvish, or powershell to stdout. Generated from the same clap
definition the parser is built from, so the flags a shell offers cannot
drift from the flags that exist.

Named for the binary rather than the git alias: `git semantic …`
completes through git's own subcommand machinery, which finds
`git-semantic` on PATH.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rust ignores SIGPIPE at startup, so writing to a closed pipe returns
EPIPE and `println!` panics on it. `git-semantic completions zsh | head`
printed a Rust panic and a backtrace note instead of the first few lines,
and `search --json | head` did the same — the two outputs most likely to
be piped were the two that broke.

Restoring the default disposition on unix makes the process die the way
every other tool in the pipeline does.

Not covered by a test: whether the child hits EPIPE at all depends on
losing a race against the reader's exit, and the completion script is
8 KB, well under a pipe buffer. A test would pass without exercising
anything. Verified by hand instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Onboarding was three commands, and the first one a new user reached for
was the wrong one. `search` answered with an error telling them to run
`index`; `index` answered with an error telling them to run `init`. None
of those steps needed a human — the model download location is fixed and
the index mode has a default — so `search` now does them:

    $ git-semantic search "race condition in auth"
    No index for this repository yet — building one (one-time).
    For a faster, message-only index instead: git-semantic index --quick

`init` and `index` still exist for warming a machine or picking a mode.
`init`'s closing message no longer recites a three-step sequence that is
no longer required.

Bootstrap indexes in full mode, matching `git-semantic index`. Quick mode
is faster but its index is not a superset, so bootstrapping into it would
quietly commit the user to the weaker option and a full re-embed to leave
it.

Progress goes to stderr, because a first run can happen underneath
`--json` and a progress line inside a JSON document is not parseable.
Indexing driven by `index` still reports on stdout as before.

Verified by hand end to end — a cold machine with no model, searching
from a nested subdirectory, downloads, indexes, and answers. Not covered
by a test: exercising it needs the 130 MB model, which CI does not have
and should not fetch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@yanxue06 yanxue06 added enhancement New feature or request release labels Aug 12, 2026
@yanxue06
yanxue06 merged commit 2a0e0bc into main Aug 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant