sdk

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sdk is what a WebAssembly plugin imports: the wire format between the scanner and a plugin, and a Main that reads the input from stdin and writes the output to stdout.

A plugin gets the tracked, non-excluded files that match its manifest's watches, plus, for a phase-2 plugin, the phase-1 facts it consumes. It returns facts in the shared vocabulary (schema/scan.v1.schema.json) whose evidence points only at files or facts it was sent. It has no file system, no network, no environment and a fixed clock, so it cannot do anything else.

The package uses only the standard library and the fact package, so it builds for GOOS=wasip1 GOARCH=wasm with the Go toolchain and with TinyGo. See https://cernly.dev/how/wasm-plugins/.

Index

Constants

View Source
const API = 1

API is the plugin protocol version this package speaks.

Variables

This section is empty.

Functions

func Line

func Line(content []byte, offset int) int

Line returns the 1-based line of a byte offset in content.

func Main

func Main(run func(in *Input) Output)

Main reads the input, calls run and writes its output. A plugin's main function is one line: sdk.Main(run).

func Match

func Match(pattern, file string) bool

Match reports whether a watch pattern covers a repo-relative file: the pattern matches the file itself or one of its parent folders, `**` spans any number of folders and other segments use path.Match syntax. It is the rule .cernly.yml exclusions follow.

func Serve

func Serve(r io.Reader, w io.Writer, run func(in *Input) Output) error

Serve is Main with explicit streams, for tests run on the host.

Types

type File

type File struct {
	Path    string `json:"path"`
	Content []byte `json:"content_b64"`
}

File is one tracked file the scanner sends.

type Input

type Input struct {
	PluginAPI int         `json:"plugin_api"`
	Repo      Repo        `json:"repo"`
	Facts     []fact.Fact `json:"facts"`
}

Input is what the plugin reads on stdin.

func (*Input) File

func (in *Input) File(p string) (File, bool)

File returns the sent file at path.

type Manifest

type Manifest struct {
	Name      string   `json:"name"`
	Version   string   `json:"version"`
	PluginAPI int      `json:"plugin_api"`
	Watches   []string `json:"watches"`
	Emits     []string `json:"emits"`
	Consumes  []string `json:"consumes,omitempty"`
	// Tools narrows consumed stack facts to these tools.
	Tools []string `json:"tools,omitempty"`
	// SHA256 is the hex hash of the .wasm module this manifest belongs to.
	SHA256 string `json:"sha256"`
}

Manifest describes a plugin; it is signed together with the module's hash (schema/plugin.v1.schema.json, "manifest").

type Output

type Output struct {
	Facts  []fact.Fact          `json:"facts"`
	Errors []fact.LocationError `json:"errors"`
}

Output is what the plugin writes on stdout.

type Repo

type Repo struct {
	Files []File `json:"files"`
}

Repo holds the files sent, sorted by path.

Jump to

Keyboard shortcuts

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