~bigbes/sr-ht-dolt

ref: a674ddb16a28934ee97a48a3938c866ad1bc508f sr-ht-dolt/web/memory.go -rw-r--r-- 1.9 KiB
a674ddb1 — Eugene Blikh ci: publish the apk into artifacts.sr.ht as well 4 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package web

import (
	"context"
	"net/url"

	"sourcecraft.dev/bigbes/sr-ht-dolt/beads"
	"sourcecraft.dev/bigbes/sr-ht-dolt/browse"
	"sourcecraft.dev/bigbes/sr-ht-dolt/core"
)

// memoryView renders the memories `bd remember` writes: config rows keyed
// kv.memory.<slug>, each with the revision its value was last written at. The
// row itself is (key, value) and carries no timestamp, so the date comes out of
// the history — see beads.BuildMemories for the walk that finds it.
//
// The reading is not here. It lives in the beads package, which the MCP
// surface's list_memories shares; this type is only the View adapter — slug,
// label, template, and the hand-off of the request's ref and query.
type memoryView struct{}

func (*memoryView) Name() string     { return "memory" }
func (*memoryView) Label() string    { return "Memory" }
func (*memoryView) Template() string { return "memory.html" }

// Applies is the beads fingerprint plus a config table carrying key and value;
// see beads.AppliesMemories. Applies sees table shapes and never rows, so a
// tracker that has never had a memory written into it still gets the tab and
// renders an empty state — the same contract Milestones has.
func (*memoryView) Applies(tables []browse.TableInfo) bool { return beads.AppliesMemories(tables) }

// Build reads the memories and dates them from the history. The result is a
// *beads.MemoryView, handed to memory.html as its .Data.
//
// The clock is passed in rather than read inside the projection: staleness is
// the one thing on this page that depends on when it was rendered, and timeNow
// is the same swappable clock the freshness line uses, so a test pins both at
// once.
func (*memoryView) Build(ctx context.Context, sess BrowseSession, _ *core.Repo, ref string, query url.Values) (any, error) {
	data, err := beads.BuildMemories(ctx, sess, ref, query, timeNow())
	if err != nil {
		return nil, err
	}
	return data, nil
}