Documentation
¶
Overview ¶
Package graphui serves the interactive graph explorer behind `prism graph`: a local web page that renders the indexed code graph at one level at a time (directories -> files -> symbols -> one symbol's neighbourhood) and lets the user drill down, search, and inspect the evidence behind an edge.
The model is a read-only projection of one graph snapshot. Every view is derived from the same symbols and edges the other Prism commands answer from; nothing here invents or re-resolves an edge.
Index ¶
- Constants
- type CrossRepoFunc
- type Crumb
- type Graph
- type Hit
- type Impact
- type ImpactFunc
- type ImpactSite
- type Link
- type LinkedRepo
- type LinkedSite
- type Meta
- type Model
- func (m *Model) Graph(scope string, o Options) (*Graph, error)
- func (m *Model) Impact(id string, raw map[string]any, depth int, includeTests bool) (*Impact, error)
- func (m *Model) ImpactQuery(id string) (query, file string, err error)
- func (m *Model) Meta() Meta
- func (m *Model) Search(q string, limit int) []Hit
- func (m *Model) Source(id string) (*Source, error)
- type Node
- type OpenRepoFunc
- type Options
- type Server
- type Site
- type Snapshot
- type Source
Constants ¶
const ( RoleTarget = "target" // the declaration being changed RoleFamily = "family" // overrides/implementations/supers that change with it RoleCaller = "caller" // direct callers: edit sites RoleAccess = "access" // reads/writes of a data member: edit sites RoleTransitive = "transitive" // callers of callers: reached, not edit sites )
Roles of the nodes in an impact view, from the change outward.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrossRepoFunc ¶
CrossRepoFunc returns prism map's crossRepo answer (plain JSON values) at directory granularity: the edges between this repository's directories and other repositories' (linked checkouts, cache clones, the link server). nil when no workspace or server is configured.
type Graph ¶
type Graph struct {
Scope Node `json:"scope"`
Crumbs []Crumb `json:"crumbs"`
Nodes []Node `json:"nodes"`
Links []Link `json:"links"`
// Hidden / HiddenOutside count nodes left out by the size caps.
Hidden int `json:"hidden"`
HiddenOutside int `json:"hiddenOutside"`
IncludeTests bool `json:"includeTests"`
// TestFilesExcluded counts test files inside the scope that were left
// out because tests are off.
TestFilesExcluded int `json:"testFilesExcluded"`
// CrossRepoCoverage says which other repositories the root view's
// repository nodes come from, and what was not covered.
CrossRepoCoverage string `json:"crossRepoCoverage,omitempty"`
// CrossRepoUnplaced counts cross references whose directory is not
// drawn (top-level files).
CrossRepoUnplaced int `json:"crossRepoUnplaced,omitempty"`
}
Graph is one rendered view.
type Hit ¶
type Hit struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
Kind string `json:"kind,omitempty"`
Path string `json:"path,omitempty"`
Line int `json:"line,omitempty"`
Test bool `json:"test,omitempty"`
}
Hit is one search result.
type Impact ¶
type Impact struct {
Query string `json:"query"`
Target Node `json:"target"`
Crumbs []Crumb `json:"crumbs"`
Nodes []Node `json:"nodes"`
Links []Link `json:"links"`
Sites []ImpactSite `json:"sites"`
Depth int `json:"depth"`
IncludeTests bool `json:"includeTests"`
Hidden int `json:"hidden"`
TestsHidden int `json:"testsHidden"` // test-file nodes left out (sites still listed)
// Verdict, copied from the change-impact answer.
Completeness string `json:"completeness,omitempty"`
CompletenessScope string `json:"completenessScope,omitempty"`
SafeToClaimComplete bool `json:"safeToClaimComplete"`
ScopeBoundary string `json:"scopeBoundary,omitempty"`
CoverageNote string `json:"coverageNote,omitempty"`
MemberKind string `json:"memberKind,omitempty"`
TotalSites int `json:"totalSites"`
RelaySites []string `json:"relaySites,omitempty"`
Related []Hit `json:"related,omitempty"`
Notes []string `json:"notes,omitempty"`
// Other repositories: linked checkouts, cache clones and the link
// server. Their sites are listed, not drawn: the graph holds one
// repository. WorkspaceScope says what was and was not covered.
LinkedRepos []LinkedRepo `json:"linkedRepos,omitempty"`
LinkedSites int `json:"linkedSites"`
WorkspaceScope string `json:"workspaceScope,omitempty"`
Counts map[string]int `json:"counts"` // nodes per role, before caps
// GroupedByFile: edit sites and reached nodes are drawn one per file
// (Node.Symbols counts the declarations each stands for).
GroupedByFile bool `json:"groupedByFile,omitempty"`
Files int `json:"files"` // distinct files holding an edit site
}
Impact is one rendered change-impact view.
type ImpactFunc ¶
ImpactFunc runs Prism's change-impact for one declaration and returns the tool's JSON answer — the same answer `prism change-impact` and the MCP tool give. file scopes the query to the declaring file.
type ImpactSite ¶
type ImpactSite struct {
Path string `json:"path"`
Line int `json:"line"`
Symbol string `json:"symbol,omitempty"`
NodeID string `json:"nodeId,omitempty"`
Role string `json:"role"`
Access string `json:"access,omitempty"` // decl | read | write | init | call
Text string `json:"text,omitempty"`
Test bool `json:"test,omitempty"`
}
ImpactSite is one confirmed edit site from the change-impact answer.
type Link ¶
type Link struct {
From string `json:"from"`
To string `json:"to"`
Weight int `json:"weight"`
Kinds map[string]int `json:"kinds"`
Tiers map[string]int `json:"tiers,omitempty"`
Sites []Site `json:"sites,omitempty"` // capped; Weight is the full count
}
Link is one drawn edge: every primitive edge from one node to another.
type LinkedRepo ¶
type LinkedRepo struct {
ID string `json:"id"`
Path string `json:"path,omitempty"`
Source string `json:"source"` // checkout | clone | server
Commit string `json:"commit,omitempty"`
Ref string `json:"ref,omitempty"`
Pin string `json:"pin,omitempty"`
State string `json:"state"`
Note string `json:"note,omitempty"`
Sites []LinkedSite `json:"sites"`
}
LinkedRepo is one other repository's part of a change-impact answer.
type LinkedSite ¶
type LinkedSite struct {
File string `json:"file"`
Line int `json:"line"`
Text string `json:"text,omitempty"`
From string `json:"from,omitempty"`
Evidence string `json:"evidence"`
Detail string `json:"detail,omitempty"`
Test bool `json:"test,omitempty"`
}
LinkedSite is one site in another repository.
type Meta ¶
type Meta struct {
Root string `json:"root"`
Name string `json:"name"`
Files int `json:"files"`
Dirs int `json:"dirs"`
Symbols int `json:"symbols"`
Edges int `json:"edges"`
TestFiles int `json:"testFiles"`
Kinds map[string]int `json:"kinds"`
EdgeKinds map[string]int `json:"edgeKinds"`
}
Meta summarises the snapshot.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is an immutable, indexed projection of one graph snapshot.
func BuildModel ¶
BuildModel indexes a snapshot. Document symbols (indexed prose) are left out, as in `prism map`: they are search food, not structure.
func (*Model) Graph ¶
Graph renders the view for a scope id: "" (repository root), "d:<dir>", "f:<file>" or "s:<symbol id>".
func (*Model) Impact ¶
func (m *Model) Impact(id string, raw map[string]any, depth int, includeTests bool) (*Impact, error)
Impact renders a change-impact answer for symbol id onto the graph: the declaration, the family that changes with it, every edit site, and — when depth > 1 — the callers of those callers, which are reached by the change but are not edit sites themselves.
func (*Model) ImpactQuery ¶
ImpactQuery returns the change-impact query for a symbol: its qualified name, scoped to its file.
type Node ¶
type Node struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"` // dir | file | symbol
Kind string `json:"kind,omitempty"`
Path string `json:"path,omitempty"`
Line int `json:"line,omitempty"`
EndLine int `json:"endLine,omitempty"`
Files int `json:"files,omitempty"`
Symbols int `json:"symbols,omitempty"`
Signature string `json:"signature,omitempty"`
Exported bool `json:"exported,omitempty"`
Test bool `json:"test,omitempty"`
// Outside marks context drawn around the scope: a neighbour of the
// scope's contents that lives elsewhere in the repository.
Outside bool `json:"outside,omitempty"`
// Focus marks the symbol a symbol view is centred on.
Focus bool `json:"focus,omitempty"`
// Member marks a symbol declared inside the focus symbol.
Member bool `json:"member,omitempty"`
// Role is the node's place in a change-impact view (impact.go).
Role string `json:"role,omitempty"`
// Detail describes another repository's node (type repo): its commit,
// and whether it was read.
Detail string `json:"detail,omitempty"`
In int `json:"in"`
Out int `json:"out"`
}
Node is one drawn vertex: a directory, a file or a symbol.
type OpenRepoFunc ¶
OpenRepoFunc starts (or finds running) the explorer for the other repository id and returns its page address, token included.
type Options ¶
type Options struct {
// IncludeTests keeps test files. A scope that is itself test code
// always includes them.
IncludeTests bool
// Flat lists every directory that holds files instead of one level of
// the directory tree. It applies to the root scope only.
Flat bool
}
Options selects how a view is built.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the explorer's HTTP surface: one page and a small read-only JSON API over the current Model.
func NewServer ¶
func NewServer(ctx context.Context, root, version string, snapshot Snapshot, reindex func(context.Context) error, impact ImpactFunc) (*Server, error)
NewServer loads the first snapshot and returns a ready server.
func (*Server) Handler ¶
Handler returns the HTTP handler. Every request must address the server by a loopback name: a page on another origin cannot read responses (no CORS headers are sent), and the Host check stops a DNS-rebinding page from turning its own hostname into this server and reading source.
func (*Server) SetCrossRepo ¶
func (s *Server) SetCrossRepo(f CrossRepoFunc)
SetCrossRepo enables other repositories' nodes on the root view.
func (*Server) SetOpenRepo ¶
func (s *Server) SetOpenRepo(f OpenRepoFunc)
SetOpenRepo lets the page open another repository's graph.
type Site ¶
type Site struct {
FromID string `json:"fromId"`
FromSymbol string `json:"fromSymbol"`
FromFile string `json:"fromFile"`
FromLine int `json:"fromLine"`
ToID string `json:"toId"`
ToSymbol string `json:"toSymbol"`
ToFile string `json:"toFile"`
ToLine int `json:"toLine"`
Kind string `json:"kind"`
Tier string `json:"tier"`
}
Site is one primitive edge behind a drawn link.
type Snapshot ¶
Snapshot loads the current graph. Reindex, when set, brings the index up to date with the working tree first (the page's Reload button).
type Source ¶
type Source struct {
ID string `json:"id"`
Path string `json:"path"`
Start int `json:"start"`
End int `json:"end"`
Signature string `json:"signature,omitempty"`
Doc string `json:"doc,omitempty"`
Text string `json:"text"`
Truncated bool `json:"truncated,omitempty"`
}
Source is the declaration text of one symbol.