Preparation API
Download, verify, unpack and seal the native runtimes a kernel plugin declares, in one store every Node host shares.
Preparation API
Import from @taucad/runtime/preparation/node. A Node host such as tau prepare, tau mcp, a daemon or a desktop main process uses it to get a native kernel's runtime onto the machine before the kernel starts. The sandboxed worker never imports it. A plugin declares what it needs in tau-plugin.json; nothing in the plugin runs during preparation.
import { createPreparationHost, parsePluginDeployment } from '@taucad/runtime/preparation/node';
import { defaultDependencyStore } from '@taucad/host';
const host = createPreparationHost({
store: defaultDependencyStore(),
plugins: [{ package: '@taucad/build123d', deployment: parsePluginDeployment(manifest) }],
});
const outcome = await host.prepare({ package: '@taucad/build123d', signal: AbortSignal.timeout(900_000) });The plugin contract
parsePluginDeployment validates parsed tau-plugin.json against schema v1 and returns a PluginDeployment. It refuses unknown fields, pins that are not SRI, paths that escape the closure, a kernel that requires an undeclared dependency and duplicate targets, with a PreparationError whose field names the offending field.
A PluginDeployment maps each dependency name to one DependencyVariant per DependencyTarget, and each kernel id to a KernelDeployment listing the dependencies it requires and the file extensions it handles. A variant lists its files, each a DependencyFile: a name, an Integrity pin, a byte length, a DependencyFileFormat (raw, tar.gz, zip or wheel), a DependencyFileOrigin (URLs, a file in the plugin package, or an asset of a locked npm dependency) and a destination inside the closure. wheelDataDestination gives the prefix a wheel's .data/data/ files install under.
Choosing a variant
detectHostIndicators returns this process's HostIndicators: OS, architecture, libc family and version on Linux, macOS version, whether the process runs translated, and WebAssembly threads. It returns undefined on a platform no closure targets. selectVariant takes one dependency's variants, the indicators and SelectVariantOptions, and returns a VariantSelection: the selected variant with the candidates it considered, or unsupported with the failing VariantAxis and the nearest declared target. targetKey spells a target as darwin-arm64, linux-x64-glibc or browser-threads.
The preparation host
createPreparationHost takes CreatePreparationHostOptions: the PreparationPlugin entries it may prepare, the store root, and optionally a mirror, a seed directory, a forced target, a fetch transport and indicators. It returns a PreparationHost.
preparetakes aPrepareInput(aPluginSelection,offlineand a signal) and resolves aPrepareOutcome:readywith the sealed receipts,blockedwith aPreparationBlockedReason, orcancelled. Bytes come from the store, the seed, the mirror, then the pinned origins, and are verified before they are written. A dependency file the plugin's own package ships is read from the package and never requested from the mirror. The closure is published with one rename, so a crash never leaves a half-written closure. Two calls for one selection join one attempt.inspectreads receipts only and returns aPluginPreparation, whosePreparationStateisidle,preparing,ready,blocked,cancelledorfailed.inspectLaunchis the per-launch read. It returns aLaunchInspectionwhosereadystate maps each dependency to aClosureLaunch: the closure root, its pins and the rows of its launch set, read from the closure's launch index and the head of its receipt. Its cost does not grow with the closure.on('preparation', handler)delivers everyPluginPreparationchange;revisionorders them.verifytakes aVerifyInputand re-hashes each sealed file, returning oneClosureVerificationper dependency. Withrepair, it re-unpacks only the dependency files that differ.describereturns aClosureDescriptionfor every declared dependency.collectGarbagetakes aCollectGarbageInputand returns aGarbageReportof closures no host links, old orphan blobs and abandoned staging.disposeaborts running attempts.
A PreparationPlugin may declare a seal step, which the host runs after every dependency file of a closure is unpacked and before the receipt is written. It receives a SealClosureInput (the package, dependency, target, closure root and the unpacked files) and may only add files, which the host receipts so treeIntegrity covers them; Build123d compiles its bytecode there. Returning a SealClosureRefusal, such as missing-system-library, ends preparation blocked with nothing sealed.
A plugin may also name a launchSet: the few files its kernel's process loads first. The host writes their rows to launch.json beside the receipt. That file is itself a receipted file, so treeIntegrity covers it. A repair moves the receipt aside while it changes the closure, so a failed repair leaves the closure unsealed and never reported intact.
readStoreGeneration returns a token that changes whenever the store seals or removes a closure, so a host can drop cached lookups.
Native kernel deployments
A native kernel package binds its deployment (tau-plugin.json, seal step, launch set) to its registrations, so listing the plugin is the whole integration; nativeDeploymentsOf reads deployments from a resolved runtime.
Receipts
Each sealed closure carries a ClosureReceipt: the declaring package and dependency, the target and how it was selected, every InstalledFile, each dependency file's pin and the DependencyFileAcquisition that served it, and two identities. computeClosureIntegrity hashes which pins make up the closure, so two machines agree before downloading. computeTreeIntegrity hashes the files the installer produced, so a closure can be compared with its golden receipt. Unpacked files are written with mode 0o644, or 0o755 when executable, so a tar of a closure verifies like a clone. reverifyClosure re-hashes one closure against the receipt beside it and names the files that differ. A host runs it when a kernel's worker exits before its handshake.
Managed machines
readManagedPreparation interprets TAU_ACQUISITION, TAU_DEPENDENCY_MIRROR, TAU_DEPENDENCY_MIRROR_NO_FALLBACK, TAU_DEPENDENCY_DIR, TAU_DEPENDENCY_TARGET and TAU_DEPENDENCY_EMULATION into a ManagedPreparation. Its AcquisitionProfile is open or locked; locked never falls back to a manifest URL. describeEffectiveProfile assembles the EffectiveProfile that tau prepare --inspect --json prints for an auditor. Its variables lists which managed, proxy and CA variables are set, by name only, because a proxy URL can carry a credential. Under locked, Tau's hosts also compose their bundler with acquisition: 'locked', so a JavaScript import outside the project's lock fails with package-not-locked rather than downloading.
Errors
PreparationError carries a PreparationErrorCode: MANIFEST_INVALID, DOWNLOAD_FAILED, INTEGRITY_MISMATCH, EXTRACTION_REFUSED or STORE_EXHAUSTED. PreparationErrorOptions adds the manifest field and a cause. A host that lacks a system library a closure links against is not a failure: missingSystemLibrary recognises a loader's report such as a missing libGL.so.1, and systemLibraryRefusal turns it into a blocked state with reason missing-system-library that names the library to install.