feat: enable file indexing by default

File indexing only adds ~3 seconds to the indexing process, so enable
it by default to make the get_file tool work out of the box.

- MCP index_revision tool now indexes files automatically
- CLI flag changed from --files to --no-files (opt-out)
- Update README examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 18:45:50 +01:00
parent 3ba85691a8
commit 452b0fda86
3 changed files with 13 additions and 6 deletions

View File

@@ -63,14 +63,14 @@ nixos-options serve
**Index a nixpkgs revision:** **Index a nixpkgs revision:**
```bash ```bash
# Index by channel name # Index by channel name (includes file contents by default)
nixos-options index nixos-unstable nixos-options index nixos-unstable
# Index by git hash # Index by git hash
nixos-options index e6eae2ee2110f3d31110d5c222cd395303343b08 nixos-options index e6eae2ee2110f3d31110d5c222cd395303343b08
# Index with file contents (enables get_file tool, slower) # Index without file contents (faster, disables get_file tool)
nixos-options index --files nixos-unstable nixos-options index --no-files nixos-unstable
``` ```
**List indexed revisions:** **List indexed revisions:**

View File

@@ -43,15 +43,15 @@ func main() {
ArgsUsage: "<revision>", ArgsUsage: "<revision>",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "files", Name: "no-files",
Usage: "Also index file contents (slower, enables get_file tool)", Usage: "Skip indexing file contents (faster, disables get_file tool)",
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if c.NArg() < 1 { if c.NArg() < 1 {
return fmt.Errorf("revision argument required") return fmt.Errorf("revision argument required")
} }
return runIndex(c, c.Args().First(), c.Bool("files")) return runIndex(c, c.Args().First(), !c.Bool("no-files"))
}, },
}, },
{ {

View File

@@ -217,12 +217,19 @@ func (s *Server) makeIndexHandler(indexer *nixos.Indexer) ToolHandler {
return ErrorContent(fmt.Errorf("indexing failed: %w", err)), nil return ErrorContent(fmt.Errorf("indexing failed: %w", err)), nil
} }
// Index files by default
fileCount, err := indexer.IndexFiles(ctx, result.Revision.ID, result.Revision.GitHash)
if err != nil {
s.logger.Printf("Warning: file indexing failed: %v", err)
}
var sb strings.Builder var sb strings.Builder
sb.WriteString(fmt.Sprintf("Indexed revision: %s\n", result.Revision.GitHash)) sb.WriteString(fmt.Sprintf("Indexed revision: %s\n", result.Revision.GitHash))
if result.Revision.ChannelName != "" { if result.Revision.ChannelName != "" {
sb.WriteString(fmt.Sprintf("Channel: %s\n", result.Revision.ChannelName)) sb.WriteString(fmt.Sprintf("Channel: %s\n", result.Revision.ChannelName))
} }
sb.WriteString(fmt.Sprintf("Options: %d\n", result.OptionCount)) sb.WriteString(fmt.Sprintf("Options: %d\n", result.OptionCount))
sb.WriteString(fmt.Sprintf("Files: %d\n", fileCount))
sb.WriteString(fmt.Sprintf("Duration: %s\n", result.Duration.Round(time.Millisecond))) sb.WriteString(fmt.Sprintf("Duration: %s\n", result.Duration.Round(time.Millisecond)))
return CallToolResult{ return CallToolResult{