aiusage

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 27 Imported by: ? modules, 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 aiusage reports AI usage in source code: it builds each language's call graph with reach, projects it as a graph fragment and matches the AI cards against it. MCP servers come from the MCP client configs in the tree (package mcp).

Index

Constants

View Source
const (
	ModelLiteral    = "literal"
	ModelConstant   = "constant"
	ModelUnresolved = "unresolved"
)

Model resolution values; a rule that reports a model leaves the field to resolveModel.

View Source
const DefaultRuleset = "ai@latest"

DefaultRuleset is the ruleset Scan downloads when Options.Ruleset is empty.

View Source
const MetadataKey = "ai"

MetadataKey is the rule block AI cards carry their metadata in.

Variables

View Source
var (
	// ErrRulesUnavailable is matched by every error that leaves a scan without rules.
	ErrRulesUnavailable = rulesets.ErrUnavailable
	// ErrAPIKeyRequired is a scan with neither a rules directory nor an API key to lease rules with.
	ErrAPIKeyRequired = fmt.Errorf("%w: API key required", ErrRulesUnavailable)
	// ErrVerdictsUnavailable is a scan whose MCP servers could not be checked with the API key it
	// has: their verdicts are unknown, so the scan has no result.
	ErrVerdictsUnavailable = errors.New("MCP server verdicts unavailable")
)

Functions

func CountAtOrAbove

func CountAtOrAbove(report *sbom.AIUsage, threshold Risk) int

CountAtOrAbove counts the findings whose risk is at least threshold.

func Render

func Render(report *sbom.AIUsage, format Format, project string) (string, error)

Render writes a report as the ai-usage command does, naming project in the document metadata.

func Scan

func Scan(ctx context.Context, target string, opts Options) (*sbom.AIUsage, error)

Scan reports the AI usage under target. Rules come from Options.RulesDir or are leased from the API; an error that leaves the scan without them matches ErrRulesUnavailable. Cancelling ctx stops the scan between languages and aborts its requests.

Types

type Format

type Format string

Format is a format Render writes a report in.

const (
	// FormatRaw is a SCANOSS raw document holding only the ai_usage section.
	FormatRaw Format = "raw"
	// FormatCycloneDX is a CycloneDX AIBOM.
	FormatCycloneDX Format = "cyclonedx"
)

type Options

type Options struct {
	// RulesDir holds the card files, one directory per card language (python/, javascript/). When
	// set, nothing is downloaded; when empty, the ruleset is leased from the API with API's key.
	RulesDir string
	// API is the SCANOSS API rulesets are leased from and MCP verdicts are looked up with.
	API scanoss.Config
	// Ruleset is the ruleset to download, name@version (default DefaultRuleset).
	Ruleset string
	// CacheDir is where downloaded rulesets are cached (default rulesets.DefaultCacheDir()).
	CacheDir string
	// NoCache downloads the ruleset again and refreshes the cache.
	NoCache bool
	// MaxStale is how old a cached ruleset may be when the API is unreachable (default 30 days,
	// at most 90).
	MaxStale time.Duration
	// Strict fails when the API is unreachable instead of using an expired cached ruleset.
	Strict bool
	// Languages are the languages to scan: python, javascript, typescript, and json for MCP
	// client configs. Empty scans every card language the rules hold and the MCP configs.
	Languages []string
	// IncludeTests also scans test files.
	IncludeTests bool
	// Reachability decides for each finding whether it runs from an entry point.
	Reachability bool
	// Vulnerabilities judges the packages MCP servers launch in place of a client built from API.
	Vulnerabilities scanoss.VulnerabilityAPI
}

Options select the rules and languages of a scan.

type Risk

type Risk int

Risk is a finding's risk level, ordered from RiskInfo to RiskCritical.

const (
	RiskInfo Risk = iota
	RiskLow
	RiskMedium
	RiskHigh
	RiskCritical
)

func ParseRisk

func ParseRisk(s string) (Risk, error)

ParseRisk reads a risk name: info, low, medium, high or critical, in any case.

Directories

Path Synopsis
Package contracts holds the types of the AI SDK client objects (what a constructor returns, what its attributes hold), which reach needs to type calls such as client.chat.completions.create.
Package contracts holds the types of the AI SDK client objects (what a constructor returns, what its attributes hold), which reach needs to type calls such as client.chat.completions.create.
Package mcp finds the MCP servers that MCP client configs in a source tree launch or connect to, and judges each launched package with the SCANOSS vulnerabilities API.
Package mcp finds the MCP servers that MCP client configs in a source tree launch or connect to, and judges each launched package with the SCANOSS vulnerabilities API.

Jump to

Keyboard shortcuts

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