feat: ingest Brevier reading copies and phone notes (#48)
Brevier keeps a copy of every page read and exports notes from the phone, and none of it reached knox. This adds a source for both. Archive copies are Markdown with title/source/read front matter, written as <archive>/<host>/<date>-<slug>.md.lz4 or .md depending on the reader's setting. Both forms are read: the setting only changes how new copies are written, and the older ones stay compressed. Entries are keyed by the source URL, so a page read on several days updates one entry and the content hash carries the version, instead of the archive's one-file-per-day turning into duplicate entries. The phone is a different problem. Its archive is app-private and never leaves the device (upstream leaves bulk export undecided), so what can arrive is the notes export and per-page saves. Those are dropped into an inbox directory and read in both shapes Brevier produces: one file with front matter, a zip with one page per file, and a single file with '## [title](url)' sections. A saved article carries no address, so it is keyed by its content; re-saving an unchanged page dedupes. Also checks the Flatpak sandbox path for the archive, since that is where a desktop install actually writes.
This commit is contained in:
+59
-5
@@ -29,8 +29,10 @@ const (
|
||||
logDebounce = 30 * time.Second
|
||||
karakeepInterval = 30 * time.Minute
|
||||
bookorbitInterval = 30 * time.Minute
|
||||
healthInterval = 15 * time.Minute
|
||||
snippetInterval = 10 * time.Minute
|
||||
// Brevier's archive changes only when a page is read, so an hour is plenty.
|
||||
brevierInterval = 1 * time.Hour
|
||||
healthInterval = 15 * time.Minute
|
||||
snippetInterval = 10 * time.Minute
|
||||
)
|
||||
|
||||
// fileState is a cheap identity for a file: an unchanged size+mtime means the
|
||||
@@ -230,6 +232,7 @@ func (w *Watcher) Start() error {
|
||||
opencodeTicker := time.NewTicker(opencodeInterval)
|
||||
karakeepTicker := time.NewTicker(karakeepInterval)
|
||||
bookorbitTicker := time.NewTicker(bookorbitInterval)
|
||||
brevierTicker := time.NewTicker(brevierInterval)
|
||||
healthTicker := time.NewTicker(healthInterval)
|
||||
threadTicker := time.NewTicker(10 * time.Minute)
|
||||
snippetTicker := time.NewTicker(snippetInterval)
|
||||
@@ -244,16 +247,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, bookorbitC, healthC <-chan time.Time
|
||||
var browserC, giteaC, gitC, opencodeC, karakeepC, bookorbitC, brevierC, healthC <-chan time.Time
|
||||
if LocalSourcesEnabled() {
|
||||
browserC, giteaC, gitC = browserTicker.C, giteaTicker.C, gitTicker.C
|
||||
opencodeC, karakeepC, bookorbitC = opencodeTicker.C, karakeepTicker.C, bookorbitTicker.C
|
||||
healthC = healthTicker.C
|
||||
brevierC, healthC = brevierTicker.C, 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, bookorbitRunning, healthRunning, snippetRunning atomic.Bool
|
||||
var opencodeRunning, karakeepRunning, bookorbitRunning, brevierRunning, healthRunning, snippetRunning atomic.Bool
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -347,6 +350,14 @@ func (w *Watcher) Start() error {
|
||||
defer bookorbitRunning.Store(false)
|
||||
w.ingestBookOrbit()
|
||||
}()
|
||||
case <-brevierC:
|
||||
if !brevierRunning.CompareAndSwap(false, true) {
|
||||
continue
|
||||
}
|
||||
go func() {
|
||||
defer brevierRunning.Store(false)
|
||||
w.ingestBrevier()
|
||||
}()
|
||||
case <-healthC:
|
||||
if !healthRunning.CompareAndSwap(false, true) {
|
||||
continue
|
||||
@@ -804,6 +815,49 @@ func (w *Watcher) ingestBookOrbit() {
|
||||
}
|
||||
}
|
||||
|
||||
// ingestBrevier pulls the local Brevier archive (pages that were read) and any
|
||||
// notes exported from the phone into a drop directory.
|
||||
func (w *Watcher) ingestBrevier() {
|
||||
results, err := ingest.NewBrevierIngester().IngestAll()
|
||||
if err != nil {
|
||||
log.Printf("[knox] brevier ingest error: %v", err)
|
||||
return
|
||||
}
|
||||
if len(results) == 0 {
|
||||
return
|
||||
}
|
||||
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: "brevier_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] brevier: %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