playground

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package playground serves the gIR Playground: a local web UI that shows what a frontend lowered a project to, and what the loaded rules make of it.

Its reason to exist is that both halves of a rule are invisible from source. A rule matches a canonical name and pins an injection point by LOGICAL argument index (`go:*gorm*.DB*.Raw#0`), where a statically-resolved method call carries its receiver as args[0] — so the index a rule pins is one less than the array index, and getting it wrong fails silently, selecting a real argument that is simply not the intended one.

Two rules keep this tool honest, and both are structural:

  • Nothing here re-implements matching. Sink/source classification and the pattern tester both go through internal/rules, so what the UI draws is the engine's verdict. A second matcher that agreed today would drift.
  • One scan per invocation. The program is lowered once by internal/scan and then only read, so what is on screen is what the command saw.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(idx *Index, addr string, openBrowser bool, w io.Writer) error

Serve listens on addr, announces the URL on w, optionally opens a browser, and blocks until the server stops.

Types

type Index

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

Index is the whole served state: one lowered program, indexed by source file.

func NewIndex

func NewIndex(res scan.Result, target, version string, rs *rules.RuleSet) *Index

NewIndex indexes a completed scan for serving. target is the path the user asked for; res.Program is the merged gIR, which internal/scan already retains.

func (*Index) Files

func (idx *Index) Files() []*fileEntry

Files returns the tree rows.

func (*Index) Handler

func (idx *Index) Handler() http.Handler

Handler returns the routed mux, so a test can drive the API with httptest instead of a listener.

func (*Index) Match

func (idx *Index) Match(fileID, pattern string) matchResult

Match tries one sink pattern against a file's calls, through the same internal/rules matching the engine uses — including the "#idx" spec, so a pattern that the loader would REJECT is reported as rejected here rather than silently widening to "every argument".

func (*Index) View

func (idx *Index) View(id string) *fileView

View renders (once) the gIR for one file. A file with no gIR still gets a view — empty module, State set, source intact — so the UI can show the source beside the reason it never lowered. Only an unknown id has no view at all.

Jump to

Keyboard shortcuts

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