Files
david 6242f21e3d
build / test (push) Successful in 3m51s
build / image (push) Successful in 37s
feat: ingest Brevier reading copies and phone notes (#53)
feat: ingest Brevier reading copies and phone notes (#53)

Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-11-09 00:31:31 +00:00

79 lines
2.3 KiB
Go

package cmd
import (
"fmt"
"log"
"github.com/david/knox/internal/db"
"github.com/david/knox/internal/ingest"
"github.com/spf13/cobra"
)
// NewBrevierCmd ingests the local Brevier archive and any notes exported from
// the phone into the knowledge index.
func NewBrevierCmd(kdb *db.KnoxDB) *cobra.Command {
cmd := &cobra.Command{
Use: "brevier",
Short: "Ingest Brevier reading copies and phone note exports",
Long: `Reads the Brevier archive (BREVIER_ARCHIVE, default
~/.local/share/brevier/archive) and a drop directory for notes exported from
the phone (BREVIER_INBOX, default ~/.local/share/knox/inbox/brevier).
Archive copies are keyed by their source URL, so a page read again on another
day updates its entry instead of adding a second one.`,
RunE: func(c *cobra.Command, args []string) error {
ing := ingest.NewBrevierIngester()
if ing.Archive == "" && ing.Inbox == "" {
return fmt.Errorf("brevier not configured: set BREVIER_ARCHIVE and BREVIER_INBOX")
}
log.Printf("[knox] ingesting Brevier from %s and %s...", ing.Archive, ing.Inbox)
results, err := ing.IngestAll()
if err != nil {
return fmt.Errorf("brevier ingest: %w", err)
}
if len(results) == 0 {
fmt.Println("No Brevier copies or note exports found.")
return nil
}
var newCount, copies, notes int
for _, result := range results {
switch result.ContentType {
case "reading/copy":
copies++
case "reading/notes":
notes++
}
_, 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: "brevier_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("Brevier: %d copies, %d note export(s), %d new\n", copies, notes, newCount)
return nil
},
}
return cmd
}