Reindex command, implicit note shorthand, add→addfile rename
- Add `kb reindex` command with confirmation prompt and --yes flag - Add implicit note shorthand: `kb "my note"` submits a note directly - Rename `add` to `addfile`, remove --note/--title/--type flags - Add client-side file extension validation before upload - Add `kb examples` command for common usage patterns - Update README, SKILL.md, and main specs - Archive completed changes and sync delta specs BREAKING: `kb add` renamed to `kb addfile`, `kb add --note` replaced by `kb "text"` Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/kb-search/kb/internal/api"
|
||||
"github.com/kb-search/kb/internal/output"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var reindexCmd = &cobra.Command{
|
||||
Use: "reindex",
|
||||
Short: "Re-embed all chunks with the current engine model",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: runReindex,
|
||||
}
|
||||
|
||||
func init() {
|
||||
reindexCmd.Flags().BoolP("yes", "y", false, "skip confirmation prompt")
|
||||
rootCmd.AddCommand(reindexCmd)
|
||||
}
|
||||
|
||||
func runReindex(cmd *cobra.Command, args []string) error {
|
||||
yes, _ := cmd.Flags().GetBool("yes")
|
||||
|
||||
client := api.NewClient()
|
||||
|
||||
if !yes {
|
||||
// Fetch model name from engine status
|
||||
modelName := "current"
|
||||
statusResp, err := client.Get("/api/v1/status")
|
||||
if err == nil && api.CheckError(statusResp) == nil {
|
||||
var status struct {
|
||||
ModelName string `json:"model_name"`
|
||||
}
|
||||
if api.DecodeJSON(statusResp, &status) == nil && status.ModelName != "" {
|
||||
modelName = status.ModelName
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Reindex all chunks? This will re-embed everything with the %s model. [y/N] ", modelName)
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
answer, _ := reader.ReadString('\n')
|
||||
answer = strings.TrimSpace(strings.ToLower(answer))
|
||||
if answer != "y" && answer != "yes" {
|
||||
fmt.Println("Cancelled.")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
resp, err := client.Post("/api/v1/reindex", nil)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := api.CheckError(resp); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var result struct {
|
||||
ChunksReindexed int `json:"chunks_reindexed"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
if output.IsJSON() {
|
||||
var raw interface{}
|
||||
if err := api.DecodeJSON(resp, &raw); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Failed to parse response:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
output.PrintJSON(raw)
|
||||
} else {
|
||||
if err := api.DecodeJSON(resp, &result); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Failed to parse response:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Reindexed %d chunks (model: %s)\n", result.ChunksReindexed, result.Model)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user