p2: digest with in-sift FIFO, SQLite caches, Honcho context, recover

Dixie is capped (max_inflight 2, queue_depth 8, queue_wait 20s) and
never queued on llama-server. Streaming chat, thinking off, 45s
fallback to clean. Digest and chunk-embedding caches are
content-addressed SQLite (Honcho context is not cached). Recover
uses the guarded Fetcher. guardian-star is refused in code.
This commit is contained in:
2026-09-22 23:54:49 -07:00
parent 505e113b64
commit 2f9d3d97e6
2023 changed files with 3815943 additions and 30 deletions
+37 -5
View File
@@ -55,14 +55,17 @@ func loadClient() (base, key string, err error) {
func fetchMain() {
fs := flag.NewFlagSet("fetch", flag.ExitOnError)
mode := fs.String("mode", "clean", "clean|raw")
mode := fs.String("mode", "", "clean|raw|digest (default digest if --question)")
jq := fs.String("jq", "", "jq filter (JSON responses)")
question := fs.String("question", "", "focus the digest")
noCtx := fs.Bool("no-context", false, "skip Honcho context")
recoverFlag := fs.Bool("recover", false, "try Wayback / archive.today on bot-wall")
noMain := fs.Bool("no-main", false, "do not isolate main content")
asJSON := fs.Bool("json", false, "print full /v1/fetch envelope")
_ = noMain
_ = fs.Parse(os.Args[1:])
if fs.NArg() < 1 {
fmt.Fprintln(os.Stderr, "usage: sift fetch <url> [--mode clean|raw] [--jq FILTER] [--json]")
fmt.Fprintln(os.Stderr, "usage: sift fetch <url> [--question Q] [--mode clean|raw|digest] [--recover] [--no-context] [--jq FILTER] [--json]")
os.Exit(2)
}
rawURL := fs.Arg(0)
@@ -71,10 +74,22 @@ func fetchMain() {
fmt.Fprintln(os.Stderr, err)
os.Exit(5)
}
modeVal := *mode
if modeVal == "" {
if *question != "" {
modeVal = "digest"
} else {
modeVal = "clean"
}
}
wantCtx := *question != "" && !*noCtx
body, _ := json.Marshal(map[string]any{
"url": rawURL,
"mode": *mode,
"jq": *jq,
"url": rawURL,
"mode": modeVal,
"jq": *jq,
"question": *question,
"context": wantCtx,
"recover": *recoverFlag,
})
req, err := http.NewRequest(http.MethodPost, base+"/v1/fetch", bytes.NewReader(body))
if err != nil {
@@ -116,6 +131,23 @@ func fetchMain() {
fmt.Println()
}
}
if src, ok := env["source"].(map[string]any); ok {
fmt.Println("--- sources ---")
if u, ok := src["final_url"].(string); ok {
fmt.Println(u)
}
if at, ok := src["snapshot_at"].(string); ok && at != "" {
fmt.Println("snapshot_at:", at)
}
}
if ctx, ok := env["context"].([]any); ok && len(ctx) > 0 {
fmt.Println("--- fleet context ---")
fmt.Println("(prior fleet knowledge, not page content)")
for _, it := range ctx {
m, _ := it.(map[string]any)
fmt.Printf("- %v: %v\n", m["peer"], m["content"])
}
}
}
func exitFor(status int, msg string) int {
+29
View File
@@ -14,7 +14,10 @@ import (
"git.wntrmute.dev/kyle/sift/internal/api"
"git.wntrmute.dev/kyle/sift/internal/auth"
"git.wntrmute.dev/kyle/sift/internal/config"
"git.wntrmute.dev/kyle/sift/internal/dcache"
"git.wntrmute.dev/kyle/sift/internal/digest"
"git.wntrmute.dev/kyle/sift/internal/fetch"
"git.wntrmute.dev/kyle/sift/internal/fleetctx"
"git.wntrmute.dev/kyle/sift/internal/guard"
"git.wntrmute.dev/kyle/sift/internal/selfip"
)
@@ -93,6 +96,32 @@ func serveMain() {
defer stop()
srv := api.New(version, g, fetcher, store, log)
if cfg.Dixie.Chat != "" {
cachePath := cfg.Digest.Cache
if cachePath == "" {
cachePath = "/var/lib/sift/cache.db"
}
cache, err := dcache.Open(cachePath, 500<<20, log)
if err != nil {
log.Warn("digest cache", "err", err)
}
srv.Digest = &digest.Engine{
ChatURL: cfg.Dixie.Chat,
EmbedURL: cfg.Dixie.Embed,
Model: cfg.Digest.Model,
Thinking: cfg.Digest.Thinking,
Gate: digest.NewGate(cfg.Dixie.MaxInflight, cfg.Dixie.QueueDepth, config.ParseDuration(cfg.Dixie.QueueWait, digest.DefaultQWait)),
Cache: cache,
Log: log,
}
}
if cfg.Context.Honcho != "" {
allow := cfg.Context.Workspaces
if len(allow) == 0 {
allow = []string{"hermes-fleet"}
}
srv.Ctx = &fleetctx.Client{Base: cfg.Context.Honcho, Allow: allow, Log: log}
}
if len(cfg.SelfIP.Sources) > 0 {
disc := &selfip.Discoverer{
Cfg: selfip.Config{