mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 04:23:02 +00:00
update
This commit is contained in:
+86
-17
@@ -1,10 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/yourorg/devour/internal/projectstate"
|
||||
"github.com/yourorg/devour/internal/search"
|
||||
"github.com/yourorg/devour/internal/ui"
|
||||
)
|
||||
|
||||
@@ -23,39 +26,105 @@ Shows:
|
||||
}
|
||||
|
||||
func runStatus(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := loadAppConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Print the small character mascot
|
||||
ui.PrintCharacterSmall()
|
||||
fmt.Println()
|
||||
|
||||
ui.PrintHeader("Devour Status")
|
||||
|
||||
// TODO: Implement actual status check
|
||||
// Check:
|
||||
// - Index existence and health
|
||||
// - Document count
|
||||
// - Vector count
|
||||
// - Last sync time
|
||||
// - Source status
|
||||
docsStats, err := projectstate.CollectDocsStats(cfg.Storage.DocsDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Placeholder status
|
||||
ui.PrintKeyValue("Index Health", "⚠️ Not initialized")
|
||||
ui.PrintKeyValue("Documents", "0 indexed")
|
||||
ui.PrintKeyValue("Chunks", "0 total")
|
||||
ui.PrintKeyValue("Vector Dimension", "1536")
|
||||
ui.PrintKeyValue("Last Updated", "Never")
|
||||
ui.PrintKeyValue("Storage Used", "0 MB")
|
||||
engine := search.NewEngine(cfg)
|
||||
indexStats, indexErr := engine.EnsureIndexed(context.Background())
|
||||
indexHealth := "✓ Healthy"
|
||||
if indexErr != nil {
|
||||
if docsStats.DocumentCount == 0 {
|
||||
indexHealth = "⚠️ No docs indexed yet"
|
||||
} else {
|
||||
indexHealth = "✗ Index error"
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdated := "Never"
|
||||
if !docsStats.LastUpdated.IsZero() {
|
||||
lastUpdated = docsStats.LastUpdated.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
chunks := 0
|
||||
if indexStats != nil {
|
||||
chunks = indexStats.Documents
|
||||
}
|
||||
|
||||
ui.PrintKeyValue("Index Health", indexHealth)
|
||||
ui.PrintKeyValue("Documents", fmt.Sprintf("%d indexed", docsStats.DocumentCount))
|
||||
ui.PrintKeyValue("Chunks", fmt.Sprintf("%d total", chunks))
|
||||
ui.PrintKeyValue("Vector Dimension", fmt.Sprintf("%d", cfg.Embeddings.Dimensions))
|
||||
ui.PrintKeyValue("Last Updated", lastUpdated)
|
||||
ui.PrintKeyValue("Storage Used", humanSize(docsStats.StorageBytes))
|
||||
|
||||
fmt.Println()
|
||||
ui.PrintSection("Sources")
|
||||
ui.PrintInfo(" None configured")
|
||||
state, stateErr := projectstate.LoadSourceState(cfg.Storage.MetadataDir)
|
||||
if stateErr != nil || len(state.Sources) == 0 {
|
||||
ui.PrintInfo(" None tracked yet")
|
||||
} else {
|
||||
keys := make([]string, 0, len(state.Sources))
|
||||
for k := range state.Sources {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sortStrings(keys)
|
||||
for _, k := range keys {
|
||||
s := state.Sources[k]
|
||||
last := "never"
|
||||
if !s.LastSync.IsZero() {
|
||||
last = s.LastSync.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
fmt.Printf(" • %s (%s): %d docs, last sync %s\n", s.Name, s.Type, s.DocCount, last)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
ui.PrintSection("Next Steps")
|
||||
fmt.Println(" 1. Run 'devour init' to initialize")
|
||||
fmt.Println(" 2. Run 'devour scrape <source>' to index documents")
|
||||
if docsStats.DocumentCount == 0 {
|
||||
fmt.Println(" 1. Run 'devour scrape <source>' to index documentation")
|
||||
fmt.Println(" 2. Run 'devour query \"<topic>\"' to search indexed docs")
|
||||
} else {
|
||||
fmt.Println(" 1. Run 'devour query \"<topic>\"' for local docs search")
|
||||
fmt.Println(" 2. Run 'devour ask --lang <lang> \"<question>\"' for structured answers")
|
||||
}
|
||||
if indexErr != nil {
|
||||
fmt.Printf(" ⚠️ Index note: %v\n", indexErr)
|
||||
}
|
||||
|
||||
// Show when check happened
|
||||
fmt.Printf("\nStatus as of: %s\n", time.Now().Format(time.RFC3339))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func humanSize(b int64) string {
|
||||
const mb = 1024 * 1024
|
||||
if b < mb {
|
||||
return fmt.Sprintf("%d KB", b/1024)
|
||||
}
|
||||
return fmt.Sprintf("%.2f MB", float64(b)/float64(mb))
|
||||
}
|
||||
|
||||
func sortStrings(values []string) {
|
||||
if len(values) < 2 {
|
||||
return
|
||||
}
|
||||
for i := 1; i < len(values); i++ {
|
||||
for j := i; j > 0 && values[j] < values[j-1]; j-- {
|
||||
values[j], values[j-1] = values[j-1], values[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user