chore: checkpoint uncommitted work before session store fix
Pre-existing work-in-progress in the tree: karakeep, snippets, skills-health and redaction ingesters, the opencode.db session sweep, gossip and metrics changes. Checkpointed as-is so the adapter fix in the next commit stays reviewable on its own.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/david/knox/internal/db"
|
||||
"github.com/david/knox/internal/ingest"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewKarakeepCmd ingests bookmarks (and their crawled article text) from a
|
||||
// self-hosted Karakeep instance into the knowledge index.
|
||||
func NewKarakeepCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "karakeep",
|
||||
Short: "Ingest Karakeep bookmarks + their crawled page content into the index",
|
||||
Long: `Reads bookmarks from the Karakeep REST API (KARAKEEP_URL, KARAKEEP_API_KEY)
|
||||
and, for link bookmarks, downloads Karakeep's crawled article text so the full
|
||||
page is searchable. Fingerprints by bookmark ID for dedup.`,
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
ing := ingest.NewKarakeepIngester()
|
||||
if ing.BaseURL == "" || ing.APIKey == "" {
|
||||
return fmt.Errorf("karakeep not configured: set KARAKEEP_URL and KARAKEEP_API_KEY")
|
||||
}
|
||||
log.Printf("[knox] ingesting Karakeep bookmarks from %s...", ing.BaseURL)
|
||||
|
||||
results, err := ing.IngestAll()
|
||||
if err != nil {
|
||||
return fmt.Errorf("karakeep ingest: %w", err)
|
||||
}
|
||||
if len(results) == 0 {
|
||||
fmt.Println("No Karakeep bookmarks found.")
|
||||
return nil
|
||||
}
|
||||
|
||||
var newCount, withContent int
|
||||
for _, result := range results {
|
||||
if result.Content != "" {
|
||||
withContent++
|
||||
}
|
||||
_, isNew, err := kdb.RecordObservation(db.ObservationRecord{
|
||||
Fingerprint: result.Fingerprint,
|
||||
SourceID: result.SourceID,
|
||||
SourcePath: result.SourcePath,
|
||||
Project: result.Project,
|
||||
ContentType: result.ContentType,
|
||||
Title: result.Title,
|
||||
Summary: result.Summary,
|
||||
Content: result.Content,
|
||||
CreatedAt: result.CreatedAt,
|
||||
Confidence: result.Confidence,
|
||||
IngesterVersion: result.IngesterVersion,
|
||||
Trigger: "karakeep_ingest",
|
||||
Provenance: ingest.ProvenanceJSON(result.Provenance),
|
||||
ContentHash: result.ContentHash,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("[knox] db error: %v", err)
|
||||
continue
|
||||
}
|
||||
if isNew {
|
||||
newCount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Karakeep: %d bookmarks (%d with page content, %d new)\n", len(results), withContent, newCount)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user