scriptlayer

package
v1.138.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package scriptlayer is the MCP surface of the managed-script feature: the manage_script tool and everything it needs to resolve, authorize, edit, validate, and dry-run a script.

It owns the assembly (the Postgres-backed script store) and the tool, and it depends on pkg/script for the domain rules and internal/platform/scriptrun for the engine. Nothing here decides what Starlark means and nothing here re-implements the edit gate; both live one layer down, so the tool is a translation from MCP arguments into domain calls.

The MCP server is captured at RegisterTool rather than at construction: the store must exist early, while the server exists only once the platform has assembled it, and run_draft needs that server to open its in-memory session.

Index

Constants

View Source
const (
	// DefaultWaitSeconds is how long run_script waits for a run to finish when
	// the caller names no window.
	DefaultWaitSeconds = 120

	// MaxWaitSeconds caps the wait, the same cap the portal's run route
	// applies (runcontrol.MaxWaitSeconds). Past it the tool answers with the
	// run id and a pending status rather than holding a request open for the
	// length of a run.
	MaxWaitSeconds = runcontrol.MaxWaitSeconds
)

Waiting policy for run_script.

View Source
const DialectContract = scriptcontract.Dialect

DialectContract is the dialect contract (internal/platform/scriptcontract).

View Source
const ToolNameManageScript = "manage_script"

ToolNameManageScript is the MCP tool name of the script-management tool, exported for composition roots that bind UI apps to it.

View Source
const ToolNameRunScript = "run_script"

ToolNameRunScript is the MCP tool name of the platform-execution tool, exported for composition roots that bind UI apps to it.

View Source
const ToolNameShowScripts = "show_scripts"

ToolNameShowScripts is the MCP tool name of the presentation-only trigger that opens the portal's script pages for the human.

Variables

View Source
var KnowledgePages = []KnowledgePage{
	{
		Slug:      "platform-writing-managed-scripts",
		Reference: knowledgePageRefPrefix + "platform-writing-managed-scripts",
		Summary: "The dialect and the authoring loop: what Starlark deliberately lacks, what a " +
			"script may call and the persona that decides it, and what a save makes runnable.",
	},
	{
		Slug:      "platform-reference-script",
		Reference: knowledgePageRefPrefix + "platform-reference-script",
		Summary: "A whole automation written as a saved one is, with the tests it is saved " +
			"with and how each test is recorded and written: start from it.",
	},
	{
		Slug:      "platform-script-outputs-and-export-identity",
		Reference: knowledgePageRefPrefix + "platform-script-outputs-and-export-identity",
		Summary: "Where an output lands and what identity it keeps across runs: a stable name " +
			"refreshes one asset, a dated name builds an archive, and a bucket destination " +
			"delivers the same bytes elsewhere.",
	},
	{
		Slug:      "platform-semi-dynamic-dashboards",
		Reference: knowledgePageRefPrefix + "platform-semi-dynamic-dashboards",
		Summary: "Choosing between composing a whole document every run and publishing one " +
			"document whose data region a schedule refreshes, and the mechanics of the " +
			"second.",
	},
	{
		Slug:      "platform-asset-references-and-the-refresh-loop",
		Reference: knowledgePageRefPrefix + "platform-asset-references-and-the-refresh-loop",
		Summary: "How a document names a file instead of carrying it, and how a run refreshes " +
			"that file so every document naming it shows the new content without being " +
			"re-saved.",
	},
	{
		Slug:      "platform-provenance-and-the-capture-loop",
		Reference: knowledgePageRefPrefix + "platform-provenance-and-the-capture-loop",
		Summary: "Naming sources with call references so an output's provenance is exact, and " +
			"the loop that turns session knowledge into reviewed catalog knowledge.",
	},
}

KnowledgePages is the reading `manage_script help` names, so the tool an agent is told to call before writing its first script is the tool that routes it to the platform's own authoring guidance instead of leaving that guidance to whatever a search happens to rank (#1476).

The slugs are declared here rather than in knowledgebuiltin because knowledgebuiltin already imports this package for the dialect contract and the reverse import would cycle; a test there fails when the two sets drift.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DB backs the script store; nil leaves the store nil and manage_script
	// unregistered (there is nowhere to keep a script).
	DB *sql.DB
	// Store, when non-nil, is used directly instead of building a Postgres
	// store from DB. Production passes DB and leaves this nil.
	Store script.Store
	// Runs is the run queue run_script enqueues onto and the run history the
	// run commands read. nil leaves run_script unregistered, which is the
	// correct shape for a deployment that cannot execute scripts at all.
	Runs script.RunStore
	// AdminPersona is the persona name that grants authority over every
	// script; matched against the caller's persona in each command.
	AdminPersona string
	// PortalURL is the deployment's public portal address, used by show_scripts
	// to name where the script pages are. Empty leaves the tool registered and
	// linkless: a deployment that has not been told its own address cannot be
	// given one by guessing.
	PortalURL string
	// Destinations is the deployment's configured bucket destinations, which a
	// draft run resolves platform.export names against exactly as a platform
	// run does.
	Destinations []script.Destination
	// Toolkits is the live toolkit registry a draft's write barrier reads the
	// api gateway's operation ids and an MCP gateway's proxied-tool
	// declarations through (#1664). Nil leaves the barrier classifying from
	// its declared table alone, which refuses both of those forms.
	Toolkits scriptdraft.ToolkitLister
	// DraftExports builds the writer a draft run with allow_writes persists
	// its exports through (#1822). Nil leaves every draft export a preview.
	DraftExports scriptdraft.Exports
	// RunLimits are the ceilings a platform run executes under on this
	// deployment, which the help reports so an author sizes a script against
	// the limits it will actually meet (#1843). Zero fields are the defaults.
	RunLimits scriptrun.PlatformLimits
	// Recordings keeps what each run and draft's host calls were answered, for
	// a script's tests and a save's replay (#1939, #1942). Nil builds one over
	// DB.
	Recordings scriptrec.Store
}

Config carries the resolved values the owner needs to assemble the script layer. The caller translates its own config into this shape so this package stays free of the platform's config types.

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle owns the assembled script layer. All accessors are nil-safe, so a deployment without a database holds a Handle that registers nothing.

func New

func New(cfg Config) *Handle

New assembles the script layer.

func (*Handle) DraftExports added in v1.134.0

func (h *Handle) DraftExports() scriptdraft.Exports

DraftExports is the writer a draft allowed to write persists its exports through, for the other surface that runs drafts (the portal editor) to run them the way manage_script does (#1822). Nil on a nil Handle.

func (*Handle) HasStore added in v1.129.0

func (h *Handle) HasStore() bool

HasStore reports whether the layer has a script store, which is the condition under which it registers manage_script, run_script and show_scripts. Callers enumerating the platform's own tools ask this rather than assuming the tools exist, so a no-database deployment is not credited with them.

func (*Handle) IndexProducer added in v1.122.0

func (h *Handle) IndexProducer() *indexjobs.Producer

IndexProducer returns the write-path index-job producer behind the managed- script store, or nil on a deployment with no database. The composition root hands it to the index queue, which binds it once the scripts consumer is registered; until then, and forever where no worker runs, NotifyWrite is a no-op and the reconciler is the only route to the index.

func (*Handle) RegisterTool

func (h *Handle) RegisterTool(server *mcp.Server)

RegisterTool registers manage_script; where the deployment can execute saved scripts, run_script; and the presentation-only show_scripts. It also captures the server the two run paths open their in-memory sessions against. No-op on a nil Handle or a no-database deployment (there is nowhere to keep a script).

type KnowledgePage added in v1.126.0

type KnowledgePage struct {
	// Slug is the page's reconcile key and the only identifier stable across
	// deployments: a built-in page's row id is generated at reconcile time, so
	// it differs per deployment and cannot be named in shipped text.
	Slug string `json:"slug"`
	// Reference is the slug in the form fetch takes.
	Reference string `json:"reference"`
	// Summary says what the page answers, so an author fetches the one that
	// bears on the decision in front of it rather than all of them.
	Summary string `json:"summary"`
}

KnowledgePage names one built-in knowledge page an author should read.

Jump to

Keyboard shortcuts

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