{"modulePath":"github.com/Fendix-app/Fendix/go","version":"v0.0.0-20261028135234-a02776cc5df9","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package plugin\n\nPackage plugin discovers and runs out-of-tree Fendix plugins.\n\nA plugin is a directory containing a plugin.yaml manifest and an executable entrypoint. The engine invokes the entrypoint with a JSON ScanRequest on stdin; the entrypoint emits zero or more newline-delimited Finding JSON objects on stdout, terminated by {\"done\": true, \"total\": N}. This is the same NDJSON contract the embedded Python engine speaks (ADR-002), so plugin authors writing a Python plugin can share most of the engine.py scaffolding.\n\nDiscovery walks two roots in order:\n\n 1. \\\u003crepo\u003e/.fendix/plugins/    (repo-local; OPT-IN — see below)\n 2. ~/.fendix/plugins/         (user-global; trusted)\n\nOn collision (same plugin name in both roots) the repo-local version wins, so a project can pin a specific plugin version without affecting the developer's other repos.\n\nRepo-local plugins are NOT auto-discovered by default (F-H2): a repository under scan is attacker-controlled in the poisoned- pipeline threat model (a malicious PR can drop a \\`.fendix/plugins/\\` directory and get arbitrary code executed in CI). The repo-local root is therefore gated behind explicit opt-in (the AllowRepoLocalPlugins config flag, threaded into Roots). The user-global ~/.fendix/plugins root the operator populated by hand stays trusted and is always searched.\n\n## Constants\n\n```go\nconst DefaultTimeout = 30 * time.Second\n```\nDefaultTimeout caps a single plugin invocation when the manifest does not specify a Timeout.\n\n```go\nconst MaxTimeout = 5 * time.Minute\n```\nMaxTimeout is the upper bound on plugin runtime regardless of what the manifest claims. A plugin that wants longer scans should run async and emit findings incrementally; the engine cannot wait forever on a single subprocess.\n\n## Functions\n\n```go\nfunc DefaultRoots(cwd string, allowRepoLocal bool) []string\n```\nDefaultRoots returns the canonical plugin search path. The user-global root (~/.fendix/plugins) is always included — the operator populated it by hand, so it's trusted. The repo-local root (\\\u003ccwd\u003e/.fendix/plugins) is included only when allowRepoLocal is true (F-H2): the scanned repo is attacker-controlled in the poisoned- pipeline threat model, so a \\`.fendix/plugins/\\` committed by a hostile PR must not auto-execute in CI. When repo-local is allowed, it's listed first so it shadows a same-named user-global plugin.\n\ncwd is the working directory whose .fendix/plugins should be searched (typically the scan root). If cwd is empty, the repo-local root is omitted regardless of allowRepoLocal. On systems where os.UserHomeDir fails (very rare) the user-global root is silently omitted.\n\n## Types\n\n```go\ntype Mode string\n```\nMode declares whether a plugin sees blackbox (URL/spec/auth) or whitebox (code path) inputs. Plugins that need both can declare Mode=\"hybrid\"; the orchestrator will run them once with all fields populated.\n\n```go\nconst (\n\tModeBlackbox Mode = \"blackbox\"\n\tModeWhitebox Mode = \"whitebox\"\n\tModeHybrid   Mode = \"hybrid\"\n)\n```\n\n```go\ntype Plugin struct {\n\tSpec\n\t// Dir is the absolute path to the plugin directory. Entrypoint\n\t// is resolved relative to Dir.\n\tDir string\n}\n```\nPlugin is a discovered, validated plugin ready to run.\n\n```go\nfunc Discover(roots []string) ([]Plugin, error)\n```\nDiscover walks the given roots in order, parses every plugin.yaml it finds, and returns the resulting Plugin list deduplicated by Name (earlier roots win — pass repo-local first, user-global second; see DefaultRoots). A malformed plugin.yaml in one directory does not stop discovery in others; the error for that directory is logged at WARN level and the plugin is skipped.\n\nSymlinked plugin \\*directories\\* are skipped (F-H2): following a symlink lets a directory entry point outside the discovery root — a poisoned repo could symlink its \\`.fendix/plugins/x\\` at an attacker-staged tree, and an operator's \\`~/.fendix/plugins/y\\` could be redirected by a hostile package. Only real directories are discovered; copy (or \\`git clone\\`) a plugin into the root rather than symlinking it.\n\nDiscover is intentionally tolerant of missing roots: a fresh install with no plugin directories returns (\\[], nil), not an error.\n\n```go\nfunc LoadPlugin(dir string) (Plugin, error)\n```\nLoadPlugin parses plugin.yaml under dir and validates the result. Exported wrapper around loadPlugin so the \\`fendix plugins install\\` subcommand (internal/pluginscmd, TASK-130) can validate a freshly- cloned tree without re-implementing the manifest parser.\n\n```go\nfunc (p Plugin) Run(ctx context.Context, req ScanRequest) ([]models.Finding, error)\n```\nRun invokes the plugin entrypoint and returns the findings it emitted. A plugin that exits with non-zero status, takes longer than its timeout, or emits a {\"error\": ...} terminator returns an error; partial findings collected before the failure are preserved in the slice.\n\nFindings emitted without a Source field are tagged with the plugin's Mode so downstream correlation/dedup treats them consistently with the embedded engines.\n\n```go\ntype ScanRequest struct {\n\tMode       Mode     `json:\"mode\"`\n\tURL        string   `json:\"url,omitempty\"`\n\tSpec       string   `json:\"spec,omitempty\"`\n\tCodePath   string   `json:\"code_path,omitempty\"`\n\tAuth       string   `json:\"auth,omitempty\"`\n\tAuthType   string   `json:\"auth_type,omitempty\"`\n\tCategories []string `json:\"categories,omitempty\"`\n\tVerbose    bool     `json:\"verbose\"`\n}\n```\nScanRequest is the JSON payload the engine sends to a plugin's stdin. It mirrors the embedded engine's ScanRequest plus a Categories field so plugins can filter to relevant work without re-walking the source tree. Field names are stable — adding new fields is fine, removing or renaming them is a breaking change.\n\n```go\ntype Spec struct {\n\tName        string        `yaml:\"name\"`\n\tVersion     string        `yaml:\"version,omitempty\"`\n\tDescription string        `yaml:\"description,omitempty\"`\n\tEntrypoint  string        `yaml:\"entrypoint\"`\n\tMode        Mode          `yaml:\"mode\"`\n\tCategories  []string      `yaml:\"categories,omitempty\"`\n\tTimeout     time.Duration `yaml:\"timeout,omitempty\"`\n\t// Env is an optional allowlist of extra environment variable names\n\t// the plugin needs passed through from the operator's environment\n\t// (F-I1). By default the runner inherits only a minimal fixed\n\t// allowlist (PATH, HOME, LANG/LC_*, TMPDIR) plus the FENDIX_PLUGIN_*\n\t// vars it sets; a plugin that needs, say, a corporate proxy var can\n\t// name it here. This is the plugin author *requesting* a var — it\n\t// does not grant access the operator hasn't already exported.\n\t// Backwards-compatible: omitting it preserves the minimal default.\n\tEnv []string `yaml:\"env,omitempty\"`\n}\n```\nSpec is the on-disk plugin.yaml schema. Unknown fields are rejected (yaml.Decoder.KnownFields(true)) so typos surface as errors rather than silently-ignored config — same posture as .fendix.yaml in policy.Load.\n\n","path":"github.com/Fendix-app/Fendix/go/internal/plugin","name":"plugin","synopsis":"Package plugin discovers and runs out-of-tree Fendix plugins.","isRedistributable":true}
