runtime/assembly.ts is the composition root: it creates and wires the process resources and injects
them into the harness host and the network service. It embeds no OAuth state machine (that is
auth-session.ts) and no close ordering (that is lifecycle.ts). The order below is the order in the
code, and each step's failure path is part of the contract.
The assembly carries the broker readiness and the browser provider's lifecycle itself; it cannot be reduced to passing capability flags into the host.
- Resolve the data directory. The CLI's default (
~/.minimax) is shared, per ADR 0006; a run needing a clean slate opts intoMINIMAX_DATA_DIRinstead. The WebUI never creates its own. - Reflect the client's region and build scope into the process environment
(
runtime-environment.ts) before the host is built, sogetRuntimeRegion(),getRuntimeBuildEnv()andisManagedRuntime()see the same scope the credential reader served. The WebUI does this for itself because ADR 0003 forbids importing the terminal client's module. A start with no client-side login falls back to the harness defaults (en/dev, not managed). - Create the one OAuth core, its lease and its refresh timer (
auth-session.ts). It reads the sharedmcode logincredential, so a browser session never signs in again. A failure here aborts the boot before any host exists. - Adopt the browser provider (
browser-provider.ts) and register the disposers withlifecycle.ts. - Prepare the mcode-tools integration (
mcode-tools.ts) when the beta switch or an explicit request asks for it. It validates the bundled resource, starts its own auth-lease broker and installs the child environment; its readiness is not the same as its configured state — see../known-gaps.md. - Build the host through the forwarded options:
runtimeOwnerKind: "webui",runtimeMode: "clean",startupExecutionPolicy: "quarantined"(unconditional, unlike the CLI which applies it per surface — ADR 0002),capabilities: {cliEmbedded, questionnaireReply, permissionPrompt, elicitation}all true, andenableLiveMcp: true.configGetterre-reads the config on every access so a model switch is visible without a restart. - Wrap the host's close (
lifecycle.registerHostClose) and start the auth watch. - Install the mcode-tools command path; a failure here closes the host before throwing.
- Enrich the host handle with the credential-backed slots the loose handle does not carry:
getUsageQuota,getSigninPanel,claimSignin, the account-login methods andsignOutAccount(a real revoke-and-remove, not just a projection invalidation). Because consumers rebuild the port fromhost(createHarnessPortFromHost(assembled.host)), these must live on the handle itself, not only on the derived port. - Derive the harness port and return
{harnessPort, host, forwardedOptions, mcodeTools, invalidateAuth}.
Any failure after a resource was acquired releases what was acquired, and startup errors are folded
into one error or an AggregateError labelled "WebUI runtime startup failed".
lifecycle.ts is the single owner of close(), idempotent, and runs:
- auth teardown (stops the watch, clears the refresh timer),
- the harness host,
- the mcode-tools broker,
- the externally supplied browser provider.
Every failure is collected and rethrown as one error or an AggregateError. The pre-host startup
path runs the same owners minus the host. A page unsubscribe never reaches this: closing a browser
connection ends that connection's delivery only. The service's own shutdown is what closes the
runtime.
OAuth core with lease and refresh timer · account login · daily check-in · usage quota and its pure projection · request signing · the runtime environment scope · the mcode-tools broker, child environment and embedded entry · the browser provider · profile files · workspace archive adapters · session transfer · the terminal process manager (one per service) · the six slash commands.
| Entry | Path | Notes |
|---|---|---|
| Development server | scripts/run-webui-server.mjs via pnpm --filter @mavis/webui dev:server |
Spawns itself under tsx with the repository's tsconfig.standalone.json; assembles the host, constructs new WebuiService(...) with the registry and the terminal manager, calls service.start(), and closes the service on SIGINT/SIGTERM. Serves the built client from dist-webui/client/. WEBUI_SERVER_PORT overrides 8787. |
| Packaged service | runtime/index.ts + server/index.ts |
The runtime's public entry and the server build entry. scripts/build-webui.mjs bundles both. |
| npm preview package | release/webui-npm/ |
See ../releasing.md. |
The dev launcher forwards process.env verbatim and constructs the host with dataDir and
appVersion. The mcode-tools broker environment is prepared by the runtime assembly and passed to
the embedded child entry; it is not supplied by the launcher.