Iterating on a tilolang app
Two loops:
- The app loop. Save a
.tlfile. The running app shows the change in about 50 ms, with its state: its resources, its view state, the scroll, the selection and the open item. - The runtime loop. Change the runtime (
tilolang-process,tilolang-tilo,tilolang-runtime) and build it. The running app restarts on the new runtime, almost all of it the build. Its resources are still there.
There are two ways to run them:
- On this desktop.
tilolang dev DIRruns the package as an ordinary window, with no Tilo session: it is the developer's own app, and its records are its local store. This is the everyday loop. - In a real session.
tilolang dev DIR --session SESSIONdevelops the package inside a running nested session, where it runs as an installed app: launched by the launcher, in its sandbox, under its own id and ownership. Use it to test a change against a real session.
On this desktop
Build the tool with the workspace's fast profile, the one it names for the desktop:
cargo build --profile fast -p tilolang-cli --bin tilolangand start the loop:
target/fast/tilolang dev apps/tl/tasks --search apps/tlThe first start builds tilolang-process from the checkout in the same profile (an ordinary
build; a thin build runs only against a session's runtime library) and opens the package's
window. --runtime BIN runs a binary you built yourself instead, and a new build of it
restarts the window on it.
What the loop counts as a save: anything that changes what a build reads. That is every
.tl file of the package and of the packages it uses, the translations in their
locales/, and entries added, removed or renamed anywhere below their directories, a
whole package directory moved in included (the loop watches the directory above each
package, so a package replaced whole is taken again). Then it compiles once: the events of
one save, and of one build writing a file in steps, are gathered for a few tens of
milliseconds first.
A --runtime BIN build counts too, and the loop starts the window again only once the new
program is whole: a build that copies the binary in place, or replaces its directory, is
taken as soon as the file has stopped growing and is executable (up to 60 seconds). The
window comes back on its checkpoint: the document, the route, the view state and the
caret. The old process is stopped first, with time to flush.
If the sources use a type this build of the tool does not know (E013 unknown type) and
the checkout's own sources are newer than the tool, the loop says so instead of leaving the
error to look like a mistake in the package: rebuild the tool and start tilolang dev
again.
The profile is not a detail of this loop: it compiles each saved package, interprets it and
draws every frame of its window, and an unoptimised build of it does each of those several
times slower. fast is the workspace's answer for a local build that must run at
near-release speed.
The loop is a directory protocol (tilo_app_module, TILO_APP_MODULE_UPDATES): the tool
publishes each build as a numbered generation and names the current one in a current
file; the app watches that file. Nothing else can reach the window. A generation holds the
compiled bundle itself: a local build stages no payload, packs no .tapp and signs nothing,
because nothing installs it.
- The app is a plain process the tool starts and stops: it has no session, no launcher and no sandbox around it.
- Its record is the framework's local store (
$XDG_DATA_HOME/tilo), so resources persist across saves, across a process restart and across latertilolang devruns. Ctrl-Cstops the tool and the window. Closing the window stops the loop.
In a real session
You need a nested-session build (dist/dev/nested-session-build.sh target/nested-session, which dist/dev/nested-session.sh builds) and the tool, built
with the nested session's profile:
cargo build --profile nested --config 'profile.nested.inherits="release"' \
--config profile.nested.lto=false --config profile.nested.codegen-units=16 \
--config profile.nested.incremental=true -p tilolang-cli --bin tilolangThe examples below call the result tilolang (target/nested/tilolang).
# Start a session and the app in it; from then on, every save reaches the app.
tilolang run apps/tl/notes --search apps/tl --headless --softwaretilolang run opens the app once the session's catalogue offers it (applications <id>): it asks the shell for the applications listing and the shell holds the answer
until the listing has settled or changed. If the run fails at any point after the session
started, the tool stops the session: the shell, its apps and its services.
To work in a session that is already running, attach to it:
dist/dev/nested-session.sh --headless --software --state /tmp/s --ready /tmp/s.json &
tilolang dev apps/tl/notes --search apps/tl --session /tmp/s.json--session takes the --ready file, the session's runtime directory, its control
socket or its state directory.
To type tilolang at the app's data, as the session's person, attach the REPL the same way:
tilolang repl --session # the only session running, or the one you pick
tilolang repl --session /tmp/s # that oneThe REPL reaches the session through Tilo's API, which every session serves its own person's
programs on this computer (the Tilo API). What it changes shows in the
session's History as the person's, and undo takes it back.
There, on every save tilolang dev:
- compiles the package in-process (tens of milliseconds);
- on an error, prints the diagnostics and stops: the app keeps running the last good build;
- signs the build into a
.tappand installs it withtilo-install, like any install; - says in one line what the running app does with it.
The gallery
apps/tl/gallery places every component of the toolkit with the values an app gives
it. Open it as a native window or in a session:
target/fast/tilolang dev apps/tl/gallery --search apps/tl # a window on this desktop
tilolang run apps/tl/gallery --search apps/tl # a nested session, the gallery open in it
tilolang dev apps/tl/gallery --search apps/tl --session /tmp/s.json # into a nested session already runningThe app loop
Both ways of running take a new build the same way, in one of two ways:
- In place. This is the usual case. Resources live in the workspace record and view state lives in the runtime, both keyed by declaration id. Scroll, selection and the open item live in the window. So the new module takes them over: the views are opened again on the same windows, under the same shell.
- Starting over. If the new build cannot read what the old one wrote, the tool says why, for
example
type Note: the field \done` changed from Bool to Int`. The app then starts over on the new build and the workspace record, as its next start would: every resource is still there. View state and the open item start fresh. Nothing is deleted. A value of the old type stays in the record until something writes the field again.
The second case covers:
- a field whose type or merge changed;
- an enum case that was removed;
- a view
statewhose type changed; - a new app name, icon or category.
The app name, icon and category are the installed manifest's. The window chrome shows them from the app's next start.
Adding and removing declarations keeps state. A removed field's values stay in the
record, unread. Renaming keeps state too, because the ids lock keeps each id
(tilolang ids --rename). tilolang has no migration rules yet. When it does, this is
where they run.
How the swap stays inside ownership in a session
A dev-mode swap installs a package exactly as any install does: verified by
tilo-install, its old version kept while it runs. Then the session hands the new
module to the tilolang process that runs the app's instances. Nothing else can.
Development sessions only. The session follows reinstalls only when two things hold:
- it is built with the developer overrides;
- it is started with
TILO_LAUNCHER_LIVE_MODULES=1, whichnested-session.shsets.
A shipped session ignores the variable (
package_store::dev_env).Verified like a launch. When the app store's registry changes, the session reads the new installation of each app a running host runs. It verifies it with the same check a launch makes (the signed record, the payload's integrity, the revocation list). It hands it over only if the host would run it: the same author signed it and it names the same runtimes. A build that names another runtime runs only on a new start.
Over the host's action API. The module goes to the host in a sealed memfd, on the action API the session hands it instances on. The host checks that it is still the app's own id, and every instance of the app takes it over.
The windows, their sandboxes and grants stay as they were launched. The only thing
that changes is which verified module the host interprets. The code is in
crates/core/tilo-runtime/src/device/processes.rs and crates/lang/tilolang-process.
On the desktop there is no session to hand anything over: the tool runs the app itself and
publishes into a directory of its own, private to the person, which the app reads
(crates/lang/tilolang-process/src/window/updates.rs, the generation protocol of crates/lang/tilo-app-module).
The runtime loop
On this desktop
Let tilolang dev build the runtime (or give --runtime BIN a binary of your own):
target/fast/tilolang dev apps/tl/tasks --search apps/tlOn every change of tilolang-process, tilolang-tilo, tilolang-runtime or tilolang it
runs cargo build --locked --profile fast -p tilolang-process --bin tilolang-process --features app-launch, and when the build
succeeds it stops the running app (SIGTERM, so it flushes its checkpoint) and starts it
again on the new binary. The resources are in its local store; the scroll, selection and
open item come back from the checkpoint.
In a session
tilolang dev apps/tl/notes --search apps/tl --session /tmp/s.json --build-runtimetilolang dev then:
- builds
tilolang-processthin withdist/dev/tilolang-runtime-build.sh(cargo). It builds again on every change oftilolang-process,tilolang-tilo,tilolang-runtimeortilolang; a failed build leaves the apps on the last good runtime; - bakes the binary into a runtime bundle signed by a key the launcher trusts;
- packs it as a runtime package (
so.tilo.runtime.tilolang.dev, providingtilolang/0.1.0+dev) and installs it withtilo-install; - builds the apps naming
tilolang/0.1.0+dev; - restarts each of their windows: to the front,
tab.close, and once the window is gonetab.reopen, which relaunches it in place as a session restore does.
--runtime BIN instead follows a binary you build yourself, and re-bakes on every
new build of it.
Every new build re-bakes and reinstalls the bundle, and the apps restart on it. Save .tl files as before: those builds name the same runtime
and are taken in place.
The binary is built thin, as the session's own runtime bundle carries it: a few
megabytes, linked against the session's libruntime_dylib.so. A thin build runs only on
the runtime library of its own Cargo graph, because a Rust dylib's symbols carry crate
hashes, so it is built with the default collection's runtime plan, as the
nested session's build does, and the tool refuses a build whose library is not the one
the session runs: start the session on a build of the same checkout.
Measuring
scripts/headless-examples/tilolang-dev-loops.py --runs 5 # in a session
scripts/headless-examples/tilolang-dev-loops.py --desktop --runs 5 # on this desktopThe script edits, waits for the change on screen, and prints the medians. Both runs are
headless, on lavapipe, under a session's compositor; the desktop run is the tool's own
window, with no session, as a plain client of that compositor. --busy N keeps N
CPU-bound processes running, so a run shows the loop under load too, and every sample
prints the load average it saw.
The script reports each save as built in <ms>, published in <ms>; the running app takes it with its state, and the app logs when it drew the new build. The first save after a
start is the app's first take-over, so its module is interpreted and drawn for the first
time; every warm save takes the build in place with its state.
In the app loop, compiling and packing take 1 to 2 ms. tilo-install takes
140 to 170 ms, but the app takes the build as soon as the install commits its
registry row, before the installer has finished. A slow run is normally an install
that waited on the disk.
The app loop is timed from the save to two points:
- the app's own first frame of the new build: the app logs
draws build N at <ms>when it draws it; - the first frame after it that the compositor presented, which the app logs as a
tilo-display-framerow withTILO_PROFILE_PRESENTATION=1.
The second adds the app's rendering of the frame, its hand-over and the compositor's presentation: 12 ms at the median here, since a changed placeholder repaints little.
- the app's own first frame of the new build: the app logs
The runtime loop is timed end to end: from the edit of a runtime source, through the build, the bake, the install and the restart, to the restarted app's first presented frame.
Running a change in a real session
The desktop loop is the person's own: the tool starts the app from their terminal and the app's record is its local store. A tilolang app inside a Tilo session is an installed app, so a changed build there still needs two things a release launcher does not grant:
- A runtime key the person authorizes. A release launcher trusts only the image's
runtime publishers. Today the session points it at its own list, which is a
developer override. The desktop needs a person-held list of development runtime keys
that a release launcher also reads. Settings would offer "Trust runtimes I build",
recording the key
tilolang devsigns with. The launcher would take such a key only for runtime versions marked+dev, and only for apps the person develops. - Live modules per app, by grant. A release session never follows reinstalls. It needs a per-app development grant that the person gives in Settings and the session records like other grants, in place of an environment variable. The session follows reinstalls of a granted app's package with the checks it makes now: same author, same runtimes, verified like a launch.
- Open and restart from a terminal. The tool opens and restarts apps through the
session's test control socket, which only developer builds serve. On a desktop it
needs the person's action API:
applications <id>,tab.closeandtab.reopen, invoked as the person. The admin socket refuses processes the shell launched, and a terminal is one.