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.
This commit is contained in:
2026-11-01 13:33:36 -08:00
parent bb852faa27
commit 0b8ac34aee
43 changed files with 6771 additions and 419 deletions
+2 -2
View File
@@ -231,7 +231,7 @@
{{range .obs}}
<div class="bg-gray-900 rounded px-3 py-2 text-sm flex items-center gap-3">
<span class="font-mono text-xs text-gray-500">#{{.ID}}</span>
<span class="flex-1">{{trunc .Title 50}}</span>
<span class="flex-1">{{trunc .Title 50}}{{with webURL .SourceID .SourcePath .ContentType}} <a href="{{.}}" target="_blank" rel="noopener" class="text-emerald-400 hover:text-emerald-300" title="Open source">↗</a>{{end}}</span>
<span class="text-xs text-gray-500">{{.SourceID}}</span>
{{if gt .Count 1}}<span class="text-xs text-amber-500" title="seen {{.Count}} times">×{{.Count}}</span>{{end}}
<span class="text-xs text-gray-600">{{humanTime .CollectedAt}}</span>
@@ -267,7 +267,7 @@
<div><span class="text-gray-500">Source</span><br>{{.entry.SourceID}}</div>
<div><span class="text-gray-500">Title</span><br><span class="font-medium">{{.entry.Title}}</span></div>
<div><span class="text-gray-500">Project</span><br>{{.entry.Project}}</div>
<div><span class="text-gray-500">Path</span><br><span class="font-mono text-xs">{{.entry.SourcePath}}</span></div>
<div><span class="text-gray-500">Path</span><br><span class="font-mono text-xs">{{.entry.SourcePath}}</span>{{with webURL .entry.SourceID .entry.SourcePath .entry.ContentType}} <a href="{{.}}" target="_blank" rel="noopener" class="text-emerald-400 hover:text-emerald-300">↗</a>{{end}}</div>
<div><span class="text-gray-500">Type</span><br>{{.entry.ContentType}}</div>
<div><span class="text-gray-500">Signal Time</span><br>{{if .entry.CreatedAt}}{{humanTime .entry.CreatedAt}}{{else}}<span class="text-gray-500">—</span>{{end}}</div>
<div><span class="text-gray-500">Ingested</span><br>{{humanTime .entry.LastSeen}}</div>
+132
View File
@@ -7,9 +7,14 @@ import (
"html/template"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/david/knox/internal/db"
@@ -29,6 +34,7 @@ func New(kdb *db.KnoxDB) *Server {
"fpURL": fpURL,
"humanTime": humanTime,
"displayTime": displayTime,
"webURL": webURL,
}).Parse(layout))
s.mux.HandleFunc("GET /", s.dashboard)
@@ -253,6 +259,132 @@ func fpURL(fp string) string {
return "/entries/" + fp
}
// ─── Web links ───────────────────────────────────────────────
// forgeBase is the Gitea/forge base URL (KNOX_FORGE_URL, default the home forge).
func forgeBase() string {
if v := strings.TrimRight(os.Getenv("KNOX_FORGE_URL"), "/"); v != "" {
return v
}
return "https://git.notsosm.art"
}
// skillsRepo is the forge "owner/repo" the skills library lives in.
func skillsRepo() string {
if v := strings.TrimSpace(os.Getenv("KNOX_SKILLS_REPO")); v != "" {
return v
}
return "david/my-skills"
}
// webURL returns a browsable URL for an observation/entry when one can be
// derived from its source and path, else "".
//
// - karakeep / browser : the URL itself.
// - gitea : forge/owner/repo (+ /issues/N or /pulls/N).
// - skills-catalog : the skills repo on the forge.
// - git : the repo's origin remote (SSH→HTTPS, creds stripped).
func webURL(sourceID, sourcePath, contentType string) string {
switch sourceID {
case "karakeep", "browser-history":
if strings.HasPrefix(sourcePath, "http://") || strings.HasPrefix(sourcePath, "https://") {
return sourcePath
}
case "gitea":
base, rest, num := forgeBase(), sourcePath, ""
if i := strings.LastIndexByte(rest, '#'); i >= 0 {
num, rest = rest[i+1:], rest[:i]
}
u := base + "/" + rest
switch contentType {
case "issue":
if num != "" {
return u + "/issues/" + num
}
return u + "/issues"
case "pull":
if num != "" {
return u + "/pulls/" + num
}
return u + "/pulls"
}
return u
case "skills-catalog":
home, _ := os.UserHomeDir()
if rel, err := filepath.Rel(filepath.Join(home, ".skills"), sourcePath); err == nil && rel != "" && !strings.HasPrefix(rel, "..") {
return forgeBase() + "/" + skillsRepo() + "/src/branch/main/" + escapePath(rel)
}
case "git":
if u := gitRemoteURL(sourcePath); u != "" {
return u
}
}
return ""
}
// escapePath path-escapes each segment while keeping the slashes.
func escapePath(p string) string {
segs := strings.Split(filepath.ToSlash(p), "/")
for i, s := range segs {
segs[i] = url.PathEscape(s)
}
return strings.Join(segs, "/")
}
var (
gitRemoteMu sync.Mutex
gitRemoteCache = map[string]string{}
)
// gitRemoteURL resolves a local repo's origin remote to an https URL, caching
// per path. Credentials are stripped; SSH remotes are converted to https.
func gitRemoteURL(repoPath string) string {
gitRemoteMu.Lock()
if u, ok := gitRemoteCache[repoPath]; ok {
gitRemoteMu.Unlock()
return u
}
gitRemoteMu.Unlock()
cmd := exec.Command("git", "-C", repoPath, "remote", "get-url", "origin")
cmd.Env = append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1")
out, err := cmd.Output()
if err != nil {
return ""
}
u := normalizeRemote(strings.TrimSpace(string(out)))
gitRemoteMu.Lock()
gitRemoteCache[repoPath] = u
gitRemoteMu.Unlock()
return u
}
// normalizeRemote converts a git remote into a clean https URL.
func normalizeRemote(remote string) string {
if remote == "" {
return ""
}
// scp-like: git@host:owner/repo.git
if !strings.Contains(remote, "://") {
if i := strings.IndexByte(remote, ':'); i >= 0 {
host := remote[:i]
if at := strings.LastIndexByte(host, '@'); at >= 0 {
host = host[at+1:]
}
return "https://" + host + "/" + strings.TrimSuffix(remote[i+1:], ".git")
}
return ""
}
parsed, err := url.Parse(remote)
if err != nil || parsed.Host == "" {
return ""
}
parsed.User = nil // strip embedded credentials/tokens
parsed.Path = strings.TrimSuffix(parsed.Path, ".git")
return parsed.String()
}
func truncStr(s string, n int) string {
runes := []rune(s)
if len(runes) <= n {