End-to-End Build Lifecycle¶
Purpose¶
This document defines the canonical lifecycle across:
- Mozaiks CLI
- the internal Studio host, its visible Studio surface, and the workflow-owned build sequence
factory_app- the active app workspace
- generated artifacts
- hosted product promotion/export
Terminology note:
Studiois the browser product andstudiois the host/composition namemozaiks studiois the current public CLI command for opening Studio- customer-facing UX should prefer
Apps,Usage,Health, andIntegrationsfor the OSS factory Studio; hosted deployments may add their own provider-owned billing or hosting sections Buildrefers to the workflow-owned agent sequence for create and refinement, not a required persistent Studio page- when this document says
Studio host, it means the management composition layer serving the Studio product
The current system has the right primitives, but the lifecycle is not explicit enough. That leads to confusion about:
- whether
initcreates a real app or just a scaffold - whether Studio and the workflow-owned build sequence are operating on the active workspace or on staged artifacts
- when
factory_appshould mutate the live app root - how generated output becomes the app that later runs
This document is the source of truth for that lifecycle.
Core Principle¶
The active app workspace and the generated build output are not the same thing.
Use this mental model:
workspace scaffold
-> holds the active app shell and local config
Studio + factory_app workflows
-> interpret intent and generate staged artifacts
generated artifact bundle
-> reviewable build output, versioned by app_id/build_id
promotion
-> explicit copy of approved artifacts into a runnable app root
In current code, the CLI creates the workspace scaffold and launches Studio. Studio creates apps and manages build/review work inside that workspace.
The generator should stage first and promote second.
The Lifecycle¶
Phase 0: Environment Setup¶
This phase configures Mozaiks itself, not the user app.
Owned by:
- CLI
Responsibilities:
- choose provider/model defaults
- set validation strategy
- choose local vs hosted posture
- choose default workspace root
- make sure required infra/env vars exist
Recommended command:
mozaiks onboard
This is the preferred public entrypoint.
Phase 1: Workspace Bootstrap¶
This phase creates a minimal app workspace scaffold.
Owned by:
- CLI
Responsibilities:
- create
app/app.json - create
app/config/ai.json - create
app/config/shell.json - create
app/brand/theme_config.json - create
app/ui/index.js - create
app/ui/route_manifest.json - create empty
app/modules/andworkflows/
Important rule:
- this scaffold is not the generated app
- it is the hostable workspace shell the platform can run against
Recommended commands:
mozaiks init <preset>for explicit/dev scaffoldingmozaiks onboardmay create this implicitly when missing
Phase 2: Studio Launch¶
This phase starts the host and opens the management UI.
Owned by:
- CLI for process launch
- Studio for lifecycle management UI
Responsibilities:
- select the active workspace
- boot backend host
- boot frontend shell
- open the current management surface
Recommended command:
mozaiks studio --open
This is the current user-facing command path. Customer-facing UX should normalize to Apps as the landing surface and route build/refinement through the workflow-owned agent sequence rather than a persistent Build page.
Low-level equivalents:
mozaiks serve <workspace> --host studio- repo dev scripts such as
run-backend.ps1andrun-frontend.ps1
Important rule:
- repo dev scripts are framework-development tools, not the primary product UX
Phase 3: Build Registry Record¶
This phase creates a durable hosted build/app record before deep generation.
Owned by:
- hosted product control plane
- invoked by
ValueEngine
Responsibilities:
- allocate
build_registry_id - associate
app_id,user_id, app name, and initial status - expose build status to the
Appsdirectory, app Studio summaries, and the workflow-owned build sequence
Important rule:
- this is a hosted control-plane record
- it is not the generated app bundle itself
Phase 4: Intent Decomposition¶
This phase decomposes user intent into planning and realization artifacts.
Owned by:
factory_app
Workflow ownership:
ValueEngine- concept capture
- capability-pack hints
- surface candidate hints
DesignDocs- final
surface_map - ownership/event/page boundary decisions
AgentGenerator- workflow-only surfaces
workflow_stages, tools, workflow-local UIAppGenerator- app schema
- module/control-plane/integration build tasks
- layered module backend contracts
Important rule:
- decomposition decisions belong to
factory_app, not to ad hoc logic in the CLI or hosted app shell - when later refinement re-enters one of these workflows, the control-plane harness should preserve the shared refinement-context contract (
change_class,refinement_request,change_intent,impact_set, and related artifact metadata) instead of relying on transcript reconstruction
Phase 5: Staged Artifact Generation¶
This phase writes generated app output to a staging directory.
Owned by:
factory_app
Current output root:
generated/apps/{app_id}/{build_id}/app
This phase may write:
app.jsonui/pages/*.yamlui/route_manifest.jsonui/pages/custom/*.jsxui/index.jsbrand/theme_config.jsonconfig/shell.jsonconfig/data.json- optional
config/data_migrations/*.json - generated module files
- provider-neutral deployment artifacts (optional):
Dockerfile,docker-compose.yml,.github/workflows/deploy.yml,env.example, anddeployment.manifest.json
Important rule:
- generation should never mutate the live app root by default
- the staged bundle is the reviewable build artifact
- deployment artifacts are deterministic outputs from the provider-neutral generated-app deployment contract and must not contain real secrets
- workflow UI code generation should stay deterministic: shared shipped workflow primitives do not produce workflow-local React files, while genuine workflow-local components are staged under the workflow
ui/tree and get a synthesizedui/index.jsbarrel during assembly
Phase 6: Review And Validation¶
This phase pauses the build sequence for user review before promotion.
Owned by:
- the
app_reviewtransition inextension_registry.json(build sequence terminal step) AppReviewScreenUI componentapp_registrymodule (promote_buildaction)- refinement control plane (revision path)
Responsibilities:
- surface build output summary, validation strategy used, and integration check results
- show sandbox preview URL when E2B or local npm validation ran
- present Promote and Revise paths to the user
- on Promote: call
app_registry.promote_build, transitionlifecycle_statefromreviewtoactive - on Revise: accept user revision request via chat, route through the refinement control plane, operate on the staged
generated/bundle path (not the active workspace)
How the pause works:
AppGeneratorterminates its AG2 session after writing the bundle and callingupdate_build_status(status="review")AppGeneratorsetslifecycle_state=reviewandbundle_pathin AG2 context_variables before terminating- the build sequence advances to the
app_reviewtransition, which rendersAppReviewScreen AppReviewScreenis the HITL boundary — the user decides to promote or request revisions- revision requests re-enter the refinement router with
artifact_rootset to the staged bundle path
App lifecycle state:
building— generation in progressreview— bundle staged, awaiting user decision (promote or revise)active— bundle promoted; this is the runnable state
Canonical frontend/workflow UI smoke targets:
factory_app/workflows/RuntimeUIPrimitiveSmokefactory_app/workflows/AgentGenerator
Important rule:
- canonical review/promotion must flow through the
app_reviewtransition andapp_registry.promote_build, not through ad hoc CLI commands or side effects - revision requests from
app_reviewoperate on the stagedgenerated/bundle, not the active workspace;artifact_rootin the context seed is the guard for this
Canonical frontend/workflow UI smoke targets:
factory_app/workflows/RuntimeUIPrimitiveSmokefactory_app/workflows/AgentGenerator
Deployment contract reference:
Use it when validating changes to:
- AgentGenerator workflow UI planning
ui.workflow_primitivemanifest contractsui.realizationworkflow UI assembly contractschat.tool_call/tool_call_responseworkflow UI transport- workflow-local React component generation rules
- real AG2 multi-turn workflow generation and review flows
Recommended smoke command:
python scripts/run_live_workflow_smoke.py \
--workflow RuntimeUIPrimitiveSmoke \
--workflows-root factory_app/workflows \
--tool-response-file factory_app/workflows/RuntimeUIPrimitiveSmoke/smoke_responses.json
python scripts/run_live_workflow_smoke.py \
--workflow AgentGenerator \
--workflows-root factory_app/workflows \
--prompt-file factory_app/workflows/AgentGenerator/smoke_prompt.txt \
--tool-response-file factory_app/workflows/AgentGenerator/smoke_responses.json \
--timeout-seconds 300
Phase 7: Promotion¶
This phase copies approved artifacts into a runnable app root.
Owned by:
- Studio host / control plane
- optionally CLI for advanced users
Promotion source:
- staged generated app bundle
Promotion target:
- active workspace app root
- export workspace
- hosted deployment bundle
Current implementation:
app_registry.promote_buildmodule action — enforcesreview → activestate guard, emitsdomain.app_registry.app_promoted- called by
AppReviewScreenwhen the user clicks Promote
Important rule:
- promotion is explicit — it is not an incidental side effect of generation
- promotion only runs when
lifecycle_state == "review" - promotion is the step that transitions
lifecycle_statetoactive; generation alone does not make an app runnable
Phase 8: Runtime / Deployment¶
This phase runs or exports the approved app.
Owned by:
- runtime host
- deployment/export tools
- hosted product modules for registry/hosting/deployment
Possible targets:
- local runtime
- downloadable zip bundle
- GitHub export
- hosted deployment pipeline
Important rule:
- running the promoted app is separate from generating it
Objects In The System¶
Use these terms consistently.
| Object | Meaning |
|---|---|
workspace root | Local folder selected by CLI or the current Studio host. |
app root | The runnable app bundle directory, usually <workspace>/app. |
build_registry_id | Hosted control-plane/build-tracking record id. |
app_id | Logical app identity used across workflows and artifacts. |
build_id | Specific build/run identity for staged generation output and lifecycle events. For routed workflow sequences this is the active journey_instance_id. |
journey_instance_id | Runtime sequence instance id shared across all chats in the same authored workflow sequence. |
generated_app_dir | Staged artifact directory under generated/apps/.../app. |
promoted app | App root after explicit promotion from staged artifacts. |
Build Lifecycle Events¶
Runtime lifecycle hook events emitted from build workflows are sequence-scoped.
build_startedis emitted from the first workflow step in the active sequence.build_completedis emitted from the terminal workflow step in the active sequence.build_failedmay be emitted by any workflow that belongs to the active sequence.- Event payload
buildIduses the activejourney_instance_idwhen the workflow is part of a routed sequence. - Event payload
buildRegistryIdis included separately once the hosted control-plane record exists.
This keeps lifecycle reporting aligned with the full routed build journey instead of treating each workflow chat id as an independent build.
Recommended CLI Model¶
The CLI should expose two different paths.
Public Path¶
For most users:
mozaiks onboardmozaiks studio --open- launch the build workflow sequence from Studio
- review staged artifacts
- promote/export/deploy
This path should hide framework details such as:
PLATFORM_PATHMOZAIKS_APP_WORKSPACE_PATH- direct
run-backend.ps1/run-frontend.ps1 - manual distinction between
factory_appand active workspace internals
Power / Dev Path¶
For framework contributors and advanced users:
mozaiks init <preset>mozaiks onboardmozaiks serve <workspace> --host studio- or repo dev scripts
This path is allowed to expose more internal mechanics.
Command Responsibilities¶
mozaiks init¶
Should:
- create a workspace scaffold only
Should not:
- imply that generation already happened
- launch Studio automatically unless explicitly requested by a flag
mozaiks onboard¶
Should:
- configure environment and product intent defaults
- create a scaffold when missing
- optionally offer to open Studio immediately
mozaiks studio¶
Should:
- become the primary entrypoint for actual building
- start backend + frontend together
- open the browser
- route the user into the current app or workspace Studio surface and launch the workflow-owned build sequence from there
mozaiks gen¶
Should:
- stay a convenience shortcut
- reuse the same canonical workflow contracts
Should not:
- become a parallel artifact-management surface
Gaps To Close¶
These are the remaining lifecycle gaps.
- There is no explicit user-facing contract saying that the scaffold is only a shell and that generated output stages separately.
- The preferred public path still feels too dev-script-centric.
- Promotion exists conceptually, but Studio/CLI responsibilities around it are not yet the dominant UX.
- External hosted product workspaces should consume the same staged build/promotion lifecycle instead of inventing a second builder path.
mozaiks gen,mozaiks onboard, andmozaiks studiostill need one coherent story rather than three adjacent tools.
Recommended Next Changes¶
- Make
mozaiks onboardthe primary first-run command. - Add
mozaiks studio --openas the standard builder launch command. - Teach onboarding and Apps/Build status surfaces to explain:
- scaffold
- staged build
- promotion
- Add first-class review/promotion UX in Build around
generated_app_dir. - Keep repo dev scripts as framework tooling only.
- Align hosted product modules (
app_registry,hosting, etc.) to the same build registry and staged artifact lifecycle.
Relationship To Other Docs¶
docs/architecture/frontend/ui-system/generated-frontend-surface-contract.md- defines persistent frontend surface contracts and realization boundaries
data-contract-and-revision-contract.md- defines canonical data contract, staged database artifacts, and revision-time migration rules
- external hosted product workspace docs (outside this repo)
- may define hosted-only boundaries built around this lifecycle
This document defines the lifecycle that those documents assume.