{"modulePath":"github.com/rossoctl/cortex/core","version":"v0.0.0-20261203232816-53bd38a4e073","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package script\n\nPackage script is the script plugin: it runs every executable file in a folder as a pipeline step, so a user can customize Cortex with a small Python or shell script instead of a Go plugin and a rebuild.\n\nOne pipeline entry, \\`script\\`, is one slot: the files directly in its folder (default ~/.cortex/plugins), in file-name order. Each file is a long-lived worker process (see internal/worker) that answers one JSON message per hook. Repeating \\`script\\` with a different \\`dir\\` puts a second slot elsewhere in the chain, which is how a Go plugin sits between two scripts.\n\nA script declares, in its handshake, which hooks it implements and whether it enforces. It starts in shadow mode — its denies and edits are recorded and not applied — so trying a script cannot break a request. A script that errors (a crash, a timeout, a malformed reply) or does not start lets the request through unless its slot is fail\\_closed.\n\nScripts run only on a local install (plugins.Deps.LocalInstall). Anywhere else a \\`script\\` entry loads nothing, so a config that names one cannot run commands in a sidecar.\n\n## Constants\n\n```go\nconst Name = \"script\"\n```\nName is the plugin's registered name.\n\n## Functions\n\n```go\nfunc Fingerprint(dir string) string\n```\nFingerprint is a digest of every script directly in dir — names, order and contents — so the reloader can tell that a slot changed even when the config file did not. Empty for an empty or missing directory.\n\n```go\nfunc SlotDir(dir string) (string, error)\n```\nSlotDir is the folder a slot's dir config names: ~/.cortex/plugins, or a folder directly inside it.\n\n## Types\n\n```go\ntype Script struct {\n\t// contains filtered or unexported fields\n}\n```\nScript is the plugin.\n\n```go\nfunc New() *Script\n```\nNew returns an unconfigured instance.\n\n```go\nfunc (s *Script) Capabilities() pipeline.PluginCapabilities\n```\nCapabilities is the ceiling until Configure, and after it what the slot is wherever scripts run: a request writer, empty or not. The response side is what still narrows to what the loaded scripts asked for — reading or rewriting responses — so a slot of request scripts does not cost every streamed response its streaming.\n\n```go\nfunc (s *Script) ConfigSchema() []pipeline.FieldSchema\n```\n\n```go\nfunc (s *Script) Configure(raw json.RawMessage) error\n```\nConfigure loads the slot's scripts and starts their workers. A script that will not start is skipped with a WARN, never failing the build: one broken file must not stop the proxy from starting or a config edit from applying. A fail\\_closed slot remembers it and refuses requests until a build in which it starts; see notStarted.\n\n```go\nfunc (s *Script) Init(context.Context) error\n```\nInit runs when this build's pipeline starts: from here its workers are the ones traffic uses, and anything an abandoned build left in the pool can go.\n\n```go\nfunc (s *Script) Metrics() []pipeline.Metric\n```\nMetrics reports the slot's counters on /v1/pipeline.\n\n```go\nfunc (s *Script) Name() string\n```\n\n```go\nfunc (s *Script) OnRequest(ctx context.Context, pctx *pipeline.Context) pipeline.Action\n```\nOnRequest runs every loaded script's request hook, in order. Each sees the request as the scripts before it left it, except that a shadow script's edits are not applied and so are not seen.\n\n```go\nfunc (s *Script) OnResponse(ctx context.Context, pctx *pipeline.Context) pipeline.Action\n```\nOnResponse is never called: the pipeline sends a StreamingResponder's responses to OnResponseFrame instead, buffered or streamed. It exists for the Plugin interface, and runs the hooks should a caller use it directly.\n\n```go\nfunc (s *Script) OnResponseFrame(ctx context.Context, pctx *pipeline.Context, frame []byte, last bool) pipeline.Action\n```\nOnResponseFrame is how responses reach scripts. A buffered response arrives as one last frame with the whole body; a streamed one as each SSE event's payload, then an empty last frame — by then every byte is with the client, so the scripts read it and cannot change or block it. A script that rewrites responses narrows this plugin to WritesResponseBody, which sends streamed responses down the buffered path, where its edits apply.\n\n```go\nfunc (s *Script) SetLocalInstall(local bool)\n```\nSetLocalInstall is how plugins.BuildWithDeps tells the plugin it may run scripts.\n\n```go\nfunc (s *Script) Shutdown(context.Context) error\n```\nShutdown releases this build's workers when its pipeline has drained. A worker the running build also holds keeps running; an edited or removed script's old worker stops here, and not before.\n\n","path":"github.com/rossoctl/cortex/core/plugins/script","name":"script","synopsis":"Package script is the script plugin: it runs every executable file in a folder as a pipeline step, so a user can customize Cortex with a small Python or shell script instead of a Go plugin and a rebuild.","isRedistributable":true}
