Initial commit: knox knowledge index

This commit is contained in:
2026-08-29 02:52:32 -07:00
commit 8eecde18b4
31 changed files with 6855 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
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
}
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]) + "..."
}