Help us shape the future of Go! Take the 2026 Go Developer Survey

models

package
v7.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// prevents memory exhaustion attacks by capping the size of files loaded into the AST.
	MaxSourceFileSize = 10 * 1024 * 1024 // 10 MB
	// limits the buffer size for LLM responses to mitigate potential DoS from upstream providers.
	MaxAPIResponseSize = 5 * 1024 * 1024 // 5 MB
	// caps the added operations listed per function in the evidence an audit
	// sends to the LLM.
	MaxDiffOpsDisplay = 10
	// caps the length of the LLM "evidence" summary. A response longer than a
	// short plain-text rationale indicates the model strayed from the output
	// protocol (e.g. echoing the payload or injected instructions back).
	MaxEvidenceRunes = 4000
	// bounds the source of one side of a flagged function in the audit
	// payload; the rest is a tool call away.
	MaxInlineSourceLines = 120
	// caps one tool result the auditor retrieves.
	MaxToolResultBytes = 16 * 1024
	// caps the lines on each side of a file_context request.
	MaxFileContextRadius = 60
	// caps the tool-call rounds of one audit; the model answers within them
	// or the audit fails closed.
	MaxAuditToolRounds = 8

	// limits the number of attempts to reach an API before conceding failure.
	MaxHTTPRetries = 3
	// provides the starting point for exponential backoff calculations.
	BaseRetryDelay = 500 * time.Millisecond
	// prevents backoff times from growing indefinitely and stalling the execution pipeline.
	MaxRetryDelay = 5 * time.Second
	// bounds one audit's LLM verification: every request and retry in it.
	LLMCallTimeout = 300 * time.Second
	// GlobalScanTimeout is LLMCallTimeout under its old name.
	//
	// Deprecated: Use LLMCallTimeout. It bounds an audit's LLM calls, not a
	// scan.
	//
	//go:fix inline
	GlobalScanTimeout = LLMCallTimeout

	// is the minimum confidence score required to suggest a structural match.
	DefaultTopologyMatchThreshold = 0.6
	// defines the baseline for flagging potentially malicious deviations.
	DefaultScanThreshold = 0.75

	// is the threshold where a function's delta is marked for manual peer review.
	RiskScoreHigh = 10
	// is the baseline penalty applied to any entirely new logic introduced in a diff.
	BaseRiskAddedFunc = 5

	//  no change detected in the target block.
	StatusPreserved = "preserved"
	//  logic changes within an existing function signature.
	StatusModified = "modified"
	//  new logic that did not exist in the baseline.
	StatusAdded = "added"
	// indicates logic that has been purged from the source.
	StatusRemoved = "removed"
	//  a function paired, under a different name, by topology similarity of at
	//  least DefaultTopologyMatchThreshold; its code may differ.
	StatusRenamed = "renamed"

	//  the analysis engine could not determine the structural change type.
	TopoDeltaUnknown = "Unknown"
	//  flags an entirely new function entry point.
	TopoDeltaNew = "NewFunction"
	//  confirms that while text may have changed, the control flow remains the same.
	TopoDeltaNone = "NoStructuralChange"
	//  alerts the auditor to new concurrent execution paths.
	TopoDeltaGoroutine = "AddedGoroutine"
	//  flags new deferred cleanup logic which could be used for resource masking.
	TopoDeltaDefer = "AddedDefer"
	//  indicates the introduction of unhandled error states.
	TopoDeltaPanic = "AddedPanic"

	//  the commit message accounts for every flagged change, in kind and scope.
	VerdictMatch = "MATCH"
	//  the message is too vague to confirm, or the change is out of proportion
	//  to its stated purpose.
	VerdictSuspicious = "SUSPICIOUS"
	//  the message claims something the code contradicts, or the code gains a
	//  capability the message does not account for.
	VerdictLie = "LIE"
	//  indicates a failure in the analysis pipeline itself.
	VerdictError = "ERROR"

	//  vulnerabilities that allow for immediate code execution or data exfiltration.
	SeverityCritical = "CRITICAL"
	//  significant security regressions.
	SeverityHigh = "HIGH"
	//  moderate risk changes or policy violations.
	SeverityMedium = "MEDIUM"
	//  minor issues or code quality concerns.
	SeverityLow = "LOW"

	// default audit model.
	ModelClaudeOpus = "claude-opus-5-5"
	// multimodal reasoning model.
	ModelGeminiPro = "gemini-3-pro-preview"
	// high speed, low latency analysis for large codebases.
	ModelGeminiFlash = "gemini-2.5-flash"
	// frontier OpenAI reasoning models.
	ModelGPT5_2 = "gpt-5.2"

	//  the signature database as one JSON file.
	BackendJSON = "json"
	//  the signature database in PebbleDB, indexed by topology and entropy.
	BackendPebbleDB = "pebbledb"
)
View Source
const (
	ModuleUpdated = "updated"
	ModuleAdded   = "added"
	ModuleRemoved = "removed"
)

Module statuses in a deps diff.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvidence

type AuditEvidence struct {
	Function        string `json:"function"`
	Status          string `json:"status,omitempty"`
	RiskScore       int    `json:"risk_score"`
	StructuralDelta string `json:"structural_delta"`
	AddedOperations string `json:"added_operations"`
	// OldSource and NewSource are the function's declaration on each side,
	// numbered lines bounded by MaxInlineSourceLines; empty for the side the
	// function does not exist on.
	OldSource string `json:"old_source,omitempty"`
	NewSource string `json:"new_source,omitempty"`
}

type AuditInputs

type AuditInputs struct {
	CommitMessage string `json:"commit_message"`
}

type AuditOutput

type AuditOutput struct {
	Inputs     AuditInputs     `json:"inputs"`
	RiskFilter RiskFilterStats `json:"risk_filter"`
	Output     LLMResult       `json:"output"`
}

type DepsDiffOutput

type DepsDiffOutput struct {
	OldDir  string          `json:"old_dir"`
	NewDir  string          `json:"new_dir"`
	Summary DepsDiffSummary `json:"summary"`
	Modules []ModuleDiff    `json:"modules"`
}

DepsDiffOutput is the result of `sfw deps diff`: how the third-party code compiled into a module changed between two trees of it.

type DepsDiffSummary

type DepsDiffSummary struct {
	ModulesUpdated   int `json:"modules_updated"`
	ModulesAdded     int `json:"modules_added"`
	ModulesRemoved   int `json:"modules_removed"`
	FunctionsChanged int `json:"functions_changed"`
	HighRiskChanges  int `json:"high_risk_changes"`
}

type DiffOutput

type DiffOutput struct {
	OldFile         string              `json:"old_file"`
	NewFile         string              `json:"new_file"`
	Summary         DiffSummary         `json:"summary"`
	Functions       []FunctionDiff      `json:"functions"`
	ErrorMessage    string              `json:"error,omitempty"`
	TopologyMatches []TopologyMatchInfo `json:"topology_matches,omitempty"`
	// Unanalyzed lists the //go:linkname directives added to or removed
	// from the file.
	Unanalyzed []FileChange `json:"unanalyzed,omitempty"`
}

type DiffSummary

type DiffSummary struct {
	TotalFunctions     int     `json:"total_functions"`
	Preserved          int     `json:"preserved"`
	Modified           int     `json:"modified"`
	Added              int     `json:"added"`
	Removed            int     `json:"removed"`
	SemanticMatchPct   float64 `json:"semantic_match_pct"`
	TopologyMatchedPct float64 `json:"topology_matched_pct,omitempty"`
	RenamedFunctions   int     `json:"renamed_functions,omitempty"`
	HighRiskChanges    int     `json:"high_risk_changes,omitempty"`
}

type FileChange

type FileChange struct {
	File      string `json:"file"`
	Kind      string `json:"kind"`
	Change    string `json:"change"`
	RiskScore int    `json:"risk_score,omitempty"`
}

FileChange is a change to a file the SSA analysis does not cover.

type FileOutput

type FileOutput struct {
	File         string                 `json:"file"`
	Functions    []FunctionFingerprint  `json:"functions"`
	ScanResults  []detection.ScanResult `json:"scan_results,omitempty"`
	ErrorMessage string                 `json:"error,omitempty"`
}

type FunctionDiff

type FunctionDiff struct {
	Function         string   `json:"function"`
	Status           string   `json:"status"`
	FingerprintMatch bool     `json:"fingerprint_match"`
	OldFingerprint   string   `json:"old_fingerprint,omitempty"`
	NewFingerprint   string   `json:"new_fingerprint,omitempty"`
	MatchedNodes     int      `json:"matched_nodes,omitempty"`
	AddedOps         []string `json:"added_ops,omitempty"`
	RemovedOps       []string `json:"removed_ops,omitempty"`
	RiskScore        int      `json:"risk_score,omitempty"`
	TopologyDelta    string   `json:"topology_delta,omitempty"`
}

type FunctionFingerprint

type FunctionFingerprint struct {
	Function    string `json:"function"`
	Fingerprint string `json:"fingerprint"`
	File        string `json:"file"`
	Line        int    `json:"line,omitempty"`
}

type LLMResult

type LLMResult struct {
	Verdict  string `json:"verdict"`
	Evidence string `json:"evidence"`
}

type ModuleDiff

type ModuleDiff struct {
	Path       string `json:"path"`
	Status     string `json:"status"`
	OldVersion string `json:"old_version,omitempty"`
	NewVersion string `json:"new_version,omitempty"`

	// Packages holds the changed functions of each of the module's packages
	// in the build (updated modules only).
	Packages []PackageDiff `json:"packages,omitempty"`

	// Reach lists exported functions and package initializers that can
	// newly reach a capability class.
	Reach []ReachChange `json:"reach,omitempty"`

	// Unanalyzed lists added, modified and removed files the SSA analysis
	// cannot see: assembly, C and other non-Go sources, .syso and other
	// object files, cgo and build-constraint-excluded Go files, embedded
	// files, and //go:linkname directives.
	Unanalyzed []FileChange `json:"unanalyzed,omitempty"`

	// Capabilities, for an added module or for the packages the new tree
	// newly builds from a module it already used, lists the capability
	// classes their exported functions and package initializers can reach.
	Capabilities []string `json:"capabilities,omitempty"`

	RiskScore       int `json:"risk_score"`
	HighRiskChanges int `json:"high_risk_changes,omitempty"`
}

ModuleDiff is one third-party module whose compiled code differs between the two trees.

type OpenAIContentPart

type OpenAIContentPart struct {
	Type    string `json:"type"`
	Text    string `json:"text"`
	Refusal string `json:"refusal,omitempty"`
}

OpenAIContentPart is one part of an output message: "output_text" carries Text, "refusal" carries Refusal.

type OpenAIInputMessage

type OpenAIInputMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

OpenAIInputMessage is one message of a Responses API input list.

type OpenAIOutputItem

type OpenAIOutputItem struct {
	Type    string              `json:"type"`
	Role    string              `json:"role"`
	Content []OpenAIContentPart `json:"content"`
}

type OpenAIResponsesRequest

type OpenAIResponsesRequest struct {
	Model string               `json:"model"`
	Input []OpenAIInputMessage `json:"input"`
	Store bool                 `json:"store"`
	Text  *OpenAITextConfig    `json:"text,omitempty"`
}

OpenAIResponsesRequest is the body of a POST /v1/responses call.

type OpenAIResponsesResponse

type OpenAIResponsesResponse struct {
	Output []OpenAIOutputItem `json:"output"`
}

OpenAIResponsesResponse is the subset of a Responses API result the client reads: the output items, of which assistant "message" items carry the text.

type OpenAITextConfig

type OpenAITextConfig struct {
	Format OpenAITextFormat `json:"format"`
}

OpenAITextConfig selects the Responses API output format.

type OpenAITextFormat

type OpenAITextFormat struct {
	Type string `json:"type"`
}

type PackageDiff

type PackageDiff struct {
	Path      string         `json:"path"`
	Summary   DiffSummary    `json:"summary"`
	Functions []FunctionDiff `json:"functions"`
}

PackageDiff is the function-level diff of one package of a module.

type ReachChange

type ReachChange struct {
	Function  string   `json:"function"`
	Added     []string `json:"added"`
	Targets   []string `json:"targets"`
	RiskScore int      `json:"risk_score"`
}

ReachChange is an entry point that can reach capability classes it could not reach before, through static calls and function values.

type RiskFilterStats

type RiskFilterStats struct {
	HighRiskDetected bool `json:"high_risk_detected"`
	EvidenceCount    int  `json:"evidence_count"`
}

type ScanOptions

type ScanOptions struct {
	DBPath    string
	Threshold float64
	ExactOnly bool
	ScanDeps  bool
	DepsDepth string
}

type ScanOutput

type ScanOutput struct {
	Target       string                 `json:"target"`
	Database     string                 `json:"database"`
	Backend      string                 `json:"backend"`
	Threshold    float64                `json:"threshold"`
	TotalScanned int                    `json:"total_functions_scanned"`
	DepsScanned  int                    `json:"dependencies_scanned,omitempty"`
	Alerts       []detection.ScanResult `json:"alerts"`
	Summary      ScanSummary            `json:"summary"`
	ScannedDeps  []string               `json:"scanned_dependencies,omitempty"`
}

type ScanSummary

type ScanSummary struct {
	CriticalAlerts int `json:"critical"`
	HighAlerts     int `json:"high"`
	MediumAlerts   int `json:"medium"`
	LowAlerts      int `json:"low"`
	TotalAlerts    int `json:"total_alerts"`
}

type SentinelResponse

type SentinelResponse struct {
	Safe     bool   `json:"safe"`
	Analysis string `json:"analysis,omitempty"`
}

type TopologyMatchInfo

type TopologyMatchInfo struct {
	OldFunction   string  `json:"old_function"`
	NewFunction   string  `json:"new_function"`
	Similarity    float64 `json:"similarity"`
	MatchedByName bool    `json:"matched_by_name"`
	OldTopology   string  `json:"old_topology,omitempty"`
	NewTopology   string  `json:"new_topology,omitempty"`
}

Jump to

Keyboard shortcuts

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