i dont like commits

This commit is contained in:
Tomas Dvorak
2026-02-24 12:10:13 +01:00
parent 898a3c303f
commit 1d72a1cc01
109 changed files with 43586 additions and 8484 deletions
+35 -18
View File
@@ -42,7 +42,7 @@ func init() {
func runServe(cmd *cobra.Command, args []string) error {
if _, err := loadAppConfig(); err != nil {
return err
return fmt.Errorf("load app config for server startup: %w", err)
}
srvCfg := &server.Config{
@@ -65,14 +65,17 @@ func runServe(cmd *cobra.Command, args []string) error {
}
srv := server.NewServer(srvCfg)
return srv.Start(context.Background())
if err := srv.Start(context.Background()); err != nil {
return fmt.Errorf("start rpc server: %w", err)
}
return nil
}
func handleServeMethod(ctx context.Context, method string, params json.RawMessage) (any, error) {
// The method implementation needs full typed config. Load per-call to avoid stale state.
loadedCfg, err := loadAppConfig()
if err != nil {
return nil, err
return nil, fmt.Errorf("load app config for rpc method %q: %w", method, err)
}
switch strings.TrimSpace(method) {
@@ -83,23 +86,31 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
Threshold float64 `json:"threshold"`
}
if len(params) > 0 {
_ = json.Unmarshal(params, &req)
if err := json.Unmarshal(params, &req); err != nil {
return nil, fmt.Errorf("decode devour_query params: %w", err)
}
}
engine := search.NewEngine(loadedCfg)
results, stats, err := engine.Search(ctx, req.Query, search.SearchOptions{Limit: req.Limit, Threshold: req.Threshold})
if err != nil {
return nil, err
return nil, fmt.Errorf("run devour_query search: %w", err)
}
return map[string]any{"query": req.Query, "count": len(results), "results": results, "indexed": stats.Documents}, nil
case "devour_status":
docsStats, err := projectstate.CollectDocsStats(loadedCfg.Storage.DocsDir)
if err != nil {
return nil, err
return nil, fmt.Errorf("collect docs stats: %w", err)
}
state, err := projectstate.LoadSourceState(loadedCfg.Storage.MetadataDir)
if err != nil {
return nil, fmt.Errorf("load source state: %w", err)
}
state, _ := projectstate.LoadSourceState(loadedCfg.Storage.MetadataDir)
engine := search.NewEngine(loadedCfg)
idxStats, _ := engine.EnsureIndexed(ctx)
idxStats, err := engine.EnsureIndexed(ctx)
if err != nil {
return nil, fmt.Errorf("ensure search index: %w", err)
}
return map[string]any{
"documents": docsStats.DocumentCount,
"storage_bytes": docsStats.StorageBytes,
@@ -122,7 +133,7 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
Exclude []string `json:"exclude"`
}
if err := json.Unmarshal(params, &req); err != nil {
return nil, err
return nil, fmt.Errorf("decode devour_scrape params: %w", err)
}
if strings.TrimSpace(req.Source) == "" {
return nil, fmt.Errorf("source is required")
@@ -148,15 +159,17 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
prevFormat := scrapeFormat
prevOutput := scrapeOutput
prevAllowEmpty := scrapeAllowEmpty
defer func() {
scrapeFormat = prevFormat
scrapeOutput = prevOutput
scrapeAllowEmpty = prevAllowEmpty
}()
scrapeFormat = coalesceString(req.Format, "json")
scrapeOutput = req.Output
scrapeAllowEmpty = false
count, err := scrapeOne(nil, loadedCfg, source, resolveOutputDir(loadedCfg, req.Output))
scrapeFormat = prevFormat
scrapeOutput = prevOutput
scrapeAllowEmpty = prevAllowEmpty
if err != nil {
return nil, err
return nil, fmt.Errorf("run scrape for %q: %w", req.Source, err)
}
return map[string]any{"source": req.Source, "type": st, "documents": count}, nil
@@ -166,7 +179,7 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
Limit int `json:"limit"`
}
if err := json.Unmarshal(params, &req); err != nil {
return nil, err
return nil, fmt.Errorf("decode devour_ask params: %w", err)
}
if strings.TrimSpace(req.Question) == "" {
return nil, fmt.Errorf("question is required")
@@ -178,7 +191,7 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
engine := search.NewEngine(loadedCfg)
results, _, err := engine.Search(ctx, req.Question, search.SearchOptions{Limit: limit})
if err != nil {
return nil, err
return nil, fmt.Errorf("run devour_ask search: %w", err)
}
summary := "No relevant docs found."
if len(results) > 0 {
@@ -194,15 +207,19 @@ func handleServeMethod(ctx context.Context, method string, params json.RawMessag
Rebuild bool `json:"rebuild"`
}
if len(params) > 0 {
_ = json.Unmarshal(params, &req)
if err := json.Unmarshal(params, &req); err != nil {
return nil, fmt.Errorf("decode devour_sync params: %w", err)
}
}
syncForce = req.Force
syncRebuild = req.Rebuild
syncSource = req.Source
defer func() {
syncForce, syncRebuild, syncSource = prevForce, prevRebuild, prevSource
}()
err := runSync(nil, nil)
syncForce, syncRebuild, syncSource = prevForce, prevRebuild, prevSource
if err != nil {
return nil, err
return nil, fmt.Errorf("run devour_sync: %w", err)
}
return map[string]any{"ok": true}, nil