feat: ingest BookOrbit highlights as chapter entries (#47)
The index had no trace of anything I have read: BookOrbit holds 234
annotations across 511 books and none of it reached knox, so recall about books
was empty.
Entries are chapters, not highlights. A book produces a handful of dense,
readable entries instead of hundreds of fragments, which is what a reader
actually asks for ("what did I highlight in this chapter").
Uses the annotations export endpoint rather than the Postgres schema: it is the
contract BookOrbit maintains, and it already carries book, chapter, note, style
and origin. Login is one POST per sweep (the endpoint is throttled at 3/min).
Fingerprint is (book, chapter); the content hash is the rendered body, so a new
highlight updates the entry and appends a log version rather than creating a
second copy of the chapter. The watcher deliberately has no mtime-style skip:
a highlight edited in place keeps the same latest timestamp, and skipping on
that would hide the edit.
Wired as 'knox bookorbit', into the full 'knox ingest' sweep, and a 30-minute
ticker inside LocalSourcesEnabled (the server node replicates only).
This commit is contained in:
+65
-7
@@ -26,10 +26,11 @@ const (
|
||||
gossipInterval = 1 * time.Minute
|
||||
// logDebounce coalesces the rapid writes of an actively-appended log so it
|
||||
// is not fully re-parsed every couple of seconds.
|
||||
logDebounce = 30 * time.Second
|
||||
karakeepInterval = 30 * time.Minute
|
||||
healthInterval = 15 * time.Minute
|
||||
snippetInterval = 10 * time.Minute
|
||||
logDebounce = 30 * time.Second
|
||||
karakeepInterval = 30 * time.Minute
|
||||
bookorbitInterval = 30 * time.Minute
|
||||
healthInterval = 15 * time.Minute
|
||||
snippetInterval = 10 * time.Minute
|
||||
)
|
||||
|
||||
// fileState is a cheap identity for a file: an unchanged size+mtime means the
|
||||
@@ -228,6 +229,7 @@ func (w *Watcher) Start() error {
|
||||
gitTicker := time.NewTicker(10 * time.Minute)
|
||||
opencodeTicker := time.NewTicker(opencodeInterval)
|
||||
karakeepTicker := time.NewTicker(karakeepInterval)
|
||||
bookorbitTicker := time.NewTicker(bookorbitInterval)
|
||||
healthTicker := time.NewTicker(healthInterval)
|
||||
threadTicker := time.NewTicker(10 * time.Minute)
|
||||
snippetTicker := time.NewTicker(snippetInterval)
|
||||
@@ -242,15 +244,16 @@ func (w *Watcher) Start() error {
|
||||
// Ingestion only runs where the sources exist. A node with no local
|
||||
// sources (KNOX_LOCAL_SOURCES=none) leaves these nil: nil channels block
|
||||
// forever, so the select never fires for them.
|
||||
var browserC, giteaC, gitC, opencodeC, karakeepC, healthC <-chan time.Time
|
||||
var browserC, giteaC, gitC, opencodeC, karakeepC, bookorbitC, healthC <-chan time.Time
|
||||
if LocalSourcesEnabled() {
|
||||
browserC, giteaC, gitC = browserTicker.C, giteaTicker.C, gitTicker.C
|
||||
opencodeC, karakeepC, healthC = opencodeTicker.C, karakeepTicker.C, healthTicker.C
|
||||
opencodeC, karakeepC, bookorbitC = opencodeTicker.C, karakeepTicker.C, bookorbitTicker.C
|
||||
healthC = healthTicker.C
|
||||
} else {
|
||||
log.Printf("[knox] KNOX_LOCAL_SOURCES=none: local ingest disabled, derivation still active")
|
||||
}
|
||||
var browserRunning, giteaRunning, gitRunning, threadRunning, gossipRunning atomic.Bool
|
||||
var opencodeRunning, karakeepRunning, healthRunning, snippetRunning atomic.Bool
|
||||
var opencodeRunning, karakeepRunning, bookorbitRunning, healthRunning, snippetRunning atomic.Bool
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -336,6 +339,14 @@ func (w *Watcher) Start() error {
|
||||
defer karakeepRunning.Store(false)
|
||||
w.ingestKarakeep()
|
||||
}()
|
||||
case <-bookorbitC:
|
||||
if !bookorbitRunning.CompareAndSwap(false, true) {
|
||||
continue
|
||||
}
|
||||
go func() {
|
||||
defer bookorbitRunning.Store(false)
|
||||
w.ingestBookOrbit()
|
||||
}()
|
||||
case <-healthC:
|
||||
if !healthRunning.CompareAndSwap(false, true) {
|
||||
continue
|
||||
@@ -746,6 +757,53 @@ func (w *Watcher) ingestKarakeep() {
|
||||
}
|
||||
}
|
||||
|
||||
// ingestBookOrbit pulls reading highlights (one entry per book chapter) from a
|
||||
// self-hosted BookOrbit instance configured via BOOKORBIT_URL,
|
||||
// BOOKORBIT_USERNAME and BOOKORBIT_PASSWORD.
|
||||
func (w *Watcher) ingestBookOrbit() {
|
||||
results, err := ingest.NewBookOrbitIngester().IngestAll()
|
||||
if err != nil {
|
||||
log.Printf("[knox] bookorbit ingest error: %v", err)
|
||||
return
|
||||
}
|
||||
if len(results) == 0 {
|
||||
return
|
||||
}
|
||||
// No mtime-style pre-check here: a highlight edited in place keeps the
|
||||
// same latest timestamp, and skipping on that would hide the edit. The
|
||||
// content hash in RecordObservation is the change signal.
|
||||
var newCount, updated int
|
||||
for _, result := range results {
|
||||
_, isNew, err := w.knoxDB.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: "bookorbit_timer",
|
||||
Provenance: ingest.ProvenanceJSON(result.Provenance),
|
||||
ContentHash: result.ContentHash,
|
||||
})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if isNew {
|
||||
newCount++
|
||||
} else {
|
||||
updated++
|
||||
}
|
||||
}
|
||||
if newCount > 0 || updated > 0 {
|
||||
log.Printf("[knox] bookorbit: %d new, %d updated", newCount, updated)
|
||||
}
|
||||
}
|
||||
|
||||
// checkSkillsHealth warns when the skills git repo looks broken — the skills
|
||||
// MCP auto-commits/pushes but hides git errors, so silent breakage (corrupt
|
||||
// objects, unpushed commits, low disk) would otherwise go unnoticed.
|
||||
|
||||
Reference in New Issue
Block a user