web

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package web serves `mesh ui`: a sovereign, single-binary localhost graph viewer (no CDN, no third-party JS, self-hosted fonts). It exposes the same in-memory graph the agent reads over MCP, as one /graph.json the SPA renders in two views (an Obsidian-style force graph and a galaxy orbiting the index note).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(vaultRoot, addr, token, basePath string, verify func(string) (int64, string, bool), scopesFor func(int64) map[string]bool) error

Serve builds the server and listens on addr (e.g. 127.0.0.1:7474), printing the URL. A loopback bind needs no auth; binding beyond loopback is fail-closed and requires a token (see newAuthConfig). Serve builds the server and listens. When verify != nil the app runs in per-member mode (each request authenticates as a hub client and is scoped to them); member auth is then the fail-closed gate, so the single-token requirement is skipped. Otherwise it is the standalone single-token viewer (loopback needs no token).

Types

type Export

type Export struct {
	Meta        ExportMeta   `json:"meta"`
	Nodes       []ExportNode `json:"nodes"`
	Edges       []ExportEdge `json:"edges"`
	Communities []ExportComm `json:"communities"`
}

Export is the full graph payload the SPA consumes. Only note nodes and the note-to-note links are included (tags/headings are intra-structure); community, degree, size, and galaxy orbit are precomputed so the client only renders.

func BuildExport

func BuildExport(g *graph.Graph, vaultRoot string, allowed map[string]bool) Export

BuildExport projects the in-memory graph into the SPA payload. allowed (nil = unrestricted) filters notes to the caller's readable scopes; an excluded note drops out of nodes, so its edges and orbit fall away with it.

type ExportComm

type ExportComm struct {
	ID    int    `json:"id"`
	Size  int    `json:"size"`
	Color string `json:"color"` // hex; perceptually-spaced for the top N, gray for the tail
	Label string `json:"label"` // exemplar (highest-degree member) title
}

type ExportEdge

type ExportEdge struct {
	Source string `json:"source"`
	Target string `json:"target"`
	Rel    string `json:"rel"`
}

type ExportMeta

type ExportMeta struct {
	Vault     string `json:"vault"`    // absolute vault root, for the editor:// bridge
	IndexID   string `json:"index_id"` // galaxy center: the highest-degree note
	NodeCount int    `json:"node_count"`
	EdgeCount int    `json:"edge_count"`
	MaxOrbit  int    `json:"max_orbit"` // largest graph-distance from the index note
}

type ExportNode

type ExportNode struct {
	ID        string   `json:"id"`    // frontmatter id
	Label     string   `json:"label"` // title
	Path      string   `json:"path"`  // vault-relative
	Line      int      `json:"line"`  // source line for the editor bridge (1 = top)
	Type      string   `json:"type"`  // frontmatter type (decision/gotcha/entity/...)
	Community int      `json:"community"`
	Degree    int      `json:"degree"`
	Size      float64  `json:"size"`  // sqrt(degree), the client scales to a radius
	Orbit     int      `json:"orbit"` // graph-distance from the index note (0 = center)
	Tags      []string `json:"tags,omitempty"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves the localhost graph viewer + app shell for one vault.

func NewServer

func NewServer(vaultRoot string) (*Server, error)

NewServer opens the vault index and builds the in-memory graph once.

func (*Server) Close

func (s *Server) Close() error

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler wires the routes: the SPA shell, the graph payload, embedded assets, and the /api surface, all behind the auth guard (a no-op on a loopback bind).

func (*Server) SetMemberAuth

func (s *Server) SetMemberAuth(verify func(token string) (int64, string, bool), scopesFor func(int64) map[string]bool)

SetMemberAuth puts the web app in per-member mode: requests authenticate as a hub client and the graph/search/note surfaces are scoped to that member. verify checks a client token; scopesFor returns a member's readable scopes (nil = unrestricted).

func (*Server) SetScopeResolver

func (s *Server) SetScopeResolver(f func(*http.Request) map[string]bool)

SetScopeResolver installs the per-request scope resolver (used by the hub to serve the app under per-member identity).

func (*Server) Store

func (s *Server) Store() *index.Store

Store exposes the index store (for a host that needs NoteScope etc.).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL