//go:build kendemo

// Command ken-demo-go-stdlib is a downloadable, self-contained ken-mcp
// server for the Go standard library. The pre-built search index and
// the Model2Vec embedding model are baked into the binary via
// //go:embed, so it starts instantly (loads the index in ~1-2s, no
// walk/chunk/embed) and needs no corpus checkout, no ~/.ken/model,
// and no network.
//
// The corpus is the Go 1.26.3 stdlib at `$GOROOT/src` minus `cmd/`
// minus `*/testdata/*` — what a Go developer thinks of as "the
// stdlib" (runtime, net, encoding, sync, io, context, ...). See
// docs/internal/road-to-1.0.md and the Phase 1 vetting evidence in
// demos/go-stdlib/QUERIES.md for the scope rationale + the 14
// vetted demo queries.
//
// Build (the kendemo tag keeps this out of the ken module's
// `go build ./...` / CI, and gates the //go:embed of the large
// assets):
//
//	# index.bin + model/ must be present (generated by
//	# `ken build-index /tmp/go-stdlib-curated -o demos/go-stdlib/index.bin --chunker=regex`
//	# and copying ~/.ken/model). Both are gitignored.
//	CGO_ENABLED=0 go build -tags=kendemo -o ken-demo-go-stdlib ./demos/go-stdlib
//
// Register in an MCP client (no env, no repo arg — the corpus is baked):
//
//	{ "mcpServers": { "ken-demo-go-stdlib": {
//	    "command": "/path/to/ken-demo-go-stdlib" } } }
//
// chunker=regex: stdlib is all-Go and ken's regex chunker has real
// Go rules that track tree-sitter boundaries closely while building
// far faster — the right call for Go (docs/BENCH.md). regex is
// registered transitively via internal/search, so no chunker
// import is needed here.
package main

import (
	"context"
	"embed"
	"io/fs"
	"log"

	"github.com/townsendmerino/ken/mcp"
)

//go:embed index.bin
var indexBytes []byte

//go:embed model
var modelEmbed embed.FS

func main() {
	modelFS, err := fs.Sub(modelEmbed, "model")
	if err != nil {
		log.Fatalf("ken-demo-go-stdlib: model fs.Sub: %v", err)
	}
	if err := mcp.Run(context.Background(), modelFS, mcp.Options{
		Mode:          "hybrid",
		ChunkerName:   "regex",
		PrebuiltIndex: indexBytes,
		ModelFS:       modelFS,
		LogLevel:      "info",
	}); err != nil {
		log.Fatalf("ken-demo-go-stdlib: %v", err)
	}
}
