Skip to content

@saflib/workflows


@saflib/workflows ​

Interfaces ​

InterfaceDescription
AgentConfigWhen in "run" mode, specify which agent to use.
CdStepInputInput for the CdStepMachine.
CommandStepInputInput for the CommandStepMachine.
CopyStepInputInput for the CopyStepMachine.
IndexedWorkspacePackage-
NpmScriptStepInputInput for the NpmScriptStepMachine.
ParsePackageNameInputArgument for the parsePackageName function.
ParsePackageNameOutputReturn value for the parsePackageName function.
ParsePathInputArgument for the parsePath function.
ParsePathOutputReturn value for the parsePath function.
PromptStepInputInput for the PromptStepMachine.
RunWorkflowOptionsArgument for the runWorkflow function.
RunWorkflowResultReturn value of the runWorkflow function.
TransformFileStepInputInput for the TransformFileStepMachine.
UpdateStepInputInput for the UpdateStepMachine.
ValidateNpmScriptTargetParams-
ValidateNpmScriptTargetResult-
WorkflowArgumentRequired or optional argument for the workflow, in a format the CLI tool (or other program) can use.
WorkflowCliOptionsOptions for configuring the workflow CLI
WorkflowDefinitionAn interface that includes everything that makes up a workflow.
WorkflowLoggerLogger interface for workflow operations
WorkflowLoggerOptionsOptions for creating a workflow logger

Type Aliases ​

Type AliasDescription
AgentCLIThe agent to use for the workflow.
CwdStepInputOld name
GetSourceUrlFunctionFunction type for getting source URLs from absolute file paths.
OffshootInitContext-
OffshootLayer-
WorkflowExecutionModeThe mode to run the workflow in.
WorkflowStepA step in a workflow with an actor and its corresponding input.

Variables ​

VariableDescription
CdStepMachineUpdates the current working directory for subsequent steps, such as "copy", "update", and "command".
CommandStepMachineRuns a shell command as part of a workflow. Stops the workflow if the command fails.
CopyStepMachineCopies all templateFiles to the given directory, performing string replacements for directories, file names, and file contents.
CwdStepMachineOld name. Use CdStepMachine instead. @deprecated.
DEFAULT_SKIP_SOURCE_GLOBSAlways skipped when expanding directory template sources.
NpmScriptStepMachineRuns npm run <script> -w <workspace> with workspace/script validation in dry, checklist, print, run, and script modes. Delegates execution to the same runner used by CommandStepMachine.
PromptStepMachinePrompts the agent or user to do an arbitrary task.
TransformFileStepMachineProgrammatically transforms a file's content. Reads the file, applies the transform function, and writes the result back. Useful for structured edits (JSON, YAML, etc.) that are too mechanical for an agent prompt but need more control than template copying.
UpdateStepMachinePrompts the agent to update one of the templateFiles that was copied over by the CopyStepMachine.

Functions ​

FunctionDescription
buildNpmRunArgs-
checklistToStringConvenience function to convert a checklist to a string.
checkPackageDependencyChecks if the cwd's package.json has a given dependency. Throws an error if it does not.
defineWorkflowHelper, identity function to infer types.
findOutermostWorkspaceRootWalk up from start and return the outermost directory whose package.json declares workspaces.
formatNpmScriptCommand-
getPackageNameReads the package.json for the given cwd and returns the package name.
indexWorkspacePackagesIndex every named package.json under a monorepo root (skipping vendor dirs).
isScriptModeValidationCommandIn script mode, skip agent-loop validation commands. Mechanical steps (install, saf-specs generate, prettier, …) still run; typecheck/test of unfinished scaffolds is asserted separately by CI harnesses when needed.
makeLineReplaceCreates a line-replace function which will handle template interpolation, given a context.
makeOffshootLineReplaceRemap golden @saflib/base-__offshoot-name__-* / Base* tokens onto the target product + offshoot, then apply __placeholder__ interpolation.
makeWorkflowMachineTakes a WorkflowsDefinition, as well as its Context and Input types, and creates an XState machine.
npmScriptToCommandInput-
parentLayerPackageJsonPathParent weave host package.json — missing when scaffolding standalone saflib packages.
parsePackageNameTakes a package name and returns a breakdown into conventional parts for templating.
parsePathTakes a target path to a file and breaks it down into conventional parts for templating.
pollingWaitFor-
resolveOffshootInitContextResolve offshoot scaffold paths.
runWorkflowConvenience function to take a WorkflowDefinition, run it in the specified mode, and return the output. Can be used to run a given workflow in checklist mode for a unit test. This is also used internally by the CLI tool.
runWorkflowCliGiven a list of workflow classes, runs a CLI for running workflows.
shouldSkipSourcePath-
stepHelper function for defining a step in a workflow, enforcing types properly.
validateNpmScriptTargetValidate that an npm workspace and script exist. Throws on invalid targets in dry, checklist, print, run, and script modes (same policy as cd validation).