graph

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package graph builds the memory graph the widget renders.

It never returns the whole vault. The graph view is ego-mode only — a focus node and its neighbourhood out to a few hops — because the full-graph hairball is a screenshot, not a tool: impressive once, useless every time after. The backend's job is to extract that neighbourhood, tag each edge with where it came from (so the UI can render trust), and, on request, add the view-time similarity edges that are computed from vectors already in the index and never written to disk.

Index

Constants

View Source
const SimilarityThreshold = 0.62

SimilarityThreshold is how close two notes must be to draw a lens edge between them. High on purpose — similarity edges are suggestive, and a low bar turns the graph into a cobweb where everything faintly touches everything.

Variables

This section is empty.

Functions

func DefaultFocus

func DefaultFocus(db *sql.DB, todaySlug string) string

DefaultFocus picks where to open the graph: today's daily note if it exists, otherwise the highest-degree node — the natural centre of what you know.

func Draw added in v0.4.9

func Draw(g Graph, cols, rows int, color bool) string

Draw renders g as a node-link picture for a terminal: edges traced in braille dots, notes as dots with their names beside them, the focus at the centre — the shape the app's graph view (and Obsidian's) draws, in a grid of characters. cols and rows are the size of the picture, not counting the header and footer lines. color turns on ANSI colour; off, the picture is the same and only the dimming of outer rings is lost.

Every label is vault content and is drawn into a terminal, so it is stripped of control characters first: a title carrying ESC would otherwise be an escape sequence the terminal obeys (invariant 6), not text it shows.

func Find

func Find(db *sql.DB, query string) (string, bool)

Find looks up a node by fuzzy title/slug match, for the "/" jump-to box.

func Label added in v0.4.9

func Label(n Node, width int) string

Label is how a node is named in the drawing: its title, or the last segment of its slug, on one line with control characters removed and clipped to width columns.

func Layout added in v0.4.9

func Layout(g Graph, w, h float64) map[string]Point

Layout places every node of g in a w×h box with a force-directed pass: edges pull their ends together, every pair of nodes pushes apart, and the focus is held at the centre throughout so the rest arranges itself around it — the eye starts where the ego graph does. The result is then stretched to fill the box, which can move the focus off dead centre by the same amount the picture was lopsided.

It is deterministic — no random start, nodes seeded on rings by hop distance in slug order — because the same focus drawn twice in a row must look the same. A layout that reshuffles on every run reads as a different graph, and a user comparing two runs to see what a new link changed would be comparing noise.

func ProjectSlug added in v0.4.9

func ProjectSlug(db *sql.DB, name string) string

ProjectSlug is where a project sits in the graph: its own note when the vault has one, and otherwise a node named for it. The fallback slug is "projects/<name>" on purpose — the edges table stores a checkpoint's project as the bare name, and the walk already matches an incoming edge by the last segment of the slug, so the hub finds its checkpoints with no special case.

func Resolve added in v0.4.9

func Resolve(db *sql.DB, arg string) (string, bool)

Resolve turns what a user typed after `logos graph` into a node: a note's slug as given, a note named by its last segment, or a project by name — which, in most vaults, is the only way in, because a project is a directory of checkpoints and a line in a memory rather than a note.

Types

type Edge

type Edge struct {
	Src        string     `json:"src"`
	Dst        string     `json:"dst"`
	Pred       string     `json:"pred"`
	Conf       float64    `json:"conf"`
	Provenance Provenance `json:"provenance"`
}

type Graph

type Graph struct {
	Focus string `json:"focus"`
	Nodes []Node `json:"nodes"`
	Edges []Edge `json:"edges"`
}

func Around added in v0.4.9

func Around(db *sql.DB, focus string, hops int, opt Options) (Graph, error)

Around is Ego with the choice of layers spelled out.

func Condense added in v0.4.9

func Condense(g Graph, keep int) (Graph, int)

Condense readies a neighbourhood for a terminal. Only the keep most recent checkpoints are drawn, because a project's whole history around its hub is forty dots and no room to name one of them; the rest are counted, and the caller says how many so the picture does not pass for the whole project. Around a project, "<project> — " is taken off its checkpoints' titles: it is the same on every one, and it was costing each label its first eight columns.

func Ego

func Ego(db *sql.DB, focus string, hops int, withSimilarity bool) (Graph, error)

Ego returns the neighbourhood within `hops` of focus. Both directions of each edge are followed — a note you are linked *from* is as much a neighbour as one you link *to*.

type Node

type Node struct {
	Slug      string `json:"slug"`
	Title     string `json:"title"`
	Kind      string `json:"kind"`
	Degree    int    `json:"degree"`
	FirstSeen int64  `json:"first_seen"`
	// Hops is the distance from the focus node, 0 for the focus itself. The UI
	// dims outer rings so the eye starts at the centre.
	Hops int `json:"hops"`
}

type Options added in v0.4.9

type Options struct {
	// Similarity adds the view-time embedding edges.
	Similarity bool
	// Memories adds what the assistant learned and the projects work was
	// filed under. Off for Ego, whose other caller is the context pack: a
	// memory there would be handed to an agent through a door that was
	// never meant to carry one.
	Memories bool
}

Options says what Around draws besides the notes and their edges.

type Point added in v0.4.9

type Point struct{ X, Y float64 }

Point is a node's position in a layout, in the units of the box it was laid out in.

type Provenance

type Provenance string

Provenance is where an edge came from — the thing that decides how much a viewer should trust it, and therefore how it is drawn.

const (
	// Wikilink: a [[link]] you typed. Absolute; drawn solid at full opacity.
	Wikilink Provenance = "wikilink"
	// Typed: a frontmatter relation carrying an explicit confidence.
	Typed Provenance = "typed"
	// Similarity: embedding proximity, computed at view time. A lens, not a
	// fact — faint, off by default, never persisted.
	Similarity Provenance = "similarity"
)

Jump to

Keyboard shortcuts

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