Files
knox/internal/ingest/ingest.go
T
david 0b8ac34aee 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.
2026-11-01 13:48:09 -08:00

65 lines
1.4 KiB
Go

package ingest
import (
"crypto/sha256"
"encoding/json"
"fmt"
)
type IngestResult struct {
Fingerprint string
SourceID string
SourcePath string
Project string
ContentType string
Title string
Summary string
CreatedAt string
LineStart int
LineEnd int
Confidence float64
IngesterVersion string
Provenance map[string]any
// ContentHash is an optional stable hash of the result's *meaningful*
// content. When set, the index treats an unchanged hash as "same knowledge"
// even if the source grew (e.g. a log with the same error set).
ContentHash string
// Content is the full searchable body. Summary stays a short preview; this
// is what full-text search matches against.
Content string
}
type Ingester interface {
SourceID() string
Ingest(path string) (*IngestResult, error)
}
func Fingerprint(data []byte) string {
h := sha256.Sum256(data)
return fmt.Sprintf("%x", h[:16])
}
func FingerprintWithMeta(data []byte, meta map[string]string) string {
h := sha256.New()
h.Write(data)
enc := json.NewEncoder(h)
_ = enc.Encode(meta)
return fmt.Sprintf("%x", h.Sum(nil)[:16])
}
func ProvenanceJSON(m map[string]any) string {
b, err := json.Marshal(m)
if err != nil {
return "{}"
}
return string(b)
}
func truncate(s string, n int) string {
runes := []rune(s)
if len(runes) <= n {
return s
}
return string(runes[:n]) + "..."
}