Protocol types
These are the FScript shapes exchanged with Terrabuild. They are ordinary FScript records and discriminated unions; see the FScript type-system documentation for the language rules.
All types below are registered by Terrabuild under Protocol.* names. The declarations describe their visible shapes; use the supplied types directly without redeclaring them.
ExtensionContext
Terrabuild supplies this context to the handler marked Default while discovering project metadata:
type ExtensionContext =
{ Debug: bool
Directory: string
CI: bool }
ActionContext
Terrabuild supplies this context to command handlers:
type BatchContext =
{ Hash: string
TempDir: string
ProjectPaths: string list
BatchCommands: string list }
type ActionContext =
{ Debug: bool
CI: bool
Command: string
Hash: string
Directory: string
Batch: BatchContext option }
Commandis the requested target action.Hashidentifies the current execution context.Directoryis the project directory.BatchisSomeduring batch resolution andNonefor an individual action.
Contexts are structurally matched, so handlers should request only the fields they use:
export let dispatch (context: {| Command: string |}) (args: string option) =
// ...
ProjectInfo
The handler marked Default returns project metadata:
type DependencyResolution =
| Path
| Scope
type ProjectInfo =
{ Id: string option
DependencyResolution: DependencyResolution option
Outputs: string list
Dependencies: string list }
Idsupplies a canonical identity inside the extension scope. When absent, Terrabuild uses the workspace-relative project path.DependencyResolution = Some Pathinterprets dependencies as paths relative to the current project directory.DependencyResolution = Some Scopeinterprets dependencies as identifiers in the current extension scope.DependencyResolution = Nonedefaults toPath.Outputscontributes default artifact patterns.Dependenciescontributes discovered project dependencies.
Outputs and dependencies are sets semantically; avoid returning duplicates.
ShellOperation
Each operation describes one process Terrabuild should execute:
type ShellOperation =
{ Command: string
Arguments: string
ErrorLevel: int }
ErrorLevel is the highest accepted exit code. Operations execute in list order.
CommandResult
Every command handler returns:
type PlatformSensitivity = Sensitive | Portable
type CommandResult =
{ Batchable: bool
Operations: ShellOperation list
PreserveProvenance: ProvenanceEffect
PlatformSensitivity: PlatformSensitivity option }
Batchable = truemeans the returned operation is valid for the supplied batch context.Batchable = falserequires individual execution.Operationsmay contain one or more ordered shell operations.
The result also declares platform sensitivity for the returned operations:
Some Portableallows reuse across execution platforms when the other cache inputs match.Some Sensitiveincludes the effective execution OS and architecture in the cache key.Nonerepresents unknown sensitivity and uses the conservative platform-sensitive behavior. Older handlers with inferred return types can omit the field. Handlers typed asProtocol.CommandResultcan useNoneto select the default.
Use None for a dispatch handler that forwards arbitrary commands. Declare Some Portable when the command’s outputs and cached result are valid across execution platforms.
For host commands, Terrabuild uses the host platform. For container commands, it uses the configured container platform. If the platform is unknown, Terrabuild executes affected targets without reusing or publishing cache entries.
Descriptor flags
The script's final value maps exported function names to these flags:
type Cacheability = Never | Local | External | Remote
type ExportFlag = Dispatch | Default | Cache of Cacheability
{ [nameof dispatch] = [Dispatch; Cache Never] }
Dispatchselects the fallback command handler.Defaultselects the project-metadata handler.Cache Never,Cache Local,Cache External, andCache Remotespecify command cacheability.
Only one function may be marked Dispatch, and only one may be marked Default. Descriptor keys must name functions declared with export let.
ProvenanceEffect = Preserved | Broken | Unaffected is a required command result field. Set Broken for operations that modify managed dependencies, Preserved when they retain them, or Unaffected when they do not affect provenance.